/** * @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 postAdd() { $location = $this->request->input('location'); $this->url = URL::findByLocation($location); if ($this->url && !$this->url->isForPage($this->page)) { // Url is being used for a different page. // Notify that the url is already in use so that the JS can load a prompt to move the url. return ['existing_url_id' => $this->url->getId()]; } elseif (!$this->url) { URL::create($location, $this->page->getId()); } }
public function store(Request $request, Page $page) { $this->auth($page); $location = $request->input('location'); $url = URLFacade::findByLocation($location); if ($url && !$url->isForPage($page)) { // Url is being used for a different page. // Notify that the url is already in use so that the JS can load a prompt to move the url. return ['existing_url_id' => $url->getId()]; } if (!$url) { URLFacade::create($location, $page); } }
/** * @param string $path * * @return mixed */ public function routePage($path) { $url = URL::findByLocation($path); if ($url) { $page = $url->getPage(); if (!$page) { // The url is in use but doesn't have a page. // The page must have been deleted. throw new GoneHttpException(); } if (Editor::isDisabled() && !$page->isVisible()) { throw new NotFoundHttpException(); } if (!$page->url()->matches($path)) { return redirect((string) $page->url(), 301); } $this->setActivePage($page); return; } throw new NotFoundHttpException(); }