Version 4.2.0
This commit is contained in:
1 parent
0dc2aee5ed
commit
96997ddd8e
2074 files changed
+125454
-55780
No files matched your search
+39
-123
@@ -1,12 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief User-Agent Management Class
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 20 Aug 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Http;
|
||||
@@ -26,28 +25,33 @@ class _Useragent
|
||||
/**
|
||||
* @brief Search engine spider?
|
||||
*/
|
||||
public $spider = FALSE;
|
||||
public $spider = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Mobile or tablet device?
|
||||
*/
|
||||
public $mobile = FALSE;
|
||||
public $mobile = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Browser or user agent key
|
||||
* @brief Browser name
|
||||
*/
|
||||
public $useragentKey = NULL;
|
||||
public $browser = NULL;
|
||||
|
||||
/**
|
||||
* @brief Browser version
|
||||
*/
|
||||
public $useragentVersion = NULL;
|
||||
|
||||
public $browserVersion = NULL;
|
||||
|
||||
/**
|
||||
* @brief Platform Name
|
||||
*/
|
||||
public $platform = NULL;
|
||||
|
||||
/**
|
||||
* @brief Full user agent string
|
||||
*/
|
||||
public $useragent = NULL;
|
||||
|
||||
public $useragent = NULL;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -56,9 +60,9 @@ class _Useragent
|
||||
*/
|
||||
protected function __construct( $userAgent )
|
||||
{
|
||||
$this->useragent = $userAgent;
|
||||
$this->useragent = $userAgent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -75,23 +79,6 @@ class _Useragent
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Human-Readable Browser Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->language()->checkKeyExists( 'useragent-' . $this->useragentKey ) )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->get( 'useragent-' . $this->useragentKey ) . ( $this->useragentVersion ? " {$this->useragentVersion}" : '' );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->useragentKey;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the user agent data
|
||||
*
|
||||
@@ -99,8 +86,15 @@ class _Useragent
|
||||
*/
|
||||
public function parseUserAgent()
|
||||
{
|
||||
/* Set basic data */
|
||||
require_once( \IPS\ROOT_PATH . '/system/3rd_party/PhpUserAgent/UserAgentParser.php' );
|
||||
$data = parse_user_agent( $this->useragent );
|
||||
$this->platform = $data['platform'];
|
||||
$this->browser = $data['browser'];
|
||||
$this->browserVersion = $data['version'];
|
||||
|
||||
/* Is this a spider? */
|
||||
foreach( array_merge( $this->searchEngineUseragents, $this->mobileEngineUseragents, $this->standardEngineUseragents ) as $key => $regex )
|
||||
foreach( $this->searchEngineUseragents as $key => $regex )
|
||||
{
|
||||
if( is_array( $regex ) )
|
||||
{
|
||||
@@ -108,13 +102,7 @@ class _Useragent
|
||||
{
|
||||
if( preg_match( "#" . $_expression . "#im", $this->useragent, $matches ) )
|
||||
{
|
||||
$this->useragentKey = $key;
|
||||
|
||||
if( isset( $matches[1] ) AND !empty( $matches[1] ) )
|
||||
{
|
||||
$this->useragentVersion = $matches[1];
|
||||
}
|
||||
|
||||
$this->spider = $key;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
@@ -123,36 +111,13 @@ class _Useragent
|
||||
{
|
||||
if( preg_match( "#" . $regex . "#im", $this->useragent, $matches ) )
|
||||
{
|
||||
$this->useragentKey = $key;
|
||||
|
||||
if( isset( $matches[1] ) AND !empty( $matches[1] ) )
|
||||
{
|
||||
$this->useragentVersion = $matches[1];
|
||||
}
|
||||
|
||||
$this->spider = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set mobile/spider flag as appropriate */
|
||||
if( $this->useragentKey )
|
||||
{
|
||||
if( array_key_exists( $this->useragentKey, $this->searchEngineUseragents ) )
|
||||
{
|
||||
$this->spider = TRUE;
|
||||
}
|
||||
else if( array_key_exists( $this->useragentKey, $this->mobileEngineUseragents ) )
|
||||
{
|
||||
$this->mobile = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->useragentKey = 'unknown';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief List of search engine user agent strings with regex to parse out the data.
|
||||
* @note Matches will be checked based on the order of this list - put more specific matches first and more generic matches later
|
||||
@@ -187,66 +152,17 @@ class _Useragent
|
||||
'yahoo' => "Yahoo(?:.*?)(?:Slurp|FeedSeeker)",
|
||||
'yandex' => "Yandex(?:[^\/]+?)\/([0-9.]{1,10})",
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* @brief List of mobile device user agent strings with regex to parse out the data.
|
||||
* @note Matches will be checked based on the order of this list - put more specific matches first and more generic matches later
|
||||
* @note If you wish to capture a version, be sure to have just ONE capturing parenthesis group (i.e. $matches[1])
|
||||
* @note You may put multiple regex definitions for a single key into an array
|
||||
* @note If the UA matches an entry in this array, $this->mobile will be set to TRUE
|
||||
* Human-Readable Browser Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected $mobileEngineUseragents = array(
|
||||
'transformer' => ";\s+?Transformer\s+?",
|
||||
'android' => "\sandroid\s+?([A-Za-z0-9.]{1,10}).+?mobile",
|
||||
'firefoxmobile' => "Mozilla(?:[^\(]+?)\((?:android|tablet)",
|
||||
'androidtablet' => "\sandroid\s+?([A-Za-z0-9.]{1,10})",
|
||||
'blackberry' => "blackberry\s?(\d+?)[\/;]",
|
||||
'iphone' => "iphone;",
|
||||
'ipodtouch' => "ipod;",
|
||||
'iPad' => "iPad;",
|
||||
'sonyericsson' => "^SonyEricsson[A-Za-z0-9]",
|
||||
'nokia' => "Nokia[A-Za-z0-9]",
|
||||
'motorola' => "^mot-[A-Za-z0-9]",
|
||||
'samsung' => "^samsung-[A-Za-z0-9]",
|
||||
'siemens' => "^sie-[A-Za-z0-9]",
|
||||
'htc' => "(?:htc-|htc_)([A-Za-z0-9.]{1,10})",
|
||||
'lg' => "^(?:lg|lge)-[A-Za-z0-9]",
|
||||
'palm' => "(?:palmsource/| pre/[0-9.]{1,10}|palm webos)",
|
||||
'operamini' => "opera (?:mobi|mini)",
|
||||
'windows7' => "Windows Phone OS ([^;]+);",
|
||||
'windows8' => "Windows Phone ([^;]+);",
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief List of other user agent strings (desktop browsers) with regex to parse out the data.
|
||||
* @note Matches will be checked based on the order of this list - put more specific matches first and more generic matches later
|
||||
* @note If you wish to capture a version, be sure to have just ONE capturing parenthesis group (i.e. $matches[1])
|
||||
* @note You may put multiple regex definitions for a single key into an array
|
||||
*/
|
||||
protected $standardEngineUseragents = array(
|
||||
'edge' => "edge/([0-9.]{1,10})",
|
||||
'amaya' => "amaya/([0-9.]{1,10})",
|
||||
'aol' => "aol[ /\-]([0-9.]{1,10})",
|
||||
'camino' => "camino/([0-9.+]{1,10})",
|
||||
'chimera' => "chimera/([0-9.+]{1,10})",
|
||||
'chrome' => "Chrome/([0-9.]{1,10})",
|
||||
'curl' => "curl[ /]([0-9.]{1,10})",
|
||||
'firebird' => "Firebird/([0-9.+]{1,10})",
|
||||
'firefox' => "Firefox/([0-9.+]{1,10})",
|
||||
'lotus' => "Lotus[ \-]?Notes[ /]([0-9.]{1,10})",
|
||||
'konqueror' => "konqueror/([0-9.]{1,10})",
|
||||
'lynx' => "lynx/([0-9a-z.]{1,10})",
|
||||
'maxthon' => " Maxthon[\);]",
|
||||
'omniweb' => "omniweb/[ a-z]?([0-9.]{1,10})$",
|
||||
'opera' => "opera[ /]([0-9.]{1,10})",
|
||||
'safari' => "version/([0-9.]{1,10})\s+?safari/([0-9.]{1,10})",
|
||||
'webtv' => "webtv[ /]([0-9.]{1,10})",
|
||||
'netscape' => "^mozilla/([0-4]\.[0-9.]{1,10})",
|
||||
'mozilla' => "^mozilla/([5-9]\.[0-9a-z.]{1,10})",
|
||||
'xbox' => "\(compatible; MSIE[ /]([0-9.]{1,10})(.*)Xbox",
|
||||
'explorer' => "\(compatible; MSIE[ /]([0-9.]{1,10})",
|
||||
);
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'user_agent_parsed', FALSE, array( 'sprintf' => array( $this->browser, $this->browserVersion, $this->platform ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief List of Facebook IP addresses
|
||||
* @see <a href='https://developers.facebook.com/docs/ApplicationSecurity/#facebook_scraper'>Facebook application security</a>
|
||||
|
||||
Reference in new issue
Block a user