Remove testbin dir

This commit is contained in:
Floorb 2021-08-20 16:19:56 -04:00
parent 4103bc48c0
commit e3d2f64d39
10 changed files with 1 additions and 507 deletions

View file

@ -1,35 +0,0 @@
<?php
// INIT
require __DIR__ . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "2a-config.php";
require PATH_LIB . "2b-lib-tag.php";
$tagDB = new Tag();
// PROCESS AJAX REQUESTS
switch ($_POST['req']) {
// INVALID
default:
echo json_encode([
"status" => 0,
"message" => "Invalid request"
]);
break;
// GET TAGS FOR POST
case "get":
$tags = $tagDB->getAll($_POST['post_id']);
echo json_encode([
"status" => is_array($tags) ? 1 : 0,
"message" => $tags
]);
break;
// SAVE TAGS
case "save":
$pass = $tagDB->reTag($_POST['post_id'], json_decode($_POST['tags']));
echo json_encode([
"status" => $pass ? 1 : 0,
"message" => $pass ? "OK" : $tagDB->error
]);
break;
}
?>

View file

@ -1,54 +0,0 @@
<?php
// INIT
require __DIR__ . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "2a-config.php";
require PATH_LIB . "2b-lib-tag.php";
$tagDB = new Tag();
// GET TAGS
$postID = 3;
$tags = $tagDB->getAll($postID);
// HTML ?>
<!DOCTYPE html>
<html>
<head>
<title>Simple Tag Demo</title>
<script src="public/3b-tag.js"></script>
<link href="public/3c-tag.css" rel="stylesheet">
</head>
<body>
<!-- [DOES NOT MATTER - YOUR POST] -->
<h1>
Lord of the Minks
</h1>
<p>
The undone complaint collapses past an east estate. The insulting nurse flames the era. A willed hierarchy surfaces.
A tentative wife bites the consenting fence.
</p>
<!-- [TAGS] -->
<div id="tag_dock">
<h3>MANAGE TAGS</h3>
<!-- [TAGS LIST] -->
<div id="tag_list"><?php
if (is_array($tags)) {
foreach ($tags as $t) {
printf("<div class='tag'>%s</div>", $t);
}
}
?></div>
<!-- [TAGS FORM] -->
<!-- NOTE : CONTROLS DISABLED UNTIL PAGE FULLY LOADED -->
<label for="tag_in">
Enter tags below, separate each with a comma.<br>
Click on existing tags above to remove.<br>
Remember to hit save to commit changes.
</label>
<input type="text" id="tag_in" maxlength="32" disabled/>
<input type="hidden" id="post_id" value="<?= $postID ?>"/>
<input type="button" id="tag_save" value="Save" onclick="tag.save()" disabled/>
</div>
</body>
</html>

View file

@ -1,29 +0,0 @@
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
LICENSE
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Copyright 2019 by Code Boxx
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
MORE
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Please visit https://code-boxx.com/ for more!

View file

@ -1,14 +0,0 @@
<?php
// MUTE NOTICES
error_reporting(E_ALL & ~E_NOTICE);
// DATABASE SETTINGS - CHANGE THESE TO YOUR OWN
define('DB_HOST', 'localhost');
define('DB_NAME', 'test');
define('DB_CHARSET', 'utf8');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
// AUTO FILE PATH
define('PATH_LIB', __DIR__ . DIRECTORY_SEPARATOR);
?>

View file

