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 $itemID integer 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:      * @access private
151:      */
152:     public $_sError;
153: 
154:     /**
155:      * Constructor Function
156:      * @param  mixed  $mId  Specifies the ID of item to load
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:      * Overriden store()-Method to set modified and modifiedby data and
170:      * to ensure, that there is only one welcome newsletter
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:      * Replaces newsletter tag (e.g. MAIL_NAME) with data.
203:      * If code is just text using str_replace; if it is HTML by using regular expressions
204:      * @param string    sCode    Code, where the tags will be replaced (by reference)
205:      * @param bool        bIsHTML    Is code HTML?
206:      * @param string    sField    Field name, without MAIL_ (e.g. just "name")
207:      * @param string    sData    Data
208:      * @access private
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:             // Extract certain tag
216:             $sRegExp   = '/\[mail\s*([^]]+)\s*name=(?:"|&quot;)'.$sField.'(?:"|&quot;)\s*(.*?)\s*\]((?:.|\s)+?)\[\/mail\]/i';
217:             $aMatch    = array();
218:             $iMatches  = preg_match($sRegExp, $sCode, $aMatch) ;
219: 
220:             if ($iMatches > 0) {
221:                 // $aMatch contains parameter info from left [1] or right [2] to name="field"
222:                 $sParameter = $aMatch[1] . $aMatch[2];
223:                 $sMessage   = $aMatch[3];
224:                 $sRegExp    = '/\s*(.*?)\s*=\s*(?:"|&quot;)(.*?)(?:"|&quot;)\s*/i';
225:                 $aMatch     = array();
226: 
227:                 if (preg_match_all($sRegExp, $sParameter, $aMatch) > 0) {
228:                     // Store parameter data as assoziative array
229:                     $aParameter = array_combine($aMatch[1], $aMatch[2]);
230:                     unset($aMatch); // $aMatch not needed anymore
231: 
232:                     if (!array_key_exists("type", $aParameter)) {
233:                         $aParameter["type"] = "text";
234:                     }
235: 
236:                     switch ($aParameter["type"]) {
237:                         case "link":
238:                             # TODO: Works everything fine?
239:                             # The current code makes it possible to do something like
240:                             # [mail ...]Some text here, then the link: [MAIL_STOP] and more text[/mail]
241:                             #
242:                             # If the other lines will be used, you don't need to
243:                             # set [MAIL_xy] and the message between the [mail]-tags will
244:                             # be used as link text (instead of using the tag parameter "text")
245: 
246:                             $sText = $aParameter["text"];
247: 
248:                             if ($sText == "") {
249:                                 $sText = $sData;
250:                             }
251:                             if ($sMessage == "") {
252:                                 $sMessage = $sData;
253:                             }
254: 
255:                             // Remove not needed parameters from the parameters list
256:                             // everything else goes into the link as parameters
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:                             #$sMessage    = '<a href="'.conHtmlentities($sData).'"'.$sParameter.'>'.$sMessage.'</a>';
268:                             break;
269:                         default:
270:                             $sMessage    = str_replace("MAIL_".strtoupper($sField), $sData, $sMessage);
271:                             #$sMessage    = $sData;
272:                     }
273: 
274:                     $sRegExp = '/\[mail[^]]+name=(?:"|&quot;)'.$sField.'(?:"|&quot;).*?\].*?\[\/mail\]/is';
275:                     $sCode   = preg_replace($sRegExp, $sMessage, $sCode, -1);
276:                     // Just to replace "text"-tags in HTML message also, just in case...
277:                     $sCode   = str_replace("MAIL_".strtoupper($sField), $sData, $sCode);
278:                 }
279:             }
280:         }
281:     }
282: 
283:     /* TODO: HerrB: Remove or insert some functionality */
284:     protected function _getNewsletterTagData($sHTML, $sTag)
285:     {
286:         //$sRegExp = "/<newsletter[^>](.*?)>.*?<\/newsletter>/i";
287:         //$sRegExp = "/\[mail[^\]](.*?)>.*?\[\/mail\]/i";
288:         #\[mail[^\]]((name="(?P<name>.*?)")|(type="(?P<type>.*?)"))\](?P<content>.*?)\[\/mail\]
289:         #\[mail[^\]]((name=(?P<name>[^"]*.*?[^"]*))|(type="(?P<type>.*?)"))\](?P<content>.*?)\[\/mail\]
290: 
291:         /* RegExp explanation:
292:          * Match the character "[" literally �\[�
293:          * Match the characters "mail" literally �mail�
294:          * Match "whitespace characters" (spaces, tabs, line breaks, etc.) after "mail" �\s*�
295:          * Match the regular expression below and capture its match into backreference number 1 �([^]]+)�
296:          * Match any character that is not a "]" �[^]]+�
297:          *       Between one and unlimited times, as many times as possible, giving back as needed (greedy) �+�
298:          * Match the character "]" literally �\]�
299:          * Match the regular expression below and capture its match into backreference number 2 �((?:.|\s)+?)�
300:          *    Match the regular expression below �(?:.|\s)+?�
301:          *       Between one and unlimited times, as few times as possible, expanding as needed (lazy) �+?�
302:          *       Match either the regular expression below (attempting the next alternative only if this one fails) �.�
303:          *          Match any single character that is not a line break character �.�
304:          *       Or match regular expression number 2 below (the entire group fails if this one fails to match) �\s�
305:          *          Match a single character that is a "whitespace character" (spaces, tabs, line breaks, etc.) �\s�
306:          * Match the character "[" literally �\[�
307:          * Match the characters "/mail" literally �/mail�
308:          * Match the character "]" literally �\]�
309:          * Ignore case (i), . includes new lines (s)
310:          **/
311: 
312:         /*
313:         $sRegExp = '/\[mail\s*([^]]+)\]((?:.|\s)+?)\[\/mail\]/is';
314:         $aMatch = array();
315:         preg_match_all($sRegExp, $sHTML, $aMatch, PREG_SET_ORDER);
316:         print_r ($aMatch);
317: 
318:         // Auf bestimmten Typ matchen
319:         $sRegExp = '/\[mail.*?name="name".*?\]((?:.|\s)+?)\[\/mail\]/is';
320:         $aMatch = array();
321:         preg_match_all($sRegExp, $sHTML, $aMatch, PREG_SET_ORDER);
322:         print_r ($aMatch); */
323: 
324:         // Parameter auseinandernehmen (ohne PREG_SET_ORDER)
325:         #$sRegExp = '/\s*(.*?)\s*=\s*"(.*?)"\s*/i';
326:         #$aMatch = array();
327:         #preg_match_all($sRegExp, $sHTML, $aMatch);
328:         #print_r ($aMatch);
329:     }
330: 
331:     protected function _deChunkHTTPBody($sHeader, $sBody, $sEOL = "\r\n")
332:     {
333:         // Based on code from jbr at ya-right dot com, posted on http://www.php.net
334:         // as user comment on fsockopen documentation (2007-05-01)
335: 
336:         // Analyze header
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:         // Get dechunked and decompressed body
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; // Not chunked, not compressed
388:         }
389: 
390:         return $sBuffer;
391:     }
392: 
393:     /**
394:      * If newsletter is HTML newsletter and necessary data available
395:      * returns final HTML message
396:      * @return string HTML message
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:             // Article ID
406:             $iIDArt = $this->get("idart");
407: 
408:             // Category ID
409:             $oClientLang = new cApiClientLanguage(false, $client, $lang);
410:             $iIDCat      = $oClientLang->getProperty("newsletter", "html_newsletter_idcat");
411:             unset($oClientLang);
412: 
413:             // Get http username and password, if frontend is protected
414:             $oClient = new cApiClient($client);
415:             $sHTTPUserName = $oClient->getProperty("newsletter", "html_username");
416:             $sHTTPPassword = $oClient->getProperty("newsletter", "html_password");
417:             unset($oClient);
418: 
419:             // Get HTML
420:             if ($iIDArt > 0 && $iIDCat > 0) {
421:                 // Check, if newsletter is online and set temporarely online, otherwise
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:                 // Maybe the website has been protected using .htaccess, then login
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:                     // Get the HTTP header and body separately
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:                     // If someone likes to use anchors in html newsletters (*sigh*)
462:                     // the base href tag has to be removed - that means, we have to fix
463:                     // all source paths manually...
464:                     if (getEffectiveSetting('newsletter', 'remove_base_tag', "false") == "true") {
465:                         // Remove base tag
466:                         $sHTML = preg_replace('/<base href=(.*?)>/is', '', $sHTML, 1);
467: 
468:                         // Fix source path
469:                         // TODO: Test any URL specification that may exist under the sun...
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:                         // Now replace anchor tags to the newsletter article itself just by the anchor
475:                         $sHTML = str_replace($frontendURL . "front_content.php?idart=".$iIDArt."#", "#", $sHTML);
476:                     }
477: 
478:                     $sReturn = $sHTML;
479:                 } else {
480:                     if ($contenido) { // Use i18n only in backend
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:                 // Set previously offline article back to offline
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:      * Checks, if html newsletter article still exists
516:      * @return bool
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:      * Sends test newsletter directly to specified email address
542:      * @param integer  $iIDCatArt        idcatart of newsletter handler article
543:      * @param string   $sEMail           Recipient email address
544:      * @param string   $sName            Optional: Recipient name
545:      * @param bool     $bSimulatePlugin  If recipient plugin activated, include plugins
546:      *                                   and simulate values from plugins
547:      * @param string   $sEncoding        Message (and header) encoding, e.g. iso-8859-1
548:      */
549:     public function sendEMail($iIDCatArt, $sEMail, $sName = "", $bSimulatePlugins = true, $sEncoding = "iso-8859-1")
550:     {
551:         global $lang, $client, $cfg, $cfgClient, $contenido;
552: 
553:         // Initialization
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:         // Get newsletter data
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:                 // There was a problem getting the html message (maybe article
585:                 // deleted). Exit with error instead of sending as text message only
586: 
587:                 if ($contenido) { // Use i18n only in backend
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:         // Preventing double lines in mail, you may wish to disable this function on windows servers
600:         if (!getSystemProperty("newsletter", "disable-rn-replacement")) {
601:             $sMessageText = str_replace("\r\n", "\n", $sMessageText);
602:         }
603: 
604:         // Simulate key, an alphanumeric string of 30 characters
605:         $sKey    = str_repeat("key", 10);
606:         $sPath    = cRegistry::getFrontendUrl() . "front_content.php?changelang=".$lang."&idcatart=".$iIDCatArt."&";
607: 
608:         // Replace message tags (text message)
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:         // Replace message tags (html message)
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:             // Enabling plugin interface
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:                                 // Replace tags in text message
642:                                 $this->_replaceTag($sMessageText, false, $sPluginVar, ":: ".$sPlugin.": ".$sPluginVar." ::");
643:                                 // Replace tags in html message
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:             // No valid destination mail address specified
658:             if ($contenido) { // Use i18n only in backend
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) { // Use i18n only in backend
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:      * Sends test newsletter directly to specified recipients (single or group)
699:      *
700:      * Note: Sending in chunks not supported! Only usable for tests and only a few
701:      * recipients.
702:      *
703:      * @param integer  $iIDCatArt     idcatart of newsletter handler article
704:      * @param integer  $iIDNewsRcp    If specified, newsletter recipient id, ignored, if group specified
705:      * @param integer  $iIDNewsGroup  If specified, newsletter recipient group id
706:      * @param array    $aSendRcps     As reference: Filled with a list of succesfull recipients
707:      * @param string   $sEncoding     Message (and header) encoding, e.g. iso-8859-1
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:         // Initialization
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:         // Get newsletter data
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:                 // There was a problem getting the html message (maybe article
743:                 // deleted). Exit with error instead of sending as text message only
744: 
745:                 if ($contenido) { // Use i18n only in backend
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:         // Preventing double lines in mail, you may wish to disable this function on windows servers
758:         if (!getSystemProperty("newsletter", "disable-rn-replacement")) {
759:             $sMessageText = str_replace("\r\n", "\n", $sMessageText);
760:         }
761: 
762:         // Single replacements
763:         // Replace message tags (text message)
764:         $this->_replaceTag($sMessageText, false, "date", strftime($sFormatDate));
765:         $this->_replaceTag($sMessageText, false, "time", strftime($sFormatTime));
766: 
767:         // Replace message tags (html message)
768:         if ($bIsHTML) {
769:             $this->_replaceTag($sMessageHTML, true, "date", strftime($sFormatDate));
770:             $this->_replaceTag($sMessageHTML, true, "time", strftime($sFormatTime));
771:         }
772: 
773:         // Enabling plugin interface
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:             // Replace message tags (html message)
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:                 // Don't change name of $recipient variable as it is used in plugins!
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; // Recipient accepts html newsletter
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:                 // Replace message tags (html message)
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:                             // Replace tags in text message
847:                             $this->_replaceTag($sRcpMsgText, false, $sPluginVar, call_user_func("recipients_".$sPlugin."_getvalue", $sPluginVar));
848:                             // Replace tags in html message
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) { // Prevents sending without having a key
857:                     if ($contenido) { // Use i18n only in backend
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) { // Use i18n only in backend
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) { // Use i18n only in backend
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) { // Use i18n only in backend
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: 
CMS CONTENIDO 4.9.2 API documentation generated by ApiGen 2.8.0