Vergleich inc/functions.php - 1.8.11 - 1.8.14

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
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 $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 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 411Zeile 425
				$relative['suffix'] = '';
$relative['prefix'] = $lang->rel_in;
}

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

			{

			{

				$relative['minute'] = 1;
$relative['plural'] = $lang->rel_minutes_single;

				$relative['minute'] = 1;
$relative['plural'] = $lang->rel_minutes_single;

			}


			}


			if($diff <= 60)
{
// Less than a minute
$relative['prefix'] = $lang->rel_less_than;
}


			if($diff <= 60)
{
// Less than a minute
$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)
{
$diff = TIME_NOW - $stamp;
$relative = array('prefix' => '', 'hour' => 0, 'plural' => $lang->rel_hours_plural, 'suffix' => $lang->rel_ago);

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





			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['hour'] = floor($diff / 3600);

			}

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


if($relative['hour'] <= 1)
{
$relative['hour'] = 1;
$relative['plural'] = $lang->rel_hours_single;


if($relative['hour'] <= 1)
{
$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);

				}
}


				}
}


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 499Zeile 538
				$date = gmdate($format, $stamp + ($offset * 3600));
}
}

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

	}

	}


if(is_object($plugins))
{


if(is_object($plugins))
{

Zeile 531Zeile 570

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


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

	{

	{

		require_once MYBB_ROOT."inc/class_mailhandler.php";

if($mybb->settings['mail_handler'] == 'smtp')

		require_once MYBB_ROOT."inc/class_mailhandler.php";

if($mybb->settings['mail_handler'] == 'smtp')

Zeile 782Zeile 821

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 966Zeile 1005

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 1043Zeile 1082

$start = '';
if($from > 1)


$start = '';
if($from > 1)

	{

	{

		if($from-1 == 1)
{
$lang->multipage_link_start = '';

		if($from-1 == 1)
{
$lang->multipage_link_start = '';

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

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

	}

	}

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

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

Zeile 1155Zeile 1194
	{
$url = str_replace("{page}", $page, $url);
}

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





	return $url;
}


	return $url;
}


Zeile 1170Zeile 1209
	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 == 0)

	if($uid == 0)

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

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

Zeile 1179Zeile 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 1427Zeile 1466
			foreach($level_permissions as $permission => $access)
{
if(empty($current_permissions[$permission]) || $access >= $current_permissions[$permission] || ($access == "yes" && $current_permissions[$permission] == "no"))

			foreach($level_permissions as $permission => $access)
{
if(empty($current_permissions[$permission]) || $access >= $current_permissions[$permission] || ($access == "yes" && $current_permissions[$permission] == "no"))

				{

				{

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

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

Zeile 3465Zeile 3504
		else
{
$clickablesmilies = "";

		else
{
$clickablesmilies = "";

		}
}
else
{
$clickablesmilies = "";

		}
}
else
{
$clickablesmilies = "";

	}

return $clickablesmilies;

	}

return $clickablesmilies;

Zeile 3485Zeile 3524
{
global $cache;
static $prefixes_cache;

{
global $cache;
static $prefixes_cache;





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

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

Zeile 3494Zeile 3533
		}

return $prefixes_cache;

		}

return $prefixes_cache;

	}

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

	}

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


if(!is_array($prefix_cache))
{


if(!is_array($prefix_cache))
{

Zeile 3510Zeile 3549
	}

$prefixes_cache = array();

	}

$prefixes_cache = array();

	foreach($prefix_cache as $prefix)
{

	foreach($prefix_cache as $prefix)
{

		$prefixes_cache[$prefix['pid']] = $prefix;

		$prefixes_cache[$prefix['pid']] = $prefix;

	}


	}


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

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

	}

	}

	else if(!empty($prefixes_cache))
{
return $prefixes_cache;

	else if(!empty($prefixes_cache))
{
return $prefixes_cache;

	}


	}


	return false;
}

	return false;
}





