Пример #1
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);
     }
 }
Пример #2
0
 public function __construct(Request $request)
 {
     $this->request = $request;
     $this->page = $request->route()->getParameter('page');
     $this->authorize('edit', $this->page);
     $this->related = Page::find($this->request->input('related_page_id'));
 }
Пример #3
0
 /**
  * Displays the CMS interface with buttons for add page, settings, etc.
  * Called from an iframe when logged into the CMS.
  * The ID of the page which is being viewed is given as a URL paramater (e.g. /boomscms/editor/toolbar/<page ID>).
  */
 public function getToolbar()
 {
     $page = Page::find($this->request->input('page_id'));
     $toolbarFilename = $this->editor->isEnabled() ? 'toolbar' : 'toolbar_preview';
     View::share(['page' => $page, 'editor' => $this->editor, 'auth' => auth(), 'person' => auth()->user()]);
     return view("boomcms::editor.{$toolbarFilename}");
 }
Пример #4
0
 public function __construct(Page $page, array $attrs, $slotname)
 {
     parent::__construct($page, $attrs, $slotname);
     if (isset($this->attrs['target_page_id'])) {
         $this->targetPage = PageFacade::find($this->attrs['target_page_id']);
     }
 }
Пример #5
0
 /**
  * @param Site $site
  * @param Page $page
  *
  * @return Page
  */
 public function postAdd(Page $page)
 {
     $this->authorize('add', $page);
     $parent = $page->getAddPageParent();
     $newPage = $this->dispatch(new CreatePage($parent));
     return PageFacade::find($newPage->getId());
 }
Пример #6
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);
 }
Пример #7
0
 public function testFactoryReturnsExternalLink()
 {
     $internalLinks = ['/test', 'http://www.google.com/test'];
     Page::shouldReceive('findByUri')->with('test')->andReturn($this->invalidPage());
     foreach ($internalLinks as $link) {
         $this->assertInstanceOf(Link\External::class, Link\Link::factory($link), $link);
     }
 }
Пример #8
0
 public function testGetTitleReturnsPageTitle()
 {
     $page = $this->getMock(Page::class, ['getTitle']);
     $page->expects($this->any())->method('getTitle')->will($this->returnValue('test'));
     PageFacade::shouldReceive('findByUri')->with('test')->andReturn($page);
     $link = new Link('test');
     $this->assertEquals('test', $link->getTitle());
 }
Пример #9
0
 protected function doDelete(Page $page)
 {
     $children = PageFacade::findByParentId($page->getId());
     foreach ($children as $child) {
         $this->doDelete($child);
         Bus::dispatch(new DeletePage($child));
     }
 }
Пример #10
0
 public function handle()
 {
     $url = $this->location !== null ? $this->location : URLHelper::fromTitle($this->prefix, $this->page->getTitle());
     $this->page->setPrimaryUri($url);
     $page = PageFacade::save($this->page);
     $url = URLFacade::create($url, $this->page->getId(), true);
     Bus::dispatch(new MakeURLPrimary($url));
     return $url;
 }
Пример #11
0
 /**
  * Displays the CMS interface with buttons for add page, settings, etc.
  * Called from an iframe when logged into the CMS.
  * The ID of the page which is being viewed is given as a URL paramater (e.g. /cms/editor/toolbar/<page ID>).
  */
 public function getToolbar()
 {
     $page = Page::find($this->request->input('page_id'));
     $this->editor->setActivePage($page);
     View::share('page', $page);
     View::share('editor', $this->editor);
     $toolbarFilename = $this->editor->isEnabled() ? 'toolbar' : 'toolbar_preview';
     return view("boomcms::editor.{$toolbarFilename}");
 }
Пример #12
0
 protected function reassignURLs()
 {
     $redirectTo = PageFacade::find($this->options['redirectTo']);
     if ($redirectTo !== null) {
         foreach ($this->page->getUrls() as $url) {
             Bus::dispatch(new ReassignURL($url, $redirectTo));
         }
     }
 }
Пример #13
0
 /**
  * @param Request $request
  * @param Page    $page
  */
 public function update(Request $request, Page $page)
 {
     $this->auth($page);
     $enabled = $request->input('enabled') === '1';
     PageFacade::recurse($page, function (Page $p) use($enabled) {
         $p->setAclEnabled($enabled);
         PageFacade::save($p);
     });
 }
Пример #14
0
 public function handle()
 {
     $attrs = ['visible_from' => time(), 'created_by' => $this->createdBy->getId()];
     if ($this->parent) {
         $attrs = ['visible_from' => time(), 'parent_id' => $this->parent->getId(), 'visible_in_nav' => $this->parent->childrenAreVisibleInNav(), 'visible_in_nav_cms' => $this->parent->childrenAreVisibleInCmsNav(), 'children_visible_in_nav' => $this->parent->childrenAreVisibleInNav(), 'children_visible_in_nav_cms' => $this->parent->childrenAreVisibleInCmsNav()];
     }
     $page = PageFacade::create($attrs);
     $page->addVersion(['edited_by' => $this->createdBy->getId(), 'page_id' => $page->getId(), 'template_id' => $this->parent ? $this->parent->getDefaultChildTemplateId() : null, 'title' => 'Untitled', 'published' => true, 'embargoed_until' => time()]);
     return $page;
 }
