/** * Checks if this action is available for the node * @param \ride\library\cms\node\Node $node * @return boolean True if available */ public function isAvailableForNode(Node $node) { if (!$node->getParent()) { return true; } $nodeType = $this->cms->getNodeType($node); return $nodeType->getFrontendCallback() ? true : false; }
/** * Checks if this action is available for the node * @param \ride\library\cms\node\Node $node * @return boolean True if available */ public function isAvailableForNode(Node $node) { if (!$node->getParent()) { return !$node->isAutoPublish(); } $nodeType = $this->cms->getNodeType($node); $isAvailable = $nodeType->getFrontendCallback() ? true : false; return $isAvailable && !$node->getRootNode()->isAutoPublish(); }
/** * Action to clone a node * @param \ride\web\cms\Cms $cms * @param string $locale * @param string $site * @param string $revision * @param string $node * @return null */ public function cloneAction(Cms $cms, $locale, $site, $revision, $node) { if (!$cms->resolveNode($site, $revision, $node)) { return; } $this->setContentLocale($locale); $referer = $this->request->getQueryParameter('referer'); if ($this->request->isPost()) { $clone = $cms->cloneNode($node); $this->addSuccess('success.node.cloned', array('node' => $node->getName($locale))); $nodeType = $cms->getNodeType($clone); $url = $this->getUrl($nodeType->getRouteEdit(), array('site' => $site->getId(), 'revision' => $clone->getRevision(), 'locale' => $locale, 'node' => $clone->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } $this->setTemplateView('cms/backend/confirm.form', array('type' => 'clone', 'referer' => $referer, 'site' => $site, 'node' => $node, 'locale' => $locale, 'locales' => $cms->getLocales())); }
/** * Dispatches the frontend of a node * @return null */ public function indexAction(Cms $cms, $node, $locale = null) { $siteLocale = null; try { $site = $cms->getCurrentSite($this->request->getBaseUrl(), $siteLocale); } catch (NodeNotFoundException $exception) { // not found, try the public web controller return $this->chainWebRequest(); } $i18n = $this->getI18n(); if ($siteLocale && $locale && $siteLocale != $locale) { // locale inconsistency, not found, try the public web controller return $this->chainWebRequest(); } elseif ($siteLocale) { // set the locale of the site $i18n->setCurrentLocale($siteLocale); } elseif ($locale) { // set the requested locale $i18n->setCurrentLocale($locale); } else { // fallback locale $locale = $i18n->getLocale()->getCode(); } // resolve the node $revision = $site->getRevision(); $site = $site->getId(); if (!$cms->resolveNode($site, $revision, $node)) { return $this->chainWebRequest(); } // chain a request to the frontend callback $nodeType = $cms->getNodeType($node); $callback = $nodeType->getFrontendCallback(); $arguments = ltrim($this->request->getBasePath(true), '/'); $route = new Route('/', $callback); $route->setIsDynamic(true); $route->setArguments(explode('/', $arguments)); $route->setPredefinedArguments(array('site' => $site->getId(), 'node' => $node->getId(), 'locale' => $locale)); $this->request->setRoute($route); $this->response->setStatusCode(Response::STATUS_CODE_OK); return $this->request; }
/** * Perform the advanced node action */ public function indexAction(Cms $cms, SecurityManager $securityManager, $locale, $site, $revision, $node) { if (!$cms->resolveNode($site, $revision, $node)) { return; } $this->setContentLocale($locale); $cms->setLastAction(self::NAME); $translator = $this->getTranslator(); $referer = $this->request->getQueryParameter('referer'); $security = $node->get(Node::PROPERTY_SECURITY, 'inherit', false); switch ($security) { case 'inherit': case Node::AUTHENTICATION_STATUS_EVERYBODY: case Node::AUTHENTICATION_STATUS_ANONYMOUS: $permissions = null; break; case Node::AUTHENTICATION_STATUS_AUTHENTICATED: default: $permissions = array_flip(explode(',', $security)); $security = Node::AUTHENTICATION_STATUS_AUTHENTICATED; break; } $data = array('published' => $node->get(Node::PROPERTY_PUBLISH, 'inherit', false), 'publishStart' => $node->get(Node::PROPERTY_PUBLISH_START, null, false), 'publishStop' => $node->get(Node::PROPERTY_PUBLISH_STOP, null, false), 'security' => $security, 'permissions' => $permissions); $permissions = $securityManager->getSecurityModel()->getPermissions(); $nodeType = $cms->getNodeType($node); $isFrontendNode = $nodeType->getFrontendCallback() || $node->getLevel() === 0 ? true : false; if ($isFrontendNode) { $data['hide'] = array(); if ($node->hideInMenu()) { $data['hide']['menu'] = 'menu'; } if ($node->hideInBreadcrumbs()) { $data['hide']['breadcrumbs'] = 'breadcrumbs'; } if ($node->hideForAnonymousUsers()) { $data['hide']['anonymous'] = 'anonymous'; } if ($node->hideForAuthenticatedUsers()) { $data['hide']['authenticated'] = 'authenticated'; } } $form = $this->createFormBuilder($data); $form->addRow('published', 'option', array('label' => $translator->translate('label.publish'), 'options' => $this->getPublishedOptions($node, $translator))); $form->addRow('publishStart', 'string', array('label' => $translator->translate('label.publish.start'), 'description' => $translator->translate('label.publish.start.description'), 'filters' => array('trim' => array()), 'validators' => array('regex' => array('required' => false, 'regex' => '/2([0-9]){3}-([0-9]){2}-([0-9]){2} ([0-9]){2}:([0-9]){2}:([0-9]){2}/', 'error.regex' => 'error.validation.date.cms')))); $form->addRow('publishStop', 'string', array('label' => $translator->translate('label.publish.stop'), 'filters' => array('trim' => array()), 'validators' => array('regex' => array('required' => false, 'regex' => '/2([0-9]){3}-([0-9]){2}-([0-9]){2} ([0-9]){2}:([0-9]){2}:([0-9]){2}/', 'error.regex' => 'error.validation.date.cms')))); $form->addRow('security', 'option', array('label' => $translator->translate('label.allow'), 'attributes' => array('data-toggle-dependant' => 'option-security'), 'options' => $this->getSecurityOptions($node, $translator), 'validators' => array('required' => array()))); if ($permissions) { $form->addRow('permissions', 'option', array('label' => $translator->translate('label.permissions.required'), 'attributes' => array('class' => 'option-security option-security-authenticated'), 'multiple' => true, 'options' => $permissions)); } if ($isFrontendNode) { $form->addRow('hide', 'option', array('label' => $translator->translate('label.hide'), 'options' => array('menu' => $translator->translate('label.hide.menu'), 'breadcrumbs' => $translator->translate('label.hide.breadcrumbs'), 'anonymous' => $translator->translate('label.hide.anonymous'), 'authenticated' => $translator->translate('label.hide.authenticated')), 'multiple' => true)); } $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); $security = $this->getSecurityValue($data['security']); if ($security == Node::AUTHENTICATION_STATUS_AUTHENTICATED && $permissions && $data['permissions']) { $security = implode(',', $data['permissions']); } $node->set(Node::PROPERTY_PUBLISH, $this->getPublishedValue($data['published'])); $node->set(Node::PROPERTY_PUBLISH_START, $data['publishStart']); $node->set(Node::PROPERTY_PUBLISH_STOP, $data['publishStop']); $node->set(Node::PROPERTY_SECURITY, $security); if ($isFrontendNode) { if ($node->getLevel() === 0) { $inherit = false; } else { $inherit = null; } $node->setHideInMenu(isset($data['hide']['menu']), $inherit); $node->setHideInBreadcrumbs(isset($data['hide']['breadcrumbs']), $inherit); $node->setHideForAnonymousUsers(isset($data['hide']['anonymous']), $inherit); $node->setHideForAuthenticatedUsers(isset($data['hide']['authenticated']), $inherit); } $cms->saveNode($node, 'Set visibility of ' . $node->getName()); $this->addSuccess('success.node.saved', array('node' => $node->getName($locale))); $url = $this->getUrl(self::ROUTE, array('site' => $site->getId(), 'revision' => $node->getRevision(), 'locale' => $locale, 'node' => $node->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } catch (ValidationException $exception) { $validationException = new ValidationException(); $errors = $exception->getAllErrors(); foreach ($errors as $field => $fieldErrors) { if ($field == Node::PROPERTY_PUBLISH) { $validationException->addErrors('published', $fieldErrors); } elseif ($field == Node::PROPERTY_PUBLISH_START) { $validationException->addErrors('publishStart', $fieldErrors); } elseif ($field == Node::PROPERTY_PUBLISH_STOP) { $validationException->addErrors('publishStop', $fieldErrors); } else { $validationException->addErrors($field, $fieldErrors); } } $this->setValidationException($validationException, $form); } } $view = $this->setTemplateView('cms/backend/node.visibility', array('site' => $site, 'node' => $node, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales())); $form->processView($view); }