2
0
forked from Wavyzz/dolibarr

Install mobiledetect from composer

This commit is contained in:
Raphaël Doursenaud
2015-08-06 16:43:30 +02:00
parent 7d934db183
commit 0eb0f52b6d
27 changed files with 4908 additions and 77 deletions

View File

@@ -15,6 +15,7 @@
"ext-curl": "*", "ext-curl": "*",
"ccampbell/chromephp": "^4.1", "ccampbell/chromephp": "^4.1",
"ckeditor/ckeditor": "4.3.3", "ckeditor/ckeditor": "4.3.3",
"mobiledetect/mobiledetectlib": "2.8.3",
"restler/framework": "3.0.*" "restler/framework": "3.0.*"
}, },
"suggest": { "suggest": {

54
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "f24ac28663637d0eab7a69e3375081a8", "hash": "f0acbff2d6b30a828c38854c432a3dad",
"packages": [ "packages": [
{ {
"name": "ccampbell/chromephp", "name": "ccampbell/chromephp",
@@ -89,6 +89,58 @@
"wysiwyg" "wysiwyg"
], ],
"time": "2014-02-26 15:34:37" "time": "2014-02-26 15:34:37"
},
{
"name": "mobiledetect/mobiledetectlib",
"version": "2.8.3",
"source": {
"type": "git",
"url": "https://github.com/serbanghita/Mobile-Detect.git",
"reference": "f5753e4b90daffe50c902e99df5ce3c58fca3fee"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/serbanghita/Mobile-Detect/zipball/f5753e4b90daffe50c902e99df5ce3c58fca3fee",
"reference": "f5753e4b90daffe50c902e99df5ce3c58fca3fee",
"shasum": ""
},
"require": {
"php": ">=5.0.0"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"type": "library",
"autoload": {
"classmap": [
"Mobile_Detect.php"
],
"psr-0": {
"Detection": "namespaced/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Serban Ghita",
"email": "serbanghita@gmail.com",
"homepage": "http://ghita.org",
"role": "Developer"
}
],
"description": "Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.",
"homepage": "https://github.com/serbanghita/Mobile-Detect",
"keywords": [
"detect mobile devices",
"mobile",
"mobile detect",
"mobile detector",
"php mobile detect"
],
"time": "2014-07-10 20:00:25"
} }
], ],
"packages-dev": [], "packages-dev": [],

View File

@@ -142,7 +142,7 @@ function getEntity($element=false, $shared=0)
*/ */
function getBrowserInfo($user_agent) function getBrowserInfo($user_agent)
{ {
include_once DOL_DOCUMENT_ROOT.'/includes/mobiledetect/mobiledetect.class.php'; include_once DOL_DOCUMENT_ROOT.'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
$name='unknown'; $name='unknown';
$version=''; $version='';

View File

@@ -6,4 +6,5 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir)); $baseDir = dirname(dirname($vendorDir));
return array( return array(
'Mobile_Detect' => $vendorDir . '/mobiledetect/mobiledetectlib/Mobile_Detect.php',
); );

View File

@@ -6,5 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir)); $baseDir = dirname(dirname($vendorDir));
return array( return array(
'Detection' => array($vendorDir . '/mobiledetect/mobiledetectlib/namespaced'),
'ChromePhp' => array($vendorDir . '/ccampbell/chromephp'), 'ChromePhp' => array($vendorDir . '/ccampbell/chromephp'),
); );

View File

@@ -86,5 +86,59 @@
"text", "text",
"wysiwyg" "wysiwyg"
] ]
},
{
"name": "mobiledetect/mobiledetectlib",
"version": "2.8.3",
"version_normalized": "2.8.3.0",
"source": {
"type": "git",
"url": "https://github.com/serbanghita/Mobile-Detect.git",
"reference": "f5753e4b90daffe50c902e99df5ce3c58fca3fee"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/serbanghita/Mobile-Detect/zipball/f5753e4b90daffe50c902e99df5ce3c58fca3fee",
"reference": "f5753e4b90daffe50c902e99df5ce3c58fca3fee",
"shasum": ""
},
"require": {
"php": ">=5.0.0"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"time": "2014-07-10 20:00:25",
"type": "library",
"installation-source": "dist",
"autoload": {
"classmap": [
"Mobile_Detect.php"
],
"psr-0": {
"Detection": "namespaced/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Serban Ghita",
"email": "serbanghita@gmail.com",
"homepage": "http://ghita.org",
"role": "Developer"
}
],
"description": "Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.",
"homepage": "https://github.com/serbanghita/Mobile-Detect",
"keywords": [
"detect mobile devices",
"mobile",
"mobile detect",
"mobile detector",
"php mobile detect"
]
} }
] ]

View File

