diff --git a/classes/DailyImageWidget.php b/classes/DailyImageWidget.php index a4193db..f5fc529 100644 --- a/classes/DailyImageWidget.php +++ b/classes/DailyImageWidget.php @@ -1,6 +1,14 @@ default_display_options = array( 'title', @@ -31,6 +39,9 @@ class DailyImageWidget { } } + /** + * 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")); @@ -39,6 +50,9 @@ class DailyImageWidget { $this->get_display_options(); } + /** + * Display a warning if the connection failed. + */ function _connection_warning() { echo "
"; @@ -148,6 +179,9 @@ class DailyImageWidget { /** * Parse a string of XML from the HubbleSite Daily Gallery Image feed. + * This will try to use SimpleXML if vailable. If not, will fall back on Expat. + * @param string $xml_text The text to parse. + * @return array|boolean The retrieved data, or false on failure. */ function parse_xml($xml_text) { if ($this->has_simplexml) { @@ -195,10 +229,16 @@ class DailyImageWidget { return $this->data; } + /** + * Expat start element handler. + */ function _start_element_handler($parser, $name, $attributes) { $this->_character_data = ""; } + /** + * Expat end element handler. + */ function _end_element_handler($parser, $name) { $name = strtolower($name); if (in_array($name, $this->_valid_column_names)) { @@ -208,10 +248,17 @@ class DailyImageWidget { $this->_character_data = ""; } + /** + * Expat character data handler. + */ function _character_data_handler($parser, $data) { $this->_character_data .= $data; } + /** + * Retrieve the cached data from WP Options. + * @return array|boolean The cached data or false upon failure. + */ function _get_cached_data() { $result = get_option('hubblesite-daily-image-cache'); @@ -235,6 +282,11 @@ class DailyImageWidget { return false; } + /** + * Try to ensure that no words in a paragraph or link are widowed. + * @param string $text The text to process. + * @return string The processed text. + */ function _fix_widows($text) { return preg_replace("#([^\ ]+)\ ([^\ \>]+)($|
|)#", '\1 \2\3', $text); }