<controller>wcf\page\DashboardPage</controller>
<name language="de"><![CDATA[Dashboard]]></name>
<name language="en"><![CDATA[Dashboard]]></name>
+ <options>module_dashboard_page</options>
</page>
<page identifier="com.woltlab.wcf.MembersList">
<controller>wcf\page\MembersListPage</controller>
<name language="de"><![CDATA[Mitglieder]]></name>
<name language="en"><![CDATA[Members]]></name>
+ <permissions>user.profile.canViewMembersList</permissions>
+ <options>module_members_list</options>
</page>
<page identifier="com.woltlab.wcf.RecentActivityList">
<controller>wcf\page\RecentActivityListPage</controller>
<name language="de"><![CDATA[Benutzer Online]]></name>
<name language="en"><![CDATA[Users Online]]></name>
<parent>com.woltlab.wcf.MembersList</parent>
+ <permissions>user.profile.canViewUsersOnlineList</permissions>
+ <options>module_users_online</options>
</page>
<page identifier="com.woltlab.wcf.Team">
<controller>wcf\page\TeamPage</controller>
<name language="de"><![CDATA[Team]]></name>
<name language="en"><![CDATA[Team]]></name>
<parent>com.woltlab.wcf.MembersList</parent>
+ <permissions>user.profile.canViewMembersList</permissions>
+ <options>module_team_page</options>
</page>
<page identifier="com.woltlab.wcf.UserSearch">
<controller>wcf\page\UserSearchForm</controller>
<name language="de"><![CDATA[Benutzer suchen]]></name>
<name language="en"><![CDATA[Search Users]]></name>
<parent>com.woltlab.wcf.MembersList</parent>
+ <permissions>user.profile.canViewMembersList</permissions>
+ <options>module_members_list</options>
</page>
<!-- static -->
<page identifier="com.woltlab.wcf.PrivacyPolicy">
<name language="en">Privacy Policy</name>
<name language="de">Datenschutzerklärung</name>
+ <options>module_privacy_policy_page</options>
<content language="en">
<title>Privacy Policy</title>
* @return boolean
*/
public function hasContent() {
- return true; // @todo
- //return count(MenuCache::getInstance()->getMenuItemsByMenuID($this->menuID)->getNodeList());
+ return $this->getMenuItemNodeTree()->getVisibleItemCount() > 0;
}
/**
}
/**
- * @return MenuItemNodeTree
+ * @return MenuItemNodeTree
*/
protected function getMenuItemNodeTree() {
if ($this->menuItemNodeTree === null) {
/**
* Returns the page that is linked by this menu item.
*
- * @return Page
+ * @return Page|null
*/
public function getPage() {
- if ($this->page === null) {
- if ($this->pageID) {
- $this->page = new Page($this->pageID);
- }
+ if ($this->page === null && $this->pageID) {
+ $this->page = new Page($this->pageID);
}
return $this->page;
* @return boolean
*/
public function isVisible() {
+ if ($this->getPage() !== null && !$this->getPage()->isVisible()) {
+ return false;
+ }
+
if ($this->getMenuPageHandler() !== null) {
return $this->getMenuPageHandler()->isVisible($this->pageObjectID ?: null);
}
}
/**
- * @return IMenuPageHandler
+ * @return IMenuPageHandler|null
*/
protected function getMenuPageHandler() {
$page = $this->getPage();
*/
public $node;
+ /**
+ * number of visible items
+ * @var integer
+ */
+ protected $visibleItemCount = 0;
+
/**
* Creates a new MenuItemNodeTree object.
*
$menuItemList->readObjects();
}
+ // build menu structure
foreach ($menuItemList as $menuItem) {
$this->menuItems[$menuItem->itemID] = $menuItem;
$this->menuItemStructure[$menuItem->parentItemID][] = $menuItem->itemID;
}
- // filter items by visibility
- foreach ($this->menuItems as $menuItemID => $menuItem) {
- if (!$menuItem->isVisible()) {
- unset($this->menuItems[$menuItemID]);
- unset($this->menuItemStructure[$menuItemID]);
-
- // remove item from parent item structure
- $key = array_search($menuItemID, $this->menuItemStructure[$menuItem->parentItemID]);
- array_splice($this->menuItemStructure[$menuItem->parentItemID], $key, 1);
- }
- }
-
// generate node tree
$this->node = new MenuItemNode();
$this->node->setChildren($this->generateNodeTree(null, $this->node));
}
/**
- * Generates the node tree recursively
+ * Generates the node tree recursively.
*
* @param integer $parentID parent menu item id
* @param MenuItemNode $parentNode parent menu item object
$itemIDs = (isset($this->menuItemStructure[$parentID]) ? $this->menuItemStructure[$parentID] : []);
foreach ($itemIDs as $itemID) {
$menuItem = $this->menuItems[$itemID];
+ if (!$menuItem->isVisible()) continue;
$node = new MenuItemNode($parentNode, $menuItem, ($parentNode !== null ? ($parentNode->getDepth() + 1) : 0));
$nodes[] = $node;
// get children
$node->setChildren($this->generateNodeTree($itemID, $node));
+
+ // increase item counter
+ $this->visibleItemCount++;
}
return $nodes;
}
/**
- * Returns the iteratable node list
+ * Returns the iteratable node list.
*
* @return \RecursiveIteratorIterator
*/
public function getNodeList() {
return new \RecursiveIteratorIterator($this->node, \RecursiveIteratorIterator::SELF_FIRST);
}
+
+ /**
+ * Returns the number of visible items.
+ *
+ * @return integer
+ */
+ public function getVisibleItemCount() {
+ return $this->visibleItemCount;
+ }
}
return $this->pageHandler;
}
+ /**
+ * Returns false if this page should be hidden from menus, but does not control the accessibility
+ * of the page itself.
+ *
+ * @return boolean false if the page should be hidden from menus
+ */
+ public function isVisible() {
+ // check the options of this page
+ $hasEnabledOption = true;
+ if ($this->options) {
+ $hasEnabledOption = false;
+ $options = explode(',', strtoupper($this->options));
+ foreach ($options as $option) {
+ if (defined($option) && constant($option)) {
+ $hasEnabledOption = true;
+ break;
+ }
+ }
+ }
+ if (!$hasEnabledOption) return false;
+
+ // check the permission of this page for the active user
+ $hasPermission = true;
+ if ($this->permissions) {
+ $hasPermission = false;
+ $permissions = explode(',', $this->permissions);
+ foreach ($permissions as $permission) {
+ if (WCF::getSession()->getPermission($permission)) {
+ $hasPermission = true;
+ break;
+ }
+ }
+ }
+ if (!$hasPermission) return false;
+
+ return true;
+ }
+
/**
* Returns the page's internal name.
*
'name' => $name,
'originIsSystem' => 1,
'parentPageID' => $parentPageID,
- 'requireObjectID' => (!empty($data['elements']['requireObjectID'])) ? 1 : 0
+ 'requireObjectID' => (!empty($data['elements']['requireObjectID'])) ? 1 : 0,
+ 'options' => (isset($data['elements']['options'])) ? $data['elements']['options'] : '',
+ 'permissions' => (isset($data['elements']['permissions'])) ? $data['elements']['permissions'] : ''
];
}
handler VARCHAR(255) NOT NULL DEFAULT '',
controllerCustomURL VARCHAR(255) NOT NULL DEFAULT '',
requireObjectID TINYINT(1) NOT NULL DEFAULT 0,
- lastUpdateTime INT(10) NOT NULL DEFAULT 0
+ lastUpdateTime INT(10) NOT NULL DEFAULT 0,
+ permissions TEXT NULL,
+ options TEXT NULL
);
DROP TABLE IF EXISTS wcf1_page_content;