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

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

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

{ERROR}

-
-

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- - - -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
+

{L_AVATAR_EXPLAIN}
+
{AVATAR}
+
+

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

{avatar_drivers.L_TITLE}

+

{avatar_drivers.L_EXPLAIN}

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

{L_AVATAR_GALLERY}

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

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

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

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

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
+

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
+
+
+

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
+

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

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

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
+
+
+

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

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

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- - -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
-
-
-

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

{ERROR}

+
+

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

{avatar_drivers.L_EXPLAIN}

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

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

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

{ERROR}


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

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

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

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

{L_AVATAR_EXPLAIN}
{AVATAR}
-
- +

{L_AVATAR_SELECT_NEW}

+
+
+
+
+
+
-

{avatar_drivers.L_TITLE}

+
+

{avatar_drivers.L_EXPLAIN}

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

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

{avatar_drivers.L_EXPLAIN}

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

{avatar_drivers.L_EXPLAIN}

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

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

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
-
-
-

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

{avatar_drivers.L_EXPLAIN}

+ {avatar_drivers.OUTPUT} +
+ +
+
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 9ad157f78a..16ae8670ce 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -54,7 +54,6 @@ class acp_groups // Clear some vars - $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false; $group_row = array(); // Grab basic data for group, if group_id is set and exists @@ -281,8 +280,24 @@ class acp_groups $error = array(); $user->add_lang('ucp'); - $avatar_select = basename(request_var('avatar_select', '')); - $category = basename(request_var('category', '')); + // Setup avatar data for later + $avatars_enabled = false; + $avatar_manager = null; + $avatar_drivers = null; + $avatar_data = null; + $avatar_error = array(); + + if ($config['allow_avatar']) + { + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + + $avatar_drivers = $avatar_manager->get_valid_drivers(); + sort($avatar_drivers); + + // This is normalised data, without the group_ prefix + $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver::FROM_GROUP); + } + // Did we submit? if ($update) @@ -300,12 +315,6 @@ class acp_groups $allow_desc_urls = request_var('desc_parse_urls', false); $allow_desc_smilies = request_var('desc_parse_smilies', false); - $data['uploadurl'] = request_var('uploadurl', ''); - $data['remotelink'] = request_var('remotelink', ''); - $data['width'] = request_var('width', ''); - $data['height'] = request_var('height', ''); - $delete = request_var('delete', ''); - $submit_ary = array( 'colour' => request_var('group_colour', ''), 'rank' => request_var('group_rank', 0), @@ -322,81 +331,38 @@ class acp_groups { $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0; } - - if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) - { - // Avatar stuff - $var_ary = array( - 'uploadurl' => array('string', true, 5, 255), - 'remotelink' => array('string', true, 5, 255), - 'width' => array('string', true, 1, 3), - 'height' => array('string', true, 1, 3), - ); - - if (!($error = validate_data($data, $var_ary))) + + if ($config['allow_avatar']) { + // Handle avatar + $driver = request_var('avatar_driver', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $data['user_id'] = "g$group_id"; + $avatar = $avatar_manager->get_driver($driver); + $result = $avatar->process_form($template, $avatar_data, $avatar_error); - if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) + if ($result && empty($avatar_error)) { - list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error); - } - else if ($data['remotelink']) - { - list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error); + // Success! Lets save the result + + /* + $result = array( + 'avatar' => ..., + 'avatar_width' => ..., + 'avatar_height' => ..., + ); + */ + + $submit_ary = array_merge($submit_ary, $result); + $submit_ary['avatar_type'] = $driver; } } - } - else if ($avatar_select && $config['allow_avatar_local']) - { - // check avatar gallery - if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) + else { - $submit_ary['avatar_type'] = AVATAR_GALLERY; - - list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select); - $submit_ary['avatar'] = $category . '/' . $avatar_select; - } - } - else if ($delete) - { - $submit_ary['avatar'] = ''; - $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0; - } - else if ($data['width'] && $data['height']) - { - // Only update the dimensions? - if ($config['avatar_max_width'] || $config['avatar_max_height']) - { - if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) - { - $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); - } - } - - if (!sizeof($error)) - { - if ($config['avatar_min_width'] || $config['avatar_min_height']) - { - if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) - { - $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); - } - } - } - - if (!sizeof($error)) - { - $submit_ary['avatar_width'] = $data['width']; - $submit_ary['avatar_height'] = $data['height']; - } - } - - if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete) - { - if (isset($group_row['group_avatar']) && $group_row['group_avatar']) - { - avatar_delete('group', $group_row, true); + // Removing the avatar + $submit_ary['avatar_type'] = ''; + $submit_ary['avatar'] = ''; + $submit_ary['avatar_width'] = 0; + $submit_ary['avatar_height'] = 0; } } @@ -423,7 +389,7 @@ class acp_groups 'rank' => 'int', 'colour' => 'string', 'avatar' => 'string', - 'avatar_type' => 'int', + 'avatar_type' => 'string', 'avatar_width' => 'int', 'avatar_height' => 'int', 'receive_pm' => 'int', @@ -553,13 +519,54 @@ class acp_groups $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : ''; $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : ''; - $avatar_img = (!empty($group_row['group_avatar'])) ? get_group_avatar($group_row) : ''; - - $display_gallery = (isset($_POST['display_gallery'])) ? true : false; - - if ($config['allow_avatar_local'] && $display_gallery) + // Load up stuff for avatars + if ($config['allow_avatar']) { - avatar_gallery($category, $avatar_select, 4); + $avatars_enabled = false; + $focused_driver = request_var('avatar_driver', $avatar_data['avatar_type']); + + foreach ($avatar_drivers as $driver) + { + if ($config["allow_avatar_$driver"]) + { + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => "acp_avatar_options_$driver.html", + )); + + $avatar = $avatar_manager->get_driver($driver); + + if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) + { + $driver_u = strtoupper($driver); + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_TITLE'), // @TODO add lang values + 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'), + + 'DRIVER' => $driver, + 'SELECTED' => ($driver == $focused_driver), + 'OUTPUT' => $template->assign_display('avatar'), + )); + } + } + } + } + + $avatar = get_group_avatar($group_row, 'GROUP_AVATAR', true); + + // Merge any avatars errors into the primary error array + // Drivers use lang constants, so we need to map to the actual strings + foreach ($avatar_error as $e) + { + if (is_array($e)) + { + $key = array_shift($e); + $error[] = vsprintf($user->lang($key), $e); + } + else + { + $error[] = $user->lang((string) $e); + } } $back_link = request_var('back_link', ''); @@ -580,12 +587,10 @@ class acp_groups 'S_ADD_GROUP' => ($action == 'add') ? true : false, 'S_GROUP_PERM' => ($action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) ? true : false, 'S_INCLUDE_SWATCH' => true, - 'S_CAN_UPLOAD' => $can_upload, 'S_ERROR' => (sizeof($error)) ? true : false, 'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL) ? true : false, - 'S_DISPLAY_GALLERY' => ($config['allow_avatar_local'] && !$display_gallery) ? true : false, - 'S_IN_GALLERY' => ($config['allow_avatar_local'] && $display_gallery) ? true : false, 'S_USER_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false, + 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', 'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name, @@ -606,8 +611,7 @@ class acp_groups 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)), - 'AVATAR' => $avatar_img, - 'AVATAR_IMAGE' => $avatar_img, + 'AVATAR' => (empty($avatar) ? '' : $avatar), 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '', diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 9b5c52e28e..ad8e7532c0 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1797,7 +1797,6 @@ class acp_users 'S_AVATAR' => true, 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', 'AVATAR' => (empty($avatar) ? '' : $avatar), - 'AV_SHOW_DELETE' => !empty($avatar), 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 85eda96018..f87854315d 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -67,6 +67,10 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver if (!empty($avatar_list[$category])) { + $template->assign_vars(array( + 'AV_LOCAL_SHOW' => true, + )); + $table_cols = isset($row['av_gallery_cols']) ? $row['av_gallery_cols'] : 4; $row_count = $col_count = $av_pos = 0; $av_count = sizeof($avatar_list[$category]); From 3963b39634225a68687cf1b817a47ae1eeb6ac79 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 4 Jul 2011 17:19:18 -0700 Subject: [PATCH 019/234] [feature/avatars] Making schema changes for db tables These schema changes make manual column chaning uncessesary. PHPBB3-10018 --- phpBB/install/database_update.php | 4 ++++ phpBB/install/schemas/firebird_schema.sql | 4 ++-- phpBB/install/schemas/mssql_schema.sql | 4 ++-- phpBB/install/schemas/mysql_40_schema.sql | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 843e8c2f23..ba6d5d34e2 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1092,6 +1092,10 @@ function database_update_info() 'change_columns' => array( GROUPS_TABLE => array( 'group_legend' => array('UINT', 0), + 'group_avatar_type' => array('VCHAR:32', 0), + ), + USERS_TABLE => array( + 'user_avatar_type' => array('VCHAR:32', 0), ), ), 'drop_columns' => array( diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index daeba45864..8b5bc90afa 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -445,7 +445,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL, group_display INTEGER DEFAULT 0 NOT NULL, group_avatar VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - group_avatar_type INTEGER DEFAULT 0 NOT NULL, + group_avatar_type VARCHAR(32) CHARACTER SET NONE DEFAULT '' NOT NULL, group_avatar_width INTEGER DEFAULT 0 NOT NULL, group_avatar_height INTEGER DEFAULT 0 NOT NULL, group_rank INTEGER DEFAULT 0 NOT NULL, @@ -1317,7 +1317,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INTEGER DEFAULT 1 NOT NULL, user_options INTEGER DEFAULT 230271 NOT NULL, user_avatar VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - user_avatar_type INTEGER DEFAULT 0 NOT NULL, + user_avatar_type VARCHAR(32) CHARACTER SET NONE DEFAULT '' NOT NULL, user_avatar_width INTEGER DEFAULT 0 NOT NULL, user_avatar_height INTEGER DEFAULT 0 NOT NULL, user_sig BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 736917fdcb..65ef420877 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -553,7 +553,7 @@ CREATE TABLE [phpbb_groups] ( [group_desc_uid] [varchar] (8) DEFAULT ('') NOT NULL , [group_display] [int] DEFAULT (0) NOT NULL , [group_avatar] [varchar] (255) DEFAULT ('') NOT NULL , - [group_avatar_type] [int] DEFAULT (0) NOT NULL , + [group_avatar_type] [varchar] (32) DEFAULT ('') NOT NULL , [group_avatar_width] [int] DEFAULT (0) NOT NULL , [group_avatar_height] [int] DEFAULT (0) NOT NULL , [group_rank] [int] DEFAULT (0) NOT NULL , @@ -1603,7 +1603,7 @@ CREATE TABLE [phpbb_users] ( [user_allow_massemail] [int] DEFAULT (1) NOT NULL , [user_options] [int] DEFAULT (230271) NOT NULL , [user_avatar] [varchar] (255) DEFAULT ('') NOT NULL , - [user_avatar_type] [int] DEFAULT (0) NOT NULL , + [user_avatar_type] [varchar] (32) DEFAULT ('') NOT NULL , [user_avatar_width] [int] DEFAULT (0) NOT NULL , [user_avatar_height] [int] DEFAULT (0) NOT NULL , [user_sig] [text] DEFAULT ('') NOT NULL , diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 97c378621b..a41a55494c 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -317,7 +317,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varbinary(8) DEFAULT '' NOT NULL, group_display tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_avatar varbinary(255) DEFAULT '' NOT NULL, - group_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + group_avatar_type varbinary(32) DEFAULT '' NOT NULL, group_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -941,7 +941,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, user_options int(11) UNSIGNED DEFAULT '230271' NOT NULL, user_avatar varbinary(255) DEFAULT '' NOT NULL, - user_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + user_avatar_type varbinary(32) DEFAULT '' NOT NULL, user_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_sig mediumblob NOT NULL, From c7976279e1c85f921156ed499dee1e587587c693 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 18:59:24 +0200 Subject: [PATCH 020/234] [feature/avatars] Fix avatar driver filename for autoloading PHPBB3-10018 --- phpBB/includes/avatar/{ => driver}/driver.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename phpBB/includes/avatar/{ => driver}/driver.php (100%) diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver/driver.php similarity index 100% rename from phpBB/includes/avatar/driver.php rename to phpBB/includes/avatar/driver/driver.php From 3b0e0dba3279a78cab2336d32ee8ff63a7077c5c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 19:08:54 +0200 Subject: [PATCH 021/234] [feature/avatars] Remove unneeded require (class is now autoloaded) PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 001fcf2f14..a81b0d1e51 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -82,8 +82,6 @@ class phpbb_avatar_manager **/ private function load_valid_drivers() { - require_once($this->phpbb_root_path . 'includes/avatar/driver.' . $this->phpEx); - if ($this->cache) { self::$valid_drivers = $this->cache->get('avatar_drivers'); From e861bb0e04c08b03366ec7c58473b630acc91181 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 19:19:13 +0200 Subject: [PATCH 022/234] [feature/avatars] Use request object in avatar drivers PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 5 +++-- phpBB/includes/avatar/driver/driver.php | 12 ++++++++++-- phpBB/includes/avatar/driver/local.php | 8 ++++---- phpBB/includes/avatar/driver/remote.php | 12 ++++++------ phpBB/includes/avatar/driver/upload.php | 2 +- phpBB/includes/avatar/manager.php | 6 ++++-- phpBB/includes/functions_display.php | 3 ++- phpBB/includes/ucp/ucp_profile.php | 4 ++-- 9 files changed, 33 insertions(+), 21 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 16ae8670ce..0a22c216c7 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -289,7 +289,7 @@ class acp_groups if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index c0da9b8ce0..12da482dbe 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -32,6 +32,7 @@ class acp_users { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; + global $request; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; @@ -466,7 +467,7 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); if ($driver = $avatar_manager->get_driver($user_row['user_avatar_type'])) { $driver->delete($user_row); @@ -1687,7 +1688,7 @@ class acp_users $avatars_enabled = false; if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index d158c419bd..8fb80693fb 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -26,7 +26,13 @@ abstract class phpbb_avatar_driver * @type phpbb_config */ protected $config; - + + /** + * Current board configuration + * @type phpbb_config + */ + protected $request; + /** * Current $phpbb_root_path * @type string @@ -62,13 +68,15 @@ abstract class phpbb_avatar_driver * Construct an driver object * * @param $config The phpBB configuration + * @param $request The request object * @param $phpbb_root_path The path to the phpBB root * @param $phpEx The php file extension * @param $cache A cache driver */ - public function __construct(phpbb_config $config, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null) + public function __construct(phpbb_config $config, phpbb_request $request, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null) { $this->config = $config; + $this->request = $request; $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->cache = $cache; diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index f87854315d..27e451c099 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -50,7 +50,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function prepare_form($template, $row, &$error) { $avatar_list = $this->get_avatar_list(); - $category = request_var('av_local_cat', ''); + $category = $this->request->variable('av_local_cat', ''); $categories = array_keys($avatar_list); @@ -110,9 +110,9 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function process_form($template, $row, &$error) { $avatar_list = $this->get_avatar_list(); - $category = request_var('av_local_cat', ''); - - $file = request_var('av_local_file', ''); + $category = $this->request->variable('av_local_cat', ''); + + $file = $this->request->variable('av_local_file', ''); if (!isset($avatar_list[$category][urldecode($file)])) { $error[] = 'AVATAR_URL_NOT_FOUND'; diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index cad9850c3f..cd0a756428 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -50,8 +50,8 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver public function prepare_form($template, $row, &$error) { $template->assign_vars(array( - 'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : request_var('av_local_width', 0), - 'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : request_var('av_local_width', 0), + 'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0), + 'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0), 'AV_REMOTE_URL' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar']) ? $row['avatar'] : '', )); @@ -63,10 +63,10 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver */ public function process_form($template, $row, &$error) { - $url = request_var('av_remote_url', ''); - $width = request_var('av_remote_width', 0); - $height = request_var('av_remote_height', 0); - + $url = $this->request->variable('av_remote_url', ''); + $width = $this->request->variable('av_remote_width', 0); + $height = $this->request->variable('av_remote_height', 0); + if (!preg_match('#^(http|https|ftp)://#i', $url)) { $url = 'http://' . $url; diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 23521ef435..c7d2b870c1 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -76,7 +76,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); - $url = request_var('av_upload_url', ''); + $url = $this->request->variable('av_upload_url', ''); if (!empty($_FILES['av_upload_file']['name'])) { diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index a81b0d1e51..f9a262b92f 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -23,17 +23,19 @@ class phpbb_avatar_manager private $phpbb_root_path; private $phpEx; private $config; + private $request; private $cache; private static $valid_drivers = false; /** * @TODO **/ - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_cache_driver_interface $cache = null) + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache = null) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->config = $config; + $this->request = $request; $this->cache = $cache; } @@ -66,7 +68,7 @@ class phpbb_avatar_manager if ($new || !is_object(self::$valid_drivers[$avatar_type])) { $class_name = 'phpbb_avatar_driver_' . $avatar_type; - self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->phpbb_root_path, $this->phpEx, $this->cache); + self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache); } return self::$valid_drivers[$avatar_type]; diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 1c1663f2cc..c59805dacd 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1312,6 +1312,7 @@ function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = fal function get_avatar($row, $alt, $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; + global $request; static $avatar_manager = null; @@ -1369,7 +1370,7 @@ function get_avatar($row, $alt, $ignore_config = false) default: if (empty($avatar_manager)) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->get_driver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); } $avatar = $avatar_manager->get_driver($row['avatar_type']); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 1c469fa290..ffc6ebf556 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -552,8 +552,8 @@ class ucp_profile if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); - + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); + $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); From 0898d114574e88eb5eda819b8921a27739be74ca Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 20:27:11 +0200 Subject: [PATCH 023/234] [feature/avatars] Fix CS PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index f9a262b92f..41429f3a06 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -116,7 +116,8 @@ class phpbb_avatar_manager /** * @TODO **/ - public function get_valid_drivers() { + public function get_valid_drivers() + { if (self::$valid_drivers === false) { $this->load_valid_drivers(); From e8a9c0ae6d92822699de9a2d7fc1aae9377ade8a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:11:06 +0200 Subject: [PATCH 024/234] [feature/avatars] Fix avatar_type in create_schema_files PHPBB3-10018 --- phpBB/develop/create_schema_files.php | 4 ++-- phpBB/install/schemas/mssql_schema.sql | 2 +- phpBB/install/schemas/mysql_41_schema.sql | 4 ++-- phpBB/install/schemas/oracle_schema.sql | 4 ++-- phpBB/install/schemas/postgres_schema.sql | 4 ++-- phpBB/install/schemas/sqlite_schema.sql | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 4088657743..6418bb57f0 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1168,7 +1168,7 @@ function get_schema_struct() 'group_desc_uid' => array('VCHAR:8', ''), 'group_display' => array('BOOL', 0), 'group_avatar' => array('VCHAR', ''), - 'group_avatar_type' => array('TINT:2', 0), + 'group_avatar_type' => array('VCHAR:32', ''), 'group_avatar_width' => array('USINT', 0), 'group_avatar_height' => array('USINT', 0), 'group_rank' => array('UINT', 0), @@ -1821,7 +1821,7 @@ function get_schema_struct() 'user_allow_massemail' => array('BOOL', 1), 'user_options' => array('UINT:11', 230271), 'user_avatar' => array('VCHAR', ''), - 'user_avatar_type' => array('TINT:2', 0), + 'user_avatar_type' => array('VCHAR:32', ''), 'user_avatar_width' => array('USINT', 0), 'user_avatar_height' => array('USINT', 0), 'user_sig' => array('MTEXT_UNI', ''), diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 2cf60e9f02..516b030f5a 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -1109,7 +1109,7 @@ CREATE TABLE [phpbb_reports] ( [report_closed] [int] DEFAULT (0) NOT NULL , [report_time] [int] DEFAULT (0) NOT NULL , [report_text] [text] DEFAULT ('') NOT NULL , - [reported_post_text] [text] DEFAULT ('') NOT NULL + [reported_post_text] [text] DEFAULT ('') NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 3fd8d4f1d1..11286e2526 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -317,7 +317,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) DEFAULT '' NOT NULL, group_display tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_avatar varchar(255) DEFAULT '' NOT NULL, - group_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + group_avatar_type varchar(32) DEFAULT '' NOT NULL, group_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -917,7 +917,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, user_options int(11) UNSIGNED DEFAULT '230271' NOT NULL, user_avatar varchar(255) DEFAULT '' NOT NULL, - user_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + user_avatar_type varchar(32) DEFAULT '' NOT NULL, user_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_sig mediumtext NOT NULL, diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 8a0f3e56b1..3bc6a853ca 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -610,7 +610,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar2(8) DEFAULT '' , group_display number(1) DEFAULT '0' NOT NULL, group_avatar varchar2(255) DEFAULT '' , - group_avatar_type number(2) DEFAULT '0' NOT NULL, + group_avatar_type varchar2(32) DEFAULT '' , group_avatar_width number(4) DEFAULT '0' NOT NULL, group_avatar_height number(4) DEFAULT '0' NOT NULL, group_rank number(8) DEFAULT '0' NOT NULL, @@ -1665,7 +1665,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail number(1) DEFAULT '1' NOT NULL, user_options number(11) DEFAULT '230271' NOT NULL, user_avatar varchar2(255) DEFAULT '' , - user_avatar_type number(2) DEFAULT '0' NOT NULL, + user_avatar_type varchar2(32) DEFAULT '' , user_avatar_width number(4) DEFAULT '0' NOT NULL, user_avatar_height number(4) DEFAULT '0' NOT NULL, user_sig clob DEFAULT '' , diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index c624024362..f139dc0ced 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -463,7 +463,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) DEFAULT '' NOT NULL, group_display INT2 DEFAULT '0' NOT NULL CHECK (group_display >= 0), group_avatar varchar(255) DEFAULT '' NOT NULL, - group_avatar_type INT2 DEFAULT '0' NOT NULL, + group_avatar_type varchar(32) DEFAULT '' NOT NULL, group_avatar_width INT2 DEFAULT '0' NOT NULL CHECK (group_avatar_width >= 0), group_avatar_height INT2 DEFAULT '0' NOT NULL CHECK (group_avatar_height >= 0), group_rank INT4 DEFAULT '0' NOT NULL CHECK (group_rank >= 0), @@ -1167,7 +1167,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INT2 DEFAULT '1' NOT NULL CHECK (user_allow_massemail >= 0), user_options INT4 DEFAULT '230271' NOT NULL CHECK (user_options >= 0), user_avatar varchar(255) DEFAULT '' NOT NULL, - user_avatar_type INT2 DEFAULT '0' NOT NULL, + user_avatar_type varchar(32) DEFAULT '' NOT NULL, user_avatar_width INT2 DEFAULT '0' NOT NULL CHECK (user_avatar_width >= 0), user_avatar_height INT2 DEFAULT '0' NOT NULL CHECK (user_avatar_height >= 0), user_sig TEXT DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index bd002c93ed..417464110b 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -309,7 +309,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) NOT NULL DEFAULT '', group_display INTEGER UNSIGNED NOT NULL DEFAULT '0', group_avatar varchar(255) NOT NULL DEFAULT '', - group_avatar_type tinyint(2) NOT NULL DEFAULT '0', + group_avatar_type varchar(32) NOT NULL DEFAULT '', group_avatar_width INTEGER UNSIGNED NOT NULL DEFAULT '0', group_avatar_height INTEGER UNSIGNED NOT NULL DEFAULT '0', group_rank INTEGER UNSIGNED NOT NULL DEFAULT '0', @@ -891,7 +891,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INTEGER UNSIGNED NOT NULL DEFAULT '1', user_options INTEGER UNSIGNED NOT NULL DEFAULT '230271', user_avatar varchar(255) NOT NULL DEFAULT '', - user_avatar_type tinyint(2) NOT NULL DEFAULT '0', + user_avatar_type varchar(32) NOT NULL DEFAULT '', user_avatar_width INTEGER UNSIGNED NOT NULL DEFAULT '0', user_avatar_height INTEGER UNSIGNED NOT NULL DEFAULT '0', user_sig mediumtext(16777215) NOT NULL DEFAULT '', From eea2ec50521e274b928d23f710108f37797cb22c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:27:09 +0200 Subject: [PATCH 025/234] [feature/avatars] Introduce global phpbb_avatar_manager PHPBB3-10018 --- phpBB/common.php | 2 ++ phpBB/download/file.php | 2 ++ phpBB/includes/acp/acp_groups.php | 10 ++++------ phpBB/includes/acp/acp_users.php | 12 +++++------- phpBB/includes/functions_display.php | 10 ++-------- phpBB/includes/ucp/ucp_profile.php | 13 ++++++------- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index b3b8d7e4f7..c59c231d28 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -130,6 +130,8 @@ $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_ $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); +$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); + // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display'))); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index c01b0789de..55364b3fd0 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -82,6 +82,8 @@ if (isset($_GET['avatar'])) $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); + $phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); + $filename = request_var('avatar', ''); $avatar_group = false; $exit = false; diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 0a22c216c7..34c233604a 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -26,6 +26,7 @@ class acp_groups { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; + global $phpbb_avatar_manager; $user->add_lang('acp/groups'); $this->tpl_name = 'acp_groups'; @@ -282,16 +283,13 @@ class acp_groups // Setup avatar data for later $avatars_enabled = false; - $avatar_manager = null; $avatar_drivers = null; $avatar_data = null; $avatar_error = array(); if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - - $avatar_drivers = $avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); // This is normalised data, without the group_ prefix @@ -337,7 +335,7 @@ class acp_groups $driver = request_var('avatar_driver', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) @@ -534,7 +532,7 @@ class acp_groups 'avatar' => "acp_avatar_options_$driver.html", )); - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 12da482dbe..fac84ba40a 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -33,6 +33,7 @@ class acp_users global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; global $request; + global $phpbb_avatar_manager; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; @@ -467,8 +468,7 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - if ($driver = $avatar_manager->get_driver($user_row['user_avatar_type'])) + if ($driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type'])) { $driver->delete($user_row); } @@ -1688,9 +1688,7 @@ class acp_users $avatars_enabled = false; if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - - $avatar_drivers = $avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); // This is normalised data, without the user_ prefix @@ -1703,7 +1701,7 @@ class acp_users $driver = request_var('avatar_driver', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); if ($result && empty($error)) @@ -1758,7 +1756,7 @@ class acp_users 'avatar' => "acp_avatar_options_$driver.html", )); - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); if ($avatar->prepare_form($template, $avatar_data, $error)) { diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index c59805dacd..e1dd67aeaf 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1313,8 +1313,7 @@ function get_avatar($row, $alt, $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; global $request; - - static $avatar_manager = null; + global $phpbb_avatar_manager; if (!$config['allow_avatar'] && !$ignore_config) { @@ -1368,12 +1367,7 @@ function get_avatar($row, $alt, $ignore_config = false) break; default: - if (empty($avatar_manager)) - { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); - } - - $avatar = $avatar_manager->get_driver($row['avatar_type']); + $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); if ($avatar) { diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index ffc6ebf556..58e5254d4b 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -30,6 +30,7 @@ class ucp_profile { global $cache, $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; global $request; + global $phpbb_avatar_manager; $user->add_lang('posting'); @@ -552,11 +553,9 @@ class ucp_profile if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - - $avatar_drivers = $avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); - + // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver::FROM_USER); @@ -567,7 +566,7 @@ class ucp_profile $driver = request_var('avatar_driver', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); if ($result && empty($error)) @@ -594,7 +593,7 @@ class ucp_profile else { // They are removing their avatar or are trying to play games with us - if ($avatar = $avatar_manager->get_driver($user->data['user_avatar_type'])) + if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) { $avatar->delete($avatar_data); } @@ -634,7 +633,7 @@ class ucp_profile 'avatar' => "ucp_avatar_options_$driver.html", )); - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); if ($avatar->prepare_form($template, $avatar_data, $error)) { From 81fb4268cd141259fe5b3bc9ad51adf2e29e0772 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:40:19 +0200 Subject: [PATCH 026/234] [feature/avatars] Introduce an avatar driver interface PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatar/driver/driver.php | 39 ++++-------- phpBB/includes/avatar/driver/interface.php | 71 ++++++++++++++++++++++ phpBB/includes/functions_display.php | 4 +- phpBB/includes/ucp/ucp_profile.php | 2 +- 6 files changed, 87 insertions(+), 33 deletions(-) create mode 100644 phpBB/includes/avatar/driver/interface.php diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 34c233604a..5a45b3b572 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -293,7 +293,7 @@ class acp_groups sort($avatar_drivers); // This is normalised data, without the group_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver::FROM_GROUP); + $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver_interface::FROM_GROUP); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index fac84ba40a..9c12116062 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1692,7 +1692,7 @@ class acp_users sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_USER); + $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); if ($submit) { diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 8fb80693fb..277130e819 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Base class for avatar drivers * @package avatars */ -abstract class phpbb_avatar_driver +abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { /** * Current board configuration @@ -51,12 +51,6 @@ abstract class phpbb_avatar_driver */ protected $cache; - /** - * @TODO - */ - const FROM_USER = 0; - const FROM_GROUP = 1; - /** * This flag should be set to true if the avatar requires a nonstandard image * tag, and will generate the html itself. @@ -83,12 +77,7 @@ abstract class phpbb_avatar_driver } /** - * Get the avatar url and dimensions - * - * @param $ignore_config Whether this function should respect the users prefs - * and board configuration configuration option, or should just render - * the avatar anyways. Useful for the ACP. - * @return array Avatar data + * @inheritdoc */ public function get_data($row, $ignore_config = false) { @@ -100,13 +89,7 @@ abstract class phpbb_avatar_driver } /** - * Returns custom html for displaying this avatar. - * Only called if $custom_html is true. - * - * @param $ignore_config Whether this function should respect the users prefs - * and board configuration configuration option, or should just render - * the avatar anyways. Useful for the ACP. - * @return string HTML + * @inheritdoc */ public function get_custom_html($row, $ignore_config = false) { @@ -114,7 +97,7 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ public function prepare_form($template, $row, &$error, &$override_focus) { @@ -122,7 +105,7 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ public function process_form($template, $row, &$error) { @@ -130,7 +113,7 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ public function delete($row) { @@ -138,18 +121,18 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ - public static function clean_row($row, $src = phpbb_avatar_driver::FROM_USER) + public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER) { $return = array(); $prefix = false; - - if ($src == phpbb_avatar_driver::FROM_USER) + + if ($src == phpbb_avatar_driver_interface::FROM_USER) { $prefix = 'user_'; } - else if ($src == phpbb_avatar_driver::FROM_GROUP) + else if ($src == phpbb_avatar_driver_interface::FROM_GROUP) { $prefix = 'group_'; } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php new file mode 100644 index 0000000000..dcec5811bb --- /dev/null +++ b/phpBB/includes/avatar/driver/interface.php @@ -0,0 +1,71 @@ + '', 'width' => 0, 'height' => 0] + */ + public function get_data($row, $ignore_config = false); + + /** + * Returns custom html for displaying this avatar. + * Only called if $custom_html is true. + * + * @param $ignore_config Whether this function should respect the users prefs + * and board configuration configuration option, or should just render + * the avatar anyways. Useful for the ACP. + * @return string HTML + */ + public function get_custom_html($row, $ignore_config = false); + + /** + * @TODO + **/ + public function prepare_form($template, $row, &$error, &$override_focus); + + /** + * @TODO + **/ + public function process_form($template, $row, &$error); + + /** + * @TODO + **/ + public function delete($row); + + /** + * @TODO + **/ + public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER); +} diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index e1dd67aeaf..82638b7f2b 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1281,7 +1281,7 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank */ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_USER); + $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); return get_avatar($row, $alt, $ignore_config); } @@ -1296,7 +1296,7 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false */ function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_GROUP); + $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_GROUP); return get_avatar($row, $alt, $ignore_config); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 58e5254d4b..9d22fd4dba 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -557,7 +557,7 @@ class ucp_profile sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver::FROM_USER); + $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver_interface::FROM_USER); if ($submit) { From 3b71e81cfba726043063b05cb793e18186143252 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 21:29:52 +0200 Subject: [PATCH 027/234] [feature/avatars] Simplify clean_row, move it to avatar manager PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatar/driver/driver.php | 41 ---------------------- phpBB/includes/avatar/driver/interface.php | 11 ------ phpBB/includes/avatar/manager.php | 19 ++++++++++ phpBB/includes/functions_display.php | 4 +-- phpBB/includes/ucp/ucp_profile.php | 2 +- 7 files changed, 24 insertions(+), 57 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 5a45b3b572..d4a3e40d93 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -293,7 +293,7 @@ class acp_groups sort($avatar_drivers); // This is normalised data, without the group_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver_interface::FROM_GROUP); + $avatar_data = phpbb_avatar_manager::clean_row($group_row); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 9c12116062..cd50b02ca1 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1692,7 +1692,7 @@ class acp_users sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); + $avatar_data = phpbb_avatar_manager::clean_row($user_row); if ($submit) { diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 277130e819..7028df4b64 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -119,45 +119,4 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { return true; } - - /** - * @inheritdoc - **/ - public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER) - { - $return = array(); - $prefix = false; - - if ($src == phpbb_avatar_driver_interface::FROM_USER) - { - $prefix = 'user_'; - } - else if ($src == phpbb_avatar_driver_interface::FROM_GROUP) - { - $prefix = 'group_'; - } - - if ($prefix) - { - $len = strlen($prefix); - foreach ($row as $key => $val) - { - $sub = substr($key, 0, $len); - if ($sub == $prefix) - { - $return[substr($key, $len)] = $val; - } - else - { - $return[$key] = $val; - } - } - } - else - { - $return = $row; - } - - return $return; - } } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index dcec5811bb..8c8a067d13 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -21,12 +21,6 @@ if (!defined('IN_PHPBB')) */ interface phpbb_avatar_driver_interface { - /** - * @TODO - */ - const FROM_USER = 0; - const FROM_GROUP = 1; - /** * Get the avatar url and dimensions * @@ -63,9 +57,4 @@ interface phpbb_avatar_driver_interface * @TODO **/ public function delete($row); - - /** - * @TODO - **/ - public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER); } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 41429f3a06..054bb0cee9 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -125,4 +125,23 @@ class phpbb_avatar_manager return array_keys(self::$valid_drivers); } + + /** + * Strip out user_ and group_ prefixes from keys + **/ + public static function clean_row($row) + { + $keys = array_keys($row); + $values = array_values($row); + + $keys = array_map( + function ($key) + { + return preg_replace('(user_|group_)', '', $key); + }, + $row + ); + + return array_combine($keys, $values); + } } diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 82638b7f2b..619c30ada5 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1281,7 +1281,7 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank */ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); + $row = phpbb_avatar_manager::clean_row($user_row); return get_avatar($row, $alt, $ignore_config); } @@ -1296,7 +1296,7 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false */ function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_GROUP); + $row = phpbb_avatar_manager::clean_row($user_row); return get_avatar($row, $alt, $ignore_config); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 9d22fd4dba..44dc57cfd7 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -557,7 +557,7 @@ class ucp_profile sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver_interface::FROM_USER); + $avatar_data = phpbb_avatar_manager::clean_row($user->data); if ($submit) { From a1132fc5c7e990d73cbc8ac7abf4502a1bbe7216 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 21:45:51 +0200 Subject: [PATCH 028/234] [feature/avatars] Update avatars in database_update PHPBB3-10018 --- phpBB/includes/functions_display.php | 72 ++++++---------------------- phpBB/install/database_update.php | 24 +++++++++- 2 files changed, 36 insertions(+), 60 deletions(-) diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 619c30ada5..291d92387f 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1325,72 +1325,28 @@ function get_avatar($row, $alt, $ignore_config = false) 'width' => $row['avatar_width'], 'height' => $row['avatar_height'], ); - - switch ($row['avatar_type']) + + $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); + + if ($avatar) { - case AVATAR_UPLOAD: - // Compatibility with old avatars - if (!$config['allow_avatar_upload'] && !$ignore_config) - { - $avatar_data['src'] = ''; - } - else - { - $avatar_data['src'] = $phpbb_root_path . "download/file.$phpEx?avatar=" . $avatar_data['src']; - $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); - } - break; + if ($avatar->custom_html) + { + return $avatar->get_html($row, $ignore_config); + } - case AVATAR_GALLERY: - // Compatibility with old avatars - if (!$config['allow_avatar_local'] && !$ignore_config) - { - $avatar_data['src'] = ''; - } - else - { - $avatar_data['src'] = $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_data['src']; - $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); - } - break; - - case AVATAR_REMOTE: - // Compatibility with old avatars - if (!$config['allow_avatar_remote'] && !$ignore_config) - { - $avatar_data['src'] = ''; - } - else - { - $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); - } - break; - - default: - $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); - - if ($avatar) - { - if ($avatar->custom_html) - { - return $avatar->get_html($row, $ignore_config); - } - - $avatar_data = $avatar->get_data($row, $ignore_config); - } - else - { - $avatar_data['src'] = ''; - } - - break; + $avatar_data = $avatar->get_data($row, $ignore_config); + } + else + { + $avatar_data['src'] = ''; } $html = ''; if (!empty($avatar_data['src'])) { - $html = ''; diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index e85fe1810d..75f1ada749 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2391,13 +2391,33 @@ function change_database_data(&$no_updates, $version) { set_config('teampage_memberships', '1'); } - + // Clear styles table and add prosilver entry _sql('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); $sql = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')"; _sql($sql, $errored, $error_ary); - + + // Update avatars to modular types + $avatar_type_map = array( + AVATAR_UPLOAD => 'upload', + AVATAR_GALLERY => 'local', + AVATAR_REMOTE => 'remote', + ); + + foreach ($avatar_type_map as $old => $new) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_avatar_type = '" . $db->sql_escape($new) . "' + WHERE user_avatar_type = '" . $db->sql_escape($old) . "'"; + _sql($sql, $errored, $error_ary); + + $sql = 'UPDATE ' . GROUPS_TABLE . " + SET group_avatar_type = '" . $db->sql_escape($new) . "' + WHERE group_avatar_type = '" . $db->sql_escape($old) . "'"; + _sql($sql, $errored, $error_ary); + } + $no_updates = false; break; From b2b812f1714fc924a7c9e595ccb8fbb35f20f203 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 22:13:10 +0200 Subject: [PATCH 029/234] [feature/avatars] Do not assign in an if statement PHPBB3-10018 --- phpBB/includes/acp/acp_users.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index cd50b02ca1..33a173b74d 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -468,7 +468,8 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present - if ($driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type'])) + $driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type']); + if ($driver) { $driver->delete($user_row); } From f273ab16ae68d15832832e2b2c98a3b99c966c97 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 22:28:40 +0200 Subject: [PATCH 030/234] [feature/avatars] Fix clean_row regex, thanks to chris PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 054bb0cee9..f4e5a6d7f8 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -137,7 +137,7 @@ class phpbb_avatar_manager $keys = array_map( function ($key) { - return preg_replace('(user_|group_)', '', $key); + return preg_replace('#^(?:user_|group_)#', '', $key); }, $row ); From 6d994380d76accba5485b0a04d3028f1c153ebd8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 14:48:51 +0200 Subject: [PATCH 031/234] [feature/avatars] Fix error in avatar_manager::clean_row PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index f4e5a6d7f8..839216b61e 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -139,7 +139,7 @@ class phpbb_avatar_manager { return preg_replace('#^(?:user_|group_)#', '', $key); }, - $row + $keys ); return array_combine($keys, $values); From d10486699273b896fffe86f05f66a6d542843f5b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 16:59:06 +0200 Subject: [PATCH 032/234] [feature/avatars] Remove unneeded argument for driver prepare_form() PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 6 +++--- phpBB/includes/avatar/driver/interface.php | 2 +- phpBB/includes/avatar/driver/local.php | 4 ++-- phpBB/includes/avatar/driver/upload.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 7028df4b64..4ac6762140 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -38,13 +38,13 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface * @type string */ protected $phpbb_root_path; - + /** * Current $phpEx * @type string */ protected $phpEx; - + /** * A cache driver * @type phpbb_cache_driver_interface @@ -99,7 +99,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc **/ - public function prepare_form($template, $row, &$error, &$override_focus) + public function prepare_form($template, $row, &$error) { return false; } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index 8c8a067d13..d3b764e275 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -46,7 +46,7 @@ interface phpbb_avatar_driver_interface /** * @TODO **/ - public function prepare_form($template, $row, &$error, &$override_focus); + public function prepare_form($template, $row, &$error); /** * @TODO diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 27e451c099..a0ef912eae 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -43,7 +43,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver ); } } - + /** * @inheritdoc */ @@ -103,7 +103,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver return true; } - + /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index c7d2b870c1..d9504c04a0 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -58,7 +58,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], )); - + return true; } From f40e6963c61548d746c59b78cb60c0f7459c7696 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 17:11:20 +0200 Subject: [PATCH 033/234] [feature/avatars] Remove empty script tag PHPBB3-10018 --- phpBB/styles/prosilver/template/ucp_avatar_options.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index e8114da3ea..a246b00ddd 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -1,4 +1,3 @@ -
@@ -66,5 +65,3 @@
- From 21df013210d1de2cffae568c0620a7ccd6d8f426 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:23:26 +0200 Subject: [PATCH 034/234] [feature/avatars] Move avatars JavaScript code to external JS file PHPBB3-10018 --- phpBB/adm/style/acp_groups.html | 23 ++---------------- phpBB/adm/style/acp_users_avatar.html | 23 ++---------------- phpBB/adm/style/avatars.js | 17 +++++++++++++ phpBB/styles/prosilver/template/avatars.js | 17 +++++++++++++ .../template/ucp_avatar_options.html | 24 ++----------------- 5 files changed, 40 insertions(+), 64 deletions(-) create mode 100644 phpBB/adm/style/avatars.js create mode 100644 phpBB/styles/prosilver/template/avatars.js diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index 42cb434ad3..167642e5cb 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -123,27 +123,6 @@ -
@@ -154,6 +133,8 @@
+ + « {L_BACK} diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index 6316ff4a22..9649fa923e 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -28,30 +28,11 @@ -
{S_FORM_TOKEN} + + diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js new file mode 100644 index 0000000000..baa2623ac9 --- /dev/null +++ b/phpBB/adm/style/avatars.js @@ -0,0 +1,17 @@ +function avatar_simplify() { + var node = document.getElementById('av_options'); + for (var i = 0; i < node.children.length; i++) { + child = node.children[i]; + child.style.display = 'none'; + } + + var selected = document.getElementById('avatar_driver').value; + var id = 'av_option_' + selected; + node = document.getElementById(id); + if (node != null) { + node.style.display = 'block'; + } +} + +avatar_simplify(); +document.getElementById('avatar_driver').onchange = avatar_simplify; diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js new file mode 100644 index 0000000000..baa2623ac9 --- /dev/null +++ b/phpBB/styles/prosilver/template/avatars.js @@ -0,0 +1,17 @@ +function avatar_simplify() { + var node = document.getElementById('av_options'); + for (var i = 0; i < node.children.length; i++) { + child = node.children[i]; + child.style.display = 'none'; + } + + var selected = document.getElementById('avatar_driver').value; + var id = 'av_option_' + selected; + node = document.getElementById(id); + if (node != null) { + node.style.display = 'block'; + } +} + +avatar_simplify(); +document.getElementById('avatar_driver').onchange = avatar_simplify; diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index a246b00ddd..2438deefd5 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -41,27 +41,7 @@ - - + + From b060667ac102109c0c8f198925bb81b489a30f34 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:26:44 +0200 Subject: [PATCH 035/234] [feature/avatars] Rewrite avatars event handler to use jQuery PHPBB3-10018 --- phpBB/adm/style/avatars.js | 16 ++++------------ phpBB/styles/prosilver/template/avatars.js | 16 ++++------------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index baa2623ac9..252081ee08 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -1,17 +1,9 @@ function avatar_simplify() { - var node = document.getElementById('av_options'); - for (var i = 0; i < node.children.length; i++) { - child = node.children[i]; - child.style.display = 'none'; - } + $('#av_options').hide(); - var selected = document.getElementById('avatar_driver').value; - var id = 'av_option_' + selected; - node = document.getElementById(id); - if (node != null) { - node.style.display = 'block'; - } + var selected = $('#avatar_driver').val(); + $('#av_option_' + selected).show(); } avatar_simplify(); -document.getElementById('avatar_driver').onchange = avatar_simplify; +$('#avatar_driver').on('change', avatar_simplify); diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index baa2623ac9..252081ee08 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -1,17 +1,9 @@ function avatar_simplify() { - var node = document.getElementById('av_options'); - for (var i = 0; i < node.children.length; i++) { - child = node.children[i]; - child.style.display = 'none'; - } + $('#av_options').hide(); - var selected = document.getElementById('avatar_driver').value; - var id = 'av_option_' + selected; - node = document.getElementById(id); - if (node != null) { - node.style.display = 'block'; - } + var selected = $('#avatar_driver').val(); + $('#av_option_' + selected).show(); } avatar_simplify(); -document.getElementById('avatar_driver').onchange = avatar_simplify; +$('#avatar_driver').on('change', avatar_simplify); From 2f3581fe3ef928d91f12c442ab5e4890c6620f58 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:37:23 +0200 Subject: [PATCH 036/234] [feature/avatars] Add self-invoking closure around avatars.js PHPBB3-10018 --- phpBB/adm/style/avatars.js | 6 ++++++ phpBB/styles/prosilver/template/avatars.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index 252081ee08..cb19aa9b7a 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -1,3 +1,7 @@ +(function($) { // Avoid conflicts with other libraries + +"use strict"; + function avatar_simplify() { $('#av_options').hide(); @@ -7,3 +11,5 @@ function avatar_simplify() { avatar_simplify(); $('#avatar_driver').on('change', avatar_simplify); + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index 252081ee08..cb19aa9b7a 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -1,3 +1,7 @@ +(function($) { // Avoid conflicts with other libraries + +"use strict"; + function avatar_simplify() { $('#av_options').hide(); @@ -7,3 +11,5 @@ function avatar_simplify() { avatar_simplify(); $('#avatar_driver').on('change', avatar_simplify); + +})(jQuery); // Avoid conflicts with other libraries From 13f4bfabbeab77698f06c3431931b73ebedc587c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 21:00:00 +0200 Subject: [PATCH 037/234] [feature/avatars] Fixup avatars.js rewrite PHPBB3-10018 --- phpBB/adm/style/avatars.js | 4 ++-- phpBB/styles/prosilver/template/avatars.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index cb19aa9b7a..2068bdbbc4 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -3,13 +3,13 @@ "use strict"; function avatar_simplify() { - $('#av_options').hide(); + $('#av_options > div').hide(); var selected = $('#avatar_driver').val(); $('#av_option_' + selected).show(); } avatar_simplify(); -$('#avatar_driver').on('change', avatar_simplify); +$('#avatar_driver').bind('change', avatar_simplify); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index cb19aa9b7a..2068bdbbc4 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -3,13 +3,13 @@ "use strict"; function avatar_simplify() { - $('#av_options').hide(); + $('#av_options > div').hide(); var selected = $('#avatar_driver').val(); $('#av_option_' + selected).show(); } avatar_simplify(); -$('#avatar_driver').on('change', avatar_simplify); +$('#avatar_driver').bind('change', avatar_simplify); })(jQuery); // Avoid conflicts with other libraries From df16bd1c49e6e970b147f15e752825dd3186fb87 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 21:02:07 +0200 Subject: [PATCH 038/234] [feature/avatars] Rewrite drivers to use full class name * Use full driver class name as avatar_type value * Move avatar drivers to core namespace * Make avatars installable through extensions PHPBB3-10018 --- phpBB/common.php | 2 +- phpBB/download/file.php | 2 +- .../avatar/driver/{ => core}/local.php | 2 +- .../avatar/driver/{ => core}/remote.php | 2 +- .../avatar/driver/{ => core}/upload.php | 2 +- phpBB/includes/avatar/driver/driver.php | 21 +++++++ phpBB/includes/avatar/driver/interface.php | 10 ++++ phpBB/includes/avatar/manager.php | 55 +++++++++---------- phpBB/includes/ucp/ucp_profile.php | 10 ++-- 9 files changed, 68 insertions(+), 38 deletions(-) rename phpBB/includes/avatar/driver/{ => core}/local.php (98%) rename phpBB/includes/avatar/driver/{ => core}/remote.php (98%) rename phpBB/includes/avatar/driver/{ => core}/upload.php (98%) diff --git a/phpBB/common.php b/phpBB/common.php index 11b84ee858..52666685ac 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -130,7 +130,7 @@ $phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_ $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); -$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); +$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $phpbb_extension_manager, $cache->get_driver()); // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 55364b3fd0..34999ab24c 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -82,7 +82,7 @@ if (isset($_GET['avatar'])) $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); - $phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); + $phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $phpbb_extension_manager, $cache->get_driver()); $filename = request_var('avatar', ''); $avatar_group = false; diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/core/local.php similarity index 98% rename from phpBB/includes/avatar/driver/local.php rename to phpBB/includes/avatar/driver/core/local.php index a0ef912eae..ca82b9c175 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/core/local.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Handles avatars selected from the board gallery * @package avatars */ -class phpbb_avatar_driver_local extends phpbb_avatar_driver +class phpbb_avatar_driver_core_local extends phpbb_avatar_driver { /** * @inheritdoc diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/core/remote.php similarity index 98% rename from phpBB/includes/avatar/driver/remote.php rename to phpBB/includes/avatar/driver/core/remote.php index cd0a756428..9f5a58e75a 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/core/remote.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Handles avatars hosted remotely * @package avatars */ -class phpbb_avatar_driver_remote extends phpbb_avatar_driver +class phpbb_avatar_driver_core_remote extends phpbb_avatar_driver { /** * @inheritdoc diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/core/upload.php similarity index 98% rename from phpBB/includes/avatar/driver/upload.php rename to phpBB/includes/avatar/driver/core/upload.php index d9504c04a0..d0ce856dbe 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/core/upload.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Handles avatars uploaded to the board * @package avatars */ -class phpbb_avatar_driver_upload extends phpbb_avatar_driver +class phpbb_avatar_driver_core_upload extends phpbb_avatar_driver { /** * @inheritdoc diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 4ac6762140..5cebd1533d 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -119,4 +119,25 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { return true; } + + /** + * @inheritdoc + **/ + public function is_enabled() + { + $driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this)); + + return $this->config["allow_avatar_$driver"]; + } + + /** + * @inheritdoc + **/ + public function get_template_name() + { + $driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this)); + $template = "ucp_avatar_options_$driver.html"; + + return $template; + } } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index d3b764e275..4f1c1f73cf 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -57,4 +57,14 @@ interface phpbb_avatar_driver_interface * @TODO **/ public function delete($row); + + /** + * @TODO + **/ + public function is_enabled(); + + /** + * @TODO + **/ + public function get_template_name(); } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 839216b61e..c2c3dbbbca 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -24,25 +24,27 @@ class phpbb_avatar_manager private $phpEx; private $config; private $request; + private $extension_manager; private $cache; private static $valid_drivers = false; /** * @TODO **/ - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache = null) + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_extension_manager $extension_manager, phpbb_cache_driver_interface $cache = null) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->config = $config; $this->request = $request; + $this->extension_manager = $extension_manager; $this->cache = $cache; } /** * @TODO **/ - public function get_driver($avatar_type, $new = false) + public function get_driver($avatar_type) { if (self::$valid_drivers === false) { @@ -53,30 +55,33 @@ class phpbb_avatar_manager switch ($avatar_type) { case AVATAR_GALLERY: - $avatar_type = 'local'; + $avatar_type = 'phpbb_avatar_driver_local'; break; case AVATAR_UPLOAD: - $avatar_type = 'upload'; + $avatar_type = 'phpbb_avatar_driver_upload'; break; case AVATAR_REMOTE: - $avatar_type = 'remote'; + $avatar_type = 'phpbb_avatar_driver_remote'; break; } - if (isset(self::$valid_drivers[$avatar_type])) - { - if ($new || !is_object(self::$valid_drivers[$avatar_type])) - { - $class_name = 'phpbb_avatar_driver_' . $avatar_type; - self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache); - } - - return self::$valid_drivers[$avatar_type]; - } - else + if (false === array_search($avatar_type, self::$valid_drivers)) { return null; } + + $r = new ReflectionClass($avatar_type); + + if ($r->isSubClassOf('phpbb_avatar_driver')) { + $driver = new $avatar_type($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache); + } else if ($r->implementsInterface('phpbb_avatar_driver')) { + $driver = new $avatar_type(); + } else { + $message = "Invalid avatar driver class name '%s' provided. It must implement phpbb_avatar_driver_interface."; + trigger_error(sprintf($message, $avatar_type)); + } + + return $driver; } /** @@ -93,18 +98,12 @@ class phpbb_avatar_manager { self::$valid_drivers = array(); - $iterator = new DirectoryIterator($this->phpbb_root_path . 'includes/avatar/driver'); + $finder = $this->extension_manager->get_finder(); - foreach ($iterator as $file) - { - // Match all files that appear to be php files - if (preg_match("/^(.*)\.{$this->phpEx}$/", $file, $match)) - { - self::$valid_drivers[] = $match[1]; - } - } - - self::$valid_drivers = array_flip(self::$valid_drivers); + self::$valid_drivers = $finder + ->extension_directory('/avatar/driver/') + ->core_path('includes/avatar/driver/core/') + ->get_classes(); if ($this->cache) { @@ -123,7 +122,7 @@ class phpbb_avatar_manager $this->load_valid_drivers(); } - return array_keys(self::$valid_drivers); + return self::$valid_drivers; } /** diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 6b2133796d..f406e9dc5b 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -623,18 +623,18 @@ class ucp_profile } $focused_driver = request_var('avatar_driver', $user->data['user_avatar_type']); - + foreach ($avatar_drivers as $driver) { - if ($config["allow_avatar_$driver"]) + $avatar = $phpbb_avatar_manager->get_driver($driver); + + if ($avatar->is_enabled()) { $avatars_enabled = true; $template->set_filenames(array( - 'avatar' => "ucp_avatar_options_$driver.html", + 'avatar' => $avatar->get_template_name(), )); - $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->prepare_form($template, $avatar_data, $error)) { $driver_u = strtoupper($driver); From cf651ef81d611865a06d93c9db7c4dfcd680405c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 17 Mar 2012 23:50:28 +0100 Subject: [PATCH 039/234] [ticket/10714] Implement a class to add logs to the database. PHPBB3-10714 --- phpBB/includes/log/interface.php | 55 ++++++++++ phpBB/includes/log/log.php | 177 +++++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 phpBB/includes/log/interface.php create mode 100644 phpBB/includes/log/log.php diff --git a/phpBB/includes/log/interface.php b/phpBB/includes/log/interface.php new file mode 100644 index 0000000000..897b8a8211 --- /dev/null +++ b/phpBB/includes/log/interface.php @@ -0,0 +1,55 @@ +log_table = $log_table; + $this->enable(); + } + + /** + * This function returns the state of the log-system. + * + * @return bool True if log is enabled + */ + public function is_enabled() + { + return $this->enabled; + } + + /** + * This function allows disable the log-system. When add_log is called, the log will not be added to the database. + */ + public function disable() + { + $this->enabled = false; + } + + /** + * This function allows re-enable the log-system. + */ + public function enable() + { + $this->enabled = true; + } + + /** + * Adds a log to the database + * + * @param string $mode The mode defines which log_type is used and in which log the entry is displayed. + * @param int $user_id User ID of the user + * @param string $log_ip IP address of the user + * @param string $log_operation Name of the operation + * @param int $log_time Timestamp when the log was added. + * @param array $additional_data More arguments can be added, depending on the log_type + * + * @return int|bool Returns the log_id, if the entry was added to the database, false otherwise. + */ + public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array()) + { + if (!$this->is_enabled()) + { + return false; + } + + global $db; + /** + * @todo: enable when events are merged + * + global $db, $phpbb_dispatcher; + */ + + if ($log_time == false) + { + $log_time = time(); + } + + $sql_ary = array( + 'user_id' => $user_id, + 'log_ip' => $log_ip, + 'log_time' => $log_time, + 'log_operation' => $log_operation, + ); + + switch ($mode) + { + case 'admin': + $sql_ary += array( + 'log_type' => LOG_ADMIN, + 'log_data' => (!sizeof($additional_data)) ? '' : serialize($additional_data), + ); + break; + + case 'mod': + $sql_ary += array( + 'log_type' => LOG_MOD, + 'forum_id' => intval(array_shift($additional_data)), + 'topic_id' => intval(array_shift($additional_data)), + 'log_data' => (!sizeof($additional_data)) ? '' : serialize($additional_data), + ); + break; + + case 'user': + $sql_ary += array( + 'log_type' => LOG_USERS, + 'reportee_id' => intval(array_shift($additional_data)), + 'log_data' => (!sizeof($additional_data)) ? '' : serialize($additional_data), + ); + break; + + case 'critical': + $sql_ary += array( + 'log_type' => LOG_CRITICAL, + 'log_data' => (!sizeof($additional_data)) ? '' : serialize($additional_data), + ); + break; + + default: + /** + * @todo: enable when events are merged + * + if ($phpbb_dispatcher != null) + { + $vars = array('mode', 'user_id', 'log_ip', 'log_time', 'additional_data', 'sql_ary'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.add_log_case', $event); + extract($event->get_data_filtered($vars)); + } + */ + + // We didn't find a log_type, so we don't save it in the database. + if (!isset($sql_ary['log_type'])) + { + return false; + } + } + + /** + * @todo: enable when events are merged + * + if ($phpbb_dispatcher != null) + { + $vars = array('mode', 'user_id', 'log_ip', 'log_time', 'additional_data', 'sql_ary'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.add_log', $event); + extract($event->get_data_filtered($vars)); + } + */ + + $db->sql_query('INSERT INTO ' . $this->log_table . ' ' . $db->sql_build_array('INSERT', $sql_ary)); + + return $db->sql_nextid(); + } +} From 3fbac076ceb4773aa3c985d24eeaf306aa0b6a42 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 17 Mar 2012 23:52:01 +0100 Subject: [PATCH 040/234] [ticket/10714] Use new phpbb_log class in add_log function PHPBB3-10714 --- phpBB/includes/functions.php | 93 ++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index ecec1e5e4a..9a1485f37a 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3357,65 +3357,74 @@ function parse_cfg_file($filename, $lines = false) */ function add_log() { - global $db, $user; + // This is all just an ugly hack to add "Dependency Injection" to a function + // the only real code is the function call which maps this function to a method. + static $static_log = null; - // In phpBB 3.1.x i want to have logging in a class to be able to control it - // For now, we need a quite hakish approach to circumvent logging for some actions - // @todo implement cleanly - if (!empty($GLOBALS['skip_add_log'])) + $args = func_get_args(); + $log = (isset($args[0])) ? $args[0] : false; + + if ($log instanceof phpbb_log_interface) + { + $static_log = $log; + return true; + } + else if ($log === false) { return false; } - $args = func_get_args(); + $tmp_log = $static_log; - $mode = array_shift($args); - $reportee_id = ($mode == 'user') ? intval(array_shift($args)) : ''; - $forum_id = ($mode == 'mod') ? intval(array_shift($args)) : ''; - $topic_id = ($mode == 'mod') ? intval(array_shift($args)) : ''; - $action = array_shift($args); - $data = (!sizeof($args)) ? '' : serialize($args); + // no log class set, create a temporary one ourselves to keep backwards compatability + if ($tmp_log === null) + { + $tmp_log = new phpbb_log(LOG_TABLE); + } - $sql_ary = array( - 'user_id' => (empty($user->data)) ? ANONYMOUS : $user->data['user_id'], - 'log_ip' => $user->ip, - 'log_time' => time(), - 'log_operation' => $action, - 'log_data' => $data, - ); + $mode = array_shift($args); + // This looks kind of dirty, but add_log has some additional data before the log_operation + $additional_data = array(); switch ($mode) { case 'admin': - $sql_ary['log_type'] = LOG_ADMIN; - break; - - case 'mod': - $sql_ary += array( - 'log_type' => LOG_MOD, - 'forum_id' => $forum_id, - 'topic_id' => $topic_id - ); - break; - - case 'user': - $sql_ary += array( - 'log_type' => LOG_USERS, - 'reportee_id' => $reportee_id - ); - break; - case 'critical': - $sql_ary['log_type'] = LOG_CRITICAL; break; - + case 'mod': + // forum_id + $additional_data[] = array_shift($args); + // topic_id + $additional_data[] = array_shift($args); + break; + case 'user': + // reportee_id + $additional_data[] = array_shift($args); + break; default: - return false; + /** + * @todo: enable when events are merged + * + global $phpbb_dispatcher; + + if ($phpbb_dispatcher != null) + { + $vars = array('mode', 'args', 'additional_data'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.function_add_log', $event); + extract($event->get_data_filtered($vars)); + } + */ } + $log_operation = array_shift($args); + $additional_data = array_merge($additional_data, $args); - $db->sql_query('INSERT INTO ' . LOG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); + global $user; - return $db->sql_nextid(); + $user_id = (empty($user->data)) ? ANONYMOUS : $user->data['user_id']; + $user_ip = (empty($user->ip)) ? '' : $user->ip; + + return $tmp_log->add($mode, $user_id, $user_ip, $log_operation, time(), $additional_data); } /** From 34ce2561a0242c9066702e5fa9c92d0a6c77c2d2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 17 Mar 2012 23:52:47 +0100 Subject: [PATCH 041/234] [ticket/10714] Remove the dirty global hack to disable the log. PHPBB3-10714 --- phpBB/includes/functions_user.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 9e33a5122e..4074eaa2f2 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -299,8 +299,10 @@ function user_add($user_row, $cp_data = false) if ($add_group_id) { - // Because these actions only fill the log unneccessarily we skip the add_log() entry with a little hack. :/ - $GLOBALS['skip_add_log'] = true; + global $phpbb_log; + + // Because these actions only fill the log unneccessarily we skip the add_log() entry. + $phpbb_log->disable(); // Add user to "newly registered users" group and set to default group if admin specified so. if ($config['new_member_group_default']) @@ -313,7 +315,7 @@ function user_add($user_row, $cp_data = false) group_user_add($add_group_id, $user_id); } - unset($GLOBALS['skip_add_log']); + $phpbb_log->enable(); } } From 87eec7cfb66f6072344680743b04bf0186e8ca17 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 00:07:09 +0100 Subject: [PATCH 042/234] [ticket/10714] Create a phpbb_log object and inject it into add_log PHPBB3-10714 --- phpBB/common.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/common.php b/phpBB/common.php index c7c5859c25..bbcf8b894f 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -139,6 +139,10 @@ foreach ($cache->obtain_hooks() as $hook) @include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx); } +// make sure add_log uses this log instance +$phpbb_log = new phpbb_log(LOG_TABLE); +add_log($phpbb_log); // "dependency injection" for a function + if (!$config['use_system_cron']) { $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver()); From 7e80e4004e92ddcf3ad147d05d43bb411010e9e0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 12:07:41 +0100 Subject: [PATCH 043/234] [ticket/10714] Add unit tests for add_log function PHPBB3-10714 --- tests/log/fixtures/empty_log.xml | 15 +++ tests/log/function_add_log_test.php | 151 ++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 tests/log/fixtures/empty_log.xml create mode 100644 tests/log/function_add_log_test.php diff --git a/tests/log/fixtures/empty_log.xml b/tests/log/fixtures/empty_log.xml new file mode 100644 index 0000000000..261b6a622a --- /dev/null +++ b/tests/log/fixtures/empty_log.xml @@ -0,0 +1,15 @@ + + + + log_id + log_type + user_id + forum_id + topic_id + reportee_id + log_ip + log_time + log_operation + log_data +
+
diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php new file mode 100644 index 0000000000..05fae0f916 --- /dev/null +++ b/tests/log/function_add_log_test.php @@ -0,0 +1,151 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml'); + } + + public static function test_add_log_function_critical_data() + { + return array( + array( + array( + array( + 'user_id' => 2, + 'log_type' => LOG_CRITICAL, + 'log_operation' => 'LOG_NO_ADDITIONAL', + 'log_data' => '', + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, + ), + ), + 2, 'critical', 'LOG_NO_ADDITIONAL', + ), + array( + array( + array( + 'user_id' => 2, + 'log_type' => LOG_CRITICAL, + 'log_operation' => 'LOG_ONE_ADDITIONAL', + 'log_data' => 'a:1:{i:0;s:9:"argument1";}', + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, + ), + ), + 2, 'critical', 'LOG_ONE_ADDITIONAL', 'argument1', + ), + array( + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_ADMIN, + 'log_operation' => 'LOG_TWO_ADDITIONAL', + 'log_data' => 'a:2:{i:0;s:9:"argument1";i:1;s:9:"argument2";}', + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, + ), + ), + false, 'admin', 'LOG_TWO_ADDITIONAL', 'argument1', 'argument2', + ), + array( + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_USERS, + 'log_operation' => 'LOG_USERS_ADDITIONAL', + 'log_data' => 'a:1:{i:0;s:9:"argument2";}', + 'reportee_id' => 2, + 'forum_id' => 0, + 'topic_id' => 0, + ), + ), + false, 'user', 2, 'LOG_USERS_ADDITIONAL', 'argument2', + ), + array( + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_TOPIC_AND_FORUM', + 'log_data' => '', + 'reportee_id' => 0, + 'forum_id' => 12, + 'topic_id' => 34, + ), + ), + false, 'mod', 12, 34, 'LOG_MOD_TOPIC_AND_FORUM', + ), + array( + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_ADDITIONAL', + 'log_data' => 'a:1:{i:0;s:9:"argument3";}', + 'reportee_id' => 0, + 'forum_id' => 56, + 'topic_id' => 78, + ), + ), + false, 'mod', 56, 78, 'LOG_MOD_ADDITIONAL', 'argument3', + ), + array( + array( + ), + false, 'mode_does_not_exist', 'LOG_MOD_ADDITIONAL', 'argument1', + ), + ); + } + + /** + * @dataProvider test_add_log_function_critical_data + */ + public function test_add_log_function_critical($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) + { + global $db, $user; + + $db = $this->new_dbal(); + + $user->ip = 'user_ip'; + if ($user_id) + { + $user->data['user_id'] = $user_id; + } + + if ($additional3 != null) + { + add_log($mode, $required1, $additional1, $additional2, $additional3); + } + else if ($additional2 != null) + { + add_log($mode, $required1, $additional1, $additional2); + } + else if ($additional1 != null) + { + add_log($mode, $required1, $additional1); + } + else + { + add_log($mode, $required1); + } + + $result = $db->sql_query('SELECT user_id, log_type, log_operation, log_data, reportee_id, forum_id, topic_id + FROM ' . LOG_TABLE); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} From 72d875ebdee08f8c6af7c016b15d3e89442ed0e1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 12:23:32 +0100 Subject: [PATCH 044/234] [ticket/10714] Add unit tests for log class PHPBB3-10714 --- tests/log/add_test.php | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/log/add_test.php diff --git a/tests/log/add_test.php b/tests/log/add_test.php new file mode 100644 index 0000000000..a2b763f2b7 --- /dev/null +++ b/tests/log/add_test.php @@ -0,0 +1,56 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml'); + } + + public function test_log_enabled() + { + $log = new phpbb_log(LOG_TABLE); + $this->assertTrue($log->is_enabled()); + + $log->disable(); + $this->assertFalse($log->is_enabled()); + + $log->enable(); + $this->assertTrue($log->is_enabled()); + } + + public function test_log_add() + { + global $db; + + $db = $this->new_dbal(); + + $mode = 'critical'; + $user_id = ANONYMOUS; + $log_ip = 'user_ip'; + $log_time = time(); + $log_operation = 'LOG_OPERATION'; + $additional_data = array(); + + // Add an entry successful + $log = new phpbb_log(LOG_TABLE); + $this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time)); + + // Disable logging + $log->disable(); + $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time)); + $log->enable(); + + // Invalid mode specified + $this->assertFalse($log->add('mode_does_not_exist', $user_id, $log_ip, $log_operation, $log_time)); + } +} From 31e18f31a6139cddb32520aa6ed020dc8f80f70a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 13:40:56 +0100 Subject: [PATCH 045/234] [ticket/10714] Serialize the log_data in the testinsteadof hardcoding it PHPBB3-10714 --- tests/log/function_add_log_test.php | 107 +++++++++++++++------------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 05fae0f916..407aeb9ad1 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -21,85 +21,82 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case return array( array( array( - array( - 'user_id' => 2, - 'log_type' => LOG_CRITICAL, - 'log_operation' => 'LOG_NO_ADDITIONAL', - 'log_data' => '', - 'reportee_id' => 0, - 'forum_id' => 0, - 'topic_id' => 0, - ), + 'user_id' => 2, + 'log_type' => LOG_CRITICAL, + 'log_operation' => 'LOG_NO_ADDITIONAL', + 'log_data' => '', + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, ), 2, 'critical', 'LOG_NO_ADDITIONAL', ), array( array( - array( - 'user_id' => 2, - 'log_type' => LOG_CRITICAL, - 'log_operation' => 'LOG_ONE_ADDITIONAL', - 'log_data' => 'a:1:{i:0;s:9:"argument1";}', - 'reportee_id' => 0, - 'forum_id' => 0, - 'topic_id' => 0, + 'user_id' => 2, + 'log_type' => LOG_CRITICAL, + 'log_operation' => 'LOG_ONE_ADDITIONAL', + 'log_data' => array( + 'argument1', ), + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, ), 2, 'critical', 'LOG_ONE_ADDITIONAL', 'argument1', ), array( array( - array( - 'user_id' => ANONYMOUS, - 'log_type' => LOG_ADMIN, - 'log_operation' => 'LOG_TWO_ADDITIONAL', - 'log_data' => 'a:2:{i:0;s:9:"argument1";i:1;s:9:"argument2";}', - 'reportee_id' => 0, - 'forum_id' => 0, - 'topic_id' => 0, + 'user_id' => ANONYMOUS, + 'log_type' => LOG_ADMIN, + 'log_operation' => 'LOG_TWO_ADDITIONAL', + 'log_data' => array( + 'argument1', + 'argument2', ), + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, ), false, 'admin', 'LOG_TWO_ADDITIONAL', 'argument1', 'argument2', ), array( array( - array( - 'user_id' => ANONYMOUS, - 'log_type' => LOG_USERS, - 'log_operation' => 'LOG_USERS_ADDITIONAL', - 'log_data' => 'a:1:{i:0;s:9:"argument2";}', - 'reportee_id' => 2, - 'forum_id' => 0, - 'topic_id' => 0, + 'user_id' => ANONYMOUS, + 'log_type' => LOG_USERS, + 'log_operation' => 'LOG_USERS_ADDITIONAL', + 'log_data' => array( + 'argument2', ), + 'reportee_id' => 2, + 'forum_id' => 0, + 'topic_id' => 0, ), false, 'user', 2, 'LOG_USERS_ADDITIONAL', 'argument2', ), array( array( - array( - 'user_id' => ANONYMOUS, - 'log_type' => LOG_MOD, - 'log_operation' => 'LOG_MOD_TOPIC_AND_FORUM', - 'log_data' => '', - 'reportee_id' => 0, - 'forum_id' => 12, - 'topic_id' => 34, - ), + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_TOPIC_AND_FORUM', + 'log_data' => '', + 'reportee_id' => 0, + 'forum_id' => 12, + 'topic_id' => 34, ), false, 'mod', 12, 34, 'LOG_MOD_TOPIC_AND_FORUM', ), array( array( - array( - 'user_id' => ANONYMOUS, - 'log_type' => LOG_MOD, - 'log_operation' => 'LOG_MOD_ADDITIONAL', - 'log_data' => 'a:1:{i:0;s:9:"argument3";}', - 'reportee_id' => 0, - 'forum_id' => 56, - 'topic_id' => 78, + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_ADDITIONAL', + 'log_data' => array( + 'argument3', ), + 'reportee_id' => 0, + 'forum_id' => 56, + 'topic_id' => 78, ), false, 'mod', 56, 78, 'LOG_MOD_ADDITIONAL', 'argument3', ), @@ -118,6 +115,16 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case { global $db, $user; + if ($expected) + { + // Serialize the log data if we have some + if (is_array($expected['log_data'])) + { + $expected['log_data'] = serialize($expected['log_data']); + } + $expected = array($expected); + } + $db = $this->new_dbal(); $user->ip = 'user_ip'; From 1539ad7ebe1493e4c486181f65976c93dbb95c29 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 13:42:08 +0100 Subject: [PATCH 046/234] [ticket/10714] Add @return null to doc blocks PHPBB3-10714 --- phpBB/includes/log/interface.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/includes/log/interface.php b/phpBB/includes/log/interface.php index 897b8a8211..7eda4b9710 100644 --- a/phpBB/includes/log/interface.php +++ b/phpBB/includes/log/interface.php @@ -31,11 +31,15 @@ interface phpbb_log_interface /** * This function allows disable the log-system. When add_log is called, the log will not be added to the database. + * + * @return null */ public function disable(); /** * This function allows re-enable the log-system. + * + * @return null */ public function enable(); From cff15ec307d76b004b6a825fb51b5dd3c8da58f2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 13:47:24 +0100 Subject: [PATCH 047/234] [ticket/10714] Use keys for the log data instead of requiring a special order PHPBB3-10714 --- phpBB/includes/functions.php | 9 +++------ phpBB/includes/log/log.php | 13 ++++++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9a1485f37a..3e3d796ba2 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3392,14 +3392,11 @@ function add_log() case 'critical': break; case 'mod': - // forum_id - $additional_data[] = array_shift($args); - // topic_id - $additional_data[] = array_shift($args); + $additional_data['forum_id'] = array_shift($args); + $additional_data['topic_id'] = array_shift($args); break; case 'user': - // reportee_id - $additional_data[] = array_shift($args); + $additional_data['reportee_id'] = array_shift($args); break; default: /** diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 89dc22593e..2523b97dbe 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -115,18 +115,25 @@ class phpbb_log implements phpbb_log_interface break; case 'mod': + $forum_id = (int) $additional_data['forum_id']; + unset($additional_data['forum_id']); + $topic_id = (int) $additional_data['topic_id']; + unset($additional_data['topic_id']); $sql_ary += array( 'log_type' => LOG_MOD, - 'forum_id' => intval(array_shift($additional_data)), - 'topic_id' => intval(array_shift($additional_data)), + 'forum_id' => $forum_id, + 'topic_id' => $topic_id, 'log_data' => (!sizeof($additional_data)) ? '' : serialize($additional_data), ); break; case 'user': + $reportee_id = (int) $additional_data['reportee_id']; + unset($additional_data['reportee_id']); + $sql_ary += array( 'log_type' => LOG_USERS, - 'reportee_id' => intval(array_shift($additional_data)), + 'reportee_id' => $reportee_id, 'log_data' => (!sizeof($additional_data)) ? '' : serialize($additional_data), ); break; From b9b08cf765d7feb2865477bb82ab58e8cfb0c156 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 13:54:33 +0100 Subject: [PATCH 048/234] [ticket/10714] Add return null to phpbb_log and add param to constructor PHPBB3-10714 --- phpBB/includes/log/log.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 2523b97dbe..67336d232a 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -34,6 +34,8 @@ class phpbb_log implements phpbb_log_interface /** * Constructor + * + * @param string $log_table The table we use to store our logs */ public function __construct($log_table) { @@ -53,6 +55,8 @@ class phpbb_log implements phpbb_log_interface /** * This function allows disable the log-system. When add_log is called, the log will not be added to the database. + * + * @return null */ public function disable() { @@ -61,6 +65,8 @@ class phpbb_log implements phpbb_log_interface /** * This function allows re-enable the log-system. + * + * @return null */ public function enable() { From 61cbabb120dfca6d924fbb08645f6dfbbcc5c1ec Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 13:59:32 +0100 Subject: [PATCH 049/234] [ticket/10714] Add missing log_operation to events in phpbb_log PHPBB3-10714 --- phpBB/includes/log/log.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 67336d232a..db774e48d5 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -157,7 +157,7 @@ class phpbb_log implements phpbb_log_interface * if ($phpbb_dispatcher != null) { - $vars = array('mode', 'user_id', 'log_ip', 'log_time', 'additional_data', 'sql_ary'); + $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); $event = new phpbb_event_data(compact($vars)); $phpbb_dispatcher->dispatch('core.add_log_case', $event); extract($event->get_data_filtered($vars)); @@ -176,7 +176,7 @@ class phpbb_log implements phpbb_log_interface * if ($phpbb_dispatcher != null) { - $vars = array('mode', 'user_id', 'log_ip', 'log_time', 'additional_data', 'sql_ary'); + $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); $event = new phpbb_event_data(compact($vars)); $phpbb_dispatcher->dispatch('core.add_log', $event); extract($event->get_data_filtered($vars)); From a0b35f8e4e94d1301421670cf35406b974510ed0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 21:56:15 +0100 Subject: [PATCH 050/234] [ticket/10714] Use {@inheritDoc} instead of repeating the doc-block PHPBB3-10714 --- phpBB/includes/log/log.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index db774e48d5..aa60c453e4 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -76,14 +76,7 @@ class phpbb_log implements phpbb_log_interface /** * Adds a log to the database * - * @param string $mode The mode defines which log_type is used and in which log the entry is displayed. - * @param int $user_id User ID of the user - * @param string $log_ip IP address of the user - * @param string $log_operation Name of the operation - * @param int $log_time Timestamp when the log was added. - * @param array $additional_data More arguments can be added, depending on the log_type - * - * @return int|bool Returns the log_id, if the entry was added to the database, false otherwise. + * {@inheritDoc} */ public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array()) { From ea652f0ec9e7046f329e692fc355e64836f9bf9d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 21 Mar 2012 13:33:25 +0100 Subject: [PATCH 051/234] [ticket/10714] Rename add_log_function test PHPBB3-10714 --- tests/log/function_add_log_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 407aeb9ad1..1f54f66d2d 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -16,7 +16,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml'); } - public static function test_add_log_function_critical_data() + public static function test_add_log_function_data() { return array( array( @@ -109,9 +109,9 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case } /** - * @dataProvider test_add_log_function_critical_data + * @dataProvider test_add_log_function_data */ - public function test_add_log_function_critical($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) + public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) { global $db, $user; From 920cb1a0de10febca3c78ef13286a49838656ab2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 21 Mar 2012 13:38:02 +0100 Subject: [PATCH 052/234] [ticket/10714] Add unit tests for view_log function PHPBB3-10714 --- tests/log/fixtures/full_log.xml | 166 +++++++++++++ tests/log/function_view_log_test.php | 341 +++++++++++++++++++++++++++ 2 files changed, 507 insertions(+) create mode 100644 tests/log/fixtures/full_log.xml create mode 100644 tests/log/function_view_log_test.php diff --git a/tests/log/fixtures/full_log.xml b/tests/log/fixtures/full_log.xml new file mode 100644 index 0000000000..2ce2643d26 --- /dev/null +++ b/tests/log/fixtures/full_log.xml @@ -0,0 +1,166 @@ + + + + log_id + log_type + user_id + forum_id + topic_id + reportee_id + log_ip + log_time + log_operation + log_data + + 1 + 0 + 1 + 0 + 0 + 0 + 127.0.0.1 + 1 + LOG_INSTALL_INSTALLED + a:1:{i:0;s:9:"3.1.0-dev";} + + + 2 + 0 + 1 + 0 + 0 + 0 + 127.0.0.1 + 1 + LOG_KEY_NOT_EXISTS + a:1:{i:0;s:15:"additional_data";} + + + 3 + 2 + 1 + 0 + 0 + 0 + 127.0.0.1 + 1 + LOG_CRITICAL + a:1:{i:0;s:13:"critical data";} + + + 4 + 1 + 1 + 12 + 34 + 0 + 127.0.0.1 + 1 + LOG_MOD + + + + 5 + 1 + 1 + 12 + 45 + 0 + 127.0.0.1 + 1 + LOG_MOD + + + + 6 + 1 + 1 + 23 + 56 + 0 + 127.0.0.1 + 1 + LOG_MOD + + + + 7 + 1 + 1 + 12 + 45 + 0 + 127.0.0.1 + 1 + LOG_MOD2 + + + + 8 + 3 + 1 + 0 + 0 + 2 + 127.0.0.1 + 1 + LOG_USER + a:1:{i:0;s:5:"admin";} + + + 9 + 3 + 1 + 0 + 0 + 1 + 127.0.0.1 + 1 + LOG_USER + a:1:{i:0;s:5:"guest";} + +
+ + user_id + username + username_clean + user_permissions + user_sig + user_occ + user_interests + + 1 + Anonymous + Anonymous + + + + + + + 2 + admin + admin + + + + + +
+ + topic_id + forum_id + + 34 + 12 + + + 45 + 12 + + + 56 + 23 + +
+
diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php new file mode 100644 index 0000000000..7c44413330 --- /dev/null +++ b/tests/log/function_view_log_test.php @@ -0,0 +1,341 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/full_log.xml'); + } + + public static function test_view_log_function_data() + { + global $phpEx; + + $expected_data_sets = array( + 1 => array( + 'id' => 1, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => 'installed: 3.1.0-dev', + ), + 2 => array( + 'id' => 2, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG KEY NOT EXISTS}
additional_data', + ), + 3 => array( + 'id' => 3, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG CRITICAL}
critical data', + ), + 4 => array( + 'id' => 4, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 12, + 'topic_id' => 34, + + 'viewforum' => '', + 'action' => '{LOG MOD}', + 'viewtopic' => '', + 'viewlogs' => '', + ), + 5 => array( + 'id' => 5, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 12, + 'topic_id' => 45, + + 'viewforum' => '', + 'action' => '{LOG MOD}', + 'viewtopic' => '', + 'viewlogs' => '', + ), + 6 => array( + 'id' => 6, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 23, + 'topic_id' => 56, + + 'viewforum' => append_sid("phpBB/viewforum.$phpEx", 'f=23'), + 'action' => '{LOG MOD}', + 'viewtopic' => append_sid("phpBB/viewtopic.$phpEx", 'f=23&t=56'), + 'viewlogs' => append_sid("phpBB/mcp.$phpEx", 'i=logs&mode=topic_logs&t=56'), + ), + 7 => array( + 'id' => 7, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 12, + 'topic_id' => 45, + + 'viewforum' => '', + 'action' => '{LOG MOD2}', + 'viewtopic' => '', + 'viewlogs' => '', + ), + 8 => array( + 'id' => 8, + + 'reportee_id' => 2, + 'reportee_username' => 'admin', + 'reportee_username_full'=> 'admin', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG USER}
admin', + ), + 9 => array( + 'id' => 9, + + 'reportee_id' => 1, + 'reportee_username' => 'Anonymous', + 'reportee_username_full'=> 'Anonymous', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG USER}
guest', + ), + ); + + $test_cases = array( + array( + 'expected' => array(1, 2), + 'expected_returned' => 0, + false, + 'admin', + ), + array( + 'expected' => array(1), + 'expected_returned' => 0, + false, + 'admin', 1, + ), + array( + 'expected' => array(2), + 'expected_returned' => 1, + false, + 'admin', 1, 1, + ), + array( + 'expected' => array(2), + 'expected_returned' => 1, + 0, + 'admin', 1, 1, + ), + array( + 'expected' => array(2), + 'expected_returned' => 1, + 0, + 'admin', 1, 5, + ), + array( + 'expected' => array(3), + 'expected_returned' => 0, + false, + 'critical', + ), + array( + 'expected' => array(), + 'expected_returned' => null, + false, + 'mode_does_not_exist', + ), + array( + 'expected' => array(4, 5, 7), + 'expected_returned' => 0, + 0, + 'mod', 5, 0, 12, + ), + array( + 'expected' => array(5, 7), + 'expected_returned' => 0, + 0, + 'mod', 5, 0, 12, 45, + ), + array( + 'expected' => array(6), + 'expected_returned' => 0, + 0, + 'mod', 5, 0, 23, + ), + array( + 'expected' => array(8), + 'expected_returned' => 0, + 0, + 'user', 5, 0, 0, 0, 2, + ), + array( + 'expected' => array(8, 9), + 'expected_returned' => 0, + 0, + 'users', + ), + ); + + foreach ($test_cases as $case => $case_data) + { + foreach ($case_data['expected'] as $data_set => $expected) + { + $test_cases[$case]['expected'][$data_set] = $expected_data_sets[$expected]; + } + } + + return $test_cases; + } + + /** + * @dataProvider test_view_log_function_data + */ + public function test_view_log_function($expected, $expected_returned, $log_count, $mode, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '') + { + global $cache, $db, $user, $auth; + + $db = $this->new_dbal(); + $cache = new phpbb_mock_cache; + + // Create auth mock + $auth = $this->getMock('auth'); + $acl_get_map = array( + array('f_read', 23, true), + array('m_', 23, true), + ); + $acl_gets_map = array( + array('a_', 'm_', 23, true), + ); + + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap($acl_get_map)); + $auth->expects($this->any()) + ->method('acl_gets') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap($acl_gets_map)); + + $user = new phpbb_mock_user; + $user->optionset('viewcensors', false); + // Test sprintf() of the data into the action + $user->lang = array( + 'LOG_INSTALL_INSTALLED' => 'installed: %s', + ); + + $log = array(); + $this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords)); + + $this->assertEquals($expected, $log); + } +} From 91384d8395166ec21995103410e35f7ba28ac830 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 15:05:02 +0100 Subject: [PATCH 053/234] [ticket/10714] Add casts to integer values. PHPBB3-10714 --- phpBB/includes/functions_admin.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 5e2ee8c8f6..e05ed3cdde 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2603,6 +2603,7 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id $log = array(); while ($row = $db->sql_fetchrow($result)) { + $row['forum_id'] = (int) $row['forum_id']; if ($row['topic_id']) { $topic_id_list[] = $row['topic_id']; @@ -2614,20 +2615,20 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id } $log[$i] = array( - 'id' => $row['log_id'], + 'id' => (int) $row['log_id'], - 'reportee_id' => $row['reportee_id'], + 'reportee_id' => (int) $row['reportee_id'], 'reportee_username' => '', 'reportee_username_full'=> '', - 'user_id' => $row['user_id'], + 'user_id' => (int) $row['user_id'], 'username' => $row['username'], 'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, $profile_url), 'ip' => $row['log_ip'], - 'time' => $row['log_time'], - 'forum_id' => $row['forum_id'], - 'topic_id' => $row['topic_id'], + 'time' => (int) $row['log_time'], + 'forum_id' => (int) $row['forum_id'], + 'topic_id' => (int) $row['topic_id'], 'viewforum' => ($row['forum_id'] && $auth->acl_get('f_read', $row['forum_id'])) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : false, 'action' => (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}', @@ -2689,6 +2690,7 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id while ($row = $db->sql_fetchrow($result)) { + $row['forum_id'] = (int) $row['forum_id']; if ($auth->acl_get('f_read', $row['forum_id'])) { $is_auth[$row['topic_id']] = $row['forum_id']; From f5063a6eda49d2a35b2aed486f86cde76e0f04a8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 15:06:13 +0100 Subject: [PATCH 054/234] [ticket/10714] Add incorrect offset calculation in view_log function PHPBB3-10714 --- phpBB/includes/functions_admin.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index e05ed3cdde..fd1f5568ab 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2584,9 +2584,13 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id return 0; } - if ($offset >= $log_count) + if ($log_count) { - $offset = ($offset - $limit < 0) ? 0 : $offset - $limit; + // Return the user to the last page that is valid + while ($offset >= $log_count) + { + $offset = ($offset - $limit < 0) ? 0 : $offset - $limit; + } } $sql = "SELECT l.*, u.username, u.username_clean, u.user_colour From 9248b9b25fdc3c05cc9fb1e99f607817f8ec7bcb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 15:06:32 +0100 Subject: [PATCH 055/234] [ticket/10714] Add doc block for view_log function PHPBB3-10714 --- phpBB/includes/functions_admin.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index fd1f5568ab..49c34f7fff 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2470,7 +2470,21 @@ function cache_moderators() /** * View log -* If $log_count is set to false, we will skip counting all entries in the database. +* +* @param string $mode The mode defines which log_type is used and in which log the entry is displayed. +* @param array &$log The result array with the logs +* @param mixed &$log_count If $log_count is set to false, we will skip counting all entries in the database. +* Otherwise an integer with the number of total matching entries is returned. +* @param int $limit Limit the number of entries that are returned +* @param int $offset Offset when fetching the log entries, f.e. on paginations +* @param mixed $forum_id Restrict the log entries to the given forum_id (can also be an array of forum_ids) +* @param int $topic_id Restrict the log entries to the given topic_id +* @param int $user_id Restrict the log entries to the given user_id +* @param int $log_time Only get log entries newer than the given timestamp +* @param string $sort_by SQL order option, e.g. 'l.log_time DESC' +* @param string $keywords Will only return log entries that have the keywords in log_operation or log_data +* +* @return int Returns the offset of the last valid page, if the specified offset was invalid (too high) */ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '') { From 55b94af82ecb7e73535bfbed6c278f1d992efecb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 16:27:52 +0100 Subject: [PATCH 056/234] [ticket/10714] Implement get_logs() based on view_log() I moved some stuff into its own function to make the code a bit clearer. PHPBB3-10714 --- phpBB/includes/log/interface.php | 64 +++++ phpBB/includes/log/log.php | 406 +++++++++++++++++++++++++++++++ 2 files changed, 470 insertions(+) diff --git a/phpBB/includes/log/interface.php b/phpBB/includes/log/interface.php index 7eda4b9710..fde718b71a 100644 --- a/phpBB/includes/log/interface.php +++ b/phpBB/includes/log/interface.php @@ -56,4 +56,68 @@ interface phpbb_log_interface * @return int|bool Returns the log_id, if the entry was added to the database, false otherwise. */ public function add($mode, $user_id, $log_ip, $log_operation, $log_time, $additional_data); + + /** + * Grab the logs from the database + * + * @param string $mode The mode defines which log_type is used and in which log the entry is displayed. + * @param bool $count_logs Shall we count all matching log entries? + * @param int $limit Limit the number of entries that are returned + * @param int $offset Offset when fetching the log entries, f.e. on paginations + * @param mixed $forum_id Restrict the log entries to the given forum_id (can also be an array of forum_ids) + * @param int $topic_id Restrict the log entries to the given topic_id + * @param int $user_id Restrict the log entries to the given user_id + * @param int $log_time Only get log entries newer than the given timestamp + * @param string $sort_by SQL order option, e.g. 'l.log_time DESC' + * @param string $keywords Will only return log entries that have the keywords in log_operation or log_data + * + * @return array The result array with the logs + */ + public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = ''); + + /** + * Generates a sql condition out of the specified keywords + * + * @param string $keywords The keywords the user specified to search for + * + * @return string Returns the SQL condition searching for the keywords + */ + static public function generate_sql_keyword($keywords); + + /** + * Determinate whether the user is allowed to read and/or moderate the forum of the topic + * + * @param array $topic_ids Array with the topic ids + * + * @return array Returns an array with two keys 'm_' and 'read_f' which are also an array of topic_id => forum_id sets when the permissions are given. Sample: + * array( + * 'permission' => array( + * topic_id => forum_id + * ), + * ), + */ + static public function get_topic_auth($topic_ids); + + /** + * Get the data for all reportee form the database + * + * @param array $reportee_ids Array with the user ids of the reportees + * + * @return array Returns an array with the reportee data + */ + static public function get_reportee_data($reportee_ids); + + /** + * Get total log count + * + * @return int Returns the number of matching logs from the last call to get_logs() + */ + public function get_log_count(); + + /** + * Get offset of the last valid page + * + * @return int Returns the offset of the last valid page from the last call to get_logs() + */ + public function get_valid_offset(); } diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index aa60c453e4..14f8bfd534 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -27,6 +27,16 @@ class phpbb_log implements phpbb_log_interface */ private $enabled; + /** + * Keeps the total log count of the last call to get_logs() + */ + private $logs_total; + + /** + * Keeps the offset of the last valid page of the last call to get_logs() + */ + private $logs_offset; + /** * The table we use to store our logs. */ @@ -180,4 +190,400 @@ class phpbb_log implements phpbb_log_interface return $db->sql_nextid(); } + + /** + * Grab the logs from the database + * + * {@inheritDoc} + */ + public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '') + { + global $db, $user, $auth, $phpEx, $phpbb_root_path, $phpbb_admin_path; + + $this->logs_total = 0; + $this->logs_offset = $offset; + + $topic_id_list = $reportee_id_list = array(); + + $profile_url = (defined('IN_ADMIN')) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview') : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile'); + + switch ($mode) + { + case 'admin': + $log_type = LOG_ADMIN; + $sql_additional = ''; + break; + + case 'mod': + $log_type = LOG_MOD; + $sql_additional = ''; + + if ($topic_id) + { + $sql_additional = 'AND l.topic_id = ' . (int) $topic_id; + } + else if (is_array($forum_id)) + { + $sql_additional = 'AND ' . $db->sql_in_set('l.forum_id', array_map('intval', $forum_id)); + } + else if ($forum_id) + { + $sql_additional = 'AND l.forum_id = ' . (int) $forum_id; + } + break; + + case 'user': + $log_type = LOG_USERS; + $sql_additional = 'AND l.reportee_id = ' . (int) $user_id; + break; + + case 'users': + $log_type = LOG_USERS; + $sql_additional = ''; + break; + + case 'critical': + $log_type = LOG_CRITICAL; + $sql_additional = ''; + break; + + default: + $log_type = null; + $sql_additional = ''; + /** + * @todo: enable when events are merged + * + if ($phpbb_dispatcher != null) + { + $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.get_logs_switch_mode', $event); + extract($event->get_data_filtered($vars)); + } + */ + + if (!isset($log_type)) + { + $this->logs_offset = 0; + return array(); + } + } + + /** + * @todo: enable when events are merged + * + if ($phpbb_dispatcher != null) + { + $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.get_logs_after_get_type', $event); + extract($event->get_data_filtered($vars)); + } + */ + + $sql_keywords = ''; + if (!empty($keywords)) + { + // Get the SQL condition for our keywords + $sql_keywords = self::generate_sql_keyword($keywords); + } + + if ($count_logs) + { + $sql = 'SELECT COUNT(l.log_id) AS total_entries + FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u + WHERE l.log_type = $log_type + AND l.user_id = u.user_id + AND l.log_time >= $log_time + $sql_keywords + $sql_additional"; + $result = $db->sql_query($sql); + $this->logs_total = (int) $db->sql_fetchfield('total_entries'); + $db->sql_freeresult($result); + + if ($this->logs_total == 0) + { + // Save the queries, because there are no logs to display + $this->logs_offset = 0; + return array(); + } + + // Return the user to the last page that is valid + while ($this->logs_offset >= $this->logs_total) + { + $this->logs_offset = ($this->logs_offset - $limit < 0) ? 0 : $this->logs_offset - $limit; + } + } + + $sql = "SELECT l.*, u.username, u.username_clean, u.user_colour + FROM " . LOG_TABLE . " l, " . USERS_TABLE . " u + WHERE l.log_type = $log_type + AND u.user_id = l.user_id + " . (($log_time) ? "AND l.log_time >= $log_time" : '') . " + $sql_keywords + $sql_additional + ORDER BY $sort_by"; + $result = $db->sql_query_limit($sql, $limit, $this->logs_offset); + + $i = 0; + $log = array(); + while ($row = $db->sql_fetchrow($result)) + { + $row['forum_id'] = (int) $row['forum_id']; + if ($row['topic_id']) + { + $topic_id_list[] = (int) $row['topic_id']; + } + + if ($row['reportee_id']) + { + $reportee_id_list[] = (int) $row['reportee_id']; + } + + $log_entry_data = array( + 'id' => (int) $row['log_id'], + + 'reportee_id' => (int) $row['reportee_id'], + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => (int) $row['user_id'], + 'username' => $row['username'], + 'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, $profile_url), + + 'ip' => $row['log_ip'], + 'time' => (int) $row['log_time'], + 'forum_id' => (int) $row['forum_id'], + 'topic_id' => (int) $row['topic_id'], + + 'viewforum' => ($row['forum_id'] && $auth->acl_get('f_read', $row['forum_id'])) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : false, + 'action' => (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}', + ); + + /** + * @todo: enable when events are merged + * + if ($phpbb_dispatcher != null) + { + $vars = array('log_entry_data', 'row'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.get_logs_entry_data', $event); + extract($event->get_data_filtered($vars)); + } + */ + + $log[$i] = $log_entry_data; + + if (!empty($row['log_data'])) + { + $log_data_ary = @unserialize($row['log_data']); + $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary; + + if (isset($user->lang[$row['log_operation']])) + { + // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array + // It doesn't matter if we add more arguments than placeholders + if ((substr_count($log[$i]['action'], '%') - sizeof($log_data_ary)) > 0) + { + $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($log[$i]['action'], '%') - sizeof($log_data_ary), '')); + } + + $log[$i]['action'] = vsprintf($log[$i]['action'], $log_data_ary); + + // If within the admin panel we do not censor text out + if (defined('IN_ADMIN')) + { + $log[$i]['action'] = bbcode_nl2br($log[$i]['action']); + } + else + { + $log[$i]['action'] = bbcode_nl2br(censor_text($log[$i]['action'])); + } + } + else if (!empty($log_data_ary)) + { + $log[$i]['action'] .= '
' . implode('', $log_data_ary); + } + + /* Apply make_clickable... has to be seen if it is for good. :/ + // Seems to be not for the moment, reconsider later... + $log[$i]['action'] = make_clickable($log[$i]['action']); + */ + } + + $i++; + } + $db->sql_freeresult($result); + + /** + * @todo: enable when events are merged + * + if ($phpbb_dispatcher != null) + { + $vars = array('log', 'topic_id_list', 'reportee_id_list'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.get_logs_additional_data', $event); + extract($event->get_data_filtered($vars)); + } + */ + + if (sizeof($topic_id_list)) + { + $topic_auth = self::get_topic_auth($topic_id_list); + + foreach ($log as $key => $row) + { + $log[$key]['viewtopic'] = (isset($topic_auth['f_read'][$row['topic_id']])) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_auth['f_read'][$row['topic_id']] . '&t=' . $row['topic_id']) : false; + $log[$key]['viewlogs'] = (isset($topic_auth['m_'][$row['topic_id']])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=logs&mode=topic_logs&t=' . $row['topic_id'], true, $user->session_id) : false; + } + } + + if (sizeof($reportee_id_list)) + { + $reportee_data_list = self::get_reportee_data($reportee_id_list); + + foreach ($log as $key => $row) + { + if (!isset($reportee_data_list[$row['reportee_id']])) + { + continue; + } + + $log[$key]['reportee_username'] = $reportee_data_list[$row['reportee_id']]['username']; + $log[$key]['reportee_username_full'] = get_username_string('full', $row['reportee_id'], $reportee_data_list[$row['reportee_id']]['username'], $reportee_data_list[$row['reportee_id']]['user_colour'], false, $profile_url); + } + } + + return $log; + } + + /** + * Generates a sql condition out of the specified keywords + * + * {@inheritDoc} + */ + static public function generate_sql_keyword($keywords) + { + global $db, $user; + + // Use no preg_quote for $keywords because this would lead to sole backslashes being added + // We also use an OR connection here for spaces and the | string. Currently, regex is not supported for searching (but may come later). + $keywords = preg_split('#[\s|]+#u', utf8_strtolower($keywords), 0, PREG_SPLIT_NO_EMPTY); + $sql_keywords = ''; + + if (!empty($keywords)) + { + $keywords_pattern = array(); + + // Build pattern and keywords... + for ($i = 0, $num_keywords = sizeof($keywords); $i < $num_keywords; $i++) + { + $keywords_pattern[] = preg_quote($keywords[$i], '#'); + $keywords[$i] = $db->sql_like_expression($db->any_char . $keywords[$i] . $db->any_char); + } + + $keywords_pattern = '#' . implode('|', $keywords_pattern) . '#ui'; + + $operations = array(); + foreach ($user->lang as $key => $value) + { + if (substr($key, 0, 4) == 'LOG_' && preg_match($keywords_pattern, $value)) + { + $operations[] = $key; + } + } + + $sql_keywords = 'AND ('; + if (!empty($operations)) + { + $sql_keywords .= $db->sql_in_set('l.log_operation', $operations) . ' OR '; + } + $sql_keywords .= 'LOWER(l.log_data) ' . implode(' OR LOWER(l.log_data) ', $keywords) . ')'; + } + + return $sql_keywords; + } + + /** + * Determinate whether the user is allowed to read and/or moderate the forum of the topic + * + * {@inheritDoc} + */ + static public function get_topic_auth($topic_ids) + { + global $auth, $db; + + $forum_auth = array('f_read' => array(), 'm_' => array()); + $topic_ids = array_unique($topic_ids); + + $sql = 'SELECT topic_id, forum_id + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', array_map('intval', $topic_ids)); + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $row['topic_id'] = (int) $row['topic_id']; + $row['forum_id'] = (int) $row['forum_id']; + + if ($auth->acl_get('f_read', $row['forum_id'])) + { + $forum_auth['f_read'][$row['topic_id']] = $row['forum_id']; + } + + if ($auth->acl_gets('a_', 'm_', $row['forum_id'])) + { + $forum_auth['m_'][$row['topic_id']] = $row['forum_id']; + } + } + $db->sql_freeresult($result); + + return $forum_auth; + } + + /** + * Get the data for all reportee form the database + * + * {@inheritDoc} + */ + static public function get_reportee_data($reportee_ids) + { + global $db; + + $reportee_ids = array_unique($reportee_ids); + $reportee_data_list = array(); + + $sql = 'SELECT user_id, username, user_colour + FROM ' . USERS_TABLE . ' + WHERE ' . $db->sql_in_set('user_id', $reportee_ids); + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $reportee_data_list[$row['user_id']] = $row; + } + $db->sql_freeresult($result); + + return $reportee_data_list; + } + + /** + * Get total log count + * + * @return int Returns the number of matching logs from the last call to get_logs() + */ + public function get_log_count() + { + return ($this->logs_total) ? $this->logs_total : 0; + } + + /** + * Get offset of the last valid log page + * + * @return int Returns the offset of the last valid page from the last call to get_logs() + */ + public function get_valid_offset() + { + return ($this->logs_offset) ? $this->logs_offset : 0; + } } From 97290647fae683ecce842541a682e3403b7717ee Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 16:39:03 +0100 Subject: [PATCH 057/234] [ticket/10714] Use phpbb_log class in view_log() PHPBB3-10714 --- phpBB/includes/functions_admin.php | 277 ++--------------------------- phpBB/includes/log/log.php | 105 +++++++---- 2 files changed, 87 insertions(+), 295 deletions(-) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 49c34f7fff..e7aed85e15 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2488,275 +2488,34 @@ function cache_moderators() */ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '') { - global $db, $user, $auth, $phpEx, $phpbb_root_path, $phpbb_admin_path; + // This is all just an ugly hack to add "Dependency Injection" to a function + // the only real code is the function call which maps this function to a method. + static $static_log = null; - $topic_id_list = $reportee_id_list = $is_auth = $is_mod = array(); - - $profile_url = (defined('IN_ADMIN')) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview') : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile'); - - switch ($mode) + if ($mode instanceof phpbb_log_interface) { - case 'admin': - $log_type = LOG_ADMIN; - $sql_forum = ''; - break; - - case 'mod': - $log_type = LOG_MOD; - $sql_forum = ''; - - if ($topic_id) - { - $sql_forum = 'AND l.topic_id = ' . (int) $topic_id; - } - else if (is_array($forum_id)) - { - $sql_forum = 'AND ' . $db->sql_in_set('l.forum_id', array_map('intval', $forum_id)); - } - else if ($forum_id) - { - $sql_forum = 'AND l.forum_id = ' . (int) $forum_id; - } - break; - - case 'user': - $log_type = LOG_USERS; - $sql_forum = 'AND l.reportee_id = ' . (int) $user_id; - break; - - case 'users': - $log_type = LOG_USERS; - $sql_forum = ''; - break; - - case 'critical': - $log_type = LOG_CRITICAL; - $sql_forum = ''; - break; - - default: - return; + $static_log = $mode; + return true; + } + else if ($mode === false) + { + return false; } - // Use no preg_quote for $keywords because this would lead to sole backslashes being added - // We also use an OR connection here for spaces and the | string. Currently, regex is not supported for searching (but may come later). - $keywords = preg_split('#[\s|]+#u', utf8_strtolower($keywords), 0, PREG_SPLIT_NO_EMPTY); - $sql_keywords = ''; + $tmp_log = $static_log; - if (!empty($keywords)) + // no log class set, create a temporary one ourselves to keep backwards compatability + if ($tmp_log === null) { - $keywords_pattern = array(); - - // Build pattern and keywords... - for ($i = 0, $num_keywords = sizeof($keywords); $i < $num_keywords; $i++) - { - $keywords_pattern[] = preg_quote($keywords[$i], '#'); - $keywords[$i] = $db->sql_like_expression($db->any_char . $keywords[$i] . $db->any_char); - } - - $keywords_pattern = '#' . implode('|', $keywords_pattern) . '#ui'; - - $operations = array(); - foreach ($user->lang as $key => $value) - { - if (substr($key, 0, 4) == 'LOG_' && preg_match($keywords_pattern, $value)) - { - $operations[] = $key; - } - } - - $sql_keywords = 'AND ('; - if (!empty($operations)) - { - $sql_keywords .= $db->sql_in_set('l.log_operation', $operations) . ' OR '; - } - $sql_lower = $db->sql_lower_text('l.log_data'); - $sql_keywords .= "$sql_lower " . implode(" OR $sql_lower ", $keywords) . ')'; + $tmp_log = new phpbb_log(LOG_TABLE); } - if ($log_count !== false) - { - $sql = 'SELECT COUNT(l.log_id) AS total_entries - FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u - WHERE l.log_type = $log_type - AND l.user_id = u.user_id - AND l.log_time >= $limit_days - $sql_keywords - $sql_forum"; - $result = $db->sql_query($sql); - $log_count = (int) $db->sql_fetchfield('total_entries'); - $db->sql_freeresult($result); - } + $count_logs = ($log_count !== false); - // $log_count may be false here if false was passed in for it, - // because in this case we did not run the COUNT() query above. - // If we ran the COUNT() query and it returned zero rows, return; - // otherwise query for logs below. - if ($log_count === 0) - { - // Save the queries, because there are no logs to display - return 0; - } + $log = $tmp_log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords); + $log_count = $tmp_log->get_log_count(); - if ($log_count) - { - // Return the user to the last page that is valid - while ($offset >= $log_count) - { - $offset = ($offset - $limit < 0) ? 0 : $offset - $limit; - } - } - - $sql = "SELECT l.*, u.username, u.username_clean, u.user_colour - FROM " . LOG_TABLE . " l, " . USERS_TABLE . " u - WHERE l.log_type = $log_type - AND u.user_id = l.user_id - " . (($limit_days) ? "AND l.log_time >= $limit_days" : '') . " - $sql_keywords - $sql_forum - ORDER BY $sort_by"; - $result = $db->sql_query_limit($sql, $limit, $offset); - - $i = 0; - $log = array(); - while ($row = $db->sql_fetchrow($result)) - { - $row['forum_id'] = (int) $row['forum_id']; - if ($row['topic_id']) - { - $topic_id_list[] = $row['topic_id']; - } - - if ($row['reportee_id']) - { - $reportee_id_list[] = $row['reportee_id']; - } - - $log[$i] = array( - 'id' => (int) $row['log_id'], - - 'reportee_id' => (int) $row['reportee_id'], - 'reportee_username' => '', - 'reportee_username_full'=> '', - - 'user_id' => (int) $row['user_id'], - 'username' => $row['username'], - 'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, $profile_url), - - 'ip' => $row['log_ip'], - 'time' => (int) $row['log_time'], - 'forum_id' => (int) $row['forum_id'], - 'topic_id' => (int) $row['topic_id'], - - 'viewforum' => ($row['forum_id'] && $auth->acl_get('f_read', $row['forum_id'])) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : false, - 'action' => (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}', - ); - - if (!empty($row['log_data'])) - { - $log_data_ary = @unserialize($row['log_data']); - $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary; - - if (isset($user->lang[$row['log_operation']])) - { - // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array - // It doesn't matter if we add more arguments than placeholders - if ((substr_count($log[$i]['action'], '%') - sizeof($log_data_ary)) > 0) - { - $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($log[$i]['action'], '%') - sizeof($log_data_ary), '')); - } - - $log[$i]['action'] = vsprintf($log[$i]['action'], $log_data_ary); - - // If within the admin panel we do not censor text out - if (defined('IN_ADMIN')) - { - $log[$i]['action'] = bbcode_nl2br($log[$i]['action']); - } - else - { - $log[$i]['action'] = bbcode_nl2br(censor_text($log[$i]['action'])); - } - } - else if (!empty($log_data_ary)) - { - $log[$i]['action'] .= '
' . implode('', $log_data_ary); - } - - /* Apply make_clickable... has to be seen if it is for good. :/ - // Seems to be not for the moment, reconsider later... - $log[$i]['action'] = make_clickable($log[$i]['action']); - */ - } - - $i++; - } - $db->sql_freeresult($result); - - if (sizeof($topic_id_list)) - { - $topic_id_list = array_unique($topic_id_list); - - // This query is not really needed if move_topics() updates the forum_id field, - // although it's also used to determine if the topic still exists in the database - $sql = 'SELECT topic_id, forum_id - FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', array_map('intval', $topic_id_list)); - $result = $db->sql_query($sql); - - $default_forum_id = 0; - - while ($row = $db->sql_fetchrow($result)) - { - $row['forum_id'] = (int) $row['forum_id']; - if ($auth->acl_get('f_read', $row['forum_id'])) - { - $is_auth[$row['topic_id']] = $row['forum_id']; - } - - if ($auth->acl_gets('a_', 'm_', $row['forum_id'])) - { - $is_mod[$row['topic_id']] = $row['forum_id']; - } - } - $db->sql_freeresult($result); - - foreach ($log as $key => $row) - { - $log[$key]['viewtopic'] = (isset($is_auth[$row['topic_id']])) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $is_auth[$row['topic_id']] . '&t=' . $row['topic_id']) : false; - $log[$key]['viewlogs'] = (isset($is_mod[$row['topic_id']])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=logs&mode=topic_logs&t=' . $row['topic_id'], true, $user->session_id) : false; - } - } - - if (sizeof($reportee_id_list)) - { - $reportee_id_list = array_unique($reportee_id_list); - $reportee_names_list = array(); - - $sql = 'SELECT user_id, username, user_colour - FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $reportee_id_list); - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $reportee_names_list[$row['user_id']] = $row; - } - $db->sql_freeresult($result); - - foreach ($log as $key => $row) - { - if (!isset($reportee_names_list[$row['reportee_id']])) - { - continue; - } - - $log[$key]['reportee_username'] = $reportee_names_list[$row['reportee_id']]['username']; - $log[$key]['reportee_username_full'] = get_username_string('full', $row['reportee_id'], $reportee_names_list[$row['reportee_id']]['username'], $reportee_names_list[$row['reportee_id']]['user_colour'], false, $profile_url); - } - } - - return $offset; + return $tmp_log->get_valid_offset(); } /** diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 14f8bfd534..5d81dd8495 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -25,7 +25,7 @@ class phpbb_log implements phpbb_log_interface /** * Keeps the status of the log-system. Is the log enabled or disabled? */ - private $enabled; + private $disabled_logs; /** * Keeps the total log count of the last call to get_logs() @@ -56,31 +56,70 @@ class phpbb_log implements phpbb_log_interface /** * This function returns the state of the log-system. * - * @return bool True if log is enabled + * @param string $type The log type we want to check. Empty to get global log status. + * + * @return bool True if log for the type is enabled */ - public function is_enabled() + public function is_enabled($type = '') { - return $this->enabled; + if ($type == '' || $type == 'all') + { + return !isset($this->disabled_logs['all']); + } + return !isset($this->disabled_logs[$type]) && !isset($this->disabled_logs['all']); } /** * This function allows disable the log-system. When add_log is called, the log will not be added to the database. * + * @param mixed $type The log type we want to enable. Empty to disable all logs. + * Can also be an array of types + * * @return null */ - public function disable() + public function disable($type = '') { - $this->enabled = false; + if (is_array($type)) + { + foreach ($type as $disable_type) + { + $this->disable($disable_type); + } + return; + } + + if ($type == '' || $type == 'all') + { + $this->disabled_logs['all'] = true; + return; + } + $this->disabled_logs[$type] = true; } /** * This function allows re-enable the log-system. * + * @param mixed $type The log type we want to enable. Empty to enable all logs. + * * @return null */ - public function enable() + public function enable($type = '') { - $this->enabled = true; + if (is_array($type)) + { + foreach ($type as $enable_type) + { + $this->enable($enable_type); + } + return; + } + + if ($type == '' || $type == 'all') + { + $this->disabled_logs = array(); + return; + } + unset($this->disabled_logs[$type]); } /** @@ -90,7 +129,7 @@ class phpbb_log implements phpbb_log_interface */ public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array()) { - if (!$this->is_enabled()) + if (!$this->is_enabled($mode)) { return false; } @@ -119,7 +158,7 @@ class phpbb_log implements phpbb_log_interface case 'admin': $sql_ary += array( 'log_type' => LOG_ADMIN, - 'log_data' => (!sizeof($additional_data)) ? '' : serialize($additional_data), + 'log_data' => (!empty($additional_data)) ? serialize($additional_data) : '', ); break; @@ -132,7 +171,7 @@ class phpbb_log implements phpbb_log_interface 'log_type' => LOG_MOD, 'forum_id' => $forum_id, 'topic_id' => $topic_id, - 'log_data' => (!sizeof($additional_data)) ? '' : serialize($additional_data), + 'log_data' => (!empty($additional_data)) ? serialize($additional_data) : '', ); break; @@ -143,14 +182,14 @@ class phpbb_log implements phpbb_log_interface $sql_ary += array( 'log_type' => LOG_USERS, 'reportee_id' => $reportee_id, - 'log_data' => (!sizeof($additional_data)) ? '' : serialize($additional_data), + 'log_data' => (!empty($additional_data)) ? serialize($additional_data) : '', ); break; case 'critical': $sql_ary += array( 'log_type' => LOG_CRITICAL, - 'log_data' => (!sizeof($additional_data)) ? '' : serialize($additional_data), + 'log_data' => (!empty($additional_data)) ? serialize($additional_data) : '', ); break; @@ -161,9 +200,7 @@ class phpbb_log implements phpbb_log_interface if ($phpbb_dispatcher != null) { $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.add_log_case', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.add_log_case', $vars, $vars)); } */ @@ -180,9 +217,7 @@ class phpbb_log implements phpbb_log_interface if ($phpbb_dispatcher != null) { $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.add_log', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.add_log', $vars, $vars)); } */ @@ -199,6 +234,11 @@ class phpbb_log implements phpbb_log_interface public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '') { global $db, $user, $auth, $phpEx, $phpbb_root_path, $phpbb_admin_path; + /** + * @todo: enable when events are merged + * + global $db, $user, $auth, $phpEx, $phpbb_root_path, $phpbb_admin_path, $phpbb_dispatcher; + */ $this->logs_total = 0; $this->logs_offset = $offset; @@ -256,9 +296,7 @@ class phpbb_log implements phpbb_log_interface if ($phpbb_dispatcher != null) { $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.get_logs_switch_mode', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.get_logs_switch_mode', $vars, $vars)); } */ @@ -275,9 +313,7 @@ class phpbb_log implements phpbb_log_interface if ($phpbb_dispatcher != null) { $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.get_logs_after_get_type', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.get_logs_after_get_type', $vars, $vars)); } */ @@ -311,12 +347,12 @@ class phpbb_log implements phpbb_log_interface // Return the user to the last page that is valid while ($this->logs_offset >= $this->logs_total) { - $this->logs_offset = ($this->logs_offset - $limit < 0) ? 0 : $this->logs_offset - $limit; + $this->logs_offset = max(0, $this->logs_offset - $limit); } } - $sql = "SELECT l.*, u.username, u.username_clean, u.user_colour - FROM " . LOG_TABLE . " l, " . USERS_TABLE . " u + $sql = 'SELECT l.*, u.username, u.username_clean, u.user_colour + FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u WHERE l.log_type = $log_type AND u.user_id = l.user_id " . (($log_time) ? "AND l.log_time >= $log_time" : '') . " @@ -366,9 +402,7 @@ class phpbb_log implements phpbb_log_interface if ($phpbb_dispatcher != null) { $vars = array('log_entry_data', 'row'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.get_logs_entry_data', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.get_logs_entry_data', $vars, $vars)); } */ @@ -377,7 +411,7 @@ class phpbb_log implements phpbb_log_interface if (!empty($row['log_data'])) { $log_data_ary = @unserialize($row['log_data']); - $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary; + $log_data_ary = ($log_data_ary !== false) ? $log_data_ary : array(); if (isset($user->lang[$row['log_operation']])) { @@ -421,9 +455,7 @@ class phpbb_log implements phpbb_log_interface if ($phpbb_dispatcher != null) { $vars = array('log', 'topic_id_list', 'reportee_id_list'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.get_logs_additional_data', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.get_logs_additional_data', $vars, $vars)); } */ @@ -498,7 +530,8 @@ class phpbb_log implements phpbb_log_interface { $sql_keywords .= $db->sql_in_set('l.log_operation', $operations) . ' OR '; } - $sql_keywords .= 'LOWER(l.log_data) ' . implode(' OR LOWER(l.log_data) ', $keywords) . ')'; + $sql_lower = $db->sql_lower_text('l.log_data'); + $sql_keywords .= " $sql_lower " . implode(" OR $sql_lower ", $keywords) . ')'; } return $sql_keywords; From 325827c40f778ef7efd3c195706cb0b1fb28805b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 16:43:26 +0100 Subject: [PATCH 058/234] [ticket/10714] Inject the global $phpbb_log into view_log() PHPBB3-10714 --- phpBB/common.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpBB/common.php b/phpBB/common.php index bbcf8b894f..799c1162b1 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -76,6 +76,7 @@ if (!empty($load_extensions) && function_exists('dl')) require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); +require($phpbb_root_path . 'includes/functions_admin.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); @@ -142,6 +143,10 @@ foreach ($cache->obtain_hooks() as $hook) // make sure add_log uses this log instance $phpbb_log = new phpbb_log(LOG_TABLE); add_log($phpbb_log); // "dependency injection" for a function +// Parameter 2 and 3 are passed by reference, so we need to create a variable for it. +$tmp_var = ''; +view_log($phpbb_log, $tmp_var, $tmp_var); // "dependency injection" for a function +unset($tmp_var); if (!$config['use_system_cron']) { From 1e00c697b766d1a8695c8e058334efe1dd3dbb7e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 17:02:56 +0100 Subject: [PATCH 059/234] [ticket/10714] Add docblock for the test cases PHPBB3-10714 --- tests/log/function_add_log_test.php | 29 ++++++++++++++++ tests/log/function_view_log_test.php | 50 ++++++++++++++-------------- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 1f54f66d2d..e7b3c4335f 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -19,6 +19,35 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case public static function test_add_log_function_data() { return array( + /** + * Case documentation + array( + // Row that is in the database afterwards + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_ADDITIONAL', + // log_data will be serialized + 'log_data' => array( + 'argument3', + ), + 'reportee_id' => 0, + 'forum_id' => 56, + 'topic_id' => 78, + ), + // user_id Can also be false, than ANONYMOUS is used + false, + // log_mode Used to determinate the log_type + 'mod', + // Followed by some additional arguments + // forum_id, topic_id and reportee_id are specified before log_operation + // The rest is specified afterwards. + 56, + 78, + 'LOG_MOD_ADDITIONAL', // log_operation + 'argument3', + ), + */ array( array( 'user_id' => 2, diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 7c44413330..78bc2843a8 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -210,77 +210,77 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case ); $test_cases = array( + /** + * Case documentation + array( + // Array of datasets that should be in $log after running the function + 'expected' => array(5, 7), + // Offset that will be returned form the function + 'expected_returned' => 0, + // view_log parameters (see includes/functions_admin.php for docblock) + // $log is ommited! + 'mod', 5, 0, 12, 45, + ), + */ array( 'expected' => array(1, 2), 'expected_returned' => 0, - false, - 'admin', + 'admin', false, ), array( 'expected' => array(1), 'expected_returned' => 0, - false, - 'admin', 1, + 'admin', false, 1, ), array( 'expected' => array(2), 'expected_returned' => 1, - false, - 'admin', 1, 1, + 'admin', false, 1, 1, ), array( 'expected' => array(2), 'expected_returned' => 1, - 0, - 'admin', 1, 1, + 'admin', 0, 1, 1, ), array( 'expected' => array(2), 'expected_returned' => 1, - 0, - 'admin', 1, 5, + 'admin', 0, 1, 5, ), array( 'expected' => array(3), 'expected_returned' => 0, - false, - 'critical', + 'critical', false, ), array( 'expected' => array(), 'expected_returned' => null, - false, - 'mode_does_not_exist', + 'mode_does_not_exist', false, ), array( 'expected' => array(4, 5, 7), 'expected_returned' => 0, - 0, - 'mod', 5, 0, 12, + 'mod', 0, 5, 0, 12, ), array( 'expected' => array(5, 7), 'expected_returned' => 0, - 0, - 'mod', 5, 0, 12, 45, + 'mod', 0, 5, 0, 12, 45, ), array( 'expected' => array(6), 'expected_returned' => 0, - 0, - 'mod', 5, 0, 23, + 'mod', 0, 5, 0, 23, ), array( 'expected' => array(8), 'expected_returned' => 0, - 0, - 'user', 5, 0, 0, 0, 2, + 'user', 0, 5, 0, 0, 0, 2, ), array( 'expected' => array(8, 9), 'expected_returned' => 0, - 0, - 'users', + 'users', 0, ), ); @@ -298,7 +298,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case /** * @dataProvider test_view_log_function_data */ - public function test_view_log_function($expected, $expected_returned, $log_count, $mode, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '') + public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '') { global $cache, $db, $user, $auth; From 2c7f498c1b43cfb96f868e9b0f9b80ad5ec626a8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 17:13:17 +0100 Subject: [PATCH 060/234] [ticket/10714] Change $phpbb_dispatcher calls to the new layout PHPBB3-10714 --- phpBB/includes/functions.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3e3d796ba2..c5a1543277 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3407,9 +3407,7 @@ function add_log() if ($phpbb_dispatcher != null) { $vars = array('mode', 'args', 'additional_data'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.function_add_log', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.function_add_log', $vars, $vars)); } */ } From 3170845a5011ea76af7f4f8359acafb43ad7e19e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 28 Mar 2012 15:48:45 +0200 Subject: [PATCH 061/234] [ticket/10714] Refactor disable mechanism to only disable certain types Only disable admin log when adding multiple users, so critical errors are still logged. PHPBB3-10714 --- phpBB/includes/functions_user.php | 4 ++-- phpBB/includes/log/interface.php | 16 ++++++++++++---- tests/log/add_test.php | 28 +++++++++++++++++++++++----- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 4074eaa2f2..d1f1544fcd 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -302,7 +302,7 @@ function user_add($user_row, $cp_data = false) global $phpbb_log; // Because these actions only fill the log unneccessarily we skip the add_log() entry. - $phpbb_log->disable(); + $phpbb_log->disable('admin'); // Add user to "newly registered users" group and set to default group if admin specified so. if ($config['new_member_group_default']) @@ -315,7 +315,7 @@ function user_add($user_row, $cp_data = false) group_user_add($add_group_id, $user_id); } - $phpbb_log->enable(); + $phpbb_log->enable('admin'); } } diff --git a/phpBB/includes/log/interface.php b/phpBB/includes/log/interface.php index fde718b71a..feeab585bf 100644 --- a/phpBB/includes/log/interface.php +++ b/phpBB/includes/log/interface.php @@ -25,23 +25,31 @@ interface phpbb_log_interface /** * This function returns the state of the log-system. * - * @return bool True if log is enabled + * @param string $type The log type we want to check. Empty to get global log status. + * + * @return bool True if log for the type is enabled */ - public function is_enabled(); + public function is_enabled($type = ''); /** * This function allows disable the log-system. When add_log is called, the log will not be added to the database. * + * @param mixed $type The log type we want to disable. Empty to disable all logs. + * Can also be an array of types + * * @return null */ - public function disable(); + public function disable($type = ''); /** * This function allows re-enable the log-system. * + * @param mixed $type The log type we want to enable. Empty to enable all logs. + * Can also be an array of types + * * @return null */ - public function enable(); + public function enable($type = ''); /** * Adds a log to the database diff --git a/tests/log/add_test.php b/tests/log/add_test.php index a2b763f2b7..faf5953836 100644 --- a/tests/log/add_test.php +++ b/tests/log/add_test.php @@ -19,13 +19,21 @@ class phpbb_log_add_test extends phpbb_database_test_case public function test_log_enabled() { $log = new phpbb_log(LOG_TABLE); - $this->assertTrue($log->is_enabled()); + $this->assertTrue($log->is_enabled(), 'Initialise failed'); $log->disable(); - $this->assertFalse($log->is_enabled()); + $this->assertFalse($log->is_enabled(), 'Disable all failed'); $log->enable(); - $this->assertTrue($log->is_enabled()); + $this->assertTrue($log->is_enabled(), 'Enable all failed'); + + $log->disable('admin'); + $this->assertFalse($log->is_enabled('admin'), 'Disable admin failed'); + $this->assertTrue($log->is_enabled('user'), 'User should be enabled, is disabled'); + $this->assertTrue($log->is_enabled(), 'Disable admin disabled all'); + + $log->enable('admin'); + $this->assertTrue($log->is_enabled('admin'), 'Enable admin failed'); } public function test_log_add() @@ -45,9 +53,19 @@ class phpbb_log_add_test extends phpbb_database_test_case $log = new phpbb_log(LOG_TABLE); $this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time)); - // Disable logging + // Disable logging for all types $log->disable(); - $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time)); + $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for all types failed'); + $log->enable(); + + // Disable logging for same type + $log->disable('critical'); + $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for same type failed'); + $log->enable(); + + // Disable logging for different type + $log->disable('admin'); + $this->assertEquals(2, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for different types failed'); $log->enable(); // Invalid mode specified From 0fcbb40a0e1affcfa07a6d51ce273b73b3a95359 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 12:40:55 +0200 Subject: [PATCH 062/234] [ticket/10714] Enable core.add_log event and remove superseded add_log_case PHPBB3-10714 --- phpBB/includes/log/log.php | 46 ++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 5d81dd8495..752ed21955 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -134,12 +134,7 @@ class phpbb_log implements phpbb_log_interface return false; } - global $db; - /** - * @todo: enable when events are merged - * global $db, $phpbb_dispatcher; - */ if ($log_time == false) { @@ -192,34 +187,37 @@ class phpbb_log implements phpbb_log_interface 'log_data' => (!empty($additional_data)) ? serialize($additional_data) : '', ); break; - - default: - /** - * @todo: enable when events are merged - * - if ($phpbb_dispatcher != null) - { - $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.add_log_case', $vars, $vars)); - } - */ - - // We didn't find a log_type, so we don't save it in the database. - if (!isset($sql_ary['log_type'])) - { - return false; - } } /** - * @todo: enable when events are merged + * Allow to modify log data before we add them to the database * + * NOTE: if sql_ary does not contain a log_type value, the entry will + * not be stored in the database. So ensure to set it, if needed. + * + * @event core.add_log + * @var string mode Mode of the entry we log + * @var int user_id ID of the user who triggered the log + * @var string log_ip IP of the user who triggered the log + * @var string log_operation Language key of the log operation + * @var int log_time Timestamp, when the log was added + * @var array additional_data Array with additional log data + * @var array sql_ary Array with log data we insert into the + * database. If sql_ary[log_type] is not set, + * we won't add the entry to the database. + * @since 3.1-A1 + */ if ($phpbb_dispatcher != null) { $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); extract($phpbb_dispatcher->trigger_event('core.add_log', $vars, $vars)); } - */ + + // We didn't find a log_type, so we don't save it in the database. + if (!isset($sql_ary['log_type'])) + { + return false; + } $db->sql_query('INSERT INTO ' . $this->log_table . ' ' . $db->sql_build_array('INSERT', $sql_ary)); From bd6dfee23e0d3f11ff028d4376e73c9c1e770f2a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 13:06:43 +0200 Subject: [PATCH 063/234] [ticket/10714] Add event core.get_logs_modify_type core.get_logs_switch_mode is superseded by this one and therefor removed PHPBB3-10714 --- phpBB/includes/log/log.php | 53 +++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 752ed21955..97d0aac623 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -231,12 +231,7 @@ class phpbb_log implements phpbb_log_interface */ public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '') { - global $db, $user, $auth, $phpEx, $phpbb_root_path, $phpbb_admin_path; - /** - * @todo: enable when events are merged - * global $db, $user, $auth, $phpEx, $phpbb_root_path, $phpbb_admin_path, $phpbb_dispatcher; - */ $this->logs_total = 0; $this->logs_offset = $offset; @@ -288,32 +283,44 @@ class phpbb_log implements phpbb_log_interface default: $log_type = null; $sql_additional = ''; - /** - * @todo: enable when events are merged - * - if ($phpbb_dispatcher != null) - { - $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); - extract($phpbb_dispatcher->trigger_event('core.get_logs_switch_mode', $vars, $vars)); - } - */ - - if (!isset($log_type)) - { - $this->logs_offset = 0; - return array(); - } } /** - * @todo: enable when events are merged + * Overwrite log type and limitations before we count and get the logs * + * NOTE: if log_type is not set, no entries will be returned. + * + * @event core.get_logs_modify_type + * @var string mode Mode of the entries we display + * @var bool count_logs Do we count all matching entries? + * @var int limit Limit the number of entries + * @var int offset Offset when fetching the entries + * @var mixed forum_id Limit entries to the forum_id, + * can also be an array of forum_ids + * @var int topic_id Limit entries to the topic_id + * @var int user_id Limit entries to the user_id + * @var int log_time Limit maximum age of log entries + * @var string sort_by SQL order option + * @var string keywords Will only return entries that have the + * keywords in log_operation or log_data + * @var string profile_url URL to the users profile + * @var int log_type Limit logs to a certain type. If log_type + * is not set, no entries will be returned. + * @var string sql_additional Additional conditions for the entries, + * e.g.: 'AND l.forum_id = 1' + * @since 3.1-A1 + */ if ($phpbb_dispatcher != null) { $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); - extract($phpbb_dispatcher->trigger_event('core.get_logs_after_get_type', $vars, $vars)); + extract($phpbb_dispatcher->trigger_event('core.get_logs_modify_type', $vars)); + } + + if (!isset($log_type)) + { + $this->logs_offset = 0; + return array(); } - */ $sql_keywords = ''; if (!empty($keywords)) From 0bb4af90a4d9a1fedb254a1b6e9702726cfcf091 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 13:07:11 +0200 Subject: [PATCH 064/234] [ticket/10714] Fix core.add_log event PHPBB3-10714 --- phpBB/includes/log/log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 97d0aac623..92730aa7da 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -210,7 +210,7 @@ class phpbb_log implements phpbb_log_interface if ($phpbb_dispatcher != null) { $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.add_log', $vars, $vars)); + extract($phpbb_dispatcher->trigger_event('core.add_log', $vars)); } // We didn't find a log_type, so we don't save it in the database. From cf095dd393a6540d092c6308bc03aab824376562 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 13:12:50 +0200 Subject: [PATCH 065/234] [ticket/10714] Enable event core.get_logs_modify_entry_data PHPBB3-10714 --- phpBB/includes/log/log.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 92730aa7da..c95b334cad 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -402,14 +402,18 @@ class phpbb_log implements phpbb_log_interface ); /** - * @todo: enable when events are merged + * Modify the entry's data before it is returned * + * @event core.get_logs_modify_entry_data + * @var array row Entry data from the database + * @var array log_entry_data Entry's data which is returned + * @since 3.1-A1 + */ if ($phpbb_dispatcher != null) { - $vars = array('log_entry_data', 'row'); - extract($phpbb_dispatcher->trigger_event('core.get_logs_entry_data', $vars, $vars)); + $vars = array('row', 'log_entry_data'); + extract($phpbb_dispatcher->trigger_event('core.get_logs_modify_entry_data', $vars)); } - */ $log[$i] = $log_entry_data; From 701052481542cad1ab46fb5e48cf5bbd139030b8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 13:19:13 +0200 Subject: [PATCH 066/234] [ticket/10714] Enable event core.get_logs_get_additional_data PHPBB3-10714 --- phpBB/includes/log/log.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index c95b334cad..ef74f6aaf4 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -459,14 +459,21 @@ class phpbb_log implements phpbb_log_interface $db->sql_freeresult($result); /** - * @todo: enable when events are merged + * Get some additional data after we got all log entries * + * @event core.get_logs_get_additional_data + * @var array log Array with all our log entries + * @var array topic_id_list Array of topic ids, for which we + * get the permission data + * @var array reportee_id_list Array of additional user IDs we + * get the username strings for + * @since 3.1-A1 + */ if ($phpbb_dispatcher != null) { $vars = array('log', 'topic_id_list', 'reportee_id_list'); - extract($phpbb_dispatcher->trigger_event('core.get_logs_additional_data', $vars, $vars)); + extract($phpbb_dispatcher->trigger_event('core.get_logs_get_additional_data', $vars)); } - */ if (sizeof($topic_id_list)) { From 151346c6e053e925b5cfcf2845eca532509bbc80 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 13:25:26 +0200 Subject: [PATCH 067/234] [ticket/10714] Remove event core.function_add_log, add_log should be used instead PHPBB3-10714 --- phpBB/includes/functions.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index c5a1543277..b5d0c4d62f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3398,18 +3398,6 @@ function add_log() case 'user': $additional_data['reportee_id'] = array_shift($args); break; - default: - /** - * @todo: enable when events are merged - * - global $phpbb_dispatcher; - - if ($phpbb_dispatcher != null) - { - $vars = array('mode', 'args', 'additional_data'); - extract($phpbb_dispatcher->trigger_event('core.function_add_log', $vars, $vars)); - } - */ } $log_operation = array_shift($args); $additional_data = array_merge($additional_data, $args); From 2afbec5ac425b8913c2d3e3193b195190b7185db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 15:50:46 +0200 Subject: [PATCH 068/234] [ticket/10714] Always try to trigger events on phpbb_dispatcher We may add the if () later again, if we decide to do that. PHPBB3-10714 --- phpBB/includes/log/log.php | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index ef74f6aaf4..780881ae13 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -207,11 +207,8 @@ class phpbb_log implements phpbb_log_interface * we won't add the entry to the database. * @since 3.1-A1 */ - if ($phpbb_dispatcher != null) - { - $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.add_log', $vars)); - } + $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); + extract($phpbb_dispatcher->trigger_event('core.add_log', $vars)); // We didn't find a log_type, so we don't save it in the database. if (!isset($sql_ary['log_type'])) @@ -310,11 +307,8 @@ class phpbb_log implements phpbb_log_interface * e.g.: 'AND l.forum_id = 1' * @since 3.1-A1 */ - if ($phpbb_dispatcher != null) - { - $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); - extract($phpbb_dispatcher->trigger_event('core.get_logs_modify_type', $vars)); - } + $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); + extract($phpbb_dispatcher->trigger_event('core.get_logs_modify_type', $vars)); if (!isset($log_type)) { @@ -409,11 +403,8 @@ class phpbb_log implements phpbb_log_interface * @var array log_entry_data Entry's data which is returned * @since 3.1-A1 */ - if ($phpbb_dispatcher != null) - { - $vars = array('row', 'log_entry_data'); - extract($phpbb_dispatcher->trigger_event('core.get_logs_modify_entry_data', $vars)); - } + $vars = array('row', 'log_entry_data'); + extract($phpbb_dispatcher->trigger_event('core.get_logs_modify_entry_data', $vars)); $log[$i] = $log_entry_data; @@ -469,11 +460,8 @@ class phpbb_log implements phpbb_log_interface * get the username strings for * @since 3.1-A1 */ - if ($phpbb_dispatcher != null) - { - $vars = array('log', 'topic_id_list', 'reportee_id_list'); - extract($phpbb_dispatcher->trigger_event('core.get_logs_get_additional_data', $vars)); - } + $vars = array('log', 'topic_id_list', 'reportee_id_list'); + extract($phpbb_dispatcher->trigger_event('core.get_logs_get_additional_data', $vars)); if (sizeof($topic_id_list)) { From d828ef93f29eda5fe31a6f8291dd1e5b3cdfd97c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 16:00:01 +0200 Subject: [PATCH 069/234] [ticket/10714] Fix unit test because of events and moved files PHPBB3-10714 --- tests/log/add_test.php | 3 ++- tests/log/function_add_log_test.php | 3 ++- tests/log/function_view_log_test.php | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/log/add_test.php b/tests/log/add_test.php index faf5953836..fceb48ed01 100644 --- a/tests/log/add_test.php +++ b/tests/log/add_test.php @@ -38,9 +38,10 @@ class phpbb_log_add_test extends phpbb_database_test_case public function test_log_add() { - global $db; + global $db, $phpbb_dispatcher; $db = $this->new_dbal(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $mode = 'critical'; $user_id = ANONYMOUS; diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index e7b3c4335f..77c4578baa 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -142,7 +142,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case */ public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) { - global $db, $user; + global $db, $user, $phpbb_dispatcher; if ($expected) { @@ -155,6 +155,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case } $db = $this->new_dbal(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $user->ip = 'user_ip'; if ($user_id) diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 78bc2843a8..790597e9c8 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -7,13 +7,12 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/auth.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; -require_once dirname(__FILE__) . '/../mock_user.php'; +require_once dirname(__FILE__) . '/../mock/user.php'; require_once dirname(__FILE__) . '/../mock/cache.php'; class phpbb_log_function_view_log_test extends phpbb_database_test_case @@ -300,13 +299,14 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case */ public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '') { - global $cache, $db, $user, $auth; + global $cache, $db, $user, $auth, $phpbb_dispatcher; $db = $this->new_dbal(); $cache = new phpbb_mock_cache; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); // Create auth mock - $auth = $this->getMock('auth'); + $auth = $this->getMock('phpbb_auth'); $acl_get_map = array( array('f_read', 23, true), array('m_', 23, true), From d289bc13acc0ab0329cac25742ae22560a80c607 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 16:49:08 +0200 Subject: [PATCH 070/234] [ticket/10714] Remove dependency injection and use global instead This avoids loading functions_admin.php globally and was suggested by naderman PHPBB3-10714 --- phpBB/common.php | 11 ++--------- phpBB/includes/functions.php | 19 +++++-------------- phpBB/includes/functions_admin.php | 26 ++++++-------------------- 3 files changed, 13 insertions(+), 43 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 799c1162b1..2d2b31df83 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -76,7 +76,6 @@ if (!empty($load_extensions) && function_exists('dl')) require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); -require($phpbb_root_path . 'includes/functions_admin.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); @@ -119,6 +118,8 @@ $config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE); set_config(null, null, null, $config); set_config_count(null, null, null, $config); +$phpbb_log = new phpbb_log(LOG_TABLE); + // load extensions $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); @@ -140,14 +141,6 @@ foreach ($cache->obtain_hooks() as $hook) @include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx); } -// make sure add_log uses this log instance -$phpbb_log = new phpbb_log(LOG_TABLE); -add_log($phpbb_log); // "dependency injection" for a function -// Parameter 2 and 3 are passed by reference, so we need to create a variable for it. -$tmp_var = ''; -view_log($phpbb_log, $tmp_var, $tmp_var); // "dependency injection" for a function -unset($tmp_var); - if (!$config['use_system_cron']) { $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver()); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b5d0c4d62f..e202273204 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3357,29 +3357,20 @@ function parse_cfg_file($filename, $lines = false) */ function add_log() { - // This is all just an ugly hack to add "Dependency Injection" to a function - // the only real code is the function call which maps this function to a method. - static $static_log = null; + global $phpbb_log; $args = func_get_args(); $log = (isset($args[0])) ? $args[0] : false; - if ($log instanceof phpbb_log_interface) - { - $static_log = $log; - return true; - } - else if ($log === false) + if ($log === false) { return false; } - $tmp_log = $static_log; - // no log class set, create a temporary one ourselves to keep backwards compatability - if ($tmp_log === null) + if ($phpbb_log === null) { - $tmp_log = new phpbb_log(LOG_TABLE); + $phpbb_log = new phpbb_log(LOG_TABLE); } $mode = array_shift($args); @@ -3407,7 +3398,7 @@ function add_log() $user_id = (empty($user->data)) ? ANONYMOUS : $user->data['user_id']; $user_ip = (empty($user->ip)) ? '' : $user->ip; - return $tmp_log->add($mode, $user_id, $user_ip, $log_operation, time(), $additional_data); + return $phpbb_log->add($mode, $user_id, $user_ip, $log_operation, time(), $additional_data); } /** diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index e7aed85e15..2a87feed51 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2488,34 +2488,20 @@ function cache_moderators() */ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '') { - // This is all just an ugly hack to add "Dependency Injection" to a function - // the only real code is the function call which maps this function to a method. - static $static_log = null; - - if ($mode instanceof phpbb_log_interface) - { - $static_log = $mode; - return true; - } - else if ($mode === false) - { - return false; - } - - $tmp_log = $static_log; + global $phpbb_log; // no log class set, create a temporary one ourselves to keep backwards compatability - if ($tmp_log === null) + if ($phpbb_log === null) { - $tmp_log = new phpbb_log(LOG_TABLE); + $phpbb_log = new phpbb_log(LOG_TABLE); } $count_logs = ($log_count !== false); - $log = $tmp_log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords); - $log_count = $tmp_log->get_log_count(); + $log = $phpbb_log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords); + $log_count = $phpbb_log->get_log_count(); - return $tmp_log->get_valid_offset(); + return $phpbb_log->get_valid_offset(); } /** From 35089bc0136e019724ee4b6c301fb94da52173cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 11 Nov 2012 12:18:04 +0100 Subject: [PATCH 071/234] [ticket/10714] Fix some comments PHPBB3-10714 --- phpBB/includes/functions.php | 2 +- phpBB/includes/log/interface.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e202273204..93dfb4cd7f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3367,7 +3367,7 @@ function add_log() return false; } - // no log class set, create a temporary one ourselves to keep backwards compatability + // no log class set, create a temporary one ourselves to keep backwards compatibility if ($phpbb_log === null) { $phpbb_log = new phpbb_log(LOG_TABLE); diff --git a/phpBB/includes/log/interface.php b/phpBB/includes/log/interface.php index feeab585bf..dd0df236f6 100644 --- a/phpBB/includes/log/interface.php +++ b/phpBB/includes/log/interface.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) interface phpbb_log_interface { /** - * This function returns the state of the log-system. + * This function returns the state of the log system. * * @param string $type The log type we want to check. Empty to get global log status. * @@ -32,7 +32,7 @@ interface phpbb_log_interface public function is_enabled($type = ''); /** - * This function allows disable the log-system. When add_log is called, the log will not be added to the database. + * This function allows disable the log system. When add_log is called, the log will not be added to the database. * * @param mixed $type The log type we want to disable. Empty to disable all logs. * Can also be an array of types @@ -42,7 +42,7 @@ interface phpbb_log_interface public function disable($type = ''); /** - * This function allows re-enable the log-system. + * This function allows re-enable the log system. * * @param mixed $type The log type we want to enable. Empty to enable all logs. * Can also be an array of types @@ -93,7 +93,7 @@ interface phpbb_log_interface static public function generate_sql_keyword($keywords); /** - * Determinate whether the user is allowed to read and/or moderate the forum of the topic + * Determine whether the user is allowed to read and/or moderate the forum of the topic * * @param array $topic_ids Array with the topic ids * From 72d1cae3f35d6f72f341b06761642545c6c663d2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 11 Nov 2012 12:29:25 +0100 Subject: [PATCH 072/234] [ticket/10714] Remove some private functions from the log interface PHPBB3-10714 --- phpBB/includes/log/interface.php | 32 ------------------------- phpBB/includes/log/log.php | 41 ++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/phpBB/includes/log/interface.php b/phpBB/includes/log/interface.php index dd0df236f6..b85dc3a474 100644 --- a/phpBB/includes/log/interface.php +++ b/phpBB/includes/log/interface.php @@ -83,38 +83,6 @@ interface phpbb_log_interface */ public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = ''); - /** - * Generates a sql condition out of the specified keywords - * - * @param string $keywords The keywords the user specified to search for - * - * @return string Returns the SQL condition searching for the keywords - */ - static public function generate_sql_keyword($keywords); - - /** - * Determine whether the user is allowed to read and/or moderate the forum of the topic - * - * @param array $topic_ids Array with the topic ids - * - * @return array Returns an array with two keys 'm_' and 'read_f' which are also an array of topic_id => forum_id sets when the permissions are given. Sample: - * array( - * 'permission' => array( - * topic_id => forum_id - * ), - * ), - */ - static public function get_topic_auth($topic_ids); - - /** - * Get the data for all reportee form the database - * - * @param array $reportee_ids Array with the user ids of the reportees - * - * @return array Returns an array with the reportee data - */ - static public function get_reportee_data($reportee_ids); - /** * Get total log count * diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 780881ae13..eff084bbd2 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) class phpbb_log implements phpbb_log_interface { /** - * Keeps the status of the log-system. Is the log enabled or disabled? + * Keeps the status of the log system. Is the log enabled or disabled? */ private $disabled_logs; @@ -54,7 +54,7 @@ class phpbb_log implements phpbb_log_interface } /** - * This function returns the state of the log-system. + * This function returns the state of the log system. * * @param string $type The log type we want to check. Empty to get global log status. * @@ -70,7 +70,7 @@ class phpbb_log implements phpbb_log_interface } /** - * This function allows disable the log-system. When add_log is called, the log will not be added to the database. + * This function allows disable the log system. When add_log is called, the log will not be added to the database. * * @param mixed $type The log type we want to enable. Empty to disable all logs. * Can also be an array of types @@ -97,7 +97,7 @@ class phpbb_log implements phpbb_log_interface } /** - * This function allows re-enable the log-system. + * This function allows re-enable the log system. * * @param mixed $type The log type we want to enable. Empty to enable all logs. * @@ -320,7 +320,7 @@ class phpbb_log implements phpbb_log_interface if (!empty($keywords)) { // Get the SQL condition for our keywords - $sql_keywords = self::generate_sql_keyword($keywords); + $sql_keywords = $this->generate_sql_keyword($keywords); } if ($count_logs) @@ -465,7 +465,7 @@ class phpbb_log implements phpbb_log_interface if (sizeof($topic_id_list)) { - $topic_auth = self::get_topic_auth($topic_id_list); + $topic_auth = $this->get_topic_auth($topic_id_list); foreach ($log as $key => $row) { @@ -476,7 +476,7 @@ class phpbb_log implements phpbb_log_interface if (sizeof($reportee_id_list)) { - $reportee_data_list = self::get_reportee_data($reportee_id_list); + $reportee_data_list = $this->get_reportee_data($reportee_id_list); foreach ($log as $key => $row) { @@ -496,9 +496,11 @@ class phpbb_log implements phpbb_log_interface /** * Generates a sql condition out of the specified keywords * - * {@inheritDoc} + * @param string $keywords The keywords the user specified to search for + * + * @return string Returns the SQL condition searching for the keywords */ - static public function generate_sql_keyword($keywords) + private function generate_sql_keyword($keywords) { global $db, $user; @@ -542,11 +544,18 @@ class phpbb_log implements phpbb_log_interface } /** - * Determinate whether the user is allowed to read and/or moderate the forum of the topic + * Determine whether the user is allowed to read and/or moderate the forum of the topic * - * {@inheritDoc} + * @param array $topic_ids Array with the topic ids + * + * @return array Returns an array with two keys 'm_' and 'read_f' which are also an array of topic_id => forum_id sets when the permissions are given. Sample: + * array( + * 'permission' => array( + * topic_id => forum_id + * ), + * ), */ - static public function get_topic_auth($topic_ids) + private function get_topic_auth($topic_ids) { global $auth, $db; @@ -579,11 +588,13 @@ class phpbb_log implements phpbb_log_interface } /** - * Get the data for all reportee form the database + * Get the data for all reportee from the database * - * {@inheritDoc} + * @param array $reportee_ids Array with the user ids of the reportees + * + * @return array Returns an array with the reportee data */ - static public function get_reportee_data($reportee_ids) + private function get_reportee_data($reportee_ids) { global $db; From 4c9820d1ca47d088146f3f52fb1126821efe3646 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 12 Nov 2012 15:01:25 +0100 Subject: [PATCH 073/234] [feature/avatars] add missing html closing tags and fix tabbing PHPBB3-10018 --- phpBB/adm/style/acp_users_avatar.html | 9 +++++---- phpBB/styles/prosilver/template/ucp_avatar_options.html | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index 93a7b38390..62c80f14c1 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -37,14 +37,15 @@ - + -
- {L_AVATAR_GALLERY} +
+ {L_AVATAR_GALLERY}
 
-

{ERROR}

+
+

{ERROR}


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

{L_LINK_REMOTE_SIZE_EXPLAIN}
+

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
+

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

{L_AVATAR_EXPLAIN}
+

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

{ERROR}

-

{L_AVATAR_EXPLAIN}
+

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

{L_AVATAR_SELECT_NEW}

+

{L_AVATAR_SELECT}

-
+
-

{L_GRAVATAR_AVATAR_EXPLAIN}
+

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

{L_LINK_REMOTE_SIZE_EXPLAIN}
+

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

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
+
+
+
+

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

{L_LINK_REMOTE_SIZE_EXPLAIN}
+

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- - -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
-
-
-

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

{ERROR}

+

{ERROR}


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

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

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

{L_AVATAR_EXPLAIN}
{AVATAR}
+

{L_AVATAR_SELECT}

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

 {L_DELETE_AVATAR} + {AVATAR_IMAGE}

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

{L_GROUP_MEMBERS}

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

 {L_DELETE_AVATAR} + {AVATAR}

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

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
-
+

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
+
-

{L_GRAVATAR_AVATAR_SIZE_EXPLAIN}
+

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

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
+

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
+

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
+

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

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

{avatar_drivers.L_EXPLAIN}

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

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

{avatar_drivers.L_EXPLAIN}

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

{L_AVATAR_EXPLAIN}
{AVATAR}
-
+

{L_AVATAR_SELECT}

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

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
-
+

{L_GRAVATAR_AVATAR_EMAIL_EXPLAIN}
+
-

{L_GRAVATAR_AVATAR_SIZE_EXPLAIN}
+

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

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
+

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
+

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
+

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

 {L_DELETE_AVATAR} + {AVATAR_IMAGE}

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

 {L_DELETE_AVATAR} + {AVATAR}

 {L_DELETE_AVATAR} @@ -35,10 +35,10 @@ - + {avatar_drivers.L_EXPLAIN} - + {avatar_drivers.OUTPUT} From 7945ffa2a131c1539a4aa929039c4d44b8e4d336 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 01:02:43 +0100 Subject: [PATCH 125/234] [feature/avatars] Use new avatar types in database updater PHPBB3-10018 --- phpBB/install/database_update.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 2015ef0475..d471833442 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2714,9 +2714,9 @@ function change_database_data(&$no_updates, $version) // Update avatars to modular types $avatar_type_map = array( - AVATAR_UPLOAD => 'upload', - AVATAR_GALLERY => 'local', - AVATAR_REMOTE => 'remote', + AVATAR_UPLOAD => 'avatar.driver.upload', + AVATAR_GALLERY => 'avatar.driver.local', + AVATAR_REMOTE => 'avatar.driver.remote', ); foreach ($avatar_type_map as $old => $new) From ce5e2f16777ae5319fcb902ee58005a4caced7e6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 01:18:27 +0100 Subject: [PATCH 126/234] [feature/avatars] Miscellaneous fixes PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 14 ++++++++------ phpBB/includes/acp/acp_users.php | 12 +++++++----- phpBB/includes/avatar/driver/gravatar.php | 5 ++--- phpBB/includes/avatar/driver/remote.php | 2 +- phpBB/includes/ucp/ucp_groups.php | 2 +- phpBB/includes/ucp/ucp_profile.php | 2 +- phpBB/install/database_update.php | 20 ++++++++++---------- 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 3a49ac8ff8..7a66f993b0 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -334,7 +334,7 @@ class acp_groups { // Handle avatar $driver = str_replace('_', '.', request_var('avatar_driver', '')); - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { @@ -534,7 +534,7 @@ class acp_groups if ($avatar->is_enabled()) { $avatars_enabled = true; - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $template->set_filenames(array( 'avatar' => "acp_avatar_options_$config_name.html", )); @@ -558,8 +558,10 @@ class acp_groups $avatar = get_group_avatar($group_row, 'GROUP_AVATAR', true); - // Merge any avatars errors into the primary error array - // Drivers use lang constants, so we need to map to the actual strings + /* + * Merge any avatar errors into the primary error array + * Drivers use language constants, so we need to map to the actual strings + */ foreach ($avatar_error as $e) { if (is_array($e)) @@ -569,7 +571,7 @@ class acp_groups } else { - $error[] = $user->lang((string) $e); + $error[] = $user->lang("$e"); } } @@ -615,7 +617,7 @@ class acp_groups 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)), - 'AVATAR' => (empty($avatar) ? '' : $avatar), + 'AVATAR' => empty($avatar) ? '' : $avatar, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '', diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 2f7662982a..8e194dc91d 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -454,7 +454,7 @@ class acp_users { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } - + $sql_ary = array( 'user_avatar' => '', 'user_avatar_type' => '', @@ -1745,7 +1745,7 @@ class acp_users if (check_form_key($form_name)) { $driver = str_replace('_', '.', request_var('avatar_driver', '')); - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { @@ -1761,6 +1761,7 @@ class acp_users 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height'], ); + $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' WHERE user_id = ' . $user_id; @@ -1771,7 +1772,8 @@ class acp_users } else { - if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); + if ($avatar) { $avatar->delete($avatar_data); } @@ -1786,7 +1788,7 @@ class acp_users $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user_id; + WHERE user_id = ' . (int) $user_id; $db->sql_query($sql); trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); @@ -1807,7 +1809,7 @@ class acp_users if ($avatar->is_enabled()) { $avatars_enabled = true; - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $template->set_filenames(array( 'avatar' => "acp_avatar_options_$config_name.html", )); diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index d873f7ba41..cca7289275 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -56,11 +56,10 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver */ public function get_custom_html($row, $ignore_config = false, $alt = '') { - $html = ''; - return $html; } /** @@ -121,7 +120,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver $row['avatar_width'] = $row['avatar_height'] = min($this->config['avatar_max_width'], $this->config['avatar_max_height']); $url = $this->get_gravatar_url($row); - if (($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) && (($image_data = @getimagesize($url)) === false)) + if (($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) && (($image_data = getimagesize($url)) === false)) { $error[] = 'UNABLE_GET_IMAGE_SIZE'; return false; diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index c2ae88cc02..f47b0d33f4 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -106,7 +106,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver // Make sure getimagesize works... if (function_exists('getimagesize')) { - if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) + if (($width <= 0 || $height <= 0) && (($image_data = getimagesize($url)) === false)) { $error[] = 'UNABLE_GET_IMAGE_SIZE'; return false; diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 2a388d17f8..5289a95e6d 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -521,7 +521,7 @@ class ucp_groups { // Handle avatar $driver = str_replace('_', '.', request_var('avatar_driver', '')); - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index ab49a11f99..402db86c1d 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -564,7 +564,7 @@ class ucp_profile if (check_form_key('ucp_avatar')) { $driver = str_replace('_', '.', request_var('avatar_driver', '')); - $config_name = preg_replace('#^avatar.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index d471833442..b27613168f 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2722,27 +2722,27 @@ function change_database_data(&$no_updates, $version) foreach ($avatar_type_map as $old => $new) { $sql = 'UPDATE ' . USERS_TABLE . " - SET user_avatar_type = '" . $db->sql_escape($new) . "' - WHERE user_avatar_type = '" . $db->sql_escape($old) . "'"; + SET user_avatar_type = '" . $new . "' + WHERE user_avatar_type = '" . $old . "'"; _sql($sql, $errored, $error_ary); $sql = 'UPDATE ' . GROUPS_TABLE . " - SET group_avatar_type = '" . $db->sql_escape($new) . "' - WHERE group_avatar_type = '" . $db->sql_escape($old) . "'"; + SET group_avatar_type = '" . $new . "' + WHERE group_avatar_type = '" . $old . "'"; _sql($sql, $errored, $error_ary); } // update avatar module_auth - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload || cfg_allow_avatar_gravatar)\' - WHERE module_class = \'ucp\' - AND module_basename = \'ucp_profile\' - AND module_mode = \'avatar\''; + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_auth = 'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload || cfg_allow_avatar_gravatar)' + WHERE module_class = 'ucp' + AND module_basename = 'ucp_profile' + AND module_mode = 'avatar'"; _sql($sql, $errored, $error_ary); if (!isset($config['allow_avatar_gravatar'])) { - $config->set('allow_avatar_gravatar', ''); + $config->set('allow_avatar_gravatar', '0'); } $no_updates = false; From 67c2e48d15d6e4ddd244dd2e126f906ed25be1ef Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 14:33:13 +0100 Subject: [PATCH 127/234] [feature/avatars] Only create avatar objects if necessary PHPBB3-10018 --- phpBB/common.php | 2 -- phpBB/includes/acp/acp_board.php | 3 ++- phpBB/includes/acp/acp_groups.php | 3 ++- phpBB/includes/acp/acp_users.php | 5 ++++- phpBB/includes/functions_display.php | 3 ++- phpBB/includes/ucp/ucp_groups.php | 3 ++- phpBB/includes/ucp/ucp_profile.php | 3 ++- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 17e7c76465..c4237dfcf5 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -128,8 +128,6 @@ $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); $template = $phpbb_container->get('template'); $phpbb_style = $phpbb_container->get('style'); -$phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'display'))); diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 5852f512cd..95da62dedf 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -28,7 +28,7 @@ class acp_board { global $db, $user, $auth, $template; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; - global $cache, $phpbb_avatar_manager; + global $cache, $phpbb_container; $user->add_lang('acp/board'); @@ -107,6 +107,7 @@ class acp_board break; case 'avatar': + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); $avatar_vars = array(); diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 7a66f993b0..c09f447f76 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -26,7 +26,7 @@ class acp_groups { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; - global $request, $phpbb_avatar_manager; + global $request, $phpbb_container; $user->add_lang('acp/groups'); $this->tpl_name = 'acp_groups'; @@ -282,6 +282,7 @@ class acp_groups $user->add_lang('ucp'); // Setup avatar data for later + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; $avatar_drivers = null; $avatar_data = null; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 8e194dc91d..885233bbd3 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -33,7 +33,7 @@ class acp_users global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; global $phpbb_dispatcher, $request; - global $phpbb_avatar_manager; + global $phpbb_container; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; @@ -468,6 +468,7 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type']); if ($driver) { @@ -1732,6 +1733,8 @@ class acp_users include($phpbb_root_path . 'includes/functions_display.' . $phpEx); $avatars_enabled = false; + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); + if ($config['allow_avatar']) { $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index bf1611a5de..669641de70 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1353,7 +1353,7 @@ function get_avatar($row, $alt, $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; global $request; - global $phpbb_avatar_manager; + global $phpbb_container; if (!$config['allow_avatar'] && !$ignore_config) { @@ -1366,6 +1366,7 @@ function get_avatar($row, $alt, $ignore_config = false) 'height' => $row['avatar_height'], ); + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); if ($avatar) diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 5289a95e6d..33f147a47e 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -27,7 +27,7 @@ class ucp_groups { global $config, $phpbb_root_path, $phpEx; global $db, $user, $auth, $cache, $template; - global $request, $phpbb_avatar_manager; + global $request, $phpbb_container; $user->add_lang('groups'); @@ -484,6 +484,7 @@ class ucp_groups $error = array(); // Setup avatar data for later + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; $avatar_drivers = null; $avatar_data = null; diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 402db86c1d..3945fc537a 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -30,7 +30,7 @@ class ucp_profile { global $cache, $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; global $request; - global $phpbb_avatar_manager; + global $phpbb_container; $user->add_lang('posting'); @@ -549,6 +549,7 @@ class ucp_profile add_form_key('ucp_avatar'); + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) From 6d061304afaa703a5305a06a903356d1c48ff2ee Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 15:03:35 +0100 Subject: [PATCH 128/234] [feature/avatars] Small fixes PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index c09f447f76..136ceeff3c 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -337,6 +337,7 @@ class acp_groups $driver = str_replace('_', '.', request_var('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) { $avatar = $phpbb_avatar_manager->get_driver($driver); @@ -344,19 +345,15 @@ class acp_groups if ($result && empty($avatar_error)) { - $result = array( - 'avatar_type' => $driver, - 'avatar' => $result['avatar'], - 'avatar_width' => $result['avatar_width'], - 'avatar_height' => $result['avatar_height'], - ); + $result['avatar_type'] = $driver; $submit_ary = array_merge($submit_ary, $result); } } else { - if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']) + if ($avatar) { $avatar->delete($avatar_data); } From 06639729ea2da6d0025da74ae7d4f3e88f211b67 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 16:04:59 +0100 Subject: [PATCH 129/234] [feature/avatars] Add static methods for handling driver names PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 6 +++--- phpBB/includes/acp/acp_users.php | 6 +++--- phpBB/includes/avatar/manager.php | 26 ++++++++++++++++++++++++++ phpBB/includes/ucp/ucp_groups.php | 6 +++--- phpBB/includes/ucp/ucp_profile.php | 6 +++--- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 136ceeff3c..2969f34b24 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -334,7 +334,7 @@ class acp_groups if ($config['allow_avatar']) { // Handle avatar - $driver = str_replace('_', '.', request_var('avatar_driver', '')); + $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); @@ -523,7 +523,7 @@ class acp_groups if ($config['allow_avatar']) { $avatars_enabled = false; - $focused_driver = str_replace('_', '.', request_var('avatar_driver', $avatar_data['avatar_type'])); + $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); foreach ($avatar_drivers as $driver) { @@ -539,7 +539,7 @@ class acp_groups if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { - $driver_name = str_replace('.', '_', $driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 885233bbd3..44e4f14ae2 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1747,7 +1747,7 @@ class acp_users { if (check_form_key($form_name)) { - $driver = str_replace('_', '.', request_var('avatar_driver', '')); + $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) @@ -1803,7 +1803,7 @@ class acp_users } } - $focused_driver = str_replace('_', '.', request_var('avatar_driver', $user_row['user_avatar_type'])); + $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type'])); foreach ($avatar_drivers as $driver) { @@ -1819,7 +1819,7 @@ class acp_users if ($avatar->prepare_form($template, $avatar_data, $error)) { - $driver_name = str_replace('.', '_', $driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index da9d843947..51727f242a 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -152,4 +152,30 @@ class phpbb_avatar_manager return array_combine($keys, $values); } + + /** + * Clean driver names that are returned from template files + * Underscores are replaced with dots + * + * @param string $name Driver name + * + * @return string Cleaned driver name + */ + public static function clean_driver_name($name) + { + return str_replace('_', '.', $name); + } + + /** + * Prepare driver names for use in template files + * Dots are replaced with underscores + * + * @param string $name Clean driver name + * + * @return string Prepared driver name + */ + public static function prepare_driver_name($name) + { + return str_replace('.', '_', $name); + } } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 33f147a47e..df6915711c 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -521,7 +521,7 @@ class ucp_groups if ($config['allow_avatar']) { // Handle avatar - $driver = str_replace('_', '.', request_var('avatar_driver', '')); + $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) @@ -652,7 +652,7 @@ class ucp_groups if ($config['allow_avatar']) { $avatars_enabled = false; - $focused_driver = str_replace('_', '.', request_var('avatar_driver', $avatar_data['avatar_type'])); + $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); foreach ($avatar_drivers as $driver) { @@ -667,7 +667,7 @@ class ucp_groups if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { - $driver_name = str_replace('.', '_', $driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 3945fc537a..36ac227bc8 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -564,7 +564,7 @@ class ucp_profile { if (check_form_key('ucp_avatar')) { - $driver = str_replace('_', '.', request_var('avatar_driver', '')); + $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); $avatar_delete = $request->variable('avatar_delete', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) @@ -624,7 +624,7 @@ class ucp_profile } } - $focused_driver = str_replace('_', '.', request_var('avatar_driver', $user->data['user_avatar_type'])); + $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type'])); foreach ($avatar_drivers as $driver) { @@ -639,7 +639,7 @@ class ucp_profile if ($avatar->prepare_form($template, $avatar_data, $error)) { - $driver_name = str_replace('.', '_', $driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( From f8256ed00f5ecc95fbf9f69fd2e8de2a92bccec6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 16:18:51 +0100 Subject: [PATCH 130/234] [feature/avatars] Small cosmetic changes PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 3 +-- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/ucp/ucp_groups.php | 13 ++++--------- phpBB/includes/ucp/ucp_profile.php | 4 ++-- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 2969f34b24..a55087adce 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -336,9 +336,8 @@ class acp_groups // Handle avatar $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $avatar_delete = $request->variable('avatar_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $avatar_error); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 44e4f14ae2..823f001fe0 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1749,8 +1749,8 @@ class acp_users { $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $avatar_delete = $request->variable('avatar_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) + + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index df6915711c..dd03f332ff 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -523,21 +523,16 @@ class ucp_groups // Handle avatar $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $avatar_delete = $request->variable('avatar_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) + + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { - $result = array( - 'avatar_type' => $driver, - 'avatar' => $result['avatar'], - 'avatar_width' => $result['avatar_width'], - 'avatar_height' => $result['avatar_height'], - ); - + $result['avatar_type'] = $driver; + $submit_ary = array_merge($submit_ary, $result); } } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 36ac227bc8..88820beac1 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -566,8 +566,8 @@ class ucp_profile { $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $avatar_delete = $request->variable('avatar_delete', ''); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && empty($avatar_delete)) + + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) { $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); From a77fcdb5f93ed291c223c445a46a5641cfdb27ea Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 17:01:21 +0100 Subject: [PATCH 131/234] [feature/avatars] Implement better treatment of avatar errors PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 10 +++++----- phpBB/includes/acp/acp_users.php | 14 ++++++-------- phpBB/includes/ucp/ucp_groups.php | 10 +++++----- phpBB/includes/ucp/ucp_profile.php | 12 +++++------- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index a55087adce..19006df306 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -559,16 +559,16 @@ class acp_groups * Merge any avatar errors into the primary error array * Drivers use language constants, so we need to map to the actual strings */ - foreach ($avatar_error as $e) + foreach ($avatar_error as $lang) { - if (is_array($e)) + if (is_array($lang)) { - $key = array_shift($e); - $error[] = vsprintf($user->lang($key), $e); + $key = array_shift($lang); + $error[] = vsprintf($user->lang($key), $lang); } else { - $error[] = $user->lang("$e"); + $error[] = $user->lang("$lang"); } } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 823f001fe0..e0dcea6d58 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1836,21 +1836,19 @@ class acp_users } // Replace "error" strings with their real, localised form - $err = $error; - $error = array(); - foreach ($err as $e) + foreach ($error as $key => $lang) { - if (is_array($e)) + if (is_array($lang)) { - $key = array_shift($e); - $error[] = vsprintf($user->lang($key), $e); + $lang_key = array_shift($lang); + $error[$key] = vsprintf($user->lang($lang_key), $lang); } else { - $error[] = $user->lang((string) $e); + $error[$key] = $user->lang("$lang"); } } - + $avatar = get_user_avatar($user_row, 'USER_AVATAR', true); $template->assign_vars(array( diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index dd03f332ff..3860d22917 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -679,16 +679,16 @@ class ucp_groups // Merge any avatars errors into the primary error array // Drivers use lang constants, so we need to map to the actual strings - foreach ($avatar_error as $e) + foreach ($avatar_error as $lang) { - if (is_array($e)) + if (is_array($lang)) { - $key = array_shift($e); - $error[] = vsprintf($user->lang($key), $e); + $key = array_shift($lang); + $error[] = vsprintf($user->lang($key), $lang); } else { - $error[] = $user->lang((string) $e); + $error[] = $user->lang("$lang"); } } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 88820beac1..c05105eaff 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -656,18 +656,16 @@ class ucp_profile } // Replace "error" strings with their real, localised form - $err = $error; - $error = array(); - foreach ($err as $e) + foreach ($error as $key => $lang) { - if (is_array($e)) + if (is_array($lang)) { - $key = array_shift($e); - $error[] = vsprintf($user->lang($key), $e); + $key = array_shift($lang); + $error[$key] = vsprintf($user->lang($key), $lang); } else { - $error[] = $user->lang((string) $e); + $error[$key] = $user->lang("$lang"); } } From 6522190ff1b7a7b4384389f23c1229911c1a58d2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 20:50:31 +0100 Subject: [PATCH 132/234] [feature/avatars] Docblock fixes and small change for php_ext PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 60 +++++++++++------------ phpBB/includes/avatar/driver/gravatar.php | 2 +- phpBB/includes/avatar/driver/remote.php | 4 +- phpBB/includes/avatar/driver/upload.php | 4 +- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 710d3dfe20..c6b864bc9f 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -23,26 +23,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { protected $name; - /** - * Returns the name of the driver. - * - * @return string Name of wrapped driver. - */ - public function get_name() - { - return $this->name; - } - - /** - * Sets the name of the driver. - * - * @param string $name The driver name - */ - public function set_name($name) - { - $this->name = $name; - } - /** * Current board configuration * @type phpbb_config @@ -50,8 +30,8 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface protected $config; /** - * Current board configuration - * @type phpbb_config + * Request object + * @type phpbb_request */ protected $request; @@ -62,10 +42,10 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface protected $phpbb_root_path; /** - * Current $phpEx + * Current $php_ext * @type string */ - protected $phpEx; + protected $php_ext; /** * A cache driver @@ -83,18 +63,18 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * Construct a driver object * - * @param $config The phpBB configuration - * @param $request The request object - * @param $phpbb_root_path The path to the phpBB root - * @param $phpEx The php file extension - * @param $cache A cache driver + * @param phpbb_config $config The phpBB configuration + * @param phpbb_request $request The request object + * @param string $phpbb_root_path The path to the phpBB root + * @param string $php_ext The php file extension + * @param phpbb_cache_driver_interface $cache A cache driver */ - public function __construct(phpbb_config $config, phpbb_request $request, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null) + public function __construct(phpbb_config $config, phpbb_request $request, $phpbb_root_path, $php_ext, phpbb_cache_driver_interface $cache = null) { $this->config = $config; $this->request = $request; $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->cache = $cache; } @@ -170,4 +150,22 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface return $template; } + + /** + * @inheritdoc + */ + public function get_name() + { + return $this->name; + } + + /** + * Sets the name of the driver. + * + * @param string $name The driver name + */ + public function set_name($name) + { + $this->name = $name; + } } diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index cca7289275..e21743242f 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -95,7 +95,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver $row['avatar_width'] = $this->request->variable('avatar_gravatar_width', 0); $row['avatar_height'] = $this->request->variable('avatar_gravatar_height', 0); - require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx); + require_once($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); $error = array_merge($error, validate_data(array( 'email' => $row['avatar'], diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index f47b0d33f4..134bf070e5 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -82,7 +82,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver $url = 'http://' . $url; } - require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx); + require_once($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); $error = array_merge($error, validate_data(array( 'url' => $url, @@ -128,7 +128,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver return false; } - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->phpEx); + include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); $types = fileupload::image_types(); $extension = strtolower(filespec::get_extension($url)); diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 9035b5364e..91de47e66d 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -29,7 +29,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver if ($ignore_config || $this->config['allow_avatar_upload']) { return array( - 'src' => $this->phpbb_root_path . 'download/file' . $this->phpEx . '?avatar=' . $row['avatar'], + 'src' => $this->phpbb_root_path . 'download/file' . $this->php_ext . '?avatar=' . $row['avatar'], 'width' => $row['avatar_width'], 'height' => $row['avatar_height'], ); @@ -72,7 +72,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver return false; } - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->phpEx); + include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); From f851d763f9997b896219d1068dd23f6de7dbfc36 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 21:14:05 +0100 Subject: [PATCH 133/234] [feature/avatars] Even more fixes to docblocks PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 42 ++++++++++++---------- phpBB/includes/avatar/driver/gravatar.php | 4 +-- phpBB/includes/avatar/driver/interface.php | 38 ++++++++++---------- phpBB/includes/avatar/driver/local.php | 4 +-- phpBB/includes/avatar/driver/remote.php | 2 +- phpBB/includes/avatar/driver/upload.php | 2 +- phpBB/includes/avatar/manager.php | 34 +++++++++--------- 7 files changed, 65 insertions(+), 61 deletions(-) diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index c6b864bc9f..234186215b 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -21,53 +21,57 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { + /** + * Avatar driver name + * @var string + */ protected $name; /** * Current board configuration - * @type phpbb_config + * @var phpbb_config */ protected $config; /** * Request object - * @type phpbb_request + * @var phpbb_request */ protected $request; /** * Current $phpbb_root_path - * @type string + * @var string */ protected $phpbb_root_path; /** * Current $php_ext - * @type string + * @var string */ protected $php_ext; /** - * A cache driver - * @type phpbb_cache_driver_interface + * Cache driver + * @var phpbb_cache_driver_interface */ protected $cache; /** * This flag should be set to true if the avatar requires a nonstandard image * tag, and will generate the html itself. - * @type boolean + * @var boolean */ public $custom_html = false; /** * Construct a driver object * - * @param phpbb_config $config The phpBB configuration - * @param phpbb_request $request The request object - * @param string $phpbb_root_path The path to the phpBB root - * @param string $php_ext The php file extension - * @param phpbb_cache_driver_interface $cache A cache driver + * @param phpbb_config $config phpBB configuration + * @param phpbb_request $request Request object + * @param string $phpbb_root_path Path to the phpBB root + * @param string $php_ext PHP file extension + * @param phpbb_cache_driver_interface $cache Cache driver */ public function __construct(phpbb_config $config, phpbb_request $request, $phpbb_root_path, $php_ext, phpbb_cache_driver_interface $cache = null) { @@ -100,7 +104,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function prepare_form($template, $row, &$error) { return false; @@ -108,7 +112,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function prepare_form_acp() { return array(); @@ -116,7 +120,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function process_form($template, $row, &$error) { return false; @@ -124,7 +128,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function delete($row) { return true; @@ -132,7 +136,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function is_enabled() { $driver = preg_replace('#^phpbb_avatar_driver_#', '', get_class($this)); @@ -142,7 +146,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc - **/ + */ public function get_template_name() { $driver = preg_replace('#^phpbb_avatar_driver_#', '', get_class($this)); @@ -162,7 +166,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * Sets the name of the driver. * - * @param string $name The driver name + * @param string $name Driver name */ public function set_name($name) { diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index e21743242f..a90c0e3ce1 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -78,7 +78,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * @inheritdoc - **/ + */ public function prepare_form_acp() { return array( @@ -170,7 +170,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * Build gravatar URL for output on page * - * @return string The gravatar URL + * @return string Gravatar URL */ protected function get_gravatar_url($row) { diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index 28220d79f2..cc6b7edd17 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -24,7 +24,7 @@ interface phpbb_avatar_driver_interface /** * Returns the name of the driver. * - * @return string Name of wrapped driver. + * @return string Name of wrapped driver. */ public function get_name(); @@ -43,7 +43,7 @@ interface phpbb_avatar_driver_interface * Returns custom html for displaying this avatar. * Only called if $custom_html is true. * - * @param $ignore_config Whether this function should respect the users prefs + * @param bool $ignore_config Whether this function should respect the users prefs * and board configuration configuration option, or should just render * the avatar anyways. Useful for the ACP. * @return string HTML @@ -53,56 +53,56 @@ interface phpbb_avatar_driver_interface /** * Prepare form for changing the settings of this avatar * - * @param object $template The template object - * @param array $row The user data or group data that has been cleaned with + * @param object $template Template object + * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row - * @param array &$error The reference to an error array + * @param array &$error Reference to an error array * - * @return bool Returns true if form has been successfully prepared - **/ + * @return bool True if form has been successfully prepared + */ public function prepare_form($template, $row, &$error); /** * Prepare form for changing the acp settings of this avatar * - * @return array Return the array containing the acp settings - **/ + * @return array Array containing the acp settings + */ public function prepare_form_acp(); /** * Process form data * - * @param object $template The template object - * @param array $row The user data or group data that has been cleaned with + * @param object $template Template object + * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row - * @param array &$error The reference to an error array + * @param array &$error Reference to an error array * - * @return array An array containing the avatar data as follows: + * @return array Array containing the avatar data as follows: * ['avatar'], ['avatar_width'], ['avatar_height'] - **/ + */ public function process_form($template, $row, &$error); /** * Delete avatar * - * @param array $row The user data or group data that has been cleaned with + * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row * * @return bool True if avatar has been deleted or there is no need to delete - **/ + */ public function delete($row); /** * Check if avatar is enabled * * @return bool True if avatar is enabled, false if it's disabled - **/ + */ public function is_enabled(); /** * Get the avatars template name * - * @return string The avatars template name - **/ + * @return string Avatar's template name + */ public function get_template_name(); } diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index c231206d8e..d46ac79d11 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -114,7 +114,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc - **/ + */ public function prepare_form_acp() { return array( @@ -148,7 +148,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * Get a list of avatars that are locally available * - * @return array An array containing the locally available avatars + * @return array Array containing the locally available avatars */ protected function get_avatar_list() { diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 134bf070e5..b7522ac3e1 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -60,7 +60,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc - **/ + */ public function prepare_form_acp() { return array( diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 91de47e66d..f00033d6bd 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -124,7 +124,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver /** * @inheritdoc - **/ + */ public function prepare_form_acp() { global $user; diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 51727f242a..ae628f0ce2 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -32,14 +32,14 @@ class phpbb_avatar_manager /** * Construct an avatar manager object * - * @param $phpbb_root_path The path to the phpBB root - * @param $phpEx The php file extension - * @param $config The phpBB configuration - * @param $request The request object - * @param $cache A cache driver - * @param $avatar_drivers The avatars drivers passed via the service container - * @param $container The container object - **/ + * @param string $phpbb_root_path Path to the phpBB root + * @param string $phpEx PHP file extension + * @param phpbb_config $config phpBB configuration + * @param phpbb_request $request Request object + * @param phpbb_cache_driver_interface $cache Cache driver + * @param array $avatar_drivers Avatar drivers passed via the service container + * @param object $container Container object + */ public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache, $avatar_drivers, $container) { $this->phpbb_root_path = $phpbb_root_path; @@ -54,10 +54,10 @@ class phpbb_avatar_manager /** * Get the driver object specified by the avatar type * - * @param string The avatar type; by default an avatar's service container name + * @param string Avatar type; by default an avatar's service container name * - * @return object The avatar driver object - **/ + * @return object Avatar driver object + */ public function get_driver($avatar_type) { if (self::$valid_drivers === false) @@ -101,7 +101,7 @@ class phpbb_avatar_manager /** * Load the list of valid drivers * This is executed once and fills self::$valid_drivers - **/ + */ protected function load_valid_drivers() { if (!empty($this->avatar_drivers)) @@ -117,8 +117,8 @@ class phpbb_avatar_manager /** * Get a list of valid avatar drivers * - * @return array An array containing a list of the valid avatar drivers - **/ + * @return array Array containing a list of the valid avatar drivers + */ public function get_valid_drivers() { if (self::$valid_drivers === false) @@ -132,11 +132,11 @@ class phpbb_avatar_manager /** * Strip out user_ and group_ prefixes from keys * - * @param array $row The user data or group data + * @param array $row User data or group data * - * @return array The user data or group data with keys that have been + * @return array User data or group data with keys that have been * stripped from the preceding "user_" or "group_" - **/ + */ public static function clean_row($row) { $keys = array_keys($row); From 0abec06b09c71feb709b6101949181ff7ec4d882 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Nov 2012 21:16:21 +0100 Subject: [PATCH 134/234] [feature/avatars] Change gravatar explain as discussed in PR PHPBB3-10018 --- phpBB/language/en/ucp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index d397ca5538..7223b13b29 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -90,7 +90,7 @@ $lang = array_merge($lang, array( 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected persistent login keys were successfully deleted.', 'AVATAR_CATEGORY' => 'Category', 'AVATAR_DRIVER_GRAVATAR_TITLE' => 'Gravatar', - 'AVATAR_DRIVER_GRAVATAR_EXPLAIN'=> 'Gravatar is a service that provides you with a globally unique avatar.', + 'AVATAR_DRIVER_GRAVATAR_EXPLAIN'=> 'Gravatar is a service that allows you to maintain the same avatar across multiple websites. Visit Gravatar for more information.', 'AVATAR_DRIVER_LOCAL_TITLE' => 'Gallery avatar', 'AVATAR_DRIVER_LOCAL_EXPLAIN' => 'You can choose your avatar from a locally available set of avatars.', 'AVATAR_DRIVER_REMOTE_TITLE' => 'Remote avatar', From cb1d98ab7f588a38fcae680aca839b805caf2a23 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Nov 2012 23:06:38 +0100 Subject: [PATCH 135/234] [feature/avatars] Check for existing functions rather than using _once PHPBB3-10018 --- phpBB/includes/avatar/driver/gravatar.php | 5 ++++- phpBB/includes/avatar/driver/remote.php | 11 +++++++++-- phpBB/includes/avatar/driver/upload.php | 5 ++++- phpBB/includes/ucp/ucp_profile.php | 5 ++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index a90c0e3ce1..7e21a737a1 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -95,7 +95,10 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver $row['avatar_width'] = $this->request->variable('avatar_gravatar_width', 0); $row['avatar_height'] = $this->request->variable('avatar_gravatar_height', 0); - require_once($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); + if (!function_exists('user_add')) + { + require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); + } $error = array_merge($error, validate_data(array( 'email' => $row['avatar'], diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index b7522ac3e1..1da5fc16e8 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -82,7 +82,10 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver $url = 'http://' . $url; } - require_once($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); + if (!function_exists('user_add')) + { + require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); + } $error = array_merge($error, validate_data(array( 'url' => $url, @@ -128,7 +131,11 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver return false; } - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + if (!class_exists('fileupload')) + { + include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + } + $types = fileupload::image_types(); $extension = strtolower(filespec::get_extension($url)); diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index f00033d6bd..497dd8ad19 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -72,7 +72,10 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver return false; } - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + if (!class_exists('fileupload')) + { + include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + } $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index c05105eaff..c8547e48d8 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -545,7 +545,10 @@ class ucp_profile break; case 'avatar': - include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); + if (!function_exists('display_forums')) + { + include($phpbb_root_path . 'includes/functions_display.' . $phpEx); + } add_form_key('ucp_avatar'); From 81a1a21185abfc230097a355216d6c6b99511b20 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 29 Nov 2012 23:08:29 +0100 Subject: [PATCH 136/234] [feature/avatars] Properly implement custom HTML in the interface Previously the driver class added a variable that defined wether an avatar driver would return custom HTML. The existence of this variable was implied in the interface. It's also not needed which is why it has been removed. PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 7 ------- phpBB/includes/avatar/driver/gravatar.php | 6 ++---- phpBB/includes/avatar/driver/interface.php | 3 +-- phpBB/includes/functions_display.php | 8 ++++---- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 234186215b..6710f1f153 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -57,13 +57,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface */ protected $cache; - /** - * This flag should be set to true if the avatar requires a nonstandard image - * tag, and will generate the html itself. - * @var boolean - */ - public $custom_html = false; - /** * Construct a driver object * diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 7e21a737a1..6ceac1a149 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -21,12 +21,10 @@ if (!defined('IN_PHPBB')) */ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver { - const GRAVATAR_URL = 'https://secure.gravatar.com/avatar/'; - /** - * @inheritdoc + * The URL for the gravatar service */ - public $custom_html = true; + const GRAVATAR_URL = 'https://secure.gravatar.com/avatar/'; /** * @inheritdoc diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index cc6b7edd17..d2f25a989f 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -40,8 +40,7 @@ interface phpbb_avatar_driver_interface public function get_data($row, $ignore_config = false); /** - * Returns custom html for displaying this avatar. - * Only called if $custom_html is true. + * Returns custom html if it is needed for displaying this avatar * * @param bool $ignore_config Whether this function should respect the users prefs * and board configuration configuration option, or should just render diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 669641de70..a7b28acac1 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1368,12 +1368,14 @@ function get_avatar($row, $alt, $ignore_config = false) $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); + $html = ''; if ($avatar) { - if ($avatar->custom_html) + $html = $avatar->get_custom_html($row, $ignore_config, $alt); + if (!empty($html)) { - return $avatar->get_custom_html($row, $ignore_config, $alt); + return $html; } $avatar_data = $avatar->get_data($row, $ignore_config); @@ -1383,8 +1385,6 @@ function get_avatar($row, $alt, $ignore_config = false) $avatar_data['src'] = ''; } - $html = ''; - if (!empty($avatar_data['src'])) { $html = ' Date: Thu, 29 Nov 2012 23:50:17 +0100 Subject: [PATCH 137/234] [feature/avatars] Get list of enabled drivers from avatar manager This shouldn't be done in the avatar drivers. We need to force the display all avatar drivers in the ACP or it won't be possible to enable avatars after they have been disabled. PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/acp/acp_groups.php | 35 ++++++++++---------- phpBB/includes/acp/acp_users.php | 37 ++++++++++------------ phpBB/includes/avatar/driver/driver.php | 10 ------ phpBB/includes/avatar/driver/interface.php | 7 ---- phpBB/includes/avatar/manager.php | 29 ++++++++++++++--- phpBB/includes/ucp/ucp_groups.php | 33 +++++++++---------- phpBB/includes/ucp/ucp_profile.php | 35 ++++++++++---------- 8 files changed, 90 insertions(+), 98 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 95da62dedf..c3bdf89866 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -108,7 +108,7 @@ class acp_board case 'avatar': $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(true); sort($avatar_drivers); $avatar_vars = array(); foreach ($avatar_drivers as $driver) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 19006df306..a15a1b9a78 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -528,27 +528,24 @@ class acp_groups { $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->is_enabled()) + $avatars_enabled = true; + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $template->set_filenames(array( + 'avatar' => "acp_avatar_options_$config_name.html", + )); + + if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { - $avatars_enabled = true; - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $template->set_filenames(array( - 'avatar' => "acp_avatar_options_$config_name.html", + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_upper = strtoupper($driver_name); + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), + + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, + 'OUTPUT' => $template->assign_display('avatar'), )); - - if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) - { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); - $driver_upper = strtoupper($driver_name); - $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - - 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, - 'OUTPUT' => $template->assign_display('avatar'), - )); - } } } } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index e0dcea6d58..d5532e35b6 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1809,28 +1809,25 @@ class acp_users { $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->is_enabled()) + $avatars_enabled = true; + $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $template->set_filenames(array( + 'avatar' => "acp_avatar_options_$config_name.html", + )); + + if ($avatar->prepare_form($template, $avatar_data, $error)) { - $avatars_enabled = true; - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); - $template->set_filenames(array( - 'avatar' => "acp_avatar_options_$config_name.html", + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_upper = strtoupper($driver_name); + + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), + + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, + 'OUTPUT' => $template->assign_display('avatar'), )); - - if ($avatar->prepare_form($template, $avatar_data, $error)) - { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); - $driver_upper = strtoupper($driver_name); - - $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - - 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, - 'OUTPUT' => $template->assign_display('avatar'), - )); - } } } } diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 6710f1f153..cde4fd95a6 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -127,16 +127,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface return true; } - /** - * @inheritdoc - */ - public function is_enabled() - { - $driver = preg_replace('#^phpbb_avatar_driver_#', '', get_class($this)); - - return $this->config["allow_avatar_$driver"]; - } - /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index d2f25a989f..7a58a40b0c 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -91,13 +91,6 @@ interface phpbb_avatar_driver_interface */ public function delete($row); - /** - * Check if avatar is enabled - * - * @return bool True if avatar is enabled, false if it's disabled - */ - public function is_enabled(); - /** * Get the avatars template name * diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index ae628f0ce2..8953557acb 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -101,15 +101,20 @@ class phpbb_avatar_manager /** * Load the list of valid drivers * This is executed once and fills self::$valid_drivers + * + * @param bool $force_all Force showing all avatar drivers */ - protected function load_valid_drivers() + protected function load_valid_drivers($force_all = false) { if (!empty($this->avatar_drivers)) { self::$valid_drivers = array(); foreach ($this->avatar_drivers as $driver) { - self::$valid_drivers[$driver->get_name()] = $driver->get_name(); + if ($force_all || $this->is_enabled($driver)) + { + self::$valid_drivers[$driver->get_name()] = $driver->get_name(); + } } } } @@ -117,13 +122,15 @@ class phpbb_avatar_manager /** * Get a list of valid avatar drivers * + * @param bool $force_all Force showing all avatar drivers + * * @return array Array containing a list of the valid avatar drivers */ - public function get_valid_drivers() + public function get_valid_drivers($force_all = false) { if (self::$valid_drivers === false) { - $this->load_valid_drivers(); + $this->load_valid_drivers($force_all); } return self::$valid_drivers; @@ -178,4 +185,18 @@ class phpbb_avatar_manager { return str_replace('.', '_', $name); } + + /** + * Check if avatar is enabled + * + * @param object $driver Avatar driver object + * + * @return bool True if avatar is enabled, false if it's disabled + */ + public function is_enabled($driver) + { + $config_name = preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + + return $this->config["allow_avatar_{$config_name}"]; + } } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 3860d22917..f17e535b0c 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -653,26 +653,23 @@ class ucp_groups { $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->is_enabled()) + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => $avatar->get_template_name(), + )); + + if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { - $avatars_enabled = true; - $template->set_filenames(array( - 'avatar' => $avatar->get_template_name(), + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_upper = strtoupper($driver_name); + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), + + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, + 'OUTPUT' => $template->assign_display('avatar'), )); - - if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) - { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); - $driver_upper = strtoupper($driver_name); - $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - - 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, - 'OUTPUT' => $template->assign_display('avatar'), - )); - } } } } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index c8547e48d8..f5c04bb432 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -633,27 +633,24 @@ class ucp_profile { $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->is_enabled()) + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => $avatar->get_template_name(), + )); + + if ($avatar->prepare_form($template, $avatar_data, $error)) { - $avatars_enabled = true; - $template->set_filenames(array( - 'avatar' => $avatar->get_template_name(), + $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_upper = strtoupper($driver_name); + + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), + 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), + + 'DRIVER' => $driver_name, + 'SELECTED' => $driver == $focused_driver, + 'OUTPUT' => $template->assign_display('avatar'), )); - - if ($avatar->prepare_form($template, $avatar_data, $error)) - { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); - $driver_upper = strtoupper($driver_name); - - $template->assign_block_vars('avatar_drivers', array( - 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), - 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), - - 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, - 'OUTPUT' => $template->assign_display('avatar'), - )); - } } } } From 562ebe5c12b8a238b94a63ba53b694af4d061bc9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 14:36:18 +0100 Subject: [PATCH 138/234] [feature/avatars] Unify size of avatar_type Previously it was set to 255 in one file while it was 32 in other files. As the size of 32 is rather low this was increased to 255. PHPBB3-10018 --- phpBB/develop/create_schema_files.php | 4 ++-- phpBB/install/schemas/firebird_schema.sql | 4 ++-- phpBB/install/schemas/mssql_schema.sql | 4 ++-- phpBB/install/schemas/mysql_40_schema.sql | 4 ++-- phpBB/install/schemas/mysql_41_schema.sql | 4 ++-- phpBB/install/schemas/oracle_schema.sql | 4 ++-- phpBB/install/schemas/postgres_schema.sql | 4 ++-- phpBB/install/schemas/sqlite_schema.sql | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 1d03a5b06e..895a945e4e 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1168,7 +1168,7 @@ function get_schema_struct() 'group_desc_uid' => array('VCHAR:8', ''), 'group_display' => array('BOOL', 0), 'group_avatar' => array('VCHAR', ''), - 'group_avatar_type' => array('VCHAR:32', ''), + 'group_avatar_type' => array('VCHAR:255', ''), 'group_avatar_width' => array('USINT', 0), 'group_avatar_height' => array('USINT', 0), 'group_rank' => array('UINT', 0), @@ -1823,7 +1823,7 @@ function get_schema_struct() 'user_allow_massemail' => array('BOOL', 1), 'user_options' => array('UINT:11', 230271), 'user_avatar' => array('VCHAR', ''), - 'user_avatar_type' => array('VCHAR:32', ''), + 'user_avatar_type' => array('VCHAR:255', ''), 'user_avatar_width' => array('USINT', 0), 'user_avatar_height' => array('USINT', 0), 'user_sig' => array('MTEXT_UNI', ''), diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index 45ab3af337..d830f0db77 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -445,7 +445,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL, group_display INTEGER DEFAULT 0 NOT NULL, group_avatar VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - group_avatar_type VARCHAR(32) CHARACTER SET NONE DEFAULT '' NOT NULL, + group_avatar_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, group_avatar_width INTEGER DEFAULT 0 NOT NULL, group_avatar_height INTEGER DEFAULT 0 NOT NULL, group_rank INTEGER DEFAULT 0 NOT NULL, @@ -1271,7 +1271,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INTEGER DEFAULT 1 NOT NULL, user_options INTEGER DEFAULT 230271 NOT NULL, user_avatar VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - user_avatar_type VARCHAR(32) CHARACTER SET NONE DEFAULT '' NOT NULL, + user_avatar_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, user_avatar_width INTEGER DEFAULT 0 NOT NULL, user_avatar_height INTEGER DEFAULT 0 NOT NULL, user_sig BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 1925935dc4..d2dd1c1d60 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -553,7 +553,7 @@ CREATE TABLE [phpbb_groups] ( [group_desc_uid] [varchar] (8) DEFAULT ('') NOT NULL , [group_display] [int] DEFAULT (0) NOT NULL , [group_avatar] [varchar] (255) DEFAULT ('') NOT NULL , - [group_avatar_type] [varchar] (32) DEFAULT ('') NOT NULL , + [group_avatar_type] [varchar] (255) DEFAULT ('') NOT NULL , [group_avatar_width] [int] DEFAULT (0) NOT NULL , [group_avatar_height] [int] DEFAULT (0) NOT NULL , [group_rank] [int] DEFAULT (0) NOT NULL , @@ -1555,7 +1555,7 @@ CREATE TABLE [phpbb_users] ( [user_allow_massemail] [int] DEFAULT (1) NOT NULL , [user_options] [int] DEFAULT (230271) NOT NULL , [user_avatar] [varchar] (255) DEFAULT ('') NOT NULL , - [user_avatar_type] [varchar] (32) DEFAULT ('') NOT NULL , + [user_avatar_type] [varchar] (255) DEFAULT ('') NOT NULL , [user_avatar_width] [int] DEFAULT (0) NOT NULL , [user_avatar_height] [int] DEFAULT (0) NOT NULL , [user_sig] [text] DEFAULT ('') NOT NULL , diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 6634615e9f..dfaf3b28e2 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -317,7 +317,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varbinary(8) DEFAULT '' NOT NULL, group_display tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_avatar varbinary(255) DEFAULT '' NOT NULL, - group_avatar_type varbinary(32) DEFAULT '' NOT NULL, + group_avatar_type varbinary(255) DEFAULT '' NOT NULL, group_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -919,7 +919,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, user_options int(11) UNSIGNED DEFAULT '230271' NOT NULL, user_avatar varbinary(255) DEFAULT '' NOT NULL, - user_avatar_type varbinary(32) DEFAULT '' NOT NULL, + user_avatar_type varbinary(255) DEFAULT '' NOT NULL, user_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_sig mediumblob NOT NULL, diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 7823c91fb8..5c27538f86 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -317,7 +317,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) DEFAULT '' NOT NULL, group_display tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_avatar varchar(255) DEFAULT '' NOT NULL, - group_avatar_type varchar(32) DEFAULT '' NOT NULL, + group_avatar_type varchar(255) DEFAULT '' NOT NULL, group_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -919,7 +919,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, user_options int(11) UNSIGNED DEFAULT '230271' NOT NULL, user_avatar varchar(255) DEFAULT '' NOT NULL, - user_avatar_type varchar(32) DEFAULT '' NOT NULL, + user_avatar_type varchar(255) DEFAULT '' NOT NULL, user_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_sig mediumtext NOT NULL, diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 78592decd5..718dd02601 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -610,7 +610,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar2(8) DEFAULT '' , group_display number(1) DEFAULT '0' NOT NULL, group_avatar varchar2(255) DEFAULT '' , - group_avatar_type varchar2(32) DEFAULT '' , + group_avatar_type varchar2(255) DEFAULT '' , group_avatar_width number(4) DEFAULT '0' NOT NULL, group_avatar_height number(4) DEFAULT '0' NOT NULL, group_rank number(8) DEFAULT '0' NOT NULL, @@ -1667,7 +1667,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail number(1) DEFAULT '1' NOT NULL, user_options number(11) DEFAULT '230271' NOT NULL, user_avatar varchar2(255) DEFAULT '' , - user_avatar_type varchar2(32) DEFAULT '' , + user_avatar_type varchar2(255) DEFAULT '' , user_avatar_width number(4) DEFAULT '0' NOT NULL, user_avatar_height number(4) DEFAULT '0' NOT NULL, user_sig clob DEFAULT '' , diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index f85cee4277..3d4d01484e 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -463,7 +463,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) DEFAULT '' NOT NULL, group_display INT2 DEFAULT '0' NOT NULL CHECK (group_display >= 0), group_avatar varchar(255) DEFAULT '' NOT NULL, - group_avatar_type varchar(32) DEFAULT '' NOT NULL, + group_avatar_type varchar(255) DEFAULT '' NOT NULL, group_avatar_width INT2 DEFAULT '0' NOT NULL CHECK (group_avatar_width >= 0), group_avatar_height INT2 DEFAULT '0' NOT NULL CHECK (group_avatar_height >= 0), group_rank INT4 DEFAULT '0' NOT NULL CHECK (group_rank >= 0), @@ -1169,7 +1169,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INT2 DEFAULT '1' NOT NULL CHECK (user_allow_massemail >= 0), user_options INT4 DEFAULT '230271' NOT NULL CHECK (user_options >= 0), user_avatar varchar(255) DEFAULT '' NOT NULL, - user_avatar_type varchar(32) DEFAULT '' NOT NULL, + user_avatar_type varchar(255) DEFAULT '' NOT NULL, user_avatar_width INT2 DEFAULT '0' NOT NULL CHECK (user_avatar_width >= 0), user_avatar_height INT2 DEFAULT '0' NOT NULL CHECK (user_avatar_height >= 0), user_sig TEXT DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index 900ed06bfe..8f488416ce 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -309,7 +309,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) NOT NULL DEFAULT '', group_display INTEGER UNSIGNED NOT NULL DEFAULT '0', group_avatar varchar(255) NOT NULL DEFAULT '', - group_avatar_type varchar(32) NOT NULL DEFAULT '', + group_avatar_type varchar(255) NOT NULL DEFAULT '', group_avatar_width INTEGER UNSIGNED NOT NULL DEFAULT '0', group_avatar_height INTEGER UNSIGNED NOT NULL DEFAULT '0', group_rank INTEGER UNSIGNED NOT NULL DEFAULT '0', @@ -893,7 +893,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INTEGER UNSIGNED NOT NULL DEFAULT '1', user_options INTEGER UNSIGNED NOT NULL DEFAULT '230271', user_avatar varchar(255) NOT NULL DEFAULT '', - user_avatar_type varchar(32) NOT NULL DEFAULT '', + user_avatar_type varchar(255) NOT NULL DEFAULT '', user_avatar_width INTEGER UNSIGNED NOT NULL DEFAULT '0', user_avatar_height INTEGER UNSIGNED NOT NULL DEFAULT '0', user_sig mediumtext(16777215) NOT NULL DEFAULT '', From d5cbedaaa28312c107ec562c78ffaa034595f336 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 15:12:34 +0100 Subject: [PATCH 139/234] [feature/avatars] Let avatar manager handle $ignore_config The avatar manager already handles if avatars are enabled. It should also handle ignoring the config settings. PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/avatar/driver/driver.php | 4 ++-- phpBB/includes/avatar/driver/gravatar.php | 25 ++++++---------------- phpBB/includes/avatar/driver/interface.php | 16 ++++++-------- phpBB/includes/avatar/driver/local.php | 23 ++++++-------------- phpBB/includes/avatar/driver/remote.php | 23 ++++++-------------- phpBB/includes/avatar/manager.php | 9 ++++---- phpBB/includes/functions_display.php | 2 +- 8 files changed, 35 insertions(+), 69 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index a15a1b9a78..75956736f7 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -351,7 +351,7 @@ class acp_groups } else { - $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']) + $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); if ($avatar) { $avatar->delete($avatar_data); diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index cde4fd95a6..317fe91b83 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -78,7 +78,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc */ - public function get_data($row, $ignore_config = false) + public function get_data($row) { return array( 'src' => '', @@ -90,7 +90,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc */ - public function get_custom_html($row, $ignore_config = false, $alt = '') + public function get_custom_html($row, $alt = '') { return ''; } diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 6ceac1a149..001a741c3f 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -29,30 +29,19 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * @inheritdoc */ - public function get_data($row, $ignore_config = false) + public function get_data($row) { - if ($ignore_config || $this->config['allow_avatar_gravatar']) - { - return array( - 'src' => $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } + return array( + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); } /** * @inheritdoc */ - public function get_custom_html($row, $ignore_config = false, $alt = '') + public function get_custom_html($row, $alt = '') { return ' '', 'width' => 0, 'height' => 0] + * ['src' => '', 'width' => 0, 'height' => 0] */ - public function get_data($row, $ignore_config = false); + public function get_data($row); /** * Returns custom html if it is needed for displaying this avatar * - * @param bool $ignore_config Whether this function should respect the users prefs - * and board configuration configuration option, or should just render - * the avatar anyways. Useful for the ACP. + * @param string $alt Alternate text for avatar image + * * @return string HTML */ - public function get_custom_html($row, $ignore_config = false, $alt = ''); + public function get_custom_html($row, $alt = ''); /** * Prepare form for changing the settings of this avatar diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index d46ac79d11..479ee3712a 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -24,24 +24,13 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver /** * @inheritdoc */ - public function get_data($row, $ignore_config = false) + public function get_data($row) { - if ($ignore_config || $this->config['allow_avatar_local']) - { - return array( - 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } + return array( + 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); } /** diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 1da5fc16e8..344275a251 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -24,24 +24,13 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver /** * @inheritdoc */ - public function get_data($row, $ignore_config = false) + public function get_data($row) { - if ($ignore_config || $this->config['allow_avatar_remote']) - { - return array( - 'src' => $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } + return array( + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); } /** diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 8953557acb..a0e1070322 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -54,15 +54,16 @@ class phpbb_avatar_manager /** * Get the driver object specified by the avatar type * - * @param string Avatar type; by default an avatar's service container name + * @param string $avatar_type Avatar type; by default an avatar's service container name + * @param bool $force_all Grab all avatar drivers, no matter if enabled or not * * @return object Avatar driver object */ - public function get_driver($avatar_type) + public function get_driver($avatar_type, $force_all = false) { - if (self::$valid_drivers === false) + if (self::$valid_drivers === false || $force_all) { - $this->load_valid_drivers(); + $this->load_valid_drivers($force_all); } // Legacy stuff... diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index a7b28acac1..f88d8c9054 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1367,7 +1367,7 @@ function get_avatar($row, $alt, $ignore_config = false) ); $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); + $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config); $html = ''; if ($avatar) From 33b98dc5ba0b690fdae72acfd676dae5a897cb6a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 16:46:11 +0100 Subject: [PATCH 140/234] [feature/avatars] Fix variable names PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/acp/acp_groups.php | 24 +++++++++----------- phpBB/includes/acp/acp_users.php | 34 +++++++++++++--------------- phpBB/includes/avatar/manager.php | 1 + phpBB/includes/functions_display.php | 8 +++---- phpBB/includes/ucp/ucp_groups.php | 31 ++++++++++++------------- phpBB/includes/ucp/ucp_profile.php | 30 ++++++++++++------------ 7 files changed, 62 insertions(+), 68 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index c3bdf89866..0467cc7c35 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -109,7 +109,7 @@ class acp_board case 'avatar': $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(true); - sort($avatar_drivers); + $avatar_vars = array(); foreach ($avatar_drivers as $driver) { diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 75956736f7..23f6d775ef 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -282,7 +282,6 @@ class acp_groups $user->add_lang('ucp'); // Setup avatar data for later - $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; $avatar_drivers = null; $avatar_data = null; @@ -290,8 +289,8 @@ class acp_groups if ($config['allow_avatar']) { + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); - sort($avatar_drivers); // This is normalised data, without the group_ prefix $avatar_data = phpbb_avatar_manager::clean_row($group_row); @@ -334,27 +333,26 @@ class acp_groups if ($config['allow_avatar']) { // Handle avatar - $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) + if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { - $avatar = $phpbb_avatar_manager->get_driver($driver); - $result = $avatar->process_form($template, $avatar_data, $avatar_error); + $driver = $phpbb_avatar_manager->get_driver($driver_name); + $result = $driver->process_form($template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { - $result['avatar_type'] = $driver; + $result['avatar_type'] = $driver_name; $submit_ary = array_merge($submit_ary, $result); } } else { - $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); - if ($avatar) + $driver = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); + if ($driver) { - $avatar->delete($avatar_data); + $driver->delete($avatar_data); } // Removing the avatar @@ -526,7 +524,7 @@ class acp_groups foreach ($avatar_drivers as $driver) { - $avatar = $phpbb_avatar_manager->get_driver($driver); + $driver = $phpbb_avatar_manager->get_driver($driver); $avatars_enabled = true; $config_name = preg_replace('#^avatar\.driver.#', '', $driver); @@ -534,7 +532,7 @@ class acp_groups 'avatar' => "acp_avatar_options_$config_name.html", )); - if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) + if ($driver->prepare_form($template, $avatar_data, $avatar_error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); $driver_upper = strtoupper($driver_name); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index d5532e35b6..3df373a7d4 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1733,12 +1733,11 @@ class acp_users include($phpbb_root_path . 'includes/functions_display.' . $phpEx); $avatars_enabled = false; - $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); if ($config['allow_avatar']) { + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); - sort($avatar_drivers); // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_manager::clean_row($user_row); @@ -1747,19 +1746,18 @@ class acp_users { if (check_form_key($form_name)) { - $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) + if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { - $avatar = $phpbb_avatar_manager->get_driver($driver); - $result = $avatar->process_form($template, $avatar_data, $error); + $driver = $phpbb_avatar_manager->get_driver($driver_name); + $result = $driver->process_form($template, $avatar_data, $error); if ($result && empty($error)) { // Success! Lets save the result in the database $result = array( - 'user_avatar_type' => $driver, + 'user_avatar_type' => $driver_name, 'user_avatar' => $result['avatar'], 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height'], @@ -1775,10 +1773,10 @@ class acp_users } else { - $avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); - if ($avatar) + $driver = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']); + if ($driver) { - $avatar->delete($avatar_data); + $driver->delete($avatar_data); } // Removing the avatar @@ -1805,19 +1803,19 @@ class acp_users $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type'])); - foreach ($avatar_drivers as $driver) + foreach ($avatar_drivers as $current_driver) { - $avatar = $phpbb_avatar_manager->get_driver($driver); + $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $config_name = preg_replace('#^avatar\.driver.#', '', $current_driver); $template->set_filenames(array( 'avatar' => "acp_avatar_options_$config_name.html", )); - if ($avatar->prepare_form($template, $avatar_data, $error)) + if ($driver->prepare_form($template, $avatar_data, $error)) { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( @@ -1825,7 +1823,7 @@ class acp_users 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, + 'SELECTED' => $current_driver == $focused_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } @@ -1842,7 +1840,7 @@ class acp_users } else { - $error[$key] = $user->lang("$lang"); + $error[$key] = $user->lang($lang); } } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index a0e1070322..176d0d659d 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -117,6 +117,7 @@ class phpbb_avatar_manager self::$valid_drivers[$driver->get_name()] = $driver->get_name(); } } + asort(self::$valid_drivers); } } diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index f88d8c9054..6b267bc901 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1367,18 +1367,18 @@ function get_avatar($row, $alt, $ignore_config = false) ); $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config); + $driver = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config); $html = ''; - if ($avatar) + if ($driver) { - $html = $avatar->get_custom_html($row, $ignore_config, $alt); + $html = $driver->get_custom_html($row, $ignore_config, $alt); if (!empty($html)) { return $html; } - $avatar_data = $avatar->get_data($row, $ignore_config); + $avatar_data = $driver->get_data($row, $ignore_config); } else { diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index f17e535b0c..c1ddaccb75 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -484,7 +484,6 @@ class ucp_groups $error = array(); // Setup avatar data for later - $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; $avatar_drivers = null; $avatar_data = null; @@ -492,8 +491,8 @@ class ucp_groups if ($config['allow_avatar']) { + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); - sort($avatar_drivers); // This is normalised data, without the group_ prefix $avatar_data = phpbb_avatar_manager::clean_row($group_row); @@ -521,26 +520,26 @@ class ucp_groups if ($config['allow_avatar']) { // Handle avatar - $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); + $config_name = preg_replace('#^avatar\.driver.#', '', $driver_name); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) + if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { - $avatar = $phpbb_avatar_manager->get_driver($driver); - $result = $avatar->process_form($template, $avatar_data, $avatar_error); + $driver = $phpbb_avatar_manager->get_driver($driver_name); + $result = $driver->process_form($template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { - $result['avatar_type'] = $driver; + $result['avatar_type'] = $driver_name; $submit_ary = array_merge($submit_ary, $result); } } else { - if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + if ($driver = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) { - $avatar->delete($avatar_data); + $driver->delete($avatar_data); } // Removing the avatar @@ -649,25 +648,25 @@ class ucp_groups $avatars_enabled = false; $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); - foreach ($avatar_drivers as $driver) + foreach ($avatar_drivers as $current_driver) { - $avatar = $phpbb_avatar_manager->get_driver($driver); + $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; $template->set_filenames(array( - 'avatar' => $avatar->get_template_name(), + 'avatar' => $driver->get_template_name(), )); - if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) + if ($driver->prepare_form($template, $avatar_data, $avatar_error)) { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, + 'SELECTED' => $current_driver == $focused_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index f5c04bb432..71a4d4e67b 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -552,13 +552,12 @@ class ucp_profile add_form_key('ucp_avatar'); - $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatars_enabled = false; if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { + $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); - sort($avatar_drivers); // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_manager::clean_row($user->data); @@ -567,19 +566,18 @@ class ucp_profile { if (check_form_key('ucp_avatar')) { - $driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); - if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$config_name"] && !$request->is_set_post('avatar_delete')) + if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { - $avatar = $phpbb_avatar_manager->get_driver($driver); - $result = $avatar->process_form($template, $avatar_data, $error); + $driver = $phpbb_avatar_manager->get_driver($driver_name); + $result = $driver->process_form($template, $avatar_data, $error); if ($result && empty($error)) { // Success! Lets save the result in the database $result = array( - 'user_avatar_type' => $driver, + 'user_avatar_type' => $driver_name, 'user_avatar' => $result['avatar'], 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height'], @@ -598,9 +596,9 @@ class ucp_profile } else { - if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + if ($driver = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) { - $avatar->delete($avatar_data); + $driver->delete($avatar_data); } $result = array( @@ -629,18 +627,18 @@ class ucp_profile $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type'])); - foreach ($avatar_drivers as $driver) + foreach ($avatar_drivers as $current_driver) { - $avatar = $phpbb_avatar_manager->get_driver($driver); + $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; $template->set_filenames(array( - 'avatar' => $avatar->get_template_name(), + 'avatar' => $driver->get_template_name(), )); - if ($avatar->prepare_form($template, $avatar_data, $error)) + if ($driver->prepare_form($template, $avatar_data, $error)) { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( @@ -648,7 +646,7 @@ class ucp_profile 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, + 'SELECTED' => $current_driver == $focused_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } From 081440f6c4bd6b7c2838dd0587ed6a4dffc87d52 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Nov 2012 23:11:44 +0100 Subject: [PATCH 141/234] [feature/avatars] Create setting for enabling avatar in manager PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 13 ++++++++--- phpBB/includes/avatar/driver/driver.php | 28 ----------------------- phpBB/includes/avatar/driver/gravatar.php | 10 -------- phpBB/includes/avatar/driver/local.php | 1 - phpBB/includes/avatar/driver/remote.php | 10 -------- phpBB/includes/avatar/driver/upload.php | 22 ++++-------------- phpBB/includes/avatar/manager.php | 16 +++++++++++++ 7 files changed, 31 insertions(+), 69 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 0467cc7c35..bb90918a46 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -111,10 +111,17 @@ class acp_board $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(true); $avatar_vars = array(); - foreach ($avatar_drivers as $driver) + foreach ($avatar_drivers as $current_driver) { - $avatar = $phpbb_avatar_manager->get_driver($driver); - $avatar_vars += $avatar->prepare_form_acp(); + $driver = $phpbb_avatar_manager->get_driver($current_driver); + + /* + * First grab the settings for enabling/disabling the avatar + * driver and afterwards grab additional settings the driver + * might have. + */ + $avatar_vars += $phpbb_avatar_manager->get_avatar_settings($driver); + $avatar_vars += $driver->prepare_form_acp(); } $display_vars = array( diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 317fe91b83..ab89cfbffe 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -75,18 +75,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface $this->cache = $cache; } - /** - * @inheritdoc - */ - public function get_data($row) - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - /** * @inheritdoc */ @@ -95,14 +83,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface return ''; } - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - return false; - } - /** * @inheritdoc */ @@ -111,14 +91,6 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface return array(); } - /** - * @inheritdoc - */ - public function process_form($template, $row, &$error) - { - return false; - } - /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 001a741c3f..8fa95bf937 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -63,16 +63,6 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver return true; } - /** - * @inheritdoc - */ - public function prepare_form_acp() - { - return array( - 'allow_avatar_gravatar' => array('lang' => 'ALLOW_GRAVATAR', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), - ); - } - /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 479ee3712a..4593161a76 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -107,7 +107,6 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function prepare_form_acp() { return array( - 'allow_avatar_local' => array('lang' => 'ALLOW_LOCAL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'avatar_gallery_path' => array('lang' => 'AVATAR_GALLERY_PATH', 'validate' => 'rpath', 'type' => 'text:20:255', 'explain' => true), ); } diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 344275a251..e96cb35684 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -47,16 +47,6 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver return true; } - /** - * @inheritdoc - */ - public function prepare_form_acp() - { - return array( - 'allow_avatar_remote' => array('lang' => 'ALLOW_REMOTE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - ); - } - /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 497dd8ad19..38627baacf 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -26,22 +26,11 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver */ public function get_data($row, $ignore_config = false) { - if ($ignore_config || $this->config['allow_avatar_upload']) - { - return array( - 'src' => $this->phpbb_root_path . 'download/file' . $this->php_ext . '?avatar=' . $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } + return array( + 'src' => $this->phpbb_root_path . 'download/file' . $this->php_ext . '?avatar=' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); } /** @@ -133,7 +122,6 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver global $user; return array( - 'allow_avatar_upload' => array('lang' => 'ALLOW_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'allow_avatar_remote_upload'=> array('lang' => 'ALLOW_REMOTE_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'avatar_filesize' => array('lang' => 'MAX_FILESIZE', 'validate' => 'int:0', 'type' => 'text:4:10', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), 'avatar_path' => array('lang' => 'AVATAR_STORAGE_PATH', 'validate' => 'rwpath', 'type' => 'text:20:255', 'explain' => true), diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 176d0d659d..267ba24dc8 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -201,4 +201,20 @@ class phpbb_avatar_manager return $this->config["allow_avatar_{$config_name}"]; } + + /** + * Get the settings array for enabling/disabling an avatar driver + * + * @param string $driver Avatar driver object + * + * @return array Array of configuration options as consumed by acp_board + */ + public function get_avatar_settings($driver) + { + $config_name = preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + + return array( + 'allow_avatar_' . $config_name => array('lang' => 'ALLOW_' . strtoupper($config_name), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + ); + } } From d439f477105903ceb29652f23bcb7812d0f34d4d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 1 Dec 2012 00:27:52 +0100 Subject: [PATCH 142/234] [feature/avatars] Fix docblocks and minor cosmetic issues PHPBB3-10018 --- phpBB/includes/avatar/driver/gravatar.php | 2 +- phpBB/includes/avatar/driver/interface.php | 27 ++++++++++++++-------- phpBB/includes/avatar/driver/local.php | 2 +- phpBB/includes/avatar/driver/remote.php | 2 +- phpBB/includes/avatar/manager.php | 13 ++++------- phpBB/includes/ucp/ucp_profile.php | 2 +- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 8fa95bf937..11996ca561 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -72,7 +72,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver $row['avatar_width'] = $this->request->variable('avatar_gravatar_width', 0); $row['avatar_height'] = $this->request->variable('avatar_gravatar_height', 0); - if (!function_exists('user_add')) + if (!function_exists('validate_data')) { require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index bba4bd102e..e8f529f3c4 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -24,7 +24,7 @@ interface phpbb_avatar_driver_interface /** * Returns the name of the driver. * - * @return string Name of wrapped driver. + * @return string Name of driver. */ public function get_name(); @@ -50,10 +50,13 @@ interface phpbb_avatar_driver_interface /** * Prepare form for changing the settings of this avatar * - * @param object $template Template object + * @param phpbb_template $template Template object * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row - * @param array &$error Reference to an error array + * @param array &$error Reference to an error array that is filled by this + * function. Key values can either be a string with a language key or + * an array that will be passed to vsprintf() with the language key in + * the first array key. * * @return bool True if form has been successfully prepared */ @@ -62,17 +65,22 @@ interface phpbb_avatar_driver_interface /** * Prepare form for changing the acp settings of this avatar * - * @return array Array containing the acp settings + * @return array Array of configuration options as consumed by acp_board. + * The setting for enabling/disabling the avatar will be handled by + * the avatar manager. */ public function prepare_form_acp(); /** * Process form data * - * @param object $template Template object + * @param phpbb_template $template Template object * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row - * @param array &$error Reference to an error array + * @param array &$error Reference to an error array that is filled by this + * function. Key values can either be a string with a language key or + * an array that will be passed to vsprintf() with the language key in + * the first array key. * * @return array Array containing the avatar data as follows: * ['avatar'], ['avatar_width'], ['avatar_height'] @@ -85,14 +93,15 @@ interface phpbb_avatar_driver_interface * @param array $row User data or group data that has been cleaned with * phpbb_avatar_manager::clean_row * - * @return bool True if avatar has been deleted or there is no need to delete + * @return bool True if avatar has been deleted or there is no need to delete, + * i.e. when the avatar is not hosted locally. */ public function delete($row); /** - * Get the avatars template name + * Get the avatar driver's template name * - * @return string Avatar's template name + * @return string Avatar driver's template name */ public function get_template_name(); } diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 4593161a76..d7611b903a 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -174,7 +174,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver ); } } - @ksort($avatar_list); + ksort($avatar_list); if ($this->cache != null) { diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index e96cb35684..9135a62eac 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -61,7 +61,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver $url = 'http://' . $url; } - if (!function_exists('user_add')) + if (!function_exists('validate_data')) { require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 267ba24dc8..409d0d4eea 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -85,16 +85,11 @@ class phpbb_avatar_manager return null; } + /* + * There is no need to handle invalid avatar types as the following code + * will cause a ServiceNotFoundException if the type does not exist + */ $driver = $this->container->get($avatar_type); - if ($driver !== false) - { - return $driver; - } - else - { - $message = "Invalid avatar driver class name '%s' provided."; - trigger_error(sprintf($message, $avatar_type)); - } return $driver; } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 71a4d4e67b..ecd828c6dc 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -545,7 +545,7 @@ class ucp_profile break; case 'avatar': - if (!function_exists('display_forums')) + if (!function_exists('get_user_avatar')) { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } From 215ac6a0daa51881dc6abb987baf10e682fc9972 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 1 Dec 2012 21:28:44 +0100 Subject: [PATCH 143/234] [feature/avatars] Removed unneeded dependencies PHPBB3-10018 --- phpBB/config/services.yml | 4 ---- phpBB/includes/avatar/manager.php | 10 +--------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 3d33731eea..6649b36ae6 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -17,11 +17,7 @@ services: avatar.manager: class: phpbb_avatar_manager arguments: - - %core.root_path% - - .%core.php_ext% - @config - - @request - - @cache.driver - @avatar.driver_collection - @service_container diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 409d0d4eea..e7ee323624 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -20,11 +20,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_avatar_manager { - protected $phpbb_root_path; - protected $phpEx; protected $config; - protected $request; - protected $cache; protected static $valid_drivers = false; protected $avatar_drivers; protected $container; @@ -40,13 +36,9 @@ class phpbb_avatar_manager * @param array $avatar_drivers Avatar drivers passed via the service container * @param object $container Container object */ - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache, $avatar_drivers, $container) + public function __construct(phpbb_config $config, $avatar_drivers, $container) { - $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; $this->config = $config; - $this->request = $request; - $this->cache = $cache; $this->avatar_drivers = $avatar_drivers; $this->container = $container; } From d771453b520938e21d52ad3464298a9cc0d0fa03 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 1 Dec 2012 21:37:57 +0100 Subject: [PATCH 144/234] [feature/avatars] Add tests for avatar manager PHPBB3-10018 --- tests/avatar/manager_test.php | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/avatar/manager_test.php diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php new file mode 100644 index 0000000000..12c88dd855 --- /dev/null +++ b/tests/avatar/manager_test.php @@ -0,0 +1,82 @@ + 'foobar', + 'user_avatar_width' => 50, + 'user_avatar_height' => 50, + ); + + protected $clean_user_row = array( + 'avatar' => 'foobar', + 'avatar_width' => 50, + 'avatar_height' => 50, + ); + + public function setUp() + { + global $phpbb_root_path, $phpEx; + + // Mock phpbb_container + $this->phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $this->phpbb_container->expects($this->any()) + ->method('get') + ->with('avatar.driver.gravatar')->will($this->returnValue('avatar_foo')); + + // Prepare dependencies for avatar manager and driver + $config = new phpbb_config(array()); + $request = $this->getMock('phpbb_request'); + $cache = $this->getMock('phpbb_cache_driver_interface'); + + // Create new avatar driver object for manager + $this->avatar_gravatar = new phpbb_avatar_driver_gravatar($config, $request, $phpbb_root_path, $phpEx, $cache); + $this->avatar_gravatar->set_name('avatar.driver.gravatar'); + $avatar_drivers = array($this->avatar_gravatar); + + // Set up avatar manager + $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); + } + + public function test_get_driver() + { + $driver = $this->manager->get_driver('avatar.driver.gravatar', true); + $this->assertEquals('avatar_foo', $driver); + + $driver = $this->manager->get_driver('avatar.driver.foo', true); + $this->assertNull($driver); + } + + public function test_get_valid_drivers() + { + $valid_drivers = $this->manager->get_valid_drivers(true); + $this->assertArrayHasKey('avatar.driver.gravatar', $valid_drivers); + $this->assertEquals('avatar.driver.gravatar', $valid_drivers['avatar.driver.gravatar']); + } + + public function test_get_avatar_settings() + { + $avatar_settings = $this->manager->get_avatar_settings($this->avatar_gravatar); + + $expected_settings = array( + 'allow_avatar_gravatar' => array('lang' => 'ALLOW_GRAVATAR', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + ); + + $this->assertEquals($expected_settings, $avatar_settings); + } +} From 232fa5b5884d97329b2bf5c79907dfa0128b618b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 2 Dec 2012 01:19:10 +0100 Subject: [PATCH 145/234] [feature/avatars] Do not use gravatar avatar in tests PHPBB3-10018 --- tests/avatar/driver/foobar.php | 19 +++++++++++++ tests/avatar/manager_test.php | 49 +++++++++++----------------------- 2 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 tests/avatar/driver/foobar.php diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php new file mode 100644 index 0000000000..fe4d47d923 --- /dev/null +++ b/tests/avatar/driver/foobar.php @@ -0,0 +1,19 @@ + 'foobar', - 'user_avatar_width' => 50, - 'user_avatar_height' => 50, - ); - - protected $clean_user_row = array( - 'avatar' => 'foobar', - 'avatar_width' => 50, - 'avatar_height' => 50, - ); - public function setUp() { global $phpbb_root_path, $phpEx; @@ -37,17 +20,17 @@ class phpbb_avatar_test extends PHPUnit_Framework_TestCase $this->phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $this->phpbb_container->expects($this->any()) ->method('get') - ->with('avatar.driver.gravatar')->will($this->returnValue('avatar_foo')); + ->with('avatar.driver.foobar')->will($this->returnValue('avatar.driver.foobar')); // Prepare dependencies for avatar manager and driver $config = new phpbb_config(array()); $request = $this->getMock('phpbb_request'); $cache = $this->getMock('phpbb_cache_driver_interface'); - - // Create new avatar driver object for manager - $this->avatar_gravatar = new phpbb_avatar_driver_gravatar($config, $request, $phpbb_root_path, $phpEx, $cache); - $this->avatar_gravatar->set_name('avatar.driver.gravatar'); - $avatar_drivers = array($this->avatar_gravatar); + $this->avatar_foobar = $this->getMock('phpbb_avatar_driver_foobar', array('get_name'), array($config, $request, $phpbb_root_path, $phpEx, $cache)); + $this->avatar_foobar->expects($this->any()) + ->method('get_name') + ->will($this->returnValue('avatar.driver.foobar')); + $avatar_drivers = array($this->avatar_foobar); // Set up avatar manager $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); @@ -55,26 +38,26 @@ class phpbb_avatar_test extends PHPUnit_Framework_TestCase public function test_get_driver() { - $driver = $this->manager->get_driver('avatar.driver.gravatar', true); - $this->assertEquals('avatar_foo', $driver); + $driver = $this->manager->get_driver('avatar.driver.foobar', true); + $this->assertEquals('avatar.driver.foobar', $driver); - $driver = $this->manager->get_driver('avatar.driver.foo', true); + $driver = $this->manager->get_driver('avatar.driver.foo_wrong', true); $this->assertNull($driver); } public function test_get_valid_drivers() { $valid_drivers = $this->manager->get_valid_drivers(true); - $this->assertArrayHasKey('avatar.driver.gravatar', $valid_drivers); - $this->assertEquals('avatar.driver.gravatar', $valid_drivers['avatar.driver.gravatar']); + $this->assertArrayHasKey('avatar.driver.foobar', $valid_drivers); + $this->assertEquals('avatar.driver.foobar', $valid_drivers['avatar.driver.foobar']); } public function test_get_avatar_settings() { - $avatar_settings = $this->manager->get_avatar_settings($this->avatar_gravatar); + $avatar_settings = $this->manager->get_avatar_settings($this->avatar_foobar); $expected_settings = array( - 'allow_avatar_gravatar' => array('lang' => 'ALLOW_GRAVATAR', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + 'allow_avatar_' . get_class($this->avatar_foobar) => array('lang' => 'ALLOW_' . strtoupper(get_class($this->avatar_foobar)), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), ); $this->assertEquals($expected_settings, $avatar_settings); From ce653db49129f215c18c4d0dab24001d73ba94e6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 2 Dec 2012 01:22:42 +0100 Subject: [PATCH 146/234] [feature/avatars] Remove unnecessary "implements" from foobar avatar PHPBB3-10018 --- tests/avatar/driver/foobar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php index fe4d47d923..fd4e452818 100644 --- a/tests/avatar/driver/foobar.php +++ b/tests/avatar/driver/foobar.php @@ -1,6 +1,6 @@ Date: Tue, 4 Dec 2012 00:49:37 +0100 Subject: [PATCH 147/234] [feature/avatars] Minor variable naming fixes PHPBB3-10018 --- phpBB/adm/style/acp_users_avatar.html | 2 +- phpBB/adm/style/avatars.js | 6 +++--- phpBB/includes/acp/acp_groups.php | 4 ++-- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/ucp/ucp_groups.php | 4 ++-- phpBB/includes/ucp/ucp_profile.php | 4 ++-- phpBB/styles/prosilver/template/avatars.js | 6 +++--- phpBB/styles/subsilver2/template/avatars.js | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index bc3a19a25e..0a72bb0b62 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -32,8 +32,8 @@
-
{S_FORM_TOKEN} + diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index 882bcfe36d..a53814c15f 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -2,14 +2,14 @@ "use strict"; -function avatar_simplify() { +function avatar_hide() { $('#avatar_options > div').hide(); var selected = $('#avatar_driver').val(); $('#avatar_option_' + selected).show(); } -avatar_simplify(); -$('#avatar_driver').bind('change', avatar_simplify); +avatar_hide(); +$('#avatar_driver').bind('change', avatar_hide); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 23f6d775ef..b425b9d374 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -520,7 +520,7 @@ class acp_groups if ($config['allow_avatar']) { $avatars_enabled = false; - $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); + $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); foreach ($avatar_drivers as $driver) { @@ -541,7 +541,7 @@ class acp_groups 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $focused_driver, + 'SELECTED' => $driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 3df373a7d4..5c485b5996 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1801,7 +1801,7 @@ class acp_users } } - $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type'])); + $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type'])); foreach ($avatar_drivers as $current_driver) { @@ -1823,7 +1823,7 @@ class acp_users 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $current_driver == $focused_driver, + 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index c1ddaccb75..262e7b238f 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -646,7 +646,7 @@ class ucp_groups if ($config['allow_avatar']) { $avatars_enabled = false; - $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); + $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); foreach ($avatar_drivers as $current_driver) { @@ -666,7 +666,7 @@ class ucp_groups 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $current_driver == $focused_driver, + 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index ecd828c6dc..7b4dddf12b 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -625,7 +625,7 @@ class ucp_profile } } - $focused_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type'])); + $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type'])); foreach ($avatar_drivers as $current_driver) { @@ -646,7 +646,7 @@ class ucp_profile 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $current_driver == $focused_driver, + 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index 882bcfe36d..a53814c15f 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -2,14 +2,14 @@ "use strict"; -function avatar_simplify() { +function avatar_hide() { $('#avatar_options > div').hide(); var selected = $('#avatar_driver').val(); $('#avatar_option_' + selected).show(); } -avatar_simplify(); -$('#avatar_driver').bind('change', avatar_simplify); +avatar_hide(); +$('#avatar_driver').bind('change', avatar_hide); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/subsilver2/template/avatars.js b/phpBB/styles/subsilver2/template/avatars.js index df6aad178a..733056a32d 100644 --- a/phpBB/styles/subsilver2/template/avatars.js +++ b/phpBB/styles/subsilver2/template/avatars.js @@ -2,14 +2,14 @@ "use strict"; -function avatar_simplify() { +function avatar_hide() { $('.[class^="avatar_option_"]').hide(); var selected = $('#avatar_driver').val(); $('.avatar_option_' + selected).show(); } -avatar_simplify(); -$('#avatar_driver').bind('change', avatar_simplify); +avatar_hide(); +$('#avatar_driver').bind('change', avatar_hide); })(jQuery); // Avoid conflicts with other libraries From fc4069f81df54630a5ac8c1373c38f4834553012 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Dec 2012 00:59:37 +0100 Subject: [PATCH 148/234] [feature/avatars] Use seperate function for retrieving all drivers PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/avatar/manager.php | 25 ++++++++++++++++++++++--- tests/avatar/manager_test.php | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index bb90918a46..9e63e59403 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -108,7 +108,7 @@ class acp_board case 'avatar': $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(true); + $avatar_drivers = $phpbb_avatar_manager->get_all_drivers(); $avatar_vars = array(); foreach ($avatar_drivers as $current_driver) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index e7ee323624..279278b71c 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -109,13 +109,32 @@ class phpbb_avatar_manager } /** - * Get a list of valid avatar drivers + * Get a list of all avatar drivers * - * @param bool $force_all Force showing all avatar drivers + * @return array Array containing a list of all avatar drivers + */ + public function get_all_drivers() + { + $drivers = array(); + + if (!empty($this->avatar_drivers)) + { + foreach ($this->avatar_drivers as $driver) + { + $drivers[$driver->get_name()] = $driver->get_name(); + } + asort($drivers); + } + + return $drivers; + } + + /** + * Get a list of valid avatar drivers * * @return array Array containing a list of the valid avatar drivers */ - public function get_valid_drivers($force_all = false) + public function get_valid_drivers() { if (self::$valid_drivers === false) { diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 9f28e1522d..af0a2edccc 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -47,7 +47,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase public function test_get_valid_drivers() { - $valid_drivers = $this->manager->get_valid_drivers(true); + $valid_drivers = $this->manager->get_all_drivers(); $this->assertArrayHasKey('avatar.driver.foobar', $valid_drivers); $this->assertEquals('avatar.driver.foobar', $valid_drivers['avatar.driver.foobar']); } From 8aaa3e055fdc50faeea6f590408a7bcbb03a8d92 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Dec 2012 15:11:14 +0100 Subject: [PATCH 149/234] [feature/avatars] Use seperate function for retrieving the config name PHPBB3-10018 --- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatar/manager.php | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 5c485b5996..b3cfd81949 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1808,7 +1808,7 @@ class acp_users $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; - $config_name = preg_replace('#^avatar\.driver.#', '', $current_driver); + $config_name = $phpbb_avatar_manager->get_driver_config_name($driver); $template->set_filenames(array( 'avatar' => "acp_avatar_options_$config_name.html", )); diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 279278b71c..81a135b46f 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -203,7 +203,7 @@ class phpbb_avatar_manager */ public function is_enabled($driver) { - $config_name = preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + $config_name = $this->get_driver_config_name($driver); return $this->config["allow_avatar_{$config_name}"]; } @@ -211,16 +211,28 @@ class phpbb_avatar_manager /** * Get the settings array for enabling/disabling an avatar driver * - * @param string $driver Avatar driver object + * @param object $driver Avatar driver object * * @return array Array of configuration options as consumed by acp_board */ public function get_avatar_settings($driver) { - $config_name = preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + $config_name = $this->get_driver_config_name($driver); return array( 'allow_avatar_' . $config_name => array('lang' => 'ALLOW_' . strtoupper($config_name), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), ); } + + /** + * Get the config name of an avatar driver + * + * @param object $driver Avatar driver object + * + * @return string Avatar driver config name + */ + public function get_driver_config_name($driver) + { + return preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + } } From fb139a88203fb5475712c2bc39e653996cd9103f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Dec 2012 15:12:04 +0100 Subject: [PATCH 150/234] [feature/avatars] Fix behavior of avatar manager and variables The $force_all variable was only partially removed and the behavior was not consistent in all files. PHPBB3-10018 --- phpBB/includes/acp/acp_board.php | 2 +- phpBB/includes/acp/acp_groups.php | 10 +++++----- phpBB/includes/avatar/manager.php | 20 ++++++++++---------- tests/avatar/manager_test.php | 7 +++++-- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 9e63e59403..a48d6eda83 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -113,7 +113,7 @@ class acp_board $avatar_vars = array(); foreach ($avatar_drivers as $current_driver) { - $driver = $phpbb_avatar_manager->get_driver($current_driver); + $driver = $phpbb_avatar_manager->get_driver($current_driver, false); /* * First grab the settings for enabling/disabling the avatar diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index b425b9d374..ae0abdd139 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -522,26 +522,26 @@ class acp_groups $avatars_enabled = false; $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); - foreach ($avatar_drivers as $driver) + foreach ($avatar_drivers as $current_driver) { - $driver = $phpbb_avatar_manager->get_driver($driver); + $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; - $config_name = preg_replace('#^avatar\.driver.#', '', $driver); + $config_name = $phpbb_avatar_manager->get_driver_config_name($driver); $template->set_filenames(array( 'avatar' => "acp_avatar_options_$config_name.html", )); if ($driver->prepare_form($template, $avatar_data, $avatar_error)) { - $driver_name = $phpbb_avatar_manager->prepare_driver_name($driver); + $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array( 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, - 'SELECTED' => $driver == $selected_driver, + 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'), )); } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 81a135b46f..2789158de5 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -47,17 +47,19 @@ class phpbb_avatar_manager * Get the driver object specified by the avatar type * * @param string $avatar_type Avatar type; by default an avatar's service container name - * @param bool $force_all Grab all avatar drivers, no matter if enabled or not + * @param bool $load_valid Load only valid avatars * * @return object Avatar driver object */ - public function get_driver($avatar_type, $force_all = false) + public function get_driver($avatar_type, $load_valid = true) { - if (self::$valid_drivers === false || $force_all) + if (self::$valid_drivers === false) { - $this->load_valid_drivers($force_all); + $this->load_valid_drivers(); } + $avatar_drivers = ($load_valid) ? self::$valid_drivers : $this->get_all_drivers(); + // Legacy stuff... switch ($avatar_type) { @@ -72,7 +74,7 @@ class phpbb_avatar_manager break; } - if (!isset(self::$valid_drivers[$avatar_type])) + if (!isset($avatar_drivers[$avatar_type])) { return null; } @@ -89,17 +91,15 @@ class phpbb_avatar_manager /** * Load the list of valid drivers * This is executed once and fills self::$valid_drivers - * - * @param bool $force_all Force showing all avatar drivers */ - protected function load_valid_drivers($force_all = false) + protected function load_valid_drivers() { if (!empty($this->avatar_drivers)) { self::$valid_drivers = array(); foreach ($this->avatar_drivers as $driver) { - if ($force_all || $this->is_enabled($driver)) + if ($this->is_enabled($driver)) { self::$valid_drivers[$driver->get_name()] = $driver->get_name(); } @@ -138,7 +138,7 @@ class phpbb_avatar_manager { if (self::$valid_drivers === false) { - $this->load_valid_drivers($force_all); + $this->load_valid_drivers(); } return self::$valid_drivers; diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index af0a2edccc..cae72c982b 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -38,10 +38,13 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase public function test_get_driver() { - $driver = $this->manager->get_driver('avatar.driver.foobar', true); + $driver = $this->manager->get_driver('avatar.driver.foobar', false); $this->assertEquals('avatar.driver.foobar', $driver); - $driver = $this->manager->get_driver('avatar.driver.foo_wrong', true); + $driver = $this->manager->get_driver('avatar.driver.foo_wrong', false); + $this->assertNull($driver); + + $driver = $this->manager->get_driver('avatar.driver.foobar'); $this->assertNull($driver); } From 780a8c98aca5dc54e1b85a79f8ff0f04ce49c5e4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Dec 2012 14:28:52 +0100 Subject: [PATCH 151/234] [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(-) 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; } From 5213ee1829c0ca4689d6137ac011cc759a727c59 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Dec 2012 14:39:57 +0100 Subject: [PATCH 152/234] [ticket/10714] Make attributed protected rather then private PHPBB3-10714 --- phpBB/includes/log/log.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index eff084bbd2..b6f275835c 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -25,22 +25,22 @@ class phpbb_log implements phpbb_log_interface /** * Keeps the status of the log system. Is the log enabled or disabled? */ - private $disabled_logs; + protected $disabled_logs; /** * Keeps the total log count of the last call to get_logs() */ - private $logs_total; + protected $logs_total; /** * Keeps the offset of the last valid page of the last call to get_logs() */ - private $logs_offset; + protected $logs_offset; /** * The table we use to store our logs. */ - private $log_table; + protected $log_table; /** * Constructor From 70d23380aa55c2aab33c1c2e5cea57f186314584 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Dec 2012 15:11:56 +0100 Subject: [PATCH 153/234] [ticket/10714] Rely on global instead of creating an instance PHPBB3-10714 --- phpBB/includes/functions.php | 6 ------ phpBB/includes/functions_admin.php | 6 ------ 2 files changed, 12 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 93dfb4cd7f..7c1a48f913 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3367,12 +3367,6 @@ function add_log() return false; } - // no log class set, create a temporary one ourselves to keep backwards compatibility - if ($phpbb_log === null) - { - $phpbb_log = new phpbb_log(LOG_TABLE); - } - $mode = array_shift($args); // This looks kind of dirty, but add_log has some additional data before the log_operation diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 2a87feed51..8a1f34e76d 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2490,12 +2490,6 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id { global $phpbb_log; - // no log class set, create a temporary one ourselves to keep backwards compatability - if ($phpbb_log === null) - { - $phpbb_log = new phpbb_log(LOG_TABLE); - } - $count_logs = ($log_count !== false); $log = $phpbb_log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords); From 0f94ff91383ee0ed533048db96a34164ba94b0a4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Dec 2012 16:05:57 +0100 Subject: [PATCH 154/234] [ticket/10714] Add global variables for the unit tests PHPBB3-10714 --- tests/log/function_add_log_test.php | 4 +++- tests/log/function_view_log_test.php | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 77c4578baa..7ed862c523 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -142,7 +142,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case */ public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) { - global $db, $user, $phpbb_dispatcher; + global $db, $cache, $user, $phpbb_log, $phpbb_dispatcher; if ($expected) { @@ -155,7 +155,9 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case } $db = $this->new_dbal(); + $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $phpbb_log = new phpbb_log(LOG_TABLE); $user->ip = 'user_ip'; if ($user_id) diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 790597e9c8..f7e2c51c32 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -24,7 +24,8 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case public static function test_view_log_function_data() { - global $phpEx; + global $phpEx, $phpbb_dispatcher; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $expected_data_sets = array( 1 => array( @@ -299,11 +300,12 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case */ public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '') { - global $cache, $db, $user, $auth, $phpbb_dispatcher; + global $cache, $db, $user, $auth, $phpbb_log, $phpbb_dispatcher; $db = $this->new_dbal(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $phpbb_log = new phpbb_log(LOGS_TABLE); // Create auth mock $auth = $this->getMock('phpbb_auth'); From 7f1b0eeb711c57de82235d7893d793969ed0cfdd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Dec 2012 16:28:46 +0100 Subject: [PATCH 155/234] [ticket/10714] Compare log_type to false, rather then null PHPBB3-10714 --- phpBB/includes/log/log.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index b6f275835c..c2ebedd6f2 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -278,14 +278,14 @@ class phpbb_log implements phpbb_log_interface break; default: - $log_type = null; + $log_type = false; $sql_additional = ''; } /** * Overwrite log type and limitations before we count and get the logs * - * NOTE: if log_type is not set, no entries will be returned. + * NOTE: if log_type is false, no entries will be returned. * * @event core.get_logs_modify_type * @var string mode Mode of the entries we display @@ -302,7 +302,7 @@ class phpbb_log implements phpbb_log_interface * keywords in log_operation or log_data * @var string profile_url URL to the users profile * @var int log_type Limit logs to a certain type. If log_type - * is not set, no entries will be returned. + * is false, no entries will be returned. * @var string sql_additional Additional conditions for the entries, * e.g.: 'AND l.forum_id = 1' * @since 3.1-A1 @@ -310,7 +310,7 @@ class phpbb_log implements phpbb_log_interface $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); extract($phpbb_dispatcher->trigger_event('core.get_logs_modify_type', $vars)); - if (!isset($log_type)) + if ($log_type === false) { $this->logs_offset = 0; return array(); From 26bde05a30c7111b57621a37d86425aa69d74263 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 9 Dec 2012 19:42:50 +0100 Subject: [PATCH 156/234] [feature/avatars] Call set_name() method in avatars.yml This is needed after 8a28271d was merged. PHPBB3-10018 --- phpBB/config/avatars.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/config/avatars.yml b/phpBB/config/avatars.yml index cc9ed05836..e6106038f5 100644 --- a/phpBB/config/avatars.yml +++ b/phpBB/config/avatars.yml @@ -7,6 +7,8 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver + calls: + - [set_name, [avatar.driver.gravatar]] tags: - { name: avatar.driver } @@ -18,6 +20,8 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver + calls: + - [set_name, [avatar.driver.local]] tags: - { name: avatar.driver } @@ -29,6 +33,8 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver + calls: + - [set_name, [avatar.driver.remote]] tags: - { name: avatar.driver } @@ -40,5 +46,7 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver + calls: + - [set_name, [avatar.driver.upload]] tags: - { name: avatar.driver } From 83b8b65016f172baa65cbbb463015602c97e9e45 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 9 Dec 2012 23:47:46 +0100 Subject: [PATCH 157/234] [ticket/10714] Use dependencies instead of globals We use a setter for the admin root path, as it is not defined all the time. Aswell as we added a setter for the table name, so it can still be used for custom tables. PHPBB3-10714 --- phpBB/config/services.yml | 11 +++ phpBB/config/tables.yml | 1 + phpBB/includes/log/log.php | 163 ++++++++++++++++++++++++++----------- 3 files changed, 129 insertions(+), 46 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 37e6c0b5df..73d8680803 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -154,6 +154,17 @@ services: tags: - { name: kernel.event_subscriber } + log: + class: phpbb_log + arguments: + - @dbal.conn + - @user + - @auth + - @dispatcher + - %core.root_path% + - %core.php_ext% + - %tables.log% + request: class: phpbb_request diff --git a/phpBB/config/tables.yml b/phpBB/config/tables.yml index cfc6dbcfed..b506e6c6b3 100644 --- a/phpBB/config/tables.yml +++ b/phpBB/config/tables.yml @@ -1,3 +1,4 @@ parameters: tables.config: %core.table_prefix%config tables.ext: %core.table_prefix%ext + tables.log: %core.table_prefix%log diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index c2ebedd6f2..3d9620a2ee 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -42,15 +42,96 @@ class phpbb_log implements phpbb_log_interface */ protected $log_table; + /** + * Database object + * @var dbal + */ + protected $db; + + /** + * User object + * @var phpbb_user + */ + protected $user; + + /** + * Auth object + * @var phpbb_auth + */ + protected $auth; + + /** + * Event dispatcher object + * @var phpbb_dispatcher + */ + protected $dispatcher; + + /** + * phpBB root path + * @var string + */ + protected $phpbb_root_path; + + /** + * Admin root path + * @var string + */ + protected $phpbb_admin_path; + + /** + * PHP Extension + * @var string + */ + protected $php_ext; + /** * Constructor * - * @param string $log_table The table we use to store our logs + * @param dbal $db Database object + * @param phpbb_user $user User object + * @param phpbb_auth $auth Auth object + * @param phpbb_dispatcher $phpbb_dispatcher Event dispatcher + * @param string $phpbb_root_path Root path + * @param string $php_ext PHP Extension + * @param string $log_table Name of the table we use to store our logs + * @return null */ - public function __construct($log_table) + public function __construct(dbal $db, phpbb_user $user, phpbb_auth $auth, phpbb_dispatcher $phpbb_dispatcher, $phpbb_root_path, $php_ext, $log_table) + { + $this->db = $db; + $this->user = $user; + $this->auth = $auth; + $this->dispatcher = $phpbb_dispatcher; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->log_table = $log_table; + + $this->enable(); + $this->set_admin_path('', false); + } + + /** + * Set phpbb_admin_path and is_in_admin in order to return administrative user profile links in get_logs() + * + * @param string $phpbb_admin_path Full path from current file to admin root + * @param bool $is_in_admin Are we called from within the acp? + * @return null + */ + public function set_admin_path($phpbb_admin_path, $is_in_admin) + { + $this->phpbb_admin_path = $phpbb_admin_path; + $this->is_in_admin = (bool) $is_in_admin; + } + + /** + * Set table name + * + * @param string $log_table Can overwrite the table to use for the logs + * @return null + */ + public function set_log_table($log_table) { $this->log_table = $log_table; - $this->enable(); } /** @@ -134,8 +215,6 @@ class phpbb_log implements phpbb_log_interface return false; } - global $db, $phpbb_dispatcher; - if ($log_time == false) { $log_time = time(); @@ -208,7 +287,7 @@ class phpbb_log implements phpbb_log_interface * @since 3.1-A1 */ $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.add_log', $vars)); + extract($this->dispatcher->trigger_event('core.add_log', $vars)); // We didn't find a log_type, so we don't save it in the database. if (!isset($sql_ary['log_type'])) @@ -216,9 +295,9 @@ class phpbb_log implements phpbb_log_interface return false; } - $db->sql_query('INSERT INTO ' . $this->log_table . ' ' . $db->sql_build_array('INSERT', $sql_ary)); + $this->db->sql_query('INSERT INTO ' . $this->log_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary)); - return $db->sql_nextid(); + return $this->db->sql_nextid(); } /** @@ -228,14 +307,12 @@ class phpbb_log implements phpbb_log_interface */ public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '') { - global $db, $user, $auth, $phpEx, $phpbb_root_path, $phpbb_admin_path, $phpbb_dispatcher; - $this->logs_total = 0; $this->logs_offset = $offset; $topic_id_list = $reportee_id_list = array(); - $profile_url = (defined('IN_ADMIN')) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview') : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile'); + $profile_url = ($this->is_in_admin && $this->phpbb_admin_path) ? append_sid("{$this->phpbb_admin_path}index.{$this->php_ext}", 'i=users&mode=overview') : append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile'); switch ($mode) { @@ -254,7 +331,7 @@ class phpbb_log implements phpbb_log_interface } else if (is_array($forum_id)) { - $sql_additional = 'AND ' . $db->sql_in_set('l.forum_id', array_map('intval', $forum_id)); + $sql_additional = 'AND ' . $this->db->sql_in_set('l.forum_id', array_map('intval', $forum_id)); } else if ($forum_id) { @@ -308,7 +385,7 @@ class phpbb_log implements phpbb_log_interface * @since 3.1-A1 */ $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); - extract($phpbb_dispatcher->trigger_event('core.get_logs_modify_type', $vars)); + extract($this->dispatcher->trigger_event('core.get_logs_modify_type', $vars)); if ($log_type === false) { @@ -332,9 +409,9 @@ class phpbb_log implements phpbb_log_interface AND l.log_time >= $log_time $sql_keywords $sql_additional"; - $result = $db->sql_query($sql); - $this->logs_total = (int) $db->sql_fetchfield('total_entries'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $this->logs_total = (int) $this->db->sql_fetchfield('total_entries'); + $this->db->sql_freeresult($result); if ($this->logs_total == 0) { @@ -358,11 +435,11 @@ class phpbb_log implements phpbb_log_interface $sql_keywords $sql_additional ORDER BY $sort_by"; - $result = $db->sql_query_limit($sql, $limit, $this->logs_offset); + $result = $this->db->sql_query_limit($sql, $limit, $this->logs_offset); $i = 0; $log = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $row['forum_id'] = (int) $row['forum_id']; if ($row['topic_id']) @@ -391,8 +468,8 @@ class phpbb_log implements phpbb_log_interface 'forum_id' => (int) $row['forum_id'], 'topic_id' => (int) $row['topic_id'], - 'viewforum' => ($row['forum_id'] && $auth->acl_get('f_read', $row['forum_id'])) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : false, - 'action' => (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}', + 'viewforum' => ($row['forum_id'] && $this->auth->acl_get('f_read', $row['forum_id'])) ? append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']) : false, + 'action' => (isset($this->user->lang[$row['log_operation']])) ? $this->user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}', ); /** @@ -404,7 +481,7 @@ class phpbb_log implements phpbb_log_interface * @since 3.1-A1 */ $vars = array('row', 'log_entry_data'); - extract($phpbb_dispatcher->trigger_event('core.get_logs_modify_entry_data', $vars)); + extract($this->dispatcher->trigger_event('core.get_logs_modify_entry_data', $vars)); $log[$i] = $log_entry_data; @@ -413,7 +490,7 @@ class phpbb_log implements phpbb_log_interface $log_data_ary = @unserialize($row['log_data']); $log_data_ary = ($log_data_ary !== false) ? $log_data_ary : array(); - if (isset($user->lang[$row['log_operation']])) + if (isset($this->user->lang[$row['log_operation']])) { // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array // It doesn't matter if we add more arguments than placeholders @@ -447,7 +524,7 @@ class phpbb_log implements phpbb_log_interface $i++; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); /** * Get some additional data after we got all log entries @@ -461,7 +538,7 @@ class phpbb_log implements phpbb_log_interface * @since 3.1-A1 */ $vars = array('log', 'topic_id_list', 'reportee_id_list'); - extract($phpbb_dispatcher->trigger_event('core.get_logs_get_additional_data', $vars)); + extract($this->dispatcher->trigger_event('core.get_logs_get_additional_data', $vars)); if (sizeof($topic_id_list)) { @@ -469,8 +546,8 @@ class phpbb_log implements phpbb_log_interface foreach ($log as $key => $row) { - $log[$key]['viewtopic'] = (isset($topic_auth['f_read'][$row['topic_id']])) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_auth['f_read'][$row['topic_id']] . '&t=' . $row['topic_id']) : false; - $log[$key]['viewlogs'] = (isset($topic_auth['m_'][$row['topic_id']])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=logs&mode=topic_logs&t=' . $row['topic_id'], true, $user->session_id) : false; + $log[$key]['viewtopic'] = (isset($topic_auth['f_read'][$row['topic_id']])) ? append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $topic_auth['f_read'][$row['topic_id']] . '&t=' . $row['topic_id']) : false; + $log[$key]['viewlogs'] = (isset($topic_auth['m_'][$row['topic_id']])) ? append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", 'i=logs&mode=topic_logs&t=' . $row['topic_id'], true, $this->user->session_id) : false; } } @@ -502,8 +579,6 @@ class phpbb_log implements phpbb_log_interface */ private function generate_sql_keyword($keywords) { - global $db, $user; - // Use no preg_quote for $keywords because this would lead to sole backslashes being added // We also use an OR connection here for spaces and the | string. Currently, regex is not supported for searching (but may come later). $keywords = preg_split('#[\s|]+#u', utf8_strtolower($keywords), 0, PREG_SPLIT_NO_EMPTY); @@ -517,13 +592,13 @@ class phpbb_log implements phpbb_log_interface for ($i = 0, $num_keywords = sizeof($keywords); $i < $num_keywords; $i++) { $keywords_pattern[] = preg_quote($keywords[$i], '#'); - $keywords[$i] = $db->sql_like_expression($db->any_char . $keywords[$i] . $db->any_char); + $keywords[$i] = $this->db->sql_like_expression($this->db->any_char . $keywords[$i] . $this->db->any_char); } $keywords_pattern = '#' . implode('|', $keywords_pattern) . '#ui'; $operations = array(); - foreach ($user->lang as $key => $value) + foreach ($this->user->lang as $key => $value) { if (substr($key, 0, 4) == 'LOG_' && preg_match($keywords_pattern, $value)) { @@ -534,9 +609,9 @@ class phpbb_log implements phpbb_log_interface $sql_keywords = 'AND ('; if (!empty($operations)) { - $sql_keywords .= $db->sql_in_set('l.log_operation', $operations) . ' OR '; + $sql_keywords .= $this->db->sql_in_set('l.log_operation', $operations) . ' OR '; } - $sql_lower = $db->sql_lower_text('l.log_data'); + $sql_lower = $this->db->sql_lower_text('l.log_data'); $sql_keywords .= " $sql_lower " . implode(" OR $sql_lower ", $keywords) . ')'; } @@ -557,32 +632,30 @@ class phpbb_log implements phpbb_log_interface */ private function get_topic_auth($topic_ids) { - global $auth, $db; - $forum_auth = array('f_read' => array(), 'm_' => array()); $topic_ids = array_unique($topic_ids); $sql = 'SELECT topic_id, forum_id FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', array_map('intval', $topic_ids)); - $result = $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('topic_id', array_map('intval', $topic_ids)); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $row['topic_id'] = (int) $row['topic_id']; $row['forum_id'] = (int) $row['forum_id']; - if ($auth->acl_get('f_read', $row['forum_id'])) + if ($this->auth->acl_get('f_read', $row['forum_id'])) { $forum_auth['f_read'][$row['topic_id']] = $row['forum_id']; } - if ($auth->acl_gets('a_', 'm_', $row['forum_id'])) + if ($this->auth->acl_gets('a_', 'm_', $row['forum_id'])) { $forum_auth['m_'][$row['topic_id']] = $row['forum_id']; } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $forum_auth; } @@ -596,21 +669,19 @@ class phpbb_log implements phpbb_log_interface */ private function get_reportee_data($reportee_ids) { - global $db; - $reportee_ids = array_unique($reportee_ids); $reportee_data_list = array(); $sql = 'SELECT user_id, username, user_colour FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $reportee_ids); - $result = $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('user_id', $reportee_ids); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $reportee_data_list[$row['user_id']] = $row; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $reportee_data_list; } From f4bc9c1673c18ed24a2ba1680f6b9a5de5c491bf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Dec 2012 10:24:49 +0100 Subject: [PATCH 158/234] [ticket/10714] Fix dependency injections in unit tests with mocks PHPBB3-10714 --- tests/log/add_test.php | 19 ++++++++++++++++--- tests/log/function_add_log_test.php | 7 +++++-- tests/log/function_view_log_test.php | 5 +++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/tests/log/add_test.php b/tests/log/add_test.php index fceb48ed01..4354cc4cc7 100644 --- a/tests/log/add_test.php +++ b/tests/log/add_test.php @@ -18,7 +18,16 @@ class phpbb_log_add_test extends phpbb_database_test_case public function test_log_enabled() { - $log = new phpbb_log(LOG_TABLE); + global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher; + + $db = $this->new_dbal(); + $cache = new phpbb_mock_cache; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = $this->getMock('phpbb_user'); + $auth = $this->getMock('phpbb_auth'); + + $log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE); + $this->assertTrue($log->is_enabled(), 'Initialise failed'); $log->disable(); @@ -38,10 +47,15 @@ class phpbb_log_add_test extends phpbb_database_test_case public function test_log_add() { - global $db, $phpbb_dispatcher; + global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher; $db = $this->new_dbal(); + $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = $this->getMock('phpbb_user'); + $auth = $this->getMock('phpbb_auth'); + + $log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE); $mode = 'critical'; $user_id = ANONYMOUS; @@ -51,7 +65,6 @@ class phpbb_log_add_test extends phpbb_database_test_case $additional_data = array(); // Add an entry successful - $log = new phpbb_log(LOG_TABLE); $this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time)); // Disable logging for all types diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 7ed862c523..0a65ce3165 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -142,7 +142,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case */ public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) { - global $db, $cache, $user, $phpbb_log, $phpbb_dispatcher; + global $db, $cache, $user, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx; if ($expected) { @@ -157,7 +157,10 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case $db = $this->new_dbal(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $phpbb_log = new phpbb_log(LOG_TABLE); + $user = $this->getMock('phpbb_user'); + $auth = $this->getMock('phpbb_auth'); + + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE); $user->ip = 'user_ip'; if ($user_id) diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index f7e2c51c32..bb33668ae4 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -300,12 +300,11 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case */ public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '') { - global $cache, $db, $user, $auth, $phpbb_log, $phpbb_dispatcher; + global $cache, $db, $user, $auth, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx; $db = $this->new_dbal(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $phpbb_log = new phpbb_log(LOGS_TABLE); // Create auth mock $auth = $this->getMock('phpbb_auth'); @@ -335,6 +334,8 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'LOG_INSTALL_INSTALLED' => 'installed: %s', ); + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE); + $log = array(); $this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords)); From c7ae790d16f662ef1cdb2e697f3276b9e618f4dd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Dec 2012 10:25:38 +0100 Subject: [PATCH 159/234] [ticket/10714] Remove type hinting to allow the usage of mocks in tests PHPBB3-10714 --- phpBB/includes/log/log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 3d9620a2ee..beb2a659e1 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -96,7 +96,7 @@ class phpbb_log implements phpbb_log_interface * @param string $log_table Name of the table we use to store our logs * @return null */ - public function __construct(dbal $db, phpbb_user $user, phpbb_auth $auth, phpbb_dispatcher $phpbb_dispatcher, $phpbb_root_path, $php_ext, $log_table) + public function __construct($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $php_ext, $log_table) { $this->db = $db; $this->user = $user; From bd334d318fb61992cedfdb7ca1306ad670f392a4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Dec 2012 13:59:21 +0100 Subject: [PATCH 160/234] [ticket/10714] Forgot most important, use container to create $phpbb_log PHPBB3-10714 --- phpBB/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/common.php b/phpBB/common.php index 344b83403f..88ab9b6b5a 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -118,7 +118,7 @@ $config = $phpbb_container->get('config'); set_config(null, null, null, $config); set_config_count(null, null, null, $config); -$phpbb_log = new phpbb_log(LOG_TABLE); +$phpbb_log = $phpbb_container->get('log'); // load extensions $phpbb_extension_manager = $phpbb_container->get('ext.manager'); From 2f47c99432c604a2adaad73821602a4b1763caa8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 11 Dec 2012 21:02:37 +0100 Subject: [PATCH 161/234] [feature/avatars] Add more consistency to codebase PHPBB3-10018 --- .../style/acp_avatar_options_gravatar.html | 4 ++-- .../adm/style/acp_avatar_options_remote.html | 4 ++-- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/avatar/driver/gravatar.php | 19 ++++++++++++------- phpBB/includes/avatar/driver/remote.php | 15 ++++++++++----- phpBB/includes/ucp/ucp_profile.php | 4 ++-- 7 files changed, 31 insertions(+), 21 deletions(-) diff --git a/phpBB/adm/style/acp_avatar_options_gravatar.html b/phpBB/adm/style/acp_avatar_options_gravatar.html index 04fd5c459d..47422a6ecd 100644 --- a/phpBB/adm/style/acp_avatar_options_gravatar.html +++ b/phpBB/adm/style/acp_avatar_options_gravatar.html @@ -5,7 +5,7 @@

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

{L_LINK_REMOTE_SIZE_EXPLAIN}
- ×  - + {L_PIXEL} ×  + {L_PIXEL}
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index ae0abdd139..fe65ea2f03 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -529,7 +529,7 @@ class acp_groups $avatars_enabled = true; $config_name = $phpbb_avatar_manager->get_driver_config_name($driver); $template->set_filenames(array( - 'avatar' => "acp_avatar_options_$config_name.html", + 'avatar' => "acp_avatar_options_{$config_name}.html", )); if ($driver->prepare_form($template, $avatar_data, $avatar_error)) diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index b3cfd81949..b2ef43edbe 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1765,7 +1765,7 @@ class acp_users $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user_id; + WHERE user_id = ' . (int) $user_id; $db->sql_query($sql); trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); @@ -1810,7 +1810,7 @@ class acp_users $avatars_enabled = true; $config_name = $phpbb_avatar_manager->get_driver_config_name($driver); $template->set_filenames(array( - 'avatar' => "acp_avatar_options_$config_name.html", + 'avatar' => "acp_avatar_options_{$config_name}.html", )); if ($driver->prepare_form($template, $avatar_data, $error)) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 11996ca561..2b10fd0c2d 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -77,13 +77,18 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); } - $error = array_merge($error, validate_data(array( - 'email' => $row['avatar'], - ), array( - 'email' => array( - array('string', false, 6, 60), - array('email')), - ))); + $validate_array = validate_data( + array( + 'email' => $row['avatar'], + ), + array( + 'email' => array( + array('string', false, 6, 60), + array('email')) + ) + ); + + $error = array_merge($error, $validate_array); if (!empty($error)) { diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 9135a62eac..1f16fce1e7 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -66,11 +66,16 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext); } - $error = array_merge($error, validate_data(array( - 'url' => $url, - ), array( - 'url' => array('string', true, 5, 255), - ))); + $validate_array = validate_data( + array( + 'url' => $url, + ), + array( + 'url' => array('string', true, 5, 255), + ) + ); + + $error = array_merge($error, $validate_array); if (!empty($error)) { diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 14639b00ff..8ed5aff3e3 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -590,7 +590,7 @@ class ucp_profile $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user->data['user_id']; + WHERE user_id = ' . (int) $user->data['user_id']; $db->sql_query($sql); @@ -615,7 +615,7 @@ class ucp_profile $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_id = ' . $user->data['user_id']; + WHERE user_id = ' . (int) $user->data['user_id']; $db->sql_query($sql); From 512697341a9c570ee11697eb221ef18d2fadfe45 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 18:47:22 +0100 Subject: [PATCH 162/234] [ticket/10714] Fix database driver class name PHPBB3-10714 --- phpBB/includes/log/log.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index beb2a659e1..521a998d8e 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -44,7 +44,7 @@ class phpbb_log implements phpbb_log_interface /** * Database object - * @var dbal + * @var phpbb_db_driver */ protected $db; @@ -87,9 +87,9 @@ class phpbb_log implements phpbb_log_interface /** * Constructor * - * @param dbal $db Database object - * @param phpbb_user $user User object - * @param phpbb_auth $auth Auth object + * @param phpbb_db_driver $db Database object + * @param phpbb_user $user User object + * @param phpbb_auth $auth Auth object * @param phpbb_dispatcher $phpbb_dispatcher Event dispatcher * @param string $phpbb_root_path Root path * @param string $php_ext PHP Extension From e6aaef6066549696453063417167e5a79c53b353 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 15 Dec 2012 15:22:39 +0100 Subject: [PATCH 163/234] [feature/avatars] Use callback method in avatar manager's clean row PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 2789158de5..f5c93a6328 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -157,17 +157,22 @@ class phpbb_avatar_manager $keys = array_keys($row); $values = array_values($row); - $keys = array_map( - function ($key) - { - return preg_replace('#^(?:user_|group_)#', '', $key); - }, - $keys - ); + $keys = array_map(array('phpbb_avatar_manager', 'strip_prefix'), $keys); return array_combine($keys, $values); } + /** + * Strip prepending user_ or group_ prefix from key + * + * @param string Array key + * @return string Key that has been stripped from its prefix + */ + protected static function strip_prefix($key) + { + return preg_replace('#^(?:user_|group_)#', '', $key); + } + /** * Clean driver names that are returned from template files * Underscores are replaced with dots From ea6bf00977a44d437806e87e9cac1b9d5fcef238 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 20:39:02 +0100 Subject: [PATCH 164/234] [feature/avatars] Improve testing to also check for enabled drivers PHPBB3-10018 --- tests/avatar/manager_test.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index cae72c982b..b910db59ee 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -31,6 +31,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase ->method('get_name') ->will($this->returnValue('avatar.driver.foobar')); $avatar_drivers = array($this->avatar_foobar); + $config['allow_avatar_' . get_class($this->avatar_foobar)] = true; // Set up avatar manager $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); @@ -45,14 +46,24 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase $this->assertNull($driver); $driver = $this->manager->get_driver('avatar.driver.foobar'); + $this->assertEquals('avatar.driver.foobar', $driver); + + $driver = $this->manager->get_driver('avatar.driver.foo_wrong'); $this->assertNull($driver); } - public function test_get_valid_drivers() + public function test_get_all_drivers() { - $valid_drivers = $this->manager->get_all_drivers(); - $this->assertArrayHasKey('avatar.driver.foobar', $valid_drivers); - $this->assertEquals('avatar.driver.foobar', $valid_drivers['avatar.driver.foobar']); + $drivers = $this->manager->get_all_drivers(); + $this->assertArrayHasKey('avatar.driver.foobar', $drivers); + $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); + } + + public function test_get_enabled_drivers() + { + $drivers = $this->manager->get_enabled_drivers(); + $this->assertArrayHasKey('avatar.driver.foobar', $drivers); + $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); } public function test_get_avatar_settings() From c865f98dcfe57c3dff231fdf3574f5d3356ab7f5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 20:42:05 +0100 Subject: [PATCH 165/234] [feature/avatars] Some more miscellaneous changes PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatar/driver/remote.php | 2 +- phpBB/includes/avatar/driver/upload.php | 2 +- phpBB/includes/avatar/manager.php | 44 ++++++++++++------------- phpBB/includes/ucp/ucp_groups.php | 2 +- phpBB/includes/ucp/ucp_profile.php | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index fe65ea2f03..eeeefe03ba 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -290,7 +290,7 @@ class acp_groups if ($config['allow_avatar']) { $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the group_ prefix $avatar_data = phpbb_avatar_manager::clean_row($group_row); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index b2ef43edbe..0c29eb658f 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1737,7 +1737,7 @@ class acp_users if ($config['allow_avatar']) { $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_manager::clean_row($user_row); diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index 1f16fce1e7..717b73eb0c 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -117,7 +117,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver if (!class_exists('fileupload')) { - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + include($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); } $types = fileupload::image_types(); diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 38627baacf..4facb243ac 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -63,7 +63,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver if (!class_exists('fileupload')) { - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); + include($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext); } $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index f5c93a6328..cbc9c4a485 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) class phpbb_avatar_manager { protected $config; - protected static $valid_drivers = false; + static protected $enabled_drivers = false; protected $avatar_drivers; protected $container; @@ -47,18 +47,18 @@ class phpbb_avatar_manager * Get the driver object specified by the avatar type * * @param string $avatar_type Avatar type; by default an avatar's service container name - * @param bool $load_valid Load only valid avatars + * @param bool $load_enabled Load only enabled avatars * * @return object Avatar driver object */ - public function get_driver($avatar_type, $load_valid = true) + public function get_driver($avatar_type, $load_enabled = true) { - if (self::$valid_drivers === false) + if (self::$enabled_drivers === false) { - $this->load_valid_drivers(); + $this->load_enabled_drivers(); } - $avatar_drivers = ($load_valid) ? self::$valid_drivers : $this->get_all_drivers(); + $avatar_drivers = ($load_enabled) ? self::$enabled_drivers : $this->get_all_drivers(); // Legacy stuff... switch ($avatar_type) @@ -89,22 +89,22 @@ class phpbb_avatar_manager } /** - * Load the list of valid drivers - * This is executed once and fills self::$valid_drivers + * Load the list of enabled drivers + * This is executed once and fills self::$enabled_drivers */ - protected function load_valid_drivers() + protected function load_enabled_drivers() { if (!empty($this->avatar_drivers)) { - self::$valid_drivers = array(); + self::$enabled_drivers = array(); foreach ($this->avatar_drivers as $driver) { if ($this->is_enabled($driver)) { - self::$valid_drivers[$driver->get_name()] = $driver->get_name(); + self::$enabled_drivers[$driver->get_name()] = $driver->get_name(); } } - asort(self::$valid_drivers); + asort(self::$enabled_drivers); } } @@ -130,18 +130,18 @@ class phpbb_avatar_manager } /** - * Get a list of valid avatar drivers + * Get a list of enabled avatar drivers * - * @return array Array containing a list of the valid avatar drivers + * @return array Array containing a list of the enabled avatar drivers */ - public function get_valid_drivers() + public function get_enabled_drivers() { - if (self::$valid_drivers === false) + if (self::$enabled_drivers === false) { - $this->load_valid_drivers(); + $this->load_enabled_drivers(); } - return self::$valid_drivers; + return self::$enabled_drivers; } /** @@ -152,7 +152,7 @@ class phpbb_avatar_manager * @return array User data or group data with keys that have been * stripped from the preceding "user_" or "group_" */ - public static function clean_row($row) + static public function clean_row($row) { $keys = array_keys($row); $values = array_values($row); @@ -168,7 +168,7 @@ class phpbb_avatar_manager * @param string Array key * @return string Key that has been stripped from its prefix */ - protected static function strip_prefix($key) + static protected function strip_prefix($key) { return preg_replace('#^(?:user_|group_)#', '', $key); } @@ -181,7 +181,7 @@ class phpbb_avatar_manager * * @return string Cleaned driver name */ - public static function clean_driver_name($name) + static public function clean_driver_name($name) { return str_replace('_', '.', $name); } @@ -194,7 +194,7 @@ class phpbb_avatar_manager * * @return string Prepared driver name */ - public static function prepare_driver_name($name) + static public function prepare_driver_name($name) { return str_replace('.', '_', $name); } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 262e7b238f..18f782f63e 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -492,7 +492,7 @@ class ucp_groups if ($config['allow_avatar']) { $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the group_ prefix $avatar_data = phpbb_avatar_manager::clean_row($group_row); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 8ed5aff3e3..3f59cda4a0 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -562,7 +562,7 @@ class ucp_profile if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_manager::clean_row($user->data); From 6f41228752fbb00139da5fd3f62c884a4391de82 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 20:46:07 +0100 Subject: [PATCH 166/234] [feature/avatars] Add missing explanation to docblock of get_all_drivers() PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index cbc9c4a485..68d1133e86 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -111,6 +111,10 @@ class phpbb_avatar_manager /** * Get a list of all avatar drivers * + * As this function will only be called in the ACP avatar settings page, it + * doesn't make much sense to cache the list of all avatar drivers like the + * list of the enabled drivers. + * * @return array Array containing a list of all avatar drivers */ public function get_all_drivers() From 8e756ad89005865b42e87ffc225f6d3bca475035 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Dec 2012 21:40:35 +0100 Subject: [PATCH 167/234] [feature/avatars] Let the server handle http or https for gravatars PHPBB3-10018 --- phpBB/includes/avatar/driver/gravatar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php index 2b10fd0c2d..c6bfb0d5c1 100644 --- a/phpBB/includes/avatar/driver/gravatar.php +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -24,7 +24,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver /** * The URL for the gravatar service */ - const GRAVATAR_URL = 'https://secure.gravatar.com/avatar/'; + const GRAVATAR_URL = '//secure.gravatar.com/avatar/'; /** * @inheritdoc From 4a8b1a6e050bba7f8f73f689bbca4185ab27cf8c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Jan 2013 10:25:08 +0100 Subject: [PATCH 168/234] [feature/avatars] Inform user of no available local avatars Rather than showing the user an empty drop-down list for the local avatar categories, inform him/her that there are currently no (local) avatars available. PHPBB3-10018 --- phpBB/language/en/common.php | 1 + .../styles/prosilver/template/ucp_avatar_options_local.html | 4 ++++ .../subsilver2/template/ucp_avatar_options_local.html | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 6277457af7..02b4443a56 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -396,6 +396,7 @@ $lang = array_merge($lang, array( 'NO_AUTH_ADMIN' => 'Access to the Administration Control Panel is not allowed as you do not have administrative permissions.', 'NO_AUTH_ADMIN_USER_DIFFER' => 'You are not able to re-authenticate as a different user.', 'NO_AUTH_OPERATION' => 'You do not have the necessary permissions to complete this operation.', + 'NO_AVATARS' => 'No avatars currently available', 'NO_CONNECT_TO_SMTP_HOST' => 'Could not connect to smtp host : %1$s : %2$s', 'NO_BIRTHDAYS' => 'No birthdays today', 'NO_EMAIL_MESSAGE' => 'Email message was blank.', diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html index d885abcd5b..3946b9d269 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options_local.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_local.html @@ -1,3 +1,4 @@ +
+
{L_AVATAR_CATEGORY}{L_COLON}
+ + + {L_NO_AVATARS} + + From 7256a2d944df10ef649794c6174fea5ca69adea3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Jan 2013 15:10:43 +0100 Subject: [PATCH 169/234] [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(-) 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' => '', From 8f8527a416be41ba5f2ac984e944f76817260ed2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Jan 2013 17:23:22 +0100 Subject: [PATCH 170/234] [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(-) 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.', From a342e47038dc62cc824efe688e574a1a7dbb0ac8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Jan 2013 18:13:49 +0100 Subject: [PATCH 171/234] [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(-) 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 From 111e02395c2879662e2a3d07558519b838ddb69a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 5 Jan 2013 20:17:53 +0100 Subject: [PATCH 172/234] [feature/avatars] Add missing docblocks to avatar manager PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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; /** From 41710c745d5507aa71e25b125b0ae1485cc7ecc1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 6 Jan 2013 21:09:07 +0100 Subject: [PATCH 173/234] [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(-) 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( From 8867cb60b1f7074c9f83c0403e5259148da65204 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 7 Jan 2013 21:16:39 +0100 Subject: [PATCH 174/234] [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(-) 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"', From 023d7a972dd5c279e0b0b24801f9e53e7865d39a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 7 Jan 2013 22:49:48 +0100 Subject: [PATCH 175/234] [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 ++-- tests/avatar/driver/foobar.php | 6 +++--- tests/avatar/manager_test.php | 4 ++-- 12 files changed, 41 insertions(+), 46 deletions(-) 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); diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php index fd4e452818..a68d0aa6c6 100644 --- a/tests/avatar/driver/foobar.php +++ b/tests/avatar/driver/foobar.php @@ -7,13 +7,13 @@ class phpbb_avatar_driver_foobar extends phpbb_avatar_driver return array(); } - public function prepare_form($template, $row, &$error) + public function prepare_form($request, $template, $row, &$error) { return false; } - public function process_form($template, $row, &$error) + public function process_form($request, $template, $row, &$error) { return false; } -} \ No newline at end of file +} diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index b910db59ee..fd7132ea82 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -26,12 +26,12 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase $config = new phpbb_config(array()); $request = $this->getMock('phpbb_request'); $cache = $this->getMock('phpbb_cache_driver_interface'); - $this->avatar_foobar = $this->getMock('phpbb_avatar_driver_foobar', array('get_name'), array($config, $request, $phpbb_root_path, $phpEx, $cache)); + $this->avatar_foobar = $this->getMock('phpbb_avatar_driver_foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); $this->avatar_foobar->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.foobar')); $avatar_drivers = array($this->avatar_foobar); - $config['allow_avatar_' . get_class($this->avatar_foobar)] = true; + $config['allow_avatar_' . get_class($this->avatar_foobar)] = true; // Set up avatar manager $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); From 8778c9c945e388c2b727f1b7cd057dd67a091441 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Jan 2013 15:34:20 +0100 Subject: [PATCH 176/234] [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(-) 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; From 9e001153d6a64a90353207c4da8b01329f8e39e5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Jan 2013 15:42:30 +0100 Subject: [PATCH 177/234] [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(-) 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']), From cb08bf3c0cac1f15ae46238a00a56ff7bf72efda Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Jan 2013 21:46:43 +0100 Subject: [PATCH 178/234] [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(-) 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); } } From caa3516d134360c86b00c3f8104f3ac7157b0e47 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Jan 2013 21:58:03 +0100 Subject: [PATCH 179/234] [feature/avatars] Differentiate tests for get drivers functions Tests for get_all_drivers() and get_enabled_drivers() should be different. PHPBB3-10018 --- tests/avatar/driver/barfoo.php | 19 +++++++++++++++++++ tests/avatar/manager_test.php | 13 ++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/avatar/driver/barfoo.php diff --git a/tests/avatar/driver/barfoo.php b/tests/avatar/driver/barfoo.php new file mode 100644 index 0000000000..936b6e0559 --- /dev/null +++ b/tests/avatar/driver/barfoo.php @@ -0,0 +1,19 @@ +getMock('phpbb_request'); $cache = $this->getMock('phpbb_cache_driver_interface'); + $this->avatar_foobar = $this->getMock('phpbb_avatar_driver_foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); $this->avatar_foobar->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.foobar')); - $avatar_drivers = array($this->avatar_foobar); + $this->avatar_barfoo = $this->getMock('phpbb_avatar_driver_barfoo', array('get_name')); + $this->avatar_barfoo->expects($this->any()) + ->method('get_name') + ->will($this->returnValue('avatar.driver.barfoo')); + + $avatar_drivers = array($this->avatar_foobar, $this->avatar_barfoo); + $config['allow_avatar_' . get_class($this->avatar_foobar)] = true; + $config['allow_avatar_' . get_class($this->avatar_barfoo)] = false; // Set up avatar manager $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); @@ -56,13 +64,16 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase { $drivers = $this->manager->get_all_drivers(); $this->assertArrayHasKey('avatar.driver.foobar', $drivers); + $this->assertArrayHasKey('avatar.driver.barfoo', $drivers); $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); + $this->assertEquals('avatar.driver.barfoo', $drivers['avatar.driver.barfoo']); } public function test_get_enabled_drivers() { $drivers = $this->manager->get_enabled_drivers(); $this->assertArrayHasKey('avatar.driver.foobar', $drivers); + $this->assertArrayNotHasKey('avatar.driver.barfoo', $drivers); $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); } From 7ea0376958f917c3c62dff7814daaa2fcf330dca Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Jan 2013 22:47:05 +0100 Subject: [PATCH 180/234] [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(-) 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 @@   - +
From 7402add107591ba675bc27248825b7bc9daedee4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 9 Jan 2013 15:50:15 +0100 Subject: [PATCH 181/234] [feature/avatars] Add missing @var to docblocks in avatar manager PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 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; From 46b75f4cf925ee0da852beeb6c4932e4fcb37992 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 15 Jan 2013 13:20:35 +0100 Subject: [PATCH 182/234] [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(+) 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 From aeeb85e1cfb9c6a54fc74942e42bc602d2a108a1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 15 Jan 2013 22:07:01 +0100 Subject: [PATCH 183/234] [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(-) 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 From 84272b1028eb0a30abffa898005c99c4f271888b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 15 Jan 2013 22:13:23 +0100 Subject: [PATCH 184/234] [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(-) 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: From 37014abd022be4f7824a590b93a329f74aef442c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 16 Jan 2013 14:18:09 +0100 Subject: [PATCH 185/234] [ticket/10714] Fix several comments and variable names PHPBB3-10714 --- phpBB/includes/log/interface.php | 20 ++++--- phpBB/includes/log/log.php | 85 ++++++++++++++-------------- tests/log/function_view_log_test.php | 2 +- 3 files changed, 53 insertions(+), 54 deletions(-) diff --git a/phpBB/includes/log/interface.php b/phpBB/includes/log/interface.php index b85dc3a474..254b65cb19 100644 --- a/phpBB/includes/log/interface.php +++ b/phpBB/includes/log/interface.php @@ -25,40 +25,42 @@ interface phpbb_log_interface /** * This function returns the state of the log system. * - * @param string $type The log type we want to check. Empty to get global log status. + * @param string $type The log type we want to check. Empty to get + * global log status. * * @return bool True if log for the type is enabled */ public function is_enabled($type = ''); /** - * This function allows disable the log system. When add_log is called, the log will not be added to the database. + * This function allows disabling the log system. When add_log is called + * and the type is disabled, the log will not be added to the database. * - * @param mixed $type The log type we want to disable. Empty to disable all logs. - * Can also be an array of types + * @param mixed $type The log type we want to disable. Empty to + * disable all logs. Can also be an array of types. * * @return null */ public function disable($type = ''); /** - * This function allows re-enable the log system. + * This function allows re-enabling the log system. * - * @param mixed $type The log type we want to enable. Empty to enable all logs. - * Can also be an array of types + * @param mixed $type The log type we want to enable. Empty to + * enable all logs. Can also be an array of types. * * @return null */ public function enable($type = ''); /** - * Adds a log to the database + * Adds a log entry to the database * * @param string $mode The mode defines which log_type is used and in which log the entry is displayed. * @param int $user_id User ID of the user * @param string $log_ip IP address of the user * @param string $log_operation Name of the operation - * @param int $log_time Timestamp when the log was added. + * @param int $log_time Timestamp when the log entry was added. * @param array $additional_data More arguments can be added, depending on the log_type * * @return int|bool Returns the log_id, if the entry was added to the database, false otherwise. diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 521a998d8e..0ee3c9561f 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -23,19 +23,21 @@ if (!defined('IN_PHPBB')) class phpbb_log implements phpbb_log_interface { /** - * Keeps the status of the log system. Is the log enabled or disabled? + * An array with the disabled log types. Logs of such types will not be + * added when add_log() is called. + * @var array */ - protected $disabled_logs; + protected $disabled_types; /** * Keeps the total log count of the last call to get_logs() */ - protected $logs_total; + protected $entry_count; /** * Keeps the offset of the last valid page of the last call to get_logs() */ - protected $logs_offset; + protected $last_page_offset; /** * The table we use to store our logs. @@ -111,7 +113,8 @@ class phpbb_log implements phpbb_log_interface } /** - * Set phpbb_admin_path and is_in_admin in order to return administrative user profile links in get_logs() + * Set phpbb_admin_path and is_in_admin in order to return administrative + * user profile links in get_logs() * * @param string $phpbb_admin_path Full path from current file to admin root * @param bool $is_in_admin Are we called from within the acp? @@ -137,26 +140,22 @@ class phpbb_log implements phpbb_log_interface /** * This function returns the state of the log system. * - * @param string $type The log type we want to check. Empty to get global log status. - * - * @return bool True if log for the type is enabled + * {@inheritDoc} */ public function is_enabled($type = '') { if ($type == '' || $type == 'all') { - return !isset($this->disabled_logs['all']); + return !isset($this->disabled_types['all']); } - return !isset($this->disabled_logs[$type]) && !isset($this->disabled_logs['all']); + return !isset($this->disabled_types[$type]) && !isset($this->disabled_types['all']); } /** - * This function allows disable the log system. When add_log is called, the log will not be added to the database. + * This function allows disabling the log system. When add_log is called + * and the type is disabled, the log will not be added to the database. * - * @param mixed $type The log type we want to enable. Empty to disable all logs. - * Can also be an array of types - * - * @return null + * {@inheritDoc} */ public function disable($type = '') { @@ -169,20 +168,18 @@ class phpbb_log implements phpbb_log_interface return; } - if ($type == '' || $type == 'all') + // Empty string is an equivalent for all types. + if ($type == '') { - $this->disabled_logs['all'] = true; - return; + $type = 'all'; } - $this->disabled_logs[$type] = true; + $this->disabled_types[$type] = true; } /** - * This function allows re-enable the log system. + * This function allows re-enabling the log system. * - * @param mixed $type The log type we want to enable. Empty to enable all logs. - * - * @return null + * {@inheritDoc} */ public function enable($type = '') { @@ -197,10 +194,10 @@ class phpbb_log implements phpbb_log_interface if ($type == '' || $type == 'all') { - $this->disabled_logs = array(); + $this->disabled_types = array(); return; } - unset($this->disabled_logs[$type]); + unset($this->disabled_types[$type]); } /** @@ -269,7 +266,7 @@ class phpbb_log implements phpbb_log_interface } /** - * Allow to modify log data before we add them to the database + * Allows to modify log data before we add it to the database * * NOTE: if sql_ary does not contain a log_type value, the entry will * not be stored in the database. So ensure to set it, if needed. @@ -307,8 +304,8 @@ class phpbb_log implements phpbb_log_interface */ public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '') { - $this->logs_total = 0; - $this->logs_offset = $offset; + $this->entry_count = 0; + $this->last_page_offset = $offset; $topic_id_list = $reportee_id_list = array(); @@ -389,7 +386,7 @@ class phpbb_log implements phpbb_log_interface if ($log_type === false) { - $this->logs_offset = 0; + $this->last_page_offset = 0; return array(); } @@ -410,20 +407,20 @@ class phpbb_log implements phpbb_log_interface $sql_keywords $sql_additional"; $result = $this->db->sql_query($sql); - $this->logs_total = (int) $this->db->sql_fetchfield('total_entries'); + $this->entry_count = (int) $this->db->sql_fetchfield('total_entries'); $this->db->sql_freeresult($result); - if ($this->logs_total == 0) + if ($this->entry_count == 0) { // Save the queries, because there are no logs to display - $this->logs_offset = 0; + $this->last_page_offset = 0; return array(); } // Return the user to the last page that is valid - while ($this->logs_offset >= $this->logs_total) + while ($this->last_page_offset >= $this->entry_count) { - $this->logs_offset = max(0, $this->logs_offset - $limit); + $this->last_page_offset = max(0, $this->last_page_offset - $limit); } } @@ -435,7 +432,7 @@ class phpbb_log implements phpbb_log_interface $sql_keywords $sql_additional ORDER BY $sort_by"; - $result = $this->db->sql_query_limit($sql, $limit, $this->logs_offset); + $result = $this->db->sql_query_limit($sql, $limit, $this->last_page_offset); $i = 0; $log = array(); @@ -487,7 +484,7 @@ class phpbb_log implements phpbb_log_interface if (!empty($row['log_data'])) { - $log_data_ary = @unserialize($row['log_data']); + $log_data_ary = unserialize($row['log_data']); $log_data_ary = ($log_data_ary !== false) ? $log_data_ary : array(); if (isset($this->user->lang[$row['log_operation']])) @@ -571,13 +568,13 @@ class phpbb_log implements phpbb_log_interface } /** - * Generates a sql condition out of the specified keywords + * Generates a sql condition for the specified keywords * * @param string $keywords The keywords the user specified to search for * * @return string Returns the SQL condition searching for the keywords */ - private function generate_sql_keyword($keywords) + protected function generate_sql_keyword($keywords) { // Use no preg_quote for $keywords because this would lead to sole backslashes being added // We also use an OR connection here for spaces and the | string. Currently, regex is not supported for searching (but may come later). @@ -630,7 +627,7 @@ class phpbb_log implements phpbb_log_interface * ), * ), */ - private function get_topic_auth($topic_ids) + protected function get_topic_auth(array $topic_ids) { $forum_auth = array('f_read' => array(), 'm_' => array()); $topic_ids = array_unique($topic_ids); @@ -667,7 +664,7 @@ class phpbb_log implements phpbb_log_interface * * @return array Returns an array with the reportee data */ - private function get_reportee_data($reportee_ids) + protected function get_reportee_data(array $reportee_ids) { $reportee_ids = array_unique($reportee_ids); $reportee_data_list = array(); @@ -689,20 +686,20 @@ class phpbb_log implements phpbb_log_interface /** * Get total log count * - * @return int Returns the number of matching logs from the last call to get_logs() + * {@inheritDoc} */ public function get_log_count() { - return ($this->logs_total) ? $this->logs_total : 0; + return ($this->entry_count) ? $this->entry_count : 0; } /** * Get offset of the last valid log page * - * @return int Returns the offset of the last valid page from the last call to get_logs() + * {@inheritDoc} */ public function get_valid_offset() { - return ($this->logs_offset) ? $this->logs_offset : 0; + return ($this->last_page_offset) ? $this->last_page_offset : 0; } } diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index bb33668ae4..7401e1ee4f 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -215,7 +215,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case array( // Array of datasets that should be in $log after running the function 'expected' => array(5, 7), - // Offset that will be returned form the function + // Offset that will be returned from the function 'expected_returned' => 0, // view_log parameters (see includes/functions_admin.php for docblock) // $log is ommited! From 786e2438d5138213447003272b36b4185cad2b42 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 16 Jan 2013 16:23:41 +0100 Subject: [PATCH 186/234] [ticket/10714] Use new core.adm_relative_path to create the object. PHPBB3-10714 --- phpBB/config/services.yml | 1 + phpBB/includes/log/log.php | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 7fd13d4eea..129cd4a4f9 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -164,6 +164,7 @@ services: - @auth - @dispatcher - %core.root_path% + - %core.adm_relative_path% - %core.php_ext% - %tables.log% diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 0ee3c9561f..092fdb6a89 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -94,35 +94,40 @@ class phpbb_log implements phpbb_log_interface * @param phpbb_auth $auth Auth object * @param phpbb_dispatcher $phpbb_dispatcher Event dispatcher * @param string $phpbb_root_path Root path + * @param string $relative_admin_path Relative admin root path * @param string $php_ext PHP Extension * @param string $log_table Name of the table we use to store our logs * @return null */ - public function __construct($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $php_ext, $log_table) + public function __construct($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $relative_admin_path, $php_ext, $log_table) { $this->db = $db; $this->user = $user; $this->auth = $auth; $this->dispatcher = $phpbb_dispatcher; $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $this->phpbb_root_path . $relative_admin_path; $this->php_ext = $php_ext; $this->log_table = $log_table; + /* + * IN_ADMIN is set after the session was created, + * so we need to take ADMIN_START into account aswell, otherwise + * it will not work for the phpbb_log object we create in common.php + */ + $this->set_is_admin((defined('ADMIN_START') && ADMIN_START) || (defined('IN_ADMIN') && IN_ADMIN)); $this->enable(); - $this->set_admin_path('', false); } /** - * Set phpbb_admin_path and is_in_admin in order to return administrative - * user profile links in get_logs() + * Set is_in_admin in order to return administrative user profile links + * in get_logs() * - * @param string $phpbb_admin_path Full path from current file to admin root * @param bool $is_in_admin Are we called from within the acp? * @return null */ - public function set_admin_path($phpbb_admin_path, $is_in_admin) + public function set_is_admin($is_in_admin) { - $this->phpbb_admin_path = $phpbb_admin_path; $this->is_in_admin = (bool) $is_in_admin; } From 2c4e7eabe248fc785cd2b43f57a42580361c599d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Jan 2013 15:10:35 +0100 Subject: [PATCH 187/234] [ticket/10714] Fix missing 8th argument in unit tests PHPBB3-10714 --- tests/log/add_test.php | 4 ++-- tests/log/function_add_log_test.php | 2 +- tests/log/function_view_log_test.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/log/add_test.php b/tests/log/add_test.php index 4354cc4cc7..a5f93232f2 100644 --- a/tests/log/add_test.php +++ b/tests/log/add_test.php @@ -26,7 +26,7 @@ class phpbb_log_add_test extends phpbb_database_test_case $user = $this->getMock('phpbb_user'); $auth = $this->getMock('phpbb_auth'); - $log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE); + $log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $this->assertTrue($log->is_enabled(), 'Initialise failed'); @@ -55,7 +55,7 @@ class phpbb_log_add_test extends phpbb_database_test_case $user = $this->getMock('phpbb_user'); $auth = $this->getMock('phpbb_auth'); - $log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE); + $log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $mode = 'critical'; $user_id = ANONYMOUS; diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 0a65ce3165..4e54a75dd6 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -160,7 +160,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case $user = $this->getMock('phpbb_user'); $auth = $this->getMock('phpbb_auth'); - $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE); + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $user->ip = 'user_ip'; if ($user_id) diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 7401e1ee4f..2ecf77aeb8 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -334,7 +334,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'LOG_INSTALL_INSTALLED' => 'installed: %s', ); - $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE); + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $log = array(); $this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords)); From c0ab3f3ddddefa8f902ffa57c864e6db5bf1f440 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Jan 2013 15:45:20 +0100 Subject: [PATCH 188/234] [ticket/10714] Fix several doc blocks and comments PHPBB3-10714 --- phpBB/includes/functions_admin.php | 4 ++-- phpBB/includes/log/interface.php | 10 +++++----- phpBB/includes/log/log.php | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 18b11182d0..60591e98d3 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2489,12 +2489,12 @@ function cache_moderators() /** * View log * -* @param string $mode The mode defines which log_type is used and in which log the entry is displayed. +* @param string $mode The mode defines which log_type is used and from which log the entry is retrieved * @param array &$log The result array with the logs * @param mixed &$log_count If $log_count is set to false, we will skip counting all entries in the database. * Otherwise an integer with the number of total matching entries is returned. * @param int $limit Limit the number of entries that are returned -* @param int $offset Offset when fetching the log entries, f.e. on paginations +* @param int $offset Offset when fetching the log entries, f.e. when paginating * @param mixed $forum_id Restrict the log entries to the given forum_id (can also be an array of forum_ids) * @param int $topic_id Restrict the log entries to the given topic_id * @param int $user_id Restrict the log entries to the given user_id diff --git a/phpBB/includes/log/interface.php b/phpBB/includes/log/interface.php index 254b65cb19..24bf412ce0 100644 --- a/phpBB/includes/log/interface.php +++ b/phpBB/includes/log/interface.php @@ -56,24 +56,24 @@ interface phpbb_log_interface /** * Adds a log entry to the database * - * @param string $mode The mode defines which log_type is used and in which log the entry is displayed. + * @param string $mode The mode defines which log_type is used and from which log the entry is retrieved * @param int $user_id User ID of the user * @param string $log_ip IP address of the user * @param string $log_operation Name of the operation - * @param int $log_time Timestamp when the log entry was added. + * @param int $log_time Timestamp when the log entry was added, if empty time() will be used * @param array $additional_data More arguments can be added, depending on the log_type * * @return int|bool Returns the log_id, if the entry was added to the database, false otherwise. */ - public function add($mode, $user_id, $log_ip, $log_operation, $log_time, $additional_data); + public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array()); /** * Grab the logs from the database * - * @param string $mode The mode defines which log_type is used and in which log the entry is displayed. + * @param string $mode The mode defines which log_type is used and ifrom which log the entry is retrieved * @param bool $count_logs Shall we count all matching log entries? * @param int $limit Limit the number of entries that are returned - * @param int $offset Offset when fetching the log entries, f.e. on paginations + * @param int $offset Offset when fetching the log entries, f.e. when paginating * @param mixed $forum_id Restrict the log entries to the given forum_id (can also be an array of forum_ids) * @param int $topic_id Restrict the log entries to the given topic_id * @param int $user_id Restrict the log entries to the given user_id diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 092fdb6a89..33c558695c 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -31,16 +31,19 @@ class phpbb_log implements phpbb_log_interface /** * Keeps the total log count of the last call to get_logs() + * @var int */ protected $entry_count; /** * Keeps the offset of the last valid page of the last call to get_logs() + * @var int */ protected $last_page_offset; /** * The table we use to store our logs. + * @var string */ protected $log_table; @@ -112,7 +115,7 @@ class phpbb_log implements phpbb_log_interface /* * IN_ADMIN is set after the session was created, - * so we need to take ADMIN_START into account aswell, otherwise + * so we need to take ADMIN_START into account as well, otherwise * it will not work for the phpbb_log object we create in common.php */ $this->set_is_admin((defined('ADMIN_START') && ADMIN_START) || (defined('IN_ADMIN') && IN_ADMIN)); From ffde887aadfcb9d3db2c42cf09e22745e5d62430 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Jan 2013 15:46:48 +0100 Subject: [PATCH 189/234] [ticket/10714] Cast values to integer before using them in the query PHPBB3-10714 --- phpBB/includes/log/log.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 33c558695c..841612f7bd 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -408,10 +408,10 @@ class phpbb_log implements phpbb_log_interface if ($count_logs) { $sql = 'SELECT COUNT(l.log_id) AS total_entries - FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u - WHERE l.log_type = $log_type + FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . ' u + WHERE l.log_type = ' . (int) $log_type . ' AND l.user_id = u.user_id - AND l.log_time >= $log_time + AND l.log_time >= ' . (int) $log_time . " $sql_keywords $sql_additional"; $result = $this->db->sql_query($sql); @@ -433,10 +433,10 @@ class phpbb_log implements phpbb_log_interface } $sql = 'SELECT l.*, u.username, u.username_clean, u.user_colour - FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u - WHERE l.log_type = $log_type + FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . ' u + WHERE l.log_type = ' . (int) $log_type . ' AND u.user_id = l.user_id - " . (($log_time) ? "AND l.log_time >= $log_time" : '') . " + ' . (($log_time) ? 'AND l.log_time >= ' . (int) $log_time : '') . " $sql_keywords $sql_additional ORDER BY $sort_by"; From c2504e9300608feea540ab162e4cc0ac79cda7a0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Jan 2013 15:56:34 +0100 Subject: [PATCH 190/234] [ticket/10714] Fix more comments PHPBB3-10714 --- phpBB/includes/log/log.php | 14 +++++++++----- tests/log/function_add_log_test.php | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 841612f7bd..09dff10ae5 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -497,8 +497,10 @@ class phpbb_log implements phpbb_log_interface if (isset($this->user->lang[$row['log_operation']])) { - // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array - // It doesn't matter if we add more arguments than placeholders + // Check if there are more occurrences of % than + // arguments, if there are we fill out the arguments + // array. It doesn't matter if we add more arguments than + // placeholders. if ((substr_count($log[$i]['action'], '%') - sizeof($log_data_ary)) > 0) { $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($log[$i]['action'], '%') - sizeof($log_data_ary), '')); @@ -507,7 +509,7 @@ class phpbb_log implements phpbb_log_interface $log[$i]['action'] = vsprintf($log[$i]['action'], $log_data_ary); // If within the admin panel we do not censor text out - if (defined('IN_ADMIN')) + if ($this->is_in_admin) { $log[$i]['action'] = bbcode_nl2br($log[$i]['action']); } @@ -584,8 +586,10 @@ class phpbb_log implements phpbb_log_interface */ protected function generate_sql_keyword($keywords) { - // Use no preg_quote for $keywords because this would lead to sole backslashes being added - // We also use an OR connection here for spaces and the | string. Currently, regex is not supported for searching (but may come later). + // Use no preg_quote for $keywords because this would lead to sole + // backslashes being added. We also use an OR connection here for + // spaces and the | string. Currently, regex is not supported for + // searching (but may come later). $keywords = preg_split('#[\s|]+#u', utf8_strtolower($keywords), 0, PREG_SPLIT_NO_EMPTY); $sql_keywords = ''; diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 4e54a75dd6..864b364862 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -35,9 +35,9 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case 'forum_id' => 56, 'topic_id' => 78, ), - // user_id Can also be false, than ANONYMOUS is used + // user_id Can also be false, then ANONYMOUS is used false, - // log_mode Used to determinate the log_type + // log_mode Used to determine the log_type 'mod', // Followed by some additional arguments // forum_id, topic_id and reportee_id are specified before log_operation From d5d282005c74a4b9539c3b37d3df723ba6e2c456 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Jan 2013 16:47:05 +0100 Subject: [PATCH 191/234] [ticket/10714] Add getter for is_in_admin and use it PHPBB3-10714 --- phpBB/includes/log/log.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 09dff10ae5..8da8b63391 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -22,6 +22,13 @@ if (!defined('IN_PHPBB')) */ class phpbb_log implements phpbb_log_interface { + /** + * If set, administrative user profile links will be returned and messages + * will not be censored. + * @var bool + */ + protected $is_in_admin; + /** * An array with the disabled log types. Logs of such types will not be * added when add_log() is called. @@ -114,7 +121,7 @@ class phpbb_log implements phpbb_log_interface $this->log_table = $log_table; /* - * IN_ADMIN is set after the session was created, + * IN_ADMIN is set after the session is created, * so we need to take ADMIN_START into account as well, otherwise * it will not work for the phpbb_log object we create in common.php */ @@ -134,6 +141,16 @@ class phpbb_log implements phpbb_log_interface $this->is_in_admin = (bool) $is_in_admin; } + /** + * Returns the is_in_admin option + * + * @return bool + */ + public function get_is_admin() + { + return $this->is_in_admin; + } + /** * Set table name * @@ -317,7 +334,7 @@ class phpbb_log implements phpbb_log_interface $topic_id_list = $reportee_id_list = array(); - $profile_url = ($this->is_in_admin && $this->phpbb_admin_path) ? append_sid("{$this->phpbb_admin_path}index.{$this->php_ext}", 'i=users&mode=overview') : append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile'); + $profile_url = ($this->get_is_admin() && $this->phpbb_admin_path) ? append_sid("{$this->phpbb_admin_path}index.{$this->php_ext}", 'i=users&mode=overview') : append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile'); switch ($mode) { @@ -509,7 +526,7 @@ class phpbb_log implements phpbb_log_interface $log[$i]['action'] = vsprintf($log[$i]['action'], $log_data_ary); // If within the admin panel we do not censor text out - if ($this->is_in_admin) + if ($this->get_is_admin()) { $log[$i]['action'] = bbcode_nl2br($log[$i]['action']); } From 79356f54415f901a8ff743817121216cbefb16ee Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 22 Jan 2013 17:21:49 +0100 Subject: [PATCH 192/234] [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 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); +} From e841453d03003ff0f2c932f5936c17739476ef4f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 22 Jan 2013 21:05:31 +0100 Subject: [PATCH 193/234] [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(-) 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 From e8fd8b9a4b37f7d7d3955cd2b0d79139a2c0222d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Jan 2013 22:40:53 +0100 Subject: [PATCH 194/234] [ticket/10714] Fix missing parameter and global phpbb_log in unit tests PHPBB3-10714 --- phpBB/includes/functions_container.php | 1 + tests/functions_user/group_user_attributes_test.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index a3ed21c35b..36c5ad507e 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -57,6 +57,7 @@ function phpbb_create_install_container($phpbb_root_path, $php_ext) $container = phpbb_create_container(array($core), $phpbb_root_path, $php_ext); $container->setParameter('core.root_path', $phpbb_root_path); + $container->setParameter('core.adm_relative_path', 'adm/'); $container->setParameter('core.php_ext', $php_ext); $container->setParameter('core.table_prefix', ''); diff --git a/tests/functions_user/group_user_attributes_test.php b/tests/functions_user/group_user_attributes_test.php index f13156c2cc..4336fd894e 100644 --- a/tests/functions_user/group_user_attributes_test.php +++ b/tests/functions_user/group_user_attributes_test.php @@ -125,7 +125,7 @@ class phpbb_functions_user_group_user_attributes_test extends phpbb_database_tes */ public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected) { - global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container; + global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container, $phpbb_log, $phpbb_root_path, $phpEx; $user->ip = ''; $cache = new phpbb_mock_cache; @@ -141,6 +141,7 @@ class phpbb_functions_user_group_user_attributes_test extends phpbb_database_tes ->method('get') ->with('cache.driver') ->will($this->returnValue($cache_driver)); + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row); From 447e845274daedd12bc40f813680fb5df64d114a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 23 Jan 2013 00:21:01 +0100 Subject: [PATCH 195/234] [ticket/10714] Remove fallback code from previous commits and move global PHPBB3-10714 --- phpBB/includes/functions.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 590fc15aa7..6f9d8ad8d6 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3512,16 +3512,9 @@ function parse_cfg_file($filename, $lines = false) */ function add_log() { - global $phpbb_log; + global $phpbb_log, $user; $args = func_get_args(); - $log = (isset($args[0])) ? $args[0] : false; - - if ($log === false) - { - return false; - } - $mode = array_shift($args); // This looks kind of dirty, but add_log has some additional data before the log_operation @@ -3539,11 +3532,10 @@ function add_log() $additional_data['reportee_id'] = array_shift($args); break; } + $log_operation = array_shift($args); $additional_data = array_merge($additional_data, $args); - global $user; - $user_id = (empty($user->data)) ? ANONYMOUS : $user->data['user_id']; $user_ip = (empty($user->ip)) ? '' : $user->ip; From 869de98f52e636fd5b9f2a9f5b75d665e7009463 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 24 Jan 2013 00:23:45 +0100 Subject: [PATCH 196/234] [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(-) 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); } From 9c3538eb0e29c491d2f8c15c44c772e29631f4e3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 25 Jan 2013 01:24:15 +0100 Subject: [PATCH 197/234] [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(-) 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'); From f322f4eac923a960e6b6ff44c27783000affb3ee Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 3 Feb 2013 23:02:35 +0100 Subject: [PATCH 198/234] [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(-) 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: [PATCH 199/234] [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(-) 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); } From 5a4da46f9bdadbd1744f78b39c68184b317df60b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 6 Feb 2013 23:47:14 +0100 Subject: [PATCH 200/234] [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(-) 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'); From f09e6865f70b7b3dfedd2d436396a555a29ebe10 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 13 Feb 2013 01:07:02 +0100 Subject: [PATCH 201/234] [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(-) 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', From 2302cd7a42004b288c5f6be6d0e4b63fe363a983 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 19 Feb 2013 12:24:21 +0100 Subject: [PATCH 202/234] [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 ++-- tests/avatar/driver/barfoo.php | 4 ++-- tests/avatar/driver/foobar.php | 4 ++-- 11 files changed, 24 insertions(+), 22 deletions(-) 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); diff --git a/tests/avatar/driver/barfoo.php b/tests/avatar/driver/barfoo.php index 936b6e0559..0b701a4d70 100644 --- a/tests/avatar/driver/barfoo.php +++ b/tests/avatar/driver/barfoo.php @@ -7,12 +7,12 @@ class phpbb_avatar_driver_barfoo extends phpbb_avatar_driver return array(); } - public function prepare_form($request, $template, $row, &$error) + public function prepare_form($request, $template, $user, $row, &$error) { return false; } - public function process_form($request, $template, $row, &$error) + public function process_form($request, $template, $user, $row, &$error) { return false; } diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php index a68d0aa6c6..995f35818b 100644 --- a/tests/avatar/driver/foobar.php +++ b/tests/avatar/driver/foobar.php @@ -7,12 +7,12 @@ class phpbb_avatar_driver_foobar extends phpbb_avatar_driver return array(); } - public function prepare_form($request, $template, $row, &$error) + public function prepare_form($request, $template, $user, $row, &$error) { return false; } - public function process_form($request, $template, $row, &$error) + public function process_form($request, $template, $user, $row, &$error) { return false; } From a9e0aea4b1587ac5ff6c94d2dc7e4d05c304423d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 19 Feb 2013 12:30:14 +0100 Subject: [PATCH 203/234] [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(-) 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), )); From 3cc4746ad3220910b6cbb17772ba594ae26e7c32 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 19 Feb 2013 12:45:08 +0100 Subject: [PATCH 204/234] [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(-) 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', From c1b4cdb1883bb6771a303624ece131eb5c7f071d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 15:57:21 +0100 Subject: [PATCH 205/234] [ticket/10714] Update add_log docs block with @param and @deprecated PHPBB3-10714 --- phpBB/includes/functions.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 6f9d8ad8d6..d9116084fd 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3508,7 +3508,18 @@ function parse_cfg_file($filename, $lines = false) } /** -* Add log event +* Add log entry +* +* @param string $mode The mode defines which log_type is used and from which log the entry is retrieved +* @param int $forum_id Mode 'mod' ONLY: forum id of the related item, NOT INCLUDED otherwise +* @param int $topic_id Mode 'mod' ONLY: topic id of the related item, NOT INCLUDED otherwise +* @param int $reportee_id Mode 'user' ONLY: user id of the reportee, NOT INCLUDED otherwise +* @param string $log_operation Name of the operation +* @param array $additional_data More arguments can be added, depending on the log_type +* +* @return int|bool Returns the log_id, if the entry was added to the database, false otherwise. +* +* @deprecated Use $phpbb_log->add() instead */ function add_log() { From 12cc64e715cd87af0195e0abc0974eaab459107d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 19:01:35 +0100 Subject: [PATCH 206/234] [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(-) 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); From 9ea48dbd45aaa7d239998910feddcc827aaaafe9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:24:11 +0100 Subject: [PATCH 207/234] [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(-) 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} From 19c3917de985d04f994bc22bcec1e814aa2e207c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 1 Mar 2013 12:46:55 +0100 Subject: [PATCH 221/234] [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(-) 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)) { From 46c4ff46e00e4f050a5c987027a4b05e72456162 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 3 Mar 2013 20:30:17 +0100 Subject: [PATCH 222/234] [ticket/10714] Logs are disabled for this page call only PHPBB3-10714 --- phpBB/includes/log/interface.php | 9 +++++++-- phpBB/includes/log/log.php | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/log/interface.php b/phpBB/includes/log/interface.php index 24bf412ce0..3b459c9bdf 100644 --- a/phpBB/includes/log/interface.php +++ b/phpBB/includes/log/interface.php @@ -33,8 +33,11 @@ interface phpbb_log_interface public function is_enabled($type = ''); /** - * This function allows disabling the log system. When add_log is called - * and the type is disabled, the log will not be added to the database. + * Disable log + * + * This function allows disabling the log system or parts of it, for this + * page call. When add_log is called and the type is disabled, + * the log will not be added to the database. * * @param mixed $type The log type we want to disable. Empty to * disable all logs. Can also be an array of types. @@ -44,6 +47,8 @@ interface phpbb_log_interface public function disable($type = ''); /** + * Enable log + * * This function allows re-enabling the log system. * * @param mixed $type The log type we want to enable. Empty to diff --git a/phpBB/includes/log/log.php b/phpBB/includes/log/log.php index 8da8b63391..7a26858348 100644 --- a/phpBB/includes/log/log.php +++ b/phpBB/includes/log/log.php @@ -177,8 +177,11 @@ class phpbb_log implements phpbb_log_interface } /** - * This function allows disabling the log system. When add_log is called - * and the type is disabled, the log will not be added to the database. + * Disable log + * + * This function allows disabling the log system or parts of it, for this + * page call. When add_log is called and the type is disabled, + * the log will not be added to the database. * * {@inheritDoc} */ @@ -202,6 +205,8 @@ class phpbb_log implements phpbb_log_interface } /** + * Enable log + * * This function allows re-enabling the log system. * * {@inheritDoc} From e0328814f30d51bfac45e9c66d17b29478addd79 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 3 Mar 2013 20:30:54 +0100 Subject: [PATCH 223/234] [ticket/10714] Use $phpbb_adm_relative_path instead of hardcoded adm/ PHPBB3-10714 --- phpBB/includes/functions_container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index 36c5ad507e..106b7d75cc 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -57,7 +57,7 @@ function phpbb_create_install_container($phpbb_root_path, $php_ext) $container = phpbb_create_container(array($core), $phpbb_root_path, $php_ext); $container->setParameter('core.root_path', $phpbb_root_path); - $container->setParameter('core.adm_relative_path', 'adm/'); + $container->setParameter('core.adm_relative_path', $phpbb_adm_relative_path); $container->setParameter('core.php_ext', $php_ext); $container->setParameter('core.table_prefix', ''); From e1bb76eb096673af9e106f4cbd6e328c2b4bfdb6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 4 Mar 2013 00:25:38 +0100 Subject: [PATCH 224/234] [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(-) 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')), ), From c7ca4e445c7dc6c775e27597cd7b0968fa5fd904 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 4 Mar 2013 01:04:36 +0100 Subject: [PATCH 225/234] [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 --- .../db/migration/data/310/avatars.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 phpBB/includes/db/migration/data/310/avatars.php 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)), + ); + } +} From e4f782819968ec44f1dd207dc9de7ec703826d29 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 19:54:22 -0600 Subject: [PATCH 226/234] [ticket/11386] Send list of migrations instead of using load_migrations Remove dependency of extension manager for migrator. Keeping load_migrations function for others to use if they desire but requiring the finder be sent to it in order to use it. PHPBB3-11386 --- phpBB/config/migrator.yml | 2 - phpBB/config/services.yml | 3 +- phpBB/includes/db/migrator.php | 188 ++++++++---------- phpBB/includes/extension/manager.php | 32 +-- phpBB/install/database_update.php | 8 +- phpBB/install/install_install.php | 13 +- tests/dbal/migrator_test.php | 20 +- tests/extension/manager_test.php | 23 +-- tests/extension/metadata_manager_test.php | 11 + .../phpbb_functional_test_case.php | 21 +- 10 files changed, 160 insertions(+), 161 deletions(-) diff --git a/phpBB/config/migrator.yml b/phpBB/config/migrator.yml index 42445ef9bf..999a2d41a3 100644 --- a/phpBB/config/migrator.yml +++ b/phpBB/config/migrator.yml @@ -10,8 +10,6 @@ services: - %core.php_ext% - %core.table_prefix% - @migrator.tool_collection - calls: - - [set_extension_manager, [@ext.manager]] migrator.tool_collection: class: phpbb_di_service_collection diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 250e4a782b..3e4ae8d129 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -116,12 +116,11 @@ services: - @service_container - @dbal.conn - @config + - @migrator - %tables.ext% - %core.root_path% - .%core.php_ext% - @cache.driver - calls: - - [set_migrator, [@migrator]] ext.finder: class: phpbb_extension_finder diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index de9c06948c..b925ca5297 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -29,10 +29,7 @@ class phpbb_db_migrator protected $db; /** @var phpbb_db_tools */ - protected $db_tools; - - /** @var phpbb_extension_manager */ - protected $extension_manager; + protected $db_tools /** @var string */ protected $table_prefix; @@ -93,16 +90,6 @@ class phpbb_db_migrator $this->load_migration_state(); } - /** - * Set Extension Manager (required) - * - * Not in constructor to prevent circular reference error - */ - public function set_extension_manager(phpbb_extension_manager $extension_manager) - { - $this->extension_manager = $extension_manager; - } - /** * Loads all migrations and their application state from the database. * @@ -145,98 +132,6 @@ class phpbb_db_migrator $this->migrations = $class_names; } - /** - * This function adds all migrations in a specified directory to the migrations table - * - * THIS SHOULD NOT GENERALLY BE USED! THIS IS FOR THE PHPBB INSTALLER. - * THIS WILL THROW ERRORS IF MIGRATIONS ALREADY EXIST IN THE TABLE, DO NOT CALL MORE THAN ONCE! - * - * @param string $path Path to migration data files - * @param bool $recursive Set to true to also load data files from subdirectories - * @return null - */ - public function populate_migrations_from_directory($path, $recursive = true) - { - $existing_migrations = $this->migrations; - - $this->migrations = array(); - $this->load_migrations($path, true, $recursive); - - foreach ($this->migrations as $name) - { - if ($this->migration_state($name) === false) - { - $state = array( - 'migration_depends_on' => $name::depends_on(), - 'migration_schema_done' => true, - 'migration_data_done' => true, - 'migration_data_state' => '', - 'migration_start_time' => time(), - 'migration_end_time' => time(), - ); - $this->insert_migration($name, $state); - } - } - - $this->migrations = $existing_migrations; - } - - /** - * Load migration data files from a directory - * - * Migration data files loaded with this function MUST contain - * ONLY ONE class in them (or an exception will be thrown). - * - * @param string $path Path to migration data files - * @param bool $check_fulfillable If TRUE (default), we will check - * if all of the migrations are fulfillable after loading them. - * If FALSE, we will not check. You SHOULD check at least once - * to prevent errors (if including multiple directories, check - * with the last call to prevent throwing errors unnecessarily). - * @return array Array of migration names - */ - public function load_migrations($path, $check_fulfillable = true) - { - if (!is_dir($path)) - { - throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); - } - - $migrations = array(); - - $finder = $this->extension_manager->get_finder(); - $files = $finder - ->extension_directory("/") - ->find_from_paths(array('/' => $path)); - foreach ($files as $file) - { - $migrations[$file['path'] . $file['filename']] = ''; - } - $migrations = $finder->get_classes_from_files($migrations); - - foreach ($migrations as $migration) - { - if (!in_array($migration, $this->migrations)) - { - $this->migrations[] = $migration; - } - } - - if ($check_fulfillable) - { - foreach ($this->migrations as $name) - { - $unfulfillable = $this->unfulfillable($name); - if ($unfulfillable !== false) - { - throw new phpbb_db_migration_exception('MIGRATION_NOT_FULFILLABLE', $name, $unfulfillable); - } - } - } - - return $this->migrations; - } - /** * Runs a single update step from the next migration to be applied. * @@ -754,4 +649,85 @@ class phpbb_db_migrator { return new $name($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); } + + /** + * This function adds all migrations sent to it to the migrations table + * + * THIS SHOULD NOT GENERALLY BE USED! THIS IS FOR THE PHPBB INSTALLER. + * THIS WILL THROW ERRORS IF MIGRATIONS ALREADY EXIST IN THE TABLE, DO NOT CALL MORE THAN ONCE! + * + * @param array $migrations Array of migrations (names) to add to the migrations table + * @return null + */ + public function populate_migrations($migrations) + { + foreach ($migrations as $name) + { + if ($this->migration_state($name) === false) + { + $state = array( + 'migration_depends_on' => $name::depends_on(), + 'migration_schema_done' => true, + 'migration_data_done' => true, + 'migration_data_state' => '', + 'migration_start_time' => time(), + 'migration_end_time' => time(), + ); + $this->insert_migration($name, $state); + } + } + } + + /** + * Load migration data files from a directory + * + * @param phpbb_extension_finder $finder + * @param string $path Path to migration data files + * @param bool $check_fulfillable If TRUE (default), we will check + * if all of the migrations are fulfillable after loading them. + * If FALSE, we will not check. You SHOULD check at least once + * to prevent errors (if including multiple directories, check + * with the last call to prevent throwing errors unnecessarily). + * @return array Array of migration names + */ + public function load_migrations(phpbb_extension_finder $finder, $path, $check_fulfillable = true) + { + if (!is_dir($path)) + { + throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); + } + + $migrations = array(); + + $files = $finder + ->extension_directory("/") + ->find_from_paths(array('/' => $path)); + foreach ($files as $file) + { + $migrations[$file['path'] . $file['filename']] = ''; + } + $migrations = $finder->get_classes_from_files($migrations); + + foreach ($migrations as $migration) + { + if (!in_array($migration, $this->migrations)) + { + $this->migrations[] = $migration; + } + } + + if ($check_fulfillable) + { + foreach ($this->migrations as $name) + { + $unfulfillable = $this->unfulfillable($name); + if ($unfulfillable !== false) + { + throw new phpbb_db_migration_exception('MIGRATION_NOT_FULFILLABLE', $name, $unfulfillable); + } + } + } + + return $this->migrations; + } } diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 0d760681b9..44a30c6280 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -43,18 +43,20 @@ class phpbb_extension_manager * @param ContainerInterface $container A container * @param phpbb_db_driver $db A database connection * @param phpbb_config $config phpbb_config + * @param phpbb_db_migrator $migrator * @param string $extension_table The name of the table holding extensions * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, phpbb_db_migrator $migrator, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { $this->container = $container; $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->config = $config; + $this->migrator = $migrator; $this->cache = $cache; $this->php_ext = $php_ext; $this->extension_table = $extension_table; @@ -68,14 +70,6 @@ class phpbb_extension_manager } } - /** - * Set migrator (get around circular reference) - */ - public function set_migrator(phpbb_db_migrator $migrator) - { - $this->migrator = $migrator; - } - /** * Loads all extension information from the database * @@ -528,13 +522,27 @@ class phpbb_extension_manager */ protected function handle_migrations($extension_name, $mode) { - $migrations_path = $this->phpbb_root_path . $this->get_extension_path($extension_name) . 'migrations/'; - if (!file_exists($migrations_path) || !is_dir($migrations_path)) + $extensions = array( + $extension_name => $this->phpbb_root_path . $this->get_extension_path($extension_name), + ); + + $finder = $this->get_finder(); + $migrations = array(); + $file_list = $finder + ->extension_directory('/migrations') + ->find_from_paths($extensions); + + if (empty($file_list)) { return true; } - $migrations = $this->migrator->load_migrations($migrations_path); + foreach ($file_list as $file) + { + $migrations[$file['named_path']] = $file['ext_name']; + } + $migrations = $finder->get_classes_from_files($migrations); + $this->migrator->set_migrations($migrations); // What is a safe limit of execution time? Half the max execution time should be safe. $safe_time_limit = (ini_get('max_execution_time') / 2); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 4938ef0f87..b84f00659c 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -210,7 +210,13 @@ if (!$db_tools->sql_table_exists($table_prefix . 'migrations')) } $migrator = $phpbb_container->get('migrator'); -$migrator->load_migrations($phpbb_root_path . 'includes/db/migration/data/'); +$extension_manager = $phpbb_container->get('ext.manager'); +$finder = $extension_manager->get_finder(); + +$migrations = $finder + ->core_path('includes/db/migration/data/') + ->get_classes(); +$migrator->set_migrations($migrations); // What is a safe limit of execution time? Half the max execution time should be safe. $safe_time_limit = (ini_get('max_execution_time') / 2); diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index f0280acc40..4cc154509c 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -114,7 +114,7 @@ class install_install extends module $this->add_bots($mode, $sub); $this->email_admin($mode, $sub); $this->disable_avatars_if_unwritable(); - $this->populate_migrations($phpbb_container->get('migrator'), $phpbb_root_path); + $this->populate_migrations($phpbb_container->get('ext.manager'), $phpbb_container->get('migrator')); // Remove the lock file @unlink($phpbb_root_path . 'cache/install_lock'); @@ -1888,12 +1888,17 @@ class install_install extends module * "installs" means it adds all migrations to the migrations table, but does not * perform any of the actions in the migrations. * + * @param phpbb_extension_manager $extension_manager * @param phpbb_db_migrator $migrator - * @param string $phpbb_root_path */ - function populate_migrations($migrator, $phpbb_root_path) + function populate_migrations($extension_manager, $migrator) { - $migrator->populate_migrations_from_directory($phpbb_root_path . 'includes/db/migration/data/'); + $finder = $extension_manager->get_finder(); + + $migrations = $finder + ->core_path('includes/db/migration/data/') + ->get_classes(); + $migrator->populate_migrations($migrations); } /** diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index b447a81cda..89669b85ec 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -45,15 +45,6 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case new phpbb_db_migration_tool_config($this->config), ); - $this->extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), - $this->db, - $this->config, - 'phpbb_ext', - dirname(__FILE__) . '/../../phpBB/', - '.php', - null - ); $this->migrator = new phpbb_db_migrator( $this->config, $this->db, @@ -64,7 +55,16 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case 'phpbb_', $tools ); - $this->migrator->set_extension_manager($this->extension_manager); + $this->extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $this->db, + $this->config, + $this->migrator, + 'phpbb_ext', + dirname(__FILE__) . '/../../phpBB/', + '.php', + null + ); } public function test_update() diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 3b81afc456..1f311116f4 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -97,15 +97,6 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $php_ext = 'php'; $table_prefix = 'phpbb_'; - $manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), - $db, - $config, - 'phpbb_ext', - dirname(__FILE__) . '/', - '.' . $php_ext, - ($with_cache) ? new phpbb_mock_cache() : null - ); $migrator = new phpbb_db_migrator( $config, $db, @@ -116,9 +107,15 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $table_prefix, array() ); - $manager->set_migrator($migrator); - $migrator->set_extension_manager($manager); - - return $manager; + return new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $db, + $config, + $migrator, + 'phpbb_ext', + dirname(__FILE__) . '/', + '.' . $php_ext, + ($with_cache) ? new phpbb_mock_cache() : null + ); } } diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 7fb19b67e3..081a32e277 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -49,10 +49,21 @@ class metadata_manager_test extends phpbb_database_test_case new phpbb_template_context() ); + $this->migrator = new phpbb_db_migrator( + $this->config, + $this->db, + $this->db_tools, + 'phpbb_migrations', + $this->phpbb_root_path, + 'php', + $this->table_prefix, + array() + ); $this->extension_manager = new phpbb_extension_manager( new phpbb_mock_container_builder(), $this->db, $this->config, + $this->migrator, 'phpbb_ext', $this->phpbb_root_path, $this->phpEx, diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 3b9629b9f8..887dfea3b5 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -138,15 +138,6 @@ class phpbb_functional_test_case extends phpbb_test_case $db = $this->get_db(); $db_tools = new phpbb_db_tools($db); - $extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), - $db, - $config, - self::$config['table_prefix'] . 'ext', - dirname(__FILE__) . '/', - '.' . $php_ext, - $this->get_cache_driver() - ); $migrator = new phpbb_db_migrator( $config, $db, @@ -157,8 +148,16 @@ class phpbb_functional_test_case extends phpbb_test_case self::$config['table_prefix'], array() ); - $extension_manager->set_migrator($migrator); - $migrator->set_extension_manager($extension_manager); + $extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $db, + $config, + $migrator, + self::$config['table_prefix'] . 'ext', + dirname(__FILE__) . '/', + '.' . $php_ext, + $this->get_cache_driver() + ); return $extension_manager; } From 6cad032fbb2ceba892c861f8a2abab82574b12ae Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 20:18:05 -0600 Subject: [PATCH 227/234] [ticket/11393] Give more information on database updater PHPBB3-11393 --- phpBB/includes/db/migrator.php | 9 ++++++++- phpBB/install/database_update.php | 23 ++++++++++++++++++++++- phpBB/language/en/migrator.php | 3 +++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index de9c06948c..81beb14b76 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -63,7 +63,9 @@ class phpbb_db_migrator protected $migrations = array(); /** - * 'name' and 'class' of the last migration run + * 'name,' 'class,' and 'state' of the last migration run + * + * 'effectively_installed' set and set to true if the migration was effectively_installed * * @var array */ @@ -304,6 +306,7 @@ class phpbb_db_migrator $this->last_run_migration = array( 'name' => $name, 'class' => $migration, + 'state' => $state, ); if (!isset($this->migration_state[$name])) @@ -318,6 +321,8 @@ class phpbb_db_migrator 'migration_start_time' => 0, 'migration_end_time' => 0, ); + + $this->last_run_migration['effectively_installed'] = true; } else { @@ -662,6 +667,8 @@ class phpbb_db_migrator } $this->migration_state[$name] = $state; + + $this->last_run_migration['state'] = $state; } /** diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 4938ef0f87..6c8a95a413 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -228,7 +228,28 @@ while (!$migrator->finished()) phpbb_end_update($cache); } - echo $migrator->last_run_migration['name'] . '
'; + $state = array_merge(array( + 'migration_schema_done' => false, + 'migration_data_done' => false, + ), + $migrator->last_run_migration['state'] + ); + + if (isset($migrator->last_run_migration['effectively_installed']) && $migrator->last_run_migration['effectively_installed']) + { + echo $user->lang('MIGRATION_EFFECTIVELY_INSTALLED', $migrator->last_run_migration['name']) . '
'; + } + else + { + if ($state['migration_data_done']) + { + echo $user->lang('MIGRATION_DATA_DONE', $migrator->last_run_migration['name']) . '
'; + } + else if ($state['migration_schema_done']) + { + echo $user->lang('MIGRATION_SCHEMA_DONE', $migrator->last_run_migration['name']) . '
'; + } + } // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if ((time() - $update_start_time) >= $safe_time_limit) diff --git a/phpBB/language/en/migrator.php b/phpBB/language/en/migrator.php index 84074c391c..a62da483cf 100644 --- a/phpBB/language/en/migrator.php +++ b/phpBB/language/en/migrator.php @@ -40,8 +40,11 @@ $lang = array_merge($lang, array( 'GROUP_NOT_EXIST' => 'The group "%s" unexpectedly does not exist.', + 'MIGRATION_DATA_DONE' => 'Installed Data: %s', + 'MIGRATION_EFFECTIVELY_INSTALLED' => 'Migration already effectively installed (skipped): %s', 'MIGRATION_EXCEPTION_ERROR' => 'Something went wrong during the request and an exception was thrown. The changes made before the error occurred were reversed to the best of our abilities, but you should check the board for errors.', 'MIGRATION_NOT_FULFILLABLE' => 'The migration "%1$s" is not fulfillable, missing migration "%2$s".', + 'MIGRATION_SCHEMA_DONE' => 'Installed Schema: %s', 'MODULE_ALREADY_EXIST' => 'The module "%s" unexpectedly already exists.', 'MODULE_ERROR' => 'An error occured while creating a module: %s', From 9dfc5fbf9a8b866bea38efa5217417e6ef341bf1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 20:47:14 -0600 Subject: [PATCH 228/234] [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(-) 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 From ae15fabb323c8f76ad2c8c994c2d205aabeafcbe Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 20:59:21 -0600 Subject: [PATCH 229/234] [ticket/11396] Rename insert_migration to set_migration_state PHPBB3-11396 --- phpBB/includes/db/migrator.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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']); From 2e2ddd7e85034f747d5dd312803aadfc47ac80e2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 4 Mar 2013 10:30:49 +0100 Subject: [PATCH 230/234] [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 --- .../db/migration/data/310/avatars.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) 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); + } } From 7423d48757bec0a81c8d439e911ed32d5af3a775 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Mar 2013 11:25:27 +0100 Subject: [PATCH 231/234] [ticket/10714] Get log from container in install, update and download/file PHPBB3-10714 --- phpBB/download/file.php | 1 + phpBB/install/database_update.php | 1 + phpBB/install/install_install.php | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 4a392b002d..855813d0d2 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -67,6 +67,7 @@ if (isset($_GET['avatar'])) $phpbb_dispatcher = $phpbb_container->get('dispatcher'); $request = $phpbb_container->get('request'); $db = $phpbb_container->get('dbal.conn'); + $phpbb_log = $phpbb_container->get('log'); // Connect to DB if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false)) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 4938ef0f87..23048df9fa 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -123,6 +123,7 @@ $request = $phpbb_container->get('request'); $user = $phpbb_container->get('user'); $auth = $phpbb_container->get('auth'); $db = $phpbb_container->get('dbal.conn'); +$phpbb_log = $phpbb_container->get('log'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index f0280acc40..d95a500929 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -53,7 +53,7 @@ class install_install extends module function main($mode, $sub) { global $lang, $template, $language, $phpbb_root_path, $phpEx; - global $phpbb_container, $cache; + global $phpbb_container, $cache, $phpbb_log; switch ($sub) { @@ -105,8 +105,9 @@ class install_install extends module // Create a normal container now $phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); - // Sets the global $cache variable + // Sets the global variables $cache = $phpbb_container->get('cache'); + $phpbb_log = $phpbb_container->get('log'); $this->build_search_index($mode, $sub); $this->add_modules($mode, $sub); From 071defded6f0e4d2a805b336f56f0a2524d5b1b6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 4 Mar 2013 09:55:23 -0600 Subject: [PATCH 232/234] [ticket/11386] Fix missing ; PHPBB3-11386 --- phpBB/includes/db/migrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index b925ca5297..9fe4f40df2 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -29,7 +29,7 @@ class phpbb_db_migrator protected $db; /** @var phpbb_db_tools */ - protected $db_tools + protected $db_tools; /** @var string */ protected $table_prefix; From 2aadc5a22c4ad58cab73bb8b56ca0109a95fab0f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 20:25:31 -0600 Subject: [PATCH 233/234] [ticket/11394] Relax Migration Tools Do not throw as many exceptions in the migration tools (when something unexpected occurs but can be safely ignored). PHPBB3-11394 --- phpBB/includes/db/migration/tool/config.php | 4 ++-- phpBB/includes/db/migration/tool/module.php | 6 +++--- phpBB/includes/db/migration/tool/permission.php | 6 +++--- phpBB/language/en/migrator.php | 4 ---- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php index 458a25fb66..0b626bf455 100644 --- a/phpBB/includes/db/migration/tool/config.php +++ b/phpBB/includes/db/migration/tool/config.php @@ -49,7 +49,7 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac { if (isset($this->config[$config_name])) { - throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXIST', $config_name); + return; } $this->config->set($config_name, $config_value, !$is_dynamic); @@ -105,7 +105,7 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac { if (!isset($this->config[$config_name])) { - throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + return; } $this->config->delete($config_name); diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index ad94c5aadb..ec683d36af 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -236,7 +236,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if ($this->exists($class, $parent, $data['module_langname'])) { - throw new phpbb_db_migration_exception('MODULE_ALREADY_EXIST', $data['module_langname']); + return; } if (!class_exists('acp_modules')) @@ -369,7 +369,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac { if (!$this->exists($class, $parent, $module)) { - throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', ((isset($this->user->lang[$module])) ? $this->user->lang[$module] : $module)); + return; } $parent_sql = ''; @@ -442,7 +442,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $result = $acp_modules->delete_module($module_id); if (!empty($result)) { - throw new phpbb_db_migration_exception('MODULE_NOT_REMOVABLE', $module_id, $result); + return; } } diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index 4231fbe1dd..3b196fdbc2 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -107,7 +107,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte { if ($this->exists($auth_option, $global)) { - throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXIST', $auth_option); + return; } // We've added permissions, so set to true to notify the user. @@ -190,7 +190,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte { if (!$this->exists($auth_option, $global)) { - throw new phpbb_db_migration_exception('PERMISSION_NOT_EXIST', $auth_option); + return; } if ($global) @@ -315,7 +315,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte if (!$role_id) { - throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $role_name); + return; } $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' diff --git a/phpBB/language/en/migrator.php b/phpBB/language/en/migrator.php index 84074c391c..59e6f06884 100644 --- a/phpBB/language/en/migrator.php +++ b/phpBB/language/en/migrator.php @@ -35,7 +35,6 @@ if (empty($lang) || !is_array($lang)) // in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine $lang = array_merge($lang, array( - 'CONFIG_ALREADY_EXIST' => 'The config setting "%s" unexpectedly already exists.', 'CONFIG_NOT_EXIST' => 'The config setting "%s" unexpectedly does not exist.', 'GROUP_NOT_EXIST' => 'The group "%s" unexpectedly does not exist.', @@ -43,13 +42,10 @@ $lang = array_merge($lang, array( 'MIGRATION_EXCEPTION_ERROR' => 'Something went wrong during the request and an exception was thrown. The changes made before the error occurred were reversed to the best of our abilities, but you should check the board for errors.', 'MIGRATION_NOT_FULFILLABLE' => 'The migration "%1$s" is not fulfillable, missing migration "%2$s".', - 'MODULE_ALREADY_EXIST' => 'The module "%s" unexpectedly already exists.', 'MODULE_ERROR' => 'An error occured while creating a module: %s', 'MODULE_INFO_FILE_NOT_EXIST' => 'A required module info file is missing: %2$s', 'MODULE_NOT_EXIST' => 'A required module does not exist: %s', - 'MODULE_NOT_REMOVABLE' => 'Module %1$s was unable to be removed: %2$s', - 'PERMISSION_ALREADY_EXIST' => 'The permission setting "%s" unexpectedly already exists.', 'PERMISSION_NOT_EXIST' => 'The permission setting "%s" unexpectedly does not exist.', 'ROLE_NOT_EXIST' => 'The permission role "%s" unexpectedly does not exist.', From e7d9cfa009ba8e22b0e75f1401ea2caa70c89c5b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 5 Mar 2013 01:06:22 +0100 Subject: [PATCH 234/234] [ticket/11398] Correctly call permission_set method in permission tool The permission_set method calls itself inside the permission tool. Probably due to an oversight, it is called as $this->set(), which causes a fatal error. This patch will get rid of this issue. PHPBB3-11398 --- phpBB/includes/db/migration/tool/permission.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index 3b196fdbc2..2f09c0ac72 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -422,7 +422,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->db->sql_query($sql); $role_name = $this->db->sql_fetchfield('role_name'); - return $this->set($role_name, $auth_option, 'role', $has_permission); + return $this->permission_set($role_name, $auth_option, 'role', $has_permission); } $sql = 'SELECT auth_option_id, auth_setting
{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.', From b0dc5925b91cb0447046e8a7f089c6675e4be95c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:29:04 +0100 Subject: [PATCH 208/234] [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(-) 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; From 1d7b082a6fa05d5760ef15ef8bf78cd3a1d204cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:58:12 +0100 Subject: [PATCH 209/234] [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 +- tests/groupposition/legend_test.php | 201 ++++++---- tests/groupposition/teampage_test.php | 408 ++++++++++++--------- 5 files changed, 413 insertions(+), 253 deletions(-) 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; } /** diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php index cb9b514ff8..30d2828e17 100644 --- a/tests/groupposition/legend_test.php +++ b/tests/groupposition/legend_test.php @@ -151,28 +151,40 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function move_up_data() { return array( - array(1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(2, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(3, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 2), - array('group_id' => 3, 'group_legend' => 1), - )), + array( + 1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 3, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), ); } /** * @dataProvider move_up_data */ - public function test_move_up($group_id, $expected) + public function test_move_up($group_id, $excepted_moved, $expected) { global $cache; @@ -182,7 +194,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_legend($db, $user); - $test_class->move_up($group_id); + $this->assertEquals($excepted_moved, $test_class->move_up($group_id)); $result = $db->sql_query('SELECT group_id, group_legend FROM ' . GROUPS_TABLE . ' @@ -194,28 +206,40 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function move_down_data() { return array( - array(1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(2, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 2), - array('group_id' => 3, 'group_legend' => 1), - )), - array(3, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), + array( + 1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), ); } /** * @dataProvider move_down_data */ - public function test_move_down($group_id, $expected) + public function test_move_down($group_id, $excepted_moved, $expected) { global $cache; @@ -225,7 +249,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_legend($db, $user); - $test_class->move_down($group_id); + $this->assertEquals($excepted_moved, $test_class->move_down($group_id)); $result = $db->sql_query('SELECT group_id, group_legend FROM ' . GROUPS_TABLE . ' @@ -237,48 +261,83 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function move_data() { return array( - array(1, 1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(1, -1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(3, 3, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 2), - array('group_id' => 3, 'group_legend' => 1), - )), - array(2, 0, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(2, -1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 2), - array('group_id' => 3, 'group_legend' => 1), - )), - array(2, -3, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 2), - array('group_id' => 3, 'group_legend' => 1), - )), - array(3, -1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), + array( + 1, + 1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 1, + -1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 3, + 3, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 2, + 0, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + -1, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 2, + -3, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + -1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), ); } /** * @dataProvider move_data */ - public function test_move($group_id, $increment, $expected) + public function test_move($group_id, $increment, $excepted_moved, $expected) { global $cache; @@ -288,7 +347,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_legend($db, $user); - $test_class->move($group_id, $increment); + $this->assertEquals($excepted_moved, $test_class->move($group_id, $increment)); $result = $db->sql_query('SELECT group_id, group_legend FROM ' . GROUPS_TABLE . ' diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index c3cfcb7bc3..8078372083 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -265,93 +265,133 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function move_data() { return array( - array(1, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(5, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(6, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - )), - array(1, -1, array( - array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(5, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(6, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), + array( + 1, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), + array( + 1, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + -1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + -1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), ); } /** * @dataProvider move_data */ - public function test_move($group_id, $move_delta, $expected) + public function test_move($group_id, $move_delta, $excepted_moved, $expected) { global $cache; @@ -361,7 +401,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->move($group_id, $move_delta); + $this->assertEquals($excepted_moved, $test_class->move($group_id, $move_delta)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' @@ -373,93 +413,133 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function move_teampage_data() { return array( - array(1, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, 1, array( - array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(5, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(6, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(1, -1, array( - array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(5, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - )), - array(6, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), + array( + 1, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 1, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), + array( + 6, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), ); } /** * @dataProvider move_teampage_data */ - public function test_move_teampage($teampage_id, $move_delta, $expected) + public function test_move_teampage($teampage_id, $move_delta, $excepted_moved, $expected) { global $cache; @@ -469,7 +549,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->move_teampage($teampage_id, $move_delta); + $this->assertEquals($excepted_moved, $test_class->move_teampage($teampage_id, $move_delta)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' From 41eea66da975a3b4140d8f4dc3f6931ea84916db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 21:24:52 +0100 Subject: [PATCH 210/234] [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 +- tests/groupposition/legend_test.php | 126 +++++++---- tests/groupposition/teampage_test.php | 252 ++++++++++++--------- 5 files changed, 257 insertions(+), 155 deletions(-) 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; } /** diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php index 30d2828e17..229654a6b8 100644 --- a/tests/groupposition/legend_test.php +++ b/tests/groupposition/legend_test.php @@ -55,23 +55,31 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function add_group_data() { return array( - array(1, array( - array('group_id' => 1, 'group_legend' => 3), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(2, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), + array( + 1, + true, + array( + array('group_id' => 1, 'group_legend' => 3), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), ); } /** * @dataProvider add_group_data */ - public function test_add_group($group_id, $expected) + public function test_add_group($group_id, $expected_added, $expected) { global $cache; @@ -81,7 +89,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_legend($db, $user); - $test_class->add_group($group_id); + $this->assertEquals($expected_added, $test_class->add_group($group_id)); $result = $db->sql_query('SELECT group_id, group_legend FROM ' . GROUPS_TABLE . ' @@ -93,43 +101,73 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function delete_group_data() { return array( - array(1, false, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' =>2), - )), - array(2, false, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_legend' => 1), - )), - array(3, false, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 0), - )), - array(1, true, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(2, true, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 1), - )), - array(3, true, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), + array( + 1, + false, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + false, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + false, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 0), + ), + ), + array( + 1, + true, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + true, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + true, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), ); } /** * @dataProvider delete_group_data */ - public function test_delete_group($group_id, $skip_group, $expected) + public function test_delete_group($group_id, $skip_group, $expected_deleted, $expected) { global $cache; @@ -139,7 +177,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_legend($db, $user); - $test_class->delete_group($group_id, $skip_group); + $this->assertEquals($expected_deleted, $test_class->delete_group($group_id, $skip_group)); $result = $db->sql_query('SELECT group_id, group_legend FROM ' . GROUPS_TABLE . ' diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index 8078372083..7d00e2c5d3 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -57,55 +57,75 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function add_group_teampage_data() { return array( - array(1, 2, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(6, 2, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(7, 2, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 7, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 9, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(7, 0, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 9, 'group_id' => 7, 'teampage_parent' => 0, 'teampage_name' => ''), - )), + array( + 1, + 2, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + 2, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 7, + 2, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 7, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 7, + 0, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 7, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), ); } /** * @dataProvider add_group_teampage_data */ - public function test_add_group_teampage($group_id, $parent_id, $expected) + public function test_add_group_teampage($group_id, $parent_id, $expected_added, $expected) { global $cache; @@ -115,7 +135,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->add_group_teampage($group_id, $parent_id); + $this->assertEquals($expected_added, $test_class->add_group_teampage($group_id, $parent_id)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' @@ -127,24 +147,28 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function add_category_teampage_data() { return array( - array('new', array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 9, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'new'), - )), + array( + 'new', + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'new'), + ), + ), ); } /** * @dataProvider add_category_teampage_data */ - public function test_add_category_teampage($group_name, $expected) + public function test_add_category_teampage($group_name, $expected_added, $expected) { global $cache; @@ -154,7 +178,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->add_category_teampage($group_name); + $this->assertEquals($expected_added, $test_class->add_category_teampage($group_name)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' @@ -166,40 +190,52 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function delete_group_data() { return array( - array(1, array( - array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(6, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - )), + array( + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), ); } /** * @dataProvider delete_group_data */ - public function test_delete_group($group_id, $expected) + public function test_delete_group($group_id, $expected_deleted, $expected) { global $cache; @@ -209,7 +245,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->delete_group($group_id, false); + $this->assertEquals($expected_deleted, $test_class->delete_group($group_id, false)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' @@ -221,29 +257,37 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function delete_teampage_data() { return array( - array(1, array( - array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), + array( + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), ); } /** * @dataProvider delete_teampage_data */ - public function test_delete_teampage($teampage_id, $expected) + public function test_delete_teampage($teampage_id, $expected_deleted, $expected) { global $cache; @@ -253,7 +297,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->delete_teampage($teampage_id, false); + $this->assertEquals($expected_deleted, $test_class->delete_teampage($teampage_id, false)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' From e0df5934485df0eee22141d1c5ded3e432119b20 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 16:52:53 +0100 Subject: [PATCH 211/234] [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 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 * From 9e70f7a4e0e419984ad5dd0392857ecd810ad252 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 16:53:51 +0100 Subject: [PATCH 212/234] [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(-) 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) + try { - $teampage->add_group($group_id); - } - - if ($group_teampage) - { - 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 . " From 1261583afab236d6986827695dd6f80770fb1eb4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 17:01:45 +0100 Subject: [PATCH 213/234] [ticket/10411] Test for thrown exceptions when group does not exist PHPBB3-10411 --- tests/groupposition/legend_test.php | 12 +++++++++--- tests/groupposition/teampage_test.php | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php index 229654a6b8..16e33b390c 100644 --- a/tests/groupposition/legend_test.php +++ b/tests/groupposition/legend_test.php @@ -18,15 +18,16 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function get_group_value_data() { return array( - array(1, 0), - array(3, 2), + array(1, 0, ''), + array(3, 2, ''), + array(4, 0, 'phpbb_groupposition_exception'), ); } /** * @dataProvider get_group_value_data */ - public function test_get_group_value($group_id, $expected) + public function test_get_group_value($group_id, $expected, $throws_exception) { global $cache; @@ -35,6 +36,11 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); + if ($throws_exception) + { + $this->setExpectedException($throws_exception); + } + $test_class = new phpbb_groupposition_legend($db, $user); $this->assertEquals($expected, $test_class->get_group_value($group_id)); } diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index 7d00e2c5d3..b0ce6b29c3 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -20,15 +20,16 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function get_group_value_data() { return array( - array(2, 3), - array(6, 8), + array(2, 3, ''), + array(6, 8, ''), + array(10, 0, 'phpbb_groupposition_exception'), ); } /** * @dataProvider get_group_value_data */ - public function test_get_group_value($group_id, $expected) + public function test_get_group_value($group_id, $expected, $throws_exception) { global $cache; @@ -37,6 +38,11 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); + if ($throws_exception) + { + $this->setExpectedException($throws_exception); + } + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); $this->assertEquals($expected, $test_class->get_group_value($group_id)); } From ba97303a60342bdb54979223cc6d18e815a70d90 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 17:17:31 +0100 Subject: [PATCH 214/234] [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(-) 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} From d61eb95b4868377cfc2a7a98b03a7d908418b1af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 00:12:18 +0100 Subject: [PATCH 215/234] [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(-) 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); + AND group_name = 'ADMINISTRATORS'"; + _sql($sql, $errored, $error_ary); - $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)) - { - $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'])) From 3362baca51bd82e6cc0d15625863e46506bece72 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 19:27:30 +0100 Subject: [PATCH 216/234] [ticket/10411] Add migrations file for teampage table PHPBB3-10411 --- .../db/migration/data/310/teampage.php | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 phpBB/includes/db/migration/data/310/teampage.php 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); + } + + } +} From 8bf04563bcb53f3eff6b966095b14b8c277c1640 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 21:43:07 +0100 Subject: [PATCH 217/234] [ticket/10411] Add unit tests for move() with values >1 PHPBB3-10411 --- tests/groupposition/teampage_test.php | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index b0ce6b29c3..db26cd09d5 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -435,6 +435,21 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), ), ), + array( + 6, + 3, + true, + array( + array('teampage_position' => 1, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), ); } @@ -583,6 +598,21 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), ), ), + array( + 8, + 3, + true, + array( + array('teampage_position' => 1, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), ); } From 97a446f5b97005f71a7ec3e015aadecaf5bffa36 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 22:00:15 +0100 Subject: [PATCH 218/234] [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(-) 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); From 8a9e1ca3f176946bc7b8ddb9be30ca8607685b80 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 28 Feb 2013 22:56:01 +0100 Subject: [PATCH 219/234] [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 --- .../template/ucp_avatar_options_gravatar.html | 14 ++++++++++++++ .../template/ucp_avatar_options_remote.html | 14 ++++++++++++++ 2 files changed, 28 insertions(+) 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}
From b8b2ede35db3d562ca6ed3087ad99933e05c4b67 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 1 Mar 2013 12:45:49 +0100 Subject: [PATCH 220/234] [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(-) 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}