Vergleich inc/functions.php - 1.8.11 - 1.8.21

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 18Zeile 18
	global $db, $lang, $theme, $templates, $plugins, $mybb;
global $debug, $templatecache, $templatelist, $maintimer, $globaltime, $parsetime;


	global $db, $lang, $theme, $templates, $plugins, $mybb;
global $debug, $templatecache, $templatelist, $maintimer, $globaltime, $parsetime;


 
	$contents = $plugins->run_hooks("pre_parse_page", $contents);

	$contents = parse_page($contents);
$totaltime = format_time_duration($maintimer->stop());
$contents = $plugins->run_hooks("pre_output_page", $contents);

	$contents = parse_page($contents);
$totaltime = format_time_duration($maintimer->stop());
$contents = $plugins->run_hooks("pre_output_page", $contents);

Zeile 322Zeile 323
/**
* 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 381
	}

$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 401
	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 438
			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 463
				$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 488
			{
$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 584Zeile 624
	// Guests get a special string
else
{

	// Guests get a special string
else
{

		return md5($session->useragent.$mybb->config['database']['username'].$mybb->settings['internal']['encryption_key']);

		return md5($session->sid.$mybb->config['database']['username'].$mybb->settings['internal']['encryption_key']);

	}
}


	}
}


Zeile 658Zeile 698
 * @return string The query string generated
*/
function build_parent_list($fid, $column="fid", $joiner="OR", $parentlist="")

 * @return string The query string generated
*/
function build_parent_list($fid, $column="fid", $joiner="OR", $parentlist="")

{

{

	if(!$parentlist)

	if(!$parentlist)

	{

	{

		$parentlist = get_parent_list($fid);

		$parentlist = get_parent_list($fid);

	}


	}


	$parentsexploded = explode(",", $parentlist);
$builtlist = "(";
$sep = '';

	$parentsexploded = explode(",", $parentlist);
$builtlist = "(";
$sep = '';





	foreach($parentsexploded as $key => $val)
{
$builtlist .= "$sep$column='$val'";
$sep = " $joiner ";

	foreach($parentsexploded as $key => $val)
{
$builtlist .= "$sep$column='$val'";
$sep = " $joiner ";

	}

$builtlist .= ")";

	}

$builtlist .= ")";


return $builtlist;
}


return $builtlist;
}

