Vergleich inc/functions.php - 1.8.8 - 1.8.18

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 18Zeile 18
	global $db, $lang, $theme, $templates, $plugins, $mybb;
global $debug, $templatecache, $templatelist, $maintimer, $globaltime, $parsetime;


	global $db, $lang, $theme, $templates, $plugins, $mybb;
global $debug, $templatecache, $templatelist, $maintimer, $globaltime, $parsetime;


 
	$contents = $plugins->run_hooks("pre_parse_page", $contents);

	$contents = parse_page($contents);
$totaltime = format_time_duration($maintimer->stop());
$contents = $plugins->run_hooks("pre_output_page", $contents);

	$contents = parse_page($contents);
$totaltime = format_time_duration($maintimer->stop());
$contents = $plugins->run_hooks("pre_output_page", $contents);

Zeile 322Zeile 323
/**
* 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 $format A date format according to PHP's date structure.

 * @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 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.

Zeile 343Zeile 344
	{
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 381
	}

$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 401
	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;
$relative = array('prefix' => '', 'minute' => 0, 'plural' => $lang->rel_minutes_plural, 'suffix' => $lang->rel_ago);

		if($ty != 2 && abs(TIME_NOW - $stamp) < 3600)
{
$diff = TIME_NOW - $stamp;
$relative = array('prefix' => '', 'minute' => 0, 'plural' => $lang->rel_minutes_plural, 'suffix' => $lang->rel_ago);


if($diff < 0)
{
$diff = abs($diff);
$relative['suffix'] = '';
$relative['prefix'] = $lang->rel_in;
}



if($diff < 0)
{
$diff = abs($diff);
$relative['suffix'] = '';
$relative['prefix'] = $lang->rel_in;
}


			$relative['minute'] = floor($diff / 60);

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

			$relative['minute'] = floor($diff / 60);

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

Zeile 426Zeile 441
				$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)
{

Zeile 446Zeile 461
			{
$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
{
if($ty)
{
if($todaysdate == $date)

		else
{
if($ty)
{
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);

				}

				}

			}


			}


			$date .= $mybb->settings['datetimesep'];
if($adodb == true)

			$date .= $mybb->settings['datetimesep'];
if($adodb == true)

			{

			{

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

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

			}

			}

			else

			else

			{

			{

				$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 497Zeile 537
			else
{
$date = gmdate($format, $stamp + ($offset * 3600));

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

			}
}
}

			}
}
}


if(is_object($plugins))
{


if(is_object($plugins))
{

Zeile 690Zeile 730
	global $forum_cache, $cache;

if($force == true)

	global $forum_cache, $cache;

if($force == true)

	{

	{

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

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

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

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

 */

 */

function get_child_list($fid)
{
static $forums_by_parent;

function get_child_list($fid)
{
static $forums_by_parent;

Zeile 735Zeile 775
	}

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

	}

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

	{

	{

		$forums[] = $forum['fid'];
$children = get_child_list($forum['fid']);
if(is_array($children))

		$forums[] = $forum['fid'];
$children = get_child_list($forum['fid']);
if(is_array($children))

Zeile 758Zeile 798

$error = $plugins->run_hooks("error", $error);
if(!$error)


$error = $plugins->run_hooks("error", $error);
if(!$error)

	{

	{

		$error = $lang->unknown_error;

		$error = $lang->unknown_error;

	}

	}


// AJAX error message?
if($mybb->get_input('ajax', MyBB::INPUT_INT))


// AJAX error message?
if($mybb->get_input('ajax', MyBB::INPUT_INT))

Zeile 769Zeile 809
		@header("Content-type: application/json; charset={$lang->settings['charset']}");
echo json_encode(array("errors" => array($error)));
exit;

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

	}


	}


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

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





	$timenow = my_date('relative', TIME_NOW);
reset_breadcrumb();
add_breadcrumb($lang->error);

	$timenow = my_date('relative', TIME_NOW);
reset_breadcrumb();
add_breadcrumb($lang->error);





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

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


exit;
}

/**


exit;
}

/**

 * Produce an error message for displaying inline on a page
*
* @param array $errors Array of errors to be shown

 * Produce an error message for displaying inline on a page
*
* @param array $errors Array of errors to be shown

Zeile 809Zeile 849
	}

// AJAX error message?

	}

// AJAX error message?

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

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

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

if(empty($json_data))

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

if(empty($json_data))

		{

		{

			echo json_encode(array("errors" => $errors));
}
else
{
echo json_encode(array_merge(array("errors" => $errors), $json_data));

			echo json_encode(array("errors" => $errors));
}
else
{
echo json_encode(array_merge(array("errors" => $errors), $json_data));

		}
exit;

		}
exit;

	}

$errorlist = '';

foreach($errors as $error)
{

	}

$errorlist = '';

foreach($errors as $error)
{

		$errorlist .= "<li>".$error."</li>\n";

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

	}

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

	}

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

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

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

				$lang_username = $lang->username;
break;

				$lang_username = $lang->username;
break;

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

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

				break;

				break;

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

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

				break;

				break;

			default:
$lang_username = $lang->username;
break;

			default:
$lang_username = $lang->username;
break;

		}

		}

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


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


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

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

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

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

	{

	{

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

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

Zeile 940Zeile 980
	if(!$message)
{
$message = $lang->redirect;

	if(!$message)
{
$message = $lang->redirect;

	}


	}


	$time = TIME_NOW;
$timenow = my_date('relative', $time);

	$time = TIME_NOW;
$timenow = my_date('relative', $time);





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

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

Zeile 952Zeile 992

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


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

	{

	{

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


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


Zeile 966Zeile 1006

run_shutdown();



run_shutdown();


		if(!my_validate_url($url, true))

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

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

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

Zeile 977Zeile 1017
	}

exit;

	}

exit;

}

/**

}

/**

 * Generate a listing of page - pagination
*
* @param int $count The number of items

 * Generate a listing of page - pagination
*
* @param int $count The number of items

Zeile 992Zeile 1032
function multipage($count, $perpage, $page, $url, $breadcrumb=false)
{
global $theme, $templates, $lang, $mybb;

function multipage($count, $perpage, $page, $url, $breadcrumb=false)
{
global $theme, $templates, $lang, $mybb;





	if($count <= $perpage)
{
return '';
}

	if($count <= $perpage)
{
return '';
}

 

$page = (int)$page;


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


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

Zeile 1102Zeile 1144
		eval("\$jumptopage = \"".$templates->get("multipage_jump_page")."\";");
}


		eval("\$jumptopage = \"".$templates->get("multipage_jump_page")."\";");
}


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

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


if($breadcrumb == true)
{


if($breadcrumb == true)
{

Zeile 1162Zeile 1204
/**
* Fetch the permissions for a specific user
*

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

 * @param int $uid The user ID

 * @param int $uid The user ID, if no user ID is provided then current user's ID will be considered.

 * @return array Array of user permissions for the specified user
*/

 * @return array Array of user permissions for the specified user
