Пример #1
0
 /**
  * Show text and redirect to another page
  * @param string $text Content
  * @param string $link Target page
  * @param int $timeout Time before redirect
  */
 public static function show($text, $link = null, $timeout = 3)
 {
     Template::setView('Misc/Redirect');
     if (is_array($text)) {
         array_unshift($text, $text[0]);
         // Set fallback string
         Template::putContext('text', call_user_func_array(array('I18N', 'parse'), $text));
     } else {
         Template::putContext('text', I18N::parse($text, $text));
     }
     Template::putContext('timeout', $timeout);
     Template::putContext('link', $link === null ? null : Response::generateURL($link));
     Filter::preRender();
     Template::render();
     Filter::afterRender();
     exit;
 }
Пример #2
0
 private function findController($requestPath)
 {
     $route = array();
     $parameter = array();
     $context = null;
     $key = strtolower($requestPath);
     if ($this->StaticRoute[$key]) {
         $route = $this->StaticRoute[$key];
     } else {
         foreach ($this->DynamicRoute as $router) {
             if (!preg_match($router['regexp'], $requestPath, $matches)) {
                 continue;
             }
             // Remove the request string
             array_shift($matches);
             $route = $router['callback'];
             $parameter = $matches;
             break;
         }
     }
     if (!$route) {
         if ($this->FallbackRouter) {
             $route = $this->FallbackRouter;
         } else {
             throw new Error(I18N::parse('Error.Messages.PageNotExists', 'The request URL is not exists'), 404);
         }
     }
     list($className, $method) = $route;
     Filter::afterRoute($className, $method);
     $controller = new $className();
     if ($parameter) {
         $context = call_user_func_array(array($controller, $method), $parameter);
     } else {
         $context = $controller->{$method}();
     }
     if ($context) {
         Template::setContext($context);
     }
     Filter::preRender();
     Template::render();
     Filter::afterRender();
 }
Пример #3
0
 private static function parseI18nTags(array $match)
 {
     $params = self::parseI18nParams($match[2]);
     $translation = I18N::parse($params['key'], $match[3]);
     if (count($params) > 1) {
         foreach ($params as $key => $value) {
             $translation = str_replace("{{$key}}", $value, $translation);
         }
     }
     return $translation;
 }