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

SafeAnalysis.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.73 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of Twig.
 005   *
 006   * (c) 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  class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor
 013  {
 014      protected $data = array();
 015      protected $safeVars = array();
 016   
 017      public function setSafeVars($safeVars)
 018      {
 019          $this->safeVars = $safeVars;
 020      }
 021   
 022      public function getSafe(Twig_NodeInterface $node)
 023      {
 024          $hash = spl_object_hash($node);
 025          if (!isset($this->data[$hash])) {
 026              return;
 027          }
 028   
 029          foreach ($this->data[$hash] as $bucket) {
 030              if ($bucket['key'] !== $node) {
 031                  continue;
 032              }
 033   
 034              if (in_array('html_attr', $bucket['value'])) {
 035                  $bucket['value'][] = 'html';
 036              }
 037   
 038              return $bucket['value'];
 039          }
 040      }
 041   
 042      protected function setSafe(Twig_NodeInterface $node, array $safe)
 043      {
 044          $hash = spl_object_hash($node);
 045          if (isset($this->data[$hash])) {
 046              foreach ($this->data[$hash] as &$bucket) {
 047                  if ($bucket['key'] === $node) {
 048                      $bucket['value'] = $safe;
 049   
 050                      return;
 051                  }
 052              }
 053          }
 054          $this->data[$hash][] = array(
 055              'key' => $node,
 056              'value' => $safe,
 057          );
 058      }
 059   
 060      /**
 061       * {@inheritdoc}
 062       */
 063      protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
 064      {
 065          return $node;
 066      }
 067   
 068      /**
 069       * {@inheritdoc}
 070       */
 071      protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
 072      {
 073          if ($node instanceof Twig_Node_Expression_Constant) {
 074              // constants are marked safe for all
 075              $this->setSafe($node, array('all'));
 076          } elseif ($node instanceof Twig_Node_Expression_BlockReference) {
 077              // blocks are safe by definition
 078              $this->setSafe($node, array('all'));
 079          } elseif ($node instanceof Twig_Node_Expression_Parent) {
 080              // parent block is safe by definition
 081              $this->setSafe($node, array('all'));
 082          } elseif ($node instanceof Twig_Node_Expression_Conditional) {
 083              // intersect safeness of both operands
 084              $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3')));
 085              $this->setSafe($node, $safe);
 086          } elseif ($node instanceof Twig_Node_Expression_Filter) {
 087              // filter expression is safe when the filter is safe
 088              $name = $node->getNode('filter')->getAttribute('value');
 089              $args = $node->getNode('arguments');
 090              if (false !== $filter = $env->getFilter($name)) {
 091                  $safe = $filter->getSafe($args);
 092                  if (null === $safe) {
 093                      $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety());
 094                  }
 095                  $this->setSafe($node, $safe);
 096              } else {
 097                  $this->setSafe($node, array());
 098              }
 099          } elseif ($node instanceof Twig_Node_Expression_Function) {
 100              // function expression is safe when the function is safe
 101              $name = $node->getAttribute('name');
 102              $args = $node->getNode('arguments');
 103              $function = $env->getFunction($name);
 104              if (false !== $function) {
 105                  $this->setSafe($node, $function->getSafe($args));
 106              } else {
 107                  $this->setSafe($node, array());
 108              }
 109          } elseif ($node instanceof Twig_Node_Expression_MethodCall) {
 110              if ($node->getAttribute('safe')) {
 111                  $this->setSafe($node, array('all'));
 112              } else {
 113                  $this->setSafe($node, array());
 114              }
 115          } elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) {
 116              $name = $node->getNode('node')->getAttribute('name');
 117              // attributes on template instances are safe
 118              if ('_self' == $name || in_array($name, $this->safeVars)) {
 119                  $this->setSafe($node, array('all'));
 120              } else {
 121                  $this->setSafe($node, array());
 122              }
 123          } else {
 124              $this->setSafe($node, array());
 125          }
 126   
 127          return $node;
 128      }
 129   
 130      protected function intersectSafe(array $a = null, array $b = null)
 131      {
 132          if (null === $a || null === $b) {
 133              return array();
 134          }
 135   
 136          if (in_array('all', $a)) {
 137              return $b;
 138          }
 139   
 140          if (in_array('all', $b)) {
 141              return $a;
 142          }
 143   
 144          return array_intersect($a, $b);
 145      }
 146   
 147      /**
 148       * {@inheritdoc}
 149       */
 150      public function getPriority()
 151      {
 152          return 0;
 153      }
 154  }
 155