diff --git a/libraries/classmap.php b/libraries/classmap.php index aa71a04c01b77..28e8f2a3ae869 100644 --- a/libraries/classmap.php +++ b/libraries/classmap.php @@ -14,3 +14,4 @@ JLoader::registerAlias('JRegistryFormatXml', '\\Joomla\\Registry\\Format\\Xml'); JLoader::registerAlias('JStringInflector', '\\Joomla\\String\\Inflector'); JLoader::registerAlias('JStringNormalise', '\\Joomla\\String\\Normalise'); +JLoader::registerAlias('JApplicationWebClient', '\\Joomla\\Application\\Web\\WebClient'); diff --git a/libraries/joomla/application/web/client.php b/libraries/joomla/application/web/client.php deleted file mode 100644 index a246832073165..0000000000000 --- a/libraries/joomla/application/web/client.php +++ /dev/null @@ -1,514 +0,0 @@ -userAgent = $_SERVER['HTTP_USER_AGENT']; - } - else - { - $this->userAgent = $userAgent; - } - - // If no explicit acceptable encoding string was given attempt to use the implicit one from server environment. - if (empty($acceptEncoding) && isset($_SERVER['HTTP_ACCEPT_ENCODING'])) - { - $this->acceptEncoding = $_SERVER['HTTP_ACCEPT_ENCODING']; - } - else - { - $this->acceptEncoding = $acceptEncoding; - } - - // If no explicit acceptable languages string was given attempt to use the implicit one from server environment. - if (empty($acceptLanguage) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) - { - $this->acceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE']; - } - else - { - $this->acceptLanguage = $acceptLanguage; - } - } - - /** - * Magic method to get an object property's value by name. - * - * @param string $name Name of the property for which to return a value. - * - * @return mixed The requested value if it exists. - * - * @since 12.1 - */ - public function __get($name) - { - switch ($name) - { - case 'mobile': - case 'platform': - if (empty($this->detection['platform'])) - { - $this->detectPlatform($this->userAgent); - } - break; - - case 'engine': - if (empty($this->detection['engine'])) - { - $this->detectEngine($this->userAgent); - } - break; - - case 'browser': - case 'browserVersion': - if (empty($this->detection['browser'])) - { - $this->detectBrowser($this->userAgent); - } - break; - - case 'languages': - if (empty($this->detection['acceptLanguage'])) - { - $this->detectLanguage($this->acceptLanguage); - } - break; - - case 'encodings': - if (empty($this->detection['acceptEncoding'])) - { - $this->detectEncoding($this->acceptEncoding); - } - break; - - case 'robot': - if (empty($this->detection['robot'])) - { - $this->detectRobot($this->userAgent); - } - break; - } - - // Return the property if it exists. - if (isset($this->$name)) - { - return $this->$name; - } - } - - /** - * Detects the client browser and version in a user agent string. - * - * @param string $userAgent The user-agent string to parse. - * - * @return void - * - * @since 12.1 - */ - protected function detectBrowser($userAgent) - { - // Attempt to detect the browser type. Obviously we are only worried about major browsers. - if ((stripos($userAgent, 'MSIE') !== false) && (stripos($userAgent, 'Opera') === false)) - { - $this->browser = self::IE; - $patternBrowser = 'MSIE'; - } - elseif ((stripos($userAgent, 'Firefox') !== false) && (stripos($userAgent, 'like Firefox') === false)) - { - $this->browser = self::FIREFOX; - $patternBrowser = 'Firefox'; - } - elseif (stripos($userAgent, 'Chrome') !== false) - { - $this->browser = self::CHROME; - $patternBrowser = 'Chrome'; - } - elseif (stripos($userAgent, 'Safari') !== false) - { - $this->browser = self::SAFARI; - $patternBrowser = 'Safari'; - } - elseif (stripos($userAgent, 'Opera') !== false) - { - $this->browser = self::OPERA; - $patternBrowser = 'Opera'; - } - - // If we detected a known browser let's attempt to determine the version. - if ($this->browser) - { - // Build the REGEX pattern to match the browser version string within the user agent string. - $pattern = '#(?Version|' . $patternBrowser . ')[/ ]+(?[0-9.|a-zA-Z.]*)#'; - - // Attempt to find version strings in the user agent string. - $matches = array(); - - if (preg_match_all($pattern, $userAgent, $matches)) - { - // Do we have both a Version and browser match? - if (count($matches['browser']) == 2) - { - // See whether Version or browser came first, and use the number accordingly. - if (strripos($userAgent, 'Version') < strripos($userAgent, $patternBrowser)) - { - $this->browserVersion = $matches['version'][0]; - } - else - { - $this->browserVersion = $matches['version'][1]; - } - } - elseif (count($matches['browser']) > 2) - { - $key = array_search('Version', $matches['browser']); - - if ($key) - { - $this->browserVersion = $matches['version'][$key]; - } - } - // We only have a Version or a browser so use what we have. - else - { - $this->browserVersion = $matches['version'][0]; - } - } - } - - // Mark this detection routine as run. - $this->detection['browser'] = true; - } - - /** - * Method to detect the accepted response encoding by the client. - * - * @param string $acceptEncoding The client accept encoding string to parse. - * - * @return void - * - * @since 12.1 - */ - protected function detectEncoding($acceptEncoding) - { - // Parse the accepted encodings. - $this->encodings = array_map('trim', (array) explode(',', $acceptEncoding)); - - // Mark this detection routine as run. - $this->detection['acceptEncoding'] = true; - } - - /** - * Detects the client rendering engine in a user agent string. - * - * @param string $userAgent The user-agent string to parse. - * - * @return void - * - * @since 12.1 - */ - protected function detectEngine($userAgent) - { - // Attempt to detect the client engine -- starting with the most popular ... for now. - if (stripos($userAgent, 'MSIE') !== false || stripos($userAgent, 'Trident') !== false) - { - $this->engine = self::TRIDENT; - } - // Evidently blackberry uses WebKit and doesn't necessarily report it. Bad RIM. - elseif (stripos($userAgent, 'AppleWebKit') !== false || stripos($userAgent, 'blackberry') !== false) - { - $this->engine = self::WEBKIT; - } - // We have to check for like Gecko because some other browsers spoof Gecko. - elseif (stripos($userAgent, 'Gecko') !== false && stripos($userAgent, 'like Gecko') === false) - { - $this->engine = self::GECKO; - } - // Sometimes Opera browsers don't say Presto. - elseif (stripos($userAgent, 'Opera') !== false || stripos($userAgent, 'Presto') !== false) - { - $this->engine = self::PRESTO; - } - // *sigh* - elseif (stripos($userAgent, 'KHTML') !== false) - { - $this->engine = self::KHTML; - } - // Lesser known engine but it finishes off the major list from Wikipedia :-) - elseif (stripos($userAgent, 'Amaya') !== false) - { - $this->engine = self::AMAYA; - } - - // Mark this detection routine as run. - $this->detection['engine'] = true; - } - - /** - * Method to detect the accepted languages by the client. - * - * @param mixed $acceptLanguage The client accept language string to parse. - * - * @return void - * - * @since 12.1 - */ - protected function detectLanguage($acceptLanguage) - { - // Parse the accepted encodings. - $this->languages = array_map('trim', (array) explode(',', $acceptLanguage)); - - // Mark this detection routine as run. - $this->detection['acceptLanguage'] = true; - } - - /** - * Detects the client platform in a user agent string. - * - * @param string $userAgent The user-agent string to parse. - * - * @return void - * - * @since 12.1 - */ - protected function detectPlatform($userAgent) - { - // Attempt to detect the client platform. - if (stripos($userAgent, 'Windows') !== false) - { - $this->platform = self::WINDOWS; - - // Let's look at the specific mobile options in the Windows space. - if (stripos($userAgent, 'Windows Phone') !== false) - { - $this->mobile = true; - $this->platform = self::WINDOWS_PHONE; - } - elseif (stripos($userAgent, 'Windows CE') !== false) - { - $this->mobile = true; - $this->platform = self::WINDOWS_CE; - } - } - // Interestingly 'iPhone' is present in all iOS devices so far including iPad and iPods. - elseif (stripos($userAgent, 'iPhone') !== false) - { - $this->mobile = true; - $this->platform = self::IPHONE; - - // Let's look at the specific mobile options in the iOS space. - if (stripos($userAgent, 'iPad') !== false) - { - $this->platform = self::IPAD; - } - elseif (stripos($userAgent, 'iPod') !== false) - { - $this->platform = self::IPOD; - } - } - // In case where iPhone is not mentioed in iPad user agent string - elseif (stripos($userAgent, 'iPad') !== false) - { - $this->mobile = true; - $this->platform = self::IPAD; - } - // In case where iPhone is not mentioed in iPod user agent string - elseif (stripos($userAgent, 'iPod') !== false) - { - $this->mobile = true; - $this->platform = self::IPOD; - } - // This has to come after the iPhone check because mac strings are also present in iOS devices. - elseif (preg_match('/macintosh|mac os x/i', $userAgent)) - { - $this->platform = self::MAC; - } - elseif (stripos($userAgent, 'Blackberry') !== false) - { - $this->mobile = true; - $this->platform = self::BLACKBERRY; - } - elseif (stripos($userAgent, 'Android') !== false) - { - $this->mobile = true; - $this->platform = self::ANDROID; - /** - * Attempt to distinguish between Android phones and tablets - * There is no totally foolproof method but certain rules almost always hold - * Android 3.x is only used for tablets - * Some devices and browsers encourage users to change their UA string to include Tablet. - * Google encourages manufacturers to exclude the string Mobile from tablet device UA strings. - * In some modes Kindle Android devices include the string Mobile but they include the string Silk. - */ - if (stripos($userAgent, 'Android 3') !== false || stripos($userAgent, 'Tablet') !== false - || stripos($userAgent, 'Mobile') === false || stripos($userAgent, 'Silk') !== false ) - { - $this->platform = self::ANDROIDTABLET; - } - } - elseif (stripos($userAgent, 'Linux') !== false) - { - $this->platform = self::LINUX; - } - - // Mark this detection routine as run. - $this->detection['platform'] = true; - } - - /** - * Determines if the browser is a robot or not. - * - * @param string $userAgent The user-agent string to parse. - * - * @return void - * - * @since 12.3 - */ - protected function detectRobot($userAgent) - { - if (preg_match('/http|bot|robot|spider|crawler|curl|^$/i', $userAgent)) - { - $this->robot = true; - } - else - { - $this->robot = false; - } - - $this->detection['robot'] = true; - } -} diff --git a/tests/unit/suites/libraries/joomla/application/web/JApplicationWebClientTest.php b/tests/unit/suites/libraries/joomla/application/web/JApplicationWebClientTest.php deleted file mode 100644 index 83dbf5bc4402c..0000000000000 --- a/tests/unit/suites/libraries/joomla/application/web/JApplicationWebClientTest.php +++ /dev/null @@ -1,331 +0,0 @@ -inspector = new JWebClientInspector; - } - - /** - * Tests the JApplicationWebClient::detectBrowser method. - * - * @param string $p The expected platform. - * @param boolean $m The expected mobile result. - * @param string $e The expected engine. - * @param string $b The expected browser. - * @param string $v The expected browser version. - * @param string $ua The input user agent. - * - * @return void - * - * @dataProvider getUserAgentData - * @since 11.3 - */ - public function testDetectBrowser($p, $m, $e, $b, $v, $ua) - { - $this->inspector->detectBrowser($ua); - - // Test the assertions. - $this->assertEquals($this->inspector->browser, $b, 'Browser detection failed'); - $this->assertEquals($this->inspector->browserVersion, $v, 'Version detection failed'); - } - - /** - * Tests the JApplicationWebClient::detectEncoding method. - * - * @param string $ae The input accept encoding. - * @param array $e The expected array of encodings. - * - * @return void - * - * @dataProvider getEncodingData - * @since 11.3 - */ - public function testDetectEncoding($ae, $e) - { - $this->inspector->detectEncoding($ae); - - // Test the assertions. - $this->assertEquals($this->inspector->encodings, $e, 'Encoding detection failed'); - } - - /** - * Tests the JApplicationWebClient::detectEngine method. - * - * @param string $p The expected platform. - * @param boolean $m The expected mobile result. - * @param string $e The expected engine. - * @param string $b The expected browser. - * @param string $v The expected browser version. - * @param string $ua The input user agent. - * - * @return void - * - * @dataProvider getUserAgentData - * @since 11.3 - */ - public function testDetectEngine($p, $m, $e, $b, $v, $ua) - { - $this->inspector->detectEngine($ua); - - // Test the assertion. - $this->assertEquals($this->inspector->engine, $e, 'Engine detection failed.'); - } - - /** - * Tests the JApplicationWebClient::detectLanguage method. - * - * @param string $al The input accept language. - * @param array $l The expected array of languages. - * - * @return void - * - * @dataProvider getLanguageData - * @since 11.3 - */ - public function testDetectLanguage($al, $l) - { - $this->inspector->detectLanguage($al); - - // Test the assertions. - $this->assertEquals($this->inspector->languages, $l, 'Language detection failed'); - } - - /** - * Tests the JApplicationWebClient::detectPlatform method. - * - * @param string $p The expected platform. - * @param boolean $m The expected mobile result. - * @param string $e The expected engine. - * @param string $b The expected browser. - * @param string $v The expected browser version. - * @param string $ua The input user agent. - * - * @return void - * - * @dataProvider getUserAgentData - * @since 11.3 - */ - public function testDetectPlatform($p, $m, $e, $b, $v, $ua) - { - $this->inspector->detectPlatform($ua); - - // Test the assertions. - $this->assertEquals($this->inspector->mobile, $m, 'Mobile detection failed.'); - $this->assertEquals($this->inspector->platform, $p, 'Platform detection failed.'); - } - - /** - * Tests the JApplicationWebClient::detectRobot method. - * - * @param string $userAgent The user agent - * @param boolean $expected The expected results of the function - * - * @return void - * - * @dataProvider detectRobotData - * @since 12.3 - */ - public function testDetectRobot($userAgent, $expected) - { - $this->inspector->detectRobot($userAgent); - - // Test the assertions. - $this->assertEquals($this->inspector->robot, $expected, 'Robot detection failed'); - } -}