Beispiel #1
0
 /**
  * Send Newsletter
  *
  * @return  void
  */
 public function doSendNewsletterTask()
 {
     //get request vars
     $newsletterId = Request::getInt('nid', 0);
     $mailinglistId = Request::getInt('mailinglist', '-1');
     //instantiate newsletter campaign object & load campaign
     $newsletterNewsletter = new Letter($this->database);
     $newsletterNewsletter->load($newsletterId);
     //check to make sure we have an object
     if (!is_object($newsletterNewsletter) || $newsletterNewsletter->name == '') {
         $this->setError(Lang::txt('COM_NEWSLETTER_UNABLE_TO_LOCATE'));
         $this->displayTask();
         return;
     }
     // make sure it wasnt deleted
     if ($newsletterNewsletter->deleted == 1) {
         $this->setError(Lang::txt('COM_NEWSLETTER_NEWSLETTER_SEND_DELETED'));
         $this->displayTask();
         return;
     }
     // get emails based on mailing list
     $newsletterMailinglist = new Mailinglist($this->database);
     // build newsletter for sending
     $newsletterNewsletterHtmlContent = $newsletterNewsletter->buildNewsletter($newsletterNewsletter);
     $newsletterNewsletterPlainContent = $newsletterNewsletter->buildNewsletterPlainTextPart($newsletterNewsletter);
     // send campaign
     // purposefully send no emails, will create later
     $newsletterMailing = $this->_send($newsletterNewsletter, $newsletterNewsletterHtmlContent, $newsletterNewsletterPlainContent, array(), $mailinglistId, $sendingTest = false);
     // array of filters
     $filters = array('lid' => $mailinglistId, 'status' => 'active', 'limit' => 10000, 'start' => 0, 'select' => 'email');
     // get count of emails
     $count = $newsletterMailinglist->getListEmailsCount($filters);
     $left = $count;
     // make sure we have emails
     if ($count < 1) {
         $this->setError(Lang::txt('COM_NEWSLETTER_NEWSLETTER_SEND_MISSING_RECIPIENTS'));
         $this->displayTask();
         return;
     }
     // add recipients at 10000 at a time
     while ($left >= 0) {
         // get emails
         $emails = $newsletterMailinglist->getListEmails($mailinglistId, 'email', $filters);
         // add recipeients
         $this->_sendTo($newsletterMailing, $emails);
         // nullify vars
         $emails = null;
         unset($emails);
         //adjust our start
         $filters['start'] += $filters['limit'];
         // remove from what we have left to get
         $left -= $filters['limit'];
     }
     //mark campaign as sent
     $newsletterNewsletter->sent = 1;
     if ($newsletterNewsletter->save($newsletterNewsletter)) {
         //redirect after sent
         App::redirect(Route::url('index.php?option=com_newsletter&controller=newsletter', false), Lang::txt('COM_NEWSLETTER_NEWSLETTER_SEND_TO', $newsletterNewsletter->name, number_format($count)));
     }
 }
 /**
  * Output Letter content as PDF
  * @return void
  */
 public function outputTask()
 {
     //get the newsletter id
     $id = $this->id;
     //instantiate campaign object
     $newsletterNewsletter = new Letter($this->database);
     //get newsletter
     $newsletter = $newsletterNewsletter->getNewsletters($id);
     //build url to newsletter with no html
     $newsletterUrl = 'https://' . $_SERVER['HTTP_HOST'] . DS . 'newsletter' . DS . $newsletter->alias . '?no_html=1';
     //path to newsletter file
     $newsletterPdfFolder = PATH_APP . DS . 'site' . DS . 'newsletter' . DS . 'pdf';
     $newsletterPdf = $newsletterPdfFolder . DS . $newsletter->alias . '.pdf';
     // check for upload path
     if (!is_dir($newsletterPdfFolder)) {
         // Build the path if it doesn't exist
         if (!\Filesystem::makeDirectory($newsletterPdfFolder)) {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&id=' . $id), Lang::txt('Unable to create the filepath.'), 'error');
             return;
         }
     }
     // check multiple places for wkhtmltopdf lib
     // fallback on phantomjs
     $cmd = '';
     $fallback = '';
     if (file_exists('/usr/bin/wkhtmltopdf') && file_exists('/usr/bin/xvfb-run')) {
         //$cmd = '/usr/bin/wkhtmltopdf ' . $newsletterUrl . ' ' . $newsletterPdf;
         $cmd = '/usr/bin/xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf ' . $newsletterUrl . ' ' . $newsletterPdf;
     } else {
         if (file_exists('/usr/local/bin/wkhtmltopdf') && file_exists('/usr/local/bin/xvfb-run')) {
             //$cmd = '/usr/local/bin/wkhtmltopdf ' . $newsletterUrl . ' ' . $newsletterPdf;
             $cmd = '/usr/local/bin/xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf ' . $newsletterUrl . ' ' . $newsletterPdf;
         }
     }
     if (file_exists('/usr/bin/phantomjs')) {
         $rasterizeFile = PATH_CORE . DS . 'components' . DS . 'com_newsletter' . DS . 'assets' . DS . 'js' . DS . 'rasterize.js';
         $fallback = '/usr/bin/phantomjs --ssl-protocol=any --ignore-ssl-errors=yes --web-security=false ' . $rasterizeFile . ' ' . $newsletterUrl . ' ' . $newsletterPdf . ' 8.5in*11in';
         if (!$cmd) {
             $cmd = $fallback;
         }
     }
     if (isset($cmd)) {
         // exec command
         exec($cmd, $ouput, $status);
         // wkhtmltopdf failed, so let's try phantomjs
         if (!file_exists($newsletterPdf) && $fallback && $cmd != $fallback) {
             exec($fallback, $ouput, $status);
         }
     }
     //make sure we have a file to output
     if (!file_exists($newsletterPdf)) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&id=' . $id), Lang::txt('COM_NEWSLETTER_VIEW_OUTPUT_PDFERROR'), 'error');
         return;
     }
     //output as attachment
     header("Content-type: application/pdf");
     header("Content-Disposition: attachment; filename=" . str_replace(' ', '_', $newsletter->name) . ".pdf");
     header("Pragma: no-cache");
     header("Expires: 0");
     echo file_get_contents($newsletterPdf);
     exit;
 }
