mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 06:30:07 +01:00
Fix tags on discover.php
This commit is contained in:
parent
9ac3a2ab4e
commit
2c7b3cb877
4 changed files with 40 additions and 32 deletions
|
@ -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 .= '<a href="/archive?q=' . urlencode($tag) . '"><span class="' . $tagcolor . '">' . pp_html_escape(ucfirst($tag)) . '</span></a>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function transformDataRow($row) {
|
||||
$titleHtml = '<a href="/' . urlencode($row[0]) . '">' . pp_html_escape($row[1]) . '</a>';
|
||||
$authorHtml = '<a href="' . urlencode($row[2]) . '">' . pp_html_escape($row[2]) . '</a>';
|
||||
|
|
|
@ -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'])
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -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 .= '<a href="/archive?q=' . urlencode($tag) . '"><span class="' . $tagcolor . '">' . pp_html_escape(ucfirst($tag)) . '</span></a>';
|
||||
}
|
||||
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, ?");
|
||||
|
|
|
@ -55,8 +55,8 @@
|
|||
<time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_time'] ?></time>
|
||||
</p>
|
||||
<?php
|
||||
if (!empty($paste['tags'])) {
|
||||
echo sandwitch($paste['tags']);
|
||||
if (count($paste['tags']) !== 0) {
|
||||
echo tagsToHtml($paste['tags']);
|
||||
} else {
|
||||
echo ' <span class="tag is-warning">No tags</span>';
|
||||
}
|
||||
|
@ -93,8 +93,8 @@
|
|||
<time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_time'] ?></time>
|
||||
</p>
|
||||
<?php
|
||||
if (!empty($paste['tags'])) {
|
||||
echo sandwitch($paste['tags']);
|
||||
if (count($paste['tags']) !== 0) {
|
||||
echo tagsToHtml($paste['tags']);
|
||||
} else {
|
||||
echo ' <span class="tag is-warning">No tags</span>';
|
||||
}
|
||||
|
@ -132,8 +132,8 @@
|
|||
<time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_time'] ?></time>
|
||||
</p>
|
||||
<?php
|
||||
if (!empty($paste['tags'])) {
|
||||
echo sandwitch($paste['tags']);
|
||||
if (count($paste['tags']) !== 0) {
|
||||
echo tagsToHtml($paste['tags']);
|
||||
} else {
|
||||
echo ' <span class="tag is-warning">No tags</span>';
|
||||
}
|
||||
|
@ -171,8 +171,8 @@
|
|||
<time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_update_time'] ?></time>
|
||||
</p>
|
||||
<?php
|
||||
if (!empty($paste['tags'])) {
|
||||
echo sandwitch($paste['tags']);
|
||||
if (count($paste['tags']) !== 0) {
|
||||
echo tagsToHtml($paste['tags']);
|
||||
} else {
|
||||
echo ' <span class="tag is-warning">No tags</span>';
|
||||
}
|
||||
|
@ -210,8 +210,8 @@
|
|||
<time datetime="<?= $paste['time'] ?>"><?= $paste['friendly_time'] ?></time>
|
||||
</p>
|
||||
<?php
|
||||
if (!empty($paste['tags'])) {
|
||||
echo sandwitch($paste['tags']);
|
||||
if (count($paste['tags']) !== 0) {
|
||||
echo tagsToHtml($paste['tags']);
|
||||
} else {
|
||||
echo ' <span class="tag is-warning">No tags</span>';
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue