PluginProbe
Super RSS Reader – Add attractive RSS Feed Widget / 2.2
Super RSS Reader – Add attractive RSS Feed Widget v2.2
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.2, at super-rss-reader.php

465 lines 18.3 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.2
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.2');
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 $show_thumb = stripslashes($instance['show_thumb']);
58 $open_newtab = intval($instance['open_newtab']);
59 $strip_desc = intval($instance['strip_desc']);
60 $read_more = htmlspecialchars($instance['read_more']);
61 $color_style = stripslashes($instance['color_style']);
62 $enable_ticker = intval($instance['enable_ticker']);
63 $visible_items = intval($instance['visible_items']);
64 $ticker_speed = intval($instance['ticker_speed']) * 1000;
65
66 if(empty($urls)){
67 return '';
68 }
69
70 $rand = array();
71 $url = explode(',', $urls);
72 $ucount = count($url);
73
74 // Generate the Tabs
75 if($ucount > 1){
76 echo '<ul class="srr-tab-wrap srr-tab-style-' . $color_style . ' srr-clearfix">';
77 for($i=0; $i<$ucount; $i++){
78 // Get the Feed URL
79 $feedUrl = trim($url[$i]);
80 $rss = fetch_feed($feedUrl);
81 $rand[$i] = rand(0, 999);
82
83 if (!is_wp_error($rss)){
84 $rss_title = esc_attr(strip_tags($rss->get_title()));
85 echo '<li data-tab="srr-tab-' . $rand[$i] . '">' . $rss_title . '</li>';
86 }else{
87 echo '<li data-tab="srr-tab-' . $rand[$i] . '">Error</li>';
88 }
89
90 }
91 echo '</ul>';
92 }
93
94 for($i=0; $i<$ucount; $i++){
95 // Get the Feed URL
96 $feedUrl = trim($url[$i]);
97 if(isset($url[$i])){
98 $rss = fetch_feed($feedUrl);
99 }else{
100 return '';
101 }
102
103 // Check for feed errors
104 if (!is_wp_error( $rss ) ){
105 $maxitems = $rss->get_item_quantity($count);
106 $rss_items = $rss->get_items(0, $maxitems);
107 $rss_title = esc_attr(strip_tags($rss->get_title()));
108 $rss_desc = esc_attr(strip_tags($rss->get_description()));
109 }else{
110 echo '<div class="srr-wrap srr-style-' . $color_style .'" data-id="srr-tab-' . $rand[$i] . '"><p>RSS Error: ' . $rss->get_error_message() . '</p></div>';
111 continue;
112 }
113
114 $randAttr = isset($rand[$i]) ? ' data-id="srr-tab-' . $rand[$i] . '" ' : '';
115
116 // Outer Wrap start
117 echo '<div class="srr-wrap ' . (($enable_ticker == 1 ) ? 'srr-vticker' : '' ) . ' srr-style-' . $color_style . '" data-visible="' . $visible_items . '" data-speed="' . $ticker_speed . '"' . $randAttr . '><div>';
118
119 // Check feed items
120 if ($maxitems == 0){
121 echo '<div>No items.</div>';
122 }else{
123 $j=1;
124 // Loop through each feed item
125 foreach ($rss_items as $item){
126 // Get the link
127 $link = $item->get_link();
128 while ( stristr($link, 'http') != $link ){ $link = substr($link, 1); }
129 $link = esc_url(strip_tags($link));
130
131 // Get the item title
132 $title = esc_attr(strip_tags($item->get_title()));
133 if ( empty($title) )
134 $title = __('No Title');
135
136 // Get the date
137 $date = $item->get_date('j F Y');
138
139 // Get thumbnail if present @since v2.2
140 $thumb = '';
141 if ($show_thumb == 1 && $enclosure = $item->get_enclosure()){
142 $thumburl = $enclosure->get_thumbnail();
143 if(!empty($thumburl))
144 $thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
145 }
146
147 // Get the description
148 $desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
149 if($strip_desc != 0){
150 $desc = wp_html_excerpt( $desc, $strip_desc );
151 $rmore = (!empty($read_more)) ? '<a href="' . $link . '" title="Read more">' . $read_more . '</a>' : '';
152
153 if ( '[...]' == substr( $desc, -5 ) )
154 $desc = substr( $desc, 0, -5 );
155 elseif ( '[&hellip;]' != substr( $desc, -10 ) )
156 $desc .= '';
157
158 $desc = esc_html( $desc );
159 }
160 $desc = $thumb . $desc . ' ' . $rmore;
161
162 // Get the author
163 $author = $item->get_author();
164 if ( is_object($author) ) {
165 $author = $author->get_name();
166 $author = esc_html(strip_tags($author));
167 }
168
169 // Open links in new tab
170 $newtab = ($open_newtab) ? ' target="_blank"' : '';
171
172 echo "\n\n\t";
173
174 // Display the feed items
175 echo '<div class="srr-item ' . (($j%2 == 0) ? 'even' : 'odd') . '">';
176 echo '<div class="srr-title"><a href="' . $link . '"' . $newtab . ' title="Posted on ' . $date . '">' .$title . '</a></div>';
177 echo '<div class="srr-meta">';
178
179 if($show_date && !empty($date))
180 echo '<time class="srr-date">' . $date . '</time>';
181
182 if($show_author && !empty($author))
183 echo ' - <cite class="srr-author">' . $author . '</cite>';
184
185 echo '</div>';
186
187 if($show_desc)
188 echo '<p class="srr-summary srr-clearfix">' . $desc . '</p>';
189
190 echo '</div>';
191 // End display
192
193 $j++;
194 }
195 }
196
197 // Outer wrap end
198 echo "\n\n</div>
199 </div> \n\n" ;
200
201 }
202 }
203
204 class super_rss_reader_widget extends WP_Widget{
205 ## Initialize
206 function super_rss_reader_widget(){
207 $widget_ops = array(
208 'classname' => 'widget_super_rss_reader',
209 'description' => "Enhanced RSS feed reader widget with advanced features."
210 );
211
212 $control_ops = array('width' => 430, 'height' => 500);
213 parent::WP_Widget('super_rss_reader', 'Super RSS Reader', $widget_ops, $control_ops);
214 }
215
216 ## Display the Widget
217 function widget($args, $instance){
218 extract($args);
219 if(empty($instance['title'])){
220 $title = '';
221 }else{
222 $title = $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title;
223 }
224
225 echo $before_widget . $title;
226 echo "\n" . '
227 <!-- Start - Super RSS Reader v' . SRR_VERSION . '-->
228 <div class="super-rss-reader-widget">' . "\n";
229
230 srr_rss_parser($instance);
231
232 echo "\n" . '</div>
233 <!-- End - Super RSS Reader -->
234 ' . "\n";
235 echo $after_widget;
236 }
237
238 ## Save settings
239 function update($new_instance, $old_instance){
240 $instance = $old_instance;
241 $instance['title'] = stripslashes($new_instance['title']);
242 $instance['urls'] = stripslashes($new_instance['urls']);
243
244 $instance['count'] = intval($new_instance['count']);
245 $instance['show_date'] = intval($new_instance['show_date']);
246 $instance['show_desc'] = intval($new_instance['show_desc']);
247 $instance['show_author'] = intval($new_instance['show_author']);
248 $instance['show_thumb'] = stripslashes($new_instance['show_thumb']);
249 $instance['open_newtab'] = intval($new_instance['open_newtab']);
250 $instance['strip_desc'] = intval($new_instance['strip_desc']);
251 $instance['read_more'] = stripslashes($new_instance['read_more']);
252
253 $instance['color_style'] = stripslashes($new_instance['color_style']);
254 $instance['enable_ticker'] = intval($new_instance['enable_ticker']);
255 $instance['visible_items'] = intval($new_instance['visible_items']);
256 $instance['ticker_speed'] = intval($new_instance['ticker_speed']);
257
258 return $instance;
259 }
260
261 ## HJA Widget form
262 function form($instance){
263 global $srr_color_styles;
264
265 $instance = wp_parse_args( (array) $instance, array(
266 'title' => '', 'urls' => '', 'count' => 5,
267 'show_date' => 0, 'show_desc' => 1, 'show_author' => 0, 'show_thumb' => 1,
268 'open_newtab' => 1, 'strip_desc' => 100, 'read_more' => '[...]',
269 'color_style' => 'none', 'enable_ticker' => 1, 'visible_items' => 5, 'ticker_speed' => 2,
270 ));
271
272 $title = htmlspecialchars($instance['title']);
273 $urls = htmlspecialchars($instance['urls']);
274
275 $count = intval($instance['count']);
276 $show_date = intval($instance['show_date']);
277 $show_desc = intval($instance['show_desc']);
278 $show_author = intval($instance['show_author']);
279 $show_thumb = intval($instance['show_thumb']);
280 $open_newtab = intval($instance['open_newtab']);
281 $strip_desc = intval($instance['strip_desc']);
282 $read_more = htmlspecialchars($instance['read_more']);
283
284 $color_style = stripslashes($instance['color_style']);
285 $enable_ticker = intval($instance['enable_ticker']);
286 $visible_items = intval($instance['visible_items']);
287 $ticker_speed = intval($instance['ticker_speed']);
288
289 ?>
290 <div class="srr_settings">
291 <table width="100%" height="72" border="0">
292 <tr>
293 <td width="13%" height="33"><label for="<?php echo $this->get_field_id('title'); ?>">Title: </label></td>
294 <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>
295 </tr>
296 <tr>
297 <td><label for="<?php echo $this->get_field_id('urls'); ?>">URLs: </label></td>
298 <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"/>
299 <small class="srr_smalltext">Can enter multiple RSS/atom feed URLs seperated by a comma.</small>
300 </td>
301 </tr>
302 </table>
303 </div>
304
305 <div class="srr_settings">
306 <h4>Settings</h4>
307 <table width="100%" border="0">
308 <tr>
309 <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>
310 <td width="40%"><label for="<?php echo $this->get_field_id('show_desc'); ?>">Show Description</label></td>
311 <td width="28%"><label for="<?php echo $this->get_field_id('count');?>">Count</label></td>
312 <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>
313 </tr>
314 <tr>
315 <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>
316 <td><label for="<?php echo $this->get_field_id('show_date'); ?>">Show Date</label></td>
317 <td><label for="<?php echo $this->get_field_id('strip_desc');?>">Strip description</label></td>
318 <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>
319 </tr>
320 <tr>
321 <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>
322 <td>Show Author</label></td>
323 <td><label for="<?php echo $this->get_field_id('read_more'); ?>">Read more text</label></td>
324 <td><input id="<?php echo $this->get_field_name('read_more'); ?>" name="<?php echo $this->get_field_name('read_more'); ?>" type="text" value="<?php echo $read_more; ?>" class="widefat" title="Leave blank to hide read more text"/></td>
325 </tr>
326 <tr>
327 <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>
328 <td><label for="<?php echo $this->get_field_id('open_newtab'); ?>">Open links in new tab</label></td>
329 <td><label for="<?php echo $this->get_field_id('show_thumb'); ?>">Show thumbnail if present</label></td>
330 <td><input id="<?php echo $this->get_field_id('show_thumb'); ?>" type="checkbox" name="<?php echo $this->get_field_name('show_thumb'); ?>" value="1" <?php echo $show_thumb == "1" ? 'checked="checked"' : ""; ?> /></td>
331 </tr>
332 </table>
333 </div>
334
335 <div class="srr_settings">
336 <h4>Other settings</h4>
337 <table width="100%" height="109" border="0">
338 <tr>
339 <td height="32"><label>Color style: </label></td>
340 <td>
341 <?php
342 echo '<select name="' . $this->get_field_name('color_style') . '" id="' . $this->get_field_id('color_style') . '">';
343 foreach($srr_color_styles as $k => $v){
344 echo '<option value="' . $v . '" ' . ($color_style == $v ? 'selected="selected"' : "") . '>' . $k . '</option>';
345 }
346 echo '</select>';
347 ?>
348 </td>
349 </tr>
350 <tr>
351 <td height="33"><label for="<?php echo $this->get_field_id('enable_ticker'); ?>">Ticker animation:</label> </td>
352 <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>
353 </tr>
354 <tr>
355 <td height="36"><label for="<?php echo $this->get_field_id('visible_items');?>">Visible items: </label></td>
356 <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."/>
357 </td>
358 </tr>
359 <tr>
360 <td height="36"><label for="<?php echo $this->get_field_id('ticker_speed');?>">Ticker speed: </label></td>
361 <td><input id="<?php echo $this->get_field_id('ticker_speed');?>" name="<?php echo $this->get_field_name('ticker_speed'); ?>" type="text" value="<?php echo $ticker_speed; ?>" title="Speed of the ticker in seconds"/> seconds
362 </td>
363 </tr>
364 </table>
365 </div>
366
367 <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>
368 <small>Please donate and share this plugin to show your support. Thank you :)</small>
369
370 <?php
371 }
372 }
373
374 function super_rss_reader_init(){
375 register_widget('super_rss_reader_widget');
376 }
377 add_action('widgets_init', 'super_rss_reader_init');
378
379 function srr_widget_scripts(){
380 if(in_array($GLOBALS['pagenow'], array('widgets.php'))){
381 ?>
382 <style type="text/css">
383 .srr_settings h4{
384 border-bottom: 1px solid #DFDFDF;
385 margin: 20px -11px 10px -11px;
386 padding: 5px 11px 5px 11px;
387 border-top: 1px solid #DFDFDF;
388 background-color: #fff;
389 background-image: -ms-linear-gradient(top,#fff,#f9f9f9);
390 background-image: -moz-linear-gradient(top,#fff,#f9f9f9);
391 background-image: -o-linear-gradient(top,#fff,#f9f9f9);
392 background-image: -webkit-gradient(linear,left top,left bottom,from(#fff),to(#f9f9f9));
393 background-image: -webkit-linear-gradient(top,#fff,#f9f9f9);
394 background-image: linear-gradient(top,#fff,#f9f9f9);
395 }
396 .srr_support{
397 border: 1px solid #DFDFDF;
398 padding: 5px 13px;
399 background: #F9F9F9;
400 text-decoration:none;
401 margin: 10px -13px;
402 }
403 .srr_support a{
404 text-decoration: none;
405 }
406 .srr_support a:hover{
407 text-decoration: underline;
408 }
409 .srr_smalltext{
410 font-size: 11px;
411 color: #666666;
412 }
413 .srr_support{
414 border: 1px solid #DFDFDF;
415 padding: 5px 13px;
416 background: #F9F9F9;
417 text-decoration:none;
418 margin: 10px -13px;
419 }
420 .srr_support a{
421 text-decoration: none;
422 }
423 .srr_support a:hover{
424 text-decoration: underline;
425 }
426 .srr_fblike{
427 background: url('<?php echo SRR_URL; ?>images/like-button.png') no-repeat;
428 padding-left: 19px;
429 }
430 .srr_fblike span{
431 display: none;
432 }
433 .srr_fblike:hover span{
434 display: inline;
435 padding:10px;
436 margin: -15px 0px 0px -50px;
437 position:absolute;
438 background:#ffffff;
439 border:1px solid #cccccc;
440 -webkit-box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.09);
441 -moz-box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.09);
442 box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.09);
443 -moz-border-radius: 5px;
444 border-radius: 5px;
445 }
446 </style>
447
448 <script type="text/javascript">
449 jQuery(document).ready(function(){
450 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>';
451
452 jQuery('.srr_fblike').live('mouseenter', function(){
453 if(jQuery('.srr_fblike span').length == 0)
454 jQuery(this).prepend('<span>' + social + '</span>');
455 });
456
457 });
458 </script>
459
460 <?php
461 }
462 }
463 add_action('admin_footer', 'srr_widget_scripts');
464
465 ?>