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