/**
  * @param array $record
  *
  * @return string
  */
 public function processRecord(array $record)
 {
     $request = $this->requestStack->getCurrentRequest();
     if ($request == null) {
         return $record;
     }
     $uaString = $request->server->get('HTTP_USER_AGENT');
     $browserInfo = $this->browscap->getBrowser($uaString);
     $record['extra']['ua']['browser'] = $browserInfo->Browser;
     $record['extra']['ua']['version'] = $browserInfo->Version;
     $record['extra']['ua']['platform'] = $browserInfo->Platform;
     return $record;
 }
 /**
  * @dataProvider providerUserAgent
  * @depends      testCheckProperties
  *
  * @param string $userAgent
  *
  * @throws \Exception
  * @throws \phpbrowscap\Exception
  */
 public function testCompare($userAgent)
 {
     $libResult = get_browser($userAgent);
     $bcResult = self::$object->getBrowser($userAgent);
     $doNotCheck = array('browser_name_regex', 'browser_name_pattern', 'Parent', 'RenderingEngine_Description');
     foreach (array_keys($this->properties) as $bcProp) {
         if (in_array($bcProp, $doNotCheck)) {
             continue;
         }
         $libProp = strtolower($bcProp);
         $libValue = (string) $libResult->{$libProp};
         $bcValue = (string) $bcResult->{$bcProp};
         self::assertSame($libValue, $bcValue, 'Expected actual "' . $bcProp . '" to be "' . (string) $libValue . '" (was "' . (string) $bcValue . '"; used pattern: ' . (string) $bcResult->browser_name_pattern . ')');
     }
 }
예제 #3
0
파일: Agent.php 프로젝트: fuelphp/agent
 /**
  * Accept a user agent to check, and try to find a match
  *
  * @param string|null $userAgent User agent string to check
  *
  * @return boolean True if the check was succesful, false otherwise
  *
  * @throws \InvalidArgumentException If the method passed to the constuctor is invalid
  */
 public function check($userAgent = null)
 {
     // was a user agent passed? If not, use the server one
     if (empty($userAgent)) {
         $userAgent = $this->server['http_user_agent'];
     }
     // store the user agent
     $this->userAgent = $userAgent;
     // fetch the data
     switch ($this->method) {
         case "browscap":
             // create a browscap object if needed?
             if (!$this->browscap) {
                 if ($this->browscap = new Browscap($this->config['cache_dir'])) {
                     // give the browscap some config
                     if (!empty($this->config['lowercase'])) {
                         $this->browscap->lowercase = true;
                     }
                     if (isset($this->config['browscap'])) {
                         foreach ($this->config['browscap'] as $key => $value) {
                             if (property_exists($this->browscap, $key)) {
                                 $this->browscap->{$key} = $value;
                             }
                         }
                     }
                     $browscap = $this->browscap->getBrowser($this->userAgent, true);
                     $this->properties = array_merge($this->defaults, $browscap);
                 }
             }
             break;
         default:
             throw new \InvalidArgumentException('Invalid detection method "' . $this->method . '", can not load browser information.');
     }
     return true;
 }
예제 #4
0
 /**
  * @dataProvider userAgentDataProvider
  * @coversNothing
  *
  * @param string $userAgent
  * @param array  $expectedProperties
  * @param bool   $lite
  *
  * @group integration
  * @group useragenttest
  * @group lite
  */
 public function testUserAgentsLite($userAgent, $expectedProperties, $lite = true)
 {
     if (!is_array($expectedProperties) || !count($expectedProperties)) {
         self::markTestSkipped('Could not run test - no properties were defined to test');
     }
     if (!$lite) {
         self::markTestSkipped('Test skipped - Browser/Platform/Version not defined for Lite Mode');
     }
     self::$browscap->iniFilename = 'lite_browscap.ini';
     self::$browscap->localFile = self::$buildFolder . '/lite_php_browscap.ini';
     self::$browscap->cacheFilename = 'cache-lite.php';
     self::$browscap->doAutoUpdate = false;
     self::$browscap->silent = false;
     self::$browscap->updateMethod = Browscap::UPDATE_LOCAL;
     static $updatedLiteCache = false;
     if (!$updatedLiteCache) {
         self::$browscap->updateCache();
         $updatedLiteCache = true;
     }
     $actualProps = (array) self::$browscap->getBrowser($userAgent);
     foreach ($expectedProperties as $propName => $propValue) {
         if (!self::$propertyHolder->isOutputProperty($propName)) {
             continue;
         }
         if (!self::$propertyHolder->isLiteModeProperty($propName)) {
             continue;
         }
         self::assertArrayHasKey($propName, $actualProps, 'Actual properties did not have "' . $propName . '" property');
         self::assertSame($propValue, $actualProps[$propName], 'Expected actual "' . $propName . '" to be "' . $propValue . '" (was "' . $actualProps[$propName] . '"; used pattern: ' . $actualProps['browser_name_pattern'] . ')');
     }
 }
