Browse Source

Tidy up theme.php

pull/61/head
discomrade 2 years ago
parent
commit
ba6b4f1bab
  1. 126
      templates/themes/categories/theme.php

126
templates/themes/categories/theme.php

@ -35,9 +35,9 @@
public static function homepage($settings) { public static function homepage($settings) {
global $config; global $config;
$description = "Leftypol is an imageboard where users can post anonymously.</br>We engage in both serious political discourse and informal discussion on various topics related to leftist thought. </br></br>They are... an interesting group of people - <i><a href='https://www.youtube.com/watch?v=rJvAxRCxxCg'>Senpai Wolff</a></i> "; $description = "Leftypol is an imageboard where users can post anonymously.</br>We engage in both serious political discourse and informal discussion on various topics related to leftist thought. </br></br>They are... an interesting group of people - <i><a href='https://www.youtube.com/watch?v=rJvAxRCxxCg'>Senpai Wolff</a></i> ";
$metadescription = "Leftypol is an imageboard where users can post anonymously about both serious political discourse and informal discussion on various topics related to leftist thought."; $metadescription = "Leftypol is an imageboard where users can post anonymously about both serious political discourse and informal discussion on various topics related to leftist thought.";
$metaextra = '<link rel="canonical" href="https://leftypol.org" />'. $metaextra = '<link rel="canonical" href="https://leftypol.org" />'.
'<script type="application/ld+json">{"@context": "https://schema.org","@type": "Organization","url": "https://leftypol.org","logo": "https://leftypol.org/static/leftypol_logo.png"}</script>'; '<script type="application/ld+json">{"@context": "https://schema.org","@type": "Organization","url": "https://leftypol.org","logo": "https://leftypol.org/static/leftypol_logo.png"}</script>'; // other sites should delete this!
$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);
@ -100,67 +100,67 @@
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",
$_board['uri'], $_board['uri'],
time()-3600) time()-3600)
) or error(db_error()); ) or error(db_error());
$boardStat['pph'] = $pph_query->fetch()['count']; $boardStat['pph'] = $pph_query->fetch()['count'];
$stats['boards'][] = $boardStat; $stats['boards'][] = $boardStat;
} }
$stats['hourly_ips'] = count($hourly); $stats['hourly_ips'] = count($hourly);
$stats['daily_ips'] = count($daily); $stats['daily_ips'] = count($daily);
$stats['weekly_ips'] = count($weekly); $stats['weekly_ips'] = count($weekly);
$stats['pph'] = array_sum(array_column($stats['boards'], 'pph')); $stats['pph'] = array_sum(array_column($stats['boards'], 'pph'));
return $stats; return $stats;
} }
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…
Cancel
Save