mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-10-31 14:10:08 +00:00
Merge branch 'suspensionList' of github.com:wbbaddons/Tims-Chat into suspensionList
This commit is contained in:
commit
55c4029057
@ -125,6 +125,9 @@ public function validateSend() {
|
||||
catch (\chat\system\command\UserNotFoundException $e) {
|
||||
throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('chat.error.userNotFound', array('exception' => $e)));
|
||||
}
|
||||
catch (\InvalidArgumentException $e) {
|
||||
throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('chat.error.invalidArgument', array('exception' => $e)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->parameters['type'] = Message::TYPE_NORMAL;
|
||||
|
@ -31,7 +31,7 @@ class Suspension extends \chat\data\CHATDatabaseObject {
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid() {
|
||||
return $this->expires > TIME_NOW;
|
||||
return $this->expires > TIME_NOW && !$this->revoked;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,15 +53,18 @@ 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));
|
||||
$condition->add('revoked = ?', array(0));
|
||||
|
||||
$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 +79,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 +87,22 @@ 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));
|
||||
$condition->add('revoked = ?', array(0));
|
||||
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;
|
||||
|
||||
|
@ -17,9 +17,9 @@ class SuspensionAction extends \wcf\data\AbstractDatabaseObjectAction {
|
||||
protected $className = '\chat\data\suspension\SuspensionEditor';
|
||||
|
||||
/**
|
||||
* Deletes expired suspensions.
|
||||
* Revokes expired suspensions.
|
||||
*
|
||||
* @return integer Number of deleted suspensions
|
||||
* @return array<integer> Revoked suspensions
|
||||
*/
|
||||
public function prune() {
|
||||
$sql = "SELECT
|
||||
@ -34,6 +34,26 @@ public function prune() {
|
||||
|
||||
while ($objectID = $stmt->fetchColumn()) $objectIDs[] = $objectID;
|
||||
|
||||
return call_user_func(array($this->className, 'deleteAll'), $objectIDs);
|
||||
$suspensionAction = new self($objectIDs, 'revoke');
|
||||
$suspensionAction->executeAction();
|
||||
|
||||
return $objectIDs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes suspensions.
|
||||
*/
|
||||
public function revoke() {
|
||||
if (!isset($this->parameters['revoker'])) {
|
||||
$this->parameters['revoker'] = null;
|
||||
}
|
||||
|
||||
$objectAction = new self($this->objectIDs, 'update', array(
|
||||
'data' => array(
|
||||
'revoked' => 1,
|
||||
'revoker' => $this->parameters['revoker']
|
||||
)
|
||||
));
|
||||
$objectAction->executeAction();
|
||||
}
|
||||
}
|
||||
|
@ -146,6 +146,9 @@ public function readCommands() {
|
||||
if ($command == 'Plain') continue;
|
||||
$this->commands[] = \wcf\util\StringUtil::toLowerCase($command);
|
||||
}
|
||||
|
||||
$this->commands = array_merge($this->commands, array_keys(\chat\system\command\CommandHandler::getAliasMap()));
|
||||
sort($this->commands);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,19 +14,19 @@
|
||||
final class CommandHandler {
|
||||
/**
|
||||
* char that indicates a command
|
||||
* @var string
|
||||
* @var string
|
||||
*/
|
||||
const COMMAND_CHAR = '/';
|
||||
|
||||
/**
|
||||
* message text
|
||||
* @var string
|
||||
* @var string
|
||||
*/
|
||||
private $text = '';
|
||||
|
||||
/**
|
||||
* current room
|
||||
* @var \chat\data\room\Room
|
||||
* @var \chat\data\room\Room
|
||||
*/
|
||||
private $room = null;
|
||||
|
||||
@ -39,6 +39,29 @@ final class CommandHandler {
|
||||
public function __construct($text, \chat\data\room\Room $room = null) {
|
||||
$this->text = $text;
|
||||
$this->room = $room;
|
||||
|
||||
$aliases = self::getAliasMap();
|
||||
foreach ($aliases as $search => $replace) {
|
||||
$this->text = \wcf\system\Regex::compile('^'.preg_quote(self::COMMAND_CHAR.$search).'( |$)')->replace($this->text, self::COMMAND_CHAR.$replace.' ');
|
||||
}
|
||||
|
||||
$this->text = \wcf\system\Regex::compile('^//')->replace($this->text, '/plain ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the alias map. Key is the alias, value is the target.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function getAliasMap() {
|
||||
$result = array();
|
||||
foreach (explode("\n", StringUtil::unifyNewlines(StringUtil::toLowerCase(CHAT_COMMAND_ALIASES))) as $line) {
|
||||
list($key, $val) = explode(':', $line, 2);
|
||||
|
||||
$result[$key] = $val;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,13 +109,9 @@ public function getParameters() {
|
||||
public function loadCommand() {
|
||||
$parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2);
|
||||
|
||||
if ($this->isCommand($parts[0])) {
|
||||
return new commands\PlainCommand($this);
|
||||
}
|
||||
|
||||
$class = '\chat\system\command\commands\\'.ucfirst(strtolower($parts[0])).'Command';
|
||||
if (!class_exists($class)) {
|
||||
throw new NotFoundException();
|
||||
throw new NotFoundException($parts[0]);
|
||||
}
|
||||
|
||||
return new $class($this);
|
||||
|
@ -10,4 +10,23 @@
|
||||
* @package be.bastelstu.chat
|
||||
* @subpackage system.chat.command
|
||||
*/
|
||||
class NotFoundException extends \Exception { }
|
||||
class NotFoundException extends \Exception {
|
||||
/**
|
||||
* given command
|
||||
* @var string
|
||||
*/
|
||||
private $command = '';
|
||||
|
||||
public function __construct($command) {
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given command
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommand() {
|
||||
return $this->command;
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
||||
foreach ($color as $key => $val) {
|
||||
if (isset(self::$colors[$val])) $color[$key] = self::$colors[$val];
|
||||
else {
|
||||
if (!$regex->match($val)) throw new \chat\system\command\NotFoundException();
|
||||
if (!$regex->match($val)) throw new \InvalidArgumentException();
|
||||
|
||||
$matches = $regex->getMatches();
|
||||
$val = $matches[1];
|
||||
|
@ -15,7 +15,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
||||
parent::__construct($commandHandler);
|
||||
|
||||
if (\wcf\util\StringUtil::toLowerCase($this->commandHandler->getParameters()) != 'the fish') {
|
||||
throw new \chat\system\command\NotFoundException();
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
$this->didInit();
|
||||
|
@ -23,7 +23,7 @@ public function executeAction() {
|
||||
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
|
||||
}
|
||||
|
||||
$action = new suspension\SuspensionAction(array($suspension), 'delete');
|
||||
$action = new suspension\SuspensionAction(array($suspension), 'revoke');
|
||||
$action->executeAction();
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,9 @@ 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 = new suspension\SuspensionAction(array($suspension), 'revoke', array(
|
||||
'revoker' => WCF::getUser()->userID
|
||||
));
|
||||
$action->executeAction();
|
||||
}
|
||||
else {
|
||||
|
@ -22,7 +22,9 @@ 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 = new suspension\SuspensionAction(array($suspension), 'revoke', array(
|
||||
'revoker' => WCF::getUser()->userID
|
||||
));
|
||||
$action->executeAction();
|
||||
}
|
||||
else {
|
||||
|
@ -39,7 +39,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
||||
$this->expires = min(max(-0x80000000, $expires), 0x7FFFFFFF);
|
||||
}
|
||||
catch (\wcf\system\exception\SystemException $e) {
|
||||
throw new \chat\system\command\NotFoundException();
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
$this->user = User::getUserByUsername($username);
|
||||
@ -61,7 +61,7 @@ public function executeAction() {
|
||||
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
|
||||
}
|
||||
|
||||
$action = new suspension\SuspensionAction(array($suspension), 'delete');
|
||||
$action = new suspension\SuspensionAction(array($suspension), 'revoke');
|
||||
$action->executeAction();
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public function getType() {
|
||||
* @see \chat\system\command\ICommand::getMessage()
|
||||
*/
|
||||
public function getMessage() {
|
||||
return \wcf\system\bbcode\PreParser::getInstance()->parse(\wcf\util\StringUtil::substring($this->commandHandler->getText(), 1), explode(',', \wcf\system\WCF::getSession()->getPermission('user.chat.allowedBBCodes')));
|
||||
return \wcf\system\bbcode\PreParser::getInstance()->parse(\chat\system\command\CommandHandler::COMMAND_CHAR.$this->commandHandler->getParameters(), explode(',', \wcf\system\WCF::getSession()->getPermission('user.chat.allowedBBCodes')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,9 @@ class UnbanCommand extends UnmuteCommand {
|
||||
*/
|
||||
public function executeAction() {
|
||||
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_BAN)) {
|
||||
$action = new suspension\SuspensionAction(array($suspension), 'delete');
|
||||
$action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
|
||||
'revoker' => WCF::getUser()->userID
|
||||
));
|
||||
$action->executeAction();
|
||||
}
|
||||
else {
|
||||
|
@ -41,7 +41,9 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
||||
*/
|
||||
public function executeAction() {
|
||||
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_MUTE)) {
|
||||
$action = new suspension\SuspensionAction(array($suspension), 'delete');
|
||||
$action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
|
||||
'revoker' => WCF::getUser()->userID
|
||||
));
|
||||
$action->executeAction();
|
||||
}
|
||||
else {
|
||||
|
@ -26,7 +26,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
||||
$this->message = \wcf\util\StringUtil::trim($message);
|
||||
}
|
||||
catch (\wcf\system\exception\SystemException $e) {
|
||||
throw new \chat\system\command\NotFoundException();
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
$this->user = User::getUserByUsername($username);
|
||||
|
@ -136,7 +136,7 @@
|
||||
> .chatSidebarMenu {
|
||||
background: @wcfContentBackgroundColor;
|
||||
margin: -14px 0 0;
|
||||
.borderRadius(0);
|
||||
border-radius: 0px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +51,10 @@ CREATE TABLE chat1_suspension (
|
||||
time INT(10) NOT NULL,
|
||||
issuer INT(10) DEFAULT NULL,
|
||||
reason VARCHAR(255) NOT NULL DEFAULT '',
|
||||
revoked TINYINT(1) NOT NULL DEFAULT 0,
|
||||
revoker INT(10) DEFAULT NULL,
|
||||
|
||||
UNIQUE KEY suspension (userID, roomID, type),
|
||||
KEY suspension (userID, roomID, type),
|
||||
KEY (roomID),
|
||||
KEY (type),
|
||||
KEY (expires)
|
||||
@ -74,6 +76,7 @@ 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;
|
||||
|
||||
|
@ -70,7 +70,7 @@
|
||||
</category>
|
||||
|
||||
<category name="chat.error">
|
||||
<item name="chat.error.notFound"><![CDATA[Der Befehl wurde nicht gefunden.]]></item>
|
||||
<item name="chat.error.notFound"><![CDATA[Der Befehl „{$exception->getCommand()}“ wurde nicht gefunden.]]></item>
|
||||
<item name="chat.error.userNotFound"><![CDATA[Der Benutzer „{$exception->getUsername()}“ wurde nicht gefunden.]]></item>
|
||||
<item name="chat.error.permissionDenied"><![CDATA[Sie dürfen diesen Befehl nicht verwenden.]]></item>
|
||||
<item name="chat.error.duplicateTab"><![CDATA[Der Chat wurde in einem weiteren Tab geöffnet.]]></item>
|
||||
@ -112,7 +112,7 @@
|
||||
<item name="chat.general.profile"><![CDATA[Profil]]></item>
|
||||
|
||||
<item name="chat.general.information"><![CDATA[Information]]></item>
|
||||
<item name="chat.general.information.chatUpdate"><![CDATA[Der Chat wurde aktualisiert. Bitte lade die Seite neu, da es sonst zu Fehlern kommen kann.]]></item>
|
||||
<item name="chat.general.information.chatUpdate"><![CDATA[Der Chat wurde aktualisiert. Bitte laden Sie die Seite neu, da es sonst zu Fehlern kommen kann.]]></item>
|
||||
<item name="chat.general.information.suspension"><![CDATA[{lang}chat.suspension.{$suspension->type}{/lang} ({if $room}{$room}{else}{lang}chat.room.global{/lang}{/if})]]></item>
|
||||
</category>
|
||||
|
||||
|
@ -44,10 +44,12 @@
|
||||
<minvalue>1</minvalue>
|
||||
<maxvalue>5000</maxvalue>
|
||||
</option>
|
||||
<option name="chat_show_version">
|
||||
<option name="chat_command_aliases">
|
||||
<categoryname>chat.general</categoryname>
|
||||
<optiontype>boolean</optiontype>
|
||||
<defaultvalue>1</defaultvalue>
|
||||
<optiontype>textarea</optiontype>
|
||||
<defaultvalue>afk:away
|
||||
col:color
|
||||
msg:whisper</defaultvalue>
|
||||
</option>
|
||||
<!-- general chat options end -->
|
||||
|
||||
|
@ -5,8 +5,9 @@
|
||||
<packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription>
|
||||
<packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription>
|
||||
<isapplication>1</isapplication>
|
||||
<version>3.0.0 Alpha 55</version><!-- Codename: Codenames are overrated -->
|
||||
<version>3.0.0 Alpha 59</version><!-- Codename: Codenames are overrated -->
|
||||
<date>2011-11-26</date>
|
||||
<license><![CDATA[Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>]]></license>
|
||||
</packageinformation>
|
||||
|
||||
<authorinformation>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<dt>{lang}chat.general.copyright.leader{/lang}</dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li><a href="http://tims.bastelstu.be/">Tim Düsterhus</a></li>
|
||||
<li><a href="http://tims.bastelstu.be/"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Tim Düsterhus</a></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
@ -14,8 +14,8 @@
|
||||
<dt>{lang}chat.general.copyright.developer{/lang}</dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li><a href="http://tims.bastelstu.be/">Tim Düsterhus</a></li>
|
||||
<li><a href="https://github.com/max-m">Maximilian Mader</a></li>
|
||||
<li><a href="http://tims.bastelstu.be/"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Tim Düsterhus</a></li>
|
||||
<li><a href="https://github.com/max-m"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Maximilian Mader</a></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
@ -23,7 +23,7 @@
|
||||
<dt>{lang}chat.general.copyright.graphics{/lang}</dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li><a href="http://www.cls-design.com/">Tom</a></li>
|
||||
<li><a href="http://www.cls-design.com/"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Tom</a></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
@ -37,10 +37,10 @@
|
||||
<dt>{lang}chat.general.copyright.thanks{/lang}</dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li><a href="http://www.wbbaddons.de/user/2020-noone/">-noone-</a></li>
|
||||
<li><a href="https://github.com/Gabbid">Gabi</a></li>
|
||||
<li><a href="https://github.com/Leon-">Stefan Hahn</a></li>
|
||||
<li><a href="http://www.wbbaddons.de">Martin Schwendowius</a></li>
|
||||
<li><a href="http://www.wbbaddons.de/user/2020-noone/"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>-noone-</a></li>
|
||||
<li><a href="https://github.com/Gabbid"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Gabi</a></li>
|
||||
<li><a href="https://github.com/Leon-"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Stefan Hahn</a></li>
|
||||
<li><a href="http://www.wbbaddons.de"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Martin Schwendowius</a></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
|
Loading…
Reference in New Issue
Block a user