-
Notifications
You must be signed in to change notification settings - Fork 1
/
threadtag.php
378 lines (324 loc) · 10.7 KB
/
threadtag.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
<?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', '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_wrapper'
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_bigthree.php');
require_once(DIR . '/includes/class_taggablecontent.php');
//do we still need this? if so, why
require_once(DIR . '/includes/functions_newpost.php');
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'manage';
}
$vbulletin->input->clean_array_gpc('r', array(
'contenttype' => TYPE_NOHTML,
'contentid' => TYPE_UINT,
'threadid' => TYPE_UINT,
'ajax' => TYPE_BOOL,
'returnurl' => TYPE_STR
));
//*******************************************************************
//Figure out the content type
if (!empty($vbulletin->GPC['contenttype']))
{
$contenttypeid = $vbulletin->GPC['contenttype'];
}
else
{
$contenttypeid = "vBForum_Thread";
}
//todo fix the old urls that use this method then elimate this code
if ($contenttypeid == 'thread')
{
$contenttypeid = "vBForum_Thread";
}
else if ($contenttypeid == 'picture')
{
$contenttypeid = "vBForum_Picture";
}
$contenttypeid = vB_Types::instance()->getContentTypeID($contenttypeid);
//*******************************************************************
//Figure out the content id
if ($vbulletin->GPC_exists['contentid'])
{
$contentid = $vbulletin->GPC['contentid'];
}
else
{
$contentid = $vbulletin->GPC['threadid'];
}
if (!$vbulletin->options['threadtagging'])
{
print_no_permission();
}
if (!$contenttypeid)
{
eval(standard_error(fetch_error('content_not_taggable')));
}
//this will terminate if there are permission errors
$content = vB_Taggable_Content_Item::create($vbulletin, $contenttypeid, $contentid);
if (!$content)
{
//do we need a phrase? This really shouldn't happen under normal operation.
eval(standard_error(fetch_error('content_not_taggable')));
}
$content->verify_ui_permissions();
//$contentinfo = $content->fetch_content_info();
$show['add_option'] = $content->can_add_tag();
$show['manage_existing_option'] = $content->can_manage_tag();
($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,
));
if ($vbulletin->GPC['ajax'])
{
$vbulletin->GPC['taglist'] = convert_urlencoded_unicode($vbulletin->GPC['taglist']);
}
//remove any tags shown and not kept.
if ($vbulletin->GPC['tagsshown'] AND $show['manage_existing_option'])
{
$tags_sql = $db->query_read("
SELECT tag.*, tagcontent.userid
FROM " . TABLE_PREFIX . "tagcontent AS tagcontent
INNER JOIN " . TABLE_PREFIX . "tag AS tag ON
(tag.tagid = tagcontent.tagid AND tagcontent.contenttypeid = " . intval($contenttypeid) . ")
WHERE tagcontent.contentid = $contentid
AND tagcontent.tagid IN (" . implode(',', $vbulletin->GPC['tagsshown']) . ")
");
$delete = array();
while ($tag = $db->fetch_array($tags_sql))
{
if ($content->can_delete_tag($tag['userid']))
{
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 . "tagcontent
WHERE contentid = $contentid AND
contenttypeid = ". intval($contenttypeid) . " AND
tagid IN (" . implode(',', $delete) . ")
");
$content->rebuild_content_tags();
}
}
($hook = vBulletinHook::fetch_hook('threadtag_domanage_postdelete')) ? eval($hook) : false;
if ($vbulletin->GPC['taglist'] AND $show['add_option'])
{
$limits = $content->fetch_tag_limits();
$errors = $content->add_tags_to_content($vbulletin->GPC['taglist'], $limits);
}
else
{
$errors = array();
}
if ($vbulletin->GPC['ajax'])
{
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($content->fetch_rendered_tag_list()));
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
{
$returnurl = $content->fetch_return_url();
$errorlist = '';
if (!empty($errors))
{
$show['errors'] = true;
$templater = vB_Template::create('newpost_errormessage');
$templater->register('errors', $errors);
$errorlist .= $templater->render();
$errorlist = fetch_error('tag_add_failed_html', $errorlist, $returnurl);
$_REQUEST['do'] = 'manage';
define('ADD_ERROR', true);
}
else
{
$vbulletin->url = $returnurl;
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.*, tagcontent.userid, user.username
FROM " . TABLE_PREFIX . "tagcontent AS tagcontent
INNER JOIN " . TABLE_PREFIX . "tag AS tag ON
(tag.tagid = tagcontent.tagid AND tagcontent.contenttypeid = " . intval($contenttypeid) . ")
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = tagcontent.userid)
WHERE tagcontent.contentid = $contentid
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'] = $content->can_delete_tag($tag['userid']);
if ($show['tag_checkbox'])
{
$have_removal_tags = true;
}
if ($tag['ismine'])
{
$mytags++;
}
// only moderators can see who added a tag
if (!$content->can_moderate_tag())
{
$tag['username'] = '';
}
($hook = vBulletinHook::fetch_hook('threadtag_managebit')) ? eval($hook) : false;
$templater = vB_Template::create('tag_managebit');
$templater->register('tag', $tag);
$tag_manage_options .= $templater->render();
}
$limits = $content->fetch_tag_limits();
if ($limits['content_limit'])
{
$content_tags_remain = max(0, $limits['content_limit'] - $total_tags);
}
else
{
$content_tags_remain = PHP_INT_MAX;
}
if ($limits['user_limit'])
{
$user_tags_remain = max(0, $limits['user_limit'] - $mytags);
}
else
{
$user_tags_remain = PHP_INT_MAX;
}
$tags_remain = min($content_tags_remain, $user_tags_remain);
($hook = vBulletinHook::fetch_hook('threadtag_manage_tagsremain')) ? eval($hook) : false;
$show['tag_limit_phrase'] = ($tags_remain !== PHP_INT_MAX);
$tags_remain = vb_number_format($tags_remain);
$tag_delimiters = addslashes_js($vbulletin->options['tagdelimiter']);
if ($vbulletin->GPC['ajax'])
{
$popup = $vbulletin->input->clean_gpc('r', 'popup', TYPE_BOOL);
if($popup)
{
$templater = vB_Template::create('tag_edit_ajax_popup');
}
else
{
$templater = vB_Template::create('tag_edit_ajax');
}
$templater->register('contentid', $contentid);
$templater->register('contenttype', $contenttypeid);
$templater->register('tags_remain', $tags_remain);
$templater->register('tag_manage_options', $tag_manage_options);
$templater->register('url', $url);
$html = $templater->render();
require_once(DIR . '/includes/class_xml.php');
$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
$xml->add_group('tag');
$xml->add_tag($popup ? 'tagpopup' : 'html', process_replacement_vars($html));
$xml->add_tag('delimiters', $vbulletin->options['tagdelimiter']);
$xml->close_group();
$xml->print_xml();
}
else
{
$returnurl = $content->fetch_return_url();
$title = $content->get_title();
if(!$title)
{
$title = $content->fetch_content_type_diplay();
}
$content_type_label = $content->fetch_content_type_diplay();
// navbar and output
$navbits = $content->fetch_page_nav();
$navbits = construct_navbits($navbits);
$navbar = render_navbar_template($navbits);
$templater = vB_Template::create('tag_edit');
$templater->register_page_templates();
$templater->register('contentid', $contentid);
$templater->register('title', $title);
$templater->register('contenttype', $contenttypeid);
$templater->register('content_type_label', $content_type_label);
$templater->register('errorlist', $errorlist);
$templater->register('navbar', $navbar);
$templater->register('returnurl', $returnurl);
$templater->register('tags_remain', $tags_remain);
$templater->register('tag_delimiters', $tag_delimiters);
$templater->register('tag_manage_options', $tag_manage_options);
print_output($templater->render());
}
}
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 16:29, Sun Dec 9th 2012
|| # CVS: $RCSfile$ - $Revision: 62098 $
|| ####################################################################
\*======================================================================*/