PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/wwwroot/phpbb/memberlist.php

https://github.com/spring/spring-website
PHP | 1852 lines | 1336 code | 290 blank | 226 comment | 270 complexity | 1350fbe77ed0b59ab2e3c33c7492cd7d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, LGPL-3.0, BSD-3-Clause

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

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