Source for file sub.php
Documentation is available at sub.php
* Copyright (c) 2005 bitweaver.org
* All Rights Reserved. See below for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
* @author spider <spider@steelsun.com>
require_once( '../kernel/setup_inc.php' );
include_once( NEWSLETTERS_PKG_PATH. 'BitNewsletterMailer.php' );
$gBitSystem->verifyPackage( 'newsletters' );
if( !$gBitUser->isRegistered() && !$gBitUser->hasPermission( 'p_newsletters_subscribe' ) && empty( $_REQUEST['c'] ) ) {
$gBitSystem->fatalError( tra("You must be logged in to subscribe to newsletters"));
require_once( NEWSLETTERS_PKG_PATH. 'lookup_newsletter_inc.php' );
$newsletters = $gContent->getList( $listHash );
$gBitSmarty->assign_by_ref('newsletters', $newsletters );
$gBitSmarty->assign('url_subscribe', httpPrefix(). $foo["path"]);
// We have a url_code from a clicked link in an email
} elseif( $gBitUser->isRegistered() ) {
$subInfo = $gBitUser->mInfo;
if( !empty( $subInfo['user_id'] ) && BitBase::verifyId( $subInfo['user_id'] ) ) {
$lookup['user_id'] = $subInfo['user_id'];
$lookup['email'] = $subInfo['email'];
if( isset ( $_REQUEST["update"] ) ) {
$subHash['response_content_id'] = $_REQUEST['response_content_id'];
$subHash['sub_lookup'] = !empty( $subInfo['user_id'] ) ? array( 'user_id' => $subInfo['user_id'] ) : array( 'email' => $subInfo['email'] );
if( !empty( $_REQUEST['unsubscribe_all'] ) ) {
$subHash['unsubscribe_all'] = 'y';
$subHash['unsub_content'] = array_keys( $newsletters );
$subHash['unsubscribe_all'] = NULL;
foreach( array_keys( $newsletters ) as $nlContentId ) {
if( empty( $_REQUEST['nl_content_id'] ) || !in_array( $nlContentId, $_REQUEST['nl_content_id'] ) ) {
$subHash['unsub_content'][] = $nlContentId;
$feedback['success'] = tra( "Your subscriptions were updated." );
$feedback['error'] = tra( "Subscriptions were not updated." );
if( isset ( $_REQUEST["subscribe"] ) && !empty( $_REQUEST["email"] ) ) {
$feedback['success'] = tra( "Thanks for your subscription. You will receive an email soon to confirm your subscription. No newsletters will be sent to you until the subscription is confirmed." );
$_REQUEST["email"] = $gBitUser->mInfo['email'];
// Now subscribe the email address to the newsletter
$gContent->subscribe( $_REQUEST["email"], TRUE, TRUE );
foreach( $unsubs as $sub ) {
if( !empty( $sub['unsubscribe_all'] ) ) {
$subInfo['unsubscribe_all'] = TRUE;
$gBitSmarty->assign( 'subInfo', $subInfo );
$gBitSmarty->assign( 'unsubs', $unsubs );
$mid = 'bitpackage:newsletters/user_subscriptions.tpl';
$title = "Newsletter Subscriptions";
$gBitSmarty->assign( 'feedback', $feedback );
$gBitSystem->display( $mid, $title , array( 'display_mode' => 'display' ));
|