示例#1
0
 /** {@inheritdoc} */
 public function render($content)
 {
     $element = $this->getElement();
     $view = $element->getView();
     if (null === $view) {
         return $content;
     }
     $placement = $this->getPlacement();
     $separator = $this->getSeparator();
     $attr = array('onchange' => '$(this).prev().val(this.value.split("|")[1]); this.selectedIndex = 0;');
     $options = array('' => 'Select page...');
     foreach (PageQuery::create()->orderByBranch()->find() as $page) {
         if (Curry_Backend_Page::isTemplatePage($page)) {
             continue;
         }
         $options[$page->getPageId() . '|' . $page->getUrl()] = str_repeat(Curry_Core::SELECT_TREE_PREFIX, $page->getLevel()) . $page->getName();
     }
     $options = Curry_Html::createSelectOptions($options, '');
     $markup = Curry_Html::createTag('select', $attr, $options);
     switch ($placement) {
         case 'PREPEND':
             $content = $markup . $separator . $content;
             break;
         case 'APPEND':
         default:
             $content = $content . $separator . $markup;
     }
     return $content;
 }
示例#2
0
 /**
  * Get page tree node properties.
  *
  * @param \Page $page
  * @param Tree $tree
  * @param int $depth
  * @return array
  */
 public function getPageTreeNode($page, Tree $tree, $depth = 0)
 {
     $p = $tree->objectToJson($page, $tree, $depth);
     if ($page->getWorkingPageRevisionId() && $page->getWorkingPageRevisionId() !== $page->getActivePageRevisionId()) {
         $p['title'] .= '*';
         $p['addClass'] = 'page-unpublished';
     }
     $p['expand'] = true;
     $p['href'] = $this->page->url(array('id' => $page->getPageId()));
     // Mark active node
     if (isset($_GET['page_id']) && $_GET['page_id'] == $page->getPageId()) {
         $p['activate'] = $p['focus'] = $p['select'] = true;
     }
     // Icon
     $p['iconClass'] = 'no-icon';
     if (\Curry_Backend_Page::isTemplatePage($page)) {
         if ($page === \Curry_Backend_Page::getTemplatePage()) {
             $p['title'] .= ' <span class="icon-columns"></span>';
         }
     } else {
         $icon = "";
         if (!$page->getEnabled()) {
             $icon .= '<span class="icon-lock" title="Inactive"></span>';
         }
         if (!$page->getVisible()) {
             $icon .= '<span class="icon-eye-close" title="Do not show in menu"></span>';
         }
         if ($page->getRedirectMethod()) {
             $icon .= '<span class="icon-link" title="Redirect"></span>';
         }
         if ($icon) {
             $p['title'] .= " {$icon}";
         }
     }
     return $p;
 }
示例#3
0
 /**
  * Build admin panel
  */
 protected function adminPanel()
 {
     $user = User::getUser();
     $page = $this->getPage();
     $commands = array();
     $url = url('admin.php?module=Curry_Backend_Page', array("view" => "PageProperties", "page_id" => $this->pageRevision->getPageId()));
     if ($user->hasPagePermission($page, PageAccessPeer::PERM_PROPERTIES)) {
         $commands[] = array('Name' => 'Page properties', 'Url' => $url, 'Class' => 'iframe');
     }
     $url = url('admin.php?module=Curry_Backend_Page', array('module' => 'Curry_Backend_Page', 'view' => 'NewPage', 'page_id' => $this->pageRevision->getPageId()));
     if ($user->hasPagePermission($page, PageAccessPeer::PERM_CREATE_PAGE)) {
         $commands[] = array('Name' => 'New page', 'Url' => $url, 'Class' => 'iframe');
     }
     $url = url('admin.php?module=Curry_Backend_Page', array('module' => 'Curry_Backend_Page', 'view' => 'PageRevisions', "page_id" => $this->pageRevision->getPageId()));
     if ($user->hasPagePermission($page, PageAccessPeer::PERM_REVISIONS)) {
         $commands[] = array('Name' => 'Page revisions', 'Url' => $url, 'Class' => 'iframe');
     }
     if ($this->pageRevision->allowEdit()) {
         $commands[] = array('Name' => 'Show all modules', 'Url' => '#', 'Class' => 'toggle-show-all-modules');
     } else {
         $url = '';
         $commands[] = array('Name' => 'Create working revision (TODO)', 'Url' => $url, 'Class' => 'iframe');
     }
     $view = Curry_Backend_Page::getPageView($page);
     $url = url('admin.php?module=Curry_Backend_Page', array('view' => $view, 'page_id' => $this->pageRevision->getPageId()));
     $commands[] = array('Name' => 'Backend', 'Url' => $url, 'Class' => 'curry-admin-backend');
     $url = (string) url('', $_GET)->add(array('curry_inline_admin' => 0));
     $commands[] = array('Name' => 'Exit Live Edit', 'Url' => $url, 'Class' => 'curry-admin-logout');
     $tpl = Curry_Twig_Template::loadTemplateString(Curry_InlineAdmin::getAdminPanelTpl());
     $content = $tpl->render(array('commands' => $commands));
     $htmlHead = $this->getHtmlHead();
     $htmlHead->addScript(Curry_Backend::JQUERY_JS);
     $htmlHead->addInlineScript('window.inlineAdminContent = ' . json_encode($content) . ';');
     $htmlHead->addScript("shared/backend/common/js/inline-admin.js");
     $htmlHead->addStyleSheet("shared/backend/" . Curry_Core::$config->curry->backend->theme . "/css/inline-admin.css");
 }
