WordPressを読む 10-4 /blog/wp-includes/functions.php 4
2014/11/30
目次
/blog/wp-includes/functions.php 4
読込元 : /blog/wp-settings.php
読込元 : /blog/wp-load.php
関数
wp_get_http()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | /** * Perform a HTTP HEAD or GET request. * * If $file_path is a writable filename, this will do a GET request and write * the file to that path. * * @since 2.5.0 * * @param string $url URL to fetch. * @param string|bool $file_path Optional. File path to write request to. Default false. * @param int $red Optional. The number of Redirects followed, Upon 5 being hit, * returns false. Default 1. * @return bool|string False on failure and string of headers if HEAD request. */ function wp_get_http( $url, $file_path = false, $red = 1 ) { @set_time_limit( 60 ); if ( $red > 5 ) return false; $options = array(); $options['redirection'] = 5; if ( false == $file_path ) $options['method'] = 'HEAD'; else $options['method'] = 'GET'; $response = wp_safe_remote_request( $url, $options ); if ( is_wp_error( $response ) ) return false; $headers = wp_remote_retrieve_headers( $response ); $headers['response'] = wp_remote_retrieve_response_code( $response ); // WP_HTTP no longer follows redirects for HEAD requests. if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) { return wp_get_http( $headers['location'], $file_path, ++$red ); } if ( false == $file_path ) return $headers; // GET request - write it to the supplied filename $out_fp = fopen($file_path, 'w'); if ( !$out_fp ) return $headers; fwrite( $out_fp, wp_remote_retrieve_body( $response ) ); fclose($out_fp); clearstatcache(); return $headers; } |
関数
wp_get_http_headers()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /** * Retrieve HTTP Headers from URL. * * @since 1.5.1 * * @param string $url URL to retrieve HTTP headers from. * @param bool $deprecated Not Used. * @return bool|string False on failure, headers on success. */ function wp_get_http_headers( $url, $deprecated = false ) { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '2.7' ); $response = wp_safe_remote_head( $url ); if ( is_wp_error( $response ) ) return false; return wp_remote_retrieve_headers( $response ); } |
関数
is_new_day()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * Whether the publish date of the current post in the loop is different from the * publish date of the previous post in the loop. * * @since 0.71 * * @global string $currentday The day of the current post in the loop. * @global string $previousday The day of the previous post in the loop. * * @return int|bool 1|true when new day, 0|false if not a new day. */ function is_new_day() { global $currentday, $previousday; if ( $currentday != $previousday ) return 1; else return 0; } |
関数
build_query()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * Build URL query based on an associative and, or indexed array. * * This is a convenient function for easily building url queries. It sets the * separator to '&' and uses _http_build_query() function. * * @since 2.3.0 * * @see _http_build_query() Used to build the query * @see http://us2.php.net/manual/en/function.http-build-query.php for more on what * http_build_query() does. * * @param array $data URL-encode key/value pairs. * @return string URL-encoded string. */ function build_query( $data ) { return _http_build_query( $data, null, '&', '', false ); } |
関数
_http_build_query()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | /** * From php.net (modified by Mark Jaquith to behave like the native PHP5 function). * * @since 3.2.0 * @access private * * @see http://us1.php.net/manual/en/function.http-build-query.php * * @param array|object $data An array or object of data. Converted to array. * @param string $prefix Optional. Numeric index. If set, start parameter numbering with it. * Default null. * @param string $sep Optional. Argument separator; defaults to 'arg_separator.output'. * Default null. * @param string $key Optional. Used to prefix key name. Default empty. * @param bool $urlencode Optional. Whether to use urlencode() in the result. Default true. * * @return string The query string. */ function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urlencode = true ) { $ret = array(); foreach ( (array) $data as $k => $v ) { if ( $urlencode) $k = urlencode($k); if ( is_int($k) && $prefix != null ) $k = $prefix.$k; if ( !empty($key) ) $k = $key . '%5B' . $k . '%5D'; if ( $v === null ) continue; elseif ( $v === FALSE ) $v = '0'; if ( is_array($v) || is_object($v) ) array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode)); elseif ( $urlencode ) array_push($ret, $k.'='.urlencode($v)); else array_push($ret, $k.'='.$v); } if ( null === $sep ) $sep = ini_get('arg_separator.output'); return implode($sep, $ret); } |
関数
add_query_arg()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | /** * Retrieve a modified URL query string. * * You can rebuild the URL and append a new query variable to the URL query by * using this function. You can also retrieve the full URL with query data. * * Adding a single key & value or an associative array. Setting a key value to * an empty string removes the key. Omitting oldquery_or_uri uses the $_SERVER * value. Additional values provided are expected to be encoded appropriately * with urlencode() or rawurlencode(). * * @since 1.5.0 * * @param string|array $param1 Either newkey or an associative_array. * @param string $param2 Either newvalue or oldquery or URI. * @param string $param3 Optional. Old query or URI. * @return string New URL query string. */ function add_query_arg() { $args = func_get_args(); if ( is_array( $args[0] ) ) { if ( count( $args ) < 2 || false === $args[1] ) $uri = $_SERVER['REQUEST_URI']; else $uri = $args[1]; } else { if ( count( $args ) < 3 || false === $args[2] ) $uri = $_SERVER['REQUEST_URI']; else $uri = $args[2]; } if ( $frag = strstr( $uri, '#' ) ) $uri = substr( $uri, 0, -strlen( $frag ) ); else $frag = ''; if ( 0 === stripos( $uri, 'http://' ) ) { $protocol = 'http://'; $uri = substr( $uri, 7 ); } elseif ( 0 === stripos( $uri, 'https://' ) ) { $protocol = 'https://'; $uri = substr( $uri, 8 ); } else { $protocol = ''; } if ( strpos( $uri, '?' ) !== false ) { list( $base, $query ) = explode( '?', $uri, 2 ); $base .= '?'; } elseif ( $protocol || strpos( $uri, '=' ) === false ) { $base = $uri . '?'; $query = ''; } else { $base = ''; $query = $uri; } wp_parse_str( $query, $qs ); $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string if ( is_array( $args[0] ) ) { $kayvees = $args[0]; $qs = array_merge( $qs, $kayvees ); } else { $qs[ $args[0] ] = $args[1]; } foreach ( $qs as $k => $v ) { if ( $v === false ) unset( $qs[$k] ); } $ret = build_query( $qs ); $ret = trim( $ret, '?' ); $ret = preg_replace( '#=(&|$)#', '$1', $ret ); $ret = $protocol . $base . $ret . $frag; $ret = rtrim( $ret, '?' ); return $ret; } |