/** * Construct the NodeSetting container * @param Node $node the node who owns the settings in this object * @param NodeSettings $inheritedSettings NodeSetting container to inherit from (optional) * @return null */ public function __construct(Node $node, NodeSettings $inheritedSettings = null) { $this->node = $node; $this->settings = array(); $this->inheritedSettings = $inheritedSettings; $this->defaultInherit = NodeTypeFacade::getInstance()->getDefaultInherit($node->type); }
/** * Construct this view * @param joppa\form\backend\SiteSelectForm $siteSelectForm form to select another site * @param joppa\model\Site $site the current site (optional) * @param joppa\model\Node $node the current node (optional) * @return null */ public function __construct(SiteSelectForm $siteSelectForm, Site $site = null, Node $node = null) { parent::__construct('joppa/backend/sidebar'); $createActions = array(); $baseUrl = $this->get('_baseUrl') . '/'; $nodeTypeFacade = NodeTypeFacade::getInstance(); $nodeTreeHtml = null; if ($site) { $this->setSubview('tree', new TreeView($site, $node)); $toggleAction = $baseUrl . Module::ROUTE_AJAX_TREE; $orderAction = $baseUrl . Module::ROUTE_JOPPA . '/node/order/'; $translator = I18n::getInstance()->getTranslator(); $deleteConfirmMessage = $translator->translate(self::TRANSLATION_DELETE_NODE_CONFIRM); $this->addJavascript(self::SCRIPT_TREE); $this->addInlineJavascript("joppaInitializeNodeTree('{$toggleAction}', '{$orderAction}', '{$deleteConfirmMessage}');"); $labels = $nodeTypeFacade->getLabels(); foreach ($labels as $type => $label) { $action = array('type' => $type, 'label' => $label, 'url' => $baseUrl . Module::ROUTE_JOPPA . '/' . $type . '/add'); $createActions[] = $action; } } else { $createActions[] = array('type' => SiteModel::NODE_TYPE, 'label' => $nodeTypeFacade->getLabel(SiteModel::NODE_TYPE), 'url' => $baseUrl . Module::ROUTE_JOPPA . '/' . SiteModel::NODE_TYPE . '/add'); } $this->set('formSiteSelect', $siteSelectForm); $this->set('createActions', $createActions); }
/** * Dispatches or redirects the node action to the right node action controller * @param string $action * @param int $id id of the node * @return null */ public function indexAction($action = null, $id = null) { if (!$id && !$action) { $this->response->setRedirect($this->getJoppaBaseUrl()); return; } if (!$this->site) { $this->response->setRedirect($this->getJoppaBaseUrl()); return; } if (!$id && is_numeric($action)) { $lastAction = $this->getSession()->get(self::SESSION_LAST_ACTION, 'content'); $this->response->setRedirect($this->getJoppaBaseUrl() . '/node/' . $lastAction . '/' . $action); return; } if (!$this->node || $this->node->id != $id) { $this->node = $this->models[NodeModel::NAME]->getNode($id, 0); if ($this->node) { $parameters = func_get_args(); $url = $this->request->getBasePath() . Request::QUERY_SEPARATOR . implode(Request::QUERY_SEPARATOR, $parameters); $this->response->setRedirect($url); } else { $this->response->setRedirect($this->getJoppaBaseUrl()); } return; } $nodeActionManager = NodeActionManager::getInstance(); if ($nodeActionManager->hasAction($action)) { // chain to the node action $this->getSession()->set(self::SESSION_LAST_ACTION, $action); $nodeAction = $nodeActionManager->getAction($action); $parameters = func_get_args(); $action = array_shift($parameters); $id = array_shift($parameters); $basePath = $this->request->getBasePath(); $basePath .= Request::QUERY_SEPARATOR . $action . Request::QUERY_SEPARATOR . $id; return $this->forward(get_class($nodeAction), null, $parameters, $basePath); } // chain to the node type's backend controller $nodeTypeFacade = NodeTypeFacade::getInstance(); if (!$nodeTypeFacade->hasNodeType($this->node->type)) { return $this->setError404(); } $nodeTypeController = $nodeTypeFacade->getBackendController($this->node->type); if (!$nodeTypeController) { return $this->setError404(); } $nodeId = $this->node->id; $nodeData = $nodeTypeFacade->getNodeData($this->node->type, $nodeId, 0); if ($nodeData) { $nodeId = $nodeData->id; } $parameters = func_get_args(); $action = array_shift($parameters); array_shift($parameters); array_unshift($parameters, $action, $nodeId); $basePath = $this->getJoppaBaseUrl() . Request::QUERY_SEPARATOR . $this->node->type; return $this->forward($nodeTypeController, null, $parameters, $basePath); }
/** * Construct this setting container * @param int $widgetId id of the widget for who this container acts * @param NodeSettings $nodeSettings underlying setting container * @return null */ public function __construct($widgetId, NodeSettings $nodeSettings) { $this->node = $nodeSettings->node; $this->settings = $nodeSettings->settings; $this->inheritedSettings = $nodeSettings->inheritedSettings; $this->defaultInherit = NodeTypeFacade::getInstance()->getDefaultInherit($this->node->type); $this->widgetId = $widgetId; $this->widgetSettingPrefix = NodeSettingModel::SETTING_WIDGET . '.' . $this->widgetId . '.'; }
/** * Render this view * @param boolean $return Set to false to output the rendered view * @return null|string The rendered view if $return is set to true, null otherwise */ public function render($return = true) { $this->baseUrl = Zibo::getInstance()->getRequest()->getBaseUrl() . '/'; $this->nodeTypeFacade = NodeTypeFacade::getInstance(); $this->locale = LocalizeController::getLocale(); $this->translator = I18n::getInstance()->getTranslator(); $defaultNodeId = null; if ($this->site->defaultNode) { $defaultNodeId = $this->site->defaultNode->id; } $siteModel = ModelManager::getInstance()->getModel(SiteModel::NAME); $this->site->node->children = $siteModel->getNodeTreeForSite($this->site, null, null, $this->locale, true); $nodeTree = array($this->site->node->id => $this->site->node); $output = $this->getNodeTreeHtml($nodeTree, $defaultNodeId, $this->site->localizationMethod == SiteModel::LOCALIZATION_METHOD_COPY, $this->node); if ($return) { return $output; } echo $output; }
/** * 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; }
/** * Checks if this action is available for the node * @param joppa\model\Node $node * @return boolean true if available */ public function isAvailableForNode(Node $node) { return NodeTypeFacade::getInstance()->isAvailableInFrontend($node->type); }
/** * Get the HTML of a node * @param joppa\model\Node $node the node to render * @param int $defaultNodeId id of the node of the default page * @param joppa\model\Node $selectedNode the current node in the ui * @param boolean $addUnlocalizedClass Set to true to add the unlocalized class to nodes which are not localized in the current locale * @param int $truncateSize number of characters to truncate the name to * @return string HTML representation of the node */ private function getNodeHtml(Node $node, $defaultNodeId, $addUnlocalizedClass, Node $selectedNode = null, $truncateSize = 20) { $isNodeSelected = false; if ($selectedNode && $selectedNode->id == $node->id) { $isNodeSelected = true; } $nodeClass = 'node'; if ($isNodeSelected) { $nodeClass .= ' selected'; } if ($addUnlocalizedClass) { if ($node->dataLocale != $this->locale) { $nodeClass .= ' unlocalized'; } else { $nodeClass .= ' localized'; } } if (AjaxTreeController::isNodeCollapsed($node->id)) { $nodeClass .= ' closed'; } $html = '<li class="' . $nodeClass . '" id="node_' . $node->id . '">'; if ($this->nodeTypeFacade->isAvailableInFrontend($node->type)) { if ($node->isSecured()) { $nodeClass = 'secured' . ucfirst($node->type); } else { $nodeClass = $node->type; } if ($node->id == $defaultNodeId) { $nodeClass .= 'Default'; } if (!$node->isPublished()) { $nodeClass .= 'Hidden'; } } else { $nodeClass = $node->type; } if ($node->children) { $html .= '<a href="#" class="toggle"></a>'; } else { $html .= '<span class="toggle"></span>'; } $icon = new Image($this->getIcon($nodeClass)); $html .= '<div class="handle ' . $nodeClass . '">'; $html .= $icon->getHtml(); $html .= '</div>'; $html .= '<div class="menu">'; $html .= $this->getAnchorHtml('/node/' . $node->id, String::truncate($node->name, $truncateSize, '...', true, true), false, 'name', null, $node->name); $html .= $this->getAnchorHtml('#', ' ', false, 'actionMenuNode', 'nodeActions_' . $node->id); // $html .= $this->getAnchorHtml(' <a href="#" class="actionMenuNode" id="nodeActions_' . $node->id . '" title="' . $node->name . '"></a>'; // $html .= ' <a href="#" class="actionMenuNode" id="nodeActions_' . $node->id . '" title="' . $node->name . '"></a>'; $html .= '<ul class="actions" id="nodeActions_' . $node->id . 'Menu">'; $addedActions = false; foreach ($this->actions as $action) { if (!$action->isAvailableForNode($node)) { continue; } $addedActions = true; $html .= '<li>'; $html .= $this->getAnchorHtml('/node/' . $action->getRoute() . '/' . $node->id, $action->getLabel($this->translator), false, $action->getRoute()); $html .= '</li>'; } $html .= '<li' . ($addedActions ? ' class="separator"' : '') . '>' . $this->getAnchorHtml('/node/edit/' . $node->id, 'button.edit', true, 'edit') . '</li>'; $html .= '<li>' . $this->getAnchorHtml('/node/copy/' . $node->id, 'joppa.button.copy', true, 'copy') . '</li>'; $html .= '<li>' . $this->getAnchorHtml('/node/delete/' . $node->id, 'button.delete', true, 'delete confirm') . '</li>'; $html .= '</ul>'; $html .= '</div>'; if ($node->children) { $html .= '<ul class="children">'; foreach ($node->children as $child) { $html .= $this->getNodeHtml($child, $defaultNodeId, $addUnlocalizedClass, $selectedNode, $truncateSize - 1); } $html .= '</ul>'; } $html .= '</li>'; return $html; }
/** * Get the breadcrumbs of a node * @param joppa\model\Node $node * @param string $baseUrl base url for the node routes * @return zibo\library\html\Breadcrumbs */ public function getBreadcrumbsForNode(Node $node, $baseUrl) { $nodeTypeFacade = NodeTypeFacade::getInstance(); $urls = array($baseUrl . Request::QUERY_SEPARATOR . $node->getRoute() => $node->name); $parent = $node->getParentNode(); do { if ($nodeTypeFacade->isAvailableInFrontend($parent->type)) { $url = $baseUrl . Request::QUERY_SEPARATOR . $parent->getRoute(); $urls[$url] = $parent->name; } $parent = $parent->getParentNode(); } while ($parent); $urls = array_reverse($urls, true); $breadcrumbs = new Breadcrumbs(); foreach ($urls as $url => $name) { $breadcrumbs->addBreadcrumb($url, $name); } return $breadcrumbs; }