4 changes: 4 additions & 0 deletions sources/controllers/Calendar.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function action_calendar()

// This is gonna be needed...
loadTemplate('Calendar');
// If it doesn't have it's specific sub-template
$context['sub_template'] = 'calendar_main';

// You can't do anything if the calendar is off.
if (empty($modSettings['cal_enabled']))
Expand Down Expand Up @@ -263,6 +265,8 @@ function CalendarPost()
return action_post();
}

$context['make_event'] = true;
$context['is_new_post'] = true;
// New?
if (!isset($_REQUEST['eventid']))
{
Expand Down
23 changes: 22 additions & 1 deletion sources/controllers/Drafts.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function loadDraft($id_draft, $type = 0, $check = true, $load = false)
*/
function action_showDrafts($member_id, $topic = false, $draft_type = 0)
{
global $scripturl, $context, $txt, $modSettings;
global $scripturl, $context, $txt, $modSettings, $options;

$context['drafts'] = array();

Expand Down Expand Up @@ -335,6 +335,27 @@ function action_showDrafts($member_id, $topic = false, $draft_type = 0)
'link' => '<a href="' . $scripturl . '?action=pm;sa=send;id_draft=' . $draft['id_draft'] . '">' . (!empty($draft['subject']) ? $draft['subject'] : $txt['drafts_none']) . '</a>',
);
}

$context['post_below']['postDraftOptions'] = array(
'collapsible' => !empty($modSettings['drafts_enabled']) && !empty($context['drafts']) && !empty($options['drafts_show_saved_enabled']),
'collapsed' => true,
'title' => array(
'collapsed' => $txt['draft_load'],
'expanded' => $txt['draft_hide'],
),
'blocks' => array(
'postDraftOptions' => array(
'custom_template' => true,
'values' => array(
'drafts' => array(
'allowed_to' => !empty($modSettings['drafts_enabled']) && !empty($context['drafts']) && !empty($options['drafts_show_saved_enabled']),
'function' => 'template_show_drafts',
),
),
),
),
);

}

