<commit_before><?php

/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines http://www.simplemachines.org
 * @copyright 2019 Simple Machines and individual contributors
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.1 RC2
 */

if (!defined('SMF'))
	die('No direct access...');

/**
 * Class browser_detector
 *  This class is an experiment for the job of correctly detecting browsers and settings needed for them.
 * - Detects the following browsers
 * - Opera, Webkit, Firefox, Web_tv, Konqueror, IE, Gecko
 * - Webkit variants: Chrome, iphone, blackberry, android, safari, ipad, ipod
 * - Opera Versions: 6, 7, 8 ... 10 ... and mobile mini and mobi
 * - Firefox Versions: 1, 2, 3 .... 11 ...
 * - Chrome Versions: 1 ... 18 ...
 * - IE Versions: 4, 5, 5.5, 6, 7, 8, 9, 10 ... mobile and Mac
 * - MS Edge
 * - Nokia
 */
class browser_detector
{
	/**
	 * @var array Holds all the browser information. Its contents will be placed into $context['browser']
	 */
	private $_browsers = null;

	/**
	 * @var boolean Whether or not this might be a mobile device
	 */
	private $_is_mobile = null;

	/**
	 * The main method of this class, you know the one that does the job: detect the thing.
	 *  - determines the user agent (browser) as best it can.
	 */
	function detectBrowser()
	{
		global $context, $user_info;

		// Init
		$this->_browsers = array();
		$this->_is_mobile = false;

		// Initialize some values we'll set differently if necessary...
		$this->_browsers['needs_size_fix'] = false;

		// One at a time, one at a time, and in this order too
		if ($this->isOpera())
			$this->setupOpera();
		// Meh...
		elseif ($this->isEdge())
			$this->setupEdge();
		// Them webkits need to be set up too
		elseif ($this->isWebkit())
			$this->setupWebkit();
		// We may have work to do on Firefox...
		elseif ($this->isFirefox())
			$this->setupFirefox();
		// Old friend, old frenemy
		elseif ($this->isIe())
			$this->setupIe();

		// Just a few mobile checks
		$this->isOperaMini();
		$this->isOperaMobi();

		// IE11 seems to be fine by itself without being lumped into the "is_ie" category
		$this->isIe11();

		// Be you robot or human?
		if ($user_info['possibly_robot'])
		{
			// This isn't meant to be reliable, it's just meant to catch most bots to prevent PHPSESSID from showing up.
			$this->_browsers['possibly_robot'] = !empty($user_info['possibly_robot']);

			// Robots shouldn't be logging in or registering.  So, they aren't a bot.  Better to be wrong than sorry (or people won't be able to log in!), anyway.
			if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register', 'signup'))) || !$user_info['is_guest'])
				$this->_browsers['possibly_robot'] = false;
		}
		else
			$this->_browsers['possibly_robot'] = false;

		// Fill out the historical array as needed to support old mods that don't use isBrowser
		$this->fillInformation();

		// Last step ...
		$this->setupBrowserPriority();

		// Now see what you've done!
		$context['browser'] = $this->_browsers;
	}

	/**
	 * Determine if the browser is Opera or not
	 *
	 * @return boolean Whether or not this is Opera
	 */
	function isOpera()
	{
		if (!isset($this->_browsers['is_opera']))
			$this->_browsers['is_opera'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false;
		return $this->_browsers['is_opera'];
	}
<commit_msg>Adds $context['browser']['is_mobile'] so isBrowser('mobile') will work<commit_after><?php

/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines http://www.simplemachines.org
 * @copyright 2019 Simple Machines and individual contributors
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.1 RC2
 */

if (!defined('SMF'))
	die('No direct access...');

/**
 * Class browser_detector
 *  This class is an experiment for the job of correctly detecting browsers and settings needed for them.
 * - Detects the following browsers
 * - Opera, Webkit, Firefox, Web_tv, Konqueror, IE, Gecko
 * - Webkit variants: Chrome, iphone, blackberry, android, safari, ipad, ipod
 * - Opera Versions: 6, 7, 8 ... 10 ... and mobile mini and mobi
 * - Firefox Versions: 1, 2, 3 .... 11 ...
 * - Chrome Versions: 1 ... 18 ...
 * - IE Versions: 4, 5, 5.5, 6, 7, 8, 9, 10 ... mobile and Mac
 * - MS Edge
 * - Nokia
 */
class browser_detector
{
	/**
	 * @var array Holds all the browser information. Its contents will be placed into $context['browser']
	 */
	private $_browsers = null;

	/**
	 * @var boolean Whether or not this might be a mobile device
	 */
	private $_is_mobile = null;

	/**
	 * The main method of this class, you know the one that does the job: detect the thing.
	 *  - determines the user agent (browser) as best it can.
	 */
	function detectBrowser()
	{
		global $context, $user_info;

		// Init
		$this->_browsers = array();
		$this->_is_mobile = false;

		// Initialize some values we'll set differently if necessary...
		$this->_browsers['needs_size_fix'] = false;

		// One at a time, one at a time, and in this order too
		if ($this->isOpera())
			$this->setupOpera();
		// Meh...
		elseif ($this->isEdge())
			$this->setupEdge();
		// Them webkits need to be set up too
		elseif ($this->isWebkit())
			$this->setupWebkit();
		// We may have work to do on Firefox...
		elseif ($this->isFirefox())
			$this->setupFirefox();
		// Old friend, old frenemy
		elseif ($this->isIe())
			$this->setupIe();

		// Just a few mobile checks
		$this->isOperaMini();
		$this->isOperaMobi();

		// IE11 seems to be fine by itself without being lumped into the "is_ie" category
		$this->isIe11();

		// Be you robot or human?
		if ($user_info['possibly_robot'])
		{
			// This isn't meant to be reliable, it's just meant to catch most bots to prevent PHPSESSID from showing up.
			$this->_browsers['possibly_robot'] = !empty($user_info['possibly_robot']);

			// Robots shouldn't be logging in or registering.  So, they aren't a bot.  Better to be wrong than sorry (or people won't be able to log in!), anyway.
			if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register', 'signup'))) || !$user_info['is_guest'])
				$this->_browsers['possibly_robot'] = false;
		}
		else
			$this->_browsers['possibly_robot'] = false;

		// Fill out the historical array as needed to support old mods that don't use isBrowser
		$this->fillInformation();

		// Make it easy to check if the browser is on a mobile device.
		$this->_browsers['is_mobile'] = $this->_is_mobile;

		// Last step ...
		$this->setupBrowserPriority();

		// Now see what you've done!
		$context['browser'] = $this->_browsers;
	}

	/**
	 * Determine if the browser is Opera or not
	 *
	 * @return boolean Whether or not this is Opera
	 */
	function isOpera()
	{
		if (!isset($this->_browsers['is_opera']))
			$this->_browsers['is_opera'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false;
		return $this->_browsers['is_opera'];
	}

{'fraction_non_alphanumeric': 0.1513590844062947, 'fraction_numerical': 0.010014306151645207, 'mean_word_length': 3.3721075672295187, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7635604', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2234, 'n_words': 770}