2013-01-14 19:52:09 +00:00
|
|
|
<?php
|
2013-01-26 21:46:54 +00:00
|
|
|
namespace chat\system\command\commands;
|
2013-01-14 19:52:09 +00:00
|
|
|
use \wcf\data\chat\suspension;
|
|
|
|
use \wcf\data\user\User;
|
|
|
|
use \wcf\system\WCF;
|
|
|
|
use \wcf\util\ChatUtil;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-01-14 19:52:09 +00:00
|
|
|
public $user = null;
|
|
|
|
public $time = 0;
|
|
|
|
public $suspensionAction = null;
|
|
|
|
public $link = '';
|
|
|
|
public $fail = false;
|
|
|
|
public $room = null;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
$parameters = $commandHandler->getParameters();
|
|
|
|
if (($comma = strpos($parameters, ',')) !== false) {
|
|
|
|
$username = substr($parameters, 0, $comma);
|
|
|
|
$this->time = ChatUtil::timeModifier(substr($parameters, $comma + 1));
|
|
|
|
}
|
|
|
|
else {
|
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
|
|
|
|
|
|
|
$color = ChatUtil::readUserData('color', $this->user);
|
|
|
|
$profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array(
|
|
|
|
'object' => $this->user
|
|
|
|
));
|
|
|
|
$this->link = '<span class="userLink" data-user-id="'.$this->user->userID.'" />';
|
|
|
|
|
|
|
|
$this->executeAction();
|
|
|
|
|
|
|
|
$this->didInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function executeAction() {
|
|
|
|
if ($suspension = suspension\ChatSuspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\ChatSuspension::TYPE_MUTE)) {
|
|
|
|
if ($suspension->time > TIME_NOW + $this->time) {
|
|
|
|
$this->fail = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$editor = new suspension\ChatSuspensionEditor($suspension);
|
|
|
|
$editor->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->suspensionAction = new suspension\ChatSuspensionAction(array(), 'create', array(
|
|
|
|
'data' => array(
|
|
|
|
'userID' => $this->user->userID,
|
|
|
|
'roomID' => ChatUtil::readUserData('roomID'),
|
|
|
|
'type' => suspension\ChatSuspension::TYPE_MUTE,
|
|
|
|
'time' => TIME_NOW + $this->time
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$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();
|
|
|
|
|
|
|
|
$this->room = \wcf\system\request\RequestHandler::getInstance()->getActiveRequest()->getRequestObject()->request->room;
|
|
|
|
$ph = new \wcf\system\chat\permission\ChatPermissionHandler();
|
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::getReceiver()
|
2013-01-14 19:52:09 +00:00
|
|
|
*/
|
|
|
|
public function getReceiver() {
|
|
|
|
if ($this->fail) return WCF::getUser()->userID;
|
|
|
|
|
|
|
|
return parent::getReceiver();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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() {
|
|
|
|
if ($this->fail) return \wcf\data\chat\message\ChatMessage::TYPE_INFORMATION;
|
|
|
|
return \wcf\data\chat\message\ChatMessage::TYPE_MODERATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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() {
|
|
|
|
if ($this->fail) return WCF::getLanguage()->get('wcf.chat.suspension.exists');
|
|
|
|
|
|
|
|
return serialize(array(
|
|
|
|
'link' => $this->link,
|
|
|
|
'until' => TIME_NOW + $this->time,
|
2013-01-26 21:46:54 +00:00
|
|
|
'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this)))
|
2013-01-14 19:52:09 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|