*/

function user_permissions($uid=0)

function user_permissions($uid=null)

{
global $mybb, $cache, $groupscache, $user_cache;

// If no user id is specified, assume it is the current user

{
global $mybb, $cache, $groupscache, $user_cache;

// If no user id is specified, assume it is the current user

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

// Its a guest. Return the group permissions directly from cache

	if($uid == 0)
{

	if($uid == 0)
{

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

		return $groupscache[1];

	}

// User id does not match current user, fetch permissions
if($uid != $mybb->user['uid'])
{
// We've already cached permissions for this user, return them.

	}

// User id does not match current user, fetch permissions
if($uid != $mybb->user['uid'])
{
// We've already cached permissions for this user, return them.

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

		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 1774Zeile 1822
	$iconlist = '';
$no_icons_checked = " checked=\"checked\"";
// read post icons from cache, and sort them accordingly

	$iconlist = '';
$no_icons_checked = " checked=\"checked\"";
// read post icons from cache, and sort them accordingly

	$posticons_cache = $cache->read("posticons");

	$posticons_cache = (array)$cache->read("posticons");

	$posticons = array();
foreach($posticons_cache as $posticon)
{

	$posticons = array();
foreach($posticons_cache as $posticon)
{

Zeile 1820Zeile 1868
 * @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)

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

 
 * @param string $samesite The samesite attribute to prevent CSRF.

 */

 */

function my_setcookie($name, $value="", $expires="", $httponly=false)

function my_setcookie($name, $value="", $expires="", $httponly=false, $samesite="")

{
global $mybb;


{
global $mybb;


Zeile 1868Zeile 1917
	if($httponly == true)
{
$cookie .= "; HttpOnly";

	if($httponly == true)
{
$cookie .= "; HttpOnly";

 
	}

if($samesite != "" && $mybb->settings['cookiesamesiteflag'])
{
$samesite = strtolower($samesite);

if($samesite == "lax" || $samesite == "strict")
{
$cookie .= "; SameSite=".$samesite;
}
}

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

	}

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

	}

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

Zeile 1978Zeile 2042
		return false;
}


		return false;
}


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

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



/*
* states:


/*
* states:

Zeile 3006Zeile 3069
 */
function format_name($username, $usergroup, $displaygroup=0)
{

 */
function format_name($username, $usergroup, $displaygroup=0)
{

	global $groupscache, $cache;

	global $groupscache, $cache, $plugins;





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

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

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

if($userin == 0)

	static $formattednames = array();

if(!isset($formattednames[$username]))













	{

	{

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

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


		$format = "{username}";

		$format = "{username}";

	}

 




	$format = stripslashes($format);




















		if(isset($groupscache[$usergroup]))
{
$ugroup = $groupscache[$usergroup];

if(strpos($ugroup['namestyle'], "{username}") !== false)
{
$format = $ugroup['namestyle'];
}
}

$format = stripslashes($format);

$parameters = compact('username', 'usergroup', 'displaygroup', 'format');

$parameters = $plugins->run_hooks('format_name', $parameters);

$format = $parameters['format'];

$formattednames[$username] = str_replace("{username}", $username, $format);
}





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

	return $formattednames[$username];

}

/**

}

/**

Zeile 3048Zeile 3127
	if(!isset($avatars))
{
$avatars = array();

	if(!isset($avatars))
{
$avatars = array();

 
	}

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

	}

if(!$avatar)

	}

if(!$avatar)

Zeile 3057Zeile 3142
		{
$theme['imgdir'] = '../images';
}

		{
$theme['imgdir'] = '../images';
}





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

if(!$max_dimensions)

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

if(!$max_dimensions)

	{

	{

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


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


Zeile 3075Zeile 3160
	}
$key2 = $max_dimensions;
if(empty($key2))

	}
$key2 = $max_dimensions;
if(empty($key2))

	{

	{

		$key2 = 'default';
}


		$key2 = 'default';
}


Zeile 3088Zeile 3173

if($dimensions)
{


if($dimensions)
{

		$dimensions = explode("|", $dimensions);

		$dimensions = preg_split('/[|x]/', $dimensions);


if($dimensions[0] && $dimensions[1])
{


if($dimensions[0] && $dimensions[1])
{

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

			list($max_width, $max_height) = preg_split('/[|x]/', $max_dimensions);


if(!empty($max_dimensions) && ($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);
$avatar_width_height = "width=\"{$scaled_dimensions['width']}\" height=\"{$scaled_dimensions['height']}\"";

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

Zeile 3113Zeile 3198
	);

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

	);

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

}

}


/**
* Build the javascript based MyCode inserter.


/**
* Build the javascript based MyCode inserter.

Zeile 3189Zeile 3274
			"editor_invalidyoutube" => "Invalid YouTube video",
"editor_dailymotion" => "Dailymotion",
"editor_metacafe" => "MetaCafe",

			"editor_invalidyoutube" => "Invalid YouTube video",
"editor_dailymotion" => "Dailymotion",
"editor_metacafe" => "MetaCafe",

			"editor_veoh" => "Veoh",

			"editor_mixer" => "Mixer",

			"editor_vimeo" => "Vimeo",
"editor_youtube" => "Youtube",
"editor_facebook" => "Facebook",

			"editor_vimeo" => "Vimeo",
"editor_youtube" => "Youtube",
"editor_facebook" => "Facebook",

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

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





			if($i < $editor_languages_count)
{
$editor_language .= ",";

			if($i < $editor_languages_count)
{
$editor_language .= ",";

Zeile 3359Zeile 3444
	}

return $codeinsert;

	}

return $codeinsert;

 
}

/**
* @param int $tid
* @param array $postoptions The options carried with form submit
*
* @return string Predefined / updated subscription method of the thread for the user
*/
function get_subscription_method($tid = 0, $postoptions = array())
{
global $mybb;

$subscription_methods = array('dont', 'none', 'email', 'pm'); // Define methods
$subscription_method = (int)$mybb->user['subscriptionmethod']; // Set user default

// If no user default method available then reset method
if(!$subscription_method)
{
$subscription_method = 0;
}

// Return user default if no thread id available, in case
if(!(int)$tid || (int)$tid <= 0)
{
return $subscription_methods[$subscription_method];
}

// If method not predefined set using data from database
if(isset($postoptions['subscriptionmethod']))
{
$method = trim($postoptions['subscriptionmethod']);
return (in_array($method, $subscription_methods)) ? $method : $subscription_methods[0];
}
else
{
global $db;

$query = $db->simple_select("threadsubscriptions", "tid, notification", "tid='".(int)$tid."' AND uid='".$mybb->user['uid']."'", array('limit' => 1));
$subscription = $db->fetch_array($query);

if($subscription['tid'])
{
$subscription_method = (int)$subscription['notification'] + 1;
}
}

return $subscription_methods[$subscription_method];

}

/**

}

/**

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

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

		}

		}


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


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

			{

			{

				$smilie_cache = $cache->read("smilies");
}
foreach($smilie_cache as $smilie)

				$smilie_cache = $cache->read("smilies");
}
foreach($smilie_cache as $smilie)

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

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

			}

			}

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

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

Zeile 3414Zeile 3546

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


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

			{

			{

				if($i < $mybb->settings['smilieinsertertot'] && $smilie['showclickable'] != 0)
{
$smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']);

				if($i < $mybb->settings['smilieinsertertot'] && $smilie['showclickable'] != 0)
{
$smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']);

Zeile 3505Zeile 3637
	}

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

	}

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

	{

	{

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

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

Zeile 3567Zeile 3699
	if(empty($prefixes))
{
return '';

	if(empty($prefixes))
{
return '';

	}

$prefixselect = $prefixselect_prefix = '';

	}

$prefixselect = $prefixselect_prefix = '';


if($multiple == 1)
{


if($multiple == 1)
{

Zeile 3577Zeile 3709
		if($selected_pid == 'any')
{
$any_selected = " selected=\"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 3605Zeile 3737
	else
{
eval("\$prefixselect = \"".$templates->get("post_prefixselect_single")."\";");

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

	}

return $prefixselect;
}


	}

return $prefixselect;
}


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

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

Zeile 3622Zeile 3754
	global $cache, $db, $lang, $mybb, $templates;

$fid = (int)$fid;

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

$fid = (int)$fid;





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

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

Zeile 3635Zeile 3767
	foreach($prefix_cache as $prefix)
{
if($prefix['forums'] != "-1")

	foreach($prefix_cache as $prefix)
{
if($prefix['forums'] != "-1")

		{

		{

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


Zeile 3661Zeile 3793
	$selected_pid = (int)$selected_pid;

if($selected_pid == 0)

	$selected_pid = (int)$selected_pid;

if($selected_pid == 0)

	{

	{

		$default_selected['all'] = ' selected="selected"';

		$default_selected['all'] = ' selected="selected"';

	}

	}

	else if($selected_pid == -1)

	else if($selected_pid == -1)

	{

	{

		$default_selected['none'] = ' selected="selected"';
}
else if($selected_pid == -2)

		$default_selected['none'] = ' selected="selected"';
}
else if($selected_pid == -2)

Zeile 3674Zeile 3806
	}

foreach($prefixes as $prefix)

	}

foreach($prefixes as $prefix)

	{

	{

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

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

Zeile 3713Zeile 3845
		}

if(my_strpos(" ".$httpaccept_encoding, "gzip"))

		}

if(my_strpos(" ".$httpaccept_encoding, "gzip"))

		{

		{

			$encoding = "gzip";
}


			$encoding = "gzip";
}


Zeile 3739Zeile 3871
	}

return $contents;

	}

return $contents;

}

}


/**
* Log the actions of a moderator.


/**
* Log the actions of a moderator.

Zeile 3770Zeile 3902
	{
$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

	}

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

Zeile 3788Zeile 3927
		"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);
}

}

/**

}

/**

Zeile 3814Zeile 3969
	else
{
$reputation_class = "reputation_neutral";

	else
{
$reputation_class = "reputation_neutral";

	}

$reputation = my_number_format($reputation);


	}

$reputation = my_number_format($reputation);


	if($uid != 0)
{
eval("\$display_reputation = \"".$templates->get("postbit_reputation_formatted_link")."\";");

	if($uid != 0)
{
eval("\$display_reputation = \"".$templates->get("postbit_reputation_formatted_link")."\";");

Zeile 4025Zeile 4180
function get_attachment_icon($ext)
{
global $cache, $attachtypes, $theme, $templates, $lang, $mybb;

function get_attachment_icon($ext)
{
global $cache, $attachtypes, $theme, $templates, $lang, $mybb;





	if(!$attachtypes)
{
$attachtypes = $cache->read("attachtypes");

	if(!$attachtypes)
{
$attachtypes = $cache->read("attachtypes");

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

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

		}

$icon = $attach_icons_schemes[$ext];

		}

$icon = $attach_icons_schemes[$ext];


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


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

Zeile 4103Zeile 4258
	if(!is_array($forum_cache))
{
cache_forums();

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

	}

	}


if(!is_array($permissioncache))
{


if(!is_array($permissioncache))
{

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

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

		}

		}

		else

		else

		{

		{

			$perms = $mybb->usergroup;
}

			$perms = $mybb->usergroup;
}





		$pwverified = 1;

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

		$pwverified = 1;

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

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

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

			}

			}


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


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

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

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

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

	}

	}


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

 

if($nav)
{


if($nav)
{

Zeile 4664Zeile 4817
	$stamp %= $msecs;
$seconds = $stamp;


	$stamp %= $msecs;
$seconds = $stamp;


	if($years == 1)


	// Prevent gross over accuracy ($options parameter will override these)
if($years > 0)

	{

	{

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






		$options = array_merge(array(
'days' => false,
'hours' => false,
'minutes' => false,
'seconds' => false
), $options);

	}

	}

	else if($years > 1)

	elseif($months > 0)

	{

	{

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





		$options = array_merge(array(
'hours' => false,
'minutes' => false,
'seconds' => false
), $options);

	}

	}


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

































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

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

	}

	}

	else if($months > 1)



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

	{

	{

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








		if($weeks == 1)
{
$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 4863Zeile 5060
	");

$cache->update_moderators();

	");

$cache->update_moderators();

}

}


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

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

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

	}

	}

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

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

Zeile 4917Zeile 5114

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


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

		{

		{

			foreach($mybb->input as $name => $value)
{
if(in_array($name, $ignore) || is_array($name) || is_array($value))
{
continue;
}

			foreach($mybb->input as $name => $value)
{
if(in_array($name, $ignore) || is_array($name) || is_array($value))
{
continue;
}





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

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

			}
}


			}
}


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

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

Zeile 4951Zeile 5148
				if(isset($_POST[$var]))
{
$addloc[] = urlencode($var).'='.urlencode($_POST[$var]);

				if(isset($_POST[$var]))
{
$addloc[] = urlencode($var).'='.urlencode($_POST[$var]);

				}
}


				}
}


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

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

Zeile 5220Zeile 5417

/**
* DEPRECATED! Please use other alternatives.


/**
* DEPRECATED! Please use other alternatives.

 *
* @deprecated
* @param string $message
*

 *
* @deprecated
* @param string $message
*

 * @return string
*/
function my_wordwrap($message)

 * @return string
*/
function my_wordwrap($message)

Zeile 5333Zeile 5530
		$lang->month_11,
$lang->month_12
);

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



 

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


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

Zeile 5402Zeile 5598
{
$bday = explode("-", $birthday);
if(!$bday[2])

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

	{
return;
}

list($day, $month, $year) = explode("-", my_date("j-n-Y", TIME_NOW, 0, 0));

	{
return;
}

list($day, $month, $year) = explode("-", my_date("j-n-Y", TIME_NOW, 0, 0));


$age = $year-$bday[2];



$age = $year-$bday[2];


Zeile 5415Zeile 5611
		--$age;
}
return $age;

		--$age;
}
return $age;

}

/**

}

/**

 * Updates the first posts in a thread.
*
* @param int $tid The thread id for which to update the first post id.

 * Updates the first posts in a thread.
*
* @param int $tid The thread id for which to update the first post id.

Zeile 5459Zeile 5655
function update_last_post($tid)
{
global $db;

function update_last_post($tid)
{
global $db;





	$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 5473Zeile 5669
	if(empty($lastpost['username']))
{
$lastpost['username'] = $lastpost['postusername'];

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

	}

	}


if(empty($lastpost['dateline']))
{


if(empty($lastpost['dateline']))
{

Zeile 5501Zeile 5697
	);
$db->update_query("threads", $update_array, "tid='{$tid}'");
}

	);
$db->update_query("threads", $update_array, "tid='{$tid}'");
}





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

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

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

if(strtolower($lang->settings['charset']) == "utf-8")

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

if(strtolower($lang->settings['charset']) == "utf-8")

	{

	{

		// Get rid of any excess RTL and LTR override for they are the workings of the devil
$string = str_replace(dec_to_utf8(8238), "", $string);
$string = str_replace(dec_to_utf8(8237), "", $string);

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

Zeile 5528Zeile 5724
	if(function_exists("mb_strlen"))
{
$string_length = mb_strlen($string);

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

	}
else

	}
else

	{
$string_length = strlen($string);
}

	{
$string_length = strlen($string);
}

Zeile 5557Zeile 5753
		if($length != null)
{
$cut_string = mb_substr($string, $start, $length);

		if($length != null)
{
$cut_string = mb_substr($string, $start, $length);

		}

		}

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

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

Zeile 5613Zeile 5809
function my_strpos($haystack, $needle, $offset=0)
{
if($needle == '')

function my_strpos($haystack, $needle, $offset=0)
{
if($needle == '')

	{

	{

		return false;

		return false;

	}

	}


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


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

	}

	}

	else
{
$position = strpos($haystack, $needle, $offset);
}

return $position;

	else
{
$position = strpos($haystack, $needle, $offset);
}

return $position;

}

}


/**
* Ups the case of a string, mb strings accounted for


/**
* Ups the case of a string, mb strings accounted for

Zeile 5640Zeile 5836
	if(function_exists("mb_strtoupper"))
{
$string = mb_strtoupper($string);

	if(function_exists("mb_strtoupper"))
{
$string = mb_strtoupper($string);

	}
else

	}
else

	{
$string = strtoupper($string);
}

	{
$string = strtoupper($string);
}

Zeile 5658Zeile 5854
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 5685Zeile 5881
		return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
}
else if($c <= 0xFFFF)

		return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
}
else if($c <= 0xFFFF)

	{

	{

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

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

									. chr(0x80 | $c & 0x3F);

									. chr(0x80 | $c & 0x3F);

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

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

	}

	}

	else
{
return false;
}

	else
{
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.

Zeile 5713Zeile 5931
	$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.

Zeile 5741Zeile 5959
function get_profile_link($uid=0)
{
$link = str_replace("{uid}", $uid, PROFILE_URL);

function get_profile_link($uid=0)
{
$link = str_replace("{uid}", $uid, PROFILE_URL);

	return htmlspecialchars_uni($link);

	return htmlspecialchars_uni($link);

}

/**

}

/**

Zeile 5772Zeile 5990
	if(!$username && $uid == 0)
{
// Return Guest phrase for no UID, no guest nickname

	if(!$username && $uid == 0)
{
// Return Guest phrase for no UID, no guest nickname

		return $lang->guest;

		return htmlspecialchars_uni($lang->guest);

	}
elseif($uid == 0)
{

	}
elseif($uid == 0)
{

Zeile 5966Zeile 6184
		return $mybb->user;
}
elseif(isset($user_cache[$uid]))

		return $mybb->user;
}
elseif(isset($user_cache[$uid]))

	{
return $user_cache[$uid];
}

	{
return $user_cache[$uid];
}

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

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





		return $user_cache[$uid];
}
return array();

		return $user_cache[$uid];
}
return array();

}

/**

}

/**

 * Get the user data of an user username.
*
* @param string $username The user username of the user.

 * Get the user data of an user username.
*
* @param string $username The user username of the user.

Zeile 5993Zeile 6211
	$username = $db->escape_string(my_strtolower($username));

if(!isset($options['username_method']))

	$username = $db->escape_string(my_strtolower($username));

if(!isset($options['username_method']))

	{

	{

		$options['username_method'] = 0;
}


		$options['username_method'] = 0;
}


Zeile 6003Zeile 6221
		case 'mysqli':
$field = 'username';
$efield = 'email';

		case 'mysqli':
$field = 'username';
$efield = 'email';

			break;

			break;

		default:
$field = 'LOWER(username)';
$efield = 'LOWER(email)';

		default:
$field = 'LOWER(username)';
$efield = 'LOWER(email)';

			break;
}

			break;
}


switch($options['username_method'])
{


switch($options['username_method'])
{

Zeile 6017Zeile 6235
			break;
case 2:
$sqlwhere = "{$field}='{$username}' OR {$efield}='{$username}'";

			break;
case 2:
$sqlwhere = "{$field}='{$username}' OR {$efield}='{$username}'";

			break;

			break;

		default:
$sqlwhere = "{$field}='{$username}'";
break;

		default:
$sqlwhere = "{$field}='{$username}'";
break;

	}


	}


	$fields = array('uid');
if(isset($options['fields']))

	$fields = array('uid');
if(isset($options['fields']))

	{

	{

		$fields = array_merge((array)$options['fields'], $fields);

		$fields = array_merge((array)$options['fields'], $fields);

	}

$query = $db->simple_select('users', implode(',', array_unique($fields)), $sqlwhere, array('limit' => 1));

	}

$query = $db->simple_select('users', implode(',', array_unique($fields)), $sqlwhere, array('limit' => 1));


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


Zeile 6077Zeile 6295
	}

return $forum_cache[$fid];

	}

return $forum_cache[$fid];

}


}


/**
* Get the thread of a thread id.
*

/**
* Get the thread of a thread id.
*

Zeile 6192Zeile 6410
 * @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.
*/

 * @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($uid = 0, $fatal = true)

{

{

	global $mybb, $lang, $session, $db;

	global $mybb, $lang, $db;





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






	$attempts = array();
$uid = (int)$uid;
$now = TIME_NOW;

// Get this user's login attempts and eventual lockout, if a uid is provided
if($uid > 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
// Find better solution to prevent clearing cookies
$loginattempts = 0;
$failedlogin = 0;

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

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

		$query = $db->simple_select("users", "loginattempts, loginlockoutexpiry", "uid='{$uid}'", 1);
$attempts = $db->fetch_array($query);





















	// Work out if the user has had more than the allowed number of login attempts
if($loginattempts > $mybb->settings['failedlogincount'])
{
// If so, then we need to work out if they can try to login again
// Some maths to work out how long they have left and display it to them
$now = TIME_NOW;

if(empty($mybb->cookies['failedlogin']))
{
$failedtime = $now;
}
else
{
$failedtime = $mybb->cookies['failedlogin'];
}

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

// This value will be empty the first time the user doesn't login in, set it
if(empty($failedlogin))
{
my_setcookie('failedlogin', $now);
if($fatal)
{
error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft));
}

return false;

		if($attempts['loginattempts'] <= 0)
{
return 0;





























		}

		}

 
	}
// This user has a cookie lockout, show waiting time
elseif($mybb->cookies['lockoutexpiry'] && $mybb->cookies['lockoutexpiry'] > $now)
{
if($fatal)
{
$secsleft = (int)($mybb->cookies['lockoutexpiry'] - $now);
$hoursleft = floor($secsleft / 3600);
$minsleft = floor(($secsleft / 60) % 60);
$secsleft = floor($secsleft % 60);





		// Work out if the user has waited long enough before letting them login again
if($mybb->cookies['failedlogin'] < ($now - $mybb->settings['failedlogintime'] * 60))
{
my_setcookie('loginattempts', 1);
my_unsetcookie('failedlogin');
if($mybb->user['uid'] != 0)
{
$update_array = array(
'loginattempts' => 1
);
$db->update_query("users", $update_array, "uid = '{$mybb->user['uid']}'");
}
return 1;
}
// Not waited long enough
else if($mybb->cookies['failedlogin'] > ($now - $mybb->settings['failedlogintime'] * 60))












			error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft));
}

return false;
}

if($mybb->settings['failedlogincount'] > 0 && $attempts['loginattempts'] >= $mybb->settings['failedlogincount'])
{
// Set the expiry dateline if not set yet
if($attempts['loginlockoutexpiry'] == 0)
{
$attempts['loginlockoutexpiry'] = $now + ((int)$mybb->settings['failedlogintime'] * 60);

// Add a cookie lockout. This is used to prevent access to the login page immediately.
// A deep lockout is issued if he tries to login into a locked out account
my_setcookie('lockoutexpiry', $attempts['loginlockoutexpiry']);

$db->update_query("users", array(
"loginlockoutexpiry" => $attempts['loginlockoutexpiry']
), "uid='{$uid}'");
}

if(empty($mybb->cookies['lockoutexpiry']))
{
$failedtime = $attempts['loginlockoutexpiry'];
}
else

		{

		{

 
			$failedtime = $mybb->cookies['lockoutexpiry'];
}

// Are we still locked out?
if($attempts['loginlockoutexpiry'] > $now)
{

			if($fatal)

			if($fatal)

			{






			{
$secsleft = (int)($attempts['loginlockoutexpiry'] - $now);
$hoursleft = floor($secsleft / 3600);
$minsleft = floor(($secsleft / 60) % 60);
$secsleft = floor($secsleft % 60);


				error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft));

				error($lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft));

			}


			}


			return false;

			return false;

 
		}
