Vergleich inc/functions.php - 1.8.3 - 1.8.5

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 173Zeile 173

if(isset($config))
{


if(isset($config))
{

 
			// Load DB interface
require_once MYBB_ROOT."inc/db_base.php";


			require_once MYBB_ROOT."inc/db_".$config['database']['type'].".php";
switch($config['database']['type'])
{

			require_once MYBB_ROOT."inc/db_".$config['database']['type'].".php";
switch($config['database']['type'])
{

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

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

		if($ty != 2 && (TIME_NOW - $stamp) < 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);

		{
$diff = TIME_NOW - $stamp;
$relative = array('prefix' => '', 'minute' => 0, 'plural' => $lang->rel_minutes_plural, 'suffix' => $lang->rel_ago);

Zeile 425Zeile 428

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

		elseif($ty != 2 && (TIME_NOW - $stamp) >= 3600 && (TIME_NOW - $stamp) < 43200)

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

		{
$diff = TIME_NOW - $stamp;
$relative = array('prefix' => '', 'hour' => 0, 'plural' => $lang->rel_hours_plural, 'suffix' => $lang->rel_ago);

		{
$diff = TIME_NOW - $stamp;
$relative = array('prefix' => '', 'hour' => 0, 'plural' => $lang->rel_hours_plural, 'suffix' => $lang->rel_ago);

Zeile 756Zeile 759
	}

// AJAX error message?

	}

// AJAX error message?

	if($mybb->get_input('ajax', 1))

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

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

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

Zeile 802Zeile 805
	}

// AJAX error message?

	}

// AJAX error message?

	if($mybb->get_input('ajax', 1))

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

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

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

Zeile 848Zeile 851

$db->update_query("sessions", $noperm_array, "sid='{$session->sid}'");



$db->update_query("sessions", $noperm_array, "sid='{$session->sid}'");


	if($mybb->get_input('ajax', 1))

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

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

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

Zeile 909Zeile 912

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



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


	if($mybb->get_input('ajax', 1))

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

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

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

Zeile 1198Zeile 1201
}

/**

}

/**

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

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

 *
* @param mixed 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

 *
* @param mixed 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

Zeile 1213Zeile 1216
	}

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

	}

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



 

if(count($groups) == 1)
{
return $groupscache[$gid];
}


if(count($groups) == 1)
{
return $groupscache[$gid];
}

 
	
$usergroup = array();


foreach($groups as $gid)
{


foreach($groups as $gid)
{

Zeile 1251Zeile 1255
				{
$usergroup[$perm] = $access;
}

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

			}
}
}

			}
}
}


return $usergroup;
}


return $usergroup;
}

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

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

	}


	}


	return $displaygroup;
}


	return $displaygroup;
}


Zeile 1306Zeile 1310
		if($uid != 0 && $uid != $mybb->user['uid'])
{
$user = get_user($uid);

		if($uid != 0 && $uid != $mybb->user['uid'])
{
$user = get_user($uid);





			$gid = $user['usergroup'].",".$user['additionalgroups'];
$groupperms = usergroup_permissions($gid);
}
else
{
$gid = $mybb->user['usergroup'];

			$gid = $user['usergroup'].",".$user['additionalgroups'];
$groupperms = usergroup_permissions($gid);
}
else
{
$gid = $mybb->user['usergroup'];





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

$groupperms = $mybb->usergroup;

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

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

	if(!is_array($fpermcache))

	{

	{

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


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


Zeile 1345Zeile 1349
			$cached_forum_permissions_permissions[$gid][$fid] = fetch_forum_permissions($fid, $gid, $groupperms);
}
return $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];

	}

	}

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

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

Zeile 1358Zeile 1362
		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 1371Zeile 1375
function fetch_forum_permissions($fid, $gid, $groupperms)
{
global $groupscache, $forum_cache, $fpermcache, $mybb, $fpermfields;

function fetch_forum_permissions($fid, $gid, $groupperms)
{
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

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

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

Zeile 1381Zeile 1385

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


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

 
	$only_reply_own_threads = 1;


foreach($groups as $gid)
{


foreach($groups as $gid)
{

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

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

			}

			}


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


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

			{

			{

				if(empty($current_permissions[$permission]) || $access >= $current_permissions[$permission] || ($access == "yes" && $current_permissions[$permission] == "no"))
{
$current_permissions[$permission] = $access;
}

				if(empty($current_permissions[$permission]) || $access >= $current_permissions[$permission] || ($access == "yes" && $current_permissions[$permission] == "no"))
{
$current_permissions[$permission] = $access;
}

			}


			}


			if($level_permissions["canview"] && empty($level_permissions["canonlyviewownthreads"]))
{
$only_view_own_threads = 0;

			if($level_permissions["canview"] && empty($level_permissions["canonlyviewownthreads"]))
{
$only_view_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)
{
$current_permissions["canonlyviewownthreads"] = 0;

	// Figure out if we can view more than our own threads
if($only_view_own_threads == 0)
{
$current_permissions["canonlyviewownthreads"] = 0;

 
	}

// Figure out if we can reply more than our own threads
if($only_reply_own_threads == 0)
{
$current_permissions["canonlyreplyownthreads"] = 0;

	}

if(count($current_permissions) == 0)

	}

if(count($current_permissions) == 0)

Zeile 1438Zeile 1454
		$current_permissions = $groupperms;
}
return $current_permissions;

		$current_permissions = $groupperms;
}
return $current_permissions;

}

/**

}

/**

 * Check the password given on a certain forum for validity
*
* @param int The forum ID

 * Check the password given on a certain forum for validity
*
* @param int The forum ID

Zeile 1449Zeile 1465
function check_forum_password($fid, $pid=0)
{
global $mybb, $header, $footer, $headerinclude, $theme, $templates, $lang, $forum_cache;

function check_forum_password($fid, $pid=0)
{
global $mybb, $header, $footer, $headerinclude, $theme, $templates, $lang, $forum_cache;





	$showform = true;

if(!is_array($forum_cache))

	$showform = true;

if(!is_array($forum_cache))

	{

	{

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

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

Zeile 1466Zeile 1482
	{
$parents = explode(',', $forum_cache[$fid]['parentlist']);
rsort($parents);

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

	}

	}

	if(!empty($parents))
{
foreach($parents as $parent_id)

	if(!empty($parents))
{
foreach($parents as $parent_id)

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

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

			}

			}

		}
}


		}
}


Zeile 1488Zeile 1504
		$password = $forum_cache[$fid]['password'];
if(isset($mybb->input['pwverify']) && $pid == 0)
{

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

			if($password == $mybb->get_input('pwverify'))
{

			if($password === $mybb->get_input('pwverify'))
{

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

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

				$showform = false;
}
else
{

				$showform = false;
}
else
{

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

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

			if(!$mybb->cookies['forumpass'][$fid] || ($mybb->cookies['forumpass'][$fid] && md5($mybb->user['uid'].$password) != $mybb->cookies['forumpass'][$fid]))

			if(!$mybb->cookies['forumpass'][$fid] || ($mybb->cookies['forumpass'][$fid] && md5($mybb->user['uid'].$password) !== $mybb->cookies['forumpass'][$fid]))

			{
$showform = true;
}

			{
$showform = true;
}

Zeile 1521Zeile 1537
		if($pid)
{
header("Location: ".$mybb->settings['bburl']."/".get_forum_link($fid));

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

		}

		}

		else
{
$_SERVER['REQUEST_URI'] = htmlspecialchars_uni($_SERVER['REQUEST_URI']);

		else
{
$_SERVER['REQUEST_URI'] = htmlspecialchars_uni($_SERVER['REQUEST_URI']);

Zeile 1534Zeile 1550

/**
* Return the permissions for a moderator in a specific forum


/**
* Return the permissions for a moderator in a specific forum

 *

 *

 * @param fid The forum ID
* @param uid The user ID to fetch permissions for (0 assumes current logged in user)
* @param string The parent list for the forum (if blank, will be fetched)

 * @param fid The forum ID
* @param uid The user ID to fetch permissions for (0 assumes current logged in user)
* @param string The parent list for the forum (if blank, will be fetched)

Zeile 1586Zeile 1602
	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 1595Zeile 1611
		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)
{
continue;

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

				}

// Figure out the user permissions
if($value == 0)

				}

// Figure out the user permissions
if($value == 0)

				{

				{

					// The user doesn't have permission to set this action
$perms[$action] = 0;
}
else
{
$perms[$action] = max($perm[$action], $perms[$action]);

					// The user doesn't have permission to set this action
$perms[$action] = 0;
}
else
{
$perms[$action] = max($perm[$action], $perms[$action]);

				}
}

				}
}

		}

foreach($groups as $group)

		}

foreach($groups as $group)

Zeile 1639Zeile 1655
	$modpermscache[$fid][$uid] = $perms;

return $perms;

	$modpermscache[$fid][$uid] = $perms;

return $perms;

}


}


/**
* Checks if a moderator has permissions to perform an action in a specific forum
*

/**
* Checks if a moderator has permissions to perform an action in a specific forum
*

Zeile 1750Zeile 1766
	foreach($posticons as $dbicon)
{
$dbicon['path'] = str_replace("{theme}", $theme['imgdir'], $dbicon['path']);

	foreach($posticons as $dbicon)
{
$dbicon['path'] = str_replace("{theme}", $theme['imgdir'], $dbicon['path']);

		$dbicon['path'] = htmlspecialchars_uni($dbicon['path']);

		$dbicon['path'] = htmlspecialchars_uni($mybb->get_asset_url($dbicon['path']));

		$dbicon['name'] = htmlspecialchars_uni($dbicon['name']);

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

		$dbicon['name'] = htmlspecialchars_uni($dbicon['name']);

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

Zeile 1854Zeile 1870
 * @param string The cookie identifier.
* @param int The cookie content id.
* @return array|boolean The cookie id's content array or false when non-existent.

 * @param string The cookie identifier.
* @param int The cookie content id.
* @return array|boolean The cookie id's content array or false when non-existent.

 */

 */

function my_get_array_cookie($name, $id)
{
global $mybb;

if(!isset($mybb->cookies['mybb'][$name]))

function my_get_array_cookie($name, $id)
{
global $mybb;

if(!isset($mybb->cookies['mybb'][$name]))

	{
return false;
}


	{
return false;
}


	$cookie = my_unserialize($mybb->cookies['mybb'][$name]);

if(is_array($cookie) && isset($cookie[$id]))
{
return $cookie[$id];

	$cookie = my_unserialize($mybb->cookies['mybb'][$name]);

if(is_array($cookie) && isset($cookie[$id]))
{
return $cookie[$id];

	}
else

	}
else

	{
return 0;
}

	{
return 0;
}

Zeile 1878Zeile 1894

/**
* Set a serialised cookie array.


/**
* Set a serialised cookie array.

 *

 *

 * @param string The cookie identifier.
* @param int The cookie content id.
* @param string The value to set the cookie to.
* @param int The timestamp of the expiry date.
*/
function my_set_array_cookie($name, $id, $value, $expires="")

 * @param string The cookie identifier.
* @param int The cookie content id.
* @param string The value to set the cookie to.
* @param int The timestamp of the expiry date.
*/
function my_set_array_cookie($name, $id, $value, $expires="")

{

{

	global $mybb;

$cookie = $mybb->cookies['mybb'];

	global $mybb;

$cookie = $mybb->cookies['mybb'];

Zeile 1899Zeile 1915
	}

$newcookie[$id] = $value;

	}

$newcookie[$id] = $value;

	$newcookie = serialize($newcookie);

	$newcookie = my_serialize($newcookie);

	my_setcookie("mybb[$name]", addslashes($newcookie), $expires);

// Make sure our current viarables are up-to-date as well
$mybb->cookies['mybb'][$name] = $newcookie;

	my_setcookie("mybb[$name]", addslashes($newcookie), $expires);

// Make sure our current viarables are up-to-date as well
$mybb->cookies['mybb'][$name] = $newcookie;

 
}

/*
* Arbitrary limits for _safe_unserialize()
*/
define('MAX_SERIALIZED_INPUT_LENGTH', 10240);
define('MAX_SERIALIZED_ARRAY_LENGTH', 256);
define('MAX_SERIALIZED_ARRAY_DEPTH', 5);

/**
* Credits go to https://github.com/piwik
* Safe unserialize() replacement
* - accepts a strict subset of PHP's native my_serialized representation
* - does not unserialize objects
*
* @param string $str
* @return mixed
* @throw Exception if $str is malformed or contains unsupported types (e.g., resources, objects)
*/
function _safe_unserialize($str)
{
if(strlen($str) > MAX_SERIALIZED_INPUT_LENGTH)
{
// input exceeds MAX_SERIALIZED_INPUT_LENGTH
return false;
}

if(empty($str) || !is_string($str))
{
return false;
}

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

/*
* states:
* 0 - initial state, expecting a single value or array
* 1 - terminal state
* 2 - in array, expecting end of array or a key
* 3 - in array, expecting value or another array
*/
$state = 0;
while($state != 1)
{
$type = isset($str[0]) ? $str[0] : '';

if($type == '}')
{
$str = substr($str, 1);
}
else if($type == 'N' && $str[1] == ';')
{
$value = null;
$str = substr($str, 2);
}
else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
{
$value = $matches[1] == '1' ? true : false;
$str = substr($str, 4);
}
else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
{
$value = (int)$matches[1];
$str = $matches[2];
}
else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
{
$value = (float)$matches[1];
$str = $matches[3];
}
else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
{
$value = substr($matches[2], 0, (int)$matches[1]);
$str = substr($matches[2], (int)$matches[1] + 2);
}
else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches) && $matches[1] < MAX_SERIALIZED_ARRAY_LENGTH)
{
$expectedLength = (int)$matches[1];
$str = $matches[2];
}
else
{
// object or unknown/malformed type
return false;
}

switch($state)
{
case 3: // in array, expecting value or another array
if($type == 'a')
{
if(count($stack) >= MAX_SERIALIZED_ARRAY_DEPTH)
{
// array nesting exceeds MAX_SERIALIZED_ARRAY_DEPTH
return false;
}

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

// missing array value
return false;

case 2: // in array, expecting end of array or a key
if($type == '}')
{
if(count($list) < end($expected))
{
// array size less than expected
return false;
}

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

// go to terminal state if we're at the end of the root array
array_pop($expected);
if(count($expected) == 0) {
$state = 1;
}
break;
}
if($type == 'i' || $type == 's')
{
if(count($list) >= MAX_SERIALIZED_ARRAY_LENGTH)
{
// array size exceeds MAX_SERIALIZED_ARRAY_LENGTH
return false;
}
if(count($list) >= end($expected))
{
// array size exceeds expected length
return false;
}

$key = $value;
$state = 3;
break;
}

// illegal array index type
return false;

case 0: // expecting array or value
if($type == 'a')
{
if(count($stack) >= MAX_SERIALIZED_ARRAY_DEPTH)
{
// array nesting exceeds MAX_SERIALIZED_ARRAY_DEPTH
return false;
}

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

// not in array
return false;
}
}

if(!empty($str))
{
// trailing data in input
return false;
}
return $data;
}

/**
* Credits go to https://github.com/piwik
* Wrapper for _safe_unserialize() that handles exceptions and multibyte encoding issue
*
* @param string $str
* @return mixed
*/
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;
}

/**
* Credits go to https://github.com/piwik
* Safe serialize() replacement
* - output a strict subset of PHP's native serialized representation
* - does not my_serialize objects
*
* @param mixed $value
* @return string
* @throw Exception if $value is malformed or contains unsupported types (e.g., resources, objects)
*/
function _safe_serialize( $value )
{
if(is_null($value))
{
return 'N;';
}

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

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

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

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

if(is_array($value))
{
$out = '';
foreach($value as $k => $v)
{
$out .= _safe_serialize($k) . _safe_serialize($v);
}

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

// safe_serialize cannot my_serialize resources or objects
return false;

}

/**

}

/**

 * Verifies that data passed is an array


 * Credits go to https://github.com/piwik
* Wrapper for _safe_serialize() that handles exceptions and multibyte encoding issue

 *

 *

 * @param array Data to unserialize
* @return array Unserialized data array
*/
function my_unserialize($data)

 * @param mixed $value
* @return string
*/
function my_serialize($value)

{

{

	// Do no unserialize objects
if(substr($data, 0, 1) == 'O')








	// 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_serialize($value);
if(isset($mbIntEnc))

	{

	{

		return array();
}

$array = unserialize($data);

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

		mb_internal_encoding($mbIntEnc);








	}

	}


return $array;

	
return $out;

}

/**

}

/**

Zeile 2065Zeile 2349

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

	foreach($counters as $counter)
{
if(array_key_exists($counter, $changes))
{
if(substr($changes[$counter], 0, 2) == "+-")
{
$changes[$counter] = substr($changes[$counter], 1);
}
// Adding or subtracting from previous value?
if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
{
if((int)$changes[$counter] != 0)
{

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

Zeile 2092Zeile 2376
					{
$new_stats[$counter] = 0;
}

					{
$new_stats[$counter] = 0;
}

				}
}

				}
}

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

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

Zeile 2107Zeile 2391
	}

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 2163Zeile 2447
	// Fetch above counters for this forum
$query = $db->simple_select("forums", implode(",", $counters), "fid='{$fid}'");
$forum = $db->fetch_array($query);

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





	foreach($counters as $counter)

	foreach($counters as $counter)

	{

	{

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

// 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 2224Zeile 2508
		else
{
$new_stats['numunapprovedthreads'] = "{$unapprovedthreads_diff}";

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

		}
}

		}
}


if(array_key_exists('posts', $update_query))
{


if(array_key_exists('posts', $update_query))
{

Zeile 2254Zeile 2538
	}

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

	}

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

	{

	{

		$deletedposts_diff = $update_query['deletedposts'] - $forum['deletedposts'];
if($deletedposts_diff > -1)
{

		$deletedposts_diff = $update_query['deletedposts'] - $forum['deletedposts'];
if($deletedposts_diff > -1)
{

Zeile 2284Zeile 2568
		update_stats($new_stats);
}
}

		update_stats($new_stats);
}
}





/**
* Update the last post information for a specific forum
*

/**
* Update the last post information for a specific forum
*

Zeile 2313Zeile 2597
	);

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

	);

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

}

}


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


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

Zeile 2547Zeile 2831
 * @param int The current depth of forums we're at
* @param int Whether or not to show extra items such as User CP, Forum home
* @param boolean Ignore the showinjump setting and show all forums (for moderation pages)

 * @param int The current depth of forums we're at
* @param int Whether or not to show extra items such as User CP, Forum home
* @param boolean Ignore the showinjump setting and show all forums (for moderation pages)

 * @param array Array of permissions

 * @param unknown_type deprecated

 * @param string The name of the forum jump
* @return string Forum jump items
*/
function build_forum_jump($pid="0", $selitem="", $addselect="1", $depth="", $showextras="1", $showall=false, $permissions="", $name="fid")
{

 * @param string The name of the forum jump
* @return string Forum jump items
*/
function build_forum_jump($pid="0", $selitem="", $addselect="1", $depth="", $showextras="1", $showall=false, $permissions="", $name="fid")
{

	global $forum_cache, $jumpfcache, $permissioncache, $mybb, $selecteddone, $forumjump, $forumjumpbits, $gobutton, $theme, $templates, $lang;

	global $forum_cache, $jumpfcache, $permissioncache, $mybb, $forumjump, $forumjumpbits, $gobutton, $theme, $templates, $lang;


$pid = (int)$pid;


$pid = (int)$pid;

	$jumpsel['default'] = '';

if($permissions)
{
$permissions = $mybb->usergroup;
}

 

if(!is_array($jumpfcache))
{
if(!is_array($forum_cache))


if(!is_array($jumpfcache))
{
if(!is_array($forum_cache))

		{

		{

			cache_forums();
}


			cache_forums();
}


Zeile 2575Zeile 2853
			if($forum['active'] != 0)
{
$jumpfcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;

			if($forum['active'] != 0)
{
$jumpfcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;

			}

			}

		}
}


		}
}


Zeile 2597Zeile 2875
					$optionselected = "";

if($selitem == $forum['fid'])

					$optionselected = "";

if($selitem == $forum['fid'])

					{
$optionselected = "selected=\"selected\"";
$selecteddone = 1;
}

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


					{
$optionselected = 'selected="selected"';
}

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



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

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

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

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

Zeile 2612Zeile 2889
						$forumjumpbits .= build_forum_jump($forum['fid'], $selitem, 0, $newdepth, $showextras, $showall);
}
}

						$forumjumpbits .= build_forum_jump($forum['fid'], $selitem, 0, $newdepth, $showextras, $showall);
}
}

			}
}
}


			}
}
}


	if($addselect)
{

	if($addselect)
{

		if(!$selecteddone)
{
if(!$selitem)
{
$selitem = "default";
}

$jumpsel[$selitem] = 'selected="selected"';
}

if($showextras == 0)

		if($showextras == 0)











		{
$template = "special";
}

		{
$template = "special";
}

Zeile 2637Zeile 2904
			$template = "advanced";

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

			$template = "advanced";

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

			{
$forum_link = "'".str_replace('{fid}', "'+this.options[this.selectedIndex].value+'", FORUM_URL)."'";
}

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

			else
{

			else
{

				$forum_link = "'".str_replace('{fid}', "'+this.options[this.selectedIndex].value", FORUM_URL);

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

			}
}

			}
}





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

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





	return $forumjump;

	return $forumjump;

}

