TYPO3 API  SVNRelease
Escape.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script belongs to the FLOW3 package "Fluid".                      *
00005  *                                                                        *
00006  * It is free software; you can redistribute it and/or modify it under    *
00007  * the terms of the GNU Lesser General Public License as published by the *
00008  * Free Software Foundation, either version 3 of the License, or (at your *
00009  * option) any later version.                                             *
00010  *                                                                        *
00011  * This script is distributed in the hope that it will be useful, but     *
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00013  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
00014  * General Public License for more details.                               *
00015  *                                                                        *
00016  * You should have received a copy of the GNU Lesser General Public       *
00017  * License along with the script.                                         *
00018  * If not, see http://www.gnu.org/licenses/lgpl.html                      *
00019  *                                                                        *
00020  * The TYPO3 project - inspiring people to share!                         *
00021  *                                                                        */
00022 
00023 /**
00024  * An interceptor adding the escape viewhelper to the suitable places.
00025  *
00026  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00027  */
00028 class Tx_Fluid_Core_Parser_Interceptor_Escape implements Tx_Fluid_Core_Parser_InterceptorInterface {
00029 
00030     /**
00031      * Is the interceptor enabled right now?
00032      * @var boolean
00033      */
00034     protected $interceptorEnabled = TRUE;
00035 
00036     /**
00037      * A stack of ViewHelperNodes which currently disable the interceptor.
00038      * Needed to enable the interceptor again.
00039      *
00040      * @var array<Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface>
00041      */
00042     protected $viewHelperNodesWhichDisableTheInterceptor = array();
00043 
00044     /**
00045      * @var Tx_Extbase_Object_ObjectManagerInterface
00046      */
00047     protected $objectManager;
00048 
00049     /**
00050      * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
00051      * @return void
00052      * @author Karsten Dambekalns <karsten@typo3.org>
00053      */
00054     public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
00055         $this->objectManager = $objectManager;
00056     }
00057 
00058     /**
00059      * Adds a ViewHelper node using the EscapeViewHelper to the given node.
00060      * If "escapingInterceptorEnabled" in the ViewHelper is FALSE, will disable itself inside the ViewHelpers body.
00061      *
00062      * @param Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface $node
00063      * @param integer $interceptorPosition One of the INTERCEPT_* constants for the current interception point
00064      * @return Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface
00065      * @author Karsten Dambekalns <karsten@typo3.org>
00066      * @author Sebastian Kurfürst <sebastian@typo3.org>
00067      */
00068     public function process(Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface $node, $interceptorPosition) {
00069         if ($interceptorPosition === Tx_Fluid_Core_Parser_InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER) {
00070             if (!$node->getUninitializedViewHelper()->isEscapingInterceptorEnabled()) {
00071                 $this->interceptorEnabled = FALSE;
00072                 $this->viewHelperNodesWhichDisableTheInterceptor[] = $node;
00073             }
00074         } elseif ($interceptorPosition === Tx_Fluid_Core_Parser_InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER) {
00075             if (end($this->viewHelperNodesWhichDisableTheInterceptor) === $node) {
00076                 array_pop($this->viewHelperNodesWhichDisableTheInterceptor);
00077                 if (count($this->viewHelperNodesWhichDisableTheInterceptor) === 0) {
00078                     $this->interceptorEnabled = TRUE;
00079                 }
00080             }
00081         } elseif ($this->interceptorEnabled && $node instanceof Tx_Fluid_Core_Parser_SyntaxTree_ObjectAccessorNode) {
00082             $node = $this->objectManager->create(
00083                 'Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode',
00084                 $this->objectManager->create('Tx_Fluid_ViewHelpers_EscapeViewHelper'),
00085                 array('value' => $node)
00086             );
00087         }
00088         return $node;
00089     }
00090 
00091     /**
00092      * This interceptor wants to hook into object accessor creation, and opening / closing ViewHelpers.
00093      *
00094      * @return array Array of INTERCEPT_* constants
00095      */
00096     public function getInterceptionPoints() {
00097         return array(
00098             Tx_Fluid_Core_Parser_InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER,
00099             Tx_Fluid_Core_Parser_InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER,
00100             Tx_Fluid_Core_Parser_InterceptorInterface::INTERCEPT_OBJECTACCESSOR
00101         );
00102     }
00103 }
00104 ?>