FEEDZY RSS Feeds Lite - Version 3.0.8

Version Description

  • 20/02/2017 =
  • Added $sizes param to feedzy_thumb_output.
  • Added check when title is empty.
  • Fixed image encoding url.
Download this release

Release Info

Developer codeinwp
Plugin Icon 128x128 FEEDZY RSS Feeds Lite
Version 3.0.8
Comparing to
See all releases

Code changes from version 3.0.7 to 3.0.8

CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
 
 
 
 
2
- Added sizes param to feedzy_thumb_output.
3
- Dont show items with empty title.
4
 
5
 
6
 
7
- Fixed is_new when pro is active.
1
 
2
+
3
+
4
+
5
+
6
+
7
 
8
 
9
 
 
css/feedzy-rss-feeds.css CHANGED
@@ -2,7 +2,7 @@
2
  * feedzy-rss-feeds.css
3
  * Feedzy RSS Feed
4
  * Copyright: (c) 2016 Themeisle, themeisle.com
5
- * Version: 3.0.7
6
  * Plugin Name: FEEDZY RSS Feeds
7
  * Plugin URI: http://themeisle.com/plugins/feedzy-rss-feeds/
8
  * Author: Themeisle
@@ -48,7 +48,7 @@
48
 
49
  /*noinspection CssUnusedSymbol*/
50
  .feedzy-rss .rss_item .rss_image .fetched {
51
- z-index: 999;
52
  }
53
 
