Advertisement:

Author Topic: How to fix the preg_replace () error?  (Read 3765 times)

Offline Almasani

  • Newbie
  • *
  • Posts: 6
How to fix the preg_replace () error?
« on: August 16, 2020, 03:13:45 AM »
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)

Code: [Select]
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') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($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') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($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') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($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('&' => '&amp;'))  . '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 . ']|&nbsp;)+|([ \t\n\r\x0B\x00' . $space_chars . ']|&nbsp;)+$~' . ($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__);
}

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 73,189
Re: How to fix the preg_replace () error?
« Reply #1 on: August 16, 2020, 05:01:48 AM »
No good deed goes unpunished
All helpful urges should be circumvented

Offline Almasani

  • Newbie
  • *
  • Posts: 6
Re: How to fix the preg_replace () error?
« Reply #2 on: October 23, 2020, 03:22:14 PM »
Thank's sir...

Offline Almasani

  • Newbie
  • *
  • Posts: 6
Re: How to fix the preg_replace () error?
« Reply #3 on: October 23, 2020, 07:42:58 PM »
Basically, upgrade to 2.0.

Sir, can you help me how to limit signature by rank or post?
If it's a member who is still lacking in posts, they can't use the signature.
SMF Version 2.0
Thank's

Offline shadav

  • Full Member
  • ***
  • Posts: 696
  • Gender: Female
    • Ask The Muslims: A Place To Ask Honest Questions and Receive Respectful Answers
Re: How to fix the preg_replace () error?
« Reply #4 on: October 23, 2020, 09:32:32 PM »
I'm assuming that you've updated to 2.0.17....

To set member group permissions for signatures: https://custom.simplemachines.org/mods/?mod=4014

To give some member groups permission to allow images, smileys, links and to also give more space and images/smileys to specific groups : https://custom.simplemachines.org/mods/?mod=4147


Offline Almasani

  • Newbie
  • *
  • Posts: 6
Re: How to fix the preg_replace () error?
« Reply #5 on: November 16, 2020, 01:08:29 PM »
Thank you for the help. Yes, I am using version 2.0.17 with a core theme.




Is it possible to set the count of characters in the signature based on rank.
For example:
Rank Jr.Member = 100 characters
Rank Full Member = 500 characters.
etc.



If we set the Features and Options => Signature Settings automatically all participants who are allowed to use the signature will have the same chance with the same count of characters.

« Last Edit: November 16, 2020, 02:12:36 PM by Almasani »

Offline shadav

  • Full Member
  • ***
  • Posts: 696
  • Gender: Female
    • Ask The Muslims: A Place To Ask Honest Questions and Receive Respectful Answers
Re: How to fix the preg_replace () error?
« Reply #6 on: November 17, 2020, 10:32:59 AM »
no not really but the second mod that I had posted allows for specific member groups to have 2x as much as other groups
I use it as a bonus for donators and staff members...so all other groups have let's say I have it set to
Maximum allowed characters 400
Maximum amount of lines 2
Maximum font size allowed in signatures 12
Allow smileys in signatures checked
Maximum smiley count 5
Maximum image count 3
Maximum width of signature images (pixels) 200
Maximum height of signature images (pixels) 100

with the mod https://custom.simplemachines.org/mods/?mod=4147
all member groups will have the above except for ones that you set their permissions to Allow more characters, images, smileys and lines and larger fonts in signature

these groups that you set that permission to will have twice as much as what is listed above, ie
Maximum allowed characters 800
Maximum amount of lines 4
Maximum font size allowed in signatures 24
Allow smileys in signatures checked
Maximum smiley count 10
Maximum image count 6
Maximum width of signature images (pixels) 400
Maximum height of signature images (pixels) 200

Offline Almasani

  • Newbie
  • *
  • Posts: 6
Re: How to fix the preg_replace () error?
« Reply #7 on: November 17, 2020, 03:44:30 PM »
Okey, thank's sir  :-*