PageRenderTime 68ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/forum/memberlist.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 1811 lines | 1409 code | 280 blank | 122 comment | 325 complexity | 8c474f88f88546081a75672e8b2cd4b0 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. define('IN_PHPBB', true);
  14. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  15. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  16. include($phpbb_root_path . 'common.' . $phpEx);
  17. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  18. // Start session management
  19. $user->session_begin();
  20. $auth->acl($user->data);
  21. $user->setup(array('memberlist', 'groups'));
  22. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  23. if (!empty($_REQUEST['un'])) {
  24. $_REQUEST['un'] = rawurldecode($_REQUEST['un']);
  25. if (!$phpbb_seo->is_utf8($_REQUEST['un'])) {
  26. $_REQUEST['un'] = utf8_normalize_nfc(utf8_recode($_REQUEST['un'], 'ISO-8859-1'));
  27. }
  28. }
  29. // www.phpBB-SEO.com SEO TOOLKIT END
  30. // Grab data
  31. $mode = request_var('mode', '');
  32. $action = request_var('action', '');
  33. $user_id = request_var('u', ANONYMOUS);
  34. $username = request_var('un', '', true);
  35. $group_id = request_var('g', 0);
  36. $topic_id = request_var('t', 0);
  37. // Check our mode...
  38. if (!in_array($mode, array('', 'group', 'viewprofile', 'email', 'contact', 'searchuser', 'leaders')))
  39. {
  40. trigger_error('NO_MODE');
  41. }
  42. switch ($mode)
  43. {
  44. case 'email':
  45. break;
  46. default:
  47. // Can this user view profiles/memberlist?
  48. if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
  49. {
  50. if ($user->data['user_id'] != ANONYMOUS)
  51. {
  52. trigger_error('NO_VIEW_USERS');
  53. }
  54. login_box('', ((isset($user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)])) ? $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $user->lang['LOGIN_EXPLAIN_MEMBERLIST']));
  55. }
  56. break;
  57. }
  58. $start = request_var('start', 0);
  59. $submit = (isset($_POST['submit'])) ? true : false;
  60. $default_key = 'c';
  61. $sort_key = request_var('sk', $default_key);
  62. $sort_dir = request_var('sd', 'a');
  63. // Grab rank information for later
  64. $ranks = $cache->obtain_ranks();
  65. // What do you want to do today? ... oops, I think that line is taken ...
  66. switch ($mode)
  67. {
  68. case 'leaders':
  69. // www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
  70. if (!empty($phpbb_seo->seo_opt['url_rewrite'])) {
  71. $phpbb_seo->seo_path['canonical'] = $phpbb_seo->drop_sid(append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=leaders'));
  72. }
  73. $phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
  74. 'mode' => array('val' => 'leaders', 'keep' => true),
  75. );
  76. $phpbb_seo->seo_chk_dupe();
  77. // www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
  78. // Display a listing of board admins, moderators
  79. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  80. $page_title = $user->lang['THE_TEAM'];
  81. $template_html = 'memberlist_leaders.html';
  82. $user_ary = $auth->acl_get_list(false, array('a_', 'm_'), false);
  83. $admin_id_ary = $global_mod_id_ary = $mod_id_ary = $forum_id_ary = array();
  84. foreach ($user_ary as $forum_id => $forum_ary)
  85. {
  86. foreach ($forum_ary as $auth_option => $id_ary)
  87. {
  88. if (!$forum_id)
  89. {
  90. if ($auth_option == 'a_')
  91. {
  92. $admin_id_ary = array_merge($admin_id_ary, $id_ary);
  93. }
  94. else
  95. {
  96. $global_mod_id_ary = array_merge($global_mod_id_ary, $id_ary);
  97. }
  98. continue;
  99. }
  100. else
  101. {
  102. $mod_id_ary = array_merge($mod_id_ary, $id_ary);
  103. }
  104. if ($forum_id)
  105. {
  106. foreach ($id_ary as $id)
  107. {
  108. $forum_id_ary[$id][] = $forum_id;
  109. }
  110. }
  111. }
  112. }
  113. $admin_id_ary = array_unique($admin_id_ary);
  114. $global_mod_id_ary = array_unique($global_mod_id_ary);
  115. $mod_id_ary = array_merge($mod_id_ary, $global_mod_id_ary);
  116. $mod_id_ary = array_unique($mod_id_ary);
  117. // Admin group id...
  118. $sql = 'SELECT group_id
  119. FROM ' . GROUPS_TABLE . "
  120. WHERE group_name = 'ADMINISTRATORS'";
  121. $result = $db->sql_query($sql);
  122. $admin_group_id = (int) $db->sql_fetchfield('group_id');
  123. $db->sql_freeresult($result);
  124. // Get group memberships for the admin id ary...
  125. $admin_memberships = group_memberships($admin_group_id, $admin_id_ary);
  126. $admin_user_ids = array();
  127. if (!empty($admin_memberships))
  128. {
  129. // ok, we only need the user ids...
  130. foreach ($admin_memberships as $row)
  131. {
  132. $admin_user_ids[$row['user_id']] = true;
  133. }
  134. }
  135. unset($admin_memberships);
  136. $sql = 'SELECT forum_id, forum_name
  137. FROM ' . FORUMS_TABLE;
  138. $result = $db->sql_query($sql);
  139. $forums = array();
  140. while ($row = $db->sql_fetchrow($result))
  141. {
  142. $forums[$row['forum_id']] = $row['forum_name'];
  143. }
  144. $db->sql_freeresult($result);
  145. $sql = $db->sql_build_query('SELECT', array(
  146. '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, g.group_name, g.group_colour, g.group_type, ug.user_id as ug_user_id',
  147. 'FROM' => array(
  148. USERS_TABLE => 'u',
  149. GROUPS_TABLE => 'g'
  150. ),
  151. 'LEFT_JOIN' => array(
  152. array(
  153. 'FROM' => array(USER_GROUP_TABLE => 'ug'),
  154. 'ON' => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . $user->data['user_id']
  155. )
  156. ),
  157. 'WHERE' => $db->sql_in_set('u.user_id', array_unique(array_merge($admin_id_ary, $mod_id_ary)), false, true) . '
  158. AND u.group_id = g.group_id',
  159. 'ORDER_BY' => 'g.group_name ASC, u.username_clean ASC'
  160. ));
  161. $result = $db->sql_query($sql);
  162. while ($row = $db->sql_fetchrow($result))
  163. {
  164. $which_row = (in_array($row['user_id'], $admin_id_ary)) ? 'admin' : 'mod';
  165. // We sort out admins not within the 'Administrators' group.
  166. // Else, we will list those as admin only having the permission to view logs for example.
  167. if ($which_row == 'admin' && empty($admin_user_ids[$row['user_id']]))
  168. {
  169. // Remove from admin_id_ary, because the user may be a mod instead
  170. unset($admin_id_ary[array_search($row['user_id'], $admin_id_ary)]);
  171. if (!in_array($row['user_id'], $mod_id_ary) && !in_array($row['user_id'], $global_mod_id_ary))
  172. {
  173. continue;
  174. }
  175. else
  176. {
  177. $which_row = 'mod';
  178. }
  179. }
  180. $s_forum_select = '';
  181. $undisclosed_forum = false;
  182. if (isset($forum_id_ary[$row['user_id']]) && !in_array($row['user_id'], $global_mod_id_ary))
  183. {
  184. if ($which_row == 'mod' && sizeof(array_diff(array_keys($forums), $forum_id_ary[$row['user_id']])))
  185. {
  186. foreach ($forum_id_ary[$row['user_id']] as $forum_id)
  187. {
  188. if (isset($forums[$forum_id]))
  189. {
  190. if ($auth->acl_get('f_list', $forum_id))
  191. {
  192. $s_forum_select .= '<option value="">' . $forums[$forum_id] . '</option>';
  193. }
  194. else
  195. {
  196. $undisclosed_forum = true;
  197. }
  198. }
  199. }
  200. }
  201. }
  202. // If the mod is only moderating non-viewable forums we skip the user. There is no gain in displaying the person then...
  203. if (!$s_forum_select && $undisclosed_forum)
  204. {
  205. // $s_forum_select = '<option value="">' . $user->lang['FORUM_UNDISCLOSED'] . '</option>';
  206. continue;
  207. }
  208. // The person is moderating several "public" forums, therefore the person should be listed, but not giving the real group name if hidden.
  209. if ($row['group_type'] == GROUP_HIDDEN && !$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $user->data['user_id'])
  210. {
  211. $group_name = $user->lang['GROUP_UNDISCLOSED'];
  212. $u_group = '';
  213. }
  214. else
  215. {
  216. $group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
  217. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  218. $phpbb_seo->prepare_url('group', $row['group_name'], $row['group_id']);
  219. // www.phpBB-SEO.com SEO TOOLKIT END
  220. $u_group = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']);
  221. }
  222. $rank_title = $rank_img = '';
  223. get_user_rank($row['user_rank'], (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src);
  224. $template->assign_block_vars($which_row, array(
  225. 'USER_ID' => $row['user_id'],
  226. 'FORUMS' => $s_forum_select,
  227. 'RANK_TITLE' => $rank_title,
  228. 'GROUP_NAME' => $group_name,
  229. 'GROUP_COLOR' => $row['group_colour'],
  230. 'RANK_IMG' => $rank_img,
  231. 'RANK_IMG_SRC' => $rank_img_src,
  232. 'U_GROUP' => $u_group,
  233. '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']) : '',
  234. 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
  235. 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
  236. 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
  237. 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
  238. ));
  239. }
  240. $db->sql_freeresult($result);
  241. $template->assign_vars(array(
  242. 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']))
  243. );
  244. break;
  245. case 'contact':
  246. $page_title = $user->lang['IM_USER'];
  247. $template_html = 'memberlist_im.html';
  248. if (!$auth->acl_get('u_sendim'))
  249. {
  250. trigger_error('NOT_AUTHORISED');
  251. }
  252. $presence_img = '';
  253. switch ($action)
  254. {
  255. case 'aim':
  256. $lang = 'AIM';
  257. $sql_field = 'user_aim';
  258. $s_select = 'S_SEND_AIM';
  259. $s_action = '';
  260. break;
  261. case 'msnm':
  262. $lang = 'MSNM';
  263. $sql_field = 'user_msnm';
  264. $s_select = 'S_SEND_MSNM';
  265. $s_action = '';
  266. break;
  267. case 'jabber':
  268. $lang = 'JABBER';
  269. $sql_field = 'user_jabber';
  270. $s_select = (@extension_loaded('xml') && $config['jab_enable']) ? 'S_SEND_JABBER' : 'S_NO_SEND_JABBER';
  271. $s_action = append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=$action&amp;u=$user_id");
  272. break;
  273. default:
  274. trigger_error('NO_MODE', E_USER_ERROR);
  275. break;
  276. }
  277. // Grab relevant data
  278. $sql = "SELECT user_id, username, user_email, user_lang, $sql_field
  279. FROM " . USERS_TABLE . "
  280. WHERE user_id = $user_id
  281. AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
  282. $result = $db->sql_query($sql);
  283. $row = $db->sql_fetchrow($result);
  284. $db->sql_freeresult($result);
  285. if (!$row)
  286. {
  287. trigger_error('NO_USER');
  288. }
  289. else if (empty($row[$sql_field]))
  290. {
  291. trigger_error('IM_NO_DATA');
  292. }
  293. // Post data grab actions
  294. switch ($action)
  295. {
  296. case 'jabber':
  297. add_form_key('memberlist_messaging');
  298. if ($submit && @extension_loaded('xml') && $config['jab_enable'])
  299. {
  300. if (check_form_key('memberlist_messaging'))
  301. {
  302. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  303. $subject = sprintf($user->lang['IM_JABBER_SUBJECT'], $user->data['username'], $config['server_name']);
  304. $message = utf8_normalize_nfc(request_var('message', '', true));
  305. if (empty($message))
  306. {
  307. trigger_error('EMPTY_MESSAGE_IM');
  308. }
  309. $messenger = new messenger(false);
  310. $messenger->template('profile_send_im', $row['user_lang']);
  311. $messenger->subject(htmlspecialchars_decode($subject));
  312. $messenger->replyto($user->data['user_email']);
  313. $messenger->im($row['user_jabber'], $row['username']);
  314. $messenger->assign_vars(array(
  315. 'BOARD_CONTACT' => $config['board_contact'],
  316. 'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']),
  317. 'TO_USERNAME' => htmlspecialchars_decode($row['username']),
  318. 'MESSAGE' => htmlspecialchars_decode($message))
  319. );
  320. $messenger->send(NOTIFY_IM);
  321. $s_select = 'S_SENT_JABBER';
  322. }
  323. else
  324. {
  325. trigger_error('FORM_INVALID');
  326. }
  327. }
  328. break;
  329. }
  330. // Send vars to the template
  331. $template->assign_vars(array(
  332. 'IM_CONTACT' => $row[$sql_field],
  333. 'A_IM_CONTACT' => addslashes($row[$sql_field]),
  334. 'U_AIM_CONTACT' => ($action == 'aim') ? 'aim:addbuddy?screenname=' . urlencode($row[$sql_field]) : '',
  335. 'U_AIM_MESSAGE' => ($action == 'aim') ? 'aim:goim?screenname=' . urlencode($row[$sql_field]) . '&amp;message=' . urlencode($config['sitename']) : '',
  336. 'USERNAME' => $row['username'],
  337. 'CONTACT_NAME' => $row[$sql_field],
  338. 'SITENAME' => $config['sitename'],
  339. 'PRESENCE_IMG' => $presence_img,
  340. 'L_SEND_IM_EXPLAIN' => $user->lang['IM_' . $lang],
  341. 'L_IM_SENT_JABBER' => sprintf($user->lang['IM_SENT_JABBER'], $row['username']),
  342. $s_select => true,
  343. 'S_IM_ACTION' => $s_action)
  344. );
  345. break;
  346. case 'viewprofile':
  347. // Display a profile
  348. if ($user_id == ANONYMOUS && !$username)
  349. {
  350. trigger_error('NO_USER');
  351. }
  352. // Get user...
  353. $sql = 'SELECT *
  354. FROM ' . USERS_TABLE . '
  355. WHERE ' . (($username) ? "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'" : "user_id = $user_id");
  356. $result = $db->sql_query($sql);
  357. $member = $db->sql_fetchrow($result);
  358. $db->sql_freeresult($result);
  359. if (!$member)
  360. {
  361. trigger_error('NO_USER');
  362. }
  363. // a_user admins and founder are able to view inactive users and bots to be able to manage them more easily
  364. // Normal users are able to see at least users having only changed their profile settings but not yet reactivated.
  365. if (!$auth->acl_get('a_user') && $user->data['user_type'] != USER_FOUNDER)
  366. {
  367. if ($member['user_type'] == USER_IGNORE)
  368. {
  369. trigger_error('NO_USER');
  370. }
  371. else if ($member['user_type'] == USER_INACTIVE && $member['user_inactive_reason'] != INACTIVE_PROFILE)
  372. {
  373. trigger_error('NO_USER');
  374. }
  375. }
  376. $user_id = (int) $member['user_id'];
  377. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  378. $phpbb_seo->set_user_url( $member['username'], $user_id );
  379. // www.phpBB-SEO.com SEO TOOLKIT END
  380. // www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
  381. if (!empty($phpbb_seo->seo_opt['url_rewrite'])) {
  382. $phpbb_seo->seo_path['canonical'] = $phpbb_seo->drop_sid(append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&amp;u=$user_id"));
  383. }
  384. $phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
  385. 'mode' => array('val' => 'viewprofile', 'keep' => true),
  386. 'u' => array('val' => $user_id, 'keep' => true, 'force' => true),
  387. );
  388. $phpbb_seo->seo_chk_dupe();
  389. // www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
  390. // Get group memberships
  391. // Also get visiting user's groups to determine hidden group memberships if necessary.
  392. $auth_hidden_groups = ($user_id === (int) $user->data['user_id'] || $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? true : false;
  393. $sql_uid_ary = ($auth_hidden_groups) ? array($user_id) : array($user_id, (int) $user->data['user_id']);
  394. // Do the SQL thang
  395. $sql = 'SELECT g.group_id, g.group_name, g.group_type, ug.user_id
  396. FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
  397. WHERE ' . $db->sql_in_set('ug.user_id', $sql_uid_ary) . '
  398. AND g.group_id = ug.group_id
  399. AND ug.user_pending = 0';
  400. $result = $db->sql_query($sql);
  401. // Divide data into profile data and current user data
  402. $profile_groups = $user_groups = array();
  403. while ($row = $db->sql_fetchrow($result))
  404. {
  405. $row['user_id'] = (int) $row['user_id'];
  406. $row['group_id'] = (int) $row['group_id'];
  407. if ($row['user_id'] == $user_id)
  408. {
  409. $profile_groups[] = $row;
  410. }
  411. else
  412. {
  413. $user_groups[$row['group_id']] = $row['group_id'];
  414. }
  415. }
  416. $db->sql_freeresult($result);
  417. // Filter out hidden groups and sort groups by name
  418. $group_data = $group_sort = array();
  419. foreach ($profile_groups as $row)
  420. {
  421. if ($row['group_type'] == GROUP_SPECIAL)
  422. {
  423. // Lookup group name in language dictionary
  424. if (isset($user->lang['G_' . $row['group_name']]))
  425. {
  426. $row['group_name'] = $user->lang['G_' . $row['group_name']];
  427. }
  428. }
  429. else if (!$auth_hidden_groups && $row['group_type'] == GROUP_HIDDEN && !isset($user_groups[$row['group_id']]))
  430. {
  431. // Skip over hidden groups the user cannot see
  432. continue;
  433. }
  434. $group_sort[$row['group_id']] = utf8_clean_string($row['group_name']);
  435. $group_data[$row['group_id']] = $row;
  436. }
  437. unset($profile_groups);
  438. unset($user_groups);
  439. asort($group_sort);
  440. $group_options = '';
  441. foreach ($group_sort as $group_id => $null)
  442. {
  443. $row = $group_data[$group_id];
  444. $group_options .= '<option value="' . $row['group_id'] . '"' . (($row['group_id'] == $member['group_id']) ? ' selected="selected"' : '') . '>' . $row['group_name'] . '</option>';
  445. }
  446. unset($group_data);
  447. unset($group_sort);
  448. // What colour is the zebra
  449. $sql = 'SELECT friend, foe
  450. FROM ' . ZEBRA_TABLE . "
  451. WHERE zebra_id = $user_id
  452. AND user_id = {$user->data['user_id']}";
  453. $result = $db->sql_query($sql);
  454. $row = $db->sql_fetchrow($result);
  455. $foe = ($row['foe']) ? true : false;
  456. $friend = ($row['friend']) ? true : false;
  457. $db->sql_freeresult($result);
  458. if ($config['load_onlinetrack'])
  459. {
  460. $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
  461. FROM ' . SESSIONS_TABLE . "
  462. WHERE session_user_id = $user_id";
  463. $result = $db->sql_query($sql);
  464. $row = $db->sql_fetchrow($result);
  465. $db->sql_freeresult($result);
  466. $member['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
  467. $member['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
  468. unset($row);
  469. }
  470. if ($config['load_user_activity'])
  471. {
  472. display_user_activity($member);
  473. }
  474. // Do the relevant calculations
  475. $memberdays = max(1, round((time() - $member['user_regdate']) / 86400));
  476. $posts_per_day = $member['user_posts'] / $memberdays;
  477. $percentage = ($config['num_posts']) ? min(100, ($member['user_posts'] / $config['num_posts']) * 100) : 0;
  478. if ($member['user_sig'])
  479. {
  480. $member['user_sig'] = censor_text($member['user_sig']);
  481. if ($member['user_sig_bbcode_bitfield'])
  482. {
  483. include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
  484. $bbcode = new bbcode();
  485. $bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']);
  486. }
  487. $member['user_sig'] = bbcode_nl2br($member['user_sig']);
  488. $member['user_sig'] = smiley_text($member['user_sig']);
  489. }
  490. $poster_avatar = get_user_avatar($member['user_avatar'], $member['user_avatar_type'], $member['user_avatar_width'], $member['user_avatar_height']);
  491. // 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
  492. $zebra_enabled = $friends_enabled = $foes_enabled = $user_notes_enabled = $warn_user_enabled = false;
  493. // Only check if the user is logged in
  494. if ($user->data['is_registered'])
  495. {
  496. if (!class_exists('p_master'))
  497. {
  498. include($phpbb_root_path . 'includes/functions_module.' . $phpEx);
  499. }
  500. $module = new p_master();
  501. $module->list_modules('ucp');
  502. $module->list_modules('mcp');
  503. $user_notes_enabled = ($module->loaded('notes', 'user_notes')) ? true : false;
  504. $warn_user_enabled = ($module->loaded('warn', 'warn_user')) ? true : false;
  505. $zebra_enabled = ($module->loaded('zebra')) ? true : false;
  506. $friends_enabled = ($module->loaded('zebra', 'friends')) ? true : false;
  507. $foes_enabled = ($module->loaded('zebra', 'foes')) ? true : false;
  508. unset($module);
  509. }
  510. $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled));
  511. // Custom Profile Fields
  512. $profile_fields = array();
  513. if ($config['load_cpf_viewprofile'])
  514. {
  515. include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
  516. $cp = new custom_profile();
  517. $profile_fields = $cp->generate_profile_fields_template('grab', $user_id);
  518. $profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields[$user_id]) : array();
  519. }
  520. // If the user has m_approve permission or a_user permission, then list then display unapproved posts
  521. if ($auth->acl_getf_global('m_approve') || $auth->acl_get('a_user'))
  522. {
  523. $sql = 'SELECT COUNT(post_id) as posts_in_queue
  524. FROM ' . POSTS_TABLE . '
  525. WHERE poster_id = ' . $user_id . '
  526. AND post_approved = 0';
  527. $result = $db->sql_query($sql);
  528. $member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
  529. $db->sql_freeresult($result);
  530. }
  531. else
  532. {
  533. $member['posts_in_queue'] = 0;
  534. }
  535. $template->assign_vars(array(
  536. 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $member['posts_in_queue']),
  537. 'POSTS_DAY' => sprintf($user->lang['POST_DAY'], $posts_per_day),
  538. 'POSTS_PCT' => sprintf($user->lang['POST_PCT'], $percentage),
  539. 'OCCUPATION' => (!empty($member['user_occ'])) ? censor_text($member['user_occ']) : '',
  540. 'INTERESTS' => (!empty($member['user_interests'])) ? censor_text($member['user_interests']) : '',
  541. 'SIGNATURE' => $member['user_sig'],
  542. 'POSTS_IN_QUEUE'=> $member['posts_in_queue'],
  543. 'AVATAR_IMG' => $poster_avatar,
  544. 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
  545. 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']),
  546. 'WWW_IMG' => $user->img('icon_contact_www', $user->lang['WWW']),
  547. 'ICQ_IMG' => $user->img('icon_contact_icq', $user->lang['ICQ']),
  548. 'AIM_IMG' => $user->img('icon_contact_aim', $user->lang['AIM']),
  549. 'MSN_IMG' => $user->img('icon_contact_msnm', $user->lang['MSNM']),
  550. 'YIM_IMG' => $user->img('icon_contact_yahoo', $user->lang['YIM']),
  551. 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']),
  552. 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
  553. 'S_PROFILE_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group'),
  554. 'S_GROUP_OPTIONS' => $group_options,
  555. 'S_CUSTOM_FIELDS' => (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
  556. 'U_USER_ADMIN' => ($auth->acl_get('a_user')) ? append_sid("{$phpbb_root_path}adm/index.$phpEx", 'i=users&amp;mode=overview&amp;u=' . $user_id, true, $user->session_id) : '',
  557. '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) : '',
  558. 'U_MCP_QUEUE' => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
  559. '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')) : '',
  560. 'S_USER_NOTES' => ($user_notes_enabled) ? true : false,
  561. 'S_WARN_USER' => ($warn_user_enabled) ? true : false,
  562. 'S_ZEBRA' => ($user->data['user_id'] != $user_id && $user->data['is_registered'] && $zebra_enabled) ? true : false,
  563. 'U_ADD_FRIEND' => (!$friend && !$foe && $friends_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
  564. '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']))) : '',
  565. 'U_REMOVE_FRIEND' => ($friend && $friends_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;usernames[]=' . $user_id) : '',
  566. '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) : '',
  567. ));
  568. if (!empty($profile_fields['row']))
  569. {
  570. $template->assign_vars($profile_fields['row']);
  571. }
  572. if (!empty($profile_fields['blockrow']))
  573. {
  574. foreach ($profile_fields['blockrow'] as $field_data)
  575. {
  576. $template->assign_block_vars('custom_fields', $field_data);
  577. }
  578. }
  579. // Inactive reason/account?
  580. if ($member['user_type'] == USER_INACTIVE)
  581. {
  582. $user->add_lang('acp/common');
  583. $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
  584. switch ($member['user_inactive_reason'])
  585. {
  586. case INACTIVE_REGISTER:
  587. $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
  588. break;
  589. case INACTIVE_PROFILE:
  590. $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
  591. break;
  592. case INACTIVE_MANUAL:
  593. $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
  594. break;
  595. case INACTIVE_REMIND:
  596. $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
  597. break;
  598. }
  599. $template->assign_vars(array(
  600. 'S_USER_INACTIVE' => true,
  601. 'USER_INACTIVE_REASON' => $inactive_reason)
  602. );
  603. }
  604. // Now generate page title
  605. $page_title = sprintf($user->lang['VIEWING_PROFILE'], $member['username']);
  606. $template_html = 'memberlist_view.html';
  607. break;
  608. case 'email':
  609. // Send an email
  610. $page_title = $user->lang['SEND_EMAIL'];
  611. $template_html = 'memberlist_email.html';
  612. add_form_key('memberlist_email');
  613. if (!$config['email_enable'])
  614. {
  615. trigger_error('EMAIL_DISABLED');
  616. }
  617. if (!$auth->acl_get('u_sendemail'))
  618. {
  619. trigger_error('NO_EMAIL');
  620. }
  621. // Are we trying to abuse the facility?
  622. if (time() - $user->data['user_emailtime'] < $config['flood_interval'])
  623. {
  624. trigger_error('FLOOD_EMAIL_LIMIT');
  625. }
  626. // Determine action...
  627. $user_id = request_var('u', 0);
  628. $topic_id = request_var('t', 0);
  629. // Send email to user...
  630. if ($user_id)
  631. {
  632. if ($user_id == ANONYMOUS || !$config['board_email_form'])
  633. {
  634. trigger_error('NO_EMAIL');
  635. }
  636. // Get the appropriate username, etc.
  637. $sql = 'SELECT username, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type
  638. FROM ' . USERS_TABLE . "
  639. WHERE user_id = $user_id
  640. AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
  641. $result = $db->sql_query($sql);
  642. $row = $db->sql_fetchrow($result);
  643. $db->sql_freeresult($result);
  644. if (!$row)
  645. {
  646. trigger_error('NO_USER');
  647. }
  648. // Can we send email to this user?
  649. if (!$row['user_allow_viewemail'] && !$auth->acl_get('a_user'))
  650. {
  651. trigger_error('NO_EMAIL');
  652. }
  653. }
  654. else if ($topic_id)
  655. {
  656. // Send topic heads-up to email address
  657. $sql = 'SELECT forum_id, topic_title
  658. FROM ' . TOPICS_TABLE . "
  659. WHERE topic_id = $topic_id";
  660. $result = $db->sql_query($sql);
  661. $row = $db->sql_fetchrow($result);
  662. $db->sql_freeresult($result);
  663. if (!$row)
  664. {
  665. trigger_error('NO_TOPIC');
  666. }
  667. if ($row['forum_id'])
  668. {
  669. if (!$auth->acl_get('f_read', $row['forum_id']))
  670. {
  671. trigger_error('SORRY_AUTH_READ');
  672. }
  673. if (!$auth->acl_get('f_email', $row['forum_id']))
  674. {
  675. trigger_error('NO_EMAIL');
  676. }
  677. }
  678. else
  679. {
  680. // If global announcement, we need to check if the user is able to at least read and email in one forum...
  681. if (!$auth->acl_getf_global('f_read'))
  682. {
  683. trigger_error('SORRY_AUTH_READ');
  684. }
  685. if (!$auth->acl_getf_global('f_email'))
  686. {
  687. trigger_error('NO_EMAIL');
  688. }
  689. }
  690. }
  691. else
  692. {
  693. trigger_error('NO_EMAIL');
  694. }
  695. $error = array();
  696. $name = utf8_normalize_nfc(request_var('name', '', true));
  697. $email = request_var('email', '');
  698. $email_lang = request_var('lang', $config['default_lang']);
  699. $subject = utf8_normalize_nfc(request_var('subject', '', true));
  700. $message = utf8_normalize_nfc(request_var('message', '', true));
  701. $cc = (isset($_POST['cc_email'])) ? true : false;
  702. $submit = (isset($_POST['submit'])) ? true : false;
  703. if ($submit)
  704. {
  705. if (!check_form_key('memberlist_email'))
  706. {
  707. $error[] = 'FORM_INVALID';
  708. }
  709. if ($user_id)
  710. {
  711. if (!$subject)
  712. {
  713. $error[] = $user->lang['EMPTY_SUBJECT_EMAIL'];
  714. }
  715. if (!$message)
  716. {
  717. $error[] = $user->lang['EMPTY_MESSAGE_EMAIL'];
  718. }
  719. $name = $row['username'];
  720. $email_lang = $row['user_lang'];
  721. $email = $row['user_email'];
  722. }
  723. else
  724. {
  725. if (!$email || !preg_match('/^' . get_preg_expression('email') . '$/i', $email))
  726. {
  727. $error[] = $user->lang['EMPTY_ADDRESS_EMAIL'];
  728. }
  729. if (!$name)
  730. {
  731. $error[] = $user->lang['EMPTY_NAME_EMAIL'];
  732. }
  733. }
  734. if (!sizeof($error))
  735. {
  736. $sql = 'UPDATE ' . USERS_TABLE . '
  737. SET user_emailtime = ' . time() . '
  738. WHERE user_id = ' . $user->data['user_id'];
  739. $result = $db->sql_query($sql);
  740. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  741. $messenger = new messenger(false);
  742. $email_tpl = ($user_id) ? 'profile_send_email' : 'email_notify';
  743. $mail_to_users = array();
  744. $mail_to_users[] = array(
  745. 'email_lang' => $email_lang,
  746. 'email' => $email,
  747. 'name' => $name,
  748. 'username' => ($user_id) ? $row['username'] : '',
  749. 'to_name' => $name,
  750. 'user_jabber' => ($user_id) ? $row['user_jabber'] : '',
  751. 'user_notify_type' => ($user_id) ? $row['user_notify_type'] : NOTIFY_EMAIL,
  752. 'topic_title' => (!$user_id) ? $row['topic_title'] : '',
  753. 'forum_id' => (!$user_id) ? $row['forum_id'] : 0,
  754. );
  755. // Ok, now the same email if CC specified, but without exposing the users email address
  756. if ($cc)
  757. {
  758. $mail_to_users[] = array(
  759. 'email_lang' => $user->data['user_lang'],
  760. 'email' => $user->data['user_email'],
  761. 'name' => $user->data['username'],
  762. 'username' => $user->data['username'],
  763. 'to_name' => $name,
  764. 'user_jabber' => $user->data['user_jabber'],
  765. 'user_notify_type' => ($user_id) ? $user->data['user_notify_type'] : NOTIFY_EMAIL,
  766. 'topic_title' => (!$user_id) ? $row['topic_title'] : '',
  767. 'forum_id' => (!$user_id) ? $row['forum_id'] : 0,
  768. );
  769. }
  770. foreach ($mail_to_users as $row)
  771. {
  772. $messenger->template($email_tpl, $row['email_lang']);
  773. $messenger->replyto($user->data['user_email']);
  774. $messenger->to($row['email'], $row['name']);
  775. if ($user_id)
  776. {
  777. $messenger->subject(htmlspecialchars_decode($subject));
  778. $messenger->im($row['user_jabber'], $row['username']);
  779. $notify_type = $row['user_notify_type'];
  780. }
  781. else
  782. {
  783. $notify_type = NOTIFY_EMAIL;
  784. }
  785. $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
  786. $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
  787. $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
  788. $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
  789. $messenger->assign_vars(array(
  790. 'BOARD_CONTACT' => $config['board_contact'],
  791. 'TO_USERNAME' => htmlspecialchars_decode($row['to_name']),
  792. 'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']),
  793. 'MESSAGE' => htmlspecialchars_decode($message))
  794. );
  795. if ($topic_id)
  796. {
  797. $messenger->assign_vars(array(
  798. 'TOPIC_NAME' => htmlspecialchars_decode($row['topic_title']),
  799. 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=" . $row['forum_id'] . "&t=$topic_id")
  800. );
  801. }
  802. $messenger->send($notify_type);
  803. }
  804. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  805. $message = ($user_id) ? sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>') : sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$row['forum_id']}&amp;t=$topic_id") . '">', '</a>');
  806. trigger_error($user->lang['EMAIL_SENT'] . '<br /><br />' . $message);
  807. }
  808. }
  809. if ($user_id)
  810. {
  811. $template->assign_vars(array(
  812. 'S_SEND_USER' => true,
  813. 'USERNAME' => $row['username'],
  814. 'L_EMAIL_BODY_EXPLAIN' => $user->lang['EMAIL_BODY_EXPLAIN'],
  815. 'S_POST_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;u=' . $user_id))
  816. );
  817. }
  818. else
  819. {
  820. $template->assign_vars(array(
  821. 'EMAIL' => $email,
  822. 'NAME' => $name,
  823. 'S_LANG_OPTIONS' => language_select($email_lang),
  824. 'L_EMAIL_BODY_EXPLAIN' => $user->lang['EMAIL_TOPIC_EXPLAIN'],
  825. 'S_POST_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;t=' . $topic_id))
  826. );
  827. }
  828. $template->assign_vars(array(
  829. 'ERROR_MESSAGE' => (sizeof($error)) ? implode('<br />', $error) : '',
  830. 'SUBJECT' => $subject,
  831. 'MESSAGE' => $message,
  832. )
  833. );
  834. break;
  835. case 'group':
  836. default:
  837. // The basic memberlist
  838. $page_title = $user->lang['MEMBERLIST'];
  839. $template_html = 'memberlist_body.html';
  840. // Sorting
  841. $sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_LOCATION'], 'c' => $user->lang['SORT_JOINED'], 'd' => $user->lang['SORT_POST_COUNT'], 'f' => $user->lang['WEBSITE'], 'g' => $user->lang['ICQ'], 'h' => $user->lang['AIM'], 'i' => $user->lang['MSNM'], 'j' => $user->lang['YIM'], 'k' => $user->lang['JABBER']);
  842. $sort_key_sql = array('a' => 'u.username_clean', 'b' => 'u.user_from', 'c' => 'u.user_regdate', 'd' => 'u.user_posts', 'f' => 'u.user_website', 'g' => 'u.user_icq', 'h' => 'u.user_aim', 'i' => 'u.user_msnm', 'j' => 'u.user_yim', 'k' => 'u.user_jabber');
  843. if ($auth->acl_get('a_user'))
  844. {
  845. $sort_key_text['e'] = $user->lang['SORT_EMAIL'];
  846. $sort_key_sql['e'] = 'u.user_email';
  847. }
  848. if ($auth->acl_get('u_viewonline'))
  849. {
  850. $sort_key_text['l'] = $user->lang['SORT_LAST_ACTIVE'];
  851. $sort_key_sql['l'] = 'u.user_lastvisit';
  852. }
  853. $sort_key_text['m'] = $user->lang['SORT_RANK'];
  854. $sort_key_sql['m'] = 'u.user_rank';
  855. $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
  856. $s_sort_key = '';
  857. foreach ($sort_key_text as $key => $value)
  858. {
  859. $selected = ($sort_key == $key) ? ' selected="selected"' : '';
  860. $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  861. }
  862. $s_sort_dir = '';
  863. foreach ($sort_dir_text as $key => $value)
  864. {
  865. $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
  866. $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  867. }
  868. // Additional sorting options for user search ... if search is enabled, if not
  869. // then only admins can make use of this (for ACP functionality)
  870. $sql_select = $sql_where_data = $sql_from = $sql_where = $order_by = '';
  871. $form = request_var('form', '');
  872. $field = request_var('field', '');
  873. $select_single = request_var('select_single', false);
  874. // Search URL parameters, if any of these are in the URL we do a search
  875. $search_params = array('username', 'email', 'icq', 'aim', 'yahoo', 'msn', 'jabber', 'search_group_id', 'joined_select', 'active_select', 'count_select', 'joined', 'active', 'count', 'ip');
  876. // We validate form and field here, only id/class allowed
  877. $form = (!preg_match('/^[a-z0-9_-]+$/i', $form)) ? '' : $form;
  878. $field = (!preg_match('/^[a-z0-9_-]+$/i', $field)) ? '' : $field;
  879. if (($mode == 'searchuser' || sizeof(array_intersect(array_keys($_GET), $search_params)) > 0) && ($config['load_search'] || $auth->acl_get('a_')))
  880. {
  881. $username = request_var('username', '', true);
  882. $email = strtolower(request_var('email', ''));
  883. $icq = request_var('icq', '');
  884. $aim = request_var('aim', '');
  885. $yahoo = request_var('yahoo', '');
  886. $msn = request_var('msn', '');
  887. $jabber = request_var('jabber', '');
  888. $search_group_id = request_var('search_group_id', 0);
  889. // when using these, make sure that we actually have values defined in $find_key_match
  890. $joined_select = request_var('joined_select', 'lt');
  891. $active_select = request_var('active_select', 'lt');
  892. $count_select = request_var('count_select', 'eq');
  893. $joined = explode('-', request_var('joined', ''));
  894. $active = explode('-', request_var('active', ''));
  895. $count = (request_var('count', '') !== '') ? request_var('count', 0) : '';
  896. $ipdomain = request_var('ip', '');
  897. $find_key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
  898. $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
  899. $s_find_count = '';
  900. foreach ($find_count as $key => $value)
  901. {
  902. $selected = ($count_select == $key) ? ' selected="selected"' : '';
  903. $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  904. }
  905. $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
  906. $s_find_join_time = '';
  907. foreach ($find_time as $key => $value)
  908. {
  909. $selected = ($joined_select == $key) ? ' selected="selected"' : '';
  910. $s_find_join_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  911. }
  912. $s_find_active_time = '';
  913. foreach ($find_time as $key => $value)
  914. {
  915. $selected = ($active_select == $key) ? ' selected="selected"' : '';
  916. $s_find_active_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  917. }
  918. $sql_where .= ($username) ? ' AND u.username_clean ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($username))) : '';
  919. $sql_where .= ($auth->acl_get('a_user') && $email) ? ' AND u.user_email ' . $db->sql_like_expression(str_replace('*', $db->any_char, $email)) . ' ' : '';
  920. $sql_where .= ($icq) ? ' AND u.user_icq ' . $db->sql_like_expression(str_replace('*', $db->any_char, $icq)) . ' ' : '';
  921. $sql_where .= ($aim) ? ' AND u.user_aim ' . $db->sql_like_expression(str_replace('*', $db->any_char, $aim)) . ' ' : '';
  922. $sql_where .= ($yahoo) ? ' AND u.user_yim ' . $db->sql_like_expression(str_replace('*', $db->any_char, $yahoo)) . ' ' : '';
  923. $sql_where .= ($msn) ? ' AND u.user_msnm ' . $db->sql_like_expression(str_replace('*', $db->any_char, $msn)) . ' ' : '';
  924. $sql_where .= ($jabber) ? ' AND u.user_jabber ' . $db->sql_like_expression(str_replace('*', $db->any_char, $jabber)) . ' ' : '';
  925. $sql_where .= (is_numeric($count) && isset($find_key_match[$count_select])) ? ' AND u.user_posts ' . $find_key_match[$count_select] . ' ' . (int) $count . ' ' : '';
  926. if (isset($find_key_match[$joined_select]) && sizeof($joined) == 3)
  927. {
  928. // Before PHP 5.1 an error value -1 can be returned instead of false.
  929. // Theoretically gmmktime() can also legitimately return -1 as an actual timestamp.
  930. // But since we do not pass the $second parameter to gmmktime(),
  931. // an actual unix timestamp -1 cannot be returned in this case.
  932. // Thus we can check whether it is -1 and treat -1 as an error.
  933. $joined_time = gmmktime(0, 0, 0, (int) $joined[1], (int) $joined[2], (int) $joined[0]);
  934. if ($joined_time !== false && $joined_time !== -1)
  935. {
  936. $sql_where .= " AND u.user_regdate " . $find_key_match[$joined_select] . ' ' . $joined_time;
  937. }
  938. }
  939. if (isset($find_key_match[$active_select]) && sizeof($active) == 3 && $auth->acl_get('u_viewonline'))
  940. {
  941. $active_time = gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]);
  942. if ($active_time !== false && $active_time !== -1)
  943. {
  944. $sql_where .= " AND u.user_lastvisit " . $find_key_match[$active_select] . ' ' . $active_time;
  945. }
  946. }
  947. $sql_where .= ($search_group_id) ? " AND u.user_id = ug.user_id AND ug.group_id = $search_group_id AND ug.user_pending = 0 " : '';
  948. if ($search_group_id)
  949. {
  950. $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
  951. }
  952. if ($ipdomain && $auth->acl_getf_global('m_info'))
  953. {
  954. if (strspn($ipdomain, 'abcdefghijklmnopqrstuvwxyz'))
  955. {
  956. $hostnames = gethostbynamel($ipdomain);
  957. if ($hostnames !== false)
  958. {
  959. $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)))) . "'";
  960. }
  961. else
  962. {
  963. $ips = false;
  964. }
  965. }
  966. else
  967. {
  968. $ips = "'" . str_replace('*', '%', $db->sql_escape($ipdomain)) . "'";
  969. }
  970. if ($ips === false)
  971. {
  972. // A minor fudge but it does the job :D
  973. $sql_where .= " AND u.user_id = 0";
  974. }
  975. else
  976. {
  977. $ip_forums = array_keys($auth->acl_getf('m_info', true));
  978. $sql = 'SELECT DISTINCT poster_id
  979. FROM ' . POSTS_TABLE . '
  980. WHERE poster_ip ' . ((strpos($ips, '%') !== false) ? 'LIKE' : 'IN') . " ($ips)
  981. AND forum_id IN (0, " . implode(', ', $ip_forums) . ')';
  982. $result = $db->sql_query($sql);
  983. if ($row = $db->sql_fetchrow($result))
  984. {
  985. $ip_sql = array();
  986. do
  987. {
  988. $ip_sql[] = $row['poster_id'];
  989. }
  990. while ($row = $db->sql_fetchrow($result));
  991. $sql_where .= ' AND ' . $db->sql_in_set('u.user_id', $ip_sql);
  992. }
  993. else
  994. {
  995. // A minor fudge but it does the job :D
  996. $sql_where .= " AND u.user_id = 0";
  997. }
  998. unset($ip_forums);
  999. $db->sql_freeresult($result);
  1000. }
  1001. }
  1002. }
  1003. $first_char = request_var('first_char', '');
  1004. if ($first_char == 'other')
  1005. {
  1006. for ($i = 97; $i < 123; $i++)
  1007. {
  1008. $sql_where .= ' AND u.username_clean NOT ' . $db->sql_like_expression(chr($i) . $db->any_char);
  1009. }
  1010. }
  1011. else if ($first_char)
  1012. {
  1013. $sql_where .= ' AND u.username_clean ' . $db->sql_like_expression(substr($first_char, 0, 1) . $db->any_char);
  1014. }
  1015. // Are we looking at a usergroup? If so, fetch additional info
  1016. // and further restrict the user info query
  1017. if ($mode == 'group')
  1018. {
  1019. // We JOIN here to save a query for determining membership for hidden groups. ;)
  1020. $sql = 'SELECT g.*, ug.user_id
  1021. FROM ' . GROUPS_TABLE . ' g
  1022. 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)
  1023. WHERE g.group_id = $group_id";
  1024. $result = $db->sql_query($sql);
  1025. $group_row = $db->sql_fetchrow($result);
  1026. $db->sql_freeresult($result);
  1027. if (!$group_row)
  1028. {
  1029. trigger_error('NO_GROUP');
  1030. }
  1031. switch ($group_row['group_type'])
  1032. {
  1033. case GROUP_OPEN:
  1034. $group_row['l_group_type'] = 'OPEN';
  1035. break;
  1036. case GROUP_CLOSED:
  1037. $group_row['l_group_type'] = 'CLOSED';
  1038. break;
  1039. case GROUP_HIDDEN:
  1040. $group_row['l_group_type'] = 'HIDDEN';
  1041. // Check for membership or special permissions
  1042. if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $group_row['user_id'] != $user->data['user_id'])
  1043. {
  1044. trigger_error('NO_GROUP');
  1045. }
  1046. break;
  1047. case GROUP_SPECIAL:
  1048. $group_row['l_group_type'] = 'SPECIAL';
  1049. break;
  1050. case GROUP_FREE:
  1051. $group_row['l_group_type'] = 'FREE';
  1052. break;
  1053. }
  1054. // Misusing the avatar function for displaying group avatars...
  1055. $avatar_img = get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR');
  1056. $rank_title = $rank_img = $rank_img_src = '';
  1057. if ($group_row['group_rank'])
  1058. {
  1059. if (isset($ranks['special'][$group_row['group_rank']]))
  1060. {
  1061. $rank_title = $ranks['special'][$group_row['group_rank']]['rank_title'];
  1062. }
  1063. $rank_img = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $ranks['special'][$group_row['group_rank']]['rank_image'] . '" alt="' . $ranks['special'][$group_row['group_rank']]['rank_title'] . '" title="' . $ranks['special'][$group_row['group_rank']]['rank_title'] . '" /><br />' : '';
  1064. $rank_img_src = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$group_row['group_rank']]['rank_image'] : '';
  1065. }
  1066. else
  1067. {
  1068. $rank_title = '';
  1069. $rank_img = '';
  1070. $rank_img_src = '';
  1071. }
  1072. $template->assign_vars(array(
  1073. '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']),
  1074. 'GROUP_NAME' => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
  1075. 'GROUP_COLOR' => $group_row['group_colour'],
  1076. 'GROUP_TYPE' => $user->lang['GROUP_IS_' . $group_row['l_group_type']],
  1077. 'GROUP_RANK' => $rank_title,
  1078. 'AVATAR_IMG' => $avatar_img,
  1079. 'RANK_IMG' => $rank_img,
  1080. 'RANK_IMG_SRC' => $rank_img_src,
  1081. '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) : '',)
  1082. );
  1083. $sql_select = ', ug.group_leader';
  1084. $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
  1085. $order_by = 'ug.group_leader DESC, ';
  1086. $sql_where .= " AND ug.user_pending = 0 AND u.user_id = ug.user_id AND ug.group_id = $group_id";
  1087. $sql_where_data = " AND u.user_id = ug.user_id AND ug.group_id = $group_id";
  1088. }
  1089. // Sorting and order
  1090. if (!isset($sort_key_sql[$sort_key]))
  1091. {
  1092. $sort_key = $default_key;
  1093. }
  1094. $order_by .= $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
  1095. // Unfortunately we must do this here for sorting by rank, else the sort order is applied wrongly
  1096. if ($sort_key == 'm')
  1097. {
  1098. $order_by .= ', u.user_posts DESC';
  1099. }
  1100. // Count the users ...
  1101. if ($sql_where)
  1102. {
  1103. $sql = 'SELECT COUNT(u.user_id) AS total_users
  1104. FROM ' . USERS_TABLE . " u$sql_from
  1105. WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
  1106. $sql_where";
  1107. $result = $db->sql_query($sql);
  1108. $total_users = (int) $db->sql_fetchfield('total_users');
  1109. $db->sql_freeresult($result);
  1110. }
  1111. else
  1112. {
  1113. $total_users = $config['num_users'];
  1114. }
  1115. $s_char_options = '<option value=""' . ((!$first_char) ? ' selected="selected"' : '') . '>&nbsp; &nbsp;</option>';
  1116. for ($i = 97; $i < 123; $i++)
  1117. {
  1118. $s_char_options .= '<option value="' . chr($i) . '"' . (($first_char == chr($i)) ? ' selected="selected"' : '') . '>' . chr($i-32) . '</option>';
  1119. }
  1120. $s_char_options .= '<option value="other"' . (($first_char == 'other') ? ' selected="selected"' : '') . '>' . $user->lang['OTHER'] . '</option>';
  1121. // Build a relevant pagination_url
  1122. $params = $sort_params = array();
  1123. // We do not use request_var() here directly to save some calls (not all variables are set)
  1124. $check_params = array(
  1125. 'g' => array('g', 0),
  1126. 'sk' => array('sk', $default_key),
  1127. 'sd' => array('sd', 'a'),
  1128. 'form' => array('form', ''),
  1129. 'field' => array('field', ''),
  1130. 'select_single' => array('select_single', $select_single),
  1131. 'username' => array('username', '', true),
  1132. 'email' => array('email', ''),
  1133. 'icq' => array('icq', ''),
  1134. 'aim' => array('aim', ''),
  1135. 'yahoo' => array('yahoo', ''),
  1136. 'msn' => array('msn', ''),
  1137. 'jabber' => array('jabber', ''),
  1138. 'search_group_id' => array('search_group_id', 0),
  1139. 'joined_select' => array('joined_select', 'lt'),
  1140. 'active_select' => array('active_select', 'lt'),
  1141. 'count_select' => array('count_select', 'eq'),
  1142. 'joined' => array('joined', ''),
  1143. 'active' => array('active', ''),
  1144. 'count' => (request_var('count', '') !== '') ? array('count', 0) : array('count', ''),
  1145. 'ip' => array('ip', ''),
  1146. 'first_char' => array('first_char', ''),
  1147. );
  1148. foreach ($check_params as $key => $call)
  1149. {
  1150. if (!isset($_REQUEST[$key]))
  1151. {
  1152. continue;
  1153. }
  1154. $param = call_user_func_array('request_var', $call);
  1155. $param = urlencode($key) . '=' . ((is_string($param)) ? urlencode($param) : $param);
  1156. $params[] = $param;
  1157. if ($key != 'sk' && $key != 'sd')
  1158. {
  1159. $sort_params[] = $param;
  1160. }
  1161. }
  1162. $u_hide_find_member = append_sid("{$phpbb_root_path}memberlist.$phpEx", "start=$start" . (!empty($params) ? '&amp;' . implode('&amp;', $params) : ''));
  1163. if ($mode)
  1164. {
  1165. $params[] = "mode=$mode";
  1166. }
  1167. $sort_params[] = "mode=$mode";
  1168. $pagination_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $params));
  1169. $sort_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $sort_params));
  1170. // www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
  1171. if ($mode == 'group') {
  1172. $phpbb_seo->prepare_url('group', $group_row['group_name'], $group_row['group_id']);
  1173. $phpbb_seo->seo_opt['zero_dupe']['start'] = $phpbb_seo->seo_chk_start( $start, $config['topics_per_page'] );
  1174. $phpbb_seo->seo_chk_dupe("{$phpbb_root_path}memberlist.$phpEx?" . implode('&amp;', $params) . '&amp;start=' . $phpbb_seo->seo_opt['zero_dupe']['start']);
  1175. if (!empty($phpbb_seo->seo_opt['url_rewrite'])) {
  1176. $phpbb_seo->seo_path['canonical'] = $phpbb_seo->drop_sid(append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=group&amp;g={$group_row['group_id']}&amp;start=" . $phpbb_seo->seo_opt['zero_dupe']['start']));
  1177. }
  1178. }
  1179. // www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
  1180. unset($search_params, $sort_params);
  1181. // Some search user specific data
  1182. if ($mode == 'searchuser' && ($config['load_search'] || $auth->acl_get('a_')))
  1183. {
  1184. $group_selected = request_var('search_group_id', 0);
  1185. $s_group_select = '<option value="0"' . ((!$group_selected) ? ' selected="selected"' : '') . '>&nbsp;</option>';
  1186. $group_ids = array();
  1187. /**
  1188. * @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)
  1189. */
  1190. if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
  1191. {
  1192. $sql = 'SELECT group_id, group_name, group_type
  1193. FROM ' . GROUPS_TABLE;
  1194. if (!$config['coppa_enable'])
  1195. {
  1196. $sql .= " WHERE group_name <> 'REGISTERED_COPPA'";
  1197. }
  1198. $sql .= ' ORDER BY group_name ASC';
  1199. }
  1200. else
  1201. {
  1202. $sql = 'SELECT g.group_id, g.group_name, g.group_type
  1203. FROM ' . GROUPS_TABLE . ' g
  1204. LEFT JOIN ' . USER_GROUP_TABLE . ' ug
  1205. ON (
  1206. g.group_id = ug.group_id
  1207. AND ug.user_id = ' . $user->data['user_id'] . '
  1208. AND ug.user_pending = 0
  1209. )
  1210. WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
  1211. if (!$config['coppa_enable'])
  1212. {
  1213. $sql .= " AND g.group_name <> 'REGISTERED_COPPA'";
  1214. }
  1215. $sql .= ' ORDER BY g.group_name ASC';
  1216. }
  1217. $result = $db->sql_query($sql);
  1218. while ($row = $db->sql_fetchrow($result))
  1219. {
  1220. $group_ids[] = $row['group_id'];
  1221. $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>';
  1222. }
  1223. $db->sql_freeresult($result);
  1224. if ($group_selected !== 0 && !in_array($group_selected, $group_ids))
  1225. {
  1226. trigger_error('NO_GROUP');
  1227. }
  1228. $template->assign_vars(array(
  1229. 'USERNAME' => $username,
  1230. 'EMAIL' => $email,
  1231. 'ICQ' => $icq,
  1232. 'AIM' => $aim,
  1233. 'YAHOO' => $yahoo,
  1234. 'MSNM' => $msn,
  1235. 'JABBER' => $jabber,
  1236. 'JOINED' => implode('-', $joined),
  1237. 'ACTIVE' => implode('-', $active),
  1238. 'COUNT' => $count,
  1239. 'IP' => $ipdomain,
  1240. 'S_IP_SEARCH_ALLOWED' => ($auth->acl_getf_global('m_info')) ? true : false,
  1241. 'S_EMAIL_SEARCH_ALLOWED'=> ($auth->acl_get('a_user')) ? true : false,
  1242. 'S_IN_SEARCH_POPUP' => ($form && $field) ? true : false,
  1243. 'S_SEARCH_USER' => true,
  1244. 'S_FORM_NAME' => $form,
  1245. 'S_FIELD_NAME' => $field,
  1246. 'S_SELECT_SINGLE' => $select_single,
  1247. 'S_COUNT_OPTIONS' => $s_find_count,
  1248. 'S_SORT_OPTIONS' => $s_sort_key,
  1249. 'S_JOINED_TIME_OPTIONS' => $s_find_join_time,
  1250. 'S_ACTIVE_TIME_OPTIONS' => $s_find_active_time,
  1251. 'S_GROUP_SELECT' => $s_group_select,
  1252. 'S_USER_SEARCH_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&amp;form=$form&amp;field=$field"))
  1253. );
  1254. }
  1255. // Get us some users :D
  1256. $sql = "SELECT u.user_id
  1257. FROM " . USERS_TABLE . " u
  1258. $sql_from
  1259. WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
  1260. $sql_where
  1261. ORDER BY $order_by";
  1262. $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
  1263. $user_list = array();
  1264. while ($row = $db->sql_fetchrow($result))
  1265. {
  1266. $user_list[] = (int) $row['user_id'];
  1267. }
  1268. $db->sql_freeresult($result);
  1269. $leaders_set = false;
  1270. // So, did we get any users?
  1271. if (sizeof($user_list))
  1272. {
  1273. // Session time?! Session time...
  1274. $sql = 'SELECT session_user_id, MAX(session_time) AS session_time
  1275. FROM ' . SESSIONS_TABLE . '
  1276. WHERE session_time >= ' . (time() - $config['session_length']) . '
  1277. AND ' . $db->sql_in_set('session_user_id', $user_list) . '
  1278. GROUP BY session_user_id';
  1279. $result = $db->sql_query($sql);
  1280. $session_times = array();
  1281. while ($row = $db->sql_fetchrow($result))
  1282. {
  1283. $session_times[$row['session_user_id']] = $row['session_time'];
  1284. }
  1285. $db->sql_freeresult($result);
  1286. // Do the SQL thang
  1287. if ($mode == 'group')
  1288. {
  1289. $sql = "SELECT u.*
  1290. $sql_select
  1291. FROM " . USERS_TABLE . " u
  1292. $sql_from
  1293. WHERE " . $db->sql_in_set('u.user_id', $user_list) . "
  1294. $sql_where_data";
  1295. }
  1296. else
  1297. {
  1298. $sql = 'SELECT *
  1299. FROM ' . USERS_TABLE . '
  1300. WHERE ' . $db->sql_in_set('user_id', $user_list);
  1301. }
  1302. $result = $db->sql_query($sql);
  1303. $id_cache = array();
  1304. while ($row = $db->sql_fetchrow($result))
  1305. {
  1306. $row['session_time'] = (!empty($session_times[$row['user_id']])) ? $session_times[$row['user_id']] : 0;
  1307. $row['last_visit'] = (!empty($row['session_time'])) ? $row['session_time'] : $row['user_lastvisit'];
  1308. $id_cache[$row['user_id']] = $row;
  1309. }
  1310. $db->sql_freeresult($result);
  1311. // Load custom profile fields
  1312. if ($config['load_cpf_memberlist'])
  1313. {
  1314. include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
  1315. $cp = new custom_profile();
  1316. // Grab all profile fields from users in id cache for later use - similar to the poster cache
  1317. $profile_fields_cache = $cp->generate_profile_fields_template('grab', $user_list);
  1318. }
  1319. // If we sort by last active date we need to adjust the id cache due to user_lastvisit not being the last active date...
  1320. if ($sort_key == 'l')
  1321. {
  1322. // 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));"));
  1323. usort($user_list, '_sort_last_active');
  1324. }
  1325. for ($i = 0, $end = sizeof($user_list); $i < $end; ++$i)
  1326. {
  1327. $user_id = $user_list[$i];
  1328. $row =& $id_cache[$user_id];
  1329. $is_leader = (isset($row['group_leader']) && $row['group_leader']) ? true : false;
  1330. $leaders_set = ($leaders_set || $is_leader);
  1331. $cp_row = array();
  1332. if ($config['load_cpf_memberlist'])
  1333. {
  1334. $cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$user_id]) : array();
  1335. }
  1336. $memberrow = array_merge(show_profile($row), array(
  1337. 'ROW_NUMBER' => $i + ($start + 1),
  1338. 'S_CUSTOM_PROFILE' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
  1339. 'S_GROUP_LEADER' => $is_leader,
  1340. 'U_VIEW_PROFILE' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_id))
  1341. );
  1342. if (isset($cp_row['row']) && sizeof($cp_row['row']))
  1343. {
  1344. $memberrow = array_merge($memberrow, $cp_row['row']);
  1345. }
  1346. $template->assign_block_vars('memberrow', $memberrow);
  1347. if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow']))
  1348. {
  1349. foreach ($cp_row['blockrow'] as $field_data)
  1350. {
  1351. $template->assign_block_vars('memberrow.custom_fields', $field_data);
  1352. }
  1353. }
  1354. unset($id_cache[$user_id]);
  1355. }
  1356. }
  1357. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1358. $seo_sep = strpos($sort_url, '?') === false ? '?' : '&amp;';
  1359. // www.phpBB-SEO.com SEO TOOLKIT END
  1360. // Generate page
  1361. $template->assign_vars(array(
  1362. 'PAGINATION' => generate_pagination($pagination_url, $total_users, $config['topics_per_page'], $start),
  1363. 'PAGE_NUMBER' => on_page($total_users, $config['topics_per_page'], $start),
  1364. 'TOTAL_USERS' => ($total_users == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $total_users),
  1365. 'PROFILE_IMG' => $user->img('icon_user_profile', $user->lang['PROFILE']),
  1366. 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
  1367. 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']),
  1368. 'WWW_IMG' => $user->img('icon_contact_www', $user->lang['WWW']),
  1369. 'ICQ_IMG' => $user->img('icon_contact_icq', $user->lang['ICQ']),
  1370. 'AIM_IMG' => $user->img('icon_contact_aim', $user->lang['AIM']),
  1371. 'MSN_IMG' => $user->img('icon_contact_msnm', $user->lang['MSNM']),
  1372. 'YIM_IMG' => $user->img('icon_contact_yahoo', $user->lang['YIM']),
  1373. 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']),
  1374. 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
  1375. '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) : '')) : '',
  1376. 'U_HIDE_FIND_MEMBER' => ($mode == 'searchuser') ? $u_hide_find_member : '',
  1377. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1378. 'U_SORT_USERNAME' => $sort_url . $seo_sep . 'sk=a&amp;sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
  1379. 'U_SORT_FROM' => $sort_url . $seo_sep . 'sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
  1380. 'U_SORT_JOINED' => $sort_url . $seo_sep . 'sk=c&amp;sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
  1381. 'U_SORT_POSTS' => $sort_url . $seo_sep . 'sk=d&amp;sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
  1382. 'U_SORT_EMAIL' => $sort_url . $seo_sep . 'sk=e&amp;sd=' . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
  1383. 'U_SORT_WEBSITE' => $sort_url . $seo_sep . 'sk=f&amp;sd=' . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
  1384. 'U_SORT_LOCATION' => $sort_url . $seo_sep . 'sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
  1385. 'U_SORT_ICQ' => $sort_url . $seo_sep . 'sk=g&amp;sd=' . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
  1386. 'U_SORT_AIM' => $sort_url . $seo_sep . 'sk=h&amp;sd=' . (($sort_key == 'h' && $sort_dir == 'a') ? 'd' : 'a'),
  1387. 'U_SORT_MSN' => $sort_url . $seo_sep . 'sk=i&amp;sd=' . (($sort_key == 'i' && $sort_dir == 'a') ? 'd' : 'a'),
  1388. 'U_SORT_YIM' => $sort_url . $seo_sep . 'sk=j&amp;sd=' . (($sort_key == 'j' && $sort_dir == 'a') ? 'd' : 'a'),
  1389. 'U_SORT_ACTIVE' => ($auth->acl_get('u_viewonline')) ? $sort_url . $seo_sep . 'sk=l&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a') : '',
  1390. 'U_SORT_RANK' => $sort_url . $seo_sep . 'sk=m&amp;sd=' . (($sort_key == 'm' && $sort_dir == 'a') ? 'd' : 'a'),
  1391. 'U_LIST_CHAR' => $sort_url . $seo_sep . 'sk=a&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a'),
  1392. // www.phpBB-SEO.com SEO TOOLKIT END
  1393. 'S_SHOW_GROUP' => ($mode == 'group') ? true : false,
  1394. 'S_VIEWONLINE' => $auth->acl_get('u_viewonline'),
  1395. 'S_LEADERS_SET' => $leaders_set,
  1396. 'S_MODE_SELECT' => $s_sort_key,
  1397. 'S_ORDER_SELECT' => $s_sort_dir,
  1398. 'S_CHAR_OPTIONS' => $s_char_options,
  1399. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1400. // Here we circumvent because our append_sid does not allow
  1401. // an url to end with an ?, as it should.
  1402. 'S_MODE_ACTION' => $pagination_url . (strpos($pagination_url, '?') !== false ? '' : '?') )
  1403. // www.phpBB-SEO.com SEO TOOLKIT END
  1404. );
  1405. }
  1406. // Output the page
  1407. page_header($page_title, false);
  1408. $template->set_filenames(array(
  1409. 'body' => $template_html)
  1410. );
  1411. make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
  1412. page_footer();
  1413. /**
  1414. * Prepare profile data
  1415. */
  1416. function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false)
  1417. {
  1418. global $config, $auth, $template, $user, $phpEx, $phpbb_root_path;
  1419. $username = $data['username'];
  1420. $user_id = $data['user_id'];
  1421. $rank_title = $rank_img = $rank_img_src = '';
  1422. get_user_rank($data['user_rank'], (($user_id == ANONYMOUS) ? false : $data['user_posts']), $rank_title, $rank_img, $rank_img_src);
  1423. if ((!empty($data['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_user'))
  1424. {
  1425. $email = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;u=' . $user_id) : (($config['board_hide_emails'] && !$auth->acl_get('a_user')) ? '' : 'mailto:' . $data['user_email']);
  1426. }
  1427. else
  1428. {
  1429. $email = '';
  1430. }
  1431. if ($config['load_onlinetrack'])
  1432. {
  1433. $update_time = $config['load_online_time'] * 60;
  1434. $online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['session_viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
  1435. }
  1436. else
  1437. {
  1438. $online = false;
  1439. }
  1440. if ($data['user_allow_viewonline'] || $auth->acl_get('u_viewonline'))
  1441. {
  1442. $last_visit = (!empty($data['session_time'])) ? $data['session_time'] : $data['user_lastvisit'];
  1443. }
  1444. else
  1445. {
  1446. $last_visit = '';
  1447. }
  1448. $age = '';
  1449. if ($config['allow_birthdays'] && $data['user_birthday'])
  1450. {
  1451. list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday']));
  1452. if ($bday_year)
  1453. {
  1454. $now = getdate(time() + $user->timezone + $user->dst - date('Z'));
  1455. $diff = $now['mon'] - $bday_month;
  1456. if ($diff == 0)
  1457. {
  1458. $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
  1459. }
  1460. else
  1461. {
  1462. $diff = ($diff < 0) ? 1 : 0;
  1463. }
  1464. $age = (int) ($now['year'] - $bday_year - $diff);
  1465. //-- mod: Prime Birthdate ---------------------------------------------------//
  1466. include($phpbb_root_path . 'includes/prime_birthdate.' . $phpEx);
  1467. $prime_birthdate->memberlist_show_age($data, $age);
  1468. //-- end: Prime Birthdate ---------------------------------------------------//
  1469. }
  1470. }
  1471. // Dump it out to the template
  1472. return array(
  1473. 'AGE' => $age,
  1474. 'RANK_TITLE' => $rank_title,
  1475. 'JOINED' => $user->format_date($data['user_regdate']),
  1476. 'VISITED' => (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
  1477. 'POSTS' => ($data['user_posts']) ? $data['user_posts'] : 0,
  1478. 'WARNINGS' => isset($data['user_warnings']) ? $data['user_warnings'] : 0,
  1479. 'USERNAME_FULL' => get_username_string('full', $user_id, $username, $data['user_colour']),
  1480. 'USERNAME' => get_username_string('username', $user_id, $username, $data['user_colour']),
  1481. 'USER_COLOR' => get_username_string('colour', $user_id, $username, $data['user_colour']),
  1482. 'U_VIEW_PROFILE' => get_username_string('profile', $user_id, $username, $data['user_colour']),
  1483. 'A_USERNAME' => addslashes(get_username_string('username', $user_id, $username, $data['user_colour'])),
  1484. 'AVATAR_IMG' => get_user_avatar($data['user_avatar'], $data['user_avatar_type'], $data['user_avatar_width'], $data['user_avatar_height']),
  1485. 'ONLINE_IMG' => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')),
  1486. 'S_ONLINE' => ($config['load_onlinetrack'] && $online) ? true : false,
  1487. 'RANK_IMG' => $rank_img,
  1488. 'RANK_IMG_SRC' => $rank_img_src,
  1489. 'ICQ_STATUS_IMG' => (!empty($data['user_icq'])) ? '<img src="http://web.icq.com/whitepages/online?icq=' . $data['user_icq'] . '&amp;img=5" width="18" height="18" />' : '',
  1490. 'S_JABBER_ENABLED' => ($config['jab_enable']) ? true : false,
  1491. 'S_WARNINGS' => ($auth->acl_getf_global('m_') || $auth->acl_get('m_warn')) ? true : false,
  1492. 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$user_id&amp;sr=posts") : '',
  1493. 'U_NOTES' => ($user_notes_enabled && $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $user_id, true, $user->session_id) : '',
  1494. 'U_WARN' => ($warn_user_enabled && $auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $user_id, true, $user->session_id) : '',
  1495. 'U_PM' => ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($data['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=' . $user_id) : '',
  1496. 'U_EMAIL' => $email,
  1497. 'U_WWW' => (!empty($data['user_website'])) ? $data['user_website'] : '',
  1498. 'U_SHORT_WWW' => (!empty($data['user_website'])) ? ((strlen($data['user_website']) > 55) ? substr($data['user_website'], 0, 39) . ' ... ' . substr($data['user_website'], -10) : $data['user_website']) : '',
  1499. 'U_ICQ' => ($data['user_icq']) ? 'http://www.icq.com/people/' . urlencode($data['user_icq']) . '/' : '',
  1500. 'U_AIM' => ($data['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=aim&amp;u=' . $user_id) : '',
  1501. 'U_YIM' => ($data['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($data['user_yim']) . '&amp;.src=pg' : '',
  1502. 'U_MSN' => ($data['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=msnm&amp;u=' . $user_id) : '',
  1503. 'U_JABBER' => ($data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=jabber&amp;u=' . $user_id) : '',
  1504. 'LOCATION' => ($data['user_from']) ? $data['user_from'] : '',
  1505. 'USER_ICQ' => $data['user_icq'],
  1506. 'USER_AIM' => $data['user_aim'],
  1507. 'USER_YIM' => $data['user_yim'],
  1508. 'USER_MSN' => $data['user_msnm'],
  1509. 'USER_JABBER' => $data['user_jabber'],
  1510. 'USER_JABBER_IMG' => ($data['user_jabber']) ? $user->img('icon_contact_jabber', $data['user_jabber']) : '',
  1511. 'L_VIEWING_PROFILE' => sprintf($user->lang['VIEWING_PROFILE'], $username),
  1512. );
  1513. }
  1514. function _sort_last_active($first, $second)
  1515. {
  1516. global $id_cache, $sort_dir;
  1517. $lesser_than = ($sort_dir === 'd') ? -1 : 1;
  1518. if (isset($id_cache[$first]['group_leader']) && $id_cache[$first]['group_leader'] && (!isset($id_cache[$second]['group_leader']) || !$id_cache[$second]['group_leader']))
  1519. {
  1520. return -1;
  1521. }
  1522. else if (isset($id_cache[$second]['group_leader']) && (!isset($id_cache[$first]['group_leader']) || !$id_cache[$first]['group_leader']) && $id_cache[$second]['group_leader'])
  1523. {
  1524. return 1;
  1525. }
  1526. else
  1527. {
  1528. return $lesser_than * (int) ($id_cache[$first]['last_visit'] - $id_cache[$second]['last_visit']);
  1529. }
  1530. }
  1531. ?>