2015-08-14 17:43:51 +02:00
|
|
|
<?php
|
2011-12-13 12:29:05 +01:00
|
|
|
|
|
|
|
if (IN_serendipity !== true) {
|
|
|
|
die ("Don't hack!");
|
|
|
|
}
|
|
|
|
|
2015-08-14 17:43:51 +02:00
|
|
|
// Load possible language files.
|
|
|
|
@serendipity_plugin_api::load_language(dirname(__FILE__));
|
2011-12-13 12:29:05 +01:00
|
|
|
|
|
|
|
class serendipity_event_smartymarkup extends serendipity_event
|
|
|
|
{
|
|
|
|
var $title = PLUGIN_EVENT_SMARTYMARKUP_NAME;
|
|
|
|
|
|
|
|
function introspect(&$propbag)
|
|
|
|
{
|
|
|
|
global $serendipity;
|
|
|
|
|
|
|
|
$propbag->add('name', PLUGIN_EVENT_SMARTYMARKUP_NAME);
|
|
|
|
$propbag->add('description', PLUGIN_EVENT_SMARTYMARKUP_DESC);
|
|
|
|
$propbag->add('stackable', false);
|
|
|
|
$propbag->add('author', 'Garvin Hicking');
|
2016-05-17 16:46:25 +02:00
|
|
|
$propbag->add('version', '1.14');
|
2011-12-13 12:29:05 +01:00
|
|
|
$propbag->add('requirements', array(
|
2015-08-14 17:43:51 +02:00
|
|
|
'serendipity' => '1.7',
|
|
|
|
'smarty' => '3.1.0',
|
|
|
|
'php' => '5.2.0'
|
2011-12-13 12:29:05 +01:00
|
|
|
));
|
|
|
|
$propbag->add('groups', array('MARKUP'));
|
|
|
|
$propbag->add('cachable_events', array('frontend_display' => true));
|
2015-08-14 17:43:51 +02:00
|
|
|
$propbag->add('event_hooks', array('frontend_display' => true));
|
2011-12-13 12:29:05 +01:00
|
|
|
|
|
|
|
if (!defined('STATICPAGE')) {
|
|
|
|
@define('STATICPAGE', 'Staticpage');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->markup_elements = array(
|
|
|
|
array(
|
|
|
|
'name' => 'ENTRY_BODY',
|
|
|
|
'element' => 'body',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'EXTENDED_BODY',
|
|
|
|
'element' => 'extended',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'COMMENT',
|
|
|
|
'element' => 'comment',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'HTML_NUGGET',
|
|
|
|
'element' => 'html_nugget',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'STATICPAGE',
|
|
|
|
'element' => 'staticpage',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$conf_array = array();
|
|
|
|
foreach($this->markup_elements as $element) {
|
|
|
|
$conf_array[] = $element['name'];
|
|
|
|
}
|
|
|
|
$propbag->add('configuration', $conf_array);
|
|
|
|
}
|
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
function install()
|
|
|
|
{
|
2011-12-13 12:29:05 +01:00
|
|
|
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
|
|
|
|
}
|
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
function uninstall(&$propbag)
|
|
|
|
{
|
2011-12-13 12:29:05 +01:00
|
|
|
serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
|
|
|
|
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
|
|
|
|
}
|
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
function generate_content(&$title)
|
|
|
|
{
|
2011-12-13 12:29:05 +01:00
|
|
|
$title = $this->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
function introspect_config_item($name, &$propbag)
|
|
|
|
{
|
|
|
|
$propbag->add('type', 'boolean');
|
|
|
|
$propbag->add('name', constant($name));
|
2012-02-01 16:01:29 +01:00
|
|
|
$propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)) . ($name == 'COMMENT' ? PLUGIN_EVENT_SMARTYMARKUP_WARN : ''));
|
2015-08-14 17:43:51 +02:00
|
|
|
$propbag->add('default', ($name == 'COMMENT' ? 'false' : 'true'));
|
2011-12-13 12:29:05 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
function smarty_resource_smartymarkupplugin_template($tpl_name, &$tpl_source)
|
|
|
|
{
|
2012-01-31 15:21:29 +01:00
|
|
|
global $serendipity;
|
|
|
|
|
|
|
|
// return the template content via referenced argument
|
2015-08-14 17:43:51 +02:00
|
|
|
$tpl_source = $serendipity['plugindata']['smartymarkupplugin'];
|
2012-01-31 15:21:29 +01:00
|
|
|
|
|
|
|
// test
|
|
|
|
#$tpl_source = '{assign var="foo" value="bar"}{$foo|escape:"html"}';
|
|
|
|
|
|
|
|
// return success state
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
function smarty_resource_smartymarkupplugin_timestamp($tpl_name, &$tpl_timestamp)
|
|
|
|
{
|
2012-01-31 15:21:29 +01:00
|
|
|
global $serendipity;
|
|
|
|
|
2015-08-14 17:43:51 +02:00
|
|
|
$tpl_timestamp = crc32($serendipity['plugindata']['smartymarkupplugin']);
|
2012-01-31 15:21:29 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
function smarty_resource_smartymarkupplugin_secure($tpl_name)
|
|
|
|
{
|
2012-01-31 15:21:29 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
function smarty_resource_smartymarkupplugin_trusted($tpl_name)
|
|
|
|
{
|
2012-01-31 15:21:29 +01:00
|
|
|
}
|
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
function smartymarkup($input, &$eventData)
|
|
|
|
{
|
2011-12-13 12:29:05 +01:00
|
|
|
global $serendipity;
|
|
|
|
|
|
|
|
if (!isset($serendipity['smarty'])) {
|
|
|
|
serendipity_smarty_init();
|
|
|
|
}
|
|
|
|
|
2015-08-14 17:43:51 +02:00
|
|
|
if (!isset($serendipity['plugindata']['smartymarkupplugin'])) {
|
|
|
|
$serendipity['smarty']->registerResource("smartymarkupplugin", array(
|
2012-01-31 15:30:02 +01:00
|
|
|
array( $this, "smarty_resource_smartymarkupplugin_template" ),
|
|
|
|
array( $this, "smarty_resource_smartymarkupplugin_timestamp" ),
|
|
|
|
array( $this, "smarty_resource_smartymarkupplugin_secure" ),
|
|
|
|
array( $this, "smarty_resource_smartymarkupplugin_trusted" )));
|
2011-12-13 12:29:05 +01:00
|
|
|
}
|
|
|
|
|
2015-08-14 17:43:51 +02:00
|
|
|
$serendipity['plugindata']['smartymarkupplugin'] =& $input;
|
2011-12-13 12:29:05 +01:00
|
|
|
$serendipity['smarty']->assign('smartymarkup_eventData', $eventData);
|
2012-01-31 15:30:02 +01:00
|
|
|
|
2012-01-31 15:21:29 +01:00
|
|
|
// avoid non existing or empty template fetch calls
|
2015-08-14 17:43:51 +02:00
|
|
|
if (isset($serendipity['plugindata']['smartymarkupplugin']) && !empty($serendipity['plugindata']['smartymarkupplugin'])) {
|
|
|
|
return $serendipity['smarty']->fetch('smartymarkupplugin:' . crc32($serendipity['plugindata']['smartymarkupplugin']));
|
2012-01-31 15:21:29 +01:00
|
|
|
}
|
2011-12-13 12:29:05 +01:00
|
|
|
}
|
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
function event_hook($event, &$bag, &$eventData, $addData=null)
|
|
|
|
{
|
2011-12-13 12:29:05 +01:00
|
|
|
global $serendipity;
|
|
|
|
|
|
|
|
$hooks = &$bag->get('event_hooks');
|
|
|
|
|
|
|
|
if (isset($hooks[$event])) {
|
2016-05-17 16:46:25 +02:00
|
|
|
|
2011-12-13 12:29:05 +01:00
|
|
|
switch($event) {
|
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
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;
|
|
|
|
}
|
2011-12-13 12:29:05 +01:00
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
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;
|
|
|
|
}
|
2011-12-13 12:29:05 +01:00
|
|
|
}
|
|
|
|
}
|
2016-05-17 16:46:25 +02:00
|
|
|
break;
|
2011-12-13 12:29:05 +01:00
|
|
|
|
2016-05-17 16:46:25 +02:00
|
|
|
default:
|
|
|
|
return false;
|
2011-12-13 12:29:05 +01:00
|
|
|
}
|
2016-05-17 16:46:25 +02:00
|
|
|
return true;
|
2011-12-13 12:29:05 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set sts=4 ts=4 expandtab : */
|
|
|
|
?>
|