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

asset.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 4.82 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          if (version_compare(PHP_VERSION, '5.4.7') < 0 && substr($url, 0, 2) === '//')
049          {
050              // Workaround for PHP 5.4.6 and older bug #62844 - add fake scheme and then remove it
051              $this->components = parse_url('http:' . $url);
052              $this->components['scheme'] = '';
053              return;
054          }
055          $this->components = parse_url($url);
056      }
057   
058      /**
059      * Convert URL components into string
060      *
061      * @param array $components URL components
062      * @return string URL
063      */
064      protected function join_url($components)
065      {
066          $path = '';
067          if (isset($components['scheme']))
068          {
069              $path = $components['scheme'] === '' ? '//' : $components['scheme'] . '://';
070          }
071   
072          if (isset($components['user']) || isset($components['pass']))
073          {
074              if ($path === '' && !isset($components['port']))
075              {
076                  $path = '//';
077              }
078              $path .= $components['user'];
079              if (isset($components['pass']))
080              {
081                  $path .= ':' . $components['pass'];
082              }
083              $path .= '@';
084          }
085   
086          if (isset($components['host']))
087          {
088              if ($path === '' && !isset($components['port']))
089              {
090                  $path = '//';
091              }
092              $path .= $components['host'];
093              if (isset($components['port']))
094              {
095                  $path .= ':' . $components['port'];
096              }
097          }
098   
099          if (isset($components['path']))
100          {
101              $path .= $components['path'];
102          }
103   
104          if (isset($components['query']))
105          {
106              $path .= '?' . $components['query'];
107          }
108   
109          if (isset($components['fragment']))
110          {
111              $path .= '#' . $components['fragment'];
112          }
113   
114          return $path;
115      }
116   
117      /**
118      * Get URL
119      *
120      * @return string URL
121      */
122      public function get_url()
123      {
124          return $this->path_helper->update_web_root_path($this->join_url($this->components));
125      }
126   
127      /**
128      * Checks if URL is local and relative
129      *
130      * @return boolean True if URL is local and relative
131      */
132      public function is_relative()
133      {
134          if (empty($this->components) || !isset($this->components['path']))
135          {
136              // Invalid URL
137              return false;
138          }
139          return !isset($this->components['scheme']) && !isset($this->components['host']) && substr($this->components['path'], 0, 1) !== '/';
140      }
141   
142      /**
143      * Get path component of current URL
144      *
145      * @return string Path
146      */
147      public function get_path()
148      {
149          return isset($this->components['path']) ? $this->components['path'] : '';
150      }
151   
152      /**
153      * Set path component
154      *
155      * @param string $path Path component
156      * @param boolean $urlencode If true, parts of path should be encoded with rawurlencode()
157      */
158      public function set_path($path, $urlencode = false)
159      {
160          // Since 1.7.0 Twig returns the real path of the file. We need it to be relative.
161          $real_root_path = $this->filesystem->realpath($this->path_helper->get_phpbb_root_path()) . DIRECTORY_SEPARATOR;
162   
163          // If the asset is under the phpBB root path we need to remove its path and then prepend $phpbb_root_path
164          if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path)
165          {
166              $path = $this->path_helper->get_phpbb_root_path() . str_replace('\\', '/', substr($path, strlen($real_root_path)));
167          }
168          else
169          {
170              // Else we make the path relative to the current working directory
171              $real_root_path = $this->filesystem->realpath('.') . DIRECTORY_SEPARATOR;
172              if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path)
173              {
174                  $path = str_replace('\\', '/', substr($path, strlen($real_root_path)));
175              }
176          }
177   
178          if ($urlencode)
179          {
180              $paths = explode('/', $path);
181              foreach ($paths as &$dir)
182              {
183                  $dir = rawurlencode($dir);
184              }
185              $path = implode('/', $paths);
186          }
187   
188          $this->components['path'] = $path;
189      }
190   
191      /**
192      * Add assets_version parameter to URL.
193      * Parameter will not be added if assets_version already exists in URL
194      *
195      * @param string $version Version
196      */
197      public function add_assets_version($version)
198      {
199          if (!isset($this->components['query']))
200          {
201              $this->components['query'] = 'assets_version=' . $version;
202              return;
203          }
204          $query = $this->components['query'];
205          if (!preg_match('/(^|[&;])assets_version=/', $query))
206          {
207              $this->components['query'] = $query . '&amp;assets_version=' . $version;
208          }
209      }
210  }
211