Vergleich inc/functions.php - 1.6.7 - 1.6.12

  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 5765 2012-03-27 09:52:45Z Tomm $

 * $Id$

 */

/**

 */

/**

Zeile 47Zeile 47

if(my_strpos(getenv("REQUEST_URI"), "?"))
{


if(my_strpos(getenv("REQUEST_URI"), "?"))
{

				$debuglink = htmlspecialchars(getenv("REQUEST_URI")) . "&debug=1";

				$debuglink = htmlspecialchars_uni(getenv("REQUEST_URI")) . "&debug=1";

			}
else
{

			}
else
{

				$debuglink = htmlspecialchars(getenv("REQUEST_URI")) . "?debug=1";

				$debuglink = htmlspecialchars_uni(getenv("REQUEST_URI")) . "?debug=1";

			}

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

			}

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

Zeile 63Zeile 63
				$gzipen = "Disabled";
}


				$gzipen = "Disabled";
}


			if(function_exists("memory_get_usage"))














			$memory_usage = get_memory_usage();

if($memory_usage)
{
$memory_usage = " / Memory Usage: ".get_friendly_size($memory_usage);
}
else
{
$memory_usage = '';
}
// MySQLi is still MySQL, so present it that way to the user
$database_server = $db->short_title;

if($database_server == 'MySQLi')

			{

			{

				$memory_usage = " / Memory Usage: ".get_friendly_size(memory_get_peak_usage(true));

				$database_server = 'MySQL';

			}

			}



 
			$other = "PHP version: $phpversion / Server Load: $serverload / GZip Compression: $gzipen";

			$other = "PHP version: $phpversion / Server Load: $serverload / GZip Compression: $gzipen";

			$debugstuff = "Generated in $totaltime seconds ($percentphp% PHP / $percentsql% MySQL)<br />SQL Queries: $db->query_count /  Global Parsing Time: $globaltime$memory_usage<br />$other<br />[<a href=\"$debuglink\" target=\"_blank\">advanced details</a>]<br />";

			$debugstuff = "Generated in $totaltime seconds ($percentphp% PHP / $percentsql% ".$database_server.")<br />SQL Queries: $db->query_count /  Global Parsing Time: $globaltime$memory_usage<br />$other<br />[<a href=\"$debuglink\" target=\"_blank\">advanced details</a>]<br />";

			$contents = str_replace("<debugstuff>", $debugstuff, $contents);
}

if($mybb->debug_mode == true)
{
debug_page();

			$contents = str_replace("<debugstuff>", $debugstuff, $contents);
}

if($mybb->debug_mode == true)
{
debug_page();

		}
}

		}
}


$contents = str_replace("<debugstuff>", "", $contents);
$contents = $plugins->run_hooks("pre_output_page", $contents);


$contents = str_replace("<debugstuff>", "", $contents);
$contents = $plugins->run_hooks("pre_output_page", $contents);





	if($mybb->settings['gzipoutput'] == 1)
{
$contents = gzip_encode($contents, $mybb->settings['gziplevel']);
}

	if($mybb->settings['gzipoutput'] == 1)
{
$contents = gzip_encode($contents, $mybb->settings['gziplevel']);
}

	



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

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

	



	echo $contents;

$plugins->run_hooks("post_output_page");

	echo $contents;

$plugins->run_hooks("post_output_page");

Zeile 102Zeile 114
 * @return boolean True if function exists, otherwise false.
*/
function add_shutdown($name, $arguments=array())

 * @return boolean True if function exists, otherwise false.
*/
function add_shutdown($name, $arguments=array())

{

{

	global $shutdown_functions;

	global $shutdown_functions;

	







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


	if(!is_array($arguments))

	if(!is_array($arguments))

	{

	{

		$arguments = array($arguments);

		$arguments = array($arguments);

	}

	}


if(is_array($name) && method_exists($name[0], $name[1]))
{


if(is_array($name) && method_exists($name[0], $name[1]))
{

		$shutdown_functions["class_".get_class($name[0])."_".$name[1]] = array('function' => $name, 'arguments' => $arguments);

		$shutdown_functions[] = array('function' => $name, 'arguments' => $arguments);

		return true;
}
else if(!is_array($name) && function_exists($name))

		return true;
}
else if(!is_array($name) && function_exists($name))

	{
$shutdown_functions[$name] = array('function' => $name, 'arguments' => $arguments);

	{
$shutdown_functions[] = array('function' => $name, 'arguments' => $arguments);

		return true;
}


		return true;
}


Zeile 156Zeile 173
		{
require MYBB_ROOT."inc/config.php";
}

		{
require MYBB_ROOT."inc/config.php";
}

		



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

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

Zeile 164Zeile 181
			{
case "sqlite":
$db = new DB_SQLite;

			{
case "sqlite":
$db = new DB_SQLite;

					break;

					break;

				case "pgsql":
$db = new DB_PgSQL;

				case "pgsql":
$db = new DB_PgSQL;

					break;

					break;

				case "mysqli":
$db = new DB_MySQLi;
break;
default:
$db = new DB_MySQL;
}

				case "mysqli":
$db = new DB_MySQLi;
break;
default:
$db = new DB_MySQL;
}

			





			$db->connect($config['database']);
define("TABLE_PREFIX", $config['database']['table_prefix']);
$db->set_table_prefix(TABLE_PREFIX);

			$db->connect($config['database']);
define("TABLE_PREFIX", $config['database']['table_prefix']);
$db->set_table_prefix(TABLE_PREFIX);

Zeile 188Zeile 205
		require_once MYBB_ROOT."inc/class_datacache.php";
$cache = new datacache;
$cache->cache();

		require_once MYBB_ROOT."inc/class_datacache.php";
$cache = new datacache;
$cache->cache();

	}


	}


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

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

Zeile 212Zeile 229
	if(is_array($shutdown_functions))
{
foreach($shutdown_functions as $function)

	if(is_array($shutdown_functions))
{
foreach($shutdown_functions as $function)

		{

		{

			call_user_func_array($function['function'], $function['arguments']);
}
}

			call_user_func_array($function['function'], $function['arguments']);
}
}

Zeile 245Zeile 262
		{
// Delete the message from the queue
$db->delete_query("mailqueue", "mid='{$email['mid']}'");

		{
// Delete the message from the queue
$db->delete_query("mailqueue", "mid='{$email['mid']}'");

			



			if($db->affected_rows() == 1)
{

			if($db->affected_rows() == 1)
{

				my_mail($email['mailto'], $email['subject'], $email['message'], $email['mailfrom'], "", $email['headers']);

				my_mail($email['mailto'], $email['subject'], $email['message'], $email['mailfrom'], "", $email['headers'], true);

			}
}
// Update the mailqueue cache and remove the lock

			}
}
// Update the mailqueue cache and remove the lock

Zeile 260Zeile 277

/**
* Parses the contents of a page before outputting it.


/**
* Parses the contents of a page before outputting it.

 *

 *

 * @param string The contents of the page.
* @return string The parsed page.
*/

 * @param string The contents of the page.
* @return string The parsed page.
*/

Zeile 272Zeile 289
	$contents = str_replace('<archive_url>', $archive_url, $contents);

if($htmldoctype)

	$contents = str_replace('<archive_url>', $archive_url, $contents);

if($htmldoctype)

	{

	{

		$contents = $htmldoctype.$contents;

		$contents = $htmldoctype.$contents;

	}

	}

	else
{
$contents = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".$contents;
}

	else
{
$contents = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".$contents;
}

	
$contents = str_replace("<html", "<html xmlns=\"http://www.w3.org/1999/xhtml\"", $contents);


$contents = str_replace("<html", "<html xmlns=\"http://www.w3.org/1999/xhtml\"", $contents);


if($lang->settings['rtl'] == 1)
{
$contents = str_replace("<html", "<html dir=\"rtl\"", $contents);


if($lang->settings['rtl'] == 1)
{
$contents = str_replace("<html", "<html dir=\"rtl\"", $contents);

	}

	}


if($lang->settings['htmllang'])


if($lang->settings['htmllang'])

	{

	{

		$contents = str_replace("<html", "<html xml:lang=\"".$lang->settings['htmllang']."\" lang=\"".$lang->settings['htmllang']."\"", $contents);

		$contents = str_replace("<html", "<html xml:lang=\"".$lang->settings['htmllang']."\" lang=\"".$lang->settings['htmllang']."\"", $contents);

	}

	}


if($error_handler->warnings)
{
$contents = str_replace("<body>", "<body>\n".$error_handler->show_warnings(), $contents);
}


if($error_handler->warnings)
{
$contents = str_replace("<body>", "<body>\n".$error_handler->show_warnings(), $contents);
}

	



	return $contents;
}


	return $contents;
}


Zeile 321Zeile 338
	}

if(!$offset && $offset != '0')

	}

if(!$offset && $offset != '0')

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

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

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

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

Zeile 333Zeile 350
			$dstcorrection = $mybbadmin['dst'];
}
else

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

		{

		{

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

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

Zeile 353Zeile 370
	{
$offset = 0;
}

	{
$offset = 0;
}

	



	if($adodb == true && function_exists('adodb_date'))
{
$date = adodb_date($format, $stamp + ($offset * 3600));

	if($adodb == true && function_exists('adodb_date'))
{
$date = adodb_date($format, $stamp + ($offset * 3600));

	}

	}

	else

	else

	{

	{

		$date = gmdate($format, $stamp + ($offset * 3600));
}

		$date = gmdate($format, $stamp + ($offset * 3600));
}

	



	if($mybb->settings['dateformat'] == $format && $ty)
{
$stamp = TIME_NOW;

	if($mybb->settings['dateformat'] == $format && $ty)
{
$stamp = TIME_NOW;

		



		if($adodb == true && function_exists('adodb_date'))
{
$todaysdate = adodb_date($format, $stamp + ($offset * 3600));
$yesterdaysdate = adodb_date($format, ($stamp - 86400) + ($offset * 3600));

		if($adodb == true && function_exists('adodb_date'))
{
$todaysdate = adodb_date($format, $stamp + ($offset * 3600));
$yesterdaysdate = adodb_date($format, ($stamp - 86400) + ($offset * 3600));

		}

		}

		else
{
$todaysdate = gmdate($format, $stamp + ($offset * 3600));

		else
{
$todaysdate = gmdate($format, $stamp + ($offset * 3600));

Zeile 394Zeile 411
	}

return $date;

	}

return $date;

}

}


/**
* Sends an email using PHP's mail function, formatting it appropriately.


/**
* Sends an email using PHP's mail function, formatting it appropriately.

Zeile 413Zeile 430
{
global $mybb;
static $mail;

{
global $mybb;
static $mail;

	



	// Does our object not exist? Create it
if(!is_object($mail))
{
require_once MYBB_ROOT."inc/class_mailhandler.php";

	// Does our object not exist? Create it
if(!is_object($mail))
{
require_once MYBB_ROOT."inc/class_mailhandler.php";

		



		if($mybb->settings['mail_handler'] == 'smtp')
{
require_once MYBB_ROOT."inc/mailhandlers/smtp.php";

		if($mybb->settings['mail_handler'] == 'smtp')
{
require_once MYBB_ROOT."inc/mailhandlers/smtp.php";

Zeile 430Zeile 447
			$mail = new PhpMail();
}
}

			$mail = new PhpMail();
}
}

	



	// Using SMTP based mail
if($mybb->settings['mail_handler'] == 'smtp')
{

	// Using SMTP based mail
if($mybb->settings['mail_handler'] == 'smtp')
{

Zeile 439Zeile 456
			$mail->keep_alive = true;
}
}

			$mail->keep_alive = true;
}
}

	



	// Using PHP based mail()
else
{

	// Using PHP based mail()
else
{

Zeile 448Zeile 465
			$mail->additional_parameters = $mybb->settings['mail_parameters'];
}
}

			$mail->additional_parameters = $mybb->settings['mail_parameters'];
}
}

	



	// Build and send
$mail->build_message($to, $subject, $message, $from, $charset, $headers, $format, $message_text, $return_email);
return $mail->send();

	// Build and send
$mail->build_message($to, $subject, $message, $from, $charset, $headers, $format, $message_text, $return_email);
return $mail->send();

Zeile 456Zeile 473

/**
* Generates a unique code for POST requests to prevent XSS/CSRF attacks


/**
* Generates a unique code for POST requests to prevent XSS/CSRF attacks

 *

 *

 * @return string The generated code
*/
function generate_post_check()
{

 * @return string The generated code
*/
function generate_post_check()
{

	global $mybb;

	global $mybb, $session;

	if($mybb->user['uid'])
{
return md5($mybb->user['loginkey'].$mybb->user['salt'].$mybb->user['regdate']);

	if($mybb->user['uid'])
{
return md5($mybb->user['loginkey'].$mybb->user['salt'].$mybb->user['regdate']);

Zeile 469Zeile 486
	// Guests get a special string
else
{

	// Guests get a special string
else
{

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

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

	}
}


	}
}


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

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

	



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

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

Zeile 588Zeile 605
		}
}
return $forum_cache;

		}
}
return $forum_cache;

}


}