// Unlock if enough time has passed
else {

if($uid > 0)
{
$db->update_query("users", array(
"loginattempts" => 0,
"loginlockoutexpiry" => 0
), "uid='{$uid}'");
}

// Wipe the cookie, no matter if a guest or a member
my_unsetcookie('lockoutexpiry');

return 0;

		}
}

// User can attempt another login

		}
}

// User can attempt another login

	return $loginattempts;

	return $attempts['loginattempts'];

}

/**

}

/**

Zeile 6288Zeile 6515
 */
function validate_email_format($email)
{

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

	return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;






}

/**

}

/**

Zeile 6302Zeile 6524
 * @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.

 * @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.

 */

 */

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

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

Zeile 6330Zeile 6552
{
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 6354Zeile 6566
	}

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

Zeile 6451Zeile 6662

// 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 6473Zeile 6684
	}

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

}

/**

}

/**

Zeile 6766Zeile 6989
function fetch_remote_file($url, $post_data=array(), $max_redirects=20)
{
global $mybb, $config;

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


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


if(
!$url_components ||
empty($url_components['host']) ||
(!empty($url_components['scheme']) && !in_array($url_components['scheme'], array('http', 'https'))) ||

		(!empty($url_components['port']) && !in_array($url_components['port'], array(80, 8080, 443))) ||

		(!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;
}

		(!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']))


if(!empty($config['disallowed_remote_addresses']))

	{
$addresses = gethostbynamel($url_components['host']);
if($addresses)
{
foreach($config['disallowed_remote_addresses'] as $disallowed_address)
{
$ip_range = fetch_ip_range($disallowed_address);
foreach($addresses as $address)
{
$packed_address = my_inet_pton($address);

if(is_array($ip_range))
{
if(strcmp($ip_range[0], $packed_address) <= 0 && strcmp($ip_range[1], $packed_address) >= 0)
{
return false;
}
}
elseif($address == $disallowed_address)
{
return false;
}
}
}

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







		}
}


		}
}


Zeile 6820Zeile 7054

if(function_exists("curl_init"))
{


if(function_exists("curl_init"))
{

		$can_followlocation = @ini_get('open_basedir') === '' && !$mybb->safemode;

$request_header = $max_redirects != 0 && !$can_followlocation;

		$fetch_header = $max_redirects > 0;




$ch = curl_init();


$ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $request_header);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

if($max_redirects != 0 && $can_followlocation)
{
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, $max_redirects);
}




























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


$response = curl_exec($ch);


if($request_header)


if($fetch_header)

		{
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);

		{
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);

Zeile 6863Zeile 7122
			else
{
$data = $body;

			else
{
$data = $body;

			}
}

			}
}

		else
{
$data = $response;

		else
{
$data = $response;

		}

		}


curl_close($ch);
return $data;
}
else if(function_exists("fsockopen"))
{


curl_close($ch);
return $data;
}
else if(function_exists("fsockopen"))
{

		if(!isset($url_components['port']))
{
$url_components['port'] = 80;
}

 
		if(!isset($url_components['path']))
{
$url_components['path'] = "/";

		if(!isset($url_components['path']))
{
$url_components['path'] = "/";

Zeile 6899Zeile 7154
			}
}


			}
}


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






























		if(function_exists('stream_context_create'))
{
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
{
$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);
}


		@stream_set_timeout($fp, 10);
if(!$fp)
{
return false;
}
$headers = array();

		@stream_set_timeout($fp, 10);
if(!$fp)
{
return false;
}
$headers = array();

		if(!empty($post_body))

		if(!empty($post_body))

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

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

Zeile 6945Zeile 7229
		}
fclose($fp);


		}
fclose($fp);


		$data = explode("\r\n\r\n", $data, 2);


		$data = explode("\r\n\r\n", $data, 2);


		$header = $data[0];
$status_line = current(explode("\n\n", $header, 1));
$body = $data[1];


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

		if($max_redirects > 0 && (strstr($status_line, ' 301 ') || strstr($status_line, ' 302 ')))

		{
preg_match('/Location:(.*?)(?:\n|$)/', $header, $matches);


		{
preg_match('/Location:(.*?)(?:\n|$)/', $header, $matches);


Zeile 6959Zeile 7243
			{
$data = fetch_remote_file(trim(array_pop($matches)), $post_data, --$max_redirects);
}

			{
$data = fetch_remote_file(trim(array_pop($matches)), $post_data, --$max_redirects);
}

		}
































		}
else
{
$data = $body;
}

return $data;
}
else
{
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
{

		else
{

			$data = $body;

			return false;

		}

		}


return $data;
}
else if(empty($post_data))














	}

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 @implode("", @file($url));
}
else
{
return false;

		return $path;





	}

	}

 

return false;

}

/**

}

/**

Zeile 7111Zeile 7437
			}
}
$in_escape = !$in_escape;

			}
}
$in_escape = !$in_escape;

	}

	}

	if(!count($strings))
{
return $original;

	if(!count($strings))
{
return $original;

Zeile 7168Zeile 7494
			$sep = ".";
}
return array(ip2long($ip_string1), ip2long($ip_string2));

			$sep = ".";
}
return array(ip2long($ip_string1), ip2long($ip_string2));

	}
}


	}
}


/**
* Fetch a list of ban times for a user account.
*

/**
* Fetch a list of ban times for a user account.
*

Zeile 7200Zeile 7526
		"0-0-1" => "1 {$lang->year}",
"0-0-2" => "2 {$lang->years}"
);

		"0-0-1" => "1 {$lang->year}",
"0-0-2" => "2 {$lang->years}"
);





	$ban_times = $plugins->run_hooks("functions_fetch_ban_times", $ban_times);

$ban_times['---'] = $lang->permanent;

	$ban_times = $plugins->run_hooks("functions_fetch_ban_times", $ban_times);

$ban_times['---'] = $lang->permanent;

Zeile 7231Zeile 7557

/**
* Expire old warnings in the database.


/**
* Expire old warnings in the database.

 *
* @return bool
*/

 *
