Browse Source

! Removed $context['complex_preg_chars'] usage in regex, only was required for php < 4.3.2
! Removed version_compare() calls and sections used to execute code for older versions of php Load.php Subs.php LogInOut.php Subs-Auth.php
! Minor tweaks to index.template for consistency
! More minor doc changes
! Pedantic changes ===
! ob_end_clean/ob_start replaced with ob_clean attachment.php

Spuds 12 years ago
parent
commit
6d253143bc

+ 2 - 2
Sources/Display.php

@@ -144,7 +144,7 @@ function Display()
 	}
 
 	// @todo Why isn't this cached?
-	// @todo if we get id_board in this query, we can save a query on posting
+	// @todo if we get id_board in this query and cache it, we can save a query on posting
 	// Get all the important topic info.
 	$request = $smcFunc['db_query']('', '
 		SELECT
@@ -213,7 +213,7 @@ function Display()
 	list ($lastPostTime) = $smcFunc['db_fetch_row']($request);
 	$smcFunc['db_free_result']($request);
 
-	$context['oldTopicError'] = !empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky);
+	$context['oldTopicError'] = !empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($topicinfo['is_sticky']);
 
 	// The start isn't a number; it's information about what to do, where to go.
 	if (!is_numeric($_REQUEST['start']))

+ 1 - 1
Sources/Groups.php

@@ -230,7 +230,7 @@ function GroupList()
  */
 function list_getGroups($start, $items_per_page, $sort)
 {
-	global $smcFunc, $txt, $scripturl, $user_info, $settings;
+	global $smcFunc, $txt, $scripturl, $user_info, $settings, $context;
 
 	// Yep, find the groups...
 	$request = $smcFunc['db_query']('', '

+ 17 - 17
Sources/Load.php

@@ -63,14 +63,14 @@ function reloadSettings()
 	}
 
 	// UTF-8 in regular expressions is unsupported on PHP(win) versions < 4.2.3.
-	$utf8 = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || version_compare(PHP_VERSION, '4.2.3', '>='));
+	$utf8 = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
 
 	// Set a list of common functions.
 	$ent_list = empty($modSettings['disableEntityCheck']) ? '&(#\d{1,7}|quot|amp|lt|gt|nbsp);' : '&(#021|quot|amp|lt|gt|nbsp);';
 	$ent_check = empty($modSettings['disableEntityCheck']) ? array('preg_replace(\'~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~e\', \'$smcFunc[\\\'entity_fix\\\'](\\\'\\2\\\')\', ', ')') : array('', '');
 
 	// Preg_replace can handle complex characters only for higher PHP versions.
