SMF 1.1.21
How to fix the preg_replace () error? preg_replace(): The / e modifier is deprecated, use preg_replace_callback instead in ... \ Sources \ Load.php (225)
global $modSettings, $db_prefix, $boarddir, $func, $txt, $db_character_set;
global $mysql_set_mode, $context;
// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
if (isset($mysql_set_mode) && $mysql_set_mode === true)
db_query("SET sql_mode='', AUTOCOMMIT=1", false, false);
// Most database systems have not set UTF-8 as their default input charset.
if (isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
db_query("
SET NAMES $db_character_set", __FILE__, __LINE__);
// Try to load it from the cache first; it'll never get cached if the setting is off.
if (($modSettings = cache_get_data('modSettings', 90)) == null)
{
$request = db_query("
SELECT variable, value
FROM {$db_prefix}settings", false, false);
$modSettings = array();
if (!$request)
db_fatal_error();
while ($row = mysql_fetch_row($request))
$modSettings[$row[0]] = $row[1];
mysql_free_result($request);
// Do a few things to protect against missing settings or settings with invalid values...
if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
$modSettings['defaultMaxTopics'] = 20;
if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
$modSettings['defaultMaxMessages'] = 15;
if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
$modSettings['defaultMaxMembers'] = 30;
if (!empty($modSettings['cache_enable']))
cache_put_data('modSettings', $modSettings, 90);
}
// 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') != -1);
// 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\', \'$func[\\\'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') != -1 ? '\x{A0}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : pack('C*', 0xC2, 0xA0, 0xE2, 0x80, 0x80) . '-' . pack('C*', 0xE2, 0x80, 0x8F, 0xE2, 0x80, 0x9F, 0xE2, 0x80, 0xAF, 0xE2, 0x80, 0x9F, 0xE3, 0x80, 0x80, 0xEF, 0xBB, 0xBF)) : '\xA0';
$func = array(
'entity_fix' => create_function('$string', '
$num = substr($string, 0, 1) === \'x\' ? hexdec(substr($string, 1)) : (int) $string;
return $num < 0x20 || $num === 0x202E || $num === 0x202D || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) ? \'\' : \'&#\' . $num . \';\';'),
'substr' => create_function('$string, $start, $length = null', '
global $func;
$ent_arr = preg_split(\'~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '\', ' . implode('$string', $ent_check) . ', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
return $length === null ? implode(\'\', array_slice($ent_arr, $start)) : implode(\'\', array_slice($ent_arr, $start, $length));'),
'strlen' => create_function('$string', '
global $func;
return strlen(preg_replace(\'~' . $ent_list . ($utf8 ? '|.~u' : '~') . '\', \'_\', ' . implode('$string', $ent_check) . '));'),
'strpos' => create_function('$haystack, $needle, $offset = 0', '
global $func;
$haystack_arr = preg_split(\'~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '\', ' . implode('$haystack', $ent_check) . ', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$haystack_size = count($haystack_arr);
if (strlen($needle) === 1)
{
$result = array_search($needle, array_slice($haystack_arr, $offset));
return is_int($result) ? $result + $offset : false;
}
else
{
$needle_arr = preg_split(\'~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '\', ' . implode('$needle', $ent_check) . ', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$needle_size = count($needle_arr);
$result = array_search($needle_arr[0], array_slice($haystack_arr, $offset));
while (is_int($result))
{
$offset += $result;
if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
return $offset;
$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
}
return false;
}'),
'htmlspecialchars' => create_function('$string, $quote_style = ENT_COMPAT, $charset = \'ISO-8859-1\'', '
global $func;
return ' . strtr($ent_check[0], array('&' => '&')) . 'htmlspecialchars($string, $quote_style, ' . ($utf8 ? '\'UTF-8\'' : '$charset') . ')' . $ent_check[1] . ';'),
'htmltrim' => create_function('$string', '
global $func;
return preg_replace(\'~^([ \t\n\r\x0B\x00' . $space_chars . ']| )+|([ \t\n\r\x0B\x00' . $space_chars . ']| )+$~' . ($utf8 ? 'u' : '') . '\', \'\', ' . implode('$string', $ent_check) . ');'),
'truncate' => create_function('$string, $length', (empty($modSettings['disableEntityCheck']) ? '
global $func;
$string = ' . implode('$string', $ent_check) . ';' : '') . '
preg_match(\'~^(' . $ent_list . '|.){\' . $func[\'strlen\'](substr($string, 0, $length)) . \'}~'. ($utf8 ? 'u' : '') . '\', $string, $matches);
$string = $matches[0];
while (strlen($string) > $length)
$string = preg_replace(\'~(' . $ent_list . '|.)$~'. ($utf8 ? 'u' : '') . '\', \'\', $string);
return $string;'),
'strtolower' => $utf8 ? (function_exists('mb_strtolower') ? create_function('$string', '
return mb_strtolower($string, \'UTF-8\');') : create_function('$string', '
global $sourcedir;
require_once($sourcedir . \'/Subs-Charset.php\');
return utf8_strtolower($string);')) : 'strtolower',
'strtoupper' => $utf8 ? (function_exists('mb_strtoupper') ? create_function('$string', '
return mb_strtoupper($string, \'UTF-8\');') : create_function('$string', '
global $sourcedir;
require_once($sourcedir . \'/Subs-Charset.php\');
return utf8_strtoupper($string);')) : 'strtoupper',
'ucfirst' => $utf8 ? create_function('$string', '
global $func;
return $func[\'strtoupper\']($func[\'substr\']($string, 0, 1)) . $func[\'substr\']($string, 1);') : 'ucfirst',
'ucwords' => $utf8 ? (function_exists('mb_convert_case') ? create_function('$string', '
return mb_convert_case($string, MB_CASE_TITLE, \'UTF-8\');') : create_function('$string', '
global $func;
$words = preg_split(\'~([\s\r\n\t]+)~\', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($i = 0, $n = count($words); $i < $n; $i += 2)
$words[$i] = $func[\'ucfirst\']($words[$i]);
return implode(\'\', $words);')) : 'ucwords',
);
// Setting the timezone is a requirement for some functions in PHP >= 5.1.
if (isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
date_default_timezone_set($modSettings['default_timezone']);
// Check the load averages?
if (!empty($modSettings['loadavg_enable']))
{
if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
{
$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
$modSettings['load_average'] = (float) $matches[1];
elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
$modSettings['load_average'] = (float) $matches[1];
else
unset($modSettings['load_average']);
if (!empty($modSettings['load_average']))
cache_put_data('loadavg', $modSettings['load_average'], 90);
}
if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
db_fatal_error(true);
}
// Integration is cool.
if (defined('SMF_INTEGRATION_SETTINGS'))
$modSettings = unserialize(SMF_INTEGRATION_SETTINGS) + $modSettings;
if (isset($modSettings['integrate_pre_include']) && file_exists(strtr($modSettings['integrate_pre_include'], array('$boarddir' => $boarddir))))
require_once(strtr($modSettings['integrate_pre_include'], array('$boarddir' => $boarddir)));
if (isset($modSettings['integrate_pre_load']) && function_exists($modSettings['integrate_pre_load']))
call_user_func($modSettings['integrate_pre_load']);
// Is it time again to optimize the database?
if (empty($modSettings['autoOptDatabase']) || $modSettings['autoOptLastOpt'] + $modSettings['autoOptDatabase'] * 3600 * 24 >= time() || SMF == 'SSI')
return;
if (!empty($modSettings['load_average']) && !empty($modSettings['loadavg_auto_opt']) && $modSettings['load_average'] >= $modSettings['loadavg_auto_opt'])
return;
if (!empty($modSettings['autoOptMaxOnline']))
{
$request = db_query("
SELECT COUNT(*)
FROM {$db_prefix}log_online", __FILE__, __LINE__);
list ($dont_do_it) = mysql_fetch_row($request);
mysql_free_result($request);
if ($dont_do_it > $modSettings['autoOptMaxOnline'])
return;
}
// Handle if things are prefixed with a database name.
if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0)
{
$request = db_query("
SHOW TABLES
FROM `" . strtr($match[1], array('`' => '')) . "`
LIKE '" . str_replace('_', '\_', $match[2]) . "%'", __FILE__, __LINE__);
}
else
{
$request = db_query("
SHOW TABLES
LIKE '" . str_replace('_', '\_', $db_prefix) . "%'", __FILE__, __LINE__);
}
$tables = array();
while ($row = mysql_fetch_row($request))
$tables[] = $row[0];
mysql_free_result($request);
updateSettings(array('autoOptLastOpt' => time()));
// Don't bail if the user does.
ignore_user_abort(true);
// Do them one at a time for locking reasons...
foreach ($tables as $table)
db_query("
OPTIMIZE TABLE `$table`", __FILE__, __LINE__);
}