diff options
| author | Andreas Fischer <bantu@phpbb.com> | 2012-01-02 18:53:55 +0100 | 
|---|---|---|
| committer | Andreas Fischer <bantu@phpbb.com> | 2012-01-02 18:53:55 +0100 | 
| commit | 2345be38b682a58f9b5e5429c76db97a0564093d (patch) | |
| tree | fe39c5f348f86c23f3c9af9011d6d0c1b0c0baf5 /phpBB/includes/functions.php | |
| parent | c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff (diff) | |
| parent | e14c3f3b77ab07ce97f357a15db5db5101df06c1 (diff) | |
| download | forums-2345be38b682a58f9b5e5429c76db97a0564093d.tar forums-2345be38b682a58f9b5e5429c76db97a0564093d.tar.gz forums-2345be38b682a58f9b5e5429c76db97a0564093d.tar.bz2 forums-2345be38b682a58f9b5e5429c76db97a0564093d.tar.xz forums-2345be38b682a58f9b5e5429c76db97a0564093d.zip | |
Merge branch 'prep-release-3.0.10'
* prep-release-3.0.10: (221 commits)
  [prep-release-3.0.10] Bumping version number for 3.0.10 final.
  [prep-release-3.0.10] Update Changelog for 3.0.10-RC3 release.
  [ticket/10531] Disallow deleting of the last style
  [ticket/8996] Revert initial fix to keep old behaviour on empty selection Part2
  [ticket/8996] Revert initial fix to keep old behaviour on empty selection
  [ticket/10319] Missing hidden fields in search form
  [ticket/10504] Revert the changes for widescreen optimisation PHPBB3-6632
  [ticket/10504] Revert the changes for widescreen optimisation PHPBB3-10408
  [ticket/10504] Revert the changes for widescreen optimisation PHPBB3-10485
  [prep-release-3.0.10] Bumping version number for 3.0.10-RC3.
  [ticket/10480] Add a build target for changelog building.
  [ticket/10480] Add a build script for exporting the changelog from tracker.
  [ticket/10502] Fix typo in changelog. 'red' should have been 'read'.
  [prep-release-3.0.10] Remove duplicate ticket PHPBB3-10490 from changelog.
  [ticket/10501] Fix description of table prefixes
  [ticket/10503] Debug error "Invalid arguments" when previewing edits
  [prep-release-3.0.10] Update Changelog for 3.0.10-RC2 release.
  [ticket/10497] Fix SQL error when guest visits forum with unread topic
  [prep-release-3.0.10] Bumping version number for 3.0.10-RC2.
  [ticket/10461] Add a comment explaining the logic here.
  ...
