Google Reader account for display in a sidebar widget or within pages or posts. Easily customized with friendly interface. Embed in page or post via shortcode; can always show newest, or start at post publication date! Version: 3.2 Author: Jacob M Goldman (C. Murray Consulting) Author URI: http://www.cmurrayconsulting.com Plugin: Copyright 2009 C. Murray Consulting (email : jake@cmurrayconsulting.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ //******************// //REQUIREMENTS CHECK// //******************// function req_check () { if(!class_exists('SimpleXmlElement')) { echo '

A version of PHP with the SimpleXML class is required. This is included with PHP 5 and newer.

'; return false; } elseif (!ini_get('allow_url_fopen') && !function_exists("curl_init")) { echo '

Host Limitation Found

Recommended Reading needs to load a foreign XML feed from Google. Your host has turned off support for "fopen" and cURL - the two most widely supported mechanisms for loading foreign information like your shared feed. Please contact your host and ask them to enable the cURL PHP module or add "allow_url_fopen" in your PHP configuration.

'; return false; } return true; } //*********// //PLUG INIT// //*********// function grs_admin_init() { register_setting('grs-options', 'gr_lastupdate'); register_setting('grs-options', 'gr_sc_lastupdate'); register_setting('grs-options', 'gr_credit'); register_setting('grs-options', 'gr_sid'); register_setting('grs-options', 'gr_num'); register_setting('grs-options', 'gr_content'); register_setting('grs-options', 'gr_trim'); register_setting('grs-options', 'gr_notes'); register_setting('grs-options', 'gr_date'); register_setting('grs-options', 'gr_datep'); register_setting('grs-options', 'gr_source'); register_setting('grs-options', 'gr_sourcep'); register_setting('grs-options', 'gr_open'); register_setting('grs-options', 'gr_notep'); register_setting('grs-options', 'gr_skipnote'); register_setting('grs-options', 'gr_sc_styles'); register_setting('grs-options', 'gr_sc_html'); register_setting('grs-options', 'gr_sc_trim'); register_setting('grs-options', 'gr_sc_strpimg'); register_setting('grs-options', 'gr_sc_simplehtml'); register_setting('grs-options', 'gr_nofollow'); register_setting('grs-options', 'gr_sc_cache'); register_setting('grs-options', 'gr_cache'); register_setting('grs-options', 'gr_publish_date'); register_setting('grs-options', 'gr_publish_upto'); } add_action( 'admin_init', 'grs_admin_init' ); //*******************// //***CORE FUNCTION***// //*******************// function google_reader_items($isshortcode = false, $maxcnt = '') { if (!req_check()) return false; //handling of posts that should only show posts older than publication date of post $gr_publish_date = ($isshortcode) ? get_option("gr_publish_date") : false; if($gr_publish_date) { $cache = get_post_meta(get_the_ID(),"_gr_cache",true); if ($cache) return $cache; //WE'RE ALREADY DONE! $post_date = get_the_time('U'); $gr_publish_upto = get_option("gr_publish_upto"); if($gr_publish_upto) { //get last post using rec reading pub date global $wpdb; $mysql_date = date ("Y-m-d H:i:s", $post_date); $last_post = $wpdb->get_row("SELECT post_date FROM $wpdb->posts WHERE post_date < '$mysql_date' AND (post_type = 'post' OR post_type = 'page') AND post_content LIKE '%[recreading%]%' ORDER BY post_date DESC LIMIT 1;", ARRAY_N); $gr_publish_upto = ($last_post[0]) ? strtotime($last_post[0]) : false; } } $gr_sid = get_option("gr_sid"); if (!$gr_sid) return 'Recommended Reading plug-in has not been configured.'; $url = "http://www.google.com/reader/public/atom/user%2F".$gr_sid."%2Fstate%2Fcom.google%2Fbroadcast"; if (function_exists("curl_init")) { //use curl - faster $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); $response = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } else { //use fopen - fallback $data = @file_get_contents($url); $response = explode(" ",$http_response_header[0],3); $response = $response[1]; } if ($response != "200") return "No Google Reader feed was found with the provided ID."; $doc = new SimpleXmlElement($data, LIBXML_NOCDATA); //basic caching handling $feedupdate = strtotime($doc->updated); $lastupdate = $isshortcode ? get_option("gr_sc_lastupdate") : get_option("gr_lastupdate"); //whether to use shortcode cache check or widget cache check if(!$lastupdate || $lastupdate < $feedupdate) { if (isset($gr_publish_upto) && $gr_publish_upto) $maxcnt = ''; //if using publish up to and it applies, set max count to all elseif (!$maxcnt) $maxcnt = get_option("gr_num"); //otherwise if it wasn't passed by shortcode, get from options $cnt = count($doc->entry); //count total number of entries in feed if (!$cnt) return "There are no items in your shared Google Reader feed."; if ($maxcnt && $maxcnt < $cnt) $cnt = $maxcnt; //if user specified number of entries (and its less than total), here's the max loop iterations $gr_open = get_option("gr_open") ? ' target="_blank"' : ' '; //HTML for opening link in new window if set to $gr_nofollow = get_option("gr_nofollow") ? ' rel="nofollow"' : ' '; //HTML for nofollow rel $gr_skipnote = get_option('gr_skipnote'); $gr_date = get_option("gr_date"); if($gr_date) $datep = get_option("gr_datep"); $gr_source = get_option("gr_source"); if ($gr_source) $sourcep = get_option("gr_sourcep"); $gr_notes = get_option("gr_notes"); if($gr_notes) $notep = get_option("gr_notep"); $gr_content = get_option("gr_content"); if ($gr_content) $desctrim = get_option("gr_trim"); if ($isshortcode) { $gr_sc_html = get_option('gr_sc_html'); $gr_sc_simplehtml = get_option('gr_sc_simplehtml'); if (get_option('gr_sc_trim')) $desctrim = ""; $gr_sc_strpimg = get_option('gr_sc_strpimg'); } $gr_cache = '"; if($isshortcode && $gr_publish_date) { //if its based on post date and we'll have multiple, we store the value in the post meta update_post_meta(get_the_ID(),"_gr_cache",$gr_cache); //FINISH UP return $gr_cache; } elseif ($isshortcode) { update_option('gr_sc_cache',$gr_cache); update_option('gr_sc_lastupdate',$feedupdate); } else { update_option('gr_cache',$gr_cache); update_option('gr_lastupdate',$feedupdate); } } if ($isshortcode) return get_option("gr_sc_cache"); //shortcode needs return instead of echo return get_option("gr_cache"); } //****************************// //*** WIDGET INITIALIZATION **// //****************************// function widgetGRS_control() { // We need to grab any preset options $options = get_option("setup_widget_grs"); if (!is_array( $options )) $options = array('title' => 'Recommended Reading'); // No options? No problem! We set them here. if (isset($_POST['widgetGRS-Submit'])) { $options['title'] = htmlspecialchars($_POST['widgetGRS-WidgetTitle']); update_option("setup_widget_grs", $options); // And we also update the options in the Wordpress Database } echo ' '; } function widget_grs($args) { extract($args); $options = get_option("setup_widget_grs"); if (!is_array( $options )) $options = array('title' => 'Recommended Reading'); if (!$options['title']) $options['title'] = "Recommended Reading"; echo $before_widget; echo $before_title.$options['title'].$after_title; echo google_reader_items(); echo $after_widget; } function grs_init() { register_sidebar_widget('Rec. Reading', 'widget_grs'); register_widget_control('Rec Reading', 'widgetGRS_control'); } add_action("plugins_loaded", "grs_init"); //************************// //** ADMIN CONTROL PANEL *// //************************// function grs_admin_menu() { add_options_page('Google Reader Shared Posts Configuration', 'Rec. Reading', 8, __FILE__, 'grs_options'); } add_action('admin_menu', 'grs_admin_menu'); //** SET DEFAULTS **/ function set_grs_options() { update_option('gr_credit', true); } register_activation_hook(__FILE__,'set_grs_options'); //** ADMIN CONTROL PANEL PAGE **// function grs_options() { if ($_GET['updated'] == 'true') { update_option("gr_lastupdate",""); // clear the cache when editing the options update_option("gr_sc_lastupdate",""); // clear the shortcode cache when editing the options //clear shortcode cache if(get_option("gr_publish_date")) { global $wpdb; $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = '_gr_cache';"); } } ?>

Recommended Reading: Google Reader Shared Configuration

Support us

Help support continued development of Recommended Reading and other plugins.

The best thing you can do is refer someone looking for web development or strategy work to our company.

Short of that, here are other ways you can help:


/> Include link to us [?]

Support page

My Google Reader ID

Google Reader ID [?]
Look up my Google Reader ID
Google Username
Google Password
Your server does not have cURL enabled. cURL is a widely supported PHP module used to load and process external web pages behind the scenes. Unfortunately, cURL support is needed to dynamically look up your ID. You may still manually find and enter your ID. Click the question mark link above for instructions.

Display Settings

Quick Set
Number of Posts [?]
Show Post Content [?] />
Truncate Content [?]
Show Date [?]
Use PHP date format.
Preface Date [?]
Show Blog Source [?] />
Preface Source [?]
Open Links in New Window />
rel="nofollow" [?] />

Shared Item Notes

Show Notes [?] />
Preface Note [?]
Skip Standalone Notes [?] />

Display on page / post (shortcode)

You can display your Google Reader shared items on a dedicated page or post by simply typing [recreading] into the content (WordPress calls this "shortcode"). An optional attribute, 'items', can be set to the number of items you want to display; for example, [recreading items=5] to show 5 shared items.

The shortcode will use the settings above, but also has a few additional settings you can control.

As of publish date [?] />
... up to last post [?] />
Don't truncate content [?] />
... and show HTML [?] />
... ... but only simple tags [?] />
... ... and hide images [?] />
Use special styles [?] />

''),$atts)); return google_reader_items(true, $atts['items']); } add_shortcode('recreading', 'grs_shortcode'); //clear the shortcode cache, if applicable function clear_gr_sc_cache($post_ID) { delete_post_meta($post_ID,"_gr_cache"); } add_action('save_post','clear_gr_sc_cache'); function grs_stylize() { if(get_option('gr_sc_styles') && (is_singular() || is_home() || is_archive())) echo ''."\n"; } add_action('wp_head', 'grs_stylize'); // SETTINGS LINK function gr_plugin_actlinks( $links ) { // Add a link to this plugin's settings page $plugin = plugin_basename(__FILE__); $settings_link = sprintf( '%s', $plugin, __('Settings') ); array_unshift( $links, $settings_link ); return $links; } if(is_admin()) add_filter("plugin_action_links_".$plugin, 'gr_plugin_actlinks' ); //backwards compatibility for calling in template function google_reader_shared($isshortcode = false) { echo google_reader_items($isshortcode); return true; } ?>