Beispiel #1
0
 protected function find(ModelCriteria $query, $params)
 {
     $all = $this->pageRevision->getPageModuleWrappers($this->langcode);
     $user = User::getUser();
     if ($user->hasPagePermission($this->pageRevision->getPage(), PageAccessPeer::PERM_MODULES)) {
         return $all;
     }
     $wrappers = array();
     foreach ($all as $wrapper) {
         if ($user->hasModuleAccess($wrapper)) {
             $wrappers[] = $wrapper;
         }
     }
     return $wrappers;
 }
Beispiel #2
0
 /**
  * Publish page revision.
  *
  * @param PageRevision $pageRevision
  */
 public function publishRevision(PageRevision $pageRevision)
 {
     $page = $pageRevision->getPage();
     $page->setActivePageRevision($pageRevision);
     $page->setWorkingPageRevision(null);
     $page->save();
     $pageRevision->setPublishedDate(time());
     $pageRevision->keepUpdateDateUnchanged();
     $pageRevision->save();
     self::updateIndex($page);
 }
 protected function getGlobals()
 {
     $lang = \Curry_Language::getLanguage();
     return array('language' => $lang ? $lang->toArray() : null, 'page' => $this->pageRevision->getPage()->toTwig());
 }
Beispiel #4
0
 protected function getGlobals()
 {
     $lang = Curry_Language::getLanguage();
     return array('ContentType' => $this->getContentType(), 'Encoding' => $this->getOutputEncoding(), 'language' => $lang ? $lang->toArray() : null, 'page' => $this->pageRevision->getPage()->toTwig(), 'request' => $this->request);
 }
Beispiel #5
0
 /**
  * Create a PageGenerator instance for the specified PageRevision.
  *
  * @param PageRevision $pageRevision
  * @param Curry_Request $request
  * @return Curry_PageGenerator
  */
 public static function createPageGenerator(PageRevision $pageRevision, Curry_Request $request)
 {
     $generatorClass = $pageRevision->getPage()->getInheritedProperty('Generator', Curry_Core::$config->curry->defaultGeneratorClass);
     return new $generatorClass($pageRevision, $request);
 }
