Vergleich inc/functions.php - 1.8.6 - 1.8.12

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

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

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

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

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

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

			$offset =  $mybbadmin['timezone'];

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

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

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

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

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

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


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


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

		if($ty != 2 && abs(TIME_NOW - $stamp) < 3600)
{
$diff = TIME_NOW - $stamp;

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


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


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

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

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

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

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

		}
else
{

Zeile 456Zeile 470
			{
if($todaysdate == $date)
{

			{
if($todaysdate == $date)
{

					$date = $lang->today;

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

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

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

					$date = $lang->yesterday;

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

				}
}


				}
}


Zeile 481Zeile 495
		{
if($todaysdate == $date)
{

		{
if($todaysdate == $date)
{

				$date = $lang->today;

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

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

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

				$date = $lang->yesterday;

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

			}
}
else

			}
}
else

Zeile 598Zeile 612
function verify_post_check($code, $silent=false)
{
global $lang;

function verify_post_check($code, $silent=false)
{
global $lang;

	if(generate_post_check() != $code)

	if(generate_post_check() !== $code)

	{
if($silent == true)
{

	{
if($silent == true)
{

Zeile 768Zeile 782
		// Send our headers.
@header("Content-type: application/json; charset={$lang->settings['charset']}");
echo json_encode(array("errors" => array($error)));

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

		exit;
}

if(!$title)

		exit;
}

if(!$title)

	{
$title = $mybb->settings['bbname'];
}

	{
$title = $mybb->settings['bbname'];
}

Zeile 801Zeile 815
	if(!$title)
{
$title = $lang->please_correct_errors;

	if(!$title)
{
$title = $lang->please_correct_errors;

	}


	}


	if(!is_array($errors))

	if(!is_array($errors))

	{

	{

		$errors = array($errors);
}


		$errors = array($errors);
}


Zeile 817Zeile 831
		if(empty($json_data))
{
echo json_encode(array("errors" => $errors));

		if(empty($json_data))
{
echo json_encode(array("errors" => $errors));

		}

		}

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

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

	}

$errorlist = '';

	}

$errorlist = '';


foreach($errors as $error)
{
$errorlist .= "<li>".$error."</li>\n";


foreach($errors as $error)
{
$errorlist .= "<li>".$error."</li>\n";

	}

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

	}

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


return $errors;
}


return $errors;
}

Zeile 861Zeile 875
		header("Content-type: application/json; charset={$lang->settings['charset']}");
echo json_encode(array("errors" => array($lang->error_nopermission_user_ajax)));
exit;

		header("Content-type: application/json; charset={$lang->settings['charset']}");
echo json_encode(array("errors" => array($lang->error_nopermission_user_ajax)));
exit;

	}


	}


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

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

		$lang->error_nopermission_user_username = $lang->sprintf($lang->error_nopermission_user_username, $mybb->user['username']);

		$lang->error_nopermission_user_username = $lang->sprintf($lang->error_nopermission_user_username, htmlspecialchars_uni($mybb->user['username']));

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

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

Zeile 893Zeile 907
			default:
$lang_username = $lang->username;
break;

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

		}

		}

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


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


Zeile 909Zeile 923
 * @param boolean $force_redirect Force the redirect page regardless of settings
*/
function redirect($url, $message="", $title="", $force_redirect=false)

 * @param boolean $force_redirect Force the redirect page regardless of settings
*/
function redirect($url, $message="", $title="", $force_redirect=false)

{

{

	global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;


	global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;


	$redirect_args = array('url' => &$url, 'message' => &$message, 'title' => &$title);


	$redirect_args = array('url' => &$url, 'message' => &$message, 'title' => &$title);


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

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

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

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

Zeile 924Zeile 938
		if($message != "")
{
$data .= 'alert("'.addslashes($message).'");';

		if($message != "")
{
$data .= 'alert("'.addslashes($message).'");';

		}

		}

		$url = str_replace("#", "&#", $url);
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);

		$url = str_replace("#", "&#", $url);
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);

Zeile 966Zeile 980

run_shutdown();



run_shutdown();


		if(my_substr($url, 0, 7) !== 'http://' && my_substr($url, 0, 8) !== 'https://' && my_substr($url, 0, 1) !== '/')

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

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

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

Zeile 1001Zeile 1015
	$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 1015Zeile 1029
	if(!$mybb->settings['maxmultipagelinks'])
{
$mybb->settings['maxmultipagelinks'] = 5;

	if(!$mybb->settings['maxmultipagelinks'])
{
$mybb->settings['maxmultipagelinks'] = 5;

	}

	}


$from = $page-floor($mybb->settings['maxmultipagelinks']/2);
$to = $page+floor($mybb->settings['maxmultipagelinks']/2);


$from = $page-floor($mybb->settings['maxmultipagelinks']/2);
$to = $page+floor($mybb->settings['maxmultipagelinks']/2);

Zeile 1209Zeile 1223
 * Fetch the usergroup permissions for a specific group or series of groups combined
*
* @param int|string $gid A list of groups (Can be a single integer, or a list of groups separated by a comma)

 * Fetch the usergroup permissions for a specific group or series of groups combined
*
* @param int|string $gid A list of groups (Can be a single integer, or a list of groups separated by a comma)

 * @return array Array of permissions generated for the groups

 * @return array Array of permissions generated for the groups, containing also a list of comma-separated checked groups under 'all_usergroups' index

 */
function usergroup_permissions($gid=0)
{

 */
function usergroup_permissions($gid=0)
{

Zeile 1224Zeile 1238

if(count($groups) == 1)
{


if(count($groups) == 1)
{

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

		return $groupscache[$gid];
}

		return $groupscache[$gid];
}

	



	$usergroup = array();

	$usergroup = array();

 
	$usergroup['all_usergroups'] = $gid;


foreach($groups as $gid)
{


foreach($groups as $gid)
{

		if(trim($gid) == "" || !$groupscache[$gid])

		if(trim($gid) == "" || empty($groupscache[$gid]))

		{
continue;

		{
continue;

		}


		}


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

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

Zeile 1243Zeile 1259
				if(isset($usergroup[$perm]))
{
$permbit = $usergroup[$perm];

				if(isset($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))

				{

				{

					$usergroup[$perm] = 0;
continue;
}

					$usergroup[$perm] = 0;
continue;
}

Zeile 1260Zeile 1276
				{
$usergroup[$perm] = $access;
}

				{
$usergroup[$perm] = $access;
}

			}
}

			}
}

	}

return $usergroup;

	}

return $usergroup;

Zeile 1291Zeile 1307
	}

return $displaygroup;

	}

return $displaygroup;

}


}


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

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

Zeile 1322Zeile 1338
		else
{
$gid = $mybb->user['usergroup'];

		else
{
$gid = $mybb->user['usergroup'];





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

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

Zeile 1337Zeile 1353
		$forum_cache = cache_forums();

if(!$forum_cache)

		$forum_cache = cache_forums();

if(!$forum_cache)

		{

		{

			return false;
}

			return false;
}

	}


	}


	if(!is_array($fpermcache))

	if(!is_array($fpermcache))

	{

	{

		$fpermcache = $cache->read("forumpermissions");
}


		$fpermcache = $cache->read("forumpermissions");
}


Zeile 1352Zeile 1368
		if(empty($cached_forum_permissions_permissions[$gid][$fid]))
{
$cached_forum_permissions_permissions[$gid][$fid] = fetch_forum_permissions($fid, $gid, $groupperms);

		if(empty($cached_forum_permissions_permissions[$gid][$fid]))
{
$cached_forum_permissions_permissions[$gid][$fid] = fetch_forum_permissions($fid, $gid, $groupperms);

		}

		}

		return $cached_forum_permissions_permissions[$gid][$fid];

		return $cached_forum_permissions_permissions[$gid][$fid];

	}

	}

	else
{
if(empty($cached_forum_permissions[$gid]))

	else
{
if(empty($cached_forum_permissions[$gid]))

Zeile 1367Zeile 1383
		return $cached_forum_permissions[$gid];
}
}

		return $cached_forum_permissions[$gid];
}
}





/**
* Fetches the permissions for a specific forum/group applying the inheritance scheme.
* Called by forum_permissions()

/**
* Fetches the permissions for a specific forum/group applying the inheritance scheme.
* Called by forum_permissions()

Zeile 1382Zeile 1398
	global $groupscache, $forum_cache, $fpermcache, $mybb, $fpermfields;

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

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

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





	if(empty($fpermcache[$fid])) // This forum has no custom or inherited permissions so lets just return the group permissions
{
return $groupperms;

	if(empty($fpermcache[$fid])) // This forum has no custom or inherited permissions so lets just return the group permissions
{
return $groupperms;

Zeile 1438Zeile 1454
			if($level_permissions["canpostreplys"] && empty($level_permissions["canonlyreplyownthreads"]))
{
$only_reply_own_threads = 0;

			if($level_permissions["canpostreplys"] && empty($level_permissions["canonlyreplyownthreads"]))
{
$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)
{

Zeile 1486Zeile 1502

// Loop through each of parent forums to ensure we have a password for them too
if(isset($forum_cache[$fid]['parentlist']))


// Loop through each of parent forums to ensure we have a password for them too
if(isset($forum_cache[$fid]['parentlist']))

	{

	{

		$parents = explode(',', $forum_cache[$fid]['parentlist']);
rsort($parents);
}

		$parents = explode(',', $forum_cache[$fid]['parentlist']);
rsort($parents);
}

Zeile 1502Zeile 1518
			if($forum_cache[$parent_id]['password'] != "")
{
check_forum_password($parent_id, $fid);

			if($forum_cache[$parent_id]['password'] != "")
{
check_forum_password($parent_id, $fid);

			}
}
}

			}
}
}


if(!empty($forum_cache[$fid]['password']))
{


if(!empty($forum_cache[$fid]['password']))
{

Zeile 1512Zeile 1528
		if(isset($mybb->input['pwverify']) && $pid == 0)
{
if($password === $mybb->get_input('pwverify'))

		if(isset($mybb->input['pwverify']) && $pid == 0)
{
if($password === $mybb->get_input('pwverify'))

			{

			{

				my_setcookie("forumpass[$fid]", md5($mybb->user['uid'].$mybb->get_input('pwverify')), null, true);
$showform = false;
}
else
{
eval("\$pwnote = \"".$templates->get("forumdisplay_password_wrongpass")."\";");

				my_setcookie("forumpass[$fid]", md5($mybb->user['uid'].$mybb->get_input('pwverify')), null, true);
$showform = false;
}
else
{
eval("\$pwnote = \"".$templates->get("forumdisplay_password_wrongpass")."\";");

				$showform = true;
}

				$showform = true;
}

		}
else
{

		}
else
{

Zeile 1535Zeile 1551
		}
}
else

		}
}
else

	{

	{

		$showform = false;
}


		$showform = false;
}


Zeile 1610Zeile 1626
	}

$mod_cache = $cache->read("moderators");

	}

$mod_cache = $cache->read("moderators");





	foreach($mod_cache as $forumid => $forum)
{
if(!is_array($forum) || !in_array($forumid, $parentslist))

	foreach($mod_cache as $forumid => $forum)
{
if(!is_array($forum) || !in_array($forumid, $parentslist))

		{

		{

			// No perms or we're not after this forum
continue;
}

			// No perms or we're not after this forum
continue;
}

Zeile 1623Zeile 1639
		if(is_array($forum['users'][$uid]))
{
$perm = $forum['users'][$uid];

		if(is_array($forum['users'][$uid]))
{
$perm = $forum['users'][$uid];

			foreach($perm as $action => $value)
{
if(strpos($action, "can") === false)

			foreach($perm as $action => $value)
{
if(strpos($action, "can") === false)

				{
continue;
}

				{
continue;
}

Zeile 1639Zeile 1655
				else
{
$perms[$action] = max($perm[$action], $perms[$action]);

				else
{
$perms[$action] = max($perm[$action], $perms[$action]);

				}
}
}

				}
}
}


foreach($groups as $group)
{


foreach($groups as $group)
{

Zeile 1698Zeile 1714
		{
$forumpermissions = forum_permissions($fid);
if($forumpermissions['canview'] && $forumpermissions['canviewthreads'] && !$forumpermissions['canonlyviewownthreads'])

		{
$forumpermissions = forum_permissions($fid);
if($forumpermissions['canview'] && $forumpermissions['canviewthreads'] && !$forumpermissions['canonlyviewownthreads'])

			{
return true;
}
return false;

			{
return true;
}
return false;

		}
return true;
}

		}
return true;
}

Zeile 1714Zeile 1730
			{
foreach($modcache as $modusers)
{

			{
foreach($modcache as $modusers)
{

					if(isset($modusers['users'][$uid]) && $modusers['users'][$uid]['mid'])

					if(isset($modusers['users'][$uid]) && $modusers['users'][$uid]['mid'] && (!$action || !empty($modusers['users'][$uid][$action])))

					{
return true;

					{
return true;

					}
elseif(isset($user_perms['gid']) && isset($modusers['usergroups'][$user_perms['gid']]))




					}

$groups = explode(',', $user_perms['all_usergroups']);

foreach($groups as $group)

					{

					{

						// Moderating usergroup
return true;



						if(trim($group) != '' && isset($modusers['usergroups'][$group]) && (!$action || !empty($modusers['usergroups'][$group][$action])))
{
return true;
}

					}
}
}

					}
}
}

Zeile 1744Zeile 1765
				else
{
return false;

				else
{
return false;

				}
}
}
}
}


				}
}
}
}
}


/**
* Generate a list of the posticons.
*

/**
* Generate a list of the posticons.
*

Zeile 1780Zeile 1801
		$dbicon['path'] = str_replace("{theme}", $theme['imgdir'], $dbicon['path']);
$dbicon['path'] = htmlspecialchars_uni($mybb->get_asset_url($dbicon['path']));
$dbicon['name'] = htmlspecialchars_uni($dbicon['name']);

		$dbicon['path'] = str_replace("{theme}", $theme['imgdir'], $dbicon['path']);
$dbicon['path'] = htmlspecialchars_uni($mybb->get_asset_url($dbicon['path']));
$dbicon['name'] = htmlspecialchars_uni($dbicon['name']);





		if($icon == $dbicon['iid'])

		if($icon == $dbicon['iid'])

		{

		{

			$checked = " checked=\"checked\"";
$no_icons_checked = '';

			$checked = " checked=\"checked\"";
$no_icons_checked = '';

		}

		}

		else
{
$checked = '';
}

		else
{
$checked = '';
}





		eval("\$iconlist .= \"".$templates->get("posticons_icon")."\";");

		eval("\$iconlist .= \"".$templates->get("posticons_icon")."\";");

	}

	}





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








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


return $posticons;
}


return $posticons;
}

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

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

 
	}

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

	}

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

	}

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

Zeile 1871Zeile 1904
	global $mybb;

$expires = -3600;

	global $mybb;

$expires = -3600;

	my_setcookie($name, "", $expires);

	my_setcookie($name, "", $expires);


unset($mybb->cookies[$name]);
}


unset($mybb->cookies[$name]);
}

Zeile 2112Zeile 2145

// not in array
return false;


// not in array
return false;

		}
}


		}
}


	if(!empty($str))
{
// trailing data in input

	if(!empty($str))
{
// trailing data in input

Zeile 2133Zeile 2166
function my_unserialize($str)
{
// Ensure we use the byte count for strings even when strlen() is overloaded by mb_strlen()

function my_unserialize($str)
{
// 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');
}

$out = _safe_unserialize($str);

if(isset($mbIntEnc))
{
mb_internal_encoding($mbIntEnc);
}

return $out;

	if(function_exists('mb_internal_encoding') && (((int)ini_get('mbstring.func_overload')) & 2))
{
$mbIntEnc = mb_internal_encoding();
mb_internal_encoding('ASCII');
}

$out = _safe_unserialize($str);

if(isset($mbIntEnc))
{
mb_internal_encoding($mbIntEnc);
}

return $out;

}

/**

}

/**

Zeile 2165Zeile 2198
	{
return 'N;';
}

	{
return 'N;';
}

	



	if(is_bool($value))

	if(is_bool($value))

	{

	{

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

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

	



	if(is_int($value))

	if(is_int($value))

	{

	{

		return 'i:'.$value.';';
}

		return 'i:'.$value.';';
}

	



	if(is_float($value))
{
return 'd:'.str_replace(',', '.', $value).';';

	if(is_float($value))
{
return 'd:'.str_replace(',', '.', $value).';';

	}


	}


	if(is_string($value))

	if(is_string($value))

	{

	{

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

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

	



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

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

Zeile 2193Zeile 2226
		{
$out .= _safe_serialize($k) . _safe_serialize($v);
}

		{
$out .= _safe_serialize($k) . _safe_serialize($v);
}

		



		return 'a:'.count($value).':{'.$out.'}';
}


		return 'a:'.count($value).':{'.$out.'}';
}


Zeile 2212Zeile 2245
{
// 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');

	}


	}


	$out = _safe_serialize($value);
if(isset($mbIntEnc))
{
mb_internal_encoding($mbIntEnc);
}

	$out = _safe_serialize($value);
if(isset($mbIntEnc))
{
mb_internal_encoding($mbIntEnc);
}

	



	return $out;
}


	return $out;
}


Zeile 2244Zeile 2277
		{
// 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"))
{

Zeile 2273Zeile 2306
				{
return $lang->unknown;
}

				{
return $lang->unknown;
}

			}

			}


$load = @exec("uptime");
$load = explode("load average: ", $load);


$load = @exec("uptime");
$load = explode("load average: ", $load);

Zeile 2283Zeile 2316
				return $lang->unknown;
}
}

				return $lang->unknown;
}
}

	}

	}

	else
{
return $lang->unknown;

	else
{
return $lang->unknown;

	}

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

	}

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


return $returnload;
}


return $returnload;
}

Zeile 2302Zeile 2335
function get_memory_usage()
{
if(function_exists('memory_get_peak_usage'))

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

	{

	{

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

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

Zeile 2361Zeile 2394

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


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

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

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

			{
$changes[$counter] = substr($changes[$counter], 1);
}

			{
$changes[$counter] = substr($changes[$counter], 1);
}

Zeile 2388Zeile 2421
					{
$new_stats[$counter] = 0;
}

					{
$new_stats[$counter] = 0;
}

				}
}

				}
}

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

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

Zeile 2397Zeile 2430
				if($new_stats[$counter] < 0)
{
$new_stats[$counter] = 0;

				if($new_stats[$counter] < 0)
{
$new_stats[$counter] = 0;

				}
}
}
}


				}
}
}
}


	if(!$force)

	if(!$force)

	{

	{

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

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

Zeile 2414Zeile 2447
		$query = $db->simple_select("users", "uid, username", "", array('order_by' => 'regdate', 'order_dir' => 'DESC', 'limit' => 1));
$lastmember = $db->fetch_array($query);
$new_stats['lastuid'] = $lastmember['uid'];

		$query = $db->simple_select("users", "uid, username", "", array('order_by' => 'regdate', 'order_dir' => 'DESC', 'limit' => 1));
$lastmember = $db->fetch_array($query);
$new_stats['lastuid'] = $lastmember['uid'];

		$new_stats['lastusername'] = $lastmember['username'];
}


		$new_stats['lastusername'] = $lastmember['username'] = htmlspecialchars_uni($lastmember['username']);
}


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

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

Zeile 2432Zeile 2465
	// Update stats row for today in the database
$todays_stats = array(
"dateline" => mktime(0, 0, 0, date("m"), date("j"), date("Y")),

	// Update stats row for today in the database
$todays_stats = array(
"dateline" => mktime(0, 0, 0, date("m"), date("j"), date("Y")),

		"numusers" => $stats['numusers'],
"numthreads" => $stats['numthreads'],
"numposts" => $stats['numposts']

		"numusers" => (int)$stats['numusers'],
"numthreads" => (int)$stats['numthreads'],
"numposts" => (int)$stats['numposts']

	);
$db->replace_query("stats", $todays_stats, "dateline");


	);
$db->replace_query("stats", $todays_stats, "dateline");


Zeile 2474Zeile 2507
				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];
}

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

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

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

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

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

		$db->update_query("forums", $update_query, "fid='".(int)$fid."'");
}


		$db->update_query("forums", $update_query, "fid='".(int)$fid."'");
}


Zeile 2975Zeile 3008
	{
$str[] = $set[my_rand(0, 61)];
}

	{
$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 3028Zeile 3061
 */
