Exemplo n.º 1
0
 public function exists($url)
 {
     $url = MsRouteHelper::sanitizeUrl($url);
     $sites = array();
     foreach ($this->all() as $site) {
         $sites[] = $site->url;
     }
     return in_array($url, $sites);
 }
Exemplo n.º 2
0
 public static function render()
 {
     if (!isset($_SESSION['routing'])) {
         global $c;
         Loader::model('multisite_domain', 'multisite');
         $site = new MultiSiteDomain();
         $hostname = MsRouteHelper::getHost();
         $requestPath = $c ? $c->getCollectionPath() : '';
         // Only filter URLs that exist as sites
         if ($site->exists($hostname)) {
             $site->load('url LIKE ?', '%' . $hostname . '%');
             $homePage = Page::getByID($site->home_id);
             if (!$requestPath) {
                 // Need a little logic to make sure we don't render 404s
                 $path = explode('?', $homePage->getCollectionPath() . $_SERVER['REQUEST_URI']);
                 $path = $path[0];
                 // don't include any URL parameters here
                 if ($path == $homePage->getCollectionPath() . '/') {
                     // render the home page
                     $c = $homePage;
                     self::renderPage($c, $site);
                 } else {
                     // render the subpages
                     $c = Page::getByPath($path);
                     self::renderPage($c, $site);
                 }
             } else {
                 if (strpos($requestPath, $homePage->getCollectionPath()) !== false) {
                     $newPath = str_replace($homePage->getCollectionPath(), '', $requestPath);
                     header('Location: ' . $newPath);
                 } else {
                     $requestPath = $homePage->getCollectionPath() . $requestPath;
                     $c = Page::getByPath($requestPath);
                     if (!$c->getCollectionID()) {
                         // force a 404
                         header('HTTP/1.0 404 Not Found');
                         $c = Page::getByPath('/page_not_found');
                     }
                     self::renderPage($c, $site);
                 }
             }
         }
     } else {
         unset($_SESSION['routing']);
     }
 }