diff --git a/acpMenu.xml b/acpMenu.xml
index 7717827..bb2e91e 100644
--- a/acpMenu.xml
+++ b/acpMenu.xml
@@ -22,5 +22,12 @@
{lang}chat.acp.suspension.list{/lang}
+
{lang}wcf.global.objectID{/lang} | +{lang}wcf.user.username{/lang} | +{lang}chat.general.room{/lang} | +{lang}chat.acp.suspension.type{/lang} | +{lang}chat.general.time{/lang} | +{lang}chat.general.expires{/lang} | +{lang}chat.acp.suspension.issuer{/lang} | +{lang}chat.acp.suspension.reason{/lang} | + + {event name='columnHeads'} +|
---|---|---|---|---|---|---|---|---|
+ + {event name='rowButtons'} + | +{#$suspension->suspensionID} | +{$suspension->username} | +{if $suspension->roomID}{$suspension->roomTitle|language}{else}{lang}chat.room.global{/lang}{/if} | +{lang}chat.suspension.{@$suspension->type}{/lang} | +{$suspension->time|plainTime} | +
+ {$suspension->expires|plainTime}{if $suspension->expires > TIME_NOW} ({$suspension->expires|dateDiff}){/if} + {if $suspension->revoker && $suspension->expires <= TIME_NOW}{lang}chat.acp.suspension.revokedBy{/lang} {/if} + |
+ {$suspension->issuerUsername} | +reason != $suspension->reason|truncate:30} class="jsTooltip" title="{$suspension->reason}"{/if}>{$suspension->reason|truncate:30} | + {event name='columns'} +
{lang}wcf.global.noItems{/lang}
+{/if} + + +{include file='footer'} diff --git a/file/lib/acp/page/ChatSuspensionListPage.class.php b/file/lib/acp/page/ChatSuspensionListPage.class.php new file mode 100644 index 0000000..94df1fb --- /dev/null +++ b/file/lib/acp/page/ChatSuspensionListPage.class.php @@ -0,0 +1,172 @@ + + * @package be.bastelstu.chat + * @subpackage acp.page + */ +class ChatSuspensionListPage extends \wcf\page\SortablePage { + /** + * @see \wcf\page\AbstractPage::$activeMenuItem + */ + public $activeMenuItem = 'chat.acp.menu.link.suspension.list'; + + /** + * @see \wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.chat.canManageSuspensions'); + + /** + * @see \wcf\page\SortablePage::$defaultSortField + */ + public $defaultSortField = 'expires'; + + /** + * @see \wcf\page\SortablePage::$validSortFields + */ + public $validSortFields = array('suspensionID', 'userID', 'username', 'roomID', 'type', 'expires', 'issuer', 'time', 'reason'); + + /** + * @see \wcf\page\MultipleLinkPage::$objectListClassName + */ + public $objectListClassName = 'chat\data\suspension\SuspensionList'; + + /** + * type filter + * + * @var integer + */ + public $filterSuspensionType = null; + + /** + * user filter + * + * @var integer + */ + public $filterUserID = null; + + /* + * username + * + * @var String + */ + public $filterUsername = null; + + /** + * issuer filter + * + * @var integer + */ + public $filterIssuerUserID = null; + + /* + * issuer username + * + * @var String + */ + public $filterIssuerUsername = null; + + /** + * room filter + * + * @var integer + */ + public $filterRoomID = null; + + /** + * display revoked suspensions + * + * @var integer + */ + public $displayRevoked = 0; + + /** + * @see \wcf\page\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + // get usernames + if (isset($_REQUEST['username']) && !empty($_REQUEST['username'])) $this->filterUsername = \wcf\util\StringUtil::trim($_REQUEST['username']); + if (isset($_REQUEST['issuerUsername']) && !empty($_REQUEST['issuerUsername'])) $this->filterIssuerUsername = \wcf\util\StringUtil::trim($_REQUEST['issuerUsername']); + + // get user IDs by username + if ($this->filterUsername != null) $this->filterUserID = \wcf\data\user\UserProfile::getUserProfileByUsername($this->filterUsername)->userID; + if ($this->filterIssuerUsername != null) $this->filterIssuerUserID = \wcf\data\user\UserProfile::getUserProfileByUsername($this->filterIssuerUsername)->userID; + + // get user IDs by request if no username was sent + if ($this->filterUserID === null && isset($_REQUEST['userID']) && !empty($_REQUEST['userID'])) $this->filterUserID = intval($_REQUEST['userID']); + if ($this->filterIssuerUserID === null && isset($_REQUEST['issuerUserID']) && !empty($_REQUEST['issuerUserID'])) $this->filterIssuerUserID = intval($_REQUEST['issuerUserID']); + + // get usernames by ID if no usernames were sent + if ($this->filterUsername === null) $this->filterUsername = \wcf\data\user\UserProfile::getUserProfile($this->filterUserID); + if ($this->filterIssuerUsername === null) $this->filterIssuerUsername = \wcf\data\user\UserProfile::getUserProfile($this->filterIssuerUserID); + + // get room IDs by request + if (isset($_REQUEST['roomID']) && $_REQUEST['roomID'] != -1) $this->filterRoomID = intval($_REQUEST['roomID']); + if (isset($_REQUEST['suspensionType']) && !empty($_REQUEST['suspensionType'])) $this->filterSuspensionType = intval($_REQUEST['suspensionType']); + + // display revoked + if (isset($_REQUEST['displayRevoked'])) $this->displayRevoked = intval($_REQUEST['displayRevoked']); + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'availableRooms' => \chat\data\room\RoomCache::getInstance()->getRooms(), + 'roomID' => ($this->filterRoomID !== null) ? $this->filterRoomID : -1, + 'username' => $this->filterUsername, + 'issuerUsername' => $this->filterIssuerUsername, + 'suspensionType' => $this->filterSuspensionType, + 'userID' => $this->filterUserID, + 'issuerUserID' => $this->filterIssuerUserID, + 'displayRevoked' => $this->displayRevoked + )); + } + + /** + * @see \wcf\page\MultipleLinkPage::readObjects() + */ + protected function initObjectList() { + parent::initObjectList(); + + $this->objectList->sqlSelects .= "user_table.username, user_table2.username AS issuerUsername, user_table3.username AS revokerUsername, room_table.title AS roomTitle"; + $this->objectList->sqlJoins .= " + LEFT JOIN wcf".WCF_N."_user user_table + ON suspension.userID = user_table.userID + LEFT JOIN wcf".WCF_N."_user user_table2 + ON suspension.issuer = user_table2.userID + LEFT JOIN wcf".WCF_N."_user user_table3 + ON suspension.issuer = user_table3.userID"; + $conditionJoins = " LEFT JOIN chat".WCF_N."_room room_table + ON suspension.roomID = room_table.roomID"; + $this->objectList->sqlConditionJoins .= $conditionJoins; + $this->objectList->sqlJoins .= $conditionJoins; + + if (!$this->displayRevoked) { + $this->objectList->getConditionBuilder()->add('expires > ?', array(TIME_NOW)); + } + $this->objectList->getConditionBuilder()->add('(room_table.permanent = ? OR suspension.roomID IS NULL)', array(1)); + if ($this->filterSuspensionType !== null) $this->objectList->getConditionBuilder()->add('suspension.type = ?', array($this->filterSuspensionType)); + if ($this->filterUserID !== null) $this->objectList->getConditionBuilder()->add('suspension.userID = ?', array($this->filterUserID)); + if ($this->filterIssuerUserID !== null) $this->objectList->getConditionBuilder()->add('suspension.issuer = ?', array($this->filterIssuerUserID)); + if ($this->filterRoomID !== null) { + if ($this->filterRoomID === 0) { + $this->objectList->getConditionBuilder()->add('suspension.roomID IS NULL', array()); + } + else { + $this->objectList->getConditionBuilder()->add('suspension.roomID = ?', array($this->filterRoomID)); + } + } + } +} diff --git a/file/lib/data/room/Room.class.php b/file/lib/data/room/Room.class.php index b60a844..87806ea 100644 --- a/file/lib/data/room/Room.class.php +++ b/file/lib/data/room/Room.class.php @@ -39,26 +39,33 @@ public function __toString() { public function canEnter(\wcf\data\user\User $user = null) { if ($user === null) $user = WCF::getUser(); if (!$user->userID) return false; + $user = new \wcf\data\user\UserProfile($user); - $ph = new \chat\system\permission\PermissionHandler($user); - $suspensions = Suspension::getSuspensionsForUser($user); + if ($user->getPermission('admin.chat.canManageSuspensions')) return true; + if ($user->getPermission('mod.chat.canGban')) return true; - $canEnter = $ph->getPermission($this, 'user.canEnter'); + $ph = new \chat\system\permission\PermissionHandler($user->getDecoratedObject()); + if ($ph->getPermission($this, 'mod.canAlwaysEnter')) return true; + if ($ph->getPermission($this, 'mod.canBan')) return true; + + if (!$ph->getPermission($this, 'user.canEnter')) return false; + + $suspensions = Suspension::getSuspensionsForUser($user->getDecoratedObject()); // room suspension - if ($canEnter && isset($suspensions[$this->roomID][Suspension::TYPE_BAN])) { + if (isset($suspensions[$this->roomID][Suspension::TYPE_BAN])) { if ($suspensions[$this->roomID][Suspension::TYPE_BAN]->isValid()) { - $canEnter = false; + return false; } } // global suspension - if ($canEnter && isset($suspensions[null][Suspension::TYPE_BAN])) { + if (isset($suspensions[null][Suspension::TYPE_BAN])) { if ($suspensions[null][Suspension::TYPE_BAN]->isValid()) { - $canEnter = false; + return false; } } - return $canEnter || $ph->getPermission($this, 'mod.canAlwaysEnter'); + return true; } /** @@ -70,26 +77,33 @@ public function canEnter(\wcf\data\user\User $user = null) { public function canWrite(\wcf\data\user\User $user = null) { if ($user === null) $user = WCF::getUser(); if (!$user->userID) return false; + $user = new \wcf\data\user\UserProfile($user); - $ph = new \chat\system\permission\PermissionHandler($user); - $suspensions = Suspension::getSuspensionsForUser($user); + if ($user->getPermission('admin.chat.canManageSuspensions')) return true; + if ($user->getPermission('mod.chat.canGmute')) return true; - $canWrite = $ph->getPermission($this, 'user.canWrite'); + $ph = new \chat\system\permission\PermissionHandler($user->getDecoratedObject()); + if ($ph->getPermission($this, 'mod.canAlwaysWrite')) return true; + if ($ph->getPermission($this, 'mod.canMute')) return true; + + if (!$ph->getPermission($this, 'user.canWrite')) return false; + + $suspensions = Suspension::getSuspensionsForUser($user->getDecoratedObject()); // room suspension - if ($canWrite && isset($suspensions[$this->roomID][Suspension::TYPE_MUTE])) { + if (isset($suspensions[$this->roomID][Suspension::TYPE_MUTE])) { if ($suspensions[$this->roomID][Suspension::TYPE_MUTE]->isValid()) { - $canWrite = false; + return false; } } // global suspension - if ($canWrite && isset($suspensions[null][Suspension::TYPE_MUTE])) { + if (isset($suspensions[null][Suspension::TYPE_MUTE])) { if ($suspensions[null][Suspension::TYPE_MUTE]->isValid()) { - $canWrite = false; + return false; } } - return $canWrite || $ph->getPermission($this, 'mod.canAlwaysWrite'); + return true; } /** diff --git a/file/lib/data/suspension/Suspension.class.php b/file/lib/data/suspension/Suspension.class.php index 3814807..75413b1 100644 --- a/file/lib/data/suspension/Suspension.class.php +++ b/file/lib/data/suspension/Suspension.class.php @@ -22,8 +22,8 @@ class Suspension extends \chat\data\CHATDatabaseObject { */ protected static $databaseTableIndexName = 'suspensionID'; - const TYPE_MUTE = 1; - const TYPE_BAN = 2; + const TYPE_MUTE = 'mute'; + const TYPE_BAN = 'ban'; /** * Returns whether the suspension still is valid. @@ -34,6 +34,36 @@ public function isValid() { return $this->expires > TIME_NOW; } + /** + * Returns whether the given user may view this suspension. + * + * @param \wcf\data\user\User $user + * @return boolean + */ + public function isVisible($user = null) { + if ($user === null) $user = WCF::getUser(); + $user = new \wcf\data\user\UserProfile($user); + $ph = new \chat\system\permission\PermissionHandler($user->getDecoratedObject()); + + if ($user->getPermission('admin.chat.canManageSuspensions')) return true; + if ($user->getPermission('mod.chat.canG'.$this->type)) return true; + if (!$this->roomID) return false; + if ($ph->getPermission($this->getRoom(), 'mod.can'.ucfirst($this->type))) return true; + + return false; + } + + /** + * Returns the room of this suspension. + * + * @return \chat\data\room\Room + */ + public function getRoom() { + if (!$this->roomID) return new \chat\data\room\Room(null, array('roomID' => null)); + + return \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID); + } + /** * Returns all the suspensions for the specified user (current user if no user was specified). * @@ -53,15 +83,17 @@ public static function getSuspensionsForUser(\wcf\data\user\User $user = null) { if ($suspensions === false) throw new \wcf\system\exception\SystemException(); } catch (\wcf\system\exception\SystemException $e) { + $condition = new \wcf\system\database\util\PreparedStatementConditionBuilder(); + $condition->add('userID = ?', array($user->userID)); + $condition->add('expires > ?', array(TIME_NOW)); + $sql = "SELECT * FROM chat".WCF_N."_suspension - WHERE - userID = ? - AND expires > ?"; + ".$condition; $stmt = WCF::getDB()->prepareStatement($sql); - $stmt->execute(array($user->userID, TIME_NOW)); + $stmt->execute($condition->getParameters()); $suspensions = array(); while ($suspension = $stmt->fetchObject('\chat\data\suspension\Suspension')) { @@ -76,7 +108,7 @@ public static function getSuspensionsForUser(\wcf\data\user\User $user = null) { /** * Returns the appropriate suspension for user, room and type. - * Returns false if no suspension was found. + * Returns false if no active suspension was found. * * @param \wcf\data\user\User $user * @param \chat\data\room\Room $room @@ -84,23 +116,21 @@ public static function getSuspensionsForUser(\wcf\data\user\User $user = null) { * @return \chat\data\suspension\Suspension */ public static function getSuspensionByUserRoomAndType(\wcf\data\user\User $user, \chat\data\room\Room $room, $type) { + $condition = new \wcf\system\database\util\PreparedStatementConditionBuilder(); + $condition->add('userID = ?', array($user->userID)); + $condition->add('type = ?', array($type)); + $condition->add('expires > ?', array(TIME_NOW)); + if ($room->roomID) $condition->add('roomID = ?', array($room->roomID)); + else $condition->add('roomID IS NULL'); + $sql = "SELECT * FROM chat".WCF_N."_suspension - WHERE - userID = ? - AND type = ?"; - - $parameter = array($user->userID, $type); - if ($room->roomID) { - $sql .= " AND roomID = ?"; - $parameter[] = $room->roomID; - } - else $sql .= " AND roomID IS NULL"; + ".$condition; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($parameter); + $statement->execute($condition->getParameters()); $row = $statement->fetchArray(); if (!$row) return false; diff --git a/file/lib/data/suspension/SuspensionAction.class.php b/file/lib/data/suspension/SuspensionAction.class.php index 669cecb..b0bf7e6 100644 --- a/file/lib/data/suspension/SuspensionAction.class.php +++ b/file/lib/data/suspension/SuspensionAction.class.php @@ -1,5 +1,6 @@ className, 'getDatabaseTableIndexName'))." - FROM - ".call_user_func(array($this->className, 'getDatabaseTableName'))." - WHERE - expires < ?"; - $stmt = \wcf\system\WCF::getDB()->prepareStatement($sql); - $stmt->execute(array(TIME_NOW)); - $objectIDs = array(); + public function validateRevoke() { + WCF::getSession()->checkPermissions((array) 'admin.chat.canManageSuspensions'); - while ($objectID = $stmt->fetchColumn()) $objectIDs[] = $objectID; + $this->parameters['revoker'] = WCF::getUser()->userID; + } + + /** + * Revokes suspensions. + */ + public function revoke() { + if (!isset($this->parameters['revoker'])) { + $this->parameters['revoker'] = null; + } - return call_user_func(array($this->className, 'deleteAll'), $objectIDs); + $objectAction = new self($this->objectIDs, 'update', array( + 'data' => array( + 'expires' => TIME_NOW, + 'revoker' => $this->parameters['revoker'] + ) + )); + $objectAction->executeAction(); } } diff --git a/file/lib/data/suspension/SuspensionList.class.php b/file/lib/data/suspension/SuspensionList.class.php new file mode 100644 index 0000000..ed72dd7 --- /dev/null +++ b/file/lib/data/suspension/SuspensionList.class.php @@ -0,0 +1,18 @@ + + * @package be.bastelstu.chat + * @subpackage data.suspension + */ +class SuspensionList extends \wcf\data\DatabaseObjectList { + /** + * @see wcf\data\DatabaseObjectList::$className + */ + public $className = 'chat\data\suspension\Suspension'; +} diff --git a/file/lib/system/command/AbstractSuspensionCommand.class.php b/file/lib/system/command/AbstractSuspensionCommand.class.php new file mode 100644 index 0000000..8d15e7c --- /dev/null +++ b/file/lib/system/command/AbstractSuspensionCommand.class.php @@ -0,0 +1,126 @@ + + * @package be.bastelstu.chat + * @subpackage system.chat.command + */ +abstract class AbstractSuspensionCommand extends AbstractRestrictedCommand { + public $user = null; + public $expires = 0; + public $suspensionAction = null; + public $link = ''; + public $room = null; + public $reason = ''; + + public function __construct(\chat\system\command\CommandHandler $commandHandler) { + parent::__construct($commandHandler); + + try { + $parameters = explode(',', $commandHandler->getParameters(), 3); + list($username, $modifier) = $parameters; + + if (isset($parameters[2])) { + $this->reason = \wcf\util\StringUtil::trim($parameters[2]); + } + + $modifier = ChatUtil::timeModifier(\wcf\util\StringUtil::trim($modifier)); + $expires = strtotime($modifier, TIME_NOW); + $this->expires = min(max(-0x80000000, $expires), 0x7FFFFFFF); + } + catch (\wcf\system\exception\SystemException $e) { + throw new \InvalidArgumentException(); + } + + $this->user = User::getUserByUsername($username); + if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException($username); + + $profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array( + 'object' => $this->user + )); + $this->link = "[url='".$profile."']".$this->user->username.'[/url]'; + + $this->executeAction(); + + $this->didInit(); + } + + public function executeAction() { + if (static::IS_GLOBAL) $room = new \chat\data\room\Room(null, array('roomID' => null)); + else $room = $this->room; + + if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, static::SUSPENSION_TYPE)) { + if ($suspension->expires >= $this->expires) { + throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists')); + } + + $action = new suspension\SuspensionAction(array($suspension), 'revoke', array( + 'revoker' => WCF::getUser()->userID + )); + $action->executeAction(); + } + + $this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array( + 'data' => array( + 'userID' => $this->user->userID, + 'roomID' => $room->roomID ?: null, + 'type' => static::SUSPENSION_TYPE, + 'expires' => $this->expires, + 'time' => TIME_NOW, + 'issuer' => WCF::getUser()->userID, + 'reason' => $this->reason + ) + )); + $this->suspensionAction->executeAction(); + } + + /** + * @see \chat\system\command\IRestrictedChatCommand::checkPermission() + */ + public function checkPermission() { + parent::checkPermission(); + + $this->room = $this->commandHandler->getRoom(); + if (WCF::getSession()->getPermission('admin.chat.canManageSuspensions')) return; + + $ph = new \chat\system\permission\PermissionHandler(); + if (static::IS_GLOBAL) { + WCF::getSession()->checkPermissions((array) 'mod.chat.canG'.static::SUSPENSION_TYPE); + } + else { + if (!WCF::getSession()->getPermission('mod.chat.canG'.static::SUSPENSION_TYPE)) { + if (!$ph->getPermission($this->room, 'mod.can'.ucfirst(static::SUSPENSION_TYPE))) { + throw new \wcf\system\exception\PermissionDeniedException(); + } + } + } + } + + /** + * @see \chat\system\command\ICommand::getType() + */ + public function getType() { + return \chat\data\message\Message::TYPE_MODERATE; + } + + /** + * @see \chat\system\command\ICommand::getMessage() + */ + public function getMessage() { + return serialize(array( + 'link' => $this->link, + 'expires' => $this->expires, + 'type' => (static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE, + 'reason' => $this->reason + )); + } +} diff --git a/file/lib/system/command/AbstractUnsuspensionCommand.class.php b/file/lib/system/command/AbstractUnsuspensionCommand.class.php new file mode 100644 index 0000000..7fa1082 --- /dev/null +++ b/file/lib/system/command/AbstractUnsuspensionCommand.class.php @@ -0,0 +1,93 @@ + + * @package be.bastelstu.chat + * @subpackage system.chat.command + */ +abstract class AbstractUnsuspensionCommand extends AbstractRestrictedCommand { + public $user = null; + public $suspensionAction = null; + public $link = ''; + public $room = null; + + public function __construct(\chat\system\command\CommandHandler $commandHandler) { + parent::__construct($commandHandler); + + $username = rtrim($commandHandler->getParameters(), ','); + $this->user = User::getUserByUsername($username); + if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException($username); + + $profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array( + 'object' => $this->user + )); + $this->link = "[url='".$profile."']".$this->user->username.'[/url]'; + + $this->executeAction(); + + $this->didInit(); + } + + public function executeAction() { + if (static::IS_GLOBAL) $room = new \chat\data\room\Room(null, array('roomID' => null)); + else $room = $this->room; + + if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, static::SUSPENSION_TYPE)) { + $action = new suspension\SuspensionAction(array($suspension), 'revoke', array( + 'revoker' => WCF::getUser()->userID + )); + $action->executeAction(); + } + else { + throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.notExists')); + } + } + + /** + * @see \chat\system\command\IRestrictedChatCommand::checkPermission() + */ + public function checkPermission() { + parent::checkPermission(); + + $this->room = $this->commandHandler->getRoom(); + if (WCF::getSession()->getPermission('admin.chat.canManageSuspensions')) return; + + $ph = new \chat\system\permission\PermissionHandler(); + if (static::IS_GLOBAL) { + WCF::getSession()->checkPermission((array) 'mod.chat.canG'.static::SUSPENSION_TYPE); + } + else { + if (!WCF::getSession()->getPermission('mod.chat.canG'.static::SUSPENSION_TYPE)) { + if (!$ph->getPermission($this->room, 'mod.can'.ucfirst(static::SUSPENSION_TYPE))) { + throw new \wcf\system\exception\PermissionDeniedException(); + } + } + } + } + + /** + * @see \chat\system\command\ICommand::getType() + */ + public function getType() { + return \chat\data\message\Message::TYPE_MODERATE; + } + + /** + * @see \chat\system\command\ICommand::getMessage() + */ + public function getMessage() { + return serialize(array( + 'link' => $this->link, + 'type' => 'un'.(static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE, + )); + } +} diff --git a/file/lib/system/command/commands/AwayCommand.class.php b/file/lib/system/command/commands/AwayCommand.class.php index b7d0518..fb0eff0 100644 --- a/file/lib/system/command/commands/AwayCommand.class.php +++ b/file/lib/system/command/commands/AwayCommand.class.php @@ -36,11 +36,4 @@ public function getType() { public function getMessage() { return \wcf\system\bbcode\PreParser::getInstance()->parse($this->commandHandler->getParameters(), explode(',', WCF::getSession()->getPermission('user.chat.allowedBBCodes'))); } - - /** - * @see \chat\system\command\ICommand::getReceiver() - */ - public function getReceiver() { - return WCF::getUser()->userID; - } } diff --git a/file/lib/system/command/commands/BanCommand.class.php b/file/lib/system/command/commands/BanCommand.class.php index 8840110..c3fcf6a 100644 --- a/file/lib/system/command/commands/BanCommand.class.php +++ b/file/lib/system/command/commands/BanCommand.class.php @@ -1,9 +1,5 @@ user, $this->room, suspension\Suspension::TYPE_BAN)) { - if ($suspension->expires > $this->expires) { - throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists')); - } - - $action = new suspension\SuspensionAction(array($suspension), 'delete'); - $action->executeAction(); - } - - $this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array( - 'data' => array( - 'userID' => $this->user->userID, - 'roomID' => WCF::getUser()->chatRoomID, - 'type' => suspension\Suspension::TYPE_BAN, - 'expires' => $this->expires - ) - )); - $this->suspensionAction->executeAction(); - } +class BanCommand extends \chat\system\command\AbstractSuspensionCommand { + const IS_GLOBAL = false; + const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_BAN; } diff --git a/file/lib/system/command/commands/GbanCommand.class.php b/file/lib/system/command/commands/GbanCommand.class.php index 33e2fd1..106bf6b 100644 --- a/file/lib/system/command/commands/GbanCommand.class.php +++ b/file/lib/system/command/commands/GbanCommand.class.php @@ -1,9 +1,5 @@ null)); - - if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_BAN)) { - if ($suspension->expires > $this->expires) { - throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists')); - } - - $action = new suspension\SuspensionAction(array($suspension), 'delete'); - $action->executeAction(); - } - - $this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array( - 'data' => array( - 'userID' => $this->user->userID, - 'roomID' => null, - 'type' => suspension\Suspension::TYPE_BAN, - 'expires' => $this->expires - ) - )); - $this->suspensionAction->executeAction(); - } +class GbanCommand extends \chat\system\command\AbstractSuspensionCommand { + const IS_GLOBAL = true; + const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_BAN; } diff --git a/file/lib/system/command/commands/GmuteCommand.class.php b/file/lib/system/command/commands/GmuteCommand.class.php index d9aa485..c32ef0b 100644 --- a/file/lib/system/command/commands/GmuteCommand.class.php +++ b/file/lib/system/command/commands/GmuteCommand.class.php @@ -1,12 +1,8 @@ null)); - - if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_MUTE)) { - if ($suspension->expires > $this->expires) { - throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists')); - } - - $action = new suspension\SuspensionAction(array($suspension), 'delete'); - $action->executeAction(); - } - - $this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array( - 'data' => array( - 'userID' => $this->user->userID, - 'roomID' => null, - 'type' => suspension\Suspension::TYPE_MUTE, - 'expires' => $this->expires - ) - )); - $this->suspensionAction->executeAction(); - } +class GmuteCommand extends \chat\system\command\AbstractSuspensionCommand { + const IS_GLOBAL = true; + const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_MUTE; } diff --git a/file/lib/system/command/commands/GunbanCommand.class.php b/file/lib/system/command/commands/GunbanCommand.class.php deleted file mode 100644 index b33d6d4..0000000 --- a/file/lib/system/command/commands/GunbanCommand.class.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @package be.bastelstu.chat - * @subpackage system.chat.command.commands - */ -class GunbanCommand extends UnmuteCommand { - /** - * @see \chat\system\command\commands\UnmuteCommand::executeAction() - */ - public function executeAction() { - $room = new \chat\data\room\Room(null, array('roomID' => null)); - - if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_BAN)) { - $action = new suspension\SuspensionAction(array($suspension), 'delete'); - $action->executeAction(); - } - else { - throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.notExists')); - } - } -} diff --git a/file/lib/system/command/commands/GunmuteCommand.class.php b/file/lib/system/command/commands/GunmuteCommand.class.php deleted file mode 100644 index 3ed8125..0000000 --- a/file/lib/system/command/commands/GunmuteCommand.class.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @package be.bastelstu.chat - * @subpackage system.chat.command.commands - */ -class GunmuteCommand extends UnmuteCommand { - /** - * @see \chat\system\command\commands\UnmuteCommand::executeAction() - */ - public function executeAction() { - $room = new \chat\data\room\Room(null, array('roomID' => null)); - - if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_MUTE)) { - $action = new suspension\SuspensionAction(array($suspension), 'delete'); - $action->executeAction(); - } - else { - throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.notExists')); - } - } -} diff --git a/file/lib/system/command/commands/InfoCommand.class.php b/file/lib/system/command/commands/InfoCommand.class.php index 23c40ba..b1f81eb 100644 --- a/file/lib/system/command/commands/InfoCommand.class.php +++ b/file/lib/system/command/commands/InfoCommand.class.php @@ -45,11 +45,11 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler) } // Suspensions - // TODO: Permissions $suspensions = \chat\data\suspension\Suspension::getSuspensionsForUser($this->user); foreach ($suspensions as $roomSuspensions) { foreach ($roomSuspensions as $typeSuspension) { if (!$typeSuspension->isValid()) continue; + if (!$typeSuspension->isVisible()) continue; $dateTime = DateUtil::getDateTimeByTimestamp($typeSuspension->expires); $name = WCF::getLanguage()->getDynamicVariable('chat.general.information.suspension', array( diff --git a/file/lib/system/command/commands/MuteCommand.class.php b/file/lib/system/command/commands/MuteCommand.class.php index 00ef2f4..519a58a 100644 --- a/file/lib/system/command/commands/MuteCommand.class.php +++ b/file/lib/system/command/commands/MuteCommand.class.php @@ -1,9 +1,5 @@ getParameters(), 2); - $modifier = ChatUtil::timeModifier(\wcf\util\StringUtil::trim($modifier)); - $expires = strtotime($modifier, TIME_NOW); - $this->expires = min(max(-0x80000000, $expires), 0x7FFFFFFF); - } - catch (\wcf\system\exception\SystemException $e) { - throw new \InvalidArgumentException(); - } - - $this->user = User::getUserByUsername($username); - if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException($username); - - $profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array( - 'object' => $this->user - )); - $this->link = "[url='".$profile."']".$this->user->username.'[/url]'; - - $this->executeAction(); - - $this->didInit(); - } - - public function executeAction() { - if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_MUTE)) { - if ($suspension->expires > $this->expires) { - throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists')); - } - - $action = new suspension\SuspensionAction(array($suspension), 'delete'); - $action->executeAction(); - } - - $this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array( - 'data' => array( - 'userID' => $this->user->userID, - 'roomID' => WCF::getUser()->chatRoomID, - 'type' => suspension\Suspension::TYPE_MUTE, - 'expires' => $this->expires - ) - )); - $this->suspensionAction->executeAction(); - } - - /** - * @see \chat\system\command\IRestrictedChatCommand::checkPermission() - */ - public function checkPermission() { - parent::checkPermission(); - - $this->room = $this->commandHandler->getRoom(); - $ph = new \chat\system\permission\PermissionHandler(); - if (!$ph->getPermission($this->room, 'mod.can'.str_replace(array('chat\system\command\commands\\', 'Command'), '', get_class($this)))) throw new \wcf\system\exception\PermissionDeniedException(); - } - - /** - * @see \chat\system\command\ICommand::getType() - */ - public function getType() { - return \chat\data\message\Message::TYPE_MODERATE; - } - - /** - * @see \chat\system\command\ICommand::getMessage() - */ - public function getMessage() { - return serialize(array( - 'link' => $this->link, - 'expires' => $this->expires, - 'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this))) - )); - } +class MuteCommand extends \chat\system\command\AbstractSuspensionCommand { + const IS_GLOBAL = false; + const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_MUTE; } diff --git a/file/lib/system/command/commands/UnbanCommand.class.php b/file/lib/system/command/commands/UnbanCommand.class.php index ee4e5eb..82427f5 100644 --- a/file/lib/system/command/commands/UnbanCommand.class.php +++ b/file/lib/system/command/commands/UnbanCommand.class.php @@ -1,9 +1,5 @@ user, $this->room, suspension\Suspension::TYPE_BAN)) { - $action = new suspension\SuspensionAction(array($suspension), 'delete'); - $action->executeAction(); - } - else { - throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.notExists')); - } - } +class UnbanCommand extends \chat\system\command\AbstractUnsuspensionCommand { + const IS_GLOBAL = false; + const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_BAN; } diff --git a/file/lib/system/command/commands/UngbanCommand.class.php b/file/lib/system/command/commands/UngbanCommand.class.php new file mode 100644 index 0000000..a742c01 --- /dev/null +++ b/file/lib/system/command/commands/UngbanCommand.class.php @@ -0,0 +1,16 @@ + + * @package be.bastelstu.chat + * @subpackage system.chat.command.commands + */ +class UngbanCommand extends \chat\system\command\AbstractUnsuspensionCommand { + const IS_GLOBAL = true; + const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_BAN; +} diff --git a/file/lib/system/command/commands/UngmuteCommand.class.php b/file/lib/system/command/commands/UngmuteCommand.class.php new file mode 100644 index 0000000..4d912fe --- /dev/null +++ b/file/lib/system/command/commands/UngmuteCommand.class.php @@ -0,0 +1,16 @@ + + * @package be.bastelstu.chat + * @subpackage system.chat.command.commands + */ +class UngmuteCommand extends \chat\system\command\AbstractUnsuspensionCommand { + const IS_GLOBAL = true; + const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_MUTE; +} diff --git a/file/lib/system/command/commands/UnmuteCommand.class.php b/file/lib/system/command/commands/UnmuteCommand.class.php index 9019a87..021e6fa 100644 --- a/file/lib/system/command/commands/UnmuteCommand.class.php +++ b/file/lib/system/command/commands/UnmuteCommand.class.php @@ -1,8 +1,5 @@ getParameters(), ','); - $this->user = User::getUserByUsername($username); - if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException($username); - - $profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array( - 'object' => $this->user - )); - $this->link = "[url='".$profile."']".$this->user->username.'[/url]'; - - $this->executeAction(); - - $this->didInit(); - } - - /** - * Removes the suspension. - */ - public function executeAction() { - if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_MUTE)) { - $action = new suspension\SuspensionAction(array($suspension), 'delete'); - $action->executeAction(); - } - else { - throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.notExists')); - } - } - - /** - * @see \chat\system\command\IRestrictedChatCommand::checkPermission() - */ - public function checkPermission() { - parent::checkPermission(); - - $this->room = $this->commandHandler->getRoom(); - $ph = new \chat\system\permission\PermissionHandler(); - if (!$ph->getPermission($this->room, 'mod.can'.ucfirst(str_replace(array('chat\system\command\commands\\Un', 'Command'), '', get_class($this))))) throw new \wcf\system\exception\PermissionDeniedException(); - } - - /** - * @see \chat\system\command\ICommand::getType() - */ - public function getType() { - return \chat\data\message\Message::TYPE_MODERATE; - } - - /** - * @see \chat\system\command\ICommand::getMessage() - */ - public function getMessage() { - return serialize(array( - 'link' => $this->link, - 'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this))) - )); - } +class UnmuteCommand extends \chat\system\command\AbstractUnsuspensionCommand { + const IS_GLOBAL = false; + const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_MUTE; } diff --git a/file/lib/system/cronjob/CleanupCronjob.class.php b/file/lib/system/cronjob/CleanupCronjob.class.php index 47e6a03..5933522 100644 --- a/file/lib/system/cronjob/CleanupCronjob.class.php +++ b/file/lib/system/cronjob/CleanupCronjob.class.php @@ -20,8 +20,6 @@ public function execute(\wcf\data\cronjob\Cronjob $cronjob) { $messageAction->executeAction(); $roomAction = new data\room\RoomAction(array(), 'prune'); $roomAction->executeAction(); - $suspensionAction = new data\suspension\SuspensionAction(array(), 'prune'); - $suspensionAction->executeAction(); // kill dead users $roomAction = new data\room\RoomAction(array(), 'removeDeadUsers'); diff --git a/install.sql b/install.sql index 7b05374..4949484 100644 --- a/install.sql +++ b/install.sql @@ -46,10 +46,14 @@ CREATE TABLE chat1_suspension ( suspensionID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, userID INT(10) NOT NULL, roomID INT(10) DEFAULT NULL, - type TINYINT(3) NOT NULL, + type VARCHAR(15) NOT NULL, expires INT(10) NOT NULL, + time INT(10) NOT NULL, + issuer INT(10) DEFAULT NULL, + reason VARCHAR(255) NOT NULL DEFAULT '', + revoker INT(10) DEFAULT NULL, - UNIQUE KEY suspension (userID, roomID, type), + KEY suspension (userID, roomID, type), KEY (roomID), KEY (type), KEY (expires) @@ -70,10 +74,12 @@ ALTER TABLE chat1_room ADD FOREIGN KEY (owner) REFERENCES wcf1_user (userID) ON ALTER TABLE chat1_suspension ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE; ALTER TABLE chat1_suspension ADD FOREIGN KEY (roomID) REFERENCES chat1_room (roomID) ON DELETE CASCADE; +ALTER TABLE chat1_suspension ADD FOREIGN KEY (issuer) REFERENCES wcf1_user (userID) ON DELETE SET NULL; +ALTER TABLE chat1_suspension ADD FOREIGN KEY (revoker) REFERENCES wcf1_user (userID) ON DELETE SET NULL; ALTER TABLE wcf1_user ADD FOREIGN KEY (chatRoomID) REFERENCES chat1_room (roomID) ON DELETE SET NULL; INSERT INTO chat1_room (title, topic, showOrder) VALUES ('chat.room.title1', 'chat.room.topic1', 1); INSERT INTO chat1_room (title, topic, showOrder) VALUES ('Testroom 2', 'Topic of Testroom 2', 2); -INSERT INTO chat1_room (title, topic, showOrder) VALUES ('Testroom with a very long', 'The topic of this room is rather loing as well!', 3); +INSERT INTO chat1_room (title, topic, showOrder) VALUES ('Testroom with a very long name', 'The topic of this room is rather loing as well!', 3); INSERT INTO chat1_room (title, topic, showOrder) VALUES ('Room w/o topic', '', 4); diff --git a/language/de.xml b/language/de.xml index 3107108..df1ac9a 100644 --- a/language/de.xml +++ b/language/de.xml @@ -11,10 +11,32 @@