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. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
remote.php
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', ''),
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', ''),
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 // Get image dimensions
096 if (($width <= 0 || $height <= 0) && (($image_data = $this->imagesize->getImageSize($url)) === false))
097 {
098 $error[] = 'UNABLE_GET_IMAGE_SIZE';
099 return false;
100 }
101
102 if (!empty($image_data) && ($image_data['width'] <= 0 || $image_data['height'] <= 0))
103 {
104 $error[] = 'AVATAR_NO_SIZE';
105 return false;
106 }
107
108 $width = ($width && $height) ? $width : $image_data['width'];
109 $height = ($width && $height) ? $height : $image_data['height'];
110
111 if ($width <= 0 || $height <= 0)
112 {
113 $error[] = 'AVATAR_NO_SIZE';
114 return false;
115 }
116
117 $types = \phpbb\files\upload::image_types();
118 $extension = strtolower(\phpbb\files\filespec::get_extension($url));
119
120 // Check if this is actually an image
121 if ($file_stream = @fopen($url, 'r'))
122 {
123 // Timeout after 1 second
124 stream_set_timeout($file_stream, 1);
125 // read some data to ensure headers are present
126 fread($file_stream, 1024);
127 $meta = stream_get_meta_data($file_stream);
128
129 if (isset($meta['wrapper_data']['headers']) && is_array($meta['wrapper_data']['headers']))
130 {
131 $headers = $meta['wrapper_data']['headers'];
132 }
133 else if (isset($meta['wrapper_data']) && is_array($meta['wrapper_data']))
134 {
135 $headers = $meta['wrapper_data'];
136 }
137 else
138 {
139 $headers = array();
140 }
141
142 foreach ($headers as $header)
143 {
144 $header = preg_split('/ /', $header, 2);
145 if (strtr(strtolower(trim($header[0], ':')), '_', '-') === 'content-type')
146 {
147 if (strpos($header[1], 'image/') !== 0)
148 {
149 $error[] = 'AVATAR_URL_INVALID';
150 fclose($file_stream);
151 return false;
152 }
153 else
154 {
155 fclose($file_stream);
156 break;
157 }
158 }
159 }
160 }
161 else
162 {
163 $error[] = 'AVATAR_URL_INVALID';
164 return false;
165 }
166
167 if (!empty($image_data) && (!isset($types[$image_data['type']]) || !in_array($extension, $types[$image_data['type']])))
168 {
169 if (!isset($types[$image_data['type']]))
170 {
171 $error[] = 'UNABLE_GET_IMAGE_SIZE';
172 }
173 else
174 {
175 $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data['type']][0], $extension);
176 }
177
178 return false;
179 }
180
181 if ($this->config['avatar_max_width'] || $this->config['avatar_max_height'])
182 {
183 if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height'])
184 {
185 $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);
186 return false;
187 }
188 }
189
190 if ($this->config['avatar_min_width'] || $this->config['avatar_min_height'])
191 {
192 if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height'])
193 {
194 $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);
195 return false;
196 }
197 }
198
199 return array(
200 'avatar' => $url,
201 'avatar_width' => $width,
202 'avatar_height' => $height,
203 );
204 }
205
206 /**
207 * {@inheritdoc}
208 */
209 public function get_template_name()
210 {
211 return 'ucp_avatar_options_remote.html';
212 }
213 }
214