Vergleich inc/functions.php - 1.2.2 - 1.2.5

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 6
 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/eula.html
*

 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/eula.html
*

 * $Id: functions.php 2459 2006-11-29 09:09:55Z chris $

 * $Id: functions.php 2794 2007-02-14 02:37:17Z chris $

 */

/**

 */

/**

Zeile 425Zeile 425

/**
* Load the forum cache in to memory


/**
* Load the forum cache in to memory

 
 *
* @param boolean True to force a reload of the cache

 */

 */

function cache_forums()

function cache_forums($force=false)

{
global $forum_cache, $db, $cache;

{
global $forum_cache, $db, $cache;

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


if(!$forum_cache)
{


if(!$forum_cache)
{

Zeile 509Zeile 517
		"location2" => 0
);
$db->update_query(TABLE_PREFIX."sessions", $noperm_array, "sid='".$session->sid."'");

		"location2" => 0
);
$db->update_query(TABLE_PREFIX."sessions", $noperm_array, "sid='".$session->sid."'");

	$url = $_SERVER['REQUEST_URI'];
$url = str_replace("&", "&", $url);

	$url = htmlspecialchars_uni($_SERVER['REQUEST_URI']);


	if($mybb->user['uid'])
{
$lang->error_nopermission_user_5 = sprintf($lang->error_nopermission_user_5, $mybb->user['username']);

	if($mybb->user['uid'])
{
$lang->error_nopermission_user_5 = sprintf($lang->error_nopermission_user_5, $mybb->user['username']);

Zeile 824Zeile 831
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);

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

 


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

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

	// The fix here for better working inheritance was provided by tinywizard - http://windizupdate.com/
// Many thanks.
foreach($fpermfields as $perm)
{
$forumpermissions[$perm] = "no";
}


	
$current_permissions = array();






	foreach($groups as $gid)
{

	foreach($groups as $gid)
{

		if($gid && $groupscache[$gid])

		if($groupscache[$gid])

		{

		{

			if(is_array($fpermcache[$fid][$gid]))


			// If this forum has permissions set
if($fpermcache[$fid][$gid])

			{

			{

				$p = $fpermcache[$fid][$gid];
}
else
{
$p = $groupperms;
}

if($p == NULL)
{
foreach($forumpermissions as $k => $v)
{
$forumpermissions[$k] = 'yes'; // no inherited group, assume one has access
}
}
else
{
foreach($p as $perm => $access)

				$level_permissions = $fpermcache[$fid][$gid];
foreach($level_permissions as $permission => $access)
















				{

				{

					if(isset($forumpermissions[$perm]) && $access == 'yes')

					if($access >= $current_permissions[$permission] || ($access == "yes" && $current_permissions[$permission] == "no") || !$current_permissions[$permission])

					{

					{

						$forumpermissions[$perm] = $access;

						$current_permissions[$permission] = $access;

					}
}
}
}
}

					}
}
}
}
}

	return $forumpermissions;






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

}

/**

}

/**

Zeile 915Zeile 911
	}
if($showform)
{

	}
if($showform)
{

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

		eval("\$pwform = \"".$templates->get("forumdisplay_password")."\";");
output_page($pwform);
exit;

		eval("\$pwform = \"".$templates->get("forumdisplay_password")."\";");
output_page($pwform);
exit;

Zeile 1626Zeile 1623
 */
function build_clickable_smilies()
{

 */
function build_clickable_smilies()
{

	global $db, $smiliecache, $theme, $templates, $lang, $mybb;

	global $db, $smiliecache, $theme, $templates, $lang, $mybb, $smiliecount;


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


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

		$smiliecount = 0;






		if(!$smiliecount)
{
$query = $db->simple_select(TABLE_PREFIX."smilies", "COUNT(*) as smilies");
$smiliecount = $db->fetch_field($query, "smilies");
}


		if(!$smiliecache)
{

		if(!$smiliecache)
{

			$query = $db->query("
SELECT *
FROM ".TABLE_PREFIX."smilies
WHERE showclickable != 'no'
ORDER BY disporder
");

			$query = $db->simple_select(TABLE_PREFIX."smilies", "*", "showclickable != 'no'", array('order_by' => 'disporder'));







while($smilie = $db->fetch_array($query))
{
$smiliecache[$smilie['find']] = $smilie['image'];


while($smilie = $db->fetch_array($query))
{
$smiliecache[$smilie['find']] = $smilie['image'];

				$smiliecount++;

 
			}
}
unset($smilie);

			}
}
unset($smilie);

Zeile 1670Zeile 1666
					{
$smilies .= "<tr>\n";
}

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

					$find = $db->escape_string(htmlspecialchars($find));

					$find = htmlspecialchars_uni($find);

					$smilies .= "<td><img src=\"{$image}\" border=\"0\" class=\"smilie\" alt=\"{$find}\" /></td>\n";
$i++;
$counter++;

					$smilies .= "<td><img src=\"{$image}\" border=\"0\" class=\"smilie\" alt=\"{$find}\" /></td>\n";
$i++;
$counter++;

Zeile 1769Zeile 1765
	if($data['tid'] == '')
{
$tid = 0;

	if($data['tid'] == '')
{
$tid = 0;

	}

	}

	else
{
$tid = $data['tid'];

	else
{
$tid = $data['tid'];

Zeile 1791Zeile 1787
		"tid" => $tid,
"action" => $db->escape_string($action),
"data" => $db->escape_string($data),

		"tid" => $tid,
"action" => $db->escape_string($action),
"data" => $db->escape_string($data),

		"ipaddress" => $session->ipaddress

		"ipaddress" => $db->escape_string($session->ipaddress)

	);
$db->insert_query(TABLE_PREFIX."moderatorlog", $sql_array);
}

	);
$db->insert_query(TABLE_PREFIX."moderatorlog", $sql_array);
}

Zeile 1864Zeile 1860
			$ip = $_SERVER['REMOTE_ADDR'];
}
}

			$ip = $_SERVER['REMOTE_ADDR'];
}
}

 
	global $db;
