[wp-cvs] wordpress/wp-includes functions-formatting.php,1.43,1.44
Ryan Boren
rboren at users.sourceforge.net
Fri Sep 10 08:36:56 UTC 2004
Update of /cvsroot/cafelog/wordpress/wp-includes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12169/wp-includes
Modified Files:
functions-formatting.php
Log Message:
Incorporate utf8_uri_encode() in sanitize_title(). Improve UTF-8 accented character decomposition in remove_accents().
Index: functions-formatting.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/functions-formatting.php,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** functions-formatting.php 8 Sep 2004 08:48:36 -0000 1.43
--- functions-formatting.php 10 Sep 2004 08:36:54 -0000 1.44
***************
*** 98,121 ****
}
function remove_accents($string) {
- $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
- .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
- .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
- .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
- .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
- .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
- .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
- .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
- .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
- .chr(252).chr(253).chr(255);
- $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
if (seems_utf8($string)) {
! $invalid_latin_chars = array(chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe', chr(197).chr(160) => 'S', chr(197).chr(189) => 'Z', chr(197).chr(161) => 's', chr(197).chr(190) => 'z', chr(226).chr(130).chr(172) => 'E');
! $string = utf8_decode(strtr($string, $invalid_latin_chars));
}
! $string = strtr($string, $chars['in'], $chars['out']);
! $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
! $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
! $string = str_replace($double_chars['in'], $double_chars['out'], $string);
return $string;
}
--- 98,189 ----
}
+ function utf8_uri_encode( $utf8_string ) {
+ $unicode = '';
+ $values = array();
+ $num_octets = 1;
+
+ for ($i = 0; $i < strlen( $utf8_string ); $i++ ) {
+
+ $value = ord( $utf8_string[ $i ] );
+
+ if ( $value < 128 ) {
+ $unicode .= chr($value);
+ } else {
+ if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
+
+ $values[] = $value;
+
+ if ( count( $values ) == $num_octets ) {
+ if ($num_octets == 3) {
+ $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
+ } else {
+ $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
+ }
+
+ $values = array();
+ $num_octets = 1;
+ }
+ }
+ }
+
+ return $unicode;
+ }
+
function remove_accents($string) {
if (seems_utf8($string)) {
! $chars = array(chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
! chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
! chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
! chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
! chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
! chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
! chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
! chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
! chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
! chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
! chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
! chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
! chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
! chr(195).chr(160) => 'a', chr(195).chr(161) => 'a',
! chr(195).chr(162) => 'a', chr(195).chr(163) => 'a',
! chr(195).chr(164) => 'a', chr(195).chr(165) => 'a',
! chr(195).chr(167) => 'c', chr(195).chr(168) => 'e',
! chr(195).chr(169) => 'e', chr(195).chr(170) => 'e',
! chr(195).chr(171) => 'e', chr(195).chr(172) => 'i',
! chr(195).chr(173) => 'i', chr(195).chr(174) => 'i',
! chr(195).chr(175) => 'i', chr(195).chr(177) => 'n',
! chr(195).chr(178) => 'o', chr(195).chr(179) => 'o',
! chr(195).chr(180) => 'o', chr(195).chr(181) => 'o',
! chr(195).chr(182) => 'o', chr(195).chr(182) => 'o',
! chr(195).chr(185) => 'u', chr(195).chr(186) => 'u',
! chr(195).chr(187) => 'u', chr(195).chr(188) => 'u',
! chr(195).chr(189) => 'y', chr(195).chr(191) => 'y',
! chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe',
! chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
! chr(197).chr(189) => 'Z', chr(197).chr(190) => 'z',
! chr(226).chr(130).chr(172) => 'E');
!
! $string = strtr($string, $chars);
! } else {
! // Assume ISO-8859-1 if not UTF-8
! $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
! .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
! .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
! .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
! .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
! .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
! .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
! .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
! .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
! .chr(252).chr(253).chr(255);
!
! $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
!
! $string = strtr($string, $chars['in'], $chars['out']);
! $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
! $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
! $string = str_replace($double_chars['in'], $double_chars['out'], $string);
}
!
return $string;
}
***************
*** 134,142 ****
function sanitize_title_with_dashes($title) {
$title = remove_accents($title);
$title = strtolower($title);
$title = preg_replace('/&.+?;/', '', $title); // kill entities
! $title = preg_replace('/[^a-z0-9 _-]/', '', $title);
! $title = preg_replace('/\s+/', ' ', $title);
! $title = str_replace(' ', '-', $title);
$title = preg_replace('|-+|', '-', $title);
$title = trim($title, '-');
--- 202,216 ----
function sanitize_title_with_dashes($title) {
$title = remove_accents($title);
+ if (seems_utf8($title)) {
+ if (function_exists('mb_strtolower')) {
+ $title = mb_strtolower($title, 'UTF-8');
+ }
+ $title = utf8_uri_encode($title);
+ }
+
$title = strtolower($title);
$title = preg_replace('/&.+?;/', '', $title); // kill entities
! $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
! $title = preg_replace('/\s+/', '-', $title);
$title = preg_replace('|-+|', '-', $title);
$title = trim($title, '-');
More information about the cvs
mailing list