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; } } }
/** * @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"); }
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; }
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; }
/** * */ 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\" />"; }
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; } } }
public function hasCache() { return Mvc::getConfig()->getData('app.cache', true) && $this->_expire > time(); }
/** * Session constructor. */ public function __construct() { session_name(Mvc::getConfig()->getData('session.name', 'LPS')); session_start(); }
public function isCacheEnabled() { return $this->_cache && Mvc::getConfig()->getData('app.cache', true); }
/** * @return Config */ public function getConfig() { return Mvc::getConfig(); }