$ip = $db->escape_string(preg_replace("#([^.0-9 ]*)#", "", $ip));


	return $ip;
}


	return $ip;
}


Zeile 1898Zeile 1897
		$size = $size . " " . $lang->size_bytes;
}
return $size;

		$size = $size . " " . $lang->size_bytes;
}
return $size;

}

/**

}

/**

 * Get the attachment icon for a specific file extension
*
* @param string The file extension

 * Get the attachment icon for a specific file extension
*
* @param string The file extension

Zeile 2188Zeile 2187
	echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">$db->query_count</font></td>\n";
echo "</tr>\n";
echo "<tr>\n";

	echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">$db->query_count</font></td>\n";
echo "</tr>\n";
echo "<tr>\n";

	echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">PHP Proccessing Time:</font></b></td>\n";

	echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">PHP Processing Time:</font></b></td>\n";

	echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">$phptime seconds ($percentphp%)</font></td>\n";
echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">MySQL Processing Time:</font></b></td>\n";
echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">$querytime seconds ($percentsql%)</font></td>\n";

	echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">$phptime seconds ($percentphp%)</font></td>\n";
echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">MySQL Processing Time:</font></b></td>\n";
echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">$querytime seconds ($percentsql%)</font></td>\n";

Zeile 2231Zeile 2230
	{
echo "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n";
echo "<tr>\n";

	{
echo "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n";
echo "<tr>\n";

		echo "<td colspan=\"8\" style=\"background-color: #ccc;\"><strong>Templates Used (Loaded for this Page) - ".count($templates->cache)." Total</strong></td>\n";

		echo "<td style=\"background-color: #ccc;\"><strong>Templates Used (Loaded for this Page) - ".count($templates->cache)." Total</strong></td>\n";

		echo "</tr>\n";
echo "<tr>\n";
echo "<td style=\"background: #fff;\">".implode(", ", array_keys($templates->cache))."</td>\n";

		echo "</tr>\n";
echo "<tr>\n";
echo "<td style=\"background: #fff;\">".implode(", ", array_keys($templates->cache))."</td>\n";

Zeile 2612Zeile 2611
 */
