📄 message.php
字号:
<?php
class Message {
var $id = null;
var $created = null;
var $toconnid = null;
var $touserid = null;
var $toroomid = null;
var $command = null;
var $userid = null;
var $roomid = null;
var $txt = null;
var $color = null;
function Message($command, $userid = null, $roomid = null, $txt = null, $color = null) {
$this->command = $command;
$this->userid = $userid;
$this->roomid = $roomid;
$this->color = htmlColor($color);
if(isset($txt)) {
$this->txt = $this->parse($txt);
}
}
function parse($txt) {
if($this->command != 'usrp') {
$txt = $this->replaceBadWord(htmlspecialchars($txt));
if($this->command == 'msg') $txt = $this->parseURL($txt);
}
return $txt;
}
function replaceBadWord($inputString) {
$replace_pairs = array( "<" => " <",
">" => "> "
);
$inputString = strtr ( $inputString, $replace_pairs);
$pattern = array();
$replacement = array();
$keys = array_keys($GLOBALS['fc_config']['badWords']);
for($i = 0; $i < count($keys); $i++)
{
if(is_numeric($keys[$i]))
{
$badword = $GLOBALS['fc_config']['badWords'][$keys[$i]];
$replacement[$i] = ' '.$GLOBALS['fc_config']['badWordSubstitute'].' ';
}
else
{
$badword = $keys[$i];
$replacement[$i] = ' '.$GLOBALS['fc_config']['badWords'][$keys[$i]].' ';
}
$badword = str_replace('*', '.?', $badword);
if(substr($badword, 0, 1) != '.') $badword = '(^|\s+)'.$badword;
if(substr($badword, -1) != '?') $badword = $badword.'($|\s+)';
$pattern[$i] = '/'.$badword.'/i';
}
$prev_str = '';
while(strcmp($prev_str,$inputString) != 0)
{
$prev_str = $inputString;
$inputString = preg_replace($pattern, $replacement, $inputString);
}
$replace_pairs = array( " <" => "<",
"> " => ">"
);
$inputString = strtr ( $inputString, $replace_pairs);
return $inputString;
}
function parseURL($inputString) {
$replace_pairs = array( "<" => " <",
">" => "> "
);
$inputString = strtr ( $inputString, $replace_pairs);
$inputTokens = explode(" ", $inputString);
$input = "";
foreach( $inputTokens as $token )
{
//smallest URL assumpted as a@a.us
if(strlen($token) > 5)
{
// check for email address
if (strpos($token, "@") !== false)
{
if(strpos($token, 'mailto:') === 0)
$token = substr($token, 7);
if(ereg("^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$",$token))
$token = "<a href=\"mailto:$token\" style=\"color:{$this->color}\"><u>$token</u></a>";
}
// check for https://, http://
else if((($pos = strpos($token, "http://")) !== false) ||
(($pos = strpos($token, "https://")) !== false)||
(($pos = strpos($token, "ftp://")) !== false))
{
$pref = substr($token, 0, $pos);
$link = substr($token, $pos);
if(strlen($link) > 8) $token = "$pref<a href=\"$link\" target=\"_blank\" style=\"color:{$this->color}\"><u>$link</u></a>";
}
// check for www.
else if(strpos($token, "www.") === 0) {
$token = "<a href=\"http://$token\" target=\"_blank\" style=\"color:{$this->color}\"><u>$token</u></a>";
}
}
$input .= $token." ";
}
$replace_pairs = array( " <" => "<",
"> " => ">"
);
$input = strtr ( $input, $replace_pairs);
return trim($input);
}
function toXML($tzoffset = 0) {
$xml = "<{$this->command}";
if($this->id) $xml .= " id=\"{$this->id}\"";
if($this->touserid) $xml .= " a=\"{$this->touserid}\"";
if($this->userid) $xml .= " u=\"{$this->userid}\"";
if($this->roomid) $xml .= " r=\"{$this->roomid}\"";
if($this->command == 'msgb') {
$user = ChatServer::getUser($this->userid);
$xml .= " l=\"{$user['login']}\"";
}
if($this->command == 'adu' || $this->command == 'lin') {
$user = ChatServer::getUser($this->userid);
$xml .= " rs=\"{$user['roles']}\"";
//$xml .= " gn=\"{$user['gender']}\"";
$gender = ChatServer::getGender($this->userid);
$xml .= " gn=\"{$gender}\"";
}
if($this->created) $xml .= " t=\"" . format_Timestamp($this->created, $tzoffset) . "\"";
if(isset($this->txt)) {
$xml .= "><![CDATA[{$this->txt}]]></{$this->command}>";
} else {
$xml .= "/>";
}
return $xml;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -