/**
  * Perform the analytics node action
  */
 public function indexAction(Cms $cms, $locale, $site, $node, $revision)
 {
     $node = $site;
     if (!$cms->resolveNode($site, $revision, $node)) {
         return;
     }
     $this->setContentLocale($locale);
     $translator = $this->getTranslator();
     $referer = $this->request->getQueryParameter('referer');
     $data = array('gtm_id' => $site->get('analytics.gtm_id'), 'ga_id' => $site->get('analytics.ga_id'));
     $form = $this->createFormBuilder($data);
     $form->addRow('gtm_id', 'string', array('label' => $translator->translate('label.analytics.gtm_id'), 'filters' => array('trim' => array()), 'validators' => array('regex' => array('regex' => '/^((GTM-[A-Z0-9]{6}))$/', 'error.regex' => 'label.analytics.gtm_id.error', 'required' => false))));
     $form->addRow('ga_id', 'string', array('label' => $translator->translate('label.analytics.ga_id'), 'filters' => array('trim' => array()), 'validators' => array('regex' => array('regex' => '/^(UA-[0-9]+-[0-9][0-9]??)$/', 'error.regex' => 'label.analytics.ga_id.error', 'required' => false))));
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             foreach ($data as $tag => $id) {
                 $site->set('analytics.' . $tag, $id);
             }
             $cms->saveNode($site, "Set analytics for " . $site->getName());
             $this->addSuccess('success.node.saved', array('node' => $site->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 $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $this->setTemplateView('cms/backend/site.analytics', array('site' => $site, 'node' => $node, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales()));
 }
 /**
  * Perform the advanced node action
  */
 public function indexAction(Cms $cms, $locale, $site, $revision, $node)
 {
     if (!$cms->resolveNode($site, $revision, $node)) {
         return;
     }
     $this->setContentLocale($locale);
     $cms->setLastAction(self::NAME);
     $referer = $this->request->getQueryParameter('referer');
     $ini = $this->getIniFromNodeProperties($node->getProperties());
     $translator = $this->getTranslator();
     $form = $this->createFormBuilder(array('properties' => $ini));
     $form->addRow('properties', 'text', array('label' => $translator->translate('label.node.properties'), 'description' => $translator->translate('label.node.properties.description'), 'attributes' => array('rows' => 10), 'filters' => array('trim' => array())));
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $nodeProperties = $this->getNodePropertiesFromIni($data['properties']);
             $node->setProperties($nodeProperties);
             $cms->saveNode($node, 'Edited advanced properties of node ' . $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 $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $this->setTemplateView('cms/backend/node.advanced', array('site' => $site, 'node' => $node, 'nodeProperties' => $this->getHtmlFromNode($node), 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales()));
 }
 /**
  * Dynamic action to preview a node
  * @param \ride\web\cms\node\dispatcher\NodeDispatcherFactory $nodeDispatcherFactory
  * @param \ride\library\template\TemplateFacade $templateFacade
  * @param string $site Id of the site
  * @param string $revision Name of the revision
  * @param string $locale Code of the locale
  * @return null
  */
 public function previewAction(NodeDispatcherFactory $nodeDispatcherFactory, TemplateFacade $templateFacade, $site, $revision, $locale)
 {
     $node = $site;
     if (!$this->cms->resolveNode($site, $revision, $node, null, true)) {
         return;
     }
     $cache = null;
     $i18n = $this->getI18n();
     $i18n->setCurrentLocale($locale);
     $requestUrl = $this->request->getUrl();
     $routeUrl = $this->request->getRoute()->getUrl($this->request->getBaseScript(), array('locale' => $locale, 'site' => $site->getId(), 'revision' => $revision));
     $path = str_replace($routeUrl, '', $requestUrl);
     $node = $site->getChildByRoute($path, $locale, $this->cms->getLocales());
     if (!$node) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         return;
     }
     $nodeDispatcher = $nodeDispatcherFactory->createNodeDispatcher($site, $node->getId(), $routeUrl, $locale);
     if (!$nodeDispatcher) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         return;
     }
     $node = $nodeDispatcher->getNode();
     if (!$node->isAvailableInLocale($locale)) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         return;
     }
     if (!$node->isAllowed($this->getSecurityManager())) {
         throw new UnauthorizedException();
     }
     $this->request->setBaseScript($routeUrl);
     if ($node->getType() == RedirectNodeType::NAME) {
         $url = $node->getRedirectUrl($locale);
         if ($url) {
             $this->response->setRedirect($url);
             return;
         }
         $node = $node->getRedirectNode($locale);
         if (!$node) {
             throw new CmsException('No redirect properties set to this node for locale "' . $locale . '".');
         }
         $revision = $site->getRevision();
         $site = $site->getId();
         if (!$this->cms->resolveNode($site, $revision, $node)) {
             return;
         }
         $redirectUrl = $this->request->getBaseScript() . $node->getRoute($locale);
         $this->response->setRedirect($redirectUrl);
         return;
     }
     $nodeView = $nodeDispatcher->getView();
     $nodeView->setLayouts($this->cms->getLayouts());
     $nodeView->setTemplateFacade($templateFacade);
     $templateFacade->setThemeModel($this->cms->getThemeModel());
     $templateFacade->setDefaultTheme($nodeView->getTemplate()->getTheme());
     $textParser = $this->dependencyInjector->get('ride\\library\\cms\\content\\text\\TextParser', 'chain');
     $textParser->setBaseUrl($this->request->getBaseUrl());
     $textParser->setSiteUrl($routeUrl);
     $nodeDispatcher->dispatch($this->request, $this->response, $this->getUser(), $cache);
 }
 /**
  * Action to dispatch to the properties of a widget
  * @param \ride\web\cms\Cms $cms
  * @param string $locale
  * @param string $site
  * @param string $revision
  * @param string $node
  * @param string $region
  * @param string $widget
  * @return null
  */
 public function indexAction(Cms $cms, $locale, $site, $revision, $node, $region, $widget)
 {
     if (!$cms->resolveNode($site, $revision, $node) || !$cms->resolveRegion($node, $locale, $region)) {
         return;
     }
     $widgetId = $widget;
     $widgetProperties = $node->getWidgetProperties($widgetId);
     $widget = $site->getWidget($widgetId);
     $widget = clone $cms->getWidget($widget);
     $translator = $this->getTranslator();
     $data = array('cache' => $widgetProperties->getCache(), 'cache-ttl' => $widgetProperties->getCacheTtl());
     $form = $this->createFormBuilder($data);
     $form->addRow('cache', 'option', array('label' => $translator->translate('label.cache'), 'options' => array(NodeWidgetProperties::CACHE_AUTO => $translator->translate('label.automatic') . ' (' . strtolower($translator->translate('label.' . ($widget->isAutoCache() ? 'enabled' : 'disabled'))) . ')', NodeWidgetProperties::CACHE_ENABLED => $translator->translate('label.enabled'), NodeWidgetProperties::CACHE_DISABLED => $translator->translate('label.disabled')), 'validators' => array('required' => array())));
     $form->addRow('cache-ttl', 'number', array('label' => $translator->translate('label.cache.ttl'), 'description' => $translator->translate('label.cache.ttl.description'), 'validators' => array('minmax' => array('minimum' => 0, 'required' => true))));
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $widgetProperties->setCache($data['cache']);
             $widgetProperties->setCacheTtl($data['cache-ttl']);
             $cms->saveNode($node, 'Updated cache for widget ' . $widgetId . ' in ' . $node->getName());
             $this->addSuccess('success.widget.saved', array('widget' => $this->getTranslator()->translate('widget.' . $widget->getName())));
             $this->response->setRedirect($this->getUrl('cms.node.content.region', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId(), 'region' => $region)));
             return;
         } catch (ValidationException $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $referer = $this->request->getQueryParameter('referer');
     $this->setTemplateView('cms/backend/widget.cache', array('site' => $site, 'node' => $node, 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales(), 'region' => $region, 'widget' => $widget, 'widgetId' => $widgetId, 'widgetName' => $this->getTranslator()->translate('widget.' . $widget->getName()), 'form' => $form->getView()));
 }
 /**
  * Perform the structure node action
  */
 public function indexAction(Cms $cms, NodeStructureParser $parser, $locale, $site, $revision)
 {
     $node = $site;
     if (!$cms->resolveNode($site, $revision, $node, null, true)) {
         return;
     }
     $this->setContentLocale($locale);
     $cms->setLastAction(self::NAME);
     $translator = $this->getTranslator();
     $referer = $this->request->getQueryParameter('referer');
     $structure = $parser->getStructure($locale, $node);
     $form = $this->createFormBuilder(array('structure' => $structure));
     $form->addRow('structure', 'text', array('label' => $translator->translate('label.node.structure'), 'description' => $translator->translate('label.node.structure.description'), 'attributes' => array('rows' => 10), 'filters' => array('trim' => array()), 'validators' => array('required' => array())));
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $parser->setStructure($locale, $node, $cms->getNodeModel(), $data['structure']);
             $this->addSuccess('success.node.saved', array('node' => $site->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 $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $this->setTemplateView('cms/backend/site.structure', array('site' => $site, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales()));
 }
 /**
  * Action to dispatch to the properties of a widget
  */
 public function indexAction(Cms $cms, $locale, $site, $revision, $node, $region, $section, $block, $widget, Invoker $invoker)
 {
     if (!$cms->resolveNode($site, $revision, $node) || !$cms->resolveRegion($node, $locale, $region)) {
         return;
     }
     $widgetId = $widget;
     $widget = $site->getWidget($widgetId);
     $widget = clone $cms->getWidget($widget);
     $widget->setRequest($this->request);
     $widget->setResponse($this->response);
     $widget->setProperties($node->getWidgetProperties($widgetId));
     $widget->setLocale($locale);
     $widget->setRegion($region);
     $widget->setSection($section);
     $widget->setBlock($block);
     $widget->setIdentifier($widgetId);
     if ($widget instanceof AbstractController) {
         $widget->setConfig($this->config);
         $widget->setDependencyInjector($this->dependencyInjector);
     }
     $propertiesCallback = $widget->getPropertiesCallback();
     if (!$propertiesCallback) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         return;
     }
     if ($invoker->invoke($propertiesCallback)) {
         $cms->saveNode($node, 'Updated properties for widget ' . $widgetId . ' in ' . $node->getName());
         $this->addSuccess('success.widget.saved', array('widget' => $this->getTranslator()->translate('widget.' . $widget->getName())));
     }
     $widgetView = $this->response->getView();
     if (!$widgetView && !$this->response->getBody() && $this->response->getStatusCode() == Response::STATUS_CODE_OK) {
         $this->response->setRedirect($this->getUrl('cms.node.content.region', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId(), 'region' => $region)));
         return;
     }
     if (!$widgetView instanceof TemplateView) {
         return;
     }
     $inheritedWidgets = $node->getInheritedWidgets($region, $section);
     if (isset($inheritedWidgets[$block][$widgetId])) {
         $this->addWarning('warning.widget.properties.inherited');
     }
     $referer = $this->request->getQueryParameter('referer');
     $template = $widgetView->getTemplate();
     $variables = array('site' => $site, 'node' => $node, 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales(), 'region' => $region, 'section' => $section, 'block' => $block, 'widget' => $widget, 'widgetId' => $widgetId, 'widgetName' => $this->getTranslator()->translate('widget.' . $widget->getName()), 'propertiesTemplate' => $template->getResource()) + $template->getVariables();
     $view = $this->setTemplateView('cms/backend/widget.properties', $variables);
     $view->getTemplate()->setResourceId(substr(md5($template->getResource()), 0, 7));
     $view->addJavascript('js/form.js');
     $view->mergeResources($widgetView);
 }
