PageRenderTime 56ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/phpBB/memberlist.php

https://github.com/Jipem/phpbb
PHP | 1650 lines | 1255 code | 273 blank | 122 comment | 290 complexity | 81637dfa917674bab1ef0fc11e136e82 MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * @ignore
  15. */
  16. define('IN_PHPBB', true);
  17. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  18. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  19. include($phpbb_root_path . 'common.' . $phpEx);
  20. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  21. $mode = request_var('mode', '');
  22. if ($mode === 'contactadmin')
  23. {
  24. define('SKIP_CHECK_BAN', true);
  25. define('SKIP_CHECK_DISABLED', true);
  26. }
  27. // Start session management
  28. $user->session_begin();
  29. $auth->acl($user->data);
  30. $user->setup(array('memberlist', 'groups'));
  31. // Setting a variable to let the style designer know where he is...
  32. $template->assign_var('S_IN_MEMBERLIST', true);
  33. // Grab data
  34. $action = request_var('action', '');
  35. $user_id = request_var('u', ANONYMOUS);
  36. $username = request_var('un', '', true);
  37. $group_id = request_var('g', 0);
  38. $topic_id = request_var('t', 0);
  39. // Redirect when old mode is used
  40. if ($mode == 'leaders')
  41. {
  42. send_status_line(301, 'Moved Permanently');
  43. redirect(append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=team'));
  44. }
  45. // Check our mode...
  46. if (!in_array($mode, array('', 'group', 'viewprofile', 'email', 'contact', 'contactadmin', 'searchuser', 'team', 'livesearch')))
  47. {
  48. trigger_error('NO_MODE');
  49. }
  50. switch ($mode)
  51. {
  52. case 'email':
  53. case 'contactadmin':
  54. break;
  55. case 'livesearch':
  56. if (!$config['allow_live_searches'])
  57. {
  58. trigger_error('LIVE_SEARCHES_NOT_ALLOWED');
  59. }
  60. // No break
  61. default:
  62. // Can this user view profiles/memberlist?
  63. if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
  64. {
  65. if ($user->data['user_id'] != ANONYMOUS)
  66. {
  67. trigger_error('NO_VIEW_USERS');
  68. }
  69. login_box('', ((isset($user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)])) ? $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $user->lang['LOGIN_EXPLAIN_MEMBERLIST']));
  70. }
  71. break;
  72. }
  73. $start = request_var('start', 0);
  74. $submit = (isset($_POST['submit'])) ? true : false;
  75. $default_key = 'c';
  76. $sort_key = request_var('sk', $default_key);
  77. $sort_dir = request_var('sd', 'a');
  78. // What do you want to do today? ... oops, I think that line is taken ...
  79. switch ($mode)
  80. {
  81. case 'team':
  82. // Display a listing of board admins, moderators
  83. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  84. $page_title = $user->lang['THE_TEAM'];
  85. $template_html = 'memberlist_team.html';
  86. $sql = 'SELECT *
  87. FROM ' . TEAMPAGE_TABLE . '
  88. ORDER BY teampage_position ASC';
  89. $result = $db->sql_query($sql, 3600);
  90. $teampage_data = $db->sql_fetchrowset($result);
  91. $db->sql_freeresult($result);
  92. $sql_ary = array(
  93. 'SELECT' => 'g.group_id, g.group_name, g.group_colour, g.group_type, ug.user_id as ug_user_id, t.teampage_id',
  94. 'FROM' => array(GROUPS_TABLE => 'g'),
  95. 'LEFT_JOIN' => array(
  96. array(
  97. 'FROM' => array(TEAMPAGE_TABLE => 't'),
  98. 'ON' => 't.group_id = g.group_id',
  99. ),
  100. array(
  101. 'FROM' => array(USER_GROUP_TABLE => 'ug'),
  102. 'ON' => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . (int) $user->data['user_id'],
  103. ),
  104. ),
  105. );
  106. $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
  107. $group_ids = $groups_ary = array();
  108. while ($row = $db->sql_fetchrow($result))
  109. {
  110. if ($row['group_type'] == GROUP_HIDDEN && !$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $user->data['user_id'])
  111. {
  112. $row['group_name'] = $user->lang['GROUP_UNDISCLOSED'];
  113. $row['u_group'] = '';
  114. }
  115. else
  116. {
  117. $row['group_name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
  118. $row['u_group'] = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']);
  119. }
  120. if ($row['teampage_id'])
  121. {
  122. // Only put groups into the array we want to display.
  123. // We are fetching all groups, to ensure we got all data for default groups.
  124. $group_ids[] = (int) $row['group_id'];
  125. }
  126. $groups_ary[(int) $row['group_id']] = $row;
  127. }
  128. $db->sql_freeresult($result);
  129. $sql_ary = array(
  130. 'SELECT' => 'u.user_id, u.group_id as default_group, u.username, u.username_clean, u.user_colour, u.user_rank, u.user_posts, u.user_allow_pm, g.group_id',
  131. 'FROM' => array(
  132. USER_GROUP_TABLE => 'ug',
  133. ),
  134. 'LEFT_JOIN' => array(
  135. array(
  136. 'FROM' => array(USERS_TABLE => 'u'),
  137. 'ON' => 'ug.user_id = u.user_id AND ug.user_pending = 0',
  138. ),
  139. array(
  140. 'FROM' => array(GROUPS_TABLE => 'g'),
  141. 'ON' => 'ug.group_id = g.group_id',
  142. ),
  143. ),
  144. 'WHERE' => $db->sql_in_set('g.group_id', $group_ids, false, true),
  145. 'ORDER_BY' => 'u.username_clean ASC',
  146. );
  147. $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
  148. $user_ary = $user_ids = $group_users = array();
  149. while ($row = $db->sql_fetchrow($result))
  150. {
  151. $row['forums'] = '';
  152. $row['forums_ary'] = array();
  153. $user_ary[(int) $row['user_id']] = $row;
  154. $user_ids[] = (int) $row['user_id'];
  155. $group_users[(int) $row['group_id']][] = (int) $row['user_id'];
  156. }
  157. $db->sql_freeresult($result);
  158. $user_ids = array_unique($user_ids);
  159. if (!empty($user_ids) && $config['teampage_forums'])
  160. {
  161. $template->assign_var('S_DISPLAY_MODERATOR_FORUMS', true);
  162. // Get all moderators
  163. $perm_ary = $auth->acl_get_list($user_ids, array('m_'), false);
  164. foreach ($perm_ary as $forum_id => $forum_ary)
  165. {
  166. foreach ($forum_ary as $auth_option => $id_ary)
  167. {
  168. foreach ($id_ary as $id)
  169. {
  170. if (!$forum_id)
  171. {
  172. $user_ary[$id]['forums'] = $user->lang['ALL_FORUMS'];
  173. }
  174. else
  175. {
  176. $user_ary[$id]['forums_ary'][] = $forum_id;
  177. }
  178. }
  179. }
  180. }
  181. $sql = 'SELECT forum_id, forum_name
  182. FROM ' . FORUMS_TABLE;
  183. $result = $db->sql_query($sql);
  184. $forums = array();
  185. while ($row = $db->sql_fetchrow($result))
  186. {
  187. $forums[$row['forum_id']] = $row['forum_name'];
  188. }
  189. $db->sql_freeresult($result);
  190. foreach ($user_ary as $user_id => $user_data)
  191. {
  192. if (!$user_data['forums'])
  193. {
  194. foreach ($user_data['forums_ary'] as $forum_id)
  195. {
  196. $user_ary[$user_id]['forums_options'] = true;
  197. if (isset($forums[$forum_id]))
  198. {
  199. if ($auth->acl_get('f_list', $forum_id))
  200. {
  201. $user_ary[$user_id]['forums'] .= '<option value="">' . $forums[$forum_id] . '</option>';
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }
  208. $parent_team = 0;
  209. foreach ($teampage_data as $team_data)
  210. {
  211. // If this team entry has no group, it's a category
  212. if (!$team_data['group_id'])
  213. {
  214. $template->assign_block_vars('group', array(
  215. 'GROUP_NAME' => $team_data['teampage_name'],
  216. ));
  217. $parent_team = (int) $team_data['teampage_id'];
  218. continue;
  219. }
  220. $group_data = $groups_ary[(int) $team_data['group_id']];
  221. $group_id = (int) $team_data['group_id'];
  222. if (!$team_data['teampage_parent'])
  223. {
  224. // If the group does not have a parent category, we display the groupname as category
  225. $template->assign_block_vars('group', array(
  226. 'GROUP_NAME' => $group_data['group_name'],
  227. 'GROUP_COLOR' => $group_data['group_colour'],
  228. 'U_GROUP' => $group_data['u_group'],
  229. ));
  230. }
  231. // Display group members.
  232. if (!empty($group_users[$group_id]))
  233. {
  234. foreach ($group_users[$group_id] as $user_id)
  235. {
  236. if (isset($user_ary[$user_id]))
  237. {
  238. $row = $user_ary[$user_id];
  239. if ($config['teampage_memberships'] == 1 && ($group_id != $groups_ary[$row['default_group']]['group_id']) && $groups_ary[$row['default_group']]['teampage_id'])
  240. {
  241. // Display users in their primary group, instead of the first group, when it is displayed on the teampage.
  242. continue;
  243. }
  244. $rank_title = $rank_img = $rank_img_src = '';
  245. get_user_rank($row['user_rank'], (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src);
  246. $template->assign_block_vars('group.user', array(
  247. 'USER_ID' => $row['user_id'],
  248. 'FORUMS' => $row['forums'],
  249. 'FORUM_OPTIONS' => (isset($row['forums_options'])) ? true : false,
  250. 'RANK_TITLE' => $rank_title,
  251. 'GROUP_NAME' => $groups_ary[$row['default_group']]['group_name'],
  252. 'GROUP_COLOR' => $groups_ary[$row['default_group']]['group_colour'],
  253. 'U_GROUP' => $groups_ary[$row['default_group']]['u_group'],
  254. 'RANK_IMG' => $rank_img,
  255. 'RANK_IMG_SRC' => $rank_img_src,
  256. '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&amp;mode=compose&amp;u=' . $row['user_id']) : '',
  257. 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
  258. 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
  259. 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
  260. 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
  261. ));
  262. if ($config['teampage_memberships'] != 2)
  263. {
  264. unset($user_ary[$user_id]);
  265. }
  266. }
  267. }
  268. }
  269. }
  270. $template->assign_vars(array(
  271. 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']))
  272. );
  273. break;
  274. case 'contact':
  275. $page_title = $user->lang['IM_USER'];
  276. $template_html = 'memberlist_im.html';
  277. if (!$auth->acl_get('u_sendim'))
  278. {
  279. trigger_error('NOT_AUTHORISED');
  280. }
  281. $presence_img = '';
  282. switch ($action)
  283. {
  284. case 'jabber':
  285. $lang = 'JABBER';
  286. $sql_field = 'user_jabber';
  287. $s_select = (@extension_loaded('xml') && $config['jab_enable']) ? 'S_SEND_JABBER' : 'S_NO_SEND_JABBER';
  288. $s_action = append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=$action&amp;u=$user_id");
  289. break;
  290. default:
  291. trigger_error('NO_MODE', E_USER_ERROR);
  292. break;
  293. }
  294. // Grab relevant data
  295. $sql = "SELECT user_id, username, user_email, user_lang, $sql_field
  296. FROM " . USERS_TABLE . "
  297. WHERE user_id = $user_id
  298. AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
  299. $result = $db->sql_query($sql);
  300. $row = $db->sql_fetchrow($result);
  301. $db->sql_freeresult($result);
  302. if (!$row)
  303. {
  304. trigger_error('NO_USER');
  305. }
  306. else if (empty($row[$sql_field]))
  307. {
  308. trigger_error('IM_NO_DATA');
  309. }
  310. // Post data grab actions
  311. switch ($action)
  312. {
  313. case 'jabber':
  314. add_form_key('memberlist_messaging');
  315. if ($submit && @extension_loaded('xml') && $config['jab_enable'])
  316. {
  317. if (check_form_key('memberlist_messaging'))
  318. {
  319. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  320. $subject = sprintf($user->lang['IM_JABBER_SUBJECT'], $user->data['username'], $config['server_name']);
  321. $message = utf8_normalize_nfc(request_var('message', '', true));
  322. if (empty($message))
  323. {
  324. trigger_error('EMPTY_MESSAGE_IM');
  325. }
  326. $messenger = new messenger(false);
  327. $messenger->template('profile_send_im', $row['user_lang']);
  328. $messenger->subject(htmlspecialchars_decode($subject));
  329. $messenger->replyto($user->data['user_email']);
  330. $messenger->set_addresses($row);
  331. $messenger->assign_vars(array(
  332. 'BOARD_CONTACT' => phpbb_get_board_contact($config, $phpEx),
  333. 'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']),
  334. 'TO_USERNAME' => htmlspecialchars_decode($row['username']),
  335. 'MESSAGE' => htmlspecialchars_decode($message))
  336. );
  337. $messenger->send(NOTIFY_IM);
  338. $s_select = 'S_SENT_JABBER';
  339. }
  340. else
  341. {
  342. trigger_error('FORM_INVALID');
  343. }
  344. }
  345. break;
  346. }
  347. // Send vars to the template
  348. $template->assign_vars(array(
  349. 'IM_CONTACT' => $row[$sql_field],
  350. 'A_IM_CONTACT' => addslashes($row[$sql_field]),
  351. 'USERNAME' => $row['username'],
  352. 'CONTACT_NAME' => $row[$sql_field],
  353. 'SITENAME' => $config['sitename'],
  354. 'PRESENCE_IMG' => $presence_img,
  355. 'L_SEND_IM_EXPLAIN' => $user->lang['IM_' . $lang],
  356. 'L_IM_SENT_JABBER' => sprintf($user->lang['IM_SENT_JABBER'], $row['username']),
  357. $s_select => true,
  358. 'S_IM_ACTION' => $s_action)
  359. );
  360. break;
  361. case 'viewprofile':
  362. // Display a profile
  363. if ($user_id == ANONYMOUS && !$username)
  364. {
  365. trigger_error('NO_USER');
  366. }
  367. // Get user...
  368. $sql = 'SELECT *
  369. FROM ' . USERS_TABLE . '
  370. WHERE ' . (($username) ? "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'" : "user_id = $user_id");
  371. $result = $db->sql_query($sql);
  372. $member = $db->sql_fetchrow($result);
  373. $db->sql_freeresult($result);
  374. if (!$member)
  375. {
  376. trigger_error('NO_USER');
  377. }
  378. // a_user admins and founder are able to view inactive users and bots to be able to manage them more easily
  379. // Normal users are able to see at least users having only changed their profile settings but not yet reactivated.
  380. if (!$auth->acl_get('a_user') && $user->data['user_type'] != USER_FOUNDER)
  381. {
  382. if ($member['user_type'] == USER_IGNORE)
  383. {
  384. trigger_error('NO_USER');
  385. }
  386. else if ($member['user_type'] == USER_INACTIVE && $member['user_inactive_reason'] != INACTIVE_PROFILE)
  387. {
  388. trigger_error('NO_USER');
  389. }
  390. }
  391. $user_id = (int) $member['user_id'];
  392. // Get group memberships
  393. // Also get visiting user's groups to determine hidden group memberships if necessary.
  394. $auth_hidden_groups = ($user_id === (int) $user->data['user_id'] || $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? true : false;
  395. $sql_uid_ary = ($auth_hidden_groups) ? array($user_id) : array($user_id, (int) $user->data['user_id']);
  396. // Do the SQL thang
  397. $sql = 'SELECT g.group_id, g.group_name, g.group_type, ug.user_id
  398. FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
  399. WHERE ' . $db->sql_in_set('ug.user_id', $sql_uid_ary) . '
  400. AND g.group_id = ug.group_id
  401. AND ug.user_pending = 0';
  402. $result = $db->sql_query($sql);
  403. // Divide data into profile data and current user data
  404. $profile_groups = $user_groups = array();
  405. while ($row = $db->sql_fetchrow($result))
  406. {
  407. $row['user_id'] = (int) $row['user_id'];
  408. $row['group_id'] = (int) $row['group_id'];
  409. if ($row['user_id'] == $user_id)
  410. {
  411. $profile_groups[] = $row;
  412. }
  413. else
  414. {
  415. $user_groups[$row['group_id']] = $row['group_id'];
  416. }
  417. }
  418. $db->sql_freeresult($result);
  419. // Filter out hidden groups and sort groups by name
  420. $group_data = $group_sort = array();
  421. foreach ($profile_groups as $row)
  422. {
  423. if ($row['group_type'] == GROUP_SPECIAL)
  424. {
  425. // Lookup group name in language dictionary
  426. if (isset($user->lang['G_' . $row['group_name']]))
  427. {
  428. $row['group_name'] = $user->lang['G_' . $row['group_name']];
  429. }
  430. }
  431. else if (!$auth_hidden_groups && $row['group_type'] == GROUP_HIDDEN && !isset($user_groups[$row['group_id']]))
  432. {
  433. // Skip over hidden groups the user cannot see
  434. continue;
  435. }
  436. $group_sort[$row['group_id']] = utf8_clean_string($row['group_name']);
  437. $group_data[$row['group_id']] = $row;
  438. }
  439. unset($profile_groups);
  440. unset($user_groups);
  441. asort($group_sort);
  442. $group_options = '';
  443. foreach ($group_sort as $group_id => $null)
  444. {
  445. $row = $group_data[$group_id];
  446. $group_options .= '<option value="' . $row['group_id'] . '"' . (($row['group_id'] == $member['group_id']) ? ' selected="selected"' : '') . '>' . $row['group_name'] . '</option>';
  447. }
  448. unset($group_data);
  449. unset($group_sort);
  450. // What colour is the zebra
  451. $sql = 'SELECT friend, foe
  452. FROM ' . ZEBRA_TABLE . "
  453. WHERE zebra_id = $user_id
  454. AND user_id = {$user->data['user_id']}";
  455. $result = $db->sql_query($sql);
  456. $row = $db->sql_fetchrow($result);
  457. $foe = ($row['foe']) ? true : false;
  458. $friend = ($row['friend']) ? true : false;
  459. $db->sql_freeresult($result);
  460. if ($config['load_onlinetrack'])
  461. {
  462. $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
  463. FROM ' . SESSIONS_TABLE . "
  464. WHERE session_user_id = $user_id";
  465. $result = $db->sql_query($sql);
  466. $row = $db->sql_fetchrow($result);
  467. $db->sql_freeresult($result);
  468. $member['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
  469. $member['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
  470. unset($row);
  471. }
  472. if ($config['load_user_activity'])
  473. {
  474. display_user_activity($member);
  475. }
  476. // Do the relevant calculations
  477. $memberdays = max(1, round((time() - $member['user_regdate']) / 86400));
  478. $posts_per_day = $member['user_posts'] / $memberdays;
  479. $percentage = ($config['num_posts']) ? min(100, ($member['user_posts'] / $config['num_posts']) * 100) : 0;
  480. if ($member['user_sig'])
  481. {
  482. $parse_flags = ($member['user_sig_bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
  483. $member['user_sig'] = generate_text_for_display($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield'], $parse_flags, true);
  484. }
  485. // 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
  486. $zebra_enabled = $friends_enabled = $foes_enabled = $user_notes_enabled = $warn_user_enabled = false;
  487. // Only check if the user is logged in
  488. if ($user->data['is_registered'])
  489. {
  490. if (!class_exists('p_master'))
  491. {
  492. include($phpbb_root_path . 'includes/functions_module.' . $phpEx);
  493. }
  494. $module = new p_master();
  495. $module->list_modules('ucp');
  496. $module->list_modules('mcp');
  497. $user_notes_enabled = ($module->loaded('mcp_notes', 'user_notes')) ? true : false;
  498. $warn_user_enabled = ($module->loaded('mcp_warn', 'warn_user')) ? true : false;
  499. $zebra_enabled = ($module->loaded('ucp_zebra')) ? true : false;
  500. $friends_enabled = ($module->loaded('ucp_zebra', 'friends')) ? true : false;
  501. $foes_enabled = ($module->loaded('ucp_zebra', 'foes')) ? true : false;
  502. unset($module);
  503. }
  504. // Custom Profile Fields
  505. $profile_fields = array();
  506. if ($config['load_cpf_viewprofile'])
  507. {
  508. $cp = $phpbb_container->get('profilefields.manager');
  509. $profile_fields = $cp->grab_profile_fields_data($user_id);
  510. $profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template_data($profile_fields[$user_id]) : array();
  511. }
  512. /**
  513. * Modify user data before we display the profile
  514. *
  515. * @event core.memberlist_view_profile
  516. * @var array member Array with user's data
  517. * @var bool user_notes_enabled Is the mcp user notes module enabled?
  518. * @var bool warn_user_enabled Is the mcp warnings module enabled?
  519. * @var bool zebra_enabled Is the ucp zebra module enabled?
  520. * @var bool friends_enabled Is the ucp friends module enabled?
  521. * @var bool foes_enabled Is the ucp foes module enabled?
  522. * @var bool friend Is the user friend?
  523. * @var bool foe Is the user foe?
  524. * @var array profile_fields Array with user's profile field data
  525. * @since 3.1.0-a1
  526. * @changed 3.1.0-b2 Added friend and foe status
  527. * @changed 3.1.0-b3 Added profile fields data
  528. */
  529. $vars = array(
  530. 'member',
  531. 'user_notes_enabled',
  532. 'warn_user_enabled',
  533. 'zebra_enabled',
  534. 'friends_enabled',
  535. 'foes_enabled',
  536. 'friend',
  537. 'foe',
  538. 'profile_fields',
  539. );
  540. extract($phpbb_dispatcher->trigger_event('core.memberlist_view_profile', compact($vars)));
  541. $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled));
  542. // If the user has m_approve permission or a_user permission, then list then display unapproved posts
  543. if ($auth->acl_getf_global('m_approve') || $auth->acl_get('a_user'))
  544. {
  545. $sql = 'SELECT COUNT(post_id) as posts_in_queue
  546. FROM ' . POSTS_TABLE . '
  547. WHERE poster_id = ' . $user_id . '
  548. AND ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE));
  549. $result = $db->sql_query($sql);
  550. $member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
  551. $db->sql_freeresult($result);
  552. }
  553. else
  554. {
  555. $member['posts_in_queue'] = 0;
  556. }
  557. $template->assign_vars(array(
  558. 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $member['posts_in_queue']),
  559. 'POSTS_DAY' => $user->lang('POST_DAY', $posts_per_day),
  560. 'POSTS_PCT' => $user->lang('POST_PCT', $percentage),
  561. 'SIGNATURE' => $member['user_sig'],
  562. 'POSTS_IN_QUEUE'=> $member['posts_in_queue'],
  563. 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
  564. 'L_SEND_EMAIL_USER' => $user->lang('SEND_EMAIL_USER', $member['username']),
  565. 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']),
  566. 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']),
  567. 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
  568. 'S_PROFILE_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group'),
  569. 'S_GROUP_OPTIONS' => $group_options,
  570. 'S_CUSTOM_FIELDS' => (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
  571. 'U_USER_ADMIN' => ($auth->acl_get('a_user')) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&amp;mode=overview&amp;u=' . $user_id, true, $user->session_id) : '',
  572. 'U_USER_BAN' => ($auth->acl_get('m_ban') && $user_id != $user->data['user_id']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=ban&amp;mode=user&amp;u=' . $user_id, true, $user->session_id) : '',
  573. 'U_MCP_QUEUE' => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
  574. 'U_SWITCH_PERMISSIONS' => ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_id) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&amp;u={$user_id}&amp;hash=" . generate_link_hash('switchperm')) : '',
  575. 'S_USER_NOTES' => ($user_notes_enabled) ? true : false,
  576. 'S_WARN_USER' => ($warn_user_enabled) ? true : false,
  577. 'S_ZEBRA' => ($user->data['user_id'] != $user_id && $user->data['is_registered'] && $zebra_enabled) ? true : false,
  578. 'U_ADD_FRIEND' => (!$friend && !$foe && $friends_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
  579. 'U_ADD_FOE' => (!$friend && !$foe && $foes_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;mode=foes&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
  580. 'U_REMOVE_FRIEND' => ($friend && $friends_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;usernames[]=' . $user_id) : '',
  581. 'U_REMOVE_FOE' => ($foe && $foes_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;mode=foes&amp;usernames[]=' . $user_id) : '',
  582. 'U_CANONICAL' => generate_board_url() . '/' . append_sid("memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_id, true, ''),
  583. ));
  584. if (!empty($profile_fields['row']))
  585. {
  586. $template->assign_vars($profile_fields['row']);
  587. }
  588. if (!empty($profile_fields['blockrow']))
  589. {
  590. foreach ($profile_fields['blockrow'] as $field_data)
  591. {
  592. $template->assign_block_vars('custom_fields', $field_data);
  593. }
  594. }
  595. // Inactive reason/account?
  596. if ($member['user_type'] == USER_INACTIVE)
  597. {
  598. $user->add_lang('acp/common');
  599. $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
  600. switch ($member['user_inactive_reason'])
  601. {
  602. case INACTIVE_REGISTER:
  603. $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
  604. break;
  605. case INACTIVE_PROFILE:
  606. $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
  607. break;
  608. case INACTIVE_MANUAL:
  609. $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
  610. break;
  611. case INACTIVE_REMIND:
  612. $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
  613. break;
  614. }
  615. $template->assign_vars(array(
  616. 'S_USER_INACTIVE' => true,
  617. 'USER_INACTIVE_REASON' => $inactive_reason)
  618. );
  619. }
  620. // Now generate page title
  621. $page_title = sprintf($user->lang['VIEWING_PROFILE'], $member['username']);
  622. $template_html = 'memberlist_view.html';
  623. break;
  624. case 'contactadmin':
  625. case 'email':
  626. if (!class_exists('messenger'))
  627. {
  628. include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  629. }
  630. $user_id = request_var('u', 0);
  631. $topic_id = request_var('t', 0);
  632. if ($user_id)
  633. {
  634. $form_name = 'user';
  635. }
  636. else if ($topic_id)
  637. {
  638. $form_name = 'topic';
  639. }
  640. else if ($mode === 'contactadmin')
  641. {
  642. $form_name = 'admin';
  643. }
  644. else
  645. {
  646. trigger_error('NO_EMAIL');
  647. }
  648. $form = $phpbb_container->get('message.form.' . $form_name);
  649. $form->bind($request);
  650. $error = $form->check_allow();
  651. if ($error)
  652. {
  653. trigger_error($error);
  654. }
  655. if ($request->is_set_post('submit'))
  656. {
  657. $messenger = new messenger(false);
  658. $form->submit($messenger);
  659. }
  660. $page_title = $form->get_page_title();
  661. $template_html = $form->get_template_file();
  662. $form->render($template);
  663. break;
  664. case 'livesearch':
  665. $username_chars = $request->variable('username', '', true);
  666. $sql = 'SELECT username, user_id, user_colour
  667. FROM ' . USERS_TABLE . '
  668. WHERE ' . $db->sql_in_set('user_type', array(USER_NORMAL, USER_FOUNDER)) . '
  669. AND username_clean ' . $db->sql_like_expression(utf8_clean_string($username_chars) . $db->any_char);
  670. $result = $db->sql_query_limit($sql, 10);
  671. $user_list = array();
  672. while ($row = $db->sql_fetchrow($result))
  673. {
  674. $user_list[] = array(
  675. 'user_id' => (int) $row['user_id'],
  676. 'result' => $row['username'],
  677. 'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
  678. 'display' => get_username_string('no_profile', $row['user_id'], $row['username'], $row['user_colour']),
  679. );
  680. }
  681. $db->sql_freeresult($result);
  682. $json_response = new \phpbb\json_response();
  683. $json_response->send(array(
  684. 'keyword' => $username_chars,
  685. 'results' => $user_list,
  686. ));
  687. break;
  688. case 'group':
  689. default:
  690. // The basic memberlist
  691. $page_title = $user->lang['MEMBERLIST'];
  692. $template_html = 'memberlist_body.html';
  693. $pagination = $phpbb_container->get('pagination');
  694. // Sorting
  695. $sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'c' => $user->lang['SORT_JOINED'], 'd' => $user->lang['SORT_POST_COUNT'], 'k' => $user->lang['JABBER']);
  696. $sort_key_sql = array('a' => 'u.username_clean', 'c' => 'u.user_regdate', 'd' => 'u.user_posts', 'k' => 'u.user_jabber');
  697. if ($auth->acl_get('a_user'))
  698. {
  699. $sort_key_text['e'] = $user->lang['SORT_EMAIL'];
  700. $sort_key_sql['e'] = 'u.user_email';
  701. }
  702. if ($auth->acl_get('u_viewonline'))
  703. {
  704. $sort_key_text['l'] = $user->lang['SORT_LAST_ACTIVE'];
  705. $sort_key_sql['l'] = 'u.user_lastvisit';
  706. }
  707. $sort_key_text['m'] = $user->lang['SORT_RANK'];
  708. $sort_key_sql['m'] = 'u.user_rank';
  709. $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
  710. $s_sort_key = '';
  711. foreach ($sort_key_text as $key => $value)
  712. {
  713. $selected = ($sort_key == $key) ? ' selected="selected"' : '';
  714. $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  715. }
  716. $s_sort_dir = '';
  717. foreach ($sort_dir_text as $key => $value)
  718. {
  719. $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
  720. $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  721. }
  722. // Additional sorting options for user search ... if search is enabled, if not
  723. // then only admins can make use of this (for ACP functionality)
  724. $sql_select = $sql_where_data = $sql_from = $sql_where = $order_by = '';
  725. $form = request_var('form', '');
  726. $field = request_var('field', '');
  727. $select_single = request_var('select_single', false);
  728. // Search URL parameters, if any of these are in the URL we do a search
  729. $search_params = array('username', 'email', 'jabber', 'search_group_id', 'joined_select', 'active_select', 'count_select', 'joined', 'active', 'count', 'ip');
  730. // We validate form and field here, only id/class allowed
  731. $form = (!preg_match('/^[a-z0-9_-]+$/i', $form)) ? '' : $form;
  732. $field = (!preg_match('/^[a-z0-9_-]+$/i', $field)) ? '' : $field;
  733. if ((($mode == '' || $mode == 'searchuser') || sizeof(array_intersect($request->variable_names(\phpbb\request\request_interface::GET), $search_params)) > 0) && ($config['load_search'] || $auth->acl_get('a_')))
  734. {
  735. $username = request_var('username', '', true);
  736. $email = strtolower(request_var('email', ''));
  737. $jabber = request_var('jabber', '');
  738. $search_group_id = request_var('search_group_id', 0);
  739. // when using these, make sure that we actually have values defined in $find_key_match
  740. $joined_select = request_var('joined_select', 'lt');
  741. $active_select = request_var('active_select', 'lt');
  742. $count_select = request_var('count_select', 'eq');
  743. $joined = explode('-', request_var('joined', ''));
  744. $active = explode('-', request_var('active', ''));
  745. $count = (request_var('count', '') !== '') ? request_var('count', 0) : '';
  746. $ipdomain = request_var('ip', '');
  747. $find_key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
  748. $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
  749. $s_find_count = '';
  750. foreach ($find_count as $key => $value)
  751. {
  752. $selected = ($count_select == $key) ? ' selected="selected"' : '';
  753. $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  754. }
  755. $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
  756. $s_find_join_time = '';
  757. foreach ($find_time as $key => $value)
  758. {
  759. $selected = ($joined_select == $key) ? ' selected="selected"' : '';
  760. $s_find_join_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  761. }
  762. $s_find_active_time = '';
  763. foreach ($find_time as $key => $value)
  764. {
  765. $selected = ($active_select == $key) ? ' selected="selected"' : '';
  766. $s_find_active_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  767. }
  768. $sql_where .= ($username) ? ' AND u.username_clean ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($username))) : '';
  769. $sql_where .= ($auth->acl_get('a_user') && $email) ? ' AND u.user_email ' . $db->sql_like_expression(str_replace('*', $db->any_char, $email)) . ' ' : '';
  770. $sql_where .= ($jabber) ? ' AND u.user_jabber ' . $db->sql_like_expression(str_replace('*', $db->any_char, $jabber)) . ' ' : '';
  771. $sql_where .= (is_numeric($count) && isset($find_key_match[$count_select])) ? ' AND u.user_posts ' . $find_key_match[$count_select] . ' ' . (int) $count . ' ' : '';
  772. if (isset($find_key_match[$joined_select]) && sizeof($joined) == 3)
  773. {
  774. $joined_time = gmmktime(0, 0, 0, (int) $joined[1], (int) $joined[2], (int) $joined[0]);
  775. if ($joined_time !== false)
  776. {
  777. $sql_where .= " AND u.user_regdate " . $find_key_match[$joined_select] . ' ' . $joined_time;
  778. }
  779. }
  780. if (isset($find_key_match[$active_select]) && sizeof($active) == 3 && $auth->acl_get('u_viewonline'))
  781. {
  782. $active_time = gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]);
  783. if ($active_time !== false)
  784. {
  785. $sql_where .= " AND u.user_lastvisit " . $find_key_match[$active_select] . ' ' . $active_time;
  786. }
  787. }
  788. $sql_where .= ($search_group_id) ? " AND u.user_id = ug.user_id AND ug.group_id = $search_group_id AND ug.user_pending = 0 " : '';
  789. if ($search_group_id)
  790. {
  791. $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
  792. }
  793. if ($ipdomain && $auth->acl_getf_global('m_info'))
  794. {
  795. if (strspn($ipdomain, 'abcdefghijklmnopqrstuvwxyz'))
  796. {
  797. $hostnames = gethostbynamel($ipdomain);
  798. if ($hostnames !== false)
  799. {
  800. $ips = "'" . implode('\', \'', array_map(array($db, 'sql_escape'), preg_replace('#([0-9]{1,3}\.[0-9]{1,3}[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})#', "\\1", gethostbynamel($ipdomain)))) . "'";
  801. }
  802. else
  803. {
  804. $ips = false;
  805. }
  806. }
  807. else
  808. {
  809. $ips = "'" . str_replace('*', '%', $db->sql_escape($ipdomain)) . "'";
  810. }
  811. if ($ips === false)
  812. {
  813. // A minor fudge but it does the job :D
  814. $sql_where .= " AND u.user_id = 0";
  815. }
  816. else
  817. {
  818. $ip_forums = array_keys($auth->acl_getf('m_info', true));
  819. $sql = 'SELECT DISTINCT poster_id
  820. FROM ' . POSTS_TABLE . '
  821. WHERE poster_ip ' . ((strpos($ips, '%') !== false) ? 'LIKE' : 'IN') . " ($ips)
  822. AND " . $db->sql_in_set('forum_id', $ip_forums);
  823. $result = $db->sql_query($sql);
  824. if ($row = $db->sql_fetchrow($result))
  825. {
  826. $ip_sql = array();
  827. do
  828. {
  829. $ip_sql[] = $row['poster_id'];
  830. }
  831. while ($row = $db->sql_fetchrow($result));
  832. $sql_where .= ' AND ' . $db->sql_in_set('u.user_id', $ip_sql);
  833. }
  834. else
  835. {
  836. // A minor fudge but it does the job :D
  837. $sql_where .= " AND u.user_id = 0";
  838. }
  839. unset($ip_forums);
  840. $db->sql_freeresult($result);
  841. }
  842. }
  843. }
  844. $first_char = request_var('first_char', '');
  845. if ($first_char == 'other')
  846. {
  847. for ($i = 97; $i < 123; $i++)
  848. {
  849. $sql_where .= ' AND u.username_clean NOT ' . $db->sql_like_expression(chr($i) . $db->any_char);
  850. }
  851. }
  852. else if ($first_char)
  853. {
  854. $sql_where .= ' AND u.username_clean ' . $db->sql_like_expression(substr($first_char, 0, 1) . $db->any_char);
  855. }
  856. // Are we looking at a usergroup? If so, fetch additional info
  857. // and further restrict the user info query
  858. if ($mode == 'group')
  859. {
  860. // We JOIN here to save a query for determining membership for hidden groups. ;)
  861. $sql = 'SELECT g.*, ug.user_id
  862. FROM ' . GROUPS_TABLE . ' g
  863. LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (ug.user_pending = 0 AND ug.user_id = ' . $user->data['user_id'] . " AND ug.group_id = $group_id)
  864. WHERE g.group_id = $group_id";
  865. $result = $db->sql_query($sql);
  866. $group_row = $db->sql_fetchrow($result);
  867. $db->sql_freeresult($result);
  868. if (!$group_row)
  869. {
  870. trigger_error('NO_GROUP');
  871. }
  872. switch ($group_row['group_type'])
  873. {
  874. case GROUP_OPEN:
  875. $group_row['l_group_type'] = 'OPEN';
  876. break;
  877. case GROUP_CLOSED:
  878. $group_row['l_group_type'] = 'CLOSED';
  879. break;
  880. case GROUP_HIDDEN:
  881. $group_row['l_group_type'] = 'HIDDEN';
  882. // Check for membership or special permissions
  883. if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $group_row['user_id'] != $user->data['user_id'])
  884. {
  885. trigger_error('NO_GROUP');
  886. }
  887. break;
  888. case GROUP_SPECIAL:
  889. $group_row['l_group_type'] = 'SPECIAL';
  890. break;
  891. case GROUP_FREE:
  892. $group_row['l_group_type'] = 'FREE';
  893. break;
  894. }
  895. $avatar_img = phpbb_get_group_avatar($group_row);
  896. // ... same for group rank
  897. $rank_title = $rank_img = $rank_img_src = '';
  898. if ($group_row['group_rank'])
  899. {
  900. get_user_rank($group_row['group_rank'], false, $rank_title, $rank_img, $rank_img_src);
  901. if ($rank_img)
  902. {
  903. $rank_img .= '<br />';
  904. }
  905. }
  906. $template->assign_vars(array(
  907. 'GROUP_DESC' => generate_text_for_display($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield'], $group_row['group_desc_options']),
  908. 'GROUP_NAME' => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
  909. 'GROUP_COLOR' => $group_row['group_colour'],
  910. 'GROUP_TYPE' => $user->lang['GROUP_IS_' . $group_row['l_group_type']],
  911. 'GROUP_RANK' => $rank_title,
  912. 'AVATAR_IMG' => $avatar_img,
  913. 'RANK_IMG' => $rank_img,
  914. 'RANK_IMG_SRC' => $rank_img_src,
  915. '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&amp;mode=compose&amp;g=' . $group_id) : '',)
  916. );
  917. $sql_select = ', ug.group_leader';
  918. $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
  919. $order_by = 'ug.group_leader DESC, ';
  920. $sql_where .= " AND ug.user_pending = 0 AND u.user_id = ug.user_id AND ug.group_id = $group_id";
  921. $sql_where_data = " AND u.user_id = ug.user_id AND ug.group_id = $group_id";
  922. }
  923. // Sorting and order
  924. if (!isset($sort_key_sql[$sort_key]))
  925. {
  926. $sort_key = $default_key;
  927. }
  928. $order_by .= $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
  929. // Unfortunately we must do this here for sorting by rank, else the sort order is applied wrongly
  930. if ($sort_key == 'm')
  931. {
  932. $order_by .= ', u.user_posts DESC';
  933. }
  934. // Count the users ...
  935. if ($sql_where)
  936. {
  937. $sql = 'SELECT COUNT(u.user_id) AS total_users
  938. FROM ' . USERS_TABLE . " u$sql_from
  939. WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
  940. $sql_where";
  941. $result = $db->sql_query($sql);
  942. $total_users = (int) $db->sql_fetchfield('total_users');
  943. $db->sql_freeresult($result);
  944. }
  945. else
  946. {
  947. $total_users = $config['num_users'];
  948. }
  949. // Build a relevant pagination_url
  950. $params = $sort_params = array();
  951. // We do not use request_var() here directly to save some calls (not all variables are set)
  952. $check_params = array(
  953. 'g' => array('g', 0),
  954. 'sk' => array('sk', $default_key),
  955. 'sd' => array('sd', 'a'),
  956. 'form' => array('form', ''),
  957. 'field' => array('field', ''),
  958. 'select_single' => array('select_single', $select_single),
  959. 'username' => array('username', '', true),
  960. 'email' => array('email', ''),
  961. 'jabber' => array('jabber', ''),
  962. 'search_group_id' => array('search_group_id', 0),
  963. 'joined_select' => array('joined_select', 'lt'),
  964. 'active_select' => array('active_select', 'lt'),
  965. 'count_select' => array('count_select', 'eq'),
  966. 'joined' => array('joined', ''),
  967. 'active' => array('active', ''),
  968. 'count' => (request_var('count', '') !== '') ? array('count', 0) : array('count', ''),
  969. 'ip' => array('ip', ''),
  970. 'first_char' => array('first_char', ''),
  971. );
  972. $u_first_char_params = array();
  973. foreach ($check_params as $key => $call)
  974. {
  975. if (!isset($_REQUEST[$key]))
  976. {
  977. continue;
  978. }
  979. $param = call_user_func_array('request_var', $call);
  980. $param = urlencode($key) . '=' . ((is_string($param)) ? urlencode($param) : $param);
  981. $params[] = $param;
  982. if ($key != 'first_char')
  983. {
  984. $u_first_char_params[] = $param;
  985. }
  986. if ($key != 'sk' && $key != 'sd')
  987. {
  988. $sort_params[] = $param;
  989. }
  990. }
  991. $u_hide_find_member = append_sid("{$phpbb_root_path}memberlist.$phpEx", "start=$start" . (!empty($params) ? '&amp;' . implode('&amp;', $params) : ''));
  992. if ($mode)
  993. {
  994. $params[] = "mode=$mode";
  995. $u_first_char_params[] = "mode=$mode";
  996. }
  997. $sort_params[] = "mode=$mode";
  998. $pagination_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $params));
  999. $sort_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $sort_params));
  1000. unset($search_params, $sort_params);
  1001. $u_first_char_params = implode('&amp;', $u_first_char_params);
  1002. $u_first_char_params .= ($u_first_char_params) ? '&amp;' : '';
  1003. $first_characters = array();
  1004. $first_characters[''] = $user->lang['ALL'];
  1005. for ($i = 97; $i < 123; $i++)
  1006. {
  1007. $first_characters[chr($i)] = chr($i - 32);
  1008. }
  1009. $first_characters['other'] = $user->lang['OTHER'];
  1010. foreach ($first_characters as $char => $desc)
  1011. {
  1012. $template->assign_block_vars('first_char', array(
  1013. 'DESC' => $desc,
  1014. 'VALUE' => $char,
  1015. 'S_SELECTED' => ($first_char == $char) ? true : false,
  1016. 'U_SORT' => append_sid("{$phpbb_root_path}memberlist.$phpEx", $u_first_char_params . 'first_char=' . $char) . '#memberlist',
  1017. ));
  1018. }
  1019. // Some search user specific data
  1020. if (($mode == '' || $mode == 'searchuser') && ($config['load_search'] || $auth->acl_get('a_')))
  1021. {
  1022. $group_selected = request_var('search_group_id', 0);
  1023. $s_group_select = '<option value="0"' . ((!$group_selected) ? ' selected="selected"' : '') . '>&nbsp;</option>';
  1024. $group_ids = array();
  1025. /**
  1026. * @todo add this to a separate function (function is responsible for returning the groups the user is able to see based on the users group membership)
  1027. */
  1028. if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
  1029. {
  1030. $sql = 'SELECT group_id, group_name, group_type
  1031. FROM ' . GROUPS_TABLE;
  1032. if (!$config['coppa_enable'])
  1033. {
  1034. $sql .= " WHERE group_name <> 'REGISTERED_COPPA'";
  1035. }
  1036. $sql .= ' ORDER BY group_name ASC';
  1037. }
  1038. else
  1039. {
  1040. $sql = 'SELECT g.group_id, g.group_name, g.group_type
  1041. FROM ' . GROUPS_TABLE . ' g
  1042. LEFT JOIN ' . USER_GROUP_TABLE . ' ug
  1043. ON (
  1044. g.group_id = ug.group_id
  1045. AND ug.user_id = ' . $user->data['user_id'] . '
  1046. AND ug.user_pending = 0
  1047. )
  1048. WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
  1049. if (!$config['coppa_enable'])
  1050. {
  1051. $sql .= " AND g.group_name <> 'REGISTERED_COPPA'";
  1052. }
  1053. $sql .= ' ORDER BY g.group_name ASC';
  1054. }
  1055. $result = $db->sql_query($sql);
  1056. while ($row = $db->sql_fetchrow($result))
  1057. {
  1058. $group_ids[] = $row['group_id'];
  1059. $s_group_select .= '<option value="' . $row['group_id'] . '"' . (($group_selected == $row['group_id']) ? ' selected="selected"' : '') . '>' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
  1060. }
  1061. $db->sql_freeresult($result);
  1062. if ($group_selected !== 0 && !in_array($group_selected, $group_ids))
  1063. {
  1064. trigger_error('NO_GROUP');
  1065. }
  1066. $template->assign_vars(array(
  1067. 'USERNAME' => $username,
  1068. 'EMAIL' => $email,
  1069. 'JABBER' => $jabber,
  1070. 'JOINED' => implode('-', $joined),
  1071. 'ACTIVE' => implode('-', $active),
  1072. 'COUNT' => $count,
  1073. 'IP' => $ipdomain,
  1074. 'S_IP_SEARCH_ALLOWED' => ($auth->acl_getf_global('m_info')) ? true : false,
  1075. 'S_EMAIL_SEARCH_ALLOWED'=> ($auth->acl_get('a_user')) ? true : false,
  1076. 'S_IN_SEARCH_POPUP' => ($form && $field) ? true : false,
  1077. 'S_SEARCH_USER' => ($mode == 'searchuser' || ($mode == '' && $submit)),
  1078. 'S_FORM_NAME' => $form,
  1079. 'S_FIELD_NAME' => $field,
  1080. 'S_SELECT_SINGLE' => $select_single,
  1081. 'S_COUNT_OPTIONS' => $s_find_count,
  1082. 'S_SORT_OPTIONS' => $s_sort_key,
  1083. 'S_JOINED_TIME_OPTIONS' => $s_find_join_time,
  1084. 'S_ACTIVE_TIME_OPTIONS' => $s_find_active_time,
  1085. 'S_GROUP_SELECT' => $s_group_select,
  1086. 'S_USER_SEARCH_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&amp;form=$form&amp;field=$field"))
  1087. );
  1088. }
  1089. $start = $pagination->validate_start($start, $config['topics_per_page'], $config['num_users']);
  1090. // Get us some users :D
  1091. $sql = "SELECT u.user_id
  1092. FROM " . USERS_TABLE . " u
  1093. $sql_from
  1094. WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
  1095. $sql_where
  1096. ORDER BY $order_by";
  1097. $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
  1098. $user_list = array();
  1099. while ($row = $db->sql_fetchrow($result))
  1100. {
  1101. $user_list[] = (int) $row['user_id'];
  1102. }
  1103. $db->sql_freeresult($result);
  1104. // Load custom profile fields
  1105. if ($config['load_cpf_memberlist'])
  1106. {
  1107. $cp = $phpbb_container->get('profilefields.manager');
  1108. $cp_row = $cp->generate_profile_fields_template_headlines('field_show_on_ml');
  1109. foreach ($cp_row as $profile_field)
  1110. {
  1111. $template->assign_block_vars('custom_fields', $profile_field);
  1112. }
  1113. }
  1114. $leaders_set = false;
  1115. // So, did we get any users?
  1116. if (sizeof($user_list))
  1117. {
  1118. // Session time?! Session time...
  1119. $sql = 'SELECT session_user_id, MAX(session_time) AS session_time
  1120. FROM ' . SESSIONS_TABLE . '
  1121. WHERE session_time >= ' . (time() - $config['session_length']) . '
  1122. AND ' . $db->sql_in_set('session_user_id', $user_list) . '
  1123. GROUP BY session_user_id';
  1124. $result = $db->sql_query($sql);
  1125. $session_times = array();
  1126. while ($row = $db->sql_fetchrow($result))
  1127. {
  1128. $session_times[$row['session_user_id']] = $row['session_time'];
  1129. }
  1130. $db->sql_freeresult($result);
  1131. // Do the SQL thang
  1132. if ($mode == 'group')
  1133. {
  1134. $sql = "SELECT u.*
  1135. $sql_select
  1136. FROM " . USERS_TABLE . " u
  1137. $sql_from
  1138. WHERE " . $db->sql_in_set('u.user_id', $user_list) . "
  1139. $sql_where_data";
  1140. }
  1141. else
  1142. {
  1143. $sql = 'SELECT *
  1144. FROM ' . USERS_TABLE . '
  1145. WHERE ' . $db->sql_in_set('user_id', $user_list);
  1146. }
  1147. $result = $db->sql_query($sql);
  1148. $id_cache = array();
  1149. while ($row = $db->sql_fetchrow($result))
  1150. {
  1151. $row['session_time'] = (!empty($session_times[$row['user_id']])) ? $session_times[$row['user_id']] : 0;
  1152. $row['last_visit'] = (!empty($row['session_time'])) ? $row['session_time'] : $row['user_lastvisit'];
  1153. $id_cache[$row['user_id']] = $row;
  1154. }
  1155. $db->sql_freeresult($result);
  1156. // Load custom profile fields
  1157. if ($config['load_cpf_memberlist'])
  1158. {
  1159. // Grab all profile fields from users in id cache for later use - similar to the poster cache
  1160. $profile_fields_cache = $cp->grab_profile_fields_data($user_list);
  1161. // Filter the fields we don't want to show
  1162. foreach ($profile_fields_cache as $user_id => $user_profile_fields)
  1163. {
  1164. foreach ($user_profile_fields as $field_ident => $profile_field)
  1165. {
  1166. if (!$profile_field['data']['field_show_on_ml'])
  1167. {
  1168. unset($profile_fields_cache[$user_id][$field_ident]);
  1169. }
  1170. }
  1171. }
  1172. }
  1173. // If we sort by last active date we need to adjust the id cache due to user_lastvisit not being the last active date...
  1174. if ($sort_key == 'l')
  1175. {
  1176. // uasort($id_cache, create_function('$first, $second', "return (\$first['last_visit'] == \$second['last_visit']) ? 0 : ((\$first['last_visit'] < \$second['last_visit']) ? $lesser_than : ($lesser_than * -1));"));
  1177. usort($user_list, '_sort_last_active');
  1178. }
  1179. for ($i = 0, $end = sizeof($user_list); $i < $end; ++$i)
  1180. {
  1181. $user_id = $user_list[$i];
  1182. $row = $id_cache[$user_id];
  1183. $is_leader = (isset($row['group_leader']) && $row['group_leader']) ? true : false;
  1184. $leaders_set = ($leaders_set || $is_leader);
  1185. $cp_row = array();
  1186. if ($config['load_cpf_memberlist'])
  1187. {
  1188. $cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template_data($profile_fields_cache[$user_id], false) : array();
  1189. }
  1190. $memberrow = array_merge(show_profile($row), array(
  1191. 'ROW_NUMBER' => $i + ($start + 1),
  1192. 'S_CUSTOM_PROFILE' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
  1193. 'S_GROUP_LEADER' => $is_leader,
  1194. 'U_VIEW_PROFILE' => get_username_string('profile', $user_id, $row['username']),
  1195. ));
  1196. if (isset($cp_row['row']) && sizeof($cp_row['row']))
  1197. {
  1198. $memberrow = array_merge($memberrow, $cp_row['row']);
  1199. }
  1200. $template->assign_block_vars('memberrow', $memberrow);
  1201. if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow']))
  1202. {
  1203. foreach ($cp_row['blockrow'] as $field_data)
  1204. {
  1205. $template->assign_block_vars('memberrow.custom_fields', $field_data);
  1206. }
  1207. }
  1208. unset($id_cache[$user_id]);
  1209. }
  1210. }
  1211. $pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_users, $config['topics_per_page'], $start);
  1212. // Generate page
  1213. $template->assign_vars(array(
  1214. 'TOTAL_USERS' => $user->lang('LIST_USERS', (int) $total_users),
  1215. 'PROFILE_IMG' => $user->img('icon_user_profile', $user->lang['PROFILE']),
  1216. 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
  1217. 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']),
  1218. 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']),
  1219. 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
  1220. 'U_FIND_MEMBER' => ($config['load_search'] || $auth->acl_get('a_')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser' . (($start) ? "&amp;start=$start" : '') . (!empty($params) ? '&amp;' . implode('&amp;', $params) : '')) : '',
  1221. 'U_HIDE_FIND_MEMBER' => ($mode == 'searchuser' || ($mode == '' && $submit)) ? $u_hide_find_member : '',
  1222. 'U_LIVE_SEARCH' => ($config['allow_live_searches']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=livesearch') : false,
  1223. 'U_SORT_USERNAME' => $sort_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
  1224. 'U_SORT_JOINED' => $sort_url . '&amp;sk=c&amp;sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
  1225. 'U_SORT_POSTS' => $sort_url . '&amp;sk=d&amp;sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
  1226. 'U_SORT_EMAIL' => $sort_url . '&amp;sk=e&amp;sd=' . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
  1227. 'U_SORT_ACTIVE' => ($auth->acl_get('u_viewonline')) ? $sort_url . '&amp;sk=l&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a') : '',
  1228. 'U_SORT_RANK' => $sort_url . '&amp;sk=m&amp;sd=' . (($sort_key == 'm' && $sort_dir == 'a') ? 'd' : 'a'),
  1229. 'U_LIST_CHAR' => $sort_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a'),
  1230. 'S_SHOW_GROUP' => ($mode == 'group') ? true : false,
  1231. 'S_VIEWONLINE' => $auth->acl_get('u_viewonline'),
  1232. 'S_LEADERS_SET' => $leaders_set,
  1233. 'S_MODE_SELECT' => $s_sort_key,
  1234. 'S_ORDER_SELECT' => $s_sort_dir,
  1235. 'S_MODE_ACTION' => $pagination_url)
  1236. );
  1237. }
  1238. // Output the page
  1239. page_header($page_title);
  1240. $template->set_filenames(array(
  1241. 'body' => $template_html)
  1242. );
  1243. make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
  1244. page_footer();
  1245. /**
  1246. * Prepare profile data
  1247. */
  1248. function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false)
  1249. {
  1250. global $config, $auth, $template, $user, $phpEx, $phpbb_root_path, $phpbb_dispatcher;
  1251. $u

Large files files are truncated, but you can click here to view the full file