diff --git a/includes/admin/feedzy-rss-feeds-admin.php b/includes/admin/feedzy-rss-feeds-admin.php index a0b4ae18..50cf3a51 100644 --- a/includes/admin/feedzy-rss-feeds-admin.php +++ b/includes/admin/feedzy-rss-feeds-admin.php @@ -1978,6 +1978,10 @@ public function feedzy_load_setup_wizard_page() { * Enqueue setup wizard required scripts. */ public function feedzy_enqueue_setup_wizard_scripts() { + if ( ! did_action( 'wp_enqueue_media' ) ) { + wp_enqueue_media(); + } + wp_enqueue_style( $this->plugin_name . '_chosen' ); wp_enqueue_style( $this->plugin_name . '_smart_wizard', FEEDZY_ABSURL . 'css/smart_wizard_all.min.css', array(), $this->version ); wp_enqueue_style( $this->plugin_name . '_setup_wizard', FEEDZY_ABSURL . 'includes/views/css/style-wizard.css', array( $this->plugin_name . '-settings' ), $this->version, 'all' ); @@ -2003,6 +2007,18 @@ public function feedzy_enqueue_setup_wizard_scripts() { 'firstButtonText' => __( 'Create Page', 'feedzy-rss-feeds' ), 'secondButtonText' => __( 'Do not create', 'feedzy-rss-feeds' ), ), + 'mediaUploadText' => array( + 'iframeTitle' => __( 'Select image', 'feedzy-rss-feeds' ), + 'iframeButton' => __( 'Set default image', 'feedzy-rss-feeds' ), + 'actionButtonTextOne' => __( 'Choose image', 'feedzy-rss-feeds' ), + 'actionButtonTextTwo' => __( 'Replace image', 'feedzy-rss-feeds' ), + 'actionButtonTextThree' => __( 'Remove image', 'feedzy-rss-feeds' ), + ), + 'dryRun' => array( + 'loading' => '

' . __( 'Processing the source and loading the items that will be imported when it runs', 'feedzy-rss-feeds' ) . '...

' + . '

', + 'title' => __( 'Importable Items', 'feedzy-rss-feeds' ), + ), ) ); } diff --git a/includes/admin/feedzy-rss-feeds-import.php b/includes/admin/feedzy-rss-feeds-import.php index a343ce72..9f954c14 100644 --- a/includes/admin/feedzy-rss-feeds-import.php +++ b/includes/admin/feedzy-rss-feeds-import.php @@ -561,9 +561,14 @@ public function feedzy_import_feed_options() { $default_thumbnail_id = 0; $inherited_thumbnail_id = ! empty( $this->free_settings['general']['default-thumbnail-id'] ) ? (int) $this->free_settings['general']['default-thumbnail-id'] : 0; + $custom_thumbnail_id = get_post_meta( $post->ID, 'default_thumbnail_id', true ); + + if ( is_numeric( $custom_thumbnail_id ) ) { + $default_thumbnail_id = $custom_thumbnail_id; + } + if ( feedzy_is_pro() ) { - $default_thumbnail_id = get_post_meta( $post->ID, 'default_thumbnail_id', true ); - $import_schedule = array( + $import_schedule = array( 'fz_cron_schedule' => ! empty( $this->free_settings['general']['fz_cron_schedule'] ) ? $this->free_settings['general']['fz_cron_schedule'] : '', ); } @@ -3951,6 +3956,8 @@ private function wizard_import_feed() { $post_type = ! empty( $_POST['post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : ''; $post_status = ! empty( $_POST['post_status'] ) ? sanitize_text_field( wp_unslash( $_POST['post_status'] ) ) : ''; + $fallback_image = ! empty( $_POST['fallback_image'] ) ? sanitize_text_field( wp_unslash( $_POST['fallback_image'] ) ) : ''; + $excluded_post_title = ! empty( $_POST['excluded_post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['excluded_post_title'] ) ) : ''; $wizard_data = get_option( 'feedzy_wizard_data', array() ); $wizard_data = ! empty( $wizard_data ) ? $wizard_data : array(); $wizard_data['post_type'] = $post_type; @@ -3994,7 +4001,25 @@ private function wizard_import_feed() { // Update wizard data. $wizard_data['job_id'] = $job_id; update_option( 'feedzy_wizard_data', $wizard_data ); - + + $filter_conditions = array( + 'match' => 'all', + 'conditions' => array(), + ); + + if ( ! empty( $excluded_post_title ) ) { + $filter_conditions['conditions'] = array( + array( + 'field' => 'title', + 'operator' => 'not_contains', + 'value' => $excluded_post_title, + ), + ); + } + + update_post_meta( $job_id, 'filter_conditions', wp_json_encode( $filter_conditions ) ); + update_post_meta( $job_id, 'default_thumbnail_id', $fallback_image ); + $response = array( 'status' => true, ); diff --git a/includes/layouts/setup-wizard.php b/includes/layouts/setup-wizard.php index d729e9ea..8d61f8c5 100644 --- a/includes/layouts/setup-wizard.php +++ b/includes/layouts/setup-wizard.php @@ -24,6 +24,7 @@ } $published_status = array( 'publish', 'draft' ); +add_thickbox(); ?>
@@ -138,6 +139,11 @@
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ + + + + +
+ +
+
+
+
+
-
- +
+ +
+ +
diff --git a/includes/views/css/style-wizard.css b/includes/views/css/style-wizard.css index 8f963126..1ebd809d 100644 --- a/includes/views/css/style-wizard.css +++ b/includes/views/css/style-wizard.css @@ -471,3 +471,36 @@ .feedzy-accordion-item__title h2 { margin-bottom: 0; } +.btn-ghost.disabled { + cursor: none; + pointer-events: none; + color: #757575; +} +#TB_ajaxContent ul { + list-style: decimal; + margin-left: 20px; +} + +#TB_ajaxContent ul li { + padding: 5px !important; +} + +#TB_ajaxContent p.loading-img { + text-align: center; +} + +#TB_ajaxContent.loaded p.hide-when-loaded { + display: none; +} + +#TB_ajaxContent div.dry_run span { + display: block; +} + +#TB_ajaxContent div.dry_run span i.pass { + color: #149714; +} + +#TB_ajaxContent div.dry_run span i.fail { + color: #ca4a1f; +} \ No newline at end of file diff --git a/js/feedzy-setup-wizard.js b/js/feedzy-setup-wizard.js index a1a744cb..4b304fe3 100644 --- a/js/feedzy-setup-wizard.js +++ b/js/feedzy-setup-wizard.js @@ -35,7 +35,7 @@ jQuery(function ($) { const feedUrl = $(this).attr('href'); $(this).parents('.fz-row').find('input:text').val(feedUrl); - $('[data-step_number="2"]').removeClass('disabled'); + $('[data-step_number="2"], #preflight').removeClass('disabled'); return false; }); @@ -211,6 +211,8 @@ jQuery(function ($) { post_status: $( 'select[name="feedzy_meta_data[import_post_status]"]' ).val(), + fallback_image: $('input[name="feedzy_meta_data[default_thumbnail_id]"]').val(), + excluded_post_title: $('input[name="feedzy_meta_data[exc_key]"]').val(), action: 'feedzy', _action: 'wizard_import_feed', }, @@ -329,9 +331,9 @@ jQuery(function ($) { // Remove disabled class from save button. $(document).on('input', '#wizard_feed_source', function () { if ('' === $(this).val()) { - $('[data-step_number="2"]').addClass('disabled'); + $('[data-step_number="2"], #preflight').addClass('disabled'); } else { - $('[data-step_number="2"]').removeClass('disabled'); + $('[data-step_number="2"], #preflight').removeClass('disabled'); } }); @@ -359,4 +361,100 @@ jQuery(function ($) { // Init chosen selectbox. $('.feedzy-chosen').chosen({ width: '100%' }); + + // on upload button click + $( 'body' ).on( 'click', '.feedzy-open-media', function( e ) { + e.preventDefault(); + const button = $( this ), + wp_media_uploader = wp.media( { + title: feedzySetupWizardData.mediaUploadText.iframeTitle, + library : { + type : 'image' + }, + button: { + text: feedzySetupWizardData.mediaUploadText.iframeButton + }, + multiple: false + } ).on( 'select', function() { // it also has "open" and "close" events + const selectedAttachments = wp_media_uploader.state().get( 'selection' ); + button.parents( '.fz-form-group' ).find( '.feedzy-media-preview' ).remove(); + // Display image preview when a single image is selected. + const attachment = selectedAttachments.first().toJSON(); + let attachmentUrl = attachment.url; + if ( attachment.sizes.thumbnail ) { + attachmentUrl = attachment.sizes.thumbnail.url; + } + if ( $( '.feedzy-media-preview' ).length ) { + $( '.feedzy-media-preview' ).find( 'img' ).attr( 'src', attachmentUrl ); + } else { + $( '
' ).insertBefore( button.parent() ); + } + // Get all selected attachment ids. + const ids = selectedAttachments.map( function( image ) { + return image.id; + } ).join( ',' ); + + button.parent().find( '.feedzy-remove-media' ).addClass( 'is-show' ); + button.parent().find( 'input:hidden' ).val( ids ).trigger( 'change' ); + $( '.feedzy-open-media' ).html( feedzySetupWizardData.mediaUploadText.actionButtonTextTwo ); + } ); + + wp_media_uploader.on(' open', function() { + const selectedVal = button.parent().find( 'input:hidden' ).val(); + if ( '' === selectedVal ) { + return; + } + const selection = wp_media_uploader.state().get('selection'); + + selectedVal.split(',').forEach(function( id ) { + const attachment = wp.media.attachment( id ); + attachment.fetch(); + selection.add(attachment ? [attachment] : []); + }); + } ); + + wp_media_uploader.open(); + }); + + $(document).on( 'click', '.feedzy-remove-media', function( e ) { + $(this) + e.preventDefault(); + $('.feedzy-media-preview').remove(); + $(this).removeClass('is-show'); + + // Reset the input. + $('input[name="feedzy_meta_data[default_thumbnail_id]"]').val(0); + $('.feedzy-open-media').html(feedzySetupWizardData.mediaUploadText.actionButtonTextOne); + } ); + + $('#preflight').on('click', function (e) { + e.preventDefault(); + const $fields = {}; + // collect all elements. + $('#smartwizard') + .find(':input') + .each(function (index, element) { + if ('undefined' === typeof $(element).attr('name')) { + return; + } + $fields[$(element).attr('name')] = $(element).val(); + }); + $fields['feedzy_meta_data[source]'] = $('#wizard_feed_source').val(); + tb_show(feedzySetupWizardData.dryRun.title, 'TB_inline?'); + $('#TB_ajaxContent').html(feedzySetupWizardData.dryRun.loading); + $.post( + ajaxurl, + { + security: window.feedzySetupWizardData.ajax.security, + fields: $.param($fields), + action: 'feedzy', + _action: 'dry_run', + environment: 'wizard', + }, + function(data) { + $('#TB_ajaxContent').addClass('loaded'); + $('#TB_ajaxContent div').html(data.data.output); + }, + ); + }); });