Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

asset.php

Zuletzt modifiziert: 01.05.2026, 11:25 - Dateigröße: 4.55 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\template;
 015   
 016  class asset
 017  {
 018      protected $components = array();
 019   
 020      /** @var \phpbb\path_helper **/
 021      protected $path_helper;
 022   
 023      /** @var \phpbb\filesystem\filesystem */
 024      protected $filesystem;
 025   
 026      /**
 027      * Constructor
 028      *
 029      * @param string $url URL
 030      * @param \phpbb\path_helper $path_helper Path helper object
 031      * @param \phpbb\filesystem\filesystem $filesystem
 032      */
 033      public function __construct($url, \phpbb\path_helper $path_helper, \phpbb\filesystem\filesystem $filesystem)
 034      {
 035          $this->path_helper = $path_helper;
 036          $this->filesystem = $filesystem;
 037   
 038          $this->set_url($url);
 039      }
 040   
 041      /**
 042      * Set URL
 043      *
 044      * @param string $url URL
 045      */
 046      public function set_url($url)
 047      {
 048          $this->components = parse_url($url);
 049      }
 050   
 051      /**
 052      * Convert URL components into string
 053      *
 054      * @param array $components URL components
 055      * @return string URL
 056      */
 057      protected function join_url($components)
 058      {
 059          $path = '';
 060          if (isset($components['scheme']))
 061          {
 062              $path = $components['scheme'] === '' ? '//' : $components['scheme'] . '://';
 063          }
 064   
 065          if (isset($components['user']) || isset($components['pass']))
 066          {
 067              if ($path === '' && !isset($components['port']))
 068              {
 069                  $path = '//';
 070              }
 071              $path .= $components['user'];
 072              if (isset($components['pass']))
 073              {
 074                  $path .= ':' . $components['pass'];
 075              }
 076              $path .= '@';
 077          }
 078   
 079          if (isset($components['host']))
 080          {
 081              if ($path === '' && !isset($components['port']))
 082              {
 083                  $path = '//';
 084              }
 085              $path .= $components['host'];
 086              if (isset($components['port']))
 087              {
 088                  $path .= ':' . $components['port'];
 089              }
 090          }
 091   
 092          if (isset($components['path']))
 093          {
 094              $path .= $components['path'];
 095          }
 096   
 097          if (isset($components['query']))
 098          {
 099              $path .= '?' . $components['query'];
 100          }
 101   
 102          if (isset($components['fragment']))
 103          {
 104              $path .= '#' . $components['fragment'];
 105          }
 106   
 107          return $path;
 108      }
 109   
 110      /**
 111      * Get URL
 112      *
 113      * @return string URL
 114      */
 115      public function get_url()
 116      {
 117          return $this->path_helper->update_web_root_path($this->join_url($this->components));
 118      }
 119   
 120      /**
 121      * Checks if URL is local and relative
 122      *
 123      * @return boolean True if URL is local and relative
 124      */
 125      public function is_relative()
 126      {
 127          if (empty($this->components) || !isset($this->components['path']))
 128          {
 129              // Invalid URL
 130              return false;
 131          }
 132          return !isset($this->components['scheme']) && !isset($this->components['host']) && substr($this->components['path'], 0, 1) !== '/';
 133      }
 134   
 135      /**
 136      * Get path component of current URL
 137      *
 138      * @return string Path
 139      */
 140      public function get_path()
 141      {
 142          return isset($this->components['path']) ? $this->components['path'] : '';
 143      }
 144   
 145      /**
 146      * Set path component
 147      *
 148      * @param string $path Path component
 149      * @param boolean $urlencode If true, parts of path should be encoded with rawurlencode()
 150      */
 151      public function set_path($path, $urlencode = false)
 152      {
 153          // Since 1.7.0 Twig returns the real path of the file. We need it to be relative.
 154          $real_root_path = $this->filesystem->realpath($this->path_helper->get_phpbb_root_path()) . DIRECTORY_SEPARATOR;
 155   
 156          // If the asset is under the phpBB root path we need to remove its path and then prepend $phpbb_root_path
 157          if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path)
 158          {
 159              $path = $this->path_helper->get_phpbb_root_path() . str_replace('\\', '/', substr($path, strlen($real_root_path)));
 160          }
 161          else
 162          {
 163              // Else we make the path relative to the current working directory
 164              $real_root_path = $this->filesystem->realpath('.') . DIRECTORY_SEPARATOR;
 165              if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path)
 166              {
 167                  $path = str_replace('\\', '/', substr($path, strlen($real_root_path)));
 168              }
 169          }
 170   
 171          if ($urlencode)
 172          {
 173              $paths = explode('/', $path);
 174              foreach ($paths as &$dir)
 175              {
 176                  $dir = rawurlencode($dir);
 177              }
 178              $path = implode('/', $paths);
 179          }
 180   
 181          $this->components['path'] = $path;
 182      }
 183   
 184      /**
 185      * Add assets_version parameter to URL.
 186      * Parameter will not be added if assets_version already exists in URL
 187      *
 188      * @param string $version Version
 189      */
 190      public function add_assets_version($version)
 191      {
 192          if (!isset($this->components['query']))
 193          {
 194              $this->components['query'] = 'assets_version=' . $version;
 195              return;
 196          }
 197          $query = $this->components['query'];
 198          if (!preg_match('/(^|[&;])assets_version=/', $query))
 199          {
 200              $this->components['query'] = $query . '&amp;assets_version=' . $version;
 201          }
 202      }
 203  }
 204