smartymarkup - Consistence changes

This commit is contained in:
Ian 2016-05-17 16:46:25 +02:00
parent 1caafa18b2
commit 0e4de59153
7 changed files with 95 additions and 80 deletions

View file

@ -1,3 +1,7 @@
1.14:
----
* Consistence changes
1.13: 1.13:
---- ----
* try/catch Exception to not break the flow * try/catch Exception to not break the flow

View file

@ -1,5 +1,4 @@
<?php <?php
# lang_cs.inc.php 1.2 2012-02-02 20:46:40 VladaAjgl $
/** /**
* @version 1.2 * @version 1.2

View file

@ -1,5 +1,4 @@
<?php <?php
# lang_cz.inc.php 1.2 2012-02-02 20:46:38 VladaAjgl $
/** /**
* @version 1.2 * @version 1.2

View file

@ -1,5 +1,4 @@
<?php <?php
# lang_cs.inc.php 1.2 2012-02-02 20:46:40 VladaAjgl $
/** /**
* @version 1.2 * @version 1.2

View file

@ -1,5 +1,4 @@
<?php <?php
# lang_cz.inc.php 1.2 2012-02-02 20:46:38 VladaAjgl $
/** /**
* @version 1.2 * @version 1.2

View file

@ -1,7 +1,7 @@
<?php <?php
/** /**
* @version $Revision$ * @version
* @author Translator Name <yourmail@example.com> * @author Translator Name <yourmail@example.com>
* EN-Revision: Revision of lang_en.inc.php * EN-Revision: Revision of lang_en.inc.php
*/ */

View file

@ -19,7 +19,7 @@ class serendipity_event_smartymarkup extends serendipity_event
$propbag->add('description', PLUGIN_EVENT_SMARTYMARKUP_DESC); $propbag->add('description', PLUGIN_EVENT_SMARTYMARKUP_DESC);
$propbag->add('stackable', false); $propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking'); $propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '1.13'); $propbag->add('version', '1.14');
$propbag->add('requirements', array( $propbag->add('requirements', array(
'serendipity' => '1.7', 'serendipity' => '1.7',
'smarty' => '3.1.0', 'smarty' => '3.1.0',
@ -63,16 +63,19 @@ class serendipity_event_smartymarkup extends serendipity_event
$propbag->add('configuration', $conf_array); $propbag->add('configuration', $conf_array);
} }
function install() { function install()
{
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title); 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_purge', $this->title);
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title); serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
} }
function generate_content(&$title) { function generate_content(&$title)
{
$title = $this->title; $title = $this->title;
} }
@ -85,7 +88,8 @@ class serendipity_event_smartymarkup extends serendipity_event
return true; return true;
} }
function smarty_resource_smartymarkupplugin_template($tpl_name, &$tpl_source) { function smarty_resource_smartymarkupplugin_template($tpl_name, &$tpl_source)
{
global $serendipity; global $serendipity;
// return the template content via referenced argument // return the template content via referenced argument
@ -98,21 +102,25 @@ class serendipity_event_smartymarkup extends serendipity_event
return true; return true;
} }
function smarty_resource_smartymarkupplugin_timestamp($tpl_name, &$tpl_timestamp) { function smarty_resource_smartymarkupplugin_timestamp($tpl_name, &$tpl_timestamp)
{
global $serendipity; global $serendipity;
$tpl_timestamp = crc32($serendipity['plugindata']['smartymarkupplugin']); $tpl_timestamp = crc32($serendipity['plugindata']['smartymarkupplugin']);
return true; return true;
} }
function smarty_resource_smartymarkupplugin_secure($tpl_name) { function smarty_resource_smartymarkupplugin_secure($tpl_name)
{
return true; 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; global $serendipity;
if (!isset($serendipity['smarty'])) { 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; global $serendipity;
$hooks = &$bag->get('event_hooks'); $hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) { if (isset($hooks[$event])) {
switch($event) { switch($event) {
case 'frontend_display':
if ($_GET['serendipity']['is_iframe'] == 'true' && $_GET['serendipity']['iframe_mode'] == 'save') { case 'frontend_display':
// 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 ($_GET['serendipity']['is_iframe'] == 'true' && $_GET['serendipity']['iframe_mode'] == 'save') {
if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && // 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] && !$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') { if (isset($eventData['ctitle']) && $temp['element'] == 'body') {
// s9y doesn't properly distinct between BODY and COMMENT fields and could be executed for both. // 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' // Skip this case. If comment-smarty markup should be enabled, it will be handled by the 'comment'
// element case. // element case.
continue; 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;
}
$element = $temp['element']; if (isset($eventData['staticpage']) && $temp['element'] == 'body') {
try { $eventData[$element] = $this->smartymarkup($eventData[$element], $eventData); } catch (Exception $e) { echo '<span class="msg-error"><span class="icon-attention-circled"></span> ' . ERROR_SOMETHING . ': '.$e->getMessage() . "</span>\n"; } // Skip applying markup to a staticpage content, because
if ($element == 'staticpage') { // it's already done for the "staticpage" element instead
$eventData['markup_staticpage'] = true; // 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 '<span class="msg-error"><span class="icon-attention-circled"></span> ' . ERROR_SOMETHING . ': '.$e->getMessage() . "</span>\n";
}
if ($element == 'staticpage') {
$eventData['markup_staticpage'] = true;
}
} }
} }
} break;
return true;
break;
default: default:
return false; return false;
} }
return true;
} else { } else {
return false; return false;
} }