Ticket #5638: formatting.phpdoc.r6597.diff
| File formatting.phpdoc.r6597.diff, 28.8 KB (added by , 18 years ago) |
|---|
-
formatting.php
1 1 <?php 2 /** 3 * 4 * 5 * @package WordPress 6 */ 2 7 8 /** 9 * wptexturize() - {@internal Missing Short Description}} 10 * 11 * {@internal Missing Long Description}} 12 * 13 * @since 0.71 14 * 15 * @param unknown_type $text 16 * @return unknown 17 */ 3 18 function wptexturize($text) { 4 19 global $wp_cockneyreplace; 5 20 $next = true; … … 24 39 $dynamic_replacements = array('’$1','$1‘', '$1″', '$1′', '$1’$2', '$1“$2', '”$1', '’$1', '$1×$2'); 25 40 26 41 for ( $i = 0; $i < $stop; $i++ ) { 27 $curl = $textarr[$i];42 $curl = $textarr[$i]; 28 43 29 44 if (isset($curl{0}) && '<' != $curl{0} && $next) { // If it's not a tag 30 45 // static strings … … 41 56 $output .= $curl; 42 57 } 43 58 44 return $output;59 return $output; 45 60 } 46 61 47 // Accepts matches array from preg_replace_callback in wpautop() 48 // or a string 62 /** 63 * clean_pre() - Accepts matches array from preg_replace_callback in wpautop() or a string 64 * 65 * {@internal Missing Long Description}} 66 * 67 * @since 1.2.0 68 * 69 * @param unknown_type $matches 70 * @return unknown 71 */ 49 72 function clean_pre($matches) { 50 73 if ( is_array($matches) ) 51 74 $text = $matches[1] . $matches[2] . "</pre>"; … … 59 82 return $text; 60 83 } 61 84 85 /** 86 * wpautop() - {@internal Missing Short Description}} 87 * 88 * {@internal Missing Long Description}} 89 * 90 * @since 0.71 91 * 92 * @param unknown_type $pee 93 * @param unknown_type $br 94 * @return unknown 95 */ 62 96 function wpautop($pee, $br = 1) { 63 97 $pee = $pee . "\n"; // just to make things a little easier, pad the end 64 98 $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee); … … 92 126 return $pee; 93 127 } 94 128 95 129 /** 130 * seems_utf8() - {@internal Missing Short Description}} 131 * 132 * {@internal Missing Long Description}} 133 * 134 * @since 1.2.1 135 * 136 * @param unknown_type $Str 137 * @return unknown 138 */ 96 139 function seems_utf8($Str) { # by bmorel at ssi dot fr 97 140 $length = strlen($Str); 98 141 for ($i=0; $i < $length; $i++) { … … 111 154 return true; 112 155 } 113 156 157 /** 158 * wp_specialchars() - {@internal Missing Short Description}} 159 * 160 * {@internal Missing Long Description}} 161 * 162 * @since 1.2.2 163 * 164 * @param unknown_type $text 165 * @param unknown_type $quotes 166 * @return unknown 167 */ 114 168 function wp_specialchars( $text, $quotes = 0 ) { 115 169 // Like htmlspecialchars except don't double-encode HTML entities 116 170 $text = str_replace('&&', '&&', $text); … … 129 183 return $text; 130 184 } 131 185 186 /** 187 * utf8_uri_encode() - {@internal Missing Short Description}} 188 * 189 * {@internal Missing Long Description}} 190 * 191 * @since 1.5.0 192 * 193 * @param unknown_type $utf8_string 194 * @param unknown_type $length 195 * @return unknown 196 */ 132 197 function utf8_uri_encode( $utf8_string, $length = 0 ) { 133 198 $unicode = ''; 134 199 $values = array(); … … 170 235 return $unicode; 171 236 } 172 237 238 /** 239 * remove_accents() - {@internal Missing Short Description}} 240 * 241 * {@internal Missing Long Description}} 242 * 243 * @since 1.2.1 244 * 245 * @param unknown_type $string 246 * @return unknown 247 */ 173 248 function remove_accents($string) { 174 249 if ( !preg_match('/[\x80-\xff]/', $string) ) 175 250 return $string; … … 300 375 return $string; 301 376 } 302 377 378 /** 379 * sanitize_file_name() - {@internal Missing Short Description}} 380 * 381 * {@internal Missing Long Description}} 382 * 383 * @since 2.1.0 384 * 385 * @param unknown_type $name 386 * @return unknown 387 */ 303 388 function sanitize_file_name( $name ) { // Like sanitize_title, but with periods 304 389 $name = strtolower( $name ); 305 390 $name = preg_replace('/&.+?;/', '', $name); // kill entities … … 311 396 return $name; 312 397 } 313 398 399 /** 400 * sanitize_user() - {@internal Missing Short Description}} 401 * 402 * {@internal Missing Long Description}} 403 * 404 * @since 2.0.0 405 * 406 * @param unknown_type $username 407 * @param unknown_type $strict 408 * @return unknown 409 */ 314 410 function sanitize_user( $username, $strict = false ) { 315 411 $raw_username = $username; 316 412 $username = strip_tags($username); … … 325 421 return apply_filters('sanitize_user', $username, $raw_username, $strict); 326 422 } 327 423 424 /** 425 * sanitize_title() - {@internal Missing Short Description}} 426 * 427 * {@internal Missing Long Description}} 428 * 429 * @since 1.0.0 430 * 431 * @param unknown_type $title 432 * @param unknown_type $fallback_title 433 * @return unknown 434 */ 328 435 function sanitize_title($title, $fallback_title = '') { 329 436 $title = strip_tags($title); 330 437 $title = apply_filters('sanitize_title', $title); … … 335 442 return $title; 336 443 } 337 444 445 /** 446 * sanitize_title_with_dashes() - {@internal Missing Short Description}} 447 * 448 * {@internal Missing Long Description}} 449 * 450 * @since 1.2.0 451 * 452 * @param unknown_type $title 453 * @return unknown 454 */ 338 455 function sanitize_title_with_dashes($title) { 339 456 $title = strip_tags($title); 340 457 // Preserve escaped octets. … … 362 479 return $title; 363 480 } 364 481 482 /** 483 * convert_chars() - {@internal Missing Short Description}} 484 * 485 * {@internal Missing Long Description}} 486 * 487 * @since 0.71 488 * 489 * @param unknown_type $content 490 * @param string $deprecated Not used 491 * @return string 492 */ 365 493 function convert_chars($content, $deprecated = '') { 366 494 // Translation of invalid Unicode references range to valid range 367 495 $wp_htmltranswinuni = array( … … 416 544 return $content; 417 545 } 418 546 547 /** 548 * funky_javascript_fix() - {@internal Missing Short Description}} 549 * 550 * {@internal Missing Long Description}} 551 * 552 * @since 1.5.0 553 * 554 * @param unknown_type $text 555 * @return unknown 556 */ 419 557 function funky_javascript_fix($text) { 420 558 // Fixes for browsers' javascript bugs 421 559 global $is_macIE, $is_winIE; … … 426 564 return $text; 427 565 } 428 566 567 /** 568 * balanceTags() - {@internal Missing Short Description}} 569 * 570 * {@internal Missing Long Description}} 571 * 572 * @since 0.71 573 * 574 * @param string $text Text to be balanced 575 * @param bool $force Forces balancing, ignoring the value of the option 576 * @return string Balanced text 577 */ 429 578 function balanceTags( $text, $force = false ) { 430 579 if ( !$force && get_option('use_balanceTags') == 0 ) 431 580 return $text; 432 581 return force_balance_tags( $text ); 433 582 } 434 583 435 /* 436 force_balance_tags437 438 Balances Tags of string using a modified stack.439 440 @param text Text to be balanced441 @param force Forces balancing, ignoring the value of the option442 @return Returns balanced text443 @author Leonard Lin (leonard@acm.org)444 @version v1.1445 @date November 4, 2001446 @license GPL v2.0447 @notes448 @changelog449 --- Modified by Scott Reilly (coffee2code) 02 Aug 2004450 1.2 ***TODO*** Make better - change loop condition to $text 451 1.1 Fixed handling of append/stack pop order of end text 452 Added Cleaning Hooks 453 1.0 First Version 454 */584 /** 585 * force_balance_tags() - Balances tags of string using a modified stack. 586 * 587 * {@internal Missing Long Description}} 588 * 589 * @since 2.0.4 590 * 591 * @author Leonard Lin <leonard@acm.org> 592 * @license GPL v2.0 593 * @date November 4, 2001 594 * @version 1.1 595 * @todo Make better - change loop condition to $text in 1.2 596 * @internal Modified by Scott Reilly (coffee2code) 02 Aug 2004 597 * 1.1 Fixed handling of append/stack pop order of end text 598 * Added Cleaning Hooks 599 * 1.0 First Version 600 * 601 * @param string $text Text to be balanced 602 * @return string Balanced text 603 */ 455 604 function force_balance_tags( $text ) { 456 605 $tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = ''; 457 606 $single_tags = array('br', 'hr', 'img', 'input'); //Known single-entity/self-closing tags … … 551 700 return $newtext; 552 701 } 553 702 703 /** 704 * format_to_edit() - {@internal Missing Short Description}} 705 * 706 * {@internal Missing Long Description}} 707 * 708 * @since 0.71 709 * 710 * @param unknown_type $content 711 * @param unknown_type $richedit 712 * @return unknown 713 */ 554 714 function format_to_edit($content, $richedit = false) { 555 715 $content = apply_filters('format_to_edit', $content); 556 716 if (! $richedit ) … … 558 718 return $content; 559 719 } 560 720 721 /** 722 * format_to_post() - {@internal Missing Short Description}} 723 * 724 * {@internal Missing Long Description}} 725 * 726 * @since 0.71 727 * 728 * @param unknown_type $content 729 * @return unknown 730 */ 561 731 function format_to_post($content) { 562 732 $content = apply_filters('format_to_post', $content); 563 733 return $content; 564 734 } 565 735 566 function zeroise($number,$threshold) { // function to add leading zeros when necessary 736 /** 737 * zeroise() - Add leading zeros when necessary 738 * 739 * {@internal Missing Long Description}} 740 * 741 * @since 0.71 742 * 743 * @param mixed $number Will convert to string and add zeros 744 * @param int $threshold Amount of digits 745 * @return string Adds leading zeros to number if needed 746 */ 747 function zeroise($number,$threshold) { 567 748 return sprintf('%0'.$threshold.'s', $number); 568 749 } 569 750 570 751 /** 752 * backslashit() - {@internal Missing Short Description}} 753 * 754 * {@internal Missing Long Description}} 755 * 756 * @since 0.71 757 * 758 * @param unknown_type $string 759 * @return unknown 760 */ 571 761 function backslashit($string) { 572 762 $string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string); 573 763 $string = preg_replace('/([a-z])/i', '\\\\\1', $string); 574 764 return $string; 575 765 } 576 766 767 /** 768 * trailingslashit() - Appends a trailing slash 769 * 770 * Will remove trailing slash if it exists already before adding 771 * a trailing slash. This prevents double slashing a string or 772 * path. 773 * 774 * The primary use of this is for paths and thus should be used 775 * for paths. It is not restricted to paths and offers no specific 776 * path support. 777 * 778 * @since 1.2.0 779 * @uses untrailingslashit() Unslashes string if it was slashed already 780 * 781 * @param string $string What to add the trailing slash to 782 * @return string String with trailing slash added 783 */ 577 784 function trailingslashit($string) { 578 785 return untrailingslashit($string) . '/'; 579 786 } 580 787 788 /** 789 * untrailingslashit() - Removes trailing slash if it exists 790 * 791 * The primary use of this is for paths and thus should be used 792 * for paths. It is not restricted to paths and offers no specific 793 * path support. 794 * 795 * @since 2.2.0 796 * 797 * @param string $string What to remove the trailing slash from 798 * @return string String without the trailing slash 799 */ 581 800 function untrailingslashit($string) { 582 801 return rtrim($string, '/'); 583 802 } 584 803 804 /** 805 * addslashes_gpc() - {@internal Missing Short Description}} 806 * 807 * {@internal Missing Long Description}} 808 * 809 * @since 0.71 810 * 811 * @param unknown_type $gpc 812 * @return unknown 813 */ 585 814 function addslashes_gpc($gpc) { 586 815 global $wpdb; 587 816 … … 592 821 return $wpdb->escape($gpc); 593 822 } 594 823 595 824 /** 825 * stripslashes_deep() - {@internal Missing Short Description}} 826 * 827 * {@internal Missing Long Description}} 828 * 829 * @since 2.0.0 830 * 831 * @param unknown_type $value 832 * @return unknown 833 */ 596 834 function stripslashes_deep($value) { 597 $value = is_array($value) ? 598 array_map('stripslashes_deep', $value) : 599 stripslashes($value); 600 601 return $value; 835 $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); 836 return $value; 602 837 } 603 838 839 /** 840 * urlencode_deep() - {@internal Missing Short Description}} 841 * 842 * {@internal Missing Long Description}} 843 * 844 * @since 2.2.0 845 * 846 * @param unknown_type $value 847 * @return unknown 848 */ 604 849 function urlencode_deep($value) { 605 $value = is_array($value) ? 606 array_map('urlencode_deep', $value) : 607 urlencode($value); 608 609 return $value; 850 $value = is_array($value) ? array_map('urlencode_deep', $value) : urlencode($value); 851 return $value; 610 852 } 611 853 854 /** 855 * antispambot() - {@internal Missing Short Description}} 856 * 857 * {@internal Missing Long Description}} 858 * 859 * @since 0.71 860 * 861 * @param unknown_type $emailaddy 862 * @param unknown_type $mailto 863 * @return unknown 864 */ 612 865 function antispambot($emailaddy, $mailto=0) { 613 866 $emailNOSPAMaddy = ''; 614 867 srand ((float) microtime() * 1000000); … … 626 879 return $emailNOSPAMaddy; 627 880 } 628 881 882 /** 883 * _make_url_clickable_cb() - {@internal Missing Short Description}} 884 * 885 * {@internal Missing Long Description}} 886 * 887 * @since 2.5 888 * @access private 889 * 890 * @param unknown_type $matches 891 * @return unknown 892 */ 629 893 function _make_url_clickable_cb($matches) { 630 894 $url = $matches[2]; 631 895 $url = clean_url($url); … … 634 898 return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>"; 635 899 } 636 900 901 /** 902 * _make_web_ftp_clickable_cb() - {@internal Missing Short Description}} 903 * 904 * {@internal Missing Long Description}} 905 * 906 * @since 2.5 907 * @access private 908 * 909 * @param unknown_type $matches 910 * @return unknown 911 */ 637 912 function _make_web_ftp_clickable_cb($matches) { 638 913 $dest = $matches[2]; 639 914 $dest = 'http://' . $dest; … … 644 919 return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>"; 645 920 } 646 921 922 /** 923 * _make_email_clickable_cb() - {@internal Missing Short Description}} 924 * 925 * {@internal Missing Long Description}} 926 * 927 * @since 2.5 928 * @access private 929 * 930 * @param unknown_type $matches 931 * @return unknown 932 */ 647 933 function _make_email_clickable_cb($matches) { 648 934 $email = $matches[2] . '@' . $matches[3]; 649 935 return $matches[1] . "<a href=\"mailto:$email\">$email</a>"; 650 936 } 651 937 938 /** 939 * make_clickable() - {@internal Missing Short Description}} 940 * 941 * {@internal Missing Long Description}} 942 * 943 * @since 0.71 944 * 945 * @param unknown_type $ret 946 * @return unknown 947 */ 652 948 function make_clickable($ret) { 653 949 $ret = ' ' . $ret; 654 950 // in testing, using arrays here was found to be faster … … 661 957 return $ret; 662 958 } 663 959 960 /** 961 * wp_rel_nofollow() - {@internal Missing Short Description}} 962 * 963 * {@internal Missing Long Description}} 964 * 965 * @since 1.5.0 966 * 967 * @param unknown_type $text 968 * @return unknown 969 */ 664 970 function wp_rel_nofollow( $text ) { 665 971 global $wpdb; 666 972 // This is a pre save filter, so text is already escaped. … … 670 976 return $text; 671 977 } 672 978 979 /** 980 * wp_rel_nofollow_callback() - {@internal Missing Short Description}} 981 * 982 * {@internal Missing Long Description}} 983 * 984 * @since 2.3.0 985 * 986 * @param unknown_type $matches 987 * @return unknown 988 */ 673 989 function wp_rel_nofollow_callback( $matches ) { 674 990 $text = $matches[1]; 675 991 $text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text); 676 992 return "<a $text rel=\"nofollow\">"; 677 993 } 678 994 995 /** 996 * convert_smilies() - {@internal Missing Short Description}} 997 * 998 * {@internal Missing Long Description}} 999 * 1000 * @since 0.71 1001 * 1002 * @param unknown_type $text 1003 * @return unknown 1004 */ 679 1005 function convert_smilies($text) { 680 1006 global $wp_smiliessearch, $wp_smiliesreplace; 681 $output = '';1007 $output = ''; 682 1008 if ( get_option('use_smilies') && !empty($wp_smiliessearch) && !empty($wp_smiliesreplace) ) { 683 1009 // HTML loop taken from texturize function, could possible be consolidated 684 1010 $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between … … 697 1023 return $output; 698 1024 } 699 1025 700 1026 /** 1027 * is_email() - {@internal Missing Short Description}} 1028 * 1029 * {@internal Missing Long Description}} 1030 * 1031 * @since 0.71 1032 * 1033 * @param unknown_type $user_email 1034 * @return unknown 1035 */ 701 1036 function is_email($user_email) { 702 1037 $chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i"; 703 1038 if (strpos($user_email, '@') !== false && strpos($user_email, '.') !== false) { … … 711 1046 } 712 1047 } 713 1048 714 // used by wp-mail to handle charsets in email subjects 1049 /** 1050 * wp_iso_descrambler() - {@internal Missing Short Description}} 1051 * 1052 * {@internal Missing Long Description}} 1053 * 1054 * @since 1.2.0 1055 * @usedby wp_mail() handles charsets in email subjects 1056 * 1057 * @param unknown_type $string 1058 * @return unknown 1059 */ 715 1060 function wp_iso_descrambler($string) { 716 /* this may only work with iso-8859-1, I'm afraid */717 if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) {718 return $string;719 } else {720 $subject = str_replace('_', ' ', $matches[2]);721 $subject = preg_replace('#\=([0-9a-f]{2})#ei', "chr(hexdec(strtolower('$1')))", $subject);722 return $subject;723 }1061 /* this may only work with iso-8859-1, I'm afraid */ 1062 if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) { 1063 return $string; 1064 } else { 1065 $subject = str_replace('_', ' ', $matches[2]); 1066 $subject = preg_replace('#\=([0-9a-f]{2})#ei', "chr(hexdec(strtolower('$1')))", $subject); 1067 return $subject; 1068 } 724 1069 } 725 1070 726 727 // give it a date, it will give you the same date as GMT 1071 /** 1072 * get_gmt_from_date() - Give it a date, it will give you the same date as GMT 1073 * 1074 * {@internal Missing Long Description}} 1075 * 1076 * @since 1.2.0 1077 * 1078 * @param unknown_type $string 1079 * @return unknown 1080 */ 728 1081 function get_gmt_from_date($string) { 729 // note: this only substracts $time_difference from the given date730 preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);731 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);732 $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_option('gmt_offset') * 3600);733 return $string_gmt;1082 // note: this only substracts $time_difference from the given date 1083 preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches); 1084 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 1085 $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_option('gmt_offset') * 3600); 1086 return $string_gmt; 734 1087 } 735 1088 736 // give it a GMT date, it will give you the same date with $time_difference added 1089 /** 1090 * get_date_from_gmt() - Give it a GMT date, it will give you the same date with $time_difference added 1091 * 1092 * {@internal Missing Long Description}} 1093 * 1094 * @since 1.2.0 1095 * 1096 * @param unknown_type $string 1097 * @return unknown 1098 */ 737 1099 function get_date_from_gmt($string) { 738 // note: this only adds $time_difference to the given date739 preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);740 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);741 $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_option('gmt_offset')*3600);742 return $string_localtime;1100 // note: this only adds $time_difference to the given date 1101 preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches); 1102 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 1103 $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_option('gmt_offset')*3600); 1104 return $string_localtime; 743 1105 } 744 1106 745 // computes an offset in seconds from an iso8601 timezone 1107 /** 1108 * iso8601_timezone_to_offset() - Computes an offset in seconds from an iso8601 timezone 1109 * 1110 * {@internal Missing Long Description}} 1111 * 1112 * @since 1.5.0 1113 * 1114 * @param unknown_type $timezone 1115 * @return unknown 1116 */ 746 1117 function iso8601_timezone_to_offset($timezone) { 747 // $timezone is either 'Z' or '[+|-]hhmm'748 if ($timezone == 'Z') {749 $offset = 0;750 } else {751 $sign = (substr($timezone, 0, 1) == '+') ? 1 : -1;752 $hours = intval(substr($timezone, 1, 2));753 $minutes = intval(substr($timezone, 3, 4)) / 60;754 $offset = $sign * 3600 * ($hours + $minutes);755 }756 return $offset;1118 // $timezone is either 'Z' or '[+|-]hhmm' 1119 if ($timezone == 'Z') { 1120 $offset = 0; 1121 } else { 1122 $sign = (substr($timezone, 0, 1) == '+') ? 1 : -1; 1123 $hours = intval(substr($timezone, 1, 2)); 1124 $minutes = intval(substr($timezone, 3, 4)) / 60; 1125 $offset = $sign * 3600 * ($hours + $minutes); 1126 } 1127 return $offset; 757 1128 } 758 1129 759 // converts an iso8601 date to MySQL DateTime format used by post_date[_gmt] 1130 /** 1131 * iso8601_to_datetime() - Converts an iso8601 date to MySQL DateTime format used by post_date[_gmt] 1132 * 1133 * {@internal Missing Long Description}} 1134 * 1135 * @since 1.5.0 1136 * 1137 * @param unknown_type $date_string 1138 * @param unknown_type $timezone 1139 * @return unknown 1140 */ 760 1141 function iso8601_to_datetime($date_string, $timezone = USER) { 761 if ($timezone == GMT) { 762 preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits); 763 if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset 764 $offset = iso8601_timezone_to_offset($date_bits[7]); 765 } else { // we don't have a timezone, so we assume user local timezone (not server's!) 766 $offset = 3600 * get_option('gmt_offset'); 767 } 768 $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]); 769 $timestamp -= $offset; 770 return gmdate('Y-m-d H:i:s', $timestamp); 771 } elseif ($timezone == USER) { 772 return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string); 773 } 1142 if ($timezone == GMT) { 1143 1144 preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits); 1145 1146 if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset 1147 $offset = iso8601_timezone_to_offset($date_bits[7]); 1148 } else { // we don't have a timezone, so we assume user local timezone (not server's!) 1149 $offset = 3600 * get_option('gmt_offset'); 1150 } 1151 1152 $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]); 1153 $timestamp -= $offset; 1154 1155 return gmdate('Y-m-d H:i:s', $timestamp); 1156 1157 } else if ($timezone == USER) { 1158 return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string); 1159 } 774 1160 } 775 1161 1162 /** 1163 * popuplinks() - Adds a element attributes to open links in new windows 1164 * 1165 * Comment text in popup windows should be filtered through this. Right 1166 * now it's a moderately dumb function, ideally it would detect whether 1167 * a target or rel attribute was already there and adjust its actions 1168 * accordingly. 1169 * 1170 * @since 0.71 1171 * 1172 * @param string $text Content to replace links to open in a new window 1173 * @return string Content that has filtered links 1174 */ 776 1175 function popuplinks($text) { 777 // Comment text in popup windows should be filtered through this.778 // Right now it's a moderately dumb function, ideally it would detect whether779 // a target or rel attribute was already there and adjust its actions accordingly.780 1176 $text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank' rel='external'>", $text); 781 1177 return $text; 782 1178 } 783 1179 1180 /** 1181 * sanitize_email() - Strips out all characters that are not allowable in an email 1182 * 1183 * @since 1.5.0 1184 * 1185 * @param string $email Email address to filter 1186 * @return string Filtered email address 1187 */ 784 1188 function sanitize_email($email) { 785 1189 return preg_replace('/[^a-z0-9+_.@-]/i', '', $email); 786 1190 } 787 1191 1192 /** 1193 * human_time_diff() - {@internal Missing Short Description}} 1194 * 1195 * {@internal Missing Long Description}} 1196 * 1197 * @since 1.5.0 1198 * 1199 * @param unknown_type $from 1200 * @param unknown_type $to 1201 * @return unknown 1202 */ 788 1203 function human_time_diff( $from, $to = '' ) { 789 1204 if ( empty($to) ) 790 1205 $to = time(); … … 811 1226 return $since; 812 1227 } 813 1228 1229 /** 1230 * wp_trim_excerpt() - {@internal Missing Short Description}} 1231 * 1232 * {@internal Missing Long Description}} 1233 * 1234 * @since 1.5.0 1235 * 1236 * @param unknown_type $text 1237 * @return unknown 1238 */ 814 1239 function wp_trim_excerpt($text) { // Fakes an excerpt if needed 815 1240 if ( '' == $text ) { 816 1241 $text = get_the_content(''); … … 828 1253 return $text; 829 1254 } 830 1255 1256 /** 1257 * ent2ncr() - {@internal Missing Short Description}} 1258 * 1259 * {@internal Missing Long Description}} 1260 * 1261 * @since 1.5.1 1262 * 1263 * @param unknown_type $text 1264 * @return unknown 1265 */ 831 1266 function ent2ncr($text) { 832 1267 $to_ncr = array( 833 1268 '"' => '"', … … 1092 1527 return str_replace( array_keys($to_ncr), array_values($to_ncr), $text ); 1093 1528 } 1094 1529 1530 /** 1531 * wp_richedit_pre() - {@internal Missing Short Description}} 1532 * 1533 * {@internal Missing Long Description}} 1534 * 1535 * @since 2.0.0 1536 * 1537 * @param unknown_type $text 1538 * @return unknown 1539 */ 1095 1540 function wp_richedit_pre($text) { 1096 1541 // Filtering a blank results in an annoying <br />\n 1097 1542 if ( empty($text) ) return apply_filters('richedit_pre', ''); … … 1107 1552 return apply_filters('richedit_pre', $output); 1108 1553 } 1109 1554 1555 /** 1556 * clean_url() - {@internal Missing Short Description}} 1557 * 1558 * {@internal Missing Long Description}} 1559 * 1560 * @since 1.2.0 1561 * 1562 * @param unknown_type $url 1563 * @param unknown_type $protocols 1564 * @param unknown_type $context 1565 * @return unknown 1566 */ 1110 1567 function clean_url( $url, $protocols = null, $context = 'display' ) { 1111 1568 $original_url = $url; 1112 1569 … … 1118 1575 /* If the URL doesn't appear to contain a scheme, we 1119 1576 * presume it needs http:// appended (unless a relative 1120 1577 * link starting with / or a php file). 1121 */1578 */ 1122 1579 if ( strpos($url, ':') === false && 1123 1580 substr( $url, 0, 1 ) != '/' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) ) 1124 1581 $url = 'http://' . $url; … … 1135 1592 return apply_filters('clean_url', $url, $original_url, $context); 1136 1593 } 1137 1594 1595 /** 1596 * sanitize_url() - {@internal Missing Short Description}} 1597 * 1598 * {@internal Missing Long Description}} 1599 * 1600 * @since 2.3.1 1601 * 1602 * @param unknown_type $url 1603 * @param unknown_type $protocols 1604 * @return unknown 1605 */ 1138 1606 function sanitize_url( $url, $protocols = null ) { 1139 return clean_url( $url, $protocols, 'db' );1607 return clean_url( $url, $protocols, 'db' ); 1140 1608 } 1141 1609 1142 // Borrowed from the PHP Manual user notes. Convert entities, while 1143 // preserving already-encoded entities: 1610 /** 1611 * htmlentities2() - Convert entities, while preserving already-encoded entities 1612 * 1613 * {@internal Missing Long Description}} 1614 * 1615 * @link http://www.php.net/htmlentities Borrowed from the PHP Manual user notes. 1616 * 1617 * @since 1.2.2 1618 * 1619 * @param unknown_type $myHTML 1620 * @return unknown 1621 */ 1144 1622 function htmlentities2($myHTML) { 1145 $translation_table =get_html_translation_table (HTML_ENTITIES,ENT_QUOTES);1623 $translation_table = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES ); 1146 1624 $translation_table[chr(38)] = '&'; 1147 return preg_replace( "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($myHTML, $translation_table));1625 return preg_replace( "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&", strtr($myHTML, $translation_table) ); 1148 1626 } 1149 1627 1150 // Escape single quotes, specialchar double quotes, and fix line endings. 1628 /** 1629 * js_escape() - Escape single quotes, specialchar double quotes, and fix line endings 1630 * 1631 * {@internal Missing Long Description}} 1632 * 1633 * @since 2.0.4 1634 * 1635 * @param string $text 1636 * @return unknown 1637 */ 1151 1638 function js_escape($text) { 1152 1639 $safe_text = wp_specialchars($text, 'double'); 1153 1640 $safe_text = preg_replace('/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes($safe_text)); … … 1155 1642 return apply_filters('js_escape', $safe_text, $text); 1156 1643 } 1157 1644 1158 // Escaping for HTML attributes 1645 /** 1646 * attribute_escape() - Escaping for HTML attributes 1647 * 1648 * {@internal Missing Long Description}} 1649 * 1650 * @since 2.0.6 1651 * 1652 * @param unknown_type $text 1653 * @return unknown 1654 */ 1159 1655 function attribute_escape($text) { 1160 1656 $safe_text = wp_specialchars($text, true); 1161 1657 return apply_filters('attribute_escape', $safe_text, $text); 1162 1658 } 1163 1659 1660 /** 1661 * wp_make_link_relative() - {@internal Missing Short Description}} 1662 * 1663 * {@internal Missing Long Description}} 1664 * 1665 * @since 2.1.0 1666 * 1667 * @param unknown_type $link 1668 * @return unknown 1669 */ 1164 1670 function wp_make_link_relative( $link ) { 1165 return preg_replace( '|https?://[^/]+(/.*)|i', '$1', $link );1671 return preg_replace( '|https?://[^/]+(/.*)|i', '$1', $link ); 1166 1672 } 1167 1673 1168 function sanitize_option($option, $value) { // Remember to call stripslashes! 1674 /** 1675 * sanitize_option() - {@internal Missing Short Description}} 1676 * 1677 * {@internal Missing Long Description}} 1678 * Remember to call stripslashes! 1679 * 1680 * @since 2.0.5 1681 * 1682 * @param unknown_type $option 1683 * @param unknown_type $value 1684 * @return unknown 1685 */ 1686 function sanitize_option($option, $value) { 1169 1687 1170 1688 switch ($option) { 1171 1689 case 'admin_email': … … 1239 1757 return $value; 1240 1758 } 1241 1759 1760 /** 1761 * wp_parse_str() - {@internal Missing Short Description}} 1762 * 1763 * {@internal Missing Long Description}} 1764 * 1765 * @since 2.2.1 1766 * @uses apply_filters() 1767 * 1768 * @param string $string 1769 * @param array $array 1770 */ 1242 1771 function wp_parse_str( $string, &$array ) { 1243 1772 parse_str( $string, $array ); 1244 1773 if ( get_magic_quotes_gpc() ) … … 1246 1775 $array = apply_filters( 'wp_parse_str', $array ); 1247 1776 } 1248 1777 1249 // Convert lone less than signs. KSES already converts lone greater than signs. 1778 /** 1779 * wp_pre_kses_less_than() - Convert lone less than signs. 1780 * 1781 * KSES already converts lone greater than signs. 1782 * {@internal Missing Long Description}} 1783 * 1784 * @since 2.3.0 1785 * 1786 * @param string $text 1787 * @return unknown 1788 */ 1250 1789 function wp_pre_kses_less_than( $text ) { 1251 1790 return preg_replace_callback('%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $text); 1252 1791 } 1253 1792 1793 /** 1794 * wp_pre_kses_less_than_callback() - {@internal Missing Short Description}} 1795 * 1796 * {@internal Missing Long Description}} 1797 * 1798 * @since 2.3.0 1799 * 1800 * @param unknown_type $matches 1801 * @return unknown 1802 */ 1254 1803 function wp_pre_kses_less_than_callback( $matches ) { 1255 1804 if ( false === strpos($matches[0], '>') ) 1256 1805 return wp_specialchars($matches[0]); 1257 1806 return $matches[0]; 1258 1807 } 1259 1808 1260 ?> 1809 ?> 1810 No newline at end of file