Skip to content

Commit cbc6a81

Browse files
committed
Adding support of php 8.0
1 parent c33d402 commit cbc6a81

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

src-php/EMT.Lib.php

+16-7
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ public static function remove_html_tags($text, $allowableTag = null)
197197
public static function safe_tag_chars($text, $way)
198198
{
199199
if ($way)
200-
$text = preg_replace_callback('/(\<\/?)([^<>]+?)(\>)/s', create_function('$m','return (strlen($m[1])==1 && substr(trim($m[2]), 0, 1) == \'-\' && substr(trim($m[2]), 1, 1) != \'-\')? $m[0] : $m[1].( substr(trim($m[2]), 0, 1) === "a" ? "%%___" : "" ) . EMT_Lib::encrypt_tag(trim($m[2])) . $m[3];'), $text);
200+
$text = preg_replace_callback('/(\<\/?)([^<>]+?)(\>)/s', EMT_Lib::create_function('$m','return (strlen($m[1])==1 && substr(trim($m[2]), 0, 1) == \'-\' && substr(trim($m[2]), 1, 1) != \'-\')? $m[0] : $m[1].( substr(trim($m[2]), 0, 1) === "a" ? "%%___" : "" ) . EMT_Lib::encrypt_tag(trim($m[2])) . $m[3];'), $text);
201201
else
202-
$text = preg_replace_callback('/(\<\/?)([^<>]+?)(\>)/s', create_function('$m','return (strlen($m[1])==1 && substr(trim($m[2]), 0, 1) == \'-\' && substr(trim($m[2]), 1, 1) != \'-\')? $m[0] : $m[1].( substr(trim($m[2]), 0, 3) === "%%___" ? EMT_Lib::decrypt_tag(substr(trim($m[2]), 4)) : EMT_Lib::decrypt_tag(trim($m[2])) ) . $m[3];'), $text);
202+
$text = preg_replace_callback('/(\<\/?)([^<>]+?)(\>)/s', EMT_Lib::create_function('$m','return (strlen($m[1])==1 && substr(trim($m[2]), 0, 1) == \'-\' && substr(trim($m[2]), 1, 1) != \'-\')? $m[0] : $m[1].( substr(trim($m[2]), 0, 3) === "%%___" ? EMT_Lib::decrypt_tag(substr(trim($m[2]), 4)) : EMT_Lib::decrypt_tag(trim($m[2])) ) . $m[3];'), $text);
203203
return $text;
204204
}
205205

@@ -212,7 +212,7 @@ public static function safe_tag_chars($text, $way)
212212
*/
213213
public static function decode_internal_blocks($text)
214214
{
215-
$text = preg_replace_callback('/'.EMT_Lib::INTERNAL_BLOCK_OPEN.'([a-zA-Z0-9\/=]+?)'.EMT_Lib::INTERNAL_BLOCK_CLOSE.'/s', create_function('$m','return EMT_Lib::decrypt_tag($m[1]);'), $text);
215+
$text = preg_replace_callback('/'.EMT_Lib::INTERNAL_BLOCK_OPEN.'([a-zA-Z0-9\/=]+?)'.EMT_Lib::INTERNAL_BLOCK_CLOSE.'/s', EMT_Lib::create_function('$m','return EMT_Lib::decrypt_tag($m[1]);'), $text);
216216
return $text;
217217
}
218218

@@ -341,6 +341,15 @@ public static function strpos_ex(&$haystack, $needle, $offset = null)
341341
return strpos($haystack, $needle, $offset);
342342
}
343343

344+
public static function create_function($args, $code) {
345+
if (version_compare(PHP_VERSION, '7.0.0') < 0) {
346+
return create_function($args, $code);
347+
}
348+
$closure = false;
349+
eval('$closure = function('.$args.') { '.$code.' }; ');
350+
return $closure;
351+
}
352+
344353
public static function _process_selector_pattern(&$pattern)
345354
{
346355
if($pattern===false) return;
@@ -649,13 +658,13 @@ public static function html_char_entity_to_unicode($entity)
649658
public static function convert_html_entities_to_unicode(&$text)
650659
{
651660
$text = preg_replace_callback("/\&#([0-9]+)\;/",
652-
create_function('$m', 'return EMT_Lib::_getUnicodeChar(intval($m[1]));')
661+
EMT_Lib::create_function('$m', 'return EMT_Lib::_getUnicodeChar(intval($m[1]));')
653662
, $text);
654663
$text = preg_replace_callback("/\&#x([0-9A-F]+)\;/",
655-
create_function('$m', 'return EMT_Lib::_getUnicodeChar(hexdec($m[1]));')
664+
EMT_Lib::create_function('$m', 'return EMT_Lib::_getUnicodeChar(hexdec($m[1]));')
656665
, $text);
657666
$text = preg_replace_callback("/\&([a-zA-Z0-9]+)\;/",
658-
create_function('$m', '$r = EMT_Lib::html_char_entity_to_unicode($m[1]); return $r ? $r : $m[0];')
667+
EMT_Lib::create_function('$m', '$r = EMT_Lib::html_char_entity_to_unicode($m[1]); return $r ? $r : $m[0];')
659668
, $text);
660669
}
661670

@@ -701,7 +710,7 @@ public static function url_regex() {
701710
URLREGEX;
702711
*/
703712
return <<<URLREGEX
704-
#(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))#iS
713+
#(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))#iSu
705714
URLREGEX;
706715

707716
/*

src-php/EMT.Tret.Quote.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected function build_sub_quotations()
130130
if($__ax)
131131
{
132132
$k = preg_replace_callback("/(^|[^0-9])([0-9]+)\&raquo\;/ui",
133-
create_function('$m','global $__ax,$__ay; $__ay++; if($__ay==$__ax){ return $m[1].$m[2]."&Prime;";} return $m[0];'),
133+
EMT_Lib::create_function('$m','global $__ax,$__ay; $__ay++; if($__ay==$__ax){ return $m[1].$m[2]."&Prime;";} return $m[0];'),
134134
$k);
135135
$amount = 1;
136136
}

src-php/EMT.Tret.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private function apply_rule($rule)
208208
}
209209
$this->error('Функция '.$rule['function'].' из правила '.$rule['id']. " не найдена");
210210
} else {
211-
$this->_text = preg_replace_callback($rule['pattern'], create_function('$m', $rule['function']), $this->_text);
211+
$this->_text = preg_replace_callback($rule['pattern'], EMT_Lib::create_function('$m', $rule['function']), $this->_text);
212212
$this->log('Замена с использованием preg_replace_callback с инлайн функцией из правила '.$rule['id']);
213213
return;
214214
}

src-php/EMT.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function safe_blocks($text, $way, $show = true)
253253
$safeblocks = true === $way ? $this->_safe_blocks : array_reverse($this->_safe_blocks);
254254
foreach ($safeblocks as $block)
255255
{
256-
$text = preg_replace_callback("/({$block['open']})(.+?)({$block['close']})/s", create_function('$m','return $m[1].'.$safeType . '.$m[3];') , $text);
256+
$text = preg_replace_callback("/({$block['open']})(.+?)({$block['close']})/s", EMT_Lib::create_function('$m','return $m[1].'.$safeType . '.$m[3];') , $text);
257257
}
258258
}
259259

0 commit comments

Comments
 (0)