/**

}

/**

 * Returns the extension of a file.
*
* @param string The filename.

 * Returns the extension of a file.
*
* @param string The filename.

Zeile 2678Zeile 2945
	{
$ch = my_rand(0, count($set)-1);
$str .= $set[$ch];

	{
$ch = my_rand(0, count($set)-1);
$str .= $set[$ch];

	}


	}


	return $str;
}


	return $str;
}


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

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

	}

$format = stripslashes($format);

	}

$format = stripslashes($format);


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


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

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


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


	if(isset($avatars[$avatar]))
{
return $avatars[$avatar];













	if(!$max_dimensions)
{
$max_dimensions = $mybb->settings['maxavatardims'];
}

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

	}


	}


	if(!$max_dimensions)

	if(isset($avatars[$avatar][$key][$key2]))

	{

	{

		$max_dimensions = $mybb->settings['maxavatardims'];

		return $avatars[$avatar][$key][$key2];

	}

$avatar_width_height = '';

	}

$avatar_width_height = '';

Zeile 2764Zeile 3043
		{
list($max_width, $max_height) = explode('x', $max_dimensions);


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


			if($dimensions[0] > $max_width || $dimensions[1] > $max_height)

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

			{
require_once MYBB_ROOT."inc/functions_image.php";
$scaled_dimensions = scale_image($dimensions[0], $dimensions[1], $max_width, $max_height);

			{
require_once MYBB_ROOT."inc/functions_image.php";
$scaled_dimensions = scale_image($dimensions[0], $dimensions[1], $max_width, $max_height);

Zeile 2777Zeile 3056
		}
}


		}
}


	$avatars[$avatar] = array(
'image' => $mybb->get_asset_url($avatar),

	$avatars[$avatar][$key][$key2] = array(
'image' => htmlspecialchars_uni($mybb->get_asset_url($avatar)),

		'width_height' => $avatar_width_height
);


		'width_height' => $avatar_width_height
);


	return $avatars[$avatar];

	return $avatars[$avatar][$key][$key2];

}

/**

}

/**

Zeile 2918Zeile 3197
						{
$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;

						}
}
}


						}
}
}


				unset($smilie);

if(is_array($smiliecache))

				unset($smilie);

if(is_array($smiliecache))

Zeile 2939Zeile 3218
						// 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 = htmlspecialchars_uni($smilie['find']);
$image = $mybb->get_asset_url($smilie['image']);
$image = htmlspecialchars_uni($image);


						$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($i < $mybb->settings['smilieinsertertot'])
{
$dropdownsmilies .= '"'.$find.'": "'.$image.'",';

						if($i < $mybb->settings['smilieinsertertot'])
{
$dropdownsmilies .= '"'.$find.'": "'.$image.'",';

Zeile 2953Zeile 3233

for($j = 1; $j < $finds_count; ++$j)
{


for($j = 1; $j < $finds_count; ++$j)
{

							$find = htmlspecialchars_uni($finds[$j]);

							$find = str_replace(array('\\', '"'), array('\\\\', '\"'), htmlspecialchars_uni($finds[$j]));

							$hiddensmilies .= '"'.$find.'": "'.$image.'",';
}
++$i;

							$hiddensmilies .= '"'.$find.'": "'.$image.'",';
}
++$i;

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

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

			}


			}


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

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

Zeile 3041Zeile 3321
		{
$smilie_cache = $cache->read("smilies");
$smiliecount = count($smilie_cache);

		{
$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)
{
if($smilie['showclickable'] != 0)

			foreach($smilie_cache as $smilie)
{
if($smilie['showclickable'] != 0)

Zeile 3060Zeile 3340
		}

unset($smilie);

		}

unset($smilie);





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

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

Zeile 3089Zeile 3369
					{
$smilies .= "<tr>\n";
}

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


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


					$find = htmlspecialchars_uni($smilie['find']);

					$find = str_replace(array('\\', "'"), array('\\\\', "\'"), htmlspecialchars_uni($smilie['find']));





					$onclick = ' onclick="MyBBEditor.insertText(\' '.$smilie['find'].' \');"';

					$onclick = " onclick=\"MyBBEditor.insertText(' $find ');\"";

					$extra_class = ' smilie_pointer';
eval('$smilie = "'.$templates->get('smilie', 1, 0).'";');
eval("\$smilies .= \"".$templates->get("smilieinsert_smilie")."\";");

					$extra_class = ' smilie_pointer';
eval('$smilie = "'.$templates->get('smilie', 1, 0).'";');
eval("\$smilies .= \"".$templates->get("smilieinsert_smilie")."\";");

Zeile 3274Zeile 3558
	if(((int)$selected_pid == 0) && $selected_pid != 'any')
{
$default_selected = " selected=\"selected\"";

	if(((int)$selected_pid == 0) && $selected_pid != 'any')
{
$default_selected = " selected=\"selected\"";

	}

foreach($prefixes as $prefix)
{

	}

foreach($prefixes as $prefix)
{

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

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

Zeile 3460Zeile 3744
		unset($data['pid']);
}


		unset($data['pid']);
}


	// Any remaining extra data - we serialize and insert in to its own column

	// Any remaining extra data - we my_serialize and insert in to its own column

	if(is_array($data))
{

	if(is_array($data))
{

		$data = serialize($data);

		$data = my_serialize($data);

	}

$sql_array = array(

	}

$sql_array = array(

Zeile 3503Zeile 3787
	{
$reputation_class = "reputation_neutral";
}

	{
$reputation_class = "reputation_neutral";
}

 
	
$reputation = my_number_format($reputation);


if($uid != 0)
{


if($uid != 0)
{

Zeile 3557Zeile 3843
{
global $mybb, $plugins;


{
global $mybb, $plugins;


	$ip = $_SERVER['REMOTE_ADDR'];

	$ip = strtolower($_SERVER['REMOTE_ADDR']);


if($mybb->settings['ip_forwarded_check'])
{


if($mybb->settings['ip_forwarded_check'])
{

Zeile 3565Zeile 3851

if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{


if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{

			$addresses = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);

			$addresses = explode(',', strtolower($_SERVER['HTTP_X_FORWARDED_FOR']));

		}
elseif(isset($_SERVER['HTTP_X_REAL_IP']))
{

		}
elseif(isset($_SERVER['HTTP_X_REAL_IP']))
{

			$addresses = explode(',', $_SERVER['HTTP_X_REAL_IP']);

			$addresses = explode(',', strtolower($_SERVER['HTTP_X_REAL_IP']));

		}

if(is_array($addresses))

		}

if(is_array($addresses))

Zeile 3591Zeile 3877
	{
if(isset($_SERVER['HTTP_CLIENT_IP']))
{

	{
if(isset($_SERVER['HTTP_CLIENT_IP']))
{

			$ip = $_SERVER['HTTP_CLIENT_IP'];

			$ip = strtolower($_SERVER['HTTP_CLIENT_IP']);

		}
}


		}
}


Zeile 3710Zeile 3996
 */
