コード例 #1
1
 function test_head_404()
 {
     $url = 'http://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
     $response = wp_remote_head($url);
     $this->assertTrue(is_array($response));
     $this->assertEquals('404', wp_remote_retrieve_response_code($response));
 }
コード例 #2
0
 function test_head_404()
 {
     $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
     $headers = wp_remote_head($url);
     $this->assertInternalType('array', $headers, "Reply wasn't array.");
     $this->assertEquals('404', wp_remote_retrieve_response_code($headers));
 }
コード例 #3
0
ファイル: res.php プロジェクト: ntnvu/tcb_online
 public static function get_preview_from_url($url)
 {
     $preview = '';
     $images = array('jpg', 'jpeg', 'bmp', 'gif', 'png');
     if (filter_var($url, FILTER_VALIDATE_URL) !== FALSE) {
         // check for extension, if it has extension then use it
         $info = pathinfo($url);
         if (isset($info['extension'])) {
             if (in_array($info['extension'], $images)) {
                 $preview = $url;
             } else {
                 $type = wp_ext2type($info['extension']);
                 if (is_null($type)) {
                     $type = 'default';
                 }
                 $preview = includes_url() . 'images/crystal/' . $type . '.png';
             }
         } else {
             // if no extension, try to discover from mime
             $mime = wp_remote_head($url);
             if (!is_wp_error($mime)) {
                 $mime = $mime['headers']['content-type'];
                 if (strpos($mime, 'image') === 0) {
                     $preview = $url;
                 } else {
                     $preview = wp_mime_type_icon($mime);
                 }
             } else {
                 $preview = includes_url() . 'images/crystal/' . 'default' . '.png';
             }
         }
     }
     return $preview;
 }
コード例 #4
0
function mixcloud_shortcode($atts, $content = null)
{
    if (empty($atts[0]) && empty($content)) {
        return "<!-- mixcloud error: invalid mixcloud resource -->";
    }
    $regular_expression = "#((?<=mixcloud.com/)([A-Za-z0-9_-]+/[A-Za-z0-9_-]+))|^([A-Za-z0-9_-]+/[A-Za-z0-9_-]+)#i";
    preg_match($regular_expression, $content, $match);
    if (!empty($match)) {
        $resource_id = trim($match[0]);
    } else {
        preg_match($regular_expression, $atts[0], $match);
        if (!empty($match)) {
            $resource_id = trim($match[0]);
        }
    }
    if (empty($resource_id)) {
        return "<!-- mixcloud error: invalid mixcloud resource -->";
    }
    $atts = shortcode_atts(array('width' => 300, 'height' => 300), $atts, 'mixcloud');
    // Build URL
    $url = add_query_arg($atts, "http://api.mixcloud.com/{$resource_id}/embed-html/");
    $head = wp_remote_head($url);
    if (is_wp_error($head) || 200 != $head['response']['code']) {
        return "<!-- mixcloud error: invalid mixcloud resource -->";
    }
    return sprintf('<iframe width="%d" height="%d" scrolling="no" frameborder="no" src="%s"></iframe>', $atts['width'], $atts['height'], esc_url($url));
}
コード例 #5
0
 function url_exists($url)
 {
     $remote_head = wp_remote_head($url);
     if (is_wp_error($remote_head)) {
         return false;
     } else {
         return 404 !== $remote_head['response']['code'];
     }
 }
 /**
  * Asserts an image actually exists as quickly as possible by sending a HEAD
  * request
  * @param string $src
  * @return boolean
  */
 protected function src_exists($src)
 {
     $results = wp_remote_head($src);
     if (is_array($results) && !$results instanceof WP_Error) {
         return strpos($results['headers']['content-type'], "image") !== FALSE;
     } else {
         return FALSE;
     }
 }
コード例 #7
0
ファイル: goodreads.php プロジェクト: brooklyntri/btc-plugins
 function goodreads_user_id_exists($user_id)
 {
     $url = "http://www.goodreads.com/user/show/{$user_id}/";
     $response = wp_remote_head($url, array('httpversion' => '1.1', 'timeout' => 3, 'redirection' => 2));
     if (wp_remote_retrieve_response_code($response) === 200) {
         return true;
     } else {
         return false;
     }
 }
