Chris@76: (int) $_REQUEST['msg'], Chris@76: )); Chris@76: if ($smcFunc['db_num_rows']($request) != 1) Chris@76: unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); Chris@76: else Chris@76: list ($topic) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: } Chris@76: Chris@76: // Check if it's locked. It isn't locked if no topic is specified. Chris@76: if (!empty($topic)) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT Chris@76: t.locked, IFNULL(ln.id_topic, 0) AS notify, t.is_sticky, t.id_poll, t.id_last_msg, mf.id_member, Chris@76: t.id_first_msg, mf.subject, Chris@76: CASE WHEN ml.poster_time > ml.modified_time THEN ml.poster_time ELSE ml.modified_time END AS last_post_time Chris@76: FROM {db_prefix}topics AS t Chris@76: LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_topic = t.id_topic AND ln.id_member = {int:current_member}) Chris@76: LEFT JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg) Chris@76: LEFT JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) Chris@76: WHERE t.id_topic = {int:current_topic} Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: 'current_topic' => $topic, Chris@76: ) Chris@76: ); Chris@76: list ($locked, $context['notify'], $sticky, $pollID, $context['topic_last_message'], $id_member_poster, $id_first_msg, $first_subject, $lastPostTime) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // If this topic already has a poll, they sure can't add another. Chris@76: if (isset($_REQUEST['poll']) && $pollID > 0) Chris@76: unset($_REQUEST['poll']); Chris@76: Chris@76: if (empty($_REQUEST['msg'])) Chris@76: { Chris@76: if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) Chris@76: is_not_guest(); Chris@76: Chris@76: // By default the reply will be approved... Chris@76: $context['becomes_approved'] = true; Chris@76: if ($id_member_poster != $user_info['id']) Chris@76: { Chris@76: if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) Chris@76: $context['becomes_approved'] = false; Chris@76: else Chris@76: isAllowedTo('post_reply_any'); Chris@76: } Chris@76: elseif (!allowedTo('post_reply_any')) Chris@76: { Chris@76: if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) Chris@76: $context['becomes_approved'] = false; Chris@76: else Chris@76: isAllowedTo('post_reply_own'); Chris@76: } Chris@76: } Chris@76: else Chris@76: $context['becomes_approved'] = true; Chris@76: Chris@76: $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own')); Chris@76: $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']); Chris@76: Chris@76: $context['notify'] = !empty($context['notify']); Chris@76: $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky; Chris@76: } Chris@76: else Chris@76: { Chris@76: $context['becomes_approved'] = true; Chris@76: if ((!$context['make_event'] || !empty($board))) Chris@76: { Chris@76: if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) Chris@76: $context['becomes_approved'] = false; Chris@76: else Chris@76: isAllowedTo('post_new'); Chris@76: } Chris@76: Chris@76: $locked = 0; Chris@76: // !!! These won't work if you're making an event. Chris@76: $context['can_lock'] = allowedTo(array('lock_any', 'lock_own')); Chris@76: $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']); Chris@76: Chris@76: $context['notify'] = !empty($context['notify']); Chris@76: $context['sticky'] = !empty($_REQUEST['sticky']); Chris@76: } Chris@76: Chris@76: // !!! These won't work if you're posting an event! Chris@76: $context['can_notify'] = allowedTo('mark_any_notify'); Chris@76: $context['can_move'] = allowedTo('move_any'); Chris@76: $context['move'] = !empty($_REQUEST['move']); Chris@76: $context['announce'] = !empty($_REQUEST['announce']); Chris@76: // You can only announce topics that will get approved... Chris@76: $context['can_announce'] = allowedTo('announce_topic') && $context['becomes_approved']; Chris@76: $context['locked'] = !empty($locked) || !empty($_REQUEST['lock']); Chris@76: $context['can_quote'] = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])); Chris@76: Chris@76: // Generally don't show the approval box... (Assume we want things approved) Chris@76: $context['show_approval'] = false; Chris@76: Chris@76: // An array to hold all the attachments for this topic. Chris@76: $context['current_attachments'] = array(); Chris@76: Chris@76: // Don't allow a post if it's locked and you aren't all powerful. Chris@76: if ($locked && !allowedTo('moderate_board')) Chris@76: fatal_lang_error('topic_locked', false); Chris@76: // Check the users permissions - is the user allowed to add or post a poll? Chris@76: if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') Chris@76: { Chris@76: // New topic, new poll. Chris@76: if (empty($topic)) Chris@76: isAllowedTo('poll_post'); Chris@76: // This is an old topic - but it is yours! Can you add to it? Chris@76: elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) Chris@76: isAllowedTo('poll_add_own'); Chris@76: // If you're not the owner, can you add to any poll? Chris@76: else Chris@76: isAllowedTo('poll_add_any'); Chris@76: Chris@76: require_once($sourcedir . '/Subs-Members.php'); Chris@76: $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); Chris@76: Chris@76: // Set up the poll options. Chris@76: $context['poll_options'] = array( Chris@76: 'max_votes' => empty($_POST['poll_max_votes']) ? '1' : max(1, $_POST['poll_max_votes']), Chris@76: 'hide' => empty($_POST['poll_hide']) ? 0 : $_POST['poll_hide'], Chris@76: 'expire' => !isset($_POST['poll_expire']) ? '' : $_POST['poll_expire'], Chris@76: 'change_vote' => isset($_POST['poll_change_vote']), Chris@76: 'guest_vote' => isset($_POST['poll_guest_vote']), Chris@76: 'guest_vote_enabled' => in_array(-1, $allowedVoteGroups['allowed']), Chris@76: ); Chris@76: Chris@76: // Make all five poll choices empty. Chris@76: $context['choices'] = array( Chris@76: array('id' => 0, 'number' => 1, 'label' => '', 'is_last' => false), Chris@76: array('id' => 1, 'number' => 2, 'label' => '', 'is_last' => false), Chris@76: array('id' => 2, 'number' => 3, 'label' => '', 'is_last' => false), Chris@76: array('id' => 3, 'number' => 4, 'label' => '', 'is_last' => false), Chris@76: array('id' => 4, 'number' => 5, 'label' => '', 'is_last' => true) Chris@76: ); Chris@76: } Chris@76: Chris@76: if ($context['make_event']) Chris@76: { Chris@76: // They might want to pick a board. Chris@76: if (!isset($context['current_board'])) Chris@76: $context['current_board'] = 0; Chris@76: Chris@76: // Start loading up the event info. Chris@76: $context['event'] = array(); Chris@76: $context['event']['title'] = isset($_REQUEST['evtitle']) ? htmlspecialchars(stripslashes($_REQUEST['evtitle'])) : ''; Chris@76: Chris@76: $context['event']['id'] = isset($_REQUEST['eventid']) ? (int) $_REQUEST['eventid'] : -1; Chris@76: $context['event']['new'] = $context['event']['id'] == -1; Chris@76: Chris@76: // Permissions check! Chris@76: isAllowedTo('calendar_post'); Chris@76: Chris@76: // Editing an event? (but NOT previewing!?) Chris@76: if (!$context['event']['new'] && !isset($_REQUEST['subject'])) Chris@76: { Chris@76: // If the user doesn't have permission to edit the post in this topic, redirect them. Chris@76: if ((empty($id_member_poster) || $id_member_poster != $user_info['id'] || !allowedTo('modify_own')) && !allowedTo('modify_any')) Chris@76: { Chris@76: require_once($sourcedir . '/Calendar.php'); Chris@76: return CalendarPost(); Chris@76: } Chris@76: Chris@76: // Get the current event information. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT Chris@76: id_member, title, MONTH(start_date) AS month, DAYOFMONTH(start_date) AS day, Chris@76: YEAR(start_date) AS year, (TO_DAYS(end_date) - TO_DAYS(start_date)) AS span Chris@76: FROM {db_prefix}calendar Chris@76: WHERE id_event = {int:id_event} Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'id_event' => $context['event']['id'], Chris@76: ) Chris@76: ); Chris@76: $row = $smcFunc['db_fetch_assoc']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Make sure the user is allowed to edit this event. Chris@76: if ($row['id_member'] != $user_info['id']) Chris@76: isAllowedTo('calendar_edit_any'); Chris@76: elseif (!allowedTo('calendar_edit_any')) Chris@76: isAllowedTo('calendar_edit_own'); Chris@76: Chris@76: $context['event']['month'] = $row['month']; Chris@76: $context['event']['day'] = $row['day']; Chris@76: $context['event']['year'] = $row['year']; Chris@76: $context['event']['title'] = $row['title']; Chris@76: $context['event']['span'] = $row['span'] + 1; Chris@76: } Chris@76: else Chris@76: { Chris@76: $today = getdate(); Chris@76: Chris@76: // You must have a month and year specified! Chris@76: if (!isset($_REQUEST['month'])) Chris@76: $_REQUEST['month'] = $today['mon']; Chris@76: if (!isset($_REQUEST['year'])) Chris@76: $_REQUEST['year'] = $today['year']; Chris@76: Chris@76: $context['event']['month'] = (int) $_REQUEST['month']; Chris@76: $context['event']['year'] = (int) $_REQUEST['year']; Chris@76: $context['event']['day'] = isset($_REQUEST['day']) ? $_REQUEST['day'] : ($_REQUEST['month'] == $today['mon'] ? $today['mday'] : 0); Chris@76: $context['event']['span'] = isset($_REQUEST['span']) ? $_REQUEST['span'] : 1; Chris@76: Chris@76: // Make sure the year and month are in the valid range. Chris@76: if ($context['event']['month'] < 1 || $context['event']['month'] > 12) Chris@76: fatal_lang_error('invalid_month', false); Chris@76: if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) Chris@76: fatal_lang_error('invalid_year', false); Chris@76: Chris@76: // Get a list of boards they can post in. Chris@76: $boards = boardsAllowedTo('post_new'); Chris@76: if (empty($boards)) Chris@76: fatal_lang_error('cannot_post_new', 'user'); Chris@76: Chris@76: // Load a list of boards for this event in the context. Chris@76: require_once($sourcedir . '/Subs-MessageIndex.php'); Chris@76: $boardListOptions = array( Chris@76: 'included_boards' => in_array(0, $boards) ? null : $boards, Chris@76: 'not_redirection' => true, Chris@76: 'use_permissions' => true, Chris@76: 'selected_board' => empty($context['current_board']) ? $modSettings['cal_defaultboard'] : $context['current_board'], Chris@76: ); Chris@76: $context['event']['categories'] = getBoardList($boardListOptions); Chris@76: } Chris@76: Chris@76: // Find the last day of the month. Chris@76: $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'])); Chris@76: Chris@76: $context['event']['board'] = !empty($board) ? $board : $modSettings['cal_defaultboard']; Chris@76: } Chris@76: Chris@76: if (empty($context['post_errors'])) Chris@76: $context['post_errors'] = array(); Chris@76: Chris@76: // See if any new replies have come along. Chris@76: if (empty($_REQUEST['msg']) && !empty($topic)) Chris@76: { Chris@76: if (empty($options['no_new_reply_warning']) && isset($_REQUEST['last_msg']) && $context['topic_last_message'] > $_REQUEST['last_msg']) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT COUNT(*) Chris@76: FROM {db_prefix}messages Chris@76: WHERE id_topic = {int:current_topic} Chris@76: AND id_msg > {int:last_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' Chris@76: AND approved = {int:approved}') . ' Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: 'last_msg' => (int) $_REQUEST['last_msg'], Chris@76: 'approved' => 1, Chris@76: ) Chris@76: ); Chris@76: list ($context['new_replies']) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: if (!empty($context['new_replies'])) Chris@76: { Chris@76: if ($context['new_replies'] == 1) Chris@76: $txt['error_new_reply'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; Chris@76: else Chris@76: $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); Chris@76: Chris@76: // If they've come from the display page then we treat the error differently.... Chris@76: if (isset($_GET['last_msg'])) Chris@76: $newRepliesError = $context['new_replies']; Chris@76: else Chris@76: $context['post_error'][$context['new_replies'] == 1 ? 'new_reply' : 'new_replies'] = true; Chris@76: Chris@76: $modSettings['topicSummaryPosts'] = $context['new_replies'] > $modSettings['topicSummaryPosts'] ? max($modSettings['topicSummaryPosts'], 5) : $modSettings['topicSummaryPosts']; Chris@76: } Chris@76: } Chris@76: // Check whether this is a really old post being bumped... Chris@76: if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) Chris@76: $oldTopicError = true; Chris@76: } Chris@76: Chris@76: // Get a response prefix (like 'Re:') in the default forum language. Chris@76: if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) Chris@76: { Chris@76: if ($language === $user_info['language']) Chris@76: $context['response_prefix'] = $txt['response_prefix']; Chris@76: else Chris@76: { Chris@76: loadLanguage('index', $language, false); Chris@76: $context['response_prefix'] = $txt['response_prefix']; Chris@76: loadLanguage('index'); Chris@76: } Chris@76: cache_put_data('response_prefix', $context['response_prefix'], 600); Chris@76: } Chris@76: Chris@76: // Previewing, modifying, or posting? Chris@76: if (isset($_REQUEST['message']) || !empty($context['post_error'])) Chris@76: { Chris@76: // Validate inputs. Chris@76: if (empty($context['post_error'])) Chris@76: { Chris@76: if (htmltrim__recursive(htmlspecialchars__recursive($_REQUEST['subject'])) == '') Chris@76: $context['post_error']['no_subject'] = true; Chris@76: if (htmltrim__recursive(htmlspecialchars__recursive($_REQUEST['message'])) == '') Chris@76: $context['post_error']['no_message'] = true; Chris@76: if (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) Chris@76: $context['post_error']['long_message'] = true; Chris@76: Chris@76: // Are you... a guest? Chris@76: if ($user_info['is_guest']) Chris@76: { Chris@76: $_REQUEST['guestname'] = !isset($_REQUEST['guestname']) ? '' : trim($_REQUEST['guestname']); Chris@76: $_REQUEST['email'] = !isset($_REQUEST['email']) ? '' : trim($_REQUEST['email']); Chris@76: Chris@76: // Validate the name and email. Chris@76: if (!isset($_REQUEST['guestname']) || trim(strtr($_REQUEST['guestname'], '_', ' ')) == '') Chris@76: $context['post_error']['no_name'] = true; Chris@76: elseif ($smcFunc['strlen']($_REQUEST['guestname']) > 25) Chris@76: $context['post_error']['long_name'] = true; Chris@76: else Chris@76: { Chris@76: require_once($sourcedir . '/Subs-Members.php'); Chris@76: if (isReservedName(htmlspecialchars($_REQUEST['guestname']), 0, true, false)) Chris@76: $context['post_error']['bad_name'] = true; Chris@76: } Chris@76: Chris@76: if (empty($modSettings['guest_post_no_email'])) Chris@76: { Chris@76: if (!isset($_REQUEST['email']) || $_REQUEST['email'] == '') Chris@76: $context['post_error']['no_email'] = true; Chris@76: elseif (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_REQUEST['email']) == 0) Chris@76: $context['post_error']['bad_email'] = true; Chris@76: } Chris@76: } Chris@76: Chris@76: // This is self explanatory - got any questions? Chris@76: if (isset($_REQUEST['question']) && trim($_REQUEST['question']) == '') Chris@76: $context['post_error']['no_question'] = true; Chris@76: Chris@76: // This means they didn't click Post and get an error. Chris@76: $really_previewing = true; Chris@76: } Chris@76: else Chris@76: { Chris@76: if (!isset($_REQUEST['subject'])) Chris@76: $_REQUEST['subject'] = ''; Chris@76: if (!isset($_REQUEST['message'])) Chris@76: $_REQUEST['message'] = ''; Chris@76: if (!isset($_REQUEST['icon'])) Chris@76: $_REQUEST['icon'] = 'xx'; Chris@76: Chris@76: // They are previewing if they asked to preview (i.e. came from quick reply). Chris@76: $really_previewing = !empty($_POST['preview']); Chris@76: } Chris@76: Chris@76: // In order to keep the approval status flowing through, we have to pass it through the form... Chris@76: $context['becomes_approved'] = empty($_REQUEST['not_approved']); Chris@76: $context['show_approval'] = isset($_REQUEST['approve']) ? ($_REQUEST['approve'] ? 2 : 1) : 0; Chris@76: $context['can_announce'] &= $context['becomes_approved']; Chris@76: Chris@76: // Set up the inputs for the form. Chris@76: $form_subject = strtr($smcFunc['htmlspecialchars']($_REQUEST['subject']), array("\r" => '', "\n" => '', "\t" => '')); Chris@76: $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES); Chris@76: Chris@76: // Make sure the subject isn't too long - taking into account special characters. Chris@76: if ($smcFunc['strlen']($form_subject) > 100) Chris@76: $form_subject = $smcFunc['substr']($form_subject, 0, 100); Chris@76: Chris@76: // Have we inadvertently trimmed off the subject of useful information? Chris@76: if ($smcFunc['htmltrim']($form_subject) === '') Chris@76: $context['post_error']['no_subject'] = true; Chris@76: Chris@76: // Any errors occurred? Chris@76: if (!empty($context['post_error'])) Chris@76: { Chris@76: loadLanguage('Errors'); Chris@76: Chris@76: $context['error_type'] = 'minor'; Chris@76: Chris@76: $context['post_error']['messages'] = array(); Chris@76: foreach ($context['post_error'] as $post_error => $dummy) Chris@76: { Chris@76: if ($post_error == 'messages') Chris@76: continue; Chris@76: Chris@76: if ($post_error == 'long_message') Chris@76: $txt['error_' . $post_error] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); Chris@76: Chris@76: $context['post_error']['messages'][] = $txt['error_' . $post_error]; Chris@76: Chris@76: // If it's not a minor error flag it as such. Chris@76: if (!in_array($post_error, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification'))) Chris@76: $context['error_type'] = 'serious'; Chris@76: } Chris@76: } Chris@76: Chris@76: if (isset($_REQUEST['poll'])) Chris@76: { Chris@76: $context['question'] = isset($_REQUEST['question']) ? $smcFunc['htmlspecialchars'](trim($_REQUEST['question'])) : ''; Chris@76: Chris@76: $context['choices'] = array(); Chris@76: $choice_id = 0; Chris@76: Chris@76: $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']); Chris@76: foreach ($_POST['options'] as $option) Chris@76: { Chris@76: if (trim($option) == '') Chris@76: continue; Chris@76: Chris@76: $context['choices'][] = array( Chris@76: 'id' => $choice_id++, Chris@76: 'number' => $choice_id, Chris@76: 'label' => $option, Chris@76: 'is_last' => false Chris@76: ); Chris@76: } Chris@76: Chris@76: if (count($context['choices']) < 2) Chris@76: { Chris@76: $context['choices'][] = array( Chris@76: 'id' => $choice_id++, Chris@76: 'number' => $choice_id, Chris@76: 'label' => '', Chris@76: 'is_last' => false Chris@76: ); Chris@76: $context['choices'][] = array( Chris@76: 'id' => $choice_id++, Chris@76: 'number' => $choice_id, Chris@76: 'label' => '', Chris@76: 'is_last' => false Chris@76: ); Chris@76: } Chris@76: $context['choices'][count($context['choices']) - 1]['is_last'] = true; Chris@76: } Chris@76: Chris@76: // Are you... a guest? Chris@76: if ($user_info['is_guest']) Chris@76: { Chris@76: $_REQUEST['guestname'] = !isset($_REQUEST['guestname']) ? '' : trim($_REQUEST['guestname']); Chris@76: $_REQUEST['email'] = !isset($_REQUEST['email']) ? '' : trim($_REQUEST['email']); Chris@76: Chris@76: $_REQUEST['guestname'] = htmlspecialchars($_REQUEST['guestname']); Chris@76: $context['name'] = $_REQUEST['guestname']; Chris@76: $_REQUEST['email'] = htmlspecialchars($_REQUEST['email']); Chris@76: $context['email'] = $_REQUEST['email']; Chris@76: Chris@76: $user_info['name'] = $_REQUEST['guestname']; Chris@76: } Chris@76: Chris@76: // Only show the preview stuff if they hit Preview. Chris@76: if ($really_previewing == true || isset($_REQUEST['xml'])) Chris@76: { Chris@76: // Set up the preview message and subject and censor them... Chris@76: $context['preview_message'] = $form_message; Chris@76: preparsecode($form_message, true); Chris@76: preparsecode($context['preview_message']); Chris@76: Chris@76: // Do all bulletin board code tags, with or without smileys. Chris@76: $context['preview_message'] = parse_bbc($context['preview_message'], isset($_REQUEST['ns']) ? 0 : 1); Chris@76: Chris@76: if ($form_subject != '') Chris@76: { Chris@76: $context['preview_subject'] = $form_subject; Chris@76: Chris@76: censorText($context['preview_subject']); Chris@76: censorText($context['preview_message']); Chris@76: } Chris@76: else Chris@76: $context['preview_subject'] = '' . $txt['no_subject'] . ''; Chris@76: Chris@76: // Protect any CDATA blocks. Chris@76: if (isset($_REQUEST['xml'])) Chris@76: $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]>')); Chris@76: } Chris@76: Chris@76: // Set up the checkboxes. Chris@76: $context['notify'] = !empty($_REQUEST['notify']); Chris@76: $context['use_smileys'] = !isset($_REQUEST['ns']); Chris@76: Chris@76: $context['icon'] = isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : 'xx'; Chris@76: Chris@76: // Set the destination action for submission. Chris@76: $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '') . (isset($_REQUEST['poll']) ? ';poll' : ''); Chris@76: $context['submit_label'] = isset($_REQUEST['msg']) ? $txt['save'] : $txt['post']; Chris@76: Chris@76: // Previewing an edit? Chris@76: if (isset($_REQUEST['msg']) && !empty($topic)) Chris@76: { Chris@76: // Get the existing message. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT Chris@76: m.id_member, m.modified_time, m.smileys_enabled, m.body, Chris@76: m.poster_name, m.poster_email, m.subject, m.icon, m.approved, Chris@76: IFNULL(a.size, -1) AS filesize, a.filename, a.id_attach, Chris@76: a.approved AS attachment_approved, t.id_member_started AS id_member_poster, Chris@76: m.poster_time Chris@76: FROM {db_prefix}messages AS m Chris@76: INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic}) Chris@76: LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type}) Chris@76: WHERE m.id_msg = {int:id_msg} Chris@76: AND m.id_topic = {int:current_topic}', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: 'attachment_type' => 0, Chris@76: 'id_msg' => $_REQUEST['msg'], Chris@76: ) Chris@76: ); Chris@76: // The message they were trying to edit was most likely deleted. Chris@76: // !!! Change this error message? Chris@76: if ($smcFunc['db_num_rows']($request) == 0) Chris@76: fatal_lang_error('no_board', false); Chris@76: $row = $smcFunc['db_fetch_assoc']($request); Chris@76: Chris@76: $attachment_stuff = array($row); Chris@76: while ($row2 = $smcFunc['db_fetch_assoc']($request)) Chris@76: $attachment_stuff[] = $row2; Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) Chris@76: { Chris@76: // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. Chris@76: if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) Chris@76: fatal_lang_error('modify_post_time_passed', false); Chris@76: elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) Chris@76: isAllowedTo('modify_replies'); Chris@76: else Chris@76: isAllowedTo('modify_own'); Chris@76: } Chris@76: elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) Chris@76: isAllowedTo('modify_replies'); Chris@76: else Chris@76: isAllowedTo('modify_any'); Chris@76: Chris@76: if (!empty($modSettings['attachmentEnable'])) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT IFNULL(size, -1) AS filesize, filename, id_attach, approved Chris@76: FROM {db_prefix}attachments Chris@76: WHERE id_msg = {int:id_msg} Chris@76: AND attachment_type = {int:attachment_type}', Chris@76: array( Chris@76: 'id_msg' => (int) $_REQUEST['msg'], Chris@76: 'attachment_type' => 0, Chris@76: ) Chris@76: ); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: if ($row['filesize'] <= 0) Chris@76: continue; Chris@76: $context['current_attachments'][] = array( Chris@76: 'name' => htmlspecialchars($row['filename']), Chris@76: 'id' => $row['id_attach'], Chris@76: 'approved' => $row['approved'], Chris@76: ); Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: } Chris@76: Chris@76: // Allow moderators to change names.... Chris@76: if (allowedTo('moderate_forum') && !empty($topic)) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_member, poster_name, poster_email Chris@76: FROM {db_prefix}messages Chris@76: WHERE id_msg = {int:id_msg} Chris@76: AND id_topic = {int:current_topic} Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: 'id_msg' => (int) $_REQUEST['msg'], Chris@76: ) Chris@76: ); Chris@76: $row = $smcFunc['db_fetch_assoc']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: if (empty($row['id_member'])) Chris@76: { Chris@76: $context['name'] = htmlspecialchars($row['poster_name']); Chris@76: $context['email'] = htmlspecialchars($row['poster_email']); Chris@76: } Chris@76: } Chris@76: } Chris@76: Chris@76: // No check is needed, since nothing is really posted. Chris@76: checkSubmitOnce('free'); Chris@76: } Chris@76: // Editing a message... Chris@76: elseif (isset($_REQUEST['msg']) && !empty($topic)) Chris@76: { Chris@76: $_REQUEST['msg'] = (int) $_REQUEST['msg']; Chris@76: Chris@76: // Get the existing message. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT Chris@76: m.id_member, m.modified_time, m.smileys_enabled, m.body, Chris@76: m.poster_name, m.poster_email, m.subject, m.icon, m.approved, Chris@76: IFNULL(a.size, -1) AS filesize, a.filename, a.id_attach, Chris@76: a.approved AS attachment_approved, t.id_member_started AS id_member_poster, Chris@76: m.poster_time Chris@76: FROM {db_prefix}messages AS m Chris@76: INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic}) Chris@76: LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type}) Chris@76: WHERE m.id_msg = {int:id_msg} Chris@76: AND m.id_topic = {int:current_topic}', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: 'attachment_type' => 0, Chris@76: 'id_msg' => $_REQUEST['msg'], Chris@76: ) Chris@76: ); Chris@76: // The message they were trying to edit was most likely deleted. Chris@76: // !!! Change this error message? Chris@76: if ($smcFunc['db_num_rows']($request) == 0) Chris@76: fatal_lang_error('no_board', false); Chris@76: $row = $smcFunc['db_fetch_assoc']($request); Chris@76: Chris@76: $attachment_stuff = array($row); Chris@76: while ($row2 = $smcFunc['db_fetch_assoc']($request)) Chris@76: $attachment_stuff[] = $row2; Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) Chris@76: { Chris@76: // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. Chris@76: if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) Chris@76: fatal_lang_error('modify_post_time_passed', false); Chris@76: elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) Chris@76: isAllowedTo('modify_replies'); Chris@76: else Chris@76: isAllowedTo('modify_own'); Chris@76: } Chris@76: elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) Chris@76: isAllowedTo('modify_replies'); Chris@76: else Chris@76: isAllowedTo('modify_any'); Chris@76: Chris@76: // When was it last modified? Chris@76: if (!empty($row['modified_time'])) Chris@76: $context['last_modified'] = timeformat($row['modified_time']); Chris@76: Chris@76: // Get the stuff ready for the form. Chris@76: $form_subject = $row['subject']; Chris@76: $form_message = un_preparsecode($row['body']); Chris@76: censorText($form_message); Chris@76: censorText($form_subject); Chris@76: Chris@76: // Check the boxes that should be checked. Chris@76: $context['use_smileys'] = !empty($row['smileys_enabled']); Chris@76: $context['icon'] = $row['icon']; Chris@76: Chris@76: // Show an "approve" box if the user can approve it, and the message isn't approved. Chris@76: if (!$row['approved'] && !$context['show_approval']) Chris@76: $context['show_approval'] = allowedTo('approve_posts'); Chris@76: Chris@76: // Load up 'em attachments! Chris@76: foreach ($attachment_stuff as $attachment) Chris@76: { Chris@76: if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) Chris@76: $context['current_attachments'][] = array( Chris@76: 'name' => htmlspecialchars($attachment['filename']), Chris@76: 'id' => $attachment['id_attach'], Chris@76: 'approved' => $attachment['attachment_approved'], Chris@76: ); Chris@76: } Chris@76: Chris@76: // Allow moderators to change names.... Chris@76: if (allowedTo('moderate_forum') && empty($row['id_member'])) Chris@76: { Chris@76: $context['name'] = htmlspecialchars($row['poster_name']); Chris@76: $context['email'] = htmlspecialchars($row['poster_email']); Chris@76: } Chris@76: Chris@76: // Set the destinaton. Chris@76: $context['destination'] = 'post2;start=' . $_REQUEST['start'] . ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] . (isset($_REQUEST['poll']) ? ';poll' : ''); Chris@76: $context['submit_label'] = $txt['save']; Chris@76: } Chris@76: // Posting... Chris@76: else Chris@76: { Chris@76: // By default.... Chris@76: $context['use_smileys'] = true; Chris@76: $context['icon'] = 'xx'; Chris@76: Chris@76: if ($user_info['is_guest']) Chris@76: { Chris@76: $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : ''; Chris@76: $context['email'] = isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : ''; Chris@76: } Chris@76: $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['poll']) ? ';poll' : ''); Chris@76: Chris@76: $context['submit_label'] = $txt['post']; Chris@76: Chris@76: // Posting a quoted reply? Chris@76: if (!empty($topic) && !empty($_REQUEST['quote'])) Chris@76: { Chris@76: // Make sure they _can_ quote this post, and if so get it. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT m.subject, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body Chris@76: FROM {db_prefix}messages AS m Chris@76: INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) Chris@76: LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) Chris@76: WHERE m.id_msg = {int:id_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' Chris@76: AND m.approved = {int:is_approved}') . ' Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'id_msg' => (int) $_REQUEST['quote'], Chris@76: 'is_approved' => 1, Chris@76: ) Chris@76: ); Chris@76: if ($smcFunc['db_num_rows']($request) == 0) Chris@76: fatal_lang_error('quoted_post_deleted', false); Chris@76: list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Add 'Re: ' to the front of the quoted subject. Chris@76: if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) Chris@76: $form_subject = $context['response_prefix'] . $form_subject; Chris@76: Chris@76: // Censor the message and subject. Chris@76: censorText($form_message); Chris@76: censorText($form_subject); Chris@76: Chris@76: // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited! Chris@76: if (strpos($form_message, '[html]') !== false) Chris@76: { Chris@76: $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE); Chris@76: for ($i = 0, $n = count($parts); $i < $n; $i++) Chris@76: { Chris@76: // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. Chris@76: if ($i % 4 == 0) Chris@76: $parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ise', '\'[html]\' . preg_replace(\'~~i\', \'<br />
\', \'$1\') . \'[/html]\'', $parts[$i]); Chris@76: } Chris@76: $form_message = implode('', $parts); Chris@76: } Chris@76: Chris@76: $form_message = preg_replace('~
~i', "\n", $form_message); Chris@76: Chris@76: // Remove any nested quotes, if necessary. Chris@76: if (!empty($modSettings['removeNestedQuotes'])) Chris@76: $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); Chris@76: Chris@76: // Add a quote string on the front and end. Chris@76: $form_message = '[quote author=' . $mname . ' link=topic=' . $topic . '.msg' . (int) $_REQUEST['quote'] . '#msg' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]'; Chris@76: } Chris@76: // Posting a reply without a quote? Chris@76: elseif (!empty($topic) && empty($_REQUEST['quote'])) Chris@76: { Chris@76: // Get the first message's subject. Chris@76: $form_subject = $first_subject; Chris@76: Chris@76: // Add 'Re: ' to the front of the subject. Chris@76: if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) Chris@76: $form_subject = $context['response_prefix'] . $form_subject; Chris@76: Chris@76: // Censor the subject. Chris@76: censorText($form_subject); Chris@76: Chris@76: $form_message = ''; Chris@76: } Chris@76: else Chris@76: { Chris@76: $form_subject = isset($_GET['subject']) ? $_GET['subject'] : ''; Chris@76: $form_message = ''; Chris@76: } Chris@76: } Chris@76: Chris@76: // !!! This won't work if you're posting an event. Chris@76: if (allowedTo('post_attachment') || allowedTo('post_unapproved_attachments')) Chris@76: { Chris@76: if (empty($_SESSION['temp_attachments'])) Chris@76: $_SESSION['temp_attachments'] = array(); Chris@76: Chris@76: if (!empty($modSettings['currentAttachmentUploadDir'])) Chris@76: { Chris@76: if (!is_array($modSettings['attachmentUploadDir'])) Chris@76: $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']); Chris@76: Chris@76: // Just use the current path for temp files. Chris@76: $current_attach_dir = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; Chris@76: } Chris@76: else Chris@76: $current_attach_dir = $modSettings['attachmentUploadDir']; Chris@76: Chris@76: // If this isn't a new post, check the current attachments. Chris@76: if (isset($_REQUEST['msg'])) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT COUNT(*), SUM(size) Chris@76: FROM {db_prefix}attachments Chris@76: WHERE id_msg = {int:id_msg} Chris@76: AND attachment_type = {int:attachment_type}', Chris@76: array( Chris@76: 'id_msg' => (int) $_REQUEST['msg'], Chris@76: 'attachment_type' => 0, Chris@76: ) Chris@76: ); Chris@76: list ($quantity, $total_size) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: } Chris@76: else Chris@76: { Chris@76: $quantity = 0; Chris@76: $total_size = 0; Chris@76: } Chris@76: Chris@76: $temp_start = 0; Chris@76: Chris@76: if (!empty($_SESSION['temp_attachments'])) Chris@76: { Chris@76: if ($context['current_action'] != 'post2' || !empty($_POST['from_qr'])) Chris@76: { Chris@76: $context['post_error']['messages'][] = $txt['error_temp_attachments']; Chris@76: $context['error_type'] = 'minor'; Chris@76: } Chris@76: Chris@76: foreach ($_SESSION['temp_attachments'] as $attachID => $name) Chris@76: { Chris@76: $temp_start++; Chris@76: Chris@76: if (preg_match('~^post_tmp_' . $user_info['id'] . '_\d+$~', $attachID) == 0) Chris@76: { Chris@76: unset($_SESSION['temp_attachments'][$attachID]); Chris@76: continue; Chris@76: } Chris@76: Chris@76: if (!empty($_POST['attach_del']) && !in_array($attachID, $_POST['attach_del'])) Chris@76: { Chris@76: $deleted_attachments = true; Chris@76: unset($_SESSION['temp_attachments'][$attachID]); Chris@76: @unlink($current_attach_dir . '/' . $attachID); Chris@76: continue; Chris@76: } Chris@76: Chris@76: $quantity++; Chris@76: $total_size += filesize($current_attach_dir . '/' . $attachID); Chris@76: Chris@76: $context['current_attachments'][] = array( Chris@76: 'name' => htmlspecialchars($name), Chris@76: 'id' => $attachID, Chris@76: 'approved' => 1, Chris@76: ); Chris@76: } Chris@76: } Chris@76: Chris@76: if (!empty($_POST['attach_del'])) Chris@76: { Chris@76: $del_temp = array(); Chris@76: foreach ($_POST['attach_del'] as $i => $dummy) Chris@76: $del_temp[$i] = (int) $dummy; Chris@76: Chris@76: foreach ($context['current_attachments'] as $k => $dummy) Chris@76: if (!in_array($dummy['id'], $del_temp)) Chris@76: { Chris@76: $context['current_attachments'][$k]['unchecked'] = true; Chris@76: $deleted_attachments = !isset($deleted_attachments) || is_bool($deleted_attachments) ? 1 : $deleted_attachments + 1; Chris@76: $quantity--; Chris@76: } Chris@76: } Chris@76: Chris@76: if (!empty($_FILES['attachment'])) Chris@76: foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) Chris@76: { Chris@76: if ($_FILES['attachment']['name'][$n] == '') Chris@76: continue; Chris@76: Chris@76: if (!is_uploaded_file($_FILES['attachment']['tmp_name'][$n]) || (@ini_get('open_basedir') == '' && !file_exists($_FILES['attachment']['tmp_name'][$n]))) Chris@76: fatal_lang_error('attach_timeout', 'critical'); Chris@76: Chris@76: if (!empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024) Chris@76: fatal_lang_error('file_too_big', false, array($modSettings['attachmentSizeLimit'])); Chris@76: Chris@76: $quantity++; Chris@76: if (!empty($modSettings['attachmentNumPerPostLimit']) && $quantity > $modSettings['attachmentNumPerPostLimit']) Chris@76: fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit'])); Chris@76: Chris@76: $total_size += $_FILES['attachment']['size'][$n]; Chris@76: if (!empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024) Chris@76: fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit'])); Chris@76: Chris@76: if (!empty($modSettings['attachmentCheckExtensions'])) Chris@76: { Chris@76: if (!in_array(strtolower(substr(strrchr($_FILES['attachment']['name'][$n], '.'), 1)), explode(',', strtolower($modSettings['attachmentExtensions'])))) Chris@76: fatal_error($_FILES['attachment']['name'][$n] . '.
' . $txt['cant_upload_type'] . ' ' . $modSettings['attachmentExtensions'] . '.', false); Chris@76: } Chris@76: Chris@76: if (!empty($modSettings['attachmentDirSizeLimit'])) Chris@76: { Chris@76: // Make sure the directory isn't full. Chris@76: $dirSize = 0; Chris@76: $dir = @opendir($current_attach_dir) or fatal_lang_error('cant_access_upload_path', 'critical'); Chris@76: while ($file = readdir($dir)) Chris@76: { Chris@76: if ($file == '.' || $file == '..') Chris@76: continue; Chris@76: Chris@76: if (preg_match('~^post_tmp_\d+_\d+$~', $file) != 0) Chris@76: { Chris@76: // Temp file is more than 5 hours old! Chris@76: if (filemtime($current_attach_dir . '/' . $file) < time() - 18000) Chris@76: @unlink($current_attach_dir . '/' . $file); Chris@76: continue; Chris@76: } Chris@76: Chris@76: $dirSize += filesize($current_attach_dir . '/' . $file); Chris@76: } Chris@76: closedir($dir); Chris@76: Chris@76: // Too big! Maybe you could zip it or something... Chris@76: if ($_FILES['attachment']['size'][$n] + $dirSize > $modSettings['attachmentDirSizeLimit'] * 1024) Chris@76: fatal_lang_error('ran_out_of_space'); Chris@76: } Chris@76: Chris@76: if (!is_writable($current_attach_dir)) Chris@76: fatal_lang_error('attachments_no_write', 'critical'); Chris@76: Chris@76: $attachID = 'post_tmp_' . $user_info['id'] . '_' . $temp_start++; Chris@76: $_SESSION['temp_attachments'][$attachID] = basename($_FILES['attachment']['name'][$n]); Chris@76: $context['current_attachments'][] = array( Chris@76: 'name' => htmlspecialchars(basename($_FILES['attachment']['name'][$n])), Chris@76: 'id' => $attachID, Chris@76: 'approved' => 1, Chris@76: ); Chris@76: Chris@76: $destName = $current_attach_dir . '/' . $attachID; Chris@76: Chris@76: if (!move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) Chris@76: fatal_lang_error('attach_timeout', 'critical'); Chris@76: @chmod($destName, 0644); Chris@76: } Chris@76: } Chris@76: Chris@76: // If we are coming here to make a reply, and someone has already replied... make a special warning message. Chris@76: if (isset($newRepliesError)) Chris@76: { Chris@76: $context['post_error']['messages'][] = $newRepliesError == 1 ? $txt['error_new_reply'] : $txt['error_new_replies']; Chris@76: $context['error_type'] = 'minor'; Chris@76: } Chris@76: Chris@76: if (isset($oldTopicError)) Chris@76: { Chris@76: $context['post_error']['messages'][] = sprintf($txt['error_old_topic'], $modSettings['oldTopicDays']); Chris@76: $context['error_type'] = 'minor'; Chris@76: } Chris@76: Chris@76: // What are you doing? Posting a poll, modifying, previewing, new post, or reply... Chris@76: if (isset($_REQUEST['poll'])) Chris@76: $context['page_title'] = $txt['new_poll']; Chris@76: elseif ($context['make_event']) Chris@76: $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; Chris@76: elseif (isset($_REQUEST['msg'])) Chris@76: $context['page_title'] = $txt['modify_msg']; Chris@76: elseif (isset($_REQUEST['subject'], $context['preview_subject'])) Chris@76: $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); Chris@76: elseif (empty($topic)) Chris@76: $context['page_title'] = $txt['start_new_topic']; Chris@76: else Chris@76: $context['page_title'] = $txt['post_reply']; Chris@76: Chris@76: // Build the link tree. Chris@76: if (empty($topic)) Chris@76: $context['linktree'][] = array( Chris@76: 'name' => '' . $txt['start_new_topic'] . '' Chris@76: ); Chris@76: else Chris@76: $context['linktree'][] = array( Chris@76: 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], Chris@76: 'name' => $form_subject, Chris@76: 'extra_before' => '' . $context['page_title'] . ' ( ', Chris@76: 'extra_after' => ' )' Chris@76: ); Chris@76: Chris@76: // Give wireless a linktree url to the post screen, so that they can switch to full version. Chris@76: if (WIRELESS) Chris@76: $context['linktree'][count($context['linktree']) - 1]['url'] = $scripturl . '?action=post;' . (!empty($topic) ? 'topic=' . $topic : 'board=' . $board) . '.' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . (int) $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : ''); Chris@76: Chris@76: // 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. Chris@76: // !!! This won't work if you're posting an event. Chris@76: $context['num_allowed_attachments'] = empty($modSettings['attachmentNumPerPostLimit']) ? 50 : min($modSettings['attachmentNumPerPostLimit'] - count($context['current_attachments']) + (isset($deleted_attachments) ? $deleted_attachments : 0), $modSettings['attachmentNumPerPostLimit']); Chris@76: $context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments'))) && $context['num_allowed_attachments'] > 0; Chris@76: $context['can_post_attachment_unapproved'] = allowedTo('post_attachment'); Chris@76: Chris@76: $context['subject'] = addcslashes($form_subject, '"'); Chris@76: $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); Chris@76: Chris@76: // Needed for the editor and message icons. Chris@76: require_once($sourcedir . '/Subs-Editor.php'); Chris@76: Chris@76: // Now create the editor. Chris@76: $editorOptions = array( Chris@76: 'id' => 'message', Chris@76: 'value' => $context['message'], Chris@76: 'labels' => array( Chris@76: 'post_button' => $context['submit_label'], Chris@76: ), Chris@76: // add height and width for the editor Chris@76: 'height' => '175px', Chris@76: 'width' => '100%', Chris@76: // We do XML preview here. Chris@76: 'preview_type' => 2, Chris@76: ); Chris@76: create_control_richedit($editorOptions); Chris@76: Chris@76: // Store the ID. Chris@76: $context['post_box_name'] = $editorOptions['id']; Chris@76: Chris@76: $context['attached'] = ''; Chris@76: $context['make_poll'] = isset($_REQUEST['poll']); Chris@76: Chris@76: // Message icons - customized icons are off? Chris@76: $context['icons'] = getMessageIcons($board); Chris@76: Chris@76: if (!empty($context['icons'])) Chris@76: $context['icons'][count($context['icons']) - 1]['is_last'] = true; Chris@76: Chris@76: $context['icon_url'] = ''; Chris@76: for ($i = 0, $n = count($context['icons']); $i < $n; $i++) Chris@76: { Chris@76: $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value']; Chris@76: if ($context['icons'][$i]['selected']) Chris@76: $context['icon_url'] = $context['icons'][$i]['url']; Chris@76: } Chris@76: if (empty($context['icon_url'])) Chris@76: { Chris@76: $context['icon_url'] = $settings[file_exists($settings['theme_dir'] . '/images/post/' . $context['icon'] . '.gif') ? 'images_url' : 'default_images_url'] . '/post/' . $context['icon'] . '.gif'; Chris@76: array_unshift($context['icons'], array( Chris@76: 'value' => $context['icon'], Chris@76: 'name' => $txt['current_icon'], Chris@76: 'url' => $context['icon_url'], Chris@76: 'is_last' => empty($context['icons']), Chris@76: 'selected' => true, Chris@76: )); Chris@76: } Chris@76: Chris@76: if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) Chris@76: getTopic(); Chris@76: Chris@76: // If the user can post attachments prepare the warning labels. Chris@76: if ($context['can_post_attachment']) Chris@76: { Chris@76: $context['allowed_extensions'] = strtr($modSettings['attachmentExtensions'], array(',' => ', ')); Chris@76: $context['attachment_restrictions'] = array(); Chris@76: $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit'); Chris@76: foreach ($attachmentRestrictionTypes as $type) Chris@76: if (!empty($modSettings[$type])) Chris@76: $context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type], $modSettings[$type]); Chris@76: } Chris@76: Chris@76: $context['back_to_topic'] = isset($_REQUEST['goback']) || (isset($_REQUEST['msg']) && !isset($_REQUEST['subject'])); Chris@76: $context['show_additional_options'] = !empty($_POST['additional_options']) || !empty($_SESSION['temp_attachments']) || !empty($deleted_attachments); Chris@76: Chris@76: $context['is_new_topic'] = empty($topic); Chris@76: $context['is_new_post'] = !isset($_REQUEST['msg']); Chris@76: $context['is_first_post'] = $context['is_new_topic'] || (isset($_REQUEST['msg']) && $_REQUEST['msg'] == $id_first_msg); Chris@76: Chris@76: // Do we need to show the visual verification image? Chris@76: $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)); Chris@76: if ($context['require_verification']) Chris@76: { Chris@76: require_once($sourcedir . '/Subs-Editor.php'); Chris@76: $verificationOptions = array( Chris@76: 'id' => 'post', Chris@76: ); Chris@76: $context['require_verification'] = create_control_verification($verificationOptions); Chris@76: $context['visual_verification_id'] = $verificationOptions['id']; Chris@76: } Chris@76: Chris@76: // If they came from quick reply, and have to enter verification details, give them some notice. Chris@76: if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) Chris@76: { Chris@76: $context['post_error']['messages'][] = $txt['enter_verification_details']; Chris@76: $context['error_type'] = 'minor'; Chris@76: } Chris@76: Chris@76: // WYSIWYG only works if BBC is enabled Chris@76: $modSettings['disable_wysiwyg'] = !empty($modSettings['disable_wysiwyg']) || empty($modSettings['enableBBC']); Chris@76: Chris@76: // Register this form in the session variables. Chris@76: checkSubmitOnce('register'); Chris@76: Chris@76: // Finally, load the template. Chris@76: if (WIRELESS && WIRELESS_PROTOCOL != 'wap') Chris@76: $context['sub_template'] = WIRELESS_PROTOCOL . '_post'; Chris@76: elseif (!isset($_REQUEST['xml'])) Chris@76: loadTemplate('Post'); Chris@76: } Chris@76: Chris@76: function Post2() Chris@76: { Chris@76: global $board, $topic, $txt, $modSettings, $sourcedir, $context; Chris@76: global $user_info, $board_info, $options, $smcFunc; Chris@76: Chris@76: // Sneaking off, are we? Chris@76: if (empty($_POST) && empty($topic)) Chris@76: redirectexit('action=post;board=' . $board . '.0'); Chris@76: elseif (empty($_POST) && !empty($topic)) Chris@76: redirectexit('action=post;topic=' . $topic . '.0'); Chris@76: Chris@76: // No need! Chris@76: $context['robot_no_index'] = true; Chris@76: Chris@76: // If we came from WYSIWYG then turn it back into BBC regardless. Chris@76: if (!empty($_REQUEST['message_mode']) && isset($_REQUEST['message'])) Chris@76: { Chris@76: require_once($sourcedir . '/Subs-Editor.php'); Chris@76: Chris@76: $_REQUEST['message'] = html_to_bbc($_REQUEST['message']); Chris@76: Chris@76: // We need to unhtml it now as it gets done shortly. Chris@76: $_REQUEST['message'] = un_htmlspecialchars($_REQUEST['message']); Chris@76: Chris@76: // We need this for everything else. Chris@76: $_POST['message'] = $_REQUEST['message']; Chris@76: } Chris@76: Chris@76: // Previewing? Go back to start. Chris@76: if (isset($_REQUEST['preview'])) Chris@76: return Post(); Chris@76: Chris@76: // Prevent double submission of this form. Chris@76: checkSubmitOnce('check'); Chris@76: Chris@76: // No errors as yet. Chris@76: $post_errors = array(); Chris@76: Chris@76: // If the session has timed out, let the user re-submit their form. Chris@76: if (checkSession('post', '', false) != '') Chris@76: $post_errors[] = 'session_timeout'; Chris@76: Chris@76: // Wrong verification code? Chris@76: 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))) Chris@76: { Chris@76: require_once($sourcedir . '/Subs-Editor.php'); Chris@76: $verificationOptions = array( Chris@76: 'id' => 'post', Chris@76: ); Chris@76: $context['require_verification'] = create_control_verification($verificationOptions, true); Chris@76: if (is_array($context['require_verification'])) Chris@76: $post_errors = array_merge($post_errors, $context['require_verification']); Chris@76: } Chris@76: Chris@76: require_once($sourcedir . '/Subs-Post.php'); Chris@76: loadLanguage('Post'); Chris@76: Chris@76: // If this isn't a new topic load the topic info that we need. Chris@76: if (!empty($topic)) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT locked, is_sticky, id_poll, approved, id_first_msg, id_last_msg, id_member_started, id_board Chris@76: FROM {db_prefix}topics Chris@76: WHERE id_topic = {int:current_topic} Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: ) Chris@76: ); Chris@76: $topic_info = $smcFunc['db_fetch_assoc']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Though the topic should be there, it might have vanished. Chris@76: if (!is_array($topic_info)) Chris@76: fatal_lang_error('topic_doesnt_exist'); Chris@76: Chris@76: // Did this topic suddenly move? Just checking... Chris@76: if ($topic_info['id_board'] != $board) Chris@76: fatal_lang_error('not_a_topic'); Chris@76: } Chris@76: Chris@76: // Replying to a topic? Chris@76: if (!empty($topic) && !isset($_REQUEST['msg'])) Chris@76: { Chris@76: // Don't allow a post if it's locked. Chris@76: if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) Chris@76: fatal_lang_error('topic_locked', false); Chris@76: Chris@76: // Sorry, multiple polls aren't allowed... yet. You should stop giving me ideas :P. Chris@76: if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) Chris@76: unset($_REQUEST['poll']); Chris@76: Chris@76: // Do the permissions and approval stuff... Chris@76: $becomesApproved = true; Chris@76: if ($topic_info['id_member_started'] != $user_info['id']) Chris@76: { Chris@76: if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) Chris@76: $becomesApproved = false; Chris@76: else Chris@76: isAllowedTo('post_reply_any'); Chris@76: } Chris@76: elseif (!allowedTo('post_reply_any')) Chris@76: { Chris@76: if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) Chris@76: $becomesApproved = false; Chris@76: else Chris@76: isAllowedTo('post_reply_own'); Chris@76: } Chris@76: Chris@76: if (isset($_POST['lock'])) Chris@76: { Chris@76: // Nothing is changed to the lock. Chris@76: if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) Chris@76: unset($_POST['lock']); Chris@76: // You're have no permission to lock this topic. Chris@76: elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) Chris@76: unset($_POST['lock']); Chris@76: // You are allowed to (un)lock your own topic only. Chris@76: elseif (!allowedTo('lock_any')) Chris@76: { Chris@76: // You cannot override a moderator lock. Chris@76: if ($topic_info['locked'] == 1) Chris@76: unset($_POST['lock']); Chris@76: else Chris@76: $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; Chris@76: } Chris@76: // Hail mighty moderator, (un)lock this topic immediately. Chris@76: else Chris@76: $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; Chris@76: } Chris@76: Chris@76: // So you wanna (un)sticky this...let's see. Chris@76: if (isset($_POST['sticky']) && (empty($modSettings['enableStickyTopics']) || $_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) Chris@76: unset($_POST['sticky']); Chris@76: Chris@76: // If the number of replies has changed, if the setting is enabled, go back to Post() - which handles the error. Chris@76: if (empty($options['no_new_reply_warning']) && isset($_POST['last_msg']) && $topic_info['id_last_msg'] > $_POST['last_msg']) Chris@76: { Chris@76: $_REQUEST['preview'] = true; Chris@76: return Post(); Chris@76: } Chris@76: Chris@76: $posterIsGuest = $user_info['is_guest']; Chris@76: } Chris@76: // Posting a new topic. Chris@76: elseif (empty($topic)) Chris@76: { Chris@76: // Now don't be silly, new topics will get their own id_msg soon enough. Chris@76: unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); Chris@76: Chris@76: // Do like, the permissions, for safety and stuff... Chris@76: $becomesApproved = true; Chris@76: if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) Chris@76: $becomesApproved = false; Chris@76: else Chris@76: isAllowedTo('post_new'); Chris@76: Chris@76: if (isset($_POST['lock'])) Chris@76: { Chris@76: // New topics are by default not locked. Chris@76: if (empty($_POST['lock'])) Chris@76: unset($_POST['lock']); Chris@76: // Besides, you need permission. Chris@76: elseif (!allowedTo(array('lock_any', 'lock_own'))) Chris@76: unset($_POST['lock']); Chris@76: // A moderator-lock (1) can override a user-lock (2). Chris@76: else Chris@76: $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; Chris@76: } Chris@76: Chris@76: if (isset($_POST['sticky']) && (empty($modSettings['enableStickyTopics']) || empty($_POST['sticky']) || !allowedTo('make_sticky'))) Chris@76: unset($_POST['sticky']); Chris@76: Chris@76: $posterIsGuest = $user_info['is_guest']; Chris@76: } Chris@76: // Modifying an existing message? Chris@76: elseif (isset($_REQUEST['msg']) && !empty($topic)) Chris@76: { Chris@76: $_REQUEST['msg'] = (int) $_REQUEST['msg']; Chris@76: Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_member, poster_name, poster_email, poster_time, approved Chris@76: FROM {db_prefix}messages Chris@76: WHERE id_msg = {int:id_msg} Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'id_msg' => $_REQUEST['msg'], Chris@76: ) Chris@76: ); Chris@76: if ($smcFunc['db_num_rows']($request) == 0) Chris@76: fatal_lang_error('cant_find_messages', false); Chris@76: $row = $smcFunc['db_fetch_assoc']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) Chris@76: fatal_lang_error('topic_locked', false); Chris@76: Chris@76: if (isset($_POST['lock'])) Chris@76: { Chris@76: // Nothing changes to the lock status. Chris@76: if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) Chris@76: unset($_POST['lock']); Chris@76: // You're simply not allowed to (un)lock this. Chris@76: elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) Chris@76: unset($_POST['lock']); Chris@76: // You're only allowed to lock your own topics. Chris@76: elseif (!allowedTo('lock_any')) Chris@76: { Chris@76: // You're not allowed to break a moderator's lock. Chris@76: if ($topic_info['locked'] == 1) Chris@76: unset($_POST['lock']); Chris@76: // Lock it with a soft lock or unlock it. Chris@76: else Chris@76: $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; Chris@76: } Chris@76: // You must be the moderator. Chris@76: else Chris@76: $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; Chris@76: } Chris@76: Chris@76: // Change the sticky status of this topic? Chris@76: if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) Chris@76: unset($_POST['sticky']); Chris@76: Chris@76: if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) Chris@76: { Chris@76: if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) Chris@76: fatal_lang_error('modify_post_time_passed', false); Chris@76: elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) Chris@76: isAllowedTo('modify_replies'); Chris@76: else Chris@76: isAllowedTo('modify_own'); Chris@76: } Chris@76: elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) Chris@76: { Chris@76: isAllowedTo('modify_replies'); Chris@76: Chris@76: // If you're modifying a reply, I say it better be logged... Chris@76: $moderationAction = true; Chris@76: } Chris@76: else Chris@76: { Chris@76: isAllowedTo('modify_any'); Chris@76: Chris@76: // Log it, assuming you're not modifying your own post. Chris@76: if ($row['id_member'] != $user_info['id']) Chris@76: $moderationAction = true; Chris@76: } Chris@76: Chris@76: $posterIsGuest = empty($row['id_member']); Chris@76: Chris@76: // Can they approve it? Chris@76: $can_approve = allowedTo('approve_posts'); Chris@76: $becomesApproved = $modSettings['postmod_active'] ? ($can_approve && !$row['approved'] ? (!empty($_REQUEST['approve']) ? 1 : 0) : $row['approved']) : 1; Chris@76: $approve_has_changed = $row['approved'] != $becomesApproved; Chris@76: Chris@76: if (!allowedTo('moderate_forum') || !$posterIsGuest) Chris@76: { Chris@76: $_POST['guestname'] = $row['poster_name']; Chris@76: $_POST['email'] = $row['poster_email']; Chris@76: } Chris@76: } Chris@76: Chris@76: // If the poster is a guest evaluate the legality of name and email. Chris@76: if ($posterIsGuest) Chris@76: { Chris@76: $_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']); Chris@76: $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']); Chris@76: Chris@76: if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') Chris@76: $post_errors[] = 'no_name'; Chris@76: if ($smcFunc['strlen']($_POST['guestname']) > 25) Chris@76: $post_errors[] = 'long_name'; Chris@76: Chris@76: if (empty($modSettings['guest_post_no_email'])) Chris@76: { Chris@76: // Only check if they changed it! Chris@76: if (!isset($row) || $row['poster_email'] != $_POST['email']) Chris@76: { Chris@76: if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) Chris@76: $post_errors[] = 'no_email'; Chris@76: if (!allowedTo('moderate_forum') && preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['email']) == 0) Chris@76: $post_errors[] = 'bad_email'; Chris@76: } Chris@76: Chris@76: // Now make sure this email address is not banned from posting. Chris@76: isBannedEmail($_POST['email'], 'cannot_post', sprintf($txt['you_are_post_banned'], $txt['guest_title'])); Chris@76: } Chris@76: Chris@76: // In case they are making multiple posts this visit, help them along by storing their name. Chris@76: if (empty($post_errors)) Chris@76: { Chris@76: $_SESSION['guest_name'] = $_POST['guestname']; Chris@76: $_SESSION['guest_email'] = $_POST['email']; Chris@76: } Chris@76: } Chris@76: Chris@76: // Check the subject and message. Chris@76: if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') Chris@76: $post_errors[] = 'no_subject'; Chris@76: if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') Chris@76: $post_errors[] = 'no_message'; Chris@76: elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) Chris@76: $post_errors[] = 'long_message'; Chris@76: else Chris@76: { Chris@76: // Prepare the message a bit for some additional testing. Chris@76: $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); Chris@76: Chris@76: // Preparse code. (Zef) Chris@76: if ($user_info['is_guest']) Chris@76: $user_info['name'] = $_POST['guestname']; Chris@76: preparsecode($_POST['message']); Chris@76: Chris@76: // Let's see if there's still some content left without the tags. Chris@76: if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), '')) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) Chris@76: $post_errors[] = 'no_message'; Chris@76: } Chris@76: if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') Chris@76: $post_errors[] = 'no_event'; Chris@76: // You are not! Chris@76: if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) Chris@76: fatal_error('Knave! Masquerader! Charlatan!', false); Chris@76: Chris@76: // Validate the poll... Chris@76: if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') Chris@76: { Chris@76: if (!empty($topic) && !isset($_REQUEST['msg'])) Chris@76: fatal_lang_error('no_access', false); Chris@76: Chris@76: // This is a new topic... so it's a new poll. Chris@76: if (empty($topic)) Chris@76: isAllowedTo('poll_post'); Chris@76: // Can you add to your own topics? Chris@76: elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) Chris@76: isAllowedTo('poll_add_own'); Chris@76: // Can you add polls to any topic, then? Chris@76: else Chris@76: isAllowedTo('poll_add_any'); Chris@76: Chris@76: if (!isset($_POST['question']) || trim($_POST['question']) == '') Chris@76: $post_errors[] = 'no_question'; Chris@76: Chris@76: $_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']); Chris@76: Chris@76: // Get rid of empty ones. Chris@76: foreach ($_POST['options'] as $k => $option) Chris@76: if ($option == '') Chris@76: unset($_POST['options'][$k], $_POST['options'][$k]); Chris@76: Chris@76: // What are you going to vote between with one choice?!? Chris@76: if (count($_POST['options']) < 2) Chris@76: $post_errors[] = 'poll_few'; Chris@76: } Chris@76: Chris@76: if ($posterIsGuest) Chris@76: { Chris@76: // If user is a guest, make sure the chosen name isn't taken. Chris@76: require_once($sourcedir . '/Subs-Members.php'); Chris@76: if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) Chris@76: $post_errors[] = 'bad_name'; Chris@76: } Chris@76: // If the user isn't a guest, get his or her name and email. Chris@76: elseif (!isset($_REQUEST['msg'])) Chris@76: { Chris@76: $_POST['guestname'] = $user_info['username']; Chris@76: $_POST['email'] = $user_info['email']; Chris@76: } Chris@76: Chris@76: // Any mistakes? Chris@76: if (!empty($post_errors)) Chris@76: { Chris@76: loadLanguage('Errors'); Chris@76: // Previewing. Chris@76: $_REQUEST['preview'] = true; Chris@76: Chris@76: $context['post_error'] = array('messages' => array()); Chris@76: foreach ($post_errors as $post_error) Chris@76: { Chris@76: $context['post_error'][$post_error] = true; Chris@76: if ($post_error == 'long_message') Chris@76: $txt['error_' . $post_error] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); Chris@76: Chris@76: $context['post_error']['messages'][] = $txt['error_' . $post_error]; Chris@76: } Chris@76: Chris@76: return Post(); Chris@76: } Chris@76: Chris@76: // Make sure the user isn't spamming the board. Chris@76: if (!isset($_REQUEST['msg'])) Chris@76: spamProtection('post'); Chris@76: Chris@76: // At about this point, we're posting and that's that. Chris@76: ignore_user_abort(true); Chris@76: @set_time_limit(300); Chris@76: Chris@76: // Add special html entities to the subject, name, and email. Chris@76: $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => '')); Chris@76: $_POST['guestname'] = htmlspecialchars($_POST['guestname']); Chris@76: $_POST['email'] = htmlspecialchars($_POST['email']); Chris@76: Chris@76: // At this point, we want to make sure the subject isn't too long. Chris@76: if ($smcFunc['strlen']($_POST['subject']) > 100) Chris@76: $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); Chris@76: Chris@76: // Make the poll... Chris@76: if (isset($_REQUEST['poll'])) Chris@76: { Chris@76: // Make sure that the user has not entered a ridiculous number of options.. Chris@76: if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) Chris@76: $_POST['poll_max_votes'] = 1; Chris@76: elseif ($_POST['poll_max_votes'] > count($_POST['options'])) Chris@76: $_POST['poll_max_votes'] = count($_POST['options']); Chris@76: else Chris@76: $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; Chris@76: Chris@76: $_POST['poll_expire'] = (int) $_POST['poll_expire']; Chris@76: $_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']); Chris@76: Chris@76: // Just set it to zero if it's not there.. Chris@76: if (!isset($_POST['poll_hide'])) Chris@76: $_POST['poll_hide'] = 0; Chris@76: else Chris@76: $_POST['poll_hide'] = (int) $_POST['poll_hide']; Chris@76: $_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0; Chris@76: Chris@76: $_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0; Chris@76: // Make sure guests are actually allowed to vote generally. Chris@76: if ($_POST['poll_guest_vote']) Chris@76: { Chris@76: require_once($sourcedir . '/Subs-Members.php'); Chris@76: $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); Chris@76: if (!in_array(-1, $allowedVoteGroups['allowed'])) Chris@76: $_POST['poll_guest_vote'] = 0; Chris@76: } Chris@76: Chris@76: // If the user tries to set the poll too far in advance, don't let them. Chris@76: if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) Chris@76: fatal_lang_error('poll_range_error', false); Chris@76: // Don't allow them to select option 2 for hidden results if it's not time limited. Chris@76: elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) Chris@76: $_POST['poll_hide'] = 1; Chris@76: Chris@76: // Clean up the question and answers. Chris@76: $_POST['question'] = htmlspecialchars($_POST['question']); Chris@76: $_POST['question'] = $smcFunc['truncate']($_POST['question'], 255); Chris@76: $_POST['question'] = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $_POST['question']); Chris@76: $_POST['options'] = htmlspecialchars__recursive($_POST['options']); Chris@76: } Chris@76: Chris@76: // Check if they are trying to delete any current attachments.... Chris@76: if (isset($_REQUEST['msg'], $_POST['attach_del']) && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')))) Chris@76: { Chris@76: $del_temp = array(); Chris@76: foreach ($_POST['attach_del'] as $i => $dummy) Chris@76: $del_temp[$i] = (int) $dummy; Chris@76: Chris@76: require_once($sourcedir . '/ManageAttachments.php'); Chris@76: $attachmentQuery = array( Chris@76: 'attachment_type' => 0, Chris@76: 'id_msg' => (int) $_REQUEST['msg'], Chris@76: 'not_id_attach' => $del_temp, Chris@76: ); Chris@76: removeAttachments($attachmentQuery); Chris@76: } Chris@76: Chris@76: // ...or attach a new file... Chris@76: if (isset($_FILES['attachment']['name']) || (!empty($_SESSION['temp_attachments']) && empty($_POST['from_qr']))) Chris@76: { Chris@76: // Verify they can post them! Chris@76: if (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_attachments')) Chris@76: isAllowedTo('post_attachment'); Chris@76: Chris@76: // Make sure we're uploading to the right place. Chris@76: if (!empty($modSettings['currentAttachmentUploadDir'])) Chris@76: { Chris@76: if (!is_array($modSettings['attachmentUploadDir'])) Chris@76: $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']); Chris@76: Chris@76: // The current directory, of course! Chris@76: $current_attach_dir = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; Chris@76: } Chris@76: else Chris@76: $current_attach_dir = $modSettings['attachmentUploadDir']; Chris@76: Chris@76: // If this isn't a new post, check the current attachments. Chris@76: if (isset($_REQUEST['msg'])) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT COUNT(*), SUM(size) Chris@76: FROM {db_prefix}attachments Chris@76: WHERE id_msg = {int:id_msg} Chris@76: AND attachment_type = {int:attachment_type}', Chris@76: array( Chris@76: 'id_msg' => (int) $_REQUEST['msg'], Chris@76: 'attachment_type' => 0, Chris@76: ) Chris@76: ); Chris@76: list ($quantity, $total_size) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: } Chris@76: else Chris@76: { Chris@76: $quantity = 0; Chris@76: $total_size = 0; Chris@76: } Chris@76: Chris@76: if (!empty($_SESSION['temp_attachments'])) Chris@76: foreach ($_SESSION['temp_attachments'] as $attachID => $name) Chris@76: { Chris@76: if (preg_match('~^post_tmp_' . $user_info['id'] . '_\d+$~', $attachID) == 0) Chris@76: continue; Chris@76: Chris@76: if (!empty($_POST['attach_del']) && !in_array($attachID, $_POST['attach_del'])) Chris@76: { Chris@76: unset($_SESSION['temp_attachments'][$attachID]); Chris@76: @unlink($current_attach_dir . '/' . $attachID); Chris@76: continue; Chris@76: } Chris@76: Chris@76: $_FILES['attachment']['tmp_name'][] = $attachID; Chris@76: $_FILES['attachment']['name'][] = $name; Chris@76: $_FILES['attachment']['size'][] = filesize($current_attach_dir . '/' . $attachID); Chris@76: list ($_FILES['attachment']['width'][], $_FILES['attachment']['height'][]) = @getimagesize($current_attach_dir . '/' . $attachID); Chris@76: Chris@76: unset($_SESSION['temp_attachments'][$attachID]); Chris@76: } Chris@76: Chris@76: if (!isset($_FILES['attachment']['name'])) Chris@76: $_FILES['attachment']['tmp_name'] = array(); Chris@76: Chris@76: $attachIDs = array(); Chris@76: foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) Chris@76: { Chris@76: if ($_FILES['attachment']['name'][$n] == '') Chris@76: continue; Chris@76: Chris@76: // Have we reached the maximum number of files we are allowed? Chris@76: $quantity++; Chris@76: if (!empty($modSettings['attachmentNumPerPostLimit']) && $quantity > $modSettings['attachmentNumPerPostLimit']) Chris@76: { Chris@76: checkSubmitOnce('free'); Chris@76: fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit'])); Chris@76: } Chris@76: Chris@76: // Check the total upload size for this post... Chris@76: $total_size += $_FILES['attachment']['size'][$n]; Chris@76: if (!empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024) Chris@76: { Chris@76: checkSubmitOnce('free'); Chris@76: fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit'])); Chris@76: } Chris@76: Chris@76: $attachmentOptions = array( Chris@76: 'post' => isset($_REQUEST['msg']) ? $_REQUEST['msg'] : 0, Chris@76: 'poster' => $user_info['id'], Chris@76: 'name' => $_FILES['attachment']['name'][$n], Chris@76: 'tmp_name' => $_FILES['attachment']['tmp_name'][$n], Chris@76: 'size' => $_FILES['attachment']['size'][$n], Chris@76: 'approved' => !$modSettings['postmod_active'] || allowedTo('post_attachment'), Chris@76: ); Chris@76: Chris@76: if (createAttachment($attachmentOptions)) Chris@76: { Chris@76: $attachIDs[] = $attachmentOptions['id']; Chris@76: if (!empty($attachmentOptions['thumb'])) Chris@76: $attachIDs[] = $attachmentOptions['thumb']; Chris@76: } Chris@76: else Chris@76: { Chris@76: if (in_array('could_not_upload', $attachmentOptions['errors'])) Chris@76: { Chris@76: checkSubmitOnce('free'); Chris@76: fatal_lang_error('attach_timeout', 'critical'); Chris@76: } Chris@76: if (in_array('too_large', $attachmentOptions['errors'])) Chris@76: { Chris@76: checkSubmitOnce('free'); Chris@76: fatal_lang_error('file_too_big', false, array($modSettings['attachmentSizeLimit'])); Chris@76: } Chris@76: if (in_array('bad_extension', $attachmentOptions['errors'])) Chris@76: { Chris@76: checkSubmitOnce('free'); Chris@76: fatal_error($attachmentOptions['name'] . '.
' . $txt['cant_upload_type'] . ' ' . $modSettings['attachmentExtensions'] . '.', false); Chris@76: } Chris@76: if (in_array('directory_full', $attachmentOptions['errors'])) Chris@76: { Chris@76: checkSubmitOnce('free'); Chris@76: fatal_lang_error('ran_out_of_space', 'critical'); Chris@76: } Chris@76: if (in_array('bad_filename', $attachmentOptions['errors'])) Chris@76: { Chris@76: checkSubmitOnce('free'); Chris@76: fatal_error(basename($attachmentOptions['name']) . '.
' . $txt['restricted_filename'] . '.', 'critical'); Chris@76: } Chris@76: if (in_array('taken_filename', $attachmentOptions['errors'])) Chris@76: { Chris@76: checkSubmitOnce('free'); Chris@76: fatal_lang_error('filename_exists'); Chris@76: } Chris@76: if (in_array('bad_attachment', $attachmentOptions['errors'])) Chris@76: { Chris@76: checkSubmitOnce('free'); Chris@76: fatal_lang_error('bad_attachment'); Chris@76: } Chris@76: } Chris@76: } Chris@76: } Chris@76: Chris@76: // Make the poll... Chris@76: if (isset($_REQUEST['poll'])) Chris@76: { Chris@76: // Create the poll. Chris@76: $smcFunc['db_insert']('', Chris@76: '{db_prefix}polls', Chris@76: array( Chris@76: 'question' => 'string-255', 'hide_results' => 'int', 'max_votes' => 'int', 'expire_time' => 'int', 'id_member' => 'int', Chris@76: 'poster_name' => 'string-255', 'change_vote' => 'int', 'guest_vote' => 'int' Chris@76: ), Chris@76: array( Chris@76: $_POST['question'], $_POST['poll_hide'], $_POST['poll_max_votes'], (empty($_POST['poll_expire']) ? 0 : time() + $_POST['poll_expire'] * 3600 * 24), $user_info['id'], Chris@76: $_POST['guestname'], $_POST['poll_change_vote'], $_POST['poll_guest_vote'], Chris@76: ), Chris@76: array('id_poll') Chris@76: ); Chris@76: $id_poll = $smcFunc['db_insert_id']('{db_prefix}polls', 'id_poll'); Chris@76: Chris@76: // Create each answer choice. Chris@76: $i = 0; Chris@76: $pollOptions = array(); Chris@76: foreach ($_POST['options'] as $option) Chris@76: { Chris@76: $pollOptions[] = array($id_poll, $i, $option); Chris@76: $i++; Chris@76: } Chris@76: Chris@76: $smcFunc['db_insert']('insert', Chris@76: '{db_prefix}poll_choices', Chris@76: array('id_poll' => 'int', 'id_choice' => 'int', 'label' => 'string-255'), Chris@76: $pollOptions, Chris@76: array('id_poll', 'id_choice') Chris@76: ); Chris@76: } Chris@76: else Chris@76: $id_poll = 0; Chris@76: Chris@76: // Creating a new topic? Chris@76: $newTopic = empty($_REQUEST['msg']) && empty($topic); Chris@76: Chris@76: $_POST['icon'] = !empty($attachIDs) && $_POST['icon'] == 'xx' ? 'clip' : $_POST['icon']; Chris@76: Chris@76: // Collect all parameters for the creation or modification of a post. Chris@76: $msgOptions = array( Chris@76: 'id' => empty($_REQUEST['msg']) ? 0 : (int) $_REQUEST['msg'], Chris@76: 'subject' => $_POST['subject'], Chris@76: 'body' => $_POST['message'], Chris@76: 'icon' => preg_replace('~[\./\\\\*:"\'<>]~', '', $_POST['icon']), Chris@76: 'smileys_enabled' => !isset($_POST['ns']), Chris@76: 'attachments' => empty($attachIDs) ? array() : $attachIDs, Chris@76: 'approved' => $becomesApproved, Chris@76: ); Chris@76: $topicOptions = array( Chris@76: 'id' => empty($topic) ? 0 : $topic, Chris@76: 'board' => $board, Chris@76: 'poll' => isset($_REQUEST['poll']) ? $id_poll : null, Chris@76: 'lock_mode' => isset($_POST['lock']) ? (int) $_POST['lock'] : null, Chris@76: 'sticky_mode' => isset($_POST['sticky']) && !empty($modSettings['enableStickyTopics']) ? (int) $_POST['sticky'] : null, Chris@76: 'mark_as_read' => true, Chris@76: 'is_approved' => !$modSettings['postmod_active'] || empty($topic) || !empty($board_info['cur_topic_approved']), Chris@76: ); Chris@76: $posterOptions = array( Chris@76: 'id' => $user_info['id'], Chris@76: 'name' => $_POST['guestname'], Chris@76: 'email' => $_POST['email'], Chris@76: 'update_post_count' => !$user_info['is_guest'] && !isset($_REQUEST['msg']) && $board_info['posts_count'], Chris@76: ); Chris@76: Chris@76: // This is an already existing message. Edit it. Chris@76: if (!empty($_REQUEST['msg'])) Chris@76: { Chris@76: // Have admins allowed people to hide their screwups? Chris@76: if (time() - $row['poster_time'] > $modSettings['edit_wait_time'] || $user_info['id'] != $row['id_member']) Chris@76: { Chris@76: $msgOptions['modify_time'] = time(); Chris@76: $msgOptions['modify_name'] = $user_info['name']; Chris@76: } Chris@76: Chris@76: // This will save some time... Chris@76: if (empty($approve_has_changed)) Chris@76: unset($msgOptions['approved']); Chris@76: Chris@76: modifyPost($msgOptions, $topicOptions, $posterOptions); Chris@76: } Chris@76: // This is a new topic or an already existing one. Save it. Chris@76: else Chris@76: { Chris@76: createPost($msgOptions, $topicOptions, $posterOptions); Chris@76: Chris@76: if (isset($topicOptions['id'])) Chris@76: $topic = $topicOptions['id']; Chris@76: } Chris@76: Chris@76: // Editing or posting an event? Chris@76: if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1)) Chris@76: { Chris@76: require_once($sourcedir . '/Subs-Calendar.php'); Chris@76: Chris@76: // Make sure they can link an event to this post. Chris@76: canLinkEvent(); Chris@76: Chris@76: // Insert the event. Chris@76: $eventOptions = array( Chris@76: 'board' => $board, Chris@76: 'topic' => $topic, Chris@76: 'title' => $_POST['evtitle'], Chris@76: 'member' => $user_info['id'], Chris@76: 'start_date' => sprintf('%04d-%02d-%02d', $_POST['year'], $_POST['month'], $_POST['day']), Chris@76: 'span' => isset($_POST['span']) && $_POST['span'] > 0 ? min((int) $modSettings['cal_maxspan'], (int) $_POST['span'] - 1) : 0, Chris@76: ); Chris@76: insertEvent($eventOptions); Chris@76: } Chris@76: elseif (isset($_POST['calendar'])) Chris@76: { Chris@76: $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; Chris@76: Chris@76: // Validate the post... Chris@76: require_once($sourcedir . '/Subs-Calendar.php'); Chris@76: validateEventPost(); Chris@76: Chris@76: // If you're not allowed to edit any events, you have to be the poster. Chris@76: if (!allowedTo('calendar_edit_any')) Chris@76: { Chris@76: // Get the event's poster. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_member Chris@76: FROM {db_prefix}calendar Chris@76: WHERE id_event = {int:id_event}', Chris@76: array( Chris@76: 'id_event' => $_REQUEST['eventid'], Chris@76: ) Chris@76: ); Chris@76: $row2 = $smcFunc['db_fetch_assoc']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Silly hacker, Trix are for kids. ...probably trademarked somewhere, this is FAIR USE! (parody...) Chris@76: isAllowedTo('calendar_edit_' . ($row2['id_member'] == $user_info['id'] ? 'own' : 'any')); Chris@76: } Chris@76: Chris@76: // Delete it? Chris@76: if (isset($_REQUEST['deleteevent'])) Chris@76: $smcFunc['db_query']('', ' Chris@76: DELETE FROM {db_prefix}calendar Chris@76: WHERE id_event = {int:id_event}', Chris@76: array( Chris@76: 'id_event' => $_REQUEST['eventid'], Chris@76: ) Chris@76: ); Chris@76: // ... or just update it? Chris@76: else Chris@76: { Chris@76: $span = !empty($modSettings['cal_allowspan']) && !empty($_REQUEST['span']) ? min((int) $modSettings['cal_maxspan'], (int) $_REQUEST['span'] - 1) : 0; Chris@76: $start_time = mktime(0, 0, 0, (int) $_REQUEST['month'], (int) $_REQUEST['day'], (int) $_REQUEST['year']); Chris@76: Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}calendar Chris@76: SET end_date = {date:end_date}, Chris@76: start_date = {date:start_date}, Chris@76: title = {string:title} Chris@76: WHERE id_event = {int:id_event}', Chris@76: array( Chris@76: 'end_date' => strftime('%Y-%m-%d', $start_time + $span * 86400), Chris@76: 'start_date' => strftime('%Y-%m-%d', $start_time), Chris@76: 'id_event' => $_REQUEST['eventid'], Chris@76: 'title' => $smcFunc['htmlspecialchars']($_REQUEST['evtitle'], ENT_QUOTES), Chris@76: ) Chris@76: ); Chris@76: } Chris@76: updateSettings(array( Chris@76: 'calendar_updated' => time(), Chris@76: )); Chris@76: } Chris@76: Chris@76: // Marking read should be done even for editing messages.... Chris@76: // Mark all the parents read. (since you just posted and they will be unread.) Chris@76: if (!$user_info['is_guest'] && !empty($board_info['parent_boards'])) Chris@76: { Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}log_boards Chris@76: SET id_msg = {int:id_msg} Chris@76: WHERE id_member = {int:current_member} Chris@76: AND id_board IN ({array_int:board_list})', Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: 'board_list' => array_keys($board_info['parent_boards']), Chris@76: 'id_msg' => $modSettings['maxMsgID'], Chris@76: ) Chris@76: ); Chris@76: } Chris@76: Chris@76: // Turn notification on or off. (note this just blows smoke if it's already on or off.) Chris@76: if (!empty($_POST['notify']) && allowedTo('mark_any_notify')) Chris@76: { Chris@76: $smcFunc['db_insert']('ignore', Chris@76: '{db_prefix}log_notify', Chris@76: array('id_member' => 'int', 'id_topic' => 'int', 'id_board' => 'int'), Chris@76: array($user_info['id'], $topic, 0), Chris@76: array('id_member', 'id_topic', 'id_board') Chris@76: ); Chris@76: } Chris@76: elseif (!$newTopic) Chris@76: $smcFunc['db_query']('', ' Chris@76: DELETE FROM {db_prefix}log_notify Chris@76: WHERE id_member = {int:current_member} Chris@76: AND id_topic = {int:current_topic}', Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: 'current_topic' => $topic, Chris@76: ) Chris@76: ); Chris@76: Chris@76: // Log an act of moderation - modifying. Chris@76: if (!empty($moderationAction)) Chris@76: logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); Chris@76: Chris@76: if (isset($_POST['lock']) && $_POST['lock'] != 2) Chris@76: logAction('lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); Chris@76: Chris@76: if (isset($_POST['sticky']) && !empty($modSettings['enableStickyTopics'])) Chris@76: logAction('sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); Chris@76: Chris@76: // Notify any members who have notification turned on for this topic - only do this if it's going to be approved(!) Chris@76: if ($becomesApproved) Chris@76: { Chris@76: if ($newTopic) Chris@76: { Chris@76: $notifyData = array( Chris@76: 'body' => $_POST['message'], Chris@76: 'subject' => $_POST['subject'], Chris@76: 'name' => $user_info['name'], Chris@76: 'poster' => $user_info['id'], Chris@76: 'msg' => $msgOptions['id'], Chris@76: 'board' => $board, Chris@76: 'topic' => $topic, Chris@76: ); Chris@76: notifyMembersBoard($notifyData); Chris@76: } Chris@76: elseif (empty($_REQUEST['msg'])) Chris@76: { Chris@76: // Only send it to everyone if the topic is approved, otherwise just to the topic starter if they want it. Chris@76: if ($topic_info['approved']) Chris@76: sendNotifications($topic, 'reply'); Chris@76: else Chris@76: sendNotifications($topic, 'reply', array(), $topic_info['id_member_started']); Chris@76: } Chris@76: } Chris@76: Chris@76: // Returning to the topic? Chris@76: if (!empty($_REQUEST['goback'])) Chris@76: { Chris@76: // Mark the board as read.... because it might get confusing otherwise. Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}log_boards Chris@76: SET id_msg = {int:maxMsgID} Chris@76: WHERE id_member = {int:current_member} Chris@76: AND id_board = {int:current_board}', Chris@76: array( Chris@76: 'current_board' => $board, Chris@76: 'current_member' => $user_info['id'], Chris@76: 'maxMsgID' => $modSettings['maxMsgID'], Chris@76: ) Chris@76: ); Chris@76: } Chris@76: Chris@76: if ($board_info['num_topics'] == 0) Chris@76: cache_put_data('board-' . $board, null, 120); Chris@76: Chris@76: if (!empty($_POST['announce_topic'])) Chris@76: redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); Chris@76: Chris@76: if (!empty($_POST['move']) && allowedTo('move_any')) Chris@76: redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); Chris@76: Chris@76: // Return to post if the mod is on. Chris@76: if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) Chris@76: redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], $context['browser']['is_ie']); Chris@76: elseif (!empty($_REQUEST['goback'])) Chris@76: redirectexit('topic=' . $topic . '.new#new', $context['browser']['is_ie']); Chris@76: // Dut-dut-duh-duh-DUH-duh-dut-duh-duh! *dances to the Final Fantasy Fanfare...* Chris@76: else Chris@76: redirectexit('board=' . $board . '.0'); Chris@76: } Chris@76: Chris@76: // General function for topic announcements. Chris@76: function AnnounceTopic() Chris@76: { Chris@76: global $context, $txt, $topic; Chris@76: Chris@76: isAllowedTo('announce_topic'); Chris@76: Chris@76: validateSession(); Chris@76: Chris@76: if (empty($topic)) Chris@76: fatal_lang_error('topic_gone', false); Chris@76: Chris@76: loadLanguage('Post'); Chris@76: loadTemplate('Post'); Chris@76: Chris@76: $subActions = array( Chris@76: 'selectgroup' => 'AnnouncementSelectMembergroup', Chris@76: 'send' => 'AnnouncementSend', Chris@76: ); Chris@76: Chris@76: $context['page_title'] = $txt['announce_topic']; Chris@76: Chris@76: // Call the function based on the sub-action. Chris@76: $subActions[isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'selectgroup'](); Chris@76: } Chris@76: Chris@76: // Allow a user to chose the membergroups to send the announcement to. Chris@76: function AnnouncementSelectMembergroup() Chris@76: { Chris@76: global $txt, $context, $topic, $board, $board_info, $smcFunc; Chris@76: Chris@76: $groups = array_merge($board_info['groups'], array(1)); Chris@76: foreach ($groups as $id => $group) Chris@76: $groups[$id] = (int) $group; Chris@76: Chris@76: $context['groups'] = array(); Chris@76: if (in_array(0, $groups)) Chris@76: { Chris@76: $context['groups'][0] = array( Chris@76: 'id' => 0, Chris@76: 'name' => $txt['announce_regular_members'], Chris@76: 'member_count' => 'n/a', Chris@76: ); Chris@76: } Chris@76: Chris@76: // Get all membergroups that have access to the board the announcement was made on. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT mg.id_group, COUNT(mem.id_member) AS num_members Chris@76: FROM {db_prefix}membergroups AS mg Chris@76: LEFT JOIN {db_prefix}members AS mem ON (mem.id_group = mg.id_group OR FIND_IN_SET(mg.id_group, mem.additional_groups) != 0 OR mg.id_group = mem.id_post_group) Chris@76: WHERE mg.id_group IN ({array_int:group_list}) Chris@76: GROUP BY mg.id_group', Chris@76: array( Chris@76: 'group_list' => $groups, Chris@76: 'newbie_id_group' => 4, Chris@76: ) Chris@76: ); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: $context['groups'][$row['id_group']] = array( Chris@76: 'id' => $row['id_group'], Chris@76: 'name' => '', Chris@76: 'member_count' => $row['num_members'], Chris@76: ); Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Now get the membergroup names. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_group, group_name Chris@76: FROM {db_prefix}membergroups Chris@76: WHERE id_group IN ({array_int:group_list})', Chris@76: array( Chris@76: 'group_list' => $groups, Chris@76: ) Chris@76: ); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: $context['groups'][$row['id_group']]['name'] = $row['group_name']; Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Get the subject of the topic we're about to announce. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT m.subject Chris@76: FROM {db_prefix}topics AS t Chris@76: INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg) Chris@76: WHERE t.id_topic = {int:current_topic}', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: ) Chris@76: ); Chris@76: list ($context['topic_subject']) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: censorText($context['announce_topic']['subject']); Chris@76: Chris@76: $context['move'] = isset($_REQUEST['move']) ? 1 : 0; Chris@76: $context['go_back'] = isset($_REQUEST['goback']) ? 1 : 0; Chris@76: Chris@76: $context['sub_template'] = 'announce'; Chris@76: } Chris@76: Chris@76: // Send the announcement in chunks. Chris@76: function AnnouncementSend() Chris@76: { Chris@76: global $topic, $board, $board_info, $context, $modSettings; Chris@76: global $language, $scripturl, $txt, $user_info, $sourcedir, $smcFunc; Chris@76: Chris@76: checkSession(); Chris@76: Chris@76: // !!! Might need an interface? Chris@76: $chunkSize = empty($modSettings['mail_queue']) ? 50 : 500; Chris@76: Chris@76: $context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start']; Chris@76: $groups = array_merge($board_info['groups'], array(1)); Chris@76: Chris@76: if (isset($_POST['membergroups'])) Chris@76: $_POST['who'] = explode(',', $_POST['membergroups']); Chris@76: Chris@76: // Check whether at least one membergroup was selected. Chris@76: if (empty($_POST['who'])) Chris@76: fatal_lang_error('no_membergroup_selected'); Chris@76: Chris@76: // Make sure all membergroups are integers and can access the board of the announcement. Chris@76: foreach ($_POST['who'] as $id => $mg) Chris@76: $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; Chris@76: Chris@76: // Get the topic subject and censor it. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT m.id_msg, m.subject, m.body Chris@76: FROM {db_prefix}topics AS t Chris@76: INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg) Chris@76: WHERE t.id_topic = {int:current_topic}', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: ) Chris@76: ); Chris@76: list ($id_msg, $context['topic_subject'], $message) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: censorText($context['topic_subject']); Chris@76: censorText($message); Chris@76: Chris@76: $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($message, false, $id_msg), array('
' => "\n", '' => "\n", '' => "\n", '[' => '[', ']' => ']'))))); Chris@76: Chris@76: // We need this in order to be able send emails. Chris@76: require_once($sourcedir . '/Subs-Post.php'); Chris@76: Chris@76: // Select the email addresses for this batch. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT mem.id_member, mem.email_address, mem.lngfile Chris@76: FROM {db_prefix}members AS mem Chris@76: WHERE mem.id_member != {int:current_member}' . (!empty($modSettings['allow_disableAnnounce']) ? ' Chris@76: AND mem.notify_announcements = {int:notify_announcements}' : '') . ' Chris@76: AND mem.is_activated = {int:is_activated} Chris@76: AND (mem.id_group IN ({array_int:group_list}) OR mem.id_post_group IN ({array_int:group_list}) OR FIND_IN_SET({raw:additional_group_list}, mem.additional_groups) != 0) Chris@76: AND mem.id_member > {int:start} Chris@76: ORDER BY mem.id_member Chris@76: LIMIT ' . $chunkSize, Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: 'group_list' => $_POST['who'], Chris@76: 'notify_announcements' => 1, Chris@76: 'is_activated' => 1, Chris@76: 'start' => $context['start'], Chris@76: 'additional_group_list' => implode(', mem.additional_groups) != 0 OR FIND_IN_SET(', $_POST['who']), Chris@76: ) Chris@76: ); Chris@76: Chris@76: // All members have received a mail. Go to the next screen. Chris@76: if ($smcFunc['db_num_rows']($request) == 0) Chris@76: { Chris@76: if (!empty($_REQUEST['move']) && allowedTo('move_any')) Chris@76: redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); Chris@76: elseif (!empty($_REQUEST['goback'])) Chris@76: redirectexit('topic=' . $topic . '.new;boardseen#new', $context['browser']['is_ie']); Chris@76: else Chris@76: redirectexit('board=' . $board . '.0'); Chris@76: } Chris@76: Chris@76: // Loop through all members that'll receive an announcement in this batch. Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: $cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']; Chris@76: Chris@76: // If the language wasn't defined yet, load it and compose a notification message. Chris@76: if (!isset($announcements[$cur_language])) Chris@76: { Chris@76: $replacements = array( Chris@76: 'TOPICSUBJECT' => $context['topic_subject'], Chris@76: 'MESSAGE' => $message, Chris@76: 'TOPICLINK' => $scripturl . '?topic=' . $topic . '.0', Chris@76: ); Chris@76: Chris@76: $emaildata = loadEmailTemplate('new_announcement', $replacements, $cur_language); Chris@76: Chris@76: $announcements[$cur_language] = array( Chris@76: 'subject' => $emaildata['subject'], Chris@76: 'body' => $emaildata['body'], Chris@76: 'recipients' => array(), Chris@76: ); Chris@76: } Chris@76: Chris@76: $announcements[$cur_language]['recipients'][$row['id_member']] = $row['email_address']; Chris@76: $context['start'] = $row['id_member']; Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // For each language send a different mail - low priority... Chris@76: foreach ($announcements as $lang => $mail) Chris@76: sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, null, false, 5); Chris@76: Chris@76: $context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1); Chris@76: Chris@76: $context['move'] = empty($_REQUEST['move']) ? 0 : 1; Chris@76: $context['go_back'] = empty($_REQUEST['goback']) ? 0 : 1; Chris@76: $context['membergroups'] = implode(',', $_POST['who']); Chris@76: $context['sub_template'] = 'announcement_send'; Chris@76: Chris@76: // Go back to the correct language for the user ;). Chris@76: if (!empty($modSettings['userLanguage'])) Chris@76: loadLanguage('Post'); Chris@76: } Chris@76: Chris@76: // Notify members of a new post. Chris@76: function notifyMembersBoard(&$topicData) Chris@76: { Chris@76: global $txt, $scripturl, $language, $user_info; Chris@76: global $modSettings, $sourcedir, $board, $smcFunc, $context; Chris@76: Chris@76: require_once($sourcedir . '/Subs-Post.php'); Chris@76: Chris@76: // Do we have one or lots of topics? Chris@76: if (isset($topicData['body'])) Chris@76: $topicData = array($topicData); Chris@76: Chris@76: // Find out what boards we have... and clear out any rubbish! Chris@76: $boards = array(); Chris@76: foreach ($topicData as $key => $topic) Chris@76: { Chris@76: if (!empty($topic['board'])) Chris@76: $boards[$topic['board']][] = $key; Chris@76: else Chris@76: { Chris@76: unset($topic[$key]); Chris@76: continue; Chris@76: } Chris@76: Chris@76: // Censor the subject and body... Chris@76: censorText($topicData[$key]['subject']); Chris@76: censorText($topicData[$key]['body']); Chris@76: Chris@76: $topicData[$key]['subject'] = un_htmlspecialchars($topicData[$key]['subject']); Chris@76: $topicData[$key]['body'] = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($topicData[$key]['body'], false), array('
' => "\n", '' => "\n", '' => "\n", '[' => '[', ']' => ']'))))); Chris@76: } Chris@76: Chris@76: // Just the board numbers. Chris@76: $board_index = array_unique(array_keys($boards)); Chris@76: Chris@76: if (empty($board_index)) Chris@76: return; Chris@76: Chris@76: // Yea, we need to add this to the digest queue. Chris@76: $digest_insert = array(); Chris@76: foreach ($topicData as $id => $data) Chris@76: $digest_insert[] = array($data['topic'], $data['msg'], 'topic', $user_info['id']); Chris@76: $smcFunc['db_insert']('', Chris@76: '{db_prefix}log_digest', Chris@76: array( Chris@76: 'id_topic' => 'int', 'id_msg' => 'int', 'note_type' => 'string', 'exclude' => 'int', Chris@76: ), Chris@76: $digest_insert, Chris@76: array() Chris@76: ); Chris@76: Chris@76: // Find the members with notification on for these boards. Chris@76: $members = $smcFunc['db_query']('', ' Chris@76: SELECT Chris@76: mem.id_member, mem.email_address, mem.notify_regularity, mem.notify_send_body, mem.lngfile, Chris@76: ln.sent, ln.id_board, mem.id_group, mem.additional_groups, b.member_groups, Chris@76: mem.id_post_group Chris@76: FROM {db_prefix}log_notify AS ln Chris@76: INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board) Chris@76: INNER JOIN {db_prefix}members AS mem ON (mem.id_member = ln.id_member) Chris@76: WHERE ln.id_board IN ({array_int:board_list}) Chris@76: AND mem.id_member != {int:current_member} Chris@76: AND mem.is_activated = {int:is_activated} Chris@76: AND mem.notify_types != {int:notify_types} Chris@76: AND mem.notify_regularity < {int:notify_regularity} Chris@76: ORDER BY mem.lngfile', Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: 'board_list' => $board_index, Chris@76: 'is_activated' => 1, Chris@76: 'notify_types' => 4, Chris@76: 'notify_regularity' => 2, Chris@76: ) Chris@76: ); Chris@76: while ($rowmember = $smcFunc['db_fetch_assoc']($members)) Chris@76: { Chris@76: if ($rowmember['id_group'] != 1) Chris@76: { Chris@76: $allowed = explode(',', $rowmember['member_groups']); Chris@76: $rowmember['additional_groups'] = explode(',', $rowmember['additional_groups']); Chris@76: $rowmember['additional_groups'][] = $rowmember['id_group']; Chris@76: $rowmember['additional_groups'][] = $rowmember['id_post_group']; Chris@76: Chris@76: if (count(array_intersect($allowed, $rowmember['additional_groups'])) == 0) Chris@76: continue; Chris@76: } Chris@76: Chris@76: $langloaded = loadLanguage('EmailTemplates', empty($rowmember['lngfile']) || empty($modSettings['userLanguage']) ? $language : $rowmember['lngfile'], false); Chris@76: Chris@76: // Now loop through all the notifications to send for this board. Chris@76: if (empty($boards[$rowmember['id_board']])) Chris@76: continue; Chris@76: Chris@76: $sentOnceAlready = 0; Chris@76: foreach ($boards[$rowmember['id_board']] as $key) Chris@76: { Chris@76: // Don't notify the guy who started the topic! Chris@76: //!!! In this case actually send them a "it's approved hooray" email Chris@76: if ($topicData[$key]['poster'] == $rowmember['id_member']) Chris@76: continue; Chris@76: Chris@76: // Setup the string for adding the body to the message, if a user wants it. Chris@76: $send_body = empty($modSettings['disallow_sendBody']) && !empty($rowmember['notify_send_body']); Chris@76: Chris@76: $replacements = array( Chris@76: 'TOPICSUBJECT' => $topicData[$key]['subject'], Chris@76: 'TOPICLINK' => $scripturl . '?topic=' . $topicData[$key]['topic'] . '.new#new', Chris@76: 'MESSAGE' => $topicData[$key]['body'], Chris@76: 'UNSUBSCRIBELINK' => $scripturl . '?action=notifyboard;board=' . $topicData[$key]['board'] . '.0', Chris@76: ); Chris@76: Chris@76: if (!$send_body) Chris@76: unset($replacements['MESSAGE']); Chris@76: Chris@76: // Figure out which email to send off Chris@76: $emailtype = ''; Chris@76: Chris@76: // Send only if once is off or it's on and it hasn't been sent. Chris@76: if (!empty($rowmember['notify_regularity']) && !$sentOnceAlready && empty($rowmember['sent'])) Chris@76: $emailtype = 'notify_boards_once'; Chris@76: elseif (empty($rowmember['notify_regularity'])) Chris@76: $emailtype = 'notify_boards'; Chris@76: Chris@76: if (!empty($emailtype)) Chris@76: { Chris@76: $emailtype .= $send_body ? '_body' : ''; Chris@76: $emaildata = loadEmailTemplate($emailtype, $replacements, $langloaded); Chris@76: sendmail($rowmember['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 3); Chris@76: } Chris@76: Chris@76: $sentOnceAlready = 1; Chris@76: } Chris@76: } Chris@76: $smcFunc['db_free_result']($members); Chris@76: Chris@76: // Sent! Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}log_notify Chris@76: SET sent = {int:is_sent} Chris@76: WHERE id_board IN ({array_int:board_list}) Chris@76: AND id_member != {int:current_member}', Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: 'board_list' => $board_index, Chris@76: 'is_sent' => 1, Chris@76: ) Chris@76: ); Chris@76: } Chris@76: Chris@76: // Get the topic for display purposes. Chris@76: function getTopic() Chris@76: { Chris@76: global $topic, $modSettings, $context, $smcFunc, $counter, $options; Chris@76: Chris@76: if (isset($_REQUEST['xml'])) Chris@76: $limit = ' Chris@76: LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']); Chris@76: else Chris@76: $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' Chris@76: LIMIT ' . (int) $modSettings['topicSummaryPosts']; Chris@76: Chris@76: // If you're modifying, get only those posts before the current one. (otherwise get all.) Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT Chris@76: IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, Chris@76: m.body, m.smileys_enabled, m.id_msg, m.id_member Chris@76: FROM {db_prefix}messages AS m Chris@76: LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) Chris@76: WHERE m.id_topic = {int:current_topic}' . (isset($_REQUEST['msg']) ? ' Chris@76: AND m.id_msg < {int:id_msg}' : '') .(!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' Chris@76: AND m.approved = {int:approved}') . ' Chris@76: ORDER BY m.id_msg DESC' . $limit, Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: 'id_msg' => isset($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0, Chris@76: 'approved' => 1, Chris@76: ) Chris@76: ); Chris@76: $context['previous_posts'] = array(); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: // Censor, BBC, ... Chris@76: censorText($row['body']); Chris@76: $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); Chris@76: Chris@76: // ...and store. Chris@76: $context['previous_posts'][] = array( Chris@76: 'counter' => $counter++, Chris@76: 'alternate' => $counter % 2, Chris@76: 'poster' => $row['poster_name'], Chris@76: 'message' => $row['body'], Chris@76: 'time' => timeformat($row['poster_time']), Chris@76: 'timestamp' => forum_time(true, $row['poster_time']), Chris@76: 'id' => $row['id_msg'], Chris@76: 'is_new' => !empty($context['new_replies']), Chris@76: 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']), Chris@76: ); Chris@76: Chris@76: if (!empty($context['new_replies'])) Chris@76: $context['new_replies']--; Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: } Chris@76: Chris@76: function QuoteFast() Chris@76: { Chris@76: global $modSettings, $user_info, $txt, $settings, $context; Chris@76: global $sourcedir, $smcFunc; Chris@76: Chris@76: loadLanguage('Post'); Chris@76: if (!isset($_REQUEST['xml'])) Chris@76: loadTemplate('Post'); Chris@76: Chris@76: include_once($sourcedir . '/Subs-Post.php'); Chris@76: Chris@76: $moderate_boards = boardsAllowedTo('moderate_board'); Chris@76: Chris@76: // Where we going if we need to? Chris@76: $context['post_box_name'] = isset($_GET['pb']) ? $_GET['pb'] : ''; Chris@76: Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body, m.id_topic, m.subject, Chris@76: m.id_board, m.id_member, m.approved Chris@76: FROM {db_prefix}messages AS m Chris@76: INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) Chris@76: INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) Chris@76: LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) Chris@76: WHERE m.id_msg = {int:id_msg}' . (isset($_REQUEST['modify']) || (!empty($moderate_boards) && $moderate_boards[0] == 0) ? '' : ' Chris@76: AND (t.locked = {int:not_locked}' . (empty($moderate_boards) ? '' : ' OR b.id_board IN ({array_int:moderation_board_list})') . ')') . ' Chris@76: LIMIT 1', Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: 'moderation_board_list' => $moderate_boards, Chris@76: 'id_msg' => (int) $_REQUEST['quote'], Chris@76: 'not_locked' => 0, Chris@76: ) Chris@76: ); Chris@76: $context['close_window'] = $smcFunc['db_num_rows']($request) == 0; Chris@76: $row = $smcFunc['db_fetch_assoc']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: $context['sub_template'] = 'quotefast'; Chris@76: if (!empty($row)) Chris@76: $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); Chris@76: Chris@76: if (!empty($can_view_post)) Chris@76: { Chris@76: // Remove special formatting we don't want anymore. Chris@76: $row['body'] = un_preparsecode($row['body']); Chris@76: Chris@76: // Censor the message! Chris@76: censorText($row['body']); Chris@76: Chris@76: $row['body'] = preg_replace('~
~i', "\n", $row['body']); Chris@76: Chris@76: // Want to modify a single message by double clicking it? Chris@76: if (isset($_REQUEST['modify'])) Chris@76: { Chris@76: censorText($row['subject']); Chris@76: Chris@76: $context['sub_template'] = 'modifyfast'; Chris@76: $context['message'] = array( Chris@76: 'id' => $_REQUEST['quote'], Chris@76: 'body' => $row['body'], Chris@76: 'subject' => addcslashes($row['subject'], '"'), Chris@76: ); Chris@76: Chris@76: return; Chris@76: } Chris@76: Chris@76: // Remove any nested quotes. Chris@76: if (!empty($modSettings['removeNestedQuotes'])) Chris@76: $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); Chris@76: Chris@76: // Make the body HTML if need be. Chris@76: if (!empty($_REQUEST['mode'])) Chris@76: { Chris@76: require_once($sourcedir . '/Subs-Editor.php'); Chris@76: $row['body'] = strtr($row['body'], array('<' => '#smlt#', '>' => '#smgt#', '&' => '#smamp#')); Chris@76: $row['body'] = bbc_to_html($row['body']); Chris@76: $lb = '
'; Chris@76: } Chris@76: else Chris@76: $lb = "\n"; Chris@76: Chris@76: // Add a quote string on the front and end. Chris@76: $context['quote']['xml'] = '[quote author=' . $row['poster_name'] . ' link=topic=' . $row['id_topic'] . '.msg' . (int) $_REQUEST['quote'] . '#msg' . (int) $_REQUEST['quote'] . ' date=' . $row['poster_time'] . ']' . $lb . $row['body'] . $lb . '[/quote]'; Chris@76: $context['quote']['text'] = strtr(un_htmlspecialchars($context['quote']['xml']), array('\'' => '\\\'', '\\' => '\\\\', "\n" => '\\n', '' => '')); Chris@76: $context['quote']['xml'] = strtr($context['quote']['xml'], array(' ' => ' ', '<' => '<', '>' => '>')); Chris@76: Chris@76: $context['quote']['mozilla'] = strtr($smcFunc['htmlspecialchars']($context['quote']['text']), array('"' => '"')); Chris@76: } Chris@76: // !!! Needs a nicer interface. Chris@76: // In case our message has been removed in the meantime. Chris@76: elseif (isset($_REQUEST['modify'])) Chris@76: { Chris@76: $context['sub_template'] = 'modifyfast'; Chris@76: $context['message'] = array( Chris@76: 'id' => 0, Chris@76: 'body' => '', Chris@76: 'subject' => '', Chris@76: ); Chris@76: } Chris@76: else Chris@76: $context['quote'] = array( Chris@76: 'xml' => '', Chris@76: 'mozilla' => '', Chris@76: 'text' => '', Chris@76: ); Chris@76: } Chris@76: Chris@76: function JavaScriptModify() Chris@76: { Chris@76: global $sourcedir, $modSettings, $board, $topic, $txt; Chris@76: global $user_info, $context, $smcFunc, $language; Chris@76: Chris@76: // We have to have a topic! Chris@76: if (empty($topic)) Chris@76: obExit(false); Chris@76: Chris@76: checkSession('get'); Chris@76: require_once($sourcedir . '/Subs-Post.php'); Chris@76: Chris@76: // Assume the first message if no message ID was given. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT Chris@76: t.locked, t.num_replies, t.id_member_started, t.id_first_msg, Chris@76: m.id_msg, m.id_member, m.poster_time, m.subject, m.smileys_enabled, m.body, m.icon, Chris@76: m.modified_time, m.modified_name, m.approved Chris@76: FROM {db_prefix}messages AS m Chris@76: INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic}) Chris@76: WHERE m.id_msg = {raw:id_msg} Chris@76: AND m.id_topic = {int:current_topic}' . (allowedTo('approve_posts') ? '' : (!$modSettings['postmod_active'] ? ' Chris@76: AND (m.id_member != {int:guest_id} AND m.id_member = {int:current_member})' : ' Chris@76: AND (m.approved = {int:is_approved} OR (m.id_member != {int:guest_id} AND m.id_member = {int:current_member}))')), Chris@76: array( Chris@76: 'current_member' => $user_info['id'], Chris@76: 'current_topic' => $topic, Chris@76: 'id_msg' => empty($_REQUEST['msg']) ? 't.id_first_msg' : (int) $_REQUEST['msg'], Chris@76: 'is_approved' => 1, Chris@76: 'guest_id' => 0, Chris@76: ) Chris@76: ); Chris@76: if ($smcFunc['db_num_rows']($request) == 0) Chris@76: fatal_lang_error('no_board', false); Chris@76: $row = $smcFunc['db_fetch_assoc']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Change either body or subject requires permissions to modify messages. Chris@76: if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon'])) Chris@76: { Chris@76: if (!empty($row['locked'])) Chris@76: isAllowedTo('moderate_board'); Chris@76: Chris@76: if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) Chris@76: { Chris@76: if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) Chris@76: fatal_lang_error('modify_post_time_passed', false); Chris@76: elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) Chris@76: isAllowedTo('modify_replies'); Chris@76: else Chris@76: isAllowedTo('modify_own'); Chris@76: } Chris@76: // Otherwise, they're locked out; someone who can modify the replies is needed. Chris@76: elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) Chris@76: isAllowedTo('modify_replies'); Chris@76: else Chris@76: isAllowedTo('modify_any'); Chris@76: Chris@76: // Only log this action if it wasn't your message. Chris@76: $moderationAction = $row['id_member'] != $user_info['id']; Chris@76: } Chris@76: Chris@76: $post_errors = array(); Chris@76: if (isset($_POST['subject']) && $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) !== '') Chris@76: { Chris@76: $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => '')); Chris@76: Chris@76: // Maximum number of characters. Chris@76: if ($smcFunc['strlen']($_POST['subject']) > 100) Chris@76: $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); Chris@76: } Chris@76: elseif (isset($_POST['subject'])) Chris@76: { Chris@76: $post_errors[] = 'no_subject'; Chris@76: unset($_POST['subject']); Chris@76: } Chris@76: Chris@76: if (isset($_POST['message'])) Chris@76: { Chris@76: if ($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message'])) === '') Chris@76: { Chris@76: $post_errors[] = 'no_message'; Chris@76: unset($_POST['message']); Chris@76: } Chris@76: elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) Chris@76: { Chris@76: $post_errors[] = 'long_message'; Chris@76: unset($_POST['message']); Chris@76: } Chris@76: else Chris@76: { Chris@76: $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); Chris@76: Chris@76: preparsecode($_POST['message']); Chris@76: Chris@76: if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), '')) === '') Chris@76: { Chris@76: $post_errors[] = 'no_message'; Chris@76: unset($_POST['message']); Chris@76: } Chris@76: } Chris@76: } Chris@76: Chris@76: if (isset($_POST['lock'])) Chris@76: { Chris@76: if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) Chris@76: unset($_POST['lock']); Chris@76: elseif (!allowedTo('lock_any')) Chris@76: { Chris@76: if ($row['locked'] == 1) Chris@76: unset($_POST['lock']); Chris@76: else Chris@76: $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; Chris@76: } Chris@76: elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) Chris@76: unset($_POST['lock']); Chris@76: else Chris@76: $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; Chris@76: } Chris@76: Chris@76: if (isset($_POST['sticky']) && !allowedTo('make_sticky')) Chris@76: unset($_POST['sticky']); Chris@76: Chris@76: if (empty($post_errors)) Chris@76: { Chris@76: $msgOptions = array( Chris@76: 'id' => $row['id_msg'], Chris@76: 'subject' => isset($_POST['subject']) ? $_POST['subject'] : null, Chris@76: 'body' => isset($_POST['message']) ? $_POST['message'] : null, Chris@76: 'icon' => isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : null, Chris@76: ); Chris@76: $topicOptions = array( Chris@76: 'id' => $topic, Chris@76: 'board' => $board, Chris@76: 'lock_mode' => isset($_POST['lock']) ? (int) $_POST['lock'] : null, Chris@76: 'sticky_mode' => isset($_POST['sticky']) && !empty($modSettings['enableStickyTopics']) ? (int) $_POST['sticky'] : null, Chris@76: 'mark_as_read' => true, Chris@76: ); Chris@76: $posterOptions = array(); Chris@76: Chris@76: // Only consider marking as editing if they have edited the subject, message or icon. Chris@76: if ((isset($_POST['subject']) && $_POST['subject'] != $row['subject']) || (isset($_POST['message']) && $_POST['message'] != $row['body']) || (isset($_REQUEST['icon']) && $_REQUEST['icon'] != $row['icon'])) Chris@76: { Chris@76: // And even then only if the time has passed... Chris@76: if (time() - $row['poster_time'] > $modSettings['edit_wait_time'] || $user_info['id'] != $row['id_member']) Chris@76: { Chris@76: $msgOptions['modify_time'] = time(); Chris@76: $msgOptions['modify_name'] = $user_info['name']; Chris@76: } Chris@76: } Chris@76: // If nothing was changed there's no need to add an entry to the moderation log. Chris@76: else Chris@76: $moderationAction = false; Chris@76: Chris@76: modifyPost($msgOptions, $topicOptions, $posterOptions); Chris@76: Chris@76: // If we didn't change anything this time but had before put back the old info. Chris@76: if (!isset($msgOptions['modify_time']) && !empty($row['modified_time'])) Chris@76: { Chris@76: $msgOptions['modify_time'] = $row['modified_time']; Chris@76: $msgOptions['modify_name'] = $row['modified_name']; Chris@76: } Chris@76: Chris@76: // Changing the first subject updates other subjects to 'Re: new_subject'. Chris@76: if (isset($_POST['subject']) && isset($_REQUEST['change_all_subjects']) && $row['id_first_msg'] == $row['id_msg'] && !empty($row['num_replies']) && (allowedTo('modify_any') || ($row['id_member_started'] == $user_info['id'] && allowedTo('modify_replies')))) Chris@76: { Chris@76: // Get the proper (default language) response prefix first. Chris@76: if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) Chris@76: { Chris@76: if ($language === $user_info['language']) Chris@76: $context['response_prefix'] = $txt['response_prefix']; Chris@76: else Chris@76: { Chris@76: loadLanguage('index', $language, false); Chris@76: $context['response_prefix'] = $txt['response_prefix']; Chris@76: loadLanguage('index'); Chris@76: } Chris@76: cache_put_data('response_prefix', $context['response_prefix'], 600); Chris@76: } Chris@76: Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}messages Chris@76: SET subject = {string:subject} Chris@76: WHERE id_topic = {int:current_topic} Chris@76: AND id_msg != {int:id_first_msg}', Chris@76: array( Chris@76: 'current_topic' => $topic, Chris@76: 'id_first_msg' => $row['id_first_msg'], Chris@76: 'subject' => $context['response_prefix'] . $_POST['subject'], Chris@76: ) Chris@76: ); Chris@76: } Chris@76: Chris@76: if (!empty($moderationAction)) Chris@76: logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); Chris@76: } Chris@76: Chris@76: if (isset($_REQUEST['xml'])) Chris@76: { Chris@76: $context['sub_template'] = 'modifydone'; Chris@76: if (empty($post_errors) && isset($msgOptions['subject']) && isset($msgOptions['body'])) Chris@76: { Chris@76: $context['message'] = array( Chris@76: 'id' => $row['id_msg'], Chris@76: 'modified' => array( Chris@76: 'time' => isset($msgOptions['modify_time']) ? timeformat($msgOptions['modify_time']) : '', Chris@76: 'timestamp' => isset($msgOptions['modify_time']) ? forum_time(true, $msgOptions['modify_time']) : 0, Chris@76: 'name' => isset($msgOptions['modify_time']) ? $msgOptions['modify_name'] : '', Chris@76: ), Chris@76: 'subject' => $msgOptions['subject'], Chris@76: 'first_in_topic' => $row['id_msg'] == $row['id_first_msg'], Chris@76: 'body' => strtr($msgOptions['body'], array(']]>' => ']]]]>')), Chris@76: ); Chris@76: Chris@76: censorText($context['message']['subject']); Chris@76: censorText($context['message']['body']); Chris@76: Chris@76: $context['message']['body'] = parse_bbc($context['message']['body'], $row['smileys_enabled'], $row['id_msg']); Chris@76: } Chris@76: // Topic? Chris@76: elseif (empty($post_errors)) Chris@76: { Chris@76: $context['sub_template'] = 'modifytopicdone'; Chris@76: $context['message'] = array( Chris@76: 'id' => $row['id_msg'], Chris@76: 'modified' => array( Chris@76: 'time' => isset($msgOptions['modify_time']) ? timeformat($msgOptions['modify_time']) : '', Chris@76: 'timestamp' => isset($msgOptions['modify_time']) ? forum_time(true, $msgOptions['modify_time']) : 0, Chris@76: 'name' => isset($msgOptions['modify_time']) ? $msgOptions['modify_name'] : '', Chris@76: ), Chris@76: 'subject' => isset($msgOptions['subject']) ? $msgOptions['subject'] : '', Chris@76: ); Chris@76: Chris@76: censorText($context['message']['subject']); Chris@76: } Chris@76: else Chris@76: { Chris@76: $context['message'] = array( Chris@76: 'id' => $row['id_msg'], Chris@76: 'errors' => array(), Chris@76: 'error_in_subject' => in_array('no_subject', $post_errors), Chris@76: 'error_in_body' => in_array('no_message', $post_errors) || in_array('long_message', $post_errors), Chris@76: ); Chris@76: Chris@76: loadLanguage('Errors'); Chris@76: foreach ($post_errors as $post_error) Chris@76: { Chris@76: if ($post_error == 'long_message') Chris@76: $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); Chris@76: else Chris@76: $context['message']['errors'][] = $txt['error_' . $post_error]; Chris@76: } Chris@76: } Chris@76: } Chris@76: else Chris@76: obExit(false); Chris@76: } Chris@76: Chris@76: ?>