1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-23 21:50:09 +00:00
Tims-Chat/file/lib/system/command/commands/MuteCommand.class.php

107 lines
3.3 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-01-14 19:52:09 +00:00
use \wcf\data\user\User;
use \wcf\system\WCF;
use \chat\util\ChatUtil;
2013-01-14 19:52:09 +00:00
/**
* 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 {
2013-01-14 19:52:09 +00:00
public $user = null;
public $time = 0;
public $suspensionAction = null;
public $link = '';
public $room = null;
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 {
throw new \chat\system\command\NotFoundException();
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
$color = ChatUtil::readUserData('color', $this->user);
$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, suspension\Suspension::TYPE_MUTE)) {
2013-01-14 19:52:09 +00:00
if ($suspension->time > TIME_NOW + $this->time) {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
2013-01-14 19:52:09 +00:00
}
$editor = new suspension\SuspensionEditor($suspension);
2013-01-14 19:52:09 +00:00
$editor->delete();
}
$this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array(
2013-01-14 19:52:09 +00:00
'data' => array(
'userID' => $this->user->userID,
'roomID' => ChatUtil::readUserData('roomID'),
'type' => suspension\Suspension::TYPE_MUTE,
2013-01-14 19:52:09 +00:00
'time' => TIME_NOW + $this->time
)
));
$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::getReceiver()
2013-01-14 19:52:09 +00:00
*/
public function getReceiver() {
return parent::getReceiver();
}
/**
* @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,
'until' => TIME_NOW + $this->time,
'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this)))
2013-01-14 19:52:09 +00:00
));
}
}