54
  .feedzy-rss .rss_item .rss_image {
2
  * feedzy-rss-feeds.css
3
  * Feedzy RSS Feed
4
  * Copyright: (c) 2016 Themeisle, themeisle.com
5
+ * Version: 3.0.8
6
  * Plugin Name: FEEDZY RSS Feeds
7
  * Plugin URI: http://themeisle.com/plugins/feedzy-rss-feeds/
8
  * Author: Themeisle
48
 
49
  /*noinspection CssUnusedSymbol*/
50
  .feedzy-rss .rss_item .rss_image .fetched {
51
+ z-index: 9;
52
  }
53
 
54
  .feedzy-rss .rss_item .rss_image {
feedzy-rss-feed.php CHANGED
@@ -15,7 +15,7 @@
15
  * Plugin Name: Feedzy RSS Feeds Lite
16
  * Plugin URI: https://themeisle.com/plugins/feedzy-rss-feeds-lite/
17
  * Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
18
- * Version: 3.0.7
19
  * Author: Themeisle
20
  * Author URI: http://themeisle.com
21
  * License: GPL-2.0+
15
  * Plugin Name: Feedzy RSS Feeds Lite
16
  * Plugin URI: https://themeisle.com/plugins/feedzy-rss-feeds-lite/
17
  * Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
18
+ * Version: 3.0.8
19
  * Author: Themeisle
20
  * Author URI: http://themeisle.com
21
  * License: GPL-2.0+
includes/abstract/feedzy-rss-feeds-admin-abstract.php CHANGED
@@ -8,6 +8,7 @@
8
  * @package feedzy-rss-feeds
9
  * @subpackage feedzy-rss-feeds/includes/abstract
10
  */
 
11
  /**
12
  * The Feedzy RSS functions of the plugin.
13
  *
@@ -20,17 +21,19 @@
20
  */
21
  abstract class Feedzy_Rss_Feeds_Admin_Abstract {
22
 
23
-
24
  /**
25
  * Defines the default image to use on RSS Feeds
26
  *
27
  * @since 3.0.0
28
  * @access public
 
29
  * @param string $imageSrc The image source, currently not used.
 
30
  * @return string
31
  */
32
  public function feedzy_define_default_image( $imageSrc ) {
33
  $defaultImg = FEEDZY_ABSURL . '/img/feedzy-default.jpg';
 
34
  return apply_filters( 'feedzy_define_default_image_filter', $defaultImg );
35
  }
36
 
@@ -42,12 +45,15 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
42
  *
43
  * @since 3.0.0
44
  * @access public
 
45
  * @param object $error The error Object.
46
  * @param string $feedURL The feed URL.
 
47
  * @return string
48
  */
49
- public function feedzy_default_error_notice( $error, $feedURL ) {
50
  error_log( 'Feedzy RSS Feeds - related feed: ' . print_r( $feedURL ) . ' - Error message: ' . $this->feedzy_array_obj_string( $error ) );
 
51
  return '<div id="message" class="error" data-error"' . esc_attr( $this->feedzy_array_obj_string( $error ) ) . '"><p>' . __( 'Sorry, this feed is currently unavailable or does not exists anymore.', 'feedzy-rss-feeds' ) . '</p></div>';
52
  }
53
 
@@ -56,7 +62,9 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
56
  *
57
  * @since 3.0.0
58
  * @access public
 
59
  * @param object $error The error Object.
 
60
  * @return string
61
  */
62
  public function feedzy_array_obj_string( $error ) {
@@ -72,14 +80,17 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
72
  *
73
  * @since 3.0.0
74
  * @access public
75
- * @param string $itemAttr The item attribute.
76
- * @param array $sizes An array with the current sizes.
 
 
77
  * @return string
78
  */
79
  public function feedzy_add_item_padding( $itemAttr, $sizes ) {
80
- $paddinTop = number_format( ( 15 / 150 ) * $sizes['height'], 0 );
81
  $paddinBottom = number_format( ( 25 / 150 ) * $sizes['height'], 0 );
82
  $stylePadding = ' style="padding: ' . $paddinTop . 'px 0 ' . $paddinBottom . 'px"';
 
83
  return $itemAttr . $stylePadding;
84
  }
85
 
@@ -88,220 +99,29 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
88
  *
89
  * @since 3.0.0
90
  * @access public
91
- * @param string $itemAttr The item attribute.
 
 
92
  * @return string
93
  */
94
  public function feedzy_classes_item( $itemAttr = '', $sizes = '', $item = '', $feedURL = '', $sc = '' ) {
95
  $classes = array( 'rss_item' );
96
  $classes = apply_filters( 'feedzy_add_classes_item', $classes, $sc );
97
  $classes = ' class="' . implode( ' ', $classes ) . '"';
98
- return $itemAttr . $classes;
99
- }
100
-
101
- /**
102
- * Retrive image from the item object
103
- *
104
- * @since 3.0.0
105
- * @access public
106
- * @param object $item The item object.
107
- * @return string
108
- */
109
- public function feedzy_retrieve_image( $item ) {
110
- $theThumbnail = '';
111
- if ( $enclosures = $item->get_enclosures() ) {
112
- foreach ( (array) $enclosures as $enclosure ) {
113
- // Item thumbnail
114
- if ( $thumbnail = $enclosure->get_thumbnail() ) {
115
- $theThumbnail = $thumbnail;
116
- }
117
-
118
- if ( isset( $enclosure->thumbnails ) ) {
119
- foreach ( (array) $enclosure->thumbnails as $thumbnail ) {
120
- $theThumbnail = $thumbnail;
121
- }
122
- }
123
-
124
- if ( $thumbnail = $enclosure->embed() ) {
125
- $pattern = '/https?:\/\/.*\.(?:jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/iU';
126
- if ( preg_match( $pattern, $thumbnail, $matches ) ) {
127
- $theThumbnail = $matches[0];
128
- }
129
- }
130
-
131
- foreach ( (array) $enclosure->get_link() as $thumbnail ) {
132
- $pattern = '/https?:\/\/.*\.(?:jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/iU';
133
- $imgsrc = $thumbnail;
134
-
135
- if ( preg_match( $pattern, $imgsrc, $matches ) ) {
136
- $theThumbnail = $matches[0];
137
- break;
138
- }
139
- }
140
-
141
- // Break loop if thumbnail is found
142
- if ( ! empty( $theThumbnail ) ) {
143
- break;
144
- }
145
- }
146
- }
147
-
148
- // xmlns:itunes podcast
149
- if ( empty( $theThumbnail ) ) {
150
- $data = $item->get_item_tags( 'http://www.itunes.com/dtds/podcast-1.0.dtd', 'image' );
151
- if ( isset( $data['0']['attribs']['']['href'] ) && ! empty( $data['0']['attribs']['']['href'] ) ) {
152
- $theThumbnail = $data['0']['attribs']['']['href'];
153
- }
154
- }
155
-
156
- // Content image
157
- if ( empty( $theThumbnail ) ) {
158
- $feedDescription = $item->get_content();
159
- $theThumbnail = $this->feedzy_return_image( $feedDescription );
160
- }
161
-
162
- // Description image
163
- if ( empty( $theThumbnail ) ) {
164
- $feedDescription = $item->get_description();
165
- $theThumbnail = $this->feedzy_return_image( $feedDescription );
166
- }
167
-
168
- return $theThumbnail;
169
- }
170
-
171
- /**
172
- * Get an image from a string
173
- *
174
- * @since 3.0.0
175
- * @access public
176
- * @param string $string A string with an <img/> tag.
177
- * @return string
178
- */
179
- public function feedzy_return_image( $string ) {
180
- $img = html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );
181
- $pattern = '/<img[^>]+\>/i';
182
- preg_match( $pattern, $img, $matches );
183
- if ( isset( $matches[0] ) ) {
184
- $blacklistCount = 0;
185
- foreach ( $matches as $matche ) {
186
- $link = $this->feedzy_scrape_image( $matche );
187
- $blacklist = array();
188
- $blacklist = apply_filters( 'feedzy_feed_blacklist_images', $this->feedzy_blacklist_images( $blacklist ) );
189
- foreach ( $blacklist as $string ) {
190
- if ( strpos( (string) $link, $string ) !== false ) {
191
- $blacklistCount++;
192
- }
193
- }
194
- if ( $blacklistCount == 0 ) { break;
195
- }
196
- }
197
- if ( $blacklistCount == 0 ) { return $link;
198
- }
199
- }
200
- return '';
201
- }
202
 
203
- /**
204
- * Scrape an image for link from a string with an <img/>
205
- *
206
- * @since 3.0.0
207
- * @access public
208
- * @param string $string A string with an <img/> tag.
209
- * @param string $link The link to search for.
210
- * @return string
211
- */
212
- public function feedzy_scrape_image( $string, $link = '' ) {
213
- $pattern = '/src=[\'"]?([^\'" >]+)[\'" >]/';
214
- preg_match( $pattern, $string, $link );
215
- if ( isset( $link[1] ) ) {
216
- $link = urldecode( $link[1] );
217
- }
218
- return $link;
219
  }
220
 
221
  /**
222
- * List blacklisted images to prevent fetching emoticons
223
  *
224
  * @since 3.0.0
225
  * @access public
226
- * @param array $blacklist An array with blacklisted resources.
227
- * @return array
228
- */
229
- public function feedzy_blacklist_images( $blacklist ) {
230
- $blacklist = array(
231
- 'frownie.png',
232
- 'icon_arrow.gif',
233
- 'icon_biggrin.gif',
234
- 'icon_confused.gif',
235
- 'icon_cool.gif',
236
- 'icon_cry.gif',
237
- 'icon_eek.gif',
238
- 'icon_evil.gif',
239
- 'icon_exclaim.gif',
240
- 'icon_idea.gif',
241
- 'icon_lol.gif',
242
- 'icon_mad.gif',
243
- 'icon_mrgreen.gif',
244
- 'icon_neutral.gif',
245
- 'icon_question.gif',
246
- 'icon_razz.gif',
247
- 'icon_redface.gif',
248
- 'icon_rolleyes.gif',
249
- 'icon_sad.gif',
250
- 'icon_smile.gif',
251
- 'icon_surprised.gif',
252
- 'icon_twisted.gif',
253
- 'icon_wink.gif',
254
- 'mrgreen.png',
255
- 'rolleyes.png',
256
- 'simple-smile.png',
257
- );
258
- return $blacklist;
259
- }
260
-
261
- /**
262
- * Image name encoder and url retrive if in url param
263
  *
264
- * @since 3.0.0
265
- * @access public
266
- * @param string $string A string containing the image URL.
267
- * @return string
268
- */
269
- public function feedzy_image_encode( $string ) {
270
- // Check if img url is set as an URL parameter
271
- $url_tab = parse_url( $string );
272
- if ( isset( $url_tab['query'] ) ) {
273
- preg_match_all( '/(http|https):\/\/[^ ]+(\.gif|\.GIF|\.jpg|\.JPG|\.jpeg|\.JPEG|\.png|\.PNG)/', $url_tab['query'], $imgUrl );
274
- if ( isset( $imgUrl[0][0] ) ) {
275
- $string = $imgUrl[0][0];
276
- }
277
- }
278
-
279
- // Encode image name only en keep extra parameters
280
- $query = $extention = '';
281
- $url_tab = parse_url( $string );
282
- if ( isset( $url_tab['query'] ) ) {
283
- $query = '?' . $url_tab['query'];
284
- }
285
- $path_parts = pathinfo( $string );
286
- $path = $path_parts['dirname'];
287
- $file = rawurldecode( $path_parts['filename'] );
288
- $extention = pathinfo( $url_tab['path'], PATHINFO_EXTENSION );
289
- if ( ! empty( $extention ) ) {
290
- $extention = '.' . $extention;
291
- }
292
-
293
- // Return a well encoded image url
294
- return $path . '/' . rawurlencode( $file ) . $extention . $query;
295
- }
296
-
297
- /**
298
- * Filter feed description input
299
  *
300
- * @since 3.0.0
301
- * @access public
302
- * @param string $description The feed description.
303
- * @param string $content The feed description.
304
- * @param string $feedURL The feed URL.
305
  * @return string
306
  */
307
  public function feedzy_summary_input_filter( $description, $content, $feedURL ) {
@@ -316,17 +136,18 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
316
  *
317
  * @since 3.0.0
318
  * @access public
 
319
  * @param boolean $continue A boolean to stop the script.
320
- * @param array $sc The shortcode attributes.
321
- * @param object $item The feed item.
322
- * @param string $feedURL The feed URL.
 
323
  * @return boolean
324
  */
325
  public function feedzy_feed_item_keywords_title( $continue, $sc, $item, $feedURL ) {
326
  if ( feedzy_is_new() && ! feedzy_is_pro() ) {
327
  return true;
328
  }
329
-
330
  $keywords_title = $sc['keywords_title'];
331
  if ( ! empty( $keywords_title ) ) {
332
  $continue = false;
@@ -336,10 +157,10 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
336
  }
337
  }
338
  }
 
339
  return $continue;
340
  }
341
 
342
-
343
  /**
344
  * Include cover picture (medium) to rss feed enclosure
345
  * and media:content
@@ -349,44 +170,125 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
349
  */
350
  public function feedzy_include_thumbnail_rss() {
351
  global $post;
352
-
353
  if ( has_post_thumbnail( $post->ID ) ) {
354
-
355
  $postThumbnailId = get_post_thumbnail_id( $post->ID );
356
- $attachmentMeta = wp_get_attachment_metadata( $postThumbnailId );
357
- $imageUrl = wp_get_attachment_image_src( $postThumbnailId, 'medium' );
358
-
359
  echo '<enclosure url="' . $imageUrl[0] . '" length="' . filesize( get_attached_file( $postThumbnailId ) ) . '" type="image/jpg" />';
360
  echo '<media:content url="' . $imageUrl[0] . '" width="' . $attachmentMeta['sizes']['medium']['width'] . '" height="' . $attachmentMeta['sizes']['medium']['height'] . '" medium="image" type="' . $attachmentMeta['sizes']['medium']['mime-type'] . '" />';
361
 
362
  }
363
  }
364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  /**
366
  * Returns the attributes of the shortcode
367
  *
368
  * @since 3.0.0
369
  * @access public
 
370
  * @param array $atts The attributes passed by WordPress.
 
371
  * @return array
372
  */
373
  public function get_short_code_attributes( $atts ) {
374
  // Retrieve & extract shorcode parameters
375
  $sc = shortcode_atts( array(
376
- 'feeds' => '', // comma separated feeds url
377
- 'max' => '5', // number of feeds items (0 for unlimited)
378
- 'feed_title' => 'yes', // display feed title yes/no
379
- 'target' => '_blank', // _blank, _self
380
- 'title' => '', // strip title after X char
381
- 'meta' => 'yes', // yes, no
382
- 'summary' => 'yes', // strip title
383
- 'summarylength' => '', // strip summary after X char
384
- 'thumb' => 'auto', // yes, no, auto
385
- 'default' => '', // default thumb URL if no image found (only if thumb is set to yes or auto)
386
- 'size' => '', // thumbs pixel size
387
- 'keywords_title' => '', // only display item if title contains specific keywords (comma-separated list/case sensitive)
 
 
 
 
 
 
 
 
 
 
 
 
388
  ), $atts, 'feedzy_default' );
389
-
390
  $sc = array_merge( $sc, apply_filters( 'feedzy_get_short_code_attributes_filter', $atts ) );
391
 
392
  return $sc;
@@ -397,24 +299,26 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
397
  *
398
  * @since 3.0.0
399
  * @access public
 
400
  * @param string $feeds The feeds from the shortcode attribute.
 
401
  * @return array|mixed
402
  */
403
  public function get_feed_url( $feeds ) {
404
  $feedURL = '';
405
  if ( ! empty( $feeds ) ) {
406
- $feeds = rtrim( $feeds, ',' );
407
- $feeds = explode( ',', $feeds );
408
  $feedURL = array();
409
  // Remove SSL from HTTP request to prevent fetching errors
410
  foreach ( $feeds as $feed ) {
411
  $feedURL[] = preg_replace( '/^https:/i', 'http:', $feed );
412
  }
413
-
414
  if ( count( $feedURL ) === 1 ) {
415
  $feedURL = $feedURL[0];
416
  }
417
  }
 
418
  return $feedURL;
419
  }
420
 
@@ -423,8 +327,10 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
423
  *
424
  * @since 3.0.0
425
  * @access public
426
- * @param array $sc The shorcode attributes array.
427
- * @param string $feedURL The feed url.
 
 
428
  * @return mixed
429
  */
430
  public function sanitize_attr( $sc, $feedURL ) {
@@ -433,15 +339,12 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
433
  } elseif ( empty( $sc['max'] ) || ! ctype_digit( $sc['max'] ) ) {
434
  $sc['max'] = '5';
435
  }
436
-
437
  if ( empty( $sc['size'] ) || ! ctype_digit( $sc['size'] ) ) {
438
  $sc['size'] = '150';
439
  }
440
-
441
  if ( ! empty( $sc['title'] ) && ! ctype_digit( $sc['title'] ) ) {
442
  $sc['title'] = '';
443
  }
444
-
445
  if ( ! empty( $sc['keywords_title'] ) ) {
446
  $sc['keywords_title'] = rtrim( $sc['keywords_title'], ',' );
447
  $sc['keywords_title'] = array_map( 'trim', explode( ',', $sc['keywords_title'] ) );
@@ -450,11 +353,9 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
450
  $sc['keywords_ban'] = rtrim( $sc['keywords_ban'], ',' );
451
  $sc['keywords_ban'] = array_map( 'trim', explode( ',', $sc['keywords_ban'] ) );
452
  }
453
-
454
  if ( ! empty( $sc['summarylength'] ) && ! ctype_digit( $sc['summarylength'] ) ) {
455
  $sc['summarylength'] = '';
456
  }
457
-
458
  if ( empty( $sc['default'] ) ) {
459
  $sc['default'] = apply_filters( 'feedzy_default_image', $sc['default'], $feedURL );
460
  }
@@ -463,20 +364,102 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
463
  }
464
 
465
  /**
466
- * Retrive the filter rss title array
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
467
  *
468
  * @since 3.0.0
469
  * @access private
470
- * @param object $feed The feed object.
 
 
471
  * @return array
472
  */
473
  private function get_feed_title_filter( $feed ) {
474
  return array(
475
- 'rss_url' => $feed->get_permalink(),
476
- 'rss_title_class' => 'rss_title',
477
- 'rss_title' => html_entity_decode( $feed->get_title() ),
478
  'rss_description_class' => 'rss_description',
479
- 'rss_description' => $feed->get_description(),
480
  );
481
  }
482
 
@@ -485,16 +468,17 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
485
  *
486
  * @since 3.0.0
487
  * @access private
488
- * @param array $sc The shorcode attributes array.
489
- * @param array $sizes The sizes array.
490
- * @param object $item The feed item object.
491
- * @param string $feedURL The feed url.
 
 
492
  * @return array
493
  */
494
  private function get_feed_item_filter( $sc, $sizes, $item, $feedURL ) {
495
  $itemLink = $item->get_permalink();
496
- $newLink = apply_filters( 'feedzy_item_url_filter', $itemLink, $sc );
497
-
498
  // Fetch image thumbnail
499
  if ( $sc['thumb'] == 'yes' || $sc['thumb'] == 'auto' ) {
500
  $theThumbnail = $this->feedzy_retrieve_image( $item );
@@ -510,14 +494,12 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
510
  $contentThumb .= '<span class="default" style="background-image:url(' . $sc['default'] . ');" alt="' . $item->get_title() . '"></span>';
511
  }
512
  }
513
-
514
- $contentThumb = apply_filters( 'feedzy_thumb_output', $contentThumb, $feedURL );
515
  } else {
516
  $contentThumb = '';
517
  $contentThumb .= '<span class="default" style="width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px; background-image:url(' . $sc['default'] . ');" alt="' . $item->get_title() . '"></span>';
518
- $contentThumb = apply_filters( 'feedzy_thumb_output', $contentThumb, $feedURL );
519
  }
520
-
521
  $contentTitle = '';
522
  if ( is_numeric( $sc['title'] ) && strlen( $item->get_title() ) > $sc['title'] ) {
523
  $contentTitle .= preg_replace( '/\s+?(\S+)?$/', '', substr( $item->get_title(), 0, $sc['title'] ) ) . '...';
@@ -525,17 +507,15 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
525
  $contentTitle .= $item->get_title();
526
  }
527
  $contentTitle = apply_filters( 'feedzy_title_output', $contentTitle, $feedURL );
528
-
529
  // Define Meta args
530
  $metaArgs = array(
531
- 'author' => true,
532
- 'date' => true,
533
  'date_format' => get_option( 'date_format' ),
534
  'time_format' => get_option( 'time_format' ),
535
  );
536
-
537
  // Filter: feedzy_meta_args
538
- $metaArgs = apply_filters( 'feedzy_meta_args', $metaArgs, $feedURL );
539
  $contentMeta = '';
540
  if ( $sc['meta'] == 'yes' && ( $metaArgs['author'] || $metaArgs['date'] ) ) {
541
  $contentMeta = '';
@@ -549,186 +529,249 @@ abstract class Feedzy_Rss_Feeds_Admin_Abstract {
549
  $contentMeta .= __( 'by', 'feedzy-rss-feeds' ) . ' <a href="http://' . $domain['host'] . '" target="' . $sc['target'] . '" title="' . $domain['host'] . '" >' . $authorName . '</a> ';
550
  }
551
  }
552
-
553
  if ( $metaArgs['date'] ) {
554
  $date_time = $item->get_date( 'U' );
555
- $date_time = apply_filters( 'feedzy_feed_timestamp',$date_time, $feedURL );
556
-
557
  $contentMeta .= __( 'on', 'feedzy-rss-feeds' ) . ' ' . date_i18n( $metaArgs['date_format'], $date_time );
558
  $contentMeta .= ' ';
559
  $contentMeta .= __( 'at', 'feedzy-rss-feeds' ) . ' ' . date_i18n( $metaArgs['time_format'], $date_time );
560
  }
561
  }
