namespace wcf\data\sitemap;
use wcf\data\DatabaseObject;
use wcf\system\exception\SystemException;
+use wcf\system\WCF;
use wcf\util\ClassUtil;
/**
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;
+ }
}
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'] : ''
);
}
if (!empty($this->cache)) {
foreach ($this->cache as $sitemap) {
- $tree[] = $sitemap->sitemapName;
+ if ($sitemap->isAccessible()) $tree[] = $sitemap->sitemapName;
}
}
*/
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 '';
}
/**
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)
);