Vergleich inc/functions.php - 1.8.11 - 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'] = '';


if($diff < 0)
{
$diff = abs($diff);
$relative['suffix'] = '';

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


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


Zeile 423Zeile 437
			if($diff <= 60)
{
// Less than a minute

			if($diff <= 60)
{
// Less than a minute

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

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

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

$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 448Zeile 462
				$relative['plural'] = $lang->rel_hours_single;
}


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

		}
else
{
if($ty)

			{

			{

				if($todaysdate == $date)
{

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

				}
}


				}
}


Zeile 473Zeile 487
			{
$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 783Zeile 822
	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
*

/**
* Produce an error message for displaying inline on a page
*

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 997Zeile 1036
	{
return '';
}

	{
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 1422Zeile 1469
			if(empty($level_permissions))
{
$level_permissions = $groupscache[$gid];

			if(empty($level_permissions))
{
$level_permissions = $groupscache[$gid];

			}

			}


foreach($level_permissions as $permission => $access)
{


foreach($level_permissions as $permission => $access)
{

Zeile 1430Zeile 1477
				{
$current_permissions[$permission] = $access;
}

				{
$current_permissions[$permission] = $access;
}

			}

			}


if($level_permissions["canview"] && empty($level_permissions["canonlyviewownthreads"]))
{


if($level_permissions["canview"] && empty($level_permissions["canonlyviewownthreads"]))
{

Zeile 1438Zeile 1485
			}

if($level_permissions["canpostreplys"] && empty($level_permissions["canonlyreplyownthreads"]))

			}

if($level_permissions["canpostreplys"] && empty($level_permissions["canonlyreplyownthreads"]))

			{

			{

				$only_reply_own_threads = 0;
}
}

				$only_reply_own_threads = 0;
}
}

	}

	}


// Figure out if we can view more than our own threads
if($only_view_own_threads == 0)


// Figure out if we can view more than our own threads
if($only_view_own_threads == 0)

	{

	{

		$current_permissions["canonlyviewownthreads"] = 0;
}


		$current_permissions["canonlyviewownthreads"] = 0;
}


Zeile 1454Zeile 1501
	if($only_reply_own_threads == 0)
{
$current_permissions["canonlyreplyownthreads"] = 0;

	if($only_reply_own_threads == 0)
{
$current_permissions["canonlyreplyownthreads"] = 0;

	}

	}


if(count($current_permissions) == 0)
{


if(count($current_permissions) == 0)
{

Zeile 1502Zeile 1549
			}

if($forum_cache[$parent_id]['password'] != "")

			}

if($forum_cache[$parent_id]['password'] != "")

			{

			{

				check_forum_password($parent_id, $fid);
}
}

				check_forum_password($parent_id, $fid);
}
}

Zeile 1516Zeile 1563
			if($password === $mybb->get_input('pwverify'))
{
my_setcookie("forumpass[$fid]", md5($mybb->user['uid'].$mybb->get_input('pwverify')), null, true);

			if($password === $mybb->get_input('pwverify'))
{
my_setcookie("forumpass[$fid]", md5($mybb->user['uid'].$mybb->get_input('pwverify')), null, true);

				$showform = false;
}
else

				$showform = false;
}
else

			{
eval("\$pwnote = \"".$templates->get("forumdisplay_password_wrongpass")."\";");
$showform = true;

			{
eval("\$pwnote = \"".$templates->get("forumdisplay_password_wrongpass")."\";");
$showform = true;

Zeile 1549Zeile 1596
	if($showform)
{
if($pid)

	if($showform)
{
if($pid)

		{

		{

			header("Location: ".$mybb->settings['bburl']."/".get_forum_link($fid));
}
else

			header("Location: ".$mybb->settings['bburl']."/".get_forum_link($fid));
}
else

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 2052Zeile 2110
					$stack[] = &$list;
$list[$key] = array();
$list = &$list[$key];

					$stack[] = &$list;
$list[$key] = array();
$list = &$list[$key];

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

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

					$state = 2;
break;
}

					$state = 2;
break;
}





				// missing array value
return false;


				// missing array value
return false;


Zeile 2072Zeile 2130
					if(count($list) < end($expected))
{
// array size less than expected

					if(count($list) < end($expected))
{
// array size less than expected

						return false;
}


						return false;
}


					unset($list);
$list = &$stack[count($stack)-1];
array_pop($stack);

					unset($list);
$list = &$stack[count($stack)-1];
array_pop($stack);

Zeile 2105Zeile 2163
				}

// illegal array index type

				}

// illegal array index type

				return false;


				return false;


			case 0: // expecting array or value
if($type == 'a')
{

			case 0: // expecting array or value
if($type == 'a')
{

Zeile 2120Zeile 2178
					$list = &$data;
$expected[] = $expectedLength;
$state = 2;

					$list = &$data;
$expected[] = $expectedLength;
$state = 2;

					break;
}

					break;
}

				if($type != '}')
{
$data = $value;

				if($type != '}')
{
$data = $value;

Zeile 2153Zeile 2211
{
// Ensure we use the byte count for strings even when strlen() is overloaded by mb_strlen()
if(function_exists('mb_internal_encoding') && (((int)ini_get('mbstring.func_overload')) & 2))

{
// Ensure we use the byte count for strings even when strlen() is overloaded by mb_strlen()
if(function_exists('mb_internal_encoding') && (((int)ini_get('mbstring.func_overload')) & 2))

	{

	{

		$mbIntEnc = mb_internal_encoding();
mb_internal_encoding('ASCII');
}

		$mbIntEnc = mb_internal_encoding();
mb_internal_encoding('ASCII');
}

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

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

	}


	}


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

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

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

		else if(@file_exists("/proc/loadavg") && $load = @file_get_contents("/proc/loadavg"))

		{

		{

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

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

Zeile 2279Zeile 2337

// 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 2311Zeile 2369
	$returnload = trim($serverload[0]);

return $returnload;

	$returnload = trim($serverload[0]);

return $returnload;

}

}


/**
* Returns the amount of memory allocated to the script.


/**
* Returns the amount of memory allocated to the script.

Zeile 2341Zeile 2399
{
global $cache, $db;
static $stats_changes;

{
global $cache, $db;
static $stats_changes;





	if(empty($stats_changes))
{
// Update stats after all changes are done

	if(empty($stats_changes))
{
// Update stats after all changes are done

Zeile 2372Zeile 2430
		}
$stats = $cache->read("stats");
$changes = $stats_changes;

		}
$stats = $cache->read("stats");
$changes = $stats_changes;

	}

	}

	else
{
$stats = $stats_changes;

	else
{
$stats = $stats_changes;

Zeile 2387Zeile 2445
			if(substr($changes[$counter], 0, 2) == "+-")
{
$changes[$counter] = substr($changes[$counter], 1);

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

			// Adding or subtracting from previous value?
if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
{

Zeile 2434Zeile 2492
		$lastmember = $db->fetch_array($query);
$new_stats['lastuid'] = $lastmember['uid'];
$new_stats['lastusername'] = $lastmember['username'] = htmlspecialchars_uni($lastmember['username']);

		$lastmember = $db->fetch_array($query);
$new_stats['lastuid'] = $lastmember['uid'];
$new_stats['lastusername'] = $lastmember['username'] = htmlspecialchars_uni($lastmember['username']);

	}

if(!empty($new_stats))
{

	}

if(!empty($new_stats))
{

		if(is_array($stats))
{
$stats = array_merge($stats, $new_stats); // Overwrite changed values

		if(is_array($stats))
{
$stats = array_merge($stats, $new_stats); // Overwrite changed values

Zeile 2517Zeile 2575
	// 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)
{

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

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

		{

		{

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

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

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

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

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

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

	}

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

	}

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

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

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

	}

	}

}

/**

}

/**

Zeile 2628Zeile 2686
	);

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

	);

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

}

}


/**
* Updates the thread counters with a specific value (or addition/subtraction of the previous value)


/**
* Updates the thread counters with a specific value (or addition/subtraction of the previous value)

Zeile 2644Zeile 2702
	$tid = (int)$tid;

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

	$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 2676Zeile 2734
				$update_query[$counter] = 0;
}
}

				$update_query[$counter] = 0;
}
}

	}


	}


	$db->free_result($query);

// Only update if we're actually doing something

	$db->free_result($query);

// Only update if we're actually doing something

Zeile 2689Zeile 2747

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


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

 *
* @param int $tid The thread ID
*/

 *
* @param int $tid The thread ID
*/

function update_thread_data($tid)
{
global $db;

function update_thread_data($tid)
{
global $db;





	$thread = get_thread($tid);

// 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;

	$thread = get_thread($tid);

// 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;

	}

$query = $db->query("

	}

$query = $db->query("

		SELECT u.uid, u.username, 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.username AS postusername, p.dateline
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)

Zeile 2798Zeile 2856
			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)


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

Zeile 2806Zeile 2864
				$update_query[$counter] = 0;
}
}

				$update_query[$counter] = 0;
}
}

	}

