Exemple #1
0
 /** send emails
  * @param bool $showHTML show report on the screen
  * @param object $mailing contain the information of mailing
  * @param objectlist $receivers all receivers
  * @params $type (1-all types of mailings, 2-confirmation email)
  */
 function send($oneQueue, $receiver)
 {
     // we should verify that the data we get is teh proper value
     if (!is_object($oneQueue)) {
         return false;
     }
     $tags = null;
     ### create the mail
     $mail = jNews_ProcessMail::getMailer($oneQueue);
     //$frompreview param is to determine if the sending is called by 'Send Test Email'
     if (empty($mail)) {
         return false;
     }
     $tags['issuenb'] = $oneQueue->issue_nb;
     ### create content
     $this->getContent($oneQueue->images, $oneQueue->htmlcontent, $oneQueue->textonly, $oneQueue->subject, true, false, $oneQueue);
     //new $oneQueue->subject
     if ($this->cancelMailing) {
         $this->cancelMailing = false;
         return true;
         // we return true even though the mail was not sent because empty. Need improvement...
     }
     if (!empty($receiver->user_id)) {
         $tags['user_id'] = $receiver->user_id;
     }
     //Forced HTML Mailing Only?
     if ($GLOBALS[JNEWS . 'forced_html']) {
         $receiver->receive_html = 1;
     }
     $tname = explode(" ", $receiver->name);
     $firstname = $tname[0];
     $toUser = $GLOBALS[JNEWS . 'minisendmail'] ? '' : $receiver->name;
     $mail->AddAddress($receiver->email, $toUser);
     $username = empty($receiver->username) ? $firstname : $receiver->username;
     if (version_compare(JVERSION, '3.0.0', '<')) {
         $date = JHTML::_('date', jnews::getNow(), JText::_('DATE_FORMAT_LC1'), JNEWS_TIME_OFFSET);
     } else {
         $date = JHtml::_('date', jnews::getNow(), JText::_('DATE_FORMAT_LC1'), JNEWS_TIME_OFFSET);
     }
     $replaceWhat = array('{tag:name}', '{tag:firstname}', '{tag:username}', '{tag:date}');
     $replaceBy = array($receiver->name, $firstname, $username, $date);
     $sujetReplaced = str_replace($replaceWhat, $replaceBy, $oneQueue->subject);
     if (class_exists('jNews_Auto')) {
         jNews_Auto::tags($sujetReplaced, $tags);
     }
     $mail->Subject = $sujetReplaced;
     if (!empty($oneQueue->html) && $receiver->receive_html) {
         $this->html = true;
         $mail->IsHTML(true);
         $ashtml = 1;
         $mail->Body = jNews_ProcessMail::replaceTags($oneQueue->htmlcontent, $receiver, $oneQueue, $ashtml, $tags);
         $mail->AltBody = jNews_ProcessMail::replaceTags($oneQueue->textonly, $receiver, $oneQueue, $ashtml, $tags);
         //this line is added when jLinks is integrated with jNews
         //variables used in integration of jLinks
         static $mailCatID = null;
         static $convertedLinks = null;
         if (empty($oneQueue->mailing_type)) {
             $oneQueue->mailing_type = 1;
         }
         $mainframe = JFactory::getApplication();
         JPluginHelper::importPlugin('jnews');
         $jomsocial = $mainframe->triggerEvent('jnewsbot_jomsocial_members', array(&$mail->Body, &$mail->AltBody, $receiver));
         $this->_linkReplacement($oneQueue->mailing_type, $oneQueue->id, $oneQueue->subject, $mail, $mailCatID, $convertedLinks, $receiver->id);
         jNews_ProcessMail::replaceClass($mail->Body, $mail->AltBody, $receiver);
         if (!empty($oneQueue->template_id)) {
             jNews_Templates::includeStyles($mail->Body, $oneQueue->template_id);
         }
     } else {
         //text only email
         $this->html = false;
         $mail->IsHTML(false);
         $mail->AltBody = '';
         $ashtml = 0;
         $mail->Body = jNews_ProcessMail::replaceTags($oneQueue->textonly, $receiver, $oneQueue, $ashtml, $tags);
         $mail->AltBody = $this->_safe_utf8_encode($mail->Body, $mail->CharSet);
         $simpleText = '';
         jNews_ProcessMail::replaceClass($mail->Body, $simpleText, $receiver);
         if (version_compare(JVERSION, '1.6.0', '<')) {
             //j15
             $imgfolders = DS . 'images' . DS . 'stories';
         } else {
             //j16
             $imgfolders = DS . 'images' . DS . 'sampledata';
         }
         if (!empty($oneQueue->images)) {
             foreach ($oneQueue->images as $image) {
                 $img = explode('|', $image);
                 $attrib = explode("/", $img[0]);
                 $path = JNEWS_JPATH_ROOT . $imgfolders;
                 if (count($img) == 1) {
                     $imageName = $img[0];
                 } else {
                     $imageName = $attrib[count($attrib) - 1];
                     for ($index = 0; $index < sizeof($attrib) - 1; $index++) {
                         $path .= $attrib[$index] . '/';
                     }
                 }
                 $mail->AddAttachment($path . $imageName);
             }
             //endofreach
         }
     }
     jNews_ProcessMail::normalizeURL($mail->Body);
     if (!empty($oneQueue->html) && $receiver->receive_html) {
         $this->_addHTMLTagToBody($mail->Body, $sujetReplaced);
     }
     if ($GLOBALS[JNEWS . 'embed_images']) {
         $this->_embedImages($mail);
     }
     $mail->addCustomHeader("X-SubscriberID: " . base64_encode($receiver->email));
     // DKIM code addition by Amod begins
     $mail = $this->_addDKIM2($mail);
     // DKIM code addition by Amod ends
     $status = $mail->Send();
     if (version_compare(JVERSION, '1.6.0', '<')) {
         //j15
         $mailErrorCount = $mail->error_count;
     } else {
         //j16
         $mailErrorCount = !empty($mail->ErrorInfo) ? 1 : 0;
     }
     //we prompt message regarding the status of the sending if there is an error
     if (!empty($mail->ErrorInfo)) {
         echo '<br><span style="color:red;">' . $mail->ErrorInfo . '</span>';
     }
     if ($status && $mailErrorCount < 1) {
         return true;
     } else {
         jNews_ProcessMail::failMailReason($mail);
         return false;
     }
 }
