]> git.mjollnir.org Git - s9y.git/commitdiff
Add smaty modifier that can pass referenced variables to a smarty plugin api. Hurts...
authorgarvinhicking <garvinhicking>
Fri, 1 Jun 2007 15:31:54 +0000 (15:31 +0000)
committergarvinhicking <garvinhicking>
Fri, 1 Jun 2007 15:31:54 +0000 (15:31 +0000)
include/compat.inc.php
include/functions_smarty.inc.php
plugins/serendipity_event_spamblock/serendipity_event_spamblock.php
templates/default/admin/entries.tpl
templates/default/admin/index.tpl

index 8e156941c7da21b8c387a4275a7e04b9664f99be..c044496d3a3d18c7987d14e5781aae23c9085841 100644 (file)
@@ -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) {
index 01fefdf4a31db402ae2aac62d52e8d40b01ff3ad..fcd60e4e91ba17519e7e97d709a54342657076ec 100644 (file)
@@ -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');
index 7be21e6f449deb2b51fa75ee7334890647d859e0..dbff907065883d271b5c6f9190f65e039e8f2df7 100644 (file)
@@ -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');
index 27c3ecdd0f786504bff5e97dd322c71330652f61..23a2ecd66ba86451d550b02ed6d9e534c7544a07 100644 (file)
@@ -35,7 +35,7 @@
     {*** ENTRY TITLE, DRAFT END ***}
 
     <tr>
-   
+
     {*** ENTRY DATE,CATEGORY START ***}
     {if $entry_vars.allowDateManipulation}
         <td>
@@ -50,7 +50,7 @@
     {else}
         <td align="right" colspan="3">
     {/if}
-            <a style="border:0; text-decoration: none" href="#" onclick="showItem('categoryselector'); return false" title="{$CONST.TOGGLE_OPTION}"><img src="{serendipity_getFile file='img/plus.png'}" id="option_categoryselector" style="border: 20px" alt="" border="0" /></a> <b>{$CONST.CATEGORY}:</b> 
+            <a style="border:0; text-decoration: none" href="#" onclick="showItem('categoryselector'); return false" title="{$CONST.TOGGLE_OPTION}"><img src="{serendipity_getFile file='img/plus.png'}" id="option_categoryselector" style="border: 20px" alt="" border="0" /></a> <b>{$CONST.CATEGORY}:</b>
             <select id="categoryselector" name="serendipity[categories][]" style="vertical-align: middle;" multiple="multiple">
                 <option value="0">[{$CONST.NO_CATEGORY}]</option>
                 {foreach from=$entry_vars.category_options item="entry_cat"}
@@ -66,7 +66,7 @@
             var selector_toggle  = new Array();
             var selector_store   = new Array();
             var selector_restore = new Array();
-        
+
             function checkSave() {
                 {serendipity_hookPlugin hook='backend_entry_checkSave' hookAll='true'}
                 return true;
             <br />
             <fieldset>
                 <legend><b>{$CONST.ADVANCED_OPTIONS}</b></legend>
-    {*** EXTERNAL PLUGINS OUTPUT START ***}                
-                {serendipity_hookPlugin hook="backend_display" data=$entry_vars.entry hookAll="true"}
-    {*** EXTERNAL PLUGINS OUTPUT END ***}                
+    {*** EXTERNAL PLUGINS OUTPUT START ***}
+                {$entry_vars.entry|@serendipity_refhookPlugin:'backend_display'}
+    {*** EXTERNAL PLUGINS OUTPUT END ***}
             </fieldset>
         </td>
     </tr>
     {foreach from=$entry_vars.wysiwyg_blocks item="wysiwyg_block_item" key="wysiwyg_block_jsname"}
         {$wysiwyg_block_item|emit_htmlarea_code:$wysiwyg_block_jsname}
     {/foreach}
-    {serendipity_hookPlugin hook="backend_wysiwyg_finish" data=$entry_vars.wysiwyg_blocks hookAll="true"}
+    {serendipity_refhookPlugin hook="backend_wysiwyg_finish" data=$entry_vars.wysiwyg_blocks}
 {/if}
 {*** SPAWN WYSIWYG EDITORS END ***}
 
index 9061f1ea5779704b9a32189dd285ae6213268574..f1932515453a4387528c88575c72ba3b96d0390d 100644 (file)
@@ -77,7 +77,7 @@
 {if NOT $admin_vars.is_logged_in}
 {*** LOGIN-AREA START ***}
 
-    {serendipity_hookPlugin hook="backend_header" data=$admin_vars.out hookAll="true"}
+    {$admin_vars.out|@serendipity_refhookPlugin:'backend_login_page'}
                 <td colspan="2" class="serendipityAdminContent">
                     <div align="center">{$CONST.WELCOME_TO_ADMIN}<br />
                     {$CONST.PLEASE_ENTER_CREDENTIALS}
@@ -88,7 +88,7 @@
                     {if $admin_vars.post_action != '' AND NOT $admin_vars.is_logged_in}
                     <div class="serendipityAdminMsgError">{$CONST.WRONG_USERNAME_OR_PASSWORD}</div>
                     {/if}
-                    
+
                     <form action="serendipity_admin.php" method="post">
                         <input type="hidden" name="serendipity[action]" value="admin" />
                         <table cellspacing="10" cellpadding="0" border="0" align="center">