Added permissions/options for sitemap items
authorMarcel Werk <burntime@woltlab.com>
Fri, 23 May 2014 11:11:50 +0000 (13:11 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 23 May 2014 11:11:50 +0000 (13:11 +0200)
wcfsetup/install/files/lib/data/sitemap/Sitemap.class.php
wcfsetup/install/files/lib/system/package/plugin/SitemapPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/sitemap/SitemapHandler.class.php
wcfsetup/setup/db/install.sql

index 1c619831c3340eb66a0a55cf55bbaaee9a9a65b0..cc574c97c09bf9ddd196230fb235c09acc071abf 100644 (file)
@@ -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;
+       }
 }
index 67cb80ec54efd566da25199669fd1617ff506b2f..c0f79b74f323aafd7b1a7d393168ccf73022f6a4 100644 (file)
@@ -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'] : ''
                );
        }
        
index 00a0764212607342067fc502ba04ce021e6b353c..e1d0168c84d38b8176066519f98ac988e1ed0786 100644 (file)
@@ -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 '';
        }
        
        /**
index 3a52154bc9c626188faa5a4bb45d1d8ada1fce6a..0745050ef6802dfb4bbcb8ad0034e0f0711b9df7 100644 (file)
@@ -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)
 );