-
Notifications
You must be signed in to change notification settings - Fork 4
/
ratethread.php
executable file
·142 lines (127 loc) · 3.41 KB
/
ratethread.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
<?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', 'ratethread.php');
$templatelist = '';
require_once "./global.php";
// Verify incoming POST request
verify_post_check($mybb->input['my_post_key']);
$lang->load("ratethread");
$tid = intval($mybb->input['tid']);
$query = $db->simple_select("threads", "*", "tid='{$tid}'");
$thread = $db->fetch_array($query);
if(!$thread['tid'])
{
error($lang->error_invalidthread);
}
$forumpermissions = forum_permissions($thread['fid']);
if($forumpermissions['canview'] == 0 || $forumpermissions['canratethreads'] == 0 || $mybb->usergroup['canratethreads'] == 0 || $mybb->settings['allowthreadratings'] == 0)
{
error_no_permission();
}
// Get forum info
$fid = $thread['fid'];
$forum = get_forum($fid);
if(!$forum)
{
error($lang->error_invalidforum);
}
// Get forum info
$forum = get_forum($fid);
if(!$forum)
{
error($lang->error_invalidforum);
}
else
{
// Is our forum closed?
if($forum['open'] == 0)
{
// Doesn't look like it is
error($lang->error_closedinvalidforum);
}
}
// Check if this forum is password protected and we have a valid password
check_forum_password($forum['fid']);
if($forum['allowtratings'] == 0)
{
error_no_permission();
}
$mybb->input['rating'] = intval($mybb->input['rating']);
if($mybb->input['rating'] < 1 || $mybb->input['rating'] > 5)
{
error($lang->error_invalidrating);
}
$plugins->run_hooks("ratethread_start");
if($mybb->user['uid'] != 0)
{
$whereclause = "uid='{$mybb->user['uid']}'";
}
else
{
$whereclause = "ipaddress='".$db->escape_string($session->ipaddress)."'";
}
$query = $db->simple_select("threadratings", "*", "{$whereclause} AND tid='{$tid}'");
$ratecheck = $db->fetch_array($query);
if($ratecheck['rid'] || $mybb->cookies['mybbratethread'][$tid])
{
error($lang->error_alreadyratedthread);
}
else
{
$plugins->run_hooks("ratethread_process");
$db->write_query("
UPDATE ".TABLE_PREFIX."threads
SET numratings=numratings+1, totalratings=totalratings+'{$mybb->input['rating']}'
WHERE tid='{$tid}'
");
if($mybb->user['uid'] != 0)
{
$insertarray = array(
'tid' => $tid,
'uid' => $mybb->user['uid'],
'rating' => $mybb->input['rating'],
'ipaddress' => $db->escape_string($session->ipaddress)
);
$db->insert_query("threadratings", $insertarray);
}
else
{
$insertarray = array(
'tid' => $tid,
'rating' => $mybb->input['rating'],
'ipaddress' => $db->escape_string($session->ipaddress)
);
$db->insert_query("threadratings", $insertarray);
$time = TIME_NOW;
my_setcookie("mybbratethread[{$tid}]", $mybb->input['rating']);
}
}
$plugins->run_hooks("ratethread_end");
if($mybb->input['ajax'])
{
echo "<success>{$lang->rating_added}</success>\n";
$query = $db->simple_select("threads", "totalratings, numratings", "tid='$tid'", array('limit' => 1));
$fetch = $db->fetch_array($query);
$width = 0;
if($fetch['numratings'] >= 0)
{
$averagerating = floatval(round($fetch['totalratings']/$fetch['numratings'], 2));
$width = intval(round($averagerating))*20;
$fetch['numratings'] = intval($fetch['numratings']);
$ratingvotesav = $lang->sprintf($lang->rating_votes_average, $fetch['numratings'], $averagerating);
echo "<average>{$ratingvotesav}</average>\n";
}
echo "<width>{$width}</width>";
exit;
}
redirect(get_thread_link($thread['tid']), $lang->redirect_threadrated);
?>