From add7ac393e441379ecf4969b08c0001eceb69919 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Sat, 9 Jan 2021 01:22:26 -0600 Subject: [PATCH 01/10] makes some fixes to the overboard code --- templates/themes/semirand/theme.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/templates/themes/semirand/theme.php b/templates/themes/semirand/theme.php index e8d3e56c..6e5b1caa 100644 --- a/templates/themes/semirand/theme.php +++ b/templates/themes/semirand/theme.php @@ -3,7 +3,7 @@ require 'info.php'; /** - * Generate the board's HTML and move it and its JavaScript in place, whence + * Generate the board's HTML and move it and its JavaScript in place, whence * it's served */ function semirand_build($action, $settings) { @@ -64,7 +64,7 @@ } /** - * Obtain list of all threads from all non-excluded boards + * Obtain list of all threads from all non-excluded boards */ private function fetchThreads() { $query = ''; @@ -87,9 +87,12 @@ /** * Retrieve all replies to a given thread */ - private function fetchReplies($board, $thread_id) { + private function fetchReplies($board, $thread_id, $preview_count) { + $query = prepare("SELECT * FROM (SELECT * FROM ``posts_$board`` WHERE `thread` = :id ORDER BY `time` DESC LIMIT :limit) as + t ORDER BY t.time ASC"); $query = prepare("SELECT * FROM ``posts_$board`` WHERE `thread` = :id"); $query->bindValue(':id', $thread_id, PDO::PARAM_INT); + $query->bindValue(':limit', $preview_count, PDO::PARAM_INT); $query->execute() or error(db_error($query)); return $query->fetchAll(PDO::FETCH_ASSOC); @@ -131,13 +134,13 @@ openBoard($post['board']); $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod); - $replies = $this->fetchReplies($post['board'], $post['id']); // Number of replies to a thread that are displayed beneath it $preview_count = $post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']; + $replies = $this->fetchReplies($post['board'], $post['id'], $preview_count); // Chomp the last few replies - $disp_replies = array_splice($replies, 0, $preview_count); + $disp_replies = $replies; $disp_img_count = 0; foreach ($disp_replies as $reply) { if ($reply['files'] !== '') @@ -182,7 +185,7 @@ // Fetch threads from all boards and chomp the first 'n' posts, depending // on the setting - $threads = $this->shuffleThreads($this->fetchThreads()); + $threads = $this->fetchThreads(); $total_count = count($threads); // Top threads displayed on load $top_threads = array_splice($threads, 0, $this->settings['thread_limit']); From a037341613aa3a861a662cb8f89300e1a9073f33 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Sat, 9 Jan 2021 01:25:44 -0600 Subject: [PATCH 02/10] fix typo produced when copying changes --- templates/themes/semirand/theme.php | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/themes/semirand/theme.php b/templates/themes/semirand/theme.php index 6e5b1caa..cd670a52 100644 --- a/templates/themes/semirand/theme.php +++ b/templates/themes/semirand/theme.php @@ -90,7 +90,6 @@ private function fetchReplies($board, $thread_id, $preview_count) { $query = prepare("SELECT * FROM (SELECT * FROM ``posts_$board`` WHERE `thread` = :id ORDER BY `time` DESC LIMIT :limit) as t ORDER BY t.time ASC"); - $query = prepare("SELECT * FROM ``posts_$board`` WHERE `thread` = :id"); $query->bindValue(':id', $thread_id, PDO::PARAM_INT); $query->bindValue(':limit', $preview_count, PDO::PARAM_INT); $query->execute() or error(db_error($query)); From ab4b6592b5376dfcc887abfae7dead6c75e5fd73 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Sat, 9 Jan 2021 17:01:44 -0600 Subject: [PATCH 03/10] Adds support to prepend foreign boards on the boardlist. Used to add the overboard. --- inc/display.php | 21 ++++++++++++++++++++- inc/instance-config.php | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/inc/display.php b/inc/display.php index 0c846cf9..be0881fd 100644 --- a/inc/display.php +++ b/inc/display.php @@ -66,8 +66,27 @@ function createBoardlist($mod=false) { foreach ($xboards as $val) { $boards[$val['uri']] = $val['title']; } + $body = ''; + if (isset($config['prepended_foreign_boards'])){ + $body .= ' ['; + + // Append links to foreign boards + $i = 0; + foreach ($config['prepended_foreign_boards'] as $fboardname => $fboardurl) { + $i++; + $body .= ' ' . $fboardname . ''; + + // only put slash in between elements + if ($i != count($config['prepended_foreign_boards'])) { + $body .= ' /'; + } + } + + $body .= '] '; + } + - $body = doBoardListPart($config['boards'], $mod?'?/':$config['root'], $boards); + $body .= doBoardListPart($config['boards'], $mod?'?/':$config['root'], $boards); if (isset($config['foreign_boards'])) { diff --git a/inc/instance-config.php b/inc/instance-config.php index eca5bb01..f50b647e 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -23,6 +23,11 @@ $config['boards'] = array( ) , array('meta') ); + +$config['prepended_foreign_boards'] = array( + 'overboard' => 'overboard/index.html', +); + $config['foreign_boards'] = array( 'GET' => 'https://getchan.net/GET/', 'ref' => 'https://getchan.net/ref/' From 1251fa01e732f49734d9e5a8ee5b334d0aa172eb Mon Sep 17 00:00:00 2001 From: nonmakina Date: Sun, 10 Jan 2021 21:18:09 -0600 Subject: [PATCH 04/10] adds catalog for overboard --- templates/themes/catalog/info.php | 14 ++++++++++++++ templates/themes/catalog/theme.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/templates/themes/catalog/info.php b/templates/themes/catalog/info.php index 0e7581f0..98b68600 100644 --- a/templates/themes/catalog/info.php +++ b/templates/themes/catalog/info.php @@ -83,6 +83,20 @@ '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' => 'Build overboard catalog', + 'name' => 'has_overboard', + 'type' => 'checkbox', + 'default' => false, + 'comment' => 'Check this if you wish to create a catalog for the overboard.' + ); + $theme['config'][] = Array( + 'title' => 'Overboard location (default \'overboard\')', + 'name' => 'overboard_location', + 'type' => 'text', + 'default' => 'overboard', + 'comment' => 'Fill in the location of the overboard directory. Default is \'overboard\' which corresponds to ./overboard' + ); // 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 63ced223..bce93d31 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -41,6 +41,9 @@ elseif ($action == 'rebuild') { print_err("catalog_build calling Catalog.build 2"); $b->build($settings, $board); + if($settings['has_overboard']) { + $b->buildOverboardCatalog($settings, $boards); + } } } // FIXME: Check that Ukko is actually enabled @@ -332,6 +335,33 @@ return $sql; } + /** + * Build and save the HTML of the catalog for the overboard + */ + public function buildOverboardCatalog($settings, $board_names) { + global $config; + $board_name = $settings['overboard_location']; + + if (array_key_exists($board_name, $this->threadsCache)) { + $threads = $this->threadsCache[$board_name]; + } else { + $sql = ''; + foreach ($boards as $board) { + $sql .= $this->buildThreadsQuery($board); + $sql .= " UNION ALL "; + } + $query = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $query); + $result = query($query) or error(db_error()); + $threads = $query->fetchAll(PDO::FETCH_ASSOC); + // Save for posterity + $this->threadsCache[$board_name] = $threads; + } + // Generate data for the template + $recent_posts = $this->generateRecentPosts($threads); + + $this->saveForBoard($board_name, $recent_posts); + } + private function generateRecentPosts($threads) { global $config, $board; From 4ee8f9349a69fabcbd757587bc09852eeb4c096d Mon Sep 17 00:00:00 2001 From: nonmakina Date: Sun, 10 Jan 2021 21:28:16 -0600 Subject: [PATCH 05/10] Add overboard catalog to the rebuild-all action --- templates/themes/catalog/theme.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index bce93d31..3c91a4ac 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -17,7 +17,7 @@ // - post-thread (a thread has been made) if ($action === 'all') { foreach ($boards as $board) { - $b = new Catalog($settings); + //$b = new Catalog($settings); $action = generation_strategy("sb_catalog", array($board)); if ($action == 'delete') { @@ -29,6 +29,17 @@ $b->build($settings, $board); } } + if($settings['has_overboard']) { + $board = $settings['overboard_location']; + $action = generation_strategy("sb_catalog", array($board)); + if ($action == 'delete') { + file_unlink($config['dir']['home'] . $board . '/catalog.html'); + file_unlink($config['dir']['home'] . $board . '/index.rss'); + } + elseif ($action == 'rebuild') { + $b->buildOverboardCatalog($settings, $boards); + } + } } elseif ($action == 'post-thread' || ($settings['update_on_posts'] && $action == 'post') || ($settings['update_on_posts'] && $action == 'post-delete') || $action == 'sticky' || ($action == 'lock' && in_array($board, $boards))) { $b = new Catalog($settings); @@ -339,7 +350,6 @@ * Build and save the HTML of the catalog for the overboard */ public function buildOverboardCatalog($settings, $board_names) { - global $config; $board_name = $settings['overboard_location']; if (array_key_exists($board_name, $this->threadsCache)) { From 5b57d35a4cd1834bf9228979fe9a9b842b6894f3 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Sun, 10 Jan 2021 21:55:20 -0600 Subject: [PATCH 06/10] fixes path for catalog. fixes syntax bugs. --- inc/instance-config.php | 2 +- templates/themes/catalog/theme.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/inc/instance-config.php b/inc/instance-config.php index f50b647e..d1f7f966 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/index.html', + 'overboard' => '/overboard', ); $config['foreign_boards'] = array( diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index 3c91a4ac..269e237f 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -349,7 +349,7 @@ /** * Build and save the HTML of the catalog for the overboard */ - public function buildOverboardCatalog($settings, $board_names) { + public function buildOverboardCatalog($settings, $boards) { $board_name = $settings['overboard_location']; if (array_key_exists($board_name, $this->threadsCache)) { @@ -360,16 +360,16 @@ $sql .= $this->buildThreadsQuery($board); $sql .= " UNION ALL "; } - $query = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $query); - $result = query($query) or error(db_error()); - $threads = $query->fetchAll(PDO::FETCH_ASSOC); + $sql = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $sql); + $result = query($sql) or error(db_error()); + $threads = $result->fetchAll(PDO::FETCH_ASSOC); // Save for posterity $this->threadsCache[$board_name] = $threads; } // Generate data for the template $recent_posts = $this->generateRecentPosts($threads); - $this->saveForBoard($board_name, $recent_posts); + $this->saveForBoard($board_name, $recent_posts, '/' . $settings['overboard_location']); } private function generateRecentPosts($threads) { From a3e2af403b68cf3bbcf0abb49de5a89657962943 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Sun, 10 Jan 2021 22:18:32 -0600 Subject: [PATCH 07/10] Adds limit to overboard catalog --- templates/themes/catalog/info.php | 7 +++++++ templates/themes/catalog/theme.php | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/templates/themes/catalog/info.php b/templates/themes/catalog/info.php index 98b68600..67999c88 100644 --- a/templates/themes/catalog/info.php +++ b/templates/themes/catalog/info.php @@ -97,6 +97,13 @@ 'default' => 'overboard', 'comment' => 'Fill in the location of the overboard directory. Default is \'overboard\' which corresponds to ./overboard' ); + $theme['config'][] = Array( + 'title' => 'Max posts in catalog overboard', + 'name' => 'overboard_limit', + 'type' => 'text', + 'default' => '350', + 'comment' => 'The maximum number of thread that will appear in the overboard catalog' + ); // 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 269e237f..9948738f 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -357,12 +357,15 @@ } else { $sql = ''; foreach ($boards as $board) { - $sql .= $this->buildThreadsQuery($board); + $sql .= '('. $this->buildThreadsQuery($board) . ')'; $sql .= " UNION ALL "; } - $sql = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $sql); - $result = query($sql) or error(db_error()); - $threads = $result->fetchAll(PDO::FETCH_ASSOC); + $sql = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC LIMIT :limit', $sql); + $query = prepare($sql); + $query->bindValue(':limit', $settings['overboard_limit'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + $threads = $query->fetchAll(PDO::FETCH_ASSOC); // Save for posterity $this->threadsCache[$board_name] = $threads; } From 57c9cba982d356a165622db33f9cd91cb763e040 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Mon, 11 Jan 2021 02:04:05 -0600 Subject: [PATCH 08/10] stale comment --- templates/themes/catalog/theme.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index 9948738f..67e6c37a 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -17,8 +17,6 @@ // - post-thread (a thread has been made) if ($action === 'all') { foreach ($boards as $board) { - //$b = new Catalog($settings); - $action = generation_strategy("sb_catalog", array($board)); if ($action == 'delete') { file_unlink($config['dir']['home'] . $board . '/catalog.html'); From 39d069a1baff64f677daa787814dea840f0dcfa5 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Mon, 11 Jan 2021 10:36:29 -0600 Subject: [PATCH 09/10] 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( From de83b874ff3473ad23c5fbb8f86e8df4c7d2211e Mon Sep 17 00:00:00 2001 From: nonmakina Date: Mon, 11 Jan 2021 10:42:51 -0600 Subject: [PATCH 10/10] fixes --- inc/display.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/inc/display.php b/inc/display.php index 3860aa84..6de187a3 100644 --- a/inc/display.php +++ b/inc/display.php @@ -57,6 +57,7 @@ function doBoardListPart($list, $root, &$boards) { } function createForeignBoardListSection($configKey){ + global $config; $body = ''; if (isset($config[$configKey])){ @@ -69,7 +70,7 @@ function createForeignBoardListSection($configKey){ $body .= ' ' . $fboardname . ''; // only put slash in between elements - if ($i != count($configKey)) { + if ($i != count($config[$configKey])) { $body .= ' /'; } } @@ -77,7 +78,7 @@ function createForeignBoardListSection($configKey){ $body .= '] '; } - return body; + return $body; } function createBoardlist($mod=false) { @@ -92,8 +93,6 @@ function createBoardlist($mod=false) { } $body = ''; $body .= createForeignBoardListSection('prepended_foreign_boards'); - - $body .= doBoardListPart($config['boards'], $mod?'?/':$config['root'], $boards); $body .= createForeignBoardListSection('foreign_boards');