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-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 Global Stats // |
23 |
/////////////////////// |
24 |
|
25 |
if(!defined("_BBC_PAGE_NAME")){define("_BBC_PAGE_NAME", "Show Global");} |
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_histcalc($array) { |
44 |
$result = 0; |
45 |
|
46 |
if (is_array($array)) { |
47 |
foreach ($array as $val) $result += $val; |
48 |
} |
49 |
return $result; |
50 |
} |
51 |
|
52 |
function bbc_rank_head($cat, $i18n, $flag = 0) { |
53 |
global $translation; |
54 |
|
55 |
return "<table class=\"centerdata\">\n" |
56 |
."<tr>\n" |
57 |
."<td colspan=\"".(!empty($flag) ? 3 : 4)."\" class=\"label\">".sprintf($translation[$i18n], $cat)."</td>\n" |
58 |
."</tr>\n"; |
59 |
} |
60 |
|
61 |
function bbc_list_item($icon, $item, $item_score, $total_score) { |
62 |
global $BBC_IMAGES_PATH; |
63 |
|
64 |
return "<tr>\n" |
65 |
.(!empty($icon) ? "<td align=\"left\"><img src=\"".$BBC_IMAGES_PATH.$icon |
66 |
."\" class=\"icon\" alt=\"$item\" title=\"$item\" /> </td>\n" : "") |
67 |
."<td align=\"left\">$item </td>\n" |
68 |
."<td align=\"right\"> $item_score</td>\n" |
69 |
."<td align=\"right\"> ".sprintf("%.2f%%", (round(10000 * $item_score / $total_score) / 100))."</td>\n" |
70 |
."</tr>\n"; |
71 |
} |
72 |
|
73 |
function bbc_rank_sum($cat, $flag = 0) { |
74 |
global $translation; |
75 |
|
76 |
return "<tr>\n" |
77 |
.(!empty($flag) ? "" : "<td> </td>\n") |
78 |
."<td align=\"left\"><b>".$translation['gstat_total']."</b> </td>\n" |
79 |
."<td align=\"right\"> <b>$cat</b></td>\n" |
80 |
."</tr></table>\n"; |
81 |
} |
82 |
|
83 |
function bbc_refgen($ref) { |
84 |
global $translation; |
85 |
|
86 |
if ($ref == "not_specified") return "<i>".$translation['misc_ignored']."</i>"; |
87 |
$ref_name = (($slash = strpos($ref, "/")) !== false) ? substr($ref, 0, $slash) : $ref; |
88 |
|
89 |
return "<script type=\"text/javascript\">\n" |
90 |
."<!--\n" |
91 |
."document.write('<a href=\"http://$ref\" rel=\"nofollow\" title=\"$ref_name\">$ref_name<\/a>');\n" |
92 |
."-->\n" |
93 |
."</script>\n" |
94 |
."<noscript><span title=\"$ref_name\">$ref_name</span></noscript>\n"; |
95 |
} |
96 |
|
97 |
function bbc_sort_page_count($page_a, $page_b) { |
98 |
if ($page_a['count'] === $page_b['count']) return 0; |
99 |
return (($page_a['count'] > $page_b['count']) ? -1 : 1); |
100 |
} |
101 |
|
102 |
// Main functions to generate Stats |
103 |
function bbc_show_browser() { |
104 |
global $BBC_IMAGES_PATH, $BBC_LIB_PATH, $BBC_MAXBROWSER, $translation, $access; |
105 |
|
106 |
if (is_readable($BBC_LIB_PATH."browser.php")) require($BBC_LIB_PATH."browser.php"); |
107 |
else return bbc_msg($BBC_LIB_PATH."browser.php"); |
108 |
|
109 |
$browser_tab = isset($access['stat']['browser']) ? $access['stat']['browser'] : array(); |
110 |
|
111 |
for ($browser_total = 0; list(, $browser_score) = each($browser_tab); $browser_total += $browser_score); |
112 |
|
113 |
arsort($browser_tab); |
114 |
reset($browser_tab); |
115 |
|
116 |
$str = bbc_rank_head($BBC_MAXBROWSER, "gstat_browsers"); |
117 |
|
118 |
for ($k = 0; (list($browser_type, $browser_score) = each($browser_tab)) && ($k < $BBC_MAXBROWSER); $k++) { |
119 |
if (!isset($browser[$browser_type])) { |
120 |
$str.= bbc_list_item("browser/question.png", $browser_type, $browser_score, $browser_total, 'browser'); |
121 |
continue; |
122 |
} |
123 |
|
124 |
$browser[$browser_type]['title'] = str_replace("other", $translation['misc_other'], $browser[$browser_type]['title']); |
125 |
|
126 |
$str.= bbc_list_item("browser/".$browser[$browser_type]['icon'].".png", $browser[$browser_type]['title'], |
127 |
$browser_score, $browser_total, 'browser'); |
128 |
} |
129 |
|
130 |
$str .= bbc_rank_sum($browser_total); |
131 |
return $str; |
132 |
} |
133 |
|
134 |
function bbc_show_os() { |
135 |
global $BBC_IMAGES_PATH, $BBC_LIB_PATH, $BBC_MAXOS, $translation, $access; |
136 |
|
137 |
if (is_readable($BBC_LIB_PATH."os.php")) require($BBC_LIB_PATH."os.php"); |
138 |
else return bbc_msg($BBC_LIB_PATH."os.php"); |
139 |
|
140 |
$os_tab = isset($access['stat']['os']) ? $access['stat']['os'] : array(); |
141 |
|
142 |
for ($os_total = 0; list(, $os_score) = each($os_tab); $os_total += $os_score); |
143 |
|
144 |
arsort($os_tab); |
145 |
reset($os_tab); |
146 |
|
147 |
$str = bbc_rank_head($BBC_MAXOS, "gstat_operating_systems"); |
148 |
|
149 |
for ($k = 0; (list($os_type, $os_score) = each($os_tab)) && ($k < $BBC_MAXOS); $k++) { |
150 |
if (!isset($os[$os_type])) { |
151 |
$str.= bbc_list_item("os/question.png", $os_type, $os_score, $os_total, 'os'); |
152 |
continue; |
153 |
} |
154 |
|
155 |
$os[$os_type]['title'] = str_replace("other", $translation['misc_other'], $os[$os_type]['title']); |
156 |
|
157 |
$str .= bbc_list_item("os/".$os[$os_type]['icon'].".png", $os[$os_type]['title'], $os_score, $os_total, 'os'); |
158 |
} |
159 |
|
160 |
$str .= bbc_rank_sum($os_total); |
161 |
return $str; |
162 |
} |
163 |
|
164 |
function bbc_show_extension() { |
165 |
global $access, $BBC_IMAGES_PATH, $BBC_MAXEXTENSION, $extensions, $translation; |
166 |
|
167 |
$ext_tab = isset($access['stat']['ext']) ? $access['stat']['ext'] : array(); |
168 |
|
169 |
for ($ext_total = 0; list(, $ext_score) = each($ext_tab); $ext_total += $ext_score); |
170 |
|
171 |
arsort($ext_tab); |
172 |
reset($ext_tab); |
173 |
|
174 |
$str = bbc_rank_head($BBC_MAXEXTENSION, "gstat_extensions"); |
175 |
|
176 |
for ($k = 0; (list($ext, $ext_score) = each($ext_tab)) && ($k < $BBC_MAXEXTENSION); $k++) { |
177 |
if (isset($extensions[$ext])) $label = $extensions[$ext]; |
178 |
else $label = $ext; |
179 |
$str .= bbc_list_item("ext/".$ext.".png", $label, $ext_score, $ext_total, 'ext'); |
180 |
} |
181 |
|
182 |
$str .= bbc_rank_sum($ext_total); |
183 |
return $str; |
184 |
} |
185 |
|
186 |
function bbc_show_robot() { |
187 |
global $access, $BBC_IMAGES_PATH, $BBC_LIB_PATH, $BBC_MAXROBOT, $translation; |
188 |
|
189 |
if (is_readable($BBC_LIB_PATH."robot.php")) require($BBC_LIB_PATH."robot.php"); |
190 |
else return bbc_msg($BBC_LIB_PATH."robot.php"); |
191 |
|
192 |
$robot_tab = isset($access['stat']['robot']) ? $access['stat']['robot'] : array(); |
193 |
|
194 |
for ($robot_total = 0; list(,$robot_score) = each($robot_tab); $robot_total += $robot_score); |
195 |
|
196 |
arsort($robot_tab); |
197 |
reset($robot_tab); |
198 |
|
199 |
$str = bbc_rank_head($BBC_MAXROBOT, "gstat_robots"); |
200 |
|
201 |
for ($k = 0; (list($robot_type, $robot_score) = each($robot_tab)) && ($k < $BBC_MAXROBOT); $k++) { |
202 |
if (!isset($robot[$robot_type])) { |
203 |
$str.= bbc_list_item("robot/robot.png", $robot_type, $robot_score, $robot_total, 'robot'); |
204 |
continue; |
205 |
} |
206 |
|
207 |
$str .= bbc_list_item("robot/".$robot[$robot_type]['icon'].".png", $robot[$robot_type]['title'], $robot_score, $robot_total, 'robot'); |
208 |
} |
209 |
|
210 |
$str .= bbc_rank_sum($robot_total); |
211 |
return $str; |
212 |
} |
213 |
|
214 |
function bbc_show_top_hosts() { |
215 |
global $access, $BBC_MAXHOST; |
216 |
|
217 |
$host_tab = isset($access['host']) ? $access['host'] : array(); |
218 |
|
219 |
for ($host_total = 0; list(, $host_score) = each($host_tab); $host_total += $host_score); |
220 |
|
221 |
arsort($host_tab); |
222 |
reset($host_tab); |
223 |
|
224 |
$str = bbc_rank_head($BBC_MAXHOST, "gstat_hosts", 1); |
225 |
|
226 |
for ($k = 0; ($k < $BBC_MAXHOST) && (list($host_name, $host_score) = each($host_tab)); $k++) { |
227 |
$str .= bbc_list_item("", $host_name, $host_score, $host_total, 'hosts'); |
228 |
} |
229 |
|
230 |
$str .= bbc_rank_sum($host_total, 1); |
231 |
return $str; |
232 |
} |
233 |
|
234 |
function bbc_show_top_pages() { |
235 |
global $BBC_MAXPAGE, $translation, $access; |
236 |
|
237 |
$page_tab = isset($access['page']) ? $access['page'] : array(); |
238 |
|
239 |
for ($page_total = 0; list(, $page_elem) = each($page_tab); $page_total += $page_elem['count']); |
240 |
|
241 |
uasort($page_tab, "bbc_sort_page_count"); |
242 |
reset($page_tab); |
243 |
|
244 |
$str = bbc_rank_head($BBC_MAXPAGE, "gstat_pages", 1); |
245 |
|
246 |
for ($k = 0; (list($page_name, $page_elem) = each($page_tab)) && ($k < $BBC_MAXPAGE); $k++) { |
247 |
$page_name = ($page_name == "index") ? $translation['navbar_main_site'] : $page_name; |
248 |
|
249 |
$str .= bbc_list_item("", "<a href=\"".$page_elem['uri']."\">$page_name</a>", $page_elem['count'], $page_total, 'pages'); |
250 |
} |
251 |
|
252 |
$str .= bbc_rank_sum($page_total, 1); |
253 |
return $str; |
254 |
} |
255 |
|
256 |
function bbc_show_top_origins() { |
257 |
global $BBC_MAXORIGIN, $translation, $access; |
258 |
|
259 |
$referer_tab = isset($access['referer']) ? $access['referer'] : array(); |
260 |
|
261 |
for ($referer_total = 0; list(, $referer_score) = each($referer_tab); $referer_total += $referer_score); |
262 |
|
263 |
arsort($referer_tab); |
264 |
reset($referer_tab); |
265 |
|
266 |
$str = bbc_rank_head($BBC_MAXORIGIN, "gstat_origins", 1); |
267 |
|
268 |
for ($k = 0; ($k < $BBC_MAXORIGIN) && (list($referer_name, $referer_score) = each($referer_tab)); $k++) { |
269 |
$str .= bbc_list_item("", bbc_refgen($referer_name), $referer_score, $referer_total, 'origins'); |
270 |
} |
271 |
|
272 |
$str .= bbc_rank_sum($referer_total, 1); |
273 |
return $str; |
274 |
} |
275 |
|
276 |
function bbc_show_top_keys() { |
277 |
global $BBC_MAXKEY, $translation, $access; |
278 |
|
279 |
$key_tab = isset($access['key']) ? $access['key'] : array(); |
280 |
|
281 |
for ($key_total = 0; list(, $key_score) = each($key_tab); $key_total += $key_score); |
282 |
|
283 |
arsort($key_tab); |
284 |
reset($key_tab); |
285 |
|
286 |
$str = bbc_rank_head($BBC_MAXKEY, "gstat_keys", 1); |
287 |
|
288 |
for ($k = 0; ($k < $BBC_MAXKEY) && (list($key_name, $key_score) = each($key_tab)); $k++) { |
289 |
$str .= bbc_list_item("", $key_name, $key_score, $key_total, 'keys'); |
290 |
} |
291 |
|
292 |
$str .= bbc_rank_sum($key_total, 1); |
293 |
return $str; |
294 |
} |
295 |
|
296 |
function bbc_show_access() { |
297 |
global $translation, $access; |
298 |
|
299 |
return "<table class=\"center\">\n" |
300 |
."<tr>\n" |
301 |
."<td colspan=\"11\" class=\"label\">".$translation['gstat_accesses']."</td></tr>\n" |
302 |
."<tr>\n" |
303 |
."<td align=\"left\">".$translation['tstat_last_year']." </td>\n" |
304 |
."<td align=\"right\">".(!empty($access['time']['month']) ? bbc_histcalc($access['time']['month']) : "0") |
305 |
."</td>\n" |
306 |
."<td>".str_repeat(" ", 6)."</td>\n" |
307 |
."<td align=\"left\">".$translation['tstat_last_month']." </td>\n" |
308 |
."<td align=\"right\">".((!empty($access['time']['month'])) ? bbc_histcalc($access['time']['day']) : "0") |
309 |
."</td>\n" |
310 |
."<td>".str_repeat(" ", 6)."</td>\n" |
311 |
."<td align=\"left\">".$translation['tstat_last_week']." </td>\n" |
312 |
."<td align=\"right\">".(!empty($access['time']['wday']) ? bbc_histcalc($access['time']['wday']) : "0") |
313 |
."</td>\n" |
314 |
."<td>".str_repeat(" ", 6)."</td>\n" |
315 |
."<td align=\"left\">".$translation['tstat_last_day']." </td>\n" |
316 |
."<td align=\"right\">".(!empty($access['time']['wday']) ? bbc_histcalc($access['time']['hour']) : "0") |
317 |
."</td></tr>\n" |
318 |
."<tr>\n" |
319 |
."<td colspan=\"3\"> </td>\n" |
320 |
."<td align=\"left\"><b>".$translation['gstat_total_visits']."</b> "."</td>\n" |
321 |
."<td align=\"right\">" |
322 |
."<b>".(!empty($access['stat']['totalvisits']) ? $access['stat']['totalvisits'] : "0")."</b>" |
323 |
."</td>\n" |
324 |
."<td>".str_repeat(" ", 6)."</td>\n" |
325 |
."<td align=\"left\"><b>".$translation['gstat_total_unique']."</b> </td>\n" |
326 |
."<td align=\"right\">" |
327 |
."<b>".(!empty($access['stat']['totalcount']) ? $access['stat']['totalcount'] : "0")."</b>" |
328 |
."</td>\n" |
329 |
."<td colspan=\"3\"> </td>\n" |
330 |
."</tr></table>\n"; |
331 |
} |
332 |
|
333 |
// Generate page (with use of the functions above) |
334 |
echo $BBC_HTML->html_begin() |
335 |
.$BBC_HTML->topbar() |
336 |
// .$BBC_HTML->last_reset() |
337 |
."<table class=\"center\">\n" |
338 |
."<tr><td class=\"padding\">\n" |
339 |
."<table class=\"centerbox\">\n" |
340 |
."<tr>\n" |
341 |
."<td class=\"padding top\">\n" |
342 |
.bbc_show_browser() |
343 |
."</td>\n" |
344 |
."<td class=\"padding top\">\n" |
345 |
.bbc_show_os() |
346 |
."</td>\n" |
347 |
."<td class=\"padding top\">\n" |
348 |
.bbc_show_extension() |
349 |
."</td>\n"; |
350 |
|
351 |
if (!empty($BBC_IGNORE_BOTS) && ($BBC_IGNORE_BOTS == 2)) { |
352 |
echo "</tr></table>\n" |
353 |
."</td>\n"; |
354 |
} |
355 |
else { |
356 |
echo "<td class=\"padding top\">\n" |
357 |
.bbc_show_robot() |
358 |
."</td></tr></table>\n" |
359 |
."</td>\n"; |
360 |
} |
361 |
|
362 |
echo "</tr>\n" |
363 |
."<tr>\n" |
364 |
."<td class=\"padding\">\n" |
365 |
."<table class=\"centerbox\">\n" |
366 |
."<tr>\n" |
367 |
."<td class=\"padding top\">\n" |
368 |
.bbc_show_top_hosts() |
369 |
."</td>\n" |
370 |
."<td class=\"padding top\">\n" |
371 |
.bbc_show_top_pages() |
372 |
."</td>\n" |
373 |
."<td class=\"padding top\">\n" |
374 |
.bbc_show_top_origins() |
375 |
."</td>\n" |
376 |
."<td class=\"padding top\">\n" |
377 |
.bbc_show_top_keys() |
378 |
."</td></tr></table>\n" |
379 |
."</td></tr>\n" |
380 |
."<tr>\n" |
381 |
."<td class=\"padding\">\n" |
382 |
."<table class=\"centerbox\">\n" |
383 |
."<tr>\n" |
384 |
."<td class=\"padding\">\n" |
385 |
.bbc_show_access() |
386 |
."</td></tr></table>\n" |
387 |
."</td></tr></table>\n" |
388 |
.$BBC_HTML->copyright() |
389 |
.$BBC_HTML->topbar(0, 1); |
390 |
|
391 |
// END + DISPLAY Time Measuring, load-time of the page (see config) |
392 |
global $BBC_LOADTIME; |
393 |
|
394 |
if (!empty($BBC_LOADTIME)) { |
395 |
$time = microtime(); |
396 |
$time = explode(' ', $time); |
397 |
$time = $time[1] + $time[0]; |
398 |
$finish = $time; |
399 |
$total_time = round(($finish - $start), 4); |
400 |
echo "<div class=\"loadtime\">".$translation['generated'].$total_time.$translation['seconds']."</div>\n"; |
401 |
} |
402 |
|
403 |
// End of HTML |
404 |
echo $BBC_HTML->html_end() |
405 |
?> |