added feature #5536: Some Hooks for tslib_content
authorIngo Renner <ingo.renner@typo3.org>
Tue, 15 Jan 2008 11:07:50 +0000 (11:07 +0000)
committerIngo Renner <ingo.renner@typo3.org>
Tue, 15 Jan 2008 11:07:50 +0000 (11:07 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2894 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/cms/tslib/class.tslib_content.php
typo3/sysext/cms/tslib/interfaces/interface.tslib_content_cobjgetsinglehook.php [new file with mode: 0644]
typo3/sysext/cms/tslib/interfaces/interface.tslib_content_getdatahook.php [new file with mode: 0644]
typo3/sysext/cms/tslib/interfaces/interface.tslib_content_stdwraphook.php [new file with mode: 0644]

index 5b764cf..107149b 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-01-14  Ingo Renner  <ingo@typo3.org>
+
+       * added feature #5536: Some Hooks for tslib_content
+
 2008-01-15  Benjamin Mack  <mack@xnos.org>
 
        * (bugfix) #2936, 5613: Improvements to clipboard copy/move selection (by Bernhard Kraft)
index cc3ea10..bf85f15 100755 (executable)
@@ -338,6 +338,7 @@ class tslib_cObj {
        var $substMarkerCache=array();  // Caching substituteMarkerArrayCached function
        var $recordRegister=array();    // Array that registers rendered content elements (or any table) to make sure they are not rendered recursively!
        var $cObjHookObjectsArr = array();              // Containig hooks for userdefined cObjects
+       private $stdWrapHookObjects = array();          // Containig hook objects for stdWrap
 
        /**
         * Class constructor.
@@ -358,6 +359,19 @@ class tslib_cObj {
                                $this->cObjHookObjectsArr[$classArr[0]] = &t3lib_div::getUserObj($classArr[1]);
                        }
                }
+
+               if(is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap'])) {
+                       foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap'] as $classData) {
+                               $hookObject = &t3lib_div::getUserObj($classData);
+
+                               if(!($hookObject instanceof tslib_content_stdWrapHook)) {
+                                       throw new UnexpectedValueException('$hookObject must implement interface tslib_content_stdWrapHook', 1195043965);
+                               }
+
+                               $this->stdWrapHookObjects[] = $hookObject;
+                       }
+               }
+
        }
 
        /**
@@ -443,6 +457,8 @@ class tslib_cObj {
         * @example http://typo3.org/doc.0.html?&encryptionKey=&tx_extrepmgm_pi1[extUid]=267&tx_extrepmgm_pi1[tocEl]=153&cHash=7e74f4d331
         */
        function cObjGetSingle($name,$conf,$TSkey='__') {
+               global $TYPO3_CONF_VARS;
+
                $content='';
                        // Checking that the function is not called eternally. This is done by interrupting at a depth of 100
                $GLOBALS['TSFE']->cObjectDepthCounter--;
@@ -566,6 +582,20 @@ class tslib_cObj {
                                                case 'MULTIMEDIA':
                                                        $content.=$this->MULTIMEDIA($conf);
                                                break;
+                                               default:
+                                                               // call hook functions for extra processing
+                                                       if(is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClassDefault']))    {
+                                                               foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClassDefault'] as $classData)    {
+                                                                       $hookObject = &t3lib_div::getUserObj($classData);
+
+                                                                       if(!($hookObject instanceof tslib_content_cObjGetSingleHook)) {
+                                                                               throw new UnexpectedValueException('$hookObject must implement interface tslib_content_cObjGetSingleHook', 1195043731);
+                                                                       }
+
+                                                                       $content .= $hookObject->getSingleContentObject($name, $conf, $TSkey, $this);
+                                                               }
+                                                       }
+                                               break;
                                        }
                                }
                        }