562
- $contentMeta = apply_filters( 'feedzy_meta_output', $contentMeta, $feedURL );
563
  $contentSummary = '';
564
  if ( $sc['summary'] == 'yes' ) {
565
  $contentSummary = '';
566
- $description = $item->get_description();
567
- $description = apply_filters( 'feedzy_summary_input', $description, $item->get_content(), $feedURL );
568
-
569
  if ( is_numeric( $sc['summarylength'] ) && strlen( $description ) > $sc['summarylength'] ) {
570
  $contentSummary .= preg_replace( '/\s+?(\S+)?$/', '', substr( $description, 0, $sc['summarylength'] ) ) . ' […]';
571
  } else {
572
  $contentSummary .= $description . ' […]';
573
  }
574
-
575
  $contentSummary = apply_filters( 'feedzy_summary_output', $contentSummary, $newLink, $feedURL );
576
  }
577
-
578
  $itemArray = array(
579
- 'item_img_class' => 'rss_image',
580
- 'item_img_style' => 'width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px;',
581
- 'item_url' => $newLink,
582
- 'item_url_target' => $sc['target'],
583
- 'item_url_title' => $item->get_title(),
584
- 'item_img' => $contentThumb,
585
- 'item_title' => $contentTitle,
586
  'item_content_class' => 'rss_content',
587
  'item_content_style' => '',
588
- 'item_meta' => $contentMeta,
589
- 'item_description' => $contentSummary,
590
  );