function format_avatar($avatar, $dimensions = '', $max_dimensions = '')
{

 */
function format_avatar($avatar, $dimensions = '', $max_dimensions = '')
{

	global $mybb;

	global $mybb, $theme;

	static $avatars;

	static $avatars;





	if(!isset($avatars))

	if(!isset($avatars))

	{

	{

		$avatars = array();

		$avatars = array();

 
	}

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

	}

if(!$avatar)
{
// Default avatar

	}

if(!$avatar)
{
// Default avatar

		$avatar = $mybb->settings['useravatar'];






		if(defined('IN_ADMINCP'))
{
$theme['imgdir'] = '../images';
}

$avatar = str_replace('{theme}', $theme['imgdir'], $mybb->settings['useravatar']);

		$dimensions = $mybb->settings['useravatardims'];
}


		$dimensions = $mybb->settings['useravatardims'];
}


Zeile 3214Zeile 3258
			$emoticons_enabled = "false";
if($smilies)
{

			$emoticons_enabled = "false";
if($smilies)
{

				if($mybb->settings['smilieinserter'] && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'])
{
$emoticon = ",emoticon";
}
$emoticons_enabled = "true";


 
				if(!$smiliecache)
{
if(!isset($smilie_cache) || !is_array($smilie_cache))

				if(!$smiliecache)
{
if(!isset($smilie_cache) || !is_array($smilie_cache))

Zeile 3233Zeile 3271
					}
}


					}
}


				unset($smilie);







				if($mybb->settings['smilieinserter'] && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'] && !empty($smiliecache))
{
$emoticon = ",emoticon";
}
$emoticons_enabled = "true";

unset($smilie);


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


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





					$dropdownsmilies = $moresmilies = $hiddensmilies = "";
$i = 0;


					$dropdownsmilies = $moresmilies = $hiddensmilies = "";
$i = 0;


Zeile 3246Zeile 3290
					{
$finds = explode("\n", $smilie['find']);
$finds_count = count($finds);

					{
$finds = explode("\n", $smilie['find']);
$finds_count = count($finds);





						// Only show the first text to replace in the box
$smilie['find'] = $finds[0];

						// Only show the first text to replace in the box
$smilie['find'] = $finds[0];





						$find = str_replace(array('\\', '"'), array('\\\\', '\"'), htmlspecialchars_uni($smilie['find']));
$image = htmlspecialchars_uni($mybb->get_asset_url($smilie['image']));
$image = str_replace(array('\\', '"'), array('\\\\', '\"'), $image);

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

						$find = str_replace(array('\\', '"'), array('\\\\', '\"'), htmlspecialchars_uni($smilie['find']));
$image = htmlspecialchars_uni($mybb->get_asset_url($smilie['image']));
$image = str_replace(array('\\', '"'), array('\\\\', '\"'), $image);

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

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

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

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

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

Zeile 3275Zeile 3319
						}
}
}

						}
}
}

			}

