Skip to content

Commit

Permalink
Merge branch 'development' into fix/title-with-chain-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Apr 12, 2024
2 parents 9cf9c57 + 6565cc0 commit 925ad29
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 24 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
##### [Version 4.4.7](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.6...v4.4.7) (2024-04-10)

### Fixes
- **Updated internal dependencies:** Enhanced performance and security.
- **Resolved mime_content_type error:** Fixed a bug where an error was generated if the server does not have mime_content_type enabled.
- **Improved image URL handling:** Addressed an issue with importing images whose URLs contain spaces.

##### [Version 4.4.6](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.5...v4.4.6) (2024-04-01)

### Improvements
- **Updated internal dependencies**

##### [Version 4.4.5](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.4...v4.4.5) (2024-03-29)

### Fixes
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion css/feedzy-rss-feeds.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* feedzy-rss-feeds.css
* Feedzy RSS Feed
* Copyright: (c) 2016 Themeisle, themeisle.com
* Version: 4.4.5
* Version: 4.4.7
* Plugin Name: FEEDZY RSS Feeds
* Plugin URI: http://themeisle.com/plugins/feedzy-rss-feeds/
* Author: Themeisle
Expand Down
10 changes: 5 additions & 5 deletions cypress/e2e/gutenberg/gutenberg_free.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ describe('Test Free - gutenberg', function() {
cy.get('.edit-post-visual-editor__post-title-wrapper .editor-post-title__input').type(PREFIX);

// insert a feedzy block
cy.get('div.edit-post-header__toolbar button.edit-post-header-toolbar__inserter-toggle').click({force:true});
cy.get('.edit-post-editor__inserter-panel-content').then(function ($popup) {
cy.wrap($popup).find('.components-search-control__input').type('feedzy');
cy.get('div.edit-post-header__toolbar button.editor-document-tools__inserter-toggle').click({force:true});
cy.get('.editor-inserter-sidebar__content').then(function ($popup) {
cy.wrap($popup).find('.components-search-control input.components-input-control__input').type('feedzy');
cy.wrap($popup).find('.block-editor-block-types-list .editor-block-list-item-feedzy-rss-feeds-feedzy-block').should('have.length', 1);
cy.wrap($popup).find('.block-editor-block-types-list .editor-block-list-item-feedzy-rss-feeds-feedzy-block').click({force:true});
});
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Test Free - gutenberg', function() {
// item options
cy.get('div.edit-post-sidebar div.components-panel__body.feedzy-advanced-options div.components-base-control.feedzy-meta input.components-text-control__input').type(gutenberg.meta, {force: true});
cy.get('div.edit-post-sidebar div.components-panel__body.feedzy-advanced-options div.components-base-control.feedzy-multiple-meta input.components-text-control__input').type(gutenberg.multiple_meta, {force: true});
/* for pro
/* for pro
cy.get('div.edit-post-sidebar div.components-panel__body.feedzy-advanced-options div.components-base-control.feedzy-include input.components-text-control__input').type(gutenberg.include);
cy.get('div.edit-post-sidebar div.components-panel__body.feedzy-advanced-options div.components-base-control.feedzy-ban input.components-text-control__input').type(gutenberg.ban);
*/
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('Test Free - gutenberg', function() {
// item options
cy.get('div.edit-post-sidebar div.components-panel__body.feedzy-advanced-options div.components-base-control.feedzy-meta input.components-text-control__input').should('have.value', gutenberg.meta);
cy.get('div.edit-post-sidebar div.components-panel__body.feedzy-advanced-options div.components-base-control.feedzy-multiple-meta input.components-text-control__input').should('have.value', gutenberg.multiple_meta);
/* for pro
/* for pro
cy.get('div.edit-post-sidebar div.components-panel__body.feedzy-advanced-options div.components-base-control.feedzy-include input.components-text-control__input').should('have.value', gutenberg.include);
cy.get('div.edit-post-sidebar div.components-panel__body.feedzy-advanced-options div.components-base-control.feedzy-ban input.components-text-control__input').should('have.value', gutenberg.ban);
*/
Expand Down
2 changes: 1 addition & 1 deletion feedzy-rss-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Plugin Name: Feedzy RSS Feeds Lite
* Plugin URI: https://themeisle.com/plugins/feedzy-rss-feeds/
* Description: A small and lightweight RSS aggregator plugin. Fast and very easy to use, it allows you to aggregate multiple RSS feeds into your WordPress site through fully customizable shortcodes & widgets.
* Version: 4.4.5
* Version: 4.4.7
* Author: Themeisle
* Author URI: http://themeisle.com
* License: GPL-2.0+
Expand Down
4 changes: 2 additions & 2 deletions includes/abstract/feedzy-rss-feeds-admin-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ public function get_usage_data( $data ) {
*/
public function feedzy_default_error_notice( $errors, $feed, $feed_url ) {
global $post;
// Show the error message only if the user who has created this post (which contains the feed) is logged in.
// Show the error message only if the user who has created this post (which contains the feed) is logged in and the user has admin privileges.
// Or if this is in the dry run window.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
$show_error = is_admin() || ( is_user_logged_in() && $post && get_current_user_id() == $post->post_author );
$show_error = is_admin() || ( is_user_logged_in() && $post && current_user_can( 'manage_options' ) && get_current_user_id() == $post->post_author );
$error_msg = '';

if ( is_array( $errors ) ) {
Expand Down
34 changes: 32 additions & 2 deletions includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,25 @@ public function tryReuseExistingFeaturedImage( &$result, $title_feed, $post_id =
return true;
}

/**
* Will retireve the file type of a file by its URL.
*
* @param string $url The URL of the file.
*
* @return string
*/
private function get_file_type_by_url( $url ) {
$response = wp_remote_get( $url );

// wp_remote_retrieve_header can return an array if there are multiple headers with the same name
$content_type = wp_remote_retrieve_header( $response, 'content-type' );
if ( is_array( $content_type ) ) {
$content_type = $content_type[0];
}

return $content_type;
}

/**
* Downloads and sets a post featured image if possible.
*
Expand All @@ -2004,7 +2023,8 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title

if ( ! $id ) {

if ( filter_var( $img_source_url, FILTER_VALIDATE_URL ) === false ) {
// We escape the URL to ensure that valid URLs are passed by the filter.
if ( filter_var( esc_url( $img_source_url ), FILTER_VALIDATE_URL ) === false ) {
$import_errors[] = 'Invalid Featured Image URL: ' . $img_source_url;
return false;
}
Expand All @@ -2024,7 +2044,17 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title
return false;
}

$type = mime_content_type( $local_file );
$type = '';
// try first to get the file type using the built-in function if available.
if ( function_exists( 'mime_content_type' ) ) {
$type = mime_content_type( $local_file );
}

// if the file type is not found, try to get it from the URL.
if ( empty( $type ) ) {
$type = $this->get_file_type_by_url( $img_source_url );
}

// the file is downloaded with a .tmp extension
// if the URL mentions the extension of the file, the upload succeeds
// but if the URL is like https://source.unsplash.com/random, then the upload fails
Expand Down
2 changes: 1 addition & 1 deletion includes/feedzy-rss-feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static function instance() {
*/
public function init() {
self::$plugin_name = 'feedzy-rss-feeds';
self::$version = '4.4.5';
self::$version = '4.4.7';
self::$instance->load_dependencies();
self::$instance->set_locale();
self::$instance->define_admin_hooks();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "feedzy-rss-feeds",
"version": "4.4.5",
"version": "4.4.7",
"description": "Feedzy RSS Feeds - lite version",
"repository": {
"type": "git",
Expand Down
20 changes: 19 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: themeisle,codeinwp,hardeepasrani,rozroz
Tags: rss aggregator, news aggregator, autoblogging, feed to post, rss import
Requires at least: 6.0
Requires PHP: 7.2
Tested up to: 6.4
Tested up to: 6.5
Stable tag: trunk
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -493,6 +493,24 @@ You have to check first if your feed is valid. Please test it here: https://vali

== Changelog ==

##### [Version 4.4.7](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.6...v4.4.7) (2024-04-10)

### Fixes
- **Updated internal dependencies:** Enhanced performance and security.
- **Resolved mime_content_type error:** Fixed a bug where an error was generated if the server does not have mime_content_type enabled.
- **Improved image URL handling:** Addressed an issue with importing images whose URLs contain spaces.




##### [Version 4.4.6](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.5...v4.4.6) (2024-04-01)

### Improvements
- **Updated internal dependencies**




##### [Version 4.4.5](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.4...v4.4.5) (2024-03-29)

### Fixes
Expand Down
62 changes: 62 additions & 0 deletions tests/test-image-import.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* WordPress unit test plugin.
*
* @package feedzy-rss-feeds-pro
* @subpackage Tests
* @copyright Copyright (c) 2024, Bogdan Preda
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 4.4.6
*/
class Test_Image_Import extends WP_UnitTestCase {

/**
* Test that the image import allows valid image URLs and logs errors for invalid ones.
* Test introduced to cover this issue https://github.com/Codeinwp/feedzy-rss-feeds/issues/917.
* @since 4.4.6
*/
public function test_image_import_url() {
$feedzy = new Feedzy_Rss_Feeds_Import( 'feedzy-rss-feeds', '1.2.0' );

$reflector = new ReflectionClass( $feedzy );
$try_save_featured_image = $reflector->getMethod( 'try_save_featured_image' );
$try_save_featured_image->setAccessible( true );

// Check that NON-IMAGE URL returns invalid
$import_errors = array();
$import_info = array();
$arguments = array( 'a random string', 0, 'Post Title', &$import_errors, &$import_info, array() );
$response = $try_save_featured_image->invokeArgs( $feedzy, $arguments );

$this->assertFalse( $response );

$this->assertTrue( count( $import_errors ) > 0 );
$this->assertEquals( 'Invalid Featured Image URL: a random string', $import_errors[0] );


// For the next test, we will use a valid URL, but the image does not exist. We will check that the error is logged and is the expected one.
add_filter( 'themeisle_log_event', function( $product, $message, $type, $file, $line ) {
if ( $type === 'error' ) {
$this->assertTrue( strpos( $message, 'Unable to download file' ) !== false );
}
}, 10, 5 );

$import_errors = array();
$import_info = array();
$arguments = array( 'https://example.com/path_to_image/image.jpeg', 0, 'Post Title', &$import_errors, &$import_info, array() );
$response = $try_save_featured_image->invokeArgs( $feedzy, $arguments );

// expected response is false because the image does not exist, but the URL is valid so no $import_errors should be set.
$this->assertFalse( $response );
$this->assertTrue( empty( $import_errors ) );

$import_errors = array();
$import_info = array();
$arguments = array( 'https://example.com/path_to_image/image w space in name.jpeg', 0, 'Post Title', &$import_errors, &$import_info, array() );
$response = $try_save_featured_image->invokeArgs( $feedzy, $arguments );

// expected response is false because the image does not exist, but the URL is valid so no $import_errors should be set.
$this->assertFalse( $response );
$this->assertTrue( empty( $import_errors ) );
}
}
35 changes: 31 additions & 4 deletions tests/test-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
class Test_Feedzy_Import extends WP_UnitTestCase {

private $import_limit = 1;

/**
* Sets up the test methods.
*/
Expand All @@ -28,10 +30,10 @@ public function setUp(): void {
* @access public
* @dataProvider importDataProvider
*/
public function test_feedzy_imports( $random_name1, $random_name2, $urls, $magic_tags = '[#item_content]', $use_filter = false ) {
public function test_feedzy_imports( $random_name1, $random_name2, $urls, $magic_tags = '[#item_content]', $use_filter = false, $type = 'post' ) {
do_action( 'init' );

$num_items = 1;
$num_items = $this->import_limit;
$user_id = $this->factory->user->create(
array(
'role' => 'administrator',
Expand Down Expand Up @@ -76,7 +78,7 @@ public function test_feedzy_imports( $random_name1, $random_name2, $urls, $magic
$_POST['feedzy_post_nonce'] = wp_create_nonce( 'feedzy_post_nonce' );
$_POST['post_type'] = 'feedzy_imports';
$_POST['feedzy_meta_data']['source'] = $slug;
$_POST['feedzy_meta_data']['import_post_type'] = 'post';
$_POST['feedzy_meta_data']['import_post_type'] = $type;
$_POST['feedzy_meta_data']['import_post_term'] = 'category_' . $category_id;
$_POST['feedzy_meta_data']['import_post_status'] = 'publish';
$_POST['feedzy_meta_data']['inc_key'] = '';
Expand Down Expand Up @@ -106,7 +108,7 @@ public function test_feedzy_imports( $random_name1, $random_name2, $urls, $magic
$import_custom_fields = get_post_meta( $p->ID, 'imports_custom_fields', true );
$import_feed_limit = get_post_meta( $p->ID, 'import_feed_limit', true );

$this->assertEquals( 'post', $import_post_type );
$this->assertEquals( $type, $import_post_type );
$this->assertEquals( 'category_' . $category_id, $import_post_term );
$this->assertEquals( 'publish', $import_post_status );
$this->assertEquals( $slug, $source );
Expand Down Expand Up @@ -174,6 +176,13 @@ public function test_feedzy_imports( $random_name1, $random_name2, $urls, $magic

do_action( 'feedzy_cron', '1' );

/**
* We bail for non post types as the subsequent tests might not apply.
*/
if ( $type !== 'post' ) {
return;
}

$created = get_posts(
array(
'numberposts' => $num_items,
Expand Down Expand Up @@ -276,6 +285,24 @@ public function test_canonical_url( $post ) {

}

/**
* Test the attachment import works and the mime type is correct.
*/
public function test_attachement_import() {
$this->test_feedzy_imports( $this->get_rand_name(), $this->get_rand_name(), $this->get_two_rand_feeds(), '[#item_content]', false, 'attachment' );
$args = array(
'post_type' =>'attachment',
'numberposts' => -1,
'orderby' => 'date',
'order' => 'DESC',
);
$attachments = get_posts($args);
$this->assertEquals( $this->import_limit, count( $attachments ) );

$this->assertTrue( isset( $attachments[0]->post_mime_type ) );
$this->assertTrue( $attachments[0]->post_mime_type === 'image/jpeg' );
}


/**
* Utility method to generate a random 5 char string.
Expand Down
19 changes: 19 additions & 0 deletions tests/test-post-access.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,23 @@ public function test_custom_post_access() {

}

public function test_contributor_user_with_errors() {
$feedzy = new Feedzy_Rss_Feeds_Admin('feedzy', 'latest');
$contributor_id = $this->factory->user->create(
array(
'role' => 'contributor',
)
);
wp_set_current_user( $contributor_id );
$post_id = $this->factory->post->create( array( 'post_author' => get_current_user_id() ) );
$GLOBALS['post'] = get_post( $post_id );
// Mock feed object and errors.
$feed = (object) array( 'multifeed_url' => array( 'http://example.com/feed' ) );
$errors = array( 'Error 1' );


$actual_output = $feedzy->feedzy_default_error_notice( $errors, $feed, 'http://example.com/feed' );

$this->assertEquals( '', $actual_output );
}
}

0 comments on commit 925ad29

Please sign in to comment.