1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-24 23:50:11 +01:00
vichan/boards.php

153 lines
5.1 KiB
PHP
Raw Normal View History

2014-09-24 01:26:27 +02:00
<?php
include "inc/functions.php";
2014-09-26 03:15:17 +02:00
include "inc/countries.php";
2014-09-24 01:26:27 +02:00
$admin = isset($mod["type"]) && $mod["type"]<=30;
if (php_sapi_name() == 'fpm-fcgi' && !$admin) {
error('Cannot be run directly.');
}
$boards = listBoards();
2014-12-03 09:10:28 +01:00
$all_tags = array();
2014-09-24 01:26:27 +02:00
$total_posts_hour = 0;
$total_posts = 0;
2015-03-11 00:20:55 +01:00
$write_maxes = false;
2014-09-24 01:26:27 +02:00
2014-12-03 09:10:28 +01:00
function to_tag($str) {
$str = trim($str);
$str = strtolower($str);
$str = str_replace(['_', ' '], '-', $str);
return $str;
}
2015-03-11 00:20:55 +01:00
if (!file_exists('maxes.txt') || filemtime('maxes.txt') < (time() - (60*60))) {
$fp = fopen('maxes.txt', 'w+');
$write_maxes = true;
}
2014-09-24 01:26:27 +02:00
2015-03-11 00:20:55 +01:00
foreach ($boards as $i => $board) {
2014-09-24 01:26:27 +02:00
$query = prepare(sprintf("
2015-03-11 00:20:55 +01:00
SELECT IFNULL(MAX(id),0) max,
2014-09-24 01:26:27 +02:00
(SELECT COUNT(*) FROM ``posts_%s`` WHERE FROM_UNIXTIME(time) > DATE_SUB(NOW(), INTERVAL 1 HOUR)) pph,
2014-10-07 03:01:01 +02:00
(SELECT COUNT(DISTINCT ip) FROM ``posts_%s`` WHERE FROM_UNIXTIME(time) > DATE_SUB(NOW(), INTERVAL 3 DAY)) uniq_ip
2014-09-29 09:17:00 +02:00
FROM ``posts_%s``
", $board['uri'], $board['uri'], $board['uri'], $board['uri'], $board['uri']));
2014-09-24 01:26:27 +02:00
$query->execute() or error(db_error($query));
$r = $query->fetch(PDO::FETCH_ASSOC);
2014-12-03 09:10:28 +01:00
$tquery = prepare("SELECT `tag` FROM ``board_tags`` WHERE `uri` = :uri");
$tquery->execute([":uri" => $board['uri']]) or error(db_error($tquery));
$r2 = $tquery->fetchAll(PDO::FETCH_ASSOC);
$tags = array();
if ($r2) {
foreach ($r2 as $ii => $t) {
$tag=to_tag($t['tag']);
$tags[] = $tag;
if (!isset($all_tags[$tag])) {
$all_tags[$tag] = (int)$r['uniq_ip'];
} else {
$all_tags[$tag] += $r['uniq_ip'];
}
}
}
2014-09-24 01:26:27 +02:00
$pph = $r['pph'];
$total_posts_hour += $pph;
$total_posts += $r['max'];
$boards[$i]['pph'] = $pph;
2015-03-11 00:20:55 +01:00
$boards[$i]['ppd'] = $pph*24;
2014-09-24 01:26:27 +02:00
$boards[$i]['max'] = $r['max'];
2014-09-29 09:17:00 +02:00
$boards[$i]['uniq_ip'] = $r['uniq_ip'];
2014-12-03 09:10:28 +01:00
$boards[$i]['tags'] = $tags;
2015-03-11 00:20:55 +01:00
if ($write_maxes) fwrite($fp, $board['uri'] . ':' . $boards[$i]['max'] . "\n");
2014-09-24 01:26:27 +02:00
}
2015-03-11 00:20:55 +01:00
if ($write_maxes) fclose($fp);
2014-09-24 01:26:27 +02:00
usort($boards,
function ($a, $b) {
2014-10-07 03:01:01 +02:00
$x = $b['uniq_ip'] - $a['uniq_ip'];
2014-09-24 01:26:27 +02:00
if ($x) { return $x;
//} else { return strcmp($a['uri'], $b['uri']); }
} else { return $b['max'] - $a['max']; }
});
$hidden_boards_total = 0;
2014-09-27 01:52:02 +02:00
$rows = array();
2014-09-24 01:26:27 +02:00
foreach ($boards as $i => &$board) {
$board_config = @file_get_contents($board['uri'].'/config.php');
$boardCONFIG = array();
if ($board_config && $board['uri'] !== 'int') {
$board_config = str_replace('$config', '$boardCONFIG', $board_config);
$board_config = str_replace('<?php', '', $board_config);
2014-11-10 07:17:50 +01:00
@eval($board_config);
2014-09-24 01:26:27 +02:00
}
$showboard = $board['indexed'];
2014-09-24 01:26:27 +02:00
$locale = isset($boardCONFIG['locale'])?$boardCONFIG['locale']:'en';
2014-09-25 22:50:37 +02:00
$board['title'] = utf8tohtml($board['title']);
2014-09-24 01:26:27 +02:00
$locale_arr = explode('_', $locale);
$locale_short = isset($locale_arr[1]) ? strtolower($locale_arr[1]) : strtolower($locale_arr[0]);
$locale_short = str_replace('.utf-8', '', $locale_short);
2014-09-26 03:15:17 +02:00
$country = get_country($locale_short);
2014-09-26 03:38:23 +02:00
if ($board['uri'] === 'int') {$locale_short = 'eo'; $locale = 'eo'; $country = 'Esperanto';}
2014-09-24 01:26:27 +02:00
$board['img'] = "<img class=\"flag flag-$locale_short\" src=\"/static/blank.gif\" style=\"width:16px;height:11px;\" alt=\"$country\" title=\"$country\">";
2014-09-24 01:26:27 +02:00
if ($showboard || $admin) {
if (!$showboard) {
$lock = ' <i class="fa fa-lock" title="No index"></i>';
} else {
$lock = '';
}
$board['ago'] = human_time_diff(strtotime($board['time']));
} else {
unset($boards[$i]);
$hidden_boards_total += 1;
}
}
$n_boards = sizeof($boards);
$t_boards = $hidden_boards_total + $n_boards;
2014-12-03 09:10:28 +01:00
$boards = array_values($boards);
arsort($all_tags);
2014-09-24 01:26:27 +02:00
$config['additional_javascript'] = array('js/jquery.min.js', 'js/jquery.tablesorter.min.js');
2015-01-29 02:55:58 +01:00
$body = Element("8chan/boards-tags.html", array("config" => $config, "n_boards" => $n_boards, "t_boards" => $t_boards, "hidden_boards_total" => $hidden_boards_total, "total_posts" => $total_posts, "total_posts_hour" => $total_posts_hour, "boards" => $boards, "last_update" => date('r'), "uptime_p" => shell_exec('uptime -p'), 'tags' => $all_tags, 'top2k' => false));
2014-09-27 01:52:02 +02:00
2014-09-24 01:26:27 +02:00
$html = Element("page.html", array("config" => $config, "body" => $body, "title" => "Boards on &infin;chan"));
2015-03-11 00:20:55 +01:00
$boards_top2k = $boards;
array_splice($boards_top2k, 2000);
$boards_top2k = array_values($boards_top2k);
$body = Element("8chan/boards-tags.html", array("config" => $config, "n_boards" => $n_boards, "t_boards" => $t_boards, "hidden_boards_total" => $hidden_boards_total, "total_posts" => $total_posts, "total_posts_hour" => $total_posts_hour, "boards" => $boards_top2k, "last_update" => date('r'), "uptime_p" => shell_exec('uptime -p'), 'tags' => $all_tags, 'top2k' => true));
2015-01-29 02:55:58 +01:00
$html_top2k = Element("page.html", array("config" => $config, "body" => $body, "title" => "Boards on &infin;chan"));
2014-09-24 01:26:27 +02:00
if ($admin) {
echo $html;
} else {
2015-03-11 00:20:55 +01:00
foreach ($boards as $i => &$b) { unset($b['img']); }
2014-09-24 01:26:27 +02:00
file_write("boards.json", json_encode($boards));
2014-12-03 09:10:28 +01:00
file_write("tags.json", json_encode($all_tags));
2014-10-29 07:22:13 +01:00
foreach ($boards as $i => $b) {
if (in_array($b['uri'], $config['no_top_bar_boards'])) {
unset($boards[$i]);
}
unset($boards[$i]['img']);
}
2015-01-01 07:28:49 +01:00
array_splice($boards, 48);
2014-10-29 07:22:13 +01:00
$boards = array_values($boards);
file_write("boards-top20.json", json_encode($boards));
2015-01-29 02:55:58 +01:00
file_write("boards.html", $html_top2k);
file_write("boards_full.html", $html);
2014-09-24 01:26:27 +02:00
echo 'Done';
}