public function execute(Request $request, \Concrete\Core\Routing\Route $route = null, $parameters = array()) { // figure out where we need to go $c = Page::getFromRequest($request); if ($c->isError() && $c->getError() == COLLECTION_NOT_FOUND) { // if we don't have a path and we're doing cID, then this automatically fires a 404. if (!$request->getPath() && $request->get('cID')) { return $this->sendPageNotFound($request); } // let's test to see if this is, in fact, the home page, // and we're routing arguments onto it (which is screwing up the path.) $home = Page::getByID(HOME_CID); $request->setCurrentPage($home); $homeController = $home->getPageController(); $homeController->setupRequestActionAndParameters($request); if (!$homeController->validateRequest()) { return $this->sendPageNotFound($request); } else { $c = $home; $c->cPathFetchIsCanonical = true; } } if (!$c->cPathFetchIsCanonical) { // Handle redirect URL (additional page paths) /** @var Url $url */ $url = \Core::make('url/manager')->resolve(array($c)); $query = $url->getQuery(); $query->modify($request->getQueryString()); $url = $url->setQuery($query); $response = Redirect::to($url); $response->setStatusCode(301); return $response; } // maintenance mode if ($c->getCollectionPath() != '/login') { $smm = Config::get('concrete.maintenance_mode'); if ($smm == 1 && !PermissionKey::getByHandle('view_in_maintenance_mode')->validate() && ($_SERVER['REQUEST_METHOD'] != 'POST' || Loader::helper('validation/token')->validate() == false)) { $v = new View('/frontend/maintenance_mode'); $v->setViewTheme(VIEW_CORE_THEME); return $this->sendResponse($v); } } if ($c->getCollectionPointerExternalLink() != '') { return Redirect::url($c->getCollectionPointerExternalLink(), 301); } $cp = new Permissions($c); if ($cp->isError() && $cp->getError() == COLLECTION_FORBIDDEN) { return $this->sendPageForbidden($request, $c); } if (!$c->isActive() && !$cp->canViewPageVersions()) { return $this->sendPageNotFound($request); } if ($cp->canEditPageContents() || $cp->canEditPageProperties() || $cp->canViewPageVersions()) { $c->loadVersionObject('RECENT'); } $vp = new Permissions($c->getVersionObject()); // returns the $vp object, which we then check if (is_object($vp) && $vp->isError()) { switch ($vp->getError()) { case COLLECTION_NOT_FOUND: return $this->sendPageNotFound($request); break; case COLLECTION_FORBIDDEN: return $this->sendPageForbidden($request, $c); break; } } // Now that we've passed all permissions checks, and we have a page, we check to see if we // ought to redirect based on base url or trailing slash settings $cms = \Core::make("app"); $response = $cms->handleCanonicalURLRedirection($request); if (!$response) { $response = $cms->handleURLSlashes($request); } if (isset($response)) { $response->send(); exit; } // Now we check to see if we're on the home page, and if it multilingual is enabled, // and if so, whether we should redirect to the default language page. if (\Core::make('multilingual/detector')->isEnabled()) { $dl = Core::make('multilingual/detector'); if ($c->getCollectionID() == HOME_CID && Config::get('concrete.multilingual.redirect_home_to_default_locale')) { // Let's retrieve the default language $ms = $dl->getPreferredSection(); if (is_object($ms) && $ms->getCollectionID() != HOME_CID) { Redirect::page($ms)->send(); exit; } } $dl->setupSiteInterfaceLocalization($c); } $request->setCurrentPage($c); require DIR_BASE_CORE . '/bootstrap/process.php'; $u = new User(); // On page view event. $pe = new PageEvent($c); $pe->setUser($u); $pe->setRequest($request); Events::dispatch('on_page_view', $pe); $controller = $c->getPageController(); $controller->on_start(); $controller->setupRequestActionAndParameters($request); $response = $controller->validateRequest(); if ($response instanceof \Symfony\Component\HttpFoundation\Response) { return $response; } else { if ($response == false) { return $this->sendPageNotFound($request); } } $requestTask = $controller->getRequestAction(); $requestParameters = $controller->getRequestActionParameters(); $response = $controller->runAction($requestTask, $requestParameters); if ($response instanceof \Symfony\Component\HttpFoundation\Response) { return $response; } $c->setController($controller); $view = $controller->getViewObject(); // Mobile theme if (Config::get('concrete.misc.mobile_theme_id') > 0) { $md = new \Mobile_Detect(); if ($md->isMobile()) { $mobileTheme = Theme::getByID(Config::get('concrete.misc.mobile_theme_id')); if ($mobileTheme instanceof Theme) { $view->setViewTheme($mobileTheme); $controller->setTheme($mobileTheme); } } } // we update the current page with the one bound to this controller. $request->setCurrentPage($c); return $this->sendResponse($view); }
/** * Gets the icon for a page (also fires the on_page_get_icon event). * * @return string $icon Path to the icon */ public function getCollectionIcon() { // returns a fully qualified image link for this page's icon, either based on its collection type or if icon.png appears in its view directory $pe = new Event($this); $pe->setArgument('icon', ''); Events::dispatch('on_page_get_icon', $pe); $icon = $pe->getArgument('icon'); if ($icon) { return $icon; } if (\Core::make('multilingual/detector')->isEnabled()) { $icon = \Concrete\Core\Multilingual\Service\UserInterface\Flag::getDashboardSitemapIconSRC($this); } if ($this->isGeneratedCollection()) { if ($this->getPackageID() > 0) { if (is_dir(DIR_PACKAGES . '/' . $this->getPackageHandle())) { $dirp = DIR_PACKAGES; $url = \Core::getApplicationURL(); } else { $dirp = DIR_PACKAGES_CORE; $url = ASSETS_URL; } $file = $dirp . '/' . $this->getPackageHandle() . '/' . DIRNAME_PAGES . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON; if (file_exists($file)) { $icon = $url . '/' . DIRNAME_PACKAGES . '/' . $this->getPackageHandle() . '/' . DIRNAME_PAGES . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON; } } elseif (file_exists(DIR_FILES_CONTENT . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON)) { $icon = \Core::getApplicationURL() . '/' . DIRNAME_PAGES . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON; } elseif (file_exists(DIR_FILES_CONTENT_REQUIRED . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON)) { $icon = ASSETS_URL . '/' . DIRNAME_PAGES . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON; } } else { } return $icon; }
/** * @inheritdoc */ public function collection(Collection $collection, $code = Response::HTTP_OK, $headers = array()) { if (!$this->app) { throw new \RuntimeException('Cannot resolve collections without a reference to the application'); } $request = $this->request; if ($collection->isError() && $collection->getError() == COLLECTION_NOT_FOUND) { if ($response = $this->collectionNotFound($collection, $request, $headers)) { return $response; } } if ($collection->getCollectionPath() != '/page_not_found') { if (!isset($collection->cPathFetchIsCanonical) || !$collection->cPathFetchIsCanonical) { // Handle redirect URL (additional page paths) /** @var Url $url */ $url = $this->app->make('url/manager')->resolve([$collection]); $query = $url->getQuery(); $query->modify($request->getQueryString()); $url = $url->setQuery($query); return $this->redirect($url, Response::HTTP_MOVED_PERMANENTLY, $headers); } } // maintenance mode if ($collection->getCollectionPath() != '/login') { $smm = $this->config->get('concrete.maintenance_mode'); if ($smm == 1 && !Key::getByHandle('view_in_maintenance_mode')->validate() && ($_SERVER['REQUEST_METHOD'] != 'POST' || Loader::helper('validation/token')->validate() == false)) { $v = new View('/frontend/maintenance_mode'); $router = $this->app->make(RouterInterface::class); $tmpTheme = $router->getThemeByRoute('/frontend/maintenance_mode'); $v->setViewTheme($tmpTheme[0]); $v->addScopeItems(['c' => $collection]); $request->setCurrentPage($collection); if (isset($tmpTheme[1])) { $v->setViewTemplate($tmpTheme[1]); } return $this->view($v, $code, $headers); } } if ($collection->getCollectionPointerExternalLink() != '') { return $this->redirect($collection->getCollectionPointerExternalLink()); } $cp = new Checker($collection); if ($cp->isError() && $cp->getError() == COLLECTION_FORBIDDEN) { return $this->forbidden($request->getUri(), Response::HTTP_FORBIDDEN, $headers); } if (!$collection->isActive() && !$cp->canViewPageVersions()) { return $this->notFound('', Response::HTTP_NOT_FOUND, $headers); } $scheduledVersion = Version::get($collection, "SCHEDULED"); if ($publishDate = $scheduledVersion->cvPublishDate) { $datetime = $this->app->make('helper/date'); $now = $datetime->date('Y-m-d G:i:s'); if (strtotime($now) >= strtotime($publishDate)) { $scheduledVersion->approve(); $collection->loadVersionObject('ACTIVE'); } } if ($cp->canEditPageContents() || $cp->canEditPageProperties() || $cp->canViewPageVersions()) { $collection->loadVersionObject('RECENT'); } $vp = new Checker($collection->getVersionObject()); // returns the $vp object, which we then check if (is_object($vp) && $vp->isError()) { switch ($vp->getError()) { case COLLECTION_NOT_FOUND: return $this->notFound('', Response::HTTP_NOT_FOUND, $headers); break; case COLLECTION_FORBIDDEN: return $this->forbidden($request->getUri(), Response::HTTP_FORBIDDEN, $headers); break; } } // Now that we've passed all permissions checks, and we have a page, we check to see if we // ought to redirect based on base url or trailing slash settings $cms = $this->app; $site = $this->app['site']->getSite(); $response = $cms->handleCanonicalURLRedirection($request, $site); if (!$response) { $response = $cms->handleURLSlashes($request, $site); } if (isset($response)) { return $response; } $dl = $cms->make('multilingual/detector'); if ($dl->isEnabled()) { $dl->setupSiteInterfaceLocalization($collection); } if (!$request->getPath() && $request->isMethod('GET') && !$request->query->has('cID')) { // This is a request to the home page –http://www.mysite.com/ // First, we check to see if we need to redirect to a default multilingual section. if ($dl->isEnabled() && $site->getConfigRepository()->get('multilingual.redirect_home_to_default_locale')) { // Let's retrieve the default language $ms = $dl->getPreferredSection(); if (is_object($ms)) { return $this->redirect(\URL::to($ms)); } } // Otherwise, let's check to see if our home page, which we have loaded already, has a path (like /en) // If it does, we'll redirect to the path. if ($collection->getCollectionPath() != '') { return $this->redirect(\URL::to($collection)); } } $request->setCurrentPage($collection); $c = $collection; // process.php needs this require DIR_BASE_CORE . '/bootstrap/process.php'; $u = new User(); // On page view event. $pe = new Event($collection); $pe->setUser($u); $pe->setRequest($request); $this->app['director']->dispatch('on_page_view', $pe); // Core menu items $item = new RelationListItem(); $menu = $this->app->make('helper/concrete/ui/menu'); $menu->addMenuItem($item); $controller = $collection->getPageController(); // we update the current page with the one bound to this controller. $collection->setController($controller); return $this->controller($controller); }
public function execute(Request $request, \Concrete\Core\Routing\Route $route = null, $parameters = array()) { // figure out where we need to go $c = Page::getFromRequest($request); if ($c->isError() && $c->getError() == COLLECTION_NOT_FOUND) { // if we don't have a path and we're doing cID, then this automatically fires a 404. if (!$request->getPath() && $request->get('cID')) { return $this->sendPageNotFound($request); } // let's test to see if this is, in fact, the home page, // and we're routing arguments onto it (which is screwing up the path.) $home = Page::getByID(HOME_CID); $homeController = $home->getPageController(); $homeController->setupRequestActionAndParameters($request); if (!$homeController->validateRequest()) { return $this->sendPageNotFound($request); } else { $c = $home; } } // maintenance mode if (!$c->isAdminArea() && $c->getCollectionPath() != '/login') { $smm = Config::get('concrete.maintenance_mode'); if ($smm == 1 && ($_SERVER['REQUEST_METHOD'] != 'POST' || Loader::helper('validation/token')->validate() == false)) { $v = new View('/frontend/maintenance_mode'); $v->setViewTheme(VIEW_CORE_THEME); return $this->sendResponse($v); } } if ($c->getCollectionPointerExternalLink() != '') { return Redirect::url($c->getCollectionPointerExternalLink(), 301)->send(); } $cp = new Permissions($c); if ($cp->isError() && $cp->getError() == COLLECTION_FORBIDDEN) { return $this->sendPageForbidden($request); } if (!$c->isActive() && !$cp->canViewPageVersions()) { return $this->sendPageNotFound($request); } if ($cp->canEditPageContents() || $cp->canEditPageProperties() || $cp->canViewPageVersions()) { $c->loadVersionObject('RECENT'); } $vp = new Permissions($c->getVersionObject()); // returns the $vp object, which we then check if (is_object($vp) && $vp->isError()) { switch ($vp->getError()) { case COLLECTION_NOT_FOUND: return $this->sendPageNotFound($request); break; case COLLECTION_FORBIDDEN: return $this->sendPageForbidden($request); break; } } $request->setCurrentPage($c); require DIR_BASE_CORE . '/bootstrap/process.php'; $u = new User(); ## Fire the on_page_view Eventclass $pe = new PageEvent($c); $pe->setUser($u); Events::dispatch('on_page_view', $pe); $controller = $c->getPageController(); $controller->on_start(); $controller->setupRequestActionAndParameters($request); $response = $controller->validateRequest(); if ($response instanceof \Concrete\Core\Http\Response) { return $response; } else { if ($response == false) { return $this->sendPageNotFound($request); } } $requestTask = $controller->getRequestAction(); $requestParameters = $controller->getRequestActionParameters(); $controller->runAction($requestTask, $requestParameters); $c->setController($controller); $view = $controller->getViewObject(); // we update the current page with the one bound to this controller. $request->setCurrentPage($c); return $this->sendResponse($view); }