source: trunk/forum/posting.php @ 1596

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