示例#4
0
 public function showEdit(PageModuleWrapper $wrapper, $backend)
 {
     $form = $this->getModuleForm($wrapper);
     if (!$form) {
         $backend->addMessage('This module doesn\'t have a backend.');
         return;
     }
     if (isPost('pid_editmodule') && $form->isValid($_POST)) {
         $modified = false;
         $moduleForm = $form->getSubForm('module' . $wrapper->getPageModuleId());
         if ($moduleForm) {
             $module = $wrapper->createObject();
             if ($module->saveBack($moduleForm) !== false) {
                 $modified = $module->saveModule();
             }
             $backend->createModelUpdateEvent('PageModule', $wrapper->getPageModuleId(), 'update');
             $backend->addBodyClass('live-edit-close');
         }
         if ($form->delete && $form->delete->isChecked()) {
             $wrapper->getModuleData()->delete();
             $modified = true;
         } else {
             if ($form->create && $form->create->isChecked() && !$wrapper->hasData()) {
                 $wrapper->createData();
                 $modified = true;
             }
         }
         if ($modified) {
             $wrapper->reload();
             $pageRevision = $wrapper->getPageRevision();
             $pageRevision->setUpdatedAt(time());
             $pageRevision->save();
             if ($pageRevision->getPage()->getActivePageRevisionId() == $pageRevision->getPageRevisionId()) {
                 Curry_Backend_Page::updateIndex($pageRevision->getPage());
             }
         }
         $form = $this->getModuleForm($wrapper);
     }
     if (!$wrapper->hasData()) {
         $moduleData = $wrapper->getDataSource();
         if ($moduleData) {
             $page = $moduleData->getPageRevision()->getPage();
             $backend->addMainContent('<p>Content is inherited from <strong title="' . $page->getUrl() . '">' . htmlspecialchars($page->getName()) . '</strong> page.</p>');
         } else {
             $backend->addMainContent('<p>No content has been set for this page.</p>');
         }
     }
     $backend->addMainContent($form);
 }