function get_attachment_icon($ext)
{

 */
function get_attachment_icon($ext)
{

	global $cache, $attachtypes, $theme, $templates, $lang;

	global $cache, $attachtypes, $theme, $templates, $lang, $mybb;


if(!$attachtypes)
{


if(!$attachtypes)
{

Zeile 3721Zeile 4007

if($attachtypes[$ext]['icon'])
{


if($attachtypes[$ext]['icon'])
{

		if(defined("IN_ADMINCP"))


		static $attach_icons_schemes = array();
if(!isset($attach_icons_schemes[$ext]))

		{

		{

			$icon = str_replace("{theme}", "", $attachtypes[$ext]['icon']);
if(my_substr($icon, 0, 1) != "/" && my_substr($icon, 0, 7) != "http://")



















			$attach_icons_schemes[$ext] = parse_url($attachtypes[$ext]['icon']);
if(!empty($attach_icons_schemes[$ext]['scheme']))
{
$attach_icons_schemes[$ext] = $attachtypes[$ext]['icon'];
}
elseif(defined("IN_ADMINCP"))
{
$attach_icons_schemes[$ext] = str_replace("{theme}", "", $attachtypes[$ext]['icon']);
if(my_substr($attach_icons_schemes[$ext], 0, 1) != "/")
{
$attach_icons_schemes[$ext] = "../".$attach_icons_schemes[$ext];
}
}
elseif(defined("IN_PORTAL"))
{
global $change_dir;
$attach_icons_schemes[$ext] = $change_dir."/".str_replace("{theme}", $theme['imgdir'], $attachtypes[$ext]['icon']);
$attach_icons_schemes[$ext] = $mybb->get_asset_url($attach_icons_schemes[$ext]);
}
else

			{

			{

				$icon = "../".$icon;


				$attach_icons_schemes[$ext] = str_replace("{theme}", $theme['imgdir'], $attachtypes[$ext]['icon']);
$attach_icons_schemes[$ext] = $mybb->get_asset_url($attach_icons_schemes[$ext]);

			}

			}

		}
elseif(defined("IN_PORTAL"))
{
global $change_dir;
$icon = $change_dir."/".str_replace("{theme}", $theme['imgdir'], $attachtypes[$ext]['icon']);
}
else
{
$icon = str_replace("{theme}", $theme['imgdir'], $attachtypes[$ext]['icon']);
}


		}

$icon = $attach_icons_schemes[$ext];









		$name = htmlspecialchars_uni($attachtypes[$ext]['name']);
}
else
{
if(defined("IN_ADMINCP"))

		$name = htmlspecialchars_uni($attachtypes[$ext]['name']);
}
else
{
if(defined("IN_ADMINCP"))

		{

		{

			$theme['imgdir'] = "../images";
}
else if(defined("IN_PORTAL"))
{
global $change_dir;
$theme['imgdir'] = "{$change_dir}/images";

			$theme['imgdir'] = "../images";
}
else if(defined("IN_PORTAL"))
{
global $change_dir;
$theme['imgdir'] = "{$change_dir}/images";

		}

$icon = "{$theme['imgdir']}/attachtypes/unknown.png";
$name = $lang->unknown;
}


		}

$icon = "{$theme['imgdir']}/attachtypes/unknown.png";

$name = $lang->unknown;
}





 
	$icon = htmlspecialchars_uni($icon);

	eval("\$attachment_icon = \"".$templates->get("attachment_icon")."\";");
return $attachment_icon;
}

	eval("\$attachment_icon = \"".$templates->get("attachment_icon")."\";");
return $attachment_icon;
}





/**
* Get a list of the unviewable forums for the current user
*

/**
* Get a list of the unviewable forums for the current user
*

Zeile 3769Zeile 4070
 */
function get_unviewable_forums($only_readable_threads=false)
{

 */
function get_unviewable_forums($only_readable_threads=false)
{

	global $forum_cache, $permissioncache, $mybb, $unviewable, $templates, $forumpass;

if(!isset($permissions))
{
$permissions = $mybb->usergroup;
}

	global $forum_cache, $permissioncache, $mybb;







if(!is_array($forum_cache))
{


if(!is_array($forum_cache))
{

Zeile 3786Zeile 4082
		$permissioncache = forum_permissions();
}


		$permissioncache = forum_permissions();
}


	$unviewableforums = '';
$password_forums = array();

	$password_forums = $unviewable = array();


	foreach($forum_cache as $fid => $forum)
{
if($permissioncache[$forum['fid']])
{
$perms = $permissioncache[$forum['fid']];

	foreach($forum_cache as $fid => $forum)
{
if($permissioncache[$forum['fid']])
{
$perms = $permissioncache[$forum['fid']];

		}

		}

		else
{
$perms = $mybb->usergroup;

		else
{
$perms = $mybb->usergroup;

		}

$pwverified = 1;

		}

$pwverified = 1;


if($forum['password'] != "")
{


if($forum['password'] != "")
{

			if($mybb->cookies['forumpass'][$forum['fid']] != md5($mybb->user['uid'].$forum['password']))

			if($mybb->cookies['forumpass'][$forum['fid']] !== md5($mybb->user['uid'].$forum['password']))

			{
$pwverified = 0;
}

$password_forums[$forum['fid']] = $forum['password'];

			{
$pwverified = 0;
}

$password_forums[$forum['fid']] = $forum['password'];

		}

		}

		else

		else

		{

		{

			// Check parents for passwords
$parents = explode(",", $forum['parentlist']);
foreach($parents as $parent)

			// Check parents for passwords
$parents = explode(",", $forum['parentlist']);
foreach($parents as $parent)

			{
if(isset($password_forums[$parent]) && $mybb->cookies['forumpass'][$parent] != md5($mybb->user['uid'].$password_forums[$parent]))

			{
if(isset($password_forums[$parent]) && $mybb->cookies['forumpass'][$parent] !== md5($mybb->user['uid'].$password_forums[$parent]))

				{
$pwverified = 0;
}

				{
$pwverified = 0;
}

			}
}

			}
}


if($perms['canview'] == 0 || $pwverified == 0 || ($only_readable_threads == true && $perms['canviewthreads'] == 0))
{


if($perms['canview'] == 0 || $pwverified == 0 || ($only_readable_threads == true && $perms['canviewthreads'] == 0))
{

			if($unviewableforums)
{
$unviewableforums .= ",";
}

$unviewableforums .= "'".$forum['fid']."'";
}
}

if(isset($unviewableforums))
{
return $unviewableforums;

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











	}

	}

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

return $unviewableforums;

}

/**

}

/**

Zeile 3848Zeile 4137
 * @return string The correct date format
*/
function fix_mktime($format, $year)

 * @return string The correct date format
*/
function fix_mktime($format, $year)

{

{

	// Our little work around for the date < 1970 thing.
// -2 idea provided by Matt Light (http://www.mephex.com)
$format = str_replace("Y", $year, $format);

	// Our little work around for the date < 1970 thing.
// -2 idea provided by Matt Light (http://www.mephex.com)
$format = str_replace("Y", $year, $format);

Zeile 3892Zeile 4181
				if(!empty($navbit['multipage']))
{
if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)

				if(!empty($navbit['multipage']))
{
if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)

					{

					{

						$mybb->settings['threadsperpage'] = 20;
}


						$mybb->settings['threadsperpage'] = 20;
}


Zeile 3921Zeile 4210
	if($nav)
{
eval("\$activesep = \"".$templates->get("nav_sep_active")."\";");

	if($nav)
{
eval("\$activesep = \"".$templates->get("nav_sep_active")."\";");

	}


	}


	eval("\$activebit = \"".$templates->get("nav_bit_active")."\";");
eval("\$donenav = \"".$templates->get("nav")."\";");


	eval("\$activebit = \"".$templates->get("nav_bit_active")."\";");
eval("\$donenav = \"".$templates->get("nav")."\";");


Zeile 3936Zeile 4225
 * @param string The URL of the item to add
*/
function add_breadcrumb($name, $url="")

 * @param string The URL of the item to add
*/
function add_breadcrumb($name, $url="")

{

{

	global $navbits;

$navsize = count($navbits);

	global $navbits;

$navsize = count($navbits);

Zeile 3964Zeile 4253
		foreach($forum_cache as $key => $val)
{
$pforumcache[$val['fid']][$val['pid']] = $val;

		foreach($forum_cache as $key => $val)
{
$pforumcache[$val['fid']][$val['pid']] = $val;

		}
}


		}
}


	if(is_array($pforumcache[$fid]))
{
foreach($pforumcache[$fid] as $key => $forumnav)

	if(is_array($pforumcache[$fid]))
{
foreach($pforumcache[$fid] as $key => $forumnav)

Zeile 3995Zeile 4284
					}
}
elseif(!empty($multipage))

					}
}
elseif(!empty($multipage))

				{

				{

					$navbits[$navsize]['url'] = get_forum_link($forumnav['fid'], $multipage['current_page']);

					$navbits[$navsize]['url'] = get_forum_link($forumnav['fid'], $multipage['current_page']);





					$navbits[$navsize]['multipage'] = $multipage;
$navbits[$navsize]['multipage']['url'] = str_replace('{fid}', $forumnav['fid'], FORUM_URL_PAGED);
}

					$navbits[$navsize]['multipage'] = $multipage;
$navbits[$navsize]['multipage']['url'] = str_replace('{fid}', $forumnav['fid'], FORUM_URL_PAGED);
}

Zeile 4008Zeile 4297
			}
}
}

			}
}
}





	return 1;

	return 1;

}


}