Пример #7
0
 public function formAction(Cms $cms, $locale, $site, $revision = null, $node = null)
 {
     if ($node) {
         if (!$cms->resolveNode($site, $revision, $node, 'folder')) {
             return;
         }
         $cms->setLastAction('edit');
     } else {
         if (!$cms->resolveNode($site, $revision)) {
             return;
         }
         $node = $cms->createNode('folder', $site);
     }
     $this->setContentLocale($locale);
     $translator = $this->getTranslator();
     $locales = $cms->getLocales();
     $themes = $cms->getThemes();
     $data = array('name' => $node->getName($locale), 'theme' => $this->getThemeValueFromNode($node), 'availableLocales' => $this->getLocalesValueFromNode($node));
     $form = $this->createFormBuilder($data);
     $form->addRow('name', 'string', array('label' => $translator->translate('label.folder'), 'description' => $translator->translate('label.folder.description'), 'filters' => array('trim' => array()), 'validators' => array('required' => array())));
     $form->addRow('theme', 'select', array('label' => $translator->translate('label.theme'), 'description' => $translator->translate('label.theme.description'), 'options' => $this->getThemeOptions($node, $translator, $themes)));
     if ($site->isLocalizationMethodCopy()) {
         $form->addRow('availableLocales', 'select', array('label' => $translator->translate('label.locales'), 'description' => $translator->translate('label.locales.available.description'), 'options' => $this->getLocalesOptions($node, $translator, $locales), 'multiple' => true, 'validators' => array('required' => array())));
     }
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $node->setName($locale, $data['name']);
             $node->setTheme($this->getOptionValueFromForm($data['theme']));
             if ($site->isLocalizationMethodCopy()) {
                 $node->setAvailableLocales($this->getOptionValueFromForm($data['availableLocales']));
             } else {
                 $node->setAvailableLocales($locale);
             }
             $cms->saveNode($node, (!$node->getId() ? 'Created new folder ' : 'Updated folder ') . $node->getName());
             $this->addSuccess('success.node.saved', array('node' => $node->getName($locale)));
             $this->response->setRedirect($this->getUrl('cms.folder.edit', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId())));
             return;
         } catch (ValidationException $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $referer = $this->request->getQueryParameter('referer');
     $this->setTemplateView('cms/backend/folder.form', array('site' => $site, 'node' => $node, 'referer' => $referer, 'form' => $form->getView(), 'locale' => $locale, 'locales' => $locales));
 }
 /**
  * Perform the template node action
  */
 public function indexAction(TemplateFacade $templateFacade, FileBrowser $fileBrowser, $locale, $site, $revision, $node)
 {
     if (!$this->cms->resolveNode($site, $revision, $node)) {
         return;
     }
     $this->setContentLocale($locale);
     $this->cms->setLastAction(self::NAME);
     $referer = $this->request->getQueryParameter('referer');
     $templateFacade->setThemeModel($this->cms->getThemeModel());
     $templates = array('index' => 'cms/frontend/index');
     if ($node->getId() == $site->getId()) {
         $id = null;
     } else {
         $id = $node->getId();
     }
     $component = new TemplatesComponent();
     $data = $component->createData($templateFacade, $templates, $node->getTheme(), $id);
     $form = $this->buildForm($component, $data);
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $applicationDirectory = $fileBrowser->getApplicationDirectory();
             foreach ($templates as $name => $template) {
                 $file = $applicationDirectory->getChild($data['path'][$name]);
                 $file->getParent()->create();
                 $file->write($data['content'][$name]);
             }
             $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 $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $this->setTemplateView('cms/backend/node.templates', array('site' => $site, 'node' => $node, 'templates' => $templates, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $this->cms->getLocales()));
 }
