phpBB
Statistics
| Revision:

root / trunk / phpBB / posting.php

History | View | Annotate | Download (57.8 kB)

1
<?php
2
/**
3
*
4
* @package phpBB3
5
* @copyright (c) 2005 phpBB Group
6
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
*
8
*/
9
10
/**
11
* @ignore
12
*/
13
define('IN_PHPBB', true);
14
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
15
$phpEx = substr(strrchr(__FILE__, '.'), 1);
16
include($phpbb_root_path . 'common.' . $phpEx);
17
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
18
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
19
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
20
21
22
// Start session management
23
$user->session_begin();
24
$auth->acl($user->data);
25
26
27
// Grab only parameters needed here
28
$post_id        = request_var('p', 0);
29
$topic_id        = request_var('t', 0);
30
$forum_id        = request_var('f', 0);
31
$draft_id        = request_var('d', 0);
32
$lastclick        = request_var('lastclick', 0);
33
34
$submit                = (isset($_POST['post'])) ? true : false;
35
$preview        = (isset($_POST['preview'])) ? true : false;
36
$save                = (isset($_POST['save'])) ? true : false;
37
$load                = (isset($_POST['load'])) ? true : false;
38
$delete                = (isset($_POST['delete'])) ? true : false;
39
$cancel                = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
40
41
$refresh        = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['full_editor']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false;
42
$mode                = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', '');
43
44
$error = $post_data = array();
45
$current_time = time();
46
47
// Was cancel pressed? If so then redirect to the appropriate page
48
if ($cancel || ($current_time - $lastclick < 2 && $submit))
49
{
50
        $f = ($forum_id) ? 'f=' . $forum_id . '&amp;' : '';
51
        $redirect = ($post_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", $f . 'p=' . $post_id) . '#p' . $post_id : (($topic_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", $f . 't=' . $topic_id) : (($forum_id) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) : append_sid("{$phpbb_root_path}index.$phpEx")));
52
        redirect($redirect);
53
}
54
55
if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$forum_id)
56
{
57
        trigger_error('NO_FORUM');
58
}
59
60
// We need to know some basic information in all cases before we do anything.
61
switch ($mode)
62
{
63
        case 'post':
64
                $sql = 'SELECT *
65
                        FROM ' . FORUMS_TABLE . "
66
                        WHERE forum_id = $forum_id";
67
        break;
68
69
        case 'bump':
70
        case 'reply':
71
                if (!$topic_id)
72
                {
73
                        trigger_error('NO_TOPIC');
74
                }
75
76
                // Force forum id
77
                $sql = 'SELECT forum_id
78
                        FROM ' . TOPICS_TABLE . '
79
                        WHERE topic_id = ' . $topic_id;
80
                $result = $db->sql_query($sql);
81
                $f_id = (int) $db->sql_fetchfield('forum_id');
82
                $db->sql_freeresult($result);
83
84
                $forum_id = (!$f_id) ? $forum_id : $f_id;
85
86
                $sql = 'SELECT f.*, t.*
87
                        FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
88
                        WHERE t.topic_id = $topic_id
89
                                AND f.forum_id = t.forum_id" .
90
                        (($auth->acl_get('m_approve', $forum_id)) ? '' : ' AND t.topic_approved = 1');
91
        break;
92
93
        case 'quote':
94
        case 'edit':
95
        case 'delete':
96
                if (!$post_id)
97
                {
98
                        $user->setup('posting');
99
                        trigger_error('NO_POST');
100
                }
101
102
                // Force forum id
103
                $sql = 'SELECT forum_id
104
                        FROM ' . POSTS_TABLE . '
105
                        WHERE post_id = ' . $post_id;
106
                $result = $db->sql_query($sql);
107
                $f_id = (int) $db->sql_fetchfield('forum_id');
108
                $db->sql_freeresult($result);
109
110
                $forum_id = (!$f_id) ? $forum_id : $f_id;
111
112
                $sql = 'SELECT f.*, t.*, p.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
113
                        FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
114
                        WHERE p.post_id = $post_id
115
                                AND t.topic_id = p.topic_id
116
                                AND u.user_id = p.poster_id
117
                                AND f.forum_id = t.forum_id" .
118
                                (($auth->acl_get('m_approve', $forum_id)) ? '' : ' AND p.post_approved = 1');
119
        break;
120
121
        case 'smilies':
122
                $sql = '';
123
                generate_smilies('window', $forum_id);
124
        break;
125
126
        case 'popup':
127
                if ($forum_id)
128
                {
129
                        $sql = 'SELECT forum_style
130
                                FROM ' . FORUMS_TABLE . '
131
                                WHERE forum_id = ' . $forum_id;
132
                }
133
                else
134
                {
135
                        upload_popup();
136
                        return;
137
                }
138
        break;
139
140
        default:
141
                $sql = '';
142
        break;
143
}
144
145
if (!$sql)
146
{
147
        $user->setup('posting');
148
        trigger_error('NO_POST_MODE');
149
}
150
151
$result = $db->sql_query($sql);
152
$post_data = $db->sql_fetchrow($result);
153
$db->sql_freeresult($result);
154
155
if (!$post_data)
156
{
157
        if (!($mode == 'post' || $mode == 'bump' || $mode == 'reply'))
158
        {
159
                $user->setup('posting');
160
        }
161
        trigger_error(($mode == 'post' || $mode == 'bump' || $mode == 'reply') ? 'NO_TOPIC' : 'NO_POST');
162
}
163
164
// Not able to reply to unapproved posts/topics
165
// TODO: add more descriptive language key
166
if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && !$post_data['topic_approved']) || ($mode == 'quote' && !$post_data['post_approved'])))
167
{
168
        trigger_error(($mode == 'reply' || $mode == 'bump') ? 'TOPIC_UNAPPROVED' : 'POST_UNAPPROVED');
169
}
170
171
if ($mode == 'popup')
172
{
173
        upload_popup($post_data['forum_style']);
174
        return;
175
}
176
177
$user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
178
179
if ($config['enable_post_confirm'] && !$user->data['is_registered'])
180
{
181
        include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
182
        $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
183
        $captcha->init(CONFIRM_POST);
184
}
185
186
// Use post_row values in favor of submitted ones...
187
$forum_id        = (!empty($post_data['forum_id'])) ? (int) $post_data['forum_id'] : (int) $forum_id;
188
$topic_id        = (!empty($post_data['topic_id'])) ? (int) $post_data['topic_id'] : (int) $topic_id;
189
$post_id        = (!empty($post_data['post_id'])) ? (int) $post_data['post_id'] : (int) $post_id;
190
191
// Need to login to passworded forum first?
192
if ($post_data['forum_password'])
193
{
194
        login_forum_box(array(
195
                'forum_id'                        => $forum_id,
196
                'forum_password'        => $post_data['forum_password'])
197
        );
198
}
199
200
// Check permissions
201
if ($user->data['is_bot'])
202
{
203
        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
204
}
205
206
// Is the user able to read within this forum?
207
if (!$auth->acl_get('f_read', $forum_id))
208
{
209
        if ($user->data['user_id'] != ANONYMOUS)
210
        {
211
                trigger_error('USER_CANNOT_READ');
212
        }
213
214
        login_box('', $user->lang['LOGIN_EXPLAIN_POST']);
215
}
216
217
// Permission to do the action asked?
218
$is_authed = false;
219
220
switch ($mode)
221
{
222
        case 'post':
223
                if ($auth->acl_get('f_post', $forum_id))
224
                {
225
                        $is_authed = true;
226
                }
227
        break;
228
229
        case 'bump':
230
                if ($auth->acl_get('f_bump', $forum_id))
231
                {
232
                        $is_authed = true;
233
                }
234
        break;
235
236
        case 'quote':
237
238
                $post_data['post_edit_locked'] = 0;
239
240
        // no break;
241
242
        case 'reply':
243
                if ($auth->acl_get('f_reply', $forum_id))
244
                {
245
                        $is_authed = true;
246
                }
247
        break;
248
249
        case 'edit':
250
                if ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id))
