diff options
| author | Christian Fowler <spider@viovio.com> | 2006-10-07 05:18:56 +0000 |
|---|---|---|
| committer | Christian Fowler <spider@viovio.com> | 2006-10-07 05:18:56 +0000 |
| commit | 6c0ef4d4b60ce9edcd848743c1e4682f3ea6d3f4 (patch) | |
| tree | a943fec0f50924cf871a891daf3013dcce71b712 | |
| parent | 487dbd3593443f0a35390b7a685864b1d7f7ce1e (diff) | |
| download | newsletters-6c0ef4d4b60ce9edcd848743c1e4682f3ea6d3f4.tar.gz newsletters-6c0ef4d4b60ce9edcd848743c1e4682f3ea6d3f4.tar.bz2 newsletters-6c0ef4d4b60ce9edcd848743c1e4682f3ea6d3f4.zip | |
major clean up to newsletter sending. everything pretty clean at this point. unsub needs work
| -rw-r--r-- | BitMailer.php | 98 | ||||
| -rw-r--r-- | admin/mail_queue.php | 17 | ||||
| -rw-r--r-- | admin/schema_inc.php | 8 | ||||
| -rw-r--r-- | admin/tend_mail_queue.php | 1 | ||||
| -rw-r--r-- | templates/mail_queue.tpl | 8 | ||||
| -rw-r--r-- | templates/menu_newsletters_admin.tpl | 1 | ||||
| -rw-r--r-- | templates/unsubscribe_inc.tpl | 4 | ||||
| -rw-r--r-- | templates/view_edition.tpl | 8 |
8 files changed, 84 insertions, 61 deletions
diff --git a/BitMailer.php b/BitMailer.php index 7d31fef..d25e1d8 100644 --- a/BitMailer.php +++ b/BitMailer.php @@ -1,12 +1,12 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_newsletters/Attic/BitMailer.php,v 1.22 2006/07/07 00:04:30 spiderr Exp $ + * $Header: /cvsroot/bitweaver/_bit_newsletters/Attic/BitMailer.php,v 1.23 2006/10/07 05:18:55 spiderr Exp $ * * Copyright (c) 2004 bitweaver.org * All Rights Reserved. See copyright.txt for details and a complete list of authors. * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details * - * $Id: BitMailer.php,v 1.22 2006/07/07 00:04:30 spiderr Exp $ + * $Id: BitMailer.php,v 1.23 2006/10/07 05:18:55 spiderr Exp $ * * Class that handles editions of newsletters * @package newsletters @@ -15,7 +15,7 @@ * * @author spiderr <spider@steelsun.com> * - * @version $Revision: 1.22 $ $Date: 2006/07/07 00:04:30 $ $Author: spiderr $ + * @version $Revision: 1.23 $ $Date: 2006/10/07 05:18:55 $ $Author: spiderr $ */ /** @@ -59,6 +59,7 @@ class BitMailer extends phpmailer { if( !empty( $pRecipients ) && BitBase::verifyId( $pContentId ) ) { $queueTime = time(); foreach( array_keys( $pRecipients ) AS $email ) { + $insertHash['mail_queue_id'] = $this->mDb->GenID( 'mail_queue_id' ); $insertHash['email'] = $email; if( !empty( $pRecipients[$email]['user_id'] ) ) { $insertHash['user_id'] = $pRecipients[$email]['user_id']; @@ -80,51 +81,52 @@ class BitMailer extends phpmailer { $query = "SELECT * FROM `".BIT_DB_PREFIX."mail_queue` mq WHERE `sent_date` IS NULL ".$this->mDb->SQLForUpdate(); - while( ($rs = $this->mDb->query( $query, NULL, 1 )) && $rs->RowCount() ) { - $pick = $rs->fields; - if( !empty( $pick['user_id'] ) ) { - $userHash = $this->mDb->getRow( "SELECT * FROM `".BIT_DB_PREFIX."users_users` WHERE `user_id`=?", array( $pick['user_id'] ) ); - $pick['full_name'] = BitUser::getDisplayName( FALSE, $userHash ); - } else { - $pick['full_name'] = NULL; - } - if( !isset( $body[$pick['content_id']] ) ) { - $gBitSmarty->assign( 'sending', TRUE ); - // We only support sending of newsletters currently - $content = new BitNewsletterEdition( NULL, $pick['content_id'] ); - if( $content->load() ) { - $body[$pick['content_id']]['body'] = $content->render(); - $body[$pick['content_id']]['subject'] = $content->getTitle(); - $body[$pick['content_id']]['reply_to'] = $content->getField( 'reply_to', $gBitSystem->getConfig( 'site_sender_email', $_SERVER['SERVER_ADMIN'] ) ); - $body[$pick['content_id']]['object'] = $content; + if( $rs = $this->mDb->query( $query, NULL ) ) { + while( $pick = $rs->fetchRow() ) { + if( !empty( $pick['user_id'] ) ) { + $userHash = $this->mDb->getRow( "SELECT * FROM `".BIT_DB_PREFIX."users_users` WHERE `user_id`=?", array( $pick['user_id'] ) ); + $pick['full_name'] = BitUser::getDisplayName( FALSE, $userHash ); + } else { + $pick['full_name'] = NULL; } -// $content[$pick['content_id']] = LibertyBase::getLibertyObject(); - } - if( !empty( $body[$pick['content_id']] ) ) { - $pick['url_code'] = md5( $pick['content_id'].$pick['email'].$pick['queue_date'] ); - $unsub = ''; - if( $body[$pick['content_id']]['object']->mNewsletter->mInfo['unsub_msg'] ) { - $gBitSmarty->assign( 'url_code', $pick['url_code'] ); + if( !isset( $body[$pick['content_id']] ) ) { $gBitSmarty->assign( 'sending', TRUE ); - $unsub = $gBitSmarty->fetch( 'bitpackage:newsletters/unsubscribe_inc.tpl' ); + // We only support sending of newsletters currently + $content = new BitNewsletterEdition( NULL, $pick['content_id'] ); + if( $content->load() ) { + $body[$pick['content_id']]['body'] = $content->render(); + $body[$pick['content_id']]['subject'] = $content->getTitle(); + $body[$pick['content_id']]['reply_to'] = $content->getField( 'reply_to', $gBitSystem->getConfig( 'site_sender_email', $_SERVER['SERVER_ADMIN'] ) ); + $body[$pick['content_id']]['object'] = $content; + } + // $content[$pick['content_id']] = LibertyBase::getLibertyObject(); } - $gBitSystem->preDisplay(''); - $header = $gBitSmarty->fetch( 'bitpackage:themes/header_inc.tpl' ); - $htmlBody = $header . "<div id='bitmain'><small>". tra("If this newsletter is not displaying correctly, please click here: ") . "<a href='".$content->getDisplayUrl()."'>".$content->getDisplayUrl()."</a></small><br />" . $body[$pick['content_id']]['body'] . $unsub . '<img src="'.NEWSLETTERS_PKG_URI.'track.php?sub='.$pick['url_code'].'" alt="" /></div>'; - $this->ClearReplyTos(); - $this->AddReplyTo( $body[$pick['content_id']]['reply_to'], $gBitSystem->getConfig( 'bitmailer_from' ) ); - print "TO: $pick[email]\t"; - if( $this->sendMail( $pick, $body[$pick['content_id']]['subject'], $htmlBody ) ) { - print "SENT\n"; - $updateQuery = "UPDATE `".BIT_DB_PREFIX."mail_queue` SET `sent_date`=?,`url_code`=? WHERE `content_id`=? AND `email`=?"; - $this->mDb->query( $updateQuery, array( time(), $pick['url_code'], $pick['content_id'], $pick['email'] ) ); - } else { - $this->logError( $pick ); + if( !empty( $body[$pick['content_id']] ) ) { + $pick['url_code'] = md5( $pick['content_id'].$pick['email'].$pick['queue_date'] ); + $unsub = ''; + if( $body[$pick['content_id']]['object']->mNewsletter->getField('unsub_msg') ) { + $gBitSmarty->assign( 'url_code', $pick['url_code'] ); + $gBitSmarty->assign( 'sending', TRUE ); + } + $gBitSystem->preDisplay(''); + $gBitSmarty->assign( 'mid', 'bitpackage:newsletters/view_edition.tpl' ); + $htmlBody = $gBitSmarty->fetch( 'bitpackage:kernel/bitweaver.tpl' ); + $gBitSmarty->assign( 'unsubMessage', $unsub ); + $gBitSmarty->assign( 'trackCode', $pick['url_code'] ); + $this->ClearReplyTos(); + $this->AddReplyTo( $body[$pick['content_id']]['reply_to'], $gBitSystem->getConfig( 'bitmailer_from' ) ); + print "TO: $pick[email]\t"; + if( $this->sendMail( $pick, $body[$pick['content_id']]['subject'], $htmlBody ) ) { + print "SENT\n"; + $updateQuery = "UPDATE `".BIT_DB_PREFIX."mail_queue` SET `sent_date`=?,`url_code`=? WHERE `content_id`=? AND `email`=?"; + $this->mDb->query( $updateQuery, array( time(), $pick['url_code'], $pick['content_id'], $pick['email'] ) ); + } else { + $this->logError( $pick ); + } + $this->mDb->CompleteTrans(); + $this->mDb->StartTrans(); } - $this->mDb->CompleteTrans(); - $this->mDb->StartTrans(); } - $rs->MoveNext(); } $this->mDb->CompleteTrans(); } @@ -227,19 +229,23 @@ class BitMailer extends phpmailer { LibertyContent::prepGetList( $pListHash ); - $query = "SELECT mq.*, lc.`title`, lc2.`title` AS newsletter_title + $query = "SELECT mq.`mail_queue_id` AS `hash_key`, mq.*, lc.`title`, lc2.`title` AS newsletter_title FROM `".BIT_DB_PREFIX."mail_queue` mq INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lc.content_id=mq.content_id) LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lc2 ON (lc2.content_id=mq.nl_content_id) WHERE begin_date IS NULL ORDER BY queue_date"; if( $rs = $this->mDb->query( $query ) ) { - - $ret = $rs->getRows(); + $ret = $rs->getAssoc(); } return $ret; } + function expungeQueueRow( $pQueueId ) { + if( BitBase::verifyId( $pQueueId ) ) { + $this->mDb->query( "DELETE FROM ".BIT_DB_PREFIX."mail_queue` WHERE `mail_queue_id`=?", array( $pQueueId ) ); + } + } } ?> diff --git a/admin/mail_queue.php b/admin/mail_queue.php index 1d9938b..b16228e 100644 --- a/admin/mail_queue.php +++ b/admin/mail_queue.php @@ -9,14 +9,19 @@ require_once( NEWSLETTERS_PKG_PATH.'BitMailer.php' ); global $gBitMailer; $gBitMailer = new BitMailer(); -if( !empty( $_REQUEST['tend_queue'] ) ) { - $gBitMailer->tendQueue(); -} else { - $listHash = array(); - $queue = $gBitMailer->getQueue( $listHash ); - $gBitSmarty->assign_by_ref( 'queue', $queue ); +if( !empty( $_REQUEST['batch_command'] ) && !empty( $_REQUEST['queue_id'] ) ) { + if( $_REQUEST['batch_command'] == 'delete' ) { + foreach( $_REQUEST['queue_id'] as $qId ) { + $gBitMailer->expungeQueueRow( $qId ); + } + } elseif( $_REQUEST['batch_command'] == 'send' ) { + } } +$listHash = array(); +$queue = $gBitMailer->getQueue( $listHash ); +$gBitSmarty->assign_by_ref( 'queue', $queue ); + $gBitSystem->display( 'bitpackage:newsletters/mail_queue.tpl' ); ?> diff --git a/admin/schema_inc.php b/admin/schema_inc.php index 5b8daed..dbcfc93 100644 --- a/admin/schema_inc.php +++ b/admin/schema_inc.php @@ -27,7 +27,7 @@ $tables = array( 'mail_subscriptions' => " email C(160), user_id I4, - nl_content_id I4, + content_id I4, sub_code C(36), is_valid C(1), subscribed_date I8, @@ -57,8 +57,9 @@ $tables = array( ", 'mail_queue' => " - content_id I4 PRIMARY, - email C(160) PRIMARY, + mail_queue_id PRIMARY, + content_id I4 NOTNULL, + email C(160) NOTNULL, nl_content_id I4 NOTNULL, user_id I4, url_code C(32), @@ -97,6 +98,7 @@ $indices = array ( 'mailq_email_idx' => array( 'table' => 'mail_queue', 'cols' => 'email', 'opts' => NULL ), 'mailq_user_idx' => array( 'table' => 'mail_queue', 'cols' => 'user_id', 'opts' => NULL ), 'mailq_content_idx' => array( 'table' => 'mail_queue', 'cols' => 'content_id', 'opts' => NULL ), + 'mailq_user_content_idx' => array( 'table' => 'mail_queue', 'cols' => 'content_id', 'opts' => array( 'UNIQUE' ) ), 'mailq_sent_idx' => array( 'table' => 'mail_queue', 'cols' => 'sent_date', 'opts' => NULL ), ); $gBitInstaller->registerSchemaIndexes( NEWSLETTERS_PKG_NAME, $indices ); diff --git a/admin/tend_mail_queue.php b/admin/tend_mail_queue.php index f7bcbd8..14f815b 100644 --- a/admin/tend_mail_queue.php +++ b/admin/tend_mail_queue.php @@ -8,6 +8,7 @@ $_SERVER['SERVER_NAME'] = ''; $_SERVER['SERVER_ADMIN'] = ''; $_SERVER['SERVER_SOFTWARE'] = 'command line'; + $_REQUEST['uri_mode'] = TRUE; /** * required setup diff --git a/templates/mail_queue.tpl b/templates/mail_queue.tpl index 9e06320..f7dc860 100644 --- a/templates/mail_queue.tpl +++ b/templates/mail_queue.tpl @@ -17,7 +17,7 @@ <td><a href="{$smarty.const.BIT_ROOT_URL}?content_id={$q.content_id}">{$q.title}</a></td> <td><a href="{$smarty.const.BIT_ROOT_URL}?content_id={$q.nl_content_id}">{$q.newsletter_title}</a></td> <td>{$q.queue_date|bit_short_datetime}</a></td> - <td>{$q.sent_date}</td> + <td>{if $q.sent_date}{$q.sent_date|bit_short_datetime}{/if}</td> <td><input type="checkbox" name="queue_id[]" value="{$qId}" /></td> </tr> {/foreach} @@ -27,10 +27,10 @@ <div style="float:right"> <div class="row"> With checked: - <select> + <select name="batch_command"> <option></option> - <option>{tr}Delete{/tr}</option> - <option>{tr}Send Immediately{/tr}</option> + <option value="delete">{tr}Delete{/tr}</option> + <option value="send">{tr}Send Immediately{/tr}</option> </select> </div> diff --git a/templates/menu_newsletters_admin.tpl b/templates/menu_newsletters_admin.tpl index ddcb9a5..3b248e2 100644 --- a/templates/menu_newsletters_admin.tpl +++ b/templates/menu_newsletters_admin.tpl @@ -2,5 +2,6 @@ <ul> <li><a class="item" href="{$smarty.const.KERNEL_PKG_URL}admin/index.php?page=newsletters">{tr}Newsletters Settings{/tr}</a></li> <li><a class="item" href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/send.php">{tr}Send Newsletters{/tr}</a></li> + <li><a class="item" href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/mail_queue.php">{tr}Tend Mail Queue{/tr}</a></li> </ul> {/if} diff --git a/templates/unsubscribe_inc.tpl b/templates/unsubscribe_inc.tpl index b059537..cc9d174 100644 --- a/templates/unsubscribe_inc.tpl +++ b/templates/unsubscribe_inc.tpl @@ -1,2 +1,2 @@ -<small>{tr}You have received this message because you are registered at{/tr} <a href="{$smarty.const.BIT_BASE_URI}">{$gBitSystem->getConfig('siteTitle', $smarty.const.BIT_BASE_URI)}</a>.<br />{tr}You can always cancel your subscription using:{/tr}<br/> -<a href="{$smarty.const.NEWSLETTERS_PKG_URI}?unsubscribe={$url_code}">{$smarty.const.NEWSLETTERS_PKG_URI}?unsubscribe={$url_code}</a></small> +<small>{tr}You have received this message because you are registered at{/tr} <a href="{$smarty.const.BIT_BASE_URI}">{$gBitSystem->getConfig('siteTitle', $smarty.const.BIT_BASE_URI)}</a>.<br /> +{tr}You can always cancel your subscription using:{/tr} <a href="{$smarty.const.NEWSLETTERS_PKG_URI}?unsubscribe={$url_code}">{$smarty.const.NEWSLETTERS_PKG_URI}?unsubscribe={$url_code}</a></small> diff --git a/templates/view_edition.tpl b/templates/view_edition.tpl index 09af6f0..14324e0 100644 --- a/templates/view_edition.tpl +++ b/templates/view_edition.tpl @@ -11,6 +11,8 @@ <a href="{$smarty.const.NEWSLETTERS_PKG_URL}edition.php?edition_id={$gContent->mEditionId}&remove=1">{biticon ipackage="icons" iname="edit-delete" iexplain="delete"}</a> {/if} </div> + {else} + <div><small>{tr}This newsletter can be viewed on the web at{/tr} <a href="{$gContent->getDisplayUrl()}">{$gContent->getDisplayUrl()}</a></small><div> {/if} <div class="header"> @@ -27,4 +29,10 @@ {$gContent->parseData()} </div> <!-- end .content --> </div> <!-- end .body --> + + {if $sending} tcode {$trackCode} + {include file="bitpackage:newsletters/unsubscribe_inc.tpl"} + <img src="{$smarty.const.NEWSLETTERS_PKG_URI}track.php?sub={$trackCode}" alt="" /> + {/if} + </div><!-- end .newsletters --> |
