diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-11-27 14:55:05 +0100 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-11-27 14:55:24 +0100 |
commit | 33f4d267ef9a3b65a1fbda82afa13ecc486b5c80 (patch) | |
tree | 2e19c6d0b72144d50197c01dcc2ad000913553ef /phpBB/phpbb/avatar | |
parent | 0d4bf3ff45a76dcb763c76502944aa7bf78b690b (diff) | |
parent | 125e76f9aa83141534387a965e8373c9b9cd5c4d (diff) | |
download | forums-33f4d267ef9a3b65a1fbda82afa13ecc486b5c80.tar forums-33f4d267ef9a3b65a1fbda82afa13ecc486b5c80.tar.gz forums-33f4d267ef9a3b65a1fbda82afa13ecc486b5c80.tar.bz2 forums-33f4d267ef9a3b65a1fbda82afa13ecc486b5c80.tar.xz forums-33f4d267ef9a3b65a1fbda82afa13ecc486b5c80.zip |
Merge branch 'develop' of https://github.com/phpbb/phpbb3 into ticket/11842
Conflicts:
phpBB/includes/acp/acp_groups.php
Diffstat (limited to 'phpBB/phpbb/avatar')
-rw-r--r-- | phpBB/phpbb/avatar/driver/driver.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/avatar/driver/driver_interface.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/avatar/driver/gravatar.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/avatar/driver/local.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/avatar/driver/remote.php | 39 | ||||
-rw-r--r-- | phpBB/phpbb/avatar/driver/upload.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/avatar/manager.php | 76 |
7 files changed, 68 insertions, 87 deletions
diff --git a/phpBB/phpbb/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php index 206df86543..d360614122 100644 --- a/phpBB/phpbb/avatar/driver/driver.php +++ b/phpBB/phpbb/avatar/driver/driver.php @@ -10,14 +10,6 @@ namespace phpbb\avatar\driver; /** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** * Base class for avatar drivers * @package phpBB3 */ diff --git a/phpBB/phpbb/avatar/driver/driver_interface.php b/phpBB/phpbb/avatar/driver/driver_interface.php index d9540c19db..7f049469a2 100644 --- a/phpBB/phpbb/avatar/driver/driver_interface.php +++ b/phpBB/phpbb/avatar/driver/driver_interface.php @@ -10,14 +10,6 @@ namespace phpbb\avatar\driver; /** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** * Interface for avatar drivers * @package phpBB3 */ diff --git a/phpBB/phpbb/avatar/driver/gravatar.php b/phpBB/phpbb/avatar/driver/gravatar.php index 3ad783932e..d64f4da734 100644 --- a/phpBB/phpbb/avatar/driver/gravatar.php +++ b/phpBB/phpbb/avatar/driver/gravatar.php @@ -10,14 +10,6 @@ namespace phpbb\avatar\driver; /** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** * Handles avatars hosted at gravatar.com * @package phpBB3 */ diff --git a/phpBB/phpbb/avatar/driver/local.php b/phpBB/phpbb/avatar/driver/local.php index 0686ffe79a..f6acc6e636 100644 --- a/phpBB/phpbb/avatar/driver/local.php +++ b/phpBB/phpbb/avatar/driver/local.php @@ -10,14 +10,6 @@ namespace phpbb\avatar\driver; /** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** * Handles avatars selected from the board gallery * @package phpBB3 */ diff --git a/phpBB/phpbb/avatar/driver/remote.php b/phpBB/phpbb/avatar/driver/remote.php index 1aa638dfe5..22d50c703e 100644 --- a/phpBB/phpbb/avatar/driver/remote.php +++ b/phpBB/phpbb/avatar/driver/remote.php @@ -10,14 +10,6 @@ namespace phpbb\avatar\driver; /** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** * Handles avatars hosted remotely * @package phpBB3 */ @@ -125,6 +117,37 @@ class remote extends \phpbb\avatar\driver\driver $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]]))) { if (!isset($types[$image_data[2]])) diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index bda872df7a..822c40af98 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -10,14 +10,6 @@ namespace phpbb\avatar\driver; /** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** * Handles avatars uploaded to the board * @package phpBB3 */ diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index c28380a401..6ce924d2eb 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -10,14 +10,6 @@ namespace phpbb\avatar; /** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** * @package avatar */ class manager @@ -42,12 +34,6 @@ class manager protected $avatar_drivers; /** - * Service container object - * @var object - */ - protected $container; - - /** * Default avatar data row * @var array */ @@ -63,13 +49,27 @@ class manager * * @param \phpbb\config\config $config phpBB configuration * @param array $avatar_drivers Avatar drivers passed via the service container - * @param object $container Container object */ - public function __construct(\phpbb\config\config $config, $avatar_drivers, $container) + public function __construct(\phpbb\config\config $config, $avatar_drivers) { $this->config = $config; - $this->avatar_drivers = $avatar_drivers; - $this->container = $container; + $this->register_avatar_drivers($avatar_drivers); + } + + /** + * Register avatar drivers + * + * @param array $avatar_drivers Service collection of avatar drivers + */ + protected function register_avatar_drivers($avatar_drivers) + { + if (!empty($avatar_drivers)) + { + foreach ($avatar_drivers as $driver) + { + $this->avatar_drivers[$driver->get_name()] = $driver; + } + } } /** @@ -112,7 +112,7 @@ class manager * There is no need to handle invalid avatar types as the following code * will cause a ServiceNotFoundException if the type does not exist */ - $driver = $this->container->get($avatar_type); + $driver = $this->avatar_drivers[$avatar_type]; return $driver; } @@ -178,14 +178,16 @@ class manager } /** - * Strip out user_ and group_ prefixes from keys + * Strip out user_, group_, or other prefixes from array keys * - * @param array $row User data or group data + * @param array $row User data or group data + * @param string $prefix Prefix of data keys (e.g. user), should not include the trailing underscore * - * @return array User data or group data with keys that have been - * stripped from the preceding "user_" or "group_" + * @return array User or group data with keys that have been + * stripped from the preceding "user_" or "group_" + * Also the group id is prefixed with g, when the prefix group is removed. */ - static public function clean_row($row) + static public function clean_row($row, $prefix = '') { // Upon creation of a user/group $row might be empty if (empty($row)) @@ -193,23 +195,19 @@ class manager return self::$default_row; } - $keys = array_keys($row); - $values = array_values($row); - - $keys = array_map(array('\phpbb\avatar\manager', 'strip_prefix'), $keys); + $output = array(); + foreach ($row as $key => $value) + { + $key = preg_replace("#^(?:{$prefix}_)#", '', $key); + $output[$key] = $value; + } - return array_combine($keys, $values); - } + if ($prefix === 'group' && isset($output['id'])) + { + $output['id'] = 'g' . $output['id']; + } - /** - * Strip prepending user_ or group_ prefix from key - * - * @param string Array key - * @return string Key that has been stripped from its prefix - */ - static protected function strip_prefix($key) - { - return preg_replace('#^(?:user_|group_)#', '', $key); + return $output; } /** |