public function __construct($id, $filename, $title, $documentation) { $number_of_segements = new SiteCommandLineArgument(array('-n', '--number-of-segments'), 'setNumberOfSegments', Deliverance::_('Sets the number of segments we want to split ' . 'the list into.')); $number_of_segements->addParameter('integer', Deliverance::_('--number-of-segments expects a single paramater.')); $this->addCommandLineArgument($number_of_segements); parent::__construct($id, $filename, $title, $documentation); $this->initLastSegments(); }
protected function runInternal() { parent::runInternal(); $list = $this->getList(); $segments = $this->getSegments(); if (count($segments)) { $this->debug(Deliverance::_('Updating Segment Counts') . "\n\n", true); foreach ($segments as $segment) { $this->updateSegment($list, $segment); } } else { $this->debug(Deliverance::_('No segments found. '), true); } $this->debug(Deliverance::_('All Done.') . "\n", true); }
protected function updateSegment(DeliveranceList $list, DeliveranceCampaignSegment $segment) { if ($list->isAvailable()) { $this->debug(sprintf(Deliverance::_('Updating ‘%s’... '), $segment->title)); try { $size = $list->getSegmentSize($segment->getSegmentOptions()); $segment->cached_segment_size = $size; $segment->save(); $locale = SwatI18NLocale::get(); $this->debug(sprintf(Deliverance::_('found %s subscribers.') . "\n", $locale->formatNumber($size))); } catch (DeliveranceApiConnectionException $e) { // ignore these exceptions. segment sizes will be updated next // time around. $this->debug(sprintf(Deliverance::_('list unavailable. Segment ‘%s’ was not updated.') . "\n", $segment->title)); } catch (Exception $e) { $e = new DeliveranceException($e); $e->processAndContinue(); $this->debug(sprintf(Deliverance::_('Update error. Segment ‘%s’ was not updated.') . "\n", $segment->title)); } } else { $this->debug(sprintf(Deliverance::_('Mailing list unavailable. Segment ‘%s’ was not updated.') . "\n", $segment->title)); } }
protected function buildInternal() { parent::buildInternal(); $dep = new AdminListDependency(); $dep->setTitle(Deliverance::_('newsletter'), Deliverance::_('newsletters')); $entries = array(); $newsletters = $this->getNewsletters(); foreach ($newsletters as $newsletter) { $entry = new AdminDependencyEntry(); $entry->title = $newsletter->getCampaignTitle(); $entry->status_level = $newsletter->isSent() ? AdminDependency::NODELETE : AdminDependency::DELETE; $entries[] = $entry; } $dep->entries = $entries; $message = $this->ui->getWidget('confirmation_message'); $message->content = $dep->getMessage(); $message->content_type = 'text/xml'; if ($dep->getStatusLevelCount(AdminDependency::DELETE) == 0) { $this->switchToCancelButton(); } }
protected function buildToolbars() { $toolbars = $this->ui->getRoot()->getDescendants('SwatToolbar'); foreach ($toolbars as $toolbar) { $toolbar->setToolLinkValues($this->newsletter->id); } // Preview link can be unavailable if the database save was successful, // but the mailing list call failed. $preview_link = $this->ui->getWidget('preview_link'); if ($this->newsletter->campaign_id === null) { $preview_link->sensitive = false; $preview_link->tooltip = Deliverance::_('This newsletter’s preview is not available due to connection ' . 'issues with the email service provider. Edit the newsletter ' . 'to enable the preview.'); } else { $campaign_type = $this->newsletter->instance instanceof SiteInstance ? $this->newsletter->instance->shortname : null; $campaign_class = DeliveranceCampaignFactory::get($this->app, $campaign_type); $this->ui->getWidget('preview_link')->link = call_user_func_array(array($campaign_class, 'getPreviewUrl'), array($this->app, $this->newsletter->campaign_id)); } if ($this->newsletter->isSent()) { $preview_link->title = Deliverance::_('View Email'); $this->ui->getWidget('edit_link')->visible = false; $this->ui->getWidget('delete_link')->visible = false; $this->ui->getWidget('cancel_link')->visible = false; $this->ui->getWidget('schedule_link')->visible = false; $this->ui->getWidget('send_preview_link')->visible = false; // reports may not exist yet if the newsletter was recently sent. $stats_link = $this->ui->getWidget('stats_link'); if ($this->newsletter->campaign_report_url === null) { $stats_link->sensitive = false; $stats_link->tooltip = Deliverance::_('This newletter’s status report will become available ' . 'shortly after the newsletter has been sent.'); } else { $stats_link->link = $this->newsletter->campaign_report_url; } } elseif ($this->newsletter->isScheduled()) { $this->ui->getWidget('edit_link')->visible = false; $this->ui->getWidget('stats_link')->visible = false; $this->ui->getWidget('delete_link')->visible = false; $this->ui->getWidget('send_preview_link')->visible = false; $this->ui->getWidget('schedule_link')->title = Deliverance::_('Reschedule Delivery'); } else { $this->ui->getWidget('stats_link')->visible = false; $this->ui->getWidget('cancel_link')->visible = false; } }
protected function addConfigDefinitions(SiteConfigModule $config) { parent::addConfigDefinitions($config); $config->addDefinitions(Deliverance::getConfigDefinitions()); }
/** * Translates a phrase * * This is an alias for {@link Deliverance::gettext()}. * * @param string $message the phrase to be translated. * * @return string the translated phrase. */ public static function _($message) { return Deliverance::gettext($message); }
protected function getExistingMemberMessage(DeliveranceList $list, $email) { // TODO: rewrite. $message = new SwatMessage(Deliverance::_('Thank you. Your email address was already subscribed to ' . 'our newsletter.'), 'notice'); $message->secondary_content = Deliverance::_('Your subscriber information has been updated, and you will ' . 'continue to receive mailings at this address.'); return $message; }
protected function getMessage() { $message = sprintf('<p>%s</p><p>%s</p>', Deliverance::_('The delivery of “%s” will canceled.'), Deliverance::_('The newsletter will not be deleted and can be ' . 'rescheduled for a later delivery date.')); return sprintf($message, $this->newsletter->subject); }
protected function buildSegments() { if (count($this->segments) > 0) { $segment_widget = $this->ui->getWidget('campaign_segment'); $segment_widget->parent->visible = true; $locale = SwatI18NLocale::get(); $last_instance_title = null; foreach ($this->segments as $segment) { if ($this->app->isMultipleInstanceAdmin() && $segment->instance instanceof SiteInstance && $last_instance_title != $segment->instance->title) { $last_instance_title = $segment->instance->title; $segment_widget->addDivider(sprintf('<span class="instance-header">%s</span>', $last_instance_title), 'text/xml'); } if ($segment->cached_segment_size > 0) { $subscribers = sprintf(Deliverance::ngettext('One subscriber', '%s subscribers', $segment->cached_segment_size), $locale->formatNumber($segment->cached_segment_size)); } else { $subscribers = Deliverance::_('No subscribers'); } $title = sprintf('%s <span class="swat-note">(%s)</span>', $segment->title, $subscribers); if ($segment->cached_segment_size > 0) { $segment_widget->addOption($segment->id, $title, 'text/xml'); } else { // TODO, use a real option and disable it. $segment_widget->addDivider($title, 'text/xml'); } } } }
protected function getConfirmationMessage() { $locale = SwatI18NLocale::get(); ob_start(); printf('<p>%s</p><p>%s</p>', sprintf(Deliverance::ngettext('The newsletter “%s” will be sent to one subscriber.', 'The newsletter “%s” will be sent to %s subscribers.', $this->send_count), $this->newsletter->subject, $locale->formatNumber($this->send_count)), Deliverance::_('Subscriber counts are estimates. Full statistics ' . 'will be available once the newsletter has been sent.')); return ob_get_clean(); }
protected function getMessage() { ob_start(); printf('<p>%s</p>', sprintf(Deliverance::_('A preview of the newsletter “%s” will be ' . 'sent to following email address.'), $this->newsletter->subject)); return ob_get_clean(); }
protected function handleResult($result, $success_message) { $clear_queued = parent::handleResult($result, $success_message); if (is_array($result)) { $clear_queued = true; $this->debug(sprintf($success_message, $result['success_count'])); // add count doesn't always exist. if (isset($result['add_count']) && $result['add_count']) { $this->debug(sprintf(Deliverance::_('%s addresses added.') . "\n", $result['add_count'])); } // update count doesn't always exist. if (isset($result['update_count']) && $result['update_count']) { $this->debug(sprintf(Deliverance::_('%s addresses updated.') . "\n", $result['update_count'])); } // Queued requests can exist in errors or in the result message // depending on the request type. $queued_count = 0; if (isset($result['queued_count']) && $result['queued_count']) { $queued_count = $result['queued_count']; } if ($result['error_count']) { $errors = array(); $not_found_count = 0; $bounced_count = 0; $previously_unsubscribed_count = 0; $invalid_count = 0; // don't throw errors for codes we know can be ignored. foreach ($result['errors'] as $error) { switch ($error['code']) { case DeliveranceMailChimpList::NOT_FOUND_ERROR_CODE: case DeliveranceMailChimpList::NOT_SUBSCRIBED_ERROR_CODE: $not_found_count++; break; case DeliveranceMailChimpList::PREVIOUSLY_UNSUBSCRIBED_ERROR_CODE: $previously_unsubscribed_count++; break; case DeliveranceMailChimpList::BOUNCED_ERROR_CODE: $bounced_count++; break; case DeliveranceMailChimpList::INVALID_ADDRESS_ERROR_CODE: $invalid_count++; break; case DeliveranceList::QUEUED: $queued_count++; break; default: $error_message = sprintf(Deliverance::_('code: %s - message: %s.'), $error['code'], $error['message']); $errors[] = $error_message; $execption = new SiteException($error_message); // don't exit on returned errors $execption->processAndContinue(); } } if ($not_found_count > 0) { $this->debug(sprintf(Deliverance::_('%s addresses not found.') . "\n", $not_found_count)); } if ($previously_unsubscribed_count > 0) { $this->debug(sprintf(Deliverance::_('%s addresses have previously subscribed, ' . 'and cannot be resubscribed.') . "\n", $previously_unsubscribed_count)); } if ($bounced_count > 0) { $this->debug(sprintf(Deliverance::_('%s addresses have bounced, and cannot be ' . 'resubscribed.') . "\n", $bounced_count)); } if ($invalid_count > 0) { $this->debug(sprintf(Deliverance::_('%s invalid addresses.') . "\n", $invalid_count)); } if (count($errors)) { $this->debug(sprintf(Deliverance::_('%s errors:') . "\n", count($errors))); foreach ($errors as $error) { $this->debug($error . "\n"); } } } if ($queued_count > 0) { $clear_queued = false; $this->debug(sprintf(Deliverance::_('%s addresses queued.') . "\n", $queued_count)); } } return $clear_queued; }
public function handleUpdateResponse($response) { switch ($response) { case DeliveranceList::NOT_FOUND: $message = new SwatMessage(Deliverance::_('Thank you. Your email address was never subscribed to ' . 'our newsletter.'), 'notice'); $message->secondary_content = Deliverance::_('You will not receive any mailings to this address.'); break; case DeliveranceList::NOT_SUBSCRIBED: $message = new SwatMessage(Deliverance::_('Thank you. Your email address has already been ' . 'unsubscribed from our newsletter.'), 'notice'); $message->secondary_content = Deliverance::_('You will not receive any mailings to this address.'); break; case DeliveranceList::FAILURE: $message = new SwatMessage(Deliverance::_('Sorry, there was an issue with updating your information.'), 'error'); $message->content_type = 'text/xml'; $message->secondary_content = sprintf(Deliverance::_('This can usually be resolved by trying again later. If ' . 'the issue persists, please <a href="%s">contact us</a>.'), $this->getContactUsLink()); $message->content_type = 'txt/xhtml'; break; default: $message = null; } return $message; }
public function getCampaignShortname() { if ($this->send_date === null) { $shortname = Deliverance::_('DRAFT'); } else { $shortname = $this->send_date->formatLikeIntl('yy-MM-dd'); } return $shortname; }