/** * @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); } }
public function __construct() { $this->query = Model::currentVersion()->withUrl(); if (Editor::isDisabled()) { $this->query = $this->query->isVisible(); } }
/** * 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); }
/** * @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(); }
/** * @param QueryBuilder $query * * @return QueryBuilder */ public function scopeLatestAvailable(QueryBuilder $query) { if (Editor::isHistory()) { return $query->where(self::ATTR_CREATED_AT, '<=', Editor::getTime()->getTimestamp())->orderBy(self::ATTR_CREATED_AT, 'desc')->orderBy(self::ATTR_ID, 'desc'); } return Editor::isDisabled() ? $this->scopeLastPublished($query) : $query->orderBy(self::ATTR_CREATED_AT, 'desc'); }
public function getCurrentVersionQuery() { $query = DB::table('page_versions')->select([DB::raw('max(id) as id'), 'page_id'])->groupBy('page_id'); if (Editor::isDisabled()) { $query->where('embargoed_until', '<=', Editor::getTime()->getTimestamp()); } if (Editor::isHistory()) { $query->where('version.created_at', '<=', Editor::getTime()->getTimestamp()); } return $query; }
public function getCurrentVersionQuery() { $query = DB::table('page_versions')->select([DB::raw('max(id) as id'), 'page_id'])->groupBy('page_id'); if (Editor::isDisabled()) { $query->where('embargoed_until', '<=', time())->where('published', '=', 1); } return $query; }
public function scopeLatestAvailable($query) { if (Editor::isDisabled()) { return $this->scopeLastPublished($query); } else { // For logged in users get the version with the highest ID. return $query->orderBy(self::ATTR_ID, 'desc'); } }