static function generateDeliveryForNewsletter($node)
 {
     // TODO: Should use a different method / datatype
     // Better with string
     $data_map = $node->DataMap();
     $status = $data_map['status'];
     $status->fromString("in progress");
     $status->store();
     $subscribers = jajNewsletterSubscription::fetchUniqueForNewsletterId($node->ID, false);
     $result = 0;
     foreach ($subscribers as $subscription) {
         $row = array("contentobject_id" => $node->ID, "uuid" => $subscription['uuid'], "email" => $subscription['email'], "state" => "pending", "created" => time());
         $delivery = new jajNewsletterDelivery($row);
         $delivery->store();
         $result += 1;
     }
     return $result;
 }
Esempio n. 2
0
<?php

$Module = $Params['Module'];
$tpl = eZTemplate::factory();
$http = eZHTTPTool::instance();
$newsletter_id = $Params['NewsletterID'];
$node = eZContentObject::fetch($newsletter_id);
if (!$node || !$node->canRead()) {
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
if ($Module->isCurrentAction('SendNewsletter')) {
    $result = jajNewsletterDelivery::generateDeliveryForNewsletter($node);
    $http->setSessionVariable('NewsletterSent', $result);
}
if ($Module->isCurrentAction('Cancel') || $Module->isCurrentAction('SendNewsletter')) {
    return $Module->redirectTo($Module->functionURI("newsletter") . "/" . $node->mainNodeID());
}
$tpl->setVariable('node', $node);
// TODO: Fix with own counter function
$unique_recipients = count(jajNewsletterSubscription::fetchUniqueForNewsletterId($node->ID, false));
$tpl->setVariable('unique_recipients', $unique_recipients);
$Result = array('content' => $tpl->fetch('design:jaj_newsletter/newsletters/send.tpl'), 'path' => array(array('url' => 'jaj_newsletter/index', 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Newsletter')), array('url' => 'jaj_newsletter/newsletters', 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Newsletters')), array('url' => 'jaj_newsletter/newsletter/' . $node->mainNodeID(), 'text' => $node->attribute('name')), array('url' => false, 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Send Newsletter'))));
Esempio n. 3
0
} else {
    if ($Module->actionParameter('SubscriptionListID')) {
        $ListID = $Module->actionParameter('SubscriptionListID');
        $template = 'design:jaj_newsletter/subscription/new_from_list.tpl';
    } else {
        $template = 'design:jaj_newsletter/subscription/new_from_list.tpl';
    }
}
$list = jajNewsletterSubscriptionList::fetch($ListID);
$tpl = eZTemplate::factory();
//    return $Module->handleError( eZError::KERNEL_NOT_FOUND, 'kernel' );
if ($Module->isCurrentAction('Subscribe') && is_object($list)) {
    $name = trim($Module->actionParameter('SubscriptionName'));
    $email = trim($Module->actionParameter('SubscriptionEmail'));
    $messages = array();
    $subscription = jajNewsletterSubscription::addSubscription($email, $name, $list);
    if ($subscription->attribute('state') == 'deleted') {
        $template = 'design:jaj_newsletter/subscription/deny.tpl';
    } else {
        if (!$subscription->isValid($messages)) {
            $tpl->setVariable('is_valid', false);
            $tpl->setVariable('validation_messages', $messages);
        } else {
            try {
                if ($subscription->State == 'unconfirmed') {
                    $subscription->sendConfirmationMail($list);
                }
                $template = 'design:jaj_newsletter/subscription/success.tpl';
            } catch (Exception $e) {
                $tpl->setVariable('is_error', true);
                $tpl->setVariable('error_messages', explode('\\n', $e->getMessage()));
Esempio n. 4
0
}
switch (eZPreferences::value('admin_jaj_newsletter_subscription_list_limit')) {
    case '25':
        $limit = 25;
        break;
    case '50':
        $limit = 50;
        break;
    default:
        $limit = 10;
        break;
}
$offset = $Params['Offset'];
$tpl = eZTemplate::factory();
$ViewState = $Params['ViewState'];
$SubscriptionStates = jajNewsletterSubscription::states();
if (!in_array($ViewState, $SubscriptionStates)) {
    $ViewState = $SubscriptionStates[0];
}
for ($i = 0; $i < count($SubscriptionStates); $i++) {
    $id = $SubscriptionStates[$i];
    $SubscriptionStates[$i] = array('id' => $id, 'name' => ucwords($id), 'count' => $list->fetchSubscribersCount($id), 'selected' => $id == $ViewState, 'first' => $i == 0);
    if ($id == $ViewState) {
        $ItemCount = $SubscriptionStates[$i]['count'];
    }
}
$subscribers = $list->fetchSubscribersByState($ViewState, $limit, $offset);
$viewParameters = array('offset' => $offset);
$tpl->setVariable('view_state', $ViewState);
$tpl->setVariable('list', $list);
$tpl->setVariable('subscriber_states', $SubscriptionStates);
Esempio n. 5
0
    case '50':
        $limit = 50;
        break;
    default:
        $limit = 10;
        break;
}
$view_parameters = array('offset' => $offset);
$deliveries = jajNewsletterDelivery::fetchDeliveriesByContentobjectID($node->ID, $limit, $offset);
$deliveries_count = jajNewsletterDelivery::fetchDeliveriesByContentobjectIdCount($node->ID);
$newsletter_ini = eZINI::instance('jaj_newsletter.ini');
$from_email = $newsletter_ini->variable('NewsletterSettings', 'FromEmail');
$from_name = $newsletter_ini->variable('NewsletterSettings', 'FromName');
$reply_email = $newsletter_ini->variable('NewsletterSettings', 'ReplyEmail');
$tpl->setVariable('node', $node);
$tpl->setVariable('recipients_lists', $recipients_lists);
$tpl->setVariable('tabs', $tabs);
$tpl->setVariable('selected_tab', $selected_tab);
$tpl->setVariable('error_strings', $error_strings);
$tpl->setVariable('feedback_strings', $feedback_strings);
$tpl->setVariable('total_active_recipients', jajNewsletterSubscription::countByRecipientsLists($recipients_lists, 'active'));
$tpl->setVariable('total_recipients', jajNewsletterSubscription::countByRecipientsLists($recipients_lists));
$tpl->setVariable('from_email', $from_email);
$tpl->setVariable('from_name', $from_name);
$tpl->setVariable('reply_email', $reply_email);
$tpl->setVariable('deliveries', $deliveries);
$tpl->setVariable('deliveries_count', $deliveries_count);
$tpl->setVariable('set_limit', $limit);
$tpl->setVariable('offset', $offset);
$tpl->setVariable('view_parameters', $view_parameters);
$Result = array('content' => $tpl->fetch('design:jaj_newsletter/newsletters/view.tpl'), 'path' => array(array('url' => 'jaj_newsletter/index', 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Newsletter')), array('url' => 'jaj_newsletter/newsletters', 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Newsletters')), array('url' => false, 'text' => $node->attribute('name'))));
 public function createSubscribersFromList(&$subscribers, &$messages = array())
 {
     $list = explode("\n", $subscribers);
     $returnList = array();
     $user = eZUser::currentUser();
     $user_id = $user->attribute("contentobject_id");
     $date_time = time();
     foreach ($list as $line) {
         list($email, $name) = explode(',', $line);
         if (strpos($name, "@") !== false) {
             list($email, $name) = array($name, $email);
         }
         list($email, $name) = array(trim($email), trim($name));
         $subscriber = $this->fetchSubscriberByEmail($email);
         $action = "ignore";
         if ($subscriber == NULL) {
             $subscriber = jajNewsletterSubscription::create();
             $subscriber->setAttribute('email', $email);
             $subscriber->setAttribute('name', $name);
             $subscriber->setAttribute('subscription_list_id', $this->ID);
             $subscriber->setAttribute('state', 'active');
             $subscriber->setAttribute('subscribed', $date_time);
             $subscriber->setAttribute('created', $date_time);
             $subscriber->setAttribute('creator_id', $user_id);
             $action = $subscriber->isValid() ? "add" : "invalid";
         } else {
             if ($subscriber->attribute('state') == 'active' && $name) {
                 $subscriber->setAttribute('name', $name);
                 $action = $subscriber->isValid() ? "update" : "invalid";
             }
         }
         if ($action == 'add' || $action == 'update') {
             $subscriber->setAttribute('modified', $date_time);
             $subscriber->setAttribute('modifier_id', $user_id);
             $subscriber->store();
         } else {
             if ($action == 'invalid') {
                 array_push($returnList, $line);
             }
         }
         $messages[$action] = isset($messages[$action]) ? $messages[$action] + 1 : 1;
     }
     $subscribers = implode("\n", $returnList);
 }
        $result = $bouncehandler->get_the_facts($raw_message);
        $result = $result[0];
        $status = $result['status'];
        $action = $result['action'];
        $recipient = trim($result['recipient']);
        if (!in_array($action, array("delayed", "failed", "autoreply"))) {
            $cli->output("Message index: {$index}, unknown action: {$action}, skipping...");
            continue;
        }
        if ($action == 'delayed' || $action == 'autoreply') {
            $cli->output("Deleting message: {$index}, action: {$action}");
            $pop3->delete($index);
            continue;
        }
        if ($action == 'failed') {
            $cli->output("Message index: {$index}, status: {$status}, action: {$action}, recipient: {$recipient}");
            $subscriptions = jajNewsletterSubscription::fetchActiveByEmail($recipient);
            foreach ($subscriptions as $subscription) {
                $state = $subscription->attribute("state");
                if ($state == "active") {
                    $cli->output("Found matching subscription: " . $subscription->attribute("uuid") . " changing status from: " . $subscription->attribute("state") . " to: bounced");
                    $subscription->setAttribute('state', 'bounced');
                    $subscription->setAttribute('bounced', time());
                    $subscription->setAttribute('modified', time());
                    $subscription->store();
                }
            }
            $pop3->delete($index);
        }
    } while ($set->nextMail());
}
Esempio n. 8
0
<?php

$Module = $Params['Module'];
$UUID = $Params['UUID'];
$valid = true;
$subscription = jajNewsletterSubscription::fetchByUUID($UUID);
$list = null;
if (!is_object($subscription)) {
    $valid = false;
} else {
    $list = $subscription->subscriptionList();
    if (!is_object($list)) {
        $valid = false;
    } else {
        $valid = $subscription->confirm();
    }
}
$tpl = eZTemplate::factory();
$template = 'design:jaj_newsletter/subscription/confirm.tpl';
$tpl->setVariable('list', $list);
$tpl->setVariable('subscription', $subscription);
$tpl->setVariable('valid', $valid);
$Result = array('path' => $path, 'content' => $tpl->fetch($template));
?>

Esempio n. 9
0
<?php

$Module = $Params['Module'];
$tpl = eZTemplate::factory();
$template = 'design:jaj_newsletter/subscription/unsubscribe.tpl';
$uuid = $Params['UUID'];
$subscription = jajNewsletterSubscription::fetchByUUID($uuid);
if (!is_object($subscription)) {
    return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
}
if ($Module->isCurrentAction('ConfirmUnsubscribe')) {
    if ($subscription->attribute("state") == "active") {
        $result = jajNewsletterSubscription::unsubscribeByUUID($subscription->attribute("uuid"));
    }
}
$subscriptions = jajNewsletterSubscription::fetchActiveByEmail($subscription->attribute('email'));
$tpl->setVariable('subscription', $subscription);
$tpl->setVariable('subscriptions', $subscriptions);
$Result = array('path' => array(array('url' => false, 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Newsletter')), array('url' => false, 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Unsubscribe'))), 'content' => $tpl->fetch($template));
 public static function addSubscription($email, $name, $list, $force_active = false)
 {
     $date_time = time();
     $userId = eZUser::currentUser()->attribute("contentobject_id");
     $subscription = $list->fetchSubscriberByEmail($email);
     $defaultState = $list->confirmationRequired() && !$force_active ? 'unconfirmed' : 'active';
     if ($subscription) {
         $currentState = $subscription->attribute("state");
         if ($currentState == 'active') {
             if ($name) {
                 $subscription->setAttribute('name', $name);
                 $subscription->store();
             }
             return $subscription;
         } else {
             if ($currentState == 'unsubscribed') {
                 $subscription->setAttribute('unsubscribed', 0);
             } else {
                 if ($currentState == 'bounced') {
                     $subscription->setAttribute('bounced', 0);
                 } else {
                     if ($currentState == 'deleted') {
                         return $subscription;
                     }
                 }
             }
         }
     } else {
         $subscription = new jajNewsletterSubscription();
         $subscription->setAttribute('subscribed', $date_time);
         $subscription->setAttribute('email', $email);
         $subscription->setAttribute('subscription_list_id', $list->ID);
         $subscription->setAttribute('created', $date_time);
         $subscription->setAttribute('creator_id', $userId);
     }
     $confirmed_time = $defaultState == 'active' ? $date_time : 0;
     if ($name) {
         $subscription->setAttribute('name', $name);
     }
     $subscription->setAttribute('state', $defaultState);
     $subscription->setAttribute('confirmed', $confirmed_time);
     $subscription->setAttribute('modified', $date_time);
     $subscription->setAttribute('modifier_id', $userId);
     if ($subscription->isValid()) {
         $subscription->store();
     }
     return $subscription;
 }