-	$space_chars = $utf8 ? (version_compare(PHP_VERSION, '4.3.3', '>=') ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : "\xC2\xA0\xC2\xAD\xE2\x80\x80-\xE2\x80\x8F\xE2\x80\x9F\xE2\x80\xAF\xE2\x80\x9F\xE3\x80\x80\xEF\xBB\xBF") : '\x00-\x08\x0B\x0C\x0E-\x19\xA0';
+	$space_chars = $utf8 ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0';
 
 	/**
 	 * @global array An array of anonymous helper functions.
@@ -765,7 +765,7 @@ function loadPermissions()
 
 			return;
 		}
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
+		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) !== null && time() - 240 > $modSettings['settings_updated'])
 			list ($user_info['permissions'], $removals) = $temp;
 	}
 
@@ -1217,6 +1217,7 @@ function loadMemberContext($user, $display_custom_fields = false)
 		}
 	}
 
+	call_integration_hook('integrate_member_context', array(&$user, $display_custom_fields));
 	return true;
 }
 
@@ -1332,7 +1333,7 @@ function loadTheme($id_theme = 0, $initialize = true)
 		$themeData = $temp;
 		$flag = true;
 	}
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
+	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) !== null && time() - 60 > $modSettings['settings_updated'])
 		$themeData = $temp + array($member => array());
 	else
 		$themeData = array(-1 => array(), 0 => array(), $member => array());
@@ -1408,7 +1409,7 @@ function loadTheme($id_theme = 0, $initialize = true)
 	// Check to see if they're accessing it from the wrong place.
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
 	{
-		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
+		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on' ? 'https://' : 'http://';
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
 		if ($temp != '/')
@@ -1535,7 +1536,7 @@ function loadTheme($id_theme = 0, $initialize = true)
 		'is_cgi' => isset($_SERVER['SERVER_SOFTWARE']) && strpos(php_sapi_name(), 'cgi') !== false,
 		'is_windows' => strpos(PHP_OS, 'WIN') === 0,
 		'iso_case_folding' => ord(strtolower(chr(138))) === 154,
-		'complex_preg_chars' => @version_compare(PHP_VERSION, '4.3.3') != -1,
+		'complex_preg_chars' => version_compare(PHP_VERSION, '4.3.3') != -1,
 	);
 	// A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
 	$context['server']['needs_login_fix'] = $context['server']['is_cgi'] && $context['server']['is_iis'];
@@ -1663,14 +1664,14 @@ function loadTheme($id_theme = 0, $initialize = true)
 
 	// Set the character set from the template.
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
-	$context['utf8'] = $context['character_set'] === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || version_compare(PHP_VERSION, '4.2.3', '>='));
+	$context['utf8'] = $context['character_set'] === 'UTF-8';
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
 
 	$context['tabindex'] = 1;
 
 	// Fix font size with HTML 4.01, etc.
 	if (isset($settings['doctype']))
-		$context['browser']['needs_size_fix'] |= $settings['doctype'] == 'html' && isBrowser('ie6');
+		$context['browser']['needs_size_fix'] |= $settings['doctype'] === 'html' && isBrowser('ie6');
 
 	// Compatibility.
 	if (!isset($settings['theme_version']))
@@ -1806,14 +1807,14 @@ function loadTemplate($template_name, $style_sheets = array(), $fatal = true)
 			loadLanguage('Errors');
 			echo '
 <div class="alert errorbox">
-	<a href="', $scripturl . '?action=admin;area=theme;sa=settings;th=1;' . $context['session_var'] . '=' . $context['session_id'], '" class="alert">', $txt['theme_dir_wrong'], '</a>
+	<a href="', $scripturl, '?action=admin;area=theme;sa=settings;th=1;', $context['session_var'], '=' . $context['session_id'], '" class="alert">', $txt['theme_dir_wrong'], '</a>
 </div>';
 		}
 
 		loadTemplate($template_name);
 	}
 	// Cause an error otherwise.
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
+	elseif ($template_name !== 'Errors' && $template_name !== 'index' && $fatal)
 		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
 	elseif ($fatal)
 		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
@@ -1825,10 +1826,9 @@ function loadTemplate($template_name, $style_sheets = array(), $fatal = true)
 /**
  * Load a sub-template.
  * What it does:
- * 	- loads the sub template specified by sub_template_name, which must be in an already-loaded
- *  template.
+ * 	- loads the sub template specified by sub_template_name, which must be in an already-loaded template.
  *  - if ?debug is in the query string, shows administrators a marker after every sub template
- *   for debugging purposes.
+ *    for debugging purposes.
  *
  * @todo get rid of reading $_REQUEST directly
  *
@@ -1875,7 +1875,7 @@ function loadCSSFile($filename, $options = array())
 }
 
 /**
- * Add a CSS file for output later
+ * Add a Javascript file for output later
  * @param string $filename
  * @param array $options
  */
@@ -1883,7 +1883,7 @@ function loadJavascriptFile($filename, $options = array())
 {
 	global $settings, $context;
 
-	if (strpos($filename, 'http://') === false || !empty($options['local']))
+	if (strpos($filename, 'http') === false || !empty($options['local']))
 		$filename = $settings['theme_url'] . '/' . $filename;
 
 	$context['javascript_files'][$filename] = $options;
@@ -2023,7 +2023,7 @@ function getBoardParents($id_parent)
 				)
 			);
 			// In the EXTREMELY unlikely event this happens, give an error message.