$basic1 = $basic2 = $align = $font = $size = $color = $removeformat = $email = $link = $list = $code = $sourcemode = "";


			}

$basic1 = $basic2 = $align = $font = $size = $color = $removeformat = $email = $link = $list = $code = $sourcemode = "";


			if($mybb->settings['allowbasicmycode'] == 1)
{
$basic1 = "bold,italic,underline,strike|";
$basic2 = "horizontalrule,";

			if($mybb->settings['allowbasicmycode'] == 1)
{
$basic1 = "bold,italic,underline,strike|";
$basic2 = "horizontalrule,";

			}


			}


			if($mybb->settings['allowalignmycode'] == 1)
{
$align = "left,center,right,justify|";

			if($mybb->settings['allowalignmycode'] == 1)
{
$align = "left,center,right,justify|";

			}


			}


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

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

			{

			{

				$font = "font,";

				$font = "font,";

			}

			}


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


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

			{

			{

				$size = "size,";
}

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

				$size = "size,";
}

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

			}

			}


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


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

Zeile 3344Zeile 3388

/**
* Build the javascript clickable smilie inserter


/**
* Build the javascript clickable smilie inserter

 *

 *

 * @return string The clickable smilies list
*/
function build_clickable_smilies()
{
global $cache, $smiliecache, $theme, $templates, $lang, $mybb, $smiliecount;

 * @return string The clickable smilies list
*/
function build_clickable_smilies()
{
global $cache, $smiliecache, $theme, $templates, $lang, $mybb, $smiliecount;





	if($mybb->settings['smilieinserter'] != 0 && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'])
{
if(!$smiliecount)
{
$smilie_cache = $cache->read("smilies");
$smiliecount = count($smilie_cache);

	if($mybb->settings['smilieinserter'] != 0 && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'])
{
if(!$smiliecount)
{
$smilie_cache = $cache->read("smilies");
$smiliecount = count($smilie_cache);

		}

		}


if(!$smiliecache)
{
if(!is_array($smilie_cache))
{
$smilie_cache = $cache->read("smilies");


if(!$smiliecache)
{
if(!is_array($smilie_cache))
{
$smilie_cache = $cache->read("smilies");

			}

			}

			foreach($smilie_cache as $smilie)
{

			foreach($smilie_cache as $smilie)
{

				if($smilie['showclickable'] != 0)
{
$smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']);
$smiliecache[$smilie['sid']] = $smilie;
}

				$smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']);
$smiliecache[$smilie['sid']] = $smilie;




			}
}


			}
}


Zeile 3392Zeile 3433
				eval("\$getmore = \"".$templates->get("smilieinsert_getmore")."\";");
}


				eval("\$getmore = \"".$templates->get("smilieinsert_getmore")."\";");
}


			$smilies = "";

			$smilies = '';

			$counter = 0;
$i = 0;

$extra_class = '';
foreach($smiliecache as $smilie)
{

			$counter = 0;
$i = 0;

$extra_class = '';
foreach($smiliecache as $smilie)
{

				if($i < $mybb->settings['smilieinsertertot'])

				if($i < $mybb->settings['smilieinsertertot'] && $smilie['showclickable'] != 0)

				{

				{

					if($counter == 0)
{
$smilies .= "<tr>\n";
}


 
					$smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']);
$smilie['image'] = htmlspecialchars_uni($mybb->get_asset_url($smilie['image']));
$smilie['name'] = htmlspecialchars_uni($smilie['name']);

					$smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']);
$smilie['image'] = htmlspecialchars_uni($mybb->get_asset_url($smilie['image']));
$smilie['name'] = htmlspecialchars_uni($smilie['name']);

					



					// Only show the first text to replace in the box
$temp = explode("\n", $smilie['find']); // assign to temporary variable for php 5.3 compatibility
$smilie['find'] = $temp[0];

					// Only show the first text to replace in the box
$temp = explode("\n", $smilie['find']); // assign to temporary variable for php 5.3 compatibility
$smilie['find'] = $temp[0];

Zeile 3419Zeile 3455
					$onclick = " onclick=\"MyBBEditor.insertText(' $find ');\"";
$extra_class = ' smilie_pointer';
eval('$smilie = "'.$templates->get('smilie', 1, 0).'";');

					$onclick = " onclick=\"MyBBEditor.insertText(' $find ');\"";
$extra_class = ' smilie_pointer';
eval('$smilie = "'.$templates->get('smilie', 1, 0).'";');

					eval("\$smilies .= \"".$templates->get("smilieinsert_smilie")."\";");

					eval("\$smilie_icons .= \"".$templates->get("smilieinsert_smilie")."\";");

					++$i;
++$counter;

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

					++$i;
++$counter;

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

						$smilies .= "</tr>\n";


						eval("\$smilies .= \"".$templates->get("smilieinsert_row")."\";");
$smilie_icons = '';

					}
}
}

					}
}
}

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

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

				$smilies .= "<td colspan=\"{$colspan}\">&nbsp;</td>\n</tr>\n";

				eval("\$smilies .= \"".$templates->get("smilieinsert_row_empty")."\";");

			}

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

			}

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

Zeile 3505Zeile 3542
}

/**

}

/**

 * Build the thread prefix selection menu

 * Build the thread prefix selection menu for the current user

 *
* @param int|string $fid The forum ID (integer ID or string all)
* @param int|string $selected_pid The selected prefix ID (integer ID or string any)
* @param int $multiple Allow multiple prefix selection

 *
* @param int|string $fid The forum ID (integer ID or string all)
* @param int|string $selected_pid The selected prefix ID (integer ID or string any)
* @param int $multiple Allow multiple prefix selection

 
 *  @param int $previous_pid The previously selected prefix ID

 *  @return string The thread prefix selection menu
*/

 *  @return string The thread prefix selection menu
*/

function build_prefix_select($fid, $selected_pid=0, $multiple=0)

function build_prefix_select($fid, $selected_pid=0, $multiple=0, $previous_pid=0)

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


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


Zeile 3524Zeile 3562
	$prefix_cache = build_prefixes(0);
if(empty($prefix_cache))
{

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

		return false; // We've got no prefixes to show
}

$groups = array($mybb->user['usergroup']);
if($mybb->user['additionalgroups'])
{
$exp = explode(",", $mybb->user['additionalgroups']);

foreach($exp as $group)
{
$groups[] = $group;
}

		// We've got no prefixes to show
return '';











	}

// Go through each of our prefixes and decide which ones we can use
$prefixes = array();
foreach($prefix_cache as $prefix)

	}

// Go through each of our prefixes and decide which ones we can use
$prefixes = array();
foreach($prefix_cache as $prefix)

	{

	{

		if($fid != "all" && $prefix['forums'] != "-1")
{
// Decide whether this prefix can be used in our forum
$forums = explode(",", $prefix['forums']);

		if($fid != "all" && $prefix['forums'] != "-1")
{
// Decide whether this prefix can be used in our forum
$forums = explode(",", $prefix['forums']);


if(!in_array($fid, $forums))
{


if(!in_array($fid, $forums) && $prefix['pid'] != $previous_pid)
{

				// This prefix is not in our forum list
continue;

				// This prefix is not in our forum list
continue;

			}

			}

		}

		}


if($prefix['groups'] != "-1")
{
$prefix_groups = explode(",", $prefix['groups']);

foreach($groups as $group)
{
if(in_array($group, $prefix_groups) && !isset($prefixes[$prefix['pid']]))
{
// Our group can use this prefix!
$prefixes[$prefix['pid']] = $prefix;
}
}
}
else


if(is_member($prefix['groups']) || $prefix['pid'] == $previous_pid)














		{

		{

			// This prefix is for anybody to use...

			// The current user can use this prefix

			$prefixes[$prefix['pid']] = $prefix;
}
}

if(empty($prefixes))
{

			$prefixes[$prefix['pid']] = $prefix;
}
}

if(empty($prefixes))
{

		return false;

		return '';

	}

$prefixselect = $prefixselect_prefix = '';

	}