@ -1,179 +0,0 @@
<?php
class Tag {
/* [DATABASE HELPER FUNCTIONS] */
protected $pdo = null;
protected $stmt = null;
public $lastID = null;
function __construct() {
// __construct() : connect to the database
// PARAM : DB_HOST, DB_CHARSET, DB_NAME, DB_USER, DB_PASSWORD
// ATTEMPT CONNECT
try {
$str = "mysql:host=" . DB_HOST . ";charset=" . DB_CHARSET;
if (defined('DB_NAME')) {
$str .= ";dbname=" . DB_NAME;
}
$this->pdo = new PDO(
$str, DB_USER, DB_PASSWORD, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false
]
);
} // ERROR - CRITICAL STOP - THROW ERROR MESSAGE
catch (Exception $ex) {
print_r($ex);
die();
}
}
function __destruct() {
// __destruct() : close connection when done
if ($this->stmt !== null) {
$this->stmt = null;
}
if ($this->pdo !== null) {
$this->pdo = null;
}
}
function exec($sql, $data = null) {
// exec() : run insert, replace, update, delete query
// PARAM $sql : SQL query
// $data : array of data
try {
$this->stmt = $this->pdo->prepare($sql);
$this->stmt->execute($data);
$this->lastID = $this->pdo->lastInsertId();
} catch (Exception $ex) {
$this->error = $ex;
return false;
}
$this->stmt = null;
return true;
}
function start() {
// start() : auto-commit off
$this->pdo->beginTransaction();
}
function end($commit = 1) {
// end() : commit or roll back?
if ($commit) {
$this->pdo->commit();
} else {
$this->pdo->rollBack();
}
}
function fetchAll($sql, $cond = null, $key = null, $value = null) {
// fetchAll() : perform select query (multiple rows expected)
// PARAM $sql : SQL query
// $cond : array of conditions
// $key : sort in this $key=>data order, optional
// $value : $key must be provided. If string provided, sort in $key=>$value order. If function provided, will be a custom sort.
$result = [];
try {
$this->stmt = $this->pdo->prepare($sql);
$this->stmt->execute($cond);
// Sort in given order
if (isset($key)) {
if (isset($value)) {
if (is_callable($value)) {
while ($row = $this->stmt->fetch(PDO::FETCH_NAMED)) {
$result[$row[$key]] = $value($row);
}
} else {
while ($row = $this->stmt->fetch(PDO::FETCH_NAMED)) {
$result[$row[$key]] = $row[$value];
}
}
} else {
while ($row = $this->stmt->fetch(PDO::FETCH_NAMED)) {
$result[$row[$key]] = $row;
}
}
} // No key-value sort order
else {
$result = $this->stmt->fetchAll();
}
} catch (Exception $ex) {
$this->error = $ex;
return false;
}
// Return result
$this->stmt = null;
return count($result) == 0 ? false : $result;
}
function fetchCol($sql, $cond = null) {
// fetchCol() : yet another version of fetch that returns a flat array
// I.E. Good for one column SELECT `col` FROM `table`
$this->stmt = $this->pdo->prepare($sql);
$this->stmt->execute($cond);
$result = $this->stmt->fetchAll(PDO::FETCH_COLUMN, 0);
return count($result) == 0 ? false : $result;
}
/* [TAG FUNCTIONS] */
function getAll($id) {
// get all tags for the given post ID
$sql = "SELECT * FROM `tags` WHERE `post_id`=?";
return $this->fetchCol("SELECT `tag` FROM `tags` WHERE `post_id`=?", [$id]);
}
function search($tag) {
// search() : search for posts with the given tag
return $this->fetchAll(
"SELECT p.* FROM `tags` t LEFT JOIN posts `p` USING (`post_id`) WHERE t.`tag`=?",
[$tag],
"post_id"
);
}
function reTag($id, $tags = null) {
// reTag() : replace tags for the given post ID
// PARAM $id : post ID
// $tags : array of tags
// Auto-commit off
$this->start();
// Remove old tags first
$pass = $this->exec(
"DELETE FROM `tags` WHERE `post_id`=?", [$id]
);
// Add new tags - If any
// Might be a good idea to limit the total number of tags...
if ($pass && is_array($tags) && count($tags) > 0) {
$sql = "INSERT INTO `tags` (`post_id`, `tag`) VALUES ";
$data = [];
foreach ($tags as $t) {
$sql .= "(?,?),";
$data[] = $id;
$data[] = $t;
}
$sql = substr($sql, 0, -1);
$pass = $this->exec($sql, $data);
}
// End - commit or rollback
$this->end($pass);
return $pass;
}
}
?>

View file

@ -1,97 +0,0 @@
var tag = {
list: [], // Existing list of tags
add: function (evt) {
// tag.add() : press comma or enter to add tag
if (evt.key == "," || evt.key == "Enter") {
// Input check
var tagged = evt.key == "," ? this.value.slice(0, -1) : this.value,
error = "";
// Freaking joker empty input
if (tagged == "") {
error = "Please enter a valid tag";
}
// Check if already in tags list
if (error == "") {
if (tag.list.indexOf(tagged) != -1) {
error = tagged + " is already defined";
}
}
// OK - Create new tag
if (error == "") {
var newTag = document.createElement("div");
newTag.classList.add("tag");
newTag.innerHTML = tagged;
newTag.addEventListener("click", tag.remove);
document.getElementById("tag_list").appendChild(newTag);
tag.list.push(tagged);
this.value = "";
}
// Not OK - Show error message
else {
this.value = tagged;
alert(error);
}
}
},
remove: function () {
// tag.remove() : remove tag
// Remove tag from list array first
// var pos = tag.list.indexOf(this.innerHTML);
tag.list.splice(tag.list.indexOf(this.innerHTML), 1);
// Remove HTML tag
document.getElementById("tag_list").removeChild(this);
},
save: function () {
// tag.save() : save the tags
// DATA
var data = new FormData();
data.append('req', 'save');
data.append('post_id', document.getElementById('post_id').value);
data.append('tags', JSON.stringify(tag.list));
// AJAX
var xhr = new XMLHttpRequest();
xhr.open('POST', "2c-ajax-tag.php", true);
xhr.onload = function () {
var res = JSON.parse(this.response);
// OK
if (res.status == 1) {
alert("Save OK");
} else {
alert(res.message);
}
};
xhr.send(data);
return false;
}
};
// INIT ON WINDOW LOAD
window.addEventListener("load", function () {
// Get list of existing tags
var all = document.querySelectorAll("#tag_list div.tag");
if (all.length > 0) {
for (var t of all) {
tag.list.push(t.innerHTML);
// Attach remove listener to tags
t.addEventListener("click", tag.remove);
}
}
// Attach comma listener to input field
document.getElementById("tag_in").addEventListener("keyup", tag.add);
// Enable controls
document.getElementById("tag_in").disabled = false;
document.getElementById("tag_save").disabled = false;
});

