-
Notifications
You must be signed in to change notification settings - Fork 1
/
newattachment.php
executable file
·577 lines (508 loc) · 18.1 KB
/
newattachment.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
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.8.11 - Licence Number VBF83FEF44
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2017 vBulletin Solutions Inc. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # www.vbulletin.com | www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
@set_time_limit(0);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('GET_EDIT_TEMPLATES', true);
define('THIS_SCRIPT', 'newattachment');
define('CSRF_PROTECTION', true);
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array('posting');
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array(
'newattachment',
'newattachmentbit',
'newpost_attachmentbit',
'newattachment_errormessage',
'newattachment_keybit',
);
// 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_file.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
if (!$vbulletin->userinfo['userid']) // Guests can not post attachments
{
print_no_permission();
}
// Variables that are reused in templates
$editpost =& $vbulletin->input->clean_gpc('r', 'editpost', TYPE_BOOL);
$poststarttime =& $vbulletin->input->clean_gpc('r', 'poststarttime', TYPE_UINT);
$posthash =& $vbulletin->input->clean_gpc('r', 'posthash', TYPE_NOHTML);
if ($postid AND $vbulletin->GPC['editpost'])
{
$postid = verify_id('post', $postid);
}
else if ($threadid)
{
$threadid = verify_id('thread', $threadid);
unset($postid); // We don't want the post from the thread we are replying to..
}
else if ($forumid)
{
$forumid = verify_id('forum', $forumid);
}
else
{
eval(standard_error(fetch_error('invalidid', $vbphrase['post'], $vbulletin->options['contactuslink'])));
}
$forumperms = fetch_permissions($foruminfo['forumid']);
// No permissions to post attachments in this forum or no permission to view threads in this forum.
if (empty($vbulletin->userinfo['attachmentextensions']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']))
{
print_no_permission();
}
if ((!$postid AND !$foruminfo['allowposting']) OR $foruminfo['link'] OR !$foruminfo['cancontainthreads'])
{
eval(standard_error(fetch_error('forumclosed')));
}
if ($threadid) // newreply.php or editpost.php called
{
if ($threadinfo['isdeleted'] OR (!$threadinfo['visible'] AND !can_moderate($threadinfo['forumid'], 'canmoderateposts')))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['thread'], $vbulletin->options['contactuslink'])));
}
if (!$threadinfo['open'])
{
if (!can_moderate($threadinfo['forumid'], 'canopenclose'))
{
$vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t=$threadid";
eval(standard_error(fetch_error('threadclosed')));
}
}
if (($vbulletin->userinfo['userid'] != $threadinfo['postuserid']) AND (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyothers'])))
{
print_no_permission();
}
// don't call this part on editpost.php (which will have a $postid)
if (!$postid AND !($forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyown']) AND $vbulletin->userinfo['userid'] == $threadinfo['postuserid'])
{
print_no_permission();
}
}
else if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostnew'])) // newthread.php
{
print_no_permission();
}
if ($postid) // editpost.php
{
if (!can_moderate($threadinfo['forumid'], 'caneditposts'))
{
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['caneditpost']))
{
print_no_permission();
}
else
{
if ($vbulletin->userinfo['userid'] != $postinfo['userid'])
{
// check user owns this post
print_no_permission();
}
else
{
// check for time limits
if ($postinfo['dateline'] < (TIMENOW - ($vbulletin->options['edittimelimit'] * 60)) AND $vbulletin->options['edittimelimit'])
{
eval(standard_error(fetch_error('edittimelimit', $vbulletin->options['edittimelimit'], $vbulletin->options['contactuslink'])));
}
}
}
}
}
$parentattach = '';
$parentclickattach = '';
$new_attachlist_js = '';
// check if there is a forum password and if so, ensure the user has it set
verify_forum_password($foruminfo['forumid'], $foruminfo['password']);
if ($posthash != md5($poststarttime . $vbulletin->userinfo['userid'] . $vbulletin->userinfo['salt']))
{
print_no_permission();
}
($hook = vBulletinHook::fetch_hook('newattachment_start')) ? eval($hook) : false;
$show['errors'] = false;
$currentattaches = $db->query_first("
SELECT COUNT(*) AS count
FROM " . TABLE_PREFIX . "attachment
WHERE posthash = '$posthash'
AND userid = " . $vbulletin->userinfo['userid']
);
$attachcount = $currentattaches['count'];
if ($postid)
{
$currentattaches = $db->query_first("
SELECT COUNT(*) AS count
FROM " . TABLE_PREFIX . "attachment
WHERE postid = $postid
");
$attachcount += $currentattaches['count'];
$show['postowner'] = true;
$attach_username = $postinfo['username'];
}
else
{
$show['postowner'] = false;
$attach_username = $vbulletin->userinfo['username'];
}
if (!$foruminfo['allowposting'] AND !$attachcount)
{
eval(standard_error(fetch_error('forumclosed')));
}
// ##################### Add Attachment to Post ####################
if ($_POST['do'] == 'manageattach')
{
$vbulletin->input->clean_array_gpc('p', array(
'upload' => TYPE_STR,
'delete' => TYPE_ARRAY_STR,
));
if (!$vbulletin->GPC['upload'])
{
if (!empty($vbulletin->GPC['delete']))
{
$attachdata = datamanager_init('Attachment', $vbulletin, ERRTYPE_STANDARD);
$popid = array_keys($vbulletin->GPC['delete']);
$attachmentid = intval($popid[0]);
$attachdata->condition = "attachmentid = $attachmentid";
if ($postid)
{
$attachdata->condition .= " AND (attachment.postid = $postid OR attachment.posthash = '" . $db->escape_string($posthash) . "')";
}
else
{
$attachdata->condition .= " AND attachment.posthash = '" . $db->escape_string($posthash) . "'";
}
if ($attachdata->delete())
{
$show['updateparent'] = true;
}
}
}
else
{ // Attach file...
$errors = array();
$vbulletin->input->clean_gpc('f', 'attachment', TYPE_FILE);
$vbulletin->input->clean_gpc('p', 'attachmenturl', TYPE_ARRAY_STR);
require_once(DIR . '/includes/class_upload.php');
require_once(DIR . '/includes/class_image.php');
if ($postid) // Editing a post
{
$userinfo = fetch_userinfo($postinfo['userid']);
cache_permissions($userinfo, true);
$postinfo['posthash'] =& $posthash;
}
else
{
$postinfo = array('posthash' => $posthash);
}
// check for any funny business
$filecount = 1;
if (!empty($vbulletin->GPC['attachment']['tmp_name']))
{
foreach ($vbulletin->GPC['attachment']['tmp_name'] AS $filename)
{
if (!empty($filename))
{
if ($filecount > $vbulletin->options['attachboxcount'])
{
@unlink($filename);
}
$filecount++;
}
}
}
// Move any urls into the attachment array if we allow url upload
if ($vbulletin->options['attachurlcount'])
{
$urlcount = 1;
foreach ($vbulletin->GPC['attachmenturl'] AS $url)
{
if (!empty($url) AND $urlcount <= $vbulletin->options['attachurlcount'])
{
$index = count($vbulletin->GPC['attachment']['name']);
$vbulletin->GPC['attachment']['name']["$index"] = $url;
$vbulletin->GPC['attachment']['url']["$index"] = true;
$urlcount++;
}
}
}
$uploadsum = count($vbulletin->GPC['attachment']['name']);
for ($x = 0; $x < $uploadsum; $x++)
{
// These are created each go around to insure memory has been freed
$attachdata = datamanager_init('Attachment', $vbulletin, ERRTYPE_ARRAY);
$upload = new vB_Upload_Attachment($vbulletin);
$image = vB_Image::fetch_library($vbulletin);
$upload->data =& $attachdata;
$upload->image =& $image;
if ($uploadsum > 1)
{
$upload->emptyfile = false;
}
$upload->foruminfo =& $foruminfo;
if ($postid) // Editing a post
{
$upload->userinfo =& $userinfo;
}
$upload->postinfo =& $postinfo;
if ($vbulletin->GPC['attachment']['url']["$x"])
{
$attachment =& $vbulletin->GPC['attachment']['name']["$x"];
}
else
{
$attachment = array(
'name' =>& $vbulletin->GPC['attachment']['name']["$x"],
'tmp_name' =>& $vbulletin->GPC['attachment']['tmp_name']["$x"],
'error' =>& $vbulletin->GPC['attachment']['error']["$x"],
'size' =>& $vbulletin->GPC['attachment']['size']["$x"],
);
}
$attachcount++;
if (!$foruminfo['allowposting'])
{
$error = $vbphrase['this_forum_is_not_accepting_new_attachments'];
$errors[] = array(
'filename' => $attachment['name'],
'error' => $error
);
}
else if ($vbulletin->options['attachlimit'] AND $attachcount > $vbulletin->options['attachlimit'])
{
$error = construct_phrase($vbphrase['you_may_only_attach_x_files_per_post'], $vbulletin->options['attachlimit']);
$errors[] = array(
'filename' => $attachment['name'],
'error' => $error
);
}
else
{
if ($attachmentid = $upload->process_upload($attachment))
{
if ($vbulletin->userinfo['userid'] != $postinfo['userid'] AND can_moderate($threadinfo['forumid'], 'caneditposts'))
{
$postinfo['attachmentid'] =& $attachmentid;
$postinfo['forumid'] =& $foruminfo['forumid'];
require_once(DIR . '/includes/functions_log_error.php');
log_moderator_action($postinfo, 'attachment_uploaded');
}
}
else
{
$attachcount--;
}
if ($error = $upload->fetch_error())
{
$errors[] = array(
'filename' => is_array($attachment) ? $attachment['name'] : $attachment,
'error' => $error,
);
}
}
}
($hook = vBulletinHook::fetch_hook('newattachment_attach')) ? eval($hook) : false;
if (!empty($errors))
{
$errorlist = '';
foreach ($errors AS $error)
{
$filename = htmlspecialchars_uni($error['filename']);
$errormessage = $error['error'];
eval('$errorlist .= "' . fetch_template('newattachment_errormessage') . '";');
}
$show['errors'] = true;
}
}
}
// <-- This is done in two queries since Mysql will not use an index on an OR query which gives a full table scan of the attachment table
// could use an UNION in 4.1+
$stopat = 1;
$currentattaches1 = $db->query_read("
SELECT dateline, filename, filesize, attachmentid, IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail
FROM " . TABLE_PREFIX . "attachment
WHERE posthash = '$posthash'
AND userid = " . iif($postinfo['postid'], $postinfo['userid'], $vbulletin->userinfo['userid']) . "
ORDER BY attachmentid
");
if ($postid) // Attachments are being added from edit post
{
$stopat = 2;
$currentattaches2 = $db->query_read_slave("
SELECT dateline, filename, filesize, attachmentid, IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail
FROM " . TABLE_PREFIX . "attachment
WHERE postid = $postid
ORDER BY attachmentid
");
}
require_once(DIR . '/includes/functions_editor.php');
$wysiwyg = is_wysiwyg_compatible();
$attachcount = 0;
$totalsize = 0;
for ($x = $stopat; $x > 0; $x--)
{
$currentattaches =& ${currentattaches . $x};
while ($attach = $db->fetch_array($currentattaches))
{
$attach['extension'] = strtolower(file_extension($attach['filename']));
$attach['filename'] = htmlspecialchars_uni($attach['filename']);
$attachcount++;
$totalsize += intval($attach['filesize']);
$attach['filesize'] = vb_number_format($attach['filesize'], 1, true);
$show['thumbnail'] = iif($attach['hasthumbnail'], true, false);
eval('$attachments .= "' . fetch_template('newattachmentbit') . '";');
eval('$parentattach .= "' . fetch_template('newpost_attachmentbit', 0, 0) . '";');
$new_attachlist_js .= "window.opener.vB_Attachments.add($attach[attachmentid], '" . addslashes_js($attach['filename']) . "', '" . addslashes_js($attach['filesize']) . "', '$stylevar[imgdir_attach]/$attach[extension].gif');\n";
if ($wysiwyg == 1)
{
$attach['filename'] = fetch_trimmed_title($attach['filename'], 12);
}
$parentclickattach .= "attachoptions[$attach[attachmentid]] = new Array();\n";
$parentclickattach .= "attachoptions[$attach[attachmentid]][\"f\"] = \"$attach[filename]\";\n";
$parentclickattach .= "attachoptions[$attach[attachmentid]][\"e\"] = \"$attach[extension]\";\n";
}
}
$totallimit = vb_number_format($totalsize, 1, true);
if ($postid)
{
$userinfo = fetch_userinfo($postinfo['userid']);
cache_permissions($userinfo, true);
$perms = $userinfo['forumpermissions'];
$attachlimit = $userinfo['permissions']['attachlimit'];
}
else
{
$userinfo =& $vbulletin->userinfo;
$perms = $vbulletin->userinfo['forumpermissions'];
$attachlimit = $permissions['attachlimit'];
}
if ($attachlimit)
{
// Get forums that allow canview access
foreach ($perms AS $pforumid => $fperm)
{
if (($fperm & $vbulletin->bf_ugp_forumpermissions['canview']) AND ($fperm & $vbulletin->bf_ugp_forumpermissions['cangetattachment']))
{
$forumids .= ",$pforumid";
}
}
unset($pforumid);
$attachdata = $db->query_first("
SELECT SUM(attachment.filesize) AS sum
FROM " . TABLE_PREFIX . "attachment AS attachment
LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = attachment.postid)
LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON (post.threadid = thread.threadid)
WHERE attachment.userid = " . iif($postid, $postinfo['userid'], $vbulletin->userinfo['userid']) . "
AND ((forumid IN(-1$forumids) AND thread.visible <> 2 AND post.visible <> 2)
OR attachment.postid = 0)
");
$attachsum = intval($attachdata['sum']);
($hook = vBulletinHook::fetch_hook('newattachment_attachsum')) ? eval($hook) : false;
if ($attachsum >= $attachlimit)
{
$totalsize = 0;
$attachsize = 100;
}
else
{
$attachsize = ceil($attachsum / $attachlimit * 100);
$totalsize = 100 - $attachsize;
}
$attachsum = vb_number_format($attachsum, 1, true);
$attachlimit = vb_number_format($attachlimit, 1, true);
$show['attachmentlimits'] = true;
$show['currentsize'] = iif($attachsize, true, false);
$show['totalsize'] = iif($totalsize, true, false);
}
else
{
$show['attachmentlimits'] = false;
$show['currentsize'] = false;
$show['totalsize'] = false;
}
if (($attachcount >= $vbulletin->options['attachlimit'] AND $vbulletin->options['attachlimit']) OR !$foruminfo['allowposting'])
{
$show['attachoption'] = false;
if (!$foruminfo['allowposting'])
{
$show['forumclosed'] = true;
}
}
else
{
// If we have unlimited attachments, set filesleft to box count
if ($vbulletin->options['attachboxcount'])
{
$show['attachoption'] = true;
$show['attachfile'] = true;
$filesleft = iif($vbulletin->options['attachlimit'], $vbulletin->options['attachlimit'] - $attachcount, $vbulletin->options['attachboxcount']);
$filesleft = iif($filesleft < $vbulletin->options['attachboxcount'], $filesleft, $vbulletin->options['attachboxcount']);
$boxcount = 1;
$attachinput = '';
while ($boxcount <= $filesleft)
{
$attachinput .= "<input type=\"file\" class=\"bginput\" name=\"attachment[]\" size=\"30\" /><br />\n";
$boxcount++;
}
}
if ($vbulletin->options['attachurlcount'] AND (ini_get('allow_url_fopen') != 0 OR function_exists('curl_init')))
{
$show['attachoption'] = true;
$show['attachurl'] = true;
$filesleft = iif($vbulletin->options['attachlimit'], $vbulletin->options['attachlimit'] - $attachcount, $vbulletin->options['attachurlcount']);
$filesleft = iif($filesleft < $vbulletin->options['attachurlcount'], $filesleft, $vbulletin->options['attachurlcount']);
$boxcount = 1;
$attachurlinput = '';
while ($boxcount <= $filesleft)
{
$attachurlinput .= "<input type=\"text\" class=\"bginput\" name=\"attachmenturl[]\" size=\"30\" dir=\"ltr\" /><br />\n";
$boxcount++;
}
}
$vbphrase['upload_word'] = iif (is_browser('safari'), $vbphrase['choose_file'], $vbphrase['browse']);
}
$show['attachmentlist'] = iif($attachments, true, false);
$inimaxattach = fetch_max_upload_size();
if ($parentattach)
{
$parentattach = str_replace('"', '\"', $parentattach);
$show['updateparent'] = true;
}
($hook = vBulletinHook::fetch_hook('newattachment_complete')) ? eval($hook) : false;
foreach($userinfo['attachmentpermissions'] AS $filetype => $extension)
{
if (!empty($extension['permissions']))
{
exec_switch_bg();
$extension['size'] = $extension['size'] > 0 ? vb_number_format($extension['size'], 1, true) : '-';
$extension['width'] = $extension['width'] > 0 ? $extension['width'] : '-';
$extension['height'] = $extension['height'] > 0 ? $extension['height'] : '-';
$extension['extension'] = $filetype;
eval('$attachkeybits .= "' . fetch_template('newattachment_keybit') . '";');
}
}
$show['updateparent'] = true;
// complete
eval('print_output("' . fetch_template('newattachment') . '");');
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 03:31, Fri Jun 16th 2017 : $Revision: 92875 $
|| # $Date: 2017-02-11 09:03:44 -0800 (Sat, 11 Feb 2017) $
|| ####################################################################
\*======================================================================*/
?>