예제 #1
0
파일: Html.php 프로젝트: varvanin/currycms
 /**
  * Wrap module with inline admin controls.
  *
  * @param string $content
  * @param Curry_PageModuleWrapper $pageModuleWrapper
  * @return string
  */
 protected function adminModule($content, Curry_PageModuleWrapper $pageModuleWrapper)
 {
     $user = User::getUser();
     $pageId = $pageModuleWrapper->getPageRevision()->getPageId();
     $page = $pageModuleWrapper->getPageRevision()->getPage();
     $pageModuleId = $pageModuleWrapper->getPageModuleId();
     $commands = array();
     $templatePermission = $user->hasAccess('Curry_Backend_Template');
     $contentPermission = $user->hasPagePermission($page, PageAccessPeer::PERM_CONTENT);
     $modulePermission = $user->hasPagePermission($page, PageAccessPeer::PERM_MODULES);
     $createPermission = $user->hasPagePermission($page, PageAccessPeer::PERM_CREATE_MODULE);
     if (!$user->hasModuleAccess($pageModuleWrapper)) {
         return $content;
     }
     if ($contentPermission || $modulePermission) {
         $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'Module', 'page_id' => $pageId, 'page_module_id' => $pageModuleId));
         if ($user->hasPagePermission($page, PageAccessPeer::PERM_CONTENT)) {
             $commands['edit'] = array('Name' => 'Edit', 'Url' => $url, 'Class' => 'iframe');
         }
     }
     if ($pageModuleWrapper->getTemplate() && $templatePermission) {
         $url = url('admin.php', array('module' => 'Curry_Backend_Template', 'view' => 'Edit', 'file' => $pageModuleWrapper->getTemplate()));
         $commands['template'] = array('Name' => 'Edit template', 'Url' => $url, 'Class' => 'iframe');
     }
     if ($modulePermission) {
         $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'ModuleProperties', 'page_id' => $pageId, 'page_module_id' => $pageModuleId));
         $commands['properties'] = array('Name' => 'Properties', 'Url' => $url, 'Class' => 'iframe');
     }
     if ($createPermission && ($contentPermission && !$pageModuleWrapper->isInherited() || $modulePermission)) {
         $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'DeleteModule', 'page_id' => $pageId, 'page_module_id' => $pageModuleId));
         $commands['delete'] = array('Name' => 'Delete', 'Url' => $url, 'Class' => 'iframe');
     }
     $module = $pageModuleWrapper->createObject();
     $module->setPageGenerator($this);
     $commands = $module->getInlineCommands($commands);
     if (!count($commands)) {
         return $content;
     }
     $tpl = Curry_Twig_Template::loadTemplateString(Curry_InlineAdmin::getAdminModuleTpl());
     return $tpl->render(array('Id' => $pageModuleId, 'Name' => $pageModuleWrapper->getName(), 'ClassName' => $pageModuleWrapper->getClassName(), 'Content' => $content, 'commands' => $commands));
 }
예제 #2
0
 /**
  * Get "copy code" for module.
  *
  * @param Curry_PageModuleWrapper $module
  * @return array
  */
 public static function getModuleCode(Curry_PageModuleWrapper $module)
 {
     $datas = array();
     $moduleDatas = ModuleDataQuery::create()->filterByPageModule($module->getPageModule())->filterByPageRevision($module->getPageRevision())->orderByLangcode()->find();
     foreach ($moduleDatas as $moduleData) {
         $datas[] = self::getModuleDataCode($moduleData);
     }
     return array("is_inherited" => $module->isInherited(), "uid" => $module->getPageModule()->getUid(), "name" => $module->getName(), "module_class" => $module->getClassName(), "inherit" => true, "target" => $module->getTarget(), "content_visibility" => $module->getPageModule()->getContentVisibility(), "search_visibility" => $module->getPageModule()->getSearchVisibility(), "datas" => $datas);
 }
예제 #3
0
 /**
  * Edit module form.
  *
  * @param Curry_PageModuleWrapper $wrapper
  * @return Curry_Form|null
  */
 protected function getModuleForm(Curry_PageModuleWrapper $wrapper)
 {
     $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'elements' => array('pid_editmodule' => array('hidden'))));
     if ($wrapper->hasData()) {
         $subform = $wrapper->createObject()->showBack();
         if ($subform == null) {
             return null;
         }
         if (!$subform instanceof Curry_Form_SubForm) {
             throw new Exception($wrapper->getClassName() . '::showBack() did not return an instance of Curry_Form_SubForm.');
         }
         if (!$subform->getLegend()) {
             $subform->setLegend($wrapper->getName() . ' (' . $wrapper->getClassName() . ')');
         }
         if (!$subform instanceof Curry_Form_MultiForm) {
             $subform->setDecorators(array('FormElements'));
         }
         $form->addSubForm($subform, 'module' . $wrapper->getPageModuleId());
         $buttons = array('save');
         $form->addElement('submit', 'save', array('label' => 'Save'));
         if ($wrapper->isDeletable()) {
             $form->addElement('submit', 'delete', array('label' => 'Remove content'));
             $buttons[] = 'delete';
         }
         $form->addDisplayGroup($buttons, 'dg1', array('class' => 'horizontal-group'));
     } else {
         $form->addElement('submit', 'create', array('label' => $wrapper->isInherited() ? 'Override content' : 'Create content'));
     }
     return $form;
 }
예제 #4
0
 /**
  * Get unique name for storing module cache.
  *
  * @param Curry_PageModuleWrapper $pageModuleWrapper
  * @param Curry_Module $module
  * @return string
  */
 private function getModuleCacheName(Curry_PageModuleWrapper $pageModuleWrapper, Curry_Module $module)
 {
     $params = array('_moduleDataId' => $pageModuleWrapper->getModuleDataId(), '_template' => $pageModuleWrapper->getTemplate());
     $cp = $module->getCacheProperties();
     if ($cp !== null) {
         $params = array_merge($params, $cp->getParams());
     }
     return __CLASS__ . '_Module_' . md5(serialize($params));
 }
예제 #5
0
 /**
  * Save module properties.
  *
  * @param Curry_PageModuleWrapper $pageModuleWrapper
  * @param array $values
  */
 public static function saveModuleProperties(Curry_PageModuleWrapper $pageModuleWrapper, array $values)
 {
     $modified = false;
     // PageModule
     $pageModule = $pageModuleWrapper->getPageModule();
     $pageModule->setName($values['name']);
     $pageModule->setTarget($values['target']);
     $pageModule->setContentVisibility($values['content_visibility']);
     $pageModule->setSearchVisibility($values['search_visibility']);
     $modified |= $pageModule->isModified();
     $pageModule->save();
     // ModuleData
     $moduleData = $pageModuleWrapper->getModuleData();
     $moduleData->setTemplate($values['local']['template'] === '' ? null : $values['local']['template']);
     $moduleData->setEnabled(self::str2bool($values['local']['show']));
     $modified |= $moduleData->isModified();
     $moduleData->save();
     if ($modified) {
         $pageRevision = $pageModuleWrapper->getPageRevision();
         $pageRevision->setUpdatedAt(time());
         $pageRevision->save();
     }
 }