nl2br restore() better callback - see Issue #67

to match all PHP version since 5.2.6
This commit is contained in:
Ian 2013-10-08 15:14:11 +02:00
parent 0f1e93ab7d
commit d858fc8eb3

View File

@ -1,6 +1,6 @@
<?php # <?php #
# serendipity_event_nl2br.php 2013-08-28 Ian $ # serendipity_event_nl2br.php 2013-10-08 Ian $
@serendipity_plugin_api::load_language(dirname(__FILE__)); @serendipity_plugin_api::load_language(dirname(__FILE__));
@ -16,7 +16,7 @@ class serendipity_event_nl2br extends serendipity_event
$propbag->add('description', PLUGIN_EVENT_NL2BR_DESC); $propbag->add('description', PLUGIN_EVENT_NL2BR_DESC);
$propbag->add('stackable', false); $propbag->add('stackable', false);
$propbag->add('author', 'Serendipity Team'); $propbag->add('author', 'Serendipity Team');
$propbag->add('version', '2.17'); $propbag->add('version', '2.18');
$propbag->add('requirements', array( $propbag->add('requirements', array(
'serendipity' => '0.8', 'serendipity' => '0.8',
'smarty' => '2.6.7', 'smarty' => '2.6.7',
@ -152,17 +152,13 @@ class serendipity_event_nl2br extends serendipity_event
return "\001" . (count($_buf) - 1); return "\001" . (count($_buf) - 1);
} }
function restore($text) { function restore_callback($matches) {
global $_buf; global $_buf;
// Define our callback here and import $_buf into its scope ... return $_buf[$matches[1]];
if (version_compare(PHP_VERSION, '5.4') >= 0) { }
// As of PHP 5.5 deprecated /e modifier we define our callback here and import $_buf into its scope ...
$callback = function ($matches) use ($_buf) { return $_buf[$matches[1]]; }; // this works! function restore($text) {
return preg_replace_callback('!\001(\d+)!', $callback, $text); return preg_replace_callback('!\001(\d+)!', array($this, 'restore_callback'), $text); // works?!
##return preg_replace_callback('!\001(\d+)!', array($this, 'restore'), $text); // NOT working - should be somehow else
} else {
return preg_replace('~\001(\d+)~e', '$_buf[$1]', $text);
}
} }
function event_hook($event, &$bag, &$eventData, $addData = null) { function event_hook($event, &$bag, &$eventData, $addData = null) {