/** * @param string $uri * * @return mixed */ public function process($uri) { $this->page = Page::findByUri($uri); if (!$this->page) { $url = URL::findByLocation($uri); // The URL isn't in use or // The URL is in use and has a page - the page must not be visible to the current user // // 404. if (!$url || !$url->getPage()->isVisible()) { throw new NotFoundHttpException(); } // The url is in use but doesn't have a page. // The page must have been deleted. // // 410. throw new GoneHttpException(); } if (Editor::isDisabled() && !$this->page->isVisible()) { throw new NotFoundHttpException(); } if (!$this->page->url()->is($uri)) { return redirect((string) $this->page->url(), 301); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { $uri = $request->route()->getParameter('location'); $page = Page::findByUri($uri); if (!$page) { $url = URL::findByLocation($uri); // The URL isn't in use or // The URL is in use and has a page - the page must not be visible to the current user // // 404. if (!$url || !$url->getPage()->isVisible()) { throw new NotFoundHttpException(); } // The url is in use but doesn't have a page. // The page must have been deleted. // // 410. throw new GoneHttpException(); } if (Editor::isDisabled() && !$page->isVisible()) { throw new NotFoundHttpException(); } if (!$page->url()->is($uri)) { return redirect((string) $page->url(), 301); } $request->route()->setParameter('page', $page); Editor::setActivePage($page); View::share('page', $page); return $next($request); }
public function __construct($link) { parent::__construct($link); if (is_numeric($link)) { $this->page = Page::find($link); } else { // Extract the query string and fragement $this->queryString = parse_url($link, PHP_URL_QUERY); $this->urlFragment = parse_url($link, PHP_URL_FRAGMENT); $path = URL::getInternalPath($link); $this->page = Page::findByUri($path); } }
public function __construct($link) { if (is_int($link) || ctype_digit($link)) { $this->page = Page::find($link); } else { $location = $link === '/' ? $link : ltrim($link, '/'); // Extract the query string and fragement $this->queryString = parse_url($link, PHP_URL_QUERY); $this->urlFragment = parse_url($link, PHP_URL_FRAGMENT); // Only get the path of the URL to ensure that if there's a query string it's ignored. $this->page = Page::findByUri(parse_url($location, PHP_URL_PATH)); } }