ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/BBClone/trunk/show_global.php
Revision: 431
Committed: Sat Apr 29 06:32:02 2023 UTC (18 months, 3 weeks ago) by joku
File size: 13825 byte(s)
Log Message:
Schow Global Top now works correctly

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

Properties

Name Value
svn:keywords Id