-
Notifications
You must be signed in to change notification settings - Fork 1
/
threadrate.php
250 lines (215 loc) · 8.58 KB
/
threadrate.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
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.2.0 Patch Level 3 - Licence Number VBFBED0615
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2012 vBulletin Solutions Inc. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'threadrate');
define('CSRF_PROTECTION', true);
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array('showthread');
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array();
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
$vbulletin->input->clean_array_gpc('p', array(
'vote' => TYPE_UINT,
'pagenumber' => TYPE_UINT,
'perpage' => TYPE_UINT,
'ajax' => TYPE_BOOL,
));
if ($vbulletin->GPC['vote'] < 1 OR $vbulletin->GPC['vote'] > 5)
{
eval(standard_error(fetch_error('invalidvote')));
}
if (!$threadinfo['threadid'] OR (!$threadinfo['visible'] AND !can_moderate($threadinfo['forumid'], 'canmoderateposts')) OR (!$threadinfo['open'] AND !can_moderate($threadinfo['forumid'], 'canopenclose')) OR ($threadinfo['isdeleted'] AND !can_moderate($threadinfo['forumid'], 'candeleteposts')))
{
eval(standard_error(fetch_error('threadrateclosed')));
}
$forumperms = fetch_permissions($threadinfo['forumid']);
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canthreadrate']) OR (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) AND ($threadinfo['postuserid'] != $vbulletin->userinfo['userid'])))
{
print_no_permission();
}
// check if there is a forum password and if so, ensure the user has it set
verify_forum_password($foruminfo['forumid'], $foruminfo['password']);
$rated = intval(fetch_bbarray_cookie('thread_rate', $threadinfo['threadid']));
($hook = vBulletinHook::fetch_hook('threadrate_start')) ? eval($hook) : false;
$update = false;
if ($vbulletin->userinfo['userid'])
{
if ($rating = $db->query_first("
SELECT *
FROM " . TABLE_PREFIX . "threadrate
WHERE userid = " . $vbulletin->userinfo['userid'] . "
AND threadid = $threadinfo[threadid]
"))
{
if ($vbulletin->options['votechange'])
{
if ($vbulletin->GPC['vote'] != $rating['vote'])
{
$threadrate =& datamanager_init('ThreadRate', $vbulletin, ERRTYPE_STANDARD);
$threadrate->set_info('thread', $threadinfo);
$threadrate->set_existing($rating);
$threadrate->set('vote', $vbulletin->GPC['vote']);
($hook = vBulletinHook::fetch_hook('threadrate_update')) ? eval($hook) : false;
$threadrate->save();
}
$update = true;
if (!$vbulletin->GPC['ajax'])
{
$vbulletin->url = fetch_seo_url('thread', $threadinfo, array('page' => $vbulletin->GPC['pagenumber'], 'pp' => $vbulletin->GPC['perpage']));
print_standard_redirect('redirect_threadrate_update');
}
}
else if (!$vbulletin->GPC['ajax'])
{
eval(standard_error(fetch_error('threadratevoted')));
}
}
else
{
$threadrate =& datamanager_init('ThreadRate', $vbulletin, ERRTYPE_STANDARD);
$threadrate->set_info('thread', $threadinfo);
$threadrate->set('threadid', $threadinfo['threadid']);
$threadrate->set('userid', $vbulletin->userinfo['userid']);
$threadrate->set('vote', $vbulletin->GPC['vote']);
($hook = vBulletinHook::fetch_hook('threadrate_add')) ? eval($hook) : false;
$threadrate->save();
$update = true;
if (!$vbulletin->GPC['ajax'])
{
$vbulletin->url = fetch_seo_url('thread', $threadinfo, array('page' => $vbulletin->GPC['pagenumber'], 'pp' => $vbulletin->GPC['perpage']));
print_standard_redirect('redirect_threadrate_add');
}
}
}
else
{
// Check for cookie on user's computer for this threadid
if ($rated AND !$vbulletin->options['votechange'])
{
if (!$vbulletin->GPC['ajax'])
{
eval(standard_error(fetch_error('threadratevoted')));
}
}
else
{
// Check for entry in Database for this Ip Addr/Threadid
if ($rating = $db->query_first("
SELECT *
FROM " . TABLE_PREFIX . "threadrate
WHERE ipaddress = '" . $db->escape_string(IPADDRESS) . "'
AND threadid = $threadinfo[threadid]
"))
{
if ($vbulletin->options['votechange'])
{
if ($vbulletin->GPC['vote'] != $rating['vote'])
{
$threadrate =& datamanager_init('ThreadRate', $vbulletin, ERRTYPE_STANDARD);
$threadrate->set_info('thread', $threadinfo);
$threadrate->set_existing($rating);
$threadrate->set('vote', $vbulletin->GPC['vote']);
($hook = vBulletinHook::fetch_hook('threadrate_update')) ? eval($hook) : false;
$threadrate->save();
}
$update = true;
if (!$vbulletin->GPC['ajax'])
{
$vbulletin->url = fetch_seo_url('thread', $threadinfo, array('page' => $vbulletin->GPC['pagenumber'], 'pp' => $vbulletin->GPC['perpage']));
print_standard_redirect('redirect_threadrate_update');
}
}
else if (!$vbulletin->GPC['ajax'])
{
eval(standard_error(fetch_error('threadratevoted')));
}
}
else
{
$threadrate =& datamanager_init('ThreadRate', $vbulletin, ERRTYPE_STANDARD);
$threadrate->set_info('thread', $threadinfo);
$threadrate->set('threadid', $threadinfo['threadid']);
$threadrate->set('userid', 0);
$threadrate->set('vote', $vbulletin->GPC['vote']);
$threadrate->set('ipaddress', IPADDRESS);
($hook = vBulletinHook::fetch_hook('threadrate_add')) ? eval($hook) : false;
$threadrate->save();
$update = true;
if (!$vbulletin->GPC['ajax'])
{
$vbulletin->url = fetch_seo_url('thread', $threadinfo, array('page' => $vbulletin->GPC['pagenumber'], 'pp' => $vbulletin->GPC['perpage']));
print_standard_redirect('redirect_threadrate_add');
}
}
}
}
require_once(DIR . '/includes/class_xml.php');
$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
$xml->add_group('threadrating');
if ($update)
{
$thread = $db->query_first_slave("
SELECT votetotal, votenum
FROM " . TABLE_PREFIX . "thread
WHERE threadid = $threadinfo[threadid]
");
$average = $thread['votetotal'] / $thread['votenum'];
$rating = round($average);
$xml->add_tag('rating_full', vb_number_format($average, 2));
$xml->add_tag('rating', $rating);
$xml->add_tag('vote_threshold_met', intval($thread['votenum'] >= $vbulletin->options['showvotes']));
/*
//I don't think we need this any longer.
if ($thread['votenum'] >= $vbulletin->options['showvotes'])
{ // Show Voteavg
$thread['voteavg'] = vb_number_format($average, 2);
// $thread['rating'] = round($thread['votetotal'] / $thread['votenum']);
$html = "$vbphrase[rating]: <img class=\"inlineimg\" src=\"$stylevar[imgdir_rating]/rating_$rating.gif\" alt=\"" .
construct_phrase($vbphrase['thread_rating_x_votes_y_average'], $thread['votenum'],
$thread['voteavg']) . "\" border=\"0\" />";
$xml->add_tag('voteavg', process_replacement_vars($html));
}
else
{
$xml->add_tag('voteavg', '');
}
*/
if (!function_exists('fetch_phrase'))
{
require_once(DIR . '/includes/functions_misc.php');
}
$xml->add_tag('message', fetch_phrase('redirect_threadrate_add', 'frontredirect', 'redirect_'));
}
else // Already voted error...
{
$xml->add_tag('error', fetch_error('threadratevoted'));
}
$xml->close_group();
$xml->print_xml();
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 16:29, Sun Dec 9th 2012
|| # CVS: $RCSfile$ - $Revision: 50189 $
|| ####################################################################
\*======================================================================*/
?>