Zeile 688Zeile 728
function cache_forums($force=false)
{
global $forum_cache, $cache;

function cache_forums($force=false)
{
global $forum_cache, $cache;





	if($force == true)
{
$forum_cache = $cache->read("forums", 1);

	if($force == true)
{
$forum_cache = $cache->read("forums", 1);

Zeile 719Zeile 759

$forums = array();
if(!is_array($forums_by_parent))


$forums = array();
if(!is_array($forums_by_parent))

	{

	{

		$forum_cache = cache_forums();
foreach($forum_cache as $forum)
{

		$forum_cache = cache_forums();
foreach($forum_cache as $forum)
{

Zeile 728Zeile 768
				$forums_by_parent[$forum['pid']][$forum['fid']] = $forum;
}
}

				$forums_by_parent[$forum['pid']][$forum['fid']] = $forum;
}
}

	}

	}

	if(!is_array($forums_by_parent[$fid]))

	if(!is_array($forums_by_parent[$fid]))

	{

	{

		return $forums;
}

foreach($forums_by_parent[$fid] as $forum)

		return $forums;
}

foreach($forums_by_parent[$fid] as $forum)

	{

	{

		$forums[] = $forum['fid'];
$children = get_child_list($forum['fid']);
if(is_array($children))

		$forums[] = $forum['fid'];
$children = get_child_list($forum['fid']);
if(is_array($children))

Zeile 783Zeile 823
	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 829Zeile 869

foreach($errors as $error)
{


foreach($errors as $error)
{

		$errorlist .= "<li>".$error."</li>\n";

		eval("\$errorlist .= \"".$templates->get("error_inline_item")."\";");

	}

eval("\$errors = \"".$templates->get("error_inline")."\";");

	}

eval("\$errors = \"".$templates->get("error_inline")."\";");

Zeile 966Zeile 1006

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 1037
	{
return '';
}

	{
return '';
}

 

$page = (int)$page;


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


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





	$pages = ceil($count / $perpage);

	$pages = ceil($count / $perpage);





	$prevpage = '';
if($page > 1)
{

	$prevpage = '';
if($page > 1)
{

Zeile 1027Zeile 1069
	}

if($to > $pages)

	}

if($to > $pages)

	{
$to = $pages;

	{
$to = $pages;

		$from = $pages-$mybb->settings['maxmultipagelinks']+1;
if($from <= 0)
{

		$from = $pages-$mybb->settings['maxmultipagelinks']+1;
if($from <= 0)
{

Zeile 1039Zeile 1081
	if($to == 0)
{
$to = $pages;

	if($to == 0)
{
$to = $pages;

	}


	}


	$start = '';
if($from > 1)
{

	$start = '';
if($from > 1)
{

Zeile 1071Zeile 1113
		else
{
eval("\$mppage .= \"".$templates->get("multipage_page")."\";");

		else
{
eval("\$mppage .= \"".$templates->get("multipage_page")."\";");

		}
}

		}
}


$end = '';
if($to < $pages)


$end = '';
if($to < $pages)

Zeile 1088Zeile 1130

$nextpage = '';
if($page < $pages)


$nextpage = '';
if($page < $pages)

	{

	{

		$next = $page+1;
$page_url = fetch_page_url($url, $next);
eval("\$nextpage = \"".$templates->get("multipage_nextpage")."\";");

		$next = $page+1;
$page_url = fetch_page_url($url, $next);
eval("\$nextpage = \"".$templates->get("multipage_nextpage")."\";");

Zeile 1102Zeile 1144
		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 1136Zeile 1178
		// Remove "Page 1" to the defacto URL
$url = str_replace($find, array("", "", $page), $url);
return $url;

		// Remove "Page 1" to the defacto URL
$url = str_replace($find, array("", "", $page), $url);
return $url;

	}

	}

	else if(strpos($url, "{page}") === false)
{
// If no page identifier is specified we tack it on to the end of the URL

	else if(strpos($url, "{page}") === false)
{
// If no page identifier is specified we tack it on to the end of the URL

Zeile 1162Zeile 1204
/**
* 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;

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





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

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

	if($uid == 0)

	if($uid === null)

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

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

 
	}

// Its a guest. Return the group permissions directly from cache
if($uid == 0)
{
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 1202Zeile 1250
	else
{
return $mybb->usergroup;

	else
{
return $mybb->usergroup;

	}

	}

}

}





/**
* Fetch the usergroup permissions for a specific group or series of groups combined
*

/**
* Fetch the usergroup permissions for a specific group or series of groups combined
*

Zeile 1215Zeile 1263
{
global $cache, $groupscache, $grouppermignore, $groupzerogreater;


{
global $cache, $groupscache, $grouppermignore, $groupzerogreater;


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

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

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

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


if(count($groups) == 1)


if(count($groups) == 1)

	{

	{

		$groupscache[$gid]['all_usergroups'] = $gid;
return $groupscache[$gid];
}

		$groupscache[$gid]['all_usergroups'] = $gid;
return $groupscache[$gid];
}





	$usergroup = array();
$usergroup['all_usergroups'] = $gid;

foreach($groups as $gid)
{
if(trim($gid) == "" || empty($groupscache[$gid]))

	$usergroup = array();
$usergroup['all_usergroups'] = $gid;

foreach($groups as $gid)
{
if(trim($gid) == "" || empty($groupscache[$gid]))

		{

		{

			continue;
}

			continue;
}





		foreach($groupscache[$gid] as $perm => $access)
{
if(!in_array($perm, $grouppermignore))
{
if(isset($usergroup[$perm]))

		foreach($groupscache[$gid] as $perm => $access)
{
if(!in_array($perm, $grouppermignore))
{
if(isset($usergroup[$perm]))

				{

				{

					$permbit = $usergroup[$perm];

					$permbit = $usergroup[$perm];

				}

				}

				else
{
$permbit = "";

				else
{
$permbit = "";

				}


				}


				// 0 represents unlimited for numerical group permissions (i.e. private message limit) so take that into account.
if(in_array($perm, $groupzerogreater) && ($access == 0 || $permbit === 0))
{

				// 0 represents unlimited for numerical group permissions (i.e. private message limit) so take that into account.
if(in_array($perm, $groupzerogreater) && ($access == 0 || $permbit === 0))
{

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

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

	}

	}


$displaygroup = array();
$group = $groupscache[$gid];


$displaygroup = array();
$group = $groupscache[$gid];





	foreach($displaygroupfields as $field)
{
$displaygroup[$field] = $group[$field];

	foreach($displaygroupfields as $field)
{
$displaygroup[$field] = $group[$field];

Zeile 1297Zeile 1345

/**
* Build the forum permissions for a specific forum, user or group


/**
* Build the forum permissions for a specific forum, user or group

 *

 *

 * @param int $fid The forum ID to build permissions for (0 builds for all forums)
* @param int $uid The user to build the permissions for (0 will select the uid automatically)
* @param int $gid The group of the user to build permissions for (0 will fetch it)

 * @param int $fid The forum ID to build permissions for (0 builds for all forums)
* @param int $uid The user to build the permissions for (0 will select the uid automatically)
* @param int $gid The group of the user to build permissions for (0 will fetch it)

Zeile 1328Zeile 1376
			if(isset($mybb->user['additionalgroups']))
{
$gid .= ",".$mybb->user['additionalgroups'];

			if(isset($mybb->user['additionalgroups']))
{
$gid .= ",".$mybb->user['additionalgroups'];

			}


			}


			$groupperms = $mybb->usergroup;

			$groupperms = $mybb->usergroup;

		}
}

		}
}


if(!is_array($forum_cache))
{
$forum_cache = cache_forums();


if(!is_array($forum_cache))
{
$forum_cache = cache_forums();





		if(!$forum_cache)
{
return false;

		if(!$forum_cache)
{
return false;

		}
}


		}
}


	if(!is_array($fpermcache))
{
$fpermcache = $cache->read("forumpermissions");

	if(!is_array($fpermcache))
{
$fpermcache = $cache->read("forumpermissions");

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

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

			}


			}


			foreach($level_permissions as $permission => $access)
{
if(empty($current_permissions[$permission]) || $access >= $current_permissions[$permission] || ($access == "yes" && $current_permissions[$permission] == "no"))

			foreach($level_permissions as $permission => $access)
{
if(empty($current_permissions[$permission]) || $access >= $current_permissions[$permission] || ($access == "yes" && $current_permissions[$permission] == "no"))

Zeile 1774Zeile 1822
	$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 1804Zeile 1852
	if(!empty($iconlist))
{
eval("\$posticons = \"".$templates->get("posticons")."\";");

	if(!empty($iconlist))
{
eval("\$posticons = \"".$templates->get("posticons")."\";");

	}

	}

	else
{
$posticons = '';

	else
{
$posticons = '';

Zeile 1812Zeile 1860

return $posticons;
}


return $posticons;
}





/**
* MyBB setcookie() wrapper.
*

/**
* MyBB setcookie() wrapper.
*

Zeile 1820Zeile 1868
 * @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;

if(!$mybb->settings['cookiepath'])
{
$mybb->settings['cookiepath'] = "/";

{
global $mybb;

if(!$mybb->settings['cookiepath'])
{
$mybb->settings['cookiepath'] = "/";

	}


	}


	if($expires == -1)
{
$expires = 0;

	if($expires == -1)
{
$expires = 0;

Zeile 1868Zeile 1917
	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 1983Zeile 2042
		return false;
}


		return false;
}


	$stack = array();
$expected = array();

	$stack = $list = $expected = array();



/*
* states:


/*
* states:

Zeile 2060Zeile 2118
				{
$list[$key] = $value;
$state = 2;

				{
$list[$key] = $value;
$state = 2;

					break;

					break;

				}

// missing array value

				}

// missing array value

Zeile 2091Zeile 2149
					if(count($list) >= MAX_SERIALIZED_ARRAY_LENGTH)
{
// array size exceeds MAX_SERIALIZED_ARRAY_LENGTH

					if(count($list) >= MAX_SERIALIZED_ARRAY_LENGTH)
{
// array size exceeds MAX_SERIALIZED_ARRAY_LENGTH

						return false;
}

						return false;
}

					if(count($list) >= end($expected))
{
// array size exceeds expected length

					if(count($list) >= end($expected))
{
// array size exceeds expected length

Zeile 2186Zeile 2244
	}

if(is_bool($value))

	}

if(is_bool($value))

	{

	{

		return 'b:'.(int)$value.';';

		return 'b:'.(int)$value.';';

	}

	}


if(is_int($value))
{
return 'i:'.$value.';';


if(is_int($value))
{
return 'i:'.$value.';';

	}

	}


if(is_float($value))
{


if(is_float($value))
{

Zeile 2201Zeile 2259
	}

if(is_string($value))

	}

if(is_string($value))

	{

	{

		return 's:'.strlen($value).':"'.$value.'";';
}


		return 's:'.strlen($value).':"'.$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)
{
return $lang->unknown;

				if(strpos(",".$func_blacklist.",", 'exec') !== false)
{
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.
*
* @return int The amount of memory allocated to the script.

 * Returns the amount of memory allocated to the script.
*
* @return int The amount of memory allocated to the script.

Zeile 2360Zeile 2418
			'numdeletedthreads' => '+0',
'inserted' => false // Reset after changes are inserted into cache
);

			'numdeletedthreads' => '+0',
'inserted' => false // Reset after changes are inserted into cache
);

		$stats = $stats_changes;
}

		$stats = $stats_changes;
}


if($force) // Force writing to cache?
{


if($force) // Force writing to cache?
{

Zeile 2376Zeile 2434
	else
{
$stats = $stats_changes;

	else
{
$stats = $stats_changes;

	}

	}


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


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

Zeile 2392Zeile 2450
			if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
{
if((int)$changes[$counter] != 0)

			if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
{
if((int)$changes[$counter] != 0)

				{

				{

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

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

					{

					{

						// We had relative values? Then it is still relative
if($new_stats[$counter] >= 0)
{
$new_stats[$counter] = "+{$new_stats[$counter]}";
}

						// We had relative values? Then it is still relative
if($new_stats[$counter] >= 0)
{
$new_stats[$counter] = "+{$new_stats[$counter]}";
}

					}

					}

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

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

				}
}

				}
}

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

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

Zeile 2439Zeile 2497
	if(!empty($new_stats))
{
if(is_array($stats))

	if(!empty($new_stats))
{
if(is_array($stats))

		{

		{

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

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

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

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

			{

			{

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

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

			{

			{

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

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

			}

			}

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

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

			}


			}


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

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

Zeile 2530Zeile 2588
	}

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

	}

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

	{

	{

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

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

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

		if($unapprovedposts_diff > -1)
{
$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 2819Zeile 2877

/**
* Deletes a thread from the database


/**
* Deletes a thread from the database

 *

 *

 * @param int $tid The thread ID
* @return bool
*/
function delete_thread($tid)
{
global $moderation;

 * @param int $tid The thread ID
* @return bool
*/
function delete_thread($tid)
{
global $moderation;





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

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

Zeile 2834Zeile 2892
	}

return $moderation->delete_thread($tid);

	}

return $moderation->delete_thread($tid);

}

}


/**
* Deletes a post from the database


/**
* Deletes a post from the database

Zeile 2879Zeile 2937
		if(!is_array($forum_cache))
{
cache_forums();

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

		}


		}


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

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

Zeile 2888Zeile 2946
				$jumpfcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
}
}

				$jumpfcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
}
}

	}

	}


if(!is_array($permissioncache))
{


if(!is_array($permissioncache))
{

Zeile 2896Zeile 2954
	}

if(isset($jumpfcache[$pid]) && is_array($jumpfcache[$pid]))

	}

if(isset($jumpfcache[$pid]) && is_array($jumpfcache[$pid]))

	{

	{

		foreach($jumpfcache[$pid] as $main)
{
foreach($main as $forum)
{
$perms = $permissioncache[$forum['fid']];

		foreach($jumpfcache[$pid] as $main)
{
foreach($main as $forum)
{
$perms = $permissioncache[$forum['fid']];





				if($forum['fid'] != "0" && ($perms['canview'] != 0 || $mybb->settings['hideprivateforums'] == 0) && $forum['linkto'] == '' && ($forum['showinjump'] != 0 || $showall == true))
{
$optionselected = "";

				if($forum['fid'] != "0" && ($perms['canview'] != 0 || $mybb->settings['hideprivateforums'] == 0) && $forum['linkto'] == '' && ($forum['showinjump'] != 0 || $showall == true))
{
$optionselected = "";





					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")."\";");

Zeile 2943Zeile 3001
			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)."\";");
}


Zeile 2961Zeile 3019
function get_extension($file)
{
return my_strtolower(my_substr(strrchr($file, "."), 1));

function get_extension($file)
{
return my_strtolower(my_substr(strrchr($file, "."), 1));

}

}


/**
* Generates a random string.


/**
* Generates a random string.

Zeile 2977Zeile 3035

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

	{

	{

		// At least one number
$str[] = $set[my_rand(0, 9)];

// At least one big letter
$str[] = $set[my_rand(10, 35)];

		// At least one number
$str[] = $set[my_rand(0, 9)];

// At least one big letter
$str[] = $set[my_rand(10, 35)];





		// At least one small letter
$str[] = $set[my_rand(36, 61)];


		// At least one small letter
$str[] = $set[my_rand(36, 61)];


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

}

/**

}

/**

Zeile 3081Zeile 3155
	// An empty key wouldn't work so we need to add a fall back
$key = $dimensions;
if(empty($key))

	// An empty key wouldn't work so we need to add a fall back
$key = $dimensions;
if(empty($key))

	{

	{

		$key = 'default';
}
$key2 = $max_dimensions;

		$key = 'default';
}
$key2 = $max_dimensions;

Zeile 3099Zeile 3173

if($dimensions)
{


if($dimensions)
{

		$dimensions = explode("|", $dimensions);

		$dimensions = preg_split('/[|x]/', $dimensions);


if($dimensions[0] && $dimensions[1])
{


if($dimensions[0] && $dimensions[1])
{

			list($max_width, $max_height) = explode('x', $max_dimensions);

			list($max_width, $max_height) = preg_split('/[|x]/', $max_dimensions);


if(!empty($max_dimensions) && ($dimensions[0] > $max_width || $dimensions[1] > $max_height))
{


if(!empty($max_dimensions) && ($dimensions[0] > $max_width || $dimensions[1] > $max_height))
{

Zeile 3200Zeile 3274
			"editor_invalidyoutube" => "Invalid YouTube video",
"editor_dailymotion" => "Dailymotion",
"editor_metacafe" => "MetaCafe",

			"editor_invalidyoutube" => "Invalid YouTube video",
"editor_dailymotion" => "Dailymotion",
"editor_metacafe" => "MetaCafe",

			"editor_veoh" => "Veoh",

			"editor_mixer" => "Mixer",

			"editor_vimeo" => "Vimeo",
"editor_youtube" => "Youtube",
"editor_facebook" => "Facebook",

			"editor_vimeo" => "Vimeo",
"editor_youtube" => "Youtube",
"editor_facebook" => "Facebook",

Zeile 3210Zeile 3284
			"editor_maximize" => "Maximize"
);
$editor_language = "(function ($) {\n$.sceditor.locale[\"mybblang\"] = {\n";

			"editor_maximize" => "Maximize"
);
$editor_language = "(function ($) {\n$.sceditor.locale[\"mybblang\"] = {\n";





		$editor_lang_strings = $plugins->run_hooks("mycode_add_codebuttons", $editor_lang_strings);

$editor_languages_count = count($editor_lang_strings);

		$editor_lang_strings = $plugins->run_hooks("mycode_add_codebuttons", $editor_lang_strings);

$editor_languages_count = count($editor_lang_strings);

Zeile 3370Zeile 3444
	}

return $codeinsert;

	}

return $codeinsert;

 
}

/**
* @param int $tid
* @param array $postoptions The options carried with form submit
*
* @return string Predefined / updated subscription method of the thread for the user
*/
function get_subscription_method($tid = 0, $postoptions = array())
{
global $mybb;

$subscription_methods = array('', 'none', 'email', 'pm'); // Define methods
$subscription_method = (int)$mybb->user['subscriptionmethod']; // Set user default

// If no user default method available then reset method
if(!$subscription_method)
{
$subscription_method = 0;
}

// Return user default if no thread id available, in case
if(!(int)$tid || (int)$tid <= 0)
{
return $subscription_methods[$subscription_method];
}

// If method not predefined set using data from database
if(isset($postoptions['subscriptionmethod']))
{
$method = trim($postoptions['subscriptionmethod']);
return (in_array($method, $subscription_methods)) ? $method : $subscription_methods[0];
}
else
{
global $db;

$query = $db->simple_select("threadsubscriptions", "tid, notification", "tid='".(int)$tid."' AND uid='".$mybb->user['uid']."'", array('limit' => 1));
$subscription = $db->fetch_array($query);

if($subscription['tid'])
{
$subscription_method = (int)$subscription['notification'] + 1;
}
}

return $subscription_methods[$subscription_method];

}

/**

}

/**

Zeile 3384Zeile 3505
	if($mybb->settings['smilieinserter'] != 0 && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'])
{
if(!$smiliecount)

	if($mybb->settings['smilieinserter'] != 0 && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'])
{
if(!$smiliecount)

		{

		{

			$smilie_cache = $cache->read("smilies");
$smiliecount = count($smilie_cache);
}

			$smilie_cache = $cache->read("smilies");
$smiliecount = count($smilie_cache);
}

Zeile 3407Zeile 3528
		if(is_array($smiliecache))
{
reset($smiliecache);

		if(is_array($smiliecache))
{
reset($smiliecache);





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

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

			{

			{

				$mybb->settings['smilieinsertertot'] = $smiliecount;
}
else if($mybb->settings['smilieinsertertot'] < $smiliecount)
{
$smiliecount = $mybb->settings['smilieinsertertot'];
eval("\$getmore = \"".$templates->get("smilieinsert_getmore")."\";");

				$mybb->settings['smilieinsertertot'] = $smiliecount;
}
else if($mybb->settings['smilieinsertertot'] < $smiliecount)
{
$smiliecount = $mybb->settings['smilieinsertertot'];
eval("\$getmore = \"".$templates->get("smilieinsert_getmore")."\";");

			}


			}


			$smilies = '';
$counter = 0;
$i = 0;

			$smilies = '';
$counter = 0;
$i = 0;

Zeile 3452Zeile 3573
						$smilie_icons = '';
}
}

						$smilie_icons = '';
}
}

			}


			}


			if($counter != 0)
{
$colspan = $mybb->settings['smilieinsertercols'] - $counter;

			if($counter != 0)
{
$colspan = $mybb->settings['smilieinsertercols'] - $counter;

Zeile 3461Zeile 3582
			}

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

			}

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

		}
else
{

		}
else
{

			$clickablesmilies = "";
}
}

			$clickablesmilies = "";
}
}

Zeile 3781Zeile 3902
	{
$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 3927
		"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 3951Zeile 4095
	}
// Zetabyte (1024 Exabytes)
elseif($size >= 1180591620717411303424)

	}
// Zetabyte (1024 Exabytes)
elseif($size >= 1180591620717411303424)

	{

	{

		$size = my_number_format(round(($size / 1180591620717411303424), 2))." ".$lang->size_zb;
}
// Exabyte (1024 Petabytes)

		$size = my_number_format(round(($size / 1180591620717411303424), 2))." ".$lang->size_zb;
}
// Exabyte (1024 Petabytes)

Zeile 4240Zeile 4384
				eval("\$nav .= \"".$templates->get("nav_bit")."\";");
}
}

				eval("\$nav .= \"".$templates->get("nav_bit")."\";");
}
}

 
		$navsize = count($navbits);
$navbit = $navbits[$navsize-1];

	}

	}


$activesep = '';
$navsize = count($navbits);
$navbit = $navbits[$navsize-1];

 

if($nav)
{


if($nav)
{

Zeile 4675Zeile 4817
	$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)

	elseif($weeks > 0)




















	{

	{

		$nicetime['days'] = "1".$lang_day;




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

	}

	}

	else if($days > 1)

	elseif($days > 0)

	{

	{

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



















































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

Zeile 4745Zeile 4931
		{
$nicetime['seconds'] = $seconds.$lang_seconds;
}

		{
$nicetime['seconds'] = $seconds.$lang_seconds;
}

	}


	}


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

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

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

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

	}

	}

	else
{
$trow = "trow1";
}

	else
{
$trow = "trow1";
}





	$alttrow = $trow;

	$alttrow = $trow;





	return $trow;

	return $trow;

}


}


/**
* Add a user to a specific additional user group.
*

/**
* Add a user to a specific additional user group.
*

Zeile 4787Zeile 4973
function join_usergroup($uid, $joingroup)
{
global $db, $mybb;

function join_usergroup($uid, $joingroup)
{
global $db, $mybb;





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

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

	{

	{

		$user = $mybb->user;

		$user = $mybb->user;

	}

	}

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

	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 4993
	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 4816Zeile 5002
				$donegroup[$gid] = 1;
}
}

				$donegroup[$gid] = 1;
}
}

	}


	}


	// What's the point in updating if they're the same?
if($groupslist != $user['additionalgroups'])
{

	// What's the point in updating if they're the same?
if($groupslist != $user['additionalgroups'])
{

Zeile 4857Zeile 5043
				$groupslist .= $comma.$gid;
$comma = ",";
$donegroup[$gid] = 1;

				$groupslist .= $comma.$gid;
$comma = ",";
$donegroup[$gid] = 1;

			}

			}

		}

		}

	}


	}


	$dispupdate = "";
if($leavegroup == $user['displaygroup'])
{
$dispupdate = ", displaygroup=usergroup";

	$dispupdate = "";
if($leavegroup == $user['displaygroup'])
{
$dispupdate = ", displaygroup=usergroup";

	}


	}


	$db->write_query("
UPDATE ".TABLE_PREFIX."users
SET additionalgroups='$groupslist' $dispupdate

	$db->write_query("
UPDATE ".TABLE_PREFIX."users
SET additionalgroups='$groupslist' $dispupdate

Zeile 4896Zeile 5082
		$location = htmlspecialchars_uni($_SERVER['SCRIPT_NAME']);
}
elseif(!empty($_SERVER['PHP_SELF']))

		$location = htmlspecialchars_uni($_SERVER['SCRIPT_NAME']);
}
elseif(!empty($_SERVER['PHP_SELF']))

	{

	{

		$location = htmlspecialchars_uni($_SERVER['PHP_SELF']);

		$location = htmlspecialchars_uni($_SERVER['PHP_SELF']);

	}

	}

	elseif(!empty($_ENV['PHP_SELF']))

	elseif(!empty($_ENV['PHP_SELF']))

	{

	{

		$location = htmlspecialchars_uni($_ENV['PHP_SELF']);

		$location = htmlspecialchars_uni($_ENV['PHP_SELF']);

	}

	}

	elseif(!empty($_SERVER['PATH_INFO']))
{
$location = htmlspecialchars_uni($_SERVER['PATH_INFO']);

	elseif(!empty($_SERVER['PATH_INFO']))
{
$location = htmlspecialchars_uni($_SERVER['PATH_INFO']);

	}

	}

	else

	else

	{

	{

		$location = htmlspecialchars_uni($_ENV['PATH_INFO']);

		$location = htmlspecialchars_uni($_ENV['PATH_INFO']);

	}

	}


if($quick)
{
return $location;
}


if($quick)
{
return $location;
}





	if($fields == true)
{
global $mybb;

	if($fields == true)
{
global $mybb;

Zeile 4937Zeile 5123
				}

$form_html .= "<input type=\"hidden\" name=\"".htmlspecialchars_uni($name)."\" value=\"".htmlspecialchars_uni($value)."\" />\n";

				}

$form_html .= "<input type=\"hidden\" name=\"".htmlspecialchars_uni($name)."\" value=\"".htmlspecialchars_uni($value)."\" />\n";

			}
}

			}
}


return array('location' => $location, 'form_html' => $form_html, 'form_method' => $mybb->request_method);
}
else
{
if(isset($_SERVER['QUERY_STRING']))


return array('location' => $location, 'form_html' => $form_html, 'form_method' => $mybb->request_method);
}
else
{
if(isset($_SERVER['QUERY_STRING']))

		{

		{

			$location .= "?".htmlspecialchars_uni($_SERVER['QUERY_STRING']);

			$location .= "?".htmlspecialchars_uni($_SERVER['QUERY_STRING']);

		}

		}

		else if(isset($_ENV['QUERY_STRING']))

		else if(isset($_ENV['QUERY_STRING']))

		{

		{

			$location .= "?".htmlspecialchars_uni($_ENV['QUERY_STRING']);
}

if((isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "POST") || (isset($_ENV['REQUEST_METHOD']) && $_ENV['REQUEST_METHOD'] == "POST"))

			$location .= "?".htmlspecialchars_uni($_ENV['QUERY_STRING']);
}

if((isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "POST") || (isset($_ENV['REQUEST_METHOD']) && $_ENV['REQUEST_METHOD'] == "POST"))

		{

		{

			$post_array = array('action', 'fid', 'pid', 'tid', 'uid', 'eid');

foreach($post_array as $var)

			$post_array = array('action', 'fid', 'pid', 'tid', 'uid', 'eid');

foreach($post_array as $var)

Zeile 4962Zeile 5148
				if(isset($_POST[$var]))
{
$addloc[] = urlencode($var).'='.urlencode($_POST[$var]);

				if(isset($_POST[$var]))
{
$addloc[] = urlencode($var).'='.urlencode($_POST[$var]);

				}
}

				}
}


if(isset($addloc) && is_array($addloc))
{


if(isset($addloc) && is_array($addloc))
{

Zeile 5008Zeile 5194
		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))
{
$query = $db->simple_select('themes', 'tid, name, pid, allowedgroups', "pid!='0'");

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

		}
}

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

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


if(is_array($tcache[$tid]))
{


if(is_array($tcache[$tid]))
{

Zeile 5030Zeile 5216
			if(is_member($theme['allowedgroups']) || $theme['allowedgroups'] == "all" || $usergroup_override == true)
{
if($theme['tid'] == $selected)

			if(is_member($theme['allowedgroups']) || $theme['allowedgroups'] == "all" || $usergroup_override == true)
{
if($theme['tid'] == $selected)

				{

				{

					$sel = " selected=\"selected\"";
}


					$sel = " selected=\"selected\"";
}


Zeile 5040Zeile 5226
					eval("\$themeselect_option .= \"".$templates->get("usercp_themeselector_option")."\";");
++$num_themes;
$depthit = $depth."--";

					eval("\$themeselect_option .= \"".$templates->get("usercp_themeselector_option")."\";");
++$num_themes;
$depthit = $depth."--";

				}

				}


if(array_key_exists($theme['tid'], $tcache))
{


if(array_key_exists($theme['tid'], $tcache))
{

Zeile 5059Zeile 5245
		else
{
eval("\$themeselect = \"".$templates->get("usercp_themeselector")."\";");

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

		}


		}


		return $themeselect;
}
else

		return $themeselect;
}
else

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

			{
$s_theme = $theme;
break 2;

			}
}
}

			}
}
}


return $s_theme;
}


return $s_theme;
}

Zeile 5132Zeile 5318
	global $mybb;

if($number == "-")

	global $mybb;

if($number == "-")

	{

	{

		return $number;
}


		return $number;
}


Zeile 5152Zeile 5338
		{
$decimals = 0;
}

		{
$decimals = 0;
}





		return number_format((double)$number, $decimals, $mybb->settings['decpoint'], $mybb->settings['thousandssep']);
}
}

		return number_format((double)$number, $decimals, $mybb->settings['decpoint'], $mybb->settings['thousandssep']);
}
}

Zeile 5172Zeile 5358
	static $use_iconv;

if(!isset($charset))

	static $use_iconv;

if(!isset($charset))

	{

	{

		$charset = my_strtolower($lang->settings['charset']);

		$charset = my_strtolower($lang->settings['charset']);

	}


	}


	if($charset == "utf-8")
{
return $str;
}

if(!isset($use_iconv))

	if($charset == "utf-8")
{
return $str;
}

if(!isset($use_iconv))

	{

	{

		$use_iconv = function_exists("iconv");
}


		$use_iconv = function_exists("iconv");
}


Zeile 5344Zeile 5530
		$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 5669Zeile 5854
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 5895
	{
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 5990
	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 5888Zeile 6095
	else
{
$link = str_replace("{pid}", $pid, POST_URL);

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

		return htmlspecialchars_uni($link);
}
}

/**

		return htmlspecialchars_uni($link);
}
}

/**

 * Build the event link.
*
* @param int $eid The event ID of the event

 * Build the event link.
*
* @param int $eid The event ID of the event

Zeile 5901Zeile 6108
function get_event_link($eid)
{
$link = str_replace("{eid}", $eid, EVENT_URL);

function get_event_link($eid)
{
$link = str_replace("{eid}", $eid, EVENT_URL);

	return htmlspecialchars_uni($link);
}

/**

	return htmlspecialchars_uni($link);
}

/**

 * Build the link to a specified date on the calendar
*
* @param int $calendar The ID of the calendar

 * Build the link to a specified date on the calendar
*
* @param int $calendar The ID of the calendar

Zeile 5981Zeile 6188
		return $user_cache[$uid];
}
elseif($uid > 0)

		return $user_cache[$uid];
}
elseif($uid > 0)

	{

	{

		$query = $db->simple_select("users", "*", "uid = '{$uid}'");
$user_cache[$uid] = $db->fetch_array($query);


		$query = $db->simple_select("users", "*", "uid = '{$uid}'");
$user_cache[$uid] = $db->fetch_array($query);


Zeile 6002Zeile 6209
	global $mybb, $db;

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

	global $mybb, $db;

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





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

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

Zeile 6045Zeile 6252
	if(isset($options['exists']))
{
return (bool)$db->num_rows($query);

	if(isset($options['exists']))
{
return (bool)$db->num_rows($query);

	}


	}


	return $db->fetch_array($query);
}


	return $db->fetch_array($query);
}


Zeile 6068Zeile 6275
	}

if(empty($forum_cache[$fid]))

	}

if(empty($forum_cache[$fid]))

	{
return false;
}

	{
return false;
}


if($active_override != 1)
{


if($active_override != 1)
{

Zeile 6088Zeile 6295
	}

return $forum_cache[$fid];

	}

return $forum_cache[$fid];

}


}


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

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

Zeile 6121Zeile 6328
		else
{
$thread_cache[$tid] = false;

		else
{
$thread_cache[$tid] = false;

			return false;
}

			return false;
}

	}
}


	}
}


Zeile 6156Zeile 6363
		else
{
$post_cache[$pid] = false;

		else
{
$post_cache[$pid] = false;

			return false;
}
}
}


			return false;
}
}
}


/**
* Get inactivate forums.
*

/**
* Get inactivate forums.
*

Zeile 6183Zeile 6390
		{
$inactive[] = $fid;
foreach($forum_cache as $fid1 => $forum1)

		{
$inactive[] = $fid;
foreach($forum_cache as $fid1 => $forum1)

			{

			{

				if(my_strpos(",".$forum1['parentlist'].",", ",".$fid.",") !== false && !in_array($fid1, $inactive))
{
$inactive[] = $fid1;

				if(my_strpos(",".$forum1['parentlist'].",", ",".$fid.",") !== false && !in_array($fid1, $inactive))
{
$inactive[] = $fid1;

Zeile 6203Zeile 6410
 * @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;

if($mybb->settings['failedlogincount'] == 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;

	global $mybb, $lang, $db;
















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



























	$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)
{
$query = $db->simple_select("users", "loginattempts, loginlockoutexpiry", "uid='{$uid}'", 1);
$attempts = $db->fetch_array($query);

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

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

return false;

	}


	}


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

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

	{

	{

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

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

		// Set the expiry dateline if not set yet
if($attempts['loginlockoutexpiry'] == 0)










		{

		{

			$failedtime = $now;














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

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






		{

		{

			my_setcookie('failedlogin', $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)

			if($uid > 0)






			{

			{

				$update_array = array(
'loginattempts' => 1
);
$db->update_query("users", $update_array, "uid = '{$mybb->user['uid']}'");

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

			}

			}

			return 1;
}
// Not waited long enough
else if($mybb->cookies['failedlogin'] > ($now - $mybb->settings['failedlogintime'] * 60))
{
if($fatal)
{
error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft));
}

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'];
}


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

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

Zeile 6299Zeile 6515
 */
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 6315Zeile 6526
 * @return boolean True when in use, false when not.
*/
function email_already_in_use($email, $uid=0)

 * @return boolean True when in use, false when not.
*/
function email_already_in_use($email, $uid=0)

{

{

	global $db;

$uid_string = "";
if($uid)
{
$uid_string = " AND uid != '".(int)$uid."'";

	global $db;

$uid_string = "";
if($uid)
{
$uid_string = " AND uid != '".(int)$uid."'";

	}

	}

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

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

	}


	}


	return false;
}


	return false;
}


Zeile 6341Zeile 6552
{
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 6566
	}

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

// 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 6684
	}

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 7432Zeile 7644
 * @param array $array The array of forums
* @return integer The number of sub forums
*/

 * @param array $array The array of forums
* @return integer The number of sub forums
*/

function subforums_count($array)

function subforums_count($array=array())

{
$count = 0;
foreach($array as $array2)

{
$count = 0;
foreach($array as $array2)

Zeile 7713Zeile 7925
	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 7995
				{
$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 8383Zeile 8594
		}

if(isset($revert))

		}

if(isset($revert))

		{

		{

			// Revert language
$lang->set_language($mybb->user['language']);
$lang->load($pm['language_file']);

			// Revert language
$lang->set_language($mybb->user['language']);
$lang->load($pm['language_file']);

Zeile 8443Zeile 8654
	}

$pm['options'] = array(

	}

$pm['options'] = array(

		"signature" => 0,

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

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

Zeile 8580Zeile 8790
 *
* @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 8831
	);
$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;
}

// Fallback function for 'array_column', PHP < 5.5.0 compatibility
if(!function_exists('array_column'))
{
function array_column($input, $column_key)
{
$values = array();
if(!is_array($input))
{
$input = array($input);
}
foreach($input as $val)
{
if(is_array($val) && isset($val[$column_key]))
{
$values[] = $val[$column_key];
}
elseif(is_object($val) && isset($val->$column_key))
{
$values[] = $val->$column_key;
}
}
return $values;
}
}

/**
* Performs a timing attack safe string comparison.
*
* @param string $known_string The first string to be compared.
* @param string $user_string The second, user-supplied string to be compared.
* @return bool Result of the comparison.
*/
function my_hash_equals($known_string, $user_string)
{
if(version_compare(PHP_VERSION, '5.6.0', '>='))
{
return hash_equals($known_string, $user_string);
}
else
{
$known_string_length = my_strlen($known_string);
$user_string_length = my_strlen($user_string);

if($user_string_length != $known_string_length)
{
return false;
}

$result = 0;

for($i = 0; $i < $known_string_length; $i++)
{
$result |= ord($known_string[$i]) ^ ord($user_string[$i]);
}

return $result === 0;
}
}

/**
* Retrieves all referrals for a specified user
*
* @param int uid
* @param int start position
* @param int total entries
* @param bool false (default) only return display info, true for all info
* @return array
*/
function get_user_referrals($uid, $start=0, $limit=0, $full=false)
{
global $db;

$referrals = $query_options = array();
$uid = (int) $uid;

if($uid === 0)
{
return $referrals;
}

if($start && $limit)
{
$query_options['limit_start'] = $start;
}

if($limit)
{
$query_options['limit'] = $limit;
}

$fields = 'uid, username, usergroup, displaygroup, regdate';
if($full === true)
{
$fields = '*';
}

$query = $db->simple_select('users', $fields, "referrer='{$uid}'", $query_options);

while($referral = $db->fetch_array($query))
{
$referrals[] = $referral;
}

return $referrals;

}

}