コード例 #8
0
 public function get_thumbnail_url($id)
 {
     $maxres = 'http://img.youtube.com/vi/' . $id . '/maxresdefault.jpg';
     $response = wp_remote_head($maxres);
     if (!is_wp_error($response) && $response['response']['code'] == '200') {
         $result = $maxres;
     } else {
         $result = 'http://img.youtube.com/vi/' . $id . '/0.jpg';
     }
     return $result;
 }
コード例 #9
0
/**
 * check http range support for heavy download
 */
function mgm_check_http_range_support($key = NULL)
{
    // sample
    //$sample_url = site_url('wp-content/plugins/magicmembers/core/assets/images/logo.png');
    // sample
    $sample_url = MGM_ASSETS_URL . 'images/logo.png';
    // headers
    $h = wp_remote_head($sample_url, array('timeout' => 30));
    // return
    return isset($h['headers']['accept-ranges']) && $h['headers']['accept-ranges'] == 'bytes' ? true : false;
}
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $env = Validators::validateEnv($input->getOption('env'));
     $root = $this->skeleton->getWebRoot();
     $plugins = $this->skeleton->get(sprintf('wordpress.%s.plugins', $env));
     require $root . '/wp-load.php';
     require ABSPATH . 'wp-admin/includes/admin.php';
     require ABSPATH . 'wp-admin/includes/plugin-install.php';
     foreach ($plugins as $slug => $version) {
         $plugin = plugins_api('plugin_information', array('slug' => $slug));
         if (is_wp_error($plugin)) {
             throw new \Exception('Could not get plugin information for ' . $slug);
         }
         if ($version) {
             list($prefix) = explode($slug, $plugin->download_link);
             $link = sprintf('%s%s.%s.zip', $prefix, $slug, $version);
             $response = wp_remote_head($link);
             if (!isset($response['response']['code']) || $response['response']['code'] != 200) {
                 throw new \Exception('Unable to verify ' . $link);
             }
             $plugin->download_link = $link;
             $plugin->version = $version;
         }
         require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         $status = install_plugin_install_status($plugin);
         $upgrader = new \Plugin_Upgrader(new UpgraderSkin($output));
         $current = current(get_plugins("/{$slug}"));
         switch ($status['status']) {
             case 'install':
                 $output->write(sprintf('Installing <info>%s</info> v<comment>%s</comment>', $plugin->name, $plugin->version));
                 $upgrader->install($plugin->download_link);
                 break;
             case 'update_available':
                 if ($plugin->version == $current['Version']) {
                     $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $plugin->version));
                 } else {
                     $output->write(sprintf('Upgrading <info>%s</info> from <comment>%s</comment> to <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version));
                     $file = sprintf('%s/%s', $slug, key(get_plugins("/{$slug}")));
                     $upgrader->upgrade($file);
                 }
                 break;
             case 'latest_installed':
                 $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $current['Version']));
                 break;
             case 'newer_installed':
                 $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is installed & newer than <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version));
                 break;
         }
     }
     if ($plugins) {
         $output->writeln(sprintf('<info>Activate plugins in the WordPress Admin</info>', $plugin->name));
     }
 }
コード例 #11
0
 public function check()
 {
     $response = wp_remote_head($this->args['domain']);
     $this->ok = !is_wp_error($response);
     if ($this->ok) {
         $this->info = __('Your server can connect to the themes demo content data', 'lambda-admin-td');
         $this->value = $response['response']['code'] . ' - ' . $response['response']['message'];
     } else {
         $this->info = __('Your server can not connect to the themes demo content data', 'lambda-admin-td');
         $this->value = $response->get_error_message();
     }
 }
コード例 #12
0
/**
 * Enqueue jQuery from Google CDN with fallback to local WordPress
 * First we have a really complex method of loading jQuery from the CDN or local
 * should the CDN fail. The code is adapted from https://gist.github.com/wpsmith/4083811.
 * Then we load basic styles.
 *
 * @package pp
 * @subpackage boilerplate-theme_filters+hooks
 * @internal only called by `wp_enqueue_scripts` action
 *
 * @link https://gist.github.com/wpsmith/4083811.
 * @link http://codex.wordpress.org/Function_Reference/wp_enqueue_script
 * @link http://codex.wordpress.org/Function_Reference/wp_register_script
 * @link http://codex.wordpress.org/Function_Reference/wp_deregister_script
 * @link http://codex.wordpress.org/Function_Reference/get_bloginfo
 * @link http://codex.wordpress.org/Function_Reference/is_wp_error
 * @link http://codex.wordpress.org/Function_Reference/set_transient
 * @link http://codex.wordpress.org/Function_Reference/get_transient
 *
 * @uses get_transient()		  Get the value of a transient.
 * @uses set_transient()		  Set/update the value of a transient.
 * @uses is_wp_error()			 Check whether the passed variable is a WordPress Error.
 * @uses get_bloginfo()			returns information about your site.
 * @uses wp_deregister_script() Deregisters javascripts for use with wp_enqueue_script() later.
 * @uses wp_register_script()	Registers javascripts for use with wp_enqueue_script() later.
 * @uses wp_enqueue_script()	 Enqueues javascript.
 */
function pp_enqueue_jquery()
{
    $script_location = 'js/dist/application.js';
    $script_head_location = 'js/dist/application-head.js';
    // Setup Google URI, default
    $protocol = isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS'] ? 'https' : 'http';
    // Get Latest Version
    $url = $protocol . '://code.jquery.com/jquery-1.11.3.min.js';
    // Get Specific Version
    //$url = $protocol . '://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js';
    // Setup WordPress URI
    $wpurl = get_bloginfo('template_directory') . '/js/src/vendor/jquery-1.11.3.min.js';
    // Setup version
    $ver = null;
    // Deregister WordPress default jQuery
    wp_deregister_script('jquery');
    // Check transient, if false, set URI to WordPress URI
    delete_transient('google_jquery');
    if ('false' == ($google = get_transient('google_jquery'))) {
        $url = $wpurl;
    } elseif (false === $google) {
        // Ping Google
        $resp = wp_remote_head($url);
        // Use Google jQuery
        if (!is_wp_error($resp) && 200 == $resp['response']['code']) {
            // Set transient for 5 minutes
            set_transient('google_jquery', 'true', 60 * 5);
        } else {
            // Set transient for 5 minutes
            set_transient('google_jquery', 'false', 60 * 5);
            // Use WordPress URI
            $url = $wpurl;
            // Set jQuery Version, WP stanards
            $ver = '1.8.2';
        }
    }
    // Register surefire jQuery
    wp_register_script('jquery', $url, array(), $ver, true);
    // Enqueue jQuery
    wp_enqueue_script('jquery');
    // Now load basic site js
    wp_enqueue_script('pp-theme-head', get_bloginfo('template_directory') . '/' . $script_head_location, array('jquery'), '1.0');
    wp_enqueue_script('pp-theme', get_bloginfo('template_directory') . '/' . $script_location, array('jquery'), '1.0', true);
    // Add some site information to a WP js object
    $wp_object = array('templateUrl' => get_bloginfo('template_url'), 'stylesheetUrl' => get_bloginfo('stylesheet_url'), 'stylesheetDirectory' => get_bloginfo('stylesheet_directory'), 'siteName' => get_bloginfo('name'), 'description' => get_bloginfo('description'), 'currentTheme' => wp_get_theme(), 'url' => get_bloginfo('url'));
    wp_localize_script('basic', 'ppWP', $wp_object);
    // For comment reply form
    if (is_singular() && get_option('thread_comments') && comments_open()) {
        wp_enqueue_script('comment-reply');
    }
}
コード例 #13
0
 /**
  * Won't work with soil-relative-urls
  */
 private static function get_banner_tint($url)
 {
     $banner_tint = '#5c5d5f';
     $thumb_request = wp_remote_head($url);
     if (is_wp_error($url)) {
         return $banner_tint;
     }
     $tonesque_exists = class_exists('Tonesque');
     $is_404_error = 404 === $thumb_request['response']['code'];
     if (!$tonesque_exists || $is_404_error) {
         return $banner_tint;
     }
     $tonesque = new \Tonesque($thumb);
     return '#' . $tonesque->color('hex');
 }
