function rewriter($module = '', $controller = '', $action = '', $get = '', $lang = '') { // Base URL $r = kw::$config['url_base']; // Actions $r .= kw::ses('lang') . '/'; $r .= ($module != '' ? $module : kw::get('m')) . '/'; $r .= ($controller != '' ? $controller : kw::get('c')) . '/'; $r .= ($action != '' ? $action : kw::get('a')) . '/'; // Final GET if ($get != '') { $r .= '?' . $get; } return $r; }
/** * @name templatePart * This function load a file located in $appdir/public/templates/$tempalte/$file * @param string $file File to include * @param string $cat_cache Category of cache * @param string $name_cache Name of cache * @param number $tcache Time in seconds maxium lifetime cache */ static function templatePart($file, $cat_cache = null, $name_cache = null, $tcache = null) { // If it would use cache if ($name_cache) { $cat_cache = kw::ses('lang') . '/' . $cat_cache; // If not have cache (so it will not loaded) if (!Cache::load('html', $cat_cache, $name_cache, $tcache)) { // Generate it ob_start(); require kw::$app_dir . 'public/templates/' . app::$template . '/' . $file . '.php'; cache::buildFromString('html', $cat_cache, $name_cache, ob_get_contents()); // Once end, it send information to client ob_end_flush(); } } else { // No cache, load directly require kw::$app_dir . 'public/templates/' . app::$template . '/' . $file . '.php'; } }
/** * @name loadLang This function select the preferred language to the user (if him not select any) */ static function loadlang() { // Intentamos leer el idioma del get $lang = kw::get('l', null); if (in_array($lang, kw::$config['languages'])) { // Language is correct, save it kw::ses('lang', $lang, true); } else { // Si el idioma no esta disponible lo intentamos coger de la SESSION $lang = null; //= kw::ses('lang', null); if ($lang == null) { // Como no hay un idioma predefinido, intentamos cargar el que mas le convenga al usuario // en funcion a la configuracion de su navegador // Si no encontramos ninguno relacionado utilizaremos el primero del array // Despues lo guardamos en la SESSION $lang = Language::prefered_language(kw::$config['languages']); kw::ses('lang', $lang, true); // Metodo alternativo (requiere PECL) //http_negotiate_language( kw::$config['languages'], $userlang ); } } // Setting language kw::$lang = $lang; }