--- get-recent-comments-2.0.4.5.php.orig Fri Nov 14 17:30:13 2008
+++ get-recent-comments-2.0.4.5.php Fri Nov 14 21:22:15 2008
@@ -1069,6 +1069,7 @@
{
// kjgrc_log("kjgrc_get_comments2 $caller");
// echo "kjgrc_get_comments2 $requested_comment_type $caller
";
+ mb_regex_encoding(mb_internal_encoding());
global $wpdb;
$batch_number = 0;
$number_of_comments = 0;
@@ -1302,8 +1303,8 @@
$trackback_title = preg_replace("/^(.+?)<\/strong>.*/s","$1",$comment->comment_content);
$trackback_title = strip_tags($trackback_title);
$trackback_title = preg_replace("/[\n\t\r]/"," ",$trackback_title);
+ $trackback_title = mb_ereg_replace('([^\s]{'.$chars_per_word.'})','\\1 ', $trackback_title); // split long words
$trackback_title = preg_replace("/\s{2,}/"," ",$trackback_title);
- $trackback_title = wordwrap($trackback_title,$chars_per_word,' ',1);
$comment_excerpt = preg_replace("/^.+?<\/strong>/","",$comment->comment_content,1);
$comment_author = $comment->comment_author;
@@ -1317,8 +1318,8 @@
$comment_excerpt = strip_tags(wptexturize($comment_excerpt));
$comment_excerpt = preg_replace("/[\n\t\r]/"," ",$comment_excerpt); // whitespace into 1 blank
+ $comment_excerpt = mb_ereg_replace('([^\s]{'.$chars_per_word.'})','\\1 ', $comment_excerpt); // split long words
$comment_excerpt = preg_replace("/\s{2,}/"," ",$comment_excerpt); // whitespace into 1 blank
- $comment_excerpt = wordwrap($comment_excerpt,$chars_per_word,' ',1);
if ($trackback_title == '')
$trackback_title = $comment_excerpt;
@@ -1558,17 +1559,21 @@
function kjgrc_excerpt ($text,$chars_per_comment,$chars_per_word,$tag,$output)
{
- $length = strlen(str_replace($tag,"",strip_tags($output)));
+ $length = mb_strlen(str_replace($tag,"",strip_tags($output)));
$length = $chars_per_comment - $length;
$length = $length -2; // we will add three dots at the end
if ($length < 0) $length = 0;
- if (strlen($text) > $length) {
- $text = substr($text,0,$length);
- $text = substr($text,0,strrpos($text,' '));
- // last word exceeds max word length:
- if ((strlen($text) - strrpos($text,' ')) > $chars_per_word) {
- $text = substr($text,0,strlen($text)-3);
- }
+ if (mb_strlen($text) > $length) {
+ $text = mb_substr($text,0,$length);
+ if ((mb_strlen($text) - mb_strrpos($text,' ')) < $chars_per_word-1) {
+ $text = mb_substr($text,0,mb_strrpos($text,' '));
+ }
+ // last word has max word length:
+ if ((mb_strlen($text) - mb_strrpos($text,' ')) > $chars_per_word-2)
+ {
+ $text = mb_substr($text,0,mb_strlen($text)-3);
+ }
+
$text = $text . "...";
}
#$text = "[EXCERPT]: '$text'";