private static function checkSpider() { $botRegex = '(bot|borg|google(^tv)|yahoo|slurp|msnbot|msrbot|openbot|archiver|netresearch|lycos|scooter|altavista|teoma|gigabot|baiduspider|blitzbot|oegp|charlotte|furlbot|http%20client|polybot|htdig|ichiro|mogimogi|larbin|pompos|scrubby|searchsight|seekbot|semanticdiscovery|silk|snappy|speedy|spider|voila|vortex|voyager|zao|zeal|fast\\-webcrawler|converacrawler|dataparksearch|findlinks)'; return preg_match("/" . $botRegex . "/i", self::$ua); } /** * Adds the user agent hash and user agent to a list for retrieval in the demo (or for any reason i guess) * @param {Object} the core template object * * @return {Object} the core template object "filled out" from ua-parser-php */ private static function createUAProperties($obj) { // include the ua-parser-php library to rip apart user agent strings require_once __DIR__ . "/lib/ua-parser-php/UAParser.php"; // classify the user agent string so we can learn more what device this really is. more for readability than anything $userAgent = UA::parse(); // save properties from ua-parser-php foreach ($userAgent as $key => $value) { $obj->{$key} = $value; } return $obj; } } // if this is a request from features.js.php don't run the build function if (!isset($p)) { $ua = Detector::build(); // include the browserFamily library to classify the browser by features require_once __DIR__ . "/lib/feature-family/featureFamily.php"; $ua->family = featureFamily::find($ua); }
<?php /*! * Detector Util - Update family property across all profiles * * Copyright (c) 2011-2012 Dave Olsen, http://dmolsen.com * Licensed under the MIT license */ // include the browserFamily lib to figure out what family this belongs too require __DIR__ . "/../lib/feature-family/featureFamily.php"; if ($uaListJSON = @file_get_contents(__DIR__ . "/../user-agents/core/ua.list.json")) { $uaList = (array) json_decode($uaListJSON); asort($uaList); foreach ($uaList as $key => $value) { $fileCore = @file_get_contents(__DIR__ . "/../user-agents/core/ua." . $key . ".json"); $fileExtended = @file_get_contents(__DIR__ . "/../user-agents/extended/ua." . $key . ".json"); $jsonCore = json_decode($fileCore); $jsonExtended = json_decode($fileExtended); $jsonMerged = (object) array_merge((array) $jsonCore, (array) $jsonExtended); $jsonExtended->family = featureFamily::find($jsonMerged); $jsonUpated = json_encode($jsonExtended); $fp = fopen(__DIR__ . "/../user-agents/extended/ua." . $key . ".json", "w"); fwrite($fp, $jsonUpated); fclose($fp); } }
<?php /* Simply prints out the name of the family based on the user agent using families.json without actually updating any of the profiles. You can also supply ?pid=[something] if you want */ // require Detector so we can popular identify the browser & populate $ua require "../../../lib/Detector/Detector.php"; print "family name: " . featureFamily::find($ua);