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)
This commit is contained in:
towards-a-new-leftypol 2023-08-03 16:26:40 -04:00
parent d79a8ea78f
commit 3d48ccf7e2
4 changed files with 52 additions and 20 deletions

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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'])) {

View File

@ -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];