/**
* Resets the breadcrumb navigation to the first item, and clears the rest
*/

/**
* Resets the breadcrumb navigation to the first item, and clears the rest
*/

Zeile 4243Zeile 4532
	global $db, $cache, $plugins;

switch($type)

	global $db, $cache, $plugins;

switch($type)

	{

	{

		case "posts":
if(is_array($id))
{

		case "posts":
if(is_array($id))
{

Zeile 4272Zeile 4561
		case "all":
$db->update_query("reportedcontent", array('reportstatus' => 1), "reportstatus='0' AND (type = 'post' OR type = '')");
break;

		case "all":
$db->update_query("reportedcontent", array('reportstatus' => 1), "reportstatus='0' AND (type = 'post' OR type = '')");
break;

	}

	}


$arguments = array('id' => $id, 'type' => $type);
$plugins->run_hooks("mark_reports", $arguments);


$arguments = array('id' => $id, 'type' => $type);
$plugins->run_hooks("mark_reports", $arguments);

Zeile 4330Zeile 4619
		$lang_minutes = " ".$lang->minutes;
$lang_second = " ".$lang->second;
$lang_seconds = " ".$lang->seconds;

		$lang_minutes = " ".$lang->minutes;
$lang_second = " ".$lang->second;
$lang_seconds = " ".$lang->seconds;

	}

	}


