Vergleich inc/functions.php - 1.8.4 - 1.8.14

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 11Zeile 11
/**
* Outputs a page directly to the browser, parsing anything which needs to be parsed.
*

/**
* Outputs a page directly to the browser, parsing anything which needs to be parsed.
*

 * @param string The contents of the page.

 * @param string $contents The contents of the page.

 */
function output_page($contents)
{

 */
function output_page($contents)
{

Zeile 101Zeile 101
/**
* Adds a function or class to the list of code to run on shutdown.
*

/**
* Adds a function or class to the list of code to run on shutdown.
*

 * @param mixed The name of the function.
* @param mixed An array of arguments for the function

 * @param string|array $name The name of the function.
* @param mixed $arguments Either an array of arguments for the function or one argument

 * @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())

Zeile 242Zeile 242
/**
* Sends a specified amount of messages from the mail queue
*

/**
* Sends a specified amount of messages from the mail queue
*

 * @param int The number of messages to send (Defaults to 10)

 * @param int $count The number of messages to send (Defaults to 10)

 */
function send_mail_queue($count=10)
{

 */
function send_mail_queue($count=10)
{

Zeile 280Zeile 280
/**
* 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.

 * @param string $contents The contents of the page.

 * @return string The parsed page.
*/
function parse_page($contents)

 * @return string The parsed page.
*/
function parse_page($contents)

Zeile 322Zeile 322
/**
* Turn a unix timestamp in to a "friendly" date/time format for the user.
*

/**
* Turn a unix timestamp in to a "friendly" date/time format for the user.
*

 * @param string A date format according to PHP's date structure.
* @param int The unix timestamp the date should be generated for.
* @param int The offset in hours that should be applied to times. (timezones)
* @param int Whether or not to use today/yesterday formatting.
* @param boolean Whether or not to use the adodb time class for < 1970 or > 2038 times

 * @param string $format A date format (either relative, normal or PHP's date() structure).
* @param int $stamp The unix timestamp the date should be generated for.
* @param int|string $offset The offset in hours that should be applied to times. (timezones) Or an empty string to determine that automatically
* @param int $ty Whether or not to use today/yesterday formatting.
* @param boolean $adodb Whether or not to use the adodb time class for < 1970 or > 2038 times

 * @return string The formatted timestamp.
*/

 * @return string The formatted timestamp.
*/

function my_date($format, $stamp="", $offset="", $ty=1, $adodb=false)

function my_date($format, $stamp=0, $offset="", $ty=1, $adodb=false)

{
global $mybb, $lang, $mybbadmin, $plugins;


{
global $mybb, $lang, $mybbadmin, $plugins;


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

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

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

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

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

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

			$offset =  $mybbadmin['timezone'];

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

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

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

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

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

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


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


Zeile 380Zeile 380
	}

$todaysdate = $yesterdaysdate = '';

	}

$todaysdate = $yesterdaysdate = '';

	if($ty && ($format == $mybb->settings['dateformat'] || $format == 'relative'))

	if($ty && ($format == $mybb->settings['dateformat'] || $format == 'relative' || $format == 'normal'))

	{
$_stamp = TIME_NOW;
if($adodb == true)

	{
$_stamp = TIME_NOW;
if($adodb == true)

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

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

 
		$real_date = $real_time = '';
if($adodb == true)
{
$real_date = adodb_date($mybb->settings['dateformat'], $stamp + ($offset * 3600));
$real_time = $mybb->settings['datetimesep'];
$real_time .= adodb_date($mybb->settings['timeformat'], $stamp + ($offset * 3600));
}
else
{
$real_date = gmdate($mybb->settings['dateformat'], $stamp + ($offset * 3600));
$real_time = $mybb->settings['datetimesep'];
$real_time .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600));
}


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

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

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


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


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

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

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

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

		{

		{

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


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


Zeile 443Zeile 457
			$relative['hour'] = floor($diff / 3600);

if($relative['hour'] <= 1)

			$relative['hour'] = floor($diff / 3600);

if($relative['hour'] <= 1)

			{

			{

				$relative['hour'] = 1;
$relative['plural'] = $lang->rel_hours_single;
}


				$relative['hour'] = 1;
$relative['plural'] = $lang->rel_hours_single;
}


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

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

		}
else
{

		}
else
{

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

			{
if($todaysdate == $date)
{

					$date = $lang->today;

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

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

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

					$date = $lang->yesterday;

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

				}
}


				}
}


Zeile 473Zeile 487
			{
$date .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600));
}

			{
$date .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600));
}

 
		}
}
elseif($format == 'normal')
{
// Normal format both date and time
if($ty != 2)
{
if($todaysdate == $date)
{
$date = $lang->today;
}
else if($yesterdaysdate == $date)
{
$date = $lang->yesterday;
}
}

$date .= $mybb->settings['datetimesep'];
if($adodb == true)
{
$date .= adodb_date($mybb->settings['timeformat'], $stamp + ($offset * 3600));
}
else
{
$date .= gmdate($mybb->settings['timeformat'], $stamp + ($offset * 3600));

		}
}
else

		}
}
else

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

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

 * @param string Address the email should be addressed to.
* @param string The subject of the email being sent.
* @param string The message being sent.
* @param string The from address of the email, if blank, the board name will be used.
* @param string The chracter set being used to send this email.
* @param boolean Do we wish to keep the connection to the mail server alive to send more than one message (SMTP only)
* @param string The format of the email to be sent (text or html). text is default
* @param string The text message of the email if being sent in html format, for email clients that don't support html
* @param string The email address to return to. Defaults to admin return email address.



 * @param string $to Address the email should be addressed to.
* @param string $subject The subject of the email being sent.
* @param string $message The message being sent.
* @param string $from The from address of the email, if blank, the board name will be used.
* @param string $charset The chracter set being used to send this email.
* @param string $headers
* @param boolean $keep_alive Do we wish to keep the connection to the mail server alive to send more than one message (SMTP only)
* @param string $format The format of the email to be sent (text or html). text is default
* @param string $message_text The text message of the email if being sent in html format, for email clients that don't support html
* @param string $return_email The email address to return to. Defaults to admin return email address.
* @return bool

 */
