Beispiel #1
0
<?php

use joppa\Module;
$module = new Module();
$module->initialize();
 /**
  * Get a NodeSettings object for a node
  * @param int|Node $node
  * @return NodeSettings
  */
 public function getNodeSettings($node)
 {
     if (is_numeric($node)) {
         $nodeId = $node;
         $node = null;
     } else {
         $nodeId = $node->id;
     }
     $cache = Module::getCache();
     $nodeSettings = $cache->get(Module::CACHE_TYPE_NODE_SETTINGS, $nodeId);
     if ($nodeSettings !== null) {
         return $nodeSettings;
     }
     if (!$node) {
         $nodeModel = $this->getModel(NodeModel::NAME);
         $node = $nodeModel->getNode($nodeId, 0);
     }
     $inheritedSettings = null;
     if ($node->parent) {
         $inheritedSettings = $this->getNodeSettings($node->getParentNodeId());
     }
     $nodeSettings = new NodeSettings($node, $inheritedSettings);
     $settings = $this->findByNodeId($nodeId);
     foreach ($settings as $setting) {
         $nodeSettings->setNodeSetting($setting);
     }
     $cache->set(Module::CACHE_TYPE_NODE_SETTINGS, $nodeId, $nodeSettings);
     return $nodeSettings;
 }
 /**
  * Get the dispatcher of a node. This method uses the Joppa cache to store the dispatcher.
  * @param int $id id of the node
  * @param string $baseUrl base url of the site
  * @return mixed null no node found or the node is not available in the frontend;
  *               string class name of the node's frontend controller;
  *               joppa\controller\frontend\NodeDispatcher a node dispatcher
  */
 private function getNodeDispatcher($id, $baseUrl)
 {
     $cache = Module::getCache();
     $locale = LocalizeController::getLocale();
     $cacheKey = md5($baseUrl) . '-' . $id . '-' . $locale;
     $nodeDispatcher = $cache->get(Module::CACHE_TYPE_NODE_DISPATCHER, $cacheKey);
     if ($nodeDispatcher) {
         return $nodeDispatcher;
     }
     $node = $this->request->getNode();
     $frontendController = NodeTypeFacade::getInstance()->getFrontendController($node->type);
     if ($frontendController) {
         $cache->set(Module::CACHE_TYPE_NODE_DISPATCHER, $cacheKey, $frontendController);
         return $frontendController;
     }
     $breadcrumbs = $this->models[NodeModel::NAME]->getBreadcrumbsForNode($node, $baseUrl);
     $rootNode = $node->getRootNode();
     $nodeView = new NodeView($node, $rootNode->name);
     $nodeDispatcher = new NodeDispatcher($node, $nodeView);
     $nodeDispatcher->setBreadcrumbs($breadcrumbs);
     $cache->set(Module::CACHE_TYPE_NODE_DISPATCHER, $cacheKey, $nodeDispatcher);
     return $nodeDispatcher;
 }
Beispiel #4
0
 /**
  * Gets the a list of the sites with a base URL
  * @return array Array with the base URL of the site as key and the id of the site as value. The default site will be indexed with key 0 instead of the url
  */
 public function getSiteUrls()
 {
     $cache = Module::getCache();
     $urls = $cache->get(Module::CACHE_TYPE_SITE_URLS, 0);
     if ($urls) {
         return $urls;
     }
     $query = $this->createQuery(0);
     $query->addCondition('({defaultNode} IS NOT NULL AND {defaultNode} <> %1%)', '');
     $query->addCondition('({baseUrl} IS NOT NULL AND {baseUrl} <> %1%) OR {isDefault} = %2%', '', true);
     $sites = $query->query();
     $urls = array();
     foreach ($sites as $site) {
         if ($site->isDefault) {
             $urls[0] = $site;
         } elseif ($site->baseUrl) {
             $urls[$site->baseUrl] = $site;
         }
     }
     $cache->set(Module::CACHE_TYPE_SITE_URLS, 0, $urls);
     return $urls;
 }
 /**
  * Dispatch the node
  * @param zibo\core\Request $request
  * @param zibo\core\Response $response
  * @return array Array with the region name as key and a view array as value. The view array has the widget id as key and the dispatched widget view as value
  */
 public function dispatch(Request $request, Response $response)
 {
     $cache = Module::getCache();
     if (!$this->breadcrumbs) {
         $this->breadcrumbs = new Breadcrumbs();
     }
     $parameters = str_replace(Request::QUERY_SEPARATOR, '-', $request->getParametersAsString());
     $views = array();
     foreach ($this->regions as $regionName => $widgets) {
         foreach ($widgets as $widgetId => $widget) {
             $isJoppaWidget = $widget instanceof JoppaWidget;
             $cacheKey = $this->node->id . '#' . $regionName . '#' . $widgetId . '#' . $this->node->dataLocale . '#' . $parameters;
             if ($isJoppaWidget) {
                 if (!$_POST) {
                     $view = $cache->get(Module::CACHE_TYPE_NODE_WIDGET_VIEW, $cacheKey);
                     if ($view) {
                         $views[$regionName][$widgetId] = $view;
                         continue;
                     }
                 }
                 $widget->setBreadcrumbs($this->breadcrumbs);
                 $widget->setNode($this->node);
             }
             $this->dispatchWidget($request, $response, $widgetId, $widget);
             if ($response->willRedirect()) {
                 return;
             }
             $view = $response->getView();
             $response->setView(null);
             if ($view instanceof FileView) {
                 return $view;
             }
             if ($isJoppaWidget && $widget->isContent()) {
                 if ($request->isXmlHttpRequest()) {
                     return $view;
                 }
                 $views[$regionName] = array($widgetId => $view);
                 break;
             }
             if ($isJoppaWidget && $widget->isCacheable()) {
                 $cache->set(Module::CACHE_TYPE_NODE_WIDGET_VIEW, $cacheKey, $view);
             }
             $views[$regionName][$widgetId] = $view;
         }
     }
     return $views;
 }
