linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file template_newsletter.php

Documentation is available at template_newsletter.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage mail
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11.  
  12. /**
  13.  * absolute_url
  14.  * http://www.howtoforge.com/forums/showthread.php?t=4
  15.  * @param $txt 
  16.  * @param $base_url 
  17.  */
  18. function absolute_url($txt$base_url{
  19.   $needles array('href="''src="''background="');
  20.   $new_txt '';
  21.   if(substr($base_url,-1!= '/'$base_url .= '/';
  22.   $new_base_url $base_url;
  23.   $base_url_parts parse_url($base_url);
  24.  
  25.   foreach($needles as $needle){
  26.     while($pos strpos($txt$needle)){
  27.       $pos += strlen($needle);
  28.       if(substr($txt,$pos,7!= 'http://' && substr($txt,$pos,8!= 'https://' && substr($txt,$pos,6!= 'ftp://' && substr($txt,$pos,7!= 'mailto:'){
  29.         if(substr($txt,$pos,1== '/'$new_base_url $base_url_parts['scheme'].'://'.$base_url_parts['host'];
  30.         $new_txt .= substr($txt,0,$pos).$new_base_url;
  31.       else {
  32.         $new_txt .= substr($txt,0,$pos);
  33.       }
  34.       $txt substr($txt,$pos);
  35.     }
  36.     $txt $new_txt.$txt;
  37.     $new_txt '';
  38.   }
  39.   return $txt;
  40. }
  41.  
  42. require_once '../lib/vendor/swift/lib/swift_required.php';
  43.  
  44. // We create the Transport
  45. if (defined('MAIL_MAILER')) {
  46.     
  47.     // by default
  48.     $transport Swift_MailTransport::newInstance();
  49.  
  50.     // sendmail
  51.     if(MAIL_MAILER=='sendmail'{
  52.         
  53.         $transport Swift_SendmailTransport::newInstance(MAIL_SENDMAIL);
  54.         
  55.     }
  56.     // smtp
  57.     if(MAIL_MAILER=='smtp'{
  58.         if(defined('MAIL_SMTP_AUTH'&& MAIL_SMTP_AUTH == 1{
  59.             
  60.             $transport Swift_SmtpTransport::newInstance(MAIL_HOSTMAIL_PORT)
  61.             ->setUsername(MAIL_SMTP_USER)
  62.             ->setPassword(MAIL_SMTP_PASS);
  63.             
  64.         else {
  65.             
  66.             $transport Swift_SmtpTransport::newInstance(MAIL_HOSTMAIL_PORT);
  67.             
  68.         }
  69.  
  70.     }
  71.     
  72. }
  73.  
  74. // Create the Mailer using the Transport
  75. $mailer Swift_Mailer::newInstance($transport);
  76.  
  77. /**
  78.  echo "destinataire : ".$email_recipient."<br />";
  79.  echo "sujet : ".$email_subject."<br />";
  80.  echo "body : ".$email_html_body."<br />";
  81.  echo "methode : ".$email_method."<br />";
  82.  echo "host : ".$mail->Host."<br />";
  83.  echo "port : ".$mail->Port."<br />";
  84.  */
  85.  
  86. for($i 0;$i count($newsletters)$i++{
  87.   $newsletter_id $newsletters[$i]['newsletter_id'];
  88.   $email_subject formatText($newsletters[$i]['newsletter_title']'2HTML');
  89.   
  90.  
  91.   $newsletter_body_html formatText($newsletters[$i]['newsletter_body']'2HTML');
  92.   preg_replace("/(<\s*(a|img)\s+[^>]*(href|src)\s*=\s*[\"'])(?!http)([^\"'>]+)[\"'>]/""$1".CURRENT_APP_URL."$4"$newsletter_body_html);
  93.   $email_html_body=str_replace('##TITLE##'$email_subject$template_html);
  94.   $email_html_body=str_replace('##CHARSET##'CHARSET$email_html_body);
  95.   $email_html_body=str_replace('##CONTENTS##'$newsletter_body_html$email_html_body);
  96.   $email_html_body=str_replace('##SITENAME##'SITE_NAME$email_html_body);
  97.   $email_html_body=str_replace('##CSSPATH##'SITE_ROOT_URLTHEME_DIRECTORY.'/public/'.THEME_PUBLIC.'/css/'$email_html_body);
  98.   $email_html_body=str_replace('##SITEURL##'SITE_ROOT_URL$email_html_body);
  99.   $email_html_body=str_replace('##SITEMAIL##'SITE_MAIL$email_html_body);
  100.   $email_html_body=absolute_url($email_html_bodySITE_ROOT_URL);
  101.  
  102.   $newsletter_body_txt formatText($newsletters[$i]['newsletter_body']);
  103.   $email_text_body=str_replace('##TITLE##'strip_tags(formatText($email_subject))$template_txt);
  104.   $email_text_body=str_replace('##CONTENTS##'strip_tags(formatText($newsletter_body_txt))$email_text_body);
  105.   $email_text_body=str_replace('##SITENAME##'SITE_NAME$email_text_body);
  106.   $email_text_body=str_replace('##SITEURL##'SITE_ROOT_URL$email_text_body);
  107.   $email_text_body=str_replace('##SITEMAIL##'SITE_MAIL$email_text_body);
  108.   $email_text_body=absolute_url($email_text_bodySITE_ROOT_URL);
  109.   
  110.   
  111.   isset($email_from$from $email_from $from MAIL_FROM;
  112.   isset($email_fromname$fromname $email_fromname $fromname MAIL_FROMNAME;
  113.   $altbody str_replace('&amp;''&'$email_text_body);
  114.   
  115.  
  116.  
  117.   // Create a message instance
  118.   $message Swift_Message::newInstance($email_subject)
  119.   ->setFrom(array($from => $fromname))
  120.   ->setReplyTo(array(MAIL_REPLY => MAIL_REPLYNAME)) ;
  121.  
  122.   for($k 0$k count($emails_batch)$k++{
  123.     $email_id $emails_batch[$k]['emailcol_id'];
  124.     $email_recipient $emails_batch[$k]['emailcol_email'];
  125.     
  126.     // we create the link to unsubscribe newsletter and add it to the message
  127.     $unsubscribe_urlSITE_ROOT_URL.'public/index.php?rub='.$GLOBALS['links'][U_L]['subscribe-newsletter']['linkvalue'].'&del_action=on&newsletteremail='.$email_recipient;
  128.     $unsubscribe_link_html sprintf(_t('newsletter''unsubscribe_html')$unsubscribe_url);
  129.     $unsubscribe_link_txt _t('newsletter''unsubscribe_txt')' '$unsubscribe_url;
  130.     
  131.     $email_html_body=str_replace('##UNSUBSCRIBE_LINK##'$unsubscribe_link_html$email_html_body);
  132.     $email_text_body=str_replace('##UNSUBSCRIBE_LINK##'$unsubscribe_link_txt$email_text_body);
  133.     
  134.     // finish message settings
  135.     $message->setBody($email_html_body'text/html')->addPart($altbody'text/plain')->setTo($email_recipient);
  136.         $r $mailer->Send($message$failures);
  137.         
  138.         if(!$r
  139.             $logmsg 'not sent';
  140.         else {
  141.             $logmsg 'sent';
  142.         }
  143.         
  144.         logfile(LOG_MAILINGarray($email_subject$newsletter_id$email_recipient$logmsg));
  145.         
  146.   }
  147.   
  148.   if(!isset($doNotPublish)) $newsletter_object->SetNewsletterPublished($newsletter_id$sql_object);
  149. }
  150.  
  151. ?>

Documentation generated on Thu, 20 Mar 2014 16:49:35 +0100 by phpDocumentor 1.4.1