Update of /cvsroot/php-blog/serendipity/include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27113/include
Modified Files:
functions.inc.php functions_comments.inc.php lang.inc.php
Log Message:
use mb_* functions when available. I patched all strtolower/strtoupper/strlen/strpos/strrpos/substr/ucfirst calls which are related to possible UTF-8 input.
For performance reasons, there are native calls left which don't deal with UTF8 characters.
The callback routines for mb_* functions are inside include/lang.inc.php because we need the LANG_CHARSET constant information for the function, and the function needs to be loaded everywhere. compact.inc.php is loaded before languages, so we can'T put it in there.
Index: functions_comments.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions_comments.inc.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- functions_comments.inc.php 30 Nov 2004 11:27:55 -0000 1.7
+++ functions_comments.inc.php 2 Dec 2004 14:11:27 -0000 1.8
@@ -134,7 +134,7 @@
foreach ($comments as $comment) {
if ($comment['parent_id'] == $parent) {
$i++;
- $retval .= '<option value="' . $comment['id'] . '"'. ($selected == $comment['id'] || (isset($serendipity['POST']['replyTo']) && $comment['id'] == $serendipity['POST']['replyTo']) ? ' selected="selected"' : '') .'>' . str_repeat(' ', $level * 2) . '#' . $indent . $i . ': ' . (empty($comment['username']) ? ANONYMOUS : htmlspecialchars($comment['username'])) . ' ' . ON . ' ' . ucfirst(serendipity_strftime(DATE_FORMAT_SHORT, $comment['timestamp'])) . "</option>\n";
+ $retval .= '<option value="' . $comment['id'] . '"'. ($selected == $comment['id'] || (isset($serendipity['POST']['replyTo']) && $comment['id'] == $serendipity['POST']['replyTo']) ? ' selected="selected"' : '') .'>' . str_repeat(' ', $level * 2) . '#' . $indent . $i . ': ' . (empty($comment['username']) ? ANONYMOUS : htmlspecialchars($comment['username'])) . ' ' . ON . ' ' . serendipity_mb('ucfirst', serendipity_strftime(DATE_FORMAT_SHORT, $comment['timestamp'])) . "</option>\n";
$retval .= serendipity_generateCommentList($id, $comments, $selected, $comment['id'], $level + 1, $indent . $i . '.');
}
}
Index: lang.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/lang.inc.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- lang.inc.php 2 Dec 2004 10:54:55 -0000 1.3
+++ lang.inc.php 2 Dec 2004 14:11:28 -0000 1.4
@@ -31,5 +31,45 @@
}
}
+if (!defined('serendipity_MB_LOADED') && defined('serendipity_LANG_LOADED')) {
+ // Needs to be included here because we need access to constant LANG_CHARSET definied in languages (not available for compat.inc.php)
+
+ // Multibyte string functions wrapper:
+ // strlen(), strpos(), strrpos(), strtolower(), strtoupper(), substr(), ucfirst()
+ function serendipity_mb() {
+ static $mbstring = null;
+
+ if (is_null($mbstring)) {
+ $mbstring = (extension_loaded('mbstring') ? true : false);
+ if ($mbstring) {
+ mb_internal_encoding(LANG_CHARSET);
+ }
+ }
+
+ $args = func_get_args();
+ $func = $args[0];
+ unset($args[0]);
+
+ switch($func) {
+ case 'ucfirst':
+ // there's no mb_ucfirst, so emulate it
+ if ($mbstring) {
+ return mb_strtoupper(mb_substr($args[1], 0, 1)) . mb_strtolower(mb_substr($args[1], 1));
+ } else {
+ return ucfirst($args[1]);
+ }
+
+ default:
+ if ($mbstring) {
+ return call_user_func_array('mb_' . $func, $args);
+ } else {
+ return call_user_func_array($func, $args);
+ }
+ }
+ }
+
+ define('serendipity_MB_LOADED', true);
+}
+
/* vim: set sts=4 ts=4 expandtab : */
-?>
+?>
\ No newline at end of file
Index: functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions.inc.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- functions.inc.php 2 Dec 2004 10:54:55 -0000 1.8
+++ functions.inc.php 2 Dec 2004 14:11:27 -0000 1.9
@@ -17,7 +17,7 @@
function serendipity_truncateString($s, $len) {
if ( strlen($s) > ($len+3) ) {
- $s = substr($s, 0, $len) . '...';
+ $s = serendipity_mb('substr', $s, 0, $len) . '...';
}
return $s;
}
@@ -65,7 +65,7 @@
$cache[$format] = str_replace('%e', '%d', $cache[$format]);
}
}
- return ucfirst(serendipity_strftime($cache[$format], (int)$time, $useOffset));
+ return serendipity_mb('ucfirst', serendipity_strftime($cache[$format], (int)$time, $useOffset));
}
function serendipity_fetchTemplates() {
|