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

upload.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 8.50 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\avatar\driver;
015   
016  /**
017  * Handles avatars uploaded to the board
018  */
019  class upload extends \phpbb\avatar\driver\driver
020  {
021      /**
022       * @var \phpbb\filesystem\filesystem_interface
023       */
024      protected $filesystem;
025   
026      /**
027      * @var \phpbb\event\dispatcher_interface
028      */
029      protected $dispatcher;
030   
031      /**
032       * @var \phpbb\files\factory
033       */
034      protected $files_factory;
035   
036      /**
037      * Construct a driver object
038      *
039      * @param \phpbb\config\config $config phpBB configuration
040      * @param string $phpbb_root_path Path to the phpBB root
041      * @param string $php_ext PHP file extension
042      * @param \phpbb\filesystem\filesystem_interface $filesystem phpBB filesystem helper
043      * @param \phpbb\path_helper $path_helper phpBB path helper
044      * @param \phpbb\event\dispatcher_interface $dispatcher phpBB Event dispatcher object
045      * @param \phpbb\files\factory $files_factory File classes factory
046      * @param \phpbb\cache\driver\driver_interface $cache Cache driver
047      */
048      public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\filesystem\filesystem_interface $filesystem, \phpbb\path_helper $path_helper, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\files\factory $files_factory, \phpbb\cache\driver\driver_interface $cache = null)
049      {
050          $this->config = $config;
051          $this->phpbb_root_path = $phpbb_root_path;
052          $this->php_ext = $php_ext;
053          $this->filesystem = $filesystem;
054          $this->path_helper = $path_helper;
055          $this->dispatcher = $dispatcher;
056          $this->files_factory = $files_factory;
057          $this->cache = $cache;
058      }
059   
060      /**
061      * {@inheritdoc}
062      */
063      public function get_data($row)
064      {
065          $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $this->path_helper->get_web_root_path();
066   
067          return array(
068              'src' => $root_path . 'download/file.' . $this->php_ext . '?avatar=' . $row['avatar'],
069              'width' => $row['avatar_width'],
070              'height' => $row['avatar_height'],
071          );
072      }
073   
074      /**
075      * {@inheritdoc}
076      */
077      public function prepare_form($request, $template, $user, $row, &$error)
078      {
079          if (!$this->can_upload())
080          {
081              return false;
082          }
083   
084          $template->assign_vars(array(
085              'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false,
086              'AVATAR_UPLOAD_SIZE' => $this->config['avatar_filesize'],
087          ));
088   
089          return true;
090      }
091   
092      /**
093      * {@inheritdoc}
094      */
095      public function process_form($request, $template, $user, $row, &$error)
096      {
097          if (!$this->can_upload())
098          {
099              return false;
100          }
101   
102          /** @var \phpbb\files\upload $upload */
103          $upload = $this->files_factory->get('upload')
104              ->set_error_prefix('AVATAR_')
105              ->set_allowed_extensions($this->allowed_extensions)
106              ->set_max_filesize($this->config['avatar_filesize'])
107              ->set_allowed_dimensions(
108                  $this->config['avatar_min_width'],
109                  $this->config['avatar_min_height'],
110                  $this->config['avatar_max_width'],
111                  $this->config['avatar_max_height'])
112              ->set_disallowed_content((isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false));
113   
114          $url = $request->variable('avatar_upload_url', '');
115          $upload_file = $request->file('avatar_upload_file');
116   
117          if (!empty($upload_file['name']))
118          {
119              $file = $upload->handle_upload('files.types.form', 'avatar_upload_file');
120          }
121          else if (!empty($this->config['allow_avatar_remote_upload']) && !empty($url))
122          {
123              if (!preg_match('#^(http|https|ftp)://#i', $url))
124              {
125                  $url = 'http://' . $url;
126              }
127   
128              if (!function_exists('validate_data'))
129              {
130                  require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
131              }
132   
133              $validate_array = validate_data(
134                  array(
135                      'url' => $url,
136                  ),
137                  array(
138                      'url' => array('string', true, 5, 255),
139                  )
140              );
141   
142              $error = array_merge($error, $validate_array);
143   
144              if (!empty($error))
145              {
146                  return false;
147              }
148   
149              $file = $upload->handle_upload('files.types.remote', $url);
150          }
151          else
152          {
153              return false;
154          }
155   
156          $prefix = $this->config['avatar_salt'] . '_';
157          $file->clean_filename('avatar', $prefix, $row['id']);
158   
159          // If there was an error during upload, then abort operation
160          if (sizeof($file->error))
161          {
162              $file->remove();
163              $error = $file->error;
164              return false;
165          }
166   
167          // Calculate new destination
168          $destination = $this->config['avatar_path'];
169   
170          // Adjust destination path (no trailing slash)
171          if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
172          {
173              $destination = substr($destination, 0, -1);
174          }
175   
176          $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
177          if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
178          {
179              $destination = '';
180          }
181   
182          $filedata = array(
183              'filename'            => $file->get('filename'),
184              'filesize'            => $file->get('filesize'),
185              'mimetype'            => $file->get('mimetype'),
186              'extension'            => $file->get('extension'),
187              'physical_filename'    => $file->get('realname'),
188              'real_filename'        => $file->get('uploadname'),
189          );
190   
191          /**
192          * Before moving new file in place (and eventually overwriting the existing avatar with the newly uploaded avatar)
193          *
194          * @event core.avatar_driver_upload_move_file_before
195          * @var    array    filedata            Array containing uploaded file data
196          * @var    string    destination            Destination directory where the file is going to be moved
197          * @var    string    prefix                Prefix for the avatar filename
198          * @var    array    row                    Array with avatar row data
199          * @var    array    error                Array of errors, if filled in by this event file will not be moved
200          * @since 3.1.6-RC1
201          * @changed 3.1.9-RC1 Added filedata
202          */
203          $vars = array(
204              'filedata',
205              'destination',
206              'prefix',
207              'row',
208              'error',
209          );
210          extract($this->dispatcher->trigger_event('core.avatar_driver_upload_move_file_before', compact($vars)));
211   
212          unset($filedata);
213   
214          if (!sizeof($error))
215          {
216              // Move file and overwrite any existing image
217              $file->move_file($destination, true);
218          }
219   
220          // If there was an error during move, then clean up leftovers
221          $error = array_merge($error, $file->error);
222          if (sizeof($error))
223          {
224              $file->remove();
225              return false;
226          }
227   
228          // Delete current avatar if not overwritten
229          $ext = substr(strrchr($row['avatar'], '.'), 1);
230          if ($ext && $ext !== $file->get('extension'))
231          {
232              $this->delete($row);
233          }
234   
235          return array(
236              'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'),
237              'avatar_width' => $file->get('width'),
238              'avatar_height' => $file->get('height'),
239          );
240      }
241   
242      /**
243      * {@inheritdoc}
244      */
245      public function prepare_form_acp($user)
246      {
247          return array(
248              'allow_avatar_remote_upload'=> array('lang' => 'ALLOW_REMOTE_UPLOAD', 'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
249              'avatar_filesize'        => array('lang' => 'MAX_FILESIZE',            'validate' => 'int:0',    'type' => 'number:0', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
250              'avatar_path'            => array('lang' => 'AVATAR_STORAGE_PATH',    'validate' => 'rpath',    'type' => 'text:20:255', 'explain' => true),
251          );
252      }
253   
254      /**
255      * {@inheritdoc}
256      */
257      public function delete($row)
258      {
259   
260          $error = array();
261          $destination = $this->config['avatar_path'];
262          $prefix = $this->config['avatar_salt'] . '_';
263          $ext = substr(strrchr($row['avatar'], '.'), 1);
264          $filename = $this->phpbb_root_path . $destination . '/' . $prefix . $row['id'] . '.' . $ext;
265   
266          /**
267          * Before deleting an existing avatar
268          *
269          * @event core.avatar_driver_upload_delete_before
270          * @var    string    destination            Destination directory where the file is going to be deleted
271          * @var    string    prefix                Prefix for the avatar filename
272          * @var    array    row                    Array with avatar row data
273          * @var    array    error                Array of errors, if filled in by this event file will not be deleted
274          * @since 3.1.6-RC1
275          */
276          $vars = array(
277              'destination',
278              'prefix',
279              'row',
280              'error',
281          );
282          extract($this->dispatcher->trigger_event('core.avatar_driver_upload_delete_before', compact($vars)));
283   
284          if (!sizeof($error) && file_exists($filename))
285          {
286              @unlink($filename);
287          }
288   
289          return true;
290      }
291   
292      /**
293      * {@inheritdoc}
294      */
295      public function get_template_name()
296      {
297          return 'ucp_avatar_options_upload.html';
298      }
299   
300      /**
301      * Check if user is able to upload an avatar
302      *
303      * @return bool True if user can upload, false if not
304      */
305      protected function can_upload()
306      {
307          return (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && $this->filesystem->is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on'));
308      }
309  }
310