View file

@ -1,63 +0,0 @@
/* [TAGS LIST] */
#tag_dock {
max-width: 400px;
padding: 20px;
background: #f7f7f7;
}
#tag_dock h3 {
margin: 0 0 3px 0;
color: #bf4646;
}
#tag_list {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
#tag_list div.tag {
box-sizing: border-box;
font-size: 0.9em;
width: 30%;
margin: 3px;
padding: 5px;
border: 1px solid #aaa;
background: #e8f2ff;
}
#tag_list div:hover {
background: #ffe8e8;
cursor: pointer;
}
/* [TAGS FORM] */
#tag_dock label, #tag_dock input {
box-sizing: border-box;
display: block;
width: 100%;
margin-top: 8px;
}
#tag_dock label {
font-size: 0.9em;
color: #888;
}
#tag_dock input {
padding: 8px;
font-size: 1em;
}
#tag_dock input[type=button] {
background: #2f75b7;
color: #fff;
cursor: pointer;
border: 0;
}
/* [DOES NOT MATTER] */
html, body {
font-family: arial, sans-serif;
}

View file

@ -1,10 +0,0 @@
CREATE TABLE `tags`
(
`post_id` int(11) NOT NULL,
`tag` varchar(32) NOT NULL
) ENGINE = InnoDB
DEFAULT CHARSET = latin1;
ALTER TABLE `tags`
ADD PRIMARY KEY (`post_id`, `tag`);
COMMIT;

View file

@ -1,25 +0,0 @@
CREATE TABLE `posts`
(
`post_id` int(11) NOT NULL,
`post_title` text NOT NULL,
`post_txt` text NOT NULL
) ENGINE = InnoDB
DEFAULT CHARSET = latin1;
INSERT INTO `posts` (`post_id`, `post_title`, `post_txt`)
VALUES (1, 'Stream of Rainbow',
'Can the predecessor hope the diesel? The unknown bombs whatever buried manpower. The crucial boy tenders a developed blurb. A top law clicks before a release. Why does our employee monitor the many lawyer? An ear fumes.'),
(2, 'Misty in the Wings',
'When will a competing helmet react in a noise? A paragraph acts above the agenda! A kept delight repairs a controlling crush. Can the procedure vanish? The documented rectangle inconveniences a hysterical luggage. The learned tobacco screams.'),
(3, 'Lord of the Minks',
'The undone complaint collapses past an east estate. The insulting nurse flames the era. A willed hierarchy surfaces. A tentative wife bites the consenting fence.'),
(4, 'Ice in the Scent',
'A futile pump bangs against the cider. A night stomachs a wizard. How does the mania originate? Can a reject wreck a taking battle?');
ALTER TABLE `posts`
ADD PRIMARY KEY (`post_id`);
ALTER TABLE `posts`
MODIFY `post_id` int(11) NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 5;
COMMIT;

View file

@ -353,7 +353,7 @@
<div class="column"> <div class="column">
<input type="text" class="input" name="pass" id="pass" <input type="text" class="input" name="pass" id="pass"
placeholder="<?php echo $lang['pwopt']; ?>" placeholder="<?php echo $lang['pwopt']; ?>"
value="<?php echo (isset($_POST['pass'])) ? pp_html_escape($_POST['pass']) : ''; ?>"> value="<?php echo (isset($_POST['pass'])) ? pp_html_escape($_POST['pass']) : ''; ?>" />
</div> </div>
</div> </div>
</div> </div>