Truncate sanitized titles to the size of the post_name field without killing multibye characters.

git-svn-id: http://svn.automattic.com/wordpress/trunk@4560 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-11-30 20:26:42 +00:00
parent 9c822fc9b3
commit f066f5ed43
1 changed files with 13 additions and 9 deletions

View File

@ -116,7 +116,7 @@ function wp_specialchars( $text, $quotes = 0 ) {
return $text; return $text;
} }
function utf8_uri_encode( $utf8_string ) { function utf8_uri_encode( $utf8_string, $length = 0 ) {
$unicode = ''; $unicode = '';
$values = array(); $values = array();
$num_octets = 1; $num_octets = 1;
@ -126,21 +126,25 @@ function utf8_uri_encode( $utf8_string ) {
$value = ord( $utf8_string[ $i ] ); $value = ord( $utf8_string[ $i ] );
if ( $value < 128 ) { if ( $value < 128 ) {
if ( $length && ( strlen($unicode) + 1 > $length ) )
break;
$unicode .= chr($value); $unicode .= chr($value);
} else { } else {
if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3; if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
$values[] = $value; $values[] = $value;
if ( $length && ( (strlen($unicode) + ($num_octets * 3)) > $length ) )
break;
if ( count( $values ) == $num_octets ) { if ( count( $values ) == $num_octets ) {
if ($num_octets == 3) { if ($num_octets == 3) {
$unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]); $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
} else { } else {
$unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]); $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
} }
$values = array(); $values = array();
$num_octets = 1; $num_octets = 1;
} }
} }
} }
@ -317,7 +321,7 @@ function sanitize_title_with_dashes($title) {
if (function_exists('mb_strtolower')) { if (function_exists('mb_strtolower')) {
$title = mb_strtolower($title, 'UTF-8'); $title = mb_strtolower($title, 'UTF-8');
} }
$title = utf8_uri_encode($title); $title = utf8_uri_encode($title, 200);
} }
$title = strtolower($title); $title = strtolower($title);