Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Escaper.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 5.24 KiB


001  <?php
002   
003  /*
004   * This file is part of Twig.
005   *
006   * (c) 2009 Fabien Potencier
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  /**
013   * Twig_NodeVisitor_Escaper implements output escaping.
014   *
015   * @author Fabien Potencier <fabien@symfony.com>
016   */
017  class Twig_NodeVisitor_Escaper implements Twig_NodeVisitorInterface
018  {
019      protected $statusStack = array();
020      protected $blocks = array();
021      protected $safeAnalysis;
022      protected $traverser;
023      protected $defaultStrategy = false;
024      protected $safeVars = array();
025   
026      public function __construct()
027      {
028          $this->safeAnalysis = new Twig_NodeVisitor_SafeAnalysis();
029      }
030   
031      /**
032       * Called before child nodes are visited.
033       *
034       * @param Twig_NodeInterface $node The node to visit
035       * @param Twig_Environment   $env  The Twig environment instance
036       *
037       * @return Twig_NodeInterface The modified node
038       */
039      public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
040      {
041          if ($node instanceof Twig_Node_Module) {
042              if ($env->hasExtension('escaper') && $defaultStrategy = $env->getExtension('escaper')->getDefaultStrategy($node->getAttribute('filename'))) {
043                  $this->defaultStrategy = $defaultStrategy;
044              }
045              $this->safeVars = array();
046          } elseif ($node instanceof Twig_Node_AutoEscape) {
047              $this->statusStack[] = $node->getAttribute('value');
048          } elseif ($node instanceof Twig_Node_Block) {
049              $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
050          } elseif ($node instanceof Twig_Node_Import) {
051              $this->safeVars[] = $node->getNode('var')->getAttribute('name');
052          }
053   
054          return $node;
055      }
056   
057      /**
058       * Called after child nodes are visited.
059       *
060       * @param Twig_NodeInterface $node The node to visit
061       * @param Twig_Environment   $env  The Twig environment instance
062       *
063       * @return Twig_NodeInterface The modified node
064       */
065      public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
066      {
067          if ($node instanceof Twig_Node_Module) {
068              $this->defaultStrategy = false;
069              $this->safeVars = array();
070          } elseif ($node instanceof Twig_Node_Expression_Filter) {
071              return $this->preEscapeFilterNode($node, $env);
072          } elseif ($node instanceof Twig_Node_Print) {
073              return $this->escapePrintNode($node, $env, $this->needEscaping($env));
074          }
075   
076          if ($node instanceof Twig_Node_AutoEscape || $node instanceof Twig_Node_Block) {
077              array_pop($this->statusStack);
078          } elseif ($node instanceof Twig_Node_BlockReference) {
079              $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env);
080          }
081   
082          return $node;
083      }
084   
085      protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type)
086      {
087          if (false === $type) {
088              return $node;
089          }
090   
091          $expression = $node->getNode('expr');
092   
093          if ($this->isSafeFor($type, $expression, $env)) {
094              return $node;
095          }
096   
097          $class = get_class($node);
098   
099          return new $class(
100              $this->getEscaperFilter($type, $expression),
101              $node->getLine()
102          );
103      }
104   
105      protected function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env)
106      {
107          $name = $filter->getNode('filter')->getAttribute('value');
108   
109          $type = $env->getFilter($name)->getPreEscape();
110          if (null === $type) {
111              return $filter;
112          }
113   
114          $node = $filter->getNode('node');
115          if ($this->isSafeFor($type, $node, $env)) {
116              return $filter;
117          }
118   
119          $filter->setNode('node', $this->getEscaperFilter($type, $node));
120   
121          return $filter;
122      }
123   
124      protected function isSafeFor($type, Twig_NodeInterface $expression, $env)
125      {
126          $safe = $this->safeAnalysis->getSafe($expression);
127   
128          if (null === $safe) {
129              if (null === $this->traverser) {
130                  $this->traverser = new Twig_NodeTraverser($env, array($this->safeAnalysis));
131              }
132   
133              $this->safeAnalysis->setSafeVars($this->safeVars);
134   
135              $this->traverser->traverse($expression);
136              $safe = $this->safeAnalysis->getSafe($expression);
137          }
138   
139          return in_array($type, $safe) || in_array('all', $safe);
140      }
141   
142      protected function needEscaping(Twig_Environment $env)
143      {
144          if (count($this->statusStack)) {
145              return $this->statusStack[count($this->statusStack) - 1];
146          }
147   
148          return $this->defaultStrategy ? $this->defaultStrategy : false;
149      }
150   
151      protected function getEscaperFilter($type, Twig_NodeInterface $node)
152      {
153          $line = $node->getLine();
154          $name = new Twig_Node_Expression_Constant('escape', $line);
155          $args = new Twig_Node(array(new Twig_Node_Expression_Constant((string) $type, $line), new Twig_Node_Expression_Constant(null, $line), new Twig_Node_Expression_Constant(true, $line)));
156   
157          return new Twig_Node_Expression_Filter($node, $name, $args, $line);
158      }
159   
160      /**
161       * {@inheritdoc}
162       */
163      public function getPriority()
164      {
165          return 0;
166      }
167  }
168