Vergleich inc/functions.php - 1.8.10 - 1.8.17

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 322Zeile 322
/**
* Turn a unix timestamp in to a "friendly" date/time format for the user.
*

/**
* Turn a unix timestamp in to a "friendly" date/time format for the user.
*

 * @param string $format A date format according to PHP's date structure.

 * @param string $format A date format (either relative, normal or PHP's date() structure).

 * @param int $stamp The unix timestamp the date should be generated for.
* @param int|string $offset The offset in hours that should be applied to times. (timezones) Or an empty string to determine that automatically
* @param int $ty Whether or not to use today/yesterday formatting.

 * @param int $stamp The unix timestamp the date should be generated for.
* @param int|string $offset The offset in hours that should be applied to times. (timezones) Or an empty string to determine that automatically
* @param int $ty Whether or not to use today/yesterday formatting.

Zeile 380Zeile 380
	}

$todaysdate = $yesterdaysdate = '';

	}

$todaysdate = $yesterdaysdate = '';

	if($ty && ($format == $mybb->settings['dateformat'] || $format == 'relative'))

	if($ty && ($format == $mybb->settings['dateformat'] || $format == 'relative' || $format == 'normal'))

	{
$_stamp = TIME_NOW;
if($adodb == true)

	{
$_stamp = TIME_NOW;
if($adodb == true)

Zeile 400Zeile 400
	if($format == 'relative')
{
// Relative formats both date and time

	if($format == 'relative')
{
// Relative formats both date and time

 
		$real_date = $real_time = '';
if($adodb == true)
{
$real_date = adodb_date($mybb->settings['dateformat'], $stamp + ($offset * 3600));
$real_time = $mybb->settings['datetimesep'];
$real_time .= adodb_date($mybb->settings['timeformat'], $stamp + ($offset * 3600));
}
else
{
$real_date = gmdate($mybb->settings['dateformat'], $stamp + ($offset * 3600));
$real_time = $mybb->settings['datetimesep'];
$real_time .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600));
}


		if($ty != 2 && abs(TIME_NOW - $stamp) < 3600)
{
$diff = TIME_NOW - $stamp;
$relative = array('prefix' => '', 'minute' => 0, 'plural' => $lang->rel_minutes_plural, 'suffix' => $lang->rel_ago);

		if($ty != 2 && abs(TIME_NOW - $stamp) < 3600)
{
$diff = TIME_NOW - $stamp;
$relative = array('prefix' => '', 'minute' => 0, 'plural' => $lang->rel_minutes_plural, 'suffix' => $lang->rel_ago);


if($diff < 0)
{
$diff = abs($diff);
$relative['suffix'] = '';
$relative['prefix'] = $lang->rel_in;
}



if($diff < 0)
{
$diff = abs($diff);
$relative['suffix'] = '';
$relative['prefix'] = $lang->rel_in;
}


			$relative['minute'] = floor($diff / 60);

if($relative['minute'] <= 1)

			$relative['minute'] = floor($diff / 60);

if($relative['minute'] <= 1)

Zeile 426Zeile 440
				$relative['prefix'] = $lang->rel_less_than;
}


				$relative['prefix'] = $lang->rel_less_than;
}


			$date = $lang->sprintf($lang->rel_time, $relative['prefix'], $relative['minute'], $relative['plural'], $relative['suffix']);

			$date = $lang->sprintf($lang->rel_time, $relative['prefix'], $relative['minute'], $relative['plural'], $relative['suffix'], $real_date, $real_time);

		}
elseif($ty != 2 && abs(TIME_NOW - $stamp) < 43200)
{

		}
elseif($ty != 2 && abs(TIME_NOW - $stamp) < 43200)
{

Zeile 446Zeile 460
			{
$relative['hour'] = 1;
$relative['plural'] = $lang->rel_hours_single;

			{
$relative['hour'] = 1;
$relative['plural'] = $lang->rel_hours_single;

			}

$date = $lang->sprintf($lang->rel_time, $relative['prefix'], $relative['hour'], $relative['plural'], $relative['suffix']);
}

			}

$date = $lang->sprintf($lang->rel_time, $relative['prefix'], $relative['hour'], $relative['plural'], $relative['suffix'], $real_date, $real_time);
}

		else
{
if($ty)
{
if($todaysdate == $date)

		else
{
if($ty)
{
if($todaysdate == $date)

				{
$date = $lang->today;

				{
$date = $lang->sprintf($lang->today_rel, $real_date);

				}
else if($yesterdaysdate == $date)
{

				}
else if($yesterdaysdate == $date)
{

					$date = $lang->yesterday;

					$date = $lang->sprintf($lang->yesterday_rel, $real_date);

				}

				}

			}


			}


			$date .= $mybb->settings['datetimesep'];
if($adodb == true)

			$date .= $mybb->settings['datetimesep'];
if($adodb == true)

			{

			{

				$date .= adodb_date($mybb->settings['timeformat'], $stamp + ($offset * 3600));

				$date .= adodb_date($mybb->settings['timeformat'], $stamp + ($offset * 3600));

			}

			}

			else

			else

			{

			{

				$date .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600));
}

				$date .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600));
}

 
		}
}
elseif($format == 'normal')
{
// Normal format both date and time
if($ty != 2)
{
if($todaysdate == $date)
{
$date = $lang->today;
}
else if($yesterdaysdate == $date)
{
$date = $lang->yesterday;
}
}

$date .= $mybb->settings['datetimesep'];
if($adodb == true)
{
$date .= adodb_date($mybb->settings['timeformat'], $stamp + ($offset * 3600));
}
else
{
$date .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600));

		}
}
else

		}
}
else

Zeile 497Zeile 536
			else
{
$date = gmdate($format, $stamp + ($offset * 3600));

			else
{
$date = gmdate($format, $stamp + ($offset * 3600));

			}
}
}

			}
}
}


if(is_object($plugins))
{


if(is_object($plugins))
{

Zeile 782Zeile 821

eval("\$errorpage = \"".$templates->get("error")."\";");
output_page($errorpage);


eval("\$errorpage = \"".$templates->get("error")."\";");
output_page($errorpage);


exit;
}

/**


exit;
}

/**

 * Produce an error message for displaying inline on a page
*
* @param array $errors Array of errors to be shown

 * Produce an error message for displaying inline on a page
*
* @param array $errors Array of errors to be shown

Zeile 809Zeile 848
	}

// AJAX error message?

	}

// AJAX error message?

	if($mybb->get_input('ajax', MyBB::INPUT_INT))
{

	if($mybb->get_input('ajax', MyBB::INPUT_INT))
{

		// Send our headers.
@header("Content-type: application/json; charset={$lang->settings['charset']}");

if(empty($json_data))

		// Send our headers.
@header("Content-type: application/json; charset={$lang->settings['charset']}");

if(empty($json_data))

		{

		{

			echo json_encode(array("errors" => $errors));
}
else
{
echo json_encode(array_merge(array("errors" => $errors), $json_data));

			echo json_encode(array("errors" => $errors));
}
else
{
echo json_encode(array_merge(array("errors" => $errors), $json_data));

		}
exit;

		}
exit;

	}

$errorlist = '';

	}

$errorlist = '';

Zeile 846Zeile 885

$time = TIME_NOW;
$plugins->run_hooks("no_permission");


$time = TIME_NOW;
$plugins->run_hooks("no_permission");





	$noperm_array = array (
"nopermission" => '1',
"location1" => 0,

	$noperm_array = array (
"nopermission" => '1',
"location1" => 0,

Zeile 882Zeile 921
		switch($mybb->settings['username_method'])
{
case 0:

		switch($mybb->settings['username_method'])
{
case 0:

				$lang_username = $lang->username;

				$lang_username = $lang->username;

				break;
case 1:
$lang_username = $lang->username1;

				break;
case 1:
$lang_username = $lang->username1;

				break;

				break;

			case 2:
$lang_username = $lang->username2;

			case 2:
$lang_username = $lang->username2;

				break;

				break;

			default:
$lang_username = $lang->username;
break;

			default:
$lang_username = $lang->username;
break;

		}

		}

		eval("\$errorpage = \"".$templates->get("error_nopermission")."\";");
}


		eval("\$errorpage = \"".$templates->get("error_nopermission")."\";");
}


Zeile 917Zeile 956
	$plugins->run_hooks("redirect", $redirect_args);

if($mybb->get_input('ajax', MyBB::INPUT_INT))

	$plugins->run_hooks("redirect", $redirect_args);

if($mybb->get_input('ajax', MyBB::INPUT_INT))

	{

	{

		// Send our headers.
//@header("Content-type: text/html; charset={$lang->settings['charset']}");
$data = "<script type=\"text/javascript\">\n";

		// Send our headers.
//@header("Content-type: text/html; charset={$lang->settings['charset']}");
$data = "<script type=\"text/javascript\">\n";

Zeile 940Zeile 979
	if(!$message)
{
$message = $lang->redirect;

	if(!$message)
{
$message = $lang->redirect;

	}


	}


	$time = TIME_NOW;
$timenow = my_date('relative', $time);

	$time = TIME_NOW;
$timenow = my_date('relative', $time);





	if(!$title)
{
$title = $mybb->settings['bbname'];

	if(!$title)
{
$title = $mybb->settings['bbname'];

Zeile 952Zeile 991

// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest, or they are forced.
if($force_redirect == true || ($mybb->settings['redirects'] == 1 && ($mybb->user['showredirect'] == 1 || !$mybb->user['uid'])))


// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest, or they are forced.
if($force_redirect == true || ($mybb->settings['redirects'] == 1 && ($mybb->user['showredirect'] == 1 || !$mybb->user['uid'])))

	{

	{

		$url = str_replace("&amp;", "&", $url);
$url = htmlspecialchars_uni($url);


		$url = str_replace("&amp;", "&", $url);
$url = htmlspecialchars_uni($url);


Zeile 966Zeile 1005

run_shutdown();



run_shutdown();


		if(!my_validate_url($url, true))

		if(!my_validate_url($url, true, true))

		{
header("Location: {$mybb->settings['bburl']}/{$url}");
}

		{
header("Location: {$mybb->settings['bburl']}/{$url}");
}

Zeile 977Zeile 1016
	}

exit;

	}

exit;

}

/**

}

/**

 * Generate a listing of page - pagination
*
* @param int $count The number of items

 * Generate a listing of page - pagination
*
* @param int $count The number of items

Zeile 992Zeile 1031
function multipage($count, $perpage, $page, $url, $breadcrumb=false)
{
global $theme, $templates, $lang, $mybb;

function multipage($count, $perpage, $page, $url, $breadcrumb=false)
{
global $theme, $templates, $lang, $mybb;





	if($count <= $perpage)
{
return '';
}

	if($count <= $perpage)
{
return '';
}

 

$page = (int)$page;


$url = str_replace("&amp;", "&", $url);
$url = htmlspecialchars_uni($url);


$url = str_replace("&amp;", "&", $url);
$url = htmlspecialchars_uni($url);

Zeile 1102Zeile 1143
		eval("\$jumptopage = \"".$templates->get("multipage_jump_page")."\";");
}


		eval("\$jumptopage = \"".$templates->get("multipage_jump_page")."\";");
}


	$lang->multipage_pages = $lang->sprintf($lang->multipage_pages, $pages);

	$multipage_pages = $lang->sprintf($lang->multipage_pages, $pages);


if($breadcrumb == true)
{


if($breadcrumb == true)
{

Zeile 1162Zeile 1203
/**
* Fetch the permissions for a specific user
*

/**
* Fetch the permissions for a specific user
*

 * @param int $uid The user ID

 * @param int $uid The user ID, if no user ID is provided then current user's ID will be considered.

 * @return array Array of user permissions for the specified user
*/

 * @return array Array of user permissions for the specified user
