@@ -54,16 +54,16 @@ discard block |
||
| 54 | 54 | * Detector constructor. |
| 55 | 55 | * @param string $pathToData Path to directory with xml data files |
| 56 | 56 | */ |
| 57 | - private function __construct($pathToData='auto') |
|
| 57 | + private function __construct($pathToData = 'auto') |
|
| 58 | 58 | { |
| 59 | - if($pathToData == 'auto') |
|
| 59 | + if ($pathToData == 'auto') |
|
| 60 | 60 | { |
| 61 | - $this->setPathToData(str_replace('src','data',__DIR__).'/'); |
|
| 61 | + $this->setPathToData(str_replace('src', 'data', __DIR__).'/'); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $xml = array('robot','browser','device','os'); |
|
| 64 | + $xml = array('robot', 'browser', 'device', 'os'); |
|
| 65 | 65 | $xmlData = array(); |
| 66 | - foreach($xml as $name) |
|
| 66 | + foreach ($xml as $name) |
|
| 67 | 67 | { |
| 68 | 68 | $xmlData[$name] = simplexml_load_file($this->getPathToData().$name.'.xml'); |
| 69 | 69 | } |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | $this->Rules = DetectorRule::loadRulesFromFile(); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - public static function analyse($uaString='UA', $pathToData='auto') |
|
| 75 | + public static function analyse($uaString = 'UA', $pathToData = 'auto') |
|
| 76 | 76 | { |
| 77 | 77 | $ua = $uaString; |
| 78 | - if($uaString == 'UA') |
|
| 78 | + if ($uaString == 'UA') |
|
| 79 | 79 | { |
| 80 | 80 | $ua = $_SERVER['HTTP_USER_AGENT']; |
| 81 | 81 | } |
@@ -83,23 +83,23 @@ discard block |
||
| 83 | 83 | $detector = new Detector($pathToData); |
| 84 | 84 | $xml = $detector->getXmlData(); |
| 85 | 85 | $data = array(); |
| 86 | - foreach($xml as $key => $item) |
|
| 86 | + foreach ($xml as $key => $item) |
|
| 87 | 87 | { |
| 88 | - $data[$key] = self::analysePart($xml,$key,$ua); |
|
| 88 | + $data[$key] = self::analysePart($xml, $key, $ua); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | $detectorResult = new DetectorResult(); |
| 92 | 92 | $detectorResult->uaString = $ua; |
| 93 | 93 | $isRobot = false; |
| 94 | 94 | |
| 95 | - foreach($data as $key => $result) |
|
| 95 | + foreach ($data as $key => $result) |
|
| 96 | 96 | { |
| 97 | - if(!$isRobot) |
|
| 97 | + if (!$isRobot) |
|
| 98 | 98 | { |
| 99 | 99 | switch ($key) |
| 100 | 100 | { |
| 101 | 101 | case 'robot': |
| 102 | - if($result !== null) |
|
| 102 | + if ($result !== null) |
|
| 103 | 103 | { |
| 104 | 104 | $robot = new Robot($result); |
| 105 | 105 | $detectorResult->Robot = $robot; |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | break; |
| 111 | 111 | case 'os': |
| 112 | - if($result !== null) |
|
| 112 | + if ($result !== null) |
|
| 113 | 113 | { |
| 114 | 114 | $os = new OS($result); |
| 115 | 115 | $os->setVersion(self::getVersion($result, $ua)); |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | break; |
| 124 | 124 | case 'device': |
| 125 | - if($result !== null) |
|
| 125 | + if ($result !== null) |
|
| 126 | 126 | { |
| 127 | 127 | $device = new Device($result); |
| 128 | 128 | $detectorResult->Device = $device; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | break; |
| 136 | 136 | case 'browser': |
| 137 | - if($result !== null) |
|
| 137 | + if ($result !== null) |
|
| 138 | 138 | { |
| 139 | 139 | $browser = new Browser($result); |
| 140 | 140 | $browser->setVersion(self::getVersion($result, $ua)); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $detectorResult = self::checkRules($detector,$detectorResult); |
|
| 153 | + $detectorResult = self::checkRules($detector, $detectorResult); |
|
| 154 | 154 | |
| 155 | 155 | return $detectorResult; |
| 156 | 156 | } |
@@ -161,13 +161,13 @@ discard block |
||
| 161 | 161 | * @param string $uaString User agent |
| 162 | 162 | * @return \SimpleXMLElement xml element |
| 163 | 163 | */ |
| 164 | - private static function analysePart($xmlData,$key,$uaString) |
|
| 164 | + private static function analysePart($xmlData, $key, $uaString) |
|
| 165 | 165 | { |
| 166 | 166 | $data = $xmlData[$key]->data; |
| 167 | - foreach($data as $xmlItem) |
|
| 167 | + foreach ($data as $xmlItem) |
|
| 168 | 168 | { |
| 169 | 169 | $pattern = '/'.$xmlItem->pattern.'/'; |
| 170 | - if(preg_match($pattern,$uaString)) |
|
| 170 | + if (preg_match($pattern, $uaString)) |
|
| 171 | 171 | { |
| 172 | 172 | return $xmlItem; |
| 173 | 173 | } |
@@ -180,21 +180,21 @@ discard block |
||
| 180 | 180 | * @param string $uaString User agent |
| 181 | 181 | * @return string Version |
| 182 | 182 | */ |
| 183 | - private static function getVersion(\SimpleXMLElement $xmlItem,$uaString) |
|
| 183 | + private static function getVersion(\SimpleXMLElement $xmlItem, $uaString) |
|
| 184 | 184 | { |
| 185 | - if($xmlItem !== null) |
|
| 185 | + if ($xmlItem !== null) |
|
| 186 | 186 | { |
| 187 | - foreach($xmlItem->children() as $node) |
|
| 187 | + foreach ($xmlItem->children() as $node) |
|
| 188 | 188 | { |
| 189 | - if($node->getName() == 'versionPattern') |
|
| 189 | + if ($node->getName() == 'versionPattern') |
|
| 190 | 190 | { |
| 191 | 191 | $vPattern = $node->__toString(); |
| 192 | - $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/'; |
|
| 192 | + $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
|
| 193 | 193 | $uaString = str_replace(' NT', '', $uaString); |
| 194 | 194 | if (preg_match($version, $uaString)) { |
| 195 | 195 | preg_match($version, $uaString, $v); |
| 196 | 196 | $version = $v[0]; |
| 197 | - $version = preg_replace('/' . $vPattern . '/', '', $version); |
|
| 197 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
| 198 | 198 | $version = str_replace(';', '', $version); |
| 199 | 199 | $version = str_replace(' ', '', $version); |
| 200 | 200 | $version = str_replace('/', '', $version); |
@@ -235,16 +235,16 @@ discard block |
||
| 235 | 235 | * @param DetectorResult $result Detector result |
| 236 | 236 | * @return DetectorResult Final result |
| 237 | 237 | */ |
| 238 | - private static function checkRules(Detector $object,DetectorResult $result) |
|
| 238 | + private static function checkRules(Detector $object, DetectorResult $result) |
|
| 239 | 239 | { |
| 240 | - foreach($object->Rules as $rule) |
|
| 240 | + foreach ($object->Rules as $rule) |
|
| 241 | 241 | { |
| 242 | 242 | $objectType = $rule->getObjectType(); |
| 243 | 243 | $objectProperty = $rule->getObjectProperty(); |
| 244 | 244 | $targetType = $rule->getTargetType(); |
| 245 | 245 | $targetValue = $rule->isTargetValue(); |
| 246 | 246 | $func = 'get'.$objectProperty; |
| 247 | - if($result->$objectType !== null) |
|
| 247 | + if ($result->$objectType !== null) |
|
| 248 | 248 | { |
| 249 | 249 | if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) { |
| 250 | 250 | $result->$targetType = $targetValue; |
@@ -255,4 +255,4 @@ discard block |
||
| 255 | 255 | return $result; |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | -define('D_NA','N\A'); |
|
| 258 | +define('D_NA', 'N\A'); |
|
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | 'Tiny Tiny RSS/1.10 (http://tt-rss.org/)' |
| 23 | 23 | ); |
| 24 | 24 | |
| 25 | - testUaList($this,'Robot','Name',$ualist,'Tiny RSS'); |
|
| 26 | - testUaList($this,'Robot','Type',$ualist,'RSS Reader'); |
|
| 25 | + testUaList($this, 'Robot', 'Name', $ualist, 'Tiny RSS'); |
|
| 26 | + testUaList($this, 'Robot', 'Type', $ualist, 'RSS Reader'); |
|
| 27 | 27 | } |
| 28 | 28 | /** |
| 29 | 29 | * Test Google Bots |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | 'Mediapartners-Google' |
| 44 | 44 | ); |
| 45 | 45 | |
| 46 | - testUaList($this,'Robot','Owner',$ualist,'Google Inc.'); |
|
| 47 | - testUaList($this,'Robot','Type',$ualist,'Search Engine'); |
|
| 48 | - testUaListBooleanTrue($this,'Robot','SearchEngine',$ualist); |
|
| 46 | + testUaList($this, 'Robot', 'Owner', $ualist, 'Google Inc.'); |
|
| 47 | + testUaList($this, 'Robot', 'Type', $ualist, 'Search Engine'); |
|
| 48 | + testUaListBooleanTrue($this, 'Robot', 'SearchEngine', $ualist); |
|
| 49 | 49 | } |
| 50 | 50 | /** |
| 51 | 51 | * Test Yandex Bots |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | 'Mozilla/5.0 (compatible; YandexSpravBot/1.0; +http://yandex.com/bots)' |
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | - testUaList($this,'Robot','Owner',$ualist,'Yandex LLC.'); |
|
| 88 | - testUaList($this,'Robot','Type',$ualist,'Search Engine'); |
|
| 89 | - testUaListBooleanTrue($this,'Robot','SearchEngine',$ualist); |
|
| 87 | + testUaList($this, 'Robot', 'Owner', $ualist, 'Yandex LLC.'); |
|
| 88 | + testUaList($this, 'Robot', 'Type', $ualist, 'Search Engine'); |
|
| 89 | + testUaListBooleanTrue($this, 'Robot', 'SearchEngine', $ualist); |
|
| 90 | 90 | } |
| 91 | 91 | /** |
| 92 | 92 | * Test Bing Bots |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | 'Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530) like Gecko BingPreview/1.0b' |
| 107 | 107 | ); |
| 108 | 108 | |
| 109 | - testUaList($this,'Robot','Name',$ualist,'Bing'); |
|
| 110 | - testUaList($this,'Robot','Type',$ualist,'Search Engine'); |
|
| 111 | - testUaListBooleanTrue($this,'Robot','SearchEngine',$ualist); |
|
| 109 | + testUaList($this, 'Robot', 'Name', $ualist, 'Bing'); |
|
| 110 | + testUaList($this, 'Robot', 'Type', $ualist, 'Search Engine'); |
|
| 111 | + testUaListBooleanTrue($this, 'Robot', 'SearchEngine', $ualist); |
|
| 112 | 112 | } |
| 113 | 113 | /** |
| 114 | 114 | * Test WASALive |
@@ -119,8 +119,8 @@ discard block |
||
| 119 | 119 | 'Mozilla/5.0 (compatible; WASALive-Bot ; http://blog.wasalive.com/wasalive-bots/) ' |
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | - testUaList($this,'Robot','Name',$ualist,'WASALive Bot'); |
|
| 123 | - testUaList($this,'Robot','Type',$ualist,'Bot/Crawler'); |
|
| 122 | + testUaList($this, 'Robot', 'Name', $ualist, 'WASALive Bot'); |
|
| 123 | + testUaList($this, 'Robot', 'Type', $ualist, 'Bot/Crawler'); |
|
| 124 | 124 | } |
| 125 | 125 | /** |
| 126 | 126 | * Test .Net robot |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | 'MS Web Services Client Protocol 1.0.3705.0' |
| 132 | 132 | ); |
| 133 | 133 | |
| 134 | - testUaList($this,'Robot','Name',$ualist,'.NET Framework CLR'); |
|
| 135 | - testUaList($this,'Robot','Type',$ualist,'Bot/Crawler'); |
|
| 134 | + testUaList($this, 'Robot', 'Name', $ualist, '.NET Framework CLR'); |
|
| 135 | + testUaList($this, 'Robot', 'Type', $ualist, 'Bot/Crawler'); |
|
| 136 | 136 | } |
| 137 | 137 | /** |
| 138 | 138 | * Test 007ac9 robot |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | 'Mozilla/5.0 (compatible; 007ac9 Crawler; http://crawler.007ac9.net/) ' |
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | - testUaList($this,'Robot','Name',$ualist,'007ac9 Crawler'); |
|
| 147 | - testUaList($this,'Robot','Type',$ualist,'Bot/Crawler'); |
|
| 146 | + testUaList($this, 'Robot', 'Name', $ualist, '007ac9 Crawler'); |
|
| 147 | + testUaList($this, 'Robot', 'Type', $ualist, 'Bot/Crawler'); |
|
| 148 | 148 | } |
| 149 | 149 | /** |
| 150 | 150 | * Test 80legs robot |
@@ -155,8 +155,8 @@ discard block |
||
| 155 | 155 | 'Mozilla/5.0 (compatible; 008/0.83; http://www.80legs.com/webcrawler.html) Gecko/2008032620 ' |
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | - testUaList($this,'Robot','Name',$ualist,'80legs Crawler'); |
|
| 159 | - testUaList($this,'Robot','Type',$ualist,'Bot/Crawler'); |
|
| 158 | + testUaList($this, 'Robot', 'Name', $ualist, '80legs Crawler'); |
|
| 159 | + testUaList($this, 'Robot', 'Type', $ualist, 'Bot/Crawler'); |
|
| 160 | 160 | } |
| 161 | 161 | /** |
| 162 | 162 | * Test 80123metaspider robot |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | '123metaspider-Bot (Version: 1.04, powered by www.123metaspider.com) ' |
| 168 | 168 | ); |
| 169 | 169 | |
| 170 | - testUaList($this,'Robot','Name',$ualist,'123metaspider Crawler'); |
|
| 171 | - testUaList($this,'Robot','Type',$ualist,'Bot/Crawler'); |
|
| 170 | + testUaList($this, 'Robot', 'Name', $ualist, '123metaspider Crawler'); |
|
| 171 | + testUaList($this, 'Robot', 'Type', $ualist, 'Bot/Crawler'); |
|
| 172 | 172 | } |
| 173 | 173 | /** |
| 174 | 174 | * Test 1470 robot |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | '1470.net crawler ' |
| 180 | 180 | ); |
| 181 | 181 | |
| 182 | - testUaList($this,'Robot','Name',$ualist,'1470 Crawler'); |
|
| 183 | - testUaList($this,'Robot','Type',$ualist,'Bot/Crawler'); |
|
| 182 | + testUaList($this, 'Robot', 'Name', $ualist, '1470 Crawler'); |
|
| 183 | + testUaList($this, 'Robot', 'Type', $ualist, 'Bot/Crawler'); |
|
| 184 | 184 | } |
| 185 | 185 | } |