From 4c699e0d0acc0aafab37e36206a92b1919282dac Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 17 Apr 2011 19:29:28 -0700 Subject: [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 (limited to 'phpBB') 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; + } + + $html = ''; + + if (!empty($avatar_data['src'])) + { + $html = ''; } - $avatar_img .= $avatar; - return '' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . ''; + 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' => '', -- cgit v1.2.1 From 1bd3d40121960c203d0dabb4b1a04c16c564b6f1 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 17 Apr 2011 19:29:41 -0700 Subject: [feature/avatars] Refactor avatars to use manager Manager now stores singletons of each driver to speed loading. PHPBB3-10018 --- phpBB/includes/avatar/driver.php | 89 +++++++++++++++++++++++++++++++++ phpBB/includes/avatar/manager.php | 91 ++++++++++++++++++++++++++++++++++ phpBB/includes/avatars/avatar_base.php | 75 ---------------------------- phpBB/includes/functions_display.php | 51 ++++++------------- 4 files changed, 196 insertions(+), 110 deletions(-) create mode 100644 phpBB/includes/avatar/driver.php create mode 100644 phpBB/includes/avatar/manager.php delete mode 100644 phpBB/includes/avatars/avatar_base.php (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver.php new file mode 100644 index 0000000000..777b225e84 --- /dev/null +++ b/phpBB/includes/avatar/driver.php @@ -0,0 +1,89 @@ +config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * 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($user_row, $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($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/avatars/avatar_base.php b/phpBB/includes/avatars/avatar_base.php deleted file mode 100644 index c84a6e8a7f..0000000000 --- a/phpBB/includes/avatars/avatar_base.php +++ /dev/null @@ -1,75 +0,0 @@ -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 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,48 +1336,27 @@ 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); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->get_driver()); + } - sort($avatar_types); - $cache->put('avatar_types', $avatar_types); - } - } + $avatar = $avatar_manager->get_singleton($user_row['user_avatar_type']); - if (in_array($user_row['user_avatar_type'], $avatar_types)) + if ($avatar) + { + if ($avatar->custom_html) { - require_once($phpbb_root_path . 'includes/avatars/avatar_' . $user_row['user_avatar_type'] . '.' . $phpEx); + return $avatar->get_html($user_row, $ignore_config); } - } - - $avatar = new $class($user_row); - if ($avatar->custom_html) + $avatar_data = $avatar->get_data($user_row, $ignore_config); + } + else { - return $avatar->get_custom_html($ignore_config); + $avatar_data['src'] = ''; } - $avatar_data = $avatar->get_data($ignore_config); - 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( -- cgit v1.2.1 From 16bb0f00b79102aed7da984cbca8a4b1741c62af Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 17 Apr 2011 19:29:48 -0700 Subject: [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 (limited to 'phpBB') 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, + ); + } + } +} -- cgit v1.2.1 From 24379f1297d092141f04ccb55013e85e9b494a83 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 17 Apr 2011 20:11:36 -0700 Subject: [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 | 50 -------------------------------- phpBB/includes/avatar/driver/local.php | 50 ++++++++++++++++++++++++++++++++ phpBB/includes/avatar/driver/upload.php | 2 +- 3 files changed, 51 insertions(+), 51 deletions(-) delete mode 100644 phpBB/includes/avatar/driver/gallery.php create mode 100644 phpBB/includes/avatar/driver/local.php (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver/gallery.php b/phpBB/includes/avatar/driver/gallery.php deleted file mode 100644 index b937332b2d..0000000000 --- a/phpBB/includes/avatar/driver/gallery.php +++ /dev/null @@ -1,50 +0,0 @@ -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/local.php b/phpBB/includes/avatar/driver/local.php new file mode 100644 index 0000000000..4014f29cbe --- /dev/null +++ b/phpBB/includes/avatar/driver/local.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/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'], -- cgit v1.2.1 From 7abded081d5ae3d231148b0485c8605b44973229 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sun, 17 Apr 2011 21:58:51 -0700 Subject: [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 +++++++++++++-------- .../prosilver/template/ucp_avatar_options.html | 63 ++++-------- .../template/ucp_avatar_options_local.html | 14 +++ .../template/ucp_avatar_options_remote.html | 4 + .../template/ucp_avatar_options_upload.html | 11 +++ .../prosilver/template/ucp_profile_avatar.html | 10 +- 11 files changed, 262 insertions(+), 91 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 (limited to 'phpBB') 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 @@
- +
- - - - -
-
- -

{L_AVATAR_GALLERY}

+ +

{avatar_drivers.L_TITLE}

+

{avatar_drivers.L_EXPLAIN}

-
- - - -
- - +
+ {avatar_drivers.OUTPUT} +
+
+   + +
+ +
+ +
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} -- cgit v1.2.1 From f102d9a631d6de464abefe2089ff1e6e13ed044d Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 18 Apr 2011 10:44:29 -0700 Subject: [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(-) (limited to 'phpBB') 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']; - - $dh = @opendir($path); + $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list'); - 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')) -- cgit v1.2.1 From 00d4b9d431d6772889291f2f4c857a144bce93fb Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 18 Apr 2011 22:54:35 -0700 Subject: [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 +++++------- .../prosilver/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(-) (limited to 'phpBB') 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}
+
-- cgit v1.2.1 From f02f6216867db63f6ad2659b0b702b81b07a875c Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 18 Apr 2011 23:34:56 -0700 Subject: [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 | 27 ++++++++++++---------- .../template/ucp_avatar_options_remote.html | 4 ++-- 3 files changed, 25 insertions(+), 15 deletions(-) (limited to 'phpBB') 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] < 2 || $image_data[1] < 2)) - { - $error[] = 'AVATAR_NO_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]; + $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}
- ×  - + ×  +
-- cgit v1.2.1 From 019b9bc0735bb74d46f4e87fe006328970211dad Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Tue, 19 Apr 2011 11:19:47 -0700 Subject: [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 | 67 +++++++++++++++++++++++++++------ phpBB/includes/ucp/ucp_profile.php | 2 +- 3 files changed, 80 insertions(+), 39 deletions(-) (limited to 'phpBB') 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')) - { - $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); - } - else + // Match all images in the gallery folder + if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) { - $dims = array(0, 0); + 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], + ); } - $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 ''; + $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) + { + return false; } - else + + if ($submitted) { - $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'], - )); + 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)); - return true; + $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; -- cgit v1.2.1 From 611a1d647a3a63013df472b469bf1f3e6e7bd657 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Wed, 20 Apr 2011 09:46:36 -0700 Subject: [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 | 168 ++++++++++++++++---------------- phpBB/includes/avatar/driver/upload.php | 112 +++++++++++---------- phpBB/includes/ucp/ucp_profile.php | 4 +- 5 files changed, 218 insertions(+), 181 deletions(-) (limited to 'phpBB') 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)) - { - return false; - } + 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; - } + // 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')) + // 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; - } - - 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]; + $error[] = 'UNABLE_GET_IMAGE_SIZE'; + return false; } - 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 (!isset($types[$image_data[2]])) - { - $error[] = 'UNABLE_GET_IMAGE_SIZE'; - } - else - { - $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension); - } + if ($width <= 0 || $height <= 0) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } - return false; - } + include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); + $types = fileupload::image_types(); + $extension = strtolower(filespec::get_extension($url)); - if ($this->config['avatar_max_width'] || $this->config['avatar_max_height']) + if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) + { + if (!isset($types[$image_data[2]])) { - 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; - } + $error[] = 'UNABLE_GET_IMAGE_SIZE'; } - - if ($this->config['avatar_min_width'] || $this->config['avatar_min_height']) + else { - 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; - } + $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension); } - $result = array( - 'user_avatar' => $url, - 'user_avatar_width' => $width, - 'user_avatar_height' => $height, - ); + return false; + } - return $result; + 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; + } } - 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,71 +47,85 @@ 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) + $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; + } + + /** + * @inheritdoc + */ + public function process_form($template, $user_row, &$error) + { + if (!$this->can_upload()) { - include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); + return false; + } - $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)); + include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); - $url = request_var('av_upload_url', ''); + $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)); - if (!empty($_FILES['av_upload_file']['name'])) - { - $file = $upload->form_upload('av_upload_file'); - } - else - { - $file = $upload->remote_upload($url); - } + $url = request_var('av_upload_url', ''); - $prefix = $this->config['avatar_salt'] . '_'; - $file->clean_filename('avatar', $prefix, $user_row['user_id']); + if (!empty($_FILES['av_upload_file']['name'])) + { + $file = $upload->form_upload('av_upload_file'); + } + else + { + $file = $upload->remote_upload($url); + } - $destination = $this->config['avatar_path']; + $prefix = $this->config['avatar_salt'] . '_'; + $file->clean_filename('avatar', $prefix, $user_row['user_id']); - // Adjust destination path (no trailing slash) - if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') - { - $destination = substr($destination, 0, -1); - } + $destination = $this->config['avatar_path']; - $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); - if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) - { - $destination = ''; - } + // Adjust destination path (no trailing slash) + if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') + { + $destination = substr($destination, 0, -1); + } - // Move file and overwrite any existing image - $file->move_file($destination, true); + $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); + if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) + { + $destination = ''; + } - if (sizeof($file->error)) - { - $file->remove(); - $error = array_merge($error, $file->error); - return false; - } + // Move file and overwrite any existing image + $file->move_file($destination, true); - return array( - 'user_avatar' => $user_row['user_id'] . '_' . time() . '.' . $file->get('extension'), - 'user_avatar_width' => $file->get('width'), - 'user_avatar_height' => $file->get('height'), - ); + if (sizeof($file->error)) + { + $file->remove(); + $error = array_merge($error, $file->error); + return false; } - - $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; + + 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( -- cgit v1.2.1 From 84099e5bc1f452e1a4643fd78658929875ab1eee Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Wed, 20 Apr 2011 23:14:38 -0700 Subject: [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 ++++ phpBB/adm/style/acp_avatar_options_remote.html | 11 +++ phpBB/adm/style/acp_avatar_options_upload.html | 11 +++ phpBB/adm/style/acp_users_avatar.html | 85 ++++------------------ 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 +++++++++ .../prosilver/template/ucp_avatar_options.html | 7 +- 11 files changed, 129 insertions(+), 80 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 (limited to 'phpBB') 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}
-
- - -
-
-
-
- - -
- -
- {L_AVATAR_GALLERY} -
-
-
 
-
+

{ERROR}

- - - - - - - - - - - - - -
{avatar_row.avatar_column.AVATAR_NAME}
+

