/** * Send an email * * @param string $email Address to send to * @param string $subject Message subject * @param mixed $contents Message to send * @param array $from Who the message is from * @param array $replyto Reply to information * @param array $additionalHeaders More headers to apply * @return boolean */ public static function sendEmail($email, $subject, $contents, $from, $replyto = '', $additionalHeaders = null) { if ($from) { $message = new Message(); $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($email); if ($replyto) { $message->addReplyTo($replyto, $from['name']); } else { $message->addReplyTo($from['email'], $from['name']); } if (is_array($additionalHeaders)) { // The xheaders array has name and value pairs foreach ($additionalHeaders as $header) { $message->addHeader($header['name'], $header['value']); } } if (is_array($contents)) { if (isset($contents['attachments'])) { if (!is_array($contents['attachments'])) { $contents['attachments'] = array($contents['attachments']); } foreach ($contents['attachments'] as $path) { if (preg_match("/\\.(bmp|gif|jpg|jpe|jpeg|png)\$/i", $path)) { $file = basename($path); $size = getimagesize($path); $width = $size[0] > 650 ? 650 : $size[0]; $contents['multipart'] = preg_replace('/<a class="img" data\\-filename="' . str_replace('.', '\\.', $file) . '" href="(.*?)"\\>(.*?)<\\/a>/i', '<img width="' . $width . '" src="' . $message->getEmbed($path) . '" alt="" />', $contents['multipart']); } else { $message->addAttachment($path); } } } $message->addPart($contents['plaintext'], 'text/plain')->addPart($contents['multipart'], 'text/html'); } else { $message->setBody($contents); } if ($message->send()) { return true; } } return false; }
/** * Display module content * * @return void */ public function display() { // Field labels $this->name_label = $this->params->get('name_label', Lang::txt('MOD_RAPID_CONTACT_FIELD_NAME')); $this->email_label = $this->params->get('email_label', Lang::txt('MOD_RAPID_CONTACT_FIELD_EMAIL')); $this->subject_label = $this->params->get('subject_label', Lang::txt('MOD_RAPID_CONTACT_FIELD_SUBJECT')); $this->message_label = $this->params->get('message_label', Lang::txt('MOD_RAPID_CONTACT_FIELD_MESSAGE')); // Button text $this->button_text = $this->params->get('button_text', Lang::txt('MOD_RAPID_CONTACT_SEND')); // Pre text $this->pre_text = $this->params->get('pre_text', ''); // Thank you message $this->page_text = $this->params->get('page_text', Lang::txt('MOD_RAPID_CONTACT_THANK_YOU')); // Error messages $this->error_text = $this->params->get('error_text', Lang::txt('MOD_RAPID_CONTACT_ERROR_SENDING')); $this->no_email = $this->params->get('no_email', Lang::txt('MOD_RAPID_CONTACT_ERROR_NO_EMAIL')); $this->invalid_email = $this->params->get('invalid_email', Lang::txt('MOD_RAPID_CONTACT_ERROR_INVALID_EMAIL')); // From $this->from_name = $this->params->get('from_name', Lang::txt('MOD_RAPID_CONTACT')); $this->from_email = $this->params->get('from_email', '*****@*****.**'); // To $this->recipient = $this->params->get('email_recipient', Config::get('mailfrom')); if (!trim($this->recipient)) { $this->recipient = Config::get('mailfrom'); } // Enable Anti-spam? $this->enable_anti_spam = $this->params->get('enable_anti_spam', true); $this->anti_spam_q = $this->params->get('anti_spam_q', Lang::txt('MOD_RAPID_CONTACT_ANTIPSAM')); $this->anti_spam_a = $this->params->get('anti_spam_a', '2'); $this->mod_class_suffix = $this->params->get('moduleclass_sfx', ''); $disable_https = $this->params->get('disable_https', false); $exact_url = $this->params->get('exact_url', true); if (!$exact_url) { //$this->url = $this->_cleanXss(filter_var(Request::current(), FILTER_SANITIZE_URL)); $this->url = Request::current(); } else { if (!$disable_https) { $this->url = !empty($_SERVER['HTTPS']) ? 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; } else { $this->url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; } } //$qs = str_replace(array('"', '?'), '', urldecode($_SERVER['QUERY_STRING'])); //$aqs = explode('?', $this->url); //$this->url = $aqs[0] . '?' . urlencode($qs); $fixed_url = $this->params->get('fixed_url', true); if ($fixed_url) { $this->url = $this->params->get('fixed_url_address', ''); } $this->error = ''; $this->replacement = ''; $this->posted = array('name' => '', 'email' => '', 'subject' => '', 'message' => ''); if (isset($_POST['rp'])) { $this->posted = Request::getVar('rp', array(), 'post'); if ($this->enable_anti_spam) { if (!isset($this->posted['anti_spam_answer']) || $this->posted['anti_spam_answer'] != $this->anti_spam_a) { $this->error = Lang::txt('MOD_RAPID_CONTACT_INVALID_ANTIPSAM_ANSWER'); } } if ($this->posted['email'] === '') { $this->error = $this->no_email; } if (!preg_match("#^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$#i", $this->posted['email'])) { $this->error = $this->invalid_email; } if ($this->error == '') { $mySubject = Sanitize::clean($this->posted['subject']); $myMessage = Lang::txt('MOD_RAPID_CONTACT_MESSAGE_FROM', $this->posted['name'], $this->posted['email'], Request::getVar('HTTP_REFERER', '', 'SERVER'), Config::get('sitename')); $myMessage .= "\n\n" . Sanitize::clean($this->posted['message']); $this->from_email = $this->posted['email']; $this->from_name = isset($this->posted['name']) && Sanitize::clean($this->posted['name']) ? Sanitize::clean($this->posted['name']) : $this->posted['email']; $mailSender = new Message(); $mailSender->setSubject($mySubject)->addFrom($this->from_email, $this->from_name)->addTo($this->recipient)->addReplyTo($this->posted['email'], $this->posted['name'])->setBody($myMessage); if (!$mailSender->send()) { $this->error = $this->error_text; } else { $this->replacement = $this->page_text; } } } require $this->getLayoutPath($this->params->get('layout', 'default')); }
/** * Delete a record * * @param boolean $isSpam * @return void */ public function removeTask($isSpam = false) { // Check for request forgeries Request::checkToken(); // Incoming $id = Request::getInt('id', 0); $parentid = Request::getInt('parentid', 0); // Ensure we have an ID to work with if (!$id) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); return; } $email = 1; // Turn off/on $gratitude = 1; // Turn off/on $message = ''; // Load the report $report = new ReportAbuse($this->database); $report->load($id); $report->reviewed = Date::toSql(); $report->reviewed_by = User::get('id'); $report->note = Request::getVar('note', ''); // Get the reported item $results = Event::trigger('support.getReportedItem', array($report->referenceid, $report->category, $parentid)); // Check the results returned for a reported item $reported = null; if ($results) { foreach ($results as $result) { if ($result) { $reported = $result[0]; } } } // Remove the reported item and any other related processes that need be performed $results = Event::trigger('support.deleteReportedItem', array($report->referenceid, $parentid, $report->category, $message)); if ($results) { foreach ($results as $result) { if ($result) { $message .= $result; } } } if ($isSpam) { $results = Event::trigger('antispam.onAntispamTrain', array($reported->text, $isSpam)); } // Mark abuse report as deleted $report->state = 2; if (!$report->store()) { throw new Exception($report->getError(), 500); } // Notify item owner if ($email) { $user = User::getInstance($reported->author); // Email "from" info $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT'), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U'))); // Email subject $subject = Lang::txt('COM_SUPPORT_REPORT_ABUSE_EMAIL_SUBJECT', Config::get('sitename')); // Plain text $eview = new View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'site', 'name' => 'emails', 'layout' => 'abuse_plain')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->reported = $reported; $eview->report = $report; $eview->author = $user; $plain = $eview->loadTemplate(false); $plain = str_replace("\n", "\r\n", $plain); // HTML $eview->setLayout('abuse_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); // Build message $message = new Message(); $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_support')->addHeader('X-Component-Object', 'abuse_item_removal'); $message->addPart($plain, 'text/plain'); $message->addPart($html, 'text/html'); // Send the email if (Utilities::checkValidEmail($user->get('email'))) { $message->send(); } } // Check the HUB configuration to see if banking is turned on $upconfig = Component::params('com_members'); $banking = $upconfig->get('bankAccounts'); // Give some points to whoever reported abuse if ($banking && $gratitude) { $BC = \Hubzero\Bank\Config::values(); $ar = $BC->get('abusereport'); // How many points? if ($ar) { $ruser = User::getInstance($report->created_by); if (is_object($ruser) && $ruser->get('id')) { $BTL = new \Hubzero\Bank\Teller($ruser->get('id')); $BTL->deposit($ar, Lang::txt('COM_SUPPORT_ACKNOWLEDGMENT_FOR_VALID_REPORT'), 'abusereport', $id); } } } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SUPPORT_REPORT_ITEM_TAKEN_DOWN')); }
/** * Instantiates and registers a mail transport mechanism on the message * * @return void */ public function onMailersRegister() { $transporter = new \Hubzero\Mail\Transport\Mandrill($this->params->get('api_key')); \Hubzero\Mail\Message::addTransporter('mandrill', $transporter); }
/** * Email Announcement * * @param object $announcement * @return boolean */ public function emailAnnouncement($announcement = null) { // make sure we have an announcement if ($announcement === null) { $announcement = $this; } // load group $group = Group::getInstance($announcement->scope_id); // get all group members $groupMembers = array(); foreach ($group->get('members') as $member) { if ($profile = Profile::getInstance($member)) { $groupMembers[$profile->get('email')] = $profile->get('name'); } } // create view object $eview = new View(array('base_path' => PATH_CORE . DS . 'plugins' . DS . 'groups' . DS . 'announcements', 'name' => 'email', 'layout' => 'announcement_plain')); // plain text $eview->announcement = $announcement; $plain = $eview->loadTemplate(); $plain = str_replace("\n", "\r\n", $plain); // HTML $eview->setLayout('announcement_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); // set from address $from = array('name' => \Config::get('sitename') . ' Groups', 'email' => \Config::get('mailfrom')); // define subject $subject = $group->get('description') . ' Group Announcement'; foreach ($groupMembers as $email => $name) { // create message object $message = new Message(); // set message details and send $message->setSubject($subject)->addReply($from['email'], $from['name'])->addFrom($from['email'], $from['name'])->setTo($email, $name)->addPart($plain, 'text/plain')->addPart($html, 'text/html')->send(); } // all good return true; }