public function exec() { // Download binary file if ($this->_binary_file) { // Send headers $this->_sendHeaders(); // Send file readfile($this->_binary_file); exit; } // 404? (without template) if (!$this->_template || !Template::exists($this->_template) && $this->_template != '_404') { $this->setData('cache.excluded', true); $this->_template = '_404'; } // Output timer('start', 'template_parse'); ob_start(); Template::parse($this->_template, $this->_data); $content = ob_get_clean(); $content = Event::filter('content', $content); timer('end', 'template_parse'); // If not excluding cache, then save cache if (!$this->getData('cache.excluded')) { Cache::factory()->save($this->_headers, $content, $this->getData('page_ttl')); } // Send headers $this->_sendHeaders(); // Send content echo Event::filter('cache', $content); }
public function getSessionVariation($template) { $this->load(Stats::getVisitId()); if ($this->getTemplate() == $template && Template::isVariation($template, $this->getVariation())) { return $this->getVariation(); } return null; }
function form_begin($conversion_key = null) { global $form_begin; $form_begin = true; echo "<form class=\"landing-pages-form\" action=\"" . \LandingPages\Template::getFormAction() . "\" method=\"post\">"; echo \LandingPages\Template::getFormKeyHtml(); if ($conversion_key !== null) { echo "<input type=\"hidden\" name=\"_CONVERSION\" value=\"{$conversion_key}\" />"; } }
/** * Find the less visited variation of template * * @param $template * * @return mixed * * @throws \Exception */ public function getLessVisitedVariation($template) { $variations = Template::getTemplateVariations($template); $data = array_combine($variations, array_pad(array(), count($variations), 0)); $collection = $this->resetCollection()->addFieldToFilter('template', $template)->collection(); /** @var Stats $item */ foreach ($collection as $item) { if (array_key_exists($item->getVariation(), $data)) { $data[$item->getVariation()] = $item->getViews(); } } asort($data); return array_shift(array_keys($data)); }
public function actionPost() { // Template $template_name = $this->getParam('template'); $response = $this->getResponse(); // we need a form_key from session to validate this come from a template form if ($this->getSession()->getData('_form_key') != $this->getParam('_form_key')) { $this->getSession()->addErrorMessage(__('Sorry. There were any errors. Please, try again in a few minutes.')); if ($template_name && Template::exists($template_name)) { $response->redirect(Template::getTemplateUrl($template_name)); } else { $response->redirect(LP_URL); } } else { // Hooks manager try { Mvc::getModel('hooks')->exec($template_name, $_POST); if (isset($_POST['success_template']) && Template::exists($_POST['success_template'])) { $template = $_POST['success_template']; } else { $template = $template_name; } // TODO: get messages from form $this->getSession()->addSuccessMessage(__('Thank you for your submit!')); $response->redirect(Template::getTemplateUrl($template)); } catch (Exception $e) { if (isset($_POST['error_template']) && Template::exists($_POST['error_template'])) { $template = $_POST['error_template']; } else { $template = $template_name; } $this->getSession()->addErrorMessage(__('Sorry. There were any errors. Please, try again in a few minutes.')); $response->redirect(Template::getTemplateUrl($template)); } } return $response; }
public function getHtml() { if ($this->hasCache()) { $this->_content = file_get_contents($this->getCacheFile()); } else { ob_start(); Template::parse($this->_template, $this->_data); $this->_content = Event::filter('content', ob_get_clean()); if ($this->isCacheEnabled()) { @mkdir(dirname($this->getCacheFile()), 0777, true); file_put_contents($this->getCacheFile(), $this->_content); if ($ttl = $this->getData('ttl')) { file_put_contents($this->getCacheFile() . '.expire', "{$ttl}"); } else { @unlink($this->getCacheFile() . '.expire'); } } } return $this->_content; }