251
                {
252
                        $is_authed = true;
253
                }
254
        break;
255
256
        case 'delete':
257
                if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id))
258
                {
259
                        $is_authed = true;
260
                }
261
        break;
262
}
263
264
if (!$is_authed)
265
{
266
        $check_auth = ($mode == 'quote') ? 'reply' : $mode;
267
268
        if ($user->data['is_registered'])
269
        {
270
                trigger_error('USER_CANNOT_' . strtoupper($check_auth));
271
        }
272
273
        login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
274
}
275
276
// Is the user able to post within this forum?
277
if ($post_data['forum_type'] != FORUM_POST && in_array($mode, array('post', 'bump', 'quote', 'reply')))
278
{
279
        trigger_error('USER_CANNOT_FORUM_POST');
280
}
281
282
// Forum/Topic locked?
283
if (($post_data['forum_status'] == ITEM_LOCKED || (isset($post_data['topic_status']) && $post_data['topic_status'] == ITEM_LOCKED)) && !$auth->acl_get('m_edit', $forum_id))
284
{
285
        trigger_error(($post_data['forum_status'] == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
286
}
287
288
// Can we edit this post ... if we're a moderator with rights then always yes
289
// else it depends on editing times, lock status and if we're the correct user
290
if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id))
291
{
292
        if ($user->data['user_id'] != $post_data['poster_id'])
293
        {
294
                trigger_error('USER_CANNOT_EDIT');
295
        }
296
297
        if (!($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time']))
298
        {
299
                trigger_error('CANNOT_EDIT_TIME');
300
        }
301
302
        if ($post_data['post_edit_locked'])
303
        {
304
                trigger_error('CANNOT_EDIT_POST_LOCKED');
305
        }
306
}
307
308
// Handle delete mode...
309
if ($mode == 'delete')
310
{
311
        handle_post_delete($forum_id, $topic_id, $post_id, $post_data);
312
        return;
313
}
314
315
// Handle bump mode...
316
if ($mode == 'bump')
317
{
318
        if ($bump_time = bump_topic_allowed($forum_id, $post_data['topic_bumped'], $post_data['topic_last_post_time'], $post_data['topic_poster'], $post_data['topic_last_poster_id'])
319
           && check_link_hash(request_var('hash', ''), "topic_{$post_data['topic_id']}"))
320
        {
321
                $meta_url = phpbb_bump_topic($forum_id, $topic_id, $post_data, $current_time);
322
                meta_refresh(3, $meta_url);
323
324
                $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . $user->lang('VIEW_MESSAGE', '<a href="' . $meta_url . '">', '</a>');
325
                $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
326
327
                trigger_error($message);
328
        }
329
330
        trigger_error('BUMP_ERROR');
331
}
332
333
// Subject length limiting to 60 characters if first post...
334
if ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_data['post_id']))
335
{
336
        $template->assign_var('S_NEW_MESSAGE', true);
337
}
338
339
// Determine some vars
340
if (isset($post_data['poster_id']) && $post_data['poster_id'] == ANONYMOUS)
341
{
342
        $post_data['quote_username'] = (!empty($post_data['post_username'])) ? $post_data['post_username'] : $user->lang['GUEST'];
343
}
344
else
345
{
346
        $post_data['quote_username'] = isset($post_data['username']) ? $post_data['username'] : '';
347
}
348
349
$post_data['post_edit_locked']        = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
350
$post_data['post_subject_md5']        = (isset($post_data['post_subject']) && $mode == 'edit') ? md5($post_data['post_subject']) : '';
351
$post_data['post_subject']                = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
352
$post_data['topic_time_limit']        = (isset($post_data['topic_time_limit'])) ? (($post_data['topic_time_limit']) ? (int) $post_data['topic_time_limit'] / 86400 : (int) $post_data['topic_time_limit']) : 0;
353
$post_data['poll_length']                = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
354
$post_data['poll_start']                = (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0;
355
$post_data['icon_id']                        = (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id'];
356
$post_data['poll_options']                = array();
357
358
// Get Poll Data
359
if ($post_data['poll_start'])
360
{
361
        $sql = 'SELECT poll_option_text
362
                FROM ' . POLL_OPTIONS_TABLE . "
363
                WHERE topic_id = $topic_id
364
                ORDER BY poll_option_id";
365
        $result = $db->sql_query($sql);
366
367
        while ($row = $db->sql_fetchrow($result))
368
        {
369
                $post_data['poll_options'][] = trim($row['poll_option_text']);
370
        }
371
        $db->sql_freeresult($result);
372
}
373
374
if ($mode == 'edit')
375
{
376
        $original_poll_data = array(
377
                'poll_title'                => $post_data['poll_title'],
378
                'poll_length'                => $post_data['poll_length'],
379
                'poll_max_options'        => $post_data['poll_max_options'],
380
                'poll_option_text'        => implode("\n", $post_data['poll_options']),
381
                'poll_start'                => $post_data['poll_start'],
382
                'poll_last_vote'        => $post_data['poll_last_vote'],
383
                'poll_vote_change'        => $post_data['poll_vote_change'],
384
        );
385
}
386
387
$orig_poll_options_size = sizeof($post_data['poll_options']);
388
389
$message_parser = new parse_message();
390
391
if (isset($post_data['post_text']))
392
{
393
        $message_parser->message = &$post_data['post_text'];
394
        unset($post_data['post_text']);
395
}
396
397
// Set some default variables
398
$uninit = array('post_attachment' => 0, 'poster_id' => $user->data['user_id'], 'enable_magic_url' => 0, 'topic_status' => 0, 'topic_type' => POST_NORMAL, 'post_subject' => '', 'topic_title' => '', 'post_time' => 0, 'post_edit_reason' => '', 'notify_set' => 0);
399
400
foreach ($uninit as $var_name => $default_value)
401
{
402
        if (!isset($post_data[$var_name]))
403
        {
404
                $post_data[$var_name] = $default_value;
405
        }
406
}
407
unset($uninit);
408
409
// Always check if the submitted attachment data is valid and belongs to the user.
410
// Further down (especially in submit_post()) we do not check this again.
411
$message_parser->get_submitted_attachment_data($post_data['poster_id']);
412
413
if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit')
414
{
415
        // Do not change to SELECT *
416
        $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
417
                FROM ' . ATTACHMENTS_TABLE . "
418
                WHERE post_msg_id = $post_id
419
                        AND in_message = 0
420
                        AND is_orphan = 0
421
                ORDER BY filetime DESC";
422
        $result = $db->sql_query($sql);
423
        $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
424
        $db->sql_freeresult($result);
425
}
426
427
if ($post_data['poster_id'] == ANONYMOUS)
428
{
429
        $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : '';
430
}
431
else
432
{
433
        $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : '';
434
}
435
436
$post_data['enable_urls'] = $post_data['enable_magic_url'];
437
438
if ($mode != 'edit')
439
{
440
        $post_data['enable_sig']                = ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false;
441
        $post_data['enable_smilies']        = ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false;
442
        $post_data['enable_bbcode']                = ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false;
443
        $post_data['enable_urls']                = true;
444
}
445
446
$post_data['enable_magic_url'] = $post_data['drafts'] = false;
447
448
// User own some drafts?
449
if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
450
{
451
        $sql = 'SELECT draft_id
452
                FROM ' . DRAFTS_TABLE . '
453
                WHERE user_id = ' . $user->data['user_id'] .
454
                        (($forum_id) ? ' AND forum_id = ' . (int) $forum_id : '') .
455
                        (($topic_id) ? ' AND topic_id = ' . (int) $topic_id : '') .
456
                        (($draft_id) ? " AND draft_id <> $draft_id" : '');
457
        $result = $db->sql_query_limit($sql, 1);
458
459
        if ($db->sql_fetchrow($result))
460
        {
461
                $post_data['drafts'] = true;
462
        }
463
        $db->sql_freeresult($result);
464
}
465
466
$check_value = (($post_data['enable_bbcode']+1) << 8) + (($post_data['enable_smilies']+1) << 4) + (($post_data['enable_urls']+1) << 2) + (($post_data['enable_sig']+1) << 1);
467
468
// Check if user is watching this topic
469
if ($mode != 'post' && $config['allow_topic_notify'] && $user->data['is_registered'])
470
{
471
        $sql = 'SELECT topic_id
472
                FROM ' . TOPICS_WATCH_TABLE . '
473
                WHERE topic_id = ' . $topic_id . '
474
                        AND user_id = ' . $user->data['user_id'];
475
        $result = $db->sql_query($sql);
476
        $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
477
        $db->sql_freeresult($result);
478
}
479
480
// Do we want to edit our post ?
481
if ($mode == 'edit' && $post_data['bbcode_uid'])
482
{
483
        $message_parser->bbcode_uid = $post_data['bbcode_uid'];
484
}
485
486
// HTML, BBCode, Smilies, Images and Flash status
487
$bbcode_status        = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false;
488
$smilies_status        = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
489
$img_status                = ($bbcode_status && $auth->acl_get('f_img', $forum_id)) ? true : false;
490
$url_status                = ($config['allow_post_links']) ? true : false;
491
$flash_status        = ($bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash']) ? true : false;
492
$quote_status        = true;
493
494
// Save Draft
495
if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
496
{
497
        $subject = utf8_normalize_nfc(request_var('subject', '', true));
498
        $subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject;
499
        $message = utf8_normalize_nfc(request_var('message', '', true));
500
501
        if ($subject && $message)
502
        {
503
                if (confirm_box(true))
504
                {
505
                        $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
506
                                'user_id'                => (int) $user->data['user_id'],
507
                                'topic_id'                => (int) $topic_id,
508
                                'forum_id'                => (int) $forum_id,
509
                                'save_time'                => (int) $current_time,
510
                                'draft_subject'        => (string) $subject,
511
                                'draft_message'        => (string) $message)
512
                        );
513
                        $db->sql_query($sql);
514
515
                        $meta_info = ($mode == 'post') ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) : append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
516
517
                        meta_refresh(3, $meta_info);
518
519
                        $message = $user->lang['DRAFT_SAVED'] . '<br /><br />';
520
                        $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : '';
521
                        $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
522
523
                        trigger_error($message);
524
                }
525
                else
526
                {
527
                        $s_hidden_fields = build_hidden_fields(array(
528
                                'mode'                => $mode,
529
                                'save'                => true,
530
                                'f'                        => $forum_id,
531
                                't'                        => $topic_id,
532
                                'subject'        => $subject,
533
                                'message'        => $message,
534
                                'attachment_data' => $message_parser->attachment_data,
535
                                )
536
                        );
537
538
                        $hidden_fields = array(
539
                                'icon_id'                        => 0,
540
541
                                'disable_bbcode'        => false,
542
                                'disable_smilies'        => false,
543
                                'disable_magic_url'        => false,
544
                                'attach_sig'                => true,
545
                                'lock_topic'                => false,
546
547
                                'topic_type'                => POST_NORMAL,
548
                                'topic_time_limit'        => 0,
549
550
                                'poll_title'                => '',
551
                                'poll_option_text'        => '',
552
                                'poll_max_options'        => 1,
553
                                'poll_length'                => 0,
554
                                'poll_vote_change'        => false,
555
                        );
556
557
                        foreach ($hidden_fields as $name => $default)
558
                        {
559
                                if (!isset($_POST[$name]))
560
                                {
561
                                        // Don't include it, if its not available
562
                                        unset($hidden_fields[$name]);
563
                                        continue;
564
                                }
565
566
                                if (is_bool($default))
567
                                {
568
                                        // Use the string representation
569
                                        $hidden_fields[$name] = request_var($name, '');
570
                                }
571
                                else
572
                                {
573
                                        $hidden_fields[$name] = request_var($name, $default);
574
                                }
575
                        }
576
577
                        $s_hidden_fields .= build_hidden_fields($hidden_fields);
578
579
                        confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
580
                }
581
        }
582
        else
583
        {
584
                if (utf8_clean_string($subject) === '')
585
                {
586
                        $error[] = $user->lang['EMPTY_SUBJECT'];
587
                }
588
589
                if (utf8_clean_string($message) === '')
590
                {
591
                        $error[] = $user->lang['TOO_FEW_CHARS'];
592
                }
593
        }
594
        unset($subject, $message);
595
}
596
597
// Load requested Draft
598
if ($draft_id && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
599
{
600
        $sql = 'SELECT draft_subject, draft_message
601
                FROM ' . DRAFTS_TABLE . "
602
                WHERE draft_id = $draft_id
603
                        AND user_id = " . $user->data['user_id'];
604
        $result = $db->sql_query_limit($sql, 1);
605
        $row = $db->sql_fetchrow($result);
606
        $db->sql_freeresult($result);
607
608
        if ($row)
609
        {
610
                $post_data['post_subject'] = $row['draft_subject'];
611
                $message_parser->message = $row['draft_message'];
612
613
                $template->assign_var('S_DRAFT_LOADED', true);
614
        }
615
        else
616
        {
617
                $draft_id = 0;
618
        }
619
}
620
621
// Load draft overview
622
if ($load && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_data['drafts'])
623
{
624
        load_drafts($topic_id, $forum_id);
625
}
626
627
628
if ($submit || $preview || $refresh)
629
{
630
        $post_data['topic_cur_post_id']        = request_var('topic_cur_post_id', 0);
631
        $post_data['post_subject']                = utf8_normalize_nfc(request_var('subject', '', true));
632
        $message_parser->message                = utf8_normalize_nfc(request_var('message', '', true));
633
634
        $post_data['username']                        = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
635
        $post_data['post_edit_reason']        = ($request->variable('edit_reason', false, false, phpbb_request_interface::POST) && $mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? utf8_normalize_nfc(request_var('edit_reason', '', true)) : '';
636
637
        $post_data['orig_topic_type']        = $post_data['topic_type'];
638
        $post_data['topic_type']                = request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL));
639
        $post_data['topic_time_limit']        = request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0));