Diffstat (limited to 'phpBB/includes/functions.php')
| -rw-r--r-- | phpBB/includes/functions.php | 202 | 
1 files changed, 145 insertions, 57 deletions
| diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b1c1c14d0c..01b3ca92a9 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -266,6 +266,27 @@ function phpbb_mt_rand($min, $max)  }  /** +* Wrapper for getdate() which returns the equivalent array for UTC timestamps. +* +* @param int $time		Unix timestamp (optional) +* +* @return array			Returns an associative array of information related to the timestamp. +*						See http://www.php.net/manual/en/function.getdate.php +*/ +function phpbb_gmgetdate($time = false) +{ +	if ($time === false) +	{ +		$time = time(); +	} + +	// getdate() interprets timestamps in local time. +	// What follows uses the fact that getdate() and +	// date('Z') balance each other out. +	return getdate($time - date('Z')); +} + +/**  * Return formatted string for filesizes  *  * @param int	$value			filesize in bytes @@ -599,6 +620,34 @@ function phpbb_email_hash($email)  }  /** +* Wrapper for version_compare() that allows using uppercase A and B +* for alpha and beta releases. +* +* See http://www.php.net/manual/en/function.version-compare.php +* +* @param string $version1		First version number +* @param string $version2		Second version number +* @param string $operator		Comparison operator (optional) +* +* @return mixed					Boolean (true, false) if comparison operator is specified. +*								Integer (-1, 0, 1) otherwise. +*/ +function phpbb_version_compare($version1, $version2, $operator = null) +{ +	$version1 = strtolower($version1); +	$version2 = strtolower($version2); + +	if (is_null($operator)) +	{ +		return version_compare($version1, $version2); +	} +	else +	{ +		return version_compare($version1, $version2, $operator); +	} +} + +/**  * Global function for chmodding directories and files for internal use  *  * This function determines owner and group whom the file belongs to and user and group of PHP and then set safest possible file permissions. @@ -1831,7 +1880,7 @@ function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $s  */  function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time = false, $mark_time_forum = false)  { -	global $db, $tracking_topics, $user, $config; +	global $db, $tracking_topics, $user, $config, $auth;  	// Determine the users last forum mark time if not given.  	if ($mark_time_forum === false) @@ -1854,6 +1903,10 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti  		}  	} +	// Handle update of unapproved topics info. +	// Only update for moderators having m_approve permission for the forum. +	$sql_update_unapproved = ($auth->acl_get('m_approve', $forum_id)) ? '': 'AND t.topic_approved = 1'; +  	// Check the forum for any left unread topics.  	// If there are none, we mark the forum as read.  	if ($config['load_db_lastread'] && $user->data['is_registered']) @@ -1869,7 +1922,8 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti  				LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')  				WHERE t.forum_id = ' . $forum_id . '  					AND t.topic_last_post_time > ' . $mark_time_forum . ' -					AND t.topic_moved_id = 0 +					AND t.topic_moved_id = 0 ' . +					$sql_update_unapproved . '  					AND (tt.topic_id IS NULL OR tt.mark_time < t.topic_last_post_time)  				GROUP BY t.forum_id';  			$result = $db->sql_query_limit($sql, 1); @@ -1889,11 +1943,12 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti  		}  		else  		{ -			$sql = 'SELECT topic_id -				FROM ' . TOPICS_TABLE . ' -				WHERE forum_id = ' . $forum_id . ' -					AND topic_last_post_time > ' . $mark_time_forum . ' -					AND topic_moved_id = 0'; +			$sql = 'SELECT t.topic_id +				FROM ' . TOPICS_TABLE . ' t +				WHERE t.forum_id = ' . $forum_id . ' +					AND t.topic_last_post_time > ' . $mark_time_forum . ' +					AND t.topic_moved_id = 0 ' . +					$sql_update_unapproved;  			$result = $db->sql_query($sql);  			$check_forum = $tracking_topics['tf'][$forum_id]; @@ -2078,7 +2133,7 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add  		$start_cnt = min(max(1, $on_page - 4), $total_pages - 5);  		$end_cnt = max(min($total_pages, $on_page + 4), 6); -		$page_string .= ($start_cnt > 1) ? ' ... ' : $seperator; +		$page_string .= ($start_cnt > 1) ? '<span class="page-dots"> ... </span>' : $seperator;  		for ($i = $start_cnt + 1; $i < $end_cnt; $i++)  		{ @@ -2089,7 +2144,7 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add  			}  		} -		$page_string .= ($end_cnt < $total_pages) ? ' ... ' : $seperator; +		$page_string .= ($end_cnt < $total_pages) ? '<span class="page-dots"> ... </span>' : $seperator;  	}  	else  	{ @@ -2176,6 +2231,12 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false)  {  	global $_SID, $_EXTRA_URL, $phpbb_hook; +	if ($params === '' || (is_array($params) && empty($params))) +	{ +		// Do not append the ? if the param-list is empty anyway. +		$params = false; +	} +  	// Developers using the hook function need to globalise the $_SID and $_EXTRA_URL on their own and also handle it appropriately.  	// They could mimic most of what is within this function  	if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id)) @@ -2659,12 +2720,6 @@ function send_status_line($code, $message)  		{  			$version = $_SERVER['SERVER_PROTOCOL'];  		} -		else if (!empty($_SERVER['HTTP_VERSION'])) -		{ -			// I cannot remember where I got this from. -			// This code path may never be reachable in reality. -			$version = $_SERVER['HTTP_VERSION']; -		}  		else  		{  			$version = 'HTTP/1.0'; @@ -3338,61 +3393,44 @@ function add_log()  }  /** -* Return a nicely formatted backtrace (parts from the php manual by diz at ysagoon dot com) +* Return a nicely formatted backtrace. +* +* Turns the array returned by debug_backtrace() into HTML markup. +* Also filters out absolute paths to phpBB root. +* +* @return string	HTML markup  */  function get_backtrace()  { -	global $phpbb_root_path; -  	$output = '<div style="font-family: monospace;">';  	$backtrace = debug_backtrace(); -	$path = phpbb_realpath($phpbb_root_path); -	foreach ($backtrace as $number => $trace) -	{ -		// We skip the first one, because it only shows this file/function -		if ($number == 0) -		{ -			continue; -		} +	// We skip the first one, because it only shows this file/function +	unset($backtrace[0]); +	foreach ($backtrace as $trace) +	{  		// Strip the current directory from path -		if (empty($trace['file'])) -		{ -			$trace['file'] = ''; -		} -		else -		{ -			$trace['file'] = str_replace(array($path, '\\'), array('', '/'), $trace['file']); -			$trace['file'] = substr($trace['file'], 1); -		} -		$args = array(); +		$trace['file'] = (empty($trace['file'])) ? '(not given by php)' : htmlspecialchars(phpbb_filter_root_path($trace['file'])); +		$trace['line'] = (empty($trace['line'])) ? '(not given by php)' : $trace['line']; -		// If include/require/include_once is not called, do not show arguments - they may contain sensible information -		if (!in_array($trace['function'], array('include', 'require', 'include_once'))) +		// Only show function arguments for include etc. +		// Other parameters may contain sensible information +		$argument = ''; +		if (!empty($trace['args'][0]) && in_array($trace['function'], array('include', 'require', 'include_once', 'require_once')))  		{ -			unset($trace['args']); -		} -		else -		{ -			// Path... -			if (!empty($trace['args'][0])) -			{ -				$argument = htmlspecialchars($trace['args'][0]); -				$argument = str_replace(array($path, '\\'), array('', '/'), $argument); -				$argument = substr($argument, 1); -				$args[] = "'{$argument}'"; -			} +			$argument = htmlspecialchars(phpbb_filter_root_path($trace['args'][0]));  		}  		$trace['class'] = (!isset($trace['class'])) ? '' : $trace['class'];  		$trace['type'] = (!isset($trace['type'])) ? '' : $trace['type'];  		$output .= '<br />'; -		$output .= '<b>FILE:</b> ' . htmlspecialchars($trace['file']) . '<br />'; +		$output .= '<b>FILE:</b> ' . $trace['file'] . '<br />';  		$output .= '<b>LINE:</b> ' . ((!empty($trace['line'])) ? $trace['line'] : '') . '<br />'; -		$output .= '<b>CALL:</b> ' . htmlspecialchars($trace['class'] . $trace['type'] . $trace['function']) . '(' . ((sizeof($args)) ? implode(', ', $args) : '') . ')<br />'; +		$output .= '<b>CALL:</b> ' . htmlspecialchars($trace['class'] . $trace['type'] . $trace['function']); +		$output .= '(' . (($argument !== '') ? "'$argument'" : '') . ')<br />';  	}  	$output .= '</div>';  	return $output; @@ -3454,6 +3492,10 @@ function get_preg_expression($mode)  			$inline = ($mode == 'relative_url') ? ')' : '';  			return "(?:[a-z0-9\-._~!$&'($inline*+,;=:@|]+|%[\dA-F]{2})*(?:/(?:[a-z0-9\-._~!$&'($inline*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~!$&'($inline*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-z0-9\-._~!$&'($inline*+,;=:@/?|]+|%[\dA-F]{2})*)?";  		break; + +		case 'table_prefix': +			return '#^[a-zA-Z][a-zA-Z0-9_]*$#'; +		break;  	}  	return ''; @@ -3686,10 +3728,19 @@ function phpbb_checkdnsrr($host, $type = 'MX')  					{  						return true;  					} +				break;  				default: -				case 'A':  				case 'AAAA': +					// AAAA records returned by nslookup on Windows XP/2003 have this format. +					// Later Windows versions use the A record format below for AAAA records. +					if (stripos($line, "$host AAAA IPv6 address") === 0) +					{ +						return true; +					} +				// No break + +				case 'A':  					if (!empty($host_matches))  					{  						// Second line @@ -3758,9 +3809,8 @@ function msg_handler($errno, $msg_text, $errfile, $errline)  			if (strpos($errfile, 'cache') === false && strpos($errfile, 'template.') === false)  			{ -				// remove complete path to installation, with the risk of changing backslashes meant to be there -				$errfile = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $errfile); -				$msg_text = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $msg_text); +				$errfile = phpbb_filter_root_path($errfile); +				$msg_text = phpbb_filter_root_path($msg_text);  				$error_name = ($errno === E_WARNING) ? 'PHP Warning' : 'PHP Notice';  				echo '<b>[phpBB Debug] ' . $error_name . '</b>: in file <b>' . $errfile . '</b> on line <b>' . $errline . '</b>: <b>' . $msg_text . '</b><br />' . "\n"; @@ -3939,6 +3989,29 @@ function msg_handler($errno, $msg_text, $errfile, $errline)  }  /** +* Removes absolute path to phpBB root directory from error messages +* and converts backslashes to forward slashes. +* +* @param string $errfile	Absolute file path +*							(e.g. /var/www/phpbb3/phpBB/includes/functions.php) +*							Please note that if $errfile is outside of the phpBB root, +*							the root path will not be found and can not be filtered. +* @return string			Relative file path +*							(e.g. /includes/functions.php) +*/ +function phpbb_filter_root_path($errfile) +{ +	static $root_path; + +	if (empty($root_path)) +	{ +		$root_path = phpbb_realpath(dirname(__FILE__) . '/../'); +	} + +	return str_replace(array($root_path, '\\'), array('[ROOT]', '/'), $errfile); +} + +/**  * Queries the session table to get information about online guests  * @param int $item_id Limits the search to the item with this id  * @param string $item The name of the item which is stored in the session table as session_{$item}_id @@ -4305,7 +4378,7 @@ function phpbb_http_login($param)  */  function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum')  { -	global $db, $config, $template, $SID, $_SID, $user, $auth, $phpEx, $phpbb_root_path; +	global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path;  	if (defined('HEADER_INC'))  	{ @@ -4458,6 +4531,15 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0  		$s_search_hidden_fields['sid'] = $_SID;  	} +	if (!empty($_EXTRA_URL)) +	{ +		foreach ($_EXTRA_URL as $url_param) +		{ +			$url_param = explode('=', $url_param, 2); +			$s_hidden_fields[$url_param[0]] = $url_param[1]; +		} +	} +  	// The following assigns all _common_ variables that may be used at any point in a template.  	$template->assign_vars(array(  		'SITENAME'						=> $config['sitename'], @@ -4589,6 +4671,12 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0  	header('Expires: 0');  	header('Pragma: no-cache'); +	if (!empty($user->data['is_bot'])) +	{ +		// Let reverse proxies know we detected a bot. +		header('X-PHPBB-IS-BOT: yes'); +	} +  	return;  } | 
