Skip to content

Commit

Permalink
Merge pull request #1046 from Codeinwp/feat/pro/775
Browse files Browse the repository at this point in the history
Adds import/export configuration
  • Loading branch information
vytisbulkevicius authored Dec 28, 2024
2 parents 7d45ada + af61a81 commit 804dd56
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 4 deletions.
81 changes: 79 additions & 2 deletions includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ public function enqueue_styles() {
'clearLogButton' => __( 'Clear Log', 'feedzy-rss-feeds' ),
'okButton' => __( 'Ok', 'feedzy-rss-feeds' ),
'removeErrorLogsMsg' => __( 'Removed all error logs.', 'feedzy-rss-feeds' ),
'importButton' => sprintf(
'<a href="#" class="page-title-action fz-export-import-btn%1$s"><span class="dashicons %2$s"></span>%3$s</a>',
! feedzy_is_pro() ? ' only-pro' : '',
feedzy_is_pro() ? 'dashicons-upload' : 'dashicons-lock',
esc_html__( 'Import Job', 'feedzy-rss-feeds' )
),
),
)
);
Expand Down Expand Up @@ -2471,6 +2477,11 @@ public function admin_notices() {
if ( false === Feedzy_Rss_Feeds_Util_Scheduler::is_scheduled( 'feedzy_cron' ) ) {
echo wp_kses_post( '<div class="notice notice-error"><p>' . __( 'Unable to register cron job. Your feeds might not get updated', 'feedzy-rss-feeds' ) . '</p></div>' );
}

// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! empty( $_GET['imported'] ) ) {
echo wp_kses_post( '<div class="notice notice-success is-dismissible"><p>' . __( 'Successfully imported.', 'feedzy-rss-feeds' ) . '</p></div>' );
}
}

/**
Expand Down Expand Up @@ -2838,12 +2849,12 @@ public function add_import_actions( $actions, $post ) {
unset( $actions['inline hide-if-no-js'] );

$actions['feedzy_purge'] = sprintf(
'<a href="#" class="feedzy-purge" data-id="%d">%2$s</a><span class="feedzy-spinner spinner"></span>',
'<a href="#" class="feedzy-purge" data-id="%d">%2$s</a>',
$post->ID,
esc_html( __( 'Purge &amp; Reset', 'feedzy-rss-feeds' ) )
);
if ( feedzy_is_pro() ) {

if ( feedzy_is_pro() ) {
$actions['feedzy_clone'] =
sprintf(
'<a href="%1$s" class="feedzy-clone" >%2$s</a>',
Expand Down Expand Up @@ -2877,6 +2888,25 @@ public function add_import_actions( $actions, $post ) {
$is_not_first = true;
}
}
// Export action.
$export_action = sprintf(
'<a href="%s" class="%s"style="%s">%s</a>',
feedzy_is_pro() ? esc_url(
add_query_arg(
array(
'action' => 'fz_export_job',
'_wpnonce' => wp_create_nonce( 'fz_export_job' ),
'id' => $post->ID,
),
admin_url( 'admin.php' )
)
) : '#',
feedzy_is_pro() ? 'fz-export-btn' : 'fz-export-btn-pro',
! feedzy_is_pro() ? 'opacity:0.5;' : '',
( ! feedzy_is_pro() ? '<span style="font-size: 13px;line-height: 1.5em;width: 13px;height: 13px;" class="dashicons dashicons-lock"></span>' : '' ) . esc_html__( 'Export', 'feedzy-rss-feeds' )
);

$actions['export'] = $export_action;
} elseif ( 1 === intval( get_post_meta( $post->ID, 'feedzy', true ) ) ) {
// show an unclickable action that mentions that it is imported by us
// so that users are aware
Expand Down Expand Up @@ -3342,4 +3372,51 @@ private function clear_error_logs() {
)
);
}

/**
* Load edit screen.
*/
public function load_edit_screen() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( empty( $_GET['post_type'] ) || 'feedzy_imports' !== $_GET['post_type'] ) {
return;
}
add_action( 'admin_footer', array( $this, 'add_import_export_section' ) );
}

