Vergleich inc/functions.php - 1.6.0 - 1.6.4

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 6
 * Website: http://mybb.com
* License: http://mybb.com/about/license
*

 * Website: http://mybb.com
* License: http://mybb.com/about/license
*

 * $Id: functions.php 5172 2010-08-02 23:13:03Z RyanGordon $

 * $Id: functions.php 5490 2011-07-12 13:39:55Z Tomm $

 */

/**

 */

/**

Zeile 197Zeile 197
	}

// And finally.. plugins

	}

// And finally.. plugins

	if(!is_object($plugins) && !defined("NO_PLUGINS"))

	if(!is_object($plugins) && !defined("NO_PLUGINS") && !($mybb->settings['no_plugins'] == 1))

	{
require_once MYBB_ROOT."inc/class_plugins.php";
$plugins = new pluginSystem;

	{
require_once MYBB_ROOT."inc/class_plugins.php";
$plugins = new pluginSystem;

Zeile 732Zeile 732
	);

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

	);

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

	$url = htmlspecialchars_uni("http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);

 

if($mybb->input['ajax'])
{


if($mybb->input['ajax'])
{

Zeile 958Zeile 957
 */
function fetch_page_url($url, $page)
{

 */
function fetch_page_url($url, $page)
{

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












	if($page <= 1)
{
$find = array(
"-page-{page}",
"&amp;page={page}",
"{page}"
);

// Remove "Page 1" to the defacto URL
$url = str_replace($find, array("", "", $page), $url);
return $url;
}
else if(strpos($url, "{page}") === false)

	{

	{

 
		// If no page identifier is specified we tack it on to the end of the URL

		if(strpos($url, "?") === false)

		if(strpos($url, "?") === false)

		{

		{

			$url .= "?";

			$url .= "?";

		}

		}

		else
{
$url .= "&amp;";
}

		else
{
$url .= "&amp;";
}

 


		$url .= "page=$page";
}
else
{
$url = str_replace("{page}", $page, $url);
}

		$url .= "page=$page";
}
else
{
$url = str_replace("{page}", $page, $url);
}

 


	return $url;

	return $url;

}

/**

}

/**

 * Fetch the permissions for a specific user
*
* @param int The user ID

 * Fetch the permissions for a specific user
*
* @param int The user ID

Zeile 987Zeile 1000
function user_permissions($uid=0)
{
global $mybb, $cache, $groupscache, $user_cache;

function user_permissions($uid=0)
{
global $mybb, $cache, $groupscache, $user_cache;





	// If no user id is specified, assume it is the current user
if($uid == 0)
{

	// If no user id is specified, assume it is the current user
if($uid == 0)
{

Zeile 996Zeile 1009

// User id does not match current user, fetch permissions
if($uid != $mybb->user['uid'])


// User id does not match current user, fetch permissions
if($uid != $mybb->user['uid'])

	{

	{

		// We've already cached permissions for this user, return them.
if($user_cache[$uid]['permissions'])
{

		// We've already cached permissions for this user, return them.
if($user_cache[$uid]['permissions'])
{

Zeile 1033Zeile 1046
function usergroup_permissions($gid=0)
{
global $cache, $groupscache, $grouppermignore, $groupzerogreater;

function usergroup_permissions($gid=0)
{
global $cache, $groupscache, $grouppermignore, $groupzerogreater;





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

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

Zeile 1069Zeile 1082

// 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 1096Zeile 1109
	global $cache, $groupscache, $displaygroupfields;

if(!is_array($groupscache))

	global $cache, $groupscache, $displaygroupfields;

if(!is_array($groupscache))

	{

	{

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

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

	}


	}


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

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





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

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

	}


	}


	return $displaygroup;
}


	return $displaygroup;
}


Zeile 1211Zeile 1224
	}

$current_permissions = array();

	}

$current_permissions = array();

 
	$only_view_own_threads = 1;

	
foreach($groups as $gid)
{

	
foreach($groups as $gid)
{

Zeile 1248Zeile 1262
				{
$current_permissions[$permission] = $access;
}

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

 
			}

if(!$level_permissions["canonlyviewownthreads"])
{
$only_view_own_threads = 0;

			}
}

			}
}

 
	}

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

	}

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

	}

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

	}

	}

	return $current_permissions;
}


	return $current_permissions;
}


Zeile 1358Zeile 1383
 */
function get_moderator_permissions($fid, $uid="0", $parentslist="")
{

 */
function get_moderator_permissions($fid, $uid="0", $parentslist="")
{

	global $mybb, $db;

	global $mybb, $cache, $db;

	static $modpermscache;

if($uid < 1)

	static $modpermscache;

if($uid < 1)

	{

	{

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

if($uid == 0)
{
return false;

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

if($uid == 0)
{
return false;

	}

if(!isset($modpermscache[$fid][$uid]))
{
if(!$parentslist)



















	}

if(isset($modpermscache[$fid][$uid]))
{
return $modpermscache[$fid][$uid];
}

if(!$parentslist)
{
$parentslist = explode(',', get_parent_list($fid));
}

// Get user groups
$perms = array();
$user = get_user($uid);

$groups = array($user['usergroup']);

if(!empty($user['additionalgroups']))
{
$extra_groups = explode(",", $user['additionalgroups']);

foreach($extra_groups as $extra_group)

		{

		{

			$parentslist = get_parent_list($fid);

			$groups[] = $extra_group;

		}

		}

		
// Get user groups
$query = $db->simple_select("users", "usergroup,additionalgroups", "uid='{$uid}'");
$usergroups = $db->fetch_array($query);
$groups = "'{$usergroups['usergroup']}'";
if(!empty($usergroups['additionalgroups']))


	}

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

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

		{

		{

			$groups .= ",'{$usergroups['additionalgroups']}'";


























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

// User settings override usergroup settings
if(is_array($forum['users'][$uid]))
{
$perm = $forum['users'][$uid];
foreach($perm as $action => $value)
{
if(strpos($action, "can") === false)
{
continue;
}

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

		}

		}

		
$query = $db->simple_select("moderators", "*", "((id IN ({$groups}) AND isgroup='1') OR (id='{$uid}' AND isgroup='0')) AND fid='$fid'");
while($results = $db->fetch_array($query))


foreach($groups as $group)


		{

		{

			$perms['caneditposts'] = max($perms['caneditposts'], $results['caneditposts']);
$perms['candeleteposts'] = max($perms['candeleteposts'], $results['candeleteposts']);
$perms['canviewips'] = max($perms['canviewips'], $results['canviewips']);
$perms['canopenclosethreads'] = max($perms['canopenclosethreads'], $results['canopenclosethreads']);
$perms['canmanagethreads'] = max($perms['canmanagethreads'], $results['canmanagethreads']);
$perms['canmovetononmodforum'] = max($perms['canmovetononmodforum'], $results['canmovetononmodforum']);











			if(!is_array($forum['usergroups'][$group]))
{
// There are no permissions set for this group
continue;
}

$perm = $forum['usergroups'][$group];
foreach($perm as $action => $value)
{
if(strpos($action, "can") === false)
{
continue;
}

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

		}

		}

		
$sql = build_parent_list($fid, "fid", "OR", $parentslist);
$query = $db->simple_select("moderators", "*", "((id IN ({$groups}) AND isgroup='1') OR (id='{$uid}' AND isgroup='0')) AND {$sql}");
$uperms = $db->fetch_array($query);

if(!$uperms && !$perms)
{
return false;
}

//Join the group permissions with the user permissions
$perms['caneditposts'] = max($perms['caneditposts'], $uperms['caneditposts']);
$perms['candeleteposts'] = max($perms['candeleteposts'], $uperms['candeleteposts']);
$perms['canviewips'] = max($perms['canviewips'], $uperms['canviewips']);
$perms['canopenclosethreads'] = max($perms['canopenclosethreads'], $uperms['canopenclosethreads']);
$perms['canmanagethreads'] = max($perms['canmanagethreads'], $uperms['canmanagethreads']);
$perms['canmovetononmodforum'] = max($perms['canmovetononmodforum'], $uperms['canmovetononmodforum']);

$modpermscache[$fid][$uid] = $perms;
}
else
{
$perms = $modpermscache[$fid][$uid];

 
	}

	}

 

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


return $perms;
}


return $perms;
}

Zeile 1463Zeile 1520
				{
if(isset($modusers['users'][$uid]) && $modusers['users'][$uid]['mid'])
{

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

 
						return true;
}
elseif(isset($modusers['usergroups'][$user_perms['gid']]))
{
// Moderating usergroup

						return true;
}
}

						return true;
}
}

Zeile 1519Zeile 1581
	
foreach($posticons as $dbicon)
{

	
foreach($posticons as $dbicon)
{

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


		if($icon == $dbicon['iid'])
{
$iconlist .= "<label><input type=\"radio\" name=\"icon\" value=\"".$dbicon['iid']."\" checked=\"checked\" /> <img src=\"".$dbicon['path']."\" alt=\"".$dbicon['name']."\" /></label>";

		if($icon == $dbicon['iid'])
{
$iconlist .= "<label><input type=\"radio\" name=\"icon\" value=\"".$dbicon['iid']."\" checked=\"checked\" /> <img src=\"".$dbicon['path']."\" alt=\"".$dbicon['name']."\" /></label>";

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

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

	}

	}


if($expires == -1)
{


if($expires == -1)
{

Zeile 1580Zeile 1645
	$cookie = "Set-Cookie: {$mybb->settings['cookieprefix']}{$name}=".urlencode($value);

if($expires > 0)

	$cookie = "Set-Cookie: {$mybb->settings['cookieprefix']}{$name}=".urlencode($value);

if($expires > 0)

	{

	{

		$cookie .= "; expires=".@gmdate('D, d-M-Y H:i:s \\G\\M\\T', $expires);
}


		$cookie .= "; expires=".@gmdate('D, d-M-Y H:i:s \\G\\M\\T', $expires);
}


Zeile 1637Zeile 1702

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



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


	if(isset($cookie[$id]))

	if(is_array($cookie) && isset($cookie[$id]))

	{
return $cookie[$id];
}
else
{
return 0;

	{
return $cookie[$id];
}
else
{
return 0;

	}
}


	}
}


/**
* Set a serialised cookie array.
*

/**
* Set a serialised cookie array.
*

Zeile 1660Zeile 1725
	
$cookie = $mybb->cookies['mybb'];
$newcookie = unserialize($cookie[$name]);

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

 

if(!is_array($newcookie))
{
// Burnt / malformed cookie - reset
$newcookie = array();
}


	$newcookie[$id] = $value;
$newcookie = serialize($newcookie);
my_setcookie("mybb[$name]", addslashes($newcookie));

	$newcookie[$id] = $value;
$newcookie = serialize($newcookie);
my_setcookie("mybb[$name]", addslashes($newcookie));

Zeile 1744Zeile 1816
function update_stats($changes=array())
{
global $cache, $db;

function update_stats($changes=array())
{
global $cache, $db;





	$stats = $cache->read("stats");

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

	$stats = $cache->read("stats");

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

Zeile 1841Zeile 1913
			}

// Less than 0? That's bad

			}

// Less than 0? That's bad

			if($update_query[$counter] < 0)

			if(!$update_query[$counter])

			{
$update_query[$counter] = 0;
}

			{
$update_query[$counter] = 0;
}

Zeile 2467Zeile 2539
	}

return $clickablesmilies;

	}

return $clickablesmilies;

 
}

/**
* Builds thread prefixes and returns a selected prefix (or all)
*
* @param int The prefix ID (0 to return all)
* @return array The thread prefix's values (or all thread prefixes)
*/
function build_prefixes($pid=0)
{
global $cache;
static $prefixes_cache;

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

return $prefixes_cache;
}

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

if($prefix_cache === false)
{
return false;
}

$prefixes_cache = array();
foreach($prefix_cache as $prefix)
{
$prefixes_cache[$prefix['pid']] = $prefix;
}

if($pid != 0 && is_array($prefixes_cache[$pid]))
{
return $prefixes_cache[$pid];
}
else if(!empty($prefixes_cache))
{
return $prefixes_cache;
}

return false;

}

/**

}

/**

Zeile 2478Zeile 2596
 */
function build_prefix_select($fid, $selected_pid=0, $multiple=0)
{

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

	global $db, $lang, $mybb;

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

	
if($fid != 'all')
{
$fid = intval($fid);
}


	
if($fid != 'all')
{
$fid = intval($fid);
}


	// Does this user have additional groups?







	$prefix_cache = build_prefixes(0);
if(!$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']);


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


		// Because we like apostrophes...
$imps = array();

 
		foreach($exp as $group)

		foreach($exp as $group)

		{
$imps[] = "'{$group}'";
}

$additional_groups = implode(",", $imps);
$extra_sql = "groups IN ({$additional_groups}) OR ";
}
else
{
$extra_sql = '';
}

switch($db->type)
{
case "pgsql":
case "sqlite":
$whereforum = "";
if($fid != 'all')
{
$whereforum = " AND (','||forums||',' LIKE '%,{$fid},%' OR ','||forums||',' LIKE '%,-1,%' OR forums='')";
}

$query = $db->query("
SELECT pid, prefix
FROM ".TABLE_PREFIX."threadprefixes
WHERE ({$extra_sql}','||groups||',' LIKE '%,{$mybb->user['usergroup']},%' OR ','||groups||',' LIKE '%,-1,%' OR groups='')
{$whereforum}
");
break;
default:
$whereforum = "";
if($fid != 'all')
{
$whereforum = " AND (CONCAT(',',forums,',') LIKE '%,{$fid},%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='')";
}

$query = $db->query("
SELECT pid, prefix
FROM ".TABLE_PREFIX."threadprefixes
WHERE ({$extra_sql}CONCAT(',',groups,',') LIKE '%,{$mybb->user['usergroup']},%' OR CONCAT(',',groups,',') LIKE '%,-1,%' OR groups='')
{$whereforum}
");
}




		{
$groups[] = $group;
}
}

// 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(!in_array($fid, $forums))
{
// 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
{
// This prefix is for anybody to use...
$prefixes[$prefix['pid']] = $prefix;
}
}

if(empty($prefixes))
{
return false;
}


	$prefixselect = "";

	$prefixselect = "";

	
if($db->num_rows($query) > 0)



























	$multipleselect = "";
if($multiple != 0)
{
$multipleselect = " multiple=\"multiple\" size=\"5\"";
}

$prefixselect = "<select name=\"threadprefix\"{$multipleselect}>\n";

if($multiple == 1)
{
$any_selected = "";
if($selected_pid == 'any')
{
$any_selected = " selected=\"selected\"";
}

$prefixselect .= "<option value=\"any\"".$any_selected.">".$lang->any_prefix."</option>\n";
}

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

$prefixselect .= "<option value=\"0\"".$default_selected.">".$lang->no_prefix."</option>\n";

foreach($prefixes as $prefix)

	{

	{

		$multipleselect = "";
if($multiple != 0)

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

		{

		{

			$multipleselect = " multiple=\"multiple\" size=\"5\"";
}

$prefixselect = "<select name=\"threadprefix\"{$multipleselect}>\n";

if($multiple == 1)
{
$any_selected = "";
if($selected_pid == 'any')
{
$any_selected = " selected=\"selected\"";
}

$prefixselect .= "<option value=\"any\"".$any_selected.">".$lang->any_prefix."</option>\n";
}

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

			$selected = " selected=\"selected\"";




















		}

		}

		
$prefixselect .= "<option value=\"0\"".$default_selected.">".$lang->no_prefix."</option>\n";

while($prefix = $db->fetch_array($query))
{
$selected = "";
if($prefix['pid'] == $selected_pid)
{
$selected = " selected=\"selected\"";
}

$prefixselect .= "<option value=\"".$prefix['pid']."\"".$selected.">".htmlspecialchars_uni($prefix['prefix'])."</option>\n";
}

$prefixselect .= "</select>\n&nbsp;";


$prefixselect .= "<option value=\"".$prefix['pid']."\"".$selected.">".htmlspecialchars_uni($prefix['prefix'])."</option>\n";














	}

	}

	




$prefixselect .= "</select>\n&nbsp;";


	return $prefixselect;
}


	return $prefixselect;
}


Zeile 2702Zeile 2822
	if($uid != 0)
{
$display_reputation = "<a href=\"reputation.php?uid={$uid}\">";

	if($uid != 0)
{
$display_reputation = "<a href=\"reputation.php?uid={$uid}\">";

	}


	}


	$display_reputation .= "<strong class=\"";

if($reputation < 0)

	$display_reputation .= "<strong class=\"";

if($reputation < 0)

	{

	{

		$display_reputation .= "reputation_negative";
}
elseif($reputation > 0)

		$display_reputation .= "reputation_negative";
}
elseif($reputation > 0)

	{

	{

		$display_reputation .= "reputation_positive";
}
else
{
$display_reputation .= "reputation_neutral";

		$display_reputation .= "reputation_positive";
}
else
{
$display_reputation .= "reputation_neutral";

	}

$display_reputation .= "\">{$reputation}</strong>";


	}

$display_reputation .= "\">{$reputation}</strong>";


	if($uid != 0)
{
$display_reputation .= "</a>";
}

	if($uid != 0)
{
$display_reputation .= "</a>";
}





	return $display_reputation;
}


	return $display_reputation;
}


Zeile 2738Zeile 2858
function get_colored_warning_level($level)
{
if($level >= 80)

function get_colored_warning_level($level)
{
if($level >= 80)

	{

	{

		return "<span class=\"high_warning\">{$level}%</span>";
}
else if($level >= 50)

		return "<span class=\"high_warning\">{$level}%</span>";
}
else if($level >= 50)

Zeile 2748Zeile 2868
	else if($level >= 25)
{
return "<span class=\"low_warning\">{$level}%</span>";

	else if($level >= 25)
{
return "<span class=\"low_warning\">{$level}%</span>";

	}

	}

	else
{
return $level."%";

	else
{
return $level."%";

Zeile 2762Zeile 2882
 */
function get_ip()
{

 */
function get_ip()
{

	if(isset($_SERVER['REMOTE_ADDR']))
{
$ip = $_SERVER['REMOTE_ADDR'];
}
elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
if(preg_match_all("#[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#s", $_SERVER['HTTP_X_FORWARDED_FOR'], $addresses))















    global $mybb, $plugins;

$ip = 0;

if(!preg_match("#^(10|172\.16|192\.168)\.#", $_SERVER['REMOTE_ADDR']))
{
$ip = $_SERVER['REMOTE_ADDR'];
}

if($mybb->settings['ip_forwarded_check'])
{
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
preg_match_all("#[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#s", $_SERVER['HTTP_X_FORWARDED_FOR'], $addresses);
}
elseif(isset($_SERVER['HTTP_X_REAL_IP']))
{
preg_match_all("#[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#s", $_SERVER['HTTP_X_REAL_IP'], $addresses);
}

if(is_array($addresses[0]))

		{
foreach($addresses[0] as $key => $val)
{

		{
foreach($addresses[0] as $key => $val)
{

Zeile 2779Zeile 2913
				}
}
}

				}
}
}

	}

if(!isset($ip))
{
if(isset($_SERVER['HTTP_CLIENT_IP']))
{
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
else
{
$ip = '';
}
}

$ip = preg_replace("#([^.0-9 ]*)#", "", $ip);
return $ip;
}

    }

if(!$ip)
{
if(isset($_SERVER['HTTP_CLIENT_IP']))
{
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
}

if($plugins)
{
$plugins->run_hooks("get_ip", array("ip" => &$ip));
}

return $ip;
}


/**
* Fetch the friendly size (GB, MB, KB, B) for a specified file size.


/**
* Fetch the friendly size (GB, MB, KB, B) for a specified file size.

Zeile 2808Zeile 2942
	global $lang;

if(!is_numeric($size))

	global $lang;

if(!is_numeric($size))

	{

	{

		return $lang->na;
}


		return $lang->na;
}


Zeile 2821Zeile 2955
	elseif($size >= 1180591620717411303424)
{
$size = my_number_format(round(($size / 1180591620717411303424), 2))." ".$lang->size_zb;

	elseif($size >= 1180591620717411303424)
{
$size = my_number_format(round(($size / 1180591620717411303424), 2))." ".$lang->size_zb;

	}

	}

	// Exabyte (1024 Petabytes)
elseif($size >= 1152921504606846976)

	// Exabyte (1024 Petabytes)
elseif($size >= 1152921504606846976)

	{

	{

		$size = my_number_format(round(($size / 1152921504606846976), 2))." ".$lang->size_eb;

		$size = my_number_format(round(($size / 1152921504606846976), 2))." ".$lang->size_eb;

	}

	}

	// Petabyte (1024 Terabytes)
elseif($size >= 1125899906842624)
{

	// Petabyte (1024 Terabytes)
elseif($size >= 1125899906842624)
{

Zeile 2839Zeile 2973
	}
// 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)
elseif($size >= 1048576)

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

	{

	{

		$size = my_number_format(round(($size / 1048576), 2))." ".$lang->size_mb;

		$size = my_number_format(round(($size / 1048576), 2))." ".$lang->size_mb;

	}

	}

	// Kilobyte (1024 bytes)
elseif($size >= 1024)
{

	// Kilobyte (1024 bytes)
elseif($size >= 1024)
{

Zeile 2855Zeile 2989
	elseif($size == 0)
{
$size = "0 ".$lang->size_bytes;

	elseif($size == 0)
{
$size = "0 ".$lang->size_bytes;

	}
else
{

	}
else
{

		$size = my_number_format($size)." ".$lang->size_bytes;
}


		$size = my_number_format($size)." ".$lang->size_bytes;
}


Zeile 2892Zeile 3026
			}
}
elseif(defined("IN_PORTAL"))

			}
}
elseif(defined("IN_PORTAL"))

		{

		{

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

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

Zeile 2927Zeile 3061
function get_unviewable_forums($only_readable_threads=false)
{
global $forum_cache, $permissioncache, $mybb, $unviewableforums, $unviewable, $templates, $forumpass;

function get_unviewable_forums($only_readable_threads=false)
{
global $forum_cache, $permissioncache, $mybb, $unviewableforums, $unviewable, $templates, $forumpass;





	$pid = intval($pid);

if(!$permissions)

	$pid = intval($pid);

if(!$permissions)

Zeile 2945Zeile 3079
		$permissioncache = forum_permissions();
}


		$permissioncache = forum_permissions();
}


 
	$password_forums = array();

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

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

Zeile 2963Zeile 3098
			if($mybb->cookies['forumpass'][$forum['fid']] != md5($mybb->user['uid'].$forum['password']))
{
$pwverified = 0;

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

 
			}

$password_forums[$forum['fid']] = $forum['password'];
}
else
{
// 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]))
{
$pwverified = 0;
}

			}
}


			}
}


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

$navbits[$navsize]['multipage'] = $multipage;

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

$navbits[$navsize]['multipage'] = $multipage;

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

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

				}
else
{

				}
else
{

Zeile 3328Zeile 3477
{
global $mybb;


{
global $mybb;


	if($mybb->settings['nocacheheaders'] == 1 && $mybb->settings['standardheaders'] != 1)

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

	{
header("Expires: Sat, 1 Jan 2000 01:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");

	{
header("Expires: Sat, 1 Jan 2000 01:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");

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

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

	







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


		return $location;
}
}

		return $location;
}
}

Zeile 3814Zeile 3968
						$is_allowed = true;
break;
}

						$is_allowed = true;
break;
}

				}
}

				}
}


// Show theme if allowed, or if override is on
if($is_allowed || $theme['allowedgroups'] == "all" || $usergroup_override == true)
{
if($theme['tid'] == $selected)


// Show theme if allowed, or if override is on
if($is_allowed || $theme['allowedgroups'] == "all" || $usergroup_override == true)
{
if($theme['tid'] == $selected)

				{

				{

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


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


Zeile 3829Zeile 3983
				{
$themeselect .= "<option value=\"".$theme['tid']."\"$sel>".$depth.$theme['name']."</option>";
$depthit = $depth."--";

				{
$themeselect .= "<option value=\"".$theme['tid']."\"$sel>".$depth.$theme['name']."</option>";
$depthit = $depth."--";

				}

				}


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


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

Zeile 3837Zeile 3991
				}
}
}

				}
}
}

	}

	}


if($tid == 1)
{


if($tid == 1)
{

Zeile 3845Zeile 3999
	}

return $themeselect;

	}

return $themeselect;

}

/**

}

/**

 * Custom function for htmlspecialchars which takes in to account unicode
*
* @param string The string to format

 * Custom function for htmlspecialchars which takes in to account unicode
*
* @param string The string to format

Zeile 3871Zeile 4025
function my_number_format($number)
{
global $mybb;

function my_number_format($number)
{
global $mybb;





	if($number == "-")
{
return $number;
}

if(is_int($number))

	if($number == "-")
{
return $number;
}

if(is_int($number))

	{

	{

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

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

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

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

		}
else
{

		}
else
{

			return @mb_convert_encoding($str, $to_charset, $from_charset);
}
}

			return @mb_convert_encoding($str, $to_charset, $from_charset);
}
}

Zeile 3962Zeile 4116
		return $str;
}
}

		return $str;
}
}





/**
* Replacement function for PHP's wordwrap(). This version does not break up HTML tags, URLs or unicode references.
*

/**
* Replacement function for PHP's wordwrap(). This version does not break up HTML tags, URLs or unicode references.
*

Zeile 3974Zeile 4128
	global $mybb;

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

	global $mybb;

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

	{

	{

		$message = convert_through_utf8($message);


		$message = convert_through_utf8($message);


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

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

		{

		{

			$new_message = preg_replace("#(?>[^\s&/<>\"\\-\.\[\]]{{$mybb->settings['wordwrap']}})#", "$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);

		}

$new_message = convert_through_utf8($new_message, false);

Zeile 4007Zeile 4161
		$j = get_bdays($i);

for($k = 11; $k >= 0; $k--)

		$j = get_bdays($i);

for($k = 11; $k >= 0; $k--)

		{

		{

			$l = ($k + 1);

for($m = $j[$k]; $m >= 1; $m--)

			$l = ($k + 1);

for($m = $j[$k]; $m >= 1; $m--)

Zeile 4074Zeile 4228
		$lang->thursday,
$lang->friday,
$lang->saturday

		$lang->thursday,
$lang->friday,
$lang->saturday

	);


	);


	$bmonth = array(
$lang->month_1,
$lang->month_2,

	$bmonth = array(
$lang->month_1,
$lang->month_2,

Zeile 4101Zeile 4255
		'Y',
'j',
'S',

		'Y',
'j',
'S',

		'l',

 
		'F',

		'F',

 
		'l',

		'M',
);


		'M',
);


 
	$html = array(
'&#109;',
'&#99;',
'&#68;',
'&#121;',
'&#89;',
'&#106;',
'&#83;',
'&#70;',
'&#108;',
'&#77;',
);

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


	$replace = array(
sprintf('%02s', $bm),
sprintf('%02s', $bd),

	$replace = array(
sprintf('%02s', $bm),
sprintf('%02s', $bd),

Zeile 4114Zeile 4284
		$by,
($bd[0] == 0 ? my_substr($bd, 1) : $bd),
($bd == 1 || $bd == 21 || $bd == 31 ? 'st' : ($bd == 2 || $bd == 22 ? 'nd' : ($bd == 3 || $bd == 23 ? 'rd' : 'th'))),

		$by,
($bd[0] == 0 ? my_substr($bd, 1) : $bd),
($bd == 1 || $bd == 21 || $bd == 31 ? 'st' : ($bd == 2 || $bd == 22 ? 'nd' : ($bd == 3 || $bd == 23 ? 'rd' : 'th'))),

		$wd,

 
		$bmonth[$bm-1],

		$bmonth[$bm-1],

 
		$wd,

		($bm == 9 ? my_substr($bmonth[$bm-1], 0, 4) :  my_substr($bmonth[$bm-1], 0, 3)),
);


		($bm == 9 ? my_substr($bmonth[$bm-1], 0, 4) :  my_substr($bmonth[$bm-1], 0, 3)),
);


Zeile 4655Zeile 4825
		return $user_cache[$uid];
}
}

		return $user_cache[$uid];
}
}



 

/**
* Get the forum of a specific forum id.


/**
* Get the forum of a specific forum id.

Zeile 4665Zeile 4834
 * @return array The database row of a forum.
*/
function get_forum($fid, $active_override=0)

 * @return array The database row of a forum.
*/
function get_forum($fid, $active_override=0)

{

{

	global $cache;
static $forum_cache;

	global $cache;
static $forum_cache;





	if(!isset($forum_cache) || is_array($forum_cache))
{
$forum_cache = $cache->read("forums");

	if(!isset($forum_cache) || is_array($forum_cache))
{
$forum_cache = $cache->read("forums");

	}


	}


	if(!$forum_cache[$fid])
{
return false;

	if(!$forum_cache[$fid])
{
return false;

Zeile 4722Zeile 4891
		{
$thread_cache[$tid] = $thread;
return $thread;

		{
$thread_cache[$tid] = $thread;
return $thread;

		}

		}

		else
{
$thread_cache[$tid] = false;

		else
{
$thread_cache[$tid] = false;

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

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

		}


		}


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

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

Zeile 4935Zeile 5104
	{
$uid_string = " AND uid != '".intval($uid)."'";
}

	{
$uid_string = " AND uid != '".intval($uid)."'";
}

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

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

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

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

Zeile 4989Zeile 5158
	@fclose($file);

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

	@fclose($file);

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

}


}


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

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

Zeile 5056Zeile 5225
		$terms = htmlspecialchars_uni($terms);
$split_words = preg_split("#\s{1,}#", $terms, -1);
if(!is_array($split_words))

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

		{

		{

			continue;
}
foreach($split_words as $word)

			continue;
}
foreach($split_words as $word)

Zeile 5102Zeile 5271
}

/**

}

/**

 * Converts a decimal reference of a character to its UTF-8 equivilant

 * Converts a decimal reference of a character to its UTF-8 equivalent

 * (Code by Anne van Kesteren, http://annevankesteren.nl/2005/05/character-references)
*
* @param string Decimal value of a character reference

 * (Code by Anne van Kesteren, http://annevankesteren.nl/2005/05/character-references)
*
* @param string Decimal value of a character reference

Zeile 5184Zeile 5353
 */
function is_banned_email($email, $update_lastuse=false)
{

 */
function is_banned_email($email, $update_lastuse=false)
{

	global $db;
$query = $db->simple_select("banfilters", "*", "type='3'");
while($banned_email = $db->fetch_array($query))









	global $cache, $db;

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

if(!$banned_cache)
{
$cache->update_bannedemails();
$banned_cache = $cache->read("bannedemails");
}

foreach($banned_cache as $banned_email)

	{
// Make regular expression * match
$banned_email['filter'] = str_replace('\*', '(.*)', preg_quote($banned_email['filter'], '#'));

	{
// Make regular expression * match
$banned_email['filter'] = str_replace('\*', '(.*)', preg_quote($banned_email['filter'], '#'));

 


		if(preg_match("#{$banned_email['filter']}#i", $email))

		if(preg_match("#{$banned_email['filter']}#i", $email))

		{
// Updating last use

		{
// Updating last use

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

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

Zeile 5334Zeile 5512
 * @return string The remote file contents.
*/
function fetch_remote_file($url, $post_data=array())

 * @return string The remote file contents.
*/
function fetch_remote_file($url, $post_data=array())

{

{

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

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

Zeile 5369Zeile 5547
			return false;
}
if(!$url['port'])

			return false;
}
if(!$url['port'])

		{

		{

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

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

Zeile 5387Zeile 5565
			return false;
}
$headers = array();

			return false;
}
$headers = array();

		if(!empty($post_body))

		if(!empty($post_body))

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

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

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

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

		}


		}


		$headers[] = "Host: {$url['host']}";
$headers[] = "Connection: Close";
$headers[] = "\r\n";

		$headers[] = "Host: {$url['host']}";
$headers[] = "Connection: Close";
$headers[] = "\r\n";

		

		

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

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

		}


		}


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

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

Zeile 5516Zeile 5694
 * Fetch an IPv4 long formatted range for searching IPv4 IP addresses.
*
* @param string The IP address to convert to a range based LONG

 * Fetch an IPv4 long formatted range for searching IPv4 IP addresses.
*
* @param string The IP address to convert to a range based LONG

 * @rturn mixed If a full IP address is provided, the ip2long equivilent, otherwise an array of the upper & lower extremities of the IP

 * @rturn mixed If a full IP address is provided, the ip2long equivalent, otherwise an array of the upper & lower extremities of the IP

 */
function fetch_longipv4_range($ip)
{

 */
function fetch_longipv4_range($ip)
{

Zeile 5550Zeile 5728
			{
$ip_string1 .= $sep."0";
$ip_string2 .= $sep."255";

			{
$ip_string1 .= $sep."0";
$ip_string2 .= $sep."255";

			}

			}

			else
{
$ip_string1 .= $sep.$piece;

			else
{
$ip_string1 .= $sep.$piece;

Zeile 5622Zeile 5800

/**
* Expire old warnings in the database.


/**
* Expire old warnings in the database.

 *

 *

 */
function expire_warnings()
{

 */
function expire_warnings()
{

Zeile 5640Zeile 5818
	{
$updated_warning = array(
"expired" => 1

	{
$updated_warning = array(
"expired" => 1

		);

		);

		$db->update_query("warnings", $updated_warning, "wid='{$warning['wid']}'");

if(array_key_exists($warning['uid'], $users))

		$db->update_query("warnings", $updated_warning, "wid='{$warning['wid']}'");

if(array_key_exists($warning['uid'], $users))

Zeile 5664Zeile 5842
			"warningpoints" => intval($warningpoints)
);
$db->update_query("users", $updated_user, "uid='".intval($uid)."'");

			"warningpoints" => intval($warningpoints)
);
$db->update_query("users", $updated_user, "uid='".intval($uid)."'");

	}
}

/**
* Unicode function for php function chr()
*
* @param string The character
* @return mixed The unicoded chr()
*/
function unicode_chr($c)
{
if($c <= 0x7F)
{
return chr($c);
}
elseif($c <= 0x7FF)
{
return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
}
elseif($c <= 0xFFFF)
{
return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);
}
elseif($c <= 0x10FFFF)
{
return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
. chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);
}
else
{
return false;
}
}

/**

	}
}

/**


































 * Custom chmod function to fix problems with hosts who's server configurations screw up umasks
*
* @param string The file to chmod

 * Custom chmod function to fix problems with hosts who's server configurations screw up umasks
*
* @param string The file to chmod

Zeile 5727Zeile 5872
 *
* @param string The path to the directory
* @param array Any files you wish to ignore (optional)

 *
* @param string The path to the directory
* @param array Any files you wish to ignore (optional)

 */

 */

function my_rmdir_recursive($path, $ignore=array())
{
global $orig_dir;

function my_rmdir_recursive($path, $ignore=array())
{
global $orig_dir;

Zeile 5750Zeile 5895
            }
@closedir($dh);
}

            }
@closedir($dh);
}

		

		

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

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

Zeile 5789Zeile 5934
 */
function my_ip2long($ip)
{

 */
function my_ip2long($ip)
{

	$ip = ip2long($ip);
if($ip >= 2147483648) // Won't occur on 32-bit PHP












	$ip_long = ip2long($ip);

if(!$ip_long)
{
$ip_long = sprintf("%u", ip2long($ip));

if(!$ip_long)
{
return 0;
}
}

if($ip_long >= 2147483648) // Won't occur on 32-bit PHP

	{

	{

		$ip -= 4294967296;

		$ip_long -= 4294967296;

	}

	}

	return $ip;



return $ip_long;

}

/**

}

/**

Zeile 5914Zeile 6071
 * Returns a signed value equal to an integer
*
* @param int The integer

 * Returns a signed value equal to an integer
*
* @param int The integer

 * @return string The signed equivallent

 * @return string The signed equivalent

 */
function signed($int)
{

 */
function signed($int)
{

Zeile 5932Zeile 6089
 * Returns a securely generated seed for PHP's RNG (Random Number Generator)
*
* @param int Length of the seed bytes (8 is default. Provides good cryptographic variance)

 * Returns a securely generated seed for PHP's RNG (Random Number Generator)
*
* @param int Length of the seed bytes (8 is default. Provides good cryptographic variance)

 * @return int An integer equivilent of a secure hexadecimal seed

 * @return int An integer equivalent of a secure hexadecimal seed

 */
function secure_seed_rng($count=8)
{

 */
function secure_seed_rng($count=8)
{

Zeile 5972Zeile 6129
 * @param int Optional lowest value to be returned (default: 0) 
* @param int Optional highest value to be returned (default: mt_getrandmax())
* @param boolean True forces it to reseed the RNG first

 * @param int Optional lowest value to be returned (default: 0) 
* @param int Optional highest value to be returned (default: mt_getrandmax())
* @param boolean True forces it to reseed the RNG first

 * @return int An integer equivilent of a secure hexadecimal seed

 * @return int An integer equivalent of a secure hexadecimal seed

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

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