[plugin_comments] Fix wordwrap at wound boundaries.
Add ChangeLog. Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
parent
9709592b7c
commit
95c71c36c9
4
plugins/serendipity_plugin_comments/ChangeLog
Normal file
4
plugins/serendipity_plugin_comments/ChangeLog
Normal file
@ -0,0 +1,4 @@
|
||||
Version 1.16:
|
||||
------------------------------------------------------------------------
|
||||
* Fix: wordwrap at word boundaries instead of "truncating" the lines
|
||||
|
@ -20,7 +20,7 @@ class serendipity_plugin_comments extends serendipity_plugin
|
||||
$propbag->add('description', PLUGIN_COMMENTS_BLAHBLAH);
|
||||
$propbag->add('stackable', true);
|
||||
$propbag->add('author', 'Garvin Hicking, Tadashi Jokagi, Judebert, G. Brockhaus');
|
||||
$propbag->add('version', '1.15');
|
||||
$propbag->add('version', '1.16');
|
||||
$propbag->add('requirements', array(
|
||||
'serendipity' => '1.6',
|
||||
'smarty' => '2.6.7',
|
||||
@ -193,6 +193,7 @@ class serendipity_plugin_comments extends serendipity_plugin
|
||||
|
||||
if ($sql && is_array($sql)) {
|
||||
foreach($sql AS $key => $row) {
|
||||
# truncate comment to $max_chars
|
||||
if (function_exists('mb_strimwidth')) {
|
||||
$comment = mb_strimwidth(strip_tags($row['comment']), 0, $max_chars, " [...]", LANG_CHARSET);
|
||||
} else {
|
||||
@ -228,14 +229,29 @@ class serendipity_plugin_comments extends serendipity_plugin
|
||||
$user = PLUGIN_COMMENTS_ANONYMOUS;
|
||||
}
|
||||
|
||||
if (function_exists('mb_strimwidth')) {
|
||||
# wrap lines at $wordwrap
|
||||
if (function_exists('mb_strimwidth') && function_exists('mb_strrpos') && function_exists('mb_substr')) {
|
||||
$pos = 0;
|
||||
$parts = array();
|
||||
$enc = LANG_CHARSET;
|
||||
$comment_len = mb_strlen($comment, $enc);
|
||||
# iterate over the (truncated) comment and wrap each line at $wordwrap
|
||||
while ($pos < $comment_len) {
|
||||
$part = mb_strimwidth($comment, $pos, $wordwrap, '', $enc);
|
||||
# do we still need to wrap this line or is it shorter than $wordwrap?
|
||||
if ($comment_len - $pos > $wordwrap) {
|
||||
# location of first space
|
||||
$spacepos = mb_strrpos(mb_substr($comment, $pos, $wordwrap, $enc), ' ', $enc);
|
||||
# wrap at word boundary if we have at least one space
|
||||
$part = ( $spacepos > 0 ) ? mb_substr($comment, $pos, $spacepos, $enc) : mb_strimwidth($comment, $pos, $wordwrap, '', $enc);;
|
||||
} else {
|
||||
# wrap "hard", i.e. truncate words that are too long
|
||||
$part = mb_substr($comment, $pos, $wordwrap, $enc);
|
||||
}
|
||||
# forward the pointer
|
||||
$pos += mb_strlen($part, $enc);
|
||||
# remove leading spaces
|
||||
$part = ltrim($part);
|
||||
# re-assemble the lines, i.e. add our current line
|
||||
$parts[] = $part;
|
||||
}
|
||||
$comment = implode("\n", $parts);
|
||||
|
Loading…
x
Reference in New Issue
Block a user