{L_AVATAR_EXPLAIN}
+
{AVATAR}
+
+
+ +
+ {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 @@ -
- - -
- -- cgit v1.2.1 From 6d0f2e478800e1e9696701eeff00ac69c1e57dee Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Wed, 15 Jun 2011 12:38:17 -0700 Subject: [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(-) (limited to 'phpBB') 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: -- cgit v1.2.1 From 22c864cb3a945b52fe9b91765d247abfe00b50bc Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Wed, 15 Jun 2011 12:58:02 -0700 Subject: [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(-) (limited to 'phpBB') 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", + )); - // Replace "error" strings with their real, localised form - $error = array_map(array($user, 'lang'), $error); - } + $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); + } - if (!$config['allow_avatar'] && $user_row['user_avatar_type']) - { - $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']; - } + $result = $avatar->process_form($template, $user_row, $error); - // Generate users avatar - $avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row, 'USER_AVATAR', true) : ''; + 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; - $display_gallery = (isset($_POST['display_gallery'])) ? true : false; - $avatar_select = basename(request_var('avatar_select', '')); - $category = basename(request_var('category', '')); + $db->sql_query($sql); + trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); + } + } - if ($config['allow_avatar_local'] && $display_gallery) + 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 + $err = $error; + $error = array(); + foreach ($err as $e) { - 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, - - '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'], - - 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(), + 'S_AVATAR' => true, + 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', + 'AVATAR' => (empty($avatar) ? '' : $avatar), + 'AV_SHOW_DELETE' => !empty($avatar), + + 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', + + '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( -- cgit v1.2.1 From 6deadc3acf302e9fd15adfd6bff5f0fe525240c7 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sat, 18 Jun 2011 21:12:29 -0700 Subject: [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 +++++++++++++++------- .../prosilver/template/ucp_avatar_options.html | 49 +++++++++++++-- 3 files changed, 94 insertions(+), 26 deletions(-) (limited to 'phpBB') 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}
+
+ +
  - +
- + + + -- cgit v1.2.1 From d0bb14ded1960de47eb07d955a483d74fd9e0af2 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sat, 18 Jun 2011 22:05:54 -0700 Subject: [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(-) (limited to 'phpBB') 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'), )); } -- cgit v1.2.1 From a06380c69a154659f4f9985238008640670669e0 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sat, 18 Jun 2011 22:50:52 -0700 Subject: [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(-) (limited to 'phpBB') 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); -- cgit v1.2.1 From 8416bf3dc9539df19530e3bef85352d40ac795f2 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Sat, 18 Jun 2011 23:49:04 -0700 Subject: [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(-) (limited to 'phpBB') 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 @@ -- cgit v1.2.1 From 48e61b1b45655b38660740abb0de9704234af849 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 4 Jul 2011 16:58:35 -0700 Subject: [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 | 98 ++++++-------- phpBB/includes/acp/acp_groups.php | 180 +++++++++++++------------- phpBB/includes/acp/acp_users.php | 1 - phpBB/includes/avatar/driver/local.php | 4 + 5 files changed, 137 insertions(+), 148 deletions(-) (limited to 'phpBB') 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}
-
- -
-
-
-
- - - - -
- {L_AVATAR_GALLERY} -
-
-
 
-
-
- - - - - - - - - - - - - -
{avatar_row.avatar_column.AVATAR_NAME}
-
-
- -
- -
- - +
+
+
+
+
+ +
+

{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) : ''; + // Load up stuff for avatars + if ($config['allow_avatar']) + { + $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", + )); - $display_gallery = (isset($_POST['display_gallery'])) ? true : false; + $avatar = $avatar_manager->get_driver($driver); - if ($config['allow_avatar_local'] && $display_gallery) + 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) { - 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); + } } $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]); -- cgit v1.2.1 From 3963b39634225a68687cf1b817a47ae1eeb6ac79 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 4 Jul 2011 17:19:18 -0700 Subject: [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(-) (limited to 'phpBB') 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, -- cgit v1.2.1 From c7976279e1c85f921156ed499dee1e587587c693 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 18:59:24 +0200 Subject: [feature/avatars] Fix avatar driver filename for autoloading PHPBB3-10018 --- phpBB/includes/avatar/driver.php | 172 -------------------------------- phpBB/includes/avatar/driver/driver.php | 172 ++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 172 deletions(-) delete mode 100644 phpBB/includes/avatar/driver.php create mode 100644 phpBB/includes/avatar/driver/driver.php (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver.php deleted file mode 100644 index d158c419bd..0000000000 --- a/phpBB/includes/avatar/driver.php +++ /dev/null @@ -1,172 +0,0 @@ -config = $config; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; - $this->cache = $cache; - } - - /** - * 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 - */ - public function get_data($row, $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 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) - { - return ''; - } - - /** - * @TODO - **/ - public function prepare_form($template, $row, &$error, &$override_focus) - { - return false; - } - - /** - * @TODO - **/ - public function process_form($template, $row, &$error) - { - return false; - } - - /** - * @TODO - **/ - 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/driver.php b/phpBB/includes/avatar/driver/driver.php new file mode 100644 index 0000000000..d158c419bd --- /dev/null +++ b/phpBB/includes/avatar/driver/driver.php @@ -0,0 +1,172 @@ +config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->cache = $cache; + } + + /** + * 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 + */ + public function get_data($row, $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 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) + { + return ''; + } + + /** + * @TODO + **/ + public function prepare_form($template, $row, &$error, &$override_focus) + { + return false; + } + + /** + * @TODO + **/ + public function process_form($template, $row, &$error) + { + return false; + } + + /** + * @TODO + **/ + 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; + } +} -- cgit v1.2.1 From 3b0e0dba3279a78cab2336d32ee8ff63a7077c5c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 19:08:54 +0200 Subject: [feature/avatars] Remove unneeded require (class is now autoloaded) PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB') 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'); -- cgit v1.2.1 From e861bb0e04c08b03366ec7c58473b630acc91181 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 19:19:13 +0200 Subject: [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(-) (limited to 'phpBB') 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); -- cgit v1.2.1 From 0898d114574e88eb5eda819b8921a27739be74ca Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 20:27:11 +0200 Subject: [feature/avatars] Fix CS PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB') 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(); -- cgit v1.2.1 From e8a9c0ae6d92822699de9a2d7fc1aae9377ade8a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:11:06 +0200 Subject: [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(-) (limited to 'phpBB') 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 '', -- cgit v1.2.1 From eea2ec50521e274b928d23f710108f37797cb22c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:27:09 +0200 Subject: [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(-) (limited to 'phpBB') 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)) { -- cgit v1.2.1 From 81fb4268cd141259fe5b3bc9ad51adf2e29e0772 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:40:19 +0200 Subject: [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 (limited to 'phpBB') 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) { -- cgit v1.2.1 From 3b71e81cfba726043063b05cb793e18186143252 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 21:29:52 +0200 Subject: [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(-) (limited to 'phpBB') 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) { -- cgit v1.2.1 From a1132fc5c7e990d73cbc8ac7abf4502a1bbe7216 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 21:45:51 +0200 Subject: [feature/avatars] Update avatars in database_update PHPBB3-10018 --- phpBB/includes/functions_display.php | 70 +++++++----------------------------- phpBB/install/database_update.php | 24 +++++++++++-- 2 files changed, 35 insertions(+), 59 deletions(-) (limited to 'phpBB') 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']) - { - 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; - 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; + $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); - 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'] = ''; - } + if ($avatar) + { + if ($avatar->custom_html) + { + return $avatar->get_html($row, $ignore_config); + } - 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; -- cgit v1.2.1 From b2b812f1714fc924a7c9e595ccb8fbb35f20f203 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 22:13:10 +0200 Subject: [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(-) (limited to 'phpBB') 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); } -- cgit v1.2.1 From f273ab16ae68d15832832e2b2c98a3b99c966c97 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 22:28:40 +0200 Subject: [feature/avatars] Fix clean_row regex, thanks to chris PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') 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 ); -- cgit v1.2.1 From 6d994380d76accba5485b0a04d3028f1c153ebd8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 14:48:51 +0200 Subject: [feature/avatars] Fix error in avatar_manager::clean_row PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') 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); -- cgit v1.2.1 From d10486699273b896fffe86f05f66a6d542843f5b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 16:59:06 +0200 Subject: [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(-) (limited to 'phpBB') 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; } -- cgit v1.2.1 From f40e6963c61548d746c59b78cb60c0f7459c7696 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 17:11:20 +0200 Subject: [feature/avatars] Remove empty script tag PHPBB3-10018 --- phpBB/styles/prosilver/template/ucp_avatar_options.html | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB') 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 @@
- -- cgit v1.2.1 From 21df013210d1de2cffae568c0620a7ccd6d8f426 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:23:26 +0200 Subject: [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 +++++++++++++++ .../prosilver/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 (limited to 'phpBB') 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 @@ - - + + -- cgit v1.2.1 From b060667ac102109c0c8f198925bb81b489a30f34 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:26:44 +0200 Subject: [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(-) (limited to 'phpBB') 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); -- cgit v1.2.1 From 2f3581fe3ef928d91f12c442ab5e4890c6620f58 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:37:23 +0200 Subject: [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(+) (limited to 'phpBB') 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 -- cgit v1.2.1 From 13f4bfabbeab77698f06c3431931b73ebedc587c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 21:00:00 +0200 Subject: [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(-) (limited to 'phpBB') 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 -- cgit v1.2.1 From df16bd1c49e6e970b147f15e752825dd3186fb87 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 21:02:07 +0200 Subject: [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 +- phpBB/includes/avatar/driver/core/local.php | 189 +++++++++++++++++++++++++++ phpBB/includes/avatar/driver/core/remote.php | 163 +++++++++++++++++++++++ phpBB/includes/avatar/driver/core/upload.php | 147 +++++++++++++++++++++ phpBB/includes/avatar/driver/driver.php | 21 +++ phpBB/includes/avatar/driver/interface.php | 10 ++ phpBB/includes/avatar/driver/local.php | 189 --------------------------- phpBB/includes/avatar/driver/remote.php | 163 ----------------------- phpBB/includes/avatar/driver/upload.php | 147 --------------------- phpBB/includes/avatar/manager.php | 55 ++++---- phpBB/includes/ucp/ucp_profile.php | 10 +- 12 files changed, 564 insertions(+), 534 deletions(-) create mode 100644 phpBB/includes/avatar/driver/core/local.php create mode 100644 phpBB/includes/avatar/driver/core/remote.php create mode 100644 phpBB/includes/avatar/driver/core/upload.php delete mode 100644 phpBB/includes/avatar/driver/local.php delete mode 100644 phpBB/includes/avatar/driver/remote.php delete mode 100644 phpBB/includes/avatar/driver/upload.php (limited to 'phpBB') 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/core/local.php b/phpBB/includes/avatar/driver/core/local.php new file mode 100644 index 0000000000..ca82b9c175 --- /dev/null +++ b/phpBB/includes/avatar/driver/core/local.php @@ -0,0 +1,189 @@ +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, + ); + } + } + + /** + * @inheritdoc + */ + public function prepare_form($template, $row, &$error) + { + $avatar_list = $this->get_avatar_list(); + $category = $this->request->variable('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])) + { + $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]); + + reset($avatar_list[$category]); + + while ($av_pos < $av_count) + { + $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; + } + } + + return true; + } + + /** + * @inheritdoc + */ + public function process_form($template, $row, &$error) + { + $avatar_list = $this->get_avatar_list(); + $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'; + return false; + } + + return array( + 'avatar' => $category . '/' . $file, + 'avatar_width' => $avatar_list[$category][urldecode($file)]['width'], + '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'); + + if (!$avatar_list) + { + $avatar_list = array(); + $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; + + $dh = @opendir($path); + + if ($dh) + { + 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); + } + + @ksort($avatar_list); + + if ($this->cache != null) + { + $this->cache->put('av_local_list', $avatar_list); + } + } + + return $avatar_list; + } +} diff --git a/phpBB/includes/avatar/driver/core/remote.php b/phpBB/includes/avatar/driver/core/remote.php new file mode 100644 index 0000000000..9f5a58e75a --- /dev/null +++ b/phpBB/includes/avatar/driver/core/remote.php @@ -0,0 +1,163 @@ +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, + ); + } + } + + /** + * @inheritdoc + */ + 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'] : $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'] : '', + )); + + return true; + } + + /** + * @inheritdoc + */ + 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); + + if (!preg_match('#^(http|https|ftp)://#i', $url)) + { + $url = 'http://' . $url; + } + + require_once($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); + + $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 (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) + { + $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; + } + } + + return array( + 'avatar' => $url, + 'avatar_width' => $width, + 'avatar_height' => $height, + ); + } +} diff --git a/phpBB/includes/avatar/driver/core/upload.php b/phpBB/includes/avatar/driver/core/upload.php new file mode 100644 index 0000000000..d0ce856dbe --- /dev/null +++ b/phpBB/includes/avatar/driver/core/upload.php @@ -0,0 +1,147 @@ +config['allow_avatar_upload']) + { + return array( + 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } + + /** + * @inheritdoc + */ + public function prepare_form($template, $row, &$error) + { + if (!$this->can_upload()) + { + return false; + } + + $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; + } + + /** + * @inheritdoc + */ + public function process_form($template, $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 = $this->request->variable('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, $row['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( + 'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'), + 'avatar_width' => $file->get('width'), + 'avatar_height' => $file->get('height'), + ); + } + + /** + * @inheritdoc + */ + public function delete($row) + { + $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)) + { + @unlink($filename); + } + + return true; + } + + /** + * @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/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/driver/local.php b/phpBB/includes/avatar/driver/local.php deleted file mode 100644 index a0ef912eae..0000000000 --- a/phpBB/includes/avatar/driver/local.php +++ /dev/null @@ -1,189 +0,0 @@ -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, - ); - } - } - - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - $avatar_list = $this->get_avatar_list(); - $category = $this->request->variable('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])) - { - $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]); - - reset($avatar_list[$category]); - - while ($av_pos < $av_count) - { - $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; - } - } - - return true; - } - - /** - * @inheritdoc - */ - public function process_form($template, $row, &$error) - { - $avatar_list = $this->get_avatar_list(); - $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'; - return false; - } - - return array( - 'avatar' => $category . '/' . $file, - 'avatar_width' => $avatar_list[$category][urldecode($file)]['width'], - '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'); - - if (!$avatar_list) - { - $avatar_list = array(); - $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; - - $dh = @opendir($path); - - if ($dh) - { - 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); - } - - @ksort($avatar_list); - - if ($this->cache != null) - { - $this->cache->put('av_local_list', $avatar_list); - } - } - - return $avatar_list; - } -} diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php deleted file mode 100644 index cd0a756428..0000000000 --- a/phpBB/includes/avatar/driver/remote.php +++ /dev/null @@ -1,163 +0,0 @@ -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, - ); - } - } - - /** - * @inheritdoc - */ - 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'] : $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'] : '', - )); - - return true; - } - - /** - * @inheritdoc - */ - 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); - - if (!preg_match('#^(http|https|ftp)://#i', $url)) - { - $url = 'http://' . $url; - } - - require_once($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); - - $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 (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) - { - $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; - } - } - - return array( - 'avatar' => $url, - 'avatar_width' => $width, - 'avatar_height' => $height, - ); - } -} diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php deleted file mode 100644 index d9504c04a0..0000000000 --- a/phpBB/includes/avatar/driver/upload.php +++ /dev/null @@ -1,147 +0,0 @@ -config['allow_avatar_upload']) - { - return array( - 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - } - - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - if (!$this->can_upload()) - { - return false; - } - - $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; - } - - /** - * @inheritdoc - */ - public function process_form($template, $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 = $this->request->variable('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, $row['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( - 'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'), - 'avatar_width' => $file->get('width'), - 'avatar_height' => $file->get('height'), - ); - } - - /** - * @inheritdoc - */ - public function delete($row) - { - $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)) - { - @unlink($filename); - } - - return true; - } - - /** - * @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/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'); - - 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]; - } - } + $finder = $this->extension_manager->get_finder(); - 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); -- cgit v1.2.1 From 4c9820d1ca47d088146f3f52fb1126821efe3646 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 12 Nov 2012 15:01:25 +0100 Subject: [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(-) (limited to 'phpBB') 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 @@ +
-- cgit v1.2.1 From 4c4b82416b8c7b3a8f97b12ca96699bea0bde91d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 12 Nov 2012 15:06:44 +0100 Subject: [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 +- phpBB/styles/prosilver/template/ucp_avatar_options_remote.html | 4 ++-- phpBB/styles/prosilver/template/ucp_avatar_options_upload.html | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) (limited to 'phpBB') 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}
×  -- cgit v1.2.1 From c70cbfac4339529e196934405d0eb2f9672121d5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 17 Nov 2012 00:50:23 +0100 Subject: [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 --- phpBB/adm/style/acp_avatar_options_gravatar.html | 11 ++++++ phpBB/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 | 26 +++++++------ phpBB/includes/ucp/ucp_profile.php | 2 +- 7 files changed, 51 insertions(+), 80 deletions(-) create mode 100644 phpBB/adm/style/acp_avatar_options_gravatar.html (limited to 'phpBB') 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_UPLOAD_AVATAR_URL}{L_COLON}
{L_UPLOAD_AVATAR_URL_EXPLAIN} - - - - - - {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_AVATAR_GALLERY}{L_COLON} - {L_DISPLAY_GALLERY} - - - - - - {L_AVATAR_GALLERY} - - - {L_AVATAR_CATEGORY}{L_COLON}   - - - - - - - - - - - - - - - - -
{avatar_row.avatar_column.AVATAR_NAME}
- + + {L_AVATAR_SELECT} - + + {L_AVATAR_TYPE}{L_COLON} + + + + + + {avatar_drivers.L_EXPLAIN} + + + {avatar_drivers.OUTPUT} + + @@ -84,4 +50,6 @@ + + -- cgit v1.2.1 From 959bc183bf21e77c694ac0b68cbda5b93ae79cd0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Nov 2012 23:09:09 +0100 Subject: [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(-) (limited to 'phpBB') 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}