$prefixselect = $prefixselect_prefix = '';

Zeile 3621Zeile 3636
}

/**

}

/**

 * Build the thread prefix selection menu for a forum

 * Build the thread prefix selection menu for a forum without group permission checks

 *
* @param int $fid The forum ID (integer ID)
* @param int $selected_pid The selected prefix ID (integer ID)

 *
* @param int $fid The forum ID (integer ID)
* @param int $selected_pid The selected prefix ID (integer ID)

 
 *  @return string The thread prefix selection menu

 */
function build_forum_prefix_select($fid, $selected_pid=0)
{

 */
function build_forum_prefix_select($fid, $selected_pid=0)
{

Zeile 3634Zeile 3650

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


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

	{
return false; // We've got no prefixes to show
}


	{
// We've got no prefixes to show
return '';
}


// Go through each of our prefixes and decide which ones we can use
$prefixes = array();
foreach($prefix_cache as $prefix)


// Go through each of our prefixes and decide which ones we can use
$prefixes = array();
foreach($prefix_cache as $prefix)

	{

	{

		if($prefix['forums'] != "-1")
{
// Decide whether this prefix can be used in our forum
$forums = explode(",", $prefix['forums']);

		if($prefix['forums'] != "-1")
{
// Decide whether this prefix can be used in our forum
$forums = explode(",", $prefix['forums']);





			if(in_array($fid, $forums))
{
// This forum can use this prefix!

			if(in_array($fid, $forums))
{
// This forum can use this prefix!

Zeile 3662Zeile 3679

if(empty($prefixes))
{


if(empty($prefixes))
{

		return false;

		return '';

	}

	}





	$default_selected = array();
$selected_pid = (int)$selected_pid;

	$default_selected = array();
$selected_pid = (int)$selected_pid;

	



	if($selected_pid == 0)
{
$default_selected['all'] = ' selected="selected"';

	if($selected_pid == 0)
{
$default_selected['all'] = ' selected="selected"';

Zeile 3823Zeile 3840
	{
$reputation_class = "reputation_neutral";
}

	{
$reputation_class = "reputation_neutral";
}

	



	$reputation = my_number_format($reputation);

if($uid != 0)

	$reputation = my_number_format($reputation);

if($uid != 0)

Zeile 3968Zeile 3985
	}
// Gigabyte (1024 Megabytes)
elseif($size >= 1073741824)

	}
// Gigabyte (1024 Megabytes)
elseif($size >= 1073741824)

	{

	{

		$size = my_number_format(round(($size / 1073741824), 2))." ".$lang->size_gb;
}
// Megabyte (1024 Kilobytes)

		$size = my_number_format(round(($size / 1073741824), 2))." ".$lang->size_gb;
}
// Megabyte (1024 Kilobytes)

Zeile 4159Zeile 4176
			$unviewable[] = $forum['fid'];
}
}

			$unviewable[] = $forum['fid'];
}
}

	



	$unviewableforums = implode(',', $unviewable);

	$unviewableforums = implode(',', $unviewable);

	



	return $unviewableforums;
}


	return $unviewableforums;
}


Zeile 4837Zeile 4854
{
global $db, $mybb, $cache;


{
global $db, $mybb, $cache;


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

	$user = get_user($uid);









$groupslist = $comma = '';
$usergroups = $user['additionalgroups'].",";


$groupslist = $comma = '';
$usergroups = $user['additionalgroups'].",";

Zeile 4889Zeile 4899
 * @return string The current URL being accessed
*/
function get_current_location($fields=false, $ignore=array(), $quick=false)

 * @return string The current URL being accessed
*/
function get_current_location($fields=false, $ignore=array(), $quick=false)

{

{

	if(defined("MYBB_LOCATION"))

	if(defined("MYBB_LOCATION"))

	{

	{

		return MYBB_LOCATION;
}

if(!empty($_SERVER['SCRIPT_NAME']))

		return MYBB_LOCATION;
}

if(!empty($_SERVER['SCRIPT_NAME']))

	{

	{

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

		$location = htmlspecialchars_uni($_SERVER['SCRIPT_NAME']);
}
elseif(!empty($_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']);
}
elseif(!empty($_SERVER['PATH_INFO']))
{
$location = htmlspecialchars_uni($_SERVER['PATH_INFO']);

		$location = htmlspecialchars_uni($_ENV['PHP_SELF']);
}
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;

Zeile 4958Zeile 4968
		}

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

		}

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

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





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

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

				}

				}

			}

if(isset($addloc) && is_array($addloc))
{
if(strpos($location, "?") === false)

			}

if(isset($addloc) && is_array($addloc))
{
if(strpos($location, "?") === false)

				{

				{

					$location .= "?";
}
else

					$location .= "?";
}
else

Zeile 4981Zeile 4991
				}
$location .= implode("&amp;", $addloc);
}

				}
$location .= implode("&amp;", $addloc);
}

		}

		}


return $location;
}
}


return $location;
}
}





/**
* Build a theme selection menu
*

/**
* Build a theme selection menu
*

Zeile 5004Zeile 5014
	global $db, $themeselect, $tcache, $lang, $mybb, $limit, $templates, $num_themes, $themeselect_option;

if($tid == 0)

	global $db, $themeselect, $tcache, $lang, $mybb, $limit, $templates, $num_themes, $themeselect_option;

if($tid == 0)

	{

	{

		$tid = 1;
$num_themes = 0;
$themeselect_option = '';

if(!isset($lang->use_default))

		$tid = 1;
$num_themes = 0;
$themeselect_option = '';

if(!isset($lang->use_default))

		{

		{

			$lang->use_default = $lang->lang_select_default;

			$lang->use_default = $lang->lang_select_default;

		}
}

		}
}


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


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

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





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

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

		// Figure out what groups this user is in
if(isset($mybb->user['additionalgroups']))
{
$in_groups = explode(",", $mybb->user['additionalgroups']);
}
$in_groups[] = $mybb->user['usergroup'];


 
		foreach($tcache[$tid] as $theme)
{
$sel = "";

		foreach($tcache[$tid] as $theme)
{
$sel = "";

Zeile 5731Zeile 5734
 */
function get_event_poster($event)
{

 */
function get_event_poster($event)
{

 
	$event['username'] = htmlspecialchars_uni($event['username']);

	$event['username'] = format_name($event['username'], $event['usergroup'], $event['displaygroup']);
$event_poster = build_profile_link($event['username'], $event['author']);
return $event_poster;

	$event['username'] = format_name($event['username'], $event['usergroup'], $event['displaygroup']);
$event_poster = build_profile_link($event['username'], $event['author']);
return $event_poster;

Zeile 5747Zeile 5751
	global $mybb;

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

	global $mybb;

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

	$event_date = mktime(0, 0, 0, $event_date[1], $event_date[0], $event_date[2]);

	$event_date = gmmktime(0, 0, 0, $event_date[1], $event_date[0], $event_date[2]);

	$event_date = my_date($mybb->settings['dateformat'], $event_date);

return $event_date;

	$event_date = my_date($mybb->settings['dateformat'], $event_date);

return $event_date;

Zeile 6201Zeile 6205
			}
}
}

			}
}
}

	



	$inactiveforums = implode(",", $inactive);