示例#5
0
 /**
  * Build admin panel
  */
 protected function adminPanel()
 {
     $user = \User::getUser();
     $page = $this->app->page;
     $pageRevision = $this->app->pageRevision;
     $commands = array();
     $url = url('/admin/curry_backend_page/', array('view' => 'PageProperties', 'page_id' => $pageRevision->getPageId()));
     if ($user->hasPagePermission($page, \PageAccessPeer::PERM_PROPERTIES)) {
         $commands[] = array('Name' => 'Page properties', 'Url' => $url, 'Class' => 'iframe');
     }
     $url = url('/admin/curry_backend_page/', array('view' => 'NewPage', 'page_id' => $pageRevision->getPageId()));
     if ($user->hasPagePermission($page, \PageAccessPeer::PERM_CREATE_PAGE)) {
         $commands[] = array('Name' => 'New page', 'Url' => $url, 'Class' => 'iframe');
     }
     $url = url('/admin/curry_backend_page/', array('view' => 'PageRevisions', 'page_id' => $pageRevision->getPageId()));
     if ($user->hasPagePermission($page, \PageAccessPeer::PERM_REVISIONS)) {
         $commands[] = array('Name' => 'Page revisions', 'Url' => $url, 'Class' => 'iframe');
     }
     if ($pageRevision->allowEdit()) {
         $commands[] = array('Name' => 'Show all modules', 'Url' => '#', 'Class' => 'toggle-show-all-modules');
     } else {
         $url = '';
         $commands[] = array('Name' => 'Create working revision (TODO)', 'Url' => $url, 'Class' => 'iframe');
     }
     $view = \Curry_Backend_Page::getPageView($page);
     $url = url('admin.php?module=Curry_Backend_Page', array('view' => $view, 'page_id' => $pageRevision->getPageId()));
     $commands[] = array('Name' => 'Backend', 'Url' => $url, 'Class' => 'curry-admin-backend');
     $url = url('', $_GET);
     $commands[] = array('Name' => 'Exit Live Edit', 'Url' => $url, 'Class' => 'curry-admin-logout');
     $tpl = $this->app->loadTemplateString($this->getAdminPanelTpl());
     $content = $tpl->render(array('commands' => $commands));
     $htmlHead = $this->app->generator->getHtmlHead();
     $htmlHead->addScript(self::JQUERY_JS);
     $htmlHead->addInlineScript('window.inlineAdminContent = ' . json_encode($content) . ';');
     $htmlHead->addScript('shared/backend/common/js/inline-admin.js');
     $htmlHead->addStyleSheet('shared/backend/' . $this->app['backend.theme'] . '/css/inline-admin.css');
 }
示例#6
0
 /**
  * Get page permission table row.
  *
  * @param Page $page
  * @param string $name
  * @param User|null $user
  * @param UserRole|null $role
  * @return string
  */
 protected static function getPagePermissionRow(Page $page, $name, User $user = null, UserRole $role = null)
 {
     $inheritPermission = $page->getPageAccess($user, $role ? $role : ($user ? $user->getUserRole() : null));
     $userPermission = Curry_Backend_Page::getPagePermission($page);
     $access = PageAccessQuery::create()->filterByPage($page)->filterByUserAndRole($user, $role)->findOne();
     $row = '';
     foreach (PageAccess::getPermissionTypes() as $colName => $phpName) {
         $fieldName = $name . '[' . $colName . ']';
         $val = $access ? $access->{'get' . $phpName}() : null;
         if ($colName == PageAccessPeer::PERM_SUBPAGES) {
             if ($val === null) {
                 $val = $inheritPermission[$colName];
             }
             $row .= '<td><input type="hidden" name="' . $fieldName . '" value="no" /><input type="checkbox" name="' . $fieldName . '" value="yes" ' . ($userPermission[$colName] ? '' : 'disabled="disabled" ') . ($val ? 'checked="checked" ' : '') . '/></td>';
             continue;
         }
         $options = array('' => '(inherited)', 'yes' => 'Yes', 'no' => 'No');
         if ($val === null) {
             $options[''] = ($inheritPermission[$colName] ? 'Yes ' : 'No ') . $options[''];
         }
         $val = $val === null ? '' : ($val ? 'yes' : 'no');
         $selectedColor = 'black';
         $opts = '';
         foreach ($options as $optionValue => $optionLabel) {
             $attr = array('value' => $optionValue);
             $color = $optionValue ? $optionValue == 'yes' ? 'green' : 'red' : '#aaa';
             $attr['style'] = 'color:' . $color;
             if ($optionValue === $val) {
                 $selectedColor = $color;
                 $attr['selected'] = 'selected';
             }
             $opts .= Html::tag('option', $attr, $optionLabel);
         }
         $row .= '<td><select name="' . $fieldName . '" ' . ($userPermission[$colName] ? '' : 'disabled="disabled" ') . 'style="color:' . $selectedColor . '" onchange="this.style.color = this.options[this.selectedIndex].style.color">';
         $row .= $opts;
         $row .= '</select></td>';
     }
     return $row;
 }