From 68fb3f761422ffe92e7a0b2496a214cfb0eb7c52 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 25 Dec 2012 20:41:05 +0100 Subject: [PATCH] Page menu items now support controllers Closes #998 --- com.woltlab.wcf/template/mainMenu.tpl | 2 +- com.woltlab.wcf/template/mainMenuSubMenu.tpl | 2 +- .../files/acp/templates/pageMenuItemAdd.tpl | 45 +++++++++++++++++- .../acp/form/PageMenuItemAddForm.class.php | 46 +++++++++++++++++-- .../acp/form/PageMenuItemEditForm.class.php | 4 ++ .../page/menu/item/PageMenuItem.class.php | 2 +- wcfsetup/install/lang/de.xml | 7 +++ 7 files changed, 98 insertions(+), 10 deletions(-) diff --git a/com.woltlab.wcf/template/mainMenu.tpl b/com.woltlab.wcf/template/mainMenu.tpl index 9e103d46bd..6dcc956a68 100644 --- a/com.woltlab.wcf/template/mainMenu.tpl +++ b/com.woltlab.wcf/template/mainMenu.tpl @@ -2,7 +2,7 @@ diff --git a/com.woltlab.wcf/template/mainMenuSubMenu.tpl b/com.woltlab.wcf/template/mainMenuSubMenu.tpl index c0e5ec585c..f3de76fe82 100644 --- a/com.woltlab.wcf/template/mainMenuSubMenu.tpl +++ b/com.woltlab.wcf/template/mainMenuSubMenu.tpl @@ -2,7 +2,7 @@ {if $__wcf->getPageMenu()->getMenuItems($menuItem->menuItem)|count > 0 && $__wcf->getPageMenu()->getActiveMenuItem() == $menuItem->menuItem} {/if} diff --git a/wcfsetup/install/files/acp/templates/pageMenuItemAdd.tpl b/wcfsetup/install/files/acp/templates/pageMenuItemAdd.tpl index 793f10ae40..02e2d2954a 100644 --- a/wcfsetup/install/files/acp/templates/pageMenuItemAdd.tpl +++ b/wcfsetup/install/files/acp/templates/pageMenuItemAdd.tpl @@ -7,6 +7,8 @@ var $isLandingPageContainer = $('#isLandingPageContainer'); var $menuPosition = $('#menuPosition'); var $parentMenuItemContainer = $('#parentMenuItemContainer'); + var $isInternalLink = $('input[name=isInternalLink]').filter('[value=1]'); + var $menuItemControllerContainer = $('#menuItemControllerContainer'); function handleMenuPosition() { if ($menuPosition.val() === 'header') { @@ -22,6 +24,15 @@ } } + function handleIsInternalLink() { + if ($isInternalLink.is(':checked')) { + $menuItemControllerContainer.show(); + } + else { + $menuItemControllerContainer.hide(); + } + } + function handleIsDisabled() { if ($isDisabled.is(':checked')) { $isLandingPageContainer.hide(); @@ -33,9 +44,11 @@ $isDisabled.change(handleIsDisabled); $menuPosition.change(handleMenuPosition); + $('input[name=isInternalLink]').change(handleIsInternalLink); handleIsDisabled(); handleMenuPosition(); + handleIsInternalLink(); }); //]]> @@ -124,11 +137,39 @@ {include file='multipleLanguageInputJavascript' elementIdentifier='pageMenuItem' forceSelection=true} + + +
+ {lang}wcf.acp.pageMenu.link{/lang} + +
+
+ + +
+
+ +
- + {if $errorField == 'menuItemLink'} {if $errorType == 'empty'} @@ -156,7 +197,7 @@
- +
diff --git a/wcfsetup/install/files/lib/acp/form/PageMenuItemAddForm.class.php b/wcfsetup/install/files/lib/acp/form/PageMenuItemAddForm.class.php index f09be1b422..43bbc1a704 100644 --- a/wcfsetup/install/files/lib/acp/form/PageMenuItemAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageMenuItemAddForm.class.php @@ -36,12 +36,24 @@ class PageMenuItemAddForm extends ACPForm { */ public $isDisabled = false; + /** + * internal link + * @var boolean + */ + public $isInternalLink = false; + /** * true, if menu item is landing page * @var boolean */ public $isLandingPage = false; + /** + * menu item controller + * @var string + */ + public $menuItemController = ''; + /** * menu item link * @var string @@ -124,7 +136,9 @@ class PageMenuItemAddForm extends ACPForm { if (I18nHandler::getInstance()->isPlainValue('pageMenuItem')) $this->pageMenuItem = I18nHandler::getInstance()->getValue('pageMenuItem'); if (isset($_POST['isDisabled'])) $this->isDisabled = true; + if (isset($_POST['isInternalLink'])) $this->isInternalLink = (bool) $_POST['isInternalLink']; if (isset($_POST['isLandingPage'])) $this->isLandingPage = true; + if (isset($_POST['menuItemController'])) $this->menuItemController = StringUtil::trim($_POST['menuItemController']); if (isset($_POST['menuPosition'])) $this->menuPosition = StringUtil::trim($_POST['menuPosition']); if (isset($_POST['newWindow'])) $this->newWindow = true; if (isset($_POST['parentMenuItem'])) $this->parentMenuItem = StringUtil::trim($_POST['parentMenuItem']); @@ -145,9 +159,28 @@ class PageMenuItemAddForm extends ACPForm { throw new UserInputException('menuPosition', 'notValid'); } - // validate menu item link - if (!I18nHandler::getInstance()->validateValue('menuItemLink')) { - throw new UserInputException('menuItemLink'); + // validate menu item controller + if ($this->isInternalLink) { + if (empty($this->menuItemController)) { + throw new UserInputException('menuItemController'); + } + + if (!class_exists($this->menuItemController)) { + throw new UserInputException('menuItemController', 'notValid'); + } + + // validate menu item link + if (!I18nHandler::getInstance()->validateValue('menuItemLink', false, true)) { + throw new UserInputException('menuItemLink'); + } + } + else { + $this->menuItemController = ''; + + // validate menu item link + if (!I18nHandler::getInstance()->validateValue('menuItemLink')) { + throw new UserInputException('menuItemLink'); + } } // validate page menu item name @@ -192,6 +225,7 @@ class PageMenuItemAddForm extends ACPForm { 'isDisabled' => ($this->isDisabled) ? 1 : 0, 'isLandingPage' => ($this->isLandingPage) ? 1 : 0, 'menuItem' => $this->pageMenuItem, + 'menuItemController' => $this->menuItemController, 'menuItemLink' => $this->menuItemLink, 'menuPosition' => $this->menuPosition, 'newWindow' => ($this->newWindow) ? 1 : 0, @@ -223,9 +257,9 @@ class PageMenuItemAddForm extends ACPForm { WCF::getTPL()->assign('success', true); // reset variables - $this->isDisabled = $this->isLandingPage = $this->newWindow = false; + $this->isDisabled = $this->isInternalLink = $this->isLandingPage = $this->newWindow = false; $this->menuPosition = 'header'; - $this->menuItemLink = $this->pageMenuItem = $this->parentMenuItem = ''; + $this->menuItemController = $this->menuItemLink = $this->pageMenuItem = $this->parentMenuItem = ''; $this->showOrder = 0; // reload parent menu items @@ -246,7 +280,9 @@ class PageMenuItemAddForm extends ACPForm { 'action' => 'add', 'availableParentMenuItems' => $this->availableParentMenuItems, 'isDisabled' => $this->isDisabled, + 'isInternalLink' => $this->isInternalLink, 'isLandingPage' => $this->isLandingPage, + 'menuItemController' => $this->menuItemController, 'menuItemLink' => $this->menuItemLink, 'menuPosition' => $this->menuPosition, 'newWindow' => $this->newWindow, diff --git a/wcfsetup/install/files/lib/acp/form/PageMenuItemEditForm.class.php b/wcfsetup/install/files/lib/acp/form/PageMenuItemEditForm.class.php index 52127b9eb0..5893bd2663 100644 --- a/wcfsetup/install/files/lib/acp/form/PageMenuItemEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageMenuItemEditForm.class.php @@ -68,7 +68,10 @@ class PageMenuItemEditForm extends PageMenuItemAddForm { if (empty($_POST)) { $this->isDisabled = ($this->menuItem->isDisabled) ? true : false; + $this->isInternalLink = ($this->menuItem->menuItemController) ? true : false; $this->isLandingPage = ($this->menuItem->isLandingPage) ? true : false; + $this->menuItemController = $this->menuItem->menuItemController; + $this->menuItemLink = $this->menuItem->menuItemLink; $this->menuPosition = $this->menuItem->menuPosition; $this->newWindow = ($this->menuItem->newWindow) ? true : false; $this->pageMenuItem = $this->menuItem->menuItem; @@ -100,6 +103,7 @@ class PageMenuItemEditForm extends PageMenuItemAddForm { $this->objectAction = new PageMenuItemAction(array($this->menuItem), 'update', array('data' => array( 'isDisabled' => ($this->isDisabled) ? 1 : 0, 'isLandingPage' => ($this->isLandingPage) ? 1 : 0, + 'menuItemController' => $this->menuItemController, 'menuItemLink' => $this->menuItemLink, 'newWindow' => ($this->newWindow) ? 1 : 0, 'parentMenuItem' => ($this->menuItem->menuPosition == 'header' ? $this->parentMenuItem : ''), diff --git a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php index 9a477ad7ec..1a6eb697aa 100644 --- a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php +++ b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php @@ -49,7 +49,7 @@ class PageMenuItem extends ProcessibleDatabaseObject implements ITreeMenuItem { */ public function getLink() { // external link - if ($this->menuItemController === null) { + if (!$this->menuItemController) { return WCF::getLanguage()->get($this->menuItemLink); } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 9b0e58ec3e..a22e993d74 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -421,12 +421,19 @@ + + + + + + + -- 2.20.1