PageRenderTime 68ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_jnewsletter/classes/class.jmail.php

https://github.com/viollarr/alab
PHP | 1365 lines | 1081 code | 207 blank | 77 comment | 240 complexity | 8933a19a03d9567a7f90738f282f7e3b MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, AGPL-3.0, Apache-2.0, BSD-3-Clause, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. defined('_JEXEC') OR defined('_VALID_MOS') OR die('...Direct Access to this location is not allowed...');
  3. ### Copyright (C) 2006-2010 Joobi Limited. All rights reserved.
  4. ### http://www.ijoobi.com/index.php?option=com_content&view=article&id=12&Itemid=54
  5. class jnewsletter_mail {
  6. function embedImages(&$mail){
  7. $normalAttachment = array();
  8. $a = 0;
  9. for($i = 0; $i < count($mail->attachment); $i++) {
  10. if($mail->attachment[$i][6] != 'inline') {
  11. $normalAttachment[$a] = $mail->attachment[$i];
  12. $a++;
  13. }
  14. }
  15. $mail->attachment = $normalAttachment;
  16. $mimetypes = array('bmp' => 'image/bmp',
  17. 'gif' => 'image/gif',
  18. 'jpeg' => 'image/jpeg',
  19. 'jpg' => 'image/jpeg',
  20. 'jpe' => 'image/jpeg',
  21. 'png' => 'image/png',
  22. 'tiff' => 'image/tiff',
  23. 'tif' => 'image/tiff');
  24. preg_match_all("/(src|background)=\"(.*)\"/Ui", $mail->Body, $images);
  25. $result = true;
  26. if(isset($images[2])) {
  27. $imagespath = array();
  28. foreach($images[2] as $i => $url) {
  29. $path = str_replace(ACA_JPATH_LIVE,ACA_JPATH_ROOT_NO_ADMIN,$url);
  30. if(isset($imagespath[$path])) continue;
  31. $imagespath[$path] = 1;
  32. $filename = basename($url);
  33. $md5 = md5($filename);
  34. $cid = 'cid:' . $md5;
  35. $fileParts = split("\.", $filename);
  36. $ext = $fileParts[1];
  37. //We don't embed php files... it can be the stat picture for example
  38. if(!isset($mimetypes[$ext])) continue;
  39. $mimeType = $mimetypes[$ext];
  40. //We only change the url if we were able to embed the image.
  41. //Otherwise we return false and display a warning
  42. if($mail->AddEmbeddedImage($path, $md5, $filename, 'base64', $mimeType)){
  43. $mail->Body = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $mail->Body);
  44. }else{
  45. $result = false;
  46. }
  47. }
  48. }
  49. return $result;
  50. }
  51. function replaceTags($content, $subscriber, $list, $mailingId, $html, $tags=null) {
  52. $Itemid = $GLOBALS[ACA.'itemidAca'];
  53. $listId = $list->id; //can be empty
  54. $subscriptionslink = '.php?option=com_jnewsletter&Itemid='.$Itemid.'&act=change&subscriber=' . $subscriber->id . '&cle=' . md5($subscriber->email). '&listid=' . $listId;
  55. $unsubscribelink = '.php?option=com_jnewsletter&Itemid='.$Itemid.'&act=unsubscribe&subscriber=' . $subscriber->id . '&cle=' . md5($subscriber->email) . '&listid=' . $listId;
  56. $subscriptiontext='';
  57. compa::completeLink($subscriptionslink,false,$GLOBALS[ACA.'use_sef']);
  58. compa::completeLink($unsubscribelink,false,$GLOBALS[ACA.'use_sef']);
  59. if($html) {
  60. $subscriptionslink = '<a href="' . $subscriptionslink . '" target="_blank"><span class="aca_subscribe">' . _ACA_CHANGE_EMAIL_SUBSCRIPTION . '</span></a>';
  61. $unsubscribelink = '<a href="' . $unsubscribelink . '" target="_blank"><span class="aca_unsubscribe">' . _ACA_UNSUBSCRIBE . '</span></a>';
  62. $subscriptionstext = '<p>'. $subscriptionslink . '<br />' . $unsubscribelink . '</p>';
  63. } else {
  64. $subscriptionslink = _ACA_CHANGE_EMAIL_SUBSCRIPTION . ' ( ' . $subscriptionslink . ' )';
  65. $unsubscribelink = _ACA_UNSUBSCRIBE . ' ( ' . $unsubscribelink . ' )';
  66. $subscriptionstext = "\r\n" . $subscriptionslink . "\r\n" . $unsubscribelink;
  67. }
  68. $subscriptionstext = '';
  69. if ($GLOBALS[ACA.'show_signature']) {
  70. if($html) {
  71. $signatureText ='<a href="http://www.ijoobi.com" target="_blank">';
  72. $signatureText .='<br /><center><div style="width: 99%; color:#FFF; background-color:#000; font-size: 0.8em; text-align: center; ">Powered by Joobi</div></center>';
  73. $signatureText .='</a>';
  74. } else {
  75. $signatureText ='Powered by Joobi ( http://www.ijoobi.com )';
  76. }
  77. $subscriptionstext .= "\r\n\r\n" . $signatureText;
  78. }
  79. $confirmlink = '.php?option=com_jnewsletter&act=confirm&listid=' . $listId . '&cle=' . md5($subscriber->email) . '&subscriber=' . $subscriber->id.'&Itemid='.$Itemid;
  80. compa::completeLink($confirmlink,false,$GLOBALS[ACA.'use_sef']);
  81. if ($html) $confirmlink = '<a href="' . $confirmlink . '" target="_blank">' . _ACA_CONFIRM_LINK . '</a>';
  82. else $confirmlink = _ACA_CONFIRM_LINK . "\n" . $confirmlink;
  83. $tname = explode(" ", $subscriber->name);
  84. $firstname = $tname[0];
  85. $username = empty($subscriber->username) ? $firstname : $subscriber->username;
  86. $archiveLink = '.php?option=com_jnewsletter&act=mailing&task=view&mailingid='.$mailingId.'&Itemid='.$Itemid;
  87. compa::completeLink($archiveLink,false,$GLOBALS[ACA.'use_sef']);
  88. $archiveAll = '<a href="'.$archiveLink.'">'._ACA_VIEWARCHIVE.'</a>';
  89. $replaceWhat = array('[CONFIRM]','[NAME]','[FIRSTNAME]','[EMAIL]','[DATE]','[USERNAME]','[LINK]','[ARCHIVE]', '[SUBSCRIPTIONS]', '[UNSUBSCRIBE]');
  90. if($GLOBALS[ACA.'type']=='PRO'){//check if the version of jnewsletter is pro
  91. $replaceWhat[] = '[COLUMN1]';
  92. $replaceWhat[] = '[COLUMN2]';
  93. $replaceWhat[] = '[COLUMN3]';
  94. $replaceWhat[] = '[COLUMN4]';
  95. $replaceWhat[] = '[COLUMN5]';
  96. }//endif check if the version of jnewsletter is pro
  97. if ( ACA_CMSTYPE ) {
  98. $replaceBy = array($confirmlink,$subscriber->name,$firstname,$subscriber->email,JHTML::_('date',jnewsletter::getNow(), JText::_('DATE_FORMAT_LC1'), 0),$username,$archiveLink,$archiveAll,$subscriptionslink,$unsubscribelink);
  99. } else {
  100. $replaceBy = array($confirmlink,$subscriber->name,$firstname,$subscriber->email,mosFormatDate(jnewsletter::getNow(), '', 0),$username,$archiveLink,$archiveAll,$subscriptionslink,$unsubscribelink);
  101. }
  102. if($GLOBALS[ACA.'type']=='PRO'){//check if the version of jnewsletter is pro
  103. $replaceBy[] = $subscriber->column1;
  104. $replaceBy[] = $subscriber->column2;
  105. $replaceBy[] = $subscriber->column3;
  106. $replaceBy[] = $subscriber->column4;
  107. $replaceBy[] = $subscriber->column5;
  108. }//endif for check version
  109. $content = str_replace($replaceWhat,$replaceBy, $content );
  110. if ( class_exists('auto') ) {
  111. auto::tags( $content, $tags );
  112. }
  113. $content = stristr($signatureText, 'Powered by Joobi') !== FALSE ? $content : $content.$subscriptionstext;
  114. if (class_exists('aca_tags') AND $tags) aca_tags::replace($content, $tags);
  115. if ( !empty($mailingId) AND $GLOBALS[ACA.'enable_statistics'] == 1 ) {
  116. if ($GLOBALS[ACA.'statistics_per_subscriber'] == 1) {
  117. if($html) $content .= '<img src="' . ACA_JPATH_LIVE_NO_HTTPS . '/index.php?option=com_jnewsletter&Itemid='.$Itemid.'&act=log&listid=' . $listId . '&mailingid=' . $mailingId . '&subscriber=' . $subscriber->id . '" border="0" width="1" height="1" />';
  118. } else {
  119. if ($html) $content .= '<img src="' . ACA_JPATH_LIVE_NO_HTTPS . '/index.php?option=com_jnewsletter&Itemid='.$Itemid.'&act=log&listid=' . $listId . '&mailingid=' . $mailingId . '" border="0" width="1" height="1" />';
  120. }
  121. }
  122. // replace for images
  123. // put the good mailto tag back (replaced before the content mambot)
  124. $replaceTag = array('href="mailto:','@','href="#');
  125. $replaceBy = array('9aca7aca5','9aca4aca1','9aca12aca3');
  126. $content = str_replace($replaceTag,$replaceBy,$content);
  127. $content = preg_replace('#src[ ]*=[ ]*\"(?!https?://)(?:\.\./|\./|/)?#','src="'.ACA_JPATH_LIVE_NO_HTTPS.'/',$content);
  128. $content = preg_replace('#href[ ]*=[ ]*\"(?!https?://)(?:\.\./|\./|/)?#','href="'.ACA_JPATH_LIVE_NO_HTTPS.'/',$content);
  129. $content = str_replace($replaceBy,$replaceTag,$content);
  130. $content = preg_replace('#\.(jpg|gif|jpeg|png)(?:(?!").)?"#', '.\\1"', $content);
  131. if (!$html) $content = str_replace('&amp;', '&', $content);
  132. return $content;
  133. }
  134. function htmlToText($textonly) {
  135. $textonly = str_replace(array('<p>', '<P>'), "", $textonly);
  136. $textonly =preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $textonly);
  137. $returns = array('<img />','<table>','</table>','<tbody>','</tbody>','<tr>','</tr>','<td>','</td>','<div>','</div>','<br>', '<br/>', '<br />', '<br >','<BR >', '<BR>', '<BR/>', '<BR />', '</p>', '</P>', '<p />', '<p/>', '<P />', '<P/>','<h1>','</h1>','<H1>','</H1>','<h2>', '</h2>','<H2>', '</H2>','<h3>','</h3>','<H3>', '</H3>','<h4>', '</h4>','<H4>', '</H4>','<h5>', '</h5>','<H5>', '</H5>', '<h6>', '</h6>','<H6>', '</H6>');
  138. $textonly = str_replace($returns, " ", $textonly);
  139. $textonly = preg_replace('/<a href="([^"]*)"[^>]*>([^<]*)<\/a>/i','${2} ( ${1} )', $textonly);
  140. $textonly = preg_replace('/<head>.*<\/head>/i', '', $textonly);
  141. $textonly = preg_replace('~&#x([0-9a-f]+);~ei', chr(hexdec("\\1")), $textonly);
  142. $textonly = preg_replace('~&#([0-9]+);~e', chr("\\1"), $textonly);
  143. $trans_tbl = get_html_translation_table(HTML_ENTITIES);
  144. $trans_tbl = array_flip($trans_tbl);
  145. $textonly = strtr($textonly, $trans_tbl);
  146. $textonly = strip_tags($textonly);
  147. $textonly= trim($textonly);
  148. return $textonly;
  149. }
  150. function getMailer($mailing, $html=0) {
  151. $fromname = $mailing->fromname;
  152. $fromemail = trim($mailing->fromemail);
  153. $frombounce = empty($mailing->frombounce) ? trim($GLOBALS[ACA.'confirm_return']) : trim($mailing->frombounce);
  154. $attachments = $mailing->attachments;
  155. $images = $mailing->images;
  156. if ( ACA_CMSTYPE ) { // joomla 15
  157. $conf =& JFactory::getConfig();
  158. $frombounceName = $fromname ? $fromname : $conf->getValue('config.fromname');
  159. if(empty($fromemail)) $fromemail = trim($conf->getValue('config.mailfrom'));
  160. if(empty($fromname)) $fromname = trim($conf->getValue('config.fromname'));
  161. } //endif
  162. if (ACA_CMSTYPE) {
  163. jimport('joomla.mail.mail');
  164. $phpmailerPath = JPATH_LIBRARIES.DS.'phpmailer'.DS;
  165. $mail = new JMail();
  166. } //endif
  167. $mail->PluginDir = $phpmailerPath ;
  168. $mail->SetLanguage('en', $phpmailerPath.'language'.DS);
  169. $mail->WordWrap = 150;
  170. $mail->addCustomHeader("X-Mailer: ".ACA_JPATH_LIVE);
  171. $mail->addCustomHeader("X-MessageID: $mailing->id");
  172. if ( $GLOBALS[ACA.'mail_format'] =='1' ) $mail->Encoding = 'base64';
  173. if($GLOBALS[ACA.'minisendmail']) $frombounceName = '';
  174. if(ACA_CMSTYPE){
  175. $mail->addReplyTo(array($frombounce, $frombounceName));
  176. }//endif
  177. $mail->From = trim($fromemail);
  178. if($GLOBALS[ACA.'minisendmail']){
  179. $mail->FromName = '';
  180. }else{
  181. $mail->FromName = $fromname;
  182. }
  183. $mail->Sender = trim($GLOBALS[ACA.'sendmail_from']);
  184. if(empty($mail->Sender)) $mail->Sender = '';
  185. switch ($GLOBALS[ACA.'emailmethod']){
  186. case 'mail' :
  187. $mail->IsMail();
  188. break;
  189. case 'sendmail':
  190. $mail->IsSendmail();
  191. if ( ACA_CMSTYPE ) { // joomla 15
  192. $conf =& JFactory::getConfig();
  193. $mail->Sendmail = $GLOBALS[ACA.'sendmail_path'] ? $GLOBALS[ACA.'sendmail_path'] : $conf->getValue('config.sendmail');
  194. } //endif
  195. break;
  196. case 'smtp':
  197. $mail->IsSMTP();
  198. if ( ACA_CMSTYPE ) { // joomla 15
  199. $conf =& JFactory::getConfig();
  200. $mail->Host = $GLOBALS[ACA.'smtp_host'] ? $GLOBALS[ACA.'smtp_host'] : $conf->getValue('config.smtphost');
  201. } //endif
  202. if((boolean)$GLOBALS[ACA.'smtp_auth_required']) {
  203. $mail->SMTPAuth = $GLOBALS[ACA.'smtp_auth_required'];
  204. $mail->Password = $GLOBALS[ACA.'smtp_password'];
  205. $mail->Username = $GLOBALS[ACA.'smtp_username'];
  206. }
  207. break;
  208. default:
  209. if ( ACA_CMSTYPE ) { // joomla 15
  210. $conf =& JFactory::getConfig();
  211. $mail->Mailer = $conf->getValue('config.mailer');
  212. } //endif
  213. break;
  214. }
  215. if (!empty($attachments)) {
  216. foreach ($attachments AS $attachment) {
  217. if(basename($attachment) !== 'index.html'){
  218. $mail->AddAttachment(ACA_JPATH_ROOT_NO_ADMIN . $GLOBALS[ACA.'upload_url'].DS.basename($attachment));
  219. }
  220. }
  221. }
  222. switch( substr( strtoupper( PHP_OS ), 0, 3 ) ) {
  223. case "WIN":
  224. $mail->LE = "\r\n";
  225. break;
  226. case "MAC":
  227. case "DAR":
  228. $mail->LE = "\r";
  229. default:
  230. break;
  231. }
  232. return $mail;
  233. }
  234. function getContent($images, $layout, &$content, &$textonly, $send = false) {
  235. $replaceTag = array('href="mailto:','@','href="#');
  236. $replaceBy = array('9aca7aca5','9aca4aca1','9aca12aca3');
  237. $content = str_replace($replaceTag,$replaceBy,$content);
  238. $content = str_replace('{mospagebreak}', '<br style="clear: both;" /><br />', $content);
  239. if (strlen(trim($textonly)) < 2 && $send) {
  240. $textonly = jnewsletter_mail::htmlToText($content);
  241. $textonly = str_replace('{mosimage}', '', $textonly);
  242. }
  243. if (!empty($images)) {
  244. foreach ($images as $image) {
  245. $image_string = '<img src="' . ACA_JPATH_LIVE . '/images/stories/' . $image. '" />';
  246. $content = preg_replace('/{mosimage}/', $image_string, $content, 1);
  247. }
  248. }
  249. if (ACA_CMSTYPE) {
  250. global $mainframe;
  251. JPluginHelper::importPlugin( 'jnewsletter' );
  252. $bot_results = $mainframe->triggerEvent('jnewsletterbot_transformall', array(&$content, &$textonly));
  253. } //endif
  254. $content = str_replace($replaceTag,$replaceBy,$content);
  255. $content = preg_replace('#src[ ]*=[ ]*\"(?!https?://)(?:\.\./|\./|/)?#','src="'.ACA_JPATH_LIVE_NO_HTTPS.'/',$content);
  256. $content = preg_replace('#href[ ]*=[ ]*\"(?!https?://)(?:\.\./|\./|/)?#','href="'.ACA_JPATH_LIVE_NO_HTTPS.'/',$content);
  257. $content = str_replace($replaceBy,$replaceTag,$content);
  258. return true;
  259. }
  260. //Checking by eve
  261. function send( $showHTML, $mailing, $receivers, $list, &$message, $tags=null ) {
  262. $h = '';
  263. $xf = new xonfig();
  264. if (empty($mailing)) {
  265. $message = _ACA_NO_MAILING_ENTERED;
  266. return false;
  267. } elseif ( empty($receivers) ) {
  268. $message = _ACA_NO_ADDRESS_ENTERED;
  269. return false;
  270. } elseif ( empty($list) ) {
  271. $message = _ACA_NO_LIST_ENTERED;
  272. return false;
  273. } else {
  274. $message = '';
  275. }
  276. $mailingId = $mailing->id;
  277. $issue_nb = $mailing->issue_nb;
  278. $subject = $mailing->subject;
  279. $content = $mailing->htmlcontent;
  280. $textonly = $mailing->textonly;
  281. $fromname = $mailing->fromname;
  282. $fromemail = $mailing->fromemail;
  283. $images = $mailing->images;
  284. $listId = $list->id;
  285. $html = $list->html;
  286. $layout = $list->layout;
  287. $totalsofar = number_format(0, 4, ',', '');
  288. $nbPause = 0;
  289. $tags['issuenb'] = $issue_nb;
  290. $template_id = $mailing->template_id;
  291. if (!ini_get('safe_mode')) {
  292. @set_time_limit(60 * $GLOBALS[ACA.'script_timeout']);
  293. @ini_set('memory_limit','128M');
  294. }
  295. ignore_user_abort(true);
  296. ### create the mail
  297. $mail = jnewsletter_mail::getMailer($mailing);
  298. ### create content
  299. jnewsletter_mail::getContent($images, $layout, $content, $textonly, true);
  300. $mtime = microtime();
  301. $mtime = explode(" ",$mtime);
  302. $mtime = $mtime[1] + $mtime[0];
  303. $starttime = $mtime;
  304. $html_sent = 0;
  305. $text_sent = 0;
  306. $size = sizeof($receivers);
  307. $i = 0;
  308. ?>
  309. <form action="index2.php" method="post" name="adminForm">
  310. <input type="hidden" name="option" value="com_jnewsletter" />
  311. <input type="hidden" name="act" value="mailing" />
  312. <input type="hidden" name="listype" value="<?php echo $mailing->mailing_type; ?>" />
  313. <input type="hidden" name="task" value="" />
  314. </form>
  315. <?php
  316. if ( $showHTML ) {
  317. echo '<form action="#" name="counterForm">';
  318. echo _ACA_SENDING_EMAIL;
  319. echo ': &nbsp;<input type="text" size="6" name="teller" value="0" style="border: 0px solid white; font-family: Arial, Helvetica, sans-serif; font-size: 1.1em;" size="1" /> of ' . $size . '</form>';
  320. }
  321. $garde = 0;
  322. //If two errors occur, we stop to try
  323. while (ob_get_level() > 0 AND $garde < 2) {
  324. if(!ob_end_flush()){
  325. $garde++;
  326. }
  327. }
  328. if ( ACA_CMSTYPE ) { // joomla 15
  329. $skip_subscribers = @$_SESSION['skip_subscribers'.$mailing->id];
  330. } //endif
  331. $format = defined('_DATE_FORMAT_LC') ? _DATE_FORMAT_LC : JText::_('DATE_FORMAT_LC');
  332. $log_detailed = "\r\n" ."\r\n" .'*** '.strftime($format).' ***'."\r\n";
  333. if(empty($skip_subscribers)){
  334. if ( ACA_CMSTYPE ) { // joomla 15
  335. $skip_subscribers = JRequest::getVar('skip_subscribers', '0' );
  336. } //endif
  337. }
  338. $nbsubscribers = count($receivers);
  339. //variables used in integration of jLinks
  340. $mailCatID = null;
  341. $convertedLinks = null;
  342. foreach ($receivers as $receiver) {
  343. $i++;
  344. if ($i <= $skip_subscribers) {
  345. continue;
  346. }
  347. $tags['user_id'] = $receiver->user_id;
  348. if ($html && (intval($receiver->receive_html) == 1)) {
  349. $mail->IsHTML(true);
  350. $ashtml = 1;
  351. $Altbody = jnewsletter_mail::replaceTags($textonly, $receiver, $list, $mailingId, 0, $tags);
  352. $mail->AltBody = jnewsletter_mail::safe_utf8_encode( $Altbody, $mail->CharSet );
  353. $html_sent++;
  354. $mail->Body = jnewsletter_mail::replaceTags($content, $receiver, $list, $mailingId, $ashtml, $tags);
  355. //this line is added when jLinks is integrated with jNews
  356. jnewsletter_mail::linkReplacement( $mailing->mailing_type, $list, $mailingId, $mailing->subject, $mail,
  357. $mailCatID, $convertedLinks, $receiver->id );
  358. //jnewsletter_mail::replaceClass($mail->Body,$mail->AltBody,$receiver);
  359. $styles = templates::getTemplateStyles($template_id);
  360. $mail->Body = templates::insertStyles($mail->Body,$mail->AltBody, $styles);
  361. } else {
  362. $mail->IsHTML(false);
  363. $mail->AltBody = '';
  364. $ashtml = 0;
  365. $text_sent++;
  366. $mail->Body = jnewsletter_mail::replaceTags($textonly, $receiver, $list, $mailingId, $ashtml, $tags);
  367. $simpleText = '';
  368. //jnewsletter_mail::replaceClass($mail->Body,$simpleText,$receiver);
  369. if( !empty($images) ) {
  370. foreach( $images as $image) {
  371. $img = explode('|', $image);
  372. $attrib = explode("/", $img[0]);
  373. $path = ACA_JPATH_ROOT. '/images/stories/';
  374. if (count($img)==1) {
  375. $imageName = $img[0];
  376. } else {
  377. $imageName = $attrib[count($attrib)-1];
  378. for ($index = 0; $index < (sizeof($attrib)-1); $index++) {
  379. $path .= $attrib[$index].'/';
  380. }
  381. }
  382. $mail->AddAttachment( $path.$imageName);
  383. }
  384. }
  385. }
  386. $tname = explode(" ", $receiver->name);
  387. $firstname = $tname[0];
  388. $toUser = $GLOBALS[ACA.'minisendmail'] ? '' : $receiver->name;
  389. $mail->AddAddress($receiver->email,$toUser);
  390. $username = empty($receiver->username) ? $firstname : $receiver->username;
  391. $date = ACA_CMSTYPE ? JHTML::_('date',jnewsletter::getNow(), JText::_('DATE_FORMAT_LC1'), 0) : mosFormatDate(jnewsletter::getNow(), '', 0);
  392. $replaceWhat = array('[NAME]','[FIRSTNAME]','[USERNAME]','[DATE]');
  393. $replaceBy = array($receiver->name,$firstname,$username,$date);
  394. $sujetReplaced = str_replace($replaceWhat, $replaceBy, $subject);
  395. if ( class_exists('auto') ) auto::tags( $sujetReplaced, $tags );
  396. $mail->Subject = $sujetReplaced;
  397. if($GLOBALS[ACA.'embed_images']){
  398. jnewsletter_mail::embedImages($mail);
  399. }
  400. $mailssend = $mail->Send();
  401. if ($showHTML) echo '<br /><strong>'.$i . ': ';
  402. if (!$mailssend || $mail->error_count > 0) {
  403. $h .= $receiver->email . '</strong> -> ' . xmailing::M('red' , _ACA_MESSAGE_NOT.'! ' . _ACA_MAILER_ERROR . ': ' . $mail->ErrorInfo);
  404. $log_detailed .= '['.$mailingId.'] '.$subject.' : '.$receiver->email . ' -> ' . _ACA_MESSAGE_NOT . "\r\n" . _ACA_MAILER_ERROR . ': ' . $mail->ErrorInfo . "\r\n";
  405. if($html && (intval($receiver->receive_html) == 1)) {
  406. $html_sent--;
  407. } else{
  408. $text_sent--;
  409. }
  410. } else {
  411. $h .= $receiver->email . '</strong> -> ' . xmailing::M('green' , _ACA_MESSAGE_SENT_SUCCESSFULLY);
  412. $log_detailed .= '['.$mailingId.'] '.$subject.' : '.$receiver->email . ' -> ' . _ACA_MESSAGE_SENT_SUCCESSFULLY . "\r\n";
  413. if ($GLOBALS[ACA.'enable_statistics'] == 1 AND $GLOBALS[ACA.'statistics_per_subscriber'] == 1) {
  414. xmailing::insertStats( $mailingId, $receiver->id, $ashtml);
  415. }
  416. }
  417. $mail->ClearAddresses();
  418. if ($showHTML) echo '<script type="text/javascript" language="javascript">document.counterForm.teller.value=\'' . $i . '\';</script>';
  419. flush();
  420. if ((($i % $GLOBALS[ACA.'emails_between_pauses']) == 0) AND $i<$nbsubscribers) {
  421. if ($showHTML) echo $h;
  422. $h ='';
  423. flush();
  424. $mtime = microtime();
  425. $mtime = explode(" ",$mtime);
  426. $mtime = $mtime[1] + $mtime[0];
  427. $endtime = $mtime;
  428. if ($totalsofar>0) {
  429. $totaltime = $totalsofar;
  430. $totalstr = strval ($totaltime);
  431. } else {
  432. $totaltime = number_format($endtime - $starttime - $nbPause * $GLOBALS[ACA.'pause_time'], 4, ',', '');
  433. $totalstr = strval ($totaltime);
  434. }
  435. if($GLOBALS[ACA.'display_trace'] == 1 AND $showHTML ) {
  436. echo '<br/>Time to send: ' .$totalstr . ' ' ._ACA_SECONDS;
  437. echo '<br/>Number of subscribers: ' . ($text_sent + $html_sent) . "<br />" .
  438. 'HTML format: ' . $html_sent . "<br />" .
  439. 'Text format: ' . $text_sent . "<br />";
  440. } else {
  441. echo _ACA_QUEUE_PROCESSED;
  442. }
  443. if ($GLOBALS[ACA.'wait_for_user'] == 0) {
  444. $mtime = microtime();
  445. $mtime = explode(" ",$mtime);
  446. $mtime = $mtime[1] + $mtime[0];
  447. $endtime = $mtime;
  448. $totaltime = number_format($endtime - $starttime - $nbPause * $GLOBALS[ACA.'pause_time'], 4, ',', '');
  449. $totalstr = strval ($totaltime);
  450. if(!class_exists('auto')){
  451. $h .= '<b>--- Total time so far: ' . $totalstr. ' seconds ---</b><br />';
  452. }
  453. $log_detailed .= "\r\n" . '--- Waiting ' . $GLOBALS[ACA.'pause_time']. ' seconds ---' . "\r\n\r\n";
  454. $log_detailed .= "\r\n" . '<b>--- Total time so far: ' . $totalstr. ' seconds ---</b><br />' . "\r\n\r\n";
  455. $nbPause++;
  456. echo $h;
  457. flush();
  458. //ADRIEN REFRESH PAGE
  459. if (class_exists('auto')){
  460. $_SESSION['skip_subscribers'.$mailing->id] = $i;
  461. //Ecriture des statistiques
  462. if($GLOBALS[ACA.'enable_statistics'] == 1 and ($html_sent>0 OR $text_sent>0)){
  463. xmailing::updateStatsGlobal( $mailingId, $html_sent, $text_sent, false);
  464. }
  465. $xf->plus('totalmailingsent'.$list->list_type, $html_sent+$text_sent);
  466. $xf->plus('totalmailingsent0', $html_sent+$text_sent);
  467. $log_simple = 'Time to send: ' . $totalstr . ' ' ._ACA_SECONDS . "\r\n" .
  468. 'Number of subscribers: ' . ($text_sent + $html_sent) . "\r\n" .
  469. 'HTML format: ' . $html_sent . "\r\n" .
  470. 'Text format: ' . $text_sent . "\r\n";
  471. $log_detailed = $log_simple . 'Details: ' . "\r\n" . $log_detailed . "\r\n";
  472. if (class_exists('lisType')) jnewsletter_mail::writeLogs($list, $log_simple, $log_detailed);
  473. }
  474. echo '<br/><b>--- Waiting '.$GLOBALS[ACA.'pause_time'].' seconds : </b>';
  475. for($a=0;$a<$GLOBALS[ACA.'pause_time']-1;$a++){
  476. sleep(1);
  477. echo $GLOBALS[ACA.'pause_time'] - $a - 1 .' ';
  478. flush();
  479. }
  480. if (class_exists('auto')){
  481. $link = 'index2.php?option=com_jnewsletter&act=mailing&task=sendNewsletter&listid='.$listId.'&listype='.$mailing->mailing_type.'&mailingid='.$mailing->id.'&skip_subscribers='.$i;
  482. compa::redirect($link);
  483. exit(0);
  484. }
  485. } else{
  486. $log_detailed .= "\r\n" . '--- Waiting for user input to continue sending ---' . "\r\n\r\n";
  487. $mtime = microtime();
  488. $mtime = explode(" ",$mtime);
  489. $mtime = $mtime[1] + $mtime[0];
  490. $endtime = $mtime;
  491. $totaltime = number_format($endtime - $starttime, 4, ',', '');
  492. if ( ACA_CMSTYPE ) { // joomla 15
  493. $timeStr = JRequest::getVar('time', '');
  494. } //endif
  495. $time = floatval($timeStr);
  496. $totalsofar = $endtime - $starttime + $time;
  497. $totalstr = strval ($totalsofar);
  498. ?>
  499. <form action="index2.php" name="counterForm" method="post">
  500. <input type="hidden" name="option" value="com_jnewsletter" />
  501. <input type="hidden" name="act" value="mailing" />
  502. <input type="hidden" name="task" value="sendNewsletter" />
  503. <input type="hidden" name="listid" value="<?php echo $listId; ?>" />
  504. <input type="hidden" name="listype" value="<?php echo $mailing->mailing_type; ?>" />
  505. <input type="hidden" name="skip_subscribers" value="<?php echo $i; ?>" />
  506. <input type="hidden" name="mailingid" value="<?php echo $mailing->id; ?>" />
  507. <input type="hidden" name="time" value="<?php echo $totalstr; ?>" />
  508. <br />
  509. <input type="submit" name="submit" value="<?php echo _ACA_CONTINUE_SENDING; ?>" />
  510. </form>
  511. <?php
  512. }
  513. }else{
  514. if ($showHTML) echo $h;
  515. $h ='';
  516. }
  517. }
  518. if($GLOBALS[ACA.'enable_statistics'] == 1){
  519. xmailing::updateStatsGlobal( $mailingId, $html_sent, $text_sent, false);
  520. }
  521. unset($_SESSION['skip_subscribers'.$mailing->id]);
  522. $mtime = microtime();
  523. $mtime = explode(" ",$mtime);
  524. $mtime = $mtime[1] + $mtime[0];
  525. $endtime = $mtime;
  526. if ($totalsofar>0) {
  527. $totaltime = $totalsofar;
  528. $totalstr = strval ($totaltime);
  529. } else {
  530. $totaltime = number_format($endtime - $starttime - $nbPause * $GLOBALS[ACA.'pause_time'], 4, ',', '');
  531. $totalstr = strval ($totaltime);
  532. }
  533. $xf->plus('totalmailingsent'.$list->list_type, $html_sent+$text_sent);
  534. $xf->plus('totalmailingsent0', $html_sent+$text_sent);
  535. $log_simple = 'Time to send: ' . $totalstr . ' ' ._ACA_SECONDS . "\r\n" .
  536. 'Number of subscribers: ' . ($text_sent + $html_sent) . "\r\n" .
  537. 'HTML format: ' . $html_sent . "\r\n" .
  538. 'Text format: ' . $text_sent . "\r\n";
  539. $log_detailed = $log_simple . 'Details: ' . "\r\n" . $log_detailed . "\r\n";
  540. if($GLOBALS[ACA.'display_trace'] == 1 AND $showHTML ) {
  541. echo '<br /><b>' . _ACA_SENDING_TOOK . ' ' . $totalstr . ' ' . _ACA_SECONDS . '</b><br />';
  542. echo 'Number of subscribers: ' . ($text_sent + $html_sent) . "<br />" .
  543. 'HTML format: ' . $html_sent . "<br />" .
  544. 'Text format: ' . $text_sent . "<br />";
  545. } else {
  546. echo _ACA_QUEUE_PROCESSED;
  547. }
  548. if (class_exists('lisType')) jnewsletter_mail::writeLogs($list, $log_simple, $log_detailed);
  549. ob_start();
  550. if ($html_sent+$text_sent>0 ) {
  551. return true;
  552. } else {
  553. $message = xmailing::M('no' , _ACA_NO_MAILING_SENT);
  554. return false;
  555. }
  556. }
  557. function sendOne($mailing, $receivers, $list, &$message , $tags=null) {
  558. $mailingId = $mailing->id;
  559. $issue_nb = $mailing->issue_nb;
  560. $subject = $mailing->subject;
  561. $content = $mailing->htmlcontent;
  562. $textonly = $mailing->textonly;
  563. $fromname = $mailing->fromname;
  564. $fromemail = $mailing->fromemail;
  565. $images = $mailing->images;
  566. $listId = $list->id;
  567. $html = $list->html;
  568. $layout = $list->layout;
  569. $tags['issuenb'] = $issue_nb;
  570. if(!empty($mailing->template_id)){
  571. $template_id = $mailing->template_id;
  572. }
  573. ### create the mail
  574. $mail = jnewsletter_mail::getMailer($mailing);
  575. ### create content
  576. jnewsletter_mail::getContent($images, $layout, $content, $textonly, true);
  577. if ( isset($receivers->user_id) ) $tags['user_id'] = $receivers->user_id;
  578. //variables used in integration of jLinks
  579. $mailCatID = null;
  580. $convertedLinks = null;
  581. if(!empty($receivers)){
  582. if($html && (intval($receivers->receive_html) == 1)) {
  583. $mail->IsHTML(true);
  584. $ashtml = 1;
  585. $Altbody = jnewsletter_mail::replaceTags($textonly, $receivers, $list, $mailingId, 0, $tags);
  586. $mail->AltBody = jnewsletter_mail::safe_utf8_encode( $Altbody, $mail->CharSet );
  587. $mail->Body = jnewsletter_mail::replaceTags($content, $receivers, $list, $mailingId, $ashtml, $tags);
  588. //this line is added when jLinks is integrated with jnewsletter
  589. //jnewsletter_mail::linkReplacement( $mailing->mailing_type, $list, $mailingId, $mailing->subject, $mail,
  590. //$mailCatID, $convertedLinks, $receivers->id );
  591. //with updates from Glenn
  592. //this line is added when jLinks is integrated with jnewsletter
  593. if( isset($mailing->mailing_type) && !empty($mailing->mailing_type) ) {
  594. jnewsletter_mail::linkReplacement( $mailing->mailing_type, $list, $mailingId, $mailing->subject, $mail,
  595. $mailCatID, $convertedLinks, $receivers->id );
  596. }
  597. //jnewsletter_mail::replaceClass($mail->Body,$mail->AltBody,$receivers);
  598. if(!empty($template_id)){ //checking for template id
  599. $styles = templates::getTemplateStyles($template_id);
  600. }
  601. if(!empty($styles)){ //checking for styles
  602. $mail->Body = templates::insertStyles($mail->Body, $mail->AltBody, $styles);
  603. }
  604. } else{
  605. $mail->IsHTML(false);
  606. $mail->AltBody = '';
  607. $ashtml = 0;
  608. $mail->Body = jnewsletter_mail::replaceTags($textonly, $receivers, $list, $mailingId, $ashtml, $tags);
  609. $simpleText = '';
  610. //jnewsletter_mail::replaceClass($mail->Body,$simpleText,$receivers);
  611. if( !empty($images) ) {
  612. foreach( $images as $image) {
  613. $img = explode('|', $image);
  614. $attrib = explode("/", $img[0]);
  615. $path = ACA_JPATH_ROOT. '/images/stories/';
  616. if (count($img)==1) {
  617. $imageName = $img[0];
  618. } else {
  619. $imageName = $attrib[count($attrib)-1];
  620. for ($index = 0; $index < (sizeof($attrib)-1); $index++) {
  621. $path .= $attrib[$index].'/';
  622. }
  623. }
  624. $mail->AddAttachment( $path.$imageName);
  625. }
  626. }
  627. }
  628. $tname = explode(" ", $receivers->name);
  629. $firstname = $tname[0];
  630. $toUser = $GLOBALS[ACA.'minisendmail'] ? '' : $receivers->name;
  631. $mail->AddAddress($receivers->email, $toUser);
  632. $username = empty($receivers->username) ? $firstname : $receivers->username;
  633. $date = ACA_CMSTYPE ? JHTML::_('date',jnewsletter::getNow(), JText::_('DATE_FORMAT_LC1'), 0) : mosFormatDate(jnewsletter::getNow(), '', 0);
  634. $replaceWhat = array('[NAME]','[FIRSTNAME]','[USERNAME]','[DATE]');
  635. $replaceBy = array($receivers->name,$firstname,$username,$date);
  636. $sujetReplaced = str_replace($replaceWhat, $replaceBy, $subject);
  637. $mail->Subject = $sujetReplaced;
  638. if(empty($mail->Body) OR empty($mail->Subject)){
  639. echo xmailing::M('red' , 'There is not Body or Subject in your e-mail');
  640. return false;
  641. }
  642. if($GLOBALS[ACA.'embed_images']){
  643. jnewsletter_mail::embedImages($mail);
  644. }
  645. $mailssend = $mail->Send();
  646. if (!$mailssend || $mail->error_count > 0) {
  647. static $info =false;
  648. if(!$info AND jnewsletter::checkPermissions('admin')){
  649. echo '<br/>Mailer Error : ' . $mail->ErrorInfo;
  650. echo " : Newsletter '$sujetReplaced' to $receivers->email";
  651. $info = true;
  652. }
  653. $message .= xmailing::M('red' , _ACA_MESSAGE_NOT.'! ' . _ACA_MAILER_ERROR . ': ' . $mail->ErrorInfo);
  654. return false;
  655. } else {
  656. $message .= _ACA_MESSAGE_SENT_SUCCESSFULLY;
  657. return true;
  658. }
  659. } else {
  660. echo xmailing::M('red' , _ACA_NO_ADDRESS_ENTERED);
  661. return false;
  662. }
  663. }
  664. function sendSchedule( $d, $showHTML, $receivers, $list, &$message, &$max, $tags=null ) {
  665. static $countEmails = 0;
  666. $mailing = $d['mailing'];
  667. $h = '';
  668. $xf = new xonfig();
  669. if (empty($mailing)) {
  670. $message = _ACA_NO_MAILING_ENTERED;
  671. return false;
  672. } elseif ( empty($receivers) ) {
  673. $message = _ACA_NO_ADDRESS_ENTERED;
  674. return false;
  675. } elseif ( empty($list) ) {
  676. $message = _ACA_NO_LIST_ENTERED;
  677. return false;
  678. } else {
  679. $message = '';
  680. }
  681. $mailingId = $mailing->id;
  682. $issue_nb = $mailing->issue_nb;
  683. $subject = $mailing->subject;
  684. $content = $mailing->htmlcontent;
  685. $textonly = $mailing->textonly;
  686. $fromname = $mailing->fromname;
  687. $fromemail = $mailing->fromemail;
  688. $images = $mailing->images;
  689. $listId = $list->id;
  690. $html = $list->html;
  691. $layout = $list->layout;
  692. $totalsofar = number_format(0, 4, ',', '');
  693. $nbPause = 0;
  694. $tags['issuenb'] = $issue_nb;
  695. $template_id = $mailing->template_id;
  696. //Just in case of...
  697. @ini_set('max_execution_time',0);
  698. @ini_set('memory_limit','128M');
  699. ignore_user_abort(true);
  700. ### create the mail
  701. $mail = jnewsletter_mail::getMailer($mailing);
  702. ### create content
  703. jnewsletter_mail::getContent($images, $layout, $content, $textonly, true);
  704. $mtime = microtime();
  705. $mtime = explode(" ",$mtime);
  706. $mtime = $mtime[1] + $mtime[0];
  707. $starttime = $mtime;
  708. $html_sent = 0;
  709. $text_sent = 0;
  710. $size = sizeof($receivers);
  711. $format = defined('_DATE_FORMAT_LC') ? _DATE_FORMAT_LC : JText::_('DATE_FORMAT_LC');
  712. $log_detailed = "\r\n" ."\r\n" .'*** '.strftime($format).' ***'."\r\n";
  713. //variables used in integration of jLinks
  714. $mailCatID = null;
  715. $convertedLinks = null;
  716. foreach ($receivers as $receiver) {
  717. $tags['user_id'] = $receiver->user_id;
  718. if ($html && (intval($receiver->receive_html) == 1)) {
  719. $mail->IsHTML(true);
  720. $ashtml = 1;
  721. $Altbody = jnewsletter_mail::replaceTags($textonly, $receiver, $list, $mailingId, 0, $tags);
  722. $mail->AltBody = jnewsletter_mail::safe_utf8_encode( $Altbody, $mail->CharSet );
  723. $html_sent++;
  724. $mail->Body = jnewsletter_mail::replaceTags($content, $receiver, $list, $mailingId, $ashtml, $tags);
  725. //this line is added when jLinks is integrated with jNews
  726. jnewsletter_mail::linkReplacement( $mailing->mailing_type, $list, $mailingId, $mailing->subject, $mail,
  727. $mailCatID, $convertedLinks, $receiver->id );
  728. //jnewsletter_mail::replaceClass($mail->Body,$mail->AltBody,$receiver);
  729. $styles = templates::getTemplateStyles($template_id);
  730. $mail->Body = templates::insertStyles($mail->Body,$mail->AltBody, $styles);
  731. } else {
  732. $mail->IsHTML(false);
  733. $mail->AltBody = '';
  734. $ashtml = 0;
  735. $text_sent++;
  736. $mail->Body = jnewsletter_mail::replaceTags($textonly, $receiver, $list, $mailingId, $ashtml, $tags);
  737. $simpleText = '';
  738. //jnewsletter_mail::replaceClass($mail->Body,$simpleText,$receiver);
  739. }
  740. $tname = explode(" ", $receiver->name);
  741. $firstname = $tname[0];
  742. $toUser = $GLOBALS[ACA.'minisendmail'] ? '' : $receiver->name;
  743. $mail->AddAddress($receiver->email, $toUser);
  744. //if(!empty($receiver->id)) $mail->addCustomHeader("X-SubscriberID: $receiver->id");
  745. $username = empty($receiver->username) ? $firstname : $receiver->username;
  746. $date = ACA_CMSTYPE ? JHTML::_('date',jnewsletter::getNow(), JText::_('DATE_FORMAT_LC1'), 0) : mosFormatDate(jnewsletter::getNow(), '', 0);
  747. $replaceWhat = array('[NAME]','[FIRSTNAME]','[USERNAME]','[DATE]');
  748. $replaceBy = array($receiver->name,$firstname,$username,$date);
  749. $sujetReplaced = str_replace($replaceWhat, $replaceBy, $subject);
  750. if ( class_exists('auto') ) auto::tags( $sujetReplaced, $tags );
  751. $mail->Subject = $sujetReplaced;
  752. if($GLOBALS[ACA.'embed_images']){
  753. jnewsletter_mail::embedImages($mail);
  754. }
  755. $mailssend = $mail->Send();
  756. $countEmails++;
  757. if ( $countEmails >= $GLOBALS[ACA.'cron_max_emails'] ) $max = true;
  758. if (!$mailssend || $mail->error_count > 0) {
  759. static $info =false;
  760. if(!$info AND jnewsletter::checkPermissions('admin')){
  761. echo '<br/>Mailer Error : ' . $mail->ErrorInfo;
  762. echo " : Newsletter '$sujetReplaced' to $receiver->email";
  763. $info = true;
  764. }
  765. $log_detailed .= '['.$mailingId.'] '.$subject.' : '.$receiver->email . ' -> ' . _ACA_MESSAGE_NOT . "\r\n" . _ACA_MAILER_ERROR . ': ' . $mail->ErrorInfo . "\r\n";
  766. if($html && (intval($receiver->receive_html) == 1)) $html_sent--; else $text_sent--;
  767. if(!subscribers::validEmail($receiver->email,true)){
  768. $deleteQueue = array();
  769. $deleteQueue[0] = queue::whatQID( $mailingId, $receiver->id, $d['listype'] );
  770. queue::deleteQueues($deleteQueue);
  771. }
  772. } else {
  773. $log_detailed .= '['.$mailingId.'] '.$subject.' : '.$receiver->email . ' -> ' . _ACA_MESSAGE_SENT_SUCCESSFULLY . "\r\n";
  774. if ($GLOBALS[ACA.'enable_statistics'] == 1 AND $GLOBALS[ACA.'statistics_per_subscriber'] == 1)
  775. xmailing::insertStats( $mailingId, $receiver->id, $ashtml);
  776. $d['qids'] = array();
  777. $erro = new xerr( __FILE__ , __FUNCTION__ , __CLASS__ );
  778. if ( $d['listype']=='2' ) {
  779. $d['qids'][0] = queue::whatQID( $mailingId, $receiver->id, $d['listype'] );
  780. $erro->ck = auto::updateAutoresponderSent($d);
  781. $erro->Eck(__LINE__ , '8137' , $d);
  782. } elseif ( $d['listype']=='1' || $d['listype']=='7' ) {
  783. $d['qids'][0] = queue::whatQID( $mailingId, $receiver->id, $d['listype'] );
  784. $erro->ck = queue::deleteQueues($d['qids']);
  785. $erro->Eck(__LINE__ , '8127' , $d);
  786. }
  787. }
  788. $mail->ClearAddresses();
  789. }
  790. if($GLOBALS[ACA.'enable_statistics'] == 1){
  791. xmailing::updateStatsGlobal( $mailingId, $html_sent, $text_sent, false);
  792. }
  793. $mtime = microtime();
  794. $mtime = explode(" ",$mtime);
  795. $mtime = $mtime[1] + $mtime[0];
  796. $endtime = $mtime;
  797. if ($totalsofar>0) {
  798. $totaltime = $totalsofar;
  799. $totalstr = strval ($totaltime);
  800. } else {
  801. $totaltime = number_format($endtime - $starttime - $nbPause * $GLOBALS[ACA.'pause_time'], 4, ',', '');
  802. $totalstr = strval ($totaltime);
  803. }
  804. $xf->plus('totalmailingsent'.$list->list_type, $html_sent+$text_sent);
  805. $xf->plus('totalmailingsent0', $html_sent+$text_sent);
  806. $log_simple = 'Time to send: ' . $totalstr . ' ' ._ACA_SECONDS . "\r\n" .
  807. 'Number of subscribers: ' . ($text_sent + $html_sent) . "\r\n" .
  808. 'HTML format: ' . $html_sent . "\r\n" .
  809. 'Text format: ' . $text_sent . "\r\n";
  810. $log_detailed = $log_simple . 'Details: ' . "\r\n" . $log_detailed . "\r\n";
  811. if (class_exists('lisType')) jnewsletter_mail::writeLogs($list, $log_simple, $log_detailed);
  812. if ( $d['listype']=='2' ) {
  813. echo '<br/>'._ACA_QUEUE_AUTO_PROCESSED;
  814. } elseif ( $d['listype']=='1' ) {
  815. echo '<br/>'._ACA_QUEUE_NEWS_PROCESSED;
  816. }
  817. if ($html_sent+$text_sent>0 ) {
  818. return true;
  819. } else {
  820. $message = xmailing::M('no' , _ACA_NO_MAILING_SENT);
  821. return false;
  822. }
  823. }
  824. function sendConfirmationEmail($subscriberId) {
  825. if ( ACA_CMSTYPE ) { // joomla 15
  826. $queue->sub_list_id = JRequest::getVar('sub_list_id', '' );
  827. } //endif
  828. if (!empty($queue->sub_list_id)) {
  829. if ( ACA_CMSTYPE ) { // joomla 15
  830. $queue->subscribed = JRequest::getVar('subscribed', '' );
  831. } //endif
  832. $listSub = array();
  833. $i = 0;
  834. $size = sizeof($queue->sub_list_id);
  835. for ($index = 1; $index <= $size; $index++) {
  836. if (isset($queue->subscribed[$index])) {
  837. if ($queue->subscribed[$index]==1) {
  838. $listSub[$i] = $queue->sub_list_id[$index];
  839. $i++;
  840. }
  841. }
  842. }
  843. } else {
  844. if ( ACA_CMSTYPE ) { // joomla 15
  845. $listSub[0] = (int) JRequest::getVar('listid', '' );
  846. } //endif
  847. }
  848. return jnewsletter_mail::processConfirmationEmail($subscriberId, $listSub);
  849. }
  850. function processConfirmationEmail($subscriberId, $listSub) {
  851. $status = true;
  852. $qid[0] = $subscriberId;
  853. $receiver = subscribers::getSubscribersFromId($qid, false);
  854. $listIds = implode(",", $listSub );
  855. $lists = lists::getSpecifiedLists($listIds, false);
  856. $message = '';
  857. foreach ($lists as $list) {
  858. $Sub_TAG = '';
  859. if (substr_count($list->subscribemessage, '[CONFIRM]')<1) {
  860. $Sub_TAG = '[CONFIRM]';
  861. }
  862. $mailing = null;
  863. if ( empty($list->subscribemessage)) $list->subscribemessage= ' ';
  864. $mailing->subject = _ACA_SUBSCRIBE_SUBJECT_MESS;
  865. $mailing->htmlcontent = $list->subscribemessage.$Sub_TAG;
  866. $mailing->textonly = '';
  867. if(!$GLOBALS[ACA.'minisendmail']) $mailing->fromname = $list->sendername;
  868. $mailing->fromemail = $list->senderemail;
  869. $mailing->frombounce = $list->bounceadres;
  870. $mailing->id = 0;
  871. $mailing->issue_nb = 0;
  872. $mailing->images = '';
  873. $mailing->attachments = '';
  874. if (!jnewsletter_mail::sendOne($mailing, $receiver, $list, $message)) $status = false;
  875. $erro = 'Could not send the confirmation email, for list #:'.$list->id.' , please contact the webmaster!';
  876. break;
  877. }
  878. return $status;
  879. }
  880. function sendUnsubcribeEmail($subscriberId, $list) {
  881. $mailing=null;
  882. $qid[0] = $subscriberId;
  883. $receiver = subscribers::getSubscribersFromId($qid, false);
  884. $mainframe =& JFactory::getApplication();
  885. $message = '';
  886. $adminName = $mainframe->getCfg('fromname');
  887. $adminEmail = $mainframe->getCfg('mailfrom');
  888. $email = '';
  889. $type = '';
  890. $title = '';
  891. $author = '';
  892. //$fromemail = $mailing->fromemail;
  893. $receiverAdmin = subscribers::sendAdminMail( $adminName, $adminEmail, $email, $type, $title, $author, $url = null );
  894. $mailing->subject = _ACA_UNSUBSCRIBE_SUBJECT_MESS;
  895. $mailing->htmlcontent = $list->unsubscribemessage;
  896. $mailing->textonly = $list->unsubscribemessage;
  897. if(!$GLOBALS[ACA.'minisendmail']) $mailing->fromname = $list->sendername;
  898. $mailing->fromemail = $list->senderemail;
  899. $mailing->frombounce = $list->bounceadres;
  900. $mailing->id = 0;
  901. $mailing->issue_nb = 0;
  902. $mailing->images = '';
  903. $mailing->attachments = '';
  904. if(jnewsletter_mail::sendOne($mailing, $receiver, $list, $message)) {
  905. $erro = '';
  906. } else {
  907. $erro = 'Could not send the unsubscribe email, for list #:'.$list->id.' , please contact the webmaster!';
  908. }
  909. return $erro;
  910. }//endfct
  911. function adminNotification($subscriberId, $list) {
  912. $qid[0] = $subscriberId;
  913. $receiver = subscribers::getSubscribersFromId($qid, false);
  914. $mainframe =& JFactory::getApplication();
  915. //send email to admin
  916. $message = '';
  917. $adminName = $mainframe->getCfg('fromname');
  918. $adminEmail = $mainframe->getCfg('mailfrom');
  919. $email = '';
  920. $type = '';
  921. $title = '';
  922. $author = '';
  923. //$fromemail = $mailing->fromemail;
  924. $receiverAdmin = subscribers::sendAdminMail( $adminName, $adminEmail, $email, $type, $title, $author, $url = null );
  925. //end send admin
  926. }//endfct
  927. function writeLogs($list, $log_simple, $log_detailed) {
  928. if ( ACA_CMSTYPE ) {
  929. $database =& JFactory::getDBO();
  930. } //endif
  931. if ($GLOBALS[ACA.'send_log_simple']) {
  932. $send = $log_simple;
  933. } else {
  934. $send = $log_detailed;
  935. }
  936. if (lisType::sendLogs($list->list_type)) {
  937. $database->setQuery( "SELECT * FROM `#__users` WHERE `gid` = 25 LIMIT 1" );
  938. if ( ACA_CMSTYPE ) { // joomla 15
  939. $admin = $database->loadObject();
  940. $owner = subscribers::getSubscriberInfoFromUserId($list->owner);
  941. if ($GLOBALS[ACA.'send_log'] == 1) {
  942. if (!empty($owner->email)) {
  943. JUTility::sendMail($admin->email, $admin->username, $owner->email, 'jNews mailing report', $send );
  944. } else {
  945. JUTility::sendMail($admin->email, $admin->username, $admin->email, 'jNews mailing report', $send );
  946. }
  947. } else {
  948. if ($GLOBALS[ACA.'send_log_closed'] == 1 && connection_aborted()) {
  949. if (!empty($owner->email)) {
  950. JUTility::sendMail($admin->email, $admin->username, $owner->email, 'jNews mailing report', $send );
  951. } else {
  952. JUTility::sendMail($admin->email, $admin->username, $admin->email, 'jNews mailing report', $send );
  953. }
  954. }
  955. }
  956. } //endif
  957. }
  958. if ($GLOBALS[ACA.'save_log']) {
  959. if ($GLOBALS[ACA.'save_log_simple']) {
  960. @file_put_contents(ACA_JPATH_ROOT_NO_ADMIN . $GLOBALS[ACA.'save_log_file'], $log_simple, FILE_APPEND);
  961. } else {
  962. @file_put_contents(ACA_JPATH_ROOT_NO_ADMIN . $GLOBALS[ACA.'save_log_file'], $log_detailed, FILE_APPEND);
  963. }
  964. }
  965. }
  966. function logStatistics( $mailingId, $subscriberId) {
  967. if ( ACA_CMSTYPE ) {
  968. $database =& JFactory::getDBO();
  969. }//endif
  970. if ($subscriberId != 0) {
  971. $query = 'REPLACE INTO `#__jnews_stats_details` ' .
  972. '( `mailing_id`, `subscriber_id`, `html`, `read`) ' .
  973. 'VALUES ( \'' . $mailingId . '\', \'' . $subscriberId . '\', \'1\', \'1\')';
  974. $database->setQuery($query);
  975. $database->query();
  976. }
  977. xmailing::updateStatsGlobal( $mailingId, 0, 0, true );
  978. ob_end_clean();
  979. $filename = ACA_JPATH_ROOT . '/images/blank.png';
  980. $handle = fopen($filename, 'r');
  981. $contents = fread($handle, filesize($filename));
  982. fclose($handle);
  983. header("Content-type: image/png");
  984. echo $contents;
  985. exit();
  986. }
  987. function safe_utf8_encode( $text, $charset ) {
  988. if( strtolower($charset) == 'utf-8') {
  989. if( !jnewsletter_mail::seems_utf8($text)) {
  990. $text = utf8_encode($text);
  991. }
  992. }
  993. $text = jnewsletter_mail::acaHtmlEntityDecode( $text, null, 'utf-8' );
  994. return $text;
  995. }
  996. function seems_utf8($Str) {
  997. for ($i=0; $i<strlen($Str); $i++) {
  998. if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
  999. elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
  1000. elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
  1001. elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
  1002. elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
  1003. elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
  1004. else return false; # Does not match any model
  1005. for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
  1006. if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80)) {
  1007. return false;
  1008. }
  1009. }
  1010. }
  1011. return true;
  1012. }
  1013. function acaHtmlEntityDecode($string, $quote_style = ENT_COMPAT, $charset = null) {
  1014. if( is_null( $charset )) {
  1015. $charset = jnewsletter_mail::acaGetCharset();
  1016. }
  1017. if( function_exists( 'html_entity_decode' )) {
  1018. return @html_entity_decode( $string, $quote_style, $charset );
  1019. }
  1020. if (!is_int($quote_style) && !is_null($quote_style)) {
  1021. user_error(__FUNCTION__.'() expects parameter 2 to be long, ' .
  1022. gettype($quote_style) . ' given', 'warning');
  1023. return;
  1024. }
  1025. $trans_tbl = get_html_translation_table(HTML_ENTITIES);
  1026. $trans_tbl = array_flip($trans_tbl);
  1027. $trans_tbl['&#039;'] = '\'';
  1028. if ($quote_style & ENT_NOQUOTES) {
  1029. unset($trans_tbl['&quot;']);
  1030. }
  1031. return strtr($string, $trans_tbl);
  1032. }
  1033. function acaGetCharset() {
  1034. $iso = explode( '=', _ISO );
  1035. if( !empty( $iso[1] )) {
  1036. return $iso[1];
  1037. }
  1038. else {
  1039. return 'UTF-8';
  1040. }
  1041. }
  1042. /**
  1043. * This function is used in the integration of jLinks to jNews. jNews
  1044. * categories are checked and jLinks entries are categorized. This is also
  1045. * where the mail content is scanned for url links and replaced with
  1046. * jLinks generated links with the namekeys of the original links.
  1047. *
  1048. * @param int $lisType list type whether Newsletter, Auto-Responder,
  1049. * or Smart Newsletter
  1050. * @param object $list object containing the list details
  1051. * @param int $mailID email ID to be used as suffix of the mail category namekey
  1052. * @param string $mailTitle title or subject of the email
  1053. * @param object $mail email object
  1054. * @param int $mailCatID determines if the mail category is created or not
  1055. * @param array $convertedLinks container of the content converted links
  1056. * @param int $subsid subscriber id
  1057. *
  1058. **/
  1059. function linkReplacement( $lisType, $list, $mailID, $mailTitle, $mail, &$mailCatID, &$convertedLinks, $subsid ) {
  1060. if ( empty($GLOBALS[ACA.'show_jlinks']) ) return true;
  1061. $acajLinkey = 'acjlink5wroot';
  1062. $acajNewsKey = 'acja2guys7lt1';
  1063. $acajAutoKey = 'acjmmdj9eslt2';
  1064. $acajSmartKey = 'acj9okesaplt7';
  1065. $acajListKey = 'acj28hfdge';
  1066. $acajMailKey = 'acjsui9bd7sk9w';
  1067. static $loaded = false;
  1068. if ( !$loaded ){
  1069. if ( !defined('JOOBI_SECURE') ) define( 'JOOBI_SECURE', true );
  1070. $joobiEntryPoint = __FILE__ ;
  1071. if(defined('JPATH_ROOT')) $path = JPATH_ROOT;
  1072. elseif(isset($mosConfig_absolute_path)) $path = $mosConfig_absolute_path;
  1073. //if jLinks is not installed on the website there is no need to proceed
  1074. if ( !file_exists( $path.DIRECTORY_SEPARATOR.'joobi'.DIRECTORY_SEPARATOR.'entry.php' ) ) return true;
  1075. $status = @include( $path.DIRECTORY_SEPARATOR.'joobi'.DIRECTORY_SEPARATOR.'entry.php' );
  1076. if ( !$status && !defined('INSTALLER_FOLDER') ) {
  1077. echo "We were unable to load Joobi library. If you removed the joobi folder, ".
  1078. "please also remove this plugins from the Joomla plugins manager.";
  1079. return true;
  1080. }//endif
  1081. $loaded = true;
  1082. }
  1083. //jLinks API class
  1084. static $redirectC = null;
  1085. if ( empty( $redirectC ) ) $redirectC = WGet::classes( 'redirect.api' );
  1086. if (!method_exists($redirectC,'getCatID')){
  1087. echo "We were unable to load the Redirect API";
  1088. return true;
  1089. }
  1090. //jLinks Newsletter Integration class
  1091. static $newsletterC = null;
  1092. if ( empty( $newsletterC ) ) $newsletterC = WGet::classes( 'redirect.newsletter' );
  1093. if (!method_exists($newsletterC,'getContentLinks')){
  1094. echo "We were unable to load the Redirect Newsletter API";
  1095. return true;
  1096. }
  1097. $contentLinks = array();
  1098. //check if mail content have links to be replace else no need to create categories
  1099. //jnewsletter_mail::getContentLinks( $mail, $contentLinks );
  1100. $newsletterC->getContentLinks( $mail, $contentLinks );
  1101. if ( empty( $contentLinks ) ) return true;
  1102. //check if links have been converted already
  1103. if ( empty( $mailCatID ) ) {
  1104. //check if jNews category is created else create it
  1105. $acajID = $redirectC->getCatID($acajLinkey);
  1106. if ( empty( $acajID ) ) {
  1107. $acajID = $redirectC->createCategory( 'jNews', 1, null, $acajLinkey);
  1108. }
  1109. //determine the type of list
  1110. $mailSuffix = '';
  1111. $mailParentCat = '';
  1112. $mailParentName = '';
  1113. //Newsletter List type
  1114. if ( $lisType == 1) {
  1115. $mailSuffix = 'n'.$mailID;
  1116. $listParentCat = $acajNewsKey;
  1117. $listParentName = 'Newsletter';
  1118. //Auto-Responder List type
  1119. } elseif ( $lisType == 2) {
  1120. $m

Large files files are truncated, but you can click here to view the full file