[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/ -> reputation.php (source)

   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      $mybb->input['comments'] = utf8_handle_4byte_string($mybb->input['comments']);
 296  
 297      // Build array of reputation data.
 298      $reputation = array(
 299          "uid" => $uid,
 300          "adduid" => $mybb->user['uid'],
 301          "pid" => intval($mybb->input['pid']),
 302          "reputation" => intval($mybb->input['reputation']),
 303          "dateline" => TIME_NOW,
 304          "comments" => $db->escape_string($mybb->input['comments'])
 305      );
 306  
 307      $plugins->run_hooks("reputation_do_add_process");
 308  
 309      // Updating an existing reputation
 310      if($existing_reputation['uid'] || $existing_post_reputation['uid'])
 311      {
 312          if($existing_reputation['uid'])
 313          {
 314              $db->update_query("reputation", $reputation, "rid='".$existing_reputation['rid']."'");
 315          }
 316          elseif($existing_post_reputation['uid'])
 317          {
 318              $db->update_query("reputation", $reputation, "rid='".$existing_post_reputation['rid']."'");
 319          }
 320  
 321          // Recount the reputation of this user - keep it in sync.
 322          $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 323          $reputation_value = $db->fetch_field($query, "reputation_count");
 324  
 325          $db->update_query("users", array('reputation' => intval($reputation_value)), "uid='{$uid}'");
 326  
 327          $lang->vote_added = $lang->vote_updated;
 328          $lang->vote_added_message = $lang->vote_updated_message;
 329      }
 330      // Insert a new reputation
 331      else
 332      {
 333          $db->insert_query("reputation", $reputation);
 334  
 335          // Recount the reputation of this user - keep it in sync.
 336          $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 337          $reputation_value = $db->fetch_field($query, "reputation_count");
 338  
 339          $db->update_query("users", array('reputation' => intval($reputation_value)), "uid='{$uid}'");
 340      }
 341  
 342      $plugins->run_hooks("reputation_do_add_end");
 343  
 344      eval("\$reputation = \"".$templates->get("reputation_added")."\";");
 345      output_page($reputation);
 346  }
 347  
 348  // Adding a new reputation
 349  if($mybb->input['action'] == "add")
 350  {
 351      $plugins->run_hooks("reputation_add_start");
 352  
 353      // If we have an existing reputation for this user, the user can modify or delete it.
 354      if($existing_reputation['uid'] || $existing_post_reputation['uid'])
 355      {
 356          $vote_title = $lang->sprintf($lang->update_reputation_vote, $user['username']);
 357          $vote_button = $lang->update_vote;
 358          if($existing_reputation['uid'])
 359          {
 360              $comments = htmlspecialchars_uni($existing_reputation['comments']);
 361          }
 362          elseif($existing_post_reputation['uid'])
 363          {
 364              $comments = htmlspecialchars_uni($existing_post_reputation['comments']);
 365          }
 366          $delete_button = "<input type=\"submit\" name=\"delete\" value=\"{$lang->delete_vote}\" />";
 367      }
 368      // Otherwise we're adding an entirely new reputation for this user.
 369      else
 370      {
 371          $vote_title = $lang->sprintf($lang->add_reputation_vote, $user['username']);
 372          $vote_button = $lang->add_vote;
 373          $comments = '';
 374          $delete_button = '';
 375      }
 376      $lang->user_comments = $lang->sprintf($lang->user_comments, $user['username']);
 377  
 378      if($mybb->input['pid'])
 379      {
 380          $post_rep_info = $lang->sprintf($lang->add_reputation_to_post, $user['username']);
 381          $lang->user_comments = $lang->no_comment_needed;
 382      }
 383      else
 384      {
 385          $post_rep_info = '';
 386      }
 387  
 388      // Draw the "power" options
 389      if($mybb->settings['negrep'] || $mybb->settings['neurep'] || $mybb->settings['posrep'])
 390      {
 391          $vote_check = '';
 392          $positive_power = '';
 393          $negative_power = '';
 394          $reputationpower = $mybb->usergroup['reputationpower'];
 395  
 396          if($existing_reputation['uid'])
 397          {
 398              $vote_check[$existing_reputation['reputation']] = " selected=\"selected\"";
 399          }
 400  
 401          if($mybb->settings['neurep'])
 402          {
 403              $neutral_title = $lang->power_neutral;
 404              $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";
 405          }
 406  
 407          for($i = 1; $i <= $reputationpower; ++$i)
 408          {
 409              if($mybb->settings['posrep'])
 410              {
 411                  $positive_title = $lang->sprintf($lang->power_positive, "+".$i);
 412                  $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;
 413              }
 414  
 415              if($mybb->settings['negrep'])
 416              {
 417                  $negative_title = $lang->sprintf($lang->power_negative, "-".$i);
 418                  $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";
 419              }
 420          }
 421  
 422          $plugins->run_hooks("reputation_add_end");
 423          eval("\$reputation_add = \"".$templates->get("reputation_add")."\";");
 424      }
 425      else
 426      {
 427          $message = $lang->add_all_rep_disabled;
 428  
 429          $plugins->run_hooks("reputation_add_end_error");
 430          eval("\$reputation_add = \"".$templates->get("reputation_add_error")."\";");
 431      }
 432  
 433      output_page($reputation_add);
 434  }
 435  
 436  // Delete a specific reputation from a user.
 437  if($mybb->input['action'] == "delete")
 438  {
 439      // Verify incoming POST request
 440      verify_post_check($mybb->input['my_post_key']);
 441  
 442      // Fetch the existing reputation for this user given by our current user if there is one.
 443      $query = $db->query("
 444          SELECT r.*, u.username
 445          FROM ".TABLE_PREFIX."reputation r
 446          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=r.adduid)
 447          WHERE rid = '".intval($mybb->input['rid'])."'
 448      ");
 449      $existing_reputation = $db->fetch_array($query);
 450  
 451      // Only administrators, super moderators, as well as users who gave a specifc vote can delete one.
 452      if($mybb->usergroup['cancp'] != 1 && $mybb->usergroup['issupermod'] != 1 && $existing_reputation['adduid'] != $mybb->user['uid'])
 453      {
 454          error_no_permission();
 455      }
 456  
 457      // Delete the specified reputation
 458      $db->delete_query("reputation", "uid='{$uid}' AND rid='".intval($mybb->input['rid'])."'");
 459  
 460      // Recount the reputation of this user - keep it in sync.
 461      $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 462      $reputation_value = $db->fetch_field($query, "reputation_count");
 463  
 464      // Create moderator log
 465      log_moderator_action(array("uid" => $user['uid'], "username" => $user['username']), $lang->sprintf($lang->delete_reputation_log, $existing_reputation['username'], $existing_reputation['adduid']));
 466  
 467      $db->update_query("users", array('reputation' => intval($reputation_value)), "uid='{$uid}'");
 468  
 469      redirect("reputation.php?uid={$uid}", $lang->vote_deleted_message);
 470  }
 471  
 472  // Otherwise, show a listing of reputations for the given user.
 473  if(!$mybb->input['action'])
 474  {
 475      if($mybb->usergroup['canviewprofiles'] == 0)
 476      {
 477          // Reputation page is a part of a profile
 478          error_no_permission();
 479      }
 480  
 481      // Fetch display group properties.
 482      $displaygroupfields = array('title', 'description', 'namestyle', 'usertitle', 'stars', 'starimage', 'image', 'usereputationsystem');
 483      $display_group = usergroup_displaygroup($user['displaygroup']);
 484  
 485      if($user_permissions['usereputationsystem'] != 1 || $display_group['title'] && $display_group['usereputationsystem'] == 0)
 486      {
 487          // Group has reputation disabled or user has a display group that has reputation disabled
 488          error($lang->reputations_disabled_group);
 489      }
 490  
 491      $lang->nav_profile = $lang->sprintf($lang->nav_profile, $user['username']);
 492      $lang->reputation_report = $lang->sprintf($lang->reputation_report, $user['username']);
 493  
 494      // Format the user name using the group username style
 495      $username = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
 496  
 497      // Set display group to their user group if they don't have a display group.
 498      if(!$user['displaygroup'])
 499      {
 500          $user['displaygroup'] = $user['usergroup'];
 501      }
 502  
 503      // This user has a custom user title
 504      if(trim($user['usertitle']) != '')
 505      {
 506          $usertitle = $user['usertitle'];
 507      }
 508      // Using our display group's user title
 509      elseif(trim($display_group['usertitle']) != '')
 510      {
 511          $usertitle = $display_group['usertitle'];
 512      }
 513      // Otherwise, fetch it from our titles table for the number of posts this user has
 514      else
 515      {
 516          $query = $db->simple_select("usertitles", "*", "posts<='{$user['postnum']}'", array('order_by' => 'posts', 'order_dir' => 'DESC'));
 517          $title = $db->fetch_array($query);
 518          $usertitle = $title['title'];
 519      }
 520  
 521      // If the user has permission to add reputations - show the image
 522      if($mybb->usergroup['cangivereputations'] == 1 && ($mybb->settings['posrep'] || $mybb->settings['neurep'] || $mybb->settings['negrep']))
 523      {
 524          eval("\$add_reputation = \"".$templates->get("reputation_addlink")."\";");
 525      }
 526      else
 527      {
 528          $add_reputation = '';
 529      }
 530  
 531      // Build navigation menu
 532      add_breadcrumb($lang->nav_profile, get_profile_link($user['uid']));
 533      add_breadcrumb($lang->nav_reputation);
 534  
 535      // Check our specified conditionals for what type of reputations to show
 536      $show_select = '';
 537      switch($mybb->input['show'])
 538      {
 539          case "positive":
 540              $s_url = "&show=positive";
 541              $conditions = 'AND r.reputation>0';
 542              $show_selected['positive'] = 'selected="selected"';
 543              break;
 544          case "neutral":
 545              $s_url = "&show=neutral";
 546              $conditions = 'AND r.reputation=0';
 547              $show_selected['neutral'] = 'selected="selected"';
 548              break;
 549          case "negative":
 550              $s_url = "&show=negative";
 551              $conditions = 'AND r.reputation<0';
 552              $show_selected['negative'] = 'selected="selected"';
 553              break;
 554          default:
 555              $s_url = '&show=all';
 556              $conditions = '';
 557              $show_select['all'] = 'selected="selected"';
 558              break;
 559      }
 560  
 561      // Check the sorting options for the reputation list
 562      $sort_select = '';
 563      switch($mybb->input['sort'])
 564      {
 565          case "username":
 566              $s_url .= "&sort=username";
 567              $order = "u.username ASC";
 568              $sort_selected['username'] = 'selected="selected"';
 569              break;
 570          default:
 571              $s_url .= '&sort=dateline';
 572              $order = "r.dateline DESC";
 573              $sort_selected['last_updated'] = 'selected="selected"';
 574              break;
 575      }
 576  
 577      if(!$mybb->input['show'] && !$mybb->input['sort'])
 578      {
 579          $s_url = '';
 580      }
 581  
 582      // Fetch the total number of reputations for this user
 583      $query = $db->simple_select("reputation r", "COUNT(r.rid) AS reputation_count", "r.uid='{$user['uid']}' $conditions");
 584      $reputation_count = $db->fetch_field($query, "reputation_count");
 585  
 586      // If the user has no reputation, suspect 0...
 587      if(!$user['reputation'])
 588      {
 589          $user['reputation'] = 0;
 590      }
 591  
 592      // Quickly check to see if we're in sync...
 593      $query = $db->simple_select("reputation", "SUM(reputation) AS reputation, COUNT(rid) AS total_reputation", "uid = '".$user['uid']."'");
 594      $reputation = $db->fetch_array($query);
 595  
 596      $sync_reputation = intval($reputation['reputation']);
 597      $total_reputation = $reputation['total_reputation'];
 598  
 599      if($sync_reputation != $user['reputation'])
 600      {
 601          // We're out of sync! Oh noes!
 602          $db->update_query("users", array("reputation" => $sync_reputation), "uid = '".$user['uid']."'");
 603          $user['reputation'] = $sync_reputation;
 604      }
 605  
 606      // Set default count variables to 0
 607      $positive_count = $negative_count = $neutral_count = 0;
 608      $positive_week = $negative_week = $neutral_week = 0;
 609      $positive_month = $negative_month = $neutral_month = 0;
 610      $positive_6months = $negative_6months = $neutral_6months = 0;
 611  
 612      // Unix timestamps for when this week, month and last 6 months started
 613      $last_week = TIME_NOW-604800;
 614      $last_month = TIME_NOW-2678400;
 615      $last_6months = TIME_NOW-16070400;
 616  
 617      // Query reputations for the "reputation card"
 618      $query = $db->simple_select("reputation", "reputation, dateline", "uid='{$user['uid']}'");
 619      while($reputation_vote = $db->fetch_array($query))
 620      {
 621          // This is a positive reputation
 622          if($reputation_vote['reputation'] > 0)
 623          {
 624              $positive_count++;
 625              if($reputation_vote['dateline'] >= $last_week)
 626              {
 627                  $positive_week++;
 628              }
 629              if($reputation_vote['dateline'] >= $last_month)
 630              {
 631                  $positive_month++;
 632              }
 633              if($reputation_vote['dateline'] >= $last_6months)
 634              {
 635                  $positive_6months++;
 636              }
 637          }
 638          // Negative reputation given
 639          else if($reputation_vote['reputation'] < 0)
 640          {
 641              $negative_count++;
 642              if($reputation_vote['dateline'] >= $last_week)
 643              {
 644                  $negative_week++;
 645              }
 646              if($reputation_vote['dateline'] >= $last_month)
 647              {
 648                  $negative_month++;
 649              }
 650              if($reputation_vote['dateline'] >= $last_6months)
 651              {
 652                  $negative_6months++;
 653              }
 654          }
 655          // Neutral reputation given
 656          else
 657          {
 658              $neutral_count++;
 659              if($reputation_vote['dateline'] >= $last_week)
 660              {
 661                  $neutral_week++;
 662              }
 663              if($reputation_vote['dateline'] >= $last_month)
 664              {
 665                  $neutral_month++;
 666              }
 667              if($reputation_vote['dateline'] >= $last_6months)
 668              {
 669                  $neutral_6months++;
 670              }
 671          }
 672      }
 673  
 674      // Format the user's 'total' reputation
 675      if($user['reputation'] < 0)
 676      {
 677          $total_class = "_minus";
 678      }
 679      elseif($user['reputation'] > 0)
 680      {
 681          $total_class = "_plus";
 682      }
 683      else
 684      {
 685          $total_class = "_neutral";
 686      }
 687  
 688      // Figure out how many reps have come from posts / 'general'
 689      // Posts
 690      $query = $db->simple_select("reputation", "COUNT(rid) AS rep_posts", "uid = '".$user['uid']."' AND pid > 0");
 691      $rep_post_count = $db->fetch_field($query, "rep_posts");
 692      $rep_posts = my_number_format($rep_post_count);
 693  
 694      // General
 695      // We count how many reps in total, then subtract the reps from posts
 696      $rep_members = my_number_format($total_reputation - $rep_posts);
 697  
 698      // Is negative reputation disabled? If so, tell the user
 699      if($mybb->settings['negrep'] == 0)
 700      {
 701          $neg_rep_info = $lang->neg_rep_disabled;
 702      }
 703  
 704      if($mybb->settings['posrep'] == 0)
 705      {
 706          $pos_rep_info = $lang->pos_rep_disabled;
 707      }
 708  
 709      if($mybb->settings['neurep'] == 0)
 710      {
 711          $neu_rep_info = $lang->neu_rep_disabled;
 712      }
 713  
 714      // Check if we're browsing a specific page of results
 715      if(intval($mybb->input['page']) > 0)
 716      {
 717          $page = $mybb->input['page'];
 718          $start = ($page-1) *$mybb->settings['repsperpage'];
 719          $pages = $reputation_count / $mybb->settings['repsperpage'];
 720          $pages = ceil($pages);
 721          if($page > $pages)
 722          {
 723              $start = 0;
 724              $page = 1;
 725          }
 726      }
 727      else
 728      {
 729          $start = 0;
 730          $page = 1;
 731      }
 732  
 733      // Build out multipage navigation
 734      if($reputation_count > 0)
 735      {
 736          $multipage = multipage($reputation_count, $mybb->settings['repsperpage'], $page, "reputation.php?uid={$user['uid']}".$s_url);
 737      }
 738  
 739      // Fetch the reputations which will be displayed on this page
 740      $query = $db->query("
 741          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
 742          FROM ".TABLE_PREFIX."reputation r
 743          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=r.adduid)
 744          LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=r.pid)
 745          WHERE r.uid='{$user['uid']}' $conditions
 746          ORDER BY $order
 747          LIMIT $start, {$mybb->settings['repsperpage']}
 748      ");
 749      while($reputation_vote = $db->fetch_array($query))
 750      {
 751          // Get the reputation for the user who posted this comment
 752          if($reputation_vote['adduid'] == 0)
 753          {
 754              $reputation_vote['user_reputation'] = 0;
 755          }
 756  
 757          $reputation_vote['user_reputation'] = get_reputation($reputation_vote['user_reputation'], $reputation_vote['adduid']);
 758  
 759          // Format the username of this poster
 760          if(!$reputation_vote['username'])
 761          {
 762              $reputation_vote['username'] = $lang->na;
 763              $reputation_vote['user_reputation'] = '';
 764          }
 765          else
 766          {
 767              $reputation_vote['username'] = format_name($reputation_vote['username'], $reputation_vote['user_usergroup'], $reputation_vote['user_displaygroup']);
 768              $reputation_vote['username'] = build_profile_link($reputation_vote['username'], $reputation_vote['uid']);
 769              $reputation_vote['user_reputation'] = "({$reputation_vote['user_reputation']})";
 770          }
 771  
 772          $vote_reputation = intval($reputation_vote['reputation']);
 773  
 774          // This is a negative reputation
 775          if($vote_reputation < 0)
 776          {
 777              $status_class = "trow_reputation_negative";
 778              $vote_type_class = "reputation_negative";
 779              $vote_type = $lang->negative;
 780          }
 781          // This is a neutral reputation
 782          else if($vote_reputation == 0)
 783          {
 784              $status_class = "trow_reputation_neutral";
 785              $vote_type_class = "reputation_neutral";
 786              $vote_type = $lang->neutral;
 787          }
 788          // Otherwise, this is a positive reputation
 789          else
 790          {
 791              $vote_reputation = "+{$vote_reputation}";
 792              $status_class = "trow_reputation_positive";
 793              $vote_type_class = "reputation_positive";
 794              $vote_type = $lang->positive;
 795          }
 796  
 797          $vote_reputation = "({$vote_reputation})";
 798  
 799          // Format the date this reputation was last modified
 800          $last_updated_date = my_date($mybb->settings['dateformat'], $reputation_vote['dateline']);
 801          $last_updated_time = my_date($mybb->settings['timeformat'], $reputation_vote['dateline']);
 802          $last_updated = $lang->sprintf($lang->last_updated, $last_updated_date, $last_updated_time);
 803  
 804          // Is this rating specific to a post?
 805          if($reputation_vote['pid'] && $reputation_vote['post_link'])
 806          {
 807              $link = "<a href=\"".get_post_link($reputation_vote['pid'])."#pid{$reputation_vote['pid']}\">{$lang->postrep_post}".$reputation_vote['pid']."</a>";
 808              $postrep_given = $lang->sprintf($lang->postrep_given, $link);
 809          }
 810          else
 811          {
 812              $postrep_given = '';
 813          }
 814  
 815          // Does the current user have permission to delete this reputation? Show delete link
 816          if($mybb->usergroup['cancp'] == 1 || $mybb->usergroup['issupermod'] == 1 || ($mybb->usergroup['cangivereputations'] == 1 && $reputation_vote['adduid'] == $mybb->user['uid'] && $mybb->user['uid'] != 0))
 817          {
 818              $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>]";
 819          }
 820          else
 821          {
 822              $delete_link = '';
 823          }
 824  
 825          // Parse smilies in the reputation vote
 826          $reputation_parser = array(
 827              "allow_html" => 0,
 828              "allow_mycode" => 0,
 829              "allow_smilies" => 1,
 830              "allow_imgcode" => 0,
 831              "filter_badwords" => 1
 832          );
 833  
 834          $reputation_vote['comments'] = $parser->parse_message($reputation_vote['comments'], $reputation_parser);
 835          if($reputation_vote['comments'] == '')
 836          {
 837              $reputation_vote['comments'] = $lang->no_comment;
 838          }
 839          eval("\$reputation_votes .= \"".$templates->get("reputation_vote")."\";");
 840      }
 841  
 842      // If we don't have any reputations display a nice message.
 843      if(!$reputation_votes)
 844      {
 845          eval("\$reputation_votes = \"".$templates->get("reputation_no_votes")."\";");
 846      }
 847  
 848      $plugins->run_hooks("reputation_end");
 849      eval("\$reputation = \"".$templates->get("reputation")."\";");
 850      output_page($reputation);
 851  }
 852  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1