/** * Setup for tests * * @return void */ public function setup() { $this->domains = ['reliv.com' => ['domain' => 'local.reliv.com', 'primaryDomain' => null, 'languageId' => 'eng', 'siteId' => 1, 'countryId' => 'USA'], 'www.reliv.com' => ['domain' => 'local.reliv.com', 'primaryDomain' => 'reliv.com', 'languageId' => 'eng', 'siteId' => 1, 'countryId' => 'USA']]; $this->redirects = ['/requestOne' => ['requestUrl' => '/requestOne', 'redirectUrl' => 'reliv.com/redirectOne'], '/requestTwo' => ['requestUrl' => '/requestTwo', 'redirectUrl' => 'reliv.com/redirectTwo']]; $config = []; $this->currentSite = new Site(); $this->currentSite->setSiteId(1); $this->currentSite->setStatus(Site::STATUS_ACTIVE); $domain = new Domain(); $domain->setDomainId(1); $domain->setDomainName('reliv.com'); $this->currentSite->setDomain($domain); $this->redirectRepo = $this->getMockBuilder('\\Rcm\\Repository\\Redirect')->disableOriginalConstructor()->getMock(); $map = []; foreach ($this->redirects as $key => $redirect) { $redirectEntity = new Redirect(); $redirectEntity->setRedirectUrl($redirect['requestUrl']); $redirectEntity->setRedirectUrl($redirect['redirectUrl']); $map[] = [$key, $this->currentSite->getSiteId(), $redirectEntity]; } $this->redirectRepo->expects($this->any())->method('getRedirect')->will($this->returnValueMap($map)); ////////////// $this->siteServiceMock = $this->getMockBuilder(SiteService::class)->disableOriginalConstructor()->getMock(); $this->siteServiceMock->expects($this->any())->method('getCurrentSite')->will($this->returnValue($this->currentSite)); $this->siteServiceMock->expects($this->any())->method('isConsoleRequest')->will($this->returnValue(false)); $this->redirectServiceMock = $this->getMockBuilder(RedirectService::class)->disableOriginalConstructor()->getMock(); $this->domainRedirectServiceMock = $this->getMockBuilder(DomainRedirectService::class)->disableOriginalConstructor()->getMock(); $this->localeServiceMock = $this->getMockBuilder(LocaleService::class)->disableOriginalConstructor()->getMock(); $this->routeListener = new RouteListener($this->siteServiceMock, $this->redirectServiceMock, $this->domainRedirectServiceMock, $this->localeServiceMock); }
/** * Test Get and Set Site Id * * @return void * * @covers \Rcm\Entity\Site */ public function testGetAndSetRevisionId() { $id = 101; $this->site->setSiteId($id); $actual = $this->site->getSiteId(); $this->assertEquals($id, $actual); }
/** * Initialize the form * * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function init() { $pageList = $this->pageRepo->getAllPageIdsAndNamesBySiteThenType($this->currentSite->getSiteId(), 't'); $pageList['blank'] = 'Blank Page (Experts Only)'; $filter = new InputFilter(); $this->add(['name' => 'url', 'options' => ['label' => 'Page Url'], 'type' => 'text']); $filter->add(['name' => 'url', 'required' => true, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim', 'options' => ['charlist' => '-_']]], 'validators' => [$this->pageValidator]]); $this->add(['name' => 'title', 'options' => ['label' => 'Page Title'], 'type' => 'text']); $filter->add(['name' => 'title', 'required' => true, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [['name' => '\\Zend\\I18n\\Validator\\Alnum', 'options' => ['allowWhiteSpace' => true]]]]); $this->add(['name' => 'page-template', 'options' => ['label' => 'Page Template', 'value_options' => $pageList], 'type' => 'Zend\\Form\\Element\\Select']); $filter->add(['name' => 'page-template', 'required' => true, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [$this->templateValidator]]); $this->add(['name' => 'main-layout', 'options' => ['label' => 'Main Layout', 'layouts' => $this->layoutManager->getSiteThemeLayoutsConfig($this->currentSite->getTheme())], 'type' => 'mainLayout']); $filter->add(['name' => 'main-layout', 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [$this->layoutValidator]]); $this->setInputFilter($filter); }
/** * 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($this->currentSite->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($this->currentSite)) { $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; }
/** * Check the defined redirects. If requested URL is found, redirect to the * new location. * * @param MvcEvent $event Zend MVC Event * * @return null|Response */ public function checkRedirect(MvcEvent $event) { $siteId = $this->currentSite->getSiteId(); if (empty($siteId)) { return null; } /** @var \Zend\Http\PhpEnvironment\Request $request */ $request = $event->getRequest(); $serverParam = $request->getServer(); $requestUri = $serverParam->get('REQUEST_URI'); $baseUri = explode('?', $requestUri); $requestUrl = $baseUri[0]; $redirect = $this->redirectRepo->getRedirect($requestUrl, $siteId); if (!empty($redirect)) { header('Location: ' . $redirect->getRedirectUrl(), true, 302); exit; /* Below is the ZF2 way but Response is not short-circuiting the event like it should */ // $response = new Response(); // $response->setStatusCode(302); // $response->getHeaders() // ->addHeaderLine( // 'Location', // $redirect->getRedirectUrl() // ); // $event->stopPropagation(true); // // return $response; } return null; }
/** * savePageAction * * @return Response|\Zend\Http\Response */ public function savePageAction() { if (!$this->rcmIsAllowed('sites.' . $this->currentSite->getSiteId() . '.pages', 'edit')) { $response = new Response(); $response->setStatusCode('401'); return $response; } // @todo - might validate these against the data coming in $pageName = $this->getEvent()->getRouteMatch()->getParam('rcmPageName', 'index'); $pageRevision = $this->getEvent()->getRouteMatch()->getParam('rcmPageRevision', null); $pageType = $this->getEvent()->getRouteMatch()->getParam('rcmPageType', 'n'); /** @var \Zend\Http\Request $request */ $request = $this->getRequest(); if ($request->isPost()) { /** @var \Zend\Stdlib\Parameters $data */ $data = $request->getPost()->toArray(); $this->prepSaveData($data); $result = $this->pageRepo->savePage($this->currentSite, $pageName, $pageRevision, $pageType, $data, $this->rcmUserGetCurrentUser()->getName()); if (empty($result)) { $return['redirect'] = $this->urlToPage($pageName, $pageType, $pageRevision); } else { $return['redirect'] = $this->urlToPage($pageName, $pageType, $result); } return $this->getJsonResponse($return); } $response = new Response(); $response->setStatusCode('404'); return $response; }
/** * Setup for tests * * @return void */ public function setup() { $this->domains = ['reliv.com' => ['domain' => 'local.reliv.com', 'primaryDomain' => null, 'languageId' => 'eng', 'siteId' => 1, 'countryId' => 'USA'], 'www.reliv.com' => ['domain' => 'local.reliv.com', 'primaryDomain' => 'reliv.com', 'languageId' => 'eng', 'siteId' => 1, 'countryId' => 'USA']]; $this->redirects = ['/requestOne' => ['requestUrl' => '/requestOne', 'redirectUrl' => 'reliv.com/redirectOne'], '/requestTwo' => ['requestUrl' => '/requestTwo', 'redirectUrl' => 'reliv.com/redirectTwo']]; $config = []; $this->currentSite = new Site(); $this->currentSite->setSiteId(1); $this->currentSite->setStatus('A'); $domain = new Domain(); $domain->setDomainId(1); $domain->setDomainName('reliv.com'); $this->currentSite->setDomain($domain); $this->redirectRepo = $this->getMockBuilder('\\Rcm\\Repository\\Redirect')->disableOriginalConstructor()->getMock(); $map = []; foreach ($this->redirects as $key => $redirect) { $redirectEntity = new Redirect(); $redirectEntity->setRedirectUrl($redirect['requestUrl']); $redirectEntity->setRedirectUrl($redirect['redirectUrl']); $map[] = [$key, $this->currentSite->getSiteId(), $redirectEntity]; } $this->redirectRepo->expects($this->any())->method('getRedirect')->will($this->returnValueMap($map)); $this->routeListener = new RouteListener($this->currentSite, $this->redirectRepo, new \Zend\Validator\Ip(), $config); }
/** * Get the Admin Menu Bar * * @return mixed */ public function getAdminWrapperAction() { $allowed = $this->cmsPermissionChecks->siteAdminCheck($this->currentSite); if (!$allowed) { return null; } /** @var RouteMatch $routeMatch */ $routeMatch = $this->getEvent()->getRouteMatch(); $siteId = $this->currentSite->getSiteId(); $sourcePageName = $routeMatch->getParam('page', 'index'); if ($sourcePageName instanceof Page) { $sourcePageName = $sourcePageName->getName(); } $pageType = $routeMatch->getParam('pageType', 'n'); $view = new ViewModel(); $view->setVariable('restrictions', false); if ($this->cmsPermissionChecks->isPageRestricted($siteId, $pageType, $sourcePageName, 'read') == true) { $view->setVariable('restrictions', true); } $view->setVariable('adminMenu', $this->adminPanelConfig); $view->setTemplate('rcm-admin/admin/admin'); return $view; }
/** * getRevisionList * * @param bool $published * @param int $limit * * @return array|mixed */ protected function getRevisionList($published = false, $limit = 10) { $revisions = $this->pageRepo->getRevisionList($this->currentSite->getSiteId(), $this->page->getName(), $this->page->getPageType(), $published, $limit); return $revisions; }
/** * Set site the page belongs to * * @param Site $site Site object to add * * @return void */ public function setSite(Site $site) { $this->site = $site; $this->siteId = $site->getSiteId(); }
/** * 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; }
/** * Set the Site the redirect belongs to * * @param \Rcm\Entity\Site $site Site Entity * * @return void */ public function setSite($site) { if ($site === null) { $this->siteId = null; $this->site = null; return; } $this->siteId = $site->getSiteId(); $this->site = $site; }
/** * prepareNewSite * * @param Site $newSite * * @return Site * @throws \Exception */ protected function prepareNewSite(Site $newSite) { $siteId = $newSite->getSiteId(); if (!empty($siteId)) { throw new \Exception("Site ID must be empty to create new site, id {$siteId} given."); } if (empty($newSite->getDomain())) { throw new \Exception('Domain is required to create new site.'); } return $this->prepareDefaultValues($newSite); }
/** * siteAdminCheck * * @param Site $site * * @return bool */ public function siteAdminCheck(Site $site) { return $this->rcmUserService->isAllowed($this->buildSiteResourceId($site->getSiteId()), 'admin', 'Rcm\\Acl\\ResourceProvider'); }