Пример #15
0
 /**
  * Displays the CMS interface with buttons for add page, settings, etc.
  * Called from an iframe when logged into the CMS.
  */
 public function getToolbar(EditorObject $editor, Request $request)
 {
     $page = PageFacade::find($request->input('page_id'));
     View::share(['page' => $page, 'editor' => $editor, 'auth' => auth(), 'person' => auth()->user()]);
     if ($editor->isHistory()) {
         return view('boomcms::editor.toolbar.history', ['previous' => $page->getCurrentVersion()->getPrevious(), 'next' => $page->getCurrentVersion()->getNext(), 'version' => $page->getCurrentVersion(), 'diff' => new Diff()]);
     }
     $toolbarFilename = $editor->isEnabled() ? 'edit' : 'preview';
     return view("boomcms::editor.toolbar.{$toolbarFilename}");
 }
Пример #16
0
 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));
     }
 }
Пример #17
0
 public function handle()
 {
     DB::transaction(function () {
         foreach ($this->sequences as $sequence => $pageId) {
             $page = PageFacade::find($pageId);
             // Only update the sequence of pages which are children of this page.
             if ($this->parent->isParentOf($page)) {
                 $page->setSequence($sequence);
                 PageFacade::save($page);
             }
         }
     });
 }
Пример #18
0
 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);
     }
 }
Пример #19
0
 public function handle(PageEvent $event)
 {
     $page = $event->getPage();
     $title = $event->getNewTitle();
     if ($title !== Page::DEFAULT_TITLE && empty($page->getInternalName())) {
         $slug = Str::slug($title);
         $unique = Str::unique($slug, function ($name) {
             return PageFacade::internalNameExists($name) === false;
         });
         $page->setInternalName($unique);
         PageFacade::save($page);
     }
 }
Пример #20
0
 public function testChildrenAreReparented()
 {
     $page = $this->validPage();
     $newParent = $this->validPage(2);
     $child = m::mock(PageModel::class);
     $child->shouldReceive('setParent')->with($newParent);
     $job = new Jobs\DeletePage($page, ['reparentChildrenTo' => $newParent->getId()]);
     Page::shouldReceive('delete')->zeroOrMoreTimes();
     Event::shouldReceive('fire')->zeroOrMoreTimes();
     Page::shouldReceive('find')->with($newParent->getId())->andReturn($newParent);
     Page::shouldReceive('findByParentId')->with($page->getId())->andReturn([$child]);
     Page::shouldReceive('save')->with($child);
     $job->handle();
 }
Пример #21
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Exception               $e
  *
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($this->isHttpException($e)) {
         $code = $e->getStatusCode();
         if ($code !== 500 || App::environment('production') || App::environment('staging')) {
             $page = Page::findByInternalName($code);
             if ($page) {
                 $request = Request::create($page->url()->getLocation(), 'GET');
                 return response(Route::dispatch($request)->getContent(), $code);
             }
         }
     }
     return parent::render($request, $e);
 }
Пример #22
0
 public function visibility()
 {
     parent::visibility();
     $wasVisible = $this->page->isVisible();
     $this->page->setVisibleAtAnyTime($this->request->input('visible') == 1);
     if ($this->page->isVisibleAtAnyTime()) {
         $visibleTo = $this->request->input('toggle_visible_to') == 1 ? new DateTime($this->request->input('visible_to')) : null;
         $this->page->setVisibleFrom(new DateTime($this->request->input('visible_from')))->setVisibleTo($visibleTo);
     }
     Page::save($this->page);
     if (!$wasVisible && $this->page->isVisible()) {
         Event::fire(new PageWasMadeVisible($this->page, Auth::getPerson()));
     }
     return (int) $this->page->isVisible();
 }
Пример #23
0
 public function handle()
 {
     $attrs = [];
     if ($this->parent) {
         $attrs += ['parent_id' => $this->parent->getId(), 'visible_in_nav' => $this->parent->childrenAreVisibleInNav(), 'visible_in_nav_cms' => $this->parent->childrenAreVisibleInCmsNav(), 'children_visible_in_nav' => $this->parent->childrenAreVisibleInNav(), 'children_visible_in_nav_cms' => $this->parent->childrenAreVisibleInCmsNav(), 'enable_acl' => $this->parent->aclEnabled()];
     }
     $page = PageFacade::create($attrs);
     $page->addVersion(['template_id' => $this->parent ? $this->parent->getDefaultChildTemplateId() : null, 'title' => $this->title, 'embargoed_until' => time()]);
     if ($this->parent) {
         $groupIds = $this->parent->getAclGroupIds();
         foreach ($groupIds as $groupId) {
             $page->addAclGroupId($groupId);
         }
     }
     Event::fire(new PageWasCreated($page, $this->parent));
     return $page;
 }
Пример #24
0
 public function getFeedItems()
 {
     return PageFacade::findByParentId($this->page->getId());
 }
Пример #25
0
 public function __construct($parent)
 {
     $this->parent = $parent instanceof Page ? $parent : PageFacade::find($parent);
 }
Пример #26
0
 public function __construct($page)
 {
     $this->page = $page instanceof Page ? $page : PageFacade::find($page);
 }
Пример #27
0
 /**
  * Save the page visibility settings.
  *
  * @param Request $request
  * @param Page    $page
  *
  * @return int
  */
 public function postVisibility(Request $request, Page $page)
 {
     $this->authorize('publish', $page);
     $wasVisible = $page->isVisible();
     $page->setVisibleAtAnyTime($request->input('visible'));
     if ($page->isVisibleAtAnyTime()) {
         $visibleFrom = $request->input('visible_from') > 0 ? new DateTime($request->input('visible_from')) : null;
         $visibleTo = $request->has('toggle_visible_to') ? new DateTime($request->input('visible_to')) : null;
         $page->setVisibleFrom($visibleFrom)->setVisibleTo($visibleTo);
     }
     PageFacade::save($page);
     if (!$wasVisible && $page->isVisible()) {
         Event::fire(new Events\PageWasMadeVisible($page, auth()->user()));
     }
     return (int) $page->isVisible();
 }