2012-03-23 22:27:15 +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\util\ChatUtil;
|
2012-04-15 11:30:08 +00:00
|
|
|
use \wcf\data\user\User;
|
2012-03-23 22:27:15 +00:00
|
|
|
use \wcf\system\WCF;
|
2013-04-23 14:16:27 +00:00
|
|
|
use \wcf\util\DateUtil;
|
2012-03-23 22:27:15 +00:00
|
|
|
use \wcf\util\StringUtil;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows information about the specified user.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
2013-01-19 19:36:40 +00:00
|
|
|
* @copyright 2010-2013 Tim Düsterhus
|
2012-03-23 22:27:15 +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
|
2012-03-24 21:37:47 +00:00
|
|
|
* @subpackage system.chat.command.commands
|
2012-03-23 22:27:15 +00:00
|
|
|
*/
|
2013-01-26 21:46:54 +00:00
|
|
|
class InfoCommand extends \chat\system\command\AbstractCommand {
|
2013-01-09 20:34:30 +00:00
|
|
|
public $enableHTML = self::SETTING_ON;
|
2012-05-19 21:03:26 +00:00
|
|
|
public $lines = array();
|
|
|
|
public $user = null;
|
2012-03-23 22:27:15 +00:00
|
|
|
|
2013-01-26 21:46:54 +00:00
|
|
|
public function __construct(\chat\system\command\CommandHandler $commandHandler) {
|
2012-03-23 22:27:15 +00:00
|
|
|
parent::__construct($commandHandler);
|
|
|
|
|
2013-05-18 20:05:03 +00:00
|
|
|
$username = rtrim($commandHandler->getParameters(), ',');
|
|
|
|
$this->user = User::getUserByUsername($username);
|
|
|
|
if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException($username);
|
2012-04-15 12:09:51 +00:00
|
|
|
|
|
|
|
// Username + link to profile
|
|
|
|
$profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array(
|
2013-03-19 17:20:40 +00:00
|
|
|
'object' => $this->user
|
2012-04-15 12:09:51 +00:00
|
|
|
));
|
2013-03-19 17:20:40 +00:00
|
|
|
$this->lines[WCF::getLanguage()->get('wcf.user.username')] = "[url='".$profile."']".$this->user->username.'[/url]';
|
2012-03-24 21:03:04 +00:00
|
|
|
|
2012-04-15 12:09:51 +00:00
|
|
|
// Away-Status
|
2012-05-19 21:03:26 +00:00
|
|
|
if (ChatUtil::readUserData('away', $this->user) !== null) {
|
|
|
|
$this->lines[WCF::getLanguage()->get('wcf.chat.away')] = ChatUtil::readUserData('away', $this->user);
|
2012-03-24 21:03:04 +00:00
|
|
|
}
|
2012-04-15 12:09:51 +00:00
|
|
|
|
|
|
|
// Room
|
2013-05-24 00:21:49 +00:00
|
|
|
$room = \chat\data\room\RoomCache::getInstance()->getRoom(ChatUtil::readUserData('roomID', $this->user));
|
2012-03-24 21:03:04 +00:00
|
|
|
if ($room->roomID && $room->canEnter()) {
|
2013-05-18 20:05:03 +00:00
|
|
|
$this->lines[WCF::getLanguage()->get('chat.general.room')] = $room->getTitle();
|
2012-03-24 21:03:04 +00:00
|
|
|
}
|
2012-04-15 12:09:51 +00:00
|
|
|
|
2013-04-23 14:16:27 +00:00
|
|
|
// Suspensions
|
|
|
|
// TODO: Permissions
|
|
|
|
$suspensions = \chat\data\suspension\Suspension::getSuspensionsForUser($this->user);
|
|
|
|
foreach ($suspensions as $roomSuspensions) {
|
|
|
|
foreach ($roomSuspensions as $typeSuspension) {
|
2013-05-23 23:21:46 +00:00
|
|
|
if (!$typeSuspension->isValid()) continue;
|
|
|
|
|
|
|
|
$dateTime = DateUtil::getDateTimeByTimestamp($typeSuspension->expires);
|
2013-05-24 00:21:49 +00:00
|
|
|
$name = WCF::getLanguage()->getDynamicVariable('chat.information.suspension', array(
|
|
|
|
'suspension' => $typeSuspension,
|
|
|
|
'room' => \chat\data\room\RoomCache::getInstance()->getRoom($typeSuspension->roomID)
|
|
|
|
));
|
|
|
|
$this->lines[$name] = str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat')));
|
2013-04-23 14:16:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-27 20:58:10 +00:00
|
|
|
// ip address
|
|
|
|
if (WCF::getSession()->getPermission('admin.user.canViewIpAddress')) {
|
|
|
|
$session = $this->fetchSession();
|
|
|
|
if ($session) {
|
2013-02-01 21:46:43 +00:00
|
|
|
$this->lines[WCF::getLanguage()->get('wcf.user.ipAddress')] = \wcf\util\UserUtil::convertIPv6To4($session->ipAddress);
|
2013-01-27 20:58:10 +00:00
|
|
|
}
|
2012-04-15 11:30:08 +00:00
|
|
|
}
|
2012-03-24 21:29:07 +00:00
|
|
|
|
|
|
|
$this->didInit();
|
2012-03-23 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 19:23:57 +00:00
|
|
|
/**
|
2012-08-15 16:04:09 +00:00
|
|
|
* Fetches the sessiondatabase object for the specified user.
|
2012-04-30 19:23:57 +00:00
|
|
|
*
|
|
|
|
* @return \wcf\data\session\Session
|
|
|
|
*/
|
2012-05-19 21:03:26 +00:00
|
|
|
public function fetchSession() {
|
2012-04-15 11:30:08 +00:00
|
|
|
$sql = "SELECT
|
|
|
|
*
|
|
|
|
FROM
|
|
|
|
wcf".WCF_N."_session
|
|
|
|
WHERE
|
|
|
|
userID = ?";
|
|
|
|
$stmt = WCF::getDB()->prepareStatement($sql);
|
2012-05-19 21:03:26 +00:00
|
|
|
$stmt->execute(array($this->user->userID));
|
2012-04-15 11:30:08 +00:00
|
|
|
$row = $stmt->fetchArray();
|
|
|
|
if (!$row) return false;
|
|
|
|
|
|
|
|
return new \wcf\data\session\Session(null, $row);
|
|
|
|
}
|
|
|
|
|
2012-03-23 22:27:15 +00:00
|
|
|
/**
|
2013-01-26 21:46:54 +00:00
|
|
|
* @see \chat\system\command\ICommand::getType()
|
2012-03-23 22:27:15 +00:00
|
|
|
*/
|
|
|
|
public function getType() {
|
2013-01-27 20:58:10 +00:00
|
|
|
return \chat\data\message\Message::TYPE_INFORMATION;
|
2012-03-23 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-26 21:46:54 +00:00
|
|
|
* @see \chat\system\command\ICommand::getMessage()
|
2012-03-23 22:27:15 +00:00
|
|
|
*/
|
|
|
|
public function getMessage() {
|
|
|
|
$lines = array();
|
|
|
|
foreach ($this->lines as $key => $val) {
|
2013-01-09 20:34:30 +00:00
|
|
|
$lines[] = '[b]'.$key.':[/b] '.$val;
|
2012-03-23 22:27:15 +00:00
|
|
|
}
|
2013-01-09 20:34:30 +00:00
|
|
|
return '[list][*]'.implode('[*]', $lines).'[/list]';
|
2012-03-23 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-26 21:46:54 +00:00
|
|
|
* @see \chat\system\command\ICommand::getReceiver()
|
2012-03-23 22:27:15 +00:00
|
|
|
*/
|
|
|
|
public function getReceiver() {
|
|
|
|
return \wcf\system\WCF::getUser()->userID;
|
|
|
|
}
|
|
|
|
}
|