/**
* Generate an array of all child and descendant forums for a specific forum.
*

/**
* Generate an array of all child and descendant forums for a specific forum.
*

Zeile 616Zeile 633
	{
return;
}

	{
return;
}

	



	foreach($forums_by_parent[$fid] as $forum)
{
$forums[] = $forum['fid'];

	foreach($forums_by_parent[$fid] as $forum)
{
$forums[] = $forum['fid'];

Zeile 643Zeile 660
	if(!$error)
{
$error = $lang->unknown_error;

	if(!$error)
{
$error = $lang->unknown_error;

	}

// AJAX error message?
if($mybb->input['ajax'])
{
// Send our headers.
@header("Content-type: text/html; charset={$lang->settings['charset']}");
echo "<error>{$error}</error>\n";
exit;
}

if(!$title)

	}

// AJAX error message?
if($mybb->input['ajax'])
{
// Send our headers.
@header("Content-type: text/html; charset={$lang->settings['charset']}");
echo "<error>{$error}</error>\n";
exit;
}

if(!$title)

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

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

Zeile 664Zeile 681
	add_breadcrumb($lang->error);

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

	add_breadcrumb($lang->error);

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

	output_page($errorpage);


	output_page($errorpage);


	exit;
}


	exit;
}


Zeile 697Zeile 714
		// Send our headers.
@header("Content-type: text/html; charset={$lang->settings['charset']}");
echo "<error>{$error}</error>\n";

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

		exit;
}


		exit;
}


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

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

Zeile 733Zeile 750
		// Send our headers.
header("Content-type: text/html; charset={$lang->settings['charset']}");
echo "<error>{$lang->error_nopermission_user_ajax}</error>\n";

		// Send our headers.
header("Content-type: text/html; charset={$lang->settings['charset']}");
echo "<error>{$lang->error_nopermission_user_ajax}</error>\n";

		exit;
}


		exit;
}


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

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

Zeile 751Zeile 768
		}

$redirect_url = htmlspecialchars_uni($redirect_url);

		}

$redirect_url = htmlspecialchars_uni($redirect_url);

		



		switch($mybb->settings['username_method'])
{
case 0:

		switch($mybb->settings['username_method'])
{
case 0:

Zeile 759Zeile 776
				break;
case 1:
$lang_username = $lang->username1;

				break;
case 1:
$lang_username = $lang->username1;

				break;

				break;

			case 2:
$lang_username = $lang->username2;
break;

			case 2:
$lang_username = $lang->username2;
break;

Zeile 782Zeile 799
function redirect($url, $message="", $title="")
{
global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;

function redirect($url, $message="", $title="")
{
global $header, $footer, $mybb, $theme, $headerinclude, $templates, $lang, $plugins;





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

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

	



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

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

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

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

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

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

	



	// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest.
if($mybb->settings['redirects'] == 1 && ($mybb->user['showredirect'] != 0 || !$mybb->user['uid']))

	// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest.
if($mybb->settings['redirects'] == 1 && ($mybb->user['showredirect'] != 0 || !$mybb->user['uid']))

	{

	{

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

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

		$url = htmlspecialchars($url);


		$url = htmlspecialchars_uni($url);


		eval("\$redirectpage = \"".$templates->get("redirect")."\";");
output_page($redirectpage);
}

		eval("\$redirectpage = \"".$templates->get("redirect")."\";");
output_page($redirectpage);
}

Zeile 830Zeile 847
	{
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);

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





		run_shutdown();

		run_shutdown();

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


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

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

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

Zeile 863Zeile 880
	{
return;
}

	{
return;
}

	



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

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

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

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





$prevpage = '';

	if($page > 1)
{
$prev = $page-1;
$page_url = fetch_page_url($url, $prev);
eval("\$prevpage = \"".$templates->get("multipage_prevpage")."\";");

	if($page > 1)
{
$prev = $page-1;
$page_url = fetch_page_url($url, $prev);
eval("\$prevpage = \"".$templates->get("multipage_prevpage")."\";");

	}


	}


	// Maximum number of "page bits" to show
if(!$mybb->settings['maxmultipagelinks'])
{
$mybb->settings['maxmultipagelinks'] = 5;
}

	// Maximum number of "page bits" to show
if(!$mybb->settings['maxmultipagelinks'])
{
$mybb->settings['maxmultipagelinks'] = 5;
}





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

if($from <= 0)

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

if($from <= 0)

	{

	{

		$from = 1;
$to = $from+$mybb->settings['maxmultipagelinks']-1;
}

		$from = 1;
$to = $from+$mybb->settings['maxmultipagelinks']-1;
}

Zeile 898Zeile 916
		if($from <= 0)
{
$from = 1;

		if($from <= 0)
{
$from = 1;

		}
}


		}
}


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


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


 
	$start = '';

	if($from > 1)
{
if($from-1 == 1)

	if($from > 1)
{
if($from-1 == 1)

		{

		{

			$lang->multipage_link_start = '';
}


			$lang->multipage_link_start = '';
}


Zeile 917Zeile 936
		eval("\$start = \"".$templates->get("multipage_start")."\";");
}


		eval("\$start = \"".$templates->get("multipage_start")."\";");
}


 
	$mppage = '';

	for($i = $from; $i <= $to; ++$i)
{
$page_url = fetch_page_url($url, $i);

	for($i = $from; $i <= $to; ++$i)
{
$page_url = fetch_page_url($url, $i);

Zeile 932Zeile 952
			}
}
else

			}
}
else

		{

		{

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

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

		}

		}

	}


	}


 
	$end = '';

	if($to < $pages)
{
if($to+1 == $pages)
{
$lang->multipage_link_end = '';
}

	if($to < $pages)
{
if($to+1 == $pages)
{
$lang->multipage_link_end = '';
}





		$page_url = fetch_page_url($url, $pages);
eval("\$end = \"".$templates->get("multipage_end")."\";");

		$page_url = fetch_page_url($url, $pages);
eval("\$end = \"".$templates->get("multipage_end")."\";");

	}

	}





 
	$nextpage = '';

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

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

 


	$lang->multipage_pages = $lang->sprintf($lang->multipage_pages, $pages);

	$lang->multipage_pages = $lang->sprintf($lang->multipage_pages, $pages);

	



	if($breadcrumb == true)
{
eval("\$multipage = \"".$templates->get("multipage_breadcrumb")."\";");

	if($breadcrumb == true)
{
eval("\$multipage = \"".$templates->get("multipage_breadcrumb")."\";");

Zeile 977Zeile 1000
function fetch_page_url($url, $page)
{
if($page <= 1)

function fetch_page_url($url, $page)
{
if($page <= 1)

 	{

	{

		$find = array(
"-page-{page}",
"&amp;page={page}",

		$find = array(
"-page-{page}",
"&amp;page={page}",

Zeile 1104Zeile 1127
				{
$usergroup[$perm] = 0;
continue;

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

				} 

				}


if($access > $permbit || ($access == "yes" && $permbit == "no") || !$permbit) // Keep yes/no for compatibility?
{


if($access > $permbit || ($access == "yes" && $permbit == "no") || !$permbit) // Keep yes/no for compatibility?
{

Zeile 1112Zeile 1135
				}
}
}

				}
}
}

	}


	}


	return $usergroup;
}


	return $usergroup;
}


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

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

	}


	}


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


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


Zeile 1141Zeile 1164
	}

return $displaygroup;

	}

return $displaygroup;

}


}


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

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

Zeile 1154Zeile 1177
function forum_permissions($fid=0, $uid=0, $gid=0)
{
global $db, $cache, $groupscache, $forum_cache, $fpermcache, $mybb, $usercache, $cached_forum_permissions_permissions, $cached_forum_permissions;

function forum_permissions($fid=0, $uid=0, $gid=0)
{
global $db, $cache, $groupscache, $forum_cache, $fpermcache, $mybb, $usercache, $cached_forum_permissions_permissions, $cached_forum_permissions;





	if($uid == 0)

	if($uid == 0)

	{

	{

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


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


Zeile 1165Zeile 1188
		if($uid != 0 && $uid != $mybb->user['uid'])
{
if(!$usercache[$uid])

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

			{

			{

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

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

Zeile 1187Zeile 1210
	}

if(!is_array($forum_cache))

	}

if(!is_array($forum_cache))

	{
$forum_cache = cache_forums();

	{
$forum_cache = cache_forums();


if(!$forum_cache)
{


if(!$forum_cache)
{

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

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

	}


	}


	if($fid) // Fetch the permissions for a single forum
{
if(!$cached_forum_permissions_permissions[$gid][$fid])

	if($fid) // Fetch the permissions for a single forum
{
if(!$cached_forum_permissions_permissions[$gid][$fid])

Zeile 1234Zeile 1257
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 permissions so lets just return the group permissions


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

	{
return $groupperms;
}

	{
return $groupperms;
}

	



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

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

	



	foreach($groups as $gid)
{
if($groupscache[$gid])
{
$level_permissions = $fpermcache[$fid][$gid];

	foreach($groups as $gid)
{
if($groupscache[$gid])
{
$level_permissions = $fpermcache[$fid][$gid];

			



			// If our permissions arn't inherited we need to figure them out
if(empty($level_permissions))
{

			// If our permissions arn't inherited we need to figure them out
if(empty($level_permissions))
{

Zeile 1266Zeile 1289
							break;
}
}

							break;
}
}

					



					// If we STILL don't have forum permissions we use the usergroup itself
if(empty($level_permissions))
{
$level_permissions = $groupscache[$gid];

					// If we STILL don't have forum permissions we use the usergroup itself
if(empty($level_permissions))
{
$level_permissions = $groupscache[$gid];

					}					

					}

				}
}

				}
}

			



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

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

			{

			{

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

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

			}

			}





			if(!$level_permissions["canonlyviewownthreads"])

			if($level_permissions["canview"] && !$level_permissions["canonlyviewownthreads"])

			{
$only_view_own_threads = 0;

			{
$only_view_own_threads = 0;

			}
}
}

			}
}
}


// Figure out if we can view more than our own threads
if($only_view_own_threads == 0)


// Figure out if we can view more than our own threads
if($only_view_own_threads == 0)

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

	$showform = true;

	



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

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

Zeile 1335Zeile 1358
			{
continue;
}

			{
continue;
}

			



			if($forum_cache[$parent_id]['password'] != "")

			if($forum_cache[$parent_id]['password'] != "")

			{

			{

				check_forum_password($parent_id, $fid);
}
}
}

				check_forum_password($parent_id, $fid);
}
}
}

	



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

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

		{

		{

			if($password == $mybb->input['pwverify'])

			if($password == $mybb->input['pwverify'])

			{

			{

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

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

				$showform = true;

				$showform = true;

			}
}
else

			}
}
else

Zeile 1391Zeile 1414
		exit;
}
}

		exit;
}
}





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

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

Zeile 1409Zeile 1432
	{
$uid = $mybb->user['uid'];
}

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

	



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

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

Zeile 1517Zeile 1540
	{
$uid = $mybb->user['uid'];
}

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

	



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

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

Zeile 1553Zeile 1576
		else
{
$modperms = get_moderator_permissions($fid, $uid);

		else
{
$modperms = get_moderator_permissions($fid, $uid);

			



			if(!$action && $modperms)

			if(!$action && $modperms)

			{

			{

				return true;
}
else
{
if($modperms[$action] == 1)

				return true;
}
else
{
if($modperms[$action] == 1)

				{

				{

					return true;

					return true;

				}

				}

				else
{
return false;
}
}

				else
{
return false;
}
}

		}

		}

	}
}


	}
}


Zeile 1588Zeile 1611
		$icon = $mybb->input['icon'];
}


		$icon = $mybb->input['icon'];
}


 
	$iconlist = '';

	$no_icons_checked = " checked=\"checked\"";
// read post icons from cache, and sort them accordingly
$posticons_cache = $cache->read("posticons");
$posticons = array();
foreach($posticons_cache as $posticon)

	$no_icons_checked = " checked=\"checked\"";
// read post icons from cache, and sort them accordingly
$posticons_cache = $cache->read("posticons");
$posticons = array();
foreach($posticons_cache as $posticon)

	{

	{

		$posticons[$posticon['name']] = $posticon;
}
krsort($posticons);

		$posticons[$posticon['name']] = $posticon;
}
krsort($posticons);

	



	foreach($posticons as $dbicon)
{
$dbicon['path'] = htmlspecialchars_uni($dbicon['path']);
$dbicon['name'] = htmlspecialchars_uni($dbicon['name']);

	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 1618Zeile 1642
		{
$iconlist .= "<br />";
$listed = 0;

		{
$iconlist .= "<br />";
$listed = 0;

		}

		}

	}

	}





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

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





	return $posticons;
}

/**
* MyBB setcookie() wrapper.

	return $posticons;
}

/**
* MyBB setcookie() wrapper.

 *
* @param string The cookie identifier.

 *
* @param string The cookie identifier.

 * @param string The cookie value.
* @param int The timestamp of the expiry date.
* @param boolean True if setting a HttpOnly cookie (supported by IE, Opera 9, Konqueror)

 * @param string The cookie value.
* @param int The timestamp of the expiry date.
* @param boolean True if setting a HttpOnly cookie (supported by IE, Opera 9, Konqueror)

Zeile 1639Zeile 1663
	global $mybb;

if(!$mybb->settings['cookiepath'])

	global $mybb;

if(!$mybb->settings['cookiepath'])

	{

	{

		$mybb->settings['cookiepath'] = "/";
}


		$mybb->settings['cookiepath'] = "/";
}


Zeile 1659Zeile 1683
	$mybb->settings['cookiepath'] = str_replace(array("\n","\r"), "", $mybb->settings['cookiepath']);
$mybb->settings['cookiedomain'] = str_replace(array("\n","\r"), "", $mybb->settings['cookiedomain']);
$mybb->settings['cookieprefix'] = str_replace(array("\n","\r", " "), "", $mybb->settings['cookieprefix']);

	$mybb->settings['cookiepath'] = str_replace(array("\n","\r"), "", $mybb->settings['cookiepath']);
$mybb->settings['cookiedomain'] = str_replace(array("\n","\r"), "", $mybb->settings['cookiedomain']);
$mybb->settings['cookieprefix'] = str_replace(array("\n","\r", " "), "", $mybb->settings['cookieprefix']);





	// Versions of PHP prior to 5.2 do not support HttpOnly cookies and IE is buggy when specifying a blank domain so set the cookie manually
$cookie = "Set-Cookie: {$mybb->settings['cookieprefix']}{$name}=".urlencode($value);


	// Versions of PHP prior to 5.2 do not support HttpOnly cookies and IE is buggy when specifying a blank domain so set the cookie manually
$cookie = "Set-Cookie: {$mybb->settings['cookieprefix']}{$name}=".urlencode($value);


Zeile 1682Zeile 1706
	{
$cookie .= "; HttpOnly";
}

	{
$cookie .= "; HttpOnly";
}

	



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

header($cookie, false);

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

header($cookie, false);

Zeile 1696Zeile 1720
function my_unsetcookie($name)
{
global $mybb;

function my_unsetcookie($name)
{
global $mybb;

	



	$expires = -3600;
my_setcookie($name, "", $expires);

	$expires = -3600;
my_setcookie($name, "", $expires);

	



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

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

}

/**

}

/**

 * Get the contents from a serialised cookie array.
*
* @param string The cookie identifier.

 * Get the contents from a serialised cookie array.
*
* @param string The cookie identifier.

Zeile 1711Zeile 1735
 * @return array|boolean The cookie id's content array or false when non-existent.
*/
function my_get_array_cookie($name, $id)

 * @return array|boolean The cookie id's content array or false when non-existent.
