[ticket/9574] Remove conditional PHP<5.2 code

There is a large amount of conditional code for PHP < 5.2 that can be
removed with phpBB 3.1.

PHPBB3-9574
This commit is contained in:
Igor Wiedler 2010-06-25 13:31:31 +02:00
parent 1e59666ee3
commit eda9fbbb63
10 changed files with 33 additions and 137 deletions

View file

@ -318,15 +318,12 @@ class acp_bbcodes
$utf8 = strpos($bbcode_match, 'INTTEXT') !== false; $utf8 = strpos($bbcode_match, 'INTTEXT') !== false;
// make sure we have utf8 support // make sure we have utf8 support
// PHP may not be linked with the bundled PCRE lib and instead with an older version
$utf8_pcre_properties = false; $utf8_pcre_properties = false;
if (version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>=')))
{
// While this is the proper range of PHP versions, PHP may not be linked with the bundled PCRE lib and instead with an older version
if (@preg_match('/\p{L}/u', 'a') !== false) if (@preg_match('/\p{L}/u', 'a') !== false)
{ {
$utf8_pcre_properties = true; $utf8_pcre_properties = true;
} }
}
$fp_match = preg_quote($bbcode_match, '!'); $fp_match = preg_quote($bbcode_match, '!');
$fp_replace = preg_replace('#^\[(.*?)\]#', '[$1:$uid]', $bbcode_match); $fp_replace = preg_replace('#^\[(.*?)\]#', '[$1:$uid]', $bbcode_match);

View file

@ -1007,43 +1007,8 @@ class sqlite_extractor extends base_extractor
function write_data($table_name) function write_data($table_name)
{ {
global $db; global $db;
static $proper;
if (is_null($proper))
{
$proper = version_compare(PHP_VERSION, '5.1.3', '>=');
}
if ($proper)
{
$col_types = sqlite_fetch_column_types($db->db_connect_id, $table_name); $col_types = sqlite_fetch_column_types($db->db_connect_id, $table_name);
}
else
{
$sql = "SELECT sql
FROM sqlite_master
WHERE type = 'table'
AND name = '" . $table_name . "'";
$table_data = sqlite_single_query($db->db_connect_id, $sql);
$table_data = preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', '', $table_data);
$table_data = trim($table_data);
preg_match('#\((.*)\)#s', $table_data, $matches);
$table_cols = explode(',', trim($matches[1]));
foreach ($table_cols as $declaration)
{
$entities = preg_split('#\s+#', trim($declaration));
$column_name = preg_replace('/"?([^"]+)"?/', '\1', $entities[0]);
// Hit a primary key, those are not what we need :D
if (empty($entities[1]) || (strtolower($entities[0]) === 'primary' && strtolower($entities[1]) === 'key'))
{
continue;
}
$col_types[$column_name] = $entities[1];
}
}
$sql = "SELECT * $sql = "SELECT *
FROM $table_name"; FROM $table_name";

View file

@ -82,7 +82,7 @@ class cache extends acm
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$censors = array(); $censors = array();
$unicode = ((version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) && @preg_match('/\p{L}/u', 'a') !== false) ? true : false; $unicode = (@preg_match('/\p{L}/u', 'a') !== false) ? true : false;
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {

View file

@ -41,14 +41,7 @@ class dbal_mssql extends dbal
@ini_set('mssql.textlimit', 2147483647); @ini_set('mssql.textlimit', 2147483647);
@ini_set('mssql.textsize', 2147483647); @ini_set('mssql.textsize', 2147483647);
if (version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.1', '>=')))
{
$this->db_connect_id = ($this->persistency) ? @mssql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mssql_connect($this->server, $this->user, $sqlpassword, $new_link); $this->db_connect_id = ($this->persistency) ? @mssql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mssql_connect($this->server, $this->user, $sqlpassword, $new_link);
}
else
{
$this->db_connect_id = ($this->persistency) ? @mssql_pconnect($this->server, $this->user, $sqlpassword) : @mssql_connect($this->server, $this->user, $sqlpassword);
}
if ($this->db_connect_id && $this->dbname != '') if ($this->db_connect_id && $this->dbname != '')
{ {

View file

@ -394,7 +394,7 @@ function _hash_gensalt_private($input, &$itoa64, $iteration_count_log2 = 6)
} }
$output = '$H$'; $output = '$H$';
$output .= $itoa64[min($iteration_count_log2 + ((PHP_VERSION >= 5) ? 5 : 3), 30)]; $output .= $itoa64[min($iteration_count_log2 + 5, 30)];
$output .= _hash_encode64($input, 6, $itoa64); $output .= _hash_encode64($input, 6, $itoa64);
return $output; return $output;
@ -480,24 +480,12 @@ function _hash_crypt_private($password, $setting, &$itoa64)
* consequently in lower iteration counts and hashes that are * consequently in lower iteration counts and hashes that are
* quicker to crack (by non-PHP code). * quicker to crack (by non-PHP code).
*/ */
if (PHP_VERSION >= 5)
{
$hash = md5($salt . $password, true); $hash = md5($salt . $password, true);
do do
{ {
$hash = md5($hash . $password, true); $hash = md5($hash . $password, true);
} }
while (--$count); while (--$count);
}
else
{
$hash = pack('H*', md5($salt . $password));
do
{
$hash = pack('H*', md5($hash . $password));
}
while (--$count);
}
$output = substr($setting, 0, 12); $output = substr($setting, 0, 12);
$output .= _hash_encode64($hash, 16, $itoa64); $output .= _hash_encode64($hash, 16, $itoa64);

View file

@ -1490,7 +1490,7 @@ function validate_username($username, $allowed_username = false)
$mbstring = $pcre = false; $mbstring = $pcre = false;
// generic UTF-8 character types supported? // generic UTF-8 character types supported?
if ((version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) && @preg_match('/\p{L}/u', 'a') !== false) if (@preg_match('/\p{L}/u', 'a') !== false)
{ {
$pcre = true; $pcre = true;
} }
@ -1626,7 +1626,7 @@ function validate_password($password)
$pcre = $mbstring = false; $pcre = $mbstring = false;
// generic UTF-8 character types supported? // generic UTF-8 character types supported?
if ((version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) && @preg_match('/\p{L}/u', 'a') !== false) if (@preg_match('/\p{L}/u', 'a') !== false)
{ {
$upp = '\p{Lu}'; $upp = '\p{Lu}';
$low = '\p{Ll}'; $low = '\p{Ll}';

View file

@ -42,14 +42,11 @@ class fulltext_mysql extends search_backend
$this->word_length = array('min' => $config['fulltext_mysql_min_word_len'], 'max' => $config['fulltext_mysql_max_word_len']); $this->word_length = array('min' => $config['fulltext_mysql_min_word_len'], 'max' => $config['fulltext_mysql_max_word_len']);
if (version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) // PHP may not be linked with the bundled PCRE lib and instead with an older version
{
// While this is the proper range of PHP versions, PHP may not be linked with the bundled PCRE lib and instead with an older version
if (@preg_match('/\p{L}/u', 'a') !== false) if (@preg_match('/\p{L}/u', 'a') !== false)
{ {
$this->pcre_properties = true; $this->pcre_properties = true;
} }
}
if (function_exists('mb_ereg')) if (function_exists('mb_ereg'))
{ {

View file

@ -282,7 +282,7 @@ function view_folder($id, $mode, $folder_id, $folder)
'subject' => censor_text($row['message_subject']), 'subject' => censor_text($row['message_subject']),
'sender' => $row['username'], 'sender' => $row['username'],
// ISO 8601 date. For PHP4 we are able to hardcode the timezone because $user->format_date() does not set it. // ISO 8601 date. For PHP4 we are able to hardcode the timezone because $user->format_date() does not set it.
'date' => $user->format_date($row['message_time'], (PHP_VERSION >= 5) ? 'c' : "Y-m-d\TH:i:s+00:00", true), 'date' => $user->format_date($row['message_time'], 'c', true),
'to' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? $address[$message_id] : '', 'to' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? $address[$message_id] : '',
'message' => $message_row['message_text'] 'message' => $message_row['message_text']
); );

View file

@ -109,12 +109,7 @@ if (extension_loaded('mbstring'))
/** /**
* UTF-8 aware alternative to strrpos * UTF-8 aware alternative to strrpos
* Find position of last occurrence of a char in a string * Find position of last occurrence of a char in a string
*
* Notes:
* - offset for mb_strrpos was added in 5.2.0, we emulate if it is lower
*/ */
if (version_compare(PHP_VERSION, '5.2.0', '>='))
{
/** /**
* UTF-8 aware alternative to strrpos * UTF-8 aware alternative to strrpos
* @ignore * @ignore
@ -136,45 +131,6 @@ if (extension_loaded('mbstring'))
return mb_strrpos($str, $needle, $offset); return mb_strrpos($str, $needle, $offset);
} }
} }
}
else
{
/**
* UTF-8 aware alternative to strrpos
* @ignore
*/
function utf8_strrpos($str, $needle, $offset = null)
{
// offset for mb_strrpos was added in 5.2.0
if (is_null($offset))
{
// Emulate behaviour of strrpos rather than raising warning
if (empty($str))
{
return false;
}
return mb_strrpos($str, $needle);
}
else
{
if (!is_int($offset))
{
trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_ERROR);
return false;
}
$str = mb_substr($str, $offset);
if (false !== ($pos = mb_strrpos($str, $needle)))
{
return $pos + $offset;
}
return false;
}
}
}
/** /**
* UTF-8 aware alternative to strpos * UTF-8 aware alternative to strpos

View file

@ -456,7 +456,7 @@ function phpbb_get_birthday($birthday = '')
{ {
$birthday = (int) $birthday; $birthday = (int) $birthday;
if (!$birthday || $birthday == 999999 || ((version_compare(PHP_VERSION, '5.1.0') < 0) && $birthday < 0)) if (!$birthday || $birthday == 999999)
{ {
return ' 0- 0- 0'; return ' 0- 0- 0';
} }