*/

function user_permissions($uid=0)

function user_permissions($uid=null)

{
global $mybb, $cache, $groupscache, $user_cache;

// If no user id is specified, assume it is the current user

{
global $mybb, $cache, $groupscache, $user_cache;

// If no user id is specified, assume it is the current user

 
	if($uid === null)
{
$uid = $mybb->user['uid'];
}

// Its a guest. Return the group permissions directly from cache

	if($uid == 0)
{

	if($uid == 0)
{

		$uid = $mybb->user['uid'];

		return $groupscache[1];

	}

// User id does not match current user, fetch permissions
if($uid != $mybb->user['uid'])
{
// We've already cached permissions for this user, return them.

	}

// User id does not match current user, fetch permissions
if($uid != $mybb->user['uid'])
{
// We've already cached permissions for this user, return them.

		if($user_cache[$uid]['permissions'])

		if(!empty($user_cache[$uid]['permissions']))

		{
return $user_cache[$uid]['permissions'];
}

// This user was not already cached, fetch their user information.

		{
return $user_cache[$uid]['permissions'];
}

// This user was not already cached, fetch their user information.

		if(!$user_cache[$uid])

		if(empty($user_cache[$uid]))

		{
$user_cache[$uid] = get_user($uid);
}

		{
$user_cache[$uid] = get_user($uid);
}

Zeile 1774Zeile 1821
	$iconlist = '';
$no_icons_checked = " checked=\"checked\"";
// read post icons from cache, and sort them accordingly

	$iconlist = '';
$no_icons_checked = " checked=\"checked\"";
// read post icons from cache, and sort them accordingly

	$posticons_cache = $cache->read("posticons");

	$posticons_cache = (array)$cache->read("posticons");

	$posticons = array();
foreach($posticons_cache as $posticon)
{

	$posticons = array();
foreach($posticons_cache as $posticon)
{

Zeile 1820Zeile 1867
 * @param string $value The cookie value.
* @param int|string $expires The timestamp of the expiry date.
* @param boolean $httponly True if setting a HttpOnly cookie (supported by the majority of web browsers)

 * @param string $value The cookie value.
* @param int|string $expires The timestamp of the expiry date.
* @param boolean $httponly True if setting a HttpOnly cookie (supported by the majority of web browsers)

 
 * @param string $samesite The samesite attribute to prevent CSRF.

 */

 */

function my_setcookie($name, $value="", $expires="", $httponly=false)

function my_setcookie($name, $value="", $expires="", $httponly=false, $samesite="")

{
global $mybb;


{
global $mybb;


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

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

 
	}

if($samesite != "" && $mybb->settings['cookiesamesiteflag'])
{
$samesite = strtolower($samesite);

if($samesite == "lax" || $samesite == "strict")
{
$cookie .= "; SameSite=".$samesite;
}

	}

if($mybb->settings['cookiesecureflag'])

	}

if($mybb->settings['cookiesecureflag'])

Zeile 2003Zeile 2061
			$str = substr($str, 1);
}
else if($type == 'N' && $str[1] == ';')

			$str = substr($str, 1);
}
else if($type == 'N' && $str[1] == ';')

		{

		{

			$value = null;
$str = substr($str, 2);
}

			$value = null;
$str = substr($str, 2);
}

Zeile 2037Zeile 2095
			// object or unknown/malformed type
return false;
}

			// object or unknown/malformed type
return false;
}





		switch($state)
{
case 3: // in array, expecting value or another array

		switch($state)
{
case 3: // in array, expecting value or another array

Zeile 2053Zeile 2111
					$list[$key] = array();
$list = &$list[$key];
$expected[] = $expectedLength;

					$list[$key] = array();
$list = &$list[$key];
$expected[] = $expectedLength;

					$state = 2;
break;
}

					$state = 2;
break;
}

				if($type != '}')
{
$list[$key] = $value;
$state = 2;
break;
}

				if($type != '}')
{
$list[$key] = $value;
$state = 2;
break;
}





				// missing array value
return false;


				// missing array value
return false;


Zeile 2070Zeile 2128
				if($type == '}')
{
if(count($list) < end($expected))

				if($type == '}')
{
if(count($list) < end($expected))

					{

					{

						// array size less than expected
return false;
}

						// array size less than expected
return false;
}

Zeile 2203Zeile 2261
	if(is_string($value))
{
return 's:'.strlen($value).':"'.$value.'";';

	if(is_string($value))
{
return 's:'.strlen($value).':"'.$value.'";';

	}


	}


	if(is_array($value))
{
$out = '';

	if(is_array($value))
{
$out = '';

Zeile 2238Zeile 2296

$out = _safe_serialize($value);
if(isset($mbIntEnc))


$out = _safe_serialize($value);
if(isset($mbIntEnc))

	{

	{

		mb_internal_encoding($mbIntEnc);
}


		mb_internal_encoding($mbIntEnc);
}


Zeile 2263Zeile 2321
		{
// 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();

			$serverload[0] = round($serverload[0], 4);
}

			$serverload[0] = round($serverload[0], 4);
}

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

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

		{

		{

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

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

Zeile 2404Zeile 2462
					}
// Less than 0? That's bad
elseif($new_stats[$counter] < 0)

					}
// Less than 0? That's bad
elseif($new_stats[$counter] < 0)

					{

					{

						$new_stats[$counter] = 0;
}
}

						$new_stats[$counter] = 0;
}
}

Zeile 2648Zeile 2706
	// 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);


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


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?

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

Zeile 2684Zeile 2742
	if(count($update_query) > 0)
{
$db->update_query("threads", $update_query, "tid='{$tid}'");

	if(count($update_query) > 0)
{
$db->update_query("threads", $update_query, "tid='{$tid}'");

	}
}

	}
}


/**
* Update the first post and lastpost data for a specific thread


/**
* Update the first post and lastpost data for a specific thread

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

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

	}


	}


	if(empty($lastpost['username']))

	if(empty($lastpost['username']))

	{

	{

		$lastpost['username'] = $lastpost['postusername'];

		$lastpost['username'] = $lastpost['postusername'];

	}

	}


if(empty($lastpost['dateline']))
{


if(empty($lastpost['dateline']))
{

Zeile 2747Zeile 2805

$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']);





	$update_array = array(
'firstpost' => (int)$firstpost['pid'],
'username' => $firstpost['username'],

	$update_array = array(
'firstpost' => (int)$firstpost['pid'],
'username' => $firstpost['username'],

Zeile 2778Zeile 2836
	// Fetch above counters for this user
$query = $db->simple_select("users", implode(",", $counters), "uid='{$uid}'");
$user = $db->fetch_array($query);

	// Fetch above counters for this user
$query = $db->simple_select("users", implode(",", $counters), "uid='{$uid}'");
$user = $db->fetch_array($query);





	foreach($counters as $counter)
{
if(array_key_exists($counter, $changes))

	foreach($counters as $counter)
{
if(array_key_exists($counter, $changes))

Zeile 3011Zeile 3069
 */
function format_name($username, $usergroup, $displaygroup=0)
{

 */
function format_name($username, $usergroup, $displaygroup=0)
{

	global $groupscache, $cache;

	global $groupscache, $cache, $plugins;





	if(!is_array($groupscache))
{
$groupscache = $cache->read("usergroups");
}

if($displaygroup != 0)
{
$usergroup = $displaygroup;
}

$ugroup = $groupscache[$usergroup];
$format = $ugroup['namestyle'];
$userin = substr_count($format, "{username}");

	static $formattednames = array();

















	if($userin == 0)

	if(!isset($formattednames[$username]))

	{

	{

 
		if(!is_array($groupscache))
{
$groupscache = $cache->read("usergroups");
}

if($displaygroup != 0)
{
$usergroup = $displaygroup;
}


		$format = "{username}";

		$format = "{username}";

	}

$format = stripslashes($format);

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

/**




















if(isset($groupscache[$usergroup]))
{
$ugroup = $groupscache[$usergroup];

if(strpos($ugroup['namestyle'], "{username}") !== false)
{
$format = $ugroup['namestyle'];
}
}

$format = stripslashes($format);

$parameters = compact('username', 'usergroup', 'displaygroup', 'format');

$parameters = $plugins->run_hooks('format_name', $parameters);

$format = $parameters['format'];

$formattednames[$username] = str_replace("{username}", $username, $format);
}

return $formattednames[$username];
}

/**

 * Formats an avatar to a certain dimension
*
* @param string $avatar The avatar file name

 * Formats an avatar to a certain dimension
*
* @param string $avatar The avatar file name

Zeile 3285Zeile 3359
						$image = str_replace(array('\\', '"'), array('\\\\', '\"'), $image);

if(!$mybb->settings['smilieinserter'] || !$mybb->settings['smilieinsertercols'] || !$mybb->settings['smilieinsertertot'] || !$smilie['showclickable'])

						$image = str_replace(array('\\', '"'), array('\\\\', '\"'), $image);

if(!$mybb->settings['smilieinserter'] || !$mybb->settings['smilieinsertercols'] || !$mybb->settings['smilieinsertertot'] || !$smilie['showclickable'])

						{
$hiddensmilies .= '"'.$find.'": "'.$image.'",';

						{
$hiddensmilies .= '"'.$find.'": "'.$image.'",';

						}
elseif($i < $mybb->settings['smilieinsertertot'])
{

						}
elseif($i < $mybb->settings['smilieinsertertot'])
{

Zeile 3333Zeile 3407
			if($mybb->settings['allowcolormycode'] == 1)
{
$color = "color,";

			if($mybb->settings['allowcolormycode'] == 1)
{
$color = "color,";

			}

			}


if($mybb->settings['allowfontmycode'] == 1 || $mybb->settings['allowsizemycode'] == 1 || $mybb->settings['allowcolormycode'] == 1)
{
$removeformat = "removeformat|";


if($mybb->settings['allowfontmycode'] == 1 || $mybb->settings['allowsizemycode'] == 1 || $mybb->settings['allowcolormycode'] == 1)
{
$removeformat = "removeformat|";

			}


			}


			if($mybb->settings['allowemailmycode'] == 1)

			if($mybb->settings['allowemailmycode'] == 1)

			{

			{

				$email = "email,";
}

if($mybb->settings['allowlinkmycode'] == 1)
{
$link = "link,unlink";

				$email = "email,";
}

if($mybb->settings['allowlinkmycode'] == 1)
{
$link = "link,unlink";

			}


			}


			if($mybb->settings['allowlistmycode'] == 1)

			if($mybb->settings['allowlistmycode'] == 1)

			{

			{

				$list = "bulletlist,orderedlist|";

				$list = "bulletlist,orderedlist|";

			}

			}


if($mybb->settings['allowcodemycode'] == 1)
{
$code = "code,php,";


if($mybb->settings['allowcodemycode'] == 1)
{
$code = "code,php,";

			}


			}


			if($mybb->user['sourceeditor'] == 1)
{
$sourcemode = "MyBBEditor.sourceMode(true);";

			if($mybb->user['sourceeditor'] == 1)
{
$sourcemode = "MyBBEditor.sourceMode(true);";

			}


			}


			eval("\$codeinsert = \"".$templates->get("codebuttons")."\";");
}
}

			eval("\$codeinsert = \"".$templates->get("codebuttons")."\";");
}
}

Zeile 3410Zeile 3484

$getmore = '';
if($mybb->settings['smilieinsertertot'] >= $smiliecount)


$getmore = '';
if($mybb->settings['smilieinsertertot'] >= $smiliecount)

			{

			{

				$mybb->settings['smilieinsertertot'] = $smiliecount;
}
else if($mybb->settings['smilieinsertertot'] < $smiliecount)

				$mybb->settings['smilieinsertertot'] = $smiliecount;
}
else if($mybb->settings['smilieinsertertot'] < $smiliecount)

Zeile 3458Zeile 3532
			{
$colspan = $mybb->settings['smilieinsertercols'] - $counter;
eval("\$smilies .= \"".$templates->get("smilieinsert_row_empty")."\";");

			{
$colspan = $mybb->settings['smilieinsertercols'] - $counter;
eval("\$smilies .= \"".$templates->get("smilieinsert_row_empty")."\";");

			}


			}


			eval("\$clickablesmilies = \"".$templates->get("smilieinsert")."\";");
}
else
{
$clickablesmilies = "";

			eval("\$clickablesmilies = \"".$templates->get("smilieinsert")."\";");
}
else
{
$clickablesmilies = "";

		}
}

		}
}

	else
{
$clickablesmilies = "";

	else
{
$clickablesmilies = "";

	}


	}


	return $clickablesmilies;
}


	return $clickablesmilies;
}


Zeile 3489Zeile 3563
	if(is_array($prefixes_cache))
{
if($pid > 0 && is_array($prefixes_cache[$pid]))

	if(is_array($prefixes_cache))
{
if($pid > 0 && is_array($prefixes_cache[$pid]))

		{

		{

			return $prefixes_cache[$pid];
}

return $prefixes_cache;
}

			return $prefixes_cache[$pid];
}

return $prefixes_cache;
}





	$prefix_cache = $cache->read("threadprefixes");

if(!is_array($prefix_cache))

	$prefix_cache = $cache->read("threadprefixes");

if(!is_array($prefix_cache))

Zeile 3506Zeile 3580
		if(!is_array($prefix_cache))
{
return array();

		if(!is_array($prefix_cache))
{
return array();

		}
}

		}
}


$prefixes_cache = array();
foreach($prefix_cache as $prefix)


$prefixes_cache = array();
foreach($prefix_cache as $prefix)

Zeile 3603Zeile 3677
		if($prefix['pid'] == $selected_pid)
{
$selected = " selected=\"selected\"";

		if($prefix['pid'] == $selected_pid)
{
$selected = " selected=\"selected\"";

		}


		}


		$prefix['prefix'] = htmlspecialchars_uni($prefix['prefix']);
eval("\$prefixselect_prefix .= \"".$templates->get("post_prefixselect_prefix")."\";");
}

		$prefix['prefix'] = htmlspecialchars_uni($prefix['prefix']);
eval("\$prefixselect_prefix .= \"".$templates->get("post_prefixselect_prefix")."\";");
}

Zeile 3781Zeile 3855
	{
$pid = (int)$data['pid'];
unset($data['pid']);

	{
$pid = (int)$data['pid'];
unset($data['pid']);

 
	}

$tids = array();
if(isset($data['tids']))
{
$tids = (array)$data['tids'];
unset($data['tids']);

	}

// Any remaining extra data - we my_serialize and insert in to its own column
if(is_array($data))
{
$data = my_serialize($data);

	}

// Any remaining extra data - we my_serialize and insert in to its own column
if(is_array($data))
{
$data = my_serialize($data);

	}


	}


	$sql_array = array(
"uid" => (int)$mybb->user['uid'],
"dateline" => TIME_NOW,

	$sql_array = array(
"uid" => (int)$mybb->user['uid'],
"dateline" => TIME_NOW,

Zeile 3799Zeile 3880
		"data" => $db->escape_string($data),
"ipaddress" => $db->escape_binary($session->packedip)
);

		"data" => $db->escape_string($data),
"ipaddress" => $db->escape_binary($session->packedip)
);

	$db->insert_query("moderatorlog", $sql_array);


















if($tids)
{
$multiple_sql_array = array();

foreach($tids as $tid)
{
$sql_array['tid'] = (int)$tid;
$multiple_sql_array[] = $sql_array;
}

$db->insert_query_multiple("moderatorlog", $multiple_sql_array);
}
else
{
$db->insert_query("moderatorlog", $sql_array);
}

}

/**

}

/**

Zeile 4675Zeile 4772
	$stamp %= $msecs;
$seconds = $stamp;


	$stamp %= $msecs;
$seconds = $stamp;


	if($years == 1)


	// Prevent gross over accuracy ($options parameter will override these)
if($years > 0)

	{

	{

		$nicetime['years'] = "1".$lang_year;






		$options = array_merge(array(
'days' => false,
'hours' => false,
'minutes' => false,
'seconds' => false
), $options);

	}

	}

	else if($years > 1)

	elseif($months > 0)

	{

	{

		$nicetime['years'] = $years.$lang_years;





		$options = array_merge(array(
'hours' => false,
'minutes' => false,
'seconds' => false
), $options);

	}

	}


if($months == 1)
{
$nicetime['months'] = "1".$lang_month;
}
else if($months > 1)
{
$nicetime['months'] = $months.$lang_months;
}

if($weeks == 1)
{
$nicetime['weeks'] = "1".$lang_week;
}
else if($weeks > 1)
{
$nicetime['weeks'] = $weeks.$lang_weeks;
}

if($days == 1)
{
$nicetime['days'] = "1".$lang_day;



























	elseif($weeks > 0)
{
$options = array_merge(array(
'minutes' => false,
'seconds' => false
), $options);
}
elseif($days > 0)
{
$options = array_merge(array(
'seconds' => false
), $options);
}

if(!isset($options['years']) || $options['years'] !== false)
{
if($years == 1)
{
$nicetime['years'] = "1".$lang_year;
}
else if($years > 1)
{
$nicetime['years'] = $years.$lang_years;
}
}

if(!isset($options['months']) || $options['months'] !== false)
{
if($months == 1)
{
$nicetime['months'] = "1".$lang_month;
}
else if($months > 1)
{
$nicetime['months'] = $months.$lang_months;
}
}

if(!isset($options['weeks']) || $options['weeks'] !== false)
{
if($weeks == 1)
{
$nicetime['weeks'] = "1".$lang_week;
}
else if($weeks > 1)
{
$nicetime['weeks'] = $weeks.$lang_weeks;
}

	}

	}

	else if($days > 1)



if(!isset($options['days']) || $options['days'] !== false)

	{

	{

		$nicetime['days'] = $days.$lang_days;








		if($days == 1)
{
$nicetime['days'] = "1".$lang_day;
}
else if($days > 1)
{
$nicetime['days'] = $days.$lang_days;
}

	}

if(!isset($options['hours']) || $options['hours'] !== false)

	}

if(!isset($options['hours']) || $options['hours'] !== false)

Zeile 4740Zeile 4881
		if($seconds == 1)
{
$nicetime['seconds'] = "1".$lang_second;

		if($seconds == 1)
{
$nicetime['seconds'] = "1".$lang_second;

		}

		}

		else if($seconds > 1)
{
$nicetime['seconds'] = $seconds.$lang_seconds;

		else if($seconds > 1)
{
$nicetime['seconds'] = $seconds.$lang_seconds;

Zeile 4750Zeile 4891
	if(is_array($nicetime))
{
return implode(", ", $nicetime);

	if(is_array($nicetime))
{
return implode(", ", $nicetime);

	}
}

	}
}


/**
* Select an alternating row colour based on the previous call to this function


/**
* Select an alternating row colour based on the previous call to this function

Zeile 4785Zeile 4926
 * @return bool
*/
function join_usergroup($uid, $joingroup)

 * @return bool
*/
function join_usergroup($uid, $joingroup)

{

{

	global $db, $mybb;

if($uid == $mybb->user['uid'])

	global $db, $mybb;

if($uid == $mybb->user['uid'])

	{

	{

		$user = $mybb->user;
}
else
{
$query = $db->simple_select("users", "additionalgroups, usergroup", "uid='".(int)$uid."'");
$user = $db->fetch_array($query);

		$user = $mybb->user;
}
else
{
$query = $db->simple_select("users", "additionalgroups, usergroup", "uid='".(int)$uid."'");
$user = $db->fetch_array($query);

	}


	}


	// Build the new list of additional groups for this user and make sure they're in the right format
$usergroups = "";
$usergroups = $user['additionalgroups'].",".$joingroup;

	// Build the new list of additional groups for this user and make sure they're in the right format
$usergroups = "";
$usergroups = $user['additionalgroups'].",".$joingroup;

Zeile 4807Zeile 4948
	if(is_array($groups))
{
$comma = '';

	if(is_array($groups))
{
$comma = '';

		foreach($groups as $gid)

		foreach($groups as $gid)

		{
if(trim($gid) != "" && $gid != $user['usergroup'] && !isset($donegroup[$gid]))
{

		{
if(trim($gid) != "" && $gid != $user['usergroup'] && !isset($donegroup[$gid]))
{

Zeile 4823Zeile 4964
	{
$db->update_query("users", array('additionalgroups' => $groupslist), "uid='".(int)$uid."'");
return true;

	{
$db->update_query("users", array('additionalgroups' => $groupslist), "uid='".(int)$uid."'");
return true;

	}
else
{
return false;
}
}


	}
else
{
return false;
}
}


/**
* Remove a user from a specific additional user group
*

/**
* Remove a user from a specific additional user group
*

Zeile 4874Zeile 5015
	");

$cache->update_moderators();

	");

$cache->update_moderators();

}

/**

}

/**

 * Get the current location taking in to account different web serves and systems
*
* @param boolean $fields True to return as "hidden" fields

 * Get the current location taking in to account different web serves and systems
*
* @param boolean $fields True to return as "hidden" fields

Zeile 5055Zeile 5196
		if($footer == true)
{
eval("\$themeselect = \"".$templates->get("footer_themeselector")."\";");

		if($footer == true)
{
eval("\$themeselect = \"".$templates->get("footer_themeselector")."\";");

		}
else
{

		}
else
{

			eval("\$themeselect = \"".$templates->get("usercp_themeselector")."\";");
}

			eval("\$themeselect = \"".$templates->get("usercp_themeselector")."\";");
}





		return $themeselect;
}
else
{
return false;

		return $themeselect;
}
else
{
return false;

	}
}

/**

	}
}

/**

 * Get the theme data of a theme id.
*
* @param int $tid The theme id of the theme.

 * Get the theme data of a theme id.
*
* @param int $tid The theme id of the theme.

Zeile 5080Zeile 5221
	global $tcache, $db;

if(!is_array($tcache))

	global $tcache, $db;

if(!is_array($tcache))

	{

	{

		$query = $db->simple_select('themes', 'tid, name, pid, allowedgroups', "pid!='0'");

		$query = $db->simple_select('themes', 'tid, name, pid, allowedgroups', "pid!='0'");





		while($theme = $db->fetch_array($query))
{
$tcache[$theme['pid']][$theme['tid']] = $theme;
}
}

		while($theme = $db->fetch_array($query))
{
$tcache[$theme['pid']][$theme['tid']] = $theme;
}
}





	$s_theme = false;

foreach($tcache as $themes)

	$s_theme = false;

foreach($tcache as $themes)

	{

	{

		foreach($themes as $theme)
{
if($tid == $theme['tid'])

		foreach($themes as $theme)
{
if($tid == $theme['tid'])

Zeile 5137Zeile 5278
	}

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

Zeile 5147Zeile 5288
		if(isset($parts[1]))
{
$decimals = my_strlen($parts[1]);

		if(isset($parts[1]))
{
$decimals = my_strlen($parts[1]);

		}
else

		}
else

		{
$decimals = 0;
}

		{
$decimals = 0;
}

Zeile 5344Zeile 5485
		$lang->month_11,
$lang->month_12
);

		$lang->month_11,
$lang->month_12
);



 

// This needs to be in this specific order
$find = array(


// This needs to be in this specific order
$find = array(

Zeile 5373Zeile 5513
		'&#70;',
'&#108;',
'&#77;',

		'&#70;',
'&#108;',
'&#77;',

	);

	);


$bdays = str_replace($find, $html, $bdays);
$bmonth = str_replace($find, $html, $bmonth);


$bdays = str_replace($find, $html, $bdays);
$bmonth = str_replace($find, $html, $bmonth);

Zeile 5420Zeile 5560
	list($day, $month, $year) = explode("-", my_date("j-n-Y", TIME_NOW, 0, 0));

$age = $year-$bday[2];

	list($day, $month, $year) = explode("-", my_date("j-n-Y", TIME_NOW, 0, 0));

$age = $year-$bday[2];





	if(($month == $bday[1] && $day < $bday[0]) || $month < $bday[1])
{
--$age;

	if(($month == $bday[1] && $day < $bday[0]) || $month < $bday[1])
{
--$age;

Zeile 5669Zeile 5809
function unhtmlentities($string)
{
// Replace numeric entities

function unhtmlentities($string)
{
// Replace numeric entities

	$string = preg_replace_callback('~&#x([0-9a-f]+);~i', create_function('$matches', 'return unichr(hexdec($matches[1]));'), $string);
$string = preg_replace_callback('~&#([0-9]+);~', create_function('$matches', 'return unichr($matches[1]);'), $string);

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


// Replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);


// Replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);

Zeile 5710Zeile 5850
	{
return false;
}

	{
return false;
}

 
}

/**
* Returns any ascii to it's character (utf-8 safe).
*
* @param array $matches Matches.
* @return string|bool The characterized ascii. False on failure
*/
function unichr_callback1($matches)
{
return unichr(hexdec($matches[1]));
}

/**
* Returns any ascii to it's character (utf-8 safe).
*
* @param array $matches Matches.
* @return string|bool The characterized ascii. False on failure
*/
function unichr_callback2($matches)
{
return unichr($matches[1]);

}

/**

}

/**

Zeile 5733Zeile 5895
 * @return string The event date.
*/
function get_event_date($event)

 * @return string The event date.
*/
function get_event_date($event)

{

{

	global $mybb;

$event_date = explode("-", $event['date']);

	global $mybb;

$event_date = explode("-", $event['date']);

Zeile 5752Zeile 5914
function get_profile_link($uid=0)
{
$link = str_replace("{uid}", $uid, PROFILE_URL);

function get_profile_link($uid=0)
{
$link = str_replace("{uid}", $uid, PROFILE_URL);

	return htmlspecialchars_uni($link);
}


	return htmlspecialchars_uni($link);
}


/**
* Get the announcement link.
*

/**
* Get the announcement link.
*

Zeile 5783Zeile 5945
	if(!$username && $uid == 0)
{
// Return Guest phrase for no UID, no guest nickname

	if(!$username && $uid == 0)
{
// Return Guest phrase for no UID, no guest nickname

		return $lang->guest;

		return htmlspecialchars_uni($lang->guest);

	}
elseif($uid == 0)
{

	}
elseif($uid == 0)
{

Zeile 5796Zeile 5958
		if(!empty($target))
{
$target = " target=\"{$target}\"";

		if(!empty($target))
{
$target = " target=\"{$target}\"";

		}


		}


		if(!empty($onclick))
{
$onclick = " onclick=\"{$onclick}\"";

		if(!empty($onclick))
{
$onclick = " onclick=\"{$onclick}\"";

Zeile 5825Zeile 5987
	else
{
$link = str_replace("{fid}", $fid, FORUM_URL);

	else
{
$link = str_replace("{fid}", $fid, FORUM_URL);

		return htmlspecialchars_uni($link);
}

		return htmlspecialchars_uni($link);
}

}

/**

}

/**

Zeile 5840Zeile 6002
function get_thread_link($tid, $page=0, $action='')
{
if($page > 1)

function get_thread_link($tid, $page=0, $action='')
{
if($page > 1)

	{
if($action)
{

	{
if($action)
{

			$link = THREAD_URL_ACTION;
$link = str_replace("{action}", $action, $link);
}

			$link = THREAD_URL_ACTION;
$link = str_replace("{action}", $action, $link);
}

Zeile 5888Zeile 6050
	else
{
$link = str_replace("{pid}", $pid, POST_URL);

	else
{
$link = str_replace("{pid}", $pid, POST_URL);

		return htmlspecialchars_uni($link);

		return htmlspecialchars_uni($link);

	}
}


	}
}


Zeile 5920Zeile 6082
		$link = str_replace("{month}", $month, CALENDAR_URL_DAY);
$link = str_replace("{year}", $year, $link);
$link = str_replace("{day}", $day, $link);

		$link = str_replace("{month}", $month, CALENDAR_URL_DAY);
$link = str_replace("{year}", $year, $link);
$link = str_replace("{day}", $day, $link);

		$link = str_replace("{calendar}", $calendar, $link);
return htmlspecialchars_uni($link);
}

		$link = str_replace("{calendar}", $calendar, $link);
return htmlspecialchars_uni($link);
}

	else if($month > 0)
{
$link = str_replace("{month}", $month, CALENDAR_URL_MONTH);

	else if($month > 0)
{
$link = str_replace("{month}", $month, CALENDAR_URL_MONTH);

Zeile 6171Zeile 6333
	global $forum_cache, $cache;

if(!$forum_cache)

	global $forum_cache, $cache;

if(!$forum_cache)

	{

	{

		cache_forums();
}


		cache_forums();
}


Zeile 6203Zeile 6365
 * @param bool $fatal (Optional) Stop execution if it finds an error with the login. Default is True
* @return bool|int Number of logins when success, false if failed.
*/

 * @param bool $fatal (Optional) Stop execution if it finds an error with the login. Default is True
* @return bool|int Number of logins when success, false if failed.
*/

function login_attempt_check($fatal = true)

function login_attempt_check($uid = 0, $fatal = true)

{

{

	global $mybb, $lang, $session, $db;

	global $mybb, $lang, $db;





	if($mybb->settings['failedlogincount'] == 0)






	$attempts = array();
$uid = (int)$uid;
$now = TIME_NOW;

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

	{

	{

		return 1;
}
// Note: Number of logins is defaulted to 1, because using 0 seems to clear cookie data. Not really a problem as long as we account for 1 being default.

// Use cookie if possible, otherwise use session
// Find better solution to prevent clearing cookies
$loginattempts = 0;
$failedlogin = 0;

if(!empty($mybb->cookies['loginattempts']))
{
$loginattempts = $mybb->cookies['loginattempts'];
}

if(!empty($mybb->cookies['failedlogin']))
{
$failedlogin = $mybb->cookies['failedlogin'];
}

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





















	// Work out if the user has had more than the allowed number of login attempts
if($loginattempts > $mybb->settings['failedlogincount'])
{
// If so, then we need to work out if they can try to login again
// Some maths to work out how long they have left and display it to them
$now = TIME_NOW;

if(empty($mybb->cookies['failedlogin']))
{
$failedtime = $now;
}
else
{
$failedtime = $mybb->cookies['failedlogin'];
}

$secondsleft = $mybb->settings['failedlogintime'] * 60 + $failedtime - $now;
$hoursleft = floor($secondsleft / 3600);
$minsleft = floor(($secondsleft / 60) % 60);
$secsleft = floor($secondsleft % 60);

// This value will be empty the first time the user doesn't login in, set it
if(empty($failedlogin))
{
my_setcookie('failedlogin', $now);
if($fatal)
{
error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft));
}

return false;

		if($attempts['loginattempts'] <= 0)
{
return 0;





























		}

		}

 
	}
// This user has a cookie lockout, show waiting time
elseif($mybb->cookies['lockoutexpiry'] && $mybb->cookies['lockoutexpiry'] > $now)
{
if($fatal)
{
$secsleft = (int)($mybb->cookies['lockoutexpiry'] - $now);
$hoursleft = floor($secsleft / 3600);
$minsleft = floor(($secsleft / 60) % 60);
$secsleft = floor($secsleft % 60);





		// Work out if the user has waited long enough before letting them login again
if($mybb->cookies['failedlogin'] < ($now - $mybb->settings['failedlogintime'] * 60))
{
my_setcookie('loginattempts', 1);
my_unsetcookie('failedlogin');
if($mybb->user['uid'] != 0)
{
$update_array = array(
'loginattempts' => 1
);
$db->update_query("users", $update_array, "uid = '{$mybb->user['uid']}'");
}
return 1;
}
// Not waited long enough
else if($mybb->cookies['failedlogin'] > ($now - $mybb->settings['failedlogintime'] * 60))












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

return false;
}

if($mybb->settings['failedlogincount'] > 0 && $attempts['loginattempts'] >= $mybb->settings['failedlogincount'])
{
// Set the expiry dateline if not set yet
if($attempts['loginlockoutexpiry'] == 0)
{
$attempts['loginlockoutexpiry'] = $now + ((int)$mybb->settings['failedlogintime'] * 60);

// Add a cookie lockout. This is used to prevent access to the login page immediately.
// A deep lockout is issued if he tries to login into a locked out account
my_setcookie('lockoutexpiry', $attempts['loginlockoutexpiry']);

$db->update_query("users", array(
"loginlockoutexpiry" => $attempts['loginlockoutexpiry']
), "uid='{$uid}'");
}

if(empty($mybb->cookies['lockoutexpiry']))
{
$failedtime = $attempts['loginlockoutexpiry'];
}
else

		{

		{

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

// Are we still locked out?
if($attempts['loginlockoutexpiry'] > $now)
{

			if($fatal)
{

			if($fatal)
{

 
				$secsleft = (int)($attempts['loginlockoutexpiry'] - $now);
$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));

			}


			}


			return false;
}

			return false;
}

	}


















		// Unlock if enough time has passed
else {

if($uid > 0)
{
$db->update_query("users", array(
"loginattempts" => 0,
"loginlockoutexpiry" => 0
), "uid='{$uid}'");
}

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

return 0;
}
}


	// User can attempt another login

	// User can attempt another login

	return $loginattempts;

	return $attempts['loginattempts'];

}

/**

}

/**

Zeile 6299Zeile 6470
 */
function validate_email_format($email)
{

 */
function validate_email_format($email)
{

	if(strpos($email, ' ') !== false)
{
return false;
}
// Valid local characters for email addresses: http://www.remote.org/jochen/mail/info/chars.html
return preg_match("/^[a-zA-Z0-9&*+\-_.{}~^\?=\/]+@[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]{2,}$/si", $email);

	return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;






}

/**

}

/**

Zeile 6324Zeile 6490
		$uid_string = " AND uid != '".(int)$uid."'";
}
$query = $db->simple_select("users", "COUNT(email) as emails", "email = '".$db->escape_string($email)."'{$uid_string}");

		$uid_string = " AND uid != '".(int)$uid."'";
}
$query = $db->simple_select("users", "COUNT(email) as emails", "email = '".$db->escape_string($email)."'{$uid_string}");





	if($db->fetch_field($query, "emails") > 0)
{
return true;

	if($db->fetch_field($query, "emails") > 0)
{
return true;

Zeile 6332Zeile 6498

return false;
}


return false;
}





/**
* Rebuilds settings.php
*

/**
* Rebuilds settings.php
*

Zeile 6340Zeile 6506
function rebuild_settings()
{
global $db, $mybb;

function rebuild_settings()
{
global $db, $mybb;


if(!file_exists(MYBB_ROOT."inc/settings.php"))
{
$mode = "x";
}
else
{
$mode = "w";
}

$options = array(
"order_by" => "title",
"order_dir" => "ASC"
);
$query = $db->simple_select("settings", "value, name", "", $options);

$settings = null;


$query = $db->simple_select("settings", "value, name", "", array(
'order_by' => 'title',
'order_dir' => 'ASC',
));

$settings = '';











	while($setting = $db->fetch_array($query))
{
$mybb->settings[$setting['name']] = $setting['value'];

	while($setting = $db->fetch_array($query))
{
$mybb->settings[$setting['name']] = $setting['value'];

Zeile 6365Zeile 6521
	}

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

	}

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

	$file = @fopen(MYBB_ROOT."inc/settings.php", $mode);
@fwrite($file, $settings);
@fclose($file);


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



$GLOBALS['settings'] = &$mybb->settings;
}


$GLOBALS['settings'] = &$mybb->settings;
}





/**
* Build a PREG compatible array of search highlight terms to replace in posts.
*

/**
* Build a PREG compatible array of search highlight terms to replace in posts.
*

Zeile 6385Zeile 6540
	if($mybb->settings['minsearchword'] < 1)
{
$mybb->settings['minsearchword'] = 3;

	if($mybb->settings['minsearchword'] < 1)
{
$mybb->settings['minsearchword'] = 3;

	}

	}


if(is_array($terms))
{


if(is_array($terms))
{

Zeile 6414Zeile 6569
			if($phrase != "")
{
if($inquote)

			if($phrase != "")
{
if($inquote)

				{

				{

					$words[] = trim($phrase);
}
else

					$words[] = trim($phrase);
}
else

Zeile 6443Zeile 6598
		$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))

		{

		{

			foreach($split_words as $word)
{
if(!$word || strlen($word) < $mybb->settings['minsearchword'])

			foreach($split_words as $word)
{
if(!$word || strlen($word) < $mybb->settings['minsearchword'])

Zeile 6462Zeile 6617

// Sort the word array by length. Largest terms go first and work their way down to the smallest term.
// This resolves problems like "test tes" where "tes" will be highlighted first, then "test" can't be highlighted because of the changed html


// Sort the word array by length. Largest terms go first and work their way down to the smallest term.
// This resolves problems like "test tes" where "tes" will be highlighted first, then "test" can't be highlighted because of the changed html

	usort($words, create_function('$a,$b', 'return strlen($b) - strlen($a);'));

	usort($words, 'build_highlight_array_sort');


// Loop through our words to build the PREG compatible strings
foreach($words as $word)


// Loop through our words to build the PREG compatible strings
foreach($words as $word)

Zeile 6473Zeile 6628

// Special boolean operators should be stripped
if($word == "" || $word == "or" || $word == "not" || $word == "and")


// Special boolean operators should be stripped
if($word == "" || $word == "or" || $word == "not" || $word == "and")

		{
continue;
}


		{
continue;
}


		// Now make PREG compatible
$find = "#(?!<.*?)(".preg_quote($word, "#").")(?![^<>]*?>)#ui";
$replacement = "<span class=\"highlight\" style=\"padding-left: 0px; padding-right: 0px;\">$1</span>";
$highlight_cache[$find] = $replacement;
}

		// Now make PREG compatible
$find = "#(?!<.*?)(".preg_quote($word, "#").")(?![^<>]*?>)#ui";
$replacement = "<span class=\"highlight\" style=\"padding-left: 0px; padding-right: 0px;\">$1</span>";
$highlight_cache[$find] = $replacement;
}





	return $highlight_cache;

	return $highlight_cache;

 
}

/**
* Sort the word array by length. Largest terms go first and work their way down to the smallest term.
*
* @param string $a First word.
* @param string $b Second word.
* @return integer Result of comparison function.
*/
function build_highlight_array_sort($a, $b)
{
return strlen($b) - strlen($a);

}

/**

}

/**

Zeile 6492Zeile 6659
 *
* @param int $src Decimal value of a character reference
* @return string|bool

 *
* @param int $src Decimal value of a character reference
* @return string|bool

 */

 */

function dec_to_utf8($src)
{
$dest = '';

if($src < 0)

function dec_to_utf8($src)
{
$dest = '';

if($src < 0)

	{

	{

		return false;

		return false;

	}

	}

	elseif($src <= 0x007f)

	elseif($src <= 0x007f)

	{

	{

		$dest .= chr($src);
}
elseif($src <= 0x07ff)
{
$dest .= chr(0xc0 | ($src >> 6));

		$dest .= chr($src);
}
elseif($src <= 0x07ff)
{
$dest .= chr(0xc0 | ($src >> 6));

		$dest .= chr(0x80 | ($src & 0x003f));

		$dest .= chr(0x80 | ($src & 0x003f));

	}
elseif($src <= 0xffff)
{

	}
elseif($src <= 0xffff)
{

Zeile 6555Zeile 6722
				$db->update_query("banfilters", array("lastuse" => TIME_NOW), "fid='{$banned_username['fid']}'");
}
return true;

				$db->update_query("banfilters", array("lastuse" => TIME_NOW), "fid='{$banned_username['fid']}'");
}
return true;

		}

		}

	}
// Still here - good username
return false;

	}
// Still here - good username
return false;

Zeile 6601Zeile 6768
	}

// Still here - good email

	}

// Still here - good email

	return false;

	return false;

}

/**

}

/**

Zeile 6777Zeile 6944
function fetch_remote_file($url, $post_data=array(), $max_redirects=20)
{
global $mybb, $config;

function fetch_remote_file($url, $post_data=array(), $max_redirects=20)
{
global $mybb, $config;

 

if(!my_validate_url($url, true))
{
return false;
}


$url_components = @parse_url($url);


$url_components = @parse_url($url);

 

if(!isset($url_components['scheme']))
{
$url_components['scheme'] = 'https';
}
if(!isset($url_components['port']))
{
$url_components['port'] = $url_components['scheme'] == 'https' ? 443 : 80;
}


if(
!$url_components ||
empty($url_components['host']) ||
(!empty($url_components['scheme']) && !in_array($url_components['scheme'], array('http', 'https'))) ||


if(
!$url_components ||
empty($url_components['host']) ||
(!empty($url_components['scheme']) && !in_array($url_components['scheme'], array('http', 'https'))) ||

		(!empty($url_components['port']) && !in_array($url_components['port'], array(80, 8080, 443))) ||

		(!in_array($url_components['port'], array(80, 8080, 443))) ||

		(!empty($config['disallowed_remote_hosts']) && in_array($url_components['host'], $config['disallowed_remote_hosts']))
)
{
return false;
}

		(!empty($config['disallowed_remote_hosts']) && in_array($url_components['host'], $config['disallowed_remote_hosts']))
)
{
return false;
}

 

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


if(!empty($config['disallowed_remote_addresses']))


if(!empty($config['disallowed_remote_addresses']))

	{
$addresses = gethostbynamel($url_components['host']);
if($addresses)

	{
foreach($config['disallowed_remote_addresses'] as $disallowed_address)


		{

		{

			foreach($config['disallowed_remote_addresses'] as $disallowed_address)





			$ip_range = fetch_ip_range($disallowed_address);

$packed_address = my_inet_pton($destination_address);

if(is_array($ip_range))

			{

			{

				$ip_range = fetch_ip_range($disallowed_address);
foreach($addresses as $address)

				if(strcmp($ip_range[0], $packed_address) <= 0 && strcmp($ip_range[1], $packed_address) >= 0)


				{

				{

					$packed_address = my_inet_pton($address);

if(is_array($ip_range))
{
if(strcmp($ip_range[0], $packed_address) <= 0 && strcmp($ip_range[1], $packed_address) >= 0)
{
return false;
}
}
elseif($address == $disallowed_address)
{
return false;
}

					return false;













				}

				}

 
			}
elseif($destination_address == $disallowed_address)
{
return false;

			}
}
}

$post_body = '';
if(!empty($post_data))

			}
}
}

$post_body = '';
if(!empty($post_data))

	{

	{

		foreach($post_data as $key => $val)
{
$post_body .= '&'.urlencode($key).'='.urlencode($val);

		foreach($post_data as $key => $val)
{
$post_body .= '&'.urlencode($key).'='.urlencode($val);

Zeile 6831Zeile 7009

if(function_exists("curl_init"))
{


if(function_exists("curl_init"))
{

		$can_followlocation = @ini_get('open_basedir') === '' && !$mybb->safemode;

$request_header = $max_redirects != 0 && !$can_followlocation;

		$fetch_header = $max_redirects > 0;




$ch = curl_init();


$ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $request_header);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

if($max_redirects != 0 && $can_followlocation)
{
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, $max_redirects);
}




























$curlopt = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => $fetch_header,
CURLOPT_TIMEOUT => 10,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 0,
);

if($ca_bundle_path = get_ca_bundle_path())
{
$curlopt[CURLOPT_SSL_VERIFYPEER] = 1;
$curlopt[CURLOPT_CAINFO] = $ca_bundle_path;
}
else
{
$curlopt[CURLOPT_SSL_VERIFYPEER] = 0;
}

$curl_version_info = curl_version();
$curl_version = $curl_version_info['version'];

if(version_compare(PHP_VERSION, '7.0.7', '>=') && version_compare($curl_version, '7.49', '>='))
{
// CURLOPT_CONNECT_TO
$curlopt[10243] = array(
$url_components['host'].':'.$url_components['port'].':'.$destination_address
);
}
elseif(version_compare(PHP_VERSION, '5.5', '>=') && version_compare($curl_version, '7.21.3', '>='))
{
// CURLOPT_RESOLVE
$curlopt[10203] = array(
$url_components['host'].':'.$url_components['port'].':'.$destination_address
);
}


		if(!empty($post_body))
{

		if(!empty($post_body))
{

			curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_body);

			$curlopt[CURLOPT_POST] = 1;
$curlopt[CURLOPT_POSTFIELDS] = $post_body;

		}

		}

 

curl_setopt_array($ch, $curlopt);


$response = curl_exec($ch);



$response = curl_exec($ch);


		if($request_header)

		if($fetch_header)

		{
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);

		{
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);

Zeile 6886Zeile 7089
	}
else if(function_exists("fsockopen"))
{

	}
else if(function_exists("fsockopen"))
{

		if(!isset($url_components['port']))
{
$url_components['port'] = 80;
}
if(!isset($url_components['path']))

		if(!isset($url_components['path']))





		{
$url_components['path'] = "/";
}
if(isset($url_components['query']))

		{
$url_components['path'] = "/";
}
if(isset($url_components['query']))

		{

		{

			$url_components['path'] .= "?{$url_components['query']}";
}

			$url_components['path'] .= "?{$url_components['query']}";
}





		$scheme = '';

if($url_components['scheme'] == 'https')

		$scheme = '';

if($url_components['scheme'] == 'https')

		{

		{

			$scheme = 'ssl://';
if($url_components['port'] == 80)
{

			$scheme = 'ssl://';
if($url_components['port'] == 80)
{

Zeile 6910Zeile 7109
			}
}


			}
}


		$fp = @fsockopen($scheme.$url_components['host'], $url_components['port'], $error_no, $error, 10);






























		if(function_exists('stream_context_create'))
{
if($url_components['scheme'] == 'https' && $ca_bundle_path = get_ca_bundle_path())
{
$context = stream_context_create(array(
'ssl' => array(
'verify_peer' => true,
'verify_peer_name' => true,
'peer_name' => $url_components['host'],
'cafile' => $ca_bundle_path,
),
));
}
else
{
$context = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
));
}

$fp = @stream_socket_client($scheme.$destination_address.':'.(int)$url_components['port'], $error_no, $error, 10, STREAM_CLIENT_CONNECT, $context);
}
else
{
$fp = @fsockopen($scheme.$url_components['host'], (int)$url_components['port'], $error_no, $error, 10);
}


		@stream_set_timeout($fp, 10);
if(!$fp)
{
return false;
}
$headers = array();

		@stream_set_timeout($fp, 10);
if(!$fp)
{
return false;
}
$headers = array();

		if(!empty($post_body))

		if(!empty($post_body))

		{
$headers[] = "POST {$url_components['path']} HTTP/1.0";
$headers[] = "Content-Length: ".strlen($post_body);

		{
$headers[] = "POST {$url_components['path']} HTTP/1.0";
$headers[] = "Content-Length: ".strlen($post_body);

Zeile 6931Zeile 7159
		$headers[] = "Host: {$url_components['host']}";
$headers[] = "Connection: Close";
$headers[] = '';

		$headers[] = "Host: {$url_components['host']}";
$headers[] = "Connection: Close";
$headers[] = '';





		if(!empty($post_body))
{
$headers[] = $post_body;

		if(!empty($post_body))
{
$headers[] = $post_body;

		}

		}

		else

		else

		{

		{

			// If we have no post body, we need to add an empty element to make sure we've got \r\n\r\n before the (non-existent) body starts
$headers[] = '';
}

$headers = implode("\r\n", $headers);
if(!@fwrite($fp, $headers))

			// If we have no post body, we need to add an empty element to make sure we've got \r\n\r\n before the (non-existent) body starts
$headers[] = '';
}

$headers = implode("\r\n", $headers);
if(!@fwrite($fp, $headers))

		{
return false;

		{
return false;

		}

$data = null;

		}

$data = null;

Zeile 6962Zeile 7190
		$status_line = current(explode("\n\n", $header, 1));
$body = $data[1];


		$status_line = current(explode("\n\n", $header, 1));
$body = $data[1];


		if($max_redirects != 0 && (strstr($status_line, ' 301 ') || strstr($status_line, ' 302 ')))

		if($max_redirects > 0 && (strstr($status_line, ' 301 ') || strstr($status_line, ' 302 ')))

		{
preg_match('/Location:(.*?)(?:\n|$)/', $header, $matches);


		{
preg_match('/Location:(.*?)(?:\n|$)/', $header, $matches);


Zeile 6975Zeile 7203
		{
$data = $body;
}

		{
$data = $body;
}


return $data;
}
else if(empty($post_data))














































return $data;
}
else
{
return false;
}
}

/**
* Resolves a hostname into a set of IP addresses.
*
* @param string $hostname The hostname to be resolved
* @return array|bool The resulting IP addresses. False on failure
*/
function get_ip_by_hostname($hostname)
{
$addresses = @gethostbynamel($hostname);

if(!$addresses)
{
$result_set = @dns_get_record($hostname, DNS_A | DNS_AAAA);

if($result_set)
{
$addresses = array_column($result_set, 'ip');
}
else
{
return false;
}
}

return $addresses;
}

/**
* Returns the location of the CA bundle defined in the PHP configuration.
*
* @return string|bool The location of the CA bundle, false if not set
*/
function get_ca_bundle_path()
{
if($path = ini_get('openssl.cafile'))
{
return $path;
}
if($path = ini_get('curl.cainfo'))

	{

	{

		return @implode("", @file($url));
}
else
{
return false;

		return $path;





	}

	}

 

return false;

}

/**

}

/**

Zeile 7002Zeile 7272
	{
global $mybb;
$super_admins = str_replace(" ", "", $mybb->config['super_admins']);

	{
global $mybb;
$super_admins = str_replace(" ", "", $mybb->config['super_admins']);

	}

if(my_strpos(",{$super_admins},", ",{$uid},") === false)

	}

if(my_strpos(",{$super_admins},", ",{$uid},") === false)

	{
return false;
}

	{
return false;
}

Zeile 7050Zeile 7320
		if((int)$groups == -1)
{
return $memberships;

		if((int)$groups == -1)
{
return $memberships;

		}
else

		}
else

		{
if(is_string($groups))
{

		{
if(is_string($groups))
{

Zeile 7098Zeile 7368
			$escape_preg = preg_quote($escape, "#");
}
$quoted_strings = preg_split("#(?<!\\\){$escape_preg}#", $string);

			$escape_preg = preg_quote($escape, "#");
}
$quoted_strings = preg_split("#(?<!\\\){$escape_preg}#", $string);

	}

	}

	else
{
$quoted_strings = array($string);

	else
{
$quoted_strings = array($string);

Zeile 7128Zeile 7398
		return $original;
}
return $strings;

		return $original;
}
return $strings;

}


}


/**
* DEPRECATED! Please use IPv6 compatible fetch_ip_range!
* Fetch an IPv4 long formatted range for searching IPv4 IP addresses.

/**
* DEPRECATED! Please use IPv6 compatible fetch_ip_range!
* Fetch an IPv4 long formatted range for searching IPv4 IP addresses.

Zeile 7253Zeile 7523
	{
require_once MYBB_ROOT.'inc/datahandlers/warnings.php';
$warningshandler = new WarningsHandler('update');

	{
require_once MYBB_ROOT.'inc/datahandlers/warnings.php';
$warningshandler = new WarningsHandler('update');

	}

	}


return $warningshandler->expire_warnings();
}


return $warningshandler->expire_warnings();
}

Zeile 7269Zeile 7539
{
// Passing $mode as an octal number causes strlen and substr to return incorrect values. Instead pass as a string
if(substr($mode, 0, 1) != '0' || strlen($mode) !== 4)

{
// Passing $mode as an octal number causes strlen and substr to return incorrect values. Instead pass as a string
if(substr($mode, 0, 1) != '0' || strlen($mode) !== 4)

	{

	{

		return false;
}
$old_umask = umask(0);

		return false;
}
$old_umask = umask(0);

Zeile 7300Zeile 7570
	if(@is_dir($path) && !@is_link($path))
{
if($dh = @opendir($path))

	if(@is_dir($path) && !@is_link($path))
{
if($dh = @opendir($path))

		{

		{

			while(($file = @readdir($dh)) !== false)
{
if($file == '.' || $file == '..' || $file == '.svn' || in_array($path.'/'.$file, $ignore) || !my_rmdir_recursive($path.'/'.$file))

			while(($file = @readdir($dh)) !== false)
{
if($file == '.' || $file == '..' || $file == '.svn' || in_array($path.'/'.$file, $ignore) || !my_rmdir_recursive($path.'/'.$file))

Zeile 7309Zeile 7579
				}
}
@closedir($dh);

				}
}
@closedir($dh);

		}

		}


// Are we done? Don't delete the main folder too and return true
if($path == $orig_dir)
{
return true;


// Are we done? Don't delete the main folder too and return true
if($path == $orig_dir)
{
return true;

		}


		}


		return @rmdir($path);
}


		return @rmdir($path);
}


Zeile 7378Zeile 7648
 * @deprecated
* @param integer $long The IP to convert (will accept 64-bit IPs as well)
* @return string IP in IPv4 format

 * @deprecated
* @param integer $long The IP to convert (will accept 64-bit IPs as well)
* @return string IP in IPv4 format

 */

 */

function my_long2ip($long)
{
// On 64-bit machines is_int will return true. On 32-bit it will return false

function my_long2ip($long)
{
// On 64-bit machines is_int will return true. On 32-bit it will return false

Zeile 7406Zeile 7676
	{
/**
* Replace inet_pton()

	{
/**
* Replace inet_pton()

		 *
* @category PHP
* @package PHP_Compat

		 *
* @category PHP
* @package PHP_Compat

		 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html
* @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
* @link http://php.net/inet_pton

		 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html
* @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
* @link http://php.net/inet_pton

Zeile 7423Zeile 7693

$delim_count = substr_count($ip, ':');
if($delim_count < 1 || $delim_count > 7)


$delim_count = substr_count($ip, ':');
if($delim_count < 1 || $delim_count > 7)

		{

		{

			return false;

			return false;

		}


		}


		$r = explode(':', $ip);
$rcount = count($r);
if(($doub = array_search('', $r, 1)) !== false)

		$r = explode(':', $ip);
$rcount = count($r);
if(($doub = array_search('', $r, 1)) !== false)

Zeile 7434Zeile 7704
			$length = (!$doub || $doub == $rcount - 1 ? 2 : 1);
array_splice($r, $doub, $length, array_fill(0, 8 + $length - $rcount, 0));
}

			$length = (!$doub || $doub == $rcount - 1 ? 2 : 1);
array_splice($r, $doub, $length, array_fill(0, 8 + $length - $rcount, 0));
}





		$r = array_map('hexdec', $r);
array_unshift($r, 'n*');
$r = call_user_func_array('pack', $r);

		$r = array_map('hexdec', $r);
array_unshift($r, 'n*');
$r = call_user_func_array('pack', $r);





		return $r;
}
}

		return $r;
}
}

Zeile 7454Zeile 7724
	if(function_exists('inet_ntop'))
{
return @inet_ntop($ip);

	if(function_exists('inet_ntop'))
{
return @inet_ntop($ip);

	}

	}

	else
{
/**

	else
{
/**

Zeile 7469Zeile 7739
		 * @version     $Revision: 269597 $
*/
switch(strlen($ip))

		 * @version     $Revision: 269597 $
*/
switch(strlen($ip))

		{

		{

			case 4:
list(,$r) = unpack('N', $ip);
return long2ip($r);

			case 4:
list(,$r) = unpack('N', $ip);
return long2ip($r);

Zeile 7500Zeile 7770
		{
// IPv6
$upper = str_replace('*', 'ffff', $ipaddress);

		{
// IPv6
$upper = str_replace('*', 'ffff', $ipaddress);

			$lower = str_replace('*', '0', $ipaddress);
}
else

			$lower = str_replace('*', '0', $ipaddress);
}
else

		{
// IPv4
$ip_bits = count(explode('.', $ipaddress));

		{
// IPv4
$ip_bits = count(explode('.', $ipaddress));

Zeile 7592Zeile 7862
		}

return array($ip_lower_pack, $ip_higher_pack);

		}

return array($ip_lower_pack, $ip_higher_pack);

	}

	}

	// Just on IP address
else
{
return my_inet_pton($ipaddress);
}
}

	// Just on IP address
else
{
return my_inet_pton($ipaddress);
}
}





/**
* Time how long it takes for a particular piece of code to run. Place calls above & below the block of code.
*

/**
* Time how long it takes for a particular piece of code to run. Place calls above & below the block of code.
*

Zeile 7608Zeile 7878
function get_execution_time()
{
static $time_start;

function get_execution_time()
{
static $time_start;





	$time = microtime(true);

	$time = microtime(true);







	// Just starting timer, init and return
if(!$time_start)
{
$time_start = $time;
return;

	// Just starting timer, init and return
if(!$time_start)
{
$time_start = $time;
return;

	}

	}

	// Timer has run, return execution time
else
{

	// Timer has run, return execution time
else
{

Zeile 7625Zeile 7894
		if($total < 0) $total = 0;
$time_start = 0;
return $total;

		if($total < 0) $total = 0;
$time_start = 0;
return $total;

	}
}


	}
}


/**
* Processes a checksum list on MyBB files and returns a result set
*

/**
* Processes a checksum list on MyBB files and returns a result set
*

Zeile 7681Zeile 7950
				{
$filename = $path."/".$file;
$handle = fopen($filename, "rb");

				{
$filename = $path."/".$file;
$handle = fopen($filename, "rb");

					$contents = '';

					$hashingContext = hash_init('sha512');

					while(!feof($handle))
{

					while(!feof($handle))
{

						$contents .= fread($handle, 8192);

						hash_update($hashingContext, fread($handle, 8192));

					}
fclose($handle);


					}
fclose($handle);


					$md5 = md5($contents);

					$checksum = hash_final($hashingContext);


// Does it match any of our hashes (unix/windows new lines taken into consideration with the hashes)


// Does it match any of our hashes (unix/windows new lines taken into consideration with the hashes)

					if(!in_array($md5, $checksums[$file_path]))

					if(!in_array($checksum, $checksums[$file_path]))

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

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

Zeile 7878Zeile 8147
		{
$elements = unpack('i', $output);
$output = abs($elements[1]);

		{
$elements = unpack('i', $output);
$output = abs($elements[1]);

		}
else
{

		}
else
{

			$elements = unpack('N2', $output);
$output = abs($elements[1] << 32 | $elements[2]);
}

			$elements = unpack('N2', $output);
$output = abs($elements[1] << 32 | $elements[2]);
}

Zeile 7911Zeile 8180
		{
$result = random_int($min, $max);
} catch (Exception $e) {

		{
$result = random_int($min, $max);
} catch (Exception $e) {

		}

		}


if(isset($result))
{


if(isset($result))
{

Zeile 8002Zeile 8271
	{
// Check to see if we have matched a first character in our utf-8 array
$offset = match_sequence($string, $hex_chrs);

	{
// Check to see if we have matched a first character in our utf-8 array
$offset = match_sequence($string, $hex_chrs);

		if(!$offset)
{
// If not, then we must have a "good" character and we don't need to do anymore processing

		if(!$offset)
{
// If not, then we must have a "good" character and we don't need to do anymore processing

			break;
}
$string = substr($string, $offset);

			break;
}
$string = substr($string, $offset);

Zeile 8340Zeile 8609
	}

$pm['options'] = array(

	}

$pm['options'] = array(

		"signature" => 0,

 
		"disablesmilies" => 0,
"savecopy" => 0,
"readreceipt" => 0

		"disablesmilies" => 0,
"savecopy" => 0,
"readreceipt" => 0

Zeile 8378Zeile 8646
	if(!is_array($data))
{
$data = array($data);

	if(!is_array($data))
{
$data = array($data);

	}


	}


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

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

Zeile 8411Zeile 8679
{
global $mybb, $plugins;


{
global $mybb, $plugins;


	$success = false;

$file_path = (string)$file_path;

	$success = false;







	$real_file_path = realpath($file_path);



	$file_path = (string)$file_path;

$real_file_path = realpath($file_path);


$file_dir_path = dirname($real_file_path);
$file_dir_path = str_replace(MYBB_ROOT, '', $file_dir_path);
$file_dir_path = ltrim($file_dir_path, './\\');


$file_dir_path = dirname($real_file_path);
$file_dir_path = str_replace(MYBB_ROOT, '', $file_dir_path);
$file_dir_path = ltrim($file_dir_path, './\\');





	$file_name = basename($real_file_path);

if(file_exists($file_path))
{
if($mybb->settings['usecdn'] && !empty($mybb->settings['cdnpath']))

	$file_name = basename($real_file_path);

if(file_exists($file_path))
{
if($mybb->settings['usecdn'] && !empty($mybb->settings['cdnpath']))

		{

		{

			$cdn_path = rtrim($mybb->settings['cdnpath'], '/\\');

if(substr($file_dir_path, 0, my_strlen(MYBB_ROOT)) == MYBB_ROOT)

			$cdn_path = rtrim($mybb->settings['cdnpath'], '/\\');

if(substr($file_dir_path, 0, my_strlen(MYBB_ROOT)) == MYBB_ROOT)

Zeile 8470Zeile 8738
	}

return $success;

	}

return $success;

}

/**

}

/**

 * Validate an url

 * Validate an url

 *

 *

 * @param string $url The url to validate.
* @param bool $relative_path Whether or not the url could be a relative path.

 * @param string $url The url to validate.
* @param bool $relative_path Whether or not the url could be a relative path.

 
 * @param bool $allow_local Whether or not the url could be pointing to local networks.

 *
* @return bool Whether this is a valid url.
*/

 *
* @return bool Whether this is a valid url.
*/

function my_validate_url($url, $relative_path=false)

function my_validate_url($url, $relative_path=false, $allow_local=false)

{

{

	if($relative_path && my_substr($url, 0, 1) == '/' || preg_match('_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$_iuS', $url))










	if($allow_local)
{
$regex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:localhost|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))\.?))(?::\d{2,5})?(?:[/?#]\S*)?$_iuS';
}
else
{
$regex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$_iuS';
}

if($relative_path && my_substr($url, 0, 1) == '/' || preg_match($regex, $url))

	{
return true;
}

	{
return true;
}



 
	return false;

	return false;

}

/**

}

/**

 * Strip html tags from string, also removes <script> and <style> contents.

 * Strip html tags from string, also removes <script> and <style> contents.

 * 


 *
* @deprecated

 * @param  string $string         String to stripe
* @param string $allowable_tags Allowed html tags

 * @param  string $string         String to stripe
* @param string $allowable_tags Allowed html tags

 * 

 *

 * @return string                 Striped string
*/
function my_strip_tags($string, $allowable_tags = '')

 * @return string                 Striped string
*/
function my_strip_tags($string, $allowable_tags = '')

Zeile 8508Zeile 8786
	);
$string = preg_replace($pattern, '', $string);
return strip_tags($string, $allowable_tags);

	);
$string = preg_replace($pattern, '', $string);
return strip_tags($string, $allowable_tags);

 
}

/**
* Escapes a RFC 4180-compliant CSV string.
* Based on https://github.com/Automattic/camptix/blob/f80725094440bf09861383b8f11e96c177c45789/camptix.php#L2867
*
* @param string $string The string to be escaped
* @param boolean $escape_active_content Whether or not to escape active content trigger characters
* @return string The escaped string
*/
function my_escape_csv($string, $escape_active_content=true)
{
if($escape_active_content)
{
$active_content_triggers = array('=', '+', '-', '@');
$delimiters = array(',', ';', ':', '|', '^', "\n", "\t", " ");

$first_character = mb_substr($string, 0, 1);

if(
in_array($first_character, $active_content_triggers, true) ||
in_array($first_character, $delimiters, true)
)
{
$string = "'".$string;
}

foreach($delimiters as $delimiter)
{
foreach($active_content_triggers as $trigger)
{
$string = str_replace($delimiter.$trigger, $delimiter."'".$trigger, $string);
}
}
}

$string = str_replace('"', '""', $string);

return $string;

}

}