-- cgit v1.2.1 From c2ba24558ff79174af9aaf2bee274529c794cac8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Nov 2012 23:11:40 +0100 Subject: [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(-) (limited to 'phpBB') 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'] )); -- cgit v1.2.1 From 7521c077a9c0b3201dffcbe33114d9da715eb9e0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Nov 2012 23:16:37 +0100 Subject: [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 ++-- phpBB/styles/subsilver2/template/ucp_avatar_options_local.html | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'phpBB') 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}
-- cgit v1.2.1 From bea6e845d3c0c25f5f84ad13fcf22f42f1249561 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 19 Nov 2012 00:27:22 +0100 Subject: [feature/avatars] Use https for gravatar PHPBB3-10018 --- phpBB/includes/avatar/driver/gravatar.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'phpBB') 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: [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(-) (limited to 'phpBB') 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'])) -- cgit v1.2.1 From 858c59279c0f8b07412dec676c96d9b291d91897 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 19 Nov 2012 23:50:34 +0100 Subject: [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(-) (limited to 'phpBB') 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)) { -- cgit v1.2.1 From b7b14f9a056190c6a01c98f6eec9e60ad73d7564 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 16:20:14 +0100 Subject: [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(-) (limited to 'phpBB') 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; + } } -- cgit v1.2.1 From 9b61204a17386742d3d3ec579ee8dcfe50cbf5a4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 16:27:20 +0100 Subject: [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(+) (limited to 'phpBB') 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'], -- cgit v1.2.1 From 726d1a16d704630a9a028010c7420bea837738d4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 17:15:35 +0100 Subject: [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(-) (limited to 'phpBB') 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 */ -- cgit v1.2.1 From 8c782122c1bafe6f232af6d9f395aa534c4d7dc1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 17:24:02 +0100 Subject: [feature/avatars] Use in_array() and fix tabbing PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB') 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; } -- cgit v1.2.1 From 01b313ea262dc7c7a3399c03758ffd1ba24d1ff4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 19:20:39 +0100 Subject: [feature/avatars] Use isset() instead of in_array() PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB') 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(); } } } -- cgit v1.2.1 From 24ac0393360aed07a17b7acaca0add6083cf8ddd Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 19:51:46 +0100 Subject: [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(-) (limited to 'phpBB') 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])) -- cgit v1.2.1 From 8a01bc171837be40818f285035ccefa5ac819213 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Nov 2012 21:42:42 +0100 Subject: [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 | 54 +++++++++++++--------------------- 1 file changed, 21 insertions(+), 33 deletions(-) (limited to 'phpBB') 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) + $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 ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) + if (function_exists('getimagesize')) { - 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); - } + $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], + ); } - @closedir($dh); } - @ksort($avatar_list); if ($this->cache != null) -- cgit v1.2.1 From 5289dc52a322f760b6a2108f5fed1b4ff365e1d4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Nov 2012 00:00:45 +0100 Subject: [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 ++++++++++----------- .../prosilver/template/ucp_avatar_options.html | 2 + .../prosilver/template/ucp_groups_manage.html | 4 +- .../subsilver2/template/ucp_groups_manage.html | 91 ++++------ .../subsilver2/template/ucp_profile_avatar.html | 4 +- 5 files changed, 125 insertions(+), 160 deletions(-) (limited to 'phpBB') 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)) - { - $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']) + else { - 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}   - -- cgit v1.2.1 From 211abe2ac9722f23d2f86b6172452e9d9d1bff38 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Nov 2012 00:39:02 +0100 Subject: [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(-) (limited to 'phpBB') 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 * -- cgit v1.2.1 From 5ff343f1e6714fd88d64cb17884f88ceee681cb6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Nov 2012 11:58:45 +0100 Subject: [feature/avatars] Remove duplicate form enctype PHPBB3-10018 --- phpBB/adm/style/acp_groups.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') 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} -- cgit v1.2.1 From 2b917199066cb06aa9c6c846ce06252d6f8036e9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Nov 2012 18:38:36 +0100 Subject: [feature/avatars] Add allow_avatar_gravatar to schema_data.sql PHPBB3-10018 --- phpBB/install/schemas/schema_data.sql | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB') 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'); -- cgit v1.2.1 From ce44e3908eef5166e5e3e43d2642c5372379b6a6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 00:54:34 +0100 Subject: [feature/avatars] Remove unnecessary abbreviations PHPBB3-10018 --- phpBB/adm/style/acp_avatar_options_gravatar.html | 10 ++++---- phpBB/adm/style/acp_avatar_options_local.html | 28 ++++++++++---------- phpBB/adm/style/acp_avatar_options_remote.html | 10 ++++---- phpBB/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 +-- .../prosilver/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 +-- .../subsilver2/template/ucp_groups_manage.html | 6 ++--- .../subsilver2/template/ucp_profile_avatar.html | 6 ++--- 28 files changed, 157 insertions(+), 157 deletions(-) (limited to 'phpBB') 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} -- cgit v1.2.1 From 7945ffa2a131c1539a4aa929039c4d44b8e4d336 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 01:02:43 +0100 Subject: [feature/avatars] Use new avatar types in database updater PHPBB3-10018 --- phpBB/install/database_update.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB') 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) -- cgit v1.2.1 From ce5e2f16777ae5319fcb902ee58005a4caced7e6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 01:18:27 +0100 Subject: [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(-) (limited to 'phpBB') 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; -- cgit v1.2.1 From 67c2e48d15d6e4ddd244dd2e126f906ed25be1ef Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 14:33:13 +0100 Subject: [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(-) (limited to 'phpBB') 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')) -- cgit v1.2.1 From 6d061304afaa703a5305a06a903356d1c48ff2ee Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 15:03:35 +0100 Subject: [feature/avatars] Small fixes PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'phpBB') 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); } -- cgit v1.2.1 From 06639729ea2da6d0025da74ae7d4f3e88f211b67 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 16:04:59 +0100 Subject: [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(-) (limited to 'phpBB') 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( -- cgit v1.2.1 From f8256ed00f5ecc95fbf9f69fd2e8de2a92bccec6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 16:18:51 +0100 Subject: [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(-) (limited to 'phpBB') 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); -- cgit v1.2.1 From a77fcdb5f93ed291c223c445a46a5641cfdb27ea Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 17:01:21 +0100 Subject: [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(-) (limited to 'phpBB') 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"); } } -- cgit v1.2.1 From 6522190ff1b7a7b4384389f23c1229911c1a58d2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 20:50:31 +0100 Subject: [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(-) (limited to 'phpBB') 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)); -- cgit v1.2.1 From f851d763f9997b896219d1068dd23f6de7dbfc36 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 21:14:05 +0100 Subject: [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(-) (limited to 'phpBB') 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); -- cgit v1.2.1 From 0abec06b09c71feb709b6101949181ff7ec4d882 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 21:16:21 +0100 Subject: [feature/avatars] Change gravatar explain as discussed in PR PHPBB3-10018 --- phpBB/language/en/ucp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') 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', -- cgit v1.2.1 From cb1d98ab7f588a38fcae680aca839b805caf2a23 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Nov 2012 23:06:38 +0100 Subject: [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(-) (limited to 'phpBB') 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'); -- cgit v1.2.1 From 81a1a21185abfc230097a355216d6c6b99511b20 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 29 Nov 2012 23:08:29 +0100 Subject: [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(-) (limited to 'phpBB') 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: [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 | 35 ++++++++++++++---------------- 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 | 33 +++++++++++++--------------- 8 files changed, 88 insertions(+), 96 deletions(-) (limited to 'phpBB') 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", - )); + $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)) - { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); - $driver_upper = strtoupper($driver_name); + 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'), + $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'), - )); - } + '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(), - )); + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => $avatar->get_template_name(), + )); - if ($avatar->prepare_form($template, $avatar_data, $error)) - { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); - $driver_upper = strtoupper($driver_name); + 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'), + $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'), - )); - } + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, + 'OUTPUT' => $template->assign_display('avatar'), + )); } } } -- cgit v1.2.1 From 562ebe5c12b8a238b94a63ba53b694af4d061bc9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 14:36:18 +0100 Subject: [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(-) (limited to 'phpBB') 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 '', -- cgit v1.2.1 From d5cbedaaa28312c107ec562c78ffaa034595f336 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 15:12:34 +0100 Subject: [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(-) (limited to 'phpBB') 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) -- cgit v1.2.1 From 33b98dc5ba0b690fdae72acfd676dae5a897cb6a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 16:46:11 +0100 Subject: [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(-) (limited to 'phpBB') 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'), )); } -- cgit v1.2.1 From 081440f6c4bd6b7c2838dd0587ed6a4dffc87d52 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 23:11:44 +0100 Subject: [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(-) (limited to 'phpBB') 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), + ); + } } -- cgit v1.2.1 From d439f477105903ceb29652f23bcb7812d0f34d4d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 1 Dec 2012 00:27:52 +0100 Subject: [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(-) (limited to 'phpBB') 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); } -- cgit v1.2.1 From 215ac6a0daa51881dc6abb987baf10e682fc9972 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 1 Dec 2012 21:28:44 +0100 Subject: [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(-) (limited to 'phpBB') 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; } -- cgit v1.2.1 From b42ca792fd7765eb415536c49b77c53c0897367e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Dec 2012 00:49:37 +0100 Subject: [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(-) (limited to 'phpBB') 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 -- cgit v1.2.1 From fc4069f81df54630a5ac8c1373c38f4834553012 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Dec 2012 00:59:37 +0100 Subject: [feature/avatars] Use seperate function for retrieving all drivers PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/avatar/manager.php | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'phpBB') 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) { -- cgit v1.2.1 From 8aaa3e055fdc50faeea6f590408a7bcbb03a8d92 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Dec 2012 15:11:14 +0100 Subject: [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(-) (limited to 'phpBB') 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)); + } } -- cgit v1.2.1 From fb139a88203fb5475712c2bc39e653996cd9103f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Dec 2012 15:12:04 +0100 Subject: [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 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'phpBB') 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; -- cgit v1.2.1 From 780a8c98aca5dc54e1b85a79f8ff0f04ce49c5e4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Dec 2012 14:28:52 +0100 Subject: [ticket/10411] Rename template variable CUR_ to CURRENT_ PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 2 +- phpBB/includes/acp/acp_groups.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB') diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index 99864f75ce..eb4c3d8819 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -108,7 +108,7 @@

{L_TEAMPAGE_EXPLAIN}

-

{L_TEAMPAGE} » {CUR_CATEGORY_NAME}

+

{L_TEAMPAGE} » {CURRENT_CATEGORY_NAME}

diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 3784e5c169..81ae567a8c 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -948,7 +948,7 @@ class acp_groups if ($row['teampage_id'] == $category_id) { $template->assign_vars(array( - 'CUR_CATEGORY_NAME' => $row['teampage_name'], + 'CURRENT_CATEGORY_NAME' => $row['teampage_name'], )); continue; } -- cgit v1.2.1 From 26bde05a30c7111b57621a37d86425aa69d74263 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 9 Dec 2012 19:42:50 +0100 Subject: [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(+) (limited to 'phpBB') 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 } -- cgit v1.2.1 From 2f47c99432c604a2adaad73821602a4b1763caa8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 11 Dec 2012 21:02:37 +0100 Subject: [feature/avatars] Add more consistency to codebase PHPBB3-10018 --- phpBB/adm/style/acp_avatar_options_gravatar.html | 4 ++-- phpBB/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(-) (limited to 'phpBB') 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); -- cgit v1.2.1 From e6aaef6066549696453063417167e5a79c53b353 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 15 Dec 2012 15:22:39 +0100 Subject: [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(-) (limited to 'phpBB') 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 -- cgit v1.2.1 From c865f98dcfe57c3dff231fdf3574f5d3356ab7f5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 20:42:05 +0100 Subject: [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(-) (limited to 'phpBB') 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); -- cgit v1.2.1 From 6f41228752fbb00139da5fd3f62c884a4391de82 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 20:46:07 +0100 Subject: [feature/avatars] Add missing explanation to docblock of get_all_drivers() PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB') 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() -- cgit v1.2.1 From 8e756ad89005865b42e87ffc225f6d3bca475035 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 21:40:35 +0100 Subject: [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(-) (limited to 'phpBB') 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 -- cgit v1.2.1 From 4a8b1a6e050bba7f8f73f689bbca4185ab27cf8c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Jan 2013 10:25:08 +0100 Subject: [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 + phpBB/styles/prosilver/template/ucp_avatar_options_local.html | 4 ++++ phpBB/styles/subsilver2/template/ucp_avatar_options_local.html | 6 ++++++ 3 files changed, 11 insertions(+) (limited to 'phpBB') 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 @@ +
+
{L_AVATAR_CATEGORY}{L_COLON}
+ + + {L_NO_AVATARS} + + -- cgit v1.2.1 From 7256a2d944df10ef649794c6174fea5ca69adea3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Jan 2013 15:10:43 +0100 Subject: [feature/avatars] Add phpbb prefix to new functions Although get_user_avatar() is not new, the phpbb prefix was prepended. This is due to the fact that it was entirely rewritten and is therefore more or less a completely new function. PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/functions_display.php | 10 +++++----- phpBB/includes/mcp/mcp_notes.php | 4 ++-- phpBB/includes/mcp/mcp_warn.php | 8 ++++---- phpBB/includes/ucp/ucp_groups.php | 2 +- phpBB/includes/ucp/ucp_pm_viewmessage.php | 4 ++-- phpBB/includes/ucp/ucp_profile.php | 4 ++-- phpBB/memberlist.php | 6 +++--- phpBB/viewtopic.php | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index eeeefe03ba..3a72a8c7ef 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -548,7 +548,7 @@ class acp_groups } } - $avatar = get_group_avatar($group_row, 'GROUP_AVATAR', true); + $avatar = phpbb_get_group_avatar($group_row, 'GROUP_AVATAR', true); /* * Merge any avatar errors into the primary error array diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 0c29eb658f..d742cad9f4 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1844,7 +1844,7 @@ class acp_users } } - $avatar = get_user_avatar($user_row, 'USER_AVATAR', true); + $avatar = phpbb_get_user_avatar($user_row, 'USER_AVATAR', true); $template->assign_vars(array( 'S_AVATAR' => true, diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index cf56250296..0a288127a4 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1347,10 +1347,10 @@ 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 phpbb_get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) { $row = phpbb_avatar_manager::clean_row($user_row); - return get_avatar($row, $alt, $ignore_config); + return phpbb_get_avatar($row, $alt, $ignore_config); } /** @@ -1362,10 +1362,10 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false * * @return string Avatar html */ -function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) +function phpbb_get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) { $row = phpbb_avatar_manager::clean_row($user_row); - return get_avatar($row, $alt, $ignore_config); + return phpbb_get_avatar($row, $alt, $ignore_config); } /** @@ -1377,7 +1377,7 @@ function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = fal * * @return string Avatar html */ -function get_avatar($row, $alt, $ignore_config = false) +function phpbb_get_avatar($row, $alt, $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; global $request; diff --git a/phpBB/includes/mcp/mcp_notes.php b/phpBB/includes/mcp/mcp_notes.php index 0b00d77d8f..12fcbfe91e 100644 --- a/phpBB/includes/mcp/mcp_notes.php +++ b/phpBB/includes/mcp/mcp_notes.php @@ -173,13 +173,13 @@ class mcp_notes } // Generate the appropriate user information for the user we are looking at - if (!function_exists('get_user_avatar')) + if (!function_exists('phpbb_get_user_avatar')) { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } $rank_title = $rank_img = ''; - $avatar_img = get_user_avatar($userrow); + $avatar_img = phpbb_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 f88ac3803f..4ef477775d 100644 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -304,13 +304,13 @@ class mcp_warn $message = smiley_text($message); // Generate the appropriate user information for the user we are looking at - if (!function_exists('get_user_avatar')) + if (!function_exists('phpbb_get_user_avatar')) { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } get_user_rank($user_row['user_rank'], $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); - $avatar_img = get_user_avatar($user_row); + $avatar_img = phpbb_get_user_avatar($user_row); $template->assign_vars(array( 'U_POST_ACTION' => $this->u_action, @@ -409,13 +409,13 @@ class mcp_warn } // Generate the appropriate user information for the user we are looking at - if (!function_exists('get_user_avatar')) + if (!function_exists('phpbb_get_user_avatar')) { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } get_user_rank($user_row['user_rank'], $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); - $avatar_img = get_user_avatar($user_row); + $avatar_img = phpbb_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 9b83688a2c..b3e07cc7b9 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 = get_group_avatar($group_row, 'GROUP_AVATAR', true); + $avatar = phpbb_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, diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index 42b63f8ce1..712032463f 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -371,12 +371,12 @@ function get_user_information($user_id, $user_row) } } - if (!function_exists('get_user_avatar')) + if (!function_exists('phpbb_get_user_avatar')) { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - $user_row['avatar'] = ($user->optionget('viewavatars')) ? get_user_avatar($user_row) : ''; + $user_row['avatar'] = ($user->optionget('viewavatars')) ? phpbb_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 3f59cda4a0..598314a035 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -550,7 +550,7 @@ class ucp_profile break; case 'avatar': - if (!function_exists('get_user_avatar')) + if (!function_exists('phpbb_get_user_avatar')) { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } @@ -672,7 +672,7 @@ class ucp_profile } } - $avatar = get_user_avatar($user->data, 'USER_AVATAR', true); + $avatar = phpbb_get_user_avatar($user->data, 'USER_AVATAR', true); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index e389d38fcc..bb2300eb6d 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -549,7 +549,7 @@ switch ($mode) $member['user_sig'] = smiley_text($member['user_sig']); } - $poster_avatar = get_user_avatar($member); + $poster_avatar = phpbb_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; @@ -1234,7 +1234,7 @@ switch ($mode) break; } - $avatar_img = get_group_avatar($group_row); + $avatar_img = phpbb_get_group_avatar($group_row); // ... same for group rank $rank_title = $rank_img = $rank_img_src = ''; @@ -1727,7 +1727,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), + 'AVATAR_IMG' => phpbb_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 594ef5f1c5..59ef7bbc80 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1083,7 +1083,7 @@ while ($row = $db->sql_fetchrow($result)) 'sig_bbcode_bitfield' => '', 'online' => false, - 'avatar' => ($user->optionget('viewavatars')) ? get_user_avatar($row) : '', + 'avatar' => ($user->optionget('viewavatars')) ? phpbb_get_user_avatar($row) : '', 'rank_title' => '', 'rank_image' => '', 'rank_image_src' => '', @@ -1149,7 +1149,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) : '', + 'avatar' => ($user->optionget('viewavatars')) ? phpbb_get_user_avatar($row) : '', 'age' => '', 'rank_title' => '', -- cgit v1.2.1 From 8f8527a416be41ba5f2ac984e944f76817260ed2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Jan 2013 17:23:22 +0100 Subject: [feature/avatars] Improve handling of incorrect input for avatars The upload avatar driver will now inform the user if insufficient data has been entered for both remote and local avatar uploads. The local avatar driver (gallery avatar) will also inform the user if he didn't select a category and/or file before submitting. PHPBB3-10018 --- phpBB/includes/avatar/driver/local.php | 7 +++++++ phpBB/includes/avatar/driver/upload.php | 7 ++++++- phpBB/language/en/common.php | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index d7611b903a..bef5c6d427 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -120,6 +120,13 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver $category = $this->request->variable('avatar_local_cat', ''); $file = $this->request->variable('avatar_local_file', ''); + + if (empty($category) || empty($file)) + { + $error[] = 'NO_AVATAR_SELECTED'; + return false; + } + if (!isset($avatar_list[$category][urldecode($file)])) { $error[] = 'AVATAR_URL_NOT_FOUND'; diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 4facb243ac..1bb86cf158 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -75,10 +75,15 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver { $file = $upload->form_upload('avatar_upload_file'); } - else + elseif (!empty($this->config['allow_avatar_remote_upload']) && !empty($url)) { $file = $upload->remote_upload($url); } + else + { + $error[] = 'NO_AVATAR_SELECTED'; + return false; + } $prefix = $this->config['avatar_salt'] . '_'; $file->clean_filename('avatar', $prefix, $row['id']); diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 02b4443a56..f064dd43ac 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -397,6 +397,7 @@ $lang = array_merge($lang, array( '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_AVATAR_SELECTED' => 'You have not selected any avatar.', '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.', -- cgit v1.2.1 From a342e47038dc62cc824efe688e574a1a7dbb0ac8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Jan 2013 18:13:49 +0100 Subject: [feature/avatars] Change avatar javascript to conform to new coding guidelines PHPBB3-10018 --- phpBB/adm/style/avatars.js | 6 +++--- phpBB/styles/prosilver/template/avatars.js | 6 +++--- phpBB/styles/subsilver2/template/avatars.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB') diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index a53814c15f..26ea24c0db 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -2,14 +2,14 @@ "use strict"; -function avatar_hide() { +function avatarHide() { $('#avatar_options > div').hide(); var selected = $('#avatar_driver').val(); $('#avatar_option_' + selected).show(); } -avatar_hide(); -$('#avatar_driver').bind('change', avatar_hide); +avatarHide(); +$('#avatar_driver').bind('change', avatarHide); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index a53814c15f..26ea24c0db 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -2,14 +2,14 @@ "use strict"; -function avatar_hide() { +function avatarHide() { $('#avatar_options > div').hide(); var selected = $('#avatar_driver').val(); $('#avatar_option_' + selected).show(); } -avatar_hide(); -$('#avatar_driver').bind('change', avatar_hide); +avatarHide(); +$('#avatar_driver').bind('change', avatarHide); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/subsilver2/template/avatars.js b/phpBB/styles/subsilver2/template/avatars.js index 733056a32d..146aca94d3 100644 --- a/phpBB/styles/subsilver2/template/avatars.js +++ b/phpBB/styles/subsilver2/template/avatars.js @@ -2,14 +2,14 @@ "use strict"; -function avatar_hide() { +function avatarHide() { $('.[class^="avatar_option_"]').hide(); var selected = $('#avatar_driver').val(); $('.avatar_option_' + selected).show(); } -avatar_hide(); -$('#avatar_driver').bind('change', avatar_hide); +avatarHide(); +$('#avatar_driver').bind('change', avatarHide); })(jQuery); // Avoid conflicts with other libraries -- cgit v1.2.1 From 111e02395c2879662e2a3d07558519b838ddb69a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 5 Jan 2013 20:17:53 +0100 Subject: [feature/avatars] Add missing docblocks to avatar manager PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 68d1133e86..7c2d03f07b 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -20,9 +20,25 @@ if (!defined('IN_PHPBB')) */ class phpbb_avatar_manager { + /** + * phpBB configuration + */ protected $config; + + /** + * Array that contains a list of enabled drivers + */ static protected $enabled_drivers = false; + + /** + * Array that contains all available avatar drivers which are passed via the + * service container + */ protected $avatar_drivers; + + /** + * Service container object + */ protected $container; /** -- cgit v1.2.1 From 41710c745d5507aa71e25b125b0ae1485cc7ecc1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 6 Jan 2013 21:09:07 +0100 Subject: [feature/avatars] Add function for localizing errors PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 18 ++---------------- phpBB/includes/acp/acp_users.php | 13 +------------ phpBB/includes/avatar/manager.php | 33 +++++++++++++++++++++++++++++---- phpBB/includes/ucp/ucp_groups.php | 14 +------------- phpBB/includes/ucp/ucp_profile.php | 15 ++------------- 5 files changed, 35 insertions(+), 58 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 3a72a8c7ef..d9452a902e 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -550,22 +550,8 @@ class acp_groups $avatar = phpbb_get_group_avatar($group_row, 'GROUP_AVATAR', true); - /* - * 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 $lang) - { - if (is_array($lang)) - { - $key = array_shift($lang); - $error[] = vsprintf($user->lang($key), $lang); - } - else - { - $error[] = $user->lang("$lang"); - } - } + // Merge any avatar errors into the primary error array + $error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error)); $back_link = request_var('back_link', ''); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index d742cad9f4..5960f33741 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1831,18 +1831,7 @@ class acp_users } // Replace "error" strings with their real, localised form - foreach ($error as $key => $lang) - { - if (is_array($lang)) - { - $lang_key = array_shift($lang); - $error[$key] = vsprintf($user->lang($lang_key), $lang); - } - else - { - $error[$key] = $user->lang($lang); - } - } + $error = $phpbb_avatar_manager->localize_errors($user, $error); $avatar = phpbb_get_user_avatar($user_row, 'USER_AVATAR', true); diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 7c2d03f07b..f91b0c4317 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -44,11 +44,7 @@ class phpbb_avatar_manager /** * Construct an avatar manager 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 */ @@ -260,4 +256,33 @@ class phpbb_avatar_manager { return preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); } + + /** + * Replace "error" strings with their real, localized form + * + * @param phpbb_user phpBB User object + * @param array $error Array containing error strings + * 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 localized error strings + */ + public function localize_errors(phpbb_user $user, $error) + { + foreach ($error as $key => $lang) + { + if (is_array($lang)) + { + $lang_key = array_shift($lang); + $error[$key] = vsprintf($user->lang($lang_key), $lang); + } + else + { + $error[$key] = $user->lang("$lang"); + } + } + + return $error; + } } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index b3e07cc7b9..86c02b5bcc 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -674,19 +674,7 @@ 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 $lang) - { - if (is_array($lang)) - { - $key = array_shift($lang); - $error[] = vsprintf($user->lang($key), $lang); - } - else - { - $error[] = $user->lang("$lang"); - } - } + $error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error)); $template->assign_vars(array( 'S_EDIT' => true, diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 598314a035..36d59e7854 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -659,19 +659,8 @@ class ucp_profile } // Replace "error" strings with their real, localised form - foreach ($error as $key => $lang) - { - if (is_array($lang)) - { - $key = array_shift($lang); - $error[$key] = vsprintf($user->lang($key), $lang); - } - else - { - $error[$key] = $user->lang("$lang"); - } - } - + $error = $phpbb_avatar_manager->localize_errors($user, $error); + $avatar = phpbb_get_user_avatar($user->data, 'USER_AVATAR', true); $template->assign_vars(array( -- cgit v1.2.1 From 8867cb60b1f7074c9f83c0403e5259148da65204 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 7 Jan 2013 21:16:39 +0100 Subject: [feature/avatars] Use empty() instead of sizeof() PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index a48d6eda83..3e47cd7c1f 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -140,7 +140,7 @@ class acp_board ) ); - if (sizeof($avatar_vars)) + if (!empty($avatar_vars)) { $display_vars['vars'] += $avatar_vars; } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 5960f33741..122bbeb770 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1837,7 +1837,7 @@ class acp_users $template->assign_vars(array( 'S_AVATAR' => true, - 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', + 'ERROR' => (!empty($error)) ? implode('
', $error) : '', 'AVATAR' => (empty($avatar) ? '' : $avatar), 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', -- cgit v1.2.1 From 023d7a972dd5c279e0b0b24801f9e53e7865d39a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 7 Jan 2013 22:49:48 +0100 Subject: [feature/avatars] Remove $request property and pass as argument if needed Remove the $request property from the phpbb_avatar_driver class and rather pass it as function argument if it's needed in a function. Currently this is only the case for the class methods prepare_form() and process_form(). PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 4 ++-- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/avatar/driver/driver.php | 9 +-------- phpBB/includes/avatar/driver/gravatar.php | 14 +++++++------- phpBB/includes/avatar/driver/interface.php | 6 ++++-- phpBB/includes/avatar/driver/local.php | 10 +++++----- phpBB/includes/avatar/driver/remote.php | 14 +++++++------- phpBB/includes/avatar/driver/upload.php | 8 ++++---- phpBB/includes/ucp/ucp_groups.php | 4 ++-- phpBB/includes/ucp/ucp_profile.php | 4 ++-- 10 files changed, 36 insertions(+), 41 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index d9452a902e..25e199ab32 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -338,7 +338,7 @@ class acp_groups if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { $driver = $phpbb_avatar_manager->get_driver($driver_name); - $result = $driver->process_form($template, $avatar_data, $avatar_error); + $result = $driver->process_form($request, $template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { @@ -532,7 +532,7 @@ class acp_groups 'avatar' => "acp_avatar_options_{$config_name}.html", )); - if ($driver->prepare_form($template, $avatar_data, $avatar_error)) + if ($driver->prepare_form($request, $template, $avatar_data, $avatar_error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 122bbeb770..61b644e9f5 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1751,7 +1751,7 @@ class acp_users if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { $driver = $phpbb_avatar_manager->get_driver($driver_name); - $result = $driver->process_form($template, $avatar_data, $error); + $result = $driver->process_form($request, $template, $avatar_data, $error); if ($result && empty($error)) { @@ -1813,7 +1813,7 @@ class acp_users 'avatar' => "acp_avatar_options_{$config_name}.html", )); - if ($driver->prepare_form($template, $avatar_data, $error)) + if ($driver->prepare_form($request, $template, $avatar_data, $error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index ab89cfbffe..d4f9139c18 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -33,12 +33,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface */ protected $config; - /** - * Request object - * @var phpbb_request - */ - protected $request; - /** * Current $phpbb_root_path * @var string @@ -66,10 +60,9 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface * @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) + public function __construct(phpbb_config $config, $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->php_ext = $php_ext; $this->cache = $cache; diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index c6bfb0d5c1..c574e23836 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -52,11 +52,11 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($template, $row, &$error) + public function prepare_form($request, $template, $row, &$error) { $template->assign_vars(array( - '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_WIDTH' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_width']) ? $row['avatar_width'] : $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'] : $request->variable('avatar_gravatar_width', 0), 'AVATAR_GRAVATAR_EMAIL' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar']) ? $row['avatar'] : '', )); @@ -66,11 +66,11 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($template, $row, &$error) + public function process_form($request, $template, $row, &$error) { - $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); + $row['avatar'] = $request->variable('avatar_gravatar_email', ''); + $row['avatar_width'] = $request->variable('avatar_gravatar_width', 0); + $row['avatar_height'] = $request->variable('avatar_gravatar_height', 0); if (!function_exists('validate_data')) { diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index e8f529f3c4..3c1db019f0 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -50,6 +50,7 @@ interface phpbb_avatar_driver_interface /** * Prepare form for changing the settings of this avatar * + * @param phpbb_request $request Request object * @param phpbb_template $template Template object * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row @@ -60,7 +61,7 @@ interface phpbb_avatar_driver_interface * * @return bool True if form has been successfully prepared */ - public function prepare_form($template, $row, &$error); + public function prepare_form($request, $template, $row, &$error); /** * Prepare form for changing the acp settings of this avatar @@ -74,6 +75,7 @@ interface phpbb_avatar_driver_interface /** * Process form data * + * @param phpbb_request $request Request 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 @@ -85,7 +87,7 @@ interface phpbb_avatar_driver_interface * @return array Array containing the avatar data as follows: * ['avatar'], ['avatar_width'], ['avatar_height'] */ - public function process_form($template, $row, &$error); + public function process_form($request, $template, $row, &$error); /** * Delete avatar diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index bef5c6d427..e49b8dd07f 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -36,10 +36,10 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($template, $row, &$error) + public function prepare_form($request, $template, $row, &$error) { $avatar_list = $this->get_avatar_list(); - $category = $this->request->variable('avatar_local_cat', ''); + $category = $request->variable('avatar_local_cat', ''); foreach ($avatar_list as $cat => $null) { @@ -114,12 +114,12 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($template, $row, &$error) + public function process_form($request, $template, $row, &$error) { $avatar_list = $this->get_avatar_list(); - $category = $this->request->variable('avatar_local_cat', ''); + $category = $request->variable('avatar_local_cat', ''); - $file = $this->request->variable('avatar_local_file', ''); + $file = $request->variable('avatar_local_file', ''); if (empty($category) || empty($file)) { diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 717b73eb0c..e8f182063e 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -36,11 +36,11 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($template, $row, &$error) + public function prepare_form($request, $template, $row, &$error) { $template->assign_vars(array( - '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_WIDTH' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_width']) ? $row['avatar_width'] : $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'] : $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'] : '', )); @@ -50,11 +50,11 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($template, $row, &$error) + public function process_form($request, $template, $row, &$error) { - $url = $this->request->variable('avatar_remote_url', ''); - $width = $this->request->variable('avatar_remote_width', 0); - $height = $this->request->variable('avatar_remote_height', 0); + $url = $request->variable('avatar_remote_url', ''); + $width = $request->variable('avatar_remote_width', 0); + $height = $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 1bb86cf158..6e6956bfde 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -36,7 +36,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($template, $row, &$error) + public function prepare_form($request, $template, $row, &$error) { if (!$this->can_upload()) { @@ -54,7 +54,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($template, $row, &$error) + public function process_form($request, $template, $row, &$error) { if (!$this->can_upload()) { @@ -68,8 +68,8 @@ 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('avatar_upload_url', ''); - $upload_file = $this->request->file('avatar_upload_file'); + $url = $request->variable('avatar_upload_url', ''); + $upload_file = $request->file('avatar_upload_file'); if (!empty($upload_file['name'])) { diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 86c02b5bcc..69cab610fc 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -526,7 +526,7 @@ class ucp_groups if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { $driver = $phpbb_avatar_manager->get_driver($driver_name); - $result = $driver->process_form($template, $avatar_data, $avatar_error); + $result = $driver->process_form($request, $template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { @@ -657,7 +657,7 @@ class ucp_groups 'avatar' => $driver->get_template_name(), )); - if ($driver->prepare_form($template, $avatar_data, $avatar_error)) + if ($driver->prepare_form($request, $template, $avatar_data, $avatar_error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 36d59e7854..518ad9d917 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -576,7 +576,7 @@ class ucp_profile if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { $driver = $phpbb_avatar_manager->get_driver($driver_name); - $result = $driver->process_form($template, $avatar_data, $error); + $result = $driver->process_form($request, $template, $avatar_data, $error); if ($result && empty($error)) { @@ -641,7 +641,7 @@ class ucp_profile 'avatar' => $driver->get_template_name(), )); - if ($driver->prepare_form($template, $avatar_data, $error)) + if ($driver->prepare_form($request, $template, $avatar_data, $error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); -- cgit v1.2.1 From 8778c9c945e388c2b727f1b7cd057dd67a091441 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Jan 2013 15:34:20 +0100 Subject: [feature/avatars] Pass phpbb_user object to get_custom_html() Pass the phpbb_user object to function get_custom_html(). This object is used in that method. Also fixed incorrect arguments to get_custom_html() in phpbb_get_avatar(). PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 2 +- phpBB/includes/avatar/driver/gravatar.php | 2 +- phpBB/includes/avatar/driver/interface.php | 5 ++++- phpBB/includes/functions_display.php | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index d4f9139c18..cb6dbd7d68 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -71,7 +71,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc */ - public function get_custom_html($row, $alt = '') + public function get_custom_html($user, $row, $alt = '') { return ''; } diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index c574e23836..79cac75e28 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -41,7 +41,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * @inheritdoc */ - public function get_custom_html($row, $alt = '') + public function get_custom_html($user, $row, $alt = '') { return 'get_custom_html($row, $ignore_config, $alt); + $html = $driver->get_custom_html($user, $row, $alt); if (!empty($html)) { return $html; -- cgit v1.2.1 From 9e001153d6a64a90353207c4da8b01329f8e39e5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Jan 2013 15:42:30 +0100 Subject: [feature/avatars] Pass phpbb_user object to prepare_form_acp() The phpbb_user object might be used for language variables. Pass it as a function argument to prepare_form_acp() instead of using globals. PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/avatar/driver/driver.php | 2 +- phpBB/includes/avatar/driver/interface.php | 4 +++- phpBB/includes/avatar/driver/local.php | 2 +- phpBB/includes/avatar/driver/upload.php | 4 +--- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 3e47cd7c1f..93e1dd71fe 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -121,7 +121,7 @@ class acp_board * might have. */ $avatar_vars += $phpbb_avatar_manager->get_avatar_settings($driver); - $avatar_vars += $driver->prepare_form_acp(); + $avatar_vars += $driver->prepare_form_acp($user); } $display_vars = array( diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index cb6dbd7d68..e03ef72b3a 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -79,7 +79,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc */ - public function prepare_form_acp() + public function prepare_form_acp($user) { return array(); } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index 836c45b49f..5d6d6b10ac 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -69,11 +69,13 @@ interface phpbb_avatar_driver_interface /** * Prepare form for changing the acp settings of this avatar * + * @param phpbb_user $user phpBB user object + * * @return array Array of configuration options as consumed by acp_board. * The setting for enabling/disabling the avatar will be handled by * the avatar manager. */ - public function prepare_form_acp(); + public function prepare_form_acp($user); /** * Process form data diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index e49b8dd07f..f82c9a6c74 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -104,7 +104,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form_acp() + public function prepare_form_acp($user) { return array( 'avatar_gallery_path' => array('lang' => 'AVATAR_GALLERY_PATH', 'validate' => 'rpath', 'type' => 'text:20:255', 'explain' => true), diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 6e6956bfde..1e3c876299 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -122,10 +122,8 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form_acp() + public function prepare_form_acp($user) { - global $user; - return array( 'allow_avatar_remote_upload'=> array('lang' => 'ALLOW_REMOTE_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'avatar_filesize' => array('lang' => 'MAX_FILESIZE', 'validate' => 'int:0', 'type' => 'text:4:10', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), -- cgit v1.2.1 From cb08bf3c0cac1f15ae46238a00a56ff7bf72efda Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Jan 2013 21:46:43 +0100 Subject: [feature/avatars] Strictly check if avatar list is empty and cache result PHPBB3-10018 --- phpBB/includes/avatar/driver/local.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index f82c9a6c74..b96b602f85 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -142,6 +142,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * Get a list of avatars that are locally available + * Results get cached for 24 hours (86400 seconds) * * @return array Array containing the locally available avatars */ @@ -149,7 +150,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver { $avatar_list = ($this->cache == null) ? false : $this->cache->get('avatar_local_list'); - if (!$avatar_list) + if ($avatar_list === false) { $avatar_list = array(); $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; @@ -185,7 +186,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver if ($this->cache != null) { - $this->cache->put('avatar_local_list', $avatar_list); + $this->cache->put('avatar_local_list', $avatar_list, 86400); } } -- cgit v1.2.1 From 7ea0376958f917c3c62dff7814daaa2fcf330dca Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Jan 2013 22:47:05 +0100 Subject: [feature/avatars] Remove not needed inline style PHPBB3-10018 --- phpBB/adm/style/acp_avatar_options_local.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/adm/style/acp_avatar_options_local.html b/phpBB/adm/style/acp_avatar_options_local.html index 927c4821f7..148efd051b 100644 --- a/phpBB/adm/style/acp_avatar_options_local.html +++ b/phpBB/adm/style/acp_avatar_options_local.html @@ -8,7 +8,7 @@   - +
-- cgit v1.2.1 From 7402add107591ba675bc27248825b7bc9daedee4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 9 Jan 2013 15:50:15 +0100 Subject: [feature/avatars] Add missing @var to docblocks in avatar manager PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index f91b0c4317..4284e2262d 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -22,22 +22,26 @@ class phpbb_avatar_manager { /** * phpBB configuration + * @var phpbb_config */ protected $config; /** * Array that contains a list of enabled drivers + * @var array */ static protected $enabled_drivers = false; /** * Array that contains all available avatar drivers which are passed via the * service container + * @var array */ protected $avatar_drivers; /** * Service container object + * @var object */ protected $container; -- cgit v1.2.1 From 46b75f4cf925ee0da852beeb6c4932e4fcb37992 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 15 Jan 2013 13:20:35 +0100 Subject: [ticket/10411] Add a comment why we left join the group table We left join the group table because we want to check that the group does exist there aswell. PHPBB3-10411 --- phpBB/includes/groupposition/teampage.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB') diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index a189d5def9..2c488dd8a9 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -88,6 +88,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function get_group_value($group_id) { + // The join is required to ensure that the group itself exists $sql = 'SELECT g.group_id, t.teampage_position FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . TEAMPAGE_TABLE . ' t @@ -114,6 +115,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function get_group_values($group_id) { + // The join is required to ensure that the group itself exists $sql = 'SELECT * FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . TEAMPAGE_TABLE . ' t -- cgit v1.2.1 From aeeb85e1cfb9c6a54fc74942e42bc602d2a108a1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 15 Jan 2013 22:07:01 +0100 Subject: [feature/avatars] Remove the obsolete request argument for avatar drivers This should have been removed earlier when the phpbb_request object was dropped from the arguments to the avatar drivers. PHPBB3-10018 --- phpBB/config/avatars.yml | 4 ---- 1 file changed, 4 deletions(-) (limited to 'phpBB') diff --git a/phpBB/config/avatars.yml b/phpBB/config/avatars.yml index e6106038f5..8eef0f837f 100644 --- a/phpBB/config/avatars.yml +++ b/phpBB/config/avatars.yml @@ -3,7 +3,6 @@ services: class: phpbb_avatar_driver_gravatar arguments: - @config - - @request - %core.root_path% - .%core.php_ext% - @cache.driver @@ -16,7 +15,6 @@ services: class: phpbb_avatar_driver_local arguments: - @config - - @request - %core.root_path% - .%core.php_ext% - @cache.driver @@ -29,7 +27,6 @@ services: class: phpbb_avatar_driver_remote arguments: - @config - - @request - %core.root_path% - .%core.php_ext% - @cache.driver @@ -42,7 +39,6 @@ services: class: phpbb_avatar_driver_upload arguments: - @config - - @request - %core.root_path% - .%core.php_ext% - @cache.driver -- cgit v1.2.1 From 84272b1028eb0a30abffa898005c99c4f271888b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 15 Jan 2013 22:13:23 +0100 Subject: [feature/avatars] Move definition of driver_collection to avatars.yml PHPBB3-10018 --- phpBB/config/avatars.yml | 7 +++++++ phpBB/config/services.yml | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB') diff --git a/phpBB/config/avatars.yml b/phpBB/config/avatars.yml index 8eef0f837f..fa0f07372a 100644 --- a/phpBB/config/avatars.yml +++ b/phpBB/config/avatars.yml @@ -46,3 +46,10 @@ services: - [set_name, [avatar.driver.upload]] tags: - { name: avatar.driver } + + avatar.driver_collection: + class: phpbb_di_service_collection + arguments: + - @service_container + tags: + - { name: service_collection, tag: avatar.driver } diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 5107c5597e..6bde65ec49 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -7,13 +7,6 @@ services: auth: class: phpbb_auth - avatar.driver_collection: - class: phpbb_di_service_collection - arguments: - - @service_container - tags: - - { name: service_collection, tag: avatar.driver } - avatar.manager: class: phpbb_avatar_manager arguments: -- cgit v1.2.1 From 79356f54415f901a8ff743817121216cbefb16ee Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 22 Jan 2013 17:21:49 +0100 Subject: [feature/avatars] Add compatibility function for get_user_avatar() PHPBB3-10018 --- phpBB/common.php | 1 + phpBB/includes/functions_compatibility.php | 41 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 phpBB/includes/functions_compatibility.php (limited to 'phpBB') diff --git a/phpBB/common.php b/phpBB/common.php index f502d37c8f..5c0feb87db 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -73,6 +73,7 @@ require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); require($phpbb_root_path . 'includes/functions_container.' . $phpEx); +include($phpbb_root_path . 'includes/functions_compatibility.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php new file mode 100644 index 0000000000..68298449c1 --- /dev/null +++ b/phpBB/includes/functions_compatibility.php @@ -0,0 +1,41 @@ + $avatar, + 'avatar_type' => $avatar_type, + 'avatar_width' => $avatar_width, + 'avatar_height' => $avatar_height, + ); + + return phpbb_get_avatar($row, $alt, $ignore_config); +} -- cgit v1.2.1 From e841453d03003ff0f2c932f5936c17739476ef4f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 22 Jan 2013 21:05:31 +0100 Subject: [feature/avatars] Add note about when compatibility function was added PHPBB3-10018 --- phpBB/includes/functions_compatibility.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index 68298449c1..11ef982a40 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -17,7 +17,8 @@ if (!defined('IN_PHPBB')) /** * Get user avatar -* +* Added in phpBB 3.1.0-A1 +* * @param string $avatar Users assigned avatar name * @param int $avatar_type Type of avatar * @param string $avatar_width Width of users avatar -- cgit v1.2.1 From 869de98f52e636fd5b9f2a9f5b75d665e7009463 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 24 Jan 2013 00:23:45 +0100 Subject: [feature/avatars] Add include of functions_display.php in BC function The needed function phpbb_get_avatar() is defined in includes/functions_display.php. Include that file in the backwards compatible function get_user_avatar(). PHPBB3-10018 --- phpBB/includes/functions_compatibility.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index 11ef982a40..4f96e46417 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -17,7 +17,7 @@ if (!defined('IN_PHPBB')) /** * Get user avatar -* Added in phpBB 3.1.0-A1 +* Compatibility function added: phpBB 3.1.0-A1 * * @param string $avatar Users assigned avatar name * @param int $avatar_type Type of avatar @@ -30,6 +30,8 @@ if (!defined('IN_PHPBB')) */ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false) { + global $phpbb_root_path, $phpEx; + // map arguments to new function phpbb_get_avatar() $row = array( 'avatar' => $avatar, @@ -38,5 +40,10 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ 'avatar_height' => $avatar_height, ); + if (!function_exists('phpbb_get_avatar')) + { + include($phpbb_root_path . 'includes/functions_display.' . $phpEx); + } + return phpbb_get_avatar($row, $alt, $ignore_config); } -- cgit v1.2.1 From 9c3538eb0e29c491d2f8c15c44c772e29631f4e3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 25 Jan 2013 01:24:15 +0100 Subject: [feature/avatars] Move list of supported formats to avatar driver class Using the regex and turning it into an array if necessary seemed like the cleanest approach to achieve this. PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 5 +++++ phpBB/includes/avatar/driver/local.php | 2 +- phpBB/includes/avatar/driver/remote.php | 2 +- phpBB/includes/avatar/driver/upload.php | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index e03ef72b3a..d7fe915d03 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -51,6 +51,11 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface */ protected $cache; + /** + * Regex for allowed avatar image extensions + */ + const REGEX_ALLOWED_EXT = 'gif|jpg|jpeg|png'; + /** * Construct a driver object * diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index b96b602f85..5132ecd389 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -162,7 +162,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver $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 (preg_match('#^[^&\'"<>]+\.(?:'. self::REGEX_ALLOWED_EXT . ')$#i', $image) && is_file($file_path . '/' . $image)) { if (function_exists('getimagesize')) { diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index e8f182063e..9b481f983e 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -84,7 +84,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver // 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)) + if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.('. self::REGEX_ALLOWED_EXT . ')$#i', $url)) { $error[] = 'AVATAR_URL_INVALID'; return false; diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 1e3c876299..ae39eb6920 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -66,7 +66,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver include($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); } - $upload = new fileupload('AVATAR_', 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)); + $upload = new fileupload('AVATAR_', explode('|', self::REGEX_ALLOWED_EXT), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); $url = $request->variable('avatar_upload_url', ''); $upload_file = $request->file('avatar_upload_file'); -- cgit v1.2.1 From f322f4eac923a960e6b6ff44c27783000affb3ee Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 3 Feb 2013 23:02:35 +0100 Subject: [feature/avatars] Correct license, copyright and package info PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 6 +++--- phpBB/includes/avatar/driver/gravatar.php | 8 ++++---- phpBB/includes/avatar/driver/interface.php | 6 +++--- phpBB/includes/avatar/driver/local.php | 6 +++--- phpBB/includes/avatar/driver/remote.php | 6 +++--- phpBB/includes/avatar/driver/upload.php | 6 +++--- phpBB/includes/avatar/manager.php | 4 ++-- phpBB/includes/functions_compatibility.php | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index d7fe915d03..5a54c3ee37 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -1,9 +1,9 @@ Date: Sun, 3 Feb 2013 23:06:30 +0100 Subject: [feature/avatars] Use deprecated for compatibility function Also moved use of global variables inside the only if statement they are used in. PHPBB3-10018 --- phpBB/includes/functions_compatibility.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index b0655ff291..2197815087 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -17,8 +17,9 @@ if (!defined('IN_PHPBB')) /** * Get user avatar -* Compatibility function added: phpBB 3.1.0-A1 -* +* +* @deprecated 3.1.0-a1 (To be removed: 3.3.0) +* * @param string $avatar Users assigned avatar name * @param int $avatar_type Type of avatar * @param string $avatar_width Width of users avatar @@ -30,8 +31,6 @@ if (!defined('IN_PHPBB')) */ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false) { - global $phpbb_root_path, $phpEx; - // map arguments to new function phpbb_get_avatar() $row = array( 'avatar' => $avatar, @@ -42,6 +41,8 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ if (!function_exists('phpbb_get_avatar')) { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } -- cgit v1.2.1 From 5a4da46f9bdadbd1744f78b39c68184b317df60b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 6 Feb 2013 23:47:14 +0100 Subject: [feature/avatars] Use array for allowed extensions and implode if needed PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 7 ++++++- phpBB/includes/avatar/driver/local.php | 2 +- phpBB/includes/avatar/driver/remote.php | 2 +- phpBB/includes/avatar/driver/upload.php | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 5a54c3ee37..a116155fd3 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -54,7 +54,12 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * Regex for allowed avatar image extensions */ - const REGEX_ALLOWED_EXT = 'gif|jpg|jpeg|png'; + protected $allowed_extensions = array( + 'gif', + 'jpg', + 'jpeg', + 'png', + ); /** * Construct a driver object diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index a789cd391d..9049cadea8 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -162,7 +162,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver $image = $file_info->getFilename(); // Match all images in the gallery folder - if (preg_match('#^[^&\'"<>]+\.(?:'. self::REGEX_ALLOWED_EXT . ')$#i', $image) && is_file($file_path . '/' . $image)) + if (preg_match('#^[^&\'"<>]+\.(?:' . implode('|', $this->allowed_extensions) . ')$#i', $image) && is_file($file_path . '/' . $image)) { if (function_exists('getimagesize')) { diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 9845db4b7f..02098f512c 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -84,7 +84,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver // 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]*?).*?\.('. self::REGEX_ALLOWED_EXT . ')$#i', $url)) + if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.('. implode('|', $this->allowed_extensions) . ')$#i', $url)) { $error[] = 'AVATAR_URL_INVALID'; return false; diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 282e0a21ff..56569ec63c 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -66,7 +66,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver include($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); } - $upload = new fileupload('AVATAR_', explode('|', self::REGEX_ALLOWED_EXT), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); + $upload = new fileupload('AVATAR_', $this->allowed_extensions, $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); $url = $request->variable('avatar_upload_url', ''); $upload_file = $request->file('avatar_upload_file'); -- cgit v1.2.1 From f09e6865f70b7b3dfedd2d436396a555a29ebe10 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 13 Feb 2013 01:07:02 +0100 Subject: [feature/avatars] Document the use of the allowed extensions array PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index a116155fd3..29c58d4e62 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -52,7 +52,12 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface protected $cache; /** - * Regex for allowed avatar image extensions + * Array of allowed avatar image extensions + * Array is used for setting the allowed extensions in the fileupload class + * and as a base for a regex of allowed extensions, which will be formed by + * imploding the array with a "|". + * + * @var array */ protected $allowed_extensions = array( 'gif', -- cgit v1.2.1 From 2302cd7a42004b288c5f6be6d0e4b63fe363a983 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 19 Feb 2013 12:24:21 +0100 Subject: [feature/avatars] Pass phpbb_user to prepare and process form functions The phpbb_user object might be used for language variables and other things. PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 4 ++-- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/avatar/driver/gravatar.php | 4 ++-- phpBB/includes/avatar/driver/interface.php | 6 ++++-- phpBB/includes/avatar/driver/local.php | 4 ++-- phpBB/includes/avatar/driver/remote.php | 4 ++-- phpBB/includes/avatar/driver/upload.php | 4 ++-- phpBB/includes/ucp/ucp_groups.php | 4 ++-- phpBB/includes/ucp/ucp_profile.php | 4 ++-- 9 files changed, 20 insertions(+), 18 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 92fd466214..483bf47db2 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -338,7 +338,7 @@ class acp_groups if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { $driver = $phpbb_avatar_manager->get_driver($driver_name); - $result = $driver->process_form($request, $template, $avatar_data, $avatar_error); + $result = $driver->process_form($request, $template, $user, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { @@ -532,7 +532,7 @@ class acp_groups 'avatar' => "acp_avatar_options_{$config_name}.html", )); - if ($driver->prepare_form($request, $template, $avatar_data, $avatar_error)) + if ($driver->prepare_form($request, $template, $user, $avatar_data, $avatar_error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 61b644e9f5..88becdb3a5 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1751,7 +1751,7 @@ class acp_users if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { $driver = $phpbb_avatar_manager->get_driver($driver_name); - $result = $driver->process_form($request, $template, $avatar_data, $error); + $result = $driver->process_form($request, $template, $user, $avatar_data, $error); if ($result && empty($error)) { @@ -1813,7 +1813,7 @@ class acp_users 'avatar' => "acp_avatar_options_{$config_name}.html", )); - if ($driver->prepare_form($request, $template, $avatar_data, $error)) + if ($driver->prepare_form($request, $template, $user, $avatar_data, $error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index b54aae94b7..5f4cfcebc6 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -52,7 +52,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($request, $template, $row, &$error) + public function prepare_form($request, $template, $user, $row, &$error) { $template->assign_vars(array( 'AVATAR_GRAVATAR_WIDTH' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_width']) ? $row['avatar_width'] : $request->variable('avatar_gravatar_width', 0), @@ -66,7 +66,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($request, $template, $row, &$error) + public function process_form($request, $template, $user, $row, &$error) { $row['avatar'] = $request->variable('avatar_gravatar_email', ''); $row['avatar_width'] = $request->variable('avatar_gravatar_width', 0); diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index 9364699b5f..6ceb48ad10 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -55,6 +55,7 @@ interface phpbb_avatar_driver_interface * * @param phpbb_request $request Request object * @param phpbb_template $template Template object + * @param phpbb_user $user User object * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row * @param array &$error Reference to an error array that is filled by this @@ -64,7 +65,7 @@ interface phpbb_avatar_driver_interface * * @return bool True if form has been successfully prepared */ - public function prepare_form($request, $template, $row, &$error); + public function prepare_form($request, $template, $user, $row, &$error); /** * Prepare form for changing the acp settings of this avatar @@ -82,6 +83,7 @@ interface phpbb_avatar_driver_interface * * @param phpbb_request $request Request object * @param phpbb_template $template Template object + * @param phpbb_user $user User object * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row * @param array &$error Reference to an error array that is filled by this @@ -92,7 +94,7 @@ interface phpbb_avatar_driver_interface * @return array Array containing the avatar data as follows: * ['avatar'], ['avatar_width'], ['avatar_height'] */ - public function process_form($request, $template, $row, &$error); + public function process_form($request, $template, $user, $row, &$error); /** * Delete avatar diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 9049cadea8..693a0ede47 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -36,7 +36,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($request, $template, $row, &$error) + public function prepare_form($request, $template, $user, $row, &$error) { $avatar_list = $this->get_avatar_list(); $category = $request->variable('avatar_local_cat', ''); @@ -114,7 +114,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($request, $template, $row, &$error) + public function process_form($request, $template, $user, $row, &$error) { $avatar_list = $this->get_avatar_list(); $category = $request->variable('avatar_local_cat', ''); diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 02098f512c..3661e16160 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -36,7 +36,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($request, $template, $row, &$error) + public function prepare_form($request, $template, $user, $row, &$error) { $template->assign_vars(array( 'AVATAR_REMOTE_WIDTH' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_width']) ? $row['avatar_width'] : $request->variable('avatar_remote_width', 0), @@ -50,7 +50,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($request, $template, $row, &$error) + public function process_form($request, $template, $user, $row, &$error) { $url = $request->variable('avatar_remote_url', ''); $width = $request->variable('avatar_remote_width', 0); diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 56569ec63c..f91d170d7c 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -36,7 +36,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc */ - public function prepare_form($request, $template, $row, &$error) + public function prepare_form($request, $template, $user, $row, &$error) { if (!$this->can_upload()) { @@ -54,7 +54,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc */ - public function process_form($request, $template, $row, &$error) + public function process_form($request, $template, $user, $row, &$error) { if (!$this->can_upload()) { diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 9635fcf079..8516682633 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -526,7 +526,7 @@ class ucp_groups if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { $driver = $phpbb_avatar_manager->get_driver($driver_name); - $result = $driver->process_form($request, $template, $avatar_data, $avatar_error); + $result = $driver->process_form($request, $template, $user, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { @@ -657,7 +657,7 @@ class ucp_groups 'avatar' => $driver->get_template_name(), )); - if ($driver->prepare_form($request, $template, $avatar_data, $avatar_error)) + if ($driver->prepare_form($request, $template, $user, $avatar_data, $avatar_error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 518ad9d917..326514aaef 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -576,7 +576,7 @@ class ucp_profile if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { $driver = $phpbb_avatar_manager->get_driver($driver_name); - $result = $driver->process_form($request, $template, $avatar_data, $error); + $result = $driver->process_form($request, $template, $user, $avatar_data, $error); if ($result && empty($error)) { @@ -641,7 +641,7 @@ class ucp_profile 'avatar' => $driver->get_template_name(), )); - if ($driver->prepare_form($request, $template, $avatar_data, $error)) + if ($driver->prepare_form($request, $template, $user, $avatar_data, $error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); -- cgit v1.2.1 From a9e0aea4b1587ac5ff6c94d2dc7e4d05c304423d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 19 Feb 2013 12:30:14 +0100 Subject: [feature/avatars] Remove trailing whitespace from avatar code PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 7 +++---- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/avatar/driver/gravatar.php | 4 ++-- phpBB/includes/avatar/driver/interface.php | 10 +++++----- phpBB/includes/avatar/driver/local.php | 2 +- phpBB/includes/ucp/ucp_profile.php | 6 +++--- 6 files changed, 16 insertions(+), 17 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 483bf47db2..56063759c9 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -329,7 +329,7 @@ class acp_groups { $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0; } - + if ($config['allow_avatar']) { // Handle avatar @@ -343,7 +343,6 @@ class acp_groups if ($result && empty($avatar_error)) { $result['avatar_type'] = $driver_name; - $submit_ary = array_merge($submit_ary, $result); } } @@ -547,9 +546,9 @@ class acp_groups } } } - + $avatar = phpbb_get_group_avatar($group_row, 'GROUP_AVATAR', true); - + // Merge any avatar errors into the primary error array $error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error)); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 88becdb3a5..8f4a22b61f 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1786,7 +1786,7 @@ class acp_users 'user_avatar_width' => 0, 'user_avatar_height' => 0, ); - + $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' WHERE user_id = ' . (int) $user_id; @@ -1843,7 +1843,7 @@ class acp_users 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', '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), )); diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 5f4cfcebc6..2e2ae2071f 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -37,7 +37,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver 'height' => $row['avatar_height'], ); } - + /** * @inheritdoc */ @@ -126,7 +126,7 @@ 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']) diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index 6ceb48ad10..3d62969aef 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -31,7 +31,7 @@ interface phpbb_avatar_driver_interface /** * Get the avatar url and dimensions * - * @param array $row User data or group data that has been cleaned with + * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row * @return array Avatar data, must have keys src, width and height, e.g. * ['src' => '', 'width' => 0, 'height' => 0] @@ -42,7 +42,7 @@ interface phpbb_avatar_driver_interface * Returns custom html if it is needed for displaying this avatar * * @param phpbb_user $user phpBB user object - * @param array $row 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 * @param string $alt Alternate text for avatar image * @@ -56,7 +56,7 @@ interface phpbb_avatar_driver_interface * @param phpbb_request $request Request object * @param phpbb_template $template Template object * @param phpbb_user $user User object - * @param array $row 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 * @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 @@ -84,7 +84,7 @@ interface phpbb_avatar_driver_interface * @param phpbb_request $request Request object * @param phpbb_template $template Template object * @param phpbb_user $user User object - * @param array $row 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 * @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 @@ -99,7 +99,7 @@ interface phpbb_avatar_driver_interface /** * Delete avatar * - * @param array $row 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, diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 693a0ede47..7237c745d6 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 'SELECTED' => ($cat == $category), )); } - + if ($cat != $category) { unset($avatar_list[$cat]); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 326514aaef..d2507e5dbd 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -593,7 +593,7 @@ class ucp_profile WHERE user_id = ' . (int) $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); @@ -618,7 +618,7 @@ class ucp_profile WHERE user_id = ' . (int) $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); @@ -670,7 +670,7 @@ class ucp_profile 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(), - + 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), )); -- cgit v1.2.1 From 3cc4746ad3220910b6cbb17772ba594ae26e7c32 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 19 Feb 2013 12:45:08 +0100 Subject: [feature/avatars] Use "Main" as category for avatars in root of gallery Before this change the whole avatar gallery path would show as category. Additionally, the avatars that were selected like that had an incorrect path and didn't show up correctly. With this patch it'll display "Main" as category and properly work. PHPBBB3-10018 --- phpBB/includes/avatar/driver/local.php | 14 ++++++++------ phpBB/language/en/common.php | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 7237c745d6..f4bcd4ce74 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -38,7 +38,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver */ public function prepare_form($request, $template, $user, $row, &$error) { - $avatar_list = $this->get_avatar_list(); + $avatar_list = $this->get_avatar_list($user); $category = $request->variable('avatar_local_cat', ''); foreach ($avatar_list as $cat => $null) @@ -116,7 +116,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver */ public function process_form($request, $template, $user, $row, &$error) { - $avatar_list = $this->get_avatar_list(); + $avatar_list = $this->get_avatar_list($user); $category = $request->variable('avatar_local_cat', ''); $file = $request->variable('avatar_local_file', ''); @@ -134,7 +134,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver } return array( - 'avatar' => $category . '/' . $file, + 'avatar' => ($category != $user->lang['MAIN']) ? $category . '/' . $file : $file, 'avatar_width' => $avatar_list[$category][urldecode($file)]['width'], 'avatar_height' => $avatar_list[$category][urldecode($file)]['height'], ); @@ -144,9 +144,11 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver * Get a list of avatars that are locally available * Results get cached for 24 hours (86400 seconds) * + * @param phpbb_user $user User object + * * @return array Array containing the locally available avatars */ - protected function get_avatar_list() + protected function get_avatar_list($user) { $avatar_list = ($this->cache == null) ? false : $this->cache->get('avatar_local_list'); @@ -172,9 +174,9 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver { $dims = array(0, 0); } - $cat = str_replace("$path/", '', $file_path); + $cat = ($path == $file_path) ? $user->lang['MAIN'] : str_replace("$path/", '', $file_path); $avatar_list[$cat][$image] = array( - 'file' => rawurlencode($cat) . '/' . rawurlencode($image), + 'file' => ($cat != $user->lang['MAIN']) ? rawurlencode($cat) . '/' . rawurlencode($image) : rawurlencode($image), 'filename' => rawurlencode($image), 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), 'width' => $dims[0], diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 6c723a5060..7758d0af16 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -358,6 +358,7 @@ $lang = array_merge($lang, array( 'LOGOUT_USER' => 'Logout [ %s ]', 'LOG_ME_IN' => 'Remember me', + 'MAIN' => 'Main', 'MARK' => 'Mark', 'MARK_ALL' => 'Mark all', 'MARK_FORUMS_READ' => 'Mark forums read', -- cgit v1.2.1 From 12cc64e715cd87af0195e0abc0974eaab459107d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 19:01:35 +0100 Subject: [ticket/10411] Ensure we only get services that do exist PHPBB3-10411 --- phpBB/includes/acp/acp_groups.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 81ae567a8c..fc31105685 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -829,7 +829,7 @@ class acp_groups // Invalid mode trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); } - else if ($field) + else if ($field && in_array($field, array('legend', 'teampage'))) { $group_position = $phpbb_container->get('groupposition.' . $field); -- cgit v1.2.1 From 9ea48dbd45aaa7d239998910feddcc827aaaafe9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:24:11 +0100 Subject: [ticket/10411] Use template loops instead of defining the html in php files PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 22 ++++++++++++++++------ phpBB/includes/acp/acp_groups.php | 18 ++++++++++++------ phpBB/language/en/acp/groups.php | 4 ++-- 3 files changed, 30 insertions(+), 14 deletions(-) (limited to 'phpBB') diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index eb4c3d8819..55bc1b2323 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -39,7 +39,7 @@
- + @@ -150,7 +150,7 @@ {ICON_MOVE_UP_DISABLED}{ICON_MOVE_DOWN_DISABLED} - {ICON_DELETE} + {ICON_DELETE} -- cgit v1.2.1 From 19c3917de985d04f994bc22bcec1e814aa2e207c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 1 Mar 2013 12:46:55 +0100 Subject: [ticket/10411] Fix call to function on non-object $db->...() PHPBB3-10411 --- phpBB/includes/db/migration/data/310/teampage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/db/migration/data/310/teampage.php b/phpBB/includes/db/migration/data/310/teampage.php index 510ecf9481..4e77da17b7 100644 --- a/phpBB/includes/db/migration/data/310/teampage.php +++ b/phpBB/includes/db/migration/data/310/teampage.php @@ -82,7 +82,7 @@ class phpbb_db_migration_data_310_teampage extends phpbb_db_migration $result = $this->db->sql_query($sql); $teampage_entries = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $teampage_entries[] = array( 'group_id' => (int) $row['group_id'], @@ -91,7 +91,7 @@ class phpbb_db_migration_data_310_teampage extends phpbb_db_migration 'teampage_parent' => 0, ); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (sizeof($teampage_entries)) { -- cgit v1.2.1 From e1bb76eb096673af9e106f4cbd6e328c2b4bfdb6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 4 Mar 2013 00:25:38 +0100 Subject: [feature/avatars] Reduce module auth of ucp avatar settings Previously the avatar types that need to be enabled were hardcoded into the module auth. This is no longer needed in the new avatar system. PHPBB3-10018 --- phpBB/includes/ucp/info/ucp_profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/ucp/info/ucp_profile.php b/phpBB/includes/ucp/info/ucp_profile.php index 98ab0597ff..e974cea713 100644 --- a/phpBB/includes/ucp/info/ucp_profile.php +++ b/phpBB/includes/ucp/info/ucp_profile.php @@ -21,7 +21,7 @@ class ucp_profile_info 'modes' => array( 'profile_info' => array('title' => 'UCP_PROFILE_PROFILE_INFO', 'auth' => 'acl_u_chgprofileinfo', 'cat' => array('UCP_PROFILE')), 'signature' => array('title' => 'UCP_PROFILE_SIGNATURE', 'auth' => 'acl_u_sig', 'cat' => array('UCP_PROFILE')), - 'avatar' => array('title' => 'UCP_PROFILE_AVATAR', '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)', 'cat' => array('UCP_PROFILE')), + 'avatar' => array('title' => 'UCP_PROFILE_AVATAR', 'auth' => 'cfg_allow_avatar', 'cat' => array('UCP_PROFILE')), 'reg_details' => array('title' => 'UCP_PROFILE_REG_DETAILS', 'auth' => '', 'cat' => array('UCP_PROFILE')), 'autologin_keys'=> array('title' => 'UCP_PROFILE_AUTOLOGIN_KEYS', 'auth' => '', 'cat' => array('UCP_PROFILE')), ), -- cgit v1.2.1 From c7ca4e445c7dc6c775e27597cd7b0968fa5fd904 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 4 Mar 2013 01:04:36 +0100 Subject: [feature/avatars] Add migrations data file for avatars The module_auth of the ucp avatar settings are used for checking if the migration has already been installed. PHPBB3-10018 --- phpBB/includes/db/migration/data/310/avatars.php | 64 ++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 phpBB/includes/db/migration/data/310/avatars.php (limited to 'phpBB') diff --git a/phpBB/includes/db/migration/data/310/avatars.php b/phpBB/includes/db/migration/data/310/avatars.php new file mode 100644 index 0000000000..de11a64556 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/avatars.php @@ -0,0 +1,64 @@ +db->sql_query($sql); + $module_auth = $this->db->sql_fetchfield('module_auth'); + $this->db->sql_freeresult($result); + return ($module_auth == 'cfg_allow_avatar'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11'); + } + + public function update_schema() + { + return array( + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_avatar_type' => array('VCHAR:255', ''), + ), + $this->table_prefix . 'groups' => array( + 'group_avatar_type' => array('VCHAR:255', ''), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_avatar_type' => array('TINT:2', ''), + ), + $this->table_prefix . 'groups' => array( + 'group_avatar_type' => array('TINT:2', ''), + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.add', array('allow_avatar_gravatar', 0)), + ); + } +} -- cgit v1.2.1 From 9dfc5fbf9a8b866bea38efa5217417e6ef341bf1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 20:47:14 -0600 Subject: [ticket/11395] Prevent acp_modules::get_modules_info from reincluding files PHPBB3-11395 --- phpBB/includes/acp/acp_modules.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index fce26bf45f..7c2ea86122 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -600,11 +600,11 @@ class acp_modules if (!class_exists($info_class)) { - if (file_exists($directory . $module . '.' . $phpEx)) + $info_class = $module . '_info'; + if (!class_exists($info_class) && file_exists($directory . $module . '.' . $phpEx)) { include($directory . $module . '.' . $phpEx); } - $info_class = $module . '_info'; } // Get module title tag -- cgit v1.2.1 From ae15fabb323c8f76ad2c8c994c2d205aabeafcbe Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 20:59:21 -0600 Subject: [ticket/11396] Rename insert_migration to set_migration_state PHPBB3-11396 --- phpBB/includes/db/migrator.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index de9c06948c..7b5e8cb2de 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -174,7 +174,7 @@ class phpbb_db_migrator 'migration_start_time' => time(), 'migration_end_time' => time(), ); - $this->insert_migration($name, $state); + $this->set_migration_state($name, $state); } } @@ -350,7 +350,7 @@ class phpbb_db_migrator } } - $this->insert_migration($name, $state); + $this->set_migration_state($name, $state); return true; } @@ -422,7 +422,7 @@ class phpbb_db_migrator $state['migration_data_done'] = ($result === true) ? false : true; } - $this->insert_migration($name, $state); + $this->set_migration_state($name, $state); } else { @@ -641,7 +641,7 @@ class phpbb_db_migrator * @param array $state * @return null */ - protected function insert_migration($name, $state) + protected function set_migration_state($name, $state) { $migration_row = $state; $migration_row['migration_depends_on'] = serialize($state['migration_depends_on']); -- cgit v1.2.1 From 2e2ddd7e85034f747d5dd312803aadfc47ac80e2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 4 Mar 2013 10:30:49 +0100 Subject: [feature/avatars] Update module_auth of ucp module and fix small issues Reduced the check effectively_installed() to just checking for the config entry "allow_avatar_gravatar". Also added the missing update of the module_auth of the ucp_profile avatar mode. PHPBB3-10018 --- phpBB/includes/db/migration/data/310/avatars.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/db/migration/data/310/avatars.php b/phpBB/includes/db/migration/data/310/avatars.php index de11a64556..79547337f7 100644 --- a/phpBB/includes/db/migration/data/310/avatars.php +++ b/phpBB/includes/db/migration/data/310/avatars.php @@ -11,15 +11,7 @@ class phpbb_db_migration_data_310_avatars extends phpbb_db_migration { public function effectively_installed() { - $sql = 'SELECT module_auth - FROM ' . MODULES_TABLE . " - WHERE module_class = 'ucp' - AND module_basename = 'ucp_profile' - AND module_mode = 'avatar'"; - $result = $this->db->sql_query($sql); - $module_auth = $this->db->sql_fetchfield('module_auth'); - $this->db->sql_freeresult($result); - return ($module_auth == 'cfg_allow_avatar'); + return isset($this->config['allow_avatar_gravatar']); } static public function depends_on() @@ -59,6 +51,17 @@ class phpbb_db_migration_data_310_avatars extends phpbb_db_migration { return array( array('config.add', array('allow_avatar_gravatar', 0)), + array('custom', array(array($this, 'update_module_auth'))), ); } + + public function update_module_auth() + { + $sql = 'UPDATE ' . $this->table_prefix . "modules + SET module_auth = 'cfg_allow_avatar' + WHERE module_class = 'ucp' + AND module_basename = 'ucp_profile' + AND module_mode = 'avatar'"; + $this->db->sql_query($sql); + } } -- cgit v1.2.1
{legend.GROUP_NAME} style="color: {legend.GROUP_COLOUR}">{legend.GROUP_NAME} {legend.GROUP_TYPE} @@ -68,7 +68,12 @@
- + {S_FORM_TOKEN} @@ -126,7 +131,7 @@ {teampage.GROUP_NAME} - {teampage.GROUP_NAME} + style="color: {teampage.GROUP_COLOUR}">{teampage.GROUP_NAME}
{teampage.GROUP_TYPE}- @@ -159,8 +164,8 @@
- - + + {S_FORM_TOKEN}
@@ -169,7 +174,12 @@
- + {S_FORM_TOKEN} diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index fc31105685..46b5a0fa4a 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -916,7 +916,7 @@ class acp_groups { $template->assign_block_vars('legend', array( 'GROUP_NAME' => $group_name, - 'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '', + 'GROUP_COLOUR' => ($row['group_colour']) ? '#' . $row['group_colour'] : '', 'GROUP_TYPE' => $user->lang[phpbb_groupposition_legend::group_type_language($row['group_type'])], 'U_MOVE_DOWN' => "{$this->u_action}&field=legend&action=move_down&g=" . $row['group_id'], @@ -926,7 +926,11 @@ class acp_groups } else { - $s_group_select_legend .= '' . $group_name . ''; + $template->assign_block_vars('add_legend', array( + 'GROUP_ID' => (int) $row['group_id'], + 'GROUP_NAME' => $group_name, + 'GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL), + )); } } $db->sql_freeresult($result); @@ -966,7 +970,7 @@ class acp_groups $template->assign_block_vars('teampage', array( 'GROUP_NAME' => $group_name, - 'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '', + 'GROUP_COLOUR' => ($row['group_colour']) ? '#' . $row['group_colour'] : '', 'GROUP_TYPE' => $group_type, 'U_CATEGORY' => (!$row['group_id']) ? "{$this->u_action}&c=" . $row['teampage_id'] : '', @@ -989,7 +993,11 @@ class acp_groups while ($row = $db->sql_fetchrow($result)) { $group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; - $s_group_select_teampage .= '' . $group_name . ''; + $template->assign_block_vars('add_teampage', array( + 'GROUP_ID' => (int) $row['group_id'], + 'GROUP_NAME' => $group_name, + 'GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL), + )); } $db->sql_freeresult($result); @@ -999,8 +1007,6 @@ class acp_groups 'U_ACTION_TEAMPAGE' => $this->u_action . '&field=teampage' . $category_url_param, 'U_ACTION_TEAMPAGE_CAT' => $this->u_action . '&field=teampage_cat', - 'S_GROUP_SELECT_LEGEND' => $s_group_select_legend, - 'S_GROUP_SELECT_TEAMPAGE' => $s_group_select_teampage, 'S_TEAMPAGE_CATEGORY' => $category_id, 'DISPLAY_FORUMS' => ($config['teampage_forums']) ? true : false, 'DISPLAY_MEMBERSHIPS' => $config['teampage_memberships'], diff --git a/phpBB/language/en/acp/groups.php b/phpBB/language/en/acp/groups.php index 18e5cbaa1d..58101e5f60 100644 --- a/phpBB/language/en/acp/groups.php +++ b/phpBB/language/en/acp/groups.php @@ -36,14 +36,13 @@ if (empty($lang) || !is_array($lang)) $lang = array_merge($lang, array( 'ACP_GROUPS_MANAGE_EXPLAIN' => 'From this panel you can administer all your usergroups. You can delete, create and edit existing groups. Furthermore, you may choose group leaders, toggle open/hidden/closed group status and set the group name and description.', - 'ADD_CATEGORY' => 'Add category', + 'ADD_GROUP_CATEGORY' => 'Add category', 'ADD_USERS' => 'Add users', 'ADD_USERS_EXPLAIN' => 'Here you can add new users to the group. You may select whether this group becomes the new default for the selected users. Additionally you can define them as group leaders. Please enter each username on a separate line.', 'COPY_PERMISSIONS' => 'Copy permissions from', 'COPY_PERMISSIONS_EXPLAIN' => 'Once created, the group will have the same permissions as the one you select here.', 'CREATE_GROUP' => 'Create new group', - 'CATEGORY_NAME' => 'Category name', 'GROUPS_NO_MEMBERS' => 'This group has no members', 'GROUPS_NO_MODS' => 'No group leaders defined', @@ -52,6 +51,7 @@ $lang = array_merge($lang, array( 'GROUP_APPROVED' => 'Approved members', 'GROUP_AVATAR' => 'Group avatar', 'GROUP_AVATAR_EXPLAIN' => 'This image will be displayed in the Group Control Panel.', + 'GROUP_CATEGORY_NAME' => 'Category name', 'GROUP_CLOSED' => 'Closed', 'GROUP_COLOR' => 'Group colour', 'GROUP_COLOR_EXPLAIN' => 'Defines the colour members’ usernames will appear in, leave blank for user default.', -- cgit v1.2.1 From b0dc5925b91cb0447046e8a7f089c6675e4be95c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:29:04 +0100 Subject: [ticket/10411] Fix typehinting and change private to protected PHPBB3-10411 --- phpBB/includes/groupposition/legend.php | 14 +++++++------- phpBB/includes/groupposition/teampage.php | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 4dcf31ff06..51f2510e85 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -32,28 +32,28 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface /** * Database object - * @var dbal + * @var phpbb_db_driver */ - private $db = null; + protected $db; /** * User object * @var phpbb_user */ - private $user = null; + protected $user; /** * URI for the adm_back_link when there was an error. */ - private $adm_back_link = ''; + protected $adm_back_link = ''; /** * Constructor * - * @param dbal $db Database object - * @param phpbb_user $user User object + * @param phpbb_db_driver $db Database object + * @param phpbb_user $user User object */ - public function __construct(dbal $db, phpbb_user $user) + public function __construct(phpbb_db_driver $db, phpbb_user $user) { $this->db = $db; $this->user = $user; diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index 2c488dd8a9..f13e171134 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -36,35 +36,35 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface /** * Database object - * @var dbal + * @var phpbb_db_driver */ - private $db = null; + protected $db; /** * User object * @var phpbb_user */ - private $user = null; + protected $user; /** * Cache object * @var phpbb_cache_driver_interface */ - private $cache = null; + protected $cache; /** * URI for the adm_back_link when there was an error. */ - private $adm_back_link = ''; + protected $adm_back_link = ''; /** * Constructor * - * @param dbal $db Database object + * @param phpbb_db_driver $db Database object * @param phpbb_user $user User object * @param phpbb_cache_driver_interface $cache Cache object */ - public function __construct(dbal $db, phpbb_user $user, phpbb_cache_driver_interface $cache) + public function __construct(phpbb_db_driver $db, phpbb_user $user, phpbb_cache_driver_interface $cache) { $this->db = $db; $this->user = $user; -- cgit v1.2.1 From 1d7b082a6fa05d5760ef15ef8bf78cd3a1d204cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:58:12 +0100 Subject: [ticket/10411] Add return value to move functions PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 6 ++--- phpBB/includes/groupposition/legend.php | 15 +++++++++---- phpBB/includes/groupposition/teampage.php | 36 +++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 18 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php index 749ad61071..6fb16134e0 100644 --- a/phpBB/includes/groupposition/interface.php +++ b/phpBB/includes/groupposition/interface.php @@ -59,7 +59,7 @@ interface phpbb_groupposition_interface * Moves a group up by group_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_up($group_id); @@ -67,7 +67,7 @@ interface phpbb_groupposition_interface * Moves a group down by group_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_down($group_id); @@ -78,7 +78,7 @@ interface phpbb_groupposition_interface * @param int $delta number of steps: * - positive = move up * - negative = move down - * @return null + * @return bool True if the group was moved successfully */ public function move($group_id, $delta); } diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 51f2510e85..9b69f9d2b3 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -168,7 +168,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface */ public function move_up($group_id) { - $this->move($group_id, 1); + return $this->move($group_id, 1); } /** @@ -178,7 +178,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface */ public function move_down($group_id) { - $this->move($group_id, -1); + return $this->move($group_id, -1); } /** @@ -188,9 +188,10 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface */ public function move($group_id, $delta) { - if (!is_int($delta) || !$delta) + $delta = (int) $delta; + if (!$delta) { - return; + return false; } $move_up = ($delta > 0) ? true : false; @@ -221,10 +222,16 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface SET group_legend = group_legend ' . (($move_up) ? ' - ' : ' + ') . $delta . ' WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + + return true; } $this->db->sql_transaction('commit'); } + + return false; } /** diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index f13e171134..cbdf06ebaf 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -359,18 +359,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function move_up($group_id) { - $this->move($group_id, 1); + return $this->move($group_id, 1); } /** * Moves an item up by teampage_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_up_teampage($teampage_id) { - $this->move_teampage($teampage_id, 1); + return $this->move_teampage($teampage_id, 1); } /** @@ -380,18 +380,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function move_down($group_id) { - $this->move($group_id, -1); + return $this->move($group_id, -1); } /** * Movesan item down by teampage_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_down_teampage($teampage_id) { - $this->move_teampage($teampage_id, -1); + return $this->move_teampage($teampage_id, -1); } /** @@ -401,9 +401,10 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function move($group_id, $delta) { - if (!is_int($delta) || !$delta) + $delta = (int) $delta; + if (!$delta) { - return; + return false; } $move_up = ($delta > 0) ? true : false; @@ -463,12 +464,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface SET teampage_position = teampage_position ' . (($move_up) ? ' - ' : ' + ') . abs($delta) . ' WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + $this->cache->destroy('sql', TEAMPAGE_TABLE); + + return true; } $this->db->sql_transaction('commit'); } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** @@ -478,13 +485,14 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * @param int $delta number of steps: * - positive = move up * - negative = move down - * @return null + * @return bool True if the group was moved successfully */ public function move_teampage($teampage_id, $delta) { - if (!is_int($delta) || !$delta) + $delta = (int) $delta; + if (!$delta) { - return; + return false; } $move_up = ($delta > 0) ? true : false; @@ -559,12 +567,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface WHERE teampage_id = ' . (int) $teampage_id . ' OR teampage_parent = ' . (int) $teampage_id; $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + $this->cache->destroy('sql', TEAMPAGE_TABLE); + + return true; } $this->db->sql_transaction('commit'); } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** -- cgit v1.2.1 From 41eea66da975a3b4140d8f4dc3f6931ea84916db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 21:24:52 +0100 Subject: [ticket/10411] Add return values to add/delete function PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 4 ++-- phpBB/includes/groupposition/legend.php | 7 +++++++ phpBB/includes/groupposition/teampage.php | 23 ++++++++++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php index 6fb16134e0..eacc04e1a4 100644 --- a/phpBB/includes/groupposition/interface.php +++ b/phpBB/includes/groupposition/interface.php @@ -42,7 +42,7 @@ interface phpbb_groupposition_interface * Addes a group by group_id * * @param int $group_id group_id of the group to be added - * @return null + * @return bool True if the group was added successfully */ public function add_group($group_id); @@ -51,7 +51,7 @@ interface phpbb_groupposition_interface * * @param int $group_id group_id of the group to be deleted * @param bool $skip_group Skip setting the value for this group, to save the query, when you need to update it anyway. - * @return null + * @return bool True if the group was deleted successfully */ public function delete_group($group_id, $skip_group = false); diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 9b69f9d2b3..8f115a8b1e 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -128,7 +128,10 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface WHERE group_legend = ' . self::GROUP_DISABLED . ' AND group_id = ' . (int) $group_id; $this->db->sql_query($sql); + return true; } + + return false; } /** @@ -158,7 +161,11 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface } $this->db->sql_transaction('commit'); + + return true; } + + return false; } /** diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index cbdf06ebaf..3be8ef2774 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -207,7 +207,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function add_group($group_id) { - $this->add_group_teampage($group_id, self::NO_PARENT); + return $this->add_group_teampage($group_id, self::NO_PARENT); } /** @@ -215,7 +215,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * * @param int $group_id group_id of the group to be added * @param int $parent_id Teampage ID of the parent item - * @return null + * @return bool True if the group was added successfully */ public function add_group_teampage($group_id, $parent_id) { @@ -266,22 +266,26 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** * Adds a new category * * @param string $category_name Name of the category to be added - * @return null + * @return bool True if the category was added successfully */ public function add_category_teampage($category_name) { if ($category_name === '') { - return; + return false; } $num_entries = $this->get_group_count(); @@ -297,6 +301,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $this->db->sql_query($sql); $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } /** @@ -318,9 +323,13 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $sql = 'DELETE FROM ' . TEAMPAGE_TABLE . ' WHERE group_id = ' . $group_id; $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** @@ -328,7 +337,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * * @param int $teampage_id teampage_id of the item to be deleted * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. - * @return null + * @return bool True if the item was deleted successfully */ public function delete_teampage($teampage_id, $skip_group = false) { @@ -347,9 +356,13 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface SET teampage_position = teampage_position - ' . $delta . ' WHERE teampage_position > ' . $current_value; $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** -- cgit v1.2.1 From e0df5934485df0eee22141d1c5ded3e432119b20 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 16:52:53 +0100 Subject: [ticket/10411] Throw exceptions instead of using trigger_error() PHPBB3-10411 --- phpBB/includes/groupposition/exception.php | 23 +++++++++++++++++++++ phpBB/includes/groupposition/legend.php | 27 +----------------------- phpBB/includes/groupposition/teampage.php | 33 ++++-------------------------- 3 files changed, 28 insertions(+), 55 deletions(-) create mode 100644 phpBB/includes/groupposition/exception.php (limited to 'phpBB') diff --git a/phpBB/includes/groupposition/exception.php b/phpBB/includes/groupposition/exception.php new file mode 100644 index 0000000000..e4ff09c703 --- /dev/null +++ b/phpBB/includes/groupposition/exception.php @@ -0,0 +1,23 @@ +user = $user; } - /** - * Set the back link for error messages - * - * @param string $adm_back_link Return URL to use after an error occured - */ - public function set_admin_back_link($adm_back_link) - { - $this->adm_back_link = $adm_back_link; - } - /** * Returns the group_legend for a given group, if the group exists. * @@ -86,7 +71,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface if ($current_value === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return (int) $current_value; @@ -241,16 +226,6 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface return false; } - /** - * Error - * - * {@inheritDoc} - */ - private function error($message) - { - trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); - } - /** * Get group type language var * diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index 3be8ef2774..7c758199e7 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -52,11 +52,6 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ protected $cache; - /** - * URI for the adm_back_link when there was an error. - */ - protected $adm_back_link = ''; - /** * Constructor * @@ -71,16 +66,6 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $this->cache = $cache; } - /** - * Set the back link for error messages - * - * @param string $adm_back_link Return URL to use after an error occured - */ - public function set_admin_back_link($adm_back_link) - { - $this->adm_back_link = $adm_back_link; - } - /** * Returns the teampage position for a given group, if the group exists. * @@ -101,7 +86,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($row === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return (int) $row['teampage_position']; @@ -128,7 +113,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($row === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return $row; @@ -152,7 +137,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($current_value === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return (int) $current_value; @@ -176,7 +161,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($row === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return $row; @@ -594,16 +579,6 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface return false; } - /** - * Error - * - * {@inheritDoc} - */ - private function error($message) - { - trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); - } - /** * Get group type language var * -- cgit v1.2.1 From 9e70f7a4e0e419984ad5dd0392857ecd810ad252 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 16:53:51 +0100 Subject: [ticket/10411] Catch exceptions from grouppositions PHPBB3-10411 --- phpBB/includes/acp/acp_groups.php | 73 ++++++++++++++++++++-------------- phpBB/includes/functions_user.php | 84 ++++++++++++++++++++++++++++++--------- 2 files changed, 108 insertions(+), 49 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 805fc28520..17145508aa 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -851,53 +851,66 @@ class acp_groups { $group_position = $phpbb_container->get('groupposition.' . $field); - $group_position->set_admin_back_link($this->u_action); } if ($field == 'teampage') { - switch ($action) + try { - case 'add': - $group_position->add_group_teampage($group_id, $category_id); - break; + switch ($action) + { + case 'add': + $group_position->add_group_teampage($group_id, $category_id); + break; - case 'add_category': - $group_position->add_category_teampage($request->variable('category_name', '', true)); - break; + case 'add_category': + $group_position->add_category_teampage($request->variable('category_name', '', true)); + break; - case 'delete': - $group_position->delete_teampage($teampage_id); - break; + case 'delete': + $group_position->delete_teampage($teampage_id); + break; - case 'move_up': - $group_position->move_up_teampage($teampage_id); - break; + case 'move_up': + $group_position->move_up_teampage($teampage_id); + break; - case 'move_down': - $group_position->move_down_teampage($teampage_id); - break; + case 'move_down': + $group_position->move_down_teampage($teampage_id); + break; + } + } + catch (phpbb_groupposition_exception $exception) + { + trigger_error($user->lang($exception->getMessage()) . adm_back_link($this->u_action), E_USER_WARNING); } } else if ($field == 'legend') { - switch ($action) + try { - case 'add': - $group_position->add_group($group_id); - break; + switch ($action) + { + case 'add': + $group_position->add_group($group_id); + break; - case 'delete': - $group_position->delete_group($group_id); - break; + case 'delete': + $group_position->delete_group($group_id); + break; - case 'move_up': - $group_position->move_up($group_id); - break; + case 'move_up': + $group_position->move_up($group_id); + break; - case 'move_down': - $group_position->move_down($group_id); - break; + case 'move_down': + $group_position->move_down($group_id); + break; + } + } + catch (phpbb_groupposition_exception $exception) + { + trigger_error($user->lang($exception->getMessage()) . adm_back_link($this->u_action), E_USER_WARNING); } } else diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 379abe4d42..cae83bf203 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2606,8 +2606,15 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $teampage = $phpbb_container->get('groupposition.teampage'); if ($group_id) { - $current_legend = $legend->get_group_value($group_id); - $current_teampage = $teampage->get_group_value($group_id); + try + { + $current_legend = $legend->get_group_value($group_id); + $current_teampage = $teampage->get_group_value($group_id); + } + catch (phpbb_groupposition_exception $exception) + { + trigger_error($user->lang($exception->getMessage())); + } } if (!empty($group_attributes['group_legend'])) @@ -2626,7 +2633,14 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow else if ($group_id && ($current_legend != phpbb_groupposition_legend::GROUP_DISABLED)) { // Group is removed from the legend - $legend->delete_group($group_id, true); + try + { + $legend->delete_group($group_id, true); + } + catch (phpbb_groupposition_exception $exception) + { + trigger_error($user->lang($exception->getMessage())); + } $group_attributes['group_legend'] = phpbb_groupposition_legend::GROUP_DISABLED; } else @@ -2733,7 +2747,14 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow // which is currently displayed. if (!$group_teampage && $group_id && $current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED) { - $teampage->delete_group($group_id); + try + { + $teampage->delete_group($group_id); + } + catch (phpbb_groupposition_exception $exception) + { + trigger_error($user->lang($exception->getMessage())); + } } if (!$group_id) @@ -2746,21 +2767,28 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow } } - if ($group_teampage && $current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) - { - $teampage->add_group($group_id); - } - - if ($group_teampage) + try { - if ($current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) + if ($group_teampage && $current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) { $teampage->add_group($group_id); } + + if ($group_teampage) + { + if ($current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) + { + $teampage->add_group($group_id); + } + } + else if ($group_id && ($current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED)) + { + $teampage->delete_group($group_id); + } } - else if ($group_id && ($current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED)) + catch (phpbb_groupposition_exception $exception) { - $teampage->delete_group($group_id); + trigger_error($user->lang($exception->getMessage())); } unset($teampage); @@ -2887,13 +2915,31 @@ function group_delete($group_id, $group_name = false) while ($start); // Delete group from legend and teampage - $legend = $phpbb_container->get('groupposition.legend'); - $legend->delete_group($group_id); - unset($legend); + try + { + $legend = $phpbb_container->get('groupposition.legend'); + $legend->delete_group($group_id); + unset($legend); + } + catch (phpbb_groupposition_exception $exception) + { + // The group we want to delete does not exist. + // No reason to worry, we just continue the deleting process. + //trigger_error($user->lang($exception->getMessage())); + } - $teampage = $phpbb_container->get('groupposition.teampage'); - $teampage->delete_group($group_id); - unset($teampage); + try + { + $teampage = $phpbb_container->get('groupposition.teampage'); + $teampage->delete_group($group_id); + unset($teampage); + } + catch (phpbb_groupposition_exception $exception) + { + // The group we want to delete does not exist. + // No reason to worry, we just continue the deleting process. + //trigger_error($user->lang($exception->getMessage())); + } // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " -- cgit v1.2.1 From ba97303a60342bdb54979223cc6d18e815a70d90 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 17:17:31 +0100 Subject: [ticket/10411] Add maxlength to category name input field PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index 55bc1b2323..47ff792b54 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -164,7 +164,7 @@
- + {S_FORM_TOKEN} -- cgit v1.2.1 From d61eb95b4868377cfc2a7a98b03a7d908418b1af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 00:12:18 +0100 Subject: [ticket/10411] Revert database_update.php changes from for easier update Revert the changes from 8fc022033a16b50aa07d06af8dc2a2508f0d94a6 * [ticket/10411] Update schema and fix database update The database changes will be added as a migration in the next step PHPBB3-10411 --- phpBB/install/database_update.php | 52 ++++++++++++--------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) (limited to 'phpBB') diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 8592b03be7..0a065573bf 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1165,18 +1165,11 @@ function database_update_info() 'ext_name' => array('UNIQUE', 'ext_name'), ), ), - TEAMPAGE_TABLE => array( - 'COLUMNS' => array( - 'teampage_id' => array('UINT', NULL, 'auto_increment'), - 'group_id' => array('UINT', 0), - 'teampage_name' => array('VCHAR_UNI:255', ''), - 'teampage_position' => array('UINT', 0), - 'teampage_parent' => array('UINT', 0), - ), - 'PRIMARY_KEY' => 'teampage_id', - ), ), 'add_columns' => array( + GROUPS_TABLE => array( + 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), + ), PROFILE_FIELDS_TABLE => array( 'field_show_on_pm' => array('BOOL', 0), ), @@ -2482,39 +2475,26 @@ function change_database_data(&$no_updates, $version) set_config('use_system_cron', 0); } - $sql = 'SELECT teampage_id - FROM ' . TEAMPAGE_TABLE; + $sql = 'SELECT group_teampage + FROM ' . GROUPS_TABLE . ' + WHERE group_teampage > 0'; $result = $db->sql_query_limit($sql, 1); - $added_groups_teampage = (bool) $db->sql_fetchfield('teampage_id'); + $added_groups_teampage = (bool) $db->sql_fetchfield('group_teampage'); $db->sql_freeresult($result); if (!$added_groups_teampage) { - $sql = 'SELECT * - FROM ' . GROUPS_TABLE . ' + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 1 WHERE group_type = ' . GROUP_SPECIAL . " - AND (group_name = 'ADMINISTRATORS' - OR group_name = 'GLOBAL_MODERATORS') - ORDER BY group_name ASC"; - $result = $db->sql_query($sql); - - $teampage_entries = array(); - while ($row = $db->sql_fetchrow($result)) - { - $teampage_entries[] = array( - 'group_id' => (int) $row['group_id'], - 'teampage_name' => '', - 'teampage_position' => sizeof($teampage_entries) + 1, - 'teampage_parent' => 0, - ); - } - $db->sql_freeresult($result); + AND group_name = 'ADMINISTRATORS'"; + _sql($sql, $errored, $error_ary); - if (sizeof($teampage_entries)) - { - $db->sql_multi_insert(TEAMPAGE_TABLE, $teampage_entries); - } - unset($teampage_entries); + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 2 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'GLOBAL_MODERATORS'"; + _sql($sql, $errored, $error_ary); } if (!isset($config['legend_sort_groupname'])) -- cgit v1.2.1 From 3362baca51bd82e6cc0d15625863e46506bece72 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 19:27:30 +0100 Subject: [ticket/10411] Add migrations file for teampage table PHPBB3-10411 --- phpBB/includes/db/migration/data/310/teampage.php | 104 ++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 phpBB/includes/db/migration/data/310/teampage.php (limited to 'phpBB') diff --git a/phpBB/includes/db/migration/data/310/teampage.php b/phpBB/includes/db/migration/data/310/teampage.php new file mode 100644 index 0000000000..510ecf9481 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/teampage.php @@ -0,0 +1,104 @@ +db_tools->sql_table_exists($this->table_prefix . 'teampage'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_310_dev'); + } + + public function update_schema() + { + return array( + 'add_tables' => array( + $this->table_prefix . 'teampage' => array( + 'COLUMNS' => array( + 'teampage_id' => array('UINT', NULL, 'auto_increment'), + 'group_id' => array('UINT', 0), + 'teampage_name' => array('VCHAR_UNI:255', ''), + 'teampage_position' => array('UINT', 0), + 'teampage_parent' => array('UINT', 0), + ), + 'PRIMARY_KEY' => 'teampage_id', + ), + ), + 'drop_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_teampage', + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'teampage', + ), + 'add_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'add_groups_teampage'))), + ); + } + + public function add_groups_teampage() + { + $sql = 'SELECT teampage_id + FROM ' . TEAMPAGE_TABLE; + $result = $this->db->sql_query_limit($sql, 1); + $added_groups_teampage = (bool) $this->db->sql_fetchfield('teampage_id'); + $this->db->sql_freeresult($result); + + if (!$added_groups_teampage) + { + $sql = 'SELECT * + FROM ' . GROUPS_TABLE . ' + WHERE group_type = ' . GROUP_SPECIAL . " + AND (group_name = 'ADMINISTRATORS' + OR group_name = 'GLOBAL_MODERATORS') + ORDER BY group_name ASC"; + $result = $this->db->sql_query($sql); + + $teampage_entries = array(); + while ($row = $db->sql_fetchrow($result)) + { + $teampage_entries[] = array( + 'group_id' => (int) $row['group_id'], + 'teampage_name' => '', + 'teampage_position' => sizeof($teampage_entries) + 1, + 'teampage_parent' => 0, + ); + } + $db->sql_freeresult($result); + + if (sizeof($teampage_entries)) + { + $this->db->sql_multi_insert(TEAMPAGE_TABLE, $teampage_entries); + } + unset($teampage_entries); + } + + } +} -- cgit v1.2.1 From 97a446f5b97005f71a7ec3e015aadecaf5bffa36 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 22:00:15 +0100 Subject: [ticket/10411] Update schema file with new table and remove the column PHPBB3-10411 --- phpBB/install/schemas/schema_data.sql | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'phpBB') diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 7c1a7d40f5..346a19f24b 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -460,13 +460,17 @@ INSERT INTO phpbb_users (user_type, group_id, username, username_clean, user_reg INSERT INTO phpbb_users (user_type, group_id, username, username_clean, user_regdate, user_password, user_email, user_lang, user_style, user_rank, user_colour, user_posts, user_permissions, user_ip, user_birthday, user_lastpage, user_last_confirm_key, user_post_sortby_type, user_post_sortby_dir, user_topic_sortby_type, user_topic_sortby_dir, user_avatar, user_sig, user_sig_bbcode_uid, user_from, user_icq, user_aim, user_yim, user_msnm, user_jabber, user_website, user_occ, user_interests, user_actkey, user_newpasswd) VALUES (3, 5, 'Admin', 'admin', 0, '21232f297a57a5a743894a0e4a801fc3', 'admin@yourdomain.com', 'en', 1, 1, 'AA0000', 1, '', '', '', '', '', 't', 'a', 't', 'd', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); # -- Groups -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GUESTS', 3, 0, '', 0, 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED', 3, 0, '', 0, 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED_COPPA', 3, 0, '', 0, 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GLOBAL_MODERATORS', 3, 0, '00AA00', 2, 2, '', '', '', 0); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('ADMINISTRATORS', 3, 1, 'AA0000', 1, 1, '', '', '', 0); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('BOTS', 3, 0, '9E8DA7', 0, 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GUESTS', 3, 0, '', 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED', 3, 0, '', 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED_COPPA', 3, 0, '', 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GLOBAL_MODERATORS', 3, 0, '00AA00', 2, '', '', '', 0); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('ADMINISTRATORS', 3, 1, 'AA0000', 1, '', '', '', 0); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('BOTS', 3, 0, '9E8DA7', 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5); + +# -- Teampage +INSERT INTO phpbb_teampage (group_id, teampage_name, teampage_position, teampage_parent) VALUES (5, '', 1, 0); +INSERT INTO phpbb_teampage (group_id, teampage_name, teampage_position, teampage_parent) VALUES (4, '', 2, 0); # -- User -> Group INSERT INTO phpbb_user_group (group_id, user_id, user_pending, group_leader) VALUES (1, 1, 0, 0); -- cgit v1.2.1 From 8a9e1ca3f176946bc7b8ddb9be30ca8607685b80 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 28 Feb 2013 22:56:01 +0100 Subject: [feature/avatars] Auto-clear avatar dimensions when first changing avatars In the remote avatar and gravatar the dimension input boxes will now be cleared when changing the avatar. This will only happen once per page-load. Any input after the first change will not trigger this. PHPBB3-10018 --- .../prosilver/template/ucp_avatar_options_gravatar.html | 14 ++++++++++++++ .../prosilver/template/ucp_avatar_options_remote.html | 14 ++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'phpBB') diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html b/phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html index 04fd5c459d..692f50cb9a 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html @@ -1,3 +1,17 @@ + +

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html index ab91e90c27..39a8483dc4 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_remote.html @@ -1,3 +1,17 @@ + +

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-- cgit v1.2.1 From b8b2ede35db3d562ca6ed3087ad99933e05c4b67 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 1 Mar 2013 12:45:49 +0100 Subject: [ticket/10411] Remove ajax delete, so the page is refreshed Otherwise if you delete a group, you can not readd it to the page. PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB') diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index 47ff792b54..cf1a7be427 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -55,7 +55,7 @@ {ICON_MOVE_UP_DISABLED} {ICON_MOVE_DOWN_DISABLED} - {ICON_DELETE} + {ICON_DELETE}