WordPress.org

Plugin Directory

Changeset 220203


Ignore:
Timestamp:
03/20/10 19:36:02 (4 years ago)
Author:
stefsoton
Message:

upload version 0.7 with local field + minor changes

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

Legend:

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

    r213982 r220203  
    33 * Plugin Name: Google News Widget/Shortcode 
    44 * Plugin URI: http://www.stefaniamarchisio.com/goggle-news-widget-shortcode-plugin/ 
    5  * Description: A list of Google News given localization, searchkey(s) or topic and the number of displayable news. It works as both widget and shortcode. 
    6  * Version: 0.6 
     5 * 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: 0.7 
    77 * Author: Stefania Marchisio 
    88 * Author URI: http://stefaniamarchisio.com/about/ 
     
    1515/*  
    1616This is a wordpress plugin compatible with wordpress 2.8+ as a widget; wordpress 2.5+ as shortcode. 
    17 From the readme.txt: 
    18 A list of Google News given: localization, searchkey(s) or topic and the number of displayable news. It works as both widget and shortcode. 
    1917 
    2018Copyright (C) 2010  Stefania Marchisio (email: mywizardwebs@gmail.com) 
     
    3937 * @since 0.1 
    4038 */ 
    41 add_action( 'widgets_init', 'funct_register_googleNews' ); 
     39add_action( 'widgets_init', 'funct_gNews' ); 
    4240 
    4341/** 
     
    4745 * @since 0.1 
    4846 */ 
    49 function funct_register_googleNews() { 
    50    register_widget( 'WP_GoogleNews' ); 
     47function funct_gNews() { 
     48   register_widget( 'WP_gNews' ); 
    5149} 
    5250 
     
    5856 * @since 0.1 
    5957 */ 
    60 class WP_GoogleNews extends WP_Widget { 
     58class WP_gNews extends WP_Widget { 
    6159 
    6260    /** 
    6361     * Widget setup. 
    6462     */ 
    65     function WP_GoogleNews() { 
     63    function WP_gNews() { 
    6664        /* Widget settings. */ 
    67         $widget_ops = array( 'classname' => 'googlenews', 'description' => __('A list of Google News given localization, searchkey(s) or topic and the number of displayable news. It works as both widget and shortcode', 'googlenews') ); 
     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. Also available as shortcode.', 'googlenews') ); 
    6866 
    6967        /* Widget control settings. */ 
     
    8280        /* Our variables from the widget settings. */ 
    8381        $title = apply_filters('widget_title', $instance['title'] ); 
     82        $location = $instance['location']; 
     83        $geo = $instance['geo']; 
    8484        $name = $instance['name']; 
    8585        $topic = $instance['topic']; 
    86         $location = $instance['location']; 
    8786        $num = $instance['number']; 
    8887        $list = $instance['list']; 
    8988        $target= $instance['target']; 
     89    /* Boolean vars */ 
     90        $lkbtitle = isset( $instance['lkbtitle'] ) ? $instance['lkbtitle'] : false; 
    9091        $pubdate = isset( $instance['pubdate'] ) ? $instance['pubdate'] : false; 
    9192        $pubtime = isset( $instance['pubtime'] ) ? $instance['pubtime'] : false; 
     
    9798        echo $before_widget; 
    9899 
    99         /* Display the widget title if one was input (before and after defined by themes). */ 
    100         if ( $title ) 
    101             echo $before_title . $title . $after_title; 
    102  
    103         /* Define the feed according to params entered */ 
    104         $feed = "http://news.google.com/news?cf=all&ned=" . $location. "&output=rss"; 
    105         if ( $name ) { $feed .= "&q=$name"; } 
    106         if ( $topic ) { $feed .= "&topic=$topic"; } 
    107  
    108     echo gnw_FeedList($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex); 
     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    /* Display the widget title if one was input (before and after defined by themes). */ 
     107    if ( $title ) { 
     108           if ( $lkbtitle ) $title = "<a target='" . $target . "' href='$feed' title='$title'>$title</a>"; 
     109          echo $before_title . $title . $after_title; 
     110        } 
     111 
     112    echo gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex); 
    109113 
    110114        /* After widget (defined by themes). */ 
     
    120124        /* Strip tags for title and name to remove HTML (important for text inputs). */ 
    121125        $instance['title'] = strip_tags($new_instance['title']); 
     126        $instance['geo'] = strip_tags($new_instance['geo']); 
    122127        $instance['name'] = strip_tags($new_instance['name']); 
    123128        $instance['number'] = strip_tags($new_instance['number']); 
     
    127132        $instance['location'] = $new_instance['location']; 
    128133        $instance['topic'] = $new_instance['topic']; 
    129  
    130134        $instance['target'] = $new_instance['target']; 
    131135        $instance['list'] = $new_instance['list']; 
    132136 
    133137        /* No need to strip tags for boolean */ 
     138        $instance['lkbtitle'] = $new_instance['lkbtitle']; 
    134139        $instance['pubdate'] = $new_instance['pubdate']; 
    135140        $instance['pubtime'] = $new_instance['pubtime']; 
     
    137142        $instance['excerpt'] = $new_instance['excerpt']; 
    138143 
    139         return $instance; 
     144    return $instance; 
    140145 
    141146    } 
     
    149154 
    150155        /* Default widget settings. */ 
    151         $defaults = array( 'title' => __('The Latest Google News', 'RSSjb'), 'name' => __('sport', 'RSSjb'), 'location' => 'us', 'topic' => '', 'number' => '10', 'pubdate' => 'off', 'pubtime' => 'off', 'pubauthor' => 'on', 'excerpt' => 'off', 'charex' => ''); 
     156        $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'); 
    152157 
    153158        $instance = wp_parse_args( (array) $instance, $defaults );  
     
    156161        <p> 
    157162            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Widget Title:', 'googlenews'); ?></label> 
    158             <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%;" /> 
     163            <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:95%;" /> 
    159164        </p> 
    160165 
    161         <!-- Search Keyword(s): Text Input --> 
    162         <p> 
    163             <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e('Search keyword(s):', 'googlenews'); ?></label> 
    164             <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%;" /> 
    165         </p> 
    166                 <p align="center">=== OR ===</p> 
    167         <!-- Topic: Select Box --> 
    168         <p> 
    169         <label for="<?php echo $this->get_field_id( 'topic' ); ?>"><?php _e('Topic:', 'googlenews'); ?></label>  
    170         <select id="<?php echo $this->get_field_id( 'topic' ); ?>" name="<?php echo $this->get_field_name( 'topic' ); ?>" class="widefat" style="width:100%;"> 
    171 // options in Google News on 20 Feb 2010 
    172 <option value="" <?php if ('' == $instance['topic']) echo 'selected';?>>Top Stories (default)</option> 
    173 <option value="w" <?php if ('w' == $instance['topic']) echo 'selected';?>>World</option> 
    174 <option value="n" <?php if ('n' == $instance['topic']) echo 'selected';?>>Nation</option> 
    175 <option value="b" <?php if ('b' == $instance['topic']) echo 'selected';?>>Business</option> 
    176 <option value="t" <?php if ('t' == $instance['topic']) echo 'selected';?>>Sci/Tecn</option> 
    177 <option value="e" <?php if ('e' == $instance['topic']) echo 'selected';?>>Entertainment</option> 
    178 <option value="s" <?php if ('s' == $instance['topic']) echo 'selected';?>>Sports</option> 
    179 <option value="m" <?php if ('m' == $instance['topic']) echo 'selected';?>>Health</option> 
    180 <option value="ir" <?php if ('ir' == $instance['topic']) echo 'selected';?>>Spotlight</option> 
    181 <option value="po" <?php if ('po' == $instance['topic']) echo 'selected';?>>Most Popular</option> 
    182         </select> 
    183         </p> 
    184  
    185         <!-- Location: Select Box --> 
    186         <p> 
    187         <label for="<?php echo $this->get_field_id( 'location' ); ?>"><?php _e('Location:', 'googlenews'); ?></label>  
    188         <select id="<?php echo $this->get_field_id( 'location' ); ?>" name="<?php echo $this->get_field_name( 'location' ); ?>" class="widefat" style="width:100%;"> 
     166    <!-- Link Title to Feed? Checkbox --> 
     167    <p> 
     168    <label for="<?php echo $this->get_field_id( 'lkbtitle' ); ?>"><?php _e('Link Widget Title to Feed URL?', 'googlenews'); ?></label> 
     169    <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' ); ?>" />  
     170    </p> 
     171 
     172    <!-- Location: Select Box --> 
     173    <p> 
     174    <label for="<?php echo $this->get_field_id( 'location' ); ?>"><?php _e('Location:', 'googlenews'); ?></label>  
     175    <select id="<?php echo $this->get_field_id( 'location' ); ?>" name="<?php echo $this->get_field_name( 'location' ); ?>" class="widefat" style="width:95%;"> 
    189176 
    190177// Locations in news.google.com on 4 Mar 10 
     
    260247<option value="hk" <?php if ("hk" == $instance['location']) echo 'selected';?>>香港版 (Hong Kong)</option> 
    261248// End Locations in news.google.com on 4 Mar 10 
    262  
    263         </select> 
    264         </p> 
    265  
    266         <!-- N. articles to display: Text Input --> 
    267         <p> 
    268             <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e('Num. of News:', 'googlenews'); ?></label> 
    269             <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%;" /> 
    270         </p> 
    271  
    272         <!-- Show Publication Date? Checkbox --> 
    273         <p> 
    274             <label for="<?php echo $this->get_field_id( 'pubdate' ); ?>"><?php _e('Show publication date?', 'googlenews'); ?></label> 
    275             <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' ); ?>" />  
    276         </p> 
    277  
    278         <!-- Show Publication Time? Checkbox --> 
    279         <p> 
    280             <label for="<?php echo $this->get_field_id( 'pubtime' ); ?>"><?php _e('Show publication time?', 'googlenews'); ?></label> 
    281             <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' ); ?>" />  
    282         </p> 
     249    </select> 
     250    </p> 
     251 
     252    <!-- Local (city, state or zipcode): Text Input --> 
     253    <p> 
     254    <label for="<?php echo $this->get_field_id( 'geo' ); ?>"><?php _e('Local:', 'googlenews'); ?> (U.S. and Canada English only)</label> 
     255    <input id="<?php echo $this->get_field_id( 'geo' ); ?>" name="<?php echo $this->get_field_name( 'geo' ); ?>" value="<?php echo $instance['geo']; ?>" style="width:95%;" /> 
     256    </p> 
     257 
     258<fieldset style="margin: 10px; border: 1px solid grey; padding: 10px"> 
     259<legend> Choose between searchkey(s) and topic </legend> 
     260 
     261    <!-- Search Keyword(s): Text Input --> 
     262    <p> 
     263    <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e('Search keyword(s):', 'googlenews'); ?></label> 
     264    <input id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" value="<?php echo $instance['name']; ?>" style="width:95%;" /> 
     265    <p align="center">=== OR ===</p> 
     266    <!-- Topic: Select Box --> 
     267    <label for="<?php echo $this->get_field_id( 'topic' ); ?>"><?php _e('Topic:', 'googlenews'); ?></label>  
     268    <select id="<?php echo $this->get_field_id( 'topic' ); ?>" name="<?php echo $this->get_field_name( 'topic' ); ?>" class="widefat" style="width:95%;"> 
     269// options in Google News on 20 Feb 2010 
     270<option value="" <?php if ('' == $instance['topic']) echo 'selected';?>>Top Stories (default)</option> 
     271<option value="w" <?php if ('w' == $instance['topic']) echo 'selected';?>>World</option> 
     272<option value="n" <?php if ('n' == $instance['topic']) echo 'selected';?>>Nation</option> 
     273<option value="b" <?php if ('b' == $instance['topic']) echo 'selected';?>>Business</option> 
     274<option value="t" <?php if ('t' == $instance['topic']) echo 'selected';?>>Sci/Tecn</option> 
     275<option value="e" <?php if ('e' == $instance['topic']) echo 'selected';?>>Entertainment</option> 
     276<option value="s" <?php if ('s' == $instance['topic']) echo 'selected';?>>Sports</option> 
     277<option value="m" <?php if ('m' == $instance['topic']) echo 'selected';?>>Health</option> 
     278<option value="ir" <?php if ('ir' == $instance['topic']) echo 'selected';?>>Spotlight</option> 
     279<option value="po" <?php if ('po' == $instance['topic']) echo 'selected';?>>Most Popular</option> 
     280    </select> 
     281<span style="font-size: 0.9em;">Note: Google (not me) imposes to choose between the two options.</span> 
     282    </p> 
     283</fieldset> 
     284 
     285    <!-- N. articles to display: Text Input --> 
     286    <p> 
     287    <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e('Num. of News:', 'googlenews'); ?></label> 
     288    <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%;" /> 
     289    </p> 
     290 
     291    <!-- Show Publication Date? Checkbox --> 
     292    <p> 
     293    <label for="<?php echo $this->get_field_id( 'pubdate' ); ?>"><?php _e('Show publication date?', 'googlenews'); ?></label> 
     294    <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' ); ?>" />  
     295    </p> 
     296 
     297    <!-- Show Publication Time? Checkbox --> 
     298    <p> 
     299    <label for="<?php echo $this->get_field_id( 'pubtime' ); ?>"><?php _e('Show publication time?', 'googlenews'); ?></label> 
     300    <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' ); ?>" />  
     301    </p> 
    283302 
    284303    <!-- Show Excerpt? Checkbox --> 
    285304    <p> 
    286     <label for="<?php echo $this->get_field_id( 'excerpt' ); ?>"><?php _e('Show excerpt?', 'RSSjb'); ?></label> 
     305    <label for="<?php echo $this->get_field_id( 'excerpt' ); ?>"><?php _e('Show excerpt?', 'googlenews'); ?></label> 
    287306    <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' ); ?>" /> 
    288  <label for="<?php echo $this->get_field_id( 'charex' ); ?>"><?php _e(' and limit it to ', 'RSSjb'); ?></label> 
     307 <label for="<?php echo $this->get_field_id( 'charex' ); ?>"><?php _e(' and limit it to ', 'googlenews'); ?></label> 
    289308    <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. 
    290309    <span style="font-size: 0.8em;">(Warning: Google's excerpt contains images & formatting: not suitable for narrow sidebars)</span> 
     
    293312    <!-- List Type: Select Box --> 
    294313    <p> 
    295         <label for="<?php echo $this->get_field_id( 'list' ); ?>"><?php _e('List Type:', 'RSSjb'); ?></label>  
     314        <label for="<?php echo $this->get_field_id( 'list' ); ?>"><?php _e('List Type:', 'googlenews'); ?></label>  
    296315        <select id="<?php echo $this->get_field_id( 'list' ); ?>" name="<?php echo $this->get_field_name( 'list' ); ?>" class="widefat" style="width:100%;"> 
    297316<option value="UL" <?php if ('UL' == $instance['list']) echo 'selected';?>>Unordered (or Dotted) List (default)</option> 
     
    334353function gnews_funct($atts) { 
    335354     extract(shortcode_atts(array( 
     355     "location" => '', 
     356     "local" => '', 
    336357     "search" => '', 
    337358     "topic" => '', 
    338      "location" => '', 
    339359     "num" => '3', 
    340360     "list" => 'UL', 
     
    349369     /* Display name from widget settings if one was input. */ 
    350370     $feed = "http://news.google.com/news?cf=all&ned=" . $location. "&output=rss"; 
     371     if ( $local ) { $feed .= "&geo=$local"; } 
    351372     if ( $search ) { $feed .= "&q=$search"; } 
    352373     if ( $topic ) { $feed .= "&topic=$topic"; } 
    353374 
    354      return gnw_FeedList($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex); 
     375     return gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex); 
    355376} 
    356377 
    357 function gnw_FeedList($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex) { 
    358      include_once(ABSPATH . WPINC . '/rss.php'); 
    359  
    360      if ( $feed != "" && $rss = fetch_rss( $feed ) ) { 
    361         $fList = "<$list>\n"; 
    362     // for ($i = 0; $i < $num; $i++) { 
    363         if ( $num >0 ) { $rss->items = array_slice( $rss->items, 0, $num ); } 
    364     foreach ( (array) $rss->items as $item ) { 
    365        // $item = $rss->items[$i]; 
    366            $fList .= '<li>'; 
    367        $fList .= '<a target="'. $target . '" href="'.esc_url( $item['link'] ).'">'. $item['title'] .'</a>'; 
    368        if ( $pubdate !== false && $pubdate !== "false") { 
    369           $fList .= ' - ' . date ( 'd M y', strtotime( $item['pubdate'] )); 
    370            }  
    371  
    372            if ( $pubtime !== false && $pubtime !== "false") { 
    373           $fList .= ' at ' . date ( 'H:i', strtotime( $item['pubdate'] ));  
    374            } 
    375            if ( $excerpt != false && $excerpt != "false") { 
    376                     // special for google news 
    377                     // strip tags <font size="-1"><b> only 
    378                     $fList .= '<br/>'. gnw_substring_between($item['summary'], '<font size=','</font>'); 
    379                             $fList .= ' <a target="' . $target . '" href="' . esc_url( $item['link'] ) . '">[...]</a>'; 
    380            }  
    381            $fList .= '</li>'; 
    382     } 
    383         $fList .= "</".$list.">\n"; 
    384      }  
    385      if ($pubauthor !== false && $pubauthor !== "false") { 
    386     $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</a></p>'; 
    387      }  
    388      return $fList; 
    389 } 
    390  
    391 function gnw_substring_between($haystack,$start,$end) { 
    392     if (strpos($haystack,$start) === false || strpos($haystack,$end) === false) { 
    393         return false; 
     378function gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex) { 
     379    // decoding needed when you use a shortcode as URLs are encoded by the shortcode 
     380    $feed = html_entity_decode($feed);   
     381       $flist = "Error message: "; 
     382 
     383    // check whether a feed URL has been entered 
     384    if ($feed) { 
     385        libxml_use_internal_errors(true); 
     386        if ( $rss = simplexml_load_file($feed) ) {  
     387            // check whether it is an RSS format feed 
     388                if (array_key_exists('item', $rss->channel)) { 
     389                // $flist = "We have an RSS feed: make a list our of this: "; 
     390 
     391                $flist = "<$list>\n"; 
     392                $i = 0; 
     393                foreach ($rss->channel->item as $item ) { 
     394                    $flist .= "<li>"; 
     395                    if ($item->title || $item->description) { 
     396 
     397                    if ( $item->link ) { 
     398                        $motext = isset( $item->description ) ? htmlentities($item->description): htmlentities($item->title); 
     399                        $flist .= "<a target='". $target . "' href='$item->link' title='$motext'>"; 
     400                    } 
     401 
     402                    $flist .= isset( $item->title ) ? htmlentities($item->title) : htmlentities($item->description); 
     403 
     404                    if ( $item->link ) 
     405                        $flist .= "</a>";  
     406         
     407                    if ( $item->pubDate && $pubdate !== false && $pubdate !== "false" ) 
     408                        $flist .= ' - ' . date ( 'd M y', strtotime( $item->pubDate )); 
     409 
     410                          if ( $item->pubDate && $pubtime !== false && $pubtime !== "false") 
     411                        $fList .= ' at ' . date ( 'H:i', strtotime( $item->pubDate ));  
     412 
     413                    if ( $item->description && $excerpt != false && $excerpt != "false") { 
     414                        if ( $charex > '0' ) {  
     415                            $flist .= '<br/>'. substr($item->description, 0, $charex); 
     416                            $flist .= ' <a target="' . $target . '" href="' . esc_url( $item->link ) . '">[...]</a>'; 
     417                        } else { 
     418                            $flist .= '<br/>'. $item->description; 
     419                        } 
     420                    }  
     421                     
     422                    } else { 
     423                        $flist .= "No standard <item> in file"; 
     424                    } 
     425                    $flist .= "</li>"; 
     426                    $i++; 
     427                    if ($i >= $num) break; 
     428                } // foreach 
     429                $flist .= "</".$list.">\n"; 
     430 
     431            // otherwise check whether it is an Atom format feed 
     432            } elseif (array_key_exists('entry', $rss)) { 
     433 
     434                $flist = "<$list>\n"; 
     435                $flist .= "We have a Atom feed!<br>"; 
     436                $i = 0; 
     437 
     438                foreach ($rss->entry as $entry ) { 
     439                    $flist .= "<li>"; 
     440                    if ($entry->title && $entry->id && $entry->updated) { 
     441 
     442                    if ( $entry->link ) { 
     443                        $motext = isset( $entry->summary ) ? htmlentities($entry->summary): htmlentities($entry->title); 
     444                        $flist .= "<a target='". $target . "' href='$entry->link' title='$motext'>"; 
     445                    } 
     446 
     447                    $flist .= htmlentities($entry->title); 
     448 
     449                    if ( $entry->link ) $flist .= "</a>"; 
     450  
     451                    if ( $entry->updated && $pubdate !== false && $pubdate !== "false" ) 
     452                        $flist .= ' - ' . date ( 'd M y', strtotime( $entry->updated )); 
     453 
     454                          if ( $entry->updated && $pubtime !== false && $pubtime !== "false") 
     455                        $flist .= ' at ' . date ( 'H:i', strtotime( $entry->updated ));  
     456 
     457                    if ( $entry->summary && $excerpt != false && $excerpt != "false") { 
     458                        if ( $charex > '0' ) {  
     459                            $flist .= '<br/>'. substr($entry->summary, 0, $charex); 
     460                            $flist .= ' <a target="' . $target . '" href="' . esc_url( $entry->link ) . '">[...]</a>'; 
     461                        } else { 
     462                            $flist .= '<br/>'. $entry->summary; 
     463                        } 
     464                    }  
     465 
     466                    //$flist .= "Entry $i "; 
     467                    } else { 
     468                        $flist .= "No standard <entry> in file"; 
     469                    } 
     470                    $flist .= "</li>"; 
     471 
     472                    $i++; 
     473                    if ($i >= $num) break; 
     474                } // foreach 
     475 
     476                $flist .= "</".$list.">\n"; 
     477 
     478            } else { 
     479                $flist .= "No typical RSS or Atom feed or search criteria not supported by Google."; 
     480            } 
     481        } else { 
     482            $flist .= "<i>" . $feed . "</i> not found or is no standard XML file.";  
     483        } 
    394484    } else { 
    395         $start_position = strpos($haystack,$start)+strlen($start); 
    396         $end_position = strpos($haystack,$end); 
    397         return substr($haystack,$start_position,$end_position-$start_position); 
    398     } 
     485        $flist .= "Feed URL not provided. I do need an URL to a RSS or Atom XML file. Please, enter one.";  
     486    } 
     487    // if pubauthor has been selected 
     488    if ($pubauthor !== false && $pubauthor !== "false") { 
     489        $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</a></p>'; 
     490    } 
     491    return $flist; 
    399492} 
    400493?> 
  • google-news-widget/trunk/readme.txt

    r213982 r220203  
    22Contributors: stefsoton 
    33Donate link: http://www.stefaniamarchisio.com/donations/ 
    4 Tags: RSS, Atom, feed, XML, Google News, Googlenews, news, widget, shortcode 
     4Tags: RSS, Atom, feed, XML, syndication, syndicate, syndicating, Google News, Googlenews, news, widget, shortcode 
    55Requires at least: 2.8 
    66Tested up to: 2.9.2 
    7 Stable tag: 0.6 
     7Stable tag: 0.7 
    88 
    9 A list of Google News given: localization, searchkey(s) or topic, number of news. It works as a widget or shortcode. 
     9A customizable list of Google News given language-country, searchkey(s) or topic, number of news and whether you want publication date, time.  
    1010 
    1111== Description == 
    1212 
    13 It displays the list of the latest news by Google News given localization (language-country), search word(s) or topic, number of displayable news and whether you want publication date, time, a footer linking to this plugin's author/not. 
    14 The look & feel is customizable too. It works as a widget or shortcode (in post/pages). In other words, you can show your news in any widget-ready area of your wordpress blog or any post/page of your choice.  
     13It displays the list of the latest news by Google News given localization (country-language), search word(s) or topic, number of displayable news and whether you want publication date, date, reference to the author displayed/not. The look & feel is customizable too. It works as a widget or shortcode. 
     14Starting from version 0.7 - for Us and Canada (eng), it's also possible to display local news by selecting city, state/province or zipcode [ Courtesy of Greg at transientmonkey.com(transientmonkey.com) ] 
    1515 
    1616== Installation == 
    1717 
    18 1. From Plugins->Installed of your wordpress administration, select "Add new", search for "google news widget" into the search text-box then click on 'Install' (on the right) when prompted with this plugin 
     181. From Plugins->Installed of your wordpress administration, select "Add new", search for "google news widget" into the search text-box then click on 'Install' on the right when prompted with this plugin 
    1919 
    2020                                    OR 
    2121 
    22 2. Download this plugin from [wordpress repository](http://wordpress.org/extend/plugins/google-news-widget/) or from [Stefania's blog](http://www.stefaniamarchisio.com/wp-content/uploads/2010/03/google-news-widget-0.6.zip), unzip it (a directory with 2 files will be extracted) and upload it to the '/wp-content/plugins/' directory of your wordpress 
     222. Download this plugin from [wordpress repository](http://wordpress.org/extend/plugins/google-news-widget/) or from [Stefania's blog](http://www.stefaniamarchisio.com/wp-content/uploads/2010/02/google-news-widget-0.7.zip), unzip it (a directory with 2 files will be extracted) and upload it to the '/wp-content/plugins/' directory of your wordpress 
    2323 
    24243. Activate the plugin through the Plugins->Installed menu in your WordPress administration 
    2525 
    26 4. Configure it (see Usage in Other Notes) 
     264. See Usage (in Other Notes) for how to configure it 
    2727 
    2828== Frequently Asked Questions == 
     
    3030= Why the heck would I need/want it? 
    3131 
    32 = Well, it provides the latest news on any subject you want to choose in real time: can you imagine what boost of traffic can it bring to your blog? Let's pretend you write about volleyball, knitting or lactose-intolerance. You just need to enter the relevant words in the Keyword(s) field or select a topic and wait for Google to display the latest news on your chosen subject. 
     32= Well, it provides the latest news on any subject you want to choose in real time: can you imagine what boost of traffic can it bring to your blog? Let's pretend you write about volleyball, knitting or lactose-intolerance. You just need to enter the relevant words in the Keyword(s) field or select a topic and wait for google to display the latest news on your subject. 
    3333 
    3434= Hey, I cannot find any configuration page in 'Settings' How does it work? 
    3535 
    36 = As a widget, you drag & drop the widget to any widget-ready area of your theme; open and complete the widget form, and click on 'Save' button.  
    37 As a shortcode, you add/edit the post/page you want the news to be displayed into - IN HTML MODE! - and enter your shortcode as explained in Usage (in Other Notes).  
     36= As a widget, you drag & drop the widget to any widget-ready area of your theme; open and complete the widget form, and click on 'Save' button. As a shortcode, you add/edit the post/page you want the news to be displayed into - IN HTML MODE! - and enter your shortcode as explained below in Usage "[gnews..." 
     37   
    3838 
    3939== Screenshots == 
     
    4343== Changelog == 
    4444 
     45= 0.7 = 
     46 
     47* New feature: added selection of local news (working for Usa and Canada English only) 
     48* Added proper error messages for: empty, non-existing URLs and invalid/misformatted feeds content 
     49* Added defaults for target and list (widget fields) 
     50* Added instruction to hide Warnings from the xmlsimple_load_file function 
     51* Fixed a bug which prevented proper display of description/summary with tags 
     52 
    4553= 0.6 = 
    46 * added excerpt option to the widget form/shortcode 
    47 * added number of excerpt chars to be displayed on the widget form/shortcode 
    48 * added working message about formatting and sidebars 
    49 * updated readme.txt 
     54* added show/not excerpt and how many chars of it to the widget form/shortcode 
     55* fixed view of certain foreign countires in the widget's "Localization" drop down menu 
     56* updated readme.txt, fixed formatting 
    5057 
    5158= 0.5 = 
    52 * added publication time option to the widget form/shortcode 
    53 * added show footer option to the widget form/shortcode 
     59* added show/not publication time to the widget form/shortcode 
     60* added show/not plugin's author to the widget form/shortcode 
    5461* updated readme.txt and fixed links and some formatting 
    5562 
    56 = 0.4 (never released. used to test the bug-fix) = 
    57 * fixed a serious bug which prevented working in admin for certain wp installations  
    58 * added publication date option to the widget form/shortcode 
     63= 0.4 = (never released. used to test the bug-fix) 
     64* fixed a which prevented working in admin for certain wp installations  
     65* added show/not publication date to the widget form/shortcode 
    5966 
    6067= 0.3 = 
    61 * fixed Plugin Home directory in the plugin header file. 
     68* fixed Plugin Home directory in the plugin file header (google-news-widget.php) 
    6269 
    6370= 0.2 = 
    64 * Fixed a bug which prevented to show news, if no search-word was defined 
    65 * added topic, list and target options to the widget form/shortcode 
     71* added topic, list and target to the widget form/shortcode 
     72* fixed a bug which prevented to show news, if no search-word was defined 
    6673* enabled a shortcode version (to add news to posts/pages) 
    6774* updated readme.txt file 
     
    7481== Upgrade Notice == 
    7582 
     83= 0.7 = 
     84* New feature: added selection of local news (working for Usa and Canada English only) 
     85* Added proper error messages for: empty, non-existing URLs and invalid/misformatted feeds content 
     86 
    7687= 0.6 = 
    77 * if you want to show Google's excerpt then upgrade to version 0.6. Please do not use on narrow sidebars as it contains images and formatting. 
     88* if you want to show the excerpt of the news or cannot see your country/language in localization, then upgrade it. 
     89 
     90= 0.5 = 
     91* if the previous version (0.2 or 0.3) prevented you from working into the administration page then please upgrade it. 
    7892 
    7993= 0.5 = 
     
    8498 
    8599= 0.3 = 
    86 * just an upgrade due to a wrong link to the plugin homepage 
     100* just an upgrade due to a wrong link to the pugin homepgae 
    87101 
    88102= 0.2 = 
    89103* if you want to avoid to enter a keyword or want to show news by-topic or in a post/page then download it. It also allows some list customizations. 
    90104 
    91 == Usage == 
     105== Other Notes == 
    92106 
    93107As a widget: 
    94108 
    95109* Drag & Drop your widget in the widget-ready area; 
    96 * Enter a title to be given to this news list; 
    97 * Enter the location of the news you wish to display; 
    98 * (optional) Select either the topic you need to cover or search word(s) (if you define both, the search words will be ignored); 
    99 * Choose whether you want a publication date/time, excerpt (and for how many char) or not; 
    100 * Select whether you want a dotted list (default) or a numbered/ordered list; 
    101 * Select whether you want the linked items to open up in a new page (default) or in the same page; 
    102 * Choose whether you allow this plugin's author footer to be displayed or not (please, say yes); 
    103 * Click on 'Save' (and Close, if you want). 
     110* Choose a title to be given to this news list (optional); 
     111* Localize your news (language/country) (mandatory, default: us); 
     112* If you live in Usa or Canada (eng only), choose a city, state or zipcode of the news you wish (optional); 
     113* Select either a topic or search word(s) (because of Google rules, if you define both, the keys will be ignored) (optional); 
     114* 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) 
     115* Select whether you want a dotted list or a numbered/ordered list (mandatory, default: dotted list) 
     116* Select whether you want the linked news to open up in a new page (default) or in the same page (mandatory, default: new page); 
     117* Click on 'Save' (and Close, if you want it). 
    104118 
    105119As a shortcode: 
    106120 
    107 * Your admin wp page->Posts/Pages->Add New or Edit, select HTML in the entry form; 
    108 * enter [gnews location="..."] where ... 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; 
     121* In Posts/Pages->Add New/Edit of your wp admin page, select HTML in the entry form; 
     122* 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. 
    109123That's the sole mandatory attribute. Optional attributes are: 
    110  
     124* local: city, state/province or zipcode (of usa or Canada english news only) 
    111125* search: search-words according to google search syntax (see the description above) (default: none); 
    112126* topic: any of Google's topic-codes (default: Top Stories). Here is a [list of topic codes](http://www.stefaniamarchisio.com/2010/02/21/google-news-topic-codes/); 
    113 * num: number of items to be displayed (default: 3); 
     127* num: number of news to be displayed (default: 3); 
     128* list: either "UL" or "OL" to get unordered or ordered lists; 
     129* target: either "_blank" or "_self" to get links opened in new/the same windows; 
    114130* pubdate: either true or false to display the publication date/not; 
    115131* pubtime: either true or false to display the publication time/not; 
    116 * excerpt: either true or false to display the excerpt/not; 
    117 * charex: number of the ecerpt chars to be displayed/not; 
    118 * list: either "UL" or "OL" to get unordered or ordered lists; 
    119 * target: either "_blank" or "_self" to get links opened in new/the same windows; 
    120 * pubauthor: true/false whether you allow this plugin's author footer to be displayed or not (please, say yes); 
    121  
    122 Example: [gnews location="es" search="sport" topic="e" num="8" list="UL" target="_self"] 
     132* pubauthor: either true or false to display a link to the author/not; 
    123133 
    124134Please note the following Google quirks: 
     
    1261361. Not all topics are set for all country/language.  If you select a topic for a country where this is not provided (as yet?) then the "Top stories" (the default) will be displayed instead. 
    1271372. Google (not me!) allows to search by topic OR by search-word(s). The two "filters" cannot apparently work together (i.e. you cannot search for "hockey" in topic "Sport"). 
    128 2. Because of the above, if topic AND search-keys are both indicated, then the search-keys are ignored (but no, no error message). 
    129 3. The maximum number of displayable articles depends on the number of articles stored into the XML page (RSS feed page) of Google news website (i.e. if you wish to display the latest 15 news and the XML page contains 10 news only, then only 10 will be displayed). 
    130 4. The search syntax is that indicated by Google. In other words, in the search results, if: 
    131  
     1383. Because of the above, if topic AND search-keys are both indicated, then the search-keys are ignored (but no, no error message). 
     1394. The maximum number of displayable articles depends on the number of articles stored into the XML page (RSS feed page) of Google news website (i.e. if you wish to display the latest 15 news and the XML page contains 10 news only, then only 10 will be displayed). 
     1405. The search syntax is that indicated by Google. In other words, in the search results, if: 
    132141* all the words need to be present, then enter space-separated words (word1 word2 etc); 
    133142* any of the words can be present, then enter words separated by OR (word1 OR word2); 
Note: See TracChangeset for help on using the changeset viewer.