mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2025-01-02 23:20:08 +00:00
Adding InfoCommand
This commit is contained in:
parent
068670ae66
commit
01be519230
@ -15,6 +15,7 @@
|
||||
* @subpackage form
|
||||
*/
|
||||
class ChatForm extends AbstractForm {
|
||||
public $enableHTML = 0;
|
||||
public $enableSmilies = 1;
|
||||
public $neededPermissions = array('user.chat.canEnter');
|
||||
public $message = '';
|
||||
@ -79,6 +80,7 @@ public function save() {
|
||||
$command = $commandHandler->loadCommand();
|
||||
|
||||
if ($command->enableSmilies != \wcf\system\chat\commands\ICommand::SMILEY_USER) $this->enableSmilies = $command->enableSmilies;
|
||||
$this->enableHTML = $command->enableHTML;
|
||||
$type = $command->getType();
|
||||
$this->message = $command->getMessage();
|
||||
$receiver = $command->getReceiver();
|
||||
@ -88,6 +90,11 @@ public function save() {
|
||||
$type = chat\message\ChatMessage::TYPE_ERROR;
|
||||
$receiver = WCF::getUser()->userID;
|
||||
}
|
||||
catch (\wcf\system\chat\commands\UserNotFoundException $e) {
|
||||
$this->message = WCF::getLanguage()->get('wcf.chat.command.error.userNotFound');
|
||||
$type = chat\message\ChatMessage::TYPE_ERROR;
|
||||
$receiver = WCF::getUser()->userID;
|
||||
}
|
||||
catch (\wcf\system\exception\PermissionDeniedException $e) {
|
||||
$this->message = WCF::getLanguage()->get('wcf.chat.command.error.permissionDenied');
|
||||
$type = chat\message\ChatMessage::TYPE_ERROR;
|
||||
@ -131,6 +138,7 @@ public function save() {
|
||||
'type' => $type,
|
||||
'message' => $this->message,
|
||||
'enableSmilies' => $this->enableSmilies,
|
||||
'enableHTML' => $this->enableHTML,
|
||||
'color1' => $this->userData['color'][1],
|
||||
'color2' => $this->userData['color'][2]
|
||||
)
|
||||
@ -144,7 +152,7 @@ public function save() {
|
||||
* @see \wcf\page\IPage::show()
|
||||
*/
|
||||
public function show() {
|
||||
//header("HTTP/1.0 204 No Content");
|
||||
header("HTTP/1.0 204 No Content");
|
||||
parent::show();
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
*/
|
||||
abstract class AbstractCommand implements ICommand {
|
||||
public $commandHandler = null;
|
||||
public $enableHTML = 0;
|
||||
|
||||
public function __construct(CommandHandler $commandHandler) {
|
||||
EventHandler::getInstance()->fireAction($this, 'shouldInit');
|
||||
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace wcf\system\chat\commands;
|
||||
|
||||
/**
|
||||
* Thrown when a user is not found.
|
||||
*
|
||||
* @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
|
||||
* @subpackage system.chat.commands
|
||||
*/
|
||||
class UserNotFoundException extends \Exception {
|
||||
private $username = '';
|
||||
|
||||
public function __construct($username) {
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
public function getUsername() {
|
||||
return $this->username;
|
||||
}
|
||||
}
|
53
file/lib/system/chat/commands/commands/Info.class.php
Normal file
53
file/lib/system/chat/commands/commands/Info.class.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace wcf\system\chat\commands\commands;
|
||||
use \wcf\system\WCF;
|
||||
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
|
||||
* @subpackage system.chat.commands.commands
|
||||
*/
|
||||
class Info extends \wcf\system\chat\commands\AbstractCommand {
|
||||
public $enableSmilies = \wcf\system\chat\commands\ICommand::SMILEY_OFF;
|
||||
public $enableHTML = 1;
|
||||
private $lines = array();
|
||||
|
||||
public function __construct(\wcf\system\chat\commands\CommandHandler $commandHandler) {
|
||||
parent::__construct($commandHandler);
|
||||
|
||||
$user = \wcf\data\user\User::getUserByUsername(rtrim($commandHandler->getParameters(), ','));
|
||||
if (!$user->userID) throw new \wcf\system\chat\commands\UserNotFoundException(rtrim($commandHandler->getParameters(), ','));
|
||||
$color = \wcf\util\ChatUtil::readUserData('color', $user);
|
||||
$this->lines[WCF::getLanguage()->get('wcf.user.username')] = \wcf\util\ChatUtil::gradient($user->username, $color[1], $color[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \wcf\system\chat\commands\ICommand::getType()
|
||||
*/
|
||||
public function getType() {
|
||||
return \wcf\data\chat\message\ChatMessage::TYPE_INFORMATION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \wcf\system\chat\commands\ICommand::getMessage()
|
||||
*/
|
||||
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>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \wcf\system\chat\commands\ICommand::getReceiver()
|
||||
*/
|
||||
public function getReceiver() {
|
||||
return \wcf\system\WCF::getUser()->userID;
|
||||
}
|
||||
}
|
@ -89,29 +89,31 @@ public static function gradient($string, $start, $end) {
|
||||
* Reads user data.
|
||||
*
|
||||
* @param string $field
|
||||
* @param \wcf\data\user\User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public static function readUserData($field) {
|
||||
public static function readUserData($field, \wcf\data\user\User $user = null) {
|
||||
if ($user === null) $user = WCF::getUser();
|
||||
$ush = UserStorageHandler::getInstance();
|
||||
$packageID = self::getPackageID();
|
||||
|
||||
// load storage
|
||||
$ush->loadStorage(array(WCF::getUser()->userID), $packageID);
|
||||
$data = $ush->getStorage(array(WCF::getUser()->userID), $field, $packageID);
|
||||
$ush->loadStorage(array($user->userID), $packageID);
|
||||
$data = $ush->getStorage(array($user->userID), $field, $packageID);
|
||||
|
||||
if ($data[WCF::getUser()->userID] === null) {
|
||||
if ($data[$user->userID] === null) {
|
||||
switch ($field) {
|
||||
case 'color':
|
||||
$data[WCF::getUser()->userID] = array(1 => self::getRandomNumber(), 2 => self::getRandomNumber() * 0xFFFF);
|
||||
$data[$user->userID] = array(1 => self::getRandomNumber(), 2 => self::getRandomNumber() * 0xFFFF);
|
||||
break;
|
||||
}
|
||||
static::writeUserData(array($field => $data[WCF::getUser()->userID]));
|
||||
static::writeUserData(array($field => $data[$user->userID]));
|
||||
|
||||
return $data[WCF::getUser()->userID];
|
||||
return $data[$user->userID];
|
||||
}
|
||||
|
||||
if (isset(static::$serialize[$field])) return unserialize($data[WCF::getUser()->userID]);
|
||||
else return $data[WCF::getUser()->userID];
|
||||
if (isset(static::$serialize[$field])) return unserialize($data[$user->userID]);
|
||||
else return $data[$user->userID];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user