CR. Refactors duplicate code. Fixes boardlist link error.

This commit is contained in:
nonmakina 2021-01-11 10:36:29 -06:00
parent 57c9cba982
commit 39d069a1ba
2 changed files with 27 additions and 37 deletions

View File

@ -56,6 +56,30 @@ function doBoardListPart($list, $root, &$boards) {
return $body; return $body;
} }
function createForeignBoardListSection($configKey){
$body = '';
if (isset($config[$configKey])){
$body .= ' <span class="sub">[';
// Append links to foreign boards
$i = 0;
foreach ($config[$configKey] as $fboardname => $fboardurl) {
$i++;
$body .= ' <a href="' . $fboardurl . '">' . $fboardname . '</a>';
// only put slash in between elements
if ($i != count($configKey)) {
$body .= ' /';
}
}
$body .= ']</span> ';
}
return body;
}
function createBoardlist($mod=false) { function createBoardlist($mod=false) {
global $config; global $config;
@ -67,45 +91,11 @@ function createBoardlist($mod=false) {
$boards[$val['uri']] = $val['title']; $boards[$val['uri']] = $val['title'];
} }
$body = ''; $body = '';
if (isset($config['prepended_foreign_boards'])){ $body .= createForeignBoardListSection('prepended_foreign_boards');
$body .= ' <span class="sub">[';
// Append links to foreign boards
$i = 0;
foreach ($config['prepended_foreign_boards'] as $fboardname => $fboardurl) {
$i++;
$body .= ' <a href="' . $fboardurl . '">' . $fboardname . '</a>';
// only put slash in between elements
if ($i != count($config['prepended_foreign_boards'])) {
$body .= ' /';
}
}
$body .= ']</span> ';
}
$body .= doBoardListPart($config['boards'], $mod?'?/':$config['root'], $boards); $body .= doBoardListPart($config['boards'], $mod?'?/':$config['root'], $boards);
$body .= createForeignBoardListSection('foreign_boards');
if (isset($config['foreign_boards'])) {
$body .= ' <span class="sub">[';
// Append links to foreign boards
$i = 0;
foreach ($config['foreign_boards'] as $fboardname => $fboardurl) {
$i++;
$body .= ' <a href="' . $fboardurl . '">' . $fboardname . '</a>';
// only put slash in between elements
if ($i != count($config['foreign_boards'])) {
$body .= ' /';
}
}
$body .= ']</span> ';
}
if ($config['boardlist_wrap_bracket'] && !preg_match('/\] $/', $body)) if ($config['boardlist_wrap_bracket'] && !preg_match('/\] $/', $body))
$body = '[' . $body . ']'; $body = '[' . $body . ']';

View File

@ -25,7 +25,7 @@ $config['boards'] = array(
); );
$config['prepended_foreign_boards'] = array( $config['prepended_foreign_boards'] = array(
'overboard' => '/overboard', 'overboard' => '/overboard/',
); );
$config['foreign_boards'] = array( $config['foreign_boards'] = array(