| 1 |
<?php |
<?php |
| 2 |
// $Id: browscap.module,v 1.6.2.3.2.6 2009/06/08 11:37:43 robloach Exp $ |
// $Id: browscap.module,v 1.6.2.3.2.7 2009/09/16 22:11:57 greggles Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 86 |
function browscap_exit() { |
function browscap_exit() { |
| 87 |
// If monitoring is enabled, record the browser |
// If monitoring is enabled, record the browser |
| 88 |
if (variable_get('browscap_monitor', FALSE)) { |
if (variable_get('browscap_monitor', FALSE)) { |
| 89 |
$browser = browscap_get_browser(); |
if ($browser = browscap_get_browser()) { |
| 90 |
$browserstring = substr(trim($browser['parent']), 0, 255); |
$browserstring = substr(trim($browser['parent']), 0, 255); |
| 91 |
if ($browserstring == '' or $browserstring == 'Default Browser') { |
if ($browserstring == '' or $browserstring == 'Default Browser') { |
| 92 |
$browserstring = trim($_SERVER['HTTP_USER_AGENT']); |
$browserstring = trim($_SERVER['HTTP_USER_AGENT']); |
| 93 |
} |
} |
| 94 |
db_query("UPDATE {browscap_statistics} SET counter = counter + 1, is_crawler=%d ". |
db_query("UPDATE {browscap_statistics} SET counter = counter + 1, is_crawler=%d ". |
| 95 |
"WHERE parent='%s'", $browser['crawler'], $browserstring); |
"WHERE parent='%s'", $browser['crawler'], $browserstring); |
| 96 |
// If we affected 0 rows, this is the first time we've seen this browser |
// If we affected 0 rows, this is the first time we've seen this browser |
| 97 |
if (!db_affected_rows()) { |
if (!db_affected_rows()) { |
| 98 |
// We must create a new row to store counters for the new browser. |
// We must create a new row to store counters for the new browser. |
| 99 |
db_query('INSERT INTO {browscap_statistics} (parent,counter,is_crawler) '. |
db_query('INSERT INTO {browscap_statistics} (parent,counter,is_crawler) '. |
| 100 |
"VALUES('%s', 1, %d)", $browserstring, $browser['crawler']); |
"VALUES('%s', 1, %d)", $browserstring, $browser['crawler']); |
| 101 |
|
} |
| 102 |
} |
} |
| 103 |
} |
} |
| 104 |
} |
} |
| 200 |
$query .= tablesort_sql($header); |
$query .= tablesort_sql($header); |
| 201 |
|
|
| 202 |
$result = pager_query($query, 50, 0, $query_cnt); |
$result = pager_query($query, 50, 0, $query_cnt); |
| 203 |
|
$rows = array(); |
| 204 |
|
|
| 205 |
while ($useragent = db_fetch_object($result)) { |
while ($useragent = db_fetch_object($result)) { |
| 206 |
if (db_result(db_query_range("SELECT useragent FROM {browscap} WHERE useragent = '%s'", $useragent->parent, 0, 1))) { |
if (db_result(db_query_range("SELECT useragent FROM {browscap} WHERE useragent = '%s'", $useragent->parent, 0, 1))) { |
| 226 |
$rows[] = array(array('data' => $pager, 'colspan' => 2)); |
$rows[] = array(array('data' => $pager, 'colspan' => 2)); |
| 227 |
} |
} |
| 228 |
|
|
| 229 |
$output .= theme('table', $header, $rows); |
$output = theme('table', $header, $rows); |
| 230 |
|
|
| 231 |
print theme('page', $output, $title); |
print theme('page', $output, $title); |
| 232 |
} |
} |
| 233 |
|
|
| 234 |
|
/** |
| 235 |
|
* Provide data about the current browser or a known user agent string. |
| 236 |
|
* |
| 237 |
|
* @param string $useragent |
| 238 |
|
* Optional user agent string to test. If empty use the value from the current request. |
| 239 |
|
* @return array |
| 240 |
|
* An array of data about the user agent. |
| 241 |
|
*/ |
| 242 |
function browscap_get_browser($useragent = NULL) { |
function browscap_get_browser($useragent = NULL) { |
| 243 |
if (!$useragent) { |
if (!$useragent) { |
| 244 |
$useragent = $_SERVER['HTTP_USER_AGENT']; |
$useragent = $_SERVER['HTTP_USER_AGENT']; |
| 262 |
//$browserinfo->tables = $browserinfo->htmltables; |
//$browserinfo->tables = $browserinfo->htmltables; |
| 263 |
cache_set($cacheid, $browserinfo, 'cache_browscap'); |
cache_set($cacheid, $browserinfo, 'cache_browscap'); |
| 264 |
} |
} |
| 265 |
$info = unserialize($browserinfo->data); |
if (isset($browserinfo) && isset($browserinfo->data)) { |
| 266 |
$info['useragent'] = $useragent; |
$info = unserialize($browserinfo->data); |
| 267 |
$info['browser_name_pattern'] = strtr($browserinfo->useragent, '%_', '*?'); |
$info['useragent'] = $useragent; |
| 268 |
return $info; |
$info['browser_name_pattern'] = strtr($browserinfo->useragent, '%_', '*?'); |
| 269 |
|
return $info; |
| 270 |
|
} |
| 271 |
} |
} |
| 272 |
|
|
|
|
|
| 273 |
// A numeric interpretation of browscap.csv's TRUE/FALSE/default fields |
// A numeric interpretation of browscap.csv's TRUE/FALSE/default fields |
| 274 |
function _browscap_boolean($value) { |
function _browscap_boolean($value) { |
| 275 |
switch ($value) { |
switch ($value) { |