/** * Short tag function * * @param mixed $url */ function wp_simple_rss_feed_reader($url, $limit = 50, $hide_description = 0, $hide_url = 0, $show_date = 0, $show_images = 0, $amount_of_words = 0) { if ($amount_of_words == 0) { $amount_of_words = 9999; } $content = SimplRssFetchFeed($url); try { $xml = new SimpleXmlElement($content); } catch (Exception $e) { /* the data provided is not valid XML */ return '<div style="background:#ffa1a1;color:#ff0000;padding:10px;">Unfortunaly, this xml/rss feed does not work correctly...</div>'; exit; } if (!is_object($xml)) { return 'Unfortunally the feed you provided is not valid...'; } $return = SimplRssParse($xml, $limit, $hide_description, $hide_url, $show_date, $show_images, $amount_of_words); return $return; }
/** @see WP_Widget::widget */ function widget($args, $instance) { //get arguments extract($args); //set title var $title = 'Simple Rss Widget'; //get title if (isset($instance['title'])) { $title = apply_filters('widget_title', $instance['title']); } //get limit $limit = 5; if (isset($instance['limit'])) { $limit = $instance['limit']; } //get amount of words per item to display $amount_of_words = 16; if (isset($instance['amount_of_words'])) { $amount_of_words = (int) ($instance['amount_of_words'] + 1); } //get hide_description $hide_description = 0; if (isset($instance['hide_description'])) { $hide_description = $instance['hide_description']; } //get hide_url $hide_url = 0; if (isset($instance['hide_url'])) { $hide_url = $instance['hide_url']; } //get show_date $show_date = 0; if (isset($instance['show_date'])) { $show_date = $instance['show_date']; } //get show_images $show_images = 1; if (isset($instance['show_images'])) { $show_images = $instance['show_images']; } //get url $url = ''; if (isset($instance['url'])) { $url = $instance['url']; } echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $i = 0; $content = SimplRssFetchFeed($url); try { $xml = new SimpleXmlElement($content); } catch (Exception $e) { /* the data provided is not valid XML */ return 'Unfortunally the feed you provided is not valid...'; exit; } if (!is_object($xml)) { echo 'Unfortunally the feed you provided is not valid...'; } else { $return = SimplRssParse($xml, $limit, $hide_description, $hide_url, $show_date, $show_images, $amount_of_words); echo $return; echo $after_widget; } }