Страница с одобренными тегами

This commit is contained in:
2024-01-27 01:43:27 +03:00
parent 93a2286d46
commit 751476c4f8
5 changed files with 86 additions and 7 deletions

View File

@@ -37,7 +37,11 @@ function Tags_GetListOfApproved (): array {
return $result; return $result;
while ($row = $d->fetch_array()) { while ($row = $d->fetch_array()) {
$result[] = $row["value"]; $result[] = array(
"value" => $row["value"],
"author_id" => $row["author_id"],
"added_at" => $row["added_at"]
);
} }
return $result; return $result;

View File

@@ -33,8 +33,8 @@ USE e949;
CREATE TABLE users ( CREATE TABLE users (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier of user', id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier of user',
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When account was created', created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When account was created',
login VARCHAR(255) NOT NULL COMMENT 'User login', login VARCHAR(255) NOT NULL UNIQUE COMMENT 'User login',
email VARCHAR(255) NULL COMMENT 'User e-mail address', email VARCHAR(255) NULL UNIQUE COMMENT 'User e-mail address',
password_hash BINARY(32) NOT NULL COMMENT 'User password hash', password_hash BINARY(32) NOT NULL COMMENT 'User password hash',
salt VARCHAR(8) NOT NULL COMMENT 'User salt, used for password hash', salt VARCHAR(8) NOT NULL COMMENT 'User salt, used for password hash',
avatar_path VARCHAR(255) NULL COMMENT 'Path or URL to avatar picture', avatar_path VARCHAR(255) NULL COMMENT 'Path or URL to avatar picture',
@@ -78,7 +78,9 @@ CREATE TABLE invites (
uses_last SMALLINT UNSIGNED NOT NULL COMMENT 'Remaining uses of invite' uses_last SMALLINT UNSIGNED NOT NULL COMMENT 'Remaining uses of invite'
); );
CREATE TABLE approved_tags ( CREATE TABLE approved_tags (
value VARCHAR(255) NOT NULL COMMENT 'The tag itself' value VARCHAR(255) NOT NULL UNIQUE COMMENT 'The tag itself',
author_id INT UNSIGNED NULL COMMENT 'ID of user who added this tag to list of approved',
added_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When this tag was added'
); );
``` ```

View File

@@ -6,11 +6,14 @@
$MARKUP_CURRENT_PAGE = "class=\"current\""; $MARKUP_CURRENT_PAGE = "class=\"current\"";
$MARKUP_CURRENT_PAGE_LOGIN = ""; $MARKUP_CURRENT_PAGE_LOGIN = "";
$MARKUP_CURRENT_PAGE_REGISTER = ""; $MARKUP_CURRENT_PAGE_REGISTER = "";
$MARKUP_CURRENT_PAGE_VIEWTAGS = "";
if ($WHAT_PAGE_IS_CURRENT["login"]) if ($WHAT_PAGE_IS_CURRENT["login"])
$MARKUP_CURRENT_PAGE_LOGIN = $MARKUP_CURRENT_PAGE; $MARKUP_CURRENT_PAGE_LOGIN = $MARKUP_CURRENT_PAGE;
if ($WHAT_PAGE_IS_CURRENT["register"]) elseif ($WHAT_PAGE_IS_CURRENT["register"])
$MARKUP_CURRENT_PAGE_REGISTER = $MARKUP_CURRENT_PAGE; $MARKUP_CURRENT_PAGE_REGISTER = $MARKUP_CURRENT_PAGE;
elseif ($WHAT_PAGE_IS_CURRENT["view_tags"])
$MARKUP_CURRENT_PAGE_VIEWTAGS = $MARKUP_CURRENT_PAGE;
@@ -33,7 +36,7 @@ if ($WHAT_PAGE_IS_CURRENT["register"])
<p><a title="A paginated list of every post" href="./?do=search_posts">Posts</p></a> <p><a title="A paginated list of every post" href="./?do=search_posts">Posts</p></a>
</li> </li>
<span>|</span> <span>|</span>
<li> <li <?php echo $MARKUP_CURRENT_PAGE_VIEWTAGS; ?>>
<p><a title="A paginated list of every tag" href="./?do=view_tags">Tags</p></a> <p><a title="A paginated list of every tag" href="./?do=view_tags">Tags</p></a>
</li> </li>
<span>|</span> <span>|</span>

View File

@@ -0,0 +1,62 @@
<?php
// Approved tags list
// Includes
require_once("api/_config.php");
require_once("api/user/index.php");
require_once("api/tags/index.php");
require_once("front/pages/main_nav.php");
require_once("front/notifications.php");
$TAGS_NEED_TO_BE_FILTERED = false;
if (isset($_GET["s"])) {
if (strlen($_GET["s"]) > 0 && strlen($_GET["s"]) < $Config["posting"]["tags"]["max_single_length"])
$TAGS_NEED_TO_BE_FILTERED = true;
}
$result = Tags_GetListOfApproved_Method();
if ($result->IsError())
NTFY_AddNotice("Error occured while trying to get tags list:<br>" . $result->GetError(), "fail");
NTFY_EchoAllNotices();
?>
<div class="visualbox">
<h1>Approved tags list</h1>
<?php
if ($TAGS_NEED_TO_BE_FILTERED)
echo "<p style=\"margin-bottom: 15px;\"><b>Search term:</b> " . $_GET["s"] . "</p>\n";
$cachedAuthorsInfo = array();
if (!$result->GetData()) {
echo "<h2 style=\"color: gray; font-style: italic;\">Nothing here yet</h2>";
} else {
foreach ($result->GetData() as $tagInfo) {
if ($TAGS_NEED_TO_BE_FILTERED && !str_contains($tagInfo["value"], $_GET["s"]))
continue;
echo "<div style=\"display: inline-block; margin-right: 20px; margin-bottom: 10px;\">\n";
echo "<p>" . $tagInfo["value"] . "</p>\n";
echo "<p style=\"font-size: 70%\">Added by: ";
$aid = $tagInfo["author_id"];
if (!isset($cachedAuthorsInfo[$aid])) {
$uinfo = User_GetInfoByID($aid);
if ($uinfo->IsError()) { // Seems like no such user id
$cachedAuthorsInfo[$aid] = strval($aid) . " <i>(user deleted)</i>";
} else {
$cachedAuthorsInfo[$aid] = "<a href=\"./?do=user_info&id=" . strval($aid) . "\">" . $uinfo->GetData()["login"] . "</a>";
}
}
echo $cachedAuthorsInfo[$aid];
echo "</p>\n</div>\n";
}
}
?>
</div>

View File

@@ -27,11 +27,19 @@ else
$WHAT_PAGE_IS_CURRENT = array( $WHAT_PAGE_IS_CURRENT = array(
"main" => false, "main" => false,
"login" => false, "login" => false,
"register" => false "register" => false,
"view_tags" => false
); );
// Picking current page // Picking current page
switch ($PICKED_PAGE) { switch ($PICKED_PAGE) {
// Approved tags viewer
case "view_tags":
$WHAT_PAGE_IS_CURRENT["view_tags"] = true;
$PAGE_TITLE = "Approved tags list";
$PAGE_STYLE = "front/styles/main.css";
$PAGE_FILE = "front/pages/tags_viewer/page.php";
break;
// Registration page // Registration page
case "register": case "register":
$WHAT_PAGE_IS_CURRENT["register"] = true; $WHAT_PAGE_IS_CURRENT["register"] = true;