Esempio n. 1
0
 public function visit(Twig_Node $node)
 {
     // autoescape?
     if ($node instanceof Twig_Node_AutoEscape) {
         $this->statusStack[] = $node->getValue();
         $node = $this->visitDeep($node);
         array_pop($this->statusStack);
         // remove the node
         return $node;
     }
     if (!$node instanceof Twig_Node_Print) {
         return $this->visitDeep($node);
     }
     if (false === $this->needEscaping()) {
         return $node;
     }
     $expression = $node->getExpression();
     // don't escape if escape has already been called
     // or if we want the safe string
     if ($expression instanceof Twig_Node_Expression_Filter && ($expression->hasFilter('escape') || $expression->hasFilter('safe'))) {
         return $node;
     }
     // escape
     if ($expression instanceof Twig_Node_Expression_Filter) {
         $expression->appendFilter(array('escape', array()));
         return $node;
     } else {
         return new Twig_Node_Print(new Twig_Node_Expression_Filter($expression, array(array('escape', array())), $node->getLine()), $node->getLine());
     }
 }
Esempio n. 2
0
 public function enterNode(Twig_Node $node, Twig_Environment $env)
 {
     if ($node instanceof Twig_Node_AutoEscape) {
         $this->statusStack[] = $node->getValue();
     } elseif ($node instanceof Twig_Node_Print && true === $this->needEscaping($env)) {
         return $this->escapeNode($node, $env);
     } elseif ($node instanceof Twig_Node_Block) {
         $this->statusStack[] = isset($this->blocks[$node->getName()]) ? $this->blocks[$node->getName()] : $this->needEscaping($env);
     }
     return $node;
 }