591
-
592
  $itemArray = apply_filters( 'feedzy_item_filter', $itemArray, $item );
593
 
594
  return $itemArray;
595
  }
596
 
597
  /**
598
- * Render the content to be displayed
599
  *
600
  * @since 3.0.0
601
  * @access public
602
- * @param array $sc The shorcode attributes array.
603
- * @param object $feed The feed object.
604
- * @param string $content The original content.
605
- * @param string $feedURL The feed url.
606
  * @return string
607
  */
608
- public function render_content( $sc, $feed, $content = '', $feedURL ) {
609
- $count = 0;
610
-
611
- $sizes = array( 'width' => $sc['size'], 'height' => $sc['size'] );
612
- $sizes = apply_filters( 'feedzy_thumb_sizes', $sizes, $feedURL );
613
-
614
- // Display the error message
615
- if ( $feed -> error() ) {
616
- $content .= apply_filters( 'feedzy_default_error', $feed -> error(), $feedURL );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617
  }
618
-
619
- $feed_title['use_title'] = false;
620
- if ( $sc['feed_title'] == 'yes' ) {
621
- $feed_title = $this->get_feed_title_filter( $feed );
622
- $feed_title['use_title'] = true;
 
 
 
 
 
 
 
 
 
 
 
623
  }
624
 
625
- $count = 0;
626
- $items = apply_filters( 'feedzy_feed_items', $feed->get_items(), $feedURL );
627
- $feed_items = array();
628
- foreach ( (array) $items as $item ) {
629
- $continue = apply_filters( 'feedzy_item_keyword', true, $sc, $item, $feedURL );
630
- if ( $continue == true ) {
631
- // Count items
632
- if ( $count >= $sc['max'] ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633
  break;
634
  }
635
- $itemAttr = apply_filters( 'feedzy_item_attributes', $itemAttr = '', $sizes, $item, $feedURL, $sc );
636
- $feed_items[ $count ] = $this->get_feed_item_filter( $sc, $sizes, $item, $feedURL );
637
- $feed_items[ $count ]['itemAttr'] = $itemAttr;
638
- $count++;
639
  }
640
  }
641
 
642
- $content = '<div class="feedzy-rss">';
 
643
 
644
- if ( $feed_title['use_title'] ) {
645
- $content .= '<div class="rss_header">';
646
- $content .= '<h2><a href="' . $feed->get_permalink() . '" class="rss_title">' . html_entity_decode( $feed->get_title() ) . '</a> <span class="rss_description"> ' . $feed->get_description() . '</span></h2>';
647
- $content .= '</div>';
 
 
 
 
 
 
 
 
 
 
 
 
648
  }
649
 
650
- $content .= '<ul>';
651
- foreach ( $feed_items as $item ) {
652
- $content .= '
653
- <li ' . $item['itemAttr'] . '>
654
- ' . ( ( ! empty( $item['item_img'] ) && $sc['thumb'] != 'no' ) ? '
655
- <div class="' . $item['item_img_class'] . '" style="' . $item['item_img_style'] . '">
656
- <a href="' . $item['item_url'] . '" target="' . $item['item_url_target'] . '" title="' . $item['item_url_title'] . '" style="' . $item['item_img_style'] . '">
657
- ' . $item['item_img'] . '
658
- </a>
659
- </div>' : '' ) . '
660
- <span class="title">
661
- <a href="' . $item['item_url'] . '" target="' . $item['item_url_target'] . '">
662
- ' . $item['item_title'] . '
663
- </a>
664
- </span>
665
- <div class="' . $item['item_content_class'] . '" style="' . $item['item_content_style'] . '">
666
- ' . ( ! empty( $item['item_meta'] ) ? '<small>
667
- ' . $item['item_meta'] . '
668
- </small>' : '' ) . '
669
- ' . ( ! empty( $item['item_description'] ) ? '<p>' . $item['item_description'] . '</p>':'') . '
670
- </div>
671
- </li>
672
- ';
673
- }
674
- $content .= '</ul> </div>';
675
 
676
- $content = apply_filters( 'feedzy_global_output', $content, $sc, $feed_title, $feed_items );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677
 
678
- return $content;
679
  }
680
 
681
  /**
682
- * Main shortcode function
683
  *
684
  * @since 3.0.0
685
  * @access public
686
- * @param array $atts Shortcode attributes.
687
- * @param string $content The item feed content.
688
- * @return mixed
 
689
  */
690
- public function feedzy_rss( $atts, $content = '' ) {
691
- // Load SimplePie if not already
692
- if ( ! class_exists( 'SimplePie' ) ) {
693
- require_once( ABSPATH . WPINC . '/feed.php' );
694
- }
695
- $sc = $this->get_short_code_attributes( $atts );
696
- $feedURL = $this->get_feed_url( $sc['feeds'] );
697
- // Load SimplePie Instance
698
- $feed = fetch_feed( $feedURL );
699
- // TODO report error when is an error loading the feed
700
- if ( is_wp_error( $feed ) ) {
701
- // Fallback for different edge cases.
702
- if ( is_array( $feedURL ) ) {
703
- $feedURL = array_map( 'html_entity_decode',$feedURL );
704
- } else {
705
- $feedURL = html_entity_decode( $feedURL );
706
  }
707
-
708
- $feed = fetch_feed( $feedURL );
709
-
710
- if ( is_wp_error( $feed ) ) {
711
- return '';
 
 
 
 
 
 
 
 
 
 
 
712
  }
713
  }
714
- $feed->set_sanitize_class( 'SimplePie_Sanitize' );
715
- $feed->sanitize = new SimplePie_Sanitize();
716
- $feed -> enable_cache( true );
717
- $feed -> enable_order_by_date( true );
718
- $feed -> set_cache_class( 'WP_Feed_Cache' );
719
- $feed -> set_file_class( 'WP_SimplePie_File' );
720
- $feed -> set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 7200, $feedURL ) );
721
- do_action_ref_array( 'wp_feed_options', array( $feed, $feedURL ) );
722
- $feed -> strip_comments( true );
723
- $feed -> strip_htmltags( array( 'base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style' ) );
724
- $feed -> init();
725
- $feed -> handle_content_type();
726
 
727
- $sc = $this->sanitize_attr( $sc, $feedURL );
728
-
729
- $content = $this->render_content( $sc, $feed, $content, $feedURL );
730
-
731
- return $content;
732
  }
733
 
734
  /**
8
  * @package feedzy-rss-feeds
9
  * @subpackage feedzy-rss-feeds/includes/abstract
10
  */
11
+
12
  /**
13
  * The Feedzy RSS functions of the plugin.
14
  *
21
  */
