From 73a2fad938997f79aa7d5305f3dd84dca01a5926 Mon Sep 17 00:00:00 2001 From: Floorb <132411956+Neetpone@users.noreply.github.com> Date: Thu, 2 Sep 2021 08:55:14 -0400 Subject: [PATCH] Experimental SSP again --- api/ajax_pastes.php | 32 +++++++++++++++++-------------- includes/Models/Tag.php | 15 ++------------- includes/NonRetardedSSP.class.php | 16 ++++++++-------- includes/common.php | 2 ++ theme/bulma/discover.php | 2 +- theme/bulma/view.php | 6 +----- 6 files changed, 32 insertions(+), 41 deletions(-) diff --git a/api/ajax_pastes.php b/api/ajax_pastes.php index 9d56d55..c028d74 100644 --- a/api/ajax_pastes.php +++ b/api/ajax_pastes.php @@ -1,14 +1,17 @@ ' . pp_html_escape($row[1]) . ''; - $authorHtml = '' . pp_html_escape($row[2]) . ''; - $tagsHtml = tagsToHtml($row[3]); +function transformPaste(Paste $paste) { + $titleHtml = '' . pp_html_escape($paste->title) . ''; + $authorHtml = '' . pp_html_escape($paste->user->username) . ''; + $tagsHtml = '';//tagsToHtml($row[3]); return [ $titleHtml, @@ -17,18 +20,19 @@ function transformDataRow($row) { ]; } +$pastes = Paste::with([ + 'user' => function($query) { + $query->select('users.id', 'username'); + }, + 'tags' => function($query) { + $query->select('tags.id', 'name', 'slug'); + } + ])->select(['id', 'user_id', 'title']); + $data = NonRetardedSSP::run( - $conn, $_GET, - 'SELECT COUNT(*) FROM pastes WHERE pastes.visible = \'0\' AND pastes.title != \'\'', - 'SELECT pastes.id AS id, title, users.username, GROUP_CONCAT(tags.name SEPARATOR \',\') AS tagsys FROM pastes - INNER JOIN users ON users.id = pastes.user_id - INNER JOIN paste_taggings on pastes.id = paste_taggings.paste_id - INNER JOIN tags ON tags.id = paste_taggings.tag_id - WHERE pastes.visible = \'0\' AND pastes.title != \'\' - GROUP BY pastes.id' + $conn, $_GET, $pastes ); - -$data['data'] = array_map('transformDataRow', $data['data']); +$data['data'] = $data['data']->map('transformPaste'); echo json_encode($data); diff --git a/includes/Models/Tag.php b/includes/Models/Tag.php index 801072b..7d70f0b 100644 --- a/includes/Models/Tag.php +++ b/includes/Models/Tag.php @@ -5,6 +5,8 @@ use Illuminate\Database\Eloquent\Model; class Tag extends Model { protected $table = 'tags'; + protected $fillable = ['name', 'slug']; + public $timestamps = false; public static function getOrCreateByName(string $name) : Tag { $name = Tag::cleanTagName($name); @@ -19,19 +21,6 @@ class Tag extends Model { ]); } - public static function replacePasteTags(DatabaseHandle $conn, int $pasteId, array $tags) { - $conn->query('DELETE FROM paste_taggings WHERE paste_id = ?', [$pasteId]); - - foreach ($tags as $tagName) { - $tag = Tag::getOrCreateByName($conn, $tagName); - - $conn->query('INSERT INTO paste_taggings (paste_id, tag_id) VALUES (?, ?)', [$pasteId, $tag->id]); - } - - // FIXME: We need to get rid of tagsys. - $conn->query('UPDATE pastes SET tagsys = ? WHERE id = ?', [implode(',', $tags), $pasteId]); - } - /** * Normalize a tag name, which involves downcasing it, normalizing smart quotes, trimming the string, and * normalizing runs of whitespace to a single space. diff --git a/includes/NonRetardedSSP.class.php b/includes/NonRetardedSSP.class.php index cd97271..3f50912 100644 --- a/includes/NonRetardedSSP.class.php +++ b/includes/NonRetardedSSP.class.php @@ -1,31 +1,31 @@ querySelectOne($countQuery, [], PDO::FETCH_NUM)[0]; + $recordsTotal = $builder->count(); /* build query */ $params = []; if ($length != 0) { - $query .= ' LIMIT ?'; - array_push($params, $length); + $builder = $builder->limit($length); if ($start != 0) { - $query .= ' OFFSET ?'; - array_push($params, $start); + $builder = $builder->offset($start); } } /* fire it off */ - $stmt = $conn->query($query, $params); - $data = $stmt->fetchAll(PDO::FETCH_NUM); + $data = $builder->get(); return [ 'draw' => $draw, diff --git a/includes/common.php b/includes/common.php index 47e46e7..4151e8b 100644 --- a/includes/common.php +++ b/includes/common.php @@ -8,6 +8,8 @@ require_once(__DIR__ . '/functions.php'); require_once(__DIR__ . '/DatabaseHandle.class.php'); use Illuminate\Database\Capsule\Manager as Capsule; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Event; use PonePaste\Helpers\SessionHelper; use PonePaste\Models\Paste; use PonePaste\Models\User; diff --git a/theme/bulma/discover.php b/theme/bulma/discover.php index b5d8486..07e3d57 100644 --- a/theme/bulma/discover.php +++ b/theme/bulma/discover.php @@ -221,7 +221,7 @@ const tabSystem = { init() { document.querySelectorAll('.tabs-menu').forEach(tabMenu => { - Array.from(tabMenu.children).forEach((child, ind) => { + Array.from(tabMenu.children).forEach(child => { child.addEventListener('click', () => { tabSystem.toggle(child.dataset.target); }); diff --git a/theme/bulma/view.php b/theme/bulma/view.php index ce39e29..da60a78 100644 --- a/theme/bulma/view.php +++ b/theme/bulma/view.php @@ -163,11 +163,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was

- - Guest - - By - + By user->username) ?>
Created: