This repository has been archived by the owner on May 31, 2021. It is now read-only.
forked from ramiy/spotim-wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit * Import code from WP.org * Add package-lock.json * Add phpcs ruleset * Exclude gulp from code sniffer * Fix: Coding Standard in inc/helpers Fix: Issue with JSON feed Fix: Deprecated usage of WP_User->id Remove: Unused Function * Update PHPCompatibility to PHPCompatibilityWP * Fix : Coding Standard in inc class files Add function for VIP check and Wrapper for remote get * Fix : Coding Standard in templates * Fix : Coding Standard in templates Reformat code * Move vip check function over to main plugin file * Reformat inc/helpers code * Remove escaping as already escaped in templates * Remove flush rewrite rules Fix phpcs issue in cron and frontend class Fix warnings with get_the_excerpt * Reformat inc class files * Fix escaping issue in sync message * Fix error display on sync error * Address Feedbacks * Address Feedbacks Use single quotes * Address Feedbacks - Update variable checks * Address Feedbacks - spacing and unused function * WR-3: Add option to enable / disable newsfeed * WR-1: Increase threshold for VIP request Add more info in logs for debugging * WR-7: Add option to display comments count on non singular pages * WR-8: Update siderail template * WR-11: Update feed build code * Define plugin version constant to be used in data-wp-v attributes * Update language file * Bump version to 4.4.0 Update Changelog
- Loading branch information
1 parent
027e3a7
commit a280514
Showing
38 changed files
with
6,757 additions
and
4,061 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,153 +1,171 @@ | ||
jQuery( document ).ready(function ( $ ) { | ||
var cancelImportProcess = false; | ||
|
||
spotimVariables.pageNumber = parseInt( spotimVariables.pageNumber, 10 ); | ||
|
||
// Import | ||
$( '.sync-button' ).on( 'click', function( event ) { | ||
var $importButton = $(this), | ||
$parentElement = $importButton.parent(), | ||
$messageField = $importButton.siblings( '.description' ), | ||
$errorsField = $importButton.siblings( '.errors' ), | ||
spotIdInputValue = $importButton.data( 'spot-id' ).trim(), | ||
importTokenInputValue = $importButton.data( 'import-token' ).trim(), | ||
postsPerRequestValue = parseInt( $importButton.data( 'posts-per-request' ) ); | ||
|
||
$parentElement.addClass( 'in-progress' ); | ||
|
||
// Empty message field from any text and reset css | ||
$messageField | ||
.removeClass( 'red-color' ) | ||
.empty(); | ||
|
||
// Disable the import button | ||
$( '.sync-button' ).attr( 'disabled', true ); | ||
|
||
var data = { | ||
'action': 'start_import', | ||
'spotim_spot_id': spotIdInputValue, | ||
'spotim_import_token': importTokenInputValue, | ||
'spotim_posts_per_request': postsPerRequestValue, | ||
|
||
// pageNumber is defined in options class, | ||
// inject from admin_javascript > spotim_variables. | ||
'spotim_page_number': spotimVariables.pageNumber | ||
}; | ||
|
||
if($importButton.hasClass('force')) | ||
data.force = true; | ||
|
||
importCommentsToWP( data, $( '.sync-button' ), $messageField, $errorsField ); | ||
|
||
event.preventDefault(); | ||
}); | ||
|
||
// Cancel import | ||
$( '#cancel_import_link' ).on( 'click', function( event ) { | ||
var cancelImportLink = $(this), | ||
$messageField = cancelImportLink.siblings( '.description' ), | ||
$parentElement = cancelImportLink.parent(), | ||
data = { | ||
'action': 'cancel_import', | ||
'spotim_page_number': 0 | ||
}; | ||
|
||
$parentElement.removeClass( 'in-progress' ); | ||
cancelImportProcess = true; | ||
|
||
$messageField | ||
.removeClass( 'red-color' ) | ||
.text( spotimVariables.cancelImportMessage ); | ||
|
||
$.post( ajaxurl, data, function() { | ||
window.location.reload( true ); | ||
}, 'json' ) | ||
.fail(function() { | ||
window.location.reload( true ); | ||
}); | ||
|
||
|
||
event.preventDefault(); | ||
}); | ||
|
||
// Checks for page number to be above zero to trigger #import_button | ||
if ( !! spotimVariables.pageNumber ) { | ||
$( '#import_button' ).trigger( 'click' ); | ||
} | ||
|
||
// Import Commets to WordPress | ||
function importCommentsToWP( params, $importButton, $messageField, $errorsField ) { | ||
$.post( ajaxurl, params, function( response ) { | ||
if ( cancelImportProcess ) { | ||
return; | ||
} | ||
|
||
delete params.force; | ||
|
||
switch( response.status ) { | ||
case 'refresh': | ||
importCommentsToWP( params, $importButton, $messageField, $errorsField ); | ||
break; | ||
case 'continue': | ||
params.spotim_page_number = params.spotim_page_number + 1; | ||
importCommentsToWP( params, $importButton, $messageField, $errorsField ); | ||
break; | ||
case 'success': | ||
// Enable the import button and hide cancel link | ||
$importButton | ||
.attr( 'disabled', false ) | ||
.parent() | ||
.removeClass( 'in-progress' ); | ||
|
||
// Reset page number to zero | ||
spotimVariables.pageNumber = 0; | ||
break; | ||
case 'error': | ||
var displayErrorLog = false; | ||
|
||
// Append to error box | ||
for (var message of response.messages) { | ||
// Check if message is not empty, display error log | ||
if ( message.trim() ) { | ||
displayErrorLog = true; | ||
} | ||
$errorsField.append( | ||
$( '<p>' ).text( message ) | ||
); | ||
} | ||
|
||
if ( displayErrorLog ) { | ||
$errorsField.removeClass( 'spotim-hide' ); | ||
} | ||
|
||
// Keep importing, don't stop | ||
params.spotim_page_number = params.spotim_page_number + 1; | ||
importCommentsToWP( params, $importButton, $messageField, $errorsField ); | ||
|
||
// Enable the import button and hide cancel link | ||
// $importButton | ||
// .attr( 'disabled', false ) | ||
// .parent() | ||
// .removeClass( 'in-progress' ); | ||
break; | ||
} | ||
|
||
// Show response message inside message field | ||
$messageField.text( response.message ); | ||
|
||
}, 'json' ) | ||
.fail(function( response ) { | ||
$messageField.addClass( 'red-color' ); | ||
|
||
// Enable the import button and hide cancel link | ||
$importButton | ||
.attr( 'disabled', false ) | ||
.parent() | ||
.removeClass( 'in-progress' ); | ||
|
||
// Show response message inside message field | ||
$messageField.text( spotimVariables.errorMessage ); | ||
}); | ||
} | ||
|
||
}); | ||
jQuery( document ).ready(function ( $ ) { | ||
var cancelImportProcess = false; | ||
|
||
spotimVariables.pageNumber = parseInt( spotimVariables.pageNumber, 10 ); | ||
|
||
// Import | ||
$( '.sync-button' ).on( 'click', function( event ) { | ||
var $importButton = $(this), | ||
$parentElement = $importButton.parent(), | ||
$messageField = $importButton.siblings( '.description' ), | ||
$errorsField = $importButton.siblings( '.errors' ), | ||
spotIdInputValue = $importButton.data( 'spot-id' ).trim(), | ||
importTokenInputValue = $importButton.data( 'import-token' ).trim(), | ||
postsPerRequestValue = parseInt( $importButton.data( 'posts-per-request' ) ); | ||
|
||
$parentElement.addClass( 'in-progress' ); | ||
|
||
// Empty message field from any text and reset css | ||
$messageField | ||
.removeClass( 'red-color' ) | ||
.empty(); | ||
|
||
// Disable the import button | ||
$( '.sync-button' ).attr( 'disabled', true ); | ||
|
||
var data = { | ||
'action': 'start_import', | ||
'spotim_spot_id': spotIdInputValue, | ||
'spotim_import_token': importTokenInputValue, | ||
'spotim_posts_per_request': postsPerRequestValue, | ||
'security' : spotimVariables.sync_nonce, | ||
|
||
// pageNumber is defined in options class, | ||
// inject from admin_javascript > spotim_variables. | ||
'spotim_page_number': spotimVariables.pageNumber | ||
}; | ||
|
||
if($importButton.hasClass('force')) | ||
data.force = true; | ||
|
||
importCommentsToWP( data, $( '.sync-button' ), $messageField, $errorsField ); | ||
|
||
event.preventDefault(); | ||
}); | ||
|
||
// Cancel import | ||
$( '#cancel_import_link' ).on( 'click', function( event ) { | ||
var cancelImportLink = $(this), | ||
$messageField = cancelImportLink.siblings( '.description' ), | ||
$parentElement = cancelImportLink.parent(), | ||
data = { | ||
'action': 'cancel_import', | ||
'spotim_page_number': 0, | ||
'security' : spotimVariables.sync_nonce, | ||
}; | ||
|
||
$parentElement.removeClass( 'in-progress' ); | ||
cancelImportProcess = true; | ||
|
||
$messageField | ||
.removeClass( 'red-color' ) | ||
.text( spotimVariables.cancelImportMessage ); | ||
|
||
$.post( ajaxurl, data, function() { | ||
window.location.reload( true ); | ||
}, 'json' ) | ||
.fail(function() { | ||
window.location.reload( true ); | ||
}); | ||
|
||
|
||
event.preventDefault(); | ||
}); | ||
|
||
// Checks for page number to be above zero to trigger #import_button | ||
if ( !! spotimVariables.pageNumber ) { | ||
$( '#import_button' ).trigger( 'click' ); | ||
} | ||
|
||
// Import Commets to WordPress | ||
function importCommentsToWP( params, $importButton, $messageField, $errorsField ) { | ||
$.post( ajaxurl, params, function( response ) { | ||
if ( cancelImportProcess ) { | ||
return; | ||
} | ||
|
||
delete params.force; | ||
|
||
switch( response.status ) { | ||
case 'refresh': | ||
importCommentsToWP( params, $importButton, $messageField, $errorsField ); | ||
break; | ||
case 'continue': | ||
params.spotim_page_number = params.spotim_page_number + 1; | ||
importCommentsToWP( params, $importButton, $messageField, $errorsField ); | ||
break; | ||
case 'success': | ||
// Enable the import button and hide cancel link | ||
$importButton | ||
.attr( 'disabled', false ) | ||
.parent() | ||
.removeClass( 'in-progress' ); | ||
|
||
// Reset page number to zero | ||
spotimVariables.pageNumber = 0; | ||
break; | ||
case 'error': | ||
var displayErrorLog = false; | ||
|
||
if ( 'undefined' !== typeof response.message ) { | ||
|
||
$messageField.text( response.message ); | ||
$messageField.addClass( 'red-color' ); | ||
|
||
// Enable the import button and hide cancel link | ||
$importButton | ||
.attr( 'disabled', false ) | ||
.parent() | ||
.removeClass( 'in-progress' ); | ||
|
||
return; | ||
} | ||
|
||
// Append to error box | ||
if ( 'undefined' !== typeof response.messages ) { | ||
for ( var message of response.messages ) { | ||
// Check if message is not empty, display error log | ||
if ( message.trim() ) { | ||
displayErrorLog = true; | ||
} | ||
$errorsField.append( | ||
$( '<p>' ).text( message ) | ||
); | ||
} | ||
} | ||
|
||
if ( displayErrorLog ) { | ||
$errorsField.removeClass( 'spotim-hide' ); | ||
} | ||
|
||
// Keep importing, don't stop | ||
params.spotim_page_number = params.spotim_page_number + 1; | ||
importCommentsToWP( params, $importButton, $messageField, $errorsField ); | ||
|
||
// Enable the import button and hide cancel link | ||
// $importButton | ||
// .attr( 'disabled', false ) | ||
// .parent() | ||
// .removeClass( 'in-progress' ); | ||
break; | ||
} | ||
|
||
// Show response message inside message field | ||
$messageField.text( response.message ); | ||
|
||
}, 'json' ) | ||
.fail(function( response ) { | ||
$messageField.addClass( 'red-color' ); | ||
|
||
// Enable the import button and hide cancel link | ||
$importButton | ||
.attr( 'disabled', false ) | ||
.parent() | ||
.removeClass( 'in-progress' ); | ||
|
||
// Show response message inside message field | ||
$messageField.text( spotimVariables.errorMessage ); | ||
}); | ||
} | ||
|
||
}); |
Oops, something went wrong.