22
  abstract class Feedzy_Rss_Feeds_Admin_Abstract {
23
 
 
24
  /**
25
  * Defines the default image to use on RSS Feeds
26
  *
27
  * @since 3.0.0
28
  * @access public
29
+ *
30
  * @param string $imageSrc The image source, currently not used.
31
+ *
32
  * @return string
33
  */
34
  public function feedzy_define_default_image( $imageSrc ) {
35
  $defaultImg = FEEDZY_ABSURL . '/img/feedzy-default.jpg';
36
+
37
  return apply_filters( 'feedzy_define_default_image_filter', $defaultImg );
38
  }
39
 
45
  *
46
  * @since 3.0.0
47
  * @access public
48
+ *
49
  * @param object $error The error Object.
50
  * @param string $feedURL The feed URL.
51
+ *
52
  * @return string
53
  */
54
+ public function feedzy_default_error_notice( $error, $feedURL ) {
55
  error_log( 'Feedzy RSS Feeds - related feed: ' . print_r( $feedURL ) . ' - Error message: ' . $this->feedzy_array_obj_string( $error ) );
56
+
57
  return '<div id="message" class="error" data-error"' . esc_attr( $this->feedzy_array_obj_string( $error ) ) . '"><p>' . __( 'Sorry, this feed is currently unavailable or does not exists anymore.', 'feedzy-rss-feeds' ) . '</p></div>';
58
  }
59
 
62
  *
63
  * @since 3.0.0
64
  * @access public
65
+ *
66
  * @param object $error The error Object.
67
+ *
68
  * @return string
69
  */
70
  public function feedzy_array_obj_string( $error ) {
80
  *
81
  * @since 3.0.0
82
  * @access public
83
+ *
84
+ * @param string $itemAttr The item attribute.
85
+ * @param array $sizes An array with the current sizes.
86
+ *
87
  * @return string
88
  */
89
  public function feedzy_add_item_padding( $itemAttr, $sizes ) {
90
+ $paddinTop = number_format( ( 15 / 150 ) * $sizes['height'], 0 );
91
  $paddinBottom = number_format( ( 25 / 150 ) * $sizes['height'], 0 );
92
  $stylePadding = ' style="padding: ' . $paddinTop . 'px 0 ' . $paddinBottom . 'px"';
93
+
94
  return $itemAttr . $stylePadding;
95
  }
96
 
99
  *
100
  * @since 3.0.0
101
  * @access public
102
+ *
103
+ * @param string $itemAttr The item attribute.
104
+ *
105
  * @return string
106
  */
107
  public function feedzy_classes_item( $itemAttr = '', $sizes = '', $item = '', $feedURL = '', $sc = '' ) {
108
  $classes = array( 'rss_item' );
109
  $classes = apply_filters( 'feedzy_add_classes_item', $classes, $sc );
110
  $classes = ' class="' . implode( ' ', $classes ) . '"';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
+ return $itemAttr . $classes;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  }
114
 
115
  /**
116
+ * Filter feed description input
117
  *
118
  * @since 3.0.0
119
  * @access public
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  *
121
+ * @param string $description The feed description.
122
+ * @param string $content The feed description.
123
+ * @param string $feedURL The feed URL.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  *
 
 
 
 
 
125
  * @return string
126
  */
127
  public function feedzy_summary_input_filter( $description, $content, $feedURL ) {
136
  *
137
  * @since 3.0.0
138
  * @access public
139
+ *
140
  * @param boolean $continue A boolean to stop the script.
141
+ * @param array $sc The shortcode attributes.
142
+ * @param object $item The feed item.
143
+ * @param string $feedURL The feed URL.
144
+ *
145
  * @return boolean
146
  */
147
  public function feedzy_feed_item_keywords_title( $continue, $sc, $item, $feedURL ) {
148
  if ( feedzy_is_new() && ! feedzy_is_pro() ) {
149
  return true;
150
  }
 
151
  $keywords_title = $sc['keywords_title'];
152
  if ( ! empty( $keywords_title ) ) {
153
  $continue = false;
157
  }
158
  }
159
  }
160
+
161
  return $continue;
162
  }
163
 
 
164
  /**
165
  * Include cover picture (medium) to rss feed enclosure
166
  * and media:content
170
  */
171
  public function feedzy_include_thumbnail_rss() {
172
  global $post;
 
173
  if ( has_post_thumbnail( $post->ID ) ) {
 
174
  $postThumbnailId = get_post_thumbnail_id( $post->ID );
175
+ $attachmentMeta = wp_get_attachment_metadata( $postThumbnailId );
176
+ $imageUrl = wp_get_attachment_image_src( $postThumbnailId, 'medium' );
 
177
  echo '<enclosure url="' . $imageUrl[0] . '" length="' . filesize( get_attached_file( $postThumbnailId ) ) . '" type="image/jpg" />';
178
  echo '<media:content url="' . $imageUrl[0] . '" width="' . $attachmentMeta['sizes']['medium']['width'] . '" height="' . $attachmentMeta['sizes']['medium']['height'] . '" medium="image" type="' . $attachmentMeta['sizes']['medium']['mime-type'] . '" />';
179
 
180
  }
181
  }
182
 
183
+ /**
184
+ * Main shortcode function
185
+ *
186
+ * @since 3.0.0
187
+ * @access public
188
+ *
189
+ * @param array $atts Shortcode attributes.
190
+ * @param string $content The item feed content.
191
+ *
192
+ * @return mixed
193
+ */
194
+ public function feedzy_rss( $atts, $content = '' ) {
195
+ // Load SimplePie if not already
196
+ if ( ! class_exists( 'SimplePie' ) ) {
197
+ require_once( ABSPATH . WPINC . '/feed.php' );
198
+ }
199
+ $sc = $this->get_short_code_attributes( $atts );
200
+ $feedURL = $this->get_feed_url( $sc['feeds'] );
201
+ // Load SimplePie Instance
202
+ $feed = fetch_feed( $feedURL );
203
+ // TODO report error when is an error loading the feed
204
+ if ( is_wp_error( $feed ) ) {
205
+ // Fallback for different edge cases.
206
+ if ( is_array( $feedURL ) ) {
207
+ $feedURL = array_map( 'html_entity_decode', $feedURL );
208
+ } else {
209
+ $feedURL = html_entity_decode( $feedURL );
210
+ }
211
+ $feed = fetch_feed( $feedURL );
212
+ if ( is_wp_error( $feed ) ) {
213
+ return '';
214
+ }
215
+ }
216
+ $feed->set_sanitize_class( 'SimplePie_Sanitize' );
217
+ $feed->sanitize = new SimplePie_Sanitize();
218
+ $feed->enable_cache( true );
219
+ $feed->enable_order_by_date( true );
220
+ $feed->set_cache_class( 'WP_Feed_Cache' );
221
+ $feed->set_file_class( 'WP_SimplePie_File' );
222
+ $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 7200, $feedURL ) );
223
+ do_action_ref_array( 'wp_feed_options', array( $feed, $feedURL ) );
224
+ $feed->strip_comments( true );
225
+ $feed->strip_htmltags( array(
226
+ 'base',
227
+ 'blink',
228
+ 'body',
229
+ 'doctype',
230
+ 'embed',
231
+ 'font',
232
+ 'form',
233
+ 'frame',
234
+ 'frameset',
235
+ 'html',
236
+ 'iframe',
237
+ 'input',
238
+ 'marquee',
239
+ 'meta',
240
+ 'noscript',
241
+ 'object',
242
+ 'param',
243
+ 'script',
244
+ 'style',
245
+ ) );
246
+ $feed->init();
247
+ $feed->handle_content_type();
248
+ $sc = $this->sanitize_attr( $sc, $feedURL );
249
+ $content = $this->render_content( $sc, $feed, $content, $feedURL );
250
+
251
+ return $content;
252
+ }
253
+
254
  /**
255
  * Returns the attributes of the shortcode
256
  *
257
  * @since 3.0.0
258
  * @access public
259
+ *
260
  * @param array $atts The attributes passed by WordPress.
261
+ *
262
  * @return array
263
  */
