Beispiel #1
0
 protected function _addTranslation($key, $translation, $locale = null)
 {
     if ($locale === null) {
         $locale = LP_LOCALE;
     }
     $config = Mvc::getConfig();
     $main_template = $config->getData('template_name');
     $main_variation = $config->getData('template_variation');
     $file_path = $this->_getTranslationsFile($locale);
     $f = @fopen($file_path, 'a+');
     if ($f !== false) {
         $from = '';
         if ($main_template) {
             $from = $main_template;
             if ($main_variation) {
                 $from .= "/{$main_variation}";
             }
         }
         @fputcsv($f, array($key, $translation, 'UNTRANSLATED', $from), ",", "\"");
         fclose($f);
         // Reload translations
         if (array_key_exists($locale, self::$_cache)) {
             self::$_cache[$locale][$key] = $translation;
         }
     }
 }
Beispiel #2
0
 public function getCacheResponse()
 {
     // If cache is disabled
     if (!Mvc::getConfig()->getData('app.cache', true)) {
         return null;
     }
     // If POST no cache
     if (count($_POST) > 0) {
         return null;
     }
     // Get cache response
     $response = new Cache();
     return $response->hasCache() ? $response : null;
 }
Beispiel #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;
 }
Beispiel #4
0
<?php

$error_messages = \LandingPages\Mvc::getSession()->getErrorMessages();
$success_messages = \LandingPages\Mvc::getSession()->getSuccessMessages();
?>

<?php 
if ($success_messages) {
    ?>
    <div class="alert alert-success" role="alert">
        <?php 
    foreach ($success_messages as $message) {
        ?>
            <p><?php 
        echo $message;
        ?>
</p>
        <?php 
    }
    ?>
    </div>
<?php 
}
if ($error_messages) {
    ?>
    <div class="alert alert-danger" role="alert">
        <?php 
    foreach ($error_messages as $message) {
        ?>
            <p><?php 
        echo $message;
Beispiel #5
0
 public static function init()
 {
     Event::register('content', function ($content) {
         // Var assignation
         $content = preg_replace_callback('/{{var ([^=}]*)=([^}]*)}}/', function ($M) {
             $varname = trim($M[1]);
             $value = trim($M[2]);
             if (substr($value, 0, 3) == '~~~') {
                 $value = I18n::getSingleton()->translate(substr($value, 3));
             }
             Mvc::getResponse()->setData($varname, $value);
             return '';
         }, $content);
         // Var echo
         $content = preg_replace_callback('/{{var ([^}]*)}}/', function ($M) {
             return Mvc::getResponse()->getData(trim($M[1]));
         }, $content);
         // Translate
         $content = preg_replace_callback('/{{~~~([^}]*)}}/', function ($M) {
             return I18n::getSingleton()->translate(trim($M[1]));
         }, $content);
         // Asset URL
         $content = preg_replace_callback('/{{asset ([^}]*)}}/', function ($M) {
             return asset(ltrim(trim($M[1]), '/'));
         }, $content);
         // Page URL helper
         $content = preg_replace_callback('/{{url[ ]?([^}]*)}}/', function ($M) {
             return page_url(trim($M[1]));
         }, $content);
         // Template include
         $content = preg_replace_callback('/{{template ([^}]*)}}/', function ($M) {
             ob_start();
             template(trim($M[1]));
             return Event::filter('content', ob_get_clean());
         }, $content);
         // {{header Content-Type: text/plain}}
         $content = preg_replace_callback('/{{header ([^}]*)}}/', function ($M) {
             if (preg_match('/^([^:]*): (.*)$/', trim($M[1]), $L)) {
                 Mvc::getResponse()->addHeader(trim($L[1]), trim($L[2]));
             }
             return '';
         }, $content);
         // {{redirect template/name}}
         $content = preg_replace_callback('/{{redirect ([^}]*)}}/', function ($M) {
             Mvc::getResponse()->redirect(page_url(trim($M[1])));
             return '';
         }, $content);
         return $content;
     });
 }
Beispiel #6
0
 /**
  * @return null
  */
 public static function getFormKey()
 {
     $session = Mvc::getSession();
     if (!$session->issetData('_form_key') || !$session->getData('_form_key')) {
         $session->setData('_form_key', generate_form_key());
     }
     return $session->getData('_form_key');
 }
Beispiel #7
0
function get_locale_url_map()
{
    static $map;
    if (!$map) {
        $map = array();
        $config = \LandingPages\Mvc::getConfig()->getData();
        foreach ($config as $key => $value) {
            if (preg_match('/^locale\\.url\\.map\\.(.*)$/', $key, $M)) {
                $map[$M[1]] = normalize_locale_name($value);
            }
        }
    }
    return $map;
}
Beispiel #8
0
 /**
  * @return array|null
  */
 public static function getVisitId()
 {
     static $visit_id;
     if (!$visit_id) {
         $session = Mvc::getSession();
         if (!$session->issetData('visit_id')) {
             $session->setData('visit_id', self::generateId());
         }
         $visit_id = $session->getData('visit_id');
     }
     return $visit_id;
 }
Beispiel #9
0
 protected function _needToRedirect($when, $locale)
 {
     $config = Mvc::getConfig();
     $detect_methods = explode(',', $config->getData('locale.detect_methods'));
     if (in_array('url', $detect_methods) && $config->getData('locale.url_redirect_after.' . $when)) {
         $url_key = array_search($locale, get_locale_url_map());
         if ($url_key) {
             header('Location: ' . LP_BASE_URL . $url_key . '/');
             exit;
         }
     }
 }
Beispiel #10
0
 public function hasCache()
 {
     return Mvc::getConfig()->getData('app.cache', true) && $this->_expire > time();
 }
Beispiel #11
0
 /**
  * Session constructor.
  */
 public function __construct()
 {
     session_name(Mvc::getConfig()->getData('session.name', 'LPS'));
     session_start();
 }
Beispiel #12
0
 public function isCacheEnabled()
 {
     return $this->_cache && Mvc::getConfig()->getData('app.cache', true);
 }
Beispiel #13
0
 /**
  * @return Config
  */
 public function getConfig()
 {
     return Mvc::getConfig();
 }