Beispiel #3
0
 /**
  * View Tracking Information task
  *
  * @return 	void
  */
 public function trackingTask()
 {
     //get request vars
     $ids = Request::getVar('id', array());
     $id = isset($ids) ? $ids[0] : null;
     //instantiate newsletter mailing object
     $newsletterMailing = new NewsletterMailing($this->database);
     $mailing = $newsletterMailing->getMailings($id);
     //get mailing recipients
     $newsletterMailingRecipient = new MailingRecipient($this->database);
     $this->view->recipients = $newsletterMailingRecipient->getRecipients($id, 'sent');
     //instantiate newsletter object
     $newsletterNewsletter = new Newsletter($this->database);
     $newsletterNewsletter->load($mailing->nid);
     //make sure we are supposed to be tracking
     if (!$newsletterNewsletter->tracking) {
         $this->setError(Lang::txt('COM_NEWSLETTER_MAILING_NOT_TRACKING'));
         $this->displayTask();
         return;
     }
     //get bounces
     $sql = "SELECT * FROM `#__email_bounces`\n\t\t\t\tWHERE component='com_newsletter'\n\t\t\t\tAND object=" . $this->database->quote('Campaign Mailing') . "\n\t\t\t\tAND object_id=" . $this->database->quote($id);
     $this->database->setQuery($sql);
     $this->view->bounces = $this->database->loadObjectList();
     //new mailing recipient action object
     $newsletterMailingRecipientAction = new MailingRecipientAction($this->database);
     //get opens, clicks, forwards, and prints
     $this->view->opens = $newsletterMailingRecipientAction->getMailingActions($id, 'open');
     $this->view->forwards = $newsletterMailingRecipientAction->getMailingActions($id, 'forward');
     $this->view->prints = $newsletterMailingRecipientAction->getMailingActions($id, 'print');
     //get opens geo
     $this->view->opensGeo = $this->getOpensGeoTask($id);
     //get clicks and process
     $clicks = $newsletterMailingRecipientAction->getMailingActions($id, 'click');
     $this->view->clicks = array();
     foreach ($clicks as $click) {
         //get click action
         $clickAction = json_decode($click->action_vars);
         $this->view->clicks[$clickAction->url] = isset($this->view->clicks[$clickAction->url]) ? $this->view->clicks[$clickAction->url] + 1 : 1;
     }
     // Set any errors
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     // Output the HTML
     $this->view->setLayout('tracking')->display();
 }
 /**
  * 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);
 }