From 72604b0d73f0f9212e12b6ac2f9d75557dd04bae Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 4 Jan 2016 15:46:52 +0100 Subject: [PATCH] Added initial support for page handlers (WIP) --- .../lib/data/menu/item/MenuItemNode.class.php | 20 +++++------ .../PagePackageInstallationPlugin.class.php | 13 ++++---- .../AbstractLookupPageHandler.class.php | 26 +++++++++++++++ .../handler/AbstractMenuPageHandler.class.php | 32 ++++++++++++++++++ .../page/handler/ILookupPageHandler.class.php | 25 ++++++++++++++ .../page/handler/IMenuPageHandler.class.php | 33 +++++++++++++++++++ wcfsetup/setup/db/install.sql | 1 + 7 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/page/handler/AbstractLookupPageHandler.class.php create mode 100644 wcfsetup/install/files/lib/system/page/handler/AbstractMenuPageHandler.class.php create mode 100644 wcfsetup/install/files/lib/system/page/handler/ILookupPageHandler.class.php create mode 100644 wcfsetup/install/files/lib/system/page/handler/IMenuPageHandler.class.php diff --git a/wcfsetup/install/files/lib/data/menu/item/MenuItemNode.class.php b/wcfsetup/install/files/lib/data/menu/item/MenuItemNode.class.php index e8a1b51529..db8fd5f7fb 100644 --- a/wcfsetup/install/files/lib/data/menu/item/MenuItemNode.class.php +++ b/wcfsetup/install/files/lib/data/menu/item/MenuItemNode.class.php @@ -14,28 +14,28 @@ namespace wcf\data\menu\item; */ class MenuItemNode implements \Countable, \RecursiveIterator { /** - * parent node - * @var MenuItemNode + * children of this node + * @var MenuItemNode[] */ - protected $parentNode = null; + protected $children = []; /** - * children of this node - * @var MenuItemNode[] + * node depth + * @var integer */ - protected $children = array(); + protected $depth = 0; /** * menu item object * @var MenuItem */ - protected $menuItem = null; + protected $menuItem; /** - * node depth - * @var integer + * parent node + * @var MenuItemNode */ - protected $depth = 0; + protected $parentNode; /** * iterator position diff --git a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php index 13b4800fa9..196ea40097 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php @@ -11,7 +11,7 @@ use wcf\util\StringUtil; * Installs, updates and deletes CMS pages. * * @author Alexander Ebert - * @copyright 2001-2015 WoltLab GmbH + * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage acp.package.plugin @@ -147,6 +147,7 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin return [ 'content' => ($isStatic) ? $data['elements']['content'] : [], 'controller' => ($isStatic) ? '' : $data['elements']['controller'], + 'handler' => (!$isStatic && !empty($data['elements']['handler'])) ? $data['elements']['handler'] : '', 'controllerCustomURL' => $customUrl, 'identifier' => $data['attributes']['identifier'], 'isMultilingual' => ($isStatic) ? 1 : 0, @@ -165,15 +166,15 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin FROM wcf".WCF_N."_".$this->tableName." WHERE identifier = ? AND packageID = ?"; - $parameters = array( + $parameters = [ $data['identifier'], $this->installation->getPackageID() - ); + ]; - return array( + return [ 'sql' => $sql, 'parameters' => $parameters - ); + ]; } /** @@ -190,7 +191,7 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin $object = parent::import($row, ['controller' => $data['controller']]); } else { - $baseClass = call_user_func(array($this->className, 'getBaseClass')); + $baseClass = call_user_func([$this->className, 'getBaseClass']); $object = new $baseClass(null, $row); } } diff --git a/wcfsetup/install/files/lib/system/page/handler/AbstractLookupPageHandler.class.php b/wcfsetup/install/files/lib/system/page/handler/AbstractLookupPageHandler.class.php new file mode 100644 index 0000000000..d077291f91 --- /dev/null +++ b/wcfsetup/install/files/lib/system/page/handler/AbstractLookupPageHandler.class.php @@ -0,0 +1,26 @@ + + * @package com.woltlab.wcf + * @subpackage system.page.handler + * @category Community Framework + * @since 2.2 + */ +abstract class AbstractLookupPageHandler implements ILookupPageHandler { + /** + * @inheritDoc + */ + public function lookup($searchString) { + return []; + } +} diff --git a/wcfsetup/install/files/lib/system/page/handler/AbstractMenuPageHandler.class.php b/wcfsetup/install/files/lib/system/page/handler/AbstractMenuPageHandler.class.php new file mode 100644 index 0000000000..ac7c4abdc9 --- /dev/null +++ b/wcfsetup/install/files/lib/system/page/handler/AbstractMenuPageHandler.class.php @@ -0,0 +1,32 @@ + + * @package com.woltlab.wcf + * @subpackage system.page.handler + * @category Community Framework + * @since 2.2 + */ +abstract class AbstractMenuPageHandler implements IMenuPageHandler{ + /** + * @inheritDoc + */ + public function getOutstandingItemCount($objectID = null) { + return 0; + } + + /** + * @inheritDoc + */ + public function isVisible($objectID = null) { + return true; + } +} diff --git a/wcfsetup/install/files/lib/system/page/handler/ILookupPageHandler.class.php b/wcfsetup/install/files/lib/system/page/handler/ILookupPageHandler.class.php new file mode 100644 index 0000000000..48976d04ac --- /dev/null +++ b/wcfsetup/install/files/lib/system/page/handler/ILookupPageHandler.class.php @@ -0,0 +1,25 @@ + + * @package com.woltlab.wcf + * @subpackage system.page.handler + * @category Community Framework + * @since 2.2 + */ +interface ILookupPageHandler extends IMenuPageHandler { + /** + * Performs a search for pages using a query string, returning an array containing + * an `objectID => title` relation. + * + * @param string $searchString search string + * @return string[] + */ + public function lookup($searchString); +} diff --git a/wcfsetup/install/files/lib/system/page/handler/IMenuPageHandler.class.php b/wcfsetup/install/files/lib/system/page/handler/IMenuPageHandler.class.php new file mode 100644 index 0000000000..c38d1fa9b5 --- /dev/null +++ b/wcfsetup/install/files/lib/system/page/handler/IMenuPageHandler.class.php @@ -0,0 +1,33 @@ + + * @package com.woltlab.wcf + * @subpackage system.page.handler + * @category Community Framework + * @since 2.2 + */ +interface IMenuPageHandler { + /** + * Returns the number of outstanding items for this page for display as a badge, optionally + * specifing a corresponding object id to limit the scope. + * + * @param integer $objectID optional page object id + * @return integer number of outstanding items + */ + public function getOutstandingItemCount($objectID = null); + + /** + * Returns false if this page should be hidden from menus, but does not control the accessibility + * of the page itself. The visibility can optionally be scoped to the given object id. + * + * @param integer $objectID optional page object id + * @return boolean false if the page should be hidden from menus + */ + public function isVisible($objectID = null); +} diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 5c2286ce66..f888d2332a 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -911,6 +911,7 @@ CREATE TABLE wcf1_page ( originIsSystem TINYINT(1) NOT NULL DEFAULT 0, packageID INT(10) NOT NULL, controller VARCHAR(255) NOT NULL DEFAULT '', + handler VARCHAR(255) NOT NULL DEFAULT '', controllerCustomURL VARCHAR(255) NOT NULL DEFAULT '', lastUpdateTime INT(10) NOT NULL DEFAULT 0 ); -- 2.20.1