Skip to content

Commit

Permalink
Update to PHP 7.2. create_function -> function()
Browse files Browse the repository at this point in the history
  • Loading branch information
雨師 committed Dec 29, 2018
1 parent 52f9661 commit 9c7a27e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
8 changes: 7 additions & 1 deletion src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ public function safe_blocks($text, $way, $show = true)
$safeblocks = true === $way ? $this->_safe_blocks : array_reverse($this->_safe_blocks);
foreach ($safeblocks as $block)
{
$text = preg_replace_callback("/({$block['open']})(.+?)({$block['close']})/s", create_function('$m','return $m[1].'.$safeType . '.$m[3];') , $text);
$text = preg_replace_callback(
"/({$block['open']})(.+?)({$block['close']})/s",
function($m) {
return $m[1].'.$safeType . '.$m[3];
},
$text
);
}
}

Expand Down
45 changes: 34 additions & 11 deletions src/Lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,26 @@ public static function safe_tag_chars($text, $way)
if ($way) {
// $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 1) === "a" ? "%%___" : "" ) . Lib::encrypt_tag(trim($m[2])) . $m[3];'), $text);
// Взял изменение из оригинального репозитория. Свои правки закомментил выше
$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);
$text = preg_replace_callback(
'/(\<\/?)([^<>]+?)(\>)/s',
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" ? "%%___" : "") . Lib::encrypt_tag(trim($m[2])) . $m[3];
},
$text
);
}
else {
// $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 3) === "%%___" ? Lib::decrypt_tag(substr(trim($m[2]), 4)) : Lib::decrypt_tag(trim($m[2])) ) . $m[3];'), $text);
// Косяк со строками вида: [THD<0,4%, кабель 3 м, Jack 1/4"], из-за < и / неверно преобразует safe tags
//$text = preg_replace_callback('/(\<\/?)([a-zA-Z0-9=\%\_\/]+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 3) === "%%___" ? Lib::decrypt_tag(substr(trim($m[2]), 4)) : Lib::decrypt_tag(trim($m[2])) ) . $m[3];'), $text);
// Взял изменение из оригинального репозитория. Свои правки закомментил выше
$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);
$text = preg_replace_callback(
'/(\<\/?)([^<>]+?)(\>)/s',
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) === "%%___" ? Lib::decrypt_tag(substr(trim($m[2]), 4)) : Lib::decrypt_tag(trim($m[2]))) . $m[3];
},
$text
);
}
return $text;
}
Expand All @@ -223,7 +235,9 @@ public static function decode_internal_blocks($text)
{
$text = preg_replace_callback(
'/'.Lib::INTERNAL_BLOCK_OPEN.'([a-zA-Z0-9\/=]+?)'. Lib::INTERNAL_BLOCK_CLOSE.'/s',
create_function('$m','return EMT\Lib::decrypt_tag($m[1]);'),
function($m) {
return Lib::decrypt_tag($m[1]);
},
$text
);
return $text;
Expand Down Expand Up @@ -667,8 +681,10 @@ public static function html_char_entity_to_numeric_entity($entity)
public static function convert_html_entities_to_numeric_entity(&$text)
{
$text = preg_replace_callback("/\&([a-zA-Z0-9]+)\;/",
create_function('$m', '$r = EMT\Lib::html_char_entity_to_numeric_entity($m[1]); return $r ? $r : $m[0];')
, $text);
function($m) {
$r = Lib::html_char_entity_to_numeric_entity($m[1]); return $r ? $r : $m[0];
},
$text);
}

/**
Expand All @@ -691,14 +707,21 @@ public static function html_char_entity_to_unicode($entity)
public static function convert_html_entities_to_unicode(&$text)
{
$text = preg_replace_callback("/\&#([0-9]+)\;/",
create_function('$m', 'return EMT\Lib::_getUnicodeChar(intval($m[1]));')
, $text);
function($m) {
return Lib::_getUnicodeChar((int)$m[1]);
},
$text);
$text = preg_replace_callback("/\&#x([0-9A-F]+)\;/",
create_function('$m', 'return EMT\Lib::_getUnicodeChar(hexdec($m[1]));')
, $text);
function($m) {
return Lib::_getUnicodeChar(hexdec($m[1]));
},
$text);
$text = preg_replace_callback("/\&([a-zA-Z0-9]+)\;/",
create_function('$m', '$r = EMT\Lib::html_char_entity_to_unicode($m[1]); return $r ? $r : $m[0];')
, $text);
function($m) {
$r = Lib::html_char_entity_to_unicode($m[1]);
return $r ? $r : $m[0];
},
$text);
}

public static function rstrpos ($haystack, $needle, $offset = 0){
Expand Down
19 changes: 13 additions & 6 deletions src/Tret/Quote.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace EMT\Tret;

use EMT\Tret;
use EMT\Lib;
use EMT\Tret;

/**
* @see EMT_Tret
Expand Down Expand Up @@ -134,11 +134,18 @@ protected function build_sub_quotations()
$__ay = 0;
if($__ax)
{
$k = preg_replace_callback("/(^|[^0-9])([0-9]+)\&raquo\;/ui",
create_function('$m','global $__ax,$__ay; $__ay++; if($__ay==$__ax){ return $m[1].$m[2]."&Prime;";} return $m[0];'),
$k);
$amount = 1;
}
$k = preg_replace_callback("/(^|[^0-9])([0-9]+)\&raquo\;/ui",
function($m) {
global $__ax, $__ay;
$__ay++;
if($__ay == $__ax) {
return $m[1] . $m[2] . "&Prime;";
}
return $m[0];
},
$k);
$amount = 1;
}



Expand Down

0 comments on commit 9c7a27e

Please sign in to comment.