cvs: pear /Net_UserAgent Detect.php /Net_UserAgent/Detect Apc.php
| From: | Jason Rust | Date: | Wed, 19 Sep 2007 21:31:55 +0000 |
| Subject: | cvs: pear /Net_UserAgent Detect.php /Net_UserAgent/Detect Apc.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-48631@lists.php.net to get a copy of this message | ||
jrust Wed Sep 19 21:31:55 2007 UTC
Added files:
/pear/Net_UserAgent/Detect Apc.php
Modified files:
/pear/Net_UserAgent Detect.php
Log:
* Adding support windows ce (Lucas Nealan)
* Adding support for IE mobile (Lucas Nealan)
* Quirk detect for AJAX has been updated (Lucas Nealan)
* Added a subclass, Net_UserAgent_Detect_APC, which allows Net_UserAgent_Detect results to be
cached which makes subsequent lookups for that useragent very fast
http://cvs.php.net/viewvc.cgi/pear/Net_UserAgent/Detect.php?r1=1.25&r2=1.26&diff_format=u Index: pear/Net_UserAgent/Detect.php diff -u pear/Net_UserAgent/Detect.php:1.25 pear/Net_UserAgent/Detect.php:1.26 --- pear/Net_UserAgent/Detect.php:1.25 Mon Apr 23 21:24:39 2007 +++ pear/Net_UserAgent/Detect.php Wed Sep 19 21:31:54 2007 @@ -18,7 +18,7 @@ // | Jason Rust <jrust@php.net> | // +----------------------------------------------------------------------+ -// $Id: Detect.php,v 1.25 2007/04/23 21:24:39 jrust Exp $ +// $Id: Detect.php,v 1.26 2007/09/19 21:31:54 jrust Exp $ // }}} // {{{ constants @@ -71,7 +71,7 @@ * @return object Net_UserAgent_Detect instance */ function &singleton($in_userAgent = null, $in_detect = null) - { + { static $instance; if (!isset($instance)) { @@ -113,8 +113,8 @@ $hasRun = true; // {{{ set up static properties - $in_userAgent = isset($options['userAgent']) && is_null($in_userAgent) ? $options['userAgent'] : null; - $in_detect = isset($options['detectOptions']) && is_null($in_detect) ? $options['detectOptions'] : null; + $in_userAgent = isset($options['userAgent']) && is_null($in_userAgent) ? $options['userAgent'] : $in_userAgent; + $in_detect = isset($options['detectOptions']) && is_null($in_detect) ? $options['detectOptions'] : $in_detect; // User agent string that is being analyzed $userAgent = &Net_UserAgent_Detect::_getStaticProperty('userAgent'); @@ -127,7 +127,7 @@ // Array that stores all of the flags for the operating systems, // and in some cases the versions of those operating systems (windows) $os = &Net_UserAgent_Detect::_getStaticProperty('os'); - $os = array_flip(array('win', 'win95', 'win16', 'win31', 'win9x', 'win98', 'winme', 'win2k', 'winxp', 'winnt', 'win2003', 'os2', 'mac', 'mac68k', 'macppc', 'linux', 'unix', 'vms', 'sun', 'sun4', 'sun5', 'suni86', 'irix', 'irix5', 'irix6', 'hpux', 'hpux9', 'hpux10', 'aix', 'aix1', 'aix2', 'aix3', 'aix4', 'sco', 'unixware', 'mpras', 'reliant', 'dec', 'sinix', 'freebsd', 'bsd')); + $os = array_flip(array('win', 'win95', 'win16', 'win31', 'win9x', 'win98', 'wince', 'winme', 'win2k', 'winxp', 'winnt', 'win2003', 'os2', 'mac', 'mac68k', 'macppc', 'linux', 'unix', 'vms', 'sun', 'sun4', 'sun5', 'suni86', 'irix', 'irix5', 'irix6', 'hpux', 'hpux9', 'hpux10', 'aix', 'aix1', 'aix2', 'aix3', 'aix4', 'sco', 'unixware', 'mpras', 'reliant', 'dec', 'sinix', 'freebsd', 'bsd')); // Array which stores known issues with the given client that can // be used for on the fly tweaking so that the client may recieve @@ -269,7 +269,7 @@ $browser['opera6'] = strpos($agt, 'opera 6') !== false || strpos($agt, 'opera/6') !== false; $browser['opera7'] = strpos($agt, 'opera 7') !== false || strpos($agt, 'opera/7') !== false; $browser['opera8'] = strpos($agt, 'opera 8') !== false || strpos($agt, 'opera/8') !== false; - $browser['opera9'] = strpos($agt, 'opera 8') !== false || strpos($agt, 'opera/9') !== false; + $browser['opera9'] = strpos($agt, 'opera 9') !== false || strpos($agt, 'opera/9') !== false; $browser['opera5up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4']; $browser['opera6up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5']; $browser['opera7up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6']; @@ -288,6 +288,7 @@ $browser['hotjava'] = strpos($agt, 'hotjava') !== false; $browser['hotjava3'] = $browser['hotjava'] && $majorVersion == 3; $browser['hotjava3up'] = $browser['hotjava'] && $majorVersion >= 3; + $browser['iemobile'] = strpos($agt, 'iemobile') !== false || strpos($agt, 'windows ce') !== false && (strpos($agt, 'ppc') !== false || strpos($agt, 'smartphone') !== false); } if ($detectFlags[NET_USERAGENT_DETECT_ALL] || @@ -296,6 +297,9 @@ if ($browser['ns2'] || $browser['ie3']) { Net_UserAgent_Detect::setFeature('javascript', 1.0); } + elseif ($browser['iemobile']) { + // no javascript + } elseif ($browser['opera5up']) { Net_UserAgent_Detect::setFeature('javascript', 1.3); } @@ -324,6 +328,7 @@ $os['win16'] = strpos($agt, 'win16') !== false || strpos($agt, '16bit') !== false || strpos($agt, 'windows 3.1') !== false || strpos($agt, 'windows 16-bit') !== false; $os['win31'] = strpos($agt, 'windows 3.1') !== false || strpos($agt, 'win16') !== false || strpos($agt, 'windows 16-bit') !== false; $os['winme'] = strpos($agt, 'win 9x 4.90') !== false; + $os['wince'] = strpos($agt, 'windows ce') !== false; $os['win2k'] = strpos($agt, 'windows nt 5.0') !== false; $os['winxp'] = strpos($agt, 'windows nt 5.1') !== false; $os['win2003'] = strpos($agt, 'windows nt 5.2') !== false; @@ -404,7 +409,7 @@ Net_UserAgent_Detect::setFeature('gecko', $matches[1]); } - if ($browser['gecko'] || $browser['ie5up'] || $browser['konq'] || $browser['opera8up']) { + if ($browser['gecko'] || ($browser['ie5up'] && !$browser['iemobile']) || $browser['konq'] || $browser['opera8up'] && !$os['wince']) { Net_UserAgent_Detect::setFeature('ajax'); } @@ -683,6 +688,7 @@ if (is_null($in_osStrings)) { $in_osStrings = array( 'win' => 'Microsoft Windows', + 'wince' => 'Microsoft Windows CE', 'win9x' => 'Microsoft Windows 9x', 'winme' => 'Microsoft Windows Millenium', 'win2k' => 'Microsoft Windows 2000', http://cvs.php.net/viewvc.cgi/pear/Net_UserAgent/Detect/Apc.php?view=markup&rev=1.1 Index: pear/Net_UserAgent/Detect/Apc.php +++ pear/Net_UserAgent/Detect/Apc.php <?php // +----------------------------------------------------------------------+ // | PHP version 4.2 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Lucas Nealan <lucas@facebook.com> | // +----------------------------------------------------------------------+ // $Id: Apc.php,v 1.1 2007/09/19 21:31:55 jrust Exp $ require_once 'Net_UserAgent/detect.php'; class Net_UserAgent_Detect_APC extends Net_UserAgent_Detect { var $key = ''; function Net_UserAgent_Detect_APC($in_userAgent = null, $in_detect = null, $ua_cache_window = 600) { $data = ''; $restored = false; $ua_cache_timeout = apc_fetch('useragent:cache_timeout'); // don't cache after time period if ($ua_cache_window > 0) { if (!$ua_cache_timeout) { // check apc uptime and disable after x mins $apc_data = apc_cache_info('file', true); if (isset($apc_data['start_time'])) { $uptime = $apc_data['start_time']; if (time() - $uptime > $ua_cache_window) { // timeout and disable after 10 minutes of uptime apc_store('useragent:cache_timeout', true); $ua_cache_timeout = true; // don't cache this one either } } } if (!$this->key) { $key_flags = ''; if ($in_detect !== null) { $key_flags = implode('-', $in_detect); } $this->key = 'useragent:'.md5($in_userAgent.$key_flags); } if ($data = apc_fetch($this->key)) { $success = null; $data = unserialize($data); if ($data) { $restored = $this->cache_restore($data); } } } if (!$data) { $this->detect($in_userAgent, $in_detect); if ($ua_cache_window > 0 && !$ua_cache_timeout) { $this->cache_save(); } } } function &singleton($in_userAgent = null, $in_detect = null) { static $instance; if (!isset($instance)) { $instance = new Net_UserAgent_Detect_APC($in_userAgent, $in_detect); } return $instance; } function cache_restore($cache) { if (is_array($cache)) { foreach($cache as $prop => $value) { $ptr = Net_UserAgent_Detect::_getStaticProperty($prop); $ptr = $value; } return true; } return false; } function cache_save() { if ($this->key) { $data = array('browser' => Net_UserAgent_Detect::_getStaticProperty('browser'), 'features' => Net_UserAgent_Detect::_getStaticProperty('features'), 'leadingIdentifier' => Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier'), 'majorVersion' => Net_UserAgent_Detect::_getStaticProperty('majorVersion'), 'options' => Net_UserAgent_Detect::_getStaticProperty('options'), 'os' => Net_UserAgent_Detect::_getStaticProperty('os'), 'quirks' => Net_UserAgent_Detect::_getStaticProperty('quirks'), 'subVersion' => Net_UserAgent_Detect::_getStaticProperty('subVersion'), 'userAgent' => Net_UserAgent_Detect::_getStaticProperty('userAgent'), 'version' => Net_UserAgent_Detect::_getStaticProperty('version'), ); apc_store($this->key, serialize($data)); } } } ?>
http://cvs.php.net/viewvc.cgi/pear/Net_UserAgent/Detect.php?r1=1.25&r2=1.26&diff_format=u Index: pear/Net_UserAgent/Detect.php diff -u pear/Net_UserAgent/Detect.php:1.25 pear/Net_UserAgent/Detect.php:1.26 --- pear/Net_UserAgent/Detect.php:1.25 Mon Apr 23 21:24:39 2007 +++ pear/Net_UserAgent/Detect.php Wed Sep 19 21:31:54 2007 @@ -18,7 +18,7 @@ // | Jason Rust <jrust@php.net> | // +----------------------------------------------------------------------+ -// $Id: Detect.php,v 1.25 2007/04/23 21:24:39 jrust Exp $ +// $Id: Detect.php,v 1.26 2007/09/19 21:31:54 jrust Exp $ // }}} // {{{ constants @@ -71,7 +71,7 @@ * @return object Net_UserAgent_Detect instance */ function &singleton($in_userAgent = null, $in_detect = null) - { + { static $instance; if (!isset($instance)) { @@ -113,8 +113,8 @@ $hasRun = true; // {{{ set up static properties - $in_userAgent = isset($options['userAgent']) && is_null($in_userAgent) ? $options['userAgent'] : null; - $in_detect = isset($options['detectOptions']) && is_null($in_detect) ? $options['detectOptions'] : null; + $in_userAgent = isset($options['userAgent']) && is_null($in_userAgent) ? $options['userAgent'] : $in_userAgent; + $in_detect = isset($options['detectOptions']) && is_null($in_detect) ? $options['detectOptions'] : $in_detect; // User agent string that is being analyzed $userAgent = &Net_UserAgent_Detect::_getStaticProperty('userAgent'); @@ -127,7 +127,7 @@ // Array that stores all of the flags for the operating systems, // and in some cases the versions of those operating systems (windows) $os = &Net_UserAgent_Detect::_getStaticProperty('os'); - $os = array_flip(array('win', 'win95', 'win16', 'win31', 'win9x', 'win98', 'winme', 'win2k', 'winxp', 'winnt', 'win2003', 'os2', 'mac', 'mac68k', 'macppc', 'linux', 'unix', 'vms', 'sun', 'sun4', 'sun5', 'suni86', 'irix', 'irix5', 'irix6', 'hpux', 'hpux9', 'hpux10', 'aix', 'aix1', 'aix2', 'aix3', 'aix4', 'sco', 'unixware', 'mpras', 'reliant', 'dec', 'sinix', 'freebsd', 'bsd')); + $os = array_flip(array('win', 'win95', 'win16', 'win31', 'win9x', 'win98', 'wince', 'winme', 'win2k', 'winxp', 'winnt', 'win2003', 'os2', 'mac', 'mac68k', 'macppc', 'linux', 'unix', 'vms', 'sun', 'sun4', 'sun5', 'suni86', 'irix', 'irix5', 'irix6', 'hpux', 'hpux9', 'hpux10', 'aix', 'aix1', 'aix2', 'aix3', 'aix4', 'sco', 'unixware', 'mpras', 'reliant', 'dec', 'sinix', 'freebsd', 'bsd')); // Array which stores known issues with the given client that can // be used for on the fly tweaking so that the client may recieve @@ -269,7 +269,7 @@ $browser['opera6'] = strpos($agt, 'opera 6') !== false || strpos($agt, 'opera/6') !== false; $browser['opera7'] = strpos($agt, 'opera 7') !== false || strpos($agt, 'opera/7') !== false; $browser['opera8'] = strpos($agt, 'opera 8') !== false || strpos($agt, 'opera/8') !== false; - $browser['opera9'] = strpos($agt, 'opera 8') !== false || strpos($agt, 'opera/9') !== false; + $browser['opera9'] = strpos($agt, 'opera 9') !== false || strpos($agt, 'opera/9') !== false; $browser['opera5up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4']; $browser['opera6up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5']; $browser['opera7up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6']; @@ -288,6 +288,7 @@ $browser['hotjava'] = strpos($agt, 'hotjava') !== false; $browser['hotjava3'] = $browser['hotjava'] && $majorVersion == 3; $browser['hotjava3up'] = $browser['hotjava'] && $majorVersion >= 3; + $browser['iemobile'] = strpos($agt, 'iemobile') !== false || strpos($agt, 'windows ce') !== false && (strpos($agt, 'ppc') !== false || strpos($agt, 'smartphone') !== false); } if ($detectFlags[NET_USERAGENT_DETECT_ALL] || @@ -296,6 +297,9 @@ if ($browser['ns2'] || $browser['ie3']) { Net_UserAgent_Detect::setFeature('javascript', 1.0); } + elseif ($browser['iemobile']) { + // no javascript + } elseif ($browser['opera5up']) { Net_UserAgent_Detect::setFeature('javascript', 1.3); } @@ -324,6 +328,7 @@ $os['win16'] = strpos($agt, 'win16') !== false || strpos($agt, '16bit') !== false || strpos($agt, 'windows 3.1') !== false || strpos($agt, 'windows 16-bit') !== false; $os['win31'] = strpos($agt, 'windows 3.1') !== false || strpos($agt, 'win16') !== false || strpos($agt, 'windows 16-bit') !== false; $os['winme'] = strpos($agt, 'win 9x 4.90') !== false; + $os['wince'] = strpos($agt, 'windows ce') !== false; $os['win2k'] = strpos($agt, 'windows nt 5.0') !== false; $os['winxp'] = strpos($agt, 'windows nt 5.1') !== false; $os['win2003'] = strpos($agt, 'windows nt 5.2') !== false; @@ -404,7 +409,7 @@ Net_UserAgent_Detect::setFeature('gecko', $matches[1]); } - if ($browser['gecko'] || $browser['ie5up'] || $browser['konq'] || $browser['opera8up']) { + if ($browser['gecko'] || ($browser['ie5up'] && !$browser['iemobile']) || $browser['konq'] || $browser['opera8up'] && !$os['wince']) { Net_UserAgent_Detect::setFeature('ajax'); } @@ -683,6 +688,7 @@ if (is_null($in_osStrings)) { $in_osStrings = array( 'win' => 'Microsoft Windows', + 'wince' => 'Microsoft Windows CE', 'win9x' => 'Microsoft Windows 9x', 'winme' => 'Microsoft Windows Millenium', 'win2k' => 'Microsoft Windows 2000', http://cvs.php.net/viewvc.cgi/pear/Net_UserAgent/Detect/Apc.php?view=markup&rev=1.1 Index: pear/Net_UserAgent/Detect/Apc.php +++ pear/Net_UserAgent/Detect/Apc.php <?php // +----------------------------------------------------------------------+ // | PHP version 4.2 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Lucas Nealan <lucas@facebook.com> | // +----------------------------------------------------------------------+ // $Id: Apc.php,v 1.1 2007/09/19 21:31:55 jrust Exp $ require_once 'Net_UserAgent/detect.php'; class Net_UserAgent_Detect_APC extends Net_UserAgent_Detect { var $key = ''; function Net_UserAgent_Detect_APC($in_userAgent = null, $in_detect = null, $ua_cache_window = 600) { $data = ''; $restored = false; $ua_cache_timeout = apc_fetch('useragent:cache_timeout'); // don't cache after time period if ($ua_cache_window > 0) { if (!$ua_cache_timeout) { // check apc uptime and disable after x mins $apc_data = apc_cache_info('file', true); if (isset($apc_data['start_time'])) { $uptime = $apc_data['start_time']; if (time() - $uptime > $ua_cache_window) { // timeout and disable after 10 minutes of uptime apc_store('useragent:cache_timeout', true); $ua_cache_timeout = true; // don't cache this one either } } } if (!$this->key) { $key_flags = ''; if ($in_detect !== null) { $key_flags = implode('-', $in_detect); } $this->key = 'useragent:'.md5($in_userAgent.$key_flags); } if ($data = apc_fetch($this->key)) { $success = null; $data = unserialize($data); if ($data) { $restored = $this->cache_restore($data); } } } if (!$data) { $this->detect($in_userAgent, $in_detect); if ($ua_cache_window > 0 && !$ua_cache_timeout) { $this->cache_save(); } } } function &singleton($in_userAgent = null, $in_detect = null) { static $instance; if (!isset($instance)) { $instance = new Net_UserAgent_Detect_APC($in_userAgent, $in_detect); } return $instance; } function cache_restore($cache) { if (is_array($cache)) { foreach($cache as $prop => $value) { $ptr = Net_UserAgent_Detect::_getStaticProperty($prop); $ptr = $value; } return true; } return false; } function cache_save() { if ($this->key) { $data = array('browser' => Net_UserAgent_Detect::_getStaticProperty('browser'), 'features' => Net_UserAgent_Detect::_getStaticProperty('features'), 'leadingIdentifier' => Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier'), 'majorVersion' => Net_UserAgent_Detect::_getStaticProperty('majorVersion'), 'options' => Net_UserAgent_Detect::_getStaticProperty('options'), 'os' => Net_UserAgent_Detect::_getStaticProperty('os'), 'quirks' => Net_UserAgent_Detect::_getStaticProperty('quirks'), 'subVersion' => Net_UserAgent_Detect::_getStaticProperty('subVersion'), 'userAgent' => Net_UserAgent_Detect::_getStaticProperty('userAgent'), 'version' => Net_UserAgent_Detect::_getStaticProperty('version'), ); apc_store($this->key, serialize($data)); } } } ?>