@@ -0,0 +1,9 @@
vendor/
nbproject/
/*.buildpath
/*.project
/.settings
/error.log
/export/nicejson
.idea/
*.iml

View File

@@ -0,0 +1,24 @@
<?php
use Symfony\CS\FixerInterface;
$finder = Symfony\CS\Finder\DefaultFinder::create()
->notName('LICENSE')
->notName('README.md')
->notName('.php_cs')
->notName('composer.*')
->notName('phpunit.xml*')
->notName('*.phar')
->exclude('vendor')
->exclude('examples')
->exclude('Symfony/CS/Tests/Fixer')
->notName('ElseifFixer.php')
->exclude('data')
->in(__DIR__)
;
return Symfony\CS\Config\Config::create()
->finder($finder)
;

View File

@@ -0,0 +1,14 @@
language: php
php:
- "5.2"
- "hhvm"
branches:
only:
- devel
script:
- phpunit --configuration tests/phpunit.xml
notifications:
email: false

View File

@@ -0,0 +1,48 @@
MIT License
Copyright (c) <2011-2014> <Serban Ghita> <serbanghita@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Developers Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

File diff suppressed because one or more lines are too long

View File

@@ -23,10 +23,7 @@
* @version 2.8.3 * @version 2.8.3
*/ */
/** class Mobile_Detect
* Class to manage detection of type of terminal (classic, tablet, mobile)
*/
class MobileDetect
{ {
/** /**
* Mobile detection type. * Mobile detection type.
@@ -155,7 +152,7 @@ class MobileDetect
'Asus' => 'Asus.*Galaxy|PadFone.*Mobile', 'Asus' => 'Asus.*Galaxy|PadFone.*Mobile',
// @ref: http://www.micromaxinfo.com/mobiles/smartphones // @ref: http://www.micromaxinfo.com/mobiles/smartphones
// Added because the codes might conflict with Acer Tablets. // Added because the codes might conflict with Acer Tablets.
'Micromax' => 'Micromax.*\bA\d+\b', 'Micromax' => 'Micromax.*\b(A210|A92|A88|A72|A111|A110Q|A115|A116|A110|A90S|A26|A51|A35|A54|A25|A27|A89|A68|A65|A57|A90)\b',
'Palm' => 'PalmSource|Palm', // avantgo|blazer|elaine|hiptop|plucker|xiino ; @todo - complete the regex. 'Palm' => 'PalmSource|Palm', // avantgo|blazer|elaine|hiptop|plucker|xiino ; @todo - complete the regex.
'Vertu' => 'Vertu|Vertu.*Ltd|Vertu.*Ascent|Vertu.*Ayxta|Vertu.*Constellation(F|Quest)?|Vertu.*Monika|Vertu.*Signature', // Just for fun ;) 'Vertu' => 'Vertu|Vertu.*Ltd|Vertu.*Ascent|Vertu.*Ayxta|Vertu.*Constellation(F|Quest)?|Vertu.*Monika|Vertu.*Signature', // Just for fun ;)
// @ref: http://www.pantech.co.kr/en/prod/prodList.do?gbrand=VEGA (PANTECH) // @ref: http://www.pantech.co.kr/en/prod/prodList.do?gbrand=VEGA (PANTECH)
@@ -179,7 +176,7 @@ class MobileDetect
protected static $tabletDevices = array( protected static $tabletDevices = array(
'iPad' => 'iPad|iPad.*Mobile', // @todo: check for mobile friendly emails topic. 'iPad' => 'iPad|iPad.*Mobile', // @todo: check for mobile friendly emails topic.
'NexusTablet' => 'Android.*Nexus[\s]+(7|10)|^.*Android.*Nexus(?:(?!Mobile).)*$', 'NexusTablet' => 'Android.*Nexus[\s]+(7|10)|^.*Android.*Nexus(?:(?!Mobile).)*$',
'SamsungTablet' => 'SAMSUNG.*Tablet|Galaxy.*Tab|SC-01C|GT-P\d+|SCH-I800|SCH-I815|SCH-I905|SGH-I957|SGH-I987|SGH-T849|SGH-T859|SGH-T869|SPH-P100|GT-N8000|SGH-I497|SPH-P500|SGH-T779|SCH-I705|SCH-I915|GT-N8013|GT-N8010|GT-N8005|GT-N8020|GT-N5100|GT-N5105|GT-N5110|SHV-E140K|SHV-E140L|SHV-E140S|SHV-E150S|SHV-E230K|SHV-E230L|SHV-E230S|SHW-M180K|SHW-M180L|SHW-M180S|SHW-M180W|SHW-M300W|SHW-M305W|SHW-M380K|SHW-M380S|SHW-M380W|SHW-M430W|SHW-M480K|SHW-M480S|SHW-M480W|SHW-M485W|SHW-M486W|SHW-M500W|GT-I9228|SCH-P739|SCH-I925|GT-I9200|GT-I9205|SM-T\d+|SM-P600|SM-P601|SM-P605|SM-P900|SM-P901|SM-P6000|SM-T3100|SGH-I467|XE500|GT-I9200X|GT-N5110X|GT-N5120|SM-P905|XE500T1C|SM-P605V|SM-P905V|SM-P600X|SM-P900X', // SCH-P709|SCH-P729|SM-T2558 - Samsung Mega - treat them like a regular phone. 'SamsungTablet' => 'SAMSUNG.*Tablet|Galaxy.*Tab|SC-01C|GT-P1000|GT-P1003|GT-P1010|GT-P3105|GT-P6210|GT-P6800|GT-P6810|GT-P7100|GT-P7300|GT-P7310|GT-P7500|GT-P7510|SCH-I800|SCH-I815|SCH-I905|SGH-I957|SGH-I987|SGH-T849|SGH-T859|SGH-T869|SPH-P100|GT-P3100|GT-P3108|GT-P3110|GT-P5100|GT-P5110|GT-P6200|GT-P7320|GT-P7511|GT-N8000|GT-P8510|SGH-I497|SPH-P500|SGH-T779|SCH-I705|SCH-I915|GT-N8013|GT-P3113|GT-P5113|GT-P8110|GT-N8010|GT-N8005|GT-N8020|GT-P1013|GT-P6201|GT-P7501|GT-N5100|GT-N5105|GT-N5110|SHV-E140K|SHV-E140L|SHV-E140S|SHV-E150S|SHV-E230K|SHV-E230L|SHV-E230S|SHW-M180K|SHW-M180L|SHW-M180S|SHW-M180W|SHW-M300W|SHW-M305W|SHW-M380K|SHW-M380S|SHW-M380W|SHW-M430W|SHW-M480K|SHW-M480S|SHW-M480W|SHW-M485W|SHW-M486W|SHW-M500W|GT-I9228|SCH-P739|SCH-I925|GT-I9200|GT-I9205|GT-P5200|GT-P5210|GT-P5210X|SM-T311|SM-T310|SM-T310X|SM-T210|SM-T210R|SM-T211|SM-P600|SM-P601|SM-P605|SM-P900|SM-P901|SM-T217|SM-T217A|SM-T217S|SM-P6000|SM-T3100|SGH-I467|XE500|SM-T110|GT-P5220|GT-I9200X|GT-N5110X|GT-N5120|SM-P905|SM-T111|SM-T2105|SM-T315|SM-T320|SM-T320X|SM-T321|SM-T520|SM-T525|SM-T530NU|SM-T230NU|SM-T330NU|SM-T900|XE500T1C|SM-P605V|SM-P905V|SM-P600X|SM-P900X|SM-T210X|SM-T230|SM-T230X|SM-T325|GT-P7503|SM-T531|SM-T330|SM-T530|SM-T705C|SM-T535|SM-T331', // SCH-P709|SCH-P729|SM-T2558 - Samsung Mega - treat them like a regular phone.
// @reference: http://www.labnol.org/software/kindle-user-agent-string/20378/ // @reference: http://www.labnol.org/software/kindle-user-agent-string/20378/
'Kindle' => 'Kindle|Silk.*Accelerated|Android.*\b(KFOT|KFTT|KFJWI|KFJWA|KFOTE|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|WFJWAE)\b', 'Kindle' => 'Kindle|Silk.*Accelerated|Android.*\b(KFOT|KFTT|KFJWI|KFJWA|KFOTE|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|WFJWAE)\b',
// Only the Surface tablets with Windows RT are considered mobile. // Only the Surface tablets with Windows RT are considered mobile.
@@ -551,8 +548,10 @@ class MobileDetect
* @param string $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT * @param string $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT
* from the $headers array instead. * from the $headers array instead.
*/ */
public function __construct(array $headers = null, $userAgent = null) public function __construct(
{ array $headers = null,
$userAgent = null
){
$this->setHttpHeaders($headers); $this->setHttpHeaders($headers);
$this->setUserAgent($userAgent); $this->setUserAgent($userAgent);
} }
@@ -573,9 +572,8 @@ class MobileDetect
/** /**
* Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers. * Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers.
* *
* @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract * @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract
* the headers. The default null is left for backwards compatibilty. * the headers. The default null is left for backwards compatibilty.
* @return void
*/ */
public function setHttpHeaders($httpHeaders = null) public function setHttpHeaders($httpHeaders = null)
{ {
@@ -637,11 +635,6 @@ class MobileDetect
return null; return null;
} }
/**
* getMobileHeaders
*
* @return string mobile Headers
*/
public function getMobileHeaders() public function getMobileHeaders()
{ {
return self::$mobileHeaders; return self::$mobileHeaders;
@@ -687,7 +680,7 @@ class MobileDetect
/** /**
* Retrieve the User-Agent. * Retrieve the User-Agent.
* *
* @return string The user agent if it's set. * @return string|null The user agent if it's set.
*/ */
public function getUserAgent() public function getUserAgent()
{ {
@@ -698,11 +691,10 @@ class MobileDetect
* Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or * Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or
* self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set. * self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set.
* *
* @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default
* parameter is null which will default to self::DETECTION_TYPE_MOBILE.
* @return void
*
* @deprecated since version 2.6.9 * @deprecated since version 2.6.9
*
* @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default
* parameter is null which will default to self::DETECTION_TYPE_MOBILE.
*/ */
public function setDetectionType($type = null) public function setDetectionType($type = null)
{ {
@@ -877,12 +869,11 @@ class MobileDetect
/** /**
* Magic overloading method. * Magic overloading method.
* *
* @param string $name Name
* @param array $arguments Arguments
* @return null|boolean
*
* @throws BadMethodCallException when the method doesn't exist and doesn't start with 'is'
* @method boolean is[...]() * @method boolean is[...]()
* @param string $name
* @param array $arguments
* @return mixed
* @throws BadMethodCallException when the method doesn't exist and doesn't start with 'is'
*/ */
public function __call($name, $arguments) public function __call($name, $arguments)
{ {
@@ -924,9 +915,9 @@ class MobileDetect
* If the key is found the try to match the corresponding * If the key is found the try to match the corresponding
* regex agains the User-Agent. * regex agains the User-Agent.
* *
* @param string $key Key * @param string $key
* @param string $userAgent deprecated * @param null $userAgent deprecated
* @return null|boolean * @return mixed
*/ */
protected function matchUAAgainstKey($key, $userAgent = null) protected function matchUAAgainstKey($key, $userAgent = null)
{ {
@@ -950,9 +941,8 @@ class MobileDetect
/** /**
* Check if the device is mobile. * Check if the device is mobile.
* Returns true if any type of mobile device detected, including special ones * Returns true if any type of mobile device detected, including special ones
* * @param null $userAgent deprecated
* @param string $userAgent deprecated * @param null $httpHeaders deprecated
* @param string $httpHeaders deprecated
* @return bool * @return bool
*/ */
public function isMobile($userAgent = null, $httpHeaders = null) public function isMobile($userAgent = null, $httpHeaders = null)
@@ -968,15 +958,10 @@ class MobileDetect
$this->setDetectionType(self::DETECTION_TYPE_MOBILE); $this->setDetectionType(self::DETECTION_TYPE_MOBILE);
if ($this->checkHttpHeadersForMobile()) if ($this->checkHttpHeadersForMobile()) {
{
//print "Found it's a mobile from http header";
return true; return true;
} } else {
else return $this->matchDetectionRulesAgainstUA();
{
//print "Check into user agent ".$this->getUserAgent();
return $this->matchDetectionRulesAgainstUA();
} }
} }
@@ -1005,13 +990,12 @@ class MobileDetect
/** /**
* This method checks for a certain property in the * This method checks for a certain property in the
* userAgent. * userAgent.
*
* @param string $key key
* @param string $userAgent deprecated
* @param string $httpHeaders deprecated
* @return null|boolean
*
* @todo: The httpHeaders part is not yet used. * @todo: The httpHeaders part is not yet used.
*
* @param string $key
* @param string $userAgent deprecated
* @param string $httpHeaders deprecated
* @return bool|int|null
*/ */
public function is($key, $userAgent = null, $httpHeaders = null) public function is($key, $userAgent = null, $httpHeaders = null)
{ {
@@ -1034,12 +1018,13 @@ class MobileDetect
* because of the diversity of devices, vendors and * because of the diversity of devices, vendors and
* their conventions in representing the User-Agent or * their conventions in representing the User-Agent or
* the HTTP headers. * the HTTP headers.
*
* This method will be used to check custom regexes against * This method will be used to check custom regexes against
* the User-Agent string. * the User-Agent string.
* *
* @param string $regex Regex * @param $regex
* @param string $userAgent User agent * @param string $userAgent
* @return bool * @return bool
* *
* @todo: search in the HTTP headers too. * @todo: search in the HTTP headers too.
*/ */
@@ -1064,10 +1049,11 @@ class MobileDetect
/** /**
* Prepare the version number. * Prepare the version number.
* *
* @param string $ver The string version, like "2.6.21.2152";
* @return float
*
* @todo Remove the error supression from str_replace() call. * @todo Remove the error supression from str_replace() call.
*
* @param string $ver The string version, like "2.6.21.2152";
*
* @return float
*/ */
public function prepareVersionNo($ver) public function prepareVersionNo($ver)
{ {
@@ -1083,37 +1069,39 @@ class MobileDetect
/** /**
* Check the version of the given property in the User-Agent. * Check the version of the given property in the User-Agent.
* Will return a string or float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31) * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)
* *
* @param string $propertyName The name of the property. See self::getProperties() array keys for all possible properties (Ex: 'iPad', 'Android', ...). * @param string $propertyName The name of the property. See self::getProperties() array
* @param string $type Either self::VERSION_TYPE_STRING to get a string value or * keys for all possible properties.
* self::VERSION_TYPE_FLOAT indicating a float value. This parameter * @param string $type Either self::VERSION_TYPE_STRING to get a string value or
* is optional and defaults to self::VERSION_TYPE_STRING. Passing an * self::VERSION_TYPE_FLOAT indicating a float value. This parameter
* invalid parameter will default to this type as well. * is optional and defaults to self::VERSION_TYPE_STRING. Passing an
* invalid parameter will default to the this type as well.
* *
* @return string|float|boolean The version of the property we are trying to extract. * @return string|float The version of the property we are trying to extract.
*/ */
public function version($propertyName, $type = self::VERSION_TYPE_STRING) public function version($propertyName, $type = self::VERSION_TYPE_STRING)
{ {
if (empty($propertyName)) return false; if (empty($propertyName)) {
return false;
}
//set the $type to the default if we don't recognize the type //set the $type to the default if we don't recognize the type
if ($type != self::VERSION_TYPE_STRING && $type != self::VERSION_TYPE_FLOAT) if ($type != self::VERSION_TYPE_STRING && $type != self::VERSION_TYPE_FLOAT) {
{
$type = self::VERSION_TYPE_STRING; $type = self::VERSION_TYPE_STRING;
} }
$properties = self::getProperties(); $properties = self::getProperties();
// Check if the property exists in the properties array. // Check if the property exists in the properties array.
if (array_key_exists($propertyName, $properties)) if (array_key_exists($propertyName, $properties)) {
{
// Prepare the pattern to be matched. // Prepare the pattern to be matched.
// Make sure we always deal with an array (string is converted). // Make sure we always deal with an array (string is converted).
$properties[$propertyName] = (array) $properties[$propertyName]; $properties[$propertyName] = (array) $properties[$propertyName];
foreach ($properties[$propertyName] as $propertyMatchString) foreach ($properties[$propertyName] as $propertyMatchString) {
{
$propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString); $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString);
// Escape the special character which is the delimiter. // Escape the special character which is the delimiter.
@@ -1122,13 +1110,14 @@ class MobileDetect
// Identify and extract the version. // Identify and extract the version.
preg_match('/'.$propertyPattern.'/is', $this->userAgent, $match); preg_match('/'.$propertyPattern.'/is', $this->userAgent, $match);
if (!empty($match[1])) if (!empty($match[1])) {
{
$version = ( $type == self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1] ); $version = ( $type == self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1] );
return $version; return $version;
} }
} }
} }
return false; return false;
@@ -1137,7 +1126,7 @@ class MobileDetect
/** /**
* Retrieve the mobile grading, using self::MOBILE_GRADE_* constants. * Retrieve the mobile grading, using self::MOBILE_GRADE_* constants.
* *
* @return string One of the self::MOBILE_GRADE_* constants. * @return string One of the self::MOBILE_GRADE_* constants.
*/ */
public function mobileGrade() public function mobileGrade()
{ {
@@ -1217,8 +1206,7 @@ class MobileDetect
// @reference: http://my.opera.com/community/openweb/idopera/ // @reference: http://my.opera.com/community/openweb/idopera/
$this->version('Opera', self::VERSION_TYPE_FLOAT)>=10 && !$isMobile $this->version('Opera', self::VERSION_TYPE_FLOAT)>=10 && !$isMobile
) ){
{
return self::MOBILE_GRADE_A; return self::MOBILE_GRADE_A;
} }
@@ -1239,8 +1227,7 @@ class MobileDetect
// @todo: report this (tested on Nokia N71) // @todo: report this (tested on Nokia N71)
$this->version('Opera Mobi', self::VERSION_TYPE_FLOAT)>=11 && $this->is('SymbianOS') $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT)>=11 && $this->is('SymbianOS')
) ){
{
return self::MOBILE_GRADE_B; return self::MOBILE_GRADE_B;
} }
@@ -1250,8 +1237,7 @@ class MobileDetect
// Windows Mobile - Tested on the HTC Leo (WinMo 5.2) // Windows Mobile - Tested on the HTC Leo (WinMo 5.2)
$this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile', self::VERSION_TYPE_FLOAT)<=5.2 $this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile', self::VERSION_TYPE_FLOAT)<=5.2
) ){
{
return self::MOBILE_GRADE_C; return self::MOBILE_GRADE_C;
} }

View File

@@ -0,0 +1,191 @@
<img src="http://demo.mobiledetect.net/logo-github.png">
> Motto: "Every business should have a mobile detection script to detect mobile readers."
<i>Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets).
It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.</i>
Nowadays web site/app <b>content strategy</b> matters, this is why you need all the tools to deliver the best and the fastest experience for the small screens. Mobile_Detect class is a [server-side detection](http://www.w3.org/TR/mwabp/#bp-devcap-detection) tool, it is not a replacement for Responsive Web Design (media queries) or other forms of client-side feature detection.
We're commited to make Mobile_Detect the best open-source mobile detection resource and this is why before each release we're running [unit tests](./tests), we also research and update the detection rules on <b>daily</b> and <b>weekly</b> basis.
<p>
<img src="https://dl.dropboxusercontent.com/u/70897251/impress_ghita_460px.jpg"><br>
<b>Thanks <a href="http://impresspages.org">ImpressPages</a> CMS for showing us some love!</b></p>
##### Download and demo
<a href="https://github.com/serbanghita/Mobile-Detect/tags">Latest releases</a>, <a href="https://github.com/serbanghita/Mobile-Detect/blob/devel/Mobile_Detect.php">Latest dev branch</a>, <a href="https://packagist.org/packages/mobiledetect/mobiledetectlib">composer package</a>
See also: <a href="https://github.com/serbanghita/Mobile-Detect/wiki/Become-a-contributor">:bulb: Become a contributor</a> / <a href="https://github.com/serbanghita/Mobile-Detect/wiki/History">:coffee: History</a> / <a href="https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples">:point_right: Code examples</a> /
<a href="http://is.gd/mobiletest">:iphone: Live demo!</a> (point your device browser to this URL)
##### Help
<a href="http://pledgie.com/campaigns/21856"><img alt='Click here to lend your support to: Research and development of Mobile Detect library!' src='http://www.pledgie.com/campaigns/21856.png?skin_name=chrome' border='0' /></a>
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=mobiledetectlib%40gmail%2ecom&lc=US&item_name=Mobile%20Detect&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" border="0"></a>
I'm currently paying for hosting and spend a lot of my family time :family: to maintain the project and planning the future releases.
I would highly appreciate any money donations that will keep the research going.
Special thanks to the community :+1: for donations, [BrowserStack](http://browserstack.com) - for providing access to their great platform, [Zend](http://zend.com) - for donating licenses, [Dragos Gavrila](https://twitter.com/grafician) who contributed with the logo.
##### 3rd party modules / [Submit new](https://github.com/serbanghita/Mobile-Detect/issues/new?title=New%203rd%20party%20module&body=Name, Link and Description of the module.)
:point_right: Keep `Mobile_Detect.php` class in a separate `module` and do NOT include it in your script core because of the high frequency of updates.
:point_right: When including the class into you `web application` or `module` always use `include_once '../path/to/Mobile_Detect.php` to prevent conflicts.
<table>
<tr>
<td>Varnish Cache</td>
<td><p><a href="https://github.com/willemk/varnish-mobiletranslate">Varnish Mobile Detect</a> - Drop-in varnish solution to mobile user detection based on the Mobile-Detect library. Made by <a href="https://github.com/willemk">willemk</a></p></td>
</tr>
<tr>
<td>WordPress</td>
<td>
<p><a href="http://wordpress.org/extend/plugins/wp-mobile-detect/">WordPress Mobile Detect</a> - Gives you the ability to wrap that infographic in a [notdevice][/notdevice] shortcode so at the server level <code>WordPress</code> will decide to show that content only if the user is NOT on a phone or tablet. Made by <a href="http://profiles.wordpress.org/professor44/">Jesse Friedman</a>.</p>
<p><a href="http://wordpress.org/plugins/mobble/">mobble</a> - provides mobile related conditional functions for your site. e.g. is_iphone(), is_mobile() and is_tablet(). Made by Scott Evans.</p>
<p><a href="https://github.com/iamspacehead/responsage">WordPress Responsage</a> - A small <code>WordPress</code> theme plugin that allows you to make your images responsive. Made by <a href="https://github.com/iamspacehead">Adrian Ciaschetti</a>.</p>
<p><a href="http://wordpress.org/plugins/social-popup/">Social PopUP</a> - This plugin will display a popup or splash screen when a new user visit your site showing a Google+, Twitter and Facebook follow links. It uses Mobile_Detect to detect mobile devices.</p>
</td>
</tr>
<tr>
<td>Drupal</td>
<td>
<p><a href="http://drupal.org/project/mobile_switch">Drupal Mobile Switch</a> - The Mobile Switch <code>Drupal</code> module provides a automatic theme switch functionality for mobile devices,
detected by Browscap or Mobile Detect. Made by <a href="http://drupal.org/user/45267">Siegfried Neumann</a>.</p>
<p><a href="http://drupal.org/project/context_mobile_detect">Drupal Context Mobile Detect</a> - This is a <code>Drupal context</code> module which integrates Context and PHP Mobile Detect library.
Created by <a href="http://drupal.org/user/432492">Artem Shymko</a>.</p>
<p><a href="http://drupal.org/project/mobile_detect">Drupal Mobile Detect</a> - Lightweight mobile detect module for <code>Drupal</code> created by <a href="http://drupal.org/user/325244">Matthew Donadio</a></p>
</td>
</tr>
<tr>
<td>Joomla</td>
<td><p><a href="http://www.yagendoo.com/en/blog/free-mobile-detection-plugin-for-joomla.html">yagendoo Joomla! Mobile Detection Plugin</a> - Lightweight PHP plugin for Joomla! that detects a mobile browser using the Mobile Detect class. Made by <a href="http://www.yagendoo.com/">yagendoo media</a>.</p></td>
</tr>
<tr>
<td>Magento</td>
<td><p><a href="http://www.magentocommerce.com/magento-connect/catalog/product/view/id/16835/">Magento</a> - This <code>Magento helper</code> from Optimise Web enables the use of all functions provided by MobileDetect.net.
Made by <a href="http://www.kathirvel.com">Kathir Vel</a>.</p></td>
</tr>
<tr>
<td>PrestaShop</td>
<td><p><a href="http://www.prestashop.com/">PrestaShop</a> is a free, secure and open source shopping cart platform. Mobile_Detect is included in the default package since 1.5.x.</p></td>
</tr>
<tr>
<td>Zend Framework</td>
<td>
<p><a href="https://github.com/neilime/zf2-mobile-detect.git">ZF2 Mobile-Detect</a> - Zend Framework 2 module that provides Mobile-Detect features (Mobile_Detect class as a service, helper for views and plugin controllers). Made by <a href="https://github.com/neilime">neilime</a></p>
<p><a href="https://github.com/nikolaposa/MobileDetectModule">ZF2 MobileDetectModule</a> - Facilitates integration of a PHP MobileDetect class with some ZF2-based application. Has similar idea like the existing ZF2 Mobile-Detect module, but differs in initialization and provision routine of the actual Mobile_Detect class. Appropriate view helper and controller plugin also have different conceptions. Made by <a href="https://github.com/nikolaposa">Nikola Posa</a></p>
</td>
</tr>
<tr>
<td>Symfony</td>
<td><p><a href="https://github.com/suncat2000/MobileDetectBundle">Symfony2 Mobile Detect Bundle</a> - The bundle for detecting mobile devices, manage mobile view and redirect to the mobile and tablet version.
Made by <a href="https://github.com/suncat2000">Nikolay Ivlev</a>.</p>
<p><a href="https://github.com/jbinfo/MobileDetectServiceProvider">Silex Mobile Detect Service Provider</a> - <code>Silex</code> service provider to interact with Mobile detect class methods. Made by <a href="https://github.com/jbinfo">Lhassan Baazzi</a>.</p>
</td>
</tr>
<tr>
<td>Laravel</td>
<td>
<p><a href="https://github.com/jenssegers/Laravel-Agent">Laravel-Agent</a> a user agent class for Laravel, based on Mobile Detect with some additional functionality. Made by <a href="https://github.com/jenssegers">Jens Segers</a>.</p>
<p><a href="https://github.com/hisorange/browser-detect">BrowserDetect</a>is a browser &amp; mobile detection package, collects and wrap together the best user-agent identifiers for Laravel. Created by <a href="https://github.com/hisorange">Varga Zsolt</a>.</p>
</td>
</tr>
<tr>
<td>ExpressionEngine</td>
<td><p><a href="https://github.com/garethtdavies/detect-mobile">EE2 Detect Mobile</a> - Lightweight PHP plugin for <code>EE2</code> that detects a mobile browser using the Mobile Detect class. Made by <a href="https://github.com/garethtdavies">Gareth Davies</a>.</p></td>
</tr>
<tr>
<td>Yii Framework</td>
<td><p><a href="https://github.com/iamsalnikov/MobileDetect">Yii Extension</a> - Mobile detect plugin for Yii framework. Made by <a href="https://github.com/iamsalnikov">Alexey Salnikov</a>.</p></td>
</tr>
<tr>
<td>CakePHP</td>
<td><p><a href="https://github.com/chronon/CakePHP-MobileDetectComponent-Plugin">CakePHP MobileDetect</a> - <code>plugin</code> component for <code>CakePHP</code> 2.x. Made by <a href="https://github.com/chronon">Gregory Gaskill</a></p></td>
</tr>
<tr>
<td>FuelPHP</td>
<td><a href="https://github.com/rob-bar/special_agent">Special Agent</a> is a FuelPHP package which uses php-mobile-detect to determine whether a device is mobile or not.
It overrides the Fuelphp Agent class its methods. Made by <a href="https://github.com/rob-bar">Robbie Bardjin</a>.</td>
</tr>
<tr>
<td>Typo3</td>
<td><a href="http://docs.typo3.org/typo3cms/extensions/px_mobiledetect/1.0.2/">px_mobiledetect</a> is an extension that helps to detect visitor's mobile device class (if thats tablet or mobile device like smartphone). Made by Alexander Tretyak.</td>
</tr>
<tr>
<td>Statamic</td>
<td><p><a href="https://github.com/sergeifilippov/statamic-mobile-detect">Statamic CMS Mobile Detect</a> - <code>plugin</code>. Made by <a href="https://github.com/haikulab/statamic-mobile-detect">Sergei Filippov of Haiku Lab</a>.</p></td>
</tr>
<tr>
<td>mobile-detect.js</td>
<td><p>A <a href="https://github.com/hgoebl/mobile-detect.js">JavaScript port</a> of Mobile-Detect class. Made by <a href="https://github.com/hgoebl">Heinrich Goebl</a></p></td>
</tr>
<tr>
<td>python</td>
<td><p><a href="http://pypi.python.org/pypi/pymobiledetect">pymobiledetect</a> - Mobile detect <code>python package</code>. Made by Bas van Oostveen.</p></td>
</tr>
<tr>
<td>GoMobileDetect</td>
<td><p><a href="https://github.com/Shaked/gomobiledetect">GoMobileDetect</a> - Go port of Mobile Detect class. Made by <a href="https://github.com/Shaked">Shaked</a>.</p></td>
</tr>
<tr>
<td>MemHT</td>
<td><p><a href="http://www.memht.com/">MemHT</a> is a Free PHP CMS and Blog that permit the creation and the management online of websites with few and easy steps. Has the class included in the core.</p></td>
</tr>
<tr>
<td>concrete5</td>
<td><p><a href="https://www.concrete5.org/">concrete5</a> is a CMS that is free and open source. The library is included in the core.</p></td>
</tr>
<tr>
<td>engine7</td>
<td><p><a href="https://github.com/gchiappe/exengine7">ExEngine 7</a> PHP Open Source Framework. The Mobile_Detect class is included in the engine.</p></td>
</tr>
<tr>
<td>Zikula</td>
<td><p><a href="http://zikula.org/">Zikula</a> is a free and open-source Content Management Framework, which allows you to run impressive websites and build powerful online applications. The core uses Mobile-Detect to switch to a special Mobile theme, using jQueryMobile</p></td>
</tr>
<tr>
<td>UserAgentInfo</td>
<td><p><a href="https://github.com/quentin389/UserAgentInfo">UserAgentInfo</a> is a PHP class for parsing user agent strings (HTTP_USER_AGENT). Includes mobile checks, bot checks, browser types/versions and more.
Based on browscap, Mobile_Detect and ua-parser. Created for high traffic websites and fast batch processing. Made by <a href="https://github.com/quentin389">quentin389</a></p></td>
</tr>
<tr>
<td>Craft CMS</td>
<td><p><a href="https://github.com/lewisjenkins/craft-lj-mobiledetect">LJ Mobile Detect</a> is a simple implementation of Mobile Detect for Craft CMS. Made by <a href="https://github.com/lewisjenkins">Lewis Jenkins</a></p></td>
</tr>
</table>

View File

@@ -0,0 +1,28 @@
{
"name": "mobiledetect/mobiledetectlib",
"type": "library",
"description": "Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.",
"keywords": ["mobile", "mobile detect", "mobile detector", "php mobile detect", "detect mobile devices"],
"homepage": "https://github.com/serbanghita/Mobile-Detect",
"license": "MIT",
"authors": [
{
"name": "Serban Ghita",
"email": "serbanghita@gmail.com",
"homepage": "http://mobiledetect.net",
"role": "Developer"
}
],
"require": {
"php": ">=5.0.0"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"autoload": {
"classmap": ["Mobile_Detect.php"],
"psr-0": {
"Detection": "namespaced/"
}
}
}

View File

@@ -0,0 +1,439 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "5b2d87ea9e6c115194bd355b7b697cec",
"packages": [
],
"packages-dev": [
{
"name": "phpunit/php-code-coverage",
"version": "1.2.12",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "1.2.12"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/1.2.12",
"reference": "1.2.12",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"phpunit/php-file-iterator": ">=1.3.0@stable",
"phpunit/php-text-template": ">=1.1.1@stable",
"phpunit/php-token-stream": ">=1.1.3@stable"
},
"require-dev": {
"phpunit/phpunit": "3.7.*@dev"
},
"suggest": {
"ext-dom": "*",
"ext-xdebug": ">=2.0.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
},
"autoload": {
"classmap": [
"PHP/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
"homepage": "https://github.com/sebastianbergmann/php-code-coverage",
"keywords": [
"coverage",
"testing",
"xunit"
],
"time": "2013-07-06 06:26:16"
},
{
"name": "phpunit/php-file-iterator",
"version": "1.3.3",
"source": {
"type": "git",
"url": "git://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "1.3.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/sebastianbergmann/php-file-iterator/zipball/1.3.3",
"reference": "1.3.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"File/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "FilterIterator implementation that filters files based on a list of suffixes.",
"homepage": "http://www.phpunit.de/",
"keywords": [
"filesystem",
"iterator"
],
"time": "2012-10-11 04:44:38"
},
{
"name": "phpunit/php-text-template",
"version": "1.1.4",
"source": {
"type": "git",
"url": "git://github.com/sebastianbergmann/php-text-template.git",
"reference": "1.1.4"
},
"dist": {
"type": "zip",
"url": "https://github.com/sebastianbergmann/php-text-template/zipball/1.1.4",
"reference": "1.1.4",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"Text/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Simple template engine.",
"homepage": "https://github.com/sebastianbergmann/php-text-template/",
"keywords": [
"template"
],
"time": "2012-10-31 11:15:28"
},
{
"name": "phpunit/php-timer",
"version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-timer.git",
"reference": "1.0.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1.0.5",
"reference": "1.0.5",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"PHP/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Utility class for timing",
"homepage": "https://github.com/sebastianbergmann/php-timer/",
"keywords": [
"timer"
],
"time": "2013-08-02 07:42:54"
},
{
"name": "phpunit/php-token-stream",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
"reference": "1.2.0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1.2.0",
"reference": "1.2.0",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2-dev"
}
},
"autoload": {
"classmap": [
"PHP/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Wrapper around PHP's tokenizer extension.",
"homepage": "https://github.com/sebastianbergmann/php-token-stream/",
"keywords": [
"tokenizer"
],
"time": "2013-08-04 05:57:48"
},
{
"name": "phpunit/phpunit",
"version": "3.7.23",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "3.7.23"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3.7.23",
"reference": "3.7.23",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-pcre": "*",
"ext-reflection": "*",
"ext-spl": "*",
"php": ">=5.3.3",
"phpunit/php-code-coverage": "~1.2.1",
"phpunit/php-file-iterator": ">=1.3.1",
"phpunit/php-text-template": ">=1.1.1",
"phpunit/php-timer": ">=1.0.4",
"phpunit/phpunit-mock-objects": "~1.2.0",
"symfony/yaml": "~2.0"
},
"require-dev": {
"pear-pear/pear": "1.9.4"
},
"suggest": {
"ext-json": "*",
"ext-simplexml": "*",
"ext-tokenizer": "*",
"phpunit/php-invoker": ">=1.1.0,<1.2.0"
},
"bin": [
"composer/bin/phpunit"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.7.x-dev"
}
},
"autoload": {
"classmap": [
"PHPUnit/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"",
"../../symfony/yaml/"
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "The PHP Unit Testing framework.",
"homepage": "http://www.phpunit.de/",
"keywords": [
"phpunit",
"testing",
"xunit"
],
"time": "2013-08-02 19:14:44"
},
{
"name": "phpunit/phpunit-mock-objects",
"version": "1.2.3",
"source": {
"type": "git",
"url": "git://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "1.2.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects/archive/1.2.3.zip",
"reference": "1.2.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"phpunit/php-text-template": ">=1.1.1@stable"
},
"suggest": {
"ext-soap": "*"
},
"type": "library",
"autoload": {
"classmap": [
"PHPUnit/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Mock Object library for PHPUnit",
"homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
"keywords": [
"mock",
"xunit"
],
"time": "2013-01-13 10:24:48"
},
{
"name": "symfony/yaml",
"version": "v2.3.2",
"target-dir": "Symfony/Component/Yaml",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
"reference": "v2.3.2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/v2.3.2",
"reference": "v2.3.2",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
}
},
"autoload": {
"psr-0": {
"Symfony\\Component\\Yaml\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Yaml Component",
"homepage": "http://symfony.com",
"time": "2013-07-11 19:36:36"
}
],
"aliases": [
],
"minimum-stability": "stable",
"stability-flags": [
],
"platform": {
"php": ">=5.0.0"
},
"platform-dev": [
]
}

View File

@@ -0,0 +1,258 @@
<?php
/**
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* -----------------------------------------------------------------------
* The demo is running all the Mobile_Detect's internal methods.
* Here you can spot detections errors instantly.
* -----------------------------------------------------------------------
*
* @author Serban Ghita <serbanghita@gmail.com>
* @license MIT License https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt
*
*/
require_once '../Mobile_Detect.php';
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
$scriptVersion = $detect->getScriptVersion();
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<title>Mobile Detect Local Demo</title>
<style type="text/css">
html { font-size: 100%; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
body { margin: 0; padding: 0 1em; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 1em; color: #333333; background-color: #ffffff; max-width:320px; }
body, td { font-size: 1em; }
table th { text-align:left; }
a { color: #0088cc; text-decoration: underline; }
a:hover { color: #005580; text-decoration: underline; }
header h1 small { font-size:small; }
section { margin-bottom:2em; }
section h1 { font-size:100%; }
.infoText { font-size:85%; }
.response { color:red; }
.computer { background-color:blue; color:white; }
.tablet { background-color:yellow; color:black; }
.phone, .true { background-color:green; color:white; }
.sendDataButton { border-radius: 1em; -moz-border-radius: 1em; -webkit-border-radius: 1em; padding:0.5em 1em; cursor: pointer; }
.sendDataButton_yes {
color:white;
border: 1px solid #56A00E;
background: #74B042;
font-weight: bold;
color: #ffffff;
text-shadow: 0 1px 0 #335413;
background-image: -webkit-gradient(linear, left top, left bottom, from( #74B042 ), to( #56A00E )); /* Saf4+, Chrome */
background-image: -webkit-linear-gradient( #74B042 , #56A00E ); /* Chrome 10+, Saf5.1+ */
background-image: -moz-linear-gradient( #74B042 , #56A00E ); /* FF3.6 */
background-image: -ms-linear-gradient( #74B042 , #56A00E ); /* IE10 */
background-image: -o-linear-gradient( #74B042 , #56A00E ); /* Opera 11.10+ */
background-image: linear-gradient( #74B042 , #56A00E );
}
.sendDataButton_no {
color:white;
border: 1px solid #cd2c24;
background: red;
font-weight: bold;
color: #ffffff;
text-shadow: 0 1px 0 #444444;
background-image: -webkit-gradient(linear, left top, left bottom, from( #e13027 ), to( #b82720 )); /* Saf4+, Chrome */
background-image: -webkit-linear-gradient( #e13027 , #b82720 ); /* Chrome 10+, Saf5.1+ */
background-image: -moz-linear-gradient( #e13027 , #b82720 ); /* FF3.6 */
background-image: -ms-linear-gradient( #e13027 , #b82720 ); /* IE10 */
background-image: -o-linear-gradient( #e13027 , #b82720 ); /* Opera 11.10+ */
background-image: linear-gradient( #e13027 , #b82720 );
}
#feedbackForm fieldset { border:1px dotted #333; }
#feedbackForm label { font-weight:bold; font-size:85%; }
#feedbackForm textarea { width: 260px; }
</style>
<script src="//code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.sendDataButton').bind('click.demo', function(e){
$button = $(this);
e.preventDefault();
$.ajax({
url: 'http://demo.mobiledetect.net/?page=addItem',
type: 'POST',
dataType: 'jsonp',
data: {
remoteDetails: $('#remoteDetails').val(),
remoteAnswer: $(this).attr('data-answer'),
uaStringFromJS: escape(navigator.userAgent),
deviceWidth: $(window).width(),
deviceHeight: $(window).height(),
source: 'demoFeedback'
},
beforeSend: function(){
$button.html('Loading...');
},
success: function(r){
$('#feedbackForm').html('<p class="response">'+r.msg+'</p>');
}
});
});
$.ajax({
url: 'http://demo.mobiledetect.net/?page=addItem',
type: 'POST',
dataType: 'jsonp',
data: {
//uaStringFromJS: escape(navigator.userAgent),
deviceWidth: $(window).width(),
deviceHeight: $(window).height(),
devicePixelRatio: (typeof window.devicePixelRatio !== 'undefined' ? window.devicePixelRatio : 0),
'source': 'demoVisitor'
},
success: function(r){
try { console.log(r); } catch (e) { }
}
});
});
</script>
</head>
<body>
<header>
<h1><a href="https://github.com/serbanghita/Mobile-Detect">Mobile_Detect</a> <small>v. <?php echo $scriptVersion; ?></small></h1>
<p class="infoText">The lightweight PHP class for detecting mobile devices.</p>
</header>
<!-- copy to GitHub with a couple of changes -->
<section>
<p>This is a <b><?php echo $deviceType; ?></b>. Your UA is <b class="<?php echo $deviceType; ?>"><?php echo htmlentities($_SERVER['HTTP_USER_AGENT']); ?></b></p>
<p class="infoText">Please help us improve the mobile detection by choosing the correct answer.<br>
Before sending an answer double check if you are using the browser in 'Desktop mode'.<br>
You can contribute by:<br>
1. <a href="https://github.com/serbanghita/Mobile-Detect">forking</a> the project<br>
2. <a href="https://github.com/serbanghita/Mobile-Detect/issues/new?body=Please%20specify%20the%20User-Agent.%20Go%20to%20http://is.gd/mobiletest%20and%20copy-paste%20it%20here.">submiting an issue</a><br>
3. sending us feedback below
</p>
<form id="feedbackForm">
<fieldset>
<legend>Contribute</legend>
<h1>Is your device really a <?php echo $deviceType; ?>?</h1>
<p>
<label for="remoteDetails">Additional feedback:</label><br>
<textarea name="remoteDetails" id="remoteDetails"></textarea>
</p>
<button class="sendDataButton sendDataButton_yes" data-answer="yes">♥ Yes, it's correct.</button> <button class="sendDataButton sendDataButton_no" data-answer="no">No, it's wrong!</button>
</fieldset>
</form>
</section>
<!-- copy to GitHub demo.php -->
<section>
<h1>Supported methods</h1>
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th colspan="2">Basic detection methods</th>
</tr>
<tr>
<td>isMobile()</td><td <?php $check = $detect->isMobile(); if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td>
</tr>
<tr>
<td>isTablet()</td><td <?php $check = $detect->isTablet(); if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td>
</tr>
</tbody>
<tbody>
<tr>
<th colspan="2">Custom detection methods</th>
</tr>
<?php foreach($detect->getRules() as $name => $regex):
$check = $detect->{'is'.$name}();
?>
<tr>
<td>is<?php echo $name; ?>()</td>
<td <?php if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tbody>
<tr>
<th colspan="2">Experimental version() method</th>
</tr>
<?php
foreach($detect->getProperties() as $name => $match):
$check = $detect->version($name);
if($check!==false):
?>
<tr>
<td>version(<?php echo $name; ?>)</td>
<td><?php var_dump($check); ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
<tbody>
<tr>
<th colspan="2">Other tests</th>
</tr>
<tr>
<td>isiphone()</td>
<td><?php var_dump($detect->isiphone()); ?></td>
</tr>
<tr>
<td>isIphone()</td>
<td><?php var_dump($detect->isIphone()); ?></td>
</tr>
<tr>
<td>istablet()</td>
<td><?php var_dump($detect->istablet()); ?></td>
</tr>
<tr>
<td>isIOS()</td>
<td><?php var_dump($detect->isIOS()); ?></td>
</tr>
<tr>
<td>isWhateverYouWant()</td>
<td class="randomcrap"><?php var_dump($detect->isWhateverYouWant()); ?></td>
</tr>
</tbody>
</table>
</section>
</body>
</html>

View File

@@ -0,0 +1,146 @@
<?php
/**
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* -----------------------------------------------------------------------
*
*
* Run this in your browser to see the example!
*
*
*
* IMPORTANT: Clear your sessions/cookies before running UA tests.
*
* This is a procedural approach example of how to switch your website layout
* based on a variable $layoutType.
*
* The example also includes the switch links that you can put in the footer
* of your page. Is a good practice to let the user switch between layouts,
* even if he is visiting the page from a phone or tablet.
* ------------------------------------------------------------------------
*
* @author Serban Ghita <serbanghita@gmail.com>
* @license MIT License https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt
*
*/
// This is mandatory if you're using sessions.
session_start();
// It's mandatory to include the library.
require_once '../Mobile_Detect.php';
/**
* Begin helper functions.
*/
// Your default site layouts.
// Update this array if you have fewer layout types.
function layoutTypes()
{
return array('classic', 'mobile', 'tablet');
}
function initLayoutType()
{
// Safety check.
if (!class_exists('Mobile_Detect')) { return 'classic'; }
$detect = new Mobile_Detect;
$isMobile = $detect->isMobile();
$isTablet = $detect->isTablet();
$layoutTypes = layoutTypes();
// Set the layout type.
if ( isset($_GET['layoutType']) ) {
$layoutType = $_GET['layoutType'];
} else {
if (empty($_SESSION['layoutType'])) {
$layoutType = ($isMobile ? ($isTablet ? 'tablet' : 'mobile') : 'classic');
} else {
$layoutType = $_SESSION['layoutType'];
}
}
// Fallback. If everything fails choose classic layout.
if ( !in_array($layoutType, $layoutTypes) ) { $layoutType = 'classic'; }
// Store the layout type for future use.
$_SESSION['layoutType'] = $layoutType;
return $layoutType;
}
/**
* End helper functions.
*/
// Let's roll. Call this function!
$layoutType = initLayoutType();
/**
*
* Example of layout switch links.
* Eg. ['Classic' | Mobile | 'Tablet']
*
*/
?>
<?php if(!isset($_GET['page'])): ?>
<!-- example page #1 -->
<h1>Demo page number one.</h1>
<p>You can go to page <a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=two">two</a>.</p>
<p>Showing you the <b><?php echo $layoutType; ?></b> version.</p>
<p><b>Note:</b> When running this test using the same browser with multiple User-Agents, clear your cookies/session before each test.</p>
<?php endif; ?>
<?php if(isset($_GET['page']) && $_GET['page']=='two'): ?>
<!-- example page #2 -->
<h1>Demo page number two.</h1>
<p>You can go back to page <a href="<?php echo $_SERVER['PHP_SELF']; ?>">one</a>.</p>
<p>Showing you the <b><?php echo $layoutType; ?></b> version.</p>
<?php endif; ?>
<!-- Footer links example. Change this as you like. -->
<?php foreach(layoutTypes() as $_layoutType): ?>
<?php if($_layoutType == $layoutType): ?>
<?php echo strtoupper($_layoutType); ?>
<?php else: ?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?layoutType=<?php echo $_layoutType; ?>"><?php echo strtoupper($_layoutType); ?></a>
<?php endif; ?>
<?php endforeach;

View File

@@ -0,0 +1,68 @@
<?php
/**
* Mobile Detect Library
* - export -
* =====================
*
* Use the resulting JSON export file in other languages
* other than PHP. Always check for 'version' key because
* new major versions can modify the structure of the JSON file.
*
* The result of running this script is the export.json file.
*
* @license Code and contributions have 'MIT License'
* More details: https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt
*
*/
// Included nicejson function to beautify the result JSON file.
// This library is not mandatory.
if( file_exists(dirname(__FILE__).'/nicejson/nicejson.php') ) {
include_once dirname(__FILE__).'/nicejson/nicejson.php';
}
// Include Mobile Detect.
require_once dirname(__FILE__).'/../Mobile_Detect.php';
$detect = new Mobile_Detect;
$json = array(
// The current version of Mobile Detect class that
// is being exported.
'version' => $detect->getScriptVersion(),
// All headers that trigger 'isMobile' to be 'true',
// before reaching the User-Agent match detection.
'headerMatch' => $detect->getMobileHeaders(),
// All possible User-Agent headers.
'uaHttpHeaders' => $detect->getUaHttpHeaders(),
// All the regexes that trigger 'isMobile' or 'isTablet'
// to be true.
'uaMatch' => array(
// If match is found, triggers 'isMobile' to be true.
'phones' => $detect->getPhoneDevices(),
// Triggers 'isTablet' to be true.
'tablets' => $detect->getTabletDevices(),
// If match is found, triggers 'isMobile' to be true.
'browsers' => $detect->getBrowsers(),
// If match is found, triggers 'isMobile' to be true.
'os' => $detect->getOperatingSystems()
)
);
$jsonString = function_exists('json_format') ? json_format($json) : json_encode($json);
// Write the JSON file to disk.
// You can import this file in your app.
$fileName = dirname(__FILE__).'/../Mobile_Detect.json';
$handle = fopen($fileName, 'w');
$fwrite = fwrite($handle, $jsonString);
fclose($handle);
if($fwrite){
echo 'Done. Check '.realpath($fileName).' file.';
} else {
echo 'Failed to write '.realpath($fileName).' to disk.';
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* Little piece of PHP to make Mobile_Detect auto-loadable in PSR-0 compatible PHP autoloaders like
* the Symfony Universal ClassLoader by Fabien Potencier. Since PSR-0 handles an underscore in
* classnames (on the filesystem) as a slash, "Mobile_Detect.php" autoloaders will try to convert
* the classname and path to "Mobile\Detect.php". This script will ensure autoloading with:
* - Namespace: Detection
* - Classname: MobileDetect
* - Namespased: \Detection\MobileDetect
* - Autoload path: ./namespaced
* - Converted path: ./namespaced/Detection/MobileDetect.php
*
* Don't forget to use MobileDetect (instead of Mobile_Detect) as class in code when autoloading.
*
* Thanks to @WietseWind.
* For details please check: https://github.com/serbanghita/Mobile-Detect/pull/120
*/
namespace Detection;
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Mobile_Detect.php';
class MobileDetect extends \Mobile_Detect {}

View File

@@ -0,0 +1,494 @@
<?php
/**
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* @author Serban Ghita <serbanghita@gmail.com>
* @license MIT License https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt
* @link http://mobiledetect.net
*/
class BasicTest extends PHPUnit_Framework_TestCase
{
/**
* @var Mobile_Detect
*/
protected $detect;
public function testClassExists()
{
$this->assertTrue(class_exists('Mobile_Detect'));
}
public function setUp()
{
$this->detect = new Mobile_Detect;
}
public function testBasicMethods()
{
$this->assertNotEmpty( $this->detect->getScriptVersion() );
$this->detect->setHttpHeaders(array(
'SERVER_SOFTWARE' => 'Apache/2.2.15 (Linux) Whatever/4.0 PHP/5.2.13',
'REQUEST_METHOD' => 'POST',
'HTTP_HOST' => 'home.ghita.org',
'HTTP_X_REAL_IP' => '1.2.3.4',
'HTTP_X_FORWARDED_FOR' => '1.2.3.5',
'HTTP_CONNECTION' => 'close',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25',
'HTTP_ACCEPT' => 'text/vnd.wap.wml, application/json, text/javascript, */*; q=0.01',
'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest',
'HTTP_REFERER' => 'http://mobiledetect.net',
'HTTP_PRAGMA' => 'no-cache',
'HTTP_CACHE_CONTROL' => 'no-cache',
'REMOTE_ADDR' => '11.22.33.44',
'REQUEST_TIME' => '01-10-2012 07:57'
));
//12 because only 12 start with HTTP_
$this->assertCount( 12, $this->detect->getHttpHeaders() );
$this->assertTrue( $this->detect->checkHttpHeadersForMobile() );
$this->detect->setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25');
$this->assertNotEmpty( $this->detect->getUserAgent() );
$this->assertTrue( $this->detect->isMobile() );
$this->assertFalse( $this->detect->isTablet() );
$this->assertTrue( $this->detect->isIphone() );
$this->assertTrue( $this->detect->isiphone() );
$this->assertTrue( $this->detect->isiOS() );
$this->assertTrue( $this->detect->isios() );
$this->assertTrue( $this->detect->is('iphone') );
$this->assertTrue( $this->detect->is('ios') );
}
public function headersProvider()
{
return array(
array(array(
'SERVER_SOFTWARE' => 'Apache/2.2.15 (Linux) Whatever/4.0 PHP/5.2.13',
'REQUEST_METHOD' => 'POST',
'HTTP_HOST' => 'home.ghita.org',
'HTTP_X_REAL_IP' => '1.2.3.4',
'HTTP_X_FORWARDED_FOR' => '1.2.3.5',
'HTTP_CONNECTION' => 'close',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25',
'HTTP_ACCEPT' => 'text/vnd.wap.wml, application/json, text/javascript, */*; q=0.01',
'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest',
'HTTP_REFERER' => 'http://mobiledetect.net',
'HTTP_PRAGMA' => 'no-cache',
'HTTP_CACHE_CONTROL' => 'no-cache',
'REMOTE_ADDR' => '11.22.33.44',
'REQUEST_TIME' => '01-10-2012 07:57'
)),
array(array(
'SERVER_SOFTWARE' => 'Rogue software',
'REQUEST_METHOD' => 'GET',
'REMOTE_ADDR' => '8.8.8.8',
'REQUEST_TIME' => '07-10-2013 23:56',
'HTTP_USER_AGENT' => "garbage/1.0"
)),
array(array(
'SERVER_SOFTWARE' => 'Apache/1.3.17 (Linux) PHP/5.5.2',
'REQUEST_METHOD' => 'HEAD',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 1.5; en-us; ADR6200 Build/CUPCAKE) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1',
'REMOTE_ADDR' => '1.250.250.0',
'REQUEST_TIME' => '06-12-2006 11:06'
)),
);
}
/**
* @dataProvider headersProvider
* @covers Mobile_Detect::getHttpHeader
*/
public function testConstructorInjection(array $headers)
{
$md = new Mobile_Detect($headers);
foreach ($headers as $header => $value) {
if (substr($header, 0, 5) !== 'HTTP_') {
//make sure it wasn't set
$this->assertNull($md->getHttpHeader($value));
} else {
//make sure it's equal
$this->assertEquals($value, $md->getHttpHeader($header));
}
}
//verify some of the headers work with the translated getter
$this->assertNull($md->getHttpHeader('Remote-Addr'));
$this->assertNull($md->getHttpHeader('Server-Software'));
$this->assertEquals($headers['HTTP_USER_AGENT'], $md->getHttpHeader('User-Agent'));
}
/**
* @dataProvider headersProvider
* @covers Mobile_Detect::getHttpHeader
*/
public function testInvalidHeader($headers)
{
$md = new Mobile_Detect($headers);
$this->assertNull($md->getHttpHeader('garbage_is_Garbage'));
}
public function userAgentProvider()
{
return array(
array(array(
'HTTP_USER_AGENT' => 'blah'
), 'blah'),
array(array(
'HTTP_USER_AGENT' => 'iphone',
'HTTP_X_OPERAMINI_PHONE_UA' => 'some other stuff'
), 'iphone some other stuff'),
array(array(
'HTTP_X_DEVICE_USER_AGENT' => 'hello world'
), 'hello world'),
array(array(), null)
);
}
/**
* @dataProvider userAgentProvider
* @covers Mobile_Detect::setUserAgent, Mobile_Detect::getUserAgent
*/
public function testGetUserAgent($headers, $expectedUserAgent)
{
$md = new Mobile_Detect($headers);
$md->setUserAgent();
$this->assertSame($expectedUserAgent, $md->getUserAgent());
}
/**
* Headers should be reset when you use setHttpHeaders.
* @covers Mobile_Detect::setHttpHeaders
* @issue #144
*/
public function testSetHttpHeaders()
{
$header1 = array('HTTP_PINK_PONY' => 'I secretly love ponies >_>');
$md = new Mobile_Detect($header1);
$this->assertSame($md->getHttpHeaders(), $header1);
$header2 = array('HTTP_FIRE_BREATHING_DRAGON' => 'yeah!');
$md->setHttpHeaders($header2);
$this->assertSame($md->getHttpHeaders(), $header2);
}
/**
* @covers Mobile_Detect::setUserAgent, Mobile_Detect::getUserAgent
*/
public function testSetUserAgent()
{
$md = new Mobile_Detect(array());
$md->setUserAgent('hello world');
$this->assertSame('hello world', $md->getUserAgent());
}
/**
* @covers Mobile_Detect::setDetectionType
*/
public function testSetDetectionType()
{
$md = new Mobile_Detect(array());
$md->setDetectionType('bskdfjhs');
$this->assertAttributeEquals(
Mobile_Detect::DETECTION_TYPE_MOBILE,
'detectionType',
$md
);
$md->setDetectionType();
$this->assertAttributeEquals(
Mobile_Detect::DETECTION_TYPE_MOBILE,
'detectionType',
$md
);
$md->setDetectionType(Mobile_Detect::DETECTION_TYPE_MOBILE);
$this->assertAttributeEquals(
Mobile_Detect::DETECTION_TYPE_MOBILE,
'detectionType',
$md
);
$md->setDetectionType(Mobile_Detect::DETECTION_TYPE_EXTENDED);
$this->assertAttributeEquals(
Mobile_Detect::DETECTION_TYPE_EXTENDED,
'detectionType',
$md
);
}
//special headers that give 'quick' indication that a device is mobile
public function quickHeadersData()
{
return array(
array(array(
'HTTP_ACCEPT' => 'application/json; q=0.2, application/x-obml2d; q=0.8, image/gif; q=0.99, */*'
)),
array(array(
'HTTP_ACCEPT' => 'text/*; q=0.1, application/vnd.rim.html'
)),
array(array(
'HTTP_ACCEPT' => 'text/vnd.wap.wml',
)),
array(array(
'HTTP_ACCEPT' => 'application/vnd.wap.xhtml+xml',
)),
array(array(
'HTTP_X_WAP_PROFILE' => 'hello',
)),
array(array(
'HTTP_X_WAP_CLIENTID' => ''
)),
array(array(
'HTTP_WAP_CONNECTION' => ''
)),
array(array(
'HTTP_PROFILE' => ''
)),
array(array(
'HTTP_X_OPERAMINI_PHONE_UA' => ''
)),
array(array(
'HTTP_X_NOKIA_GATEWAY_ID' => ''
)),
array(array(
'HTTP_X_ORANGE_ID' => ''
)),
array(array(
'HTTP_X_VODAFONE_3GPDPCONTEXT' => ''
)),
array(array(
'HTTP_X_HUAWEI_USERID' => ''
)),
array(array(
'HTTP_UA_OS' => ''
)),
array(array(
'HTTP_X_MOBILE_GATEWAY' => ''
)),
array(array(
'HTTP_X_ATT_DEVICEID' => ''
)),
array(array(
'HTTP_UA_CPU' => 'ARM'
))
);
}
/**
* @dataProvider quickHeadersData
* @covers Mobile_Detect::checkHttpHeadersForMobile
*/
public function testQuickHeaders($headers)
{
$md = new Mobile_Detect($headers);
$this->assertTrue($md->checkHttpHeadersForMobile());
}
// Headers that are not mobile.
public function quickNonMobileHeadersData()
{
return array(
array(array(
'HTTP_UA_CPU' => 'AMD64'
)),
array(array(
'HTTP_UA_CPU' => 'X86'
)),
array(array(
'HTTP_ACCEPT' => 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01'
)),
array(array(
'HTTP_REQUEST_METHOD' => 'DELETE'
)),
array(array(
'HTTP_VIA' => '1.1 ws-proxy.stuff.co.il C0A800FA'
)),
);
}
/**
* @dataProvider quickNonMobileHeadersData
* @covers Mobile_Detect::checkHttpHeadersForMobile
*/
public function testNonMobileQuickHeaders($headers)
{
$md = new Mobile_Detect($headers);
$this->assertFalse($md->checkHttpHeadersForMobile());
}
/**
* @expectedException BadMethodCallException
* @coversNothing
*/
public function testBadMethodCall()
{
$md = new Mobile_Detect(array());
$md->badmethodthatdoesntexistatall();
}
public function versionDataProvider()
{
return array(
array(
'Mozilla/5.0 (Linux; Android 4.0.4; ARCHOS 80G9 Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19',
'Android',
'4.0.4',
4.04
),
array(
'Mozilla/5.0 (Linux; Android 4.0.4; ARCHOS 80G9 Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19',
'Webkit',
'535.19',
535.19
),
array(
'Mozilla/5.0 (Linux; Android 4.0.4; ARCHOS 80G9 Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19',
'Chrome',
'18.0.1025.166',
18.01025166
),
array(
'Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; en-US) AppleWebKit/534.8 (KHTML, like Gecko) Version/6.0.0.448 Mobile Safari/534.8',
'BlackBerry',
'6.0.0.448',
6.00448
),
array(
'Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; en-US) AppleWebKit/534.8 (KHTML, like Gecko) Version/6.0.0.448 Mobile Safari/534.8',
'Webkit',
'534.8',
534.8
),
array(
'Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-GB) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.546 Mobile Safari/534.8+',
'BlackBerry',
'6.0.0.546',
6.00546
)
);
}
/**
* @dataProvider versionDataProvider
* @covers Mobile_Detect::version
*/
public function testVersionExtraction($userAgent, $property, $stringVersion, $floatVersion)
{
$md = new Mobile_Detect(array('HTTP_USER_AGENT' => $userAgent));
$prop = $md->version($property);
$this->assertSame($stringVersion, $prop);
$prop = $md->version($property, 'float');
$this->assertSame($floatVersion, $prop);
//assert that garbage data is always === false
$prop = $md->version('garbage input is always garbage');
$this->assertFalse($prop);
}
/**
* @covers Mobile_Detect::getMobileDetectionRules
*/
public function testRules()
{
$md = new Mobile_Detect;
$count = array_sum(array(
count(Mobile_Detect::getPhoneDevices()),
count(Mobile_Detect::getTabletDevices()),
count(Mobile_Detect::getOperatingSystems()),
count(Mobile_Detect::getBrowsers())
));
$rules = $md->getRules();
$this->assertEquals($count, count($rules));
}
/**
* @covers Mobile_Detect::getMobileDetectionRulesExtended
*/
public function testRulesExtended()
{
$md = new Mobile_Detect;
$count = array_sum(array(
count(Mobile_Detect::getPhoneDevices()),
count(Mobile_Detect::getTabletDevices()),
count(Mobile_Detect::getOperatingSystems()),
count(Mobile_Detect::getBrowsers()),
count(Mobile_Detect::getUtilities())
));
$md->setDetectionType(Mobile_Detect::DETECTION_TYPE_EXTENDED);
$rules = $md->getRules();
$this->assertEquals($count, count($rules));
}
/**
* @covers Mobile_Detect::getScriptVersion
*/
public function testScriptVersion()
{
$v = Mobile_Detect::getScriptVersion();
$formatCheck = (bool)preg_match('/^[0-9]+\.[0-9]+\.[0-9](-[a-zA-Z0-9])?$/', $v);
$this->assertTrue($formatCheck, "Fails the semantic version test. The version " . var_export($v, true)
. ' does not match X.Y.Z pattern');
}
public function crazyVersionNumbers()
{
return array(
array('2.5.6', 2.56),
array('12142.2142.412521.24.152', 12142.214241252124152),
array('6_3', 6.3),
array('4_7 /7 7 12_9', 4.777129),
array('49', 49.0),
array('2.6.x', 2.6),
array('45.6.1.x.12', 45.61)
);
}
/**
* @dataProvider crazyVersionNumbers
* @covers Mobile_Detect::prepareVersionNo
*/
public function testPrepareVersionNo($raw, $expected)
{
$md = new Mobile_Detect;
$actual = $md->prepareVersionNo($raw);
$this->assertSame($expected, $actual, "We expected " . var_export($raw, true) . " to convert to "
. var_export($expected, true) . ', but got ' . var_export($actual, true) . ' instead');
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,202 @@
<?php
/**
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* @author Serban Ghita <serbanghita@gmail.com>
* @license MIT License https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt
* @link http://mobiledetect.net
*/
class UserAgentTest extends PHPUnit_Framework_TestCase
{
protected static $ualist = array();
protected static $json;
public static function generateJson()
{
//in case this gets run multiple times
if (isset(self::$json)) {
return self::$json;
}
//the json and PHP formatted files
$jsonFile = dirname(__FILE__) . '/ualist.json';
$phpFile = dirname(__FILE__) . '/UA_List.inc.php';
//check recency of the file
if (file_exists($jsonFile) && is_readable($jsonFile)) {
//read the json file
$json = json_decode(file_get_contents($jsonFile), true);
//check that the hash matches
$hash = isset($json['hash']) ? $json['hash'] : null;
if ($hash == sha1_file($phpFile)) {
//file is up to date, just read the json file
self::$json = $json['user_agents'];
return self::$json;
}
}
//uses the UA_List.inc.php to generate a json file
if (file_exists($jsonFile) && !is_writable($jsonFile)) {
throw new RuntimeException("Need to be able to create/update $jsonFile from UA_List.inc.php.");
}
if (!is_writable(dirname($jsonFile))) {
throw new RuntimeException("Insufficient permissions to create this file: $jsonFile");
}
//currently stored as a PHP array
$list = include $phpFile;
$json = array();
foreach ($list as $vendor => $vendorList) {
foreach ($vendorList as $userAgent => $props) {
if (is_int($userAgent)) {
//this means that the user agent is the props
$userAgent = $props;
$props = array();
}
$tmp = array(
'vendor' => $vendor,
'user_agent' => $userAgent
);
if (isset($props['isMobile'])) {
$tmp['mobile'] = $props['isMobile'];
}
if (isset($props['isTablet'])) {
$tmp['tablet'] = $props['isTablet'];
}
if (isset($props['version'])) {
$tmp['version'] = $props['version'];
}
if (isset($props['model'])) {
$tmp['model'] = $props['model'];
}
$json[] = $tmp;
}
}
//save the hash
$hash = sha1_file($phpFile);
$json = array(
'hash' => $hash,
'user_agents' => $json
);
if (defined('JSON_PRETTY_PRINT')) {
$jsonString = json_encode($json, JSON_PRETTY_PRINT);
} else {
$jsonString = json_encode($json);
}
file_put_contents($jsonFile, $jsonString);
self::$json = $json['user_agents'];
return self::$json;
}
public static function setUpBeforeClass()
{
//generate json file first
self::generateJson();
//get the generated JSON data
$json = self::$json;
//make a list that is usable by functions (THE ORDER OF THE KEYS MATTERS!)
foreach ($json as $userAgent) {
$tmp = array();
$tmp[] = isset($userAgent['user_agent']) ? $userAgent['user_agent'] : null;
$tmp[] = isset($userAgent['mobile']) ? $userAgent['mobile'] : null;
$tmp[] = isset($userAgent['tablet']) ? $userAgent['tablet'] : null;
$tmp[] = isset($userAgent['version']) ? $userAgent['version'] : null;
$tmp[] = isset($userAgent['model']) ? $userAgent['model'] : null;
$tmp[] = isset($userAgent['vendor']) ? $userAgent['vendor'] : null;
self::$ualist[] = $tmp;
}
}
public function userAgentData()
{
if (!count(self::$ualist))
self::setUpBeforeClass();
return self::$ualist;
}
/**
* @medium
* @dataProvider userAgentData
*/
public function testUserAgents($userAgent, $isMobile, $isTablet, $version, $model, $vendor)
{
//make sure we're passed valid data
if (!is_string($userAgent) || !is_bool($isMobile) || !is_bool($isTablet)) {
$this->markTestIncomplete("The User-Agent $userAgent does not have sufficient information for testing.");
return;
}
//setup
$md = new Mobile_Detect;
$md->setUserAgent($userAgent);
//is mobile?
$this->assertEquals($md->isMobile(), $isMobile);
//is tablet?
$this->assertEquals($md->isTablet(), $isTablet);
if (isset($version)) {
foreach ($version as $condition => $assertion) {
$this->assertEquals($assertion, $md->version($condition), 'FAILED UA (version("'.$condition.'")): '.$userAgent);
}
}
//version property tests
if (isset($version)) {
foreach ($version as $property => $stringVersion) {
$v = $md->version($property);
$this->assertSame($stringVersion, $v);
}
}
//@todo: model test, not sure how exactly yet
//@todo: vendor test. The below is theoretical, but fails 50% of the tests...
/*if (isset($vendor)) {
$method = "is$vendor";
$this->assertTrue($md->{$method}(), "Expected Mobile_Detect::{$method}() to be true.");
}*/
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* @author Serban Ghita <serbanghita@gmail.com>
* @license MIT License https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt
* @link http://mobiledetect.net
*/
class VendorsTest extends PHPUnit_Framework_TestCase
{
protected $detect;
protected static $items;
public function setUp()
{
$this->detect = new Mobile_Detect;
}
public static function setUpBeforeClass()
{
//this method could be called multiple times
if (!self::$items) {
self::$items = include dirname(__FILE__).'/UA_List.inc.php';
}
}
public function testisMobileIsTablet()
{
foreach (self::$items as $brand => $deviceArr) {
foreach ($deviceArr as $userAgent => $conditions) {
if (!is_array($conditions)) { continue; }
$this->detect->setUserAgent($userAgent);
foreach ($conditions as $condition => $assert) {
// Currently not supporting version and model here.
// @todo: I need to split this tests!
if ( in_array($condition, array('model') ) ) { continue; } // 'version',
switch ($condition) {
case 'version':
// Android, iOS, Chrome, Build, etc.
foreach ($assert as $assertKey => $assertValue) {
//if ($brand == 'Apple') {
// echo 'UA ('.$condition.'('.$assertKey.') === '.$assertValue.'): '.$userAgent . "\n";
//}
$this->assertTrue( $this->detect->$condition( $assertKey ) == $assertValue, 'UA ('.$condition.'('.$assertKey.') === '.$assertValue.'): '.$userAgent);
}
break;
default:
$this->assertTrue( $this->detect->$condition() === $assert, 'UA ('.$condition.'): '.$userAgent);
break;
}
}
}
}
}
public function testVersion()
{
foreach (self::$items as $brand => $deviceArr) {
foreach ($deviceArr as $userAgent => $conditions) {
if ( !is_array($conditions) || !isset($conditions['version']) ) { continue; }
$this->detect->setUserAgent($userAgent);
foreach ($conditions['version'] as $condition => $assertion) {
$this->assertEquals( $this->detect->version($condition), $assertion, 'UA (version("'.$condition.'")): '.$userAgent );
}
}
}
}
}

View File

@@ -0,0 +1,2 @@
<?php
require_once dirname(__FILE__).'/../Mobile_Detect.php';

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
strict="true"
colors="false"
verbose="false"
bootstrap="bootstrap.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
mapTestClassNameToCoveredClassName="true"
timeoutForSmallTests="2">
<php>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="1G"/>
</php>
<testsuite name="All Mobile Detect tests">
<directory suffix="Test.php">./</directory>
</testsuite>
</phpunit>

File diff suppressed because one or more lines are too long