Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • Newsletter
  • NewsletterCollection
  • NewsletterJob
  • NewsletterJobCollection
  • NewsletterLog
  • NewsletterLogCollection
  • NewsletterRecipient
  • NewsletterRecipientCollection
  • NewsletterRecipientGroup
  • NewsletterRecipientGroupCollection
  • NewsletterRecipientGroupMember
  • NewsletterRecipientGroupMemberCollection
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the Newsletter recipient class.
  4:  *
  5:  * @package Plugin
  6:  * @subpackage Newsletter
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Bjoern Behrens
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Newsletter recipient class.
 20:  *
 21:  * @package Plugin
 22:  * @subpackage Newsletter
 23:  */
 24: class NewsletterCollection extends ItemCollection
 25: {
 26:     /**
 27:      * Constructor Function
 28:      * @param none
 29:      */
 30:     public function __construct()
 31:     {
 32:         global $cfg;
 33:         parent::__construct($cfg["tab"]["news"], "idnews");
 34:         $this->_setItemClass("Newsletter");
 35:     }
 36: 
 37:     /**
 38:      * Creates a new newsletter
 39:      * @param $name string specifies the newsletter name
 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:         // Check if the newsletter name already exists
 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:      * Duplicates the newsletter specified by $itemID
 74:      * @param  int $itemID specifies the newsletter id
 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); // Article has to be online for sending...
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); // But more or less deprecated
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:         // Copy properties, runtime on-demand allocation of the properties object
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:  * Single Newsletter Item
145:  */
146: class Newsletter extends Item
147: {
148:     /**
149:      * @var string Error storage
150:      */
151:     public $_sError;
152: 
153:     /**
154:      * Constructor Function
155:      * @param  mixed  $mId  Specifies the ID of item to load
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:      * Overriden store()-Method to set modified and modifiedby data and
169:      * to ensure, that there is only one welcome newsletter
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:      * Replaces newsletter tag (e.g. MAIL_NAME) with data.
202:      * If code is just text using str_replace; if it is HTML by using regular expressions
203:      * @param string    $sCode    Code, where the tags will be replaced (by reference)
204:      * @param bool        $bIsHTML    Is code HTML?
205:      * @param string    $sField    Field name, without MAIL_ (e.g. just "name")
206:      * @param string    $sData    Data
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:             // Extract certain tag
214:             $sRegExp   = '/\[mail\s*([^]]+)\s*name=(?:"|&quot;)'.$sField.'(?:"|&quot;)\s*(.*?)\s*\]((?:.|\s)+?)\[\/mail\]/i';
215:             $aMatch    = array();
216:             $iMatches  = preg_match($sRegExp, $sCode, $aMatch) ;
217: 
218:             if ($iMatches > 0) {
219:                 // $aMatch contains parameter info from left [1] or right [2] to name="field"
220:                 $sParameter = $aMatch[1] . $aMatch[2];
221:                 $sMessage   = $aMatch[3];
222:                 $sRegExp    = '/\s*(.*?)\s*=\s*(?:"|&quot;)(.*?)(?:"|&quot;)\s*/i';
223:                 $aMatch     = array();
224: 
225:                 if (preg_match_all($sRegExp, $sParameter, $aMatch) > 0) {
226:                     // Store parameter data as assoziative array
227:                     $aParameter = array_combine($aMatch[1], $aMatch[2]);
228:                     unset($aMatch); // $aMatch not needed anymore
229: 
230:                     if (!array_key_exists("type", $aParameter)) {
231:                         $aParameter["type"] = "text";
232:                     }
233: 
234:                     switch ($aParameter["type"]) {
235:                         case "link":
236:                             # TODO: Works everything fine?
237:                             # The current code makes it possible to do something like
238:                             # [mail ...]Some text here, then the link: [MAIL_STOP] and more text[/mail]
239:                             #
240:                             # If the other lines will be used, you don't need to
241:                             # set [MAIL_xy] and the message between the [mail]-tags will
242:                             # be used as link text (instead of using the tag parameter "text")
243: 
244:                             $sText = $aParameter["text"];
245: 
246:                             if ($sText == "") {
247:                                 $sText = $sData;
248:                             }
249:                             if ($sMessage == "") {
250:                                 $sMessage = $sData;
251:                             }
252: 
253:                             // Remove not needed parameters from the parameters list
254:                             // everything else goes into the link as parameters
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:                             #$sMessage    = '<a href="'.conHtmlentities($sData).'"'.$sParameter.'>'.$sMessage.'</a>';
266:                             break;
267:                         default:
268:                             $sMessage    = str_replace("MAIL_".strtoupper($sField), $sData, $sMessage);
269:                             #$sMessage    = $sData;
270:                     }
271: 
272:                     $sRegExp = '/\[mail[^]]+name=(?:"|&quot;)'.$sField.'(?:"|&quot;).*?\].*?\[\/mail\]/is';
273:                     $sCode   = preg_replace($sRegExp, $sMessage, $sCode, -1);
274:                     // Just to replace "text"-tags in HTML message also, just in case...
275:                     $sCode   = str_replace("MAIL_".strtoupper($sField), $sData, $sCode);
276:                 }
277:             }
278:         }
279:     }
280: 
281:     /* TODO: HerrB: Remove or insert some functionality */
282:     protected function _getNewsletterTagData($sHTML, $sTag)
283:     {
284:         //$sRegExp = "/<newsletter[^>](.*?)>.*?<\/newsletter>/i";
285:         //$sRegExp = "/\[mail[^\]](.*?)>.*?\[\/mail\]/i";
286:         //\[mail[^\]]((name="(?P<name>.*?)")|(type="(?P<type>.*?)"))\](?P<content>.*?)\[\/mail\]
287:         //\[mail[^\]]((name=(?P<name>[^"]*.*?[^"]*))|(type="(?P<type>.*?)"))\](?P<content>.*?)\[\/mail\]
288: 
289:         /* RegExp explanation:
290:          * Match the character "[" literally �\[�
291:          * Match the characters "mail" literally �mail�
292:          * Match "whitespace characters" (spaces, tabs, line breaks, etc.) after "mail" �\s*�
293:          * Match the regular expression below and capture its match into backreference number 1 �([^]]+)�
294:          * Match any character that is not a "]" �[^]]+�
295:          *       Between one and unlimited times, as many times as possible, giving back as needed (greedy) �+�
296:          * Match the character "]" literally �\]�
297:          * Match the regular expression below and capture its match into backreference number 2 �((?:.|\s)+?)�
298:          *    Match the regular expression below �(?:.|\s)+?�
299:          *       Between one and unlimited times, as few times as possible, expanding as needed (lazy) �+?�
300:          *       Match either the regular expression below (attempting the next alternative only if this one fails) �.�
301:          *          Match any single character that is not a line break character �.�
302:          *       Or match regular expression number 2 below (the entire group fails if this one fails to match) �\s�
303:          *          Match a single character that is a "whitespace character" (spaces, tabs, line breaks, etc.) �\s�
304:          * Match the character "[" literally �\[�
305:          * Match the characters "/mail" literally �/mail�
306:          * Match the character "]" literally �\]�
307:          * Ignore case (i), . includes new lines (s)
308:          **/
309: 
310:         /*
311:         $sRegExp = '/\[mail\s*([^]]+)\]((?:.|\s)+?)\[\/mail\]/is';
312:         $aMatch = array();
313:         preg_match_all($sRegExp, $sHTML, $aMatch, PREG_SET_ORDER);
314:         print_r ($aMatch);
315: 
316:         // Auf bestimmten Typ matchen
317:         $sRegExp = '/\[mail.*?name="name".*?\]((?:.|\s)+?)\[\/mail\]/is';
318:         $aMatch = array();
319:         preg_match_all($sRegExp, $sHTML, $aMatch, PREG_SET_ORDER);
320:         print_r ($aMatch); */
321: 
322:         // Parameter auseinandernehmen (ohne PREG_SET_ORDER)
323:         //$sRegExp = '/\s*(.*?)\s*=\s*"(.*?)"\s*/i';
324:         //$aMatch = array();
325:         //preg_match_all($sRegExp, $sHTML, $aMatch);
326:         //print_r ($aMatch);
327:     }
328: 
329:     protected function _deChunkHTTPBody($sHeader, $sBody, $sEOL = "\r\n")
330:     {
331:         // Based on code from jbr at ya-right dot com, posted on http://www.php.net
332:         // as user comment on fsockopen documentation (2007-05-01)
333: 
334:         // Analyze header
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:         // Get dechunked and decompressed body
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; // Not chunked, not compressed
386:         }
387: 
388:         return $sBuffer;
389:     }
390: 
391:     /**
392:      * If newsletter is HTML newsletter and necessary data available
393:      * returns final HTML message
394:      * @return string HTML message
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:             // Article ID
404:             $iIDArt = $this->get("idart");
405: 
406:             // Category ID
407:             $oClientLang = new cApiClientLanguage(false, $client, $lang);
408:             $iIDCat      = $oClientLang->getProperty("newsletter", "html_newsletter_idcat");
409:             unset($oClientLang);
410: 
411:             // Get http username and password, if frontend is protected
412:             $oClient = new cApiClient($client);
413:             $sHTTPUserName = $oClient->getProperty("newsletter", "html_username");
414:             $sHTTPPassword = $oClient->getProperty("newsletter", "html_password");
415:             unset($oClient);
416: 
417:             // Get HTML
418:             if ($iIDArt > 0 && $iIDCat > 0) {
419:                 // Check, if newsletter is online and set temporarely online, otherwise
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:                 // Maybe the website has been protected using .htaccess, then login
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:                     // Get the HTTP header and body separately
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:                     // If someone likes to use anchors in html newsletters (*sigh*)
460:                     // the base href tag has to be removed - that means, we have to fix
461:                     // all source paths manually...
462:                     if (getEffectiveSetting('newsletter', 'remove_base_tag', "false") == "true") {
463:                         // Remove base tag
464:                         $sHTML = preg_replace('/<base href=(.*?)>/is', '', $sHTML, 1);
465: 
466:                         // Fix source path
467:                         // TODO: Test any URL specification that may exist under the sun...
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:                         // Now replace anchor tags to the newsletter article itself just by the anchor
473:                         $sHTML = str_replace($frontendURL . "front_content.php?idart=".$iIDArt."#", "#", $sHTML);
474:                     }
475: 
476:                     $sReturn = $sHTML;
477:                 } else {
478:                     if ($contenido) { // Use i18n only in backend
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:                 // Set previously offline article back to offline
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:      * Checks, if html newsletter article still exists
514:      * @return bool
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:      * Sends test newsletter directly to specified email address
540:      * @param int  $iIDCatArt        idcatart of newsletter handler article
541:      * @param string   $sEMail           Recipient email address
542:      * @param string   $sName            Optional: Recipient name
543:      * @param bool     $bSimulatePlugin  If recipient plugin activated, include plugins
544:      *                                   and simulate values from plugins
545:      * @param string   $sEncoding        Message (and header) encoding, e.g. iso-8859-1
546:      */
547:     public function sendEMail($iIDCatArt, $sEMail, $sName = "", $bSimulatePlugins = true, $sEncoding = "iso-8859-1")
548:     {
549:         global $lang, $client, $cfg, $cfgClient, $contenido;
550: 
551:         // Initialization
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:         // Get newsletter data
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:                 // There was a problem getting the html message (maybe article
583:                 // deleted). Exit with error instead of sending as text message only
584: 
585:                 if ($contenido) { // Use i18n only in backend
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:         // Preventing double lines in mail, you may wish to disable this function on windows servers
598:         if (!getSystemProperty("newsletter", "disable-rn-replacement")) {
599:             $sMessageText = str_replace("\r\n", "\n", $sMessageText);
600:         }
601: 
602:         // Simulate key, an alphanumeric string of 30 characters
603:         $sKey    = str_repeat("key", 10);
604:         $sPath    = cRegistry::getFrontendUrl() . "front_content.php?changelang=".$lang."&idcatart=".$iIDCatArt."&";
605: 
606:         // Replace message tags (text message)
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:         // Replace message tags (html message)
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:             // Enabling plugin interface
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:                                 // Replace tags in text message
640:                                 $this->_replaceTag($sMessageText, false, $sPluginVar, ":: ".$sPlugin.": ".$sPluginVar." ::");
641:                                 // Replace tags in html message
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:             // No valid destination mail address specified
656:             if ($contenido) { // Use i18n only in backend
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) { // Use i18n only in backend
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:      * Sends test newsletter directly to specified recipients (single or group)
697:      *
698:      * Note: Sending in chunks not supported! Only usable for tests and only a few
699:      * recipients.
700:      *
701:      * @param int  $iIDCatArt     idcatart of newsletter handler article
702:      * @param int  $iIDNewsRcp    If specified, newsletter recipient id, ignored, if group specified
703:      * @param int  $iIDNewsGroup  If specified, newsletter recipient group id
704:      * @param array    $aSendRcps     As reference: Filled with a list of succesfull recipients
705:      * @param string   $sEncoding     Message (and header) encoding, e.g. iso-8859-1
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:         // Initialization
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:         // Get newsletter data
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:                 // There was a problem getting the html message (maybe article
741:                 // deleted). Exit with error instead of sending as text message only
742: 
743:                 if ($contenido) { // Use i18n only in backend
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:         // Preventing double lines in mail, you may wish to disable this function on windows servers
756:         if (!getSystemProperty("newsletter", "disable-rn-replacement")) {
757:             $sMessageText = str_replace("\r\n", "\n", $sMessageText);
758:         }
759: 
760:         // Single replacements
761:         // Replace message tags (text message)
762:         $this->_replaceTag($sMessageText, false, "date", strftime($sFormatDate));
763:         $this->_replaceTag($sMessageText, false, "time", strftime($sFormatTime));
764: 
765:         // Replace message tags (html message)
766:         if ($bIsHTML) {
767:             $this->_replaceTag($sMessageHTML, true, "date", strftime($sFormatDate));
768:             $this->_replaceTag($sMessageHTML, true, "time", strftime($sFormatTime));
769:         }
770: 
771:         // Enabling plugin interface
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:             // Replace message tags (html message)
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:                 // Don't change name of $recipient variable as it is used in plugins!
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; // Recipient accepts html newsletter
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:                 // Replace message tags (html message)
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:                             // Replace tags in text message
845:                             $this->_replaceTag($sRcpMsgText, false, $sPluginVar, call_user_func("recipients_".$sPlugin."_getvalue", $sPluginVar));
846:                             // Replace tags in html message
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) { // Prevents sending without having a key
855:                     if ($contenido) { // Use i18n only in backend
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) { // Use i18n only in backend
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) { // Use i18n only in backend
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) { // Use i18n only in backend
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: 
CMS CONTENIDO 4.9.3 API documentation generated by ApiGen 2.8.0