640
641
        if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
642
        {
643
                $post_data['icon_id'] = request_var('icon', (int) $post_data['icon_id']);
644
        }
645
646
        $post_data['enable_bbcode']                = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
647
        $post_data['enable_smilies']        = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
648
        $post_data['enable_urls']                = (isset($_POST['disable_magic_url'])) ? 0 : 1;
649
        $post_data['enable_sig']                = (!$config['allow_sig'] || !$auth->acl_get('f_sigs', $forum_id) || !$auth->acl_get('u_sig')) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false);
650
651
        if ($config['allow_topic_notify'] && $user->data['is_registered'])
652
        {
653
                $notify = (isset($_POST['notify'])) ? true : false;
654
        }
655
        else
656
        {
657
                $notify = false;
658
        }
659
660
        $topic_lock                        = (isset($_POST['lock_topic'])) ? true : false;
661
        $post_lock                        = (isset($_POST['lock_post'])) ? true : false;
662
        $poll_delete                = (isset($_POST['poll_delete'])) ? true : false;
663
664
        if ($submit)
665
        {
666
                $status_switch = (($post_data['enable_bbcode']+1) << 8) + (($post_data['enable_smilies']+1) << 4) + (($post_data['enable_urls']+1) << 2) + (($post_data['enable_sig']+1) << 1);
667
                $status_switch = ($status_switch != $check_value);
668
        }
