From 8671e40217f8a14fc653a8a3570e7ee93101407f Mon Sep 17 00:00:00 2001 From: "Forumhulp.com" Date: Mon, 4 Aug 2014 14:11:25 +0200 Subject: [PATCH 1/6] [ticket/12993] Improve get_user_ranks Explanation in http://area51.phpbb.com/phpBB/viewtopic.php?f=108&t=46051 PHPBB3-12993 --- phpBB/includes/functions_display.php | 32 +++++++++++++++++------ phpBB/includes/mcp/mcp_warn.php | 4 +-- phpBB/includes/ucp/ucp_pm_viewmessage.php | 2 +- phpBB/memberlist.php | 4 +-- phpBB/viewtopic.php | 4 +-- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 78137d075b..1c80855163 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1378,7 +1378,7 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, /** * Get user rank title and image * -* @param int $user_rank the current stored users rank id +* @param array $user_data the current stored users data * @param int $user_posts the users number of posts * @param string &$rank_title the rank title will be stored here after execution * @param string &$rank_img the rank image as full img tag is stored here after execution @@ -1386,9 +1386,21 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, * * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false */ -function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src) +function get_user_rank($user_data, $user_posts, &$rank_title, &$rank_img, &$rank_img_src) { - global $ranks, $config, $phpbb_root_path, $phpbb_path_helper; + global $ranks, $config, $phpbb_root_path, $phpbb_path_helper, $phpbb_dispatcher; + + /** + * Preparing a user's rank before displaying + * + * @event core.modify_user_rank + * @var array user_data Array with user's data + * @var int user_posts User_posts to change + * @since 3.1.0-RC3 + */ + + $vars = array('user_data', 'user_posts'); + extract($phpbb_dispatcher->trigger_event('core.modify_user_rank', compact($vars))); if (empty($ranks)) { @@ -1396,11 +1408,14 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank $ranks = $cache->obtain_ranks(); } - if (!empty($user_rank)) + if (!empty($user_data['user_rank'])) { - $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : ''; - $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image']) : ''; - $rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '' . $ranks['special'][$user_rank]['rank_title'] . '' : ''; + + $rank_title = (isset($ranks['special'][$user_data['user_rank']]['rank_title'])) ? $ranks['special'][$user_data['user_rank']]['rank_title'] : ''; + + $rank_img_src = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_data['user_rank']]['rank_image']) : ''; + + $rank_img = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? '' . $ranks['special'][$user_data['user_rank']]['rank_title'] . '' : ''; } else if ($user_posts !== false) { @@ -1420,6 +1435,7 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank } } + /** * Prepare profile data */ @@ -1431,7 +1447,7 @@ function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabl $user_id = $data['user_id']; $rank_title = $rank_img = $rank_img_src = ''; - get_user_rank($data['user_rank'], (($user_id == ANONYMOUS) ? false : $data['user_posts']), $rank_title, $rank_img, $rank_img_src); + get_user_rank($data, (($user_id == ANONYMOUS) ? false : $data['user_posts']), $rank_title, $rank_img, $rank_img_src); if ((!empty($data['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_user')) { diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php index fb47522644..1629e62872 100644 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -341,7 +341,7 @@ class mcp_warn include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - get_user_rank($user_row['user_rank'], $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); + get_user_rank($user_row, $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); $avatar_img = phpbb_get_user_avatar($user_row); $template->assign_vars(array( @@ -490,7 +490,7 @@ class mcp_warn { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - get_user_rank($user_row['user_rank'], $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); + get_user_rank($user_row, $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); $avatar_img = phpbb_get_user_avatar($user_row); // OK, they didn't submit a warning so lets build the page for them to do so diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index d5a1dbae87..3b3a45a8ff 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -408,7 +408,7 @@ function get_user_information($user_id, $user_row) include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - get_user_rank($user_row['user_rank'], $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']); + get_user_rank($user_row, $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']); if ((!empty($user_row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email')) { diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 4f4dcb1b41..761c1df679 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -284,7 +284,7 @@ switch ($mode) } $rank_title = $rank_img = $rank_img_src = ''; - get_user_rank($row['user_rank'], (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src); + get_user_rank($row, (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src); $template->assign_block_vars('group.user', array( 'USER_ID' => $row['user_id'], @@ -1083,7 +1083,7 @@ switch ($mode) $rank_title = $rank_img = $rank_img_src = ''; if ($group_row['group_rank']) { - get_user_rank($group_row['group_rank'], false, $rank_title, $rank_img, $rank_img_src); + get_user_rank($group_roup, false, $rank_title, $rank_img, $rank_img_src); if ($rank_img) { diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 8d7ab5323d..c9d7d884c4 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1174,7 +1174,7 @@ while ($row = $db->sql_fetchrow($result)) $user_cache[$poster_id] = $user_cache_data; - get_user_rank($row['user_rank'], false, $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); + get_user_rank($row, false, $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); } else { @@ -1238,7 +1238,7 @@ while ($row = $db->sql_fetchrow($result)) $user_cache[$poster_id] = $user_cache_data; - get_user_rank($row['user_rank'], $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); + get_user_rank($row, $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); if ((!empty($row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email')) { From 685bdc87e6480597c7d7f30a7b9477c543099d2e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 18 Aug 2014 14:04:11 +0200 Subject: [PATCH 2/6] [ticket/12993] Fix user_loader and memberlist PHPBB3-12993 --- phpBB/memberlist.php | 2 +- phpBB/phpbb/user_loader.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 761c1df679..a1737116cf 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1083,7 +1083,7 @@ switch ($mode) $rank_title = $rank_img = $rank_img_src = ''; if ($group_row['group_rank']) { - get_user_rank($group_roup, false, $rank_title, $rank_img, $rank_img_src); + get_user_rank($group_row, false, $rank_title, $rank_img, $rank_img_src); if ($rank_img) { diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index c9707ee432..e6a2429163 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -223,7 +223,7 @@ class user_loader 'rank_img_src', ); - get_user_rank($user['user_rank'], (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); + get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); return $rank; } From 496cc64bc63befc2bb6f250e1712cd5a00986aef Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 18 Aug 2014 16:13:32 +0200 Subject: [PATCH 3/6] [ticket/12993] Rename to phpbb_get_user_rank PHPBB3-12993 --- phpBB/includes/functions_compatibility.php | 18 ++++++++++++++++++ phpBB/includes/functions_display.php | 7 +++---- phpBB/includes/mcp/mcp_warn.php | 4 ++-- phpBB/includes/ucp/ucp_pm_viewmessage.php | 2 +- phpBB/memberlist.php | 4 ++-- phpBB/phpbb/user_loader.php | 2 +- phpBB/viewtopic.php | 4 ++-- 7 files changed, 29 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index 093cb19538..b371978ee5 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -166,3 +166,21 @@ function update_foes($group_id = false, $user_id = false) global $db, $auth; return phpbb_update_foes($db, $auth, $group_id, $user_id); } + +/** +* Get user rank title and image +* +* @param int $user_rank the current stored users rank id +* @param int $user_posts the users number of posts +* @param string &$rank_title the rank title will be stored here after execution +* @param string &$rank_img the rank image as full img tag is stored here after execution +* @param string &$rank_img_src the rank image source is stored here after execution +* +* @deprecated 3.1 +* +* Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false +*/ +function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src) +{ + phpbb_get_user_rank(array('user_rank' => $user_rank), $user_posts, $rank_title, $rank_img, $rank_img_src); +} diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 1c80855163..75b86b4f71 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1386,7 +1386,7 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, * * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false */ -function get_user_rank($user_data, $user_posts, &$rank_title, &$rank_img, &$rank_img_src) +function phpbb_get_user_rank($user_data, $user_posts, &$rank_title, &$rank_img, &$rank_img_src) { global $ranks, $config, $phpbb_root_path, $phpbb_path_helper, $phpbb_dispatcher; @@ -1396,7 +1396,7 @@ function get_user_rank($user_data, $user_posts, &$rank_title, &$rank_img, &$rank * @event core.modify_user_rank * @var array user_data Array with user's data * @var int user_posts User_posts to change - * @since 3.1.0-RC3 + * @since 3.1.0-RC4 */ $vars = array('user_data', 'user_posts'); @@ -1435,7 +1435,6 @@ function get_user_rank($user_data, $user_posts, &$rank_title, &$rank_img, &$rank } } - /** * Prepare profile data */ @@ -1447,7 +1446,7 @@ function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabl $user_id = $data['user_id']; $rank_title = $rank_img = $rank_img_src = ''; - get_user_rank($data, (($user_id == ANONYMOUS) ? false : $data['user_posts']), $rank_title, $rank_img, $rank_img_src); + phpbb_get_user_rank($data, (($user_id == ANONYMOUS) ? false : $data['user_posts']), $rank_title, $rank_img, $rank_img_src); if ((!empty($data['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_user')) { diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php index 1629e62872..356988d2e8 100644 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -341,7 +341,7 @@ class mcp_warn include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - get_user_rank($user_row, $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); + phpbb_get_user_rank($user_row, $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); $avatar_img = phpbb_get_user_avatar($user_row); $template->assign_vars(array( @@ -490,7 +490,7 @@ class mcp_warn { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - get_user_rank($user_row, $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); + phpbb_get_user_rank($user_row, $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); $avatar_img = phpbb_get_user_avatar($user_row); // OK, they didn't submit a warning so lets build the page for them to do so diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index 3b3a45a8ff..c98aa39b5b 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -408,7 +408,7 @@ function get_user_information($user_id, $user_row) include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - get_user_rank($user_row, $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']); + phpbb_get_user_rank($user_row, $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']); if ((!empty($user_row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email')) { diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index a1737116cf..4a117ea9e6 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -284,7 +284,7 @@ switch ($mode) } $rank_title = $rank_img = $rank_img_src = ''; - get_user_rank($row, (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src); + phpbb_get_user_rank($row, (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src); $template->assign_block_vars('group.user', array( 'USER_ID' => $row['user_id'], @@ -1083,7 +1083,7 @@ switch ($mode) $rank_title = $rank_img = $rank_img_src = ''; if ($group_row['group_rank']) { - get_user_rank($group_row, false, $rank_title, $rank_img, $rank_img_src); + phpbb_get_user_rank($group_row, false, $rank_title, $rank_img, $rank_img_src); if ($rank_img) { diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index e6a2429163..35199d8864 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -223,7 +223,7 @@ class user_loader 'rank_img_src', ); - get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); + phpbb_get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); return $rank; } diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index c9d7d884c4..89b5a5033b 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1174,7 +1174,7 @@ while ($row = $db->sql_fetchrow($result)) $user_cache[$poster_id] = $user_cache_data; - get_user_rank($row, false, $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); + phpbb_get_user_rank($row, false, $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); } else { @@ -1238,7 +1238,7 @@ while ($row = $db->sql_fetchrow($result)) $user_cache[$poster_id] = $user_cache_data; - get_user_rank($row, $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); + phpbb_get_user_rank($row, $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); if ((!empty($row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email')) { From 5e7d9d2fcf5a78ef97287c635310c6ea28572464 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 18 Aug 2014 18:44:23 +0200 Subject: [PATCH 4/6] [ticket/12993] Fix includes of functions_display PHPBB3-12993 --- phpBB/includes/functions_compatibility.php | 6 ++++++ phpBB/includes/mcp/mcp_warn.php | 4 ++-- phpBB/includes/ucp/ucp_pm_viewmessage.php | 2 +- phpBB/phpbb/user_loader.php | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index b371978ee5..efd586c234 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -182,5 +182,11 @@ function update_foes($group_id = false, $user_id = false) */ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src) { + global $phpbb_root_path, $phpEx; + if (!function_exists('phpbb_get_user_rank')) + { + include($phpbb_root_path . 'includes/functions_display.' . $phpEx); + } + phpbb_get_user_rank(array('user_rank' => $user_rank), $user_posts, $rank_title, $rank_img, $rank_img_src); } diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php index 356988d2e8..b4b6656499 100644 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -336,7 +336,7 @@ class mcp_warn $message = generate_text_for_display($user_row['post_text'], $user_row['bbcode_uid'], $user_row['bbcode_bitfield'], $parse_flags, true); // Generate the appropriate user information for the user we are looking at - if (!function_exists('get_user_rank')) + if (!function_exists('phpbb_get_user_rank')) { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } @@ -486,7 +486,7 @@ class mcp_warn } // Generate the appropriate user information for the user we are looking at - if (!function_exists('get_user_rank')) + if (!function_exists('phpbb_get_user_rank')) { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index c98aa39b5b..a36ee398f4 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -403,7 +403,7 @@ function get_user_information($user_id, $user_row) $user_row['avatar'] = ($user->optionget('viewavatars')) ? phpbb_get_user_avatar($user_row) : ''; - if (!function_exists('get_user_rank')) + if (!function_exists('phpbb_get_user_rank')) { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 35199d8864..4da2b383c6 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -212,7 +212,7 @@ class user_loader return ''; } - if (!function_exists('get_user_rank')) + if (!function_exists('phpbb_get_user_rank')) { include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); } From fe1ab6d2efe7389ab5deb6cab0d721a1fa80c503 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 19 Aug 2014 22:25:01 +0200 Subject: [PATCH 5/6] [ticket/12993] Return an array instead of reference passing PHPBB3-12993 --- phpBB/includes/functions_compatibility.php | 5 ++- phpBB/includes/functions_display.php | 36 +++++++++++++--------- phpBB/includes/mcp/mcp_warn.php | 12 ++++---- phpBB/includes/ucp/ucp_pm_viewmessage.php | 5 ++- phpBB/memberlist.php | 23 ++++++++------ phpBB/phpbb/user_loader.php | 5 ++- phpBB/viewtopic.php | 10 ++++-- 7 files changed, 60 insertions(+), 36 deletions(-) diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index efd586c234..7dcb1fb9c1 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -188,5 +188,8 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - phpbb_get_user_rank(array('user_rank' => $user_rank), $user_posts, $rank_title, $rank_img, $rank_img_src); + $rank_data = phpbb_get_user_rank(array('user_rank' => $user_rank), $user_posts); + $rank_title = $rank_data['title']; + $rank_img = $rank_data['img']; + $rank_img_src = $rank_data['img_src']; } diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 75b86b4f71..f12d557fd2 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1380,16 +1380,21 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, * * @param array $user_data the current stored users data * @param int $user_posts the users number of posts -* @param string &$rank_title the rank title will be stored here after execution -* @param string &$rank_img the rank image as full img tag is stored here after execution -* @param string &$rank_img_src the rank image source is stored here after execution +* +* @return array An associative array containing the rank title (title), the rank image source (img) and the rank image as full img tag (img) * * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false */ -function phpbb_get_user_rank($user_data, $user_posts, &$rank_title, &$rank_img, &$rank_img_src) +function phpbb_get_user_rank($user_data, $user_posts) { global $ranks, $config, $phpbb_root_path, $phpbb_path_helper, $phpbb_dispatcher; + $user_rank_data = array( + 'title' => null, + 'img' => null, + 'img_src' => null, + ); + /** * Preparing a user's rank before displaying * @@ -1411,11 +1416,11 @@ function phpbb_get_user_rank($user_data, $user_posts, &$rank_title, &$rank_img, if (!empty($user_data['user_rank'])) { - $rank_title = (isset($ranks['special'][$user_data['user_rank']]['rank_title'])) ? $ranks['special'][$user_data['user_rank']]['rank_title'] : ''; + $user_rank_data['title'] = (isset($ranks['special'][$user_data['user_rank']]['rank_title'])) ? $ranks['special'][$user_data['user_rank']]['rank_title'] : ''; - $rank_img_src = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_data['user_rank']]['rank_image']) : ''; + $user_rank_data['img_src'] = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_data['user_rank']]['rank_image']) : ''; - $rank_img = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? '' . $ranks['special'][$user_data['user_rank']]['rank_title'] . '' : ''; + $user_rank_data['img'] = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? '' . $ranks['special'][$user_data['user_rank']]['rank_title'] . '' : ''; } else if ($user_posts !== false) { @@ -1425,14 +1430,16 @@ function phpbb_get_user_rank($user_data, $user_posts, &$rank_title, &$rank_img, { if ($user_posts >= $rank['rank_min']) { - $rank_title = $rank['rank_title']; - $rank_img_src = (!empty($rank['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image']) : ''; - $rank_img = (!empty($rank['rank_image'])) ? '' . $rank['rank_title'] . '' : ''; + $user_rank_data['title'] = $rank['rank_title']; + $user_rank_data['img_src'] = (!empty($rank['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image']) : ''; + $user_rank_data['img'] = (!empty($rank['rank_image'])) ? '' . $rank['rank_title'] . '' : ''; break; } } } } + + return $user_rank_data; } /** @@ -1445,8 +1452,7 @@ function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabl $username = $data['username']; $user_id = $data['user_id']; - $rank_title = $rank_img = $rank_img_src = ''; - phpbb_get_user_rank($data, (($user_id == ANONYMOUS) ? false : $data['user_posts']), $rank_title, $rank_img, $rank_img_src); + $user_rank_data = phpbb_get_user_rank($data, (($user_id == ANONYMOUS) ? false : $data['user_posts'])); if ((!empty($data['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_user')) { @@ -1527,7 +1533,7 @@ function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabl // Dump it out to the template $template_data = array( 'AGE' => $age, - 'RANK_TITLE' => $rank_title, + 'RANK_TITLE' => $user_rank_data['title'], 'JOINED' => $user->format_date($data['user_regdate']), 'LAST_ACTIVE' => (empty($last_active)) ? ' - ' : $user->format_date($last_active), 'POSTS' => ($data['user_posts']) ? $data['user_posts'] : 0, @@ -1543,8 +1549,8 @@ function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabl 'AVATAR_IMG' => phpbb_get_user_avatar($data), 'ONLINE_IMG' => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')), 'S_ONLINE' => ($config['load_onlinetrack'] && $online) ? true : false, - 'RANK_IMG' => $rank_img, - 'RANK_IMG_SRC' => $rank_img_src, + 'RANK_IMG' => $user_rank_data['img'], + 'RANK_IMG_SRC' => $user_rank_data['img_src'], 'S_JABBER_ENABLED' => ($config['jab_enable']) ? true : false, 'S_WARNINGS' => ($auth->acl_getf_global('m_') || $auth->acl_get('m_warn')) ? true : false, diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php index b4b6656499..37e4d62fb7 100644 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -341,7 +341,7 @@ class mcp_warn include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - phpbb_get_user_rank($user_row, $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); + $user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']); $avatar_img = phpbb_get_user_avatar($user_row); $template->assign_vars(array( @@ -350,13 +350,13 @@ class mcp_warn 'POST' => $message, 'USERNAME' => $user_row['username'], 'USER_COLOR' => (!empty($user_row['user_colour'])) ? $user_row['user_colour'] : '', - 'RANK_TITLE' => $rank_title, + 'RANK_TITLE' => $user_rank_data['title'], 'JOINED' => $user->format_date($user_row['user_regdate']), 'POSTS' => ($user_row['user_posts']) ? $user_row['user_posts'] : 0, 'WARNINGS' => ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0, 'AVATAR_IMG' => $avatar_img, - 'RANK_IMG' => $rank_img, + 'RANK_IMG' => $user_rank_data['img'], 'L_WARNING_POST_DEFAULT' => sprintf($user->lang['WARNING_POST_DEFAULT'], generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&p=$post_id#p$post_id"), @@ -490,14 +490,14 @@ class mcp_warn { include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - phpbb_get_user_rank($user_row, $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src); + $user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']); $avatar_img = phpbb_get_user_avatar($user_row); // OK, they didn't submit a warning so lets build the page for them to do so $template->assign_vars(array( 'U_POST_ACTION' => $this->u_action, - 'RANK_TITLE' => $rank_title, + 'RANK_TITLE' => $user_rank_data['title'], 'JOINED' => $user->format_date($user_row['user_regdate']), 'POSTS' => ($user_row['user_posts']) ? $user_row['user_posts'] : 0, 'WARNINGS' => ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0, @@ -508,7 +508,7 @@ class mcp_warn 'U_PROFILE' => get_username_string('profile', $user_row['user_id'], $user_row['username'], $user_row['user_colour']), 'AVATAR_IMG' => $avatar_img, - 'RANK_IMG' => $rank_img, + 'RANK_IMG' => $user_rank_data['img'], 'S_CAN_NOTIFY' => $s_can_notify, )); diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index a36ee398f4..2f34fd64a5 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -408,7 +408,10 @@ function get_user_information($user_id, $user_row) include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } - phpbb_get_user_rank($user_row, $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']); + $user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']); + $user_row['rank_title'] = $user_rank_data['title']; + $user_row['rank_image'] = $user_rank_data['img']; + $user_row['rank_image_src'] = $user_rank_data['img_src']; if ((!empty($user_row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email')) { diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 4a117ea9e6..919036a85c 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -283,21 +283,20 @@ switch ($mode) continue; } - $rank_title = $rank_img = $rank_img_src = ''; - phpbb_get_user_rank($row, (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src); + $user_rank_data = phpbb_get_user_rank($row, (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts'])); $template->assign_block_vars('group.user', array( 'USER_ID' => $row['user_id'], 'FORUMS' => $row['forums'], 'FORUM_OPTIONS' => (isset($row['forums_options'])) ? true : false, - 'RANK_TITLE' => $rank_title, + 'RANK_TITLE' => $user_rank_data['title'], 'GROUP_NAME' => $groups_ary[$row['default_group']]['group_name'], 'GROUP_COLOR' => $groups_ary[$row['default_group']]['group_colour'], 'U_GROUP' => $groups_ary[$row['default_group']]['u_group'], - 'RANK_IMG' => $rank_img, - 'RANK_IMG_SRC' => $rank_img_src, + 'RANK_IMG' => $user_rank_data['img'], + 'RANK_IMG_SRC' => $user_rank_data['img_src'], 'U_PM' => ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $row['user_id']) : '', @@ -1080,10 +1079,14 @@ switch ($mode) $avatar_img = phpbb_get_group_avatar($group_row); // ... same for group rank - $rank_title = $rank_img = $rank_img_src = ''; + $user_rank_data = array( + 'title' => null, + 'img' => null, + 'img_src' => null, + ); if ($group_row['group_rank']) { - phpbb_get_user_rank($group_row, false, $rank_title, $rank_img, $rank_img_src); + $user_rank_data = phpbb_get_user_rank($group_row, false); if ($rank_img) { @@ -1096,11 +1099,11 @@ switch ($mode) 'GROUP_NAME' => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'], 'GROUP_COLOR' => $group_row['group_colour'], 'GROUP_TYPE' => $user->lang['GROUP_IS_' . $group_row['l_group_type']], - 'GROUP_RANK' => $rank_title, + 'GROUP_RANK' => $user_rank_data['title'], 'AVATAR_IMG' => $avatar_img, - 'RANK_IMG' => $rank_img, - 'RANK_IMG_SRC' => $rank_img_src, + 'RANK_IMG' => $user_rank_data['img'], + 'RANK_IMG_SRC' => $user_rank_data['img_src'], 'U_PM' => ($auth->acl_get('u_sendpm') && $auth->acl_get('u_masspm_group') && $group_row['group_receive_pm'] && $config['allow_privmsg'] && $config['allow_mass_pm']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&g=' . $group_id) : '',) ); diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 4da2b383c6..24e663b150 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -223,7 +223,10 @@ class user_loader 'rank_img_src', ); - phpbb_get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); + $user_rank_data = phpbb_get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts'])); + $rank['rank_title'] = $user_rank_data['title']; + $rank['rank_img'] = $user_rank_data['img']; + $rank['rank_img_src'] = $user_rank_data['img_src']; return $rank; } diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 89b5a5033b..792bd296c0 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1174,7 +1174,10 @@ while ($row = $db->sql_fetchrow($result)) $user_cache[$poster_id] = $user_cache_data; - phpbb_get_user_rank($row, false, $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); + $user_rank_data = phpbb_get_user_rank($row, false); + $user_cache[$poster_id]['rank_title'] = $user_rank_data['title']; + $user_cache[$poster_id]['rank_image'] = $user_rank_data['img']; + $user_cache[$poster_id]['rank_image_src'] = $user_rank_data['img_src']; } else { @@ -1238,7 +1241,10 @@ while ($row = $db->sql_fetchrow($result)) $user_cache[$poster_id] = $user_cache_data; - phpbb_get_user_rank($row, $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); + $user_rank_data = phpbb_get_user_rank($row, false); + $user_cache[$poster_id]['rank_title'] = $user_rank_data['title']; + $user_cache[$poster_id]['rank_image'] = $user_rank_data['img']; + $user_cache[$poster_id]['rank_image_src'] = $user_rank_data['img_src']; if ((!empty($row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email')) { From cd7b21a7033d692b2f558dfd82bb67d3696d9e0e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 24 Sep 2014 16:04:24 +0200 Subject: [PATCH 6/6] [ticket/12993] Update doc block PHPBB3-12993 --- phpBB/includes/functions_compatibility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index 7dcb1fb9c1..47f31075c2 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -176,7 +176,7 @@ function update_foes($group_id = false, $user_id = false) * @param string &$rank_img the rank image as full img tag is stored here after execution * @param string &$rank_img_src the rank image source is stored here after execution * -* @deprecated 3.1 +* @deprecated 3.1.0-RC5 (To be removed: 3.3.0) * * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false */