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