/**
  * Show PM form
  *
  * @param	string 		Error message
  * @return	string		returns HTML
  */
 protected function _showNewTopicForm($errors = '')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     /* Check max per day */
     if ($this->messengerFunctions->checkHasHitMax()) {
         $this->registry->getClass('output')->showError('maxperday_hit', 10271);
     }
     /* Check PM flood */
     if ($this->messengerFunctions->floodControlCheck() !== TRUE) {
         $this->registry->getClass('output')->showError(sprintf($this->lang->words['pm_flood_stop'], $this->messengerFunctions->exceptionData[0]), 010271);
     }
     /* Check limit*/
     if (!$this->messengerFunctions->withinPMQuota($this->memberData)) {
         $this->registry->getClass('output')->showError('cannot_send_new_limit', 10273, FALSE, '', 40);
     }
     $_msg_id = 0;
     $formMemberID = intval($this->request['fromMemberID']);
     # WAS MID
     $topicID = intval($this->request['topicID']);
     $preview = $this->request['preview'];
     $inviteUsers = array();
     $displayData = array('errors' => $errors ? array($errors) : array(), 'topicID' => $topicID, 'preview' => '', 'name' => '', 'title' => '', 'message' => '');
     $_POST['Post-NS'] = isset($_POST['Post']) ? $_POST['Post'] : '';
     $_POST['Post'] = IPSText::raw2form(isset($_POST['Post']) ? $_POST['Post'] : '');
     //-----------------------------------------
     // Load editor
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/editor/composite.php', 'classes_editor_composite');
     $_editor = new $classToLoad();
     $_editor->setAllowHtml(false);
     //-----------------------------------------
     // Preview post?
     //-----------------------------------------
     if ($preview) {
         /* Grab language for attachment previews */
         $this->registry->getClass('class_localization')->loadLanguageFile(array("public_topic"), 'forums');
         /* Load parser */
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
         $parser = new $classToLoad();
         $parser->set(array('memberData' => $this->memberData, 'parseBBCode' => 1, 'parseArea' => 'pms', 'parseHtml' => 0, 'parseEmoticons' => 1));
         if ($this->request['_from'] == 'quickPM') {
             $old_msg = $_editor->process($_editor->fromPlainTextArea($_POST['Post']));
         } else {
             $old_msg = $_editor->process($_POST['Post']);
         }
         $old_msg = $parser->display($old_msg);
         if (!is_object($this->class_attach)) {
             //-----------------------------------------
             // Grab render attach class
             //-----------------------------------------
             $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php', 'class_attach');
             $this->class_attach = new $classToLoad($this->registry);
         }
         //-----------------------------------------
         // Continue...
         //-----------------------------------------
         $this->class_attach->type = 'msg';
         $this->class_attach->attach_post_key = $this->_postKey;
         $this->class_attach->init();
         $attachData = $this->class_attach->renderAttachments(array(0 => $old_msg));
         $displayData['preview'] = $attachData[0]['html'] . $attachData[0]['attachmentHtml'];
     }
     //-----------------------------------------
     // Errors
     //-----------------------------------------
     if ($errors or IPSText::getTextClass('bbcode')->error != "") {
         if (IPSText::getTextClass('bbcode')->error) {
             $displayData['errors'][] = $this->lang->words[IPSText::getTextClass('bbcode')->error];
         }
         $preview = 1;
     }
     //-----------------------------------------
     // Did we come from a button with a user ID?
     //-----------------------------------------
     if ($formMemberID) {
         $name = IPSMember::load($formMemberID, 'core');
         if ($name['member_id']) {
             $displayData['name'] = $name['members_display_name'];
         }
     } else {
         $displayData['name'] = $this->request['entered_name'] ? $this->request['entered_name'] : '';
     }
     //-----------------------------------------
     // Are we quoting an old message?
     //-----------------------------------------
     if ($preview) {
         $displayData['message'] = $_POST['Post-NS'];
         if ($this->request['_from'] == 'quickPM') {
             $displayData['message'] = IPSText::parseCleanValue($displayData['message'], true);
         }
         $displayData['title'] = str_replace("'", "'", str_replace('"', '"', IPSText::stripslashes($_POST['msg_title'])));
     } else {
         if ($topicID) {
             $draftTopic = $this->messengerFunctions->fetchTopicDataWithMessage($topicID, TRUE);
             /* Permission to view this? */
             if ($draftTopic['mt_starter_id'] == $this->memberData['member_id']) {
                 if ($draftTopic['mt_to_member_id']) {
                     $displayData['name'] = $draftTopic['from_name'];
                 }
                 if ($draftTopic['mt_title']) {
                     $_member = IPSMember::load($draftTopic['mt_to_member_id'], 'core');
                     $displayData['name'] = $_member['members_display_name'];
                     $displayData['title'] = $draftTopic['mt_title'];
                     $_msg_id = $draftTopic['msg_id'];
                     $this->_postKey = $draftTopic['msg_post_key'];
                     /* Load parser */
                     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
                     $parser = new $classToLoad();
                     $parser->set(array('memberData' => $this->memberData, 'parseBBCode' => 1, 'parseArea' => 'pms', 'parseHtml' => 0, 'parseEmoticons' => 1));
                     $displayData['message'] = $draftTopic['msg_post'];
                 }
             }
         }
     }
     //-----------------------------------------
     // CC Boxes
     //-----------------------------------------
     if ($this->memberData['g_max_mass_pm'] > 0) {
         if ($_POST['inviteUsers']) {
             $displayData['inviteUsers'] = IPSText::parseCleanValue($_POST['inviteUsers']);
         } else {
             if ($draftTopic['mt_invited_members']) {
                 $_inviteUsers = $this->messengerFunctions->getInvitedUsers($draftTopic['mt_invited_members']);
                 $__inviteUsers = IPSMember::load($_inviteUsers, 'core');
                 if (is_array($__inviteUsers)) {
                     $_tmp = array();
                     foreach ($__inviteUsers as $id => $data) {
                         $_tmp[] = $data['members_display_name'];
                     }
                     if (is_array($_tmp)) {
                         $displayData['inviteUsers'] = implode(", ", $_tmp);
                     }
                 }
             }
         }
     }
     $_editor->setContent($displayData['message']);
     $displayData['editor'] = $_editor->show('Post', array('height' => 350));
     //-----------------------------------------
     // More Data...
     //-----------------------------------------
     $displayData['uploadData'] = $this->_canUpload ? array('canUpload' => 1) : array('canUpload' => 0);
     $displayData['postKey'] = $this->_postKey;
     //-----------------------------------------
     // Load attachments so we get some stats
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php', 'class_attach');
     $class_attach = new $classToLoad($this->registry);
     $class_attach->type = 'msg';
     $class_attach->init();
     $class_attach->getUploadFormSettings();
     $displayData['uploadData']['attach_stats'] = $class_attach->attach_stats;
     //-----------------------------------------
     // Build up the HTML for the send form
     //-----------------------------------------
     $this->_title = $this->lang->words['sendMsgTitle'];
     $this->_navigation[] = array($this->lang->words['sendMsgTitle'], '');
     return $this->registry->getClass('output')->getTemplate('messaging')->sendNewPersonalTopicForm($displayData);
 }
 /**
  * Show PM form
  *
  * @access	private
  * @param	array 		Array of errors
  * @return	string		returns HTML
  */
 private function _showNewTopicForm($errors = '')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     /* Check max per day */
     if ($this->messengerFunctions->checkHasHitMax()) {
         $this->registry->getClass('output')->showError('maxperday_hit', 10271);
     }
     /* Check PM flood */
     if ($this->messengerFunctions->floodControlCheck() !== TRUE) {
         $this->registry->getClass('output')->showError(sprintf($this->lang->words['pm_flood_stop'], $this->messengerFunctions->exceptionData[0]), 010271);
     }
     $_msg_id = 0;
     $formMemberID = intval($this->request['fromMemberID']);
     # WAS MID
     $topicID = intval($this->request['topicID']);
     $preview = $this->request['preview'];
     $inviteUsers = array();
     $displayData = array('errors' => $errors, 'topicID' => $topicID, 'preview' => '', 'name' => '', 'title' => '', 'message' => '');
     $_POST['Post-NS'] = isset($_POST['Post']) ? $_POST['Post'] : '';
     $_POST['Post'] = IPSText::removeMacrosFromInput(IPSText::raw2form(isset($_POST['Post']) ? $_POST['Post'] : ''));
     //-----------------------------------------
     // Preview post?
     //-----------------------------------------
     if ($preview) {
         /* Grab language for attachment previews */
         $this->registry->getClass('class_localization')->loadLanguageFile(array("public_topic"), 'forums');
         IPSText::getTextClass('bbcode')->parse_html = $this->settings['msg_allow_html'];
         IPSText::getTextClass('bbcode')->parse_nl2br = 1;
         IPSText::getTextClass('bbcode')->parse_smilies = 1;
         IPSText::getTextClass('bbcode')->parse_bbcode = $this->settings['msg_allow_code'];
         IPSText::getTextClass('bbcode')->parsing_section = 'pms';
         IPSText::getTextClass('bbcode')->parsing_mgroup = $this->memberData['member_group_id'];
         IPSText::getTextClass('bbcode')->parsing_mgroup_others = $this->memberData['mgroup_others'];
         $this->settings['max_emos'] = 0;
         $old_msg = IPSText::getTextClass('editor')->processRawPost('Post-NS');
         $old_msg = IPSText::getTextClass('bbcode')->preDisplayParse(IPSText::getTextClass('bbcode')->preDbParse($old_msg));
         if (!is_object($this->class_attach)) {
             //-----------------------------------------
             // Grab render attach class
             //-----------------------------------------
             require_once IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php';
             $this->class_attach = new class_attach($this->registry);
         }
         //-----------------------------------------
         // Continue...
         //-----------------------------------------
         $this->class_attach->type = 'msg';
         $this->class_attach->attach_post_key = $this->_postKey;
         $this->class_attach->init();
         $attachData = $this->class_attach->renderAttachments(array(0 => $old_msg));
         $displayData['preview'] = $attachData[0]['html'] . $attachData[0]['attachmentHtml'];
     }
     //-----------------------------------------
     // Errors
     //-----------------------------------------
     if ($errors or IPSText::getTextClass('bbcode')->error != "") {
         if (IPSText::getTextClass('bbcode')->error) {
             $displayData['errors'][] = $this->lang->words[IPSText::getTextClass('bbcode')->error];
         }
         $preview = 1;
     }
     //-----------------------------------------
     // Did we come from a button with a user ID?
     //-----------------------------------------
     if ($formMemberID) {
         $name = IPSMember::load($formMemberID, 'core');
         if ($name['member_id']) {
             $displayData['name'] = $name['members_display_name'];
         }
     } else {
         $displayData['name'] = $this->request['entered_name'] ? $this->request['entered_name'] : '';
     }
     //-----------------------------------------
     // Are we quoting an old message?
     //-----------------------------------------
     if ($preview) {
         $displayData['message'] = $_POST['Post-NS'];
         $displayData['title'] = str_replace("'", "'", str_replace('"', '"', IPSText::stripslashes($_POST['msg_title'])));
     } else {
         if ($topicID) {
             $draftTopic = $this->messengerFunctions->fetchTopicDataWithMessage($topicID, TRUE);
             if ($draftTopic['mt_to_member_id']) {
                 $displayData['name'] = $draftTopic['from_name'];
             }
             if ($draftTopic['mt_title']) {
                 $_member = IPSMember::load($draftTopic['mt_to_member_id'], 'core');
                 $displayData['name'] = $_member['members_display_name'];
                 $displayData['title'] = $draftTopic['mt_title'];
                 $_msg_id = $draftTopic['msg_id'];
                 $this->_postKey = $draftTopic['msg_post_key'];
                 IPSText::getTextClass('bbcode')->parse_html = $this->settings['msg_allow_html'];
                 IPSText::getTextClass('bbcode')->parse_nl2br = 1;
                 IPSText::getTextClass('bbcode')->parse_smilies = 1;
                 IPSText::getTextClass('bbcode')->parse_bbcode = $this->settings['msg_allow_code'];
                 IPSText::getTextClass('bbcode')->parsing_section = 'pms';
                 $displayData['message'] = IPSText::getTextClass('bbcode')->preEditParse($draftTopic['msg_post']);
             }
         }
     }
     //-----------------------------------------
     // CC Boxes
     //-----------------------------------------
     if ($this->memberData['g_max_mass_pm'] > 0) {
         if ($_POST['inviteUsers']) {
             $displayData['inviteUsers'] = $_POST['inviteUsers'];
         } else {
             if ($draftTopic['mt_invited_members']) {
                 $_inviteUsers = $this->messengerFunctions->getInvitedUsers($draftTopic['mt_invited_members']);
                 $__inviteUsers = IPSMember::load($_inviteUsers, 'core');
                 if (is_array($__inviteUsers)) {
                     $_tmp = array();
                     foreach ($__inviteUsers as $id => $data) {
                         $_tmp[] = $data['members_display_name'];
                     }
                     if (is_array($_tmp)) {
                         $displayData['inviteUsers'] = implode(", ", $_tmp);
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Remove side panel
     //-----------------------------------------
     IPSText::getTextClass('editor')->remove_side_panel = 1;
     //-----------------------------------------
     // PM returns
     //-----------------------------------------
     if (IPSText::getTextClass('editor')->method == 'rte' and $displayData['message'] and $fromMsgID) {
         $displayData['message'] = IPSText::getTextClass('bbcode')->convertForRTE(nl2br($displayData['message']));
     } else {
         if (IPSText::getTextClass('editor')->method == 'std' and $displayData['message'] and $fromMsgID) {
             $displayData['message'] = IPSText::getTextClass('bbcode')->preEditParse($displayData['message']);
         }
     }
     //-----------------------------------------
     // Is this RTE? If so, convert BBCode
     //-----------------------------------------
     if (IPSText::getTextClass('editor')->method == 'rte' and $displayData['message']) {
         if (count($errors) or $preview) {
             $displayData['message'] = stripslashes($displayData['message']);
         }
         $displayData['message'] = IPSText::getTextClass('bbcode')->convertForRTE($displayData['message']);
     } else {
         if ($displayData['message']) {
             $displayData['message'] = IPSText::stripslashes($displayData['message']);
         }
     }
     $displayData['editor'] = IPSText::getTextClass('editor')->showEditor($displayData['message'], 'Post');
     //-----------------------------------------
     // More Data...
     //-----------------------------------------
     $displayData['uploadData'] = $this->_canUpload ? array('canUpload' => 1) : array('canUpload' => 0);
     $displayData['postKey'] = $this->_postKey;
     //-----------------------------------------
     // Load attachments so we get some stats
     //-----------------------------------------
     require_once IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php';
     $class_attach = new class_attach($this->registry);
     $class_attach->type = 'msg';
     $class_attach->init();
     $class_attach->getUploadFormSettings();
     $displayData['uploadData']['attach_stats'] = $class_attach->attach_stats;
     //-----------------------------------------
     // Build up the HTML for the send form
     //-----------------------------------------
     $this->_title = $this->lang->words['sendMsgTitle'];
     $this->_navigation[] = array($this->lang->words['sendMsgTitle'], '');
     return $this->registry->getClass('output')->getTemplate('messaging')->sendNewPersonalTopicForm($displayData);
 }
 /**
  * Check Multi Quote
  * Checks for quoted information
  *
  * @access	public
  * @param	string	Any raw post
  * @return	string	Formatted post
  */
 protected function _checkMultiQuote($postContent)
 {
     $raw_post = '';
     if (!$this->request['qpid']) {
         $this->request['qpid'] = IPSCookie::get('mqtids');
         if ($this->request['qpid'] == ",") {
             $this->request['qpid'] = "";
         }
     } else {
         //-----------------------------------------
         // Came from reply button
         //-----------------------------------------
         $this->request['parent_id'] = $this->request['qpid'];
     }
     $this->request['qpid'] = preg_replace("/[^,\\d]/", "", trim($this->request['qpid']));
     if ($this->request['qpid']) {
         $this->quoted_pids = preg_split('/,/', $this->request['qpid'], -1, PREG_SPLIT_NO_EMPTY);
         //-----------------------------------------
         // Get the posts from the DB and ensure we have
         // suitable read permissions to quote them
         //-----------------------------------------
         if (count($this->quoted_pids)) {
             $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN(" . implode(',', $this->quoted_pids) . ")", 'add_join' => array(array('select' => 't.forum_id', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'), array('select' => 'member_id, members_display_name', 'from' => array('members' => 'm'), 'where' => 'p.author_id=m.member_id', 'type' => 'left'))));
             $this->DB->execute();
             while ($tp = $this->DB->fetch()) {
                 //if( IPSMember::checkPermissions('read', $this->getForumID() ) == TRUE )
                 $perm_id = $this->getAuthor('org_perm_id') ? $this->getAuthor('org_perm_id') : $this->getAuthor('g_perm_id');
                 $perm_array = explode(",", $perm_id);
                 if ($this->registry->permissions->check('read', $this->getForumData(), $perm_array) === TRUE) {
                     $tmp_post = $this->_afterPostCompile($tp['post'], 'reply');
                     $tp['author_name'] = $tp['members_display_name'] ? $tp['members_display_name'] : $tp['author_name'];
                     /*if ( IPSText::getTextClass( 'editor' )->method == 'rte' )
                     		{
                     			$tmp_post = IPSText::getTextClass( 'bbcode' )->convertForRTE(  $tp['post'] );
                     		}
                     		else
                     		{
                     			$tmp_post = trim( IPSText::getTextClass( 'bbcode' )->preEditParse( $tp['post'] ) );
                     		}*/
                     if ($this->settings['strip_quotes']) {
                         $tmp_post = trim($this->_recursiveKillQuotes($tmp_post));
                     }
                     $extra = "";
                     if ($tmp_post) {
                         if (IPSText::getTextClass('editor')->method == 'rte') {
                             $raw_post .= "[quote name='" . IPSText::getTextClass('bbcode')->makeQuoteSafe($tp['author_name']) . "' date='" . IPSText::getTextClass('bbcode')->makeQuoteSafe($this->registry->getClass('class_localization')->getDate($tp['post_date'], 'LONG', 1)) . "' timestamp='" . $tp['post_date'] . "' post='" . $tp['pid'] . "']<br />{$tmp_post}<br />" . $extra . '[/quote]<br /><br /><br />';
                         } else {
                             /* Knocks out <br />  */
                             $tmp_post = trim(IPSText::getTextClass('bbcode')->preEditParse($tmp_post));
                             $raw_post .= "[quote name='" . IPSText::getTextClass('bbcode')->makeQuoteSafe($tp['author_name']) . "' date='" . IPSText::getTextClass('bbcode')->makeQuoteSafe($this->registry->getClass('class_localization')->getDate($tp['post_date'], 'LONG', 1)) . "' timestamp='" . $tp['post_date'] . "' post='" . $tp['pid'] . "']\n{$tmp_post}\n" . $extra . "[/quote]\n\n\n";
                         }
                     }
                 }
             }
             $raw_post = trim($raw_post) . "\n";
         }
     }
     //-----------------------------------------
     // Need to put into RTE format..
     //-----------------------------------------
     if (IPSText::getTextClass('editor')->method == 'rte') {
         $raw_post = IPSText::getTextClass('bbcode')->convertForRTE($raw_post);
     }
     //-----------------------------------------
     // Make raw POST safe for the text area
     //-----------------------------------------
     $raw_post .= IPSText::raw2form($postContent);
     return $raw_post;
 }