PluginProbe
Super RSS Reader – Add attractive RSS Feed Widget / 2.1
Super RSS Reader – Add attractive RSS Feed Widget v2.1
trunk 0.8 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 3.0 3.1 3.2 4.0 4.0.1 4.1 4.2 4.3 4.4 4.4.1 4.5 4.6 4.7 4.8 All 33 releases
super-rss-reader / super-rss-reader.php

super-rss-reader.php in Super RSS Reader – Add attractive RSS Feed Widget 2.1, at super-rss-reader.php

423 lines 15.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Super RSS Reader
4 Plugin URI: http://www.aakashweb.com/wordpress-plugins/super-rss-reader/
5 Author URI: http://www.aakashweb.com/
6 Description: Super RSS Reader is jQuery based RSS reader widget, which displays the RSS feeds in the widget in an attractive way. It uses the jQuery easy ticker plugin to add a news ticker like effect to the RSS feeds. Multiple RSS feeds can be added for a single widget and they get seperated in tabs. <a href="http://www.youtube.com/watch?v=02aOG_-98Tg" target="_blank" title="Super RSS Reader demo video">Check out the demo video</a>.
7 Author: Aakash Chakravarthy
8 Version: 2.1
9 */
10
11 if(!defined('WP_CONTENT_URL')) {
12 $srr_url = get_option('siteurl') . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__)).'/';
13 }else{
14 $srr_url = WP_CONTENT_URL . '/plugins/' . plugin_basename(dirname(__FILE__)) . '/';
15 }
16
17 define('SRR_VERSION', '2.1');
18 define('SRR_AUTHOR', 'Aakash Chakravarthy');
19 define('SRR_URL', $srr_url);
20
21 ## Include the required scripts
22 function srr_public_scripts(){
23 // jQuery
24 wp_deregister_script('jquery');
25 wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js');
26 wp_enqueue_script('jquery');
27
28 // Super RSS Reader JS and CSS
29 wp_register_script('super-rss-reader-js', SRR_URL . 'public/srr-js.js');
30 wp_enqueue_script(array('jquery', 'super-rss-reader-js'));
31 }
32 add_action('wp_enqueue_scripts', 'srr_public_scripts');
33
34 ## Include the required styles
35 function srr_public_styles(){
36 wp_register_style('super-rss-reader-css', SRR_URL . 'public/srr-css.css');
37 wp_enqueue_style('super-rss-reader-css');
38 }
39 add_action('wp_enqueue_scripts', 'srr_public_styles');
40
41 ## Default color styles
42 $srr_color_styles = array(
43 'No style' => 'none',
44 'Grey' => 'grey',
45 'Dark' => 'dark',
46 'Orange' => 'orange'
47 );
48
49 ## The main RSS Parser
50 function srr_rss_parser($instance){
51
52 $urls = stripslashes($instance['urls']);
53 $count = intval($instance['count']);
54 $show_date = intval($instance['show_date']);
55 $show_desc = intval($instance['show_desc']);
56 $show_author = intval($instance['show_author']);
57 $open_newtab = intval($instance['open_newtab']);
58 $strip_desc = intval($instance['strip_desc']);
59 $color_style = stripslashes($instance['color_style']);
60 $enable_ticker = intval($instance['enable_ticker']);
61 $visible_items = intval($instance['visible_items']);
62
63 if(empty($urls)){
64 return '';
65 }
66
67 $rand = array();
68 $url = explode(',', $urls);
69
70 // Generate the Tabs
71 if(count($url) > 1){
72 echo '<ul class="srr-tab-wrap srr-tab-style-' . $color_style . ' srr-clearfix">';
73 for($i=0; $i<count($url); $i++){
74 // Get the Feed URL
75 $feedUrl = trim($url[$i]);
76 $rss = fetch_feed($feedUrl);
77 if (is_wp_error($rss)){
78 if (is_admin() || current_user_can('manage_options')){
79 echo '<p><strong>RSS Error</strong>:' . $rss->get_error_message() . '</p>';
80 return;
81 }
82 }
83 $rss_title = esc_attr(strip_tags($rss->get_title()));
84 $rand[$i] = rand(0, 999);
85 echo '<li data-tab="srr-tab-' . $rand[$i] . '">' . $rss_title . '</li>';
86 }
87 echo '</ul>';
88 }
89
90 for($i=0; $i<count($url); $i++){
91 // Get the Feed URL
92 $feedUrl = trim($url[$i]);
93 if(isset($url[$i])){
94 $rss = fetch_feed($feedUrl);
95 }else{
96 return '';
97 }
98
99 // Check for feed errors
100 if (!is_wp_error( $rss ) ){
101 $maxitems = $rss->get_item_quantity($count);
102 $rss_items = $rss->get_items(0, $maxitems);
103 $rss_title = esc_attr(strip_tags($rss->get_title()));
104 $rss_desc = esc_attr(strip_tags($rss->get_description()));
105 }
106
107 // Outer Wrap start
108 echo '<div class="srr-wrap ' . (($enable_ticker == 1 ) ? 'srr-vticker' : '' ) . ' srr-style-' . $color_style . '" data-visible="' . $visible_items . '" data-id="srr-tab-' . $rand[$i] . '"><div>';
109
110 // Check feed items
111 if ($maxitems == 0){
112 echo '<div>No items.</div>';
113 }else{
114 $j=1;
115 // Loop through each feed item
116 foreach ($rss_items as $item){
117 // Get the link
118 $link = $item->get_link();
119 while ( stristr($link, 'http') != $link ){ $link = substr($link, 1); }
120 $link = esc_url(strip_tags($link));
121
122 // Get the item title
123 $title = esc_attr(strip_tags($item->get_title()));
124 if ( empty($title) )
125 $title = __('Untitled');
126
127 // Get the date
128 $date = $item->get_date('j F Y');
129
130 // Get the description
131 $desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
132
133 if($strip_desc != 0){
134 $desc = wp_html_excerpt( $desc, $strip_desc );
135 if ( '[...]' == substr( $desc, -5 ) )
136 $desc = substr( $desc, 0, -5 ) . '[&hellip;]';
137 elseif ( '[&hellip;]' != substr( $desc, -10 ) )
138 $desc .= ' [&hellip;]';
139 }
140 $desc = esc_html( $desc );
141
142 // Get the author
143 $author = $item->get_author();
144 if ( is_object($author) ) {
145 $author = $author->get_name();
146 $author = esc_html(strip_tags($author));
147 }
148
149 // Open links in new tab
150 $newtab = ($open_newtab) ? ' target="_blank"' : '';
151
152 echo "\n\n\t";
153
154 // Display the feed items
155 echo '<div class="srr-item ' . (($j%2 == 0) ? 'even' : 'odd') . '">';
156 echo '<a href="' . $link . '"' . $newtab . ' title="Posted on ' . $date . '">' .$title . '</a>';
157 if($show_date) echo '<br/><em class="srr-date">' . $date . '</em>';
158 if($show_author) echo ' - <cite class="srr-author">' . $author . '</cite>';
159 if($show_desc) echo '<p class="srr-summary">' . $desc . '</p>';
160 echo '</div>';
161 // End display
162
163 $j++;
164 }
165 }
166
167 // Outer wrap end
168 echo "\n\n</div>
169 </div> \n\n" ;
170
171 }
172 }
173
174 class super_rss_reader_widget extends WP_Widget{
175 ## Initialize
176 function super_rss_reader_widget(){
177 $widget_ops = array(
178 'classname' => 'widget_super_rss_reader',
179 'description' => "Enhanced RSS feed reader widget with advanced features."
180 );
181
182 $control_ops = array('width' => 430, 'height' => 500);
183 parent::WP_Widget('super_rss_reader', 'Super RSS Reader', $widget_ops, $control_ops);
184 }
185
186 ## Display the Widget
187 function widget($args, $instance){
188 extract($args);
189 if(empty($instance['title'])){
190 $title = '';
191 }else{
192 $title = $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title;
193 }
194
195 echo $before_widget . $title;
196 echo "\n" . '
197 <!-- Start - Super RSS Reader -->
198 <div class="super-rss-reader-widget">' . "\n";
199
200 srr_rss_parser($instance, $instance['urls']);
201
202 echo "\n" . '</div>
203 <!-- End - Super RSS Reader -->
204 ' . "\n";
205 echo $after_widget;
206 }
207
208 ## Save settings
209 function update($new_instance, $old_instance){
210 $instance = $old_instance;
211 $instance['title'] = stripslashes($new_instance['title']);
212 $instance['urls'] = stripslashes($new_instance['urls']);
213
214 $instance['count'] = intval($new_instance['count']);
215 $instance['show_date'] = intval($new_instance['show_date']);
216 $instance['show_desc'] = intval($new_instance['show_desc']);
217 $instance['show_author'] = intval($new_instance['show_author']);
218 $instance['open_newtab'] = intval($new_instance['open_newtab']);
219 $instance['strip_desc'] = intval($new_instance['strip_desc']);
220
221 $instance['color_style'] = stripslashes($new_instance['color_style']);
222 $instance['enable_ticker'] = intval($new_instance['enable_ticker']);
223 $instance['visible_items'] = intval($new_instance['visible_items']);
224
225 return $instance;
226 }
227
228 ## HJA Widget form
229 function form($instance){
230 global $srr_color_styles;
231
232 $instance = wp_parse_args( (array) $instance, array(
233 'title' => '', 'urls' => '', 'count' => 5,
234 'show_date' => 0, 'show_desc' => 1, 'show_author' => 0,
235 'open_newtab' => 1, 'strip_desc' => 100, 'color_style' => 'none',
236 'enable_ticker' => 1, 'visible_items' => 5
237 ));
238
239 $title = htmlspecialchars($instance['title']);
240 $urls = htmlspecialchars($instance['urls']);
241
242 $count = intval($instance['count']);
243 $show_date = intval($instance['show_date']);
244 $show_desc = intval($instance['show_desc']);
245 $show_author = intval($instance['show_author']);
246 $open_newtab = intval($instance['open_newtab']);
247 $strip_desc = intval($instance['strip_desc']);
248
249 $color_style = stripslashes($instance['color_style']);
250 $enable_ticker = intval($instance['enable_ticker']);
251 $visible_items = intval($instance['visible_items']);
252
253 ?>
254 <div class="srr_settings">
255 <table width="100%" height="72" border="0">
256 <tr>
257 <td width="13%" height="33"><label for="<?php echo $this->get_field_id('title'); ?>">Title: </label></td>
258 <td width="87%"><input id="<?php echo $this->get_field_id('title');?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" class="widefat"/></td>
259 </tr>
260 <tr>
261 <td><label for="<?php echo $this->get_field_id('urls'); ?>">URLs: </label></td>
262 <td><input id="<?php echo $this->get_field_id('urls');?>" name="<?php echo $this->get_field_name('urls'); ?>" type="text" value="<?php echo $urls; ?>" class="widefat"/>
263 <small class="srr_smalltext">Can enter multiple RSS/atom feed URLs seperated by a comma.</small>
264 </td>
265 </tr>
266 </table>
267 </div>
268
269 <div class="srr_settings">
270 <h4>Settings</h4>
271 <table width="100%" border="0">
272 <tr>
273 <td width="7%" height="28"><input id="<?php echo $this->get_field_id('show_desc'); ?>" type="checkbox" name="<?php echo $this->get_field_name('show_desc'); ?>" value="1" <?php echo $show_desc == "1" ? 'checked="checked"' : ""; ?> /></td>
274 <td width="40%"><label for="<?php echo $this->get_field_id('show_desc'); ?>">Show Description</label></td>
275 <td width="28%"><label for="<?php echo $this->get_field_id('count');?>">Count</label></td>
276 <td width="25%"><input id="<?php echo $this->get_field_id('count');?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo $count; ?>" class="widefat" title="No of feed items to parse"/></td>
277 </tr>
278 <tr>
279 <td height="32"><input id="<?php echo $this->get_field_id('show_date'); ?>" type="checkbox" name="<?php echo $this->get_field_name('show_date'); ?>" value="1" <?php echo $show_date == "1" ? 'checked="checked"' : ""; ?> /></td>
280 <td><label for="<?php echo $this->get_field_id('show_date'); ?>">Show Date</label></td>
281 <td><label for="<?php echo $this->get_field_id('strip_desc');?>">Strip description</label></td>
282 <td><input id="<?php echo $this->get_field_id('strip_desc');?>" name="<?php echo $this->get_field_name('strip_desc'); ?>" type="text" value="<?php echo $strip_desc; ?>" class="widefat" title="Use 0 to avoid striping the description of the feed"/> </td>
283 </tr>
284 <tr>
285 <td height="29"><input id="<?php echo $this->get_field_id('show_author'); ?>" type="checkbox" name="<?php echo $this->get_field_name('show_author'); ?>" value="1" <?php echo $show_author == "1" ? 'checked="checked"' : ""; ?> /></td>
286 <td><label for="<?php echo $this->get_field_id('show_author'); ?>">Show Author</label></td>
287 <td>&nbsp;</td>
288 <td>&nbsp;</td>
289 </tr>
290 <tr>
291 <td height="29"><input id="<?php echo $this->get_field_id('open_newtab'); ?>" type="checkbox" name="<?php echo $this->get_field_name('open_newtab'); ?>" value="1" <?php echo $open_newtab == "1" ? 'checked="checked"' : ""; ?> /></td>
292 <td><label for="<?php echo $this->get_field_id('open_newtab'); ?>">Open links in new tab</label></td>
293 <td>&nbsp;</td>
294 <td>&nbsp;</td>
295 </tr>
296 </table>
297 </div>
298
299 <div class="srr_settings">
300 <h4>Other settings</h4>
301 <table width="100%" height="109" border="0">
302 <tr>
303 <td height="32"><label>Color style: </label></td>
304 <td>
305 <?php
306 echo '<select name="' . $this->get_field_name('color_style') . '" id="' . $this->get_field_id('color_style') . '">';
307 foreach($srr_color_styles as $k => $v){
308 echo '<option value="' . $v . '" ' . ($color_style == $v ? 'selected="selected"' : "") . '>' . $k . '</option>';
309 }
310 echo '</select>';
311 ?>
312 </td>
313 </tr>
314 <tr>
315 <td height="33"><label for="<?php echo $this->get_field_id('enable_ticker'); ?>">Ticker animation:</label> </td>
316 <td><input id="<?php echo $this->get_field_id('enable_ticker'); ?>" type="checkbox" name="<?php echo $this->get_field_name('enable_ticker'); ?>" value="1" <?php echo $enable_ticker == "1" ? 'checked="checked"' : ""; ?> /></td>
317 </tr>
318 <tr>
319 <td height="36"><label for="<?php echo $this->get_field_id('visible_items');?>">Visible items: </label></td>
320 <td><input id="<?php echo $this->get_field_id('visible_items');?>" name="<?php echo $this->get_field_name('visible_items'); ?>" type="text" value="<?php echo $visible_items; ?>" class="widefat" title="The no of feed items to be visible."/>
321 </td>
322 </tr>
323 </table>
324 </div>
325
326 <div class="srr_support"> <a href="http://facebook.com/aakashweb" class="srr_fblike" target="_blank">Like</a> | <a href="http://bit.ly/srrdonate" target="_blank" style="color: #FF6600" title="If you like this plugin, then just make a small donation and it will be helpful for the plugin's development.">Donate</a> | <a href="http://www.aakashweb.com/wordpress-plugins/super-rss-reader/" target="_blank">Support</a></div>
327
328 <?php
329 }
330 }
331
332 function super_rss_reader_init(){
333 register_widget('super_rss_reader_widget');
334 }
335 add_action('widgets_init', 'super_rss_reader_init');
336
337 function srr_widget_scripts(){
338 if(in_array($GLOBALS['pagenow'], array('widgets.php'))){
339 ?>
340 <style type="text/css">
341 .srr_settings h4{
342 border-bottom: 1px solid #DFDFDF;
343 margin: 20px -11px 10px -11px;
344 padding: 5px 11px 5px 11px;
345 border-top: 1px solid #DFDFDF;
346 background-color: #fff;
347 background-image: -ms-linear-gradient(top,#fff,#f9f9f9);
348 background-image: -moz-linear-gradient(top,#fff,#f9f9f9);
349 background-image: -o-linear-gradient(top,#fff,#f9f9f9);
350 background-image: -webkit-gradient(linear,left top,left bottom,from(#fff),to(#f9f9f9));
351 background-image: -webkit-linear-gradient(top,#fff,#f9f9f9);
352 background-image: linear-gradient(top,#fff,#f9f9f9);
353 }
354 .srr_support{
355 border: 1px solid #DFDFDF;
356 padding: 5px 13px;
357 background: #F9F9F9;
358 text-decoration:none;
359 margin: 10px -13px;
360 }
361 .srr_support a{
362 text-decoration: none;
363 }
364 .srr_support a:hover{
365 text-decoration: underline;
366 }
367 .srr_smalltext{
368 font-size: 11px;
369 color: #666666;
370 }
371 .srr_support{
372 border: 1px solid #DFDFDF;
373 padding: 5px 13px;
374 background: #F9F9F9;
375 text-decoration:none;
376 margin: 10px -13px;
377 }
378 .srr_support a{
379 text-decoration: none;
380 }
381 .srr_support a:hover{
382 text-decoration: underline;
383 }
384 .srr_fblike{
385 background: url('<?php echo SRR_URL; ?>images/like-button.png') no-repeat;
386 padding-left: 19px;
387 }
388 .srr_fblike span{
389 display: none;
390 }
391 .srr_fblike:hover span{
392 display: inline;
393 padding:10px;
394 margin: -15px 0px 0px -50px;
395 position:absolute;
396 background:#ffffff;
397 border:1px solid #cccccc;
398 -webkit-box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.09);
399 -moz-box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.09);
400 box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.09);
401 -moz-border-radius: 5px;
402 border-radius: 5px;
403 }
404 </style>
405
406 <script type="text/javascript">
407 jQuery(document).ready(function(){
408 var social = '<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Faakashweb&amp;send=false&amp;layout=button_count&amp;width=75&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21&amp;appId=106994469342299" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:75px; height:21px;" allowTransparency="true"></iframe>';
409
410 jQuery('.srr_fblike').live('mouseenter', function(){
411 if(jQuery('.srr_fblike span').length == 0)
412 jQuery(this).prepend('<span>' + social + '</span>');
413 });
414
415 });
416 </script>
417
418 <?php
419 }
420 }
421 add_action('admin_footer', 'srr_widget_scripts');
422
423 ?>