From 0714422d9a4b364c406ebb9242e582738c172c0d Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Wed, 13 Dec 2023 03:01:05 +0000 Subject: [PATCH] retab templates/themes/categories/theme.php --- templates/themes/categories/theme.php | 212 +++++++++++++------------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/templates/themes/categories/theme.php b/templates/themes/categories/theme.php index 1e731cae..bc837e58 100644 --- a/templates/themes/categories/theme.php +++ b/templates/themes/categories/theme.php @@ -1,128 +1,128 @@ fetchAll(PDO::FETCH_ASSOC); - $stats = Categories::getPostStatistics($settings); - return Element( - 'themes/categories/frames.html', - Array( - 'config' => $config, - 'settings' => $settings, - 'description' => $description, - 'categories' => Categories::getCategories($config), - 'news' => $news, - 'stats' => $stats, - 'boardlist' => createBoardlist(false) + // Build homepage + public static function homepage($settings) { + global $config; + $description = 'Welcome to Siberia.'; + $query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error()); + $news = $query->fetchAll(PDO::FETCH_ASSOC); + $stats = Categories::getPostStatistics($settings); + return Element( + 'themes/categories/frames.html', + Array( + 'config' => $config, + 'settings' => $settings, + 'description' => $description, + 'categories' => Categories::getCategories($config), + 'news' => $news, + 'stats' => $stats, + 'boardlist' => createBoardlist(false) - ) - ); - } + ) + ); + } - // Build news page - public static function news($settings) { - global $config; + // Build news page + public static function news($settings) { + global $config; - $query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error()); - $news = $query->fetchAll(PDO::FETCH_ASSOC); - $stats = Categories::getPostStatistics($settings); - return Element('themes/categories/news.html', Array( - 'settings' => $settings, - 'config' => $config, - 'news' => $news, - 'stats' => $stats, - 'boardlist' => createBoardlist(false) - )); - } + $query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error()); + $news = $query->fetchAll(PDO::FETCH_ASSOC); + $stats = Categories::getPostStatistics($settings); + return Element('themes/categories/news.html', Array( + 'settings' => $settings, + 'config' => $config, + 'news' => $news, + 'stats' => $stats, + 'boardlist' => createBoardlist(false) + )); + } - // Build sidebar - public static function sidebar($settings) { - global $config, $board; + // Build sidebar + public static function sidebar($settings) { + global $config, $board; - return Element('themes/categories/sidebar.html', Array( - 'settings' => $settings, - 'config' => $config, - 'categories' => Categories::getCategories($config) - )); - } + return Element('themes/categories/sidebar.html', Array( + 'settings' => $settings, + 'config' => $config, + 'categories' => Categories::getCategories($config) + )); + } - private static function getCategories($config) { - $categories = $config['categories']; + private static function getCategories($config) { + $categories = $config['categories']; - foreach ($categories as &$boards) { - foreach ($boards as &$board) { - $title = boardTitle($board); - if (!$title) - $title = $board; // board doesn't exist, but for some reason you want to display it anyway - $board = Array('title' => $title, 'uri' => sprintf($config['board_path'], $board)); - } - } + foreach ($categories as &$boards) { + foreach ($boards as &$board) { + $title = boardTitle($board); + if (!$title) + $title = $board; // board doesn't exist, but for some reason you want to display it anyway + $board = Array('title' => $title, 'uri' => sprintf($config['board_path'], $board)); + } + } - return $categories; - } + return $categories; + } private static function getPostStatistics($settings) { - global $config; + global $config; - if (!isset($config['boards'])) { - return null; - } + if (!isset($config['boards'])) { + return null; + } - $HOUR = 3600; - $DAY = $HOUR * 24; - $WEEK = $DAY * 7; + $HOUR = 3600; + $DAY = $HOUR * 24; + $WEEK = $DAY * 7; - $stats = []; - $hourly = []; - $daily = []; - $weekly = []; + $stats = []; + $hourly = []; + $daily = []; + $weekly = []; foreach (array_merge(... $config['boards']) as $uri) { - $_board = getBoardInfo($uri); - if (!$_board) { - // board doesn't exist. - continue; - } + $_board = getBoardInfo($uri); + if (!$_board) { + // board doesn't exist. + continue; + } - $boardStat['title'] = $_board['title']; + $boardStat['title'] = $_board['title']; - $boardStat['hourly_ips'] = Categories::countUniqueIps($hourly, $HOUR, $_board); - $boardStat['daily_ips'] = Categories::countUniqueIps($daily, $DAY, $_board); - $boardStat['weekly_ips'] = Categories::countUniqueIps($weekly, $WEEK, $_board); + $boardStat['hourly_ips'] = Categories::countUniqueIps($hourly, $HOUR, $_board); + $boardStat['daily_ips'] = Categories::countUniqueIps($daily, $DAY, $_board); + $boardStat['weekly_ips'] = Categories::countUniqueIps($weekly, $WEEK, $_board); $pph_query = query( sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d", @@ -147,19 +147,19 @@ } private static function countUniqueIps($markAsCounted, $timespan, $_board) { - $unique_query = query( - sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d", + $unique_query = query( + sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d", $_board['uri'], time()-$timespan) ) or error(db_error()); - $uniqueIps = $unique_query->fetchAll(); - foreach ($uniqueIps as $_k => $row) { + $uniqueIps = $unique_query->fetchAll(); + foreach ($uniqueIps as $_k => $row) { $markAsCounted[$row['ip']] = true; } return count($uniqueIps); } - }; + }; ?>