/** * isPageAllowedForReading * * @param Page $page * * @return bool */ public function isPageAllowedForReading(Page $page) { $allowed = $this->rcmUserService->isAllowed($this->buildPageResourceId($page->getSite()->getSiteId(), $page->getPageType(), $page->getName()), 'read', 'Rcm\\Acl\\ResourceProvider'); /* ltrim added for BC */ $currentPage = $page->getName(); $siteLoginPage = ltrim($page->getSite()->getLoginPage(), '/'); $notAuthorizedPage = ltrim($page->getSite()->getNotAuthorizedPage(), '/'); $notFoundPage = ltrim($page->getSite()->getNotFoundPage(), '/'); if ($siteLoginPage == $currentPage || $notAuthorizedPage == $currentPage || $notFoundPage == $currentPage) { $allowed = true; } return $allowed; }
/** * Update config place holders with correct data * * @param $item * @param $key * @param $revisionNumber * * @return void */ protected function updatePlaceHolders(&$item, $key, $revisionNumber) { if (empty($this->page)) { return; } $find = [':rcmPageName', ':rcmPageType', ':rcmPageRevision']; $replace = [$this->page->getName(), $this->page->getPageType(), $revisionNumber]; $item = str_replace($find, $replace, $item); }
/** * getRevisionLink * * @param Page $page * @param RevisionEntity $revision * * @return string */ public function getRevisionLink(Page $page, RevisionEntity $revision) { $view = $this->getView(); $revisionId = $revision->getRevisionId(); $publishedId = $page->getPublishedRevision(); $stagedId = $page->getStagedRevision(); if (!empty($publishedId) && $publishedId->getRevisionId() == $revision->getRevisionId() || !empty($stagedId) && $stagedId->getRevisionId() == $revision->getRevisionId()) { $revisionId = null; } $html = '<a href="' . $view->urlToPage($page->getName(), $page->getPageType(), $revisionId) . '">'; $html .= $this->getRevisionType($page, $revision) . ' - ' . $revision->getAuthor(); $html .= '</a>'; return $html; }
/** * create * * @param mixed $data * * @return mixed|ApiJsonModel|\Zend\Stdlib\ResponseInterface */ public function create($data) { //ACCESS CHECK if (!$this->rcmIsAllowed('sites', 'admin')) { $this->getResponse()->setStatusCode(Response::STATUS_CODE_401); return $this->getResponse(); } $siteId = $this->getRequestSiteId(); $site = $this->getSite($siteId); if (empty($site)) { return new ApiJsonModel(null, 1, "Site was not found with id {$siteId}."); } // // // $inputFilter = new SitePageDuplicateInputFilter(); $inputFilter->setData($data); if (!$inputFilter->isValid()) { return new ApiJsonModel([], 1, 'Some values are missing or invalid for page duplication.', $inputFilter->getMessages()); } $data = $inputFilter->getValues(); $destinationSite = $this->getSite($data['destinationSiteId']); if (empty($destinationSite)) { return new ApiJsonModel(null, 1, "Destination site was not found with id {$data['destinationSiteId']}."); } $page = $this->getPage($site, $data['pageId']); $newPage = new Page(); $newPage->populate($data); if (empty($page)) { return new ApiJsonModel(null, 1, "Source page was not found with id {$data['pageId']}."); } if ($this->hasPage($destinationSite, $newPage->getName(), $newPage->getPageType())) { return new ApiJsonModel(null, 1, 'Page already exists, duplicates cannot be created'); } // force author to current user $newPage->setAuthor($this->getCurrentAuthor()); try { $newPage = $this->getPageRepo()->copyPage($destinationSite, $page, $newPage->toArray(), null, true); } catch (\Exception $e) { return new ApiJsonModel(null, 1, $e->getMessage()); } $apiResponse = new SitePageApiResponse(); $apiResponse->populate($newPage->toArray()); return new ApiJsonModel($apiResponse, 0, "Success: Duplicated page to site {$data['destinationSiteId']}"); }
/** * prepPageRevisionForDisplay * * @param Page $page * @param null $pageRevisionId * * @return void|Response */ public function prepPageRevisionForDisplay(Page $page, $pageRevisionId = null) { // First Check for a page Revision if (!empty($pageRevisionId)) { $userCanSeeRevisions = $this->shouldShowRevisions($page->getSite()->getSiteId(), $page->getName(), $page->getPageType()); if ($userCanSeeRevisions) { $revision = $page->getRevisionById($pageRevisionId); if (!empty($revision) || $revision instanceof Revision) { $page->setCurrentRevision($revision); } return; } else { return $this->redirectToPage($page->getName(), $page->getPageType()); } } // Check for staging if ($this->rcmIsSiteAdmin($page->getSite())) { $revision = $page->getStagedRevision(); if (!empty($revision) || $revision instanceof Revision) { $page->setCurrentRevision($revision); return; } } // Finally look for published revision $revision = $page->getPublishedRevision(); if (!empty($revision) || $revision instanceof Revision) { $page->setCurrentRevision($revision); } return; }
public function testUtilities() { $data = []; $data['name'] = 'testname'; $data['pageTitle'] = 'TESTTITLE'; $data['pageType'] = 'n'; $data['description'] = 'TESTDESC'; $data['keywords'] = 'KEY,WORD'; $data['author'] = 'TESTAUTHOR'; $data['pageLayout'] = 'TESTPAGELAYOUT'; $data['siteLayoutOverride'] = 'TESTLAYOUTOVERRIDE'; $data['parent'] = null; $obj1 = new Page(); $obj1->populate($data); $this->assertEquals($data['name'], $obj1->getName()); $this->assertEquals($data['pageTitle'], $obj1->getPageTitle()); $this->assertEquals($data['pageType'], $obj1->getPageType()); $this->assertEquals($data['description'], $obj1->getDescription()); $this->assertEquals($data['keywords'], $obj1->getKeywords()); $this->assertEquals($data['author'], $obj1->getAuthor()); $this->assertEquals($data['pageLayout'], $obj1->getPageLayout()); $this->assertEquals($data['siteLayoutOverride'], $obj1->getSiteLayoutOverride()); $this->assertEquals($data['parent'], $obj1->getParent()); $data['parent'] = new Page(); $obj1->populate($data); $this->assertEquals($data['parent'], $obj1->getParent()); // $json = json_encode($obj1); $this->assertJson($json); $iterator = $obj1->getIterator(); $this->assertInstanceOf('\\ArrayIterator', $iterator); $array = $obj1->toArray([]); $this->assertEquals($data['name'], $array['name']); $this->assertEquals($data['pageTitle'], $array['pageTitle']); $this->assertEquals($data['pageType'], $array['pageType']); $this->assertEquals($data['description'], $array['description']); $this->assertEquals($data['keywords'], $array['keywords']); $this->assertEquals($data['author'], $array['author']); $this->assertEquals($data['pageLayout'], $array['pageLayout']); $this->assertEquals($data['siteLayoutOverride'], $array['siteLayoutOverride']); $this->assertEquals($data['parent'], $array['parent']); }
/** * Get all Page Resources * * @param Page $page Rcm Page Entity * @param Site $site Rcm Site Entity * * @return mixed */ protected function getPageResources(Page $page, Site $site) { $primaryDomainName = $site->getDomain()->getDomainName(); $siteId = $site->getSiteId(); $pageName = $page->getName(); $pageType = $page->getPageType(); $return['sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName] = ['resourceId' => 'sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName, 'parentResourceId' => 'sites.' . $siteId . '.pages', 'name' => $primaryDomainName . ' - pages - ' . $pageName, 'description' => "Resource for page '{$pageName}'" . " of type '{$pageType}' on site '{$primaryDomainName}'"]; $return['sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName] = array_merge($this->resources['pages'], $return['sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName]); return $return; }