diff --git a/classes/DailyImageWidget.php b/classes/DailyImageWidget.php
index 5d18bdb..ce19f6d 100644
--- a/classes/DailyImageWidget.php
+++ b/classes/DailyImageWidget.php
@@ -16,7 +16,8 @@ class DailyImageWidget {
);
$this->_cache_time = 86400;
-
+ $this->_source_stamp = "&f=wpw";
+
$this->data_source = "http://hubblesite.org/gallery/album/daily_image.php";
$this->has_simplexml = class_exists('SimpleXMLElement');
@@ -29,22 +30,22 @@ class DailyImageWidget {
);
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;
- }
}
/**
* WordPress init hook.
*/
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"));
+ 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"));
+
+ if (!$skip_load_data) {
+ if (!$this->_load_data()) {
+ add_action("admin_notices", array(&$this, "_connection_warning"));
+ }
+ } else {
+ $this->data = false;
+ }
$this->handle_post();
$this->get_display_options();
@@ -147,13 +148,13 @@ class DailyImageWidget {
echo "HubbleSite Daily Image";
echo $after_title;
if (in_array("image", $options)) {
- echo '';
+ echo '';
echo '';
echo '';
}
if (in_array("title", $options)) {
- echo '';
+ echo '';
echo $this->_fix_widows($this->data['title']);
echo '';
}
@@ -192,46 +193,20 @@ class DailyImageWidget {
* @return array|boolean The retrieved data, or false on failure.
*/
function parse_xml($xml_text) {
- if ($this->has_simplexml) {
- try {
- $xml = new SimpleXMLElement($xml_text);
-
- if ($xml !== false) {
- $data = array();
- $is_valid = true;
- foreach ($this->_valid_column_names as $node) {
- if ($xml->{$node}) {
- $data[$node] = (string)$xml->{$node};
- } else {
- $is_valid = false; break;
- }
- }
-
- if ($is_valid) {
- $this->data = $data;
- } else {
- $this->data = false;
- }
- }
- } catch (Exception $e) {
- $this->data = false;
- }
- } else {
- $parser = xml_parser_create();
- $this->_character_data = "";
- $this->_xml_data = array();
- xml_set_element_handler(
- $parser,
- array($this, "_start_element_handler"),
- array($this, "_end_element_handler")
- );
- xml_set_character_data_handler($parser, array($this, "_character_data_handler"));
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- $this->data = false;
- if (xml_parse($parser, $xml_text)) {
- if (count($this->_xml_data) == count($this->_valid_column_names)) {
- $this->data = $this->_xml_data;
- }
+ $parser = xml_parser_create();
+ $this->_character_data = "";
+ $this->_xml_data = array();
+ xml_set_element_handler(
+ $parser,
+ array(&$this, "_start_element_handler"),
+ array(&$this, "_end_element_handler")
+ );
+ xml_set_character_data_handler($parser, array(&$this, "_character_data_handler"));
+ xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
+ $this->data = false;
+ if (xml_parse($parser, $xml_text)) {
+ if (count($this->_xml_data) == count($this->_valid_column_names)) {
+ $this->data = $this->_xml_data;
}
}
return $this->data;
diff --git a/test/DailyImageWidgetTest.php b/test/DailyImageWidgetTest.php
index bba3ed8..9897d32 100644
--- a/test/DailyImageWidgetTest.php
+++ b/test/DailyImageWidgetTest.php
@@ -60,14 +60,14 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
"image",
array(
'//div[@id="hubblesite-daily-image"]' => false,
- '//a[@href="gallery_url" and @title="title"]' => true,
+ '//a[@href="gallery_url&f=wpw" and @title="title"]' => true,
'//a/img[@src="image_url" and @alt="title"]' => true,
)
),
array(
"title",
array(
- '//a[@href="gallery_url" and @id="hubblesite-daily-image-title"]' => "title"
+ '//a[@href="gallery_url&f=wpw" and @id="hubblesite-daily-image-title"]' => "title"
)
),
array(