[ Index ]

PHP Cross Reference of MyBB 1.8.19

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


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