mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-10-31 14:10:08 +00:00
Add possibility to use BBCodes
This commit is contained in:
parent
d2f23cb5a7
commit
539dcb2a4e
@ -77,7 +77,12 @@ public function getFormattedMessage($outputType = 'text/html') {
|
||||
$message = $message['message'];
|
||||
case self::TYPE_NORMAL:
|
||||
case self::TYPE_ME:
|
||||
if (!$this->enableHTML && $outputType == 'text/html') {
|
||||
if ($this->enableBBCodes) {
|
||||
$messageParser = \wcf\system\bbcode\MessageParser::getInstance();
|
||||
$messageParser->setOutputType($outputType);
|
||||
$message = $messageParser->parse($message, $this->enableSmilies, $this->enableHTML, true, false);
|
||||
}
|
||||
else if (!$this->enableHTML && $outputType == 'text/html') {
|
||||
$message = \wcf\system\bbcode\SimpleMessageParser::getInstance()->parse($message, true, $this->enableSmilies);
|
||||
}
|
||||
break;
|
||||
@ -85,6 +90,12 @@ public function getFormattedMessage($outputType = 'text/html') {
|
||||
if ($this->enableHTML) {
|
||||
$message = self::replaceUserLink($message, $outputType);
|
||||
}
|
||||
|
||||
if ($this->enableBBCodes) {
|
||||
$messageParser = \wcf\system\bbcode\MessageParser::getInstance();
|
||||
$messageParser->setOutputType($outputType);
|
||||
$message = $messageParser->parse($message, $this->enableSmilies, $this->enableHTML, true, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,13 @@ class ChatForm extends AbstractForm {
|
||||
*/
|
||||
public $enableHTML = 0;
|
||||
|
||||
/**
|
||||
* Should bbcodes be enabled for this message.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $enableBBCodes = CHAT_ENABLE_BBCODES;
|
||||
|
||||
/**
|
||||
* Should smilies be enabled for this message.
|
||||
*
|
||||
@ -82,7 +89,7 @@ class ChatForm extends AbstractForm {
|
||||
* @see wcf\page\IPage::__run()
|
||||
*/
|
||||
public function __run() {
|
||||
if (($this->request = \wcf\system\request\RequestHandler::getInstance()->getActiveRequest()->getRequestObject()) === $this) throw new IllegalLinkException();
|
||||
if (($this->request = \wcf\system\request\RequestHandler::getInstance()->getActiveRequest()->getRequestObject()) === $this) throw new \wcf\system\exception\IllegalLinkException();
|
||||
|
||||
parent::__run();
|
||||
}
|
||||
@ -141,8 +148,10 @@ public function save() {
|
||||
try {
|
||||
$command = $commandHandler->loadCommand();
|
||||
|
||||
if ($command->enableSmilies != \wcf\system\chat\command\ICommand::SMILEY_USER) $this->enableSmilies = $command->enableSmilies;
|
||||
if ($command->enableSmilies != \wcf\system\chat\command\ICommand::SETTING_USER) $this->enableSmilies = $command->enableSmilies;
|
||||
$this->enableHTML = $command->enableHTML;
|
||||
if ($command->enableBBCodes != \wcf\system\chat\command\ICommand::SETTING_USER) $this->enableBBCodes = $command->enableBBCodes;
|
||||
|
||||
$type = $command->getType();
|
||||
$this->message = $command->getMessage();
|
||||
$receiver = $command->getReceiver();
|
||||
@ -202,6 +211,7 @@ public function save() {
|
||||
'message' => $this->message,
|
||||
'enableSmilies' => $this->enableSmilies,
|
||||
'enableHTML' => $this->enableHTML,
|
||||
'enableBBCodes' => $this->enableBBCodes,
|
||||
'color1' => $this->userData['color'][1],
|
||||
'color2' => $this->userData['color'][2]
|
||||
)
|
||||
|
@ -23,18 +23,30 @@ abstract class AbstractCommand implements ICommand {
|
||||
* Should HTML be enabled?
|
||||
*
|
||||
* @var integer
|
||||
* @see \wcf\system\chat\command\ICommand::SETTING_OFF
|
||||
* @see \wcf\system\chat\command\ICommand::SETTING_ON
|
||||
*/
|
||||
public $enableHTML = 0;
|
||||
public $enableHTML = ICommand::SETTING_OFF;
|
||||
|
||||
/**
|
||||
* Should BBCodes be enabled?
|
||||
*
|
||||
* @var integer
|
||||
* @see \wcf\system\chat\command\ICommand::SETTING_OFF
|
||||
* @see \wcf\system\chat\command\ICommand::SETTING_ON
|
||||
* @see \wcf\system\chat\command\ICommand::SETTING_USER
|
||||
*/
|
||||
public $enableBBCodes = ICommand::SETTING_OFF;
|
||||
|
||||
/**
|
||||
* Should smilies be enabled?
|
||||
*
|
||||
* @var integer
|
||||
* @see \wcf\system\chat\command\ICommand::SMILEY_OFF
|
||||
* @see \wcf\system\chat\command\ICommand::SMILEY_ON
|
||||
* @see \wcf\system\chat\command\ICommand::SMILEY_USER
|
||||
* @see \wcf\system\chat\command\ICommand::SETTING_OFF
|
||||
* @see \wcf\system\chat\command\ICommand::SETTING_ON
|
||||
* @see \wcf\system\chat\command\ICommand::SETTING_USER
|
||||
*/
|
||||
public $enableSmilies = ICommand::SMILEY_OFF;
|
||||
public $enableSmilies = ICommand::SETTING_OFF;
|
||||
|
||||
public function __construct(CommandHandler $commandHandler) {
|
||||
EventHandler::getInstance()->fireAction($this, 'shouldInit');
|
||||
|
@ -70,7 +70,7 @@ public function loadCommand() {
|
||||
$parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2);
|
||||
|
||||
if ($this->isCommand($parts[0])) {
|
||||
return new commands\Plain($this);
|
||||
return new commands\PlainCommand($this);
|
||||
}
|
||||
|
||||
$class = '\wcf\system\chat\command\commands\\'.ucfirst(strtolower($parts[0])).'Command';
|
||||
|
@ -12,25 +12,25 @@
|
||||
*/
|
||||
interface ICommand {
|
||||
/**
|
||||
* Smilies are forced to be disabled.
|
||||
* Setting is forced to be disabled.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const SMILEY_OFF = 0;
|
||||
const SETTING_OFF = 0;
|
||||
|
||||
/**
|
||||
* Smilies are forced to be enabled.
|
||||
* Setting is forced to be enabled.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const SMILEY_ON = 1;
|
||||
const SETTING_ON = 1;
|
||||
|
||||
/**
|
||||
* The user may decide whether smilies are on or off.
|
||||
* The user may decide whether this setting is on or off.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const SMILEY_USER = 2;
|
||||
const SETTING_USER = 2;
|
||||
|
||||
/**
|
||||
* Returns the message-type for this command.
|
||||
|
@ -15,7 +15,8 @@
|
||||
* @subpackage system.chat.command.commands
|
||||
*/
|
||||
class InfoCommand extends \wcf\system\chat\command\AbstractCommand {
|
||||
public $enableHTML = 1;
|
||||
public $enableBBCodes = self::SETTING_ON;
|
||||
public $enableHTML = self::SETTING_ON;
|
||||
public $lines = array();
|
||||
public $user = null;
|
||||
|
||||
@ -86,9 +87,9 @@ public function getType() {
|
||||
public function getMessage() {
|
||||
$lines = array();
|
||||
foreach ($this->lines as $key => $val) {
|
||||
$lines[] = '<strong>'.$key.':</strong> '.$val;
|
||||
$lines[] = '[b]'.$key.':[/b] '.$val;
|
||||
}
|
||||
return '<ul><li>'.implode('</li><li>', $lines).'</li></ul>';
|
||||
return '[list][*]'.implode('[*]', $lines).'[/list]';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,14 +24,7 @@ public function __construct(\wcf\system\chat\command\CommandHandler $commandHand
|
||||
$this->user = User::getUserByUsername(rtrim($commandHandler->getParameters(), ','));
|
||||
if (!$this->user->userID) throw new \wcf\system\chat\command\UserNotFoundException(rtrim($commandHandler->getParameters(), ','));
|
||||
|
||||
// Username + link to profile
|
||||
$color = array(1 => ChatUtil::getRandomNumber(), 2 => ChatUtil::getRandomNumber() * 0xFFFF);
|
||||
ChatUtil::writeUserData(array('color' => $color), $this->user);
|
||||
|
||||
$profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array(
|
||||
'object' => $this->user
|
||||
));
|
||||
$this->link = '<a href="'.$profile.'" class="userLink" data-user-id="'.$this->user->userID.'">'.ChatUtil::gradient($this->user->username, $color[1], $color[2]).'</a>';
|
||||
$this->link = '<span class="userLink" data-user-id="'.$this->user->userID.'" />';
|
||||
|
||||
$this->didInit();
|
||||
}
|
||||
|
@ -11,7 +11,8 @@
|
||||
* @subpackage system.chat.command.commands
|
||||
*/
|
||||
class WhereCommand extends \wcf\system\chat\command\AbstractCommand {
|
||||
public $enableHTML = 1;
|
||||
public $enableHTML = self::SETTING_ON;
|
||||
public $enableBBCodes = self::SETTING_ON;
|
||||
|
||||
/**
|
||||
* @see \wcf\system\chat\command\ICommand::getType()
|
||||
@ -30,16 +31,12 @@ public function getMessage() {
|
||||
$users = $room->getUsers();
|
||||
$tmp = array();
|
||||
foreach ($users as $user) {
|
||||
$profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array(
|
||||
'object' => $user
|
||||
));
|
||||
|
||||
$tmp[] = '<a href="'.$profile.'">'.$user.'</a>';
|
||||
$tmp[] = '<span class="userLink" data-user-id="'.$user->userID.'" />';
|
||||
}
|
||||
if (!empty($tmp)) $lines[] = '<strong>'.$room.':</strong> '.implode(', ', $tmp);
|
||||
if (!empty($tmp)) $lines[] = '[b]'.$room.':[/b] '.implode(', ', $tmp);
|
||||
}
|
||||
|
||||
return '<ul><li>'.implode('</li><li>', $lines).'</li></ul>';
|
||||
return '[list][*]'.implode('[*]', $lines).'[/list]';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,6 +18,7 @@ CREATE TABLE wcf1_chat_message (
|
||||
type TINYINT(3) NOT NULL DEFAULT 1,
|
||||
message MEDIUMTEXT NOT NULL,
|
||||
enableSmilies TINYINT(1) NOT NULL DEFAULT 1,
|
||||
enableBBCodes TINYINT(1) NOT NULL DEFAULT 0,
|
||||
enableHTML TINYINT(1) NOT NULL DEFAULT 0,
|
||||
color1 INT(10) NOT NULL DEFAULT 0,
|
||||
color2 INT(10) NOT NULL DEFAULT 0,
|
||||
|
@ -37,6 +37,12 @@
|
||||
<defaultvalue>1</defaultvalue>
|
||||
<showorder>5</showorder>
|
||||
</option>
|
||||
<option name="chat_enable_bbcodes">
|
||||
<categoryname>chat.general</categoryname>
|
||||
<optiontype>boolean</optiontype>
|
||||
<defaultvalue>1</defaultvalue>
|
||||
<showorder>6</showorder>
|
||||
</option>
|
||||
<option name="chat_max_length">
|
||||
<categoryname>chat.general</categoryname>
|
||||
<optiontype>integer</optiontype>
|
||||
|
Loading…
Reference in New Issue
Block a user