$years = floor($stamp/$ysecs);
$stamp %= $ysecs;


$years = floor($stamp/$ysecs);
$stamp %= $ysecs;

Zeile 4345Zeile 4634
	$minutes = floor($stamp/$msecs);
$stamp %= $msecs;
$seconds = $stamp;

	$minutes = floor($stamp/$msecs);
$stamp %= $msecs;
$seconds = $stamp;





	if($years == 1)

	if($years == 1)

	{

	{

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

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

	}

	}

	else if($years > 1)

	else if($years > 1)

	{

	{

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

if($months == 1)

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

if($months == 1)

	{

	{

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

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

	{

	{

		$nicetime['months'] = $months.$lang_months;

		$nicetime['months'] = $months.$lang_months;

	}

	}


if($weeks == 1)


if($weeks == 1)

	{

	{

		$nicetime['weeks'] = "1".$lang_week;

		$nicetime['weeks'] = "1".$lang_week;

	}

	}

	else if($weeks > 1)

	else if($weeks > 1)

	{

	{

		$nicetime['weeks'] = $weeks.$lang_weeks;
}

if($days == 1)

		$nicetime['weeks'] = $weeks.$lang_weeks;
}

if($days == 1)

	{

	{

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

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

	}

	}

	else if($days > 1)

	else if($days > 1)

	{

	{

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


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


Zeile 4389Zeile 4678
			$nicetime['hours'] = "1".$lang_hour;
}
else if($hours > 1)

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

		{

		{

			$nicetime['hours'] = $hours.$lang_hours;

			$nicetime['hours'] = $hours.$lang_hours;

		}

		}

	}

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

	}

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

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

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

		}

		}

	}

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

	}

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

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

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





	if($alttrow == "trow1" && !$reset)

	if($alttrow == "trow1" && !$reset)

	{

	{

		$trow = "trow2";

		$trow = "trow2";

	}

	}

	else
{
$trow = "trow1";
}

	else
{
$trow = "trow1";
}





	$alttrow = $trow;

return $trow;
}

	$alttrow = $trow;

return $trow;
}





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

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

Zeile 4477Zeile 4766
	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 4490Zeile 4779

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

	{

	{

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

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

Zeile 4517Zeile 4806
	else
{
$user = get_user($uid);

	else
{
$user = get_user($uid);

	}


	}


	$groupslist = $comma = '';
$usergroups = $user['additionalgroups'].",";
$donegroup = array();

	$groupslist = $comma = '';
$usergroups = $user['additionalgroups'].",";
$donegroup = array();

Zeile 4558Zeile 4847
 *
* @param boolean True to return as "hidden" fields
* @param array Array of fields to ignore if first argument is true

 *
* @param boolean True to return as "hidden" fields
* @param array Array of fields to ignore if first argument is true

 
 * @param boolean True to skip all inputs and return only the file path part of the URL

 * @return string The current URL being accessed
*/

 * @return string The current URL being accessed
*/

function get_current_location($fields=false, $ignore=array())

function get_current_location($fields=false, $ignore=array(), $quick=false)

{
if(defined("MYBB_LOCATION"))
{
return MYBB_LOCATION;
}


{
if(defined("MYBB_LOCATION"))
{
return MYBB_LOCATION;
}


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

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

	{

	{

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

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





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

	}
else

	}
else

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






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

if($quick)
{
return $location;

	}

if($fields == true)

	}

if($fields == true)

Zeile 4591Zeile 4890
		if(!is_array($ignore))
{
$ignore = array($ignore);

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

		}

		}


$form_html = '';
if(!empty($mybb->input))


$form_html = '';
if(!empty($mybb->input))

Zeile 4604Zeile 4903
				}

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

		}

return array('location' => $location, 'form_html' => $form_html, 'form_method' => $mybb->request_method);

Zeile 4629Zeile 4928
				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(strpos($location, "?") === false)
{
$location .= "?";


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

				}

				}

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

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

		}

