From 1251fa01e732f49734d9e5a8ee5b334d0aa172eb Mon Sep 17 00:00:00 2001 From: nonmakina Date: Sun, 10 Jan 2021 21:18:09 -0600 Subject: [PATCH] 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;