From 2395ce3472a25271bf86509b17dd95d6c2240649 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 2 Nov 2009 13:05:07 -0500 Subject: [PATCH] use wp http instead of rolling our own --- classes/DailyImageWidget.php | 23 ++++++++++++++--------- hubblesite-daily-image-wordpress.php | 2 +- readme.txt | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/classes/DailyImageWidget.php b/classes/DailyImageWidget.php index ce19f6d..4d1d416 100644 --- a/classes/DailyImageWidget.php +++ b/classes/DailyImageWidget.php @@ -36,7 +36,14 @@ class DailyImageWidget { * WordPress init hook. */ function _init() { - register_sidebar_widget(__("HubbleSite Daily Image", "hubblesite-daily-image-widget"), array(&$this, "render")); + wp_register_sidebar_widget( + 'hubblesite-daily-image', + __("HubbleSite Daily Image", "hubblesite-daily-image-widget"), + array(&$this, "render"), + array( + 'description' => __('Embed a daily HubbleSite Gallery image on your WordPress blog.', 'hubblesite-daily-image-widget') + ) + ); register_widget_control(__("HubbleSite Daily Image", "hubblesite-daily-image-widget"), array(&$this, "render_ui")); if (!$skip_load_data) { @@ -66,15 +73,13 @@ class DailyImageWidget { * @return string The data from the remote source. */ function _get_from_data_source() { - if (extension_loaded('curl')) { - $ch = curl_init($this->data_source); - curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); - $result = curl_exec($ch); - curl_close($ch); - return $result; - } else { - return @file_get_contents($this->data_source); + $response = wp_remote_request($this->data_source, array('method' => 'GET')); + if (!is_wp_error($response)) { + if (isset($response['body'])) { + return $response['body']; + } } + return false; } /** diff --git a/hubblesite-daily-image-wordpress.php b/hubblesite-daily-image-wordpress.php index 74a11d3..83b62f0 100644 --- a/hubblesite-daily-image-wordpress.php +++ b/hubblesite-daily-image-wordpress.php @@ -3,7 +3,7 @@ Plugin Name: HubbleSite Daily Image Widget Plugin URI: http://github.com/johnbintz/hubblesite-daily-image-wordpress/tree/master Description: The HubbleSite Daily Image Widget embeds a daily HubbleSite Gallery image on your WordPress blog. -Version: 0.1 +Version: 0.1.1 Author: John Bintz Author URI: http://hubblesite.org/ diff --git a/readme.txt b/readme.txt index e794baa..57a282c 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: stsci-opo, johncoswell Tags: widget, picture, image Requires at least: 2.7.1 -Tested up to: 2.8.2 -Stable tag: 0.1 +Tested up to: 2.8.4 +Stable tag: 0.1.1 The HubbleSite Daily Image Widget embeds a daily HubbleSite Gallery image on your WordPress blog.