From d99f20527081759a43e0c5c1f3b531d7a02c6ae2 Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Fri, 1 Jun 2007 15:31:54 +0000 Subject: [PATCH] Add smaty modifier that can pass referenced variables to a smarty plugin api. Hurts to see that, but seems to be the only way --- include/compat.inc.php | 2 +- include/functions_smarty.inc.php | 39 ++++++++++++++++++- .../serendipity_event_spamblock.php | 7 +++- templates/default/admin/entries.tpl | 14 +++---- templates/default/admin/index.tpl | 4 +- 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/include/compat.inc.php b/include/compat.inc.php index 8e15694..c044496 100644 --- a/include/compat.inc.php +++ b/include/compat.inc.php @@ -133,7 +133,7 @@ if (extension_loaded('filter') && function_exists('filter_id') && function_exist foreach ($_COOKIE as $key => $value) { $_COOKIE[$key] = filter_input(INPUT_COOKIE, $key, FILTER_UNSAFE_RAW); } - + // NOT YET IMPLEMENTED IN PHP: /* foreach ($_SESSION as $key => $value) { diff --git a/include/functions_smarty.inc.php b/include/functions_smarty.inc.php index 01fefdf..fcd60e4 100644 --- a/include/functions_smarty.inc.php +++ b/include/functions_smarty.inc.php @@ -496,6 +496,42 @@ function serendipity_smarty_hookPlugin($params, &$smarty) { serendipity_plugin_api::hook_event($params['hook'], $params['data'], $params['addData']); } +/** + * Smarty Modifier: Be able to execute the hook of an event plugin and return its output, uses a REFERENCED variable. + * + * Listens to specific serendipity global variables: + * $serendipity['skip_smarty_hooks'] - If TRUE, no plugins will be executed at all + * $serendipity['skip_smarty_hook'] - Can be set to an array of plugin hooks to NOT execute + * + * @access public + * @param mixed EventData (referenced) + * @param string Event hook name + * @param mixed Additional data + * @return null + */ +function serendipity_smarty_refhookPlugin(&$eventData, $hook, $addData = null) { + global $serendipity; + + if (!isset($hook)) { + $smarty->trigger_error(__FUNCTION__ .": missing 'hook' parameter"); + return; + } + + // Smarty hooks can be bypassed via an internal variable (temporarily) + if (isset($serendipity['skip_smarty_hooks']) && $serendipity['skip_smarty_hooks']) { + return; + } + + // A specific hook can also be bypassed by creating an associative array like this: + // $serendipity['skip_smarty_hook'] = array('entries_header'); + // That would only skip the entries_header event hook, but allow all others. + // Of course it cannot be used in conjunction with the all-blocking skip_smarty_hooks. + if (isset($serendipity['skip_smarty_hook']) && is_array($serendipity['skip_smarty_hook']) && isset($serendipity['skip_smarty_hook'][$params['hook']])) { + return; + } + + serendipity_plugin_api::hook_event($hook, $eventData, $addData); +} /** * Smarty Function: Prints a list of sidebar plugins @@ -704,7 +740,7 @@ function serendipity_smarty_init($vars = array()) { if (!class_exists('Smarty')) { include SMARTY_DIR . 'Smarty.class.php'; } - + if (!class_exists('Smarty')) { return false; } @@ -745,6 +781,7 @@ function serendipity_smarty_init($vars = array()) { $serendipity['smarty']->register_modifier('serendipity_utf8_encode', 'serendipity_utf8_encode'); $serendipity['smarty']->register_modifier('ifRemember', 'serendipity_ifRemember'); $serendipity['smarty']->register_modifier('checkPermission', 'serendipity_checkPermission'); + $serendipity['smarty']->register_modifier('serendipity_refhookPlugin', 'serendipity_smarty_refhookPlugin'); $serendipity['smarty']->register_function('serendipity_printSidebar', 'serendipity_smarty_printSidebar'); $serendipity['smarty']->register_function('serendipity_hookPlugin', 'serendipity_smarty_hookPlugin'); diff --git a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php index 7be21e6..dbff907 100644 --- a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php +++ b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php @@ -39,7 +39,7 @@ var $filter_defaults; 'smarty' => '2.6.7', 'php' => '4.1.0' )); - $propbag->add('version', '1.67'); + $propbag->add('version', '1.68'); $propbag->add('event_hooks', array( 'frontend_saveComment' => true, 'external_plugin' => true, @@ -682,6 +682,11 @@ var $filter_defaults; // Check if the entry is older than the allowed amount of time. Enforce kaptchas if that is true // of if kaptchas are activated for every entry $show_captcha = ($captchas && isset($eventData['timestamp']) && ($captchas_ttl < 1 || ($eventData['timestamp'] < (time() - ($captchas_ttl*60*60*24)))) ? true : false); + + // Plugins can override with custom captchas + if (isset($serendipity['plugins']['disable_internal_captcha'])) { + $show_captcha = false; + } $forcemoderation = $this->get_config('forcemoderation', 60); $forcemoderation_treat = $this->get_config('forcemoderation_treat', 'moderate'); diff --git a/templates/default/admin/entries.tpl b/templates/default/admin/entries.tpl index 27c3ecd..23a2ecd 100644 --- a/templates/default/admin/entries.tpl +++ b/templates/default/admin/entries.tpl @@ -35,7 +35,7 @@ {*** ENTRY TITLE, DRAFT END ***} - + {*** ENTRY DATE,CATEGORY START ***} {if $entry_vars.allowDateManipulation} @@ -50,7 +50,7 @@ {else} {/if} - {$CONST.CATEGORY}: + {$CONST.CATEGORY}: -- 2.39.5