1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-25 22:10:08 +00:00
Tims-Chat/file/lib/system/command/commands/InfoCommand.class.php

118 lines
3.7 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
/**
* 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);
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
if ($this->user->chatAway !== null) {
$this->lines[WCF::getLanguage()->get('wcf.chat.away')] = $this->user->chatAway;
2012-03-24 21:03:04 +00:00
}
2012-04-15 12:09:51 +00:00
// Room
$room = \chat\data\room\RoomCache::getInstance()->getRoom($this->user->chatRoomID);
if ($room !== null && $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
$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;
2013-06-22 15:40:24 +00:00
if (!$typeSuspension->isVisible()) continue;
2013-05-23 23:21:46 +00:00
$dateTime = DateUtil::getDateTimeByTimestamp($typeSuspension->expires);
2013-05-24 17:26:29 +00:00
$name = WCF::getLanguage()->getDynamicVariable('chat.general.information.suspension', array(
2013-05-24 00:21:49 +00:00
'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
}
}
// 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;
}
}