1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class NewsletterCollection extends ItemCollection
25: {
26: 27: 28: 29:
30: public function __construct()
31: {
32: global $cfg;
33: parent::__construct($cfg["tab"]["news"], "idnews");
34: $this->_setItemClass("Newsletter");
35: }
36:
37: 38: 39: 40:
41: public function create($sName)
42: {
43: global $client, $lang, $auth;
44:
45: $sName = $this->escape($sName);
46: $client = cSecurity::toInteger($client);
47: $lang = cSecurity::toInteger($lang);
48:
49:
50: $this->resetQuery();
51: $this->setWhere("idclient", $client);
52: $this->setWhere("idlang", $lang);
53: $this->setWhere("name", $sName);
54: $this->query();
55:
56: if ($this->next()) {
57: return $this->create($sName . "_" . substr(md5(rand()), 0, 10));
58: }
59:
60: $oItem = parent::createNewItem();
61: $oItem->set("idclient", $client);
62: $oItem->set("idlang", $lang);
63: $oItem->set("name", $sName);
64: $oItem->set("created", date('Y-m-d H:i:s'), false);
65: $oItem->set("author", $auth->auth["uid"]);
66:
67: $oItem->store();
68:
69: return $oItem;
70: }
71:
72: 73: 74: 75:
76: public function duplicate($iItemID)
77: {
78: global $client, $lang, $auth;
79:
80: $client = cSecurity::toInteger($client);
81: $lang = cSecurity::toInteger($lang);
82:
83: cInclude("includes", "functions.con.php");
84:
85: $oBaseItem = new Newsletter();
86: $oBaseItem->loadByPrimaryKey($iItemID);
87:
88: $oItem = parent::createNewItem();
89: $oItem->set("name", $oBaseItem->get("name") . "_" . substr(md5(rand()), 0, 10));
90:
91: $iIDArt = 0;
92: if ($oBaseItem->get("type") == "html" && $oBaseItem->get("idart") > 0 && $oBaseItem->get("template_idart") > 0) {
93: $oClientLang = new cApiClientLanguage(false, $client, $lang);
94:
95: if ($oClientLang->getProperty("newsletter", "html_newsletter") == "true") {
96: $iIDArt = conCopyArticle($oBaseItem->get("idart"),
97: $oClientLang->getProperty("newsletter", "html_newsletter_idcat"),
98: sprintf(i18n("Newsletter: %s"), $oItem->get("name"))
99: );
100: conMakeOnline($iIDArt, $lang);
101: }
102: unset($oClientLang);
103: }
104: $oItem->set("idart", $iIDArt);
105: $oItem->set("template_idart", $oBaseItem->get("template_idart"));
106: $oItem->set("idclient", $client);
107: $oItem->set("idlang", $lang);
108: $oItem->set("welcome", 0);
109: $oItem->set("type", $oBaseItem->get("type"));
110: $oItem->set("subject", $oBaseItem->get("subject"));
111: $oItem->set("message", $oBaseItem->get("message"));
112: $oItem->set("newsfrom", $oBaseItem->get("newsfrom"));
113: $oItem->set("newsfromname", $oBaseItem->get("newsfromname"));
114: $oItem->set("newsdate", date("Y-m-d H:i:s"), false);
115: $oItem->set("use_cronjob", $oBaseItem->get("use_cronjob"));
116: $oItem->set("send_to", $oBaseItem->get("send_to"));
117: $oItem->set("send_ids", $oBaseItem->get("send_ids"));
118: $oItem->set("dispatch", $oBaseItem->get("dispatch"));
119: $oItem->set("dispatch_count", $oBaseItem->get("dispatch_count"));
120: $oItem->set("dispatch_delay", $oBaseItem->get("dispatch_delay"));
121: $oItem->set("author", $auth->auth["uid"]);
122: $oItem->set("created", date('Y-m-d H:i:s'), false);
123:
124:
125: if (!is_object($this->properties)) {
126: $this->properties = new cApiPropertyCollection();
127: }
128: $this->properties->setWhere("idclient", $client);
129: $this->properties->setWhere("itemtype", $this->primaryKey);
130: $this->properties->setWhere("itemid", $iItemID);
131: $this->properties->query();
132:
133: while ($oPropertyItem = $this->properties->next()) {
134: $oItem->setProperty($oPropertyItem->get("type"), $oPropertyItem->get("name"), $oPropertyItem->get("value"), $client);
135: }
136:
137: $oItem->store();
138:
139: return $oItem;
140: }
141: }
142:
143: 144: 145:
146: class Newsletter extends Item
147: {
148: 149: 150:
151: public $_sError;
152:
153: 154: 155: 156:
157: public function __construct($mId = false)
158: {
159: global $cfg;
160: parent::__construct($cfg["tab"]["news"], "idnews");
161: $this->_sError = "";
162: if ($mId !== false) {
163: $this->loadByPrimaryKey($mId);
164: }
165: }
166:
167: 168: 169: 170:
171: public function store()
172: {
173: global $client, $lang, $auth;
174:
175: $client = cSecurity::toInteger($client);
176: $lang = cSecurity::toInteger($lang);
177:
178: $this->set("modified", date('Y-m-d H:i:s'), false);
179: $this->set("modifiedby", $auth->auth["uid"]);
180:
181: if ($this->get("welcome") == 1) {
182: $oItems = new NewsletterCollection();
183: $oItems->setWhere("idclient", $client);
184: $oItems->setWhere("idlang", $lang);
185: $oItems->setWhere("welcome", 1);
186: $oItems->setWhere("idnews", $this->get("idnews"), "<>");
187: $oItems->query();
188:
189: while ($oItem = $oItems->next()) {
190: $oItem->set("welcome", 0);
191: $oItem->store();
192: }
193: unset($oItem);
194: unset($oItems);
195: }
196:
197: return parent::store();
198: }
199:
200: 201: 202: 203: 204: 205: 206: 207:
208: public function _replaceTag(&$sCode, $bIsHTML, $sField, $sData)
209: {
210: if ($sCode && !$bIsHTML) {
211: $sCode = str_replace("MAIL_".strtoupper($sField), $sData, $sCode);
212: } else if ($sCode) {
213:
214: $sRegExp = '/\[mail\s*([^]]+)\s*name=(?:"|")'.$sField.'(?:"|")\s*(.*?)\s*\]((?:.|\s)+?)\[\/mail\]/i';
215: $aMatch = array();
216: $iMatches = preg_match($sRegExp, $sCode, $aMatch) ;
217:
218: if ($iMatches > 0) {
219:
220: $sParameter = $aMatch[1] . $aMatch[2];
221: $sMessage = $aMatch[3];
222: $sRegExp = '/\s*(.*?)\s*=\s*(?:"|")(.*?)(?:"|")\s*/i';
223: $aMatch = array();
224:
225: if (preg_match_all($sRegExp, $sParameter, $aMatch) > 0) {
226:
227: $aParameter = array_combine($aMatch[1], $aMatch[2]);
228: unset($aMatch);
229:
230: if (!array_key_exists("type", $aParameter)) {
231: $aParameter["type"] = "text";
232: }
233:
234: switch ($aParameter["type"]) {
235: case "link":
236:
237:
238:
239:
240:
241:
242:
243:
244: $sText = $aParameter["text"];
245:
246: if ($sText == "") {
247: $sText = $sData;
248: }
249: if ($sMessage == "") {
250: $sMessage = $sData;
251: }
252:
253:
254:
255: unset($aParameter["type"]);
256: unset($aParameter["text"]);
257:
258: $sParameter = "";
259: if (count($aParameter) > 0) {
260: foreach ($aParameter as $sKey => $sValue) {
261: $sParameter .= ' '.$sKey . '="' . $sValue . '"';
262: }
263: }
264: $sMessage = str_replace("MAIL_".strtoupper($sField), '<a href="'.conHtmlentities($sData).'"'.$sParameter.'>'.$sText.'</a>', $sMessage);
265:
266: break;
267: default:
268: $sMessage = str_replace("MAIL_".strtoupper($sField), $sData, $sMessage);
269:
270: }
271:
272: $sRegExp = '/\[mail[^]]+name=(?:"|")'.$sField.'(?:"|").*?\].*?\[\/mail\]/is';
273: $sCode = preg_replace($sRegExp, $sMessage, $sCode, -1);
274:
275: $sCode = str_replace("MAIL_".strtoupper($sField), $sData, $sCode);
276: }
277: }
278: }
279: }
280:
281:
282: protected function _getNewsletterTagData($sHTML, $sTag)
283: {
284:
285:
286:
287:
288:
289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308:
309:
310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320:
321:
322:
323:
324:
325:
326:
327: }
328:
329: protected function _deChunkHTTPBody($sHeader, $sBody, $sEOL = "\r\n")
330: {
331:
332:
333:
334:
335: $aParts = preg_split("/\r?\n/", $sHeader, -1, PREG_SPLIT_NO_EMPTY);
336:
337: $aHeader = array();
338: for ($i = 0;$i < sizeof ($aParts); $i++) {
339: if ($i != 0) {
340: $iPos = strpos($aParts[$i], ':');
341: $sParameter = strtolower (str_replace(' ', '', substr ($aParts[$i], 0, $iPos)));
342: $sValue = trim(substr($aParts[$i], ($iPos + 1)));
343: } else {
344: $sField = 'status';
345: $aParameters = explode(' ', $aParts[$i]);
346: $sParameter = $aParameters[1];
347: }
348:
349: if ($sParameter == 'set-cookie') {
350: $aHeader['cookies'][] = $sValue;
351: } else if ($sParameter == 'content-type') {
352: if (($iPos = strpos($sValue, ';')) !== false) {
353: $aHeader[$sParameter] = substr($sValue, 0, $iPos);
354: } else {
355: $aHeader[$sParameter] = $sValue;
356: }
357: } else {
358: $aHeader[$sParameter] = $sValue;
359: }
360: }
361:
362:
363: $iEOLLen = strlen($sEOL);
364:
365: $sBuffer = '';
366: if (isset($aHeader['transfer-encoding']) && $aHeader['transfer-encoding'] == 'chunked') {
367: do {
368: $sBody = ltrim ($sBody);
369: $iPos = strpos($sBody, $sEOL);
370: $iDataLen = hexdec (substr($sBody, 0, $iPos));
371:
372: if (isset($aHeader['content-encoding'])) {
373: $sBuffer .= gzinflate(substr($sBody, ($iPos + $iEOLLen + 10), $iDataLen));
374: } else {
375: $sBuffer .= substr($sBody, ($iPos + $iEOLLen), $iDataLen);
376: }
377:
378: $sBody = substr ($sBody, ($iPos + $iDataLen + $iEOLLen));
379: $sRemaining = trim ($sBody);
380:
381: } while (!empty($sRemaining));
382: } else if (isset($aHeader['content-encoding'])) {
383: $sBuffer = gzinflate(substr($sBody, 10));
384: } else {
385: $sBuffer = $sBody;
386: }
387:
388: return $sBuffer;
389: }
390:
391: 392: 393: 394: 395:
396: public function getHTMLMessage()
397: {
398: global $lang, $client, $contenido;
399: $frontendURL = cRegistry::getFrontendUrl();
400:
401: if ($this->get("type") == "html" && $this->get("idart") > 0 && $this->htmlArticleExists()) {
402:
403:
404: $iIDArt = $this->get("idart");
405:
406:
407: $oClientLang = new cApiClientLanguage(false, $client, $lang);
408: $iIDCat = $oClientLang->getProperty("newsletter", "html_newsletter_idcat");
409: unset($oClientLang);
410:
411:
412: $oClient = new cApiClient($client);
413: $sHTTPUserName = $oClient->getProperty("newsletter", "html_username");
414: $sHTTPPassword = $oClient->getProperty("newsletter", "html_password");
415: unset($oClient);
416:
417:
418: if ($iIDArt > 0 && $iIDCat > 0) {
419:
420: $bSetOffline = false;
421: $oArticles = new cApiArticleLanguageCollection;
422: $oArticles->setWhere("idlang", $this->get("idlang"));
423: $oArticles->setWhere("idart", $this->get("idart"));
424: $oArticles->query();
425:
426: if ($oArticle = $oArticles->next()) {
427: if ($oArticle->get("online") == 0) {
428: $bSetOffline = true;
429: $oArticle->set("online", 1);
430: $oArticle->store();
431: }
432: unset($oArticle);
433: }
434: unset($oArticles);
435:
436: $sFile = "front_content.php?client=$client&lang=$lang&idcat=$iIDCat&idart=$iIDArt&noex=1&send=1";
437:
438: $handler = cHttpRequest::getHttpRequest($frontendURL.$sFile);
439: $headers = array();
440:
441:
442: if ($sHTTPUserName != "" && $sHTTPPassword != "") {
443: $headers['Authorization'] = "Basic " . base64_encode("$sHTTPUserName:$sHTTPPassword");
444: }
445:
446: $headers['Referer'] = "Referer: http://".$frontendURL;
447: $headers['User-Agent'] = "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
448:
449: $handler->setHeaders($headers);
450:
451: $iErrorNo = 0;
452: $sErrorMsg = "";
453: if ($output = $handler->getRequest(true, true)) {
454:
455: $sHTML = strstr(strstr($output, "200"), "\r\n\r\n");
456: $sHeader = strstr($output, "\r\n\r\n", true);
457: $sHTML = $this->_deChunkHTTPBody($sHeader, $sHTML);
458:
459:
460:
461:
462: if (getEffectiveSetting('newsletter', 'remove_base_tag', "false") == "true") {
463:
464: $sHTML = preg_replace('/<base href=(.*?)>/is', '', $sHTML, 1);
465:
466:
467:
468: $sHTML = preg_replace('/[sS[rR][cC][ ]*=[ ]*"([^h][^t][^t][^p][^:].*)"/', 'rc="'.$frontendURL.'$1"', $sHTML);
469: $sHTML = preg_replace('/[hH][rR][eE][fF][ ]*=[ ]*"([^h][^t][^t][^p][^:][A-Za-z0-9#\.?\-=_&]*)"/', 'href="'.$frontendURL.'$1"', $sHTML);
470: $sHTML = preg_replace('/url\((.*)\)/', 'url('. $frontendURL.'$1)', $sHTML);
471:
472:
473: $sHTML = str_replace($frontendURL . "front_content.php?idart=".$iIDArt."#", "#", $sHTML);
474: }
475:
476: $sReturn = $sHTML;
477: } else {
478: if ($contenido) {
479: $sErrorText = i18n("There was a problem getting the newsletter article using http. Error: %s (%s)");
480: } else {
481: $sErrorText = "There was a problem getting the newsletter article using http. Error: %s (%s)";
482: }
483:
484: $this->_sError = sprintf($sErrorText, $sErrorMsg, $iErrorNo);
485: $sReturn = false;
486: }
487:
488:
489: if ($bSetOffline) {
490: $oArticles = new cApiArticleLanguageCollection();
491: $oArticles->setWhere("idlang", $this->get("idlang"));
492: $oArticles->setWhere("idart", $this->get("idart"));
493: $oArticles->query();
494:
495: if ($oArticle = $oArticles->next()) {
496: $oArticle->set("online", 0);
497: $oArticle->store();
498: }
499: unset($oArticle);
500: unset($oArticles);
501: }
502:
503: return $sReturn;
504: } else {
505: return false;
506: }
507: } else {
508: return false;
509: }
510: }
511:
512: 513: 514: 515:
516: public function htmlArticleExists()
517: {
518: if ($this->get("idart") > 0) {
519: $oArticles = new cApiArticleLanguageCollection();
520: $oArticles->setWhere("idlang", $this->get("idlang"));
521: $oArticles->setWhere("idart", $this->get("idart"));
522: $oArticles->query();
523:
524: if ($oArticles->count() > 0) {
525: $bReturn = true;
526: } else {
527: $bReturn = false;
528: }
529:
530: unset($oArticles);
531: } else {
532: $bReturn = false;
533: }
534:
535: return $bReturn;
536: }
537:
538: 539: 540: 541: 542: 543: 544: 545: 546:
547: public function sendEMail($iIDCatArt, $sEMail, $sName = "", $bSimulatePlugins = true, $sEncoding = "iso-8859-1")
548: {
549: global $lang, $client, $cfg, $cfgClient, $contenido;
550:
551:
552: if ($sName == "") {
553: $sName = $sEMail;
554: }
555:
556: $oLanguage = new cApiLanguage($lang);
557: $sFormatDate = $oLanguage->getProperty("dateformat", "date");
558: $sFormatTime = $oLanguage->getProperty("dateformat", "time");
559: unset($oLanguage);
560:
561: if ($sFormatDate == "") {
562: $sFormatDate = "%d.%m.%Y";
563: }
564: if ($sFormatTime == "") {
565: $sFormatTime = "%H:%M";
566: }
567:
568:
569: $sFrom = $this->get("newsfrom");
570: $sFromName = $this->get("newsfromname");
571: if ($sFromName == "") {
572: $sFromName = $sFrom;
573: }
574: $sSubject = $this->get("subject");
575: $sMessageText = $this->get("message");
576:
577: $bIsHTML = false;
578: if ($this->get("type") == "html") {
579: $sMessageHTML = $this->getHTMLMessage();
580:
581: if ($sMessageHTML === false) {
582:
583:
584:
585: if ($contenido) {
586: $sError = i18n("Newsletter to %s could not be sent: No html message available");
587: } else {
588: $sError = "Newsletter to %s could not be sent: No html message available";
589: }
590: $this->_sError = $sName." (".$sEMail."): ".sprintf($sError, $sEMail);
591: return false;
592: } else {
593: $bIsHTML = true;
594: }
595: }
596:
597:
598: if (!getSystemProperty("newsletter", "disable-rn-replacement")) {
599: $sMessageText = str_replace("\r\n", "\n", $sMessageText);
600: }
601:
602:
603: $sKey = str_repeat("key", 10);
604: $sPath = cRegistry::getFrontendUrl() . "front_content.php?changelang=".$lang."&idcatart=".$iIDCatArt."&";
605:
606:
607: $this->_replaceTag($sMessageText, false, "name", $sName);
608: $this->_replaceTag($sMessageText, false, "number", 1);
609: $this->_replaceTag($sMessageText, false, "date", strftime($sFormatDate));
610: $this->_replaceTag($sMessageText, false, "time", strftime($sFormatTime));
611: $this->_replaceTag($sMessageText, false, "unsubscribe", $sPath."unsubscribe=".$sKey);
612: $this->_replaceTag($sMessageText, false, "change", $sPath."change=".$sKey);
613: $this->_replaceTag($sMessageText, false, "stop", $sPath."stop=".$sKey);
614: $this->_replaceTag($sMessageText, false, "goon", $sPath."goon=".$sKey);
615:
616:
617: if ($bIsHTML) {
618: $this->_replaceTag($sMessageHTML, true, "name", $sName);
619: $this->_replaceTag($sMessageHTML, true, "number", 1);
620: $this->_replaceTag($sMessageHTML, true, "date", strftime($sFormatDate));
621: $this->_replaceTag($sMessageHTML, true, "time", strftime($sFormatTime));
622: $this->_replaceTag($sMessageHTML, true, "unsubscribe", $sPath."unsubscribe=".$sKey);
623: $this->_replaceTag($sMessageHTML, true, "change", $sPath."change=".$sKey);
624: $this->_replaceTag($sMessageHTML, true, "stop", $sPath."stop=".$sKey);
625: $this->_replaceTag($sMessageHTML, true, "goon", $sPath."goon=".$sKey);
626: }
627:
628: if ($bSimulatePlugins) {
629:
630: if (getSystemProperty("newsletter", "newsletter-recipients-plugin") == "true") {
631: if (is_array($cfg['plugins']['recipients'])) {
632: foreach ($cfg['plugins']['recipients'] as $sPlugin) {
633: plugin_include("recipients", $sPlugin."/".$sPlugin.".php");
634: if (function_exists("recipients_".$sPlugin."_wantedVariables")) {
635: $aPluginVars = array();
636: $aPluginVars = call_user_func("recipients_".$sPlugin."_wantedVariables");
637:
638: foreach ($aPluginVars as $sPluginVar) {
639:
640: $this->_replaceTag($sMessageText, false, $sPluginVar, ":: ".$sPlugin.": ".$sPluginVar." ::");
641:
642: if ($bIsHTML) {
643: $this->_replaceTag($sMessageHTML, true, $sPluginVar, ":: ".$sPlugin.": ".$sPluginVar." ::");
644: }
645: }
646: }
647: }
648: }
649: } else {
650: setSystemProperty("newsletter", "newsletter-recipients-plugin", "false");
651: }
652: }
653:
654: if (!isValidMail($sEMail) || strtolower($sEMail) == "sysadmin@ihresite.de") {
655:
656: if ($contenido) {
657: $sError = i18n("Newsletter to %s could not be sent: No valid e-mail address");
658: } else {
659: $sError = "Newsletter to %s could not be sent: No valid e-mail address";
660: }
661: $this->_sError = $sName." (".$sEMail."): ".sprintf($sError, $sEMail);
662: return false;
663: } else {
664: if ($bIsHTML) {
665: $body = $sMessageHTML;
666: } else {
667: $body = $sMessageText."\n\n";
668: }
669: if ($bIsHTML) {
670: $contentType = 'text/html';
671: } else {
672: $contentType = 'text/plain';
673: }
674:
675: $mailer = new cMailer();
676: $message = Swift_Message::newInstance($sSubject, $body, $contentType, $sEncoding);
677: $message->setFrom($sFrom, $sFromName);
678: $message->setTo($sEMail);
679: $result = $mailer->send($message);
680:
681: if (!$result) {
682: if ($contenido) {
683: $sError = i18n("Newsletter to %s could not be sent");
684: } else {
685: $sError = "Newsletter to %s could not be sent";
686: }
687: $this->_sError = $sName." (".$sEMail."): ".sprintf($sError, $sEMail);
688: return false;
689: } else {
690: return true;
691: }
692: }
693: }
694:
695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706:
707: public function sendDirect($iIDCatArt, $iIDNewsRcp = false, $iIDNewsGroup = false, &$aSendRcps, $sEncoding = "iso-8859-1")
708: {
709: global $lang, $client, $cfg, $cfgClient, $contenido, $recipient;
710:
711:
712: $aMessages = array();
713:
714: $oLanguage = new cApiLanguage($lang);
715: unset($oLanguage);
716:
717: if ($sFormatDate == "") {
718: $sFormatDate = "%d.%m.%Y";
719: }
720: if ($sFormatTime == "") {
721: $sFormatTime = "%H:%M";
722: }
723:
724: $sPath = cRegistry::getFrontendUrl() . "front_content.php?changelang=".$lang."&idcatart=".$iIDCatArt."&";
725:
726:
727: $sFrom = $this->get("newsfrom");
728: $sFromName = $this->get("newsfromname");
729: if ($sFromName == "") {
730: $sFromName = $sFrom;
731: }
732: $sSubject = $this->get("subject");
733: $sMessageText = $this->get("message");
734:
735: $bIsHTML = false;
736: if ($this->get("type") == "html") {
737: $sMessageHTML = $this->getHTMLMessage();
738:
739: if ($sMessageHTML === false) {
740:
741:
742:
743: if ($contenido) {
744: $sError = i18n("Newsletter could not be sent: No html message available");
745: } else {
746: $sError = "Newsletter could not be sent: No html message available";
747: }
748: $this->_sError = $sError;
749: return false;
750: } else {
751: $bIsHTML = true;
752: }
753: }
754:
755:
756: if (!getSystemProperty("newsletter", "disable-rn-replacement")) {
757: $sMessageText = str_replace("\r\n", "\n", $sMessageText);
758: }
759:
760:
761:
762: $this->_replaceTag($sMessageText, false, "date", strftime($sFormatDate));
763: $this->_replaceTag($sMessageText, false, "time", strftime($sFormatTime));
764:
765:
766: if ($bIsHTML) {
767: $this->_replaceTag($sMessageHTML, true, "date", strftime($sFormatDate));
768: $this->_replaceTag($sMessageHTML, true, "time", strftime($sFormatTime));
769: }
770:
771:
772: if (getSystemProperty("newsletter", "newsletter-recipients-plugin") == "true") {
773: $bPluginEnabled = true;
774: $aPlugins = array();
775:
776: if (is_array($cfg['plugins']['recipients'])) {
777: foreach ($cfg['plugins']['recipients'] as $sPlugin) {
778: plugin_include("recipients", $sPlugin."/".$sPlugin.".php");
779: if (function_exists("recipients_".$sPlugin."_wantedVariables")) {
780: $aPlugins[$sPlugin] = call_user_func("recipients_".$sPlugin."_wantedVariables");
781: }
782: }
783: }
784: } else {
785: setSystemProperty("newsletter", "newsletter-recipients-plugin", "false");
786: $bPluginEnabled = false;
787: }
788:
789: $aRecipients = array();
790: if ($iIDNewsGroup !== false) {
791: $oGroupMembers = new NewsletterRecipientGroupMemberCollection;
792: $aRecipients = $oGroupMembers->getRecipientsInGroup($iIDNewsGroup, false);
793: } else if ($iIDNewsRcp !== false) {
794: $aRecipients[] = $iIDNewsRcp;
795: }
796:
797: $iCount = count($aRecipients);
798: if ($iCount > 0) {
799: $this->_replaceTag($sMessageText, false, "number", $iCount);
800:
801:
802: if ($bIsHTML) {
803: $this->_replaceTag($sMessageHTML, true, "number", $iCount);
804: }
805:
806: foreach ($aRecipients as $iID) {
807: $sRcpMsgText = $sMessageText;
808: $sRcpMsgHTML = $sMessageHTML;
809:
810:
811: $recipient = new NewsletterRecipient;
812: $recipient->loadByPrimaryKey($iID);
813:
814: $sEMail = $recipient->get("email");
815: $sName = $recipient->get("name");
816: if (empty ($sName)) {
817: $sName = $sEMail;
818: }
819: $sKey = $recipient->get("hash");
820:
821: $bSendHTML = false;
822: if ($recipient->get("news_type") == 1) {
823: $bSendHTML = true;
824: }
825:
826: $this->_replaceTag($sRcpMsgText, false, "name", $sName);
827: $this->_replaceTag($sRcpMsgText, false, "unsubscribe", $sPath."unsubscribe=".$sKey);
828: $this->_replaceTag($sRcpMsgText, false, "change", $sPath."change=".$sKey);
829: $this->_replaceTag($sRcpMsgText, false, "stop", $sPath."stop=".$sKey);
830: $this->_replaceTag($sRcpMsgText, false, "goon", $sPath."goon=".$sKey);
831:
832:
833: if ($bIsHTML && $bSendHTML) {
834: $this->_replaceTag($sRcpMsgHTML, true, "name", $sName);
835: $this->_replaceTag($sRcpMsgHTML, true, "unsubscribe", $sPath."unsubscribe=".$sKey);
836: $this->_replaceTag($sRcpMsgHTML, true, "change", $sPath."change=".$sKey);
837: $this->_replaceTag($sRcpMsgHTML, true, "stop", $sPath."stop=".$sKey);
838: $this->_replaceTag($sRcpMsgHTML, true, "goon", $sPath."goon=".$sKey);
839: }
840:
841: if ($bPluginEnabled) {
842: foreach ($aPlugins as $sPlugin => $aPluginVar) {
843: foreach ($aPluginVar as $sPluginVar) {
844:
845: $this->_replaceTag($sRcpMsgText, false, $sPluginVar, call_user_func("recipients_".$sPlugin."_getvalue", $sPluginVar));
846:
847: if ($bIsHTML && $bSendHTML) {
848: $this->_replaceTag($sRcpMsgHTML, true, $sPluginVar, call_user_func("recipients_".$sPlugin."_getvalue", $sPluginVar));
849: }
850: }
851: }
852: }
853:
854: if (strlen($sKey) != 30) {
855: if ($contenido) {
856: $sError = i18n("Newsletter to %s could not be sent: Recipient has an incompatible or empty key");
857: } else {
858: $sError = "Newsletter to %s could not be sent: Recipient has an incompatible or empty key";
859: }
860: $aMessages[] = $sName." (".$sEMail."): ".sprintf($sError, $sEMail);
861: } else if (!isValidMail($sEMail)) {
862: if ($contenido) {
863: $sError = i18n("Newsletter to %s could not be sent: No valid e-mail address specified");
864: } else {
865: $sError = "Newsletter to %s could not be sent: No valid e-mail address specified";
866: }
867: $aMessages[] = $sName." (".$sEMail."): ".sprintf($sError, $sEMail);
868: } else {
869: if ($bIsHTML && $bSendHTML) {
870: $body = $sRcpMsgHTML;
871: } else {
872: $body = $sRcpMsgText."\n\n";
873: }
874:
875: if ($bIsHTML && $bSendHTML) {
876: $contentType = 'text/html';
877: } else {
878: $contentType = 'text/plain';
879: }
880:
881: $mailer = new cMailer();
882: $message = Swift_Message::newInstance($sSubject, $body, $contentType, $sEncoding);
883: $message->setFrom($sFrom, $sFromName);
884: $message->setTo($sEMail);
885: $result = $mailer->send($message);
886:
887: if ($result) {
888: $aSendRcps[] = $sName." (".$sEMail.")";
889: } else {
890: if ($contenido) {
891: $sError = i18n("Newsletter to %s could not be sent");
892: } else {
893: $sError = "Newsletter to %s could not be sent";
894: }
895: $aMessages[] = $sName." (".$sEMail."): ".sprintf($sError, $sEMail);
896: }
897: }
898: }
899: } else {
900: if ($contenido) {
901: $sError = i18n("No recipient with specified recipient/group id %s/%s found");
902: } else {
903: $sError = "No recipient with specified recpient/group id %s/%s found";
904: }
905: $aMessages[] = sprintf($sError, $iIDNewsRcp, $iIDNewsGroup);
906: }
907:
908: if (count($aMessages) > 0) {
909: $this->_sError = implode("<br>", $aMessages);
910: return false;
911: } else {
912: return true;
913: }
914: }
915: }
916: