Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

remote.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 5.62 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 hosted remotely
018  */
019  class remote extends \phpbb\avatar\driver\driver
020  {
021      /**
022      * {@inheritdoc}
023      */
024      public function get_data($row)
025      {
026          return array(
027              'src' => $row['avatar'],
028              'width' => $row['avatar_width'],
029              'height' => $row['avatar_height'],
030          );
031      }
032   
033      /**
034      * {@inheritdoc}
035      */
036      public function prepare_form($request, $template, $user, $row, &$error)
037      {
038          $template->assign_vars(array(
039              'AVATAR_REMOTE_WIDTH' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_width']) ? $row['avatar_width'] : $request->variable('avatar_remote_width', 0),
040              'AVATAR_REMOTE_HEIGHT' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_height']) ? $row['avatar_height'] : $request->variable('avatar_remote_width', 0),
041              'AVATAR_REMOTE_URL' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar']) ? $row['avatar'] : '',
042          ));
043   
044          return true;
045      }
046   
047      /**
048      * {@inheritdoc}
049      */
050      public function process_form($request, $template, $user, $row, &$error)
051      {
052          $url = $request->variable('avatar_remote_url', '');
053          $width = $request->variable('avatar_remote_width', 0);
054          $height = $request->variable('avatar_remote_height', 0);
055   
056          if (empty($url))
057          {
058              return false;
059          }
060   
061          if (!preg_match('#^(http|https|ftp)://#i', $url))
062          {
063              $url = 'http://' . $url;
064          }
065   
066          if (!function_exists('validate_data'))
067          {
068              require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
069          }
070   
071          $validate_array = validate_data(
072              array(
073                  'url' => $url,
074              ),
075              array(
076                  'url' => array('string', true, 5, 255),
077              )
078          );
079   
080          $error = array_merge($error, $validate_array);
081   
082          if (!empty($error))
083          {
084              return false;
085          }
086   
087          // Check if this url looks alright
088          // This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible
089          if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.('. implode('|', $this->allowed_extensions) . ')$#i', $url))
090          {
091              $error[] = 'AVATAR_URL_INVALID';
092              return false;
093          }
094   
095          // Make sure getimagesize works...
096          if (function_exists('getimagesize'))
097          {
098              if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false))
099              {
100                  $error[] = 'UNABLE_GET_IMAGE_SIZE';
101                  return false;
102              }
103   
104              if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0))
105              {
106                  $error[] = 'AVATAR_NO_SIZE';
107                  return false;
108              }
109   
110              $width = ($width && $height) ? $width : $image_data[0];
111              $height = ($width && $height) ? $height : $image_data[1];
112          }
113   
114          if ($width <= 0 || $height <= 0)
115          {
116              $error[] = 'AVATAR_NO_SIZE';
117              return false;
118          }
119   
120          if (!class_exists('fileupload'))
121          {
122              include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext);
123          }
124   
125          $types = \fileupload::image_types();
126          $extension = strtolower(\filespec::get_extension($url));
127   
128          // Check if this is actually an image
129          if ($file_stream = @fopen($url, 'r'))
130          {
131              // Timeout after 1 second
132              stream_set_timeout($file_stream, 1);
133              // read some data to ensure headers are present
134              fread($file_stream, 1024);
135              $meta = stream_get_meta_data($file_stream);
136   
137              if (isset($meta['wrapper_data']['headers']) && is_array($meta['wrapper_data']['headers']))
138              {
139                  $headers = $meta['wrapper_data']['headers'];
140              }
141              else if (isset($meta['wrapper_data']) && is_array($meta['wrapper_data']))
142              {
143                  $headers = $meta['wrapper_data'];
144              }
145              else
146              {
147                  $headers = array();
148              }
149   
150              foreach ($headers as $header)
151              {
152                  $header = preg_split('/ /', $header, 2);
153                  if (strtr(strtolower(trim($header[0], ':')), '_', '-') === 'content-type')
154                  {
155                      if (strpos($header[1], 'image/') !== 0)
156                      {
157                          $error[] = 'AVATAR_URL_INVALID';
158                          fclose($file_stream);
159                          return false;
160                      }
161                      else
162                      {
163                          fclose($file_stream);
164                          break;
165                      }
166                  }
167              }
168          }
169          else
170          {
171              $error[] = 'AVATAR_URL_INVALID';
172              return false;
173          }
174   
175          if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]])))
176          {
177              if (!isset($types[$image_data[2]]))
178              {
179                  $error[] = 'UNABLE_GET_IMAGE_SIZE';
180              }
181              else
182              {
183                  $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension);
184              }
185   
186              return false;
187          }
188   
189          if ($this->config['avatar_max_width'] || $this->config['avatar_max_height'])
190          {
191              if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height'])
192              {
193                  $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height);
194                  return false;
195              }
196          }
197   
198          if ($this->config['avatar_min_width'] || $this->config['avatar_min_height'])
199          {
200              if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height'])
201              {
202                  $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height);
203                  return false;
204              }
205          }
206   
207          return array(
208              'avatar' => $url,
209              'avatar_width' => $width,
210              'avatar_height' => $height,
211          );
212      }
213   
214      /**
215      * {@inheritdoc}
216      */
217      public function get_template_name()
218      {
219          return 'ucp_avatar_options_remote.html';
220      }
221  }
222