From d858fc8eb399425d6266cf591eecbae42edcd62a Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 8 Oct 2013 15:14:11 +0200 Subject: [PATCH] nl2br restore() better callback - see Issue #67 to match all PHP version since 5.2.6 --- .../serendipity_event_nl2br.php | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/serendipity_event_nl2br/serendipity_event_nl2br.php b/plugins/serendipity_event_nl2br/serendipity_event_nl2br.php index 8ebe342c..8b00b8ef 100644 --- a/plugins/serendipity_event_nl2br/serendipity_event_nl2br.php +++ b/plugins/serendipity_event_nl2br/serendipity_event_nl2br.php @@ -1,6 +1,6 @@ add('description', PLUGIN_EVENT_NL2BR_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Serendipity Team'); - $propbag->add('version', '2.17'); + $propbag->add('version', '2.18'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', @@ -152,17 +152,13 @@ class serendipity_event_nl2br extends serendipity_event return "\001" . (count($_buf) - 1); } - function restore($text) { + function restore_callback($matches) { global $_buf; - // Define our callback here and import $_buf into its scope ... - 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! - return preg_replace_callback('!\001(\d+)!', $callback, $text); - ##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); - } + return $_buf[$matches[1]]; + } + + function restore($text) { + return preg_replace_callback('!\001(\d+)!', array($this, 'restore_callback'), $text); // works?! } function event_hook($event, &$bag, &$eventData, $addData = null) {