[ Index ]

PHP Cross Reference of phpBB-3.2.2-deutsch

title

Body

[close]

/ -> memberlist.php (source)

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


Generated: Thu Jan 11 23:14:31 2018 Cross-referenced by PHPXref 0.7.1