1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Remove text/plain output

This commit is contained in:
Tim Düsterhus 2013-03-19 18:20:40 +01:00
parent 805d7a3a11
commit 90b27972b0
4 changed files with 10 additions and 56 deletions

View File

@ -57,7 +57,7 @@ public function __toString() {
* @param string $outputType outputtype for messageparser * @param string $outputType outputtype for messageparser
* @return string * @return string
*/ */
public function getFormattedMessage($outputType = 'text/html') { public function getFormattedMessage() {
$message = $this->message; $message = $this->message;
switch ($this->type) { switch ($this->type) {
@ -70,24 +70,15 @@ public function getFormattedMessage($outputType = 'text/html') {
case self::TYPE_MODERATE: case self::TYPE_MODERATE:
$message = unserialize($message); $message = unserialize($message);
$message = WCF::getLanguage()->getDynamicVariable('chat.message.'.$this->type.'.'.$message['type'], $message ?: array()); $message = WCF::getLanguage()->getDynamicVariable('chat.message.'.$this->type.'.'.$message['type'], $message ?: array());
$message = self::replaceUserLink($message, $outputType);
break; break;
case self::TYPE_WHISPER: case self::TYPE_WHISPER:
$message = unserialize($message); $message = unserialize($message);
$message = $message['message']; $message = $message['message'];
case self::TYPE_NORMAL: case self::TYPE_NORMAL:
case self::TYPE_ME: case self::TYPE_ME:
$messageParser = \wcf\system\bbcode\MessageParser::getInstance();
$messageParser->setOutputType($outputType);
$message = $messageParser->parse($message, $this->enableSmilies, $this->enableHTML, true, false);
break;
default: default:
if ($this->enableHTML) {
$message = self::replaceUserLink($message, $outputType);
}
$messageParser = \wcf\system\bbcode\MessageParser::getInstance(); $messageParser = \wcf\system\bbcode\MessageParser::getInstance();
$messageParser->setOutputType($outputType); $messageParser->setOutputType('text/html');
$message = $messageParser->parse($message, $this->enableSmilies, $this->enableHTML, true, false); $message = $messageParser->parse($message, $this->enableSmilies, $this->enableHTML, true, false);
break; break;
} }
@ -118,45 +109,6 @@ public function getUsername($colored = false) {
return $username; return $username;
} }
/**
* Replaces a userLink in a message.
*/
public static function replaceUserLink($message, $outputType) {
static $regex = null;
if ($regex === null) $regex = new Regex('<span class="userLink" data-user-id="(\d+)" />');
if ($outputType === 'text/html') {
return $regex->replace($message, new \wcf\system\Callback(function ($matches) {
return self::getUserLink($matches[1]);
}));
}
else {
return $regex->replace($message, new \wcf\system\Callback(function ($matches) {
self::getUserLink($matches[1]);
return self::$users[$matches[1]]->username;
}));
}
}
/**
* Returns a fully colored userlink.
*/
public static function getUserLink($userID) {
if (!isset(self::$users[$userID])) {
self::$users[$userID] = $user = new \wcf\data\user\User($userID);
// Username + link to profile
$color = ChatUtil::readUserData('color', $user);
$profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array(
'object' => $user
));
self::$users[$userID]->userLink = '<a href="'.$profile.'" class="userLink" data-user-id="'.$user->userID.'">'.ChatUtil::gradient($user->username, $color[1], $color[2]).'</a>';
}
return self::$users[$userID]->userLink;
}
/** /**
* Converts this message into json-form. * Converts this message into json-form.
* *
@ -181,7 +133,7 @@ public function jsonify($raw = false) {
'formattedMessage' => $this->getFormattedMessage(), 'formattedMessage' => $this->getFormattedMessage(),
'formattedTime' => \wcf\util\DateUtil::format(\wcf\util\DateUtil::getDateTimeByTimestamp($this->time), 'H:i:s'), 'formattedTime' => \wcf\util\DateUtil::format(\wcf\util\DateUtil::getDateTimeByTimestamp($this->time), 'H:i:s'),
'separator' => $separator, 'separator' => $separator,
'message' => $this->getFormattedMessage('text/plain'), 'message' => $this->message,
'sender' => (int) $this->sender, 'sender' => (int) $this->sender,
'username' => $this->getUsername(), 'username' => $this->getUsername(),
'time' => (int) $this->time, 'time' => (int) $this->time,

View File

@ -26,11 +26,10 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException(rtrim($commandHandler->getParameters(), ',')); if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException(rtrim($commandHandler->getParameters(), ','));
// Username + link to profile // Username + link to profile
$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' => $this->user 'object' => $this->user
)); ));
$this->lines[WCF::getLanguage()->get('wcf.user.username')] = '<span class="userLink" data-user-id="'.$this->user->userID.'" />'; $this->lines[WCF::getLanguage()->get('wcf.user.username')] = "[url='".$profile."']".$this->user->username.'[/url]';
// Away-Status // Away-Status
if (ChatUtil::readUserData('away', $this->user) !== null) { if (ChatUtil::readUserData('away', $this->user) !== null) {

View File

@ -30,7 +30,10 @@ public function getMessage() {
$users = $room->getUsers(); $users = $room->getUsers();
$tmp = array(); $tmp = array();
foreach ($users as $user) { foreach ($users as $user) {
$tmp[] = '<span class="userLink" data-user-id="'.$user->userID.'" />'; $profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array(
'object' => $user
));
$tmp[] = "[url='".$profile."']".$user->username.'[/url]';
} }
if (!empty($tmp)) $lines[] = '[b]'.$room.':[/b] '.implode(', ', $tmp); if (!empty($tmp)) $lines[] = '[b]'.$room.':[/b] '.implode(', ', $tmp);
} }