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 to put the CSS in the mailing
  * @param string $body
  * @param int $templateId
  */
 public static function includeStyles(&$body, $templateId)
 {
     static $checkMe = true;
     $body = preg_replace('#< *(tr|td|table)([^>]*)(style="[^"]*)background-image *: *url\\(\'?([^)\']*)\'?\\);?#Ui', '<$1 background="$4" $2 $3', $body);
     jNews_ProcessMail::normalizeURL($body);
     $body = preg_replace('#< *img([^>]*)(style="[^"]*)(float *: *)(right|left|top|bottom|middle)#Ui', '<img$1 align="$4" hspace="5" $2$3$4', $body);
     //load template
     $template = jNews_Templates::loadOneTemplate('*', $templateId);
     $template->csstyle = jNews_Templates::cleanCSSComments($template->csstyle);
     if (!empty($template->styles) || !empty($template->csstyle)) {
         $csstyle = jNews_Templates::convertCSSInline($template->styles, $template->csstyle);
     }
     $themeCSS = array();
     if (!empty($template->styles)) {
         foreach ($template->styles as $cName => $sContent) {
             if ($cName != 'color_bg') {
             } elseif (preg_match('#^tag_(.*)$#', $cName, $result)) {
                 $mainStyle['#< *' . $result[1] . '((?:(?!style).)*)>#Ui'] = '<' . $result[1] . ' style="' . $sContent . '" $1>';
             } else {
                 $themeCSS['class="' . $cName . '"'] = 'style="' . $sContent . '"';
             }
         }
     }
     if (!empty($mainStyle)) {
         $body = preg_replace(array_keys($mainStyle), $mainStyle, $body);
     }
     if (!empty($themeCSS)) {
         $body = str_replace(array_keys($themeCSS), $themeCSS, $body);
     }
     if (!empty($template->styles['color_bg'])) {
         $pattern1 = '#^([^<]*<[^>]*background-color:)([^;">]{1,10})#i';
         $found = false;
         if (preg_match($pattern1, $body)) {
             $body = preg_replace($pattern1, '$1' . $template->styles['color_bg'], $body);
             $found = true;
         }
         $pattern2 = '#^([^<]*<[^>]*bgcolor=")([^;">]{1,10})#i';
         if (preg_match($pattern2, $body)) {
             $body = preg_replace($pattern2, '$1' . $template->styles['color_bg'], $body);
             $found = true;
         }
         if (!$found) {
             $body = '<div style="background-color:' . $template->styles['color_bg'] . ';" width="100%">' . $body . '</div>';
         }
     }
     if ($checkMe) {
         if (version_compare(PHP_VERSION, '5.0.0', '>=') && class_exists('DOMDocument') && function_exists('mb_convert_encoding')) {
             require_once JNEWS_PATH_INCLUDES . 'emogrifier' . DS . 'emogrifier.php';
         }
         $checkMe = false;
     }
     if (!empty($csstyle) && class_exists('Emogrifier')) {
         $emogrifier = new Emogrifier($body, $csstyle);
         $body = $emogrifier->emogrify();
         if (strpos($body, '<!DOCTYPE') !== false) {
             $body = preg_replace('#<\\!DOCTYPE.*<body([^>]*)>#Usi', '', $body);
             $body = preg_replace('#</body>.*$#si', '', $body);
         }
     }
 }