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

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

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

{ERROR}

-
-

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- - -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
+

{L_AVATAR_EXPLAIN}
+
{AVATAR}
+
+

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

{L_AVATAR_GALLERY}

+ +

{avatar_drivers.L_TITLE}

+

{avatar_drivers.L_EXPLAIN}

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

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

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

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

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
+

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
+
+
+

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
+

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

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

{L_LINK_REMOTE_AVATAR_EXPLAIN}
+
+
+
+

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

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

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- - -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
-
-
-

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

{ERROR}

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

{L_AVATAR_EXPLAIN}
+
{AVATAR}
+
+
+ +
+ {avatar_drivers.L_TITLE} +

{avatar_drivers.L_EXPLAIN}

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

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

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

{ERROR}


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

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

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

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

{L_AVATAR_EXPLAIN}
{AVATAR}
-
- +

{L_AVATAR_SELECT_NEW}

+
+
+
+
+
+
-

{avatar_drivers.L_TITLE}

+
+

{avatar_drivers.L_EXPLAIN}

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

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

{avatar_drivers.L_EXPLAIN}

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

{avatar_drivers.L_EXPLAIN}

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

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

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

{L_UPLOAD_AVATAR_URL_EXPLAIN}
-
-
- -
-

{L_LINK_REMOTE_AVATAR_EXPLAIN}
-
-
-
-

{L_LINK_REMOTE_SIZE_EXPLAIN}
-
{L_PIXEL} × {L_PIXEL}
-
- -
-
-
-
- - - - -
- {L_AVATAR_GALLERY} -
-
-
 
-
-
- - - - - - - - - - - - - -
{avatar_row.avatar_column.AVATAR_NAME}
-
-
- -
- -
- - +
+
+
+
+
+ +
+

{avatar_drivers.L_EXPLAIN}