-			if ($smcFunc['db_num_rows']($result) == 0)
+			if ($smcFunc['db_num_rows']($result) === 0)
 				fatal_lang_error('parent_not_found', 'critical');
 			while ($row = $smcFunc['db_fetch_assoc']($result))
 			{
@@ -2411,7 +2411,7 @@ function loadDatabase()
 		display_db_error();
 
 	// If in SSI mode fix up the prefix.
-	if (SMF == 'SSI')
+	if (SMF === 'SSI')
 		db_fix_prefix($db_prefix, $db_name);
 }
 

+ 3 - 13
Sources/LogInOut.php

@@ -646,19 +646,9 @@ function phpBB3_password_check($passwd, $passwd_hash)
 	$count2 = $count;
 	$salt = substr($passwd_hash, 4, 8);
 
-	// Things are done differently for PHP 5.
-	if (version_compare(PHP_VERSION, '5', '>='))
-	{
-		$hash = md5($salt . $passwd, true);
-		for (; $count != 0; --$count)
-			$hash = md5($hash . $passwd, true);
-	}
-	else
-	{
-		$hash = pack('H*', md5($salt . $passwd));
-		for (; $count != 0; --$count)
-			$hash = pack('H*', md5($hash . $passwd));
-	}
+	$hash = md5($salt . $passwd, true);
+	for (; $count != 0; --$count)
+		$hash = md5($hash . $passwd, true);
 
 	$output = substr($passwd_hash, 0, 12);
 	$i = 0;

+ 1 - 7
Sources/Logging.php

@@ -270,13 +270,7 @@ function displayDebug()
 
 	// Gotta have valid HTML ;).
 	$temp = ob_get_contents();
-	if (function_exists('ob_clean'))
-		ob_clean();
-	else
-	{
-		ob_end_clean();
-		ob_start('ob_sessrewrite');
-	}
+	ob_clean();
 
 	echo preg_replace('~</body>\s*</html>~', '', $temp), '
 <div class="smalltext" style="text-align: left; margin: 1ex;">

+ 2 - 4
Sources/PostModeration.php

