Vergleich inc/functions.php - 1.8.37 - 1.8.38

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 1694Zeile 1694
{
global $groupscache, $forum_cache, $fpermcache, $mybb, $fpermfields;


{
global $groupscache, $forum_cache, $fpermcache, $mybb, $fpermfields;


	$groups = explode(",", $gid);








    if(isset($gid))
{
$groups = explode(",", $gid);
}
else
{
$groups = array();
}


$current_permissions = array();
$only_view_own_threads = 1;


$current_permissions = array();
$only_view_own_threads = 1;

Zeile 2727Zeile 2734
		{
// sys_getloadavg() will return an array with [0] being load within the last minute.
$serverload = sys_getloadavg();

		{
// sys_getloadavg() will return an array with [0] being load within the last minute.
$serverload = sys_getloadavg();

 

if(!is_array($serverload))
{
return $lang->unknown;
}


			$serverload[0] = round($serverload[0], 4);
}
else if(@file_exists("/proc/loadavg") && $load = @file_get_contents("/proc/loadavg"))

			$serverload[0] = round($serverload[0], 4);
}
else if(@file_exists("/proc/loadavg") && $load = @file_get_contents("/proc/loadavg"))

Zeile 2743Zeile 2756

// 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'))

			{
if(strpos(",".$func_blacklist.",", 'exec') !== false)
{

			{
if(strpos(",".$func_blacklist.",", 'exec') !== false)
{

					return $lang->unknown;
}
}

					return $lang->unknown;
}
}

Zeile 2802Zeile 2815
 * @param boolean $force Force stats update?
*/
function update_stats($changes=array(), $force=false)

 * @param boolean $force Force stats update?
*/
function update_stats($changes=array(), $force=false)

{

{

	global $cache, $db;
static $stats_changes;


	global $cache, $db;
static $stats_changes;


Zeile 2942Zeile 2955
	// Fetch above counters for this forum
$query = $db->simple_select("forums", implode(",", $counters), "fid='{$fid}'");
$forum = $db->fetch_array($query);

	// Fetch above counters for this forum
$query = $db->simple_select("forums", implode(",", $counters), "fid='{$fid}'");
$forum = $db->fetch_array($query);


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) == "-")


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)
{

			{
if((int)$changes[$counter] != 0)
{

Zeile 2962Zeile 2975
			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 2981Zeile 2994
	// Guess we should update the statistics too?
$new_stats = array();
if(array_key_exists('threads', $update_query))

	// Guess we should update the statistics too?
$new_stats = array();
if(array_key_exists('threads', $update_query))

	{

	{

		$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}";
}
else
{
$new_stats['numthreads'] = "{$threads_diff}";

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

		}

		}

	}

if(array_key_exists('unapprovedthreads', $update_query))

	}

if(array_key_exists('unapprovedthreads', $update_query))

Zeile 2999Zeile 3012
		if($unapprovedthreads_diff > -1)
{
$new_stats['numunapprovedthreads'] = "+{$unapprovedthreads_diff}";

		if($unapprovedthreads_diff > -1)
{
$new_stats['numunapprovedthreads'] = "+{$unapprovedthreads_diff}";

		}

		}

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

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

Zeile 3025Zeile 3038
		if($unapprovedposts_diff > -1)
{
$new_stats['numunapprovedposts'] = "+{$unapprovedposts_diff}";

		if($unapprovedposts_diff > -1)
{
$new_stats['numunapprovedposts'] = "+{$unapprovedposts_diff}";

		}
else
{

		}
else
{

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

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

Zeile 3046Zeile 3059
	}

if(array_key_exists('deletedthreads', $update_query))

	}

if(array_key_exists('deletedthreads', $update_query))

	{

	{

		$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}";
}

	}

	}


if(!empty($new_stats))
{


if(!empty($new_stats))
{

Zeile 3102Zeile 3115
			"lastposttid" => 0,
"lastpostsubject" => '',
);

			"lastposttid" => 0,
"lastpostsubject" => '',
);

	}

	}