+ {avatar_drivers.OUTPUT} +
+ +
+
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 9ad157f78a..16ae8670ce 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -54,7 +54,6 @@ class acp_groups // Clear some vars - $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false; $group_row = array(); // Grab basic data for group, if group_id is set and exists @@ -281,8 +280,24 @@ class acp_groups $error = array(); $user->add_lang('ucp'); - $avatar_select = basename(request_var('avatar_select', '')); - $category = basename(request_var('category', '')); + // Setup avatar data for later + $avatars_enabled = false; + $avatar_manager = null; + $avatar_drivers = null; + $avatar_data = null; + $avatar_error = array(); + + if ($config['allow_avatar']) + { + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + + $avatar_drivers = $avatar_manager->get_valid_drivers(); + sort($avatar_drivers); + + // This is normalised data, without the group_ prefix + $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver::FROM_GROUP); + } + // Did we submit? if ($update) @@ -300,12 +315,6 @@ class acp_groups $allow_desc_urls = request_var('desc_parse_urls', false); $allow_desc_smilies = request_var('desc_parse_smilies', false); - $data['uploadurl'] = request_var('uploadurl', ''); - $data['remotelink'] = request_var('remotelink', ''); - $data['width'] = request_var('width', ''); - $data['height'] = request_var('height', ''); - $delete = request_var('delete', ''); - $submit_ary = array( 'colour' => request_var('group_colour', ''), 'rank' => request_var('group_rank', 0), @@ -322,81 +331,38 @@ class acp_groups { $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0; } - - if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) - { - // Avatar stuff - $var_ary = array( - 'uploadurl' => array('string', true, 5, 255), - 'remotelink' => array('string', true, 5, 255), - 'width' => array('string', true, 1, 3), - 'height' => array('string', true, 1, 3), - ); - - if (!($error = validate_data($data, $var_ary))) + + if ($config['allow_avatar']) { + // Handle avatar + $driver = request_var('avatar_driver', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $data['user_id'] = "g$group_id"; + $avatar = $avatar_manager->get_driver($driver); + $result = $avatar->process_form($template, $avatar_data, $avatar_error); - if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) + if ($result && empty($avatar_error)) { - list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error); - } - else if ($data['remotelink']) - { - list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error); + // Success! Lets save the result + + /* + $result = array( + 'avatar' => ..., + 'avatar_width' => ..., + 'avatar_height' => ..., + ); + */ + + $submit_ary = array_merge($submit_ary, $result); + $submit_ary['avatar_type'] = $driver; } } - } - else if ($avatar_select && $config['allow_avatar_local']) - { - // check avatar gallery - if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) + else { - $submit_ary['avatar_type'] = AVATAR_GALLERY; - - list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select); - $submit_ary['avatar'] = $category . '/' . $avatar_select; - } - } - else if ($delete) - { - $submit_ary['avatar'] = ''; - $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0; - } - else if ($data['width'] && $data['height']) - { - // Only update the dimensions? - if ($config['avatar_max_width'] || $config['avatar_max_height']) - { - if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) - { - $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); - } - } - - if (!sizeof($error)) - { - if ($config['avatar_min_width'] || $config['avatar_min_height']) - { - if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) - { - $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); - } - } - } - - if (!sizeof($error)) - { - $submit_ary['avatar_width'] = $data['width']; - $submit_ary['avatar_height'] = $data['height']; - } - } - - if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete) - { - if (isset($group_row['group_avatar']) && $group_row['group_avatar']) - { - avatar_delete('group', $group_row, true); + // Removing the avatar + $submit_ary['avatar_type'] = ''; + $submit_ary['avatar'] = ''; + $submit_ary['avatar_width'] = 0; + $submit_ary['avatar_height'] = 0; } } @@ -423,7 +389,7 @@ class acp_groups 'rank' => 'int', 'colour' => 'string', 'avatar' => 'string', - 'avatar_type' => 'int', + 'avatar_type' => 'string', 'avatar_width' => 'int', 'avatar_height' => 'int', 'receive_pm' => 'int', @@ -553,13 +519,54 @@ class acp_groups $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : ''; $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : ''; - $avatar_img = (!empty($group_row['group_avatar'])) ? get_group_avatar($group_row) : ''; + // Load up stuff for avatars + if ($config['allow_avatar']) + { + $avatars_enabled = false; + $focused_driver = request_var('avatar_driver', $avatar_data['avatar_type']); + + foreach ($avatar_drivers as $driver) + { + if ($config["allow_avatar_$driver"]) + { + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => "acp_avatar_options_$driver.html", + )); - $display_gallery = (isset($_POST['display_gallery'])) ? true : false; + $avatar = $avatar_manager->get_driver($driver); - if ($config['allow_avatar_local'] && $display_gallery) + if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) + { + $driver_u = strtoupper($driver); + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_TITLE'), // @TODO add lang values + 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'), + + 'DRIVER' => $driver, + 'SELECTED' => ($driver == $focused_driver), + 'OUTPUT' => $template->assign_display('avatar'), + )); + } + } + } + } + + $avatar = get_group_avatar($group_row, 'GROUP_AVATAR', true); + + // Merge any avatars errors into the primary error array + // Drivers use lang constants, so we need to map to the actual strings + foreach ($avatar_error as $e) { - avatar_gallery($category, $avatar_select, 4); + if (is_array($e)) + { + $key = array_shift($e); + $error[] = vsprintf($user->lang($key), $e); + } + else + { + $error[] = $user->lang((string) $e); + } } $back_link = request_var('back_link', ''); @@ -580,12 +587,10 @@ class acp_groups 'S_ADD_GROUP' => ($action == 'add') ? true : false, 'S_GROUP_PERM' => ($action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) ? true : false, 'S_INCLUDE_SWATCH' => true, - 'S_CAN_UPLOAD' => $can_upload, 'S_ERROR' => (sizeof($error)) ? true : false, 'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL) ? true : false, - 'S_DISPLAY_GALLERY' => ($config['allow_avatar_local'] && !$display_gallery) ? true : false, - 'S_IN_GALLERY' => ($config['allow_avatar_local'] && $display_gallery) ? true : false, 'S_USER_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false, + 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', 'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name, @@ -606,8 +611,7 @@ class acp_groups 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)), - 'AVATAR' => $avatar_img, - 'AVATAR_IMAGE' => $avatar_img, + 'AVATAR' => (empty($avatar) ? '' : $avatar), 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '', diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 9b5c52e28e..ad8e7532c0 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1797,7 +1797,6 @@ class acp_users 'S_AVATAR' => true, 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', 'AVATAR' => (empty($avatar) ? '' : $avatar), - 'AV_SHOW_DELETE' => !empty($avatar), 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 85eda96018..f87854315d 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -67,6 +67,10 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver if (!empty($avatar_list[$category])) { + $template->assign_vars(array( + 'AV_LOCAL_SHOW' => true, + )); + $table_cols = isset($row['av_gallery_cols']) ? $row['av_gallery_cols'] : 4; $row_count = $col_count = $av_pos = 0; $av_count = sizeof($avatar_list[$category]); -- cgit v1.2.1 From 3963b39634225a68687cf1b817a47ae1eeb6ac79 Mon Sep 17 00:00:00 2001 From: Cullen Walsh Date: Mon, 4 Jul 2011 17:19:18 -0700 Subject: [feature/avatars] Making schema changes for db tables These schema changes make manual column chaning uncessesary. PHPBB3-10018 --- phpBB/install/database_update.php | 4 ++++ phpBB/install/schemas/firebird_schema.sql | 4 ++-- phpBB/install/schemas/mssql_schema.sql | 4 ++-- phpBB/install/schemas/mysql_40_schema.sql | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) (limited to 'phpBB') diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 843e8c2f23..ba6d5d34e2 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1092,6 +1092,10 @@ function database_update_info() 'change_columns' => array( GROUPS_TABLE => array( 'group_legend' => array('UINT', 0), + 'group_avatar_type' => array('VCHAR:32', 0), + ), + USERS_TABLE => array( + 'user_avatar_type' => array('VCHAR:32', 0), ), ), 'drop_columns' => array( diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index daeba45864..8b5bc90afa 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -445,7 +445,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL, group_display INTEGER DEFAULT 0 NOT NULL, group_avatar VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - group_avatar_type INTEGER DEFAULT 0 NOT NULL, + group_avatar_type VARCHAR(32) CHARACTER SET NONE DEFAULT '' NOT NULL, group_avatar_width INTEGER DEFAULT 0 NOT NULL, group_avatar_height INTEGER DEFAULT 0 NOT NULL, group_rank INTEGER DEFAULT 0 NOT NULL, @@ -1317,7 +1317,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INTEGER DEFAULT 1 NOT NULL, user_options INTEGER DEFAULT 230271 NOT NULL, user_avatar VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - user_avatar_type INTEGER DEFAULT 0 NOT NULL, + user_avatar_type VARCHAR(32) CHARACTER SET NONE DEFAULT '' NOT NULL, user_avatar_width INTEGER DEFAULT 0 NOT NULL, user_avatar_height INTEGER DEFAULT 0 NOT NULL, user_sig BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 736917fdcb..65ef420877 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -553,7 +553,7 @@ CREATE TABLE [phpbb_groups] ( [group_desc_uid] [varchar] (8) DEFAULT ('') NOT NULL , [group_display] [int] DEFAULT (0) NOT NULL , [group_avatar] [varchar] (255) DEFAULT ('') NOT NULL , - [group_avatar_type] [int] DEFAULT (0) NOT NULL , + [group_avatar_type] [varchar] (32) DEFAULT ('') NOT NULL , [group_avatar_width] [int] DEFAULT (0) NOT NULL , [group_avatar_height] [int] DEFAULT (0) NOT NULL , [group_rank] [int] DEFAULT (0) NOT NULL , @@ -1603,7 +1603,7 @@ CREATE TABLE [phpbb_users] ( [user_allow_massemail] [int] DEFAULT (1) NOT NULL , [user_options] [int] DEFAULT (230271) NOT NULL , [user_avatar] [varchar] (255) DEFAULT ('') NOT NULL , - [user_avatar_type] [int] DEFAULT (0) NOT NULL , + [user_avatar_type] [varchar] (32) DEFAULT ('') NOT NULL , [user_avatar_width] [int] DEFAULT (0) NOT NULL , [user_avatar_height] [int] DEFAULT (0) NOT NULL , [user_sig] [text] DEFAULT ('') NOT NULL , diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 97c378621b..a41a55494c 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -317,7 +317,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varbinary(8) DEFAULT '' NOT NULL, group_display tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_avatar varbinary(255) DEFAULT '' NOT NULL, - group_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + group_avatar_type varbinary(32) DEFAULT '' NOT NULL, group_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -941,7 +941,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, user_options int(11) UNSIGNED DEFAULT '230271' NOT NULL, user_avatar varbinary(255) DEFAULT '' NOT NULL, - user_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + user_avatar_type varbinary(32) DEFAULT '' NOT NULL, user_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_sig mediumblob NOT NULL, -- cgit v1.2.1 From c7976279e1c85f921156ed499dee1e587587c693 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 18:59:24 +0200 Subject: [feature/avatars] Fix avatar driver filename for autoloading PHPBB3-10018 --- phpBB/includes/avatar/driver.php | 172 -------------------------------- phpBB/includes/avatar/driver/driver.php | 172 ++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 172 deletions(-) delete mode 100644 phpBB/includes/avatar/driver.php create mode 100644 phpBB/includes/avatar/driver/driver.php (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver.php b/phpBB/includes/avatar/driver.php deleted file mode 100644 index d158c419bd..0000000000 --- a/phpBB/includes/avatar/driver.php +++ /dev/null @@ -1,172 +0,0 @@ -config = $config; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; - $this->cache = $cache; - } - - /** - * Get the avatar url and dimensions - * - * @param $ignore_config Whether this function should respect the users prefs - * and board configuration configuration option, or should just render - * the avatar anyways. Useful for the ACP. - * @return array Avatar data - */ - public function get_data($row, $ignore_config = false) - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - - /** - * Returns custom html for displaying this avatar. - * Only called if $custom_html is true. - * - * @param $ignore_config Whether this function should respect the users prefs - * and board configuration configuration option, or should just render - * the avatar anyways. Useful for the ACP. - * @return string HTML - */ - public function get_custom_html($row, $ignore_config = false) - { - return ''; - } - - /** - * @TODO - **/ - public function prepare_form($template, $row, &$error, &$override_focus) - { - return false; - } - - /** - * @TODO - **/ - public function process_form($template, $row, &$error) - { - return false; - } - - /** - * @TODO - **/ - public function delete($row) - { - return true; - } - - /** - * @TODO - **/ - public static function clean_row($row, $src = phpbb_avatar_driver::FROM_USER) - { - $return = array(); - $prefix = false; - - if ($src == phpbb_avatar_driver::FROM_USER) - { - $prefix = 'user_'; - } - else if ($src == phpbb_avatar_driver::FROM_GROUP) - { - $prefix = 'group_'; - } - - if ($prefix) - { - $len = strlen($prefix); - foreach ($row as $key => $val) - { - $sub = substr($key, 0, $len); - if ($sub == $prefix) - { - $return[substr($key, $len)] = $val; - } - else - { - $return[$key] = $val; - } - } - } - else - { - $return = $row; - } - - return $return; - } -} diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php new file mode 100644 index 0000000000..d158c419bd --- /dev/null +++ b/phpBB/includes/avatar/driver/driver.php @@ -0,0 +1,172 @@ +config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->cache = $cache; + } + + /** + * Get the avatar url and dimensions + * + * @param $ignore_config Whether this function should respect the users prefs + * and board configuration configuration option, or should just render + * the avatar anyways. Useful for the ACP. + * @return array Avatar data + */ + public function get_data($row, $ignore_config = false) + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + + /** + * Returns custom html for displaying this avatar. + * Only called if $custom_html is true. + * + * @param $ignore_config Whether this function should respect the users prefs + * and board configuration configuration option, or should just render + * the avatar anyways. Useful for the ACP. + * @return string HTML + */ + public function get_custom_html($row, $ignore_config = false) + { + return ''; + } + + /** + * @TODO + **/ + public function prepare_form($template, $row, &$error, &$override_focus) + { + return false; + } + + /** + * @TODO + **/ + public function process_form($template, $row, &$error) + { + return false; + } + + /** + * @TODO + **/ + public function delete($row) + { + return true; + } + + /** + * @TODO + **/ + public static function clean_row($row, $src = phpbb_avatar_driver::FROM_USER) + { + $return = array(); + $prefix = false; + + if ($src == phpbb_avatar_driver::FROM_USER) + { + $prefix = 'user_'; + } + else if ($src == phpbb_avatar_driver::FROM_GROUP) + { + $prefix = 'group_'; + } + + if ($prefix) + { + $len = strlen($prefix); + foreach ($row as $key => $val) + { + $sub = substr($key, 0, $len); + if ($sub == $prefix) + { + $return[substr($key, $len)] = $val; + } + else + { + $return[$key] = $val; + } + } + } + else + { + $return = $row; + } + + return $return; + } +} -- cgit v1.2.1 From 3b0e0dba3279a78cab2336d32ee8ff63a7077c5c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 19:08:54 +0200 Subject: [feature/avatars] Remove unneeded require (class is now autoloaded) PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 001fcf2f14..a81b0d1e51 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -82,8 +82,6 @@ class phpbb_avatar_manager **/ private function load_valid_drivers() { - require_once($this->phpbb_root_path . 'includes/avatar/driver.' . $this->phpEx); - if ($this->cache) { self::$valid_drivers = $this->cache->get('avatar_drivers'); -- cgit v1.2.1 From e861bb0e04c08b03366ec7c58473b630acc91181 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 19:19:13 +0200 Subject: [feature/avatars] Use request object in avatar drivers PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 5 +++-- phpBB/includes/avatar/driver/driver.php | 12 ++++++++++-- phpBB/includes/avatar/driver/local.php | 8 ++++---- phpBB/includes/avatar/driver/remote.php | 12 ++++++------ phpBB/includes/avatar/driver/upload.php | 2 +- phpBB/includes/avatar/manager.php | 6 ++++-- phpBB/includes/functions_display.php | 3 ++- phpBB/includes/ucp/ucp_profile.php | 4 ++-- 9 files changed, 33 insertions(+), 21 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 16ae8670ce..0a22c216c7 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -289,7 +289,7 @@ class acp_groups if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index c0da9b8ce0..12da482dbe 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -32,6 +32,7 @@ class acp_users { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; + global $request; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; @@ -466,7 +467,7 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); if ($driver = $avatar_manager->get_driver($user_row['user_avatar_type'])) { $driver->delete($user_row); @@ -1687,7 +1688,7 @@ class acp_users $avatars_enabled = false; if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index d158c419bd..8fb80693fb 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -26,7 +26,13 @@ abstract class phpbb_avatar_driver * @type phpbb_config */ protected $config; - + + /** + * Current board configuration + * @type phpbb_config + */ + protected $request; + /** * Current $phpbb_root_path * @type string @@ -62,13 +68,15 @@ abstract class phpbb_avatar_driver * Construct an driver object * * @param $config The phpBB configuration + * @param $request The request object * @param $phpbb_root_path The path to the phpBB root * @param $phpEx The php file extension * @param $cache A cache driver */ - public function __construct(phpbb_config $config, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null) + public function __construct(phpbb_config $config, phpbb_request $request, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null) { $this->config = $config; + $this->request = $request; $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->cache = $cache; diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index f87854315d..27e451c099 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -50,7 +50,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function prepare_form($template, $row, &$error) { $avatar_list = $this->get_avatar_list(); - $category = request_var('av_local_cat', ''); + $category = $this->request->variable('av_local_cat', ''); $categories = array_keys($avatar_list); @@ -110,9 +110,9 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver public function process_form($template, $row, &$error) { $avatar_list = $this->get_avatar_list(); - $category = request_var('av_local_cat', ''); - - $file = request_var('av_local_file', ''); + $category = $this->request->variable('av_local_cat', ''); + + $file = $this->request->variable('av_local_file', ''); if (!isset($avatar_list[$category][urldecode($file)])) { $error[] = 'AVATAR_URL_NOT_FOUND'; diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php index cad9850c3f..cd0a756428 100644 --- a/phpBB/includes/avatar/driver/remote.php +++ b/phpBB/includes/avatar/driver/remote.php @@ -50,8 +50,8 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver public function prepare_form($template, $row, &$error) { $template->assign_vars(array( - 'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : request_var('av_local_width', 0), - 'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : request_var('av_local_width', 0), + 'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0), + 'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0), 'AV_REMOTE_URL' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar']) ? $row['avatar'] : '', )); @@ -63,10 +63,10 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver */ public function process_form($template, $row, &$error) { - $url = request_var('av_remote_url', ''); - $width = request_var('av_remote_width', 0); - $height = request_var('av_remote_height', 0); - + $url = $this->request->variable('av_remote_url', ''); + $width = $this->request->variable('av_remote_width', 0); + $height = $this->request->variable('av_remote_height', 0); + if (!preg_match('#^(http|https|ftp)://#i', $url)) { $url = 'http://' . $url; diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index 23521ef435..c7d2b870c1 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -76,7 +76,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); - $url = request_var('av_upload_url', ''); + $url = $this->request->variable('av_upload_url', ''); if (!empty($_FILES['av_upload_file']['name'])) { diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index a81b0d1e51..f9a262b92f 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -23,17 +23,19 @@ class phpbb_avatar_manager private $phpbb_root_path; private $phpEx; private $config; + private $request; private $cache; private static $valid_drivers = false; /** * @TODO **/ - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_cache_driver_interface $cache = null) + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache = null) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->config = $config; + $this->request = $request; $this->cache = $cache; } @@ -66,7 +68,7 @@ class phpbb_avatar_manager if ($new || !is_object(self::$valid_drivers[$avatar_type])) { $class_name = 'phpbb_avatar_driver_' . $avatar_type; - self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->phpbb_root_path, $this->phpEx, $this->cache); + self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache); } return self::$valid_drivers[$avatar_type]; diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 1c1663f2cc..c59805dacd 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1312,6 +1312,7 @@ function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = fal function get_avatar($row, $alt, $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; + global $request; static $avatar_manager = null; @@ -1369,7 +1370,7 @@ function get_avatar($row, $alt, $ignore_config = false) default: if (empty($avatar_manager)) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->get_driver()); + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); } $avatar = $avatar_manager->get_driver($row['avatar_type']); diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 1c469fa290..ffc6ebf556 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -552,8 +552,8 @@ class ucp_profile if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver()); - + $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); + $avatar_drivers = $avatar_manager->get_valid_drivers(); sort($avatar_drivers); -- cgit v1.2.1 From 0898d114574e88eb5eda819b8921a27739be74ca Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Apr 2012 20:27:11 +0200 Subject: [feature/avatars] Fix CS PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index f9a262b92f..41429f3a06 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -116,7 +116,8 @@ class phpbb_avatar_manager /** * @TODO **/ - public function get_valid_drivers() { + public function get_valid_drivers() + { if (self::$valid_drivers === false) { $this->load_valid_drivers(); -- cgit v1.2.1 From e8a9c0ae6d92822699de9a2d7fc1aae9377ade8a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:11:06 +0200 Subject: [feature/avatars] Fix avatar_type in create_schema_files PHPBB3-10018 --- phpBB/develop/create_schema_files.php | 4 ++-- phpBB/install/schemas/mssql_schema.sql | 2 +- phpBB/install/schemas/mysql_41_schema.sql | 4 ++-- phpBB/install/schemas/oracle_schema.sql | 4 ++-- phpBB/install/schemas/postgres_schema.sql | 4 ++-- phpBB/install/schemas/sqlite_schema.sql | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) (limited to 'phpBB') diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 4088657743..6418bb57f0 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1168,7 +1168,7 @@ function get_schema_struct() 'group_desc_uid' => array('VCHAR:8', ''), 'group_display' => array('BOOL', 0), 'group_avatar' => array('VCHAR', ''), - 'group_avatar_type' => array('TINT:2', 0), + 'group_avatar_type' => array('VCHAR:32', ''), 'group_avatar_width' => array('USINT', 0), 'group_avatar_height' => array('USINT', 0), 'group_rank' => array('UINT', 0), @@ -1821,7 +1821,7 @@ function get_schema_struct() 'user_allow_massemail' => array('BOOL', 1), 'user_options' => array('UINT:11', 230271), 'user_avatar' => array('VCHAR', ''), - 'user_avatar_type' => array('TINT:2', 0), + 'user_avatar_type' => array('VCHAR:32', ''), 'user_avatar_width' => array('USINT', 0), 'user_avatar_height' => array('USINT', 0), 'user_sig' => array('MTEXT_UNI', ''), diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 2cf60e9f02..516b030f5a 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -1109,7 +1109,7 @@ CREATE TABLE [phpbb_reports] ( [report_closed] [int] DEFAULT (0) NOT NULL , [report_time] [int] DEFAULT (0) NOT NULL , [report_text] [text] DEFAULT ('') NOT NULL , - [reported_post_text] [text] DEFAULT ('') NOT NULL + [reported_post_text] [text] DEFAULT ('') NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 3fd8d4f1d1..11286e2526 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -317,7 +317,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) DEFAULT '' NOT NULL, group_display tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_avatar varchar(255) DEFAULT '' NOT NULL, - group_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + group_avatar_type varchar(32) DEFAULT '' NOT NULL, group_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, group_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -917,7 +917,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, user_options int(11) UNSIGNED DEFAULT '230271' NOT NULL, user_avatar varchar(255) DEFAULT '' NOT NULL, - user_avatar_type tinyint(2) DEFAULT '0' NOT NULL, + user_avatar_type varchar(32) DEFAULT '' NOT NULL, user_avatar_width smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_avatar_height smallint(4) UNSIGNED DEFAULT '0' NOT NULL, user_sig mediumtext NOT NULL, diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 8a0f3e56b1..3bc6a853ca 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -610,7 +610,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar2(8) DEFAULT '' , group_display number(1) DEFAULT '0' NOT NULL, group_avatar varchar2(255) DEFAULT '' , - group_avatar_type number(2) DEFAULT '0' NOT NULL, + group_avatar_type varchar2(32) DEFAULT '' , group_avatar_width number(4) DEFAULT '0' NOT NULL, group_avatar_height number(4) DEFAULT '0' NOT NULL, group_rank number(8) DEFAULT '0' NOT NULL, @@ -1665,7 +1665,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail number(1) DEFAULT '1' NOT NULL, user_options number(11) DEFAULT '230271' NOT NULL, user_avatar varchar2(255) DEFAULT '' , - user_avatar_type number(2) DEFAULT '0' NOT NULL, + user_avatar_type varchar2(32) DEFAULT '' , user_avatar_width number(4) DEFAULT '0' NOT NULL, user_avatar_height number(4) DEFAULT '0' NOT NULL, user_sig clob DEFAULT '' , diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index c624024362..f139dc0ced 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -463,7 +463,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) DEFAULT '' NOT NULL, group_display INT2 DEFAULT '0' NOT NULL CHECK (group_display >= 0), group_avatar varchar(255) DEFAULT '' NOT NULL, - group_avatar_type INT2 DEFAULT '0' NOT NULL, + group_avatar_type varchar(32) DEFAULT '' NOT NULL, group_avatar_width INT2 DEFAULT '0' NOT NULL CHECK (group_avatar_width >= 0), group_avatar_height INT2 DEFAULT '0' NOT NULL CHECK (group_avatar_height >= 0), group_rank INT4 DEFAULT '0' NOT NULL CHECK (group_rank >= 0), @@ -1167,7 +1167,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INT2 DEFAULT '1' NOT NULL CHECK (user_allow_massemail >= 0), user_options INT4 DEFAULT '230271' NOT NULL CHECK (user_options >= 0), user_avatar varchar(255) DEFAULT '' NOT NULL, - user_avatar_type INT2 DEFAULT '0' NOT NULL, + user_avatar_type varchar(32) DEFAULT '' NOT NULL, user_avatar_width INT2 DEFAULT '0' NOT NULL CHECK (user_avatar_width >= 0), user_avatar_height INT2 DEFAULT '0' NOT NULL CHECK (user_avatar_height >= 0), user_sig TEXT DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index bd002c93ed..417464110b 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -309,7 +309,7 @@ CREATE TABLE phpbb_groups ( group_desc_uid varchar(8) NOT NULL DEFAULT '', group_display INTEGER UNSIGNED NOT NULL DEFAULT '0', group_avatar varchar(255) NOT NULL DEFAULT '', - group_avatar_type tinyint(2) NOT NULL DEFAULT '0', + group_avatar_type varchar(32) NOT NULL DEFAULT '', group_avatar_width INTEGER UNSIGNED NOT NULL DEFAULT '0', group_avatar_height INTEGER UNSIGNED NOT NULL DEFAULT '0', group_rank INTEGER UNSIGNED NOT NULL DEFAULT '0', @@ -891,7 +891,7 @@ CREATE TABLE phpbb_users ( user_allow_massemail INTEGER UNSIGNED NOT NULL DEFAULT '1', user_options INTEGER UNSIGNED NOT NULL DEFAULT '230271', user_avatar varchar(255) NOT NULL DEFAULT '', - user_avatar_type tinyint(2) NOT NULL DEFAULT '0', + user_avatar_type varchar(32) NOT NULL DEFAULT '', user_avatar_width INTEGER UNSIGNED NOT NULL DEFAULT '0', user_avatar_height INTEGER UNSIGNED NOT NULL DEFAULT '0', user_sig mediumtext(16777215) NOT NULL DEFAULT '', -- cgit v1.2.1 From eea2ec50521e274b928d23f710108f37797cb22c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:27:09 +0200 Subject: [feature/avatars] Introduce global phpbb_avatar_manager PHPBB3-10018 --- phpBB/common.php | 2 ++ phpBB/download/file.php | 2 ++ phpBB/includes/acp/acp_groups.php | 10 ++++------ phpBB/includes/acp/acp_users.php | 12 +++++------- phpBB/includes/functions_display.php | 10 ++-------- phpBB/includes/ucp/ucp_profile.php | 13 ++++++------- 6 files changed, 21 insertions(+), 28 deletions(-) (limited to 'phpBB') diff --git a/phpBB/common.php b/phpBB/common.php index b3b8d7e4f7..c59c231d28 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -130,6 +130,8 @@ $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_ $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); +$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); + // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display'))); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index c01b0789de..55364b3fd0 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -82,6 +82,8 @@ if (isset($_GET['avatar'])) $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); + $phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); + $filename = request_var('avatar', ''); $avatar_group = false; $exit = false; diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 0a22c216c7..34c233604a 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -26,6 +26,7 @@ class acp_groups { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; + global $phpbb_avatar_manager; $user->add_lang('acp/groups'); $this->tpl_name = 'acp_groups'; @@ -282,16 +283,13 @@ class acp_groups // Setup avatar data for later $avatars_enabled = false; - $avatar_manager = null; $avatar_drivers = null; $avatar_data = null; $avatar_error = array(); if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - - $avatar_drivers = $avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); // This is normalised data, without the group_ prefix @@ -337,7 +335,7 @@ class acp_groups $driver = request_var('avatar_driver', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) @@ -534,7 +532,7 @@ class acp_groups 'avatar' => "acp_avatar_options_$driver.html", )); - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); if ($avatar->prepare_form($template, $avatar_data, $avatar_error)) { diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 12da482dbe..fac84ba40a 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -33,6 +33,7 @@ class acp_users global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; global $request; + global $phpbb_avatar_manager; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; @@ -467,8 +468,7 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - if ($driver = $avatar_manager->get_driver($user_row['user_avatar_type'])) + if ($driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type'])) { $driver->delete($user_row); } @@ -1688,9 +1688,7 @@ class acp_users $avatars_enabled = false; if ($config['allow_avatar']) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - - $avatar_drivers = $avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); // This is normalised data, without the user_ prefix @@ -1703,7 +1701,7 @@ class acp_users $driver = request_var('avatar_driver', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); if ($result && empty($error)) @@ -1758,7 +1756,7 @@ class acp_users 'avatar' => "acp_avatar_options_$driver.html", )); - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); if ($avatar->prepare_form($template, $avatar_data, $error)) { diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index c59805dacd..e1dd67aeaf 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1313,8 +1313,7 @@ function get_avatar($row, $alt, $ignore_config = false) { global $user, $config, $cache, $phpbb_root_path, $phpEx; global $request; - - static $avatar_manager = null; + global $phpbb_avatar_manager; if (!$config['allow_avatar'] && !$ignore_config) { @@ -1368,12 +1367,7 @@ function get_avatar($row, $alt, $ignore_config = false) break; default: - if (empty($avatar_manager)) - { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); - } - - $avatar = $avatar_manager->get_driver($row['avatar_type']); + $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); if ($avatar) { diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index ffc6ebf556..58e5254d4b 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -30,6 +30,7 @@ class ucp_profile { global $cache, $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; global $request; + global $phpbb_avatar_manager; $user->add_lang('posting'); @@ -552,11 +553,9 @@ class ucp_profile if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) { - $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->getDriver()); - - $avatar_drivers = $avatar_manager->get_valid_drivers(); + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); sort($avatar_drivers); - + // This is normalised data, without the user_ prefix $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver::FROM_USER); @@ -567,7 +566,7 @@ class ucp_profile $driver = request_var('avatar_driver', ''); if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) { - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); $result = $avatar->process_form($template, $avatar_data, $error); if ($result && empty($error)) @@ -594,7 +593,7 @@ class ucp_profile else { // They are removing their avatar or are trying to play games with us - if ($avatar = $avatar_manager->get_driver($user->data['user_avatar_type'])) + if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) { $avatar->delete($avatar_data); } @@ -634,7 +633,7 @@ class ucp_profile 'avatar' => "ucp_avatar_options_$driver.html", )); - $avatar = $avatar_manager->get_driver($driver); + $avatar = $phpbb_avatar_manager->get_driver($driver); if ($avatar->prepare_form($template, $avatar_data, $error)) { -- cgit v1.2.1 From 81fb4268cd141259fe5b3bc9ad51adf2e29e0772 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 16:40:19 +0200 Subject: [feature/avatars] Introduce an avatar driver interface PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatar/driver/driver.php | 39 +++++----------- phpBB/includes/avatar/driver/interface.php | 71 ++++++++++++++++++++++++++++++ phpBB/includes/functions_display.php | 4 +- phpBB/includes/ucp/ucp_profile.php | 2 +- 6 files changed, 87 insertions(+), 33 deletions(-) create mode 100644 phpBB/includes/avatar/driver/interface.php (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 34c233604a..5a45b3b572 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -293,7 +293,7 @@ class acp_groups sort($avatar_drivers); // This is normalised data, without the group_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver::FROM_GROUP); + $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver_interface::FROM_GROUP); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index fac84ba40a..9c12116062 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1692,7 +1692,7 @@ class acp_users sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_USER); + $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); if ($submit) { diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 8fb80693fb..277130e819 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Base class for avatar drivers * @package avatars */ -abstract class phpbb_avatar_driver +abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { /** * Current board configuration @@ -51,12 +51,6 @@ abstract class phpbb_avatar_driver */ protected $cache; - /** - * @TODO - */ - const FROM_USER = 0; - const FROM_GROUP = 1; - /** * This flag should be set to true if the avatar requires a nonstandard image * tag, and will generate the html itself. @@ -83,12 +77,7 @@ abstract class phpbb_avatar_driver } /** - * Get the avatar url and dimensions - * - * @param $ignore_config Whether this function should respect the users prefs - * and board configuration configuration option, or should just render - * the avatar anyways. Useful for the ACP. - * @return array Avatar data + * @inheritdoc */ public function get_data($row, $ignore_config = false) { @@ -100,13 +89,7 @@ abstract class phpbb_avatar_driver } /** - * Returns custom html for displaying this avatar. - * Only called if $custom_html is true. - * - * @param $ignore_config Whether this function should respect the users prefs - * and board configuration configuration option, or should just render - * the avatar anyways. Useful for the ACP. - * @return string HTML + * @inheritdoc */ public function get_custom_html($row, $ignore_config = false) { @@ -114,7 +97,7 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ public function prepare_form($template, $row, &$error, &$override_focus) { @@ -122,7 +105,7 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ public function process_form($template, $row, &$error) { @@ -130,7 +113,7 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ public function delete($row) { @@ -138,18 +121,18 @@ abstract class phpbb_avatar_driver } /** - * @TODO + * @inheritdoc **/ - public static function clean_row($row, $src = phpbb_avatar_driver::FROM_USER) + public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER) { $return = array(); $prefix = false; - - if ($src == phpbb_avatar_driver::FROM_USER) + + if ($src == phpbb_avatar_driver_interface::FROM_USER) { $prefix = 'user_'; } - else if ($src == phpbb_avatar_driver::FROM_GROUP) + else if ($src == phpbb_avatar_driver_interface::FROM_GROUP) { $prefix = 'group_'; } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php new file mode 100644 index 0000000000..dcec5811bb --- /dev/null +++ b/phpBB/includes/avatar/driver/interface.php @@ -0,0 +1,71 @@ + '', 'width' => 0, 'height' => 0] + */ + public function get_data($row, $ignore_config = false); + + /** + * Returns custom html for displaying this avatar. + * Only called if $custom_html is true. + * + * @param $ignore_config Whether this function should respect the users prefs + * and board configuration configuration option, or should just render + * the avatar anyways. Useful for the ACP. + * @return string HTML + */ + public function get_custom_html($row, $ignore_config = false); + + /** + * @TODO + **/ + public function prepare_form($template, $row, &$error, &$override_focus); + + /** + * @TODO + **/ + public function process_form($template, $row, &$error); + + /** + * @TODO + **/ + public function delete($row); + + /** + * @TODO + **/ + public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER); +} diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index e1dd67aeaf..82638b7f2b 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1281,7 +1281,7 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank */ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_USER); + $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); return get_avatar($row, $alt, $ignore_config); } @@ -1296,7 +1296,7 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false */ function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver::FROM_GROUP); + $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_GROUP); return get_avatar($row, $alt, $ignore_config); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 58e5254d4b..9d22fd4dba 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -557,7 +557,7 @@ class ucp_profile sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver::FROM_USER); + $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver_interface::FROM_USER); if ($submit) { -- cgit v1.2.1 From 3b71e81cfba726043063b05cb793e18186143252 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 21:29:52 +0200 Subject: [feature/avatars] Simplify clean_row, move it to avatar manager PHPBB3-10018 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/avatar/driver/driver.php | 41 ------------------------------ phpBB/includes/avatar/driver/interface.php | 11 -------- phpBB/includes/avatar/manager.php | 19 ++++++++++++++ phpBB/includes/functions_display.php | 4 +-- phpBB/includes/ucp/ucp_profile.php | 2 +- 7 files changed, 24 insertions(+), 57 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 5a45b3b572..d4a3e40d93 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -293,7 +293,7 @@ class acp_groups sort($avatar_drivers); // This is normalised data, without the group_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver_interface::FROM_GROUP); + $avatar_data = phpbb_avatar_manager::clean_row($group_row); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 9c12116062..cd50b02ca1 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1692,7 +1692,7 @@ class acp_users sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); + $avatar_data = phpbb_avatar_manager::clean_row($user_row); if ($submit) { diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 277130e819..7028df4b64 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -119,45 +119,4 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { return true; } - - /** - * @inheritdoc - **/ - public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER) - { - $return = array(); - $prefix = false; - - if ($src == phpbb_avatar_driver_interface::FROM_USER) - { - $prefix = 'user_'; - } - else if ($src == phpbb_avatar_driver_interface::FROM_GROUP) - { - $prefix = 'group_'; - } - - if ($prefix) - { - $len = strlen($prefix); - foreach ($row as $key => $val) - { - $sub = substr($key, 0, $len); - if ($sub == $prefix) - { - $return[substr($key, $len)] = $val; - } - else - { - $return[$key] = $val; - } - } - } - else - { - $return = $row; - } - - return $return; - } } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index dcec5811bb..8c8a067d13 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -21,12 +21,6 @@ if (!defined('IN_PHPBB')) */ interface phpbb_avatar_driver_interface { - /** - * @TODO - */ - const FROM_USER = 0; - const FROM_GROUP = 1; - /** * Get the avatar url and dimensions * @@ -63,9 +57,4 @@ interface phpbb_avatar_driver_interface * @TODO **/ public function delete($row); - - /** - * @TODO - **/ - public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER); } diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 41429f3a06..054bb0cee9 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -125,4 +125,23 @@ class phpbb_avatar_manager return array_keys(self::$valid_drivers); } + + /** + * Strip out user_ and group_ prefixes from keys + **/ + public static function clean_row($row) + { + $keys = array_keys($row); + $values = array_values($row); + + $keys = array_map( + function ($key) + { + return preg_replace('(user_|group_)', '', $key); + }, + $row + ); + + return array_combine($keys, $values); + } } diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 82638b7f2b..619c30ada5 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1281,7 +1281,7 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank */ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER); + $row = phpbb_avatar_manager::clean_row($user_row); return get_avatar($row, $alt, $ignore_config); } @@ -1296,7 +1296,7 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false */ function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) { - $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_GROUP); + $row = phpbb_avatar_manager::clean_row($user_row); return get_avatar($row, $alt, $ignore_config); } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 9d22fd4dba..44dc57cfd7 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -557,7 +557,7 @@ class ucp_profile sort($avatar_drivers); // This is normalised data, without the user_ prefix - $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver_interface::FROM_USER); + $avatar_data = phpbb_avatar_manager::clean_row($user->data); if ($submit) { -- cgit v1.2.1 From a1132fc5c7e990d73cbc8ac7abf4502a1bbe7216 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 21:45:51 +0200 Subject: [feature/avatars] Update avatars in database_update PHPBB3-10018 --- phpBB/includes/functions_display.php | 70 +++++++----------------------------- phpBB/install/database_update.php | 24 +++++++++++-- 2 files changed, 35 insertions(+), 59 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 619c30ada5..291d92387f 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1325,72 +1325,28 @@ function get_avatar($row, $alt, $ignore_config = false) 'width' => $row['avatar_width'], 'height' => $row['avatar_height'], ); - - switch ($row['avatar_type']) - { - case AVATAR_UPLOAD: - // Compatibility with old avatars - if (!$config['allow_avatar_upload'] && !$ignore_config) - { - $avatar_data['src'] = ''; - } - else - { - $avatar_data['src'] = $phpbb_root_path . "download/file.$phpEx?avatar=" . $avatar_data['src']; - $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); - } - break; - case AVATAR_GALLERY: - // Compatibility with old avatars - if (!$config['allow_avatar_local'] && !$ignore_config) - { - $avatar_data['src'] = ''; - } - else - { - $avatar_data['src'] = $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_data['src']; - $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); - } - break; - - case AVATAR_REMOTE: - // Compatibility with old avatars - if (!$config['allow_avatar_remote'] && !$ignore_config) - { - $avatar_data['src'] = ''; - } - else - { - $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']); - } - break; + $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); - default: - $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']); - - if ($avatar) - { - if ($avatar->custom_html) - { - return $avatar->get_html($row, $ignore_config); - } - - $avatar_data = $avatar->get_data($row, $ignore_config); - } - else - { - $avatar_data['src'] = ''; - } + if ($avatar) + { + if ($avatar->custom_html) + { + return $avatar->get_html($row, $ignore_config); + } - break; + $avatar_data = $avatar->get_data($row, $ignore_config); + } + else + { + $avatar_data['src'] = ''; } $html = ''; if (!empty($avatar_data['src'])) { - $html = ''; diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index e85fe1810d..75f1ada749 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2391,13 +2391,33 @@ function change_database_data(&$no_updates, $version) { set_config('teampage_memberships', '1'); } - + // Clear styles table and add prosilver entry _sql('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); $sql = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')"; _sql($sql, $errored, $error_ary); - + + // Update avatars to modular types + $avatar_type_map = array( + AVATAR_UPLOAD => 'upload', + AVATAR_GALLERY => 'local', + AVATAR_REMOTE => 'remote', + ); + + foreach ($avatar_type_map as $old => $new) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_avatar_type = '" . $db->sql_escape($new) . "' + WHERE user_avatar_type = '" . $db->sql_escape($old) . "'"; + _sql($sql, $errored, $error_ary); + + $sql = 'UPDATE ' . GROUPS_TABLE . " + SET group_avatar_type = '" . $db->sql_escape($new) . "' + WHERE group_avatar_type = '" . $db->sql_escape($old) . "'"; + _sql($sql, $errored, $error_ary); + } + $no_updates = false; break; -- cgit v1.2.1 From b2b812f1714fc924a7c9e595ccb8fbb35f20f203 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 22:13:10 +0200 Subject: [feature/avatars] Do not assign in an if statement PHPBB3-10018 --- phpBB/includes/acp/acp_users.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index cd50b02ca1..33a173b74d 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -468,7 +468,8 @@ class acp_users $db->sql_query($sql); // Delete old avatar if present - if ($driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type'])) + $driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type']); + if ($driver) { $driver->delete($user_row); } -- cgit v1.2.1 From f273ab16ae68d15832832e2b2c98a3b99c966c97 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Apr 2012 22:28:40 +0200 Subject: [feature/avatars] Fix clean_row regex, thanks to chris PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 054bb0cee9..f4e5a6d7f8 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -137,7 +137,7 @@ class phpbb_avatar_manager $keys = array_map( function ($key) { - return preg_replace('(user_|group_)', '', $key); + return preg_replace('#^(?:user_|group_)#', '', $key); }, $row ); -- cgit v1.2.1 From a9cf558af7fc08539e15ceca1e889e087c815c8d Mon Sep 17 00:00:00 2001 From: Sajaki Date: Sat, 28 Apr 2012 10:43:43 +0200 Subject: [ticket/10854] sql server drop default constraint when dropping column drops default columns with T-SQL before attempting drop column to avoids sql exception. This is a huge annoyance in UMIL scripts running under sql server. --- phpBB/includes/db/db_tools.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index c6dd23e6bd..f63ff18cbe 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -1819,6 +1819,22 @@ class phpbb_db_tools case 'mssql': case 'mssqlnative': + // remove default cosntraints first + // http://msdn.microsoft.com/en-us/library/aa175912%28v=sql.80%29.aspx + $statements[] = "DECLARE @drop_default_name VARCHAR(100), @cmd VARCHAR(1000) + SET @drop_default_name = + (SELECT so.name FROM sysobjects so + JOIN sysconstraints sc ON so.id = sc.constid + WHERE object_name(so.parent_obj) = '{$table_name}' + AND so.xtype = 'D' + AND sc.colid = (SELECT colid FROM syscolumns + WHERE id = object_id('{$table_name}') + AND name = '{$column_name}')) + IF @drop_default_name <> '' + BEGIN + SET @cmd = 'ALTER TABLE [{$table_name}] DROP CONSTRAINT [' + @drop_default_name + ']' + EXEC(@cmd) + END"; $statements[] = 'ALTER TABLE [' . $table_name . '] DROP COLUMN [' . $column_name . ']'; break; -- cgit v1.2.1 From d5a788ae5b615c1b6b642c631884a4d936be2a4c Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 21 Jun 2012 19:16:05 +0100 Subject: [ticket/10949] Converted AJAX coding standards to new guidelines. Basically, moved parentheses to same line and changed variable names to camel case. PHPBB3-10949 --- phpBB/assets/javascript/core.js | 195 +++++++++++++------------------- phpBB/styles/prosilver/template/ajax.js | 24 ++-- 2 files changed, 87 insertions(+), 132 deletions(-) (limited to 'phpBB') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 958b6c9ff6..53b85e677a 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -1,5 +1,5 @@ var phpbb = {}; -phpbb.alert_time = 100; +phpbb.alertTime = 100; (function($) { // Avoid conflicts with other libraries @@ -12,35 +12,31 @@ var keymap = { }; var dark = $('#darkenwrapper'); -var loading_alert = $('#loadingalert'); +var loadingAlert = $('#loadingalert'); /** - * Display a loading screen. + * Display a loading screen * - * @returns object Returns loading_alert. + * @returns object Returns loadingAlert. */ -phpbb.loading_alert = function() { - if (dark.is(':visible')) - { - loading_alert.fadeIn(phpbb.alert_time); - } - else - { - loading_alert.show(); - dark.fadeIn(phpbb.alert_time, function() { +phpbb.loadingAlert = function() { + if (dark.is(':visible')) { + loadingAlert.fadeIn(phpbb.alertTime); + } else { + loadingAlert.show(); + dark.fadeIn(phpbb.alertTime, function() { // Wait five seconds and display an error if nothing has been returned by then. setTimeout(function() { - if (loading_alert.is(':visible')) - { + if (loadingAlert.is(':visible')) { phpbb.alert($('#phpbb_alert').attr('data-l-err'), $('#phpbb_alert').attr('data-l-timeout-processing-req')); } }, 5000); }); } - return loading_alert; -} + return loadingAlert; +}; /** * Display a simple alert similar to JSs native alert(). @@ -67,7 +63,7 @@ phpbb.alert = function(title, msg, fadedark) { div.find('.alert_close').unbind('click'); fade = (typeof fadedark !== 'undefined' && !fadedark) ? div : dark; - fade.fadeOut(phpbb.alert_time, function() { + fade.fadeOut(phpbb.alertTime, function() { div.hide(); }); @@ -90,27 +86,22 @@ phpbb.alert = function(title, msg, fadedark) { e.preventDefault(); }); - if (loading_alert.is(':visible')) - { - loading_alert.fadeOut(phpbb.alert_time, function() { + if (loadingAlert.is(':visible')) { + loadingAlert.fadeOut(phpbb.alertTime, function() { dark.append(div); - div.fadeIn(phpbb.alert_time); + div.fadeIn(phpbb.alertTime); }); - } - else if (dark.is(':visible')) - { + } else if (dark.is(':visible')) { dark.append(div); - div.fadeIn(phpbb.alert_time); - } - else - { + div.fadeIn(phpbb.alertTime); + } else { dark.append(div); div.show(); - dark.fadeIn(phpbb.alert_time); + dark.fadeIn(phpbb.alertTime); } return div; -} +}; /** * Display a simple yes / no box to the user. @@ -136,7 +127,7 @@ phpbb.confirm = function(msg, callback, fadedark) { var click_handler = function(e) { var res = this.className === 'button1'; var fade = (typeof fadedark !== 'undefined' && !fadedark && res) ? div : dark; - fade.fadeOut(phpbb.alert_time, function() { + fade.fadeOut(phpbb.alertTime, function() { div.hide(); }); div.find('input[type="button"]').unbind('click', click_handler); @@ -151,7 +142,7 @@ phpbb.confirm = function(msg, callback, fadedark) { dark.one('click', function(e) { div.find('.alert_close').unbind('click'); - dark.fadeOut(phpbb.alert_time, function() { + dark.fadeOut(phpbb.alertTime, function() { div.hide(); }); callback(false); @@ -174,7 +165,7 @@ phpbb.confirm = function(msg, callback, fadedark) { div.find('.alert_close').one('click', function(e) { var fade = (typeof fadedark !== 'undefined' && fadedark) ? div : dark; - fade.fadeOut(phpbb.alert_time, function() { + fade.fadeOut(phpbb.alertTime, function() { div.hide(); }); callback(false); @@ -182,27 +173,22 @@ phpbb.confirm = function(msg, callback, fadedark) { e.preventDefault(); }); - if (loading_alert.is(':visible')) - { - loading_alert.fadeOut(phpbb.alert_time, function() { + if (loadingAlert.is(':visible')) { + loadingAlert.fadeOut(phpbb.alertTime, function() { dark.append(div); - div.fadeIn(phpbb.alert_time); + div.fadeIn(phpbb.alertTime); }); - } - else if (dark.is(':visible')) - { + } else if (dark.is(':visible')) { dark.append(div); - div.fadeIn(phpbb.alert_time); - } - else - { + div.fadeIn(phpbb.alertTime); + } else { dark.append(div); div.show(); - dark.fadeIn(phpbb.alert_time); + dark.fadeIn(phpbb.alertTime); } return div; -} +}; /** * Turn a querystring into an array. @@ -214,13 +200,12 @@ phpbb.parse_querystring = function(string) { var params = {}, i, split; string = string.split('&'); - for (i = 0; i < string.length; i++) - { + for (i = 0; i < string.length; i++) { split = string[i].split('='); params[split[0]] = decodeURIComponent(split[1]); } return params; -} +}; /** @@ -246,14 +231,13 @@ phpbb.ajaxify = function(options) { refresh = options.refresh, callback = options.callback, overlay = (typeof options.overlay !== 'undefined') ? options.overlay : true, - is_form = elements.is('form'), - event_name = is_form ? 'submit' : 'click'; + isForm = elements.is('form'), + eventName = isForm ? 'submit' : 'click'; - elements.bind(event_name, function(event) { + elements.bind(eventName, function(event) { var action, method, data, submit, that = this, $this = $(this); - if ($this.find('input[type="submit"][data-clicked]').attr('data-ajax') === 'false') - { + if ($this.find('input[type="submit"][data-clicked]').attr('data-ajax') === 'false') { return; } @@ -267,84 +251,69 @@ phpbb.ajaxify = function(options) { * * @param object res The object sent back by the server. */ - function return_handler(res) - { + function returnHandler(res) { var alert; // Is a confirmation required? - if (typeof res.S_CONFIRM_ACTION === 'undefined') - { + if (typeof res.S_CONFIRM_ACTION === 'undefined') { // If a confirmation is not required, display an alert and call the // callbacks. - if (typeof res.MESSAGE_TITLE !== 'undefined') - { + if (typeof res.MESSAGE_TITLE !== 'undefined') { alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - } - else - { - dark.fadeOut(phpbb.alert_time); + } else { + dark.fadeOut(phpbb.alertTime); } - if (typeof phpbb.ajax_callbacks[callback] === 'function') - { - phpbb.ajax_callbacks[callback].call(that, res); + if (typeof phpbb.ajaxCallbacks[callback] === 'function') { + phpbb.ajaxCallbacks[callback].call(that, res); } // If the server says to refresh the page, check whether the page should // be refreshed and refresh page after specified time if required. - if (res.REFRESH_DATA) - { - if (typeof refresh === 'function') - { + if (res.REFRESH_DATA) { + if (typeof refresh === 'function') { refresh = refresh(res.REFRESH_DATA.url); - } - else if (typeof refresh !== 'boolean') - { + } else if (typeof refresh !== 'boolean') { refresh = false; } setTimeout(function() { - if (refresh) - { + if (refresh) { window.location = res.REFRESH_DATA.url; } // Hide the alert even if we refresh the page, in case the user // presses the back button. - dark.fadeOut(phpbb.alert_time, function() { + dark.fadeOut(phpbb.alertTime, function() { alert.hide(); }); }, res.REFRESH_DATA.time * 1000); // Server specifies time in seconds } - } - else - { + } else { // If confirmation is required, display a diologue to the user. phpbb.confirm(res.MESSAGE_TEXT, function(del) { - if (del) - { - phpbb.loading_alert(); + if (del) { + phpbb.loadingAlert(); data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); $.ajax({ url: res.S_CONFIRM_ACTION, type: 'POST', data: data + '&confirm=' + res.YES_VALUE, - success: return_handler, - error: error_handler + success: returnHandler, + error: errorHandler }); } }, false); } } - function error_handler() - { + function errorHandler() { var alert; alert = phpbb.alert(dark.attr('data-ajax-error-title'), dark.attr('data-ajax-error-text')); setTimeout(function () { - dark.fadeOut(phpbb.alert_time, function() { + dark.fadeOut(phpbb.alertTime, function() { alert.hide(); }); }, 5000); @@ -352,25 +321,21 @@ phpbb.ajaxify = function(options) { // If the element is a form, POST must be used and some extra data must // be taken from the form. - var run_filter = (typeof options.filter === 'function'); + var runFilter = (typeof options.filter === 'function'); - if (is_form) - { + if (isForm) { action = $this.attr('action').replace('&', '&'); data = $this.serializeArray(); method = $this.attr('method') || 'GET'; - if ($this.find('input[type="submit"][data-clicked]')) - { + if ($this.find('input[type="submit"][data-clicked]')) { submit = $this.find('input[type="submit"][data-clicked]'); data.push({ name: submit.attr('name'), value: submit.val() }); } - } - else - { + } else { action = this.href; data = null; method = 'GET'; @@ -378,28 +343,26 @@ phpbb.ajaxify = function(options) { // If filter function returns false, cancel the AJAX functionality, // and return true (meaning that the HTTP request will be sent normally). - if (run_filter && !options.filter.call(this, data)) - { + if (runFilter && !options.filter.call(this, data)) { return; } - if (overlay) - { - phpbb.loading_alert(); + if (overlay) { + phpbb.loadingAlert(); } $.ajax({ url: action, type: method, data: data, - success: return_handler, - error: error_handler + success: returnHandler, + error: errorHandler }); event.preventDefault(); }); - if (is_form) { + if (isForm) { elements.find('input:submit').click(function () { var $this = $(this); @@ -409,9 +372,9 @@ phpbb.ajaxify = function(options) { } return this; -} +}; -phpbb.ajax_callbacks = {}; +phpbb.ajaxCallbacks = {}; /** * Adds an AJAX callback to be used by phpbb.ajaxify. @@ -421,14 +384,12 @@ phpbb.ajax_callbacks = {}; * @param string id The name of the callback. * @param function callback The callback to be called. */ -phpbb.add_ajax_callback = function(id, callback) -{ - if (typeof callback === 'function') - { - phpbb.ajax_callbacks[id] = callback; +phpbb.add_ajax_callback = function(id, callback) { + if (typeof callback === 'function') { + phpbb.ajaxCallbacks[id] = callback; } return this; -} +}; /** @@ -438,11 +399,11 @@ phpbb.add_ajax_callback = function(id, callback) */ phpbb.add_ajax_callback('alt_text', function(data) { var el = $(this), - alt_text; + altText; - alt_text = el.attr('data-alt-text'); - el.attr('title', alt_text); - el.text(alt_text); + altText = el.attr('data-alt-text'); + el.attr('title', altText); + el.text(altText); }); diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js index 54f34e4204..83335b23af 100644 --- a/phpBB/styles/prosilver/template/ajax.js +++ b/phpBB/styles/prosilver/template/ajax.js @@ -5,14 +5,12 @@ // This callback finds the post from the delete link, and removes it. phpbb.add_ajax_callback('post_delete', function() { var el = $(this), - post_id; - - if (el.attr('data-refresh') === undefined) - { - post_id = el[0].href.split('&p=')[1]; - var post = el.parents('#p' + post_id).css('pointer-events', 'none'); - if (post.hasClass('bg1') || post.hasClass('bg2')) - { + postId; + + if (el.attr('data-refresh') === undefined) { + postId = el[0].href.split('&p=')[1]; + var post = el.parents('#p' + postId).css('pointer-events', 'none'); + if (post.hasClass('bg1') || post.hasClass('bg2')) { var posts1 = post.nextAll('.bg1'); post.nextAll('.bg2').removeClass('bg2').addClass('bg1'); posts1.removeClass('bg1').addClass('bg2'); @@ -54,8 +52,7 @@ $('[data-ajax]').each(function() { ajax = $this.attr('data-ajax'), fn; - if (ajax !== 'false') - { + if (ajax !== 'false') { fn = (ajax !== 'true') ? ajax : null; phpbb.ajaxify({ selector: this, @@ -89,12 +86,9 @@ phpbb.ajaxify({ filter: function (data) { var action = $('#quick-mod-select').val(); - if (action === 'make_normal') - { + if (action === 'make_normal') { return $(this).find('select option[value="make_global"]').length > 0; - } - else if (action === 'lock' || action === 'unlock') - { + } else if (action === 'lock' || action === 'unlock') { return true; } -- cgit v1.2.1 From 6d994380d76accba5485b0a04d3028f1c153ebd8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 14:48:51 +0200 Subject: [feature/avatars] Fix error in avatar_manager::clean_row PHPBB3-10018 --- phpBB/includes/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index f4e5a6d7f8..839216b61e 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -139,7 +139,7 @@ class phpbb_avatar_manager { return preg_replace('#^(?:user_|group_)#', '', $key); }, - $row + $keys ); return array_combine($keys, $values); -- cgit v1.2.1 From d10486699273b896fffe86f05f66a6d542843f5b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 16:59:06 +0200 Subject: [feature/avatars] Remove unneeded argument for driver prepare_form() PHPBB3-10018 --- phpBB/includes/avatar/driver/driver.php | 6 +++--- phpBB/includes/avatar/driver/interface.php | 2 +- phpBB/includes/avatar/driver/local.php | 4 ++-- phpBB/includes/avatar/driver/upload.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 7028df4b64..4ac6762140 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -38,13 +38,13 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface * @type string */ protected $phpbb_root_path; - + /** * Current $phpEx * @type string */ protected $phpEx; - + /** * A cache driver * @type phpbb_cache_driver_interface @@ -99,7 +99,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface /** * @inheritdoc **/ - public function prepare_form($template, $row, &$error, &$override_focus) + public function prepare_form($template, $row, &$error) { return false; } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index 8c8a067d13..d3b764e275 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -46,7 +46,7 @@ interface phpbb_avatar_driver_interface /** * @TODO **/ - public function prepare_form($template, $row, &$error, &$override_focus); + public function prepare_form($template, $row, &$error); /** * @TODO diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php index 27e451c099..a0ef912eae 100644 --- a/phpBB/includes/avatar/driver/local.php +++ b/phpBB/includes/avatar/driver/local.php @@ -43,7 +43,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver ); } } - + /** * @inheritdoc */ @@ -103,7 +103,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver return true; } - + /** * @inheritdoc */ diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php index c7d2b870c1..d9504c04a0 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/includes/avatar/driver/upload.php @@ -58,7 +58,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], )); - + return true; } -- cgit v1.2.1 From f40e6963c61548d746c59b78cb60c0f7459c7696 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 17:11:20 +0200 Subject: [feature/avatars] Remove empty script tag PHPBB3-10018 --- phpBB/styles/prosilver/template/ucp_avatar_options.html | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB') diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index e8114da3ea..a246b00ddd 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -1,4 +1,3 @@ -
@@ -66,5 +65,3 @@
- -- cgit v1.2.1 From 21df013210d1de2cffae568c0620a7ccd6d8f426 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:23:26 +0200 Subject: [feature/avatars] Move avatars JavaScript code to external JS file PHPBB3-10018 --- phpBB/adm/style/acp_groups.html | 23 ++------------------- phpBB/adm/style/acp_users_avatar.html | 23 ++------------------- phpBB/adm/style/avatars.js | 17 +++++++++++++++ phpBB/styles/prosilver/template/avatars.js | 17 +++++++++++++++ .../prosilver/template/ucp_avatar_options.html | 24 ++-------------------- 5 files changed, 40 insertions(+), 64 deletions(-) create mode 100644 phpBB/adm/style/avatars.js create mode 100644 phpBB/styles/prosilver/template/avatars.js (limited to 'phpBB') diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index 42cb434ad3..167642e5cb 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -123,27 +123,6 @@ -
@@ -154,6 +133,8 @@
+ + « {L_BACK} diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index 6316ff4a22..9649fa923e 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -28,30 +28,11 @@ -
{S_FORM_TOKEN} + + diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js new file mode 100644 index 0000000000..baa2623ac9 --- /dev/null +++ b/phpBB/adm/style/avatars.js @@ -0,0 +1,17 @@ +function avatar_simplify() { + var node = document.getElementById('av_options'); + for (var i = 0; i < node.children.length; i++) { + child = node.children[i]; + child.style.display = 'none'; + } + + var selected = document.getElementById('avatar_driver').value; + var id = 'av_option_' + selected; + node = document.getElementById(id); + if (node != null) { + node.style.display = 'block'; + } +} + +avatar_simplify(); +document.getElementById('avatar_driver').onchange = avatar_simplify; diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js new file mode 100644 index 0000000000..baa2623ac9 --- /dev/null +++ b/phpBB/styles/prosilver/template/avatars.js @@ -0,0 +1,17 @@ +function avatar_simplify() { + var node = document.getElementById('av_options'); + for (var i = 0; i < node.children.length; i++) { + child = node.children[i]; + child.style.display = 'none'; + } + + var selected = document.getElementById('avatar_driver').value; + var id = 'av_option_' + selected; + node = document.getElementById(id); + if (node != null) { + node.style.display = 'block'; + } +} + +avatar_simplify(); +document.getElementById('avatar_driver').onchange = avatar_simplify; diff --git a/phpBB/styles/prosilver/template/ucp_avatar_options.html b/phpBB/styles/prosilver/template/ucp_avatar_options.html index a246b00ddd..2438deefd5 100644 --- a/phpBB/styles/prosilver/template/ucp_avatar_options.html +++ b/phpBB/styles/prosilver/template/ucp_avatar_options.html @@ -41,27 +41,7 @@ - - + + -- cgit v1.2.1 From b060667ac102109c0c8f198925bb81b489a30f34 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:26:44 +0200 Subject: [feature/avatars] Rewrite avatars event handler to use jQuery PHPBB3-10018 --- phpBB/adm/style/avatars.js | 16 ++++------------ phpBB/styles/prosilver/template/avatars.js | 16 ++++------------ 2 files changed, 8 insertions(+), 24 deletions(-) (limited to 'phpBB') diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index baa2623ac9..252081ee08 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -1,17 +1,9 @@ function avatar_simplify() { - var node = document.getElementById('av_options'); - for (var i = 0; i < node.children.length; i++) { - child = node.children[i]; - child.style.display = 'none'; - } + $('#av_options').hide(); - var selected = document.getElementById('avatar_driver').value; - var id = 'av_option_' + selected; - node = document.getElementById(id); - if (node != null) { - node.style.display = 'block'; - } + var selected = $('#avatar_driver').val(); + $('#av_option_' + selected).show(); } avatar_simplify(); -document.getElementById('avatar_driver').onchange = avatar_simplify; +$('#avatar_driver').on('change', avatar_simplify); diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index baa2623ac9..252081ee08 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -1,17 +1,9 @@ function avatar_simplify() { - var node = document.getElementById('av_options'); - for (var i = 0; i < node.children.length; i++) { - child = node.children[i]; - child.style.display = 'none'; - } + $('#av_options').hide(); - var selected = document.getElementById('avatar_driver').value; - var id = 'av_option_' + selected; - node = document.getElementById(id); - if (node != null) { - node.style.display = 'block'; - } + var selected = $('#avatar_driver').val(); + $('#av_option_' + selected).show(); } avatar_simplify(); -document.getElementById('avatar_driver').onchange = avatar_simplify; +$('#avatar_driver').on('change', avatar_simplify); -- cgit v1.2.1 From 2f3581fe3ef928d91f12c442ab5e4890c6620f58 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 18:37:23 +0200 Subject: [feature/avatars] Add self-invoking closure around avatars.js PHPBB3-10018 --- phpBB/adm/style/avatars.js | 6 ++++++ phpBB/styles/prosilver/template/avatars.js | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'phpBB') diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index 252081ee08..cb19aa9b7a 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -1,3 +1,7 @@ +(function($) { // Avoid conflicts with other libraries + +"use strict"; + function avatar_simplify() { $('#av_options').hide(); @@ -7,3 +11,5 @@ function avatar_simplify() { avatar_simplify(); $('#avatar_driver').on('change', avatar_simplify); + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index 252081ee08..cb19aa9b7a 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -1,3 +1,7 @@ +(function($) { // Avoid conflicts with other libraries + +"use strict"; + function avatar_simplify() { $('#av_options').hide(); @@ -7,3 +11,5 @@ function avatar_simplify() { avatar_simplify(); $('#avatar_driver').on('change', avatar_simplify); + +})(jQuery); // Avoid conflicts with other libraries -- cgit v1.2.1 From 13f4bfabbeab77698f06c3431931b73ebedc587c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 21:00:00 +0200 Subject: [feature/avatars] Fixup avatars.js rewrite PHPBB3-10018 --- phpBB/adm/style/avatars.js | 4 ++-- phpBB/styles/prosilver/template/avatars.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB') diff --git a/phpBB/adm/style/avatars.js b/phpBB/adm/style/avatars.js index cb19aa9b7a..2068bdbbc4 100644 --- a/phpBB/adm/style/avatars.js +++ b/phpBB/adm/style/avatars.js @@ -3,13 +3,13 @@ "use strict"; function avatar_simplify() { - $('#av_options').hide(); + $('#av_options > div').hide(); var selected = $('#avatar_driver').val(); $('#av_option_' + selected).show(); } avatar_simplify(); -$('#avatar_driver').on('change', avatar_simplify); +$('#avatar_driver').bind('change', avatar_simplify); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/avatars.js b/phpBB/styles/prosilver/template/avatars.js index cb19aa9b7a..2068bdbbc4 100644 --- a/phpBB/styles/prosilver/template/avatars.js +++ b/phpBB/styles/prosilver/template/avatars.js @@ -3,13 +3,13 @@ "use strict"; function avatar_simplify() { - $('#av_options').hide(); + $('#av_options > div').hide(); var selected = $('#avatar_driver').val(); $('#av_option_' + selected).show(); } avatar_simplify(); -$('#avatar_driver').on('change', avatar_simplify); +$('#avatar_driver').bind('change', avatar_simplify); })(jQuery); // Avoid conflicts with other libraries -- cgit v1.2.1 From df16bd1c49e6e970b147f15e752825dd3186fb87 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 27 Jun 2012 21:02:07 +0200 Subject: [feature/avatars] Rewrite drivers to use full class name * Use full driver class name as avatar_type value * Move avatar drivers to core namespace * Make avatars installable through extensions PHPBB3-10018 --- phpBB/common.php | 2 +- phpBB/download/file.php | 2 +- phpBB/includes/avatar/driver/core/local.php | 189 +++++++++++++++++++++++++++ phpBB/includes/avatar/driver/core/remote.php | 163 +++++++++++++++++++++++ phpBB/includes/avatar/driver/core/upload.php | 147 +++++++++++++++++++++ phpBB/includes/avatar/driver/driver.php | 21 +++ phpBB/includes/avatar/driver/interface.php | 10 ++ phpBB/includes/avatar/driver/local.php | 189 --------------------------- phpBB/includes/avatar/driver/remote.php | 163 ----------------------- phpBB/includes/avatar/driver/upload.php | 147 --------------------- phpBB/includes/avatar/manager.php | 55 ++++---- phpBB/includes/ucp/ucp_profile.php | 10 +- 12 files changed, 564 insertions(+), 534 deletions(-) create mode 100644 phpBB/includes/avatar/driver/core/local.php create mode 100644 phpBB/includes/avatar/driver/core/remote.php create mode 100644 phpBB/includes/avatar/driver/core/upload.php delete mode 100644 phpBB/includes/avatar/driver/local.php delete mode 100644 phpBB/includes/avatar/driver/remote.php delete mode 100644 phpBB/includes/avatar/driver/upload.php (limited to 'phpBB') diff --git a/phpBB/common.php b/phpBB/common.php index 11b84ee858..52666685ac 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -130,7 +130,7 @@ $phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_ $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); -$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); +$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $phpbb_extension_manager, $cache->get_driver()); // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 55364b3fd0..34999ab24c 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -82,7 +82,7 @@ if (isset($_GET['avatar'])) $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); - $phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver()); + $phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $phpbb_extension_manager, $cache->get_driver()); $filename = request_var('avatar', ''); $avatar_group = false; diff --git a/phpBB/includes/avatar/driver/core/local.php b/phpBB/includes/avatar/driver/core/local.php new file mode 100644 index 0000000000..ca82b9c175 --- /dev/null +++ b/phpBB/includes/avatar/driver/core/local.php @@ -0,0 +1,189 @@ +config['allow_avatar_local']) + { + return array( + 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } + + /** + * @inheritdoc + */ + public function prepare_form($template, $row, &$error) + { + $avatar_list = $this->get_avatar_list(); + $category = $this->request->variable('av_local_cat', ''); + + $categories = array_keys($avatar_list); + + foreach ($categories as $cat) + { + if (!empty($avatar_list[$cat])) + { + $template->assign_block_vars('av_local_cats', array( + 'NAME' => $cat, + 'SELECTED' => ($cat == $category), + )); + } + } + + if (!empty($avatar_list[$category])) + { + $template->assign_vars(array( + 'AV_LOCAL_SHOW' => true, + )); + + $table_cols = isset($row['av_gallery_cols']) ? $row['av_gallery_cols'] : 4; + $row_count = $col_count = $av_pos = 0; + $av_count = sizeof($avatar_list[$category]); + + reset($avatar_list[$category]); + + while ($av_pos < $av_count) + { + $img = current($avatar_list[$category]); + next($avatar_list[$category]); + + if ($col_count == 0) + { + ++$row_count; + $template->assign_block_vars('av_local_row', array( + )); + } + + $template->assign_block_vars('av_local_row.av_local_col', array( + 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'], + 'AVATAR_NAME' => $img['name'], + 'AVATAR_FILE' => $img['filename'], + )); + + $col_count = ($col_count + 1) % $table_cols; + + ++$av_pos; + } + } + + return true; + } + + /** + * @inheritdoc + */ + public function process_form($template, $row, &$error) + { + $avatar_list = $this->get_avatar_list(); + $category = $this->request->variable('av_local_cat', ''); + + $file = $this->request->variable('av_local_file', ''); + if (!isset($avatar_list[$category][urldecode($file)])) + { + $error[] = 'AVATAR_URL_NOT_FOUND'; + return false; + } + + return array( + 'avatar' => $category . '/' . $file, + 'avatar_width' => $avatar_list[$category][urldecode($file)]['width'], + 'avatar_height' => $avatar_list[$category][urldecode($file)]['height'], + ); + } + + /** + * @TODO + */ + private function get_avatar_list() + { + $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list'); + + if (!$avatar_list) + { + $avatar_list = array(); + $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; + + $dh = @opendir($path); + + if ($dh) + { + while (($cat = readdir($dh)) !== false) { + if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) + { + if ($ch = @opendir("$path/$cat")) + { + while (($image = readdir($ch)) !== false) + { + // Match all images in the gallery folder + if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) + { + if (function_exists('getimagesize')) + { + $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); + } + else + { + $dims = array(0, 0); + } + $avatar_list[$cat][$image] = array( + 'file' => rawurlencode($cat) . '/' . rawurlencode($image), + 'filename' => rawurlencode($image), + 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), + 'width' => $dims[0], + 'height' => $dims[1], + ); + } + } + @closedir($ch); + } + } + } + @closedir($dh); + } + + @ksort($avatar_list); + + if ($this->cache != null) + { + $this->cache->put('av_local_list', $avatar_list); + } + } + + return $avatar_list; + } +} diff --git a/phpBB/includes/avatar/driver/core/remote.php b/phpBB/includes/avatar/driver/core/remote.php new file mode 100644 index 0000000000..9f5a58e75a --- /dev/null +++ b/phpBB/includes/avatar/driver/core/remote.php @@ -0,0 +1,163 @@ +config['allow_avatar_remote']) + { + return array( + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } + + /** + * @inheritdoc + */ + public function prepare_form($template, $row, &$error) + { + $template->assign_vars(array( + 'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0), + 'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0), + 'AV_REMOTE_URL' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar']) ? $row['avatar'] : '', + )); + + return true; + } + + /** + * @inheritdoc + */ + public function process_form($template, $row, &$error) + { + $url = $this->request->variable('av_remote_url', ''); + $width = $this->request->variable('av_remote_width', 0); + $height = $this->request->variable('av_remote_height', 0); + + if (!preg_match('#^(http|https|ftp)://#i', $url)) + { + $url = 'http://' . $url; + } + + require_once($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); + + $error = array_merge($error, validate_data(array( + 'url' => $url, + ), array( + 'url' => array('string', true, 5, 255), + ))); + + if (!empty($error)) + { + return false; + } + + // Check if this url looks alright + // This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible + if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $url)) + { + $error[] = 'AVATAR_URL_INVALID'; + return false; + } + + // Make sure getimagesize works... + if (function_exists('getimagesize')) + { + if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) + { + $error[] = 'UNABLE_GET_IMAGE_SIZE'; + return false; + } + + if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0)) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } + + $width = ($width && $height) ? $width : $image_data[0]; + $height = ($width && $height) ? $height : $image_data[1]; + } + + if ($width <= 0 || $height <= 0) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } + + include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); + $types = fileupload::image_types(); + $extension = strtolower(filespec::get_extension($url)); + + if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) + { + if (!isset($types[$image_data[2]])) + { + $error[] = 'UNABLE_GET_IMAGE_SIZE'; + } + else + { + $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension); + } + + return false; + } + + if ($this->config['avatar_max_width'] || $this->config['avatar_max_height']) + { + if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height']) + { + $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height); + return false; + } + } + + if ($this->config['avatar_min_width'] || $this->config['avatar_min_height']) + { + if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height']) + { + $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height); + return false; + } + } + + return array( + 'avatar' => $url, + 'avatar_width' => $width, + 'avatar_height' => $height, + ); + } +} diff --git a/phpBB/includes/avatar/driver/core/upload.php b/phpBB/includes/avatar/driver/core/upload.php new file mode 100644 index 0000000000..d0ce856dbe --- /dev/null +++ b/phpBB/includes/avatar/driver/core/upload.php @@ -0,0 +1,147 @@ +config['allow_avatar_upload']) + { + return array( + 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } + + /** + * @inheritdoc + */ + public function prepare_form($template, $row, &$error) + { + if (!$this->can_upload()) + { + return false; + } + + $template->assign_vars(array( + 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, + 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], + )); + + return true; + } + + /** + * @inheritdoc + */ + public function process_form($template, $row, &$error) + { + if (!$this->can_upload()) + { + return false; + } + + include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); + + $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); + + $url = $this->request->variable('av_upload_url', ''); + + if (!empty($_FILES['av_upload_file']['name'])) + { + $file = $upload->form_upload('av_upload_file'); + } + else + { + $file = $upload->remote_upload($url); + } + + $prefix = $this->config['avatar_salt'] . '_'; + $file->clean_filename('avatar', $prefix, $row['id']); + + $destination = $this->config['avatar_path']; + + // Adjust destination path (no trailing slash) + if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') + { + $destination = substr($destination, 0, -1); + } + + $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); + if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) + { + $destination = ''; + } + + // Move file and overwrite any existing image + $file->move_file($destination, true); + + if (sizeof($file->error)) + { + $file->remove(); + $error = array_merge($error, $file->error); + return false; + } + + return array( + 'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'), + 'avatar_width' => $file->get('width'), + 'avatar_height' => $file->get('height'), + ); + } + + /** + * @inheritdoc + */ + public function delete($row) + { + $ext = substr(strrchr($row['avatar'], '.'), 1); + $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext; + + if (file_exists($filename)) + { + @unlink($filename); + } + + return true; + } + + /** + * @TODO + */ + private function can_upload() + { + return (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')); + } +} diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index 4ac6762140..5cebd1533d 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -119,4 +119,25 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface { return true; } + + /** + * @inheritdoc + **/ + public function is_enabled() + { + $driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this)); + + return $this->config["allow_avatar_$driver"]; + } + + /** + * @inheritdoc + **/ + public function get_template_name() + { + $driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this)); + $template = "ucp_avatar_options_$driver.html"; + + return $template; + } } diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php index d3b764e275..4f1c1f73cf 100644 --- a/phpBB/includes/avatar/driver/interface.php +++ b/phpBB/includes/avatar/driver/interface.php @@ -57,4 +57,14 @@ interface phpbb_avatar_driver_interface * @TODO **/ public function delete($row); + + /** + * @TODO + **/ + public function is_enabled(); + + /** + * @TODO + **/ + public function get_template_name(); } diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php deleted file mode 100644 index a0ef912eae..0000000000 --- a/phpBB/includes/avatar/driver/local.php +++ /dev/null @@ -1,189 +0,0 @@ -config['allow_avatar_local']) - { - return array( - 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - } - - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - $avatar_list = $this->get_avatar_list(); - $category = $this->request->variable('av_local_cat', ''); - - $categories = array_keys($avatar_list); - - foreach ($categories as $cat) - { - if (!empty($avatar_list[$cat])) - { - $template->assign_block_vars('av_local_cats', array( - 'NAME' => $cat, - 'SELECTED' => ($cat == $category), - )); - } - } - - if (!empty($avatar_list[$category])) - { - $template->assign_vars(array( - 'AV_LOCAL_SHOW' => true, - )); - - $table_cols = isset($row['av_gallery_cols']) ? $row['av_gallery_cols'] : 4; - $row_count = $col_count = $av_pos = 0; - $av_count = sizeof($avatar_list[$category]); - - reset($avatar_list[$category]); - - while ($av_pos < $av_count) - { - $img = current($avatar_list[$category]); - next($avatar_list[$category]); - - if ($col_count == 0) - { - ++$row_count; - $template->assign_block_vars('av_local_row', array( - )); - } - - $template->assign_block_vars('av_local_row.av_local_col', array( - 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'], - 'AVATAR_NAME' => $img['name'], - 'AVATAR_FILE' => $img['filename'], - )); - - $col_count = ($col_count + 1) % $table_cols; - - ++$av_pos; - } - } - - return true; - } - - /** - * @inheritdoc - */ - public function process_form($template, $row, &$error) - { - $avatar_list = $this->get_avatar_list(); - $category = $this->request->variable('av_local_cat', ''); - - $file = $this->request->variable('av_local_file', ''); - if (!isset($avatar_list[$category][urldecode($file)])) - { - $error[] = 'AVATAR_URL_NOT_FOUND'; - return false; - } - - return array( - 'avatar' => $category . '/' . $file, - 'avatar_width' => $avatar_list[$category][urldecode($file)]['width'], - 'avatar_height' => $avatar_list[$category][urldecode($file)]['height'], - ); - } - - /** - * @TODO - */ - private function get_avatar_list() - { - $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list'); - - if (!$avatar_list) - { - $avatar_list = array(); - $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; - - $dh = @opendir($path); - - if ($dh) - { - while (($cat = readdir($dh)) !== false) { - if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) - { - if ($ch = @opendir("$path/$cat")) - { - while (($image = readdir($ch)) !== false) - { - // Match all images in the gallery folder - if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) - { - if (function_exists('getimagesize')) - { - $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); - } - else - { - $dims = array(0, 0); - } - $avatar_list[$cat][$image] = array( - 'file' => rawurlencode($cat) . '/' . rawurlencode($image), - 'filename' => rawurlencode($image), - 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), - 'width' => $dims[0], - 'height' => $dims[1], - ); - } - } - @closedir($ch); - } - } - } - @closedir($dh); - } - - @ksort($avatar_list); - - if ($this->cache != null) - { - $this->cache->put('av_local_list', $avatar_list); - } - } - - return $avatar_list; - } -} diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php deleted file mode 100644 index cd0a756428..0000000000 --- a/phpBB/includes/avatar/driver/remote.php +++ /dev/null @@ -1,163 +0,0 @@ -config['allow_avatar_remote']) - { - return array( - 'src' => $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - } - - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - $template->assign_vars(array( - 'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0), - 'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0), - 'AV_REMOTE_URL' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar']) ? $row['avatar'] : '', - )); - - return true; - } - - /** - * @inheritdoc - */ - public function process_form($template, $row, &$error) - { - $url = $this->request->variable('av_remote_url', ''); - $width = $this->request->variable('av_remote_width', 0); - $height = $this->request->variable('av_remote_height', 0); - - if (!preg_match('#^(http|https|ftp)://#i', $url)) - { - $url = 'http://' . $url; - } - - require_once($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); - - $error = array_merge($error, validate_data(array( - 'url' => $url, - ), array( - 'url' => array('string', true, 5, 255), - ))); - - if (!empty($error)) - { - return false; - } - - // Check if this url looks alright - // This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible - if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $url)) - { - $error[] = 'AVATAR_URL_INVALID'; - return false; - } - - // Make sure getimagesize works... - if (function_exists('getimagesize')) - { - if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) - { - $error[] = 'UNABLE_GET_IMAGE_SIZE'; - return false; - } - - if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0)) - { - $error[] = 'AVATAR_NO_SIZE'; - return false; - } - - $width = ($width && $height) ? $width : $image_data[0]; - $height = ($width && $height) ? $height : $image_data[1]; - } - - if ($width <= 0 || $height <= 0) - { - $error[] = 'AVATAR_NO_SIZE'; - return false; - } - - include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); - $types = fileupload::image_types(); - $extension = strtolower(filespec::get_extension($url)); - - if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) - { - if (!isset($types[$image_data[2]])) - { - $error[] = 'UNABLE_GET_IMAGE_SIZE'; - } - else - { - $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension); - } - - return false; - } - - if ($this->config['avatar_max_width'] || $this->config['avatar_max_height']) - { - if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height']) - { - $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height); - return false; - } - } - - if ($this->config['avatar_min_width'] || $this->config['avatar_min_height']) - { - if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height']) - { - $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height); - return false; - } - } - - return array( - 'avatar' => $url, - 'avatar_width' => $width, - 'avatar_height' => $height, - ); - } -} diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php deleted file mode 100644 index d9504c04a0..0000000000 --- a/phpBB/includes/avatar/driver/upload.php +++ /dev/null @@ -1,147 +0,0 @@ -config['allow_avatar_upload']) - { - return array( - 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - } - - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - if (!$this->can_upload()) - { - return false; - } - - $template->assign_vars(array( - 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, - 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], - )); - - return true; - } - - /** - * @inheritdoc - */ - public function process_form($template, $row, &$error) - { - if (!$this->can_upload()) - { - return false; - } - - include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx); - - $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); - - $url = $this->request->variable('av_upload_url', ''); - - if (!empty($_FILES['av_upload_file']['name'])) - { - $file = $upload->form_upload('av_upload_file'); - } - else - { - $file = $upload->remote_upload($url); - } - - $prefix = $this->config['avatar_salt'] . '_'; - $file->clean_filename('avatar', $prefix, $row['id']); - - $destination = $this->config['avatar_path']; - - // Adjust destination path (no trailing slash) - if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') - { - $destination = substr($destination, 0, -1); - } - - $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); - if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) - { - $destination = ''; - } - - // Move file and overwrite any existing image - $file->move_file($destination, true); - - if (sizeof($file->error)) - { - $file->remove(); - $error = array_merge($error, $file->error); - return false; - } - - return array( - 'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'), - 'avatar_width' => $file->get('width'), - 'avatar_height' => $file->get('height'), - ); - } - - /** - * @inheritdoc - */ - public function delete($row) - { - $ext = substr(strrchr($row['avatar'], '.'), 1); - $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext; - - if (file_exists($filename)) - { - @unlink($filename); - } - - return true; - } - - /** - * @TODO - */ - private function can_upload() - { - return (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')); - } -} diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 839216b61e..c2c3dbbbca 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -24,25 +24,27 @@ class phpbb_avatar_manager private $phpEx; private $config; private $request; + private $extension_manager; private $cache; private static $valid_drivers = false; /** * @TODO **/ - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache = null) + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_extension_manager $extension_manager, phpbb_cache_driver_interface $cache = null) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->config = $config; $this->request = $request; + $this->extension_manager = $extension_manager; $this->cache = $cache; } /** * @TODO **/ - public function get_driver($avatar_type, $new = false) + public function get_driver($avatar_type) { if (self::$valid_drivers === false) { @@ -53,30 +55,33 @@ class phpbb_avatar_manager switch ($avatar_type) { case AVATAR_GALLERY: - $avatar_type = 'local'; + $avatar_type = 'phpbb_avatar_driver_local'; break; case AVATAR_UPLOAD: - $avatar_type = 'upload'; + $avatar_type = 'phpbb_avatar_driver_upload'; break; case AVATAR_REMOTE: - $avatar_type = 'remote'; + $avatar_type = 'phpbb_avatar_driver_remote'; break; } - if (isset(self::$valid_drivers[$avatar_type])) - { - if ($new || !is_object(self::$valid_drivers[$avatar_type])) - { - $class_name = 'phpbb_avatar_driver_' . $avatar_type; - self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache); - } - - return self::$valid_drivers[$avatar_type]; - } - else + if (false === array_search($avatar_type, self::$valid_drivers)) { return null; } + + $r = new ReflectionClass($avatar_type); + + if ($r->isSubClassOf('phpbb_avatar_driver')) { + $driver = new $avatar_type($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache); + } else if ($r->implementsInterface('phpbb_avatar_driver')) { + $driver = new $avatar_type(); + } else { + $message = "Invalid avatar driver class name '%s' provided. It must implement phpbb_avatar_driver_interface."; + trigger_error(sprintf($message, $avatar_type)); + } + + return $driver; } /** @@ -93,18 +98,12 @@ class phpbb_avatar_manager { self::$valid_drivers = array(); - $iterator = new DirectoryIterator($this->phpbb_root_path . 'includes/avatar/driver'); - - foreach ($iterator as $file) - { - // Match all files that appear to be php files - if (preg_match("/^(.*)\.{$this->phpEx}$/", $file, $match)) - { - self::$valid_drivers[] = $match[1]; - } - } + $finder = $this->extension_manager->get_finder(); - self::$valid_drivers = array_flip(self::$valid_drivers); + self::$valid_drivers = $finder + ->extension_directory('/avatar/driver/') + ->core_path('includes/avatar/driver/core/') + ->get_classes(); if ($this->cache) { @@ -123,7 +122,7 @@ class phpbb_avatar_manager $this->load_valid_drivers(); } - return array_keys(self::$valid_drivers); + return self::$valid_drivers; } /** diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 6b2133796d..f406e9dc5b 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -623,18 +623,18 @@ class ucp_profile } $focused_driver = request_var('avatar_driver', $user->data['user_avatar_type']); - + foreach ($avatar_drivers as $driver) { - if ($config["allow_avatar_$driver"]) + $avatar = $phpbb_avatar_manager->get_driver($driver); + + if ($avatar->is_enabled()) { $avatars_enabled = true; $template->set_filenames(array( - 'avatar' => "ucp_avatar_options_$driver.html", + 'avatar' => $avatar->get_template_name(), )); - $avatar = $phpbb_avatar_manager->get_driver($driver); - if ($avatar->prepare_form($template, $avatar_data, $error)) { $driver_u = strtoupper($driver); -- cgit v1.2.1 From cf651ef81d611865a06d93c9db7c4dfcd680405c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 17 Mar 2012 23:50:28 +0100 Subject: [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 (limited to 'phpBB') 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(); + } +} -- cgit v1.2.1 From 3fbac076ceb4773aa3c985d24eeaf306aa0b6a42 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 17 Mar 2012 23:52:01 +0100 Subject: [ticket/10714] Use new phpbb_log class in add_log function PHPBB3-10714 --- phpBB/includes/functions.php | 89 ++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 40 deletions(-) (limited to 'phpBB') 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; + + $args = func_get_args(); + $log = (isset($args[0])) ? $args[0] : false; - // 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'])) + 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); - - $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, - ); + // no log class set, create a temporary one ourselves to keep backwards compatability + if ($tmp_log === null) + { + $tmp_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 + $additional_data = array(); switch ($mode) { case 'admin': - $sql_ary['log_type'] = LOG_ADMIN; + case 'critical': break; - case 'mod': - $sql_ary += array( - 'log_type' => LOG_MOD, - 'forum_id' => $forum_id, - 'topic_id' => $topic_id - ); + // forum_id + $additional_data[] = array_shift($args); + // topic_id + $additional_data[] = array_shift($args); break; - case 'user': - $sql_ary += array( - 'log_type' => LOG_USERS, - 'reportee_id' => $reportee_id - ); + // reportee_id + $additional_data[] = array_shift($args); break; - - case 'critical': - $sql_ary['log_type'] = LOG_CRITICAL; - 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); + + global $user; - $db->sql_query('INSERT INTO ' . LOG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); + $user_id = (empty($user->data)) ? ANONYMOUS : $user->data['user_id']; + $user_ip = (empty($user->ip)) ? '' : $user->ip; - return $db->sql_nextid(); + return $tmp_log->add($mode, $user_id, $user_ip, $log_operation, time(), $additional_data); } /** -- cgit v1.2.1 From 34ce2561a0242c9066702e5fa9c92d0a6c77c2d2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 17 Mar 2012 23:52:47 +0100 Subject: [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(-) (limited to 'phpBB') 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(); } } -- cgit v1.2.1 From 87eec7cfb66f6072344680743b04bf0186e8ca17 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 00:07:09 +0100 Subject: [ticket/10714] Create a phpbb_log object and inject it into add_log PHPBB3-10714 --- phpBB/common.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB') 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()); -- cgit v1.2.1 From 1539ad7ebe1493e4c486181f65976c93dbb95c29 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 13:42:08 +0100 Subject: [ticket/10714] Add @return null to doc blocks PHPBB3-10714 --- phpBB/includes/log/interface.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB') 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(); -- cgit v1.2.1 From cff15ec307d76b004b6a825fb51b5dd3c8da58f2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 13:47:24 +0100 Subject: [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(-) (limited to 'phpBB') 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; -- cgit v1.2.1 From b9b08cf765d7feb2865477bb82ab58e8cfb0c156 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 13:54:33 +0100 Subject: [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(+) (limited to 'phpBB') 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() { -- cgit v1.2.1 From 61cbabb120dfca6d924fbb08645f6dfbbcc5c1ec Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 13:59:32 +0100 Subject: [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(-) (limited to 'phpBB') 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)); -- cgit v1.2.1 From a0b35f8e4e94d1301421670cf35406b974510ed0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 21:56:15 +0100 Subject: [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(-) (limited to 'phpBB') 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()) { -- cgit v1.2.1 From 91384d8395166ec21995103410e35f7ba28ac830 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 15:05:02 +0100 Subject: [ticket/10714] Add casts to integer values. PHPBB3-10714 --- phpBB/includes/functions_admin.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'phpBB') 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']; -- cgit v1.2.1 From f5063a6eda49d2a35b2aed486f86cde76e0f04a8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 15:06:13 +0100 Subject: [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(-) (limited to 'phpBB') 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 -- cgit v1.2.1 From 9248b9b25fdc3c05cc9fb1e99f607817f8ec7bcb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 15:06:32 +0100 Subject: [ticket/10714] Add doc block for view_log function PHPBB3-10714 --- phpBB/includes/functions_admin.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'phpBB') 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 = '') { -- cgit v1.2.1 From 55b94af82ecb7e73535bfbed6c278f1d992efecb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 16:27:52 +0100 Subject: [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(+) (limited to 'phpBB') 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; + } } -- cgit v1.2.1 From 97290647fae683ecce842541a682e3403b7717ee Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 16:39:03 +0100 Subject: [ticket/10714] Use phpbb_log class in view_log() PHPBB3-10714 --- phpBB/includes/functions_admin.php | 273 +++---------------------------------- phpBB/includes/log/log.php | 105 +++++++++----- 2 files changed, 85 insertions(+), 293 deletions(-) (limited to 'phpBB') 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; - } - - // 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_lower = $db->sql_lower_text('l.log_data'); - $sql_keywords .= "$sql_lower " . implode(" OR $sql_lower ", $keywords) . ')'; + $static_log = $mode; + return true; } - - if ($log_count !== false) + else if ($mode === 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); + return 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; - } + $tmp_log = $static_log; - if ($log_count) + // no log class set, create a temporary one ourselves to keep backwards compatability + if ($tmp_log === null) { - // Return the user to the last page that is valid - while ($offset >= $log_count) - { - $offset = ($offset - $limit < 0) ? 0 : $offset - $limit; - } + $tmp_log = new phpbb_log(LOG_TABLE); } - $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), + $count_logs = ($log_count !== false); - 'ip' => $row['log_ip'], - 'time' => (int) $row['log_time'], - 'forum_id' => (int) $row['forum_id'], - 'topic_id' => (int) $row['topic_id'], + $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(); - '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; -- cgit v1.2.1 From 325827c40f778ef7efd3c195706cb0b1fb28805b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 16:43:26 +0100 Subject: [ticket/10714] Inject the global $phpbb_log into view_log() PHPBB3-10714 --- phpBB/common.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB') 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']) { -- cgit v1.2.1 From 2c7f498c1b43cfb96f868e9b0f9b80ad5ec626a8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 17:13:17 +0100 Subject: [ticket/10714] Change $phpbb_dispatcher calls to the new layout PHPBB3-10714 --- phpBB/includes/functions.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'phpBB') 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)); } */ } -- cgit v1.2.1 From 3170845a5011ea76af7f4f8359acafb43ad7e19e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 28 Mar 2012 15:48:45 +0200 Subject: [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 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'phpBB') 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 -- cgit v1.2.1 From 0fcbb40a0e1affcfa07a6d51ce273b73b3a95359 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 12:40:55 +0200 Subject: [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(-) (limited to 'phpBB') 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)); -- cgit v1.2.1 From bd6dfee23e0d3f11ff028d4376e73c9c1e770f2a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 13:06:43 +0200 Subject: [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(-) (limited to 'phpBB') 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)) -- cgit v1.2.1 From 0bb4af90a4d9a1fedb254a1b6e9702726cfcf091 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 13:07:11 +0200 Subject: [ticket/10714] Fix core.add_log event PHPBB3-10714 --- phpBB/includes/log/log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') 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. -- cgit v1.2.1 From cf095dd393a6540d092c6308bc03aab824376562 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 13:12:50 +0200 Subject: [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(-) (limited to 'phpBB') 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; -- cgit v1.2.1 From 701052481542cad1ab46fb5e48cf5bbd139030b8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 13:19:13 +0200 Subject: [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(-) (limited to 'phpBB') 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)) { -- cgit v1.2.1 From 151346c6e053e925b5cfcf2845eca532509bbc80 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 13:25:26 +0200 Subject: [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(-) (limited to 'phpBB') 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); -- cgit v1.2.1 From 2afbec5ac425b8913c2d3e3193b195190b7185db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 15:50:46 +0200 Subject: [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(-) (limited to 'phpBB') 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)) { -- cgit v1.2.1 From d289bc13acc0ab0329cac25742ae22560a80c607 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 16:49:08 +0200 Subject: [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(-) (limited to 'phpBB') 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(); } /** -- cgit v1.2.1 From b887fcc3d180860e3b7fdcb2a70e2cd8a519bea2 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 10:49:58 -0500 Subject: [ticket/11103] The start of an all-encompassing notifications system This system will take input from various systems to store notifications and send notifications to users all in one nice extendable system. This system should act something like the notifications system on other social networking sites (in that, there is a single location where a user can see all of their notifications for various events). PHPBB3-11103 --- phpBB/config/services.yml | 5 + phpBB/includes/constants.php | 1 + phpBB/includes/notifications/method/base.php | 51 ++++++ phpBB/includes/notifications/method/email.php | 28 +++ phpBB/includes/notifications/method/interface.php | 24 +++ phpBB/includes/notifications/service.php | 197 ++++++++++++++++++++++ phpBB/includes/notifications/type/base.php | 128 ++++++++++++++ phpBB/includes/notifications/type/interface.php | 31 ++++ phpBB/includes/notifications/type/post.php | 65 +++++++ 9 files changed, 530 insertions(+) create mode 100644 phpBB/includes/notifications/method/base.php create mode 100644 phpBB/includes/notifications/method/email.php create mode 100644 phpBB/includes/notifications/method/interface.php create mode 100644 phpBB/includes/notifications/service.php create mode 100644 phpBB/includes/notifications/type/base.php create mode 100644 phpBB/includes/notifications/type/interface.php create mode 100644 phpBB/includes/notifications/type/post.php (limited to 'phpBB') diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 133a43b77e..b9c697b481 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -89,6 +89,11 @@ services: - .%core.php_ext% - @cache.driver + notifications: + class: phpbb_notifications_service + arguments: + - @container + processor.config: class: phpbb_di_processor_ext arguments: diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 68af41ab20..de289c73dc 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -239,6 +239,7 @@ define('LOG_TABLE', $table_prefix . 'log'); define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts'); define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache'); define('MODULES_TABLE', $table_prefix . 'modules'); +define('NOTIFICATIONS_TABLE', $table_prefix . 'notifications'); define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options'); define('POLL_VOTES_TABLE', $table_prefix . 'poll_votes'); define('POSTS_TABLE', $table_prefix . 'posts'); diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php new file mode 100644 index 0000000000..a70f37db95 --- /dev/null +++ b/phpBB/includes/notifications/method/base.php @@ -0,0 +1,51 @@ +phpbb_container = $phpbb_container; + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + $this->user = $phpbb_container->get('user'); + } +} diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php new file mode 100644 index 0000000000..b06e2c018e --- /dev/null +++ b/phpBB/includes/notifications/method/email.php @@ -0,0 +1,28 @@ +phpbb_container = $phpbb_container; + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + } + + private function get_type_class_name(&$type, $safe = false) + { + if (!$safe) + { + $type = preg_replace('#[^a-z]#', '', $type); + } + + return 'phpbb_notifications_type_' . $type; + } + + /** + * Load the user's notifications + * + * @param array $options Optional options to control what notifications are loaded + * user_id User id to load notifications for (Default: $user->data['user_id']) + * limit Number of notifications to load (Default: 5) + * start Notifications offset (Default: 0) + */ + public function load_notifications($options = array()) + { + $user = $this->phpbb_container->get('user'); + + // Merge default options + $options = array_merge(array( + 'user_id' => $user->data['user_id'], + 'limit' => 5, + 'start' => 0, + ), $options); + + $notifications = $user_ids = array(); + + $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id']; + $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); + + while ($row = $this->db->sql_fetchrow($result)) + { + $type_class_name = $this->get_type_class_name($row['type'], true); + + $notification = new $type_class_name($this->phpbb_container, $row); + $notification->users($this->users); + + $user_ids = array_merge($user_ids, $notification->users_to_query()); + + $notifications[] = $notification(); + } + $this->db->sql_freeresult($result); + + // Load the users + $user_ids = array_unique($user_ids); + + // @todo do not load users we already have in $this->users + + if (sizeof($user_ids)) + { + // @todo do not select everything + $sql = 'SELECT * FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + } + + return $notifications; + } + + public function add_notifications($type, $data) + { + $type_class_name = $this->get_type_class_name($type); + + $notification_objects = array(); // 'user_id' => object + $methods = $new_rows = array(); + + // find out which users want to receive this type of notification + $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', array(2)); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $row['method'] = ''; + + $notification = new $type_class_name($this->phpbb_container); + + $notification->user_id = $row['user_id']; + + $new_rows[] = $notification->create_insert_array($data); + + // setup the notification methods and add the notification to the queue + if ($row['method']) + { + if (!isset($methods[$row['method']])) + { + $method_class_name = 'phpbb_notifications_method_' . $row['method']; + $methods[$row['method']] = new $$method_class_name(); + } + + $methods[$row['method']]->add_to_queue($notification); + } + } + + // insert into the db + $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); + + // run the queue for each method to send notifications + foreach ($methods as $method) + { + $method->run_queue(); + } + } + + public function update_notifications($type, $type_id, $data) + { + $type_class_name = $this->get_type_class_name($type); + + $object = new $$type_class($this->phpbb_container); + $update = $object->update($data); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $update) . " + WHERE type = '" . $this->db->sql_escape($type) . "' + AND type_id = " . (int) $type_id; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $object = new $type_class_name($this->phpbb_container, $row); + $object->update($data); + + $update_rows[] = $object->getForUpdate(); + } + } +} diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php new file mode 100644 index 0000000000..959516fd19 --- /dev/null +++ b/phpBB/includes/notifications/type/base.php @@ -0,0 +1,128 @@ +phpbb_container = $phpbb_container; + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); + $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + + // The row from the database (unless this is a new notification we're going to add) + $this->data = $data; + $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); + } + + public function __get($name) + { + return $this->data[$name]; + } + + public function __set($name, $value) + { + $this->data[$name] = $value; + } + + public function get_data($name) + { + return $this->data['data'][$name]; + } + + public function set_data($name, $value) + { + $this->data['data'][$name] = $value; + } + + public function users(&$users) + { + $this->users = $users; + } + + /** + * Output the notification to the template + * + * @param array $options Array of options + * template_block Template block name to output to (Default: notifications) + */ + public function display($options = array()) + { + $template = $this->phpbb_container->get('template'); + $user = $this->phpbb_container->get('user'); + + // Merge default options + $options = array_merge(array( + 'template_block' => 'notifications', + ), $options); + + $template->assign_block_vars($options['template_block'], array( + 'TITLE' => $this->get_title(), + 'URL' => $this->get_url(), + 'TIME' => $user->format_date($this->time), + + 'ID' => $this->notification_id, + 'UNREAD' => $this->unread, + )); + } + + public function create_insert_array($data) + { + // Defaults + $data = array_merge(array( + 'item_type' => $this->get_type(), + 'time' => time(), + 'unread' => true, + + 'data' => array(), + ), $this->data); + + $data['data'] = serialize($data['data']); + + return $data; + } +} diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php new file mode 100644 index 0000000000..ace5ca67da --- /dev/null +++ b/phpBB/includes/notifications/type/interface.php @@ -0,0 +1,31 @@ +data['post_username'] . ' posted in the topic ' . censor_text($this->data['topic_title']); + } + + public function get_url() + { + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['poster_id']); + } + + public function create_insert_array($post) + { + $this->item_id = $post['post_id']; + + $this->set_data('poster_id', $post['poster_id']); + + $this->set_data('topic_title', $post['topic_title']); + + $this->set_data('post_username', $post['post_username']); + + return parent::create_insert_array($post); + } +} -- cgit v1.2.1 From 44f07df96fbf933bc20166a516bf0eecee00df4c Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 11:40:02 -0500 Subject: [ticket/11103] Working on the add/update notifications functions Some cleanup and additional commenting as well PHPBB3-11103 --- phpBB/includes/notifications/method/base.php | 18 +---- phpBB/includes/notifications/service.php | 100 +++++++++++++++--------- phpBB/includes/notifications/type/base.php | 66 ++++++++++++++-- phpBB/includes/notifications/type/interface.php | 2 +- phpBB/includes/notifications/type/post.php | 20 +++++ 5 files changed, 146 insertions(+), 60 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index a70f37db95..1c223df045 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ @@ -25,21 +27,7 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me protected $db; protected $user; - /** - * notification_id - * item_type - * item_id - * - * by_user_id (one who caused the notification) - * user_id - * time - * unread - * - * data (special serialized field that each notification type can use to store stuff) - */ - protected $data = array(); - - public function __construct(Symfony\Component\DependencyInjection\ContainerBuilder $phpbb_container, $data = array()) + public function __construct(ContainerBuilder $phpbb_container, $data = array()) { // phpBB Container $this->phpbb_container = $phpbb_container; diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 8f5d559867..fd2c51a330 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ @@ -50,7 +52,7 @@ class phpbb_notifications_service * sms? */ - public function __construct(Symfony\Component\DependencyInjection\ContainerBuilder $phpbb_container) + public function __construct(ContainerBuilder $phpbb_container) { $this->phpbb_container = $phpbb_container; @@ -58,23 +60,13 @@ class phpbb_notifications_service $this->db = $phpbb_container->get('dbal.conn'); } - private function get_type_class_name(&$type, $safe = false) - { - if (!$safe) - { - $type = preg_replace('#[^a-z]#', '', $type); - } - - return 'phpbb_notifications_type_' . $type; - } - /** * Load the user's notifications * * @param array $options Optional options to control what notifications are loaded - * user_id User id to load notifications for (Default: $user->data['user_id']) - * limit Number of notifications to load (Default: 5) - * start Notifications offset (Default: 0) + * user_id User id to load notifications for (Default: $user->data['user_id']) + * limit Number of notifications to load (Default: 5) + * start Notifications offset (Default: 0) */ public function load_notifications($options = array()) { @@ -128,38 +120,58 @@ class phpbb_notifications_service return $notifications; } + /** + * Add a notification + * + * @param string $type Type identifier + * @param int $type_id Identifier within the type + * @param array $data Data specific for this type that will be inserted + */ public function add_notifications($type, $data) { $type_class_name = $this->get_type_class_name($type); - $notification_objects = array(); // 'user_id' => object - $methods = $new_rows = array(); + $notify_users = array(); + $notification_objects = $notification_methods = array(); + $new_rows = array(); // find out which users want to receive this type of notification $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' WHERE ' . $this->db->sql_in_set('user_id', array(2)); $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) { - $row['method'] = ''; + if (!isset($notify_users[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = ''; + } + $this->db->sql_freeresult($result); + // Go through each user so we can insert a row in the DB and then notify them by their desired means + foreach ($notify_users as $user => $methods) + { $notification = new $type_class_name($this->phpbb_container); - $notification->user_id = $row['user_id']; + $notification->user_id = (int) $user; $new_rows[] = $notification->create_insert_array($data); - // setup the notification methods and add the notification to the queue - if ($row['method']) + foreach ($methods as $method) { - if (!isset($methods[$row['method']])) + // setup the notification methods and add the notification to the queue + if ($row['method']) { - $method_class_name = 'phpbb_notifications_method_' . $row['method']; - $methods[$row['method']] = new $$method_class_name(); - } + if (!isset($notification_methods[$row['method']])) + { + $method_class_name = 'phpbb_notifications_method_' . $row['method']; + $notification_methods[$row['method']] = new $method_class_name(); + } - $methods[$row['method']]->add_to_queue($notification); + $notification_methods[$row['method']]->add_to_queue($notification); + } } } @@ -167,31 +179,43 @@ class phpbb_notifications_service $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); // run the queue for each method to send notifications - foreach ($methods as $method) + foreach ($notification_methods as $method) { $method->run_queue(); } } + /** + * Update a notification + * + * @param string $type Type identifier + * @param int $type_id Identifier within the type + * @param array $data Data specific for this type that will be updated + */ public function update_notifications($type, $type_id, $data) { $type_class_name = $this->get_type_class_name($type); - $object = new $$type_class($this->phpbb_container); - $update = $object->update($data); + $notification = new $type_class_name($this->phpbb_container); + $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $update) . " - WHERE type = '" . $this->db->sql_escape($type) . "' - AND type_id = " . (int) $type_id; - $result = $this->db->sql_query($sql); + SET ' . $this->db->sql_build_array('UPDATE', $update_array) . " + WHERE item_type = '" . $this->db->sql_escape($type) . "' + AND item_id = " . (int) $type_id; + $this->db->sql_query($sql); + } - while ($row = $this->db->sql_fetchrow($result)) + /** + * Helper to get the notifications type class name and clean it if unsafe + */ + private function get_type_class_name(&$type, $safe = false) + { + if (!$safe) { - $object = new $type_class_name($this->phpbb_container, $row); - $object->update($data); - - $update_rows[] = $object->getForUpdate(); + $type = preg_replace('#[^a-z]#', '', $type); } + + return 'phpbb_notifications_type_' . $type; } } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 959516fd19..2b194557e3 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ @@ -26,7 +28,12 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type protected $phpbb_root_path; protected $php_ext; - protected $users; + /** + * Array of user data containing information needed to output the notifications to the template + * + * @var array + */ + protected $users = array(); /** * Indentification data @@ -40,11 +47,11 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * data (special serialized field that each notification type can use to store stuff) * * @var array $data Notification row from the database - * This must be private, all interaction should use __get(), __set() + * This must be private, all interaction should use __get(), __set(), get_data(), set_data() */ private $data = array(); - public function __construct(Symfony\Component\DependencyInjection\ContainerBuilder $phpbb_container, $data = array()) + public function __construct(ContainerBuilder $phpbb_container, $data = array()) { // phpBB Container $this->phpbb_container = $phpbb_container; @@ -69,16 +76,33 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type $this->data[$name] = $value; } - public function get_data($name) + /** + * Get special data (only important for the classes that extend this) + * + * @param string $name Name of the variable to get + * + * @return mixed + */ + protected function get_data($name) { return $this->data['data'][$name]; } - public function set_data($name, $value) + /** + * Set special data (only important for the classes that extend this) + * + * @param string $name Name of the variable to set + * @param mixed $value Value to set to the variable + */ + protected function set_data($name, $value) { $this->data['data'][$name] = $value; } + /** + * Function to store the users loaded from the database (for output to the template) + * (The service handles this) + */ public function users(&$users) { $this->users = $users; @@ -110,7 +134,15 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type )); } - public function create_insert_array($data) + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $special_data Data unique to this notification type + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($special_data) { // Defaults $data = array_merge(array( @@ -125,4 +157,26 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $data; } + + /** + * Function for preparing the data for update in an SQL query + * (The service handles insertion) + * + * @param array $special_data Data unique to this notification type + * + * @return array Array of data ready to be updated in the database + */ + public function create_update_array($special_data) + { + $data = $this->create_insert_array($special_data); + + // Unset data unique to each row + unset( + $data['notification_id'], + $data['unread'], + $data['user_id'] + ); + + return $data; + } } diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index ace5ca67da..57de755c82 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -27,5 +27,5 @@ interface phpbb_notifications_type_interface public function get_url(); - public function create_insert_array($data); + public function create_insert_array($special_data); } diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index eb8d92c79c..08da7a77cb 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -30,11 +30,21 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return 'post'; } + /** + * Get the title of this notification + * + * @return string + */ public function get_title() { return $this->data['post_username'] . ' posted in the topic ' . censor_text($this->data['topic_title']); } + /** + * Get the url to this item + * + * @return string URL + */ public function get_url() { return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); @@ -50,6 +60,14 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return array($this->data['poster_id']); } + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ public function create_insert_array($post) { $this->item_id = $post['post_id']; @@ -60,6 +78,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('post_username', $post['post_username']); + $this->time = $post['post_time']; + return parent::create_insert_array($post); } } -- cgit v1.2.1 From e45fb0025ec8c27147caee7e3c14902f2e3f02c5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 12:05:55 -0500 Subject: [ticket/11103] Output the notifications to the template For now, just dumping the notifications in the header. PHPBB3-11103 --- phpBB/common.php | 3 +++ phpBB/includes/functions.php | 9 ++++++++- phpBB/includes/notifications/service.php | 4 ++-- phpBB/includes/notifications/type/base.php | 15 +++++++++++++-- phpBB/includes/notifications/type/post.php | 13 ++++++++++++- phpBB/styles/prosilver/template/overall_header.html | 7 +++++++ 6 files changed, 45 insertions(+), 6 deletions(-) (limited to 'phpBB') diff --git a/phpBB/common.php b/phpBB/common.php index 281eb88c4d..52879deb9c 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -146,6 +146,9 @@ if (!$config['use_system_cron']) $cron = $phpbb_container->get('cron.manager'); } +// Load notifications +$phpbb_notifications = $phpbb_container->get('notifications'); + /** * Main event which is triggered on every page * diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 834f57a38b..7632ea1fcb 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4778,7 +4778,7 @@ function phpbb_http_login($param) function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; - global $phpbb_dispatcher; + global $phpbb_dispatcher, $phpbb_container; if (defined('HEADER_INC')) { @@ -5092,6 +5092,13 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); + // Output the notifications + $phpbb_notifications = $phpbb_container->get('notifications'); + foreach ($phpbb_notifications->load_notifications() as $notification) + { + $notification->display(); + } + // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index fd2c51a330..8db414cb16 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -87,14 +87,14 @@ class phpbb_notifications_service while ($row = $this->db->sql_fetchrow($result)) { - $type_class_name = $this->get_type_class_name($row['type'], true); + $type_class_name = $this->get_type_class_name($row['item_type'], true); $notification = new $type_class_name($this->phpbb_container, $row); $notification->users($this->users); $user_ids = array_merge($user_ids, $notification->users_to_query()); - $notifications[] = $notification(); + $notifications[] = $notification; } $this->db->sql_freeresult($result); diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 2b194557e3..1b01e1d46c 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -85,7 +85,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type */ protected function get_data($name) { - return $this->data['data'][$name]; + return (isset($this->data['data'][$name])) ? $this->data['data'][$name] : null; } /** @@ -105,7 +105,18 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type */ public function users(&$users) { - $this->users = $users; + $this->users = &$users; + } + + /** + * Get a user row from our users cache + * + * @param int $user_id + * @return array + */ + protected function get_user($user_id) + { + return $this->users[$user_id]; } /** diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 08da7a77cb..4b343650a1 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -37,7 +37,18 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base */ public function get_title() { - return $this->data['post_username'] . ' posted in the topic ' . censor_text($this->data['topic_title']); + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->get_user($this->get_data('poster_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + + return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title')); } /** diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index 43ae83767d..77fdb230ad 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -166,3 +166,10 @@ + + +

+ {notifications.TITLE}
+ {notifications.TIME} +

+ \ No newline at end of file -- cgit v1.2.1 From 32a966b21da7051def3bd2ae608f3f2457d22476 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 12:28:58 -0500 Subject: [ticket/11103] Private Message type notification Also cleanup PHPBB3-11103 --- phpBB/includes/notifications/service.php | 68 ++++++++++++----- phpBB/includes/notifications/type/base.php | 2 +- phpBB/includes/notifications/type/interface.php | 4 +- phpBB/includes/notifications/type/pm.php | 97 +++++++++++++++++++++++++ phpBB/includes/notifications/type/post.php | 12 ++- 5 files changed, 162 insertions(+), 21 deletions(-) create mode 100644 phpBB/includes/notifications/type/pm.php (limited to 'phpBB') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 8db414cb16..059c2b420d 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -87,9 +87,9 @@ class phpbb_notifications_service while ($row = $this->db->sql_fetchrow($result)) { - $type_class_name = $this->get_type_class_name($row['item_type'], true); + $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); - $notification = new $type_class_name($this->phpbb_container, $row); + $notification = new $item_type_class_name($this->phpbb_container, $row); $notification->users($this->users); $user_ids = array_merge($user_ids, $notification->users_to_query()); @@ -123,13 +123,18 @@ class phpbb_notifications_service /** * Add a notification * - * @param string $type Type identifier - * @param int $type_id Identifier within the type + * @param string $item_type Type identifier + * @param int $item_id Identifier within the type * @param array $data Data specific for this type that will be inserted */ - public function add_notifications($type, $data) + public function add_notifications($item_type, $data) { - $type_class_name = $this->get_type_class_name($type); + $item_type_class_name = $this->get_item_type_class_name($item_type); + + $item_id = $item_type_class_name::get_item_id($data); + + // Update any existing notifications for this item + $this->update_notifications($item_type, $item_id, $data); $notify_users = array(); $notification_objects = $notification_methods = array(); @@ -150,10 +155,22 @@ class phpbb_notifications_service } $this->db->sql_freeresult($result); + // Make sure not to send new notifications to users who've already been notified about this item + // This may happen when an item was added, but now new users are able to see the item + $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + unset($notify_users[$row['user_id']]); + } + $this->db->sql_freeresult($result); + // Go through each user so we can insert a row in the DB and then notify them by their desired means foreach ($notify_users as $user => $methods) { - $notification = new $type_class_name($this->phpbb_container); + $notification = new $item_type_class_name($this->phpbb_container); $notification->user_id = (int) $user; @@ -188,34 +205,49 @@ class phpbb_notifications_service /** * Update a notification * - * @param string $type Type identifier - * @param int $type_id Identifier within the type + * @param string $item_type Type identifier + * @param int $item_id Identifier within the type * @param array $data Data specific for this type that will be updated */ - public function update_notifications($type, $type_id, $data) + public function update_notifications($item_type, $item_id, $data) { - $type_class_name = $this->get_type_class_name($type); + $item_type_class_name = $this->get_item_type_class_name($item_type); - $notification = new $type_class_name($this->phpbb_container); + $notification = new $item_type_class_name($this->phpbb_container); $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $update_array) . " - WHERE item_type = '" . $this->db->sql_escape($type) . "' - AND item_id = " . (int) $type_id; + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; + $this->db->sql_query($sql); + } + + /** + * Delete a notification + * + * @param string $item_type Type identifier + * @param int $item_id Identifier within the type + * @param array $data Data specific for this type that will be updated + */ + public function delete_notifications($item_type, $item_id) + { + $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; $this->db->sql_query($sql); } /** - * Helper to get the notifications type class name and clean it if unsafe + * Helper to get the notifications item type class name and clean it if unsafe */ - private function get_type_class_name(&$type, $safe = false) + private function get_item_type_class_name(&$item_type, $safe = false) { if (!$safe) { - $type = preg_replace('#[^a-z]#', '', $type); + $item_type = preg_replace('#[^a-z]#', '', $item_type); } - return 'phpbb_notifications_type_' . $type; + return 'phpbb_notifications_type_' . $item_type; } } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 1b01e1d46c..89143873a8 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -157,7 +157,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type { // Defaults $data = array_merge(array( - 'item_type' => $this->get_type(), + 'item_type' => $this->get_item_type(), 'time' => time(), 'unread' => true, diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index 57de755c82..b1ee9ae0b6 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -21,7 +21,9 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notifications_type_interface { - public function get_type(); + public static function get_item_type(); + + public static function get_item_id($post); public function get_title(); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php new file mode 100644 index 0000000000..f86050486e --- /dev/null +++ b/phpBB/includes/notifications/type/pm.php @@ -0,0 +1,97 @@ +get_user($this->get_data('author_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + return $username . ' sent you a private message titled: ' . $this->get_data('message_subject'); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['author_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->item_id = $post['msg_id']; + + $this->set_data('author_id', $post['author_id']); + + $this->set_data('message_subject', $post['message_subject']); + + $this->time = $post['message_time']; + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 4b343650a1..9bd343d288 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -25,11 +25,21 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base * Get the type of notification this is * phpbb_notifications_type_ */ - public function get_type() + public static function get_item_type() { return 'post'; } + /** + * Get the id of the + * + * @param array $post The data from the post + */ + public static function get_item_id($post) + { + return $post['post_id']; + } + /** * Get the title of this notification * -- cgit v1.2.1 From b59463552644ca4afd9e8ca7edd761ae382fc8ed Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 13:09:34 -0500 Subject: [ticket/11103] Add tables to the database updater and installer PHPBB3-11103 --- phpBB/develop/create_schema_files.php | 41 ++++++++++++++++++++ phpBB/includes/notifications/method/base.php | 32 +++++++++++++++ phpBB/includes/notifications/method/interface.php | 1 + phpBB/includes/notifications/service.php | 38 +++++++++--------- phpBB/install/database_update.php | 47 +++++++++++++++++++++++ 5 files changed, 140 insertions(+), 19 deletions(-) (limited to 'phpBB') diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 6eb4a80199..88aa9b70dd 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1295,6 +1295,28 @@ function get_schema_struct() ), ); + $schema_data['phpbb_notifications'] = array( + 'COLUMNS' => array( + 'item_type' => array('UINT', 0), + 'item_id' => array('UINT', 0), + 'user_id' => array('UINT', 0), + 'unread' => array('BOOL', 1), + 'time' => array('TIMESTAMP', 1), + 'data' => array('TEXT_UNI', ''), + ), + 'PRIMARY_KEY' => array( + 'item_type', + 'item_id', + 'user_id', + ), + 'KEYS' => array( + 'item_type' => array('INDEX', 'item_type'), + 'item_id' => array('INDEX', 'item_id'), + 'user_id' => array('INDEX', 'user_id'), + 'time' => array('INDEX', 'time'), + ), + ); + $schema_data['phpbb_poll_options'] = array( 'COLUMNS' => array( 'poll_option_id' => array('TINT:4', 0), @@ -1751,6 +1773,25 @@ function get_schema_struct() ), ); + $schema_data['phpbb_user_notifications'] = array( + 'COLUMNS' => array( + 'item_type' => array('UINT', 0), + 'item_id' => array('UINT', 0), + 'user_id' => array('UINT', 0), + 'method' => array('VCHAR:25', ''), + ), + 'PRIMARY_KEY' => array( + 'item_type', + 'item_id', + 'user_id', + 'method', + ), + 'KEYS' => array( + 'it' => array('INDEX', 'item_type'), + 'uid' => array('INDEX', 'user_id'), + ), + ); + $schema_data['phpbb_user_group'] = array( 'COLUMNS' => array( 'group_id' => array('UINT', 0), diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index 1c223df045..dbf851a059 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -27,6 +27,13 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me protected $db; protected $user; + /** + * Queue of messages to be sent + * + * @var array + */ + protected $queue = array(); + public function __construct(ContainerBuilder $phpbb_container, $data = array()) { // phpBB Container @@ -36,4 +43,29 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me $this->db = $phpbb_container->get('dbal.conn'); $this->user = $phpbb_container->get('user'); } + + /** + * Add a notification to the queue + * + * @param phpbb_notifications_type_interface $notification + */ + public function add_to_queue(phpbb_notifications_type_interface $notification) + { + $this->queue[] = $notification; + } + + /** + * Basic run queue function. + * Child methods should override this function if there are more efficient methods to mass-notification + */ + public function run_queue() + { + foreach ($this->queue as $notification) + { + $this->notify($notification); + } + + // Empty queue + $this->queue = array(); + } } diff --git a/phpBB/includes/notifications/method/interface.php b/phpBB/includes/notifications/method/interface.php index 2d8a8b605e..f18d005b8b 100644 --- a/phpBB/includes/notifications/method/interface.php +++ b/phpBB/includes/notifications/method/interface.php @@ -21,4 +21,5 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notifications_method_interface { + public function notify($notification); } diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 059c2b420d..32211b26cf 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -33,25 +33,6 @@ class phpbb_notifications_service */ protected $users; - /** - * Desired notifications - * unique by (type, type_id, user_id, method) - * if multiple methods are desired, multiple rows will exist. - * - * method of "none" will over-ride any other options - * - * type - * type_id - * user_id - * method - * none (will never receive notifications) - * standard (listed in notifications window - * popup? - * email - * jabber - * sms? - */ - public function __construct(ContainerBuilder $phpbb_container) { $this->phpbb_container = $phpbb_container; @@ -140,6 +121,25 @@ class phpbb_notifications_service $notification_objects = $notification_methods = array(); $new_rows = array(); + /** + * Desired notifications + * unique by (type, type_id, user_id, method) + * if multiple methods are desired, multiple rows will exist. + * + * method of "none" will over-ride any other options + * + * item_type + * item_id + * user_id + * method + * none (will never receive notifications) + * standard (listed in notifications window + * popup? + * email + * jabber + * sms? + */ + // find out which users want to receive this type of notification $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' WHERE ' . $this->db->sql_in_set('user_id', array(2)); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 0b470ced26..99e40ddee9 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -106,6 +106,14 @@ if (!defined('EXT_TABLE')) { define('EXT_TABLE', $table_prefix . 'ext'); } +if (!defined('NOTIFICATIONS_TABLE')) +{ + define('NOTIFICATIONS_TABLE', $table_prefix . 'notifications'); +} +if (!defined('USER_NOTIFICATIONS_TABLE')) +{ + define('USER_NOTIFICATIONS_TABLE', $table_prefix . 'user_notifications'); +} $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".$phpEx"); $phpbb_class_loader_ext->register(); @@ -1097,6 +1105,45 @@ function database_update_info() 'ext_name' => array('UNIQUE', 'ext_name'), ), ), + NOTIFICATIONS_TABLE => array( + 'COLUMNS' => array( + 'item_type' => array('UINT', 0), + 'item_id' => array('UINT', 0), + 'user_id' => array('UINT', 0), + 'unread' => array('BOOL', 1), + 'time' => array('TIMESTAMP', 1), + 'data' => array('TEXT_UNI', ''), + ), + 'PRIMARY_KEY' => array( + 'item_type', + 'item_id', + 'user_id', + ), + 'KEYS' => array( + 'item_type' => array('INDEX', 'item_type'), + 'item_id' => array('INDEX', 'item_id'), + 'user_id' => array('INDEX', 'user_id'), + 'time' => array('INDEX', 'time'), + ), + ), + USER_NOTIFICATIONS_TABLE => array( + 'COLUMNS' => array( + 'item_type' => array('UINT', 0), + 'item_id' => array('UINT', 0), + 'user_id' => array('UINT', 0), + 'method' => array('VCHAR:25', ''), + ), + 'PRIMARY_KEY' => array( + 'item_type', + 'item_id', + 'user_id', + 'method', + ), + 'KEYS' => array( + 'it' => array('INDEX', 'item_type'), + 'uid' => array('INDEX', 'user_id'), + ), + ), ), 'add_columns' => array( GROUPS_TABLE => array( -- cgit v1.2.1 From 7b0b6fc63c2593cafaa84cc38a9b3029af1ed369 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 13:40:05 -0500 Subject: [ticket/11103] Forgot a constant PHPBB3-11103 --- phpBB/includes/constants.php | 1 + phpBB/includes/notifications/method/email.php | 10 +++++++++- phpBB/includes/notifications/type/pm.php | 2 ++ phpBB/includes/notifications/type/post.php | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index de289c73dc..7a3c73e987 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -273,6 +273,7 @@ define('TOPICS_POSTED_TABLE', $table_prefix . 'topics_posted'); define('TOPICS_TRACK_TABLE', $table_prefix . 'topics_track'); define('TOPICS_WATCH_TABLE', $table_prefix . 'topics_watch'); define('USER_GROUP_TABLE', $table_prefix . 'user_group'); +define('USER_NOTIFICATIONS_TABLE', $table_prefix . 'user_notifications'); define('USERS_TABLE', $table_prefix . 'users'); define('WARNINGS_TABLE', $table_prefix . 'warnings'); define('WORDS_TABLE', $table_prefix . 'words'); diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index b06e2c018e..0c3cb4bd85 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -17,11 +17,19 @@ if (!defined('IN_PHPBB')) /** * Email notification method class +* This class handles sending emails for notifications +* * @package notifications */ class phpbb_notifications_method_email extends phpbb_notifications_method_base { - function notify() + public static function is_available() + { + // Email is always available + return true; + } + + public function notify() { // email the user } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index f86050486e..191c0b7e7f 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -17,6 +17,8 @@ if (!defined('IN_PHPBB')) /** * Private message notifications class +* This class handles notifications for private messages +* * @package notifications */ class phpbb_notifications_type_pm extends phpbb_notifications_type_base diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 9bd343d288..addaa30ea6 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -17,6 +17,8 @@ if (!defined('IN_PHPBB')) /** * Post notifications class +* This class handles notifications for replies to a topic +* * @package notifications */ class phpbb_notifications_type_post extends phpbb_notifications_type_base -- cgit v1.2.1 From 7fee0cfdf60c9aeebcd498d2f41696bb7fed2dd0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 15:48:46 -0500 Subject: [ticket/11103] Work on the pm type and email method PHPBB3-11103 --- phpBB/includes/functions_privmsgs.php | 13 +++++ phpBB/includes/notifications/method/base.php | 11 +++- phpBB/includes/notifications/method/email.php | 61 ++++++++++++++++++++++ phpBB/includes/notifications/service.php | 14 +---- phpBB/includes/notifications/type/base.php | 13 ++--- phpBB/includes/notifications/type/interface.php | 6 ++- phpBB/includes/notifications/type/pm.php | 69 ++++++++++++++++++++++--- 7 files changed, 159 insertions(+), 28 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 9e055a319f..99ad2ad791 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1855,6 +1855,19 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) */ function pm_notification($mode, $author, $recipients, $subject, $message, $msg_id) { + global $phpbb_container; + + $phpbb_notifications = $phpbb_container->get('notifications'); + + $phpbb_notifications->add_notifications('pm', array( + 'author_id' => $author, + 'recipients' => $recipients, + 'message_subject' => $subject, + 'msg_id' => $msg_id, + )); + + return; + global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; $subject = censor_text($subject); diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index dbf851a059..98c06509c6 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -26,6 +26,8 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me protected $phpbb_container; protected $db; protected $user; + protected $phpbb_root_path; + protected $php_ext; /** * Queue of messages to be sent @@ -42,6 +44,9 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me // Some common things we're going to use $this->db = $phpbb_container->get('dbal.conn'); $this->user = $phpbb_container->get('user'); + + $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); + $this->php_ext = $phpbb_container->getParameter('core.php_ext'); } /** @@ -65,7 +70,11 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me $this->notify($notification); } - // Empty queue + $this->empty_queue(); + } + + protected function empty_queue() + { $this->queue = array(); } } diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 0c3cb4bd85..725ede7913 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -33,4 +33,65 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base { // email the user } + + public function run_queue() + { + if (!sizeof($this->queue)) + { + return; + } + + // Load all users we want to notify (we need their email address) + $user_ids = $users = array(); + foreach ($this->queue as $notification) + { + $user_ids[] = $notification->user_id; + } + + $sql = 'SELECT * FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + + // Load the messenger + if (!class_exists('messenger')) + { + include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); + } + $messenger = new messenger(); + $board_url = generate_board_url(); + + // Time to go through the queue and send emails + foreach ($this->queue as $notification) + { + $notification->users($users); + + $user = $notification->get_user(); + + $messenger->template('privmsg_notify', $user['user_lang']); + + $messenger->to($user['user_email'], $user['username']); + + $messenger->assign_vars(array( + 'SUBJECT' => htmlspecialchars_decode($notification->get_title()), + 'AUTHOR_NAME' => '', + 'USERNAME' => htmlspecialchars_decode($user['username']), + + 'U_INBOX' => $board_url . "/ucp.{$this->php_ext}?i=pm&folder=inbox", + 'U_VIEW_MESSAGE' => $board_url . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$notification->get_item_id()}", + )); + + $messenger->send($addr['method']); + } + + // Save the queue in the messenger class (has to be called or these emails could be lost?) + $messenger->save_queue(); + + // We're done, empty the queue + $this->empty_queue(); + } } diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 32211b26cf..ba57fe9f72 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -141,19 +141,7 @@ class phpbb_notifications_service */ // find out which users want to receive this type of notification - $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' - WHERE ' . $this->db->sql_in_set('user_id', array(2)); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (!isset($notify_users[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = ''; - } - $this->db->sql_freeresult($result); + $notify_users = $item_type_class_name::find_users_for_notification($data); // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 89143873a8..f031abae77 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -58,6 +58,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type // Some common things we're going to use $this->db = $phpbb_container->get('dbal.conn'); + $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); $this->php_ext = $phpbb_container->getParameter('core.php_ext'); @@ -114,7 +115,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * @param int $user_id * @return array */ - protected function get_user($user_id) + public function get_user($user_id) { return $this->users[$user_id]; } @@ -149,11 +150,11 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * Function for preparing the data for insertion in an SQL query * (The service handles insertion) * - * @param array $special_data Data unique to this notification type + * @param array $type_data Data unique to this notification type * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($special_data) + public function create_insert_array($type_data) { // Defaults $data = array_merge(array( @@ -173,13 +174,13 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * Function for preparing the data for update in an SQL query * (The service handles insertion) * - * @param array $special_data Data unique to this notification type + * @param array $type_data Data unique to this notification type * * @return array Array of data ready to be updated in the database */ - public function create_update_array($special_data) + public function create_update_array($type_data) { - $data = $this->create_insert_array($special_data); + $data = $this->create_insert_array($type_data); // Unset data unique to each row unset( diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index b1ee9ae0b6..b710a75606 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -23,11 +23,13 @@ interface phpbb_notifications_type_interface { public static function get_item_type(); - public static function get_item_id($post); + public static function get_item_id($type_data); public function get_title(); public function get_url(); - public function create_insert_array($special_data); + public function create_insert_array($type_data); + + public function find_users_for_notification($type_data); } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 191c0b7e7f..7685a49614 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -84,16 +84,73 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($pm) { - $this->item_id = $post['msg_id']; + $this->item_id = $pm['msg_id']; - $this->set_data('author_id', $post['author_id']); + $this->set_data('author_id', $pm['author_id']); - $this->set_data('message_subject', $post['message_subject']); + $this->set_data('message_subject', $pm['message_subject']); - $this->time = $post['message_time']; + return parent::create_insert_array($pm); + } + + /** + * Find the users who want to receive notifications + * + * @param array $pm Data from + * @return array + */ + public function find_users_for_notification($pm) + { + $user = $this->phpbb_container->get('user'); + + // Exclude guests, current user and banned users from notifications + unset($pm['recipients'][ANONYMOUS], $pm['recipients'][$user->data['user_id']]); + + if (!sizeof($pm['recipients'])) + { + return; + } + + if (!function_exists('phpbb_get_banned_user_ids')) + { + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + } + $banned_users = phpbb_get_banned_user_ids(array_keys($pm['recipients'])); + $pm['recipients'] = array_diff(array_keys($pm['recipients']), $banned_users); + + if (!sizeof($pm['recipients'])) + { + return; + } + + $sql = 'SELECT user_id, user_notify_pm, user_notify_type + FROM ' . USERS_TABLE . ' + WHERE ' . $db->sql_in_set('user_id', $pm['recipients']); + $result = $db->sql_query($sql); + + $pm['recipients'] = array(); + + while ($row = $db->sql_fetchrow($result)) + { + if ($row['user_notify_pm']) + { + $pm['recipients'][$row['user_id']] = array(); + + if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH) + { + $pm['recipients'][$row['user_id']][] = 'email'; + } + + if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH) + { + $pm['recipients'][$row['user_id']][] = 'jabber'; + } + } + } + $db->sql_freeresult($result); - return parent::create_insert_array($post); + return $pm['recipients']; } } -- cgit v1.2.1 From a4eb8bf47a77cb2637bfad5db20ab9f0dc236059 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 15:49:22 -0500 Subject: [ticket/11103] Jabber notification method base PHPBB3-11103 --- phpBB/includes/notifications/method/jabber.php | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 phpBB/includes/notifications/method/jabber.php (limited to 'phpBB') diff --git a/phpBB/includes/notifications/method/jabber.php b/phpBB/includes/notifications/method/jabber.php new file mode 100644 index 0000000000..15614db96c --- /dev/null +++ b/phpBB/includes/notifications/method/jabber.php @@ -0,0 +1,36 @@ + Date: Sat, 8 Sep 2012 16:02:32 -0500 Subject: [ticket/11103] Fixing some db columns that were of the incorrect type PHPBB3-11103 --- phpBB/develop/create_schema_files.php | 4 ++-- phpBB/includes/notifications/service.php | 7 ++++++- phpBB/includes/notifications/type/interface.php | 2 +- phpBB/includes/notifications/type/pm.php | 11 +++++++---- phpBB/includes/notifications/type/post.php | 2 ++ phpBB/install/database_update.php | 8 ++++---- 6 files changed, 22 insertions(+), 12 deletions(-) (limited to 'phpBB') diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 88aa9b70dd..a2f7463dd4 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1297,7 +1297,7 @@ function get_schema_struct() $schema_data['phpbb_notifications'] = array( 'COLUMNS' => array( - 'item_type' => array('UINT', 0), + 'item_type' => array('VCHAR:25', ''), 'item_id' => array('UINT', 0), 'user_id' => array('UINT', 0), 'unread' => array('BOOL', 1), @@ -1775,7 +1775,7 @@ function get_schema_struct() $schema_data['phpbb_user_notifications'] = array( 'COLUMNS' => array( - 'item_type' => array('UINT', 0), + 'item_type' => array('VCHAR:25', ''), 'item_id' => array('UINT', 0), 'user_id' => array('UINT', 0), 'method' => array('VCHAR:25', ''), diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index ba57fe9f72..a689e1c68a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -141,7 +141,7 @@ class phpbb_notifications_service */ // find out which users want to receive this type of notification - $notify_users = $item_type_class_name::find_users_for_notification($data); + $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data); // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item @@ -155,6 +155,11 @@ class phpbb_notifications_service } $this->db->sql_freeresult($result); + if (!sizeof($notify_users)) + { + return; + } + // Go through each user so we can insert a row in the DB and then notify them by their desired means foreach ($notify_users as $user => $methods) { diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index b710a75606..ccd963ba06 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -31,5 +31,5 @@ interface phpbb_notifications_type_interface public function create_insert_array($type_data); - public function find_users_for_notification($type_data); + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 7685a49614..2b2a835470 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ @@ -101,12 +103,13 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base * @param array $pm Data from * @return array */ - public function find_users_for_notification($pm) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm) { - $user = $this->phpbb_container->get('user'); + $db = $phpbb_container->get('dbal.conn'); + $user = $phpbb_container->get('user'); // Exclude guests, current user and banned users from notifications - unset($pm['recipients'][ANONYMOUS], $pm['recipients'][$user->data['user_id']]); + unset($pm['recipients'][ANONYMOUS]);//, $pm['recipients'][$user->data['user_id']]); if (!sizeof($pm['recipients'])) { @@ -115,7 +118,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base if (!function_exists('phpbb_get_banned_user_ids')) { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + include($phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $phpbb_container->getParameter('core.php_ext')); } $banned_users = phpbb_get_banned_user_ids(array_keys($pm['recipients'])); $pm['recipients'] = array_diff(array_keys($pm['recipients']), $banned_users); diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index addaa30ea6..920a53bcf2 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 99e40ddee9..c3c2da4451 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1107,7 +1107,7 @@ function database_update_info() ), NOTIFICATIONS_TABLE => array( 'COLUMNS' => array( - 'item_type' => array('UINT', 0), + 'item_type' => array('VCHAR:25', ''), 'item_id' => array('UINT', 0), 'user_id' => array('UINT', 0), 'unread' => array('BOOL', 1), @@ -1128,7 +1128,7 @@ function database_update_info() ), USER_NOTIFICATIONS_TABLE => array( 'COLUMNS' => array( - 'item_type' => array('UINT', 0), + 'item_type' => array('VCHAR:25', ''), 'item_id' => array('UINT', 0), 'user_id' => array('UINT', 0), 'method' => array('VCHAR:25', ''), @@ -2676,10 +2676,10 @@ function change_database_data(&$no_updates, $version) // Create config value for displaying last subject on forum list if (!isset($config['display_last_subject'])) - { + { $config->set('display_last_subject', '1'); } - + $no_updates = false; if (!isset($config['assets_version'])) -- cgit v1.2.1 From 86b801df7304d43f117bea762710149c25385260 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 16:12:20 -0500 Subject: [ticket/11103] Some fixes for the email method PHPBB3-11103 --- phpBB/includes/functions_privmsgs.php | 25 +++++++++++-------------- phpBB/includes/notifications/method/email.php | 8 ++++---- phpBB/includes/notifications/service.php | 11 +++++------ phpBB/includes/notifications/type/base.php | 2 -- 4 files changed, 20 insertions(+), 26 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 99ad2ad791..8002765ee2 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1543,6 +1543,7 @@ function get_folder_status($folder_id, $folder) function submit_pm($mode, $subject, &$data, $put_in_outbox = true) { global $db, $auth, $config, $phpEx, $template, $user, $phpbb_root_path; + global $phpbb_container; // We do not handle erasing pms here if ($mode == 'delete') @@ -1844,7 +1845,16 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) // Send Notifications if ($mode != 'edit') { - pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message'], $data['msg_id']); + $phpbb_notifications = $phpbb_container->get('notifications'); + + $phpbb_notifications->add_notifications('pm', array( + 'author_id' => $data['from_user_id'], + 'recipients' => $recipients, + 'message_subject' => $subject, + 'msg_id' => $data['msg_id'], + )); + + //pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message'], $data['msg_id']); } return $data['msg_id']; @@ -1855,19 +1865,6 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) */ function pm_notification($mode, $author, $recipients, $subject, $message, $msg_id) { - global $phpbb_container; - - $phpbb_notifications = $phpbb_container->get('notifications'); - - $phpbb_notifications->add_notifications('pm', array( - 'author_id' => $author, - 'recipients' => $recipients, - 'message_subject' => $subject, - 'msg_id' => $msg_id, - )); - - return; - global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; $subject = censor_text($subject); diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 725ede7913..0120485cff 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -29,7 +29,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base return true; } - public function notify() + public function notify($notification) { // email the user } @@ -70,7 +70,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base { $notification->users($users); - $user = $notification->get_user(); + $user = $notification->get_user($notification->user_id); $messenger->template('privmsg_notify', $user['user_lang']); @@ -82,10 +82,10 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base 'USERNAME' => htmlspecialchars_decode($user['username']), 'U_INBOX' => $board_url . "/ucp.{$this->php_ext}?i=pm&folder=inbox", - 'U_VIEW_MESSAGE' => $board_url . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$notification->get_item_id()}", + 'U_VIEW_MESSAGE' => $board_url . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$notification->item_id}", )); - $messenger->send($addr['method']); + $messenger->send('email'); } // Save the queue in the messenger class (has to be called or these emails could be lost?) diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index a689e1c68a..74e2e29e1a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -172,15 +172,14 @@ class phpbb_notifications_service foreach ($methods as $method) { // setup the notification methods and add the notification to the queue - if ($row['method']) + if ($method) { - if (!isset($notification_methods[$row['method']])) + if (!isset($notification_methods[$method])) { - $method_class_name = 'phpbb_notifications_method_' . $row['method']; - $notification_methods[$row['method']] = new $method_class_name(); + $method_class_name = 'phpbb_notifications_method_' . $method; + $notification_methods[$method] = new $method_class_name($this->phpbb_container); } - - $notification_methods[$row['method']]->add_to_queue($notification); + $notification_methods[$method]->add_to_queue($notification); } } } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index f031abae77..32d8f58ff3 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -37,7 +37,6 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type /** * Indentification data - * notification_id * item_type * item_id * user_id @@ -141,7 +140,6 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type 'URL' => $this->get_url(), 'TIME' => $user->format_date($this->time), - 'ID' => $this->notification_id, 'UNREAD' => $this->unread, )); } -- cgit v1.2.1 From 16a0757f2a21ad2ca36a9463c822539c9ea14d30 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 8 Sep 2012 17:28:13 -0500 Subject: [ticket/11103] Order notifications properly PHPBB3-11103 --- phpBB/includes/notifications/service.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 74e2e29e1a..4794472883 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -46,6 +46,8 @@ class phpbb_notifications_service * * @param array $options Optional options to control what notifications are loaded * user_id User id to load notifications for (Default: $user->data['user_id']) + * order_by Order by (Default: time) + * order_dir Order direction (Default: DESC) * limit Number of notifications to load (Default: 5) * start Notifications offset (Default: 0) */ @@ -58,12 +60,15 @@ class phpbb_notifications_service 'user_id' => $user->data['user_id'], 'limit' => 5, 'start' => 0, + 'order_by' => 'time', + 'order_dir' => 'DESC', ), $options); $notifications = $user_ids = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $options['user_id']; + WHERE user_id = ' . (int) $options['user_id'] . ' + ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); while ($row = $this->db->sql_fetchrow($result)) -- cgit v1.2.1 From 6983f380c55779054b545e4760bf250e8ecace2e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 8 Sep 2012 17:48:13 -0500 Subject: [ticket/11103] Full url function PHPBB3-11103 --- phpBB/includes/notifications/method/email.php | 11 ++++++----- phpBB/includes/notifications/type/interface.php | 2 ++ phpBB/includes/notifications/type/pm.php | 12 +++++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 0120485cff..b1979296b9 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -23,6 +23,10 @@ if (!defined('IN_PHPBB')) */ class phpbb_notifications_method_email extends phpbb_notifications_method_base { + /** + * Is this method available for the user? + * This is checked on the notifications options + */ public static function is_available() { // Email is always available @@ -77,12 +81,9 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base $messenger->to($user['user_email'], $user['username']); $messenger->assign_vars(array( - 'SUBJECT' => htmlspecialchars_decode($notification->get_title()), - 'AUTHOR_NAME' => '', - 'USERNAME' => htmlspecialchars_decode($user['username']), + 'SUBJECT' => htmlspecialchars_decode($notification->get_title()), - 'U_INBOX' => $board_url . "/ucp.{$this->php_ext}?i=pm&folder=inbox", - 'U_VIEW_MESSAGE' => $board_url . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$notification->item_id}", + 'U_VIEW_MESSAGE' => $notification->get_full_url(), )); $messenger->send('email'); diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index ccd963ba06..03e24358a9 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -29,6 +29,8 @@ interface phpbb_notifications_type_interface public function get_url(); + public function get_full_url(); + public function create_insert_array($type_data); public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 2b2a835470..50c67de21a 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -65,7 +65,17 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base */ public function get_url() { - return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); + return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); + } + + /** + * Get the full url to this item + * + * @return string URL + */ + public function get_full_url() + { + return generate_board_url() . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$this->item_id}"; } /** -- cgit v1.2.1 From 98a03090a05b1d7651c05ad23802973cf20dcf6b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 8 Sep 2012 21:05:49 -0500 Subject: [ticket/11103] Move banned user checking to email method This will make sure banned users are never sent notification emails PHPBB3-11103 --- phpBB/includes/notifications/method/email.php | 12 ++++++++++++ phpBB/includes/notifications/type/pm.php | 16 ++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index b1979296b9..2b80b5bf3a 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -52,6 +52,13 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base $user_ids[] = $notification->user_id; } + // We do not send emails to banned users + if (!function_exists('phpbb_get_banned_user_ids')) + { + include($phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $phpbb_container->getParameter('core.php_ext')); + } + $banned_users = phpbb_get_banned_user_ids($user_ids); + $sql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE ' . $this->db->sql_in_set('user_id', $user_ids); $result = $this->db->sql_query($sql); @@ -72,6 +79,11 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base // Time to go through the queue and send emails foreach ($this->queue as $notification) { + if (in_array($notification->user_id, $banned_users)) + { + continue; + } + $notification->users($users); $user = $notification->get_user($notification->user_id); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 50c67de21a..92026c08d7 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -118,20 +118,8 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base $db = $phpbb_container->get('dbal.conn'); $user = $phpbb_container->get('user'); - // Exclude guests, current user and banned users from notifications - unset($pm['recipients'][ANONYMOUS]);//, $pm['recipients'][$user->data['user_id']]); - - if (!sizeof($pm['recipients'])) - { - return; - } - - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $phpbb_container->getParameter('core.php_ext')); - } - $banned_users = phpbb_get_banned_user_ids(array_keys($pm['recipients'])); - $pm['recipients'] = array_diff(array_keys($pm['recipients']), $banned_users); + // Exclude guests and current user from notifications + unset($pm['recipients'][ANONYMOUS], $pm['recipients'][$user->data['user_id']]); if (!sizeof($pm['recipients'])) { -- cgit v1.2.1 From 4b4ea7c5cde7c9f3684ca325c110f81eda593d67 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 10:19:46 -0500 Subject: [ticket/11103] The service now handles all user loading itself Delete pm notifications when pms are deleted PHPBB3-11103 --- phpBB/includes/functions_privmsgs.php | 106 ++++-------------------- phpBB/includes/notifications/method/base.php | 25 +++++- phpBB/includes/notifications/method/email.php | 14 +--- phpBB/includes/notifications/service.php | 101 ++++++++++++---------- phpBB/includes/notifications/type/base.php | 24 +----- phpBB/includes/notifications/type/interface.php | 4 +- phpBB/includes/notifications/type/pm.php | 98 +++++++++++----------- 7 files changed, 152 insertions(+), 220 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 8002765ee2..88c5bd8e2a 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -982,6 +982,7 @@ function handle_mark_actions($user_id, $mark_action) function delete_pm($user_id, $msg_ids, $folder_id) { global $db, $user, $phpbb_root_path, $phpEx; + global $phpbb_container; $user_id = (int) $user_id; $folder_id = (int) $folder_id; @@ -1093,6 +1094,10 @@ function delete_pm($user_id, $msg_ids, $folder_id) $user->data['user_unread_privmsg'] -= $num_unread; } + // Delete Notifications + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->delete_notifications('pm', array_keys($delete_rows)); + // Now we have to check which messages we can delete completely $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . ' @@ -1843,104 +1848,23 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) $db->sql_transaction('commit'); // Send Notifications - if ($mode != 'edit') - { - $phpbb_notifications = $phpbb_container->get('notifications'); - - $phpbb_notifications->add_notifications('pm', array( - 'author_id' => $data['from_user_id'], - 'recipients' => $recipients, - 'message_subject' => $subject, - 'msg_id' => $data['msg_id'], - )); - - //pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message'], $data['msg_id']); - } - - return $data['msg_id']; -} - -/** -* PM Notification -*/ -function pm_notification($mode, $author, $recipients, $subject, $message, $msg_id) -{ - global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; - - $subject = censor_text($subject); - - // Exclude guests, current user and banned users from notifications - unset($recipients[ANONYMOUS], $recipients[$user->data['user_id']]); - - if (!sizeof($recipients)) - { - return; - } - - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - } - $banned_users = phpbb_get_banned_user_ids(array_keys($recipients)); - $recipients = array_diff(array_keys($recipients), $banned_users); + $phpbb_notifications = $phpbb_container->get('notifications'); - if (!sizeof($recipients)) - { - return; - } - - $sql = 'SELECT user_id, username, user_email, user_lang, user_notify_pm, user_notify_type, user_jabber - FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $recipients); - $result = $db->sql_query($sql); - - $msg_list_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - if ($row['user_notify_pm'] == 1 && trim($row['user_email'])) - { - $msg_list_ary[] = array( - 'method' => $row['user_notify_type'], - 'email' => $row['user_email'], - 'jabber' => $row['user_jabber'], - 'name' => $row['username'], - 'lang' => $row['user_lang'] - ); - } - } - $db->sql_freeresult($result); + $pm_data = array_merge($data, array( + 'message_subject' => $subject, + 'recipients' => $recipients, + )); - if (!sizeof($msg_list_ary)) + if ($mode == 'edit') { - return; + $phpbb_notifications->update_notifications('pm', $pm_data); } - - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $messenger = new messenger(); - - foreach ($msg_list_ary as $pos => $addr) + else { - $messenger->template('privmsg_notify', $addr['lang']); - - $messenger->to($addr['email'], $addr['name']); - $messenger->im($addr['jabber'], $addr['name']); - - $messenger->assign_vars(array( - 'SUBJECT' => htmlspecialchars_decode($subject), - 'AUTHOR_NAME' => htmlspecialchars_decode($author), - 'USERNAME' => htmlspecialchars_decode($addr['name']), - - 'U_INBOX' => generate_board_url() . "/ucp.$phpEx?i=pm&folder=inbox", - 'U_VIEW_MESSAGE' => generate_board_url() . "/ucp.$phpEx?i=pm&mode=view&p=$msg_id", - )); - - $messenger->send($addr['method']); + $phpbb_notifications->add_notifications('pm', $pm_data); } - unset($msg_list_ary); - $messenger->save_queue(); - - unset($messenger); + return $data['msg_id']; } /** diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index 98c06509c6..3ed9d3f33c 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -24,11 +24,31 @@ if (!defined('IN_PHPBB')) abstract class phpbb_notifications_method_base implements phpbb_notifications_method_interface { protected $phpbb_container; + protected $service; protected $db; protected $user; protected $phpbb_root_path; protected $php_ext; + /** + * Desired notifications + * unique by (type, type_id, user_id, method) + * if multiple methods are desired, multiple rows will exist. + * + * method of "none" will over-ride any other options + * + * item_type + * item_id + * user_id + * method + * none (will never receive notifications) + * standard (listed in notifications window + * popup? + * email + * jabber + * sms? + */ + /** * Queue of messages to be sent * @@ -36,11 +56,14 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me */ protected $queue = array(); - public function __construct(ContainerBuilder $phpbb_container, $data = array()) + public function __construct(ContainerBuilder $phpbb_container) { // phpBB Container $this->phpbb_container = $phpbb_container; + // Service + $this->service = $phpbb_container->get('notifications'); + // Some common things we're going to use $this->db = $phpbb_container->get('dbal.conn'); $this->user = $phpbb_container->get('user'); diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 2b80b5bf3a..50df9a6c56 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -59,14 +59,8 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base } $banned_users = phpbb_get_banned_user_ids($user_ids); - $sql = 'SELECT * FROM ' . USERS_TABLE . ' - WHERE ' . $this->db->sql_in_set('user_id', $user_ids); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $users[$row['user_id']] = $row; - } - $this->db->sql_freeresult($result); + // Load all the users we need + $this->service->load_users($user_ids); // Load the messenger if (!class_exists('messenger')) @@ -84,9 +78,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base continue; } - $notification->users($users); - - $user = $notification->get_user($notification->user_id); + $user = $this->service->get_user($notification->user_id); $messenger->template('privmsg_notify', $user['user_lang']); diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 4794472883..50ceb1584a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -31,7 +31,7 @@ class phpbb_notifications_service * * @var array Array of user data that we've loaded from the DB */ - protected $users; + protected $users = array(); public function __construct(ContainerBuilder $phpbb_container) { @@ -76,7 +76,6 @@ class phpbb_notifications_service $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); $notification = new $item_type_class_name($this->phpbb_container, $row); - $notification->users($this->users); $user_ids = array_merge($user_ids, $notification->users_to_query()); @@ -84,24 +83,7 @@ class phpbb_notifications_service } $this->db->sql_freeresult($result); - // Load the users - $user_ids = array_unique($user_ids); - - // @todo do not load users we already have in $this->users - - if (sizeof($user_ids)) - { - // @todo do not select everything - $sql = 'SELECT * FROM ' . USERS_TABLE . ' - WHERE ' . $this->db->sql_in_set('user_id', $user_ids); - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $this->users[$row['user_id']] = $row; - } - $this->db->sql_freeresult($result); - } + $this->load_users($user_ids); return $notifications; } @@ -122,32 +104,16 @@ class phpbb_notifications_service // Update any existing notifications for this item $this->update_notifications($item_type, $item_id, $data); - $notify_users = array(); + $notify_users = $user_ids = array(); $notification_objects = $notification_methods = array(); $new_rows = array(); - /** - * Desired notifications - * unique by (type, type_id, user_id, method) - * if multiple methods are desired, multiple rows will exist. - * - * method of "none" will over-ride any other options - * - * item_type - * item_id - * user_id - * method - * none (will never receive notifications) - * standard (listed in notifications window - * popup? - * email - * jabber - * sms? - */ - // find out which users want to receive this type of notification $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data); + // Never send notifications to the anonymous user or the current user! + $notify_users = array_diff($notify_users, array(ANONYMOUS, $this->phpbb_container->get('user')->data['user_id'])); + // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " @@ -172,8 +138,12 @@ class phpbb_notifications_service $notification->user_id = (int) $user; + // Store the creation array in our new rows that will be inserted later $new_rows[] = $notification->create_insert_array($data); + // Users are needed to send notifications + $user_ids = array_merge($user_ids, $notification->users_to_query()); + foreach ($methods as $method) { // setup the notification methods and add the notification to the queue @@ -184,6 +154,7 @@ class phpbb_notifications_service $method_class_name = 'phpbb_notifications_method_' . $method; $notification_methods[$method] = new $method_class_name($this->phpbb_container); } + $notification_methods[$method]->add_to_queue($notification); } } @@ -192,6 +163,9 @@ class phpbb_notifications_service // insert into the db $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); + // We need to load all of the users to send notifications + $this->load_users($user_ids); + // run the queue for each method to send notifications foreach ($notification_methods as $method) { @@ -203,13 +177,14 @@ class phpbb_notifications_service * Update a notification * * @param string $item_type Type identifier - * @param int $item_id Identifier within the type * @param array $data Data specific for this type that will be updated */ - public function update_notifications($item_type, $item_id, $data) + public function update_notifications($item_type, $data) { $item_type_class_name = $this->get_item_type_class_name($item_type); + $item_id = $item_type_class_name::get_item_id($data); + $notification = new $item_type_class_name($this->phpbb_container); $update_array = $notification->create_update_array($data); @@ -224,17 +199,55 @@ class phpbb_notifications_service * Delete a notification * * @param string $item_type Type identifier - * @param int $item_id Identifier within the type + * @param int|array $item_id Identifier within the type (or array of ids) * @param array $data Data specific for this type that will be updated */ public function delete_notifications($item_type, $item_id) { $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND item_id = " . (int) $item_id; + AND " . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id); $this->db->sql_query($sql); } + /** + * Load user helper + * + * @param array $user_ids + */ + public function load_users($user_ids) + { + // Load the users + $user_ids = array_unique($user_ids); + + // Do not load users we already have in $this->users + $user_ids = array_diff($user_ids, array_keys($this->users)); + + if (sizeof($user_ids)) + { + $sql = 'SELECT * FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + } + } + + /** + * Get a user row from our users cache + * + * @param int $user_id + * @return array + */ + public function get_user($user_id) + { + return $this->users[$user_id]; + } + /** * Helper to get the notifications item type class name and clean it if unsafe */ diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 32d8f58ff3..b0b8801a7e 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -24,6 +24,7 @@ if (!defined('IN_PHPBB')) abstract class phpbb_notifications_type_base implements phpbb_notifications_type_interface { protected $phpbb_container; + protected $service; protected $db; protected $phpbb_root_path; protected $php_ext; @@ -55,6 +56,9 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type // phpBB Container $this->phpbb_container = $phpbb_container; + // Service + $this->service = $phpbb_container->get('notifications'); + // Some common things we're going to use $this->db = $phpbb_container->get('dbal.conn'); @@ -99,26 +103,6 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type $this->data['data'][$name] = $value; } - /** - * Function to store the users loaded from the database (for output to the template) - * (The service handles this) - */ - public function users(&$users) - { - $this->users = &$users; - } - - /** - * Get a user row from our users cache - * - * @param int $user_id - * @return array - */ - public function get_user($user_id) - { - return $this->users[$user_id]; - } - /** * Output the notification to the template * diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index 03e24358a9..85fe41f6ef 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -25,6 +25,8 @@ interface phpbb_notifications_type_interface public static function get_item_id($type_data); + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); + public function get_title(); public function get_url(); @@ -32,6 +34,4 @@ interface phpbb_notifications_type_interface public function get_full_url(); public function create_insert_array($type_data); - - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 92026c08d7..8b8f41d1c2 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -44,6 +44,50 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base return $pm['msg_id']; } + /** + * Find the users who want to receive notifications + * + * @param array $pm Data from + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm) + { + $service = $phpbb_container->get('notifications'); + $db = $phpbb_container->get('dbal.conn'); + $user = $phpbb_container->get('user'); + + if (!sizeof($pm['recipients'])) + { + return array(); + } + + $service->load_users(array_keys($pm['recipients'])); + + $notify_users = array(); + + foreach (array_keys($pm['recipients']) as $user_id) + { + $recipient = $service->get_user($user_id); + + if ($recipient['user_notify_pm']) + { + $notify_users[$recipient['user_id']] = array(); + + if ($recipient['user_notify_type'] == NOTIFY_EMAIL || $recipient['user_notify_type'] == NOTIFY_BOTH) + { + $notify_users[$recipient['user_id']][] = 'email'; + } + + if ($recipient['user_notify_type'] == NOTIFY_IM || $recipient['user_notify_type'] == NOTIFY_BOTH) + { + $notify_users[$recipient['user_id']][] = 'jabber'; + } + } + } + + return $notify_users; + } + /** * Get the title of this notification * @@ -51,7 +95,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base */ public function get_title() { - $user_data = $this->get_user($this->get_data('author_id')); + $user_data = $this->service->get_user($this->get_data('from_user_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); @@ -85,7 +129,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base */ public function users_to_query() { - return array($this->data['author_id']); + return array($this->data['from_user_id']); } /** @@ -100,58 +144,10 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base { $this->item_id = $pm['msg_id']; - $this->set_data('author_id', $pm['author_id']); + $this->set_data('from_user_id', $pm['from_user_id']); $this->set_data('message_subject', $pm['message_subject']); return parent::create_insert_array($pm); } - - /** - * Find the users who want to receive notifications - * - * @param array $pm Data from - * @return array - */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm) - { - $db = $phpbb_container->get('dbal.conn'); - $user = $phpbb_container->get('user'); - - // Exclude guests and current user from notifications - unset($pm['recipients'][ANONYMOUS], $pm['recipients'][$user->data['user_id']]); - - if (!sizeof($pm['recipients'])) - { - return; - } - - $sql = 'SELECT user_id, user_notify_pm, user_notify_type - FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $pm['recipients']); - $result = $db->sql_query($sql); - - $pm['recipients'] = array(); - - while ($row = $db->sql_fetchrow($result)) - { - if ($row['user_notify_pm']) - { - $pm['recipients'][$row['user_id']] = array(); - - if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH) - { - $pm['recipients'][$row['user_id']][] = 'email'; - } - - if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH) - { - $pm['recipients'][$row['user_id']][] = 'jabber'; - } - } - } - $db->sql_freeresult($result); - - return $pm['recipients']; - } } -- cgit v1.2.1 From ff45c9aa7c077fc0a03c64764917d1efcccf48f4 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 10:36:22 -0500 Subject: [ticket/11103] General notification email template. PHPBB3-11103 --- phpBB/includes/notifications/method/base.php | 13 +------------ phpBB/includes/notifications/method/email.php | 15 +++++++-------- phpBB/includes/notifications/method/interface.php | 2 +- phpBB/includes/notifications/service.php | 2 +- phpBB/includes/notifications/type/base.php | 22 +++++++++++++++++++++- phpBB/includes/notifications/type/interface.php | 4 ++++ phpBB/includes/notifications/type/pm.php | 16 ++++++++++++++-- phpBB/language/en/email/notification.txt | 16 ++++++++++++++++ 8 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 phpBB/language/en/email/notification.txt (limited to 'phpBB') diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index 3ed9d3f33c..b860fcffda 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -83,19 +83,8 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me } /** - * Basic run queue function. - * Child methods should override this function if there are more efficient methods to mass-notification + * Empty the queue */ - public function run_queue() - { - foreach ($this->queue as $notification) - { - $this->notify($notification); - } - - $this->empty_queue(); - } - protected function empty_queue() { $this->queue = array(); diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 50df9a6c56..69546be73f 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -33,12 +33,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base return true; } - public function notify($notification) - { - // email the user - } - - public function run_queue() + public function notify() { if (!sizeof($this->queue)) { @@ -80,14 +75,18 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base $user = $this->service->get_user($notification->user_id); - $messenger->template('privmsg_notify', $user['user_lang']); + $messenger->template('notification', $user['user_lang']); $messenger->to($user['user_email'], $user['username']); $messenger->assign_vars(array( - 'SUBJECT' => htmlspecialchars_decode($notification->get_title()), + 'USERNAME' => $user['username'], + + 'MESSAGE' => htmlspecialchars_decode($notification->get_title()), 'U_VIEW_MESSAGE' => $notification->get_full_url(), + + 'U_UNSUBSCRIBE' => $notification->get_unsubscribe_url(), )); $messenger->send('email'); diff --git a/phpBB/includes/notifications/method/interface.php b/phpBB/includes/notifications/method/interface.php index f18d005b8b..7d7f3abcd0 100644 --- a/phpBB/includes/notifications/method/interface.php +++ b/phpBB/includes/notifications/method/interface.php @@ -21,5 +21,5 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notifications_method_interface { - public function notify($notification); + public function notify(); } diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 50ceb1584a..463798fa07 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -169,7 +169,7 @@ class phpbb_notifications_service // run the queue for each method to send notifications foreach ($notification_methods as $method) { - $method->run_queue(); + $method->notify(); } } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index b0b8801a7e..91cc9f175a 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -120,7 +120,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type ), $options); $template->assign_block_vars($options['template_block'], array( - 'TITLE' => $this->get_title(), + 'TITLE' => $this->get_formatted_title(), 'URL' => $this->get_url(), 'TIME' => $user->format_date($this->time), @@ -173,4 +173,24 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $data; } + + /** + * Get the formatted title of this notification (fall-back) + * + * @return string + */ + public function get_formatted_title() + { + return $this->get_title(); + } + + /** + * URL to unsubscribe to this notification + * + * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item + */ + public function get_unsubscribe_url($method = false) + { + return false; + } } diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index 85fe41f6ef..c165815835 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -29,9 +29,13 @@ interface phpbb_notifications_type_interface public function get_title(); + public function get_formatted_title(); + public function get_url(); public function get_full_url(); + public function get_unsubscribe_url($method); + public function create_insert_array($type_data); } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 8b8f41d1c2..702ec39c16 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -89,11 +89,11 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base } /** - * Get the title of this notification + * Get the HTML formatted title of this notification * * @return string */ - public function get_title() + public function get_formatted_title() { $user_data = $this->service->get_user($this->get_data('from_user_id')); @@ -102,6 +102,18 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base return $username . ' sent you a private message titled: ' . $this->get_data('message_subject'); } + /** + * Get the plain text title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->service->get_user($this->get_data('from_user_id')); + + return $user_data['username'] . ' sent you a private message titled: ' . $this->get_data('message_subject'); + } + /** * Get the url to this item * diff --git a/phpBB/language/en/email/notification.txt b/phpBB/language/en/email/notification.txt new file mode 100644 index 0000000000..ed35e96c85 --- /dev/null +++ b/phpBB/language/en/email/notification.txt @@ -0,0 +1,16 @@ +Subject: Notification from {SITENAME} + +Hello {USERNAME}, + +{MESSAGE} + +You can view this by clicking on the following link: + +{U_VIEW_MESSAGE} + + +You may unsubscribe by clicking on the following link: +{U_UNSUBSCRIBE} + + +{EMAIL_SIG} \ No newline at end of file -- cgit v1.2.1 From 570fe6cee87da807f0917cdc0c84aee604b50510 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 12:27:37 -0500 Subject: [ticket/11103] Do not initialize the notifications in common.php DIC initializes it when it is needed. PHPBB3-11103 --- phpBB/common.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB') diff --git a/phpBB/common.php b/phpBB/common.php index 52879deb9c..281eb88c4d 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -146,9 +146,6 @@ if (!$config['use_system_cron']) $cron = $phpbb_container->get('cron.manager'); } -// Load notifications -$phpbb_notifications = $phpbb_container->get('notifications'); - /** * Main event which is triggered on every page * -- cgit v1.2.1 From 74e2a8f893a2e7a69ba129a74dd0b3c31e742e79 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 13:29:47 -0500 Subject: [ticket/11103] Post notifications PHPBB3-11103 --- phpBB/includes/functions_posting.php | 252 +++-------------------------- phpBB/includes/mcp/mcp_queue.php | 6 +- phpBB/includes/notifications/type/base.php | 32 ++++ phpBB/includes/notifications/type/pm.php | 2 + phpBB/includes/notifications/type/post.php | 71 +++++++- 5 files changed, 122 insertions(+), 241 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index c50395a5df..6c5c4535a3 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -61,7 +61,7 @@ function generate_smilies($mode, $forum_id) 'body' => 'posting_smilies.html') ); - generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), $smiley_count, $config['smilies_per_page'], $start); + generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), $smiley_count, $config['smilies_per_page'], $start); } $display_link = false; @@ -1173,237 +1173,6 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id return true; } -/** -* User Notification -*/ -function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id) -{ - global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; - - $topic_notification = ($mode == 'reply' || $mode == 'quote') ? true : false; - $forum_notification = ($mode == 'post') ? true : false; - - if (!$topic_notification && !$forum_notification) - { - trigger_error('NO_MODE'); - } - - if (($topic_notification && !$config['allow_topic_notify']) || ($forum_notification && !$config['allow_forum_notify'])) - { - return; - } - - $topic_title = ($topic_notification) ? $topic_title : $subject; - $topic_title = censor_text($topic_title); - - // Exclude guests, current user and banned users from notifications - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - } - $sql_ignore_users = phpbb_get_banned_user_ids(); - $sql_ignore_users[ANONYMOUS] = ANONYMOUS; - $sql_ignore_users[$user->data['user_id']] = $user->data['user_id']; - - $notify_rows = array(); - - // -- get forum_userids || topic_userids - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber - FROM ' . (($topic_notification) ? TOPICS_WATCH_TABLE : FORUMS_WATCH_TABLE) . ' w, ' . USERS_TABLE . ' u - WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . ' - AND ' . $db->sql_in_set('w.user_id', $sql_ignore_users, true) . ' - AND w.notify_status = ' . NOTIFY_YES . ' - AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') - AND u.user_id = w.user_id'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $notify_user_id = (int) $row['user_id']; - $notify_rows[$notify_user_id] = array( - 'user_id' => $notify_user_id, - 'username' => $row['username'], - 'user_email' => $row['user_email'], - 'user_jabber' => $row['user_jabber'], - 'user_lang' => $row['user_lang'], - 'notify_type' => ($topic_notification) ? 'topic' : 'forum', - 'template' => ($topic_notification) ? 'topic_notify' : 'newtopic_notify', - 'method' => $row['user_notify_type'], - 'allowed' => false - ); - - // Add users who have been already notified to ignore list - $sql_ignore_users[$notify_user_id] = $notify_user_id; - } - $db->sql_freeresult($result); - - // forum notification is sent to those not already receiving topic notifications - if ($topic_notification) - { - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber - FROM ' . FORUMS_WATCH_TABLE . ' fw, ' . USERS_TABLE . " u - WHERE fw.forum_id = $forum_id - AND " . $db->sql_in_set('fw.user_id', $sql_ignore_users, true) . ' - AND fw.notify_status = ' . NOTIFY_YES . ' - AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') - AND u.user_id = fw.user_id'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $notify_user_id = (int) $row['user_id']; - $notify_rows[$notify_user_id] = array( - 'user_id' => $notify_user_id, - 'username' => $row['username'], - 'user_email' => $row['user_email'], - 'user_jabber' => $row['user_jabber'], - 'user_lang' => $row['user_lang'], - 'notify_type' => 'forum', - 'template' => 'forum_notify', - 'method' => $row['user_notify_type'], - 'allowed' => false - ); - } - $db->sql_freeresult($result); - } - - if (!sizeof($notify_rows)) - { - return; - } - - // Make sure users are allowed to read the forum - foreach ($auth->acl_get_list(array_keys($notify_rows), 'f_read', $forum_id) as $forum_id => $forum_ary) - { - foreach ($forum_ary as $auth_option => $user_ary) - { - foreach ($user_ary as $user_id) - { - $notify_rows[$user_id]['allowed'] = true; - } - } - } - - // Now, we have to do a little step before really sending, we need to distinguish our users a little bit. ;) - $msg_users = $delete_ids = $update_notification = array(); - foreach ($notify_rows as $user_id => $row) - { - if (!$row['allowed'] || !trim($row['user_email'])) - { - $delete_ids[$row['notify_type']][] = $row['user_id']; - } - else - { - $msg_users[] = $row; - $update_notification[$row['notify_type']][] = $row['user_id']; - - /* - * We also update the forums watch table for this user when we are - * sending out a topic notification to prevent sending out another - * notification in case this user is also subscribed to the forum - * this topic was posted in. - * Since an UPDATE query is used, this has no effect on users only - * subscribed to the topic (i.e. no row is created) and should not - * be a performance issue. - */ - if ($row['notify_type'] === 'topic') - { - $update_notification['forum'][] = $row['user_id']; - } - } - } - unset($notify_rows); - - // Now, we are able to really send out notifications - if (sizeof($msg_users)) - { - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $messenger = new messenger(); - - $msg_list_ary = array(); - foreach ($msg_users as $row) - { - $pos = (!isset($msg_list_ary[$row['template']])) ? 0 : sizeof($msg_list_ary[$row['template']]); - - $msg_list_ary[$row['template']][$pos]['method'] = $row['method']; - $msg_list_ary[$row['template']][$pos]['email'] = $row['user_email']; - $msg_list_ary[$row['template']][$pos]['jabber'] = $row['user_jabber']; - $msg_list_ary[$row['template']][$pos]['name'] = $row['username']; - $msg_list_ary[$row['template']][$pos]['lang'] = $row['user_lang']; - $msg_list_ary[$row['template']][$pos]['user_id']= $row['user_id']; - } - unset($msg_users); - - foreach ($msg_list_ary as $email_template => $email_list) - { - foreach ($email_list as $addr) - { - $messenger->template($email_template, $addr['lang']); - - $messenger->to($addr['email'], $addr['name']); - $messenger->im($addr['jabber'], $addr['name']); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($addr['name']), - 'TOPIC_TITLE' => htmlspecialchars_decode($topic_title), - 'FORUM_NAME' => htmlspecialchars_decode($forum_name), - - 'U_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id", - 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id", - 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&p=$post_id&e=$post_id", - 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?uid={$addr['user_id']}&f=$forum_id&t=$topic_id&unwatch=topic", - 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.$phpEx?uid={$addr['user_id']}&f=$forum_id&unwatch=forum", - )); - - $messenger->send($addr['method']); - } - } - unset($msg_list_ary); - - $messenger->save_queue(); - } - - // Handle the DB updates - $db->sql_transaction('begin'); - - if (!empty($update_notification['topic'])) - { - $sql = 'UPDATE ' . TOPICS_WATCH_TABLE . ' - SET notify_status = ' . NOTIFY_NO . " - WHERE topic_id = $topic_id - AND " . $db->sql_in_set('user_id', $update_notification['topic']); - $db->sql_query($sql); - } - - if (!empty($update_notification['forum'])) - { - $sql = 'UPDATE ' . FORUMS_WATCH_TABLE . ' - SET notify_status = ' . NOTIFY_NO . " - WHERE forum_id = $forum_id - AND " . $db->sql_in_set('user_id', $update_notification['forum']); - $db->sql_query($sql); - } - - // Now delete the user_ids not authorised to receive notifications on this topic/forum - if (!empty($delete_ids['topic'])) - { - $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . " - WHERE topic_id = $topic_id - AND " . $db->sql_in_set('user_id', $delete_ids['topic']); - $db->sql_query($sql); - } - - if (!empty($delete_ids['forum'])) - { - $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . " - WHERE forum_id = $forum_id - AND " . $db->sql_in_set('user_id', $delete_ids['forum']); - $db->sql_query($sql); - } - - $db->sql_transaction('commit'); -} - // // Post handling functions // @@ -1640,6 +1409,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; + global $phpbb_container; // We do not handle erasing posts here if ($mode == 'delete') @@ -2452,7 +2222,23 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Send Notifications if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) { - user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']); + $notifications = $phpbb_container->get('notifications'); + + switch ($mode) + { + case 'reply' : + case 'quote' : + $notifications->add_notifications('post', array_merge($data, array( + 'post_username' => $username, + ))); + break; + + case 'post' : + $notifications->add_notifications('topic', array_merge($data, array( + 'post_username' => $username, + ))); + break; + } } $params = $add_anchor = ''; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index b44685b8a3..d5c431e478 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -421,7 +421,7 @@ class mcp_queue $base_url = $this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start); - + // Now display the page $template->assign_vars(array( 'L_DISPLAY_ITEMS' => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'], @@ -639,12 +639,12 @@ function approve_post($post_id_list, $id, $mode) if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) { // Forum Notifications - user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + $notifications->add_notifications('topic', $post_data); } else { // Topic Notifications - user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + $notifications->add_notifications('post', $post_data); } } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 91cc9f175a..df273f9e81 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -174,6 +174,38 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $data; } + /** + * Find the users who want to receive notifications (helper) + * + * @param ContainerBuilder $phpbb_container + * @param array $item_id The item_id to search for + * + * @return array + */ + protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id) + { + $db = $phpbb_container->get('dbal.conn'); + + $rowset = array(); + + $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . static::get_item_type() . "' + AND item_id = " . (int) $item_id; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (!isset($rowset[$row['user_id']])) + { + $rowset[$row['user_id']] = array(); + } + + $rowset[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $rowset; + } + /** * Get the formatted title of this notification (fall-back) * diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 702ec39c16..e060b5d658 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -47,7 +47,9 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base /** * Find the users who want to receive notifications * + * @param ContainerBuilder $phpbb_container * @param array $pm Data from + * * @return array */ public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm) diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 920a53bcf2..96faa0131c 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -45,11 +45,45 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } /** - * Get the title of this notification + * Find the users who want to receive notifications + * + * @param ContainerBuilder $phpbb_container + * @param array $post Data from + * + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) + { + $users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); + + if (!sizeof($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + { + $notify_users[$user_id] = $users[$user_id]; + } + + return $notify_users; + } + + /** + * Get the HTML formatted title of this notification * * @return string */ - public function get_title() + public function get_formatted_title() { if ($this->get_data('post_username')) { @@ -57,7 +91,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } else { - $user_data = $this->get_user($this->get_data('poster_id')); + $user_data = $this->service->get_user($this->get_data('poster_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } @@ -65,6 +99,25 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title')); } + /** + * Get the title of this notification + * + * @return string + */ + public function get_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $username = $user_data['username']; + } + + return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title')); + } + /** * Get the url to this item * @@ -75,6 +128,16 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); } + /** + * Get the full url to this item + * + * @return string URL + */ + public function get_full_url() + { + return generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}"; + } + /** * Users needed to query before this notification can be displayed * @@ -103,8 +166,6 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('post_username', $post['post_username']); - $this->time = $post['post_time']; - return parent::create_insert_array($post); } } -- cgit v1.2.1 From 3624d2c50ac1acca767c5642767102b97fd6b832 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 14:20:14 -0500 Subject: [ticket/11103] Use the language system, topic notifications PHPBB3-11103 --- phpBB/includes/notifications/method/email.php | 8 +- phpBB/includes/notifications/type/pm.php | 4 +- phpBB/includes/notifications/type/post.php | 8 +- phpBB/includes/notifications/type/topic.php | 185 ++++++++++++++++++++++++++ phpBB/language/en/common.php | 3 + 5 files changed, 200 insertions(+), 8 deletions(-) create mode 100644 phpBB/includes/notifications/type/topic.php (limited to 'phpBB') diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 69546be73f..d6468c9dc3 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -50,7 +50,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base // We do not send emails to banned users if (!function_exists('phpbb_get_banned_user_ids')) { - include($phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $phpbb_container->getParameter('core.php_ext')); + include($this->phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $this->phpbb_container->getParameter('core.php_ext')); } $banned_users = phpbb_get_banned_user_ids($user_ids); @@ -68,13 +68,13 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base // Time to go through the queue and send emails foreach ($this->queue as $notification) { - if (in_array($notification->user_id, $banned_users)) + $user = $this->service->get_user($notification->user_id); + + if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) { continue; } - $user = $this->service->get_user($notification->user_id); - $messenger->template('notification', $user['user_lang']); $messenger->to($user['user_email'], $user['username']); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index e060b5d658..3368b171df 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -101,7 +101,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); - return $username . ' sent you a private message titled: ' . $this->get_data('message_subject'); + return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } /** @@ -113,7 +113,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base { $user_data = $this->service->get_user($this->get_data('from_user_id')); - return $user_data['username'] . ' sent you a private message titled: ' . $this->get_data('message_subject'); + return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $user_data['username'], $this->get_data('message_subject')); } /** diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 96faa0131c..04e269737e 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -96,7 +96,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } - return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title')); + return $this->phpbb_container->get('user')->lang('NOTIFICATION_POST', $username, censor_text($this->get_data('topic_title'))); } /** @@ -112,10 +112,12 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } else { + $user_data = $this->service->get_user($this->get_data('poster_id')); + $username = $user_data['username']; } - return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title')); + return $this->phpbb_container->get('user')->lang('NOTIFICATION_POST', $username, censor_text($this->get_data('topic_title'))); } /** @@ -166,6 +168,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('post_username', $post['post_username']); + $this->set_data('forum_name', $post['forum_name']); + return parent::create_insert_array($post); } } diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php new file mode 100644 index 0000000000..f58419a633 --- /dev/null +++ b/phpBB/includes/notifications/type/topic.php @@ -0,0 +1,185 @@ +get('auth')->acl_get_list(array_keys($users), 'f_read', $topic['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_read[$topic['forum_id']]['f_read'] as $user_id) + { + $notify_users[$user_id] = $users[$user_id]; + } + + return $notify_users; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_formatted_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + + return $this->phpbb_container->get('user')->lang( + 'NOTIFICATION_TOPIC', + $username, + censor_text($this->get_data('topic_title')), + $this->get_data('forum_name') + ); + } + + /** + * Get the title of this notification + * + * @return string + */ + public function get_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + $username = $user_data['username']; + } + + return $this->phpbb_container->get('user')->lang( + 'NOTIFICATION_TOPIC', + $username, + censor_text($this->get_data('topic_title')), + $this->get_data('forum_name') + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t{$this->item_id}"); + } + + /** + * Get the full url to this item + * + * @return string URL + */ + public function get_full_url() + { + return generate_board_url() . "/viewtopic.{$this->php_ext}?t{$this->item_id}"; + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['poster_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->item_id = $post['post_id']; + + $this->set_data('poster_id', $post['poster_id']); + + $this->set_data('topic_title', $post['topic_title']); + + $this->set_data('post_username', $post['post_username']); + + $this->set_data('forum_name', $post['forum_name']); + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index e6022e3b79..23f205dcc7 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -385,6 +385,9 @@ $lang = array_merge($lang, array( 'NOT_AUTHORISED' => 'You are not authorised to access this area.', 'NOT_WATCHING_FORUM' => 'You are no longer subscribed to updates on this forum.', 'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.', + 'NOTIFICATION_PM' => '%1$s sent you a Private Message titled: %2$s.', + 'NOTIFICATION_POST' => '%1$s replied to the topic "%2$s".', + 'NOTIFICATION_TOPIC' => '%1$s posted a new topic "%2$s" in the forum "%3$s".', 'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.', 'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: %1$s', 'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.', -- cgit v1.2.1 From e09f25d59707fc842b073fa2909cefc3d16ecbf3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 14:55:40 -0500 Subject: [ticket/11103] Update notifications on post/topic edit PHPBB3-11103 --- phpBB/includes/functions_posting.php | 19 ++++++++++++++++--- phpBB/includes/notifications/service.php | 6 +++--- phpBB/includes/notifications/type/post.php | 14 +++++++++++--- phpBB/includes/notifications/type/topic.php | 8 ++++---- 4 files changed, 34 insertions(+), 13 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6c5c4535a3..64840bfa51 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2220,12 +2220,18 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications - if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) + if ($post_approval) { $notifications = $phpbb_container->get('notifications'); switch ($mode) { + case 'post' : + $notifications->add_notifications('topic', array_merge($data, array( + 'post_username' => $username, + ))); + break; + case 'reply' : case 'quote' : $notifications->add_notifications('post', array_merge($data, array( @@ -2233,8 +2239,15 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u ))); break; - case 'post' : - $notifications->add_notifications('topic', array_merge($data, array( + case 'edit_topic' : + case 'edit_first_post' : + case 'edit' : + case 'edit_last_post' : + $notifications->update_notifications('topic', array_merge($data, array( + 'post_username' => $username, + 'topic_title' => $subject, + ))); + $notifications->update_notifications('post', array_merge($data, array( 'post_username' => $username, ))); break; diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 463798fa07..112cbae3fd 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -58,10 +58,10 @@ class phpbb_notifications_service // Merge default options $options = array_merge(array( 'user_id' => $user->data['user_id'], - 'limit' => 5, - 'start' => 0, 'order_by' => 'time', 'order_dir' => 'DESC', + 'limit' => 5, + 'start' => 0, ), $options); $notifications = $user_ids = array(); @@ -147,7 +147,7 @@ class phpbb_notifications_service foreach ($methods as $method) { // setup the notification methods and add the notification to the queue - if ($method) + if ($method) // blank means we just insert it as a notification, but do not notify them by any other means { if (!isset($notification_methods[$method])) { diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 04e269737e..efada4220e 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -96,7 +96,11 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } - return $this->phpbb_container->get('user')->lang('NOTIFICATION_POST', $username, censor_text($this->get_data('topic_title'))); + return $this->phpbb_container->get('user')->lang( + 'NOTIFICATION_POST', + $username, + censor_text($this->get_data('topic_title')) + ); } /** @@ -117,7 +121,11 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $username = $user_data['username']; } - return $this->phpbb_container->get('user')->lang('NOTIFICATION_POST', $username, censor_text($this->get_data('topic_title'))); + return $this->phpbb_container->get('user')->lang( + 'NOTIFICATION_POST', + $username, + censor_text($this->get_data('topic_title')) + ); } /** @@ -166,7 +174,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('topic_title', $post['topic_title']); - $this->set_data('post_username', $post['post_username']); + $this->set_data('post_username', (($post['post_username'] != $this->phpbb_container->get('user')->data['username']) ? $post['post_username'] : '')); $this->set_data('forum_name', $post['forum_name']); diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index f58419a633..ee8c21fd9c 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -137,7 +137,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function get_url() { - return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t{$this->item_id}"); + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t={$this->item_id}"); } /** @@ -147,7 +147,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function get_full_url() { - return generate_board_url() . "/viewtopic.{$this->php_ext}?t{$this->item_id}"; + return generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->item_id}"; } /** @@ -170,13 +170,13 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function create_insert_array($post) { - $this->item_id = $post['post_id']; + $this->item_id = $post['topic_id']; $this->set_data('poster_id', $post['poster_id']); $this->set_data('topic_title', $post['topic_title']); - $this->set_data('post_username', $post['post_username']); + $this->set_data('post_username', (($post['post_username'] != $this->phpbb_container->get('user')->data['username']) ? $post['post_username'] : '')); $this->set_data('forum_name', $post['forum_name']); -- cgit v1.2.1 From 5502f3c4aa30ce72131f2a55bcfa3db7a4059427 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 17:20:39 -0500 Subject: [ticket/11103] Restyle the notification list Very rough (lots of inline CSS, very ugly) PHPBB3-11103 --- phpBB/includes/functions.php | 2 +- phpBB/includes/functions_display.php | 7 ++-- phpBB/includes/mcp/mcp_queue.php | 4 +- phpBB/includes/notifications/service.php | 14 +++++++ phpBB/includes/notifications/type/base.php | 44 +++++++++++++--------- phpBB/includes/notifications/type/pm.php | 8 ++++ phpBB/includes/notifications/type/post.php | 8 ++++ phpBB/includes/notifications/type/topic.php | 8 ++++ .../styles/prosilver/template/overall_header.html | 25 ++++++++---- phpBB/styles/prosilver/theme/common.css | 8 ++++ 10 files changed, 98 insertions(+), 30 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 7632ea1fcb..e5c7839894 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5096,7 +5096,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $phpbb_notifications = $phpbb_container->get('notifications'); foreach ($phpbb_notifications->load_notifications() as $notification) { - $notification->display(); + $template->assign_block_vars('notifications', $notification->prepare_for_display()); } // application/xhtml+xml not used because of IE diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 8328b9ee7a..84cb47867e 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1319,10 +1319,11 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank * @param string $avatar_height Height of users avatar * @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 +* @param string $custom_css Custom CSS class to apply to the image * * @return string Avatar image */ -function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false) +function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false, $custom_css = '') { global $user, $config, $phpbb_root_path, $phpEx; global $phpbb_dispatcher; @@ -1343,7 +1344,7 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ * @var string overwrite_avatar If set, this string will be the avatar * @since 3.1-A1 */ - $vars = array('avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'alt', 'ignore_config', 'overwrite_avatar'); + $vars = array('avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'alt', 'ignore_config', 'overwrite_avatar', 'custom_css'); extract($phpbb_dispatcher->trigger_event('core.user_get_avatar', compact($vars))); if ($overwrite_avatar) @@ -1385,7 +1386,7 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ } $avatar_img .= $avatar; - return '' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . ''; + return '' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . ''; } /** diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index d5c431e478..1d9a2dfedc 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -451,7 +451,7 @@ function approve_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; - global $request; + global $request, $phpbb_container; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -634,6 +634,8 @@ function approve_post($post_id_list, $id, $mode) // Send out normal user notifications $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + $notifications = $phpbb_container->get('notifications'); + foreach ($post_info as $post_id => $post_data) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 112cbae3fd..5dcfeb127b 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -210,6 +210,20 @@ class phpbb_notifications_service $this->db->sql_query($sql); } + public function add_subscription($item_type, $item_id, $method = '') + { + $this->get_item_type_class_name($item_type); + + $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $this->db->sql_build_array('INSERT', array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => $this->phpbb_container->get('user')->data['user_id'], + 'method' => $method, + )); + $this->db->sql_query($sql); + } + /** * Load user helper * diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index df273f9e81..e60b20c449 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -104,28 +104,23 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type } /** - * Output the notification to the template - * - * @param array $options Array of options - * template_block Template block name to output to (Default: notifications) + * Prepare to output the notification to the template */ - public function display($options = array()) + public function prepare_for_display() { - $template = $this->phpbb_container->get('template'); $user = $this->phpbb_container->get('user'); - // Merge default options - $options = array_merge(array( - 'template_block' => 'notifications', - ), $options); + return array( + 'AVATAR' => $this->get_avatar(), + + 'FORMATTED_TITLE' => $this->get_formatted_title(), + 'TITLE' => $this->get_title(), - $template->assign_block_vars($options['template_block'], array( - 'TITLE' => $this->get_formatted_title(), - 'URL' => $this->get_url(), - 'TIME' => $user->format_date($this->time), + 'URL' => $this->get_url(), + 'TIME' => $user->format_date($this->time), - 'UNREAD' => $this->unread, - )); + 'UNREAD' => $this->unread, + ); } /** @@ -206,6 +201,13 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $rowset; } + protected function _get_avatar($user_id) + { + $user = $this->service->get_user($user_id); + + return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], $user['username'], false, 'notifications-avatar'); + } + /** * Get the formatted title of this notification (fall-back) * @@ -217,7 +219,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type } /** - * URL to unsubscribe to this notification + * URL to unsubscribe to this notification (fall-back) * * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item */ @@ -225,4 +227,12 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type { return false; } + + /** + * Get the user's avatar (fall-back) + */ + public function get_avatar() + { + return ''; + } } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 3368b171df..c78efcdd55 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -90,6 +90,14 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base return $notify_users; } + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('from_user_id')); + } + /** * Get the HTML formatted title of this notification * diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index efada4220e..f374114890 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -78,6 +78,14 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return $notify_users; } + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('poster_id')); + } + /** * Get the HTML formatted title of this notification * diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index ee8c21fd9c..51a95d5e19 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -78,6 +78,14 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base return $notify_users; } + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('poster_id')); + } + /** * Get the HTML formatted title of this notification * diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index 77fdb230ad..1695f8d03a 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -132,6 +132,22 @@