示例#1
0
 /**
  * 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;
 }
示例#2
0
 /**
  * Display send newsletter form
  *
  * @return  void
  */
 public function sendNewsletterTask()
 {
     // get the request vars
     $ids = Request::getVar("id", array());
     $id = isset($ids[0]) ? $ids[0] : null;
     // make sure we have an id
     if (!$id) {
         $this->setError(Lang::txt('COM_NEWSLETTER_SELECT_NEWSLETTER_FOR_MAILING'));
         $this->displayTask();
         return;
     }
     // get the newsletter
     $newsletterNewsletter = new Letter($this->database);
     $this->view->newsletter = $newsletterNewsletter->getNewsletters($id);
     // get newsletter mailing lists
     $newsletterMailinglist = new Mailinglist($this->database);
     $this->view->mailinglists = $newsletterMailinglist->getLists();
     // get the mailings
     $newsletterMailing = new Mailing($this->database);
     $this->view->mailings = $newsletterMailing->getMailings(null, $id);
     // get # left to send
     foreach ($this->view->mailings as $k => $mailing) {
         $this->database->setQuery("SELECT COUNT(*) FROM `#__newsletter_mailing_recipients` WHERE mid=" . $this->database->quote($mailing->id) . " AND status='queued'");
         $mailing->queueCount = $this->database->loadResult();
     }
     // check if we have any errors
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     // vars for view
     $this->view->database = $this->database;
     // Output the HTML
     $this->view->setLayout('send')->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);
 }