$db->free_result($query);

	}

$db->free_result($query);


// Only update if we're actually doing something
if(count($update_query) > 0)
{
$db->update_query("users", $update_query, "uid='{$uid}'");


// Only update if we're actually doing something
if(count($update_query) > 0)
{
$db->update_query("users", $update_query, "uid='{$uid}'");

	}
}

/**

	}
}

/**

 * Deletes a thread from the database
*
* @param int $tid The thread ID

 * Deletes a thread from the database
*
* @param int $tid The thread ID

Zeile 2910Zeile 2968
					if($selitem == $forum['fid'])
{
$optionselected = 'selected="selected"';

					if($selitem == $forum['fid'])
{
$optionselected = 'selected="selected"';

					}

$forum['name'] = htmlspecialchars_uni(strip_tags($forum['name']));

eval("\$forumjumpbits .= \"".$templates->get("forumjump_bit")."\";");

					}

$forum['name'] = htmlspecialchars_uni(strip_tags($forum['name']));

eval("\$forumjumpbits .= \"".$templates->get("forumjump_bit")."\";");


if($forum_cache[$forum['fid']])
{


if($forum_cache[$forum['fid']])
{

Zeile 2929Zeile 2987
	if($addselect)
{
if($showextras == 0)

	if($addselect)
{
if($showextras == 0)

		{

		{

			$template = "special";
}
else

			$template = "special";
}
else

Zeile 2937Zeile 2995
			$template = "advanced";

if(strpos(FORUM_URL, '.html') !== false)

			$template = "advanced";

if(strpos(FORUM_URL, '.html') !== false)

			{

			{

				$forum_link = "'".str_replace('{fid}', "'+option+'", FORUM_URL)."'";

				$forum_link = "'".str_replace('{fid}', "'+option+'", FORUM_URL)."'";

			}

			}

			else
{
$forum_link = "'".str_replace('{fid}', "'+option", FORUM_URL);

			else
{
$forum_link = "'".str_replace('{fid}', "'+option", FORUM_URL);

			}
}

			}
}


eval("\$forumjump = \"".$templates->get("forumjump_".$template)."\";");
}


eval("\$forumjump = \"".$templates->get("forumjump_".$template)."\";");
}





	return $forumjump;
}

/**
* Returns the extension of a file.

	return $forumjump;
}

/**
* Returns the extension of a file.

 *

 *

 * @param string $file The filename.
* @return string The extension of the file.
*/

 * @param string $file The filename.
