Truncate sanitized titles to the size of the post_name field without killing multibye characters.
git-svn-id: https://develop.svn.wordpress.org/trunk@4560 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
6248dfb2ca
commit
c539a41672
@ -116,7 +116,7 @@ function wp_specialchars( $text, $quotes = 0 ) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
function utf8_uri_encode( $utf8_string ) {
|
||||
function utf8_uri_encode( $utf8_string, $length = 0 ) {
|
||||
$unicode = '';
|
||||
$values = array();
|
||||
$num_octets = 1;
|
||||
@ -126,21 +126,25 @@ function utf8_uri_encode( $utf8_string ) {
|
||||
$value = ord( $utf8_string[ $i ] );
|
||||
|
||||
if ( $value < 128 ) {
|
||||
if ( $length && ( strlen($unicode) + 1 > $length ) )
|
||||
break;
|
||||
$unicode .= chr($value);
|
||||
} else {
|
||||
if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
|
||||
|
||||
$values[] = $value;
|
||||
|
||||
if ( $length && ( (strlen($unicode) + ($num_octets * 3)) > $length ) )
|
||||
break;
|
||||
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]);
|
||||
}
|
||||
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;
|
||||
$values = array();
|
||||
$num_octets = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -317,7 +321,7 @@ function sanitize_title_with_dashes($title) {
|
||||
if (function_exists('mb_strtolower')) {
|
||||
$title = mb_strtolower($title, 'UTF-8');
|
||||
}
|
||||
$title = utf8_uri_encode($title);
|
||||
$title = utf8_uri_encode($title, 200);
|
||||
}
|
||||
|
||||
$title = strtolower($title);
|
||||
|
Loading…
Reference in New Issue
Block a user