Exemple #2
0
 public static function getMailingView($mailingId, $listId = 0)
 {
     $archivemailing = new stdClass();
     if ($mailingId != 0) {
         if ($listId > 0) {
             $list = jNews_Lists::getOneList($listId);
             $archivemailing = jNews_Mailing::getOneMailing($list, $mailingId, 0, $new);
         } else {
             $archivemailing = jNews_Mailing::getOneMailing(0, $mailingId, 0, $new);
         }
         $mailingtype = JRequest::getInt('listype');
         if ($mailingtype == '7') {
             $db = JFactory::getDBO();
             $query = 'SELECT `delay` FROM `#__jnews_queue` WHERE `type` = 7 AND `mailing_id` = ' . $archivemailing->id;
             $db->setQuery($query);
             $snDelay = $db->loadResult();
             if (!empty($snDelay)) {
                 $myTime = jnews::getNow();
                 $computedDate = jNews_Autonews::computeSmartDate($archivemailing->delay_min, $snDelay, $myTime);
                 //We use the start date to previous the first one
                 $computedDate->lastDate = $archivemailing->start_date;
                 $newMailing = jNews_Autonews::loadSmartContent($archivemailing, $computedDate->lastDate, $snDelay);
                 $archivemailing = !empty($newMailing) ? $newMailing : $archivemailing;
             }
         }
         if ($new) {
             return '';
         } else {
             $mainframe = JFactory::getApplication();
             JPluginHelper::importPlugin('jnews');
             $bot_results = $mainframe->triggerEvent('jnewsbot_transformall', array(&$archivemailing->htmlcontent, &$archivemailing->textonly, &$archivemailing->subject));
             $myReceiver = JFactory::getUser();
             $db = JFactory::getDBO();
             $query = "SELECT A.`id`, A.`receive_html` ";
             //we retreive the extra columns info of the user
             if ($GLOBALS[JNEWS . 'level'] > 2) {
                 //check if the version of jnews is pro
                 if ($GLOBALS[JNEWS . 'show_column1']) {
                     $query .= ', A.`column1`';
                 }
                 if ($GLOBALS[JNEWS . 'show_column2']) {
                     $query .= ',A.`column2`';
                 }
                 if ($GLOBALS[JNEWS . 'show_column3']) {
                     $query .= ',A.`column3`';
                 }
                 if ($GLOBALS[JNEWS . 'show_column4']) {
                     $query .= ',A.`column4`';
                 }
                 if ($GLOBALS[JNEWS . 'show_column5']) {
                     $query .= ',A.`column5`';
                 }
             }
             $query .= " FROM `#__jnews_subscribers` AS A WHERE A.`user_id`=" . $myReceiver->id;
             $db->setQuery($query);
             $myReceiverColumns = $db->loadObject();
             if ($GLOBALS[JNEWS . 'level'] > 2) {
                 //check if the version of jnews is pro
                 if ($GLOBALS[JNEWS . 'show_column1']) {
                     $myReceiver->column1 = $myReceiverColumns->column1;
                 }
                 if ($GLOBALS[JNEWS . 'show_column2']) {
                     $myReceiver->column2 = $myReceiverColumns->column2;
                 }
                 if ($GLOBALS[JNEWS . 'show_column3']) {
                     $myReceiver->column3 = $myReceiverColumns->column3;
                 }
                 if ($GLOBALS[JNEWS . 'show_column4']) {
                     $myReceiver->column4 = $myReceiverColumns->column4;
                 }
                 if ($GLOBALS[JNEWS . 'show_column5']) {
                     $myReceiver->column5 = $myReceiverColumns->column5;
                 }
             }
             $myReceiver->receive_html = !empty($myReceiverColumns->id) ? $myReceiverColumns->receive_html : 1;
             $oneQueue = new stdClass();
             $oneQueue->id = $mailingId;
             $archivemailing->subject = jNews_ProcessMail::replaceTags($archivemailing->subject, $myReceiver, $oneQueue, false, null, false);
             $archivemailing->htmlcontent = jNews_ProcessMail::replaceTags($archivemailing->htmlcontent, $myReceiver, $oneQueue, true);
             preg_match_all('/<img([^>]*)src="([^">]+)"([^>]*)>/i', $archivemailing->htmlcontent, $images, PREG_SET_ORDER);
             if (version_compare(JVERSION, '1.6.0', '<')) {
                 //j15
                 $imgfolders = '/images/stories';
             } else {
                 //j16
                 $imgfolders = '/images/sampledata';
             }
             foreach ($images as $image) {
                 $image[2] = preg_replace('/(\\.\\.\\/)+/', '/', $image[2]);
                 $image[2] = str_replace(array(JNEWS_JPATH_LIVE, JNEWS_JPATH_LIVE_NO_HTTPS), '', $image[2]);
                 $image[2] = preg_replace('/^\\//', '', $image[2]);
                 if (stristr($image[2], 'http://') === false) {
                     // remove unneeded directory information
                     if (stristr($image[2], $imgfolders) !== false) {
                         $image[2] = '/' . stristr($image[2], $imgfolders);
                     }
                     // end if
                     $replacement = '<img ' . $image[1] . 'src="' . JNEWS_JPATH_LIVE_NO_HTTPS . $image[2] . '"' . $image[3] . '>';
                 } else {
                     $replacement = '<img ' . $image[1] . 'src="' . $image[2] . '"' . $image[3] . '>';
                 }
                 // end if
             }
         }
     }
     return $archivemailing;
 }