<commit_before><?

	#
	# some startup tasks which come before anything else:
	#  * set up the timezone
	#  * record the time
	#  * set the mbstring encoding
	#

	# Also: there is running code at the bottom of this file

	error_reporting((E_ALL | E_STRICT) ^ E_NOTICE);

	putenv('TZ=EST5EDT');
	date_default_timezone_set('America/New_York');

	$GLOBALS['timings'] = array();
	$GLOBALS['timings']['execution_start'] = microtime_ms();
	$GLOBALS['timing_keys'] = array();

	$GLOBALS['timing_keys']['config'] = 'Config files';
	$GLOBALS['timings']['config_count'] = 0;
	$GLOBALS['timings']['config_time'] = 0;

	$GLOBALS['timing_keys']['loadlib'] = 'Libraries';
	$GLOBALS['timings']['loadlib_count'] = 0;
	$GLOBALS['timings']['loadlib_time'] = 0;

	$GLOBALS['timing_keys']['loadlib_default'] = 'Libraries (default)';
	$GLOBALS['timings']['loadlib_default_count'] = 0;
	$GLOBALS['timings']['loadlib_default_time'] = 0;

	$GLOBALS['timing_keys']['loadlib_auto'] = 'Libraries (auto)';
	$GLOBALS['timings']['loadlib_auto_count'] = 0;
	$GLOBALS['timings']['loadlib_auto_time'] = 0;

	$GLOBALS['timing_keys']['db_init'] = 'DB init';
	$GLOBALS['timings']['db_init_count'] = 1;
	$GLOBALS['timings']['db_init_time'] = 0;

	mb_internal_encoding('UTF-8');
	#
	# the module loading code.
	#
	# we track which modules we've loaded ourselves instead of
	# using include_once(). we do this so that we can avoid the
	# stat() overhead involved in figuring out the canonical path
	# to a file. so long as we always load modules via this
	# method, we save some filesystem overhead.
	#
	# we can also ensure that modules don't pollute the global
	# namespace accidentally, since they are always loaded in a
	# function's private scope.
	#

	$GLOBALS['loaded_libs'] = array();

	define('FLAMEWORK_INCLUDE_DIR', dirname(__FILE__).'/');

	function loadlib($name){

		if ($GLOBALS['loaded_libs'][$name]){
			return;
		}

		$GLOBALS['loaded_libs'][$name] = 1;

		$start = microtime_ms();

		$fq_name = _loadlib_enpathify("lib_{$name}.php");
		include($fq_name);

		$end = microtime_ms();
		$time = $end - $start;

		$GLOBALS['timings']['loadlib_count'] += 1;
		$GLOBALS['timings']['loadlib_time'] += $time;

		# $GLOBALS['timing_keys']["loadlib_{$name}"] = "lib_{$name}";
		# $GLOBALS['timings']["loadlib_{$name}_count"] = 1;
		# $GLOBALS['timings']["loadlib_{$name}_time"] = $time;
	}

	function loadpear($name){

		if ($GLOBALS['loaded_libs']['PEAR:'.$name]){
			return;
		}

		$GLOBALS['loaded_libs']['PEAR:'.$name] = 1;

		$fq_name = _loadlib_enpathify("pear/{$name}.php");
		include($fq_name);
	}

	function _loadlib_enpathify($lib){

		# see also: http://www.php.net/manual/en/ini.core.php#ini.include-path

		$inc_path = ini_get('include_path');

		if (preg_match("/\/flamework\//", $inc_path)){
			return $lib;
		}

		return FLAMEWORK_INCLUDE_DIR . $lib;
	}

	#
	# general utility functions
	#

	# This is necessary to account for traffic being load-balanced by nginx. See also:

	function remote_addr(){

		if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){

			// X-Forwarded-For is a list of forwarded IP addresses, representing
			// each hop of a proxy chain. It comes in as a comma-separated list.
			//
			// At which position in the list the client's public IP appears
			// depends on the specific proxy setup. We default to "first in the
			// list," but it needs to be configured according to the network
			// stack.
			//
			// Note that IPs get prepended to the _front_ of the list, so the
			// index config is really counting from the end. If X-Fowarded-For
			// comes in as 1.1.1.1, 2.2.2.2, 3.3.3.3, and the
			// $GLOBALS['cfg']['remote_addr_index'] value is set to 0, then
			// that means 3.3.3.3 is chosen as the remote_addr() return value.
			//
			// This is important because getting it wrong means an attacker
			// could spoof somebody's IP, simply by making a request like this:
			// curl -H "X-Forwarded-For 1.2.3.4" ... and that value would get
			// prepended to the list of IPs added by our own proxies,
			// potentially tricking us into accepting a forged crumb.
			//
			// See also: See: http://nginx.org/en/docs/http/ngx_http_proxy_module.html
			// (20171024/dphiffer)

			$ip_list = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
			$ip_list = array_reverse($ip_list); // remember that IPs are prepended, not appended
			$ip_index = 0;
			if ($GLOBALS['cfg']['remote_addr_index']){
				$ip_index = intval($GLOBALS['cfg']['remote_addr_index']);
			}

			if (! $ip_list[$ip_index]){
				// We cannot trust crumbs at this point, so just bail out
				// with an error message.
				die("remote_addr() error: X-Forwarded-For does not have an index $ip_index.");
			}<commit_msg>:information_desk_person: tweaking the comments just a bit<commit_after><?

	#
	# some startup tasks which come before anything else:
	#  * set up the timezone
	#  * record the time
	#  * set the mbstring encoding
	#

	# Also: there is running code at the bottom of this file

	error_reporting((E_ALL | E_STRICT) ^ E_NOTICE);

	putenv('TZ=EST5EDT');
	date_default_timezone_set('America/New_York');

	$GLOBALS['timings'] = array();
	$GLOBALS['timings']['execution_start'] = microtime_ms();
	$GLOBALS['timing_keys'] = array();

	$GLOBALS['timing_keys']['config'] = 'Config files';
	$GLOBALS['timings']['config_count'] = 0;
	$GLOBALS['timings']['config_time'] = 0;

	$GLOBALS['timing_keys']['loadlib'] = 'Libraries';
	$GLOBALS['timings']['loadlib_count'] = 0;
	$GLOBALS['timings']['loadlib_time'] = 0;

	$GLOBALS['timing_keys']['loadlib_default'] = 'Libraries (default)';
	$GLOBALS['timings']['loadlib_default_count'] = 0;
	$GLOBALS['timings']['loadlib_default_time'] = 0;

	$GLOBALS['timing_keys']['loadlib_auto'] = 'Libraries (auto)';
	$GLOBALS['timings']['loadlib_auto_count'] = 0;
	$GLOBALS['timings']['loadlib_auto_time'] = 0;

	$GLOBALS['timing_keys']['db_init'] = 'DB init';
	$GLOBALS['timings']['db_init_count'] = 1;
	$GLOBALS['timings']['db_init_time'] = 0;

	mb_internal_encoding('UTF-8');
	#
	# the module loading code.
	#
	# we track which modules we've loaded ourselves instead of
	# using include_once(). we do this so that we can avoid the
	# stat() overhead involved in figuring out the canonical path
	# to a file. so long as we always load modules via this
	# method, we save some filesystem overhead.
	#
	# we can also ensure that modules don't pollute the global
	# namespace accidentally, since they are always loaded in a
	# function's private scope.
	#

	$GLOBALS['loaded_libs'] = array();

	define('FLAMEWORK_INCLUDE_DIR', dirname(__FILE__).'/');

	function loadlib($name){

		if ($GLOBALS['loaded_libs'][$name]){
			return;
		}

		$GLOBALS['loaded_libs'][$name] = 1;

		$start = microtime_ms();

		$fq_name = _loadlib_enpathify("lib_{$name}.php");
		include($fq_name);

		$end = microtime_ms();
		$time = $end - $start;

		$GLOBALS['timings']['loadlib_count'] += 1;
		$GLOBALS['timings']['loadlib_time'] += $time;

		# $GLOBALS['timing_keys']["loadlib_{$name}"] = "lib_{$name}";
		# $GLOBALS['timings']["loadlib_{$name}_count"] = 1;
		# $GLOBALS['timings']["loadlib_{$name}_time"] = $time;
	}

	function loadpear($name){

		if ($GLOBALS['loaded_libs']['PEAR:'.$name]){
			return;
		}

		$GLOBALS['loaded_libs']['PEAR:'.$name] = 1;

		$fq_name = _loadlib_enpathify("pear/{$name}.php");
		include($fq_name);
	}

	function _loadlib_enpathify($lib){

		# see also: http://www.php.net/manual/en/ini.core.php#ini.include-path

		$inc_path = ini_get('include_path');

		if (preg_match("/\/flamework\//", $inc_path)){
			return $lib;
		}

		return FLAMEWORK_INCLUDE_DIR . $lib;
	}

	#
	# general utility functions
	#

	# This is necessary to account for traffic being load-balanced by nginx. See also:

	function remote_addr(){

		if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){

			// X-Forwarded-For is a list of forwarded IP addresses, representing
			// each hop of a proxy chain. It comes in as a comma-separated list.
			//
			// At which position in the list the client's public IP appears
			// depends on the specific proxy setup. We default to "first in the
			// list," but it needs to be configured according to the network
			// stack. This is controlled by a 'remote_addr_index' config, which
			// defaults to 0.
			//
			// Note that IPs get prepended to the _front_ of the list, so the
			// index config is really counting from the end. If X-Fowarded-For
			// comes in as 1.1.1.1, 2.2.2.2, 3.3.3.3, and
			// $GLOBALS['cfg']['remote_addr_index'] is set to 0, then
			// that means 3.3.3.3 is chosen as the remote_addr() return value.
			//
			// This is important because getting it wrong means an attacker
			// could spoof somebody's IP, simply by making a request like this:
			// curl -H "X-Forwarded-For: 1.2.3.4" ... and that value would get
			// prepended to the list of IPs of our proxies, potentially tricking
			// us into accepting a forged crumb.
			//
			// See also: http://nginx.org/en/docs/http/ngx_http_proxy_module.html
			// (20171024/dphiffer)

			$ip_list = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
			$ip_list = array_reverse($ip_list); // remember that IPs are prepended, not appended
			$ip_index = 0;
			if ($GLOBALS['cfg']['remote_addr_index']){
				$ip_index = intval($GLOBALS['cfg']['remote_addr_index']);
			}

			if (! $ip_list[$ip_index]){
				// We cannot trust crumbs at this point, so just bail out
				// with an error message. This is may be overly-conservative,
				// but we'll stick with that for now.
				die("remote_addr() error: X-Forwarded-For does not have an index $ip_index.");
			}
{'fraction_non_alphanumeric': 0.1590623691921306, 'fraction_numerical': 0.009732105483465885, 'mean_word_length': 4.08080808080808, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 10, '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': '3702303', 'n_tokens_mistral': 3679, 'n_tokens_neox': 3274, 'n_words': 884}