1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-11-01 14:20:07 +00:00
Tims-Chat/file/lib/system/command/commands/MuteCommand.class.php

112 lines
3.5 KiB
PHP
Raw Normal View History

2013-01-14 19:52:09 +00:00
<?php
namespace chat\system\command\commands;
use \chat\data\suspension;
2013-05-18 20:05:03 +00:00
use \chat\util\ChatUtil;
2013-01-14 19:52:09 +00:00
use \wcf\data\user\User;
use \wcf\system\WCF;
/**
* Mutes a user.
*
* @author Tim Düsterhus
2013-01-19 19:36:40 +00:00
* @copyright 2010-2013 Tim Düsterhus
2013-01-14 19:52:09 +00:00
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
2013-01-19 19:36:40 +00:00
* @package be.bastelstu.chat
2013-01-14 19:52:09 +00:00
* @subpackage system.chat.command.commands
*/
class MuteCommand extends \chat\system\command\AbstractRestrictedCommand {
const SUSPENSION_TYPE = suspension\Suspension::TYPE_MUTE;
2013-01-14 19:52:09 +00:00
public $user = null;
2013-05-23 23:21:46 +00:00
public $expires = 0;
2013-01-14 19:52:09 +00:00
public $suspensionAction = null;
public $link = '';
public $room = null;
public $reason = '';
2013-01-14 19:52:09 +00:00
public function __construct(\chat\system\command\CommandHandler $commandHandler) {
2013-01-14 19:52:09 +00:00
parent::__construct($commandHandler);
2013-05-23 20:09:47 +00:00
try {
$parameters = explode(',', $commandHandler->getParameters(), 3);
list($username, $modifier) = $parameters;
if (isset($parameters[2])) {
$this->reason = \wcf\util\StringUtil::trim($parameters[2]);
}
2013-05-23 20:09:47 +00:00
$modifier = ChatUtil::timeModifier(\wcf\util\StringUtil::trim($modifier));
2013-05-23 23:21:46 +00:00
$expires = strtotime($modifier, TIME_NOW);
$this->expires = min(max(-0x80000000, $expires), 0x7FFFFFFF);
2013-01-14 19:52:09 +00:00
}
2013-05-23 20:09:47 +00:00
catch (\wcf\system\exception\SystemException $e) {
throw new \InvalidArgumentException();
2013-01-14 19:52:09 +00:00
}
$this->user = User::getUserByUsername($username);
if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException($username);
2013-01-14 19:52:09 +00:00
$profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array(
'object' => $this->user
));
$this->link = "[url='".$profile."']".$this->user->username.'[/url]';
2013-01-14 19:52:09 +00:00
$this->executeAction();
$this->didInit();
}
public function executeAction() {
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, static::SUSPENSION_TYPE)) {
if ($suspension->expires >= $this->expires) {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
2013-01-14 19:52:09 +00:00
}
2013-06-22 12:40:54 +00:00
$action = new suspension\SuspensionAction(array($suspension), 'revoke');
2013-05-18 20:05:03 +00:00
$action->executeAction();
2013-01-14 19:52:09 +00:00
}
$this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array(
2013-01-14 19:52:09 +00:00
'data' => array(
'userID' => $this->user->userID,
'roomID' => WCF::getUser()->chatRoomID,
2013-06-22 00:40:03 +00:00
'type' => static::SUSPENSION_TYPE,
2013-06-08 14:28:40 +00:00
'expires' => $this->expires,
'time' => TIME_NOW,
'issuer' => WCF::getUser()->userID,
'reason' => $this->reason
2013-01-14 19:52:09 +00:00
)
));
$this->suspensionAction->executeAction();
}
/**
* @see \chat\system\command\IRestrictedChatCommand::checkPermission()
2013-01-14 19:52:09 +00:00
*/
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();
2013-01-14 19:52:09 +00:00
}
/**
* @see \chat\system\command\ICommand::getType()
2013-01-14 19:52:09 +00:00
*/
public function getType() {
return \chat\data\message\Message::TYPE_MODERATE;
2013-01-14 19:52:09 +00:00
}
/**
* @see \chat\system\command\ICommand::getMessage()
2013-01-14 19:52:09 +00:00
*/
public function getMessage() {
return serialize(array(
'link' => $this->link,
2013-05-23 23:21:46 +00:00
'expires' => $this->expires,
'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this))),
2013-06-22 12:21:15 +00:00
'reason' => $this->reason
2013-01-14 19:52:09 +00:00
));
}
}