* @return bool
*/

function expire_warnings()
{
global $warningshandler;

function expire_warnings()
{
global $warningshandler;





	if(!is_object($warningshandler))
{
require_once MYBB_ROOT.'inc/datahandlers/warnings.php';
$warningshandler = new WarningsHandler('update');
}

	if(!is_object($warningshandler))
{
require_once MYBB_ROOT.'inc/datahandlers/warnings.php';
$warningshandler = new WarningsHandler('update');
}





	return $warningshandler->expire_warnings();
}

/**
* Custom chmod function to fix problems with hosts who's server configurations screw up umasks

	return $warningshandler->expire_warnings();
}

/**
* Custom chmod function to fix problems with hosts who's server configurations screw up umasks

 *

 *

 * @param string $file The file to chmod
* @param string $mode The mode to chmod(i.e. 0666)
* @return bool

 * @param string $file The file to chmod
* @param string $mode The mode to chmod(i.e. 0666)
* @return bool

Zeile 7318Zeile 7644
 * @param array $array The array of forums
* @return integer The number of sub forums
*/

 * @param array $array The array of forums
* @return integer The number of sub forums
*/

function subforums_count($array)

function subforums_count($array=array())

{
$count = 0;
foreach($array as $array2)
{
$count += count($array2);

{
$count = 0;
foreach($array as $array2)
{
$count += count($array2);

	}


	}


	return $count;
}


	return $count;
}


Zeile 7355Zeile 7681
	if($ip_long >= 2147483648) // Won't occur on 32-bit PHP
{
$ip_long -= 4294967296;

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

	}

	}


