protected function _getToken($uri) { $config = Mvc::getConfig(); // Have we a URI? if ($uri) { // Is a landing template? if (preg_match('/^(.*)\\.html$/', $uri, $M)) { // Translate URI to get the right template //return $this->_getLandingToken( __URL($M[1]) ); $i18n = new I18n(); return $this->_getLandingToken($i18n->untranslateUrl($M[1])); } // ...else it should be a token return $uri; } // Check home.landing (template) if ($template = $config->getData('home.landing')) { return $this->_getLandingToken($template); } // Check home.token (controller/action) if ($token = $config->getData('home.token')) { return $token; } return 'index/index'; }
public static function init() { Event::register('content', function ($content) { // Block: template with cache return preg_replace_callback('/{{block ([^}]*)}}/', function ($M) { $params = array(); $parameters = preg_replace_callback('/([a-zA-Z_0-9]*)=([^"]{1}[^ ]*)/', function ($S) { return "{$S[1]}=\"{$S[2]}\""; }, $M[1]); // template vars if (preg_match_all('/([a-zA-Z_0-9]*)="([^"]*)"/', $parameters, $L, PREG_SET_ORDER)) { foreach ($L as $param) { $varname = trim($param[1]); $value = trim($param[2]); if (substr($value, 0, 3) == '~~~') { $value = I18n::getSingleton()->translate(substr($value, 3)); } $params[$varname] = $value; } } // config vars $block_key = "block.{$params['template']}."; $block_key_length = strlen($block_key); foreach (Mvc::getConfig()->getData() as $key => $value) { if (substr($key, 0, $block_key_length) == $block_key) { $varname = trim(substr($key, $block_key_length)); $value = trim($value); if (substr($value, 0, 3) === '~~~') { $value = I18n::getSingleton()->translate(substr($value, 3)); } $params[$varname] = $value; } } return Block::factory($params)->getHtml(); }, $content); }); }
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; }); }