if(strlen($location) > 150)
{
$location = substr($location, 0, 150);

 
		}

return $location;

		}

return $location;

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

	if($charset == "utf-8")

	{

	{

		return $str;

		return $str;

	}

	}


if(!isset($use_iconv))
{


if(!isset($use_iconv))
{

Zeile 4845Zeile 5139
	}

if(!isset($use_mb))

	}

if(!isset($use_mb))

	{

	{

		$use_mb = function_exists("mb_convert_encoding");
}

if($use_iconv || $use_mb)
{
if($to)

		$use_mb = function_exists("mb_convert_encoding");
}

if($use_iconv || $use_mb)
{
if($to)

		{

		{

			$from_charset = $lang->settings['charset'];
$to_charset = "UTF-8";
}

			$from_charset = $lang->settings['charset'];
$to_charset = "UTF-8";
}

Zeile 4860Zeile 5154
		{
$from_charset = "UTF-8";
$to_charset = $lang->settings['charset'];

		{
$from_charset = "UTF-8";
$to_charset = $lang->settings['charset'];

		}

		}

		if($use_iconv)
{
return iconv($from_charset, $to_charset."//IGNORE", $str);

		if($use_iconv)
{
return iconv($from_charset, $to_charset."//IGNORE", $str);

Zeile 4888Zeile 5182
}

/**

}

/**

 * Replacement function for PHP's wordwrap(). This version does not break up HTML tags, URLs or unicode references.
*
* @param string The string to be word wrapped
* @return string The word wraped string

 * DEPRECATED! Please use other alternatives.




 */
function my_wordwrap($message)
{

 */
function my_wordwrap($message)
{

	global $mybb;

if($mybb->settings['wordwrap'] > 0)
{
$message = convert_through_utf8($message);

if(!($new_message = @preg_replace("#(((?>[^\s&/<>\"\\-\[\]])|(&\#[a-z0-9]{1,10};)){{$mybb->settings['wordwrap']}})#u", "$0&#8203;", $message)))
{
$new_message = preg_replace("#(((?>[^\s&/<>\"\\-\[\]])|(&\#[a-z0-9]{1,10};)){{$mybb->settings['wordwrap']}})#", "$0&#8203;", $message);
}

$new_message = convert_through_utf8($new_message, false);

return $new_message;
}


 
	return $message;
}


	return $message;
}


Zeile 4965Zeile 5240
		($in % 4 == 0 && ($in % 100 > 0 || $in % 400 == 0) ? 29 : 28),
31,
30,

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

		31,
30,
31,

		31,
30,
31,

		31,
30,
31,

		31,
30,
31,

Zeile 5322Zeile 5597
	else
{
$string = strtoupper($string);

	else
{
$string = strtoupper($string);

	}


	}


	return $string;
}


	return $string;
}


Zeile 5554Zeile 5829
	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 The event ID of the event

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

Zeile 5572Zeile 5847

/**
* Build the link to a specified date on the calendar


/**
* Build the link to a specified date on the calendar

 *
* @param int The ID of the calendar

 *
* @param int The ID of the calendar

 * @param int The year
* @param int The month
* @param int The day (optional)

 * @param int The year
* @param int The month
* @param int The day (optional)

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

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

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

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

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

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

Zeile 5642Zeile 5917
	if(!empty($mybb->user) && $uid == $mybb->user['uid'])
{
return $mybb->user;

	if(!empty($mybb->user) && $uid == $mybb->user['uid'])
{
return $mybb->user;

	}
elseif(isset($user_cache[$uid]))
{
return $user_cache[$uid];
}

	}
elseif(isset($user_cache[$uid]))
{
return $user_cache[$uid];
}

	elseif($uid > 0)
{
$query = $db->simple_select("users", "*", "uid = '{$uid}'");

	elseif($uid > 0)
{
$query = $db->simple_select("users", "*", "uid = '{$uid}'");

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

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

 
	}

switch($db->type)
{
case 'mysql':
case 'mysqli':
$field = 'username';
$efield = 'email';
break;
default:
$field = 'LOWER(username)';
$efield = 'LOWER(email)';
break;

	}

switch($options['username_method'])
{
case 1:

	}

switch($options['username_method'])
{
case 1:

			$sqlwhere = 'LOWER(email)=\''.$username.'\'';

			$sqlwhere = "{$efield}='{$username}'";

			break;
case 2:

			break;
case 2:

			$sqlwhere = 'LOWER(username)=\''.$username.'\' OR LOWER(email)=\''.$username.'\'';

			$sqlwhere = "{$field}='{$username}' OR {$efield}='{$username}'";

			break;
default:

			break;
default:

			$sqlwhere = 'LOWER(username)=\''.$username.'\'';

			$sqlwhere = "{$field}='{$username}'";

			break;
}


			break;
}


Zeile 5823Zeile 6111
 */
function get_inactive_forums()
{

 */
function get_inactive_forums()
{

	global $forum_cache, $cache, $inactiveforums;

	global $forum_cache, $cache;


if(!$forum_cache)


if(!$forum_cache)

	{

	{

		cache_forums();
}

		cache_forums();
}





	$inactive = array();

foreach($forum_cache as $fid => $forum)

	$inactive = array();

foreach($forum_cache as $fid => $forum)

	{

	{

		if($forum['active'] == 0)
{
$inactive[] = $fid;

		if($forum['active'] == 0)
{
$inactive[] = $fid;

Zeile 5843Zeile 6131
				{
$inactive[] = $fid1;
}

				{
$inactive[] = $fid1;
}

			}
}

			}
}

	}

	}

 
	

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

return $inactiveforums;

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

return $inactiveforums;

Zeile 5864Zeile 6153
	if($mybb->settings['failedlogincount'] == 0)
{
return 1;

	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.

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

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

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

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

	}

	}


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


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

Zeile 5896Zeile 6185
		else
{
$failedtime = $mybb->cookies['failedlogin'];

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

		}

		}


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


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

Zeile 5907Zeile 6196
		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
if($mybb->cookies['failedlogin'] < ($now - $mybb->settings['failedlogintime'] * 60))


// Work out if the user has waited long enough before letting them login again
if($mybb->cookies['failedlogin'] < ($now - $mybb->settings['failedlogintime'] * 60))

Zeile 6287Zeile 6576
		$ip_range = fetch_ip_range($banned_ip['filter']);
if(is_array($ip_range))
{

		$ip_range = fetch_ip_range($banned_ip['filter']);
if(is_array($ip_range))
{

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

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

			{
$banned = true;
}

			{
$banned = true;
}

Zeile 6402Zeile 6691

eval("\$select = \"".$templates->get("usercp_options_timezone")."\";");
return $select;


eval("\$select = \"".$templates->get("usercp_options_timezone")."\";");
return $select;

}


}


