Esempio n. 1
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);
 }
Esempio 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);
     }
 }
Esempio n. 3
0
 public function __construct()
 {
     $this->query = Model::currentVersion()->withUrl();
     if (Editor::isDisabled()) {
         $this->query = $this->query->isVisible();
     }
 }
Esempio n. 4
0
 /**
  * Returns whether the logged in user is allowed to edit a page.
  *
  * @return bool
  */
 public function allowedToEdit(Page $page = null)
 {
     if ($page === null) {
         return true;
     }
     return Editor::isEnabled() && $this->gate->allows('edit', $page);
 }
Esempio n. 5
0
 public function testPubUsesNamespaceOfActivePageTemplate()
 {
     $template = new Template(['theme' => 'test']);
     $page = $this->getMock(Page::class, ['getTemplate']);
     $page->expects($this->once())->method('getTemplate')->willReturn($template);
     Editor::shouldReceive('getActivePage')->andReturn($page);
     $this->assertEquals('/vendor/boomcms/themes/test/file.png', Helpers::pub('file.png'));
 }
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     View::share('request', $request);
     View::share('editor', Editor::getFacadeRoot());
     $viewHelpers = Config::get('boomcms.viewHelpers');
     foreach ($viewHelpers as $key => $value) {
         View::share($key, $value);
     }
     return $next($request);
 }
Esempio n. 7
0
 /**
  * Returns a chunk object of the required type.
  *
  * @param string $type     Chunk type, e.g. text, feature, etc.
  * @param string $slotname The name of the slot to retrieve a chunk from.
  * @param mixed  $page     The page the chunk belongs to. If not given then the page from the current request will be used.
  *
  * @return BaseChunk
  */
 public function edit($type, $slotname, $page = null)
 {
     $className = 'BoomCMS\\Core\\Chunk\\' . ucfirst($type);
     if ($page === null) {
         $page = Editor::getActivePage();
     } elseif ($page === 0) {
         // 0 was given as the page - this signifies a 'global' chunk not assigned to any page.
         $page = new Page();
     }
     $chunk = $this->find($type, $slotname, $page->getCurrentVersion());
     $attrs = $chunk ? $chunk->toArray() : [];
     return new $className($page, $attrs, $slotname, $this->allowedToEdit($page));
 }
Esempio n. 8
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();
 }
Esempio n. 9
0
 /**
  * Get the pages applied to the children of a page.
  *
  * @param Page\Page $page
  * @param string    $group
  *
  * @return array
  */
 public static function getTagsInSection(PageInterface $page = null, $group = null)
 {
     $page = $page ?: Editor::getActivePage();
     $finder = new Tag\Finder\Finder();
     $finder->addFilter(new Tag\Finder\AppliedToPageDescendants($page));
     $finder->addFilter(new Tag\Finder\Group($group));
     return $finder->setOrderBy('name', 'asc')->findAll();
 }
Esempio n. 10
0
 /**
  * Attempts to get the chunk data from the cache, otherwise calls _execute to generate the cache.
  */
 public function render()
 {
     try {
         $html = $this->html();
         if ($this->editable === true || Editor::isHistory()) {
             $html = $this->addAttributesToHtml($html);
         }
         return empty($html) ? $html : $this->before . $html . $this->after;
     } catch (\Exception $e) {
         if (App::environment() === 'local') {
             throw $e;
         }
     }
 }
Esempio n. 11
0
 protected function show()
 {
     return Editor::isEnabled() ? $this->editLink() : $this->getContent();
 }
Esempio n. 12
0
 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;
 }
Esempio n. 13
0
 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');
     }
 }
Esempio n. 14
0
 public function shouldBeApplied()
 {
     return $this->apply === true || $this->apply === null && !Editor::isEnabled();
 }
Esempio n. 15
0
 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;
 }
Esempio n. 16
0
 /**
  * @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');
 }
Esempio n. 17
0
 protected function getNavigationVisibilityColumn()
 {
     return Editor::isEnabled() ? 'visible_in_nav_cms' : 'visible_in_nav';
 }