2013-01-14 19:52:09 +00:00
|
|
|
<?php
|
2013-01-26 21:46:54 +00:00
|
|
|
namespace chat\system\command\commands;
|
2013-01-27 20:58:10 +00:00
|
|
|
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
|
|
|
|
*/
|
2013-01-26 21:46:54 +00:00
|
|
|
class MuteCommand extends \chat\system\command\AbstractRestrictedCommand {
|
2013-06-22 00:19:52 +00:00
|
|
|
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;
|
2013-06-22 00:19:52 +00:00
|
|
|
public $reason = '';
|
2013-01-14 19:52:09 +00:00
|
|
|
|
2013-01-26 21:46:54 +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 {
|
2013-06-22 00:19:52 +00:00
|
|
|
$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) {
|
2013-01-26 21:46:54 +00:00
|
|
|
throw new \chat\system\command\NotFoundException();
|
2013-01-14 19:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->user = User::getUserByUsername($username);
|
2013-01-26 21:46:54 +00:00
|
|
|
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
|
|
|
|
));
|
2013-04-20 17:49:06 +00:00
|
|
|
$this->link = "[url='".$profile."']".$this->user->username.'[/url]';
|
2013-01-14 19:52:09 +00:00
|
|
|
|
|
|
|
$this->executeAction();
|
|
|
|
|
|
|
|
$this->didInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function executeAction() {
|
2013-06-22 00:19:52 +00:00
|
|
|
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, static::SUSPENSION_TYPE)) {
|
|
|
|
if ($suspension->expires >= $this->expires) {
|
2013-04-23 13:53:21 +00:00
|
|
|
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
|
2013-01-14 19:52:09 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 20:05:03 +00:00
|
|
|
$action = new suspension\SuspensionAction(array($suspension), 'delete');
|
|
|
|
$action->executeAction();
|
2013-01-14 19:52:09 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 20:58:10 +00:00
|
|
|
$this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array(
|
2013-01-14 19:52:09 +00:00
|
|
|
'data' => array(
|
|
|
|
'userID' => $this->user->userID,
|
2013-05-24 15:30:27 +00:00
|
|
|
'roomID' => WCF::getUser()->chatRoomID,
|
2013-01-27 20:58:10 +00:00
|
|
|
'type' => suspension\Suspension::TYPE_MUTE,
|
2013-06-08 14:28:40 +00:00
|
|
|
'expires' => $this->expires,
|
|
|
|
'time' => TIME_NOW,
|
2013-06-22 00:19:52 +00:00
|
|
|
'issuer' => WCF::getUser()->userID,
|
|
|
|
'reason' => $this->reason
|
2013-01-14 19:52:09 +00:00
|
|
|
)
|
|
|
|
));
|
|
|
|
$this->suspensionAction->executeAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-26 21:46:54 +00:00
|
|
|
* @see \chat\system\command\IRestrictedChatCommand::checkPermission()
|
2013-01-14 19:52:09 +00:00
|
|
|
*/
|
|
|
|
public function checkPermission() {
|
|
|
|
parent::checkPermission();
|
|
|
|
|
2013-03-11 16:17:58 +00:00
|
|
|
$this->room = $this->commandHandler->getRoom();
|
2013-01-27 20:58:10 +00:00
|
|
|
$ph = new \chat\system\permission\PermissionHandler();
|
2013-01-26 21:46:54 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-26 21:46:54 +00:00
|
|
|
* @see \chat\system\command\ICommand::getType()
|
2013-01-14 19:52:09 +00:00
|
|
|
*/
|
|
|
|
public function getType() {
|
2013-01-27 20:58:10 +00:00
|
|
|
return \chat\data\message\Message::TYPE_MODERATE;
|
2013-01-14 19:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-26 21:46:54 +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,
|
2013-06-22 00:19:52 +00:00
|
|
|
'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this))),
|
|
|
|
'message' => $this->suspensionMessage
|
2013-01-14 19:52:09 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|