[ Index ]

PHP Cross Reference of MyBB 1.8.12

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


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