function my_mail($to, $subject, $message, $from="", $charset="", $headers="", $keep_alive=false, $format="text", $message_text="", $return_email="")
{
global $mybb;
static $mail;

 */
function my_mail($to, $subject, $message, $from="", $charset="", $headers="", $keep_alive=false, $format="text", $message_text="", $return_email="")
{
global $mybb;
static $mail;





	// Does our object not exist? Create it
if(!is_object($mail))
{

	// Does our object not exist? Create it
if(!is_object($mail))
{

Zeile 565Zeile 606
	// 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();

}

/**

}

/**

 * Generates a unique code for POST requests to prevent XSS/CSRF attacks
*
* @return string The generated code

 * Generates a unique code for POST requests to prevent XSS/CSRF attacks
*
* @return string The generated code

Zeile 580Zeile 621
		return md5($mybb->user['loginkey'].$mybb->user['salt'].$mybb->user['regdate']);
}
// Guests get a special string

		return md5($mybb->user['loginkey'].$mybb->user['salt'].$mybb->user['regdate']);
}
// Guests get a special string

	else
{

	else
{

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

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

Zeile 589Zeile 630
/**
* Verifies a POST check code is valid, if not shows an error (silently returns false on silent parameter)
*

/**
* Verifies a POST check code is valid, if not shows an error (silently returns false on silent parameter)
*

 * @param string The incoming POST check code
* @param boolean Silent mode or not (silent mode will not show the error to the user but returns false)


 * @param string $code The incoming POST check code
* @param boolean $silent Silent mode or not (silent mode will not show the error to the user but returns false)
* @return bool

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

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

	if(generate_post_check() != $code)

	if(generate_post_check() !== $code)

	{
if($silent == true)

	{
if($silent == true)

		{

		{

			return false;
}
else
{
if(defined("IN_ADMINCP"))

			return false;
}
else
{
if(defined("IN_ADMINCP"))

			{

			{

				return false;

				return false;

			}

			}

			else
{
error($lang->invalid_post_code);
}
}

			else
{
error($lang->invalid_post_code);
}
}

	}

	}

	else
{
return true;

	else
{
return true;

Zeile 622Zeile 664
/**
* Return a parent list for the specified forum.
*

/**
* Return a parent list for the specified forum.
*

 * @param int The forum id to get the parent list for.

 * @param int $fid The forum id to get the parent list for.

 * @return string The comma-separated parent list.
*/
function get_parent_list($fid)

 * @return string The comma-separated parent list.
*/
function get_parent_list($fid)

Zeile 642Zeile 684
	{
cache_forums();
return $forum_cache[$fid]['parentlist'];

	{
cache_forums();
return $forum_cache[$fid]['parentlist'];

	}
}


	}
}


/**
* Build a parent list of a specific forum, suitable for querying
*

/**
* Build a parent list of a specific forum, suitable for querying
*

 * @param int The forum ID
* @param string The column name to add to the query
* @param string The joiner for each forum for querying (OR | AND | etc)
* @param string The parent list of the forum - if you have it

 * @param int $fid The forum ID
* @param string $column The column name to add to the query
* @param string $joiner The joiner for each forum for querying (OR | AND | etc)
* @param string $parentlist The parent list of the forum - if you have it

 * @return string The query string generated
*/
function build_parent_list($fid, $column="fid", $joiner="OR", $parentlist="")

 * @return string The query string generated
*/
function build_parent_list($fid, $column="fid", $joiner="OR", $parentlist="")

Zeile 659Zeile 701
	if(!$parentlist)
{
$parentlist = get_parent_list($fid);

	if(!$parentlist)
{
$parentlist = get_parent_list($fid);

	}

	}


$parentsexploded = explode(",", $parentlist);
$builtlist = "(";


$parentsexploded = explode(",", $parentlist);
$builtlist = "(";

Zeile 679Zeile 721
/**
* Load the forum cache in to memory
*

/**
* Load the forum cache in to memory
*

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


 * @param boolean $force True to force a reload of the cache
* @return array The forum cache

 */
function cache_forums($force=false)
{

 */
function cache_forums($force=false)
{

Zeile 701Zeile 744
		}
}
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.
*

 * @param int The forum ID
* @param return Array of descendants

 * @param int $fid The forum ID
* @return Array of descendants

 */
function get_child_list($fid)
{

 */
function get_child_list($fid)
{

Zeile 718Zeile 761
	{
$forum_cache = cache_forums();
foreach($forum_cache as $forum)

	{
$forum_cache = cache_forums();
foreach($forum_cache as $forum)

		{

		{

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

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

Zeile 727Zeile 770
	}
if(!is_array($forums_by_parent[$fid]))
{

	}
if(!is_array($forums_by_parent[$fid]))
{

		return;

		return $forums;

	}

foreach($forums_by_parent[$fid] as $forum)

	}

foreach($forums_by_parent[$fid] as $forum)

Zeile 745Zeile 788
/**
* Produce a friendly error message page
*

/**
* Produce a friendly error message page
*

 * @param string The error message to be shown
* @param string The title of the message shown in the title of the page and the error table

 * @param string $error The error message to be shown
* @param string $title The title of the message shown in the title of the page and the error table

 */
function error($error="", $title="")
{

 */
function error($error="", $title="")
{

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

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

		exit;
}


		exit;
}


	if(!$title)
{
$title = $mybb->settings['bbname'];

	if(!$title)
{
$title = $mybb->settings['bbname'];

Zeile 785Zeile 828
/**
* Produce an error message for displaying inline on a page
*

/**
* Produce an error message for displaying inline on a page
*

 * @param array Array of errors to be shown
* @param string The title of the error message
* @param string JSON data to be encoded (we may want to send more data; e.g. newreply.php uses this for CAPTCHA)

 * @param array $errors Array of errors to be shown
* @param string $title The title of the error message
* @param array $json_data JSON data to be encoded (we may want to send more data; e.g. newreply.php uses this for CAPTCHA)

 * @return string The inline error HTML
*/
function inline_error($errors, $title="", $json_data=array())

 * @return string The inline error HTML
*/
function inline_error($errors, $title="", $json_data=array())

Zeile 861Zeile 904

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


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

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

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

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

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

Zeile 899Zeile 942
/**
* Redirect the user to a given URL with a given message
*

/**
* Redirect the user to a given URL with a given message
*

 * @param string The URL to redirect the user to
* @param string The redirection message to be shown
* @param string The title of the redirection page
* @param boolean Force the redirect page regardless of settings

 * @param string $url The URL to redirect the user to
* @param string $message The redirection message to be shown
* @param string $title The title of the redirection page
* @param boolean $force_redirect Force the redirect page regardless of settings

 */
function redirect($url, $message="", $title="", $force_redirect=false)
{

 */
function redirect($url, $message="", $title="", $force_redirect=false)
{

Zeile 962Zeile 1005

run_shutdown();



run_shutdown();


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

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

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

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

Zeile 978Zeile 1021
/**
* Generate a listing of page - pagination
*

/**
* Generate a listing of page - pagination
*

 * @param int The number of items
* @param int The number of items to be shown per page
* @param int The current page number
* @param string The URL to have page numbers tacked on to (If {page} is specified, the value will be replaced with the page #)
* @param boolean Whether or not the multipage is being shown in the navigation breadcrumb

 * @param int $count The number of items
* @param int $perpage The number of items to be shown per page
* @param int $page The current page number
* @param string $url The URL to have page numbers tacked on to (If {page} is specified, the value will be replaced with the page #)
* @param boolean $breadcrumb Whether or not the multipage is being shown in the navigation breadcrumb

 * @return string The generated pagination
*/
function multipage($count, $perpage, $page, $url, $breadcrumb=false)

 * @return string The generated pagination
*/
function multipage($count, $perpage, $page, $url, $breadcrumb=false)

Zeile 991Zeile 1034

if($count <= $perpage)
{


if($count <= $perpage)
{

		return;

		return '';

	}

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

	}

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

Zeile 1115Zeile 1158
/**
* Generate a page URL for use by the multipage function
*

/**
* Generate a page URL for use by the multipage function
*

 * @param string The URL being passed
* @param int The page number


 * @param string $url The URL being passed
* @param int $page The page number
* @return string

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

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

Zeile 1157Zeile 1201
/**
* Fetch the permissions for a specific user
*

/**
* Fetch the permissions for a specific user
*

 * @param int The user ID

 * @param int $uid The user ID

 * @return array Array of user permissions for the specified user
*/
function user_permissions($uid=0)

 * @return array Array of user permissions for the specified user
*/
function user_permissions($uid=0)

Zeile 1174Zeile 1218
	if($uid != $mybb->user['uid'])
{
// We've already cached permissions for this user, return them.

	if($uid != $mybb->user['uid'])
{
// We've already cached permissions for this user, return them.

		if($user_cache[$uid]['permissions'])

		if(!empty($user_cache[$uid]['permissions']))

		{
return $user_cache[$uid]['permissions'];
}

// This user was not already cached, fetch their user information.

		{
return $user_cache[$uid]['permissions'];
}

// This user was not already cached, fetch their user information.

		if(!$user_cache[$uid])

		if(empty($user_cache[$uid]))

		{
$user_cache[$uid] = get_user($uid);
}

		{
$user_cache[$uid] = get_user($uid);
}

Zeile 1203Zeile 1247
/**
* Fetch the usergroup permissions for a specific group or series of groups combined
*

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

 * @param mixed A list of groups (Can be a single integer, or a list of groups separated by a comma)
* @return array Array of permissions generated for the groups

 * @param int|string $gid A list of groups (Can be a single integer, or a list of groups separated by a comma)
* @return array Array of permissions generated for the groups, containing also a list of comma-separated checked groups under 'all_usergroups' index

 */
function usergroup_permissions($gid=0)
{

 */
function usergroup_permissions($gid=0)
{

Zeile 1219Zeile 1263

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


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

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

		return $groupscache[$gid];
}

		return $groupscache[$gid];
}

	



	$usergroup = array();

	$usergroup = array();

 
	$usergroup['all_usergroups'] = $gid;


foreach($groups as $gid)
{


foreach($groups as $gid)
{

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

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

		{
continue;
}

		{
continue;
}

Zeile 1265Zeile 1311
/**
* Fetch the display group properties for a specific display group
*

/**
* Fetch the display group properties for a specific display group
*

 * @param int The group ID to fetch the display properties for

 * @param int $gid The group ID to fetch the display properties for

 * @return array Array of display properties for the group
*/
function usergroup_displaygroup($gid)

 * @return array Array of display properties for the group
*/
function usergroup_displaygroup($gid)

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

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

 * @param int The forum ID to build permissions for (0 builds for all forums)
* @param int The user to build the permissions for (0 will select the uid automatically)
* @param int The group of the user to build permissions for (0 will fetch it)

 * @param int $fid The forum ID to build permissions for (0 builds for all forums)
* @param int $uid The user to build the permissions for (0 will select the uid automatically)
* @param int $gid The group of the user to build permissions for (0 will fetch it)

 * @return array Forum permissions for the specific forum or forums
*/
function forum_permissions($fid=0, $uid=0, $gid=0)

 * @return array Forum permissions for the specific forum or forums
*/
function forum_permissions($fid=0, $uid=0, $gid=0)

Zeile 1360Zeile 1406
			}
}
return $cached_forum_permissions[$gid];

			}
}
return $cached_forum_permissions[$gid];

	}
}

	}
}


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


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

 * @param int The forum ID
* @param string A comma separated list of usergroups
* @param array Group permissions

 * @param int $fid The forum ID
* @param string $gid A comma separated list of usergroups
* @param array $groupperms Group permissions

 * @return array Permissions for this forum
*/
function fetch_forum_permissions($fid, $gid, $groupperms)

 * @return array Permissions for this forum
*/
function fetch_forum_permissions($fid, $gid, $groupperms)

Zeile 1459Zeile 1505
/**
* Check the password given on a certain forum for validity
*

/**
* Check the password given on a certain forum for validity
*

 * @param int The forum ID
* @param boolean The Parent ID



 * @param int $fid The forum ID
* @param int $pid The Parent ID
* @param bool $return
* @return bool

 */

 */

function check_forum_password($fid, $pid=0)

function check_forum_password($fid, $pid=0, $return=false)

{
global $mybb, $header, $footer, $headerinclude, $theme, $templates, $lang, $forum_cache;


{
global $mybb, $header, $footer, $headerinclude, $theme, $templates, $lang, $forum_cache;


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

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

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

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

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

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

Zeile 1517Zeile 1565
		}
else
{

		}
else
{

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

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

			{
$showform = true;
}

			{
$showform = true;
}

Zeile 1530Zeile 1578
	else
{
$showform = false;

	else
{
$showform = false;

 
	}

if($return)
{
return $showform;

	}

if($showform)

	}

if($showform)

Zeile 1551Zeile 1604
/**
* Return the permissions for a moderator in a specific forum
*

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

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

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

 * @return array Array of moderator permissions for the specific forum
*/

 * @return array Array of moderator permissions for the specific forum
*/

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

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

{
global $mybb, $cache, $db;
static $modpermscache;

{
global $mybb, $cache, $db;
static $modpermscache;

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

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

 * @param int The forum ID (0 assumes global)
* @param string The action tyring to be performed. (blank assumes any action at all)
* @param int The user ID (0 assumes current user)

 * @param int $fid The forum ID (0 assumes global)
* @param string $action The action tyring to be performed. (blank assumes any action at all)
* @param int $uid The user ID (0 assumes current user)

 * @return bool Returns true if the user has permission, false if they do not
*/

 * @return bool Returns true if the user has permission, false if they do not
*/

function is_moderator($fid="0", $action="", $uid="0")

function is_moderator($fid=0, $action="", $uid=0)

{
global $mybb, $cache;


{
global $mybb, $cache;


Zeile 1702Zeile 1755
			{
foreach($modcache as $modusers)
{

			{
foreach($modcache as $modusers)
{

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

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

					{
return true;
}

					{
return true;
}

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





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

foreach($groups as $group)

					{

					{

						// Moderating usergroup
return true;



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

					}
}
}

					}
}
}

Zeile 1782Zeile 1840
		eval("\$iconlist .= \"".$templates->get("posticons_icon")."\";");
}


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


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








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


return $posticons;
}


return $posticons;
}

Zeile 1790Zeile 1855
/**
* MyBB setcookie() wrapper.
*

/**
* MyBB setcookie() wrapper.
*

 * @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 $name The cookie identifier.
* @param string $value The cookie value.
* @param int|string $expires The timestamp of the expiry date.
* @param boolean $httponly True if setting a HttpOnly cookie (supported by the majority of web browsers)

 */
function my_setcookie($name, $value="", $expires="", $httponly=false)
{
global $mybb;

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

 */
function my_setcookie($name, $value="", $expires="", $httponly=false)
{
global $mybb;

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

	{

	{

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

if($expires == -1)
{
$expires = 0;

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

if($expires == -1)
{
$expires = 0;

	}

	}

	elseif($expires == "" || $expires == null)
{
$expires = TIME_NOW + (60*60*24*365); // Make the cookie expire in a years time
}
else

	elseif($expires == "" || $expires == null)
{
$expires = TIME_NOW + (60*60*24*365); // Make the cookie expire in a years time
}
else

	{

	{

		$expires = TIME_NOW + (int)$expires;
}

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

		$expires = TIME_NOW + (int)$expires;
}

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

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

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

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

	}

	}


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


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

Zeile 1840Zeile 1905
	}

if($httponly == true)

	}

if($httponly == true)

	{

	{

		$cookie .= "; HttpOnly";

		$cookie .= "; HttpOnly";

 
	}

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

	}

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

	}

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

Zeile 1852Zeile 1922
/**
* Unset a cookie set by MyBB.
*

/**
* Unset a cookie set by MyBB.
*

 * @param string The cookie identifier.

 * @param string $name The cookie identifier.

 */
function my_unsetcookie($name)
{

 */
function my_unsetcookie($name)
{

Zeile 1867Zeile 1937
/**
* Get the contents from a serialised cookie array.
*

/**
* Get the contents from a serialised cookie array.
*

 * @param string The cookie identifier.
* @param int The cookie content id.

 * @param string $name The cookie identifier.
* @param int $id The cookie content id.

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

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

Zeile 1895Zeile 1965
/**
* Set a serialised cookie array.
*

/**
* Set a serialised cookie array.
*

 * @param string The cookie identifier.
* @param int The cookie content id.
* @param string The value to set the cookie to.
* @param int The timestamp of the expiry date.

 * @param string $name The cookie identifier.
* @param int $id The cookie content id.
* @param string $value The value to set the cookie to.
* @param int|string $expires The timestamp of the expiry date.

 */
function my_set_array_cookie($name, $id, $value, $expires="")
{

 */
function my_set_array_cookie($name, $id, $value, $expires="")
{

Zeile 2074Zeile 2144
				}

// illegal array index type

				}

// illegal array index type

				return false;

				return false;


case 0: // expecting array or value
if($type == 'a')


case 0: // expecting array or value
if($type == 'a')

Zeile 2109Zeile 2179
		return false;
}
return $data;

		return false;
}
return $data;

}

/**
* Credits go to https://github.com/piwik

}

/**
* Credits go to https://github.com/piwik

 * Wrapper for _safe_unserialize() that handles exceptions and multibyte encoding issue
*
* @param string $str

 * Wrapper for _safe_unserialize() that handles exceptions and multibyte encoding issue
*
* @param string $str

Zeile 2133Zeile 2203
	{
mb_internal_encoding($mbIntEnc);
}

	{
mb_internal_encoding($mbIntEnc);
}

	



	return $out;
}


	return $out;
}


Zeile 2150Zeile 2220
function _safe_serialize( $value )
{
if(is_null($value))

function _safe_serialize( $value )
{
if(is_null($value))

	{

	{

		return 'N;';

		return 'N;';

	}


	}


	if(is_bool($value))

	if(is_bool($value))

	{

	{

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

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

	



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

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

	



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

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

	



	if(is_string($value))

	if(is_string($value))

	{

	{

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

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

	



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

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

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

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

		



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


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


Zeile 2204Zeile 2274
		$mbIntEnc = mb_internal_encoding();
mb_internal_encoding('ASCII');
}

		$mbIntEnc = mb_internal_encoding();
mb_internal_encoding('ASCII');
}

	



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

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

	



	return $out;
}


	return $out;
}


Zeile 2232Zeile 2302
		{
// sys_getloadavg() will return an array with [0] being load within the last minute.
$serverload = sys_getloadavg();

		{
// sys_getloadavg() will return an array with [0] being load within the last minute.
$serverload = sys_getloadavg();

			$serverload[0] = round($serverload[0], 4);
}

			$serverload[0] = round($serverload[0], 4);
}

		else if(@file_exists("/proc/loadavg") && $load = @file_get_contents("/proc/loadavg"))

		else if(@file_exists("/proc/loadavg") && $load = @file_get_contents("/proc/loadavg"))

		{

		{

			$serverload = explode(" ", $load);
$serverload[0] = round($serverload[0], 4);
}
if(!is_numeric($serverload[0]))
{
if($mybb->safemode)

			$serverload = explode(" ", $load);
$serverload[0] = round($serverload[0], 4);
}
if(!is_numeric($serverload[0]))
{
if($mybb->safemode)

			{
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 2271Zeile 2341
				return $lang->unknown;
}
}

				return $lang->unknown;
}
}

	}

	}

	else
{
return $lang->unknown;
}


	else
{
return $lang->unknown;
}


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


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


	return $returnload;
}

/**
* Returns the amount of memory allocated to the script.

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

 * @return int The amount of memory allocated to the script.
*/
function get_memory_usage()

Zeile 2303Zeile 2373
/**
* Updates the forum statistics with specific values (or addition/subtraction of the previous value)
*

/**
* Updates the forum statistics with specific values (or addition/subtraction of the previous value)
*

 * @param array Array of items being updated (numthreads,numposts,numusers,numunapprovedthreads,numunapprovedposts,numdeletedposts,numdeletedthreads)
* @param boolean Force stats update?

 * @param array $changes Array of items being updated (numthreads,numposts,numusers,numunapprovedthreads,numunapprovedposts,numdeletedposts,numdeletedthreads)
* @param boolean $force Force stats update?

 */
function update_stats($changes=array(), $force=false)
{

 */
function update_stats($changes=array(), $force=false)
{

Zeile 2312Zeile 2382
	static $stats_changes;

if(empty($stats_changes))

	static $stats_changes;

if(empty($stats_changes))

	{

	{

		// Update stats after all changes are done
add_shutdown('update_stats', array(array(), true));
}

		// Update stats after all changes are done
add_shutdown('update_stats', array(array(), true));
}

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

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

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

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

	}

if(!empty($new_stats))

	}

if(!empty($new_stats))

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

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

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

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

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


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


Zeile 2433Zeile 2503
/**
* Updates the forum counters with a specific value (or addition/subtraction of the previous value)
*

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

 * @param int The forum ID
* @param array Array of items being updated (threads, posts, unapprovedthreads, unapprovedposts, deletedposts, deletedthreads) and their value (ex, 1, +1, -1)

 * @param int $fid The forum ID
* @param array $changes Array of items being updated (threads, posts, unapprovedthreads, unapprovedposts, deletedposts, deletedthreads) and their value (ex, 1, +1, -1)

 */
function update_forum_counters($fid, $changes=array())
{

 */
function update_forum_counters($fid, $changes=array())
{

Zeile 2530Zeile 2600
		if($unapprovedposts_diff > -1)
{
$new_stats['numunapprovedposts'] = "+{$unapprovedposts_diff}";

		if($unapprovedposts_diff > -1)
{
$new_stats['numunapprovedposts'] = "+{$unapprovedposts_diff}";

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

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

	}

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

	}

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

Zeile 2554Zeile 2624
	{
$deletedthreads_diff = $update_query['deletedthreads'] - $forum['deletedthreads'];
if($deletedthreads_diff > -1)

	{
$deletedthreads_diff = $update_query['deletedthreads'] - $forum['deletedthreads'];
if($deletedthreads_diff > -1)

		{

		{

			$new_stats['numdeletedthreads'] = "+{$deletedthreads_diff}";
}
else

			$new_stats['numdeletedthreads'] = "+{$deletedthreads_diff}";
}
else

Zeile 2567Zeile 2637
	{
update_stats($new_stats);
}

	{
update_stats($new_stats);
}

}

}


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


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

 * @param int The forum ID

 * @param int $fid The forum ID

 */
function update_forum_lastpost($fid)
{

 */
function update_forum_lastpost($fid)
{

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

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

 * @param int The thread ID
* @param array Array of items being updated (replies, unapprovedposts, deletedposts, attachmentcount) and their value (ex, 1, +1, -1)

 * @param int $tid The thread ID
* @param array $changes Array of items being updated (replies, unapprovedposts, deletedposts, attachmentcount) and their value (ex, 1, +1, -1)

 */
function update_thread_counters($tid, $changes=array())
{

 */
function update_thread_counters($tid, $changes=array())
{

Zeile 2632Zeile 2702
				if((int)$changes[$counter] != 0)
{
$update_query[$counter] = $thread[$counter] + $changes[$counter];

				if((int)$changes[$counter] != 0)
{
$update_query[$counter] = $thread[$counter] + $changes[$counter];

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

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


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

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


	$db->free_result($query);

// Only update if we're actually doing something

	$db->free_result($query);

// Only update if we're actually doing something

Zeile 2658Zeile 2728

/**
* Update the first post and lastpost data for a specific thread


/**
* Update the first post and lastpost data for a specific thread

 *
* @param int The thread ID

 *
* @param int $tid The thread ID

 */
function update_thread_data($tid)
{
global $db;

$thread = get_thread($tid);

 */
function update_thread_data($tid)
{
global $db;

$thread = get_thread($tid);





	// If this is a moved thread marker, don't update it - we need it to stay as it is
if(strpos($thread['closed'], 'moved|') !== false)

	// If this is a moved thread marker, don't update it - we need it to stay as it is
if(strpos($thread['closed'], 'moved|') !== false)

	{
return false;
}


	{
return;
}


	$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 2713Zeile 2783
		$lastpost['uid'] = $firstpost['uid'];
$lastpost['dateline'] = $firstpost['dateline'];
}

		$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 2732Zeile 2802
/**
* Updates the user counters with a specific value (or addition/subtraction of the previous value)
*

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

 * @param int The user ID
* @param array Array of items being updated (postnum, threadnum) and their value (ex, 1, +1, -1)

 * @param int $uid The user ID
* @param array $changes Array of items being updated (postnum, threadnum) and their value (ex, 1, +1, -1)

 */
function update_user_counters($uid, $changes=array())
{

 */
function update_user_counters($uid, $changes=array())
{

Zeile 2755Zeile 2825
			if(substr($changes[$counter], 0, 2) == "+-")
{
$changes[$counter] = substr($changes[$counter], 1);

			if(substr($changes[$counter], 0, 2) == "+-")
{
$changes[$counter] = substr($changes[$counter], 1);

			}

			}

			// Adding or subtracting from previous value?
if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
{

			// Adding or subtracting from previous value?
if(substr($changes[$counter], 0, 1) == "+" || substr($changes[$counter], 0, 1) == "-")
{

Zeile 2789Zeile 2859
/**
* Deletes a thread from the database
*

/**
* Deletes a thread from the database
*

 * @param int The thread ID


 * @param int $tid The thread ID
* @return bool

 */
function delete_thread($tid)
{

 */
function delete_thread($tid)
{

Zeile 2807Zeile 2878
/**
* Deletes a post from the database
*

/**
* Deletes a post from the database
*

 * @param int The thread ID


 * @param int $pid The thread ID
* @return bool

 */
function delete_post($pid)
{

 */
function delete_post($pid)
{

Zeile 2825Zeile 2897
/**
* Builds a forum jump menu
*

/**
* Builds a forum jump menu
*

 * @param int The parent forum to start with
* @param int The selected item ID
* @param int If we need to add select boxes to this cal or not
* @param int The current depth of forums we're at
* @param int Whether or not to show extra items such as User CP, Forum home
* @param boolean Ignore the showinjump setting and show all forums (for moderation pages)
* @param unknown_type deprecated
* @param string The name of the forum jump

 * @param int $pid The parent forum to start with
* @param int $selitem The selected item ID
* @param int $addselect If we need to add select boxes to this cal or not
* @param string $depth The current depth of forums we're at
* @param int $showextras Whether or not to show extra items such as User CP, Forum home
* @param boolean $showall Ignore the showinjump setting and show all forums (for moderation pages)
* @param mixed $permissions deprecated
* @param string $name The name of the forum jump

 * @return string Forum jump items
*/

 * @return string Forum jump items
*/

function build_forum_jump($pid="0", $selitem="", $addselect="1", $depth="", $showextras="1", $showall=false, $permissions="", $name="fid")

function build_forum_jump($pid=0, $selitem=0, $addselect=1, $depth="", $showextras=1, $showall=false, $permissions="", $name="fid")

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


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


Zeile 2922Zeile 2994
/**
* Returns the extension of a file.
*

/**
* Returns the extension of a file.
*

 * @param string The filename.

 * @param string $file The filename.

 * @return string The extension of the file.
*/
function get_extension($file)

 * @return string The extension of the file.
*/
function get_extension($file)

Zeile 2933Zeile 3005
/**
* Generates a random string.
*

/**
* Generates a random string.
*

 * @param int The length of the string to generate.


 * @param int $length The length of the string to generate.
* @param bool $complex Whether to return complex string. Defaults to false

 * @return string The random string.
*/

 * @return string The random string.
*/

function random_str($length="8")

function random_str($length=8, $complex=false)

{

{

	$set = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v","V","w","W","x","X","y","Y","z","Z","1","2","3","4","5","6","7","8","9");
$str = '';

	$set = array_merge(range(0, 9), range('A', 'Z'), range('a', 'z'));
$str = array();





	for($i = 1; $i <= $length; ++$i)


	// Complex strings have always at least 3 characters, even if $length < 3
if($complex == true)

	{

	{

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














		// At least one number
$str[] = $set[my_rand(0, 9)];

// At least one big letter
$str[] = $set[my_rand(10, 35)];

// At least one small letter
$str[] = $set[my_rand(36, 61)];

$length -= 3;
}

for($i = 0; $i < $length; ++$i)
{
$str[] = $set[my_rand(0, 61)];

	}


	}


	return $str;




	// Make sure they're in random order and convert them to a string
shuffle($str);

return implode($str);

}

/**
* Formats a username based on their display group
*

}

/**
* Formats a username based on their display group
*

 * @param string The username
* @param int The usergroup for the user (if not specified, will be fetched)
* @param int The display group for the user (if not specified, will be fetched)

 * @param string $username The username
* @param int $usergroup The usergroup for the user
* @param int $displaygroup The display group for the user

 * @return string The formatted username
*/

 * @return string The formatted username
*/

function format_name($username, $usergroup, $displaygroup="")

function format_name($username, $usergroup, $displaygroup=0)

{
global $groupscache, $cache;

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

{
global $groupscache, $cache;

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

	}


	}


	if($displaygroup != 0)
{
$usergroup = $displaygroup;

	if($displaygroup != 0)
{
$usergroup = $displaygroup;

	}


	}


	$ugroup = $groupscache[$usergroup];
$format = $ugroup['namestyle'];
$userin = substr_count($format, "{username}");

	$ugroup = $groupscache[$usergroup];
$format = $ugroup['namestyle'];
$userin = substr_count($format, "{username}");

Zeile 2982Zeile 3072
	}

$format = stripslashes($format);

	}

$format = stripslashes($format);





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

/**
* Formats an avatar to a certain dimension
*

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

/**
* Formats an avatar to a certain dimension
*

 * @param string The avatar file name
* @param string Dimensions of the avatar, width x height (e.g. 44|44)
* @param string The maximum dimensions of the formatted avatar

 * @param string $avatar The avatar file name
* @param string $dimensions Dimensions of the avatar, width x height (e.g. 44|44)
* @param string $max_dimensions The maximum dimensions of the formatted avatar

 * @return array Information for the formatted avatar
*/
function format_avatar($avatar, $dimensions = '', $max_dimensions = '')
{

 * @return array Information for the formatted avatar
*/
function format_avatar($avatar, $dimensions = '', $max_dimensions = '')
{

	global $mybb;

	global $mybb, $theme;

	static $avatars;

if(!isset($avatars))

	static $avatars;

if(!isset($avatars))

Zeile 3004Zeile 3094
		$avatars = array();
}


		$avatars = array();
}


	if(!$avatar)







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

if(!$avatar)

	{
// Default avatar

	{
// Default avatar

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






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

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

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


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


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


















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

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

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

	{

	{

		return $avatars[$avatar];
}

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

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






	}

$avatar_width_height = '';

	}

$avatar_width_height = '';

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


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


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

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

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

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

Zeile 3044Zeile 3157
		}
}


		}
}


	$avatars[$avatar] = array(

	$avatars[$avatar][$key][$key2] = array(

		'image' => htmlspecialchars_uni($mybb->get_asset_url($avatar)),
'width_height' => $avatar_width_height
);


		'image' => htmlspecialchars_uni($mybb->get_asset_url($avatar)),
'width_height' => $avatar_width_height
);


	return $avatars[$avatar];

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

}

/**

}

/**

Zeile 3168Zeile 3281
			// Smilies
$emoticon = "";
$emoticons_enabled = "false";

			// Smilies
$emoticon = "";
$emoticons_enabled = "false";

			if($smilies && $mybb->settings['smilieinserter'] != 0 && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'])

			if($smilies)

			{

			{

				$emoticon = ",emoticon";
$emoticons_enabled = "true";


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

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

Zeile 3181Zeile 3291
					}
foreach($smilie_cache as $smilie)
{

					}
foreach($smilie_cache as $smilie)
{

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

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




					}
}

					}
}

 

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


unset($smilie);



unset($smilie);


Zeile 3205Zeile 3318

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


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





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


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


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





						if(!$mybb->settings['smilieinserter'] || !$mybb->settings['smilieinsertercols'] || !$mybb->settings['smilieinsertertot'] || !$smilie['showclickable'])
{
$hiddensmilies .= '"'.$find.'": "'.$image.'",';
}
elseif($i < $mybb->settings['smilieinsertertot'])

						{
$dropdownsmilies .= '"'.$find.'": "'.$image.'",';

						{
$dropdownsmilies .= '"'.$find.'": "'.$image.'",';

 
							++$i;

						}
else
{

						}
else
{

Zeile 3224Zeile 3342
							$find = str_replace(array('\\', '"'), array('\\\\', '\"'), htmlspecialchars_uni($finds[$j]));
$hiddensmilies .= '"'.$find.'": "'.$image.'",';
}

							$find = str_replace(array('\\', '"'), array('\\\\', '\"'), htmlspecialchars_uni($finds[$j]));
$hiddensmilies .= '"'.$find.'": "'.$image.'",';
}

						++$i;

 
					}
}
}

					}
}
}

Zeile 3319Zeile 3436
			}
foreach($smilie_cache as $smilie)
{

			}
foreach($smilie_cache as $smilie)
{

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

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




			}
}


			}
}


Zeile 3335Zeile 3449

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


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

			{

			{

				$mybb->settings['smilieinsertertot'] = $smiliecount;
}
else if($mybb->settings['smilieinsertertot'] < $smiliecount)

				$mybb->settings['smilieinsertertot'] = $smiliecount;
}
else if($mybb->settings['smilieinsertertot'] < $smiliecount)

			{

			{

				$smiliecount = $mybb->settings['smilieinsertertot'];
eval("\$getmore = \"".$templates->get("smilieinsert_getmore")."\";");
}

				$smiliecount = $mybb->settings['smilieinsertertot'];
eval("\$getmore = \"".$templates->get("smilieinsert_getmore")."\";");
}


$smilies = "";


$smilies = '';

			$counter = 0;
$i = 0;

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

			$counter = 0;
$i = 0;

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

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

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

				{

				{

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


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

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

					



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

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

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

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

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

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

					++$i;
++$counter;

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

					++$i;
++$counter;

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

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


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

					}
}
}

					}
}
}

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

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

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

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

			}

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

			}

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

Zeile 3407Zeile 3517
/**
* 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)

 *  @param int $pid The prefix ID (0 to return all)

 *  @return array The thread prefix's values (or all thread prefixes)
*/
function build_prefixes($pid=0)

 *  @return array The thread prefix's values (or all thread prefixes)
*/
function build_prefixes($pid=0)

Zeile 3457Zeile 3567
}

/**

}

/**

 * Build the thread prefix selection menu

 * Build the thread prefix selection menu for the current user

 *

 *

 *  @param mixed The forum ID (integer ID or string all)
* @param mixed The selected prefix ID (integer ID or string any)
* @param int Allow multiple prefix selection


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

 *  @return string The thread prefix selection menu
*/

 *  @return string The thread prefix selection menu
*/

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

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

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


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


Zeile 3476Zeile 3587
	$prefix_cache = build_prefixes(0);
if(empty($prefix_cache))
{

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

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

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

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

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











	}

// Go through each of our prefixes and decide which ones we can use

	}

// Go through each of our prefixes and decide which ones we can use

Zeile 3499Zeile 3600
			// Decide whether this prefix can be used in our forum
$forums = explode(",", $prefix['forums']);


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


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

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

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

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


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

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


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














		{

		{

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

			// The current user can use this prefix

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

if(empty($prefixes))
{

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

if(empty($prefixes))
{

		return false;

		return '';

	}

	}





	$prefixselect = $prefixselect_prefix = '';

if($multiple == 1)

	$prefixselect = $prefixselect_prefix = '';

if($multiple == 1)

	{

	{

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

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

		}
}


		}
}


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

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

Zeile 3555Zeile 3643
		{
$selected = " selected=\"selected\"";
}

		{
$selected = " selected=\"selected\"";
}





		$prefix['prefix'] = htmlspecialchars_uni($prefix['prefix']);
eval("\$prefixselect_prefix .= \"".$templates->get("post_prefixselect_prefix")."\";");

		$prefix['prefix'] = htmlspecialchars_uni($prefix['prefix']);
eval("\$prefixselect_prefix .= \"".$templates->get("post_prefixselect_prefix")."\";");

	}

	}


if($multiple != 0)
{
eval("\$prefixselect = \"".$templates->get("post_prefixselect_multiple")."\";");


if($multiple != 0)
{
eval("\$prefixselect = \"".$templates->get("post_prefixselect_multiple")."\";");

	}
else

	}
else

	{
eval("\$prefixselect = \"".$templates->get("post_prefixselect_single")."\";");
}

return $prefixselect;
}

	{
eval("\$prefixselect = \"".$templates->get("post_prefixselect_single")."\";");
}

return $prefixselect;
}





/**

/**

 * Build the thread prefix selection menu for a forum

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

 *

 *

 *  @param mixed The forum ID (integer ID)
* @param mixed The selected prefix ID (integer ID)


 *  @param int $fid The forum ID (integer ID)
* @param int $selected_pid The selected prefix ID (integer ID)
* @return string The thread prefix selection menu

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

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

Zeile 3586Zeile 3675

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


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

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


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

	}

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

	}

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

	{

	{

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

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

Zeile 3614Zeile 3704

if(empty($prefixes))
{


if(empty($prefixes))
{

		return false;

		return '';

	}

	}





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

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

	



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

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

Zeile 3652Zeile 3742
/**
* Gzip encodes text to a specified level
*

/**
* Gzip encodes text to a specified level
*

 * @param string The string to encode
* @param int The level (1-9) to encode at

 * @param string $contents The string to encode
* @param int $level The level (1-9) to encode at

 * @return string The encoded string
*/
function gzip_encode($contents, $level=1)

 * @return string The encoded string
*/
function gzip_encode($contents, $level=1)

Zeile 3704Zeile 3794
/**
* Log the actions of a moderator.
*

/**
* Log the actions of a moderator.
*

 * @param array The data of the moderator's action.
* @param string The message to enter for the action the moderator performed.

 * @param array $data The data of the moderator's action.
* @param string $action The message to enter for the action the moderator performed.

 */
function log_moderator_action($data, $action="")
{

 */
function log_moderator_action($data, $action="")
{

Zeile 3730Zeile 3820
	{
$pid = (int)$data['pid'];
unset($data['pid']);

	{
$pid = (int)$data['pid'];
unset($data['pid']);

 
	}

$tids = array();
if(isset($data['tids']))
{
$tids = (array)$data['tids'];
unset($data['tids']);

	}

// Any remaining extra data - we my_serialize and insert in to its own column
if(is_array($data))
{
$data = my_serialize($data);

	}

// Any remaining extra data - we my_serialize and insert in to its own column
if(is_array($data))
{
$data = my_serialize($data);

	}

	}


$sql_array = array(
"uid" => (int)$mybb->user['uid'],


$sql_array = array(
"uid" => (int)$mybb->user['uid'],

Zeile 3748Zeile 3845
		"data" => $db->escape_string($data),
"ipaddress" => $db->escape_binary($session->packedip)
);

		"data" => $db->escape_string($data),
"ipaddress" => $db->escape_binary($session->packedip)
);

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


















if($tids)
{
$multiple_sql_array = array();

foreach($tids as $tid)
{
$sql_array['tid'] = (int)$tid;
$multiple_sql_array[] = $sql_array;
}

$db->insert_query_multiple("moderatorlog", $multiple_sql_array);
}
else
{
$db->insert_query("moderatorlog", $sql_array);
}

}

/**
* Get the formatted reputation for a user.
*

}

/**
* Get the formatted reputation for a user.
*

 * @param int The reputation value
* @param int The user ID (if not specified, the generated reputation will not be a link)

 * @param int $reputation The reputation value
* @param int $uid The user ID (if not specified, the generated reputation will not be a link)

 * @return string The formatted repuation
*/
function get_reputation($reputation, $uid=0)

 * @return string The formatted repuation
*/
function get_reputation($reputation, $uid=0)

Zeile 3764Zeile 3877

$display_reputation = $reputation_class = '';
if($reputation < 0)


$display_reputation = $reputation_class = '';
if($reputation < 0)

	{

	{

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

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

Zeile 3775Zeile 3888
	{
$reputation_class = "reputation_neutral";
}

	{
$reputation_class = "reputation_neutral";
}

 

$reputation = my_number_format($reputation);


if($uid != 0)
{


if($uid != 0)
{

Zeile 3791Zeile 3906
/**
* Fetch a color coded version of a warning level (based on it's percentage)
*

/**
* Fetch a color coded version of a warning level (based on it's percentage)
*

 * @param int The warning level (percentage of 100)

 * @param int $level The warning level (percentage of 100)

 * @return string Formatted warning level
*/
function get_colored_warning_level($level)

 * @return string Formatted warning level
*/
function get_colored_warning_level($level)

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

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

 * @param int The size in bytes

 * @param int $size The size in bytes

 * @return string The friendly file size
*/
function get_friendly_size($size)

 * @return string The friendly file size
*/
function get_friendly_size($size)

Zeile 3946Zeile 4061
/**
* Format a decimal number in to microseconds, milliseconds, or seconds.
*

/**
* Format a decimal number in to microseconds, milliseconds, or seconds.
*

 * @param int The time in microseconds

 * @param int $time The time in microseconds

 * @return string The friendly time duration
*/
function format_time_duration($time)

 * @return string The friendly time duration
*/
function format_time_duration($time)

Zeile 3977Zeile 4092
/**
* Get the attachment icon for a specific file extension
*

/**
* Get the attachment icon for a specific file extension
*

 * @param string The file extension

 * @param string $ext The file extension

 * @return string The attachment icon
*/
function get_attachment_icon($ext)

 * @return string The attachment icon
*/
function get_attachment_icon($ext)

Zeile 3993Zeile 4108

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


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

		if(defined("IN_ADMINCP"))


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

		{

		{

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

			$attach_icons_schemes[$ext] = parse_url($attachtypes[$ext]['icon']);
if(!empty($attach_icons_schemes[$ext]['scheme']))

			{

			{

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




















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

			}
}

			}
}

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


$icon = $attach_icons_schemes[$ext];











$name = htmlspecialchars_uni($attachtypes[$ext]['name']);
}


$name = htmlspecialchars_uni($attachtypes[$ext]['name']);
}

Zeile 4028Zeile 4154
		}

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

		}

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

 


		$name = $lang->unknown;
}


		$name = $lang->unknown;
}


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

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

 * @param boolean Set to true to only fetch those forums for which users can actually read a thread in.

 * @param boolean $only_readable_threads Set to true to only fetch those forums for which users can actually read a thread in.

 * @return string Comma separated values list of the forum IDs which the user cannot view

 * @return string Comma separated values list of the forum IDs which the user cannot view

 */

 */

function get_unviewable_forums($only_readable_threads=false)
{
global $forum_cache, $permissioncache, $mybb;

function get_unviewable_forums($only_readable_threads=false)
{
global $forum_cache, $permissioncache, $mybb;

Zeile 4066Zeile 4193
		else
{
$perms = $mybb->usergroup;

		else
{
$perms = $mybb->usergroup;

		}

		}


$pwverified = 1;

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


$pwverified = 1;

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

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

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

			{
$pwverified = 0;
}

			{
$pwverified = 0;
}

Zeile 4085Zeile 4212
			$parents = explode(",", $forum['parentlist']);
foreach($parents as $parent)
{

			$parents = explode(",", $forum['parentlist']);
foreach($parents as $parent)
{

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

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

				{
$pwverified = 0;
}

				{
$pwverified = 0;
}

Zeile 4097Zeile 4224
			$unviewable[] = $forum['fid'];
}
}

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

	



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

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

	



	return $unviewableforums;
}

/**
* Fixes mktime for dates earlier than 1970
*

	return $unviewableforums;
}

/**
* Fixes mktime for dates earlier than 1970
*

 * @param string The date format to use
* @param int The year of the date

 * @param string $format The date format to use
* @param int $year The year of the date

 * @return string The correct date format

 * @return string The correct date format

 */

 */

function fix_mktime($format, $year)
{
// Our little work around for the date < 1970 thing.

function fix_mktime($format, $year)
{
// Our little work around for the date < 1970 thing.

Zeile 4123Zeile 4250
/**
* Build the breadcrumb navigation trail from the specified items
*

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

 * @return The formatted breadcrumb navigation trail

 * @return string The formatted breadcrumb navigation trail

 */
function build_breadcrumb()
{

 */
function build_breadcrumb()
{

Zeile 4135Zeile 4262
	$activesep = '';

if(is_array($navbits))

	$activesep = '';

if(is_array($navbits))

	{

	{

		reset($navbits);
foreach($navbits as $key => $navbit)
{

		reset($navbits);
foreach($navbits as $key => $navbit)
{

Zeile 4144Zeile 4271
				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 4174Zeile 4301

eval("\$nav .= \"".$templates->get("nav_bit")."\";");
}


eval("\$nav .= \"".$templates->get("nav_bit")."\";");
}

		}
}


		}
}


	$activesep = '';
$navsize = count($navbits);
$navbit = $navbits[$navsize-1];

	$activesep = '';
$navsize = count($navbits);
$navbit = $navbits[$navsize-1];

Zeile 4195Zeile 4322
/**
* Add a breadcrumb menu item to the list.
*

/**
* Add a breadcrumb menu item to the list.
*

 * @param string The name of the item to add
* @param string The URL of the item to add

 * @param string $name The name of the item to add
* @param string $url The URL of the item to add

 */
function add_breadcrumb($name, $url="")
{

 */
function add_breadcrumb($name, $url="")
{

Zeile 4210Zeile 4337
/**
* Build the forum breadcrumb nagiation (the navigation to a specific forum including all parent forums)
*

/**
* Build the forum breadcrumb nagiation (the navigation to a specific forum including all parent forums)
*

 * @param int The forum ID to build the navigation for
* @param array The multipage drop down array of information


 * @param int $fid The forum ID to build the navigation for
* @param array $multipage The multipage drop down array of information
* @return int Returns 1 in every case. Kept for compatibility

 */
function build_forum_breadcrumb($fid, $multipage=array())
{

 */
function build_forum_breadcrumb($fid, $multipage=array())
{

Zeile 4220Zeile 4348
	if(!$pforumcache)
{
if(!is_array($forum_cache))

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

		{

		{

			cache_forums();
}


			cache_forums();
}


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

if(defined("IN_ARCHIVE"))

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

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 4296Zeile 4424
/**
* Builds a URL to an archive mode page
*

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

 * @param string The type of page (thread|announcement|forum)
* @param int The ID of the item

 * @param string $type The type of page (thread|announcement|forum)
* @param int $id The ID of the item

 * @return string The URL
*/

 * @return string The URL
*/

function build_archive_link($type="", $id="")

function build_archive_link($type="", $id=0)

{
global $mybb;


{
global $mybb;


Zeile 4477Zeile 4605
	echo "</body>";
echo "</html>";
exit;

	echo "</body>";
echo "</html>";
exit;

}

}


/**
* Outputs the correct page headers.


/**
* Outputs the correct page headers.

Zeile 4498Zeile 4626
/**
* Mark specific reported posts of a certain type as dealt with
*

/**
* Mark specific reported posts of a certain type as dealt with
*

 * @param mixed An array or int of the ID numbers you're marking as dealt with
* @param string The type of item the above IDs are for - post, posts, thread, threads, forum, all

 * @param array|int $id An array or int of the ID numbers you're marking as dealt with
* @param string $type The type of item the above IDs are for - post, posts, thread, threads, forum, all

 */
function mark_reports($id, $type="post")
{
global $db, $cache, $plugins;

switch($type)

 */
function mark_reports($id, $type="post")
{
global $db, $cache, $plugins;

switch($type)

	{

	{

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

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

Zeile 4545Zeile 4673
/**
* Fetch a friendly x days, y months etc date stamp from a timestamp
*

/**
* Fetch a friendly x days, y months etc date stamp from a timestamp
*

 * @param int The timestamp
* @param array Array of options

 * @param int $stamp The timestamp
* @param array $options Array of options

 * @return string The friendly formatted timestamp
*/
function nice_time($stamp, $options=array())

 * @return string The friendly formatted timestamp
*/
function nice_time($stamp, $options=array())

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

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

	}


	}


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

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

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

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


if($years == 1)
{
$nicetime['years'] = "1".$lang_year;
}
else if($years > 1)
{
$nicetime['years'] = $years.$lang_years;
}

if($months == 1)
{
$nicetime['months'] = "1".$lang_month;
































// Prevent gross over accuracy ($options parameter will override these)
if($years > 0)
{
$options = array_merge(array(
'days' => false,
'hours' => false,
'minutes' => false,
'seconds' => false
), $options);
}
elseif($months > 0)
{
$options = array_merge(array(
'hours' => false,
'minutes' => false,
'seconds' => false
), $options);
}
elseif($weeks > 0)
{
$options = array_merge(array(
'minutes' => false,
'seconds' => false
), $options);
}
elseif($days > 0)
{
$options = array_merge(array(
'seconds' => false
), $options);
}

if(!isset($options['years']) || $options['years'] !== false)
{
if($years == 1)
{
$nicetime['years'] = "1".$lang_year;
}
else if($years > 1)
{
$nicetime['years'] = $years.$lang_years;
}

	}

	}

	else if($months > 1)



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

	{

	{

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








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

	}


	}


	if($weeks == 1)

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

	{

	{

		$nicetime['weeks'] = "1".$lang_week;
}
else if($weeks > 1)
{
$nicetime['weeks'] = $weeks.$lang_weeks;




		if($weeks == 1)
{
$nicetime['weeks'] = "1".$lang_week;
}
else if($weeks > 1)
{
$nicetime['weeks'] = $weeks.$lang_weeks;
}

	}


	}


	if($days == 1)

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

	{

	{

		$nicetime['days'] = "1".$lang_day;
}
else if($days > 1)
{
$nicetime['days'] = $days.$lang_days;




		if($days == 1)
{
$nicetime['days'] = "1".$lang_day;
}
else if($days > 1)
{
$nicetime['days'] = $days.$lang_days;
}

	}

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

	}

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

Zeile 4690Zeile 4862
/**
* 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
*

 * @param int 1 to reset the row to trow1.

 * @param int $reset 1 to reset the row to trow1.

 * @return string trow1 or trow2 depending on the previous call
*/
function alt_trow($reset=0)

 * @return string trow1 or trow2 depending on the previous call
*/
function alt_trow($reset=0)

Zeile 4714Zeile 4886
/**
* Add a user to a specific additional user group.
*

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

 * @param int The user ID
* @param int The user group ID to join


 * @param int $uid The user ID
* @param int $joingroup The user group ID to join
* @return bool

 */
function join_usergroup($uid, $joingroup)
{

 */
function join_usergroup($uid, $joingroup)
{

Zeile 4766Zeile 4939
/**
* Remove a user from a specific additional user group
*

/**
* Remove a user from a specific additional user group
*

 * @param int The user ID
* @param int The user group ID

 * @param int $uid The user ID
* @param int $leavegroup The user group ID

 */
function leave_usergroup($uid, $leavegroup)
{
global $db, $mybb, $cache;


 */
function leave_usergroup($uid, $leavegroup)
{
global $db, $mybb, $cache;


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


	$user = get_user($uid);









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

$groups = explode(",", $user['additionalgroups']);

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

$groups = explode(",", $user['additionalgroups']);





	if(is_array($groups))
{
foreach($groups as $gid)

	if(is_array($groups))
{
foreach($groups as $gid)

Zeile 4803Zeile 4969

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


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

	{

	{

		$dispupdate = ", displaygroup=usergroup";
}


		$dispupdate = ", displaygroup=usergroup";
}


Zeile 4819Zeile 4985
/**
* Get the current location taking in to account different web serves and systems
*

/**
* Get the current location taking in to account different web serves and systems
*

 * @param boolean True to return as "hidden" fields
* @param array Array of fields to ignore if first argument is true
* @param boolean True to skip all inputs and return only the file path part of the URL

 * @param boolean $fields True to return as "hidden" fields
* @param array $ignore Array of fields to ignore if first argument is true
* @param boolean $quick True to skip all inputs and return only the file path part of the URL

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

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

Zeile 4838Zeile 5004
	elseif(!empty($_SERVER['PHP_SELF']))
{
$location = htmlspecialchars_uni($_SERVER['PHP_SELF']);

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

	}

	}

	elseif(!empty($_ENV['PHP_SELF']))

	elseif(!empty($_ENV['PHP_SELF']))

	{

	{

		$location = htmlspecialchars_uni($_ENV['PHP_SELF']);

		$location = htmlspecialchars_uni($_ENV['PHP_SELF']);

	}

	}

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

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

	}
else

	}
else

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

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

	



	if($quick)
{
return $location;

	if($quick)
{
return $location;

Zeile 4887Zeile 5053
		if(isset($_SERVER['QUERY_STRING']))
{
$location .= "?".htmlspecialchars_uni($_SERVER['QUERY_STRING']);

		if(isset($_SERVER['QUERY_STRING']))
{
$location .= "?".htmlspecialchars_uni($_SERVER['QUERY_STRING']);

		}

		}

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

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

Zeile 4926Zeile 5092
/**
* Build a theme selection menu
*

/**
* Build a theme selection menu
*

 * @param string The name of the menu
* @param int The ID of the selected theme
* @param int The ID of the parent theme to select from
* @param int The current selection depth
* @param boolean Whether or not to override usergroup permissions (true to override)
* @param boolean Whether or not theme select is in the footer (true if it is)
* @param boolean Whether or not to override output based on theme count (true to override)

 * @param string $name The name of the menu
* @param int $selected The ID of the selected theme
* @param int $tid The ID of the parent theme to select from
* @param string $depth The current selection depth
* @param boolean $usergroup_override Whether or not to override usergroup permissions (true to override)
* @param boolean $footer Whether or not theme select is in the footer (true if it is)
* @param boolean $count_override Whether or not to override output based on theme count (true to override)

 * @return string The theme selection list
*/

 * @return string The theme selection list
*/

function build_theme_select($name, $selected="", $tid=0, $depth="", $usergroup_override=false, $footer=false, $count_override=false)

function build_theme_select($name, $selected=-1, $tid=0, $depth="", $usergroup_override=false, $footer=false, $count_override=false)

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


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


Zeile 4953Zeile 5119

if(!is_array($tcache))
{


if(!is_array($tcache))
{

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

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


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


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

Zeile 4963Zeile 5129

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


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

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


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

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

			// 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)
{
if(in_array($agid, $in_groups))
{
$is_allowed = true;
break;
}
}
}


 
			// Show theme if allowed, or if override is on

			// Show theme if allowed, or if override is on

			if($is_allowed || $theme['allowedgroups'] == "all" || $usergroup_override == true)

			if(is_member($theme['allowedgroups']) || $theme['allowedgroups'] == "all" || $usergroup_override == true)

			{
if($theme['tid'] == $selected)
{
$sel = " selected=\"selected\"";

			{
if($theme['tid'] == $selected)
{
$sel = " selected=\"selected\"";

				}

				}


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


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

Zeile 5007Zeile 5150

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


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

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

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

				}
}
}

				}
}
}

Zeile 5018Zeile 5161
		if($footer == true)
{
eval("\$themeselect = \"".$templates->get("footer_themeselector")."\";");

		if($footer == true)
{
eval("\$themeselect = \"".$templates->get("footer_themeselector")."\";");

		}

		}

		else
{
eval("\$themeselect = \"".$templates->get("usercp_themeselector")."\";");

		else
{
eval("\$themeselect = \"".$templates->get("usercp_themeselector")."\";");

Zeile 5030Zeile 5173
	{
return false;
}

	{
return false;
}

 
}

/**
* Get the theme data of a theme id.
*
* @param int $tid The theme id of the theme.
* @return boolean|array False if no valid theme, Array with the theme data otherwise
*/
function get_theme($tid)
{
global $tcache, $db;

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

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

$s_theme = false;

foreach($tcache as $themes)
{
foreach($themes as $theme)
{
if($tid == $theme['tid'])
{
$s_theme = $theme;
break 2;
}
}
}

return $s_theme;

}

/**
* Custom function for htmlspecialchars which takes in to account unicode
*

}

/**
* Custom function for htmlspecialchars which takes in to account unicode
*

 * @param string The string to format

 * @param string $message The string to format

 * @return string The string with htmlspecialchars applied
*/
function htmlspecialchars_uni($message)

 * @return string The string with htmlspecialchars applied
*/
function htmlspecialchars_uni($message)

Zeile 5050Zeile 5230
/**
* Custom function for formatting numbers.
*

/**
* Custom function for formatting numbers.
*

 * @param int The number to format.

 * @param int $number The number to format.

 * @return int The formatted number.
*/
function my_number_format($number)

 * @return int The formatted number.
*/
function my_number_format($number)

Zeile 5086Zeile 5266
/**
* Converts a string of text to or from UTF-8.
*

/**
* Converts a string of text to or from UTF-8.
*

 * @param string The string of text to convert
* @param boolean Whether or not the string is being converted to or from UTF-8 (true if converting to)

 * @param string $str The string of text to convert
* @param boolean $to Whether or not the string is being converted to or from UTF-8 (true if converting to)

 * @return string The converted string
*/
function convert_through_utf8($str, $to=true)

 * @return string The converted string
*/
function convert_through_utf8($str, $to=true)

Zeile 5157Zeile 5337

/**
* DEPRECATED! Please use other alternatives.


/**
* DEPRECATED! Please use other alternatives.

 
 *
* @deprecated
* @param string $message
*
* @return string

 */
function my_wordwrap($message)
{
return $message;

 */
function my_wordwrap($message)
{
return $message;

}

/**
* Workaround for date limitation in PHP to establish the day of a birthday (Provided by meme)

}

/**
* Workaround for date limitation in PHP to establish the day of a birthday (Provided by meme)

 *

 *

 * @param int The month of the birthday
* @param int The day of the birthday
* @param int The year of the bithday

 * @param int $month The month of the birthday
* @param int $day The day of the birthday
* @param int $year The year of the bithday

 * @return int The numeric day of the week for the birthday
*/
function get_weekday($month, $day, $year)
{
$h = 4;

 * @return int The numeric day of the week for the birthday
*/
function get_weekday($month, $day, $year)
{
$h = 4;





	for($i = 1969; $i >= $year; $i--)
{
$j = get_bdays($i);

	for($i = 1969; $i >= $year; $i--)
{
$j = get_bdays($i);

Zeile 5182Zeile 5367
		for($k = 11; $k >= 0; $k--)
{
$l = ($k + 1);

		for($k = 11; $k >= 0; $k--)
{
$l = ($k + 1);





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

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

Zeile 5204Zeile 5389
/**
* Workaround for date limitation in PHP to establish the day of a birthday (Provided by meme)
*

/**
* Workaround for date limitation in PHP to establish the day of a birthday (Provided by meme)
*

 * @param int The year.

 * @param int $in The year.

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

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

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

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

		30,
31,
30,
31,
31,
30,

		30,
31,
30,
31,
31,
30,

		31,
30,
31

		31,
30,
31

Zeile 5226Zeile 5411
}

/**

}

/**

 
 * DEPRECATED! Please use mktime()!

 * Formats a birthday appropriately
*

 * Formats a birthday appropriately
*

 * @param string The PHP date format string
* @param int The month of the birthday
* @param int The day of the birthday
* @param int The year of the birthday
* @param int The weekday of the birthday


 * @deprecated
* @param string $display The PHP date format string
* @param int $bm The month of the birthday
* @param int $bd The day of the birthday
* @param int $by The year of the birthday
* @param int $wd The weekday of the birthday

 * @return string The formatted birthday
*/
function format_bdays($display, $bm, $bd, $by, $wd)

 * @return string The formatted birthday
*/
function format_bdays($display, $bm, $bd, $by, $wd)

Zeile 5268Zeile 5455
	// This needs to be in this specific order
$find = array(
'm',

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

 
		'n',

		'd',
'D',
'y',

		'd',
'D',
'y',

Zeile 5281Zeile 5469

$html = array(
'&#109;',


$html = array(
'&#109;',

 
		'&#110;',

		'&#99;',
'&#68;',
'&#121;',

		'&#99;',
'&#68;',
'&#121;',

Zeile 5297Zeile 5486

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


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

 
		$bm,

		sprintf('%02s', $bd),
($wd == 2 ? my_substr($bdays[$wd], 0, 4) : ($wd == 4 ? my_substr($bdays[$wd], 0, 5) : my_substr($bdays[$wd], 0, 3))),
my_substr($by, 2),

		sprintf('%02s', $bd),
($wd == 2 ? my_substr($bdays[$wd], 0, 4) : ($wd == 4 ? my_substr($bdays[$wd], 0, 5) : my_substr($bdays[$wd], 0, 3))),
my_substr($by, 2),

Zeile 5322Zeile 5512
/**
* Returns the age of a user with specified birthday.
*

/**
* Returns the age of a user with specified birthday.
*

 * @param string The birthday of a user.
* @return float The age of a user with that birthday.

 * @param string $birthday The birthday of a user.
* @return int The age of a user with that birthday.

 */
function get_age($birthday)
{

 */
function get_age($birthday)
{

Zeile 5340Zeile 5530
	if(($month == $bday[1] && $day < $bday[0]) || $month < $bday[1])
{
--$age;

	if(($month == $bday[1] && $day < $bday[0]) || $month < $bday[1])
{
--$age;

	}

	}

	return $age;
}

/**
* Updates the first posts in a thread.
*

	return $age;
}

/**
* Updates the first posts in a thread.
*

 * @param int The thread id for which to update the first post id.

 * @param int $tid The thread id for which to update the first post id.

 */
function update_first_post($tid)
{

 */
function update_first_post($tid)
{

Zeile 5368Zeile 5558
		$firstpost['username'] = $firstpost['postusername'];
}
$firstpost['username'] = $db->escape_string($firstpost['username']);

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





	$update_array = array(
'firstpost' => (int)$firstpost['pid'],
'username' => $firstpost['username'],

	$update_array = array(
'firstpost' => (int)$firstpost['pid'],
'username' => $firstpost['username'],

Zeile 5381Zeile 5571
/**
* Updates the last posts in a thread.
*

/**
* Updates the last posts in a thread.
*

 * @param int The thread id for which to update the last post id.

 * @param int $tid The thread id for which to update the last post id.

 */
function update_last_post($tid)
{

 */
function update_last_post($tid)
{

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

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

 * @param string The string to check the length of.

 * @param string $string The string to check the length of.

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

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

Zeile 5440Zeile 5630
	global $lang;

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

	global $lang;

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





	if(strtolower($lang->settings['charset']) == "utf-8")

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

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

if(function_exists("mb_strlen"))

	$string = trim($string);

if(function_exists("mb_strlen"))

	{

	{

		$string_length = mb_strlen($string);

		$string_length = mb_strlen($string);

	}
else
{

	}
else
{

		$string_length = strlen($string);
}


		$string_length = strlen($string);
}


Zeile 5467Zeile 5657
/**
* Cuts a string at a specified point, mb strings accounted for
*

/**
* Cuts a string at a specified point, mb strings accounted for
*

 * @param string The string to cut.
* @param int Where to cut
* @param int (optional) How much to cut
* @param bool (optional) Properly handle HTML entities?
* @return int The cut part of the string.

 * @param string $string The string to cut.
* @param int $start Where to cut
* @param int $length (optional) How much to cut
* @param bool $handle_entities (optional) Properly handle HTML entities?
* @return string The cut part of the string.

 */

 */

function my_substr($string, $start, $length="", $handle_entities = false)

function my_substr($string, $start, $length=null, $handle_entities = false)

{
if($handle_entities)
{

{
if($handle_entities)
{

Zeile 5481Zeile 5671
	}
if(function_exists("mb_substr"))
{

	}
if(function_exists("mb_substr"))
{

		if($length != "")

		if($length != null)

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

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

Zeile 5492Zeile 5682
	}
else
{

	}
else
{

		if($length != "")

		if($length != null)

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

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

Zeile 5512Zeile 5702
/**
* Lowers the case of a string, mb strings accounted for
*

/**
* Lowers the case of a string, mb strings accounted for
*

 * @param string The string to lower.
* @return int The lowered string.

 * @param string $string The string to lower.
* @return string The lowered string.

 */
function my_strtolower($string)
{

 */
function my_strtolower($string)
{

Zeile 5532Zeile 5722
/**
* Finds a needle in a haystack and returns it position, mb strings accounted for
*

/**
* Finds a needle in a haystack and returns it position, mb strings accounted for
*

 * @param string String to look in (haystack)
* @param string What to look for (needle)
* @param int (optional) How much to offset
* @return int false on needle not found, integer position if found

 * @param string $haystack String to look in (haystack)
* @param string $needle What to look for (needle)
* @param int $offset (optional) How much to offset
* @return int|bool false on needle not found, integer position if found

 */
function my_strpos($haystack, $needle, $offset=0)
{

 */
function my_strpos($haystack, $needle, $offset=0)
{

Zeile 5559Zeile 5749
/**
* Ups the case of a string, mb strings accounted for
*

/**
* Ups the case of a string, mb strings accounted for
*

 * @param string The string to up.
* @return int The uped string.

 * @param string $string The string to up.
* @return string The uped string.

 */
function my_strtoupper($string)
{

 */
function my_strtoupper($string)
{

Zeile 5579Zeile 5769
/**
* Returns any html entities to their original character
*

/**
* Returns any html entities to their original character
*

 * @param string The string to un-htmlentitize.
* @return int The un-htmlentitied' string.

 * @param string $string The string to un-htmlentitize.
* @return string The un-htmlentitied' string.

 */
function unhtmlentities($string)
{
// Replace numeric entities

 */
function unhtmlentities($string)
{
// Replace numeric entities

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

	$string = preg_replace_callback('~&#x([0-9a-f]+);~i', 'unichr_callback1', $string);
$string = preg_replace_callback('~&#([0-9]+);~', 'unichr_callback2', $string);


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


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

Zeile 5598Zeile 5788
/**
* Returns any ascii to it's character (utf-8 safe).
*

/**
* Returns any ascii to it's character (utf-8 safe).
*

 * @param string The ascii to characterize.
* @return int The characterized ascii.

 * @param int $c The ascii to characterize.
* @return string|bool The characterized ascii. False on failure

 */
function unichr($c)
{

 */
function unichr($c)
{

Zeile 5626Zeile 5816
	{
return false;
}

	{
return false;
}

 
}

/**
* Returns any ascii to it's character (utf-8 safe).
*
* @param array $matches Matches.
* @return string|bool The characterized ascii. False on failure
*/
function unichr_callback1($matches)
{
return unichr(hexdec($matches[1]));
}

/**
* Returns any ascii to it's character (utf-8 safe).
*
* @param array $matches Matches.
* @return string|bool The characterized ascii. False on failure
*/
function unichr_callback2($matches)
{
return unichr($matches[1]);

}

/**
* Get the event poster.
*

}

/**
* Get the event poster.
*

 * @param array The event data array.

 * @param array $event The event data array.

 * @return string The link to the event poster.
*/
function get_event_poster($event)
{

 * @return string The link to the event poster.
*/
function get_event_poster($event)
{

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

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

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

}

}


/**
* Get the event date.
*


/**
* Get the event date.
*

 * @param array The event data array.

 * @param array $event The event data array.

 * @return string The event date.
*/
function get_event_date($event)
{
global $mybb;

 * @return string The event date.
*/
function get_event_date($event)
{
global $mybb;





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

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

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

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

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

return $event_date;

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

return $event_date;

Zeile 5661Zeile 5874
/**
* Get the profile link.
*

/**
* Get the profile link.
*

 * @param int The user id of the profile.

 * @param int $uid The user id of the profile.

 * @return string The url to the profile.
*/
function get_profile_link($uid=0)

 * @return string The url to the profile.
*/
function get_profile_link($uid=0)

Zeile 5673Zeile 5886
/**
* Get the announcement link.
*

/**
* Get the announcement link.
*

 * @param int The announement id of the announcement.

 * @param int $aid The announement id of the announcement.

 * @return string The url to the announcement.
*/
function get_announcement_link($aid=0)

 * @return string The url to the announcement.
*/
function get_announcement_link($aid=0)

Zeile 5685Zeile 5898
/**
* Build the profile link.
*

/**
* Build the profile link.
*

 * @param string The Username of the profile.
* @param int The user id of the profile.
* @param string The target frame
* @param string Any onclick javascript.

 * @param string $username The Username of the profile.
* @param int $uid The user id of the profile.
* @param string $target The target frame
* @param string $onclick Any onclick javascript.

 * @return string The complete profile link.
*/
function build_profile_link($username="", $uid=0, $target="", $onclick="")

 * @return string The complete profile link.
*/
function build_profile_link($username="", $uid=0, $target="", $onclick="")

Zeile 5696Zeile 5909
	global $mybb, $lang;

if(!$username && $uid == 0)

	global $mybb, $lang;

if(!$username && $uid == 0)

	{

	{

		// Return Guest phrase for no UID, no guest nickname

		// Return Guest phrase for no UID, no guest nickname

		return $lang->guest;

		return htmlspecialchars_uni($lang->guest);

	}
elseif($uid == 0)
{

	}
elseif($uid == 0)
{

Zeile 5716Zeile 5929
		if(!empty($onclick))
{
$onclick = " onclick=\"{$onclick}\"";

		if(!empty($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 5725Zeile 5938
/**
* Build the forum link.
*

/**
* Build the forum link.
*

 * @param int The forum id of the forum.
* @param int (Optional) The page number of the forum.

 * @param int $fid The forum id of the forum.
* @param int $page (Optional) The page number of the forum.

 * @return string The url to the forum.
*/
function get_forum_link($fid, $page=0)

 * @return string The url to the forum.
*/
function get_forum_link($fid, $page=0)

Zeile 5747Zeile 5960
/**
* Build the thread link.
*

/**
* Build the thread link.
*

 * @param int The thread id of the thread.
* @param int (Optional) The page number of the thread.
* @param string (Optional) The action we're performing (ex, lastpost, newpost, etc)

 * @param int $tid The thread id of the thread.
* @param int $page (Optional) The page number of the thread.
* @param string $action (Optional) The action we're performing (ex, lastpost, newpost, etc)

 * @return string The url to the thread.
*/
function get_thread_link($tid, $page=0, $action='')

 * @return string The url to the thread.
*/
function get_thread_link($tid, $page=0, $action='')

Zeile 5788Zeile 6001
/**
* Build the post link.
*

/**
* Build the post link.
*

 * @param int The post ID of the post
* @param int The thread id of the post.

 * @param int $pid The post ID of the post
* @param int $tid The thread id of the post.

 * @return string The url to the post.
*/
function get_post_link($pid, $tid=0)

 * @return string The url to the post.
*/
function get_post_link($pid, $tid=0)

Zeile 5810Zeile 6023
/**
* Build the event link.
*

/**
* Build the event link.
*

 * @param int The event ID of the event

 * @param int $eid The event ID of the event

 * @return string The URL of the event
*/
function get_event_link($eid)

 * @return string The URL of the event
*/
function get_event_link($eid)

Zeile 5822Zeile 6035
/**
* Build the link to a specified date on the calendar
*

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

 * @param int The ID of the calendar
* @param int The year
* @param int The month
* @param int The day (optional)

 * @param int $calendar The ID of the calendar
* @param int $year The year
* @param int $month The month
* @param int $day The day (optional)

 * @return string The URL of the calendar
*/
function get_calendar_link($calendar, $year=0, $month=0, $day=0)

 * @return string The URL of the calendar
*/
function get_calendar_link($calendar, $year=0, $month=0, $day=0)

Zeile 5859Zeile 6072
/**
* Build the link to a specified week on the calendar
*

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

 * @param int The ID of the calendar
* @param int The year
* @param int The week

 * @param int $calendar The ID of the calendar
* @param int $week The week


 * @return string The URL of the calendar
*/
function get_calendar_week_link($calendar, $week)

 * @return string The URL of the calendar
*/
function get_calendar_week_link($calendar, $week)

Zeile 5878Zeile 6090
/**
* Get the user data of an user id.
*

/**
* Get the user data of an user id.
*

 * @param int The user id of the user.

 * @param int $uid The user id of the user.

 * @return array The users data
*/
function get_user($uid)

 * @return array The users data
*/
function get_user($uid)

Zeile 5909Zeile 6121
/**
* Get the user data of an user username.
*

/**
* Get the user data of an user username.
*

 * @param string The user username of the user.


 * @param string $username The user username of the user.
* @param array $options

 * @return array The users data
*/
function get_user_by_username($username, $options=array())

 * @return array The users data
*/
function get_user_by_username($username, $options=array())

Zeile 5960Zeile 6173
	if(isset($options['exists']))
{
return (bool)$db->num_rows($query);

	if(isset($options['exists']))
{
return (bool)$db->num_rows($query);

	}

	}


return $db->fetch_array($query);
}


return $db->fetch_array($query);
}





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

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

 * @param int The forum id of the forum.
* @param int (Optional) If set to 1, will override the active forum status
* @return array The database row of a forum.

 * @param int $fid The forum id of the forum.
* @param int $active_override (Optional) If set to 1, will override the active forum status
* @return array|bool The database row of a forum. False on failure

 */
function get_forum($fid, $active_override=0)
{

 */
function get_forum($fid, $active_override=0)
{

Zeile 5978Zeile 6191
	static $forum_cache;

if(!isset($forum_cache) || is_array($forum_cache))

	static $forum_cache;

if(!isset($forum_cache) || is_array($forum_cache))

	{

	{

		$forum_cache = $cache->read("forums");
}


		$forum_cache = $cache->read("forums");
}


Zeile 6008Zeile 6221
/**
* Get the thread of a thread id.
*

/**
* Get the thread of a thread id.
*

 * @param int The thread id of the thread.
* @param boolean Whether or not to recache the thread.
* @return string The database row of the thread.

 * @param int $tid The thread id of the thread.
* @param boolean $recache Whether or not to recache the thread.
* @return array|bool The database row of the thread. False on failure

 */
function get_thread($tid, $recache = false)
{

 */
function get_thread($tid, $recache = false)
{

Zeile 6022Zeile 6235
	if(isset($thread_cache[$tid]) && !$recache)
{
return $thread_cache[$tid];

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

	}
else

	}
else

	{
$query = $db->simple_select("threads", "*", "tid = '{$tid}'");
$thread = $db->fetch_array($query);

	{
$query = $db->simple_select("threads", "*", "tid = '{$tid}'");
$thread = $db->fetch_array($query);

Zeile 6032Zeile 6245
		{
$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;
}
}

}

/**
* Get the post of a post id.
*

}

/**
* Get the post of a post id.
*

 * @param int The post id of the post.
* @param boolean Whether or not to recache the post.
* @param array An array of fields to gather from the database
* @return string The database row of the post.

 * @param int $pid The post id of the post.
* @return array|bool The database row of the post. False on failure



 */
function get_post($pid)
{

 */
function get_post($pid)
{

Zeile 6084Zeile 6295
 * @return string The comma separated values of the inactivate forum.
*/
function get_inactive_forums()

 * @return string The comma separated values of the inactivate forum.
*/
function get_inactive_forums()

{

{

	global $forum_cache, $cache;

	global $forum_cache, $cache;





	if(!$forum_cache)
{
cache_forums();

	if(!$forum_cache)
{
cache_forums();

Zeile 6097Zeile 6308
	foreach($forum_cache as $fid => $forum)
{
if($forum['active'] == 0)

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

		{

		{

			$inactive[] = $fid;
foreach($forum_cache as $fid1 => $forum1)
{

			$inactive[] = $fid;
foreach($forum_cache as $fid1 => $forum1)
{

Zeile 6108Zeile 6319
			}
}
}

			}
}
}

	



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

return $inactiveforums;

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

return $inactiveforums;

Zeile 6117Zeile 6328
/**
* Checks to make sure a user has not tried to login more times than permitted
*

/**
* Checks to make sure a user has not tried to login more times than permitted
*

 * @param bool (Optional) Stop execution if it finds an error with the login. Default is True
* @return bool Number of logins when success, false if failed.

 * @param bool $fatal (Optional) Stop execution if it finds an error with the login. Default is True
* @return bool|int Number of logins when success, false if failed.

 */
function login_attempt_check($fatal = true)
{

 */
function login_attempt_check($fatal = true)
{

Zeile 6127Zeile 6338
	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.

// Use cookie if possible, otherwise use session

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

Zeile 6141Zeile 6352
	}

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

	}

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

	{

	{

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

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





	// Work out if the user has had more than the allowed number of login attempts
if($loginattempts > $mybb->settings['failedlogincount'])
{

	// Work out if the user has had more than the allowed number of login attempts
if($loginattempts > $mybb->settings['failedlogincount'])
{

Zeile 6155Zeile 6366
		if(empty($mybb->cookies['failedlogin']))
{
$failedtime = $now;

		if(empty($mybb->cookies['failedlogin']))
{
$failedtime = $now;

		}

		}

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

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

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

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

			}

return false;

			}

return false;

		}
}

// User can attempt another login
return $loginattempts;

		}
}

// User can attempt another login
return $loginattempts;

}

}


/**
* Validates the format of an email address.
*


/**
* Validates the format of an email address.
*

 * @param string The string to check.

 * @param string $email The string to check.

 * @return boolean True when valid, false when invalid.
*/
function validate_email_format($email)

 * @return boolean True when valid, false when invalid.
*/
function validate_email_format($email)

{

{

	if(strpos($email, ' ') !== false)
{
return false;
}
// Valid local characters for email addresses: http://www.remote.org/jochen/mail/info/chars.html
return preg_match("/^[a-zA-Z0-9&*+\-_.{}~^\?=\/]+@[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]{2,}$/si", $email);

	if(strpos($email, ' ') !== false)
{
return false;
}
// Valid local characters for email addresses: http://www.remote.org/jochen/mail/info/chars.html
return preg_match("/^[a-zA-Z0-9&*+\-_.{}~^\?=\/]+@[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]{2,}$/si", $email);

}

/**

}

/**

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

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

 * @param string The email to check.
* @param string User ID of the user (updating only)

 * @param string $email The email to check.
* @param int $uid User ID of the user (updating only)

 * @return boolean True when in use, false when not.
*/

 * @return boolean True when in use, false when not.
*/

function email_already_in_use($email, $uid="")

function email_already_in_use($email, $uid=0)

{
global $db;


{
global $db;


Zeile 6258Zeile 6469
{
global $db, $mybb;


{
global $db, $mybb;


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

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

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















	$settings = null;

	$settings = '';

	while($setting = $db->fetch_array($query))
{
$mybb->settings[$setting['name']] = $setting['value'];

	while($setting = $db->fetch_array($query))
{
$mybb->settings[$setting['name']] = $setting['value'];

Zeile 6282Zeile 6483
	}

$settings = "<"."?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n$settings\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);
@fclose($file);


file_put_contents(MYBB_ROOT.'inc/settings.php', $settings, LOCK_EX);



$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.
*

 * @param string Incoming terms to highlight

 * @param string $terms Incoming terms to highlight

 * @return array PREG compatible array of terms
*/
function build_highlight_array($terms)

 * @return array PREG compatible array of terms
*/
function build_highlight_array($terms)

Zeile 6379Zeile 6579

// Sort the word array by length. Largest terms go first and work their way down to the smallest term.
// This resolves problems like "test tes" where "tes" will be highlighted first, then "test" can't be highlighted because of the changed html


// Sort the word array by length. Largest terms go first and work their way down to the smallest term.
// This resolves problems like "test tes" where "tes" will be highlighted first, then "test" can't be highlighted because of the changed html

	usort($words, create_function('$a,$b', 'return strlen($b) - strlen($a);'));

	usort($words, 'build_highlight_array_sort');


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


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

Zeile 6401Zeile 6601
	}

return $highlight_cache;

	}

return $highlight_cache;

 
}

/**
* Sort the word array by length. Largest terms go first and work their way down to the smallest term.
*
* @param string $a First word.
* @param string $b Second word.
* @return integer Result of comparison function.
*/
function build_highlight_array_sort($a, $b)
{
return strlen($b) - strlen($a);

}

/**
* Converts a decimal reference of a character to its UTF-8 equivalent
* (Code by Anne van Kesteren, http://annevankesteren.nl/2005/05/character-references)
*

}

/**
* Converts a decimal reference of a character to its UTF-8 equivalent
* (Code by Anne van Kesteren, http://annevankesteren.nl/2005/05/character-references)
*

 * @param string Decimal value of a character reference


 * @param int $src Decimal value of a character reference
* @return string|bool

 */
function dec_to_utf8($src)
{

 */
function dec_to_utf8($src)
{

Zeile 6451Zeile 6664
/**
* Checks if a username has been disallowed for registration/use.
*

/**
* Checks if a username has been disallowed for registration/use.
*

 * @param string The username
* @param boolean True if the 'last used' dateline should be updated if a match is found.

 * @param string $username The username
* @param boolean $update_lastuse True if the 'last used' dateline should be updated if a match is found.

 * @return boolean True if banned, false if not banned
*/
function is_banned_username($username, $update_lastuse=false)

 * @return boolean True if banned, false if not banned
*/
function is_banned_username($username, $update_lastuse=false)

Zeile 6480Zeile 6693
/**
* Check if a specific email address has been banned.
*

/**
* Check if a specific email address has been banned.
*

 * @param string The email address.
* @param boolean True if the 'last used' dateline should be updated if a match is found.

 * @param string $email The email address.
* @param boolean $update_lastuse True if the 'last used' dateline should be updated if a match is found.

 * @return boolean True if banned, false if not banned
*/
function is_banned_email($email, $update_lastuse=false)

 * @return boolean True if banned, false if not banned
*/
function is_banned_email($email, $update_lastuse=false)

Zeile 6523Zeile 6736
/**
* Checks if a specific IP address has been banned.
*

/**
* Checks if a specific IP address has been banned.
*

 * @param string The IP address.
* @param boolean True if the 'last used' dateline should be updated if a match is found.

 * @param string $ip_address The IP address.
* @param boolean $update_lastuse True if the 'last used' dateline should be updated if a match is found.

 * @return boolean True if banned, false if not banned.
*/
function is_banned_ip($ip_address, $update_lastuse=false)

 * @return boolean True if banned, false if not banned.
*/
function is_banned_ip($ip_address, $update_lastuse=false)

Zeile 6571Zeile 6784
	}

// Still here - good ip

	}

// Still here - good ip

	return false;
}

/**
* Build a time zone selection list.
*
* @param string The name of the select
* @param int The selected time zone (defaults to GMT)
* @param boolean True to generate a "short" list with just timezone and current time
*/
function build_timezone_select($name, $selected=0, $short=false)
{
global $mybb, $lang, $templates;

	return false;
}
















 
/**
* Returns an array of supported timezones
*
* @return string[] Key is timezone offset, Value the language description
*/
function get_supported_timezones()
{
global $lang;

	$timezones = array(
"-12" => $lang->timezone_gmt_minus_1200,
"-11" => $lang->timezone_gmt_minus_1100,

	$timezones = array(
"-12" => $lang->timezone_gmt_minus_1200,
"-11" => $lang->timezone_gmt_minus_1100,

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

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

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

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

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

Zeile 6626Zeile 6838
		"13" => $lang->timezone_gmt_1300,
"14" => $lang->timezone_gmt_1400
);

		"13" => $lang->timezone_gmt_1300,
"14" => $lang->timezone_gmt_1400
);

 
	return $timezones;
}

/**
* Build a time zone selection list.
*
* @param string $name The name of the select
* @param int $selected The selected time zone (defaults to GMT)
* @param boolean $short True to generate a "short" list with just timezone and current time
* @return string
*/
function build_timezone_select($name, $selected=0, $short=false)
{
global $mybb, $lang, $templates;

$timezones = get_supported_timezones();


$selected = str_replace("+", "", $selected);
foreach($timezones as $timezone => $label)


$selected = str_replace("+", "", $selected);
foreach($timezones as $timezone => $label)

Zeile 6646Zeile 6874
					$label = "+{$label}";
}
if(strpos($timezone, ".") !== false)

					$label = "+{$label}";
}
if(strpos($timezone, ".") !== false)

				{

				{

					$label = str_replace(".", ":", $label);
$label = str_replace(":5", ":30", $label);
$label = str_replace(":75", ":45", $label);

					$label = str_replace(".", ":", $label);
$label = str_replace(":5", ":30", $label);
$label = str_replace(":75", ":45", $label);

Zeile 6654Zeile 6882
				else
{
$label .= ":00";

				else
{
$label .= ":00";

				}

				}

			}
$time_in_zone = my_date($mybb->settings['timeformat'], TIME_NOW, $timezone);
$label = $lang->sprintf($lang->timezone_gmt_short, $label." ", $time_in_zone);

			}
$time_in_zone = my_date($mybb->settings['timeformat'], TIME_NOW, $timezone);
$label = $lang->sprintf($lang->timezone_gmt_short, $label." ", $time_in_zone);

Zeile 6670Zeile 6898
/**
* Fetch the contents of a remote file.
*

/**
* Fetch the contents of a remote file.
*

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


 * @param string $url The URL of the remote file
* @param array $post_data The array of post data
* @param int $max_redirects Number of maximum redirects
* @return string|bool The remote file contents. False on failure

 */

 */

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

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

{

{

 
	global $mybb, $config;

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

$url_components = @parse_url($url);

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

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

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

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

$packed_address = my_inet_pton($destination_address);

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


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

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

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

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

	}


	}


	if(function_exists("curl_init"))
{

	if(function_exists("curl_init"))
{

 
		$fetch_header = $max_redirects > 0;


		$ch = curl_init();

		$ch = curl_init();

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


































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

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

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

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


		if(!empty($post_body))
{

		if(!empty($post_body))
{

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






























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

curl_setopt_array($ch, $curlopt);

$response = curl_exec($ch);

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

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

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

		}

		}

		$data = curl_exec($ch);



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

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

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

		if(!isset($url_components['path']))














		{

		{

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

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

		}

		}







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


		$scheme = '';


		$scheme = '';


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










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

if(function_exists('stream_context_create'))

		{

		{

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











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

			{

			{

				$url['port'] = 443;






				$context = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
));

			}

			}

 

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

		}


		}


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		}
else
{

		}
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);
if(!@fwrite($fp, $headers))

			// 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);
if(!@fwrite($fp, $headers))

		{
return false;
}




		{
return false;
}

$data = null;


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

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

 


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

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

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

















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

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

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

return $data;
}

	else

	else

	{

	{

		return false;
}

		return false;
}

 
}

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

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

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

return $addresses;
}

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

return false;

}

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

}

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

 *
* @param int The user ID to check against the list of super admins

 *
* @param int $uid The user ID to check against the list of super admins

 * @return boolean True if a super admin, false if not
*/
function is_super_admin($uid)

 * @return boolean True if a super admin, false if not
*/
function is_super_admin($uid)

Zeile 6810Zeile 7241
		return false;
}
else

		return false;
}
else

	{

	{

		return true;
}
}

		return true;
}
}

Zeile 6820Zeile 7251
 * Originates from frostschutz's PluginLibrary
* github.com/frostschutz
*

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

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

 * @param array|int|string A selection of groups (as array or comma seperated) to check or -1 for any group
* @param bool|array|int False assumes the current user. Otherwise an user array or an id can be passed

 * @return array Array of groups specified in the first param to which the user belongs
*/
function is_member($groups, $user = false)
{
global $mybb;

 * @return array Array of groups specified in the first param to which the user belongs
*/
function is_member($groups, $user = false)
{
global $mybb;

	



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

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

	}	

	}


if($user == false)
{


if($user == false)
{

Zeile 6874Zeile 7305
 * 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
*

 * @param string The delimeter to split by
* @param string The string to split
* @param string The escape character or string if we have one.

 * @param string $delimeter The delimeter to split by
* @param string $string The string to split
* @param string $escape The escape character or string if we have one.

 * @return array Array of split string
*/
function escaped_explode($delimeter, $string, $escape="")

 * @return array Array of split string
*/
function escaped_explode($delimeter, $string, $escape="")

Zeile 6935Zeile 7366
 * DEPRECATED! Please use IPv6 compatible fetch_ip_range!
* Fetch an IPv4 long formatted range for searching IPv4 IP addresses.
*

 * DEPRECATED! Please use IPv6 compatible fetch_ip_range!
* Fetch an IPv4 long formatted range for searching IPv4 IP addresses.
*

 * @param string The IP address to convert to a range based LONG
* @rturn mixed If a full IP address is provided, the ip2long equivalent, otherwise an array of the upper & lower extremities of the IP


 * @deprecated
* @param string $ip The IP address to convert to a range based LONG
* @return string|array If a full IP address is provided, the ip2long equivalent, otherwise an array of the upper & lower extremities of the IP

 */
function fetch_longipv4_range($ip)
{

 */
function fetch_longipv4_range($ip)
{

Zeile 7021Zeile 7453
/**
* Format a ban length in to a UNIX timestamp.
*

/**
* Format a ban length in to a UNIX timestamp.
*

 * @param string The ban length string
* @param int The optional UNIX timestamp, if 0, current time is used.

 * @param string $date The ban length string
* @param int $stamp The optional UNIX timestamp, if 0, current time is used.

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

Zeile 7037Zeile 7469
	$n[1] += $d[0];
$n[2] += $d[1];
$n[3] += $d[2];

	$n[1] += $d[0];
$n[2] += $d[1];
$n[3] += $d[2];

	return mktime(date("G"), date("i"), 0, $n[2], $n[1], $n[3]);

	return mktime(date("G", $stamp), date("i", $stamp), 0, $n[2], $n[1], $n[3]);

}

/**
* Expire old warnings in the database.
*

}

/**
* Expire old warnings in the database.
*

 
 * @return bool

 */
function expire_warnings()
{

 */
function expire_warnings()
{

Zeile 7060Zeile 7493
/**
* Custom chmod function to fix problems with hosts who's server configurations screw up umasks
*

/**
* Custom chmod function to fix problems with hosts who's server configurations screw up umasks
*

 * @param string The file to chmod
* @param string The mode to chmod(i.e. 0666)


 * @param string $file The file to chmod
* @param string $mode The mode to chmod(i.e. 0666)
* @return bool

 */
function my_chmod($file, $mode)
{

 */
function my_chmod($file, $mode)
{

Zeile 7082Zeile 7516
/**
* Custom rmdir function to loop through an entire directory and delete all files/folders within
*

/**
* Custom rmdir function to loop through an entire directory and delete all files/folders within
*

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


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

 */
function my_rmdir_recursive($path, $ignore=array())
{

 */
function my_rmdir_recursive($path, $ignore=array())
{

Zeile 7123Zeile 7558
/**
* Counts the number of subforums in a array([pid][disporder][fid]) starting from the pid
*

/**
* Counts the number of subforums in a array([pid][disporder][fid]) starting from the pid
*

 * @param array The array of forums

 * @param array $array The array of forums

 * @return integer The number of sub forums
*/
function subforums_count($array)

 * @return integer The number of sub forums
*/
function subforums_count($array)

Zeile 7142Zeile 7577
 * Fix for PHP's ip2long to guarantee a 32-bit signed integer value is produced (this is aimed
* at 64-bit versions of PHP)
*

 * Fix for PHP's ip2long to guarantee a 32-bit signed integer value is produced (this is aimed
* at 64-bit versions of PHP)
*

 * @param string The IP to convert


 * @deprecated
* @param string $ip The IP to convert

 * @return integer IP in 32-bit signed format
*/
function my_ip2long($ip)

 * @return integer IP in 32-bit signed format
*/
function my_ip2long($ip)

Zeile 7171Zeile 7607
 * DEPRECATED! Please use IPv6 compatible my_inet_ntop!
* As above, fix for PHP's long2ip on 64-bit versions
*

 * DEPRECATED! Please use IPv6 compatible my_inet_ntop!
* As above, fix for PHP's long2ip on 64-bit versions
*

 * @param integer The IP to convert (will accept 64-bit IPs as well)


 * @deprecated
* @param integer $long The IP to convert (will accept 64-bit IPs as well)

 * @return string IP in IPv4 format
*/
function my_long2ip($long)

 * @return string IP in IPv4 format
*/
function my_long2ip($long)

Zeile 7188Zeile 7625
/**
* Converts a human readable IP address to its packed in_addr representation
*

/**
* Converts a human readable IP address to its packed in_addr representation
*

 * @param string The IP to convert

 * @param string $ip The IP to convert

 * @return string IP in 32bit or 128bit binary format
*/
function my_inet_pton($ip)

 * @return string IP in 32bit or 128bit binary format
*/
function my_inet_pton($ip)

Zeile 7241Zeile 7678
/**
* Converts a packed internet address to a human readable representation
*

/**
* Converts a packed internet address to a human readable representation
*

 * @param string IP in 32bit or 128bit binary format

 * @param string $ip IP in 32bit or 128bit binary format

 * @return string IP in human readable format
*/
function my_inet_ntop($ip)

 * @return string IP in human readable format
*/
function my_inet_ntop($ip)

Zeile 7283Zeile 7720
/**
* Fetch an binary formatted range for searching IPv4 and IPv6 IP addresses.
*

/**
* Fetch an binary formatted range for searching IPv4 and IPv6 IP addresses.
*

 * @param string The IP address to convert to a range
* @rturn mixed If a full IP address is provided, the in_addr representation, otherwise an array of the upper & lower extremities of the IP

 * @param string $ipaddress The IP address to convert to a range
* @return string|array|bool If a full IP address is provided, the in_addr representation, otherwise an array of the upper & lower extremities of the IP. False on failure

 */
function fetch_ip_range($ipaddress)
{

 */
function fetch_ip_range($ipaddress)
{

Zeile 7426Zeile 7863
/**
* Processes a checksum list on MyBB files and returns a result set
*

/**
* Processes a checksum list on MyBB files and returns a result set
*

 * @param array The array of checksums and their corresponding files
* @param int The count of files

 * @param string $path The base path
* @param int $count The count of files

 * @return array The bad files
*/
function verify_files($path=MYBB_ROOT, $count=0)

 * @return array The bad files
*/
function verify_files($path=MYBB_ROOT, $count=0)

Zeile 7435Zeile 7872
	global $mybb, $checksums, $bad_verify_files;

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

	global $mybb, $checksums, $bad_verify_files;

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

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

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

	$ignore_ext = array("attach");

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

	$ignore_ext = array("attach");

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

Zeile 7522Zeile 7959
/**
* Returns a signed value equal to an integer
*

/**
* Returns a signed value equal to an integer
*

 * @param int The integer

 * @param int $int The integer

 * @return string The signed equivalent
*/
function signed($int)

 * @return string The signed equivalent
*/
function signed($int)

Zeile 7538Zeile 7975
}

/**

}

/**

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

 * Returns a securely generated seed

 *

 *

 * @param int Length of the seed bytes (8 is default. Provides good cryptographic variance)
* @return int An integer equivalent of a secure hexadecimal seed

 * @return string A secure binary seed


 */

 */

function secure_seed_rng($count=8)

function secure_binary_seed_rng($bytes)

{

{

	$output = '';
// DIRECTORY_SEPARATOR checks if running windows
if(DIRECTORY_SEPARATOR != '\\')
{
// Unix/Linux
// Use OpenSSL when available
if(function_exists('openssl_random_pseudo_bytes'))
{
$output = openssl_random_pseudo_bytes($count);
}
// Try mcrypt
elseif(function_exists('mcrypt_create_iv'))

	$output = null;

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








		{

		{

			$output = mcrypt_create_iv($count, MCRYPT_DEV_URANDOM);
}
// Try /dev/urandom
elseif(@is_readable('/dev/urandom') && ($handle = @fopen('/dev/urandom', 'rb')))
{
$output = @fread($handle, $count);
@fclose($handle);

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






		}
}

		}
}

	else



if(strlen($output) < $bytes)

	{

	{

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

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




		{

		{

			$output = openssl_random_pseudo_bytes($count);


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

		}

		}

		// Try mcrypt
elseif(function_exists('mcrypt_create_iv'))





























	}
else
{
return $output;
}

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

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

if(strlen($output) < $bytes)
{
if(function_exists('openssl_random_pseudo_bytes'))

		{

		{

			$output = mcrypt_create_iv($count, MCRYPT_RAND);









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

		}

		}

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








	}
else
{
return $output;
}

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

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

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

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

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

				}
} catch (Exception $e) {
}
}

				}
} catch (Exception $e) {
}
}

 
	}
else
{
return $output;

	}


	}


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

	if(strlen($output) < $bytes)


	{

	{

		$output = '';


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


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


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



		$rounds = ceil($bytes / 16);

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

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

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

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

			$output .= md5($unique_state);

		}

		}

	}

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

 




/**
* 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 boolean True forces it to reseed the RNG first
* @return int An integer equivalent of a secure hexadecimal seed
*/
function my_rand($min=null, $max=null, $force_seed=false)
{
static $seeded = false;
static $obfuscator = 0;

if($seeded == false || $force_seed == true)
{
mt_srand(secure_seed_rng());
$seeded = true;

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

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



















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

// 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)
{
return $min + (int)((float)($distance + 1) * (float)(mt_rand() ^ $obfuscator) / (mt_getrandmax() + 1));
}
else
{
return mt_rand($min, $max);
}
}

		return $output;
}




















	else
{

	else
{

		$val = mt_rand() ^ $obfuscator;
return $val;

		return $output;


	}
}

/**

	}
}

/**

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



































































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

do
{

$output = secure_binary_seed_rng($bytes);

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

} while($output > PHP_INT_MAX);

return $output;
}

/**
* Generates a cryptographically secure random number.
*
* @param int $min Optional lowest value to be returned (default: 0)
* @param int $max Optional highest value to be returned (default: PHP_INT_MAX)
*/
function my_rand($min=0, $max=PHP_INT_MAX)
{
// backward compatibility
if($min === null || $max === null || $max < $min)
{
$min = 0;
$max = PHP_INT_MAX;
}

if(version_compare(PHP_VERSION, '7.0', '>='))
{
try
{
$result = random_int($min, $max);
} catch (Exception $e) {
}

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

$seed = secure_seed_rng();

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

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

 * from http://kb.mozillazine.org/Network.IDN.blacklist_chars
*

 * from http://kb.mozillazine.org/Network.IDN.blacklist_chars
*

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

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

 * @return string The trimmed string
*/

 * @return string The trimmed string
*/

function trim_blank_chrs($string, $charlist=false)

function trim_blank_chrs($string, $charlist="")

{
$hex_chrs = array(

{
$hex_chrs = array(

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

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








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

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

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

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

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

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

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

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

	);

$hex_chrs_rev = array(

	);

$hex_chrs_rev = array(

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

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


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

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

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

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



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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		$offset = match_sequence($string, $hex_chrs);

		$offset = match_sequence($string, $hex_chrs);

		if(!$offset)

		if(!$offset)

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

Zeile 7763Zeile 8247
	$string = strrev($string);
do
{

	$string = strrev($string);
do
{

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

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

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

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

Zeile 7775Zeile 8259
	while(++$i);
$string = strrev($string);


	while(++$i);
$string = strrev($string);


	if($charlist !== false)

	if($charlist)

	{
$string = trim($string, $charlist);

	{
$string = trim($string, $charlist);

	}

	}

	else
{
$string = trim($string);
}

	else
{
$string = trim($string);
}





	return $string;

	return $string;

}


}


/**
* Match a sequence
*

/**
* Match a sequence
*

 * @param string The string to match from
* @param array The array to match from
* @param int Number in the string
* @param int Number of matches

 * @param string $string The string to match from
* @param array $array The array to match from
* @param int $i Number in the string
* @param int $n Number of matches

 * @return int The number matched
*/
function match_sequence($string, $array, $i=0, $n=0)
{
if($string === "")

 * @return int The number matched
*/
function match_sequence($string, $array, $i=0, $n=0)
{
if($string === "")

	{

	{

		return 0;
}


		return 0;
}


Zeile 7852Zeile 8336
		$info = stristr($info, 'gd version');
preg_match('/\d/', $info, $gd);
$gd_version = $gd[0];

		$info = stristr($info, 'gd version');
preg_match('/\d/', $info, $gd);
$gd_version = $gd[0];

	}


	}


	return $gd_version;
}

/*
* Validates an UTF-8 string.
*

	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

 * @param string $input The string to be checked
* @param boolean $allow_mb4 Allow 4 byte UTF-8 characters?
* @param boolean $return Return the cleaned string?
* @return string|boolean Cleaned string or boolean

 */
function validate_utf8_string($input, $allow_mb4=true, $return=true)
{

 */
function validate_utf8_string($input, $allow_mb4=true, $return=true)
{

Zeile 7977Zeile 8461
/**
* Send a Private Message to a user.
*

/**
* Send a Private Message to a user.
*

 * @param array Array containing: 'subject', 'message', 'touid' and 'receivepms' (the latter should reflect the value found in the users table: receivepms and receivefrombuddy)
* @param int Sender UID (0 if you want to use $mybb->user['uid'] or -1 to use MyBB Engine)
* @param bool Whether or not do override user defined options for receiving PMs

 * @param array $pm Array containing: 'subject', 'message', 'touid' and 'receivepms' (the latter should reflect the value found in the users table: receivepms and receivefrombuddy)
* @param int $fromid Sender UID (0 if you want to use $mybb->user['uid'] or -1 to use MyBB Engine)
* @param bool $admin_override Whether or not do override user defined options for receiving PMs

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

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

Zeile 8009Zeile 8493

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


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

			$lang_string = $pm[$key];

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

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

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

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

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

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

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

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

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

				}

				}


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

 
			}

			}


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






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

$pm[$key] = $lang_string;
}


		if(isset($revert))
{
// Revert language
$lang->set_language($mybb->user['language']);
$lang->load($pm['language_file']);
}

		if(isset($revert))
{
// Revert language
$lang->set_language($mybb->user['language']);
$lang->load($pm['language_file']);
}

	}

	}


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


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


$lang->load('messages');

 

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



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


Zeile 8218Zeile 8702
	}

return $success;

	}

return $success;

 
}

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

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

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

/**
* Escapes a RFC 4180-compliant CSV string.
* Based on https://github.com/Automattic/camptix/blob/f80725094440bf09861383b8f11e96c177c45789/camptix.php#L2867
*
* @param string $string The string to be escaped
* @param boolean $escape_active_content Whether or not to escape active content trigger characters
* @return string The escaped string
*/
function my_escape_csv($string, $escape_active_content=true)
{
if($escape_active_content)
{
$active_content_triggers = array('=', '+', '-', '@');
$delimiters = array(',', ';', ':', '|', '^', "\n", "\t", " ");

$first_character = mb_substr($string, 0, 1);

if(
in_array($first_character, $active_content_triggers, true) ||
in_array($first_character, $delimiters, true)
)
{
$string = "'".$string;
}

foreach($delimiters as $delimiter)
{
foreach($active_content_triggers as $trigger)
{
$string = str_replace($delimiter.$trigger, $delimiter."'".$trigger, $string);
}
}
}

$string = str_replace('"', '""', $string);

return $string;

}

}