/**
* Build the thread prefix selection menu for the current user
*

/**
* Build the thread prefix selection menu for the current user
*

Zeile 3543Zeile 3582
	if($fid != 'all')
{
$fid = (int)$fid;

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

	}

$prefix_cache = build_prefixes(0);
if(empty($prefix_cache))
{
// We've got no prefixes to show
return '';
}

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

	}

$prefix_cache = build_prefixes(0);
if(empty($prefix_cache))
{
// 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)
{

	$prefixes = array();
foreach($prefix_cache as $prefix)
{

Zeile 3572Zeile 3611
		{
// The current user can use this prefix
$prefixes[$prefix['pid']] = $prefix;

		{
// The current user can use this prefix
$prefixes[$prefix['pid']] = $prefix;

		}
}

		}
}


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


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

	}

	}


$prefixselect = $prefixselect_prefix = '';



$prefixselect = $prefixselect_prefix = '';


Zeile 3593Zeile 3632

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


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

	{

	{

		$default_selected = " selected=\"selected\"";
}


		$default_selected = " selected=\"selected\"";
}


Zeile 3716Zeile 3755
		if(isset($_SERVER['HTTP_ACCEPT_ENCODING']))
{
$httpaccept_encoding = $_SERVER['HTTP_ACCEPT_ENCODING'];

		if(isset($_SERVER['HTTP_ACCEPT_ENCODING']))
{
$httpaccept_encoding = $_SERVER['HTTP_ACCEPT_ENCODING'];

		}

		}


if(my_strpos(" ".$httpaccept_encoding, "x-gzip"))
{


if(my_strpos(" ".$httpaccept_encoding, "x-gzip"))
{

Zeile 3781Zeile 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'],
"dateline" => TIME_NOW,

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

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

}

/**

}

/**

Zeile 4675Zeile 4737
	$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 5669Zeile 5775
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 5710Zeile 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]);

}

/**

}

/**

Zeile 5783Zeile 5911
	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 5901Zeile 6029
function get_event_link($eid)
{
$link = str_replace("{eid}", $eid, EVENT_URL);

function get_event_link($eid)
{
$link = str_replace("{eid}", $eid, EVENT_URL);

	return htmlspecialchars_uni($link);
}


	return htmlspecialchars_uni($link);
}


/**
* Build the link to a specified date on the calendar
*

/**
* Build the link to a specified date on the calendar
*

Zeile 5938Zeile 6066
	{
$link = str_replace("{calendar}", $calendar, CALENDAR_URL);
return htmlspecialchars_uni($link);

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

	}
}

	}
}


/**
* Build the link to a specified week on the calendar


/**
* Build the link to a specified week on the calendar

Zeile 5951Zeile 6079
function get_calendar_week_link($calendar, $week)
{
if($week < 0)

function get_calendar_week_link($calendar, $week)
{
if($week < 0)

	{

	{

		$week = str_replace('-', "n", $week);
}
$link = str_replace("{week}", $week, CALENDAR_URL_WEEK);

		$week = str_replace('-', "n", $week);
}
$link = str_replace("{week}", $week, CALENDAR_URL_WEEK);

Zeile 5963Zeile 6091
 * Get the user data of an user id.
*
* @param int $uid The user id of the user.

 * Get the user data of an user id.
*
* @param int $uid The user id of the user.

 * @return array The users data

 * @return array The users data

 */