/**
Expand Down
209 changes: 181 additions & 28 deletions sources/controllers/Post.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ function action_post()
// Posting an event?
$context['make_event'] = isset($_REQUEST['calendar']);
$context['robot_no_index'] = true;
$context['post_above'] = array(
'top' => array(),
'callback' => array(),
);
$context['post_below'] = array(
'postAdditionalOptions' => array(),
);

// You must be posting to *some* board.
if (empty($board) && !$context['make_event'])
Expand Down Expand Up @@ -96,7 +103,7 @@ function action_post()
'current_topic' => $topic,
)
);
list ($locked, $context['notify'], $sticky, $pollID, $context['topic_last_message'], $id_member_poster, $id_first_msg, $first_subject, $lastPostTime) = $smcFunc['db_fetch_row']($request);
list ($locked, $notify, $sticky, $pollID, $context['topic_last_message'], $id_member_poster, $id_first_msg, $first_subject, $lastPostTime) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

// If this topic already has a poll, they sure can't add another.
Expand Down Expand Up @@ -129,9 +136,7 @@ function action_post()
$context['becomes_approved'] = true;

$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
$context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);

$context['notify'] = !empty($context['notify']);
$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;

// Check whether this is a really old post being bumped...
Expand All @@ -153,9 +158,7 @@ function action_post()

// @todo These won't work if you're making an event.
$context['can_lock'] = allowedTo(array('lock_any', 'lock_own'));
$context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);

$context['notify'] = !empty($context['notify']);
$context['sticky'] = !empty($_REQUEST['sticky']);
}

Expand All @@ -168,9 +171,12 @@ function action_post()
$context['can_announce'] = allowedTo('announce_topic') && $context['becomes_approved'];
$context['locked'] = !empty($locked) || !empty($_REQUEST['lock']);
$context['can_quote'] = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
// Moved out from the if/else block
$context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);

// Generally don't show the approval box... (Assume we want things approved)
$context['show_approval'] = allowedTo('approve_posts') && $context['becomes_approved'] ? 2 : (allowedTo('approve_posts') ? 1 : 0);
$context['back_to_topic'] = isset($_REQUEST['goback']) || (isset($_REQUEST['msg']) && !isset($_REQUEST['subject']));

// An array to hold all the attachments for this topic.
$context['current_attachments'] = array();
Expand Down Expand Up @@ -218,6 +224,13 @@ function action_post()

if ($context['make_event'])
{
loadTemplate('Calendar');
$context['post_above']['callback']['make_event'] = array(
'id' => 'event',
'value' => 'template_event_post',
'params' => array(true),
);

// They might want to pick a board.
if (!isset($context['current_board']))
$context['current_board'] = 0;
Expand All @@ -226,8 +239,8 @@ function action_post()
$context['event'] = array();
$context['event']['title'] = isset($_REQUEST['evtitle']) ? htmlspecialchars(stripslashes($_REQUEST['evtitle'])) : '';

$context['event']['id'] = isset($_REQUEST['eventid']) ? (int) $_REQUEST['eventid'] : -1;
$context['event']['new'] = $context['event']['id'] == -1;
$context['event']['eventid'] = isset($_REQUEST['eventid']) ? (int) $_REQUEST['eventid'] : -1;
$context['event']['new'] = $context['event']['eventid'] == -1;

// Permissions check!
isAllowedTo('calendar_post');
Expand All @@ -252,7 +265,7 @@ function action_post()
WHERE id_event = {int:id_event}
LIMIT 1',
array(
'id_event' => $context['event']['id'],
'id_event' => $context['event']['eventid'],
)
);
$row = $smcFunc['db_fetch_assoc']($request);
Expand Down Expand Up @@ -305,6 +318,7 @@ function action_post()
'selected_board' => empty($context['current_board']) ? $modSettings['cal_defaultboard'] : $context['current_board'],
);
$context += getBoardList($boardListOptions);
$context['boards_current_disabled'] = false;
}

// Find the last day of the month.
Expand Down Expand Up @@ -454,6 +468,23 @@ function action_post()
$context['email'] = $_REQUEST['email'];

$user_info['name'] = $_REQUEST['guestname'];
$context['post_above']['top']['caption_guestname'] = array(
'id' => 'name',
'post_name' => 'guestname',
'type' => 'text',
'value' => $context['name'],
'text' => $txt['name'],
'options' => ' size="25"',
);
if (empty($modSettings['guest_post_no_email']))
$context['post_above']['top']['caption_email'] = array(
'id' => 'email',
'post_name' => 'email',
'type' => 'text',
'value' => $context['email'],
'text' => $txt['email'],
'options' => ' size="25"',
);
}

// Only show the preview stuff if they hit Preview.
Expand Down Expand Up @@ -490,8 +521,8 @@ function action_post()
}

// Set up the checkboxes.
$context['notify'] = !empty($_REQUEST['notify']);
$context['use_smileys'] = !isset($_REQUEST['ns']);
$notify = !empty($_REQUEST['notify']);
$context['use_smileys'] = empty($_REQUEST['ns']);

$context['icon'] = isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : 'xx';

Expand Down Expand Up @@ -644,16 +675,6 @@ function action_post()
}
}

// Are we moving a discussion to its own topic?
if (!empty($_REQUEST['followup']))
{
$context['original_post'] = isset($_REQUEST['quote']) ? (int) $_REQUEST['quote'] : (int) $_REQUEST['followup'];
$context['show_boards_dropdown'] = true;
require_once(SUBSDIR . '/MessageIndex.subs.php');
$context += getBoardList(array('use_permissions' => true, 'not_redirection' => true, 'allowed_to' => 'post_new'));
$context['boards_current_disabled'] = false;
}

$context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
if ($context['can_post_attachment'])
{
Expand Down Expand Up @@ -833,7 +854,7 @@ function action_post()
if (isset($_REQUEST['poll']))
$context['page_title'] = $txt['new_poll'];
elseif ($context['make_event'])
$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
$context['page_title'] = $context['event']['eventid'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
elseif (isset($_REQUEST['msg']))
$context['page_title'] = $txt['modify_msg'];
elseif (isset($_REQUEST['subject'], $context['preview_subject']))
Expand Down Expand Up @@ -864,7 +885,20 @@ function action_post()
'extra_after' => '<span><strong class="nav"> )</strong></span>'
);

$context['is_new_topic'] = empty($topic);
$context['is_new_post'] = !isset($_REQUEST['msg']);
$context['is_first_post'] = $context['is_new_topic'] || (isset($_REQUEST['msg']) && $_REQUEST['msg'] == $id_first_msg);

$context['subject'] = addcslashes($form_subject, '"');
$context['post_above']['top']['caption_subject'] = array(
'id' => 'subject',
'post_name' => 'subject',
'type' => 'text',
'value' => $context['subject'],
'text' => $txt['subject'],
'options' => ' size="80" maxlength="80"',
);

$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);

// Are post drafts enabled?
Expand Down Expand Up @@ -904,10 +938,25 @@ function action_post()
$context['attached'] = '';
$context['make_poll'] = isset($_REQUEST['poll']);
if ($context['make_poll'])
{
loadTemplate('Poll');
$context['post_above']['callback']['make_poll'] = array(
'id' => 'poll',
'value' => 'template_poll_edit',
'params' => array(true),
);
}

// Message icons - customized or not, retrieve them...
$context['icons'] = getMessageIcons($board);
$context['post_above']['top']['icon'] = array(
'id' => 'icon',
'post_name' => 'icon',
'type' => 'select',
'value' => $context['icons'],
'text' => $txt['message_icon'],
'options' => ' onchange="showimage()"',
);

$context['icon_url'] = '';

Expand All @@ -917,6 +966,24 @@ function action_post()
$context['icons'][0]['selected'] = true;
$context['icon'] = $context['icons'][0]['value'];
$context['icon_url'] = $context['icons'][0]['url'];
$context['post_above']['top']['icon']['after_control'] = '<img src="' . $context['icon_url'] . '" name="icons" alt="" />';
}

// Are we moving a discussion to its own topic?
if (!empty($_REQUEST['followup']))
{
$context['original_post'] = isset($_REQUEST['quote']) ? (int) $_REQUEST['quote'] : (int) $_REQUEST['followup'];
$context['show_boards_dropdown'] = true;
require_once(SUBSDIR . '/MessageIndex.subs.php');
$context += getBoardList(array('use_permissions' => true, 'not_redirection' => true, 'allowed_to' => 'post_new'));
$context['boards_current_disabled'] = false;
$context['post_above']['top']['boards'] = array(
'id' => 'boards',
'text' => $txt['post_in_board'],
'type' => 'callback',
'value' => 'template_select_boards',
'params' => array('post_in_board'),
);
}

// Are we starting a poll? if set the poll icon as selected if its available
Expand Down Expand Up @@ -955,16 +1022,102 @@ function action_post()
}
}

$context['back_to_topic'] = isset($_REQUEST['goback']) || (isset($_REQUEST['msg']) && !isset($_REQUEST['subject']));
$context['show_additional_options'] = !empty($_POST['additional_options']) || isset($_SESSION['temp_attachments']['post']) || isset($_GET['additionalOptions']);

$context['is_new_topic'] = empty($topic);
$context['is_new_post'] = !isset($_REQUEST['msg']);
$context['is_first_post'] = $context['is_new_topic'] || (isset($_REQUEST['msg']) && $_REQUEST['msg'] == $id_first_msg);

// WYSIWYG only works if BBC is enabled
$modSettings['disable_wysiwyg'] = !empty($modSettings['disable_wysiwyg']) || empty($modSettings['enableBBC']);

$context['post_below']['postAdditionalOptions'] = array(
'collapsible' => !empty($settings['additional_options_collapsable']),
'collapsed' => !isset($_SESSION['temp_attachments']['post']) && !isset($_GET['additionalOptions']),
'title' => array(
'collapsed' => $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'],
'expanded' => $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'],
),
'blocks' => array(
'postMoreOptions' => array(
'values' => array(
'notify' => array(
'allowed_to' => allowedTo('mark_any_notify'),
'type' => 'check',
'text' => $txt['notify_replies'],
'selected' => !empty($notify) || !empty($options['auto_notify']),
),
'lock' => array(
'allowed_to' => allowedTo('lock_any') || ((empty($id_member_poster) || $user_info['id'] == $id_member_poster) && allowedTo('lock_own')),
'type' => 'check',
'text' => $txt['lock_topic'],
'selected' => $context['locked'],
),
'goback' => array(
'allowed_to' => true,
'type' => 'check',
'text' => $txt['back_to_topic'],
'selected' => $context['back_to_topic'] || !empty($options['return_to_post']),
),
'sticky' => array(
'allowed_to' => allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']),
'type' => 'check',
'text' => $txt['sticky_after'],
'selected' => $context['sticky'],
),
'ns' => array(
'allowed_to' => true,
'type' => 'check',
'text' => $txt['dont_use_smileys'],
'selected' => !$context['use_smileys'],
),
'move' => array(
'allowed_to' => allowedTo('move_any'),
'type' => 'check',
'text' => $txt['move_after2'],
'selected' => !empty($context['move']),
),
'announce_topic' => array(
'allowed_to' => $context['can_announce'] && $context['is_first_post'],
'type' => 'check',
'text' => $txt['announce_topic'],
'selected' => !empty($context['announce']),
),
'approve' => array(
'allowed_to' => $context['show_approval'],
'type' => 'check',
'text' => $txt['approve_this_post'],
'selected' => $context['show_approval'] === 2,
),
),
),
'postAttachmentOptions' => array(
'custom_template' => true,
'values' => array(
'current_attach' => array(
'allowed_to' => !empty($context['current_attachments']),
'function' => 'template_current_attachments',
),
'new_attach' => array(
'allowed_to' => $context['can_post_attachment'],
'function' => 'template_post_attachments',
),
),
),
),
);

foreach ($context['post_below'] as $optkey => $blocks)
{
$show_block = false;
foreach ($blocks['blocks'] as $bk => $block)
{
$show = false;
foreach ($block['values'] as $val)
{
$show = $show[$bk] || $val['allowed_to'];
}
$context['post_below'][$optkey]['blocks'][$bk]['show'] = $show;
$show_block = $show_block || $show;
}
$context['post_below'][$optkey]['show'] = $show_block;
$context['post_below'][$optkey]['collapsed'] = $context['post_below'][$optkey]['collapsed'] && empty($_POST[$optkey . '_status']);
}

// Register this form in the session variables.
checkSubmitOnce('register');

Expand Down
Loading