* @return string The extension of the file.
*/

Zeile 2974Zeile 3032
{
$set = array_merge(range(0, 9), range('A', 'Z'), range('a', 'z'));
$str = array();

{
$set = array_merge(range(0, 9), range('A', 'Z'), range('a', 'z'));
$str = array();





	// Complex strings have always at least 3 characters, even if $length < 3
if($complex == true)
{

	// Complex strings have always at least 3 characters, even if $length < 3
if($complex == true)
{

Zeile 2993Zeile 3051
	for($i = 0; $i < $length; ++$i)
{
$str[] = $set[my_rand(0, 61)];

	for($i = 0; $i < $length; ++$i)
{
$str[] = $set[my_rand(0, 61)];

	}


	}


	// Make sure they're in random order and convert them to a string
shuffle($str);


	// Make sure they're in random order and convert them to a string
shuffle($str);


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



	static $formattednames = array();

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

	{

	{

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

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





















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

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

$format = "{username}";

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





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

		$format = $parameters['format'];







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

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



	}


	}


	$format = stripslashes($format);

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

	return $formattednames[$username];



}

/**

}

/**

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)
{
$email = "email,";

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

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

			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 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 3492Zeile 3566
		{
return $prefixes_cache[$pid];
}

		{
return $prefixes_cache[$pid];
}





		return $prefixes_cache;
}


		return $prefixes_cache;
}


Zeile 3502Zeile 3576
	{
// No cache
$prefix_cache = $cache->read("threadprefixes", true);

	{
// No cache
$prefix_cache = $cache->read("threadprefixes", true);





		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 3522Zeile 3596
	else if(!empty($prefixes_cache))
{
return $prefixes_cache;

	else if(!empty($prefixes_cache))
{
return $prefixes_cache;

	}

	}


return false;
}


return false;
}

Zeile 3543Zeile 3617
	if($fid != 'all')
{
$fid = (int)$fid;

	if($fid != 'all')
{
$fid = (int)$fid;

	}


	}


	$prefix_cache = build_prefixes(0);
if(empty($prefix_cache))
{

	$prefix_cache = build_prefixes(0);
if(empty($prefix_cache))
{

Zeile 3629Zeile 3703
 *  @return string The thread prefix selection menu
*/
function build_forum_prefix_select($fid, $selected_pid=0)

 *  @return string The thread prefix selection menu
*/
function build_forum_prefix_select($fid, $selected_pid=0)

{

{

	global $cache, $db, $lang, $mybb, $templates;

$fid = (int)$fid;

	global $cache, $db, $lang, $mybb, $templates;

$fid = (int)$fid;

Zeile 3714Zeile 3788
		$httpaccept_encoding = '';

if(isset($_SERVER['HTTP_ACCEPT_ENCODING']))

		$httpaccept_encoding = '';

if(isset($_SERVER['HTTP_ACCEPT_ENCODING']))

		{

		{

			$httpaccept_encoding = $_SERVER['HTTP_ACCEPT_ENCODING'];
}


			$httpaccept_encoding = $_SERVER['HTTP_ACCEPT_ENCODING'];
}


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;
}
else if($days > 1)

	elseif($weeks > 0)
























	{

	{

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


























































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

if(!isset($options['days']) || $options['days'] !== false)
{
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($hours == 1)

	}

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

		{

		{

			$nicetime['hours'] = "1".$lang_hour;
}
else if($hours > 1)
{
$nicetime['hours'] = $hours.$lang_hours;

			$nicetime['hours'] = "1".$lang_hour;
}
else if($hours > 1)
{
$nicetime['hours'] = $hours.$lang_hours;

		}
}

		}
}


if(!isset($options['minutes']) || $options['minutes'] !== false)
{
if($minutes == 1)
{
$nicetime['minutes'] = "1".$lang_minute;


if(!isset($options['minutes']) || $options['minutes'] !== false)
{
if($minutes == 1)
{
$nicetime['minutes'] = "1".$lang_minute;

		}

		}

		else if($minutes > 1)
{
$nicetime['minutes'] = $minutes.$lang_minutes;

		else if($minutes > 1)
{
$nicetime['minutes'] = $minutes.$lang_minutes;

		}
}

		}
}


if(!isset($options['seconds']) || $options['seconds'] !== false)
{
if($seconds == 1)


if(!isset($options['seconds']) || $options['seconds'] !== false)
{
if($seconds == 1)

		{

		{

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

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

	}

	}


if(is_array($nicetime))
{


if(is_array($nicetime))
{

Zeile 4758Zeile 4899
 *
* @param int $reset 1 to reset the row to trow1.
* @return string trow1 or trow2 depending on the previous call

 *
* @param int $reset 1 to reset the row to trow1.
* @return string trow1 or trow2 depending on the previous call

 */

 */

function alt_trow($reset=0)
{
global $alttrow;

function alt_trow($reset=0)
{
global $alttrow;





	if($alttrow == "trow1" && !$reset)
{
$trow = "trow2";

	if($alttrow == "trow1" && !$reset)
{
$trow = "trow2";

	}

	}

	else
{
$trow = "trow1";

	else
{
$trow = "trow1";

	}


	}


	$alttrow = $trow;

return $trow;

	$alttrow = $trow;

return $trow;

Zeile 4796Zeile 4937
	{
$query = $db->simple_select("users", "additionalgroups, usergroup", "uid='".(int)$uid."'");
$user = $db->fetch_array($query);

	{
$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 = "";


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

Zeile 4998Zeile 5139
function build_theme_select($name, $selected=-1, $tid=0, $depth="", $usergroup_override=false, $footer=false, $count_override=false)
{
global $db, $themeselect, $tcache, $lang, $mybb, $limit, $templates, $num_themes, $themeselect_option;

function build_theme_select($name, $selected=-1, $tid=0, $depth="", $usergroup_override=false, $footer=false, $count_override=false)
{
global $db, $themeselect, $tcache, $lang, $mybb, $limit, $templates, $num_themes, $themeselect_option;





	if($tid == 0)
{
$tid = 1;
$num_themes = 0;
$themeselect_option = '';

	if($tid == 0)
{
$tid = 1;
$num_themes = 0;
$themeselect_option = '';





		if(!isset($lang->use_default))
{
$lang->use_default = $lang->lang_select_default;

		if(!isset($lang->use_default))
{
$lang->use_default = $lang->lang_select_default;

		}
}

if(!is_array($tcache))

		}
}

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'");


Zeile 5024Zeile 5165
	if(is_array($tcache[$tid]))
{
foreach($tcache[$tid] as $theme)

	if(is_array($tcache[$tid]))
{
foreach($tcache[$tid] as $theme)

		{

		{

			$sel = "";
// Show theme if allowed, or if override is on
if(is_member($theme['allowedgroups']) || $theme['allowedgroups'] == "all" || $usergroup_override == true)

			$sel = "";
// Show theme if allowed, or if override is on
if(is_member($theme['allowedgroups']) || $theme['allowedgroups'] == "all" || $usergroup_override == true)

Zeile 5047Zeile 5188
					build_theme_select($name, $selected, $theme['tid'], $depthit, $usergroup_override, $footer, $count_override);
}
}

					build_theme_select($name, $selected, $theme['tid'], $depthit, $usergroup_override, $footer, $count_override);
}
}

		}
}


		}
}


	if($tid == 1 && ($num_themes > 1 || $count_override == true))
{
if($footer == true)

	if($tid == 1 && ($num_themes > 1 || $count_override == true))
{
if($footer == true)

		{

		{

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

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

Zeile 5062Zeile 5203
		}

return $themeselect;

		}

return $themeselect;

	}

	}

	else
{
return false;

	else
{
return false;

Zeile 5099Zeile 5240
			{
$s_theme = $theme;
break 2;

			{
$s_theme = $theme;
break 2;

			}

			}

		}
}


		}
}


Zeile 5301Zeile 5442
		31,
30,
31

		31,
30,
31

	);

	);

}

/**

}

/**

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 5401Zeile 5541
	}

return str_replace($find, $replace, $display);

	}

return str_replace($find, $replace, $display);

}


}


/**
* Returns the age of a user with specified birthday.
*

/**
* Returns the age of a user with specified birthday.
*

Zeile 5413Zeile 5553
{
$bday = explode("-", $birthday);
if(!$bday[2])

{
$bday = explode("-", $birthday);
if(!$bday[2])

	{

	{

		return;
}


		return;
}


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

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

	}

	}

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

$update_array = array(

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

$update_array = array(

Zeile 5501Zeile 5641
		$lastpost['username'] = $firstpost['username'];
$lastpost['uid'] = $firstpost['uid'];
$lastpost['dateline'] = $firstpost['dateline'];

		$lastpost['username'] = $firstpost['username'];
$lastpost['uid'] = $firstpost['uid'];
$lastpost['dateline'] = $firstpost['dateline'];

	}

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

	}

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


$update_array = array(
'lastpost' => (int)$lastpost['dateline'],


$update_array = array(
'lastpost' => (int)$lastpost['dateline'],

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 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 5883Zeile 6045
	{
$link = str_replace("{tid}", $tid, THREAD_URL_POST);
$link = str_replace("{pid}", $pid, $link);

	{
$link = str_replace("{tid}", $tid, THREAD_URL_POST);
$link = str_replace("{pid}", $pid, $link);

		return htmlspecialchars_uni($link);
}
else
{

		return htmlspecialchars_uni($link);
}
else
{

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

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

Zeile 6140Zeile 6302
	$pid = (int)$pid;

if(isset($post_cache[$pid]))

	$pid = (int)$pid;

if(isset($post_cache[$pid]))

	{

	{

		return $post_cache[$pid];
}
else

		return $post_cache[$pid];
}
else

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;







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

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

	}

	}

	// 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;




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





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

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







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

		return false;



	}


	}


	// Work out if the user has had more than the allowed number of login attempts
if($loginattempts > $mybb->settings['failedlogincount'])

	if($mybb->settings['failedlogincount'] > 0 && $attempts['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;
}











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

		else
{

			$failedtime = $mybb->cookies['failedlogin'];

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

		}


		}


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

		// 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));
}

return false;
}

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

return false;
}

 
		// Unlock if enough time has passed
else {





		// 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))
{
if($fatal)

			if($uid > 0)


















			{

			{

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




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

			}


			}


			return false;




			// 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 6341Zeile 6507
{
global $db, $mybb;


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

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















	$settings = null;

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

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 6484Zeile 6639
	}

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 6498Zeile 6665
	$dest = '';

if($src < 0)

	$dest = '';

if($src < 0)

	{

	{

		return false;

		return false;

	}

	}

	elseif($src <= 0x007f)

	elseif($src <= 0x007f)

	{

	{

		$dest .= chr($src);

		$dest .= chr($src);

	}

	}

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

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

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

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

	elseif($src <= 0xffff)
{
$dest .= chr(0xe0 | ($src >> 12));

	elseif($src <= 0xffff)
{
$dest .= chr(0xe0 | ($src >> 12));

Zeile 6530Zeile 6697
	}

return $dest;

	}

return $dest;

}


}


/**
* Checks if a username has been disallowed for registration/use.
*

/**
* Checks if a username has been disallowed for registration/use.
*

Zeile 6575Zeile 6742
	$banned_cache = $cache->read("bannedemails");

if($banned_cache === false)

	$banned_cache = $cache->read("bannedemails");

if($banned_cache === false)

	{

	{

		// 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");

Zeile 6826Zeile 6993
			elseif($destination_address == $disallowed_address)
{
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 6841Zeile 7008
	}

if(function_exists("curl_init"))

	}

if(function_exists("curl_init"))

	{

	{

		$fetch_header = $max_redirects > 0;

$ch = curl_init();

		$fetch_header = $max_redirects > 0;

$ch = curl_init();

Zeile 6871Zeile 7038
		{
// CURLOPT_CONNECT_TO
$curlopt[10243] = array(

		{
// CURLOPT_CONNECT_TO
$curlopt[10243] = array(

				$url_components['host'].':'.$url_components['port'].':'.$destination_address
);
}

				$url_components['host'].':'.$url_components['port'].':'.$destination_address
);
}

		elseif(version_compare(PHP_VERSION, '5.5', '>=') && version_compare($curl_version, '7.21.3', '>='))

		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

			// CURLOPT_RESOLVE
$curlopt[10203] = array(
$url_components['host'].':'.$url_components['port'].':'.$destination_address

Zeile 6886Zeile 7053
		{
$curlopt[CURLOPT_POST] = 1;
$curlopt[CURLOPT_POSTFIELDS] = $post_body;

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

		}

curl_setopt_array($ch, $curlopt);

		}

curl_setopt_array($ch, $curlopt);


$response = curl_exec($ch);



$response = curl_exec($ch);


Zeile 6952Zeile 7119
						'verify_peer_name' => true,
'peer_name' => $url_components['host'],
'cafile' => $ca_bundle_path,

						'verify_peer_name' => true,
'peer_name' => $url_components['host'],
'cafile' => $ca_bundle_path,

					),
));
}

					),
));
}

			else
{
$context = stream_context_create(array(

			else
{
$context = stream_context_create(array(

Zeile 6966Zeile 7133
			}

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

			}

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

		}
else

		}
else

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

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

Zeile 6983Zeile 7150
			$headers[] = "POST {$url_components['path']} HTTP/1.0";
$headers[] = "Content-Length: ".strlen($post_body);
$headers[] = "Content-Type: application/x-www-form-urlencoded";

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

		}

		}

		else
{
$headers[] = "GET {$url_components['path']} HTTP/1.0";

		else
{
$headers[] = "GET {$url_components['path']} HTTP/1.0";

Zeile 7012Zeile 7179
		$data = null;

while(!feof($fp))

		$data = null;

while(!feof($fp))

		{
$data .= fgets($fp, 12800);
}

		{
$data .= fgets($fp, 12800);
}

		fclose($fp);

$data = explode("\r\n\r\n", $data, 2);

		fclose($fp);

$data = explode("\r\n\r\n", $data, 2);

Zeile 7062Zeile 7229
		if($result_set)
{
$addresses = array_column($result_set, 'ip');

		if($result_set)
{
$addresses = array_column($result_set, 'ip');

		}

		}

		else
{
return false;
}
}

		else
{
return false;
}
}





	return $addresses;
}


	return $addresses;
}


Zeile 7078Zeile 7245
 * @return string|bool The location of the CA bundle, false if not set
*/
function get_ca_bundle_path()

 * @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('openssl.cafile'))
{
return $path;

Zeile 7583Zeile 7750
					array('::', '(int)"$1"?"$1":"0$1"'),
$r);
return $r;

					array('::', '(int)"$1"?"$1":"0$1"'),
$r);
return $r;

		}
return false;
}
}

