コード例 #1
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);
     $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()));
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * 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()));
 }
コード例 #4
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()));
 }
コード例 #5
0
 /**
  * Action to add a widget to the provided region
  * @param \ride\web\cms\Cms $cms Facade to the CMS
  * @param \ride\web\cms\controller\backend\actino\widget\WidgetActionManager $widgetActionManager
  * @param string $locale Code of the locale
  * @param string $site Id of the site
  * @param string $revision Name of the revision
  * @param string $node Id of the node
  * @param string $region Name of the region
  * @param string $widget Id of the widget instance
  * @return null
  */
 public function widgetAddAction(Cms $cms, WidgetActionManager $widgetActionManager, $locale, $site, $revision, $node, $region, $section, $block, $widget)
 {
     if (!$cms->resolveNode($site, $revision, $node) || !$cms->resolveRegion($node, $locale, $region)) {
         return;
     }
     $widgetId = $site->createWidget($widget);
     $node->addWidget($region, $section, $block, $widgetId);
     $cms->saveNode($site, 'Created new instance for widget ' . $widget . ' in ' . $site->getName());
     $cms->saveNode($node, 'Added widget ' . $widget . ' to ' . $node->getName());
     $widget = clone $cms->getWidget($widget);
     $widget->setProperties($node->getWidgetProperties($widgetId));
     $widget->setLocale($locale);
     $widget->setRegion($region);
     $widget->setSection($section);
     $widget->setBlock($block);
     if ($widget instanceof AbstractController) {
         $widget->setConfig($this->config);
         $widget->setDependencyInjector($this->dependencyInjector);
     }
     $this->setTemplateView('cms/backend/widget.content', array('locale' => $locale, 'site' => $site, 'node' => $node, 'region' => $region, 'section' => $section, 'block' => $block, 'widget' => $widget, 'widgetId' => $widgetId, 'inheritedWidgets' => array(), 'actions' => $widgetActionManager->getWidgetActions()));
 }
コード例 #6
0
 /**
  * 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()));
 }