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