[ Index ]

PHP Cross Reference of MyBB 1.8.17

title

Body

[close]

/ -> memberlist.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  define("IN_MYBB", 1);
  12  define('THIS_SCRIPT', 'memberlist.php');
  13  
  14  $templatelist = "memberlist,memberlist_search,memberlist_user,memberlist_user_groupimage,memberlist_user_avatar,memberlist_user_userstar,memberlist_search_contact_field,memberlist_referrals,memberlist_referrals_bit";
  15  $templatelist .= ",multipage,multipage_end,multipage_jump_page,multipage_nextpage,multipage_page,multipage_page_current,multipage_page_link_current,multipage_prevpage,multipage_start,memberlist_error,memberlist_orderarrow";
  16  
  17  require_once  "./global.php";
  18  
  19  // Load global language phrases
  20  $lang->load("memberlist");
  21  
  22  if($mybb->settings['enablememberlist'] == 0)
  23  {
  24      error($lang->memberlist_disabled);
  25  }
  26  
  27  $plugins->run_hooks("memberlist_start");
  28  
  29  add_breadcrumb($lang->nav_memberlist, "memberlist.php");
  30  
  31  if($mybb->usergroup['canviewmemberlist'] == 0)
  32  {
  33      error_no_permission();
  34  }
  35  
  36  // Showing advanced search page?
  37  if($mybb->get_input('action') == "search")
  38  {
  39      $plugins->run_hooks("memberlist_search");
  40      add_breadcrumb($lang->nav_memberlist_search);
  41  
  42      $contact_fields = array();
  43      foreach(array('skype', 'google', 'yahoo', 'icq') as $field)
  44      {
  45          $contact_fields[$field] = '';
  46          $settingkey = 'allow'.$field.'field';
  47  
  48          if($mybb->settings[$settingkey] != '' && is_member($mybb->settings[$settingkey], array('usergroup' => $mybb->usergroup['usergroup'], 'additionalgroups' => $mybb->usergroup['additionalgroups'])))
  49          {
  50              $tmpl = 'memberlist_search_'.$field;
  51  
  52              $lang_string = 'search_'.$field;
  53              $lang_string = $lang->{$lang_string};
  54  
  55              $bgcolors[$field] = alt_trow();
  56              eval('$contact_fields[\''.$field.'\'] = "'.$templates->get('memberlist_search_contact_field').'";');
  57          }
  58      }
  59  
  60      if($mybb->settings['usereferrals'] == 1)
  61      {
  62          eval("\$referrals_option = \"".$templates->get("memberlist_referrals_option")."\";");
  63      }
  64  
  65      eval("\$search_page = \"".$templates->get("memberlist_search")."\";");
  66      output_page($search_page);
  67  }
  68  else
  69  {
  70      $colspan = 6;
  71      $search_url = '';
  72  
  73      // Incoming sort field?
  74      if(isset($mybb->input['sort']))
  75      {
  76          $mybb->input['sort'] = strtolower($mybb->get_input('sort'));
  77      }
  78      else
  79      {
  80          $mybb->input['sort'] = $mybb->settings['default_memberlist_sortby'];
  81      }
  82  
  83      $sort_selected = array(
  84          'regdate' => '',
  85          'lastvisit' => '',
  86          'reputation' => '',
  87          'postnum' => '',
  88          'referrals' => '',
  89          'username' => ''
  90      );
  91  
  92      switch($mybb->input['sort'])
  93      {
  94          case "regdate":
  95              $sort_field = "u.regdate";
  96              break;
  97          case "lastvisit":
  98              $sort_field = "u.lastactive";
  99              break;
 100          case "reputation":
 101              $sort_field = "u.reputation";
 102              break;
 103          case "postnum":
 104              $sort_field = "u.postnum";
 105              break;
 106          case "threadnum":
 107              $sort_field = "u.threadnum";
 108              break;
 109          case "referrals":
 110              if($mybb->settings['usereferrals'] == 1)
 111              {
 112                  $sort_field = "u.referrals";
 113              }
 114              else
 115              {
 116                  $sort_field = "u.username";
 117              }
 118              break;
 119          default:
 120              $sort_field = "u.username";
 121              $mybb->input['sort'] = 'username';
 122              break;
 123      }
 124      $sort_selected[$mybb->input['sort']] = " selected=\"selected\"";
 125  
 126      // Incoming sort order?
 127      if(isset($mybb->input['order']))
 128      {
 129          $mybb->input['order'] = strtolower($mybb->input['order']);
 130      }
 131      else
 132      {
 133          $mybb->input['order'] = strtolower($mybb->settings['default_memberlist_order']);
 134      }
 135  
 136      $order_check = array('ascending' => '', 'descending' => '');
 137      if($mybb->input['order'] == "ascending" || (!$mybb->input['order'] && $mybb->input['sort'] == 'username'))
 138      {
 139          $sort_order = "ASC";
 140          $sortordernow = "ascending";
 141          $oppsort = $lang->desc;
 142          $oppsortnext = "descending";
 143          $mybb->input['order'] = "ascending";
 144      }
 145      else
 146      {
 147          $sort_order = "DESC";
 148          $sortordernow = "descending";
 149          $oppsort = $lang->asc;
 150          $oppsortnext = "ascending";
 151          $mybb->input['order'] = "descending";
 152      }
 153      $order_check[$mybb->input['order']] = " checked=\"checked\"";
 154  
 155      // Incoming results per page?
 156      $mybb->input['perpage'] = $mybb->get_input('perpage', MyBB::INPUT_INT);
 157      if($mybb->input['perpage'] > 0 && $mybb->input['perpage'] <= 500)
 158      {
 159          $per_page = $mybb->input['perpage'];
 160      }
 161      else if($mybb->settings['membersperpage'])
 162      {
 163          $per_page = $mybb->input['perpage'] = (int)$mybb->settings['membersperpage'];
 164      }
 165      else
 166      {
 167          $per_page = $mybb->input['perpage'] = 20;
 168      }
 169  
 170      $search_query = '1=1';
 171      $search_url = "";
 172  
 173      switch($db->type)
 174      {
 175          // PostgreSQL's LIKE is case sensitive
 176          case "pgsql":
 177              $like = "ILIKE";
 178              break;
 179          default:
 180              $like = "LIKE";
 181      }
 182  
 183      // Limiting results to a certain letter
 184      if(isset($mybb->input['letter']))
 185      {
 186          $letter = chr(ord($mybb->get_input('letter')));
 187          if($mybb->input['letter'] == -1)
 188          {
 189              $search_query .= " AND u.username NOT REGEXP('[a-zA-Z]')";
 190          }
 191          else if(strlen($letter) == 1)
 192          {
 193              $search_query .= " AND u.username {$like} '".$db->escape_string_like($letter)."%'";
 194          }
 195          $search_url .= "&letter={$letter}";
 196      }
 197  
 198      // Searching for a matching username
 199      $search_username = htmlspecialchars_uni(trim($mybb->get_input('username')));
 200      if($search_username != '')
 201      {
 202          $username_like_query = $db->escape_string_like($search_username);
 203  
 204          // Name begins with
 205          if($mybb->input['username_match'] == "begins")
 206          {
 207              $search_query .= " AND u.username {$like} '".$username_like_query."%'";
 208              $search_url .= "&username_match=begins";
 209          }
 210          // Just contains
 211          else
 212          {
 213              $search_query .= " AND u.username {$like} '%".$username_like_query."%'";
 214          }
 215  
 216          $search_url .= "&username=".urlencode($search_username);
 217      }
 218  
 219      // Website contains
 220      $mybb->input['website'] = trim($mybb->get_input('website'));
 221      $search_website = htmlspecialchars_uni($mybb->input['website']);
 222      if(trim($mybb->input['website']))
 223      {
 224          $search_query .= " AND u.website {$like} '%".$db->escape_string_like($mybb->input['website'])."%'";
 225          $search_url .= "&website=".urlencode($mybb->input['website']);
 226      }
 227  
 228      // Search by contact field input
 229      foreach(array('icq', 'google', 'skype', 'yahoo') as $cfield)
 230      {
 231          $csetting = 'allow'.$cfield.'field';
 232          $mybb->input[$cfield] = trim($mybb->get_input($cfield));
 233          if($mybb->input[$cfield] && $mybb->settings[$csetting] != '')
 234          {
 235              if($mybb->settings[$csetting] != -1)
 236              {
 237                  $gids = explode(',', (string)$mybb->settings[$csetting]);
 238  
 239                  $search_query .= " AND (";
 240                  $or = '';
 241                  foreach($gids as $gid)
 242                  {
 243                      $gid = (int)$gid;
 244                      $search_query .= $or.'u.usergroup=\''.$gid.'\'';
 245                      switch($db->type)
 246                      {
 247                          case 'pgsql':
 248                          case 'sqlite':
 249                              $search_query .= " OR ','||u.additionalgroups||',' LIKE '%,{$gid},%'";
 250                              break;
 251                          default:
 252                              $search_query .= " OR CONCAT(',',u.additionalgroups,',') LIKE '%,{$gid},%'";
 253                              break;
 254                      }
 255                      $or = ' OR ';
 256                  }
 257                  $search_query .= ")";
 258              }
 259              if($cfield == 'icq')
 260              {
 261                  $search_query .= " AND u.{$cfield} LIKE '%".(int)$mybb->input[$cfield]."%'";
 262              }
 263              else
 264              {
 265                  $search_query .= " AND u.{$cfield} {$like} '%".$db->escape_string_like($mybb->input[$cfield])."%'";
 266              }
 267              $search_url .= "&{$cfield}=".urlencode($mybb->input[$cfield]);
 268          }
 269      }
 270  
 271      $usergroups_cache = $cache->read('usergroups');
 272  
 273      $group = array();
 274      foreach($usergroups_cache as $gid => $groupcache)
 275      {
 276          if($groupcache['showmemberlist'] == 0)
 277          {
 278              $group[] = (int)$gid;
 279          }
 280      }
 281  
 282      if(is_array($group) && !empty($group))
 283      {
 284          $hiddengroup = implode(',', $group);
 285  
 286          $search_query .= " AND u.usergroup NOT IN ({$hiddengroup})";
 287  
 288          foreach($group as $hidegid)
 289          {
 290              switch($db->type)
 291              {
 292                  case "pgsql":
 293                  case "sqlite":
 294                      $search_query .= " AND ','||u.additionalgroups||',' NOT LIKE '%,{$hidegid},%'";
 295                      break;
 296                  default:
 297                      $search_query .= " AND CONCAT(',',u.additionalgroups,',') NOT LIKE '%,{$hidegid},%'";
 298                      break;
 299              }
 300          }
 301      }
 302    
 303      $sorturl = htmlspecialchars_uni("memberlist.php?perpage={$mybb->input['perpage']}{$search_url}");
 304      $search_url = htmlspecialchars_uni("memberlist.php?sort={$mybb->input['sort']}&order={$mybb->input['order']}&perpage={$mybb->input['perpage']}{$search_url}");
 305  
 306      $plugins->run_hooks('memberlist_intermediate');
 307  
 308      $query = $db->simple_select("users u", "COUNT(*) AS users", "{$search_query}");
 309      $num_users = $db->fetch_field($query, "users");
 310  
 311      $page = $mybb->get_input('page', MyBB::INPUT_INT);
 312      if($page && $page > 0)
 313      {
 314          $start = ($page - 1) * $per_page;
 315      }
 316      else
 317      {
 318          $start = 0;
 319          $page = 1;
 320      }
 321  
 322      $sort = htmlspecialchars_uni($mybb->input['sort']);
 323      eval("\$orderarrow['{$sort}'] = \"".$templates->get("memberlist_orderarrow")."\";");
 324  
 325      // Referral?
 326      if($mybb->settings['usereferrals'] == 1)
 327      {
 328          $colspan = 7;
 329          eval("\$referral_header = \"".$templates->get("memberlist_referrals")."\";");
 330      }
 331  
 332      $multipage = multipage($num_users, $per_page, $page, $search_url);
 333  
 334      // Cache a few things
 335      $usertitles = $cache->read('usertitles');
 336      $usertitles_cache = array();
 337      foreach($usertitles as $usertitle)
 338      {
 339          $usertitles_cache[$usertitle['posts']] = $usertitle;
 340      }
 341      $users = '';
 342      $query = $db->query("
 343          SELECT u.*, f.*
 344          FROM ".TABLE_PREFIX."users u
 345          LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
 346          WHERE {$search_query}
 347          ORDER BY {$sort_field} {$sort_order}
 348          LIMIT {$start}, {$per_page}
 349      ");
 350      while($user = $db->fetch_array($query))
 351      {
 352          $user = $plugins->run_hooks("memberlist_user", $user);
 353  
 354          $alt_bg = alt_trow();
 355  
 356          $user['username'] = format_name(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']);
 357  
 358          $user['profilelink'] = build_profile_link($user['username'], $user['uid']);
 359  
 360          // Get the display usergroup
 361          if($user['usergroup'])
 362          {
 363              $usergroup = usergroup_permissions($user['usergroup']);
 364          }
 365          else
 366          {
 367              $usergroup = usergroup_permissions(1);
 368          }
 369  
 370          $displaygroupfields = array("title", "description", "namestyle", "usertitle", "stars", "starimage", "image");
 371  
 372          if(!$user['displaygroup'])
 373          {
 374              $user['displaygroup'] = $user['usergroup'];
 375          }
 376  
 377          $display_group = usergroup_displaygroup($user['displaygroup']);
 378          if(is_array($display_group))
 379          {
 380              $usergroup = array_merge($usergroup, $display_group);
 381          }
 382  
 383          // Build referral?
 384          if($mybb->settings['usereferrals'] == 1)
 385          {
 386              eval("\$referral_bit = \"".$templates->get("memberlist_referrals_bit")."\";");
 387              eval("\$referrals_option = \"".$templates->get("memberlist_referrals_option")."\";");
 388          }
 389  
 390          $usergroup['groupimage'] = '';
 391          // Work out the usergroup/title stuff
 392          if(!empty($usergroup['image']))
 393          {
 394              if(!empty($mybb->user['language']))
 395              {
 396                  $language = $mybb->user['language'];
 397              }
 398              else
 399              {
 400                  $language = $mybb->settings['bblanguage'];
 401              }
 402              $usergroup['image'] = str_replace("{lang}", $language, $usergroup['image']);
 403              $usergroup['image'] = str_replace("{theme}", $theme['imgdir'], $usergroup['image']);
 404              eval("\$usergroup['groupimage'] = \"".$templates->get("memberlist_user_groupimage")."\";");
 405          }
 406  
 407          $has_custom_title = 0;
 408          if(trim($user['usertitle']) != "")
 409          {
 410              $has_custom_title = 1;
 411          }
 412  
 413          if($usergroup['usertitle'] != "" && !$has_custom_title)
 414          {
 415              $user['usertitle'] = $usergroup['usertitle'];
 416          }
 417          elseif(is_array($usertitles_cache) && !$usergroup['usertitle'])
 418          {
 419              foreach($usertitles_cache as $posts => $titleinfo)
 420              {
 421                  if($user['postnum'] >= $posts)
 422                  {
 423                      if(!$has_custom_title)
 424                      {
 425                          $user['usertitle'] = $titleinfo['title'];
 426                      }
 427                      $user['stars'] = $titleinfo['stars'];
 428                      $user['starimage'] = $titleinfo['starimage'];
 429                      break;
 430                  }
 431              }
 432          }
 433          
 434          $user['usertitle'] = htmlspecialchars_uni($user['usertitle']);
 435  
 436          if(!empty($usergroup['stars']))
 437          {
 438              $user['stars'] = $usergroup['stars'];
 439          }
 440  
 441          if(empty($user['starimage']))
 442          {
 443              $user['starimage'] = $usergroup['starimage'];
 444          }
 445  
 446          $user['userstars'] = '';
 447          if(!empty($user['starimage']))
 448          {
 449              // Only display stars if we have an image to use...
 450              $starimage = str_replace("{theme}", $theme['imgdir'], $user['starimage']);
 451  
 452              for($i = 0; $i < $user['stars']; ++$i)
 453              {
 454                  eval("\$user['userstars'] .= \"".$templates->get("memberlist_user_userstar", 1, 0)."\";");
 455              }
 456          }
 457  
 458          if($user['userstars'] && $usergroup['groupimage'])
 459          {
 460              $user['userstars'] = "<br />".$user['userstars'];
 461          }
 462  
 463          // Show avatar
 464          $useravatar = format_avatar($user['avatar'], $user['avatardimensions'], my_strtolower($mybb->settings['memberlistmaxavatarsize']));
 465          eval("\$user['avatar'] = \"".$templates->get("memberlist_user_avatar")."\";");
 466  
 467          if($user['invisible'] == 1 && $mybb->usergroup['canviewwolinvis'] != 1 && $user['uid'] != $mybb->user['uid'])
 468          {
 469              $user['lastvisit'] = $lang->lastvisit_never;
 470  
 471              if($user['lastvisit'])
 472              {
 473                  // We have had at least some active time, hide it instead
 474                  $user['lastvisit'] = $lang->lastvisit_hidden;
 475              }
 476          }
 477          else
 478          {
 479              $user['lastvisit'] = my_date('relative', $user['lastactive']);
 480          }
 481  
 482          $user['regdate'] = my_date('relative', $user['regdate']);
 483          $user['postnum'] = my_number_format($user['postnum']);
 484          $user['threadnum'] = my_number_format($user['threadnum']);
 485          eval("\$users .= \"".$templates->get("memberlist_user")."\";");
 486      }
 487  
 488      // Do we have no results?
 489      if(!$users)
 490      {
 491          eval("\$users = \"".$templates->get("memberlist_error")."\";");
 492      }
 493  
 494      $plugins->run_hooks("memberlist_end");
 495  
 496      eval("\$memberlist = \"".$templates->get("memberlist")."\";");
 497      output_page($memberlist);
 498  }


2005 - 2018 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref 0.7.1