/**
* Add import export section.
*/
public function add_import_export_section() {
if ( ! feedzy_is_pro() ) :
?>
<div id="fz_import_export_upsell" class="hidden" style="max-width:450px">
<div class="modal-content">
<span class="notice-dismiss close-modal">
<span class="screen-reader-text"><?php esc_html_e( 'Dismiss this dialog', 'feedzy-rss-feeds' ); ?></span>
</span>
<div class="modal-header">
<h2><span class="dashicons dashicons-lock"></span> <?php esc_html_e( 'Import/Export is a PRO feature', 'feedzy-rss-feeds' ); ?></h2>
</div>
<div class="modal-body">
<p><?php esc_html_e( 'We\'re sorry, import/export is not available on your plan. Please upgrade to the Pro plan to unlock all these features.', 'feedzy-rss-feeds' ); ?></p>
</div>
<div class="modal-footer">
<div class="button-container"><a href="<?php echo esc_url( tsdk_translate_link( tsdk_utmify( FEEDZY_UPSELL_LINK, 'importExport' ) ) ); ?>" target="_blank" rel="noopener " class="button button-primary button-large"><?php esc_html_e( 'Upgrade to PRO', 'feedzy-rss-feeds' ); ?><span aria-hidden="true" class="dashicons dashicons-external"></span></a></div>
</div>
</div>
</div>
<?php endif; ?>
<script type="template/text" id="fz_import_field_section">
<div class="fz-import-field hidden">
<form method="post" enctype="multipart/form-data" action="<?php echo esc_url( add_query_arg( array( 'action' => 'fz_import_job' ), admin_url( 'admin.php' ) ) ); ?>">
<h4> <?php esc_html_e( 'Choose the inport job .json file to import.', 'feedzy-rss-feeds' ); ?></h4>
<?php wp_nonce_field( 'fz_import_job' ); ?>
<input type="file" accept=".json" name="fz_import" required>
<button type="submit" class="button button-primary"><?php esc_html_e( 'Import', 'feedzy-rss-feeds' ); ?></button>
</form>
</div>
</script>
<?php
}
}
2 changes: 1 addition & 1 deletion includes/feedzy-rss-feeds-feed-tweaks.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ function feedzy_is_legacyv5( ) {

return $legacy === 1;
}

/**
* Check if the user is pro or not.
*
* @return bool If the users is pro or not
*/
function feedzy_is_pro( $check_license = true ) {

$status = apply_filters( 'product_feedzy_license_status', false ) === 'valid';
if ( ! $check_license ) {
$status = true;
Expand Down
1 change: 1 addition & 0 deletions includes/feedzy-rss-feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ function () {
self::$instance->loader->add_filter( 'feedzy_magic_tags_post_excerpt', $plugin_import, 'magic_tags_post_excerpt', 11 );
self::$instance->loader->add_action( 'admin_action_feedzy_clone_import_job', $plugin_import, 'feedzy_clone_import_job' );
self::$instance->loader->add_action( 'admin_notices', $plugin_import, 'feedzy_import_clone_success_notice' );
self::$instance->loader->add_action( 'load-edit.php', $plugin_import, 'load_edit_screen' );
// Remove elementor feature.
self::$instance->loader->add_action( 'elementor/experiments/feature-registered', self::$instance->admin, 'feedzy_remove_elementor_feature', 10, 2 );
// Remove widget.
Expand Down
63 changes: 63 additions & 0 deletions includes/views/css/import-metabox-edit.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,66 @@ span.feedzy-spinner {
.feedzy-errors-dialog + .ui-widget-content button.feedzy-clear-logs {
margin-left: 0;
}

.wp-core-ui .fz-export-import-btn {
display: inline-flex !important;
align-items: center;
}

.wp-core-ui .fz-header-action {
display: inline-flex !important;
gap: 8px;
}

#fz_import_export_upsell .modal-content {
background: #fff;
border-radius: 3px;]
width: auto;
margin: 1.75rem auto ;
}
#fz_import_export_upsell .modal-body {
text-align: center;
}
#fz_import_export_upsell .modal-header {
padding-bottom: 10px;
margin-bottom: 10px;
position: relative;
}
#fz_import_export_upsell .modal-header .dashicons {
font-size: 1.3em;
line-height: inherit;
}
#fz_import_export_upsell .modal-header h2 {
text-align: center;
}
#fz_import_export_upsell .close-modal {
position: absolute;
top: 0;
right: 0;
}
#fz_import_export_upsell .modal-footer .dashicons{