/**

/**

 * Fetch the contents of a remote fle.

 * Fetch the contents of a remote file.

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

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

Zeile 6424Zeile 6713
	}

if(function_exists("curl_init"))

	}

if(function_exists("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);

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

		if(!empty($post_body))

		if(!empty($post_body))

		{

		{

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

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

Zeile 6451Zeile 6741
			$url['port'] = 80;
}
if(!$url['path'])

			$url['port'] = 80;
}
if(!$url['path'])

		{

		{

			$url['path'] = "/";

			$url['path'] = "/";

		}

		}

		if($url['query'])

		if($url['query'])

		{

		{

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

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

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














$scheme = '';

if($url['scheme'] == 'https')
{
$scheme = 'ssl://';
if($url['port'] == 80)
{
$url['port'] = 443;
}
}

$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 6544Zeile 6846
 * Originates from frostschutz's PluginLibrary
* github.com/frostschutz
*

 * Originates from frostschutz's PluginLibrary
* github.com/frostschutz
*

 * @param mixed A selection of groups to check

 * @param mixed A selection of groups to check or -1 for any group

 * @param mixed User to check selection against

 * @param mixed User to check selection against

 * @return mixed Array of groups this user belongs to

 * @return array Array of groups specified in the first param to which the user belongs

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

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

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


if($user == false)


if($user == false)

	{

	{

		$user = $mybb->user;

		$user = $mybb->user;

	}

	}

	else if(!is_array($user))
{
// Assume it's a UID

	else if(!is_array($user))
{
// Assume it's a UID

Zeile 6567Zeile 6874

if(!is_array($groups))
{


if(!is_array($groups))
{

		if(is_string($groups))

		if((int)$groups == -1)

		{

		{

			$groups = explode(',', $groups);

			return $memberships;

		}
else
{

		}
else
{

			$groups = (array)$groups;








			if(is_string($groups))
{
$groups = explode(',', $groups);
}
else
{
$groups = (array)$groups;
}

		}
}


		}
}


Zeile 7012Zeile 7326
		else
{
// IPv4

		else
{
// IPv4

 
			$ip_bits = count(explode('.', $ipaddress));
if($ip_bits < 4)
{
// Support for 127.0.*
$replacement = str_repeat('.*', 4-$ip_bits);
$ipaddress = substr_replace($ipaddress, $replacement, strrpos($ipaddress, '*')+1, 0);
}

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

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

		}

		}

		$upper = my_inet_pton($upper);
$lower = my_inet_pton($lower);
if($upper === false || $lower === false)

		$upper = my_inet_pton($upper);
$lower = my_inet_pton($lower);
if($upper === false || $lower === false)

Zeile 7022Zeile 7343
			return false;
}
return array($lower, $upper);

			return false;
}
return array($lower, $upper);

	}

	}

	// CIDR notation
elseif(strpos($ipaddress, '/') !== false)
{

	// CIDR notation
elseif(strpos($ipaddress, '/') !== false)
{

Zeile 7034Zeile 7355
		{
// Invalid input
return false;

		{
// Invalid input
return false;

		}

		}

		else
{
$ip_address = my_inet_pton($ip_address);

		else
{
$ip_address = my_inet_pton($ip_address);

Zeile 7108Zeile 7429
function get_execution_time()
{
static $time_start;

function get_execution_time()
{
static $time_start;


$time = microtime(true);




$time = microtime(true);



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

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

Zeile 7369Zeile 7690
}

/**

}

/**

 * More robust version of PHP's trim() function. It includes a list of UTF-16 blank characters

 * 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 The string to trim from

 * from http://kb.mozillazine.org/Network.IDN.blacklist_chars
*
* @param string The string to trim from

Zeile 7379Zeile 7700
function trim_blank_chrs($string, $charlist=false)
{
$hex_chrs = array(

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

		0x20 => 1,
0x09 => 1,
0x0A => 1,
0x0D => 1,
0x0B => 1,
0xAD => 1,
0xA0 => 1,
0xAD => 1,
0xBF => 1,
0x81 => 1,
0x8D => 1,
0x90 => 1,
0x9D => 1,
0xCC => array(0xB7 => 1, 0xB8 => 1), // \x{0337} or \x{0338}
0xE1 => array(0x85 => array(0x9F => 1, 0xA0 => 1)), // \x{115F} or \x{1160}
0xE2 => array(0x80 => array(0x80 => 1, 0x81 => 1, 0x82 => 1, 0x83 => 1, 0x84 => 1, 0x85 => 1, 0x86 => 1, 0x87 => 1, 0x88 => 1, 0x89 => 1, 0x8A => 1, 0x8B => 1, // \x{2000} to \x{200B}
0xA8 => 1, 0xA9 => 1, 0xAA => 1, 0xAB => 1, 0xAC => 1, 0xAD => 1, 0xAE => 1, 0xAF => 1), // \x{2028} to \x{202F}
0x81 => array(0x9F => 1)), // \x{205F}

		0x09 => 1, // \x{0009}
0x0A => 1, // \x{000A}
0x0B => 1, // \x{000B}
0x0D => 1, // \x{000D}
0x20 => 1, // \x{0020}
0xC2 => array(0x81 => 1, 0x8D => 1, 0x90 => 1, 0x9D => 1, 0xA0 => 1, 0xAD => 1), // \x{0081}, \x{008D}, \x{0090}, \x{009D}, \x{00A0}, \x{00AD}
0xCC => array(0xB7 => 1, 0xB8 => 1), // \x{0337}, \x{0338}
0xE1 => array(0x85 => array(0x9F => 1, 0xA0 => 1), 0x9A => array(0x80 => 1), 0xA0 => array(0x8E => 1)), // \x{115F}, \x{1160}, \x{1680}, \x{180E}
0xE2 => array(0x80 => array(0x80 => 1, 0x81 => 1, 0x82 => 1, 0x83 => 1, 0x84 => 1, 0x85 => 1, 0x86 => 1, 0x87 => 1, 0x88 => 1, 0x89 => 1, 0x8A => 1, 0x8B => 1, 0x8C => 1, 0x8D => 1, 0x8E => 1, 0x8F => 1, // \x{2000} - \x{200F}
0xA8 => 1, 0xA9 => 1, 0xAA => 1, 0xAB => 1, 0xAC => 1, 0xAD => 1, 0xAE => 1, 0xAF => 1), // \x{2028} - \x{202F}
0x81 => array(0x9F => 1)), // \x{205F}








		0xE3 => array(0x80 => array(0x80 => 1), // \x{3000}

		0xE3 => array(0x80 => array(0x80 => 1), // \x{3000}

					  0x85 => array(0xA4 => 1)), // \x{3164}

			0x85 => array(0xA4 => 1)), // \x{3164}

		0xEF => array(0xBB => array(0xBF => 1), // \x{FEFF}

		0xEF => array(0xBB => array(0xBF => 1), // \x{FEFF}

					  0xBE => array(0xA0 => 1), // \x{FFA0}
0xBF => array(0xB9 => 1, 0xBA => 1, 0xBB => 1)), // \x{FFF9} to \x{FFFB}

			0xBE => array(0xA0 => 1), // \x{FFA0}
0xBF => array(0xB9 => 1, 0xBA => 1, 0xBB => 1)), // \x{FFF9} - \x{FFFB}

	);

$hex_chrs_rev = array(

	);

$hex_chrs_rev = array(

		0x20 => 1,
0x09 => 1,
0x0A => 1,
0x0D => 1,
0x0B => 1,
0xA0 => array(0xC2 => 1),
0xAD => array(0xC2 => 1),
0xBF => array(0xC2 => 1),
0x81 => array(0xC2 => 1),
0x8D => array(0xC2 => 1),
0x90 => array(0xC2 => 1),
0x9D => array(0xC2 => 1),

		0x09 => 1, // \x{0009}
0x0A => 1, // \x{000A}
0x0B => 1, // \x{000B}
0x0D => 1, // \x{000D}
0x20 => 1, // \x{0020}
0x81 => array(0xC2 => 1, 0x80 => array(0xE2 => 1)), // \x{0081}, \x{2001}
0x8D => array(0xC2 => 1, 0x80 => array(0xE2 => 1)), // \x{008D}, \x{200D}
0x90 => array(0xC2 => 1), // \x{0090}
0x9D => array(0xC2 => 1), // \x{009D}
0xA0 => array(0xC2 => 1, 0x85 => array(0xE1 => 1), 0x81 => array(0xE2 => 1), 0xBE => array(0xEF => 1)), // \x{00A0}, \x{1160}, \x{2060}, \x{FFA0}
0xAD => array(0xC2 => 1, 0x80 => array(0xE2 => 1)), // \x{00AD}, \x{202D}


		0xB8 => array(0xCC => 1), // \x{0338}
0xB7 => array(0xCC => 1), // \x{0337}

		0xB8 => array(0xCC => 1), // \x{0338}
0xB7 => array(0xCC => 1), // \x{0337}

		0xA0 => array(0x85 => array(0xE1 => 1)), // \x{1160}
0x9F => array(0x85 => array(0xE1 => 1), // \x{115F}
0x81 => array(0xE2 => 1)), // \x{205F}
0x80 => array(0x80 => array(0xE3 => 1, 0xE2 => 1)), // \x{3000}, \x{2000}
0x81 => array(0x80 => array(0xE2 => 1)), // \x{2001}

		0x9F => array(0x85 => array(0xE1 => 1), 0x81 => array(0xE2 => 1)), // \x{115F}, \x{205F}
0x80 => array(0x9A => array(0xE1 => 1), 0x80 => array(0xE2 => 1, 0xE3 => 1)), // \x{1680}, \x{2000}, \x{3000}
0x8E => array(0xA0 => array(0xE1 => 1), 0x80 => array(0xE2 => 1)), // \x{180E}, \x{200E}



		0x82 => array(0x80 => array(0xE2 => 1)), // \x{2002}
0x83 => array(0x80 => array(0xE2 => 1)), // \x{2003}
0x84 => array(0x80 => array(0xE2 => 1)), // \x{2004}

		0x82 => array(0x80 => array(0xE2 => 1)), // \x{2002}
0x83 => array(0x80 => array(0xE2 => 1)), // \x{2003}
0x84 => array(0x80 => array(0xE2 => 1)), // \x{2004}

Zeile 7434Zeile 7745
		0x89 => array(0x80 => array(0xE2 => 1)), // \x{2009}
0x8A => array(0x80 => array(0xE2 => 1)), // \x{200A}
0x8B => array(0x80 => array(0xE2 => 1)), // \x{200B}

		0x89 => array(0x80 => array(0xE2 => 1)), // \x{2009}
0x8A => array(0x80 => array(0xE2 => 1)), // \x{200A}
0x8B => array(0x80 => array(0xE2 => 1)), // \x{200B}

 
		0x8C => array(0x80 => array(0xE2 => 1)), // \x{200C}
0x8F => array(0x80 => array(0xE2 => 1)), // \x{200F}

		0xA8 => array(0x80 => array(0xE2 => 1)), // \x{2028}
0xA9 => array(0x80 => array(0xE2 => 1)), // \x{2029}
0xAA => array(0x80 => array(0xE2 => 1)), // \x{202A}
0xAB => array(0x80 => array(0xE2 => 1)), // \x{202B}
0xAC => array(0x80 => array(0xE2 => 1)), // \x{202C}

		0xA8 => array(0x80 => array(0xE2 => 1)), // \x{2028}
0xA9 => array(0x80 => array(0xE2 => 1)), // \x{2029}
0xAA => array(0x80 => array(0xE2 => 1)), // \x{202A}
0xAB => array(0x80 => array(0xE2 => 1)), // \x{202B}
0xAC => array(0x80 => array(0xE2 => 1)), // \x{202C}

		0xAD => array(0x80 => array(0xE2 => 1)), // \x{202D}

 
		0xAE => array(0x80 => array(0xE2 => 1)), // \x{202E}
0xAF => array(0x80 => array(0xE2 => 1)), // \x{202F}
0xA4 => array(0x85 => array(0xE3 => 1)), // \x{3164}
0xBF => array(0xBB => array(0xEF => 1)), // \x{FEFF}

		0xAE => array(0x80 => array(0xE2 => 1)), // \x{202E}
0xAF => array(0x80 => array(0xE2 => 1)), // \x{202F}
0xA4 => array(0x85 => array(0xE3 => 1)), // \x{3164}
0xBF => array(0xBB => array(0xEF => 1)), // \x{FEFF}

		0xA0 => array(0xBE => array(0xEF => 1)), // \x{FFA0}

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

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

	);


	);


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

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

		// Check to see if we have matched a first character in our utf-16 array

		// Check to see if we have matched a first character in our utf-8 array

		$offset = match_sequence($string, $hex_chrs);
if(!$offset)
{

		$offset = match_sequence($string, $hex_chrs);
if(!$offset)
{

Zeile 7468Zeile 7779
	$string = strrev($string);
do
{

	$string = strrev($string);
do
{

		// Check to see if we have matched a first character in our utf-16 array

		// Check to see if we have matched a first character in our utf-8 array

		$offset = match_sequence($string, $hex_chrs_rev);
if(!$offset)
{

		$offset = match_sequence($string, $hex_chrs_rev);
if(!$offset)
{

Zeile 7649Zeile 7960
				}
}
else

				}
}
else

			{

			{

				$string .= $input[$i];
}
}

				$string .= $input[$i];
}
}

Zeile 7658Zeile 7969
	if($return)
{
if($allow_mb4)

	if($return)
{
if($allow_mb4)

		{

		{

			return $input;

			return $input;

		}
else
{

		}
else
{

			return preg_replace("#[^\\x00-\\x7F][\\x80-\\xBF]{3,}#", '?', $input);
}
}

			return preg_replace("#[^\\x00-\\x7F][\\x80-\\xBF]{3,}#", '?', $input);
}
}

Zeile 7697Zeile 8008
	}

if(!is_array($pm))

	}

if(!is_array($pm))

	{
return false;
}

	{
return false;
}


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


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

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

$revert = true;

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

$revert = true;

		}


		}


		foreach(array('subject', 'message') as $key)
{
$lang_string = $pm[$key];

		foreach(array('subject', 'message') as $key)
{
$lang_string = $pm[$key];

Zeile 7736Zeile 8047
			$lang->set_language($mybb->user['language']);
$lang->load($pm['language_file']);
}

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

	}

	}


if(!$pm['subject'] ||!$pm['message'] || !$pm['touid'] || (!$pm['receivepms'] && !$admin_override))
{
return false;
}



if(!$pm['subject'] ||!$pm['message'] || !$pm['touid'] || (!$pm['receivepms'] && !$admin_override))
{
return false;
}


	$lang->load('messages');


	$lang->load('messages');


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

$pmhandler = new PMDataHandler();

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

$pmhandler = new PMDataHandler();





	$subject = $pm['subject'];
$message = $pm['message'];
$toid = $pm['touid'];

// Our recipients
if(is_array($toid))

	$subject = $pm['subject'];
$message = $pm['message'];
$toid = $pm['touid'];

// Our recipients
if(is_array($toid))

	{

	{

		$recipients_to = $toid;
}
else
{
$recipients_to = array($toid);

		$recipients_to = $toid;
}
else
{
$recipients_to = array($toid);

	}

	}


$recipients_bcc = array();

// Determine user ID
if((int)$fromid == 0)


$recipients_bcc = array();

// Determine user ID
if((int)$fromid == 0)

	{

	{

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

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

	}


	}


	// Build our final PM array
$pm = array(
"subject" => $subject,

	// Build our final PM array
$pm = array(
"subject" => $subject,

Zeile 7785Zeile 8096
		"bccid" => $recipients_bcc,
"do" => '',
"pmid" => ''

		"bccid" => $recipients_bcc,
"do" => '',
"pmid" => ''

	);


	);


	if(isset($session))
{
$pm['ipaddress'] = $session->packedip;

	if(isset($session))
{
$pm['ipaddress'] = $session->packedip;

Zeile 7797Zeile 8108
		"disablesmilies" => 0,
"savecopy" => 0,
"readreceipt" => 0

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

	);

$pm['saveasdraft'] = 0;

	);

$pm['saveasdraft'] = 0;


// Admin override
$pmhandler->admin_override = (int)$admin_override;


// Admin override
$pmhandler->admin_override = (int)$admin_override;





	$pmhandler->set_data($pm);

if($pmhandler->validate_pm())
{
$pmhandler->insert_pm();
return true;

	$pmhandler->set_data($pm);

if($pmhandler->validate_pm())
{
$pmhandler->insert_pm();
return true;

	}

	}


return false;
}


return false;
}

Zeile 7823Zeile 8134
 * @param string $ip_address The IP addres of the user.
* @param array $data An array of extra data to go with the block (eg: confidence rating).
* @return bool Whether the action was logged successfully.

 * @param string $ip_address The IP addres of the user.
* @param array $data An array of extra data to go with the block (eg: confidence rating).
* @return bool Whether the action was logged successfully.

 */

 */

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;