Пример #9
0
 /**
  * Perform the error node action
  */
 public function indexAction(Cms $cms, $locale, $site, $revision)
 {
     $node = $site;
     if (!$cms->resolveNode($site, $revision, $node, null, true)) {
         return;
     }
     $cms->setLastAction(self::NAME);
     $this->setContentLocale($locale);
     $translator = $this->getTranslator();
     $referer = $this->request->getQueryParameter('referer');
     $nodeList = $cms->getNodeList($node, $locale);
     $data = array('node404' => $site->get('error.404'), 'node403' => $site->get('error.403'));
     $form = $this->createFormBuilder($data);
     $form->addRow('node404', 'select', array('label' => $translator->translate('label.node.404'), 'options' => $nodeList));
     $form->addRow('node403', 'select', array('label' => $translator->translate('label.node.403'), 'options' => $nodeList));
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             foreach ($data as $statusCode => $errorNode) {
                 $statusCode = str_replace('node', '', $statusCode);
                 $site->set('error.' . $statusCode, $errorNode);
             }
             $cms->saveNode($site, "Set error pages for " . $site->getName());
             $this->addSuccess('success.node.saved', array('node' => $site->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 $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $this->setTemplateView('cms/backend/site.error', array('site' => $site, 'node' => $node, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales()));
 }
Пример #10
0
 /**
  * Perform the publish node action
  */
 public function indexAction(Cms $cms, $locale, $site, $revision, $node)
 {
     if (!$cms->resolveNode($site, $revision, $node)) {
         return;
     }
     $this->setContentLocale($locale);
     $cms->setLastAction(self::NAME);
     $translator = $this->getTranslator();
     $defaultRevision = $cms->getDefaultRevision();
     $data = array('revision' => $defaultRevision, 'recursive' => true);
     $revisions = $site->getRevisions();
     if (!isset($revisions[$defaultRevision])) {
         $revisions[$defaultRevision] = $defaultRevision;
     }
     unset($revisions[$node->getRevision()]);
     $form = $this->createFormBuilder($data);
     $form->addRow('revision', 'select', array('label' => $translator->translate('label.revision'), 'description' => $translator->translate('label.revision.publish.description'), 'options' => $revisions, 'validators' => array('required' => array())));
     $form->addRow('recursive', 'option', array('label' => $translator->translate('label.recursive'), 'description' => $translator->translate('label.recursive.publish.description')));
     $referer = $this->request->getQueryParameter('referer');
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $cms->publishNode($node, $data['revision'], $data['recursive']);
             $this->addSuccess('success.node.published', array('node' => $node->getName($locale), 'revision' => $data['revision']));
             $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 $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $this->setTemplateView('cms/backend/node.publish', array('site' => $site, 'node' => $node, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales()));
 }
Пример #11
0
 public function formAction(Cms $cms, $locale, ImageUrlGenerator $imageUrlGenerator, $site, $revision, $node = null)
 {
     if ($node) {
         if (!$cms->resolveNode($site, $revision, $node, 'page')) {
             return;
         }
         $cms->setLastAction('edit');
     } else {
         if (!$cms->resolveNode($site, $revision)) {
             return;
         }
         $node = $cms->createNode('page', $site);
     }
     $this->setContentLocale($locale);
     $translator = $this->getTranslator();
     $locales = $cms->getLocales();
     $themes = $cms->getThemes();
     $referer = $this->request->getQueryParameter('referer');
     // gather data
     $data = array('name' => $node->getName($locale), 'name-title' => $node->get('name.' . $locale . '.title', null, false), 'name-menu' => $node->get('name.' . $locale . '.menu', null, false), 'name-breadcrumb' => $node->get('name.' . $locale . '.breadcrumb', null, false), 'description' => $node->getDescription($locale), 'image' => $node->getImage($locale), 'route' => $node->getRoute($locale, false), 'theme' => $this->getThemeValueFromNode($node), 'availableLocales' => $this->getLocalesValueFromNode($node));
     // build form
     $form = $this->createFormBuilder($data);
     $form->addRow('name', 'string', array('label' => $translator->translate('label.page'), 'description' => $translator->translate('label.page.description'), 'filters' => array('trim' => array()), 'validators' => array('required' => array())));
     $form->addRow('name-title', 'string', array('label' => $translator->translate('label.name.title'), 'description' => $translator->translate('label.name.title.description'), 'filters' => array('trim' => array())));
     $form->addRow('name-menu', 'string', array('label' => $translator->translate('label.name.menu'), 'description' => $translator->translate('label.name.menu.description'), 'filters' => array('trim' => array())));
     $form->addRow('name-breadcrumb', 'string', array('label' => $translator->translate('label.name.breadcrumb'), 'description' => $translator->translate('label.name.breadcrumb.description'), 'filters' => array('trim' => array())));
     $form->addRow('route', 'string', array('label' => $translator->translate('label.route'), 'description' => $translator->translate('label.route.description'), 'filters' => array('trim' => array())));
     $form->addRow('description', 'text', array('label' => $translator->translate('label.description'), 'description' => $translator->translate('label.description.node.description'), 'filters' => array('trim' => array())));
     $form->addRow('image', 'image', array('label' => $translator->translate('label.image'), 'description' => $translator->translate('label.image.node.description')));
     $form->addRow('theme', 'select', array('label' => $translator->translate('label.theme'), 'description' => $translator->translate('label.theme.description'), 'options' => $this->getThemeOptions($node, $translator, $themes)));
     if ($site->isLocalizationMethodCopy()) {
         $form->addRow('availableLocales', 'select', array('label' => $translator->translate('label.locales'), 'description' => $translator->translate('label.locales.available.description'), 'options' => $this->getLocalesOptions($node, $translator, $locales), 'multiple' => true, 'validators' => array('required' => array())));
     }
     // process form
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $node->setName($locale, $data['name']);
             $node->setName($locale, $data['name-title'], 'title');
             $node->setName($locale, $data['name-menu'], 'menu');
             $node->setName($locale, $data['name-breadcrumb'], 'breadcrumb');
             $node->setDescription($locale, $data['description']);
             $node->setImage($locale, $data['image']);
             $node->setRoute($locale, $data['route']);
             $node->setTheme($this->getOptionValueFromForm($data['theme']));
             if ($site->isLocalizationMethodCopy()) {
                 $node->setAvailableLocales($this->getOptionValueFromForm($data['availableLocales']));
             } else {
                 $node->setAvailableLocales($locale);
             }
             $cms->saveNode($node, (!$node->getId() ? 'Created new page ' : 'Updated page ') . $node->getName());
             $this->addSuccess('success.node.saved', array('node' => $node->getName($locale)));
             $url = $this->getUrl('cms.page.edit', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId()));
             if ($referer) {
                 $url .= '?referer=' . urlencode($referer);
             }
             $this->response->setRedirect($url);
             return;
         } catch (ValidationException $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     // show view
     $this->setTemplateView('cms/backend/page.form', array('site' => $site, 'node' => $node, 'referer' => $referer, 'form' => $form->getView(), 'locale' => $locale, 'locales' => $locales));
 }
Пример #12
0
 /**
  * Action to manage the trash of a site
  * @param \ride\web\cms\Cms $cms Facade to the CMS
  * @param string $site Id of the site
  * @param string $revision Name of the revision to work with
  * @param string $locale Code of the locale
  * @return null
  */
 public function trashAction(Cms $cms, $site, $revision, $locale)
 {
     if (!$cms->resolveNode($site, $revision)) {
         return;
     }
     $this->setContentLocale($locale);
     $translator = $this->getTranslator();
     $referer = $this->request->getQueryParameter('referer');
     $trashNodeOptions = array();
     $trashNodes = $cms->getTrashNodes($site->getId());
     foreach ($trashNodes as $trashNodeId => $trashNode) {
         $trashNodeOptions[$trashNodeId] = $trashNode->getNode()->getName($locale) . ' (' . date('Y-m-d H:i:s', $trashNode->getDate()) . ')';
     }
     $form = $this->createFormBuilder();
     $form->addRow('nodes', 'option', array('label' => $translator->translate('label.nodes.trash'), 'description' => $translator->translate('label.nodes.trash.description'), 'options' => $trashNodeOptions, 'multiple' => true, 'validators' => array('required' => array())));
     $form->addRow('destination', 'select', array('label' => $translator->translate('label.destination'), 'description' => $translator->translate('label.destination.restore.description'), 'options' => $cms->getNodeList($site, $locale, true)));
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $restoreNodes = array();
             foreach ($data['nodes'] as $trashNodeId => $trashNodeName) {
                 $restoreNodes[] = $trashNodes[$trashNodeId];
             }
             $cms->restoreTrashNodes($site, $restoreNodes, $data['destination']);
             $this->response->setRedirect($referer);
             return;
         } catch (ValidationException $exception) {
             $this->setValidationException($exception, $form);
         }
     }
     $this->setTemplateView('cms/backend/site.trash', array('referer' => $referer, 'site' => $site, 'node' => $site, 'form' => $form->getView(), 'trashNodes' => $trashNodes, 'locale' => $locale, 'locales' => $cms->getLocales()));
 }