vertical-align: middle;
font-size: initial;
}
#fz_import_export_upsell .modal-footer {
padding-top: 10px;
margin-top: 10px;
text-align: center;
}
.fz-import-field {
background-color: #fff;
max-width: 400px;
width: 100%;
margin: 0 auto;
position: relative;
padding: 15px;
height: 120px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
.fz-import-field.hidden {
display: none;
}
53 changes: 53 additions & 0 deletions includes/views/js/import-metabox-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,59 @@
tagList.find( 'input:text' ).val( '' );
}
} );
// Append import button.
$( feedzy.i10n.importButton ).insertAfter( $( '.page-title-action', document ) );
$( $( '.page-title-action', document ) ).wrapAll( '<div class="fz-header-action"></div>' );

// Create dialog box
$( '#fz_import_export_upsell' ).dialog( {
title: '',
dialogClass: 'wp-dialog',
autoOpen: false,
draggable: false,
width: 'auto',
modal: true,
resizable: false,
closeOnEscape: true,
position: {
my: "center",
at: "center",
of: window
},
open: function( event, ui ) {
$(".ui-dialog-titlebar-close", ui.dialog | ui).hide();
$(".ui-dialog-titlebar", ui.dialog | ui).hide();
},
create: function() {
// style fix for WordPress admin
$( '.ui-dialog-titlebar-close' ).addClass( 'ui-button' );
},
} );

$( '.fz-export-import-btn.only-pro, .fz-export-btn-pro' ).on( 'click', function( e ) {
e.preventDefault();
$( '#fz_import_export_upsell' ).dialog( 'open' );
});

$( '#fz_import_export_upsell' ).on( 'click', '.close-modal', function ( e ) {
e.preventDefault();
$( '#fz_import_export_upsell' ).dialog( 'close' );
} );

$(document).on( 'click', '.fz-export-import-btn:not(.only-pro)', function( e ) {
e.preventDefault();
if ( $('.fz-import-field').length === 0 ) {
var importField = $( '#fz_import_field_section' ).html();
$( importField ).insertAfter( $( this ).parents( 'div.wrap' ).find( '.wp-header-end' ) );
}
$('.fz-import-field').toggleClass('hidden');
});

let url = new URL(window.location.href);
if (url.searchParams.has('imported')) {
url.searchParams.delete('imported');
history.replaceState(history.state, '', url.href);
}
}

function initSummary() {
Expand Down
30 changes: 30 additions & 0 deletions tests/e2e/specs/upsell.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,33 @@ test.describe( 'Upsell', () => {
await expect( upgradeAlert ).toBeVisible();
} );
});

test.describe( 'List Page Upsell', () => {
test.beforeEach( async ( { requestUtils, page } ) => {
await page.goto('/wp-admin/edit.php?post_type=feedzy_imports');
} );

test('Import/Export', async ({ editor, page }) => {
// Locate and click the "Import Job" link
const importButton = page.locator('.fz-export-import-btn');
await expect(importButton).toBeVisible();
await importButton.click();

// Wait for the popup to become visible
const upsellPopup = page.locator('#fz_import_export_upsell');
await expect(upsellPopup).toBeVisible();

// Locate and check the "Upgrade to PRO" link inside the popup
const upgradeToProLink = upsellPopup.locator('a', { hasText: 'Upgrade to PRO' });
await expect(upgradeToProLink).toBeVisible();

// Get the URL from the "Upgrade to PRO" link
const upsellLink = new URL(await upgradeToProLink.getAttribute('href'));

// Validate the URL parameters
expect(upsellLink.host).toBe('themeisle.com');
expect(upsellLink.searchParams.get('utm_source')).toBe('wpadmin');
expect(upsellLink.searchParams.get('utm_medium')).toBe('edit');
expect(upsellLink.searchParams.get('utm_content')).toBe('feedzy-rss-feeds');
});
});
2 changes: 1 addition & 1 deletion tests/e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export async function runFeedImport( page ) {

// Open the dialog with the imported feeds.
await page.locator('.feedzy-items a').click();
await expect( page.locator('#ui-id-1').locator('li a').count() ).resolves.toBeGreaterThan(0);
await expect( page.locator('#ui-id-2').locator('li a').count() ).resolves.toBeGreaterThan(0);
await page.getByRole('button', { name: 'Ok' }).click();
}

Expand Down

0 comments on commit 804dd56

Please sign in to comment.