/**

		}
return false;
}
}

/**

 * Fetch an binary formatted range for searching IPv4 and IPv6 IP addresses.
*
* @param string $ipaddress The IP address to convert to a range

 * Fetch an binary formatted range for searching IPv4 and IPv6 IP addresses.
*
* @param string $ipaddress The IP address to convert to a range

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

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

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

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

		else
{
// IPv4

		else
{
// IPv4

Zeile 7667Zeile 7834
			$bit = decbin(ord($ip_pack[$i]));
$bit = str_pad($bit, 8, '0', STR_PAD_LEFT);
$ip_bits .= $bit;

			$bit = decbin(ord($ip_pack[$i]));
$bit = str_pad($bit, 8, '0', STR_PAD_LEFT);
$ip_bits .= $bit;

		}

		}


// Significative bits (from the ip range)
$ip_bits = substr($ip_bits, 0, $ip_range);


// Significative bits (from the ip range)
$ip_bits = substr($ip_bits, 0, $ip_range);

Zeile 7713Zeile 7880
	static $time_start;

$time = microtime(true);

	static $time_start;

$time = microtime(true);



 

// Just starting timer, init and return
if(!$time_start)


// Just starting timer, init and return
if(!$time_start)

Zeile 7784Zeile 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 7971Zeile 8137
{
$bytes = PHP_INT_SIZE;


{
$bytes = PHP_INT_SIZE;


	do
{


	do
{


		$output = secure_binary_seed_rng($bytes);

// convert binary data to a decimal number
if ($bytes == 4)

		$output = secure_binary_seed_rng($bytes);

// convert binary data to a decimal number
if ($bytes == 4)

		{

		{

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

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

Zeile 7986Zeile 8152
		{
$elements = unpack('N2', $output);
$output = abs($elements[1] << 32 | $elements[2]);

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

		}

} while($output > PHP_INT_MAX);


		}

} while($output > PHP_INT_MAX);


	return $output;
}


	return $output;
}


Zeile 8021Zeile 8187
			return $result;
}
}

			return $result;
}
}





	$seed = secure_seed_rng();

$distance = $max - $min;

	$seed = secure_seed_rng();

$distance = $max - $min;

Zeile 8098Zeile 8264
		0xB9 => array(0xBF => array(0xEF => 1)), // \x{FFF9}
0xBA => array(0xBF => array(0xEF => 1)), // \x{FFFA}
0xBB => array(0xBF => array(0xEF => 1)), // \x{FFFB}

		0xB9 => array(0xBF => array(0xEF => 1)), // \x{FFF9}
0xBA => array(0xBF => array(0xEF => 1)), // \x{FFFA}
0xBB => array(0xBF => array(0xEF => 1)), // \x{FFFB}

	);


	);


	// Start from the beginning and work our way in
do
{

	// Start from the beginning and work our way in
do
{

Zeile 8352Zeile 8518
	}

if(isset($pm['language']))

	}

if(isset($pm['language']))

	{

	{

		if($pm['language'] != $mybb->user['language'] && $lang->language_exists($pm['language']))
{
// Load user language

		if($pm['language'] != $mybb->user['language'] && $lang->language_exists($pm['language']))
{
// Load user language

Zeile 8443Zeile 8609
	}

$pm['options'] = array(

	}

$pm['options'] = array(

		"signature" => 0,

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

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

Zeile 8580Zeile 8745
 *
* @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)

	{

	{

		return true;





		$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 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 = '')

{

{

	$pattern = array(
'@(&lt;)style[^(&gt;)]*?(&gt;).*?(&lt;)/style(&gt;)@siu',
'@(&lt;)script[^(&gt;)]*?.*?(&lt;)/script(&gt;)@siu',

	$pattern = array(
'@(&lt;)style[^(&gt;)]*?(&gt;).*?(&lt;)/style(&gt;)@siu',
'@(&lt;)script[^(&gt;)]*?.*?(&lt;)/script(&gt;)@siu',

Zeile 8611Zeile 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;

}

}