function build_theme_select($name, $selected="", $tid=0, $depth="", $usergroup_override=0)
{

 */
function build_theme_select($name, $selected="", $tid=0, $depth="", $usergroup_override=0)
{

	global $db, $themeselect, $tcache, $lang, $mybb;


	global $db, $themeselect, $tcache, $lang, $mybb, $limit;


	if($tid == 0)

	if($tid == 0)

	{

	{

		$themeselect = "<select name=\"$name\">";
$themeselect .= "<option value=\"0\">".$lang->use_default."</option>\n";
$themeselect .= "<option value=\"0\">-----------</option>\n";

		$themeselect = "<select name=\"$name\">";
$themeselect .= "<option value=\"0\">".$lang->use_default."</option>\n";
$themeselect .= "<option value=\"0\">-----------</option>\n";

	}



		$tid = 1;
}


	if(!is_array($tcache))

	if(!is_array($tcache))

	{
$query = $db->query("
SELECT name, pid, tid, allowedgroups
FROM ".TABLE_PREFIX."themes
WHERE pid != 0
ORDER BY pid, name
");

	{
$query = $db->simple_select(TABLE_PREFIX."themes", "name, pid, tid, allowedgroups", "pid != '0'", array('order_by' => 'pid, name'));






		while($theme = $db->fetch_array($query))

		while($theme = $db->fetch_array($query))

		{
$tcache[$theme['pid']][] = $theme;
}
}
if(is_array($tcache))
{


		{
$tcache[$theme['pid']][$theme['tid']] = $theme;
}
}

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

		// Figure out what groups this user is in
if($mybb->user['additionalgroups'])
{

		// Figure out what groups this user is in
if($mybb->user['additionalgroups'])
{

Zeile 2641Zeile 2640
		}
$in_groups[] = $mybb->user['usergroup'];


		}
$in_groups[] = $mybb->user['usergroup'];


		foreach($tcache as $misc)

		foreach($tcache[$tid] as $theme)

		{

		{

			foreach($misc as $theme)




			$sel = "";
// Make theme allowed groups into array
$is_allowed = false;
if($theme['allowedgroups'] != "all" && $theme['allowedgroups'] != "")

			{

			{

				$sel = "";
// Make theme allowed groups into array
$is_allowed = false;
if($theme['allowedgroups'] != "all" && $theme['allowedgroups'] != "")

				$allowed_groups = explode(",", $theme['allowedgroups']);
// See if groups user is in is allowed
foreach($allowed_groups as $agid)


				{

				{

					$allowed_groups = explode(",", $theme['allowedgroups']);
// See if groups user is in is allowed
foreach($allowed_groups as $agid)

					if(in_array($agid, $in_groups))



					{

					{

						if(in_array($agid, $in_groups))
{
$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 == 1)
















			}

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

if($theme['pid'] != 0)
{
$themeselect .= "<option value=\"".$theme['tid']."\"$sel>".$depth.$theme['name']."</option>";
$depthit = $depth."--";
}

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

				{

				{

					if($theme['tid'] == $selected)
{
$sel = " selected=\"selected\"";
}
if($theme['pid'] != 0)
{
$themeselect .= "<option value=\"".$theme['tid']."\"$sel>".$depth.$theme['name']."</option>";
$depthit = $depth."--";
}
if(array_key_exists($theme['tid'], $tcache))
{
build_theme_select($name, $selected, $theme['tid'], $depthit, $usergroup_override);
}

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













				}
}
}
}

				}
}
}
}

 
	

	if(!$tid)
{
$themeselect .= "</select>";
}

	if(!$tid)
{
$themeselect .= "</select>";
}

 
	

	return $themeselect;
}


	return $themeselect;
}


Zeile 2725Zeile 2726
	{
$parts = explode('.', $number);
if(isset($parts[1]))

	{
$parts = explode('.', $number);
if(isset($parts[1]))

		{

		{

			$decimals = my_strlen($parts[1]);
}
else

			$decimals = my_strlen($parts[1]);
}
else

Zeile 2793Zeile 2794
 * @return array The number of days in each month of that year
*/
function get_bdays($in)

 * @return array The number of days in each month of that year
*/
function get_bdays($in)

{

{

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


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


Zeile 2828Zeile 2829
{
$bday = explode("-", $birthday);
if($bday[2] < 1970)

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

        {

        {

                $years = 1970-$bday[2];
$year = $bday[2]+($years*2);
$stamp = mktime(0, 0, 0, $bday[1], $bday[0], $year)-($years*31556926*2);

                $years = 1970-$bday[2];
$year = $bday[2]+($years*2);
$stamp = mktime(0, 0, 0, $bday[1], $bday[0], $year)-($years*31556926*2);

Zeile 2862Zeile 2863
	{
$replyto_update = array("replyto" => 0);
$db->update_query(TABLE_PREFIX."threads", $replyto_update, "pid='{$post['pid']}");

	{
$replyto_update = array("replyto" => 0);
$db->update_query(TABLE_PREFIX."threads", $replyto_update, "pid='{$post['pid']}");

	}

	}

	$firstpostup = array("firstpost" => $post['pid']);
$db->update_query(TABLE_PREFIX."threads", $firstpostup, "tid='$tid'");

	$firstpostup = array("firstpost" => $post['pid']);
$db->update_query(TABLE_PREFIX."threads", $firstpostup, "tid='$tid'");

}

}


/**
* Checks for the length of a string, mb strings accounted for


/**
* Checks for the length of a string, mb strings accounted for

 *

 *

 * @param string The string to check the length of.
* @return int The length of the string.
*/
function my_strlen($string)
{

 * @param string The string to check the length of.
* @return int The length of the string.
*/
function my_strlen($string)
{

	$string = preg_replace("#&\#(0-9]+);#", "-", $string);
if(function_exists("mb_strlen"))
{
$string_length = mb_strlen($string);
}
else
{
$string_length = strlen($string);
}

    global $lang;

$string = preg_replace("#&\#(0-9]+);#", "-", $string);

if(strtolower($lang->settings['charset']) == "utf-8")
{
// Get rid of any excess RTL and LTR override for they are the workings of the devil
$string = str_replace(dec_to_utf8(8238), "", $string);
$string = str_replace(dec_to_utf8(8237), "", $string);





	return $string_length;















        // Remove dodgy whitspaces
$string = str_replace(chr(0xCA), "", $string);
}
$string = trim($string);

if(function_exists("mb_strlen"))
{
$string_length = mb_strlen($string);
}
else
{
$string_length = strlen($string);
}

return $string_length;

}

/**

}

/**

Zeile 2899Zeile 2914
function my_substr($string, $start, $length="")
{
if(function_exists("mb_substr"))

function my_substr($string, $start, $length="")
{
if(function_exists("mb_substr"))

	{
if($length != "")
{

	{
if($length != "")
{

			$cut_string = mb_substr($string, $start, $length);
}
else
{
$cut_string = mb_substr($string, $start);

			$cut_string = mb_substr($string, $start, $length);
}
else
{
$cut_string = mb_substr($string, $start);

		}
}
else
{

		}
}
else
{

		if($length != "")
{
$cut_string = substr($string, $start, $length);

		if($length != "")
{
$cut_string = substr($string, $start, $length);

		}

		}

		else
{
$cut_string = substr($string, $start);

		else
{
$cut_string = substr($string, $start);

Zeile 2922Zeile 2937
	}

return $cut_string;

	}

return $cut_string;

 
}

/**
* lowers the case of a string, mb strings accounted for
*
* @param string The string to lower.
* @return int The lowered string.
*/
function my_strtolower($string)
{
if(function_exists("mb_strtolower"))
{
$string = mb_strtolower($string);
}
else
{
$string = strtolower($string);
}

return $string;
}

/**
* Finds a needle in a haystack and returns it position, mb strings accounted for
*
* @param string String to look in (haystack)
* @param string What to look for (needle)
* @param int (optional) How much to offset
* @return int false on needle not found, integer position if found
*/
function my_strpos($haystack, $needle, $offset=0)
{
if($needle == '')
{
return false;
}

if(function_exists("mb_strpos"))
{
$position = mb_strpos($haystack, $needle, $offset);
}
else
{
$position = strpos($haystack, $needle, $offset);
}

return $position;
}

/**
* ups the case of a string, mb strings accounted for
*
* @param string The string to up.
* @return int The uped string.
*/
function my_strtoupper($string)
{
if(function_exists("mb_strtoupper"))
{
$string = mb_strtoupper($string);
}
else
{
$string = strtoupper($string);
}

return $string;

}

/**

}

/**

Zeile 2932Zeile 3014
 */
function unhtmlentities($string)
{

 */
function unhtmlentities($string)
{

   // replace numeric entities

   // Replace numeric entities

   $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);

   $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);

   // replace literal entities



// Replace literal entities

   $trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);

   $trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);

 


   return strtr($string, $trans_tbl);
}


   return strtr($string, $trans_tbl);
}


Zeile 3302Zeile 3386
*/
function validate_email_format($email)
{

*/
function validate_email_format($email)
{

	if(!preg_match("/^(.+)@[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+$/si", $email))

	if(!preg_match("/^(.+)@[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+$/si", $email) || strpos($email, ' ') !== false)

	{
return false;
}

	{
return false;
}

Zeile 3388Zeile 3472
		return false;
}
return $dest;

		return false;
}
return $dest;

 
}

/**
* Return a list of banned usernames.
*
* @return array The array of banned usernames.
*/
function get_banned_usernames()
{
global $mybb;
$banned_usernames = explode(",", $mybb->settings['bannedusernames']);
$banned_usernames = array_map("trim", $banned_usernames);
$banned_usernames = array_map("strtolower", $banned_usernames);
return $banned_usernames;
}

/**
* Checks if a username has been disallowed for registration/use.
*
* @param string The username
* @return boolean True if banned, false if not banned
*/
function is_banned_username($username)
{
$banned_usernames = get_banned_usernames();
if(in_array(strtolower($username), $banned_usernames))
{
return true;
}
else
{
return false;
}
}

/**
* Return a list of banned email addresses.
*
* @return array The array of banned email addresses.
*/
function get_banned_emails()
{
global $mybb;
$banned_emails = explode(",", $mybb->settings['bannedemails']);
$banned_emails = array_map("trim", $banned_emails);
$banned_emails = array_map("strtolower", $banned_emails);
return $banned_emails;
}

/**
* Check if a specific email address has been banned.
*
* @param string The email address.
* @return boolean True if banned, false if not banned
*/
function is_banned_email($email)
{
$banned_emails = get_banned_emails();
$email = strtolower($email);
foreach($banned_emails as $banned_email)
{
if($banned_email != "" && strpos($email, $banned_email) !== false)
{
return true;
}
}
return false;
}

/**
* Return a list of banned IP addresses.
*
* @return array The array of banned IP addresses.
*/
function get_banned_ips()
{
global $mybb;
$banned_ips = explode(",", $mybb->settings['bannedips']);
$banned_ips = array_map("trim", $banned_ips);
return $banned_ips;
}

/**
* Checks if a specific IP address has been banned.
*
* @param string The IP address.
* @return boolean True if banned, false if not banned.
*/
function is_banned_ip($ip_address)
{
$banned_ips = get_banned_ips();
foreach($banned_ips as $banned_ip)
{
if($banned_ip != "" && strpos($ip_address, $banned_ip) !== false)
{
return true;
}
}
return false;

}

/**

}

/**