Changeset 8598
- Timestamp:
- 08/09/2008 04:51:51 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r8589 r8598 119 119 if ( -1 == $i ) 120 120 $i = false; 121 121 122 122 if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) { 123 123 $datemonth = $wp_locale->get_month( date( 'm', $i ) ); … … 196 196 } 197 197 198 198 /** 199 * Get the week start and end from the datetime or date string from mysql. 200 * 201 * @since 0.71 202 * 203 * @param string $mysqlstring Date or datetime field type from mysql. 204 * @param int $start_of_week Optional. Start of the week as an integer. 205 * @return array Keys are 'start' and 'end'. 206 */ 199 207 function get_weekstartend( $mysqlstring, $start_of_week = '' ) { 200 $my = substr( $mysqlstring, 0, 4 ); 201 $mm = substr( $mysqlstring, 8, 2 ); 202 $md = substr( $mysqlstring, 5, 2 ); 203 $day = mktime( 0, 0, 0, $md, $mm, $my ); 204 $weekday = date( 'w', $day ); 205 $i = 86400; 208 $my = substr( $mysqlstring, 0, 4 ); // Mysql string Year 209 $mm = substr( $mysqlstring, 8, 2 ); // Mysql string Month 210 $md = substr( $mysqlstring, 5, 2 ); // Mysql string day 211 $day = mktime( 0, 0, 0, $md, $mm, $my ); // The timestamp for mysqlstring day. 212 $weekday = date( 'w', $day ); // The day of the week from the timestamp 213 $i = 86400; // One day 206 214 if( !is_numeric($start_of_week) ) 207 215 $start_of_week = get_option( 'start_of_week' ); … … 416 424 */ 417 425 function get_alloptions() { 418 global $wpdb , $wp_queries;426 global $wpdb; 419 427 $show = $wpdb->hide_errors(); 420 428 if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) ) … … 640 648 } 641 649 642 650 /** 651 * Strip HTML and put links at the bottom of stripped content. 652 * 653 * Searches for all of the links, strips them out of the content, and places 654 * them at the bottom of the content with numbers. 655 * 656 * @since unknown 657 * 658 * @param string $content Content to get links 659 * @return string HTML stripped out of content with links at the bottom. 660 */ 643 661 function make_url_footnote( $content ) { 644 662 preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches ); … … 660 678 } 661 679 662 680 /** 681 * Retrieve post title from XMLRPC XML. 682 * 683 * If the title element is not part of the XML, then the default post title from 684 * the $post_default_title will be used instead. 685 * 686 * @package WordPress 687 * @subpackage XMLRPC 688 * @since unknown 689 * 690 * @global string $post_default_title Default XMLRPC post title. 691 * 692 * @param string $content XMLRPC XML Request content 693 * @return string Post title 694 */ 663 695 function xmlrpc_getposttitle( $content ) { 664 696 global $post_default_title; … … 673 705 } 674 706 675 707 /** 708 * Retrieve the post category or categories from XMLRPC XML. 709 * 710 * If the category element is not found, then the default post category will be 711 * used. The return type then would be what $post_default_category. If the 712 * category is found, then it will always be an array. 713 * 714 * @package WordPress 715 * @subpackage XMLRPC 716 * @since unknown 717 * 718 * @global string $post_default_category Default XMLRPC post category. 719 * 720 * @param string $content XMLRPC XML Request content 721 * @return string|array List of categories or category name. 722 */ 676 723 function xmlrpc_getpostcategory( $content ) { 677 724 global $post_default_category; … … 685 732 } 686 733 687 734 /** 735 * XMLRPC XML content without title and category elements. 736 * 737 * @package WordPress 738 * @subpackage XMLRPC 739 * @since unknown 740 * 741 * @param string $content XMLRPC XML Request content 742 * @return string XMLRPC XML Request content without title and category elements. 743 */ 688 744 function xmlrpc_removepostdata( $content ) { 689 745 $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content ); … … 904 960 * Whether today is a new day. 905 961 * 906 * {@internal Need to find out how this function is used.}}907 *908 962 * @since 0.71 909 963 * @uses $day Today … … 936 990 */ 937 991 function build_query( $data ) { 938 return _http_build_query( $data, NULL, '&', '', false );992 return _http_build_query( $data, null, '&', '', false ); 939 993 } 940 994 … … 954 1008 * @param mixed $param2 Either newvalue or oldquery or uri 955 1009 * @param mixed $param3 Optional. Old query or uri 956 * @return unknown1010 * @return string New URL query string. 957 1011 */ 958 1012 function add_query_arg() { … … 1028 1082 * @param string|array $key Query key or keys to remove. 1029 1083 * @param bool $query When false uses the $_SERVER value. 1030 * @return unknown1084 * @return string New URL query string. 1031 1085 */ 1032 1086 function remove_query_arg( $key, $query=false ) { … … 1106 1160 } 1107 1161 1108 1162 /** 1163 * Setup the WordPress query. 1164 * 1165 * @since 2.0.0 1166 * 1167 * @param string $query_vars Default WP_Query arguments. 1168 */ 1109 1169 function wp( $query_vars = '' ) { 1110 1170 global $wp, $wp_query, $wp_the_query; … … 1264 1324 } 1265 1325 1266 1326 /** 1327 * Loads the feed template from the use of an action hook. 1328 * 1329 * If the feed action does not have a hook, then the function will die with a 1330 * message telling the visitor that the feed is not valid. 1331 * 1332 * It is better to only have one hook for each feed. 1333 * 1334 * @since 2.1.0 1335 * @uses $wp_query Used to tell if the use a comment feed. 1336 * @uses do_action() Calls 'do_feed_$feed' hook, if a hook exists for the feed. 1337 */ 1267 1338 function do_feed() { 1268 1339 global $wp_query; … … 1354 1425 } 1355 1426 1356 1427 /** 1428 * Test whether blog is already installed. 1429 * 1430 * The cache will be checked first. If you have a cache plugin, which saves the 1431 * cache values, then this will work. If you use the default WordPress cache, 1432 * and the database goes away, then you might have problems. 1433 * 1434 * Checks for the option siteurl for whether WordPress is installed. 1435 * 1436 * @since 2.1.0 1437 * @uses $wpdb 1438 * 1439 * @return bool Whether blog is already installed. 1440 */ 1357 1441 function is_blog_installed() { 1358 1442 global $wpdb; 1359 1443 1360 // Check cache first. 1444 // Check cache first. If options table goes away and we have true cached, oh well. 1361 1445 if ( wp_cache_get('is_blog_installed') ) 1362 1446 return true; … … 1372 1456 } 1373 1457 1374 1458 /** 1459 * Retrieve URL with nonce added to URL query. 1460 * 1461 * @since 2.0.4 1462 * 1463 * @param string $actionurl URL to add nonce action 1464 * @param string $action Optional. Nonce action name 1465 * @return string URL with nonce action added. 1466 */ 1375 1467 function wp_nonce_url( $actionurl, $action = -1 ) { 1376 1468 $actionurl = str_replace( '&', '&', $actionurl ); 1377 1469 return wp_specialchars( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) ); 1378 1470 } 1379 1380 1471 1381 1472 function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) { … … 1391 1482 } 1392 1483 1393 1394 1484 function wp_referer_field( $echo = true) { 1395 1485 $ref = attribute_escape( $_SERVER['REQUEST_URI'] ); … … 1410 1500 } 1411 1501 1412 1413 1502 function wp_get_referer() { 1414 1503 $ref = ''; … … 1429 1518 return false; 1430 1519 } 1431 1432 1520 1433 1521 function wp_mkdir_p( $target ) { … … 1454 1542 } 1455 1543 1456 // Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows') 1544 /** 1545 * Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows'). 1546 * 1547 * @since unknown 1548 * 1549 * @param string $path File path 1550 * @return bool True if path is absolute, false is not absolute. 1551 */ 1457 1552 function path_is_absolute( $path ) { 1458 1553 // this is definitive if true but fails if $path does not exist or contains a symbolic link … … 1471 1566 } 1472 1567 1473 // Join two filesystem paths together (e.g. 'give me $path relative to $base') 1568 /** 1569 * Join two filesystem paths together (e.g. 'give me $path relative to $base'). 1570 * 1571 * If the $path is absolute, then it the full path is returned. 1572 * 1573 * @since unknown 1574 * 1575 * @param string $base 1576 * @param string $path 1577 * @return string The path with the base or absolute path. 1578 */ 1474 1579 function path_join( $base, $path ) { 1475 1580 if ( path_is_absolute($path) ) … … 1479 1584 } 1480 1585 1481 // Returns an array containing the current upload directory's path and url, or an error message. 1482 function wp_upload_dir( $time = NULL ) { 1586 /** 1587 * Get an array containing the current upload directory's path and url, or an error message. 1588 * 1589 * {@internal Missing Long Description}} 1590 * 1591 * @since 2.0.0 1592 * 1593 * @param unknown_type $time 1594 * @return unknown 1595 */ 1596 function wp_upload_dir( $time = null ) { 1483 1597 $siteurl = get_option( 'siteurl' ); 1484 1598 $upload_path = get_option( 'upload_path' ); … … 1531 1645 } 1532 1646 1533 // return a filename that is sanitized and unique for the given directory 1534 function wp_unique_filename( $dir, $filename, $unique_filename_callback = NULL ) { 1647 /** 1648 * Get a filename that is sanitized and unique for the given directory. 1649 * 1650 * {@internal Missing Long Description}} 1651 * 1652 * @since 2.5 1653 * 1654 * @param string $dir 1655 * @param string $filename 1656 * @param string $unique_filename_callback Function name 1657 * @return unknown 1658 */ 1659 function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) { 1535 1660 $filename = strtolower( $filename ); 1536 1661 // separate the filename into a name and extension … … 1538 1663 $ext = $info['extension']; 1539 1664 $name = basename($filename, ".{$ext}"); 1540 1665 1541 1666 // edge case: if file is named '.ext', treat as an empty name 1542 1667 if( $name === ".$ext" ) … … 1569 1694 } 1570 1695 1571 function wp_upload_bits( $name, $deprecated, $bits, $time = NULL) {1696 function wp_upload_bits( $name, $deprecated, $bits, $time = null ) { 1572 1697 if ( empty( $name ) ) 1573 1698 return array( 'error' => __( "Empty filename" ) ); … … 1608 1733 } 1609 1734 1735 /** 1736 * Retrieve the file type based on the extension name. 1737 * 1738 * @package WordPress 1739 * @since unknown 1740 * @uses apply_filters() Calls 'ext2type' hook on default supported types. 1741 * 1742 * @param string $ext The extension to search. 1743 * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found. 1744 */ 1610 1745 function wp_ext2type( $ext ) { 1611 1746 $ext2type = apply_filters('ext2type', array( … … 1624 1759 } 1625 1760 1761 /** 1762 * Retrieve the file type from the file name. 1763 * 1764 * You can optionally define the mime array, if needed. 1765 * 1766 * @since 2.0.4 1767 * 1768 * @param string $filename File name or path. 1769 * @param array $mimes Optional. Key is the file extension with value as the mime type. 1770 * @return array Values with extension first and mime type. 1771 */ 1626 1772 function wp_check_filetype( $filename, $mimes = null ) { 1627 1773 // Accepted MIME types are set here as PCRE unless provided. … … 1688 1834 } 1689 1835 1836 /** 1837 * Retrieve nonce action "Are you sure" message. 1838 * 1839 * The action is split by verb and noun. The action format is as follows: 1840 * verb-action_extra. The verb is before the first dash and has the format of 1841 * letters and no spaces and numbers. The noun is after the dash and before the 1842 * underscore, if an underscore exists. The noun is also only letters. 1843 * 1844 * The filter will be called for any action, which is not defined by WordPress. 1845 * You may use the filter for your plugin to explain nonce actions to the user, 1846 * when they get the "Are you sure?" message. The filter is in the format of 1847 * 'explain_nonce_$verb-$noun' with the $verb replaced by the found verb and the 1848 * $noun replaced by the found noun. The two parameters that are given to the 1849 * hook are the localized "Are you sure you want to do this?" message with the 1850 * extra text (the text after the underscore). 1851 * 1852 * @since 2.0.4 1853 * 1854 * @param string $action Nonce action. 1855 * @return string Are you sure message. 1856 */ 1690 1857 function wp_explain_nonce( $action ) { 1691 1858 if ( $action !== -1 && preg_match( '/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches ) ) { … … 1753 1920 } 1754 1921 1755 1922 /** 1923 * Display "Are You Sure" message to confirm the action being taken. 1924 * 1925 * If the action has the nonce explain message, then it will be displayed along 1926 * with the "Are you sure?" message. 1927 * 1928 * @since 2.0.4 1929 * 1930 * @param string $action The nonce action. 1931 */ 1756 1932 function wp_nonce_ays( $action ) { 1757 1933 $title = __( 'WordPress Failure Notice' ); … … 1762 1938 } 1763 1939 1764 1940 /** 1941 * Kill WordPress execution and display HTML message with error message. 1942 * 1943 * Call this function complements the die() PHP function. The difference is that 1944 * HTML will be displayed to the user. It is recommended to use this function 1945 * only, when the execution should not continue any further. It is not 1946 * recommended to call this function very often and try to handle as many errors 1947 * as possible siliently. 1948 * 1949 * @since 2.0.4 1950 * 1951 * @param string $message Error message. 1952 * @param string $title Error title. 1953 */ 1765 1954 function wp_die( $message, $title = '' ) { 1766 1955 global $wp_locale; … … 1832 2021 } 1833 2022 1834 2023 /** 2024 * Retrieve the WordPress home page URL. 2025 * 2026 * If the constant named 'WP_HOME' exists, then it willl be used and returned by 2027 * the function. This can be used to counter the redirection on your local 2028 * development environment. 2029 * 2030 * @access private 2031 * @package WordPress 2032 * @since 2.2.0 2033 * 2034 * @param string $url URL for the home location 2035 * @return string Homepage location. 2036 */ 1835 2037 function _config_wp_home( $url = '' ) { 1836 2038 if ( defined( 'WP_HOME' ) ) … … 1839 2041 } 1840 2042 1841 2043 /** 2044 * Retrieve the WordPress site URL. 2045 * 2046 * If the constant named 'WP_SITEURL' is defined, then the value in that 2047 * constant will always be returned. This can be used for debugging a site on 2048 * your localhost while not having to change the database to your URL. 2049 * 2050 * @access private 2051 * @package WordPress 2052 * @since 2.2.0 2053 * 2054 * @param string $url URL to set the WordPress site location. 2055 * @return string The WordPress Site URL 2056 */ 1842 2057 function _config_wp_siteurl( $url = '' ) { 1843 2058 if ( defined( 'WP_SITEURL' ) ) … … 1846 2061 } 1847 2062 1848 2063 /** 2064 * Set the localized direction for MCE plugin. 2065 * 2066 * Will only set the direction to 'rtl', if the WordPress locale has the text 2067 * direction set to 'rtl'. 2068 * 2069 * Fills in the 'directionality', 'plugins', and 'theme_advanced_button1' array 2070 * keys. These keys are then returned in the $input array. 2071 * 2072 * @access private 2073 * @package WordPress 2074 * @subpackage MCE 2075 * @since 2.1.0 2076 * 2077 * @param array $input MCE plugin array. 2078 * @return array Direction set for 'rtl', if needed by locale. 2079 */ 1849 2080 function _mce_set_direction( $input ) { 1850 2081 global $wp_locale; … … 1859 2090 } 1860 2091 1861 2092 /** 2093 * Convert smiley code to the icon graphic file equivalent. 2094 * 2095 * You can turn off smilies, by going to the write setting screen and unchecking 2096 * the box, or by setting 'use_smilies' option to false or removing the option. 2097 * 2098 * Plugins may override the default smiley list by setting the $wpsmiliestrans 2099 * to an array, with the key the code the blogger types in and the value the 2100 * image file. 2101 * 2102 * The $wp_smiliessearch global is for the regular expression array and is 2103 * set each time the function is called. The $wp_smiliesreplace is the full 2104 * replacement. Supposely, the $wp_smiliessearch array is looped over using 2105 * preg_replace() or just setting the array of $wp_smiliessearch along with the 2106 * array of $wp_smiliesreplace in the search and replace parameters of 2107 * preg_replace(), which would be faster and less overhead. Either way, both are 2108 * used with preg_replace() and can be defined after the function is called. 2109 * 2110 * The full list of smilies can be found in the function and won't be listed in 2111 * the description. Probably should create a Codex page for it, so that it is 2112 * available. 2113 * 2114 * @global array $wpsmiliestrans 2115 * @global array $wp_smiliesreplace 2116 * @global array $wp_smiliessearch 2117 * @since 2.2.0 2118 */ 1862 2119 function smilies_init() { 1863 2120 global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace; … … 2057 2314 * 2058 2315 * @since 2.5 2059 * 2060 * @param mixed $maybeint data you wish to have convered to an absolute integer2061 * @return int an absolute integer2316 * 2317 * @param mixed $maybeint Data you wish to have convered to an absolute integer 2318 * @return int An absolute integer 2062 2319 */ 2063 2320 function absint( $maybeint ) { … … 2078 2335 { 2079 2336 if (in_array('curl', get_loaded_extensions())) { 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2337 $ssl = preg_replace( '/^http:\/\//', 'https://', $url ); 2338 2339 $ch = curl_init(); 2340 curl_setopt($ch, CURLOPT_URL, $ssl); 2341 curl_setopt($ch, CURLOPT_FAILONERROR, true); 2342 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 2343 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 2344 2345 curl_exec($ch); 2346 2347 $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); 2348 curl_close ($ch); 2349 2350 if ($status == 200 || $status == 401) { 2351 return true; 2352 } 2096 2353 } 2097 2354 return false; … … 2135 2392 * 2136 2393 * @param string $function The function that was called 2137 * @param string $version The version of WordPress that deprec eated the function2394 * @param string $version The version of WordPress that deprecated the function 2138 2395 * @param string $replacement Optional. The function that should have been called 2139 2396 */ … … 2172 2429 * 2173 2430 * @param string $file The file that was included 2174 * @param string $version The version of WordPress that deprec eated the function2431 * @param string $version The version of WordPress that deprecated the function 2175 2432 * @param string $replacement Optional. The function that should have been called 2176 2433 */
Note: See TracChangeset
for help on using the changeset viewer.