diff --git a/sources/controllers/Calendar.controller.php b/sources/controllers/Calendar.controller.php index b015d9808f..aa02ec1be6 100644 --- a/sources/controllers/Calendar.controller.php +++ b/sources/controllers/Calendar.controller.php @@ -252,10 +252,6 @@ function action_event_post() modifyEvent($_REQUEST['eventid'], $eventOptions); } - updateSettings(array( - 'calendar_updated' => time(), - )); - // No point hanging around here now... redirectexit($scripturl . '?action=calendar;month=' . $_POST['month'] . ';year=' . $_POST['year']); } diff --git a/sources/controllers/Post.controller.php b/sources/controllers/Post.controller.php index 8c497c4253..2dec6abd90 100644 --- a/sources/controllers/Post.controller.php +++ b/sources/controllers/Post.controller.php @@ -771,7 +771,27 @@ function action_post() // Update the topic summary, needed to show new posts in a preview if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) - getTopic(); + { + require_once(SUBSDIR . '/Topic.subs.php'); + $only_approved = $modSettings['postmod_active'] && !allowedTo('approve_posts'); + if (isset($_REQUEST['xml'])) + $limit = empty($context['new_replies']) ? 0 : (int) $context['new_replies']; + else + $limit = empty($modSettings['topicSummaryPosts']) ? 0 : (int) $modSettings['topicSummaryPosts']; + $before = isset($_REQUEST['msg']) ? array('before' => (int) $_REQUEST['msg']) : array(); + + $counter = 0; + $context['previous_posts'] = selectMessages($topic, 0, $limit, $before, $only_approved); + foreach ($context['previous_posts'] as &$post) + { + $post['is_new'] = !empty($context['new_replies']); + $post['counter'] = $counter++; + $post['is_ignored'] = !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($post['id_poster'], $user_info['ignoreusers']); + + if (!empty($context['new_replies'])) + $context['new_replies']--; + } + } // Just ajax previewing then lets stop now if (isset($_REQUEST['xml'])) @@ -910,7 +930,7 @@ function action_post() */ function action_post2() { - global $board, $topic, $txt, $modSettings, $context; + global $board, $topic, $txt, $modSettings, $context, $user_settings; global $user_info, $board_info, $options, $smcFunc, $scripturl, $settings; // Sneaking off, are we? @@ -1214,7 +1234,7 @@ function action_post2() } } - // Incase we want to override + // In case we want to override if (allowedTo('approve_posts')) { $becomesApproved = !isset($_REQUEST['approve']) || !empty($_REQUEST['approve']) ? 1 : 0; @@ -1410,7 +1430,23 @@ function action_post2() $_POST['question'] = $smcFunc['truncate']($_POST['question'], 255); $_POST['question'] = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $_POST['question']); $_POST['options'] = htmlspecialchars__recursive($_POST['options']); + + // Finally, make the poll. + require_once(SUBSDIR . '/Poll.subs.php'); + $id_poll = createPoll( + $_POST['question'], + $user_info['id'], + $_POST['guestname'], + $_POST['poll_max_votes'], + $_POST['poll_hide'], + $_POST['poll_expire'], + $_POST['poll_change_vote'], + $_POST['poll_guest_vote'], + $_POST['options'] + ); } + else + $id_poll = 0; // ...or attach a new file... if (empty($ignore_temp) && $context['can_post_attachment'] && !empty($_SESSION['temp_attachments']) && empty($_POST['from_qr'])) @@ -1484,45 +1520,6 @@ function action_post2() unset($_SESSION['temp_attachments']); } - // Make the poll... - if (isset($_REQUEST['poll'])) - { - // Create the poll. - $smcFunc['db_insert']('', - '{db_prefix}polls', - array( - 'question' => 'string-255', 'hide_results' => 'int', 'max_votes' => 'int', 'expire_time' => 'int', 'id_member' => 'int', - 'poster_name' => 'string-255', 'change_vote' => 'int', 'guest_vote' => 'int' - ), - array( - $_POST['question'], $_POST['poll_hide'], $_POST['poll_max_votes'], (empty($_POST['poll_expire']) ? 0 : time() + $_POST['poll_expire'] * 3600 * 24), $user_info['id'], - $_POST['guestname'], $_POST['poll_change_vote'], $_POST['poll_guest_vote'], - ), - array('id_poll') - ); - $id_poll = $smcFunc['db_insert_id']('{db_prefix}polls', 'id_poll'); - - // Create each answer choice. - $i = 0; - $pollOptions = array(); - foreach ($_POST['options'] as $option) - { - $pollOptions[] = array($id_poll, $i, $option); - $i++; - } - - $smcFunc['db_insert']('insert', - '{db_prefix}poll_choices', - array('id_poll' => 'int', 'id_choice' => 'int', 'label' => 'string-255'), - $pollOptions, - array('id_poll', 'id_choice') - ); - - call_integration_hook('integrate_poll_add_edit', array($id_poll, false)); - } - else - $id_poll = 0; - // Creating a new topic? $newTopic = empty($_REQUEST['msg']) && empty($topic); @@ -1643,53 +1640,45 @@ function action_post2() // Delete it? if (isset($_REQUEST['deleteevent'])) - $smcFunc['db_query']('', ' - DELETE FROM {db_prefix}calendar - WHERE id_event = {int:id_event}', - array( - 'id_event' => $_REQUEST['eventid'], - ) - ); + removeEvent($_REQUEST['eventid']); // ... or just update it? else { $span = !empty($modSettings['cal_allowspan']) && !empty($_REQUEST['span']) ? min((int) $modSettings['cal_maxspan'], (int) $_REQUEST['span'] - 1) : 0; $start_time = mktime(0, 0, 0, (int) $_REQUEST['month'], (int) $_REQUEST['day'], (int) $_REQUEST['year']); - $smcFunc['db_query']('', ' - UPDATE {db_prefix}calendar - SET end_date = {date:end_date}, - start_date = {date:start_date}, - title = {string:title} - WHERE id_event = {int:id_event}', - array( - 'end_date' => strftime('%Y-%m-%d', $start_time + $span * 86400), - 'start_date' => strftime('%Y-%m-%d', $start_time), - 'id_event' => $_REQUEST['eventid'], - 'title' => $smcFunc['htmlspecialchars']($_REQUEST['evtitle'], ENT_QUOTES), - ) - ); + modifyEvent($_REQUEST['eventid'], array( + 'start_date' => strftime('%Y-%m-%d', $start_time), + 'end_date' => strftime('%Y-%m-%d', $start_time + $span * 86400), + 'title' => $_REQUEST['evtitle'], + )); } - updateSettings(array( - 'calendar_updated' => time(), - )); } // Marking read should be done even for editing messages.... // Mark all the parents read. (since you just posted and they will be unread.) - if (!$user_info['is_guest'] && !empty($board_info['parent_boards'])) + if (!$user_info['is_guest']) { - $smcFunc['db_query']('', ' - UPDATE {db_prefix}log_boards - SET id_msg = {int:id_msg} - WHERE id_member = {int:current_member} - AND id_board IN ({array_int:board_list})', - array( - 'current_member' => $user_info['id'], - 'board_list' => array_keys($board_info['parent_boards']), - 'id_msg' => $modSettings['maxMsgID'], - ) - ); + $board_list = !empty($board_info['parent_boards']) ? array_keys($board_info['parent_boards']) : array(); + + // Returning to the topic? + if (!empty($_REQUEST['goback'])) + $board_list[] = $board; + + if (!empty($board_list)) + { + $smcFunc['db_query']('', ' + UPDATE {db_prefix}log_boards + SET id_msg = {int:id_msg} + WHERE id_member = {int:current_member} + AND id_board IN ({array_int:board_list})', + array( + 'current_member' => $user_info['id'], + 'board_list' => $board_list, + 'id_msg' => $modSettings['maxMsgID'], + ) + ); + } } // Turn notification on or off. (note this just blows smoke if it's already on or off.) @@ -1750,23 +1739,6 @@ function action_post2() } } - // Returning to the topic? - if (!empty($_REQUEST['goback'])) - { - // Mark the board as read.... because it might get confusing otherwise. - $smcFunc['db_query']('', ' - UPDATE {db_prefix}log_boards - SET id_msg = {int:maxMsgID} - WHERE id_member = {int:current_member} - AND id_board = {int:current_board}', - array( - 'current_board' => $board, - 'current_member' => $user_info['id'], - 'maxMsgID' => $modSettings['maxMsgID'], - ) - ); - } - if ($board_info['num_topics'] == 0) cache_put_data('board-' . $board, null, 120); @@ -1835,7 +1807,7 @@ function action_quotefast() loadJavascriptFile('post.js', array(), 'post_scripts'); } - include_once(SUBSDIR . '/Post.subs.php'); + require_once(SUBSDIR . '/Post.subs.php'); $moderate_boards = boardsAllowedTo('moderate_board'); @@ -2270,64 +2242,3 @@ function action_spellcheck() $context['sub_template'] = 'spellcheck'; } } - -/** - * Get the topic for display purposes. - * - * gets a summary of the most recent posts in a topic. - * depends on the topicSummaryPosts setting. - * if you are editing a post, only shows posts previous to that post. - */ -function getTopic() -{ - global $topic, $modSettings, $context, $smcFunc, $counter, $options; - - if (isset($_REQUEST['xml'])) - $limit = ' - LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']); - else - $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' - LIMIT ' . (int) $modSettings['topicSummaryPosts']; - - // If you're modifying, get only those posts before the current one. (otherwise get all.) - $request = $smcFunc['db_query']('', ' - SELECT - IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, - m.body, m.smileys_enabled, m.id_msg, m.id_member - FROM {db_prefix}messages AS m - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) - WHERE m.id_topic = {int:current_topic}' . (isset($_REQUEST['msg']) ? ' - AND m.id_msg < {int:id_msg}' : '') .(!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' - AND m.approved = {int:approved}') . ' - ORDER BY m.id_msg DESC' . $limit, - array( - 'current_topic' => $topic, - 'id_msg' => isset($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0, - 'approved' => 1, - ) - ); - $context['previous_posts'] = array(); - while ($row = $smcFunc['db_fetch_assoc']($request)) - { - // Censor, BBC, ... - censorText($row['body']); - $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); - - // ...and store. - $context['previous_posts'][] = array( - 'counter' => $counter++, - 'alternate' => $counter % 2, - 'poster' => $row['poster_name'], - 'message' => $row['body'], - 'time' => standardTime($row['poster_time']), - 'timestamp' => forum_time(true, $row['poster_time']), - 'id' => $row['id_msg'], - 'is_new' => !empty($context['new_replies']), - 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']), - ); - - if (!empty($context['new_replies'])) - $context['new_replies']--; - } - $smcFunc['db_free_result']($request); -} diff --git a/sources/subs/Poll.subs.php b/sources/subs/Poll.subs.php index b8bdebeb06..3145c0fb8d 100644 --- a/sources/subs/Poll.subs.php +++ b/sources/subs/Poll.subs.php @@ -164,4 +164,69 @@ function getPollInfo($topicID) $smcFunc['db_free_result']($request); return $pollinfo; +} + +/** + * Create a poll + * + * @param string $question The title/question of the poll + * @param int $id_member = false The id of the creator + * @param string $poster_name The name of the poll creator + * @param int $max_votes = 1 The maximum number of votes you can do + * @param bool $hide_results = true If the results should be hidden + * @param int $expire = 0 The time in days that this poll will expire + * @param bool $can_change_vote = false If you can change your vote + * @param bool $can_guest_vote = false If guests can vote + * @param array $options = array() The poll options + * @return int the id of the created poll + */ +function createPoll($question, $id_member, $poster_name, $max_votes = 1, $hide_results = true, $expire = 0, $can_change_vote = false, $can_guest_vote = false, array $options = array()) +{ + $expire = empty($expire) ? 0 : time() + $expire * 3600 * 24; + + $db = database(); + $db->insert('', + '{db_prefix}polls', + array( + 'question' => 'string-255', 'hide_results' => 'int', 'max_votes' => 'int', 'expire_time' => 'int', 'id_member' => 'int', + 'poster_name' => 'string-255', 'change_vote' => 'int', 'guest_vote' => 'int' + ), + array( + $question, $hide_results, $max_votes, $expire, $id_member, + $poster_name, $can_change_vote, $can_guest_vote, + ), + array('id_poll') + ); + + $id_poll = $db->insert_id('{db_prefix}polls', 'id_poll'); + + if (!empty($options)) + addPollOptions($id_poll, $options); + + call_integration_hook('integrate_poll_add_edit', array($id_poll, false)); + + return $id_poll; +} + +/** + * Add options to an already created poll + * + * @param int $id_poll The id of the poll you're adding the options to + * @param array $options The options to choose from + */ +function addPollOptions($id_poll, array $options) +{ + $pollOptions = array(); + foreach ($options as $i => $option) + { + $pollOptions[] = array($id_poll, $i, $option); + } + + $db = database(); + $db->insert('insert', + '{db_prefix}poll_choices', + array('id_poll' => 'int', 'id_choice' => 'int', 'label' => 'string-255'), + $pollOptions, + array('id_poll', 'id_choice') + ); } \ No newline at end of file diff --git a/sources/subs/Topic.subs.php b/sources/subs/Topic.subs.php index 4b08a5153d..a5ebbf14a2 100644 --- a/sources/subs/Topic.subs.php +++ b/sources/subs/Topic.subs.php @@ -1283,10 +1283,12 @@ function selectMessages($topic, $start, $per_page, $messages = array(), $only_ap // Get the messages and stick them into an array. $request = $smcFunc['db_query']('', ' - SELECT m.subject, IFNULL(mem.real_name, m.poster_name) AS real_name, m.poster_time, m.body, m.id_msg, m.smileys_enabled + SELECT m.subject, IFNULL(mem.real_name, m.poster_name) AS real_name, m.poster_time, m.body, m.id_msg, m.smileys_enabled, m.id_member FROM {db_prefix}messages AS m LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) - WHERE m.id_topic = {int:current_topic}' . (empty($messages['excluded']) ? '' : ' + WHERE m.id_topic = {int:current_topic}' . (empty($messages['before']) ? '' : ' + AND m.id_msg < {int:msg_before}') . (empty($messages['after']) ? '' : ' + AND m.id_msg > {int:msg_after}') . (empty($messages['excluded']) ? '' : ' AND m.id_msg NOT IN ({array_int:no_split_msgs})') . (empty($messages['included']) ? '' : ' AND m.id_msg IN ({array_int:split_msgs})') . (!$only_approved ? '' : ' AND approved = {int:is_approved}') . ' @@ -1299,6 +1301,8 @@ function selectMessages($topic, $start, $per_page, $messages = array(), $only_ap 'is_approved' => 1, 'start' => $start, 'messages_per_page' => $per_page, + 'msg_before' => !empty($messages['before']) ? (int) $messages['before'] : 0, + 'msg_after' => !empty($messages['after']) ? (int) $messages['after'] : 0, ) ); $messages = array(); @@ -1317,6 +1321,7 @@ function selectMessages($topic, $start, $per_page, $messages = array(), $only_ap 'timestamp' => forum_time(true, $row['poster_time']), 'body' => $row['body'], 'poster' => $row['real_name'], + 'id_poster' => $row['id_member'], ); } $smcFunc['db_free_result']($request); diff --git a/themes/default/Post.template.php b/themes/default/Post.template.php index 9d37752830..06881632ce 100644 --- a/themes/default/Post.template.php +++ b/themes/default/Post.template.php @@ -600,7 +600,7 @@ function template_main() } echo ' -
', $post['message'], '
+
', $post['body'], '
'; }