/** * Get singleton instance. */ public static function getInstance() { if (self::$instance === null) { self::$instance = new AvisotaBase(); } return self::$instance; }
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'); } }
/** * 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 element */ public function compile() { $id = $this->Input->get('items'); $pageId = $this->Input->get('page'); if (!$pageId) { $pageId = 0; } $limit = $this->perPage; $offset = $pageId * $limit; $newsletter = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_message WHERE sendOn > 0 AND pid IN (" . implode(',', $this->avisota_categories) . ") ORDER BY sendOn DESC"); if ($limit > 0) { $newsletter->limit($limit, $offset); } $newsletter = $newsletter->execute(); $viewPage = $this->jumpTo ? $this->getPageDetails($this->avisota_view_page) : false; $viewOnlineCache = array(); $newsletterDataSets = array(); while ($newsletter->next()) { $newsletterData = $newsletter->row(); $params = '/items/' . ($GLOBALS['TL_CONFIG']['disableAlias'] ? $newsletterData['id'] : $newsletterData['alias']); if ($viewPage) { $newsletterData['href'] = $this->generateFrontendUrl($viewPage->row(), $params); } else { if (!isset($viewOnlineCache[$newsletter->pid])) { $category = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_message_category WHERE id=?")->execute($newsletter->pid); if ($category->next()) { $viewOnlineCache[$newsletter->pid] = $this->Base->getViewOnlinePage($category); } else { $viewOnlineCache[$newsletter->pid] = false; } } if ($viewOnlineCache[$newsletter->pid]) { $newsletterData['href'] = $this->generateFrontendUrl($viewOnlineCache[$newsletter->pid]->row(), $params); } else { $newsletterData['href'] = ''; } } $newsletterDataSets[] = $newsletterData; } $template = new FrontendTemplate($this->avisota_list_template); $template->newsletters = $newsletterDataSets; $this->Template->list = $template->parse(); $newsletter = \Database::getInstance()->prepare("SELECT COUNT(id) as `count` FROM orm_avisota_message WHERE sendOn > 0 AND pid IN (" . implode(',', $this->avisota_categories) . ")")->execute(); $this->Template->limit = $limit; $this->Template->total = $newsletter->next() ? $newsletter->count : 0; }
protected function getTemplateGroup($prefix, $themeId = 0) { return AvisotaBase::getInstance()->getTemplateGroup($prefix, $themeId); }