Beispiel #6
0
 /**
  * Create new module form.
  *
  * @param PageRevision $pageRevision
  * @param string $moduleClass
  * @return Curry_Form
  */
 public static function getNewModuleForm($pageRevision, $moduleClass, $target)
 {
     $valid = array();
     $modules = array();
     foreach (ModuleQuery::create()->orderByTitle()->find() as $module) {
         $inTargets = in_array($target, $module->getTargets());
         if (!$target || ($module->getTargetsExclude() ? !$inTargets : $inTargets)) {
             $modules[$module->getModuleId()] = $module->getTitle();
             $valid[] = $module->getModuleId();
         }
     }
     $user = User::getUser();
     $modulePermission = $user->hasPagePermission($pageRevision->getPage(), PageAccessPeer::PERM_MODULES);
     if ($modulePermission) {
         $modules = array('Predefined' => $modules);
         foreach (AbstractModule::getModuleList() as $className) {
             $parts = explode("_", str_replace("_Module_", "_", $className));
             $package = array_shift($parts);
             $modules[$package][$className] = join(" / ", $parts);
             $valid[] = $className;
         }
     }
     if (!$moduleClass || !in_array($moduleClass, $valid)) {
         $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('module_class' => array('select', array('label' => 'Type', 'multiOptions' => $modules, 'required' => true)), 'next' => array('submit', array('label' => 'Next')))));
         return $form;
     } else {
         // Fetch template targets
         $targets = array();
         try {
             $template = $pageRevision->getInheritedProperty('Template');
             if ($template) {
                 $template = \Curry\App::getInstance()->twig->loadTemplate($template);
             }
             while ($template) {
                 $targets = array_merge($targets, $template->getPlaceholders());
                 $template = $template->getParent(array());
             }
         } catch (Exception $e) {
             \Curry\App::getInstance()->logger->warning('Error in template: ' . $e->getMessage());
         }
         if (count($targets)) {
             $targets = array_combine(array_values($targets), array_values($targets));
         }
         // Check for predefined module creation
         if (ctype_digit($moduleClass)) {
             $module = ModuleQuery::create()->findPk($moduleClass);
             $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('pid_newmodule' => array('hidden', array('value' => 1)), 'module_class' => array('hidden', array('value' => $moduleClass)), 'name' => array('text', array('label' => 'Name', 'required' => true, 'description' => 'A descriptive name of the module.', 'value' => $module->getName())))));
             if (!$target) {
                 // Show only acceptable targets...
                 $form->addElement('select', 'target', array('label' => 'Target', 'description' => 'Specifies what placeholder/variable in the page-template to attach this module to.', 'multiOptions' => $targets));
             } else {
                 $form->addElement('hidden', 'target', array('value' => $target));
                 $form->setCsrfCheck(false);
                 $_POST = $form->getValues();
             }
             $form->addElement('submit', 'add', array('label' => 'Add module'));
             return $form;
         }
         if (!class_exists($moduleClass)) {
             throw new Exception('Class \'' . $moduleClass . '\' could not be loaded, please check the path and classname.');
         }
         $defaultName = substr($moduleClass, strrpos($moduleClass, '_') + 1);
         $targets[''] = '[ Custom ]';
         asort($targets);
         $templates = array('' => "[ None ]", 'new' => "[ Create new ]") + Curry_Backend_Template::getTemplateSelect();
         $defaultTemplateName = 'Modules/' . $defaultName . '.html';
         $defaultTemplate = '';
         if ($moduleClass !== 'Curry_Module_Article' && call_user_func(array($moduleClass, 'hasTemplate'))) {
             $defaultTemplate = array_key_exists($defaultTemplateName, $templates) ? $defaultTemplateName : 'new';
         }
         $predefinedTemplates = call_user_func(array($moduleClass, 'getPredefinedTemplates'));
         $predefinedTemplates = count($predefinedTemplates) ? array_combine(array_keys($predefinedTemplates), array_keys($predefinedTemplates)) : array();
         $predefinedTemplates = array('' => '[ Empty ]') + $predefinedTemplates;
         $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('pid_newmodule' => array('hidden'), 'module_class' => array('hidden', array('value' => $moduleClass)), 'module_class_display' => array('rawHtml', array('label' => 'Type', 'value' => '<input type="text" value="' . $moduleClass . '" disabled="disabled" />')), 'name' => array('text', array('label' => 'Name', 'required' => true, 'description' => 'A descriptive name of the module.', 'value' => $defaultName)), 'target' => array('select', array('label' => 'Target', 'description' => 'Specifies what placeholder/variable in the page-template to attach this module to.', 'value' => isset($_GET['target']) ? $_GET['target'] : null, 'multiOptions' => $targets, 'class' => 'trigger-change', 'onchange' => "\$('#target_name-label, #target_name-element').toggle(\$(this).val() == '');")), 'target_name' => array('text', array('label' => 'Target Name')), 'template' => array('select', array('class' => 'trigger-change', 'label' => 'Template', 'multiOptions' => $templates, 'value' => $defaultTemplate, 'onchange' => "\$('#template_name-label, #template_name-element, #predefined_template-label, #predefined_template-element').toggle(\$(this).val() == 'new');")), 'template_name' => array('text', array('label' => 'Name', 'value' => $defaultTemplateName)), 'predefined_template' => array('select', array('label' => 'Predefined template', 'multiOptions' => $predefinedTemplates)), 'content_visibility' => array('select', array('label' => 'Content Visibility', 'description' => 'Set the visibility of this module in the Content backend module.', 'multiOptions' => PageModulePeer::$contentVisiblityOptions, 'value' => PageModulePeer::CONTENT_VISIBILITY_ALWAYS, 'required' => true)), 'search_visibility' => array('checkbox', array('label' => 'Search Visibility', 'description' => 'If this module should be rendered when indexing pages.', 'value' => true, 'required' => true)))));
         $form->addDisplayGroup(array('position', 'content_visibility', 'search_visibility'), 'advanced', array('class' => 'advanced', 'legend' => 'Advanced'));
         $form->addElement('submit', 'add', array('label' => 'Add module'));
     }
     return $form;
 }