Пример #1
0
 /**
  * Send test newsletter
  *
  * @return  void
  */
 public function doSendTestTask()
 {
     //vars needed for test sending
     $goodEmails = array();
     $badEmails = array();
     //get request vars
     $emails = Request::getVar('emails', '');
     $newsletterId = Request::getInt('nid', 0);
     //parse emails
     $emails = array_filter(array_map("strtolower", array_map("trim", explode(",", $emails))));
     //make sure we have valid email addresses
     foreach ($emails as $k => $email) {
         if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
             if (count($goodEmails) <= 4) {
                 $goodEmails[] = $email;
             } else {
                 $badEmails[] = $email;
             }
         } else {
             $badEmails[] = $email;
         }
     }
     //instantiate newsletter campaign object & load campaign
     $newsletterNewsletter = new Letter($this->database);
     $newsletterNewsletter->load($newsletterId);
     //build newsletter for sending
     $newsletterNewsletterHtmlContent = $newsletterNewsletter->buildNewsletter($newsletterNewsletter);
     $newsletterNewsletterPlainContent = $newsletterNewsletter->buildNewsletterPlainTextPart($newsletterNewsletter);
     //send campaign
     $this->_send($newsletterNewsletter, $newsletterNewsletterHtmlContent, $newsletterNewsletterPlainContent, $goodEmails, $newsletterMailinglist = null, $sendingTest = true);
     //do we have good emails to tell user about
     if (count($goodEmails)) {
         $message = Lang::txt('COM_NEWSLETTER_TEST_SEND_SUCCESS', $newsletterNewsletter->name, implode("<br />", $goodEmails));
         $type = 'success';
     }
     //do we have any bad emails to tell user about
     if (count($badEmails)) {
         $message = Lang::txt('COM_NEWSLETTER_TEST_SEND_FAIL', $newsletterNewsletter->name, implode("<br />", $badEmails));
         $type = 'error';
     }
     //redirect after sent
     App::redirect(Route::url('index.php?option=com_newsletter&controller=newsletter', false), $message, $type);
 }
Пример #2
0
 /**
  * Return data for past newsletters
  *
  * @apiMethod GET
  * @apiUri    /newsletters/archive
  * @apiParameter {
  * 		"name":          "limit",
  * 		"description":   "Number of result to return.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       5
  * }
  * @apiParameter {
  * 		"name":          "start",
  * 		"description":   "Number of where to start returning results.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       0
  * }
  * @return    void
  */
 public function archiveTask()
 {
     $limit = Request::getInt('limit', 5);
     $start = Request::getInt('start', 0);
     $result = array();
     $database = \App::get('db');
     $newsletterNewsletter = new Newsletter($database);
     // get newsletters
     $newsletters = $newsletterNewsletter->getNewsletters();
     // add newsletter details to return array
     foreach ($newsletters as $k => $newsletter) {
         $result[$k]['id'] = $newsletter->issue;
         $result[$k]['title'] = $newsletter->name;
         $result[$k]['content'] = $newsletterNewsletter->buildNewsletter($newsletter);
     }
     $obj = new stdClass();
     $obj->newsletters = $result;
     $this->send($obj);
 }