本文整理汇总了PHP中WP_Http::make_absolute_url方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Http::make_absolute_url方法的具体用法?PHP WP_Http::make_absolute_url怎么用?PHP WP_Http::make_absolute_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Http
的用法示例。
在下文中一共展示了WP_Http::make_absolute_url方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_make_absolute_url
/**
* @dataProvider make_absolute_url_testcases
*/
function test_make_absolute_url($relative_url, $absolute_url, $expected)
{
if (!is_callable(array('WP_Http', 'make_absolute_url'))) {
$this->markTestSkipped("This version of WP_HTTP doesn't support WP_HTTP::make_absolute_url()");
return;
}
$actual = WP_Http::make_absolute_url($relative_url, $absolute_url);
$this->assertEquals($expected, $actual);
}
示例2: handle_redirects
/**
* Handles HTTP Redirects and follows them if appropriate.
*
* @since 3.7.0
*
* @static
*
* @param string $url The URL which was requested.
* @param array $args The Arguments which were used to make the request.
* @param array $response The Response of the HTTP request.
* @return false|object False if no redirect is present, a WP_HTTP or WP_Error result otherwise.
*/
public static function handle_redirects($url, $args, $response)
{
// If no redirects are present, or, redirects were not requested, perform no action.
if (!isset($response['headers']['location']) || 0 === $args['_redirection']) {
return false;
}
// Only perform redirections on redirection http codes.
if ($response['response']['code'] > 399 || $response['response']['code'] < 300) {
return false;
}
// Don't redirect if we've run out of redirects.
if ($args['redirection']-- <= 0) {
return new WP_Error('http_request_failed', __('Too many redirects.'));
}
$redirect_location = $response['headers']['location'];
// If there were multiple Location headers, use the last header specified.
if (is_array($redirect_location)) {
$redirect_location = array_pop($redirect_location);
}
$redirect_location = WP_Http::make_absolute_url($redirect_location, $url);
// POST requests should not POST to a redirected location.
if ('POST' == $args['method']) {
if (in_array($response['response']['code'], array(302, 303))) {
$args['method'] = 'GET';
}
}
// Include valid cookies in the redirect process.
if (!empty($response['cookies'])) {
foreach ($response['cookies'] as $cookie) {
if ($cookie->test($redirect_location)) {
$args['cookies'][] = $cookie;
}
}
}
return wp_remote_request($redirect_location, $args);
}
示例3: _links_add_base
/**
* Callback to add a base url to relative links in passed content.
*
* @since 2.7.0
* @access private
*
* @global string $_links_add_base
*
* @param string $m The matched link.
* @return string The processed link.
*/
function _links_add_base($m)
{
global $_links_add_base;
//1 = attribute name 2 = quotation mark 3 = URL
return $m[1] . '=' . $m[2] . (preg_match('#^(\\w{1,20}):#', $m[3], $protocol) && in_array($protocol[1], wp_allowed_protocols()) ? $m[3] : WP_Http::make_absolute_url($m[3], $_links_add_base)) . $m[2];
}
示例4: update_data
function update_data()
{
remove_filter('pre_post_title', 'pre_post_title');
$upload_dir = wp_upload_dir();
$filename = $upload_dir['basedir'] . '/data.json';
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/image.php';
require_once ABSPATH . 'wp-admin/includes/media.php';
$items = array();
$args = array('numberposts' => -1, 'post_type' => 'business');
foreach (get_posts($args) as $post) {
$custom_fields = get_post_custom($post->ID);
list($address) = $custom_fields['address'];
list($latlng) = $custom_fields['latlng'];
list($phone) = $custom_fields['phone'];
$item = array('label' => my_html_entity_decode(wptexturize($post->post_title)), 'permalink' => get_permalink($post));
$item += array_filter(compact('address', 'latlng', 'phone'));
$website = esc_url_raw($custom_fields['website'][0]);
if ($website) {
$website = strtolower($website);
$website = preg_replace('/^https?:\\/\\/(?:www\\.)?([-.\\d_a-z~]+(?:\\/[-.\\/\\d_a-z~]+)?)\\/*/', 'http://$1', $website);
$args = array('timeout' => 300, 'redirection' => 0);
$response = wp_safe_remote_get($website, $args);
$args['redirection'] = 1;
$args['reject_unsafe_urls'] = true;
for ($i = 0; $i < 5; $i++) {
if (is_wp_error($response)) {
delete_post_meta($post->ID, 'website_up');
break;
}
$redirect_response = WP_Http::handle_redirects($website, $args, $response);
if (!$redirect_response) {
$website = preg_replace('/^(https?:\\/\\/[-.\\d_a-z~]+)\\/+$/i', '$1', $website);
//update_post_meta($post->ID, 'website', $website);
update_post_meta($post->ID, 'website_up', $website);
$body = wp_remote_retrieve_body($response);
$doc = new DOMDocument();
@$doc->loadHTML($body);
$url_parts = my_parse_url($website);
$urls = array();
foreach ($doc->getElementsByTagName('img') as $node) {
$relative_url_parts = my_parse_url($node->getAttribute('src'));
$relative_url_parts['path'] = str_replace(' ', '%20', $relative_url_parts['path']);
$relative_url_parts['query'] = str_replace(' ', '+', $relative_url_parts['query']);
if (!$relative_url_parts['scheme']) {
$relative_url_parts['scheme'] = $url_parts['scheme'];
if (!$relative_url_parts['host']) {
$relative_url_parts['host'] = $url_parts['host'];
$relative_url_parts['port'] = $url_parts['port'];
if (!$relative_url_parts['path']) {
$relative_url_parts['path'] = $url_parts['path'];
if (!$relative_url_parts['query']) {
$relative_url_parts['query'] = $url_parts['query'];
}
} else {
if ($relative_url_parts['path'][0] != '/') {
$relative_url_parts['path'] = "/{$relative_url_parts['path']}";
if ($url_parts['path']) {
$relative_url_parts['path'] = substr($url_parts['path'], 0, strrpos($url_parts['path'], '/')) . $relative_url_parts['path'];
}
}
}
}
}
do {
$relative_url_parts['path'] = preg_replace('/[^\\/]+\\/\\.\\.(?:\\/|$)/', '', $relative_url_parts['path'], 1, $count);
} while ($count);
$url = "{$relative_url_parts['scheme']}://{$relative_url_parts['host']}";
if ($relative_url_parts['port']) {
$url .= ":{$relative_url_parts['port']}";
}
$url .= $relative_url_parts['path'];
if ($relative_url_parts['query']) {
$url .= "?{$relative_url_parts['query']}";
}
$urls[$url] = $url;
}
if ($urls) {
$args = array('post_parent' => $post->ID, 'post_type' => 'attachment');
foreach (get_children($args) as $attachment) {
wp_delete_attachment($attachment->ID);
}
$found = false;
foreach ($urls as $url) {
$tmp_name = download_url($url);
list($width, $height) = getimagesize($tmp_name);
if ($width > 40 && $height > 40 && $width + $height > 180) {
preg_match('/[^\\/]+?(?=\\/?(?:$|\\?))/', $url, $matches);
$file_array = array('name' => $matches[0], 'tmp_name' => $tmp_name);
$thumbnail_id = media_handle_sideload($file_array, $post->ID);
if (!$found) {
set_post_thumbnail($post, $thumbnail_id);
$found = true;
}
}
}
}
break;
}
$website = WP_Http::make_absolute_url(wp_remote_retrieve_header($response, 'location'), $website);
//.........这里部分代码省略.........