1 |
matthys |
18 |
<?php |
2 |
|
|
/* This file is part of BBClone (A PHP based Web Counter on Steroids) |
3 |
|
|
* |
4 |
|
|
* SVN FILE $Id: authors.txt 6 2013-11-21 12:36:57Z matthys $ |
5 |
|
|
* |
6 |
|
|
* Copyright (C) 2001-2013, the BBClone Team (see doc/authors.txt for details) |
7 |
|
|
* |
8 |
|
|
* This program is free software: you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation, either version 3 of the License, or |
11 |
|
|
* (at your option) any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* See doc/copying.txt for details |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
///////////////////// |
22 |
|
|
// Show Time Stats // |
23 |
|
|
///////////////////// |
24 |
|
|
|
25 |
|
|
if(!defined("_BBC_PAGE_NAME")){define("_BBC_PAGE_NAME", "Show Time");} |
26 |
|
|
|
27 |
|
|
// START Time Measuring, load-time of the page (see config) |
28 |
|
|
$time = microtime(); |
29 |
|
|
$time = explode(' ', $time); |
30 |
|
|
$time = $time[1] + $time[0]; |
31 |
|
|
$start = $time; |
32 |
|
|
|
33 |
|
|
// Read constants |
34 |
|
|
if (is_readable("constants.php")) require_once("constants.php"); |
35 |
|
|
else exit("ERROR: Unable to open constants.php"); |
36 |
|
|
|
37 |
|
|
foreach (array($BBC_CONFIG_FILE, $BBC_LIB_PATH."selectlang.php", $BBC_ACCESS_FILE) as $i) { |
38 |
|
|
if (is_readable($i)) require_once($i); |
39 |
|
|
else exit(bbc_msg($i)); |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
// Functions to calculate Stats |
43 |
|
|
function bbc_graph_spacer($last, $nr, $values) { |
44 |
|
|
if ($nr == $last) $str = "none"; |
45 |
|
|
else $str = ($values[$nr] > $values[($nr + 1)]) ? "solid" : "none"; |
46 |
|
|
|
47 |
|
|
$str .= " none "; |
48 |
|
|
|
49 |
|
|
if ($nr === 0) $str .= "none"; |
50 |
|
|
else $str .= ($values[$nr] >= $values[($nr - 1)]) ? "solid" : "none"; |
51 |
|
|
|
52 |
|
|
return $str; |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
// Plot a positive sequence of integers $y in function of a sequence $x |
56 |
|
|
// (whatever it is) in a box of size [$width * $height] in pixels |
57 |
|
|
function bbc_plot($x, $y, $width, $height) { |
58 |
|
|
global $BBC_IMAGES_PATH, $translation; |
59 |
|
|
|
60 |
|
|
// Various sizes |
61 |
|
|
$nb_x = count($x); |
62 |
|
|
$nb_y = count($y); |
63 |
|
|
$nb = !empty($x) ? min($nb_x, $nb_y) : $nb_y; |
64 |
|
|
$bar_width = round($width / $nb); |
65 |
|
|
|
66 |
|
|
$sum_y = array_sum($y); |
67 |
|
|
$nb_e = $nb; |
68 |
|
|
if ($nb_e == 12) { |
69 |
|
|
for ($i = 0; $i < 12; $i++) { |
70 |
|
|
if ($y[$i] != 0) { |
71 |
|
|
$nb_e = $nb_e-$i; |
72 |
|
|
break; |
73 |
|
|
} |
74 |
|
|
} |
75 |
|
|
} |
76 |
|
|
$avarage=round($sum_y/$nb_e); |
77 |
|
|
|
78 |
|
|
// Finding the max |
79 |
|
|
for ($k = 0, $max_y = 0; $k < $nb; $max_y = max($y[$k],$max_y), $k++); |
80 |
|
|
// The height of one unit |
81 |
|
|
$unit_height = !empty($max_y) ? (0.92 * ($height / $max_y)) : 0; |
82 |
|
|
|
83 |
|
|
$avarage_height = round($max_y*$unit_height) - round($avarage*$unit_height)+17; |
84 |
|
|
$str = "<div><div class=\"graph-line\" style=\"top:".$avarage_height."px; \"><p align=\"left\" style=\"color:#df5959; padding:0px;margin:0px;\"><em>".$translation['tstat_average'].": ".$avarage."</em></p></div>"; |
85 |
|
|
$str .= "<table class=\"centerbox\">\n" |
86 |
|
|
."<tr class=\"graph-background\">\n"; |
87 |
|
|
|
88 |
|
|
for ($k = 0; $k < $nb; $k++) { |
89 |
|
|
$bar_height = round($y[$k] * $unit_height); |
90 |
|
|
|
91 |
|
|
$str .= "<td class=\"nopadding\" width=\"$bar_width\" height=\"$height\">\n" |
92 |
|
|
."<table class=\"centerdata\">\n" |
93 |
|
|
."<tr>\n"; |
94 |
|
|
|
95 |
|
|
if ($y[$k]) { |
96 |
|
|
$numb = ($y[$k] >= 1000) ? substr(($tmp = $y[$k] / 1000) ,0 , (strpos($tmp, ".") + 2))."k" : $y[$k]; |
97 |
|
|
|
98 |
|
|
$bbc_column_color = "column"; // default column color |
99 |
|
|
if ($nb > 27 || $nb == 7) { // make sure it's a month and not a week, hour, etc. |
100 |
|
|
$bbc_weekend = mktime(0, 0, 0, date("m"), date("d") - ($nb - $k - 1), date("Y")); |
101 |
|
|
if (date("w", $bbc_weekend) == 0 || date("w", $bbc_weekend) == 6) { // 0 is Sunday and 6 is Saturday |
102 |
|
|
$bbc_column_color = "weekend-column"; // column color for weekends |
103 |
|
|
} |
104 |
|
|
} else if ($nb == 24) { |
105 |
|
|
$bbc_weekend = mktime(date("G") - ($nb - $k - 1), 0, 0, date("m"), date("d"), date("Y")); |
106 |
|
|
} else { |
107 |
|
|
$bbc_weekend = mktime(0, 0, 0, date("m") - ($nb - $k - 1), date("d"), date("Y")); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
$str .= "<td class=\"sky\" height=\"".($height - $bar_height)."\" " |
111 |
|
|
."style=\"border-style: none ".bbc_graph_spacer(($nb - 1), $k, $y)."\">" |
112 |
|
|
."<span class=\"label-graph-ydata\">$numb</span>" |
113 |
|
|
."</td>\n" |
114 |
|
|
."</tr>\n" |
115 |
|
|
."<tr class=\"".$bbc_column_color."\">\n"; |
116 |
|
|
if ($nb > 27 || $nb == 7) { // make sure it's a month and not a week, hour, etc. |
117 |
|
|
// week (7 days), and full month (>27 days) |
118 |
|
|
$str .= "<td title=\"".date_format_translated($translation['global_day_format'], $bbc_weekend)." «".$y[$k]."»\" height=\"$bar_height\" class=\"brd\" "; |
119 |
|
|
} else if ($nb == 24) { |
120 |
|
|
// hours (24) |
121 |
|
|
$str .= "<td title=\"".date_format_translated($translation['global_hours_format'], $bbc_weekend)." «".$y[$k]."»\" height=\"$bar_height\" class=\"brd\" "; |
122 |
|
|
} else { |
123 |
|
|
// months (12) |
124 |
|
|
$str .= "<td title=\"".date_format_translated($translation['global_month_format'], $bbc_weekend)." «".$y[$k]."»\" height=\"$bar_height\" class=\"brd\" "; |
125 |
|
|
} |
126 |
|
|
$str .= "style=\"border-style: solid ".bbc_graph_spacer(($nb - 1), $k, $y)."\"></td>\n"; |
127 |
|
|
} |
128 |
|
|
else $str .= "<td height=\"$height\"></td>\n"; |
129 |
|
|
|
130 |
|
|
$str .= "</tr>\n" |
131 |
|
|
."</table>\n" |
132 |
|
|
."</td>\n"; |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
$str .= "</tr>\n" |
136 |
|
|
."<tr class=\"bottombox\">\n"; |
137 |
|
|
|
138 |
|
|
for ($k = 0; $k < $nb; $k++) { |
139 |
|
|
$str .= "<td class=\"center\" width=\"$bar_width\" height=\"15\">\n" |
140 |
|
|
."<table class=\"brd\" style=\"border-style: solid none none\" align=\"center\" border=\"0\" " |
141 |
|
|
."cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n" |
142 |
|
|
."<tr>\n" |
143 |
|
|
."<td class=\"label-graph-xdata\">".$x[$k]."</td>\n" |
144 |
|
|
."</tr>\n" |
145 |
|
|
."</table>\n" |
146 |
|
|
."</td>\n"; |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
$str .= "</tr>\n" |
150 |
|
|
."</table>\n"; |
151 |
|
|
|
152 |
|
|
$str .= "</div>"; |
153 |
|
|
return $str; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
function bbc_show_plot_time_type($time_type, $width, $height) { |
157 |
|
|
global $BBC_TIMESTAMP, $BBC_TIME_OFFSET, $translation, $access; |
158 |
|
|
|
159 |
|
|
$last_time = isset($access['time']['last']) ? $access['time']['last'] : 0; |
160 |
|
|
$current_time = $BBC_TIMESTAMP + ($BBC_TIME_OFFSET * 60); |
161 |
|
|
$nb_seconds_in_day = 86400; |
162 |
|
|
$nb_seconds_in_week = 7 * $nb_seconds_in_day; |
163 |
|
|
$last_month = date("n", $last_time) - 1; |
164 |
|
|
$nb_seconds_in_last_year = (date("L", $last_time) ? 366 : 365) * $nb_seconds_in_day; |
165 |
|
|
|
166 |
|
|
switch ($time_type) { |
167 |
|
|
case "hour": |
168 |
|
|
$current_hour = date("G", $current_time); |
169 |
|
|
$last_hour = date("G", $last_time); |
170 |
|
|
|
171 |
|
|
for ($k = $current_hour - 23; $k <= $current_hour; $x[] = ($k < 0) ? ($k + 24) : $k, $k++); |
172 |
|
|
for ($k = 0; $k < 24; $y[$k] = 0, $k++); |
173 |
|
|
if (($current_time - $last_time) <= $nb_seconds_in_day) { |
174 |
|
|
$elapsed = $current_hour - $last_hour; |
175 |
|
|
$elapsed = ($elapsed < 0) ? ($elapsed + 24) : $elapsed; |
176 |
|
|
|
177 |
|
|
for ($k = $elapsed; $k < 24; $k++) { |
178 |
|
|
$y[$k - $elapsed] = $access['time']['hour'][($last_hour + 1 + $k) % 24]; |
179 |
|
|
} |
180 |
|
|
} |
181 |
|
|
break; |
182 |
|
|
|
183 |
|
|
case "wday": |
184 |
|
|
$day_name = array($translation['tstat_su'], $translation['tstat_mo'], $translation['tstat_tu'], $translation['tstat_we'], $translation['tstat_th'], $translation['tstat_fr'], $translation['tstat_sa']); |
185 |
|
|
|
186 |
|
|
$current_wday = date("w", $current_time); |
187 |
|
|
$last_wday = date("w", $last_time); |
188 |
|
|
|
189 |
|
|
for ($k = $current_wday - 6; $k <= $current_wday; |
190 |
|
|
$x[] = $day_name[($k < 0) ? $k + 7 : $k], $k++); |
191 |
|
|
for ($k = 0; $k < 7; $y[$k] = 0, $k++); |
192 |
|
|
if (($current_time - $last_time) <= $nb_seconds_in_week) { |
193 |
|
|
$elapsed = $current_wday - $last_wday; |
194 |
|
|
$elapsed = ($elapsed < 0) ? $elapsed + 7 : $elapsed; |
195 |
|
|
|
196 |
|
|
for ($k = $elapsed; $k < 7; $k++) { |
197 |
|
|
$y[$k - $elapsed] = $access['time']['wday'][($last_wday + 1 + $k) % 7]; |
198 |
|
|
} |
199 |
|
|
} |
200 |
|
|
break; |
201 |
|
|
|
202 |
|
|
case "day": |
203 |
|
|
// We suppose that the first day of the month is 0 for array compatibility |
204 |
|
|
$current_day = date("j", $current_time) - 1; |
205 |
|
|
$last_day = date("j", $last_time) - 1; |
206 |
|
|
$time_in_prec_month = $current_time - ($current_day + 1) * $nb_seconds_in_day; |
207 |
|
|
$lg_prec_month = date("t", $time_in_prec_month); |
208 |
|
|
$lg_prec_month = ($current_day >= $lg_prec_month) ? ($current_day + 1) : $lg_prec_month; |
209 |
|
|
$current_month = date("n", $current_time); |
210 |
|
|
$prec_month = date("n", $time_in_prec_month); |
211 |
|
|
|
212 |
|
|
// Computing the $x |
213 |
|
|
for ($k = $current_day + 1; $k < $lg_prec_month; $x[] = ($k + 1), $k++); |
214 |
|
|
for ($k = 0; $k <= $current_day; $x[] = ($k + 1), $k++); |
215 |
|
|
// Computing the $y |
216 |
|
|
for ($k = 0; $k < 31; $y[$k] = 0, $k++); |
217 |
|
|
if (($current_time - $last_time) <= ($lg_prec_month * $nb_seconds_in_day)) { |
218 |
|
|
$elapsed = $current_day - $last_day; |
219 |
|
|
$elapsed = ($elapsed < 0) ? ($elapsed + $lg_prec_month) : $elapsed; |
220 |
|
|
|
221 |
|
|
for ($k = $elapsed; $k < $lg_prec_month; $k++) { |
222 |
|
|
$y[$k - $elapsed] = $access['time']['day'][($last_day + 1 + $k) % $lg_prec_month]; |
223 |
|
|
} |
224 |
|
|
} |
225 |
|
|
break; |
226 |
|
|
|
227 |
|
|
case "month": |
228 |
|
|
$month_name = array($translation['tstat_jan'], $translation['tstat_feb'], $translation['tstat_mar'], $translation['tstat_apr'], $translation['tstat_may'], $translation['tstat_jun'], |
229 |
|
|
$translation['tstat_jul'], $translation['tstat_aug'], $translation['tstat_sep'], $translation['tstat_oct'], $translation['tstat_nov'], $translation['tstat_dec']); |
230 |
|
|
|
231 |
|
|
$current_month = date("n", $current_time) - 1; |
232 |
|
|
$last_month = date("n", $last_time) - 1; |
233 |
|
|
|
234 |
|
|
for ($k = $current_month - 11; $k <= $current_month; $x[] = $month_name[(($k < 0) ? ($k + 12) : $k)], $k++); |
235 |
|
|
for ($k = 0; $k < 12; $y[$k] = 0, $k++); |
236 |
|
|
|
237 |
|
|
if (($current_time - $last_time) <= $nb_seconds_in_last_year) { |
238 |
|
|
$elapsed = $current_month - $last_month; |
239 |
|
|
$elapsed = ($elapsed < 0) ? $elapsed + 12 : $elapsed; |
240 |
|
|
|
241 |
|
|
for ($k = $elapsed; $k < 12; $k++) { |
242 |
|
|
$y[$k - $elapsed] = $access['time']['month'][(($last_month + 1 + $k) % 12)]; |
243 |
|
|
} |
244 |
|
|
} |
245 |
|
|
break; |
246 |
|
|
} |
247 |
|
|
return bbc_plot($x, $y, $width, $height); |
248 |
|
|
} |
249 |
|
|
|
250 |
|
|
// Generate page (with use of the functions above) |
251 |
|
|
echo $BBC_HTML->html_begin() |
252 |
|
|
.$BBC_HTML->topbar() |
253 |
|
|
// .$BBC_HTML->last_reset() |
254 |
|
|
."<table class=\"center\">\n" |
255 |
|
|
."<tr><td class=\"padding\">\n" |
256 |
|
|
."<table class=\"centerbox\">\n" |
257 |
|
|
."<tr>\n" |
258 |
|
|
."<td class=\"label\" colspan=\"2\"><br />".$translation['tstat_last_day']."</td>\n" |
259 |
|
|
."</tr>\n" |
260 |
|
|
."<tr>\n" |
261 |
|
|
."<td class=\"padding\" align=\"center\" colspan=\"2\">\n" |
262 |
|
|
.bbc_show_plot_time_type("hour", 640, 200) |
263 |
|
|
."</td>\n" |
264 |
|
|
."</tr>\n" |
265 |
|
|
."<tr>\n" |
266 |
|
|
."<td class=\"label\">".$translation['tstat_last_week']."</td>\n" |
267 |
|
|
."<td class=\"label\">".$translation['tstat_last_year']."</td>\n" |
268 |
|
|
."</tr>\n" |
269 |
|
|
."<tr>\n" |
270 |
|
|
."<td class=\"padding\" align=\"center\">\n" |
271 |
|
|
.bbc_show_plot_time_type("wday", 203, 200) |
272 |
|
|
."</td>\n" |
273 |
|
|
."<td class=\"padding\" align=\"center\">\n" |
274 |
|
|
.bbc_show_plot_time_type("month", 407, 200) |
275 |
|
|
."</td>\n" |
276 |
|
|
."</tr>\n" |
277 |
|
|
."<tr>\n" |
278 |
|
|
."<td class=\"label\" colspan=\"2\">".$translation['tstat_last_month']."</td>\n" |
279 |
|
|
."</tr>\n" |
280 |
|
|
."<tr>\n" |
281 |
|
|
."<td class=\"padding\" align=\"center\" colspan=\"2\">\n" |
282 |
|
|
.bbc_show_plot_time_type("day", 640, 200) |
283 |
|
|
."</td></tr></table></td></tr></table>\n" |
284 |
|
|
.$BBC_HTML->copyright() |
285 |
|
|
.$BBC_HTML->topbar(0, 1); |
286 |
|
|
|
287 |
|
|
// END + DISPLAY Time Measuring, load-time of the page (see config) |
288 |
|
|
global $BBC_LOADTIME; |
289 |
|
|
|
290 |
|
|
if (!empty($BBC_LOADTIME)) { |
291 |
|
|
$time = microtime(); |
292 |
|
|
$time = explode(' ', $time); |
293 |
|
|
$time = $time[1] + $time[0]; |
294 |
|
|
$finish = $time; |
295 |
|
|
$total_time = round(($finish - $start), 4); |
296 |
|
|
echo "<div class=\"loadtime\">".$translation['generated'].$total_time.$translation['seconds']."</div>\n"; |
297 |
|
|
} |
298 |
|
|
|
299 |
|
|
// End of HTML |
300 |
|
|
echo $BBC_HTML->html_end() |
301 |
|
|
?> |