return $inactiveforums;

	$inactiveforums = implode(",", $inactive);

return $inactiveforums;

Zeile 6234Zeile 6238
	}

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

	}

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

	{

	{

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


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


Zeile 6263Zeile 6267
		if(empty($failedlogin))
{
my_setcookie('failedlogin', $now);

		if(empty($failedlogin))
{
my_setcookie('failedlogin', $now);

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

return false;

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

return false;

		}

// Work out if the user has waited long enough before letting them login again

		}

// Work out if the user has waited long enough before letting them login again

Zeile 6291Zeile 6295
			if($fatal)
{
error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft));

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

			}

return false;
}
}

			}

return false;
}
}


// User can attempt another login
return $loginattempts;


// User can attempt another login
return $loginattempts;

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

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

}

}


/**
* Checks to see if the email is already in use by another


/**
* Checks to see if the email is already in use by another

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

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





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

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

Zeile 6372Zeile 6376
		$mybb->settings[$setting['name']] = $setting['value'];
$setting['value'] = addcslashes($setting['value'], '\\"$');
$settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n";

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

	}

	}


$settings = "<"."?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n";
$file = @fopen(MYBB_ROOT."inc/settings.php", $mode);


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

Zeile 6391Zeile 6395
function build_highlight_array($terms)
{
global $mybb;

function build_highlight_array($terms)
{
global $mybb;





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

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

	{

	{

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

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

	}


	}


	if(is_array($terms))
{
$terms = implode(' ', $terms);

	if(is_array($terms))
{
$terms = implode(' ', $terms);

	}


	}


	// Strip out any characters that shouldn't be included
$bad_characters = array(
"(",

	// Strip out any characters that shouldn't be included
$bad_characters = array(
"(",

Zeile 6448Zeile 6452
		}
}
// Otherwise just a simple search query with no phrases

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

	else

	else

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

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

Zeile 6466Zeile 6470
	}

if(!is_array($words))

	}

if(!is_array($words))

	{
return false;
}

	{
return false;
}


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

Zeile 6516Zeile 6520
		$dest .= chr($src);
}
elseif($src <= 0x07ff)

		$dest .= chr($src);
}
elseif($src <= 0x07ff)

	{

	{

		$dest .= chr(0xc0 | ($src >> 6));

		$dest .= chr(0xc0 | ($src >> 6));

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

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

	}
elseif($src <= 0xffff)
{
$dest .= chr(0xe0 | ($src >> 12));
$dest .= chr(0x80 | (($src >> 6) & 0x003f));
$dest .= chr(0x80 | ($src & 0x003f));

	}
elseif($src <= 0xffff)
{
$dest .= chr(0xe0 | ($src >> 12));
$dest .= chr(0x80 | (($src >> 6) & 0x003f));
$dest .= chr(0x80 | ($src & 0x003f));

	}

	}

	elseif($src <= 0x10ffff)
{
$dest .= chr(0xf0 | ($src >> 18));

	elseif($src <= 0x10ffff)
{
$dest .= chr(0xf0 | ($src >> 18));

Zeile 6706Zeile 6710
		"6.5" => $lang->timezone_gmt_650,
"7" => $lang->timezone_gmt_700,
"8" => $lang->timezone_gmt_800,

		"6.5" => $lang->timezone_gmt_650,
"7" => $lang->timezone_gmt_700,
"8" => $lang->timezone_gmt_800,

 
		"8.5" => $lang->timezone_gmt_850,
"8.75" => $lang->timezone_gmt_875,

		"9" => $lang->timezone_gmt_900,
"9.5" => $lang->timezone_gmt_950,
"10" => $lang->timezone_gmt_1000,

		"9" => $lang->timezone_gmt_900,
"9.5" => $lang->timezone_gmt_950,
"10" => $lang->timezone_gmt_1000,

Zeile 6779Zeile 6785
 *
* @param string $url The URL of the remote file
* @param array $post_data The array of post data

 *
* @param string $url The URL of the remote file
* @param array $post_data The array of post data

 
 * @param int $max_redirects Number of maximum redirects

 * @return string|bool The remote file contents. False on failure
*/

 * @return string|bool The remote file contents. False on failure
*/

function fetch_remote_file($url, $post_data=array())

function fetch_remote_file($url, $post_data=array(), $max_redirects=20)

