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/InfoCommand.class.php

112 lines
3.5 KiB
PHP
Raw Normal View History

2012-03-23 22:27:15 +00:00
<?php
namespace chat\system\command\commands;
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
* @subpackage system.chat.command.commands
2012-03-23 22:27:15 +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
public function __construct(\chat\system\command\CommandHandler $commandHandler) {
2012-03-23 22:27:15 +00:00
parent::__construct($commandHandler);
2012-05-19 21:03:26 +00:00
$this->user = User::getUserByUsername(rtrim($commandHandler->getParameters(), ','));
if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException(rtrim($commandHandler->getParameters(), ','));
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
$room = new \chat\data\room\Room(ChatUtil::readUserData('roomID', $this->user));
2012-03-24 21:03:04 +00:00
if ($room->roomID && $room->canEnter()) {
$this->lines[WCF::getLanguage()->get('wcf.chat.room')] = $room->getTitle();
}
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) {
$dateTime = DateUtil::getDateTimeByTimestamp($typeSuspension->time);
$this->lines[$typeSuspension->type.'-'.$typeSuspension->roomID] = str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat')));
}
}
// 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);
}
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
/**
* @see \chat\system\command\ICommand::getType()
2012-03-23 22:27:15 +00:00
*/
public function getType() {
return \chat\data\message\Message::TYPE_INFORMATION;
2012-03-23 22:27:15 +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
}
/**
* @see \chat\system\command\ICommand::getReceiver()
2012-03-23 22:27:15 +00:00
*/
public function getReceiver() {
return \wcf\system\WCF::getUser()->userID;
}
}