public static function dispatch() { static::$_uri = $uri = trim($_SERVER['REQUEST_URI'], static::URI_DELIMITER); $containerRoute = static::containerRoute(); if (null !== $containerRoute) { return; } $defaultRoute = static::defaultRoute(); if (null !== $defaultRoute) { return; } $entities = container()->getEntities(); /* Pages non routées */ if (true === container()->getMultiSite() && !empty($entities) && null === container()->getMapRoutes()) { $url = substr($_SERVER['REQUEST_URI'], 1); $db = new Querydata('page'); $res = $db->where('is_home = ' . getBool('true')->getId())->get(); $home = $db->first($res); $_homeUrl = Cms::__($home->getUrl()); $homeUrl = null !== $_homeUrl ? $_homeUrl : 'home'; $url = !strlen($url) ? $homeUrl : $url; $pages = Cms::getPages(); $cmsRoutes = array(); $lngs = explode(',', cms_option('page_languages')); if (count($pages)) { foreach ($pages as $pageTmp) { if (1 < count($lngs)) { $urlTab = $pageTmp->getUrl(); foreach ($lngs as $lng) { if (ake($lng, $urlTab)) { $cmsRoutes[$urlTab[$lng]] = $pageTmp; } } } else { $cmsRoutes[Cms::__($pageTmp->getUrl())] = $pageTmp; } } } $found = Arrays::exists($url, $cmsRoutes); if (false === $found) { $found = Cms::match($cmsRoutes); } if (true === $found && ake($url, $cmsRoutes)) { $page = $cmsRoutes[$url]; $status = Inflector::lower($page->getStatuspage()->getName()); $dateDepub = $page->getDateOut(); $now = time(); $continue = true; if (strlen($dateDepub)) { list($d, $m, $y) = explode('-', $dateDepub, 3); $dateDepub = "{$y}-{$m}-{$d}"; $dateDepub = new Date($dateDepub); } if ($dateDepub instanceof Date) { $ts = $dateDepub->getTimestamp(); if ($ts < $now) { $page = $cmsRoutes['home']; } } if ('offline' == $status) { $continue = false; } else { if ('online' != $status) { $page = ake($status, $cmsRoutes) ? $cmsRoutes[$status] : $cmsRoutes['home']; } } if (true === $continue) { return static::isCms($page); } } } if (true === container()->getMultiSite()) { $file = APPLICATION_PATH . DS . 'config' . DS . SITE_NAME . DS . 'routes.php'; } else { $file = APPLICATION_PATH . DS . 'config' . DS . 'routes.php'; } if (File::exists($file)) { $configRoutes = (include $file); $routes = $configRoutes['collection']; $routes += null !== container()->getRoutes() ? container()->getRoutes() : array(); foreach ($routes as $route) { if (!$route instanceof Container) { continue; } $path = $route->getPath(); if ($path == $uri) { return static::make($route); } } foreach ($routes as $route) { if (!$route instanceof Container) { continue; } if (!strlen($route->getPath())) { continue; } $matched = static::match($route->getPath()); if (false === $matched) { continue; } else { return static::make($route); } } } else { static::make(container()->getNotFoundRoute()); return; } if (null === container()->getMapRoutes()) { static::is404(); } else { static::make(container()->getNotFoundRoute()); return; } }