/** * 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(); }
/** * 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; }