From 89c8c8fd73bb83f8ad8d8dabb125020170480dea Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 18 Nov 2011 23:15:12 +0100 Subject: [PATCH] Modified user options to support output type That was a joke, fat chance. User options are completely messed up now :/ --- .../files/lib/data/option/Option.class.php | 9 ++++- .../lib/data/user/option/UserOption.class.php | 35 ++++++++++++++---- .../lib/system/option/OptionHandler.class.php | 37 +++++++++++++++---- .../option/user/UserOptionHandler.class.php | 15 ++++++++ 4 files changed, 80 insertions(+), 16 deletions(-) diff --git a/wcfsetup/install/files/lib/data/option/Option.class.php b/wcfsetup/install/files/lib/data/option/Option.class.php index 7cc1277fd5..0620e69d9f 100644 --- a/wcfsetup/install/files/lib/data/option/Option.class.php +++ b/wcfsetup/install/files/lib/data/option/Option.class.php @@ -26,11 +26,16 @@ class Option extends DatabaseObject { */ protected static $databaseTableIndexName = 'optionID'; + // equals to an empty bitmask, NOT a valid bit! const VISIBILITY_NONE = 0; + const VISIBILITY_OWNER = 1; const VISIBILITY_ADMINISTRATOR = 2; - const VISIBILITY_OTHER = 4; - const VISIBILITY_ALL = 7; + const VISIBILITY_REGISTERED = 4; + const VISIBILITY_GUEST = 8; + + // equals to VISIBILITY_GUEST, NOT a valid bit! + const VISIBILITY_ALL = 15; /** * @see wcf\data\DatabaseObject::handleData() diff --git a/wcfsetup/install/files/lib/data/user/option/UserOption.class.php b/wcfsetup/install/files/lib/data/user/option/UserOption.class.php index ce9732206a..306857a716 100644 --- a/wcfsetup/install/files/lib/data/user/option/UserOption.class.php +++ b/wcfsetup/install/files/lib/data/user/option/UserOption.class.php @@ -1,7 +1,9 @@ user = $user; + } + /** * @see wcf\data\option\Option::isVisible() */ public function isVisible() { - $bitmask = $this->options[$optionName]->visible; // check if option is hidden - if ($bitmask & Option::VISIBILITY_NONE) { - $visible = false; + if (!$this->visible) { + return false; } + // proceed if option is visible for all - else if ($bitmask & Option::VISIBILITY_OTHER) { + if ($this->visible & Option::VISIBILITY_GUEST) { + $visible = true; + } + // proceed if option is visible for registered users and current user is logged in + else if (($this->visible & Option::VISIBILITY_REGISTERED) && WCF::getUser()->userID) { $visible = true; } else { $isAdmin = $isOwner = $visible = false; // check admin permissions - if ($bitmask & Option::VISIBILITY_ADMINISTRATOR) { + if ($this->visible & Option::VISIBILITY_ADMINISTRATOR) { if (WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) { $isAdmin = true; } } // check owner state - if ($bitmask & Option::VISIBILITY_OWNER) { - if ($user->userID == WCF::getUser()->userID) { + if ($this->visible & Option::VISIBILITY_OWNER) { + if ($this->user->userID == WCF::getUser()->userID) { $isOwner = true; } } diff --git a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php index 652fb3beb4..5ca9d1293c 100644 --- a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php @@ -54,7 +54,7 @@ class OptionHandler implements IOptionHandler { * option structure * @var array */ - protected $cachedOptionToCategories = null; + public $cachedOptionToCategories = null; /** * Name of the active option category. @@ -98,10 +98,16 @@ class OptionHandler implements IOptionHandler { */ public $supportI18n = false; + /** + * cache initialization state + * @var boolean + */ + public $didInit = false; + /** * @see wcf\system\option\IOptionHandler::__construct() */ - public function __construct($cacheName, $cacheClass, $supportI18n, $languageItemPattern = '', $categoryName = '') { + public function __construct($cacheName, $cacheClass, $supportI18n, $languageItemPattern = '', $categoryName = '', $loadActiveOptions = true) { $this->cacheName = $cacheName; $this->cacheClass = $cacheClass; $this->categoryName = $categoryName; @@ -109,7 +115,7 @@ class OptionHandler implements IOptionHandler { $this->supportI18n = $supportI18n; // load cache on init - $this->readCache(); + $this->readCache($loadActiveOptions); } /** @@ -334,8 +340,10 @@ class OptionHandler implements IOptionHandler { /** * Gets all options and option categories from cache. + * + * @param boolean $loadActiveOptions */ - protected function readCache() { + protected function readCache($loadActiveOptions) { $cacheName = $this->cacheName . '-' . PACKAGE_ID; CacheHandler::getInstance()->addResource($cacheName, WCF_DIR.'cache/cache.'.$cacheName.'.php', $this->cacheClass); @@ -345,8 +353,13 @@ class OptionHandler implements IOptionHandler { $this->cachedCategoryStructure = CacheHandler::getInstance()->get($cacheName, 'categoryStructure'); $this->cachedOptionToCategories = CacheHandler::getInstance()->get($cacheName, 'optionToCategories'); - // get active options - $this->loadActiveOptions($this->categoryName); + if ($loadActiveOptions) { + // get active options + $this->loadActiveOptions($this->categoryName); + + // mark options as initialized + $this->didInit = true; + } } /** @@ -443,10 +456,20 @@ class OptionHandler implements IOptionHandler { if (!$hasEnabledOption) return false; } - if (!$option->isVisible()) { + if (!$this->checkVisibility($option)) { return false; } return true; } + + /** + * Checks visibility of an option. + * + * @param wcf\data\option\Option $option + * @return boolean + */ + protected function checkVisibility(Option $option) { + return $option->isVisible(); + } } diff --git a/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php b/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php index eb21035a39..62c7502547 100644 --- a/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php @@ -37,6 +37,12 @@ class UserOptionHandler extends OptionHandler { $userOption = 'userOption' . $option->optionID; $this->optionValues[$option->optionName] = $this->user->{$userOption}; } + + if (!$this->didInit) { + $this->loadActiveOptions($this->categoryName); + + $this->didInit = true; + } } /** @@ -69,4 +75,13 @@ class UserOptionHandler extends OptionHandler { return parent::checkCategory($category); } + + /** + * @see wcf\system\option\OptionHandler::checkVisibility() + */ + protected function checkVisibility(Option $option) { + $option->setUser($this->user); + + return $option->isVisible(); + } } -- 2.20.1