From 39d069a1baff64f677daa787814dea840f0dcfa5 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Mon, 11 Jan 2021 10:36:29 -0600 Subject: [PATCH] CR. Refactors duplicate code. Fixes boardlist link error. --- inc/display.php | 54 +++++++++++++++++------------------------ inc/instance-config.php | 2 +- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/inc/display.php b/inc/display.php index be0881fd..3860aa84 100644 --- a/inc/display.php +++ b/inc/display.php @@ -56,56 +56,46 @@ function doBoardListPart($list, $root, &$boards) { return $body; } -function createBoardlist($mod=false) { - global $config; - - if (!isset($config['boards'])) return array('top'=>'','bottom'=>''); - - $xboards = listBoards(); - $boards = array(); - foreach ($xboards as $val) { - $boards[$val['uri']] = $val['title']; - } +function createForeignBoardListSection($configKey){ $body = ''; - if (isset($config['prepended_foreign_boards'])){ + + if (isset($config[$configKey])){ $body .= ' ['; // Append links to foreign boards $i = 0; - foreach ($config['prepended_foreign_boards'] as $fboardname => $fboardurl) { + foreach ($config[$configKey] as $fboardname => $fboardurl) { $i++; $body .= ' ' . $fboardname . ''; // only put slash in between elements - if ($i != count($config['prepended_foreign_boards'])) { + if ($i != count($configKey)) { $body .= ' /'; } } $body .= '] '; } - - - $body .= doBoardListPart($config['boards'], $mod?'?/':$config['root'], $boards); - - if (isset($config['foreign_boards'])) { - - $body .= ' ['; - - // Append links to foreign boards - $i = 0; - foreach ($config['foreign_boards'] as $fboardname => $fboardurl) { - $i++; - $body .= ' ' . $fboardname . ''; - // only put slash in between elements - if ($i != count($config['foreign_boards'])) { - $body .= ' /'; - } - } + return body; +} - $body .= '] '; +function createBoardlist($mod=false) { + global $config; + + if (!isset($config['boards'])) return array('top'=>'','bottom'=>''); + + $xboards = listBoards(); + $boards = array(); + foreach ($xboards as $val) { + $boards[$val['uri']] = $val['title']; } + $body = ''; + $body .= createForeignBoardListSection('prepended_foreign_boards'); + + + $body .= doBoardListPart($config['boards'], $mod?'?/':$config['root'], $boards); + $body .= createForeignBoardListSection('foreign_boards'); if ($config['boardlist_wrap_bracket'] && !preg_match('/\] $/', $body)) $body = '[' . $body . ']'; diff --git a/inc/instance-config.php b/inc/instance-config.php index d1f7f966..f4d86604 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -25,7 +25,7 @@ $config['boards'] = array( ); $config['prepended_foreign_boards'] = array( - 'overboard' => '/overboard', + 'overboard' => '/overboard/', ); $config['foreign_boards'] = array(