retab templates/themes/categories/theme.php
This commit is contained in:
parent
e9372e50ee
commit
0714422d9a
|
@ -1,128 +1,128 @@
|
||||||
<?php
|
<?php
|
||||||
require 'info.php';
|
require 'info.php';
|
||||||
|
|
||||||
function categories_build($action, $settings, $board) {
|
function categories_build($action, $settings, $board) {
|
||||||
// Possible values for $action:
|
// Possible values for $action:
|
||||||
// - all (rebuild everything, initialization)
|
// - all (rebuild everything, initialization)
|
||||||
// - news (news has been updated)
|
// - news (news has been updated)
|
||||||
// - boards (board list changed)
|
// - boards (board list changed)
|
||||||
|
|
||||||
Categories::build($action, $settings);
|
Categories::build($action, $settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
|
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
|
||||||
class Categories {
|
class Categories {
|
||||||
public static function build($action, $settings) {
|
public static function build($action, $settings) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if ($action == 'all' ||
|
if ($action == 'all' ||
|
||||||
$action == 'boards' ||
|
$action == 'boards' ||
|
||||||
$action == 'news' ||
|
$action == 'news' ||
|
||||||
$action == 'post' ||
|
$action == 'post' ||
|
||||||
$action == 'post-thread' ||
|
$action == 'post-thread' ||
|
||||||
$action == 'post-delete'){
|
$action == 'post-delete'){
|
||||||
file_write($config['dir']['home'] . $settings['file_main'], Categories::homepage($settings));
|
file_write($config['dir']['home'] . $settings['file_main'], Categories::homepage($settings));
|
||||||
file_write($config['dir']['home'] . $settings['file_news'], Categories::news($settings));
|
file_write($config['dir']['home'] . $settings['file_news'], Categories::news($settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == 'all'){
|
if ($action == 'all'){
|
||||||
file_write($config['dir']['home'] . $settings['file_sidebar'], Categories::sidebar($settings));
|
file_write($config['dir']['home'] . $settings['file_sidebar'], Categories::sidebar($settings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Build homepage
|
// Build homepage
|
||||||
public static function homepage($settings) {
|
public static function homepage($settings) {
|
||||||
global $config;
|
global $config;
|
||||||
$description = 'Welcome to Siberia.';
|
$description = 'Welcome to Siberia.';
|
||||||
$query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
|
$query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
|
||||||
$news = $query->fetchAll(PDO::FETCH_ASSOC);
|
$news = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$stats = Categories::getPostStatistics($settings);
|
$stats = Categories::getPostStatistics($settings);
|
||||||
return Element(
|
return Element(
|
||||||
'themes/categories/frames.html',
|
'themes/categories/frames.html',
|
||||||
Array(
|
Array(
|
||||||
'config' => $config,
|
'config' => $config,
|
||||||
'settings' => $settings,
|
'settings' => $settings,
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'categories' => Categories::getCategories($config),
|
'categories' => Categories::getCategories($config),
|
||||||
'news' => $news,
|
'news' => $news,
|
||||||
'stats' => $stats,
|
'stats' => $stats,
|
||||||
'boardlist' => createBoardlist(false)
|
'boardlist' => createBoardlist(false)
|
||||||
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build news page
|
// Build news page
|
||||||
public static function news($settings) {
|
public static function news($settings) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
|
$query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
|
||||||
$news = $query->fetchAll(PDO::FETCH_ASSOC);
|
$news = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$stats = Categories::getPostStatistics($settings);
|
$stats = Categories::getPostStatistics($settings);
|
||||||
return Element('themes/categories/news.html', Array(
|
return Element('themes/categories/news.html', Array(
|
||||||
'settings' => $settings,
|
'settings' => $settings,
|
||||||
'config' => $config,
|
'config' => $config,
|
||||||
'news' => $news,
|
'news' => $news,
|
||||||
'stats' => $stats,
|
'stats' => $stats,
|
||||||
'boardlist' => createBoardlist(false)
|
'boardlist' => createBoardlist(false)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build sidebar
|
// Build sidebar
|
||||||
public static function sidebar($settings) {
|
public static function sidebar($settings) {
|
||||||
global $config, $board;
|
global $config, $board;
|
||||||
|
|
||||||
return Element('themes/categories/sidebar.html', Array(
|
return Element('themes/categories/sidebar.html', Array(
|
||||||
'settings' => $settings,
|
'settings' => $settings,
|
||||||
'config' => $config,
|
'config' => $config,
|
||||||
'categories' => Categories::getCategories($config)
|
'categories' => Categories::getCategories($config)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getCategories($config) {
|
private static function getCategories($config) {
|
||||||
$categories = $config['categories'];
|
$categories = $config['categories'];
|
||||||
|
|
||||||
foreach ($categories as &$boards) {
|
foreach ($categories as &$boards) {
|
||||||
foreach ($boards as &$board) {
|
foreach ($boards as &$board) {
|
||||||
$title = boardTitle($board);
|
$title = boardTitle($board);
|
||||||
if (!$title)
|
if (!$title)
|
||||||
$title = $board; // board doesn't exist, but for some reason you want to display it anyway
|
$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));
|
$board = Array('title' => $title, 'uri' => sprintf($config['board_path'], $board));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $categories;
|
return $categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getPostStatistics($settings) {
|
private static function getPostStatistics($settings) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if (!isset($config['boards'])) {
|
if (!isset($config['boards'])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$HOUR = 3600;
|
$HOUR = 3600;
|
||||||
$DAY = $HOUR * 24;
|
$DAY = $HOUR * 24;
|
||||||
$WEEK = $DAY * 7;
|
$WEEK = $DAY * 7;
|
||||||
|
|
||||||
$stats = [];
|
$stats = [];
|
||||||
$hourly = [];
|
$hourly = [];
|
||||||
$daily = [];
|
$daily = [];
|
||||||
$weekly = [];
|
$weekly = [];
|
||||||
|
|
||||||
foreach (array_merge(... $config['boards']) as $uri) {
|
foreach (array_merge(... $config['boards']) as $uri) {
|
||||||
$_board = getBoardInfo($uri);
|
$_board = getBoardInfo($uri);
|
||||||
if (!$_board) {
|
if (!$_board) {
|
||||||
// board doesn't exist.
|
// board doesn't exist.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$boardStat['title'] = $_board['title'];
|
$boardStat['title'] = $_board['title'];
|
||||||
|
|
||||||
$boardStat['hourly_ips'] = Categories::countUniqueIps($hourly, $HOUR, $_board);
|
$boardStat['hourly_ips'] = Categories::countUniqueIps($hourly, $HOUR, $_board);
|
||||||
$boardStat['daily_ips'] = Categories::countUniqueIps($daily, $DAY, $_board);
|
$boardStat['daily_ips'] = Categories::countUniqueIps($daily, $DAY, $_board);
|
||||||
$boardStat['weekly_ips'] = Categories::countUniqueIps($weekly, $WEEK, $_board);
|
$boardStat['weekly_ips'] = Categories::countUniqueIps($weekly, $WEEK, $_board);
|
||||||
|
|
||||||
$pph_query = query(
|
$pph_query = query(
|
||||||
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
|
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
|
||||||
|
@ -147,19 +147,19 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function countUniqueIps($markAsCounted, $timespan, $_board) {
|
private static function countUniqueIps($markAsCounted, $timespan, $_board) {
|
||||||
$unique_query = query(
|
$unique_query = query(
|
||||||
sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d",
|
sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d",
|
||||||
$_board['uri'],
|
$_board['uri'],
|
||||||
time()-$timespan)
|
time()-$timespan)
|
||||||
) or error(db_error());
|
) or error(db_error());
|
||||||
$uniqueIps = $unique_query->fetchAll();
|
$uniqueIps = $unique_query->fetchAll();
|
||||||
foreach ($uniqueIps as $_k => $row) {
|
foreach ($uniqueIps as $_k => $row) {
|
||||||
$markAsCounted[$row['ip']] = true;
|
$markAsCounted[$row['ip']] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return count($uniqueIps);
|
return count($uniqueIps);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue