diff --git a/includes/abstract/feedzy-rss-feeds-admin-abstract.php b/includes/abstract/feedzy-rss-feeds-admin-abstract.php
index 65ff80f13..0027ae1ea 100644
--- a/includes/abstract/feedzy-rss-feeds-admin-abstract.php
+++ b/includes/abstract/feedzy-rss-feeds-admin-abstract.php
@@ -620,6 +620,8 @@ public function get_short_code_attributes( $atts ) {
'default' => '',
// thumbs pixel size.
'size' => '',
+ // default aspect ratio for the image.
+ 'aspectRatio' => '1',
// only display item if title contains specific keywords (Use comma(,) and plus(+) keyword).
'keywords_title' => '',
// 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
$item_link = $item->get_feed()->get_permalink();
}
}
- $new_link = apply_filters( 'feedzy_item_url_filter', $item_link, $sc, $item );
+ $new_link = apply_filters( 'feedzy_item_url_filter', $item_link, $sc, $item );
+ $amp_running = function_exists( 'amp_is_request' ) && amp_is_request();
+ $content_thumb = '';
- // Fetch image thumbnail.
+ $thumbnail_to_use = '';
if ( 'yes' === $sc['thumb'] || 'auto' === $sc['thumb'] ) {
- $the_thumbnail = $this->feedzy_retrieve_image( $item, $sc );
- $content_thumb = '';
+ // Fetch image thumbnail.
+ $thumbnail_to_use = $this->feedzy_retrieve_image( $item, $sc );
+ $thumbnail_to_use = $this->feedzy_image_encode( $thumbnail_to_use );
+
+ if ( empty( $thumbnail_to_use ) && 'yes' === $sc['thumb'] ) {
+ $thumbnail_to_use = $sc['default'];
+ }
+ } else {
+ $thumbnail_to_use = $sc['default'];
+ }
+
+ if ( ! empty( $thumbnail_to_use ) && is_string( $thumbnail_to_use ) ) {
+ $img_style = '';
+
+ if ( isset( $sizes['height'] ) && is_numeric( $sizes['height'] ) ) {
+ $img_style .= 'height:' . $sizes['height'] . 'px;';
+ }
+
+ if ( isset( $sc['aspectRatio'] ) && '1' !== $sc['aspectRatio'] ) {
+ $img_style .= 'aspect-ratio:' . $sc['aspectRatio'] . '; object-fit: fill;';
+ }
+
if (
- is_string( $the_thumbnail ) && ! empty( $the_thumbnail ) &&
+ isset( $sizes['width'] ) && is_numeric( $sizes['width'] ) &&
(
- 'yes' === $sc['thumb'] ||
+ $sizes['width'] !== $sizes['height'] || // Note: Custom modification via filters.
(
- 'auto' === $sc['thumb'] &&
- ! strpos( $the_thumbnail, 'img/feedzy.svg' )
+ isset( $sc['aspectRatio'] ) &&
+ (
+ ( 'auto' === $sc['aspectRatio'] && $amp_running ) || // Note: AMP compatibility. Auto without `height` breaks the layout.
+ '1' === $sc['aspectRatio'] // Note: Backward compatiblity.
+ )
)
)
) {
- $the_thumbnail = $this->feedzy_image_encode( $the_thumbnail );
- $content_thumb .= '';
- if ( ! isset( $sc['amp'] ) || 'no' !== $sc['amp'] ) {
- $content_thumb .= '';
- }
+ $img_style .= 'width:' . $sizes['width'] . 'px;';
}
- if ( empty( $the_thumbnail ) && 'yes' === $sc['thumb'] ) {
- $content_thumb .= '';
- if ( ! isset( $sc['amp'] ) || 'no' !== $sc['amp'] ) {
- $content_thumb .= '';
- }
- }
- $content_thumb = apply_filters( 'feedzy_thumb_output', $content_thumb, $feed_url, $sizes, $item );
- } else {
- $content_thumb = '';
- $content_thumb .= '';
- if ( ! isset( $sc['amp'] ) || 'no' !== $sc['amp'] ) {
- $content_thumb .= '';
- }
- $content_thumb = apply_filters( 'feedzy_thumb_output', $content_thumb, $feed_url, $sizes, $item );
+ $content_thumb .= '
';
+ $content_thumb = apply_filters( 'feedzy_thumb_output', $content_thumb, $feed_url, $sizes, $item );
}
+
$content_title = html_entity_decode( $item->get_title(), ENT_QUOTES, 'UTF-8' );
if ( is_numeric( $sc['title'] ) ) {
$length = intval( $sc['title'] );
@@ -1593,11 +1605,22 @@ private function get_feed_item_filter( $sc, $sizes, $item, $feed_url, $index, $i
if ( empty( $item_content ) ) {
$item_content = esc_html__( 'Post Content', 'feedzy-rss-feeds' );
}
+
+ $img_style = '';
+ if ( isset( $sizes['height'] ) ) {
+ $img_style = 'height:' . $sizes['height'] . 'px;';
+ if ( isset( $sc['aspectRatio'] ) && '1' !== $sc['aspectRatio'] ) {
+ $img_style .= 'aspect-ratio:' . $sc['aspectRatio'] . ';';
+ } elseif ( isset( $sizes['width'] ) ) {
+ $img_style .= 'width:' . $sizes['width'] . 'px;';
+ }
+ }
+
$item_array = array(
'feed_url' => $item->get_feed()->subscribe_url(),
'item_unique_hash' => wp_hash( $item->get_permalink() ),
'item_img_class' => 'rss_image',
- 'item_img_style' => 'width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px;',
+ 'item_img_style' => $img_style,
'item_url' => $new_link,
'item_url_target' => $sc['target'],
'item_url_follow' => isset( $sc['follow'] ) && 'yes' === $sc['follow'] ? 'nofollow' : '',
diff --git a/includes/gutenberg/feedzy-rss-feeds-gutenberg-block.php b/includes/gutenberg/feedzy-rss-feeds-gutenberg-block.php
index 8752e324f..8edb37c5a 100644
--- a/includes/gutenberg/feedzy-rss-feeds-gutenberg-block.php
+++ b/includes/gutenberg/feedzy-rss-feeds-gutenberg-block.php
@@ -171,6 +171,10 @@ public function feedzy_register_block_type() {
'type' => 'number',
'default' => 150,
),
+ 'aspectRatio' => array(
+ 'type' => 'string',
+ 'default' => '1',
+ ),
'price' => array(
'type' => 'boolean',
'default' => true,
diff --git a/js/FeedzyBlock/Editor.js b/js/FeedzyBlock/Editor.js
index 91a6022f1..05f6efee5 100644
--- a/js/FeedzyBlock/Editor.js
+++ b/js/FeedzyBlock/Editor.js
@@ -53,6 +53,7 @@ class Editor extends Component {
this.onThumb = this.onThumb.bind(this);
this.onDefault = this.onDefault.bind(this);
this.onSize = this.onSize.bind(this);
+ this.onAspectRatio = this.onAspectRatio.bind(this);
this.onReferralURL = this.onReferralURL.bind(this);
this.onColumns = this.onColumns.bind(this);
this.onTemplate = this.onTemplate.bind(this);
@@ -326,6 +327,9 @@ class Editor extends Component {
onSize(value) {
this.props.setAttributes({ size: !value ? 150 : Number(value) });
}
+ onAspectRatio(value) {
+ this.props.setAttributes({ aspectRatio: value });
+ }
onReferralURL(value) {
window.tiTrk?.with('feedzy').add({ feature: 'block-referral-url' });
this.props.setAttributes({ referral_url: value });
@@ -669,9 +673,9 @@ class Editor extends Component {
-
+ />
diff --git a/js/FeedzyBlock/attributes.js b/js/FeedzyBlock/attributes.js
index 79a831595..c39c401c3 100644
--- a/js/FeedzyBlock/attributes.js
+++ b/js/FeedzyBlock/attributes.js
@@ -117,7 +117,7 @@ const attributes = {
disableStyle: {
type: 'boolean',
default: false,
- },
+ },
follow: {
type: 'string',
default: 'no',
@@ -137,7 +137,11 @@ const attributes = {
_dry_run_tags_: {
type: 'string',
default: '',
- }
+ },
+ aspectRatio: {
+ type: 'string',
+ default: '1',
+ },
};
-export default attributes;
\ No newline at end of file
+export default attributes;
diff --git a/js/FeedzyBlock/inspector.js b/js/FeedzyBlock/inspector.js
index 1d68c3a9c..456552228 100644
--- a/js/FeedzyBlock/inspector.js
+++ b/js/FeedzyBlock/inspector.js
@@ -660,6 +660,79 @@ class Inspector extends Component {
this.props.edit.onSize
}
/>
+
)}
diff --git a/tests/e2e/specs/classic-block.spec.js b/tests/e2e/specs/classic-block.spec.js
new file mode 100644
index 000000000..e5a9c38e1
--- /dev/null
+++ b/tests/e2e/specs/classic-block.spec.js
@@ -0,0 +1,65 @@
+/**
+ * WordPress dependencies
+ */
+import { test, expect } from '@wordpress/e2e-test-utils-playwright';
+
+test.describe('Feedzy Classic Block', () => {
+ test('check aspect ratio default', async ({ editor, page, admin }) => {
+ await admin.createNewPost();
+
+ await editor.insertBlock({
+ name: 'feedzy-rss-feeds/feedzy-block',
+ attributes: {
+ feeds: 'https://www.nasa.gov/feeds/iotd-feed/',
+ max: 1,
+ },
+ });
+
+ const postId = await editor.publishPost();
+ await page.goto(`/?p=${postId}`);
+
+ const image = page.locator('.feedzy-rss .rss_image img');
+ await expect(image).toHaveAttribute(
+ 'style',
+ 'height:150px;width:150px;'
+ );
+ });
+
+ test('check aspect ratio (3/2)', async ({ editor, page, admin }) => {
+ await admin.createNewPost();
+
+ await editor.insertBlock({
+ name: 'feedzy-rss-feeds/feedzy-block',
+ attributes: {
+ aspectRatio: '3/2',
+ feeds: 'https://www.nasa.gov/feeds/iotd-feed/',
+ max: 1,
+ },
+ });
+
+ const postId = await editor.publishPost();
+ await page.goto(`/?p=${postId}`);
+
+ const image = page.locator('.feedzy-rss .rss_image img');
+ await expect(image).toHaveAttribute('style', /aspect-ratio:\s*3\/2;/i);
+ });
+
+ test('check aspect ratio auto', async ({ editor, page, admin }) => {
+ await admin.createNewPost();
+
+ await editor.insertBlock({
+ name: 'feedzy-rss-feeds/feedzy-block',
+ attributes: {
+ aspectRatio: 'auto',
+ feeds: 'https://www.nasa.gov/feeds/iotd-feed/',
+ max: 1,
+ },
+ });
+
+ const postId = await editor.publishPost();
+ await page.goto(`/?p=${postId}`);
+
+ const image = page.locator('.feedzy-rss .rss_image img');
+ await expect(image).toHaveAttribute('style', /aspect-ratio:\s*auto;/i);
+ });
+});