ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/BBClone/trunk/show_global.php
Revision: 394
Committed: Wed Dec 30 14:39:27 2020 UTC (3 years, 10 months ago) by joku
File size: 14455 byte(s)
Log Message:
update Copyright 

File Contents

# User Rev Content
1 joku 63 <?php
2     /* This file is part of BBClone (A PHP based Web Counter on Steroids)
3     *
4     * SVN FILE $Id$
5     *
6 joku 394 * Copyright (C) 2001-2021, the BBClone Team (see doc/authors.txt for details)
7 joku 63 *
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 matthys 208 if(!defined("_BBC_PAGE_NAME")){define("_BBC_PAGE_NAME", "BBClone - Show Global");}
26 joku 63
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\" />&nbsp;&nbsp;</td>\n" : "")
67     ."<td align=\"left\">$item&nbsp;</td>\n"
68     ."<td align=\"right\">&nbsp;$item_score</td>\n"
69     ."<td align=\"right\">&nbsp;".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>&nbsp;</td>\n")
78     ."<td align=\"left\"><b>".$translation['gstat_total']."</b>&nbsp;</td>\n"
79     ."<td align=\"right\">&nbsp;<b>$cat</b></td>\n"
80     ."</tr></table>\n";
81     }
82    
83     function bbc_refgen($ref) {
84     global $translation;
85    
86 joku 388 if ($ref == "not_specified") return "<i>".$translation['misc_ignored']."</i>";
87 joku 63 $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 joku 388
105 joku 63 global $BBC_IMAGES_PATH, $BBC_LIB_PATH, $BBC_MAXBROWSER, $translation, $access;
106    
107     if (is_readable($BBC_LIB_PATH."browser.php")) require($BBC_LIB_PATH."browser.php");
108     else return bbc_msg($BBC_LIB_PATH."browser.php");
109    
110     $browser_tab = isset($access['stat']['browser']) ? $access['stat']['browser'] : array();
111    
112 joku 388 for ($browser_total = 0; $browser_score = current($browser_tab), next($browser_tab); $browser_total += $browser_score);
113 joku 63
114     arsort($browser_tab);
115     reset($browser_tab);
116    
117     $str = bbc_rank_head($BBC_MAXBROWSER, "gstat_browsers");
118 joku 388
119     $k = 0;
120     foreach ($browser_tab as $browser_type => $browser_score) {
121     if($k > $BBC_MAXBROWSER) break; {
122     $k ++;
123     }
124 joku 63
125     if (!isset($browser[$browser_type])) {
126     $str.= bbc_list_item("browser/question.png", $browser_type, $browser_score, $browser_total, 'browser');
127     continue;
128     }
129    
130     $browser[$browser_type]['title'] = str_replace("other", $translation['misc_other'], $browser[$browser_type]['title']);
131    
132     $str.= bbc_list_item("browser/".$browser[$browser_type]['icon'].".png", $browser[$browser_type]['title'],
133     $browser_score, $browser_total, 'browser');
134 joku 388 }
135    
136 joku 63 $str .= bbc_rank_sum($browser_total);
137     return $str;
138     }
139    
140     function bbc_show_os() {
141 joku 388
142 joku 63 global $BBC_IMAGES_PATH, $BBC_LIB_PATH, $BBC_MAXOS, $translation, $access;
143    
144     if (is_readable($BBC_LIB_PATH."os.php")) require($BBC_LIB_PATH."os.php");
145     else return bbc_msg($BBC_LIB_PATH."os.php");
146    
147     $os_tab = isset($access['stat']['os']) ? $access['stat']['os'] : array();
148    
149 joku 388 for ($os_total = 0; $os_score = current($os_tab), next($os_tab); $os_total += $os_score);
150 joku 63
151     arsort($os_tab);
152     reset($os_tab);
153    
154     $str = bbc_rank_head($BBC_MAXOS, "gstat_operating_systems");
155    
156 joku 388 //for ($k = 0; (list($os_type, $os_score) = @each($os_tab)) && ($k < $BBC_MAXOS); $k++) {
157     $k = 0;
158     foreach ($os_tab as $os_type => $os_score) {
159     if($k > $BBC_MAXOS) break; {
160     $k ++;
161     }
162    
163     if (!isset($os[$os_type])) {
164 joku 63 $str.= bbc_list_item("os/question.png", $os_type, $os_score, $os_total, 'os');
165     continue;
166     }
167    
168     $os[$os_type]['title'] = str_replace("other", $translation['misc_other'], $os[$os_type]['title']);
169    
170     $str .= bbc_list_item("os/".$os[$os_type]['icon'].".png", $os[$os_type]['title'], $os_score, $os_total, 'os');
171     }
172    
173     $str .= bbc_rank_sum($os_total);
174     return $str;
175     }
176    
177     function bbc_show_extension() {
178 joku 388
179 joku 63 global $access, $BBC_IMAGES_PATH, $BBC_MAXEXTENSION, $extensions, $translation;
180    
181     $ext_tab = isset($access['stat']['ext']) ? $access['stat']['ext'] : array();
182    
183 joku 388 for ($ext_total = 0; $ext_score = current($ext_tab), next($ext_tab); $ext_total += $ext_score);
184 joku 63
185     arsort($ext_tab);
186     reset($ext_tab);
187    
188     $str = bbc_rank_head($BBC_MAXEXTENSION, "gstat_extensions");
189    
190 joku 388 //for ($k = 0; (list($ext, $ext_score) = each($ext_tab)) && ($k < $BBC_MAXEXTENSION); $k++) {
191     $k = 0;
192     foreach ($ext_tab as $ext => $ext_score) {
193     if($k > $BBC_MAXEXTENSION) break; {
194     $k ++;
195     }
196    
197     if (isset($extensions[$ext])) $label = $extensions[$ext];
198 joku 63 else $label = $ext;
199     $str .= bbc_list_item("ext/".$ext.".png", $label, $ext_score, $ext_total, 'ext');
200     }
201    
202     $str .= bbc_rank_sum($ext_total);
203     return $str;
204     }
205    
206     function bbc_show_robot() {
207 joku 388
208 joku 63 global $access, $BBC_IMAGES_PATH, $BBC_LIB_PATH, $BBC_MAXROBOT, $translation;
209    
210     if (is_readable($BBC_LIB_PATH."robot.php")) require($BBC_LIB_PATH."robot.php");
211     else return bbc_msg($BBC_LIB_PATH."robot.php");
212    
213     $robot_tab = isset($access['stat']['robot']) ? $access['stat']['robot'] : array();
214    
215 joku 388 for ($robot_total = 0; $robot_score = current($robot_tab), next($robot_tab); $robot_total += $robot_score);
216 joku 63
217     arsort($robot_tab);
218     reset($robot_tab);
219    
220     $str = bbc_rank_head($BBC_MAXROBOT, "gstat_robots");
221    
222 joku 388 //for ($k = 0; (list($robot_type, $robot_score) = @each($robot_tab)) && ($k < $BBC_MAXROBOT); $k++) {
223     $k = 0;
224     foreach ($robot_tab as $robot_type => $robot_score) {
225     if($k > $BBC_MAXROBOT) break; {
226     $k ++;
227     }
228    
229    
230     if (!isset($robot[$robot_type])) {
231 joku 63 $str.= bbc_list_item("robot/robot.png", $robot_type, $robot_score, $robot_total, 'robot');
232     continue;
233     }
234    
235     $str .= bbc_list_item("robot/".$robot[$robot_type]['icon'].".png", $robot[$robot_type]['title'], $robot_score, $robot_total, 'robot');
236     }
237    
238     $str .= bbc_rank_sum($robot_total);
239     return $str;
240     }
241    
242     function bbc_show_top_hosts() {
243 joku 388
244 joku 63 global $access, $BBC_MAXHOST;
245    
246     $host_tab = isset($access['host']) ? $access['host'] : array();
247    
248 joku 388 for ($host_total = 0; $host_score = current($host_tab), next($host_tab); $host_total += $host_score);
249 joku 63
250     arsort($host_tab);
251     reset($host_tab);
252    
253     $str = bbc_rank_head($BBC_MAXHOST, "gstat_hosts", 1);
254    
255 joku 388 //for ($k = 0; ($k < $BBC_MAXHOST) && (list($host_name, $host_score) = @each($host_tab)); $k++) {
256     $k = 0;
257     foreach ($host_tab as $host_name => $host_score) {
258     if($k > $BBC_MAXHOST) break; {
259     $k ++;
260     }
261    
262     $str .= bbc_list_item("", $host_name, $host_score, $host_total, 'hosts');
263 joku 63 }
264    
265     $str .= bbc_rank_sum($host_total, 1);
266     return $str;
267     }
268    
269     function bbc_show_top_pages() {
270     global $BBC_MAXPAGE, $translation, $access;
271    
272     $page_tab = isset($access['page']) ? $access['page'] : array();
273    
274 joku 388 for ($page_total = 0; $page_elem = current($page_tab), next($page_tab); $page_total += $page_elem['count']);
275 joku 63
276     uasort($page_tab, "bbc_sort_page_count");
277     reset($page_tab);
278    
279     $str = bbc_rank_head($BBC_MAXPAGE, "gstat_pages", 1);
280    
281 joku 388 //for ($k = 0; (list($page_name, $page_elem) = @each($page_tab)) && ($k < $BBC_MAXPAGE); $k++) {
282     $k = 0;
283     foreach ($page_tab as $page_name => $page_elem) {
284     if($k > $BBC_MAXPAGE) break; {
285     $k ++;
286     }
287    
288 joku 63 $page_name = ($page_name == "index") ? $translation['navbar_main_site'] : $page_name;
289    
290     $str .= bbc_list_item("", "<a href=\"".$page_elem['uri']."\">$page_name</a>", $page_elem['count'], $page_total, 'pages');
291     }
292    
293     $str .= bbc_rank_sum($page_total, 1);
294     return $str;
295     }
296    
297     function bbc_show_top_origins() {
298     global $BBC_MAXORIGIN, $translation, $access;
299    
300     $referer_tab = isset($access['referer']) ? $access['referer'] : array();
301    
302 joku 388 for ($referer_total = 0; $referer_score = current($referer_tab), next($referer_tab); $referer_total += $referer_score);
303 joku 63
304     arsort($referer_tab);
305     reset($referer_tab);
306    
307     $str = bbc_rank_head($BBC_MAXORIGIN, "gstat_origins", 1);
308    
309 joku 388 //for ($k = 0; ($k < $BBC_MAXORIGIN) && (list($referer_name, $referer_score) = @each($referer_tab)); $k++) {
310     $k = 0;
311     foreach ($referer_tab as $referer_name => $referer_score) {
312     if($k > $BBC_MAXORIGIN) break; {
313     $k ++;
314     }
315    
316     $str .= bbc_list_item("", bbc_refgen($referer_name), $referer_score, $referer_total, 'origins');
317 joku 63 }
318    
319     $str .= bbc_rank_sum($referer_total, 1);
320     return $str;
321     }
322    
323     function bbc_show_top_keys() {
324     global $BBC_MAXKEY, $translation, $access;
325    
326     $key_tab = isset($access['key']) ? $access['key'] : array();
327    
328 joku 388 for ($key_total = 0; $key_score = current($key_tab), next($key_tab); $key_total += $key_score);
329 joku 63
330     arsort($key_tab);
331     reset($key_tab);
332    
333     $str = bbc_rank_head($BBC_MAXKEY, "gstat_keys", 1);
334    
335 joku 388 //for ($k = 0; ($k < $BBC_MAXKEY) && (list($key_name, $key_score) = @each($key_tab)); $k++) {
336     $k = 0;
337     foreach ($key_tab as $key_name => $key_score) {
338     if($k > $BBC_MAXKEY) break; {
339     $k ++;
340     }
341    
342     $str .= bbc_list_item("", $key_name, $key_score, $key_total, 'keys');
343 joku 63 }
344    
345     $str .= bbc_rank_sum($key_total, 1);
346     return $str;
347     }
348    
349     function bbc_show_access() {
350     global $translation, $access;
351    
352     return "<table class=\"center\">\n"
353     ."<tr>\n"
354     ."<td colspan=\"11\" class=\"label\">".$translation['gstat_accesses']."</td></tr>\n"
355     ."<tr>\n"
356     ."<td align=\"left\">".$translation['tstat_last_year']."&nbsp;&nbsp;</td>\n"
357     ."<td align=\"right\">".(!empty($access['time']['month']) ? bbc_histcalc($access['time']['month']) : "0")
358     ."</td>\n"
359     ."<td>".str_repeat("&nbsp;", 6)."</td>\n"
360     ."<td align=\"left\">".$translation['tstat_last_month']."&nbsp;&nbsp;</td>\n"
361     ."<td align=\"right\">".((!empty($access['time']['month'])) ? bbc_histcalc($access['time']['day']) : "0")
362     ."</td>\n"
363     ."<td>".str_repeat("&nbsp;", 6)."</td>\n"
364     ."<td align=\"left\">".$translation['tstat_last_week']."&nbsp;&nbsp;</td>\n"
365     ."<td align=\"right\">".(!empty($access['time']['wday']) ? bbc_histcalc($access['time']['wday']) : "0")
366     ."</td>\n"
367     ."<td>".str_repeat("&nbsp;", 6)."</td>\n"
368     ."<td align=\"left\">".$translation['tstat_last_day']."&nbsp;&nbsp;</td>\n"
369     ."<td align=\"right\">".(!empty($access['time']['wday']) ? bbc_histcalc($access['time']['hour']) : "0")
370     ."</td></tr>\n"
371     ."<tr>\n"
372     ."<td colspan=\"3\">&nbsp;</td>\n"
373     ."<td align=\"left\"><b>".$translation['gstat_total_visits']."</b>&nbsp;&nbsp;"."</td>\n"
374     ."<td align=\"right\">"
375     ."<b>".(!empty($access['stat']['totalvisits']) ? $access['stat']['totalvisits'] : "0")."</b>"
376     ."</td>\n"
377     ."<td>".str_repeat("&nbsp;", 6)."</td>\n"
378     ."<td align=\"left\"><b>".$translation['gstat_total_unique']."</b>&nbsp;&nbsp;</td>\n"
379     ."<td align=\"right\">"
380     ."<b>".(!empty($access['stat']['totalcount']) ? $access['stat']['totalcount'] : "0")."</b>"
381     ."</td>\n"
382     ."<td colspan=\"3\">&nbsp;</td>\n"
383     ."</tr></table>\n";
384     }
385    
386     // Generate page (with use of the functions above)
387     echo $BBC_HTML->html_begin()
388     .$BBC_HTML->topbar()
389     // .$BBC_HTML->last_reset()
390     ."<table class=\"center\">\n"
391     ."<tr><td class=\"padding\">\n"
392     ."<table class=\"centerbox\">\n"
393     ."<tr>\n"
394     ."<td class=\"padding top\">\n"
395     .bbc_show_browser()
396     ."</td>\n"
397     ."<td class=\"padding top\">\n"
398     .bbc_show_os()
399     ."</td>\n"
400     ."<td class=\"padding top\">\n"
401     .bbc_show_extension()
402     ."</td>\n";
403    
404     if (!empty($BBC_IGNORE_BOTS) && ($BBC_IGNORE_BOTS == 2)) {
405     echo "</tr></table>\n"
406     ."</td>\n";
407     }
408     else {
409     echo "<td class=\"padding top\">\n"
410     .bbc_show_robot()
411     ."</td></tr></table>\n"
412     ."</td>\n";
413     }
414    
415     echo "</tr>\n"
416     ."<tr>\n"
417     ."<td class=\"padding\">\n"
418     ."<table class=\"centerbox\">\n"
419     ."<tr>\n"
420     ."<td class=\"padding top\">\n"
421     .bbc_show_top_hosts()
422     ."</td>\n"
423     ."<td class=\"padding top\">\n"
424     .bbc_show_top_pages()
425     ."</td>\n"
426     ."<td class=\"padding top\">\n"
427     .bbc_show_top_origins()
428     ."</td>\n"
429     ."<td class=\"padding top\">\n"
430     .bbc_show_top_keys()
431     ."</td></tr></table>\n"
432     ."</td></tr>\n"
433     ."<tr>\n"
434     ."<td class=\"padding\">\n"
435     ."<table class=\"centerbox\">\n"
436     ."<tr>\n"
437     ."<td class=\"padding\">\n"
438     .bbc_show_access()
439     ."</td></tr></table>\n"
440     ."</td></tr></table>\n"
441     .$BBC_HTML->copyright()
442     .$BBC_HTML->topbar(0, 1);
443    
444     // END + DISPLAY Time Measuring, load-time of the page (see config)
445     global $BBC_LOADTIME;
446    
447     if (!empty($BBC_LOADTIME)) {
448     $time = microtime();
449     $time = explode(' ', $time);
450     $time = $time[1] + $time[0];
451     $finish = $time;
452     $total_time = round(($finish - $start), 4);
453     echo "<div class=\"loadtime\">".$translation['generated'].$total_time.$translation['seconds']."</div>\n";
454     }
455    
456     // End of HTML
457     echo $BBC_HTML->html_end()
458 joku 243 ?>

Properties

Name Value
svn:keywords Id