264
  public function get_short_code_attributes( $atts ) {
265
  // Retrieve & extract shorcode parameters
266
  $sc = shortcode_atts( array(
267
+ 'feeds' => '',
268
+ // comma separated feeds url
269
+ 'max' => '5',
270
+ // number of feeds items (0 for unlimited)
271
+ 'feed_title' => 'yes',
272
+ // display feed title yes/no
273
+ 'target' => '_blank',
274
+ // _blank, _self
275
+ 'title' => '',
276
+ // strip title after X char
277
+ 'meta' => 'yes',
278
+ // yes, no
279
+ 'summary' => 'yes',
280
+ // strip title
281
+ 'summarylength' => '',
282
+ // strip summary after X char
283
+ 'thumb' => 'auto',
284
+ // yes, no, auto
285
+ 'default' => '',
286
+ // default thumb URL if no image found (only if thumb is set to yes or auto)
287
+ 'size' => '',
288
+ // thumbs pixel size
289
+ 'keywords_title' => '',
290
+ // only display item if title contains specific keywords (comma-separated list/case sensitive)
291
  ), $atts, 'feedzy_default' );
 
292
  $sc = array_merge( $sc, apply_filters( 'feedzy_get_short_code_attributes_filter', $atts ) );
293
 
294
  return $sc;
299
  *
300
  * @since 3.0.0
301
  * @access public
302
+ *
303
  * @param string $feeds The feeds from the shortcode attribute.
304
+ *
305
  * @return array|mixed
306
  */
307
  public function get_feed_url( $feeds ) {
308
  $feedURL = '';
309
  if ( ! empty( $feeds ) ) {
310
+ $feeds = rtrim( $feeds, ',' );
311
+ $feeds = explode( ',', $feeds );
312
  $feedURL = array();
313
  // Remove SSL from HTTP request to prevent fetching errors
314
  foreach ( $feeds as $feed ) {
315
  $feedURL[] = preg_replace( '/^https:/i', 'http:', $feed );
316
  }
 
317
  if ( count( $feedURL ) === 1 ) {
318
  $feedURL = $feedURL[0];
319
  }
320
  }
321
+
322
  return $feedURL;
323
  }
324
 
327
  *
328
  * @since 3.0.0
329
  * @access public
330
+ *
331
+ * @param array $sc The shorcode attributes array.
332
+ * @param string $feedURL The feed url.
333
+ *
334
  * @return mixed
335
  */
336
  public function sanitize_attr( $sc, $feedURL ) {
339
  } elseif ( empty( $sc['max'] ) || ! ctype_digit( $sc['max'] ) ) {
340
  $sc['max'] = '5';
341
  }
 
342
  if ( empty( $sc['size'] ) || ! ctype_digit( $sc['size'] ) ) {
343
  $sc['size'] = '150';
344
  }
 
345
  if ( ! empty( $sc['title'] ) && ! ctype_digit( $sc['title'] ) ) {
346
  $sc['title'] = '';
347
  }
 
348
  if ( ! empty( $sc['keywords_title'] ) ) {
349
  $sc['keywords_title'] = rtrim( $sc['keywords_title'], ',' );
350
  $sc['keywords_title'] = array_map( 'trim', explode( ',', $sc['keywords_title'] ) );
353
  $sc['keywords_ban'] = rtrim( $sc['keywords_ban'], ',' );
354
  $sc['keywords_ban'] = array_map( 'trim', explode( ',', $sc['keywords_ban'] ) );
355
  }
 
356
  if ( ! empty( $sc['summarylength'] ) && ! ctype_digit( $sc['summarylength'] ) ) {
357
  $sc['summarylength'] = '';
358
  }
 
359
  if ( empty( $sc['default'] ) ) {
360
  $sc['default'] = apply_filters( 'feedzy_default_image', $sc['default'], $feedURL );
361
  }
364
  }
365
 
366
  /**
367
+ * Render the content to be displayed
368
+ *
369
+ * @since 3.0.0
370
+ * @access public
371
+ *
372
+ * @param array $sc The shorcode attributes array.
373
+ * @param object $feed The feed object.
374
+ * @param string $content The original content.
375
+ * @param string $feedURL The feed url.
376
+ *
377
+ * @return string
378
+ */
379
+ public function render_content( $sc, $feed, $content = '', $feedURL ) {
380
+ $count = 0;
381
+ $sizes = array( 'width' => $sc['size'], 'height' => $sc['size'] );
382
+ $sizes = apply_filters( 'feedzy_thumb_sizes', $sizes, $feedURL );
383
+ // Display the error message
384
+ if ( $feed->error() ) {
385
+ $content .= apply_filters( 'feedzy_default_error', $feed->error(), $feedURL );
386
+ }
387
+ $feed_title['use_title'] = false;
388
+ if ( $sc['feed_title'] == 'yes' ) {
389
+ $feed_title = $this->get_feed_title_filter( $feed );
390
+ $feed_title['use_title'] = true;
391
+ }
392
+ $count = 0;
393
+ $items = apply_filters( 'feedzy_feed_items', $feed->get_items(), $feedURL );
394
+ $feed_items = array();
395
+ foreach ( (array) $items as $item ) {
396
+ if ( ! trim( $item->get_title() ) != '' ) {
397
+ $continue = apply_filters( 'feedzy_item_keyword', true, $sc, $item, $feedURL );
398
+ if ( $continue == true ) {
399
+ // Count items
400
+ if ( $count >= $sc['max'] ) {
401
+ break;
402
+ }
403
+ $itemAttr = apply_filters( 'feedzy_item_attributes', $itemAttr = '', $sizes, $item, $feedURL, $sc );
404
+ $feed_items[ $count ] = $this->get_feed_item_filter( $sc, $sizes, $item, $feedURL );
405
+ $feed_items[ $count ]['itemAttr'] = $itemAttr;
406
+ $count ++;
407
+ }
408
+ }
409
+ }
410
+ $content = '<div class="feedzy-rss">';
411
+ if ( $feed_title['use_title'] ) {
412
+ $content .= '<div class="rss_header">';
413
+ $content .= '<h2><a href="' . $feed->get_permalink() . '" class="rss_title">' . html_entity_decode( $feed->get_title() ) . '</a> <span class="rss_description"> ' . $feed->get_description() . '</span></h2>';
414
+ $content .= '</div>';
415
+ }
416
+ $content .= '<ul>';
417
+ foreach ( $feed_items as $item ) {
418
+ $content .= '
419
+ <li ' . $item['itemAttr'] . '>
420
+ ' . ( ( ! empty( $item['item_img'] ) && $sc['thumb'] != 'no' ) ? '
421
+ <div class="' . $item['item_img_class'] . '" style="' . $item['item_img_style'] . '">
422
+ <a href="' . $item['item_url'] . '" target="' . $item['item_url_target'] . '" title="' . $item['item_url_title'] . '" style="' . $item['item_img_style'] . '">
423
+ ' . $item['item_img'] . '
424
+ </a>
425
+ </div>' : '' ) . '
426
+ <span class="title">
427
+ <a href="' . $item['item_url'] . '" target="' . $item['item_url_target'] . '">
428
+ ' . $item['item_title'] . '
429
+ </a>
430
+ </span>
431
+ <div class="' . $item['item_content_class'] . '" style="' . $item['item_content_style'] . '">
432
+ ' . ( ! empty( $item['item_meta'] ) ? '<small>
433
+ ' . $item['item_meta'] . '
434
+ </small>' : '' ) . '
435
+ ' . ( ! empty( $item['item_description'] ) ? '<p>' . $item['item_description'] . '</p>' : '' ) . '
436
+ </div>
437
+ </li>
438
+ ';
439
+ }
440
+ $content .= '</ul> </div>';
441
+ $content = apply_filters( 'feedzy_global_output', $content, $sc, $feed_title, $feed_items );
442
+
443
+ return $content;
444
+ }
445
+
446
+ /**
447
+ * Retrive the filter rss title array
448
  *
449
  * @since 3.0.0
450
  * @access private
451
+ *
452
+ * @param object $feed The feed object.
453
+ *
454
  * @return array
455
  */
456
  private function get_feed_title_filter( $feed ) {
457
  return array(
458
+ 'rss_url' => $feed->get_permalink(),
459
+ 'rss_title_class' => 'rss_title',
460
+ 'rss_title' => html_entity_decode( $feed->get_title() ),
461
  'rss_description_class' => 'rss_description',
462
+ 'rss_description' => $feed->get_description(),
463
  );
464
  }
465
 
468
  *
469
  * @since 3.0.0
470
  * @access private
471
+ *
472
+ * @param array $sc The shorcode attributes array.
473
+ * @param array $sizes The sizes array.
474
+ * @param object $item The feed item object.
475
+ * @param string $feedURL The feed url.
476
+ *
477
  * @return array
478
  */
