From 3c46aeb0055d88919e1438941c34b97445a17878 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Feb 2014 16:32:25 +0100 Subject: [PATCH] [ticket/12169] Allow displaying profile fields on memberlist We can not sort by profile field values atm. And also I'm not sure whether this is possible at all. PHPBB3-12169 --- phpBB/memberlist.php | 35 +++++++++++++++---- phpBB/phpbb/profilefields/manager.php | 30 ++++++++++++++-- .../prosilver/template/memberlist_body.html | 19 ++++++++-- .../template/ucp_pm_viewmessage.html | 1 - .../prosilver/template/viewtopic_body.html | 1 - .../subsilver2/template/viewtopic_body.html | 1 - 6 files changed, 72 insertions(+), 15 deletions(-) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index e8cbcc94ef..166d4d8959 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -998,8 +998,8 @@ switch ($mode) $pagination = $phpbb_container->get('pagination'); // Sorting - $sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_LOCATION'], 'c' => $user->lang['SORT_JOINED'], 'd' => $user->lang['SORT_POST_COUNT'], 'f' => $user->lang['WEBSITE'], 'g' => $user->lang['ICQ'], 'h' => $user->lang['AIM'], 'i' => $user->lang['MSNM'], 'j' => $user->lang['YIM'], 'k' => $user->lang['JABBER']); - $sort_key_sql = array('a' => 'u.username_clean', 'b' => 'u.user_from', 'c' => 'u.user_regdate', 'd' => 'u.user_posts', 'f' => 'u.user_website', 'g' => 'u.user_icq', 'h' => 'u.user_aim', 'i' => 'u.user_msnm', 'j' => 'u.user_yim', 'k' => 'u.user_jabber'); + $sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'c' => $user->lang['SORT_JOINED'], 'd' => $user->lang['SORT_POST_COUNT'], 'f' => $user->lang['WEBSITE'], 'g' => $user->lang['ICQ'], 'h' => $user->lang['AIM'], 'i' => $user->lang['MSNM'], 'j' => $user->lang['YIM'], 'k' => $user->lang['JABBER']); + $sort_key_sql = array('a' => 'u.username_clean', 'c' => 'u.user_regdate', 'd' => 'u.user_posts', 'f' => 'u.user_website', 'g' => 'u.user_icq', 'h' => 'u.user_aim', 'i' => 'u.user_msnm', 'j' => 'u.user_yim', 'k' => 'u.user_jabber'); if ($auth->acl_get('a_user')) { @@ -1502,6 +1502,20 @@ switch ($mode) $user_list[] = (int) $row['user_id']; } $db->sql_freeresult($result); + + // Load custom profile fields + if ($config['load_cpf_memberlist']) + { + $cp = $phpbb_container->get('profilefields.manager'); + + // @todo: Add separate setting for this. + $cp_row = $cp->generate_profile_fields_template('headlines', false, false, 'field_show_on_pm'); + foreach ($cp_row as $profile_field) + { + $template->assign_block_vars('custom_fields', $profile_field); + } + } + $leaders_set = false; // So, did we get any users? if (sizeof($user_list)) @@ -1552,10 +1566,20 @@ switch ($mode) // Load custom profile fields if ($config['load_cpf_memberlist']) { - $cp = $phpbb_container->get('profilefields.manager'); - // Grab all profile fields from users in id cache for later use - similar to the poster cache $profile_fields_cache = $cp->generate_profile_fields_template('grab', $user_list); + + // Filter the fields we don't want to show + foreach ($profile_fields_cache as $user_id => $user_profile_fields) + { + foreach ($user_profile_fields as $field_ident => $profile_field) + { + if (!$profile_field['data']['field_show_on_pm']) + { + unset($profile_fields_cache[$user_id][$field_ident]); + } + } + } } // If we sort by last active date we need to adjust the id cache due to user_lastvisit not being the last active date... @@ -1627,12 +1651,10 @@ switch ($mode) 'U_FIND_MEMBER' => ($config['load_search'] || $auth->acl_get('a_')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser' . (($start) ? "&start=$start" : '') . (!empty($params) ? '&' . implode('&', $params) : '')) : '', 'U_HIDE_FIND_MEMBER' => ($mode == 'searchuser' || ($mode == '' && $submit)) ? $u_hide_find_member : '', 'U_SORT_USERNAME' => $sort_url . '&sk=a&sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'), - 'U_SORT_FROM' => $sort_url . '&sk=b&sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'), 'U_SORT_JOINED' => $sort_url . '&sk=c&sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'), 'U_SORT_POSTS' => $sort_url . '&sk=d&sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'), 'U_SORT_EMAIL' => $sort_url . '&sk=e&sd=' . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'), 'U_SORT_WEBSITE' => $sort_url . '&sk=f&sd=' . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'), - 'U_SORT_LOCATION' => $sort_url . '&sk=b&sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'), 'U_SORT_ICQ' => $sort_url . '&sk=g&sd=' . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'), 'U_SORT_AIM' => $sort_url . '&sk=h&sd=' . (($sort_key == 'h' && $sort_dir == 'a') ? 'd' : 'a'), 'U_SORT_MSN' => $sort_url . '&sk=i&sd=' . (($sort_key == 'i' && $sort_dir == 'a') ? 'd' : 'a'), @@ -1764,7 +1786,6 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f 'U_YIM' => ($data['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($data['user_yim']) . '&.src=pg' : '', 'U_MSN' => ($data['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=msnm&u=' . $user_id) : '', 'U_JABBER' => ($data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $user_id) : '', - 'LOCATION' => ($data['user_from']) ? $data['user_from'] : '', 'USER_ICQ' => $data['user_icq'], 'USER_AIM' => $data['user_aim'], diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index ead978374c..3948f32e93 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -246,9 +246,35 @@ class manager * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template */ - public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false) + public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false, $restrict_option = false) { - if ($mode == 'grab') + if ($mode == 'headlines') + { + if (!sizeof($this->profile_cache)) + { + $this->build_cache(); + } + + // Go through the fields in correct order + foreach ($this->profile_cache as $field_ident => $field_data) + { + if ($restrict_option && !$field_data[$restrict_option]) + { + continue; + } + + $profile_field = $this->type_collection[$field_data['field_type']]; + + $tpl_fields[] = array( + 'PROFILE_FIELD_TYPE' => $field_data['field_type'], + 'PROFILE_FIELD_NAME' => $profile_field->get_field_name($field_data['lang_name']), + 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($field_data['lang_explain']), + ); + } + + return $tpl_fields; + } + else if ($mode == 'grab') { if (!is_array($user_id)) { diff --git a/phpBB/styles/prosilver/template/memberlist_body.html b/phpBB/styles/prosilver/template/memberlist_body.html index 606314f9d0..c155d431fa 100644 --- a/phpBB/styles/prosilver/template/memberlist_body.html +++ b/phpBB/styles/prosilver/template/memberlist_body.html @@ -60,7 +60,10 @@ {L_RANK}{L_GROUP_LEADER}{L_USERNAME} {L_POSTS} - {L_WEBSITE}{L_COMMA_SEPARATOR}{L_LOCATION} + + {L_WEBSITE} + {L_COMMA_SEPARATOR} {custom_fields.PROFILE_FIELD_NAME} + {L_JOINED} {L_LAST_ACTIVE} @@ -91,7 +94,10 @@ {L_RANK}{L_GROUP_MEMBERS}{L_USERNAME} {L_POSTS} - {L_WEBSITE}{L_COMMA_SEPARATOR}{L_LOCATION} + + {L_WEBSITE} + {L_COMMA_SEPARATOR} {custom_fields.PROFILE_FIELD_NAME} + {L_JOINED} {L_LAST_ACTIVE} @@ -111,7 +117,14 @@ {memberrow.RANK_IMG}{memberrow.RANK_TITLE} {memberrow.USERNAME_FULL}
{L_SELECT} ] {memberrow.POSTS}{memberrow.POSTS} -
{memberrow.U_SHORT_WWW}
{memberrow.LOCATION}
  + + +
{memberrow.U_SHORT_WWW}
+
{memberrow.custom_fields.PROFILE_FIELD_VALUE}
+ +   + + {memberrow.JOINED} {memberrow.VISITED}  diff --git a/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html b/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html index 208aeb9399..3623489ccf 100644 --- a/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html +++ b/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html @@ -24,7 +24,6 @@
{L_POSTS}{L_COLON} {AUTHOR_POSTS}
{L_JOINED}{L_COLON} {AUTHOR_JOINED}
-
{L_LOCATION}{L_COLON} {AUTHOR_FROM}
diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html index 338c67dd33..1818f9c3d8 100644 --- a/phpBB/styles/prosilver/template/viewtopic_body.html +++ b/phpBB/styles/prosilver/template/viewtopic_body.html @@ -129,7 +129,6 @@
{L_POSTS}{L_COLON} {postrow.POSTER_POSTS}
{L_JOINED}{L_COLON} {postrow.POSTER_JOINED}
-
{L_LOCATION}{L_COLON} {postrow.POSTER_FROM}
diff --git a/phpBB/styles/subsilver2/template/viewtopic_body.html b/phpBB/styles/subsilver2/template/viewtopic_body.html index c3f8bf205b..141a38a138 100644 --- a/phpBB/styles/subsilver2/template/viewtopic_body.html +++ b/phpBB/styles/subsilver2/template/viewtopic_body.html @@ -201,7 +201,6 @@
{L_JOINED}{L_COLON} {postrow.POSTER_JOINED}
{L_POSTS}{L_COLON} {postrow.POSTER_POSTS} -
{L_LOCATION}{L_COLON} {postrow.POSTER_FROM}