PluginProbe
Super RSS Reader – Add attractive RSS Feed Widget / 3.2
Super RSS Reader – Add attractive RSS Feed Widget v3.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 / includes / feed.php

feed.php in Super RSS Reader – Add attractive RSS Feed Widget 3.2, at includes/feed.php

241 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Prepares the feed HTML
4 *
5 */
6
7 if( ! defined( 'ABSPATH' ) ) exit;
8
9 class SRR_Feed{
10
11 public $options = array();
12
13 public function __construct( $options ){
14
15 $this->options = wp_parse_args( $options, SRR_Options::default_options() );
16
17 }
18
19 public function html(){
20
21 $urls = stripslashes( trim( $this->options['urls'] ) );
22 $tab_titles = stripslashes( $this->options['tab_titles'] );
23 $count = intval( $this->options['count'] );
24
25 $show_date = intval( $this->options['show_date'] );
26 $show_desc = intval( $this->options['show_desc'] );
27 $show_author = intval( $this->options['show_author'] );
28 $show_thumb = stripslashes( $this->options['show_thumb'] );
29 $open_newtab = intval( $this->options['open_newtab'] );
30 $add_nofollow = intval( $this->options['add_nofollow'] );
31 $strip_desc = intval( $this->options['strip_desc'] );
32 $strip_title = intval( $this->options['strip_title'] );
33 $read_more = htmlspecialchars( $this->options['read_more'] );
34 $rich_desc = intval( $this->options['rich_desc'] );
35
36 $color_theme = stripslashes( $this->options['color_style'] );
37 $display_type = stripslashes( $this->options['display_type'] );
38 $visible_items = intval( $this->options['visible_items'] );
39 $ticker_speed = intval( $this->options['ticker_speed'] ) * 1000;
40
41 if( empty( $urls ) ){
42 return '';
43 }
44
45 $url_delim = strpos( $urls, ',' ) !== false ? ',' : "\n";
46 $tab_title_delim = strpos( $tab_titles, ',' ) !== false ? ',' : "\n";
47
48 $urls = explode( $url_delim, $urls );
49 $tab_titles = explode( $tab_title_delim, $tab_titles );
50 $url_count = count( $urls );
51
52 $feeds = array();
53 $html = '';
54
55 // Fetch the feed
56 for( $i=0; $i < $url_count; $i++ ){
57 $feed_url = trim( $urls[$i] );
58 $feed = fetch_feed( $feed_url );
59
60 if( is_wp_error( $feed ) ){
61 $feed_title = 'Error';
62 }else{
63 $feed_title = ( isset( $tab_titles[$i] ) && !empty( $tab_titles[$i] ) ) ? $tab_titles[$i] : esc_attr( strip_tags( $feed->get_title() ) );
64 }
65
66 $feeds[ $feed_url ] = array(
67 'id' => rand( 100, 999 ),
68 'feed' => $feed,
69 'title' => $feed_title
70 );
71 }
72
73 // Generate tabs
74 if( $url_count > 1 ){
75 $html .= '<ul class="srr-tab-wrap srr-tab-style-' . $color_theme . ' srr-clearfix">';
76 foreach( $feeds as $url => $data ){
77 $id = $data[ 'id' ];
78 $feed = $data[ 'feed' ];
79 if( is_wp_error( $feed ) ){
80 $html .= '<li data-tab="srr-tab-' . $id . '">Error</li>';
81 }else{
82 $html .= '<li data-tab="srr-tab-' . $id . '">' . $data[ 'title' ] . '</li>';
83 }
84 }
85 $html .= '</ul>';
86 }
87
88 // Generate feed items
89 foreach( $feeds as $url => $data ){
90
91 $id = $data[ 'id' ];
92 $feed = $data[ 'feed' ];
93
94 // Check for feed errors
95 if ( is_wp_error( $feed ) ){
96 $html .= '<div class="srr-wrap srr-style-' . $color_theme .'" data-id="srr-tab-' . $id . '"><p>RSS Error: ' . $feed->get_error_message() . '</p></div>';
97 continue;
98 }
99
100 if( method_exists( $feed, 'enable_order_by_date' ) ){
101 $feed->enable_order_by_date( false );
102 }
103
104 $max_items = $feed->get_item_quantity( $count );
105 $feed_items = $feed->get_items( 0, $max_items );
106
107 $classes = array( 'srr-wrap', 'srr-style-' . $color_theme );
108 if( $display_type == 'vertical_ticker' ) array_push( $classes, 'srr-vticker' );
109 $class = implode( ' ', $classes );
110
111 // Outer wrap start
112 $html .= '<div class="' . $class . '" data-visible="' . $visible_items . '" data-speed="' . $ticker_speed . '" data-id="srr-tab-' . $id . '">';
113 $html .= '<div>';
114
115 // Check feed items
116 if ( $max_items == 0 ){
117 $html .= '<div>No items.</div>';
118 }else{
119 $j=1;
120 // Loop through each feed item
121 foreach( $feed_items as $item ){
122
123 // Link
124 $link = $item->get_link();
125 while ( stristr( $link, 'http' ) != $link ){ $link = substr( $link, 1 ); }
126 $link = esc_url( strip_tags($link) );
127
128 // Title
129 $title = esc_attr( strip_tags( $item->get_title() ) );
130 $title_full = $title;
131
132 if ( empty( $title ) ){
133 $title = __( 'No Title', 'super-rss-reader' );
134 }
135
136 if( $strip_title > 0 && strlen( $title ) > $strip_title ){
137 $title = wp_trim_words( $title, $strip_title );
138 }
139
140 // Open links in new tab
141 $new_tab = $open_newtab ? ' target="_blank"' : '';
142
143 // Add no follow attribute
144 $no_follow = $add_nofollow ? ' rel="nofollow"' : '';
145
146 // Date
147 $date = $item->get_date( 'j F Y' );
148 $date_full = esc_attr( $item->get_date() );
149
150 // Thumbnail
151 $thumb = '';
152 if ( $show_thumb == 1 && $enclosure = $item->get_enclosure() ){
153 $thumb_url = $enclosure->get_thumbnail();
154 if( !empty( $thumb_url ) ){
155 $thumb = '<img src="' . $thumb_url . '" alt="' . $title_full . '" class="srr-thumb" align="left" />';
156 }
157 }
158
159 // Description
160 $desc = '';
161 if( $show_desc ){
162 if( $rich_desc ){
163 $desc = strip_tags( $item->get_description(), '<p><a><img><em><strong><font><strike><s><u><i>' );
164 }else{
165
166 $desc = str_replace( array( "\n", "\r" ), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
167 $read_more_link = '';
168
169 if( $strip_desc != 0 ){
170 $desc = wp_trim_words( $desc, $strip_desc );
171 $read_more_link = !empty( $read_more ) ? ' <a href="' . $link . '" title="Read more"' . $new_tab . $no_follow . '>' . $read_more . '</a>' : '';
172
173 if ( '[...]' == substr( $desc, -5 ) ){
174 $desc = substr( $desc, 0, -5 );
175 }elseif ( '[&hellip;]' != substr( $desc, -10 ) ){
176 $desc .= '';
177 }
178
179 $desc = esc_html( $desc );
180 }
181
182 $desc = $desc . $read_more_link;
183
184 }
185 }
186
187 // Author
188 $author = $item->get_author();
189 if ( is_object( $author ) ) {
190 $author = $author->get_name();
191 $author = esc_html( strip_tags( $author ) );
192 }
193
194 // Display the feed items
195 $html .= '<div class="srr-item ' . ( ( $j%2 == 0 ) ? 'even' : 'odd') . ' srr-clearfix">';
196 $html .= '<div class="srr-title"><a href="' . $link . '"' . $new_tab . $no_follow . ' title="' . $title_full . '">' . $title . '</a></div>';
197
198 $html .= '<div class="srr-meta">';
199 if( $show_date && !empty( $date ) ){
200 $html .= '<time class="srr-date" title="' . $date_full . '">' . $date . '</time>';
201 }
202
203 if( $show_author && !empty( $author ) ){
204 $html .= ' - <cite class="srr-author">' . $author . '</cite>';
205 }
206 $html .= '</div>';
207
208 if ( $show_thumb ){
209 $html .= $thumb;
210 }
211
212 if( $show_desc ){
213 $html .= '<div class="srr-summary srr-clearfix">';
214 $html .= $rich_desc ? $desc : ( '<p>' . $desc . '</p>' );
215 $html .= '</div>';
216 }
217
218 $html .= '</div>';
219 // End display
220
221 $j++;
222 }
223 }
224
225 // Outer wrap end
226 $html .= '</div></div>' ;
227
228 if ( !is_wp_error( $feed ) )
229 $feed->__destruct();
230
231 unset( $feed );
232
233 }
234
235 return $html;
236
237 }
238
239 }
240
241 ?>