| [ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** Formatting 3 4 Taken from bbPress, taken from WordPress 5 6 */ 7 8 if ( !function_exists( 'clean_pre' ) ) : // Current at [WP9840] 9 /** 10 * Accepts matches array from preg_replace_callback in wpautop() or a string. 11 * 12 * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not 13 * converted into paragraphs or line-breaks. 14 * 15 * @since WP 1.2.0 16 * 17 * @param array|string $matches The array or string 18 * @return string The pre block without paragraph/line-break conversion. 19 */ 20 function clean_pre($matches) { 21 if ( is_array($matches) ) 22 $text = $matches[1] . $matches[2] . "</pre>"; 23 else 24 $text = $matches; 25 26 $text = str_replace('<br />', '', $text); 27 $text = str_replace('<p>', "\n", $text); 28 $text = str_replace('</p>', '', $text); 29 30 return $text; 31 } 32 endif; 33 34 if ( !function_exists( 'js_escape' ) ) : // Current at [WP9840] 35 /** 36 * Escape single quotes, specialchar double quotes, and fix line endings. 37 * 38 * The filter 'js_escape' is also applied here. 39 * 40 * @since WP 2.0.4 41 * 42 * @param string $text The text to be escaped. 43 * @return string Escaped text. 44 */ 45 function js_escape($text) { 46 $safe_text = wp_check_invalid_utf8( $text ); 47 $safe_text = wp_specialchars( $safe_text, ENT_COMPAT ); 48 $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); 49 $safe_text = preg_replace( "/\r?\n/", "\\n", addslashes( $safe_text ) ); 50 return apply_filters( 'js_escape', $safe_text, $text ); 51 } 52 endif; 53 54 if ( !function_exists( 'attribute_escape' ) ) : // Not like WordPress - uses wp_check_invalid_utf8() and wp_entities() 55 /** 56 * Escaping for HTML attributes. 57 * 58 * @since WP 2.0.6 59 * 60 * @param string $text 61 * @return string 62 */ 63 function attribute_escape( $text ) { 64 $safe_text = wp_check_invalid_utf8( $text ); 65 $safe_text = wp_specialchars( $safe_text, ENT_QUOTES ); 66 return apply_filters( 'attribute_escape', $safe_text, $text ); 67 } 68 endif; 69 70 if ( !function_exists( 'build_query' ) ) : // Current at [WP9840] 71 /** 72 * Build URL query based on an associative and, or indexed array. 73 * 74 * This is a convenient function for easily building url queries. It sets the 75 * separator to '&' and uses _http_build_query() function. 76 * 77 * @see _http_build_query() Used to build the query 78 * @link http://us2.php.net/manual/en/function.http-build-query.php more on what 79 * http_build_query() does. 80 * 81 * @since WP 2.3.0 82 * 83 * @param array $data URL-encode key/value pairs. 84 * @return string URL encoded string 85 */ 86 function build_query( $data ) { 87 return _http_build_query( $data, null, '&', '', false ); 88 } 89 endif; 90 91 if ( !function_exists( 'add_query_arg' ) ) : // Current at [WP9840] 92 /** 93 * Retrieve a modified URL query string. 94 * 95 * You can rebuild the URL and append a new query variable to the URL query by 96 * using this function. You can also retrieve the full URL with query data. 97 * 98 * Adding a single key & value or an associative array. Setting a key value to 99 * emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER 100 * value. 101 * 102 * @since WP 1.5.0 103 * 104 * @param mixed $param1 Either newkey or an associative_array 105 * @param mixed $param2 Either newvalue or oldquery or uri 106 * @param mixed $param3 Optional. Old query or uri 107 * @return string New URL query string. 108 */ 109 function add_query_arg() { 110 $ret = ''; 111 if ( is_array( func_get_arg(0) ) ) { 112 if ( @func_num_args() < 2 || false === @func_get_arg( 1 ) ) 113 $uri = $_SERVER['REQUEST_URI']; 114 else 115 $uri = @func_get_arg( 1 ); 116 } else { 117 if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) ) 118 $uri = $_SERVER['REQUEST_URI']; 119 else 120 $uri = @func_get_arg( 2 ); 121 } 122 123 if ( $frag = strstr( $uri, '#' ) ) 124 $uri = substr( $uri, 0, -strlen( $frag ) ); 125 else 126 $frag = ''; 127 128 if ( preg_match( '|^https?://|i', $uri, $matches ) ) { 129 $protocol = $matches[0]; 130 $uri = substr( $uri, strlen( $protocol ) ); 131 } else { 132 $protocol = ''; 133 } 134 135 if ( strpos( $uri, '?' ) !== false ) { 136 $parts = explode( '?', $uri, 2 ); 137 if ( 1 == count( $parts ) ) { 138 $base = '?'; 139 $query = $parts[0]; 140 } else { 141 $base = $parts[0] . '?'; 142 $query = $parts[1]; 143 } 144 } elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) { 145 $base = $uri . '?'; 146 $query = ''; 147 } else { 148 $base = ''; 149 $query = $uri; 150 } 151 152 wp_parse_str( $query, $qs ); 153 $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string 154 if ( is_array( func_get_arg( 0 ) ) ) { 155 $kayvees = func_get_arg( 0 ); 156 $qs = array_merge( $qs, $kayvees ); 157 } else { 158 $qs[func_get_arg( 0 )] = func_get_arg( 1 ); 159 } 160 161 foreach ( (array) $qs as $k => $v ) { 162 if ( $v === false ) 163 unset( $qs[$k] ); 164 } 165 166 $ret = build_query( $qs ); 167 $ret = trim( $ret, '?' ); 168 $ret = preg_replace( '#=(&|$)#', '$1', $ret ); 169 $ret = $protocol . $base . $ret . $frag; 170 $ret = rtrim( $ret, '?' ); 171 return $ret; 172 } 173 endif; 174 175 if ( !function_exists( 'remove_query_arg' ) ) : // Current at [WP9840] 176 /** 177 * Removes an item or list from the query string. 178 * 179 * @since WP 1.5.0 180 * 181 * @param string|array $key Query key or keys to remove. 182 * @param bool $query When false uses the $_SERVER value. 183 * @return string New URL query string. 184 */ 185 function remove_query_arg( $key, $query=false ) { 186 if ( is_array( $key ) ) { // removing multiple keys 187 foreach ( $key as $k ) 188 $query = add_query_arg( $k, false, $query ); 189 return $query; 190 } 191 return add_query_arg( $key, false, $query ); 192 } 193 endif; 194 195 if ( !function_exists( 'ent2ncr' ) ) : // Current at [WP9840] 196 /** 197 * Converts named entities into numbered entities. 198 * 199 * @since WP 1.5.1 200 * 201 * @param string $text The text within which entities will be converted. 202 * @return string Text with converted entities. 203 */ 204 function ent2ncr($text) { 205 $to_ncr = array( 206 '"' => '"', 207 '&' => '&', 208 '⁄' => '/', 209 '<' => '<', 210 '>' => '>', 211 '|' => '|', 212 ' ' => ' ', 213 '¡' => '¡', 214 '¢' => '¢', 215 '£' => '£', 216 '¤' => '¤', 217 '¥' => '¥', 218 '¦' => '¦', 219 '&brkbar;' => '¦', 220 '§' => '§', 221 '¨' => '¨', 222 '¨' => '¨', 223 '©' => '©', 224 'ª' => 'ª', 225 '«' => '«', 226 '¬' => '¬', 227 '­' => '­', 228 '®' => '®', 229 '¯' => '¯', 230 '&hibar;' => '¯', 231 '°' => '°', 232 '±' => '±', 233 '²' => '²', 234 '³' => '³', 235 '´' => '´', 236 'µ' => 'µ', 237 '¶' => '¶', 238 '·' => '·', 239 '¸' => '¸', 240 '¹' => '¹', 241 'º' => 'º', 242 '»' => '»', 243 '¼' => '¼', 244 '½' => '½', 245 '¾' => '¾', 246 '¿' => '¿', 247 'À' => 'À', 248 'Á' => 'Á', 249 'Â' => 'Â', 250 'Ã' => 'Ã', 251 'Ä' => 'Ä', 252 'Å' => 'Å', 253 'Æ' => 'Æ', 254 'Ç' => 'Ç', 255 'È' => 'È', 256 'É' => 'É', 257 'Ê' => 'Ê', 258 'Ë' => 'Ë', 259 'Ì' => 'Ì', 260 'Í' => 'Í', 261 'Î' => 'Î', 262 'Ï' => 'Ï', 263 'Ð' => 'Ð', 264 'Ñ' => 'Ñ', 265 'Ò' => 'Ò', 266 'Ó' => 'Ó', 267 'Ô' => 'Ô', 268 'Õ' => 'Õ', 269 'Ö' => 'Ö', 270 '×' => '×', 271 'Ø' => 'Ø', 272 'Ù' => 'Ù', 273 'Ú' => 'Ú', 274 'Û' => 'Û', 275 'Ü' => 'Ü', 276 'Ý' => 'Ý', 277 'Þ' => 'Þ', 278 'ß' => 'ß', 279 'à' => 'à', 280 'á' => 'á', 281 'â' => 'â', 282 'ã' => 'ã', 283 'ä' => 'ä', 284 'å' => 'å', 285 'æ' => 'æ', 286 'ç' => 'ç', 287 'è' => 'è', 288 'é' => 'é', 289 'ê' => 'ê', 290 'ë' => 'ë', 291 'ì' => 'ì', 292 'í' => 'í', 293 'î' => 'î', 294 'ï' => 'ï', 295 'ð' => 'ð', 296 'ñ' => 'ñ', 297 'ò' => 'ò', 298 'ó' => 'ó', 299 'ô' => 'ô', 300 'õ' => 'õ', 301 'ö' => 'ö', 302 '÷' => '÷', 303 'ø' => 'ø', 304 'ù' => 'ù', 305 'ú' => 'ú', 306 'û' => 'û', 307 'ü' => 'ü', 308 'ý' => 'ý', 309 'þ' => 'þ', 310 'ÿ' => 'ÿ', 311 'Œ' => 'Œ', 312 'œ' => 'œ', 313 'Š' => 'Š', 314 'š' => 'š', 315 'Ÿ' => 'Ÿ', 316 'ƒ' => 'ƒ', 317 'ˆ' => 'ˆ', 318 '˜' => '˜', 319 'Α' => 'Α', 320 'Β' => 'Β', 321 'Γ' => 'Γ', 322 'Δ' => 'Δ', 323 'Ε' => 'Ε', 324 'Ζ' => 'Ζ', 325 'Η' => 'Η', 326 'Θ' => 'Θ', 327 'Ι' => 'Ι', 328 'Κ' => 'Κ', 329 'Λ' => 'Λ', 330 'Μ' => 'Μ', 331 'Ν' => 'Ν', 332 'Ξ' => 'Ξ', 333 'Ο' => 'Ο', 334 'Π' => 'Π', 335 'Ρ' => 'Ρ', 336 'Σ' => 'Σ', 337 'Τ' => 'Τ', 338 'Υ' => 'Υ', 339 'Φ' => 'Φ', 340 'Χ' => 'Χ', 341 'Ψ' => 'Ψ', 342 'Ω' => 'Ω', 343 'α' => 'α', 344 'β' => 'β', 345 'γ' => 'γ', 346 'δ' => 'δ', 347 'ε' => 'ε', 348 'ζ' => 'ζ', 349 'η' => 'η', 350 'θ' => 'θ', 351 'ι' => 'ι', 352 'κ' => 'κ', 353 'λ' => 'λ', 354 'μ' => 'μ', 355 'ν' => 'ν', 356 'ξ' => 'ξ', 357 'ο' => 'ο', 358 'π' => 'π', 359 'ρ' => 'ρ', 360 'ς' => 'ς', 361 'σ' => 'σ', 362 'τ' => 'τ', 363 'υ' => 'υ', 364 'φ' => 'φ', 365 'χ' => 'χ', 366 'ψ' => 'ψ', 367 'ω' => 'ω', 368 'ϑ' => 'ϑ', 369 'ϒ' => 'ϒ', 370 'ϖ' => 'ϖ', 371 ' ' => ' ', 372 ' ' => ' ', 373 ' ' => ' ', 374 '‌' => '‌', 375 '‍' => '‍', 376 '‎' => '‎', 377 '‏' => '‏', 378 '–' => '–', 379 '—' => '—', 380 '‘' => '‘', 381 '’' => '’', 382 '‚' => '‚', 383 '“' => '“', 384 '”' => '”', 385 '„' => '„', 386 '†' => '†', 387 '‡' => '‡', 388 '•' => '•', 389 '…' => '…', 390 '‰' => '‰', 391 '′' => '′', 392 '″' => '″', 393 '‹' => '‹', 394 '›' => '›', 395 '‾' => '‾', 396 '⁄' => '⁄', 397 '€' => '€', 398 'ℑ' => 'ℑ', 399 '℘' => '℘', 400 'ℜ' => 'ℜ', 401 '™' => '™', 402 'ℵ' => 'ℵ', 403 '↵' => '↵', 404 '⇐' => '⇐', 405 '⇑' => '⇑', 406 '⇒' => '⇒', 407 '⇓' => '⇓', 408 '⇔' => '⇔', 409 '∀' => '∀', 410 '∂' => '∂', 411 '∃' => '∃', 412 '∅' => '∅', 413 '∇' => '∇', 414 '∈' => '∈', 415 '∉' => '∉', 416 '∋' => '∋', 417 '∏' => '∏', 418 '∑' => '∑', 419 '−' => '−', 420 '∗' => '∗', 421 '√' => '√', 422 '∝' => '∝', 423 '∞' => '∞', 424 '∠' => '∠', 425 '∧' => '∧', 426 '∨' => '∨', 427 '∩' => '∩', 428 '∪' => '∪', 429 '∫' => '∫', 430 '∴' => '∴', 431 '∼' => '∼', 432 '≅' => '≅', 433 '≈' => '≈', 434 '≠' => '≠', 435 '≡' => '≡', 436 '≤' => '≤', 437 '≥' => '≥', 438 '⊂' => '⊂', 439 '⊃' => '⊃', 440 '⊄' => '⊄', 441 '⊆' => '⊆', 442 '⊇' => '⊇', 443 '⊕' => '⊕', 444 '⊗' => '⊗', 445 '⊥' => '⊥', 446 '⋅' => '⋅', 447 '⌈' => '⌈', 448 '⌉' => '⌉', 449 '⌊' => '⌊', 450 '⌋' => '⌋', 451 '⟨' => '〈', 452 '⟩' => '〉', 453 '←' => '←', 454 '↑' => '↑', 455 '→' => '→', 456 '↓' => '↓', 457 '↔' => '↔', 458 '◊' => '◊', 459 '♠' => '♠', 460 '♣' => '♣', 461 '♥' => '♥', 462 '♦' => '♦' 463 ); 464 465 return str_replace( array_keys($to_ncr), array_values($to_ncr), $text ); 466 } 467 endif; 468 469 if ( !function_exists( 'urlencode_deep' ) ) : // Current at [WP9840] 470 /** 471 * Navigates through an array and encodes the values to be used in a URL. 472 * 473 * Uses a callback to pass the value of the array back to the function as a 474 * string. 475 * 476 * @since WP 2.2.0 477 * 478 * @param array|string $value The array or string to be encoded. 479 * @return array|string $value The encoded array (or string from the callback). 480 */ 481 function urlencode_deep($value) { 482 $value = is_array($value) ? array_map('urlencode_deep', $value) : urlencode($value); 483 return $value; 484 } 485 endif; 486 487 if ( !function_exists( 'zeroise' ) ) : // Current at [WP9840] 488 /** 489 * Add leading zeros when necessary. 490 * 491 * If you set the threshold to '4' and the number is '10', then you will get 492 * back '0010'. If you set the number to '4' and the number is '5000', then you 493 * will get back '5000'. 494 * 495 * Uses sprintf to append the amount of zeros based on the $threshold parameter 496 * and the size of the number. If the number is large enough, then no zeros will 497 * be appended. 498 * 499 * @since WP 0.71 500 * 501 * @param mixed $number Number to append zeros to if not greater than threshold. 502 * @param int $threshold Digit places number needs to be to not have zeros added. 503 * @return string Adds leading zeros to number if needed. 504 */ 505 function zeroise($number, $threshold) { 506 return sprintf('%0'.$threshold.'s', $number); 507 } 508 endif; 509 510 if ( !function_exists( 'backslashit' ) ) : // Current at [WP9840] 511 /** 512 * Adds backslashes before letters and before a number at the start of a string. 513 * 514 * @since WP 0.71 515 * 516 * @param string $string Value to which backslashes will be added. 517 * @return string String with backslashes inserted. 518 */ 519 function backslashit($string) { 520 $string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string); 521 $string = preg_replace('/([a-z])/i', '\\\\\1', $string); 522 return $string; 523 } 524 endif; 525 526 if ( !function_exists( '_make_url_clickable_cb' ) ): // Current at [WP11307] 527 /** 528 * Callback to convert URI match to HTML A element. 529 * 530 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link 531 * make_clickable()}. 532 * 533 * @since 2.3.2 534 * @access private 535 * 536 * @param array $matches Single Regex Match. 537 * @return string HTML A element with URI address. 538 */ 539 function _make_url_clickable_cb($matches) { 540 $url = $matches[2]; 541 $url = clean_url($url); 542 if ( empty($url) ) 543 return $matches[0]; 544 return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>"; 545 } 546 endif; 547 548 if ( !function_exists( '_make_web_ftp_clickable_cb' ) ): // Current at [WP11307] 549 /** 550 * Callback to convert URL match to HTML A element. 551 * 552 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link 553 * make_clickable()}. 554 * 555 * @since 2.3.2 556 * @access private 557 * 558 * @param array $matches Single Regex Match. 559 * @return string HTML A element with URL address. 560 */ 561 function _make_web_ftp_clickable_cb($matches) { 562 $ret = ''; 563 $dest = $matches[2]; 564 $dest = 'http://' . $dest; 565 $dest = clean_url($dest); 566 if ( empty($dest) ) 567 return $matches[0]; 568 // removed trailing [,;:] from URL 569 if ( in_array(substr($dest, -1), array('.', ',', ';', ':')) === true ) { 570 $ret = substr($dest, -1); 571 $dest = substr($dest, 0, strlen($dest)-1); 572 } 573 return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>" . $ret; 574 } 575 endif; 576 577 if ( !function_exists( '_make_email_clickable_cb' ) ): // Current at [WP11307] 578 /** 579 * Callback to convert email address match to HTML A element. 580 * 581 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link 582 * make_clickable()}. 583 * 584 * @since 2.3.2 585 * @access private 586 * 587 * @param array $matches Single Regex Match. 588 * @return string HTML A element with email address. 589 */ 590 function _make_email_clickable_cb($matches) { 591 $email = $matches[2] . '@' . $matches[3]; 592 return $matches[1] . "<a href=\"mailto:$email\">$email</a>"; 593 } 594 endif; 595 596 if ( !function_exists( 'make_clickable' ) ): // Current at [WP11307] 597 /** 598 * Convert plaintext URI to HTML links. 599 * 600 * Converts URI, www and ftp, and email addresses. Finishes by fixing links 601 * within links. 602 * 603 * @since 0.71 604 * 605 * @param string $ret Content to convert URIs. 606 * @return string Content with converted URIs. 607 */ 608 function make_clickable($ret) { 609 $ret = ' ' . $ret; 610 // in testing, using arrays here was found to be faster 611 $ret = preg_replace_callback('#(?<=[\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&~/\-=?@\[\](+]|[.,;:](?![\s<])|(?(1)\)(?![\s<])|\)))+)#is', '_make_url_clickable_cb', $ret); 612 $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret); 613 $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret); 614 // this one is not in an array because we need it to run last, for cleanup of accidental links within links 615 $ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret); 616 $ret = trim($ret); 617 return $ret; 618 } 619 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu May 24 03:59:35 2012 | Hosted by follow the white rabbit. |