internet stuff
This commit is contained in:
parent
5f4aec6b7a
commit
ef179118ed
|
@ -16,6 +16,7 @@ class DailyImageWidget {
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->_cache_time = 86400;
|
$this->_cache_time = 86400;
|
||||||
|
$this->_source_stamp = "&f=wpw";
|
||||||
|
|
||||||
$this->data_source = "http://hubblesite.org/gallery/album/daily_image.php";
|
$this->data_source = "http://hubblesite.org/gallery/album/daily_image.php";
|
||||||
|
|
||||||
|
@ -29,22 +30,22 @@ class DailyImageWidget {
|
||||||
);
|
);
|
||||||
|
|
||||||
add_action('init', array($this, "_init"));
|
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.
|
* WordPress init hook.
|
||||||
*/
|
*/
|
||||||
function _init() {
|
function _init() {
|
||||||
register_sidebar_widget(__("HubbleSite Daily Image", "hubblesite-daily-image-widget"), array($this, "render"));
|
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_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->handle_post();
|
||||||
$this->get_display_options();
|
$this->get_display_options();
|
||||||
|
@ -147,13 +148,13 @@ class DailyImageWidget {
|
||||||
echo "HubbleSite Daily Image";
|
echo "HubbleSite Daily Image";
|
||||||
echo $after_title;
|
echo $after_title;
|
||||||
if (in_array("image", $options)) {
|
if (in_array("image", $options)) {
|
||||||
echo '<a href="' . $this->data['gallery_url'] . '" title="' . $this->data['title'] . '">';
|
echo '<a href="' . $this->data['gallery_url'] . $this->_source_stamp . '" title="' . $this->data['title'] . '">';
|
||||||
echo '<img src="' . $this->data['image_url'] . '" alt="' . $this->data['title'] . '" width="100%" />';
|
echo '<img src="' . $this->data['image_url'] . '" alt="' . $this->data['title'] . '" width="100%" />';
|
||||||
echo '</a>';
|
echo '</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array("title", $options)) {
|
if (in_array("title", $options)) {
|
||||||
echo '<a id="hubblesite-daily-image-title" href="' . $this->data['gallery_url'] . '">';
|
echo '<a id="hubblesite-daily-image-title" href="' . $this->data['gallery_url'] . $this->_source_stamp . '">';
|
||||||
echo $this->_fix_widows($this->data['title']);
|
echo $this->_fix_widows($this->data['title']);
|
||||||
echo '</a>';
|
echo '</a>';
|
||||||
}
|
}
|
||||||
|
@ -192,46 +193,20 @@ class DailyImageWidget {
|
||||||
* @return array|boolean The retrieved data, or false on failure.
|
* @return array|boolean The retrieved data, or false on failure.
|
||||||
*/
|
*/
|
||||||
function parse_xml($xml_text) {
|
function parse_xml($xml_text) {
|
||||||
if ($this->has_simplexml) {
|
$parser = xml_parser_create();
|
||||||
try {
|
$this->_character_data = "";
|
||||||
$xml = new SimpleXMLElement($xml_text);
|
$this->_xml_data = array();
|
||||||
|
xml_set_element_handler(
|
||||||
if ($xml !== false) {
|
$parser,
|
||||||
$data = array();
|
array(&$this, "_start_element_handler"),
|
||||||
$is_valid = true;
|
array(&$this, "_end_element_handler")
|
||||||
foreach ($this->_valid_column_names as $node) {
|
);
|
||||||
if ($xml->{$node}) {
|
xml_set_character_data_handler($parser, array(&$this, "_character_data_handler"));
|
||||||
$data[$node] = (string)$xml->{$node};
|
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
|
||||||
} else {
|
$this->data = false;
|
||||||
$is_valid = false; break;
|
if (xml_parse($parser, $xml_text)) {
|
||||||
}
|
if (count($this->_xml_data) == count($this->_valid_column_names)) {
|
||||||
}
|
$this->data = $this->_xml_data;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->data;
|
return $this->data;
|
||||||
|
|
|
@ -60,14 +60,14 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
"image",
|
"image",
|
||||||
array(
|
array(
|
||||||
'//div[@id="hubblesite-daily-image"]' => false,
|
'//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,
|
'//a/img[@src="image_url" and @alt="title"]' => true,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
"title",
|
"title",
|
||||||
array(
|
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(
|
array(
|
||||||
|
|
Loading…
Reference in New Issue