-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpostsbytime.php
82 lines (66 loc) · 2.13 KB
/
postsbytime.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
<?php
require 'lib/function.php';
$_GET['id'] = filter_int($_GET['id']);
$qstrings = array();
if ($_GET['id']) {
$qstrings[] = "user = {$_GET['id']}";
$from = 'from '.$sql->resultq("SELECT name FROM users WHERE id = {$_GET['id']}");
} else {
$from = "from the board";
}
$_GET['posttime'] = isset($_GET['posttime']) ? (int) $_GET['posttime'] : 86400;
if (!$_GET['id'] && (!$_GET['posttime'] || $_GET['posttime'] > 2592000)) // All posts
$_GET['posttime'] = 2592000;
if ($_GET['posttime']) {
$qstrings[] = "date > ".(ctime()-$_GET['posttime']);
$during = ' during the last '.timeunits2($_GET['posttime']);
} else {
$during = "";
}
if (empty($qstrings)) $qwhere = '1';
else $qwhere = implode(' AND ', $qstrings);
$posts = $sql->query("
SELECT COUNT(*) AS cnt, FROM_UNIXTIME(date,'%k') AS hour
FROM posts
WHERE {$qwhere}
GROUP BY hour
");
pageheader("Posts by time of day");
$qid = ($_GET['id'] ? "id={$_GET['id']}&" : "");
?>
<span class="fonts">
Timeframe:
<a href='postsbytime.php?id=<?=$qid?>&posttime=86400'>Last day</a> |
<a href='postsbytime.php?id=<?=$qid?>&posttime=604800'>Last week</a> |
<a href='postsbytime.php?id=<?=$qid?>&posttime=2592000'>Last 30 days</a> |
<a href='postsbytime.php?id=<?=$qid?>&posttime=31536000'>Last year</a> |
<a href='postsbytime.php?id=<?=$qid?>&posttime=0'>All-time</a>
<br>
</span>
<span class="font"> Posts <?=$from?> by time of day<?=$during?>:</span>
<table class='table'>
<tr>
<td class='tdbgh center' width=100>Time</td>
<td class='tdbgh center' width=50>Posts</td>
<td class='tdbgh center'> </td>
</tr>
<?php
$postshour = array_fill(0, 24, 0);
$max = 0;
while($h = $sql->fetch($posts))
if (($postshour[$h['hour']] = $h['cnt']) > $max)
$max = $h['cnt'];
for($i = 0; $i < 24 ;++$i) {
$time = sprintf('%1$02d:00 - %1$02d:59', $i);
$bar = drawminibar($max, 8, $postshour[$i], "images/bar/{$numdir}bar-on.png");
?>
<tr>
<td class='tdbg2 fonts center'><?=$time?></td>
<td class='tdbg2 fonts center'><?=$postshour[$i]?></td>
<td class='tdbg1 fonts' width=*><?=$bar?></td>
</tr>
<?php
}
?> </table>
<?php
pagefooter();