Esempio n. 1
0
 /**
  * Show all PM drafts of the current user
  * Uses the showpmdraft template
  * Allows for the deleting and loading/editing of PM drafts
  */
 public function action_showPMDrafts()
 {
     global $txt, $user_info, $scripturl, $modSettings, $context;
     require_once SUBSDIR . '/Profile.subs.php';
     require_once SUBSDIR . '/Drafts.subs.php';
     $memID = currentMemberID();
     // Quick check how we got here.
     if ($memID != $user_info['id']) {
         // empty($modSettings['drafts_enabled']) || empty($modSettings['drafts_pm_enabled']))
         fatal_lang_error('no_access', false);
     }
     // Set up what we will need
     $context['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
     // If just deleting a draft, do it and then redirect back.
     if (!empty($_REQUEST['delete'])) {
         checkSession('get');
         $id_delete = (int) $_REQUEST['delete'];
         deleteDrafts($id_delete, $memID);
         redirectexit('action=pm;sa=showpmdrafts;start=' . $context['start']);
     }
     // Perhaps a draft was selected for editing? if so pass this off
     if (!empty($_REQUEST['id_draft']) && !empty($context['drafts_pm_save'])) {
         checkSession('get');
         $id_draft = (int) $_REQUEST['id_draft'];
         redirectexit('action=pm;sa=send;id_draft=' . $id_draft);
     }
     // Init
     $maxIndex = (int) $modSettings['defaultMaxMessages'];
     // Default to 10.
     if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
         $_REQUEST['viewscount'] = 10;
     }
     // Get the count of applicable drafts
     $msgCount = draftsCount($memID, 1);
     // Make sure the starting place makes sense and construct our friend the page index.
     $context['page_index'] = constructPageIndex($scripturl . '?action=pm;sa=showpmdrafts', $context['start'], $msgCount, $maxIndex);
     $context['current_page'] = $context['start'] / $maxIndex;
     // Reverse the query if we're past 50% of the total for better performance.
     $start = $context['start'];
     $reverse = $start > $msgCount / 2;
     if ($reverse) {
         $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages'];
         $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages'];
     }
     // Go get em'
     $order = 'ud.poster_time ' . ($reverse ? 'ASC' : 'DESC');
     $limit = $start . ', ' . $maxIndex;
     $user_drafts = load_user_drafts($memID, 1, false, $order, $limit);
     // Start counting at the number of the first message displayed.
     $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start'];
     $context['posts'] = array();
     foreach ($user_drafts as $row) {
         // Censor....
         if (empty($row['body'])) {
             $row['body'] = '';
         }
         $row['subject'] = Util::htmltrim($row['subject']);
         if (empty($row['subject'])) {
             $row['subject'] = $txt['no_subject'];
         }
         censorText($row['body']);
         censorText($row['subject']);
         // BBC-ilize the message.
         $row['body'] = parse_bbc($row['body'], true, 'draft' . $row['id_draft']);
         // Have they provided who this will go to?
         $recipients = array('to' => array(), 'bcc' => array());
         $recipient_ids = !empty($row['to_list']) ? unserialize($row['to_list']) : array();
         // Get nice names to show the user, the id's are not that great to see!
         if (!empty($recipient_ids['to']) || !empty($recipient_ids['bcc'])) {
             $recipient_ids['to'] = array_map('intval', $recipient_ids['to']);
             $recipient_ids['bcc'] = array_map('intval', $recipient_ids['bcc']);
             $allRecipients = array_merge($recipient_ids['to'], $recipient_ids['bcc']);
             $recipients = draftsRecipients($allRecipients, $recipient_ids);
         }
         // Add the items to the array for template use
         $context['drafts'][$counter += $reverse ? -1 : 1] = array('body' => $row['body'], 'counter' => $counter, 'alternate' => $counter % 2, 'subject' => $row['subject'], 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'id_draft' => $row['id_draft'], 'recipients' => $recipients, 'age' => floor((time() - $row['poster_time']) / 86400), 'remaining' => !empty($modSettings['drafts_keep_days']) ? floor($modSettings['drafts_keep_days'] - (time() - $row['poster_time']) / 86400) : 0);
     }
     // If the drafts were retrieved in reverse order, then put them in the right order again.
     if ($reverse) {
         $context['drafts'] = array_reverse($context['drafts'], true);
     }
     // Off to the template we go
     $context['page_title'] = $txt['drafts'];
     $context['sub_template'] = 'showPMDrafts';
     $context['linktree'][] = array('url' => $scripturl . '?action=pm;sa=showpmdrafts', 'name' => $txt['drafts']);
 }
Esempio n. 2
0
 /**
  * Loads in a group of post drafts for the user.
  * Loads a specific draft for current use in the postbox if selected.
  * Used in the posting screens to allow draft selection
  * Will load a draft if selected is supplied via post
  *
  * @param int $member_id
  * @param int|false $id_topic if set, load drafts for the specified topic
  * @return false|null
  */
 private function _prepareDraftsContext($member_id, $id_topic = false)
 {
     global $scripturl, $context, $txt, $modSettings;
     $context['drafts'] = array();
     // Need a member
     if (empty($member_id)) {
         return false;
     }
     // We haz drafts
     loadLanguage('Drafts');
     require_once SUBSDIR . '/Drafts.subs.php';
     // has a specific draft has been selected?  Load it up if there is not already a message already in the editor
     if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) {
         loadDraft((int) $_REQUEST['id_draft'], 0, true, true);
     }
     // load all the drafts for this user that meet the criteria
     $order = 'poster_time DESC';
     $user_drafts = load_user_drafts($member_id, 0, $id_topic, $order);
     // Add them to the context draft array for template display
     foreach ($user_drafts as $draft) {
         $short_subject = empty($draft['subject']) ? $txt['drafts_none'] : Util::shorten_text(stripslashes($draft['subject']), !empty($modSettings['draft_subject_length']) ? $modSettings['draft_subject_length'] : 24);
         $context['drafts'][] = array('subject' => censorText($short_subject), 'poster_time' => standardTime($draft['poster_time']), 'link' => '<a href="' . $scripturl . '?action=post;board=' . $draft['id_board'] . ';' . (!empty($draft['id_topic']) ? 'topic=' . $draft['id_topic'] . '.0;' : '') . 'id_draft=' . $draft['id_draft'] . '">' . (!empty($draft['subject']) ? $draft['subject'] : $txt['drafts_none']) . '</a>');
     }
 }