1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Expose user-object.

This commit is contained in:
Tim Düsterhus 2012-05-19 23:03:26 +02:00
parent 3456cacd32
commit aec5ba361f

View File

@ -17,34 +17,35 @@
class Info extends \wcf\system\chat\command\AbstractCommand { class Info extends \wcf\system\chat\command\AbstractCommand {
public $enableSmilies = \wcf\system\chat\command\ICommand::SMILEY_OFF; public $enableSmilies = \wcf\system\chat\command\ICommand::SMILEY_OFF;
public $enableHTML = 1; public $enableHTML = 1;
private $lines = array(); public $lines = array();
public $user = null;
public function __construct(\wcf\system\chat\command\CommandHandler $commandHandler) { public function __construct(\wcf\system\chat\command\CommandHandler $commandHandler) {
parent::__construct($commandHandler); parent::__construct($commandHandler);
$user = User::getUserByUsername(rtrim($commandHandler->getParameters(), ',')); $this->user = User::getUserByUsername(rtrim($commandHandler->getParameters(), ','));
if (!$user->userID) throw new \wcf\system\chat\command\UserNotFoundException(rtrim($commandHandler->getParameters(), ',')); if (!$this->user->userID) throw new \wcf\system\chat\command\UserNotFoundException(rtrim($commandHandler->getParameters(), ','));
// Username + link to profile // Username + link to profile
$color = ChatUtil::readUserData('color', $user); $color = ChatUtil::readUserData('color', $this->user);
$profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array( $profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array(
'object' => $user 'object' => $this->user
)); ));
$this->lines[WCF::getLanguage()->get('wcf.user.username')] = '<a href="'.$profile.'">'.ChatUtil::gradient($user->username, $color[1], $color[2]).'</a>'; $this->lines[WCF::getLanguage()->get('wcf.user.username')] = '<a href="'.$profile.'">'.ChatUtil::gradient($this->user->username, $color[1], $color[2]).'</a>';
// Away-Status // Away-Status
if (ChatUtil::readUserData('away', $user) !== null) { if (ChatUtil::readUserData('away', $this->user) !== null) {
$this->lines[WCF::getLanguage()->get('wcf.chat.away')] = ChatUtil::readUserData('away', $user); $this->lines[WCF::getLanguage()->get('wcf.chat.away')] = ChatUtil::readUserData('away', $this->user);
} }
// Room // Room
$room = new \wcf\data\chat\room\ChatRoom(ChatUtil::readUserData('roomID', $user)); $room = new \wcf\data\chat\room\ChatRoom(ChatUtil::readUserData('roomID', $this->user));
if ($room->roomID && $room->canEnter()) { if ($room->roomID && $room->canEnter()) {
$this->lines[WCF::getLanguage()->get('wcf.chat.room')] = $room->getTitle(); $this->lines[WCF::getLanguage()->get('wcf.chat.room')] = $room->getTitle();
} }
// IP-Address // IP-Address
$session = $this->fetchSession($user); $session = $this->fetchSession();
if ($session) { if ($session) {
// TODO: Check permission // TODO: Check permission
$this->lines[WCF::getLanguage()->get('wcf.user.ipAddress')] = $session->ipAddress; $this->lines[WCF::getLanguage()->get('wcf.user.ipAddress')] = $session->ipAddress;
@ -58,7 +59,7 @@ public function __construct(\wcf\system\chat\command\CommandHandler $commandHand
* *
* @return \wcf\data\session\Session * @return \wcf\data\session\Session
*/ */
public function fetchSession(User $user) { public function fetchSession() {
$sql = "SELECT $sql = "SELECT
* *
FROM FROM
@ -66,7 +67,7 @@ public function fetchSession(User $user) {
WHERE WHERE
userID = ?"; userID = ?";
$stmt = WCF::getDB()->prepareStatement($sql); $stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(array($user->userID)); $stmt->execute(array($this->user->userID));
$row = $stmt->fetchArray(); $row = $stmt->fetchArray();
if (!$row) return false; if (!$row) return false;