"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/formatter/highlight/chat.php" between
wacko.6.1.14.zip and wacko.6.1.15.zip

About: WackoWiki is a multilingual Wiki-engine that supports WYTIWYG-editing, page rights (ACLs), design themes (skins), file upload, email notification and much more.

chat.php  (wacko.6.1.14):chat.php  (wacko.6.1.15)
skipping to change at line 14 skipping to change at line 14
Supports various date-username-message chat log formats Supports various date-username-message chat log formats
Installation: copy to /wacko/formatter/highlight/chat.php Installation: copy to /wacko/formatter/highlight/chat.php
Usage: Usage:
%%(chat) %%(chat)
[12:04:34 01.05.2010] User: Message text by User. [12:04:34 01.05.2010] User: Message text by User.
%% %%
*/ */
// defaults
$options['type'] ??= 'div'; $options['type'] ??= 'div';
$options['user'] ??= 0; $options['user'] ??= 0;
// sanitize $text // sanitize $text
$text = htmlspecialchars($text); $text = htmlspecialchars($text);
$output = '';
// replace text links to HMTL // replace text links to HMTL
$text = preg_replace('/\b(https?|ftp|file|nntp|telnet):\/\/\S+/u', '<a href="\\0" target="_blank">\\0</a>', $text); $text = preg_replace('/\b(https?|ftp|file|nntp|telnet):\/\/\S+/u', '<a href="\\0" target="_blank">\\0</a>', $text);
$pattern = '/^[\[\(]([^\r\n\]\)]*)[\]\)]\s*(&lt;)?([^:\&\r\n]*)(&gt;)?\s*: ?((?:(?!^[\[\(]).*(?:\r?\n)*)*)/um'; $pattern = '/^[\[\(]([^\r\n\]\)]*)[\]\)]\s*(&lt;)?([^:\&\r\n]*)(&gt;)?\s*: ?((?:(?!^[\[\(]).*(?:\r?\n)*)*)/um';
// split the $text into $matches: $1 - date, $3 - username, $5 - message // split the $text into $matches: $1 - date, $3 - username, $5 - message
preg_match_all($pattern, $text, $matches, PREG_SET_ORDER); preg_match_all($pattern, $text, $matches, PREG_SET_ORDER);
// build the $names array of usernames in chat // build the $names array of usernames in chat
$names = []; $names = [];
$c = 1; $c = 1;
foreach($matches as $match) foreach($matches as $match)
{ {
if (!array_key_exists($match[3], $names)) if (!array_key_exists($match[3], $names))
{ {
$names[$match[3]] = $c++; $names[$match[3]] = $c++;
} }
} }
// HTML output: $type = match($options['type']){
'div' => 'd',
'table' => 't',
};
$tpl->enter($type . '_n_');
foreach($matches as $log) foreach($matches as $log)
{ {
if ($options['type'] == 'div') $tpl->name = $names[$log[3]];
{ $tpl->time = $log[1];
$output .= $tpl->user = $log[3];
'<div class="chat-u'. $names[$log[3]] .'">' . // replace \n to <br> to keep multiline messages
'<span class="chat-time">[' . $log[1] . ']</span> $tpl->text = str_replace("\n", '<br>', $log[5]);
' .
'<span class="chat-user">' . $log[3] . '</span> '
.
'<span class="chat-text">' . $log[5] . '</span>'
.
'</div>';
}
else if ($options['type'] == 'table')
{
$output .=
'<tr class="chat-u'. $names[$log[3]] .'">' .
'<td class="chat-user">' . $log[3] . '</td>' .
'<td class="chat-text">' . $log[5] . '</td>' .
'<td class="chat-time">' . $log[1] . '</td>' .
'</tr>';
}
} }
// replace \n to <br> to keep multiline messages $tpl->leave(); // d_ / t_
$output = str_replace("\n", '<br>', $output);
// show chat participants // show chat participants
if ($options['user']) if ($options['user'])
{ {
ksort($names); ksort($names);
$people = ''; $people = '';
foreach($names as $name => $v) foreach($names as $name => $v)
{ {
$people .= $name . ', '; $people .= $name . ', ';
} }
echo '<p><b>' . trim($people, ', ') . ':</b></p>'; $tpl->u_people = trim($people, ', ');
}
if ($options['type'] == 'div')
{
echo '<div class="chat">' . $output . '</div>';
}
else if ($options['type'] == 'table')
{
echo '<div><table class="chat">' . $output . '</table></div>';
} }
 End of changes. 6 change blocks. 
35 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)