Пример #13
0
 /**
  * Action to dispatch to the properties of a widget
  * @param \ride\web\cms\Cms $cms
  * @param string $locale
  * @param string $site
  * @param string $revision
  * @param string $node
  * @param string $region
  * @param string $widget
  * @return null
  */
 public function indexAction(Cms $cms, $locale, $site, $revision, $node, $region, $widget)
 {
     if (!$cms->resolveNode($site, $revision, $node) || !$cms->resolveRegion($node, $locale, $region)) {
         return;
     }
     $widgetId = $widget;
     $widgetProperties = $node->getWidgetProperties($widgetId);
     $widget = $site->getWidget($widgetId);
     $widget = clone $cms->getWidget($widget);
     $widget->setRequest($this->request);
     $widget->setResponse($this->response);
     $widget->setProperties($widgetProperties);
     $widget->setLocale($locale);
     $widget->setRegion($region);
     if ($widget instanceof AbstractController) {
         $widget->setConfig($this->config);
         $widget->setDependencyInjector($this->dependencyInjector);
     }
     $styleOptions = $widget->getWidgetStyleOptions();
     $data = array();
     foreach ($styleOptions as $styleOption => $styleTranslationKey) {
         $data[$styleOption] = $widgetProperties->getWidgetProperty('style.' . $styleOption);
     }
     $translator = $this->getTranslator();
     $form = $this->createFormBuilder($data);
     foreach ($styleOptions as $styleOption => $styleTranslationKey) {
         $form->addRow($styleOption, 'string', array('label' => $translator->translate($styleTranslationKey)));
     }
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             foreach ($styleOptions as $styleOption => $styleTranslationKey) {
                 $widgetProperties->setWidgetProperty('style.' . $styleOption, $data[$styleOption]);
             }
             $cms->saveNode($node, 'Updated style for widget ' . $widgetId . ' in ' . $node->getName());
             $this->addSuccess('success.widget.saved', array('widget' => $this->getTranslator()->translate('widget.' . $widget->getName())));
             $this->response->setRedirect($this->getUrl('cms.node.content.region', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId(), 'region' => $region)));
             return;
         } catch (ValidationException $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $referer = $this->request->getQueryParameter('referer');
     $this->setTemplateView('cms/backend/widget.style', array('site' => $site, 'node' => $node, 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales(), 'region' => $region, 'widget' => $widget, 'widgetId' => $widgetId, 'widgetName' => $this->getTranslator()->translate('widget.' . $widget->getName()), 'form' => $form->getView()));
 }
 public function formAction(Cms $cms, ImageUrlGenerator $imageUrlGenerator, $locale, OrmManager $orm, $site, $revision = null, $node = null)
 {
     if ($node) {
         if (!$cms->resolveNode($site, $revision, $node, 'entry')) {
             return;
         }
         $cms->setLastAction('edit');
     } else {
         if (!$cms->resolveNode($site, $revision)) {
             return;
         }
         $node = $cms->createNode('entry', $site);
     }
     $translator = $this->getTranslator();
     $locales = $cms->getLocales();
     $themes = $cms->getThemes();
     // gather data
     $data = array('name' => $node->getName($locale), 'model' => $node->getEntryModel(), 'entry' => $node->getEntryId(), 'route' => $node->getRoute($locale, false), 'theme' => $this->getThemeValueFromNode($node), 'availableLocales' => $this->getLocalesValueFromNode($node));
     $entryOptions = array('' => '---');
     if ($data['model']) {
         $model = $orm->getModel($data['model']);
         $entries = $model->find(null, $locale);
         $entryOptions += $model->getOptionsFromEntries($entries);
     }
     // build form
     $form = $this->createFormBuilder($data);
     $form->addRow('model', 'select', array('label' => $translator->translate('label.model'), 'description' => $translator->translate('label.model.description'), 'options' => $this->getModelOptions($orm), 'validators' => array('required' => array())));
     $form->addRow('entry', 'select', array('label' => $translator->translate('label.entry'), 'description' => $translator->translate('label.entry.description'), 'options' => $entryOptions, 'validators' => array('required' => array())));
     $form->addRow('name', 'string', array('label' => $translator->translate('label.name'), 'description' => $translator->translate('label.entry.name.description'), 'filters' => array('trim' => array())));
     $form->addRow('route', 'string', array('label' => $translator->translate('label.route'), 'description' => $translator->translate('label.route.description'), 'filters' => array('trim' => array())));
     $form->addRow('theme', 'select', array('label' => $translator->translate('label.theme'), 'description' => $translator->translate('label.theme.description'), 'options' => $this->getThemeOptions($node, $translator, $themes)));
     if ($site->isLocalizationMethodCopy()) {
         $form->addRow('availableLocales', 'select', array('label' => $translator->translate('label.locales'), 'description' => $translator->translate('label.locales.available.description'), 'options' => $this->getLocalesOptions($node, $translator, $locales), 'multiple' => true, 'validators' => array('required' => array())));
     }
     // process form
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             if (!$data['name']) {
                 $data['name'] = $entryOptions[$data['entry']];
             }
             $node->setName($locale, $data['name']);
             $node->setRoute($locale, $data['route']);
             $node->setTheme($this->getOptionValueFromForm($data['theme']));
             if ($site->isLocalizationMethodCopy()) {
                 $node->setAvailableLocales($this->getOptionValueFromForm($data['availableLocales']));
             } else {
                 $node->setAvailableLocales($locale);
             }
             $node->setEntry($data['model'], $data['entry']);
             $cms->saveNode($node, (!$node->getId() ? 'Created new entry ' : 'Updated entry ') . $node->getName());
             $this->addSuccess('success.node.saved', array('node' => $node->getName($locale)));
             $this->response->setRedirect($this->getUrl('cms.entry.edit', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId())));
             return;
         } catch (ValidationException $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $referer = $this->request->getQueryParameter('referer');
     if (!$referer) {
         $referer = $this->getUrl('cms.site.detail.locale', array('site' => $site->getId(), 'revision' => $site->getRevision(), 'locale' => $locale));
     }
     // show view
     $view = $this->setTemplateView('cms/backend/entry.form', array('site' => $site, 'node' => $node, 'referer' => $referer, 'form' => $form->getView(), 'locale' => $locale, 'locales' => $locales));
     $view->addJavascript('js/cms/orm.js');
     $view->addInlineJavascript('initializeNodeEntryForm("' . $this->getUrl('api.orm.list', array('model' => '%model%')) . '");');
 }
Пример #15
0
 /**
  * Perform the meta node action
  */
 public function indexAction(Cms $cms, MetaComponent $metaComponent, $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');
     $data = array('meta' => array());
     if ($site->getId() != $node->getId()) {
         $parentMeta = $node->getParentNode()->getMeta($locale);
     } else {
         $parentMeta = array();
     }
     $meta = $node->getMeta($locale, null, false);
     foreach ($meta as $property => $content) {
         switch ($property) {
             case 'title':
                 $data['title'] = $content;
                 break;
             case 'description':
                 $data['description'] = $content;
                 break;
             case 'keywords':
                 $data['keywords'] = $content;
                 break;
             case 'og:title':
                 $data['og-title'] = $content;
                 break;
             case 'og:description':
                 $data['og-description'] = $content;
                 break;
             case 'og:image':
                 $data['og-image'] = $content;
                 break;
             default:
                 $data['meta'][] = $property . '=' . $content;
                 break;
         }
     }
     $form = $this->createFormBuilder($data);
     $form->addRow('title', 'string', array('label' => $translator->translate('label.title'), 'filters' => array('trim' => array())));
     $form->addRow('description', 'text', array('label' => $translator->translate('label.description'), 'filters' => array('trim' => array())));
     $form->addRow('keywords', 'string', array('label' => $translator->translate('label.keywords'), 'filters' => array('trim' => array())));
     $form->addRow('og-title', 'string', array('label' => $translator->translate('label.title'), 'filters' => array('trim' => array())));
     $form->addRow('og-description', 'text', array('label' => $translator->translate('label.description'), 'filters' => array('trim' => array())));
     $form->addRow('og-image', 'image', array('label' => $translator->translate('label.image')));
     $form->addRow('meta', 'collection', array('label' => $translator->translate('label.meta'), 'type' => 'component', 'options' => array('component' => $metaComponent)));
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $meta = array();
             if ($data['title']) {
                 $meta['title'] = $data['title'];
             }
             if ($data['description']) {
                 $meta['description'] = $data['description'];
             }
             if ($data['keywords']) {
                 $meta['keywords'] = $data['keywords'];
             }
             if ($data['og-title']) {
                 $meta['og:title'] = $data['og-title'];
             }
             if ($data['og-description']) {
                 $meta['og:description'] = $data['og-description'];
             }
             if ($data['og-image']) {
                 $meta['og:image'] = $data['og-image'];
             }
             foreach ($data['meta'] as $property) {
                 list($property, $content) = explode('=', $property, 2);
                 $meta[$property] = $content;
             }
             $node->setMeta($locale, $meta);
             $cms->saveNode($node, 'Set meta tags to ' . $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 $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $this->setTemplateView('cms/backend/node.meta', array('site' => $site, 'node' => $node, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales(), 'parentMeta' => $parentMeta));
 }
 /**
  * Action to dispatch to the properties of a widget
  * @param \ride\web\cms\Cms $cms
  * @param \ride\library\security\SecurityManager $securityManager
  * @param string $locale
  * @param string $site
  * @param string $revision
  * @param string $node
  * @param string $region
  * @param string $widget
  * @return null
  */
 public function indexAction(Cms $cms, SecurityManager $securityManager, $locale, $site, $revision, $node, $region, $widget)
 {
     if (!$cms->resolveNode($site, $revision, $node) || !$cms->resolveRegion($node, $locale, $region)) {
         return;
     }
     $widgetId = $widget;
     $widgetProperties = $node->getWidgetProperties($widgetId);
     $widget = $site->getWidget($widgetId);
     $widget = clone $cms->getWidget($widget);
     $widget->setRequest($this->request);
     $widget->setResponse($this->response);
     $widget->setProperties($widgetProperties);
     $widget->setLocale($locale);
     $widget->setRegion($region);
     if ($widget instanceof AbstractController) {
         $widget->setConfig($this->config);
         $widget->setDependencyInjector($this->dependencyInjector);
     }
     $translator = $this->getTranslator();
     $referer = $this->request->getQueryParameter('referer');
     $security = $widgetProperties->getWidgetProperty(Node::PROPERTY_SECURITY, Node::AUTHENTICATION_STATUS_EVERYBODY);
     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' => $widgetProperties->getWidgetProperty(Node::PROPERTY_PUBLISH, true), 'publishStart' => $widgetProperties->getWidgetProperty(Node::PROPERTY_PUBLISH_START, null), 'publishStop' => $widgetProperties->getWidgetProperty(Node::PROPERTY_PUBLISH_STOP, null), 'security' => $security, 'permissions' => $permissions);
     $permissions = $securityManager->getSecurityModel()->getPermissions();
     $form = $this->createFormBuilder($data);
     $form->addRow('published', 'option', array('label' => $translator->translate('label.publish'), 'options' => $this->getPublishedOptions($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'), 'options' => $this->getSecurityOptions($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));
     }
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             if ($data['security'] == Node::AUTHENTICATION_STATUS_AUTHENTICATED && $permissions && $data['permissions']) {
                 $data['security'] = implode(',', $data['permissions']);
             }
             $widgetProperties->setWidgetProperty(Node::PROPERTY_PUBLISH, $data['published']);
             $widgetProperties->setWidgetProperty(Node::PROPERTY_PUBLISH_START, $data['publishStart']);
             $widgetProperties->setWidgetProperty(Node::PROPERTY_PUBLISH_STOP, $data['publishStop']);
             $widgetProperties->setWidgetProperty(Node::PROPERTY_SECURITY, $data['security']);
             $cms->saveNode($node, 'Updated visibility properties for widget ' . $widgetId . ' in ' . $node->getName());
             $this->addSuccess('success.widget.saved', array('widget' => $translator->translate('widget.' . $widget->getName())));
             $this->response->setRedirect($this->getUrl('cms.node.content.region', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId(), 'region' => $region)));
             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);
         }
     }
     $referer = $this->request->getQueryParameter('referer');
     $this->setTemplateView('cms/backend/widget.visibility', array('site' => $site, 'node' => $node, 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales(), 'region' => $region, 'widget' => $widget, 'widgetId' => $widgetId, 'widgetName' => $translator->translate('widget.' . $widget->getName()), 'form' => $form->getView()));
 }
 /**
  * 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);
 }
Пример #18
0
 /**
  * Action to delete a node
  * @param \ride\web\cms\Cms $cms
  * @param string $locale
  * @param string $site
  * @param string $revision
  * @param string $node
  * @return null
  */
 public function deleteAction(Cms $cms, $locale, $site, $revision, $node)
 {
     if (!$cms->resolveNode($site, $revision, $node)) {
         return;
     }
     $this->setContentLocale($locale);
     $translator = $this->getTranslator();
     $referer = $this->request->getQueryParameter('referer');
     $form = $this->createFormBuilder();
     $form->addRow('recursive', 'option', array('label' => '', 'description' => $translator->translate('label.confirm.node.delete.recursive')));
     $form = $form->build();
     if ($form->isSubmitted()) {
         $data = $form->getData();
         $cms->removeNode($node, $data['recursive']);
         $this->addSuccess('success.node.deleted', array('node' => $node->getName($locale)));
         $url = $this->getUrl('cms.site.detail.locale', array('site' => $site->getId(), 'revision' => $node->getRevision(), 'locale' => $locale, 'node' => $node->getId()));
         if ($referer) {
             $url .= '?referer=' . urlencode($referer);
         }
         $this->response->setRedirect($url);
         return;
     }
     $this->setTemplateView('cms/backend/delete.form', array('form' => $form->getView(), 'referer' => $referer, 'site' => $site, 'node' => $node, 'locale' => $locale, 'locales' => $cms->getLocales()));
 }
 public function formAction(Cms $cms, $locale, $site, $revision = null, $node = null)
 {
     if ($node) {
         if (!$cms->resolveNode($site, $revision, $node, 'redirect')) {
             return;
         }
         $cms->setLastAction('edit');
     } else {
         if (!$cms->resolveNode($site, $revision)) {
             return;
         }
         $node = $cms->createNode('redirect', $site);
     }
     $this->setContentLocale($locale);
     $translator = $this->getTranslator();
     $locales = $cms->getLocales();
     $referer = $this->request->getQueryParameter('referer');
     // get available nodes
     $nodeList = $cms->getNodeList($site, $locale, true, false);
     if ($node && isset($nodeList[$node->getId()])) {
         unset($nodeList[$node->getId()]);
     }
     // gather data
     $data = array('name' => $node->getName($locale), 'redirect-node' => $node->getRedirectNode($locale), 'redirect-url' => $node->getRedirectUrl($locale), 'route' => $node->getRoute($locale, false), 'availableLocales' => $this->getLocalesValueFromNode($node));
     if ($data['redirect-url']) {
         $data['redirect-type'] = 'url';
     } else {
         $data['redirect-type'] = 'node';
     }
     // build form
     $form = $this->createFormBuilder($data);
     $form->addRow('name', 'string', array('label' => $translator->translate('label.redirect'), 'description' => $translator->translate('label.redirect.name.description'), 'filters' => array('trim' => array()), 'validators' => array('required' => array())));
     $form->addRow('redirect-type', 'option', array('label' => $translator->translate('label.redirect.to'), 'options' => array('node' => $translator->translate('label.node'), 'url' => $translator->translate('label.url')), 'validators' => array('required' => array())));
     $form->addRow('redirect-node', 'select', array('label' => $translator->translate('label.redirect.node'), 'description' => $translator->translate('label.redirect.node.description'), 'options' => $nodeList));
     $form->addRow('redirect-url', 'string', array('label' => $translator->translate('label.redirect.url'), 'description' => $translator->translate('label.redirect.url.description'), 'filters' => array('trim' => array())));
     $form->addRow('route', 'string', array('label' => $translator->translate('label.route'), 'description' => $translator->translate('label.route.description'), 'filters' => array('trim' => array())));
     if ($site->isLocalizationMethodCopy()) {
         $form->addRow('availableLocales', 'select', array('label' => $translator->translate('label.locales'), 'description' => $translator->translate('label.locales.available.description'), 'options' => $this->getLocalesOptions($node, $translator, $locales), 'multiple' => true, 'validators' => array('required' => array())));
     }
     // process form
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $node->setName($locale, $data['name']);
             $node->setRoute($locale, $data['route']);
             if ($site->isLocalizationMethodCopy()) {
                 $node->setAvailableLocales($this->getOptionValueFromForm($data['availableLocales']));
             } else {
                 $node->setAvailableLocales($locale);
             }
             if ($data['redirect-type'] == 'node') {
                 $node->setRedirectNode($locale, $data['redirect-node']);
                 $node->setRedirectUrl($locale, null);
             } else {
                 $node->setRedirectNode($locale, null);
                 $node->setRedirectUrl($locale, $data['redirect-url']);
             }
             $cms->saveNode($node, (!$node->getId() ? 'Created new redirect ' : 'Updated redirect ') . $node->getName());
             $this->addSuccess('success.node.saved', array('node' => $node->getName($locale)));
             $url = $this->getUrl('cms.redirect.edit', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId()));
             if ($referer) {
                 $url .= '?referer=' . urlencode($referer);
             }
             $this->response->setRedirect($url);
             return;
         } catch (ValidationException $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     // show view
     $this->setTemplateView('cms/backend/redirect.form', array('site' => $site, 'node' => $node, 'referer' => $referer, 'form' => $form->getView(), 'locale' => $locale, 'locales' => $locales));
 }
 /**
  * Perform the structure node action
  */
 public function indexAction(Cms $cms, CmsVarnishService $varnishService, $locale, $site, $revision, $node)
 {
     if (!$cms->resolveNode($site, $revision, $node, null, true)) {
         return;
     }
     $this->setContentLocale($locale);
     $cms->setLastAction(self::NAME);
     $referer = $this->request->getQueryParameter('referer');
     if (!$referer) {
         $referer = $this->getUrl('cms.node.varnish', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $site->getRevision(), 'node' => $node->getId()));
     }
     $translator = $this->getTranslator();
     $cache = $node->get('cache.target', 'inherit', false);
     $data = array('cacheTarget' => $cache, 'sharedMaxAge' => in_array($cache, array('intermediate', 'all')) ? $node->getHeader($locale, 's-maxage') : null, 'maxAge' => $cache == 'all' ? $node->getHeader($locale, 'max-age') : ($cache == 'intermediate' ? 0 : null));
     $formHeaders = null;
     if ($this->isPermissionGranted('cms.node.varnish.manage')) {
         $formHeaders = $this->createFormBuilder($data);
         $formHeaders->setAction('headers');
         $formHeaders->addRow('cacheTarget', 'option', array('label' => $translator->translate('label.cache.target'), 'options' => $this->getCacheOptions($node, $translator, $locale), 'attributes' => array('data-toggle-dependant' => 'option-cachetarget'), 'validators' => array('required' => array())));
         $formHeaders->addRow('maxAge', 'select', array('label' => $translator->translate('label.header.maxage'), 'description' => $translator->translate('label.header.maxage.description'), 'options' => $this->getTimeOptions($translator, 0, 3600), 'attributes' => array('class' => 'option-cachetarget option-cachetarget-all')));
         $formHeaders->addRow('sharedMaxAge', 'select', array('label' => $translator->translate('label.header.smaxage'), 'description' => $translator->translate('label.header.smaxage.description'), 'options' => $this->getTimeOptions($translator, 0, 31536000), 'attributes' => array('class' => 'option-cachetarget option-cachetarget-intermediate option-cachetarget-all')));
         $formHeaders = $formHeaders->build();
         if ($formHeaders->isSubmitted()) {
             try {
                 $formHeaders->validate();
                 $data = $formHeaders->getData();
                 $node->set('cache.target', $data['cacheTarget']);
                 $node->setHeader($locale, 'max-age', $data['cacheTarget'] == 'all' ? $data['maxAge'] : ($data['cacheTarget'] == 'intermediate' ? 0 : ($data['cacheTarget'] == 'inherit' ? null : '')));
                 $node->setHeader($locale, 's-maxage', in_array($data['cacheTarget'], array('intermediate', 'all')) ? $data['sharedMaxAge'] : ($data['cacheTarget'] == 'inherit' ? null : ''));
                 $node->setHeader($locale, 'Expires', 'Wed, 06 Jul 1983 5:00:00 GMT');
                 $cms->saveNode($node, "Set cache properties for " . $node->getName());
                 $this->addSuccess('success.node.saved', array('node' => $site->getName($locale)));
                 $this->response->setRedirect($referer);
                 return;
             } catch (ValidationException $exception) {
                 $this->setValidationException($exception, $formHeaders);
             }
         }
         $formHeaders = $formHeaders->getView();
     }
     $formClear = $this->createFormBuilder();
     $formClear->setAction('clear');
     $formClear->addRow('recursive', 'option', array('label' => '', 'description' => $translator->translate('label.confirm.varnish.clear.recursive')));
     $formClear = $formClear->build();
     if ($formClear->isSubmitted()) {
         $baseUrl = $site->getBaseUrl($locale);
         if (!$baseUrl) {
             $baseUrl = $this->request->getBaseUrl();
         }
         $data = $formClear->getData();
         $varnishService->banNode($node, $baseUrl, $locale, $data['recursive']);
         $this->addSuccess('success.node.varnish.cleared', array('node' => $node->getName($locale)));
         $this->response->setRedirect($referer);
         return;
     }
     $referer = $this->request->getQueryParameter('referer');
     $this->setTemplateView('cms/backend/node.varnish', array('site' => $site, 'node' => $node, 'formHeaders' => $formHeaders, 'formClear' => $formClear->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales()));
 }
