From a3e0f4f37702d07f621a7bb0f4918328cf9e1ef5 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 23 May 2014 13:11:50 +0200 Subject: [PATCH] Added permissions/options for sitemap items --- .../files/lib/data/sitemap/Sitemap.class.php | 38 +++++++++++++++++++ ...SitemapPackageInstallationPlugin.class.php | 4 +- .../system/sitemap/SitemapHandler.class.php | 13 +++---- wcfsetup/setup/db/install.sql | 2 + 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/lib/data/sitemap/Sitemap.class.php b/wcfsetup/install/files/lib/data/sitemap/Sitemap.class.php index 1c619831c3..cc574c97c0 100644 --- a/wcfsetup/install/files/lib/data/sitemap/Sitemap.class.php +++ b/wcfsetup/install/files/lib/data/sitemap/Sitemap.class.php @@ -2,6 +2,7 @@ namespace wcf\data\sitemap; use wcf\data\DatabaseObject; use wcf\system\exception\SystemException; +use wcf\system\WCF; use wcf\util\ClassUtil; /** @@ -52,4 +53,41 @@ class Sitemap extends DatabaseObject { return $this->sitemapObj->getTemplate(); } + + /** + * Returns true, if the active user has access to this sitemap. + * + * @return boolean + */ + public function isAccessible() { + // check the options of this item + $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 item 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; + } } diff --git a/wcfsetup/install/files/lib/system/package/plugin/SitemapPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/SitemapPackageInstallationPlugin.class.php index 67cb80ec54..c0f79b74f3 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/SitemapPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/SitemapPackageInstallationPlugin.class.php @@ -45,7 +45,9 @@ class SitemapPackageInstallationPlugin extends AbstractXMLPackageInstallationPlu return array( 'sitemapName' => $data['attributes']['name'], 'className' => $data['elements']['classname'], - 'showOrder' => $showOrder + 'showOrder' => $showOrder, + 'options' => (isset($data['elements']['options'])) ? $data['elements']['options'] : '', + 'permissions' => (isset($data['elements']['permissions'])) ? $data['elements']['permissions'] : '' ); } diff --git a/wcfsetup/install/files/lib/system/sitemap/SitemapHandler.class.php b/wcfsetup/install/files/lib/system/sitemap/SitemapHandler.class.php index 00a0764212..e1d0168c84 100644 --- a/wcfsetup/install/files/lib/system/sitemap/SitemapHandler.class.php +++ b/wcfsetup/install/files/lib/system/sitemap/SitemapHandler.class.php @@ -38,7 +38,7 @@ class SitemapHandler extends SingletonFactory { if (!empty($this->cache)) { foreach ($this->cache as $sitemap) { - $tree[] = $sitemap->sitemapName; + if ($sitemap->isAccessible()) $tree[] = $sitemap->sitemapName; } } @@ -52,17 +52,16 @@ class SitemapHandler extends SingletonFactory { */ public function getDefaultSitemapName() { foreach ($this->cache as $sitemap) { - if ($sitemap->packageID == PACKAGE_ID) { - $sitemapName = $sitemap->sitemapName; + if ($sitemap->packageID == PACKAGE_ID && $sitemap->isAccessible()) { + return $sitemap->sitemapName; } } - if (empty($sitemapName)) { - $sitemap = reset($this->cache); - $sitemapName = $sitemap->sitemapName; + foreach ($this->cache as $sitemap) { + if ($sitemap->isAccessible()) return $sitemap->sitemapName; } - return $sitemapName; + return ''; } /** diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 3a52154bc9..0745050ef6 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -837,6 +837,8 @@ CREATE TABLE wcf1_sitemap ( sitemapName VARCHAR(80) NOT NULL DEFAULT '', className VARCHAR(255) NOT NULL DEFAULT '', showOrder INT(10) NOT NULL DEFAULT 0, + permissions TEXT NULL, + options TEXT NULL, UNIQUE KEY sitemapName (packageID, sitemapName) ); -- 2.20.1