/** * Method to get the field input markup. * * @return string The field input markup. * * @since 11.1 */ protected function getInput() { $html = array(); $link = 'index.php?option=com_emailtemplates&view=emails&layout=modal&tmpl=component&field=' . $this->id; // Initialize some field attributes. $attr = !empty($this->class) ? ' class="' . $this->class . '"' : ''; $attr .= !empty($this->size) ? ' size="' . $this->size . '"' : ''; $attr .= $this->required ? ' required' : ''; // Load the modal behavior script. JHtml::_('behavior.modal', 'a.modal_' . $this->id); // Build the script. $script = array(); $script[] = ' function jSelectEmailTemplate_' . $this->id . '(id, title) {'; $script[] = ' var old_id = document.getElementById("' . $this->id . '_id").value;'; $script[] = ' if (old_id != id) {'; $script[] = ' document.getElementById("' . $this->id . '_id").value = id;'; $script[] = ' document.getElementById("' . $this->id . '").value = title;'; $script[] = ' document.getElementById("' . $this->id . '").className = document.getElementById("' . $this->id . '").className.replace(" invalid" , "");'; $script[] = ' ' . $this->onchange; $script[] = ' }'; $script[] = ' jModalClose();'; $script[] = ' }'; // Add the script to the document head. JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); if (is_numeric($this->value) and !empty($this->value)) { $email = new Emailtemplates\Email(); $email->setDb(JFactory::getDbo()); $email->load($this->value); $title = $email->getTitle(); } else { $title = JText::_('LIB_EMAILTEMPLATES_SELECT_EMAIL_TEMPLATE'); } // Create a dummy text field with the email template title. $html[] = '<div class="input-append">'; $html[] = ' <input type="text" id="' . $this->id . '" value="' . htmlspecialchars($title, ENT_COMPAT, 'UTF-8') . '" readonly' . $attr . ' />'; // Create the user select button. if ($this->readonly === false) { $html[] = ' <a class="btn modal_' . $this->id . '" title="' . JText::_('LIB_EMAILTEMPLATES_CHANGE_EMAIL_TEMPLATE') . '" href="' . $link . '"' . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">'; $html[] = '<i class="icon-envelope"></i></a>'; } $html[] = '</div>'; // Create the real field, hidden, that stored the user id. $html[] = '<input type="hidden" id="' . $this->id . '_id" name="' . $this->name . '" value="' . $this->value . '" />'; return implode("\n", $html); }
/** * @param stdClass $project * @param int $emailId * * @return bool */ protected function sendMail($project, $emailId) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get website $uri = JUri::getInstance(); $website = $uri->toString(array('scheme', 'host')); $emailMode = $this->params->get('email_mode', 'plain'); // Route project URI $appSite = JApplicationCms::getInstance('site'); $router = $appSite->getRouter('site'); $routedUri = $router->build(CrowdfundingHelperRoute::getDetailsRoute($project->slug, $project->catslug)); if ($routedUri instanceof JUri) { $routedUri = $routedUri->toString(); } if (0 === strpos($routedUri, '/administrator')) { $routedUri = str_replace('/administrator', '', $routedUri); } // Prepare data for parsing $data = array('site_name' => $app->get('sitename'), 'site_url' => JUri::root(), 'item_title' => $project->title, 'item_url' => $website . $routedUri); $email = new Emailtemplates\Email(); $email->setDb(JFactory::getDbo()); $email->load($emailId); if (!$email->getSenderName()) { $email->setSenderName($app->get('fromname')); } if (!$email->getSenderEmail()) { $email->setSenderEmail($app->get('mailfrom')); } $recipientName = $project->name; $recipientMail = $project->email; // Prepare data for parsing $data['sender_name'] = $email->getSenderName(); $data['sender_email'] = $email->getSenderEmail(); $data['recipient_name'] = $recipientName; $data['recipient_email'] = $recipientMail; $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp('html', $emailMode) === 0) { // Send as HTML message $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML); } else { // Send as plain text. $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN); } // Log the error. if ($result !== true) { JLog::add($this->errorPrefix . $mailer->ErrorInfo, JLog::WARNING, 'com_crowdfunding'); return false; } return true; }
protected function sendReportMail($report, $emailId) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Send mail to the administrator if (!$emailId) { return false; } // Get website $uri = JUri::getInstance(); $website = $uri->toString(array('scheme', 'host')); $emailMode = $this->params->get('email_mode', 'plain'); // Get project $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $report->project_id); // Prepare data for parsing $data = array('site_name' => $app->get('sitename'), 'site_url' => JUri::root(), 'item_title' => $project->getTitle(), 'item_url' => $website . JRoute::_(CrowdfundingHelperRoute::getDetailsRoute($project->getSlug(), $project->getCatSlug())), 'report_subject' => $report->subject, 'report_description' => $report->description); $email = new Emailtemplates\Email(); $email->setDb(JFactory::getDbo()); $email->load($emailId); if (!$email->getSenderName()) { $email->setSenderName($app->get('fromname')); } if (!$email->getSenderEmail()) { $email->setSenderEmail($app->get('mailfrom')); } // Prepare recipient data. $componentParams = JComponentHelper::getParams('com_crowdfunding'); /** @var $componentParams Joomla\Registry\Registry */ $recipientId = (int) $componentParams->get('administrator_id'); if ($recipientId > 0) { $recipient = JFactory::getUser($recipientId); $recipientName = $recipient->get('name'); $recipientMail = $recipient->get('email'); } else { $recipientName = $app->get('fromname'); $recipientMail = $app->get('mailfrom'); } // Prepare data for parsing $data['sender_name'] = $email->getSenderName(); $data['sender_email'] = $email->getSenderEmail(); $data['recipient_name'] = $recipientName; $data['recipient_email'] = $recipientMail; $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp('html', $emailMode) === 0) { // Send as HTML message $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML); } else { // Send as plain text. $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN); } // Log the error. if ($result !== true) { $this->log->add(JText::sprintf('PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_SEND_MAIL', $this->name), 'PLG_CONTENT_ADMIN_EMAIL_ERROR', JText::sprintf('PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_SEND_MAIL_NOTE', $mailer->ErrorInfo)); return false; } return true; }