Пример #21
0
 /**
  * Action to dispatch to the style of a section
  * @param \ride\web\cms\Cms $cms
  * @param string $locale
  * @param string $site
  * @param string $revision
  * @param string $node
  * @param string $region
  * @param string $widget
  * @return null
  */
 public function sectionStyleAction(Cms $cms, $locale, $site, $revision, $node, $region, $section)
 {
     if (!$cms->resolveNode($site, $revision, $node) || !$cms->resolveRegion($node, $locale, $region)) {
         return;
     }
     $translator = $this->getTranslator();
     $data = array('style' => $node->getSectionStyle($region, $section));
     $form = $this->createFormBuilder($data);
     $form->addRow('style', 'string', array('label' => $translator->translate('label.style.container')));
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $node->setSectionStyle($region, $section, $data['style']);
             $cms->saveNode($node, 'Updated style for section ' . $section . ' in region ' . $region . ' of node ' . $node->getName());
             $this->response->setRedirect($this->getUrl('cms.node.content.region', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId(), 'region' => $region)));
             return;
         } catch (ValidationException $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $referer = $this->request->getQueryParameter('referer');
     $this->setTemplateView('cms/backend/section.style', array('site' => $site, 'node' => $node, 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales(), 'region' => $region, 'section' => $section, 'form' => $form->getView()));
 }
 /**
  * Action to edit the templates of the widget
  * @param Cms $cms
  * @param TemplateFacade $templateFacade
  * @param FileBrowser $fileBrowser
  * @param string $locale
  * @param string $site
  * @param string $revision
  * @param string $node
  * @param string $region
  * @param string $widget
  * @return null
  */
 public function indexAction(Cms $cms, TemplateFacade $templateFacade, FileBrowser $fileBrowser, $locale, $site, $revision, $node, $region, $widget)
 {
     if (!$cms->resolveNode($site, $revision, $node) || !$cms->resolveRegion($node, $locale, $region)) {
         return;
     }
     $templateFacade->setThemeModel($cms->getThemeModel());
     $widgetId = $widget;
     $widget = $site->getWidget($widgetId);
     $widget = clone $cms->getWidget($widget);
     $widget->setRequest($this->request);
     $widget->setResponse($this->response);
     $widget->setProperties($node->getWidgetProperties($widgetId));
     $widget->setLocale($locale);
     $widget->setRegion($region);
     if ($widget instanceof AbstractController) {
         $widget->setConfig($this->config);
         $widget->setDependencyInjector($this->dependencyInjector);
     }
     $templates = $widget->getTemplates();
     foreach ($templates as $index => $template) {
         $tokens = explode('/', $template);
         $name = array_pop($tokens);
         unset($templates[$index]);
         $templates[$name] = $template;
     }
     $component = new TemplatesComponent();
     $data = $component->createData($templateFacade, $templates, $node->getTheme(), $widgetId);
     $form = $this->buildForm($component, $data);
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             $applicationDirectory = $fileBrowser->getApplicationDirectory();
             foreach ($templates as $name => $template) {
                 $file = $applicationDirectory->getChild($data['path'][$name]);
                 $file->getParent()->create();
                 $file->write($data['content'][$name]);
             }
             $this->addSuccess('success.widget.saved', array('widget' => $this->getTranslator()->translate('widget.' . $widget->getName())));
             $this->response->setRedirect($this->getUrl('cms.node.content.region', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId(), 'region' => $region)));
             return;
         } catch (ValidationException $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $referer = $this->request->getQueryParameter('referer');
     $this->setTemplateView('cms/backend/widget.templates', array('site' => $site, 'node' => $node, 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales(), 'region' => $region, 'widget' => $widget, 'widgetId' => $widgetId, 'widgetName' => $this->getTranslator()->translate('widget.' . $widget->getName()), 'templates' => $templates, 'form' => $form->getView()));
 }