479
  private function get_feed_item_filter( $sc, $sizes, $item, $feedURL ) {
480
  $itemLink = $item->get_permalink();
481
+ $newLink = apply_filters( 'feedzy_item_url_filter', $itemLink, $sc );
 
482
  // Fetch image thumbnail
483
  if ( $sc['thumb'] == 'yes' || $sc['thumb'] == 'auto' ) {
484
  $theThumbnail = $this->feedzy_retrieve_image( $item );
494
  $contentThumb .= '<span class="default" style="background-image:url(' . $sc['default'] . ');" alt="' . $item->get_title() . '"></span>';
495
  }
496
  }
497
+ $contentThumb = apply_filters( 'feedzy_thumb_output', $contentThumb, $feedURL, $sizes );
 
498
  } else {
499
  $contentThumb = '';
500
  $contentThumb .= '<span class="default" style="width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px; background-image:url(' . $sc['default'] . ');" alt="' . $item->get_title() . '"></span>';
501
+ $contentThumb = apply_filters( 'feedzy_thumb_output', $contentThumb, $feedURL, $sizes );
502
  }
 
503
  $contentTitle = '';
504
  if ( is_numeric( $sc['title'] ) && strlen( $item->get_title() ) > $sc['title'] ) {
505
  $contentTitle .= preg_replace( '/\s+?(\S+)?$/', '', substr( $item->get_title(), 0, $sc['title'] ) ) . '...';
507
  $contentTitle .= $item->get_title();
508
  }
509
  $contentTitle = apply_filters( 'feedzy_title_output', $contentTitle, $feedURL );
 
510
  // Define Meta args
511
  $metaArgs = array(
512
+ 'author' => true,
513
+ 'date' => true,
514
  'date_format' => get_option( 'date_format' ),
515
  'time_format' => get_option( 'time_format' ),
516
  );
 
517
  // Filter: feedzy_meta_args
518
+ $metaArgs = apply_filters( 'feedzy_meta_args', $metaArgs, $feedURL );
519
  $contentMeta = '';
520
  if ( $sc['meta'] == 'yes' && ( $metaArgs['author'] || $metaArgs['date'] ) ) {
521
  $contentMeta = '';
529
  $contentMeta .= __( 'by', 'feedzy-rss-feeds' ) . ' <a href="http://' . $domain['host'] . '" target="' . $sc['target'] . '" title="' . $domain['host'] . '" >' . $authorName . '</a> ';
530
  }
531
  }
 
532
  if ( $metaArgs['date'] ) {
533
  $date_time = $item->get_date( 'U' );
534
+ $date_time = apply_filters( 'feedzy_feed_timestamp', $date_time, $feedURL );
 
535
  $contentMeta .= __( 'on', 'feedzy-rss-feeds' ) . ' ' . date_i18n( $metaArgs['date_format'], $date_time );
536
  $contentMeta .= ' ';
537
  $contentMeta .= __( 'at', 'feedzy-rss-feeds' ) . ' ' . date_i18n( $metaArgs['time_format'], $date_time );
538
  }
539
  }
540
+ $contentMeta = apply_filters( 'feedzy_meta_output', $contentMeta, $feedURL );
541
  $contentSummary = '';
542
  if ( $sc['summary'] == 'yes' ) {
543
  $contentSummary = '';
544
+ $description = $item->get_description();
545
+ $description = apply_filters( 'feedzy_summary_input', $description, $item->get_content(), $feedURL );
 
546
  if ( is_numeric( $sc['summarylength'] ) && strlen( $description ) > $sc['summarylength'] ) {
547
  $contentSummary .= preg_replace( '/\s+?(\S+)?$/', '', substr( $description, 0, $sc['summarylength'] ) ) . ' […]';
548
  } else {
549
  $contentSummary .= $description . ' […]';
550
  }
 
551
  $contentSummary = apply_filters( 'feedzy_summary_output', $contentSummary, $newLink, $feedURL );
552
  }
 
553
  $itemArray = array(
554
+ 'item_img_class' => 'rss_image',
555
+ 'item_img_style' => 'width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px;',
556
+ 'item_url' => $newLink,
557
+ 'item_url_target' => $sc['target'],
558
+ 'item_url_title' => $item->get_title(),
559
+ 'item_img' => $contentThumb,
560
+ 'item_title' => $contentTitle,
561
  'item_content_class' => 'rss_content',
562
  'item_content_style' => '',
563
+ 'item_meta' => $contentMeta,
564
+ 'item_description' => $contentSummary,
565
  );
 
566
  $itemArray = apply_filters( 'feedzy_item_filter', $itemArray, $item );
567
 
568
  return $itemArray;
569
  }
570
 
571
  /**
572
+ * Retrive image from the item object
573
  *
574
  * @since 3.0.0
575
  * @access public
576
+ *
577
+ * @param object $item The item object.
578
+ *
 
579
  * @return string
580
  */
581
+ public function feedzy_retrieve_image( $item ) {
582
+ $theThumbnail = '';
583
+ if ( $enclosures = $item->get_enclosures() ) {
584
+ foreach ( (array) $enclosures as $enclosure ) {
585
+ // Item thumbnail
586
+ if ( $thumbnail = $enclosure->get_thumbnail() ) {
587
+ $theThumbnail = $thumbnail;
588
+ }
589
+ if ( isset( $enclosure->thumbnails ) ) {
590
+ foreach ( (array) $enclosure->thumbnails as $thumbnail ) {
591
+ $theThumbnail = $thumbnail;
592
+ }
593
+ }
594
+ if ( $thumbnail = $enclosure->embed() ) {
595
+ $pattern = '/https?:\/\/.*\.(?:jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/iU';
596
+ if ( preg_match( $pattern, $thumbnail, $matches ) ) {
597
+ $theThumbnail = $matches[0];
598
+ }
599
+ }
600
+ foreach ( (array) $enclosure->get_link() as $thumbnail ) {
601
+ $pattern = '/https?:\/\/.*\.(?:jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/iU';
602
+ $imgsrc = $thumbnail;
603
+ if ( preg_match( $pattern, $imgsrc, $matches ) ) {
604
+ $theThumbnail = $matches[0];
605
+ break;
606
+ }
607
+ }
608
+ // Break loop if thumbnail is found
609
+ if ( ! empty( $theThumbnail ) ) {
610
+ break;
611
+ }
612
+ }
613
  }
614
+ // xmlns:itunes podcast
615
+ if ( empty( $theThumbnail ) ) {
616
+ $data = $item->get_item_tags( 'http://www.itunes.com/dtds/podcast-1.0.dtd', 'image' );
617
+ if ( isset( $data['0']['attribs']['']['href'] ) && ! empty( $data['0']['attribs']['']['href'] ) ) {
618
+ $theThumbnail = $data['0']['attribs']['']['href'];
619
+ }
620
+ }
621
+ // Content image
622
+ if ( empty( $theThumbnail ) ) {
623
+ $feedDescription = $item->get_content();
624
+ $theThumbnail = $this->feedzy_return_image( $feedDescription );
625
+ }
626
+ // Description image
627
+ if ( empty( $theThumbnail ) ) {
628
+ $feedDescription = $item->get_description();
629
+ $theThumbnail = $this->feedzy_return_image( $feedDescription );
630
  }
631
 
632
+ return $theThumbnail;
633
+ }
634
+
635
+ /**
636
+ * Get an image from a string
637
+ *
638
+ * @since 3.0.0
639
+ * @access public
640
+ *
641
+ * @param string $string A string with an <img/> tag.
642
+ *
643
+ * @return string
644
+ */
645
+ public function feedzy_return_image( $string ) {
646
+ $img = html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );
647
+ $pattern = '/<img[^>]+\>/i';
648
+ preg_match( $pattern, $img, $matches );
649
+ if ( isset( $matches[0] ) ) {
650
+ $blacklistCount = 0;
651
+ foreach ( $matches as $matche ) {
652
+ $link = $this->feedzy_scrape_image( $matche );
653
+ $blacklist = array();
654
+ $blacklist = apply_filters( 'feedzy_feed_blacklist_images', $this->feedzy_blacklist_images( $blacklist ) );
655
+ foreach ( $blacklist as $string ) {
656
+ if ( strpos( (string) $link, $string ) !== false ) {
657
+ $blacklistCount ++;
658
+ }
659
+ }
660
+ if ( $blacklistCount == 0 ) {
661
  break;
662
  }
663
+ }
664
+ if ( $blacklistCount == 0 ) {
665
+ return $link;
 
666
  }
667
  }
