[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\avatar\driver; 15 16 /** 17 * Handles avatars hosted remotely 18 */ 19 class remote extends \phpbb\avatar\driver\driver 20 { 21 /** 22 * {@inheritdoc} 23 */ 24 public function get_data($row) 25 { 26 return array( 27 'src' => $row['avatar'], 28 'width' => $row['avatar_width'], 29 'height' => $row['avatar_height'], 30 ); 31 } 32 33 /** 34 * {@inheritdoc} 35 */ 36 public function prepare_form($request, $template, $user, $row, &$error) 37 { 38 $template->assign_vars(array( 39 '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', ''), 40 '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', ''), 41 'AVATAR_REMOTE_URL' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar']) ? $row['avatar'] : '', 42 )); 43 44 return true; 45 } 46 47 /** 48 * {@inheritdoc} 49 */ 50 public function process_form($request, $template, $user, $row, &$error) 51 { 52 $url = $request->variable('avatar_remote_url', ''); 53 $width = $request->variable('avatar_remote_width', 0); 54 $height = $request->variable('avatar_remote_height', 0); 55 56 if (empty($url)) 57 { 58 return false; 59 } 60 61 if (!preg_match('#^(http|https|ftp)://#i', $url)) 62 { 63 $url = 'http://' . $url; 64 } 65 66 if (!function_exists('validate_data')) 67 { 68 require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); 69 } 70 71 $validate_array = validate_data( 72 array( 73 'url' => $url, 74 ), 75 array( 76 'url' => array('string', true, 5, 255), 77 ) 78 ); 79 80 $error = array_merge($error, $validate_array); 81 82 if (!empty($error)) 83 { 84 return false; 85 } 86 87 // Check if this url looks alright 88 // Do not allow specifying the port (see RFC 3986) or IP addresses 89 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) || 90 preg_match('@^(http|https|ftp)://[^/:?#]+:[0-9]+[/:?#]@i', $url) || 91 preg_match('#^(http|https|ftp)://(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])#i', $url) || 92 preg_match('#^(http|https|ftp)://(?:(?:(?:[\dA-F]{1,4}:){6}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:::(?:[\dA-F]{1,4}:){0,5}(?:[\dA-F]{1,4}(?::[\dA-F]{1,4})?|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:):(?:[\dA-F]{1,4}:){4}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,2}:(?:[\dA-F]{1,4}:){3}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,3}:(?:[\dA-F]{1,4}:){2}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,4}:(?:[\dA-F]{1,4}:)(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,5}:(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,6}:[\dA-F]{1,4})|(?:(?:[\dA-F]{1,4}:){1,7}:)|(?:::))#i', $url)) 93 { 94 $error[] = 'AVATAR_URL_INVALID'; 95 return false; 96 } 97 98 // Make sure getimagesize works... 99 if (function_exists('getimagesize')) 100 { 101 if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) 102 { 103 $error[] = 'UNABLE_GET_IMAGE_SIZE'; 104 return false; 105 } 106 107 if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0)) 108 { 109 $error[] = 'AVATAR_NO_SIZE'; 110 return false; 111 } 112 113 $width = ($width && $height) ? $width : $image_data[0]; 114 $height = ($width && $height) ? $height : $image_data[1]; 115 } 116 117 if ($width <= 0 || $height <= 0) 118 { 119 $error[] = 'AVATAR_NO_SIZE'; 120 return false; 121 } 122 123 if (!class_exists('fileupload')) 124 { 125 include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext); 126 } 127 128 $types = \fileupload::image_types(); 129 $extension = strtolower(\filespec::get_extension($url)); 130 131 // Check if this is actually an image 132 if ($file_stream = @fopen($url, 'r')) 133 { 134 // Timeout after 1 second 135 stream_set_timeout($file_stream, 1); 136 // read some data to ensure headers are present 137 fread($file_stream, 1024); 138 $meta = stream_get_meta_data($file_stream); 139 140 if (isset($meta['wrapper_data']['headers']) && is_array($meta['wrapper_data']['headers'])) 141 { 142 $headers = $meta['wrapper_data']['headers']; 143 } 144 else if (isset($meta['wrapper_data']) && is_array($meta['wrapper_data'])) 145 { 146 $headers = $meta['wrapper_data']; 147 } 148 else 149 { 150 $headers = array(); 151 } 152 153 foreach ($headers as $header) 154 { 155 $header = preg_split('/ /', $header, 2); 156 if (strtr(strtolower(trim($header[0], ':')), '_', '-') === 'content-type') 157 { 158 if (strpos($header[1], 'image/') !== 0) 159 { 160 $error[] = 'AVATAR_URL_INVALID'; 161 fclose($file_stream); 162 return false; 163 } 164 else 165 { 166 fclose($file_stream); 167 break; 168 } 169 } 170 } 171 } 172 else 173 { 174 $error[] = 'AVATAR_URL_INVALID'; 175 return false; 176 } 177 178 if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) 179 { 180 if (!isset($types[$image_data[2]])) 181 { 182 $error[] = 'UNABLE_GET_IMAGE_SIZE'; 183 } 184 else 185 { 186 $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension); 187 } 188 189 return false; 190 } 191 192 if ($this->config['avatar_max_width'] || $this->config['avatar_max_height']) 193 { 194 if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height']) 195 { 196 $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); 197 return false; 198 } 199 } 200 201 if ($this->config['avatar_min_width'] || $this->config['avatar_min_height']) 202 { 203 if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height']) 204 { 205 $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); 206 return false; 207 } 208 } 209 210 return array( 211 'avatar' => $url, 212 'avatar_width' => $width, 213 'avatar_height' => $height, 214 ); 215 } 216 217 /** 218 * {@inheritdoc} 219 */ 220 public function get_template_name() 221 { 222 return 'ucp_avatar_options_remote.html'; 223 } 224 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |