Merge branch 'ticket/igorw/9574' into develop

* ticket/igorw/9574:
  [ticket/9574] Add pcre_utf8_support() function
  [ticket/9574] Remove conditional PHP<5.2 code
  [ticket/9574] Drop fallback implementations
This commit is contained in:
Andreas Fischer 2010-12-28 22:40:09 +01:00
commit 6e51e52f0c
10 changed files with 47 additions and 242 deletions

View file

@ -317,16 +317,7 @@ class acp_bbcodes
$bbcode_tpl = trim($bbcode_tpl);
$utf8 = strpos($bbcode_match, 'INTTEXT') !== false;
// make sure we have utf8 support
$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)
{
$utf8_pcre_properties = true;
}
}
$utf8_pcre_properties = pcre_utf8_support();
$fp_match = preg_quote($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)
{
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);
}
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];
}
}
$col_types = sqlite_fetch_column_types($db->db_connect_id, $table_name);
$sql = "SELECT *
FROM $table_name";

View file

@ -82,7 +82,7 @@ class cache extends acm
$result = $db->sql_query($sql);
$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 = pcre_utf8_support();
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.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);
}
else
{
$this->db_connect_id = ($this->persistency) ? @mssql_pconnect($this->server, $this->user, $sqlpassword) : @mssql_connect($this->server, $this->user, $sqlpassword);
}
$this->db_connect_id = ($this->persistency) ? @mssql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mssql_connect($this->server, $this->user, $sqlpassword, $new_link);
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 .= $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);
return $output;
@ -480,24 +480,12 @@ function _hash_crypt_private($password, $setting, &$itoa64)
* consequently in lower iteration counts and hashes that are
* quicker to crack (by non-PHP code).
*/
if (PHP_VERSION >= 5)
$hash = md5($salt . $password, true);
do
{
$hash = md5($salt . $password, true);
do
{
$hash = md5($hash . $password, true);
}
while (--$count);
}
else
{
$hash = pack('H*', md5($salt . $password));
do
{
$hash = pack('H*', md5($hash . $password));
}
while (--$count);
$hash = md5($hash . $password, true);
}
while (--$count);
$output = substr($setting, 0, 12);
$output .= _hash_encode64($hash, 16, $itoa64);
@ -752,95 +740,6 @@ function phpbb_is_writable($file)
}
}
// Compatibility functions
if (!function_exists('array_combine'))
{
/**
* A wrapper for the PHP5 function array_combine()
* @param array $keys contains keys for the resulting array
* @param array $values contains values for the resulting array
*
* @return Returns an array by using the values from the keys array as keys and the
* values from the values array as the corresponding values. Returns false if the
* number of elements for each array isn't equal or if the arrays are empty.
*/
function array_combine($keys, $values)
{
$keys = array_values($keys);
$values = array_values($values);
$n = sizeof($keys);
$m = sizeof($values);
if (!$n || !$m || ($n != $m))
{
return false;
}
$combined = array();
for ($i = 0; $i < $n; $i++)
{
$combined[$keys[$i]] = $values[$i];
}
return $combined;
}
}
if (!function_exists('str_split'))
{
/**
* A wrapper for the PHP5 function str_split()
* @param array $string contains the string to be converted
* @param array $split_length contains the length of each chunk
*
* @return Converts a string to an array. If the optional split_length parameter is specified,
* the returned array will be broken down into chunks with each being split_length in length,
* otherwise each chunk will be one character in length. FALSE is returned if split_length is
* less than 1. If the split_length length exceeds the length of string, the entire string is
* returned as the first (and only) array element.
*/
function str_split($string, $split_length = 1)
{
if ($split_length < 1)
{
return false;
}
else if ($split_length >= strlen($string))
{
return array($string);
}
else
{
preg_match_all('#.{1,' . $split_length . '}#s', $string, $matches);
return $matches[0];
}
}
}
if (!function_exists('stripos'))
{
/**
* A wrapper for the PHP5 function stripos
* Find position of first occurrence of a case-insensitive string
*
* @param string $haystack is the string to search in
* @param string $needle is the string to search for
*
* @return mixed Returns the numeric position of the first occurrence of needle in the haystack string. Unlike strpos(), stripos() is case-insensitive.
* Note that the needle may be a string of one or more characters.
* If needle is not found, stripos() will return boolean FALSE.
*/
function stripos($haystack, $needle)
{
if (preg_match('#' . preg_quote($needle, '#') . '#i', $haystack, $m))
{
return strpos($haystack, $m[0]);
}
return false;
}
}
/**
* Checks if a path ($path) is absolute or relative
*
@ -1046,18 +945,6 @@ else
}
}
if (!function_exists('htmlspecialchars_decode'))
{
/**
* A wrapper for htmlspecialchars_decode
* @ignore
*/
function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT)
{
return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
}
}
// functions used for building option fields
/**
@ -4620,3 +4507,19 @@ function phpbb_user_session_handler()
return;
}
/**
* Check if PCRE has UTF-8 support
* PHP may not be linked with the bundled PCRE lib and instead with an older version
*
* @return bool Returns true if PCRE (the regular expressions library) supports UTF-8 encoding
*/
function pcre_utf8_support()
{
static $utf8_pcre_properties = null;
if (is_null($utf8_pcre_properties))
{
$utf8_pcre_properties = (@preg_match('/\p{L}/u', 'a') !== false);
}
return $utf8_pcre_properties;
}

View file

@ -1490,7 +1490,7 @@ function validate_username($username, $allowed_username = false)
$mbstring = $pcre = false;
// 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 (pcre_utf8_support())
{
$pcre = true;
}
@ -1626,7 +1626,7 @@ function validate_password($password)
$pcre = $mbstring = false;
// 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 (pcre_utf8_support())
{
$upp = '\p{Lu}';
$low = '\p{Ll}';

View file

@ -42,13 +42,10 @@ class fulltext_mysql extends search_backend
$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
if (pcre_utf8_support())
{
// 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)
{
$this->pcre_properties = true;
}
$this->pcre_properties = true;
}
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']),
'sender' => $row['username'],
// 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] : '',
'message' => $message_row['message_text']
);

View file

@ -109,70 +109,26 @@ if (extension_loaded('mbstring'))
/**
* UTF-8 aware alternative to strrpos
* 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
* @ignore
*/
function utf8_strrpos($str, $needle, $offset = null)
{
/**
* UTF-8 aware alternative to strrpos
* @ignore
*/
function utf8_strrpos($str, $needle, $offset = null)
// Emulate behaviour of strrpos rather than raising warning
if (empty($str))
{
// Emulate behaviour of strrpos rather than raising warning
if (empty($str))
{
return false;
}
if (is_null($offset))
{
return mb_strrpos($str, $needle);
}
else
{
return mb_strrpos($str, $needle, $offset);
}
return false;
}
}
else
{
/**
* UTF-8 aware alternative to strrpos
* @ignore
*/
function utf8_strrpos($str, $needle, $offset = null)
if (is_null($offset))
{
// 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;
}
return mb_strrpos($str, $needle);
}
else
{
return mb_strrpos($str, $needle, $offset);
}
}

View file

@ -456,7 +456,7 @@ function phpbb_get_birthday($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';
}