Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post #425

Merged
merged 18 commits into from May 20, 2013
Merged

Post #425

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions sources/controllers/Calendar.controller.php
Expand Up @@ -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']);
}
Expand Down
223 changes: 67 additions & 156 deletions sources/controllers/Post.controller.php
Expand Up @@ -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']))
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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']))
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.)
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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);
}
65 changes: 65 additions & 0 deletions sources/subs/Poll.subs.php
Expand Up @@ -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')
);
}