Zeile 7845Zeile 8156
		'email'     => $db->escape_string($email),
'ipaddress' => $db->escape_binary($ip_address),
'dateline' => (int)TIME_NOW,

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

		'data'      => $db->escape_string(@serialize($data)),

		'data'      => $db->escape_string(@my_serialize($data)),

	);

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

	);

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

 
}

/**
* Copy a file to the CDN.
*
* @param string $file_path The path to the file to upload to the CDN.
*
* @param string $uploaded_path The path the file was uploaded to, reference parameter for when this may be needed.
*
* @return bool Whether the file was copied successfully.
*/
function copy_file_to_cdn($file_path = '', &$uploaded_path = null)
{
global $mybb, $plugins;

$success = false;

$file_path = (string)$file_path;

$real_file_path = realpath($file_path);

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

$file_name = basename($real_file_path);

if(file_exists($file_path))
{
if($mybb->settings['usecdn'] && !empty($mybb->settings['cdnpath']))
{
$cdn_path = rtrim($mybb->settings['cdnpath'], '/\\');

if(substr($file_dir_path, 0, my_strlen(MYBB_ROOT)) == MYBB_ROOT)
{
$file_dir_path = str_replace(MYBB_ROOT, '', $file_dir_path);
}

$cdn_upload_path = $cdn_path . DIRECTORY_SEPARATOR . $file_dir_path;

if(!($dir_exists = is_dir($cdn_upload_path)))
{
$dir_exists = @mkdir($cdn_upload_path, 0777, true);
}

if($dir_exists)
{
if(($cdn_upload_path = realpath($cdn_upload_path)) !== false)
{
$success = @copy($file_path, $cdn_upload_path.DIRECTORY_SEPARATOR.$file_name);

if($success)
{
$uploaded_path = $cdn_upload_path;
}
}
}
}

if(is_object($plugins))
{
$hook_args = array(
'file_path' => &$file_path,
'real_file_path' => &$real_file_path,
'file_name' => &$file_name,
'uploaded_path' => &$uploaded_path,
'success' => &$success,
);

$plugins->run_hooks('copy_file_to_cdn_end', $hook_args);
}
}

return $success;

}

}