From fcad23c7093fd279dbeded4db568c8d34f72bec9 Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Thu, 28 Mar 2024 14:57:01 +0200 Subject: [PATCH 01/20] feat: allow title to use chained actions --- includes/admin/feedzy-rss-feeds-actions.php | 88 +++++++++++++-------- includes/admin/feedzy-rss-feeds-import.php | 26 +++--- includes/views/import-metabox-edit.php | 2 +- js/ActionPopup/action-popup.js | 21 ++--- 4 files changed, 83 insertions(+), 54 deletions(-) diff --git a/includes/admin/feedzy-rss-feeds-actions.php b/includes/admin/feedzy-rss-feeds-actions.php index a8f94c68..30a4c677 100644 --- a/includes/admin/feedzy-rss-feeds-actions.php +++ b/includes/admin/feedzy-rss-feeds-actions.php @@ -23,11 +23,11 @@ class Feedzy_Rss_Feeds_Actions { private static $instance; /** - * Content actions. + * Serialized content actions. It can contain a mix of magic tags and simple text. * - * @var string $actions Content actions. + * @var string $raw_serialized_actions Content actions. */ - private $actions; + private $raw_serialized_actions; /** * Setting options. @@ -39,7 +39,7 @@ class Feedzy_Rss_Feeds_Actions { /** * Extract tags. * - * @var string $extract_tags Extract tags. + * @var array $extract_tags Extract tags. */ private $extract_tags; @@ -72,11 +72,11 @@ class Feedzy_Rss_Feeds_Actions { public $result = ''; /** - * Post content. + * The field content (title, description, post content, date, etc.) * - * @var string $post_content + * @var string $field_content */ - public $post_content = ''; + public $field_content = ''; /** * Default value. @@ -129,13 +129,13 @@ public static function instance() { /** * Run actions. * - * @param string $actions Item content actions. - * @return string + * @param string $raw_serialized_actions Item content actions. + * @return string|array */ - public function set_actions( $actions = '' ) { - $this->actions = $actions; - if ( empty( $this->actions ) ) { - return $this->actions; + public function set_raw_serialized_actions( $raw_serialized_actions = '' ) { + $this->raw_serialized_actions = $raw_serialized_actions; + if ( empty( $this->raw_serialized_actions ) ) { + return $this->raw_serialized_actions; } $this->extract_tags = $this->extract_magic_tags(); return $this->extract_tags; @@ -154,10 +154,23 @@ public function set_settings( $options ) { /** * Extract magic tags. * - * @return string + * @return array|array[] */ public function extract_magic_tags() { - preg_match_all( '/\[\[\{(.*)\}\]\]/U', $this->actions, $item_magic_tags, PREG_PATTERN_ORDER ); + /** + * Transform the serialized string of magic tags to array. + * + * Input(string): [[{"value":"[{"id":"chat_gpt_rewrite","tag":"item_title","data":{"ChatGPT":"Create a long description: {content}"}},{"id":"fz_summarize","tag":"item_title","data":{"fz_summarize":true}}]"}]] with a nice weather. + * + * Output: + * [ + * [ + * [replace_to] => [[{"value":"[{"id":"chat_gpt_rewrite","tag":"item_title","data":{"ChatGPT":"Create a long description: {content}"}},{"id":"fz_summarize","tag":"item_title","data":{"fz_summarize":true}}]"}]] + * [replace_with] => [{"id":"chat_gpt_rewrite","tag":"item_title","data":{"ChatGPT":"Create a long description: {content}"}},{"id":"fz_summarize","tag":"item_title","data":{"fz_summarize":true}}] + * ] + * ] + */ + preg_match_all( '/\[\[\{(.*)\}\]\]/U', $this->raw_serialized_actions, $item_magic_tags, PREG_PATTERN_ORDER ); $extract_tags = array(); if ( ! empty( $item_magic_tags[0] ) ) { $extract_tags = array_map( @@ -175,12 +188,14 @@ function( $tag ) { } /** - * Get magic tags. + * Get the extracted serialized actions from the Tagify tags. The actions can be a mix of Tagify tags and simple text. + * + * @return string The serialized actions. */ - public function get_tags() { + public function get_serialized_actions() { $replace_to = array_column( $this->get_extract_tags(), 'replace_to' ); $replace_with = array_column( $this->get_extract_tags(), 'replace_with' ); - return str_replace( $replace_to, $replace_with, $this->actions ); + return str_replace( $replace_to, $replace_with, $this->raw_serialized_actions ); } /** @@ -191,17 +206,21 @@ public function get_extract_tags() { } /** - * Get actions. + * Get actions. Return pairs of serialized actions and their deserialized versions. + * + * Deserialized version is used to run the action job. While serialized version is used to replace the job result in the input content. + * + * @return array */ public function get_actions() { $replace_with = array_column( $this->get_extract_tags(), 'replace_with' ); $actions = array_map( - function( $action ) { - $replace_with = json_decode( $action ); - if ( $replace_with ) { + function( $serialized_actions ) { + $job_actions = json_decode( $serialized_actions ); + if ( $job_actions ) { return array( - 'replace_to' => wp_json_encode( $replace_with ), - 'replace_with' => $replace_with, + 'serialized_actions' => $serialized_actions, + 'job_actions' => $job_actions, ); } return false; @@ -214,7 +233,7 @@ function( $action ) { /** * Run action job. * - * @param string $post_content Post content. + * @param string $field_content Field content. It can contain a mix of magic tags and simple text. * @param string $import_translation_lang Translation language code. * @param object $job Post object. * @param string $language_code Feed language code. @@ -222,38 +241,39 @@ function( $action ) { * @param string $default_value Default value. * @return string */ - public function run_action_job( $post_content, $import_translation_lang, $job, $language_code, $item, $default_value = '' ) { + public function run_action_job( $field_content, $import_translation_lang, $job, $language_code, $item, $default_value = '' ) { $this->item = $item; $this->job = $job; $this->language_code = $language_code; $this->translation_lang = $import_translation_lang; - $this->post_content = $post_content; + $this->field_content = $field_content; $this->default_value = $default_value; $actions = $this->get_actions(); if ( ! empty( $actions ) ) { foreach ( $actions as $key => $jobs ) { - if ( ! isset( $jobs['replace_with'] ) ) { + if ( ! isset( $jobs['job_actions'] ) ) { continue; } + $this->result = null; - $replace_with = isset( $jobs['replace_with'] ) ? $jobs['replace_with'] : array(); - $replace_to = isset( $jobs['replace_to'] ) ? $jobs['replace_to'] : ''; - foreach ( $replace_with as $job ) { + $jobs_actions = $jobs['job_actions']; + $replace_to = isset( $jobs['serialized_actions'] ) ? $jobs['serialized_action'] : ''; + foreach ( $jobs_actions as $job ) { $this->current_job = $job; $this->result = $this->action_process(); } if ( 'item_image' === $this->type ) { - $this->post_content = str_replace( $replace_to, $this->result, wp_json_encode( $replace_with ) ); + $this->field_content = str_replace( $replace_to, $this->result, wp_json_encode( $jobs_actions ) ); } else { - $this->post_content = str_replace( $replace_to, $this->result, $this->post_content ); + $this->field_content = str_replace( $replace_to, $this->result, $this->field_content ); } } } if ( empty( $actions ) && 'item_image' === $this->type ) { return $default_value; } - return $this->post_content; + return $this->field_content; } /** diff --git a/includes/admin/feedzy-rss-feeds-import.php b/includes/admin/feedzy-rss-feeds-import.php index 402d5a12..41495374 100644 --- a/includes/admin/feedzy-rss-feeds-import.php +++ b/includes/admin/feedzy-rss-feeds-import.php @@ -1422,6 +1422,10 @@ private function run_job( $job, $max ) { $translated_title = apply_filters( 'feedzy_invoke_auto_translate_services', $item['item_title'], '[#translated_title]', $import_translation_lang, $job, $language_code, $item ); } + $import_title = rawurldecode( $import_title ); + $import_title = str_replace( PHP_EOL, "\r\n", $import_title ); + $import_title = trim( $import_title ); + $post_title = str_replace( array( '[#item_title]', @@ -1448,6 +1452,10 @@ private function run_job( $job, $max ) { $post_title = apply_filters( 'feedzy_parse_custom_tags', $post_title, $item_obj ); } + $title_action = $this->get_actions_runner( $post_title, 'item_title' ); + $post_title = $title_action->get_serialized_actions(); + $post_title = $title_action->run_action_job( $post_title, $translated_title, $job, $language_code, $item ); + $post_title = apply_filters( 'feedzy_invoke_services', $post_title, 'title', $item['item_title'], $job ); // Get translated item link text. @@ -1543,8 +1551,8 @@ private function run_job( $job, $max ) { $post_content = apply_filters( 'feedzy_invoke_services', $post_content, 'full_content', $full_content, $job ); } // Item content action. - $content_action = $this->handle_content_actions( $post_content, 'item_content' ); - $post_content = $content_action->get_tags(); + $content_action = $this->get_actions_runner( $post_content, 'item_content' ); + $post_content = $content_action->get_serialized_actions(); // Item content action process. $post_content = $content_action->run_action_job( $post_content, $import_translation_lang, $job, $language_code, $item ); // Parse custom tags. @@ -1829,7 +1837,7 @@ function( $term ) { // Item image action. $import_featured_img = rawurldecode( $import_featured_img ); $import_featured_img = trim( $import_featured_img ); - $img_action = $this->handle_content_actions( $import_featured_img, 'item_image' ); + $img_action = $this->get_actions_runner( $import_featured_img, 'item_image' ); // Item image action process. $image_url = $img_action->run_action_job( $import_featured_img, $import_translation_lang, $job, $language_code, $item, $image_url ); @@ -2310,8 +2318,8 @@ public function render_magic_tags( $default, $tags, $type ) { $disabled[ str_replace( ':disabled', '', $tag ) ] = $label; continue; } - if ( in_array( $type, array( 'import_post_content', 'import_post_featured_img' ), true ) ) { - if ( in_array( $tag, array( 'item_content', 'item_description', 'item_full_content', 'item_categories', 'item_image' ), true ) ) { + if ( in_array( $type, array( 'import_post_content', 'import_post_featured_img', 'import_post_title' ), true ) ) { + if ( in_array( $tag, array( 'item_content', 'item_description', 'item_full_content', 'item_categories', 'item_image', 'item_title' ), true ) ) { $default .= '' . $label . ' [#' . $tag . ']'; continue; } @@ -2917,16 +2925,16 @@ private function wizard_import_feed() { } /** - * Handle item content actions. + * Get the content action runner used for processing the chained actions from the tags. * * @param string $actions Item content actions. * @param string $type Action type. - * @return object `Feedzy_Rss_Feeds_Actions` class instance. + * @return Feedzy_Rss_Feeds_Actions The class instance. */ - public function handle_content_actions( $actions = '', $type = '' ) { + public function get_actions_runner( $actions = '', $type = '' ) { $action_instance = Feedzy_Rss_Feeds_Actions::instance(); $action_instance->type = $type; - $action_instance->set_actions( $actions ); + $action_instance->set_raw_serialized_actions( $actions ); $action_instance->set_settings( $this->settings ); return $action_instance; } diff --git a/includes/views/import-metabox-edit.php b/includes/views/import-metabox-edit.php index ecf69cc4..60218942 100644 --- a/includes/views/import-metabox-edit.php +++ b/includes/views/import-metabox-edit.php @@ -389,7 +389,7 @@ class="dashicons dashicons-arrow-down-alt2"> ?> -
+
` } - catch(err){} + catch(err){ + console.error(err); + } } } } ); From b987a2b79e124e52512b251c4092692be42e4646 Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Wed, 22 May 2024 17:02:28 +0300 Subject: [PATCH 17/20] fix: processing order --- includes/admin/feedzy-rss-feeds-import.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/admin/feedzy-rss-feeds-import.php b/includes/admin/feedzy-rss-feeds-import.php index 44828bc0..68c30c22 100644 --- a/includes/admin/feedzy-rss-feeds-import.php +++ b/includes/admin/feedzy-rss-feeds-import.php @@ -1448,14 +1448,14 @@ private function run_job( $job, $max ) { $import_title ); + // Run all the actions stored for the embedded/serialized tags in the title field. + $title_action = $this->get_actions_runner( $post_title, 'item_title' ); + $post_title = $title_action->run_action_job( $title_action->get_serialized_actions(), $translated_title, $job, $language_code, $item ); + if ( $this->feedzy_is_business() ) { $post_title = apply_filters( 'feedzy_parse_custom_tags', $post_title, $item_obj ); } - $title_action = $this->get_actions_runner( $post_title, 'item_title' ); - $post_title = $title_action->get_serialized_actions(); - $post_title = $title_action->run_action_job( $post_title, $translated_title, $job, $language_code, $item ); - $post_title = apply_filters( 'feedzy_invoke_services', $post_title, 'title', $item['item_title'], $job ); // Get translated item link text. From 6834e53ccfbb39d253048f0190c854bd83b4f6ce Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Mon, 27 May 2024 14:18:49 +0300 Subject: [PATCH 18/20] fix: use the user defined custom image tag --- includes/admin/feedzy-rss-feeds-import.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/admin/feedzy-rss-feeds-import.php b/includes/admin/feedzy-rss-feeds-import.php index f9e036d5..33c9aa07 100644 --- a/includes/admin/feedzy-rss-feeds-import.php +++ b/includes/admin/feedzy-rss-feeds-import.php @@ -1652,7 +1652,7 @@ private function run_job( $job, $max ) { $image_source_url = ''; $img_success = true; $new_post_id = 0; - $default_img_tag = ! empty( $import_featured_img ) ? '[#item_image]' : ''; + $default_img_tag = ! empty( $import_featured_img ) && is_string( $import_featured_img ) ? $import_featured_img : ''; // image tag if ( strpos( $default_img_tag, '[#item_image]' ) !== false ) { @@ -1759,7 +1759,7 @@ function( $term ) { do_action( 'feedzy_import_extra', $job, $item_obj, $new_post_id, $import_errors, $import_info ); - $default_img_tag = ! empty( $import_featured_img ) ? '[#item_image]' : ''; + $default_img_tag = ! empty( $import_featured_img ) && is_string( $import_featured_img ) ? $import_featured_img : ''; if ( ! empty( $default_img_tag ) && 'attachment' !== $import_post_type ) { $image_source_url = ''; $img_success = true; From 1daf2ed920cf034e9deaec04641811d6ebebf5f3 Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Mon, 27 May 2024 14:34:37 +0300 Subject: [PATCH 19/20] fix: E2E test image tag --- cypress/e2e/default/import_feed_free.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/default/import_feed_free.js b/cypress/e2e/default/import_feed_free.js index 830c976e..8845fa6e 100644 --- a/cypress/e2e/default/import_feed_free.js +++ b/cypress/e2e/default/import_feed_free.js @@ -54,7 +54,7 @@ describe('Test Free - Import Feed', function() { cy.get('[name="feedzy_meta_data[import_post_title]"]').clear({force: true}).invoke('val', PREFIX + feed.title).blur({force: true}); cy.get('[name="feedzy_meta_data[import_post_content]"]').clear({force: true}).invoke('val', PREFIX + feed.fullcontent.content + feed.content).blur({force: true}); - cy.get('[name="feedzy_meta_data[import_post_featured_img]"]').clear({force: true}).invoke('val', feed.image.url).blur({force: true}); + cy.get('[name="feedzy_meta_data[import_post_featured_img]"]').clear({force: true}).invoke('val', feed.image.tag).blur({force: true}); // check disallowd magic tags const tags = feed.tags.disallowed; @@ -122,7 +122,7 @@ describe('Test Free - Import Feed', function() { cy.get('[name="feedzy_meta_data[import_post_content]"]').should('have.value', PREFIX + feed.fullcontent.content + feed.content + '\n'); // image from URL - cy.get('[name="feedzy_meta_data[import_post_featured_img]"]').should('have.value', feed.image.url); + cy.get('[name="feedzy_meta_data[import_post_featured_img]"]').should('have.value', feed.image.tag); // publish cy.get('button[type="submit"][name="publish"]').scrollIntoView().click({force:true}); From 6787a29813171c950d54e487b6d5a51a19e14882 Mon Sep 17 00:00:00 2001 From: "themeisle[bot]" Date: Thu, 30 May 2024 12:41:01 +0000 Subject: [PATCH 20/20] chore(release): 4.4.9 ##### [Version 4.4.9](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.8...v4.4.9) (2024-05-30) Improvements - Allow chained actions for `[#item_title]` - Added floating widget to the dashboard - Made item_date tag to respect and convert to site timezone on import - Updated internal dependencies Fixes - Fix `auto` option for default fallback image in Feedzy RSS Block. - Fixed issue when images with non-Latin characters in the URL are not imported - Fixed issue with fallback image per import job not working [PRO] - Fixed usage of custom tag for featured image in the import settings [PRO] --- CHANGELOG.md | 14 ++++++++++++++ css/feedzy-rss-feeds.css | 2 +- feedzy-rss-feed.php | 2 +- includes/feedzy-rss-feeds.php | 2 +- package.json | 2 +- readme.txt | 17 +++++++++++++++++ 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eb74c74..2ef60b5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +##### [Version 4.4.9](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.8...v4.4.9) (2024-05-30) + +Improvements +- Allow chained actions for `[#item_title]` +- Added floating widget to the dashboard +- Made item_date tag to respect and convert to site timezone on import +- Updated internal dependencies + +Fixes +- Fix `auto` option for default fallback image in Feedzy RSS Block. +- Fixed issue when images with non-Latin characters in the URL are not imported +- Fixed issue with fallback image per import job not working [PRO] +- Fixed usage of custom tag for featured image in the import settings [PRO] + ##### [Version 4.4.8](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.7...v4.4.8) (2024-04-15) ### Fixes diff --git a/css/feedzy-rss-feeds.css b/css/feedzy-rss-feeds.css index 468f2f35..2eec96c5 100644 --- a/css/feedzy-rss-feeds.css +++ b/css/feedzy-rss-feeds.css @@ -2,7 +2,7 @@ * feedzy-rss-feeds.css * Feedzy RSS Feed * Copyright: (c) 2016 Themeisle, themeisle.com - * Version: 4.4.8 + * Version: 4.4.9 * Plugin Name: FEEDZY RSS Feeds * Plugin URI: http://themeisle.com/plugins/feedzy-rss-feeds/ * Author: Themeisle diff --git a/feedzy-rss-feed.php b/feedzy-rss-feed.php index 025a054a..fd2176dd 100644 --- a/feedzy-rss-feed.php +++ b/feedzy-rss-feed.php @@ -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.8 + * Version: 4.4.9 * Author: Themeisle * Author URI: http://themeisle.com * License: GPL-2.0+ diff --git a/includes/feedzy-rss-feeds.php b/includes/feedzy-rss-feeds.php index 31604e54..80428c91 100644 --- a/includes/feedzy-rss-feeds.php +++ b/includes/feedzy-rss-feeds.php @@ -104,7 +104,7 @@ public static function instance() { */ public function init() { self::$plugin_name = 'feedzy-rss-feeds'; - self::$version = '4.4.8'; + self::$version = '4.4.9'; self::$instance->load_dependencies(); self::$instance->set_locale(); self::$instance->define_admin_hooks(); diff --git a/package.json b/package.json index 37790b67..b040ae9b 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "feedzy-rss-feeds", - "version": "4.4.8", + "version": "4.4.9", "description": "Feedzy RSS Feeds - lite version", "repository": { "type": "git", diff --git a/readme.txt b/readme.txt index 69ce4c94..f1acb5fd 100644 --- a/readme.txt +++ b/readme.txt @@ -493,6 +493,23 @@ You have to check first if your feed is valid. Please test it here: https://vali == Changelog == +##### [Version 4.4.9](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.8...v4.4.9) (2024-05-30) + +Improvements +- Allow chained actions for +- Added floating widget to the dashboard +- Made item_date tag to respect and convert to site timezone on import +- Updated internal dependencies + +Fixes +- Fix option for default fallback image in Feedzy RSS Block. +- Fixed issue when images with non-Latin characters in the URL are not imported +- Fixed issue with fallback image per import job not working [PRO] +- Fixed usage of custom tag for featured image in the import settings [PRO] + + + + ##### [Version 4.4.8](https://github.com/Codeinwp/feedzy-rss-feeds/compare/v4.4.7...v4.4.8) (2024-04-15) ### Fixes