0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: mail.php.tar
home/academiac/www/libraries/joomla/mail/mail.php 0000644 00000026457 15137263365 0016052 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Mail * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; jimport('phpmailer.phpmailer'); /** * Email Class. Provides a common interface to send email from the Joomla! Platform * * @package Joomla.Platform * @subpackage Mail * @since 11.1 */ class JMail extends PHPMailer { /** * @var array JMail instances container. * @since 11.3 */ protected static $instances = array(); /** * @var string Charset of the message. * @since 11.1 */ public $CharSet = 'utf-8'; /** * Constructor */ public function __construct() { // PHPMailer has an issue using the relative path for its language files $this->SetLanguage('joomla', JPATH_PLATFORM . '/phpmailer/language/'); } /** * Returns the global email object, only creating it * if it doesn't already exist. * * NOTE: If you need an instance to use that does not have the global configuration * values, use an id string that is not 'Joomla'. * * @param string $id The id string for the JMail instance [optional] * * @return JMail The global JMail object * * @since 11.1 */ public static function getInstance($id = 'Joomla') { if (empty(self::$instances[$id])) { self::$instances[$id] = new JMail; } return self::$instances[$id]; } /** * Send the mail * * @return mixed True if successful, a JError object otherwise * * @since 11.1 */ public function Send() { if (($this->Mailer == 'mail') && !function_exists('mail')) { return JError::raiseNotice(500, JText::_('JLIB_MAIL_FUNCTION_DISABLED')); } @$result = parent::Send(); if ($result == false) { // TODO: Set an appropriate error number $result = JError::raiseNotice(500, JText::_($this->ErrorInfo)); } return $result; } /** * Set the email sender * * @param array $from email address and Name of sender * <code>array([0] => email Address [1] => Name)</code> * * @return JMail Returns this object for chaining. * * @since 11.1 */ public function setSender($from) { if (is_array($from)) { // If $from is an array we assume it has an address and a name if (isset($from[2])) { // If it is an array with entries, use them $this->SetFrom(JMailHelper::cleanLine($from[0]), JMailHelper::cleanLine($from[1]), (bool) $from[2]); } else { $this->SetFrom(JMailHelper::cleanLine($from[0]), JMailHelper::cleanLine($from[1])); } } elseif (is_string($from)) { // If it is a string we assume it is just the address $this->SetFrom(JMailHelper::cleanLine($from)); } else { // If it is neither, we throw a warning JError::raiseWarning(0, JText::sprintf('JLIB_MAIL_INVALID_EMAIL_SENDER', $from)); } return $this; } /** * Set the email subject * * @param string $subject Subject of the email * * @return JMail Returns this object for chaining. * * @since 11.1 */ public function setSubject($subject) { $this->Subject = JMailHelper::cleanLine($subject); return $this; } /** * Set the email body * * @param string $content Body of the email * * @return JMail Returns this object for chaining. * * @since 11.1 */ public function setBody($content) { /* * Filter the Body * TODO: Check for XSS */ $this->Body = JMailHelper::cleanText($content); return $this; } /** * Add recipients to the email * * @param mixed $recipient Either a string or array of strings [email address(es)] * @param mixed $name Either a string or array of strings [name(s)] * * @return JMail Returns this object for chaining. * * @since 11.1 */ public function addRecipient($recipient, $name = '') { // If the recipient is an array, add each recipient... otherwise just add the one if (is_array($recipient)) { foreach ($recipient as $to) { $to = JMailHelper::cleanLine($to); $this->AddAddress($to); } } else { $recipient = JMailHelper::cleanLine($recipient); $this->AddAddress($recipient); } return $this; } /** * Add carbon copy recipients to the email * * @param mixed $cc Either a string or array of strings [email address(es)] * @param mixed $name Either a string or array of strings [name(s)] * * @return JMail Returns this object for chaining. * * @since 11.1 */ public function addCC($cc, $name = '') { // If the carbon copy recipient is an array, add each recipient... otherwise just add the one if (isset($cc)) { if (is_array($cc)) { foreach ($cc as $to) { $to = JMailHelper::cleanLine($to); parent::AddCC($to); } } else { $cc = JMailHelper::cleanLine($cc); parent::AddCC($cc); } } return $this; } /** * Add blind carbon copy recipients to the email * * @param mixed $bcc Either a string or array of strings [email address(es)] * @param mixed $name Either a string or array of strings [name(s)] * * @return JMail Returns this object for chaining. * * @since 11.1 */ public function addBCC($bcc, $name = '') { // If the blind carbon copy recipient is an array, add each recipient... otherwise just add the one if (isset($bcc)) { if (is_array($bcc)) { foreach ($bcc as $to) { $to = JMailHelper::cleanLine($to); parent::AddBCC($to); } } else { $bcc = JMailHelper::cleanLine($bcc); parent::AddBCC($bcc); } } return $this; } /** * Add file attachments to the email * * @param mixed $attachment Either a string or array of strings [filenames] * @param mixed $name Either a string or array of strings [names] * @param mixed $encoding The encoding of the attachment * @param mixed $type The mime type * * @return JMail Returns this object for chaining. * * @since 11.1 */ public function addAttachment($attachment, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { // If the file attachments is an array, add each file... otherwise just add the one if (isset($attachment)) { if (is_array($attachment)) { foreach ($attachment as $file) { parent::AddAttachment($file, $name, $encoding, $type); } } else { parent::AddAttachment($attachment, $name, $encoding, $type); } } return $this; } /** * Add Reply to email address(es) to the email * * @param array $replyto Either an array or multi-array of form * <code>array([0] => email Address [1] => Name)</code> * @param mixed $name Either an array or single string * * @return JMail Returns this object for chaining. * * @since 11.1 */ public function addReplyTo($replyto, $name = '') { // Take care of reply email addresses if (is_array($replyto[0])) { foreach ($replyto as $to) { $to0 = JMailHelper::cleanLine($to[0]); $to1 = JMailHelper::cleanLine($to[1]); parent::AddReplyTo($to0, $to1); } } else { $replyto0 = JMailHelper::cleanLine($replyto[0]); $replyto1 = JMailHelper::cleanLine($replyto[1]); parent::AddReplyTo($replyto0, $replyto1); } return $this; } /** * Use sendmail for sending the email * * @param string $sendmail Path to sendmail [optional] * * @return boolean True on success * * @since 11.1 */ public function useSendmail($sendmail = null) { $this->Sendmail = $sendmail; if (!empty($this->Sendmail)) { $this->IsSendmail(); return true; } else { $this->IsMail(); return false; } } /** * Use SMTP for sending the email * * @param string $auth SMTP Authentication [optional] * @param string $host SMTP Host [optional] * @param string $user SMTP Username [optional] * @param string $pass SMTP Password [optional] * @param string $secure Use secure methods * @param integer $port The SMTP port * * @return boolean True on success * * @since 11.1 */ public function useSMTP($auth = null, $host = null, $user = null, $pass = null, $secure = null, $port = 25) { $this->SMTPAuth = $auth; $this->Host = $host; $this->Username = $user; $this->Password = $pass; $this->Port = $port; if ($secure == 'ssl' || $secure == 'tls') { $this->SMTPSecure = $secure; } if (($this->SMTPAuth !== null && $this->Host !== null && $this->Username !== null && $this->Password !== null) || ($this->SMTPAuth === null && $this->Host !== null)) { $this->IsSMTP(); return true; } else { $this->IsMail(); return false; } } /** * Function to send an email * * @param string $from From email address * @param string $fromName From name * @param mixed $recipient Recipient email address(es) * @param string $subject email subject * @param string $body Message body * @param boolean $mode false = plain text, true = HTML * @param mixed $cc CC email address(es) * @param mixed $bcc BCC email address(es) * @param mixed $attachment Attachment file name(s) * @param mixed $replyTo Reply to email address(es) * @param mixed $replyToName Reply to name(s) * * @return boolean True on success * * @since 11.1 */ public function sendMail($from, $fromName, $recipient, $subject, $body, $mode = false, $cc = null, $bcc = null, $attachment = null, $replyTo = null, $replyToName = null) { $this->setSubject($subject); $this->setBody($body); // Are we sending the email as HTML? if ($mode) { $this->IsHTML(true); } $this->addRecipient($recipient); $this->addCC($cc); $this->addBCC($bcc); $this->addAttachment($attachment); // Take care of reply email addresses if (is_array($replyTo)) { $numReplyTo = count($replyTo); for ($i = 0; $i < $numReplyTo; $i++) { $this->addReplyTo(array($replyTo[$i], $replyToName[$i])); } } elseif (isset($replyTo)) { $this->addReplyTo(array($replyTo, $replyToName)); } // Add sender to replyTo only if no replyTo received $autoReplyTo = (empty($this->ReplyTo)) ? true : false; $this->setSender(array($from, $fromName, $autoReplyTo)); return $this->Send(); } /** * Sends mail to administrator for approval of a user submission * * @param string $adminName Name of administrator * @param string $adminEmail Email address of administrator * @param string $email [NOT USED TODO: Deprecate?] * @param string $type Type of item to approve * @param string $title Title of item to approve * @param string $author Author of item to approve * @param string $url A URL to included in the mail * * @return boolean True on success * * @since 11.1 */ public function sendAdminMail($adminName, $adminEmail, $email, $type, $title, $author, $url = null) { $subject = JText::sprintf('JLIB_MAIL_USER_SUBMITTED', $type); $message = sprintf(JText::_('JLIB_MAIL_MSG_ADMIN'), $adminName, $type, $title, $author, $url, $url, 'administrator', $type); $message .= JText::_('JLIB_MAIL_MSG') . "\n"; $this->addRecipient($adminEmail); $this->setSubject($subject); $this->setBody($message); return $this->Send(); } } home/academiac/www/administrator/components/com_users/models/mail.php 0000644 00000012457 15140225336 0022203 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; jimport('joomla.application.component.modeladmin'); /** * Users mail model. * * @package Joomla.Administrator * @subpackage com_users * @since 1.6 */ class UsersModelMail extends JModelAdmin { /** * Method to get the row form. * * @param array $data An optional array of data for the form to interogate. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * @return JForm A JForm object on success, false on failure * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Initialise variables. $app = JFactory::getApplication(); // Get the form. $form = $this->loadForm('com_users.mail', 'mail', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } return $form; } /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_users.display.mail.data', array()); return $data; } /** * Override preprocessForm to load the user plugin group instead of content. * * @param object A form object. * @param mixed The data expected for the form. * @throws Exception if there is an error in the form event. * @since 1.6 */ protected function preprocessForm(JForm $form, $data, $group = 'user') { parent::preprocessForm($form, $data, $group); } public function send() { // Initialise variables. $data = JRequest::getVar('jform', array(), 'post', 'array'); $app = JFactory::getApplication(); $user = JFactory::getUser(); $acl = JFactory::getACL(); $db = $this->getDbo(); $mode = array_key_exists('mode', $data) ? intval($data['mode']) : 0; $subject = array_key_exists('subject', $data) ? $data['subject'] : ''; $grp = array_key_exists('group', $data) ? intval($data['group']) : 0; $recurse = array_key_exists('recurse', $data) ? intval($data['recurse']) : 0; $bcc = array_key_exists('bcc', $data) ? intval($data['bcc']) : 0; $disabled = array_key_exists('disabled', $data) ? intval($data['disabled']) : 0; $message_body = array_key_exists('message', $data) ? $data['message'] : ''; // automatically removes html formatting if (!$mode) { $message_body = JFilterInput::getInstance()->clean($message_body, 'string'); } // Check for a message body and subject if (!$message_body || !$subject) { $app->setUserState('com_users.display.mail.data', $data); $this->setError(JText::_('COM_USERS_MAIL_PLEASE_FILL_IN_THE_FORM_CORRECTLY')); return false; } // get users in the group out of the acl $to = $acl->getUsersByGroup($grp, $recurse); // Get all users email and group except for senders $query = $db->getQuery(true); $query->select('email'); $query->from('#__users'); $query->where('id != '.(int) $user->get('id')); if ($grp !== 0) { if (empty($to)) { $query->where('0'); } else { $query->where('id IN (' . implode(',', $to) . ')'); } } if ($disabled == 0){ $query->where("block = 0"); } $db->setQuery($query); $rows = $db->loadColumn(); // Check to see if there are any users in this group before we continue if (!count($rows)) { $app->setUserState('com_users.display.mail.data', $data); if (in_array($user->id, $to)) { $this->setError(JText::_('COM_USERS_MAIL_ONLY_YOU_COULD_BE_FOUND_IN_THIS_GROUP')); } else { $this->setError(JText::_('COM_USERS_MAIL_NO_USERS_COULD_BE_FOUND_IN_THIS_GROUP')); } return false; } // Get the Mailer $mailer = JFactory::getMailer(); $params = JComponentHelper::getParams('com_users'); // Build email message format. $mailer->setSender(array($app->getCfg('mailfrom'), $app->getCfg('fromname'))); $mailer->setSubject($params->get('mailSubjectPrefix') . stripslashes($subject)); $mailer->setBody($message_body . $params->get('mailBodySuffix')); $mailer->IsHTML($mode); // Add recipients if ($bcc) { $mailer->addBCC($rows); $mailer->addRecipient($app->getCfg('mailfrom')); } else { $mailer->addRecipient($rows); } // Send the Mail $rs = $mailer->Send(); // Check for an error if ($rs instanceof Exception) { $app->setUserState('com_users.display.mail.data', $data); $this->setError($rs->getError()); return false; } elseif (empty($rs)) { $app->setUserState('com_users.display.mail.data', $data); $this->setError(JText::_('COM_USERS_MAIL_THE_MAIL_COULD_NOT_BE_SENT')); return false; } else { // Fill the data (specially for the 'mode', 'group' and 'bcc': they could not exist in the array // when the box is not checked and in this case, the default value would be used instead of the '0' // one) $data['mode']=$mode; $data['subject']=$subject; $data['group']=$grp; $data['recurse']=$recurse; $data['bcc']=$bcc; $data['message']=$message_body; $app->setUserState('com_users.display.mail.data', array()); $app->enqueueMessage(JText::plural('COM_USERS_MAIL_EMAIL_SENT_TO_N_USERS', count($rows)), 'message'); return true; } } }
©
2018.