669
        else
670
        {
671
                $status_switch = 1;
672
        }
673
674
        // Delete Poll
675
        if ($poll_delete && $mode == 'edit' && sizeof($post_data['poll_options']) &&
676
                ((!$post_data['poll_last_vote'] && $post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id)))
677
        {
678
                if ($submit && check_form_key('posting'))
679
                {
680
                        $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
681
                                WHERE topic_id = $topic_id";
682
                        $db->sql_query($sql);
683
684
                        $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
685
                                WHERE topic_id = $topic_id";
686
                        $db->sql_query($sql);
687
688
                        $topic_sql = array(
689
                                'poll_title'                => '',
690
                                'poll_start'                 => 0,
691
                                'poll_length'                => 0,
692
                                'poll_last_vote'        => 0,
693
                                'poll_max_options'        => 0,
694
                                'poll_vote_change'        => 0
695
                        );
696
697
                        $sql = 'UPDATE ' . TOPICS_TABLE . '
698
                                SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
699
                                WHERE topic_id = $topic_id";
700
                        $db->sql_query($sql);
701
                }
702
703
                $post_data['poll_title'] = $post_data['poll_option_text'] = '';
704
                $post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0;
705
        }
706
        else
707
        {
708
                $post_data['poll_title']                = utf8_normalize_nfc(request_var('poll_title', '', true));
709
                $post_data['poll_length']                = request_var('poll_length', 0);
710
                $post_data['poll_option_text']        = utf8_normalize_nfc(request_var('poll_option_text', '', true));
711
                $post_data['poll_max_options']        = request_var('poll_max_options', 1);
712
                $post_data['poll_vote_change']        = ($auth->acl_get('f_votechg', $forum_id) && $auth->acl_get('f_vote', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0;
713
        }
714
715
        // If replying/quoting and last post id has changed
716
        // give user option to continue submit or return to post
717
        // notify and show user the post made between his request and the final submit
718
        if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id'])
719
        {
720
                // Only do so if it is allowed forum-wide
721
                if ($post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
722
                {
723
                        if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id']))
724
                        {
725
                                $template->assign_var('S_POST_REVIEW', true);
726
                        }
727
728
                        $submit = false;
729
                        $refresh = true;
730
                }
731
        }
732
733
        // Parse Attachments - before checksum is calculated
734
        $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
735
736
        // Grab md5 'checksum' of new message
737
        $message_md5 = md5($message_parser->message);
738
739
        // If editing and checksum has changed we know the post was edited while we're editing
740
        // Notify and show user the changed post
741
        if ($mode == 'edit' && $post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
742
        {
743
                $edit_post_message_checksum = request_var('edit_post_message_checksum', '');
744
                $edit_post_subject_checksum = request_var('edit_post_subject_checksum', '');
745
746
                // $post_data['post_checksum'] is the checksum of the post submitted in the meantime
747
                // $message_md5 is the checksum of the post we're about to submit
748
                // $edit_post_message_checksum is the checksum of the post we're editing
749
                // ...
750
751
                // We make sure nobody else made exactly the same change
752
                // we're about to submit by also checking $message_md5 != $post_data['post_checksum']
753
                if (($edit_post_message_checksum !== '' && $edit_post_message_checksum != $post_data['post_checksum'] && $message_md5 != $post_data['post_checksum'])
754
                 || ($edit_post_subject_checksum !== '' && $edit_post_subject_checksum != $post_data['post_subject_md5'] && md5($post_data['post_subject']) != $post_data['post_subject_md5']))
755
                {
756
                        if (topic_review($topic_id, $forum_id, 'post_review_edit', $post_id))
757
                        {
758
                                $template->assign_vars(array(
759
                                        'S_POST_REVIEW'                        => true,
760
761
                                        'L_POST_REVIEW'                        => $user->lang['POST_REVIEW_EDIT'],
762
                                        'L_POST_REVIEW_EXPLAIN'        => $user->lang['POST_REVIEW_EDIT_EXPLAIN'],
763
                                ));
764
                        }
765
766
                        $submit = false;
767
                        $refresh = true;
768
                }
769
        }
770
771
        // Check checksum ... don't re-parse message if the same
772
        $update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch || strlen($post_data['bbcode_uid']) < BBCODE_UID_LEN) ? true : false;
773
774
        // Also check if subject got updated...
775
        $update_subject = $mode != 'edit' || ($post_data['post_subject_md5'] && $post_data['post_subject_md5'] != md5($post_data['post_subject']));
776
777
        // Parse message
778
        if ($update_message)
779
        {
780
                if (sizeof($message_parser->warn_msg))
781
                {
782
                        $error[] = implode('<br />', $message_parser->warn_msg);
783
                        $message_parser->warn_msg = array();
784
                }
785
786
                $message_parser->parse($post_data['enable_bbcode'], ($config['allow_post_links']) ? $post_data['enable_urls'] : false, $post_data['enable_smilies'], $img_status, $flash_status, $quote_status, $config['allow_post_links']);
787
788
                // On a refresh we do not care about message parsing errors
789
                if (sizeof($message_parser->warn_msg) && $refresh)
790
                {
791
                        $message_parser->warn_msg = array();
792
                }
793
        }
794
        else
795
        {
796
                $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
797
        }
798
799
        if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
800
        {
801
                // Flood check
802
                $last_post_time = 0;
803
804
                if ($user->data['is_registered'])
805
                {
806
                        $last_post_time = $user->data['user_lastpost_time'];
807
                }
808
                else
809
                {
810
                        $sql = 'SELECT post_time AS last_post_time
811
                                FROM ' . POSTS_TABLE . "
812
                                WHERE poster_ip = '" . $user->ip . "'
813
                                        AND post_time > " . ($current_time - $config['flood_interval']);
814
                        $result = $db->sql_query_limit($sql, 1);
815
                        if ($row = $db->sql_fetchrow($result))
816
                        {
817
                                $last_post_time = $row['last_post_time'];
818
                        }
819
                        $db->sql_freeresult($result);
820
                }
821
822
                if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
823
                {
824
                        $error[] = $user->lang['FLOOD_ERROR'];
825
                }
826
        }
827
828
        // Validate username
829
        if (($post_data['username'] && !$user->data['is_registered']) || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS && $post_data['username'] && $post_data['post_username'] && $post_data['post_username'] != $post_data['username']))
830
        {
831
                include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
832
833
                $user->add_lang('ucp');
834
835
                if (($result = validate_username($post_data['username'], (!empty($post_data['post_username'])) ? $post_data['post_username'] : '')) !== false)
836
                {
837
                        $error[] = $user->lang[$result . '_USERNAME'];
838
                }
839
840
                if (($result = validate_string($post_data['username'], false, $config['min_name_chars'], $config['max_name_chars'])) !== false)
841
                {
842
                        $min_max_amount = ($result == 'TOO_SHORT') ? $config['min_name_chars'] : $config['max_name_chars'];
843
                        $error[] = $user->lang('FIELD_' . $result, $min_max_amount, $user->lang['USERNAME']);
844
                }
845
        }
846
847
        if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
848
        {
849
                $captcha_data = array(
850
                        'message'        => utf8_normalize_nfc(request_var('message', '', true)),
851
                        'subject'        => utf8_normalize_nfc(request_var('subject', '', true)),
852
                        'username'        => utf8_normalize_nfc(request_var('username', '', true)),
853
                );
854
                $vc_response = $captcha->validate($captcha_data);
855
                if ($vc_response)
856
                {
857
                        $error[] = $vc_response;
858
                }
859
        }
860
861
        // check form
862
        if (($submit || $preview) && !check_form_key('posting'))
863
        {
864
                $error[] = $user->lang['FORM_INVALID'];
865
        }
866
867
        // Parse subject
868
        if (!$preview && !$refresh && utf8_clean_string($post_data['post_subject']) === '' && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
869
        {
870
                $error[] = $user->lang['EMPTY_SUBJECT'];
871
        }
872
873
        $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0;
874
875
        if ($post_data['poll_option_text'] &&
876
                ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
877
                && $auth->acl_get('f_poll', $forum_id))
878
        {
879
                $poll = array(
880
                        'poll_title'                => $post_data['poll_title'],
881
                        'poll_length'                => $post_data['poll_length'],
882
                        'poll_max_options'        => $post_data['poll_max_options'],
883
                        'poll_option_text'        => $post_data['poll_option_text'],
884
                        'poll_start'                => $post_data['poll_start'],
885
                        'poll_last_vote'        => $post_data['poll_last_vote'],
886
                        'poll_vote_change'        => $post_data['poll_vote_change'],
887
                        'enable_bbcode'                => $post_data['enable_bbcode'],
888
                        'enable_urls'                => $post_data['enable_urls'],
889
                        'enable_smilies'        => $post_data['enable_smilies'],
890
                        'img_status'                => $img_status
891
                );
892
893
                $message_parser->parse_poll($poll);
894
895
                $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : array();
896
                $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
897
898
                /* We reset votes, therefore also allow removing options
899
                if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
900
                {
901
                        $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
902
                }*/
903
        }
904
        else if ($mode == 'edit' && $post_id == $post_data['topic_first_post_id'] && $auth->acl_get('f_poll', $forum_id))
905
        {
906
                // The user removed all poll options, this is equal to deleting the poll.
907
                $poll = array(
908
                        'poll_title'                => '',
909
                        'poll_length'                => 0,
910
                        'poll_max_options'        => 0,
911
                        'poll_option_text'        => '',
912
                        'poll_start'                => 0,
913
                        'poll_last_vote'        => 0,
914
                        'poll_vote_change'        => 0,
915
                        'poll_options'                => array(),
916
                );
917
918
                $post_data['poll_options'] = array();
919
                $post_data['poll_title'] = '';
920
                $post_data['poll_start'] = $post_data['poll_length'] = $post_data['poll_max_options'] = $post_data['poll_last_vote'] = $post_data['poll_vote_change'] = 0;
921
        }
922
        else if (!$auth->acl_get('f_poll', $forum_id) && ($mode == 'edit') && ($post_id == $post_data['topic_first_post_id']) && ($original_poll_data['poll_title'] != ''))
923
        {
924
                // We have a poll but the editing user is not permitted to create/edit it.
925
                // So we just keep the original poll-data.
926
                $poll = array_merge($original_poll_data, array(
927
                        'enable_bbcode'                => $post_data['enable_bbcode'],
928
                        'enable_urls'                => $post_data['enable_urls'],
929
                        'enable_smilies'        => $post_data['enable_smilies'],
930
                        'img_status'                => $img_status,
931
                ));
932
933
                $message_parser->parse_poll($poll);
934
935
                $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : array();
936
                $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
937
        }
938
        else
939
        {
940
                $poll = array();
941
        }
942
943
        // Check topic type
944
        if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
945
        {
946
                switch ($post_data['topic_type'])
947
                {
948
                        case POST_GLOBAL:
949
                        case POST_ANNOUNCE:
950
                                $auth_option = 'f_announce';
951
                        break;
952
953
                        case POST_STICKY:
954
                                $auth_option = 'f_sticky';
955
                        break;
956
957
                        default:
958
                                $auth_option = '';
959
                        break;
960
                }
961
962
                if (!$auth->acl_get($auth_option, $forum_id))
963
                {
964
                        // There is a special case where a user edits his post whereby the topic type got changed by an admin/mod.
965
                        // Another case would be a mod not having sticky permissions for example but edit permissions.
966
                        if ($mode == 'edit')
967
                        {
968
                                // To prevent non-authed users messing around with the topic type we reset it to the original one.
969
                                $post_data['topic_type'] = $post_data['orig_topic_type'];
970
                        }
971
                        else
972
                        {
973
                                $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
974
                        }
975
                }
976
        }
977
978
        if (sizeof($message_parser->warn_msg))
979
        {
980
                $error[] = implode('<br />', $message_parser->warn_msg);
981
        }
982
983
        // DNSBL check
984
        if ($config['check_dnsbl'] && !$refresh)
985
        {
986
                if (($dnsbl = $user->check_dnsbl('post')) !== false)
987
                {
988
                        $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
989
                }
990
        }
991
992
        // Store message, sync counters
993
        if (!sizeof($error) && $submit)
994
        {
995
                if ($submit)
996
                {
997
                        // Lock/Unlock Topic
998
                        $change_topic_status = $post_data['topic_status'];
999
                        $perm_lock_unlock = ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && !empty($post_data['topic_poster']) && $user->data['user_id'] == $post_data['topic_poster'] && $post_data['topic_status'] == ITEM_UNLOCKED)) ? true : false;
1000
1001
                        if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
1002
                        {
1003
                                $change_topic_status = ITEM_UNLOCKED;
1004
                        }
1005
                        else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
1006
                        {
1007
                                $change_topic_status = ITEM_LOCKED;
1008
                        }
1009
1010
                        if ($change_topic_status != $post_data['topic_status'])
1011
                        {
1012
                                $sql = 'UPDATE ' . TOPICS_TABLE . "
1013
                                        SET topic_status = $change_topic_status
1014
                                        WHERE topic_id = $topic_id
1015
                                                AND topic_moved_id = 0";
1016
                                $db->sql_query($sql);
1017
1018
                                $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : '';
1019
1020
                                add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']);
1021
                        }
1022
1023
                        // Lock/Unlock Post Edit
1024
                        if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
1025
                        {
1026
                                $post_data['post_edit_locked'] = ITEM_UNLOCKED;
1027
                        }
1028
                        else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
1029
                        {
1030
                                $post_data['post_edit_locked'] = ITEM_LOCKED;
1031
                        }
1032
1033
                        $data = array(
1034
                                'topic_title'                        => (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
1035
                                'topic_first_post_id'        => (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
1036
                                'topic_last_post_id'        => (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
1037
                                'topic_time_limit'                => (int) $post_data['topic_time_limit'],
1038
                                'topic_attachment'                => (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
1039
                                'post_id'                                => (int) $post_id,
1040
                                'topic_id'                                => (int) $topic_id,
1041
                                'forum_id'                                => (int) $forum_id,
1042
                                'icon_id'                                => (int) $post_data['icon_id'],
1043
                                'poster_id'                                => (int) $post_data['poster_id'],
1044
                                'enable_sig'                        => (bool) $post_data['enable_sig'],
1045
                                'enable_bbcode'                        => (bool) $post_data['enable_bbcode'],
1046
                                'enable_smilies'                => (bool) $post_data['enable_smilies'],
1047
                                'enable_urls'                        => (bool) $post_data['enable_urls'],
1048
                                'enable_indexing'                => (bool) $post_data['enable_indexing'],
1049
                                'message_md5'                        => (string) $message_md5,
1050
                                'post_time'                                => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
1051
                                'post_checksum'                        => (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
1052
                                'post_edit_reason'                => $post_data['post_edit_reason'],
1053
                                'post_edit_user'                => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
1054
                                'forum_parents'                        => $post_data['forum_parents'],
1055
                                'forum_name'                        => $post_data['forum_name'],
1056
                                'notify'                                => $notify,
1057
                                'notify_set'                        => $post_data['notify_set'],
1058
                                'poster_ip'                                => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
1059
                                'post_edit_locked'                => (int) $post_data['post_edit_locked'],
1060
                                'bbcode_bitfield'                => $message_parser->bbcode_bitfield,
1061
                                'bbcode_uid'                        => $message_parser->bbcode_uid,
1062
                                'message'                                => $message_parser->message,
1063
                                'attachment_data'                => $message_parser->attachment_data,
1064
                                'filename_data'                        => $message_parser->filename_data,
1065
1066
                                'topic_approved'                => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false,
1067
                                'post_approved'                        => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false,
1068
                        );
1069
1070
                        if ($mode == 'edit')
1071
                        {
1072
                                $data['topic_replies_real'] = $post_data['topic_replies_real'];
1073
                                $data['topic_replies'] = $post_data['topic_replies'];
1074
                        }
1075
1076
                        // The last parameter tells submit_post if search indexer has to be run
1077
                        $redirect_url = submit_post($mode, $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message, ($update_message || $update_subject) ? true : false);
1078
1079
                        if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === true) && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
1080
                        {
1081
                                $captcha->reset();
1082
                        }
1083
1084
                        // Check the permissions for post approval. Moderators are not affected.
1085
                        if ((!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id']) && empty($data['force_approved_state'])) || (isset($data['force_approved_state']) && !$data['force_approved_state']))
1086
                        {
1087
                                meta_refresh(10, $redirect_url);
1088
                                $message = ($mode == 'edit') ? $user->lang['POST_EDITED_MOD'] : $user->lang['POST_STORED_MOD'];
1089
                                $message .= (($user->data['user_id'] == ANONYMOUS) ? '' : ' '. $user->lang['POST_APPROVAL_NOTIFY']);
1090
                        }
1091
                        else
1092
                        {
1093
                                meta_refresh(3, $redirect_url);
1094
1095
                                $message = ($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED';
1096
                                $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>');
1097
                        }
1098
1099
                        $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']) . '">', '</a>');
1100
                        trigger_error($message);
1101
                }
1102
        }
1103
}
1104
1105
// Preview
1106
if (!sizeof($error) && $preview)
1107
{
1108
        $post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time;
1109
1110
        $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
1111
1112
        $preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig'];
1113
        $preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
1114
        $preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
1115
1116
        // Signature
1117
        if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
1118
        {
1119
                $parse_sig = new parse_message($preview_signature);
1120
                $parse_sig->bbcode_uid = $preview_signature_uid;
1121
                $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
1122
1123
                // Not sure about parameters for bbcode/smilies/urls... in signatures
1124
                $parse_sig->format_display($config['allow_sig_bbcode'], $config['allow_sig_links'], $config['allow_sig_smilies']);
1125
                $preview_signature = $parse_sig->message;
1126
                unset($parse_sig);
1127
        }
1128
        else
1129
        {
1130
                $preview_signature = '';
1131
        }
1132
1133
        $preview_subject = censor_text($post_data['post_subject']);
1134
1135
        // Poll Preview
1136
        if (!$poll_delete && ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
1137
        && $auth->acl_get('f_poll', $forum_id))
1138
        {
1139
                $parse_poll = new parse_message($post_data['poll_title']);
1140
                $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
1141
                $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
1142
1143
                $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1144
1145
                if ($post_data['poll_length'])
1146
                {
1147
                        $poll_end = ($post_data['poll_length'] * 86400) + (($post_data['poll_start']) ? $post_data['poll_start'] : time());
1148
                }
1149
1150
                $template->assign_vars(array(
1151
                        'S_HAS_POLL_OPTIONS'        => (sizeof($post_data['poll_options'])),
1152
                        'S_IS_MULTI_CHOICE'                => ($post_data['poll_max_options'] > 1) ? true : false,
1153
1154
                        'POLL_QUESTION'                => $parse_poll->message,
1155
1156
                        'L_POLL_LENGTH'                => ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_end)) : '',
1157
                        'L_MAX_VOTES'                => $user->lang('MAX_OPTIONS_SELECT', (int) $post_data['poll_max_options']),
1158
                ));
1159
1160
                $parse_poll->message = implode("\n", $post_data['poll_options']);
1161
                $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1162
                $preview_poll_options = explode('<br />', $parse_poll->message);
1163
                unset($parse_poll);
1164
1165
                foreach ($preview_poll_options as $key => $option)
1166
                {
1167
                        $template->assign_block_vars('poll_option', array(
1168
                                'POLL_OPTION_CAPTION'        => $option,
1169
                                'POLL_OPTION_ID'                => $key + 1)
1170
                        );
1171
                }
1172
                unset($preview_poll_options);
1173
        }
1174
1175
        // Attachment Preview
1176
        if (sizeof($message_parser->attachment_data))
1177
        {
1178
                $template->assign_var('S_HAS_ATTACHMENTS', true);
1179
1180
                $update_count = array();
1181
                $attachment_data = $message_parser->attachment_data;
1182
1183
                parse_attachments($forum_id, $preview_message, $attachment_data, $update_count, true);
1184
1185
                foreach ($attachment_data as $i => $attachment)
1186
                {
1187
                        $template->assign_block_vars('attachment', array(
1188
                                'DISPLAY_ATTACHMENT'        => $attachment)
1189
                        );
1190
                }
1191
                unset($attachment_data);
1192
        }
1193
1194
        if (!sizeof($error))
1195
        {
1196
                $template->assign_vars(array(
1197
                        'PREVIEW_SUBJECT'                => $preview_subject,
1198
                        'PREVIEW_MESSAGE'                => $preview_message,
1199
                        'PREVIEW_SIGNATURE'                => $preview_signature,
1200
1201
                        'S_DISPLAY_PREVIEW'                => true)
1202
                );
1203
        }
1204
}
1205
1206
// Decode text for message display
1207
$post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
1208
$message_parser->decode_message($post_data['bbcode_uid']);
1209
1210
if ($mode == 'quote' && !$submit && !$preview && !$refresh)
1211
{
1212
        if ($config['allow_bbcode'])
1213
        {
1214
                $message_parser->message = '[quote=&quot;' . $post_data['quote_username'] . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
1215
        }
1216
        else
1217
        {
1218
                $offset = 0;
1219
                $quote_string = "&gt; ";
1220
                $message = censor_text(trim($message_parser->message));
1221
                // see if we are nesting. It's easily tricked but should work for one level of nesting
1222
                if (strpos($message, "&gt;") !== false)
1223
                {
1224
                        $offset = 10;
1225
                }
1226
                $message = utf8_wordwrap($message, 75 + $offset, "\n");
1227
1228
                $message = $quote_string . $message;
1229
                $message = str_replace("\n", "\n" . $quote_string, $message);
1230
                $message_parser->message =  $post_data['quote_username'] . " " . $user->lang['WROTE'] . ":\n" . $message . "\n";
1231
        }
1232
}
1233
1234
if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
1235
{
1236
        $post_data['post_subject'] = ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
1237
}
1238
1239
$attachment_data = $message_parser->attachment_data;
1240
$filename_data = $message_parser->filename_data;
1241
$post_data['post_text'] = $message_parser->message;
1242
1243
if (sizeof($post_data['poll_options']) || !empty($post_data['poll_title']))
1244
{
1245
        $message_parser->message = $post_data['poll_title'];
1246
        $message_parser->bbcode_uid = $post_data['bbcode_uid'];
1247
1248
        $message_parser->decode_message();
1249
        $post_data['poll_title'] = $message_parser->message;
1250
1251
        $message_parser->message = implode("\n", $post_data['poll_options']);
1252
        $message_parser->decode_message();
1253
        $post_data['poll_options'] = explode("\n", $message_parser->message);
1254
}
1255
1256
// MAIN POSTING PAGE BEGINS HERE
1257
1258
// Forum moderators?
1259
$moderators = array();
1260
if ($config['load_moderators'])
1261
{
1262
        get_moderators($moderators, $forum_id);
1263
}
1264
1265
// Generate smiley listing
1266
generate_smilies('inline', $forum_id);
1267
1268
// Generate inline attachment select box
1269
posting_gen_inline_attachments($attachment_data);
1270
1271
// Do show topic type selection only in first post.
1272
$topic_type_toggle = false;
1273
1274
if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))
1275
{
1276
        $topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']);
1277
}
1278
1279
$s_topic_icons = false;
1280
if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
1281
{
1282
        $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
1283
}
1284
1285
$bbcode_checked                = (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
1286
$smilies_checked        = (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
1287
$urls_checked                = (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0;
1288
$sig_checked                = $post_data['enable_sig'];
1289
$lock_topic_checked        = (isset($topic_lock) && $topic_lock) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0);
1290
$lock_post_checked        = (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked'];
1291
1292
// If the user is replying or posting and not already watching this topic but set to always being notified we need to overwrite this setting
1293
$notify_set                        = ($mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set']) ? $user->data['user_notify'] : $post_data['notify_set'];
1294
$notify_checked                = (isset($notify)) ? $notify : (($mode == 'post') ? $user->data['user_notify'] : $notify_set);
1295
1296
// Page title & action URL
1297
$s_action = append_sid("{$phpbb_root_path}posting.$phpEx", "mode=$mode&amp;f=$forum_id");
1298
$s_action .= ($topic_id) ? "&amp;t=$topic_id" : '';
1299
$s_action .= ($post_id) ? "&amp;p=$post_id" : '';
1300
1301
switch ($mode)
1302
{
1303
        case 'post':
1304
                $page_title = $user->lang['POST_TOPIC'];
1305
        break;
1306
1307
        case 'quote':
1308
        case 'reply':
1309
                $page_title = $user->lang['POST_REPLY'];
1310
        break;
1311
1312
        case 'delete':
1313
        case 'edit':
1314
                $page_title = $user->lang['EDIT_POST'];
1315
        break;
1316
}
1317
1318
// Build Navigation Links
1319
generate_forum_nav($post_data);
1320
1321
// Build Forum Rules
1322
generate_forum_rules($post_data);
1323
1324
// Posting uses is_solved for legacy reasons. Plugins have to use is_solved to force themselves to be displayed.
1325
if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === false) && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
1326
{
1327
1328
        $template->assign_vars(array(
1329
                'S_CONFIRM_CODE'                        => true,
1330
                'CAPTCHA_TEMPLATE'                        => $captcha->get_template(),
1331
        ));
1332
}
1333
1334
$s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $post_data['topic_last_post_id'] . '" />' : '';
1335
$s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1336
$s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : '';
1337
1338
if ($mode == 'edit')
1339
{
1340
        $s_hidden_fields .= build_hidden_fields(array(
1341
                'edit_post_message_checksum'        => $post_data['post_checksum'],
1342
                'edit_post_subject_checksum'        => $post_data['post_subject_md5'],
1343
        ));
1344
}
1345
1346
// Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
1347
if (isset($captcha) && $captcha->is_solved() !== false)
1348
{
1349
        $s_hidden_fields .= build_hidden_fields($captcha->get_hidden_fields());
1350
}
1351
1352
$form_enctype = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !$config['allow_attachments'] || !$auth->acl_get('u_attach') || !$auth->acl_get('f_attach', $forum_id)) ? '' : ' enctype="multipart/form-data"';
1353
add_form_key('posting');
1354
1355
1356
// Start assigning vars for main posting page ...
1357
$template->assign_vars(array(
1358
        'L_POST_A'                                        => $page_title,
1359
        'L_ICON'                                        => ($mode == 'reply' || $mode == 'quote' || ($mode == 'edit' && $post_id != $post_data['topic_first_post_id'])) ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'],
1360
        'L_MESSAGE_BODY_EXPLAIN'        => $user->lang('MESSAGE_BODY_EXPLAIN', (int) $config['max_post_chars']),
1361
1362
        'FORUM_NAME'                        => $post_data['forum_name'],
1363
        'FORUM_DESC'                        => ($post_data['forum_desc']) ? generate_text_for_display($post_data['forum_desc'], $post_data['forum_desc_uid'], $post_data['forum_desc_bitfield'], $post_data['forum_desc_options']) : '',
1364
        'TOPIC_TITLE'                        => censor_text($post_data['topic_title']),
1365
        'MODERATORS'                        => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '',
1366
        'USERNAME'                                => ((!$preview && $mode != 'quote') || $preview) ? $post_data['username'] : '',
1367
        'SUBJECT'                                => $post_data['post_subject'],
1368
        'MESSAGE'                                => $post_data['post_text'],
1369
        'BBCODE_STATUS'                        => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
1370
        'IMG_STATUS'                        => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
1371
        'FLASH_STATUS'                        => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
1372
        'SMILIES_STATUS'                => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
1373
        'URL_STATUS'                        => ($bbcode_status && $url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
1374
        'MAX_FONT_SIZE'                        => (int) $config['max_post_font_size'],
1375
        'MINI_POST_IMG'                        => $user->img('icon_post_target', $user->lang['POST']),
1376
        'POST_DATE'                                => ($post_data['post_time']) ? $user->format_date($post_data['post_time']) : '',
1377
        'ERROR'                                        => (sizeof($error)) ? implode('<br />', $error) : '',
1378
        'TOPIC_TIME_LIMIT'                => (int) $post_data['topic_time_limit'],
1379
        'EDIT_REASON'                        => $post_data['post_edit_reason'],
1380
        'U_VIEW_FORUM'                        => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"),
1381
        'U_VIEW_TOPIC'                        => ($mode != 'post') ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") : '',
1382
        'U_PROGRESS_BAR'                => append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&amp;mode=popup"),
1383
        'UA_PROGRESS_BAR'                => addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&amp;mode=popup")),
1384
1385
        'S_PRIVMSGS'                                => false,
1386
        'S_CLOSE_PROGRESS_WINDOW'        => (isset($_POST['add_file'])) ? true : false,
1387
        'S_EDIT_POST'                                => ($mode == 'edit') ? true : false,
1388
        'S_EDIT_REASON'                                => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1389
        'S_DISPLAY_USERNAME'                => (!$user->data['is_registered'] || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS)) ? true : false,
1390
        'S_SHOW_TOPIC_ICONS'                => $s_topic_icons,
1391
        'S_DELETE_ALLOWED'                        => ($mode == 'edit' && (($post_id == $post_data['topic_last_post_id'] && $post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && !$post_data['post_edit_locked'] && ($post_data['post_time'] > time() - ($config['delete_time'] * 60) || !$config['delete_time'])) || $auth->acl_get('m_delete', $forum_id))) ? true : false,
1392
        'S_BBCODE_ALLOWED'                        => ($bbcode_status) ? 1 : 0,
1393
        'S_BBCODE_CHECKED'                        => ($bbcode_checked) ? ' checked="checked"' : '',
1394
        'S_SMILIES_ALLOWED'                        => $smilies_status,
1395
        'S_SMILIES_CHECKED'                        => ($smilies_checked) ? ' checked="checked"' : '',
1396
        'S_SIG_ALLOWED'                                => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']) ? true : false,
1397
        'S_SIGNATURE_CHECKED'                => ($sig_checked) ? ' checked="checked"' : '',
1398
        'S_NOTIFY_ALLOWED'                        => (!$user->data['is_registered'] || ($mode == 'edit' && $user->data['user_id'] != $post_data['poster_id']) || !$config['allow_topic_notify'] || !$config['email_enable']) ? false : true,
1399
        'S_NOTIFY_CHECKED'                        => ($notify_checked) ? ' checked="checked"' : '',
1400
        'S_LOCK_TOPIC_ALLOWED'                => (($mode == 'edit' || $mode == 'reply' || $mode == 'quote') && ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && !empty($post_data['topic_poster']) && $user->data['user_id'] == $post_data['topic_poster'] && $post_data['topic_status'] == ITEM_UNLOCKED))) ? true : false,
1401
        'S_LOCK_TOPIC_CHECKED'                => ($lock_topic_checked) ? ' checked="checked"' : '',
1402
        'S_LOCK_POST_ALLOWED'                => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1403
        'S_LOCK_POST_CHECKED'                => ($lock_post_checked) ? ' checked="checked"' : '',
1404
        'S_LINKS_ALLOWED'                        => $url_status,
1405
        'S_MAGIC_URL_CHECKED'                => ($urls_checked) ? ' checked="checked"' : '',
1406
        'S_TYPE_TOGGLE'                                => $topic_type_toggle,
1407
        'S_SAVE_ALLOWED'                        => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $mode != 'edit') ? true : false,
1408
        'S_HAS_DRAFTS'                                => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $post_data['drafts']) ? true : false,
1409
        'S_FORM_ENCTYPE'                        => $form_enctype,
1410
1411
        'S_BBCODE_IMG'                        => $img_status,
1412
        'S_BBCODE_URL'                        => $url_status,
1413
        'S_BBCODE_FLASH'                => $flash_status,
1414
        'S_BBCODE_QUOTE'                => $quote_status,
1415
1416
        'S_POST_ACTION'                        => $s_action,
1417
        'S_HIDDEN_FIELDS'                => $s_hidden_fields)
1418
);
1419
1420
// Build custom bbcodes array
1421
display_custom_bbcodes();
1422
1423
// Poll entry
1424
if (($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
1425
        && $auth->acl_get('f_poll', $forum_id))
1426
{
1427
        $template->assign_vars(array(
1428
                'S_SHOW_POLL_BOX'                => true,
1429
                'S_POLL_VOTE_CHANGE'        => ($auth->acl_get('f_votechg', $forum_id) && $auth->acl_get('f_vote', $forum_id)),
1430
                'S_POLL_DELETE'                        => ($mode == 'edit' && sizeof($post_data['poll_options']) && ((!$post_data['poll_last_vote'] && $post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))),
1431
                'S_POLL_DELETE_CHECKED'        => (!empty($poll_delete)) ? true : false,
1432
1433
                'L_POLL_OPTIONS_EXPLAIN'        => $user->lang('POLL_OPTIONS_' . (($mode == 'edit') ? 'EDIT_' : '') . 'EXPLAIN', (int) $config['max_poll_options']),
1434
1435
                'VOTE_CHANGE_CHECKED'        => (!empty($post_data['poll_vote_change'])) ? ' checked="checked"' : '',
1436
                'POLL_TITLE'                        => (isset($post_data['poll_title'])) ? $post_data['poll_title'] : '',
1437
                'POLL_OPTIONS'                        => (!empty($post_data['poll_options'])) ? implode("\n", $post_data['poll_options']) : '',
1438
                'POLL_MAX_OPTIONS'                => (isset($post_data['poll_max_options'])) ? (int) $post_data['poll_max_options'] : 1,
1439
                'POLL_LENGTH'                        => $post_data['poll_length'])
1440
        );
1441
}
1442
1443
// Show attachment box for adding attachments if true
1444
$allowed = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype);
1445
1446
// Attachment entry
1447
posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
1448
1449
// Output page ...
1450
page_header($page_title, false);
1451
1452
$template->set_filenames(array(
1453
        'body' => 'posting_body.html')
1454
);
1455
1456
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
1457
1458
// Topic review
1459
if ($mode == 'reply' || $mode == 'quote')
1460
{
1461
        if (topic_review($topic_id, $forum_id))
1462
        {
1463
                $template->assign_var('S_DISPLAY_REVIEW', true);
1464
        }
1465
}
1466
1467
page_footer();
1468
1469
/**
1470
* Show upload popup (progress bar)
1471
*/
1472
function upload_popup($forum_style = 0)
1473
{
1474
        global $template, $user;
1475
1476
        ($forum_style) ? $user->setup('posting', $forum_style) : $user->setup('posting');
1477
1478
        page_header($user->lang['PROGRESS_BAR'], false);
1479
1480
        $template->set_filenames(array(
1481
                'popup'        => 'posting_progress_bar.html')
1482
        );
1483
1484
        $template->assign_vars(array(
1485
                'PROGRESS_BAR'        => $user->img('upload_bar', $user->lang['UPLOAD_IN_PROGRESS']))
1486
        );
1487
1488
        $template->display('popup');
1489
1490
        garbage_collection();
1491
        exit_handler();
1492
}
1493
1494
/**
1495
* Do the various checks required for removing posts as well as removing it
1496
*/
1497
function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data)
1498
{
1499
        global $user, $db, $auth, $config;
1500
        global $phpbb_root_path, $phpEx;
1501
1502
        // If moderator removing post or user itself removing post, present a confirmation screen
1503
        if ($auth->acl_get('m_delete', $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get('f_delete', $forum_id) && $post_id == $post_data['topic_last_post_id'] && !$post_data['post_edit_locked'] && ($post_data['post_time'] > time() - ($config['delete_time'] * 60) || !$config['delete_time'])))
1504
        {
1505
                $s_hidden_fields = build_hidden_fields(array(
1506
                        'p'                => $post_id,
1507
                        'f'                => $forum_id,
1508
                        'mode'        => 'delete')
1509
                );
1510
1511
                if (confirm_box(true))
1512
                {
1513
                        $data = array(
1514
                                'topic_first_post_id'        => $post_data['topic_first_post_id'],
1515
                                'topic_last_post_id'        => $post_data['topic_last_post_id'],
1516
                                'topic_replies_real'        => $post_data['topic_replies_real'],
1517
                                'topic_approved'                => $post_data['topic_approved'],
1518
                                'topic_type'                        => $post_data['topic_type'],
1519
                                'post_approved'                        => $post_data['post_approved'],
1520
                                'post_reported'                        => $post_data['post_reported'],
1521
                                'post_time'                                => $post_data['post_time'],
1522
                                'poster_id'                                => $post_data['poster_id'],
1523
                                'post_postcount'                => $post_data['post_postcount']
1524
                        );
1525
1526
                        $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data);
1527
                        $post_username = ($post_data['poster_id'] == ANONYMOUS && !empty($post_data['post_username'])) ? $post_data['post_username'] : $post_data['username'];
1528
1529
                        if ($next_post_id === false)
1530
                        {
1531
                                add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title'], $post_username);
1532
1533
                                $meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
1534
                                $message = $user->lang['POST_DELETED'];
1535
                        }
1536
                        else
1537
                        {
1538
                                add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject'], $post_username);
1539
1540
                                $meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p=$next_post_id") . "#p$next_post_id";
1541
                                $message = $user->lang['POST_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
1542
                        }
1543
1544
                        meta_refresh(3, $meta_info);
1545
                        $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
1546
                        trigger_error($message);
1547
                }
1548
                else
1549
                {
1550
                        confirm_box(false, 'DELETE_POST', $s_hidden_fields);
1551
                }
1552
        }
1553
1554
        // If we are here the user is not able to delete - present the correct error message
1555
        if ($post_data['poster_id'] != $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id))
1556
        {
1557
                trigger_error('DELETE_OWN_POSTS');
1558
        }
1559
1560
        if ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $post_data['topic_last_post_id'])
1561
        {
1562
                trigger_error('CANNOT_DELETE_REPLIED');
1563
        }
1564
1565
        trigger_error('USER_CANNOT_DELETE');
1566
}