ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/BBClone/trunk/lib/new_connect.php
Revision: 15
Committed: Thu Nov 21 13:05:03 2013 UTC (11 years ago) by matthys
File size: 3426 byte(s)
Log Message:
Setup lib folder and files.

File Contents

# Content
1 <?php
2 /* This file is part of BBClone (A PHP based Web Counter on Steroids)
3 *
4 * CVS FILE $Id: new_connect.php,v 1.43 2011/12/30 23:03:47 joku Exp $
5 *
6 * Copyright (C) 2001-2012, 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 // New Connect //
23 /////////////////
24
25 function bbc_get_extension($host, $addr) {
26 global $BBC_EXT_LOOKUP;
27
28 $ext = "";
29 if ($BBC_EXT_LOOKUP) {
30 // if plugin is defined, then try lookup via plugin
31 $ext = bbc_extension_plugin($host, $addr);
32 }
33
34 if ($ext) {
35 // plugin did find answer, so return it
36 return $ext;
37 }
38
39 // plugin did not find extention, try taking the last part of the hostname
40
41 $ext = strtolower(substr($host, (strrpos($host, ".") + 1)));
42 if (preg_match(":^[0-9]+$:", $ext)) {
43 return "numeric";
44 } else if (strpos($host, ".") === false) {
45 return "unknown";
46 } else {
47 return $ext;
48 }
49 }
50
51
52 function bbc_update_connect($connect) {
53 global $BBC_LIB_PATH;
54
55 // Sanity check has already been made in mark_page.php
56 foreach (array("browser", "os", "robot") as $i) require($BBC_LIB_PATH.$i.".php");
57
58 $connect['visits'] = 1;
59
60 // Detecting robots, browsers and os
61 foreach (array("robot", "browser", "os") as $rule) {
62 reset($$rule);
63
64 while (list(${$rule."_name"}, ${$rule."_elem"}) = each($$rule)) {
65 reset(${$rule."_elem"}['rule']);
66
67 while (list($pattern, $note) = each(${$rule."_elem"}['rule'])) {
68 if (!preg_match('~'.$pattern.'~i', $connect['agent'], $regs)) continue;
69 $connect[$rule] = ${$rule."_name"};
70
71 if (preg_match(":\\\\[0-9]{1}:" ,$note)) {
72 $str = preg_replace(":\\\\([0-9]{1}):", "\$regs[\\1]", $note);
73
74 eval("\$str = \"$str\";");
75
76 $connect[$rule."_note"] = $str;
77 } else if (preg_match(":^text\:.*:", $note)) {
78 $connect[$rule."_note"] = substr($note, 5);
79 }
80 break 2;
81 }
82 }
83 if (!empty($connect['robot'])) break;
84 }
85 return $connect;
86 }
87
88 function bbc_update_access($connect) {
89 global $access;
90
91 // Assign an identification number to the new connection
92 $connect['id'] = isset($access['stat']['totalcount']) ? ($access['stat']['totalcount'] + 1) : 1;
93
94 // Recording the detected extension in the global statistics
95 $access['stat']['ext'][$connect['ext']] = !isset($access['stat']['ext'][$connect['ext']]) ? 1 :
96 ++$access['stat']['ext'][$connect['ext']];
97
98 foreach (array("robot", "browser", "os") as $type) {
99 if (($type == "robot") && (empty($connect[$type]))) continue;
100
101 if (isset($access['stat'][$type][$connect[$type]])) $access['stat'][$type][$connect[$type]]++;
102 else $access['stat'][$type][$connect[$type]] = 1;
103
104 if (($type == "robot") && (!empty($connect[$type]))) break;
105 }
106 return $connect;
107 }
108 ?>