Exemplo n.º 1
0
 public function handle()
 {
     DB::table('page_urls')->where('page_id', '=', $this->url->getPageId())->where('id', '!=', $this->url->getId())->where('is_primary', '=', true)->update(['is_primary' => false]);
     $this->url->setPrimary(true);
     URLFacade::save($this->url);
     DB::table('pages')->where('id', '=', $this->url->getPageId())->update(['primary_uri' => $this->url->getLocation()]);
 }
Exemplo n.º 2
0
 /**
  * @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);
     }
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
Exemplo n.º 4
0
 public function destroy(Page $page, URL $url)
 {
     $this->auth($page);
     if (!$url->isPrimary()) {
         URLFacade::delete($url);
     }
 }
Exemplo n.º 5
0
 public function handle()
 {
     $url = $this->location !== null ? $this->location : URLHelper::fromTitle($this->page->getSite(), $this->prefix, $this->page->getTitle());
     $url = URLFacade::create($url, $this->page, true);
     Bus::dispatch(new MakeURLPrimary($url));
     return $url;
 }
Exemplo n.º 6
0
 public function testHandle()
 {
     $page = $this->validPage();
     $url = m::mock(URL::class);
     $url->shouldReceive('setPageId')->with($page->getId())->andReturnSelf();
     $url->shouldReceive('setIsPrimary')->with(false)->andReturnSelf();
     URLFacade::shouldReceive('save')->with($url);
 }
Exemplo n.º 7
0
 /**
  * @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();
 }
Exemplo n.º 8
0
 public function handle()
 {
     $this->url->setPageId($this->page->getId())->setIsPrimary(false);
     URLFacade::save($this->url);
 }
Exemplo n.º 9
0
 public function postDelete()
 {
     if (!$this->url->isPrimary()) {
         URL::delete($this->url);
     }
 }
Exemplo n.º 10
0
 /**
  * Set the title of the page.
  *
  * @param Request $request
  * @param Page    $page
  *
  * @return array
  */
 public function postTitle(Request $request, Page $page)
 {
     $this->authorize('edit', $page);
     $oldTitle = $page->getTitle();
     $page->setTitle($request->input('title'));
     Event::fire(new Events\PageTitleWasChanged($page, $oldTitle, $page->getTitle()));
     return ['status' => $page->getCurrentVersion()->getStatus(), 'location' => (string) URLFacade::page($page)];
 }
Exemplo n.º 11
0
 /**
  * Increments a numeric suffix until the URL is unique.
  *
  * @param string $url
  *
  * @return string
  */
 public static function makeUnique($url)
 {
     return Str::unique($url, function ($url) {
         return URLFacade::isAvailable($url);
     });
 }