예제 #1
0
파일: Escape.php 프로젝트: bwaidelich/Fluid
 /**
  * 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)
 {
     $resolver = $parsingState->getViewHelperResolver();
     if ($interceptorPosition === InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER) {
         /** @var ViewHelperNode $node */
         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 ViewHelperNode $node */
         if ($this->childrenEscapingEnabled && $node->getUninitializedViewHelper()->isOutputEscapingEnabled()) {
             $node = $this->wrapNode($node, $resolver, $parsingState);
         }
     } elseif ($this->childrenEscapingEnabled && $node instanceof ObjectAccessorNode) {
         $node = $this->wrapNode($node, $resolver, $parsingState);
     }
     return $node;
 }
 /**
  * @param NodeInterface $node
  * @return bool
  */
 protected function isCaseNode(NodeInterface $node)
 {
     if ($node instanceof ViewHelperNode) {
         $viewHelperClassName = $node->getViewHelperClassName();
         return $viewHelperClassName === CaseViewHelper::class || $viewHelperClassName === OriginalCaseViewHelper::class;
     }
     return false;
 }
예제 #3
0
 /**
  * @param NodeInterface $node
  * @param RenderingContextInterface $renderingContext
  * @param boolean $cast
  * @return mixed
  */
 protected function evaluateChildNode(NodeInterface $node, RenderingContextInterface $renderingContext, $cast)
 {
     $output = $node->evaluate($renderingContext);
     if ($cast && is_object($output)) {
         if (!method_exists($output, '__toString')) {
             throw new Parser\Exception('Cannot cast object of type "' . get_class($output) . '" to string.', 1273753083);
         }
         $output = (string) $output;
     }
     return $output;
 }
예제 #4
0
 /**
  * @param NodeInterface $node
  * @return boolean
  */
 protected function isCaseNode(NodeInterface $node)
 {
     return $node instanceof ViewHelperNode && $node->getViewHelperClassName() === 'TYPO3Fluid\\Fluid\\ViewHelpers\\CaseViewHelper';
 }
예제 #5
0
 /**
  * Return the value associated to the syntax tree.
  *
  * @param RenderingContextInterface $renderingContext
  * @return number the value stored in this node/subtree.
  */
 public function evaluate(RenderingContextInterface $renderingContext)
 {
     return htmlspecialchars($this->node->evaluate($renderingContext), ENT_QUOTES);
 }
예제 #6
0
 /**
  * @param NodeInterface $node
  * @return array
  * @see convert()
  */
 public function convertListOfSubNodes(NodeInterface $node)
 {
     switch (count($node->getChildNodes())) {
         case 0:
             return array('initialization' => '', 'execution' => 'NULL');
         case 1:
             $childNode = current($node->getChildNodes());
             if ($childNode instanceof NodeInterface) {
                 return $this->convert($childNode);
             }
         default:
             $outputVariableName = $this->variableName('output');
             $initializationPhpCode = sprintf('%s = \'\';', $outputVariableName) . chr(10);
             foreach ($node->getChildNodes() as $childNode) {
                 $converted = $this->convert($childNode);
                 $initializationPhpCode .= $converted['initialization'] . chr(10);
                 $initializationPhpCode .= sprintf('%s .= %s;', $outputVariableName, $converted['execution']) . chr(10);
             }
             return array('initialization' => $initializationPhpCode, 'execution' => $outputVariableName);
     }
 }
예제 #7
0
 /**
  * @param NodeInterface $node
  * @return boolean
  */
 protected function isCaseNode(NodeInterface $node)
 {
     return $node instanceof ViewHelperNode && $node->getViewHelperClassName() === CaseViewHelper::class;
 }
 /**
  * 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 = new RootNode();
     foreach ($textParts as $part) {
         $matches = [];
         if (preg_match(self::PATTERN_MATCH_RESOURCE_URI, $part, $matches)) {
             $arguments = ['path' => new TextNode($matches['Path'])];
             if ($this->defaultPackageKey !== null) {
                 $arguments['package'] = new TextNode($this->defaultPackageKey);
             }
             if (isset($matches['Package']) && preg_match(Package::PATTERN_MATCH_PACKAGEKEY, $matches['Package'])) {
                 $arguments['package'] = new TextNode($matches['Package']);
             }
             $resourceUriNode = new ResourceUriNode($arguments, $parsingState);
             $node->addChildNode($resourceUriNode);
         } else {
             $textNode = new TextNode($part);
             $node->addChildNode($textNode);
         }
     }
     return $node;
 }