@@ -620,6 +620,8 @@ public function get_short_code_attributes( $atts ) {
620620 'default ' => '' ,
621621 // thumbs pixel size.
622622 'size ' => '' ,
623+ // default aspect ratio for the image.
624+ 'aspectRatio ' => '1 ' ,
623625 // only display item if title contains specific keywords (Use comma(,) and plus(+) keyword).
624626 'keywords_title ' => '' ,
625627 // only display item if title OR content contains specific keywords (Use comma(,) and plus(+) keyword).
@@ -1404,44 +1406,54 @@ private function get_feed_item_filter( $sc, $sizes, $item, $feed_url, $index, $i
14041406 $ item_link = $ item ->get_feed ()->get_permalink ();
14051407 }
14061408 }
1407- $ new_link = apply_filters ( 'feedzy_item_url_filter ' , $ item_link , $ sc , $ item );
1409+ $ new_link = apply_filters ( 'feedzy_item_url_filter ' , $ item_link , $ sc , $ item );
1410+ $ amp_running = function_exists ( 'amp_is_request ' ) && amp_is_request ();
1411+ $ content_thumb = '' ;
14081412
1409- // Fetch image thumbnail.
1413+ $ thumbnail_to_use = '' ;
14101414 if ( 'yes ' === $ sc ['thumb ' ] || 'auto ' === $ sc ['thumb ' ] ) {
1411- $ the_thumbnail = $ this ->feedzy_retrieve_image ( $ item , $ sc );
1412- $ content_thumb = '' ;
1415+ // Fetch image thumbnail.
1416+ $ thumbnail_to_use = $ this ->feedzy_retrieve_image ( $ item , $ sc );
1417+ $ thumbnail_to_use = $ this ->feedzy_image_encode ( $ thumbnail_to_use );
1418+
1419+ if ( empty ( $ thumbnail_to_use ) && 'yes ' === $ sc ['thumb ' ] ) {
1420+ $ thumbnail_to_use = $ sc ['default ' ];
1421+ }
1422+ } else {
1423+ $ thumbnail_to_use = $ sc ['default ' ];
1424+ }
1425+
1426+ if ( ! empty ( $ thumbnail_to_use ) && is_string ( $ thumbnail_to_use ) ) {
1427+ $ img_style = '' ;
1428+
1429+ if ( isset ( $ sizes ['height ' ] ) && is_numeric ( $ sizes ['height ' ] ) ) {
1430+ $ img_style .= 'height: ' . $ sizes ['height ' ] . 'px; ' ;
1431+ }
1432+
1433+ if ( isset ( $ sc ['aspectRatio ' ] ) && '1 ' !== $ sc ['aspectRatio ' ] ) {
1434+ $ img_style .= 'aspect-ratio: ' . $ sc ['aspectRatio ' ] . '; object-fit: fill; ' ;
1435+ }
1436+
14131437 if (
1414- is_string ( $ the_thumbnail ) && ! empty ( $ the_thumbnail ) &&
1438+ isset ( $ sizes [ ' width ' ] ) && is_numeric ( $ sizes [ ' width ' ] ) &&
14151439 (
1416- ' yes ' === $ sc [ ' thumb ' ] ||
1440+ $ sizes [ ' width ' ] !== $ sizes [ ' height ' ] || // Note: Custom modification via filters.
14171441 (
1418- 'auto ' === $ sc ['thumb ' ] &&
1419- ! strpos ( $ the_thumbnail , 'img/feedzy.svg ' )
1442+ isset ( $ sc ['aspectRatio ' ] ) &&
1443+ (
1444+ ( 'auto ' === $ sc ['aspectRatio ' ] && $ amp_running ) || // Note: AMP compatibility. Auto without `height` breaks the layout.
1445+ '1 ' === $ sc ['aspectRatio ' ] // Note: Backward compatiblity.
1446+ )
14201447 )
14211448 )
14221449 ) {
1423- $ the_thumbnail = $ this ->feedzy_image_encode ( $ the_thumbnail );
1424- $ content_thumb .= '<span class="fetched" style="background-image: url( \'' . $ the_thumbnail . '\');" title=" ' . esc_attr ( $ item ->get_title () ) . '"></span> ' ;
1425- if ( ! isset ( $ sc ['amp ' ] ) || 'no ' !== $ sc ['amp ' ] ) {
1426- $ content_thumb .= '<amp-img width=" ' . $ sizes ['width ' ] . '" height=" ' . $ sizes ['height ' ] . '" src=" ' . $ the_thumbnail . '"> ' ;
1427- }
1450+ $ img_style .= 'width: ' . $ sizes ['width ' ] . 'px; ' ;
14281451 }
14291452
1430- if ( empty ( $ the_thumbnail ) && 'yes ' === $ sc ['thumb ' ] ) {
1431- $ content_thumb .= '<span class="default" style="background-image:url( ' . $ sc ['default ' ] . ');" title=" ' . esc_attr ( $ item ->get_title () ) . '"></span> ' ;
1432- if ( ! isset ( $ sc ['amp ' ] ) || 'no ' !== $ sc ['amp ' ] ) {
1433- $ content_thumb .= '<amp-img width=" ' . $ sizes ['width ' ] . '" height=" ' . $ sizes ['height ' ] . '" src=" ' . $ sc ['default ' ] . '"> ' ;
1434- }
1435- }
1436- $ content_thumb = apply_filters ( 'feedzy_thumb_output ' , $ content_thumb , $ feed_url , $ sizes , $ item );
1437- } else {
1438- $ content_thumb = '' ;
1439- $ content_thumb .= '<span class="default" style="width: ' . $ sizes ['width ' ] . 'px; height: ' . $ sizes ['height ' ] . 'px; background-image:url( ' . $ sc ['default ' ] . ');" title=" ' . $ item ->get_title () . '"></span> ' ;
1440- if ( ! isset ( $ sc ['amp ' ] ) || 'no ' !== $ sc ['amp ' ] ) {
1441- $ content_thumb .= '<amp-img width=" ' . $ sizes ['width ' ] . '" height=" ' . $ sizes ['height ' ] . '" src=" ' . $ sc ['default ' ] . '"> ' ;
1442- }
1443- $ content_thumb = apply_filters ( 'feedzy_thumb_output ' , $ content_thumb , $ feed_url , $ sizes , $ item );
1453+ $ content_thumb .= '<img decoding="async" src=" ' . $ thumbnail_to_use . '" title=" ' . esc_attr ( $ item ->get_title () ) . '" style=" ' . $ img_style . '"> ' ;
1454+ $ content_thumb = apply_filters ( 'feedzy_thumb_output ' , $ content_thumb , $ feed_url , $ sizes , $ item );
14441455 }
1456+
14451457 $ content_title = html_entity_decode ( $ item ->get_title (), ENT_QUOTES , 'UTF-8 ' );
14461458 if ( is_numeric ( $ sc ['title ' ] ) ) {
14471459 $ length = intval ( $ sc ['title ' ] );
@@ -1593,11 +1605,22 @@ private function get_feed_item_filter( $sc, $sizes, $item, $feed_url, $index, $i
15931605 if ( empty ( $ item_content ) ) {
15941606 $ item_content = esc_html__ ( 'Post Content ' , 'feedzy-rss-feeds ' );
15951607 }
1608+
1609+ $ img_style = '' ;
1610+ if ( isset ( $ sizes ['height ' ] ) ) {
1611+ $ img_style = 'height: ' . $ sizes ['height ' ] . 'px; ' ;
1612+ if ( isset ( $ sc ['aspectRatio ' ] ) && '1 ' !== $ sc ['aspectRatio ' ] ) {
1613+ $ img_style .= 'aspect-ratio: ' . $ sc ['aspectRatio ' ] . '; ' ;
1614+ } elseif ( isset ( $ sizes ['width ' ] ) ) {
1615+ $ img_style .= 'width: ' . $ sizes ['width ' ] . 'px; ' ;
1616+ }
1617+ }
1618+
15961619 $ item_array = array (
15971620 'feed_url ' => $ item ->get_feed ()->subscribe_url (),
15981621 'item_unique_hash ' => wp_hash ( $ item ->get_permalink () ),
15991622 'item_img_class ' => 'rss_image ' ,
1600- 'item_img_style ' => ' width: ' . $ sizes [ ' width ' ] . ' px; height: ' . $ sizes [ ' height ' ] . ' px; ' ,
1623+ 'item_img_style ' => $ img_style ,
16011624 'item_url ' => $ new_link ,
16021625 'item_url_target ' => $ sc ['target ' ],
16031626 'item_url_follow ' => isset ( $ sc ['follow ' ] ) && 'yes ' === $ sc ['follow ' ] ? 'nofollow ' : '' ,
0 commit comments