/** * 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>'); } }
/** * Saves a PM draft in the user_drafts table * * - The core draft feature must be enabled, as well as the pm draft option * - Determines if this is a new or and update to an existing pm draft * * @package Drafts * @param mixed[] $recipientList */ function savePMDraft($recipientList) { global $context, $user_info, $modSettings; // Ajax calling if (!isset($context['drafts_pm_save'])) { $context['drafts_pm_save'] = !empty($modSettings['drafts_enabled']) && !empty($modSettings['drafts_pm_enabled']) && allowedTo('pm_draft'); } // PM survey says ... can you stay or must you go if (empty($context['drafts_pm_save']) || !isset($_POST['save_draft']) || !isset($_POST['id_pm_draft'])) { return false; } // Read in what was sent $id_pm_draft = empty($_POST['id_pm_draft']) ? 0 : (int) $_POST['id_pm_draft']; $draft_info = loadDraft($id_pm_draft, 1); $post_errors = Error_Context::context('pm', 1); // 5 seconds is the same limit we have for posting if (isset($_REQUEST['xml']) && !empty($draft_info['poster_time']) && time() < $draft_info['poster_time'] + 5) { // Send something back to the javascript caller if (!empty($id_pm_draft)) { loadTemplate('Xml'); $context['sub_template'] = 'xml_draft'; $context['id_draft'] = $id_pm_draft; $context['draft_saved_on'] = $draft_info['poster_time']; obExit(); } return true; } // Determine who this is being sent to if (isset($_REQUEST['xml'])) { $recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array(); $recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array(); } elseif (!empty($draft_info['to_list']) && empty($recipientList)) { $recipientList = unserialize($draft_info['to_list']); } // Prepare the data $draft = array('id_pm_draft' => $id_pm_draft, 'reply_id' => empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to'], 'body' => Util::htmlspecialchars($_POST['message'], ENT_QUOTES), 'subject' => strtr(Util::htmlspecialchars($_POST['subject']), array("\r" => '', "\n" => '', "\t" => '')), 'id_member' => $user_info['id']); // message and subject always need a bit more work preparsecode($draft['body']); if (Util::strlen($draft['subject']) > 100) { $draft['subject'] = Util::substr($draft['subject'], 0, 100); } // Modifying an existing PM draft? if (!empty($id_pm_draft) && !empty($draft_info)) { modify_pm_draft($draft, $recipientList); // some items to return to the form $context['draft_saved'] = true; $context['id_pm_draft'] = $id_pm_draft; } else { $id_pm_draft = create_pm_draft($draft, $recipientList); // Everything go as expected, if not toss back an error if (!empty($id_pm_draft)) { $context['draft_saved'] = true; $context['id_pm_draft'] = $id_pm_draft; } else { $post_errors->addError('draft_not_saved'); } } // if we were called from the autosave function, send something back if (!empty($id_pm_draft) && isset($_REQUEST['xml']) && !$post_errors->hasError('session_timeout')) { loadTemplate('Xml'); $context['sub_template'] = 'xml_draft'; $context['id_draft'] = $id_pm_draft; $context['draft_saved_on'] = time(); obExit(); } return; }