summaryrefslogtreecommitdiff
path: root/templates/themes/catalog
diff options
context:
space:
mode:
authorAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:30:13 +1000
committerAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:30:13 +1000
commit2c69095a1edf7474073451285238659d0f62ce3f (patch)
tree5dee476605402c66dc2853d0836b29f6aedae62b /templates/themes/catalog
parente9a61e2fbbd930eaa80d6a5f33420cedc59d748c (diff)
PHP8.1 fixes from Rector
Diffstat (limited to 'templates/themes/catalog')
-rw-r--r--templates/themes/catalog/info.php87
-rw-r--r--templates/themes/catalog/theme.php94
2 files changed, 48 insertions, 133 deletions
diff --git a/templates/themes/catalog/info.php b/templates/themes/catalog/info.php
index bc0e7eb5..cf0d42ab 100644
--- a/templates/themes/catalog/info.php
+++ b/templates/themes/catalog/info.php
@@ -1,96 +1,37 @@
<?php
- $theme = array();
+ $theme = [];
// Theme name
- $theme['name'] = 'Catalog';
+ $theme['name'] = \Catalog::class;
// Description (you can use Tinyboard markup here)
$theme['description'] = 'Show a post catalog.';
$theme['version'] = 'v0.2.1';
// Theme configuration
- $theme['config'] = Array();
+ $theme['config'] = [];
- $theme['config'][] = Array(
- 'title' => 'Title',
- 'name' => 'title',
- 'type' => 'text',
- 'default' => 'Catalog'
- );
+ $theme['config'][] = ['title' => 'Title', 'name' => 'title', 'type' => 'text', 'default' => \Catalog::class];
$__boards = listBoards();
- $__default_boards = Array();
+ $__default_boards = [];
foreach ($__boards as $__board)
$__default_boards[] = $__board['uri'];
- $theme['config'][] = Array(
- 'title' => 'Included boards',
- 'name' => 'boards',
- 'type' => 'text',
- 'comment' => '(space seperated)',
- 'default' => implode(' ', $__default_boards)
- );
+ $theme['config'][] = ['title' => 'Included boards', 'name' => 'boards', 'type' => 'text', 'comment' => '(space seperated)', 'default' => implode(' ', $__default_boards)];
- $theme['config'][] = Array(
- 'title' => 'Update on new posts',
- 'name' => 'update_on_posts',
- 'type' => 'checkbox',
- 'default' => false,
- 'comment' => 'Without this checked, the catalog only updates on new threads.'
- );
+ $theme['config'][] = ['title' => 'Update on new posts', 'name' => 'update_on_posts', 'type' => 'checkbox', 'default' => false, 'comment' => 'Without this checked, the catalog only updates on new threads.'];
- $theme['config'][] = Array(
- 'title' => 'Enable Ukko catalog',
- 'name' => 'enable_ukko',
- 'type' => 'checkbox',
- 'default' => false,
- 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko theme to be enabled.'
- );
+ $theme['config'][] = ['title' => 'Enable Ukko catalog', 'name' => 'enable_ukko', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko theme to be enabled.'];
- $theme['config'][] = Array(
- 'title' => 'Enable Ukko2 catalog',
- 'name' => 'enable_ukko2',
- 'type' => 'checkbox',
- 'default' => false,
- 'comment' => 'Enable catalog for the Ukko2 theme. This requires the Ukko2 theme to be enabled.'
- );
+ $theme['config'][] = ['title' => 'Enable Ukko2 catalog', 'name' => 'enable_ukko2', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Ukko2 theme. This requires the Ukko2 theme to be enabled.'];
- $theme['config'][] = Array(
- 'title' => 'Enable Ukko3 catalog',
- 'name' => 'enable_ukko3',
- 'type' => 'checkbox',
- 'default' => false,
- 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko3 theme to be enabled.'
- );
- $theme['config'][] = Array(
- 'title' => 'Enable Ukko4 catalog',
- 'name' => 'enable_ukko4',
- 'type' => 'checkbox',
- 'default' => false,
- 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko4 theme to be enabled.'
- );
+ $theme['config'][] = ['title' => 'Enable Ukko3 catalog', 'name' => 'enable_ukko3', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko3 theme to be enabled.'];
+ $theme['config'][] = ['title' => 'Enable Ukko4 catalog', 'name' => 'enable_ukko4', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko4 theme to be enabled.'];
- $theme['config'][] = Array(
- 'title' => 'Enable Rand catalog',
- 'name' => 'enable_rand',
- 'type' => 'checkbox',
- 'default' => false,
- 'comment' => 'Enable catalog for the Rand theme. This requires the Rand theme to be enabled.'
- );
- $theme['config'][] = Array(
- 'title' => 'Use tooltipster',
- 'name' => 'use_tooltipster',
- 'type' => 'checkbox',
- 'default' => true,
- 'comment' => 'Check this if you wish to show a nice tooltip with info about the thread on mouse over.'
- );
+ $theme['config'][] = ['title' => 'Enable Rand catalog', 'name' => 'enable_rand', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Rand theme. This requires the Rand theme to be enabled.'];
+ $theme['config'][] = ['title' => 'Use tooltipster', 'name' => 'use_tooltipster', 'type' => 'checkbox', 'default' => true, 'comment' => 'Check this if you wish to show a nice tooltip with info about the thread on mouse over.'];
- $theme['config'][] = Array(
- 'title' => 'Base URL',
- 'name' => 'base_url',
- 'type' => 'text',
- 'default' => 'http://test.com',
- 'comment' => '(eg. "http://test.com")'
- );
+ $theme['config'][] = ['title' => 'Base URL', 'name' => 'base_url', 'type' => 'text', 'default' => 'http://test.com', 'comment' => '(eg. "http://test.com")'];
// Unique function name for building everything
$theme['build_function'] = 'catalog_build';
diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php
index 1b55d56e..f4c59681 100644
--- a/templates/themes/catalog/theme.php
+++ b/templates/themes/catalog/theme.php
@@ -5,7 +5,7 @@
global $config;
$b = new Catalog($settings);
- $boards = explode(' ', $settings['boards']);
+ $boards = explode(' ', (string) $settings['boards']);
// Possible values for $action:
// - all (rebuild everything, initialization)
@@ -17,7 +17,7 @@
foreach ($boards as $board) {
$b = new Catalog($settings);
- $action = generation_strategy("sb_catalog", array($board));
+ $action = generation_strategy("sb_catalog", [$board]);
if ($action == 'delete') {
file_unlink($config['dir']['home'] . $board . '/catalog.html');
file_unlink($config['dir']['home'] . $board . '/index.rss');
@@ -30,7 +30,7 @@
|| $action == 'sticky' || ($action == 'lock' && in_array($board, $boards))) {
$b = new Catalog($settings);
- $action = generation_strategy("sb_catalog", array($board));
+ $action = generation_strategy("sb_catalog", [$board]);
if ($action == 'delete') {
file_unlink($config['dir']['home'] . $board . '/catalog.html');
file_unlink($config['dir']['home'] . $board . '/index.rss');
@@ -82,13 +82,12 @@
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
class Catalog {
- private $settings;
// Cache for threads from boards that have already been processed
- private $threadsCache = array();
+ private array $threadsCache = [];
- public function __construct($settings) {
- $this->settings = $settings;
- }
+ public function __construct(private $settings)
+ {
+ }
/**
* Build and save the HTML of the catalog for the Ukko theme
@@ -97,10 +96,10 @@
global $config;
$ukkoSettings = themeSettings('ukko');
- $queries = array();
- $threads = array();
+ $queries = [];
+ $threads = [];
- $exclusions = explode(' ', $ukkoSettings['exclude']);
+ $exclusions = explode(' ', (string) $ukkoSettings['exclude']);
$boards = array_diff(listBoards(true), $exclusions);
foreach ($boards as $b) {
@@ -119,9 +118,7 @@
}
// Sort in bump order
- usort($threads, function($a, $b) {
- return strcmp($b['bump'], $a['bump']);
- });
+ usort($threads, fn($a, $b) => strcmp((string) $b['bump'], (string) $a['bump']));
// Generate data for the template
$recent_posts = $this->generateRecentPosts($threads);
@@ -134,10 +131,10 @@
public function buildUkko2() {
global $config;
$ukkoSettings = themeSettings('ukko2');
- $queries = array();
- $threads = array();
+ $queries = [];
+ $threads = [];
- $inclusions = explode(' ', $ukkoSettings['include']);
+ $inclusions = explode(' ', (string) $ukkoSettings['include']);
$boards = array_intersect(listBoards(true), $inclusions);
foreach ($boards as $b) {
@@ -156,9 +153,7 @@
}
// Sort in bump order
- usort($threads, function($a, $b) {
- return strcmp($b['bump'], $a['bump']);
- });
+ usort($threads, fn($a, $b) => strcmp((string) $b['bump'], (string) $a['bump']));
// Generate data for the template
$recent_posts = $this->generateRecentPosts($threads);
@@ -173,10 +168,10 @@
global $config;
$ukkoSettings = themeSettings('ukko3');
- $queries = array();
- $threads = array();
+ $queries = [];
+ $threads = [];
- $inclusions = explode(' ', $ukkoSettings['include']);
+ $inclusions = explode(' ', (string) $ukkoSettings['include']);
$boards = array_intersect(listBoards(true), $inclusions);
foreach ($boards as $b) {
@@ -195,9 +190,7 @@
}
// Sort in bump order
- usort($threads, function($a, $b) {
- return strcmp($b['bump'], $a['bump']);
- });
+ usort($threads, fn($a, $b) => strcmp((string) $b['bump'], (string) $a['bump']));
// Generate data for the template
$recent_posts = $this->generateRecentPosts($threads);
@@ -212,10 +205,10 @@
global $config;
$ukkoSettings = themeSettings('ukko4');
- $queries = array();
- $threads = array();
+ $queries = [];
+ $threads = [];
- $exclusions = explode(' ', $ukkoSettings['exclude']);
+ $exclusions = explode(' ', (string) $ukkoSettings['exclude']);
$boards = array_diff(listBoards(true), $exclusions);
foreach ($boards as $b) {
@@ -234,9 +227,7 @@
}
// Sort in bump order
- usort($threads, function($a, $b) {
- return strcmp($b['bump'], $a['bump']);
- });
+ usort($threads, fn($a, $b) => strcmp((string) $b['bump'], (string) $a['bump']));
// Generate data for the template
$recent_posts = $this->generateRecentPosts($threads);
@@ -250,10 +241,10 @@
global $config;
$randSettings = themeSettings('rand');
- $queries = array();
- $threads = array();
+ $queries = [];
+ $threads = [];
- $exclusions = explode(' ', $randSettings['exclude']);
+ $exclusions = explode(' ', (string) $randSettings['exclude']);
$boards = array_diff(listBoards(true), $exclusions);
foreach ($boards as $b) {
@@ -272,9 +263,7 @@
}
// Sort in bump order
- usort($threads, function($a, $b) {
- return strcmp($b['bump'], $a['bump']);
- });
+ usort($threads, fn($a, $b) => strcmp((string) $b['bump'], (string) $a['bump']));
// Generate data for the template
$recent_posts = $this->generateRecentPosts($threads);
@@ -321,7 +310,7 @@
private function generateRecentPosts($threads) {
global $config, $board;
- $posts = array();
+ $posts = [];
foreach ($threads as $post) {
if ($board['uri'] !== $post['board']) {
openBoard($post['board']);
@@ -330,16 +319,16 @@
$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)) {
+ if ($post['embed'] && preg_match('/^https?:\/\/(\w+\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9\-_]{10,11})(&.+)?$/i', (string) $post['embed'], $matches)) {
$post['youtube'] = $matches[2];
}
if (isset($post['files']) && $post['files']) {
- $files = json_decode($post['files']);
+ $files = json_decode((string) $post['files'], null, 512, JSON_THROW_ON_ERROR);
if ($files[0]) {
if ($files[0]->file == 'deleted') {
- if (count($files) > 1) {
+ if ((is_countable($files) ? count($files) : 0) > 1) {
foreach ($files as $file) {
if (($file == $files[0]) || ($file->file == 'deleted'))
continue;
@@ -378,8 +367,7 @@
$board_link = $config['root'] . $board['dir'];
}
- $required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js',
- 'js/catalog.js');
+ $required_scripts = ['js/jquery.min.js', 'js/jquery.mixitup.min.js', 'js/catalog.js'];
// Include scripts that haven't been yet included
foreach($required_scripts as $i => $s) {
@@ -387,22 +375,8 @@
$config['additional_javascript'][] = $s;
}
- file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', Array(
- 'settings' => $this->settings,
- 'config' => $config,
- 'boardlist' => createBoardlist(),
- 'recent_images' => array(),
- 'recent_posts' => $recent_posts,
- 'stats' => array(),
- 'board' => $board_name,
- 'link' => $board_link
- )));
+ file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', ['settings' => $this->settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => [], 'recent_posts' => $recent_posts, 'stats' => [], 'board' => $board_name, 'link' => $board_link]));
- file_write($config['dir']['home'] . $board_name . '/index.rss', Element('themes/catalog/index.rss', Array(
- 'settings' => $this->settings,
- 'config' => $config,
- 'recent_posts' => $recent_posts,
- 'board' => $board
- )));
+ file_write($config['dir']['home'] . $board_name . '/index.rss', Element('themes/catalog/index.rss', ['settings' => $this->settings, 'config' => $config, 'recent_posts' => $recent_posts, 'board' => $board]));
}
}