2012-03-23 22:27:15 +00:00
|
|
|
<?php
|
2012-03-24 21:37:47 +00:00
|
|
|
namespace wcf\system\chat\command\commands;
|
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;
|
2012-03-24 21:03:04 +00:00
|
|
|
use \wcf\util\ChatUtil;
|
2012-03-23 22:27:15 +00:00
|
|
|
use \wcf\util\StringUtil;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows information about the specified user.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
|
|
|
* @copyright 2010-2012 Tim Düsterhus
|
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
|
|
|
* @package timwolla.wcf.chat
|
2012-03-24 21:37:47 +00:00
|
|
|
* @subpackage system.chat.command.commands
|
2012-03-23 22:27:15 +00:00
|
|
|
*/
|
2012-03-24 21:37:47 +00:00
|
|
|
class Info extends \wcf\system\chat\command\AbstractCommand {
|
|
|
|
public $enableSmilies = \wcf\system\chat\command\ICommand::SMILEY_OFF;
|
2012-03-23 22:27:15 +00:00
|
|
|
public $enableHTML = 1;
|
|
|
|
private $lines = array();
|
|
|
|
|
2012-03-24 21:37:47 +00:00
|
|
|
public function __construct(\wcf\system\chat\command\CommandHandler $commandHandler) {
|
2012-03-23 22:27:15 +00:00
|
|
|
parent::__construct($commandHandler);
|
|
|
|
|
2012-04-15 11:30:08 +00:00
|
|
|
$user = User::getUserByUsername(rtrim($commandHandler->getParameters(), ','));
|
2012-03-24 21:37:47 +00:00
|
|
|
if (!$user->userID) throw new \wcf\system\chat\command\UserNotFoundException(rtrim($commandHandler->getParameters(), ','));
|
2012-03-24 21:03:04 +00:00
|
|
|
$room = new \wcf\data\chat\room\ChatRoom(ChatUtil::readUserData('roomID', $user));
|
|
|
|
$color = ChatUtil::readUserData('color', $user);
|
|
|
|
|
|
|
|
$this->lines[WCF::getLanguage()->get('wcf.user.username')] = ChatUtil::gradient($user->username, $color[1], $color[2]);
|
|
|
|
if (ChatUtil::readUserData('away', $user) !== null) {
|
|
|
|
$this->lines[WCF::getLanguage()->get('wcf.chat.away')] = ChatUtil::readUserData('away', $user);
|
|
|
|
}
|
|
|
|
if ($room->roomID && $room->canEnter()) {
|
|
|
|
$this->lines[WCF::getLanguage()->get('wcf.chat.room')] = $room->getTitle();
|
|
|
|
}
|
2012-04-15 11:30:08 +00:00
|
|
|
$session = $this->fetchSession($user);
|
|
|
|
if ($session) {
|
|
|
|
// TODO: Check permission
|
|
|
|
$this->lines['IP_ADDRESS'] = $session->ipAddress;
|
|
|
|
}
|
2012-03-24 21:29:07 +00:00
|
|
|
|
|
|
|
$this->didInit();
|
2012-03-23 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
2012-04-15 11:30:08 +00:00
|
|
|
public function fetchSession(User $user) {
|
|
|
|
$sql = "SELECT
|
|
|
|
*
|
|
|
|
FROM
|
|
|
|
wcf".WCF_N."_session
|
|
|
|
WHERE
|
|
|
|
userID = ?";
|
|
|
|
$stmt = WCF::getDB()->prepareStatement($sql);
|
|
|
|
$stmt->execute(array($user->userID));
|
|
|
|
$row = $stmt->fetchArray();
|
|
|
|
if (!$row) return false;
|
|
|
|
|
|
|
|
return new \wcf\data\session\Session(null, $row);
|
|
|
|
}
|
|
|
|
|
2012-03-23 22:27:15 +00:00
|
|
|
/**
|
2012-03-24 21:37:47 +00:00
|
|
|
* @see \wcf\system\chat\command\ICommand::getType()
|
2012-03-23 22:27:15 +00:00
|
|
|
*/
|
|
|
|
public function getType() {
|
|
|
|
return \wcf\data\chat\message\ChatMessage::TYPE_INFORMATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-24 21:37:47 +00:00
|
|
|
* @see \wcf\system\chat\command\ICommand::getMessage()
|
2012-03-23 22:27:15 +00:00
|
|
|
*/
|
|
|
|
public function getMessage() {
|
|
|
|
$lines = array();
|
|
|
|
foreach ($this->lines as $key => $val) {
|
|
|
|
$lines[] = '<strong>'.$key.':</strong> '.$val;
|
|
|
|
}
|
|
|
|
return '<ul><li>'.implode('</li><li>', $lines).'</li></ul>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-24 21:37:47 +00:00
|
|
|
* @see \wcf\system\chat\command\ICommand::getReceiver()
|
2012-03-23 22:27:15 +00:00
|
|
|
*/
|
|
|
|
public function getReceiver() {
|
|
|
|
return \wcf\system\WCF::getUser()->userID;
|
|
|
|
}
|
|
|
|
}
|