return $ip_long;
}


return $ip_long;
}

Zeile 7386Zeile 7712
 * @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)

{

{

	if(function_exists('inet_pton'))

	if(function_exists('inet_pton'))

	{

	{

		return @inet_pton($ip);
}
else

		return @inet_pton($ip);
}
else

Zeile 7401Zeile 7727
		 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html
* @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
* @link http://php.net/inet_pton

		 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html
* @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
* @link http://php.net/inet_pton

		 * @author      Arpad Ray <arpad@php.net>

		 * @author      Arpad Ray <arpad@php.net>

		 * @version     $Revision: 269597 $
*/
$r = ip2long($ip);

		 * @version     $Revision: 269597 $
*/
$r = ip2long($ip);

Zeile 7429Zeile 7755
		$r = call_user_func_array('pack', $r);

return $r;

		$r = call_user_func_array('pack', $r);

return $r;

	}
}


	}
}


/**
* Converts a packed internet address to a human readable representation
*

/**
* Converts a packed internet address to a human readable representation
*

Zeile 7476Zeile 7802

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

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

Zeile 7489Zeile 7815
		{
// IPv6
$upper = str_replace('*', 'ffff', $ipaddress);

		{
// IPv6
$upper = str_replace('*', 'ffff', $ipaddress);

			$lower = str_replace('*', '0', $ipaddress);
}
else

			$lower = str_replace('*', '0', $ipaddress);
}
else

		{
// IPv4
$ip_bits = count(explode('.', $ipaddress));

		{
// IPv4
$ip_bits = count(explode('.', $ipaddress));

Zeile 7599Zeile 7925
	static $time_start;

$time = microtime(true);

	static $time_start;

$time = microtime(true);







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

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

Zeile 7614Zeile 7939
		if($total < 0) $total = 0;
$time_start = 0;
return $total;

		if($total < 0) $total = 0;
$time_start = 0;
return $total;

	}
}

	}
}


/**
* Processes a checksum list on MyBB files and returns a result set


/**
* Processes a checksum list on MyBB files and returns a result set

Zeile 7629Zeile 7954
	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");

	$ignore_ext = array("attach");





	if(substr($path, -1, 1) == "/")
{
$path = substr($path, 0, -1);

	if(substr($path, -1, 1) == "/")
{
$path = substr($path, 0, -1);

Zeile 7670Zeile 7995
				{
$filename = $path."/".$file;
$handle = fopen($filename, "rb");

				{
$filename = $path."/".$file;
$handle = fopen($filename, "rb");

					$contents = '';

					$hashingContext = hash_init('sha512');

					while(!feof($handle))
{

					while(!feof($handle))
{

						$contents .= fread($handle, 8192);

						hash_update($hashingContext, fread($handle, 8192));

					}
fclose($handle);


					}
fclose($handle);


					$md5 = md5($contents);

					$checksum = hash_final($hashingContext);


// Does it match any of our hashes (unix/windows new lines taken into consideration with the hashes)


// Does it match any of our hashes (unix/windows new lines taken into consideration with the hashes)

					if(!in_array($md5, $checksums[$file_path]))

					if(!in_array($checksum, $checksums[$file_path]))

					{
$bad_verify_files[] = array("status" => "changed", "path" => $file_path);
}

					{
$bad_verify_files[] = array("status" => "changed", "path" => $file_path);
}

Zeile 7728Zeile 8053
	else
{
return "+$int";

	else
{
return "+$int";

	}
}

	}
}


/**
* Returns a securely generated seed


/**
* Returns a securely generated seed

Zeile 8329Zeile 8654
	}

$pm['options'] = array(

	}

$pm['options'] = array(

		"signature" => 0,

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

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

Zeile 8345Zeile 8669
	if($pmhandler->validate_pm())
{
$pmhandler->insert_pm();

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

		return true;
}

return false;
}


		return true;
}

return false;
}


/**
* Log a user spam block from StopForumSpam (or other spam service providers...)
*

/**
* Log a user spam block from StopForumSpam (or other spam service providers...)
*

Zeile 8397Zeile 8721
 * @return bool Whether the file was copied successfully.
*/
function copy_file_to_cdn($file_path = '', &$uploaded_path = null)

 * @return bool Whether the file was copied successfully.