コード例 #14
0
ファイル: LinkCard.php プロジェクト: Aquei/purely
 /**
  * 投稿の最初の画像についてsrcとsrcsetを探す
  * @return array src文字列 srcset文字列 alt文字列
  */
 protected function getImg()
 {
     if (\has_post_thumbnail($this->post->ID)) {
         $target = \get_the_post_thumbnail($this->post->ID);
     } else {
         $target = $this->getContent();
     }
     $patterns = ["img" => "/<img [^>]+>/i", "src" => "/src=(?P<q>\"|')(?P<src>.*?)(?P=q)/", "srcset" => "/srcset=(?P<q>\"|')(?P<srcset>.*?)(?P=q)/", "alt" => "/alt=(?P<q>\"|')(?P<alt>.*?)(?P=q)/"];
     $src = "";
     $srcset = "";
     $alt = "";
     $result = \preg_match($patterns["img"], $target, $m);
     if ($result) {
         $img = $m[0];
         if (\preg_match($patterns["src"], $img, $m2)) {
             $src = $m2["src"];
         }
         if (\preg_match($patterns["srcset"], $img, $m3)) {
             $srcset = $m3["srcset"];
         }
         if (\preg_match($patterns["alt"], $img, $m4)) {
             $alt = $m4["alt"];
         }
     }
     if (!$result) {
         //youtubeの埋め込みコードを探す
         $yt_patterns = ["@<iframe\\b[^>]+src=['\"]https?://www\\.youtube\\.com/embed/(?P<id>[a-zA-Z0-9_\\-]+)@"];
         foreach ($yt_patterns as $p) {
             $result = \preg_match($p, $target, $match);
             if ($result) {
                 $id = $match["id"];
                 $src = "https://i.ytimg.com/vi/{$id}/0.jpg";
                 $temp = ["https://i.ytimg.com/vi/{$id}/default.jpg 120w", "https://i.ytimg.com/vi/{$id}/mqdefault.jpg 320w", "https://i.ytimg.com/vi/{$id}/0.jpg 480w"];
                 //maxresdefault.jpgが存在するかチェック
                 $maxQ = "https://i.ytimg.com/vi/{$id}/maxresdefault.jpg";
                 $resp = \wp_remote_head($maxQ);
                 if (!\is_wp_error($resp) && in_array(\wp_remote_retrieve_response_code($resp), [200, 301, 302])) {
                     //あった
                     //maxresdefaultは1980等の場合もある 注意
                     \array_push($temp, $maxQ . " 1280w");
                 }
                 $srcset = \implode(" ,", $temp);
                 break;
             }
         }
     }
     return ["src" => $src, "srcset" => $srcset, "alt" => $alt];
 }
コード例 #15
0
 /**
  * Test the tests
  *
  * @group external-oembed
  * @ticket 28507
  * @ticket 32360
  *
  * @dataProvider oEmbedProviderData
  */
 public function testOembedTestURLsResolve($match, array $urls)
 {
     if (empty($urls)) {
         $this->markTestIncomplete();
     }
     foreach ($urls as $url) {
         $msg = sprintf('Test URL: %s', $url);
         $r = wp_remote_head($url, array('redirection' => 3));
         if (is_wp_error($r)) {
             $this->fail(sprintf("%s (%s)\n%s", $r->get_error_message(), $r->get_error_code(), $msg));
         }
         $http_code = wp_remote_retrieve_response_code($r);
         $http_message = wp_remote_retrieve_response_message($r);
         $this->assertSame(200, $http_code, "{$msg}\n- HTTP response code: {$http_code} {$http_message}");
     }
 }
