ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/BBClone/branches/0.6.4-RC1/show_time.php
Revision: 357
Committed: Sun Dec 13 12:21:06 2015 UTC (8 years, 11 months ago) by matthys
File size: 11931 byte(s)
Log Message:
0.6.4-Release Candidate 1

File Contents

# Content
1 <?php
2 /* This file is part of BBClone (A PHP based Web Counter on Steroids)
3 *
4 * SVN FILE $Id$
5 *
6 * Copyright (C) 2001-2016, 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", "BBClone - 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, $BBC_TIME_OFFSET, $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(date("G"), date("i"), 0, date("m"), date("d") - ($nb - $k - 1), date("Y"));
101 // Correct for time offset
102 $bbc_weekend = $bbc_weekend + ($BBC_TIME_OFFSET * 60);
103 if (date("w", $bbc_weekend) == 0 || date("w", $bbc_weekend) == 6) { // 0 is Sunday and 6 is Saturday
104 $bbc_column_color = "weekend-column"; // column color for weekends
105 }
106 } else if ($nb == 24) {
107 $bbc_weekend = mktime(date("G") - ($nb - $k - 1), date("i"), 0, date("m"), date("d"), date("Y"));
108 // Correct for time offset
109 $bbc_weekend = $bbc_weekend + ($BBC_TIME_OFFSET * 60);
110 } else {
111 $bbc_weekend = mktime(date("G"), date("i"), 0, date("m") - ($nb - $k - 1), date("d"), date("Y"));
112 // Correct for time offset
113 $bbc_weekend = $bbc_weekend + ($BBC_TIME_OFFSET * 60);
114 }
115
116 $str .= "<td class=\"sky\" height=\"".($height - $bar_height)."\" "
117 ."style=\"border-style: none ".bbc_graph_spacer(($nb - 1), $k, $y)."\">"
118 ."<span class=\"label-graph-ydata\">$numb</span>"
119 ."</td>\n"
120 ."</tr>\n"
121 ."<tr class=\"".$bbc_column_color."\">\n";
122 if ($nb > 27 || $nb == 7) { // make sure it's a month and not a week, hour, etc.
123 // week (7 days), and full month (>27 days)
124 $str .= "<td title=\"".date_format_translated($translation['global_day_format'], $bbc_weekend)."&nbsp;&laquo;".$y[$k]."&raquo;\" height=\"$bar_height\" class=\"brd\" ";
125 } else if ($nb == 24) {
126 // hours (24)
127 $str .= "<td title=\"".date_format_translated($translation['global_hours_format'], $bbc_weekend)."&nbsp;&laquo;".$y[$k]."&raquo;\" height=\"$bar_height\" class=\"brd\" ";
128 } else {
129 // months (12)
130 $str .= "<td title=\"".date_format_translated($translation['global_month_format'], $bbc_weekend)."&nbsp;&laquo;".$y[$k]."&raquo;\" height=\"$bar_height\" class=\"brd\" ";
131 }
132 $str .= "style=\"border-style: solid ".bbc_graph_spacer(($nb - 1), $k, $y)."\"></td>\n";
133 }
134 else $str .= "<td height=\"$height\"></td>\n";
135
136 $str .= "</tr>\n"
137 ."</table>\n"
138 ."</td>\n";
139 }
140
141 $str .= "</tr>\n"
142 ."<tr class=\"bottombox\">\n";
143
144 for ($k = 0; $k < $nb; $k++) {
145 $str .= "<td class=\"center\" width=\"$bar_width\" height=\"15\">\n"
146 ."<table class=\"brd\" style=\"border-style: solid none none\" align=\"center\" border=\"0\" "
147 ."cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n"
148 ."<tr>\n"
149 ."<td class=\"label-graph-xdata\">".$x[$k]."</td>\n"
150 ."</tr>\n"
151 ."</table>\n"
152 ."</td>\n";
153 }
154
155 $str .= "</tr>\n"
156 ."</table>\n";
157
158 $str .= "</div>";
159 return $str;
160 }
161
162 function bbc_show_plot_time_type($time_type, $width, $height) {
163 global $BBC_TIMESTAMP, $BBC_TIME_OFFSET, $translation, $access;
164
165 $last_time = isset($access['time']['last']) ? $access['time']['last'] : 0;
166 $current_time = $BBC_TIMESTAMP + ($BBC_TIME_OFFSET * 60);
167 $nb_seconds_in_day = 86400;
168 $nb_seconds_in_week = 7 * $nb_seconds_in_day;
169 $last_month = date("n", $last_time) - 1;
170 $nb_seconds_in_last_year = (date("L", $last_time) ? 366 : 365) * $nb_seconds_in_day;
171
172 switch ($time_type) {
173 case "hour":
174 $current_hour = date("G", $current_time);
175 $last_hour = date("G", $last_time);
176
177 for ($k = $current_hour - 23; $k <= $current_hour; $x[] = ($k < 0) ? ($k + 24) : $k, $k++);
178 for ($k = 0; $k < 24; $y[$k] = 0, $k++);
179 if (($current_time - $last_time) <= $nb_seconds_in_day) {
180 $elapsed = $current_hour - $last_hour;
181 $elapsed = ($elapsed < 0) ? ($elapsed + 24) : $elapsed;
182
183 for ($k = $elapsed; $k < 24; $k++) {
184 $y[$k - $elapsed] = $access['time']['hour'][($last_hour + 1 + $k) % 24];
185 }
186 }
187 break;
188
189 case "wday":
190 $day_name = array($translation['tstat_su'], $translation['tstat_mo'], $translation['tstat_tu'], $translation['tstat_we'], $translation['tstat_th'], $translation['tstat_fr'], $translation['tstat_sa']);
191
192 $current_wday = date("w", $current_time);
193 $last_wday = date("w", $last_time);
194
195 for ($k = $current_wday - 6; $k <= $current_wday;
196 $x[] = $day_name[($k < 0) ? $k + 7 : $k], $k++);
197 for ($k = 0; $k < 7; $y[$k] = 0, $k++);
198 if (($current_time - $last_time) <= $nb_seconds_in_week) {
199 $elapsed = $current_wday - $last_wday;
200 $elapsed = ($elapsed < 0) ? $elapsed + 7 : $elapsed;
201
202 for ($k = $elapsed; $k < 7; $k++) {
203 $y[$k - $elapsed] = $access['time']['wday'][($last_wday + 1 + $k) % 7];
204 }
205 }
206 break;
207
208 case "day":
209 // We suppose that the first day of the month is 0 for array compatibility
210 $current_day = date("j", $current_time) - 1;
211 $last_day = date("j", $last_time) - 1;
212 $time_in_prec_month = $current_time - ($current_day + 1) * $nb_seconds_in_day;
213 $lg_prec_month = date("t", $time_in_prec_month);
214 $lg_prec_month = ($current_day >= $lg_prec_month) ? ($current_day + 1) : $lg_prec_month;
215 $current_month = date("n", $current_time);
216 $prec_month = date("n", $time_in_prec_month);
217
218 // Computing the $x
219 for ($k = $current_day + 1; $k < $lg_prec_month; $x[] = ($k + 1), $k++);
220 for ($k = 0; $k <= $current_day; $x[] = ($k + 1), $k++);
221 // Computing the $y
222 for ($k = 0; $k < 31; $y[$k] = 0, $k++);
223 if (($current_time - $last_time) <= ($lg_prec_month * $nb_seconds_in_day)) {
224 $elapsed = $current_day - $last_day;
225 $elapsed = ($elapsed < 0) ? ($elapsed + $lg_prec_month) : $elapsed;
226
227 for ($k = $elapsed; $k < $lg_prec_month; $k++) {
228 $y[$k - $elapsed] = $access['time']['day'][($last_day + 1 + $k) % $lg_prec_month];
229 }
230 }
231 break;
232
233 case "month":
234 $month_name = array($translation['tstat_jan'], $translation['tstat_feb'], $translation['tstat_mar'], $translation['tstat_apr'], $translation['tstat_may'], $translation['tstat_jun'],
235 $translation['tstat_jul'], $translation['tstat_aug'], $translation['tstat_sep'], $translation['tstat_oct'], $translation['tstat_nov'], $translation['tstat_dec']);
236
237 $current_month = date("n", $current_time) - 1;
238 $last_month = date("n", $last_time) - 1;
239
240 for ($k = $current_month - 11; $k <= $current_month; $x[] = $month_name[(($k < 0) ? ($k + 12) : $k)], $k++);
241 for ($k = 0; $k < 12; $y[$k] = 0, $k++);
242
243 if (($current_time - $last_time) <= $nb_seconds_in_last_year) {
244 $elapsed = $current_month - $last_month;
245 $elapsed = ($elapsed < 0) ? $elapsed + 12 : $elapsed;
246
247 for ($k = $elapsed; $k < 12; $k++) {
248 $y[$k - $elapsed] = $access['time']['month'][(($last_month + 1 + $k) % 12)];
249 }
250 }
251 break;
252 }
253 return bbc_plot($x, $y, $width, $height);
254 }
255
256 // Generate page (with use of the functions above)
257 echo $BBC_HTML->html_begin()
258 .$BBC_HTML->topbar()
259 // .$BBC_HTML->last_reset()
260 ."<table class=\"center\">\n"
261 ."<tr><td class=\"padding\">\n"
262 ."<table class=\"centerbox\">\n"
263 ."<tr>\n"
264 ."<td class=\"label\" colspan=\"2\"><br />".$translation['tstat_last_day']."</td>\n"
265 ."</tr>\n"
266 ."<tr>\n"
267 ."<td class=\"padding\" align=\"center\" colspan=\"2\">\n"
268 .bbc_show_plot_time_type("hour", 640, 200)
269 ."</td>\n"
270 ."</tr>\n"
271 ."<tr>\n"
272 ."<td class=\"label\">".$translation['tstat_last_week']."</td>\n"
273 ."<td class=\"label\">".$translation['tstat_last_year']."</td>\n"
274 ."</tr>\n"
275 ."<tr>\n"
276 ."<td class=\"padding\" align=\"center\">\n"
277 .bbc_show_plot_time_type("wday", 203, 200)
278 ."</td>\n"
279 ."<td class=\"padding\" align=\"center\">\n"
280 .bbc_show_plot_time_type("month", 407, 200)
281 ."</td>\n"
282 ."</tr>\n"
283 ."<tr>\n"
284 ."<td class=\"label\" colspan=\"2\">".$translation['tstat_last_month']."</td>\n"
285 ."</tr>\n"
286 ."<tr>\n"
287 ."<td class=\"padding\" align=\"center\" colspan=\"2\">\n"
288 .bbc_show_plot_time_type("day", 640, 200)
289 ."</td></tr></table></td></tr></table>\n"
290 .$BBC_HTML->copyright()
291 .$BBC_HTML->topbar(0, 1);
292
293 // END + DISPLAY Time Measuring, load-time of the page (see config)
294 global $BBC_LOADTIME;
295
296 if (!empty($BBC_LOADTIME)) {
297 $time = microtime();
298 $time = explode(' ', $time);
299 $time = $time[1] + $time[0];
300 $finish = $time;
301 $total_time = round(($finish - $start), 4);
302 echo "<div class=\"loadtime\">".$translation['generated'].$total_time.$translation['seconds']."</div>\n";
303 }
304
305 // End of HTML
306 echo $BBC_HTML->html_end()
307 ?>

Properties

Name Value
svn:keywords Id