@@ -50,7 +50,7 @@ function PostModerationMain()
  */
 function UnapprovedPosts()
 {
-	global $txt, $scripturl, $context, $user_info, $sourcedir, $smcFunc;
+	global $txt, $scripturl, $context, $user_info, $smcFunc;
 
 	$context['current_view'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? 'topics' : 'replies';
 	$context['page_title'] = $txt['mc_unapproved_posts'];
@@ -59,9 +59,7 @@ function UnapprovedPosts()
 	$approve_boards = boardsAllowedTo('approve_posts');
 
 	// If we filtered by board remove ones outside of this board.
-	/**
-	 * @todo Put a message saying we're filtered?
-	 */
+	// @todo Put a message saying we're filtered?
 	if (isset($_REQUEST['brd']))
 	{
 		$filter_board = array((int) $_REQUEST['brd']);

+ 3 - 3
Sources/QueryString.php

@@ -69,7 +69,7 @@ function cleanRequest()
 	}
 
 	// Are we going to need to parse the ; out?
-	if ((strpos(ini_get('arg_separator.input'), ';') === false || version_compare(PHP_VERSION, '4.2.0', '<')) && !empty($_SERVER['QUERY_STRING']))
+	if (strpos(ini_get('arg_separator.input'), ';') === false && !empty($_SERVER['QUERY_STRING']))
 	{
 		// Get rid of the old one! You don't know where it's been!
 		$_GET = array();
@@ -551,7 +551,7 @@ function cleanXml($string)
 	global $context;
 
 	// http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char
-	return preg_replace('~[\x00-\x08\x0B\x0C\x0E-\x19' . ($context['utf8'] ? (version_compare(PHP_VERSION, '4.3.3', '>=') ? '\x{D800}-\x{DFFF}\x{FFFE}\x{FFFF}' : "\xED\xA0\x80-\xED\xBF\xBF\xEF\xBF\xBE\xEF\xBF\xBF") : '') . ']~' . ($context['utf8'] ? 'u' : ''), '', $string);
+	return preg_replace('~[\x00-\x08\x0B\x0C\x0E-\x19' . ($context['utf8'] ? '\x{D800}-\x{DFFF}\x{FFFE}\x{FFFF}' : '') . ']~' . ($context['utf8'] ? 'u' : ''), '', $string);
 }
 
 /**
@@ -601,7 +601,7 @@ function ob_sessrewrite($buffer)
 
 	// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
 	// @todo smflib
-	if (empty($_COOKIE) && SID != '' && isBrowser('possibly_robot') && version_compare(PHP_VERSION, '4.3.0', '>='))
+	if (empty($_COOKIE) && SID != '' && isBrowser('possibly_robot'))
 		$buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
 	// Debugging templates, are we?
 	elseif (isset($_GET['debug']))

+ 1 - 1
Sources/Recent.php

@@ -236,7 +236,7 @@ function RecentPosts()
 		while (!$done)
 		{
 			// Find the 10 most recent messages they can *view*.
-			// @todoSLOW This query is really slow still, probably?
+			// @todo SLOW This query is really slow still, probably?
 			$request = $smcFunc['db_query']('', '
 				SELECT m.id_msg
 				FROM {db_prefix}messages AS m

+ 1 - 1
Sources/Register.php

@@ -832,7 +832,7 @@ function RegisterCheckUsername()
 	$context['valid_username'] = true;
 
 	// Clean it up like mother would.
-	$context['checked_username'] = preg_replace('~[\t\n\r\x0B\0' . ($context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}' : "\xC2\xA0") : '\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $context['checked_username']);
+	$context['checked_username'] = preg_replace('~[\t\n\r\x0B\0' . ($context['utf8'] ? '\x{A0}' : '\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $context['checked_username']);
 	if ($smcFunc['strlen']($context['checked_username']) > 25)
 		$context['checked_username'] = $smcFunc['htmltrim']($smcFunc['substr']($context['checked_username'], 0, 25));
 

+ 1 - 1
Sources/Search.php

@@ -601,7 +601,7 @@ function PlushSearch2()
 	}
 
 	// Change non-word characters into spaces.
-	$stripped_query = preg_replace('~(?:[\x0B\0' . ($context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}' : "\xC2\xA0") : '\xA0') . '\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~' . ($context['utf8'] ? 'u' : ''), ' ', $search_params['search']);
+	$stripped_query = preg_replace('~(?:[\x0B\0' . ($context['utf8'] ? '\x{A0}' : '\xA0') . '\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~' . ($context['utf8'] ? 'u' : ''), ' ', $search_params['search']);
 
 	// Make the query lower case. It's gonna be case insensitive anyway.
 	$stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query));

+ 3 - 5
Sources/Session.php

@@ -60,7 +60,7 @@ function loadSession()
 		}
 
 		// Use database sessions? (they don't work in 4.1.x!)
-		if (!empty($modSettings['databaseSession_enable']) && version_compare(PHP_VERSION, '4.2.0', '>='))
+		if (!empty($modSettings['databaseSession_enable']))
 		{
 			session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC');
 			@ini_set('session.gc_probability', '1');
@@ -71,6 +71,8 @@ function loadSession()
 		// Use cache setting sessions?
 		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli')
 		{
+			call_integration_hook('integrate_session_handlers');
+			// @todo move these to a plugin.
 			if (function_exists('mmcache_set_session_handlers'))
 				mmcache_set_session_handlers();
 			elseif (function_exists('eaccelerator_set_session_handlers'))
@@ -84,10 +86,6 @@ function loadSession()
 			header('Cache-Control: private');
 	}
 
-	// While PHP 4.1.x should use $_SESSION, it seems to need this to do it right.
-	if (version_compare(PHP_VERSION, '4.2.0', '<'))
-		$HTTP_SESSION_VARS['php_412_bugfix'] = true;
-
 	// Set the randomly generated code.
 	if (!isset($_SESSION['session_var']))
 	{

+ 0 - 9
Sources/Subs-Auth.php

@@ -99,15 +99,6 @@ function setLoginCookie($cookie_length, $id, $password = '')
 		session_regenerate_id();
 		$_SESSION = $oldSessionData;
 
-		// Version 4.3.2 didn't store the cookie of the new session.
-		if (version_compare(PHP_VERSION, '4.3.2', '=='))
-		{
-			// Do not check $_COOKIE here, PHP only updates it at the next page load,
-			// therefore here it will always be unset for the session just created.
-			$sessionCookieLifetime = ini_get('session.cookie_lifetime');
-			smf_setcookie(session_name(), session_id(), time() + (empty($sessionCookieLifetime) ? $cookie_length : $sessionCookieLifetime), $cookie_url[1], $cookie_url[0]);
-		}
-
 		$_SESSION['login_' . $cookiename] = $data;
 	}
 }

+ 1 - 3
Sources/Subs-Graphics.php

@@ -584,9 +584,7 @@ function showCodeImage($code)
 {
 	global $settings, $user_info, $modSettings;
 
-	/*
-		Note: The higher the value of visual_verification_type the harder the verification is - from 0 as disabled through to 4 as "Very hard".
-	*/
+	// Note: The higher the value of visual_verification_type the harder the verification is - from 0 as disabled through to 4 as "Very hard".
 
 	// What type are we going to be doing?
 	$imageType = $modSettings['visual_verification_type'];

+ 1 - 1
Sources/Subs-Members.php

@@ -470,7 +470,7 @@ function registerMember(&$regOptions, $return_errors = false)
 		$reg_errors[] = array('lang', 'need_username');
 
 	// Spaces and other odd characters are evil...
-	$regOptions['username'] = preg_replace('~[\t\n\r\x0B\0' . ($context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}' : "\xC2\xA0") : '\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $regOptions['username']);
+	$regOptions['username'] = preg_replace('~[\t\n\r\x0B\0' . ($context['utf8'] ? '\x{A0}' : '\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $regOptions['username']);
 
 	// Don't use too long a name.
 	if ($smcFunc['strlen']($regOptions['username']) > 25)

+ 3 - 0
Sources/Subs-OpenID.php

@@ -81,6 +81,7 @@ function smf_openID_validate($openid_uri, $return = false, $save_fields = array(
 
 /**
  * Revalidate a user using OpenID. Note that this function will not return when authentication is required.
+ * @return bool
  */
 function smf_openID_revalidate()
 {
@@ -146,6 +147,7 @@ function smf_openID_getAssociation($server, $handle = null, $no_delete = false)
 /**
  * @todo Enter description here ...
  * @param string $server
+ * @return array
  */
 function smf_openID_makeAssociation($server)
 {
@@ -400,6 +402,7 @@ function smf_openID_canonize($uri)
 /**
  * @todo Enter description here ...
  * @param string $uri
+ * @return array
  */
 function smf_openid_member_exists($url)
 {

+ 2 - 2
Sources/Subs-Post.php

@@ -85,7 +85,7 @@ function preparsecode(&$message, $previewing = false)
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
 
 	// The regular expression non breaking space has many versions.
-	$non_breaking_space = $context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}' : "\xC2\xA0") : '\xA0';
+	$non_breaking_space = $context['utf8'] ? '\x{A0}' : '\xA0';
 
 	// Only mess with stuff outside [code] tags.
 	for ($i = 0, $n = count($parts); $i < $n; $i++)
@@ -1220,7 +1220,7 @@ function mimespecialchars($string, $with_charset = true, $hotmail_fix = false, $
 				return "";');
 
 		// Convert all 'special' characters to HTML entities.
-		return array($charset, preg_replace('~([\x80-' . ($context['server']['complex_preg_chars'] ? '\x{10FFFF}' : "\xF7\xBF\xBF\xBF") . '])~eu', '$entityConvert(\'\1\')', $string), '7bit');
+		return array($charset, preg_replace('~([\x80-' . '\x{10FFFF}' . '])~eu', '$entityConvert(\'\1\')', $string), '7bit');
 	}
 
 	// We don't need to mess with the subject line if no special characters were in it..

+ 7 - 19
Sources/Subs.php

@@ -214,6 +214,7 @@ function updateStats($type, $parameter1 = null, $parameter2 = null)
 
 		// Set all membergroups from most posts to least posts.
 		$conditions = '';
+		$lastMin = 0;
 		foreach ($postgroups as $id => $min_posts)
 		{
 			$conditions .= '
@@ -720,9 +721,9 @@ function timeformat($log_time, $show_today = true, $offset_type = false)
  */
 function un_htmlspecialchars($string)
 {
-	static $translation = '';
+	static $translation = array();
 
-	if (!isset($translation))
+	if (empty($translation))
 		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array('&#039;' => '\'', '&nbsp;' => ' ');
 
 	return strtr($string, $translation);
@@ -1645,7 +1646,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra
 	$message = strtr($message, array("\n" => '<br />'));
 
 	// The non-breaking-space looks a bit different each time.
-	$non_breaking_space = $context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}' : "\xC2\xA0") : '\xA0';
+	$non_breaking_space = $context['utf8'] ? '\x{A0}' : '\xA0';
 
 	// This saves time by doing our break long words checks here.
 	if (!empty($modSettings['fixLongWords']) && $modSettings['fixLongWords'] > 5)
@@ -2446,7 +2447,7 @@ function parsesmileys(&$message)
 		}
 
 		// The non-breaking-space is a complex thing...
-		$non_breaking_space = $context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}' : "\xC2\xA0") : '\xA0';
+		$non_breaking_space = $context['utf8'] ? '\x{A0}' : '\xA0';
 
 		// This smiley regex makes sure it doesn't parse smileys within code tags (so [url=mailto:[email protected]] doesn't parse the :D smiley)
 		$smileyPregReplacements = array();
@@ -2489,16 +2490,7 @@ function highlight_php_code($code)
 
 	$oldlevel = error_reporting(0);
 
-	// It's easier in 4.2.x+.
-	if (version_compare(PHP_VERSION, '4.2.0', '<'))
-	{
-		ob_start();
-		@highlight_string($code);
-		$buffer = str_replace(array("\n", "\r"), '', ob_get_contents());
-		ob_end_clean();
-	}
-	else
-		$buffer = str_replace(array("\n", "\r"), '', @highlight_string($code, true));
+	$buffer = str_replace(array("\n", "\r"), '', @highlight_string($code, true));
 
 	error_reporting($oldlevel);
 
@@ -3201,10 +3193,6 @@ function host_from_ip($ip)
 		return $host;
 	$t = microtime();
 
-	// If we can't access nslookup/host, PHP 4.1.x might just crash.
-	if (version_compare(PHP_VERSION, '4.2.0', '<'))
-		$host = false;
-
 	// Try the Linux host command, perhaps?
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
 	{
@@ -3256,7 +3244,7 @@ function text2words($text, $max_chars = 20, $encrypt = false)
 	global $smcFunc, $context;
 
 	// Step 1: Remove entities/things we don't consider words:
-	$words = preg_replace('~(?:[\x0B\0' . ($context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}' : "\xC2\xA0") : '\xA0') . '\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~' . ($context['utf8'] ? 'u' : ''), ' ', strtr($text, array('<br />' => ' ')));
+	$words = preg_replace('~(?:[\x0B\0' . ($context['utf8'] ? '\x{A0}' : '\xA0') . '\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~' . ($context['utf8'] ? 'u' : ''), ' ', strtr($text, array('<br />' => ' ')));
 
 	// Step 2: Entities we left to letters, where applicable, lowercase.
 	$words = un_htmlspecialchars($smcFunc['strtolower']($words));