コード例 #16
0
 /**
  * @ticket 33711
  */
 function test_get_response_cookies()
 {
     $url = 'https://login.wordpress.org/wp-login.php';
     $response = wp_remote_head($url);
     $cookies = wp_remote_retrieve_cookies($response);
     $this->assertNotEmpty($cookies);
     $cookie = wp_remote_retrieve_cookie($response, 'wordpress_test_cookie');
     $this->assertInstanceOf('WP_Http_Cookie', $cookie);
     $this->assertSame('wordpress_test_cookie', $cookie->name);
     $this->assertSame('WP Cookie check', $cookie->value);
     $value = wp_remote_retrieve_cookie_value($response, 'wordpress_test_cookie');
     $this->assertSame('WP Cookie check', $value);
     $no_value = wp_remote_retrieve_cookie_value($response, 'not_a_cookie');
     $this->assertSame('', $no_value);
     $no_cookie = wp_remote_retrieve_cookie($response, 'not_a_cookie');
     $this->assertSame('', $no_cookie);
 }
コード例 #17
0
 function validate_gravatar($id_or_email)
 {
     //id or email code borrowed from wp-includes/pluggable.php
     $email = '';
     if (is_numeric($id_or_email)) {
         $id = (int) $id_or_email;
         $user = get_userdata($id);
         if ($user) {
             $email = $user->user_email;
         }
     } elseif (is_object($id_or_email)) {
         // No avatar for pingbacks or trackbacks
         $allowed_comment_types = apply_filters('get_avatar_comment_types', array('comment'));
         if (!empty($id_or_email->comment_type) && !in_array($id_or_email->comment_type, (array) $allowed_comment_types)) {
             return false;
         }
         if (!empty($id_or_email->user_id)) {
             $id = (int) $id_or_email->user_id;
             $user = get_userdata($id);
             if ($user) {
                 $email = $user->user_email;
             }
         } elseif (!empty($id_or_email->comment_author_email)) {
             $email = $id_or_email->comment_author_email;
         }
     } else {
         $email = $id_or_email;
     }
     $hashkey = md5(strtolower(trim($email)));
     $uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
     $data = wp_cache_get($hashkey);
     if (false === $data) {
         $response = wp_remote_head($uri);
         if (is_wp_error($response)) {
             $data = 'not200';
         } else {
             $data = $response['response']['code'];
         }
         wp_cache_set($hashkey, $data, $group = '', $expire = 60 * 5);
     }
     if ($data == '200') {
         return true;
     } else {
         return false;
     }
 }
コード例 #18
0
ファイル: updater.php プロジェクト: markoheijnen/life-control
 public function check_streamallthis($episode)
 {
     $serie = get_post($episode->post_parent);
     if (!$serie) {
         return;
     }
     $streamallthis = get_post_meta($serie->ID, 'streamallthis_name', true);
     $season = get_post_meta($episode->ID, 'season', true);
     $episode_nr = get_post_meta($episode->ID, 'episode', true);
     if ($streamallthis) {
         $code = sprintf('s%02de%02d', $season, $episode_nr);
         $url = 'http://streamallthis.me/watch/' . $streamallthis . '/' . $code . '.html';
         $response = wp_remote_head($url);
         if (!is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response)) {
             update_post_meta($episode->ID, 'streamallthis', $url);
         }
     }
 }
コード例 #19
0
ファイル: avatars.php プロジェクト: DrewAPicture/Largo
/**
 * Determine whether or not an author has a valid gravatar image
 * see: http://codex.wordpress.org/Using_Gravatars
 *
 * @param $email string an author's email address
 * @return bool true if a gravatar is available for this user
 * @since 0.3
 */
