[ Index ]

PHP Cross Reference of MyBB 1.8.20

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 if($mybb->input['username_match'] == "contains")
 212          {
 213              $search_query .= " AND u.username {$like} '%".$username_like_query."%'";
 214              $search_url .= "&username_match=contains";
 215          }
 216          // Exact
 217          else
 218          {
 219              $search_query .= " AND u.username='{$username_like_query}'";
 220          }
 221  
 222          $search_url .= "&username=".urlencode($search_username);
 223      }
 224  
 225      // Website contains
 226      $mybb->input['website'] = trim($mybb->get_input('website'));
 227      $search_website = htmlspecialchars_uni($mybb->input['website']);
 228      if(trim($mybb->input['website']))
 229      {
 230          $search_query .= " AND u.website {$like} '%".$db->escape_string_like($mybb->input['website'])."%'";
 231          $search_url .= "&website=".urlencode($mybb->input['website']);
 232      }
 233  
 234      // Search by contact field input
 235      foreach(array('icq', 'google', 'skype', 'yahoo') as $cfield)
 236      {
 237          $csetting = 'allow'.$cfield.'field';
 238          $mybb->input[$cfield] = trim($mybb->get_input($cfield));
 239          if($mybb->input[$cfield] && $mybb->settings[$csetting] != '')
 240          {
 241              if($mybb->settings[$csetting] != -1)
 242              {
 243                  $gids = explode(',', (string)$mybb->settings[$csetting]);
 244  
 245                  $search_query .= " AND (";
 246                  $or = '';
 247                  foreach($gids as $gid)
 248                  {
 249                      $gid = (int)$gid;
 250                      $search_query .= $or.'u.usergroup=\''.$gid.'\'';
 251                      switch($db->type)
 252                      {
 253                          case 'pgsql':
 254                          case 'sqlite':
 255                              $search_query .= " OR ','||u.additionalgroups||',' LIKE '%,{$gid},%'";
 256                              break;
 257                          default:
 258                              $search_query .= " OR CONCAT(',',u.additionalgroups,',') LIKE '%,{$gid},%'";
 259                              break;
 260                      }
 261                      $or = ' OR ';
 262                  }
 263                  $search_query .= ")";
 264              }
 265              if($cfield == 'icq')
 266              {
 267                  $search_query .= " AND u.{$cfield} LIKE '%".(int)$mybb->input[$cfield]."%'";
 268              }
 269              else
 270              {
 271                  $search_query .= " AND u.{$cfield} {$like} '%".$db->escape_string_like($mybb->input[$cfield])."%'";
 272              }
 273              $search_url .= "&{$cfield}=".urlencode($mybb->input[$cfield]);
 274          }
 275      }
 276  
 277      $usergroups_cache = $cache->read('usergroups');
 278  
 279      $group = array();
 280      foreach($usergroups_cache as $gid => $groupcache)
 281      {
 282          if($groupcache['showmemberlist'] == 0)
 283          {
 284              $group[] = (int)$gid;
 285          }
 286      }
 287  
 288      if(is_array($group) && !empty($group))
 289      {
 290          $hiddengroup = implode(',', $group);
 291  
 292          $search_query .= " AND u.usergroup NOT IN ({$hiddengroup})";
 293  
 294          foreach($group as $hidegid)
 295          {
 296              switch($db->type)
 297              {
 298                  case "pgsql":
 299                  case "sqlite":
 300                      $search_query .= " AND ','||u.additionalgroups||',' NOT LIKE '%,{$hidegid},%'";
 301                      break;
 302                  default:
 303                      $search_query .= " AND CONCAT(',',u.additionalgroups,',') NOT LIKE '%,{$hidegid},%'";
 304                      break;
 305              }
 306          }
 307      }
 308    
 309      $sorturl = htmlspecialchars_uni("memberlist.php?perpage={$mybb->input['perpage']}{$search_url}");
 310      $search_url = htmlspecialchars_uni("memberlist.php?sort={$mybb->input['sort']}&order={$mybb->input['order']}&perpage={$mybb->input['perpage']}{$search_url}");
 311  
 312      $plugins->run_hooks('memberlist_intermediate');
 313  
 314      $query = $db->simple_select("users u", "COUNT(*) AS users", "{$search_query}");
 315      $num_users = $db->fetch_field($query, "users");
 316  
 317      $page = $mybb->get_input('page', MyBB::INPUT_INT);
 318      if($page && $page > 0)
 319      {
 320          $start = ($page - 1) * $per_page;
 321          $pages = ceil($num_users / $per_page);
 322          if($page > $pages)
 323          {
 324              $start = 0;
 325              $page = 1;
 326          }
 327      }
 328      else
 329      {
 330          $start = 0;
 331          $page = 1;
 332      }
 333  
 334      $sort = htmlspecialchars_uni($mybb->input['sort']);
 335      eval("\$orderarrow['{$sort}'] = \"".$templates->get("memberlist_orderarrow")."\";");
 336  
 337      // Referral?
 338      if($mybb->settings['usereferrals'] == 1)
 339      {
 340          $colspan = 7;
 341          eval("\$referral_header = \"".$templates->get("memberlist_referrals")."\";");
 342      }
 343  
 344      $multipage = multipage($num_users, $per_page, $page, $search_url);
 345  
 346      // Cache a few things
 347      $usertitles = $cache->read('usertitles');
 348      $usertitles_cache = array();
 349      foreach($usertitles as $usertitle)
 350      {
 351          $usertitles_cache[$usertitle['posts']] = $usertitle;
 352      }
 353      $users = '';
 354      $query = $db->query("
 355          SELECT u.*, f.*
 356          FROM ".TABLE_PREFIX."users u
 357          LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
 358          WHERE {$search_query}
 359          ORDER BY {$sort_field} {$sort_order}
 360          LIMIT {$start}, {$per_page}
 361      ");
 362      while($user = $db->fetch_array($query))
 363      {
 364          $user = $plugins->run_hooks("memberlist_user", $user);
 365  
 366          $alt_bg = alt_trow();
 367  
 368          $user['username'] = format_name(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']);
 369  
 370          $user['profilelink'] = build_profile_link($user['username'], $user['uid']);
 371  
 372          // Get the display usergroup
 373          if($user['usergroup'])
 374          {
 375              $usergroup = usergroup_permissions($user['usergroup']);
 376          }
 377          else
 378          {
 379              $usergroup = usergroup_permissions(1);
 380          }
 381  
 382          $displaygroupfields = array("title", "description", "namestyle", "usertitle", "stars", "starimage", "image");
 383  
 384          if(!$user['displaygroup'])
 385          {
 386              $user['displaygroup'] = $user['usergroup'];
 387          }
 388  
 389          $display_group = usergroup_displaygroup($user['displaygroup']);
 390          if(is_array($display_group))
 391          {
 392              $usergroup = array_merge($usergroup, $display_group);
 393          }
 394  
 395          // Build referral?
 396          if($mybb->settings['usereferrals'] == 1)
 397          {
 398              $referral_count = (int) $user['referrals'];
 399              if($referral_count > 0)
 400              {
 401                  $uid = (int) $user['uid'];
 402                  eval("\$user['referrals'] = \"".$templates->get('member_referrals_link')."\";");
 403              }
 404  
 405              eval("\$referral_bit = \"".$templates->get("memberlist_referrals_bit")."\";");
 406              eval("\$referrals_option = \"".$templates->get("memberlist_referrals_option")."\";");
 407          }
 408  
 409          $usergroup['groupimage'] = '';
 410          // Work out the usergroup/title stuff
 411          if(!empty($usergroup['image']))
 412          {
 413              if(!empty($mybb->user['language']))
 414              {
 415                  $language = $mybb->user['language'];
 416              }
 417              else
 418              {
 419                  $language = $mybb->settings['bblanguage'];
 420              }
 421              $usergroup['image'] = str_replace("{lang}", $language, $usergroup['image']);
 422              $usergroup['image'] = str_replace("{theme}", $theme['imgdir'], $usergroup['image']);
 423              eval("\$usergroup['groupimage'] = \"".$templates->get("memberlist_user_groupimage")."\";");
 424          }
 425  
 426          $has_custom_title = 0;
 427          if(trim($user['usertitle']) != "")
 428          {
 429              $has_custom_title = 1;
 430          }
 431  
 432          if($usergroup['usertitle'] != "" && !$has_custom_title)
 433          {
 434              $user['usertitle'] = $usergroup['usertitle'];
 435          }
 436          elseif(is_array($usertitles_cache) && !$usergroup['usertitle'])
 437          {
 438              foreach($usertitles_cache as $posts => $titleinfo)
 439              {
 440                  if($user['postnum'] >= $posts)
 441                  {
 442                      if(!$has_custom_title)
 443                      {
 444                          $user['usertitle'] = $titleinfo['title'];
 445                      }
 446                      $user['stars'] = $titleinfo['stars'];
 447                      $user['starimage'] = $titleinfo['starimage'];
 448                      break;
 449                  }
 450              }
 451          }
 452          
 453          $user['usertitle'] = htmlspecialchars_uni($user['usertitle']);
 454  
 455          if(!empty($usergroup['stars']))
 456          {
 457              $user['stars'] = $usergroup['stars'];
 458          }
 459  
 460          if(empty($user['starimage']))
 461          {
 462              $user['starimage'] = $usergroup['starimage'];
 463          }
 464  
 465          $user['userstars'] = '';
 466          if(!empty($user['starimage']))
 467          {
 468              // Only display stars if we have an image to use...
 469              $starimage = str_replace("{theme}", $theme['imgdir'], $user['starimage']);
 470  
 471              for($i = 0; $i < $user['stars']; ++$i)
 472              {
 473                  eval("\$user['userstars'] .= \"".$templates->get("memberlist_user_userstar", 1, 0)."\";");
 474              }
 475          }
 476  
 477          if($user['userstars'] && $usergroup['groupimage'])
 478          {
 479              $user['userstars'] = "<br />".$user['userstars'];
 480          }
 481  
 482          // Show avatar
 483          $useravatar = format_avatar($user['avatar'], $user['avatardimensions'], my_strtolower($mybb->settings['memberlistmaxavatarsize']));
 484          eval("\$user['avatar'] = \"".$templates->get("memberlist_user_avatar")."\";");
 485  
 486          if($user['invisible'] == 1 && $mybb->usergroup['canviewwolinvis'] != 1 && $user['uid'] != $mybb->user['uid'])
 487          {
 488              $user['lastvisit'] = $lang->lastvisit_never;
 489  
 490              if($user['lastvisit'])
 491              {
 492                  // We have had at least some active time, hide it instead
 493                  $user['lastvisit'] = $lang->lastvisit_hidden;
 494              }
 495          }
 496          else
 497          {
 498              $user['lastvisit'] = my_date('relative', $user['lastactive']);
 499          }
 500  
 501          $user['regdate'] = my_date('relative', $user['regdate']);
 502          $user['postnum'] = my_number_format($user['postnum']);
 503          $user['threadnum'] = my_number_format($user['threadnum']);
 504          eval("\$users .= \"".$templates->get("memberlist_user")."\";");
 505      }
 506  
 507      // Do we have no results?
 508      if(!$users)
 509      {
 510          eval("\$users = \"".$templates->get("memberlist_error")."\";");
 511      }
 512  
 513      $plugins->run_hooks("memberlist_end");
 514  
 515      eval("\$memberlist = \"".$templates->get("memberlist")."\";");
 516      output_page($memberlist);
 517  }


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