Changeset 846 for trunk/bb-includes/formatting-functions.php
- Timestamp:
- 06/07/2007 07:04:40 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bb-includes/formatting-functions.php
r839 r846 122 122 } 123 123 124 function bb_trim_for_db( $string, $length ) { 125 if ( seems_utf8( $string ) ) 126 $_string = bb_utf8_cut( $string, $length ); 127 return apply_filters( 'bb_trim_for_db', $_string, $string, $length ); 128 } 129 124 130 // Reduce utf8 string to $length in single byte character equivalents without breaking multibyte characters 125 function bb_utf8_cut( $utf8_string, $length ) { 131 function bb_utf8_cut( $utf8_string, $length = 0 ) { 132 if ( $length < 1 ) 133 return $utf8_string; 134 126 135 $unicode = ''; 127 136 $chars = array(); … … 154 163 } 155 164 156 function bb_tag_sanitize( $tag ) { 165 function bb_encoded_utf8_cut( $encoded, $length = 0 ) { 166 if ( $length < 1 ) 167 return $encoded; 168 169 $r = ''; 170 $values = preg_split( '/(%[0-9a-f]{2})/i', $encoded, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );; 171 172 for ($i = 0; $i < count( $values ); $i += $num_octets ) { 173 $num_octets = 1; 174 if ( '%' != $values[$i][0] ) { 175 $r .= $values[$i]; 176 if ( $length && strlen($r) > $length ) 177 return substr($r, 0, $length); 178 } else { 179 $value = hexdec(substr($values[$i], 1)); 180 181 if ( 1 == $num_octets ) 182 $num_octets = $value < 224 ? 2 : 3; 183 184 if ( $length && ( strlen($r) + $num_octets * 3 ) > $length ) 185 return $r; 186 187 $r .= $values[$i] . $values[$i + 1]; 188 if ( 3 == $num_octets ) 189 $r .= $values[$i + 2]; 190 } 191 } 192 193 return $r; 194 } 195 196 function bb_tag_sanitize( $tag, $length = 200 ) { 157 197 $_tag = $tag; 158 return apply_filters( 'bb_tag_sanitize', bb_sanitize_with_dashes( $tag ), $_tag);159 } 160 161 function bb_slug_sanitize( $slug ) {198 return apply_filters( 'bb_tag_sanitize', bb_sanitize_with_dashes( $tag, $length ), $_tag, $length ); 199 } 200 201 function bb_slug_sanitize( $slug, $length = 255 ) { 162 202 $_slug = $slug; 163 return apply_filters( 'bb_slug_sanitize', sanitize_with_dashes( $slug ), $_slug);164 } 165 166 function bb_sanitize_with_dashes( $text, $length = 200 ) { // Multibyte aware203 return apply_filters( 'bb_slug_sanitize', bb_sanitize_with_dashes( $slug, $length ), $_slug, $length ); 204 } 205 206 function bb_sanitize_with_dashes( $text, $length = 0 ) { // Multibyte aware 167 207 $_text = $text; 168 208 $text = trim($text); 169 209 $text = strip_tags($text); 170 171 210 // Preserve escaped octets. 172 211 $text = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $text); … … 176 215 $text = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $text); 177 216 178 $text = apply_filters( 'pre_sanitize_with_dashes', $text, $_text );217 $text = apply_filters( 'pre_sanitize_with_dashes', $text, $_text, $length ); 179 218 180 219 $text = strtolower($text); … … 187 226 } 188 227 189 function bb_pre_sanitize_with_dashes_utf8( $text ) {228 function bb_pre_sanitize_with_dashes_utf8( $text, $_text = '', $length = 0 ) { 190 229 $text = remove_accents($text); 191 230 … … 193 232 if ( function_exists('mb_strtolower') ) 194 233 $text = mb_strtolower($text, 'UTF-8'); 195 $text = utf8_uri_encode( $text ); 196 } 234 $text = utf8_uri_encode( $text, $length ); 235 } 236 197 237 return $text; 198 238 }
Note: See TracChangeset
for help on using the changeset viewer.