function largo_has_gravatar($email)
{
    // Craft a potential url and test its headers
    $hash = md5(strtolower(trim($email)));
    $cache_key = 'largo_has_gravatar_' . $hash;
    if (false !== ($cache_value = get_transient($cache_key))) {
        return (bool) $cache_value;
    }
    $uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
    $response = wp_remote_head($uri);
    if (200 == wp_remote_retrieve_response_code($response)) {
        $cache_value = '1';
    } else {
        $cache_value = '0';
    }
    set_transient($cache_key, $cache_value);
    return (bool) $cache_value;
}
コード例 #20
0
 /**
  * Gets the Pingback endpoint URI provided by a web page specified by URL
  *
  * @return string|boolean Returns the Pingback endpoint URI if found or false
  */
 function get_endpoint_uri($url)
 {
     // First check for an X-pingback header
     if (!($response = wp_remote_head($url))) {
         return false;
     }
     if (!($content_type = wp_remote_retrieve_header($response, 'content-type'))) {
         return false;
     }
     if (preg_match('#(image|audio|video|model)/#is', $content_type)) {
         return false;
     }
     if ($x_pingback = wp_remote_retrieve_header($response, 'x-pingback')) {
         return trim($x_pingback);
     }
     // Fall back to extracting it from the HTML link
     if (!($response = wp_remote_get($url))) {
         return false;
     }
     if (200 !== wp_remote_retrieve_response_code($response)) {
         return false;
     }
     if ('' === ($response_body = wp_remote_retrieve_body($response))) {
         return false;
     }
     if (!preg_match_all('@<link([^>]+)>@im', $response_body, $response_links)) {
         return false;
     }
     foreach ($response_links[1] as $response_link_attributes) {
         $_link = array('rel' => false, 'href' => false);
         $response_link_attributes = preg_split('@\\s+@im', $response_link_attributes, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($response_link_attributes as $response_link_attribute) {
             if ($_link['rel'] == 'pingback' && $_link['href']) {
                 return $_link['href'];
             }
             if (strpos($response_link_attribute, '=', 1) !== false) {
                 list($_key, $_value) = explode('=', $response_link_attribute, 2);
                 $_link[strtolower($_key)] = trim($_value, "'\"");
             }
         }
     }
     // Fail
     return false;
 }
コード例 #21
0
 public function get_thumbnail_url($id)
 {
     $request = 'https://graph.facebook.com/' . $id . '/picture?redirect=false';
     $response = wp_remote_get($request, array('sslverify' => false));
     if (is_wp_error($response)) {
         $result = $this->construct_info_retrieval_error($request, $response);
     } else {
         $result = json_decode($response['body']);
         $result = $result->data->url;
         $high_res = str_replace('_t.jpg', '_b.jpg', $result);
         if ($high_res != $result) {
             $response = wp_remote_head($high_res);
             if (!is_wp_error($response) && $response['response']['code'] == '200') {
                 $result = $high_res;
             }
         }
     }
     return $result;
 }
コード例 #22
0
ファイル: ip2nation.php プロジェクト: ashik968/digiplot
 function status()
 {
     global $wpdb;
     $sql = "SHOW TABLE STATUS WHERE Name LIKE '" . $this->db . "'";
     $db_info = $wpdb->get_row($sql);
     if ($db_info != NULL) {
         $ip2nationdb_ts = $db_info->Update_time != NULL ? strtotime($db_info->Update_time) : strtotime($db_info->Create_time);
         $ip2nationdb_time = date('D, d M Y H:i:s', $ip2nationdb_ts);
         $uninstall = True;
     } else {
         $ip2nationdb_ts = False;
         $uninstall = False;
     }
     $result = wp_remote_head($this->remote_file, array('timeout' => 1));
     if (is_wp_error($result)) {
         $ip2nationfile_ts = False;
     } else {
         $ip2nationfile_ts = strtotime($result['headers']['last-modified']);
         $ip2nationfile_time = date('D, d M Y H:i:s', $ip2nationfile_ts);
         $ip2nationfile_length = $result['headers']['content-length'];
     }
     $install = False;
     if (!$ip2nationdb_ts) {
         if (!$ip2nationfile_ts) {
             $message = __('You currently do not have <b>ip2nation</b> installed, and the remote file is unavailable', 'amazon-link');
         } else {
             $install = True;
             $message = sprintf(__('You currently do not have <b>ip2nation</b> installed, the latest version available is dated: %s', 'amazon-link'), $ip2nationfile_time);
         }
     } else {
         if (!$ip2nationfile_ts) {
             $message = sprintf(__('Your <b>ip2nation</b> database was last updated on %1$s, the remote file is unavailable.', 'amazon-link'), $ip2nationdb_time);
         } else {
             if ($ip2nationfile_ts > $ip2nationdb_ts) {
                 $message = sprintf(__('<b>WARNING!</b> Your <b>ip2nation</b> database is out of date. It was last updated on %1$s, the latest version available is dated: %2$s', 'amazon-link'), $ip2nationdb_time, $ip2nationfile_time);
                 $install = True;
             } else {
                 $message = sprintf(__('Your <b>ip2nation</b> database is up to date. (It was last updated on %1$s, the latest version available is dated: %2$s).', 'amazon-link'), $ip2nationdb_time, $ip2nationfile_time);
             }
         }
     }
     return array('Uninstall' => $uninstall, 'Install' => $install, 'Message' => $message);
 }
コード例 #23
0
/**
 * Check if a URL returns a 200 HTTP response
 *
 * The result us cachec for one hour.
 *
 * @param  string $url The URL
 * @return bool   The result   
 */
function url_works($url)
{
    // Return cached success
    if ('url_works' === get_transient(md5('url_' . $url))) {
        return TRUE;
    }
    // Check result
    $response = wp_remote_head($url);
    if (is_wp_error($response) || 200 != $response['response']['code']) {
        $url_works = FALSE;
    } else {
        $url_works = TRUE;
    }
    // Save success
    if ($url_works) {
        set_transient(md5('url_' . $url), 'url_works', 3600);
    }
    // Return result
    return $url_works;
}
コード例 #24
0
 /**
  * Returns true if user has Gravatar-hosted image
  * @since 1.4
  * @param int|string $id_or_email
  * @param bool $has_gravatar
  * @param int|string $user
  * @param string $email
  * @uses get_user_by()
  * @uses is_wp_error()
  * @uses wp_cache_get()
  * @uses wp_cache_set()
  * @uses wp_remote_head()
  * @return bool $has_gravatar
  */
 public function wpua_has_gravatar($id_or_email = "", $has_gravatar = 0, $user = "", $email = "")
 {
     if (!is_object($id_or_email) && !empty($id_or_email)) {
         // Find user by ID or e-mail address
         $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
         // Get registered user e-mail address
         $email = !empty($user) ? $user->user_email : "";
     }
     // Check if Gravatar image returns 200 (OK) or 404 (Not Found)
     $hash = md5(strtolower(trim($email)));
     $gravatar = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
     $data = wp_cache_get($hash);
     if (false === $data) {
         $response = wp_remote_head($gravatar);
         $data = is_wp_error($response) ? 'not200' : $response['response']['code'];
         wp_cache_set($hash, $data, $group = "", $expire = 60 * 5);
     }
     $has_gravatar = $data == '200' ? true : false;
     return (bool) $has_gravatar;
 }
コード例 #25
0
ファイル: class.ss-ga.php プロジェクト: thibmo/hackthis.co.uk
 /**
  * Use WP's HTTP class or CURL or fopen 
  * @return array|null 
  */
 private function remote_call()
 {
     if (function_exists('wp_remote_head')) {
         // Check if this is being used with WordPress, if so use it's excellent HTTP class
         $response = wp_remote_head($this->tracking);
         // prp($response);
         return $response;
     } elseif (function_exists('curl_init')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $this->tracking);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_TIMEOUT, 10);
         curl_exec($ch);
         curl_close($ch);
     } else {
         $handle = fopen($this->tracking, "r");
         fclose($handle);
     }
     return;
 }
