public function run()
 {
     // user have to be authenticated
     $this->User->authenticate();
     // read session data
     $sessionData = $this->Session->get('AVISOTA_PREVIEW');
     // get preview mode
     if ($this->Input->get('mode')) {
         $sessionData['mode'] = $this->Input->get('mode');
     }
     // fallback preview mode
     if (!$sessionData['mode']) {
         $sessionData['mode'] = NL_HTML;
     }
     /*
     // get personalized state
     if ($this->Input->get('personalized'))
     {
     	$arrSession['personalized'] = $this->Input->get('personalized');
     }
     
     // fallback personalized state
     if (!$arrSession['personalized'])
     {
     	$arrSession['personalized'] = 'anonymous';
     }
     */
     // store session data
     $this->Session->set('AVISOTA_PREVIEW', $sessionData);
     // find the newsletter
     $id = $this->Input->get('id');
     $newsletter = \Database::getInstance()->prepare("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\torm_avisota_message\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tid=?")->execute($id);
     if (!$newsletter->next()) {
         $this->log('Newsletter ID ' . $id . ' does not exists!', 'AvisotaNewsletterPreview', TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     // find the newsletter category
     $category = \Database::getInstance()->prepare("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\torm_avisota_message_category\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tid=?")->execute($newsletter->pid);
     if (!$category->next()) {
         $this->log('Category ID ' . $newsletter->pid . ' does not exists!', 'AvisotaNewsletterPreview', TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     // build the recipient data array
     $recipientData = $this->Base->getPreviewRecipient();
     $this->Static->set($category, $newsletter, $recipientData);
     // generate the preview
     switch ($sessionData['mode']) {
         case NL_HTML:
             header('Content-Type: text/html; charset=utf-8');
             echo $this->replaceInsertTags($this->Content->prepareBeforeSending($this->Content->generateHtml($newsletter, $category, $sessionData['personalized'])));
             exit(0);
         case NL_PLAIN:
             header('Content-Type: text/plain; charset=utf-8');
             echo $this->replaceInsertTags($this->Content->prepareBeforeSending($this->Content->generatePlain($newsletter, $category, $sessionData['personalized'])));
             exit(0);
         default:
             $this->log('Unsupported newsletter preview mode ' . var_export($sessionData['mode']) . '!', 'AvisotaNewsletterPreview', TL_ERROR);
             $this->redirect('contao/main.php?act=error');
     }
 }
Exemple #2
0
 /**
  * Show preview and send the Newsletter.
  *
  * @return string
  */
 public function send()
 {
     $id = $this->Input->get('id');
     $newsletter = AvisotaNewsletter::load($id);
     if (!$newsletter) {
         $this->redirect('contao/main.php?do=avisota_newsletter');
     }
     $category = AvisotaNewsletterCategory::load($newsletter->pid);
     if (!$category) {
         $this->redirect('contao/main.php?do=avisota_newsletter');
     }
     if (!$this->User->isAdmin) {
         if (!is_array($this->User->avisota_newsletter_categories) || count($this->User->avisota_newsletter_categories) < 1) {
             $root = array(0);
         } else {
             $root = $this->User->avisota_newsletter_categories;
         }
         if (!in_array($category->id, $root)) {
             $this->log('Not enough permissions to send newsletter from category ID ' . $category->id, 'Avisota::send()', TL_ERROR);
             $this->redirect('contao/main.php?act=error');
         }
     }
     AvisotaStatic::pushCategory($category);
     AvisotaStatic::pushNewsletter($newsletter);
     $template = new BackendTemplate('be_avisota_send');
     $template->import('BackendUser', 'User');
     // allow backend sending
     $template->beSend = $this->Base->allowBackendSending();
     // Store the current referer
     $session = $this->Session->get('referer');
     if ($session['current'] != $this->Environment->requestUri) {
         $session['orm_avisota_message'] = $this->Environment->requestUri;
         $session['last'] = $session['current'];
         $session['current'] = $this->Environment->requestUri;
         $this->Session->set('referer', $session);
     }
     $template->users = $this->getAllowedUsers();
     return $template->parse();
 }
 /**
  * Reset all data.
  */
 public static function reset()
 {
     self::$category = array();
     self::$newsletter = array();
     self::$recipientData = array();
 }
 /**
  * Return all template files of a particular group as array
  *
  * @author     Leo Feyer <http://www.contao.org>
  * @see        Controll::getTemplate in Contao OpenSource CMS
  *
  * @param string
  * @param integer
  *
  * @return array
  * @throws Exception
  */
 protected function getTemplateGroup($prefix, $themeId = 0)
 {
     $folders = array();
     $templates = array();
     // Add the templates root directory
     $folders[] = TL_ROOT . '/templates';
     // Add the theme templates folder
     if ($themeId > 0) {
         $theme = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_message_theme WHERE id=?")->limit(1)->execute($themeId);
         if ($theme->numRows > 0 && $theme->templateDirectory != '') {
             $folders[] = TL_ROOT . '/' . $theme->templateDirectory;
         }
     } else {
         $newsletter = AvisotaStatic::getNewsletter();
         // Check for a theme folder
         if ($newsletter) {
             $folders[] = TL_ROOT . '/' . $newsletter->getTheme()->getTemplateDirectory();
         }
     }
     // Add the module templates folders if they exist
     foreach ($this->Config->getActiveModules() as $module) {
         $folder = TL_ROOT . '/system/modules/' . $module . '/templates';
         if (is_dir($folder)) {
             $folders[] = $folder;
         }
     }
     // Find all matching templates
     foreach ($folders as $folder) {
         $files = preg_grep('/^' . preg_quote($prefix, '/') . '/i', scan($folder));
         foreach ($files as $file) {
             $filename = basename($file);
             $templates[] = substr($filename, 0, strrpos($filename, '.'));
         }
     }
     natcasesort($templates);
     $templates = array_values(array_unique($templates));
     return $templates;
 }
Exemple #5
0
 public function getCurrentTransport()
 {
     $newsletter = AvisotaStatic::getNewsletter();
     $category = AvisotaStatic::getCategory();
     if ($category && $category->transport && $category->setTransport == 'category') {
         $transportModuleId = $category->transport;
     } else {
         if ($newsletter && $newsletter->transport) {
             $transportModuleId = $newsletter->transport;
         } else {
             if ($category && $category->transport) {
                 $transportModuleId = $category->transport;
             } else {
                 $transportModuleId = 0;
             }
         }
     }
     return AvisotaTransport::getTransportModule($transportModuleId);
 }
 /**
  * Generate the content text for this newsletter.
  *
  * @return string
  */
 public function generateContentText($area)
 {
     if (!$this->theme instanceof AvisotaNewsletterTheme) {
         throw new Exception('A newsletter need a theme!');
     }
     AvisotaStatic::pushNewsletter($this);
     $content = '';
     if (isset($this->contentArray[$area])) {
         foreach ($this->contentArray[$area] as $element) {
             $content .= AvisotaNewsletterContent::getInstance()->generateNewsletterElement($element, NL_PLAIN);
         }
     }
     // reset static information
     AvisotaStatic::popNewsletter();
     return $content;
 }