1
0
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:
Tim Düsterhus 2012-03-23 23:27:15 +01:00
parent 068670ae66
commit 01be519230
5 changed files with 98 additions and 11 deletions

View File

@ -15,6 +15,7 @@
* @subpackage form * @subpackage form
*/ */
class ChatForm extends AbstractForm { class ChatForm extends AbstractForm {
public $enableHTML = 0;
public $enableSmilies = 1; public $enableSmilies = 1;
public $neededPermissions = array('user.chat.canEnter'); public $neededPermissions = array('user.chat.canEnter');
public $message = ''; public $message = '';
@ -79,6 +80,7 @@ public function save() {
$command = $commandHandler->loadCommand(); $command = $commandHandler->loadCommand();
if ($command->enableSmilies != \wcf\system\chat\commands\ICommand::SMILEY_USER) $this->enableSmilies = $command->enableSmilies; if ($command->enableSmilies != \wcf\system\chat\commands\ICommand::SMILEY_USER) $this->enableSmilies = $command->enableSmilies;
$this->enableHTML = $command->enableHTML;
$type = $command->getType(); $type = $command->getType();
$this->message = $command->getMessage(); $this->message = $command->getMessage();
$receiver = $command->getReceiver(); $receiver = $command->getReceiver();
@ -88,6 +90,11 @@ public function save() {
$type = chat\message\ChatMessage::TYPE_ERROR; $type = chat\message\ChatMessage::TYPE_ERROR;
$receiver = WCF::getUser()->userID; $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) { catch (\wcf\system\exception\PermissionDeniedException $e) {
$this->message = WCF::getLanguage()->get('wcf.chat.command.error.permissionDenied'); $this->message = WCF::getLanguage()->get('wcf.chat.command.error.permissionDenied');
$type = chat\message\ChatMessage::TYPE_ERROR; $type = chat\message\ChatMessage::TYPE_ERROR;
@ -131,6 +138,7 @@ public function save() {
'type' => $type, 'type' => $type,
'message' => $this->message, 'message' => $this->message,
'enableSmilies' => $this->enableSmilies, 'enableSmilies' => $this->enableSmilies,
'enableHTML' => $this->enableHTML,
'color1' => $this->userData['color'][1], 'color1' => $this->userData['color'][1],
'color2' => $this->userData['color'][2] 'color2' => $this->userData['color'][2]
) )
@ -144,7 +152,7 @@ public function save() {
* @see \wcf\page\IPage::show() * @see \wcf\page\IPage::show()
*/ */
public function show() { public function show() {
//header("HTTP/1.0 204 No Content"); header("HTTP/1.0 204 No Content");
parent::show(); parent::show();
} }
} }

View File

@ -13,6 +13,7 @@
*/ */
abstract class AbstractCommand implements ICommand { abstract class AbstractCommand implements ICommand {
public $commandHandler = null; public $commandHandler = null;
public $enableHTML = 0;
public function __construct(CommandHandler $commandHandler) { public function __construct(CommandHandler $commandHandler) {
EventHandler::getInstance()->fireAction($this, 'shouldInit'); EventHandler::getInstance()->fireAction($this, 'shouldInit');

View File

@ -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;
}
}

View 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;
}
}

View File

@ -88,30 +88,32 @@ public static function gradient($string, $start, $end) {
/** /**
* Reads user data. * Reads user data.
* *
* @param string $field * @param string $field
* @param \wcf\data\user\User $user
* @return mixed * @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(); $ush = UserStorageHandler::getInstance();
$packageID = self::getPackageID(); $packageID = self::getPackageID();
// load storage // load storage
$ush->loadStorage(array(WCF::getUser()->userID), $packageID); $ush->loadStorage(array($user->userID), $packageID);
$data = $ush->getStorage(array(WCF::getUser()->userID), $field, $packageID); $data = $ush->getStorage(array($user->userID), $field, $packageID);
if ($data[WCF::getUser()->userID] === null) { if ($data[$user->userID] === null) {
switch ($field) { switch ($field) {
case 'color': 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; 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]); if (isset(static::$serialize[$field])) return unserialize($data[$user->userID]);
else return $data[WCF::getUser()->userID]; else return $data[$user->userID];
} }
/** /**