diff options
Diffstat (limited to 'phpBB/phpbb/avatar/driver')
| -rw-r--r-- | phpBB/phpbb/avatar/driver/driver.php | 41 | ||||
| -rw-r--r-- | phpBB/phpbb/avatar/driver/driver_interface.php (renamed from phpBB/phpbb/avatar/driver/interface.php) | 36 | ||||
| -rw-r--r-- | phpBB/phpbb/avatar/driver/gravatar.php | 18 | ||||
| -rw-r--r-- | phpBB/phpbb/avatar/driver/local.php | 24 | ||||
| -rw-r--r-- | phpBB/phpbb/avatar/driver/remote.php | 53 | ||||
| -rw-r--r-- | phpBB/phpbb/avatar/driver/upload.php | 24 |
6 files changed, 110 insertions, 86 deletions
diff --git a/phpBB/phpbb/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php index 29c58d4e62..dd55f09119 100644 --- a/phpBB/phpbb/avatar/driver/driver.php +++ b/phpBB/phpbb/avatar/driver/driver.php @@ -7,19 +7,13 @@ * */ -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} +namespace phpbb\avatar\driver; /** * Base class for avatar drivers * @package phpBB3 */ -abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface +abstract class driver implements \phpbb\avatar\driver\driver_interface { /** * Avatar driver name @@ -29,7 +23,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * Current board configuration - * @var phpbb_config + * @var \phpbb\config\config */ protected $config; @@ -46,8 +40,14 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface protected $php_ext; /** + * Path Helper + * @var \phpbb\path_helper + */ + protected $path_helper; + + /** * Cache driver - * @var phpbb_cache_driver_interface + * @var \phpbb\cache\driver\driver_interface */ protected $cache; @@ -69,17 +69,19 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * Construct a driver object * - * @param phpbb_config $config phpBB configuration - * @param phpbb_request $request Request object + * @param \phpbb\config\config $config phpBB configuration + * @param \phpbb\request\request $request Request object * @param string $phpbb_root_path Path to the phpBB root * @param string $php_ext PHP file extension - * @param phpbb_cache_driver_interface $cache Cache driver + * @param \phpbb_path_helper $path_helper phpBB path helper + * @param \phpbb\cache\driver\driver_interface $cache Cache driver */ - public function __construct(phpbb_config $config, $phpbb_root_path, $php_ext, phpbb_cache_driver_interface $cache = null) + public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\path_helper $path_helper, \phpbb\cache\driver\driver_interface $cache = null) { $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->path_helper = $path_helper; $this->cache = $cache; } @@ -110,17 +112,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc */ - public function get_template_name() - { - $driver = preg_replace('#^phpbb_avatar_driver_#', '', get_class($this)); - $template = "ucp_avatar_options_$driver.html"; - - return $template; - } - - /** - * @inheritdoc - */ public function get_name() { return $this->name; diff --git a/phpBB/phpbb/avatar/driver/interface.php b/phpBB/phpbb/avatar/driver/driver_interface.php index 3d62969aef..7f049469a2 100644 --- a/phpBB/phpbb/avatar/driver/interface.php +++ b/phpBB/phpbb/avatar/driver/driver_interface.php @@ -7,19 +7,13 @@ * */ -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} +namespace phpbb\avatar\driver; /** * Interface for avatar drivers * @package phpBB3 */ -interface phpbb_avatar_driver_interface +interface driver_interface { /** * Returns the name of the driver. @@ -32,7 +26,7 @@ interface phpbb_avatar_driver_interface * Get the avatar url and dimensions * * @param array $row User data or group data that has been cleaned with - * phpbb_avatar_manager::clean_row + * \phpbb\avatar\manager::clean_row * @return array Avatar data, must have keys src, width and height, e.g. * ['src' => '', 'width' => 0, 'height' => 0] */ @@ -41,9 +35,9 @@ interface phpbb_avatar_driver_interface /** * Returns custom html if it is needed for displaying this avatar * - * @param phpbb_user $user phpBB user object + * @param \phpbb\user $user phpBB user object * @param array $row User data or group data that has been cleaned with - * phpbb_avatar_manager::clean_row + * \phpbb\avatar\manager::clean_row * @param string $alt Alternate text for avatar image * * @return string HTML @@ -53,11 +47,11 @@ interface phpbb_avatar_driver_interface /** * Prepare form for changing the settings of this avatar * - * @param phpbb_request $request Request object - * @param phpbb_template $template Template object - * @param phpbb_user $user User object + * @param \phpbb\request\request $request Request object + * @param \phpbb\template\template $template Template object + * @param \phpbb\user $user User object * @param array $row User data or group data that has been cleaned with - * phpbb_avatar_manager::clean_row + * \phpbb\avatar\manager::clean_row * @param array &$error Reference to an error array that is filled by this * function. Key values can either be a string with a language key or * an array that will be passed to vsprintf() with the language key in @@ -70,7 +64,7 @@ interface phpbb_avatar_driver_interface /** * Prepare form for changing the acp settings of this avatar * - * @param phpbb_user $user phpBB user object + * @param \phpbb\user $user phpBB user object * * @return array Array of configuration options as consumed by acp_board. * The setting for enabling/disabling the avatar will be handled by @@ -81,11 +75,11 @@ interface phpbb_avatar_driver_interface /** * Process form data * - * @param phpbb_request $request Request object - * @param phpbb_template $template Template object - * @param phpbb_user $user User object + * @param \phpbb\request\request $request Request object + * @param \phpbb\template\template $template Template object + * @param \phpbb\user $user User object * @param array $row User data or group data that has been cleaned with - * phpbb_avatar_manager::clean_row + * \phpbb\avatar\manager::clean_row * @param array &$error Reference to an error array that is filled by this * function. Key values can either be a string with a language key or * an array that will be passed to vsprintf() with the language key in @@ -100,7 +94,7 @@ interface phpbb_avatar_driver_interface * Delete avatar * * @param array $row User data or group data that has been cleaned with - * phpbb_avatar_manager::clean_row + * \phpbb\avatar\manager::clean_row * * @return bool True if avatar has been deleted or there is no need to delete, * i.e. when the avatar is not hosted locally. diff --git a/phpBB/phpbb/avatar/driver/gravatar.php b/phpBB/phpbb/avatar/driver/gravatar.php index d559da1c0d..9f14b7f468 100644 --- a/phpBB/phpbb/avatar/driver/gravatar.php +++ b/phpBB/phpbb/avatar/driver/gravatar.php @@ -7,19 +7,13 @@ * */ -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} +namespace phpbb\avatar\driver; /** * Handles avatars hosted at gravatar.com * @package phpBB3 */ -class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver +class gravatar extends \phpbb\avatar\driver\driver { /** * The URL for the gravatar service @@ -153,6 +147,14 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver } /** + * @inheritdoc + */ + public function get_template_name() + { + return 'ucp_avatar_options_gravatar.html'; + } + + /** * Build gravatar URL for output on page * * @return string Gravatar URL diff --git a/phpBB/phpbb/avatar/driver/local.php b/phpBB/phpbb/avatar/driver/local.php index f4bcd4ce74..611a44cb3d 100644 --- a/phpBB/phpbb/avatar/driver/local.php +++ b/phpBB/phpbb/avatar/driver/local.php @@ -7,19 +7,13 @@ * */ -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} +namespace phpbb\avatar\driver; /** * Handles avatars selected from the board gallery * @package phpBB3 */ -class phpbb_avatar_driver_local extends phpbb_avatar_driver +class local extends \phpbb\avatar\driver\driver { /** * @inheritdoc @@ -27,7 +21,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function get_data($row) { return array( - 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], + 'src' => $this->path_helper->get_web_root_path() . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], 'width' => $row['avatar_width'], 'height' => $row['avatar_height'], ); @@ -141,10 +135,18 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver } /** + * @inheritdoc + */ + public function get_template_name() + { + return 'ucp_avatar_options_local.html'; + } + + /** * Get a list of avatars that are locally available * Results get cached for 24 hours (86400 seconds) * - * @param phpbb_user $user User object + * @param \phpbb\user $user User object * * @return array Array containing the locally available avatars */ @@ -157,7 +159,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver $avatar_list = array(); $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS), RecursiveIteratorIterator::SELF_FIRST); + $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS), \RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file_info) { $file_path = $file_info->getPath(); diff --git a/phpBB/phpbb/avatar/driver/remote.php b/phpBB/phpbb/avatar/driver/remote.php index d629a490fd..36623942df 100644 --- a/phpBB/phpbb/avatar/driver/remote.php +++ b/phpBB/phpbb/avatar/driver/remote.php @@ -7,19 +7,13 @@ * */ -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} +namespace phpbb\avatar\driver; /** * Handles avatars hosted remotely * @package phpBB3 */ -class phpbb_avatar_driver_remote extends phpbb_avatar_driver +class remote extends \phpbb\avatar\driver\driver { /** * @inheritdoc @@ -120,8 +114,39 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext); } - $types = fileupload::image_types(); - $extension = strtolower(filespec::get_extension($url)); + $types = \fileupload::image_types(); + $extension = strtolower(\filespec::get_extension($url)); + + // Check if this is actually an image + if ($file_stream = @fopen($url, 'r')) + { + // Timeout after 1 second + stream_set_timeout($file_stream, 1); + $meta = stream_get_meta_data($file_stream); + foreach ($meta['wrapper_data'] as $header) + { + $header = preg_split('/ /', $header, 2); + if (strtr(strtolower(trim($header[0], ':')), '_', '-') === 'content-type') + { + if (strpos($header[1], 'image/') !== 0) + { + $error[] = 'AVATAR_URL_INVALID'; + fclose($file_stream); + return false; + } + else + { + fclose($file_stream); + break; + } + } + } + } + else + { + $error[] = 'AVATAR_URL_INVALID'; + return false; + } if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) { @@ -161,4 +186,12 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver 'avatar_height' => $height, ); } + + /** + * @inheritdoc + */ + public function get_template_name() + { + return 'ucp_avatar_options_remote.html'; + } } diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index 685ac4f349..f77ef1332b 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -7,19 +7,13 @@ * */ -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} +namespace phpbb\avatar\driver; /** * Handles avatars uploaded to the board * @package phpBB3 */ -class phpbb_avatar_driver_upload extends phpbb_avatar_driver +class upload extends \phpbb\avatar\driver\driver { /** * @inheritdoc @@ -27,7 +21,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver public function get_data($row, $ignore_config = false) { return array( - 'src' => $this->phpbb_root_path . 'download/file.' . $this->php_ext . '?avatar=' . $row['avatar'], + 'src' => $this->path_helper->get_web_root_path() . 'download/file.' . $this->php_ext . '?avatar=' . $row['avatar'], 'width' => $row['avatar_width'], 'height' => $row['avatar_height'], ); @@ -66,7 +60,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext); } - $upload = new fileupload('AVATAR_', $this->allowed_extensions, $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); + $upload = new \fileupload('AVATAR_', $this->allowed_extensions, $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); $url = $request->variable('avatar_upload_url', ''); $upload_file = $request->file('avatar_upload_file'); @@ -153,7 +147,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver return array( 'allow_avatar_remote_upload'=> array('lang' => 'ALLOW_REMOTE_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'avatar_filesize' => array('lang' => 'MAX_FILESIZE', 'validate' => 'int:0', 'type' => 'number:0', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), - 'avatar_path' => array('lang' => 'AVATAR_STORAGE_PATH', 'validate' => 'rwpath', 'type' => 'text:20:255', 'explain' => true), + 'avatar_path' => array('lang' => 'AVATAR_STORAGE_PATH', 'validate' => 'rpath', 'type' => 'text:20:255', 'explain' => true), ); } @@ -174,6 +168,14 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver } /** + * @inheritdoc + */ + public function get_template_name() + { + return 'ucp_avatar_options_upload.html'; + } + + /** * Check if user is able to upload an avatar * * @return bool True if user can upload, false if not |
