mirror of
https://github.com/Mibew/java.git
synced 2025-01-22 17:40:35 +03:00
Moved themeMessage method from ThreadProcessor to Thread
This commit is contained in:
parent
c26fc8bb26
commit
1528c610d7
@ -381,6 +381,55 @@ Class Thread {
|
||||
return $kind_names[$message_kind];
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme message to display in chat window
|
||||
*
|
||||
* @param array $message Message array
|
||||
* @return string Ready to display themed message
|
||||
*/
|
||||
public static function themeMessage($message) {
|
||||
global $webim_encoding;
|
||||
|
||||
// No theming for avatars
|
||||
if ($message['ikind'] == Thread::KIND_AVATAR) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Prepare messages fields
|
||||
$creation_date = date("H:i:s", $message['created']);
|
||||
$kind_name = Thread::kindToString($message['ikind']);
|
||||
$sender_name = $message['tname']
|
||||
? "<span class='n{$kind_name}'>" . htmlspecialchars($message['tname']) . "</span>: "
|
||||
: '';
|
||||
|
||||
// Prepare message text
|
||||
// Escape special chars
|
||||
$text = htmlspecialchars($message['tmessage']);
|
||||
// Replace URL's by <a> tags
|
||||
$text = preg_replace('/(https?|ftp):\/\/\S*/', '<a href="$0" target="_blank">$0</a>', $text);
|
||||
// Add <br> tags instead of \n chars
|
||||
$text = str_replace("\n", "<br/>", $text);
|
||||
// Span and storng tags available for system messages
|
||||
if ($message['ikind'] != Thread::KIND_USER && $message['ikind'] != Thread::KIND_AGENT) {
|
||||
$text = preg_replace('/<(span|strong)>(.*)<\/\1>/U', '<$1>$2</$1>', $text);
|
||||
$text = preg_replace(
|
||||
'/<span class="(.*)">(.*)<\/span>/U',
|
||||
'<span class="$1">$2</span>',
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
// Build result message
|
||||
$result = sprintf(
|
||||
"<span>%s</span> %s<span class='m%s'>%s</span><br/>",
|
||||
$creation_date,
|
||||
$sender_name,
|
||||
$kind_name,
|
||||
$text
|
||||
);
|
||||
return myiconv($webim_encoding, "utf-8", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return next revision number (last revision number plus one)
|
||||
*
|
||||
|
@ -224,55 +224,6 @@ class ThreadProcessor extends RequestProcessor {
|
||||
return $requests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme message to display in chat window
|
||||
*
|
||||
* @param array $message Message array
|
||||
* @return string Ready to display themed message
|
||||
*/
|
||||
protected function themeMessage($message) {
|
||||
global $webim_encoding;
|
||||
|
||||
// No theming for avatars
|
||||
if ($message['ikind'] == Thread::KIND_AVATAR) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Prepare messages fields
|
||||
$creation_date = date("H:i:s", $message['created']);
|
||||
$kind_name = Thread::kindToString($message['ikind']);
|
||||
$sender_name = $message['tname']
|
||||
? "<span class='n{$kind_name}'>" . htmlspecialchars($message['tname']) . "</span>: "
|
||||
: '';
|
||||
|
||||
// Prepare message text
|
||||
// Escape special chars
|
||||
$text = htmlspecialchars($message['tmessage']);
|
||||
// Replace URL's by <a> tags
|
||||
$text = preg_replace('/(https?|ftp):\/\/\S*/', '<a href="$0" target="_blank">$0</a>', $text);
|
||||
// Add <br> tags instead of \n chars
|
||||
$text = str_replace("\n", "<br/>", $text);
|
||||
// Span and storng tags available for system messages
|
||||
if ($message['ikind'] != Thread::KIND_USER && $message['ikind'] != Thread::KIND_AGENT) {
|
||||
$text = preg_replace('/<(span|strong)>(.*)<\/\1>/U', '<$1>$2</$1>', $text);
|
||||
$text = preg_replace(
|
||||
'/<span class="(.*)">(.*)<\/span>/U',
|
||||
'<span class="$1">$2</span>',
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
// Build result message
|
||||
$result = sprintf(
|
||||
"<span>%s</span> %s<span class='m%s'>%s</span><br/>",
|
||||
$creation_date,
|
||||
$sender_name,
|
||||
$kind_name,
|
||||
$text
|
||||
);
|
||||
return myiconv($webim_encoding, "utf-8", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send new messages to window
|
||||
*
|
||||
@ -287,7 +238,7 @@ class ThreadProcessor extends RequestProcessor {
|
||||
$messages = $thread->getMessages($is_user, $last_message_id);
|
||||
if (! empty($messages)) {
|
||||
foreach($messages as $key => $msg) {
|
||||
$messages[$key] = $this->themeMessage($msg);
|
||||
$messages[$key] = Thread::themeMessage($msg);
|
||||
}
|
||||
$this->responses[] = array(
|
||||
'token' => md5(time() . rand()),
|
||||
|
Loading…
Reference in New Issue
Block a user