From 3d48ccf7e2fe5511718b08e7189e87e850ea6da7 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Thu, 3 Aug 2023 16:26:40 -0400 Subject: [PATCH] More fixes after upgrading to php8 broke everything - call openBoard inside of catalog build. I have no idea how it could have been defined before because it depends on a global variable $board which seems to be only globally defined by openBoard in functions.php, but that's called later. the fix is to just call openBoard, that's what tinyboard does. (somehow the code expected the uri to already be set) --- inc/anti-bot.php | 24 ++++++++++++++++++++++-- inc/functions.php | 14 +++++++------- inc/mod/pages.php | 15 ++++++++++++++- templates/themes/catalog/theme.php | 19 +++++++++---------- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/inc/anti-bot.php b/inc/anti-bot.php index b6be5e60..31eb76e8 100644 --- a/inc/anti-bot.php +++ b/inc/anti-bot.php @@ -11,8 +11,28 @@ $hidden_inputs_twig = array(); $logfile = "/tmp/lainchan_err.out"; function print_err($s) { - // global $logfile; - // file_put_contents($logfile, $s . "\n", FILE_APPEND); + global $logfile; + file_put_contents($logfile, $s . "\n", FILE_APPEND); +} + +function getStackTraceAsString() { + $stackTrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + + $traceString = ''; + foreach ($stackTrace as $index => $entry) { + if ($index > 0) { + $traceString .= sprintf( + "#%d %s(%d): %s%s", + $index - 1, + isset($entry['file']) ? $entry['file'] : 'unknown', + isset($entry['line']) ? $entry['line'] : 0, + isset($entry['class']) ? $entry['class'] . $entry['type'] . $entry['function'] : $entry['function'], + PHP_EOL + ); + } + } + + return $traceString; } function print_err2($s) { diff --git a/inc/functions.php b/inc/functions.php index 991729ef..a20531b2 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -405,11 +405,11 @@ function rebuildThemes($action, $boardname = false) { $config = $_config; $board = $_board; - // Reload the locale - if ($config['locale'] != $current_locale) { - $current_locale = $config['locale']; - init_locale($config['locale']); - } + // Reload the locale + if ($config['locale'] != $current_locale) { + $current_locale = $config['locale']; + init_locale($config['locale']); + } if (PHP_SAPI === 'cli') { echo "Rebuilding theme ".$theme['theme']."... "; @@ -446,7 +446,7 @@ function loadThemeConfig($_theme) { return $theme; } -function rebuildTheme($theme, $action, $board = false) { +function rebuildTheme($theme, $action, $boardname = false) { global $config, $_theme; $_theme = $theme; @@ -455,7 +455,7 @@ function rebuildTheme($theme, $action, $board = false) { if (file_exists($config['dir']['themes'] . '/' . $_theme . '/theme.php')) { require_once $config['dir']['themes'] . '/' . $_theme . '/theme.php'; - $theme['build_function']($action, themeSettings($_theme), $board); + $theme['build_function']($action, themeSettings($_theme), $boardname); } } diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 1e1866d9..37772d3c 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2676,6 +2676,19 @@ function mod_new_pm($username) { )); } +function clearCacheFiles($cacheLocation) { + if (is_string($cacheLocation)) { + foreach (new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($cacheLocation), + \RecursiveIteratorIterator::LEAVES_ONLY) as $file + ) { + if ($file->isFile()) { + @unlink($file->getPathname()); + } + } + } +} + function mod_rebuild() { global $config, $twig; print_err("mod_rebuild"); @@ -2698,7 +2711,7 @@ function mod_rebuild() { $log[] = 'Clearing template cache'; load_twig(); - $twig->clearCacheFiles(); + clearCacheFiles("{$config['dir']['template']}/cache"); } if (isset($_POST['rebuild_themes'])) { diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index 5980482c..7ec88f96 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -19,14 +19,14 @@ // - post (a reply has been made) // - post-thread (a thread has been made) if ($action === 'all') { - foreach ($boards as $board) { - $action = generation_strategy("sb_catalog", array($board)); + foreach ($boards as $board_name) { + $action = generation_strategy("sb_catalog", array($board_name)); if ($action == 'delete') { - file_unlink($config['dir']['home'] . $board . '/catalog.html'); - file_unlink($config['dir']['home'] . $board . '/index.rss'); + file_unlink($config['dir']['home'] . $board_name . '/catalog.html'); + file_unlink($config['dir']['home'] . $board_name . '/index.rss'); } elseif ($action == 'rebuild') { - $b->build($settings, $board); + $b->build($settings, $board_name); } } if(isset($settings['has_overboard']) && $settings['has_overboard']) { @@ -307,11 +307,10 @@ */ public function build($settings, $board_name) { global $config, $board; - if ($board['uri'] != $board_name) { - if (!openBoard($board_name)) { - error(sprintf(_("Board %s doesn't exist"), $board_name)); - } - } + + if (!openBoard($board_name)) { + error(sprintf(_("Board %s doesn't exist"), $board_name)); + } if (array_key_exists($board_name, $this->threadsCache)) { $threads = $this->threadsCache[$board_name];