コード例 #26
0
 private function sideload_attachment($attachment, $_to_post_id, $date)
 {
     if ('image' === $attachment->type) {
         $response = wp_remote_head($attachment->url);
         if (200 == wp_remote_retrieve_response_code($response)) {
             $_mimes = array_flip(wp_get_mime_types());
             $_content_type = wp_remote_retrieve_header($response, 'content-type');
             if (isset($_mimes[$_content_type])) {
                 $_ext = strtok($_mimes[$_content_type], '|');
                 $_temp_file = download_url($attachment->url);
                 // TODO check for WP_Error
                 $_new_file = str_replace('.tmp', '.' . $_ext, $_temp_file);
                 rename($_temp_file, $_new_file);
                 $file_array = array();
                 $file_array['name'] = basename($_new_file);
                 $file_array['tmp_name'] = $_new_file;
                 $attachment_id = media_handle_sideload($file_array, $_to_post_id, '', array('post_date' => $date, 'post_date_gmt' => $date));
             }
         }
     }
 }
コード例 #27
0
ファイル: initialize.php プロジェクト: nautilus7/cosmos
function cosmos_enqueue_scripts()
{
    // Load jquery from Google CDN (protocol relative) with local fallback when not available
    if (false === ($url = get_transient('jquery_url'))) {
        // Check if Google CDN is working
        $url = (is_ssl() ? 'https:' : 'http:') . '//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
        // Load local jquery if Google down
        if (200 != wp_remote_retrieve_response_code(wp_remote_head($url))) {
            $url = get_template_directory_uri() . '/js/vendor/jquery-1.7.2.min.js';
        }
        // Cache the result for 5 minutes to save bandwidth
        set_transient('jquery_url', $url, 60 * 5);
    }
    // Deregister Wordpress' jquery and register theme's copy in the footer
    wp_deregister_script('jquery');
    wp_register_script('jquery', $url, array(), null, true);
    // Load other theme scripts here
    wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/vendor/modernizr-2.5.3.min.js', array(), null, false);
    wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/vendor/bootstrap.min.js', array('jquery'), null, true);
    wp_enqueue_script('main', get_template_directory_uri() . '/js/main.js', array('jquery'), null, true);
}
コード例 #28
0
function powerpress_admin_verify_url($url)
{
    $response = wp_remote_head($url, array('httpversion' => 1.1));
    for ($x = 0; $x < 5; $x++) {
        // Redirect 1-5
        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
            $headers = wp_remote_retrieve_headers($response);
            $response = wp_remote_head($headers['location'], array('httpversion' => 1.1));
        } else {
            break;
            // Either we had an error or the response code is no longer a redirect
        }
    }
    if (is_wp_error($response)) {
        return array('error' => $response->get_error_message());
    }
    if (isset($response['response']['code']) && ($response['response']['code'] < 200 || $response['response']['code'] > 203)) {
        return array('error' => 'Error, HTTP ' . $response['response']['code']);
    }
    return array('error' => false);
}
コード例 #29
0
 public function validate()
 {
     $response = wp_remote_head($this->url);
     // Might just be unavailable right now, so ignore.
     // It would be great to track this over time and create conflicts.
     if (is_wp_error($response)) {
         return;
     }
     $remote_etag = wp_remote_retrieve_header($response, 'etag');
     $remote_last_modified = wp_remote_retrieve_header($response, 'last-modified');
     if ($this->etag || $remote_etag) {
         if ($this->etag != $remote_etag) {
             $this->has_changed = true;
         }
     }
     if ($this->last_modified || $remote_last_modified) {
         if ($this->last_modified != $remote_last_modified) {
             $this->has_changed = true;
         }
     }
     // @fixme: what to do if both etag and last_modified are missing?
     // right now those cases never count as "changed"
 }
コード例 #30
0
function powerpress_admin_verify_url($url)
{
    $wp_remote_options = array();
    $wp_remote_options['user-agent'] = 'Blubrry PowerPress/' . POWERPRESS_VERSION;
    $wp_remote_options['httpversion'] = '1.1';
    $response = wp_remote_head($url, $wp_remote_options);
    for ($x = 0; $x < 5; $x++) {
        // Redirect 1-5
        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
            $headers = wp_remote_retrieve_headers($response);
            $response = wp_remote_head($headers['location'], $wp_remote_options);
        } else {
            break;
            // Either we had an error or the response code is no longer a redirect
        }
    }
    if (is_wp_error($response)) {
        return array('error' => $response->get_error_message());
    }
    if (isset($response['response']['code']) && ($response['response']['code'] < 200 || $response['response']['code'] > 203)) {
        return array('error' => 'Error, HTTP ' . $response['response']['code']);
    }
    return array('error' => false);
}