/** * @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); } }
/** * @param Page $page * * @return string */ public function getPrefix(Page $page) { $parent = $page->getParent(); if ($parent === null) { return ''; } return $parent->getChildPageUrlPrefix() ?: $page->getParent()->url()->getLocation(); }
protected function doDelete(Page $page) { $children = PageFacade::findByParentId($page->getId()); foreach ($children as $child) { $this->doDelete($child); Bus::dispatch(new DeletePage($child)); } }
protected function reassignURLs() { $redirectTo = PageFacade::find($this->options['redirectTo']); if ($redirectTo !== null) { foreach ($this->page->getUrls() as $url) { Bus::dispatch(new ReassignURL($url, $redirectTo)); } } }
public function getNextTo(PageInterface $page, $direction) { $params = $this->params; if (isset($params['parent'])) { unset($params['parent']); } $params['parentid'] = $page->getParentId(); $params['nextto'] = [$page, $direction]; $finder = $this->addFilters(new Finder\Finder(), $params); return $finder->find(); }
protected function getValue($column) { switch ($column) { case 'visible_from': return $this->currentPage->getVisibleFrom()->getTimestamp(); case 'sequence': return $this->currentPage->getManualOrderPosition(); default: return $this->currentPage->getTitle(); } }
public function asHtml(Page $page) { $template = $page->getTemplate(); View::share('chunk', function ($type, $slotname, $page = null) { $chunks = []; if ($page) { return Chunk::get($type, $slotname, $page); } return isset($chunks[$type][$slotname]) ? $chunks[$type][$slotname] : Chunk::edit($type, $slotname); }); return $template->getView(); }
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 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); } } }); }
public function lookupPagePermission(Person $person, $role, Page $page) { // Page permissions are prefixed with p_ so add the prefix if it's not present. if (substr($role, 0, 2) !== 'p_') { $role = 'p_' . $role; } do { $result = $this->doLookup($person, $role, $page->getId()); if ($page->getParentId() === null) { break; } if ($result === null) { $page = $page->getParent(); } } while ($result === null && $page !== null); return (bool) $result; }
public function postSave() { $input = $this->request->input(); if (isset($input['template'])) { unset($input['template']); } $chunk = ChunkFacade::create($this->page, $input); if ($this->request->input('template')) { $chunk->template($this->request->input('template')); } // This is usually defined by the page controller. // We need to define a variant of it incase the callback is used in teh chunk view. View::share('chunk', function ($type, $slotname, $page = null) { return ChunkFacade::get($type, $slotname, $page); }); View::share('page', $this->page); Event::fire(new ChunkWasCreated($this->page, $chunk)); return ['status' => $this->page->getCurrentVersion()->getStatus(), 'html' => $chunk->render()]; }
/** * Whether the page can be viewed. * * @param Person $person * @param Page $page * * @return bool */ public function view(Person $person, Page $page) { if (!$page->aclEnabled()) { return true; } if ($page->wasCreatedBy($person) || $this->managesPages()) { return true; } $aclGroupIds = $page->getAclGroupIds(); if (empty($aclGroupIds)) { return true; } $groups = $person->getGroups(); foreach ($groups as $group) { if (in_array($group->getId(), $aclGroupIds)) { return true; } } return false; }
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; }
public function load(Page $page, $chunks) { foreach ($chunks as $type => $slotnames) { $model = ucfirst($type); $class = "\\BoomCMS\\Core\\Chunk\\" . $model; $models = $this->find($type, $slotnames, $page->getCurrentVersion()); $found = []; foreach ($models as $m) { if ($m) { $found[] = $m->slotname; $chunks[$type][$m->slotname] = new $class($page, $m->toArray(), $m->slotname, $this->allowedToEdit($page)); } } $not_found = array_diff($slotnames, $found); foreach ($not_found as $slotname) { $chunks[$type][$slotname] = new $class($page, [], $slotname, $this->allowedToEdit($page)); } } return $chunks; }
/** * Returns whether or not the logged in user can edit the content of a page. * * A page can be edited if it was created by a user or they have edit permissions for the page. * * @param Page $page * * @return bool */ public function isEditable(Page $page) { return $page->wasCreatedBy($this->auth->getPerson()) || $this->auth->loggedIn('edit_page_content', $page); }
/** * TODO: This should probably be in a \Boom\Page\Tags class. */ protected function getTagIds() { return DB::table('pages_tags')->select('tag_id')->where('page_id', '=', $this->page->getId())->lists('tag_id'); }
public function asHtml(Page $page) { $template = $page->getTemplate(); View::share('page', $page); return $template->getView(); }
public function handle() { $this->url->setPageId($this->page->getId())->setIsPrimary(false); URLFacade::save($this->url); }
/** * @param PageInterface $parent * * @return $this */ public function setParent(PageInterface $parent) { if (!$parent->is($this) && $parent->getParentId() !== $this->getId()) { $this->{self::ATTR_PARENT} = $parent->getId(); } return $this; }
/** * @param Page $page * * @return bool */ public function isForPage(PageInterface $page) { return $this->getPageId() === $page->getId(); }
/** * Find a version by page and version ID. * * @param PageModelInterface $page * @param type $versionId * * @return Model */ public function find(PageModelInterface $page, $versionId) { return $this->model->where(Model::ATTR_PAGE, $page->getId())->where(Model::ATTR_ID, $versionId)->first(); }
/** * Determines whether the current user can delete a given page. * * @param Page $page * * @return bool */ public function canDelete(Page $page) { return $page->wasCreatedBy($this->getPerson()) || $this->loggedIn('delete_page', $page) || $this->loggedIn('manage_pages'); }
public function getPrefix(Page $page) { return $page->getParent()->getChildPageUrlPrefix() ?: $page->getParent()->url()->getLocation(); }
/** * Save a page. * * @param PageModelInterface $page * * @return PageModelInterface */ public function save(PageModelInterface $page) { $page->save(); return $page; }
/** * Returns the primary URL for the given page. * * @param PageInterface $page * * @return URLInterface */ public function page(PageInterface $page) { return $this->model->where(Model::ATTR_PAGE_ID, '=', $page->getId())->where(Model::ATTR_IS_PRIMARY, '=', true)->first(); }
public function scopeForPage($query, PageInterface $page) { return $query->where(self::ATTR_PAGE, '=', $page->getId()); }
public function urls() { return view($this->viewPrefix . 'urls', ['page' => $this->page, 'urls' => $this->page->getUrls()]); }
/** * Returns an array of HTML attributes which are required to be make the chunk editable. * * To add other attributes see the attributes method. * * @return array */ public function getRequiredAttributes() { return [$this->attributePrefix . 'chunk' => $this->getType(), $this->attributePrefix . 'slot-name' => $this->slotname, $this->attributePrefix . 'slot-template' => $this->template, $this->attributePrefix . 'page' => $this->page->getId(), $this->attributePrefix . 'chunk-id' => isset($this->attrs['id']) ? $this->attrs['id'] : 0]; }
public function get($type, $slotname, Page $page) { $className = $this->getClassName($type); $chunk = $this->find($type, $slotname, $page->getCurrentVersion()); $attrs = $chunk ? $chunk->toArray() : []; return new $className($page, $attrs, $slotname); }