[geeklog-cvs] geeklog: Fixed handling of multi-byte encoded texts when limitin...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sat May 9 10:45:34 EDT 2009


details:   http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/5aca2dbf9ac3
changeset: 7016:5aca2dbf9ac3
user:      Dirk Haun <dirk at haun-online.de>
date:      Sat May 09 16:44:43 2009 +0200
description:
Fixed handling of multi-byte encoded texts when limiting the content of feed entries to a certain amount of characters

diffstat:

3 files changed, 34 insertions(+), 35 deletions(-)
public_html/docs/history   |    2 ++
system/lib-mbyte.php       |   42 ++++++++++++++++++++++--------------------
system/lib-syndication.php |   25 ++++++++++---------------

diffs (131 lines):

diff -r 9925b80d9681 -r 5aca2dbf9ac3 public_html/docs/history
--- a/public_html/docs/history	Thu May 07 12:22:39 2009 +0200
+++ b/public_html/docs/history	Sat May 09 16:44:43 2009 +0200
@@ -11,6 +11,8 @@
 + Comment moderation and editable comments, by Jared Wenerd
 
 Other changes:
+- Fixed handling of multi-byte encoded texts when limiting the content of feed
+  entries to a certain amount of characters (reported by alank) [Dirk]
 - Added a verbose logging option to the search class and make it default to off
   [Dirk]
 
diff -r 9925b80d9681 -r 5aca2dbf9ac3 system/lib-mbyte.php
--- a/system/lib-mbyte.php	Thu May 07 12:22:39 2009 +0200
+++ b/system/lib-mbyte.php	Sat May 09 16:44:43 2009 +0200
@@ -2,13 +2,13 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.5                                                               |
+// | Geeklog 1.6                                                               |
 // +---------------------------------------------------------------------------+
 // | lib-mbyte.php                                                             |
 // |                                                                           |
 // | function collection to handle mutli-byte related issues                   |
 // +---------------------------------------------------------------------------+
-// | Copyright (C) 2000-2008 by the following authors:                         |
+// | Copyright (C) 2000-2009 by the following authors:                         |
 // |                                                                           |
 // | Authors: Oliver Spiesshofer - oliver AT spiesshofer DOT com               |
 // +---------------------------------------------------------------------------+
@@ -28,8 +28,6 @@
 // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
 // |                                                                           |
 // +---------------------------------------------------------------------------+
-//
-// $Id: lib-mbyte.php,v 1.21 2008/09/21 08:37:11 dhaun Exp $
 
 if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-mbyte.php') !== false) {
     die('This file can not be used on its own!');
@@ -156,6 +154,26 @@
         $result = mb_strpos($hay, $needle, $offset);
     } else {
         $result = strpos($hay, $needle, $offset);
+    }
+
+    return $result;
+}
+
+function MBYTE_strrpos($hay, $needle, $offset = NULL)
+{
+    static $mb_enabled;
+
+    if (!isset($mb_enabled)) {
+        $mb_enabled = MBYTE_checkEnabled();
+    }
+    if ($mb_enabled) {
+        if ($offset === NULL) {
+            $result = mb_strrpos($hay, $needle);
+        } else {
+            $result = mb_strrpos($hay, $needle, $offset);
+        }
+    } else {
+        $result = strrpos($hay, $needle, $offset);
     }
 
     return $result;
@@ -243,22 +261,6 @@
     return $result;
 }
 
-function MBYTE_strrpos($hay, $needle, $offset='')
-{
-    static $mb_enabled;
-
-    if (!isset($mb_enabled)) {
-        $mb_enabled = MBYTE_checkEnabled();
-    }
-    if ($mb_enabled) {
-        $result = mb_strrpos($hay, $needle, $offset, 'utf-8');
-    } else {
-        $result = strrpos($hay, $needle, $offset);
-    }
-
-    return $result;
-}
-
 function MBYTE_mail($to, $subj, $mess, $header = NULL, $param = NULL)
 {
     static $mb_enabled;
diff -r 9925b80d9681 -r 5aca2dbf9ac3 system/lib-syndication.php
--- a/system/lib-syndication.php	Thu May 07 12:22:39 2009 +0200
+++ b/system/lib-syndication.php	Sat May 09 16:44:43 2009 +0200
@@ -621,27 +621,22 @@
 * @return   string              truncated text
 *
 */
-function SYND_truncateSummary( $text, $length )
+function SYND_truncateSummary($text, $length)
 {
-    if( $length == 0 )
-    {
+    if ($length == 0) {
         return '';
-    }
-    else
-    {
-        $text = stripslashes( $text );
-        $text = trim( $text );
+    } else {
+        $text = stripslashes($text);
+        $text = trim($text);
         $text = str_replace(array("\015\012", "\015"), "\012", $text);
-        if(( $length > 3 ) && ( MBYTE_strlen( $text ) > $length ))
-        {
-            $text = substr( $text, 0, $length - 3 ) . '...';
+        if (($length > 3) && (MBYTE_strlen($text) > $length)) {
+            $text = MBYTE_substr($text, 0, $length - 3) . '...';
         }
 
-        // Check if we broke html tag and storytext is now something
+        // Check if we broke an html tag and storytext is now something
         // like "blah blah <a href= ...". Delete "<*" if so.
-        if( strrpos( $text, '<' ) > strrpos( $text, '>' ))
-        {
-            $text = substr( $text, 0, strrpos( $text, '<' ) - 1 )
+        if (MBYTE_strrpos($text, '<' ) > MBYTE_strrpos($text, '>')) {
+            $text = MBYTE_substr($text, 0, MBYTE_strrpos($text, '<'))
                   . ' ...';
         }
 



More information about the geeklog-cvs mailing list