From 4db4ab9cf07c852048361ba1a4cd1af2108ff682 Mon Sep 17 00:00:00 2001 From: sshscp15 <92885280+sshscp15@users.noreply.github.com> Date: Mon, 20 Jun 2022 15:09:55 -0300 Subject: [PATCH] simple catalog support for moderators --- inc/config.php | 1 + inc/mod/pages.php | 12 ++++++++++++ mod.php | 1 + templates/index.html | 2 +- templates/themes/catalog/catalog.html | 4 +++- templates/themes/catalog/theme.php | 23 ++++++++++++++++++----- templates/thread.html | 2 +- 7 files changed, 37 insertions(+), 8 deletions(-) diff --git a/inc/config.php b/inc/config.php index 401a01db..59ccf66a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1207,6 +1207,7 @@ // Location of files. $config['file_index'] = 'index.html'; $config['file_page'] = '%d.html'; // NB: page is both an index page and a thread + $config['file_catalog'] = 'catalog.html'; $config['file_page50'] = '%d+50.html'; $config['file_page_slug'] = '%d-%s.html'; $config['file_page50_slug'] = '%d-%s+50.html'; diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 6f8e8f14..02d39ea4 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -734,6 +734,18 @@ function mod_board_log($board, $page_no = 1, $hide_names = false, $public = fals mod_page(_('Board log'), 'mod/log.html', array('logs' => $logs, 'count' => $count, 'board' => $board, 'hide_names' => $hide_names, 'public' => $public)); } +function mod_view_catalog($boardName) { + global $config, $mod; + require_once($config['dir']['themes'].'/catalog/theme.php'); + $settings = array(); + $settings['boards'] = $boardName; + $settings['update_on_posts'] = true; + $settings['title'] = 'Catalog'; + $settings['use_tooltipster'] = true; + $catalog = new Catalog(); + echo $catalog->build($settings, $boardName, true); +} + function mod_view_board($boardName, $page_no = 1) { global $config, $mod; diff --git a/mod.php b/mod.php index 38b9e07a..72095304 100644 --- a/mod.php +++ b/mod.php @@ -102,6 +102,7 @@ $pages = array( // This should always be at the end: '/(\%b)/' => 'view_board', '/(\%b)/' . preg_quote($config['file_index'], '!') => 'view_board', + '/(\%b)/' . preg_quote($config['file_catalog'], '!') => 'view_catalog', '/(\%b)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_board', '/(\%b)/' . preg_quote($config['dir']['res'], '!') . str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '!')) => 'view_thread50', diff --git a/templates/index.html b/templates/index.html index 24b2b1d7..e606f9f6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -80,7 +80,7 @@ [{{ page.num }}]{% if loop.last %} {% endif %} {% endfor %} {{ btn.next }} {% if config.catalog_link %} - | {% trans %}Catalog{% endtrans %} + | {% trans %}Catalog{% endtrans %} {% endif %} diff --git a/templates/themes/catalog/catalog.html b/templates/themes/catalog/catalog.html index 3cbc1f17..f3fe981c 100644 --- a/templates/themes/catalog/catalog.html +++ b/templates/themes/catalog/catalog.html @@ -14,7 +14,9 @@ {{ boardlist.top }} {{ settings.title }} (/{{ board }}/) - {{ settings.subtitle }} + {{ settings.subtitle }} + {% if mod %}{% trans %}Return to dashboard{% endtrans %}{% endif %} + {% trans 'Sort by' %}: diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index b25abf32..a439dcdb 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -42,7 +42,7 @@ // Wrap functions in a class so they don't interfere with normal Tinyboard operations class Catalog { - public function build($settings, $board_name) { + public function build($settings, $board_name, $mod = false) { global $config, $board; if (!isset($board) || $board['uri'] != $board_name) { @@ -62,7 +62,11 @@ $board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error()); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { - $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post); + + if ($mod) + $post['link'] = $config['root'] . $config['file_mod'] . '?/'. $board['dir'] . $config['dir']['res'] . link_for($post); + else + $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post); $post['board_name'] = $board['name']; if ($post['embed'] && preg_match('/^https?:\/\/(\w+\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) { @@ -109,7 +113,9 @@ $config['additional_javascript'][] = $s; } - file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', Array( + $link = ($mod) ? $config['root'] . $config['file_mod'] . '?/' . $board['dir'] : $config['root'] . $board['dir']; + + $element = Element('themes/catalog/catalog.html', Array( 'settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), @@ -117,8 +123,14 @@ 'recent_posts' => $recent_posts, 'stats' => $stats, 'board' => $board_name, - 'link' => $config['root'] . $board['dir'] - ))); + 'link' => $link, + 'mod' => $mod + )); + + if ($mod) { + return $element; + } else { + file_write($config['dir']['home'] . $board_name . '/catalog.html', $element); file_write($config['dir']['home'] . $board_name . '/index.rss', Element('themes/catalog/index.rss', Array( 'config' => $config, @@ -126,4 +138,5 @@ 'board' => $board ))); } + } }; diff --git a/templates/thread.html b/templates/thread.html index 48bba51c..bc338d8d 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -63,7 +63,7 @@ [{% trans %}Return{% endtrans %}] [{% trans %}Go to top{% endtrans %}] {% if config.catalog_link %} - [{% trans %}Catalog{% endtrans %}] + {% trans %}Catalog{% endtrans %} {% endif %}
{% trans %}Return to dashboard{% endtrans %}