public static function boot() { Cli::show("Start of execution", 'COMMENT'); View::cleanCache(); Database::cleanCache(); Utils::cleanCache(true); Cli::show("End of execution", 'COMMENT'); }
private function display($page) { $v = $this; $e = function ($_) use($v) { return $v->show($_); }; $cache = container()->redis(); $keyHtml = 'cms::pages::' . sha1($page) . '::html'; $keyAge = 'cms::pages::' . sha1($page) . '::age'; $age = filemtime($page); $cached = $cache->get($keyHtml); $useCache = APPLICATION_ENV == 'production'; if (strlen($cached) && $useCache) { $aged = $cache->get($keyAge); if ($aged == $age) { echo $cached; echo View::showStats(); exit; } } $content = fgc($page); $config = $this->getConfigPage($content); eval($config); $templateFile = $this->themeDir . DS . $template . '.html'; if (File::exists($templateFile)) { $html = fgc($templateFile); $html = $this->parse($config, $html, $this->getHtml($content)); ob_start(); eval(' ?>' . $html . '<?php '); $content = ob_get_contents(); ob_end_clean(); if ($useCache) { $cache->set($keyAge, $age); $cache->set($keyHtml, $content); } echo $content; echo View::showStats(); exit; } }
public static function run() { Request::$route = $route = Utils::get('appDispatch'); container()->setRoute($route); $render = $route->getRender(); $tplDir = $route->getTemplateDir(); $module = $route->getModule(); $controller = $route->getController(); $action = $route->getAction(); $alert = $route->getAlert(); $page = container()->getPage(); $isCms = !empty($page); if (!empty($render)) { $tplMotor = $route->getTemplateMotor(); $tplDir = empty($tplDir) ? APPLICATION_PATH . DS . SITE_NAME . DS . 'app' . DS . 'views' : $tplDir; $tpl = $tplDir . DS . $render . '.phtml'; if (File::exists($tpl)) { if ('Twig' == $tplMotor) { if (!class_exists('Twig_Autoloader')) { require_once 'Twig/Autoloader.php'; } $tab = explode(DS, $tpl); $file = Arrays::last($tab); $path = repl(DS . $file, '', $tpl); $loader = new \Twig_Loader_Filesystem($path); $view = new \Twig_Environment($loader, array('cache' => CACHE_PATH, 'debug' => false, 'charset' => 'utf-8', 'strict_variables' => false)); container()->setView($view); if ($action instanceof Closure) { $action($view); } $params = null === container()->getViewParams() ? array() : container()->getViewParams(); echo $view->render($file, $params); /* stats */ if (null === container()->getNoShowStats() && null === $route->getNoShowStats()) { echo View::showStats(); } } else { $view = new View($tpl); container()->setView($view); if ($action instanceof Closure) { $action($view); } $view->render(); /* stats */ if (null === container()->getNoShowStats() && null === $route->getNoShowStats()) { echo View::showStats(); } } return; } } $module = Inflector::lower($module); $controller = Inflector::lower($controller); $action = Inflector::lower($action); if (true === container()->getMultiSite()) { $moduleDir = APPLICATION_PATH . DS . SITE_NAME . DS . 'modules' . DS . $module; } else { $moduleDir = APPLICATION_PATH . DS . 'modules' . DS . $module; } if (!is_dir($moduleDir)) { throw new Exception("The module '{$module}' does not exist."); } $controllerDir = $moduleDir . DS . 'controllers'; if (!is_dir($controllerDir)) { throw new Exception("The controller '{$controller}' does not exist."); } $controllerFile = $controllerDir . DS . $controller . 'Controller.php'; if (!File::exists($controllerFile)) { throw new Exception("The controller '{$controllerFile}' does not exist."); } require_once $controllerFile; $controllerClass = 'Thin\\' . $controller . 'Controller'; $controller = new $controllerClass(); $controller->view = new View($route->getView()); if (null !== $alert) { $controller->view->alert($alert); } container()->setController($controller); $actions = get_class_methods($controllerClass); if (true === $isCms) { if (!Arrays::inArray($action, $actions)) { $action = 'page'; } } container()->setAction($action); if (strstr($action, '-')) { $words = explode('-', $action); $newAction = ''; for ($i = 0; $i < count($words); $i++) { $word = trim($words[$i]); if ($i > 0) { $word = ucfirst($word); } $newAction .= $word; } $action = $newAction; } $actionName = $action . 'Action'; if (Arrays::in('init', $actions)) { $controller->init(); } if (Arrays::in('preDispatch', $actions)) { $controller->preDispatch(); } if (!Arrays::in($actionName, $actions)) { throw new Exception("The action '{$actionName}' does not exist."); } $controller->{$actionName}(); $controller->view->render(); if (Arrays::inArray('postDispatch', $actions)) { $controller->postDispatch(); } /* stats */ if (null !== Utils::get("showStats")) { echo View::showStats(); } }
function partial($file) { if (strstr($file, 'http://')) { $content = fgc($file); $file = CACHE_PATH . DS . sha1($file) . '.html'; file_put_contents($file, $content); } if (File::exists($file)) { $view = new View($file); $view->render(); } }
public static function dispatch() { lib('lang')->locale('web'); $controller = isAke(static::$route, 'controller', false); $action = isAke(static::$route, 'action', false); $file = APPLICATION_PATH . DS . 'front' . DS . 'controllers' . DS . $controller . '.php'; $tpl = APPLICATION_PATH . DS . 'front' . DS . 'views' . DS . $controller . DS . $action . '.phtml'; if (!File::exists($file)) { static::is404(); } require_once $file; $class = 'Thin\\' . ucfirst($controller) . 'Controller'; $i = new $class(); if (File::exists($tpl)) { $i->view = new Container(); if (static::$pjax) { $i->view->partial = function ($partial) { return true; }; } else { $i->view->partial = function ($partial) use($i) { $tpl = APPLICATION_PATH . DS . 'front' . DS . 'views' . DS . 'partials' . DS . $partial . '.phtml'; if (File::exists($tpl)) { $code = View::lng(File::read($tpl)); $code = str_replace('$this', '$i->view', $code); eval('; ?>' . $code . '<?php ;'); } }; } } $methods = get_class_methods($i); $call = strtolower(static::$method) . ucfirst($action); if (!Arrays::in($call, $methods)) { static::is404(); } if (Arrays::in('init', $methods)) { $i->init(); } $i->{$call}(); if (Arrays::in('after', $methods)) { $i->after(); } if (File::exists($tpl)) { $code = View::lng(File::read($tpl)); $code = str_replace('$this', '$i->view', $code); header("HTTP/1.0 200 OK"); eval('; ?>' . $code . '<?php ;'); exit; } }
private static function go($module, $controller, $action) { $cdir = APPLICATION_PATH . DS . 'modules' . DS . SITE_NAME . DS . Inflector::lower($module) . DS . 'controllers'; if (!is_dir($cdir)) { static::is404(); } else { $dirApps = realpath(APPLICATION_PATH); $tplDir = realpath($dirApps . DS . 'modules' . DS . SITE_NAME . DS . Inflector::lower($module) . DS . 'views'); $controllerDir = realpath($dirApps . DS . 'modules' . DS . SITE_NAME . DS . Inflector::lower($module) . DS . 'controllers'); $tpl = $tplDir . DS . Inflector::lower($controller) . DS . Inflector::lower($action) . '.phtml'; $controllerFile = $controllerDir . DS . Inflector::lower($controller) . 'Controller.php'; if (!file::exists($controllerFile)) { return static::is404(); } else { if (File::exists($tpl)) { $view = new View($tpl); } require_once $controllerFile; $controllerClass = 'Thin\\' . Inflector::lower($controller) . 'Controller'; $instance = new $controllerClass(); if (File::exists($tpl)) { $instance->view = $view; } if (strstr($action, '-')) { $words = explode('-', $action); $newAction = ''; for ($i = 0; $i < count($words); $i++) { $word = trim($words[$i]); if ($i > 0) { $word = ucfirst($word); } $newAction .= $word; } $action = $newAction; } $actionName = $action . 'Action'; $actions = get_class_methods($controllerClass); if (!Arrays::in($actionName, $actions)) { $continue = false; foreach ($actions as $act) { if (Inflector::lower($act) == Inflector::lower($actionName)) { $actionName = $act; $continue = true; break; } } if (false === $continue) { return static::is404(); } } if (Arrays::in('init', $actions)) { $instance->init(); } if (Arrays::in('preDispatch', $actions)) { $instance->preDispatch(); } $instance->{$actionName}(); if (File::exists($tpl)) { $instance->view->render(); } /* stats */ if (File::exists($tpl) && null === container()->getNoShowStats()) { echo View::showStats(); } if (Arrays::in('postDispatch', $actions)) { $instance->postDispatch(); } if (Arrays::in('exit', $actions)) { $instance->exit(); } } } exit; }