forked from ctrlcctrlv/infinity
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathboards.php
executable file
·95 lines (64 loc) · 2.5 KB
/
boards.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
include "inc/functions.php";
$admin = isset($mod["type"]) && $mod["type"]<=30;
if (php_sapi_name() == 'fpm-fcgi' && !$admin && count($_GET) == 0) {
error('Cannot be run directly.');
}
$statistics = [];
$statistics_hours = 24;
$sort_by = 'unical_count';
$query = prepare(sprintf("SELECT * FROM ``boards`` WHERE `indexed`=1"));
$query->execute() or error(db_error($query));
$boards = $query->fetchAll(PDO::FETCH_ASSOC);
foreach ($boards as $board) {
$sta = getBoardStatistics($board['uri'], $statistics_hours);
$sta['uri'] = $board['uri'];
$sta['title'] = $board['title'];
for ($i=0; $i<count($statistics); $i++) {
if($sta[$sort_by] > $statistics[$i][$sort_by]){
array_splice($statistics, $i, 0, array($sta));
$sta = null;
break;
}
}
if ($sta) {
array_push($statistics, $sta);
}
}
$HTML = Element("site/index.html", array(
"config" => $config,
"boards" => $statistics,
"date" => date("H:i:s / j-m-Y"),
));
file_put_contents("index.html", $HTML);
file_put_contents("boards.json", json_encode($statistics));
function getBoardStatistics($uri, $hours){
$min_time = time() - ($hours * 3600);
$ago3days = time() - 24 * 3600 * 72;
$hourAgo = time() - 24 * 3600;
$table_name = "posts_$uri";
$query = prepare("SELECT count(`id`) as post_count,count(DISTINCT(`ip`)) as unical_count FROM `$table_name` WHERE `time`> :min_time");
$query->bindParam(':min_time', $min_time, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$boards = $query->fetchAll(PDO::FETCH_ASSOC);
$query = prepare("SELECT count(`id`) as post_count,count(DISTINCT(`ip`)) as unical_count FROM `$table_name` WHERE `time`> :min_time");
$query->bindParam(':min_time', $ago3days, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$boards72 = $query->fetchAll(PDO::FETCH_ASSOC);
$query = prepare("SELECT count(`id`) as post_count,count(DISTINCT(`ip`)) as unical_count FROM `$table_name` WHERE `time`> :min_time");
$query->bindParam(':min_time', $hourAgo, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$pph = $query->fetchAll(PDO::FETCH_ASSOC);
$query = prepare("SELECT max(`id`) as 'post_total' FROM `$table_name`");
$query->execute() or error(db_error($query));
$max = $query->fetchAll(PDO::FETCH_ASSOC);
return array(
'post_count' => $boards[0]['post_count'],
'unical_count' => $boards[0]['unical_count'],
'post_total' => $max[0]['post_total'],
// for api old 72 style
'pph' => $pph[0]['unical_count'],
'active' => $boards72[0]['unical_count'],
'new' => true,
);
}