@@ -3124,6 +3154,10 @@ class tslib_cObj {
        function stdWrap($content,$conf)        {
                if (is_array($conf))    {
 
+                       foreach($this->stdWrapHookObjects as $hookObject) {
+                               $content = $hookObject->stdWrapPreProcess($content, $conf, $this);
+                       }
+
                                // Setting current value, if so
                        if ($conf['setContentToCurrent']){$this->data[$this->currentValKey]=$content;}
                        if ($conf['setCurrent'] || $conf['setCurrent.']){$this->data[$this->currentValKey] = $this->stdWrap($conf['setCurrent'], $conf['setCurrent.']);}
@@ -3141,6 +3175,10 @@ class tslib_cObj {
                        if ($conf['filelist'] || $conf['filelist.'])    {$content=$this->filelist($this->stdWrap($conf['filelist'], $conf['filelist.']));}
                        if ($conf['preUserFunc'])       {$content = $this->callUserFunction($conf['preUserFunc'], $conf['preUserFunc.'], $content);}
 
+                       foreach($this->stdWrapHookObjects as $hookObject)       {
+                               $content = $hookObject->stdWrapOverride($content, $conf, $this);
+                       }
+
                                // Overriding values, evaluating conditions
                        if ($conf['override'] || $conf['override.']){
                                $override = $this->stdWrap($conf['override'], $conf['override.']);
@@ -3168,6 +3206,10 @@ class tslib_cObj {
                                // Call stdWrap recursively
                        if ($conf['stdWrap.'])  { $content=$this->stdWrap($content,$conf['stdWrap.']); }
 
+                       foreach($this->stdWrapHookObjects as $hookObject) {
+                               $content = $hookObject->stdWrapProcess($content, $conf, $this);
+                       }
+
                        if (   ($conf['required'] && (string)$content=='') || ($conf['if.'] && !$this->checkIf($conf['if.'])) || ($conf['fieldRequired'] && !trim($this->data[$conf['fieldRequired']]))    ){
                                $content = '';
                        } else  {
@@ -3263,10 +3305,21 @@ class tslib_cObj {
                                        $content ='<!--'.$substKey.'-->';
                                }
                                        // Various:
-                               if ($conf['prefixComment'] && !$GLOBALS['TSFE']->config['config']['disablePrefixComment'])      {$content = $this->prefixComment($conf['prefixComment'], $conf['prefixComment.'], $content);}
+                               if ($conf['prefixComment'] && !$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
+                                       $content = $this->prefixComment($conf['prefixComment'], $conf['prefixComment.'], $content);
+                               }
+
+                               if ($conf['editIcons'] && $GLOBALS['TSFE']->beUserLogin) {
+                                       $content = $this->editIcons($content, $conf['editIcons'], $conf['editIcons.']);
+                               }
+
+                               if ($conf['editPanel'] && $GLOBALS['TSFE']->beUserLogin) {
+                                       $content = $this->editPanel($content, $conf['editPanel.']);
+                               }
+                       }
 
-                               if ($conf['editIcons'] && $GLOBALS['TSFE']->beUserLogin){$content=$this->editIcons($content,$conf['editIcons'],$conf['editIcons.']);}
-                               if ($conf['editPanel'] && $GLOBALS['TSFE']->beUserLogin){$content=$this->editPanel($content, $conf['editPanel.']);}
+                       foreach($this->stdWrapHookObjects as $hookObject) {
+                               $content = $hookObject->stdWrapPostProcess($content, $conf, $this);
                        }
 
                                //Debug:
@@ -4760,6 +4813,8 @@ class tslib_cObj {
         * @see getFieldVal()
         */
        function getData($string,$fieldArray)   {
+               global $TYPO3_CONF_VARS;
+
                if (!is_array($fieldArray))     {
                        $fieldArray=$GLOBALS['TSFE']->page;
                }
@@ -4874,7 +4929,20 @@ class tslib_cObj {
                                        break;
                                }
                        }
+
+                       if(is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['getData']))    {
+                               foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['getData'] as $classData)    {
+                                       $hookObject = &t3lib_div::getUserObj($classData);
+
+                                       if(!($hookObject instanceof tslib_content_getDataHook)) {
+                                               throw new UnexpectedValueException('$hookObject must implement interface tslib_content_getDataHook', 1195044480);
+                                       }
+
+                                       $retVal = $hookObject->getDataExtension($string, $fieldArray, $secVal, $retVal, $this);
+                               }
+                       }
                }
+
                return $retVal;
        }
 
diff --git a/typo3/sysext/cms/tslib/interfaces/interface.tslib_content_cobjgetsinglehook.php b/typo3/sysext/cms/tslib/interfaces/interface.tslib_content_cobjgetsinglehook.php
new file mode 100644 (file)
index 0000000..d3b7388
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2007 Ingo Renner <ingo@typo3.org>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+
+/**
+ * interface for classes which hook into tslib_content and do additional cObjGetSingle processing
+ *
+ * @author     Ingo Renner <ingo@typo3.org>
+ * @package TYPO3
+ * @subpackage t3lib
+ */
+interface tslib_content_cObjGetSingleHook {
+
+       /**
+        * Renders content objects, that are not defined in the core
+        *
+        * @param       string          The content object name, eg. "TEXT" or "USER" or "IMAGE"
+        * @param       array           array with TypoScript properties for the content object
+        * @param       string          label used for the internal debug tracking
+        * @param       tslib_cObj      parent content object
+        * @return      string          cObject output
+        */
+       public function getSingleContentObject($contentObjectName, array $configuration, $TypoScriptKey, tslib_cObj &$parentObject);
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/cms/tslib/interfaces/interface.tslib_content_getdatahook.php b/typo3/sysext/cms/tslib/interfaces/interface.tslib_content_getdatahook.php
new file mode 100644 (file)
index 0000000..47d7bdc
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2007 Ingo Renner <ingo@typo3.org>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+
+/**
+ * interface for classes which hook into tslib_content and do additional getData processing
+ *
+ * @author     Ingo Renner <ingo@typo3.org>
+ * @package TYPO3
+ * @subpackage t3lib
+ */
+interface tslib_content_getDataHook {
+
+       /**
+        * Extends the getData()-Method of tslib_cObj to process more/other commands
+        *
+        * @param       string          full content of getData-request e.g. "TSFE:id // field:title // field:uid"
+        * @param       array           current field-array
+        * @param       string          currently examined section value of the getData request e.g. "field:title"
+        * @param       string          current returnValue that was processed so far by getData
+        * @param       tslib_cObj      parent content object
+        * @return      string          get data result
+        */
+       public function getDataExtension($getDataString, array $fields, $sectionValue, $returnValue, tslib_cObj &$parentObject);
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/cms/tslib/interfaces/interface.tslib_content_stdwraphook.php b/typo3/sysext/cms/tslib/interfaces/interface.tslib_content_stdwraphook.php
new file mode 100644 (file)
index 0000000..a1e12a0
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2007 Ingo Renner <ingo@typo3.org>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+
+/**
+ * interface for classes which hook into tslib_content and do additional stdWrap processing
+ *
+ * @author     Ingo Renner <ingo@typo3.org>
+ * @package TYPO3
+ * @subpackage t3lib
+ */
+interface tslib_content_stdWrapHook {
+
+       /**
+        * Hook for modifying $content before core's stdWrap does anything
+        *
+        * @param       string          input value undergoing processing in this function. Possibly substituted by other values fetched from another source.
+        * @param       array           TypoScript stdWrap properties
+        * @param       tslib_cObj      parent content object
+        * @return      string          further processed $content
+        */
+       public function stdWrapPreProcess($content, array $configuration, tslib_cObj &$parentObject);
+
+       /**
+        * Hook for modifying $content after core's stdWrap has processed setContentToCurrent, setCurrent, lang, data, field, current, cObject, numRows, filelist and/or preUserFunc
+        *
+        * @param       string          input value undergoing processing in this function. Possibly substituted by other values fetched from another source.
+        * @param       array           TypoScript stdWrap properties
+        * @param       tslib_cObj      parent content object
+        * @return      string          further processed $content
+        */
+       public function stdWrapOverride($content, array $configuration, tslib_cObj &$parentObject);
+
+       /**
+        * Hook for modifying $content after core's stdWrap has processed override, preIfEmptyListNum, ifEmpty, ifBlank, listNum, trim and/or more (nested) stdWraps
+        *
+        * @param       string          input value undergoing processing in this function. Possibly substituted by other values fetched from another source.
+        * @param       array           TypoScript "stdWrap properties".
+        * @param       tslib_cObj      parent content object
+        * @return      string          further processed $content
+        */
+       public function stdWrapProcess($content, array $configuration, tslib_cObj &$parentObject);
+
+       /**
+        * Hook for modifying $content after core's stdWrap has processed anything but debug
+        *
+        * @param       string          input value undergoing processing in this function. Possibly substituted by other values fetched from another source.
+        * @param       array           TypoScript stdWrap properties
+        * @param       tslib_cObj      parent content object
+        * @return      string          further processed $content
+        */
+       public function stdWrapPostProcess($content, array $configuration, tslib_cObj &$parentObject);
+
+}
+
+?>
\ No newline at end of file