예제 #5
0
 /**
  * @param string $ua
  * @param string $mode
  *
  * @return string
  */
 private function testUA($ua, $mode)
 {
     $data = $this->browscap->getBrowser($ua, true);
     if ($mode == GrepCommand::MODE_UNMATCHED && $data['Browser'] == 'Default Browser') {
         $this->logger->info($ua);
         return GrepCommand::MODE_UNMATCHED;
     } elseif ($mode == GrepCommand::MODE_MATCHED && $data['Browser'] != 'Default Browser') {
         $this->logger->info($ua);
         return GrepCommand::MODE_MATCHED;
     }
     return GrepCommand::FOUND_INVISIBLE;
 }
 /**
  * @dataProvider providerUserAgent
  */
 public function testCompare($userAgent)
 {
     $libResult = get_browser($userAgent);
     $bcResult = $this->object->getBrowser($userAgent);
     if ($userAgent == Browscap::BROWSCAP_VERSION_KEY) {
         self::assertSame($libResult->version, $this->object->getSourceVersion(), 'Source file version incorrect: ' . $libResult->version . ' != ' . $this->object->getSourceVersion());
     } else {
         foreach ($this->properties as $bcProp => $libProp) {
             $libValue = $libResult->{$libProp};
             $bcValue = $bcResult->{$bcProp};
             self::assertSame($libValue, $bcValue, $bcProp . ': ' . $libValue . ' != ' . $bcValue);
         }
     }
 }
 protected function checkProperties()
 {
     $lib_properties = get_object_vars(get_browser('x'));
     $bc_properties = get_object_vars($this->browscap->getBrowser('x'));
     foreach (array_keys($bc_properties) as $bc_prop) {
         if ('browser_name' == $bc_prop) {
             continue;
         }
         if (!isset($lib_properties[strtolower($bc_prop)])) {
             throw new Exception("Property `{$bc_prop}` from Browscap doesn't match anything in get_browser.");
         }
         if ('browser_name_regex' != $bc_prop) {
             $this->properties[$bc_prop] = strtolower($bc_prop);
         }
         unset($lib_properties[strtolower($bc_prop)]);
     }
     unset($lib_properties['renderingengine_description']);
     if (!empty($lib_properties)) {
         throw new Exception('There are ' . count($lib_properties) . '(' . implode(', ', array_keys($lib_properties)) . ') properties in get_browser that do not match those in Browscap.');
     }
 }