{

{

 
	global $mybb, $config;

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

$url_components = @parse_url($url);

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

if(
!$url_components ||
empty($url_components['host']) ||
(!empty($url_components['scheme']) && !in_array($url_components['scheme'], array('http', 'https'))) ||
(!in_array($url_components['port'], array(80, 8080, 443))) ||
(!empty($config['disallowed_remote_hosts']) && in_array($url_components['host'], $config['disallowed_remote_hosts']))
)
{
return false;
}

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

if(!empty($config['disallowed_remote_addresses']))
{
foreach($config['disallowed_remote_addresses'] as $disallowed_address)
{
$ip_range = fetch_ip_range($disallowed_address);

$packed_address = my_inet_pton($destination_address);

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


	$post_body = '';
if(!empty($post_data))
{
foreach($post_data as $key => $val)

	$post_body = '';
if(!empty($post_data))
{
foreach($post_data as $key => $val)

		{

		{

			$post_body .= '&'.urlencode($key).'='.urlencode($val);
}
$post_body = ltrim($post_body, '&');

			$post_body .= '&'.urlencode($key).'='.urlencode($val);
}
$post_body = ltrim($post_body, '&');

	}


	}


	if(function_exists("curl_init"))
{

	if(function_exists("curl_init"))
{

 
		$fetch_header = $max_redirects > 0;


		$ch = curl_init();

		$ch = curl_init();

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


































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

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

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

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


		if(!empty($post_body))
{

		if(!empty($post_body))
{

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

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

		}

		}

		$data = curl_exec($ch);































curl_setopt_array($ch, $curlopt);

$response = curl_exec($ch);

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

if(in_array(curl_getinfo($ch, CURLINFO_HTTP_CODE), array(301, 302)))
{
preg_match('/Location:(.*?)(?:\n|$)/', $header, $matches);

if($matches)
{
$data = fetch_remote_file(trim(array_pop($matches)), $post_data, --$max_redirects);
}
}
else
{
$data = $body;
}
}
else
{
$data = $response;
}


		curl_close($ch);
return $data;
}
else if(function_exists("fsockopen"))
{

		curl_close($ch);
return $data;
}
else if(function_exists("fsockopen"))
{

		$url = @parse_url($url);
if(!$url['host'])
{
return false;
}
if(!$url['port'])
{
$url['port'] = 80;
}
if(!$url['path'])
{
$url['path'] = "/";
}
if($url['query'])
{
$url['path'] .= "?{$url['query']}";
}

$scheme = '';

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

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

$scheme = '';

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










		{
$scheme = 'ssl://';

		{
$scheme = 'ssl://';

			if($url['port'] == 80)

			if($url_components['port'] == 80)

			{

			{

				$url['port'] = 443;

























				$url_components['port'] = 443;
}
}

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

			}

			}

 

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

		}


		}


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

 
		@stream_set_timeout($fp, 10);
if(!$fp)
{

		@stream_set_timeout($fp, 10);
if(!$fp)
{

Zeile 6850Zeile 6994
		$headers = array();
if(!empty($post_body))
{

		$headers = array();
if(!empty($post_body))
{

			$headers[] = "POST {$url['path']} HTTP/1.0";

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

			$headers[] = "Content-Length: ".strlen($post_body);
$headers[] = "Content-Type: application/x-www-form-urlencoded";
}
else
{

			$headers[] = "Content-Length: ".strlen($post_body);
$headers[] = "Content-Type: application/x-www-form-urlencoded";
}
else
{

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

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

		}


		}


		$headers[] = "Host: {$url['host']}";

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

		$headers[] = "Connection: Close";
$headers[] = '';


		$headers[] = "Connection: Close";
$headers[] = '';


Zeile 6878Zeile 7022
		{
return false;
}

		{
return false;
}

 

$data = null;


		while(!feof($fp))
{
$data .= fgets($fp, 12800);
}
fclose($fp);

		while(!feof($fp))
{
$data .= fgets($fp, 12800);
}
fclose($fp);

 


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

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

		return $data[1];
}
else if(empty($post_data))
{
return @implode("", @file($url));
}
else
{
return false;
}
}































































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

if($max_redirects > 0 && (strstr($status_line, ' 301 ') || strstr($status_line, ' 302 ')))
{
preg_match('/Location:(.*?)(?:\n|$)/', $header, $matches);

if($matches)
{
$data = fetch_remote_file(trim(array_pop($matches)), $post_data, --$max_redirects);
}
}
else
{
$data = $body;
}

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

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

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

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

return $addresses;
}

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

return false;
}


/**
* Checks if a particular user is a super administrator.


/**
* Checks if a particular user is a super administrator.

Zeile 6907Zeile 7116
	static $super_admins;

if(!isset($super_admins))

	static $super_admins;

if(!isset($super_admins))

	{

	{

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

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

Zeile 6934Zeile 7143
function is_member($groups, $user = false)
{
global $mybb;

function is_member($groups, $user = false)
{
global $mybb;

	



	if(empty($groups))
{
return array();

	if(empty($groups))
{
return array();

Zeile 7548Zeile 7757
	global $mybb, $checksums, $bad_verify_files;

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

	global $mybb, $checksums, $bad_verify_files;

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

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

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

	$ignore_ext = array("attach");

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

	$ignore_ext = array("attach");

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

Zeile 7651Zeile 7860
}

/**

}

/**

 * Returns a securely generated seed for PHP's RNG (Random Number Generator)

 * Returns a securely generated seed

 *

 *

 * @param int $count Length of the seed bytes (8 is default. Provides good cryptographic variance)
* @return int An integer equivalent of a secure hexadecimal seed
*/
function secure_seed_rng($count=8)
{
$output = '';
// DIRECTORY_SEPARATOR checks if running windows
if(DIRECTORY_SEPARATOR != '\\')
{
// Unix/Linux
// Use OpenSSL when available
if(function_exists('openssl_random_pseudo_bytes'))
{
$output = openssl_random_pseudo_bytes($count);
}
// Try mcrypt
elseif(function_exists('mcrypt_create_iv'))
{
$output = mcrypt_create_iv($count, MCRYPT_DEV_URANDOM);
}
// Try /dev/urandom
elseif(@is_readable('/dev/urandom') && ($handle = @fopen('/dev/urandom', 'rb')))

 * @return string A secure binary seed
*/
function secure_binary_seed_rng($bytes)
{
$output = null;

if(version_compare(PHP_VERSION, '7.0', '>='))
{
try














		{

		{

			$output = @fread($handle, $count);
@fclose($handle);
}

			$output = random_bytes($bytes);
} catch (Exception $e) {
}

	}

	}

	else



if(strlen($output) < $bytes)

	{

	{

		// Windows
// Use OpenSSL when available
// PHP <5.3.4 had a bug which makes that function unusable on Windows
if(function_exists('openssl_random_pseudo_bytes') && version_compare(PHP_VERSION, '5.3.4', '>='))

		if(@is_readable('/dev/urandom') && ($handle = @fopen('/dev/urandom', 'rb')))




		{

		{

			$output = openssl_random_pseudo_bytes($count);
}
// Try mcrypt
elseif(function_exists('mcrypt_create_iv'))
{
$output = mcrypt_create_iv($count, MCRYPT_RAND);

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





		}

		}

		// Try Windows CAPICOM before using our own generator
elseif(class_exists('COM'))

















































	}
else
{
return $output;
}

if(strlen($output) < $bytes)
{
if(function_exists('mcrypt_create_iv'))
{
if (DIRECTORY_SEPARATOR == '/')
{
$source = MCRYPT_DEV_URANDOM;
}
else
{
$source = MCRYPT_RAND;
}

$output = @mcrypt_create_iv($bytes, $source);
}
}
else
{
return $output;
}

if(strlen($output) < $bytes)
{
if(function_exists('openssl_random_pseudo_bytes'))
{
// PHP <5.3.4 had a bug which makes that function unusable on Windows
if ((DIRECTORY_SEPARATOR == '/') || version_compare(PHP_VERSION, '5.3.4', '>='))
{
$output = openssl_random_pseudo_bytes($bytes, $crypto_strong);
if ($crypto_strong == false)
{
$output = null;
}
}
}
}
else
{
return $output;
}

if(strlen($output) < $bytes)
{
if(class_exists('COM'))

		{
try
{
$CAPI_Util = new COM('CAPICOM.Utilities.1');
if(is_callable(array($CAPI_Util, 'GetRandom')))
{

		{
try
{
$CAPI_Util = new COM('CAPICOM.Utilities.1');
if(is_callable(array($CAPI_Util, 'GetRandom')))
{

					$output = $CAPI_Util->GetRandom($count, 0);

					$output = $CAPI_Util->GetRandom($bytes, 0);

				}
} catch (Exception $e) {
}
}

				}
} catch (Exception $e) {
}
}

 
	}
else
{
return $output;

	}


	}


	// Didn't work? Do we still not have enough bytes? Use our own (less secure) rng generator
if(strlen($output) < $count)

	if(strlen($output) < $bytes)


	{

	{

		$output = '';


 
		// Close to what PHP basically uses internally to seed, but not quite.
$unique_state = microtime().@getmypid();

		// Close to what PHP basically uses internally to seed, but not quite.
$unique_state = microtime().@getmypid();


for($i = 0; $i < $count; $i += 16)
{




$rounds = ceil($bytes / 16);

for($i = 0; $i < $rounds; $i++)
{

			$unique_state = md5(microtime().$unique_state);

			$unique_state = md5(microtime().$unique_state);

			$output .= pack('H*', md5($unique_state));
}











			$output .= md5($unique_state);
}

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

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

return $output;
}
else
{
return $output;

	}

	}

 
}

/**
* Returns a securely generated seed integer
*
* @return int An integer equivalent of a secure hexadecimal seed
*/
function secure_seed_rng()
{
$bytes = PHP_INT_SIZE;

do
{

$output = secure_binary_seed_rng($bytes);

// convert binary data to a decimal number
if ($bytes == 4)
{
$elements = unpack('i', $output);
$output = abs($elements[1]);
}
else
{
$elements = unpack('N2', $output);
$output = abs($elements[1] << 32 | $elements[2]);
}





	// /dev/urandom and openssl will always be twice as long as $count. base64_encode will roughly take up 33% more space but crc32 will put it to 32 characters
$output = hexdec(substr(dechex(crc32(base64_encode($output))), 0, $count));

	} while($output > PHP_INT_MAX);



return $output;
}

/**


return $output;
}

/**

 * Wrapper function for mt_rand. Automatically seeds using a secure seed once.

 * Generates a cryptographically secure random number.

 *
* @param int $min Optional lowest value to be returned (default: 0)

 *
* @param int $min Optional lowest value to be returned (default: 0)

 * @param int $max Optional highest value to be returned (default: mt_getrandmax())
* @param boolean $force_seed True forces it to reseed the RNG first
* @return int An integer equivalent of a secure hexadecimal seed

 * @param int $max Optional highest value to be returned (default: PHP_INT_MAX)



 */

 */

function my_rand($min=null, $max=null, $force_seed=false)

function my_rand($min=0, $max=PHP_INT_MAX)

{

{

	static $seeded = false;
static $obfuscator = 0;





	// backward compatibility
if($min === null || $max === null || $max < $min)
{
$min = 0;
$max = PHP_INT_MAX;
}





	if($seeded == false || $force_seed == true)

	if(version_compare(PHP_VERSION, '7.0', '>='))

	{

	{

		mt_srand(secure_seed_rng());
$seeded = true;

$obfuscator = abs((int) secure_seed_rng());


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





		// Ensure that $obfuscator is <= mt_getrandmax() for 64 bit systems.
if($obfuscator > mt_getrandmax())

		if(isset($result))


		{

		{

			$obfuscator -= mt_getrandmax();

			return $result;

		}
}

		}
}


if($min !== null && $max !== null)
{
$distance = $max - $min;
if($distance > 0)
{
return $min + (int)((float)($distance + 1) * (float)(mt_rand() ^ $obfuscator) / (mt_getrandmax() + 1));
}
else
{
return mt_rand($min, $max);
}
}
else
{
$val = mt_rand() ^ $obfuscator;
return $val;
}


$seed = secure_seed_rng();

$distance = $max - $min;
return $min + floor($distance * ($seed / PHP_INT_MAX) );














}

/**
* More robust version of PHP's trim() function. It includes a list of UTF-8 blank characters
* from http://kb.mozillazine.org/Network.IDN.blacklist_chars

}

/**
* More robust version of PHP's trim() function. It includes a list of UTF-8 blank characters
* from http://kb.mozillazine.org/Network.IDN.blacklist_chars

 *

 *

 * @param string $string The string to trim from
* @param string $charlist Optional. The stripped characters can also be specified using the charlist parameter
* @return string The trimmed string

 * @param string $string The string to trim from
* @param string $charlist Optional. The stripped characters can also be specified using the charlist parameter
* @return string The trimmed string

Zeile 7787Zeile 8053
function trim_blank_chrs($string, $charlist="")
{
$hex_chrs = array(

function trim_blank_chrs($string, $charlist="")
{
$hex_chrs = array(

		0x09 => 1, // \x{0009}
0x0A => 1, // \x{000A}

		0x09 => 1, // \x{0009}
0x0A => 1, // \x{000A}

		0x0B => 1, // \x{000B}
0x0D => 1, // \x{000D}
0x20 => 1, // \x{0020}

		0x0B => 1, // \x{000B}
0x0D => 1, // \x{000D}
0x20 => 1, // \x{0020}

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

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

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

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

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

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

Zeile 7885Zeile 8151
	else
{
$string = trim($string);

	else
{
$string = trim($string);

	}

	}


return $string;
}


return $string;
}

Zeile 7904Zeile 8170
	if($string === "")
{
return 0;

	if($string === "")
{
return 0;

	}

	}


$ord = ord($string[$i]);
if(array_key_exists($ord, $array))


$ord = ord($string[$i]);
if(array_key_exists($ord, $array))

Zeile 7932Zeile 8198
	static $gd_version;

if($gd_version)

	static $gd_version;

if($gd_version)

	{

	{

		return $gd_version;
}
if(!extension_loaded('gd'))

		return $gd_version;
}
if(!extension_loaded('gd'))

Zeile 8086Zeile 8352
 * @return bool True if PM sent
*/
function send_pm($pm, $fromid = 0, $admin_override=false)

 * @return bool True if PM sent
*/
function send_pm($pm, $fromid = 0, $admin_override=false)

{

{

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

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





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

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

	{
return false;

	{
return false;

	}

if(!is_array($pm))

	}

if(!is_array($pm))

	{
return false;

	{
return false;

	}

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

	}

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

Zeile 8105Zeile 8371
		{
// Load user language
$lang->set_language($pm['language']);

		{
// Load user language
$lang->set_language($pm['language']);

			$lang->load($pm['language_file']);

			$lang->load($pm['language_file']);


$revert = true;
}

foreach(array('subject', 'message') as $key)
{


$revert = true;
}

foreach(array('subject', 'message') as $key)
{

			$lang_string = $pm[$key];

 
			if(is_array($pm[$key]))
{

			if(is_array($pm[$key]))
{

 
				$lang_string = $lang->{$pm[$key][0]};

				$num_args = count($pm[$key]);

				$num_args = count($pm[$key]);





				for($i = 1; $i < $num_args; $i++)
{

				for($i = 1; $i < $num_args; $i++)
{

					$lang->{$pm[$key][0]} = str_replace('{'.$i.'}', $pm[$key][$i], $lang->{$pm[$key][0]});

					$lang_string = str_replace('{'.$i.'}', $pm[$key][$i], $lang_string);

				}

				}


$lang_string = $pm[$key][0];



			}
else
{
$lang_string = $lang->{$pm[$key]};

			}


			}


			$pm[$key] = $lang->{$lang_string};

			$pm[$key] = $lang_string;

		}

if(isset($revert))

		}

if(isset($revert))

Zeile 8140Zeile 8408
	{
return false;
}

	{
return false;
}


$lang->load('messages');

 

require_once MYBB_ROOT."inc/datahandlers/pm.php";



require_once MYBB_ROOT."inc/datahandlers/pm.php";


Zeile 8167Zeile 8433
	if((int)$fromid == 0)
{
$fromid = (int)$mybb->user['uid'];

	if((int)$fromid == 0)
{
$fromid = (int)$mybb->user['uid'];

	}

	}

	elseif((int)$fromid < 0)
{
$fromid = 0;

	elseif((int)$fromid < 0)
{
$fromid = 0;

Zeile 8196Zeile 8462
		"savecopy" => 0,
"readreceipt" => 0
);

		"savecopy" => 0,
"readreceipt" => 0
);





	$pm['saveasdraft'] = 0;

// Admin override

	$pm['saveasdraft'] = 0;

// Admin override

Zeile 8225Zeile 8491
function log_spam_block($username = '', $email = '', $ip_address = '', $data = array())
{
global $db, $session;

function log_spam_block($username = '', $email = '', $ip_address = '', $data = array())
{
global $db, $session;





	if(!is_array($data))

	if(!is_array($data))

	{

	{

		$data = array($data);

		$data = array($data);

	}

	}


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


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





	$ip_address = my_inet_pton($ip_address);

$insert_array = array(

	$ip_address = my_inet_pton($ip_address);

$insert_array = array(

Zeile 8244Zeile 8510
		'ipaddress' => $db->escape_binary($ip_address),
'dateline' => (int)TIME_NOW,
'data' => $db->escape_string(@my_serialize($data)),

		'ipaddress' => $db->escape_binary($ip_address),
'dateline' => (int)TIME_NOW,
'data' => $db->escape_string(@my_serialize($data)),

	);

	);


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


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

Zeile 8264Zeile 8530

$success = false;



$success = false;


	$file_path = (string)$file_path;


	$file_path = (string)$file_path;


	$real_file_path = realpath($file_path);

	$real_file_path = realpath($file_path);





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

$file_name = basename($real_file_path);

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

$file_name = basename($real_file_path);





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

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

Zeile 8321Zeile 8587
	}

return $success;

	}

return $success;

 
}

/**
* Validate an url
*
* @param string $url The url to validate.
* @param bool $relative_path Whether or not the url could be a relative path.
* @param bool $allow_local Whether or not the url could be pointing to local networks.
*
* @return bool Whether this is a valid url.
*/
function my_validate_url($url, $relative_path=false, $allow_local=false)
{
if($allow_local)
{
$regex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:localhost|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))\.?))(?::\d{2,5})?(?:[/?#]\S*)?$_iuS';
}
else
{
$regex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$_iuS';
}

if($relative_path && my_substr($url, 0, 1) == '/' || preg_match($regex, $url))
{
return true;
}
return false;
}

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

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

}

}