*/
function my_get_array_cookie($name, $id)

{

{

	global $mybb;

	global $mybb;

	



	if(!isset($mybb->cookies['mybb'][$name]))
{
return false;

	if(!isset($mybb->cookies['mybb'][$name]))
{
return false;

	}

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


	}

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


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

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

	{

	{

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

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

	}

	}

}

/**

}

/**

Zeile 1741Zeile 1765
function my_set_array_cookie($name, $id, $value, $expires="")
{
global $mybb;

function my_set_array_cookie($name, $id, $value, $expires="")
{
global $mybb;

	



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


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


Zeile 1769Zeile 1793
	}

return $array;

	}

return $array;

} 

}


/**
* Returns the serverload of the system.


/**
* Returns the serverload of the system.

Zeile 1802Zeile 1826
			{
return $lang->unknown;
}

			{
return $lang->unknown;
}

			



			// Suhosin likes to throw a warning if exec is disabled then die - weird
if($func_blacklist = @ini_get('suhosin.executor.func.blacklist'))
{

			// Suhosin likes to throw a warning if exec is disabled then die - weird
if($func_blacklist = @ini_get('suhosin.executor.func.blacklist'))
{

Zeile 1817Zeile 1841
				if(strpos(",".$func_blacklist.",", 'exec') !== false)
{
return $lang->unknown;

				if(strpos(",".$func_blacklist.",", 'exec') !== false)
{
return $lang->unknown;

				}
}


				}
}


			$load = @exec("uptime");
$load = explode("load average: ", $load);
$serverload = explode(",", $load[1]);

			$load = @exec("uptime");
$load = explode("load average: ", $load);
$serverload = explode(",", $load[1]);

Zeile 1828Zeile 1852
				return $lang->unknown;
}
}

				return $lang->unknown;
}
}

	}

	}

	else
{
return $lang->unknown;

	else
{
return $lang->unknown;

Zeile 1837Zeile 1861
	$returnload = trim($serverload[0]);

return $returnload;

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

return $returnload;

 
}

/**
* Returns the amount of memory allocated to the script.
*
* @return int The amount of memory allocated to the script.
*/
function get_memory_usage()
{
if(function_exists('memory_get_peak_usage'))
{
return memory_get_peak_usage(true);
}
elseif(function_exists('memory_get_usage'))
{
return memory_get_usage(true);
}
return false;

}

/**

}

/**

Zeile 1860Zeile 1902
			if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
{
if(intval($changes[$counter]) != 0)

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

                {

				{

					$new_stats[$counter] = $stats[$counter] + $changes[$counter];
}
}

					$new_stats[$counter] = $stats[$counter] + $changes[$counter];
}
}

Zeile 1868Zeile 1910
			{
$new_stats[$counter] = $changes[$counter];
}

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

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

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

		}

		}

	}


	}


	// Fetch latest user if the user count is changing
if(array_key_exists('numusers', $changes))
{

	// Fetch latest user if the user count is changing
if(array_key_exists('numusers', $changes))
{

		$query = $db->simple_select("users", "uid, username", "", array('order_by' => 'uid', 'order_dir' => 'DESC', 'limit' => 1));

		$query = $db->simple_select("users", "uid, username", "", array('order_by' => 'regdate', 'order_dir' => 'DESC', 'limit' => 1));

		$lastmember = $db->fetch_array($query);
$new_stats['lastuid'] = $lastmember['uid'];
$new_stats['lastusername'] = $lastmember['username'];
}

		$lastmember = $db->fetch_array($query);
$new_stats['lastuid'] = $lastmember['uid'];
$new_stats['lastusername'] = $lastmember['username'];
}

	



	if(empty($new_stats))
{
return;
}

	if(empty($new_stats))
{
return;
}

	



	if(is_array($stats))
{
$stats = array_merge($stats, $new_stats);

	if(is_array($stats))
{
$stats = array_merge($stats, $new_stats);

Zeile 1942Zeile 1984
			{
$update_query[$counter] = $changes[$counter];
}

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

			



			// Less than 0? That's bad

			// Less than 0? That's bad

			if(!$update_query[$counter])

			if($update_query[$counter] < 0)

			{
$update_query[$counter] = 0;
}

			{
$update_query[$counter] = 0;
}

Zeile 1958Zeile 2000
	}

// Guess we should update the statistics too?

	}

// Guess we should update the statistics too?

	if(isset($update_query['threads']) || isset($update_query['posts']) || isset($update_query['unapprovedthreads']) || isset($update_query['unapprovedposts']))
{
$new_stats = array();
if(array_key_exists('threads', $update_query))
{
$threads_diff = $update_query['threads'] - $forum['threads'];
if($threads_diff > -1)
{
$new_stats['numthreads'] = "+{$threads_diff}";
}
else
{
$new_stats['numthreads'] = "{$threads_diff}";
}
}

if(array_key_exists('unapprovedthreads', $update_query))
{
$unapprovedthreads_diff = $update_query['unapprovedthreads'] - $forum['unapprovedthreads'];
if($unapprovedthreads_diff > -1)
{
$new_stats['numunapprovedthreads'] = "+{$unapprovedthreads_diff}";
}
else
{
$new_stats['numunapprovedthreads'] = "{$unapprovedthreads_diff}";
}




















	$new_stats = array();
if(array_key_exists('threads', $update_query))
{
$threads_diff = $update_query['threads'] - $forum['threads'];
if($threads_diff > -1)
{
$new_stats['numthreads'] = "+{$threads_diff}";
}
else
{
$new_stats['numthreads'] = "{$threads_diff}";
}
}

if(array_key_exists('unapprovedthreads', $update_query))
{
$unapprovedthreads_diff = $update_query['unapprovedthreads'] - $forum['unapprovedthreads'];
if($unapprovedthreads_diff > -1)
{
$new_stats['numunapprovedthreads'] = "+{$unapprovedthreads_diff}";
}
else
{
$new_stats['numunapprovedthreads'] = "{$unapprovedthreads_diff}";
}
}

if(array_key_exists('posts', $update_query))
{
$posts_diff = $update_query['posts'] - $forum['posts'];
if($posts_diff > -1)
{
$new_stats['numposts'] = "+{$posts_diff}";
}
else
{
$new_stats['numposts'] = "{$posts_diff}";
}
}

if(array_key_exists('unapprovedposts', $update_query))
{
$unapprovedposts_diff = $update_query['unapprovedposts'] - $forum['unapprovedposts'];
if($unapprovedposts_diff > -1)
{
$new_stats['numunapprovedposts'] = "+{$unapprovedposts_diff}";

		}

		}

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

		else


		{

		{

			$posts_diff = $update_query['posts'] - $forum['posts'];
if($posts_diff > -1)
{
$new_stats['numposts'] = "+{$posts_diff}";
}
else
{
$new_stats['numposts'] = "{$posts_diff}";
}
}

if(array_key_exists('unapprovedposts', $update_query))
{
$unapprovedposts_diff = $update_query['unapprovedposts'] - $forum['unapprovedposts'];
if($unapprovedposts_diff > -1)
{
$new_stats['numunapprovedposts'] = "+{$unapprovedposts_diff}";
}
else
{
$new_stats['numunapprovedposts'] = "{$unapprovedposts_diff}";
}

			$new_stats['numunapprovedposts'] = "{$unapprovedposts_diff}";






















		}

		}

 
	}

if(!empty($new_stats))
{

		update_stats($new_stats);
}

		update_stats($new_stats);
}





	// Update last post info
update_forum_lastpost($fid);

	// Update last post info
update_forum_lastpost($fid);

	



	$cache->update_forums();
}


	$cache->update_forums();
}


Zeile 2025Zeile 2068
 * Update the last post information for a specific forum
*
* @param int The forum ID

 * Update the last post information for a specific forum
*
* @param int The forum ID

 */

 */

function update_forum_lastpost($fid)
{
global $db;

function update_forum_lastpost($fid)
{
global $db;

Zeile 2062Zeile 2105
	global $db;

$update_query = array();

	global $db;

$update_query = array();

	



	$counters = array('replies','unapprovedposts','attachmentcount', 'attachmentcount');

	$counters = array('replies','unapprovedposts','attachmentcount', 'attachmentcount');

	



	// Fetch above counters for this thread
$query = $db->simple_select("threads", implode(",", $counters), "tid='{$tid}'");
$thread = $db->fetch_array($query);

	// Fetch above counters for this thread
$query = $db->simple_select("threads", implode(",", $counters), "tid='{$tid}'");
$thread = $db->fetch_array($query);

	



	foreach($counters as $counter)
{
if(array_key_exists($counter, $changes))

	foreach($counters as $counter)
{
if(array_key_exists($counter, $changes))

Zeile 2082Zeile 2125
			{
$update_query[$counter] = $changes[$counter];
}

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

			



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

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

	}

$db->free_result($query);


	}

$db->free_result($query);


	// Only update if we're actually doing something
if(count($update_query) > 0)
{
$db->update_query("threads", $update_query, "tid='".intval($tid)."'");
}

	// Only update if we're actually doing something
if(count($update_query) > 0)
{
$db->update_query("threads", $update_query, "tid='".intval($tid)."'");
}

	



	unset($update_query, $thread);

update_thread_data($tid);

	unset($update_query, $thread);

update_thread_data($tid);

Zeile 2119Zeile 2162
	if(strpos($thread['closed'], 'moved|') !== false)
{
return false;

	if(strpos($thread['closed'], 'moved|') !== false)
{
return false;

	}

	}


$query = $db->query("
SELECT u.uid, u.username, p.username AS postusername, p.dateline


$query = $db->query("
SELECT u.uid, u.username, p.username AS postusername, p.dateline

Zeile 2130Zeile 2173
		LIMIT 1"
);
$lastpost = $db->fetch_array($query);

		LIMIT 1"
);
$lastpost = $db->fetch_array($query);

	



	$db->free_result($query);

	$db->free_result($query);

	



	$query = $db->query("
SELECT u.uid, u.username, p.username AS postusername, p.dateline
FROM ".TABLE_PREFIX."posts p

	$query = $db->query("
SELECT u.uid, u.username, p.username AS postusername, p.dateline
FROM ".TABLE_PREFIX."posts p

Zeile 2142Zeile 2185
		LIMIT 1
");
$firstpost = $db->fetch_array($query);

		LIMIT 1
");
$firstpost = $db->fetch_array($query);

	



	$db->free_result($query);

if(!$firstpost['username'])
{
$firstpost['username'] = $firstpost['postusername'];

	$db->free_result($query);

if(!$firstpost['username'])
{
$firstpost['username'] = $firstpost['postusername'];

	}


	}


	if(!$lastpost['username'])
{
$lastpost['username'] = $lastpost['postusername'];
}

if(!$lastpost['dateline'])

	if(!$lastpost['username'])
{
$lastpost['username'] = $lastpost['postusername'];
}

if(!$lastpost['dateline'])

	{

	{

		$lastpost['username'] = $firstpost['username'];
$lastpost['uid'] = $firstpost['uid'];
$lastpost['dateline'] = $firstpost['dateline'];
}

		$lastpost['username'] = $firstpost['username'];
$lastpost['uid'] = $firstpost['uid'];
$lastpost['dateline'] = $firstpost['dateline'];
}





	$lastpost['username'] = $db->escape_string($lastpost['username']);
$firstpost['username'] = $db->escape_string($firstpost['username']);


	$lastpost['username'] = $db->escape_string($lastpost['username']);
$firstpost['username'] = $db->escape_string($firstpost['username']);


Zeile 2174Zeile 2217
		'lastposteruid' => intval($lastpost['uid']),
);
$db->update_query("threads", $update_array, "tid='{$tid}'");

		'lastposteruid' => intval($lastpost['uid']),
);
$db->update_query("threads", $update_array, "tid='{$tid}'");

	



	unset($firstpost, $lastpost, $update_array);
}


	unset($firstpost, $lastpost, $update_array);
}


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

$pid = intval($pid);

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

$pid = intval($pid);

 
	$jumpsel['default'] = '';


if($permissions)
{


if($permissions)
{

Zeile 2272Zeile 2316
		$permissioncache = forum_permissions();
}


		$permissioncache = forum_permissions();
}


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

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

	{
foreach($jumpfcache[$pid] as $main)
{

	{
foreach($jumpfcache[$pid] as $main)
{

Zeile 2289Zeile 2333
						$optionselected = "selected=\"selected\"";
$selecteddone = 1;
}

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

					



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

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

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

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

Zeile 2314Zeile 2358
			}

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

			}

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

		}

		}


