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

482 lines 23.0 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: https://www.aakashweb.com/wordpress-plugins/super-rss-reader/
5 * Author URI: https://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 separated in tabs. <a href="https://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.6
9 */
10
11 define('SRR_VERSION', '2.6');
12 define('SRR_URL', plugin_dir_url( __FILE__ ));
13
14 // Include the required scripts & styles
15 function srr_public_scripts(){
16 wp_enqueue_script('jquery-easy-ticker-js', 'https://cdn.rawgit.com/vaakash/jquery-easy-ticker/92e6e76c/jquery.easy-ticker.min.js', array( 'jquery', 'super-rss-reader-js' ));
17 wp_enqueue_script('super-rss-reader-js', SRR_URL . 'public/js/script.min.js', array( 'jquery' ));
18 wp_enqueue_style('super-rss-reader-css', SRR_URL . 'public/css/style.min.css');
19 }
20 add_action('wp_enqueue_scripts', 'srr_public_scripts');
21
22 // Default color styles
23 function srr_color_styles(){
24 return array(
25 'No style' => 'none',
26 'Grey' => 'grey',
27 'Dark' => 'dark',
28 'Orange' => 'orange',
29 'Simple modern' => 'smodern'
30 );
31 }
32
33 function srr_defaults(){
34 return array(
35 'title' => '',
36 'urls' => '',
37 'tab_titles' => '',
38 'count' => 5,
39 'show_date' => 0,
40 'show_desc' => 1,
41 'show_author' => 0,
42 'show_thumb' => 1,
43 'open_newtab' => 1,
44 'strip_desc' => 100,
45 'read_more' => '[...]',
46 'rich_desc' => 0 ,
47 'color_style' => 'none',
48 'enable_ticker' => 1,
49 'visible_items' => 5,
50 'strip_title' => 0,
51 'ticker_speed' => 4,
52 );
53 }
54
55 // The main RSS Parser
56 function srr_rss_parser($instance){
57
58 $instance = wp_parse_args($instance, srr_defaults());
59
60 $urls = stripslashes($instance['urls']);
61 $tab_titles = stripslashes($instance['tab_titles']);
62 $count = intval($instance['count']);
63
64 $show_date = intval($instance['show_date']);
65 $show_desc = intval($instance['show_desc']);
66 $show_author = intval($instance['show_author']);
67 $show_thumb = stripslashes($instance['show_thumb']);
68 $open_newtab = intval($instance['open_newtab']);
69 $strip_desc = intval($instance['strip_desc']);
70 $strip_title = intval($instance['strip_title']);
71 $read_more = htmlspecialchars($instance['read_more']);
72 $rich_desc = intval($instance['rich_desc']);
73
74 $color_style = stripslashes($instance['color_style']);
75 $enable_ticker = intval($instance['enable_ticker']);
76 $visible_items = intval($instance['visible_items']);
77 $ticker_speed = intval($instance['ticker_speed']) * 1000;
78
79 if(empty($urls)){
80 return '';
81 }
82
83 $rand = array();
84 $url = explode(',', $urls);
85 $tab_title = explode(',', $tab_titles);
86 $ucount = count($url);
87
88 // Generate the Tabs
89 if($ucount > 1){
90 echo '<ul class="srr-tab-wrap srr-tab-style-' . $color_style . ' srr-clearfix">';
91 for( $i=0; $i < $ucount; $i++ ){
92 // Get the Feed URL
93 $feedUrl = trim( $url[$i] );
94 $rss = fetch_feed( $feedUrl );
95 $rand[$i] = rand(0, 999);
96
97 if (!is_wp_error($rss)){
98
99 if( isset( $tab_title[$i] ) && !empty( $tab_title[$i]) ){
100 $rss_title = $tab_title[$i];
101 }else{
102 $rss_title = esc_attr(strip_tags($rss->get_title()));
103 }
104
105 echo '<li data-tab="srr-tab-' . $rand[$i] . '">' . $rss_title . '</li>';
106 }else{
107 echo '<li data-tab="srr-tab-' . $rand[$i] . '">Error</li>';
108 }
109
110 }
111 echo '</ul>';
112 }
113
114 for($i=0; $i<$ucount; $i++){
115 // Get the Feed URL
116 $feedUrl = trim($url[$i]);
117 if(isset($url[$i])){
118 $rss = fetch_feed($feedUrl);
119 }else{
120 return '';
121 }
122
123 if( method_exists( $rss, 'enable_order_by_date' ) ){
124 $rss->enable_order_by_date(false);
125 }
126
127 // Check for feed errors
128 if (!is_wp_error( $rss ) ){
129 $maxitems = $rss->get_item_quantity($count);
130 $rss_items = $rss->get_items(0, $maxitems);
131 $rss_title = esc_attr(strip_tags($rss->get_title()));
132 $rss_desc = esc_attr(strip_tags($rss->get_description()));
133 }else{
134 echo '<div class="srr-wrap srr-style-' . $color_style .'" data-id="srr-tab-' . $rand[$i] . '"><p>RSS Error: ' . $rss->get_error_message() . '</p></div>';
135 continue;
136 }
137
138 $randAttr = isset($rand[$i]) ? ' data-id="srr-tab-' . $rand[$i] . '" ' : '';
139
140 // Outer Wrap start
141 echo '<div class="srr-wrap ' . (($enable_ticker == 1 ) ? 'srr-vticker' : '' ) . ' srr-style-' . $color_style . '" data-visible="' . $visible_items . '" data-speed="' . $ticker_speed . '"' . $randAttr . '><div>';
142
143 // Check feed items
144 if ($maxitems == 0){
145 echo '<div>No items.</div>';
146 }else{
147 $j=1;
148 // Loop through each feed item
149 foreach ($rss_items as $item){
150 // Get the link
151 $link = $item->get_link();
152 while ( stristr($link, 'http') != $link ){ $link = substr($link, 1); }
153 $link = esc_url(strip_tags($link));
154
155 // Get the item title
156 $title = esc_attr(strip_tags($item->get_title()));
157 if ( empty($title) )
158 $title = __('No Title');
159
160 if( $strip_title != 0 ){
161 $titleLen = strlen($title);
162 $title = wp_html_excerpt( $title, $strip_title );
163 $title = ($titleLen > $strip_title) ? $title . ' ...' : $title;
164 }
165
166 // Open links in new tab
167 $newtab = ($open_newtab) ? ' target="_blank"' : '';
168
169 // Get the date
170 $date = $item->get_date('j F Y');
171
172 // Get thumbnail if present @since v2.2
173 $thumb = '';
174 if ($show_thumb == 1 && $enclosure = $item->get_enclosure()){
175 $thumburl = $enclosure->get_thumbnail();
176 if(!empty($thumburl))
177 $thumb = '<img src="' . $thumburl . '" alt="' . $title . '" class="srr-thumb" align="left"/>';
178 }
179
180 // Get the description
181 $desc = '';
182 if( $rich_desc == 1 ){
183
184 $desc = strip_tags( str_replace( 'eval', '', $item->get_description() ) , '<p><a><img><em><strong><font><strike><s><u><i>');
185
186 }else{
187 $rmore = '';
188 $desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
189 if($strip_desc != 0){
190 $desc = wp_html_excerpt( $desc, $strip_desc );
191 $rmore = (!empty($read_more)) ? '<a href="' . $link . '" title="Read more"' . $newtab . '>' . $read_more . '</a>' : '';
192
193 if ( '[...]' == substr( $desc, -5 ) )
194 $desc = substr( $desc, 0, -5 );
195 elseif ( '[&hellip;]' != substr( $desc, -10 ) )
196 $desc .= '';
197
198 $desc = esc_html( $desc );
199 }
200
201 $desc = $thumb . $desc . ' ' . $rmore;
202
203 }
204
205 // Get the author
206 $author = $item->get_author();
207 if ( is_object($author) ) {
208 $author = $author->get_name();
209 $author = esc_html(strip_tags($author));
210 }
211
212 echo "\n\n\t";
213
214 // Display the feed items
215 echo '<div class="srr-item ' . (($j%2 == 0) ? 'even' : 'odd') . '">';
216 echo '<div class="srr-title"><a href="' . $link . '"' . $newtab . ' title="Posted on ' . $date . '">' . $title . '</a></div>';
217 echo '<div class="srr-meta">';
218
219 if($show_date && !empty($date))
220 echo '<time class="srr-date">' . $date . '</time>';
221
222 if($show_author && !empty($author))
223 echo ' - <cite class="srr-author">' . $author . '</cite>';
224
225 echo '</div>';
226
227 if($show_desc)
228 echo '<p class="srr-summary srr-clearfix">' . $desc . '</p>';
229
230 echo '</div>';
231 // End display
232
233 $j++;
234 }
235 }
236
237 // Outer wrap end
238 echo "\n\n</div>
239 </div> \n\n" ;
240
241 if ( ! is_wp_error($rss) )
242 $rss->__destruct();
243
244 unset($rss);
245
246 }
247 }
248
249 class super_rss_reader_widget extends WP_Widget{
250 // Initialize
251 public function __construct(){
252 $widget_ops = array(
253 'classname' => 'widget_super_rss_reader',
254 'description' => 'Enhanced RSS feed reader widget with advanced features.'
255 );
256
257 $control_ops = array('width' => 500, 'height' => 500);
258 parent::__construct('super_rss_reader', 'Super RSS Reader', $widget_ops, $control_ops);
259 }
260
261 // Display the Widget
262 public function widget($args, $instance){
263 extract($args);
264 if(empty($instance['title'])){
265 $title = '';
266 }else{
267 $title = $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title;
268 }
269
270 echo $before_widget . $title;
271 echo "\n" . '
272 <!-- Start - Super RSS Reader v' . SRR_VERSION . '-->
273 <div class="super-rss-reader-widget">' . "\n";
274
275 srr_rss_parser($instance);
276
277 echo "\n" . '</div>
278 <!-- End - Super RSS Reader -->
279 ' . "\n";
280 echo $after_widget;
281 }
282
283 // Save settings
284 public function update($new_instance, $old_instance){
285 $instance = $old_instance;
286 $instance['title'] = stripslashes($new_instance['title']);
287 $instance['urls'] = stripslashes($new_instance['urls']);
288 $instance['tab_titles'] = stripslashes($new_instance['tab_titles']);
289
290 $instance['count'] = intval($new_instance['count']);
291 $instance['show_date'] = intval($new_instance['show_date']);
292 $instance['show_desc'] = intval($new_instance['show_desc']);
293 $instance['show_author'] = intval($new_instance['show_author']);
294 $instance['show_thumb'] = stripslashes($new_instance['show_thumb']);
295 $instance['open_newtab'] = intval($new_instance['open_newtab']);
296 $instance['strip_desc'] = intval($new_instance['strip_desc']);
297 $instance['strip_title'] = intval($new_instance['strip_title']);
298 $instance['read_more'] = stripslashes($new_instance['read_more']);
299 $instance['rich_desc'] = stripslashes($new_instance['rich_desc']);
300
301 $instance['color_style'] = stripslashes($new_instance['color_style']);
302 $instance['enable_ticker'] = intval($new_instance['enable_ticker']);
303 $instance['visible_items'] = intval($new_instance['visible_items']);
304 $instance['ticker_speed'] = intval($new_instance['ticker_speed']);
305
306 return $instance;
307 }
308
309 // HJA Widget form
310 public function form($instance){
311
312 $instance = wp_parse_args((array) $instance, srr_defaults());
313
314 $title = htmlspecialchars($instance['title']);
315 $urls = htmlspecialchars($instance['urls']);
316 $tab_titles = htmlspecialchars($instance['tab_titles']);
317
318 $count = intval($instance['count']);
319 $show_date = intval($instance['show_date']);
320 $show_desc = intval($instance['show_desc']);
321 $show_author = intval($instance['show_author']);
322 $show_thumb = intval($instance['show_thumb']);
323 $open_newtab = intval($instance['open_newtab']);
324 $strip_desc = intval($instance['strip_desc']);
325 $strip_title = intval($instance['strip_title']);
326 $read_more = htmlspecialchars($instance['read_more']);
327 $rich_desc = htmlspecialchars($instance['rich_desc']);
328
329 $color_style = stripslashes($instance['color_style']);
330 $enable_ticker = intval($instance['enable_ticker']);
331 $visible_items = intval($instance['visible_items']);
332 $ticker_speed = intval($instance['ticker_speed']);
333
334 ?>
335 <div class="srr_settings">
336 <table width="100%" height="72" border="0">
337 <tr>
338 <td width="13%" height="33"><label for="<?php echo $this->get_field_id('title'); ?>">Title: </label></td>
339 <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>
340 </tr>
341 <tr>
342 <td><label for="<?php echo $this->get_field_id('urls'); ?>">URLs: </label></td>
343 <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"/>
344 <small class="srr_smalltext">Can enter multiple RSS/atom feed URLs seperated by a comma.</small>
345 </td>
346 </tr>
347
348 <tr>
349 <td><label for="<?php echo $this->get_field_id('tab_titles'); ?>">Tab titles: </label></td>
350 <td><input id="<?php echo $this->get_field_id('tab_titles');?>" name="<?php echo $this->get_field_name('tab_titles'); ?>" type="text" value="<?php echo $tab_titles; ?>" class="widefat"/>
351 <small class="srr_smalltext">Enter corresponding tab titles seperated by a comma.</small>
352 </td>
353 </tr>
354
355 </table>
356 </div>
357
358 <div class="srr_settings">
359 <h4>Settings</h4>
360 <table width="100%" border="0">
361 <tr>
362 <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>
363 <td width="40%"><label for="<?php echo $this->get_field_id('show_desc'); ?>">Show Description</label></td>
364 <td width="28%"><label for="<?php echo $this->get_field_id('count');?>">Total items to show:</label></td>
365 <td width="25%"><input id="<?php echo $this->get_field_id('count');?>" name="<?php echo $this->get_field_name('count'); ?>" type="number" value="<?php echo $count; ?>" class="widefat" title="No of feed items to parse"/></td>
366 </tr>
367 <tr>
368 <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>
369 <td><label for="<?php echo $this->get_field_id('show_date'); ?>">Show Date</label></td>
370 <td><label for="<?php echo $this->get_field_id('strip_desc');?>">Strip description characters:</label></td>
371 <td><input id="<?php echo $this->get_field_id('strip_desc');?>" name="<?php echo $this->get_field_name('strip_desc'); ?>" type="number" value="<?php echo $strip_desc; ?>" class="widefat" title="The number of charaters to be displayed. Use 0 to disable stripping"/> </td>
372 </tr>
373 <tr>
374 <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>
375 <td><label for="<?php echo $this->get_field_id('show_author'); ?>">Show Author</label></td>
376 <td><label for="<?php echo $this->get_field_id('strip_title'); ?>">Strip title characters:</label></td>
377 <td><input id="<?php echo $this->get_field_id('strip_title');?>" name="<?php echo $this->get_field_name('strip_title'); ?>" type="number" value="<?php echo $strip_title; ?>" class="widefat" title="The number of charaters to be displayed. Use 0 to disable stripping"/></td>
378 </tr>
379 <tr>
380 <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>
381 <td><label for="<?php echo $this->get_field_id('open_newtab'); ?>">Open links in new tab</label></td>
382 <td><label for="<?php echo $this->get_field_id('read_more'); ?>">Read more text:</label></td>
383 <td><input id="<?php echo $this->get_field_id('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>
384 </tr>
385 <tr>
386 <td height="29"><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>
387 <td><label for="<?php echo $this->get_field_id('show_thumb'); ?>">Show thumbnail if present</label></td>
388 <td>&nbsp;</td>
389 <td>&nbsp;</td>
390 </tr>
391
392 <tr>
393 <td height="29"><input id="<?php echo $this->get_field_id('rich_desc'); ?>" type="checkbox" name="<?php echo $this->get_field_name('rich_desc'); ?>" value="1" <?php echo $rich_desc == "1" ? 'checked="checked"' : ""; ?> /></td>
394 <td><label for="<?php echo $this->get_field_id('rich_desc'); ?>">Enable full or rich description</label></td>
395 <td>&nbsp;</td>
396 <td>&nbsp;</td>
397 </tr>
398
399 </table>
400 </div>
401
402 <?php if( $rich_desc == 1 ): ?>
403 <span class="srr_note">Note: You have enabled "Full/Rich HTML" Please make sure that the feed(s) are from trusted sources and do not contain any harmful scripts. If there are some aligment issues in the description, please use custom CSS to fix that. </span>
404 <?php endif; ?>
405
406 <div class="srr_settings">
407 <h4>Other settings</h4>
408 <table width="100%" height="109" border="0">
409 <tr>
410 <td height="32"><label for="<?php echo $this->get_field_id('color_style');?>">Color style: </label></td>
411 <td>
412 <?php
413 $color_styles = srr_color_styles();
414 echo '<select name="' . $this->get_field_name('color_style') . '" id="' . $this->get_field_id('color_style') . '">';
415 foreach($color_styles as $k => $v){
416 echo '<option value="' . $v . '" ' . ($color_style == $v ? 'selected="selected"' : "") . '>' . $k . '</option>';
417 }
418 echo '</select>';
419 ?>
420 </td>
421 </tr>
422 <tr>
423 <td height="36"><label for="<?php echo $this->get_field_id('visible_items');?>">Widget height:</label></td>
424 <td><input id="<?php echo $this->get_field_id('visible_items');?>" name="<?php echo $this->get_field_name('visible_items'); ?>" type="number" value="<?php echo $visible_items; ?>" title="Height of the RSS feed."/><br/>
425 <small>Set value less than 20 to show visible feed items. Example: <b>5</b> items</small></br>
426 <small>Set value greater than 20 for fixed widget height. Example: <b>400</b> px</small></br>
427 </td>
428 </tr>
429 <tr>
430 <td height="33"><label for="<?php echo $this->get_field_id('enable_ticker'); ?>">Ticker animation:</label> </td>
431 <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>
432 </tr>
433 <tr>
434 <td height="36"><label for="<?php echo $this->get_field_id('ticker_speed');?>">Ticker speed: </label></td>
435 <td><input id="<?php echo $this->get_field_id('ticker_speed');?>" name="<?php echo $this->get_field_name('ticker_speed'); ?>" type="number" value="<?php echo $ticker_speed; ?>" title="Speed of the ticker in seconds"/> seconds
436 </td>
437 </tr>
438 </table>
439 </div>
440
441 <div class="srr_coffee">
442 <p>Thank you for using Super RSS Reader. If you found it useful, please buy me a coffee !</p>
443 <div class="srr_coffee_wrap">
444 <p><select class="srr_coffee_amt">
445 <option value="2">$2</option>
446 <option value="3">$3</option>
447 <option value="4">$4</option>
448 <option value="5" selected="selected">$5</option>
449 <option value="6">$6</option>
450 <option value="7">$7</option>
451 <option value="8">$8</option>
452 <option value="9">$9</option>
453 <option value="10">$10</option>
454 <option value="11">$11</option>
455 <option value="12">$12</option>
456 <option value="">Custom</option>
457 </select></p>
458 <a class="button button-primary srr_coffee_btn" href="https://www.paypal.me/vaakash/5" data-link="https://www.paypal.me/vaakash/" target="_blank">Buy me a coffee !</a>
459 </div>
460 </div>
461
462 <p><a href="https://goo.gl/PB1oR6" target="_blank">Report issue</a> | <a href="https://goo.gl/7gCKb8" target="_blank">Rate 5 stars & review</a> | v<?php echo SRR_VERSION; ?></p>
463
464 <?php
465 }
466 }
467
468 function super_rss_reader_init(){
469 register_widget('super_rss_reader_widget');
470 }
471 add_action('widgets_init', 'super_rss_reader_init');
472
473
474 function srr_admin_scripts( $hook ){
475 if( $hook == 'widgets.php' ){
476 wp_enqueue_style( 'srr_admin_css', SRR_URL . 'admin/css/style.css' );
477 wp_enqueue_script( 'srr_admin_js', SRR_URL . 'admin/js/script.js' );
478 }
479 }
480 add_action( 'admin_enqueue_scripts', 'srr_admin_scripts' );
481
482 ?>