WordPress.org

Plugin Directory

Changeset 324961


Ignore:
Timestamp:
12/21/10 14:02:38 (3 years ago)
Author:
stefsoton
Message:

version 1.1

Location:
google-news-widget/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • google-news-widget/trunk/google-news-widget.php

    r222482 r324961  
    44 * Plugin URI: http://www.stefaniamarchisio.com/goggle-news-widget-shortcode-plugin/ 
    55 * Description: A customizable list of Google News given language/country, (searchkey(s) or topic) and the number of displayable news. It works as both widget and shortcode. 
    6  * Version: 1.0 
     6 * Version: 1.1 
    77 * Author: Stefania Marchisio 
    88 * Author URI: http://stefaniamarchisio.com/about/ 
     
    3838 */ 
    3939add_action( 'widgets_init', 'funct_gNews' ); 
     40/** 
     41 * Add hook to fetch_feed (change refresh feed to 30 mins) 
     42 * @since 1.1 
     43 */ 
     44add_filter( 'wp_feed_cache_transient_lifetime', create_function( '$a', 'return 1800;' )); 
    4045 
    4146/** 
     
    5863class WP_gNews extends WP_Widget { 
    5964 
    60     /** 
    61     * Widget setup. 
    62     */ 
    63     function WP_gNews() { 
    64         /* Widget settings. */ 
    65         $widget_ops = array( 'classname' => 'googlenews', 'description' => __('A customizable list of Google News given language/country, (searchkey(s) or topic) and the number of displayable news. It works as both widget and shortcode.', 'googlenews') ); 
    66  
    67         /* Widget control settings. */ 
    68         $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'google-news-widget' ); 
    69  
    70         /* Create the widget. */ 
    71         $this->WP_Widget( 'google-news-widget', __('Google News Widget', 'googlenews'), $widget_ops, $control_ops ); 
    72     } 
    73  
    74     /** 
    75     * How to display the widget on the screen. 
    76     */ 
    77     function widget( $args, $instance ) { 
    78         extract( $args ); 
    79  
    80         /* Our variables from the widget settings. */ 
    81         $title = apply_filters('widget_title', $instance['title'] ); 
    82         $location = $instance['location']; 
    83         $geo = $instance['geo']; 
    84         $name = $instance['name']; 
    85         $topic = $instance['topic']; 
    86         $num = $instance['number']; 
    87         $list = $instance['list']; 
    88         $target= $instance['target']; 
     65/** 
     66 * Widget setup. 
     67 */ 
     68function WP_gNews() { 
     69    /* Widget settings. */ 
     70    $widget_ops = array( 'classname' => 'googlenews', 'description' => __('A customizable list of Google News given language/country, (searchkey(s) or topic) and the number of displayable news. It works as both widget and shortcode.', 'googlenews') ); 
     71 
     72    /* Widget control settings. */ 
     73    $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'google-news-widget' ); 
     74 
     75    /* Create the widget. */ 
     76    $this->WP_Widget( 'google-news-widget', __('Google News Widget', 'googlenews'), $widget_ops, $control_ops ); 
     77} 
     78 
     79/** 
     80 * How to display the widget on the screen. 
     81 */ 
     82function widget( $args, $instance ) { 
     83    extract( $args ); 
     84 
     85    /* Our variables from the widget settings. */ 
     86    $title = apply_filters('widget_title', $instance['title'] ); 
     87    $location = $instance['location']; 
     88    $geo = $instance['geo']; 
     89    $name = $instance['name']; 
     90    $topic = $instance['topic']; 
     91    $num = $instance['number']; 
     92    $list = $instance['list']; 
     93    $target= $instance['target']; 
    8994    /* Boolean vars */ 
    90         $lkbtitle = isset( $instance['lkbtitle'] ) ? $instance['lkbtitle'] : false; 
    91         $pubdate = isset( $instance['pubdate'] ) ? $instance['pubdate'] : false; 
    92         $pubtime = isset( $instance['pubtime'] ) ? $instance['pubtime'] : false; 
    93         $pubauthor = isset( $instance['pubauthor'] ) ? $instance['pubauthor'] : false; 
    94         $excerpt = isset( $instance['excerpt'] ) ? $instance['excerpt'] : false; 
    95         $charex = $instance['charex']; 
     95    $lkbtitle = isset( $instance['lkbtitle'] ) ? $instance['lkbtitle'] : false; 
     96    $pubdate = isset( $instance['pubdate'] ) ? $instance['pubdate'] : false; 
     97    $pubtime = isset( $instance['pubtime'] ) ? $instance['pubtime'] : false; 
     98    $pubauthor = isset( $instance['pubauthor'] ) ? $instance['pubauthor'] : false; 
     99    $excerpt = isset( $instance['excerpt'] ) ? $instance['excerpt'] : false; 
     100    $charex = $instance['charex']; 
    96101 
    97102    /* Before widget (defined by themes). */ 
    98         echo $before_widget; 
    99  
    100         /* Define the feed according to params entered */ 
    101         $feed = "http://news.google.com/news?cf=all&ned=" . $location. "&output=rss"; 
    102                 if ( $geo ) { $feed .= "&geo=$geo"; } 
    103         if ( $name ) { $feed .= "&q=$name"; } 
    104         if ( $topic ) { $feed .= "&topic=$topic"; } 
    105  
    106         $tle = ''; 
    107               /* Display the widget title if one was input (before and after defined by themes). */ 
    108         if ( $title ) { 
    109                   if ( $lkbtitle ) $tle = "<a target='" . $target . "' href='$feed' title='$title'><img src='/wp-content/plugins/google-news-widget/rss-cube.gif' width='25px' height='25px' title=' [feed link] '></a> "; 
    110                   echo $before_title . $tle . $title . $after_title; 
    111               } 
    112  
    113     echo gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex); 
    114  
    115         /* After widget (defined by themes). */ 
    116         echo $after_widget; 
    117     } 
    118  
    119     /** 
    120      * Update the widget settings. 
    121      */ 
    122     function update( $new_instance, $old_instance ) { 
    123         $instance = $old_instance; 
    124  
    125         /* Strip tags for title and name to remove HTML (important for text inputs). */ 
    126         $instance['title'] = strip_tags($new_instance['title']); 
    127         $instance['geo'] = strip_tags($new_instance['geo']); 
    128         $instance['name'] = strip_tags($new_instance['name']); 
    129         $instance['number'] = strip_tags($new_instance['number']); 
    130         $instance['charex'] = strip_tags($new_instance['charex']); 
    131  
    132         /* No need to strip tags for location (from drop-down menu) */ 
    133         $instance['location'] = $new_instance['location']; 
    134         $instance['topic'] = $new_instance['topic']; 
    135         $instance['target'] = $new_instance['target']; 
    136         $instance['list'] = $new_instance['list']; 
    137  
    138         /* No need to strip tags for boolean */ 
    139         $instance['lkbtitle'] = $new_instance['lkbtitle']; 
    140         $instance['pubdate'] = $new_instance['pubdate']; 
    141         $instance['pubtime'] = $new_instance['pubtime']; 
    142         $instance['pubauthor'] = $new_instance['pubauthor']; 
    143         $instance['excerpt'] = $new_instance['excerpt']; 
    144  
    145     return $instance; 
    146  
    147     } 
    148  
    149     /** 
    150     * Displays the widget settings controls on the widget panel. 
    151     * Make use of the get_field_id() and get_field_name() function 
    152      * when creating your form elements. This handles the confusing stuff. 
    153     */ 
    154     function form( $instance ) { 
    155  
    156         /* Default widget settings. */ 
    157         $defaults = array( 'title' => __('The Latest Google News', 'googlenews'), 'name' => __('sport', 'googlenews'), 'lkbtitle' => 'off', 'location' => 'us', 'geo' => '', 'topic' => '', 'number' => '10', 'pubdate' => 'off', 'pubtime' => 'off', 'pubauthor' => 'on', 'excerpt' => 'off', 'charex' => '', 'list' => 'UL', 'target' => '_blank'); 
    158  
    159         $instance = wp_parse_args( (array) $instance, $defaults );  
     103    echo $before_widget; 
     104 
     105    /* Define the feed according to params entered */ 
     106    $feed = "http://news.google.com/news?cf=all&ned=" . $location . "&output=rss"; 
     107        if ( $geo ) { $feed .= "&geo=$geo"; } 
     108    if ( $name ) { $feed .= "&q=$name"; } 
     109    if ( $topic ) { $feed .= "&topic=$topic"; } 
     110 
     111    $tle = ''; 
     112    /* Display the widget title if one was input (before and after defined by themes). */ 
     113    if ( $title ) { 
     114            if ( $lkbtitle ) $tle = "<a target='" . $target . "' href='" . $feed . "' title='$title'><img src='/wp-content/plugins/google-news-widget/rss-cube.gif' width='25px' height='25px' title=' [feed link] '/></a> "; 
     115            echo $before_title . $tle . $title . $after_title; 
     116        } 
     117 
     118    /* Call the function to read the feed content */ 
     119        echo gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex); 
     120 
     121    /* After widget (defined by themes). */ 
     122    echo $after_widget; 
     123} 
     124 
     125/** 
     126 * Update the widget settings. 
     127 */ 
     128function update( $new_instance, $old_instance ) { 
     129    $instance = $old_instance; 
     130 
     131    /* Strip tags for title and name to remove HTML (important for text inputs). */ 
     132    $instance['title'] = strip_tags($new_instance['title']); 
     133    $instance['geo'] = strip_tags($new_instance['geo']); 
     134    $instance['name'] = strip_tags($new_instance['name']); 
     135    $instance['number'] = strip_tags($new_instance['number']); 
     136    $instance['charex'] = strip_tags($new_instance['charex']); 
     137 
     138    /* No need to strip tags for drop-down menus */ 
     139    $instance['location'] = $new_instance['location']; 
     140    $instance['topic'] = $new_instance['topic']; 
     141    $instance['target'] = $new_instance['target']; 
     142    $instance['list'] = $new_instance['list']; 
     143 
     144    /* No need to strip tags for boolean */ 
     145    $instance['lkbtitle'] = $new_instance['lkbtitle']; 
     146    $instance['pubdate'] = $new_instance['pubdate']; 
     147    $instance['pubtime'] = $new_instance['pubtime']; 
     148    $instance['pubauthor'] = $new_instance['pubauthor']; 
     149    $instance['excerpt'] = $new_instance['excerpt']; 
     150 
     151return $instance; 
     152} 
     153 
     154/** 
     155 * Displays the widget settings controls on the widget panel. 
     156 * Make use of the get_field_id() and get_field_name() function 
     157 * when creating your form elements. This handles the confusing stuff.   
     158 */ 
     159function form( $instance ) { 
     160 
     161    /* Default widget settings. */ 
     162    $defaults = array( 'title' => __('The Latest Google News', 'googlenews'), 'name' => __('sport', 'googlenews'), 'lkbtitle' => 'off', 'location' => 'us', 'geo' => '', 'topic' => '', 'number' => '10', 'pubdate' => 'off', 'pubtime' => 'off', 'pubauthor' => 'on', 'excerpt' => 'off', 'charex' => '', 'list' => 'ul', 'target' => '_blank'); 
     163 
     164    $instance = wp_parse_args( (array) $instance, $defaults );  
    160165?> 
    161         <!-- Widget Title: Text Input --> 
    162         <p> 
    163             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Widget Title:', 'googlenews'); ?></label> 
    164             <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" /> 
    165         </p> 
     166    <!-- Widget Title: Text Input --> 
     167    <p> 
     168    <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Widget Title:', 'googlenews'); ?></label> 
     169    <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" /> 
     170    </p> 
    166171 
    167172    <!-- Link Title to Feed? Checkbox --> 
    168173    <p> 
    169         <label for="<?php echo $this->get_field_id( 'lkbtitle' ); ?>"><?php _e('Link Widget Title to Feed URL?', 'googlenews'); ?></label> 
    170         <input class="checkbox" type="checkbox" <?php checked( $instance['lkbtitle'], 'on' ); ?> id="<?php echo $this->get_field_id( 'lkbtitle' ); ?>" name="<?php echo $this->get_field_name( 'lkbtitle' ); ?>" />  
    171     </p> 
    172  
    173         <!-- Search Keyword(s): Text Input --> 
    174         <p> 
    175             <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e('Search keyword(s):', 'googlenews'); ?></label> 
    176             <input id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" value="<?php echo $instance['name']; ?>" style="width:100%;" /> 
    177         </p> 
    178     <p align="center">=== OR ===</p> 
    179         <!-- Topic: Select Box --> 
    180         <p> 
    181         <label for="<?php echo $this->get_field_id( 'topic' ); ?>"><?php _e('Topic:', 'googlenews'); ?></label>  
    182         <select id="<?php echo $this->get_field_id( 'topic' ); ?>" name="<?php echo $this->get_field_name( 'topic' ); ?>" class="widefat" style="width:100%;"> 
     174    <label for="<?php echo $this->get_field_id( 'lkbtitle' ); ?>"><?php _e('Link Widget Title to Feed URL?', 'googlenews'); ?></label> 
     175    <input class="checkbox" type="checkbox" <?php checked( $instance['lkbtitle'], 'on' ); ?> id="<?php echo $this->get_field_id( 'lkbtitle' ); ?>" name="<?php echo $this->get_field_name( 'lkbtitle' ); ?>" />  
     176    </p> 
     177 
     178    <fieldset> 
     179    <legend> Keyword(s) OR Topic </legend> 
     180    <!-- Search Keyword(s): Text Input --> 
     181    <p> 
     182    <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e('Search keyword(s):', 'googlenews'); ?></label> 
     183    <input id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" value="<?php echo $instance['name']; ?>" style="width:100%;" /> 
     184    </p> 
     185    <p align="center">=== OR ===</p> 
     186 
     187    <!-- Topic: Select Box --> 
     188    <p> 
     189    <label for="<?php echo $this->get_field_id( 'topic' ); ?>"><?php _e('Topic:', 'googlenews'); ?></label>  
     190    <select id="<?php echo $this->get_field_id( 'topic' ); ?>" name="<?php echo $this->get_field_name( 'topic' ); ?>" class="widefat" style="width:100%;"> 
    183191// options in Google News on 20 Feb 2010 
    184192<option value="" <?php if ('' == $instance['topic']) echo 'selected';?>>Top Stories (default)</option> 
     
    192200<option value="ir" <?php if ('ir' == $instance['topic']) echo 'selected';?>>Spotlight</option> 
    193201<option value="po" <?php if ('po' == $instance['topic']) echo 'selected';?>>Most Popular</option> 
    194         </select> 
    195         </p> 
    196  
    197         <!-- Location: Select Box --> 
    198         <p> 
    199         <label for="<?php echo $this->get_field_id( 'location' ); ?>"><?php _e('Location:', 'googlenews'); ?></label>  
    200         <select id="<?php echo $this->get_field_id( 'location' ); ?>" name="<?php echo $this->get_field_name( 'location' ); ?>" class="widefat" style="width:100%;"> 
    201  
     202    </select> 
     203    </p> 
     204    </fieldset> 
     205    <!-- Location: Select Box --> 
     206    <p> 
     207    <label for="<?php echo $this->get_field_id( 'location' ); ?>"><?php _e('Location:', 'googlenews'); ?></label>  
     208    <select id="<?php echo $this->get_field_id( 'location' ); ?>" name="<?php echo $this->get_field_name( 'location' ); ?>" class="widefat" style="width:100%;"> 
    202209// Locations in news.google.com on 4 Mar 10 
    203210<option value="es_ar" <?php if ("es_ar" == $instance['location']) echo 'selected';?>>Argentina</option>  
     
    272279<option value="hk" <?php if ("hk" == $instance['location']) echo 'selected';?>>香港版 (Hong Kong)</option> 
    273280// End Locations in news.google.com on 4 Mar 10 
    274  
    275         </select> 
    276         </p> 
    277  
    278         <!-- Widget Title: Text Input --> 
    279         <p> 
    280         <label for="<?php echo $this->get_field_id( 'geo' ); ?>"><?php _e('Local:', 'googlenews'); ?></label> 
    281         <input id="<?php echo $this->get_field_id( 'geo' ); ?>" name="<?php echo $this->get_field_name( 'geo' ); ?>" value="<?php echo $instance['geo']; ?>" style="width:100%;" /> 
    282         </p> 
    283  
    284         <!-- N. articles to display: Text Input --> 
    285         <p> 
    286             <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e('Num. of News:', 'googlenews'); ?></label> 
    287             <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" value="<?php echo $instance['number']; ?>" style="width:20%;" /> 
    288         </p> 
    289  
    290         <!-- Show Publication Date? Checkbox --> 
    291         <p> 
    292         <label for="<?php echo $this->get_field_id( 'pubdate' ); ?>"><?php _e('Show publication date?', 'googlenews'); ?></label> 
    293         <input class="checkbox" type="checkbox" <?php checked( $instance['pubdate'], 'on' ); ?> id="<?php echo $this->get_field_id( 'pubdate' ); ?>" name="<?php echo $this->get_field_name( 'pubdate' ); ?>" />  
    294         </p> 
    295  
    296         <!-- Show Publication Time? Checkbox --> 
    297         <p> 
    298         <label for="<?php echo $this->get_field_id( 'pubtime' ); ?>"><?php _e('Show publication time?', 'googlenews'); ?></label> 
    299         <input class="checkbox" type="checkbox" <?php checked( $instance['pubtime'], 'on' ); ?> id="<?php echo $this->get_field_id( 'pubtime' ); ?>" name="<?php echo $this->get_field_name( 'pubtime' ); ?>" />  
    300         </p> 
     281    </select> 
     282    </p> 
     283 
     284    <!-- Widget Title: Text Input --> 
     285    <p> 
     286    <label for="<?php echo $this->get_field_id( 'geo' ); ?>"><?php _e('Local:', 'googlenews'); ?></label> 
     287    <input id="<?php echo $this->get_field_id( 'geo' ); ?>" name="<?php echo $this->get_field_name( 'geo' ); ?>" value="<?php echo $instance['geo']; ?>" style="width:100%;" /> 
     288    </p> 
     289 
     290    <!-- N. articles to display: Text Input --> 
     291    <p> 
     292    <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e('Num. of News:', 'googlenews'); ?></label> 
     293    <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" value="<?php echo $instance['number']; ?>" style="width:20%;" /> 
     294    </p> 
     295 
     296    <!-- Show Publication Date? Checkbox --> 
     297    <p> 
     298    <label for="<?php echo $this->get_field_id( 'pubdate' ); ?>"><?php _e('Show publication date?', 'googlenews'); ?></label> 
     299    <input class="checkbox" type="checkbox" <?php checked( $instance['pubdate'], 'on' ); ?> id="<?php echo $this->get_field_id( 'pubdate' ); ?>" name="<?php echo $this->get_field_name( 'pubdate' ); ?>" />  
     300    </p> 
     301 
     302    <!-- Show Publication Time? Checkbox --> 
     303    <p> 
     304    <label for="<?php echo $this->get_field_id( 'pubtime' ); ?>"><?php _e('Show publication time?', 'googlenews'); ?></label> 
     305    <input class="checkbox" type="checkbox" <?php checked( $instance['pubtime'], 'on' ); ?> id="<?php echo $this->get_field_id( 'pubtime' ); ?>" name="<?php echo $this->get_field_name( 'pubtime' ); ?>" />  
     306    </p> 
    301307 
    302308    <!-- Show Excerpt? Checkbox --> 
     
    304310    <label for="<?php echo $this->get_field_id( 'excerpt' ); ?>"><?php _e('Show excerpt?', 'googlenews'); ?></label> 
    305311    <input class="checkbox" type="checkbox" <?php checked( $instance['excerpt'], 'on' ); ?> id="<?php echo $this->get_field_id( 'excerpt' ); ?>" name="<?php echo $this->get_field_name( 'excerpt' ); ?>" /> 
    306  <label for="<?php echo $this->get_field_id( 'charex' ); ?>"><?php _e(' and limit it to ', 'googlenews'); ?></label> 
     312    <label for="<?php echo $this->get_field_id( 'charex' ); ?>"><?php _e(' and limit it to ', 'googlenews'); ?></label> 
    307313    <input id="<?php echo $this->get_field_id( 'charex' ); ?>" name="<?php echo $this->get_field_name( 'charex' ); ?>" value="<?php echo $instance['charex']; ?>" style="width:10%;" /> chars. 
    308     <span style="font-size: 0.8em;">(Warning: Google's excerpt contains images & formatting: not suitable for narrow sidebars)</span> 
     314    <br /><span style="font-size: 0.8em;">(Warning: Google's excerpt contains images & formatting: not suitable for narrow sidebars)</span> 
    309315         </p> 
    310316 
     
    313319    <label for="<?php echo $this->get_field_id( 'list' ); ?>"><?php _e('List Type:', 'googlenews'); ?></label>  
    314320    <select id="<?php echo $this->get_field_id( 'list' ); ?>" name="<?php echo $this->get_field_name( 'list' ); ?>" class="widefat" style="width:100%;"> 
    315 <option value="UL" <?php if ('UL' == $instance['list']) echo 'selected';?>>Unordered (or Dotted) List (default)</option> 
    316 <option value="OL" <?php if ('OL' == $instance['list']) echo 'selected';?>>Ordered (or Numbered) List</option> 
     321    <option value="ul" <?php if ('ul' == $instance['list']) echo 'selected';?>>Unordered (or Dotted) List (default)</option> 
     322    <option value="ol" <?php if ('ol' == $instance['list']) echo 'selected';?>>Ordered (or Numbered) List</option> 
    317323    </select> 
    318324    </p> 
     
    322328    <label for="<?php echo $this->get_field_id( 'target' ); ?>"><?php _e('Target:', 'googlenews'); ?></label>  
    323329    <select id="<?php echo $this->get_field_id( 'target' ); ?>" name="<?php echo $this->get_field_name( 'target' ); ?>" class="widefat" style="width:100%;"> 
    324 <option value="_blank" <?php if ('_blank' == $instance['target']) echo 'selected';?>>Open link in a new window (default)</option> 
    325 <option value="_self" <?php if ('_self' == $instance['target']) echo 'selected';?>>Open link in the same window</option> 
     330    <option value="_blank" <?php if ('_blank' == $instance['target']) echo 'selected';?>>Open link in a new window (default)</option> 
     331    <option value="_self" <?php if ('_self' == $instance['target']) echo 'selected';?>>Open link in the same window</option> 
    326332    </select> 
    327333    </p> 
     
    333339    <br /><span style="font-size: 0.9em;">(please, say yes)</span> 
    334340    </p> 
    335  
    336341<?php 
    337342    } 
     
    357362     "local" => '', 
    358363     "num" => '3', 
    359      "list" => 'UL', 
     364     "list" => 'ul', 
    360365     "target" => '_blank', 
    361366     "pubdate" => false, 
     
    369374 
    370375     /* Display name from widget settings if one was input. */ 
    371      $feed = "http://news.google.com/news?cf=all&ned=" . $location. "&output=rss"; 
     376     $feed = "http://news.google.com/news?cf=all&ned=" . $location . "&output=rss"; 
    372377     if ( $local) { $feed .= "&geo=$local"; } 
    373378     if ( $search ) { $feed .= "&q=$search"; } 
     
    375380     $tle = ""; 
    376381     if ( $link || $title ) {  
    377         if ( $link ) $tle = "<a href='$feed'><img src='/wp-content/plugins/google-news-widget/rss-cube.gif' width='25px' height='25px' alt=' [feed link] '></a> ";  
     382        if ( $link ) $tle = "<a target='" . $target . "' href='" . $feed . "'><img src='/wp-content/plugins/google-news-widget/rss-cube.gif' width='25px' height='25px' alt=' [feed link] '/></a> ";  
    378383        $tle .= $title;  
    379384     } 
     
    381386} 
    382387 
     388/* 
     389From URL: http://www.rssboard.org/rss-2-0-1#hrelementsOfLtitemgt 
     390(The latest specification of an RSS feed (2.0.1). Backcompatible with versions 2.0, 0.92, 0.91) 
     391A channel may contain any number of <item>s. An item may represent a "story" -- much like a story in a newspaper or magazine; if so its description is a synopsis of the story, and the link points to the full story. An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed), and the link and title may be omitted. All elements of an item are optional, however at least one of title or description must be present.  
     392*/ 
     393 
    383394function gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex) { 
     395    include_once(ABSPATH . WPINC . '/feed.php'); 
     396 
    384397    // decoding needed when you use a shortcode as URLs are encoded by the shortcode 
    385398    $feed = html_entity_decode($feed);   
    386         $flist = "Error message: "; 
     399    $flist = "Error message: "; 
    387400 
    388401    // check whether a feed URL has been entered 
    389402    if ($feed) { 
    390         // debug string 
    391               // echo "<a href='$feed'>$feed</a>"; 
    392                 libxml_use_internal_errors(true); 
    393         if ( $rss = simplexml_load_file($feed) ) {  
    394             // check whether it is an RSS format feed 
    395                 if (array_key_exists('item', $rss->channel)) { 
    396                 // $flist = "We have an RSS feed: make a list our of this: "; 
    397  
    398                 $flist = "<$list>\n"; 
    399                 $i = 0; 
    400                 foreach ($rss->channel->item as $item ) { 
    401                     $flist .= "<li>"; 
    402                                    if ($item->title || $item->description) { 
    403  
    404                     if ( $item->link ) { 
    405                        $motext = isset( $item->description ) ? strip_tags(str_replace("><","> <",$item->description)): strip_tags($item->title); 
    406                        $flist .= "<a target='". $target . "' href='$item->link' title='$motext'>"; 
     403 
     404        $rss = ""; 
     405    if ( $rss = fetch_feed($feed) ) {  
     406 
     407    if (!is_wp_error( $rss )) { 
     408        // Checks that the object is created correctly  
     409            // Figure out how many total items there are, but limit it to 5.  
     410            $numitems = $rss->get_item_quantity($num);  
     411 
     412            // Build an array of all the items, starting with element 0 (first element). 
     413            $rss_items = $rss->get_items(0, $numitems);  
     414 
     415        // check whether it is an RSS format feed 
     416        // if (array_key_exists('item', $rss->channel)) { 
     417        // $flist = "We have an RSS feed: make a list our of this: "; 
     418 
     419        $flist = "<$list>\n"; 
     420        foreach ( $rss_items as $item ) { 
     421            $flist .= "<li>"; 
     422            $title = $item->get_title(); 
     423            $desc = $item->get_description(); 
     424            $permalink = $item->get_permalink(); 
     425            if ( $title || $desc ) { 
     426                if ( $permalink ) { 
     427                   $motext = isset( $desc ) ? strip_tags(str_replace("><","> <",$desc)): strip_tags($title); 
     428                   $flist .= "<a target='". $target . "' href='".$permalink."' title='$motext'>"; 
     429                } 
     430                $flist .= isset( $title ) ? $title : $desc; 
     431                if ( $permalink )   $flist .= "</a>";  
     432         
     433                if ( $item->get_date() && $pubdate !== false && $pubdate !== "false" ) 
     434                    $flist .= ' - ' . date ( 'd M y', strtotime( $item->get_date() )); 
     435 
     436                    if ( $item->get_date() && $pubtime !== false && $pubtime !== "false") 
     437                    $flist .= ' at ' . date ( 'H:i', strtotime( $item->get_date() ));  
     438 
     439                if ( $desc && $excerpt != false && $excerpt != "false") { 
     440                    if ( $charex > '0' ) {  
     441                        $flist .= '<br/>'. substr($item->description, 0, $charex); 
     442                        $flist .= ' <a target="' . $target . '" href="' . esc_url( $item->get_description() ) . '">[...]</a>'; 
     443                    } else { 
     444                        $flist .= '<br/>'. $item->get_description(); 
    407445                    } 
    408  
    409                     $flist .= isset( $item->title ) ? $item->title : $item->description; 
    410  
    411                     if ( $item->link ) 
    412                         $flist .= "</a>";  
    413          
    414                     if ( $item->pubDate && $pubdate !== false && $pubdate !== "false" ) 
    415                         $flist .= ' - ' . date ( 'd M y', strtotime( $item->pubDate )); 
    416  
    417                           if ( $item->pubDate && $pubtime !== false && $pubtime !== "false") 
    418                         $fList .= ' at ' . date ( 'H:i', strtotime( $item->pubDate ));  
    419  
    420                     if ( $item->description && $excerpt != false && $excerpt != "false") { 
    421                         if ( $charex > '0' ) {  
    422                             $flist .= '<br/>'. substr($item->description, 0, $charex); 
    423                             $flist .= ' <a target="' . $target . '" href="' . esc_url( $item->link ) . '">[...]</a>'; 
    424                         } else { 
    425                             $flist .= '<br/>'. $item->description; 
    426                         } 
    427                     }  
    428                      
    429                     } else { 
    430                         $flist .= "No standard <item> in file"; 
    431                     } 
    432                     $flist .= "</li>"; 
    433                     $i++; 
    434                     if ($i >= $num) break; 
    435                 } // foreach 
    436                 $flist .= "</".$list.">\n"; 
    437  
    438             // otherwise check whether it is an Atom format feed 
     446                } 
    439447            } else { 
    440                $flist .= "No typical RSS feed by Google or they have changed their feed format after the relase of this plugin. Please let me know about this."; 
     448                $flist .= urlencode("<li>No standard <item> in file."); 
    441449            } 
    442         } else { 
    443             $flist .= "<i>" . $feed . "</i> not found or is no standard XML file.";  
    444         } 
     450            $flist .= "</li>"; 
     451        } // foreach 
     452        $flist .= "</".$list.">\n"; 
    445453    } else { 
    446         $flist .= "Feed URL not provided. I do need an URL to a RSS or Atom XML file. Please, enter one.";  
    447     } 
    448     // if pubauthor has been selected 
     454        $flist .= "Atypical RSS/Atom feed or not supported by this plugin."; 
     455    } // if (!is_wp_error( $rss )) 
     456 
     457    } else { 
     458        $flist .= "<i>" . $feed . "</i> not found or no standard XML file.";  
     459    } // if ($rss = fetch_feed($feed)) 
     460     
     461    } else { 
     462        $flist .= "Feed URL not provided. This plugin does need an URL to a RSS or Atom XML file. Please, enter one.";  
     463    } // if ($feed) 
     464 
     465    // if pubauthor has been selected 
    449466    if ($pubauthor !== false && $pubauthor !== "false") { 
    450         $flist .= '<p style="text-align:center; font-size: 0.8em">powered by <a target="_blank" href="http://www.stefaniamarchisio.com/portfolio/">Google News Wizard/Shortcode</a></p>'; 
     467        $flist .= '<p style="text-align:center; font-size: 0.8em">powered by <a target="_blank" href="http://www.stefaniamarchisio.com/portfolio/">Google News Widget/Shortcode plugin</a></p>'; 
    451468    } 
    452469    return $flist; 
  • google-news-widget/trunk/readme.txt

    r222482 r324961  
    44Tags: RSS, Atom, feed, XML, syndication, syndicate, syndicating, Google News, Googlenews, news, widget, shortcode 
    55Requires at least: 2.8 
    6 Tested up to: 2.9.2 
    7 Stable tag: 1.0 
     6Tested up to: 3.0.3 
     7Stable tag: 1.1 
    88 
    99A customizable list of Google News given language-country, searchkey(s) or topic, number of news and whether you want publication date, time.  
     
    4343== Changelog == 
    4444 
     45= 1.1 =  
     46 
     47* New feature: forced feed cache to refresh every 30 minutes instead of the default 12 hours 
     48* New feature: made it (hopefully) compatible with XHTML1.0 by writing all tags and attributed in small letters 
     49* Changed feature: fetch_feed function is called to catch the feed instead of simplexml_load_file. Some users were unable to use this last PHP 5 function on their own webserver. (http://php.net/manual/en/function.simplexml-load-file.php) 
     50 
     51* Fixed bug: incorrect links to feed URLs in shortcodes were generated 
     52 
    4553= 1.0 =  
    4654 
    47 * New feature: Made linkable/not shortcode title 
    48 * Change feature: Added a feed small icon linking to its feed URL (instead of linking the title directly) 
    49 * Improvement: HTML tags are now stripped from the description to make the mouseover experience more meaningful  
     55* New feature: Made titles linkable for shortcodes too 
     56* Change feature: Added a feed small icon linking to its feed URL (instead of linking to the title directly) 
     57* HTML tags are now stripped from the description to make the mouseover experience more meaningful  
    5058* Fixed a bug which prevented the title to be linkable 
    5159 
     
    100108== Upgrade Notice == 
    101109 
     110= 1.1 =  
     111 
    102112= 1.0 = 
    103 * New feature: Made linkable/not shortcode title 
    104 * Change feature: Added a feed small icon linking to its feed URL (instead of linking the title directly) 
    105 * Improvement: HTML tags are now stripped from the description to make the mouseover experience more meaningful  
    106  
    107 = 0.9 = 
    108 * Non-standard chars are properly displayed  
    109113 
    110114= 0.9 = 
     
    112116 
    113117= 0.8 = 
    114 * Never released. Used internally for tests. 
     118 * Never released. Used internally for tests. 
    115119 
    116120= 0.7 = 
     
    141145As a widget: 
    142146 
    143 * Drag & Drop your widget in the widget-ready area; 
    144 * Choose a title to be given to this news list (optional); 
     147* Drag & Drop your widget in the widget-ready area of your choice; 
     148* Choose a title to be given to your news list (optional); 
     149* Tick off the box if you want your title to be linked to the correspondent feed URL (optional); 
    145150* Localize your news (language/country) (mandatory, default: us); 
    146 * If you live in Usa or Canada (eng only), choose a city, state or zipcode of the news you wish (optional); 
    147 * Select either a topic or search word(s) (because of Google rules, if you define both, the keys will be ignored) (optional); 
    148 * Select whether you want a publication date/time, excerpt (and for how many chars) or reference to this plugin author displayed or not (all optional) 
    149 * Select whether you want a dotted list or a numbered/ordered list (mandatory, default: dotted list) 
     151* If you live in the Usa or Canada (eng only), you might want to enter a city, state or zipcode of the news you want to display (optional); 
     152* Select EITHER a topic OR search word(s) (because of Google rules, if you define both, the keyword(s) will be ignored) (optional); 
     153* Tick off the box if you want a publication date, time, excerpt (and how many chars of it) or mention of this plugin author displayed or not (all optionals); 
     154* Select whether you want a dotted list or a numbered/ordered list (mandatory, default: dotted list); 
    150155* Select whether you want the linked news to open up in a new page (default) or in the same page (mandatory, default: new page); 
    151156* Click on 'Save' (and Close, if you want it). 
     
    154159 
    155160* In Posts/Pages->Add New/Edit of your wp admin page, select HTML in the entry form; 
    156 * enter [gnews location="xx"] where xx is any Google's location-code of the news you wish to display.A list of [Google's localization codes](http://www.stefaniamarchisio.com/2010/02/21/google-news-localization-codes/) is here. 
     161* enter [gnews location="xx"] where xx is any Google's location-code of the news you wish to display. A list of [Google's localization codes](http://www.stefaniamarchisio.com/2010/02/21/google-news-localization-codes/) is here. 
    157162That's the sole mandatory attribute. Optional attributes are: 
     163* link: either true or false to display a link to the  
    158164* local: city, state/province or zipcode (of usa or Canada english news only) 
    159165* search: search-words according to google search syntax (see the description above) (default: none); 
Note: See TracChangeset for help on using the changeset viewer.