From a8a69eaaa917f1547289607b0bf29685a0fcae9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 17 Dec 2011 18:40:20 +0100 Subject: [PATCH 1/3] Encoded the chars in ChatUtil::gradient() --- file/lib/util/ChatUtil.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file/lib/util/ChatUtil.class.php b/file/lib/util/ChatUtil.class.php index 9f8c5b8..85cddc2 100644 --- a/file/lib/util/ChatUtil.class.php +++ b/file/lib/util/ChatUtil.class.php @@ -39,7 +39,7 @@ public static function gradient($string, $start, $end) { $result = ''; for ($i = 0, $max = count($string); $i < $max; $i++) { - $result .= ''.$string[$i].''; + $result .= ''.StringUtil::encodeHTML($string[$i]).''; } return $result; From 7076988c02ca804f003bd62630e37a3ed8010d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 19 Dec 2011 16:14:27 +0100 Subject: [PATCH 2/3] Shortcut :) --- file/lib/page/ChatPage.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file/lib/page/ChatPage.class.php b/file/lib/page/ChatPage.class.php index 9f92903..0948afa 100644 --- a/file/lib/page/ChatPage.class.php +++ b/file/lib/page/ChatPage.class.php @@ -130,7 +130,7 @@ public function readRoom() { // redirect to first chat-room $this->rooms->seek(0); \wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array( - 'object' => $this->rooms->search($this->rooms->key()) + 'object' => $this->rooms->current() ))); exit; } From 80daee9c463283f73f3e1fa58c207fd2f2f86b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 19 Dec 2011 16:22:56 +0100 Subject: [PATCH 3/3] Adding Permission-Handler for ACL --- file/lib/data/chat/room/ChatRoom.class.php | 9 +++ .../ChatPermissionHandler.class.php | 81 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 file/lib/system/chat/permissions/ChatPermissionHandler.class.php diff --git a/file/lib/data/chat/room/ChatRoom.class.php b/file/lib/data/chat/room/ChatRoom.class.php index d167a49..565d8ba 100644 --- a/file/lib/data/chat/room/ChatRoom.class.php +++ b/file/lib/data/chat/room/ChatRoom.class.php @@ -69,4 +69,13 @@ public function getTitle() { public function getID() { return $this->roomID; } + + /** + * Returns whether the user is allowed to enter the room + * + * @return boolean + */ + public function canEnter() { + return \wcf\system\chat\permissions\ChatPermissionHandler::getInstance()->getPermission($this, 'canEnter'); + } } diff --git a/file/lib/system/chat/permissions/ChatPermissionHandler.class.php b/file/lib/system/chat/permissions/ChatPermissionHandler.class.php new file mode 100644 index 0000000..c8ef28e --- /dev/null +++ b/file/lib/system/chat/permissions/ChatPermissionHandler.class.php @@ -0,0 +1,81 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.permissions + */ +class ChatPermissionHandler extends \wcf\system\SingletonFactory { + protected $chatPermissions = array(); + + /** + * @see wcf\system\SingletonFactory::init() + */ + protected function init() { + $packageID = PackageDependencyHandler::getPackageID('timwolla.wcf.chat'); + $ush = \wcf\system\user\storage\UserStorageHandler::getInstance(); + // TODO: get groups permissions + + // get user permissions + if (WCF::getUser()->userID) { + // get data from storage + $ush->loadStorage(array(WCF::getUser()->userID), $packageID); + + // get ids + $data = $ush->getStorage(array(WCF::getUser()->userID), 'chatUserPermissions', $packageID); + + // cache does not exist or is outdated + if ($data[WCF::getUser()->userID] === null) { + $userPermissions = array(); + + $conditionBuilder = new \wcf\system\database\util\PreparedStatementConditionBuilder(); + $conditionBuilder->add('acl_option.packageID IN (?)', array(PackageDependencyHandler::getDependencies())); + $conditionBuilder->add('acl_option.objectTypeID = ?', array(ACLHandler::getInstance()->getObjectTypeID('timwolla.wcf.chat.room'))); + $conditionBuilder->add('option_to_user.optionID = acl_option.optionID'); + $conditionBuilder->add('option_to_user.userID = ?', array(WCF::getUser()->userID)); + $sql = "SELECT option_to_user.objectID AS roomID, option_to_user.optionValue, + acl_option.optionName AS permission + FROM wcf".WCF_N."_acl_option acl_option, + wcf".WCF_N."_acl_option_to_user option_to_user + ".$conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + while ($row = $statement->fetchArray()) { + $userPermissions[$row['roomID']][$row['permission']] = $row['optionValue']; + } + + // update cache + $ush->update(WCF::getUser()->userID, 'chatUserPermissions', serialize($userPermissions), $packageID); + } + else { + $userPermissions = unserialize($data[WCF::getUser()->userID]); + } + + foreach ($userPermissions as $roomID => $permissions) { + foreach ($permissions as $name => $value) { + $this->chatPermissions[$roomID][$name] = $value; + } + } + } + } + + /** + * Fetches the given permission for the given room + * + * @param \wcf\data\chat\room\ChatRoom $room + * @param string $permission + * @return boolean + */ + public function getPermission(\wcf\data\chat\room\ChatRoom $room, $permission) { + if (!isset($this->chatPermissions[$room->roomID][$permission])) return true; + return (boolean) $this->chatPermissions[$room->roomID][$permission]; + } +} \ No newline at end of file