Example #1
0
 /**
  * Adds a ViewHelper node using the Format\HtmlspecialcharsViewHelper to the given node.
  * If "escapingInterceptorEnabled" in the ViewHelper is FALSE, will disable itself inside the ViewHelpers body.
  *
  * @param \TYPO3\Fluid\Core\Parser\SyntaxTree\NodeInterface $node
  * @param integer $interceptorPosition One of the INTERCEPT_* constants for the current interception point
  * @param \TYPO3\Fluid\Core\Parser\ParsingState $parsingState the current parsing state. Not needed in this interceptor.
  * @return \TYPO3\Fluid\Core\Parser\SyntaxTree\NodeInterface
  */
 public function process(\TYPO3\Fluid\Core\Parser\SyntaxTree\NodeInterface $node, $interceptorPosition, \TYPO3\Fluid\Core\Parser\ParsingState $parsingState)
 {
     if ($interceptorPosition === \TYPO3\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER) {
         if (!$node->getUninitializedViewHelper()->isEscapingInterceptorEnabled()) {
             $this->interceptorEnabled = FALSE;
             $this->viewHelperNodesWhichDisableTheInterceptor[] = $node;
         }
     } elseif ($interceptorPosition === \TYPO3\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER) {
         if (end($this->viewHelperNodesWhichDisableTheInterceptor) === $node) {
             array_pop($this->viewHelperNodesWhichDisableTheInterceptor);
             if (count($this->viewHelperNodesWhichDisableTheInterceptor) === 0) {
                 $this->interceptorEnabled = TRUE;
             }
         }
     } elseif ($this->interceptorEnabled && $node instanceof \TYPO3\Fluid\Core\Parser\SyntaxTree\ObjectAccessorNode) {
         $escapeViewHelper = $this->objectManager->get('TYPO3\\Fluid\\ViewHelpers\\Format\\HtmlspecialcharsViewHelper');
         $node = $this->objectManager->create('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', $escapeViewHelper, array('value' => $node));
     }
     return $node;
 }
 /**
  * Adds a ViewHelper node using the Format\HtmlspecialcharsViewHelper to the given node.
  * If "escapingInterceptorEnabled" in the ViewHelper is FALSE, will disable itself inside the ViewHelpers body.
  *
  * @param NodeInterface $node
  * @param integer $interceptorPosition One of the INTERCEPT_* constants for the current interception point
  * @param ParsingState $parsingState the current parsing state. Not needed in this interceptor.
  * @return NodeInterface
  */
 public function process(NodeInterface $node, $interceptorPosition, ParsingState $parsingState)
 {
     if ($interceptorPosition === InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER) {
         /** @var $node ViewHelperNode */
         if (!$node->getUninitializedViewHelper()->isChildrenEscapingEnabled()) {
             $this->childrenEscapingEnabled = FALSE;
             $this->viewHelperNodesWhichDisableTheInterceptor[] = $node;
         }
     } elseif ($interceptorPosition === InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER) {
         if (end($this->viewHelperNodesWhichDisableTheInterceptor) === $node) {
             array_pop($this->viewHelperNodesWhichDisableTheInterceptor);
             if (count($this->viewHelperNodesWhichDisableTheInterceptor) === 0) {
                 $this->childrenEscapingEnabled = TRUE;
             }
         }
         /** @var $node ViewHelperNode */
         if ($this->childrenEscapingEnabled && $node->getUninitializedViewHelper()->isOutputEscapingEnabled()) {
             $node = $this->wrapNode($node);
         }
     } elseif ($this->childrenEscapingEnabled && $node instanceof ObjectAccessorNode) {
         $node = $this->wrapNode($node);
     }
     return $node;
 }
 /**
  * Looks for URIs pointing to package resources and in place of those adds
  * ViewHelperNode instances using the ResourceViewHelper.
  *
  * @param \TYPO3\Fluid\Core\Parser\SyntaxTree\NodeInterface $node
  * @param integer $interceptorPosition One of the INTERCEPT_* constants for the current interception point
  * @param \TYPO3\Fluid\Core\Parser\ParsingState $parsingState the current parsing state. Not needed in this interceptor.
  * @return \TYPO3\Fluid\Core\Parser\SyntaxTree\NodeInterface the modified node
  */
 public function process(\TYPO3\Fluid\Core\Parser\SyntaxTree\NodeInterface $node, $interceptorPosition, \TYPO3\Fluid\Core\Parser\ParsingState $parsingState)
 {
     if (strpos($node->getText(), 'Public/') === FALSE) {
         return $node;
     }
     $textParts = preg_split(self::PATTERN_SPLIT_AT_RESOURCE_URIS, $node->getText(), -1, PREG_SPLIT_DELIM_CAPTURE);
     $node = $this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode');
     foreach ($textParts as $part) {
         $matches = array();
         if (preg_match(self::PATTERN_MATCH_RESOURCE_URI, $part, $matches)) {
             $arguments = array('path' => $this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\TextNode', $matches['Path']));
             if (isset($matches['Package']) && preg_match(\TYPO3\Flow\Package\Package::PATTERN_MATCH_PACKAGEKEY, $matches['Package'])) {
                 $arguments['package'] = $this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\TextNode', $matches['Package']);
             } elseif ($this->defaultPackageKey !== NULL) {
                 $arguments['package'] = $this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\TextNode', $this->defaultPackageKey);
             }
             $viewHelper = $this->objectManager->get('TYPO3\\Fluid\\ViewHelpers\\Uri\\ResourceViewHelper');
             $node->addChildNode($this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', $viewHelper, $arguments));
         } else {
             $node->addChildNode($this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\TextNode', $part));
         }
     }
     return $node;
 }
 /**
  * Looks for URIs pointing to package resources and in place of those adds
  * ViewHelperNode instances using the ResourceViewHelper.
  *
  * @param NodeInterface $node
  * @param integer $interceptorPosition One of the INTERCEPT_* constants for the current interception point
  * @param ParsingState $parsingState the current parsing state. Not needed in this interceptor.
  * @return NodeInterface the modified node
  */
 public function process(NodeInterface $node, $interceptorPosition, ParsingState $parsingState)
 {
     /** @var $node TextNode */
     if (strpos($node->getText(), 'Public/') === false) {
         return $node;
     }
     $textParts = preg_split(self::PATTERN_SPLIT_AT_RESOURCE_URIS, $node->getText(), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
     $node = $this->objectManager->get(\TYPO3\Fluid\Core\Parser\SyntaxTree\RootNode::class);
     foreach ($textParts as $part) {
         $matches = array();
         if (preg_match(self::PATTERN_MATCH_RESOURCE_URI, $part, $matches)) {
             $arguments = array('path' => $this->objectManager->get(\TYPO3\Fluid\Core\Parser\SyntaxTree\TextNode::class, $matches['Path']));
             if (isset($matches['Package']) && preg_match(Package::PATTERN_MATCH_PACKAGEKEY, $matches['Package'])) {
                 $arguments['package'] = $this->objectManager->get(\TYPO3\Fluid\Core\Parser\SyntaxTree\TextNode::class, $matches['Package']);
             } elseif ($this->defaultPackageKey !== null) {
                 $arguments['package'] = $this->objectManager->get(\TYPO3\Fluid\Core\Parser\SyntaxTree\TextNode::class, $this->defaultPackageKey);
             }
             $viewHelper = $this->objectManager->get(\TYPO3\Fluid\ViewHelpers\Uri\ResourceViewHelper::class);
             /** @var $viewHelperNode ViewHelperNode */
             $viewHelperNode = $this->objectManager->get(\TYPO3\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, $viewHelper, $arguments);
             $node->addChildNode($viewHelperNode);
         } else {
             /** @var $textNode TextNode */
             $textNode = $this->objectManager->get(\TYPO3\Fluid\Core\Parser\SyntaxTree\TextNode::class, $part);
             $node->addChildNode($textNode);
         }
     }
     return $node;
 }