WordPress.org

Plugin Directory

Changeset 507904


Ignore:
Timestamp:
02/20/12 21:27:59 (2 years ago)
Author:
stefsoton
Message:

updating to version 1.2

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

Legend:

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

    r324961 r507904  
    11<?php 
    22/** 
    3  * Plugin Name: Google News Widget/Shortcode 
    4  * Plugin URI: http://www.stefaniamarchisio.com/goggle-news-widget-shortcode-plugin/ 
     3 * Plugin Name: Google News Just Better 
     4 * Plugin URI: http://www.stefaniamarchisio.com/google-news-just-better-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.1 
     6 * Version: 1.2 
    77 * Author: Stefania Marchisio 
    88 * Author URI: http://stefaniamarchisio.com/about/ 
     
    1616This is a wordpress plugin compatible with wordpress 2.8+ as a widget; wordpress 2.5+ as shortcode. 
    1717 
    18 Copyright (C) 2010  Stefania Marchisio (email: mywizardwebs@gmail.com) 
     18Copyright (C) 2012  Stefania Marchisio (email: stefonthenet@gmail.com) 
    1919 
    2020This program is free software; you can redistribute it and/or 
     
    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  */ 
    44 add_filter( 'wp_feed_cache_transient_lifetime', create_function( '$a', 'return 1800;' )); 
    4540 
    4641/** 
     
    7469 
    7570    /* Create the widget. */ 
    76     $this->WP_Widget( 'google-news-widget', __('Google News Widget', 'googlenews'), $widget_ops, $control_ops ); 
     71    $this->WP_Widget( 'google-news-widget', __('Google News Just Better', 'googlenews'), $widget_ops, $control_ops ); 
    7772} 
    7873 
     
    9085    $topic = $instance['topic']; 
    9186    $num = $instance['number']; 
     87    $cachefeed = $instance['cachefeed']; 
    9288    $list = $instance['list']; 
    9389    $target= $instance['target']; 
     
    117113 
    118114    /* Call the function to read the feed content */ 
    119         echo gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex); 
     115        echo gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex, $cachefeed); 
    120116 
    121117    /* After widget (defined by themes). */ 
     
    135131    $instance['number'] = strip_tags($new_instance['number']); 
    136132    $instance['charex'] = strip_tags($new_instance['charex']); 
     133    $instance['cachefeed'] = strip_tags($new_instance['cachefeed']); 
    137134 
    138135    /* No need to strip tags for drop-down menus */ 
     
    160157 
    161158    /* 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'); 
     159    $defaults = array( 'title' => __('The Latest Google News', 'googlenews'), 'name' => '', 'lkbtitle' => 'off', 'location' => 'us', 'geo' => '', 'topic' => '', 'number' => '10', 'pubdate' => 'off', 'pubtime' => 'off', 'pubauthor' => 'on', 'excerpt' => 'off', 'charex' => '', 'list' => 'ul', 'target' => '_blank', 'cachefeed' => '3600'); 
    163160 
    164161    $instance = wp_parse_args( (array) $instance, $defaults );  
     
    176173    </p> 
    177174 
    178     <fieldset> 
    179     <legend> Keyword(s) OR Topic </legend> 
    180175    <!-- Search Keyword(s): Text Input --> 
    181176    <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%;"> 
     177    <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e('Search  for keyword(s) OR Topic:', 'googlenews'); ?></label> 
     178    <input id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" value="<?php echo $instance['name']; ?>" style="width:45%;" /> 
     179 
     180    <!-- Topic: Select Box -->  
     181    <select id="<?php echo $this->get_field_id( 'topic' ); ?>" name="<?php echo $this->get_field_name( 'topic' ); ?>" class="widefat" style="width:50%;"> 
    191182// options in Google News on 20 Feb 2010 
    192183<option value="" <?php if ('' == $instance['topic']) echo 'selected';?>>Top Stories (default)</option> 
     
    195186<option value="b" <?php if ('b' == $instance['topic']) echo 'selected';?>>Business</option> 
    196187<option value="t" <?php if ('t' == $instance['topic']) echo 'selected';?>>Sci/Tecn</option> 
     188<option value="tc" <?php if ('tc' == $instance['topic']) echo 'selected';?>>Technology</option> 
    197189<option value="e" <?php if ('e' == $instance['topic']) echo 'selected';?>>Entertainment</option> 
    198190<option value="s" <?php if ('s' == $instance['topic']) echo 'selected';?>>Sports</option> 
     191<option value="snc" <?php if ('snc' == $instance['topic']) echo 'selected';?>>Science</option> 
    199192<option value="m" <?php if ('m' == $instance['topic']) echo 'selected';?>>Health</option> 
    200193<option value="ir" <?php if ('ir' == $instance['topic']) echo 'selected';?>>Spotlight</option> 
     
    202195    </select> 
    203196    </p> 
    204     </fieldset> 
     197 
    205198    <!-- Location: Select Box --> 
    206199    <p> 
    207200    <label for="<?php echo $this->get_field_id( 'location' ); ?>"><?php _e('Location:', 'googlenews'); ?></label>  
    208201    <select id="<?php echo $this->get_field_id( 'location' ); ?>" name="<?php echo $this->get_field_name( 'location' ); ?>" class="widefat" style="width:100%;"> 
    209 // Locations in news.google.com on 4 Mar 10 
     202// Locations in news.google.com on 12 Nov 11 
    210203<option value="es_ar" <?php if ("es_ar" == $instance['location']) echo 'selected';?>>Argentina</option>  
    211204<option value="au" <?php if ("au" == $instance['location']) echo 'selected';?>>Australia</option>  
     
    278271<option value="jp" <?php if ("jp" == $instance['location']) echo 'selected';?>>日本 (Japan)</option>  
    279272<option value="hk" <?php if ("hk" == $instance['location']) echo 'selected';?>>香港版 (Hong Kong)</option> 
    280 // End Locations in news.google.com on 4 Mar 10 
     273// End Locations in news.google.com on 12 Nov 11 
    281274    </select> 
    282275    </p> 
     
    286279    <label for="<?php echo $this->get_field_id( 'geo' ); ?>"><?php _e('Local:', 'googlenews'); ?></label> 
    287280    <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%;" /> 
     281    </p> 
     282 
     283    <!-- Cache Refresh Frequency(sec.): Text Input --> 
     284    <p> 
     285    <label for="<?php echo $this->get_field_id( 'cachefeed' ); ?>"><?php _e('Cache Refresh Frequency (in sec.):', 'RSSjb'); ?></label> 
     286    <input id="<?php echo $this->get_field_id( 'cachefeed' ); ?>" name="<?php echo $this->get_field_name( 'cachefeed' ); ?>" value="<?php echo $instance['cachefeed']; ?>" style="width:100%;" /> 
    288287    </p> 
    289288 
     
    370369     "charex" => '', 
    371370     "title" => '', 
    372      "link" => false 
     371     "link" => false, 
     372     "cachefeed" => '3600' 
    373373     ), $atts)); 
    374374 
     
    379379     if ( $topic ) { $feed .= "&topic=$topic"; } 
    380380     $tle = ""; 
    381      if ( $link || $title ) {  
     381     if ( filter_var($link, FILTER_VALIDATE_BOOLEAN) || $title ) {  
    382382        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> ";  
    383383        $tle .= $title;  
    384384     } 
    385      return $tle . gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex); 
     385     return $tle . gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex, $cachefeed); 
    386386} 
    387387 
     
    392392*/ 
    393393 
    394 function gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex) { 
     394function gnw_List($feed, $num, $list, $target, $pubdate, $pubtime, $pubauthor, $excerpt, $charex, $cachefeed) { 
    395395    include_once(ABSPATH . WPINC . '/feed.php'); 
    396396 
     
    402402    if ($feed) { 
    403403 
    404         $rss = ""; 
    405     if ( $rss = fetch_feed($feed) ) {  
     404    // set cache recreation frequency (in seconds) 
     405    add_filter( 'wp_feed_cache_transient_lifetime' , create_function( '$a', 'return '.$cachefeed.';' )  ); 
     406    // fetch feed using simplepie. Returns a standard simplepie object 
     407    $rss = fetch_feed($feed); 
     408    // unset cache recreation frequency 
     409    remove_filter( 'wp_feed_cache_transient_lifetime' , create_function( '$a', 'return 42300;' )  ); 
     410     
     411    if ( $rss ) {  
    406412 
    407413    if (!is_wp_error( $rss )) { 
     
    431437                if ( $permalink )   $flist .= "</a>";  
    432438         
    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") { 
     439                if ( $item->get_date() && filter_var($pubdate, FILTER_VALIDATE_BOOLEAN) )   $flist .= ' - ' . date ( get_option('date_format'),  strtotime( $item->get_date() ) ); 
     440 
     441                        if ( $item->get_date() && filter_var($pubtime, FILTER_VALIDATE_BOOLEAN) )   $flist .= ' at ' . date ( get_option('time_format'),  strtotime( $item->get_date() ) );  
     442 
     443                if ( $desc && filter_var($excerpt, FILTER_VALIDATE_BOOLEAN) ) { 
    440444                    if ( $charex > '0' ) {  
    441445                        $flist .= '<br/>'. substr($item->description, 0, $charex); 
     
    463467    } // if ($feed) 
    464468 
    465     // if pubauthor has been selected 
    466     if ($pubauthor !== false && $pubauthor !== "false") { 
    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>'; 
     469    // if pubauthor has to be displayed (= is true) 
     470    if ( filter_var($pubauthor, FILTER_VALIDATE_BOOLEAN) ) { 
     471        $flist .= '<p style="text-align:center; font-size: 0.8em">powered by <a target="_blank" href="http://www.stefaniamarchisio.com/google-news-just-better-plugin/">Google News Just Better</a> 1.2 plugin</p>'; 
    468472    } 
    469473    return $flist; 
  • google-news-widget/trunk/readme.txt

    r324961 r507904  
    1 === Google News Widget === 
     1=== Google News Just Better === 
    22Contributors: stefsoton 
    33Donate link: http://www.stefaniamarchisio.com/donations/ 
    44Tags: RSS, Atom, feed, XML, syndication, syndicate, syndicating, Google News, Googlenews, news, widget, shortcode 
     5Author URI: http://www.stefaniamarchisio.com 
     6Plugin URI: http://www.stefaniamarchisio.com/google-news-just-better-plugin/ 
    57Requires at least: 2.8 
    6 Tested up to: 3.0.3 
    7 Stable tag: 1.1 
    8  
    9 A customizable list of Google News given language-country, searchkey(s) or topic, number of news and whether you want publication date, time.  
     8Tested up to: 3.3.1 
     9Stable tag: 1.2 
     10 
     11A customizable list of Google News given: language & country code, keyword(s) or topic, cache recreation frequency, number of items to display. It also let you choose if you want to publish an excerpt, date, time and the author.  
    1012 
    1113== Description == 
     
    1618== Installation == 
    1719 
    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 
     201. From Plugins->Installed of your wordpress administration, select "Add new", search for "google news just better" into the search text-box then click on 'Install' on the right when prompted with this plugin 
    1921 
    2022                                    OR 
    2123 
    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/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 
     242. Download this plugin from [wordpress repository](http://wordpress.org/extend/plugins/google-news-just better/), unzip it (a directory with 2 files will be extracted) and upload it to the '/wp-content/plugins/' directory of your wordpress 
    2325 
    24263. Activate the plugin through the Plugins->Installed menu in your WordPress administration 
     
    4244 
    4345== Changelog == 
     46 
     47= 1.2 =  
     48 
     49* New feature: the user is able to set the cache refresh time both in the widget form and the shortcode 
     50 
     51* Change: Copyright set to 2012 
     52* Change: Replaced old email address (mywizardwebs@) with new (stefonthenet@) 
     53* Change: Added the plugin version number in the "Powered from" line at the botton 
     54* Change: Renamed plugin from Google News Widget/Shortcode to Google News Just Better 
     55* Change: Author URI, Plugin URI added to readme.txt file 
     56* Change: formatting topic and keyword(s) (now on the same line) 
     57* Change: "sport" (as default keyword removed from keyword(s) textbox in widget form 
     58* Change: List of Google News location set to 12 Nov 2011 (last time check) 
     59* Change: Topic Science/Technology has been split into Science and Technology (2 topics) by Google itself. 
     60* Change: Improved description of sample shortcode 
     61 
     62* Fixed bug: Boolean variables were not properly tested and caused some inconsistent views when used as a shortcode 
    4463 
    4564= 1.1 =  
     
    107126 
    108127== Upgrade Notice == 
     128 
     129= 1.2 = 
    109130 
    110131= 1.1 =  
     
    159180 
    160181* In Posts/Pages->Add New/Edit of your wp admin page, select HTML in the entry form; 
    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. 
     182* enter [gnews location="replace-with-the-Google-s-location-code-of-the-country-language-you-want-news-from"]. Here is a list of [Google's localization codes](http://www.stefaniamarchisio.com/2010/02/21/google-news-localization-codes/) is here. 
    162183That's the sole mandatory attribute. Optional attributes are: 
    163184* link: either true or false to display a link to the  
     
    189210 
    190211== Interaction == 
    191 * Would you like to see a new feature in this plugin? Please write me here: mywizardwebs@gmail.com; 
     212* Would you like to see a new feature in this plugin? Please write me here: stefonthenet@gmail.com; 
    192213* Would you like to see a broken/orphan plugin working again? Write me anyhow, I might (hey, MIGHT not will/shall) find the time to give it a look. 
Note: See TracChangeset for help on using the changeset viewer.