예제 #8
0
 public function __construct()
 {
     global $wp_version, $WP_Statistics;
     // Call the parent constructor (WP_Statistics::__construct)
     parent::__construct();
     // Set the timestamp value.
     $this->timestamp = $this->current_date('U');
     // Set the default seconds a user needs to visit the site before they are considered offline.
     $this->second = 30;
     // Get the user set value for seconds to check for users online.
     if ($this->get_option('check_online')) {
         $this->second = $this->get_option('check_online');
     }
     // Check to see if the user wants us to record why we're excluding hits.
     if ($this->get_option('record_exclusions')) {
         $this->exclusion_record = TRUE;
     }
     // Let's check to see if our subnet matches a private IP address range, if so go ahead and set the location infomraiton now.
     if ($this->get_option('private_country_code') != '000' && $this->get_option('private_country_code') != '') {
         $private_subnets = array('10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', '127.0.0.1/24');
         foreach ($private_subnets as $psub) {
             if ($this->net_match($psub, $this->ip)) {
                 $this->location = $this->get_option('private_country_code');
                 break;
             }
         }
     }
     // The follow exclusion checks are done during the class construction so we don't have to execute them twice if we're tracking visits and visitors.
     //
     // Order of exclusion checks is:
     //		1 - Robots
     // 		2 - IP/Subnets
     //		3 - Self Referrals, Referrer Spam & login page
     //		4 - User roles
     //		5 - Host name list
     //
     // The GoeIP exclusions will be processed in the GeoIP hits class constructor.
     //
     // Get the upload directory from WordPRess.
     $upload_dir = wp_upload_dir();
     // Create a variable with the name of the database file to download.
     $BrowscapFile = $upload_dir['basedir'] . '/wp-statistics';
     $crawler = false;
     $ua_string = "";
     if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
         $ua_string = $_SERVER['HTTP_USER_AGENT'];
     }
     if ($this->get_option('last_browscap_dl') > 1 && $this->get_option('browscap')) {
         // Get the Browser Capabilities use Browscap.
         $bc = new Browscap($BrowscapFile);
         $bc->doAutoUpdate = false;
         // We don't want to auto update.
         try {
             $current_browser = $bc->getBrowser();
             // Make sure we got an object back and it has the Crawler property before accessing it.
             if (is_object($current_browser) && property_exists($current_browser, 'Crawler')) {
                 $crawler = $current_browser->Crawler;
             } else {
                 $crawler = false;
             }
         } catch (Exception $e) {
             $crawler = false;
         }
     } else {
         $this->update_option('update_browscap', true);
     }
     // If we're a crawler as per browscap, exclude us, otherwise double check based on the WP Statistics robot list.
     if ($crawler == true) {
         $this->exclusion_match = TRUE;
         $this->exclusion_reason = "browscap";
     } else {
         // Pull the robots from the database.
         $robots = explode("\n", $this->get_option('robotlist'));
         // Check to see if we match any of the robots.
         foreach ($robots as $robot) {
             $robot = trim($robot);
             // If the match case is less than 4 characters long, it might match too much so don't execute it.
             if (strlen($robot) > 3) {
                 if (stripos($ua_string, $robot) !== FALSE) {
                     $this->exclusion_match = TRUE;
                     $this->exclusion_reason = "robot";
                     break;
                 }
             }
         }
         // Finally check to see if we have corrupt header information.
         if (!$this->exclusion_match && $this->get_option('corrupt_browser_info')) {
             if ($ua_string == '' || $this->ip == '') {
                 $this->exclusion_match = TRUE;
                 $this->exclusion_reason = "robot";
             }
         }
     }
     // If we didn't match a robot, check ip subnets.
     if (!$this->exclusion_match) {
         // Pull the subnets from the database.
         $subnets = explode("\n", $this->get_option('exclude_ip'));
         // Check to see if we match any of the excluded addresses.
         foreach ($subnets as $subnet) {
             $subnet = trim($subnet);
             // The shortest ip address is 1.1.1.1, anything less must be a malformed entry.
             if (strlen($subnet) > 6) {
                 if ($this->net_match($subnet, $this->ip)) {
                     $this->exclusion_match = TRUE;
                     $this->exclusion_reason = "ip match";
                     break;
                 }
             }
         }
         // Check to see if we are being referred to ourselves.
         if (!$this->exclusion_match) {
             if ($ua_string == "WordPress/" . $wp_version . "; " . get_home_url(null, "/")) {
                 $this->exclusion_match = TRUE;
                 $this->exclusion_reason = "self referral";
             }
             if ($ua_string == "WordPress/" . $wp_version . "; " . get_home_url()) {
                 $this->exclusion_match = TRUE;
                 $this->exclusion_reason = "self referral";
             }
             if ($this->get_option('exclude_loginpage')) {
                 $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']), 'https') === FALSE ? 'http' : 'https';
                 $host = $_SERVER['HTTP_HOST'];
                 $script = $_SERVER['SCRIPT_NAME'];
                 $currentURL = $protocol . '://' . $host . $script;
                 $loginURL = wp_login_url();
                 if ($currentURL == $loginURL) {
                     $this->exclusion_match = TRUE;
                     $this->exclusion_reason = "login page";
                 }
             }
             if ($this->get_option('exclude_adminpage') && !$this->exclusion_match) {
                 $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']), 'https') === FALSE ? 'http' : 'https';
                 $host = $_SERVER['HTTP_HOST'];
                 $script = $_SERVER['SCRIPT_NAME'];
                 $currentURL = $protocol . '://' . $host . $script;
                 $adminURL = get_admin_url();
                 $currentURL = substr($currentURL, 0, strlen($adminURL));
                 if ($currentURL == $adminURL) {
                     $this->exclusion_match = TRUE;
                     $this->exclusion_reason = "admin page";
                 }
             }
             if ($this->get_option('referrerspam') && !$this->exclusion_match) {
                 $referrer = $this->get_Referred();
                 // Pull the referrer spam list from the database.
                 $referrerspamlist = explode("\n", $this->get_option('referrerspamlist'));
                 // Check to see if we match any of the robots.
                 foreach ($referrerspamlist as $item) {
                     $item = trim($item);
                     // If the match case is less than 4 characters long, it might match too much so don't execute it.
                     if (strlen($item) > 3) {
                         if (stripos($referrer, $item) !== FALSE) {
                             $this->exclusion_match = TRUE;
                             $this->exclusion_reason = "referrer_spam";
                             break;
                         }
                     }
                 }
             }
             if ($this->get_option('exclude_feeds') && !$this->exclusion_match) {
                 if (is_object($WP_Statistics)) {
                     if ($WP_Statistics->check_feed()) {
                         $this->exclusion_match = TRUE;
                         $this->exclusion_reason = "feed";
                     }
                 }
             }
             if ($this->get_option('exclude_404s') && !$this->exclusion_match) {
                 if (is_404()) {
                     $this->exclusion_match = TRUE;
                     $this->exclusion_reason = "404";
                 }
             }
             if ($this->get_option('excluded_urls') && !$this->exclusion_match) {
                 $script = $_SERVER['REQUEST_URI'];
                 $delimiter = strpos($script, '?');
                 if ($delimiter > 0) {
                     $script = substr($script, 0, $delimiter);
                 }
                 $excluded_urls = explode("\n", $this->get_option('excluded_urls'));
                 foreach ($excluded_urls as $url) {
                     $this_url = trim($url);
                     if (strlen($this_url) > 2) {
                         if (stripos($script, $this_url) === 0) {
                             $this->exclusion_match = TRUE;
                             $this->exclusion_reason = "excluded url";
                             break;
                         }
                     }
                 }
             }
             // Check to see if we are excluding based on the user role.
             if (!$this->exclusion_match) {
                 if (is_user_logged_in()) {
                     $current_user = wp_get_current_user();
                     foreach ($current_user->roles as $role) {
                         $option_name = 'exclude_' . str_replace(" ", "_", strtolower($role));
                         if ($this->get_option($option_name) == TRUE) {
                             $this->exclusion_match = TRUE;
                             $this->exclusion_reason = "user role";
                             break;
                         }
                     }
                 }
                 // Check to see if we are excluded by the host name.
                 if (!$this->exclusion_match) {
                     $excluded_host = explode("\n", $this->get_option('excluded_hosts'));
                     // If there's nothing in the excluded host list, don't do anything.
                     if (count($excluded_host) > 0) {
                         $transient_name = 'wps_excluded_hostname_to_ip_cache';
                         // Get the transient with the hostname cache.
                         $hostname_cache = get_transient($transient_name);
                         // If the transient has expired (or has never been set), create one now.
                         if ($hostname_cache === false) {
                             // Flush the failed cache variable.
                             $hostname_cache = array();
                             // Loop through the list of hosts and look them up.
                             foreach ($excluded_host as $host) {
                                 if (strpos($host, '.') > 0) {
                                     // We add the extra period to the end of the host name to make sure we don't append the local dns suffix to the resolution cycle.
                                     $hostname_cache[$host] = gethostbyname($host . ".");
                                 }
                             }
                             // Set the transient and store it for 1 hour.
                             set_transient($transient_name, $hostname_cache, 360);
                         }
                         // Check if the current IP address matches one of the ones in the excluded hosts list.
                         if (in_array($this->ip, $hostname_cache)) {
                             $this->exclusion_match = TRUE;
                             $this->exclusion_reason = "hostname";
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $bc = new Browscap($this->container->getParameter('kernel.cache_dir'));
     $event->getRequest()->attributes->set('_browser', $bc->getBrowser());
 }
예제 #10
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
use phpbrowscap\Browscap;
use phpcaniuse\CanIUse;
$bc = new Browscap('/tmp');
$browser = $bc->getBrowser();
$can = new phpcaniuse\CanIUse($browser, file_get_contents("../data.json"));
echo "supported:" . $can->check(array('fontface', 'video')) . "<br>";
echo "browser<br><textarea rows=25 cols=80>" . var_export($browser, true) . "</textarea>";
echo "<br>getInfo<br><textarea rows=10 cols=80>" . var_export($can->getInfo(), true) . "</textarea><br>";
echo "<br>browserCan<br><textarea rows=25 cols=80>" . var_export($can->browserCan(), true) . "</textarea><br>";
echo "<br>featureList<br><textarea rows=25 cols=80>" . var_export($can->featureList(), true) . "</textarea><br>";
echo "<br>raw data<br><textarea rows=25 cols=80>" . var_export($can->dataGet(), true) . "</textarea>";
echo "\n<br>fin<br>\n";
	function wp_statistics_download_browscap() {

		GLOBAL $WP_Statistics;

		// We need the download_url() function, it should exists on virtually all installs of PHP, but if it doesn't for some reason, bail out.
		if( !function_exists( 'download_url' ) ) { return ''; }

		// If browscap is disabled, bail out.
		if( $WP_Statistics->get_option('browscap') == false ) { return '';}

		// This is the location of the file to download.
		$download_url = 'http://browscap.org/stream?q=Full_PHP_BrowsCapINI';
		$download_version = 'http://browscap.org/version-number';

		// Get the upload directory from WordPress.
		$upload_dir = wp_upload_dir();

		// Check to see if the subdirectory we're going to upload to exists, if not create it.
		if( !file_exists($upload_dir['basedir'] . '/wp-statistics') ) { mkdir($upload_dir['basedir'] . '/wp-statistics'); }

		$LocalVersion = 0;

		// Get the Browscap object, tell it NOT to autoupdate.
		$bc = new Browscap($upload_dir['basedir'] . '/wp-statistics');
		$bc->doAutoUpdate = false; 	// We don't want to auto update.

		// If we already have a browscap.ini file (aka we're already done a download in the past) we can get it's version number.
		// We can't execute this code if no browscap.ini exists as then the library will automatically download a full version, even
		// though we've told it not to autoupdate above.
		if( $WP_Statistics->get_option('last_browscap_dl') > 1 ) {
			// Get the current browser so that the version information is populated.
			try {
				$bc->getBrowser();
				$LocalVersion = $bc->getSourceVersion();
			}
			catch( Exception $e ) {
				$crawler = false;
				$LocalVersion = 0;
			}

		}

		// Get the remote version info from browscap.org.
		$TempVersionFile = download_url( $download_version );

		// Read the version we just downloaded in to a string.
		$RemoteVersion = file_get_contents($TempVersionFile);

		// Get rid of the temporary file.
		unlink( $TempVersionFile );

		// If there is a new version, let's go get it.
		if( intval($RemoteVersion) >  $LocalVersion ) {

			// Download the file from browscap.org, this places it in a temporary location.
			$TempFile = download_url( $download_url );

			// If we failed, through a message, otherwise proceed.
			if (is_wp_error( $TempFile ) ) {
				$result = "<div class='updated settings-error'><p><strong>" . sprintf(__('Error downloading browscap database from: %s - %s', 'wp_statistics'), $download_url, $TempFile->get_error_message() ) . "</strong></p></div>";
			}
			else {
				// Keep the current version just in case by renaming it.
				if( file_exists( $upload_dir['basedir'] . '/wp-statistics/browscap.old' ) ) { unlink( $upload_dir['basedir'] . '/wp-statistics/browscap.old' ); }
				if( file_exists( $upload_dir['basedir'] . '/wp-statistics/cache.old' ) ) { unlink( $upload_dir['basedir'] . '/wp-statistics/cache.old' ); }
				if( file_exists( $upload_dir['basedir'] . '/wp-statistics/browscap.ini' ) ) { rename( $upload_dir['basedir'] . '/wp-statistics/browscap.ini', $upload_dir['basedir'] . '/wp-statistics/browscap.old' ); }
				if( file_exists( $upload_dir['basedir'] . '/wp-statistics/cache.php' ) ) { rename( $upload_dir['basedir'] . '/wp-statistics/cache.php', $upload_dir['basedir'] . '/wp-statistics/cache.old' ); }

				// Setup our file handles.
				$infile = fopen($TempFile, 'r' );
				$outfile = fopen($upload_dir['basedir'] . '/wp-statistics/browscap.ini', 'w');

				// We're going to need some variables to use as we process the new browscap.ini.
				// $crawler has three possible settings:
				// 		0 = no setting found
				//		1 = setting found but not a crawler
				// 		2 = setting found and a crawler
				$parent = '';
				$title = '';
				$crawler = 0;
				$parents = array( '' => false );

				// Now read in the browscap.ini file we downloaded one line at a time.
				while( ( $buffer = fgets($infile) ) !== false)
					{
					// Let's get rid of the tailing carriage return extra spaces.
					$buffer = trim($buffer);

					// We're going to do some things based on the first charater on the line so let's just get it once.
					$firstchar = substr( $buffer, 0, 1 );

					// The first character will tell us what kind of line we're dealing with.
					switch( $firstchar )
						{
						// A square bracket means it's a section title.
						case '[':

							// We have three sections we need to copy verbatium so don't do the standard processing for them.
							if( $title != 'GJK_Browscap_Version' && $title != 'DefaultProperties' && $title != '*' && $title != '')
								{
								// Write out the section if:
								//     the current section is a crawler and there is no parent
								//  OR
								//     the current section is a crawler, has a parent and the parent is a crawler as well (Note, this will drop some crawlers who's parent's aren't because we haven't written out all the parent's that aren't crawlers this could cause mis-identificaton of some users as crawlers).
								//  OR
								//     the current section isn't a crawler but the parent is
								//
								if( ( $crawler == 2 && $parent == '' ) ||
								    ( $crawler == 2 && $parent != '' && array_key_exists( $parent, $parents ) ) ||
									( $crawler == 0 && array_key_exists( $parent, $parents ) ) )
									{
									// Write out the section with just the parent/crawler setting saved.
									fwrite( $outfile, "[" . $title . "]\n" );
									fwrite( $outfile, "Crawler=\"true\"\n" );
									}
								}

							// Reset our variables.
							$crawler = 0;
							$parent = '';
							$title = substr( $buffer, 1, strlen($buffer) - 2 );

							// We have three sections we need to copy verbatium so write out their headings immediatly instead of waiting to see if they are a crawler.
							if( $title == 'GJK_Browscap_Version' || $title == 'DefaultProperties' || $title == "*" ) { fwrite($outfile,"[" . $title . "]\n"); }

							break;
						// A space or semi-colan means it's a comment.
						case ' ':
						case ';':
							// Since we're hacking out lots of data the only comments we want to keep are the first few in the file before the first section is processed.
							if( $title == '' ) { fwrite( $outfile, $buffer . "\n" ); }

							break;
						// Otherwise its a real setting line.
						default:
							// If the setting is for the crawler let's inidicate we found it and it's true.  We can also set the parents array.
							if( $buffer == 'Crawler="true"' ) { $crawler = 2; $parents[$title] = true;}

							// If the setting for the parent then set it now.
							if( substr( $buffer, 0, 7 ) == 'Parent=' ) { $parent = substr( $buffer, 8, -1 ); }

							// We have three sections we need to copy verbatium so write out their settings.
							if( $title == 'GJK_Browscap_Version' || $title == 'DefaultProperties' || $title == "*" ) { fwrite( $outfile, $buffer . "\n" ); }
						}
					}

				// Close the files.
				fclose( $outfile );
				fclose( $infile );

				// Delete the temporary file.
				unlink( $TempFile );

				// Check to see if an old (more than a minute old) lock file exists, if so delete it.
				$cache_lock = $upload_dir['basedir'] . '/wp-statistics/cache.lock';
				if( file_exists( $cache_lock ) ) {
					if( time() - filemtime( $cache_lock ) > 60 ) {
						unlink( $cache_lock );
					}
				}

				// Force the cache to be updated.
				$bc->updateCache();

				// Update the options to reflect the new download.
				$WP_Statistics->update_option('last_browscap_dl', time());
				$WP_Statistics->update_option('update_browscap', false);

				$result = "<div class='updated settings-error'><p><strong>" . __('browscap database updated successfully!', 'wp_statistics') . "</strong></p></div>";

				// Do some sanity checks on the new ini/cache file
				$ini_fs = filesize( $upload_dir['basedir'] . '/wp-statistics/browscap.ini' );
				$cache_fs = filesize( $upload_dir['basedir'] . '/wp-statistics/cache.php' );
				$fail = false;

				// Check to make sure the cache file isn't any more than 15% larger than then ini file
				if( $cache_fs - $ini_fs > $ini_fs * 0.15 ) {
					$fail = true;
					$result = "<div class='updated settings-error'><p><strong>" . __('browscap database updated failed!  Cache file too large, reverting to previous browscap.ini.', 'wp_statistics') . "</strong></p></div>";
				} else {
					// Check to make sure we don't resolve a typical user agent as a robot.
					$test_browser = $bc->getBrowser("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0");
					$crawler = $test_browser->Crawler;

					if( $crawler == true ) {
						$fail = true;
						$result = "<div class='updated settings-error'><p><strong>" . __('browscap database updated failed!  New browscap.ini is mis-identifing user agents as crawlers, reverting to previous browscap.ini.', 'wp_statistics') . "</strong></p></div>";
					}
				}

				// If we failed, roll back the update, otherwise just delete the old files.
				if( $fail == true ) {
					if( file_exists( $upload_dir['basedir'] . '/wp-statistics/browscap.ini' ) ) { unlink( $upload_dir['basedir'] . '/wp-statistics/browscap.ini' ); }
					if( file_exists( $upload_dir['basedir'] . '/wp-statistics/cache.php' ) ) { unlink( $upload_dir['basedir'] . '/wp-statistics/cache.php' ); }
					if( file_exists( $upload_dir['basedir'] . '/wp-statistics/browscap.old' ) ) { rename( $upload_dir['basedir'] . '/wp-statistics/browscap.old', $upload_dir['basedir'] . '/wp-statistics/browscap.ini' ); }
					if( file_exists( $upload_dir['basedir'] . '/wp-statistics/cache.old' ) ) { rename( $upload_dir['basedir'] . '/wp-statistics/cache.old', $upload_dir['basedir'] . '/wp-statistics/cache.php' ); }
				}
				else {
					if( file_exists( $upload_dir['basedir'] . '/wp-statistics/browscap.old' ) ) { unlink( $upload_dir['basedir'] . '/wp-statistics/browscap.old' ); }
					if( file_exists( $upload_dir['basedir'] . '/wp-statistics/cache.old' ) ) { unlink( $upload_dir['basedir'] . '/wp-statistics/cache.old' ); }
				}
			}
		}
		else {
			// Update the options to reflect the new download.
			$WP_Statistics->update_option('last_browscap_dl', time());
			$WP_Statistics->update_option('update_browscap', false);

			$result = "<div class='updated settings-error'><p><strong>" . __('browscap already at current version!', 'wp_statistics') . "</strong></p></div>";
		}

		if( $WP_Statistics->get_option('browscap_report') == true ) {
			$blogname = get_bloginfo('name');
			$blogemail = get_bloginfo('admin_email');

			$headers[] = "From: $blogname <$blogemail>";
			$headers[] = "MIME-Version: 1.0";
			$headers[] = "Content-type: text/html; charset=utf-8";

			if( $WP_Statistics->get_option('email_list') == '' ) { $WP_Statistics->update_option( 'email_list', $blogemail ); }

			wp_mail( $WP_Statistics->get_option('email_list'), __('Browscap.ini update on', 'wp_statistics') . ' ' . $blogname, $result, $headers );
		}

		// All of the messages displayed above are stored in a stirng, now it's time to actually output the messages.
		return $result;
	}
예제 #12
0
파일: u2f.php 프로젝트: paul999/phpbb_2fa
 /**
  * Check if the user can potentially use this.
  * This method is called at registration page.
  *
  * You can, for example, check if the current browser is suitable.
  *
  * @param int|boolean $user_id Use false to ignore user
  * @return bool
  */
 public function is_potentially_usable($user_id = false)
 {
     $browsercap = new Browscap($this->root_path . 'cache/');
     $info = $browsercap->getBrowser($this->request->server('HTTP_USER_AGENT'));
     return strtolower($info->Browser) === 'chrome' && $this->is_ssl();
 }
예제 #13
0
 /**
  * Returns the platform and version (e.g. OsX 10.10) for
  * the given useragent
  * @param $strUseragent
  *
  * @return mixed
  * @throws Exception
  * @throws \phpbrowscap\Exception
  */
 public function getPlatformForUseragent($strUseragent)
 {
     $objInfo = $this->objBrowscap->getBrowser($strUseragent);
     return $objInfo->Platform . " " . $objInfo->Platform_Version;
 }