*/
function copy_file_to_cdn($file_path = '', &$uploaded_path = null)

{

{

	global $mybb, $plugins;

$success = false;

	global $mybb, $plugins;

$success = false;

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

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

			}


			}


			if($dir_exists)
{
if(($cdn_upload_path = realpath($cdn_upload_path)) !== false)

			if($dir_exists)
{
if(($cdn_upload_path = realpath($cdn_upload_path)) !== false)

Zeile 8441Zeile 8765
						$uploaded_path = $cdn_upload_path;
}
}

						$uploaded_path = $cdn_upload_path;
}
}

			}
}


			}
}


		if(is_object($plugins))
{
$hook_args = array(

		if(is_object($plugins))
{
$hook_args = array(

Zeile 8453Zeile 8777
				'uploaded_path' => &$uploaded_path,
'success' => &$success,
);

				'uploaded_path' => &$uploaded_path,
'success' => &$success,
);





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

return $success;

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

return $success;

}

/**

}

/**

 * Validate an url

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

 *
* @return bool Whether this is a valid url.
*/

function my_validate_url($url, $relative_path=false)

function my_validate_url($url, $relative_path=false, $allow_local=false)

{

{

	if($relative_path && my_substr($url, 0, 1) == '/' || preg_match('_^(?:(?: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', $url))
















































































	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.
*
* @deprecated
* @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;
}

// Fallback function for 'array_column', PHP < 5.5.0 compatibility
if(!function_exists('array_column'))
{
function array_column($input, $column_key)

	{

	{

		return true;

















		$values = array();
if(!is_array($input))
{
$input = array($input);
}
foreach($input as $val)
{
if(is_array($val) && isset($val[$column_key]))
{
$values[] = $val[$column_key];
}
elseif(is_object($val) && isset($val->$column_key))
{
$values[] = $val->$column_key;
}
}
return $values;

	}

	}


return false;

 
}

}