668
 
669
+ return '';
670
+ }
671
 
672
+ /**
673
+ * Scrape an image for link from a string with an <img/>
674
+ *
675
+ * @since 3.0.0
676
+ * @access public
677
+ *
678
+ * @param string $string A string with an <img/> tag.
679
+ * @param string $link The link to search for.
680
+ *
681
+ * @return string
682
+ */
683
+ public function feedzy_scrape_image( $string, $link = '' ) {
684
+ $pattern = '/src=[\'"]?([^\'" >]+)[\'" >]/';
685
+ preg_match( $pattern, $string, $link );
686
+ if ( isset( $link[1] ) ) {
687
+ $link = urldecode( $link[1] );
688
  }
689
 
690
+ return $link;
691
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
692
 
693
+ /**
694
+ * List blacklisted images to prevent fetching emoticons
695
+ *
696
+ * @since 3.0.0
697
+ * @access public
698
+ *
699
+ * @param array $blacklist An array with blacklisted resources.
700
+ *
701
+ * @return array
702
+ */
703
+ public function feedzy_blacklist_images( $blacklist ) {
704
+ $blacklist = array(
705
+ 'frownie.png',
706
+ 'icon_arrow.gif',
707
+ 'icon_biggrin.gif',
708
+ 'icon_confused.gif',
709
+ 'icon_cool.gif',
710
+ 'icon_cry.gif',
711
+ 'icon_eek.gif',
712
+ 'icon_evil.gif',
713
+ 'icon_exclaim.gif',
714
+ 'icon_idea.gif',
715
+ 'icon_lol.gif',
716
+ 'icon_mad.gif',
717
+ 'icon_mrgreen.gif',
718
+ 'icon_neutral.gif',
719
+ 'icon_question.gif',
720
+ 'icon_razz.gif',
721
+ 'icon_redface.gif',
722
+ 'icon_rolleyes.gif',
723
+ 'icon_sad.gif',
724
+ 'icon_smile.gif',
725
+ 'icon_surprised.gif',
726
+ 'icon_twisted.gif',
727
+ 'icon_wink.gif',
728
+ 'mrgreen.png',
729
+ 'rolleyes.png',
730
+ 'simple-smile.png',
731
+ );
732
 
733
+ return $blacklist;
734
  }
735
 
736
  /**
737
+ * Image name encoder and url retrive if in url param
738
  *
739
  * @since 3.0.0
740
  * @access public
741
+ *
742
+ * @param string $string A string containing the image URL.
743
+ *
744
+ * @return string
745
  */
746
+ public function feedzy_image_encode( $string ) {
747
+ // Check if img url is set as an URL parameter
748
+ $url_tab = parse_url( $string );
749
+ if ( isset( $url_tab['query'] ) ) {
750
+ preg_match_all( '/(http|https):\/\/[^ ]+(\.gif|\.GIF|\.jpg|\.JPG|\.jpeg|\.JPEG|\.png|\.PNG)/', $url_tab['query'], $imgUrl );
751
+ if ( isset( $imgUrl[0][0] ) ) {
752
+ $string = $imgUrl[0][0];
 
 
 
 
 
 
 
 
 
753
  }
754
+ }
755
+ // Encode image name only en keep extra parameters
756
+ $query = $extention = '';
757
+ $url_tab = parse_url( $string );
758
+ if ( isset( $url_tab['query'] ) ) {
759
+ $query = '?' . $url_tab['query'];
760
+ }
761
+ $path_parts = pathinfo( $string );
762
+ $path = $path_parts['dirname'];
763
+ $file = rawurldecode( $path_parts['filename'] );
764
+ $extention = pathinfo( $url_tab['path'], PATHINFO_EXTENSION );
765
+ if ( ! empty( $extention ) ) {
766
+ $extention = '.' . $extention;
767
+ } else {
768
+ if ( isset( $path_parts['extension'] ) ) {
769
+ $extention = '.' . $path_parts['extension'];
770
  }
771
  }
 
 
 
 
 
 
 
 
 
 
 
 
772
 
773
+ // Return a well encoded image url
774
+ return $path . '/' . rawurlencode( $file ) . $extention . $query;
 
 
 
775
  }
776
 
777
  /**
includes/feedzy-rss-feeds.php CHANGED
@@ -104,7 +104,7 @@ class Feedzy_Rss_Feeds {
104
  */
105
  public function init() {
106
  self::$plugin_name = 'feedzy-rss-feeds';
107
- self::$version = '3.0.7';
108
  self::$instance->load_dependencies();
109
  self::$instance->set_locale();
110
  self::$instance->define_admin_hooks();
104
  */
105
  public function init() {
106
  self::$plugin_name = 'feedzy-rss-feeds';
107
+ self::$version = '3.0.8';
108
  self::$instance->load_dependencies();
109
  self::$instance->set_locale();
110
  self::$instance->define_admin_hooks();
languages/feedzy-rss-feeds.pot CHANGED
@@ -4,7 +4,7 @@ msgid ""
4
  msgstr ""
5
  "Project-Id-Version: Feedzy RSS Feeds Lite 3.0.7\n"
6
  "Report-Msgid-Bugs-To: https://github.com/Codeinwp/feedzy-rss-feeds/issues\n"
7
- "POT-Creation-Date: 2017-02-03 12:00:17+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -28,19 +28,19 @@ msgstr ""
28
  msgid "Premium"
29
  msgstr ""
30
 
31
- #: includes/abstract/feedzy-rss-feeds-admin-abstract.php:51
32
  msgid "Sorry, this feed is currently unavailable or does not exists anymore."
33
  msgstr ""
34
 
35
- #: includes/abstract/feedzy-rss-feeds-admin-abstract.php:549
36
  msgid "by"
37
  msgstr ""
38
 
39
- #: includes/abstract/feedzy-rss-feeds-admin-abstract.php:557
40
  msgid "on"
41
  msgstr ""
42
 
43
- #: includes/abstract/feedzy-rss-feeds-admin-abstract.php:559
44
  msgid "at"
45
  msgstr ""
46
 
4
  msgstr ""
5
  "Project-Id-Version: Feedzy RSS Feeds Lite 3.0.7\n"
6
  "Report-Msgid-Bugs-To: https://github.com/Codeinwp/feedzy-rss-feeds/issues\n"
7
+ "POT-Creation-Date: 2017-02-20 15:13:55+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
28
  msgid "Premium"
29
  msgstr ""
30
 
31
+ #: includes/abstract/feedzy-rss-feeds-admin-abstract.php:57
32
  msgid "Sorry, this feed is currently unavailable or does not exists anymore."
33
  msgstr ""
34
 
35
+ #: includes/abstract/feedzy-rss-feeds-admin-abstract.php:529
36
  msgid "by"
37
  msgstr ""
38
 
39
+ #: includes/abstract/feedzy-rss-feeds-admin-abstract.php:535
40
  msgid "on"
41
  msgstr ""
42
 
43
+ #: includes/abstract/feedzy-rss-feeds-admin-abstract.php:537
44
  msgid "at"
45
  msgstr ""
46
 
readme.txt CHANGED
@@ -188,6 +188,11 @@ http://docs.themeisle.com/article/567-how-to-display-rss-feed-time-and-date-in-l
188
 
189
  == Changelog ==
190
 
 
 
 
 
 
191
  = 3.0.6 - 27/01/2017 =
192
  * Added feedzy_feed_timestamp filter.
193
  * Fixed issue with edge cases feed urls.
188
 
189
  == Changelog ==
190
 
191
+ = 3.0.8 - 20/02/2017 =
192
+ * Added $sizes param to feedzy_thumb_output.
193
+ * Added check when title is empty.
194
+ * Fixed image encoding url.
195
+
196
  = 3.0.6 - 27/01/2017 =
197
  * Added feedzy_feed_timestamp filter.
198
  * Fixed issue with edge cases feed urls.