PluginProbe
Super RSS Reader – Add attractive RSS Feed Widget / 4.5
Super RSS Reader – Add attractive RSS Feed Widget v4.5
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
← All changes | includes/feed.php +169 -38 3.24.5 View file →
@@ -11,9 +11,9 @@
11 11 public $options = array();
12 12
13 13 public function __construct( $options ){
14 14
15 - $this->options = wp_parse_args( $options, SRR_Options::default_options() );
15 + $this->options = wp_parse_args( $options, SRR_Options::defaults() );
16 16
17 17 }
18 18
19 19 public function html(){
@@ -29,11 +29,18 @@
29 29 $open_newtab = intval( $this->options['open_newtab'] );
30 30 $add_nofollow = intval( $this->options['add_nofollow'] );
31 31 $strip_desc = intval( $this->options['strip_desc'] );
32 32 $strip_title = intval( $this->options['strip_title'] );
33 + $date_format = htmlspecialchars( $this->options['date_format'] );
34 + $order_by = htmlspecialchars( $this->options['order_by'] );
33 35 $read_more = htmlspecialchars( $this->options['read_more'] );
34 36 $rich_desc = intval( $this->options['rich_desc'] );
35 -
37 + $desc_type = htmlspecialchars( $this->options['desc_type'] );
38 + $thumbnail_position = htmlspecialchars( $this->options['thumbnail_position'] );
39 + $thumbnail_size = htmlspecialchars( $this->options['thumbnail_size'] );
40 + $thumbnail_default = htmlspecialchars( $this->options['thumbnail_default'] );
41 + $no_feed_text = htmlspecialchars( $this->options['no_feed_text'] );
42 +
36 43 $color_theme = stripslashes( $this->options['color_style'] );
37 44 $display_type = stripslashes( $this->options['display_type'] );
38 45 $visible_items = intval( $this->options['visible_items'] );
39 46 $ticker_speed = intval( $this->options['ticker_speed'] ) * 1000;
@@ -50,9 +57,14 @@
50 57 $url_count = count( $urls );
51 58
52 59 $feeds = array();
53 60 $html = '';
61 + $no_feed_html = '<div>' . $no_feed_text . '</div>';
54 62
63 + $classes = array( 'srr-wrap', 'srr-style-' . $color_theme );
64 + if( $display_type == 'vertical_ticker' ) array_push( $classes, 'srr-vticker' );
65 + $class = implode( ' ', $classes );
66 +
55 67 // Fetch the feed
56 68 for( $i=0; $i < $url_count; $i++ ){
57 69 $feed_url = trim( $urls[$i] );
58 70 $feed = fetch_feed( $feed_url );
@@ -97,27 +109,30 @@
97 109 continue;
98 110 }
99 111
100 112 if( method_exists( $feed, 'enable_order_by_date' ) ){
101 - $feed->enable_order_by_date( false );
113 + if( in_array( $order_by, array( 'date', 'date_reverse' ) ) ){
114 + $feed->enable_order_by_date( true );
115 + }else{
116 + $feed->enable_order_by_date( false );
117 + }
102 118 }
103 119
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 120 // Outer wrap start
112 121 $html .= '<div class="' . $class . '" data-visible="' . $visible_items . '" data-speed="' . $ticker_speed . '" data-id="srr-tab-' . $id . '">';
113 122 $html .= '<div>';
114 123
124 + $max_items = $feed->get_item_quantity();
125 +
115 126 // Check feed items
116 127 if ( $max_items == 0 ){
117 - $html .= '<div>No items.</div>';
128 + $html .= $no_feed_html;
118 129 }else{
130 +
131 + $feed_items = $feed->get_items();
132 + $feed_items = $this->process_items( $feed_items, $count, $order_by );
119 133 $j=1;
134 +
120 135 // Loop through each feed item
121 136 foreach( $feed_items as $item ){
122 137
123 138 // Link
@@ -140,20 +155,40 @@
140 155 // Open links in new tab
141 156 $new_tab = $open_newtab ? ' target="_blank"' : '';
142 157
143 158 // Add no follow attribute
144 - $no_follow = $add_nofollow ? ' rel="nofollow"' : '';
159 + $no_follow = $add_nofollow ? ' rel="nofollow noopener noreferrer"' : '';
145 160
146 161 // Date
147 - $date = $item->get_date( 'j F Y' );
162 + $date = '';
148 163 $date_full = esc_attr( $item->get_date() );
149 164
165 + if( strtolower( $date_format ) == 'relative' ){
166 + $item_date = $item->get_date( 'U' );
167 + if( $item_date ){
168 + $date = human_time_diff( $item_date, current_time( 'U' ) ) . ' ' . __( 'ago' );
169 + }else{
170 + $date = __( 'Today' );
171 + }
172 + }else{
173 + $date = date_i18n( $date_format, $item->get_date( 'U' ) );
174 + }
175 +
150 176 // Thumbnail
151 177 $thumb = '';
152 - if ( $show_thumb == 1 && $enclosure = $item->get_enclosure() ){
153 - $thumb_url = $enclosure->get_thumbnail();
178 + if ( $show_thumb == 1 ){
179 + $thumb_url = $this->get_thumbnail_url( $item, $thumbnail_default );
180 + $thumb_url = apply_filters( 'srr_mod_thumbnail_url', $thumb_url, $item, $feed, $thumbnail_default );
154 181 if( !empty( $thumb_url ) ){
155 - $thumb = '<img src="' . $thumb_url . '" alt="' . $title_full . '" class="srr-thumb" align="left" />';
182 + $thumb_styles = array(
183 + 'width' => $thumbnail_size,
184 + 'height' => $thumbnail_size
185 + );
186 + $thumb_style = '';
187 + foreach( $thumb_styles as $prop => $val ){
188 + $thumb_style .= "$prop:$val;";
189 + }
190 + $thumb = '<a href="' . $link . '" class="srr-thumb srr-thumb-' . $thumbnail_position . '" style="' . $thumb_style . '" ' . $new_tab . $no_follow . '><img src="' . $thumb_url . '" alt="' . $title_full . '" align="left" /></a>';
156 191 }
157 192 }
158 193
159 194 // Description
@@ -158,18 +193,19 @@
158 193
159 194 // Description
160 195 $desc = '';
161 196 if( $show_desc ){
197 + $desc_content = ( $desc_type == 'summary' ) ? $item->get_description() : $item->get_content();
162 198 if( $rich_desc ){
163 - $desc = strip_tags( $item->get_description(), '<p><a><img><em><strong><font><strike><s><u><i>' );
199 + $desc = strip_tags( $desc_content, '<p><a><img><em><strong><font><strike><s><u><i>' );
164 200 }else{
165 201
166 - $desc = str_replace( array( "\n", "\r" ), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
202 + $desc = str_replace( array( "\n", "\r" ), ' ', esc_attr( strip_tags( @html_entity_decode( $desc_content, ENT_QUOTES, get_option('blog_charset') ) ) ) );
167 203 $read_more_link = '';
168 204
169 205 if( $strip_desc != 0 ){
170 206 $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>' : '';
207 + $read_more_link = !empty( $read_more ) ? ' <a href="' . $link . '" title="' . __( 'Read more', 'super-rss-reader' ) . '"' . $new_tab . $no_follow . ' class="srr-read-more">' . $read_more . '</a>' : '';
172 208
173 209 if ( '[...]' == substr( $desc, -5 ) ){
174 210 $desc = substr( $desc, 0, -5 );
175 211 }elseif ( '[&hellip;]' != substr( $desc, -10 ) ){
@@ -178,9 +214,12 @@
178 214
179 215 $desc = esc_html( $desc );
180 216 }
181 217
182 - $desc = $desc . $read_more_link;
218 + $desc = trim( $desc );
219 + if( !empty( $desc ) ){
220 + $desc = $desc . $read_more_link;
221 + }
183 222
184 223 }
185 224 }
186 225
@@ -190,43 +229,76 @@
190 229 $author = $author->get_name();
191 230 $author = esc_html( strip_tags( $author ) );
192 231 }
193 232
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>';
233 + $t_title = '';
234 + $t_meta = '';
235 + $t_thumb = '';
236 + $t_desc = '';
197 237
198 - $html .= '<div class="srr-meta">';
199 - if( $show_date && !empty( $date ) ){
200 - $html .= '<time class="srr-date" title="' . $date_full . '">' . $date . '</time>';
201 - }
238 + $t_title .= '<div class="srr-title"><a href="' . $link . '"' . $new_tab . $no_follow . ' title="' . $title_full . '">' . $title . '</a></div>';
202 239
203 - if( $show_author && !empty( $author ) ){
204 - $html .= ' - <cite class="srr-author">' . $author . '</cite>';
240 + // Metadata
241 + if( $show_date || $show_author ){
242 + $t_meta .= '<div class="srr-meta">';
243 + if( $show_date && !empty( $date ) ){
244 + $t_meta .= '<time class="srr-date" title="' . $date_full . ' UTC">' . $date . '</time>';
245 + }
246 +
247 + if( $show_author && !empty( $author ) ){
248 + $t_meta .= ' - <cite class="srr-author">' . $author . '</cite>';
249 + }
250 + $t_meta .= '</div>'; // End meta
205 251 }
206 - $html .= '</div>';
207 252
208 253 if ( $show_thumb ){
209 - $html .= $thumb;
254 + $t_thumb .= $thumb;
210 255 }
211 256
212 - if( $show_desc ){
213 - $html .= '<div class="srr-summary srr-clearfix">';
214 - $html .= $rich_desc ? $desc : ( '<p>' . $desc . '</p>' );
215 - $html .= '</div>';
257 + if( $show_desc && !empty( $desc ) ){
258 + $t_desc .= '<div class="srr-summary srr-clearfix">';
259 + $t_desc .= $rich_desc ? $desc : ( '<p>' . $desc . '</p>' );
260 + $t_desc .= '</div>'; // End summary
216 261 }
217 262
218 - $html .= '</div>';
219 - // End display
263 + $f_data = apply_filters( 'srr_mod_item_html', array(
264 + 'title' => $t_title,
265 + 'meta' => $t_meta,
266 + 'thumbnail' => $t_thumb,
267 + 'description' => $t_desc,
268 + 'before' => '',
269 + 'after' => ''
270 + ), $url, $item );
220 271
272 + $f_title = !isset( $f_data[ 'title' ] ) ? '' : $f_data[ 'title' ];
273 + $f_meta = !isset( $f_data[ 'meta' ] ) ? '' : $f_data[ 'meta' ];
274 + $f_thumb = !isset( $f_data[ 'thumbnail' ] ) ? '' : $f_data[ 'thumbnail' ];
275 + $f_desc = !isset( $f_data[ 'description' ] ) ? '' : $f_data[ 'description' ];
276 + $f_before = !isset( $f_data[ 'before' ] ) ? '' : $f_data[ 'before' ];
277 + $f_after = !isset( $f_data[ 'after' ] ) ? '' : $f_data[ 'after' ];
278 +
279 + // Display the feed items
280 + $html .= '<div class="srr-item ' . ( ( $j%2 == 0 ) ? 'srr-stripe' : '') . '">';
281 + $html .= '<div class="srr-clearfix">';
282 + $html .= $f_before;
283 + $html .= $f_title . $f_meta . $f_thumb . $f_desc;
284 + $html .= $f_after;
285 + $html .= '</div>'; // End item inner clearfix
286 + $html .= '</div>'; // End feed item
287 +
221 288 $j++;
222 289 }
290 +
291 + if( $j == 1 ){
292 + $html .= $no_feed_html;
293 + }
294 +
223 295 }
224 296
225 297 // Outer wrap end
226 298 $html .= '</div></div>' ;
227 299
228 - if ( !is_wp_error( $feed ) )
300 + if( !is_wp_error( $feed ) )
229 301 $feed->__destruct();
230 302
231 303 unset( $feed );
232 304
@@ -231,9 +303,68 @@
231 303 unset( $feed );
232 304
233 305 }
234 306
307 + $html = '<div class="srr-main">' . $html . '</div>';
308 +
235 309 return $html;
310 +
311 + }
312 +
313 + function process_items( $items, $count, $order_by ){
314 +
315 + if( count( $items ) == 0 ){
316 + return $items;
317 + }
318 +
319 + // For shuffle order - Shuffle first and then slice as per count
320 + if( $order_by == 'random' ){
321 + shuffle( $items );
322 + return array_slice( $items, 0, $count );
323 + }
324 +
325 + // For date based order - slice first and then order
326 + $items = array_slice( $items, 0, $count );
327 +
328 + if( $order_by == 'date_reverse' ){
329 + $items = array_reverse( $items );
330 + }
331 +
332 + return $items;
333 +
334 + }
335 +
336 + function get_thumbnail_url( $item, $thumbnail_default ){
337 +
338 + // Try to get from the item enclosure
339 + $enclosure = $item->get_enclosure();
340 +
341 + if ( $enclosure->get_thumbnail() ) {
342 + return $enclosure->get_thumbnail();
343 + }
344 +
345 + if ( $enclosure->get_link() ) {
346 + return $enclosure->get_link();
347 + }
348 +
349 + // Try to get from item content
350 + $content = $item->get_content();
351 +
352 + preg_match_all('~<img.*?src=["\']+(.*?)["\']+~', $content, $urls);
353 + $urls = $urls[1];
354 +
355 + if( !empty( $urls ) ){
356 + return $urls[0];
357 + }
358 +
359 + // Try to get the image tag finally if available
360 + $image = $item->get_item_tags( '', 'image' );
361 +
362 + if( isset( $image[0]['data'] ) ){
363 + return $image[0]['data'];
364 + }
365 +
366 + return trim( $thumbnail_default );
236 367
237 368 }
238 369
239 370 }