Vergleich inc/functions.php - 1.8.8 - 1.8.10

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 343Zeile 343
	{
if(isset($mybb->user['uid']) && $mybb->user['uid'] != 0 && array_key_exists("timezone", $mybb->user))
{

	{
if(isset($mybb->user['uid']) && $mybb->user['uid'] != 0 && array_key_exists("timezone", $mybb->user))
{

			$offset = $mybb->user['timezone'];

			$offset = (float)$mybb->user['timezone'];

			$dstcorrection = $mybb->user['dst'];
}
elseif(defined("IN_ADMINCP"))
{

			$dstcorrection = $mybb->user['dst'];
}
elseif(defined("IN_ADMINCP"))
{

			$offset =  $mybbadmin['timezone'];

			$offset = (float)$mybbadmin['timezone'];

			$dstcorrection = $mybbadmin['dst'];
}
else
{

			$dstcorrection = $mybbadmin['dst'];
}
else
{

			$offset = $mybb->settings['timezoneoffset'];

			$offset = (float)$mybb->settings['timezoneoffset'];

			$dstcorrection = $mybb->settings['dstcorrection'];
}


			$dstcorrection = $mybb->settings['dstcorrection'];
}


Zeile 1868Zeile 1868
	if($httponly == true)
{
$cookie .= "; HttpOnly";

	if($httponly == true)
{
$cookie .= "; HttpOnly";

 
	}

if($mybb->settings['cookiesecureflag'])
{
$cookie .= "; Secure";

	}

$mybb->cookies[$name] = $value;

	}

$mybb->cookies[$name] = $value;

Zeile 2178Zeile 2183
	if(is_null($value))
{
return 'N;';

	if(is_null($value))
{
return 'N;';

	}


	}


	if(is_bool($value))
{
return 'b:'.(int)$value.';';

	if(is_bool($value))
{
return 'b:'.(int)$value.';';

Zeile 2218Zeile 2223
/**
* Credits go to https://github.com/piwik
* Wrapper for _safe_serialize() that handles exceptions and multibyte encoding issue

/**
* Credits go to https://github.com/piwik
* Wrapper for _safe_serialize() that handles exceptions and multibyte encoding issue

 *

 *

 * @param mixed $value
* @return string
*/

 * @param mixed $value
* @return string
*/

Zeile 2270Zeile 2275
			if($mybb->safemode)
{
return $lang->unknown;

			if($mybb->safemode)
{
return $lang->unknown;

			}

			}


// Suhosin likes to throw a warning if exec is disabled then die - weird
if($func_blacklist = @ini_get('suhosin.executor.func.blacklist'))


// Suhosin likes to throw a warning if exec is disabled then die - weird
if($func_blacklist = @ini_get('suhosin.executor.func.blacklist'))

Zeile 2282Zeile 2287
			}
// PHP disabled functions?
if($func_blacklist = @ini_get('disable_functions'))

			}
// PHP disabled functions?
if($func_blacklist = @ini_get('disable_functions'))

			{

			{

				if(strpos(",".$func_blacklist.",", 'exec') !== false)
{
return $lang->unknown;

				if(strpos(",".$func_blacklist.",", 'exec') !== false)
{
return $lang->unknown;

Zeile 2293Zeile 2298
			$load = explode("load average: ", $load);
$serverload = explode(",", $load[1]);
if(!is_array($serverload))

			$load = explode("load average: ", $load);
$serverload = explode(",", $load[1]);
if(!is_array($serverload))

			{

			{

				return $lang->unknown;
}
}

				return $lang->unknown;
}
}

Zeile 2316Zeile 2321
function get_memory_usage()
{
if(function_exists('memory_get_peak_usage'))

function get_memory_usage()
{
if(function_exists('memory_get_peak_usage'))

	{

	{

		return memory_get_peak_usage(true);
}
elseif(function_exists('memory_get_usage'))

		return memory_get_peak_usage(true);
}
elseif(function_exists('memory_get_usage'))

Zeile 2375Zeile 2380

$new_stats = array();
$counters = array('numthreads', 'numunapprovedthreads', 'numposts', 'numunapprovedposts', 'numusers', 'numdeletedposts', 'numdeletedthreads');


$new_stats = array();
$counters = array('numthreads', 'numunapprovedthreads', 'numposts', 'numunapprovedposts', 'numusers', 'numdeletedposts', 'numdeletedthreads');

	foreach($counters as $counter)
{
if(array_key_exists($counter, $changes))
{
if(substr($changes[$counter], 0, 2) == "+-")
{
$changes[$counter] = substr($changes[$counter], 1);
}
// Adding or subtracting from previous value?
if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
{
if((int)$changes[$counter] != 0)

	foreach($counters as $counter)
{
if(array_key_exists($counter, $changes))
{
if(substr($changes[$counter], 0, 2) == "+-")
{
$changes[$counter] = substr($changes[$counter], 1);
}
// Adding or subtracting from previous value?
if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
{
if((int)$changes[$counter] != 0)

				{
$new_stats[$counter] = $stats[$counter] + $changes[$counter];
if(!$force && (substr($stats[$counter], 0, 1) == "+" || substr($stats[$counter], 0, 1) == "-"))

				{
$new_stats[$counter] = $stats[$counter] + $changes[$counter];
if(!$force && (substr($stats[$counter], 0, 1) == "+" || substr($stats[$counter], 0, 1) == "-"))

Zeile 2412Zeile 2417
				{
$new_stats[$counter] = 0;
}

				{
$new_stats[$counter] = 0;
}

			}

			}

		}
}


		}
}


Zeile 2438Zeile 2443
			$stats = array_merge($stats, $new_stats); // Overwrite changed values
}
else

			$stats = array_merge($stats, $new_stats); // Overwrite changed values
}
else

		{

		{

			$stats = $new_stats;
}
}

			$stats = $new_stats;
}
}

Zeile 2451Zeile 2456
		"numposts" => (int)$stats['numposts']
);
$db->replace_query("stats", $todays_stats, "dateline");

		"numposts" => (int)$stats['numposts']
);
$db->replace_query("stats", $todays_stats, "dateline");





	$cache->update("stats", $stats, "dateline");
$stats_changes['inserted'] = true;
}

	$cache->update("stats", $stats, "dateline");
$stats_changes['inserted'] = true;
}

