Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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:58 - Dateigröße: 4.87 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 extends Twig_BaseNodeVisitor
 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       * {@inheritdoc}
 033       */
 034      protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
 035      {
 036          if ($node instanceof Twig_Node_Module) {
 037              if ($env->hasExtension('escaper') && $defaultStrategy = $env->getExtension('escaper')->getDefaultStrategy($node->getAttribute('filename'))) {
 038                  $this->defaultStrategy = $defaultStrategy;
 039              }
 040              $this->safeVars = array();
 041              $this->blocks = array();
 042          } elseif ($node instanceof Twig_Node_AutoEscape) {
 043              $this->statusStack[] = $node->getAttribute('value');
 044          } elseif ($node instanceof Twig_Node_Block) {
 045              $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
 046          } elseif ($node instanceof Twig_Node_Import) {
 047              $this->safeVars[] = $node->getNode('var')->getAttribute('name');
 048          }
 049   
 050          return $node;
 051      }
 052   
 053      /**
 054       * {@inheritdoc}
 055       */
 056      protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
 057      {
 058          if ($node instanceof Twig_Node_Module) {
 059              $this->defaultStrategy = false;
 060              $this->safeVars = array();
 061              $this->blocks = array();
 062          } elseif ($node instanceof Twig_Node_Expression_Filter) {
 063              return $this->preEscapeFilterNode($node, $env);
 064          } elseif ($node instanceof Twig_Node_Print) {
 065              return $this->escapePrintNode($node, $env, $this->needEscaping($env));
 066          }
 067   
 068          if ($node instanceof Twig_Node_AutoEscape || $node instanceof Twig_Node_Block) {
 069              array_pop($this->statusStack);
 070          } elseif ($node instanceof Twig_Node_BlockReference) {
 071              $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env);
 072          }
 073   
 074          return $node;
 075      }
 076   
 077      protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type)
 078      {
 079          if (false === $type) {
 080              return $node;
 081          }
 082   
 083          $expression = $node->getNode('expr');
 084   
 085          if ($this->isSafeFor($type, $expression, $env)) {
 086              return $node;
 087          }
 088   
 089          $class = get_class($node);
 090   
 091          return new $class(
 092              $this->getEscaperFilter($type, $expression),
 093              $node->getLine()
 094          );
 095      }
 096   
 097      protected function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env)
 098      {
 099          $name = $filter->getNode('filter')->getAttribute('value');
 100   
 101          $type = $env->getFilter($name)->getPreEscape();
 102          if (null === $type) {
 103              return $filter;
 104          }
 105   
 106          $node = $filter->getNode('node');
 107          if ($this->isSafeFor($type, $node, $env)) {
 108              return $filter;
 109          }
 110   
 111          $filter->setNode('node', $this->getEscaperFilter($type, $node));
 112   
 113          return $filter;
 114      }
 115   
 116      protected function isSafeFor($type, Twig_NodeInterface $expression, $env)
 117      {
 118          $safe = $this->safeAnalysis->getSafe($expression);
 119   
 120          if (null === $safe) {
 121              if (null === $this->traverser) {
 122                  $this->traverser = new Twig_NodeTraverser($env, array($this->safeAnalysis));
 123              }
 124   
 125              $this->safeAnalysis->setSafeVars($this->safeVars);
 126   
 127              $this->traverser->traverse($expression);
 128              $safe = $this->safeAnalysis->getSafe($expression);
 129          }
 130   
 131          return in_array($type, $safe) || in_array('all', $safe);
 132      }
 133   
 134      protected function needEscaping(Twig_Environment $env)
 135      {
 136          if (count($this->statusStack)) {
 137              return $this->statusStack[count($this->statusStack) - 1];
 138          }
 139   
 140          return $this->defaultStrategy ? $this->defaultStrategy : false;
 141      }
 142   
 143      protected function getEscaperFilter($type, Twig_NodeInterface $node)
 144      {
 145          $line = $node->getLine();
 146          $name = new Twig_Node_Expression_Constant('escape', $line);
 147          $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)));
 148   
 149          return new Twig_Node_Expression_Filter($node, $name, $args, $line);
 150      }
 151   
 152      /**
 153       * {@inheritdoc}
 154       */
 155      public function getPriority()
 156      {
 157          return 0;
 158      }
 159  }
 160