comment removed. March 21, 2007 Apparently--at least this is what I think happened--Google altered the XML format of their feed, thereby destroying the link targets of the plugin. This is now fixed, at least until the XML format changes again. Thanks to Amish for alerting me to the problem! BUG FIXES: Fixed year in previous update timestamps! TO DO: The things I previously assigned myself to do. But I've been busy... February 3, 2007 BUG FIXES 1. Fixed stupid javascript bug (it's getElementById, not getDocumentById!) Now the Content Length textbox is only enabled if you want content excerpts. January 28, 2007 BUG FIXES 1. If you are only listing titles, then the close tag is not ! (Thanks Amish!) January 27, 2007 NEW FEATURES 1. "Silent" failures can be made verbose by changing the below "define('READER_SHARED_DEBUG', false)" to "..., true)". It is not recommended that this be done except for debugging. 2. Added optional argument to the readerShared so that extracts only those shared items that have been tagged, or given the label, 'tag'. Conversely, if you provided a specific URL for a label, then will show all items, regardless of tag. TO DO 1. Allow additional optional arguments to readerShared. These will likely have the following format: readerShared('tag1', 'tag2', '!tag3', 'tag4', '!tag5', ...) will display those shared items that match tag1, tag2, and tag4 while not matching tag3 or tag5. Similarly, readerShared('!tag') removes items tagged with 'tag' from what would otherwise be displayed; this is backwards compatible with the current readherShared('tag') which displays those items with that tag; etc.. Be warned that this is incompatible with having a tag which begins with a '!'. Posted 2007-01-20 BUG FIXES 1. removed the "class=..." from the dd tag. This is unnecessary provided the style sheet contains a ".classname dd" rule; and any "dd.classname" rule should be converted to ".classname dd". Moreover the way it was written, if there was no class, then '
$s
\n"; } } if ( !function_exists('readerShared_goodInt') ) { function readerShared_goodInt($s, $min=0, $max=NULL) { $s = trim($s); if ( !ctype_digit($s) && ( ($min !== NULL && $min >=0) || $s{0} != '-' || !ctype_digits(substr($s, 1)) ) ) { return FALSE; } $i = (int)$s; if ( $min !== NULL && $i < $min ) { return -1; } if ( $max !== NULL && $i > $max ) { return 1; } return 0; } } // Format the plugin page if (is_plugin_page()) { // sanity check: don't want our "url" to e.g. be "file:///etc/passwd" // even if only an admin user is ostensibly able to get to this page // on the other hand, we should be as liberal as possible...so allow ftp $readerSharedErrors = array(); if ( isset($_POST['update_reader']) ) { if ( isset($_POST['url']) && preg_match('!^\s*(?:https?|ftp)://!', $_POST['url']) ) { if ( !preg_match('!^https?://www\.google\.com/reader/public/atom/user/\d+/state/com\.google/broadcast$!', $_POST['url']) ) { if ( preg_match('!^https?://www\.google\.com/reader/public/atom/user/\d+/label/[^/]+$!', $_POST['url']) ) { // could do something like a warning } else { $readerSharedErrors[] = "I will use the provided URL,{$_POST['url']}
, even though it does not look like a Google Reader URL";
}
} // finished checking type of google reader url
update_option('GoogleReader_FeedURL', $_POST['url']);
} else {
$readerSharedErrors[] = 'Please '.( isset($_POST['update_reader'])
? 'provide' : 'correct' )
.' your feed URL.';
}
// make sure numdisp is a number within the advertised bounds
if ( isset($_POST['numdisp'])
&& ($readerSharedITest
= readerShared_goodInt($_POST['numdisp'], 1, 20)) === 0 ) {
update_option('GoogleReader_NumDisplay', $_POST['numdisp']);
} else {
$readerSharedErrorPre = '\"Number to Display\"';
if ( $readerSharedITest === FALSE ) {
$readerSharedErrors[] = $readerSharedErrorPre." must be an integer!";
} else if ( $readerSharedITest === 1 ) {
$readerSharedErrors[] = $readerSharedErrorPre." must be positive.";
} else { // must be -1
$readerSharedErrors[] = $readerSharedErrorPre." must be less than 20.";
}
} // done with numdisp
// nothing to check for the class
update_option('GoogleReader_CSSClass', $_POST['cssclass']);
// excerpt is a checkbox
update_option('GoogleReader_IncludeExcerpts',
(isset($_POST['excerpt']) ? "1" : "" ));
// even if !excerpt, update the content length, if there. Never an
// error to omit; defaults to unlimited
// similarly curl time out length
foreach ( array('contentlen'=>array('GoogleReader_ContentLength', 'amount to excerpt'),
'curltime' => array('GoogleReader_curlTimeOut', 'cURL time out'))
as $readerShared_id => $readerShared_stuff ) {
if ( isset($_POST[$readerShared_id]) ) {
$readerSharedErrorPre = "{$readerShared_stuff[1]}";
if ( ($readerSharedITest
= readerShared_goodInt($_POST[$readerShared_id], 0, NULL)) === 0 ) {
update_option($readerShared_stuff[0], $_POST[$readerShared_id]);
} else if ( trim($_POST[$readerShared_id]) === "" ) { // treat as 0
update_option($readerShared_stuff[0], '0');
} else if ( $readerSharedITest !== 1 ) { // wasn't empty
$readerSharedErrors[] = $readerSharedErrorPre.' must be a nonnegative integer.';
}
} // end of if isset
} // end of foreach similar integer
echo('' .(!empty($readerSharedErrors) ? 'Valid o' : 'O') .'ptions changes saved.
If you excerpt, the Google Reader list will be inside a <dl> (descriptive list) element; the headlines will be inside a <dt> element and the excerpted content will be inside a <dd> element. Otherwise, <ul> and <li> tags will be used as usual. Please ensure your style sheet is written accordingly.
Make sure your sidebar.php
contains lines functionally
equivalent to
<h2>Google Reader</h2> <?php readerShared(); ?>
url_fopen
or cURL
.');
return;
}
if ( !is_a($feed, 'SimpleXMLElement') ) { // problem occurred
readerShared_echo('SimpleXML failed somehow.');
return;
}
$loopcount = 0;
if ( $excerpt = (get_option('GoogleReader_IncludeExcerpts') == '1') ) {
$listType = 'dl';
$listElement = 'dt';
$excerptLen = trim(get_option('GoogleReader_ContentLength'));
if ( empty($excerptLen) ) {
$excerptLen = 0;
} else {
$excerptLen = (int)$excerptLen;
}
} else {
$listType = 'ul';
$listElement = 'li';
}
printf('<%s%s>', $listType, ($class != '') ? " class=\"$class\"" : '');
foreach ($feed->entry as $item) {
if ($loopcount < $display) {
printf('<%s>%s - %s%1$s>',
$listElement,
htmlspecialchars($item->link['href']),
$item->title,
$item->source->title);
$loopcount++;
if ( !$excerpt ) continue;
$content = ( !empty($item->summary) ? $item->summary : $item->content );
$content = readerShared_excerptContent($content, $excerptLen);//defined below
echo "Shared by\\s*\\w+\\s*$\\s*\\s*$!msu', // m allows $ to match eol; s allows . to match eol; and u is for ungreedy. $s, $matches) ) { $s = substr($s, strlen($matches[0])); /*$comment = strip_tags($matches[1]);*/ // unnecessary since complete $comment = $matches[1]; } else { $comment = ''; } // easiest to strip tags and then truncate then to truncate, strip tags, // and worry about whether there is an unfinished tag "
\\s*$\\s*(.*)
$comment\n$s" : $s; } } if ( !function_exists('readerShared_Menu') ) { function readerShared_Menu() { add_options_page('Google Reader Shared Options', 'Google Reader', 9, basename(__FILE__)); } } add_action('admin_menu', 'readerShared_Menu'); ?>