summaryrefslogtreecommitdiff
path: root/reader_shared.php
blob: f3be003fcbafa95c23a95e0fb0e70f23bf8db368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
	Plugin Name: Google Reader Shared
	Plugin URI: http://mike.crute.org/
	Description: A sidebar add-in for Google Reader shared items.
	Version: 1.0
	Author: Mike Crute
	Author URI: http://mike.crute.org/
*/

// Format the plugin page
if (is_plugin_page()) { 
	if (isset($_POST['update_reader'])) {
		update_option('GoogleReader_FeedURL', $_POST['url']);
		update_option('GoogleReader_NumDisplay', $_POST['numdisp']);
		update_option('GoogleReader_CSSClass', $_POST['cssclass']);
		echo('<div class="updated"><p>Options changes saved.</p></div>');
}
?>
	<div class="wrap">
		<h2>Google Reader Shared Items Options</h2>
		
		<form method="post">		
			<fieldset class="options">
				<p><strong>Google Reader</strong></p>
				
				<label for="url">Feed URL:</label>
        		<input name="url" type="text" id="url" value="<?php echo get_option('GoogleReader_FeedURL'); ?>" />
        		
				<label for="numdisp">Number to Display (max is 20):</label>
		        <input name="numdisp" type="text" id="numdisp" value="<?php echo get_option('GoogleReader_NumDisplay'); ?>" />
		        
		        <label for="cssclass">CSS Class:</label>
		        <input name="cssclass" type="text" id="cssclass" value="<?php echo get_option('GoogleReader_CSSClass'); ?>" />
        	</fieldset>

		  	<p><div class="submit"><input type="submit" name="update_reader" value="Save Settings" style="font-weight:bold;" /></div></p>
        </form>       
    </div>
<?php
}

else {
	function readerShared() {
		$feedurl = trim(get_option('GoogleReader_FeedURL'));
		$display = trim(get_option('GoogleReader_NumDisplay'));
		$class = trim(get_option('GoogleReader_CSSClass'));
	
		printf('<ul%s>', ($class != '') ? " class=\"$class\"" : '');
		$feed = simplexml_load_file($feedurl);
		$loopcount = 0;
		
		foreach ($feed->entry as $item) {
			if ($loopcount < $display) {
				printf('<li><a href="%s" rel="nofollow">%s - %s</a></li>',$item->link[1]['href'],$item->title,$item->source->title);
				$loopcount++;
			}
		}
		echo('</ul>');
	}
}	
	
function readerShared_Menu() {
	add_options_page('Google Reader Shared Options', 'Google Reader', 9, basename(__FILE__));
}

add_action('admin_menu', 'readerShared_Menu');
?>