From 2c7b3cb877a72d3e59002fbf88b27e58d3fdd410 Mon Sep 17 00:00:00 2001 From: Floorb <132411956+Neetpone@users.noreply.github.com> Date: Tue, 17 Aug 2021 13:13:04 -0400 Subject: [PATCH] Fix tags on discover.php --- api/ajax_pastes.php | 21 --------------------- discover.php | 5 ++++- includes/functions.php | 26 ++++++++++++++++++++++++++ theme/bulma/discover.php | 20 ++++++++++---------- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/api/ajax_pastes.php b/api/ajax_pastes.php index 83a73c1..17c64ad 100644 --- a/api/ajax_pastes.php +++ b/api/ajax_pastes.php @@ -6,27 +6,6 @@ define('IN_PONEPASTE', 1); require_once('../includes/common.php'); require_once('../includes/NonRetardedSSP.class.php'); -function tagsToHtml(string $tags) : string { - $output = ""; - $tagsSplit = explode(",", $tags); - foreach ($tagsSplit as $tag) { - if (stripos($tag, 'nsfw') !== false) { - $tag = strtoupper($tag); - $tagcolor = "tag is-danger"; - } elseif (stripos($tag, 'SAFE') !== false) { - $tag = strtoupper($tag); - $tagcolor = "tag is-success"; - } elseif (str_contains($tag, '/')) { - $tagcolor = "tag is-primary"; - } else { - $tagcolor = "tag is-info"; - } - $output .= '' . pp_html_escape(ucfirst($tag)) . ''; - } - return $output; -} - - function transformDataRow($row) { $titleHtml = '' . pp_html_escape($row[1]) . ''; $authorHtml = '' . pp_html_escape($row[2]) . ''; diff --git a/discover.php b/discover.php index 61997cf..e6b1e9a 100644 --- a/discover.php +++ b/discover.php @@ -21,6 +21,8 @@ header('Content-Type: text/html; charset=utf-8'); function transformPasteRow(array $row) : array { + global $conn; + return [ 'id' => $row['id'], 'title' => $row['title'], @@ -28,7 +30,8 @@ function transformPasteRow(array $row) : array { 'time' => $row['created_at'], 'time_update' => $row['updated_at'], 'friendly_update_time' => friendlyDateDifference(new DateTime($row['updated_at']), new DateTime()), - 'friendly_time' => friendlyDateDifference(new DateTime($row['created_at']), new DateTime()) + 'friendly_time' => friendlyDateDifference(new DateTime($row['created_at']), new DateTime()), + 'tags' => getPasteTags($conn, $row['id']) ]; } diff --git a/includes/functions.php b/includes/functions.php index db2566d..8707655 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -72,6 +72,32 @@ function sandwitch($str) { } +function tagsToHtml(string | array $tags) : string { + $output = ""; + if (is_array($tags)) { + $tagsSplit = array_map(function($tag) { return $tag['name']; }, $tags); + } else { + $tagsSplit = explode(",", $tags); + } + + foreach ($tagsSplit as $tag) { + if (stripos($tag, 'nsfw') !== false) { + $tag = strtoupper($tag); + $tagcolor = "tag is-danger"; + } elseif (stripos($tag, 'SAFE') !== false) { + $tag = strtoupper($tag); + $tagcolor = "tag is-success"; + } elseif (str_contains($tag, '/')) { + $tagcolor = "tag is-primary"; + } else { + $tagcolor = "tag is-info"; + } + $output .= '' . pp_html_escape(ucfirst($tag)) . ''; + } + return $output; +} + + function getevent($conn, $event_name, $count) { $query = $conn->prepare("SELECT id, visible, title, date, now_time, views, member FROM pastes WHERE visible='1' AND tagsys LIKE '%?%' ORDER BY RAND () LIMIT 0, ?"); diff --git a/theme/bulma/discover.php b/theme/bulma/discover.php index 39041f9..e56cc1e 100644 --- a/theme/bulma/discover.php +++ b/theme/bulma/discover.php @@ -55,8 +55,8 @@

No tags'; } @@ -93,8 +93,8 @@

No tags'; } @@ -132,8 +132,8 @@

No tags'; } @@ -171,8 +171,8 @@

No tags'; } @@ -210,8 +210,8 @@

No tags'; }