if($showextras == 0)
{


if($showextras == 0)
{

Zeile 2323Zeile 2367
		else
{
$template = "advanced";

		else
{
$template = "advanced";

 

if(strpos(FORUM_URL, '.html') !== false)
{
$forum_link = "'".str_replace('{fid}', "'+this.options[this.selectedIndex].value+'", FORUM_URL)."'";
}
else
{
$forum_link = "'".str_replace('{fid}', "'+this.options[this.selectedIndex].value", FORUM_URL);
}

		}

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

		}

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

Zeile 2451Zeile 2504
			"editor_color"
);
$editor_language = "var editor_language = {\n";

			"editor_color"
);
$editor_language = "var editor_language = {\n";

		



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

foreach($editor_lang_strings as $key => $lang_string)

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

foreach($editor_lang_strings as $key => $lang_string)

Zeile 2461Zeile 2514
			$string = str_replace("\"", "\\\"", $lang->$lang_string);
$editor_language .= "\t{$js_lang_string}: \"{$string}\"";


			$string = str_replace("\"", "\\\"", $lang->$lang_string);
$editor_language .= "\t{$js_lang_string}: \"{$string}\"";


			if($editor_lang_strings[$key+1])

			if(isset($editor_lang_strings[$key+1]))

			{
$editor_language .= ",";
}

			{
$editor_language .= ",";
}

Zeile 2523Zeile 2576
		{
reset($smiliecache);


		{
reset($smiliecache);


 
			$getmore = '';

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

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

Zeile 2582Zeile 2636

/**
* Builds thread prefixes and returns a selected prefix (or all)


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

 *  @param int The prefix ID (0 to return all)
* @return array The thread prefix's values (or all thread prefixes)
*/

Zeile 2596Zeile 2650
		if($pid > 0 && is_array($prefixes_cache[$pid]))
{
return $prefixes_cache[$pid];

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

		}

return $prefixes_cache;
}

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


		}

return $prefixes_cache;
}

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


	if(!is_array($prefix_cache))
{
// No cache

	if(!is_array($prefix_cache))
{
// No cache

Zeile 2621Zeile 2675
	}

if($pid != 0 && is_array($prefixes_cache[$pid]))

	}

if($pid != 0 && is_array($prefixes_cache[$pid]))

	{

	{

		return $prefixes_cache[$pid];
}
else if(!empty($prefixes_cache))

		return $prefixes_cache[$pid];
}
else if(!empty($prefixes_cache))

Zeile 2634Zeile 2688

/**
* Build the thread prefix selection menu


/**
* Build the thread prefix selection menu

 * 

 *

 *  @param mixed The forum ID (integer ID or string all)
* @param mixed The selected prefix ID (integer ID or string any)
* @return string The thread prefix selection menu

 *  @param mixed The forum ID (integer ID or string all)
* @param mixed The selected prefix ID (integer ID or string any)
* @return string The thread prefix selection menu

Zeile 2642Zeile 2696
function build_prefix_select($fid, $selected_pid=0, $multiple=0)
{
global $cache, $db, $lang, $mybb;

function build_prefix_select($fid, $selected_pid=0, $multiple=0)
{
global $cache, $db, $lang, $mybb;

	



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

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

Zeile 2816Zeile 2870
	if($data['fid'] == '')
{
$fid = 0;

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

	}

	}

	else
{
$fid = $data['fid'];
unset($data['fid']);

	else
{
$fid = $data['fid'];
unset($data['fid']);

	}


	}


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

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

	{

	{

		$tid = $data['tid'];
unset($data['tid']);
}

		$tid = $data['tid'];
unset($data['tid']);
}

Zeile 2863Zeile 2917
function get_reputation($reputation, $uid=0)
{
global $theme;

function get_reputation($reputation, $uid=0)
{
global $theme;

 

$display_reputation = '';


if($uid != 0)
{


if($uid != 0)
{

Zeile 2927Zeile 2983
 */
function get_ip()
{

 */
function get_ip()
{

    global $mybb, $plugins;

	global $mybb, $plugins;





    $ip = 0;

	$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(!preg_match("#^(10|172\.16|192\.168)\.#", $_SERVER['REMOTE_ADDR']))
{
$ip = $_SERVER['REMOTE_ADDR'];
}
















		if(is_array($addresses[0]))












	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 2958Zeile 3014
				}
}
}

				}
}
}

    }

	}





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

if($plugins)
{
$ip_array = array("ip" => &$ip); // Used for backwards compatibility on this hook with the updated run_hooks() function.
$plugins->run_hooks("get_ip", $ip_array);
}

return $ip;

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

if($plugins)
{
$ip_array = array("ip" => &$ip); // Used for backwards compatibility on this hook with the updated run_hooks() function.
$plugins->run_hooks("get_ip", $ip_array);
}

return $ip;

}

/**

}

/**

Zeile 2986Zeile 3042
function get_friendly_size($size)
{
global $lang;

function get_friendly_size($size)
{
global $lang;

	



	if(!is_numeric($size))
{
return $lang->na;
}

	if(!is_numeric($size))
{
return $lang->na;
}

	



	// Yottabyte (1024 Zettabytes)
if($size >= 1208925819614629174706176)
{

	// Yottabyte (1024 Zettabytes)
if($size >= 1208925819614629174706176)
{

Zeile 3093Zeile 3149
			global $change_dir;
$theme['imgdir'] = "{$change_dir}/images";
}

			global $change_dir;
$theme['imgdir'] = "{$change_dir}/images";
}

		



		return "<img src=\"{$theme['imgdir']}/attachtypes/unknown.gif\" border=\"0\" alt=\".{$ext}\" />";

		return "<img src=\"{$theme['imgdir']}/attachtypes/unknown.gif\" border=\"0\" alt=\".{$ext}\" />";

	}

	}

}

}





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

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

Zeile 3106Zeile 3162
 */
function get_unviewable_forums($only_readable_threads=false)
{

 */
function get_unviewable_forums($only_readable_threads=false)
{

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

$pid = intval($pid);

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

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









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


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

	}

if(!is_array($permissioncache))
{

	}

if(!is_array($permissioncache))
{

		$permissioncache = forum_permissions();
}


		$permissioncache = forum_permissions();
}


Zeile 3131Zeile 3180
		if($permissioncache[$forum['fid']])
{
$perms = $permissioncache[$forum['fid']];

		if($permissioncache[$forum['fid']])
{
$perms = $permissioncache[$forum['fid']];

		}
else
{

		}
else
{

			$perms = $mybb->usergroup;
}

			$perms = $mybb->usergroup;
}





		$pwverified = 1;

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

		$pwverified = 1;

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

Zeile 3144Zeile 3193
			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

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

Zeile 3167Zeile 3216
			{
$unviewableforums .= ",";
}

			{
$unviewableforums .= ",";
}





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

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

	}

	}





	return $unviewableforums;




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

}