Beispiel #6
0
 /**
  * Get an array with the nodes and specify the number of levels for fetching the children of the nodes.
  * @param int|Node $parent the parent node
  * @param string|array $excludes id's of nodes which are not to be included in the result
  * @param int $maxDepth maximum number of nested levels will be looked for
  * @param string $locale Locale code
  * @param boolean $loadSettings set to true to load the NodeSettings object of the node
  * @param boolean $isFrontend Set to true to get only the nodes available in the frontend*
  * @return array Array with the node id as key and the node as value
  */
 public function getNodeTree($parent, $excludes = null, $maxDepth = null, $locale = null, $includeUnlocalized = null, $loadSettings = false, $isFrontend = false)
 {
     if ($excludes) {
         if (!is_array($excludes)) {
             $excludes = array($excludes);
         }
     } else {
         $excludes = array();
     }
     $cache = Module::getCache();
     $cacheKey = md5('p' . $parent . 'd' . $maxDepth . 's' . $loadSettings . 'e' . implode(',', $excludes) . 'l' . $locale . 'i' . ($includeUnlocalized === null ? 'n' : $includeUnlocalized) . 'f' . $isFrontend);
     $tree = $cache->get(Module::CACHE_TYPE_NODE_TREE, $cacheKey);
     if ($tree) {
         return $tree;
     }
     $nodeSettingsModel = null;
     if ($loadSettings) {
         $nodeSettingsModel = $this->getModel(NodeSettingModel::NAME);
     }
     if (is_numeric($parent)) {
         $parent = $this->getNode($parent, 0, $locale);
     }
     $tree = $this->getNodes($parent, $excludes, $maxDepth, $locale, $includeUnlocalized, $nodeSettingsModel, $isFrontend);
     $cache->set(Module::CACHE_TYPE_NODE_TREE, $cacheKey, $tree);
     return $tree;
 }
Beispiel #7
0
 /**
  * Get the widgets for a region
  * @param string $region name of the region
  * @return array Array with zibo\library\widget\controller\Widget objects
  * @throws zibo\ZiboException when the NodeSettings are not set to this node
  * @throws zibo\ZiboException when a widget could not be found
  */
 public function getWidgets($region)
 {
     $cache = Module::getCache();
     $cacheKey = $this->id . '-' . $region;
     $widgets = $cache->get(Module::CACHE_TYPE_NODE_WIDGETS, $cacheKey);
     if ($widgets !== null) {
         return $widgets;
     }
     $this->checkSettings();
     $widgets = array();
     $widgetString = $this->settings->get(NodeSettingModel::SETTING_WIDGETS . '.' . $region);
     if (!$widgetString) {
         $cache->set(Module::CACHE_TYPE_NODE_WIDGETS, $cacheKey, $widgets);
         return $widgets;
     }
     $widgetIdModel = ModelManager::getInstance()->getModel(WidgetModel::NAME);
     $widgetObjectModel = ZiboWidgetModel::getInstance();
     $widgetIds = explode(NodeSettingModel::WIDGETS_SEPARATOR, $widgetString);
     foreach ($widgetIds as $widgetId) {
         $widgetId = trim($widgetId);
         $widget = $widgetIdModel->findById($widgetId);
         if (!$widget) {
             throw new ZiboException('No widget found for id ' . $widgetId);
         }
         $widget = $widgetObjectModel->getWidget($widget->namespace, $widget->name);
         $widgets[$widgetId] = $widget;
     }
     $cache->set(Module::CACHE_TYPE_NODE_WIDGETS, $cacheKey, $widgets);
     return $widgets;
 }