From 0e4de59153efd8ffd6d68ed344fc982ba037ac45 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 17 May 2016 16:46:25 +0200 Subject: [PATCH] smartymarkup - Consistence changes --- serendipity_event_smartymarkup/ChangeLog | 4 + .../UTF-8/lang_cs.inc.php | 1 - .../UTF-8/lang_cz.inc.php | 1 - .../lang_cs.inc.php | 1 - .../lang_cz.inc.php | 1 - .../lang_en.inc.php | 2 +- .../serendipity_event_smartymarkup.php | 165 ++++++++++-------- 7 files changed, 95 insertions(+), 80 deletions(-) diff --git a/serendipity_event_smartymarkup/ChangeLog b/serendipity_event_smartymarkup/ChangeLog index 74191aeb..311adc5d 100644 --- a/serendipity_event_smartymarkup/ChangeLog +++ b/serendipity_event_smartymarkup/ChangeLog @@ -1,3 +1,7 @@ +1.14: +---- + * Consistence changes + 1.13: ---- * try/catch Exception to not break the flow diff --git a/serendipity_event_smartymarkup/UTF-8/lang_cs.inc.php b/serendipity_event_smartymarkup/UTF-8/lang_cs.inc.php index 3c774e50..a4f4f231 100644 --- a/serendipity_event_smartymarkup/UTF-8/lang_cs.inc.php +++ b/serendipity_event_smartymarkup/UTF-8/lang_cs.inc.php @@ -1,5 +1,4 @@ * EN-Revision: Revision of lang_en.inc.php */ diff --git a/serendipity_event_smartymarkup/serendipity_event_smartymarkup.php b/serendipity_event_smartymarkup/serendipity_event_smartymarkup.php index 861927da..62869366 100644 --- a/serendipity_event_smartymarkup/serendipity_event_smartymarkup.php +++ b/serendipity_event_smartymarkup/serendipity_event_smartymarkup.php @@ -19,7 +19,7 @@ class serendipity_event_smartymarkup extends serendipity_event $propbag->add('description', PLUGIN_EVENT_SMARTYMARKUP_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking'); - $propbag->add('version', '1.13'); + $propbag->add('version', '1.14'); $propbag->add('requirements', array( 'serendipity' => '1.7', 'smarty' => '3.1.0', @@ -63,16 +63,19 @@ class serendipity_event_smartymarkup extends serendipity_event $propbag->add('configuration', $conf_array); } - function install() { + function install() + { serendipity_plugin_api::hook_event('backend_cache_entries', $this->title); } - function uninstall(&$propbag) { + function uninstall(&$propbag) + { serendipity_plugin_api::hook_event('backend_cache_purge', $this->title); serendipity_plugin_api::hook_event('backend_cache_entries', $this->title); } - function generate_content(&$title) { + function generate_content(&$title) + { $title = $this->title; } @@ -85,7 +88,8 @@ class serendipity_event_smartymarkup extends serendipity_event return true; } - function smarty_resource_smartymarkupplugin_template($tpl_name, &$tpl_source) { + function smarty_resource_smartymarkupplugin_template($tpl_name, &$tpl_source) + { global $serendipity; // return the template content via referenced argument @@ -98,21 +102,25 @@ class serendipity_event_smartymarkup extends serendipity_event return true; } - function smarty_resource_smartymarkupplugin_timestamp($tpl_name, &$tpl_timestamp) { + function smarty_resource_smartymarkupplugin_timestamp($tpl_name, &$tpl_timestamp) + { global $serendipity; $tpl_timestamp = crc32($serendipity['plugindata']['smartymarkupplugin']); return true; } - function smarty_resource_smartymarkupplugin_secure($tpl_name) { + function smarty_resource_smartymarkupplugin_secure($tpl_name) + { return true; } - function smarty_resource_smartymarkupplugin_trusted($tpl_name) { + function smarty_resource_smartymarkupplugin_trusted($tpl_name) + { } - function smartymarkup($input, &$eventData) { + function smartymarkup($input, &$eventData) + { global $serendipity; if (!isset($serendipity['smarty'])) { @@ -136,87 +144,94 @@ class serendipity_event_smartymarkup extends serendipity_event } } - function event_hook($event, &$bag, &$eventData, $addData=null) { + function event_hook($event, &$bag, &$eventData, $addData=null) + { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { + switch($event) { - case 'frontend_display': - if ($_GET['serendipity']['is_iframe'] == 'true' && $_GET['serendipity']['iframe_mode'] == 'save') { - // Due to strange errors passing by with an unregistered function at this point, - // eg. giving a 'Fatal error: Call to undefined function staticpage_display()', - // we disable this in Serendipity iframe preview saving mode. - // $serendipity['GET'] is not available too - // This also disables the preview on saving, which is not a need and might confuse here - return; - } + case 'frontend_display': - foreach ($this->markup_elements as $temp) { - if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && + if ($_GET['serendipity']['is_iframe'] == 'true' && $_GET['serendipity']['iframe_mode'] == 'save') { + // Due to strange errors passing by with an unregistered function at this point, + // eg. giving a 'Fatal error: Call to undefined function staticpage_display()', + // we disable this in Serendipity iframe preview saving mode. + // $serendipity['GET'] is not available too + // This also disables the preview on saving, which is not a need and might confuse here + return; + } + + foreach ($this->markup_elements as $temp) { + if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && !$eventData['properties']['ep_disable_markup_' . $this->instance] && - !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) { + !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) + { - if (isset($eventData['ctitle']) && $temp['element'] == 'body') { - // s9y doesn't properly distinct between BODY and COMMENT fields and could be executed for both. - // Skip this case. If comment-smarty markup should be enabled, it will be handled by the 'comment' - // element case. - continue; - } - - if (isset($eventData['staticpage']) && $temp['element'] == 'body') { - // Skip applying markup to a staticpage content, because - // it's already done for the "staticpage" element instead - // of "body". - continue; - } - // This matches CKEDITOR codesnippet and Googles prettyprint highlight markup - // ToDo: enhance to match only when it finds {$foo} and {word_boundary patterns ...} in it - $regex = '/(<(pre|code)\s+[^>]*?class\s*?=\s*?["|\'].*?(prettyprint|language-).*?["|\'].*?>)(.*?)(<\/(code|pre)>)/si'; - if (isset($eventData['body']) && preg_match($regex, $eventData['body']) || - isset($eventData['extended']) && preg_match($regex, $eventData['extended']) || - isset($eventData['staticpage']) && preg_match($regex, $eventData['staticpage'])) { - // Skip parsing when entry has code highlighter blocks, - // which are show-code only, set by CKEDITOR codesnippet plugin. - // This should work for other highlighters too, - // since this pattern is a common usage for marking syntax code. - // Do not use both in entries: Smarty parsing and Coding Blocks with Smarty! - // Default to skip are code highlighter blocks. - continue; - } - if (isset($eventData['body']) && preg_match('@\[\[\{\$@', $eventData['body']) || - isset($eventData['extended']) && preg_match('@\[\[\{\$@', $eventData['extended']) || - isset($eventData['staticpage']) && preg_match('@\[\[\{\$@', $eventData['staticpage'])) { - // Do not parse content with WP-Smarty like executors eg [[{$foo}]] - // set by a possible future plugin... - continue; - } - if (isset($eventData['body']) && preg_match('@{{!@', $eventData['body']) || - isset($eventData['extended']) && preg_match('@{{!@', $eventData['extended']) || - isset($eventData['staticpage']) && preg_match('@{{!@', $eventData['staticpage'])) { - // Do not parse content with multilanguage tags - // set by the multilingual plugin. - // Do not use both in entries: Smarty parsing and multilingual tags! - // Default to skip is tag multilingual. - continue; - } + if (isset($eventData['ctitle']) && $temp['element'] == 'body') { + // s9y doesn't properly distinct between BODY and COMMENT fields and could be executed for both. + // Skip this case. If comment-smarty markup should be enabled, it will be handled by the 'comment' + // element case. + continue; + } - $element = $temp['element']; - try { $eventData[$element] = $this->smartymarkup($eventData[$element], $eventData); } catch (Exception $e) { echo ' ' . ERROR_SOMETHING . ': '.$e->getMessage() . "\n"; } - if ($element == 'staticpage') { - $eventData['markup_staticpage'] = true; + if (isset($eventData['staticpage']) && $temp['element'] == 'body') { + // Skip applying markup to a staticpage content, because + // it's already done for the "staticpage" element instead + // of "body". + continue; + } + // This matches CKEDITOR codesnippet and Googles prettyprint highlight markup + // ToDo: enhance to match only when it finds {$foo} and {word_boundary patterns ...} in it + $regex = '/(<(pre|code)\s+[^>]*?class\s*?=\s*?["|\'].*?(prettyprint|language-).*?["|\'].*?>)(.*?)(<\/(code|pre)>)/si'; + if (isset($eventData['body']) && preg_match($regex, $eventData['body']) || + isset($eventData['extended']) && preg_match($regex, $eventData['extended']) || + isset($eventData['staticpage']) && preg_match($regex, $eventData['staticpage'])) { + // Skip parsing when entry has code highlighter blocks, + // which are show-code only, set by CKEDITOR codesnippet plugin. + // This should work for other highlighters too, + // since this pattern is a common usage for marking syntax code. + // Do not use both in entries: Smarty parsing and Coding Blocks with Smarty! + // Default to skip are code highlighter blocks. + continue; + } + if (isset($eventData['body']) && preg_match('@\[\[\{\$@', $eventData['body']) || + isset($eventData['extended']) && preg_match('@\[\[\{\$@', $eventData['extended']) || + isset($eventData['staticpage']) && preg_match('@\[\[\{\$@', $eventData['staticpage'])) { + // Do not parse content with WP-Smarty like executors eg [[{$foo}]] + // set by a possible future plugin... + continue; + } + if (isset($eventData['body']) && preg_match('@{{!@', $eventData['body']) || + isset($eventData['extended']) && preg_match('@{{!@', $eventData['extended']) || + isset($eventData['staticpage']) && preg_match('@{{!@', $eventData['staticpage'])) { + // Do not parse content with multilanguage tags + // set by the multilingual plugin. + // Do not use both in entries: Smarty parsing and multilingual tags! + // Default to skip is tag multilingual. + continue; + } + + $element = $temp['element']; + try { + $eventData[$element] = $this->smartymarkup($eventData[$element], $eventData); + } catch (Exception $e) { + echo ' ' . ERROR_SOMETHING . ': '.$e->getMessage() . "\n"; + } + if ($element == 'staticpage') { + $eventData['markup_staticpage'] = true; + } } } - } - return true; - break; + break; - default: - return false; + default: + return false; } - + return true; } else { return false; }