/** * Open, parse, and return the template file. * * @param $file string the template file name */ public function fetch($file = null) { $tmpFile = $file; if (empty($file)) { $file = $this->file; } $file = JPATH_ROOT . DS . 'components' . DS . 'com_messaging' . DS . 'templates' . DS . 'default' . DS . $file . '.php'; // Template variable: $my; $my = JXFactory::getUser(); $this->setRef('my', $my); // Template variable: the rest. if ($this->vars) { extract($this->vars, EXTR_REFS); } if (!JFile::exists($file)) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::sprintf('COM_STREAM_TEMPLATE_FILE_NOT_FOUND', $tmpFile . '.php'), 'error'); return; } ob_start(); // Start output buffering require $file; // Include the file $contents = ob_get_contents(); // Get the contents of the buffer ob_end_clean(); // End buffering and discard // Replace all _QQQ_ to " // Language file now uses new _QQQ_ to maintain Joomla 1.6 compatibility $contents = MessagingTemplate::quote($contents); return $contents; // Return the contents }
public function addReply() { $msgId = JRequest::getVar('msgid', '', 'POST'); $reply = JRequest::getVar('reply', '', 'POST'); $attachment = JRequest::getVar('attachment', array(), 'POST', 'array'); $my = JXFactory::getUser(); $messagingModel = MessagingFactory::getModel('inbox'); $message = $messagingModel->getMessage($msgId); if ($my->id == 0) { return; } $now = new JDate(); $obj = new stdClass(); $obj->id = null; $obj->from = $my->id; $obj->posted_on = $now->toMySQL(); $obj->from_name = $my->name; $obj->subject = 'RE:' . $message->subject; $obj->body = $reply; $obj->attachment = implode(', ', $attachment); $messagingModel->sendReply($obj, $msgId); $deleteLink = JRoute::_('index.php?option=com_community&view=inbox&task=remove&msgid=' . $obj->id); $authorLink = JRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id); $this->_addAttachments($obj->id); $attachments = $messagingModel->getAttachments($obj); $tmpl = new MessagingTemplate(); $tmpl->set('user', JXFactory::getUser($obj->from)); $tmpl->set('msg', $obj); $tmpl->set('removeLink', $deleteLink); $tmpl->set('authorLink', $authorLink); $tmpl->set('attachments', $attachments); $html = $tmpl->fetch('inbox.message'); $data = array(); $data['html'] = $html; header('Content-Type: text/json'); echo json_encode($data); exit; }
/** * Show the message reading page */ public function read($data) { $mainframe = JFactory::getApplication(); $my = JFactory::getUser(); $doc = JFactory::getDocument(); // Add file attachment library $doc->addScript(JURI::root() . 'media/uploader/fileuploader.js'); $doc->addStyleSheet(JURI::root() . 'media/uploader/fileuploader.css'); $this->addPathway(JText::_('COM_COMMUNITY_INBOX'), JRoute::_('index.php?option=com_messaging&view=inbox')); //JXModule::addBuffer('right', '<br /><h4>Side bar stuff goes here</h4>'); $inboxModel = MessagingFactory::getModel('inbox'); $msgid = JRequest::getVar('msgid', 0, 'REQUEST'); $parentData = ''; $html = $htmlContent = ''; $messageHeading = ''; $recipient = array(); $parentData = $inboxModel->getMessage($msgid); if (!empty($data->messages)) { $document = JFactory::getDocument(); $document->setTitle($this->escape($parentData->subject)); $this->addPathway($this->escape($parentData->subject)); foreach ($data->messages as $row) { // onMessageDisplay Event trigger $args = array(); $args[] =& $row; $user = JXFactory::getUser($row->from); //construct the delete link $deleteLink = JRoute::_('index.php?option=com_community&task=remove&msgid=' . $row->id); $authorLink = JRoute::_('index.php?option=com_profile&view=display&user='******'user', $user)->set('msg', $row)->set('isMine', 0)->set('removeLink', $deleteLink)->set('authorLink', $authorLink)->set('attachments', $attachments)->set('readBy', $readBy)->fetch('inbox.message'); } $myLink = JRoute::_('index.php?option=com_profile&view=display'); $recipient = array(); // Put the sender in the participant list $from = new stdClass(); $from->to = $parentData->from; $recipient[] = $from; $recipient = array_merge($recipient, $inboxModel->getRecepientMessage($msgid)); $recepientCount = count($recipient) - 1; // exclude the sender $textOther = $recepientCount > 1 ? 'COM_COMMUNITY_MSG_OTHER' : 'COM_COMMUNITY_MSG_OTHER_SINGULAR'; $messageHeading = JText::sprintf('COM_COMMUNITY_MSG_BETWEEN_YOU_AND_USER', $myLink, '#', JText::sprintf($textOther, $recepientCount)); } else { $html = '<div class="text">' . JText::_('COM_COMMUNITY_INBOX_MESSAGE_EMPTY') . '</div>'; } $tmplMain = new MessagingTemplate(); $html .= $tmplMain->set('messageHeading', $messageHeading)->set('msgid', $msgid)->set('recipient', $recipient)->set('messages', $data->messages)->set('parentData', $parentData)->set('htmlContent', $htmlContent)->set('my', $my)->fetch('inbox.read'); return $html; }