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

Ssi.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 5.92 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
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  namespace Symfony\Component\HttpKernel\HttpCache;
013   
014  use Symfony\Component\HttpFoundation\Request;
015  use Symfony\Component\HttpFoundation\Response;
016  use Symfony\Component\HttpKernel\HttpKernelInterface;
017   
018  /**
019   * Ssi implements the SSI capabilities to Request and Response instances.
020   *
021   * @author Sebastian Krebs <krebs.seb@gmail.com>
022   */
023  class Ssi implements SurrogateInterface
024  {
025      private $contentTypes;
026      private $phpEscapeMap = array(
027          array('<?', '<%', '<s', '<S'),
028          array('<?php echo "<?"; ?>', '<?php echo "<%"; ?>', '<?php echo "<s"; ?>', '<?php echo "<S"; ?>'),
029      );
030   
031      /**
032       * Constructor.
033       *
034       * @param array $contentTypes An array of content-type that should be parsed for SSI information
035       *                            (default: text/html, text/xml, application/xhtml+xml, and application/xml)
036       */
037      public function __construct(array $contentTypes = array('text/html', 'text/xml', 'application/xhtml+xml', 'application/xml'))
038      {
039          $this->contentTypes = $contentTypes;
040      }
041   
042      /**
043       * {@inheritdoc}
044       */
045      public function getName()
046      {
047          return 'ssi';
048      }
049   
050      /**
051       * {@inheritdoc}
052       */
053      public function createCacheStrategy()
054      {
055          return new ResponseCacheStrategy();
056      }
057   
058      /**
059       * {@inheritdoc}
060       */
061      public function hasSurrogateCapability(Request $request)
062      {
063          if (null === $value = $request->headers->get('Surrogate-Capability')) {
064              return false;
065          }
066   
067          return false !== strpos($value, 'SSI/1.0');
068      }
069   
070      /**
071       * {@inheritdoc}
072       */
073      public function addSurrogateCapability(Request $request)
074      {
075          $current = $request->headers->get('Surrogate-Capability');
076          $new = 'symfony2="SSI/1.0"';
077   
078          $request->headers->set('Surrogate-Capability', $current ? $current.', '.$new : $new);
079      }
080   
081      /**
082       * {@inheritdoc}
083       */
084      public function addSurrogateControl(Response $response)
085      {
086          if (false !== strpos($response->getContent(), '<!--#include')) {
087              $response->headers->set('Surrogate-Control', 'content="SSI/1.0"');
088          }
089      }
090   
091      /**
092       * {@inheritdoc}
093       */
094      public function needsParsing(Response $response)
095      {
096          if (!$control = $response->headers->get('Surrogate-Control')) {
097              return false;
098          }
099   
100          return (bool) preg_match('#content="[^"]*SSI/1.0[^"]*"#', $control);
101      }
102   
103      /**
104       * {@inheritdoc}
105       */
106      public function renderIncludeTag($uri, $alt = null, $ignoreErrors = true, $comment = '')
107      {
108          return sprintf('<!--#include virtual="%s" -->', $uri);
109      }
110   
111      /**
112       * {@inheritdoc}
113       */
114      public function process(Request $request, Response $response)
115      {
116          $type = $response->headers->get('Content-Type');
117          if (empty($type)) {
118              $type = 'text/html';
119          }
120   
121          $parts = explode(';', $type);
122          if (!in_array($parts[0], $this->contentTypes)) {
123              return $response;
124          }
125   
126          // we don't use a proper XML parser here as we can have SSI tags in a plain text response
127          $content = $response->getContent();
128   
129          $chunks = preg_split('#<!--\#include\s+(.*?)\s*-->#', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
130          $chunks[0] = str_replace($this->phpEscapeMap[0], $this->phpEscapeMap[1], $chunks[0]);
131   
132          $i = 1;
133          while (isset($chunks[$i])) {
134              $options = array();
135              preg_match_all('/(virtual)="([^"]*?)"/', $chunks[$i], $matches, PREG_SET_ORDER);
136              foreach ($matches as $set) {
137                  $options[$set[1]] = $set[2];
138              }
139   
140              if (!isset($options['virtual'])) {
141                  throw new \RuntimeException('Unable to process an SSI tag without a "virtual" attribute.');
142              }
143   
144              $chunks[$i] = sprintf('<?php echo $this->surrogate->handle($this, %s, \'\', false) ?>'."\n",
145                  var_export($options['virtual'], true)
146              );
147              ++$i;
148              $chunks[$i] = str_replace($this->phpEscapeMap[0], $this->phpEscapeMap[1], $chunks[$i]);
149              ++$i;
150          }
151          $content = implode('', $chunks);
152   
153          $response->setContent($content);
154          $response->headers->set('X-Body-Eval', 'SSI');
155   
156          // remove SSI/1.0 from the Surrogate-Control header
157          if ($response->headers->has('Surrogate-Control')) {
158              $value = $response->headers->get('Surrogate-Control');
159              if ('content="SSI/1.0"' == $value) {
160                  $response->headers->remove('Surrogate-Control');
161              } elseif (preg_match('#,\s*content="SSI/1.0"#', $value)) {
162                  $response->headers->set('Surrogate-Control', preg_replace('#,\s*content="SSI/1.0"#', '', $value));
163              } elseif (preg_match('#content="SSI/1.0",\s*#', $value)) {
164                  $response->headers->set('Surrogate-Control', preg_replace('#content="SSI/1.0",\s*#', '', $value));
165              }
166          }
167      }
168   
169      /**
170       * {@inheritdoc}
171       */
172      public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors)
173      {
174          $subRequest = Request::create($uri, 'get', array(), $cache->getRequest()->cookies->all(), array(), $cache->getRequest()->server->all());
175   
176          try {
177              $response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
178   
179              if (!$response->isSuccessful()) {
180                  throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $subRequest->getUri(), $response->getStatusCode()));
181              }
182   
183              return $response->getContent();
184          } catch (\Exception $e) {
185              if ($alt) {
186                  return $this->handle($cache, $alt, '', $ignoreErrors);
187              }
188   
189              if (!$ignoreErrors) {
190                  throw $e;
191              }
192          }
193      }
194  }
195