From: Robert Kaiser Date: Mon, 1 Oct 2007 15:53:46 +0000 (+0200) Subject: deal with Gecko identifiers that include the build hour and add parsing of Gecko... X-Git-Url: https://git-public.kairo.at/?p=php-utility-classes.git;a=commitdiff_plain;h=a3e499ad3709e3d59996f3f0bb22f7983f64fcc2 deal with Gecko identifiers that include the build hour and add parsing of Gecko build date/time into the UA class itself --- diff --git a/include/classes/useragent.php-class b/include/classes/useragent.php-class index eba3ed2..dbcad27 100755 --- a/include/classes/useragent.php-class +++ b/include/classes/useragent.php-class @@ -97,6 +97,9 @@ class userAgent { // public function getGeckoDate() // returns the Gecko date for Gecko-based browsers, null for others // + // public function getGeckoTime() + // returns the Gecko build date/time as a unix epoch time number for Gecko-based browsers, null for others + // // *** functions for compat to older versions of this class *** // // public function isns() @@ -1099,6 +1102,24 @@ class userAgent { return $this->uadata['geckodate']; } + public function getGeckoTime() { + if (!isset($this->uadata['geckotime'])) { + $this->uadata['geckotime'] = null; + if (!is_null($this->getGeckoDate())) { + $use_time = (strlen($this->getGeckoDate()) > 8); + $gd_str = substr($this->getGeckoDate(),0,4).'-'.substr($this->getGeckoDate(),4,2).'-'.substr($this->getGeckoDate(),6,2); + if ($use_time) { + $gd_str .= substr($this->getGeckoDate(),8,2).':00'; + $old_tz = date_default_timezone_get(); + date_default_timezone_set("America/Los_Angeles"); + } + $this->uadata['geckotime'] = strtotime($gd_str); + if ($use_time) { date_default_timezone_set($old_tz); } + } + } + return $this->uadata['geckotime']; + } + public function isBot() { return $this->bot; } public function isns() { diff --git a/testbed/ua_test.php b/testbed/ua_test.php index 30b485a..4bcbd05 100644 --- a/testbed/ua_test.php +++ b/testbed/ua_test.php @@ -25,7 +25,10 @@ print("
The engine version is reported as "".$ua->getEngineVersion(). print("
The operating system is reported as "".$ua->getOS().""\n"); print("
The system platform is reported as "".$ua->getPlatform().""\n"); print("
The browser language is reported as "".$ua->getLanguage().""\n"); -if ($ua->hasEngine('gecko')) { print("
The Gecko date is reported as "".$ua->getGeckoDate().""\n"); } +if ($ua->hasEngine('gecko')) { + print("
The Gecko date is reported as "".$ua->getGeckoDate().""\n"); + print("
The full Gecko date/time is reported as "".date('r',$ua->getGeckoTime()).""\n"); +} print("

I conclude this must be ".$ua->getBrand()." ".$ua->getVersion()."\n"); print("
This is ".($ua->isBot()?"an":"no")." automated robot.\n");