function get_user($uid)
{
global $mybb, $db;
static $user_cache;

 */
function get_user($uid)
{
global $mybb, $db;
static $user_cache;





	$uid = (int)$uid;

if(!empty($mybb->user) && $uid == $mybb->user['uid'])
{
return $mybb->user;

	$uid = (int)$uid;

if(!empty($mybb->user) && $uid == $mybb->user['uid'])
{
return $mybb->user;

	}

	}

	elseif(isset($user_cache[$uid]))
{
return $user_cache[$uid];

	elseif(isset($user_cache[$uid]))
{
return $user_cache[$uid];

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

{

{

	global $mybb, $db;

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

	global $mybb, $db;

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

Zeile 6022Zeile 6150
	}

switch($options['username_method'])

	}

switch($options['username_method'])

	{

	{

		case 1:
$sqlwhere = "{$efield}='{$username}'";
break;

		case 1:
$sqlwhere = "{$efield}='{$username}'";
break;

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

Zeile 6092Zeile 6220

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


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

 *

 *

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

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

Zeile 6128Zeile 6256

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


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

 *

 *

 * @param int $pid The post id of the post.
* @return array|bool The database row of the post. False on failure
*/

 * @param int $pid The post id of the post.
* @return array|bool The database row of the post. False on failure
*/

Zeile 6136Zeile 6264
{
global $db;
static $post_cache;

{
global $db;
static $post_cache;





	$pid = (int)$pid;

if(isset($post_cache[$pid]))

	$pid = (int)$pid;

if(isset($post_cache[$pid]))

	{

	{

		return $post_cache[$pid];
}
else

		return $post_cache[$pid];
}
else

Zeile 6152Zeile 6280
		{
$post_cache[$pid] = $post;
return $post;

		{
$post_cache[$pid] = $post;
return $post;

		}

		}

		else
{
$post_cache[$pid] = false;

		else
{
$post_cache[$pid] = false;

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

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

				}

				}

			}
}
}

			}
}
}

Zeile 6210Zeile 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.

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

	// Use cookie if possible, otherwise use session
// Find better solution to prevent clearing cookies
$loginattempts = 0;

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

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

	}


	}


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

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

Zeile 6253Zeile 6381
		if(empty($failedlogin))
{
my_setcookie('failedlogin', $now);

		if(empty($failedlogin))
{
my_setcookie('failedlogin', $now);

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


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

Zeile 6341Zeile 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'];
$setting['value'] = addcslashes($setting['value'], '\\"$');
$settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n";

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

	}



	}

$settings = "<"."?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n";





	$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 6388Zeile 6505
	}

if(is_array($terms))

	}

if(is_array($terms))

	{

	{

		$terms = implode(' ', $terms);
}


		$terms = implode(' ', $terms);
}


Zeile 6412Zeile 6529
		{
$phrase = htmlspecialchars_uni($phrase);
if($phrase != "")

		{
$phrase = htmlspecialchars_uni($phrase);
if($phrase != "")

			{

			{

				if($inquote)
{
$words[] = trim($phrase);

				if($inquote)
{
$words[] = trim($phrase);

Zeile 6435Zeile 6552
				}
}
$inquote = !$inquote;

				}
}
$inquote = !$inquote;

		}

		}

	}
// Otherwise just a simple search query with no phrases
else

	}
// Otherwise just a simple search query with no phrases
else

Zeile 6458Zeile 6575
	if(!is_array($words))
{
return false;

	if(!is_array($words))
{
return false;

	}


	}


	// Sort the word array by length. Largest terms go first and work their way down to the smallest term.
// This resolves problems like "test tes" where "tes" will be highlighted first, then "test" can't be highlighted because of the changed html

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

}

/**

}

/**

Zeile 7583Zeile 7712
					array('::', '(int)"$1"?"$1":"0$1"'),
$r);
return $r;

					array('::', '(int)"$1"?"$1":"0$1"'),
$r);
return $r;

		}
return false;
}

		}
return false;
}

}

/**

}

/**

Zeile 7617Zeile 7746
			}
$upper = str_replace('*', '255', $ipaddress);
$lower = str_replace('*', '0', $ipaddress);

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

		}

		}

		$upper = my_inet_pton($upper);
$lower = my_inet_pton($lower);
if($upper === false || $lower === false)

		$upper = my_inet_pton($upper);
$lower = my_inet_pton($lower);
if($upper === false || $lower === false)

Zeile 7712Zeile 7841
{
static $time_start;


{
static $time_start;


	$time = microtime(true);



	$time = microtime(true);



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

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

Zeile 7968Zeile 8097
 * @return int An integer equivalent of a secure hexadecimal seed
*/
function secure_seed_rng()

 * @return int An integer equivalent of a secure hexadecimal seed
*/
function secure_seed_rng()