$db->update_query("forums", $updated_forum, "fid='{$fid}'");
}


$db->update_query("forums", $updated_forum, "fid='{$fid}'");
}

Zeile 3112Zeile 3125
 *
* @param int $tid The thread ID
* @param array $changes Array of items being updated (replies, unapprovedposts, deletedposts, attachmentcount) and their value (ex, 1, +1, -1)

 *
* @param int $tid The thread ID
* @param array $changes Array of items being updated (replies, unapprovedposts, deletedposts, attachmentcount) and their value (ex, 1, +1, -1)

 */

 */

function update_thread_counters($tid, $changes=array())
{
global $db;

function update_thread_counters($tid, $changes=array())
{
global $db;





	$update_query = array();
$tid = (int)$tid;

$counters = array('replies', 'unapprovedposts', 'attachmentcount', 'deletedposts', 'attachmentcount');

	$update_query = array();
$tid = (int)$tid;

$counters = array('replies', 'unapprovedposts', 'attachmentcount', 'deletedposts', 'attachmentcount');





	// Fetch above counters for this thread
$query = $db->simple_select("threads", implode(",", $counters), "tid='{$tid}'");
$thread = $db->fetch_array($query);

	// Fetch above counters for this thread
$query = $db->simple_select("threads", implode(",", $counters), "tid='{$tid}'");
$thread = $db->fetch_array($query);

Zeile 3131Zeile 3144
		if(array_key_exists($counter, $changes))
{
if(substr($changes[$counter], 0, 2) == "+-")

		if(array_key_exists($counter, $changes))
{
if(substr($changes[$counter], 0, 2) == "+-")

			{

			{

				$changes[$counter] = substr($changes[$counter], 1);
}
// Adding or subtracting from previous value?

				$changes[$counter] = substr($changes[$counter], 1);
}
// Adding or subtracting from previous value?

Zeile 3177Zeile 3190

// 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 3327Zeile 3340
	global $moderation;

if(!is_object($moderation))

	global $moderation;

if(!is_object($moderation))

	{

	{

		require_once MYBB_ROOT."inc/class_moderation.php";
$moderation = new Moderation;
}

		require_once MYBB_ROOT."inc/class_moderation.php";
$moderation = new Moderation;
}

Zeile 5731Zeile 5744
	}

if(is_int($number))

	}

if(is_int($number))

	{

	{

		return number_format($number, 0, $mybb->settings['decpoint'], $mybb->settings['thousandssep']);
}
else
{

		return number_format($number, 0, $mybb->settings['decpoint'], $mybb->settings['thousandssep']);
}
else
{

		$parts = explode('.', $number);








        if(isset($number))
{
$parts = explode('.', $number);
}
else
{
$parts = array();
}


if(isset($parts[1]))
{


if(isset($parts[1]))
{

Zeile 5881Zeile 5901
 * @return array The number of days in each month of that year
*/
function get_bdays($in)

 * @return array The number of days in each month of that year
*/
function get_bdays($in)

{

{

	return array(
31,
($in % 4 == 0 && ($in % 100 > 0 || $in % 400 == 0) ? 29 : 28),

	return array(
31,
($in % 4 == 0 && ($in % 100 > 0 || $in % 400 == 0) ? 29 : 28),

Zeile 6027Zeile 6047
 * @param int $tid The thread id for which to update the first post id.
*/
function update_first_post($tid)

 * @param int $tid The thread id for which to update the first post id.
*/
function update_first_post($tid)

{
global $db;

$query = $db->query("

{
global $db;

$query = $db->query("

		SELECT u.uid, u.username, p.pid, p.username AS postusername, p.dateline
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)

		SELECT u.uid, u.username, p.pid, p.username AS postusername, p.dateline
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)

Zeile 6123Zeile 6143

$string = preg_replace("#&\#([0-9]+);#", "-", $string);



$string = preg_replace("#&\#([0-9]+);#", "-", $string);


	if(strtolower($lang->settings['charset']) == "utf-8")

	if(isset($lang->settings['charset']) && strtolower($lang->settings['charset']) == "utf-8")

	{
// Get rid of any excess RTL and LTR override for they are the workings of the devil
$string = str_replace(dec_to_utf8(8238), "", $string);

	{
// Get rid of any excess RTL and LTR override for they are the workings of the devil
$string = str_replace(dec_to_utf8(8238), "", $string);

Zeile 6249Zeile 6269
function my_strpos($haystack, $needle, $offset=0)
{
if($needle == '')

function my_strpos($haystack, $needle, $offset=0)
{
if($needle == '')

	{
return false;
}

if(function_exists("mb_strpos"))
{
$position = mb_strpos($haystack, $needle, $offset);

	{
return false;
}

if(function_exists("mb_strpos"))
{
$position = mb_strpos($haystack, $needle, $offset);

	}
else
{

	}
else
{

Zeile 6263Zeile 6283
	}

return $position;

	}

return $position;

}

/**

}

/**

 * Ups the case of a string, mb strings accounted for
*
* @param string $string The string to up.

 * Ups the case of a string, mb strings accounted for
*
* @param string $string The string to up.

Zeile 6274Zeile 6294
function my_strtoupper($string)
{
if(function_exists("mb_strtoupper"))

function my_strtoupper($string)
{
if(function_exists("mb_strtoupper"))

	{

	{

		$string = mb_strtoupper($string);

		$string = mb_strtoupper($string);

	}

	}

	else
{
$string = strtoupper($string);
}

return $string;

	else
{
$string = strtoupper($string);
}

return $string;

}

}


/**
* Returns any html entities to their original character


/**
* Returns any html entities to their original character

Zeile 6292Zeile 6312
 * @return string The un-htmlentitied' string.
*/
function unhtmlentities($string)

 * @return string The un-htmlentitied' string.
*/
function unhtmlentities($string)

{

{

	// Replace numeric entities
$string = preg_replace_callback('~&#x([0-9a-f]+);~i', 'unichr_callback1', $string);
$string = preg_replace_callback('~&#([0-9]+);~', 'unichr_callback2', $string);

	// Replace numeric entities
$string = preg_replace_callback('~&#x([0-9a-f]+);~i', 'unichr_callback1', $string);
$string = preg_replace_callback('~&#([0-9]+);~', 'unichr_callback2', $string);

Zeile 6330Zeile 6350
		return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
. chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);

		return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
. chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);

	}
else
{
return false;
}

	}
else
{
return false;
}

}

/**

}

/**

Zeile 6485Zeile 6505
 * @return string The url to the thread.
*/
function get_thread_link($tid, $page=0, $action='')

 * @return string The url to the thread.
*/
function get_thread_link($tid, $page=0, $action='')

{

{

	if($page > 1)
{
if($action)

	if($page > 1)
{
if($action)

Zeile 6635Zeile 6655
		return $user_cache[$uid];
}
return array();

		return $user_cache[$uid];
}
return array();

}

}


/**
* Get the user data of an user username.


/**
* Get the user data of an user username.

Zeile 6645Zeile 6665
 * @return array The users data
*/
function get_user_by_username($username, $options=array())

 * @return array The users data
*/
function get_user_by_username($username, $options=array())

{

{

	global $mybb, $db;

	global $mybb, $db;





	$username = $db->escape_string(my_strtolower($username));

	$username = $db->escape_string(my_strtolower($username));





	if(!isset($options['username_method']))
{
$options['username_method'] = 0;

	if(!isset($options['username_method']))
{
$options['username_method'] = 0;

	}


	}


	switch($db->type)
{
case 'mysql':

	switch($db->type)
{
case 'mysql':

Zeile 6710Zeile 6730
	static $forum_cache;

if(!isset($forum_cache) || !is_array($forum_cache))

	static $forum_cache;

if(!isset($forum_cache) || !is_array($forum_cache))

	{

	{

		$forum_cache = $cache->read("forums");

		$forum_cache = $cache->read("forums");

	}


	}


	if(empty($forum_cache[$fid]))
{
return false;
}

if($active_override != 1)

	if(empty($forum_cache[$fid]))
{
return false;
}

if($active_override != 1)

	{

	{

		$parents = explode(",", $forum_cache[$fid]['parentlist']);
if(is_array($parents))
{

		$parents = explode(",", $forum_cache[$fid]['parentlist']);
if(is_array($parents))
{

Zeile 6739Zeile 6759

/**
* Get the thread of a thread id.


/**
* Get the thread of a thread id.

 *

 *

 * @param int $tid The thread id of the thread.
* @param boolean $recache Whether or not to recache the thread.
* @return array|bool The database row of the thread. False on failure

 * @param int $tid The thread id of the thread.
* @param boolean $recache Whether or not to recache the thread.
* @return array|bool The database row of the thread. False on failure

Zeile 6748Zeile 6768
{
global $db;
static $thread_cache;

{
global $db;
static $thread_cache;





	$tid = (int)$tid;

if(isset($thread_cache[$tid]) && !$recache)

	$tid = (int)$tid;

if(isset($thread_cache[$tid]) && !$recache)

Zeile 6785Zeile 6805
	static $post_cache;

$pid = (int)$pid;

	static $post_cache;

$pid = (int)$pid;





	if(isset($post_cache[$pid]))
{
return $post_cache[$pid];

	if(isset($post_cache[$pid]))
{
return $post_cache[$pid];

Zeile 6804Zeile 6824
		{
$post_cache[$pid] = false;
return false;

		{
$post_cache[$pid] = false;
return false;

		}

		}

	}
}


	}
}


Zeile 6814Zeile 6834
 * @return string The comma separated values of the inactivate forum.
*/
function get_inactive_forums()

 * @return string The comma separated values of the inactivate forum.
*/
function get_inactive_forums()

{

{

	global $forum_cache, $cache;

	global $forum_cache, $cache;





	if(!$forum_cache)
{
cache_forums();
}

$inactive = array();

	if(!$forum_cache)
{
cache_forums();
}

$inactive = array();





	foreach($forum_cache as $fid => $forum)
{
if($forum['active'] == 0)

	foreach($forum_cache as $fid => $forum)
{
if($forum['active'] == 0)

Zeile 6860Zeile 6880

// Get this user's login attempts and eventual lockout, if a uid is provided
if($uid > 0)


// Get this user's login attempts and eventual lockout, if a uid is provided
if($uid > 0)

	{

	{

		$query = $db->simple_select("users", "loginattempts, loginlockoutexpiry", "uid='{$uid}'", 1);
$attempts = $db->fetch_array($query);


		$query = $db->simple_select("users", "loginattempts, loginlockoutexpiry", "uid='{$uid}'", 1);
$attempts = $db->fetch_array($query);


Zeile 6878Zeile 6898
			$hoursleft = floor($secsleft / 3600);
$minsleft = floor(($secsleft / 60) % 60);
$secsleft = floor($secsleft % 60);

			$hoursleft = floor($secsleft / 3600);
$minsleft = floor(($secsleft / 60) % 60);
$secsleft = floor($secsleft % 60);





			error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft));
}


			error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft));
}


Zeile 6906Zeile 6926
			$failedtime = $attempts['loginlockoutexpiry'];
}
else

			$failedtime = $attempts['loginlockoutexpiry'];
}
else

		{

		{

			$failedtime = $mybb->cookies['lockoutexpiry'];
}


			$failedtime = $mybb->cookies['lockoutexpiry'];
}


Zeile 6934Zeile 6954
					"loginattempts" => 0,
"loginlockoutexpiry" => 0
), "uid='{$uid}'");

					"loginattempts" => 0,
"loginlockoutexpiry" => 0
), "uid='{$uid}'");

			}


			}


			// Wipe the cookie, no matter if a guest or a member
my_unsetcookie('lockoutexpiry');


			// Wipe the cookie, no matter if a guest or a member
my_unsetcookie('lockoutexpiry');


Zeile 6954Zeile 6974

/**
* Validates the format of an email address.


/**
* Validates the format of an email address.

 *

 *

 * @param string $email The string to check.
* @return boolean True when valid, false when invalid.
*/

 * @param string $email The string to check.
* @return boolean True when valid, false when invalid.
*/

Zeile 6973Zeile 6993
function email_already_in_use($email, $uid=0)
{
global $db;

function email_already_in_use($email, $uid=0)
{
global $db;





	$uid_string = "";
if($uid)
{

	$uid_string = "";
if($uid)
{

Zeile 7010Zeile 7030
		$setting['name'] = addcslashes($setting['name'], "\\'");
$setting['value'] = addcslashes($setting['value'], '\\"$');
$settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n";

		$setting['name'] = addcslashes($setting['name'], "\\'");
$setting['value'] = addcslashes($setting['value'], '\\"$');
$settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n";

	}


	}


	$settings = "<"."?php\n/*********************************\ \n  DO NOT EDIT THIS FILE, PLEASE USE\n  THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n";

file_put_contents(MYBB_ROOT.'inc/settings.php', $settings, LOCK_EX);

	$settings = "<"."?php\n/*********************************\ \n  DO NOT EDIT THIS FILE, PLEASE USE\n  THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n";

file_put_contents(MYBB_ROOT.'inc/settings.php', $settings, LOCK_EX);

Zeile 7030Zeile 7050
	global $mybb;

if($mybb->settings['minsearchword'] < 1)

	global $mybb;

if($mybb->settings['minsearchword'] < 1)

	{

	{

		$mybb->settings['minsearchword'] = 3;
}


		$mybb->settings['minsearchword'] = 3;
}


Zeile 7068Zeile 7088
				{
$split_words = preg_split("#\s{1,}#", $phrase, -1);
if(!is_array($split_words))

				{
$split_words = preg_split("#\s{1,}#", $phrase, -1);
if(!is_array($split_words))

					{

					{

						continue;
}
foreach($split_words as $word)

						continue;
}
foreach($split_words as $word)

Zeile 7085Zeile 7105
		}
}
// Otherwise just a simple search query with no phrases

		}
}
// Otherwise just a simple search query with no phrases

	else
{

	else
{

		$terms = htmlspecialchars_uni($terms);
$split_words = preg_split("#\s{1,}#", $terms, -1);
if(is_array($split_words))

		$terms = htmlspecialchars_uni($terms);
$split_words = preg_split("#\s{1,}#", $terms, -1);
if(is_array($split_words))

Zeile 7235Zeile 7255
		// Failed to read cache, see if we can rebuild it
$cache->update_bannedemails();
$banned_cache = $cache->read("bannedemails");

		// Failed to read cache, see if we can rebuild it
$cache->update_bannedemails();
$banned_cache = $cache->read("bannedemails");

	}


	}


	if(is_array($banned_cache) && !empty($banned_cache))
{
foreach($banned_cache as $banned_email)

	if(is_array($banned_cache) && !empty($banned_cache))
{
foreach($banned_cache as $banned_email)

Zeile 7460Zeile 7480
	)
{
return false;

	)
{
return false;

	}


	}


	$addresses = get_ip_by_hostname($url_components['host']);
$destination_address = $addresses[0];


	$addresses = get_ip_by_hostname($url_components['host']);
$destination_address = $addresses[0];


Zeile 7537Zeile 7557
			$curlopt[10203] = array(
$url_components['host'].':'.$url_components['port'].':'.$destination_address
);

			$curlopt[10203] = array(
$url_components['host'].':'.$url_components['port'].':'.$destination_address
);

 
		}

if(defined('CURLOPT_DISALLOW_USERNAME_IN_URL'))
{
$curlopt[CURLOPT_DISALLOW_USERNAME_IN_URL] = true;

		}

if(!empty($post_body))

		}

if(!empty($post_body))