/**

}

/**

Zeile 3191Zeile 3243

return $format;
}


return $format;
}





/**
* Build the breadcrumb navigation trail from the specified items
*

/**
* Build the breadcrumb navigation trail from the specified items
*

Zeile 3200Zeile 3252
function build_breadcrumb()
{
global $nav, $navbits, $templates, $theme, $lang, $mybb;

function build_breadcrumb()
{
global $nav, $navbits, $templates, $theme, $lang, $mybb;





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

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

	



	$i = 0;

	$i = 0;

	


	$activesep = '';


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

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

Zeile 3215Zeile 3268
				if(isset($navbits[$key+2]))
{
$sep = $navsep;

				if(isset($navbits[$key+2]))
{
$sep = $navsep;

				}

				}

				else
{
$sep = "";
}

				else
{
$sep = "";
}

				



				$multipage = null;
$multipage_dropdown = null;
if(!empty($navbit['multipage']))

				$multipage = null;
$multipage_dropdown = null;
if(!empty($navbit['multipage']))

Zeile 3301Zeile 3354
		{
if($fid == $forumnav['fid'])
{

		{
if($fid == $forumnav['fid'])
{

				if($pforumcache[$forumnav['pid']])

				if(!empty($pforumcache[$forumnav['pid']]))

				{
build_forum_breadcrumb($forumnav['pid']);
}

				{
build_forum_breadcrumb($forumnav['pid']);
}

Zeile 3310Zeile 3363
				// Convert & to &amp;
$navbits[$navsize]['name'] = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $forumnav['name']);


				// Convert & to &amp;
$navbits[$navsize]['name'] = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $forumnav['name']);


				if(IN_ARCHIVE == 1)

				if(defined("IN_ARCHIVE"))

				{
// Set up link to forum in breadcrumb.
if($pforumcache[$fid][$forumnav['pid']]['type'] == 'f' || $pforumcache[$fid][$forumnav['pid']]['type'] == 'c')

				{
// Set up link to forum in breadcrumb.
if($pforumcache[$fid][$forumnav['pid']]['type'] == 'f' || $pforumcache[$fid][$forumnav['pid']]['type'] == 'c')

Zeile 3325Zeile 3378
				elseif(!empty($multipage))
{
$navbits[$navsize]['url'] = get_forum_link($forumnav['fid'], $multipage['current_page']);

				elseif(!empty($multipage))
{
$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 3354Zeile 3407
	unset($GLOBALS['navbits']);
$GLOBALS['navbits'] = $newnav;
}

	unset($GLOBALS['navbits']);
$GLOBALS['navbits'] = $newnav;
}





/**
* Builds a URL to an archive mode page
*

/**
* Builds a URL to an archive mode page
*

Zeile 3365Zeile 3418
function build_archive_link($type, $id="")
{
global $mybb;

function build_archive_link($type, $id="")
{
global $mybb;

	



	// If the server OS is not Windows and not Apache or the PHP is running as a CGI or we have defined ARCHIVE_QUERY_STRINGS, use query strings - DIRECTORY_SEPARATOR checks if running windows

	// If the server OS is not Windows and not Apache or the PHP is running as a CGI or we have defined ARCHIVE_QUERY_STRINGS, use query strings - DIRECTORY_SEPARATOR checks if running windows

	if((DIRECTORY_SEPARATOR == '\\' && is_numeric(stripos($_SERVER['SERVER_SOFTWARE'], "apache")) == false) || is_numeric(stripos(SAPI_NAME, "cgi")) !== false || defined("ARCHIVE_QUERY_STRINGS"))
{
$base_url = $mybb->settings['bburl']."/archive/index.php?";


	//if((DIRECTORY_SEPARATOR == '\\' && is_numeric(stripos($_SERVER['SERVER_SOFTWARE'], "apache")) == false) || is_numeric(stripos(SAPI_NAME, "cgi")) !== false || defined("ARCHIVE_QUERY_STRINGS"))
if($mybb->settings['seourls_archive'] == 1)
{
$base_url = $mybb->settings['bburl']."/archive/index.php/";

	}
else
{

	}
else
{

		$base_url = $mybb->settings['bburl']."/archive/index.php/";

		$base_url = $mybb->settings['bburl']."/archive/index.php?";

	}

switch($type)

	}

switch($type)

Zeile 3399Zeile 3453
 */
function debug_page()
{

 */
function debug_page()
{

	global $db, $debug, $templates, $templatelist, $mybb, $maintimer, $globaltime, $ptimer, $parsetime;

	global $db, $debug, $templates, $templatelist, $mybb, $maintimer, $globaltime, $ptimer, $parsetime, $lang;


$totaltime = $maintimer->totaltime;
$phptime = $maintimer->format($maintimer->totaltime - $db->query_time);


$totaltime = $maintimer->totaltime;
$phptime = $maintimer->format($maintimer->totaltime - $db->query_time);

Zeile 3464Zeile 3518
	echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">".count($templates->cache)." (".intval(count(explode(",", $templatelist)))." Cached / ".intval(count($templates->uncached_templates))." Manually Loaded)</font></td>\n";
echo "</tr>\n";


	echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">".count($templates->cache)." (".intval(count(explode(",", $templatelist)))." Cached / ".intval(count($templates->uncached_templates))." Manually Loaded)</font></td>\n";
echo "</tr>\n";


	if(function_exists("memory_get_usage"))


	$memory_usage = get_memory_usage();
if(!$memory_usage)

	{

	{

		$memory_usage = memory_get_peak_usage(true);
$memory_limit = @ini_get("memory_limit");
echo "<tr>\n";
echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Memory Usage:</font></b></td>\n";
echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">".get_friendly_size($memory_usage)." ({$memory_usage} bytes)</font></td>\n";
echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Memory Limit:</font></b></td>\n";
echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$memory_limit}</font></td>\n";
echo "</tr>\n";

		$memory_usage = $lang->unknown;








	}

	}

 
	else
{
$memory_usage = get_friendly_size($memory_usage)." ({$memory_usage} bytes)";
}
$memory_limit = @ini_get("memory_limit");
echo "<tr>\n";
echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Memory Usage:</font></b></td>\n";
echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$memory_usage}</font></td>\n";
echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Memory Limit:</font></b></td>\n";
echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$memory_limit}</font></td>\n";
echo "</tr>\n";


echo "</table>\n";



echo "</table>\n";


Zeile 3503Zeile 3562
		echo "<br />\n";
}


		echo "<br />\n";
}


	if(count($templates->uncached_templates > 0))

	if(count($templates->uncached_templates) > 0)

	{
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";

Zeile 3601Zeile 3660
	$hsecs = 60*60;
$msecs = 60;


	$hsecs = 60*60;
$msecs = 60;


	if($options['short'] == true)

	if(isset($options['short']))

	{
$lang_year = $lang->year_short;
$lang_years = $lang->years_short;

	{
$lang_year = $lang->year_short;
$lang_years = $lang->years_short;

Zeile 3686Zeile 3745
		$nicetime['days'] = $days.$lang_days;
}


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


	if($options['hours'] !== false)

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

	{
if($hours == 1)
{

	{
if($hours == 1)
{

Zeile 3698Zeile 3757
		}
}


		}
}


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

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

	{
if($minutes == 1)
{
$nicetime['minutes'] = "1".$lang_minute;

	{
if($minutes == 1)
{
$nicetime['minutes'] = "1".$lang_minute;

		}

		}

		else if($minutes > 1)

		else if($minutes > 1)

		{

		{

			$nicetime['minutes'] = $minutes.$lang_minutes;

			$nicetime['minutes'] = $minutes.$lang_minutes;

		}

		}

	}


	}


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

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

	{
if($seconds == 1)
{
$nicetime['seconds'] = "1".$lang_second;

	{
if($seconds == 1)
{
$nicetime['seconds'] = "1".$lang_second;

		}

		}

		else if($seconds > 1)
{
$nicetime['seconds'] = $seconds.$lang_seconds;

		else if($seconds > 1)
{
$nicetime['seconds'] = $seconds.$lang_seconds;

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

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

	}
}

	}
}


/**
* Select an alternating row colour based on the previous call to this function


/**
* Select an alternating row colour based on the previous call to this function

Zeile 3795Zeile 3854
	if($groupslist != $user['additionalgroups'])
{
$db->update_query("users", array('additionalgroups' => $groupslist), "uid='".intval($uid)."'");

	if($groupslist != $user['additionalgroups'])
{
$db->update_query("users", array('additionalgroups' => $groupslist), "uid='".intval($uid)."'");

		return true;
}
else
{

		return true;
}
else
{

		return false;
}
}

		return false;
}
}

Zeile 3810Zeile 3869
 * @param int The user group ID
*/
function leave_usergroup($uid, $leavegroup)

 * @param int The user group ID
*/
function leave_usergroup($uid, $leavegroup)

{

{

	global $db, $mybb, $cache;

	global $db, $mybb, $cache;





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

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

	{

	{

		$user = $mybb->user;

		$user = $mybb->user;

	}

	}

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

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

	}


	}


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

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

Zeile 3841Zeile 3900
			}
}
}

			}
}
}

	



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

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

	}


	}


	$db->write_query("
UPDATE ".TABLE_PREFIX."users
SET additionalgroups='$groupslist' $dispupdate
WHERE uid='".intval($uid)."'
");

	$db->write_query("
UPDATE ".TABLE_PREFIX."users
SET additionalgroups='$groupslist' $dispupdate
WHERE uid='".intval($uid)."'
");

	



	$cache->update_moderators();
}


	$cache->update_moderators();
}


Zeile 3891Zeile 3950
	if($fields == true)
{
global $mybb;

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

		



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

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

		}


		}


		$form_html = "";

		$form_html = "";

		$field_parts = explode('&', $field_parts);


 
		if(!empty($mybb->input))
{
foreach($mybb->input as $name => $value)

		if(!empty($mybb->input))
{
foreach($mybb->input as $name => $value)

Zeile 3908Zeile 3965
				{
continue;
}

				{
continue;
}

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


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

			}
}

			}
}

		



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

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

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

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

		



		if((isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "POST") || (isset($_ENV['REQUEST_METHOD']) && $_ENV['REQUEST_METHOD'] == "POST"))
{
$post_array = array('action', 'fid', 'pid', 'tid', 'uid', 'eid');

		if((isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "POST") || (isset($_ENV['REQUEST_METHOD']) && $_ENV['REQUEST_METHOD'] == "POST"))
{
$post_array = array('action', 'fid', 'pid', 'tid', 'uid', 'eid');

	



			foreach($post_array as $var)
{
if(isset($_POST[$var]))

			foreach($post_array as $var)
{
if(isset($_POST[$var]))

Zeile 3937Zeile 3994
					$addloc[] = urlencode($var).'='.urlencode($_POST[$var]);
}
}

					$addloc[] = urlencode($var).'='.urlencode($_POST[$var]);
}
}

	



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

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

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

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

		}


		}


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

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

Zeile 3974Zeile 4031
function build_theme_select($name, $selected="", $tid=0, $depth="", $usergroup_override=false)
{
global $db, $themeselect, $tcache, $lang, $mybb, $limit;

function build_theme_select($name, $selected="", $tid=0, $depth="", $usergroup_override=false)
{
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";

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

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





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

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

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

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

		{

		{

			$in_groups = explode(",", $mybb->user['additionalgroups']);
}
$in_groups[] = $mybb->user['usergroup'];

			$in_groups = explode(",", $mybb->user['additionalgroups']);
}
$in_groups[] = $mybb->user['usergroup'];

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

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

			{

			{

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

Zeile 4018Zeile 4075
						$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)


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

Zeile 4030Zeile 4087
				}

if($theme['pid'] != 0)

				}

if($theme['pid'] != 0)

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

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

					$depthit = $depth."--";

					$depthit = $depth."--";

				}

				}


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


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

Zeile 4041Zeile 4098
				}
}
}

				}
}
}

	}

	}


