Advertisement
Guest User

diff for RSSFeedChecker 0.8

a guest
Oct 15th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.43 KB | None | 0 0
  1. diff -wru a/RSSFeedChecker.php b/RSSFeedChecker.php
  2. --- a/RSSFeedChecker.php    2012-10-14 10:49:25.390625000 -0700
  3. +++ b/RSSFeedChecker.php    2012-10-14 16:29:50.734375000 -0700
  4. @@ -1,7 +1,7 @@
  5.  <?php
  6.  /*
  7.  Plugin Name: RSS Feed Checker
  8. -Plugin URI: #
  9. +Plugin URI: http://wordpress.org/extend/plugins/rssfeedchecker/
  10.  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
  11.  Version: 0.8
  12.  Author: Andy Clark.
  13. diff -wru a/RSSFeedCheckerDB.php b/RSSFeedCheckerDB.php
  14. --- a/RSSFeedCheckerDB.php  2012-10-14 10:49:25.390625000 -0700
  15. +++ b/RSSFeedCheckerDB.php  2012-10-14 11:16:36.171875000 -0700
  16. @@ -57,11 +57,41 @@
  17.              }
  18.          }
  19.      
  20. -        static function rss_list($count) {
  21. +        static function rss_list($instance) {
  22.          //Return an array? of upto $count links
  23.              global $wpdb;
  24. +
  25. +            $count = (int) $instance["count"];
  26. +            $limit = ($count > 0) ? "limit 0, $count" : "";
  27. +
  28. +            // Restrain results to a category
  29. +            $cat_join = "";
  30. +            $cat_sql = "";
  31. +            if($wpdb->get_var($wpdb->prepare(sprintf(
  32. +                "SELECT count(*) FROM $wpdb->terms term NATURAL JOIN $wpdb->term_taxonomy tax"
  33. +                . " WHERE tax.taxonomy = 'link_category'"
  34. +                . " AND term.name = '%s'", $wpdb->escape($instance['title'])
  35. +            )))){
  36. +                $cat_join = " JOIN $wpdb->term_relationships trel on l.link_id = trel.object_id "
  37. +                . " NATURAL JOIN $wpdb->term_taxonomy tax "
  38. +                . " NATURAL JOIN $wpdb->terms term "
  39. +                ;
  40. +                $cat_where = sprintf(" AND term.name = '%s'", $wpdb->escape($instance['title']));
  41. +            }
  42. +            
  43. +            
  44.              $tblrss = $wpdb->prefix . self::$tablename;
  45. -            $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");
  46. +                                    
  47. +            $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
  48. +            FROM $tblrss r
  49. +            right join $wpdb->links l on r.link_id = l.link_id
  50. +            $cat_join
  51. +            where  "
  52. +            // latest_item_url is not null and
  53. +            . " l.link_visible = 'Y' "
  54. +            . $cat_where
  55. +            . " order by abs(last_updated is null), last_updated desc $limit");
  56. +
  57.              return $links;          
  58.          }
  59.          
  60. diff -wru a/RSSFeedCheckerWidget.php b/RSSFeedCheckerWidget.php
  61. --- a/RSSFeedCheckerWidget.php  2012-10-14 10:49:25.390625000 -0700
  62. +++ b/RSSFeedCheckerWidget.php  2012-10-14 11:16:36.171875000 -0700
  63. @@ -18,10 +18,10 @@
  64.          
  65.          // [LinksRSSEnhanced count="number"]
  66.         static function RenderShortcode( $atts ) {
  67. -           extract( shortcode_atts( array(
  68. +          return self::renderlinks(shortcode_atts( array(
  69.                 'count' => 5,
  70. +              'title' => 'Blog Roll'
  71.             ), $atts ) );
  72. -       return self::renderlinks($count);
  73.          }
  74.  
  75.          
  76. @@ -35,8 +35,10 @@
  77.          }
  78.         }
  79.  
  80. +        public function get_field_list_id($field){ return $this->get_field_id($field) . "-list"; }
  81. +
  82.          public function form_input_text($field,$caption,$value) {
  83. -         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));
  84. +         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));
  85.          }
  86.          
  87.          public function form_input_option($field,$caption,$value,$options){
  88. @@ -68,24 +70,37 @@
  89.                  echo $before_title . $title . $after_title;
  90.              };
  91.  
  92. -            echo self::renderlinks($count);
  93. +            echo self::renderlinks($instance);
  94.          
  95.              echo $after_widget;    
  96.         }
  97.        
  98. -       function renderlinks($count){
  99. +       function renderlinks($instance){       
  100.              $htmlout = '<ul class="RSSFeedBlogRoll blogroll">';
  101. -            $links = RSSCheckerDB::rss_list($count);
  102. +            $links = RSSCheckerDB::rss_list($instance);
  103.              foreach ($links as $link){
  104. -                $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));
  105. +
  106. +                $image_html = "";
  107. +                if($link->link_image){
  108. +                    // TODO: see if there are standard classes for this
  109. +                    $image_html = sprintf('<img style="blogrollicon" src="%s">', esc_html($link->link_image));
  110. +                }
  111. +
  112. +                $latest_html = "";
  113. +                if($link->latest_item_url){
  114. +                    $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));
  115. +                }
  116. +
  117. +                $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);
  118. +
  119.              }
  120.              $htmlout = $htmlout . '</ul>';
  121.              
  122.              // display link to blog roll page if it exists
  123.              global $wpdb;
  124.              $blogrollid = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name='Blog-Roll'");
  125. +            if ($blogrollid) {
  126.              $link = get_permalink($blogrollid);
  127. -            if ($link != '') {
  128.                  $htmlout = $htmlout . sprintf('<p><a href="%s">%s</a></p>',$link,__('Show all links','RSS'));
  129.              }
  130.              return $htmlout;
  131. @@ -147,7 +162,7 @@
  132.          $instance['title'] = strip_tags($new_instance['title']);
  133.          $count = absint(strip_tags($new_instance['count']));
  134.          if ($count > 50) { $count = 50;}
  135. -        if ($count < 1) { $count = 1;}
  136. +        if ($count < 0) { $count = 0;} // allow 0 == unlimited
  137.          $instance['count'] = $count;
  138.              
  139.          return $instance;
  140. @@ -162,6 +177,13 @@
  141.          $this->form_input_text('title',__('Title','RSS'),$title);
  142.          $this->form_input_text('count',__('Maximum number of links to display (default = 5)','RSS'),$count);
  143.  
  144. +       global $wpdb;
  145. +       $datalist = sprintf('<datalist id="%s">', $this->get_field_list_id('title'));
  146. +       foreach($wpdb->get_col($wpdb->prepare("SELECT name FROM $wpdb->terms term NATURAL JOIN $wpdb->term_taxonomy tax WHERE taxonomy = 'link_category'")) as $opt){
  147. +           $datalist .= "\n\t<option>$opt</option>";
  148. +       }
  149. +       $datalist .= "\n</datalist>\n";
  150. +       print $datalist;
  151.          
  152.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement