Example #1
0
 /**
  *
  *
  * @param $template
  * @param null $variation
  *
  * @return $this|bool
  *
  * @throws \Exception
  */
 public function register($template, $variation = null)
 {
     $id = self::getVisitId();
     $uri = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
     if (!Template::exists($template)) {
         return false;
     }
     if ($variation && !Template::isVariation($template, $variation)) {
         return false;
     }
     // Registro visita general
     $visit = new Visits();
     $visit->register($id, $uri, $template, $variation);
     // Registro visitas plantilla
     $this->load(array('template' => $template, 'variation' => $variation));
     if ($this->getId()) {
         $this->setData('views', $this->getViews() + 1);
         $conversions = new Conversions();
         $conversions->recalculateRates($template, $variation, $this->getViews());
     } else {
         $this->setData('template', $template);
         $this->setData('variation', $variation);
         $this->setData('views', 1);
         $this->setData('conversions', 0);
     }
     return $this->save();
 }
Example #2
0
 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);
 }
Example #3
0
 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;
 }