Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

base.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 5.01 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\cache\driver;
015   
016  abstract class base implements \phpbb\cache\driver\driver_interface
017  {
018      var $vars = array();
019      var $is_modified = false;
020   
021      var $sql_rowset = array();
022      var $sql_row_pointer = array();
023      var $cache_dir = '';
024   
025      /**
026      * {@inheritDoc}
027      */
028      function purge()
029      {
030          // Purge all phpbb cache files
031          try
032          {
033              $iterator = new \DirectoryIterator($this->cache_dir);
034          }
035          catch (\Exception $e)
036          {
037              return;
038          }
039   
040          foreach ($iterator as $fileInfo)
041          {
042              if ($fileInfo->isDot())
043              {
044                  continue;
045              }
046              $filename = $fileInfo->getFilename();
047              if ($fileInfo->isDir())
048              {
049                  $this->remove_dir($fileInfo->getPathname());
050              }
051              else if (strpos($filename, 'container_') === 0 ||
052                  strpos($filename, 'autoload_') === 0 ||
053                  strpos($filename, 'url_matcher') === 0 ||
054                  strpos($filename, 'url_generator') === 0 ||
055                  strpos($filename, 'sql_') === 0 ||
056                  strpos($filename, 'data_') === 0)
057              {
058                  $this->remove_file($fileInfo->getPathname());
059              }
060          }
061   
062          unset($this->vars);
063          unset($this->sql_rowset);
064          unset($this->sql_row_pointer);
065   
066          if (function_exists('opcache_reset'))
067          {
068              @opcache_reset();
069          }
070   
071          $this->vars = array();
072          $this->sql_rowset = array();
073          $this->sql_row_pointer = array();
074   
075          $this->is_modified = false;
076      }
077   
078      /**
079      * {@inheritDoc}
080      */
081      function unload()
082      {
083          $this->save();
084          unset($this->vars);
085          unset($this->sql_rowset);
086          unset($this->sql_row_pointer);
087   
088          $this->vars = array();
089          $this->sql_rowset = array();
090          $this->sql_row_pointer = array();
091      }
092   
093      /**
094      * {@inheritDoc}
095      */
096      function sql_load($query)
097      {
098          // Remove extra spaces and tabs
099          $query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
100          $query_id = md5($query);
101   
102          if (($result = $this->_read('sql_' . $query_id)) === false)
103          {
104              return false;
105          }
106   
107          $this->sql_rowset[$query_id] = $result;
108          $this->sql_row_pointer[$query_id] = 0;
109   
110          return $query_id;
111      }
112   
113      /**
114      * {@inheritDoc}
115      */
116      function sql_exists($query_id)
117      {
118          $query_id = $this->clean_query_id($query_id);
119          return isset($this->sql_rowset[$query_id]);
120      }
121   
122      /**
123      * {@inheritDoc}
124      */
125      function sql_fetchrow($query_id)
126      {
127          $query_id = $this->clean_query_id($query_id);
128          if ($this->sql_row_pointer[$query_id] < count($this->sql_rowset[$query_id]))
129          {
130              return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
131          }
132   
133          return false;
134      }
135   
136      /**
137      * {@inheritDoc}
138      */
139      function sql_fetchfield($query_id, $field)
140      {
141          $query_id = $this->clean_query_id($query_id);
142          if ($this->sql_row_pointer[$query_id] < count($this->sql_rowset[$query_id]))
143          {
144              return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++][$field] : false;
145          }
146   
147          return false;
148      }
149   
150      /**
151      * {@inheritDoc}
152      */
153      function sql_rowseek($rownum, $query_id)
154      {
155          $query_id = $this->clean_query_id($query_id);
156          if ($rownum >= count($this->sql_rowset[$query_id]))
157          {
158              return false;
159          }
160   
161          $this->sql_row_pointer[$query_id] = $rownum;
162          return true;
163      }
164   
165      /**
166      * {@inheritDoc}
167      */
168      function sql_freeresult($query_id)
169      {
170          $query_id = $this->clean_query_id($query_id);
171          if (!isset($this->sql_rowset[$query_id]))
172          {
173              return false;
174          }
175   
176          unset($this->sql_rowset[$query_id]);
177          unset($this->sql_row_pointer[$query_id]);
178   
179          return true;
180      }
181   
182      /**
183      * Removes/unlinks file
184      *
185      * @param string $filename Filename to remove
186      * @param bool $check Check file permissions
187      * @return bool True if the file was successfully removed, otherwise false
188      */
189      function remove_file($filename, $check = false)
190      {
191          global $phpbb_filesystem;
192   
193          if ($check && !$phpbb_filesystem->is_writable($this->cache_dir))
194          {
195              // E_USER_ERROR - not using language entry - intended.
196              trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR);
197          }
198   
199          return @unlink($filename);
200      }
201   
202      /**
203      * Remove directory
204      *
205      * @param string $dir Directory to remove
206      *
207      * @return null
208      */
209      protected function remove_dir($dir)
210      {
211          try
212          {
213              $iterator = new \DirectoryIterator($dir);
214          }
215          catch (\Exception $e)
216          {
217              return;
218          }
219   
220          foreach ($iterator as $fileInfo)
221          {
222              if ($fileInfo->isDot())
223              {
224                  continue;
225              }
226   
227              if ($fileInfo->isDir())
228              {
229                  $this->remove_dir($fileInfo->getPathname());
230              }
231              else
232              {
233                  $this->remove_file($fileInfo->getPathname());
234              }
235          }
236   
237          @rmdir($dir);
238      }
239   
240      /**
241       * {@inheritDoc}
242       */
243      public function clean_query_id($query_id)
244      {
245          // Some DBMS functions accept/return objects and/or resources instead of integer identifier
246          // Attempting to cast object to int will throw error, hence correctly handle all cases
247          if (is_resource($query_id))
248          {
249              return function_exists('get_resource_id') ? get_resource_id($query_id) : (int) $query_id;
250          }
251          else
252          {
253              return is_object($query_id) ? spl_object_id($query_id) : $query_id;
254          }
255      }
256  }
257