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

base_extractor.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 4.37 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\db\extractor;
015   
016  use phpbb\db\extractor\exception\invalid_format_exception;
017  use phpbb\db\extractor\exception\extractor_not_initialized_exception;
018   
019  /**
020   * Abstract base class for database extraction
021   */
022  abstract class base_extractor implements extractor_interface
023  {
024      /**
025       * @var    string    phpBB root path
026       */
027      protected $phpbb_root_path;
028   
029      /**
030       * @var    \phpbb\request\request_interface
031       */
032      protected $request;
033   
034      /**
035       * @var    \phpbb\db\driver\driver_interface
036       */
037      protected $db;
038   
039      /**
040       * @var    bool
041       */
042      protected $download;
043   
044      /**
045       * @var    bool
046       */
047      protected $store;
048   
049      /**
050       * @var    int
051       */
052      protected $time;
053   
054      /**
055       * @var    string
056       */
057      protected $format;
058   
059      /**
060       * @var    resource
061       */
062      protected $fp;
063   
064      /**
065       * @var string
066       */
067      protected $write;
068   
069      /**
070       * @var string
071       */
072      protected $close;
073   
074      /**
075       * @var bool
076       */
077      protected $run_comp;
078   
079      /**
080       * @var bool
081       */
082      protected $is_initialized;
083   
084      /**
085       * Constructor
086       *
087       * @param string $phpbb_root_path
088       * @param \phpbb\request\request_interface $request
089       * @param \phpbb\db\driver\driver_interface $db
090       */
091      public function __construct($phpbb_root_path, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db)
092      {
093          $this->phpbb_root_path    = $phpbb_root_path;
094          $this->request            = $request;
095          $this->db                = $db;
096          $this->fp                = null;
097   
098          $this->is_initialized   = false;
099      }
100   
101      /**
102      * {@inheritdoc}
103      */
104      public function init_extractor($format, $filename, $time, $download = false, $store = false)
105      {
106          $this->download            = $download;
107          $this->store            = $store;
108          $this->time                = $time;
109          $this->format            = $format;
110   
111          switch ($format)
112          {
113              case 'text':
114                  $ext = '.sql';
115                  $open = 'fopen';
116                  $this->write = 'fwrite';
117                  $this->close = 'fclose';
118                  $mimetype = 'text/x-sql';
119              break;
120              case 'bzip2':
121                  $ext = '.sql.bz2';
122                  $open = 'bzopen';
123                  $this->write = 'bzwrite';
124                  $this->close = 'bzclose';
125                  $mimetype = 'application/x-bzip2';
126              break;
127              case 'gzip':
128                  $ext = '.sql.gz';
129                  $open = 'gzopen';
130                  $this->write = 'gzwrite';
131                  $this->close = 'gzclose';
132                  $mimetype = 'application/x-gzip';
133              break;
134              default:
135                  throw new invalid_format_exception();
136              break;
137          }
138   
139          if ($download === true)
140          {
141              $name = $filename . $ext;
142              header('Cache-Control: private, no-cache');
143              header("Content-Type: $mimetype; name=\"$name\"");
144              header("Content-disposition: attachment; filename=$name");
145   
146              switch ($format)
147              {
148                  case 'bzip2':
149                      ob_start();
150                  break;
151   
152                  case 'gzip':
153                      if (strpos($this->request->header('Accept-Encoding'), 'gzip') !== false && strpos(strtolower($this->request->header('User-Agent')), 'msie') === false)
154                      {
155                          ob_start('ob_gzhandler');
156                      }
157                      else
158                      {
159                          $this->run_comp = true;
160                      }
161                  break;
162              }
163          }
164   
165          if ($store === true)
166          {
167              $file = $this->phpbb_root_path . 'store/' . $filename . $ext;
168   
169              $this->fp = $open($file, 'w');
170   
171              if (!$this->fp)
172              {
173                  trigger_error('FILE_WRITE_FAIL', E_USER_ERROR);
174              }
175          }
176   
177          $this->is_initialized = true;
178      }
179   
180      /**
181      * {@inheritdoc}
182      */
183      public function write_end()
184      {
185          static $close;
186   
187          if (!$this->is_initialized)
188          {
189              throw new extractor_not_initialized_exception();
190          }
191   
192          if ($this->store)
193          {
194              if ($close === null)
195              {
196                  $close = $this->close;
197              }
198              $close($this->fp);
199          }
200   
201          // bzip2 must be written all the way at the end
202          if ($this->download && $this->format === 'bzip2')
203          {
204              $c = ob_get_clean();
205              echo bzcompress($c);
206          }
207      }
208   
209      /**
210      * {@inheritdoc}
211      */
212      public function flush($data)
213      {
214          static $write;
215   
216          if (!$this->is_initialized)
217          {
218              throw new extractor_not_initialized_exception();
219          }
220   
221          if ($this->store === true)
222          {
223              if ($write === null)
224              {
225                  $write = $this->write;
226              }
227              $write($this->fp, $data);
228          }
229   
230          if ($this->download === true)
231          {
232              if ($this->format === 'bzip2' || $this->format === 'text' || ($this->format === 'gzip' && !$this->run_comp))
233              {
234                  echo $data;
235              }
236   
237              // we can write the gzip data as soon as we get it
238              if ($this->format === 'gzip')
239              {
240                  if ($this->run_comp)
241                  {
242                      echo gzencode($data);
243                  }
244                  else
245                  {
246                      ob_flush();
247                      flush();
248                  }
249              }
250          }
251      }
252  }
253