if($tid == 1)
{


if($tid == 1)
{

Zeile 4084Zeile 4141
	if(is_int($number))
{
return number_format($number, 0, $mybb->settings['decpoint'], $mybb->settings['thousandssep']);

	if(is_int($number))
{
return number_format($number, 0, $mybb->settings['decpoint'], $mybb->settings['thousandssep']);

	}

	}

	else
{
$parts = explode('.', $number);

	else
{
$parts = explode('.', $number);

Zeile 4108Zeile 4165
	static $charset;
static $use_mb;
static $use_iconv;

	static $charset;
static $use_mb;
static $use_iconv;

	



	if(!isset($charset))

	if(!isset($charset))

	{

	{

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

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

	}


	}


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

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

	



	if(!isset($use_iconv))

	if(!isset($use_iconv))

	{

	{

		$use_iconv = function_exists("iconv");

		$use_iconv = function_exists("iconv");

	}


	}


	if(!isset($use_mb))
{
$use_mb = function_exists("mb_convert_encoding");
}

	if(!isset($use_mb))
{
$use_mb = function_exists("mb_convert_encoding");
}

	



	if($use_iconv || $use_mb)

	if($use_iconv || $use_mb)

	{
if($to)
{

	{
if($to)
{

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

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

Zeile 4174Zeile 4231
 * @return string The word wraped string
*/
function my_wordwrap($message)

 * @return string The word wraped string
*/
function my_wordwrap($message)

{
global $mybb;


{
global $mybb;


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

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

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

		



		return $new_message;
}


		return $new_message;
}


Zeile 4294Zeile 4351
		$lang->month_11,
$lang->month_12
);

		$lang->month_11,
$lang->month_12
);

	




// This needs to be in this specific order
$find = array(


// This needs to be in this specific order
$find = array(

Zeile 4325Zeile 4382

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


$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 4338Zeile 4395
		$wd,
($bm == 9 ? my_substr($bmonth[$bm-1], 0, 4) : my_substr($bmonth[$bm-1], 0, 3)),
);

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

	



	// Do we have the full month in our output?
// If so there's no need for the short month
if(strpos($display, 'F') !== false)

	// Do we have the full month in our output?
// If so there's no need for the short month
if(strpos($display, 'F') !== false)

Zeile 4346Zeile 4403
		array_pop($find);
array_pop($replace);
}

		array_pop($find);
array_pop($replace);
}

	



	return str_replace($find, $replace, $display);
}


	return str_replace($find, $replace, $display);
}


Zeile 4409Zeile 4466
 */
function my_strlen($string)
{

 */
function my_strlen($string)
{

    global $lang;

$string = preg_replace("#&\#([0-9]+);#", "-", $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);





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

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

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







	$string = trim($string);


	$string = trim($string);


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

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





    return $string_length;

	return $string_length;

}

/**

}

/**

Zeile 4543Zeile 4600
	else
{
$string = strtoupper($string);

	else
{
$string = strtoupper($string);

	}


	}


	return $string;
}


	return $string;
}


Zeile 4555Zeile 4612
 * @return int The un-htmlentitied' string.
*/
function unhtmlentities($string)

 * @return int The un-htmlentitied' string.
*/
function unhtmlentities($string)

{	

{

	// Replace numeric entities

	// Replace numeric entities

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


	$string = preg_replace_callback('~&#x([0-9a-f]+);~i', create_function('$matches', 'return unichr(hexdec($matches[1]));'), $string);
$string = preg_replace_callback('~&#([0-9]+);~', create_function('$matches', 'return unichr($matches[1]);'), $string);


	// Replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);

	// Replace literal entities
$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 4575Zeile 4632
 */
function unichr($c)
{

 */
function unichr($c)
{

    if($c <= 0x7F)

	if($c <= 0x7F)

	{

	{

        return chr($c);
}

		return chr($c);
}

	else if($c <= 0x7FF)
{

	else if($c <= 0x7FF)
{

        return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
}

		return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
}

	else if($c <= 0xFFFF)
{

	else if($c <= 0xFFFF)
{

        return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);
}

		return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);
}

	else if($c <= 0x10FFFF)

	else if($c <= 0x10FFFF)

	{
return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
. chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);
}

	{
return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
. chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);
}

	else
{

	else
{

        return false;
}
}

/**

		return false;
}
}

/**

 * Get the event poster.
*
* @param array The event data array.
* @return string The link to the event poster.
*/
function get_event_poster($event)

 * Get the event poster.
*
* @param array The event data array.
* @return string The link to the event poster.
*/
function get_event_poster($event)

{

{

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

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

Zeile 4622Zeile 4679
function get_event_date($event)
{
global $mybb;

function get_event_date($event)
{
global $mybb;

	



	$event_date = explode("-", $event['date']);
$event_date = mktime(0, 0, 0, $event_date[1], $event_date[0], $event_date[2]);
$event_date = my_date($mybb->settings['dateformat'], $event_date);

	$event_date = explode("-", $event['date']);
$event_date = mktime(0, 0, 0, $event_date[1], $event_date[0], $event_date[2]);
$event_date = my_date($mybb->settings['dateformat'], $event_date);

Zeile 4689Zeile 4746
		{
$onclick = " onclick=\"{$onclick}\"";
}

		{
$onclick = " onclick=\"{$onclick}\"";
}

		



		return "<a href=\"{$mybb->settings['bburl']}/".get_profile_link($uid)."\"{$target}{$onclick}>{$username}</a>";
}
}

		return "<a href=\"{$mybb->settings['bburl']}/".get_profile_link($uid)."\"{$target}{$onclick}>{$username}</a>";
}
}

Zeile 4707Zeile 4764
	{
$link = str_replace("{fid}", $fid, FORUM_URL_PAGED);
$link = str_replace("{page}", $page, $link);

	{
$link = str_replace("{fid}", $fid, FORUM_URL_PAGED);
$link = str_replace("{page}", $page, $link);

		return htmlspecialchars_uni($link);

		return htmlspecialchars_uni($link);

	}
else
{

	}
else
{

Zeile 4737Zeile 4794
		{
$link = THREAD_URL_PAGED;
}

		{
$link = THREAD_URL_PAGED;
}

		$link = str_replace("{tid}", $tid, $link);		

		$link = str_replace("{tid}", $tid, $link);

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

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

Zeile 4869Zeile 4926
	{
return $user_cache[$uid];
}

	{
return $user_cache[$uid];
}

	else

	elseif(($uid > 0))

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

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





		return $user_cache[$uid];

		return $user_cache[$uid];

	}
}

/**


	}
return array();
}

/**

 * Get the forum of a specific forum id.
*
* @param int The forum id of the forum.

 * Get the forum of a specific forum id.
*
* @param int The forum id of the forum.

Zeile 4896Zeile 4954
	}

if(!$forum_cache[$fid])

	}

if(!$forum_cache[$fid])

	{

	{

		return false;
}


		return false;
}


Zeile 4904Zeile 4962
	{
$parents = explode(",", $forum_cache[$fid]['parentlist']);
if(is_array($parents))

	{
$parents = explode(",", $forum_cache[$fid]['parentlist']);
if(is_array($parents))

		{

		{

			foreach($parents as $parent)
{
if($forum_cache[$parent]['active'] == 0)

			foreach($parents as $parent)
{
if($forum_cache[$parent]['active'] == 0)

Zeile 4913Zeile 4971
				}
}
}

				}
}
}

	}

	}


return $forum_cache[$fid];
}


return $forum_cache[$fid];
}

Zeile 4931Zeile 4989
	static $thread_cache;

if(isset($thread_cache[$tid]) && !$recache)

	static $thread_cache;

if(isset($thread_cache[$tid]) && !$recache)

	{

	{

		return $thread_cache[$tid];
}
else

		return $thread_cache[$tid];
}
else

Zeile 4940Zeile 4998
		$thread = $db->fetch_array($query);

if($thread)

		$thread = $db->fetch_array($query);

if($thread)

		{

		{

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

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

		}

		}

		else
{
$thread_cache[$tid] = false;

		else
{
$thread_cache[$tid] = false;

			return false;
}

			return false;
}

	}
}


	}
}


Zeile 4957Zeile 5015
 *
* @param int The post id of the post.
* @return string The database row of the post.

 *
* @param int The post id of the post.
* @return string The database row of the post.

 */

 */

function get_post($pid)
{
global $db;

function get_post($pid)
{
global $db;

Zeile 4966Zeile 5024
	if(isset($post_cache[$pid]))
{
return $post_cache[$pid];

	if(isset($post_cache[$pid]))
{
return $post_cache[$pid];

	}

	}

	else
{
$query = $db->simple_select("posts", "*", "pid='".intval($pid)."'");

	else
{
$query = $db->simple_select("posts", "*", "pid='".intval($pid)."'");

Zeile 4984Zeile 5042
		}
}
}

		}
}
}





/**
* Get inactivate forums.
*

/**
* Get inactivate forums.
*

Zeile 4993Zeile 5051
function get_inactive_forums()
{
global $forum_cache, $cache, $inactiveforums;

function get_inactive_forums()
{
global $forum_cache, $cache, $inactiveforums;





	if(!$forum_cache)
{
cache_forums();

	if(!$forum_cache)
{
cache_forums();

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

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

				}
}

				}
}

		}

		}

	}

	}

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

return $inactiveforums;

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

return $inactiveforums;

Zeile 5030Zeile 5088
function login_attempt_check($fatal = true)
{
global $mybb, $lang, $session, $db;

function login_attempt_check($fatal = true)
{
global $mybb, $lang, $session, $db;





	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

	// Use cookie if possible, otherwise use session

	// Session stops user clearing cookies to bypass the login
// Also use the greater of the two numbers present, stops people using scripts with altered cookie data to stay the same
$cookielogins = intval($mybb->cookies['loginattempts']);
$cookietime = $mybb->cookies['failedlogin'];

if(empty($cookielogins) || $cookielogins < $session->logins)
{
$loginattempts = $session->logins;
}
else
{
$loginattempts = $cookielogins;
}

	// Find better solution to prevent clearing cookies
$loginattempts = 0;
$failedlogin = 0;















	if(empty($cookietime) || $cookietime < $session->failedlogin)

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

	{

	{

		$failedlogin = $session->failedlogin;

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

	}

	}

	else



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

	{

	{

		$failedlogin = $cookietime;

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

	}

// Work out if the user has had more than the allowed number of login attempts

	}

// Work out if the user has had more than the allowed number of login attempts

Zeile 5150Zeile 5199
function email_already_in_use($email, $uid="")
{
global $db;

function email_already_in_use($email, $uid="")
{
global $db;

	



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

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

	



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

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

	



	return false;
}

/*
* DEPRECATED! ONLY INCLUDED FOR COMPATIBILITY PURPOSES.

	return false;
}

/*
* DEPRECATED! ONLY INCLUDED FOR COMPATIBILITY PURPOSES.

 */

 */

function rebuildsettings()
{
rebuild_settings();

function rebuildsettings()
{
rebuild_settings();

Zeile 5185Zeile 5234
	if(!file_exists(MYBB_ROOT."inc/settings.php"))
{
$mode = "x";

	if(!file_exists(MYBB_ROOT."inc/settings.php"))
{
$mode = "x";

	}
else
{
$mode = "w";
}

	}
else
{
$mode = "w";
}


$options = array(
"order_by" => "title",
"order_dir" => "ASC"
);
$query = $db->simple_select("settings", "value, name", "", $options);


$options = array(
"order_by" => "title",
"order_dir" => "ASC"
);
$query = $db->simple_select("settings", "value, name", "", $options);





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

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

	



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

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

Zeile 5211Zeile 5260

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


$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 5225Zeile 5274
	if($mybb->settings['minsearchword'] < 1)
{
$mybb->settings['minsearchword'] = 3;

	if($mybb->settings['minsearchword'] < 1)
{
$mybb->settings['minsearchword'] = 3;

	} 

	}


if(is_array($terms))
{


if(is_array($terms))
{

Zeile 5298Zeile 5347
	{
return false;
}

	{
return false;
}

	



	// Sort the word array by length. Largest terms go first and work their way down to the smallest term.
// This resolves problems like "test tes" where "tes" will be highlighted first, then "test" can't be highlighted because of the changed html
usort($words, create_function('$a,$b', 'return strlen($b) - strlen($a);'));

	// Sort the word array by length. Largest terms go first and work their way down to the smallest term.
// This resolves problems like "test tes" where "tes" will be highlighted first, then "test" can't be highlighted because of the changed html
usort($words, create_function('$a,$b', 'return strlen($b) - strlen($a);'));





	// Loop through our words to build the PREG compatible strings
foreach($words as $word)
{
$word = trim($word);

	// Loop through our words to build the PREG compatible strings
foreach($words as $word)
{
$word = trim($word);





		$word = my_strtolower($word);

		$word = my_strtolower($word);

	



		// Special boolean operators should be stripped
if($word == "" || $word == "or" || $word == "not" || $word == "and")
{

		// Special boolean operators should be stripped
if($word == "" || $word == "or" || $word == "not" || $word == "and")
{

Zeile 5337Zeile 5386

if($src < 0)
{


if($src < 0)
{

  		return false;
}

		return false;
}

	elseif($src <= 0x007f)
{
$dest .= chr($src);

	elseif($src <= 0x007f)
{
$dest .= chr($src);

Zeile 5411Zeile 5460
	global $cache, $db;

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

	global $cache, $db;

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

	



	if($banned_cache === false)
{
// Failed to read cache, see if we can rebuild it
$cache->update_bannedemails();
$banned_cache = $cache->read("bannedemails");

	if($banned_cache === false)
{
// Failed to read cache, see if we can rebuild it
$cache->update_bannedemails();
$banned_cache = $cache->read("bannedemails");

	}


	}


	if(is_array($banned_cache) && !empty($banned_cache))
{
foreach($banned_cache as $banned_email)

	if(is_array($banned_cache) && !empty($banned_cache))
{
foreach($banned_cache as $banned_email)

Zeile 5435Zeile 5484
				}
return true;
}

				}
return true;
}

		}
}


		}
}


	// Still here - good email
return false;
}

	// Still here - good email
return false;
}

Zeile 5452Zeile 5501
function is_banned_ip($ip_address, $update_lastuse=false)
{
global $db, $cache;

function is_banned_ip($ip_address, $update_lastuse=false)
{
global $db, $cache;

	



	$banned_ips = $cache->read("bannedips");
if(!is_array($banned_ips))
{
return false;
}

	$banned_ips = $cache->read("bannedips");
if(!is_array($banned_ips))
{
return false;
}

	



	foreach($banned_ips as $banned_ip)
{
if(!$banned_ip['filter'])
{
continue;
}

	foreach($banned_ips as $banned_ip)
{
if(!$banned_ip['filter'])
{
continue;
}

		



		// Make regular expression * match
$banned_ip['filter'] = str_replace('\*', '(.*)', preg_quote($banned_ip['filter'], '#'));
if(preg_match("#^{$banned_ip['filter']}$#i", $ip_address))

		// Make regular expression * match
$banned_ip['filter'] = str_replace('\*', '(.*)', preg_quote($banned_ip['filter'], '#'));
if(preg_match("#^{$banned_ip['filter']}$#i", $ip_address))

Zeile 5583Zeile 5632
		}
$post_body = ltrim($post_body, '&');
}

		}
$post_body = ltrim($post_body, '&');
}

	



	if(function_exists("curl_init"))
{
$ch = curl_init();

	if(function_exists("curl_init"))
{
$ch = curl_init();

Zeile 5591Zeile 5640
		curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		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 5600Zeile 5649
		curl_close($ch);
return $data;
}

		curl_close($ch);
return $data;
}

 	else if(function_exists("fsockopen"))

	else if(function_exists("fsockopen"))

	{
$url = @parse_url($url);
if(!$url['host'])

	{
$url = @parse_url($url);
if(!$url['host'])

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

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

		{

		{

			$url['port'] = 80;

			$url['port'] = 80;

		}

		}

		if(!$url['path'])
{
$url['path'] = "/";
}
if($url['query'])

		if(!$url['path'])
{
$url['path'] = "/";
}
if($url['query'])

		{

		{

			$url['path'] .= "?{$url['query']}";
}
$fp = @fsockopen($url['host'], $url['port'], $error_no, $error, 10);

			$url['path'] .= "?{$url['query']}";
}
$fp = @fsockopen($url['host'], $url['port'], $error_no, $error, 10);

Zeile 5624Zeile 5673
		if(!$fp)
{
return false;

		if(!$fp)
{
return false;

		}

		}

		$headers = array();
if(!empty($post_body))
{
$headers[] = "POST {$url['path']} HTTP/1.0";
$headers[] = "Content-Length: ".strlen($post_body);
$headers[] = "Content-Type: application/x-www-form-urlencoded";

		$headers = array();
if(!empty($post_body))
{
$headers[] = "POST {$url['path']} HTTP/1.0";
$headers[] = "Content-Length: ".strlen($post_body);
$headers[] = "Content-Type: application/x-www-form-urlencoded";

		}
else

		}
else

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

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

		



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

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

		



		if(!empty($post_body))

		if(!empty($post_body))

		{

		{

			$headers[] = $post_body;

			$headers[] = $post_body;

		}

		}

		else
{
// If we have no post body, we need to add an empty element to make sure we've got \r\n\r\n before the (non-existent) body starts
$headers[] = '';
}

		else
{
// If we have no post body, we need to add an empty element to make sure we've got \r\n\r\n before the (non-existent) body starts
$headers[] = '';
}

		
$headers = implode("\r\n", $headers);


$headers = implode("\r\n", $headers);

		if(!@fwrite($fp, $headers))
{
return false;

		if(!@fwrite($fp, $headers))
{
return false;

Zeile 5683Zeile 5732
function is_super_admin($uid)
{
global $mybb;

function is_super_admin($uid)
{
global $mybb;

	



	$mybb->config['super_admins'] = str_replace(" ", "", $mybb->config['super_admins']);
if(my_strpos(",{$mybb->config['super_admins']},", ",{$uid},") === false)

	$mybb->config['super_admins'] = str_replace(" ", "", $mybb->config['super_admins']);
if(my_strpos(",{$mybb->config['super_admins']},", ",{$uid},") === false)

	{

	{

		return false;

		return false;

	}

	}

	else
{
return true;

	else
{
return true;

	}
}


	}
}


/**
* Split a string based on the specified delimeter, ignoring said delimeter in escaped strings.
* Ex: the "quick brown fox" jumped, could return 1 => the, 2 => quick brown fox, 3 => jumped

/**
* Split a string based on the specified delimeter, ignoring said delimeter in escaped strings.
* Ex: the "quick brown fox" jumped, could return 1 => the, 2 => quick brown fox, 3 => jumped

Zeile 5705Zeile 5754
 * @return array Array of split string
*/
function escaped_explode($delimeter, $string, $escape="")

 * @return array Array of split string
*/
function escaped_explode($delimeter, $string, $escape="")

{

{

	$strings = array();
$original = $string;
$in_escape = false;

	$strings = array();
$original = $string;
$in_escape = false;

Zeile 5728Zeile 5777
	else
{
$quoted_strings = array($string);

	else
{
$quoted_strings = array($string);

	}

	}

	foreach($quoted_strings as $string)
{

	foreach($quoted_strings as $string)
{

		if($string != "") 

		if($string != "")

		{
if($in_escape)
{

		{
if($in_escape)
{

Zeile 5752Zeile 5801
	if(!count($strings))
{
return $original;

	if(!count($strings))
{
return $original;

	}

	}

	return $strings;
}


	return $strings;
}


Zeile 5769Zeile 5818

if($ip == "*")
{


if($ip == "*")
{

		return array(ip2long('0.0.0.0'), ip2long('255.255.255.255'));

		return array(my_ip2long('128.0.0.0'), my_ip2long('127.255.255.255'));

	}

if(strpos($ip, ".*") === false)

	}

if(strpos($ip, ".*") === false)

Zeile 5777Zeile 5826
		$ip = str_replace("*", "", $ip);
if(count($ip_bits) == 4)
{

		$ip = str_replace("*", "", $ip);
if(count($ip_bits) == 4)
{

			return ip2long($ip);
}
else
{
return array(ip2long($ip.".0"), ip2long($ip.".255"));

			return my_ip2long($ip);
}
else
{
return array(my_ip2long($ip.".0"), my_ip2long($ip.".255"));

		}
}
// Wildcard based IP provided

		}
}
// Wildcard based IP provided

Zeile 5802Zeile 5851
			}
$sep = ".";
}

			}
$sep = ".";
}

		return array(ip2long($ip_string1), ip2long($ip_string2));
}
}

/**

		return array(my_ip2long($ip_string1), my_ip2long($ip_string2));
}
}

/**

 * Fetch a list of ban times for a user account.
*
* @return array Array of ban times

 * Fetch a list of ban times for a user account.
*
* @return array Array of ban times

Zeile 5850Zeile 5899
 * @return int The UNIX timestamp when the ban will be lifted
*/
function ban_date2timestamp($date, $stamp=0)

 * @return int The UNIX timestamp when the ban will be lifted
*/
function ban_date2timestamp($date, $stamp=0)

{

{

	if($stamp == 0)
{
$stamp = TIME_NOW;

	if($stamp == 0)
{
$stamp = TIME_NOW;

Zeile 5871Zeile 5920
function expire_warnings()
{
global $db;

function expire_warnings()
{
global $db;

	



	$users = array();

	$users = array();

	



	$query = $db->query("
SELECT w.wid, w.uid, w.points, u.warningpoints
FROM ".TABLE_PREFIX."warnings w

	$query = $db->query("
SELECT w.wid, w.uid, w.points, u.warningpoints
FROM ".TABLE_PREFIX."warnings w

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

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

		



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

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

		{

		{

			$users[$warning['uid']] -= $warning['points'];

			$users[$warning['uid']] -= $warning['points'];

		}

		}

		else
{
$users[$warning['uid']] = $warning['warningpoints']-$warning['points'];
}
}

		else
{
$users[$warning['uid']] = $warning['warningpoints']-$warning['points'];
}
}

	



	foreach($users as $uid => $warningpoints)
{
if($warningpoints < 0)
{
$warningpoints = 0;
}

	foreach($users as $uid => $warningpoints)
{
if($warningpoints < 0)
{
$warningpoints = 0;
}

		



		$updated_user = array(
"warningpoints" => intval($warningpoints)
);

		$updated_user = array(
"warningpoints" => intval($warningpoints)
);

Zeile 5925Zeile 5974
		return false;
}
$old_umask = umask(0);

		return false;
}
$old_umask = umask(0);

	



	// We convert the octal string to a decimal number because passing a octal string doesn't work with chmod
// and type casting subsequently removes the prepended 0 which is needed for octal numbers
$result = chmod($file, octdec($mode));

	// We convert the octal string to a decimal number because passing a octal string doesn't work with chmod
// and type casting subsequently removes the prepended 0 which is needed for octal numbers
$result = chmod($file, octdec($mode));

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

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

	



	if(!isset($orig_dir))

	if(!isset($orig_dir))

	{

	{

		$orig_dir = $path;
}

		$orig_dir = $path;
}

	
if(@is_dir($path) && !@is_link($path))
{
if($dh = @opendir($path))
{
while(($file = @readdir($dh)) !== false)
{
if($file == '.' || $file == '..' || $file == '.svn' || in_array($path.'/'.$file, $ignore) || !my_rmdir_recursive($path.'/'.$file))
{
continue;
}
}
@closedir($dh);
}



if(@is_dir($path) && !@is_link($path))
{
if($dh = @opendir($path))
{
while(($file = @readdir($dh)) !== false)
{
if($file == '.' || $file == '..' || $file == '.svn' || in_array($path.'/'.$file, $ignore) || !my_rmdir_recursive($path.'/'.$file))
{
continue;
}
}
@closedir($dh);
}


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

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

		
return @rmdir($path);
}

return @unlink($path);


return @rmdir($path);
}

return @unlink($path);

}

/**

}

/**

Zeile 5987Zeile 6036
	{
$count += count($array2);
}

	{
$count += count($array2);
}

	



	return $count;
}


	return $count;
}


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

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

		



		if(!$ip_long)
{
return 0;
}

		if(!$ip_long)
{
return 0;
}

	}


	}


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

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

	}


	}


	return $ip_long;
}


	return $ip_long;
}


Zeile 6027Zeile 6076
 * @return string IP in IPv4 format
*/
function my_long2ip($long)

 * @return string IP in IPv4 format
*/
function my_long2ip($long)

{

{

	// On 64-bit machines is_int will return true. On 32-bit it will return false
if($long < 0 && is_int(2147483648))
{

	// On 64-bit machines is_int will return true. On 32-bit it will return false
if($long < 0 && is_int(2147483648))
{

Zeile 6036Zeile 6085
	}
return long2ip($long);
}

	}
return long2ip($long);
}







/**
* Processes a checksum list on MyBB files and returns a result set
*

/**
* Processes a checksum list on MyBB files and returns a result set
*

Zeile 6047Zeile 6096
function verify_files($path=MYBB_ROOT, $count=0)
{
global $mybb, $checksums, $bad_verify_files;

function verify_files($path=MYBB_ROOT, $count=0)
{
global $mybb, $checksums, $bad_verify_files;

	



	// We don't need to check these types of files
$ignore = array(".", "..", ".svn", "config.php", "settings.php", "Thumb.db", "config.default.php", "lock", "htaccess.txt", "logo.gif");
$ignore_ext = array("attach");

	// We don't need to check these types of files
$ignore = array(".", "..", ".svn", "config.php", "settings.php", "Thumb.db", "config.default.php", "lock", "htaccess.txt", "logo.gif");
$ignore_ext = array("attach");

	



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

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

	{

	{

		$path = substr($path, 0, -1);

		$path = substr($path, 0, -1);

	}


	}


	if(!is_array($bad_verify_files))

	if(!is_array($bad_verify_files))

	{

	{

		$bad_verify_files = array();
}

		$bad_verify_files = array();
}

	



	// Make sure that we're in a directory and it's not a symbolic link

	// Make sure that we're in a directory and it's not a symbolic link

    if(@is_dir($path) && !@is_link($path))
{
if($dh = @opendir($path))
{

	if(@is_dir($path) && !@is_link($path))
{
if($dh = @opendir($path))
{

			// Loop through all the files/directories in this directory

			// Loop through all the files/directories in this directory

            while(($file = @readdir($dh)) !== false)
{

			while(($file = @readdir($dh)) !== false)
{

				if(in_array($file, $ignore) || in_array(get_extension($file), $ignore_ext))

				if(in_array($file, $ignore) || in_array(get_extension($file), $ignore_ext))

				{
continue;

				{
continue;

				}

				}

				



				// Recurse through the directory tree
if(is_dir($path."/".$file))
{
verify_files($path."/".$file, ($count+1));
continue;

				// Recurse through the directory tree
if(is_dir($path."/".$file))
{
verify_files($path."/".$file, ($count+1));
continue;

				}


				}


				// We only need the last part of the path (from the MyBB directory to the file. i.e. inc/functions.php)
$file_path = ".".str_replace(substr(MYBB_ROOT, 0, -1), "", $path)."/".$file;

				// We only need the last part of the path (from the MyBB directory to the file. i.e. inc/functions.php)
$file_path = ".".str_replace(substr(MYBB_ROOT, 0, -1), "", $path)."/".$file;

				



				// Does this file even exist in our official list? Perhaps it's a plugin
if(array_key_exists($file_path, $checksums))
{

				// Does this file even exist in our official list? Perhaps it's a plugin
if(array_key_exists($file_path, $checksums))
{

Zeile 6096Zeile 6145
						$contents .= fread($handle, 8192);
}
fclose($handle);

						$contents .= fread($handle, 8192);
}
fclose($handle);

					



					$md5 = md5($contents);

					$md5 = md5($contents);

					



					// Does it match any of our hashes (unix/windows new lines taken into consideration with the hashes)
if(!in_array($md5, $checksums[$file_path]))

					// Does it match any of our hashes (unix/windows new lines taken into consideration with the hashes)
if(!in_array($md5, $checksums[$file_path]))

					{						

					{

						$bad_verify_files[] = array("status" => "changed", "path" => $file_path);
}
}
unset($checksums[$file_path]);

						$bad_verify_files[] = array("status" => "changed", "path" => $file_path);
}
}
unset($checksums[$file_path]);

            }
@closedir($dh);
}
}

if($count == 0)

			}
@closedir($dh);
}
}

if($count == 0)

	{
if(!empty($checksums))
{

	{
if(!empty($checksums))
{

Zeile 6123Zeile 6172
				}
$bad_verify_files[] = array("status" => "missing", "path" => $file_path);
}

				}
$bad_verify_files[] = array("status" => "missing", "path" => $file_path);
}

		}

		}

	}

	}

	



	// uh oh
if($count == 0)
{

	// uh oh
if($count == 0)
{

Zeile 6160Zeile 6209
function secure_seed_rng($count=8)
{
$output = '';

function secure_seed_rng($count=8)
{
$output = '';

	



	// Try the unix/linux method
if(@is_readable('/dev/urandom') && ($handle = @fopen('/dev/urandom', 'rb')))

	// Try the unix/linux method
if(@is_readable('/dev/urandom') && ($handle = @fopen('/dev/urandom', 'rb')))

	{

	{

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

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

	



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

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

		



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

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

		



		for($i = 0; $i < $count; $i += 16)
{
$unique_state = md5(microtime().$unique_state);
$output .= pack('H*', md5($unique_state));
}
}

		for($i = 0; $i < $count; $i += 16)
{
$unique_state = md5(microtime().$unique_state);
$output .= pack('H*', md5($unique_state));
}
}

	



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

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

	



	return $output;
}

	return $output;
}





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

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

 * @param int Optional lowest value to be returned (default: 0) 
* @param int Optional highest value to be returned (default: mt_getrandmax())

 * @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 equivalent of a secure hexadecimal seed
*/

 * @param boolean True forces it to reseed the RNG first
* @return int An integer equivalent of a secure hexadecimal seed
*/

Zeile 6208Zeile 6257
		$seeded = true;

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

		$seeded = true;

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

		



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

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

		}
}

		}
}


if($min !== null && $max !== null)
{
$distance = $max - $min;
if ($distance > 0)


if($min !== null && $max !== null)
{
$distance = $max - $min;
if ($distance > 0)

		{

		{

			return $min + (int)((float)($distance + 1) * (float)(mt_rand() ^ $obfuscator) / (mt_getrandmax() + 1));
}
else

			return $min + (int)((float)($distance + 1) * (float)(mt_rand() ^ $obfuscator) / (mt_getrandmax() + 1));
}
else

Zeile 6252Zeile 6301
		0x0D => 1,
0x0B => 1,
0xAD => 1,

		0x0D => 1,
0x0B => 1,
0xAD => 1,

		0xC2 => array(0xA0 => 1,
0xAD => 1,
0xBF => 1,
0x81 => 1,
0x8D => 1,
0x90 => 1,
0x9D => 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}

		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}

Zeile 6270Zeile 6319
					  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} to \x{FFFB}
);

	



	$hex_chrs_rev = array(
0x20 => 1,
0x09 => 1,

	$hex_chrs_rev = array(
0x20 => 1,
0x09 => 1,

Zeile 6316Zeile 6365
		0xBA => array(0xBF => array(0xEF => 1)), // \x{FFFA}
0xBB => array(0xBF => array(0xEF => 1)), // \x{FFFB}
);

		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
{
// Check to see if we have matched a first character in our utf-16 array
$offset = match_sequence($string, $hex_chrs);

	// 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
$offset = match_sequence($string, $hex_chrs);

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

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

	while(++$i);

	while(++$i);

	



	// Start from the end and work our way in
$string = strrev($string);
do

	// Start from the end and work our way in
$string = strrev($string);
do

Zeile 6341Zeile 6390
		{
// If not, then we must have a "good" character and we don't need to do anymore processing
break;

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

		}

		}

		$string = substr($string, $offset);
}
while(++$i);
$string = strrev($string);

		$string = substr($string, $offset);
}
while(++$i);
$string = strrev($string);

	



	if($charlist !== false)
{
$string = trim($string, $charlist);

	if($charlist !== false)
{
$string = trim($string, $charlist);

Zeile 6355Zeile 6404
	{
$string = trim($string);
}

	{
$string = trim($string);
}

	



	return $string;
}

	return $string;
}





function match_sequence($string, $array, $i=0, $n=0)
{
if($string === "")
{
return 0;
}

function match_sequence($string, $array, $i=0, $n=0)
{
if($string === "")
{
return 0;
}

	



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

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

Zeile 6378Zeile 6427
		}
return $n;
}

		}
return $n;
}

	



	return 0;

	return 0;

}

}


/**
* Obtain the version of GD installed.


/**
* Obtain the version of GD installed.

Zeile 6390Zeile 6439
function gd_version()
{
static $gd_version;

function gd_version()
{
static $gd_version;

	



	if($gd_version)

	if($gd_version)

	{

	{

		return $gd_version;

		return $gd_version;

	}

	}

	if(!extension_loaded('gd'))

	if(!extension_loaded('gd'))

	{

	{

		return;

		return;

	}


	}


	if(function_exists("gd_info"))

	if(function_exists("gd_info"))

	{

	{

		$gd_info = gd_info();

		$gd_info = gd_info();

   		preg_match('/\d/', $gd_info['GD Version'], $gd);
$gd_version = $gd[0];
}
else
{

		preg_match('/\d/', $gd_info['GD Version'], $gd);
$gd_version = $gd[0];
}
else
{

		ob_start();
phpinfo(8);
$info = ob_get_contents();

		ob_start();
phpinfo(8);
$info = ob_get_contents();

Zeile 6416Zeile 6465
		preg_match('/\d/', $info, $gd);
$gd_version = $gd[0];
}

		preg_match('/\d/', $info, $gd);
$gd_version = $gd[0];
}

	



	return $gd_version;

	return $gd_version;

}

}





 
/**
* Validates an UTF-8 string.
*
* @param string The string to be checked
* @param boolean Allow 4 byte UTF-8 characters?
* @param boolean Return the cleaned string?
* @return string/boolean Cleaned string or boolean
*/
function validate_utf8_string($input, $allow_mb4=true, $return=true)
{
// Valid UTF-8 sequence?
if(!preg_match('##u', $input))
{
$string = '';
$len = strlen($input);
for($i = 0; $i < $len; $i++)
{
$c = ord($input[$i]);
if($c > 128)
{
if($c > 247 || $c <= 191)
{
if($return)
{
$string .= '?';
continue;
}
else
{
return false;
}
}
elseif($c > 239)
{
$bytes = 4;
}
elseif($c > 223)
{
$bytes = 3;
}
elseif($c > 191)
{
$bytes = 2;
}
if(($i + $bytes) > $len)
{
if($return)
{
$string .= '?';
break;
}
else
{
return false;
}
}
$valid = true;
$multibytes = $input[$i];
while($bytes > 1)
{
$i++;
$b = ord($input[$i]);
if($b < 128 || $b > 191)
{
if($return)
{
$valid = false;
$string .= '?';
break;
}
else
{
return false;
}
}
else
{
$multibytes .= $input[$i];
}
$bytes--;
}
if($valid)
{
$string .= $multibytes;
}
}
else
{
$string .= $input[$i];
}
}
$input = $string;
}
if($return)
{
if($allow_mb4)
{
return $input;
}
else
{
return preg_replace("#[^\\x00-\\x7F][\\x80-\\xBF]{3,}#", '?', $input);
}
}
else
{
if($allow_mb4)
{
return true;
}
else
{
return !preg_match("#[^\\x00-\\x7F][\\x80-\\xBF]{3,}#", $input);
}
}
}

?>

?>