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
 /**
  * @param $name
  * @param array $params
  */
 public static function parse($template_name, $params = array())
 {
     if (is_array($GLOBALS)) {
         extract($GLOBALS);
     }
     if (is_array($params)) {
         extract($params);
     }
     $session = Mvc::getSession();
     $request = Mvc::getRequest();
     $response = Mvc::getResponse();
     $config = Mvc::getConfig();
     $router = Mvc::getRouter();
     $dispatcher = Mvc::getDispatcher();
     foreach ($params as $varname => $value) {
         $response->setData($varname, $value);
     }
     unset($varname, $value, $params);
     foreach (array(LP_APP_DIRECTORY, LP_DEFAULT_APP_DIRECTORY, LP_ROOT_DIRECTORY) as $_dir) {
         $template_path = "{$_dir}/templates/{$template_name}.php";
         if (is_file($template_path)) {
             // Execute the template
             require $template_path;
             return;
         }
     }
     throw new \Exception("Template not found: /templates/{$template_name}.php");
 }
Beispiel #3
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 #4
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 #5
0
 /**
  *
  */
 public static function getHtmlPixel()
 {
     //global $main_template, $main_variation;
     $config = Mvc::getConfig();
     $main_template = $config->getData('template_name');
     $main_variation = $config->getData('template_variation');
     $url = LP_BASE_URI . "stats/visit/pixel.png?la={$main_template}&va={$main_variation}";
     echo "<img src=\"{$url}\" width=\"1\" height=\"1\" />";
 }
Beispiel #6
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 #7
0
 public function hasCache()
 {
     return Mvc::getConfig()->getData('app.cache', true) && $this->_expire > time();
 }
Beispiel #8
0
 /**
  * Session constructor.
  */
 public function __construct()
 {
     session_name(Mvc::getConfig()->getData('session.name', 'LPS'));
     session_start();
 }
Beispiel #9
0
 public function isCacheEnabled()
 {
     return $this->_cache && Mvc::getConfig()->getData('app.cache', true);
 }
Beispiel #10
0
 /**
  * @return Config
  */
 public function getConfig()
 {
     return Mvc::getConfig();
 }