Zeile 2488Zeile 2493
				if((int)$changes[$counter] != 0)
{
$update_query[$counter] = $forum[$counter] + $changes[$counter];

				if((int)$changes[$counter] != 0)
{
$update_query[$counter] = $forum[$counter] + $changes[$counter];

				}
}

				}
}

			else
{
$update_query[$counter] = $changes[$counter];

			else
{
$update_query[$counter] = $changes[$counter];

			}

			}


// Less than 0? That's bad
if(isset($update_query[$counter]) && $update_query[$counter] < 0)
{
$update_query[$counter] = 0;
}


// Less than 0? That's bad
if(isset($update_query[$counter]) && $update_query[$counter] < 0)
{
$update_query[$counter] = 0;
}

		}
}


		}
}


	// Only update if we're actually doing something
if(count($update_query) > 0)
{

	// Only update if we're actually doing something
if(count($update_query) > 0)
{

Zeile 2515Zeile 2520
	{
$threads_diff = $update_query['threads'] - $forum['threads'];
if($threads_diff > -1)

	{
$threads_diff = $update_query['threads'] - $forum['threads'];
if($threads_diff > -1)

		{

		{

			$new_stats['numthreads'] = "+{$threads_diff}";

			$new_stats['numthreads'] = "+{$threads_diff}";

		}

		}

		else
{
$new_stats['numthreads'] = "{$threads_diff}";

		else
{
$new_stats['numthreads'] = "{$threads_diff}";

Zeile 2528Zeile 2533
	{
$unapprovedthreads_diff = $update_query['unapprovedthreads'] - $forum['unapprovedthreads'];
if($unapprovedthreads_diff > -1)

	{
$unapprovedthreads_diff = $update_query['unapprovedthreads'] - $forum['unapprovedthreads'];
if($unapprovedthreads_diff > -1)

		{

		{

			$new_stats['numunapprovedthreads'] = "+{$unapprovedthreads_diff}";

			$new_stats['numunapprovedthreads'] = "+{$unapprovedthreads_diff}";

		}

		}

		else
{
$new_stats['numunapprovedthreads'] = "{$unapprovedthreads_diff}";

		else
{
$new_stats['numunapprovedthreads'] = "{$unapprovedthreads_diff}";

Zeile 2541Zeile 2546
	{
$posts_diff = $update_query['posts'] - $forum['posts'];
if($posts_diff > -1)

	{
$posts_diff = $update_query['posts'] - $forum['posts'];
if($posts_diff > -1)

		{

		{

			$new_stats['numposts'] = "+{$posts_diff}";

			$new_stats['numposts'] = "+{$posts_diff}";

		}

		}

		else
{
$new_stats['numposts'] = "{$posts_diff}";

		else
{
$new_stats['numposts'] = "{$posts_diff}";

Zeile 2554Zeile 2559
	{
$unapprovedposts_diff = $update_query['unapprovedposts'] - $forum['unapprovedposts'];
if($unapprovedposts_diff > -1)

	{
$unapprovedposts_diff = $update_query['unapprovedposts'] - $forum['unapprovedposts'];
if($unapprovedposts_diff > -1)

		{

		{

			$new_stats['numunapprovedposts'] = "+{$unapprovedposts_diff}";

			$new_stats['numunapprovedposts'] = "+{$unapprovedposts_diff}";

		}

		}

		else
{
$new_stats['numunapprovedposts'] = "{$unapprovedposts_diff}";

		else
{
$new_stats['numunapprovedposts'] = "{$unapprovedposts_diff}";

Zeile 2567Zeile 2572
	{
$deletedposts_diff = $update_query['deletedposts'] - $forum['deletedposts'];
if($deletedposts_diff > -1)

	{
$deletedposts_diff = $update_query['deletedposts'] - $forum['deletedposts'];
if($deletedposts_diff > -1)

		{

		{

			$new_stats['numdeletedposts'] = "+{$deletedposts_diff}";

			$new_stats['numdeletedposts'] = "+{$deletedposts_diff}";

		}

		}

		else
{
$new_stats['numdeletedposts'] = "{$deletedposts_diff}";

		else
{
$new_stats['numdeletedposts'] = "{$deletedposts_diff}";

Zeile 2580Zeile 2585
	{
$deletedthreads_diff = $update_query['deletedthreads'] - $forum['deletedthreads'];
if($deletedthreads_diff > -1)

	{
$deletedthreads_diff = $update_query['deletedthreads'] - $forum['deletedthreads'];
if($deletedthreads_diff > -1)

		{

		{

			$new_stats['numdeletedthreads'] = "+{$deletedthreads_diff}";

			$new_stats['numdeletedthreads'] = "+{$deletedthreads_diff}";

		}

		}

		else
{
$new_stats['numdeletedthreads'] = "{$deletedthreads_diff}";

		else
{
$new_stats['numdeletedthreads'] = "{$deletedthreads_diff}";

Zeile 2592Zeile 2597
	if(!empty($new_stats))
{
update_stats($new_stats);

	if(!empty($new_stats))
{
update_stats($new_stats);

	}

	}

}

/**

}

/**

Zeile 2695Zeile 2700

// If this is a moved thread marker, don't update it - we need it to stay as it is
if(strpos($thread['closed'], 'moved|') !== false)


// If this is a moved thread marker, don't update it - we need it to stay as it is
if(strpos($thread['closed'], 'moved|') !== false)

	{

	{

		return;
}


		return;
}


Zeile 2726Zeile 2731
	if(empty($firstpost['username']))
{
$firstpost['username'] = $firstpost['postusername'];

	if(empty($firstpost['username']))
{
$firstpost['username'] = $firstpost['postusername'];

	}


	}


	if(empty($lastpost['username']))
{
$lastpost['username'] = $lastpost['postusername'];

	if(empty($lastpost['username']))
{
$lastpost['username'] = $lastpost['postusername'];

	}


	}


	if(empty($lastpost['dateline']))
{
$lastpost['username'] = $firstpost['username'];
$lastpost['uid'] = $firstpost['uid'];
$lastpost['dateline'] = $firstpost['dateline'];

	if(empty($lastpost['dateline']))
{
$lastpost['username'] = $firstpost['username'];
$lastpost['uid'] = $firstpost['uid'];
$lastpost['dateline'] = $firstpost['dateline'];

	}


	}


	$lastpost['username'] = $db->escape_string($lastpost['username']);
$firstpost['username'] = $db->escape_string($firstpost['username']);


	$lastpost['username'] = $db->escape_string($lastpost['username']);
$firstpost['username'] = $db->escape_string($firstpost['username']);


Zeile 2819Zeile 2824
 * @return bool
*/
function delete_thread($tid)

 * @return bool
*/
function delete_thread($tid)

{
global $moderation;

if(!is_object($moderation))
{
require_once MYBB_ROOT."inc/class_moderation.php";
$moderation = new Moderation;
}


{
global $moderation;

if(!is_object($moderation))
{
require_once MYBB_ROOT."inc/class_moderation.php";
$moderation = new Moderation;
}


	return $moderation->delete_thread($tid);
}


	return $moderation->delete_thread($tid);
}


Zeile 3003Zeile 3008
 * @param int $usergroup The usergroup for the user
* @param int $displaygroup The display group for the user
* @return string The formatted username

 * @param int $usergroup The usergroup for the user
* @param int $displaygroup The display group for the user
* @return string The formatted username

 */

 */

function format_name($username, $usergroup, $displaygroup=0)
{
global $groupscache, $cache;

if(!is_array($groupscache))

function format_name($username, $usergroup, $displaygroup=0)
{
global $groupscache, $cache;

if(!is_array($groupscache))

	{

	{

		$groupscache = $cache->read("usergroups");
}

if($displaygroup != 0)

		$groupscache = $cache->read("usergroups");
}

if($displaygroup != 0)

	{

	{

		$usergroup = $displaygroup;
}


		$usergroup = $displaygroup;
}


Zeile 3025Zeile 3030
	if($userin == 0)
{
$format = "{username}";

	if($userin == 0)
{
$format = "{username}";

	}


	}


	$format = stripslashes($format);

return str_replace("{username}", $username, $format);
}

	$format = stripslashes($format);

return str_replace("{username}", $username, $format);
}





/**
* Formats an avatar to a certain dimension
*

/**
* Formats an avatar to a certain dimension
*

Zeile 3048Zeile 3053
	if(!isset($avatars))
{
$avatars = array();

	if(!isset($avatars))
{
$avatars = array();

 
	}

if(my_strpos($avatar, '://') !== false && !$mybb->settings['allowremoteavatars'])
{
// Remote avatar, but remote avatars are disallowed.
$avatar = null;

	}

if(!$avatar)

	}

if(!$avatar)

Zeile 4346Zeile 4357

unset($GLOBALS['navbits']);
$GLOBALS['navbits'] = $newnav;


unset($GLOBALS['navbits']);
$GLOBALS['navbits'] = $newnav;

}


}


/**
* Builds a URL to an archive mode page
*

/**
* Builds a URL to an archive mode page
*

Zeile 5998Zeile 6009
	}

switch($db->type)

	}

switch($db->type)

	{

	{

		case 'mysql':
case 'mysqli':
$field = 'username';

		case 'mysql':
case 'mysqli':
$field = 'username';

Zeile 7629Zeile 7640
	global $mybb, $checksums, $bad_verify_files;

// We don't need to check these types of files

	global $mybb, $checksums, $bad_verify_files;

// We don't need to check these types of files

	$ignore = array(".", "..", ".svn", "config.php", "settings.php", "Thumb.db", "config.default.php", "lock", "htaccess.txt", "logo.gif", "logo.png");

	$ignore = array(".", "..", ".svn", "config.php", "settings.php", "Thumb.db", "config.default.php", "lock", "htaccess.txt", "htaccess-nginx.txt", "logo.gif", "logo.png");

	$ignore_ext = array("attach");

if(substr($path, -1, 1) == "/")

	$ignore_ext = array("attach");

if(substr($path, -1, 1) == "/")

Zeile 7651Zeile 7662
			while(($file = @readdir($dh)) !== false)
{
if(in_array($file, $ignore) || in_array(get_extension($file), $ignore_ext))

			while(($file = @readdir($dh)) !== false)
{
if(in_array($file, $ignore) || in_array(get_extension($file), $ignore_ext))

				{
continue;
}

				{
continue;
}


// Recurse through the directory tree
if(is_dir($path."/".$file))


// Recurse through the directory tree
if(is_dir($path."/".$file))

Zeile 7661Zeile 7672
					verify_files($path."/".$file, ($count+1));
continue;
}

					verify_files($path."/".$file, ($count+1));
continue;
}





				// We only need the last part of the path (from the MyBB directory to the file. i.e. inc/functions.php)

				// We only need the last part of the path (from the MyBB directory to the file. i.e. inc/functions.php)

				$file_path = ".".str_replace(substr(MYBB_ROOT, 0, -1), "", $path)."/".$file;


				$file_path = ".".str_replace(substr(MYBB_ROOT, 0, -1), "", $path)."/".$file;


				// Does this file even exist in our official list? Perhaps it's a plugin
if(array_key_exists($file_path, $checksums))
{

				// Does this file even exist in our official list? Perhaps it's a plugin
if(array_key_exists($file_path, $checksums))
{

Zeile 7688Zeile 7699
				unset($checksums[$file_path]);
}
@closedir($dh);

				unset($checksums[$file_path]);
}
@closedir($dh);

		}
}


		}
}


	if($count == 0)
{
if(!empty($checksums))

	if($count == 0)
{
if(!empty($checksums))

Zeile 7703Zeile 7714
				}
$bad_verify_files[] = array("status" => "missing", "path" => $file_path);
}

				}
$bad_verify_files[] = array("status" => "missing", "path" => $file_path);
}

		}

		}

	}

// uh oh

	}

// uh oh

Zeile 7755Zeile 7766
		{
$output = @fread($handle, $bytes);
@fclose($handle);

		{
$output = @fread($handle, $bytes);
@fclose($handle);

		}

		}

	}
else

	}
else

	{

	{

		return $output;
}


		return $output;
}


Zeile 7767Zeile 7778
		if(function_exists('mcrypt_create_iv'))
{
if (DIRECTORY_SEPARATOR == '/')

		if(function_exists('mcrypt_create_iv'))
{
if (DIRECTORY_SEPARATOR == '/')

			{

			{

				$source = MCRYPT_DEV_URANDOM;

				$source = MCRYPT_DEV_URANDOM;

			}

			}

			else
{
$source = MCRYPT_RAND;
}

$output = @mcrypt_create_iv($bytes, $source);

			else
{
$source = MCRYPT_RAND;
}

$output = @mcrypt_create_iv($bytes, $source);

		}
}
else
{

		}
}
else
{

		return $output;
}


		return $output;
}


Zeile 7792Zeile 7803
			{
$output = openssl_random_pseudo_bytes($bytes, $crypto_strong);
if ($crypto_strong == false)

			{
$output = openssl_random_pseudo_bytes($bytes, $crypto_strong);
if ($crypto_strong == false)

				{

				{

					$output = null;

					$output = null;

				}
}
}
}
else
{
return $output;
}

if(strlen($output) < $bytes)
{

				}
}
}
}
else
{
return $output;
}

if(strlen($output) < $bytes)
{

		if(class_exists('COM'))
{
try

		if(class_exists('COM'))
{
try

Zeile 7816Zeile 7827
				}
} catch (Exception $e) {
}

				}
} catch (Exception $e) {
}

		}
}

		}
}

	else

	else

	{

	{

		return $output;
}

		return $output;
}





	if(strlen($output) < $bytes)
{
// Close to what PHP basically uses internally to seed, but not quite.
$unique_state = microtime().@getmypid();

	if(strlen($output) < $bytes)
{
// Close to what PHP basically uses internally to seed, but not quite.
$unique_state = microtime().@getmypid();





		$rounds = ceil($bytes / 16);

		$rounds = ceil($bytes / 16);





		for($i = 0; $i < $rounds; $i++)
{
$unique_state = md5(microtime().$unique_state);
$output .= md5($unique_state);
}

		for($i = 0; $i < $rounds; $i++)
{
$unique_state = md5(microtime().$unique_state);
$output .= md5($unique_state);
}





		$output = substr($output, 0, ($bytes * 2));

		$output = substr($output, 0, ($bytes * 2));





		$output = pack('H*', $output);

		$output = pack('H*', $output);


return $output;
}


return $output;
}

	else

	else

	{

	{

		return $output;
}
}

		return $output;
}
}





/**
* Returns a securely generated seed integer
*
* @return int An integer equivalent of a secure hexadecimal seed
*/
function secure_seed_rng()

/**
* Returns a securely generated seed integer
*
* @return int An integer equivalent of a secure hexadecimal seed
*/
function secure_seed_rng()

{
$bytes = PHP_INT_SIZE;

do
{

{
$bytes = PHP_INT_SIZE;

do
{


$output = secure_binary_seed_rng($bytes);



$output = secure_binary_seed_rng($bytes);


Zeile 8064Zeile 8075
 * Obtain the version of GD installed.
*
* @return float Version of GD

 * Obtain the version of GD installed.
*
* @return float Version of GD

 */

 */

function gd_version()
{
static $gd_version;

function gd_version()
{
static $gd_version;





	if($gd_version)
{
return $gd_version;

	if($gd_version)
{
return $gd_version;

	}

	}

	if(!extension_loaded('gd'))
{
return;

	if(!extension_loaded('gd'))
{
return;

	}


	}


	if(function_exists("gd_info"))
{
$gd_info = gd_info();

	if(function_exists("gd_info"))
{
$gd_info = gd_info();

Zeile 8124Zeile 8135
					{
$string .= '?';
continue;

					{
$string .= '?';
continue;

					}
else
{
return false;
}
}

					}
else
{
return false;
}
}

				elseif($c > 239)

				elseif($c > 239)

				{

				{

					$bytes = 4;

					$bytes = 4;

				}

				}

				elseif($c > 223)
{
$bytes = 3;

				elseif($c > 223)
{
$bytes = 3;

Zeile 8142Zeile 8153
				{
$bytes = 2;
}

				{
$bytes = 2;
}

				if(($i + $bytes) > $len)

				if(($i + $bytes) > $len)

				{
if($return)
{

				{
if($return)
{

Zeile 8167Zeile 8178
							$valid = false;
$string .= '?';
break;

							$valid = false;
$string .= '?';
break;

						}

						}

						else
{
return false;

						else
{
return false;

Zeile 8372Zeile 8383
	if(!$ip_address)
{
$ip_address = get_ip();

	if(!$ip_address)
{
$ip_address = get_ip();

	}

$ip_address = my_inet_pton($ip_address);

	}

$ip_address = my_inet_pton($ip_address);


$insert_array = array(
'username' => $db->escape_string($username),


$insert_array = array(
'username' => $db->escape_string($username),

Zeile 8385Zeile 8396
	);

return (bool)$db->insert_query('spamlog', $insert_array);

	);

return (bool)$db->insert_query('spamlog', $insert_array);

}


}


/**
* Copy a file to the CDN.
*
* @param string $file_path The path to the file to upload to the CDN.

/**
* Copy a file to the CDN.
*
* @param string $file_path The path to the file to upload to the CDN.

 *

 *

 * @param string $uploaded_path The path the file was uploaded to, reference parameter for when this may be needed.
*
* @return bool Whether the file was copied successfully.

 * @param string $uploaded_path The path the file was uploaded to, reference parameter for when this may be needed.
*
* @return bool Whether the file was copied successfully.

Zeile 8399Zeile 8410
function copy_file_to_cdn($file_path = '', &$uploaded_path = null)
{
global $mybb, $plugins;

function copy_file_to_cdn($file_path = '', &$uploaded_path = null)
{
global $mybb, $plugins;





	$success = false;

$file_path = (string)$file_path;

	$success = false;

$file_path = (string)$file_path;

Zeile 8477Zeile 8488
	}

return false;

	}

return false;

 
}

/**
* Strip html tags from string, also removes <script> and <style> contents.
*
* @param string $string String to stripe
* @param string $allowable_tags Allowed html tags
*
* @return string Striped string
*/
function my_strip_tags($string, $allowable_tags = '')
{
$pattern = array(
'@(&lt;)style[^(&gt;)]*?(&gt;).*?(&lt;)/style(&gt;)@siu',
'@(&lt;)script[^(&gt;)]*?.*?(&lt;)/script(&gt;)@siu',
'@<style[^>]*?>.*?</style>@siu',
'@<script[^>]*?.*?</script>@siu',
);
$string = preg_replace($pattern, '', $string);
return strip_tags($string, $allowable_tags);

}

}