getCurrentPage() public method

public getCurrentPage ( ) : Node | null
return Jarves\Model\Node | null
Example #1
0
 /**
  * @param int|null $nodeId
  *
  * @return bool
  */
 public function isEditMode($nodeId = null)
 {
     $request = $this->requestStack->getMasterRequest();
     $hasRequest = !!$request;
     if ($nodeId) {
         return $hasRequest && 1 === (int) $request->get('_jarves_editor') && $this->acl->isUpdatable('jarves/node', ['id' => $nodeId]);
     }
     return $hasRequest && 1 === (int) $request->get('_jarves_editor') && $this->pageStack->getCurrentPage() && $this->acl->isUpdatable('jarves/node', ['id' => $this->pageStack->getCurrentPage()->getId()]);
 }
Example #2
0
 /**
  * Injects all necessary files to get the Jarves Content Editor working
  * on the current page response.
  *
  * This register in `parent.jarves` a new jarves.Editor.
  */
 public function registerEditor()
 {
     $this->addMainResources(['noJs' => true]);
     $this->addSessionScripts();
     $page = $this->pageStack->getCurrentPage();
     $response = $this->pageStack->getPageResponse();
     $response->addJsFile('@JarvesBundle/admin/mootools-core-1.4.5-fixed-memory-leak.js');
     $response->addJsFile('@JarvesBundle/admin/mootools-more.js');
     $response->setResourceCompression(false);
     $response->setDomainHandling(false);
     $request = $this->pageStack->getRequest();
     $nodeArray['id'] = $page->getId();
     $nodeArray['title'] = $page->getTitle();
     $nodeArray['domainId'] = $page->getDomainId();
     $nodeArray['theme'] = $page->getTheme();
     $nodeArray['layout'] = $request->query->get('_jarves_editor_layout') ?: $page->getLayout();
     $domain = DomainQuery::create()->findPk($page->getDomainId());
     $domainArray['id'] = $domain->getId();
     $domainArray['domain'] = $domain->getDomain();
     $domainArray['path'] = $domain->getPath();
     $domainArray['theme'] = $domain->getTheme();
     $domainArray['themeOptions'] = $domain->getThemeOptions();
     $options = ['id' => $request->query->get('_jarves_editor_id'), 'node' => $nodeArray, 'domain' => $domainArray];
     if (is_array($extraOptions = $request->query->get('_jarves_editor_options'))) {
         $options = array_merge($options, $extraOptions);
         $options['standalone'] = filter_var($options['standalone'], FILTER_VALIDATE_BOOLEAN);
     }
     $response->addJsAtBottom('window.editor = new parent.jarves.Editor(' . json_encode($options) . ', document.documentElement);');
 }
Example #3
0
 /**
  * @param array $options
  *
  * @return null|Model\Node
  *
  * @throws Exceptions\BundleNotFoundException
  * @throws \Exception
  */
 public function get($options)
 {
     $options['id'] = isset($options['id']) ? $options['id'] : false;
     $options['level'] = isset($options['level']) ? $options['level'] : false;
     //        $withFolders = (isset($options['folders']) && $options['folders'] == 1) ? true : false;
     $navigation = false;
     if (!$navigation && $options['id'] != 'breadcrumb' && ($options['id'] || $options['level'])) {
         if ($options['id'] + 0 > 0) {
             $navigation = $this->pageStack->getPage($options['id'] + 0);
             if (!$navigation) {
                 return null;
             }
         }
         if ($options['level'] > 1) {
             $currentPage = $this->pageStack->getCurrentPage();
             $parents = $currentPage->getParents();
             $parents[] = $currentPage;
             $currentLevel = count($parents) + 1;
             $page = $this->arrayLevel($parents, $options['level']);
             if ($page && $page->getId() > 0) {
                 $navigation = $this->pageStack->getPage($page->getId());
             } elseif ($options['level'] == $currentLevel + 1) {
                 $navigation = $this->pageStack->getCurrentPage();
             }
         }
         if ($options['level'] == 1) {
             $navigation = NodeQuery::create()->findRoot($this->pageStack->getCurrentDomain()->getId());
         }
     }
     return $navigation;
 }
