diff --git a/README b/README
index 6744d5d..8ce7a55 100644
--- a/README
+++ b/README
@@ -1,21 +1,16 @@
The HubbleSite Daily Image Widget embeds a daily HubbleSite Gallery image on
your WordPress blog.
-Copyright (c) 2009 John Bintz
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in the
-Software without restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
-Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
diff --git a/classes/DailyImageWidget.php b/classes/DailyImageWidget.php
index aaa7fd7..7ccc78b 100644
--- a/classes/DailyImageWidget.php
+++ b/classes/DailyImageWidget.php
@@ -1,7 +1,7 @@
default_display_options = array(
'title',
'image',
@@ -11,23 +11,61 @@ class DailyImageWidget {
$this->_cache_time = 86400;
$this->data_source = "http://hubblesite.org/gallery/album/daily_image.php";
- $this->data = false;
$this->has_simplexml = class_exists('SimpleXMLElement');
$this->_valid_column_names = array('title', 'caption', 'date', 'image_url', 'gallery_url', 'credits');
$this->_valid_options = array(
- "image" => "Daily Image",
- "title" => "Image Title",
- "caption" => "Image Caption",
- "credits" => "Credits",
- "styles" => "HubbleSite Styles",
+ "image" => __("Daily Image", "hubblesite-daily-image-widget"),
+ "title" => __("Image Title", "hubblesite-daily-image-widget"),
+ "caption" => __("Image Caption", "hubblesite-daily-image-widget"),
+ "credits" => __("Credits", "hubblesite-daily-image-widget"),
+ "styles" => __("HubbleSite Styles", "hubblesite-daily-image-widget"),
);
- wp_register_sidebar_widget("hubblesite-daily-image", "HubbleSite Daily Image", array($this, "render"));
- register_widget_control("hubblesite-daily-image", array($this, "render_ui"));
+ add_action('init', array($this, "_init"));
+
+ if (!$skip_load_data) {
+ if (!$this->_load_data()) {
+ add_action("admin_notices", array($this, "_connection_warning"));
+ }
+ } else {
+ $this->data = false;
+ }
+
+ $this->display_options = $this->get_display_options();
}
+ function _init() {
+ register_sidebar_widget(__("HubbleSite Daily Image", "hubblesite-daily-image-widget"), array($this, "render"));
+ register_widget_control(__("HubbleSite Daily Image", "hubblesite-daily-image-widget"), array($this, "render_ui"));
+ }
+
+ function _connection_warning() {
+ echo "
";
+ _e("HubbleSite Daily Image Widget was unable to retrieve new data from HubbleSite.", "hubblesite-daily-image-widget");
+ _e("The widget will appear as empty in your site until data can be downloaded again.", "hubblesite-daily-image-widget");
+ echo "
";
+ }
+
+ function _get_from_data_source() {
+ return @file_get_contents($this->data_source);
+ }
+
+ function _load_data() {
+ if (($result = $this->_get_cached_data()) === false) {
+ if (($xml_text = $this->_get_from_data_source()) !== false) {
+ if (($result = $this->parse_xml($xml_text)) !== false) {
+ update_option('hubblesite-daily-image-cache', array(time(), $result));
+ return true;
+ }
+ }
+ return false;
+ } else {
+ return true;
+ }
+ }
+
/**
* Get the list of display options from the WordPress options database.
*/
@@ -42,6 +80,8 @@ class DailyImageWidget {
$this->display_options = $this->default_display_options;
}
+ update_option('hubblesite-daily-image-options', implode(",", $this->display_options));
+
return $this->display_options;
}
@@ -87,13 +127,16 @@ class DailyImageWidget {
}
function render_ui() {
- echo "
Show on Widget:
";
+ echo "
";
+ _e("Show on Widget:", "hubblesite-daily-image-widget");
+ echo "