Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -wru a/RSSFeedChecker.php b/RSSFeedChecker.php
- --- a/RSSFeedChecker.php 2012-10-14 10:49:25.390625000 -0700
- +++ b/RSSFeedChecker.php 2012-10-14 16:29:50.734375000 -0700
- @@ -1,7 +1,7 @@
- <?php
- /*
- Plugin Name: RSS Feed Checker
- -Plugin URI: #
- +Plugin URI: http://wordpress.org/extend/plugins/rssfeedchecker/
- Description: Checks your links RSS feeds and stores the date that it was last modified so that it can be used in a Links RSS Enhanced widget
- Version: 0.8
- Author: Andy Clark.
- diff -wru a/RSSFeedCheckerDB.php b/RSSFeedCheckerDB.php
- --- a/RSSFeedCheckerDB.php 2012-10-14 10:49:25.390625000 -0700
- +++ b/RSSFeedCheckerDB.php 2012-10-14 11:16:36.171875000 -0700
- @@ -57,11 +57,41 @@
- }
- }
- - static function rss_list($count) {
- + static function rss_list($instance) {
- //Return an array? of upto $count links
- global $wpdb;
- +
- + $count = (int) $instance["count"];
- + $limit = ($count > 0) ? "limit 0, $count" : "";
- +
- + // Restrain results to a category
- + $cat_join = "";
- + $cat_sql = "";
- + if($wpdb->get_var($wpdb->prepare(sprintf(
- + "SELECT count(*) FROM $wpdb->terms term NATURAL JOIN $wpdb->term_taxonomy tax"
- + . " WHERE tax.taxonomy = 'link_category'"
- + . " AND term.name = '%s'", $wpdb->escape($instance['title'])
- + )))){
- + $cat_join = " JOIN $wpdb->term_relationships trel on l.link_id = trel.object_id "
- + . " NATURAL JOIN $wpdb->term_taxonomy tax "
- + . " NATURAL JOIN $wpdb->terms term "
- + ;
- + $cat_where = sprintf(" AND term.name = '%s'", $wpdb->escape($instance['title']));
- + }
- +
- +
- $tblrss = $wpdb->prefix . self::$tablename;
- - $links=$wpdb->get_results("SELECT l.link_id,l.link_name,l.link_url,rss_address,latest_item_url,latest_item_title,last_updated FROM $tblrss r inner join $wpdb->links l on r.link_id = l.link_id where latest_item_url is not null and l.link_visible = 'Y' order by last_updated desc limit 0, $count");
- +
- + $links=$wpdb->get_results($sql = "SELECT l.link_id,l.link_name,l.link_url,l.link_image,rss_address,latest_item_url,latest_item_title,last_updated
- + FROM $tblrss r
- + right join $wpdb->links l on r.link_id = l.link_id
- + $cat_join
- + where "
- + // latest_item_url is not null and
- + . " l.link_visible = 'Y' "
- + . $cat_where
- + . " order by abs(last_updated is null), last_updated desc $limit");
- +
- return $links;
- }
- diff -wru a/RSSFeedCheckerWidget.php b/RSSFeedCheckerWidget.php
- --- a/RSSFeedCheckerWidget.php 2012-10-14 10:49:25.390625000 -0700
- +++ b/RSSFeedCheckerWidget.php 2012-10-14 11:16:36.171875000 -0700
- @@ -18,10 +18,10 @@
- // [LinksRSSEnhanced count="number"]
- static function RenderShortcode( $atts ) {
- - extract( shortcode_atts( array(
- + return self::renderlinks(shortcode_atts( array(
- 'count' => 5,
- + 'title' => 'Blog Roll'
- ), $atts ) );
- - return self::renderlinks($count);
- }
- @@ -35,8 +35,10 @@
- }
- }
- + public function get_field_list_id($field){ return $this->get_field_id($field) . "-list"; }
- +
- public function form_input_text($field,$caption,$value) {
- - printf ('<p><label for="%s">%s: <input class="widefat" id="%s" name="%s" type="text" value="%s" " /></label></p>',$this->get_field_id($field),esc_html($caption),$this->get_field_id($field),$this->get_field_name($field),esc_attr($value));
- + printf ('<p><label for="%s">%s: <input class="widefat" id="%s" name="%s" list="%s" type="text" value="%s" " /></label></p>',$this->get_field_id($field),esc_html($caption),$this->get_field_id($field),$this->get_field_name($field),$this->get_field_list_id($field), esc_attr($value));
- }
- public function form_input_option($field,$caption,$value,$options){
- @@ -68,24 +70,37 @@
- echo $before_title . $title . $after_title;
- };
- - echo self::renderlinks($count);
- + echo self::renderlinks($instance);
- echo $after_widget;
- }
- - function renderlinks($count){
- + function renderlinks($instance){
- $htmlout = '<ul class="RSSFeedBlogRoll blogroll">';
- - $links = RSSCheckerDB::rss_list($count);
- + $links = RSSCheckerDB::rss_list($instance);
- foreach ($links as $link){
- - $htmlout = $htmlout . sprintf('<li class="blogrollitem"><a href="%s" class="blogrollbloglink">%s</a><p style="margin-left:px;"><a href="%s" class="blogrollfeedlink">%s</a><br />%s</p></li>',esc_url($link->link_url),esc_html($link->link_name),esc_url($link->latest_item_url),esc_html($link->latest_item_title),self::pretty_date($link->last_updated));
- +
- + $image_html = "";
- + if($link->link_image){
- + // TODO: see if there are standard classes for this
- + $image_html = sprintf('<img style="blogrollicon" src="%s">', esc_html($link->link_image));
- + }
- +
- + $latest_html = "";
- + if($link->latest_item_url){
- + $latest_html = sprintf('<p style="margin-left:px;"><a href="%s" class="blogrollfeedlink">%s</a><br />%s</p>',esc_url($link->latest_item_url),esc_html($link->latest_item_title),self::pretty_date($link->last_updated));
- + }
- +
- + $htmlout = $htmlout . sprintf('<li class="blogrollitem"><a href="%s" class="blogrollbloglink">%s %s</a>%s</li>',esc_url($link->link_url),$image_html, esc_html($link->link_name),$latest_html);
- +
- }
- $htmlout = $htmlout . '</ul>';
- // display link to blog roll page if it exists
- global $wpdb;
- $blogrollid = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name='Blog-Roll'");
- + if ($blogrollid) {
- $link = get_permalink($blogrollid);
- - if ($link != '') {
- $htmlout = $htmlout . sprintf('<p><a href="%s">%s</a></p>',$link,__('Show all links','RSS'));
- }
- return $htmlout;
- @@ -147,7 +162,7 @@
- $instance['title'] = strip_tags($new_instance['title']);
- $count = absint(strip_tags($new_instance['count']));
- if ($count > 50) { $count = 50;}
- - if ($count < 1) { $count = 1;}
- + if ($count < 0) { $count = 0;} // allow 0 == unlimited
- $instance['count'] = $count;
- return $instance;
- @@ -162,6 +177,13 @@
- $this->form_input_text('title',__('Title','RSS'),$title);
- $this->form_input_text('count',__('Maximum number of links to display (default = 5)','RSS'),$count);
- + global $wpdb;
- + $datalist = sprintf('<datalist id="%s">', $this->get_field_list_id('title'));
- + foreach($wpdb->get_col($wpdb->prepare("SELECT name FROM $wpdb->terms term NATURAL JOIN $wpdb->term_taxonomy tax WHERE taxonomy = 'link_category'")) as $opt){
- + $datalist .= "\n\t<option>$opt</option>";
- + }
- + $datalist .= "\n</datalist>\n";
- + print $datalist;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement