-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadtag.php
More file actions
376 lines (317 loc) · 12.1 KB
/
threadtag.php
File metadata and controls
376 lines (317 loc) · 12.1 KB
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
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.8.9 - Licence Number VBFE810A2D
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2015 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', 'threadtag');
define('CSRF_PROTECTION', true);
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array('posting', 'showthread');
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array(
'newpost_errormessage',
'tag_edit',
'tag_managebit',
'tagbit',
'tagbit_wrapper'
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_newpost.php');
require_once(DIR . '/includes/functions_bigthree.php');
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'manage';
}
$threadinfo = verify_id('thread', $vbulletin->GPC['threadid'], 1, 1);
if (!$vbulletin->options['threadtagging'])
{
print_no_permission();
}
// *********************************************************************************
// check for visible / deleted thread
if (((!$threadinfo['visible'] AND !can_moderate($threadinfo['forumid'], 'canmoderateposts'))) OR ($threadinfo['isdeleted'] AND !can_moderate($threadinfo['forumid'])))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['thread'], $vbulletin->options['contactuslink'])));
}
// *********************************************************************************
// jump page if thread is actually a redirect
if ($threadinfo['open'] == 10)
{
exec_header_redirect('showthread.php?' . $vbulletin->session->vars['sessionurl_js'] . "t=$threadinfo[pollid]");
}
// *********************************************************************************
// Tachy goes to coventry
if (in_coventry($threadinfo['postuserid']) AND !can_moderate($threadinfo['forumid']))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['thread'], $vbulletin->options['contactuslink'])));
}
// *********************************************************************************
// get forum info
$foruminfo = fetch_foruminfo($threadinfo['forumid']);
// *********************************************************************************
// check forum permissions
$forumperms = fetch_permissions($threadinfo['forumid']);
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']))
{
print_no_permission();
}
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) AND ($threadinfo['postuserid'] != $vbulletin->userinfo['userid'] OR $vbulletin->userinfo['userid'] == 0))
{
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']);
if (!$foruminfo['allowposting'] OR (!$threadinfo['open'] AND !can_moderate($threadinfo['forumid'], 'canopenclose')))
{
// thread is closed and can't be opened by this person
$show['add_option'] = false;
$show['manage_existing_option'] = can_moderate($threadinfo['forumid'], 'caneditthreads');
}
else
{
$show['add_option'] = (
(($forumperms & $vbulletin->bf_ugp_forumpermissions['cantagown']) AND $threadinfo['postuserid'] == $vbulletin->userinfo['userid'])
OR ($forumperms & $vbulletin->bf_ugp_forumpermissions['cantagothers'])
);
$show['manage_existing_option'] = (
$show['add_option']
OR (($forumperms & $vbulletin->bf_ugp_forumpermissions['candeletetagown']) AND $threadinfo['postuserid'] == $vbulletin->userinfo['userid'])
OR can_moderate($threadinfo['forumid'], 'caneditthreads')
);
}
($hook = vBulletinHook::fetch_hook('threadtag_start')) ? eval($hook) : false;
if (!$show['add_option'] AND !$show['manage_existing_option'])
{
print_no_permission();
}
// ##############################################################################
if ($_POST['do'] == 'managetags')
{
$vbulletin->input->clean_array_gpc('p', array(
'tagskept' => TYPE_ARRAY_UINT,
'tagsshown' => TYPE_ARRAY_UINT,
'taglist' => TYPE_NOHTML,
'ajax' => TYPE_BOOL
));
if ($vbulletin->GPC['ajax'])
{
$vbulletin->GPC['taglist'] = convert_urlencoded_unicode($vbulletin->GPC['taglist']);
}
if ($vbulletin->GPC['tagsshown'] AND $show['manage_existing_option'])
{
$tags_sql = $db->query_read("
SELECT tag.*, tagthread.userid
FROM " . TABLE_PREFIX . "tagthread AS tagthread
INNER JOIN " . TABLE_PREFIX . "tag AS tag ON (tag.tagid = tagthread.tagid)
WHERE tagthread.threadid = $threadinfo[threadid]
AND tagthread.tagid IN (" . implode(',', $vbulletin->GPC['tagsshown']) . ")
");
$delete = array();
while ($tag = $db->fetch_array($tags_sql))
{
if ($tag['userid'] == $vbulletin->userinfo['userid']
OR (($forumperms & $vbulletin->bf_ugp_forumpermissions['candeletetagown']) AND $threadinfo['postuserid'] == $vbulletin->userinfo['userid'])
OR can_moderate($threadinfo['forumid'], 'caneditthreads')
)
{
if (!in_array($tag['tagid'], $vbulletin->GPC['tagskept']))
{
$delete[] = $tag['tagid'];
}
}
}
($hook = vBulletinHook::fetch_hook('threadtag_domanage_delete')) ? eval($hook) : false;
if ($delete)
{
$db->query_write("
DELETE FROM " . TABLE_PREFIX . "tagthread
WHERE threadid = $threadinfo[threadid]
AND tagid IN (" . implode(',', $delete) . ")
");
$threadinfo['taglist'] = rebuild_thread_taglist($threadinfo['threadid']);
}
}
($hook = vBulletinHook::fetch_hook('threadtag_domanage_postdelete')) ? eval($hook) : false;
if ($vbulletin->GPC['taglist'] AND $show['add_option'])
{
$errors = add_tags_to_thread($threadinfo, $vbulletin->GPC['taglist']);
}
else
{
$errors = array();
}
if ($vbulletin->GPC['ajax'])
{
$threadinfo = fetch_threadinfo($threadinfo['threadid'], false); // get updated tag list
$tagcount = ($threadinfo['taglist'] ? count(explode(',', $threadinfo['taglist'])) : 0);
require_once(DIR . '/includes/class_xml.php');
$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
$xml->add_group('tag');
$xml->add_tag('taghtml', process_replacement_vars(fetch_tagbits($threadinfo)));
if ($errors)
{
$errorlist = '';
foreach ($errors AS $error)
{
$errorlist .= "\n * $error";
}
$xml->add_tag('warning', fetch_error('tag_add_failed_plain', $errorlist));
}
$xml->close_group();
$xml->print_xml();
}
else
{
if ($errors)
{
$errorlist = '';
foreach ($errors AS $key => $errormessage)
{
eval('$errorlist .= "' . fetch_template('newpost_errormessage') . '";');
}
$errorlist = fetch_error('tag_add_failed_html', $errorlist, 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t=$threadinfo[threadid]#taglist");
$_REQUEST['do'] = 'manage';
define('ADD_ERROR', true);
}
else
{
$vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t=$threadinfo[threadid]#taglist";
eval(print_standard_redirect(fetch_error('tags_edited_successfully'), false));
}
}
}
// ##############################################################################
if ($_REQUEST['do'] == 'manage')
{
$show['errors'] = defined('ADD_ERROR');
if (!$show['errors'])
{
$valid_tag_html = '';
}
$tag_manage_options = '';
$have_removal_tags = false;
$mytags = 0;
$tags_sql = $db->query_read("
SELECT tag.*, tagthread.userid, user.username
FROM " . TABLE_PREFIX . "tagthread AS tagthread
INNER JOIN " . TABLE_PREFIX . "tag AS tag ON (tag.tagid = tagthread.tagid)
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = tagthread.userid)
WHERE tagthread.threadid = $threadinfo[threadid]
ORDER BY tag.tagtext
");
$total_tags = $db->num_rows($tags_sql);
if ($total_tags == 0 AND !$show['add_option'])
{
print_no_permission();
}
while ($tag = $db->fetch_array($tags_sql))
{
$tag['ismine'] = ($tag['userid'] == $vbulletin->userinfo['userid']);
$show['tag_checkbox'] = ($tag['ismine']
OR (($forumperms & $vbulletin->bf_ugp_forumpermissions['candeletetagown']) AND $threadinfo['postuserid'] == $vbulletin->userinfo['userid'])
OR can_moderate($threadinfo['forumid'], 'caneditthreads')
);
if ($show['tag_checkbox'])
{
$have_removal_tags = true;
}
if ($tag['ismine'])
{
$mytags++;
}
// only moderators can see who added a tag
if (!can_moderate($threadinfo['forumid'], 'caneditthreads'))
{
$tag['username'] = '';
}
($hook = vBulletinHook::fetch_hook('threadtag_managebit')) ? eval($hook) : false;
eval('$tag_manage_options .= "' . fetch_template('tag_managebit') . '";');
}
// determine the number of tags this person can add
$user_tags_remain = null;
if ($vbulletin->options['tagmaxthread'])
{
// check global limit
$tags_remain = max(0, $vbulletin->options['tagmaxthread'] - $total_tags);
if ($tags_remain == 0 AND !$have_removal_tags)
{
// thread full and no tags can be removed - error
standard_error(fetch_error('thread_has_max_allowed_tags'));
}
$user_tags_remain = $tags_remain;
}
if (!can_moderate($threadinfo['forumid'], 'caneditthreads'))
{
$tags_remain = null;
if ($vbulletin->options['tagmaxstarter'] AND $threadinfo['postuserid'] == $vbulletin->userinfo['userid'])
{
$tags_remain = max(0, $vbulletin->options['tagmaxstarter'] - $mytags);
}
else if ($vbulletin->options['tagmaxuser'])
{
$tags_remain = max(0, $vbulletin->options['tagmaxuser'] - $mytags);
}
if ($tags_remain !== null)
{
if ($user_tags_remain == null)
{
$user_tags_remain = $tags_remain;
}
else
{
$user_tags_remain = min($tags_remain, $user_tags_remain);
}
}
}
($hook = vBulletinHook::fetch_hook('threadtag_manage_tagsremain')) ? eval($hook) : false;
$show['tag_limit_phrase'] = ($user_tags_remain !== null);
$tags_remain = vb_number_format($user_tags_remain);
$tag_delimiters = addslashes_js($vbulletin->options['tagdelimiter']);
if ($vbulletin->GPC['ajax'])
{
eval('$html = "' . fetch_template('tag_edit_ajax') . '";');
require_once(DIR . '/includes/class_xml.php');
$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
$xml->add_group('tag');
$xml->add_tag('html', process_replacement_vars($html));
$xml->add_tag('delimiters', $vbulletin->options['tagdelimiter']);
$xml->close_group();
$xml->print_xml();
}
// navbar and output
$navbits = array();
$parentlist = array_reverse(explode(',', substr($foruminfo['parentlist'], 0, -3)));
foreach ($parentlist AS $forumid)
{
$forum_title = $vbulletin->forumcache["$forumid"]['title'];
$navbits['forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f=$forumid"] = $forum_title;
}
$navbits['showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t=$threadinfo[threadid]"] = $threadinfo['prefix_plain_html'] . ' ' . $threadinfo['title'];
$navbits[''] = $vbphrase['tag_management'];
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('tag_edit') . '");');
}
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 18:59, Mon Jul 11th 2016
|| # CVS: $RCSfile$ - $Revision: 83872 $
|| ####################################################################
\*======================================================================*/
?>