/sources/controllers/Post.controller.php
PHP | 2388 lines | 1737 code | 324 blank | 327 comment | 575 complexity | 20edfe0bd7cdd63d6a54702e7833b1db MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * @name ElkArte Forum
- * @copyright ElkArte Forum contributors
- * @license BSD http://opensource.org/licenses/BSD-3-Clause
- *
- * This software is a derived product, based on:
- *
- * Simple Machines Forum (SMF)
- * copyright: 2011 Simple Machines (http://www.simplemachines.org)
- * license: BSD, See included LICENSE.TXT for terms and conditions.
- *
- * @version 1.0 Alpha
- *
- * The job of this file is to handle everything related to posting replies,
- * new topics, quotes, and modifications to existing posts. It also handles
- * quoting posts by way of javascript.
- *
- */
- if (!defined('ELKARTE'))
- die('No access...');
- /**
- * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
- *
- * - additionally handles previews of posts.
- * - @uses the Post template and language file, main sub template.
- * - allows wireless access using the protocol_post sub template.
- * - requires different permissions depending on the actions, but most notably post_new, post_reply_own, and post_reply_any.
- * - shows options for the editing and posting of calendar events and attachments, as well as the posting of polls.
- * - accessed from ?action=post.
- *
- * @param array $post_errors holds any errors found tyring to post
- */
- function action_post()
- {
- global $txt, $scripturl, $topic, $modSettings, $board;
- global $user_info, $context, $settings;
- global $options, $smcFunc, $language;
- loadLanguage('Post');
- // You can't reply with a poll... hacker.
- if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
- unset($_REQUEST['poll']);
- $post_errors = error_context::context('post', 1);
- $attach_errors = error_context::context('attachment', 1);
- // Posting an event?
- $context['make_event'] = isset($_REQUEST['calendar']);
- $context['robot_no_index'] = true;
- // You must be posting to *some* board.
- if (empty($board) && !$context['make_event'])
- fatal_lang_error('no_board', false);
- require_once(SUBSDIR . '/Post.subs.php');
- if (isset($_REQUEST['xml']))
- {
- $context['sub_template'] = 'post';
- // Just in case of an earlier error...
- $context['preview_message'] = '';
- $context['preview_subject'] = '';
- }
- // No message is complete without a topic.
- if (empty($topic) && !empty($_REQUEST['msg']))
- {
- $request = $smcFunc['db_query']('', '
- SELECT id_topic
- FROM {db_prefix}messages
- WHERE id_msg = {int:msg}',
- array(
- 'msg' => (int) $_REQUEST['msg'],
- ));
- if ($smcFunc['db_num_rows']($request) != 1)
- unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
- else
- list ($topic) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- }
- // Check if it's locked. It isn't locked if no topic is specified.
- if (!empty($topic))
- {
- $request = $smcFunc['db_query']('', '
- SELECT
- t.locked, IFNULL(ln.id_topic, 0) AS notify, t.is_sticky, t.id_poll, t.id_last_msg, mf.id_member,
- t.id_first_msg, mf.subject,
- CASE WHEN ml.poster_time > ml.modified_time THEN ml.poster_time ELSE ml.modified_time END AS last_post_time
- FROM {db_prefix}topics AS t
- LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_topic = t.id_topic AND ln.id_member = {int:current_member})
- LEFT JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
- LEFT JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
- WHERE t.id_topic = {int:current_topic}
- LIMIT 1',
- array(
- 'current_member' => $user_info['id'],
- 'current_topic' => $topic,
- )
- );
- list ($locked, $context['notify'], $sticky, $pollID, $context['topic_last_message'], $id_member_poster, $id_first_msg, $first_subject, $lastPostTime) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- // If this topic already has a poll, they sure can't add another.
- if (isset($_REQUEST['poll']) && $pollID > 0)
- unset($_REQUEST['poll']);
- if (empty($_REQUEST['msg']))
- {
- if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
- is_not_guest();
- // By default the reply will be approved...
- $context['becomes_approved'] = true;
- if ($id_member_poster != $user_info['id'])
- {
- if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
- $context['becomes_approved'] = false;
- else
- isAllowedTo('post_reply_any');
- }
- elseif (!allowedTo('post_reply_any'))
- {
- if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
- $context['becomes_approved'] = false;
- else
- isAllowedTo('post_reply_own');
- }
- }
- else
- $context['becomes_approved'] = true;
- $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
- $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);
- $context['notify'] = !empty($context['notify']);
- $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
- // Check whether this is a really old post being bumped...
- if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
- $post_errors->addError(array('old_topic', array($modSettings['oldTopicDays'])), 0);
- }
- else
- {
- $context['becomes_approved'] = true;
- if ((!$context['make_event'] || !empty($board)))
- {
- if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
- $context['becomes_approved'] = false;
- else
- isAllowedTo('post_new');
- }
- $locked = 0;
- // @todo These won't work if you're making an event.
- $context['can_lock'] = allowedTo(array('lock_any', 'lock_own'));
- $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);
- $context['notify'] = !empty($context['notify']);
- $context['sticky'] = !empty($_REQUEST['sticky']);
- }
- // @todo These won't work if you're posting an event!
- $context['can_notify'] = allowedTo('mark_any_notify');
- $context['can_move'] = allowedTo('move_any');
- $context['move'] = !empty($_REQUEST['move']);
- $context['announce'] = !empty($_REQUEST['announce']);
- // You can only announce topics that will get approved...
- $context['can_announce'] = allowedTo('announce_topic') && $context['becomes_approved'];
- $context['locked'] = !empty($locked) || !empty($_REQUEST['lock']);
- $context['can_quote'] = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
- // Generally don't show the approval box... (Assume we want things approved)
- $context['show_approval'] = allowedTo('approve_posts') && $context['becomes_approved'] ? 2 : (allowedTo('approve_posts') ? 1 : 0);
- // An array to hold all the attachments for this topic.
- $context['current_attachments'] = array();
- // Don't allow a post if it's locked and you aren't all powerful.
- if ($locked && !allowedTo('moderate_board'))
- fatal_lang_error('topic_locked', false);
- // Check the users permissions - is the user allowed to add or post a poll?
- if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
- {
- // New topic, new poll.
- if (empty($topic))
- isAllowedTo('poll_post');
- // This is an old topic - but it is yours! Can you add to it?
- elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
- isAllowedTo('poll_add_own');
- // If you're not the owner, can you add to any poll?
- else
- isAllowedTo('poll_add_any');
- $context['can_moderate_poll'] = true;
- require_once(SUBSDIR . '/Members.subs.php');
- $allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
- // Set up the poll options.
- $context['poll'] = array(
- 'max_votes' => empty($_POST['poll_max_votes']) ? '1' : max(1, $_POST['poll_max_votes']),
- 'hide_results' => empty($_POST['poll_hide']) ? 0 : $_POST['poll_hide'],
- 'expiration' => !isset($_POST['poll_expire']) ? '' : $_POST['poll_expire'],
- 'change_vote' => isset($_POST['poll_change_vote']),
- 'guest_vote' => isset($_POST['poll_guest_vote']),
- 'guest_vote_allowed' => in_array(-1, $allowedVoteGroups['allowed']),
- );
- // Make all five poll choices empty.
- $context['choices'] = array(
- array('id' => 0, 'number' => 1, 'label' => '', 'is_last' => false),
- array('id' => 1, 'number' => 2, 'label' => '', 'is_last' => false),
- array('id' => 2, 'number' => 3, 'label' => '', 'is_last' => false),
- array('id' => 3, 'number' => 4, 'label' => '', 'is_last' => false),
- array('id' => 4, 'number' => 5, 'label' => '', 'is_last' => true)
- );
- $context['last_choice_id'] = 4;
- }
- if ($context['make_event'])
- {
- // They might want to pick a board.
- if (!isset($context['current_board']))
- $context['current_board'] = 0;
- // Start loading up the event info.
- $context['event'] = array();
- $context['event']['title'] = isset($_REQUEST['evtitle']) ? htmlspecialchars(stripslashes($_REQUEST['evtitle'])) : '';
- $context['event']['id'] = isset($_REQUEST['eventid']) ? (int) $_REQUEST['eventid'] : -1;
- $context['event']['new'] = $context['event']['id'] == -1;
- // Permissions check!
- isAllowedTo('calendar_post');
- // Editing an event? (but NOT previewing!?)
- if (empty($context['event']['new']) && !isset($_REQUEST['subject']))
- {
- // If the user doesn't have permission to edit the post in this topic, redirect them.
- if ((empty($id_member_poster) || $id_member_poster != $user_info['id'] || !allowedTo('modify_own')) && !allowedTo('modify_any'))
- {
- // @todo this shouldn't call directly CalendarPost()
- require_once(CONTROLLERDIR . '/Calendar.controller.php');
- return CalendarPost();
- }
- // Get the current event information.
- $request = $smcFunc['db_query']('', '
- SELECT
- id_member, title, MONTH(start_date) AS month, DAYOFMONTH(start_date) AS day,
- YEAR(start_date) AS year, (TO_DAYS(end_date) - TO_DAYS(start_date)) AS span
- FROM {db_prefix}calendar
- WHERE id_event = {int:id_event}
- LIMIT 1',
- array(
- 'id_event' => $context['event']['id'],
- )
- );
- $row = $smcFunc['db_fetch_assoc']($request);
- $smcFunc['db_free_result']($request);
- // Make sure the user is allowed to edit this event.
- if ($row['id_member'] != $user_info['id'])
- isAllowedTo('calendar_edit_any');
- elseif (!allowedTo('calendar_edit_any'))
- isAllowedTo('calendar_edit_own');
- $context['event']['month'] = $row['month'];
- $context['event']['day'] = $row['day'];
- $context['event']['year'] = $row['year'];
- $context['event']['title'] = $row['title'];
- $context['event']['span'] = $row['span'] + 1;
- }
- else
- {
- $today = getdate();
- // You must have a month and year specified!
- if (!isset($_REQUEST['month']))
- $_REQUEST['month'] = $today['mon'];
- if (!isset($_REQUEST['year']))
- $_REQUEST['year'] = $today['year'];
- $context['event']['month'] = (int) $_REQUEST['month'];
- $context['event']['year'] = (int) $_REQUEST['year'];
- $context['event']['day'] = isset($_REQUEST['day']) ? $_REQUEST['day'] : ($_REQUEST['month'] == $today['mon'] ? $today['mday'] : 0);
- $context['event']['span'] = isset($_REQUEST['span']) ? $_REQUEST['span'] : 1;
- // Make sure the year and month are in the valid range.
- if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
- fatal_lang_error('invalid_month', false);
- if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
- fatal_lang_error('invalid_year', false);
- // Get a list of boards they can post in.
- $boards = boardsAllowedTo('post_new');
- if (empty($boards))
- fatal_lang_error('cannot_post_new', 'user');
- // Load a list of boards for this event in the context.
- require_once(SUBSDIR . '/MessageIndex.subs.php');
- $boardListOptions = array(
- 'included_boards' => in_array(0, $boards) ? null : $boards,
- 'not_redirection' => true,
- 'use_permissions' => true,
- 'selected_board' => empty($context['current_board']) ? $modSettings['cal_defaultboard'] : $context['current_board'],
- );
- $context['event']['categories'] = getBoardList($boardListOptions);
- }
- // Find the last day of the month.
- $context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
- $context['event']['board'] = !empty($board) ? $board : $modSettings['cal_defaultboard'];
- }
- // See if any new replies have come along.
- // Huh, $_REQUEST['msg'] is set upon submit, so this doesn't get executed at submit
- // only at preview
- if (empty($_REQUEST['msg']) && !empty($topic))
- {
- if (empty($options['no_new_reply_warning']) && isset($_REQUEST['last_msg']) && $context['topic_last_message'] > $_REQUEST['last_msg'])
- {
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*)
- FROM {db_prefix}messages
- WHERE id_topic = {int:current_topic}
- AND id_msg > {int:last_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
- AND approved = {int:approved}') . '
- LIMIT 1',
- array(
- 'current_topic' => $topic,
- 'last_msg' => (int) $_REQUEST['last_msg'],
- 'approved' => 1,
- )
- );
- list ($context['new_replies']) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- if (!empty($context['new_replies']))
- {
- if ($context['new_replies'] == 1)
- $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
- else
- $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
- $post_errors->addError('new_replies', 0);
- $modSettings['topicSummaryPosts'] = $context['new_replies'] > $modSettings['topicSummaryPosts'] ? max($modSettings['topicSummaryPosts'], 5) : $modSettings['topicSummaryPosts'];
- }
- }
- }
- // Get a response prefix (like 'Re:') in the default forum language.
- if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
- {
- if ($language === $user_info['language'])
- $context['response_prefix'] = $txt['response_prefix'];
- else
- {
- loadLanguage('index', $language, false);
- $context['response_prefix'] = $txt['response_prefix'];
- loadLanguage('index');
- }
- cache_put_data('response_prefix', $context['response_prefix'], 600);
- }
- // Previewing, modifying, or posting?
- // Do we have a body, but an error happened.
- if (isset($_REQUEST['message']) || $post_errors->hasErrors())
- {
- // Validate inputs.
- if (!$post_errors->hasErrors())
- {
- // This means they didn't click Post and get an error.
- $really_previewing = true;
- }
- else
- {
- if (!isset($_REQUEST['subject']))
- $_REQUEST['subject'] = '';
- if (!isset($_REQUEST['message']))
- $_REQUEST['message'] = '';
- if (!isset($_REQUEST['icon']))
- $_REQUEST['icon'] = 'xx';
- // They are previewing if they asked to preview (i.e. came from quick reply).
- $really_previewing = !empty($_POST['preview']);
- }
- // In order to keep the approval status flowing through, we have to pass it through the form...
- $context['becomes_approved'] = empty($_REQUEST['not_approved']);
- $context['show_approval'] = isset($_REQUEST['approve']) ? ($_REQUEST['approve'] ? 2 : 1) : 0;
- $context['can_announce'] &= $context['becomes_approved'];
- // Set up the inputs for the form.
- $form_subject = strtr($smcFunc['htmlspecialchars']($_REQUEST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
- $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
- // Make sure the subject isn't too long - taking into account special characters.
- if ($smcFunc['strlen']($form_subject) > 100)
- $form_subject = $smcFunc['substr']($form_subject, 0, 100);
- if (isset($_REQUEST['poll']))
- {
- $context['poll']['question'] = isset($_REQUEST['question']) ? $smcFunc['htmlspecialchars'](trim($_REQUEST['question'])) : '';
- $context['choices'] = array();
- $choice_id = 0;
- $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
- foreach ($_POST['options'] as $option)
- {
- if (trim($option) == '')
- continue;
- $context['choices'][] = array(
- 'id' => $choice_id++,
- 'number' => $choice_id,
- 'label' => $option,
- 'is_last' => false
- );
- }
- // One empty option for those with js disabled...I know are few... :P
- $context['choices'][] = array(
- 'id' => $choice_id++,
- 'number' => $choice_id,
- 'label' => '',
- 'is_last' => false
- );
- if (count($context['choices']) < 2)
- {
- $context['choices'][] = array(
- 'id' => $choice_id++,
- 'number' => $choice_id,
- 'label' => '',
- 'is_last' => false
- );
- }
- $context['last_choice_id'] = $choice_id;
- $context['choices'][count($context['choices']) - 1]['is_last'] = true;
- }
- // Are you... a guest?
- if ($user_info['is_guest'])
- {
- $_REQUEST['guestname'] = !isset($_REQUEST['guestname']) ? '' : trim($_REQUEST['guestname']);
- $_REQUEST['email'] = !isset($_REQUEST['email']) ? '' : trim($_REQUEST['email']);
- $_REQUEST['guestname'] = htmlspecialchars($_REQUEST['guestname']);
- $context['name'] = $_REQUEST['guestname'];
- $_REQUEST['email'] = htmlspecialchars($_REQUEST['email']);
- $context['email'] = $_REQUEST['email'];
- $user_info['name'] = $_REQUEST['guestname'];
- }
- // Only show the preview stuff if they hit Preview.
- if (($really_previewing === true || isset($_REQUEST['xml'])) && !isset($_REQUEST['save_draft']))
- {
- // Set up the preview message and subject
- $context['preview_message'] = $form_message;
- preparsecode($form_message, true);
- // Do all bulletin board code thing on the message
- preparsecode($context['preview_message']);
- $context['preview_message'] = parse_bbc($context['preview_message'], isset($_REQUEST['ns']) ? 0 : 1);
- censorText($context['preview_message']);
- // Dont forget the subject
- $context['preview_subject'] = $form_subject;
- censorText($context['preview_subject']);
- // Any errors we should tell them about?
- if ($form_subject === '')
- {
- $post_errors->addError('no_subject', 0);
- $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
- }
- if ($context['preview_message'] === '')
- $post_errors->addError('no_message');
- elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($form_message) > $modSettings['max_messageLength'])
- $post_errors->addError(array('long_message', array($modSettings['max_messageLength'])));
- // Protect any CDATA blocks.
- if (isset($_REQUEST['xml']))
- $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
- }
- // Set up the checkboxes.
- $context['notify'] = !empty($_REQUEST['notify']);
- $context['use_smileys'] = !isset($_REQUEST['ns']);
- $context['icon'] = isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : 'xx';
- // Set the destination action for submission.
- $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '') . (isset($_REQUEST['poll']) ? ';poll' : '');
- $context['submit_label'] = isset($_REQUEST['msg']) ? $txt['save'] : $txt['post'];
- // Previewing an edit?
- if (isset($_REQUEST['msg']) && !empty($topic))
- {
- require_once(SUBSDIR . '/Messages.subs.php');
- // Get the existing message.
- $message = getExistingMessage((int) $_REQUEST['msg'], $topic);
- // The message they were trying to edit was most likely deleted.
- // @todo Change this error message?
- if ($message === false)
- fatal_lang_error('no_board', false);
- $errors = checkMessagePermissions($message['message']);
- if (!empty($errors))
- foreach ($errors as $error)
- $post_errors->addError($error);
- prepareMessageContext($message);
- }
- // No check is needed, since nothing is really posted.
- checkSubmitOnce('free');
- }
- // Editing a message...
- elseif (isset($_REQUEST['msg']) && !empty($topic))
- {
- $_REQUEST['msg'] = (int) $_REQUEST['msg'];
- require_once(SUBSDIR . '/Messages.subs.php');
- // Get the existing message.
- $message = getExistingMessage((int) $_REQUEST['msg'], $topic);
- // The message they were trying to edit was most likely deleted.
- if ($message === false)
- fatal_lang_error('no_message', false);
- $errors = checkMessagePermissions($message['message']);
- if (!empty($errors))
- foreach ($errors as $error)
- $post_errors->addError($error);
- prepareMessageContext($message);
- // Get the stuff ready for the form.
- $form_subject = $message['message']['subject'];
- $form_message = un_preparsecode($message['message']['body']);
- censorText($form_message);
- censorText($form_subject);
- // Check the boxes that should be checked.
- $context['use_smileys'] = !empty($message['message']['smileys_enabled']);
- $context['icon'] = $message['message']['icon'];
- // Set the destinaton.
- $context['destination'] = 'post2;start=' . $_REQUEST['start'] . ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] . (isset($_REQUEST['poll']) ? ';poll' : '');
- $context['submit_label'] = $txt['save'];
- }
- // Posting...
- else
- {
- // By default....
- $context['use_smileys'] = true;
- $context['icon'] = 'xx';
- if ($user_info['is_guest'])
- {
- $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : '';
- $context['email'] = isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : '';
- }
- $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['poll']) ? ';poll' : '');
- $context['submit_label'] = $txt['post'];
- // Posting a quoted reply?
- if (!empty($topic) && !empty($_REQUEST['quote']))
- {
- // Make sure they _can_ quote this post, and if so get it.
- $request = $smcFunc['db_query']('', '
- SELECT m.subject, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body
- FROM {db_prefix}messages AS m
- INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
- WHERE m.id_msg = {int:id_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
- AND m.approved = {int:is_approved}') . '
- LIMIT 1',
- array(
- 'id_msg' => (int) $_REQUEST['quote'],
- 'is_approved' => 1,
- )
- );
- if ($smcFunc['db_num_rows']($request) == 0)
- fatal_lang_error('quoted_post_deleted', false);
- list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- // Add 'Re: ' to the front of the quoted subject.
- if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
- $form_subject = $context['response_prefix'] . $form_subject;
- // Censor the message and subject.
- censorText($form_message);
- censorText($form_subject);
- // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited!
- if (strpos($form_message, '[html]') !== false)
- {
- $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE);
- for ($i = 0, $n = count($parts); $i < $n; $i++)
- {
- // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
- if ($i % 4 == 0)
- $parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ise', '\'[html]\' . preg_replace(\'~<br\s?/?' . '>~i\', \'<br /><br />\', \'$1\') . \'[/html]\'', $parts[$i]);
- }
- $form_message = implode('', $parts);
- }
- $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
- // Remove any nested quotes, if necessary.
- if (!empty($modSettings['removeNestedQuotes']))
- $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
- // Add a quote string on the front and end.
- $form_message = '[quote author=' . $mname . ' link=topic=' . $topic . '.msg' . (int) $_REQUEST['quote'] . '#msg' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
- }
- // Posting a reply without a quote?
- elseif (!empty($topic) && empty($_REQUEST['quote']))
- {
- // Get the first message's subject.
- $form_subject = $first_subject;
- // Add 'Re: ' to the front of the subject.
- if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
- $form_subject = $context['response_prefix'] . $form_subject;
- // Censor the subject.
- censorText($form_subject);
- $form_message = '';
- }
- else
- {
- $form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
- $form_message = '';
- }
- }
- $context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
- if ($context['can_post_attachment'])
- {
- // If there are attachments, calculate the total size and how many.
- $context['attachments']['total_size'] = 0;
- $context['attachments']['quantity'] = 0;
- // If this isn't a new post, check the current attachments.
- if (isset($_REQUEST['msg']))
- {
- $context['attachments']['quantity'] = count($context['current_attachments']);
- foreach ($context['current_attachments'] as $attachment)
- $context['attachments']['total_size'] += $attachment['size'];
- }
- // A bit of house keeping first.
- if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
- unset($_SESSION['temp_attachments']);
- if (!empty($_SESSION['temp_attachments']))
- {
- // Is this a request to delete them?
- if (isset($_GET['delete_temp']))
- {
- foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
- {
- if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
- if (file_exists($attachment['tmp_name']))
- unlink($attachment['tmp_name']);
- }
- $attach_errors->addError('temp_attachments_gone');
- $_SESSION['temp_attachments'] = array();
- }
- // Hmm, coming in fresh and there are files in session.
- elseif ($context['current_action'] != 'post2' || !empty($_POST['from_qr']))
- {
- // Let's be nice and see if they belong here first.
- if ((empty($_REQUEST['msg']) && empty($_SESSION['temp_attachments']['post']['msg']) && $_SESSION['temp_attachments']['post']['board'] == $board) || (!empty($_REQUEST['msg']) && $_SESSION['temp_attachments']['post']['msg'] == $_REQUEST['msg']))
- {
- // See if any files still exist before showing the warning message and the files attached.
- foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
- {
- if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
- continue;
- if (file_exists($attachment['tmp_name']))
- {
- $attach_errors->addError('temp_attachments_new');
- $context['files_in_session_warning'] = $txt['attached_files_in_session'];
- unset($_SESSION['temp_attachments']['post']['files']);
- break;
- }
- }
- }
- else
- {
- // Since, they don't belong here. Let's inform the user that they exist..
- if (!empty($topic))
- $delete_link = '<a href="' . $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp">' . $txt['here'] . '</a>';
- else
- $delete_link = '<a href="' . $scripturl . '?action=post;board=' . $board . ';delete_temp">' . $txt['here'] . '</a>';
- // Compile a list of the files to show the user.
- $file_list = array();
- foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
- if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
- $file_list[] = $attachment['name'];
- $_SESSION['temp_attachments']['post']['files'] = $file_list;
- $file_list = '<div class="attachments">' . implode('<br />', $file_list) . '</div>';
- if (!empty($_SESSION['temp_attachments']['post']['msg']))
- {
- // We have a message id, so we can link back to the old topic they were trying to edit..
- $goback_link = '<a href="' . $scripturl . '?action=post' .(!empty($_SESSION['temp_attachments']['post']['msg']) ? (';msg=' . $_SESSION['temp_attachments']['post']['msg']) : '') . (!empty($_SESSION['temp_attachments']['post']['last_msg']) ? (';last_msg=' . $_SESSION['temp_attachments']['post']['last_msg']) : '') . ';topic=' . $_SESSION['temp_attachments']['post']['topic'] . ';additionalOptions">' . $txt['here'] . '</a>';
- $attach_errors->addError(array('temp_attachments_found', array($delete_link, $goback_link, $file_list)));
- $context['ignore_temp_attachments'] = true;
- }
- else
- {
- $attach_errors->addError(array('temp_attachments_lost', array($delete_link, $file_list)));
- $context['ignore_temp_attachments'] = true;
- }
- }
- }
- if (!empty($context['we_are_history']))
- $attach_errors->addError($context['we_are_history']);
- foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
- {
- if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
- break;
- if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
- continue;
- if ($attachID == 'initial_error')
- {
- $txt['error_attach_initial_error'] = $txt['attach_no_upload'] . '<div style="padding: 0 1em;">' . (is_array($attachment) ? vsprintf($txt[$attachment[0]], $attachment[1]) : $txt[$attachment]) . '</div>';
- $attach_errors->addError('attach_initial_error');
- unset($_SESSION['temp_attachments']);
- break;
- }
- // Show any errors which might of occured.
- if (!empty($attachment['errors']))
- {
- $txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br />' : '';
- $txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
- foreach ($attachment['errors'] as $error)
- $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br />';
- $txt['error_attach_errors'] .= '</div>';
- $attach_errors->addError('attach_errors');
- // Take out the trash.
- unset($_SESSION['temp_attachments'][$attachID]);
- if (file_exists($attachment['tmp_name']))
- unlink($attachment['tmp_name']);
- continue;
- }
- // More house keeping.
- if (!file_exists($attachment['tmp_name']))
- {
- unset($_SESSION['temp_attachments'][$attachID]);
- continue;
- }
- $context['attachments']['quantity']++;
- $context['attachments']['total_size'] += $attachment['size'];
- if (!isset($context['files_in_session_warning']))
- $context['files_in_session_warning'] = $txt['attached_files_in_session'];
- $context['current_attachments'][] = array(
- 'name' => '<u>' . htmlspecialchars($attachment['name']) . '</u>',
- 'size' => $attachment['size'],
- 'id' => $attachID,
- 'unchecked' => false,
- 'approved' => 1,
- );
- }
- }
- }
- // Do we need to show the visual verification image?
- $context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1));
- if ($context['require_verification'])
- {
- require_once(SUBSDIR . '/Editor.subs.php');
- $verificationOptions = array(
- 'id' => 'post',
- );
- $context['require_verification'] = create_control_verification($verificationOptions);
- $context['visual_verification_id'] = $verificationOptions['id'];
- }
- // If they came from quick reply, and have to enter verification details, give them some notice.
- if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
- $post_errors->addError('need_qr_verification', 0);
- // Any errors occurred?
- $context['post_error'] = array(
- 'errors' => $post_errors->prepareErrors(),
- 'type' => $post_errors->getErrorType() == 0 ? 'minor' : 'serious',
- 'title' => $txt['error_while_submitting'],
- );
- $context['attachment_error'] = array(
- 'errors' => $attach_errors->prepareErrors(),
- 'type' => $attach_errors->getErrorType() == 0 ? 'minor' : 'serious',
- 'title' => $txt['error_while_submitting'],
- );
- // What are you doing? Posting a poll, modifying, previewing, new post, or reply...
- if (isset($_REQUEST['poll']))
- $context['page_title'] = $txt['new_poll'];
- elseif ($context['make_event'])
- $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
- elseif (isset($_REQUEST['msg']))
- $context['page_title'] = $txt['modify_msg'];
- elseif (isset($_REQUEST['subject'], $context['preview_subject']))
- $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
- elseif (empty($topic))
- $context['page_title'] = $txt['start_new_topic'];
- else
- $context['page_title'] = $txt['post_reply'];
- // Update the topic summary, needed to show new posts in a preview
- if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
- getTopic();
- // Just ajax previewing then lets stop now
- if (isset($_REQUEST['xml']))
- obExit();
- // Build the link tree.
- if (empty($topic))
- $context['linktree'][] = array(
- 'name' => '<em>' . $txt['start_new_topic'] . '</em>'
- );
- else
- $context['linktree'][] = array(
- 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
- 'name' => $form_subject,
- 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' ( </strong></span>',
- 'extra_after' => '<span><strong class="nav"> )</strong></span>'
- );
- $context['subject'] = addcslashes($form_subject, '"');
- $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message);
- // Are post drafts enabled?
- $context['drafts_save'] = !empty($modSettings['drafts_enabled']) && !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft');
- $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']) && allowedTo('post_autosave_draft');
- // Build a list of drafts that they can load in to the editor
- if (!empty($context['drafts_save']))
- {
- require_once(CONTROLLERDIR . '/Drafts.controller.php');
- action_showDrafts($user_info['id'], $topic);
- }
- // Needed for the editor and message icons.
- require_once(SUBSDIR . '/Editor.subs.php');
- // Now create the editor.
- $editorOptions = array(
- 'id' => 'message',
- 'value' => $context['message'],
- 'labels' => array(
- 'post_button' => $context['submit_label'],
- ),
- // add height and width for the editor
- 'height' => '275px',
- 'width' => '100%',
- // We do XML preview here.
- 'preview_type' => 2,
- // Live errors - try or die
- 'live_errors' => true
- );
- create_control_richedit($editorOptions);
- // Store the ID.
- $context['post_box_name'] = $editorOptions['id'];
- $context['attached'] = '';
- $context['make_poll'] = isset($_REQUEST['poll']);
- if ($context['make_poll'])
- loadTemplate('Poll');
- // Message icons - customized or not, retrieve them...
- $context['icons'] = getMessageIcons($board);
- $context['icon_url'] = '';
- if (!empty($context['icons']))
- {
- $context['icons'][count($context['icons']) - 1]['is_last'] = true;
- $context['icons'][0]['selected'] = true;
- $context['icon'] = $context['icons'][0]['value'];
- $context['icon_url'] = $context['icons'][0]['url'];
- }
- // Are we starting a poll? if set the poll icon as selected if its available
- if (isset($_REQUEST['poll']))
- {
- for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
- {
- if ($context['icons'][$i]['value'] == 'poll')
- {
- $context['icons'][$i]['selected'] = true;
- $context['icon'] = 'poll';
- $context['icon_url'] = $context['icons'][$i]['url'];
- break;
- }
- }
- }
- // If the user can post attachments prepare the warning labels.
- if ($context['can_post_attachment'])
- {
- // If they've unchecked an attachment, they may still want to attach that many more files, but don't allow more than num_allowed_attachments.
- $context['num_allowed_attachments'] = empty($modSettings['attachmentNumPerPostLimit']) ? 50 : min($modSettings['attachmentNumPerPostLimit'] - count($context['current_attachments']), $modSettings['attachmentNumPerPostLimit']);
- $context['can_post_attachment_unapproved'] = allowedTo('post_attachment');
- $context['attachment_restrictions'] = array();
- $context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
- $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
- foreach ($attachmentRestrictionTypes as $type)
- if (!empty($modSettings[$type]))
- {
- $context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type], comma_format($modSettings[$type], 0));
- // Show some numbers. If they exist.
- if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0)
- $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
- elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0)
- $context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1028), 0)), 0));
- }
- }
- $context['back_to_topic'] = isset($_REQUEST['goback']) || (isset($_REQUEST['msg']) && !isset($_REQUEST['subject']));
- $context['show_additional_options'] = !empty($_POST['additional_options']) || isset($_SESSION['temp_attachments']['post']) || isset($_GET['additionalOptions']);
- $context['is_new_topic'] = empty($topic);
- $context['is_new_post'] = !isset($_REQUEST['msg']);
- $context['is_first_post'] = $context['is_new_topic'] || (isset($_REQUEST['msg']) && $_REQUEST['msg'] == $id_first_msg);
- // WYSIWYG only works if BBC is enabled
- $modSettings['disable_wysiwyg'] = !empty($modSettings['disable_wysiwyg']) || empty($modSettings['enableBBC']);
- // Register this form in the session variables.
- checkSubmitOnce('register');
- // Finally, load the template.
- if (!isset($_REQUEST['xml']))
- loadTemplate('Post');
- }
- /**
- * Posts or saves the message composed with Post().
- *
- * requires various permissions depending on the action.
- * handles attachment, post, and calendar saving.
- * sends off notifications, and allows for announcements and moderation.
- * accessed from ?action=post2.
- */
- function action_post2()
- {
- global $board, $topic, $txt, $modSettings, $context;
- global $user_info, $board_info, $options, $smcFunc, $scripturl, $settings;
- // Sneaking off, are we?
- if (empty($_POST) && empty($topic))
- {
- if (empty($_SERVER['CONTENT_LENGTH']))
- redirectexit('action=post;board=' . $board . '.0');
- else
- fatal_lang_error('post_upload_error', false);
- }
- elseif (empty($_POST) && !empty($topic))
- redirectexit('action=post;topic=' . $topic . '.0');
- // No need!
- $context['robot_no_index'] = true;
- // Previewing? Go back to start.
- if (isset($_REQUEST['preview']))
- return action_post();
- // Prevent double submission of this form.
- checkSubmitOnce('check');
- // No errors as yet.
- $post_errors = error_context::context('post', 1);
- $attach_errors = attachment_error_context::context();
- // If the session has timed out, let the user re-submit their form.
- if (checkSession('post', '', false) != '')
- $post_errors->addError('session_timeout');
- // Wrong verification code?
- if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
- {
- require_once(SUBSDIR . '/Editor.subs.php');
- $verificationOptions = array(
- 'id' => 'post',
- );
- $context['require_verification'] = create_control_verification($verificationOptions, true);
- }
- require_once(SUBSDIR . '/Post.subs.php');
- loadLanguage('Post');
- // Drafts enabled and needed?
- if (!empty($modSettings['drafts_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
- require_once(CONTROLLERDIR . '/Drafts.controller.php');
- // First check to see if they are trying to delete any current attachments.
- if (isset($_POST['attach_del']))
- {
- $keep_temp = array();
- $keep_ids = array();
- foreach ($_POST['attach_del'] as $dummy)
- if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
- $keep_temp[] = $dummy;
- else
- $keep_ids[] = (int) $dummy;
- if (isset($_SESSION['temp_attachments']))
- foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
- {
- if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
- continue;
- unset($_SESSION['temp_attachments'][$attachID]);
- unlink($attachment['tmp_name']);
- }
- if (!empty($_REQUEST['msg']))
- {
- require_once(SUBSDIR . '/Attachments.subs.php');
- $attachmentQuery = array(
- 'attachment_type' => 0,
- 'id_msg' => (int) $_REQUEST['msg'],
- 'not_id_attach' => $keep_ids,
- );
- removeAttachments($attachmentQuery);
- }
- }
- // Then try to upload any attachments.
- $context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
- if ($context['can_post_attachment'] && empty($_POST['from_qr']))
- {
- require_once(SUBSDIR . '/Attachments.subs.php');
- processAttachments();
- }
- // If this isn't a new topic load the topic info that we need.
- if (!empty($topic))
- {
- $request = $smcFunc['db_query']('', '
- SELECT locked, is_sticky, id_poll, approved, id_first_msg, id_last_msg, id_member_started, id_board
- FROM {db_prefix}topics
- WHERE id_topic = {int:current_topic}
- LIMIT 1',
- array(
- 'current_topic' => $topic,
- )
- );
- $topic_info = $smcFunc['db_fetch_assoc']($request);
- $smcFunc['db_free_result']($request);
- // Though the topic should be there, it might have vanished.
- if (!is_array($topic_info))
- fatal_lang_error('topic_doesnt_exist');
- // Did this topic suddenly move? Just checking...
- if ($topic_info['id_board'] != $board)
- fatal_lang_error('not_a_topic');
- }
- // Replying to a topic?
- if (!empty($topic) && !isset($_REQUEST['msg']))
- {
- // Don't allow a post if it's locked.
- if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
- fatal_lang_error('topic_locked', false);
- // Sorry, multiple polls aren't allowed... yet. You should stop giving me ideas :P.
- if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
- unset($_REQUEST['poll']);
- // Do the permissions and approval stuff...
- $becomesApproved = true;
- if ($topic_info['id_member_started'] != $user_info['id'])
- {
- if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
- $becomesApproved = false;
- else
- isAllowedTo('post_reply_any');
- }
- elseif (!allowedTo('post_reply_any'))
- {
- if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
- $becomesApproved = false;
- else
- isAllowedTo('post_reply_own');
- }
- if (isset($_POST['lock']))
- {
- // Nothing is changed to the lock.
- if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
- unset($_POST['lock']);
- // You're have no permission to lock this topic.
- elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
- unset($_POST['lock']);
- // You are allowed to (un)lock your own topic only.
- elseif (!allowedTo('lock_any'))
- {
- // You cannot override a moderator lock.
- if ($topic_info['locked'] == 1)
- unset($_POST['lock']);
- else
- $_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
- }
- // Hail mighty moderator, (un)lock this topic immediately.
- else
- $_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
- }
- // So you wanna (un)sticky this...let's see.
- if (isset($_POST['sticky']) && (empty($modSettings['enableStickyTopics']) || $_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
- unset($_POST['sticky']);
- // If drafts are enabled, then pass this off
- if (!empty($modSettings['drafts_enabled']) && isset($_POST['save_draft']))
- {
- saveDraft();
- return action_post();
- }
- // If the number of replies has changed, if the setting is enabled, go back to action_post() - which handles the error.
- if (empty($options['no_new_reply_warning']) && isset($_POST['last_msg']) && $topic_info['id_last_msg'] > $_POST['last_msg'])
- {
- $_REQUEST['preview'] = true;
- return action_post();
- }
- $posterIsGuest = $user_info['is_guest'];
- }
- // Posting a new topic.
- elseif (empty($topic))
- {
- // Now don't be silly, new topics will get their own id_msg soon enough.
- unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
- // Do like, the permissions, for safety and stuff...
- $becomesApproved = true;
- if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
- $becomesApproved = false;
- else
- isAllowedTo('post_new');
- if (isset($_POST['lock']))
- {
- // New topics are by default not locked.
- if (empty($_POST['lock']))
- unset($_POST['lock']);
- // Besides, you need permission.
- elseif (!allowedTo(array('lock_any', 'lock_own')))
- unset($_POST['lock']);
- // A moderator-lock (1) can override a user-lock (2).
- else
- $_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
- }
- if (isset($_POST['sticky']) && (empty($modSettings['enableStickyTopics']) || empty($_POST['sticky']) || !allowedTo('make_sticky')))
- unset($_POST['sticky']);
- // Saving your new topic as a draft first?
- if (!empty($modSettings['drafts_enabled']) && isset($_POST['save_draft']))
- {
- saveDraft();
- return action_post();
- }
- $posterIsGuest = $user_info['is_guest'];
- }
- // Modifying an existing message?
- elseif (isset($_REQUEST['msg']) && !empty($topic))
- {
- $_REQUEST['msg'] = (int) $_REQUEST['msg'];
- $request = $smcFunc['db_query']('', '
- SELECT id_member, poster_name, poster_email, poster_time, approved
- FROM {db_prefix}messages
- WHERE id_msg = {int:id_msg}
- LIMIT 1',
- array(
- 'id_msg' => $_REQUEST['msg'],
- )
- );
- if ($smcFunc['db_num_rows']($request) == 0)
- fatal_lang_error('cant_find_messages', false);
- $row = $smcFunc['db_fetch_assoc']($request);
- $smcFunc['db_free_result']($request);
- if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
- fatal_lang_error('topic_locked', false);
- if (isset($_POST['lock']))
- {
- // Nothing changes to the lock status.
- if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
- unset($_POST['lock']);
- // You're simply not allowed to (un)lock this.
- elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
- unset($_POST['lock']);
- // You're only allowed to lock your own topics.
- elseif (!allowedTo('lock_any'))
- {
- // You're not allowed to break a moderator's lock.
- if ($topic_info['locked'] == 1)
- unset($_POST['lock']);
- // Lock it with a soft lock or unlock it.
- else
- $_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
- }
- // You must be the moderator.
- else
- $_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
- }
- // Change the sticky status of this topic?
- if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
- unset($_POST['sticky']);
- if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
- {
- if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
- fatal_lang_error('modify_post_time_passed', false);
- elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
- isAllowedTo('modify_replies');
- else
- isAllowedTo('modify_own');
- }
- elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
- {
- isAllowedTo('modify_replies');
- // If you're modifying a reply, I say it better be logged...
- $moderationAction = true;
- }
- else
- {
- isAllowedTo('modify_any');
- // Log it, assuming you're not modifying your own post.
- if ($row['id_member'] != $user_info['id'])
- $moderationAction = true;
- }
- // If drafts are enabled, then lets send this off to save
- if (!empty($modSettings['drafts_enabled']) && isset($_POST['save_draft']))
- {
- saveDraft();
- return action_post();
- }
- $posterIsGuest = empty($row['id_member']);
- // Can they approve it?
- $can_approve = allowedTo('approve_posts');
- $becomesApproved = $modSettings['postmod_active'] ? ($can_approve && !$row['approved'] ? (!empty($_REQUEST['approve']) ? 1 : 0) : $row['…
Large files files are truncated, but you can click here to view the full file