From 751476c4f813af3bcef6a994510357472004ba58 Mon Sep 17 00:00:00 2001 From: shr3dd3r Date: Sat, 27 Jan 2024 01:43:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?= =?UTF-8?q?=D0=B0=20=D1=81=20=D0=BE=D0=B4=D0=BE=D0=B1=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=BC=D0=B8=20=D1=82=D0=B5=D0=B3=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/tags/index.php | 6 +++- docs/DB.md | 8 +++-- front/pages/main_nav.php | 7 ++-- front/pages/tags_viewer/page.php | 62 ++++++++++++++++++++++++++++++++ index.php | 10 +++++- 5 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 front/pages/tags_viewer/page.php diff --git a/api/tags/index.php b/api/tags/index.php index 1f65376..cb08e14 100644 --- a/api/tags/index.php +++ b/api/tags/index.php @@ -37,7 +37,11 @@ function Tags_GetListOfApproved (): array { return $result; 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; diff --git a/docs/DB.md b/docs/DB.md index 6dba1d5..9dec960 100644 --- a/docs/DB.md +++ b/docs/DB.md @@ -33,8 +33,8 @@ USE e949; CREATE TABLE users ( 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', - login VARCHAR(255) NOT NULL COMMENT 'User login', - email VARCHAR(255) NULL COMMENT 'User e-mail address', + login VARCHAR(255) NOT NULL UNIQUE COMMENT 'User login', + email VARCHAR(255) NULL UNIQUE COMMENT 'User e-mail address', password_hash BINARY(32) NOT NULL COMMENT 'User 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', @@ -78,7 +78,9 @@ CREATE TABLE invites ( uses_last SMALLINT UNSIGNED NOT NULL COMMENT 'Remaining uses of invite' ); 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' ); ``` diff --git a/front/pages/main_nav.php b/front/pages/main_nav.php index 7903c51..06f23ce 100644 --- a/front/pages/main_nav.php +++ b/front/pages/main_nav.php @@ -6,11 +6,14 @@ $MARKUP_CURRENT_PAGE = "class=\"current\""; $MARKUP_CURRENT_PAGE_LOGIN = ""; $MARKUP_CURRENT_PAGE_REGISTER = ""; +$MARKUP_CURRENT_PAGE_VIEWTAGS = ""; if ($WHAT_PAGE_IS_CURRENT["login"]) $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; +elseif ($WHAT_PAGE_IS_CURRENT["view_tags"]) + $MARKUP_CURRENT_PAGE_VIEWTAGS = $MARKUP_CURRENT_PAGE; @@ -33,7 +36,7 @@ if ($WHAT_PAGE_IS_CURRENT["register"])

Posts

| -
  • +
  • >

    Tags

  • | diff --git a/front/pages/tags_viewer/page.php b/front/pages/tags_viewer/page.php new file mode 100644 index 0000000..6a0e189 --- /dev/null +++ b/front/pages/tags_viewer/page.php @@ -0,0 +1,62 @@ + 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:
    " . $result->GetError(), "fail"); + + + +NTFY_EchoAllNotices(); + + + +?> +
    +

    Approved tags list

    + Search term: " . $_GET["s"] . "

    \n"; + + $cachedAuthorsInfo = array(); + + if (!$result->GetData()) { + echo "

    Nothing here yet

    "; + } else { + foreach ($result->GetData() as $tagInfo) { + if ($TAGS_NEED_TO_BE_FILTERED && !str_contains($tagInfo["value"], $_GET["s"])) + continue; + echo "
    \n"; + echo "

    " . $tagInfo["value"] . "

    \n"; + echo "

    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) . " (user deleted)"; + } else { + $cachedAuthorsInfo[$aid] = "" . $uinfo->GetData()["login"] . ""; + } + } + echo $cachedAuthorsInfo[$aid]; + echo "

    \n
    \n"; + } + } + ?> +
    diff --git a/index.php b/index.php index f1a2cb6..3c23161 100644 --- a/index.php +++ b/index.php @@ -27,11 +27,19 @@ else $WHAT_PAGE_IS_CURRENT = array( "main" => false, "login" => false, - "register" => false + "register" => false, + "view_tags" => false ); // Picking current 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 case "register": $WHAT_PAGE_IS_CURRENT["register"] = true;