@@ -1692,28 +1692,34 @@ private function get_feed_item_filter( $sc, $sizes, $item, $feed_url, $index, $i
16921692 if ( ! empty ( $ thumbnail_to_use ) && is_string ( $ thumbnail_to_use ) ) {
16931693 $ img_style = '' ;
16941694
1695- if ( isset ( $ sizes ['height ' ] ) && is_numeric ( $ sizes ['height ' ] ) ) {
1696- $ img_style .= 'height: ' . esc_attr ( $ sizes ['height ' ] ) . 'px; ' ;
1695+ $ safe_height = ( isset ( $ sizes ['height ' ] ) && is_numeric ( $ sizes ['height ' ] ) && (int ) $ sizes ['height ' ] > 0 ) ? (int ) $ sizes ['height ' ] : 0 ;
1696+ $ safe_width = ( isset ( $ sizes ['width ' ] ) && is_numeric ( $ sizes ['width ' ] ) && (int ) $ sizes ['width ' ] > 0 ) ? (int ) $ sizes ['width ' ] : 0 ;
1697+ $ raw_ratio = isset ( $ sc ['aspectRatio ' ] ) ? (string ) $ sc ['aspectRatio ' ] : '' ;
1698+ $ safe_ratio = ( '' !== $ raw_ratio && preg_match ( '~^(auto|\d+(?:\.\d+)?(?:\s*/\s*\d+(?:\.\d+)?)?)$~ ' , $ raw_ratio ) ) ? $ raw_ratio : '' ;
1699+ $ has_valid_ratio = ( '' !== $ safe_ratio && '1 ' !== $ safe_ratio );
1700+
1701+ if ( $ safe_height > 0 ) {
1702+ $ img_style .= 'height: ' . $ safe_height . 'px; ' ;
16971703 }
16981704
1699- if ( isset ( $ sc [ ' aspectRatio ' ] ) && ' 1 ' !== $ sc [ ' aspectRatio ' ] ) {
1700- $ img_style .= 'aspect-ratio: ' . esc_attr ( $ sc [ ' aspectRatio ' ] ) . '; object-fit: fill; ' ;
1705+ if ( $ has_valid_ratio ) {
1706+ $ img_style .= 'aspect-ratio: ' . $ safe_ratio . '; object-fit: fill; ' ;
17011707 }
1702-
1708+
17031709 if (
1704- isset ( $ sizes [ ' width ' ] ) && is_numeric ( $ sizes [ ' width ' ] ) &&
1710+ $ safe_width > 0 &&
17051711 (
1706- $ sizes [ ' width ' ] !== $ sizes [ ' height ' ] || // Note: Custom modification via filters.
1712+ $ safe_width !== $ safe_height ||
17071713 (
1708- isset ( $ sc [ ' aspectRatio ' ] ) &&
1714+ '' !== $ safe_ratio &&
17091715 (
1710- ( 'auto ' === $ sc [ ' aspectRatio ' ] && $ amp_running ) || // Note: AMP compatibility. Auto without `height` breaks the layout.
1711- '1 ' === $ sc [ ' aspectRatio ' ] // Note: Backward compatiblity.
1716+ ( 'auto ' === $ safe_ratio && $ amp_running ) ||
1717+ '1 ' === $ safe_ratio // Note: Backward compatiblity.
17121718 )
17131719 )
17141720 )
17151721 ) {
1716- $ img_style .= 'width: ' . esc_attr ( $ sizes [ ' width ' ] ) . 'px; ' ;
1722+ $ img_style .= 'width: ' . $ safe_width . 'px; ' ;
17171723 }
17181724
17191725 $ content_thumb .= '<img decoding="async" src=" ' . esc_url ( $ thumbnail_to_use ) . '" title=" ' . esc_attr ( $ item ->get_title () ) . '" style=" ' . esc_attr ( $ img_style ) . '"> ' ;
@@ -1872,13 +1878,17 @@ private function get_feed_item_filter( $sc, $sizes, $item, $feed_url, $index, $i
18721878 $ item_content = esc_html__ ( 'Post Content ' , 'feedzy-rss-feeds ' );
18731879 }
18741880
1875- $ img_style = '' ;
1876- if ( isset ( $ sizes ['height ' ] ) ) {
1877- $ img_style = 'height: ' . esc_attr ( $ sizes ['height ' ] ) . 'px; ' ;
1878- if ( isset ( $ sc ['aspectRatio ' ] ) && '1 ' !== $ sc ['aspectRatio ' ] ) {
1879- $ img_style .= 'aspect-ratio: ' . esc_attr ( $ sc ['aspectRatio ' ] ) . '; ' ;
1880- } elseif ( isset ( $ sizes ['width ' ] ) ) {
1881- $ img_style .= 'width: ' . esc_attr ( $ sizes ['width ' ] ) . 'px; ' ;
1881+ $ img_style = '' ;
1882+ $ safe_height_val = ( isset ( $ sizes ['height ' ] ) && is_numeric ( $ sizes ['height ' ] ) && (int ) $ sizes ['height ' ] > 0 ) ? (int ) $ sizes ['height ' ] : 0 ;
1883+ $ safe_width_val = ( isset ( $ sizes ['width ' ] ) && is_numeric ( $ sizes ['width ' ] ) && (int ) $ sizes ['width ' ] > 0 ) ? (int ) $ sizes ['width ' ] : 0 ;
1884+ $ raw_ratio_val = isset ( $ sc ['aspectRatio ' ] ) ? (string ) $ sc ['aspectRatio ' ] : '' ;
1885+ $ safe_ratio_val = ( '' !== $ raw_ratio_val && preg_match ( '~^(auto|\d+(?:\.\d+)?(?:\s*/\s*\d+(?:\.\d+)?)?)$~ ' , $ raw_ratio_val ) ) ? $ raw_ratio_val : '' ;
1886+ if ( $ safe_height_val > 0 ) {
1887+ $ img_style = 'height: ' . $ safe_height_val . 'px; ' ;
1888+ if ( '' !== $ safe_ratio_val && '1 ' !== $ safe_ratio_val ) {
1889+ $ img_style .= 'aspect-ratio: ' . $ safe_ratio_val . '; ' ;
1890+ } elseif ( $ safe_width_val > 0 ) {
1891+ $ img_style .= 'width: ' . $ safe_width_val . 'px; ' ;
18821892 }
18831893 }
18841894
0 commit comments