[ Index ]

PHP Cross Reference of MyBB 1.8.12

title

Body

[close]

/ -> reputation.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', 'reputation.php');
  13  
  14  $templatelist = "reputation_addlink,reputation_no_votes,reputation,reputation_vote,multipage,multipage_end,multipage_jump_page,multipage_nextpage,multipage_page,multipage_page_current,multipage_page_link_current,multipage_prevpage,multipage_start,reputation_vote_delete";
  15  $templatelist .= ",reputation_add_delete,reputation_add_neutral,reputation_add_positive,reputation_add_negative,reputation_add_error,reputation_add_error_nomodal,reputation_add,reputation_added,reputation_deleted,reputation_vote_report,postbit_reputation_formatted_link";
  16  
  17  require_once  "./global.php";
  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 = $mybb->get_input('uid', MyBB::INPUT_INT);
  40  $user = get_user($uid);
  41  if(!$user)
  42  {
  43      error($lang->add_no_uid);
  44  }
  45  $user_permissions = user_permissions($uid);
  46  
  47  $mybb->input['action'] = $mybb->get_input('action');
  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          if($mybb->input['nomodal'])
  58          {
  59              eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
  60          }
  61          else
  62          {
  63              eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
  64          }
  65          echo $error;
  66          exit;
  67      }
  68  
  69      // The user we're trying to give a reputation to doesn't have permission to receive reps.
  70      if($user_permissions['usereputationsystem'] != 1)
  71      {
  72          $message = $lang->add_disabled;
  73          if($mybb->input['nomodal'])
  74          {
  75              eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
  76          }
  77          else
  78          {
  79              eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
  80          }
  81          echo $error;
  82          exit;
  83      }
  84  
  85      // Is this user trying to give themself a reputation?
  86      if($uid == $mybb->user['uid'])
  87      {
  88          $message = $lang->add_yours;
  89          if($mybb->input['nomodal'])
  90          {
  91              eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
  92          }
  93          else
  94          {
  95              eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
  96          }
  97          echo $error;
  98          exit;
  99      }
 100  
 101      // 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.
 102      if($mybb->settings['postrep'] != 1)
 103      {
 104          $mybb->input['pid'] = 0;
 105      }
 106  
 107      if($mybb->get_input('pid', MyBB::INPUT_INT))
 108      {
 109          // 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.
 110          $post = get_post($mybb->get_input('pid', MyBB::INPUT_INT));
 111          if($post)
 112          {
 113              $thread = get_thread($post['tid']);
 114              $forum = get_forum($thread['fid']);
 115              $forumpermissions = forum_permissions($forum['fid']);
 116  
 117              // Post doesn't belong to that user or isn't visible
 118              if($uid != $post['uid'] || $post['visible'] != 1)
 119              {
 120                  $mybb->input['pid'] = 0;
 121              }
 122  
 123              // Thread isn't visible
 124              elseif($thread['visible'] != 1)
 125              {
 126                  $mybb->input['pid'] = 0;
 127              }
 128  
 129              // Current user can't see the forum
 130              elseif($forumpermissions['canview'] == 0 || $forumpermissions['canpostreplys'] == 0 || $mybb->user['suspendposting'] == 1)
 131              {
 132                  $mybb->input['pid'] = 0;
 133              }
 134  
 135              // Current user can't see that thread
 136              elseif(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
 137              {
 138                  $mybb->input['pid'] = 0;
 139              }
 140          }
 141          else
 142          {
 143              $mybb->input['pid'] = 0;
 144          }
 145      }
 146  
 147      $rid = 0;
 148  
 149      // Fetch the existing reputation for this user given by our current user if there is one.
 150      // If multiple reputations is allowed, then this isn't needed
 151      if($mybb->settings['multirep'] != 1 && $mybb->get_input('pid', MyBB::INPUT_INT) == 0)
 152      {
 153          $query = $db->simple_select("reputation", "*", "adduid='".$mybb->user['uid']."' AND uid='{$uid}' AND pid='0'");
 154          $existing_reputation = $db->fetch_array($query);
 155          $rid = $existing_reputation['rid'];
 156          $was_post = false;
 157      }
 158      if($mybb->get_input('pid', MyBB::INPUT_INT) != 0)
 159      {
 160          $query = $db->simple_select("reputation", "*", "adduid='".$mybb->user['uid']."' AND uid='{$uid}' AND pid = '".$mybb->get_input('pid', MyBB::INPUT_INT)."'");
 161          $existing_reputation = $db->fetch_array($query);
 162          $rid = $existing_reputation['rid'];
 163          $was_post = true;
 164      }
 165  
 166      if($rid == 0 && ($mybb->input['action'] != "do_add" || ($mybb->input['action'] == "do_add" && empty($mybb->input['delete']))))
 167      {
 168          $message = '';
 169  
 170          // Check if this user has reached their "maximum reputations per day" quota
 171          if($mybb->usergroup['maxreputationsday'] != 0)
 172          {
 173              $timesearch = TIME_NOW - (60 * 60 * 24);
 174              $query = $db->simple_select("reputation", "*", "adduid='{$mybb->user['uid']}' AND dateline>'$timesearch'");
 175              $numtoday = $db->num_rows($query);
 176  
 177              // Reached the quota - error.
 178              if($numtoday >= $mybb->usergroup['maxreputationsday'])
 179              {
 180                  $message = $lang->add_maxperday;
 181              }
 182          }
 183  
 184          // Is the user giving too much reputation to another?
 185          if(!$message && $mybb->usergroup['maxreputationsperuser'] != 0)
 186          {
 187              $timesearch = TIME_NOW - (60 * 60 * 24);
 188              $query = $db->simple_select("reputation", "*", "uid='{$uid}' AND adduid='{$mybb->user['uid']}' AND dateline>'$timesearch'");
 189              $numtoday = $db->num_rows($query);
 190  
 191              if($numtoday >= $mybb->usergroup['maxreputationsperuser'])
 192              {
 193                  $message = $lang->add_maxperuser;
 194              }
 195          }
 196  
 197          // We have the correct post, but has the user given too much reputation to another in the same thread?
 198          if(!$message && $was_post && $mybb->usergroup['maxreputationsperthread'] != 0)
 199          {
 200              $timesearch = TIME_NOW - (60 * 60 * 24);
 201              $query = $db->query("
 202                  SELECT COUNT(p.pid) AS posts
 203                  FROM ".TABLE_PREFIX."reputation r
 204                  LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid = r.pid)
 205                  WHERE r.uid = '{$uid}' AND r.adduid = '{$mybb->user['uid']}' AND p.tid = '{$post['tid']}' AND r.dateline > '{$timesearch}'
 206              ");
 207  
 208              $numtoday = $db->fetch_field($query, 'posts');
 209  
 210              if($numtoday >= $mybb->usergroup['maxreputationsperthread'])
 211              {
 212                  $message = $lang->add_maxperthread;
 213              }
 214          }
 215  
 216          if($message)
 217          {
 218              if($mybb->input['nomodal'])
 219              {
 220                  eval('$error = "'.$templates->get("reputation_add_error_nomodal", 1, 0).'";');
 221              }
 222              else
 223              {
 224                  eval('$error = "'.$templates->get("reputation_add_error", 1, 0).'";');
 225              }
 226              echo $error;
 227              exit;
 228          }
 229      }
 230  }
 231  
 232  // Saving the new reputation
 233  if($mybb->input['action'] == "do_add" && $mybb->request_method == "post")
 234  {
 235      // Verify incoming POST request
 236      verify_post_check($mybb->get_input('my_post_key'));
 237  
 238      $plugins->run_hooks("reputation_do_add_start");
 239  
 240      // Check if the reputation power they're trying to give is within their "power limit"
 241      $reputation = abs($mybb->get_input('reputation', MyBB::INPUT_INT));
 242  
 243      // Deleting our current reputation of this user.
 244      if(!empty($mybb->input['delete']))
 245      {
 246          // Only administrators, super moderators, as well as users who gave a specifc vote can delete one.
 247          if($mybb->usergroup['issupermod'] != 1 && ($mybb->usergroup['candeletereputations'] != 1 || $existing_reputation['adduid'] != $mybb->user['uid'] || $mybb->user['uid'] == 0))
 248          {
 249              error_no_permission();
 250          }
 251  
 252          if($mybb->get_input('pid', MyBB::INPUT_INT) != 0)
 253          {
 254              $db->delete_query("reputation", "uid='{$uid}' AND adduid='".$mybb->user['uid']."' AND pid = '".$mybb->get_input('pid', MyBB::INPUT_INT)."'");
 255          }
 256          else
 257          {
 258              $db->delete_query("reputation", "rid='{$rid}' AND uid='{$uid}' AND adduid='".$mybb->user['uid']."'");
 259          }
 260  
 261          // Recount the reputation of this user - keep it in sync.
 262          $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 263          $reputation_value = $db->fetch_field($query, "reputation_count");
 264  
 265          $db->update_query("users", array('reputation' => (int)$reputation_value), "uid='{$uid}'");
 266          eval("\$error = \"".$templates->get("reputation_deleted", 1, 0)."\";");
 267          echo $error;
 268          exit;
 269      }
 270  
 271      $mybb->input['comments'] = trim($mybb->get_input('comments')); // Trim whitespace to check for length
 272      if(my_strlen($mybb->input['comments']) < $mybb->settings['minreplength'] && $mybb->get_input('pid', MyBB::INPUT_INT) == 0)
 273      {
 274          $message = $lang->add_no_comment;
 275          if($mybb->input['nomodal'])
 276          {
 277              eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
 278          }
 279          else
 280          {
 281              eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
 282          }
 283          echo $error;
 284          exit;
 285      }
 286  
 287      // The power for the reputation they specified was invalid.
 288      if($reputation > $mybb->usergroup['reputationpower'])
 289      {
 290          $message = $lang->add_invalidpower;
 291          if($mybb->input['nomodal'])
 292          {
 293              eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
 294          }
 295          else
 296          {
 297              eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
 298          }
 299          echo $error;
 300          exit;
 301      }
 302  
 303      // The user is trying to give a negative reputation, but negative reps have been disabled.
 304      if($mybb->get_input('reputation', MyBB::INPUT_INT) < 0 && $mybb->settings['negrep'] != 1)
 305      {
 306          $message = $lang->add_negative_disabled;
 307          if($mybb->input['nomodal'])
 308          {
 309              eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
 310          }
 311          else
 312          {
 313              eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
 314          }
 315          echo $error;
 316          exit;
 317      }
 318  
 319      // This user is trying to give a neutral reputation, but neutral reps have been disabled.
 320      if($mybb->get_input('reputation', MyBB::INPUT_INT) == 0 && $mybb->settings['neurep'] != 1)
 321      {
 322          $message = $lang->add_neutral_disabled;
 323          if($mybb->input['nomodal'])
 324          {
 325              eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
 326          }
 327          else
 328          {
 329              eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
 330          }
 331          echo $error;
 332          exit;
 333      }
 334  
 335      // This user is trying to give a positive reputation, but positive reps have been disabled.
 336      if($mybb->get_input('reputation', MyBB::INPUT_INT) > 0 && $mybb->settings['posrep'] != 1)
 337      {
 338          $message = $lang->add_positive_disabled;
 339          if($mybb->input['nomodal'])
 340          {
 341              eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
 342          }
 343          else
 344          {
 345              eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
 346          }
 347          echo $error;
 348          exit;
 349      }
 350  
 351      // The length of the comment is too long
 352      if(my_strlen($mybb->input['comments']) > $mybb->settings['maxreplength'])
 353      {
 354          $message = $lang->sprintf($lang->add_toolong, $mybb->settings['maxreplength']);
 355          if($mybb->input['nomodal'])
 356          {
 357              eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
 358          }
 359          else
 360          {
 361              eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
 362          }
 363          echo $error;
 364          exit;
 365      }
 366  
 367      // Build array of reputation data.
 368      $reputation = array(
 369          "uid" => $uid,
 370          "adduid" => $mybb->user['uid'],
 371          "pid" => $mybb->get_input('pid', MyBB::INPUT_INT),
 372          "reputation" => $mybb->get_input('reputation', MyBB::INPUT_INT),
 373          "dateline" => TIME_NOW,
 374          "comments" => $db->escape_string($mybb->input['comments'])
 375      );
 376  
 377      $plugins->run_hooks("reputation_do_add_process");
 378  
 379      // Updating an existing reputation
 380      if(!empty($existing_reputation['uid']))
 381      {
 382          $db->update_query("reputation", $reputation, "rid='".$existing_reputation['rid']."'");
 383  
 384          // Recount the reputation of this user - keep it in sync.
 385          $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 386          $reputation_value = $db->fetch_field($query, "reputation_count");
 387  
 388          $db->update_query("users", array('reputation' => (int)$reputation_value), "uid='{$uid}'");
 389  
 390          $lang->vote_added = $lang->vote_updated;
 391          $lang->vote_added_message = $lang->vote_updated_message;
 392      }
 393      // Insert a new reputation
 394      else
 395      {
 396          $db->insert_query("reputation", $reputation);
 397  
 398          // Recount the reputation of this user - keep it in sync.
 399          $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 400          $reputation_value = $db->fetch_field($query, "reputation_count");
 401  
 402          $db->update_query("users", array('reputation' => (int)$reputation_value), "uid='{$uid}'");
 403      }
 404  
 405      $plugins->run_hooks("reputation_do_add_end");
 406  
 407      eval("\$reputation = \"".$templates->get("reputation_added", 1, 0)."\";");
 408      echo $reputation;
 409      exit;
 410  }
 411  
 412  // Adding a new reputation
 413  if($mybb->input['action'] == "add")
 414  {
 415      $plugins->run_hooks("reputation_add_start");
 416  
 417      // If we have an existing reputation for this user, the user can modify or delete it.
 418      $user['username'] = htmlspecialchars_uni($user['username']);
 419      if(!empty($existing_reputation['uid']))
 420      {
 421          $vote_title = $lang->sprintf($lang->update_reputation_vote, $user['username']);
 422          $vote_button = $lang->update_vote;
 423          $comments = htmlspecialchars_uni($existing_reputation['comments']);
 424  
 425          if($mybb->usergroup['issupermod'] == 1 || ($mybb->usergroup['candeletereputations'] == 1 && $existing_reputation['adduid'] == $mybb->user['uid'] && $mybb->user['uid'] != 0))
 426          {
 427              eval("\$delete_button = \"".$templates->get("reputation_add_delete")."\";");
 428          }
 429      }
 430      // Otherwise we're adding an entirely new reputation for this user.
 431      else
 432      {
 433          $vote_title = $lang->sprintf($lang->add_reputation_vote, $user['username']);
 434          $vote_button = $lang->add_vote;
 435          $comments = '';
 436          $delete_button = '';
 437      }
 438      $lang->user_comments = $lang->sprintf($lang->user_comments, $user['username']);
 439  
 440      if($mybb->get_input('pid', MyBB::INPUT_INT))
 441      {
 442          $post_rep_info = $lang->sprintf($lang->add_reputation_to_post, $user['username']);
 443          $lang->user_comments = $lang->no_comment_needed;
 444      }
 445      else
 446      {
 447          $post_rep_info = '';
 448      }
 449  
 450      // Draw the "power" options
 451      if($mybb->settings['negrep'] || $mybb->settings['neurep'] || $mybb->settings['posrep'])
 452      {
 453          $vote_check = array();
 454          $positive_power = '';
 455          $negative_power = '';
 456          $reputationpower = (int)$mybb->usergroup['reputationpower'];
 457  
 458          foreach(range(-$mybb->usergroup['reputationpower'], $mybb->usergroup['reputationpower']) as $value)
 459          {
 460              $vote_check[$value] = '';
 461          }
 462  
 463          if(!empty($existing_reputation['uid']) && !$was_post)
 464          {
 465              $vote_check[$existing_reputation['reputation']] = " selected=\"selected\"";
 466          }
 467  
 468          if($mybb->settings['neurep'])
 469          {
 470              $neutral_title = $lang->power_neutral;
 471              eval("\$neutral_power = \"".$templates->get("reputation_add_neutral")."\";");
 472          }
 473  
 474          for($value = 1; $value <= $reputationpower; ++$value)
 475          {
 476              if($mybb->settings['posrep'])
 477              {
 478                  $positive_title = $lang->sprintf($lang->power_positive, "+".$value);
 479                  eval("\$positive_power = \"".$templates->get("reputation_add_positive")."\";");
 480              }
 481  
 482              if($mybb->settings['negrep'])
 483              {
 484                  $negative_title = $lang->sprintf($lang->power_negative, "-".$value);
 485                  $neg_value = "-{$value}";
 486                  eval("\$negative_power .= \"".$templates->get("reputation_add_negative")."\";");
 487              }
 488          }
 489  
 490          $mybb->input['pid'] = $mybb->get_input('pid', MyBB::INPUT_INT);
 491  
 492          $plugins->run_hooks("reputation_add_end");
 493          eval("\$reputation_add = \"".$templates->get("reputation_add", 1, 0)."\";");
 494      }
 495      else
 496      {
 497          $message = $lang->add_all_rep_disabled;
 498  
 499          $plugins->run_hooks("reputation_add_end_error");
 500          if($mybb->input['nomodal'])
 501          {
 502              eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
 503          }
 504          else
 505          {
 506              eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
 507          }
 508      }
 509  
 510      echo $reputation_add;
 511      exit;
 512  }
 513  
 514  // Delete a specific reputation from a user.
 515  if($mybb->input['action'] == "delete")
 516  {
 517      // Verify incoming POST request
 518      verify_post_check($mybb->get_input('my_post_key'));
 519  
 520      // Fetch the existing reputation for this user given by our current user if there is one.
 521      $query = $db->query("
 522          SELECT r.*, u.username
 523          FROM ".TABLE_PREFIX."reputation r
 524          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=r.adduid)
 525          WHERE rid = '".$mybb->get_input('rid', MyBB::INPUT_INT)."'
 526      ");
 527      $existing_reputation = $db->fetch_array($query);
 528  
 529      // Only administrators, super moderators, as well as users who gave a specifc vote can delete one.
 530      if($mybb->usergroup['issupermod'] != 1 && ($mybb->usergroup['candeletereputations'] != 1 || $existing_reputation['adduid'] != $mybb->user['uid'] || $mybb->user['uid'] == 0))
 531      {
 532          error_no_permission();
 533      }
 534  
 535      // Delete the specified reputation
 536      $db->delete_query("reputation", "uid='{$uid}' AND rid='".$mybb->get_input('rid', MyBB::INPUT_INT)."'");
 537  
 538      // Recount the reputation of this user - keep it in sync.
 539      $query = $db->simple_select("reputation", "SUM(reputation) AS reputation_count", "uid='{$uid}'");
 540      $reputation_value = $db->fetch_field($query, "reputation_count");
 541  
 542      // Create moderator log
 543      log_moderator_action(array("uid" => $user['uid'], "username" => $user['username']), $lang->sprintf($lang->delete_reputation_log, $existing_reputation['username'], $existing_reputation['adduid']));
 544  
 545      $db->update_query("users", array('reputation' => (int)$reputation_value), "uid='{$uid}'");
 546  
 547      redirect("reputation.php?uid={$uid}", $lang->vote_deleted_message);
 548  }
 549  
 550  // Otherwise, show a listing of reputations for the given user.
 551  if(!$mybb->input['action'])
 552  {
 553      if($mybb->usergroup['canviewprofiles'] == 0)
 554      {
 555          // Reputation page is a part of a profile
 556          error_no_permission();
 557      }
 558  
 559      // Set display group to their user group if they don't have a display group.
 560      if(!$user['displaygroup'])
 561      {
 562          $user['displaygroup'] = $user['usergroup'];
 563      }
 564  
 565      // Fetch display group properties.
 566      $displaygroupfields = array('title', 'description', 'namestyle', 'usertitle', 'stars', 'starimage', 'image', 'usereputationsystem');
 567      $display_group = usergroup_displaygroup($user['displaygroup']);
 568  
 569      if($user_permissions['usereputationsystem'] != 1 || $display_group['title'] && $display_group['usereputationsystem'] == 0)
 570      {
 571          // Group has reputation disabled or user has a display group that has reputation disabled
 572          error($lang->reputations_disabled_group);
 573      }
 574  
 575      $user['username'] = htmlspecialchars_uni($user['username']);
 576      $lang->nav_profile = $lang->sprintf($lang->nav_profile, $user['username']);
 577      $lang->reputation_report = $lang->sprintf($lang->reputation_report, $user['username']);
 578  
 579      // Format the user name using the group username style
 580      $username = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
 581  
 582      // Set display group to their user group if they don't have a display group.
 583      if(!$user['displaygroup'])
 584      {
 585          $user['displaygroup'] = $user['usergroup'];
 586      }
 587  
 588      $usertitle = '';
 589  
 590      // This user has a custom user title
 591      if(trim($user['usertitle']) != '')
 592      {
 593          $usertitle = $user['usertitle'];
 594      }
 595      // Using our display group's user title
 596      elseif(trim($display_group['usertitle']) != '')
 597      {
 598          $usertitle = $display_group['usertitle'];
 599      }
 600      // Otherwise, fetch it from our titles table for the number of posts this user has
 601      else
 602      {
 603          $usertitles = $cache->read('usertitles');
 604          foreach($usertitles as $title)
 605          {
 606              if($title['posts'] <= $user['postnum'])
 607              {
 608                  $usertitle = $title['title'];
 609                  break;
 610              }
 611          }
 612          unset($usertitles, $title);
 613      }
 614      
 615      $usertitle = htmlspecialchars_uni($usertitle);
 616  
 617      // If the user has permission to add reputations - show the image
 618      if($mybb->usergroup['cangivereputations'] == 1 && $mybb->user['uid'] != $user['uid'] && ($mybb->settings['posrep'] || $mybb->settings['neurep'] || $mybb->settings['negrep']))
 619      {
 620          eval("\$add_reputation = \"".$templates->get("reputation_addlink")."\";");
 621      }
 622      else
 623      {
 624          $add_reputation = '';
 625      }
 626  
 627      // Build navigation menu
 628      add_breadcrumb($lang->nav_profile, get_profile_link($user['uid']));
 629      add_breadcrumb($lang->nav_reputation);
 630  
 631      // Check our specified conditionals for what type of reputations to show
 632      $show_selected = array('all' => '', 'positive' => '', 'neutral' => '', 'negative' => '');
 633      switch($mybb->get_input('show'))
 634      {
 635          case "positive":
 636              $s_url = "&show=positive";
 637              $conditions = 'AND r.reputation>0';
 638              $show_selected['positive'] = 'selected="selected"';
 639              break;
 640          case "neutral":
 641              $s_url = "&show=neutral";
 642              $conditions = 'AND r.reputation=0';
 643              $show_selected['neutral'] = 'selected="selected"';
 644              break;
 645          case "negative":
 646              $s_url = "&show=negative";
 647              $conditions = 'AND r.reputation<0';
 648              $show_selected['negative'] = 'selected="selected"';
 649              break;
 650          default:
 651              $s_url = '&show=all';
 652              $conditions = '';
 653              $show_select['all'] = 'selected="selected"';
 654              break;
 655      }
 656  
 657      // Check the sorting options for the reputation list
 658      $sort_selected = array('username' => '', 'last_ipdated' => '');
 659      switch($mybb->get_input('sort'))
 660      {
 661          case "username":
 662              $s_url .= "&sort=username";
 663              $order = "u.username ASC";
 664              $sort_selected['username'] = 'selected="selected"';
 665              break;
 666          default:
 667              $s_url .= '&sort=dateline';
 668              $order = "r.dateline DESC";
 669              $sort_selected['last_updated'] = 'selected="selected"';
 670              break;
 671      }
 672  
 673      if(empty($mybb->input['show']) && empty($mybb->input['sort']))
 674      {
 675          $s_url = '';
 676      }
 677  
 678      // Fetch the total number of reputations for this user
 679      $query = $db->simple_select("reputation r", "COUNT(r.rid) AS reputation_count", "r.uid='{$user['uid']}' $conditions");
 680      $reputation_count = $db->fetch_field($query, "reputation_count");
 681  
 682      // If the user has no reputation, suspect 0...
 683      if(!$user['reputation'])
 684      {
 685          $user['reputation'] = 0;
 686      }
 687  
 688      // Quickly check to see if we're in sync...
 689      $query = $db->simple_select("reputation", "SUM(reputation) AS reputation, COUNT(rid) AS total_reputation", "uid = '".$user['uid']."'");
 690      $reputation = $db->fetch_array($query);
 691  
 692      $sync_reputation = (int)$reputation['reputation'];
 693      $total_reputation = $reputation['total_reputation'];
 694  
 695      if($sync_reputation != $user['reputation'])
 696      {
 697          // We're out of sync! Oh noes!
 698          $db->update_query("users", array("reputation" => $sync_reputation), "uid = '".$user['uid']."'");
 699          $user['reputation'] = $sync_reputation;
 700      }
 701  
 702      // Set default count variables to 0
 703      $positive_count = $negative_count = $neutral_count = 0;
 704      $positive_week = $negative_week = $neutral_week = 0;
 705      $positive_month = $negative_month = $neutral_month = 0;
 706      $positive_6months = $negative_6months = $neutral_6months = 0;
 707  
 708      // Unix timestamps for when this week, month and last 6 months started
 709      $last_week = TIME_NOW-604800;
 710      $last_month = TIME_NOW-2678400;
 711      $last_6months = TIME_NOW-16070400;
 712  
 713      // Query reputations for the "reputation card"
 714      $query = $db->simple_select("reputation", "reputation, dateline", "uid='{$user['uid']}'");
 715      while($reputation_vote = $db->fetch_array($query))
 716      {
 717          // This is a positive reputation
 718          if($reputation_vote['reputation'] > 0)
 719          {
 720              $positive_count++;
 721              if($reputation_vote['dateline'] >= $last_week)
 722              {
 723                  $positive_week++;
 724              }
 725              if($reputation_vote['dateline'] >= $last_month)
 726              {
 727                  $positive_month++;
 728              }
 729              if($reputation_vote['dateline'] >= $last_6months)
 730              {
 731                  $positive_6months++;
 732              }
 733          }
 734          // Negative reputation given
 735          else if($reputation_vote['reputation'] < 0)
 736          {
 737              $negative_count++;
 738              if($reputation_vote['dateline'] >= $last_week)
 739              {
 740                  $negative_week++;
 741              }
 742              if($reputation_vote['dateline'] >= $last_month)
 743              {
 744                  $negative_month++;
 745              }
 746              if($reputation_vote['dateline'] >= $last_6months)
 747              {
 748                  $negative_6months++;
 749              }
 750          }
 751          // Neutral reputation given
 752          else
 753          {
 754              $neutral_count++;
 755              if($reputation_vote['dateline'] >= $last_week)
 756              {
 757                  $neutral_week++;
 758              }
 759              if($reputation_vote['dateline'] >= $last_month)
 760              {
 761                  $neutral_month++;
 762              }
 763              if($reputation_vote['dateline'] >= $last_6months)
 764              {
 765                  $neutral_6months++;
 766              }
 767          }
 768      }
 769      
 770      // Format all reputation numbers
 771      $rep_total = my_number_format($user['reputation']);
 772      $f_positive_count = my_number_format($positive_count);
 773      $f_negative_count = my_number_format($negative_count);
 774      $f_neutral_count = my_number_format($neutral_count);
 775      $f_positive_week = my_number_format($positive_week);
 776      $f_negative_week = my_number_format($negative_week);
 777      $f_neutral_week = my_number_format($neutral_week);
 778      $f_positive_month = my_number_format($positive_month);
 779      $f_negative_month = my_number_format($negative_month);
 780      $f_neutral_month = my_number_format($neutral_month);
 781      $f_positive_6months = my_number_format($positive_6months);
 782      $f_negative_6months = my_number_format($negative_6months);
 783      $f_neutral_6months = my_number_format($neutral_6months);
 784      
 785      // Format the user's 'total' reputation
 786      if($user['reputation'] < 0)
 787      {
 788          $total_class = "_minus";
 789      }
 790      elseif($user['reputation'] > 0)
 791      {
 792          $total_class = "_plus";
 793      }
 794      else
 795      {
 796          $total_class = "_neutral";
 797      }
 798  
 799      // Figure out how many reps have come from posts / 'general'
 800      // Posts
 801      $query = $db->simple_select("reputation", "COUNT(rid) AS rep_posts", "uid = '".$user['uid']."' AND pid > 0");
 802      $rep_post_count = $db->fetch_field($query, "rep_posts");
 803      $rep_posts = my_number_format($rep_post_count);
 804  
 805      // General
 806      // We count how many reps in total, then subtract the reps from posts
 807      $rep_members = my_number_format($total_reputation - $rep_post_count);
 808  
 809      // Is negative reputation disabled? If so, tell the user
 810      if($mybb->settings['negrep'] == 0)
 811      {
 812          $neg_rep_info = $lang->neg_rep_disabled;
 813      }
 814  
 815      if($mybb->settings['posrep'] == 0)
 816      {
 817          $pos_rep_info = $lang->pos_rep_disabled;
 818      }
 819  
 820      if($mybb->settings['neurep'] == 0)
 821      {
 822          $neu_rep_info = $lang->neu_rep_disabled;
 823      }
 824  
 825      $perpage = (int)$mybb->settings['repsperpage'];
 826      if($perpage < 1)
 827      {
 828          $perpage = 15;
 829      }
 830  
 831      // Check if we're browsing a specific page of results
 832      if($mybb->get_input('page', MyBB::INPUT_INT) > 0)
 833      {
 834          $page = $mybb->get_input('page', MyBB::INPUT_INT);
 835          $start = ($page-1) * $perpage;
 836          $pages = $reputation_count / $perpage;
 837          $pages = ceil($pages);
 838          if($page > $pages)
 839          {
 840              $start = 0;
 841              $page = 1;
 842          }
 843      }
 844      else
 845      {
 846          $start = 0;
 847          $page = 1;
 848      }
 849  
 850      $multipage = '';
 851  
 852      // Build out multipage navigation
 853      if($reputation_count > 0)
 854      {
 855          $multipage = multipage($reputation_count, $perpage, $page, "reputation.php?uid={$user['uid']}".$s_url);
 856      }
 857  
 858      // Fetch the reputations which will be displayed on this page
 859      $query = $db->query("
 860          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
 861          FROM ".TABLE_PREFIX."reputation r
 862          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=r.adduid)
 863          WHERE r.uid='{$user['uid']}' $conditions
 864          ORDER BY $order
 865          LIMIT $start, {$perpage}
 866      ");
 867  
 868      // Gather a list of items that have post reputation
 869      $reputation_cache = $post_cache = $post_reputation = array();
 870  
 871      while($reputation_vote = $db->fetch_array($query))
 872      {
 873          $reputation_cache[] = $reputation_vote;
 874  
 875          // If this is a post, hold it and gather some information about it
 876          if($reputation_vote['pid'] && !isset($post_cache[$reputation_vote['pid']]))
 877          {
 878              $post_cache[$reputation_vote['pid']] = $reputation_vote['pid'];
 879          }
 880      }
 881  
 882      if(!empty($post_cache))
 883      {
 884          $pids = implode(',', $post_cache);
 885  
 886          $sql = array("p.pid IN ({$pids})");
 887  
 888          // get forums user cannot view
 889          $unviewable = get_unviewable_forums(true);
 890          if($unviewable)
 891          {
 892              $sql[] = "p.fid NOT IN ({$unviewable})";
 893          }
 894  
 895          // get inactive forums
 896          $inactive = get_inactive_forums();
 897          if($inactive)
 898          {
 899              $sql[] = "p.fid NOT IN ({$inactive})";
 900          }
 901  
 902          if(!$mybb->user['ismoderator'])
 903          {
 904              $sql[] = "p.visible='1'";
 905              $sql[] = "t.visible='1'";
 906          }
 907  
 908          $sql = implode(' AND ', $sql);
 909  
 910          $query = $db->query("
 911              SELECT p.pid, p.uid, p.fid, p.visible, p.message, t.tid, t.subject, t.visible AS thread_visible
 912              FROM ".TABLE_PREFIX."posts p
 913              LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
 914              WHERE {$sql}
 915          ");
 916  
 917          $forumpermissions = array();
 918  
 919          while($post = $db->fetch_array($query))
 920          {
 921              if(($post['visible'] == 0 || $post['thread_visible'] == 0) && !is_moderator($post['fid'], 'canviewunapprove'))
 922              {
 923                  continue;
 924              }
 925  
 926              if(($post['visible'] == -1 || $post['thread_visible'] == -1) && !is_moderator($post['fid'], 'canviewdeleted'))
 927              {
 928                  continue;
 929              }
 930  
 931              if(!isset($forumpermissions[$post['fid']]))
 932              {
 933                  $forumpermissions[$post['fid']] = forum_permissions($post['fid']);
 934              }
 935  
 936              // Make sure we can view this post
 937              if(isset($forumpermissions[$post['fid']]['canonlyviewownthreads']) && $forumpermissions[$post['fid']]['canonlyviewownthreads'] == 1 && $post['uid'] != $mybb->user['uid'])
 938              {
 939                  continue;
 940              }
 941  
 942              $post_reputation[$post['pid']] = $post;
 943          }
 944      }
 945  
 946      $reputation_votes = '';
 947  
 948      foreach($reputation_cache as $reputation_vote)
 949      {
 950          // Get the reputation for the user who posted this comment
 951          if($reputation_vote['adduid'] == 0)
 952          {
 953              $reputation_vote['user_reputation'] = 0;
 954          }
 955  
 956          $reputation_vote['user_reputation'] = get_reputation($reputation_vote['user_reputation'], $reputation_vote['adduid']);
 957  
 958          // Format the username of this poster
 959          if(!$reputation_vote['username'])
 960          {
 961              $reputation_vote['username'] = $lang->na;
 962              $reputation_vote['user_reputation'] = '';
 963          }
 964          else
 965          {
 966              $reputation_vote['username'] = format_name(htmlspecialchars_uni($reputation_vote['username']), $reputation_vote['user_usergroup'], $reputation_vote['user_displaygroup']);
 967              $reputation_vote['username'] = build_profile_link($reputation_vote['username'], $reputation_vote['uid']);
 968              $reputation_vote['user_reputation'] = "({$reputation_vote['user_reputation']})";
 969          }
 970  
 971          $vote_reputation = (int)$reputation_vote['reputation'];
 972  
 973          // This is a negative reputation
 974          if($vote_reputation < 0)
 975          {
 976              $status_class = "trow_reputation_negative";
 977              $vote_type_class = "reputation_negative";
 978              $vote_type = $lang->negative;
 979          }
 980          // This is a neutral reputation
 981          else if($vote_reputation == 0)
 982          {
 983              $status_class = "trow_reputation_neutral";
 984              $vote_type_class = "reputation_neutral";
 985              $vote_type = $lang->neutral;
 986          }
 987          // Otherwise, this is a positive reputation
 988          else
 989          {
 990              $vote_reputation = "+{$vote_reputation}";
 991              $status_class = "trow_reputation_positive";
 992              $vote_type_class = "reputation_positive";
 993              $vote_type = $lang->positive;
 994          }
 995  
 996          $vote_reputation = "({$vote_reputation})";
 997  
 998          // Format the date this reputation was last modified
 999          $last_updated_date = my_date('relative', $reputation_vote['dateline']);
1000          $last_updated = $lang->sprintf($lang->last_updated, $last_updated_date);
1001  
1002          $user['username'] = htmlspecialchars_uni($user['username']);
1003  
1004          // Is this rating specific to a post?
1005          $postrep_given = '';
1006          if($reputation_vote['pid'])
1007          {
1008              $postrep_given = $lang->sprintf($lang->postrep_given_nolink, $user['username']);
1009              if(isset($post_reputation[$reputation_vote['pid']]))
1010              {
1011                  $thread_link = get_thread_link($post_reputation[$reputation_vote['pid']]['tid']);
1012                  $subject = htmlspecialchars_uni($parser->parse_badwords($post_reputation[$reputation_vote['pid']]['subject']));
1013  
1014                  $thread_link = $lang->sprintf($lang->postrep_given_thread, $thread_link, $subject);
1015                  $link = get_post_link($reputation_vote['pid'])."#pid{$reputation_vote['pid']}";
1016  
1017                  $postrep_given = $lang->sprintf($lang->postrep_given, $link, $user['username'], $thread_link);
1018              }
1019          }
1020  
1021          // Does the current user have permission to delete this reputation? Show delete link
1022          $delete_link = '';
1023          if($mybb->usergroup['issupermod'] == 1 || ($mybb->usergroup['candeletereputations'] == 1 && $reputation_vote['adduid'] == $mybb->user['uid'] && $mybb->user['uid'] != 0))
1024          {
1025              eval("\$delete_link = \"".$templates->get("reputation_vote_delete")."\";");
1026          }
1027  
1028          $report_link = '';
1029          if($mybb->user['uid'] != 0)
1030          {
1031              eval("\$report_link = \"".$templates->get("reputation_vote_report")."\";");
1032          }
1033  
1034          // Parse smilies in the reputation vote
1035          $reputation_parser = array(
1036              "allow_html" => 0,
1037              "allow_mycode" => 0,
1038              "allow_smilies" => 1,
1039              "allow_imgcode" => 0,
1040              "filter_badwords" => 1
1041          );
1042  
1043          $reputation_vote['comments'] = $parser->parse_message($reputation_vote['comments'], $reputation_parser);
1044          if($reputation_vote['comments'] == '')
1045          {
1046              $reputation_vote['comments'] = $lang->no_comment;
1047          }
1048  
1049          $plugins->run_hooks("reputation_vote");
1050  
1051          eval("\$reputation_votes .= \"".$templates->get("reputation_vote")."\";");
1052      }
1053  
1054      // If we don't have any reputations display a nice message.
1055      if(!$reputation_votes)
1056      {
1057          eval("\$reputation_votes = \"".$templates->get("reputation_no_votes")."\";");
1058      }
1059  
1060      $plugins->run_hooks("reputation_end");
1061      eval("\$reputation = \"".$templates->get("reputation")."\";");
1062      output_page($reputation);
1063  }


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