Skip to content

Commit

Permalink
smartymarkup - Consistence changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ophian committed May 17, 2016
1 parent 1caafa1 commit 0e4de59
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 83 deletions.
4 changes: 4 additions & 0 deletions serendipity_event_smartymarkup/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.14:
----
* Consistence changes

1.13:
----
* try/catch Exception to not break the flow
Expand Down
1 change: 0 additions & 1 deletion serendipity_event_smartymarkup/UTF-8/lang_cs.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
# lang_cs.inc.php 1.2 2012-02-02 20:46:40 VladaAjgl $

/**
* @version 1.2
Expand Down
1 change: 0 additions & 1 deletion serendipity_event_smartymarkup/UTF-8/lang_cz.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
# lang_cz.inc.php 1.2 2012-02-02 20:46:38 VladaAjgl $

/**
* @version 1.2
Expand Down
1 change: 0 additions & 1 deletion serendipity_event_smartymarkup/lang_cs.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
# lang_cs.inc.php 1.2 2012-02-02 20:46:40 VladaAjgl $

/**
* @version 1.2
Expand Down
1 change: 0 additions & 1 deletion serendipity_event_smartymarkup/lang_cz.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
# lang_cz.inc.php 1.2 2012-02-02 20:46:38 VladaAjgl $

/**
* @version 1.2
Expand Down
2 changes: 1 addition & 1 deletion serendipity_event_smartymarkup/lang_en.inc.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @version $Revision$
* @version
* @author Translator Name <yourmail@example.com>
* EN-Revision: Revision of lang_en.inc.php
*/
Expand Down
171 changes: 93 additions & 78 deletions serendipity_event_smartymarkup/serendipity_event_smartymarkup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function introspect(&$propbag)
$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',
Expand Down Expand Up @@ -63,16 +63,19 @@ function introspect(&$propbag)
$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;
}

Expand All @@ -85,7 +88,8 @@ function introspect_config_item($name, &$propbag)
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
Expand All @@ -98,21 +102,25 @@ function smarty_resource_smartymarkupplugin_template($tpl_name, &$tpl_source) {
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'])) {
Expand All @@ -136,87 +144,94 @@ function smartymarkup($input, &$eventData) {
}
}

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;
}

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])) {

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;
}
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;
}

$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;
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]))
{

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;
}

$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;
}
}
}
}
return true;
break;
break;

default:
return false;
default:
return false;
}

return true;
} else {
return false;
}
Expand Down

0 comments on commit 0e4de59

Please sign in to comment.