Example #4
0
 /**
  * @param Node|int|string $id Node, node id, or node url
  * @param bool $exact whether it should also return true when a children is active
  * @return bool
  */
 public function isActive($id, $exact = false)
 {
     $current = $this->pageStack->getCurrentPage();
     $url = $this->pageStack->getNodeUrl($current, true, true);
     $purl = $this->pageStack->getNodeUrl($id, true, true);
     if ($url === $purl) {
         return true;
     }
     if (!$exact) {
         if ($url && $purl) {
             $pos = strpos($url, $purl);
             if ($url == '/' || $pos != 0 || $pos === false) {
                 return false;
             } else {
                 return true;
             }
         }
     }
 }
Example #5
0
 /**
  * @param integer $nodeId
  * @param integer $slotId
  * @param array   $params
  *
  * @return string
  */
 public function renderSingleSlot($nodeId = null, $slotId = 1, $params = array())
 {
     $params['id'] = $slotId;
     $disableEditor = isset($params['_disable_editor']) && $params['_disable_editor'] ? true : false;
     if ($this->editMode->isEditMode() && !$disableEditor) {
         return '<div class="jarves-slot jarves-single-slot" params="' . htmlspecialchars(json_encode($params)) . '"></div>';
     }
     if (!$nodeId) {
         $nodeId = $this->pageStack->getCurrentPage()->getId();
     }
     $contents = $this->getSlotContents($nodeId, $slotId);
     return $this->renderSlotContents($contents, $params);
 }
Example #6
0
 /**
  * Build the page and return the PageResponse.
  *
  * Checks for links, mounts etc.
  *
  * @return Response
  * @throws AccessDeniedException
  * @throws \Exception
  */
 public function handleAction()
 {
     $node = $this->pageStack->getCurrentPage();
     //is link
     if ($node->getType() == 1) {
         $to = $node->getLink();
         if (!$to) {
             throw new \Exception('Redirect failed: ' . sprintf('Current page with title %s has no target link.', $node->getTitle()));
         }
         if (intval($to) > 0) {
             return new RedirectResponse($this->pageStack->getNodeUrl($to), 301);
         } else {
             return new RedirectResponse($to, 301);
         }
     }
     if ($this->editMode->isEditMode()) {
         $this->editMode->registerEditor();
     }
     $pageResponse = $this->pageStack->getPageResponse();
     $pageResponse->renderContent();
     return $pageResponse;
     //new Response('<body>ho</body>');
 }
Example #7
0
 public function breadcrumb(\Twig_Environment $twig, $view = 'JarvesBundle:Default:breadcrumb.html.twig')
 {
     $breadcrumbs = [];
     $page = $this->pageStack->getCurrentPage();
     $cacheKey = 'core/breadcrumbs/' . $page->getCacheKey();
     if ($cache = $this->cacher->getDistributedCache($cacheKey)) {
         if (is_string($cache)) {
             return $cache;
         }
     }
     foreach ($page->getParents() as $parent) {
         if ($parent->getLevel() === 0) {
             continue;
         }
         if ($parent->getType() >= 2) {
             continue;
         }
         $breadcrumbs[] = $parent;
     }
     $data = ['domain' => $this->pageStack->getCurrentDomain(), 'baseUrl' => $this->pageStack->getPageResponse()->getBaseHref(), 'breadcrumbs' => $breadcrumbs, 'currentPage' => $this->pageStack->getCurrentPage()];
     $html = $twig->render($view, $data);
     $this->cacher->setDistributedCache($cacheKey, $html);
     return $html;
 }
Example #8
0
 /**
  * Gets the html title.
  *
  * @return string
  */
 public function getTitle()
 {
     if (null !== $this->title) {
         return $this->title;
     }
     if ($this->getDomainHandling() && $this->pageStack->getCurrentDomain()) {
         $title = $this->pageStack->getCurrentDomain()->getTitleFormat() ?: '%title%';
         if ($page = $this->pageStack->getCurrentPage()) {
             return str_replace(array('%title%'), array($page->getAlternativeTitle() ?: $page->getTitle()), $title);
         }
     } else {
         if ($this->pageStack->getCurrentPage()) {
             return $this->pageStack->getCurrentPage()->getTitle();
         }
     }
 }