{

{

	$bytes = PHP_INT_SIZE;

do

	$bytes = PHP_INT_SIZE;

do

Zeile 8224Zeile 8353
{
// Valid UTF-8 sequence?
if(!preg_match('##u', $input))

{
// Valid UTF-8 sequence?
if(!preg_match('##u', $input))

	{

	{

		$string = '';
$len = strlen($input);
for($i = 0; $i < $len; $i++)

		$string = '';
$len = strlen($input);
for($i = 0; $i < $len; $i++)

Zeile 8479Zeile 8608
	global $db, $session;

if(!is_array($data))

	global $db, $session;

if(!is_array($data))

	{

	{

		$data = array($data);
}


		$data = array($data);
}


Zeile 8511Zeile 8640
 * @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;


	global $mybb, $plugins;


	$success = false;

$file_path = (string)$file_path;

	$success = false;







	$real_file_path = realpath($file_path);



	$file_path = (string)$file_path;

$real_file_path = realpath($file_path);


$file_dir_path = dirname($real_file_path);
$file_dir_path = str_replace(MYBB_ROOT, '', $file_dir_path);
$file_dir_path = ltrim($file_dir_path, './\\');


$file_dir_path = dirname($real_file_path);
$file_dir_path = str_replace(MYBB_ROOT, '', $file_dir_path);
$file_dir_path = ltrim($file_dir_path, './\\');





	$file_name = basename($real_file_path);

if(file_exists($file_path))

	$file_name = basename($real_file_path);

if(file_exists($file_path))

	{

	{

		if($mybb->settings['usecdn'] && !empty($mybb->settings['cdnpath']))
{
$cdn_path = rtrim($mybb->settings['cdnpath'], '/\\');

		if($mybb->settings['usecdn'] && !empty($mybb->settings['cdnpath']))
{
$cdn_path = rtrim($mybb->settings['cdnpath'], '/\\');

Zeile 8535Zeile 8664
			if(substr($file_dir_path, 0, my_strlen(MYBB_ROOT)) == MYBB_ROOT)
{
$file_dir_path = str_replace(MYBB_ROOT, '', $file_dir_path);

			if(substr($file_dir_path, 0, my_strlen(MYBB_ROOT)) == MYBB_ROOT)
{
$file_dir_path = str_replace(MYBB_ROOT, '', $file_dir_path);

			}


			}


			$cdn_upload_path = $cdn_path . DIRECTORY_SEPARATOR . $file_dir_path;

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

			$cdn_upload_path = $cdn_path . DIRECTORY_SEPARATOR . $file_dir_path;

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)
{
$success = @copy($file_path, $cdn_upload_path.DIRECTORY_SEPARATOR.$file_name);

			if($dir_exists)
{
if(($cdn_upload_path = realpath($cdn_upload_path)) !== false)
{
$success = @copy($file_path, $cdn_upload_path.DIRECTORY_SEPARATOR.$file_name);





					if($success)
{
$uploaded_path = $cdn_upload_path;

					if($success)
{
$uploaded_path = $cdn_upload_path;

Zeile 8559Zeile 8688
		}

if(is_object($plugins))

		}

if(is_object($plugins))

		{

		{

			$hook_args = array(
'file_path' => &$file_path,
'real_file_path' => &$real_file_path,

			$hook_args = array(
'file_path' => &$file_path,
'real_file_path' => &$real_file_path,

Zeile 8567Zeile 8696
				'uploaded_path' => &$uploaded_path,
'success' => &$success,
);

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





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

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





	return $success;

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



 
	return false;

	return false;

}

/**

}

/**

 * Strip html tags from string, also removes <script> and <style> contents.

 * Strip html tags from string, also removes <script> and <style> contents.

 * 

 *

 * @param  string $string         String to stripe
* @param string $allowable_tags Allowed html tags

 * @param  string $string         String to stripe
* @param string $allowable_tags Allowed html tags

 * 

 *

 * @return string                 Striped string
*/
function my_strip_tags($string, $allowable_tags = '')

 * @return string                 Striped string
*/
function my_strip_tags($string, $allowable_tags = '')

Zeile 8611Zeile 8749
	);
$string = preg_replace($pattern, '', $string);
return strip_tags($string, $allowable_tags);

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

}

}