From 4c699e0d0acc0aafab37e36206a92b1919282dac Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 17 Apr 2011 19:29:28 -0700 Subject: [PATCH 001/138] [feature/avatars] Modularized Avatars A modularized avatar system that easily allows plugins to be created for various avatar services, such as Gravatar. This inital commit includes module support and is backwards compatible with 3.0 avatars, but does notcontain ACP or UCP modules for manipulating new avatars. PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatars/avatar_base.php | 75 +++++++++++++ phpBB/includes/functions_display.php | 128 +++++++++++++++++++--- phpBB/includes/mcp/mcp_notes.php | 2 +- phpBB/includes/mcp/mcp_warn.php | 4 +- phpBB/includes/ucp/ucp_groups.php | 2 +- phpBB/includes/ucp/ucp_pm_viewmessage.php | 2 +- phpBB/includes/ucp/ucp_profile.php | 2 +- phpBB/memberlist.php | 7 +- phpBB/viewtopic.php | 4 +- 11 files changed, 198 insertions(+), 32 deletions(-) create mode 100644 phpBB/includes/avatars/avatar_base.php diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 607254adb5..9ad157f78a 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -553,7 +553,7 @@ class acp_groups $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : ''; $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : ''; - $avatar_img = (!empty($group_row['group_avatar'])) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : ''; + $avatar_img = (!empty($group_row['group_avatar'])) ? get_group_avatar($group_row) : ''; $display_gallery = (isset($_POST['display_gallery'])) ? true : false; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 97f4b1b5fd..390e421a51 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1715,7 +1715,7 @@ class acp_users } // Generate users avatar - $avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height'], 'USER_AVATAR', true) : ''; + $avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row, 'USER_AVATAR', true) : ''; $display_gallery = (isset($_POST['display_gallery'])) ? true : false; $avatar_select = basename(request_var('avatar_select', '')); diff --git a/phpBB/includes/avatars/avatar_base.php b/phpBB/includes/avatars/avatar_base.php new file mode 100644 index 0000000000..c84a6e8a7f --- /dev/null +++ b/phpBB/includes/avatars/avatar_base.php @@ -0,0 +1,75 @@ +user_row = $user_row; + } + + /** + * Get the avatar url and dimensions + * + * @param $ignore_config Whether $user or global avatar visibility settings + * should be ignored + * @return array Avatar data + */ + public function get_data($ignore_config = false) + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + + /** + * Returns custom html for displaying this avatar. + * Only called if $custom_html is true. + * + * @param $ignore_config Whether $user or global avatar visibility settings + * should be ignored + * @return string HTML + */ + public function get_custom_html($ignore_config = false) + { + return ''; + } +} diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 9335cabc15..eba123be9d 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1272,52 +1272,144 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank /** * Get user avatar * -* @param string $avatar Users assigned avatar name -* @param int $avatar_type Type of avatar -* @param string $avatar_width Width of users avatar -* @param string $avatar_height Height of users avatar +* @param array $user_row Row from the users table * @param string $alt Optional language string for alt tag within image, can be a language key or text * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP * -* @return string Avatar image +* @return string Avatar html */ -function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false) +function get_user_avatar(&$user_row, $alt = 'USER_AVATAR', $ignore_config = false) { - global $user, $config, $phpbb_root_path, $phpEx; + global $user, $config, $cache, $phpbb_root_path, $phpEx; - if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config)) + if (!$config['allow_avatar'] && !$ignore_config) { return ''; } - $avatar_img = ''; - - switch ($avatar_type) + $avatar_data = array( + 'src' => $user_row['user_avatar'], + 'width' => $user_row['user_avatar_width'], + 'height' => $user_row['user_avatar_height'], + ); + + switch ($user_row['user_avatar_type']) { case AVATAR_UPLOAD: + // Compatibility with old avatars if (!$config['allow_avatar_upload'] && !$ignore_config) { - return ''; + $avatar_data['src'] = ''; + } + else + { + $avatar_data['src'] = $phpbb_root_path . "download/file.$phpEx?avatar=" . $avatar_data['src']; + $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); } - $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar="; break; case AVATAR_GALLERY: + // Compatibility with old avatars if (!$config['allow_avatar_local'] && !$ignore_config) { - return ''; + $avatar_data['src'] = ''; + } + else + { + $avatar_data['src'] = $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_data['src']; + $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); } - $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/'; break; case AVATAR_REMOTE: + // Compatibility with old avatars if (!$config['allow_avatar_remote'] && !$ignore_config) { - return ''; + $avatar_data['src'] = ''; + } + else + { + $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); } break; + + default: + $class = 'phpbb_avatar_' . $user_row['user_avatar_type']; + + if (!class_exists($class)) + { + $avatar_types = $cache->get('avatar_types'); + + if (empty($avatar_types)) + { + $avatar_types = array(); + + if ($dh = @opendir($phpbb_root_path . 'includes/avatars')) + { + while ($file = @readdir($dh)) + { + if (preg_match("/avatar_(.*)\.$phpEx/", $file, $match)) + { + $avatar_types[] = $match[1]; + } + } + + @closedir($dh); + + sort($avatar_types); + $cache->put('avatar_types', $avatar_types); + } + } + + if (in_array($user_row['user_avatar_type'], $avatar_types)) + { + require_once($phpbb_root_path . 'includes/avatars/avatar_' . $user_row['user_avatar_type'] . '.' . $phpEx); + } + } + + $avatar = new $class($user_row); + + if ($avatar->custom_html) + { + return $avatar->get_custom_html($ignore_config); + } + + $avatar_data = $avatar->get_data($ignore_config); + + break; } - $avatar_img .= $avatar; - return '' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . ''; + $html = ''; + + if (!empty($avatar_data['src'])) + { + $html = ''; + } + + return $html; +} + +/** +* Get group avatar +* +* @param array $group_row Row from the groups table +* @param string $alt Optional language string for alt tag within image, can be a language key or text +* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP +* +* @return string Avatar html +*/ +function get_group_avatar(&$group_row, $alt = 'GROUP_AVATAR', $ignore_config = false) +{ + // Kind of abusing this functionality... + $avatar_row = array( + 'user_avatar' => $group_row['group_avatar'], + 'user_avatar_type' => $group_row['group_avatar_type'], + 'user_avatar_width' => $group_row['group_avatar_width'], + 'user_avatar_height' => $group_row['group_avatar_height'], + ); + + return get_user_avatar($group_row, $alt, $ignore_config); } diff --git a/phpBB/includes/mcp/mcp_notes.php b/phpBB/includes/mcp/mcp_notes.php index 99dbb8d86d..fe5be5dc0b 100644 --- a/phpBB/includes/mcp/mcp_notes.php +++ b/phpBB/includes/mcp/mcp_notes.php @@ -179,7 +179,7 @@ class mcp_notes } $rank_title = $rank_img = ''; - $avatar_img = get_user_avatar($userrow['user_avatar'], $userrow['user_avatar_type'], $userrow['user_avatar_width'], $userrow['user_avatar_height']); + $avatar_img = get_user_avatar($userrow); $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_DATE'], 'c' => $user->lang['SORT_IP'], 'd' => $user->lang['SORT_ACTION']); diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php index d8e655000f..3af021565f 100644 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -308,7 +308,7 @@ class mcp_warn } $rank_title = $rank_img = ''; - $avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']); + $avatar_img = get_user_avatar($user_row); $template->assign_vars(array( 'U_POST_ACTION' => $this->u_action, @@ -413,7 +413,7 @@ class mcp_warn } $rank_title = $rank_img = ''; - $avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']); + $avatar_img = get_user_avatar($user_row); // OK, they didn't submit a warning so lets build the page for them to do so $template->assign_vars(array( diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index a7c6479759..98bdf17d3f 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -438,7 +438,7 @@ class ucp_groups $group_name = $group_row['group_name']; $group_type = $group_row['group_type']; - $avatar_img = (!empty($group_row['group_avatar'])) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : ''; + $avatar_img = (!empty($group_row['group_avatar'])) ? get_group_avatar($group_row) : ''; $template->assign_vars(array( 'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name, diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index c55e8850a6..a807e3a537 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -350,7 +350,7 @@ function get_user_information($user_id, $user_row) include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - $user_row['avatar'] = ($user->optionget('viewavatars')) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']) : ''; + $user_row['avatar'] = ($user->optionget('viewavatars')) ? get_user_avatar($user_row) : ''; get_user_rank($user_row['user_rank'], $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 9d81503f0a..f61e692f32 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -587,7 +587,7 @@ class ucp_profile $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', - 'AVATAR' => get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height'], 'USER_AVATAR', true), + 'AVATAR' => get_user_avatar($user->data, 'USER_AVATAR', true), 'AVATAR_SIZE' => $config['avatar_filesize'], 'U_GALLERY' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&mode=avatar&display_gallery=1'), diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 741ac2f430..a2bac28be3 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -554,7 +554,7 @@ switch ($mode) $member['user_sig'] = smiley_text($member['user_sig']); } - $poster_avatar = get_user_avatar($member['user_avatar'], $member['user_avatar_type'], $member['user_avatar_width'], $member['user_avatar_height']); + $poster_avatar = get_user_avatar($member); // We need to check if the modules 'zebra' ('friends' & 'foes' mode), 'notes' ('user_notes' mode) and 'warn' ('warn_user' mode) are accessible to decide if we can display appropriate links $zebra_enabled = $friends_enabled = $foes_enabled = $user_notes_enabled = $warn_user_enabled = false; @@ -1219,8 +1219,7 @@ switch ($mode) break; } - // Misusing the avatar function for displaying group avatars... - $avatar_img = get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR'); + $avatar_img = get_group_avatar($group_row); $rank_title = $rank_img = $rank_img_src = ''; if ($group_row['group_rank']) @@ -1716,7 +1715,7 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f 'A_USERNAME' => addslashes(get_username_string('username', $user_id, $username, $data['user_colour'])), - 'AVATAR_IMG' => get_user_avatar($data['user_avatar'], $data['user_avatar_type'], $data['user_avatar_width'], $data['user_avatar_height']), + 'AVATAR_IMG' => get_user_avatar($data), 'ONLINE_IMG' => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')), 'S_ONLINE' => ($config['load_onlinetrack'] && $online) ? true : false, 'RANK_IMG' => $rank_img, diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 7cb6df3660..4ad80210f8 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1055,7 +1055,7 @@ while ($row = $db->sql_fetchrow($result)) 'sig_bbcode_bitfield' => '', 'online' => false, - 'avatar' => ($user->optionget('viewavatars')) ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']) : '', + 'avatar' => ($user->optionget('viewavatars')) ? get_user_avatar($row) : '', 'rank_title' => '', 'rank_image' => '', 'rank_image_src' => '', @@ -1107,7 +1107,7 @@ while ($row = $db->sql_fetchrow($result)) 'viewonline' => $row['user_allow_viewonline'], 'allow_pm' => $row['user_allow_pm'], - 'avatar' => ($user->optionget('viewavatars')) ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']) : '', + 'avatar' => ($user->optionget('viewavatars')) ? get_user_avatar($row) : '', 'age' => '', 'rank_title' => '', From 1bd3d40121960c203d0dabb4b1a04c16c564b6f1 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 17 Apr 2011 19:29:41 -0700 Subject: [PATCH 002/138] [feature/avatars] Refactor avatars to use manager Manager now stores singletons of each driver to speed loading. PHPBB3-10018 --- .../avatar_base.php => avatar/driver.php} | 34 +++++-- phpBB/includes/avatar/manager.php | 91 +++++++++++++++++++ phpBB/includes/functions_display.php | 55 ++++------- 3 files changed, 133 insertions(+), 47 deletions(-) rename phpBB/includes/{avatars/avatar_base.php => avatar/driver.php} (62%) create mode 100644 phpBB/includes/avatar/manager.php diff --git a/phpBB/includes/avatars/avatar_base.php b/phpBB/includes/avatar/driver.php similarity index 62% rename from phpBB/includes/avatars/avatar_base.php rename to phpBB/includes/avatar/driver.php index c84a6e8a7f..777b225e84 100644 --- a/phpBB/includes/avatars/avatar_base.php +++ b/phpBB/includes/avatar/driver.php @@ -1,7 +1,7 @@ user_row = $user_row; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; } /** @@ -51,7 +65,7 @@ class phpbb_avatar_base * should be ignored * @return array Avatar data */ - public function get_data($ignore_config = false) + public function get_data($user_row, $ignore_config = false) { return array( 'src' => '', @@ -68,7 +82,7 @@ class phpbb_avatar_base * should be ignored * @return string HTML */ - public function get_custom_html($ignore_config = false) + public function get_custom_html($user_row, $ignore_config = false) { return ''; } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php new file mode 100644 index 0000000000..04a4d8f425 --- /dev/null +++ b/phpBB/includes/avatar/manager.php @@ -0,0 +1,91 @@ +phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->config = $config; + $this->cache = $cache; + } + + public function get_singleton($avatar_type) + { + if (self::$valid_drivers === false) + { + $this->load_valid_drivers(); + } + + if (isset(self::$valid_drivers[$avatar_type])) + { + if (!is_object(self::$valid_drivers[$avatar_type])) + { + $class_name = 'phpbb_avatar_driver_' . $avatar_type; + self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->phpbb_root_path, $this->php_ext); + } + + return self::$valid_drivers[$avatar_type]; + } + else + { + return null; + } + } + + private function load_valid_drivers() + { + require_once($this->phpbb_root_path . 'includes/avatar/driver.' . $this->php_ext); + + if ($this->cache) + { + self::$valid_drivers = $this->cache->get('avatar_drivers'); + } + + if (empty($this->valid_drivers)) + { + self::$valid_drivers = array(); + + $iterator = new DirectoryIterator($this->phpbb_root_path . 'includes/avatar/driver'); + + foreach ($iterator as $file) + { + if (preg_match("/^(.*)\.{$this->php_ext}$/", $file, $match)) + { + self::$valid_drivers[] = $match[1]; + } + } + + self::$valid_drivers = array_flip(self::$valid_drivers); + + if ($this->cache) + { + $this->cache->put('avatar_drivers', self::$valid_drivers); + } + } + } +} diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index eba123be9d..3aeee5f704 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1278,10 +1278,12 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank * * @return string Avatar html */ -function get_user_avatar(&$user_row, $alt = 'USER_AVATAR', $ignore_config = false) +function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; + static $avatar_manager = null; + if (!$config['allow_avatar'] && !$ignore_config) { return ''; @@ -1334,47 +1336,26 @@ function get_user_avatar(&$user_row, $alt = 'USER_AVATAR', $ignore_config = fals break; default: - $class = 'phpbb_avatar_' . $user_row['user_avatar_type']; - - if (!class_exists($class)) + if (empty($avatar_manager)) { - $avatar_types = $cache->get('avatar_types'); - - if (empty($avatar_types)) - { - $avatar_types = array(); - - if ($dh = @opendir($phpbb_root_path . 'includes/avatars')) - { - while ($file = @readdir($dh)) - { - if (preg_match("/avatar_(.*)\.$phpEx/", $file, $match)) - { - $avatar_types[] = $match[1]; - } - } - - @closedir($dh); - - sort($avatar_types); - $cache->put('avatar_types', $avatar_types); - } - } - - if (in_array($user_row['user_avatar_type'], $avatar_types)) - { - require_once($phpbb_root_path . 'includes/avatars/avatar_' . $user_row['user_avatar_type'] . '.' . $phpEx); - } + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->get_driver()); } - $avatar = new $class($user_row); + $avatar = $avatar_manager->get_singleton($user_row['user_avatar_type']); - if ($avatar->custom_html) + if ($avatar) { - return $avatar->get_custom_html($ignore_config); - } + if ($avatar->custom_html) + { + return $avatar->get_html($user_row, $ignore_config); + } - $avatar_data = $avatar->get_data($ignore_config); + $avatar_data = $avatar->get_data($user_row, $ignore_config); + } + else + { + $avatar_data['src'] = ''; + } break; } @@ -1401,7 +1382,7 @@ function get_user_avatar(&$user_row, $alt = 'USER_AVATAR', $ignore_config = fals * * @return string Avatar html */ -function get_group_avatar(&$group_row, $alt = 'GROUP_AVATAR', $ignore_config = false) +function get_group_avatar($group_row, $alt = 'GROUP_AVATAR', $ignore_config = false) { // Kind of abusing this functionality... $avatar_row = array( From 16bb0f00b79102aed7da984cbca8a4b1741c62af Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 17 Apr 2011 19:29:48 -0700 Subject: [PATCH 003/138] [feature/avatars] Add drivers for standard avatar types Adding drivers for gallery, uploaded, and remote avatars. These may be used as examples for others to develop their own avatar drivers. PHPBB3-10018 --- phpBB/includes/avatar/driver/gallery.php | 50 ++++++++++++++++++++++++ phpBB/includes/avatar/driver/remote.php | 50 ++++++++++++++++++++++++ phpBB/includes/avatar/driver/upload.php | 50 ++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 phpBB/includes/avatar/driver/gallery.php create mode 100644 phpBB/includes/avatar/driver/remote.php create mode 100644 phpBB/includes/avatar/driver/upload.php diff --git a/phpBB/includes/avatar/driver/gallery.php b/phpBB/includes/avatar/driver/gallery.php new file mode 100644 index 0000000000..b937332b2d --- /dev/null +++ b/phpBB/includes/avatar/driver/gallery.php @@ -0,0 +1,50 @@ +config['allow_avatar_local']) + { + return array( + 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $user_row['user_avatar'], + 'width' => $user_row['user_avatar_width'], + 'height' => $user_row['user_avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } +} diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php new file mode 100644 index 0000000000..dbd567124d --- /dev/null +++ b/phpBB/includes/avatar/driver/remote.php @@ -0,0 +1,50 @@ +config['allow_avatar_remote']) + { + return array( + 'src' => $user_row['user_avatar'], + 'width' => $user_row['user_avatar_width'], + 'height' => $user_row['user_avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } +} diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php new file mode 100644 index 0000000000..777c9c2060 --- /dev/null +++ b/phpBB/includes/avatar/driver/upload.php @@ -0,0 +1,50 @@ +config['allow_avatar_upload']) + { + return array( + 'src' => $this->phpbb_root_path . 'download/file.' . $this->php_ext . '?avatar=' . $user_row['user_avatar'], + 'width' => $user_row['user_avatar_width'], + 'height' => $user_row['user_avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } +} From 24379f1297d092141f04ccb55013e85e9b494a83 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 17 Apr 2011 20:11:36 -0700 Subject: [PATCH 004/138] [feature/avatars] Rename gallery avatar driver Renaming gallery avatar driver to better work with existing config options. PHPBB3-10018 --- phpBB/includes/avatar/driver/{gallery.php => local.php} | 2 +- phpBB/includes/avatar/driver/upload.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename phpBB/includes/avatar/driver/{gallery.php => local.php} (93%) diff --git a/phpBB/includes/avatar/driver/gallery.php b/phpBB/includes/avatar/driver/local.php similarity index 93% rename from phpBB/includes/avatar/driver/gallery.php rename to phpBB/includes/avatar/driver/local.php index b937332b2d..4014f29cbe 100644 --- a/phpBB/includes/avatar/driver/gallery.php +++ b/phpBB/includes/avatar/driver/local.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Handles avatars selected from the board gallery * @package avatars */ -class phpbb_avatar_driver_gallery extends phpbb_avatar_driver +class phpbb_avatar_driver_local extends phpbb_avatar_driver { /** * Get the avatar url and dimensions diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 777c9c2060..da12d52d40 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -30,7 +30,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver */ public function get_data($user_row, $ignore_config = false) { - if (ignore_config || $this->config['allow_avatar_upload']) + if ($ignore_config || $this->config['allow_avatar_upload']) { return array( 'src' => $this->phpbb_root_path . 'download/file.' . $this->php_ext . '?avatar=' . $user_row['user_avatar'], From 7abded081d5ae3d231148b0485c8605b44973229 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 17 Apr 2011 21:58:51 -0700 Subject: [PATCH 005/138] [feature/avatars] UCP Avatar Interface This stubs out the avatar form fields and how form processing will occur. Form processing is not yet implemented, but shouldn't be too hard. After this I will refactor/duplicate some of the logic for the ACP. PHPBB3-10018 --- phpBB/includes/avatar/driver.php | 8 ++ phpBB/includes/avatar/driver/local.php | 73 ++++++++++++ phpBB/includes/avatar/driver/remote.php | 15 +++ phpBB/includes/avatar/driver/upload.php | 27 +++++ phpBB/includes/avatar/manager.php | 21 ++++ phpBB/includes/ucp/ucp_profile.php | 107 +++++++++++------- .../template/ucp_avatar_options.html | 69 ++++------- .../template/ucp_avatar_options_local.html | 14 +++ .../template/ucp_avatar_options_remote.html | 4 + .../template/ucp_avatar_options_upload.html | 11 ++ .../template/ucp_profile_avatar.html | 10 +- 11 files changed, 265 insertions(+), 94 deletions(-) create mode 100644 phpBB/styles/prosilver/template/ucp_avatar_options_local.html create mode 100644 phpBB/styles/prosilver/template/ucp_avatar_options_remote.html create mode 100644 phpBB/styles/prosilver/template/ucp_avatar_options_upload.html diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver.php index 777b225e84..016f9e94a8 100644 --- a/phpBB/includes/avatar/driver.php +++ b/phpBB/includes/avatar/driver.php @@ -86,4 +86,12 @@ abstract class phpbb_avatar_driver { return ''; } + + /** + * @TODO + **/ + public function handle_form($template, &$error = array(), $submitted = false) + { + return false; + } } diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 4014f29cbe..0a3ae51a48 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -47,4 +47,77 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver ); } } + + /** + * @TODO + **/ + public function handle_form($template, &$error = array(), $submitted = false) + { + if ($submitted) { + $error[] = 'TODO'; + return ''; + } + + $avatar_list = array(); + $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; + + $dh = @opendir($path); + + if (!$dh) + { + return $avatar_list; + } + + while (($cat = readdir($dh)) !== false) { + if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) + { + if ($ch = @opendir("$path/$cat")) + { + while (($image = readdir($ch)) !== false) + { + if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) + { + $avatar_list[$cat][] = array( + 'file' => rawurlencode($cat) . '/' . rawurlencode($image), + 'filename' => rawurlencode($image), + 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), + ); + } + } + @closedir($ch); + } + } + } + @closedir($dh); + + @ksort($avatar_list); + + $category = request_var('av_local_cat', ''); + $categories = array_keys($avatar_list); + + foreach ($categories as $cat) + { + if (!empty($avatar_list[$cat])) + { + $template->assign_block_vars('av_local_cats', array( + 'NAME' => $cat, + 'SELECTED' => ($cat == $category), + )); + } + } + + if (!empty($avatar_list[$category])) + { + foreach ($avatar_list[$category] as $img => $data) + { + $template->assign_block_vars('av_local_imgs', array( + 'AVATAR_IMAGE' => $path . '/' . $data['file'], + 'AVATAR_NAME' => $data['name'], + 'AVATAR_FILE' => $data['filename'], + )); + } + } + + return true; + } } diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index dbd567124d..c60102e787 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -47,4 +47,19 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver ); } } + + /** + * @TODO + **/ + public function handle_form($template, &$error = array(), $submitted = false) + { + if ($submitted) { + $error[] = 'TODO'; + return ''; + } + else + { + return true; + } + } } diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index da12d52d40..fbfd5dcc89 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -47,4 +47,31 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver ); } } + + /** + * @TODO + **/ + public function handle_form($template, &$error = array(), $submitted = false) + { + if ($submitted) { + $error[] = 'TODO'; + return ''; + } + else + { + $can_upload = (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; + if ($can_upload) + { + $template->assign_vars(array( + 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, + )); + + return true; + } + else + { + return false; + } + } + } } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 04a4d8f425..11b7e75017 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -26,6 +26,9 @@ class phpbb_avatar_manager private $cache; private static $valid_drivers = false; + /** + * @TODO + **/ public function __construct($phpbb_root_path, $php_ext = '.php', phpbb_config $config, phpbb_cache_driver_interface $cache = null) { $this->phpbb_root_path = $phpbb_root_path; @@ -34,6 +37,9 @@ class phpbb_avatar_manager $this->cache = $cache; } + /** + * @TODO + **/ public function get_singleton($avatar_type) { if (self::$valid_drivers === false) @@ -57,6 +63,9 @@ class phpbb_avatar_manager } } + /** + * @TODO + **/ private function load_valid_drivers() { require_once($this->phpbb_root_path . 'includes/avatar/driver.' . $this->php_ext); @@ -88,4 +97,16 @@ class phpbb_avatar_manager } } } + + /** + * @TODO + **/ + public function get_valid_drivers() { + if (self::$valid_drivers === false) + { + $this->load_valid_drivers(); + } + + return array_keys(self::$valid_drivers); + } } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index f61e692f32..0a2440d77d 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -28,7 +28,7 @@ class ucp_profile function main($id, $mode) { - global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; + global $cache, $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; global $request; $user->add_lang('posting'); @@ -544,55 +544,89 @@ class ucp_profile break; case 'avatar': - include($phpbb_root_path . 'includes/functions_display.' . $phpEx); - + $display_gallery = request_var('display_gallery', '0'); $avatar_select = basename(request_var('avatar_select', '')); $category = basename(request_var('category', '')); - - $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; - + add_form_key('ucp_avatar'); - if ($submit) + $avatars_enabled = false; + + if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { - if (check_form_key('ucp_avatar')) - { - if (avatar_process_user($error, false, $can_upload)) - { - meta_refresh(3, $this->u_action); - $message = $user->lang['PROFILE_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); - trigger_error($message); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + $avatar_drivers = $avatar_manager->get_valid_drivers(); + sort($avatar_drivers); + + foreach ($avatar_drivers as $driver) { + if ($config["allow_avatar_$driver"]) { + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => "ucp_avatar_options_$driver.html", + )); + + $avatar = $avatar_manager->get_singleton($driver); + if (isset($_POST["submit_av_$driver"])) + { + if (check_form_key('ucp_avatar')) + { + $result = $avatar->handle_form($template, $error, true); + + if (empty($error)) + { + // Success! Lets save the result in the database + $sql_ary = array( + 'user_avatar_type' => $driver, + 'user_avatar' => (string) $result, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . $user->data['user_id']; + + $db->sql_query($sql); + + meta_refresh(3, $this->u_action); + $message = $user->lang['PROFILE_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); + trigger_error($message); + } + } + else + { + $error[] = 'FORM_INVALID'; + } + } + + if ($avatar->handle_form($template, $error)) { + $driver_u = strtoupper($driver); + + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_TITLE'), // @TODO add lang values + 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'), + + 'DRIVER' => $driver, + 'OUTPUT' => $template->assign_display('avatar'), + )); + } } } - else - { - $error[] = 'FORM_INVALID'; - } - // Replace "error" strings with their real, localised form - $error = array_map(array($user, 'lang'), $error); } + + // Replace "error" strings with their real, localised form + $error = array_map(array($user, 'lang'), $error); - if (!$config['allow_avatar'] && $user->data['user_avatar_type']) - { - $error[] = $user->lang['AVATAR_NOT_ALLOWED']; - } - else if ((($user->data['user_avatar_type'] == AVATAR_UPLOAD) && !$config['allow_avatar_upload']) || - (($user->data['user_avatar_type'] == AVATAR_REMOTE) && !$config['allow_avatar_remote']) || - (($user->data['user_avatar_type'] == AVATAR_GALLERY) && !$config['allow_avatar_local'])) - { - $error[] = $user->lang['AVATAR_TYPE_NOT_ALLOWED']; - } + $avatar = get_user_avatar($user->data, 'USER_AVATAR', true); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', - 'AVATAR' => get_user_avatar($user->data, 'USER_AVATAR', true), + 'AVATAR' => $avatar, 'AVATAR_SIZE' => $config['avatar_filesize'], 'U_GALLERY' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&mode=avatar&display_gallery=1'), - 'S_FORM_ENCTYPE' => ($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) ? ' enctype="multipart/form-data"' : '', + 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(), )); @@ -603,16 +637,11 @@ class ucp_profile } else if ($config['allow_avatar']) { - $avatars_enabled = (($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) || ($auth->acl_get('u_chgavatar') && ($config['allow_avatar_local'] || $config['allow_avatar_remote']))) ? true : false; - $template->assign_vars(array( - 'AVATAR_WIDTH' => request_var('width', $user->data['user_avatar_width']), - 'AVATAR_HEIGHT' => request_var('height', $user->data['user_avatar_height']), + 'AVATAR_WIDTH' => request_var('width', empty($avatar) ? 0 : $user->data['user_avatar_width']), + 'AVATAR_HEIGHT' => request_var('height', empty($avatar) ? 0 : $user->data['user_avatar_height']), 'S_AVATARS_ENABLED' => $avatars_enabled, - 'S_UPLOAD_AVATAR_FILE' => ($can_upload && $config['allow_avatar_upload']) ? true : false, - 'S_UPLOAD_AVATAR_URL' => ($can_upload && $config['allow_avatar_remote_upload']) ? true : false, - 'S_LINK_AVATAR' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_remote']) ? true : false, 'S_DISPLAY_GALLERY' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) ? true : false) ); } diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index 7012c42f3b..680267bb10 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -7,31 +7,12 @@

{ERROR}

-
-

{L_AVATAR_EXPLAIN}
-
{AVATAR}
-
-
- -
-
-
-
- - - -
-

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- - - -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
+

{L_AVATAR_EXPLAIN}
+
{AVATAR}
+
+

{L_LINK_REMOTE_SIZE_EXPLAIN}
@@ -39,32 +20,26 @@
+ +
+ + +

{avatar_drivers.L_TITLE}

+

{avatar_drivers.L_EXPLAIN}

+ +
+ {avatar_drivers.OUTPUT} +
+
+   + +
+ + +
+
- - - - -
-
- -

{L_AVATAR_GALLERY}

- -
- - - -
- - - - -
diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html new file mode 100644 index 0000000000..2644397e0d --- /dev/null +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html @@ -0,0 +1,14 @@ + + + + diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html new file mode 100644 index 0000000000..70869086a9 --- /dev/null +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html @@ -0,0 +1,4 @@ +
+

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
+
diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html b/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html new file mode 100644 index 0000000000..9caab72444 --- /dev/null +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html @@ -0,0 +1,11 @@ +
+
+
+
+ + +
+

{L_UPLOAD_AVATAR_URL_EXPLAIN}
+
+
+ diff --git a/phpBB/styles/prosilver/template/ucp_profile_avatar.html b/phpBB/styles/prosilver/template/ucp_profile_avatar.html index a25c43a588..8157d8c15b 100644 --- a/phpBB/styles/prosilver/template/ucp_profile_avatar.html +++ b/phpBB/styles/prosilver/template/ucp_profile_avatar.html @@ -6,14 +6,8 @@ -
- {S_HIDDEN_FIELDS} -   -   -   - - {S_FORM_TOKEN} -
+{S_HIDDEN_FIELDS} +{S_FORM_TOKEN} From f102d9a631d6de464abefe2089ff1e6e13ed044d Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 18 Apr 2011 10:44:29 -0700 Subject: [PATCH 006/138] [feature/avatars] Various cosmetic changes Various small changes based on feedback from nn- * Renaming $php_ext to $phpEx * Fixing copyright years * Explain $ignore_config * Explain Regex * Copypasta package error * rename get_singleton PHPBB3-10018 --- phpBB/includes/avatar/driver.php | 32 ++++++++---- phpBB/includes/avatar/driver/local.php | 65 ++++++++++++++----------- phpBB/includes/avatar/driver/remote.php | 12 ++--- phpBB/includes/avatar/driver/upload.php | 14 ++---- phpBB/includes/avatar/manager.php | 21 ++++---- phpBB/includes/functions_display.php | 2 +- phpBB/includes/ucp/ucp_profile.php | 2 +- 7 files changed, 80 insertions(+), 68 deletions(-) diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver.php index 016f9e94a8..60ec18670e 100644 --- a/phpBB/includes/avatar/driver.php +++ b/phpBB/includes/avatar/driver.php @@ -2,7 +2,7 @@ /** * * @package avatar -* @copyright (c) 2005, 2009 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ @@ -37,7 +37,13 @@ abstract class phpbb_avatar_driver * Current $phpEx * @type string */ - protected $php_ext; + protected $phpEx; + + /** + * A cache driver + * @type phpbb_cache_driver_interface + */ + protected $cache; /** * This flag should be set to true if the avatar requires a nonstandard image @@ -47,22 +53,27 @@ abstract class phpbb_avatar_driver public $custom_html = false; /** - * Construct an avatar object + * Construct an driver object * - * @param $user_row User data to base the avatar url/html on + * @param $config The phpBB configuration + * @param $phpbb_root_path The path to the phpBB root + * @param $phpEx The php file extension + * @param $cache A cache driver */ - public function __construct(phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_config $config, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null) { $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->phpEx = $phpEx; + $this->cache = $cache; } /** * Get the avatar url and dimensions * - * @param $ignore_config Whether $user or global avatar visibility settings - * should be ignored + * @param $ignore_config Whether this function should respect the users/board + * configuration option, or should just render the avatar anyways. + * Useful for the ACP. * @return array Avatar data */ public function get_data($user_row, $ignore_config = false) @@ -78,8 +89,9 @@ abstract class phpbb_avatar_driver * Returns custom html for displaying this avatar. * Only called if $custom_html is true. * - * @param $ignore_config Whether $user or global avatar visibility settings - * should be ignored + * @param $ignore_config Whether this function should respect the users/board + * configuration option, or should just render the avatar anyways. + * Useful for the ACP. * @return string HTML */ public function get_custom_html($user_row, $ignore_config = false) diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 0a3ae51a48..65340c92ce 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -2,7 +2,7 @@ /** * * @package avatar -* @copyright (c) 2005, 2009 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ @@ -22,11 +22,7 @@ if (!defined('IN_PHPBB')) class phpbb_avatar_driver_local extends phpbb_avatar_driver { /** - * Get the avatar url and dimensions - * - * @param $ignore_config Whether $user or global avatar visibility settings - * should be ignored - * @return array Avatar data + * @inheritdoc */ public function get_data($user_row, $ignore_config = false) { @@ -49,8 +45,8 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver } /** - * @TODO - **/ + * @inheritdoc + */ public function handle_form($template, &$error = array(), $submitted = false) { if ($submitted) { @@ -58,39 +54,50 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver return ''; } - $avatar_list = array(); - $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; + $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list'); - $dh = @opendir($path); - - if (!$dh) + if (!$avatar_list) { - return $avatar_list; - } + $avatar_list = array(); + $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; - while (($cat = readdir($dh)) !== false) { - if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) + $dh = @opendir($path); + + if (!$dh) { - if ($ch = @opendir("$path/$cat")) + return $avatar_list; + } + + while (($cat = readdir($dh)) !== false) { + if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) { - while (($image = readdir($ch)) !== false) + if ($ch = @opendir("$path/$cat")) { - if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) + while (($image = readdir($ch)) !== false) { - $avatar_list[$cat][] = array( - 'file' => rawurlencode($cat) . '/' . rawurlencode($image), - 'filename' => rawurlencode($image), - 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), - ); + // Match all images in the gallery folder + if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) + { + $avatar_list[$cat][] = array( + 'file' => rawurlencode($cat) . '/' . rawurlencode($image), + 'filename' => rawurlencode($image), + 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), + ); + } } + @closedir($ch); } - @closedir($ch); } } - } - @closedir($dh); + @closedir($dh); - @ksort($avatar_list); + @ksort($avatar_list); + + if ($this->cache != null) + { + $this->cache->put('av_local_list', $avatar_list); + } + } $category = request_var('av_local_cat', ''); $categories = array_keys($avatar_list); diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index c60102e787..bfc1be263f 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -2,7 +2,7 @@ /** * * @package avatar -* @copyright (c) 2005, 2009 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ @@ -22,11 +22,7 @@ if (!defined('IN_PHPBB')) class phpbb_avatar_driver_remote extends phpbb_avatar_driver { /** - * Get the avatar url and dimensions - * - * @param $ignore_config Whether $user or global avatar visibility settings - * should be ignored - * @return array Avatar data + * @inheritdoc */ public function get_data($user_row, $ignore_config = false) { @@ -49,8 +45,8 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver } /** - * @TODO - **/ + * @inheritdoc + */ public function handle_form($template, &$error = array(), $submitted = false) { if ($submitted) { diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index fbfd5dcc89..9705a888b6 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -2,7 +2,7 @@ /** * * @package avatar -* @copyright (c) 2005, 2009 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ @@ -22,18 +22,14 @@ if (!defined('IN_PHPBB')) class phpbb_avatar_driver_upload extends phpbb_avatar_driver { /** - * Get the avatar url and dimensions - * - * @param $ignore_config Whether $user or global avatar visibility settings - * should be ignored - * @return array Avatar data + * @inheritdoc */ public function get_data($user_row, $ignore_config = false) { if ($ignore_config || $this->config['allow_avatar_upload']) { return array( - 'src' => $this->phpbb_root_path . 'download/file.' . $this->php_ext . '?avatar=' . $user_row['user_avatar'], + 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $user_row['user_avatar'], 'width' => $user_row['user_avatar_width'], 'height' => $user_row['user_avatar_height'], ); @@ -49,8 +45,8 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver } /** - * @TODO - **/ + * @inheritdoc + */ public function handle_form($template, &$error = array(), $submitted = false) { if ($submitted) { diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 11b7e75017..6471c4cc9c 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -2,7 +2,7 @@ /** * * @package avatar -* @copyright (c) 2010 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ @@ -16,12 +16,12 @@ if (!defined('IN_PHPBB')) } /** -* @package acm +* @package avatar */ class phpbb_avatar_manager { private $phpbb_root_path; - private $php_ext; + private $phpEx; private $config; private $cache; private static $valid_drivers = false; @@ -29,10 +29,10 @@ class phpbb_avatar_manager /** * @TODO **/ - public function __construct($phpbb_root_path, $php_ext = '.php', phpbb_config $config, phpbb_cache_driver_interface $cache = null) + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_cache_driver_interface $cache = null) { $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->phpEx = $phpEx; $this->config = $config; $this->cache = $cache; } @@ -40,7 +40,7 @@ class phpbb_avatar_manager /** * @TODO **/ - public function get_singleton($avatar_type) + public function get_driver($avatar_type, $new = false) { if (self::$valid_drivers === false) { @@ -49,10 +49,10 @@ class phpbb_avatar_manager if (isset(self::$valid_drivers[$avatar_type])) { - if (!is_object(self::$valid_drivers[$avatar_type])) + if ($new || !is_object(self::$valid_drivers[$avatar_type])) { $class_name = 'phpbb_avatar_driver_' . $avatar_type; - self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->phpbb_root_path, $this->php_ext); + self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->phpbb_root_path, $this->phpEx, $this->cache); } return self::$valid_drivers[$avatar_type]; @@ -68,7 +68,7 @@ class phpbb_avatar_manager **/ private function load_valid_drivers() { - require_once($this->phpbb_root_path . 'includes/avatar/driver.' . $this->php_ext); + require_once($this->phpbb_root_path . 'includes/avatar/driver.' . $this->phpEx); if ($this->cache) { @@ -83,7 +83,8 @@ class phpbb_avatar_manager foreach ($iterator as $file) { - if (preg_match("/^(.*)\.{$this->php_ext}$/", $file, $match)) + // Match all files that appear to be php files + if (preg_match("/^(.*)\.{$this->phpEx}$/", $file, $match)) { self::$valid_drivers[] = $match[1]; } diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 3aeee5f704..23900dfd88 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1341,7 +1341,7 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->get_driver()); } - $avatar = $avatar_manager->get_singleton($user_row['user_avatar_type']); + $avatar = $avatar_manager->get_driver($user_row['user_avatar_type']); if ($avatar) { diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 0a2440d77d..a93430644c 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -567,7 +567,7 @@ class ucp_profile 'avatar' => "ucp_avatar_options_$driver.html", )); - $avatar = $avatar_manager->get_singleton($driver); + $avatar = $avatar_manager->get_driver($driver); if (isset($_POST["submit_av_$driver"])) { if (check_form_key('ucp_avatar')) From 00d4b9d431d6772889291f2f4c857a144bce93fb Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 18 Apr 2011 22:54:35 -0700 Subject: [PATCH 007/138] [feature/avatars] Implement UCP remote/local avatars Implementing selection logic for gallery and remote avatars. Modified some of the driver interfaces to make things work nicer also. Upload functionality will be in the next commit. PHPBB3-10018 --- phpBB/includes/avatar/driver.php | 2 +- phpBB/includes/avatar/driver/local.php | 31 ++++-- phpBB/includes/avatar/driver/remote.php | 105 +++++++++++++++++- phpBB/includes/avatar/driver/upload.php | 3 +- phpBB/includes/ucp/ucp_profile.php | 58 ++++------ .../template/ucp_avatar_options.html | 9 -- .../template/ucp_avatar_options_local.html | 2 +- .../template/ucp_avatar_options_remote.html | 11 +- .../template/ucp_avatar_options_upload.html | 8 +- 9 files changed, 165 insertions(+), 64 deletions(-) diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver.php index 60ec18670e..a2ff5d804d 100644 --- a/phpBB/includes/avatar/driver.php +++ b/phpBB/includes/avatar/driver.php @@ -102,7 +102,7 @@ abstract class phpbb_avatar_driver /** * @TODO **/ - public function handle_form($template, &$error = array(), $submitted = false) + public function handle_form($template, $user_row, &$error, $submitted = false) { return false; } diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 65340c92ce..c00f65a81d 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -47,13 +47,8 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function handle_form($template, &$error = array(), $submitted = false) + public function handle_form($template, $user_row, &$error, $submitted = false) { - if ($submitted) { - $error[] = 'TODO'; - return ''; - } - $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list'); if (!$avatar_list) @@ -78,10 +73,13 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver // Match all images in the gallery folder if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) { - $avatar_list[$cat][] = array( + $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); + $avatar_list[$cat][$image] = array( 'file' => rawurlencode($cat) . '/' . rawurlencode($image), 'filename' => rawurlencode($image), 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), + 'width' => $dims[0], + 'height' => $dims[1], ); } } @@ -98,8 +96,25 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver $this->cache->put('av_local_list', $avatar_list); } } - + $category = request_var('av_local_cat', ''); + + if ($submitted) { + $file = request_var('av_local_file', ''); + if (!isset($avatar_list[$category][urldecode($file)])) + { + $error[] = 'AVATAR_URL_NOT_FOUND'; + return false; + } + + return array( + 'user_avatar' => $category . '/' . $file, + 'user_avatar_width' => $avatar_list[$category][urldecode($file)]['width'], + 'user_avatar_height' => $avatar_list[$category][urldecode($file)]['height'], + ); + } + + $categories = array_keys($avatar_list); foreach ($categories as $cat) diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index bfc1be263f..ebaf3cf5c4 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -47,14 +47,111 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function handle_form($template, &$error = array(), $submitted = false) + public function handle_form($template, $user_row, &$error, $submitted = false) { - if ($submitted) { - $error[] = 'TODO'; - return ''; + if ($submitted) + { + $url = request_var('av_remote_url', ''); + $width = request_var('av_remote_width', 0); + $height = request_var('av_remote_height', 0); + + if (!preg_match('#^(http|https|ftp)://#i', $url)) + { + $url = 'http://' . $url; + } + + $error = array_merge($error, validate_data(array( + 'url' => $url, + ), array( + 'url' => array('string', true, 5, 255), + ))); + + if (!empty($error)) + { + return false; + } + + // Check if this url looks alright + // This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible + if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $url)) + { + $error[] = 'AVATAR_URL_INVALID'; + return false; + } + + // Make sure getimagesize works... + if (($image_data = getimagesize($url)) === false && ($width <= 0 || $height <= 0)) + { + $error[] = 'UNABLE_GET_IMAGE_SIZE'; + return false; + } + + if (!empty($image_data) && ($image_data[0] < 2 || $image_data[1] < 2)) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } + + $width = ($width && $height) ? $width : $image_data[0]; + $height = ($width && $height) ? $height : $image_data[1]; + + if ($width < 2 || $height < 2) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } + + include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); + $types = fileupload::image_types(); + $extension = strtolower(filespec::get_extension($url)); + + if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) + { + if (!isset($types[$image_data[2]])) + { + $error[] = 'UNABLE_GET_IMAGE_SIZE'; + } + else + { + $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension); + } + + return false; + } + + if ($this->config['avatar_max_width'] || $this->config['avatar_max_height']) + { + if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height']) + { + $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); + return false; + } + } + + if ($this->config['avatar_min_width'] || $this->config['avatar_min_height']) + { + if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height']) + { + $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); + return false; + } + } + + $result = array( + 'user_avatar' => $url, + 'user_avatar_width' => $width, + 'user_avatar_height' => $height, + ); + + return $result; } else { + $template->assign_vars(array( + 'AV_REMOTE_WIDTH' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar_width']) ? $user_row['user_avatar_width'] : request_var('av_local_width', 0), + 'AV_REMOTE_HEIGHT' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar_height']) ? $user_row['user_avatar_height'] : request_var('av_local_width', 0), + 'AV_REMOTE_URL' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar']) ? $user_row['user_avatar'] : '', + )); return true; } } diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 9705a888b6..84168722ec 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -47,7 +47,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc */ - public function handle_form($template, &$error = array(), $submitted = false) + public function handle_form($template, $user_row, &$error, $submitted = false) { if ($submitted) { $error[] = 'TODO'; @@ -60,6 +60,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver { $template->assign_vars(array( 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, + 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], )); return true; diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index a93430644c..5d7dbe12d8 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -544,12 +544,8 @@ class ucp_profile break; case 'avatar': - include($phpbb_root_path . 'includes/functions_display.' . $phpEx); - - $display_gallery = request_var('display_gallery', '0'); - $avatar_select = basename(request_var('avatar_select', '')); - $category = basename(request_var('category', '')); - + include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); + add_form_key('ucp_avatar'); $avatars_enabled = false; @@ -572,18 +568,15 @@ class ucp_profile { if (check_form_key('ucp_avatar')) { - $result = $avatar->handle_form($template, $error, true); + $result = $avatar->handle_form($template, $user->data, $error, true); if (empty($error)) { // Success! Lets save the result in the database - $sql_ary = array( - 'user_avatar_type' => $driver, - 'user_avatar' => (string) $result, - ); + $result['user_avatar_type'] = $driver; $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); @@ -599,7 +592,7 @@ class ucp_profile } } - if ($avatar->handle_form($template, $error)) { + if ($avatar->handle_form($template, $user->data, $error)) { $driver_u = strtoupper($driver); $template->assign_block_vars('avatar_drivers', array( @@ -613,39 +606,36 @@ class ucp_profile } } } - - // Replace "error" strings with their real, localised form - $error = array_map(array($user, 'lang'), $error); + // Replace "error" strings with their real, localised form + $err = $error; + $error = array(); + foreach ($err as $e) + { + if (is_array($e)) + { + $key = array_shift($e); + $error[] = vsprintf($user->lang($key), $e); + } + else + { + $error[] = $user->lang((string) $e); + } + } + $avatar = get_user_avatar($user->data, 'USER_AVATAR', true); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', 'AVATAR' => $avatar, - 'AVATAR_SIZE' => $config['avatar_filesize'], - - 'U_GALLERY' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&mode=avatar&display_gallery=1'), 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(), + + 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), )); - if ($config['allow_avatar'] && $display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) - { - avatar_gallery($category, $avatar_select, 4); - } - else if ($config['allow_avatar']) - { - $template->assign_vars(array( - 'AVATAR_WIDTH' => request_var('width', empty($avatar) ? 0 : $user->data['user_avatar_width']), - 'AVATAR_HEIGHT' => request_var('height', empty($avatar) ? 0 : $user->data['user_avatar_height']), - - 'S_AVATARS_ENABLED' => $avatars_enabled, - 'S_DISPLAY_GALLERY' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) ? true : false) - ); - } - break; } diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index 680267bb10..e30fcc74aa 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -12,15 +12,6 @@
{AVATAR}
- -
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
-
- ×  - -
-
- diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html index 2644397e0d..0dd83db017 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html @@ -9,6 +9,6 @@ diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html index 70869086a9..4e62e96d9d 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html @@ -1,4 +1,11 @@
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
+

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
+
+
+

{L_LINK_REMOTE_SIZE_EXPLAIN}
+
+ ×  + +
diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html b/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html index 9caab72444..9c8dd9af01 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html @@ -1,11 +1,11 @@
-
-
+
+
-

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
+

{L_UPLOAD_AVATAR_URL_EXPLAIN}
+
From f02f6216867db63f6ad2659b0b702b81b07a875c Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 18 Apr 2011 23:34:56 -0700 Subject: [PATCH 008/138] [feature/avatars] Fixing remote avatars size checks Remote avatars size checks were broken. It assumed getimagesize() was available and used the wrong template values. PHPBB3-10018 --- phpBB/includes/avatar/driver/local.php | 9 +++++- phpBB/includes/avatar/driver/remote.php | 29 ++++++++++--------- .../template/ucp_avatar_options_remote.html | 4 +-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index c00f65a81d..4c15b5de2e 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -73,7 +73,14 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver // Match all images in the gallery folder if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) { - $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); + if (function_exists('getimagesize')) + { + $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); + } + else + { + $dims = array(0, 0); + } $avatar_list[$cat][$image] = array( 'file' => rawurlencode($cat) . '/' . rawurlencode($image), 'filename' => rawurlencode($image), diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index ebaf3cf5c4..48f86cac3f 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -80,22 +80,25 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver } // Make sure getimagesize works... - if (($image_data = getimagesize($url)) === false && ($width <= 0 || $height <= 0)) + if (function_exists('getimagesize')) { - $error[] = 'UNABLE_GET_IMAGE_SIZE'; - return false; + if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) + { + $error[] = 'UNABLE_GET_IMAGE_SIZE'; + return false; + } + + if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0)) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } + + $width = ($width && $height) ? $width : $image_data[0]; + $height = ($width && $height) ? $height : $image_data[1]; } - if (!empty($image_data) && ($image_data[0] < 2 || $image_data[1] < 2)) - { - $error[] = 'AVATAR_NO_SIZE'; - return false; - } - - $width = ($width && $height) ? $width : $image_data[0]; - $height = ($width && $height) ? $height : $image_data[1]; - - if ($width < 2 || $height < 2) + if ($width <= 0 || $height <= 0) { $error[] = 'AVATAR_NO_SIZE'; return false; diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html index 4e62e96d9d..02704c5be8 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html @@ -5,7 +5,7 @@

{L_LINK_REMOTE_SIZE_EXPLAIN}
- ×  - + ×  +
From 019b9bc0735bb74d46f4e87fe006328970211dad Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Tue, 19 Apr 2011 11:19:47 -0700 Subject: [PATCH 009/138] [feature/avatars] Implement avatar uploads for ucp As above, implement avatar uploads from local and remote sources in the UCP. PHPBB3-10018 --- phpBB/includes/avatar/driver/local.php | 50 +++++++++-------- phpBB/includes/avatar/driver/upload.php | 71 ++++++++++++++++++++----- phpBB/includes/ucp/ucp_profile.php | 2 +- 3 files changed, 82 insertions(+), 41 deletions(-) diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 4c15b5de2e..f9b7662e93 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -58,43 +58,41 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver $dh = @opendir($path); - if (!$dh) + if ($dh) { - return $avatar_list; - } - - while (($cat = readdir($dh)) !== false) { - if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) - { - if ($ch = @opendir("$path/$cat")) + while (($cat = readdir($dh)) !== false) { + if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) { - while (($image = readdir($ch)) !== false) + if ($ch = @opendir("$path/$cat")) { - // Match all images in the gallery folder - if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) + while (($image = readdir($ch)) !== false) { - if (function_exists('getimagesize')) + // Match all images in the gallery folder + if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) { - $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); + if (function_exists('getimagesize')) + { + $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); + } + else + { + $dims = array(0, 0); + } + $avatar_list[$cat][$image] = array( + 'file' => rawurlencode($cat) . '/' . rawurlencode($image), + 'filename' => rawurlencode($image), + 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), + 'width' => $dims[0], + 'height' => $dims[1], + ); } - else - { - $dims = array(0, 0); - } - $avatar_list[$cat][$image] = array( - 'file' => rawurlencode($cat) . '/' . rawurlencode($image), - 'filename' => rawurlencode($image), - 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), - 'width' => $dims[0], - 'height' => $dims[1], - ); } + @closedir($ch); } - @closedir($ch); } } + @closedir($dh); } - @closedir($dh); @ksort($avatar_list); diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 84168722ec..cbc46e0e49 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -49,26 +49,69 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver */ public function handle_form($template, $user_row, &$error, $submitted = false) { - if ($submitted) { - $error[] = 'TODO'; - return ''; - } - else - { - $can_upload = (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; - if ($can_upload) - { - $template->assign_vars(array( - 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, - 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], - )); + $can_upload = (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; - return true; + if ($can_upload == false) + { + return false; + } + + if ($submitted) + { + include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); + + $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $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_var('av_upload_url', ''); + + if (!empty($_FILES['av_upload_file']['name'])) + { + $file = $upload->form_upload('av_upload_file'); } else { + $file = $upload->remote_upload($url); + } + + $prefix = $this->config['avatar_salt'] . '_'; + $file->clean_filename('avatar', $prefix, $user_row['user_id']); + + $destination = $this->config['avatar_path']; + + // Adjust destination path (no trailing slash) + if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') + { + $destination = substr($destination, 0, -1); + } + + $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); + if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) + { + $destination = ''; + } + + // Move file and overwrite any existing image + $file->move_file($destination, true); + + if (sizeof($file->error)) + { + $file->remove(); + $error = array_merge($error, $file->error); return false; } + + return array( + 'user_avatar' => $user_row['user_id'] . '_' . time() . '.' . $file->get('extension'), + 'user_avatar_width' => $file->get('width'), + 'user_avatar_height' => $file->get('height'), + ); } + + $template->assign_vars(array( + 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, + 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], + )); + + return true; } } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 5d7dbe12d8..a815ec7987 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -570,7 +570,7 @@ class ucp_profile { $result = $avatar->handle_form($template, $user->data, $error, true); - if (empty($error)) + if ($result && empty($error)) { // Success! Lets save the result in the database $result['user_avatar_type'] = $driver; From 611a1d647a3a63013df472b469bf1f3e6e7bd657 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Wed, 20 Apr 2011 09:46:36 -0700 Subject: [PATCH 010/138] [feature/avatars] Refactor avatar's handle_form Since it was performing two distinct operations, refactor handle_form to separate functions that prepare and process forms. PHPBB3-10018 --- phpBB/includes/avatar/driver.php | 10 +- phpBB/includes/avatar/driver/local.php | 105 ++++++++------ phpBB/includes/avatar/driver/remote.php | 178 ++++++++++++------------ phpBB/includes/avatar/driver/upload.php | 124 +++++++++-------- phpBB/includes/ucp/ucp_profile.php | 4 +- 5 files changed, 229 insertions(+), 192 deletions(-) diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver.php index a2ff5d804d..5d3b734f7b 100644 --- a/phpBB/includes/avatar/driver.php +++ b/phpBB/includes/avatar/driver.php @@ -102,7 +102,15 @@ abstract class phpbb_avatar_driver /** * @TODO **/ - public function handle_form($template, $user_row, &$error, $submitted = false) + public function prepare_form($template, $user_row, &$error) + { + return false; + } + + /** + * @TODO + **/ + public function process_form($template, $user_row, &$error) { return false; } diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index f9b7662e93..47ae143ec9 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -47,7 +47,65 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function handle_form($template, $user_row, &$error, $submitted = false) + public function prepare_form($template, $user_row, &$error) + { + $avatar_list = $this->get_avatar_list(); + $category = request_var('av_local_cat', ''); + + $categories = array_keys($avatar_list); + + foreach ($categories as $cat) + { + if (!empty($avatar_list[$cat])) + { + $template->assign_block_vars('av_local_cats', array( + 'NAME' => $cat, + 'SELECTED' => ($cat == $category), + )); + } + } + + if (!empty($avatar_list[$category])) + { + foreach ($avatar_list[$category] as $img => $data) + { + $template->assign_block_vars('av_local_imgs', array( + 'AVATAR_IMAGE' => $path . '/' . $data['file'], + 'AVATAR_NAME' => $data['name'], + 'AVATAR_FILE' => $data['filename'], + )); + } + } + + return true; + } + + /** + * @inheritdoc + */ + public function process_form($template, $user_row, &$error) + { + $avatar_list = $this->get_avatar_list(); + $category = request_var('av_local_cat', ''); + + $file = request_var('av_local_file', ''); + if (!isset($avatar_list[$category][urldecode($file)])) + { + $error[] = 'AVATAR_URL_NOT_FOUND'; + return false; + } + + return array( + 'user_avatar' => $category . '/' . $file, + 'user_avatar_width' => $avatar_list[$category][urldecode($file)]['width'], + 'user_avatar_height' => $avatar_list[$category][urldecode($file)]['height'], + ); + } + + /** + * @TODO + */ + private function get_avatar_list() { $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list'); @@ -101,50 +159,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver $this->cache->put('av_local_list', $avatar_list); } } - - $category = request_var('av_local_cat', ''); - - if ($submitted) { - $file = request_var('av_local_file', ''); - if (!isset($avatar_list[$category][urldecode($file)])) - { - $error[] = 'AVATAR_URL_NOT_FOUND'; - return false; - } - return array( - 'user_avatar' => $category . '/' . $file, - 'user_avatar_width' => $avatar_list[$category][urldecode($file)]['width'], - 'user_avatar_height' => $avatar_list[$category][urldecode($file)]['height'], - ); - } - - - $categories = array_keys($avatar_list); - - foreach ($categories as $cat) - { - if (!empty($avatar_list[$cat])) - { - $template->assign_block_vars('av_local_cats', array( - 'NAME' => $cat, - 'SELECTED' => ($cat == $category), - )); - } - } - - if (!empty($avatar_list[$category])) - { - foreach ($avatar_list[$category] as $img => $data) - { - $template->assign_block_vars('av_local_imgs', array( - 'AVATAR_IMAGE' => $path . '/' . $data['file'], - 'AVATAR_NAME' => $data['name'], - 'AVATAR_FILE' => $data['filename'], - )); - } - } - - return true; + return $avatar_list; } } diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 48f86cac3f..32f93c7928 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -47,115 +47,115 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function handle_form($template, $user_row, &$error, $submitted = false) + public function prepare_form($template, $user_row, &$error) { - if ($submitted) - { - $url = request_var('av_remote_url', ''); - $width = request_var('av_remote_width', 0); - $height = request_var('av_remote_height', 0); + $template->assign_vars(array( + 'AV_REMOTE_WIDTH' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar_width']) ? $user_row['user_avatar_width'] : request_var('av_local_width', 0), + 'AV_REMOTE_HEIGHT' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar_height']) ? $user_row['user_avatar_height'] : request_var('av_local_width', 0), + 'AV_REMOTE_URL' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar']) ? $user_row['user_avatar'] : '', + )); + + return true; + } + + /** + * @inheritdoc + */ + public function process_form($template, $user_row, &$error) + { + $url = request_var('av_remote_url', ''); + $width = request_var('av_remote_width', 0); + $height = request_var('av_remote_height', 0); - if (!preg_match('#^(http|https|ftp)://#i', $url)) - { - $url = 'http://' . $url; - } + if (!preg_match('#^(http|https|ftp)://#i', $url)) + { + $url = 'http://' . $url; + } - $error = array_merge($error, validate_data(array( - 'url' => $url, - ), array( - 'url' => array('string', true, 5, 255), - ))); + $error = array_merge($error, validate_data(array( + 'url' => $url, + ), array( + 'url' => array('string', true, 5, 255), + ))); - if (!empty($error)) + if (!empty($error)) + { + return false; + } + + // Check if this url looks alright + // This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible + if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $url)) + { + $error[] = 'AVATAR_URL_INVALID'; + return false; + } + + // Make sure getimagesize works... + if (function_exists('getimagesize')) + { + if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) { + $error[] = 'UNABLE_GET_IMAGE_SIZE'; return false; } - // Check if this url looks alright - // This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible - if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $url)) - { - $error[] = 'AVATAR_URL_INVALID'; - return false; - } - - // Make sure getimagesize works... - if (function_exists('getimagesize')) - { - if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) - { - $error[] = 'UNABLE_GET_IMAGE_SIZE'; - return false; - } - - if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0)) - { - $error[] = 'AVATAR_NO_SIZE'; - return false; - } - - $width = ($width && $height) ? $width : $image_data[0]; - $height = ($width && $height) ? $height : $image_data[1]; - } - - if ($width <= 0 || $height <= 0) + if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0)) { $error[] = 'AVATAR_NO_SIZE'; return false; } - include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); - $types = fileupload::image_types(); - $extension = strtolower(filespec::get_extension($url)); + $width = ($width && $height) ? $width : $image_data[0]; + $height = ($width && $height) ? $height : $image_data[1]; + } - if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) + if ($width <= 0 || $height <= 0) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } + + include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); + $types = fileupload::image_types(); + $extension = strtolower(filespec::get_extension($url)); + + if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) + { + if (!isset($types[$image_data[2]])) { - if (!isset($types[$image_data[2]])) - { - $error[] = 'UNABLE_GET_IMAGE_SIZE'; - } - else - { - $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension); - } + $error[] = 'UNABLE_GET_IMAGE_SIZE'; + } + else + { + $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension); + } + return false; + } + + if ($this->config['avatar_max_width'] || $this->config['avatar_max_height']) + { + if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height']) + { + $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); return false; } - - if ($this->config['avatar_max_width'] || $this->config['avatar_max_height']) - { - if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height']) - { - $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); - return false; - } - } - - if ($this->config['avatar_min_width'] || $this->config['avatar_min_height']) - { - if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height']) - { - $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); - return false; - } - } - - $result = array( - 'user_avatar' => $url, - 'user_avatar_width' => $width, - 'user_avatar_height' => $height, - ); - - return $result; } - else + + if ($this->config['avatar_min_width'] || $this->config['avatar_min_height']) { - $template->assign_vars(array( - 'AV_REMOTE_WIDTH' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar_width']) ? $user_row['user_avatar_width'] : request_var('av_local_width', 0), - 'AV_REMOTE_HEIGHT' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar_height']) ? $user_row['user_avatar_height'] : request_var('av_local_width', 0), - 'AV_REMOTE_URL' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar']) ? $user_row['user_avatar'] : '', - )); - return true; + if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height']) + { + $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); + return false; + } } + + return array( + 'user_avatar' => $url, + 'user_avatar_width' => $width, + 'user_avatar_height' => $height, + ); } } diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index cbc46e0e49..dd1dbfa5a0 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -47,66 +47,13 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc */ - public function handle_form($template, $user_row, &$error, $submitted = false) + public function prepare_form($template, $user_row, &$error) { - $can_upload = (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; - - if ($can_upload == false) + if (!$this->can_upload()) { return false; } - if ($submitted) - { - include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); - - $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $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_var('av_upload_url', ''); - - if (!empty($_FILES['av_upload_file']['name'])) - { - $file = $upload->form_upload('av_upload_file'); - } - else - { - $file = $upload->remote_upload($url); - } - - $prefix = $this->config['avatar_salt'] . '_'; - $file->clean_filename('avatar', $prefix, $user_row['user_id']); - - $destination = $this->config['avatar_path']; - - // Adjust destination path (no trailing slash) - if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') - { - $destination = substr($destination, 0, -1); - } - - $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); - if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) - { - $destination = ''; - } - - // Move file and overwrite any existing image - $file->move_file($destination, true); - - if (sizeof($file->error)) - { - $file->remove(); - $error = array_merge($error, $file->error); - return false; - } - - return array( - 'user_avatar' => $user_row['user_id'] . '_' . time() . '.' . $file->get('extension'), - 'user_avatar_width' => $file->get('width'), - 'user_avatar_height' => $file->get('height'), - ); - } - $template->assign_vars(array( 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], @@ -114,4 +61,71 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver return true; } + + /** + * @inheritdoc + */ + public function process_form($template, $user_row, &$error) + { + if (!$this->can_upload()) + { + return false; + } + + include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); + + $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $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_var('av_upload_url', ''); + + if (!empty($_FILES['av_upload_file']['name'])) + { + $file = $upload->form_upload('av_upload_file'); + } + else + { + $file = $upload->remote_upload($url); + } + + $prefix = $this->config['avatar_salt'] . '_'; + $file->clean_filename('avatar', $prefix, $user_row['user_id']); + + $destination = $this->config['avatar_path']; + + // Adjust destination path (no trailing slash) + if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') + { + $destination = substr($destination, 0, -1); + } + + $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); + if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) + { + $destination = ''; + } + + // Move file and overwrite any existing image + $file->move_file($destination, true); + + if (sizeof($file->error)) + { + $file->remove(); + $error = array_merge($error, $file->error); + return false; + } + + return array( + 'user_avatar' => $user_row['user_id'] . '_' . time() . '.' . $file->get('extension'), + 'user_avatar_width' => $file->get('width'), + 'user_avatar_height' => $file->get('height'), + ); + } + + /** + * @TODO + */ + private function can_upload() + { + return (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')); + } } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index a815ec7987..a712547bd1 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -568,7 +568,7 @@ class ucp_profile { if (check_form_key('ucp_avatar')) { - $result = $avatar->handle_form($template, $user->data, $error, true); + $result = $avatar->process_form($template, $user->data, $error); if ($result && empty($error)) { @@ -592,7 +592,7 @@ class ucp_profile } } - if ($avatar->handle_form($template, $user->data, $error)) { + if ($avatar->prepare_form($template, $user->data, $error)) { $driver_u = strtoupper($driver); $template->assign_block_vars('avatar_drivers', array( From 84099e5bc1f452e1a4643fd78658929875ab1eee Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Wed, 20 Apr 2011 23:14:38 -0700 Subject: [PATCH 011/138] [feature/avatars] Support proper avatar deletion, stub ACP Fixing avatar deletion in the UCP and ACP, and stubbing the ACP configuration page. I'll admit I kind of got caught carried away, so this really should be a couple separate commits. PHPBB3-10018 --- phpBB/adm/style/acp_avatar_options_local.html | 14 +++ .../adm/style/acp_avatar_options_remote.html | 11 +++ .../adm/style/acp_avatar_options_upload.html | 11 +++ phpBB/adm/style/acp_users_avatar.html | 87 ++++--------------- phpBB/includes/acp/acp_users.php | 9 +- phpBB/includes/avatar/driver.php | 8 ++ phpBB/includes/avatar/driver/upload.php | 16 ++++ phpBB/includes/avatar/manager.php | 14 +++ phpBB/includes/functions_user.php | 1 + phpBB/includes/ucp/ucp_profile.php | 33 +++++++ .../template/ucp_avatar_options.html | 7 +- 11 files changed, 130 insertions(+), 81 deletions(-) create mode 100644 phpBB/adm/style/acp_avatar_options_local.html create mode 100644 phpBB/adm/style/acp_avatar_options_remote.html create mode 100644 phpBB/adm/style/acp_avatar_options_upload.html diff --git a/phpBB/adm/style/acp_avatar_options_local.html b/phpBB/adm/style/acp_avatar_options_local.html new file mode 100644 index 0000000000..0dd83db017 --- /dev/null +++ b/phpBB/adm/style/acp_avatar_options_local.html @@ -0,0 +1,14 @@ + + + + diff --git a/phpBB/adm/style/acp_avatar_options_remote.html b/phpBB/adm/style/acp_avatar_options_remote.html new file mode 100644 index 0000000000..02704c5be8 --- /dev/null +++ b/phpBB/adm/style/acp_avatar_options_remote.html @@ -0,0 +1,11 @@ +
+

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
+
+
+

{L_LINK_REMOTE_SIZE_EXPLAIN}
+
+ ×  + +
+
diff --git a/phpBB/adm/style/acp_avatar_options_upload.html b/phpBB/adm/style/acp_avatar_options_upload.html new file mode 100644 index 0000000000..9c8dd9af01 --- /dev/null +++ b/phpBB/adm/style/acp_avatar_options_upload.html @@ -0,0 +1,11 @@ +
+
+
+
+ + +
+

{L_UPLOAD_AVATAR_URL_EXPLAIN}
+
+
+ diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index 35d8374237..3d6754830b 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -1,78 +1,23 @@ -
enctype="multipart/form-data"> +
{L_ACP_USER_AVATAR} -
-

{L_AVATAR_EXPLAIN}
-
{AVATAR_IMAGE}
-
-
- - -
-
-
-
- - -
-

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- - -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
-
-
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
-
{L_PIXEL} × {L_PIXEL}
-
- - -
-
-
-
- - -
- +

{ERROR}

+
+

{L_AVATAR_EXPLAIN}
+
{AVATAR}
+
+
+ +
- {L_AVATAR_GALLERY} -
-
-
 
-
-
- - - - - - - - - - - - - -
{avatar_row.avatar_column.AVATAR_NAME}
-
+ {avatar_drivers.L_TITLE} +

{avatar_drivers.L_EXPLAIN}

+ {avatar_drivers.OUTPUT}
- -
- +
+   +
- - -
- -
- - {S_FORM_TOKEN} -
- +
diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 390e421a51..5dc1829e8b 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -452,10 +452,10 @@ class acp_users { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } - + $sql_ary = array( 'user_avatar' => '', - 'user_avatar_type' => 0, + 'user_avatar_type' => '', 'user_avatar_width' => 0, 'user_avatar_height' => 0, ); @@ -466,9 +466,10 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present - if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY) + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + if ($driver = $avatar_manager->get_driver($user_row['user_avatar_type'])) { - avatar_delete('user', $user_row); + $driver->delete($user_row); } add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']); diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver.php index 5d3b734f7b..5322f73c60 100644 --- a/phpBB/includes/avatar/driver.php +++ b/phpBB/includes/avatar/driver.php @@ -114,4 +114,12 @@ abstract class phpbb_avatar_driver { return false; } + + /** + * @TODO + **/ + public function delete($user_row) + { + return true; + } } diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index dd1dbfa5a0..5b487745b1 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -121,6 +121,22 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver ); } + /** + * @inheritdoc + */ + public function delete($user_row) + { + $ext = substr(strrchr($user_row['user_avatar'], '.'), 1); + $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $user_row['user_id'] . '.' . $ext; + + if (file_exists($filename)) + { + @unlink($filename); + } + + return true; + } + /** * @TODO */ diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 6471c4cc9c..7137243898 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -47,6 +47,20 @@ class phpbb_avatar_manager $this->load_valid_drivers(); } + // Legacy stuff... + switch ($avatar_type) + { + case AVATAR_LOCAL: + $avatar_type = 'local'; + break; + case AVATAR_UPLOAD: + $avatar_type = 'upload'; + break; + case AVATAR_REMOTE: + $avatar_type = 'remote'; + break; + } + if (isset(self::$valid_drivers[$avatar_type])) { if ($new || !is_object(self::$valid_drivers[$avatar_type])) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 509e1a953c..9035cac7be 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1968,6 +1968,7 @@ function avatar_delete($mode, $row, $clean_db = false) avatar_remove_db($row[$mode . '_avatar']); } $filename = get_avatar_filename($row[$mode . '_avatar']); + if (file_exists($phpbb_root_path . $config['avatar_path'] . '/' . $filename)) { @unlink($phpbb_root_path . $config['avatar_path'] . '/' . $filename); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index a712547bd1..222d9e0af4 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -553,6 +553,39 @@ class ucp_profile if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + + if (isset($_POST['av_delete'])) + { + if (check_form_key('ucp_avatar')) + { + $result = array( + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_width' => 0, + 'user_avatar_height' => 0, + ); + + if ($driver = $avatar_manager->get_driver($user->data['user_avatar_type'])) + { + $driver->delete($user->data); + } + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE user_id = ' . $user->data['user_id']; + + $db->sql_query($sql); + + meta_refresh(3, $this->u_action); + $message = $user->lang['PROFILE_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); + trigger_error($message); + } + else + { + $error[] = 'FORM_INVALID'; + } + } + $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index e30fcc74aa..f05e96410d 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -10,7 +10,7 @@

{L_AVATAR_EXPLAIN}
{AVATAR}
-
+
@@ -27,10 +27,5 @@ -
- - -
- From 6d0f2e478800e1e9696701eeff00ac69c1e57dee Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Wed, 15 Jun 2011 12:38:17 -0700 Subject: [PATCH 012/138] [feature/avatars] Fixing typos in avatar manager and local avatars See above PHPBB3-10018 --- phpBB/includes/avatar/driver/local.php | 2 +- phpBB/includes/avatar/manager.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 47ae143ec9..216ad2ce46 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -70,7 +70,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver foreach ($avatar_list[$category] as $img => $data) { $template->assign_block_vars('av_local_imgs', array( - 'AVATAR_IMAGE' => $path . '/' . $data['file'], + 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $data['file'], 'AVATAR_NAME' => $data['name'], 'AVATAR_FILE' => $data['filename'], )); diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 7137243898..001fcf2f14 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -50,7 +50,7 @@ class phpbb_avatar_manager // Legacy stuff... switch ($avatar_type) { - case AVATAR_LOCAL: + case AVATAR_GALLERY: $avatar_type = 'local'; break; case AVATAR_UPLOAD: From 22c864cb3a945b52fe9b91765d247abfe00b50bc Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Wed, 15 Jun 2011 12:58:02 -0700 Subject: [PATCH 013/138] [feature/avatars] Dynamically list the avatar types in UCP and ACP List the avatar types more nicely, adding UCP modify user support PHPBB3-10018 --- phpBB/adm/style/acp_users_avatar.html | 6 +- phpBB/includes/acp/acp_users.php | 136 ++++++++++++++++++-------- phpBB/includes/ucp/ucp_profile.php | 9 +- 3 files changed, 103 insertions(+), 48 deletions(-) diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index 3d6754830b..c0ec9e5f8c 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -5,8 +5,8 @@

{ERROR}


{L_AVATAR_EXPLAIN}
-
{AVATAR}
-
+
{AVATAR}
+
@@ -16,8 +16,8 @@ {avatar_drivers.OUTPUT}
-  
+ {S_FORM_TOKEN} diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 5dc1829e8b..9c8a1c683e 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1683,65 +1683,117 @@ class acp_users case 'avatar': include($phpbb_root_path . 'includes/functions_display.' . $phpEx); - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false; - - if ($submit) + $avatars_enabled = false; + if ($config['allow_avatar']) { + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); - if (!check_form_key($form_name)) + if (isset($_POST['av_delete'])) { + if (!check_form_key($form_name)) + { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); + } + + $result = array( + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_height' => 0, + 'user_avatar_width' => 0, + ); + + if ($driver = $avatar_manager->get_driver($user_row['user_avatar_type'])) + { + $driver->delete($user_row); + } + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE user_id = ' . $user_id; + + $db->sql_query($sql); + trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); } - if (avatar_process_user($error, $user_row, $can_upload)) + $avatar_drivers = $avatar_manager->get_valid_drivers(); + sort($avatar_drivers); + + foreach ($avatar_drivers as $driver) { - trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_row['user_id'])); + if ($config["allow_avatar_$driver"]) + { + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => "acp_avatar_options_$driver.html", + )); + + $avatar = $avatar_manager->get_driver($driver); + if (isset($_POST["submit_av_$driver"])) + { + if (!check_form_key($form_name)) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); + } + + $result = $avatar->process_form($template, $user_row, $error); + + if ($result && empty($error)) + { + // Success! Lets save the result in the database + $result['user_avatar_type'] = $driver; + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE user_id = ' . $user_id; + + $db->sql_query($sql); + trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); + } + } + + if ($avatar->prepare_form($template, $user_row, $error)) + { + $driver_u = strtoupper($driver); + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_TITLE'), // @TODO add lang values + 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'), + 'DRIVER' => $driver, + 'OUTPUT' => $template->assign_display('avatar'), + )); + } + } } - - // Replace "error" strings with their real, localised form - $error = array_map(array($user, 'lang'), $error); } - if (!$config['allow_avatar'] && $user_row['user_avatar_type']) + // Replace "error" strings with their real, localised form + $err = $error; + $error = array(); + foreach ($err as $e) { - $error[] = $user->lang['USER_AVATAR_NOT_ALLOWED']; - } - else if ((($user_row['user_avatar_type'] == AVATAR_UPLOAD) && !$config['allow_avatar_upload']) || - (($user_row['user_avatar_type'] == AVATAR_REMOTE) && !$config['allow_avatar_remote']) || - (($user_row['user_avatar_type'] == AVATAR_GALLERY) && !$config['allow_avatar_local'])) - { - $error[] = $user->lang['USER_AVATAR_TYPE_NOT_ALLOWED']; - } - - // Generate users avatar - $avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row, 'USER_AVATAR', true) : ''; - - $display_gallery = (isset($_POST['display_gallery'])) ? true : false; - $avatar_select = basename(request_var('avatar_select', '')); - $category = basename(request_var('category', '')); - - if ($config['allow_avatar_local'] && $display_gallery) - { - avatar_gallery($category, $avatar_select, 4); + if (is_array($e)) + { + $key = array_shift($e); + $error[] = vsprintf($user->lang($key), $e); + } + else + { + $error[] = $user->lang((string) $e); + } } + + $avatar = get_user_avatar($user_row, 'USER_AVATAR', true); $template->assign_vars(array( - 'S_AVATAR' => true, - 'S_CAN_UPLOAD' => $can_upload, - 'S_UPLOAD_FILE' => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_upload']) ? true : false, - 'S_REMOTE_UPLOAD' => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_remote_upload']) ? true : false, - 'S_ALLOW_REMOTE' => ($config['allow_avatar'] && $config['allow_avatar_remote']) ? true : false, - 'S_DISPLAY_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery) ? true : false, - 'S_IN_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery) ? true : false, + 'S_AVATAR' => true, + 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', + 'AVATAR' => (empty($avatar) ? '' : $avatar), + 'AV_SHOW_DELETE' => !empty($avatar), - 'AVATAR_IMAGE' => $avatar_img, - 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], - 'USER_AVATAR_WIDTH' => $user_row['user_avatar_width'], - 'USER_AVATAR_HEIGHT' => $user_row['user_avatar_height'], + 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', - 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(), + 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024), + + 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), )); break; diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 222d9e0af4..bcafd3d636 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -589,8 +589,10 @@ class ucp_profile $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); - foreach ($avatar_drivers as $driver) { - if ($config["allow_avatar_$driver"]) { + foreach ($avatar_drivers as $driver) + { + if ($config["allow_avatar_$driver"]) + { $avatars_enabled = true; $template->set_filenames(array( 'avatar' => "ucp_avatar_options_$driver.html", @@ -625,7 +627,8 @@ class ucp_profile } } - if ($avatar->prepare_form($template, $user->data, $error)) { + if ($avatar->prepare_form($template, $user->data, $error)) + { $driver_u = strtoupper($driver); $template->assign_block_vars('avatar_drivers', array( From 6deadc3acf302e9fd15adfd6bff5f0fe525240c7 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sat, 18 Jun 2011 21:12:29 -0700 Subject: [PATCH 014/138] [feature/avatars] Rework UCP to be simpler/more consistent Redesigning the UCP avatar page to use javascript to make use less confusing. This design is also more easily transfered to the ACP for group avatars, which will give better consistency in the long run. PHPBB3-10018 --- phpBB/includes/avatar/driver/remote.php | 2 + phpBB/includes/ucp/ucp_profile.php | 69 +++++++++++++------ .../template/ucp_avatar_options.html | 49 +++++++++++-- 3 files changed, 94 insertions(+), 26 deletions(-) diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 32f93c7928..c28eed93da 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -72,6 +72,8 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver $url = 'http://' . $url; } + require_once($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); + $error = array_merge($error, validate_data(array( 'url' => $url, ), array( diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index bcafd3d636..d5f3ec4b81 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -554,31 +554,60 @@ class ucp_profile { $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); - if (isset($_POST['av_delete'])) + $avatar_drivers = $avatar_manager->get_valid_drivers(); + sort($avatar_drivers); + + if ($submit) { if (check_form_key('ucp_avatar')) { - $result = array( - 'user_avatar' => '', - 'user_avatar_type' => '', - 'user_avatar_width' => 0, - 'user_avatar_height' => 0, - ); - - if ($driver = $avatar_manager->get_driver($user->data['user_avatar_type'])) + $driver = request_var('avatar_driver', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $driver->delete($user->data); + $avatar = $avatar_manager->get_driver($driver); + $result = $avatar->process_form($template, $user->data, $error); + + if ($result && empty($error)) + { + // Success! Lets save the result in the database + $result['user_avatar_type'] = $driver; + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE user_id = ' . $user->data['user_id']; + + $db->sql_query($sql); + + meta_refresh(3, $this->u_action); + $message = $user->lang['PROFILE_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); + trigger_error($message); + } } - - $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user->data['user_id']; + else + { + // They are removing their avatar or are trying to play games with us + if ($avatar = $avatar_manager->get_driver($user->data['user_avatar_type'])) + { + $avatar->delete($user->data); + } - $db->sql_query($sql); + $result = array( + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_width' => 0, + 'user_avatar_height' => 0, + ); - meta_refresh(3, $this->u_action); - $message = $user->lang['PROFILE_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); - trigger_error($message); + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE user_id = ' . $user->data['user_id']; + + $db->sql_query($sql); + + meta_refresh(3, $this->u_action); + $message = $user->lang['PROFILE_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); + trigger_error($message); + } } else { @@ -586,9 +615,6 @@ class ucp_profile } } - $avatar_drivers = $avatar_manager->get_valid_drivers(); - sort($avatar_drivers); - foreach ($avatar_drivers as $driver) { if ($config["allow_avatar_$driver"]) @@ -636,6 +662,7 @@ class ucp_profile 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'), 'DRIVER' => $driver, + 'SELECTED' => ($driver == $user->data['user_avatar_type']), 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index f05e96410d..eb78e9f77c 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -10,22 +10,61 @@

{L_AVATAR_EXPLAIN}
{AVATAR}
-
- +

{L_AVATAR_SELECT_NEW}

+
+
+
+
+
+
-

{avatar_drivers.L_TITLE}

+
+

{avatar_drivers.L_EXPLAIN}

{avatar_drivers.OUTPUT}
+
+ +
  - +
- + + + From d0bb14ded1960de47eb07d955a483d74fd9e0af2 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sat, 18 Jun 2011 22:05:54 -0700 Subject: [PATCH 015/138] [feature/avatars] Update ACP manage users, fix gallery focus issue Updated ACP to match UCP with dropdown. Correctly determe which avatar to focus on by checking if the form was submitted and avatar_driver is set. PHPBB3-10018 --- phpBB/adm/style/acp_users_avatar.html | 56 ++++++++++++++---- phpBB/includes/acp/acp_users.php | 84 ++++++++++++++------------- phpBB/includes/avatar/driver.php | 2 +- phpBB/includes/ucp/ucp_profile.php | 31 +--------- 4 files changed, 92 insertions(+), 81 deletions(-) diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index c0ec9e5f8c..6316ff4a22 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -6,18 +6,52 @@

{L_AVATAR_EXPLAIN}
{AVATAR}
-
- -
- {avatar_drivers.L_TITLE} -

{avatar_drivers.L_EXPLAIN}

- {avatar_drivers.OUTPUT} -
-
- -
- +
+ {L_AVATAR_SELECT_NEW} +
+
+
+
+
+ +
+

{avatar_drivers.L_EXPLAIN}

+ {avatar_drivers.OUTPUT} +
+ +
+
+ + +
+ +
{S_FORM_TOKEN} diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 9c8a1c683e..bcce458e20 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1689,53 +1689,17 @@ class acp_users { $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); - if (isset($_POST['av_delete'])) - { - if (!check_form_key($form_name)) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); - } - - $result = array( - 'user_avatar' => '', - 'user_avatar_type' => '', - 'user_avatar_height' => 0, - 'user_avatar_width' => 0, - ); - - if ($driver = $avatar_manager->get_driver($user_row['user_avatar_type'])) - { - $driver->delete($user_row); - } - - $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user_id; - - $db->sql_query($sql); - trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); - } - $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); - foreach ($avatar_drivers as $driver) + if ($submit) { - if ($config["allow_avatar_$driver"]) + if (check_form_key($form_name)) { - $avatars_enabled = true; - $template->set_filenames(array( - 'avatar' => "acp_avatar_options_$driver.html", - )); - - $avatar = $avatar_manager->get_driver($driver); - if (isset($_POST["submit_av_$driver"])) + $driver = request_var('avatar_driver', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - if (!check_form_key($form_name)) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); - } - + $avatar = $avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $user_row, $error); if ($result && empty($error)) @@ -1750,6 +1714,42 @@ class acp_users trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); } } + else + { + // Removing the avatar + $result = array( + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_width' => 0, + 'user_avatar_height' => 0, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE user_id = ' . $user_id; + + $db->sql_query($sql); + trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); + } + } + else + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); + } + } + + $focused_driver = request_var('avatar_driver', $user_row['user_avatar_type']); + + foreach ($avatar_drivers as $driver) + { + if ($config["allow_avatar_$driver"]) + { + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => "acp_avatar_options_$driver.html", + )); + + $avatar = $avatar_manager->get_driver($driver); if ($avatar->prepare_form($template, $user_row, $error)) { @@ -1757,7 +1757,9 @@ class acp_users $template->assign_block_vars('avatar_drivers', array( 'L_TITLE' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_TITLE'), // @TODO add lang values 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'), + 'DRIVER' => $driver, + 'SELECTED' => ($driver == $focused_driver), 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver.php index 5322f73c60..1ed5b1a5f7 100644 --- a/phpBB/includes/avatar/driver.php +++ b/phpBB/includes/avatar/driver.php @@ -102,7 +102,7 @@ abstract class phpbb_avatar_driver /** * @TODO **/ - public function prepare_form($template, $user_row, &$error) + public function prepare_form($template, $user_row, &$error, &$override_focus) { return false; } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index d5f3ec4b81..186c023798 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -615,6 +615,8 @@ class ucp_profile } } + $focused_driver = request_var('avatar_driver', $user->data['user_avatar_type']); + foreach ($avatar_drivers as $driver) { if ($config["allow_avatar_$driver"]) @@ -625,33 +627,6 @@ class ucp_profile )); $avatar = $avatar_manager->get_driver($driver); - if (isset($_POST["submit_av_$driver"])) - { - if (check_form_key('ucp_avatar')) - { - $result = $avatar->process_form($template, $user->data, $error); - - if ($result && empty($error)) - { - // Success! Lets save the result in the database - $result['user_avatar_type'] = $driver; - - $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user->data['user_id']; - - $db->sql_query($sql); - - meta_refresh(3, $this->u_action); - $message = $user->lang['PROFILE_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); - trigger_error($message); - } - } - else - { - $error[] = 'FORM_INVALID'; - } - } if ($avatar->prepare_form($template, $user->data, $error)) { @@ -662,7 +637,7 @@ class ucp_profile 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'), 'DRIVER' => $driver, - 'SELECTED' => ($driver == $user->data['user_avatar_type']), + 'SELECTED' => ($driver == $focused_driver), 'OUTPUT' => $template->assign_display('avatar'), )); } From a06380c69a154659f4f9985238008640670669e0 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sat, 18 Jun 2011 22:50:52 -0700 Subject: [PATCH 016/138] [feature/avatars] Make avatars generic Adding a cleaning function for data coming from the users/groups tables so drivers only deal with clean data (ideally). Refactored get_user_avatar() and get_group_avatar() to use an underlying get_avatar() function. PHPBB3-10018 --- phpBB/includes/avatar/driver.php | 69 +++++++++++++++++++++---- phpBB/includes/avatar/driver/local.php | 18 +++---- phpBB/includes/avatar/driver/remote.php | 24 ++++----- phpBB/includes/avatar/driver/upload.php | 26 +++++----- phpBB/includes/functions_display.php | 66 ++++++++++++----------- phpBB/includes/ucp/ucp_profile.php | 16 ++++-- 6 files changed, 141 insertions(+), 78 deletions(-) diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver.php index 1ed5b1a5f7..d158c419bd 100644 --- a/phpBB/includes/avatar/driver.php +++ b/phpBB/includes/avatar/driver.php @@ -44,6 +44,12 @@ abstract class phpbb_avatar_driver * @type phpbb_cache_driver_interface */ protected $cache; + + /** + * @TODO + */ + const FROM_USER = 0; + const FROM_GROUP = 1; /** * This flag should be set to true if the avatar requires a nonstandard image @@ -71,12 +77,12 @@ abstract class phpbb_avatar_driver /** * Get the avatar url and dimensions * - * @param $ignore_config Whether this function should respect the users/board - * configuration option, or should just render the avatar anyways. - * Useful for the ACP. + * @param $ignore_config Whether this function should respect the users prefs + * and board configuration configuration option, or should just render + * the avatar anyways. Useful for the ACP. * @return array Avatar data */ - public function get_data($user_row, $ignore_config = false) + public function get_data($row, $ignore_config = false) { return array( 'src' => '', @@ -89,12 +95,12 @@ abstract class phpbb_avatar_driver * Returns custom html for displaying this avatar. * Only called if $custom_html is true. * - * @param $ignore_config Whether this function should respect the users/board - * configuration option, or should just render the avatar anyways. - * Useful for the ACP. + * @param $ignore_config Whether this function should respect the users prefs + * and board configuration configuration option, or should just render + * the avatar anyways. Useful for the ACP. * @return string HTML */ - public function get_custom_html($user_row, $ignore_config = false) + public function get_custom_html($row, $ignore_config = false) { return ''; } @@ -102,7 +108,7 @@ abstract class phpbb_avatar_driver /** * @TODO **/ - public function prepare_form($template, $user_row, &$error, &$override_focus) + public function prepare_form($template, $row, &$error, &$override_focus) { return false; } @@ -110,7 +116,7 @@ abstract class phpbb_avatar_driver /** * @TODO **/ - public function process_form($template, $user_row, &$error) + public function process_form($template, $row, &$error) { return false; } @@ -118,8 +124,49 @@ abstract class phpbb_avatar_driver /** * @TODO **/ - public function delete($user_row) + public function delete($row) { return true; } + + /** + * @TODO + **/ + public static function clean_row($row, $src = phpbb_avatar_driver::FROM_USER) + { + $return = array(); + $prefix = false; + + if ($src == phpbb_avatar_driver::FROM_USER) + { + $prefix = 'user_'; + } + else if ($src == phpbb_avatar_driver::FROM_GROUP) + { + $prefix = 'group_'; + } + + if ($prefix) + { + $len = strlen($prefix); + foreach ($row as $key => $val) + { + $sub = substr($key, 0, $len); + if ($sub == $prefix) + { + $return[substr($key, $len)] = $val; + } + else + { + $return[$key] = $val; + } + } + } + else + { + $return = $row; + } + + return $return; + } } diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 216ad2ce46..edd62696f0 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -24,14 +24,14 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function get_data($user_row, $ignore_config = false) + public function get_data($row, $ignore_config = false) { if ($ignore_config || $this->config['allow_avatar_local']) { return array( - 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $user_row['user_avatar'], - 'width' => $user_row['user_avatar_width'], - 'height' => $user_row['user_avatar_height'], + 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], ); } else @@ -47,7 +47,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($template, $user_row, &$error) + public function prepare_form($template, $row, &$error) { $avatar_list = $this->get_avatar_list(); $category = request_var('av_local_cat', ''); @@ -83,7 +83,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($template, $user_row, &$error) + public function process_form($template, $row, &$error) { $avatar_list = $this->get_avatar_list(); $category = request_var('av_local_cat', ''); @@ -96,9 +96,9 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver } return array( - 'user_avatar' => $category . '/' . $file, - 'user_avatar_width' => $avatar_list[$category][urldecode($file)]['width'], - 'user_avatar_height' => $avatar_list[$category][urldecode($file)]['height'], + 'avatar' => $category . '/' . $file, + 'avatar_width' => $avatar_list[$category][urldecode($file)]['width'], + 'avatar_height' => $avatar_list[$category][urldecode($file)]['height'], ); } diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index c28eed93da..cad9850c3f 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -24,14 +24,14 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function get_data($user_row, $ignore_config = false) + public function get_data($row, $ignore_config = false) { if ($ignore_config || $this->config['allow_avatar_remote']) { return array( - 'src' => $user_row['user_avatar'], - 'width' => $user_row['user_avatar_width'], - 'height' => $user_row['user_avatar_height'], + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], ); } else @@ -47,12 +47,12 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($template, $user_row, &$error) + public function prepare_form($template, $row, &$error) { $template->assign_vars(array( - 'AV_REMOTE_WIDTH' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar_width']) ? $user_row['user_avatar_width'] : request_var('av_local_width', 0), - 'AV_REMOTE_HEIGHT' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar_height']) ? $user_row['user_avatar_height'] : request_var('av_local_width', 0), - 'AV_REMOTE_URL' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar']) ? $user_row['user_avatar'] : '', + 'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : request_var('av_local_width', 0), + 'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : request_var('av_local_width', 0), + 'AV_REMOTE_URL' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar']) ? $row['avatar'] : '', )); return true; @@ -61,7 +61,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($template, $user_row, &$error) + public function process_form($template, $row, &$error) { $url = request_var('av_remote_url', ''); $width = request_var('av_remote_width', 0); @@ -155,9 +155,9 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver } return array( - 'user_avatar' => $url, - 'user_avatar_width' => $width, - 'user_avatar_height' => $height, + 'avatar' => $url, + 'avatar_width' => $width, + 'avatar_height' => $height, ); } } diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 5b487745b1..23521ef435 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -24,14 +24,14 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc */ - public function get_data($user_row, $ignore_config = false) + public function get_data($row, $ignore_config = false) { if ($ignore_config || $this->config['allow_avatar_upload']) { return array( - 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $user_row['user_avatar'], - 'width' => $user_row['user_avatar_width'], - 'height' => $user_row['user_avatar_height'], + 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], ); } else @@ -47,7 +47,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($template, $user_row, &$error) + public function prepare_form($template, $row, &$error) { if (!$this->can_upload()) { @@ -65,7 +65,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($template, $user_row, &$error) + public function process_form($template, $row, &$error) { if (!$this->can_upload()) { @@ -88,7 +88,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver } $prefix = $this->config['avatar_salt'] . '_'; - $file->clean_filename('avatar', $prefix, $user_row['user_id']); + $file->clean_filename('avatar', $prefix, $row['id']); $destination = $this->config['avatar_path']; @@ -115,19 +115,19 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver } return array( - 'user_avatar' => $user_row['user_id'] . '_' . time() . '.' . $file->get('extension'), - 'user_avatar_width' => $file->get('width'), - 'user_avatar_height' => $file->get('height'), + 'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'), + 'avatar_width' => $file->get('width'), + 'avatar_height' => $file->get('height'), ); } /** * @inheritdoc */ - public function delete($user_row) + public function delete($row) { - $ext = substr(strrchr($user_row['user_avatar'], '.'), 1); - $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $user_row['user_id'] . '.' . $ext; + $ext = substr(strrchr($row['avatar'], '.'), 1); + $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext; if (file_exists($filename)) { diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 23900dfd88..b82f004505 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1279,6 +1279,36 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank * @return string Avatar html */ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) +{ + $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_USER); + return get_avatar($row, $alt, $ignore_config); +} + +/** +* Get group avatar +* +* @param array $group_row Row from the groups table +* @param string $alt Optional language string for alt tag within image, can be a language key or text +* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP +* +* @return string Avatar html +*/ +function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) +{ + $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_GROUP); + return get_avatar($row, $alt, $ignore_config); +} + +/** +* Get avatar +* +* @param array $row Row cleaned by phpbb_avatar_driver::clean_row +* @param string $alt Optional language string for alt tag within image, can be a language key or text +* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP +* +* @return string Avatar html +*/ +function get_avatar($row, $alt, $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; @@ -1290,12 +1320,12 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false } $avatar_data = array( - 'src' => $user_row['user_avatar'], - 'width' => $user_row['user_avatar_width'], - 'height' => $user_row['user_avatar_height'], + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], ); - switch ($user_row['user_avatar_type']) + switch ($row['avatar_type']) { case AVATAR_UPLOAD: // Compatibility with old avatars @@ -1341,16 +1371,16 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->get_driver()); } - $avatar = $avatar_manager->get_driver($user_row['user_avatar_type']); + $avatar = $avatar_manager->get_driver($row['avatar_type']); if ($avatar) { if ($avatar->custom_html) { - return $avatar->get_html($user_row, $ignore_config); + return $avatar->get_html($row, $ignore_config); } - $avatar_data = $avatar->get_data($user_row, $ignore_config); + $avatar_data = $avatar->get_data($row, $ignore_config); } else { @@ -1372,25 +1402,3 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false return $html; } - -/** -* Get group avatar -* -* @param array $group_row Row from the groups table -* @param string $alt Optional language string for alt tag within image, can be a language key or text -* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP -* -* @return string Avatar html -*/ -function get_group_avatar($group_row, $alt = 'GROUP_AVATAR', $ignore_config = false) -{ - // Kind of abusing this functionality... - $avatar_row = array( - 'user_avatar' => $group_row['group_avatar'], - 'user_avatar_type' => $group_row['group_avatar_type'], - 'user_avatar_width' => $group_row['group_avatar_width'], - 'user_avatar_height' => $group_row['group_avatar_height'], - ); - - return get_user_avatar($group_row, $alt, $ignore_config); -} diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 186c023798..1c469fa290 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -556,6 +556,9 @@ class ucp_profile $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); + + // This is normalised data, without the user_ prefix + $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver::FROM_USER); if ($submit) { @@ -565,12 +568,17 @@ class ucp_profile if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { $avatar = $avatar_manager->get_driver($driver); - $result = $avatar->process_form($template, $user->data, $error); + $result = $avatar->process_form($template, $avatar_data, $error); if ($result && empty($error)) { // Success! Lets save the result in the database - $result['user_avatar_type'] = $driver; + $result = array( + 'user_avatar_type' => $driver, + 'user_avatar' => $result['avatar'], + 'user_avatar_width' => $result['avatar_width'], + 'user_avatar_height' => $result['avatar_height'], + ); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' @@ -588,7 +596,7 @@ class ucp_profile // They are removing their avatar or are trying to play games with us if ($avatar = $avatar_manager->get_driver($user->data['user_avatar_type'])) { - $avatar->delete($user->data); + $avatar->delete($avatar_data); } $result = array( @@ -628,7 +636,7 @@ class ucp_profile $avatar = $avatar_manager->get_driver($driver); - if ($avatar->prepare_form($template, $user->data, $error)) + if ($avatar->prepare_form($template, $avatar_data, $error)) { $driver_u = strtoupper($driver); From 8416bf3dc9539df19530e3bef85352d40ac795f2 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sat, 18 Jun 2011 23:49:04 -0700 Subject: [PATCH 017/138] [feature/avatars] Made ACP avatar gallery in Manage Users prettier Added row/column information so avatars can be displayed nicely in the ACP PHPBB3-10018 --- phpBB/adm/style/acp_avatar_options_local.html | 39 ++++++++++++------- phpBB/includes/acp/acp_users.php | 14 +++++-- phpBB/includes/avatar/driver/local.php | 32 ++++++++++++--- .../template/ucp_avatar_options_local.html | 10 +++-- 4 files changed, 68 insertions(+), 27 deletions(-) diff --git a/phpBB/adm/style/acp_avatar_options_local.html b/phpBB/adm/style/acp_avatar_options_local.html index 0dd83db017..0a50a4eed4 100644 --- a/phpBB/adm/style/acp_avatar_options_local.html +++ b/phpBB/adm/style/acp_avatar_options_local.html @@ -1,14 +1,25 @@ - - - - +
+
+
 
+
+
+ + + + + + + + + + + + + +
{av_local_row.av_local_col.AVATAR_NAME}
+
diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index bcce458e20..9b5c52e28e 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1692,6 +1692,9 @@ class acp_users $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); + // This is normalised data, without the user_ prefix + $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_USER); + if ($submit) { if (check_form_key($form_name)) @@ -1700,12 +1703,17 @@ class acp_users if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { $avatar = $avatar_manager->get_driver($driver); - $result = $avatar->process_form($template, $user_row, $error); + $result = $avatar->process_form($template, $avatar_data, $error); if ($result && empty($error)) { // Success! Lets save the result in the database - $result['user_avatar_type'] = $driver; + $result = array( + 'user_avatar_type' => $driver, + 'user_avatar' => $result['avatar'], + 'user_avatar_width' => $result['avatar_width'], + 'user_avatar_height' => $result['avatar_height'], + ); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' WHERE user_id = ' . $user_id; @@ -1751,7 +1759,7 @@ class acp_users $avatar = $avatar_manager->get_driver($driver); - if ($avatar->prepare_form($template, $user_row, $error)) + if ($avatar->prepare_form($template, $avatar_data, $error)) { $driver_u = strtoupper($driver); $template->assign_block_vars('avatar_drivers', array( diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index edd62696f0..85eda96018 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -51,7 +51,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver { $avatar_list = $this->get_avatar_list(); $category = request_var('av_local_cat', ''); - + $categories = array_keys($avatar_list); foreach ($categories as $cat) @@ -67,13 +67,33 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver if (!empty($avatar_list[$category])) { - foreach ($avatar_list[$category] as $img => $data) + $table_cols = isset($row['av_gallery_cols']) ? $row['av_gallery_cols'] : 4; + $row_count = $col_count = $av_pos = 0; + $av_count = sizeof($avatar_list[$category]); + + reset($avatar_list[$category]); + + while ($av_pos < $av_count) { - $template->assign_block_vars('av_local_imgs', array( - 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $data['file'], - 'AVATAR_NAME' => $data['name'], - 'AVATAR_FILE' => $data['filename'], + $img = current($avatar_list[$category]); + next($avatar_list[$category]); + + if ($col_count == 0) + { + ++$row_count; + $template->assign_block_vars('av_local_row', array( + )); + } + + $template->assign_block_vars('av_local_row.av_local_col', array( + 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'], + 'AVATAR_NAME' => $img['name'], + 'AVATAR_FILE' => $img['filename'], )); + + $col_count = ($col_count + 1) % $table_cols; + + ++$av_pos; } } diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html index 0dd83db017..9f726e2ff9 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html @@ -7,8 +7,10 @@ From 48e61b1b45655b38660740abb0de9704234af849 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 4 Jul 2011 16:58:35 -0700 Subject: [PATCH 018/138] [feature/avatars] Support editing of group avatars in ACP Edited templates for group avatars so they can be properly modified in ACP PHPBB3-10018 --- phpBB/adm/style/acp_avatar_options_local.html | 2 + phpBB/adm/style/acp_groups.html | 94 ++++----- phpBB/includes/acp/acp_groups.php | 184 +++++++++--------- phpBB/includes/acp/acp_users.php | 1 - phpBB/includes/avatar/driver/local.php | 4 + 5 files changed, 137 insertions(+), 148 deletions(-) diff --git a/phpBB/adm/style/acp_avatar_options_local.html b/phpBB/adm/style/acp_avatar_options_local.html index 0a50a4eed4..d762fa9008 100644 --- a/phpBB/adm/style/acp_avatar_options_local.html +++ b/phpBB/adm/style/acp_avatar_options_local.html @@ -8,6 +8,7 @@  
+ @@ -22,4 +23,5 @@
+
diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index 158751623a..1c78c0c344 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -104,66 +104,46 @@ {L_GROUP_AVATAR}

{L_AVATAR_EXPLAIN}
-
{AVATAR_IMAGE}
-
+
{AVATAR}
- - -
-
-
-
-
-

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
-
-
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
-
{L_PIXEL} × {L_PIXEL}
-
- -
-
-
-
- - - +
+
+
+
+
+ +
+

{avatar_drivers.L_EXPLAIN}

+ {avatar_drivers.OUTPUT} +
+ +
+
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 9ad157f78a..16ae8670ce 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -54,7 +54,6 @@ class acp_groups // Clear some vars - $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false; $group_row = array(); // Grab basic data for group, if group_id is set and exists @@ -281,8 +280,24 @@ class acp_groups $error = array(); $user->add_lang('ucp'); - $avatar_select = basename(request_var('avatar_select', '')); - $category = basename(request_var('category', '')); + // Setup avatar data for later + $avatars_enabled = false; + $avatar_manager = null; + $avatar_drivers = null; + $avatar_data = null; + $avatar_error = array(); + + if ($config['allow_avatar']) + { + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + + $avatar_drivers = $avatar_manager->get_valid_drivers(); + sort($avatar_drivers); + + // This is normalised data, without the group_ prefix + $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver::FROM_GROUP); + } + // Did we submit? if ($update) @@ -300,12 +315,6 @@ class acp_groups $allow_desc_urls = request_var('desc_parse_urls', false); $allow_desc_smilies = request_var('desc_parse_smilies', false); - $data['uploadurl'] = request_var('uploadurl', ''); - $data['remotelink'] = request_var('remotelink', ''); - $data['width'] = request_var('width', ''); - $data['height'] = request_var('height', ''); - $delete = request_var('delete', ''); - $submit_ary = array( 'colour' => request_var('group_colour', ''), 'rank' => request_var('group_rank', 0), @@ -322,81 +331,38 @@ class acp_groups { $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0; } - - if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) - { - // Avatar stuff - $var_ary = array( - 'uploadurl' => array('string', true, 5, 255), - 'remotelink' => array('string', true, 5, 255), - 'width' => array('string', true, 1, 3), - 'height' => array('string', true, 1, 3), - ); - - if (!($error = validate_data($data, $var_ary))) + + if ($config['allow_avatar']) { + // Handle avatar + $driver = request_var('avatar_driver', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $data['user_id'] = "g$group_id"; + $avatar = $avatar_manager->get_driver($driver); + $result = $avatar->process_form($template, $avatar_data, $avatar_error); - if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) + if ($result && empty($avatar_error)) { - list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error); - } - else if ($data['remotelink']) - { - list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error); + // Success! Lets save the result + + /* + $result = array( + 'avatar' => ..., + 'avatar_width' => ..., + 'avatar_height' => ..., + ); + */ + + $submit_ary = array_merge($submit_ary, $result); + $submit_ary['avatar_type'] = $driver; } } - } - else if ($avatar_select && $config['allow_avatar_local']) - { - // check avatar gallery - if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) + else { - $submit_ary['avatar_type'] = AVATAR_GALLERY; - - list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select); - $submit_ary['avatar'] = $category . '/' . $avatar_select; - } - } - else if ($delete) - { - $submit_ary['avatar'] = ''; - $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0; - } - else if ($data['width'] && $data['height']) - { - // Only update the dimensions? - if ($config['avatar_max_width'] || $config['avatar_max_height']) - { - if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) - { - $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); - } - } - - if (!sizeof($error)) - { - if ($config['avatar_min_width'] || $config['avatar_min_height']) - { - if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) - { - $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); - } - } - } - - if (!sizeof($error)) - { - $submit_ary['avatar_width'] = $data['width']; - $submit_ary['avatar_height'] = $data['height']; - } - } - - if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete) - { - if (isset($group_row['group_avatar']) && $group_row['group_avatar']) - { - avatar_delete('group', $group_row, true); + // Removing the avatar + $submit_ary['avatar_type'] = ''; + $submit_ary['avatar'] = ''; + $submit_ary['avatar_width'] = 0; + $submit_ary['avatar_height'] = 0; } } @@ -423,7 +389,7 @@ class acp_groups 'rank' => 'int', 'colour' => 'string', 'avatar' => 'string', - 'avatar_type' => 'int', + 'avatar_type' => 'string', 'avatar_width' => 'int', 'avatar_height' => 'int', 'receive_pm' => 'int', @@ -553,13 +519,54 @@ class acp_groups $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : ''; $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : ''; - $avatar_img = (!empty($group_row['group_avatar'])) ? get_group_avatar($group_row) : ''; - - $display_gallery = (isset($_POST['display_gallery'])) ? true : false; - - if ($config['allow_avatar_local'] && $display_gallery) + // Load up stuff for avatars + if ($config['allow_avatar']) { - avatar_gallery($category, $avatar_select, 4); + $avatars_enabled = false; + $focused_driver = request_var('avatar_driver', $avatar_data['avatar_type']); + + foreach ($avatar_drivers as $driver) + { + if ($config["allow_avatar_$driver"]) + { + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => "acp_avatar_options_$driver.html", + )); + + $avatar = $avatar_manager->get_driver($driver); + + if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) + { + $driver_u = strtoupper($driver); + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_TITLE'), // @TODO add lang values + 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'), + + 'DRIVER' => $driver, + 'SELECTED' => ($driver == $focused_driver), + 'OUTPUT' => $template->assign_display('avatar'), + )); + } + } + } + } + + $avatar = get_group_avatar($group_row, 'GROUP_AVATAR', true); + + // Merge any avatars errors into the primary error array + // Drivers use lang constants, so we need to map to the actual strings + foreach ($avatar_error as $e) + { + if (is_array($e)) + { + $key = array_shift($e); + $error[] = vsprintf($user->lang($key), $e); + } + else + { + $error[] = $user->lang((string) $e); + } } $back_link = request_var('back_link', ''); @@ -580,12 +587,10 @@ class acp_groups 'S_ADD_GROUP' => ($action == 'add') ? true : false, 'S_GROUP_PERM' => ($action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) ? true : false, 'S_INCLUDE_SWATCH' => true, - 'S_CAN_UPLOAD' => $can_upload, 'S_ERROR' => (sizeof($error)) ? true : false, 'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL) ? true : false, - 'S_DISPLAY_GALLERY' => ($config['allow_avatar_local'] && !$display_gallery) ? true : false, - 'S_IN_GALLERY' => ($config['allow_avatar_local'] && $display_gallery) ? true : false, 'S_USER_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false, + 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', 'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name, @@ -606,8 +611,7 @@ class acp_groups 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)), - 'AVATAR' => $avatar_img, - 'AVATAR_IMAGE' => $avatar_img, + 'AVATAR' => (empty($avatar) ? '' : $avatar), 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '', diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 9b5c52e28e..ad8e7532c0 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1797,7 +1797,6 @@ class acp_users 'S_AVATAR' => true, 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', 'AVATAR' => (empty($avatar) ? '' : $avatar), - 'AV_SHOW_DELETE' => !empty($avatar), 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 85eda96018..f87854315d 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -67,6 +67,10 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver if (!empty($avatar_list[$category])) { + $template->assign_vars(array( + 'AV_LOCAL_SHOW' => true, + )); + $table_cols = isset($row['av_gallery_cols']) ? $row['av_gallery_cols'] : 4; $row_count = $col_count = $av_pos = 0; $av_count = sizeof($avatar_list[$category]); From 3963b39634225a68687cf1b817a47ae1eeb6ac79 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 4 Jul 2011 17:19:18 -0700 Subject: [PATCH 019/138] [feature/avatars] Making schema changes for db tables These schema changes make manual column chaning uncessesary. PHPBB3-10018 --- phpBB/install/database_update.php | 4 ++++ phpBB/install/schemas/firebird_schema.sql | 4 ++-- phpBB/install/schemas/mssql_schema.sql | 4 ++-- phpBB/install/schemas/mysql_40_schema.sql | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 843e8c2f23..ba6d5d34e2 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1092,6 +1092,10 @@ function database_update_info() 'change_columns' => array( GROUPS_TABLE => array( 'group_legend' => array('UINT', 0), + 'group_avatar_type' => array('VCHAR:32', 0), + ), + USERS_TABLE => array( + 'user_avatar_type' => array('VCHAR:32', 0), ), ), 'drop_columns' => array( diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index daeba45864..8b5bc90afa 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -445,7 +445,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL, group_display INTEGER DEFAULT 0 NOT NULL, group_avatar VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - group_avatar_type INTEGER DEFAULT 0 NOT NULL, + group_avatar_type VARCHAR(32) CHARACTER SET NONE DEFAULT '' NOT NULL, group_avatar_width INTEGER DEFAULT 0 NOT NULL, group_avatar_height INTEGER DEFAULT 0 NOT NULL, group_rank INTEGER DEFAULT 0 NOT NULL, @@ -1317,7 +1317,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INTEGER DEFAULT 1 NOT NULL, user_options INTEGER DEFAULT 230271 NOT NULL, user_avatar VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - user_avatar_type INTEGER DEFAULT 0 NOT NULL, + user_avatar_type VARCHAR(32) CHARACTER SET NONE DEFAULT '' NOT NULL, user_avatar_width INTEGER DEFAULT 0 NOT NULL, user_avatar_height INTEGER DEFAULT 0 NOT NULL, user_sig BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 736917fdcb..65ef420877 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -553,7 +553,7 @@ CREATE TABLE [phpbb_groups] ( [group_desc_uid] [varchar] (8) DEFAULT ('') NOT NULL , [group_display] [int] DEFAULT (0) NOT NULL , [group_avatar] [varchar] (255) DEFAULT ('') NOT NULL , - [group_avatar_type] [int] DEFAULT (0) NOT NULL , + [group_avatar_type] [varchar] (32) DEFAULT ('') NOT NULL , [group_avatar_width] [int] DEFAULT (0) NOT NULL , [group_avatar_height] [int] DEFAULT (0) NOT NULL , [group_rank] [int] DEFAULT (0) NOT NULL , @@ -1603,7 +1603,7 @@ CREATE TABLE [phpbb_users] ( [user_allow_massemail] [int] DEFAULT (1) NOT NULL , [user_options] [int] DEFAULT (230271) NOT NULL , [user_avatar] [varchar] (255) DEFAULT ('') NOT NULL , - [user_avatar_type] [int] DEFAULT (0) NOT NULL , + [user_avatar_type] [varchar] (32) DEFAULT ('') NOT NULL , [user_avatar_width] [int] DEFAULT (0) NOT NULL , [user_avatar_height] [int] DEFAULT (0) NOT NULL , [user_sig] [text] DEFAULT ('') NOT NULL , diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 97c378621b..a41a55494c 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -317,7 +317,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varbinary(8) DEFAULT '' NOT NULL, group_display tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_avatar varbinary(255) DEFAULT '' NOT NULL, - group_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + group_avatar_type varbinary(32) DEFAULT '' NOT NULL, group_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -941,7 +941,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, user_options int(11) UNSIGNED DEFAULT '230271' NOT NULL, user_avatar varbinary(255) DEFAULT '' NOT NULL, - user_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + user_avatar_type varbinary(32) DEFAULT '' NOT NULL, user_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_sig mediumblob NOT NULL, From c7976279e1c85f921156ed499dee1e587587c693 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 18:59:24 +0200 Subject: [PATCH 020/138] [feature/avatars] Fix avatar driver filename for autoloading PHPBB3-10018 --- phpBB/includes/avatar/{ => driver}/driver.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename phpBB/includes/avatar/{ => driver}/driver.php (100%) diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver/driver.php similarity index 100% rename from phpBB/includes/avatar/driver.php rename to phpBB/includes/avatar/driver/driver.php From 3b0e0dba3279a78cab2336d32ee8ff63a7077c5c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 19:08:54 +0200 Subject: [PATCH 021/138] [feature/avatars] Remove unneeded require (class is now autoloaded) PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 001fcf2f14..a81b0d1e51 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -82,8 +82,6 @@ class phpbb_avatar_manager **/ private function load_valid_drivers() { - require_once($this->phpbb_root_path . 'includes/avatar/driver.' . $this->phpEx); - if ($this->cache) { self::$valid_drivers = $this->cache->get('avatar_drivers'); From e861bb0e04c08b03366ec7c58473b630acc91181 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 19:19:13 +0200 Subject: [PATCH 022/138] [feature/avatars] Use request object in avatar drivers PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 5 +++-- phpBB/includes/avatar/driver/driver.php | 12 ++++++++++-- phpBB/includes/avatar/driver/local.php | 8 ++++---- phpBB/includes/avatar/driver/remote.php | 12 ++++++------ phpBB/includes/avatar/driver/upload.php | 2 +- phpBB/includes/avatar/manager.php | 6 ++++-- phpBB/includes/functions_display.php | 3 ++- phpBB/includes/ucp/ucp_profile.php | 4 ++-- 9 files changed, 33 insertions(+), 21 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 16ae8670ce..0a22c216c7 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -289,7 +289,7 @@ class acp_groups if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index c0da9b8ce0..12da482dbe 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -32,6 +32,7 @@ class acp_users { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; + global $request; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; @@ -466,7 +467,7 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); if ($driver = $avatar_manager->get_driver($user_row['user_avatar_type'])) { $driver->delete($user_row); @@ -1687,7 +1688,7 @@ class acp_users $avatars_enabled = false; if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index d158c419bd..8fb80693fb 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -26,7 +26,13 @@ abstract class phpbb_avatar_driver * @type phpbb_config */ protected $config; - + + /** + * Current board configuration + * @type phpbb_config + */ + protected $request; + /** * Current $phpbb_root_path * @type string @@ -62,13 +68,15 @@ abstract class phpbb_avatar_driver * Construct an driver object * * @param $config The phpBB configuration + * @param $request The request object * @param $phpbb_root_path The path to the phpBB root * @param $phpEx The php file extension * @param $cache A cache driver */ - public function __construct(phpbb_config $config, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null) + public function __construct(phpbb_config $config, phpbb_request $request, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null) { $this->config = $config; + $this->request = $request; $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->cache = $cache; diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index f87854315d..27e451c099 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -50,7 +50,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function prepare_form($template, $row, &$error) { $avatar_list = $this->get_avatar_list(); - $category = request_var('av_local_cat', ''); + $category = $this->request->variable('av_local_cat', ''); $categories = array_keys($avatar_list); @@ -110,9 +110,9 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function process_form($template, $row, &$error) { $avatar_list = $this->get_avatar_list(); - $category = request_var('av_local_cat', ''); - - $file = request_var('av_local_file', ''); + $category = $this->request->variable('av_local_cat', ''); + + $file = $this->request->variable('av_local_file', ''); if (!isset($avatar_list[$category][urldecode($file)])) { $error[] = 'AVATAR_URL_NOT_FOUND'; diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index cad9850c3f..cd0a756428 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -50,8 +50,8 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver public function prepare_form($template, $row, &$error) { $template->assign_vars(array( - 'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : request_var('av_local_width', 0), - 'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : request_var('av_local_width', 0), + 'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0), + 'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0), 'AV_REMOTE_URL' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar']) ? $row['avatar'] : '', )); @@ -63,10 +63,10 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver */ public function process_form($template, $row, &$error) { - $url = request_var('av_remote_url', ''); - $width = request_var('av_remote_width', 0); - $height = request_var('av_remote_height', 0); - + $url = $this->request->variable('av_remote_url', ''); + $width = $this->request->variable('av_remote_width', 0); + $height = $this->request->variable('av_remote_height', 0); + if (!preg_match('#^(http|https|ftp)://#i', $url)) { $url = 'http://' . $url; diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 23521ef435..c7d2b870c1 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -76,7 +76,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $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_var('av_upload_url', ''); + $url = $this->request->variable('av_upload_url', ''); if (!empty($_FILES['av_upload_file']['name'])) { diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index a81b0d1e51..f9a262b92f 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -23,17 +23,19 @@ class phpbb_avatar_manager private $phpbb_root_path; private $phpEx; private $config; + private $request; private $cache; private static $valid_drivers = false; /** * @TODO **/ - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_cache_driver_interface $cache = null) + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache = null) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->config = $config; + $this->request = $request; $this->cache = $cache; } @@ -66,7 +68,7 @@ class phpbb_avatar_manager if ($new || !is_object(self::$valid_drivers[$avatar_type])) { $class_name = 'phpbb_avatar_driver_' . $avatar_type; - self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->phpbb_root_path, $this->phpEx, $this->cache); + self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache); } return self::$valid_drivers[$avatar_type]; diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 1c1663f2cc..c59805dacd 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1312,6 +1312,7 @@ function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = fal function get_avatar($row, $alt, $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; + global $request; static $avatar_manager = null; @@ -1369,7 +1370,7 @@ function get_avatar($row, $alt, $ignore_config = false) default: if (empty($avatar_manager)) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->get_driver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); } $avatar = $avatar_manager->get_driver($row['avatar_type']); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 1c469fa290..ffc6ebf556 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -552,8 +552,8 @@ class ucp_profile if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); - + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); + $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); From 0898d114574e88eb5eda819b8921a27739be74ca Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 20:27:11 +0200 Subject: [PATCH 023/138] [feature/avatars] Fix CS PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index f9a262b92f..41429f3a06 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -116,7 +116,8 @@ class phpbb_avatar_manager /** * @TODO **/ - public function get_valid_drivers() { + public function get_valid_drivers() + { if (self::$valid_drivers === false) { $this->load_valid_drivers(); From e8a9c0ae6d92822699de9a2d7fc1aae9377ade8a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:11:06 +0200 Subject: [PATCH 024/138] [feature/avatars] Fix avatar_type in create_schema_files PHPBB3-10018 --- phpBB/develop/create_schema_files.php | 4 ++-- phpBB/install/schemas/mssql_schema.sql | 2 +- phpBB/install/schemas/mysql_41_schema.sql | 4 ++-- phpBB/install/schemas/oracle_schema.sql | 4 ++-- phpBB/install/schemas/postgres_schema.sql | 4 ++-- phpBB/install/schemas/sqlite_schema.sql | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 4088657743..6418bb57f0 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1168,7 +1168,7 @@ function get_schema_struct() 'group_desc_uid' => array('VCHAR:8', ''), 'group_display' => array('BOOL', 0), 'group_avatar' => array('VCHAR', ''), - 'group_avatar_type' => array('TINT:2', 0), + 'group_avatar_type' => array('VCHAR:32', ''), 'group_avatar_width' => array('USINT', 0), 'group_avatar_height' => array('USINT', 0), 'group_rank' => array('UINT', 0), @@ -1821,7 +1821,7 @@ function get_schema_struct() 'user_allow_massemail' => array('BOOL', 1), 'user_options' => array('UINT:11', 230271), 'user_avatar' => array('VCHAR', ''), - 'user_avatar_type' => array('TINT:2', 0), + 'user_avatar_type' => array('VCHAR:32', ''), 'user_avatar_width' => array('USINT', 0), 'user_avatar_height' => array('USINT', 0), 'user_sig' => array('MTEXT_UNI', ''), diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 2cf60e9f02..516b030f5a 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -1109,7 +1109,7 @@ CREATE TABLE [phpbb_reports] ( [report_closed] [int] DEFAULT (0) NOT NULL , [report_time] [int] DEFAULT (0) NOT NULL , [report_text] [text] DEFAULT ('') NOT NULL , - [reported_post_text] [text] DEFAULT ('') NOT NULL + [reported_post_text] [text] DEFAULT ('') NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 3fd8d4f1d1..11286e2526 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -317,7 +317,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) DEFAULT '' NOT NULL, group_display tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_avatar varchar(255) DEFAULT '' NOT NULL, - group_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + group_avatar_type varchar(32) DEFAULT '' NOT NULL, group_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -917,7 +917,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, user_options int(11) UNSIGNED DEFAULT '230271' NOT NULL, user_avatar varchar(255) DEFAULT '' NOT NULL, - user_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + user_avatar_type varchar(32) DEFAULT '' NOT NULL, user_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_sig mediumtext NOT NULL, diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 8a0f3e56b1..3bc6a853ca 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -610,7 +610,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar2(8) DEFAULT '' , group_display number(1) DEFAULT '0' NOT NULL, group_avatar varchar2(255) DEFAULT '' , - group_avatar_type number(2) DEFAULT '0' NOT NULL, + group_avatar_type varchar2(32) DEFAULT '' , group_avatar_width number(4) DEFAULT '0' NOT NULL, group_avatar_height number(4) DEFAULT '0' NOT NULL, group_rank number(8) DEFAULT '0' NOT NULL, @@ -1665,7 +1665,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail number(1) DEFAULT '1' NOT NULL, user_options number(11) DEFAULT '230271' NOT NULL, user_avatar varchar2(255) DEFAULT '' , - user_avatar_type number(2) DEFAULT '0' NOT NULL, + user_avatar_type varchar2(32) DEFAULT '' , user_avatar_width number(4) DEFAULT '0' NOT NULL, user_avatar_height number(4) DEFAULT '0' NOT NULL, user_sig clob DEFAULT '' , diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index c624024362..f139dc0ced 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -463,7 +463,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) DEFAULT '' NOT NULL, group_display INT2 DEFAULT '0' NOT NULL CHECK (group_display >= 0), group_avatar varchar(255) DEFAULT '' NOT NULL, - group_avatar_type INT2 DEFAULT '0' NOT NULL, + group_avatar_type varchar(32) DEFAULT '' NOT NULL, group_avatar_width INT2 DEFAULT '0' NOT NULL CHECK (group_avatar_width >= 0), group_avatar_height INT2 DEFAULT '0' NOT NULL CHECK (group_avatar_height >= 0), group_rank INT4 DEFAULT '0' NOT NULL CHECK (group_rank >= 0), @@ -1167,7 +1167,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INT2 DEFAULT '1' NOT NULL CHECK (user_allow_massemail >= 0), user_options INT4 DEFAULT '230271' NOT NULL CHECK (user_options >= 0), user_avatar varchar(255) DEFAULT '' NOT NULL, - user_avatar_type INT2 DEFAULT '0' NOT NULL, + user_avatar_type varchar(32) DEFAULT '' NOT NULL, user_avatar_width INT2 DEFAULT '0' NOT NULL CHECK (user_avatar_width >= 0), user_avatar_height INT2 DEFAULT '0' NOT NULL CHECK (user_avatar_height >= 0), user_sig TEXT DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index bd002c93ed..417464110b 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -309,7 +309,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) NOT NULL DEFAULT '', group_display INTEGER UNSIGNED NOT NULL DEFAULT '0', group_avatar varchar(255) NOT NULL DEFAULT '', - group_avatar_type tinyint(2) NOT NULL DEFAULT '0', + group_avatar_type varchar(32) NOT NULL DEFAULT '', group_avatar_width INTEGER UNSIGNED NOT NULL DEFAULT '0', group_avatar_height INTEGER UNSIGNED NOT NULL DEFAULT '0', group_rank INTEGER UNSIGNED NOT NULL DEFAULT '0', @@ -891,7 +891,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INTEGER UNSIGNED NOT NULL DEFAULT '1', user_options INTEGER UNSIGNED NOT NULL DEFAULT '230271', user_avatar varchar(255) NOT NULL DEFAULT '', - user_avatar_type tinyint(2) NOT NULL DEFAULT '0', + user_avatar_type varchar(32) NOT NULL DEFAULT '', user_avatar_width INTEGER UNSIGNED NOT NULL DEFAULT '0', user_avatar_height INTEGER UNSIGNED NOT NULL DEFAULT '0', user_sig mediumtext(16777215) NOT NULL DEFAULT '', From eea2ec50521e274b928d23f710108f37797cb22c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:27:09 +0200 Subject: [PATCH 025/138] [feature/avatars] Introduce global phpbb_avatar_manager PHPBB3-10018 --- phpBB/common.php | 2 ++ phpBB/download/file.php | 2 ++ phpBB/includes/acp/acp_groups.php | 10 ++++------ phpBB/includes/acp/acp_users.php | 12 +++++------- phpBB/includes/functions_display.php | 10 ++-------- phpBB/includes/ucp/ucp_profile.php | 13 ++++++------- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index b3b8d7e4f7..c59c231d28 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -130,6 +130,8 @@ $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_ $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); +$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); + // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display'))); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index c01b0789de..55364b3fd0 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -82,6 +82,8 @@ if (isset($_GET['avatar'])) $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); + $phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); + $filename = request_var('avatar', ''); $avatar_group = false; $exit = false; diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 0a22c216c7..34c233604a 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -26,6 +26,7 @@ class acp_groups { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; + global $phpbb_avatar_manager; $user->add_lang('acp/groups'); $this->tpl_name = 'acp_groups'; @@ -282,16 +283,13 @@ class acp_groups // Setup avatar data for later $avatars_enabled = false; - $avatar_manager = null; $avatar_drivers = null; $avatar_data = null; $avatar_error = array(); if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - - $avatar_drivers = $avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); // This is normalised data, without the group_ prefix @@ -337,7 +335,7 @@ class acp_groups $driver = request_var('avatar_driver', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) @@ -534,7 +532,7 @@ class acp_groups 'avatar' => "acp_avatar_options_$driver.html", )); - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 12da482dbe..fac84ba40a 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -33,6 +33,7 @@ class acp_users global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; global $request; + global $phpbb_avatar_manager; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; @@ -467,8 +468,7 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - if ($driver = $avatar_manager->get_driver($user_row['user_avatar_type'])) + if ($driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type'])) { $driver->delete($user_row); } @@ -1688,9 +1688,7 @@ class acp_users $avatars_enabled = false; if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - - $avatar_drivers = $avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); // This is normalised data, without the user_ prefix @@ -1703,7 +1701,7 @@ class acp_users $driver = request_var('avatar_driver', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); if ($result && empty($error)) @@ -1758,7 +1756,7 @@ class acp_users 'avatar' => "acp_avatar_options_$driver.html", )); - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); if ($avatar->prepare_form($template, $avatar_data, $error)) { diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index c59805dacd..e1dd67aeaf 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1313,8 +1313,7 @@ function get_avatar($row, $alt, $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; global $request; - - static $avatar_manager = null; + global $phpbb_avatar_manager; if (!$config['allow_avatar'] && !$ignore_config) { @@ -1368,12 +1367,7 @@ function get_avatar($row, $alt, $ignore_config = false) break; default: - if (empty($avatar_manager)) - { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); - } - - $avatar = $avatar_manager->get_driver($row['avatar_type']); + $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); if ($avatar) { diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index ffc6ebf556..58e5254d4b 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -30,6 +30,7 @@ class ucp_profile { global $cache, $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; global $request; + global $phpbb_avatar_manager; $user->add_lang('posting'); @@ -552,11 +553,9 @@ class ucp_profile if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - - $avatar_drivers = $avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); - + // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver::FROM_USER); @@ -567,7 +566,7 @@ class ucp_profile $driver = request_var('avatar_driver', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); if ($result && empty($error)) @@ -594,7 +593,7 @@ class ucp_profile else { // They are removing their avatar or are trying to play games with us - if ($avatar = $avatar_manager->get_driver($user->data['user_avatar_type'])) + if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) { $avatar->delete($avatar_data); } @@ -634,7 +633,7 @@ class ucp_profile 'avatar' => "ucp_avatar_options_$driver.html", )); - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); if ($avatar->prepare_form($template, $avatar_data, $error)) { From 81fb4268cd141259fe5b3bc9ad51adf2e29e0772 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:40:19 +0200 Subject: [PATCH 026/138] [feature/avatars] Introduce an avatar driver interface PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatar/driver/driver.php | 39 ++++-------- phpBB/includes/avatar/driver/interface.php | 71 ++++++++++++++++++++++ phpBB/includes/functions_display.php | 4 +- phpBB/includes/ucp/ucp_profile.php | 2 +- 6 files changed, 87 insertions(+), 33 deletions(-) create mode 100644 phpBB/includes/avatar/driver/interface.php diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 34c233604a..5a45b3b572 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -293,7 +293,7 @@ class acp_groups sort($avatar_drivers); // This is normalised data, without the group_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver::FROM_GROUP); + $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver_interface::FROM_GROUP); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index fac84ba40a..9c12116062 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1692,7 +1692,7 @@ class acp_users sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_USER); + $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); if ($submit) { diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 8fb80693fb..277130e819 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Base class for avatar drivers * @package avatars */ -abstract class phpbb_avatar_driver +abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { /** * Current board configuration @@ -51,12 +51,6 @@ abstract class phpbb_avatar_driver */ protected $cache; - /** - * @TODO - */ - const FROM_USER = 0; - const FROM_GROUP = 1; - /** * This flag should be set to true if the avatar requires a nonstandard image * tag, and will generate the html itself. @@ -83,12 +77,7 @@ abstract class phpbb_avatar_driver } /** - * Get the avatar url and dimensions - * - * @param $ignore_config Whether this function should respect the users prefs - * and board configuration configuration option, or should just render - * the avatar anyways. Useful for the ACP. - * @return array Avatar data + * @inheritdoc */ public function get_data($row, $ignore_config = false) { @@ -100,13 +89,7 @@ abstract class phpbb_avatar_driver } /** - * Returns custom html for displaying this avatar. - * Only called if $custom_html is true. - * - * @param $ignore_config Whether this function should respect the users prefs - * and board configuration configuration option, or should just render - * the avatar anyways. Useful for the ACP. - * @return string HTML + * @inheritdoc */ public function get_custom_html($row, $ignore_config = false) { @@ -114,7 +97,7 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ public function prepare_form($template, $row, &$error, &$override_focus) { @@ -122,7 +105,7 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ public function process_form($template, $row, &$error) { @@ -130,7 +113,7 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ public function delete($row) { @@ -138,18 +121,18 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ - public static function clean_row($row, $src = phpbb_avatar_driver::FROM_USER) + public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER) { $return = array(); $prefix = false; - - if ($src == phpbb_avatar_driver::FROM_USER) + + if ($src == phpbb_avatar_driver_interface::FROM_USER) { $prefix = 'user_'; } - else if ($src == phpbb_avatar_driver::FROM_GROUP) + else if ($src == phpbb_avatar_driver_interface::FROM_GROUP) { $prefix = 'group_'; } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php new file mode 100644 index 0000000000..dcec5811bb --- /dev/null +++ b/phpBB/includes/avatar/driver/interface.php @@ -0,0 +1,71 @@ + '', 'width' => 0, 'height' => 0] + */ + public function get_data($row, $ignore_config = false); + + /** + * Returns custom html for displaying this avatar. + * Only called if $custom_html is true. + * + * @param $ignore_config Whether this function should respect the users prefs + * and board configuration configuration option, or should just render + * the avatar anyways. Useful for the ACP. + * @return string HTML + */ + public function get_custom_html($row, $ignore_config = false); + + /** + * @TODO + **/ + public function prepare_form($template, $row, &$error, &$override_focus); + + /** + * @TODO + **/ + public function process_form($template, $row, &$error); + + /** + * @TODO + **/ + public function delete($row); + + /** + * @TODO + **/ + public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER); +} diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index e1dd67aeaf..82638b7f2b 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1281,7 +1281,7 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank */ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_USER); + $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); return get_avatar($row, $alt, $ignore_config); } @@ -1296,7 +1296,7 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false */ function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_GROUP); + $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_GROUP); return get_avatar($row, $alt, $ignore_config); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 58e5254d4b..9d22fd4dba 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -557,7 +557,7 @@ class ucp_profile sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver::FROM_USER); + $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver_interface::FROM_USER); if ($submit) { From 3b71e81cfba726043063b05cb793e18186143252 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 21:29:52 +0200 Subject: [PATCH 027/138] [feature/avatars] Simplify clean_row, move it to avatar manager PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatar/driver/driver.php | 41 ---------------------- phpBB/includes/avatar/driver/interface.php | 11 ------ phpBB/includes/avatar/manager.php | 19 ++++++++++ phpBB/includes/functions_display.php | 4 +-- phpBB/includes/ucp/ucp_profile.php | 2 +- 7 files changed, 24 insertions(+), 57 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 5a45b3b572..d4a3e40d93 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -293,7 +293,7 @@ class acp_groups sort($avatar_drivers); // This is normalised data, without the group_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver_interface::FROM_GROUP); + $avatar_data = phpbb_avatar_manager::clean_row($group_row); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 9c12116062..cd50b02ca1 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1692,7 +1692,7 @@ class acp_users sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); + $avatar_data = phpbb_avatar_manager::clean_row($user_row); if ($submit) { diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 277130e819..7028df4b64 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -119,45 +119,4 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { return true; } - - /** - * @inheritdoc - **/ - public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER) - { - $return = array(); - $prefix = false; - - if ($src == phpbb_avatar_driver_interface::FROM_USER) - { - $prefix = 'user_'; - } - else if ($src == phpbb_avatar_driver_interface::FROM_GROUP) - { - $prefix = 'group_'; - } - - if ($prefix) - { - $len = strlen($prefix); - foreach ($row as $key => $val) - { - $sub = substr($key, 0, $len); - if ($sub == $prefix) - { - $return[substr($key, $len)] = $val; - } - else - { - $return[$key] = $val; - } - } - } - else - { - $return = $row; - } - - return $return; - } } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index dcec5811bb..8c8a067d13 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -21,12 +21,6 @@ if (!defined('IN_PHPBB')) */ interface phpbb_avatar_driver_interface { - /** - * @TODO - */ - const FROM_USER = 0; - const FROM_GROUP = 1; - /** * Get the avatar url and dimensions * @@ -63,9 +57,4 @@ interface phpbb_avatar_driver_interface * @TODO **/ public function delete($row); - - /** - * @TODO - **/ - public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER); } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 41429f3a06..054bb0cee9 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -125,4 +125,23 @@ class phpbb_avatar_manager return array_keys(self::$valid_drivers); } + + /** + * Strip out user_ and group_ prefixes from keys + **/ + public static function clean_row($row) + { + $keys = array_keys($row); + $values = array_values($row); + + $keys = array_map( + function ($key) + { + return preg_replace('(user_|group_)', '', $key); + }, + $row + ); + + return array_combine($keys, $values); + } } diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 82638b7f2b..619c30ada5 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1281,7 +1281,7 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank */ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); + $row = phpbb_avatar_manager::clean_row($user_row); return get_avatar($row, $alt, $ignore_config); } @@ -1296,7 +1296,7 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false */ function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_GROUP); + $row = phpbb_avatar_manager::clean_row($user_row); return get_avatar($row, $alt, $ignore_config); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 9d22fd4dba..44dc57cfd7 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -557,7 +557,7 @@ class ucp_profile sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver_interface::FROM_USER); + $avatar_data = phpbb_avatar_manager::clean_row($user->data); if ($submit) { From a1132fc5c7e990d73cbc8ac7abf4502a1bbe7216 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 21:45:51 +0200 Subject: [PATCH 028/138] [feature/avatars] Update avatars in database_update PHPBB3-10018 --- phpBB/includes/functions_display.php | 72 ++++++---------------------- phpBB/install/database_update.php | 24 +++++++++- 2 files changed, 36 insertions(+), 60 deletions(-) diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 619c30ada5..291d92387f 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1325,72 +1325,28 @@ function get_avatar($row, $alt, $ignore_config = false) 'width' => $row['avatar_width'], 'height' => $row['avatar_height'], ); - - switch ($row['avatar_type']) + + $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); + + if ($avatar) { - case AVATAR_UPLOAD: - // Compatibility with old avatars - if (!$config['allow_avatar_upload'] && !$ignore_config) - { - $avatar_data['src'] = ''; - } - else - { - $avatar_data['src'] = $phpbb_root_path . "download/file.$phpEx?avatar=" . $avatar_data['src']; - $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); - } - break; + if ($avatar->custom_html) + { + return $avatar->get_html($row, $ignore_config); + } - case AVATAR_GALLERY: - // Compatibility with old avatars - if (!$config['allow_avatar_local'] && !$ignore_config) - { - $avatar_data['src'] = ''; - } - else - { - $avatar_data['src'] = $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_data['src']; - $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); - } - break; - - case AVATAR_REMOTE: - // Compatibility with old avatars - if (!$config['allow_avatar_remote'] && !$ignore_config) - { - $avatar_data['src'] = ''; - } - else - { - $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); - } - break; - - default: - $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); - - if ($avatar) - { - if ($avatar->custom_html) - { - return $avatar->get_html($row, $ignore_config); - } - - $avatar_data = $avatar->get_data($row, $ignore_config); - } - else - { - $avatar_data['src'] = ''; - } - - break; + $avatar_data = $avatar->get_data($row, $ignore_config); + } + else + { + $avatar_data['src'] = ''; } $html = ''; if (!empty($avatar_data['src'])) { - $html = ''; diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index e85fe1810d..75f1ada749 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2391,13 +2391,33 @@ function change_database_data(&$no_updates, $version) { set_config('teampage_memberships', '1'); } - + // Clear styles table and add prosilver entry _sql('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); $sql = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')"; _sql($sql, $errored, $error_ary); - + + // Update avatars to modular types + $avatar_type_map = array( + AVATAR_UPLOAD => 'upload', + AVATAR_GALLERY => 'local', + AVATAR_REMOTE => 'remote', + ); + + foreach ($avatar_type_map as $old => $new) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_avatar_type = '" . $db->sql_escape($new) . "' + WHERE user_avatar_type = '" . $db->sql_escape($old) . "'"; + _sql($sql, $errored, $error_ary); + + $sql = 'UPDATE ' . GROUPS_TABLE . " + SET group_avatar_type = '" . $db->sql_escape($new) . "' + WHERE group_avatar_type = '" . $db->sql_escape($old) . "'"; + _sql($sql, $errored, $error_ary); + } + $no_updates = false; break; From b2b812f1714fc924a7c9e595ccb8fbb35f20f203 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 22:13:10 +0200 Subject: [PATCH 029/138] [feature/avatars] Do not assign in an if statement PHPBB3-10018 --- phpBB/includes/acp/acp_users.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index cd50b02ca1..33a173b74d 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -468,7 +468,8 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present - if ($driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type'])) + $driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type']); + if ($driver) { $driver->delete($user_row); } From f273ab16ae68d15832832e2b2c98a3b99c966c97 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 22:28:40 +0200 Subject: [PATCH 030/138] [feature/avatars] Fix clean_row regex, thanks to chris PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 054bb0cee9..f4e5a6d7f8 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -137,7 +137,7 @@ class phpbb_avatar_manager $keys = array_map( function ($key) { - return preg_replace('(user_|group_)', '', $key); + return preg_replace('#^(?:user_|group_)#', '', $key); }, $row ); From 6d994380d76accba5485b0a04d3028f1c153ebd8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 14:48:51 +0200 Subject: [PATCH 031/138] [feature/avatars] Fix error in avatar_manager::clean_row PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index f4e5a6d7f8..839216b61e 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -139,7 +139,7 @@ class phpbb_avatar_manager { return preg_replace('#^(?:user_|group_)#', '', $key); }, - $row + $keys ); return array_combine($keys, $values); From d10486699273b896fffe86f05f66a6d542843f5b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 16:59:06 +0200 Subject: [PATCH 032/138] [feature/avatars] Remove unneeded argument for driver prepare_form() PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 6 +++--- phpBB/includes/avatar/driver/interface.php | 2 +- phpBB/includes/avatar/driver/local.php | 4 ++-- phpBB/includes/avatar/driver/upload.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 7028df4b64..4ac6762140 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -38,13 +38,13 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface * @type string */ protected $phpbb_root_path; - + /** * Current $phpEx * @type string */ protected $phpEx; - + /** * A cache driver * @type phpbb_cache_driver_interface @@ -99,7 +99,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc **/ - public function prepare_form($template, $row, &$error, &$override_focus) + public function prepare_form($template, $row, &$error) { return false; } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index 8c8a067d13..d3b764e275 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -46,7 +46,7 @@ interface phpbb_avatar_driver_interface /** * @TODO **/ - public function prepare_form($template, $row, &$error, &$override_focus); + public function prepare_form($template, $row, &$error); /** * @TODO diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 27e451c099..a0ef912eae 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -43,7 +43,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver ); } } - + /** * @inheritdoc */ @@ -103,7 +103,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver return true; } - + /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index c7d2b870c1..d9504c04a0 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -58,7 +58,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], )); - + return true; } From f40e6963c61548d746c59b78cb60c0f7459c7696 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 17:11:20 +0200 Subject: [PATCH 033/138] [feature/avatars] Remove empty script tag PHPBB3-10018 --- phpBB/styles/prosilver/template/ucp_avatar_options.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index e8114da3ea..a246b00ddd 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -1,4 +1,3 @@ -
@@ -66,5 +65,3 @@
- From 21df013210d1de2cffae568c0620a7ccd6d8f426 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:23:26 +0200 Subject: [PATCH 034/138] [feature/avatars] Move avatars JavaScript code to external JS file PHPBB3-10018 --- phpBB/adm/style/acp_groups.html | 23 ++---------------- phpBB/adm/style/acp_users_avatar.html | 23 ++---------------- phpBB/adm/style/avatars.js | 17 +++++++++++++ phpBB/styles/prosilver/template/avatars.js | 17 +++++++++++++ .../template/ucp_avatar_options.html | 24 ++----------------- 5 files changed, 40 insertions(+), 64 deletions(-) create mode 100644 phpBB/adm/style/avatars.js create mode 100644 phpBB/styles/prosilver/template/avatars.js diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index 42cb434ad3..167642e5cb 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -123,27 +123,6 @@ -
@@ -154,6 +133,8 @@
+ + « {L_BACK} diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index 6316ff4a22..9649fa923e 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -28,30 +28,11 @@ -
{S_FORM_TOKEN} + + diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js new file mode 100644 index 0000000000..baa2623ac9 --- /dev/null +++ b/phpBB/adm/style/avatars.js @@ -0,0 +1,17 @@ +function avatar_simplify() { + var node = document.getElementById('av_options'); + for (var i = 0; i < node.children.length; i++) { + child = node.children[i]; + child.style.display = 'none'; + } + + var selected = document.getElementById('avatar_driver').value; + var id = 'av_option_' + selected; + node = document.getElementById(id); + if (node != null) { + node.style.display = 'block'; + } +} + +avatar_simplify(); +document.getElementById('avatar_driver').onchange = avatar_simplify; diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js new file mode 100644 index 0000000000..baa2623ac9 --- /dev/null +++ b/phpBB/styles/prosilver/template/avatars.js @@ -0,0 +1,17 @@ +function avatar_simplify() { + var node = document.getElementById('av_options'); + for (var i = 0; i < node.children.length; i++) { + child = node.children[i]; + child.style.display = 'none'; + } + + var selected = document.getElementById('avatar_driver').value; + var id = 'av_option_' + selected; + node = document.getElementById(id); + if (node != null) { + node.style.display = 'block'; + } +} + +avatar_simplify(); +document.getElementById('avatar_driver').onchange = avatar_simplify; diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index a246b00ddd..2438deefd5 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -41,27 +41,7 @@ - - + + From b060667ac102109c0c8f198925bb81b489a30f34 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:26:44 +0200 Subject: [PATCH 035/138] [feature/avatars] Rewrite avatars event handler to use jQuery PHPBB3-10018 --- phpBB/adm/style/avatars.js | 16 ++++------------ phpBB/styles/prosilver/template/avatars.js | 16 ++++------------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index baa2623ac9..252081ee08 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -1,17 +1,9 @@ function avatar_simplify() { - var node = document.getElementById('av_options'); - for (var i = 0; i < node.children.length; i++) { - child = node.children[i]; - child.style.display = 'none'; - } + $('#av_options').hide(); - var selected = document.getElementById('avatar_driver').value; - var id = 'av_option_' + selected; - node = document.getElementById(id); - if (node != null) { - node.style.display = 'block'; - } + var selected = $('#avatar_driver').val(); + $('#av_option_' + selected).show(); } avatar_simplify(); -document.getElementById('avatar_driver').onchange = avatar_simplify; +$('#avatar_driver').on('change', avatar_simplify); diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index baa2623ac9..252081ee08 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -1,17 +1,9 @@ function avatar_simplify() { - var node = document.getElementById('av_options'); - for (var i = 0; i < node.children.length; i++) { - child = node.children[i]; - child.style.display = 'none'; - } + $('#av_options').hide(); - var selected = document.getElementById('avatar_driver').value; - var id = 'av_option_' + selected; - node = document.getElementById(id); - if (node != null) { - node.style.display = 'block'; - } + var selected = $('#avatar_driver').val(); + $('#av_option_' + selected).show(); } avatar_simplify(); -document.getElementById('avatar_driver').onchange = avatar_simplify; +$('#avatar_driver').on('change', avatar_simplify); From 2f3581fe3ef928d91f12c442ab5e4890c6620f58 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:37:23 +0200 Subject: [PATCH 036/138] [feature/avatars] Add self-invoking closure around avatars.js PHPBB3-10018 --- phpBB/adm/style/avatars.js | 6 ++++++ phpBB/styles/prosilver/template/avatars.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index 252081ee08..cb19aa9b7a 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -1,3 +1,7 @@ +(function($) { // Avoid conflicts with other libraries + +"use strict"; + function avatar_simplify() { $('#av_options').hide(); @@ -7,3 +11,5 @@ function avatar_simplify() { avatar_simplify(); $('#avatar_driver').on('change', avatar_simplify); + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index 252081ee08..cb19aa9b7a 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -1,3 +1,7 @@ +(function($) { // Avoid conflicts with other libraries + +"use strict"; + function avatar_simplify() { $('#av_options').hide(); @@ -7,3 +11,5 @@ function avatar_simplify() { avatar_simplify(); $('#avatar_driver').on('change', avatar_simplify); + +})(jQuery); // Avoid conflicts with other libraries From 13f4bfabbeab77698f06c3431931b73ebedc587c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 21:00:00 +0200 Subject: [PATCH 037/138] [feature/avatars] Fixup avatars.js rewrite PHPBB3-10018 --- phpBB/adm/style/avatars.js | 4 ++-- phpBB/styles/prosilver/template/avatars.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index cb19aa9b7a..2068bdbbc4 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -3,13 +3,13 @@ "use strict"; function avatar_simplify() { - $('#av_options').hide(); + $('#av_options > div').hide(); var selected = $('#avatar_driver').val(); $('#av_option_' + selected).show(); } avatar_simplify(); -$('#avatar_driver').on('change', avatar_simplify); +$('#avatar_driver').bind('change', avatar_simplify); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index cb19aa9b7a..2068bdbbc4 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -3,13 +3,13 @@ "use strict"; function avatar_simplify() { - $('#av_options').hide(); + $('#av_options > div').hide(); var selected = $('#avatar_driver').val(); $('#av_option_' + selected).show(); } avatar_simplify(); -$('#avatar_driver').on('change', avatar_simplify); +$('#avatar_driver').bind('change', avatar_simplify); })(jQuery); // Avoid conflicts with other libraries From df16bd1c49e6e970b147f15e752825dd3186fb87 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 21:02:07 +0200 Subject: [PATCH 038/138] [feature/avatars] Rewrite drivers to use full class name * Use full driver class name as avatar_type value * Move avatar drivers to core namespace * Make avatars installable through extensions PHPBB3-10018 --- phpBB/common.php | 2 +- phpBB/download/file.php | 2 +- .../avatar/driver/{ => core}/local.php | 2 +- .../avatar/driver/{ => core}/remote.php | 2 +- .../avatar/driver/{ => core}/upload.php | 2 +- phpBB/includes/avatar/driver/driver.php | 21 +++++++ phpBB/includes/avatar/driver/interface.php | 10 ++++ phpBB/includes/avatar/manager.php | 55 +++++++++---------- phpBB/includes/ucp/ucp_profile.php | 10 ++-- 9 files changed, 68 insertions(+), 38 deletions(-) rename phpBB/includes/avatar/driver/{ => core}/local.php (98%) rename phpBB/includes/avatar/driver/{ => core}/remote.php (98%) rename phpBB/includes/avatar/driver/{ => core}/upload.php (98%) diff --git a/phpBB/common.php b/phpBB/common.php index 11b84ee858..52666685ac 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -130,7 +130,7 @@ $phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_ $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); -$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); +$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $phpbb_extension_manager, $cache->get_driver()); // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 55364b3fd0..34999ab24c 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -82,7 +82,7 @@ if (isset($_GET['avatar'])) $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); - $phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); + $phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $phpbb_extension_manager, $cache->get_driver()); $filename = request_var('avatar', ''); $avatar_group = false; diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/core/local.php similarity index 98% rename from phpBB/includes/avatar/driver/local.php rename to phpBB/includes/avatar/driver/core/local.php index a0ef912eae..ca82b9c175 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/core/local.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Handles avatars selected from the board gallery * @package avatars */ -class phpbb_avatar_driver_local extends phpbb_avatar_driver +class phpbb_avatar_driver_core_local extends phpbb_avatar_driver { /** * @inheritdoc diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/core/remote.php similarity index 98% rename from phpBB/includes/avatar/driver/remote.php rename to phpBB/includes/avatar/driver/core/remote.php index cd0a756428..9f5a58e75a 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/core/remote.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Handles avatars hosted remotely * @package avatars */ -class phpbb_avatar_driver_remote extends phpbb_avatar_driver +class phpbb_avatar_driver_core_remote extends phpbb_avatar_driver { /** * @inheritdoc diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/core/upload.php similarity index 98% rename from phpBB/includes/avatar/driver/upload.php rename to phpBB/includes/avatar/driver/core/upload.php index d9504c04a0..d0ce856dbe 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/core/upload.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Handles avatars uploaded to the board * @package avatars */ -class phpbb_avatar_driver_upload extends phpbb_avatar_driver +class phpbb_avatar_driver_core_upload extends phpbb_avatar_driver { /** * @inheritdoc diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 4ac6762140..5cebd1533d 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -119,4 +119,25 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { return true; } + + /** + * @inheritdoc + **/ + public function is_enabled() + { + $driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this)); + + return $this->config["allow_avatar_$driver"]; + } + + /** + * @inheritdoc + **/ + public function get_template_name() + { + $driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this)); + $template = "ucp_avatar_options_$driver.html"; + + return $template; + } } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index d3b764e275..4f1c1f73cf 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -57,4 +57,14 @@ interface phpbb_avatar_driver_interface * @TODO **/ public function delete($row); + + /** + * @TODO + **/ + public function is_enabled(); + + /** + * @TODO + **/ + public function get_template_name(); } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 839216b61e..c2c3dbbbca 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -24,25 +24,27 @@ class phpbb_avatar_manager private $phpEx; private $config; private $request; + private $extension_manager; private $cache; private static $valid_drivers = false; /** * @TODO **/ - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache = null) + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_extension_manager $extension_manager, phpbb_cache_driver_interface $cache = null) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->config = $config; $this->request = $request; + $this->extension_manager = $extension_manager; $this->cache = $cache; } /** * @TODO **/ - public function get_driver($avatar_type, $new = false) + public function get_driver($avatar_type) { if (self::$valid_drivers === false) { @@ -53,30 +55,33 @@ class phpbb_avatar_manager switch ($avatar_type) { case AVATAR_GALLERY: - $avatar_type = 'local'; + $avatar_type = 'phpbb_avatar_driver_local'; break; case AVATAR_UPLOAD: - $avatar_type = 'upload'; + $avatar_type = 'phpbb_avatar_driver_upload'; break; case AVATAR_REMOTE: - $avatar_type = 'remote'; + $avatar_type = 'phpbb_avatar_driver_remote'; break; } - if (isset(self::$valid_drivers[$avatar_type])) - { - if ($new || !is_object(self::$valid_drivers[$avatar_type])) - { - $class_name = 'phpbb_avatar_driver_' . $avatar_type; - self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache); - } - - return self::$valid_drivers[$avatar_type]; - } - else + if (false === array_search($avatar_type, self::$valid_drivers)) { return null; } + + $r = new ReflectionClass($avatar_type); + + if ($r->isSubClassOf('phpbb_avatar_driver')) { + $driver = new $avatar_type($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache); + } else if ($r->implementsInterface('phpbb_avatar_driver')) { + $driver = new $avatar_type(); + } else { + $message = "Invalid avatar driver class name '%s' provided. It must implement phpbb_avatar_driver_interface."; + trigger_error(sprintf($message, $avatar_type)); + } + + return $driver; } /** @@ -93,18 +98,12 @@ class phpbb_avatar_manager { self::$valid_drivers = array(); - $iterator = new DirectoryIterator($this->phpbb_root_path . 'includes/avatar/driver'); + $finder = $this->extension_manager->get_finder(); - foreach ($iterator as $file) - { - // Match all files that appear to be php files - if (preg_match("/^(.*)\.{$this->phpEx}$/", $file, $match)) - { - self::$valid_drivers[] = $match[1]; - } - } - - self::$valid_drivers = array_flip(self::$valid_drivers); + self::$valid_drivers = $finder + ->extension_directory('/avatar/driver/') + ->core_path('includes/avatar/driver/core/') + ->get_classes(); if ($this->cache) { @@ -123,7 +122,7 @@ class phpbb_avatar_manager $this->load_valid_drivers(); } - return array_keys(self::$valid_drivers); + return self::$valid_drivers; } /** diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 6b2133796d..f406e9dc5b 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -623,18 +623,18 @@ class ucp_profile } $focused_driver = request_var('avatar_driver', $user->data['user_avatar_type']); - + foreach ($avatar_drivers as $driver) { - if ($config["allow_avatar_$driver"]) + $avatar = $phpbb_avatar_manager->get_driver($driver); + + if ($avatar->is_enabled()) { $avatars_enabled = true; $template->set_filenames(array( - 'avatar' => "ucp_avatar_options_$driver.html", + 'avatar' => $avatar->get_template_name(), )); - $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->prepare_form($template, $avatar_data, $error)) { $driver_u = strtoupper($driver); From 4c9820d1ca47d088146f3f52fb1126821efe3646 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 12 Nov 2012 15:01:25 +0100 Subject: [PATCH 039/138] [feature/avatars] add missing html closing tags and fix tabbing PHPBB3-10018 --- phpBB/adm/style/acp_users_avatar.html | 9 +++++---- phpBB/styles/prosilver/template/ucp_avatar_options.html | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index 93a7b38390..62c80f14c1 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -37,14 +37,15 @@ - + -
- {L_AVATAR_GALLERY} +
+ {L_AVATAR_GALLERY}
 
-

{ERROR}

+
+

{ERROR}


{L_AVATAR_EXPLAIN}
{AVATAR}
diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index d9763adc85..30015c5ec2 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -21,6 +21,7 @@ +
From 4c4b82416b8c7b3a8f97b12ca96699bea0bde91d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 12 Nov 2012 15:06:44 +0100 Subject: [PATCH 040/138] [feature/avatars] Replace colon usage with {L_COLON} PHPBB3-10018 --- phpBB/adm/style/acp_avatar_options_local.html | 2 +- phpBB/adm/style/acp_avatar_options_remote.html | 4 ++-- phpBB/adm/style/acp_avatar_options_upload.html | 4 ++-- phpBB/adm/style/acp_groups.html | 2 +- phpBB/adm/style/acp_users_avatar.html | 2 +- phpBB/styles/prosilver/template/ucp_avatar_options_local.html | 2 +- .../styles/prosilver/template/ucp_avatar_options_remote.html | 4 ++-- .../styles/prosilver/template/ucp_avatar_options_upload.html | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/phpBB/adm/style/acp_avatar_options_local.html b/phpBB/adm/style/acp_avatar_options_local.html index d762fa9008..02ff58fe15 100644 --- a/phpBB/adm/style/acp_avatar_options_local.html +++ b/phpBB/adm/style/acp_avatar_options_local.html @@ -1,5 +1,5 @@
-
+
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
+

{L_LINK_REMOTE_SIZE_EXPLAIN}
×  diff --git a/phpBB/adm/style/acp_avatar_options_upload.html b/phpBB/adm/style/acp_avatar_options_upload.html index 9c8dd9af01..d0a4f516e1 100644 --- a/phpBB/adm/style/acp_avatar_options_upload.html +++ b/phpBB/adm/style/acp_avatar_options_upload.html @@ -1,11 +1,11 @@
-
+
-

{L_UPLOAD_AVATAR_URL_EXPLAIN}
+

{L_UPLOAD_AVATAR_URL_EXPLAIN}
diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index 3a551adca7..6fb2908b0a 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -103,7 +103,7 @@
{L_GROUP_AVATAR}
-

{L_AVATAR_EXPLAIN}
+

{L_AVATAR_EXPLAIN}
{AVATAR}
diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index 62c80f14c1..c179e1958d 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -47,7 +47,7 @@

{ERROR}

-

{L_AVATAR_EXPLAIN}
+

{L_AVATAR_EXPLAIN}
{AVATAR}
diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html index 9f726e2ff9..9ca9b6e9ec 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html @@ -1,4 +1,4 @@ -
-

{L_AVATAR_SELECT_NEW}

+

{L_AVATAR_SELECT}

-
+
-

{L_GRAVATAR_AVATAR_EXPLAIN}
+

{L_GRAVATAR_AVATAR_SIZE_EXPLAIN}
×  diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html index ec5a22b691..cf3eb20a39 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html @@ -3,7 +3,7 @@
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
+

{L_LINK_REMOTE_SIZE_EXPLAIN}
×  From c70cbfac4339529e196934405d0eb2f9672121d5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 17 Nov 2012 00:50:23 +0100 Subject: [PATCH 052/138] [feature/avatars] Fix acp front-end of user and group avatars Due to the changes to the avatar manager etc. these had to be updated. PHPBB3-10018 --- .../style/acp_avatar_options_gravatar.html | 11 +++++ .../adm/style/acp_avatar_options_remote.html | 2 +- phpBB/adm/style/acp_groups.html | 4 +- phpBB/adm/style/acp_users_avatar.html | 49 ++----------------- phpBB/includes/acp/acp_groups.php | 37 +++++++------- phpBB/includes/acp/acp_users.php | 28 ++++++----- phpBB/includes/ucp/ucp_profile.php | 2 +- 7 files changed, 52 insertions(+), 81 deletions(-) create mode 100644 phpBB/adm/style/acp_avatar_options_gravatar.html diff --git a/phpBB/adm/style/acp_avatar_options_gravatar.html b/phpBB/adm/style/acp_avatar_options_gravatar.html new file mode 100644 index 0000000000..5629e873cf --- /dev/null +++ b/phpBB/adm/style/acp_avatar_options_gravatar.html @@ -0,0 +1,11 @@ +
+

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
+
+
+
+

{L_GRAVATAR_AVATAR_SIZE_EXPLAIN}
+
+ ×  + +
+
diff --git a/phpBB/adm/style/acp_avatar_options_remote.html b/phpBB/adm/style/acp_avatar_options_remote.html index ec5a22b691..cf3eb20a39 100644 --- a/phpBB/adm/style/acp_avatar_options_remote.html +++ b/phpBB/adm/style/acp_avatar_options_remote.html @@ -3,7 +3,7 @@
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
+

{L_LINK_REMOTE_SIZE_EXPLAIN}
×  diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index 6fb2908b0a..d062064fe9 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -107,9 +107,9 @@
{AVATAR}
-
+
{L_DELETE_AVATAR}
-
- - -
-
-
-
- - -
-

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- - -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
-
-
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
-
{L_PIXEL} × {L_PIXEL}
-
- - -
-
-
-
- - -
- -
- {L_AVATAR_GALLERY} -
-
-
 
-
-

{ERROR}

+

{ERROR}


{L_AVATAR_EXPLAIN}
{AVATAR}
- {L_AVATAR_SELECT_NEW} + {L_AVATAR_SELECT}
+ + + {L_GRAVATAR_AVATAR_SIZE}{L_COLON}
{L_GRAVATAR_AVATAR_SIZE_EXPLAIN} + + {L_PIXEL} ×  + {L_PIXEL} + + + diff --git a/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html b/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html new file mode 100644 index 0000000000..37ac864b27 --- /dev/null +++ b/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html @@ -0,0 +1,29 @@ + + + + + + + +
{L_AVATAR_CATEGORY}{L_COLON}   +
+ + + + + + + + + + + + + +
{av_local_col.av_local_col.AVATAR_NAME}
+
diff --git a/phpBB/styles/subsilver2/template/ucp_avatar_options_remote.html b/phpBB/styles/subsilver2/template/ucp_avatar_options_remote.html new file mode 100644 index 0000000000..8fe7201953 --- /dev/null +++ b/phpBB/styles/subsilver2/template/ucp_avatar_options_remote.html @@ -0,0 +1,10 @@ + + + + + + + + + +
{L_LINK_REMOTE_AVATAR}{L_COLON}
{L_LINK_REMOTE_AVATAR_EXPLAIN}
{L_LINK_REMOTE_SIZE}{L_COLON}
{L_LINK_REMOTE_SIZE_EXPLAIN}
{L_PIXEL} × {L_PIXEL}
diff --git a/phpBB/styles/subsilver2/template/ucp_avatar_options_upload.html b/phpBB/styles/subsilver2/template/ucp_avatar_options_upload.html new file mode 100644 index 0000000000..e76abc0433 --- /dev/null +++ b/phpBB/styles/subsilver2/template/ucp_avatar_options_upload.html @@ -0,0 +1,12 @@ + + + + + + + + + + + +
{L_UPLOAD_AVATAR_FILE}{L_COLON}
{L_UPLOAD_AVATAR_URL}{L_COLON}
{L_UPLOAD_AVATAR_URL_EXPLAIN}
diff --git a/phpBB/styles/subsilver2/template/ucp_profile_avatar.html b/phpBB/styles/subsilver2/template/ucp_profile_avatar.html index 160f8a2399..f8129e60e6 100644 --- a/phpBB/styles/subsilver2/template/ucp_profile_avatar.html +++ b/phpBB/styles/subsilver2/template/ucp_profile_avatar.html @@ -21,61 +21,27 @@ {L_AVATAR_FEATURES_DISABLED} - - - {L_UPLOAD_AVATAR_FILE}{L_COLON} - + + {L_AVATAR_SELECT} - - - - {L_UPLOAD_AVATAR_URL}{L_COLON}
{L_UPLOAD_AVATAR_URL_EXPLAIN} - + + {L_AVATAR_TYPE}{L_COLON} + + - - - - {L_LINK_REMOTE_AVATAR}{L_COLON}
{L_LINK_REMOTE_AVATAR_EXPLAIN} - + + + {avatar_drivers.L_EXPLAIN} - - {L_LINK_REMOTE_SIZE}{L_COLON}
{L_LINK_REMOTE_SIZE_EXPLAIN} - {L_PIXEL} × {L_PIXEL} + + {avatar_drivers.OUTPUT} - - - - {L_AVATAR_GALLERY}{L_COLON} - {L_DISPLAY_GALLERY} - - - - - - {L_AVATAR_GALLERY} - - - {L_AVATAR_CATEGORY}{L_COLON}   - - - - - - - - - - - - - - - - -
{avatar_row.avatar_column.AVATAR_NAME}
- - - + @@ -84,4 +50,6 @@ + + From 959bc183bf21e77c694ac0b68cbda5b93ae79cd0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Nov 2012 23:09:09 +0100 Subject: [PATCH 057/138] [feature/avatars] Handle deletion of avatars Previously this wasn't handled correctly if at all. PHPBB3-10018 --- phpBB/adm/style/acp_groups.html | 1 + phpBB/adm/style/acp_users_avatar.html | 1 + phpBB/includes/acp/acp_groups.php | 8 +++++++- phpBB/includes/acp/acp_users.php | 8 +++++++- phpBB/includes/ucp/ucp_profile.php | 4 ++-- phpBB/styles/prosilver/template/ucp_avatar_options.html | 1 + 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index d062064fe9..b38d61bef3 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -105,6 +105,7 @@

{L_AVATAR_EXPLAIN}
{AVATAR}
+
diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index 069f7f6e50..e32d8f379b 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -6,6 +6,7 @@

{L_AVATAR_EXPLAIN}
{AVATAR}
+
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 7be58b6df1..f461555056 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -335,7 +335,8 @@ class acp_groups // Handle avatar $driver = str_replace('_', '.', request_var('avatar_driver', '')); $config_name = preg_replace('#^avatar.driver.#', '', $driver); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"]) + $av_delete = $request->variable('av_delete', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($av_delete)) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $avatar_error); @@ -354,6 +355,11 @@ class acp_groups } else { + if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + { + $avatar->delete($avatar_data); + } + // Removing the avatar $submit_ary['avatar_type'] = ''; $submit_ary['avatar'] = ''; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 562353b229..fdad1df0fd 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1746,7 +1746,8 @@ class acp_users { $driver = str_replace('_', '.', request_var('avatar_driver', '')); $config_name = preg_replace('#^avatar.driver.#', '', $driver); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"]) + $av_delete = $request->variable('av_delete', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($av_delete)) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); @@ -1770,6 +1771,11 @@ class acp_users } else { + if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + { + $avatar->delete($avatar_data); + } + // Removing the avatar $result = array( 'user_avatar' => '', diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 6a1ad33ceb..77b2dc7054 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -565,7 +565,8 @@ class ucp_profile { $driver = str_replace('_', '.', request_var('avatar_driver', '')); $config_name = preg_replace('#^avatar.driver.#', '', $driver); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"]) + $av_delete = $request->variable('av_delete', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($av_delete)) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); @@ -593,7 +594,6 @@ class ucp_profile } else { - // They are removing their avatar or are trying to play games with us if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) { $avatar->delete($avatar_data); diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index bca957043b..e7300a075d 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -9,6 +9,7 @@

{L_AVATAR_EXPLAIN}
{AVATAR}
+

{L_AVATAR_SELECT}

From c2ba24558ff79174af9aaf2bee274529c794cac8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Nov 2012 23:11:40 +0100 Subject: [PATCH 058/138] [feature/avatars] Fix local and upload avatar in the ACP PHPBB3-10018 --- phpBB/adm/style/acp_avatar_options_local.html | 7 +++---- phpBB/adm/style/acp_groups.html | 2 +- phpBB/includes/avatar/driver/local.php | 5 +++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/adm/style/acp_avatar_options_local.html b/phpBB/adm/style/acp_avatar_options_local.html index 02ff58fe15..b317cd2aa5 100644 --- a/phpBB/adm/style/acp_avatar_options_local.html +++ b/phpBB/adm/style/acp_avatar_options_local.html @@ -17,11 +17,10 @@ - - - + + + - diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index b38d61bef3..e96adcee90 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -17,7 +17,7 @@ -
enctype="multipart/form-data"> + enctype="multipart/form-data" enctype="multipart/form-data">
{L_GROUP_DETAILS} diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 080921c325..cdee983d9e 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -91,11 +91,12 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver $template->assign_block_vars('av_local_row.av_local_col', array( 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'], - 'AVATAR_NAME' => $img['name'], - 'AVATAR_FILE' => $img['filename'], + 'AVATAR_NAME' => $img['name'], + 'AVATAR_FILE' => $img['filename'], )); $template->assign_block_vars('av_local_row.av_local_option', array( + 'AVATAR_FILE' => $img['filename'], 'S_OPTIONS_AVATAR' => $img['filename'] )); From 7521c077a9c0b3201dffcbe33114d9da715eb9e0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Nov 2012 23:16:37 +0100 Subject: [PATCH 059/138] [feature/avatars] Miscellaenous template fixes PHPBB3-10018 --- phpBB/adm/style/acp_avatar_options_local.html | 3 +-- phpBB/styles/prosilver/template/ucp_avatar_options_local.html | 4 ++-- .../styles/subsilver2/template/ucp_avatar_options_local.html | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/acp_avatar_options_local.html b/phpBB/adm/style/acp_avatar_options_local.html index b317cd2aa5..08ec170195 100644 --- a/phpBB/adm/style/acp_avatar_options_local.html +++ b/phpBB/adm/style/acp_avatar_options_local.html @@ -7,9 +7,8 @@   -
- +
diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html index 9ca9b6e9ec..8b46dfa7f5 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html @@ -9,8 +9,8 @@ diff --git a/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html b/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html index 37ac864b27..352052f9f4 100644 --- a/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html +++ b/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html @@ -22,6 +22,10 @@ + + + +
{L_NO_AVATAR_CATEGORY}
From bea6e845d3c0c25f5f84ad13fcf22f42f1249561 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 19 Nov 2012 00:27:22 +0100 Subject: [PATCH 060/138] [feature/avatars] Use https for gravatar PHPBB3-10018 --- phpBB/includes/avatar/driver/gravatar.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index b07af59366..b8f23b04a9 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -56,7 +56,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver */ public function get_custom_html($row, $ignore_config = false, $alt = '') { - $html = ' Date: Mon, 19 Nov 2012 00:30:18 +0100 Subject: [PATCH 061/138] [feature/avatars] Fix the docs and small naming fixes PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 2 +- phpBB/includes/avatar/driver/gravatar.php | 4 +-- phpBB/includes/avatar/driver/interface.php | 34 ++++++++++++++++--- phpBB/includes/avatar/driver/local.php | 4 ++- phpBB/includes/avatar/driver/upload.php | 4 ++- phpBB/includes/avatar/manager.php | 38 +++++++++++++++++----- phpBB/install/database_update.php | 5 +++ 7 files changed, 71 insertions(+), 20 deletions(-) diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 9a213ce730..1e899b7c50 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -81,7 +81,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface public $custom_html = false; /** - * Construct an driver object + * Construct a driver object * * @param $config The phpBB configuration * @param $request The request object diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index b8f23b04a9..036800fd45 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -19,11 +19,10 @@ if (!defined('IN_PHPBB')) * Handles avatars hosted at gravatar.com * @package avatars */ -// @todo: rename classes to phpbb_ext_foo_avatar_driver_foo and similar class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver { /** - * We'll need to create a different type of avatar for gravatar + * @inheritdoc */ public $custom_html = true; @@ -32,7 +31,6 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver */ public function get_data($row, $ignore_config = false) { - // @todo: add allow_avatar_gravatar to database_update.php etc. if ($ignore_config || $this->config['allow_avatar_gravatar']) { return array( diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index f066470174..11dbffa65d 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -51,27 +51,51 @@ interface phpbb_avatar_driver_interface public function get_custom_html($row, $ignore_config = false, $alt = ''); /** - * @TODO + * Prepare form for changing the settings of this avatar + * + * @param object $template The template object + * @param array $row The user data or group data that has been cleaned with + * phpbb_avatar_manager::clean_row + * @param array &$error The reference to an error array + * + * @return bool Returns true if form has been successfully prepared **/ public function prepare_form($template, $row, &$error); /** - * @TODO + * Process form data + * + * @param object $template The template object + * @param array $row The user data or group data that has been cleaned with + * phpbb_avatar_manager::clean_row + * @param array &$error The reference to an error array + * + * @return array An array containing the avatar data as follows: + * ['avatar'], ['avatar_width'], ['avatar_height'] **/ public function process_form($template, $row, &$error); /** - * @TODO + * Delete avatar + * + * @param array $row The user data or group data that has been cleaned with + * phpbb_avatar_manager::clean_row + * + * @return bool True if avatar has been deleted or there is no need to delete **/ public function delete($row); /** - * @TODO + * Check if avatar is enabled + * + * @return bool True if avatar is enabled, false if it's disabled **/ public function is_enabled(); /** - * @TODO + * Get the avatars template name + * + * @return string The avatars template name **/ public function get_template_name(); } diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index cdee983d9e..9b3807ee4b 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -132,7 +132,9 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver } /** - * @TODO + * Get a list of avatars that are locally available + * + * @return array An array containing the locally available avatars */ private function get_avatar_list() { diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 8f044ca37f..c9913548fc 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -139,7 +139,9 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver } /** - * @TODO + * Check if user is able to upload an avatar + * + * @return bool True if user can upload, false if not */ private function can_upload() { diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 546cdcdc05..7c7bd6c7ba 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -26,25 +26,37 @@ class phpbb_avatar_manager private $request; private $cache; private static $valid_drivers = false; - private $tasks; + private $avatar_drivers; private $container; /** - * @TODO + * Construct an avatar manager object + * + * @param $phpbb_root_path The path to the phpBB root + * @param $phpEx The php file extension + * @param $config The phpBB configuration + * @param $request The request object + * @param $cache A cache driver + * @param $avatar_drivers The avatars drivers passed via the service container + * @param $container The container object **/ - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache, $tasks, $container) + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache, $avatar_drivers, $container) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->config = $config; $this->request = $request; $this->cache = $cache; - $this->tasks = $tasks; + $this->avatar_drivers = $avatar_drivers; $this->container = $container; } /** - * @TODO + * Get the driver object specified by the avatar type + * + * @param string The avatar type; by default an avatar's service container name + * + * @return object The avatar driver object **/ public function get_driver($avatar_type) { @@ -87,14 +99,15 @@ class phpbb_avatar_manager } /** - * @TODO + * Load the list of valid drivers + * This is executed once and fills self::$valid_drivers **/ private function load_valid_drivers() { - if (!empty($this->tasks)) + if (!empty($this->avatar_drivers)) { self::$valid_drivers = array(); - foreach ($this->tasks as $driver) + foreach ($this->avatar_drivers as $driver) { self::$valid_drivers[] = $driver->get_name(); } @@ -102,7 +115,9 @@ class phpbb_avatar_manager } /** - * @TODO + * Get a list of valid avatar drivers + * + * @return array An array containing a list of the valid avatar drivers **/ public function get_valid_drivers() { @@ -116,6 +131,11 @@ class phpbb_avatar_manager /** * Strip out user_ and group_ prefixes from keys + * + * @param array $row The user data or group data + * + * @return array The user data or group data with keys that have been + * stripped from the preceding "user_" or "group_" **/ public static function clean_row($row) { diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 9498d3963b..2015ef0475 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2740,6 +2740,11 @@ function change_database_data(&$no_updates, $version) AND module_mode = \'avatar\''; _sql($sql, $errored, $error_ary); + if (!isset($config['allow_avatar_gravatar'])) + { + $config->set('allow_avatar_gravatar', ''); + } + $no_updates = false; if (!isset($config['assets_version'])) From 858c59279c0f8b07412dec676c96d9b291d91897 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 19 Nov 2012 23:50:34 +0100 Subject: [PATCH 062/138] [feature/avatars] Use protected instead of private PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 2 +- phpBB/includes/avatar/driver/local.php | 2 +- phpBB/includes/avatar/driver/upload.php | 2 +- phpBB/includes/avatar/manager.php | 18 +++++++++--------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 1e899b7c50..ef0c8ce44e 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { - private $name; + protected $name; /** * Returns the name of the driver. diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 9b3807ee4b..d0ad8708b0 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -136,7 +136,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver * * @return array An array containing the locally available avatars */ - private function get_avatar_list() + protected function get_avatar_list() { $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list'); diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index c9913548fc..9475cad7a1 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -143,7 +143,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver * * @return bool True if user can upload, false if not */ - private function can_upload() + protected function can_upload() { return (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')); } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 7c7bd6c7ba..0d36118dbc 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -20,14 +20,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_avatar_manager { - private $phpbb_root_path; - private $phpEx; - private $config; - private $request; - private $cache; - private static $valid_drivers = false; - private $avatar_drivers; - private $container; + protected $phpbb_root_path; + protected $phpEx; + protected $config; + protected $request; + protected $cache; + protected static $valid_drivers = false; + protected $avatar_drivers; + protected $container; /** * Construct an avatar manager object @@ -102,7 +102,7 @@ class phpbb_avatar_manager * Load the list of valid drivers * This is executed once and fills self::$valid_drivers **/ - private function load_valid_drivers() + protected function load_valid_drivers() { if (!empty($this->avatar_drivers)) { From b7b14f9a056190c6a01c98f6eec9e60ad73d7564 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 16:20:14 +0100 Subject: [PATCH 063/138] [feature/avatars] Use constant for URL and fix usage of getimagesize We now use a constant for the gravatar URL. Additionally the usage of getimagesize() was reduced. It should only be run if the user didn't specify both the width and height of the avatar. PHPBB3-10018 --- phpBB/includes/avatar/driver/gravatar.php | 55 ++++++++++++++++------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 036800fd45..a73a28a234 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -21,6 +21,8 @@ if (!defined('IN_PHPBB')) */ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver { + const GRAVATAR_URL = 'https://secure.gravatar.com/avatar/'; + /** * @inheritdoc */ @@ -54,8 +56,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver */ public function get_custom_html($row, $ignore_config = false, $alt = '') { - $html = 'get_gravatar_url($row) . '" ' . ($row['avatar_width'] ? ('width="' . $row['avatar_width'] . '" ') : '') . ($row['avatar_height'] ? ('height="' . $row['avatar_height'] . '" ') : '') . 'alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />'; @@ -81,14 +82,14 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver */ public function process_form($template, $row, &$error) { - $email = $this->request->variable('av_gravatar_email', ''); - $width = $this->request->variable('av_gravatar_width', 0); - $height = $this->request->variable('av_gravatar_height', 0); + $row['avatar'] = $this->request->variable('av_gravatar_email', ''); + $row['avatar_width'] = $this->request->variable('av_gravatar_width', 0); + $row['avatar_height'] = $this->request->variable('av_gravatar_height', 0); require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx); $error = array_merge($error, validate_data(array( - 'email' => $email, + 'email' => $row['avatar'], ), array( 'email' => array( array('string', false, 6, 60), @@ -101,12 +102,16 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver } // Make sure getimagesize works... - if (function_exists('getimagesize')) + if (function_exists('getimagesize') && ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0)) { - // build URL - $url = 'https://secure.gravatar.com/' . md5(strtolower(trim($email))); + /** + * default to the minimum of the maximum allowed avatar size if the size + * is not or only partially entered + */ + $row['avatar_width'] = $row['avatar_height'] = min($this->config['avatar_max_width'], $this->config['avatar_max_height']); + $url = $this->get_gravatar_url($row); - if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) + if (($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) && (($image_data = @getimagesize($url)) === false)) { $error[] = 'UNABLE_GET_IMAGE_SIZE'; return false; @@ -118,20 +123,38 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver return false; } - $width = ($width && $height) ? $width : $image_data[0]; - $height = ($width && $height) ? $height : $image_data[1]; + $row['avatar_width'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_width'] : $image_data[0]; + $row['avatar_height'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_height'] : $image_data[1]; } - if ($width <= 0 || $height <= 0) + if ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) { $error[] = 'AVATAR_NO_SIZE'; return false; } return array( - 'avatar' => $email, - 'avatar_width' => $width, - 'avatar_height' => $height, + 'avatar' => $row['avatar'], + 'avatar_width' => $row['avatar_width'], + 'avatar_height' => $row['avatar_height'], ); } + + /** + * Build gravatar URL for output on page + * + * @return string The gravatar URL + */ + protected function get_gravatar_url($row) + { + $url = self::GRAVATAR_URL; + $url .= md5(strtolower(trim($row['avatar']))); + + if ($row['avatar_width'] || $row['avatar_height']) + { + $url .= '?s=' . max($row['avatar_width'], $row['avatar_height']); + } + + return $url; + } } From 9b61204a17386742d3d3ec579ee8dcfe50cbf5a4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 16:27:20 +0100 Subject: [PATCH 064/138] [feature/avatars] Check if gravatar is within min/max width/height PHPBB3-10018 --- phpBB/includes/avatar/driver/gravatar.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index a73a28a234..f0ab2ab548 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -132,6 +132,24 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver $error[] = 'AVATAR_NO_SIZE'; return false; } + + if ($this->config['avatar_max_width'] || $this->config['avatar_max_height']) + { + if ($row['avatar_width'] > $this->config['avatar_max_width'] || $row['avatar_height'] > $this->config['avatar_max_height']) + { + $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'], $row['avatar_width'], $row['avatar_height']); + return false; + } + } + + if ($this->config['avatar_min_width'] || $this->config['avatar_min_height']) + { + if ($row['avatar_width'] < $this->config['avatar_min_width'] || $row['avatar_height'] < $this->config['avatar_min_height']) + { + $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'], $row['avatar_width'], $row['avatar_height']); + return false; + } + } return array( 'avatar' => $row['avatar'], From 726d1a16d704630a9a028010c7420bea837738d4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 17:15:35 +0100 Subject: [PATCH 065/138] [feature/avatars] Move avatar specific settings to drivers PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 24 ++++++++++++++-------- phpBB/includes/avatar/driver/driver.php | 8 ++++++++ phpBB/includes/avatar/driver/gravatar.php | 10 +++++++++ phpBB/includes/avatar/driver/interface.php | 7 +++++++ phpBB/includes/avatar/driver/local.php | 11 ++++++++++ phpBB/includes/avatar/driver/remote.php | 10 +++++++++ phpBB/includes/avatar/driver/upload.php | 15 ++++++++++++++ 7 files changed, 76 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 4ad0b38708..5852f512cd 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -28,7 +28,7 @@ class acp_board { global $db, $user, $auth, $template; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; - global $cache; + global $cache, $phpbb_avatar_manager; $user->add_lang('acp/board'); @@ -107,6 +107,15 @@ class acp_board break; case 'avatar': + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + sort($avatar_drivers); + $avatar_vars = array(); + foreach ($avatar_drivers as $driver) + { + $avatar = $phpbb_avatar_manager->get_driver($driver); + $avatar_vars += $avatar->prepare_form_acp(); + } + $display_vars = array( 'title' => 'ACP_AVATAR_SETTINGS', 'vars' => array( @@ -118,18 +127,15 @@ class acp_board 'avatar_max_height' => array('lang' => 'MAX_AVATAR_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'allow_avatar' => array('lang' => 'ALLOW_AVATARS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'allow_avatar_gravatar' => array('lang' => 'ALLOW_GRAVATAR', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), - 'allow_avatar_local' => array('lang' => 'ALLOW_LOCAL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), - 'allow_avatar_remote' => array('lang' => 'ALLOW_REMOTE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'allow_avatar_upload' => array('lang' => 'ALLOW_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), - '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' => 'text:4:10', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), 'avatar_min' => array('lang' => 'MIN_AVATAR_SIZE', 'validate' => 'int:0', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']), 'avatar_max' => array('lang' => 'MAX_AVATAR_SIZE', 'validate' => 'int:0', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']), - 'avatar_path' => array('lang' => 'AVATAR_STORAGE_PATH', 'validate' => 'rwpath', 'type' => 'text:20:255', 'explain' => true), - 'avatar_gallery_path' => array('lang' => 'AVATAR_GALLERY_PATH', 'validate' => 'rpath', 'type' => 'text:20:255', 'explain' => true), ) ); + + if (sizeof($avatar_vars)) + { + $display_vars['vars'] += $avatar_vars; + } break; case 'message': diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index ef0c8ce44e..710d3dfe20 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -126,6 +126,14 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface return false; } + /** + * @inheritdoc + **/ + public function prepare_form_acp() + { + return array(); + } + /** * @inheritdoc **/ diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index f0ab2ab548..58ac535e6b 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -77,6 +77,16 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver return true; } + /** + * @inheritdoc + **/ + public function prepare_form_acp() + { + return array( + 'allow_avatar_gravatar' => array('lang' => 'ALLOW_GRAVATAR', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + ); + } + /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index 11dbffa65d..28220d79f2 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -62,6 +62,13 @@ interface phpbb_avatar_driver_interface **/ public function prepare_form($template, $row, &$error); + /** + * Prepare form for changing the acp settings of this avatar + * + * @return array Return the array containing the acp settings + **/ + public function prepare_form_acp(); + /** * Process form data * diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index d0ad8708b0..f3c0d516af 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -109,6 +109,17 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver return true; } + /** + * @inheritdoc + **/ + public function prepare_form_acp() + { + return array( + 'allow_avatar_local' => array('lang' => 'ALLOW_LOCAL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + 'avatar_gallery_path' => array('lang' => 'AVATAR_GALLERY_PATH', 'validate' => 'rpath', 'type' => 'text:20:255', 'explain' => true), + ); + } + /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 3c06209352..61ea0ebaf0 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -58,6 +58,16 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver return true; } + /** + * @inheritdoc + **/ + public function prepare_form_acp() + { + return array( + 'allow_avatar_remote' => array('lang' => 'ALLOW_REMOTE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + ); + } + /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 9475cad7a1..77cd81c8c9 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -122,6 +122,21 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver ); } + /** + * @inheritdoc + **/ + public function prepare_form_acp() + { + global $user; + + return array( + 'allow_avatar_upload' => array('lang' => 'ALLOW_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + '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' => 'text:4:10', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), + 'avatar_path' => array('lang' => 'AVATAR_STORAGE_PATH', 'validate' => 'rwpath', 'type' => 'text:20:255', 'explain' => true), + ); + } + /** * @inheritdoc */ From 8c782122c1bafe6f232af6d9f395aa534c4d7dc1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 17:24:02 +0100 Subject: [PATCH 066/138] [feature/avatars] Use in_array() and fix tabbing PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 0d36118dbc..8255fb0759 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -70,16 +70,16 @@ class phpbb_avatar_manager { case AVATAR_GALLERY: $avatar_type = 'avatar.driver.local'; - break; + break; case AVATAR_UPLOAD: $avatar_type = 'avatar.driver.upload'; - break; + break; case AVATAR_REMOTE: $avatar_type = 'avatar.driver.remote'; - break; + break; } - if (false === array_search($avatar_type, self::$valid_drivers)) + if (!in_array($avatar_type, self::$valid_drivers)) { return null; } From 01b313ea262dc7c7a3399c03758ffd1ba24d1ff4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 19:20:39 +0100 Subject: [PATCH 067/138] [feature/avatars] Use isset() instead of in_array() PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 8255fb0759..da9d843947 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -79,7 +79,7 @@ class phpbb_avatar_manager break; } - if (!in_array($avatar_type, self::$valid_drivers)) + if (!isset(self::$valid_drivers[$avatar_type])) { return null; } @@ -109,7 +109,7 @@ class phpbb_avatar_manager self::$valid_drivers = array(); foreach ($this->avatar_drivers as $driver) { - self::$valid_drivers[] = $driver->get_name(); + self::$valid_drivers[$driver->get_name()] = $driver->get_name(); } } } From 24ac0393360aed07a17b7acaca0add6083cf8ddd Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 19:51:46 +0100 Subject: [PATCH 068/138] [feature/avatars] Get rid of array_keys() in gallery avatar PHPBB3-10018 --- phpBB/includes/avatar/driver/local.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index f3c0d516af..a206f5b1b0 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -52,9 +52,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver $avatar_list = $this->get_avatar_list(); $category = $this->request->variable('av_local_cat', ''); - $categories = array_keys($avatar_list); - - foreach ($categories as $cat) + foreach ($avatar_list as $cat => $null) { if (!empty($avatar_list[$cat])) { @@ -63,6 +61,11 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver 'SELECTED' => ($cat == $category), )); } + + if ($cat != $category) + { + unset($avatar_list[$cat]); + } } if (!empty($avatar_list[$category])) From 8a01bc171837be40818f285035ccefa5ac819213 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 21:42:42 +0100 Subject: [PATCH 069/138] [feature/avatars] Use RecursiveDirectoryIterator for gallery avatar RecursiveDirectoryIterator is now used for populating the avatar list array of the gallery avatar. PHPBB3-10018 --- phpBB/includes/avatar/driver/local.php | 62 +++++++++++--------------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index a206f5b1b0..8ac511f909 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -159,45 +159,33 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver $avatar_list = array(); $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; - $dh = @opendir($path); - - if ($dh) + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS), RecursiveIteratorIterator::SELF_FIRST); + foreach ($iterator as $file_info) { - while (($cat = readdir($dh)) !== false) - { - if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) - { - if ($ch = @opendir("$path/$cat")) - { - while (($image = readdir($ch)) !== false) - { - // Match all images in the gallery folder - if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) - { - if (function_exists('getimagesize')) - { - $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); - } - else - { - $dims = array(0, 0); - } - $avatar_list[$cat][$image] = array( - 'file' => rawurlencode($cat) . '/' . rawurlencode($image), - 'filename' => rawurlencode($image), - 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), - 'width' => $dims[0], - 'height' => $dims[1], - ); - } - } - @closedir($ch); - } - } - } - @closedir($dh); - } + $file_path = $file_info->getPath(); + $image = $file_info->getFilename(); + // Match all images in the gallery folder + if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image) && is_file($file_path . '/' . $image)) + { + if (function_exists('getimagesize')) + { + $dims = getimagesize($file_path . '/' . $image); + } + else + { + $dims = array(0, 0); + } + $cat = str_replace("$path/", '', $file_path); + $avatar_list[$cat][$image] = array( + 'file' => rawurlencode($cat) . '/' . rawurlencode($image), + 'filename' => rawurlencode($image), + 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), + 'width' => $dims[0], + 'height' => $dims[1], + ); + } + } @ksort($avatar_list); if ($this->cache != null) From 5289dc52a322f760b6a2108f5fed1b4ff365e1d4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Nov 2012 00:00:45 +0100 Subject: [PATCH 070/138] [feature/avatars] Add support for modularized avatars to ucp groups This seems to be the last component where the new avatars system was still missing. PHPBB3-10018 --- phpBB/includes/ucp/ucp_groups.php | 184 +++++++++--------- .../template/ucp_avatar_options.html | 2 + .../prosilver/template/ucp_groups_manage.html | 4 +- .../template/ucp_groups_manage.html | 91 +++------ .../template/ucp_profile_avatar.html | 4 +- 5 files changed, 125 insertions(+), 160 deletions(-) diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 3aa6146081..1d469814b6 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -27,7 +27,7 @@ class ucp_groups { global $config, $phpbb_root_path, $phpEx; global $db, $user, $auth, $cache, $template; - global $request; + global $request, $phpbb_avatar_manager; $user->add_lang('groups'); @@ -438,7 +438,7 @@ class ucp_groups $group_name = $group_row['group_name']; $group_type = $group_row['group_type']; - $avatar_img = (!empty($group_row['group_avatar'])) ? get_group_avatar($group_row) : ''; + $avatar = get_group_avatar($group_row, 'GROUP_AVATAR', true); $template->assign_vars(array( 'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name, @@ -447,8 +447,8 @@ class ucp_groups 'GROUP_DESC_DISP' => generate_text_for_display($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield'], $group_row['group_desc_options']), 'GROUP_TYPE' => $group_row['group_type'], - 'AVATAR' => $avatar_img, - 'AVATAR_IMAGE' => $avatar_img, + 'AVATAR' => (empty($avatar) ? '' : $avatar), + 'AVATAR_IMAGE' => (empty($avatar) ? '' : $avatar), 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '', )); @@ -483,10 +483,20 @@ class ucp_groups $error = array(); - $avatar_select = basename(request_var('avatar_select', '')); - $category = basename(request_var('category', '')); + // Setup avatar data for later + $avatars_enabled = false; + $avatar_drivers = null; + $avatar_data = null; + $avatar_error = array(); - $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false; + if ($config['allow_avatar']) + { + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + sort($avatar_drivers); + + // This is normalised data, without the group_ prefix + $avatar_data = phpbb_avatar_manager::clean_row($group_row); + } // Did we submit? if ($update) @@ -507,87 +517,41 @@ class ucp_groups 'max_recipients'=> request_var('group_max_recipients', 0), ); - $data['uploadurl'] = request_var('uploadurl', ''); - $data['remotelink'] = request_var('remotelink', ''); - $data['width'] = request_var('width', ''); - $data['height'] = request_var('height', ''); - $delete = request_var('delete', ''); - - $uploadfile = $request->file('uploadfile'); - if (!empty($uploadfile['tmp_name']) || $data['uploadurl'] || $data['remotelink']) + if ($config['allow_avatar']) { - // Avatar stuff - $var_ary = array( - 'uploadurl' => array('string', true, 5, 255), - 'remotelink' => array('string', true, 5, 255), - 'width' => array('string', true, 1, 3), - 'height' => array('string', true, 1, 3), - ); - - if (!($error = validate_data($data, $var_ary))) + // Handle avatar + $driver = str_replace('_', '.', request_var('avatar_driver', '')); + $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $av_delete = $request->variable('av_delete', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($av_delete)) { - $data['user_id'] = "g$group_id"; + $avatar = $phpbb_avatar_manager->get_driver($driver); + $result = $avatar->process_form($template, $avatar_data, $avatar_error); - if ((!empty($uploadfile['tmp_name']) || $data['uploadurl']) && $can_upload) + if ($result && empty($avatar_error)) { - list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error); - } - else if ($data['remotelink']) - { - list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error); + $result = array( + 'avatar_type' => $driver, + 'avatar' => $result['avatar'], + 'avatar_width' => $result['avatar_width'], + 'avatar_height' => $result['avatar_height'], + ); + + $submit_ary = array_merge($submit_ary, $result); } } - } - else if ($avatar_select && $config['allow_avatar_local']) - { - // check avatar gallery - if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) + else { - $submit_ary['avatar_type'] = AVATAR_GALLERY; - - list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select); - $submit_ary['avatar'] = $category . '/' . $avatar_select; - } - } - else if ($delete) - { - $submit_ary['avatar'] = ''; - $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0; - } - else if ($data['width'] && $data['height']) - { - // Only update the dimensions? - if ($config['avatar_max_width'] || $config['avatar_max_height']) - { - if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) + if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) { - $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); + $avatar->delete($avatar_data); } - } - if (!sizeof($error)) - { - if ($config['avatar_min_width'] || $config['avatar_min_height']) - { - if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) - { - $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); - } - } - } - - if (!sizeof($error)) - { - $submit_ary['avatar_width'] = $data['width']; - $submit_ary['avatar_height'] = $data['height']; - } - } - - if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete) - { - if (isset($group_row['group_avatar']) && $group_row['group_avatar']) - { - avatar_delete('group', $group_row, true); + // Removing the avatar + $submit_ary['avatar_type'] = ''; + $submit_ary['avatar'] = ''; + $submit_ary['avatar_width'] = 0; + $submit_ary['avatar_height'] = 0; } } @@ -607,7 +571,7 @@ class ucp_groups 'rank' => 'int', 'colour' => 'string', 'avatar' => 'string', - 'avatar_type' => 'int', + 'avatar_type' => 'string', 'avatar_width' => 'int', 'avatar_height' => 'int', 'receive_pm' => 'int', @@ -683,28 +647,63 @@ class ucp_groups $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : ''; $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : ''; - $display_gallery = (isset($_POST['display_gallery'])) ? true : false; - - if ($config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery) + // Load up stuff for avatars + if ($config['allow_avatar']) { - avatar_gallery($category, $avatar_select, 4); + $avatars_enabled = false; + $focused_driver = str_replace('_', '.', request_var('avatar_driver', $avatar_data['avatar_type'])); + + foreach ($avatar_drivers as $driver) + { + $avatar = $phpbb_avatar_manager->get_driver($driver); + + if ($avatar->is_enabled()) + { + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => $avatar->get_template_name(), + )); + + if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) + { + $driver_n = str_replace('.', '_', $driver); + $driver_u = strtoupper($driver_n); + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang($driver_u . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_u . '_EXPLAIN'), + + 'DRIVER' => $driver_n, + 'SELECTED' => ($driver == $focused_driver), + 'OUTPUT' => $template->assign_display('avatar'), + )); + } + } + } } - $avatars_enabled = ($config['allow_avatar'] && (($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) || ($config['allow_avatar_local'] || $config['allow_avatar_remote']))) ? true : false; + // Merge any avatars errors into the primary error array + // Drivers use lang constants, so we need to map to the actual strings + foreach ($avatar_error as $e) + { + if (is_array($e)) + { + $key = array_shift($e); + $error[] = vsprintf($user->lang($key), $e); + } + else + { + $error[] = $user->lang((string) $e); + } + } $template->assign_vars(array( 'S_EDIT' => true, 'S_INCLUDE_SWATCH' => true, - 'S_FORM_ENCTYPE' => ($config['allow_avatar'] && $can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) ? ' enctype="multipart/form-data"' : '', + 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'S_ERROR' => (sizeof($error)) ? true : false, 'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL) ? true : false, - 'S_AVATARS_ENABLED' => $avatars_enabled, - 'S_DISPLAY_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery) ? true : false, - 'S_IN_GALLERY' => ($config['allow_avatar_local'] && $display_gallery) ? true : false, - - 'S_UPLOAD_AVATAR_FILE' => ($config['allow_avatar'] && $config['allow_avatar_upload'] && $can_upload) ? true : false, - 'S_UPLOAD_AVATAR_URL' => ($config['allow_avatar'] && $config['allow_avatar_remote_upload'] && $can_upload) ? true : false, - 'S_LINK_AVATAR' => ($config['allow_avatar'] && $config['allow_avatar_remote']) ? true : false, + 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), + 'S_GROUP_MANAGE' => true, 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', 'GROUP_RECEIVE_PM' => (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ? ' checked="checked"' : '', @@ -717,7 +716,6 @@ class ucp_groups 'S_DESC_SMILIES_CHECKED'=> $group_desc_data['allow_smilies'], 'S_RANK_OPTIONS' => $rank_options, - 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'GROUP_TYPE_FREE' => GROUP_FREE, 'GROUP_TYPE_OPEN' => GROUP_OPEN, diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index e7300a075d..354ddcc69c 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -38,10 +38,12 @@ +
 
+ diff --git a/phpBB/styles/prosilver/template/ucp_groups_manage.html b/phpBB/styles/prosilver/template/ucp_groups_manage.html index 6b017ea3fa..f6fcfa043d 100644 --- a/phpBB/styles/prosilver/template/ucp_groups_manage.html +++ b/phpBB/styles/prosilver/template/ucp_groups_manage.html @@ -70,9 +70,7 @@
{S_HIDDEN_FIELDS} -   -   -   +   {S_FORM_TOKEN}
diff --git a/phpBB/styles/subsilver2/template/ucp_groups_manage.html b/phpBB/styles/subsilver2/template/ucp_groups_manage.html index 12319c9e4e..e15335f4e1 100644 --- a/phpBB/styles/subsilver2/template/ucp_groups_manage.html +++ b/phpBB/styles/subsilver2/template/ucp_groups_manage.html @@ -60,74 +60,43 @@
{L_AVATAR_EXPLAIN} - {AVATAR_IMAGE}

 {L_DELETE_AVATAR} + {AVATAR_IMAGE}

 {L_DELETE_AVATAR} - - - - - - - - - -
{L_UPLOAD_AVATAR_URL_EXPLAIN} - - - - - -
{L_LINK_REMOTE_AVATAR_EXPLAIN} - - - -
{L_LINK_REMOTE_SIZE_EXPLAIN} - px X px - - - - - - - - - - - - {L_AVATAR_GALLERY} - - - -   - - - - - - - - - - - - - - - - -
{avatar_row.avatar_column.AVATAR_NAME}
- - - - - + + + {L_AVATAR_FEATURES_DISABLED} + + + + {L_AVATAR_SELECT} + + + {L_AVATAR_TYPE}{L_COLON} + + + + + + {avatar_drivers.L_EXPLAIN} + + + {avatar_drivers.OUTPUT} + + -   + {S_HIDDEN_FIELDS}  + +

{L_GROUP_MEMBERS}

diff --git a/phpBB/styles/subsilver2/template/ucp_profile_avatar.html b/phpBB/styles/subsilver2/template/ucp_profile_avatar.html index f8129e60e6..4e65b37e3c 100644 --- a/phpBB/styles/subsilver2/template/ucp_profile_avatar.html +++ b/phpBB/styles/subsilver2/template/ucp_profile_avatar.html @@ -12,7 +12,7 @@ {L_CURRENT_IMAGE}{L_COLON}
{L_AVATAR_EXPLAIN}
- {AVATAR}

 {L_DELETE_AVATAR} + {AVATAR}

 {L_DELETE_AVATAR} @@ -43,11 +43,9 @@ - {S_HIDDEN_FIELDS}   - From 211abe2ac9722f23d2f86b6172452e9d9d1bff38 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Nov 2012 00:39:02 +0100 Subject: [PATCH 071/138] [feature/avatars] Remove obsolete functions from functions_user.php The removed functions are no longer needed due to the new avatar system. PHPBB3-10018 --- phpBB/includes/functions_user.php | 466 ------------------------------ 1 file changed, 466 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 7cac0fb34f..3b11147a3a 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2058,134 +2058,6 @@ function avatar_delete($mode, $row, $clean_db = false) return false; } -/** -* Remote avatar linkage -*/ -function avatar_remote($data, &$error) -{ - global $config, $db, $user, $phpbb_root_path, $phpEx; - - if (!preg_match('#^(http|https|ftp)://#i', $data['remotelink'])) - { - $data['remotelink'] = 'http://' . $data['remotelink']; - } - if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $data['remotelink'])) - { - $error[] = $user->lang['AVATAR_URL_INVALID']; - return false; - } - - // Make sure getimagesize works... - if (($image_data = @getimagesize($data['remotelink'])) === false && (empty($data['width']) || empty($data['height']))) - { - $error[] = $user->lang['UNABLE_GET_IMAGE_SIZE']; - return false; - } - - if (!empty($image_data) && ($image_data[0] < 2 || $image_data[1] < 2)) - { - $error[] = $user->lang['AVATAR_NO_SIZE']; - return false; - } - - $width = ($data['width'] && $data['height']) ? $data['width'] : $image_data[0]; - $height = ($data['width'] && $data['height']) ? $data['height'] : $image_data[1]; - - if ($width < 2 || $height < 2) - { - $error[] = $user->lang['AVATAR_NO_SIZE']; - return false; - } - - // Check image type - include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); - $types = fileupload::image_types(); - $extension = strtolower(filespec::get_extension($data['remotelink'])); - - if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) - { - if (!isset($types[$image_data[2]])) - { - $error[] = $user->lang['UNABLE_GET_IMAGE_SIZE']; - } - else - { - $error[] = sprintf($user->lang['IMAGE_FILETYPE_MISMATCH'], $types[$image_data[2]][0], $extension); - } - return false; - } - - if ($config['avatar_max_width'] || $config['avatar_max_height']) - { - if ($width > $config['avatar_max_width'] || $height > $config['avatar_max_height']) - { - $error[] = phpbb_avatar_error_wrong_size($width, $height); - return false; - } - } - - if ($config['avatar_min_width'] || $config['avatar_min_height']) - { - if ($width < $config['avatar_min_width'] || $height < $config['avatar_min_height']) - { - $error[] = phpbb_avatar_error_wrong_size($width, $height); - return false; - } - } - - return array(AVATAR_REMOTE, $data['remotelink'], $width, $height); -} - -/** -* Avatar upload using the upload class -*/ -function avatar_upload($data, &$error) -{ - global $phpbb_root_path, $config, $db, $user, $phpEx, $request; - - // Init upload class - include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); - $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $config['avatar_filesize'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], (isset($config['mime_triggers']) ? explode('|', $config['mime_triggers']) : false)); - - $uploadfile = $request->file('uploadfile'); - if (!empty($uploadfile['name'])) - { - $file = $upload->form_upload('uploadfile'); - } - else - { - $file = $upload->remote_upload($data['uploadurl']); - } - - $prefix = $config['avatar_salt'] . '_'; - $file->clean_filename('avatar', $prefix, $data['user_id']); - - $destination = $config['avatar_path']; - - // Adjust destination path (no trailing slash) - if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') - { - $destination = substr($destination, 0, -1); - } - - $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); - if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) - { - $destination = ''; - } - - // Move file and overwrite any existing image - $file->move_file($destination, true); - - if (sizeof($file->error)) - { - $file->remove(); - $error = array_merge($error, $file->error); - } - - return array(AVATAR_UPLOAD, $data['user_id'] . '_' . time() . '.' . $file->get('extension'), $file->get('width'), $file->get('height')); -} - /** * Generates avatar filename from the database entry */ @@ -2208,344 +2080,6 @@ function get_avatar_filename($avatar_entry) return $config['avatar_salt'] . '_' . (($avatar_group) ? 'g' : '') . $avatar_entry . '.' . $ext; } -/** -* Avatar Gallery -*/ -function avatar_gallery($category, $avatar_select, $items_per_column, $block_var = 'avatar_row') -{ - global $user, $cache, $template; - global $config, $phpbb_root_path; - - $avatar_list = array(); - - $path = $phpbb_root_path . $config['avatar_gallery_path']; - - if (!file_exists($path) || !is_dir($path)) - { - $avatar_list = array($user->lang['NO_AVATAR_CATEGORY'] => array()); - } - else - { - // Collect images - $dp = @opendir($path); - - if (!$dp) - { - return array($user->lang['NO_AVATAR_CATEGORY'] => array()); - } - - while (($file = readdir($dp)) !== false) - { - if ($file[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $file) && is_dir("$path/$file")) - { - $avatar_row_count = $avatar_col_count = 0; - - if ($dp2 = @opendir("$path/$file")) - { - while (($sub_file = readdir($dp2)) !== false) - { - if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $sub_file)) - { - $avatar_list[$file][$avatar_row_count][$avatar_col_count] = array( - 'file' => rawurlencode($file) . '/' . rawurlencode($sub_file), - 'filename' => rawurlencode($sub_file), - 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $sub_file))), - ); - $avatar_col_count++; - if ($avatar_col_count == $items_per_column) - { - $avatar_row_count++; - $avatar_col_count = 0; - } - } - } - closedir($dp2); - } - } - } - closedir($dp); - } - - if (!sizeof($avatar_list)) - { - $avatar_list = array($user->lang['NO_AVATAR_CATEGORY'] => array()); - } - - @ksort($avatar_list); - - $category = (!$category) ? key($avatar_list) : $category; - $avatar_categories = array_keys($avatar_list); - - $s_category_options = ''; - foreach ($avatar_categories as $cat) - { - $s_category_options .= ''; - } - - $template->assign_vars(array( - 'S_AVATARS_ENABLED' => true, - 'S_IN_AVATAR_GALLERY' => true, - 'S_CAT_OPTIONS' => $s_category_options) - ); - - $avatar_list = (isset($avatar_list[$category])) ? $avatar_list[$category] : array(); - - foreach ($avatar_list as $avatar_row_ary) - { - $template->assign_block_vars($block_var, array()); - - foreach ($avatar_row_ary as $avatar_col_ary) - { - $template->assign_block_vars($block_var . '.avatar_column', array( - 'AVATAR_IMAGE' => $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_col_ary['file'], - 'AVATAR_NAME' => $avatar_col_ary['name'], - 'AVATAR_FILE' => $avatar_col_ary['filename']) - ); - - $template->assign_block_vars($block_var . '.avatar_option_column', array( - 'AVATAR_IMAGE' => $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_col_ary['file'], - 'S_OPTIONS_AVATAR' => $avatar_col_ary['filename']) - ); - } - } - - return $avatar_list; -} - - -/** -* Tries to (re-)establish avatar dimensions -*/ -function avatar_get_dimensions($avatar, $avatar_type, &$error, $current_x = 0, $current_y = 0) -{ - global $config, $phpbb_root_path, $user; - - switch ($avatar_type) - { - case AVATAR_REMOTE : - break; - - case AVATAR_UPLOAD : - $avatar = $phpbb_root_path . $config['avatar_path'] . '/' . get_avatar_filename($avatar); - break; - - case AVATAR_GALLERY : - $avatar = $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar ; - break; - } - - // Make sure getimagesize works... - if (($image_data = @getimagesize($avatar)) === false) - { - $error[] = $user->lang['UNABLE_GET_IMAGE_SIZE']; - return false; - } - - if ($image_data[0] < 2 || $image_data[1] < 2) - { - $error[] = $user->lang['AVATAR_NO_SIZE']; - return false; - } - - // try to maintain ratio - if (!(empty($current_x) && empty($current_y))) - { - if ($current_x != 0) - { - $image_data[1] = (int) floor(($current_x / $image_data[0]) * $image_data[1]); - $image_data[1] = min($config['avatar_max_height'], $image_data[1]); - $image_data[1] = max($config['avatar_min_height'], $image_data[1]); - } - if ($current_y != 0) - { - $image_data[0] = (int) floor(($current_y / $image_data[1]) * $image_data[0]); - $image_data[0] = min($config['avatar_max_width'], $image_data[1]); - $image_data[0] = max($config['avatar_min_width'], $image_data[1]); - } - } - return array($image_data[0], $image_data[1]); -} - -/** -* Uploading/Changing user avatar -*/ -function avatar_process_user(&$error, $custom_userdata = false, $can_upload = null) -{ - global $config, $phpbb_root_path, $auth, $user, $db, $request; - - $data = array( - 'uploadurl' => request_var('uploadurl', ''), - 'remotelink' => request_var('remotelink', ''), - 'width' => request_var('width', 0), - 'height' => request_var('height', 0), - ); - - $error = validate_data($data, array( - 'uploadurl' => array('string', true, 5, 255), - 'remotelink' => array('string', true, 5, 255), - 'width' => array('string', true, 1, 3), - 'height' => array('string', true, 1, 3), - )); - - if (sizeof($error)) - { - return false; - } - - $sql_ary = array(); - - if ($custom_userdata === false) - { - $userdata = &$user->data; - } - else - { - $userdata = &$custom_userdata; - } - - $data['user_id'] = $userdata['user_id']; - $change_avatar = ($custom_userdata === false) ? $auth->acl_get('u_chgavatar') : true; - $avatar_select = basename(request_var('avatar_select', '')); - - // Can we upload? - if (is_null($can_upload)) - { - $can_upload = ($config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $change_avatar && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; - } - - $uploadfile = $request->file('uploadfile'); - if ((!empty($uploadfile['name']) || $data['uploadurl']) && $can_upload) - { - list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_upload($data, $error); - } - else if ($data['remotelink'] && $change_avatar && $config['allow_avatar_remote']) - { - list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_remote($data, $error); - } - else if ($avatar_select && $change_avatar && $config['allow_avatar_local']) - { - $category = basename(request_var('category', '')); - - $sql_ary['user_avatar_type'] = AVATAR_GALLERY; - $sql_ary['user_avatar'] = $avatar_select; - - // check avatar gallery - if (!is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) - { - $sql_ary['user_avatar'] = ''; - $sql_ary['user_avatar_type'] = $sql_ary['user_avatar_width'] = $sql_ary['user_avatar_height'] = 0; - } - else - { - list($sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . urldecode($sql_ary['user_avatar'])); - $sql_ary['user_avatar'] = $category . '/' . $sql_ary['user_avatar']; - } - } - else if (isset($_POST['delete']) && $change_avatar) - { - $sql_ary['user_avatar'] = ''; - $sql_ary['user_avatar_type'] = $sql_ary['user_avatar_width'] = $sql_ary['user_avatar_height'] = 0; - } - else if (!empty($userdata['user_avatar'])) - { - // Only update the dimensions - - if (empty($data['width']) || empty($data['height'])) - { - if ($dims = avatar_get_dimensions($userdata['user_avatar'], $userdata['user_avatar_type'], $error, $data['width'], $data['height'])) - { - list($guessed_x, $guessed_y) = $dims; - if (empty($data['width'])) - { - $data['width'] = $guessed_x; - } - if (empty($data['height'])) - { - $data['height'] = $guessed_y; - } - } - } - if (($config['avatar_max_width'] || $config['avatar_max_height']) && - (($data['width'] != $userdata['user_avatar_width']) || $data['height'] != $userdata['user_avatar_height'])) - { - if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) - { - $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); - } - } - - if (!sizeof($error)) - { - if ($config['avatar_min_width'] || $config['avatar_min_height']) - { - if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) - { - $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); - } - } - } - - if (!sizeof($error)) - { - $sql_ary['user_avatar_width'] = $data['width']; - $sql_ary['user_avatar_height'] = $data['height']; - } - } - - if (!sizeof($error)) - { - // Do we actually have any data to update? - if (sizeof($sql_ary)) - { - $ext_new = $ext_old = ''; - if (isset($sql_ary['user_avatar'])) - { - $userdata = ($custom_userdata === false) ? $user->data : $custom_userdata; - $ext_new = (empty($sql_ary['user_avatar'])) ? '' : substr(strrchr($sql_ary['user_avatar'], '.'), 1); - $ext_old = (empty($userdata['user_avatar'])) ? '' : substr(strrchr($userdata['user_avatar'], '.'), 1); - - if ($userdata['user_avatar_type'] == AVATAR_UPLOAD) - { - // Delete old avatar if present - if ((!empty($userdata['user_avatar']) && empty($sql_ary['user_avatar'])) - || ( !empty($userdata['user_avatar']) && !empty($sql_ary['user_avatar']) && $ext_new !== $ext_old)) - { - avatar_delete('user', $userdata); - } - } - } - - $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE user_id = ' . (($custom_userdata === false) ? $user->data['user_id'] : $custom_userdata['user_id']); - $db->sql_query($sql); - - } - } - - return (sizeof($error)) ? false : true; -} - -/** -* Returns a language string with the avatar size of the new avatar and the allowed maximum and minimum -* -* @param $width int The width of the new uploaded/selected avatar -* @param $height int The height of the new uploaded/selected avatar -* @return string -*/ -function phpbb_avatar_error_wrong_size($width, $height) -{ - global $config, $user; - - return $user->lang('AVATAR_WRONG_SIZE', - $user->lang('PIXELS', (int) $config['avatar_min_width']), - $user->lang('PIXELS', (int) $config['avatar_min_height']), - $user->lang('PIXELS', (int) $config['avatar_max_width']), - $user->lang('PIXELS', (int) $config['avatar_max_height']), - $user->lang('PIXELS', (int) $width), - $user->lang('PIXELS', (int) $height)); -} - /** * Returns an explanation string with maximum avatar settings * From 5ff343f1e6714fd88d64cb17884f88ceee681cb6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Nov 2012 11:58:45 +0100 Subject: [PATCH 072/138] [feature/avatars] Remove duplicate form enctype PHPBB3-10018 --- phpBB/adm/style/acp_groups.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index e96adcee90..a4699571d6 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -17,7 +17,7 @@ - enctype="multipart/form-data" enctype="multipart/form-data"> +
{L_GROUP_DETAILS} From 2b917199066cb06aa9c6c846ce06252d6f8036e9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Nov 2012 18:38:36 +0100 Subject: [PATCH 073/138] [feature/avatars] Add allow_avatar_gravatar to schema_data.sql PHPBB3-10018 --- phpBB/install/schemas/schema_data.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index dbb5fd7481..262221fcf3 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -9,6 +9,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('active_sessions', INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_attachments', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_autologin', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar', '1'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_gravatar', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_local', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_remote', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_upload', '1'); From ce44e3908eef5166e5e3e43d2642c5372379b6a6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 00:54:34 +0100 Subject: [PATCH 074/138] [feature/avatars] Remove unnecessary abbreviations PHPBB3-10018 --- .../style/acp_avatar_options_gravatar.html | 10 +++---- phpBB/adm/style/acp_avatar_options_local.html | 28 ++++++++--------- .../adm/style/acp_avatar_options_remote.html | 10 +++---- .../adm/style/acp_avatar_options_upload.html | 8 ++--- phpBB/adm/style/acp_groups.html | 6 ++-- phpBB/adm/style/acp_users_avatar.html | 6 ++-- phpBB/adm/style/avatars.js | 4 +-- phpBB/includes/acp/acp_groups.php | 16 +++++----- phpBB/includes/acp/acp_users.php | 16 +++++----- phpBB/includes/avatar/driver/gravatar.php | 12 ++++---- phpBB/includes/avatar/driver/local.php | 30 +++++++++---------- phpBB/includes/avatar/driver/remote.php | 12 ++++---- phpBB/includes/avatar/driver/upload.php | 8 ++--- phpBB/includes/ucp/ucp_groups.php | 16 +++++----- phpBB/includes/ucp/ucp_profile.php | 16 +++++----- phpBB/styles/prosilver/template/avatars.js | 4 +-- .../template/ucp_avatar_options.html | 6 ++-- .../template/ucp_avatar_options_gravatar.html | 10 +++---- .../template/ucp_avatar_options_local.html | 22 +++++++------- .../template/ucp_avatar_options_remote.html | 10 +++---- .../template/ucp_avatar_options_upload.html | 8 ++--- phpBB/styles/subsilver2/template/avatars.js | 4 +-- .../template/ucp_avatar_options_gravatar.html | 6 ++-- .../template/ucp_avatar_options_local.html | 26 ++++++++-------- .../template/ucp_avatar_options_remote.html | 4 +-- .../template/ucp_avatar_options_upload.html | 4 +-- .../template/ucp_groups_manage.html | 6 ++-- .../template/ucp_profile_avatar.html | 6 ++-- 28 files changed, 157 insertions(+), 157 deletions(-) diff --git a/phpBB/adm/style/acp_avatar_options_gravatar.html b/phpBB/adm/style/acp_avatar_options_gravatar.html index 5629e873cf..04fd5c459d 100644 --- a/phpBB/adm/style/acp_avatar_options_gravatar.html +++ b/phpBB/adm/style/acp_avatar_options_gravatar.html @@ -1,11 +1,11 @@
-

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
-
+

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
+
-

{L_GRAVATAR_AVATAR_SIZE_EXPLAIN}
+

{L_GRAVATAR_AVATAR_SIZE_EXPLAIN}
- ×  - + ×  +
diff --git a/phpBB/adm/style/acp_avatar_options_local.html b/phpBB/adm/style/acp_avatar_options_local.html index 08ec170195..927c4821f7 100644 --- a/phpBB/adm/style/acp_avatar_options_local.html +++ b/phpBB/adm/style/acp_avatar_options_local.html @@ -1,25 +1,25 @@
-
- - - -  
+ + + +  
- + - + - - - + + + - - - + + + - +
{av_local_row.av_local_col.AVATAR_NAME}{avatar_local_row.avatar_local_col.AVATAR_NAME}
diff --git a/phpBB/adm/style/acp_avatar_options_remote.html b/phpBB/adm/style/acp_avatar_options_remote.html index cf3eb20a39..ab91e90c27 100644 --- a/phpBB/adm/style/acp_avatar_options_remote.html +++ b/phpBB/adm/style/acp_avatar_options_remote.html @@ -1,11 +1,11 @@
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
+

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
+

{L_LINK_REMOTE_SIZE_EXPLAIN}
- ×  - + ×  +
diff --git a/phpBB/adm/style/acp_avatar_options_upload.html b/phpBB/adm/style/acp_avatar_options_upload.html index d0a4f516e1..9d3efbd018 100644 --- a/phpBB/adm/style/acp_avatar_options_upload.html +++ b/phpBB/adm/style/acp_avatar_options_upload.html @@ -1,11 +1,11 @@
-
-
+
+
-

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
+

{L_UPLOAD_AVATAR_URL_EXPLAIN}
+
diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index a4699571d6..bab30a7b6f 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -105,7 +105,7 @@

{L_AVATAR_EXPLAIN}
{AVATAR}
-
+
@@ -116,9 +116,9 @@
-
+
-
+

{avatar_drivers.L_EXPLAIN}

{avatar_drivers.OUTPUT}
diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index e32d8f379b..bc3a19a25e 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -6,7 +6,7 @@

{L_AVATAR_EXPLAIN}
{AVATAR}
-
+
@@ -20,9 +20,9 @@
-
+
-
+

{avatar_drivers.L_EXPLAIN}

{avatar_drivers.OUTPUT}
diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index 2068bdbbc4..882bcfe36d 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -3,10 +3,10 @@ "use strict"; function avatar_simplify() { - $('#av_options > div').hide(); + $('#avatar_options > div').hide(); var selected = $('#avatar_driver').val(); - $('#av_option_' + selected).show(); + $('#avatar_option_' + selected).show(); } avatar_simplify(); diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index f461555056..3a49ac8ff8 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -335,8 +335,8 @@ class acp_groups // Handle avatar $driver = str_replace('_', '.', request_var('avatar_driver', '')); $config_name = preg_replace('#^avatar.driver.#', '', $driver); - $av_delete = $request->variable('av_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($av_delete)) + $avatar_delete = $request->variable('avatar_delete', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $avatar_error); @@ -541,14 +541,14 @@ class acp_groups if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { - $driver_n = str_replace('.', '_', $driver); - $driver_u = strtoupper($driver_n); + $driver_name = str_replace('.', '_', $driver); + $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_u . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_u . '_EXPLAIN'), + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - 'DRIVER' => $driver_n, - 'SELECTED' => ($driver == $focused_driver), + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index fdad1df0fd..2f7662982a 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1746,8 +1746,8 @@ class acp_users { $driver = str_replace('_', '.', request_var('avatar_driver', '')); $config_name = preg_replace('#^avatar.driver.#', '', $driver); - $av_delete = $request->variable('av_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($av_delete)) + $avatar_delete = $request->variable('avatar_delete', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); @@ -1814,15 +1814,15 @@ class acp_users if ($avatar->prepare_form($template, $avatar_data, $error)) { - $driver_n = str_replace('.', '_', $driver); - $driver_u = strtoupper($driver_n); + $driver_name = str_replace('.', '_', $driver); + $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_u . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_u . '_EXPLAIN'), + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - 'DRIVER' => $driver_n, - 'SELECTED' => ($driver == $focused_driver), + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 58ac535e6b..d873f7ba41 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -69,9 +69,9 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver public function prepare_form($template, $row, &$error) { $template->assign_vars(array( - 'AV_GRAVATAR_WIDTH' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_gravatar_width', 0), - 'AV_GRAVATAR_HEIGHT' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_gravatar_width', 0), - 'AV_GRAVATAR_EMAIL' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar']) ? $row['avatar'] : '', + 'AVATAR_GRAVATAR_WIDTH' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('avatar_gravatar_width', 0), + 'AVATAR_GRAVATAR_HEIGHT' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('avatar_gravatar_width', 0), + 'AVATAR_GRAVATAR_EMAIL' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar']) ? $row['avatar'] : '', )); return true; @@ -92,9 +92,9 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver */ public function process_form($template, $row, &$error) { - $row['avatar'] = $this->request->variable('av_gravatar_email', ''); - $row['avatar_width'] = $this->request->variable('av_gravatar_width', 0); - $row['avatar_height'] = $this->request->variable('av_gravatar_height', 0); + $row['avatar'] = $this->request->variable('avatar_gravatar_email', ''); + $row['avatar_width'] = $this->request->variable('avatar_gravatar_width', 0); + $row['avatar_height'] = $this->request->variable('avatar_gravatar_height', 0); require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx); diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 8ac511f909..c231206d8e 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -50,13 +50,13 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function prepare_form($template, $row, &$error) { $avatar_list = $this->get_avatar_list(); - $category = $this->request->variable('av_local_cat', ''); + $category = $this->request->variable('avatar_local_cat', ''); foreach ($avatar_list as $cat => $null) { if (!empty($avatar_list[$cat])) { - $template->assign_block_vars('av_local_cats', array( + $template->assign_block_vars('avatar_local_cats', array( 'NAME' => $cat, 'SELECTED' => ($cat == $category), )); @@ -71,16 +71,16 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver if (!empty($avatar_list[$category])) { $template->assign_vars(array( - 'AV_LOCAL_SHOW' => true, + 'AVATAR_LOCAL_SHOW' => true, )); - $table_cols = isset($row['av_gallery_cols']) ? $row['av_gallery_cols'] : 4; - $row_count = $col_count = $av_pos = 0; - $av_count = sizeof($avatar_list[$category]); + $table_cols = isset($row['avatar_gallery_cols']) ? $row['avatar_gallery_cols'] : 4; + $row_count = $col_count = $avatar_pos = 0; + $avatar_count = sizeof($avatar_list[$category]); reset($avatar_list[$category]); - while ($av_pos < $av_count) + while ($avatar_pos < $avatar_count) { $img = current($avatar_list[$category]); next($avatar_list[$category]); @@ -88,24 +88,24 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver if ($col_count == 0) { ++$row_count; - $template->assign_block_vars('av_local_row', array( + $template->assign_block_vars('avatar_local_row', array( )); } - $template->assign_block_vars('av_local_row.av_local_col', array( + $template->assign_block_vars('avatar_local_row.avatar_local_col', array( 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'], 'AVATAR_NAME' => $img['name'], 'AVATAR_FILE' => $img['filename'], )); - $template->assign_block_vars('av_local_row.av_local_option', array( + $template->assign_block_vars('avatar_local_row.avatar_local_option', array( 'AVATAR_FILE' => $img['filename'], 'S_OPTIONS_AVATAR' => $img['filename'] )); $col_count = ($col_count + 1) % $table_cols; - ++$av_pos; + ++$avatar_pos; } } @@ -129,9 +129,9 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function process_form($template, $row, &$error) { $avatar_list = $this->get_avatar_list(); - $category = $this->request->variable('av_local_cat', ''); + $category = $this->request->variable('avatar_local_cat', ''); - $file = $this->request->variable('av_local_file', ''); + $file = $this->request->variable('avatar_local_file', ''); if (!isset($avatar_list[$category][urldecode($file)])) { $error[] = 'AVATAR_URL_NOT_FOUND'; @@ -152,7 +152,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver */ protected function get_avatar_list() { - $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list'); + $avatar_list = ($this->cache == null) ? false : $this->cache->get('avatar_local_list'); if (!$avatar_list) { @@ -190,7 +190,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver if ($this->cache != null) { - $this->cache->put('av_local_list', $avatar_list); + $this->cache->put('avatar_local_list', $avatar_list); } } diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 61ea0ebaf0..c2ae88cc02 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -50,9 +50,9 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver public function prepare_form($template, $row, &$error) { $template->assign_vars(array( - 'AV_REMOTE_WIDTH' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_remote_width', 0), - 'AV_REMOTE_HEIGHT' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_remote_width', 0), - 'AV_REMOTE_URL' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar']) ? $row['avatar'] : '', + 'AVATAR_REMOTE_WIDTH' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('avatar_remote_width', 0), + 'AVATAR_REMOTE_HEIGHT' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('avatar_remote_width', 0), + 'AVATAR_REMOTE_URL' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar']) ? $row['avatar'] : '', )); return true; @@ -73,9 +73,9 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver */ public function process_form($template, $row, &$error) { - $url = $this->request->variable('av_remote_url', ''); - $width = $this->request->variable('av_remote_width', 0); - $height = $this->request->variable('av_remote_height', 0); + $url = $this->request->variable('avatar_remote_url', ''); + $width = $this->request->variable('avatar_remote_width', 0); + $height = $this->request->variable('avatar_remote_height', 0); if (!preg_match('#^(http|https|ftp)://#i', $url)) { diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 77cd81c8c9..9035b5364e 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -56,7 +56,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver $template->assign_vars(array( 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, - 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], + 'AVATAR_UPLOAD_SIZE' => $this->config['avatar_filesize'], )); return true; @@ -76,12 +76,12 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $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 = $this->request->variable('av_upload_url', ''); - $upload_file = $this->request->file('av_upload_file'); + $url = $this->request->variable('avatar_upload_url', ''); + $upload_file = $this->request->file('avatar_upload_file'); if (!empty($upload_file['name'])) { - $file = $upload->form_upload('av_upload_file'); + $file = $upload->form_upload('avatar_upload_file'); } else { diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 1d469814b6..2a388d17f8 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -522,8 +522,8 @@ class ucp_groups // Handle avatar $driver = str_replace('_', '.', request_var('avatar_driver', '')); $config_name = preg_replace('#^avatar.driver.#', '', $driver); - $av_delete = $request->variable('av_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($av_delete)) + $avatar_delete = $request->variable('avatar_delete', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $avatar_error); @@ -666,14 +666,14 @@ class ucp_groups if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { - $driver_n = str_replace('.', '_', $driver); - $driver_u = strtoupper($driver_n); + $driver_name = str_replace('.', '_', $driver); + $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_u . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_u . '_EXPLAIN'), + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - 'DRIVER' => $driver_n, - 'SELECTED' => ($driver == $focused_driver), + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 77b2dc7054..ab49a11f99 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -565,8 +565,8 @@ class ucp_profile { $driver = str_replace('_', '.', request_var('avatar_driver', '')); $config_name = preg_replace('#^avatar.driver.#', '', $driver); - $av_delete = $request->variable('av_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($av_delete)) + $avatar_delete = $request->variable('avatar_delete', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); @@ -638,15 +638,15 @@ class ucp_profile if ($avatar->prepare_form($template, $avatar_data, $error)) { - $driver_n = str_replace('.', '_', $driver); - $driver_u = strtoupper($driver_n); + $driver_name = str_replace('.', '_', $driver); + $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_u . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_u . '_EXPLAIN'), + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - 'DRIVER' => $driver_n, - 'SELECTED' => ($driver == $focused_driver), + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index 2068bdbbc4..882bcfe36d 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -3,10 +3,10 @@ "use strict"; function avatar_simplify() { - $('#av_options > div').hide(); + $('#avatar_options > div').hide(); var selected = $('#avatar_driver').val(); - $('#av_option_' + selected).show(); + $('#avatar_option_' + selected).show(); } avatar_simplify(); diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index 354ddcc69c..e7f4a48e11 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -9,7 +9,7 @@

{L_AVATAR_EXPLAIN}
{AVATAR}
-
+

{L_AVATAR_SELECT}

@@ -24,9 +24,9 @@ -
+
-
+
diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html b/phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html index 5629e873cf..04fd5c459d 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html @@ -1,11 +1,11 @@
-

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
-
+

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
+
-

{L_GRAVATAR_AVATAR_SIZE_EXPLAIN}
+

{L_GRAVATAR_AVATAR_SIZE_EXPLAIN}
- ×  - + ×  +
diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html index 8b46dfa7f5..d885abcd5b 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html @@ -1,16 +1,16 @@ - - + diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html index cf3eb20a39..ab91e90c27 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html @@ -1,11 +1,11 @@
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
+

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
+

{L_LINK_REMOTE_SIZE_EXPLAIN}
- ×  - + ×  +
diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html b/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html index d0a4f516e1..9d3efbd018 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_upload.html @@ -1,11 +1,11 @@
-
-
+
+
-

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
+

{L_UPLOAD_AVATAR_URL_EXPLAIN}
+
diff --git a/phpBB/styles/subsilver2/template/avatars.js b/phpBB/styles/subsilver2/template/avatars.js index a9b2cc5722..df6aad178a 100644 --- a/phpBB/styles/subsilver2/template/avatars.js +++ b/phpBB/styles/subsilver2/template/avatars.js @@ -3,10 +3,10 @@ "use strict"; function avatar_simplify() { - $('.[class^="av_option_"]').hide(); + $('.[class^="avatar_option_"]').hide(); var selected = $('#avatar_driver').val(); - $('.av_option_' + selected).show(); + $('.avatar_option_' + selected).show(); } avatar_simplify(); diff --git a/phpBB/styles/subsilver2/template/ucp_avatar_options_gravatar.html b/phpBB/styles/subsilver2/template/ucp_avatar_options_gravatar.html index 9bf8a3fc39..b8840e0aab 100644 --- a/phpBB/styles/subsilver2/template/ucp_avatar_options_gravatar.html +++ b/phpBB/styles/subsilver2/template/ucp_avatar_options_gravatar.html @@ -1,13 +1,13 @@ - +
{L_GRAVATAR_AVATAR_EMAIL}{L_COLON}
{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
{L_GRAVATAR_AVATAR_SIZE}{L_COLON}
{L_GRAVATAR_AVATAR_SIZE_EXPLAIN}
- {L_PIXEL} ×  - {L_PIXEL} + {L_PIXEL} ×  + {L_PIXEL}
diff --git a/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html b/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html index 352052f9f4..f4273192ad 100644 --- a/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html +++ b/phpBB/styles/subsilver2/template/ucp_avatar_options_local.html @@ -1,32 +1,32 @@ - diff --git a/phpBB/styles/subsilver2/template/ucp_avatar_options_remote.html b/phpBB/styles/subsilver2/template/ucp_avatar_options_remote.html index 8fe7201953..50ebb9b93d 100644 --- a/phpBB/styles/subsilver2/template/ucp_avatar_options_remote.html +++ b/phpBB/styles/subsilver2/template/ucp_avatar_options_remote.html @@ -1,10 +1,10 @@
{L_AVATAR_CATEGORY}{L_COLON} {L_AVATAR_CATEGORY}{L_COLON}   + + + +  
- + - - - + + + - - - + + + - +
{av_local_col.av_local_col.AVATAR_NAME}{avatar_local_col.avatar_local_col.AVATAR_NAME}
{L_NO_AVATAR_CATEGORY}
- + - +
{L_LINK_REMOTE_AVATAR}{L_COLON}
{L_LINK_REMOTE_AVATAR_EXPLAIN}
{L_LINK_REMOTE_SIZE}{L_COLON}
{L_LINK_REMOTE_SIZE_EXPLAIN}
{L_PIXEL} × {L_PIXEL} {L_PIXEL} × {L_PIXEL}
diff --git a/phpBB/styles/subsilver2/template/ucp_avatar_options_upload.html b/phpBB/styles/subsilver2/template/ucp_avatar_options_upload.html index e76abc0433..6b813baeaa 100644 --- a/phpBB/styles/subsilver2/template/ucp_avatar_options_upload.html +++ b/phpBB/styles/subsilver2/template/ucp_avatar_options_upload.html @@ -1,12 +1,12 @@ - + - +
{L_UPLOAD_AVATAR_FILE}{L_COLON}
{L_UPLOAD_AVATAR_URL}{L_COLON}
{L_UPLOAD_AVATAR_URL_EXPLAIN}
diff --git a/phpBB/styles/subsilver2/template/ucp_groups_manage.html b/phpBB/styles/subsilver2/template/ucp_groups_manage.html index e15335f4e1..8064e1e6e9 100644 --- a/phpBB/styles/subsilver2/template/ucp_groups_manage.html +++ b/phpBB/styles/subsilver2/template/ucp_groups_manage.html @@ -60,7 +60,7 @@
{L_AVATAR_EXPLAIN} - {AVATAR_IMAGE}

 {L_DELETE_AVATAR} + {AVATAR_IMAGE}

 {L_DELETE_AVATAR} @@ -81,10 +81,10 @@ - + {avatar_drivers.L_EXPLAIN} - + {avatar_drivers.OUTPUT} diff --git a/phpBB/styles/subsilver2/template/ucp_profile_avatar.html b/phpBB/styles/subsilver2/template/ucp_profile_avatar.html index 4e65b37e3c..4c7458e940 100644 --- a/phpBB/styles/subsilver2/template/ucp_profile_avatar.html +++ b/phpBB/styles/subsilver2/template/ucp_profile_avatar.html @@ -12,7 +12,7 @@ {L_CURRENT_IMAGE}{L_COLON}
{L_AVATAR_EXPLAIN}
- {AVATAR}

 {L_DELETE_AVATAR} + {AVATAR}

 {L_DELETE_AVATAR} @@ -35,10 +35,10 @@ - + {avatar_drivers.L_EXPLAIN} - + {avatar_drivers.OUTPUT} From 7945ffa2a131c1539a4aa929039c4d44b8e4d336 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 01:02:43 +0100 Subject: [PATCH 075/138] [feature/avatars] Use new avatar types in database updater PHPBB3-10018 --- phpBB/install/database_update.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 2015ef0475..d471833442 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2714,9 +2714,9 @@ function change_database_data(&$no_updates, $version) // Update avatars to modular types $avatar_type_map = array( - AVATAR_UPLOAD => 'upload', - AVATAR_GALLERY => 'local', - AVATAR_REMOTE => 'remote', + AVATAR_UPLOAD => 'avatar.driver.upload', + AVATAR_GALLERY => 'avatar.driver.local', + AVATAR_REMOTE => 'avatar.driver.remote', ); foreach ($avatar_type_map as $old => $new) From ce5e2f16777ae5319fcb902ee58005a4caced7e6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 01:18:27 +0100 Subject: [PATCH 076/138] [feature/avatars] Miscellaneous fixes PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 14 ++++++++------ phpBB/includes/acp/acp_users.php | 12 +++++++----- phpBB/includes/avatar/driver/gravatar.php | 5 ++--- phpBB/includes/avatar/driver/remote.php | 2 +- phpBB/includes/ucp/ucp_groups.php | 2 +- phpBB/includes/ucp/ucp_profile.php | 2 +- phpBB/install/database_update.php | 20 ++++++++++---------- 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 3a49ac8ff8..7a66f993b0 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -334,7 +334,7 @@ class acp_groups { // Handle avatar $driver = str_replace('_', '.', request_var('avatar_driver', '')); - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { @@ -534,7 +534,7 @@ class acp_groups if ($avatar->is_enabled()) { $avatars_enabled = true; - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $template->set_filenames(array( 'avatar' => "acp_avatar_options_$config_name.html", )); @@ -558,8 +558,10 @@ class acp_groups $avatar = get_group_avatar($group_row, 'GROUP_AVATAR', true); - // Merge any avatars errors into the primary error array - // Drivers use lang constants, so we need to map to the actual strings + /* + * Merge any avatar errors into the primary error array + * Drivers use language constants, so we need to map to the actual strings + */ foreach ($avatar_error as $e) { if (is_array($e)) @@ -569,7 +571,7 @@ class acp_groups } else { - $error[] = $user->lang((string) $e); + $error[] = $user->lang("$e"); } } @@ -615,7 +617,7 @@ class acp_groups 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)), - 'AVATAR' => (empty($avatar) ? '' : $avatar), + 'AVATAR' => empty($avatar) ? '' : $avatar, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '', diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 2f7662982a..8e194dc91d 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -454,7 +454,7 @@ class acp_users { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } - + $sql_ary = array( 'user_avatar' => '', 'user_avatar_type' => '', @@ -1745,7 +1745,7 @@ class acp_users if (check_form_key($form_name)) { $driver = str_replace('_', '.', request_var('avatar_driver', '')); - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { @@ -1761,6 +1761,7 @@ class acp_users 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height'], ); + $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' WHERE user_id = ' . $user_id; @@ -1771,7 +1772,8 @@ class acp_users } else { - if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); + if ($avatar) { $avatar->delete($avatar_data); } @@ -1786,7 +1788,7 @@ class acp_users $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user_id; + WHERE user_id = ' . (int) $user_id; $db->sql_query($sql); trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); @@ -1807,7 +1809,7 @@ class acp_users if ($avatar->is_enabled()) { $avatars_enabled = true; - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $template->set_filenames(array( 'avatar' => "acp_avatar_options_$config_name.html", )); diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index d873f7ba41..cca7289275 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -56,11 +56,10 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver */ public function get_custom_html($row, $ignore_config = false, $alt = '') { - $html = ''; - return $html; } /** @@ -121,7 +120,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver $row['avatar_width'] = $row['avatar_height'] = min($this->config['avatar_max_width'], $this->config['avatar_max_height']); $url = $this->get_gravatar_url($row); - if (($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) && (($image_data = @getimagesize($url)) === false)) + if (($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) && (($image_data = getimagesize($url)) === false)) { $error[] = 'UNABLE_GET_IMAGE_SIZE'; return false; diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index c2ae88cc02..f47b0d33f4 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -106,7 +106,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver // Make sure getimagesize works... if (function_exists('getimagesize')) { - if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) + if (($width <= 0 || $height <= 0) && (($image_data = getimagesize($url)) === false)) { $error[] = 'UNABLE_GET_IMAGE_SIZE'; return false; diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 2a388d17f8..5289a95e6d 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -521,7 +521,7 @@ class ucp_groups { // Handle avatar $driver = str_replace('_', '.', request_var('avatar_driver', '')); - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index ab49a11f99..402db86c1d 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -564,7 +564,7 @@ class ucp_profile if (check_form_key('ucp_avatar')) { $driver = str_replace('_', '.', request_var('avatar_driver', '')); - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index d471833442..b27613168f 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2722,27 +2722,27 @@ function change_database_data(&$no_updates, $version) foreach ($avatar_type_map as $old => $new) { $sql = 'UPDATE ' . USERS_TABLE . " - SET user_avatar_type = '" . $db->sql_escape($new) . "' - WHERE user_avatar_type = '" . $db->sql_escape($old) . "'"; + SET user_avatar_type = '" . $new . "' + WHERE user_avatar_type = '" . $old . "'"; _sql($sql, $errored, $error_ary); $sql = 'UPDATE ' . GROUPS_TABLE . " - SET group_avatar_type = '" . $db->sql_escape($new) . "' - WHERE group_avatar_type = '" . $db->sql_escape($old) . "'"; + SET group_avatar_type = '" . $new . "' + WHERE group_avatar_type = '" . $old . "'"; _sql($sql, $errored, $error_ary); } // update avatar module_auth - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload || cfg_allow_avatar_gravatar)\' - WHERE module_class = \'ucp\' - AND module_basename = \'ucp_profile\' - AND module_mode = \'avatar\''; + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_auth = 'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload || cfg_allow_avatar_gravatar)' + WHERE module_class = 'ucp' + AND module_basename = 'ucp_profile' + AND module_mode = 'avatar'"; _sql($sql, $errored, $error_ary); if (!isset($config['allow_avatar_gravatar'])) { - $config->set('allow_avatar_gravatar', ''); + $config->set('allow_avatar_gravatar', '0'); } $no_updates = false; From 67c2e48d15d6e4ddd244dd2e126f906ed25be1ef Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 14:33:13 +0100 Subject: [PATCH 077/138] [feature/avatars] Only create avatar objects if necessary PHPBB3-10018 --- phpBB/common.php | 2 -- phpBB/includes/acp/acp_board.php | 3 ++- phpBB/includes/acp/acp_groups.php | 3 ++- phpBB/includes/acp/acp_users.php | 5 ++++- phpBB/includes/functions_display.php | 3 ++- phpBB/includes/ucp/ucp_groups.php | 3 ++- phpBB/includes/ucp/ucp_profile.php | 3 ++- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 17e7c76465..c4237dfcf5 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -128,8 +128,6 @@ $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); $template = $phpbb_container->get('template'); $phpbb_style = $phpbb_container->get('style'); -$phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'display'))); diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 5852f512cd..95da62dedf 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -28,7 +28,7 @@ class acp_board { global $db, $user, $auth, $template; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; - global $cache, $phpbb_avatar_manager; + global $cache, $phpbb_container; $user->add_lang('acp/board'); @@ -107,6 +107,7 @@ class acp_board break; case 'avatar': + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); $avatar_vars = array(); diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 7a66f993b0..c09f447f76 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -26,7 +26,7 @@ class acp_groups { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; - global $request, $phpbb_avatar_manager; + global $request, $phpbb_container; $user->add_lang('acp/groups'); $this->tpl_name = 'acp_groups'; @@ -282,6 +282,7 @@ class acp_groups $user->add_lang('ucp'); // Setup avatar data for later + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; $avatar_drivers = null; $avatar_data = null; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 8e194dc91d..885233bbd3 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -33,7 +33,7 @@ class acp_users global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; global $phpbb_dispatcher, $request; - global $phpbb_avatar_manager; + global $phpbb_container; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; @@ -468,6 +468,7 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type']); if ($driver) { @@ -1732,6 +1733,8 @@ class acp_users include($phpbb_root_path . 'includes/functions_display.' . $phpEx); $avatars_enabled = false; + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); + if ($config['allow_avatar']) { $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index bf1611a5de..669641de70 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1353,7 +1353,7 @@ function get_avatar($row, $alt, $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; global $request; - global $phpbb_avatar_manager; + global $phpbb_container; if (!$config['allow_avatar'] && !$ignore_config) { @@ -1366,6 +1366,7 @@ function get_avatar($row, $alt, $ignore_config = false) 'height' => $row['avatar_height'], ); + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); if ($avatar) diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 5289a95e6d..33f147a47e 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -27,7 +27,7 @@ class ucp_groups { global $config, $phpbb_root_path, $phpEx; global $db, $user, $auth, $cache, $template; - global $request, $phpbb_avatar_manager; + global $request, $phpbb_container; $user->add_lang('groups'); @@ -484,6 +484,7 @@ class ucp_groups $error = array(); // Setup avatar data for later + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; $avatar_drivers = null; $avatar_data = null; diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 402db86c1d..3945fc537a 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -30,7 +30,7 @@ class ucp_profile { global $cache, $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; global $request; - global $phpbb_avatar_manager; + global $phpbb_container; $user->add_lang('posting'); @@ -549,6 +549,7 @@ class ucp_profile add_form_key('ucp_avatar'); + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) From 6d061304afaa703a5305a06a903356d1c48ff2ee Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 15:03:35 +0100 Subject: [PATCH 078/138] [feature/avatars] Small fixes PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index c09f447f76..136ceeff3c 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -337,6 +337,7 @@ class acp_groups $driver = str_replace('_', '.', request_var('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { $avatar = $phpbb_avatar_manager->get_driver($driver); @@ -344,19 +345,15 @@ class acp_groups if ($result && empty($avatar_error)) { - $result = array( - 'avatar_type' => $driver, - 'avatar' => $result['avatar'], - 'avatar_width' => $result['avatar_width'], - 'avatar_height' => $result['avatar_height'], - ); + $result['avatar_type'] = $driver; $submit_ary = array_merge($submit_ary, $result); } } else { - if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']) + if ($avatar) { $avatar->delete($avatar_data); } From 06639729ea2da6d0025da74ae7d4f3e88f211b67 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 16:04:59 +0100 Subject: [PATCH 079/138] [feature/avatars] Add static methods for handling driver names PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 6 +++--- phpBB/includes/acp/acp_users.php | 6 +++--- phpBB/includes/avatar/manager.php | 26 ++++++++++++++++++++++++++ phpBB/includes/ucp/ucp_groups.php | 6 +++--- phpBB/includes/ucp/ucp_profile.php | 6 +++--- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 136ceeff3c..2969f34b24 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -334,7 +334,7 @@ class acp_groups if ($config['allow_avatar']) { // Handle avatar - $driver = str_replace('_', '.', request_var('avatar_driver', '')); + $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); @@ -523,7 +523,7 @@ class acp_groups if ($config['allow_avatar']) { $avatars_enabled = false; - $focused_driver = str_replace('_', '.', request_var('avatar_driver', $avatar_data['avatar_type'])); + $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); foreach ($avatar_drivers as $driver) { @@ -539,7 +539,7 @@ class acp_groups if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { - $driver_name = str_replace('.', '_', $driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 885233bbd3..44e4f14ae2 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1747,7 +1747,7 @@ class acp_users { if (check_form_key($form_name)) { - $driver = str_replace('_', '.', request_var('avatar_driver', '')); + $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) @@ -1803,7 +1803,7 @@ class acp_users } } - $focused_driver = str_replace('_', '.', request_var('avatar_driver', $user_row['user_avatar_type'])); + $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type'])); foreach ($avatar_drivers as $driver) { @@ -1819,7 +1819,7 @@ class acp_users if ($avatar->prepare_form($template, $avatar_data, $error)) { - $driver_name = str_replace('.', '_', $driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index da9d843947..51727f242a 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -152,4 +152,30 @@ class phpbb_avatar_manager return array_combine($keys, $values); } + + /** + * Clean driver names that are returned from template files + * Underscores are replaced with dots + * + * @param string $name Driver name + * + * @return string Cleaned driver name + */ + public static function clean_driver_name($name) + { + return str_replace('_', '.', $name); + } + + /** + * Prepare driver names for use in template files + * Dots are replaced with underscores + * + * @param string $name Clean driver name + * + * @return string Prepared driver name + */ + public static function prepare_driver_name($name) + { + return str_replace('.', '_', $name); + } } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 33f147a47e..df6915711c 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -521,7 +521,7 @@ class ucp_groups if ($config['allow_avatar']) { // Handle avatar - $driver = str_replace('_', '.', request_var('avatar_driver', '')); + $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) @@ -652,7 +652,7 @@ class ucp_groups if ($config['allow_avatar']) { $avatars_enabled = false; - $focused_driver = str_replace('_', '.', request_var('avatar_driver', $avatar_data['avatar_type'])); + $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); foreach ($avatar_drivers as $driver) { @@ -667,7 +667,7 @@ class ucp_groups if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { - $driver_name = str_replace('.', '_', $driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 3945fc537a..36ac227bc8 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -564,7 +564,7 @@ class ucp_profile { if (check_form_key('ucp_avatar')) { - $driver = str_replace('_', '.', request_var('avatar_driver', '')); + $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) @@ -624,7 +624,7 @@ class ucp_profile } } - $focused_driver = str_replace('_', '.', request_var('avatar_driver', $user->data['user_avatar_type'])); + $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type'])); foreach ($avatar_drivers as $driver) { @@ -639,7 +639,7 @@ class ucp_profile if ($avatar->prepare_form($template, $avatar_data, $error)) { - $driver_name = str_replace('.', '_', $driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( From f8256ed00f5ecc95fbf9f69fd2e8de2a92bccec6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 16:18:51 +0100 Subject: [PATCH 080/138] [feature/avatars] Small cosmetic changes PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 3 +-- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/ucp/ucp_groups.php | 13 ++++--------- phpBB/includes/ucp/ucp_profile.php | 4 ++-- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 2969f34b24..a55087adce 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -336,9 +336,8 @@ class acp_groups // Handle avatar $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $avatar_delete = $request->variable('avatar_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $avatar_error); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 44e4f14ae2..823f001fe0 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1749,8 +1749,8 @@ class acp_users { $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $avatar_delete = $request->variable('avatar_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) + + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index df6915711c..dd03f332ff 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -523,21 +523,16 @@ class ucp_groups // Handle avatar $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $avatar_delete = $request->variable('avatar_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) + + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { - $result = array( - 'avatar_type' => $driver, - 'avatar' => $result['avatar'], - 'avatar_width' => $result['avatar_width'], - 'avatar_height' => $result['avatar_height'], - ); - + $result['avatar_type'] = $driver; + $submit_ary = array_merge($submit_ary, $result); } } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 36ac227bc8..88820beac1 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -566,8 +566,8 @@ class ucp_profile { $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $avatar_delete = $request->variable('avatar_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) + + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); From a77fcdb5f93ed291c223c445a46a5641cfdb27ea Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 17:01:21 +0100 Subject: [PATCH 081/138] [feature/avatars] Implement better treatment of avatar errors PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 10 +++++----- phpBB/includes/acp/acp_users.php | 14 ++++++-------- phpBB/includes/ucp/ucp_groups.php | 10 +++++----- phpBB/includes/ucp/ucp_profile.php | 12 +++++------- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index a55087adce..19006df306 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -559,16 +559,16 @@ class acp_groups * Merge any avatar errors into the primary error array * Drivers use language constants, so we need to map to the actual strings */ - foreach ($avatar_error as $e) + foreach ($avatar_error as $lang) { - if (is_array($e)) + if (is_array($lang)) { - $key = array_shift($e); - $error[] = vsprintf($user->lang($key), $e); + $key = array_shift($lang); + $error[] = vsprintf($user->lang($key), $lang); } else { - $error[] = $user->lang("$e"); + $error[] = $user->lang("$lang"); } } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 823f001fe0..e0dcea6d58 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1836,21 +1836,19 @@ class acp_users } // Replace "error" strings with their real, localised form - $err = $error; - $error = array(); - foreach ($err as $e) + foreach ($error as $key => $lang) { - if (is_array($e)) + if (is_array($lang)) { - $key = array_shift($e); - $error[] = vsprintf($user->lang($key), $e); + $lang_key = array_shift($lang); + $error[$key] = vsprintf($user->lang($lang_key), $lang); } else { - $error[] = $user->lang((string) $e); + $error[$key] = $user->lang("$lang"); } } - + $avatar = get_user_avatar($user_row, 'USER_AVATAR', true); $template->assign_vars(array( diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index dd03f332ff..3860d22917 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -679,16 +679,16 @@ class ucp_groups // Merge any avatars errors into the primary error array // Drivers use lang constants, so we need to map to the actual strings - foreach ($avatar_error as $e) + foreach ($avatar_error as $lang) { - if (is_array($e)) + if (is_array($lang)) { - $key = array_shift($e); - $error[] = vsprintf($user->lang($key), $e); + $key = array_shift($lang); + $error[] = vsprintf($user->lang($key), $lang); } else { - $error[] = $user->lang((string) $e); + $error[] = $user->lang("$lang"); } } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 88820beac1..c05105eaff 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -656,18 +656,16 @@ class ucp_profile } // Replace "error" strings with their real, localised form - $err = $error; - $error = array(); - foreach ($err as $e) + foreach ($error as $key => $lang) { - if (is_array($e)) + if (is_array($lang)) { - $key = array_shift($e); - $error[] = vsprintf($user->lang($key), $e); + $key = array_shift($lang); + $error[$key] = vsprintf($user->lang($key), $lang); } else { - $error[] = $user->lang((string) $e); + $error[$key] = $user->lang("$lang"); } } From 6522190ff1b7a7b4384389f23c1229911c1a58d2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 20:50:31 +0100 Subject: [PATCH 082/138] [feature/avatars] Docblock fixes and small change for php_ext PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 60 +++++++++++------------ phpBB/includes/avatar/driver/gravatar.php | 2 +- phpBB/includes/avatar/driver/remote.php | 4 +- phpBB/includes/avatar/driver/upload.php | 4 +- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 710d3dfe20..c6b864bc9f 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -23,26 +23,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { protected $name; - /** - * Returns the name of the driver. - * - * @return string Name of wrapped driver. - */ - public function get_name() - { - return $this->name; - } - - /** - * Sets the name of the driver. - * - * @param string $name The driver name - */ - public function set_name($name) - { - $this->name = $name; - } - /** * Current board configuration * @type phpbb_config @@ -50,8 +30,8 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface protected $config; /** - * Current board configuration - * @type phpbb_config + * Request object + * @type phpbb_request */ protected $request; @@ -62,10 +42,10 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface protected $phpbb_root_path; /** - * Current $phpEx + * Current $php_ext * @type string */ - protected $phpEx; + protected $php_ext; /** * A cache driver @@ -83,18 +63,18 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * Construct a driver object * - * @param $config The phpBB configuration - * @param $request The request object - * @param $phpbb_root_path The path to the phpBB root - * @param $phpEx The php file extension - * @param $cache A cache driver + * @param phpbb_config $config The phpBB configuration + * @param phpbb_request $request The request object + * @param string $phpbb_root_path The path to the phpBB root + * @param string $php_ext The php file extension + * @param phpbb_cache_driver_interface $cache A cache driver */ - public function __construct(phpbb_config $config, phpbb_request $request, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null) + public function __construct(phpbb_config $config, phpbb_request $request, $phpbb_root_path, $php_ext, phpbb_cache_driver_interface $cache = null) { $this->config = $config; $this->request = $request; $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->cache = $cache; } @@ -170,4 +150,22 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface return $template; } + + /** + * @inheritdoc + */ + public function get_name() + { + return $this->name; + } + + /** + * Sets the name of the driver. + * + * @param string $name The driver name + */ + public function set_name($name) + { + $this->name = $name; + } } diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index cca7289275..e21743242f 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -95,7 +95,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver $row['avatar_width'] = $this->request->variable('avatar_gravatar_width', 0); $row['avatar_height'] = $this->request->variable('avatar_gravatar_height', 0); - require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx); + require_once($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); $error = array_merge($error, validate_data(array( 'email' => $row['avatar'], diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index f47b0d33f4..134bf070e5 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -82,7 +82,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver $url = 'http://' . $url; } - require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx); + require_once($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); $error = array_merge($error, validate_data(array( 'url' => $url, @@ -128,7 +128,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver return false; } - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->phpEx); + include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); $types = fileupload::image_types(); $extension = strtolower(filespec::get_extension($url)); diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 9035b5364e..91de47e66d 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -29,7 +29,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver if ($ignore_config || $this->config['allow_avatar_upload']) { return array( - 'src' => $this->phpbb_root_path . 'download/file' . $this->phpEx . '?avatar=' . $row['avatar'], + 'src' => $this->phpbb_root_path . 'download/file' . $this->php_ext . '?avatar=' . $row['avatar'], 'width' => $row['avatar_width'], 'height' => $row['avatar_height'], ); @@ -72,7 +72,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver return false; } - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->phpEx); + include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $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)); From f851d763f9997b896219d1068dd23f6de7dbfc36 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 21:14:05 +0100 Subject: [PATCH 083/138] [feature/avatars] Even more fixes to docblocks PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 42 ++++++++++++---------- phpBB/includes/avatar/driver/gravatar.php | 4 +-- phpBB/includes/avatar/driver/interface.php | 38 ++++++++++---------- phpBB/includes/avatar/driver/local.php | 4 +-- phpBB/includes/avatar/driver/remote.php | 2 +- phpBB/includes/avatar/driver/upload.php | 2 +- phpBB/includes/avatar/manager.php | 34 +++++++++--------- 7 files changed, 65 insertions(+), 61 deletions(-) diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index c6b864bc9f..234186215b 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -21,53 +21,57 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { + /** + * Avatar driver name + * @var string + */ protected $name; /** * Current board configuration - * @type phpbb_config + * @var phpbb_config */ protected $config; /** * Request object - * @type phpbb_request + * @var phpbb_request */ protected $request; /** * Current $phpbb_root_path - * @type string + * @var string */ protected $phpbb_root_path; /** * Current $php_ext - * @type string + * @var string */ protected $php_ext; /** - * A cache driver - * @type phpbb_cache_driver_interface + * Cache driver + * @var phpbb_cache_driver_interface */ protected $cache; /** * This flag should be set to true if the avatar requires a nonstandard image * tag, and will generate the html itself. - * @type boolean + * @var boolean */ public $custom_html = false; /** * Construct a driver object * - * @param phpbb_config $config The phpBB configuration - * @param phpbb_request $request The request object - * @param string $phpbb_root_path The path to the phpBB root - * @param string $php_ext The php file extension - * @param phpbb_cache_driver_interface $cache A cache driver + * @param phpbb_config $config phpBB configuration + * @param phpbb_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 */ public function __construct(phpbb_config $config, phpbb_request $request, $phpbb_root_path, $php_ext, phpbb_cache_driver_interface $cache = null) { @@ -100,7 +104,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function prepare_form($template, $row, &$error) { return false; @@ -108,7 +112,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function prepare_form_acp() { return array(); @@ -116,7 +120,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function process_form($template, $row, &$error) { return false; @@ -124,7 +128,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function delete($row) { return true; @@ -132,7 +136,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function is_enabled() { $driver = preg_replace('#^phpbb_avatar_driver_#', '', get_class($this)); @@ -142,7 +146,7 @@ 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)); @@ -162,7 +166,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * Sets the name of the driver. * - * @param string $name The driver name + * @param string $name Driver name */ public function set_name($name) { diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index e21743242f..a90c0e3ce1 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -78,7 +78,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * @inheritdoc - **/ + */ public function prepare_form_acp() { return array( @@ -170,7 +170,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * Build gravatar URL for output on page * - * @return string The gravatar URL + * @return string Gravatar URL */ protected function get_gravatar_url($row) { diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index 28220d79f2..cc6b7edd17 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -24,7 +24,7 @@ interface phpbb_avatar_driver_interface /** * Returns the name of the driver. * - * @return string Name of wrapped driver. + * @return string Name of wrapped driver. */ public function get_name(); @@ -43,7 +43,7 @@ interface phpbb_avatar_driver_interface * Returns custom html for displaying this avatar. * Only called if $custom_html is true. * - * @param $ignore_config Whether this function should respect the users prefs + * @param bool $ignore_config Whether this function should respect the users prefs * and board configuration configuration option, or should just render * the avatar anyways. Useful for the ACP. * @return string HTML @@ -53,56 +53,56 @@ interface phpbb_avatar_driver_interface /** * Prepare form for changing the settings of this avatar * - * @param object $template The template object - * @param array $row The user data or group data that has been cleaned with + * @param object $template Template object + * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row - * @param array &$error The reference to an error array + * @param array &$error Reference to an error array * - * @return bool Returns true if form has been successfully prepared - **/ + * @return bool True if form has been successfully prepared + */ public function prepare_form($template, $row, &$error); /** * Prepare form for changing the acp settings of this avatar * - * @return array Return the array containing the acp settings - **/ + * @return array Array containing the acp settings + */ public function prepare_form_acp(); /** * Process form data * - * @param object $template The template object - * @param array $row The user data or group data that has been cleaned with + * @param object $template Template object + * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row - * @param array &$error The reference to an error array + * @param array &$error Reference to an error array * - * @return array An array containing the avatar data as follows: + * @return array Array containing the avatar data as follows: * ['avatar'], ['avatar_width'], ['avatar_height'] - **/ + */ public function process_form($template, $row, &$error); /** * Delete avatar * - * @param array $row The user data or group data that has been cleaned with + * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row * * @return bool True if avatar has been deleted or there is no need to delete - **/ + */ public function delete($row); /** * Check if avatar is enabled * * @return bool True if avatar is enabled, false if it's disabled - **/ + */ public function is_enabled(); /** * Get the avatars template name * - * @return string The avatars template name - **/ + * @return string Avatar's template name + */ public function get_template_name(); } diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index c231206d8e..d46ac79d11 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -114,7 +114,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc - **/ + */ public function prepare_form_acp() { return array( @@ -148,7 +148,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * Get a list of avatars that are locally available * - * @return array An array containing the locally available avatars + * @return array Array containing the locally available avatars */ protected function get_avatar_list() { diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 134bf070e5..b7522ac3e1 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -60,7 +60,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc - **/ + */ public function prepare_form_acp() { return array( diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 91de47e66d..f00033d6bd 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -124,7 +124,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc - **/ + */ public function prepare_form_acp() { global $user; diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 51727f242a..ae628f0ce2 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -32,14 +32,14 @@ class phpbb_avatar_manager /** * Construct an avatar manager object * - * @param $phpbb_root_path The path to the phpBB root - * @param $phpEx The php file extension - * @param $config The phpBB configuration - * @param $request The request object - * @param $cache A cache driver - * @param $avatar_drivers The avatars drivers passed via the service container - * @param $container The container object - **/ + * @param string $phpbb_root_path Path to the phpBB root + * @param string $phpEx PHP file extension + * @param phpbb_config $config phpBB configuration + * @param phpbb_request $request Request object + * @param phpbb_cache_driver_interface $cache Cache driver + * @param array $avatar_drivers Avatar drivers passed via the service container + * @param object $container Container object + */ public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache, $avatar_drivers, $container) { $this->phpbb_root_path = $phpbb_root_path; @@ -54,10 +54,10 @@ class phpbb_avatar_manager /** * Get the driver object specified by the avatar type * - * @param string The avatar type; by default an avatar's service container name + * @param string Avatar type; by default an avatar's service container name * - * @return object The avatar driver object - **/ + * @return object Avatar driver object + */ public function get_driver($avatar_type) { if (self::$valid_drivers === false) @@ -101,7 +101,7 @@ class phpbb_avatar_manager /** * Load the list of valid drivers * This is executed once and fills self::$valid_drivers - **/ + */ protected function load_valid_drivers() { if (!empty($this->avatar_drivers)) @@ -117,8 +117,8 @@ class phpbb_avatar_manager /** * Get a list of valid avatar drivers * - * @return array An array containing a list of the valid avatar drivers - **/ + * @return array Array containing a list of the valid avatar drivers + */ public function get_valid_drivers() { if (self::$valid_drivers === false) @@ -132,11 +132,11 @@ class phpbb_avatar_manager /** * Strip out user_ and group_ prefixes from keys * - * @param array $row The user data or group data + * @param array $row User data or group data * - * @return array The user data or group data with keys that have been + * @return array User data or group data with keys that have been * stripped from the preceding "user_" or "group_" - **/ + */ public static function clean_row($row) { $keys = array_keys($row); From 0abec06b09c71feb709b6101949181ff7ec4d882 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 21:16:21 +0100 Subject: [PATCH 084/138] [feature/avatars] Change gravatar explain as discussed in PR PHPBB3-10018 --- phpBB/language/en/ucp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index d397ca5538..7223b13b29 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -90,7 +90,7 @@ $lang = array_merge($lang, array( 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected persistent login keys were successfully deleted.', 'AVATAR_CATEGORY' => 'Category', 'AVATAR_DRIVER_GRAVATAR_TITLE' => 'Gravatar', - 'AVATAR_DRIVER_GRAVATAR_EXPLAIN'=> 'Gravatar is a service that provides you with a globally unique avatar.', + 'AVATAR_DRIVER_GRAVATAR_EXPLAIN'=> 'Gravatar is a service that allows you to maintain the same avatar across multiple websites. Visit Gravatar for more information.', 'AVATAR_DRIVER_LOCAL_TITLE' => 'Gallery avatar', 'AVATAR_DRIVER_LOCAL_EXPLAIN' => 'You can choose your avatar from a locally available set of avatars.', 'AVATAR_DRIVER_REMOTE_TITLE' => 'Remote avatar', From cb1d98ab7f588a38fcae680aca839b805caf2a23 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Nov 2012 23:06:38 +0100 Subject: [PATCH 085/138] [feature/avatars] Check for existing functions rather than using _once PHPBB3-10018 --- phpBB/includes/avatar/driver/gravatar.php | 5 ++++- phpBB/includes/avatar/driver/remote.php | 11 +++++++++-- phpBB/includes/avatar/driver/upload.php | 5 ++++- phpBB/includes/ucp/ucp_profile.php | 5 ++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index a90c0e3ce1..7e21a737a1 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -95,7 +95,10 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver $row['avatar_width'] = $this->request->variable('avatar_gravatar_width', 0); $row['avatar_height'] = $this->request->variable('avatar_gravatar_height', 0); - require_once($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); + if (!function_exists('user_add')) + { + require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); + } $error = array_merge($error, validate_data(array( 'email' => $row['avatar'], diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index b7522ac3e1..1da5fc16e8 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -82,7 +82,10 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver $url = 'http://' . $url; } - require_once($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); + if (!function_exists('user_add')) + { + require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); + } $error = array_merge($error, validate_data(array( 'url' => $url, @@ -128,7 +131,11 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver return false; } - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + if (!class_exists('fileupload')) + { + include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + } + $types = fileupload::image_types(); $extension = strtolower(filespec::get_extension($url)); diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index f00033d6bd..497dd8ad19 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -72,7 +72,10 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver return false; } - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + if (!class_exists('fileupload')) + { + include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + } $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $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)); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index c05105eaff..c8547e48d8 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -545,7 +545,10 @@ class ucp_profile break; case 'avatar': - include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); + if (!function_exists('display_forums')) + { + include($phpbb_root_path . 'includes/functions_display.' . $phpEx); + } add_form_key('ucp_avatar'); From 81a1a21185abfc230097a355216d6c6b99511b20 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 29 Nov 2012 23:08:29 +0100 Subject: [PATCH 086/138] [feature/avatars] Properly implement custom HTML in the interface Previously the driver class added a variable that defined wether an avatar driver would return custom HTML. The existence of this variable was implied in the interface. It's also not needed which is why it has been removed. PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 7 ------- phpBB/includes/avatar/driver/gravatar.php | 6 ++---- phpBB/includes/avatar/driver/interface.php | 3 +-- phpBB/includes/functions_display.php | 8 ++++---- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 234186215b..6710f1f153 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -57,13 +57,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface */ protected $cache; - /** - * This flag should be set to true if the avatar requires a nonstandard image - * tag, and will generate the html itself. - * @var boolean - */ - public $custom_html = false; - /** * Construct a driver object * diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 7e21a737a1..6ceac1a149 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -21,12 +21,10 @@ if (!defined('IN_PHPBB')) */ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver { - const GRAVATAR_URL = 'https://secure.gravatar.com/avatar/'; - /** - * @inheritdoc + * The URL for the gravatar service */ - public $custom_html = true; + const GRAVATAR_URL = 'https://secure.gravatar.com/avatar/'; /** * @inheritdoc diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index cc6b7edd17..d2f25a989f 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -40,8 +40,7 @@ interface phpbb_avatar_driver_interface public function get_data($row, $ignore_config = false); /** - * Returns custom html for displaying this avatar. - * Only called if $custom_html is true. + * Returns custom html if it is needed for displaying this avatar * * @param bool $ignore_config Whether this function should respect the users prefs * and board configuration configuration option, or should just render diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 669641de70..a7b28acac1 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1368,12 +1368,14 @@ function get_avatar($row, $alt, $ignore_config = false) $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); + $html = ''; if ($avatar) { - if ($avatar->custom_html) + $html = $avatar->get_custom_html($row, $ignore_config, $alt); + if (!empty($html)) { - return $avatar->get_custom_html($row, $ignore_config, $alt); + return $html; } $avatar_data = $avatar->get_data($row, $ignore_config); @@ -1383,8 +1385,6 @@ function get_avatar($row, $alt, $ignore_config = false) $avatar_data['src'] = ''; } - $html = ''; - if (!empty($avatar_data['src'])) { $html = ' Date: Thu, 29 Nov 2012 23:50:17 +0100 Subject: [PATCH 087/138] [feature/avatars] Get list of enabled drivers from avatar manager This shouldn't be done in the avatar drivers. We need to force the display all avatar drivers in the ACP or it won't be possible to enable avatars after they have been disabled. PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/acp/acp_groups.php | 35 ++++++++++---------- phpBB/includes/acp/acp_users.php | 37 ++++++++++------------ phpBB/includes/avatar/driver/driver.php | 10 ------ phpBB/includes/avatar/driver/interface.php | 7 ---- phpBB/includes/avatar/manager.php | 29 ++++++++++++++--- phpBB/includes/ucp/ucp_groups.php | 33 +++++++++---------- phpBB/includes/ucp/ucp_profile.php | 35 ++++++++++---------- 8 files changed, 90 insertions(+), 98 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 95da62dedf..c3bdf89866 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -108,7 +108,7 @@ class acp_board case 'avatar': $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(true); sort($avatar_drivers); $avatar_vars = array(); foreach ($avatar_drivers as $driver) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 19006df306..a15a1b9a78 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -528,27 +528,24 @@ class acp_groups { $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->is_enabled()) + $avatars_enabled = true; + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $template->set_filenames(array( + 'avatar' => "acp_avatar_options_$config_name.html", + )); + + if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { - $avatars_enabled = true; - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $template->set_filenames(array( - 'avatar' => "acp_avatar_options_$config_name.html", + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_upper = strtoupper($driver_name); + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), + + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, + 'OUTPUT' => $template->assign_display('avatar'), )); - - if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) - { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); - $driver_upper = strtoupper($driver_name); - $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - - 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, - 'OUTPUT' => $template->assign_display('avatar'), - )); - } } } } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index e0dcea6d58..d5532e35b6 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1809,28 +1809,25 @@ class acp_users { $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->is_enabled()) + $avatars_enabled = true; + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $template->set_filenames(array( + 'avatar' => "acp_avatar_options_$config_name.html", + )); + + if ($avatar->prepare_form($template, $avatar_data, $error)) { - $avatars_enabled = true; - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $template->set_filenames(array( - 'avatar' => "acp_avatar_options_$config_name.html", + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_upper = strtoupper($driver_name); + + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), + + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, + 'OUTPUT' => $template->assign_display('avatar'), )); - - if ($avatar->prepare_form($template, $avatar_data, $error)) - { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); - $driver_upper = strtoupper($driver_name); - - $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - - 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, - 'OUTPUT' => $template->assign_display('avatar'), - )); - } } } } diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 6710f1f153..cde4fd95a6 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -127,16 +127,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface return true; } - /** - * @inheritdoc - */ - public function is_enabled() - { - $driver = preg_replace('#^phpbb_avatar_driver_#', '', get_class($this)); - - return $this->config["allow_avatar_$driver"]; - } - /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index d2f25a989f..7a58a40b0c 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -91,13 +91,6 @@ interface phpbb_avatar_driver_interface */ public function delete($row); - /** - * Check if avatar is enabled - * - * @return bool True if avatar is enabled, false if it's disabled - */ - public function is_enabled(); - /** * Get the avatars template name * diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index ae628f0ce2..8953557acb 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -101,15 +101,20 @@ class phpbb_avatar_manager /** * Load the list of valid drivers * This is executed once and fills self::$valid_drivers + * + * @param bool $force_all Force showing all avatar drivers */ - protected function load_valid_drivers() + protected function load_valid_drivers($force_all = false) { if (!empty($this->avatar_drivers)) { self::$valid_drivers = array(); foreach ($this->avatar_drivers as $driver) { - self::$valid_drivers[$driver->get_name()] = $driver->get_name(); + if ($force_all || $this->is_enabled($driver)) + { + self::$valid_drivers[$driver->get_name()] = $driver->get_name(); + } } } } @@ -117,13 +122,15 @@ class phpbb_avatar_manager /** * Get a list of valid avatar drivers * + * @param bool $force_all Force showing all avatar drivers + * * @return array Array containing a list of the valid avatar drivers */ - public function get_valid_drivers() + public function get_valid_drivers($force_all = false) { if (self::$valid_drivers === false) { - $this->load_valid_drivers(); + $this->load_valid_drivers($force_all); } return self::$valid_drivers; @@ -178,4 +185,18 @@ class phpbb_avatar_manager { return str_replace('.', '_', $name); } + + /** + * Check if avatar is enabled + * + * @param object $driver Avatar driver object + * + * @return bool True if avatar is enabled, false if it's disabled + */ + public function is_enabled($driver) + { + $config_name = preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + + return $this->config["allow_avatar_{$config_name}"]; + } } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 3860d22917..f17e535b0c 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -653,26 +653,23 @@ class ucp_groups { $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->is_enabled()) + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => $avatar->get_template_name(), + )); + + if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { - $avatars_enabled = true; - $template->set_filenames(array( - 'avatar' => $avatar->get_template_name(), + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_upper = strtoupper($driver_name); + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), + + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, + 'OUTPUT' => $template->assign_display('avatar'), )); - - if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) - { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); - $driver_upper = strtoupper($driver_name); - $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - - 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, - 'OUTPUT' => $template->assign_display('avatar'), - )); - } } } } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index c8547e48d8..f5c04bb432 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -633,27 +633,24 @@ class ucp_profile { $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->is_enabled()) + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => $avatar->get_template_name(), + )); + + if ($avatar->prepare_form($template, $avatar_data, $error)) { - $avatars_enabled = true; - $template->set_filenames(array( - 'avatar' => $avatar->get_template_name(), + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_upper = strtoupper($driver_name); + + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), + + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, + 'OUTPUT' => $template->assign_display('avatar'), )); - - if ($avatar->prepare_form($template, $avatar_data, $error)) - { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); - $driver_upper = strtoupper($driver_name); - - $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - - 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, - 'OUTPUT' => $template->assign_display('avatar'), - )); - } } } } From 562ebe5c12b8a238b94a63ba53b694af4d061bc9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 14:36:18 +0100 Subject: [PATCH 088/138] [feature/avatars] Unify size of avatar_type Previously it was set to 255 in one file while it was 32 in other files. As the size of 32 is rather low this was increased to 255. PHPBB3-10018 --- phpBB/develop/create_schema_files.php | 4 ++-- phpBB/install/schemas/firebird_schema.sql | 4 ++-- phpBB/install/schemas/mssql_schema.sql | 4 ++-- phpBB/install/schemas/mysql_40_schema.sql | 4 ++-- phpBB/install/schemas/mysql_41_schema.sql | 4 ++-- phpBB/install/schemas/oracle_schema.sql | 4 ++-- phpBB/install/schemas/postgres_schema.sql | 4 ++-- phpBB/install/schemas/sqlite_schema.sql | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 1d03a5b06e..895a945e4e 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1168,7 +1168,7 @@ function get_schema_struct() 'group_desc_uid' => array('VCHAR:8', ''), 'group_display' => array('BOOL', 0), 'group_avatar' => array('VCHAR', ''), - 'group_avatar_type' => array('VCHAR:32', ''), + 'group_avatar_type' => array('VCHAR:255', ''), 'group_avatar_width' => array('USINT', 0), 'group_avatar_height' => array('USINT', 0), 'group_rank' => array('UINT', 0), @@ -1823,7 +1823,7 @@ function get_schema_struct() 'user_allow_massemail' => array('BOOL', 1), 'user_options' => array('UINT:11', 230271), 'user_avatar' => array('VCHAR', ''), - 'user_avatar_type' => array('VCHAR:32', ''), + 'user_avatar_type' => array('VCHAR:255', ''), 'user_avatar_width' => array('USINT', 0), 'user_avatar_height' => array('USINT', 0), 'user_sig' => array('MTEXT_UNI', ''), diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index 45ab3af337..d830f0db77 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -445,7 +445,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL, group_display INTEGER DEFAULT 0 NOT NULL, group_avatar VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - group_avatar_type VARCHAR(32) CHARACTER SET NONE DEFAULT '' NOT NULL, + group_avatar_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, group_avatar_width INTEGER DEFAULT 0 NOT NULL, group_avatar_height INTEGER DEFAULT 0 NOT NULL, group_rank INTEGER DEFAULT 0 NOT NULL, @@ -1271,7 +1271,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INTEGER DEFAULT 1 NOT NULL, user_options INTEGER DEFAULT 230271 NOT NULL, user_avatar VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - user_avatar_type VARCHAR(32) CHARACTER SET NONE DEFAULT '' NOT NULL, + user_avatar_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, user_avatar_width INTEGER DEFAULT 0 NOT NULL, user_avatar_height INTEGER DEFAULT 0 NOT NULL, user_sig BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 1925935dc4..d2dd1c1d60 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -553,7 +553,7 @@ CREATE TABLE [phpbb_groups] ( [group_desc_uid] [varchar] (8) DEFAULT ('') NOT NULL , [group_display] [int] DEFAULT (0) NOT NULL , [group_avatar] [varchar] (255) DEFAULT ('') NOT NULL , - [group_avatar_type] [varchar] (32) DEFAULT ('') NOT NULL , + [group_avatar_type] [varchar] (255) DEFAULT ('') NOT NULL , [group_avatar_width] [int] DEFAULT (0) NOT NULL , [group_avatar_height] [int] DEFAULT (0) NOT NULL , [group_rank] [int] DEFAULT (0) NOT NULL , @@ -1555,7 +1555,7 @@ CREATE TABLE [phpbb_users] ( [user_allow_massemail] [int] DEFAULT (1) NOT NULL , [user_options] [int] DEFAULT (230271) NOT NULL , [user_avatar] [varchar] (255) DEFAULT ('') NOT NULL , - [user_avatar_type] [varchar] (32) DEFAULT ('') NOT NULL , + [user_avatar_type] [varchar] (255) DEFAULT ('') NOT NULL , [user_avatar_width] [int] DEFAULT (0) NOT NULL , [user_avatar_height] [int] DEFAULT (0) NOT NULL , [user_sig] [text] DEFAULT ('') NOT NULL , diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 6634615e9f..dfaf3b28e2 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -317,7 +317,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varbinary(8) DEFAULT '' NOT NULL, group_display tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_avatar varbinary(255) DEFAULT '' NOT NULL, - group_avatar_type varbinary(32) DEFAULT '' NOT NULL, + group_avatar_type varbinary(255) DEFAULT '' NOT NULL, group_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -919,7 +919,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, user_options int(11) UNSIGNED DEFAULT '230271' NOT NULL, user_avatar varbinary(255) DEFAULT '' NOT NULL, - user_avatar_type varbinary(32) DEFAULT '' NOT NULL, + user_avatar_type varbinary(255) DEFAULT '' NOT NULL, user_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_sig mediumblob NOT NULL, diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 7823c91fb8..5c27538f86 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -317,7 +317,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) DEFAULT '' NOT NULL, group_display tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_avatar varchar(255) DEFAULT '' NOT NULL, - group_avatar_type varchar(32) DEFAULT '' NOT NULL, + group_avatar_type varchar(255) DEFAULT '' NOT NULL, group_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -919,7 +919,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, user_options int(11) UNSIGNED DEFAULT '230271' NOT NULL, user_avatar varchar(255) DEFAULT '' NOT NULL, - user_avatar_type varchar(32) DEFAULT '' NOT NULL, + user_avatar_type varchar(255) DEFAULT '' NOT NULL, user_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_sig mediumtext NOT NULL, diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 78592decd5..718dd02601 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -610,7 +610,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar2(8) DEFAULT '' , group_display number(1) DEFAULT '0' NOT NULL, group_avatar varchar2(255) DEFAULT '' , - group_avatar_type varchar2(32) DEFAULT '' , + group_avatar_type varchar2(255) DEFAULT '' , group_avatar_width number(4) DEFAULT '0' NOT NULL, group_avatar_height number(4) DEFAULT '0' NOT NULL, group_rank number(8) DEFAULT '0' NOT NULL, @@ -1667,7 +1667,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail number(1) DEFAULT '1' NOT NULL, user_options number(11) DEFAULT '230271' NOT NULL, user_avatar varchar2(255) DEFAULT '' , - user_avatar_type varchar2(32) DEFAULT '' , + user_avatar_type varchar2(255) DEFAULT '' , user_avatar_width number(4) DEFAULT '0' NOT NULL, user_avatar_height number(4) DEFAULT '0' NOT NULL, user_sig clob DEFAULT '' , diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index f85cee4277..3d4d01484e 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -463,7 +463,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) DEFAULT '' NOT NULL, group_display INT2 DEFAULT '0' NOT NULL CHECK (group_display >= 0), group_avatar varchar(255) DEFAULT '' NOT NULL, - group_avatar_type varchar(32) DEFAULT '' NOT NULL, + group_avatar_type varchar(255) DEFAULT '' NOT NULL, group_avatar_width INT2 DEFAULT '0' NOT NULL CHECK (group_avatar_width >= 0), group_avatar_height INT2 DEFAULT '0' NOT NULL CHECK (group_avatar_height >= 0), group_rank INT4 DEFAULT '0' NOT NULL CHECK (group_rank >= 0), @@ -1169,7 +1169,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INT2 DEFAULT '1' NOT NULL CHECK (user_allow_massemail >= 0), user_options INT4 DEFAULT '230271' NOT NULL CHECK (user_options >= 0), user_avatar varchar(255) DEFAULT '' NOT NULL, - user_avatar_type varchar(32) DEFAULT '' NOT NULL, + user_avatar_type varchar(255) DEFAULT '' NOT NULL, user_avatar_width INT2 DEFAULT '0' NOT NULL CHECK (user_avatar_width >= 0), user_avatar_height INT2 DEFAULT '0' NOT NULL CHECK (user_avatar_height >= 0), user_sig TEXT DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index 900ed06bfe..8f488416ce 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -309,7 +309,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) NOT NULL DEFAULT '', group_display INTEGER UNSIGNED NOT NULL DEFAULT '0', group_avatar varchar(255) NOT NULL DEFAULT '', - group_avatar_type varchar(32) NOT NULL DEFAULT '', + group_avatar_type varchar(255) NOT NULL DEFAULT '', group_avatar_width INTEGER UNSIGNED NOT NULL DEFAULT '0', group_avatar_height INTEGER UNSIGNED NOT NULL DEFAULT '0', group_rank INTEGER UNSIGNED NOT NULL DEFAULT '0', @@ -893,7 +893,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INTEGER UNSIGNED NOT NULL DEFAULT '1', user_options INTEGER UNSIGNED NOT NULL DEFAULT '230271', user_avatar varchar(255) NOT NULL DEFAULT '', - user_avatar_type varchar(32) NOT NULL DEFAULT '', + user_avatar_type varchar(255) NOT NULL DEFAULT '', user_avatar_width INTEGER UNSIGNED NOT NULL DEFAULT '0', user_avatar_height INTEGER UNSIGNED NOT NULL DEFAULT '0', user_sig mediumtext(16777215) NOT NULL DEFAULT '', From d5cbedaaa28312c107ec562c78ffaa034595f336 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 15:12:34 +0100 Subject: [PATCH 089/138] [feature/avatars] Let avatar manager handle $ignore_config The avatar manager already handles if avatars are enabled. It should also handle ignoring the config settings. PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/avatar/driver/driver.php | 4 ++-- phpBB/includes/avatar/driver/gravatar.php | 25 ++++++---------------- phpBB/includes/avatar/driver/interface.php | 16 ++++++-------- phpBB/includes/avatar/driver/local.php | 23 ++++++-------------- phpBB/includes/avatar/driver/remote.php | 23 ++++++-------------- phpBB/includes/avatar/manager.php | 9 ++++---- phpBB/includes/functions_display.php | 2 +- 8 files changed, 35 insertions(+), 69 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index a15a1b9a78..75956736f7 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -351,7 +351,7 @@ class acp_groups } else { - $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']) + $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); if ($avatar) { $avatar->delete($avatar_data); diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index cde4fd95a6..317fe91b83 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -78,7 +78,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc */ - public function get_data($row, $ignore_config = false) + public function get_data($row) { return array( 'src' => '', @@ -90,7 +90,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc */ - public function get_custom_html($row, $ignore_config = false, $alt = '') + public function get_custom_html($row, $alt = '') { return ''; } diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 6ceac1a149..001a741c3f 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -29,30 +29,19 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * @inheritdoc */ - public function get_data($row, $ignore_config = false) + public function get_data($row) { - if ($ignore_config || $this->config['allow_avatar_gravatar']) - { - return array( - 'src' => $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } + return array( + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); } /** * @inheritdoc */ - public function get_custom_html($row, $ignore_config = false, $alt = '') + public function get_custom_html($row, $alt = '') { return ' '', 'width' => 0, 'height' => 0] + * ['src' => '', 'width' => 0, 'height' => 0] */ - public function get_data($row, $ignore_config = false); + public function get_data($row); /** * Returns custom html if it is needed for displaying this avatar * - * @param bool $ignore_config Whether this function should respect the users prefs - * and board configuration configuration option, or should just render - * the avatar anyways. Useful for the ACP. + * @param string $alt Alternate text for avatar image + * * @return string HTML */ - public function get_custom_html($row, $ignore_config = false, $alt = ''); + public function get_custom_html($row, $alt = ''); /** * Prepare form for changing the settings of this avatar diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index d46ac79d11..479ee3712a 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -24,24 +24,13 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function get_data($row, $ignore_config = false) + public function get_data($row) { - if ($ignore_config || $this->config['allow_avatar_local']) - { - return array( - 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } + return array( + 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); } /** diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 1da5fc16e8..344275a251 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -24,24 +24,13 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function get_data($row, $ignore_config = false) + public function get_data($row) { - if ($ignore_config || $this->config['allow_avatar_remote']) - { - return array( - 'src' => $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } + return array( + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); } /** diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 8953557acb..a0e1070322 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -54,15 +54,16 @@ class phpbb_avatar_manager /** * Get the driver object specified by the avatar type * - * @param string Avatar type; by default an avatar's service container name + * @param string $avatar_type Avatar type; by default an avatar's service container name + * @param bool $force_all Grab all avatar drivers, no matter if enabled or not * * @return object Avatar driver object */ - public function get_driver($avatar_type) + public function get_driver($avatar_type, $force_all = false) { - if (self::$valid_drivers === false) + if (self::$valid_drivers === false || $force_all) { - $this->load_valid_drivers(); + $this->load_valid_drivers($force_all); } // Legacy stuff... diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index a7b28acac1..f88d8c9054 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1367,7 +1367,7 @@ function get_avatar($row, $alt, $ignore_config = false) ); $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); + $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config); $html = ''; if ($avatar) From 33b98dc5ba0b690fdae72acfd676dae5a897cb6a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 16:46:11 +0100 Subject: [PATCH 090/138] [feature/avatars] Fix variable names PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/acp/acp_groups.php | 24 +++++++++----------- phpBB/includes/acp/acp_users.php | 34 +++++++++++++--------------- phpBB/includes/avatar/manager.php | 1 + phpBB/includes/functions_display.php | 8 +++---- phpBB/includes/ucp/ucp_groups.php | 31 ++++++++++++------------- phpBB/includes/ucp/ucp_profile.php | 30 ++++++++++++------------ 7 files changed, 62 insertions(+), 68 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index c3bdf89866..0467cc7c35 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -109,7 +109,7 @@ class acp_board case 'avatar': $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(true); - sort($avatar_drivers); + $avatar_vars = array(); foreach ($avatar_drivers as $driver) { diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 75956736f7..23f6d775ef 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -282,7 +282,6 @@ class acp_groups $user->add_lang('ucp'); // Setup avatar data for later - $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; $avatar_drivers = null; $avatar_data = null; @@ -290,8 +289,8 @@ class acp_groups if ($config['allow_avatar']) { + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); - sort($avatar_drivers); // This is normalised data, without the group_ prefix $avatar_data = phpbb_avatar_manager::clean_row($group_row); @@ -334,27 +333,26 @@ class acp_groups if ($config['allow_avatar']) { // Handle avatar - $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) + if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { - $avatar = $phpbb_avatar_manager->get_driver($driver); - $result = $avatar->process_form($template, $avatar_data, $avatar_error); + $driver = $phpbb_avatar_manager->get_driver($driver_name); + $result = $driver->process_form($template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { - $result['avatar_type'] = $driver; + $result['avatar_type'] = $driver_name; $submit_ary = array_merge($submit_ary, $result); } } else { - $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); - if ($avatar) + $driver = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); + if ($driver) { - $avatar->delete($avatar_data); + $driver->delete($avatar_data); } // Removing the avatar @@ -526,7 +524,7 @@ class acp_groups foreach ($avatar_drivers as $driver) { - $avatar = $phpbb_avatar_manager->get_driver($driver); + $driver = $phpbb_avatar_manager->get_driver($driver); $avatars_enabled = true; $config_name = preg_replace('#^avatar\.driver.#', '', $driver); @@ -534,7 +532,7 @@ class acp_groups 'avatar' => "acp_avatar_options_$config_name.html", )); - if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) + if ($driver->prepare_form($template, $avatar_data, $avatar_error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); $driver_upper = strtoupper($driver_name); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index d5532e35b6..3df373a7d4 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1733,12 +1733,11 @@ class acp_users include($phpbb_root_path . 'includes/functions_display.' . $phpEx); $avatars_enabled = false; - $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); if ($config['allow_avatar']) { + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); - sort($avatar_drivers); // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_manager::clean_row($user_row); @@ -1747,19 +1746,18 @@ class acp_users { if (check_form_key($form_name)) { - $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) + if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { - $avatar = $phpbb_avatar_manager->get_driver($driver); - $result = $avatar->process_form($template, $avatar_data, $error); + $driver = $phpbb_avatar_manager->get_driver($driver_name); + $result = $driver->process_form($template, $avatar_data, $error); if ($result && empty($error)) { // Success! Lets save the result in the database $result = array( - 'user_avatar_type' => $driver, + 'user_avatar_type' => $driver_name, 'user_avatar' => $result['avatar'], 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height'], @@ -1775,10 +1773,10 @@ class acp_users } else { - $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); - if ($avatar) + $driver = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); + if ($driver) { - $avatar->delete($avatar_data); + $driver->delete($avatar_data); } // Removing the avatar @@ -1805,19 +1803,19 @@ class acp_users $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type'])); - foreach ($avatar_drivers as $driver) + foreach ($avatar_drivers as $current_driver) { - $avatar = $phpbb_avatar_manager->get_driver($driver); + $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $current_driver); $template->set_filenames(array( 'avatar' => "acp_avatar_options_$config_name.html", )); - if ($avatar->prepare_form($template, $avatar_data, $error)) + if ($driver->prepare_form($template, $avatar_data, $error)) { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( @@ -1825,7 +1823,7 @@ class acp_users 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, + 'SELECTED' => $current_driver == $focused_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } @@ -1842,7 +1840,7 @@ class acp_users } else { - $error[$key] = $user->lang("$lang"); + $error[$key] = $user->lang($lang); } } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index a0e1070322..176d0d659d 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -117,6 +117,7 @@ class phpbb_avatar_manager self::$valid_drivers[$driver->get_name()] = $driver->get_name(); } } + asort(self::$valid_drivers); } } diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index f88d8c9054..6b267bc901 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1367,18 +1367,18 @@ function get_avatar($row, $alt, $ignore_config = false) ); $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config); + $driver = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config); $html = ''; - if ($avatar) + if ($driver) { - $html = $avatar->get_custom_html($row, $ignore_config, $alt); + $html = $driver->get_custom_html($row, $ignore_config, $alt); if (!empty($html)) { return $html; } - $avatar_data = $avatar->get_data($row, $ignore_config); + $avatar_data = $driver->get_data($row, $ignore_config); } else { diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index f17e535b0c..c1ddaccb75 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -484,7 +484,6 @@ class ucp_groups $error = array(); // Setup avatar data for later - $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; $avatar_drivers = null; $avatar_data = null; @@ -492,8 +491,8 @@ class ucp_groups if ($config['allow_avatar']) { + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); - sort($avatar_drivers); // This is normalised data, without the group_ prefix $avatar_data = phpbb_avatar_manager::clean_row($group_row); @@ -521,26 +520,26 @@ class ucp_groups if ($config['allow_avatar']) { // Handle avatar - $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver_name); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) + if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { - $avatar = $phpbb_avatar_manager->get_driver($driver); - $result = $avatar->process_form($template, $avatar_data, $avatar_error); + $driver = $phpbb_avatar_manager->get_driver($driver_name); + $result = $driver->process_form($template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { - $result['avatar_type'] = $driver; + $result['avatar_type'] = $driver_name; $submit_ary = array_merge($submit_ary, $result); } } else { - if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + if ($driver = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) { - $avatar->delete($avatar_data); + $driver->delete($avatar_data); } // Removing the avatar @@ -649,25 +648,25 @@ class ucp_groups $avatars_enabled = false; $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); - foreach ($avatar_drivers as $driver) + foreach ($avatar_drivers as $current_driver) { - $avatar = $phpbb_avatar_manager->get_driver($driver); + $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; $template->set_filenames(array( - 'avatar' => $avatar->get_template_name(), + 'avatar' => $driver->get_template_name(), )); - if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) + if ($driver->prepare_form($template, $avatar_data, $avatar_error)) { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, + 'SELECTED' => $current_driver == $focused_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index f5c04bb432..71a4d4e67b 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -552,13 +552,12 @@ class ucp_profile add_form_key('ucp_avatar'); - $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); - sort($avatar_drivers); // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_manager::clean_row($user->data); @@ -567,19 +566,18 @@ class ucp_profile { if (check_form_key('ucp_avatar')) { - $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) + if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { - $avatar = $phpbb_avatar_manager->get_driver($driver); - $result = $avatar->process_form($template, $avatar_data, $error); + $driver = $phpbb_avatar_manager->get_driver($driver_name); + $result = $driver->process_form($template, $avatar_data, $error); if ($result && empty($error)) { // Success! Lets save the result in the database $result = array( - 'user_avatar_type' => $driver, + 'user_avatar_type' => $driver_name, 'user_avatar' => $result['avatar'], 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height'], @@ -598,9 +596,9 @@ class ucp_profile } else { - if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + if ($driver = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) { - $avatar->delete($avatar_data); + $driver->delete($avatar_data); } $result = array( @@ -629,18 +627,18 @@ class ucp_profile $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type'])); - foreach ($avatar_drivers as $driver) + foreach ($avatar_drivers as $current_driver) { - $avatar = $phpbb_avatar_manager->get_driver($driver); + $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; $template->set_filenames(array( - 'avatar' => $avatar->get_template_name(), + 'avatar' => $driver->get_template_name(), )); - if ($avatar->prepare_form($template, $avatar_data, $error)) + if ($driver->prepare_form($template, $avatar_data, $error)) { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( @@ -648,7 +646,7 @@ class ucp_profile 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, + 'SELECTED' => $current_driver == $focused_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } From 081440f6c4bd6b7c2838dd0587ed6a4dffc87d52 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 23:11:44 +0100 Subject: [PATCH 091/138] [feature/avatars] Create setting for enabling avatar in manager PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 13 ++++++++--- phpBB/includes/avatar/driver/driver.php | 28 ----------------------- phpBB/includes/avatar/driver/gravatar.php | 10 -------- phpBB/includes/avatar/driver/local.php | 1 - phpBB/includes/avatar/driver/remote.php | 10 -------- phpBB/includes/avatar/driver/upload.php | 22 ++++-------------- phpBB/includes/avatar/manager.php | 16 +++++++++++++ 7 files changed, 31 insertions(+), 69 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 0467cc7c35..bb90918a46 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -111,10 +111,17 @@ class acp_board $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(true); $avatar_vars = array(); - foreach ($avatar_drivers as $driver) + foreach ($avatar_drivers as $current_driver) { - $avatar = $phpbb_avatar_manager->get_driver($driver); - $avatar_vars += $avatar->prepare_form_acp(); + $driver = $phpbb_avatar_manager->get_driver($current_driver); + + /* + * First grab the settings for enabling/disabling the avatar + * driver and afterwards grab additional settings the driver + * might have. + */ + $avatar_vars += $phpbb_avatar_manager->get_avatar_settings($driver); + $avatar_vars += $driver->prepare_form_acp(); } $display_vars = array( diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 317fe91b83..ab89cfbffe 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -75,18 +75,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface $this->cache = $cache; } - /** - * @inheritdoc - */ - public function get_data($row) - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - /** * @inheritdoc */ @@ -95,14 +83,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface return ''; } - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - return false; - } - /** * @inheritdoc */ @@ -111,14 +91,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface return array(); } - /** - * @inheritdoc - */ - public function process_form($template, $row, &$error) - { - return false; - } - /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 001a741c3f..8fa95bf937 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -63,16 +63,6 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver return true; } - /** - * @inheritdoc - */ - public function prepare_form_acp() - { - return array( - 'allow_avatar_gravatar' => array('lang' => 'ALLOW_GRAVATAR', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), - ); - } - /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 479ee3712a..4593161a76 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -107,7 +107,6 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function prepare_form_acp() { return array( - 'allow_avatar_local' => array('lang' => 'ALLOW_LOCAL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'avatar_gallery_path' => array('lang' => 'AVATAR_GALLERY_PATH', 'validate' => 'rpath', 'type' => 'text:20:255', 'explain' => true), ); } diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 344275a251..e96cb35684 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -47,16 +47,6 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver return true; } - /** - * @inheritdoc - */ - public function prepare_form_acp() - { - return array( - 'allow_avatar_remote' => array('lang' => 'ALLOW_REMOTE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - ); - } - /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 497dd8ad19..38627baacf 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -26,22 +26,11 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver */ public function get_data($row, $ignore_config = false) { - if ($ignore_config || $this->config['allow_avatar_upload']) - { - return array( - 'src' => $this->phpbb_root_path . 'download/file' . $this->php_ext . '?avatar=' . $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } + return array( + 'src' => $this->phpbb_root_path . 'download/file' . $this->php_ext . '?avatar=' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); } /** @@ -133,7 +122,6 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver global $user; return array( - 'allow_avatar_upload' => array('lang' => 'ALLOW_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), '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' => 'text:4:10', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), 'avatar_path' => array('lang' => 'AVATAR_STORAGE_PATH', 'validate' => 'rwpath', 'type' => 'text:20:255', 'explain' => true), diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 176d0d659d..267ba24dc8 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -201,4 +201,20 @@ class phpbb_avatar_manager return $this->config["allow_avatar_{$config_name}"]; } + + /** + * Get the settings array for enabling/disabling an avatar driver + * + * @param string $driver Avatar driver object + * + * @return array Array of configuration options as consumed by acp_board + */ + public function get_avatar_settings($driver) + { + $config_name = preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + + return array( + 'allow_avatar_' . $config_name => array('lang' => 'ALLOW_' . strtoupper($config_name), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + ); + } } From d439f477105903ceb29652f23bcb7812d0f34d4d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 1 Dec 2012 00:27:52 +0100 Subject: [PATCH 092/138] [feature/avatars] Fix docblocks and minor cosmetic issues PHPBB3-10018 --- phpBB/includes/avatar/driver/gravatar.php | 2 +- phpBB/includes/avatar/driver/interface.php | 27 ++++++++++++++-------- phpBB/includes/avatar/driver/local.php | 2 +- phpBB/includes/avatar/driver/remote.php | 2 +- phpBB/includes/avatar/manager.php | 13 ++++------- phpBB/includes/ucp/ucp_profile.php | 2 +- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 8fa95bf937..11996ca561 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -72,7 +72,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver $row['avatar_width'] = $this->request->variable('avatar_gravatar_width', 0); $row['avatar_height'] = $this->request->variable('avatar_gravatar_height', 0); - if (!function_exists('user_add')) + if (!function_exists('validate_data')) { require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index bba4bd102e..e8f529f3c4 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -24,7 +24,7 @@ interface phpbb_avatar_driver_interface /** * Returns the name of the driver. * - * @return string Name of wrapped driver. + * @return string Name of driver. */ public function get_name(); @@ -50,10 +50,13 @@ interface phpbb_avatar_driver_interface /** * Prepare form for changing the settings of this avatar * - * @param object $template Template object + * @param phpbb_template $template Template object * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row - * @param array &$error Reference to an error array + * @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 + * the first array key. * * @return bool True if form has been successfully prepared */ @@ -62,17 +65,22 @@ interface phpbb_avatar_driver_interface /** * Prepare form for changing the acp settings of this avatar * - * @return array Array containing the acp settings + * @return array Array of configuration options as consumed by acp_board. + * The setting for enabling/disabling the avatar will be handled by + * the avatar manager. */ public function prepare_form_acp(); /** * Process form data * - * @param object $template Template object + * @param phpbb_template $template Template object * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row - * @param array &$error Reference to an error array + * @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 + * the first array key. * * @return array Array containing the avatar data as follows: * ['avatar'], ['avatar_width'], ['avatar_height'] @@ -85,14 +93,15 @@ interface phpbb_avatar_driver_interface * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row * - * @return bool True if avatar has been deleted or there is no need to delete + * @return bool True if avatar has been deleted or there is no need to delete, + * i.e. when the avatar is not hosted locally. */ public function delete($row); /** - * Get the avatars template name + * Get the avatar driver's template name * - * @return string Avatar's template name + * @return string Avatar driver's template name */ public function get_template_name(); } diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 4593161a76..d7611b903a 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -174,7 +174,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver ); } } - @ksort($avatar_list); + ksort($avatar_list); if ($this->cache != null) { diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index e96cb35684..9135a62eac 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -61,7 +61,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver $url = 'http://' . $url; } - if (!function_exists('user_add')) + if (!function_exists('validate_data')) { require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 267ba24dc8..409d0d4eea 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -85,16 +85,11 @@ class phpbb_avatar_manager return null; } + /* + * 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); - if ($driver !== false) - { - return $driver; - } - else - { - $message = "Invalid avatar driver class name '%s' provided."; - trigger_error(sprintf($message, $avatar_type)); - } return $driver; } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 71a4d4e67b..ecd828c6dc 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -545,7 +545,7 @@ class ucp_profile break; case 'avatar': - if (!function_exists('display_forums')) + if (!function_exists('get_user_avatar')) { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } From 215ac6a0daa51881dc6abb987baf10e682fc9972 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 1 Dec 2012 21:28:44 +0100 Subject: [PATCH 093/138] [feature/avatars] Removed unneeded dependencies PHPBB3-10018 --- phpBB/config/services.yml | 4 ---- phpBB/includes/avatar/manager.php | 10 +--------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 3d33731eea..6649b36ae6 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -17,11 +17,7 @@ services: avatar.manager: class: phpbb_avatar_manager arguments: - - %core.root_path% - - .%core.php_ext% - @config - - @request - - @cache.driver - @avatar.driver_collection - @service_container diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 409d0d4eea..e7ee323624 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -20,11 +20,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_avatar_manager { - protected $phpbb_root_path; - protected $phpEx; protected $config; - protected $request; - protected $cache; protected static $valid_drivers = false; protected $avatar_drivers; protected $container; @@ -40,13 +36,9 @@ class phpbb_avatar_manager * @param array $avatar_drivers Avatar drivers passed via the service container * @param object $container Container object */ - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache, $avatar_drivers, $container) + public function __construct(phpbb_config $config, $avatar_drivers, $container) { - $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; $this->config = $config; - $this->request = $request; - $this->cache = $cache; $this->avatar_drivers = $avatar_drivers; $this->container = $container; } From d771453b520938e21d52ad3464298a9cc0d0fa03 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 1 Dec 2012 21:37:57 +0100 Subject: [PATCH 094/138] [feature/avatars] Add tests for avatar manager PHPBB3-10018 --- tests/avatar/manager_test.php | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/avatar/manager_test.php diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php new file mode 100644 index 0000000000..12c88dd855 --- /dev/null +++ b/tests/avatar/manager_test.php @@ -0,0 +1,82 @@ + 'foobar', + 'user_avatar_width' => 50, + 'user_avatar_height' => 50, + ); + + protected $clean_user_row = array( + 'avatar' => 'foobar', + 'avatar_width' => 50, + 'avatar_height' => 50, + ); + + public function setUp() + { + global $phpbb_root_path, $phpEx; + + // Mock phpbb_container + $this->phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $this->phpbb_container->expects($this->any()) + ->method('get') + ->with('avatar.driver.gravatar')->will($this->returnValue('avatar_foo')); + + // Prepare dependencies for avatar manager and driver + $config = new phpbb_config(array()); + $request = $this->getMock('phpbb_request'); + $cache = $this->getMock('phpbb_cache_driver_interface'); + + // Create new avatar driver object for manager + $this->avatar_gravatar = new phpbb_avatar_driver_gravatar($config, $request, $phpbb_root_path, $phpEx, $cache); + $this->avatar_gravatar->set_name('avatar.driver.gravatar'); + $avatar_drivers = array($this->avatar_gravatar); + + // Set up avatar manager + $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); + } + + public function test_get_driver() + { + $driver = $this->manager->get_driver('avatar.driver.gravatar', true); + $this->assertEquals('avatar_foo', $driver); + + $driver = $this->manager->get_driver('avatar.driver.foo', true); + $this->assertNull($driver); + } + + public function test_get_valid_drivers() + { + $valid_drivers = $this->manager->get_valid_drivers(true); + $this->assertArrayHasKey('avatar.driver.gravatar', $valid_drivers); + $this->assertEquals('avatar.driver.gravatar', $valid_drivers['avatar.driver.gravatar']); + } + + public function test_get_avatar_settings() + { + $avatar_settings = $this->manager->get_avatar_settings($this->avatar_gravatar); + + $expected_settings = array( + 'allow_avatar_gravatar' => array('lang' => 'ALLOW_GRAVATAR', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + ); + + $this->assertEquals($expected_settings, $avatar_settings); + } +} From 232fa5b5884d97329b2bf5c79907dfa0128b618b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 2 Dec 2012 01:19:10 +0100 Subject: [PATCH 095/138] [feature/avatars] Do not use gravatar avatar in tests PHPBB3-10018 --- tests/avatar/driver/foobar.php | 19 +++++++++++++ tests/avatar/manager_test.php | 49 +++++++++++----------------------- 2 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 tests/avatar/driver/foobar.php diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php new file mode 100644 index 0000000000..fe4d47d923 --- /dev/null +++ b/tests/avatar/driver/foobar.php @@ -0,0 +1,19 @@ + 'foobar', - 'user_avatar_width' => 50, - 'user_avatar_height' => 50, - ); - - protected $clean_user_row = array( - 'avatar' => 'foobar', - 'avatar_width' => 50, - 'avatar_height' => 50, - ); - public function setUp() { global $phpbb_root_path, $phpEx; @@ -37,17 +20,17 @@ class phpbb_avatar_test extends PHPUnit_Framework_TestCase $this->phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $this->phpbb_container->expects($this->any()) ->method('get') - ->with('avatar.driver.gravatar')->will($this->returnValue('avatar_foo')); + ->with('avatar.driver.foobar')->will($this->returnValue('avatar.driver.foobar')); // Prepare dependencies for avatar manager and driver $config = new phpbb_config(array()); $request = $this->getMock('phpbb_request'); $cache = $this->getMock('phpbb_cache_driver_interface'); - - // Create new avatar driver object for manager - $this->avatar_gravatar = new phpbb_avatar_driver_gravatar($config, $request, $phpbb_root_path, $phpEx, $cache); - $this->avatar_gravatar->set_name('avatar.driver.gravatar'); - $avatar_drivers = array($this->avatar_gravatar); + $this->avatar_foobar = $this->getMock('phpbb_avatar_driver_foobar', array('get_name'), array($config, $request, $phpbb_root_path, $phpEx, $cache)); + $this->avatar_foobar->expects($this->any()) + ->method('get_name') + ->will($this->returnValue('avatar.driver.foobar')); + $avatar_drivers = array($this->avatar_foobar); // Set up avatar manager $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); @@ -55,26 +38,26 @@ class phpbb_avatar_test extends PHPUnit_Framework_TestCase public function test_get_driver() { - $driver = $this->manager->get_driver('avatar.driver.gravatar', true); - $this->assertEquals('avatar_foo', $driver); + $driver = $this->manager->get_driver('avatar.driver.foobar', true); + $this->assertEquals('avatar.driver.foobar', $driver); - $driver = $this->manager->get_driver('avatar.driver.foo', true); + $driver = $this->manager->get_driver('avatar.driver.foo_wrong', true); $this->assertNull($driver); } public function test_get_valid_drivers() { $valid_drivers = $this->manager->get_valid_drivers(true); - $this->assertArrayHasKey('avatar.driver.gravatar', $valid_drivers); - $this->assertEquals('avatar.driver.gravatar', $valid_drivers['avatar.driver.gravatar']); + $this->assertArrayHasKey('avatar.driver.foobar', $valid_drivers); + $this->assertEquals('avatar.driver.foobar', $valid_drivers['avatar.driver.foobar']); } public function test_get_avatar_settings() { - $avatar_settings = $this->manager->get_avatar_settings($this->avatar_gravatar); + $avatar_settings = $this->manager->get_avatar_settings($this->avatar_foobar); $expected_settings = array( - 'allow_avatar_gravatar' => array('lang' => 'ALLOW_GRAVATAR', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + 'allow_avatar_' . get_class($this->avatar_foobar) => array('lang' => 'ALLOW_' . strtoupper(get_class($this->avatar_foobar)), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), ); $this->assertEquals($expected_settings, $avatar_settings); From ce653db49129f215c18c4d0dab24001d73ba94e6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 2 Dec 2012 01:22:42 +0100 Subject: [PATCH 096/138] [feature/avatars] Remove unnecessary "implements" from foobar avatar PHPBB3-10018 --- tests/avatar/driver/foobar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php index fe4d47d923..fd4e452818 100644 --- a/tests/avatar/driver/foobar.php +++ b/tests/avatar/driver/foobar.php @@ -1,6 +1,6 @@ Date: Tue, 4 Dec 2012 00:49:37 +0100 Subject: [PATCH 097/138] [feature/avatars] Minor variable naming fixes PHPBB3-10018 --- phpBB/adm/style/acp_users_avatar.html | 2 +- phpBB/adm/style/avatars.js | 6 +++--- phpBB/includes/acp/acp_groups.php | 4 ++-- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/ucp/ucp_groups.php | 4 ++-- phpBB/includes/ucp/ucp_profile.php | 4 ++-- phpBB/styles/prosilver/template/avatars.js | 6 +++--- phpBB/styles/subsilver2/template/avatars.js | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index bc3a19a25e..0a72bb0b62 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -32,8 +32,8 @@
-
{S_FORM_TOKEN} + diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index 882bcfe36d..a53814c15f 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -2,14 +2,14 @@ "use strict"; -function avatar_simplify() { +function avatar_hide() { $('#avatar_options > div').hide(); var selected = $('#avatar_driver').val(); $('#avatar_option_' + selected).show(); } -avatar_simplify(); -$('#avatar_driver').bind('change', avatar_simplify); +avatar_hide(); +$('#avatar_driver').bind('change', avatar_hide); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 23f6d775ef..b425b9d374 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -520,7 +520,7 @@ class acp_groups if ($config['allow_avatar']) { $avatars_enabled = false; - $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); + $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); foreach ($avatar_drivers as $driver) { @@ -541,7 +541,7 @@ class acp_groups 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, + 'SELECTED' => $driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 3df373a7d4..5c485b5996 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1801,7 +1801,7 @@ class acp_users } } - $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type'])); + $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type'])); foreach ($avatar_drivers as $current_driver) { @@ -1823,7 +1823,7 @@ class acp_users 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $current_driver == $focused_driver, + 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index c1ddaccb75..262e7b238f 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -646,7 +646,7 @@ class ucp_groups if ($config['allow_avatar']) { $avatars_enabled = false; - $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); + $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); foreach ($avatar_drivers as $current_driver) { @@ -666,7 +666,7 @@ class ucp_groups 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $current_driver == $focused_driver, + 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index ecd828c6dc..7b4dddf12b 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -625,7 +625,7 @@ class ucp_profile } } - $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type'])); + $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type'])); foreach ($avatar_drivers as $current_driver) { @@ -646,7 +646,7 @@ class ucp_profile 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $current_driver == $focused_driver, + 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index 882bcfe36d..a53814c15f 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -2,14 +2,14 @@ "use strict"; -function avatar_simplify() { +function avatar_hide() { $('#avatar_options > div').hide(); var selected = $('#avatar_driver').val(); $('#avatar_option_' + selected).show(); } -avatar_simplify(); -$('#avatar_driver').bind('change', avatar_simplify); +avatar_hide(); +$('#avatar_driver').bind('change', avatar_hide); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/subsilver2/template/avatars.js b/phpBB/styles/subsilver2/template/avatars.js index df6aad178a..733056a32d 100644 --- a/phpBB/styles/subsilver2/template/avatars.js +++ b/phpBB/styles/subsilver2/template/avatars.js @@ -2,14 +2,14 @@ "use strict"; -function avatar_simplify() { +function avatar_hide() { $('.[class^="avatar_option_"]').hide(); var selected = $('#avatar_driver').val(); $('.avatar_option_' + selected).show(); } -avatar_simplify(); -$('#avatar_driver').bind('change', avatar_simplify); +avatar_hide(); +$('#avatar_driver').bind('change', avatar_hide); })(jQuery); // Avoid conflicts with other libraries From fc4069f81df54630a5ac8c1373c38f4834553012 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Dec 2012 00:59:37 +0100 Subject: [PATCH 098/138] [feature/avatars] Use seperate function for retrieving all drivers PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/avatar/manager.php | 25 ++++++++++++++++++++++--- tests/avatar/manager_test.php | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index bb90918a46..9e63e59403 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -108,7 +108,7 @@ class acp_board case 'avatar': $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(true); + $avatar_drivers = $phpbb_avatar_manager->get_all_drivers(); $avatar_vars = array(); foreach ($avatar_drivers as $current_driver) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index e7ee323624..279278b71c 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -109,13 +109,32 @@ class phpbb_avatar_manager } /** - * Get a list of valid avatar drivers + * Get a list of all avatar drivers * - * @param bool $force_all Force showing all avatar drivers + * @return array Array containing a list of all avatar drivers + */ + public function get_all_drivers() + { + $drivers = array(); + + if (!empty($this->avatar_drivers)) + { + foreach ($this->avatar_drivers as $driver) + { + $drivers[$driver->get_name()] = $driver->get_name(); + } + asort($drivers); + } + + return $drivers; + } + + /** + * Get a list of valid avatar drivers * * @return array Array containing a list of the valid avatar drivers */ - public function get_valid_drivers($force_all = false) + public function get_valid_drivers() { if (self::$valid_drivers === false) { diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 9f28e1522d..af0a2edccc 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -47,7 +47,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase public function test_get_valid_drivers() { - $valid_drivers = $this->manager->get_valid_drivers(true); + $valid_drivers = $this->manager->get_all_drivers(); $this->assertArrayHasKey('avatar.driver.foobar', $valid_drivers); $this->assertEquals('avatar.driver.foobar', $valid_drivers['avatar.driver.foobar']); } From 8aaa3e055fdc50faeea6f590408a7bcbb03a8d92 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Dec 2012 15:11:14 +0100 Subject: [PATCH 099/138] [feature/avatars] Use seperate function for retrieving the config name PHPBB3-10018 --- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatar/manager.php | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 5c485b5996..b3cfd81949 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1808,7 +1808,7 @@ class acp_users $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; - $config_name = preg_replace('#^avatar\.driver.#', '', $current_driver); + $config_name = $phpbb_avatar_manager->get_driver_config_name($driver); $template->set_filenames(array( 'avatar' => "acp_avatar_options_$config_name.html", )); diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 279278b71c..81a135b46f 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -203,7 +203,7 @@ class phpbb_avatar_manager */ public function is_enabled($driver) { - $config_name = preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + $config_name = $this->get_driver_config_name($driver); return $this->config["allow_avatar_{$config_name}"]; } @@ -211,16 +211,28 @@ class phpbb_avatar_manager /** * Get the settings array for enabling/disabling an avatar driver * - * @param string $driver Avatar driver object + * @param object $driver Avatar driver object * * @return array Array of configuration options as consumed by acp_board */ public function get_avatar_settings($driver) { - $config_name = preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + $config_name = $this->get_driver_config_name($driver); return array( 'allow_avatar_' . $config_name => array('lang' => 'ALLOW_' . strtoupper($config_name), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), ); } + + /** + * Get the config name of an avatar driver + * + * @param object $driver Avatar driver object + * + * @return string Avatar driver config name + */ + public function get_driver_config_name($driver) + { + return preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + } } From fb139a88203fb5475712c2bc39e653996cd9103f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Dec 2012 15:12:04 +0100 Subject: [PATCH 100/138] [feature/avatars] Fix behavior of avatar manager and variables The $force_all variable was only partially removed and the behavior was not consistent in all files. PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/acp/acp_groups.php | 10 +++++----- phpBB/includes/avatar/manager.php | 20 ++++++++++---------- tests/avatar/manager_test.php | 7 +++++-- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 9e63e59403..a48d6eda83 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -113,7 +113,7 @@ class acp_board $avatar_vars = array(); foreach ($avatar_drivers as $current_driver) { - $driver = $phpbb_avatar_manager->get_driver($current_driver); + $driver = $phpbb_avatar_manager->get_driver($current_driver, false); /* * First grab the settings for enabling/disabling the avatar diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index b425b9d374..ae0abdd139 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -522,26 +522,26 @@ class acp_groups $avatars_enabled = false; $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); - foreach ($avatar_drivers as $driver) + foreach ($avatar_drivers as $current_driver) { - $driver = $phpbb_avatar_manager->get_driver($driver); + $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $config_name = $phpbb_avatar_manager->get_driver_config_name($driver); $template->set_filenames(array( 'avatar' => "acp_avatar_options_$config_name.html", )); if ($driver->prepare_form($template, $avatar_data, $avatar_error)) { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $selected_driver, + 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 81a135b46f..2789158de5 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -47,17 +47,19 @@ class phpbb_avatar_manager * Get the driver object specified by the avatar type * * @param string $avatar_type Avatar type; by default an avatar's service container name - * @param bool $force_all Grab all avatar drivers, no matter if enabled or not + * @param bool $load_valid Load only valid avatars * * @return object Avatar driver object */ - public function get_driver($avatar_type, $force_all = false) + public function get_driver($avatar_type, $load_valid = true) { - if (self::$valid_drivers === false || $force_all) + if (self::$valid_drivers === false) { - $this->load_valid_drivers($force_all); + $this->load_valid_drivers(); } + $avatar_drivers = ($load_valid) ? self::$valid_drivers : $this->get_all_drivers(); + // Legacy stuff... switch ($avatar_type) { @@ -72,7 +74,7 @@ class phpbb_avatar_manager break; } - if (!isset(self::$valid_drivers[$avatar_type])) + if (!isset($avatar_drivers[$avatar_type])) { return null; } @@ -89,17 +91,15 @@ class phpbb_avatar_manager /** * Load the list of valid drivers * This is executed once and fills self::$valid_drivers - * - * @param bool $force_all Force showing all avatar drivers */ - protected function load_valid_drivers($force_all = false) + protected function load_valid_drivers() { if (!empty($this->avatar_drivers)) { self::$valid_drivers = array(); foreach ($this->avatar_drivers as $driver) { - if ($force_all || $this->is_enabled($driver)) + if ($this->is_enabled($driver)) { self::$valid_drivers[$driver->get_name()] = $driver->get_name(); } @@ -138,7 +138,7 @@ class phpbb_avatar_manager { if (self::$valid_drivers === false) { - $this->load_valid_drivers($force_all); + $this->load_valid_drivers(); } return self::$valid_drivers; diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index af0a2edccc..cae72c982b 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -38,10 +38,13 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase public function test_get_driver() { - $driver = $this->manager->get_driver('avatar.driver.foobar', true); + $driver = $this->manager->get_driver('avatar.driver.foobar', false); $this->assertEquals('avatar.driver.foobar', $driver); - $driver = $this->manager->get_driver('avatar.driver.foo_wrong', true); + $driver = $this->manager->get_driver('avatar.driver.foo_wrong', false); + $this->assertNull($driver); + + $driver = $this->manager->get_driver('avatar.driver.foobar'); $this->assertNull($driver); } From 26bde05a30c7111b57621a37d86425aa69d74263 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 9 Dec 2012 19:42:50 +0100 Subject: [PATCH 101/138] [feature/avatars] Call set_name() method in avatars.yml This is needed after 8a28271d was merged. PHPBB3-10018 --- phpBB/config/avatars.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/config/avatars.yml b/phpBB/config/avatars.yml index cc9ed05836..e6106038f5 100644 --- a/phpBB/config/avatars.yml +++ b/phpBB/config/avatars.yml @@ -7,6 +7,8 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver + calls: + - [set_name, [avatar.driver.gravatar]] tags: - { name: avatar.driver } @@ -18,6 +20,8 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver + calls: + - [set_name, [avatar.driver.local]] tags: - { name: avatar.driver } @@ -29,6 +33,8 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver + calls: + - [set_name, [avatar.driver.remote]] tags: - { name: avatar.driver } @@ -40,5 +46,7 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver + calls: + - [set_name, [avatar.driver.upload]] tags: - { name: avatar.driver } From 2f47c99432c604a2adaad73821602a4b1763caa8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 11 Dec 2012 21:02:37 +0100 Subject: [PATCH 102/138] [feature/avatars] Add more consistency to codebase PHPBB3-10018 --- .../style/acp_avatar_options_gravatar.html | 4 ++-- .../adm/style/acp_avatar_options_remote.html | 4 ++-- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/avatar/driver/gravatar.php | 19 ++++++++++++------- phpBB/includes/avatar/driver/remote.php | 15 ++++++++++----- phpBB/includes/ucp/ucp_profile.php | 4 ++-- 7 files changed, 31 insertions(+), 21 deletions(-) diff --git a/phpBB/adm/style/acp_avatar_options_gravatar.html b/phpBB/adm/style/acp_avatar_options_gravatar.html index 04fd5c459d..47422a6ecd 100644 --- a/phpBB/adm/style/acp_avatar_options_gravatar.html +++ b/phpBB/adm/style/acp_avatar_options_gravatar.html @@ -5,7 +5,7 @@

{L_GRAVATAR_AVATAR_SIZE_EXPLAIN}
- ×  - + {L_PIXEL} ×  + {L_PIXEL}
diff --git a/phpBB/adm/style/acp_avatar_options_remote.html b/phpBB/adm/style/acp_avatar_options_remote.html index ab91e90c27..1dc4b05992 100644 --- a/phpBB/adm/style/acp_avatar_options_remote.html +++ b/phpBB/adm/style/acp_avatar_options_remote.html @@ -5,7 +5,7 @@

{L_LINK_REMOTE_SIZE_EXPLAIN}
- ×  - + {L_PIXEL} ×  + {L_PIXEL}
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index ae0abdd139..fe65ea2f03 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -529,7 +529,7 @@ class acp_groups $avatars_enabled = true; $config_name = $phpbb_avatar_manager->get_driver_config_name($driver); $template->set_filenames(array( - 'avatar' => "acp_avatar_options_$config_name.html", + 'avatar' => "acp_avatar_options_{$config_name}.html", )); if ($driver->prepare_form($template, $avatar_data, $avatar_error)) diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index b3cfd81949..b2ef43edbe 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1765,7 +1765,7 @@ class acp_users $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user_id; + WHERE user_id = ' . (int) $user_id; $db->sql_query($sql); trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); @@ -1810,7 +1810,7 @@ class acp_users $avatars_enabled = true; $config_name = $phpbb_avatar_manager->get_driver_config_name($driver); $template->set_filenames(array( - 'avatar' => "acp_avatar_options_$config_name.html", + 'avatar' => "acp_avatar_options_{$config_name}.html", )); if ($driver->prepare_form($template, $avatar_data, $error)) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 11996ca561..2b10fd0c2d 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -77,13 +77,18 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); } - $error = array_merge($error, validate_data(array( - 'email' => $row['avatar'], - ), array( - 'email' => array( - array('string', false, 6, 60), - array('email')), - ))); + $validate_array = validate_data( + array( + 'email' => $row['avatar'], + ), + array( + 'email' => array( + array('string', false, 6, 60), + array('email')) + ) + ); + + $error = array_merge($error, $validate_array); if (!empty($error)) { diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 9135a62eac..1f16fce1e7 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -66,11 +66,16 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); } - $error = array_merge($error, validate_data(array( - 'url' => $url, - ), array( - 'url' => array('string', true, 5, 255), - ))); + $validate_array = validate_data( + array( + 'url' => $url, + ), + array( + 'url' => array('string', true, 5, 255), + ) + ); + + $error = array_merge($error, $validate_array); if (!empty($error)) { diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 14639b00ff..8ed5aff3e3 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -590,7 +590,7 @@ class ucp_profile $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user->data['user_id']; + WHERE user_id = ' . (int) $user->data['user_id']; $db->sql_query($sql); @@ -615,7 +615,7 @@ class ucp_profile $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user->data['user_id']; + WHERE user_id = ' . (int) $user->data['user_id']; $db->sql_query($sql); From e6aaef6066549696453063417167e5a79c53b353 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 15 Dec 2012 15:22:39 +0100 Subject: [PATCH 103/138] [feature/avatars] Use callback method in avatar manager's clean row PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 2789158de5..f5c93a6328 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -157,17 +157,22 @@ class phpbb_avatar_manager $keys = array_keys($row); $values = array_values($row); - $keys = array_map( - function ($key) - { - return preg_replace('#^(?:user_|group_)#', '', $key); - }, - $keys - ); + $keys = array_map(array('phpbb_avatar_manager', 'strip_prefix'), $keys); return array_combine($keys, $values); } + /** + * Strip prepending user_ or group_ prefix from key + * + * @param string Array key + * @return string Key that has been stripped from its prefix + */ + protected static function strip_prefix($key) + { + return preg_replace('#^(?:user_|group_)#', '', $key); + } + /** * Clean driver names that are returned from template files * Underscores are replaced with dots From ea6bf00977a44d437806e87e9cac1b9d5fcef238 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 20:39:02 +0100 Subject: [PATCH 104/138] [feature/avatars] Improve testing to also check for enabled drivers PHPBB3-10018 --- tests/avatar/manager_test.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index cae72c982b..b910db59ee 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -31,6 +31,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase ->method('get_name') ->will($this->returnValue('avatar.driver.foobar')); $avatar_drivers = array($this->avatar_foobar); + $config['allow_avatar_' . get_class($this->avatar_foobar)] = true; // Set up avatar manager $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); @@ -45,14 +46,24 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase $this->assertNull($driver); $driver = $this->manager->get_driver('avatar.driver.foobar'); + $this->assertEquals('avatar.driver.foobar', $driver); + + $driver = $this->manager->get_driver('avatar.driver.foo_wrong'); $this->assertNull($driver); } - public function test_get_valid_drivers() + public function test_get_all_drivers() { - $valid_drivers = $this->manager->get_all_drivers(); - $this->assertArrayHasKey('avatar.driver.foobar', $valid_drivers); - $this->assertEquals('avatar.driver.foobar', $valid_drivers['avatar.driver.foobar']); + $drivers = $this->manager->get_all_drivers(); + $this->assertArrayHasKey('avatar.driver.foobar', $drivers); + $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); + } + + public function test_get_enabled_drivers() + { + $drivers = $this->manager->get_enabled_drivers(); + $this->assertArrayHasKey('avatar.driver.foobar', $drivers); + $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); } public function test_get_avatar_settings() From c865f98dcfe57c3dff231fdf3574f5d3356ab7f5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 20:42:05 +0100 Subject: [PATCH 105/138] [feature/avatars] Some more miscellaneous changes PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatar/driver/remote.php | 2 +- phpBB/includes/avatar/driver/upload.php | 2 +- phpBB/includes/avatar/manager.php | 44 ++++++++++++------------- phpBB/includes/ucp/ucp_groups.php | 2 +- phpBB/includes/ucp/ucp_profile.php | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index fe65ea2f03..eeeefe03ba 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -290,7 +290,7 @@ class acp_groups if ($config['allow_avatar']) { $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the group_ prefix $avatar_data = phpbb_avatar_manager::clean_row($group_row); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index b2ef43edbe..0c29eb658f 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1737,7 +1737,7 @@ class acp_users if ($config['allow_avatar']) { $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_manager::clean_row($user_row); diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 1f16fce1e7..717b73eb0c 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -117,7 +117,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver if (!class_exists('fileupload')) { - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + include($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); } $types = fileupload::image_types(); diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 38627baacf..4facb243ac 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -63,7 +63,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver if (!class_exists('fileupload')) { - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + include($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); } $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $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)); diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index f5c93a6328..cbc9c4a485 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) class phpbb_avatar_manager { protected $config; - protected static $valid_drivers = false; + static protected $enabled_drivers = false; protected $avatar_drivers; protected $container; @@ -47,18 +47,18 @@ class phpbb_avatar_manager * Get the driver object specified by the avatar type * * @param string $avatar_type Avatar type; by default an avatar's service container name - * @param bool $load_valid Load only valid avatars + * @param bool $load_enabled Load only enabled avatars * * @return object Avatar driver object */ - public function get_driver($avatar_type, $load_valid = true) + public function get_driver($avatar_type, $load_enabled = true) { - if (self::$valid_drivers === false) + if (self::$enabled_drivers === false) { - $this->load_valid_drivers(); + $this->load_enabled_drivers(); } - $avatar_drivers = ($load_valid) ? self::$valid_drivers : $this->get_all_drivers(); + $avatar_drivers = ($load_enabled) ? self::$enabled_drivers : $this->get_all_drivers(); // Legacy stuff... switch ($avatar_type) @@ -89,22 +89,22 @@ class phpbb_avatar_manager } /** - * Load the list of valid drivers - * This is executed once and fills self::$valid_drivers + * Load the list of enabled drivers + * This is executed once and fills self::$enabled_drivers */ - protected function load_valid_drivers() + protected function load_enabled_drivers() { if (!empty($this->avatar_drivers)) { - self::$valid_drivers = array(); + self::$enabled_drivers = array(); foreach ($this->avatar_drivers as $driver) { if ($this->is_enabled($driver)) { - self::$valid_drivers[$driver->get_name()] = $driver->get_name(); + self::$enabled_drivers[$driver->get_name()] = $driver->get_name(); } } - asort(self::$valid_drivers); + asort(self::$enabled_drivers); } } @@ -130,18 +130,18 @@ class phpbb_avatar_manager } /** - * Get a list of valid avatar drivers + * Get a list of enabled avatar drivers * - * @return array Array containing a list of the valid avatar drivers + * @return array Array containing a list of the enabled avatar drivers */ - public function get_valid_drivers() + public function get_enabled_drivers() { - if (self::$valid_drivers === false) + if (self::$enabled_drivers === false) { - $this->load_valid_drivers(); + $this->load_enabled_drivers(); } - return self::$valid_drivers; + return self::$enabled_drivers; } /** @@ -152,7 +152,7 @@ class phpbb_avatar_manager * @return array User data or group data with keys that have been * stripped from the preceding "user_" or "group_" */ - public static function clean_row($row) + static public function clean_row($row) { $keys = array_keys($row); $values = array_values($row); @@ -168,7 +168,7 @@ class phpbb_avatar_manager * @param string Array key * @return string Key that has been stripped from its prefix */ - protected static function strip_prefix($key) + static protected function strip_prefix($key) { return preg_replace('#^(?:user_|group_)#', '', $key); } @@ -181,7 +181,7 @@ class phpbb_avatar_manager * * @return string Cleaned driver name */ - public static function clean_driver_name($name) + static public function clean_driver_name($name) { return str_replace('_', '.', $name); } @@ -194,7 +194,7 @@ class phpbb_avatar_manager * * @return string Prepared driver name */ - public static function prepare_driver_name($name) + static public function prepare_driver_name($name) { return str_replace('.', '_', $name); } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 262e7b238f..18f782f63e 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -492,7 +492,7 @@ class ucp_groups if ($config['allow_avatar']) { $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the group_ prefix $avatar_data = phpbb_avatar_manager::clean_row($group_row); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 8ed5aff3e3..3f59cda4a0 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -562,7 +562,7 @@ class ucp_profile if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_manager::clean_row($user->data); From 6f41228752fbb00139da5fd3f62c884a4391de82 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 20:46:07 +0100 Subject: [PATCH 106/138] [feature/avatars] Add missing explanation to docblock of get_all_drivers() PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index cbc9c4a485..68d1133e86 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -111,6 +111,10 @@ class phpbb_avatar_manager /** * Get a list of all avatar drivers * + * As this function will only be called in the ACP avatar settings page, it + * doesn't make much sense to cache the list of all avatar drivers like the + * list of the enabled drivers. + * * @return array Array containing a list of all avatar drivers */ public function get_all_drivers() From 8e756ad89005865b42e87ffc225f6d3bca475035 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 21:40:35 +0100 Subject: [PATCH 107/138] [feature/avatars] Let the server handle http or https for gravatars PHPBB3-10018 --- phpBB/includes/avatar/driver/gravatar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 2b10fd0c2d..c6bfb0d5c1 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -24,7 +24,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * The URL for the gravatar service */ - const GRAVATAR_URL = 'https://secure.gravatar.com/avatar/'; + const GRAVATAR_URL = '//secure.gravatar.com/avatar/'; /** * @inheritdoc From 4a8b1a6e050bba7f8f73f689bbca4185ab27cf8c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Jan 2013 10:25:08 +0100 Subject: [PATCH 108/138] [feature/avatars] Inform user of no available local avatars Rather than showing the user an empty drop-down list for the local avatar categories, inform him/her that there are currently no (local) avatars available. PHPBB3-10018 --- phpBB/language/en/common.php | 1 + .../styles/prosilver/template/ucp_avatar_options_local.html | 4 ++++ .../subsilver2/template/ucp_avatar_options_local.html | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 6277457af7..02b4443a56 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -396,6 +396,7 @@ $lang = array_merge($lang, array( 'NO_AUTH_ADMIN' => 'Access to the Administration Control Panel is not allowed as you do not have administrative permissions.', 'NO_AUTH_ADMIN_USER_DIFFER' => 'You are not able to re-authenticate as a different user.', 'NO_AUTH_OPERATION' => 'You do not have the necessary permissions to complete this operation.', + 'NO_AVATARS' => 'No avatars currently available', 'NO_CONNECT_TO_SMTP_HOST' => 'Could not connect to smtp host : %1$s : %2$s', 'NO_BIRTHDAYS' => 'No birthdays today', 'NO_EMAIL_MESSAGE' => 'Email message was blank.', diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html index d885abcd5b..3946b9d269 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html @@ -1,3 +1,4 @@ +