Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * This file contains the Newsletter Collection 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: 
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: /**
 20:  * Newsletter Collection class.
 21:  *
 22:  * @package Plugin
 23:  * @subpackage Newsletter
 24:  */
 25: class NewsletterRecipientCollection extends ItemCollection {
 26: 
 27:     /**
 28:      * Constructor Function
 29:      *
 30:      * @param none
 31:      */
 32:     public function __construct() {
 33:         global $cfg;
 34:         parent::__construct($cfg["tab"]["news_rcp"], "idnewsrcp");
 35:         $this->_setItemClass("NewsletterRecipient");
 36:     }
 37: 
 38:     /**
 39:      * Creates a new recipient
 40:      *
 41:      * @param string $sEMail Specifies the e-mail adress
 42:      * @param string $sName Specifies the recipient name (optional)
 43:      * @param int $iConfirmed Specifies, if the recipient is confirmed
 44:      *            (optional)
 45:      * @param string $sJoinID Specifies additional recipient group ids to join
 46:      *            (optional, e.g. 47,12,...)
 47:      * @param int $iMessageType Specifies the message type for the recipient (0
 48:      *            = text, 1 = html)
 49:      */
 50:     public function create($sEMail, $sName = "", $iConfirmed = 0, $sJoinID = "", $iMessageType = 0) {
 51:         global $client, $lang, $auth;
 52: 
 53:         /* Check if the e-mail adress already exists */
 54:         $email = strtolower($sEMail); // e-mail always lower case
 55:         $this->setWhere("idclient", $client);
 56:         $this->setWhere("idlang", $lang);
 57:         $this->setWhere("email", $email);
 58:         $this->query();
 59: 
 60:         if ($this->next()) {
 61:             return $this->create($email . "_" . substr(md5(rand()), 0, 10), $sName, 0, $sJoinID, $iMessageType); // 0:
 62:                                                                                                             // Deactivate
 63:                                                                                                             // 'confirmed'
 64:         }
 65:         $oItem = $this->createNewItem();
 66:         $oItem->set("idclient", $client);
 67:         $oItem->set("idlang", $lang);
 68:         $oItem->set("name", $sName);
 69:         $oItem->set("email", $email);
 70:         $oItem->set("hash", substr(md5(rand()), 0, 17) . uniqid("")); // Generating
 71:                                                                     // UID, 30
 72:                                                                     // characters
 73:         $oItem->set("confirmed", $iConfirmed);
 74:         $oItem->set("news_type", $iMessageType);
 75: 
 76:         if ($iConfirmed) {
 77:             $oItem->set("confirmeddate", date("Y-m-d H:i:s"), false);
 78:         }
 79:         $oItem->set("deactivated", 0);
 80:         $oItem->set("created", date('Y-m-d H:i:s'), false);
 81:         $oItem->set("author", $auth->auth["uid"]);
 82:         $oItem->store();
 83: 
 84:         $iIDRcp = $oItem->get("idnewsrcp"); // Getting internal id of new
 85:                                             // recipient
 86: 
 87:         // Add this recipient to the default recipient group (if available)
 88:         $oGroups = new NewsletterRecipientGroupCollection();
 89:         $oGroupMembers = new NewsletterRecipientGroupMemberCollection();
 90: 
 91:         $oGroups->setWhere("idclient", $client);
 92:         $oGroups->setWhere("idlang", $lang);
 93:         $oGroups->setWhere("defaultgroup", 1);
 94:         $oGroups->query();
 95: 
 96:         while ($oGroup = $oGroups->next()) {
 97:             $iIDGroup = $oGroup->get("idnewsgroup");
 98:             $oGroupMembers->create($iIDGroup, $iIDRcp);
 99:         }
100: 
101:         // Add to other recipient groups as well? Do so!
102:         if ($sJoinID != "") {
103:             $aJoinID = explode(",", $sJoinID);
104: 
105:             if (count($aJoinID) > 0) {
106:                 foreach ($aJoinID as $iIDGroup) {
107:                     $oGroupMembers->create($iIDGroup, $iIDRcp);
108:                 }
109:             }
110:         }
111: 
112:         return $oItem;
113:     }
114: 
115:     /**
116:      * Overridden delete method to remove recipient from groupmember table
117:      * before deleting recipient
118:      *
119:      * @param $itemID int specifies the recipient
120:      */
121:     public function delete($itemID) {
122:         $oAssociations = new NewsletterRecipientGroupMemberCollection();
123:         $oAssociations->setWhere("idnewsrcp", $itemID);
124:         $oAssociations->query();
125: 
126:         While ($oItem = $oAssociations->next()) {
127:             $oAssociations->delete($oItem->get("idnewsgroupmember"));
128:         }
129:         parent::delete($itemID);
130:     }
131: 
132:     /**
133:      * Purge method to delete recipients which hasn't been confirmed since over
134:      * a month
135:      *
136:      * @param $timeframe int Days after creation a not confirmed recipient will
137:      *            be removed
138:      * @return int Count of deleted recipients
139:      */
140:     public function purge($timeframe) {
141:         global $client, $lang;
142: 
143:         $oRecipientCollection = new NewsletterRecipientCollection();
144: 
145:         // DATEDIFF(created, NOW()) > 30 would be better, but it's only
146:         // available in MySQL V4.1.1 and above
147:         // Note, that, TO_DAYS or NOW may not be available in other database
148:         // systems than MySQL
149:         $oRecipientCollection->setWhere("idclient", $client);
150:         $oRecipientCollection->setWhere("idlang", $lang);
151:         $oRecipientCollection->setWhere("confirmed", 0);
152:         $oRecipientCollection->setWhere("(TO_DAYS(NOW()) - TO_DAYS(created))", $timeframe, ">");
153:         $oRecipientCollection->query();
154: 
155:         while ($oItem = $oRecipientCollection->next()) {
156:             $oRecipientCollection->delete($oItem->get("idnewsrcp"));
157:         }
158:         return $oRecipientCollection->count();
159:     }
160: 
161:     /**
162:      * checkEMail returns true, if there is no recipient with the same e-mail
163:      * address; otherwise false
164:      *
165:      * @param $email string e-mail
166:      * @return recpient item if item with e-mail exists, false otherwise
167:      */
168:     public function emailExists($sEmail) {
169:         global $client, $lang;
170: 
171:         $oRecipientCollection = new NewsletterRecipientCollection();
172: 
173:         $oRecipientCollection->setWhere("idclient", $client);
174:         $oRecipientCollection->setWhere("idlang", $lang);
175:         $oRecipientCollection->setWhere("email", strtolower($sEmail));
176:         $oRecipientCollection->query();
177: 
178:         if ($oItem = $oRecipientCollection->next()) {
179:             return $oItem;
180:         } else {
181:             return false;
182:         }
183:     }
184: 
185:     /**
186:      * Sets a key for all recipients without key or an old key (len(key) <> 30)
187:      *
188:      * @param none
189:      */
190:     public function updateKeys() {
191:         $this->setWhere("LENGTH(hash)", 30, "<>");
192:         $this->query();
193: 
194:         $iUpdated = $this->count();
195:         while ($oItem = $this->next()) {
196:             $oItem->set("hash", substr(md5(rand()), 0, 17) . uniqid("")); /*
197:                                                                          *
198:                                                                          * Generating
199:                                                                          * UID,
200:                                                                          * 30
201:                                                                          * characters
202:                                                                          */
203:             $oItem->store();
204:         }
205: 
206:         return $iUpdated;
207:     }
208: 
209: }
210: 
211: /**
212:  * Single Recipient Item
213:  */
214: class NewsletterRecipient extends Item {
215: 
216:     /**
217:      * Constructor Function
218:      *
219:      * @param mixed $mId Specifies the ID of item to load
220:      */
221:     public function __construct($mId = false) {
222:         global $cfg;
223:         parent::__construct($cfg["tab"]["news_rcp"], "idnewsrcp");
224:         if ($mId !== false) {
225:             $this->loadByPrimaryKey($mId);
226:         }
227:     }
228: 
229:     public function store() {
230:         global $auth;
231: 
232:         $this->set("lastmodified", date('Y-m-d H:i:s'), false);
233:         $this->set("modifiedby", $auth->auth["uid"]);
234:         $success = parent::store();
235: 
236:         // @todo do update below only if code from abve was successfull
237: 
238:         // Update name, email and newsletter type for recipients in pending
239:         // newsletter jobs
240:         $sName = $this->get("name");
241:         $sEmail = $this->get("email");
242:         if ($sName == "") {
243:             $sName = $sEmail;
244:         }
245:         $iNewsType = $this->get("news_type");
246: 
247:         $oLogs = new NewsletterLogCollection();
248:         $oLogs->setWhere("idnewsrcp", $this->get($this->primaryKey));
249:         $oLogs->setWhere("status", "pending");
250:         $oLogs->query();
251: 
252:         while ($oLog = $oLogs->next()) {
253:             $oLog->set("rcpname", $sName);
254:             $oLog->set("rcpemail", $sEmail);
255:             $oLog->set("rcpnewstype", $iNewsType);
256:             $oLog->store();
257:         }
258: 
259:         return $success;
260:     }
261: 
262:     /**
263:      * Userdefined setter for newsletter recipients fields.
264:      *
265:      * @param string $name
266:      * @param mixed $value
267:      * @param bool $bSafe Flag to run defined inFilter on passed value
268:      */
269:     public function setField($name, $value, $bSafe = true) {
270:         switch ($name) {
271:             case 'confirmed':
272:                 $value = (int) $value;
273:                 break;
274:             case 'news_type':
275:                 $value = (int) $value;
276:                 break;
277:         }
278: 
279:         return parent::setField($name, $value, $bSafe);
280:     }
281: 
282: }
283: 
284: ?>
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen