MyBB PHP Cross Reference Discussion Forums

Source: /reputation.php - 850 lines - 27947 bytes - Summary - Text - Print

Description: MyBB 1.6 Copyright 2010 MyBB Group, All Rights Reserved

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  define("IN_MYBB", 1);
  13  define('THIS_SCRIPT', 'reputation.php');
  14  
  15  $templatelist = 'reputation_addlink,reputation_no_votes,reputation,reputation_add_error,reputation_deleted,reputation_added,reputation_add,reputation_vote,multipage_page_current,multipage_page,multipage_nextpage,multipage,multipage_prevpage,multipage_start,multipage_end';
  16  require_once  "./global.php";
  17  
  18  require_once  MYBB_ROOT."inc/class_parser.php";
  19  $parser = new postParser;
  20  
  21  // Load global language phrases
  22  $lang->load("reputation");
  23  
  24  $plugins->run_hooks("reputation_start");
  25  
  26  // Check if the reputation system is globally disabled or not.
  27  if($mybb->settings['enablereputation'] != 1)
  28  {
  29      error($lang->reputation_disabled);
  30  }
  31  
  32  // Does this user have permission to view the board?
  33  if($mybb->usergroup['canview'] != 1)
  34  {
  35      error_no_permission();
  36  }
  37  
  38  // If we have a specified incoming username, validate it and fetch permissions for it
  39  $uid = intval($mybb->input['uid']);
  40  $user = get_user($uid);
  41  if(!$user['uid'])
  42  {
  43      error($lang->add_no_uid);
  44  }
  45  $user_permissions = user_permissions($uid);
  46  
  47  $show_back = '0';
  48  
  49  // Here we perform our validation when adding a reputation to see if the user
  50  // has permission or not. This is done here to save duplicating the same code.
  51  if($mybb->input['action'] == "add" || $mybb->input['action'] == "do_add")
  52  {
  53      // This user doesn't have permission to give reputations.
  54      if($mybb->usergroup['cangivereputations'] != 1)
  55      {
  56          $message = $lang->add_no_permission;
  57          eval("\$error = \"".$templates->get("reputation_add_error")."\";");
  58          output_page($error);
  59          exit;
  60      }
  61  
  62      // The user we're trying to give a reputation to doesn't have permission to receive reps.
  63      if($user_permissions['usereputationsystem'] != 1)
  64      {
  65          $message = $lang->add_disabled;
  66          eval("\$error = \"".$templates->get("reputation_add_error")."\";");
  67          output_page($error);
  68          exit;
  69      }
  70  
  71      // Is this user trying to give themself a reputation?
  72      if($uid == $mybb->user['uid'])
  73      {
  74          $message = $lang->add_yours;
  75          eval("\$error = \"".$templates->get("reputation_add_error")."\";");
  76          output_page($error);
  77          exit;
  78      }
  79  
  80      // If a post has been given but post ratings have been disabled, set the post to 0. This will mean all subsequent code will think no post was given.
  81      if($mybb->input['pid'] != 0 && $mybb->settings['postrep'] != 1)
  82      {
  83          $mybb->input['pid'] = 0;
  84      }
  85  
  86      // Check if this user has reached their "maximum reputations per day" quota
  87      if($mybb->usergroup['maxreputationsday'] != 0 && ($mybb->input['action'] != "do_add" || ($mybb->input['action'] == "do_add" && !$mybb->input['delete'])))
  88      {
  89          $timesearch = TIME_NOW - (60 * 60 * 24);
  90          $query = $db->simple_select("reputation", "*", "adduid='".$mybb->user['uid']."' AND dateline>'$timesearch'");
  91          $numtoday = $db->num_rows($query);
  92  
  93          // Reached the quota - error.
  94          if($numtoday >= $mybb->usergroup['maxreputationsday'])
  95          {
  96              $message = $lang->add_maxperday;
  97              eval("\$error = \"".$templates->get("reputation_add_error")."\";");
  98              output_page($error);
  99              exit;
 100          }
 101      }
 102  
 103      // Is the user giving too much reputation to another?
 104      if($mybb->usergroup['maxreputationsperuser'] != 0 && ($mybb->input['action'] != "do_add" || ($mybb->input['action'] == "do_add" && !$mybb->input['delete'])))
 105      {
 106          $timesearch = TIME_NOW - (60 * 60 * 24);
 107          $query = $db->simple_select("reputation", "*", "uid='".$uid."' AND dateline>'$timesearch'");
 108          $numtoday = $db->num_rows($query);
 109  
 110          if($numtoday >= $mybb->usergroup['maxreputationsperuser'])
 111          {
 112              $message = $lang->add_maxperuser;
 113              eval("\$error = \"".$templates->get("reputation_add_error")."\";");
 114              output_page($error);
 115              exit;
 116          }
 117      }
 118  
 119      if($mybb->input['pid'])
 120      {
 121          // Make sure that this post exists, and that the author of the post we're giving this reputation for corresponds with the user the rep is being given to.
 122          $post = get_post($mybb->input['pid']);
 123          if($post)
 124          {
 125              $thread = get_thread($post['tid']);
 126              $forum = get_forum($thread['fid']);
 127              $forumpermissions = forum_permissions($forum['fid']);
 128              // Post doesn't belong to that user or isn't visible
 129              if($uid != $post['uid'] || ($post['visible'] == 0 && !is_moderator($fid)) || $post['visible'] < 0)
 130              {
 131                  $mybb->input['pid'] = 0;
 132              }
 133              // Thread isn't visible
 134              elseif(($thread['visible'] == 0 && !is_moderator($forum['fid'])) || $thread['visible'] < 0)
 135              {
 136                  $mybb->input['pid'] = 0;
 137              }
 138              // Current user can't see the forum
 139              elseif($forumpermissions['canview'] == 0 || $forumpermissions['canpostreplys'] == 0 || $mybb->user['suspendposting'] == 1)
 140              {
 141                  $mybb->input['pid'] = 0;
 142              }
 143              // Current user can't see that thread
 144              elseif(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
 145              {
 146                  $mybb->input['pid'] = 0;
 147              }
 148              else
 149              // We have the correct post, but has the user given too much reputation to another in the same thread?
 150              if($mybb->usergroup['maxreputationsperthread'] != 0 && ($mybb->input['action'] != "do_add" || ($mybb->input['action'] == "do_add" && !$mybb->input['delete'])))
 151              {
 152                  $timesearch = TIME_NOW - (60 * 60 * 24);
 153                  $query = $db->query("
 154                      SELECT COUNT(p.pid) AS posts
 155                      FROM ".TABLE_PREFIX."reputation r
 156                      LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid = r.pid)
 157                      WHERE r.uid = '{$uid}' AND r.adduid = '{$mybb->user['uid']}' AND p.tid = '{$post['tid']}' AND r.dateline > '{$timesearch}'
 158                  ");
 159  
 160                  $numtoday = $db->fetch_field($query, 'posts');
 161  
 162                  if($numtoday >= $mybb->usergroup['maxreputationsperthread'])
 163                  {
 164                      $message = $lang->add_maxperthread;
 165                      eval("\$error = \"".$templates->get("reputation_add_error")."\";");
 166                      output_page($error);
 167                      exit;
 168                  }
 169              }
 170          }
 171          else
 172          {
 173              $mybb->input['pid'] = 0;
 174          }
 175      }
 176  
 177      // Fetch the existing reputation for this user given by our current user if there is one.
 178      // If multiple reputations is allowed, then this isn't needed
 179      if($mybb->settings['multirep'] != 1 && $mybb->input['pid'] == 0)
 180      {
 181          $query = $db->simple_select("reputation", "*", "adduid='".$mybb->user['uid']."' AND uid='{$uid}' AND pid='0'");
 182          $existing_reputation = $db->fetch_array($query);
 183          $rid = $existing_reputation['rid'];
 184      }
 185      if($mybb->input['pid'] != 0)
 186      {
 187          $query = $db->simple_select("reputation", "*", "adduid='".$mybb->user['uid']."' AND uid='{$uid}' AND pid = '".intval($mybb->input['pid'])."'");
 188          $existing_post_reputation = $db->fetch_array($query);
 189          $rid = $existing_post_reputation['rid'];
 190      }
 191  }
 192  
 193  // Saving the new reputation
 194  if($mybb->input['action'] == "do_add" && $mybb->request_method == "post")
 195  {
 196      // Verify incoming POST request
 197      verify_post_check($mybb->input['my_post_key']);
 198  
 199      $plugins->run_hooks("reputation_do_add_start");
 200  
 201      // Check if the reputation power they're trying to give is within their "power limit"
 202      $reputation = intval(str_replace("-", "", $mybb->input['reputation']));
 203  
 204      // Deleting our current reputation of this user.
 205      if($mybb->input['delete'])
 206      {
 207          // Only administrators, super moderators, as well as users who gave a specifc vote can delete one.
 208          if($mybb->usergroup['cancp'] != 1 && $mybb->usergroup['issupermod'] != 1 && $existing_reputation['adduid'] != $mybb->user['uid'])
 209          {
 210              error_no_permission();
 211          }
 212  
 213          if($mybb->input['pid'] != 0)
 214          {
 215              $db->delete_query("reputation", "uid='{$uid}' AND adduid='".$mybb->user['uid']."' AND pid = '".intval($mybb->input['pid'])."'");
 216          }
 217          else
 218          {
 219              $db->delete_query("reputation", "rid='{$rid}' AND uid='{$uid}' AND adduid='".$mybb->user['uid']."'");
 220          }
 221  
 222          // Recount the reputation of this user - keep it in sync.
 223          $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 224          $reputation_value = $db->fetch_field($query, "reputation_count");
 225  
 226          $db->update_query("users", array('reputation' => intval($reputation_value)), "uid='{$uid}'");
 227          eval("\$error = \"".$templates->get("reputation_deleted")."\";");
 228          output_page($error);
 229          exit;
 230      }
 231  
 232      if($mybb->input['pid'] == 0)
 233      {
 234          $mybb->input['comments'] = trim($mybb->input['comments']); // Trim whitespace to check for length
 235          if(my_strlen($mybb->input['comments']) < 10)
 236          {
 237              $show_back = 1;
 238              $message = $lang->add_no_comment;
 239              eval("\$error = \"".$templates->get("reputation_add_error")."\";");
 240              output_page($error);
 241              exit;
 242          }
 243      }
 244  
 245      // The power for the reputation they specified was invalid.
 246      if($reputation > $mybb->usergroup['reputationpower'] || !is_numeric($mybb->input['reputation']))
 247      {
 248          $show_back = 1;
 249          $message = $lang->add_invalidpower;
 250          eval("\$error = \"".$templates->get("reputation_add_error")."\";");
 251          output_page($error);
 252          exit;
 253      }
 254  
 255      // The user is trying to give a negative reputation, but negative reps have been disabled.
 256      if($mybb->input['reputation'] < 0 && $mybb->settings['negrep'] != 1)
 257      {
 258          $show_back = 1;
 259          $message = $lang->add_negative_disabled;
 260          eval("\$error = \"".$templates->get("reputation_add_error")."\";");
 261          output_page($error);
 262          exit;
 263      }
 264  
 265      // This user is trying to give a neutral reputation, but neutral reps have been disabled.
 266      if($mybb->input['reputation'] == 0 && $mybb->settings['neurep'] != 1)
 267      {
 268          $show_back = 1;
 269          $message = $lang->add_neutral_disabled;
 270          eval("\$error = \"".$templates->get("reputation_add_error")."\";");
 271          output_page($error);
 272          exit;
 273      }
 274  
 275      // This user is trying to give a positive reputation, but positive reps have been disabled.
 276      if($mybb->input['reputation'] > 0 && $mybb->settings['posrep'] != 1)
 277      {
 278          $show_back = 1;
 279          $message = $lang->add_positive_disabled;
 280          eval("\$error = \"".$templates->get("reputation_add_error")."\";");
 281          output_page($error);
 282          exit;
 283      }
 284  
 285      // The length of the comment is too long
 286      if(my_strlen($mybb->input['comments']) > $mybb->settings['maxreplength'])
 287      {
 288          $show_back = 1;
 289          $message = $lang->sprintf($lang->add_toolong, $mybb->settings['maxreplength']);
 290          eval("\$error = \"".$templates->get("reputation_add_error")."\";");
 291          output_page($error);
 292          exit;
 293      }
 294  
 295      // Build array of reputation data.
 296      $reputation = array(
 297          "uid" => $uid,
 298          "adduid" => $mybb->user['uid'],
 299          "pid" => intval($mybb->input['pid']),
 300          "reputation" => intval($mybb->input['reputation']),
 301          "dateline" => TIME_NOW,
 302          "comments" => $db->escape_string($mybb->input['comments'])
 303      );
 304  
 305      $plugins->run_hooks("reputation_do_add_process");
 306  
 307      // Updating an existing reputation
 308      if($existing_reputation['uid'] || $existing_post_reputation['uid'])
 309      {
 310          if($existing_reputation['uid'])
 311          {
 312              $db->update_query("reputation", $reputation, "rid='".$existing_reputation['rid']."'");
 313          }
 314          elseif($existing_post_reputation['uid'])
 315          {
 316              $db->update_query("reputation", $reputation, "rid='".$existing_post_reputation['rid']."'");
 317          }
 318  
 319          // Recount the reputation of this user - keep it in sync.
 320          $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 321          $reputation_value = $db->fetch_field($query, "reputation_count");
 322  
 323          $db->update_query("users", array('reputation' => intval($reputation_value)), "uid='{$uid}'");
 324  
 325          $lang->vote_added = $lang->vote_updated;
 326          $lang->vote_added_message = $lang->vote_updated_message;
 327      }
 328      // Insert a new reputation
 329      else
 330      {
 331          $db->insert_query("reputation", $reputation);
 332  
 333          // Recount the reputation of this user - keep it in sync.
 334          $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 335          $reputation_value = $db->fetch_field($query, "reputation_count");
 336  
 337          $db->update_query("users", array('reputation' => intval($reputation_value)), "uid='{$uid}'");
 338      }
 339  
 340      $plugins->run_hooks("reputation_do_add_end");
 341  
 342      eval("\$reputation = \"".$templates->get("reputation_added")."\";");
 343      output_page($reputation);
 344  }
 345  
 346  // Adding a new reputation
 347  if($mybb->input['action'] == "add")
 348  {
 349      $plugins->run_hooks("reputation_add_start");
 350  
 351      // If we have an existing reputation for this user, the user can modify or delete it.
 352      if($existing_reputation['uid'] || $existing_post_reputation['uid'])
 353      {
 354          $vote_title = $lang->sprintf($lang->update_reputation_vote, $user['username']);
 355          $vote_button = $lang->update_vote;
 356          if($existing_reputation['uid'])
 357          {
 358              $comments = htmlspecialchars_uni($existing_reputation['comments']);
 359          }
 360          elseif($existing_post_reputation['uid'])
 361          {
 362              $comments = htmlspecialchars_uni($existing_post_reputation['comments']);
 363          }
 364          $delete_button = "<input type=\"submit\" name=\"delete\" value=\"{$lang->delete_vote}\" />";
 365      }
 366      // Otherwise we're adding an entirely new reputation for this user.
 367      else
 368      {
 369          $vote_title = $lang->sprintf($lang->add_reputation_vote, $user['username']);
 370          $vote_button = $lang->add_vote;
 371          $comments = '';
 372          $delete_button = '';
 373      }
 374      $lang->user_comments = $lang->sprintf($lang->user_comments, $user['username']);
 375  
 376      if($mybb->input['pid'])
 377      {
 378          $post_rep_info = $lang->sprintf($lang->add_reputation_to_post, $user['username']);
 379          $lang->user_comments = $lang->no_comment_needed;
 380      }
 381      else
 382      {
 383          $post_rep_info = '';
 384      }
 385  
 386      // Draw the "power" options
 387      if($mybb->settings['negrep'] || $mybb->settings['neurep'] || $mybb->settings['posrep'])
 388      {
 389          $vote_check = '';
 390          $positive_power = '';
 391          $negative_power = '';
 392          $reputationpower = $mybb->usergroup['reputationpower'];
 393  
 394          if($existing_reputation['uid'])
 395          {
 396              $vote_check[$existing_reputation['reputation']] = " selected=\"selected\"";
 397          }
 398  
 399          if($mybb->settings['neurep'])
 400          {
 401              $neutral_title = $lang->power_neutral;
 402              $neutral_power = "\t\t\t\t\t<option value=\"0\" class=\"reputation_neutral\" onclick=\"$('reputation').className='reputation_neutral'\"{$vote_check[0]}>{$lang->power_neutral}</option>\n";
 403          }
 404  
 405          for($i = 1; $i <= $reputationpower; ++$i)
 406          {
 407              if($mybb->settings['posrep'])
 408              {
 409                  $positive_title = $lang->sprintf($lang->power_positive, "+".$i);
 410                  $positive_power = "\t\t\t\t\t<option value=\"{$i}\" class=\"reputation_positive\" onclick=\"$('reputation').className='reputation_positive'\"{$vote_check[$i]}>{$positive_title}</option>\n".$positive_power;
 411              }
 412  
 413              if($mybb->settings['negrep'])
 414              {
 415                  $negative_title = $lang->sprintf($lang->power_negative, "-".$i);
 416                  $negative_power .= "\t\t\t\t\t<option value=\"-{$i}\" class=\"reputation_negative\" onclick=\"$('reputation').className='reputation_negative'\"{$vote_check[-$i]}>{$negative_title}</option>\n";
 417              }
 418          }
 419  
 420          $plugins->run_hooks("reputation_add_end");
 421          eval("\$reputation_add = \"".$templates->get("reputation_add")."\";");
 422      }
 423      else
 424      {
 425          $message = $lang->add_all_rep_disabled;
 426  
 427          $plugins->run_hooks("reputation_add_end_error");
 428          eval("\$reputation_add = \"".$templates->get("reputation_add_error")."\";");
 429      }
 430  
 431      output_page($reputation_add);
 432  }
 433  
 434  // Delete a specific reputation from a user.
 435  if($mybb->input['action'] == "delete")
 436  {
 437      // Verify incoming POST request
 438      verify_post_check($mybb->input['my_post_key']);
 439  
 440      // Fetch the existing reputation for this user given by our current user if there is one.
 441      $query = $db->query("
 442          SELECT r.*, u.username
 443          FROM ".TABLE_PREFIX."reputation r
 444          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=r.adduid)
 445          WHERE rid = '".intval($mybb->input['rid'])."'
 446      ");
 447      $existing_reputation = $db->fetch_array($query);
 448  
 449      // Only administrators, super moderators, as well as users who gave a specifc vote can delete one.
 450      if($mybb->usergroup['cancp'] != 1 && $mybb->usergroup['issupermod'] != 1 && $existing_reputation['adduid'] != $mybb->user['uid'])
 451      {
 452          error_no_permission();
 453      }
 454  
 455      // Delete the specified reputation
 456      $db->delete_query("reputation", "uid='{$uid}' AND rid='".intval($mybb->input['rid'])."'");
 457  
 458      // Recount the reputation of this user - keep it in sync.
 459      $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 460      $reputation_value = $db->fetch_field($query, "reputation_count");
 461  
 462      // Create moderator log
 463      log_moderator_action(array("uid" => $user['uid'], "username" => $user['username']), $lang->sprintf($lang->delete_reputation_log, $existing_reputation['username'], $existing_reputation['adduid']));
 464  
 465      $db->update_query("users", array('reputation' => intval($reputation_value)), "uid='{$uid}'");
 466  
 467      redirect("reputation.php?uid={$uid}", $lang->vote_deleted_message);
 468  }
 469  
 470  // Otherwise, show a listing of reputations for the given user.
 471  if(!$mybb->input['action'])
 472  {
 473      if($mybb->usergroup['canviewprofiles'] == 0)
 474      {
 475          // Reputation page is a part of a profile
 476          error_no_permission();
 477      }
 478  
 479      // Fetch display group properties.
 480      $displaygroupfields = array('title', 'description', 'namestyle', 'usertitle', 'stars', 'starimage', 'image', 'usereputationsystem');
 481      $display_group = usergroup_displaygroup($user['displaygroup']);
 482  
 483      if($user_permissions['usereputationsystem'] != 1 || $display_group['title'] && $display_group['usereputationsystem'] == 0)
 484      {
 485          // Group has reputation disabled or user has a display group that has reputation disabled
 486          error($lang->reputations_disabled_group);
 487      }
 488  
 489      $lang->nav_profile = $lang->sprintf($lang->nav_profile, $user['username']);
 490      $lang->reputation_report = $lang->sprintf($lang->reputation_report, $user['username']);
 491  
 492      // Format the user name using the group username style
 493      $username = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
 494  
 495      // Set display group to their user group if they don't have a display group.
 496      if(!$user['displaygroup'])
 497      {
 498          $user['displaygroup'] = $user['usergroup'];
 499      }
 500  
 501      // This user has a custom user title
 502      if(trim($user['usertitle']) != '')
 503      {
 504          $usertitle = $user['usertitle'];
 505      }
 506      // Using our display group's user title
 507      elseif(trim($display_group['usertitle']) != '')
 508      {
 509          $usertitle = $display_group['usertitle'];
 510      }
 511      // Otherwise, fetch it from our titles table for the number of posts this user has
 512      else
 513      {
 514          $query = $db->simple_select("usertitles", "*", "posts<='{$user['postnum']}'", array('order_by' => 'posts', 'order_dir' => 'DESC'));
 515          $title = $db->fetch_array($query);
 516          $usertitle = $title['title'];
 517      }
 518  
 519      // If the user has permission to add reputations - show the image
 520      if($mybb->usergroup['cangivereputations'] == 1 && ($mybb->settings['posrep'] || $mybb->settings['neurep'] || $mybb->settings['negrep']))
 521      {
 522          eval("\$add_reputation = \"".$templates->get("reputation_addlink")."\";");
 523      }
 524      else
 525      {
 526          $add_reputation = '';
 527      }
 528  
 529      // Build navigation menu
 530      add_breadcrumb($lang->nav_profile, get_profile_link($user['uid']));
 531      add_breadcrumb($lang->nav_reputation);
 532  
 533      // Check our specified conditionals for what type of reputations to show
 534      $show_select = '';
 535      switch($mybb->input['show'])
 536      {
 537          case "positive":
 538              $s_url = "&show=positive";
 539              $conditions = 'AND r.reputation>0';
 540              $show_selected['positive'] = 'selected="selected"';
 541              break;
 542          case "neutral":
 543              $s_url = "&show=neutral";
 544              $conditions = 'AND r.reputation=0';
 545              $show_selected['neutral'] = 'selected="selected"';
 546              break;
 547          case "negative":
 548              $s_url = "&show=negative";
 549              $conditions = 'AND r.reputation<0';
 550              $show_selected['negative'] = 'selected="selected"';
 551              break;
 552          default:
 553              $s_url = '&show=all';
 554              $conditions = '';
 555              $show_select['all'] = 'selected="selected"';
 556              break;
 557      }
 558  
 559      // Check the sorting options for the reputation list
 560      $sort_select = '';
 561      switch($mybb->input['sort'])
 562      {
 563          case "username":
 564              $s_url .= "&sort=username";
 565              $order = "u.username ASC";
 566              $sort_selected['username'] = 'selected="selected"';
 567              break;
 568          default:
 569              $s_url .= '&sort=dateline';
 570              $order = "r.dateline DESC";
 571              $sort_selected['last_updated'] = 'selected="selected"';
 572              break;
 573      }
 574  
 575      if(!$mybb->input['show'] && !$mybb->input['sort'])
 576      {
 577          $s_url = '';
 578      }
 579  
 580      // Fetch the total number of reputations for this user
 581      $query = $db->simple_select("reputation r", "COUNT(r.rid) AS reputation_count", "r.uid='{$user['uid']}' $conditions");
 582      $reputation_count = $db->fetch_field($query, "reputation_count");
 583  
 584      // If the user has no reputation, suspect 0...
 585      if(!$user['reputation'])
 586      {
 587          $user['reputation'] = 0;
 588      }
 589  
 590      // Quickly check to see if we're in sync...
 591      $query = $db->simple_select("reputation", "SUM(reputation) AS reputation, COUNT(rid) AS total_reputation", "uid = '".$user['uid']."'");
 592      $reputation = $db->fetch_array($query);
 593  
 594      $sync_reputation = intval($reputation['reputation']);
 595      $total_reputation = $reputation['total_reputation'];
 596  
 597      if($sync_reputation != $user['reputation'])
 598      {
 599          // We're out of sync! Oh noes!
 600          $db->update_query("users", array("reputation" => $sync_reputation), "uid = '".$user['uid']."'");
 601          $user['reputation'] = $sync_reputation;
 602      }
 603  
 604      // Set default count variables to 0
 605      $positive_count = $negative_count = $neutral_count = 0;
 606      $positive_week = $negative_week = $neutral_week = 0;
 607      $positive_month = $negative_month = $neutral_month = 0;
 608      $positive_6months = $negative_6months = $neutral_6months = 0;
 609  
 610      // Unix timestamps for when this week, month and last 6 months started
 611      $last_week = TIME_NOW-604800;
 612      $last_month = TIME_NOW-2678400;
 613      $last_6months = TIME_NOW-16070400;
 614  
 615      // Query reputations for the "reputation card"
 616      $query = $db->simple_select("reputation", "reputation, dateline", "uid='{$user['uid']}'");
 617      while($reputation_vote = $db->fetch_array($query))
 618      {
 619          // This is a positive reputation
 620          if($reputation_vote['reputation'] > 0)
 621          {
 622              $positive_count++;
 623              if($reputation_vote['dateline'] >= $last_week)
 624              {
 625                  $positive_week++;
 626              }
 627              if($reputation_vote['dateline'] >= $last_month)
 628              {
 629                  $positive_month++;
 630              }
 631              if($reputation_vote['dateline'] >= $last_6months)
 632              {
 633                  $positive_6months++;
 634              }
 635          }
 636          // Negative reputation given
 637          else if($reputation_vote['reputation'] < 0)
 638          {
 639              $negative_count++;
 640              if($reputation_vote['dateline'] >= $last_week)
 641              {
 642                  $negative_week++;
 643              }
 644              if($reputation_vote['dateline'] >= $last_month)
 645              {
 646                  $negative_month++;
 647              }
 648              if($reputation_vote['dateline'] >= $last_6months)
 649              {
 650                  $negative_6months++;
 651              }
 652          }
 653          // Neutral reputation given
 654          else
 655          {
 656              $neutral_count++;
 657              if($reputation_vote['dateline'] >= $last_week)
 658              {
 659                  $neutral_week++;
 660              }
 661              if($reputation_vote['dateline'] >= $last_month)
 662              {
 663                  $neutral_month++;
 664              }
 665              if($reputation_vote['dateline'] >= $last_6months)
 666              {
 667                  $neutral_6months++;
 668              }
 669          }
 670      }
 671  
 672      // Format the user's 'total' reputation
 673      if($user['reputation'] < 0)
 674      {
 675          $total_class = "_minus";
 676      }
 677      elseif($user['reputation'] > 0)
 678      {
 679          $total_class = "_plus";
 680      }
 681      else
 682      {
 683          $total_class = "_neutral";
 684      }
 685  
 686      // Figure out how many reps have come from posts / 'general'
 687      // Posts
 688      $query = $db->simple_select("reputation", "COUNT(rid) AS rep_posts", "uid = '".$user['uid']."' AND pid > 0");
 689      $rep_post_count = $db->fetch_field($query, "rep_posts");
 690      $rep_posts = my_number_format($rep_post_count);
 691  
 692      // General
 693      // We count how many reps in total, then subtract the reps from posts
 694      $rep_members = my_number_format($total_reputation - $rep_posts);
 695  
 696      // Is negative reputation disabled? If so, tell the user
 697      if($mybb->settings['negrep'] == 0)
 698      {
 699          $neg_rep_info = $lang->neg_rep_disabled;
 700      }
 701  
 702      if($mybb->settings['posrep'] == 0)
 703      {
 704          $pos_rep_info = $lang->pos_rep_disabled;
 705      }
 706  
 707      if($mybb->settings['neurep'] == 0)
 708      {
 709          $neu_rep_info = $lang->neu_rep_disabled;
 710      }
 711  
 712      // Check if we're browsing a specific page of results
 713      if(intval($mybb->input['page']) > 0)
 714      {
 715          $page = $mybb->input['page'];
 716          $start = ($page-1) *$mybb->settings['repsperpage'];
 717          $pages = $reputation_count / $mybb->settings['repsperpage'];
 718          $pages = ceil($pages);
 719          if($page > $pages)
 720          {
 721              $start = 0;
 722              $page = 1;
 723          }
 724      }
 725      else
 726      {
 727          $start = 0;
 728          $page = 1;
 729      }
 730  
 731      // Build out multipage navigation
 732      if($reputation_count > 0)
 733      {
 734          $multipage = multipage($reputation_count, $mybb->settings['repsperpage'], $page, "reputation.php?uid={$user['uid']}".$s_url);
 735      }
 736  
 737      // Fetch the reputations which will be displayed on this page
 738      $query = $db->query("
 739          SELECT r.*, r.uid AS rated_uid, u.uid, u.username, u.reputation AS user_reputation, u.usergroup AS user_usergroup, u.displaygroup AS user_displaygroup, p.pid AS post_link
 740          FROM ".TABLE_PREFIX."reputation r
 741          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=r.adduid)
 742          LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=r.pid)
 743          WHERE r.uid='{$user['uid']}' $conditions
 744          ORDER BY $order
 745          LIMIT $start, {$mybb->settings['repsperpage']}
 746      ");
 747      while($reputation_vote = $db->fetch_array($query))
 748      {
 749          // Get the reputation for the user who posted this comment
 750          if($reputation_vote['adduid'] == 0)
 751          {
 752              $reputation_vote['user_reputation'] = 0;
 753          }
 754  
 755          $reputation_vote['user_reputation'] = get_reputation($reputation_vote['user_reputation'], $reputation_vote['adduid']);
 756  
 757          // Format the username of this poster
 758          if(!$reputation_vote['username'])
 759          {
 760              $reputation_vote['username'] = $lang->na;
 761              $reputation_vote['user_reputation'] = '';
 762          }
 763          else
 764          {
 765              $reputation_vote['username'] = format_name($reputation_vote['username'], $reputation_vote['user_usergroup'], $reputation_vote['user_displaygroup']);
 766              $reputation_vote['username'] = build_profile_link($reputation_vote['username'], $reputation_vote['uid']);
 767              $reputation_vote['user_reputation'] = "({$reputation_vote['user_reputation']})";
 768          }
 769  
 770          $vote_reputation = intval($reputation_vote['reputation']);
 771  
 772          // This is a negative reputation
 773          if($vote_reputation < 0)
 774          {
 775              $status_class = "trow_reputation_negative";
 776              $vote_type_class = "reputation_negative";
 777              $vote_type = $lang->negative;
 778          }
 779          // This is a neutral reputation
 780          else if($vote_reputation == 0)
 781          {
 782              $status_class = "trow_reputation_neutral";
 783              $vote_type_class = "reputation_neutral";
 784              $vote_type = $lang->neutral;
 785          }
 786          // Otherwise, this is a positive reputation
 787          else
 788          {
 789              $vote_reputation = "+{$vote_reputation}";
 790              $status_class = "trow_reputation_positive";
 791              $vote_type_class = "reputation_positive";
 792              $vote_type = $lang->positive;
 793          }
 794  
 795          $vote_reputation = "({$vote_reputation})";
 796  
 797          // Format the date this reputation was last modified
 798          $last_updated_date = my_date($mybb->settings['dateformat'], $reputation_vote['dateline']);
 799          $last_updated_time = my_date($mybb->settings['timeformat'], $reputation_vote['dateline']);
 800          $last_updated = $lang->sprintf($lang->last_updated, $last_updated_date, $last_updated_time);
 801  
 802          // Is this rating specific to a post?
 803          if($reputation_vote['pid'] && $reputation_vote['post_link'])
 804          {
 805              $link = "<a href=\"".get_post_link($reputation_vote['pid'])."#pid{$reputation_vote['pid']}\">{$lang->postrep_post}".$reputation_vote['pid']."</a>";
 806              $postrep_given = $lang->sprintf($lang->postrep_given, $link);
 807          }
 808          else
 809          {
 810              $postrep_given = '';
 811          }
 812  
 813          // Does the current user have permission to delete this reputation? Show delete link
 814          if($mybb->usergroup['cancp'] == 1 || $mybb->usergroup['issupermod'] == 1 || ($mybb->usergroup['cangivereputations'] == 1 && $reputation_vote['adduid'] == $mybb->user['uid'] && $mybb->user['uid'] != 0))
 815          {
 816              $delete_link = "[<a href=\"reputation.php?action=delete&amp;uid={$reputation_vote['rated_uid']}&amp;rid={$reputation_vote['rid']}\" onclick=\"MyBB.deleteReputation({$reputation_vote['rated_uid']}, {$reputation_vote['rid']}); return false;\">{$lang->delete_vote}</a>]";
 817          }
 818          else
 819          {
 820              $delete_link = '';
 821          }
 822  
 823          // Parse smilies in the reputation vote
 824          $reputation_parser = array(
 825              "allow_html" => 0,
 826              "allow_mycode" => 0,
 827              "allow_smilies" => 1,
 828              "allow_imgcode" => 0,
 829              "filter_badwords" => 1
 830          );
 831  
 832          $reputation_vote['comments'] = $parser->parse_message($reputation_vote['comments'], $reputation_parser);
 833          if($reputation_vote['comments'] == '')
 834          {
 835              $reputation_vote['comments'] = $lang->no_comment;
 836          }
 837          eval("\$reputation_votes .= \"".$templates->get("reputation_vote")."\";");
 838      }
 839  
 840      // If we don't have any reputations display a nice message.
 841      if(!$reputation_votes)
 842      {
 843          eval("\$reputation_votes = \"".$templates->get("reputation_no_votes")."\";");
 844      }
 845  
 846      $plugins->run_hooks("reputation_end");
 847      eval("\$reputation = \"".$templates->get("reputation")."\";");
 848      output_page($reputation);
 849  }
 850  ?>

title

Description

title

Description

title

Description

title

title

Body