diff --git a/lib/classes/class-bootstrap.php b/lib/classes/class-bootstrap.php
index 24659731a..fec34bf11 100644
--- a/lib/classes/class-bootstrap.php
+++ b/lib/classes/class-bootstrap.php
@@ -1169,6 +1169,7 @@ public function admin_init() {
$settings = ud_get_stateless_media()->get('sm');
$settings['wildcards'] = $this->settings->wildcards;
$settings['network_admin'] = is_network_admin();
+ $settings['is_multisite'] = is_multisite();
if(defined('WP_STATELESS_MEDIA_JSON_KEY') && WP_STATELESS_MEDIA_JSON_KEY){
$settings['key_json'] = "Currently configured via a constant.";
}
@@ -1254,7 +1255,7 @@ public function admin_enqueue_scripts( $hook ) {
$data = array(
'key' => 'stateless-cache-busting',
'class' => 'notice',
- 'title' => sprintf( __( "Stateless mode enables and requires the Cache-Busting option.", ud_get_stateless_media()->domain ) ),
+ 'title' => sprintf( __( "Stateless and Ephemeral modes enables and requires the Cache-Busting option.", ud_get_stateless_media()->domain ) ),
'message' => sprintf( __("WordPress looks at local files to prevent files with the same filenames.
Since Stateless mode bypasses this check, there is a potential for files to be stored with the same file name. We enforce the Cache-Busting option to prevent this.
Override with the %s constant.", ud_get_stateless_media()->domain),"https://wp-stateless.github.io/docs/constants/#wp_stateless_media_cache_busting", "WP_STATELESS_MEDIA_CACHE_BUSTING" ),
@@ -1262,6 +1263,16 @@ public function admin_enqueue_scripts( $hook ) {
echo "";
+
+ $data = array(
+ 'key' => 'stateless-folder',
+ 'class' => 'notice',
+ 'title' => sprintf( __( "Stateless mode requires the Folder value.", ud_get_stateless_media()->domain ) ),
+ 'message' => sprintf( __("Field Folder shoul be filled for correct work Stateless mode. ", ud_get_stateless_media()->domain) ),
+ );
+ echo "";
break;
default: break;
}
diff --git a/static/scripts/error-notice.js b/static/scripts/error-notice.js
index 2616a3eb9..340c91b7e 100644
--- a/static/scripts/error-notice.js
+++ b/static/scripts/error-notice.js
@@ -2,70 +2,82 @@
* EVENTS
*/
jQuery( document ).ready( function ($) {
-
- jQuery( document ).on( 'click', '.stateless-admin-notice.ud-admin-notice .button-action', function(e){
- var _this = jQuery( this );
- if(_this.attr('href') != '#'){
- return;
- }
-
- e.preventDefault();
-
- var data = {
- action: 'stateless_enable_notice_button_action',
- key: _this.data('key'),
+ jQuery( document ).on( 'click', '.stateless-admin-notice.ud-admin-notice .button-action', function(e){
+ var _this = jQuery( this );
+ if(_this.attr('href') != '#'){
+ return;
+ }
+
+ e.preventDefault();
+
+
+ var data = {
+ action: 'stateless_enable_notice_button_action',
+ key: _this.data('key'),
+ }
+
+ jQuery.post( ajaxurl, data, function ( result_data ) {
+ if( result_data.success == '1' ) {
+ _this.closest('.ud-admin-notice').remove();
+
+ var key = _this.attr('data-key');
+ key = key.replace('button_secondary_', '');
+ $("#" + key + " option[value=" + key +"]").attr('selected', 'selected');
+ $("#" + key).val('true');
+ } else if ( result_data.success == '0' ) {
+ // alert(result_data.error);
}
-
- jQuery.post( ajaxurl, data, function ( result_data ) {
- if( result_data.success == '1' ) {
- _this.closest('.ud-admin-notice').remove();
-
- var key = _this.attr('data-key');
- key = key.replace('button_secondary_', '');
- $("#" + key + " option[value=" + key +"]").attr('selected', 'selected');
- $("#" + key).val('true');
- } else if ( result_data.success == '0' ) {
- // alert(result_data.error);
- }
- }, "json" );
- return false;
- });
+ }, "json" );
+ return false;
+ });
+
+ jQuery( '.stateless-admin-notice.ud-admin-notice' ).off( 'click', '.dismiss');
+ jQuery( document ).on( 'click', '.stateless-admin-notice.ud-admin-notice .dismiss-warning', function(e){
+ e.preventDefault();
- jQuery( '.stateless-admin-notice.ud-admin-notice' ).off( 'click', '.dismiss');
- jQuery( document ).on( 'click', '.stateless-admin-notice.ud-admin-notice .dismiss-warning', function(e){
- e.preventDefault();
+ var _this = jQuery( this );
- var _this = jQuery( this );
+ var data = {
+ action: 'stateless_notice_dismiss',
+ key: _this.data('key'),
+ }
- var data = {
- action: 'stateless_notice_dismiss',
- key: _this.data('key'),
+ jQuery.post( ajaxurl, data, function ( result_data ) {
+ if( result_data.success == '1' ) {
+ _this.closest('.ud-admin-notice').remove();
+ } else if ( result_data.success == '0' ) {
+ // alert(result_data.error);
}
+ }, "json" );
+ return false;
+ });
- jQuery.post( ajaxurl, data, function ( result_data ) {
- if( result_data.success == '1' ) {
- _this.closest('.ud-admin-notice').remove();
- } else if ( result_data.success == '0' ) {
- // alert(result_data.error);
- }
- }, "json" );
- return false;
- });
+ jQuery('#stless_settings_tab .sm-mode input[type=radio]').on('change', function(){
- jQuery('#stless_settings_tab .sm-mode input[type=radio]').on('change', function(){
- var $this = jQuery('#sm_mode_stateless');
- if($this.is(':checked')){
- var notice = jQuery('#stateless-notice-stateless-cache-busting');
- if(!notice.length){
- notice = jQuery(jQuery('#template-stateless-cache-busting').html());
- notice.appendTo("#stateless-settings-page-title");
- }
- jQuery('#stateless-notice-stateless-cache-busting').show();
+ if($(this).val() == 'stateless' || $(this).val() == 'ephemeral'){
+ var notice = jQuery('#stateless-notice-stateless-cache-busting');
+ if(!notice.length){
+ notice = jQuery(jQuery('#template-stateless-cache-busting').html());
+ notice.appendTo("#stateless-settings-page-title");
}
- else{
- jQuery('#stateless-notice-stateless-cache-busting').hide();
+ jQuery('#stateless-notice-stateless-cache-busting').show();
+ }
+ else{
+ jQuery('#stateless-notice-stateless-cache-busting').hide();
+ }
+
+ if( $(this).val() == 'stateless' ){
+ var notice = jQuery('#stateless-notice-stateless-folder');
+ if(!notice.length){
+ notice = jQuery(jQuery('#template-stateless-folder').html());
+ notice.appendTo("#stateless-settings-page-title");
}
- });
-
- } );
\ No newline at end of file
+ jQuery('#stateless-notice-stateless-folder').show();
+ }
+ else{
+ jQuery('#stateless-notice-stateless-folder').hide();
+ }
+ });
+
+} );
\ No newline at end of file
diff --git a/static/scripts/wp-stateless.js b/static/scripts/wp-stateless.js
index f829052e9..3dc169734 100644
--- a/static/scripts/wp-stateless.js
+++ b/static/scripts/wp-stateless.js
@@ -7,926 +7,954 @@
var wpStatelessApp = angular.module('wpStatelessApp', ['ngSanitize'])
// Controller
-.controller('wpStatelessTools', ['$scope', '$http', function ($scope, $http) {
-
- var WP_DEBUG = wp_stateless_configs.WP_DEBUG || false;
- $scope.action = 'regenerate_images';
- $scope.method = 'start';
- $scope.bulk_size = 1;
-
- /**
- * Counters
- * @type {number}
- */
- $scope.objectsCounter = 0;
- $scope.objectsTotal = 0;
-
- /**
- * Error storage
- * @type {boolean}
- */
- $scope.error = false;
-
- /**
- * Flags
- * @type {boolean}
- */
- $scope.isRunning = false;
- $scope.isLoading = false;
- $scope.continue = true;
-
- /**
- *
- * @type {{images: boolean, other: boolean}}
- */
- $scope.progresses = {
- images: false,
- other: false
- };
-
- /**
- *
- * @type {{images: boolean, other: boolean}}
- */
- $scope.fails = {
- images: false,
- other: false
- }
+ .controller('wpStatelessTools', ['$scope', '$http', function ($scope, $http) {
- /**
- * IDs storage
- * @type {Array}
- */
- $scope.objectIDs = [];
-
- /**
- *
- * @type {Array}
- */
- $scope.chunkIDs = [];
-
- /**
- * Log
- * @type {Array}
- */
- $scope.log = [];
-
- /**
- * Status message
- * @type {String}
- */
- $scope.status = '';
-
- /**
- * Status message
- * @type {String}
- */
- $scope.extraStatus = '';
-
- /**
- * Init
- */
- $scope.init = function() {
- jQuery("#regenthumbs-bar").progressbar();
- }
+ var WP_DEBUG = wp_stateless_configs.WP_DEBUG || false;
+ $scope.action = 'regenerate_images';
+ $scope.method = 'start';
+ $scope.bulk_size = 1;
- /**
- * Get error message
- */
- $scope.getError = function(response, message) {
- if(response.data && typeof response.data.data !== 'undefined' && typeof response.data.success !== 'undefined' && response.data.success == false){
- $scope.extraStatus = response.data.data;
- return message;
- }
+ /**
+ * Counters
+ * @type {number}
+ */
+ $scope.objectsCounter = 0;
+ $scope.objectsTotal = 0;
- if(response.data && typeof response.data.data !== 'undefined'){
- return response.data.data;
- }
+ /**
+ * Error storage
+ * @type {boolean}
+ */
+ $scope.error = false;
- if(response.data && typeof response.data == 'string'){
- $scope.extraStatus = response.data;
- return message;
+ /**
+ * Flags
+ * @type {boolean}
+ */
+ $scope.isRunning = false;
+ $scope.isLoading = false;
+ $scope.continue = true;
+
+ /**
+ *
+ * @type {{images: boolean, other: boolean}}
+ */
+ $scope.progresses = {
+ images: false,
+ other: false
+ };
+
+ /**
+ *
+ * @type {{images: boolean, other: boolean}}
+ */
+ $scope.fails = {
+ images: false,
+ other: false
}
- if(!response.data && response.statusText){
- return response.statusText + " (" + stateless_l10n.response_code + response.status + ")";
- }
+ /**
+ * IDs storage
+ * @type {Array}
+ */
+ $scope.objectIDs = [];
+
+ /**
+ *
+ * @type {Array}
+ */
+ $scope.chunkIDs = [];
- if(!response.data && response.status == -1){
- return stateless_l10n.unable_to_connect_to_the_server;
+ /**
+ * Log
+ * @type {Array}
+ */
+ $scope.log = [];
+
+ /**
+ * Status message
+ * @type {String}
+ */
+ $scope.status = '';
+
+ /**
+ * Status message
+ * @type {String}
+ */
+ $scope.extraStatus = '';
+
+ /**
+ * Init
+ */
+ $scope.init = function() {
+ jQuery("#regenthumbs-bar").progressbar();
}
- return message;
- }
+ /**
+ * Get error message
+ */
+ $scope.getError = function(response, message) {
+ if(response.data && typeof response.data.data !== 'undefined' && typeof response.data.success !== 'undefined' && response.data.success == false){
+ $scope.extraStatus = response.data.data;
+ return message;
+ }
+
+ if(response.data && typeof response.data.data !== 'undefined'){
+ return response.data.data;
+ }
- /**
- *
- * @param callback
- */
- $scope.getBucketFolder = function( callback ) {
+ if(response.data && typeof response.data == 'string'){
+ $scope.extraStatus = response.data;
+ return message;
+ }
+
+ if(!response.data && response.statusText){
+ return response.statusText + " (" + stateless_l10n.response_code + response.status + ")";
+ }
+
+ if(!response.data && response.status == -1){
+ return stateless_l10n.unable_to_connect_to_the_server;
+ }
+
+ return message;
+ }
+
+ /**
+ *
+ * @param callback
+ */
+ $scope.getBucketFolder = function( callback ) {
$scope.isLoading = true;
$http({
- method: 'GET',
- url: ajaxurl,
- params: {
- action: 'stateless_get_bucket_folder'
- }
+ method: 'GET',
+ url: ajaxurl,
+ params: {
+ action: 'stateless_get_bucket_folder'
+ }
}).then(function(response){
- var data = response.data || {};
+ var data = response.data || {};
- if ( data.success ) {
- if ( typeof data.data !== 'undefined' ) {
- $scope.bucket_folder = data.data.bucket_folder;
+ if ( data.success ) {
+ if ( typeof data.data !== 'undefined' ) {
+ $scope.bucket_folder = data.data.bucket_folder;
- if ( 'function' === typeof callback ) {
- callback();
- }
- } else {
- console.error( stateless_l10n.could_not_retrieve_progress );
- }
+ if ( 'function' === typeof callback ) {
+ callback();
+ }
} else {
- console.error( stateless_l10n.could_not_retrieve_progress );
+ console.error( stateless_l10n.could_not_retrieve_progress );
}
+ } else {
+ console.error( stateless_l10n.could_not_retrieve_progress );
+ }
- $scope.isLoading = false;
+ $scope.isLoading = false;
}, function(response) {
- console.error( stateless_l10n.could_not_retrieve_progress );
+ console.error( stateless_l10n.could_not_retrieve_progress );
- $scope.isLoading = false;
+ $scope.isLoading = false;
});
- };
-
- /**
- *
- */
- $scope.getBucketFolder();
-
- /**
- *
- * @param callback
- */
- $scope.getCurrentProgresses = function( callback ) {
- $scope.isLoading = true;
-
- $http({
- method: 'GET',
- url: ajaxurl,
- params: {
- action: 'stateless_get_current_progresses'
- }
- }).then(function(response){
- var data = response.data || {};
-
- if ( data.success ) {
- if ( typeof data.data !== 'undefined' ) {
- $scope.progresses.images = data.data.images;
- $scope.progresses.other = data.data.other;
- $scope.startFrom = null;
- if($scope.action == 'regenerate_images' && typeof $scope.progresses.images[1] == "number"){
- // Subtracting 1 so user get where from the sync will start instead of where it ended. We will add 1 in class-ajax.php.
- $scope.startFrom = $scope.progresses.images[1] - 1;
- }
- else if($scope.action == 'sync_non_images' && typeof $scope.progresses.other[1] == "number"){
- // Subtracting 1 so user get where from the sync will start instead of where it ended. We will add 1 in class-ajax.php.
- $scope.startFrom = $scope.progresses.other[1] - 1;
- }
+ };
+
+ /**
+ *
+ */
+ $scope.getBucketFolder();
+
+ /**
+ *
+ * @param callback
+ */
+ $scope.getCurrentProgresses = function( callback ) {
+ $scope.isLoading = true;
+
+ $http({
+ method: 'GET',
+ url: ajaxurl,
+ params: {
+ action: 'stateless_get_current_progresses'
+ }
+ }).then(function(response){
+ var data = response.data || {};
- if ( 'function' === typeof callback ) {
- callback();
+ if ( data.success ) {
+ if ( typeof data.data !== 'undefined' ) {
+ $scope.progresses.images = data.data.images;
+ $scope.progresses.other = data.data.other;
+ $scope.startFrom = null;
+ if($scope.action == 'regenerate_images' && typeof $scope.progresses.images[1] == "number"){
+ // Subtracting 1 so user get where from the sync will start instead of where it ended. We will add 1 in class-ajax.php.
+ $scope.startFrom = $scope.progresses.images[1] - 1;
+ }
+ else if($scope.action == 'sync_non_images' && typeof $scope.progresses.other[1] == "number"){
+ // Subtracting 1 so user get where from the sync will start instead of where it ended. We will add 1 in class-ajax.php.
+ $scope.startFrom = $scope.progresses.other[1] - 1;
+ }
+
+ if ( 'function' === typeof callback ) {
+ callback();
+ }
+ } else {
+ console.error( stateless_l10n.could_not_retrieve_progress );
}
} else {
console.error( stateless_l10n.could_not_retrieve_progress );
}
- } else {
- console.error( stateless_l10n.could_not_retrieve_progress );
- }
-
- $scope.isLoading = false;
- }, function(response) {
- console.error( stateless_l10n.could_not_retrieve_progress );
-
- $scope.isLoading = false;
- });
- };
- /**
- *
- */
- $scope.getCurrentProgresses();
+ $scope.isLoading = false;
+ }, function(response) {
+ console.error( stateless_l10n.could_not_retrieve_progress );
- /**
- *
- * @param callback
- */
- function getAllFails( callback ) {
- $scope.isLoading = true;
+ $scope.isLoading = false;
+ });
+ };
+
+ /**
+ *
+ */
+ $scope.getCurrentProgresses();
+
+ /**
+ *
+ * @param callback
+ */
+ function getAllFails( callback ) {
+ $scope.isLoading = true;
- $http({
- method: 'GET',
- url: ajaxurl,
- params: {
- action: 'stateless_get_all_fails'
- }
- }).then(function(response){
- var data = response.data || {};
+ $http({
+ method: 'GET',
+ url: ajaxurl,
+ params: {
+ action: 'stateless_get_all_fails'
+ }
+ }).then(function(response){
+ var data = response.data || {};
- if ( data.success ) {
- if ( typeof data.data !== 'undefined' ) {
+ if ( data.success ) {
+ if ( typeof data.data !== 'undefined' ) {
- $scope.fails.images = data.data.images;
- $scope.fails.other = data.data.other;
+ $scope.fails.images = data.data.images;
+ $scope.fails.other = data.data.other;
- if ( 'function' === typeof callback ) {
- callback();
+ if ( 'function' === typeof callback ) {
+ callback();
+ }
+ } else {
+ console.error( stateless_l10n.could_not_get_fails );
}
} else {
console.error( stateless_l10n.could_not_get_fails );
}
- } else {
- console.error( stateless_l10n.could_not_get_fails );
- }
-
- $scope.isLoading = false;
- }, function(response) {
- console.error( stateless_l10n.could_not_get_fails );
- $scope.isLoading = false;
- });
- };
+ $scope.isLoading = false;
+ }, function(response) {
+ console.error( stateless_l10n.could_not_get_fails );
- getAllFails();
+ $scope.isLoading = false;
+ });
+ };
+
+ getAllFails();
+
+ /**
+ * Form submit handler
+ * @param e
+ * @returns {boolean}
+ */
+ $scope.processStart = function(e) {
+
+ $scope.error = false;
+ $scope.status = '';
+ $scope.extraStatus = '';
+ $scope.objectsCounter = 0;
+ $scope.objectsTotal = 0;
+ $scope.objectIDs = [];
+ $scope.chunkIDs = [];
+
+ if ( $scope.method === 'fix' ) {
+
+ if ( $scope.action ) {
+ switch( $scope.action ) {
+ case 'regenerate_images':
+ $scope.objectIDs = $scope.fails.images;
+ $scope.regenerateImages();
+ break;
+ case 'sync_non_images':
+ $scope.objectIDs = $scope.fails.other;
+ $scope.syncFiles();
+ break;
+ default: break;
+ }
+ }
- /**
- * Form submit handler
- * @param e
- * @returns {boolean}
- */
- $scope.processStart = function(e) {
+ return false;
+ }
- $scope.error = false;
- $scope.status = '';
- $scope.extraStatus = '';
- $scope.objectsCounter = 0;
- $scope.objectsTotal = 0;
- $scope.objectIDs = [];
- $scope.chunkIDs = [];
+ var cont = 0;
+ if ( 'continue' === $scope.method ) {
+ cont = 1;
+ }
- if ( $scope.method === 'fix' ) {
+ var use_wildcards = 0;
+ if ( 'use_wildcards' === $scope.method ) {
+ use_wildcards = 1;
+ }
if ( $scope.action ) {
switch( $scope.action ) {
case 'regenerate_images':
- $scope.objectIDs = $scope.fails.images;
- $scope.regenerateImages();
+ $scope.getImagesMedia( $scope.regenerateImages, cont, use_wildcards );
break;
case 'sync_non_images':
- $scope.objectIDs = $scope.fails.other;
- $scope.syncFiles();
+ $scope.getOtherMedia( $scope.syncFiles, cont, use_wildcards );
+ break;
+ case 'sync_non_library_files':
+ $scope.getNonLibraryFiles( $scope.syncNonLibraryFiles, cont );
break;
default: break;
}
}
return false;
- }
+ };
+
+ /**
+ * Stop process
+ */
+ $scope.processStop = function() {
+ $scope.status = stateless_l10n.stopping;
+ $scope.continue = false;
+ };
+
+ function array_bulk( arr, bulk_size ) {
+ var groups = [];
+ var i;
+
+ for ( i = 0; i < bulk_size; i++ ) {
+ groups[ i ] = [];
+ }
- var cont = 0;
- if ( 'continue' === $scope.method ) {
- cont = 1;
- }
+ for ( i = 0; i < arr.length; i ++ ) {
+ groups[ i % bulk_size ].push( arr[ i ] );
+ }
- var use_wildcards = 0;
- if ( 'use_wildcards' === $scope.method ) {
- use_wildcards = 1;
+ return groups;
}
- if ( $scope.action ) {
- switch( $scope.action ) {
- case 'regenerate_images':
- $scope.getImagesMedia( $scope.regenerateImages, cont, use_wildcards );
- break;
- case 'sync_non_images':
- $scope.getOtherMedia( $scope.syncFiles, cont, use_wildcards );
- break;
- case 'sync_non_library_files':
- $scope.getNonLibraryFiles( $scope.syncNonLibraryFiles, cont );
- break;
- default: break;
+ $scope.finishProcess = function( chunk_id ) {
+ var mode = 'images';
+ if ( 'sync_non_images' === $scope.action ) {
+ mode = 'other';
}
- }
- return false;
- };
+ if ( $scope.objectsCounter >= $scope.objectsTotal ) {
+ // process finished
- /**
- * Stop process
- */
- $scope.processStop = function() {
- $scope.status = stateless_l10n.stopping;
- $scope.continue = false;
- };
-
- function array_bulk( arr, bulk_size ) {
- var groups = [];
- var i;
-
- for ( i = 0; i < bulk_size; i++ ) {
- groups[ i ] = [];
- }
+ $http({
+ method: 'GET',
+ url: ajaxurl,
+ params: {
+ action: 'stateless_reset_progress',
+ mode: mode
+ }
+ }).then(function(response){
+ $scope.progresses[ mode ] = false;
- for ( i = 0; i < arr.length; i ++ ) {
- groups[ i % bulk_size ].push( arr[ i ] );
- }
+ $scope.status = stateless_l10n.finished;
+ $scope.isLoading = false;
+ $scope.isRunning = false;
+ }, function(response) {
+ console.error( stateless_l10n.could_not_reset_progress );
+ });
+ } else if ( 'undefined' !== typeof chunk_id ) {
+ // process cancelled, but this is only a chunk finishing request
+
+ $scope.chunkIDs[ chunk_id ] = false;
+ var all_done = true;
+ for ( var i in $scope.chunkIDs ) {
+ if ( false !== $scope.chunkIDs[ i ] ) {
+ all_done = false;
+ break;
+ }
+ }
+ if ( all_done ) {
+ $scope.getCurrentProgresses( function() {
+ $scope.status = stateless_l10n.cancelled;
+ $scope.isRunning = false;
+ });
+ }
+ } else {
+ // process cancelled
- return groups;
- }
+ $scope.getCurrentProgresses( function() {
+ $scope.status = stateless_l10n.cancelled;
+ $scope.isRunning = false;
+ });
+ }
+ };
- $scope.finishProcess = function( chunk_id ) {
- var mode = 'images';
- if ( 'sync_non_images' === $scope.action ) {
- mode = 'other';
- }
+ /**
+ * Load images IDs
+ * @param callback
+ */
+ $scope.getImagesMedia = function( callback, cont, use_wildcards ) {
- if ( $scope.objectsCounter >= $scope.objectsTotal ) {
- // process finished
+ $scope.continue = true;
+ $scope.isLoading = true;
+ $scope.status = stateless_l10n.loading_images_media_objects;
$http({
method: 'GET',
url: ajaxurl,
params: {
- action: 'stateless_reset_progress',
- mode: mode
+ action: 'get_images_media_ids',
+ start_from: $scope.startFrom,
+ continue: cont
}
}).then(function(response){
- $scope.progresses[ mode ] = false;
+ var data = response.data || {};
+
+ if ( data.success ) {
+ if ( typeof callback === 'function' ) {
+ if ( typeof data.data !== 'undefined' ) {
+ $scope.objectIDs = data.data;
+ $scope.use_wildcards = use_wildcards;
+ callback();
+ } else {
+ $scope.status = stateless_l10n.ids_are_malformed;
+ $scope.error = true;
+ }
+ }
+ } else {
+ $scope.status = $scope.getError(response, stateless_l10n.unable_to_get_images_media_id);
+ $scope.error = true;
+ }
- $scope.status = stateless_l10n.finished;
$scope.isLoading = false;
- $scope.isRunning = false;
- }, function(response) {
- console.error( stateless_l10n.could_not_reset_progress );
- });
- } else if ( 'undefined' !== typeof chunk_id ) {
- // process cancelled, but this is only a chunk finishing request
- $scope.chunkIDs[ chunk_id ] = false;
- var all_done = true;
- for ( var i in $scope.chunkIDs ) {
- if ( false !== $scope.chunkIDs[ i ] ) {
- all_done = false;
- break;
+ if(WP_DEBUG){
+ console.log(stateless_l10n.wp_stateless_get_images_media_id, response);
}
- }
- if ( all_done ) {
- $scope.getCurrentProgresses( function() {
- $scope.status = stateless_l10n.cancelled;
- $scope.isRunning = false;
- });
- }
- } else {
- // process cancelled
- $scope.getCurrentProgresses( function() {
- $scope.status = stateless_l10n.cancelled;
- $scope.isRunning = false;
- });
- }
- };
-
- /**
- * Load images IDs
- * @param callback
- */
- $scope.getImagesMedia = function( callback, cont, use_wildcards ) {
-
- $scope.continue = true;
- $scope.isLoading = true;
- $scope.status = stateless_l10n.loading_images_media_objects;
-
- $http({
- method: 'GET',
- url: ajaxurl,
- params: {
- action: 'get_images_media_ids',
- start_from: $scope.startFrom,
- continue: cont
- }
- }).then(function(response){
- var data = response.data || {};
-
- if ( data.success ) {
- if ( typeof callback === 'function' ) {
- if ( typeof data.data !== 'undefined' ) {
- $scope.objectIDs = data.data;
- $scope.use_wildcards = use_wildcards;
- callback();
- } else {
- $scope.status = stateless_l10n.ids_are_malformed;
- $scope.error = true;
- }
- }
- } else {
- $scope.status = $scope.getError(response, stateless_l10n.unable_to_get_images_media_id);
+ }, function(response) {
$scope.error = true;
- }
-
- $scope.isLoading = false;
+ $scope.status = $scope.getError(response, get_images_media_id + ": " + stateless_l10n.request_failed);
+ $scope.isLoading = false;
- if(WP_DEBUG){
- console.log(stateless_l10n.wp_stateless_get_images_media_id, response);
- }
+ if(WP_DEBUG){
+ console.log(stateless_l10n.wp_stateless_get_images_media_id + ": " + stateless_l10n.request_failed, response, typeof response.headers === 'function'?response.headers() : '');
+ }
+ });
- }, function(response) {
- $scope.error = true;
- $scope.status = $scope.getError(response, get_images_media_id + ": " + stateless_l10n.request_failed);
- $scope.isLoading = false;
+ };
- if(WP_DEBUG){
- console.log(stateless_l10n.wp_stateless_get_images_media_id + ": " + stateless_l10n.request_failed, response, typeof response.headers === 'function'?response.headers() : '');
- }
- });
+ /**
+ * Load non-images media files
+ * @param callback
+ */
+ $scope.getOtherMedia = function( callback, cont, use_wildcards ) {
- };
+ $scope.continue = true;
+ $scope.isLoading = true;
+ $scope.status = stateless_l10n.loading_non_image_media_objects;
- /**
- * Load non-images media files
- * @param callback
- */
- $scope.getOtherMedia = function( callback, cont, use_wildcards ) {
+ $http({
+ method: 'GET',
+ url: ajaxurl,
+ params: {
+ action: 'get_other_media_ids',
+ start_from: $scope.startFrom,
+ continue: cont
+ }
+ }).then(function(response){
+ var data = response.data || {};
- $scope.continue = true;
- $scope.isLoading = true;
- $scope.status = stateless_l10n.loading_non_image_media_objects;
+ if ( data.success ) {
+ if ( typeof callback === 'function' ) {
+ if ( typeof data.data !== 'undefined' ) {
+ $scope.objectIDs = data.data;
+ $scope.use_wildcards = use_wildcards;
+ callback();
+ } else {
+ $scope.status = $scope.getError(response, stateless_l10n.ids_are_malformed);
+ $scope.error = true;
+ }
+ }
+ } else {
+ $scope.status = $scope.getError(response, stateless_l10n.unable_to_get_non_images_media_id);
+ $scope.error = true;
+ }
- $http({
- method: 'GET',
- url: ajaxurl,
- params: {
- action: 'get_other_media_ids',
- start_from: $scope.startFrom,
- continue: cont
- }
- }).then(function(response){
- var data = response.data || {};
+ $scope.isLoading = false;
- if ( data.success ) {
- if ( typeof callback === 'function' ) {
- if ( typeof data.data !== 'undefined' ) {
- $scope.objectIDs = data.data;
- $scope.use_wildcards = use_wildcards;
- callback();
- } else {
- $scope.status = $scope.getError(response, stateless_l10n.ids_are_malformed);
- $scope.error = true;
- }
+ if(WP_DEBUG){
+ console.log("WP-Stateless get non Images Media ID:", response, typeof response.headers === 'function'?response.headers(): "");
}
- } else {
- $scope.status = $scope.getError(response, stateless_l10n.unable_to_get_non_images_media_id);
+ }, function(response) {
$scope.error = true;
- }
+ $scope.status = $scope.getError(response, stateless_l10n.get_non_images_media_id_request_failed);
+ $scope.isLoading = false;
+ if(WP_DEBUG){
+ console.log("WP-Stateless get non Images Media ID: Request failed", response, typeof response.headers === 'function'?response.headers(): "");
+ }
+ });
- $scope.isLoading = false;
+ };
- if(WP_DEBUG){
- console.log("WP-Stateless get non Images Media ID:", response, typeof response.headers === 'function'?response.headers(): "");
- }
- }, function(response) {
- $scope.error = true;
- $scope.status = $scope.getError(response, stateless_l10n.get_non_images_media_id_request_failed);
- $scope.isLoading = false;
- if(WP_DEBUG){
- console.log("WP-Stateless get non Images Media ID: Request failed", response, typeof response.headers === 'function'?response.headers(): "");
- }
- });
+ /**
+ * Load non-images media files
+ * @param callback
+ */
+ $scope.getNonLibraryFiles = function( callback, cont ) {
- };
+ $scope.continue = true;
+ $scope.isLoading = true;
+ $scope.status = stateless_l10n.loading_non_library_objects;
- /**
- * Load non-images media files
- * @param callback
- */
- $scope.getNonLibraryFiles = function( callback, cont ) {
+ $http({
+ method: 'GET',
+ url: ajaxurl,
+ params: {
+ action: 'get_non_library_files_id',
+ continue: cont
+ }
+ }).then(function(response){
+ var data = response.data || {};
- $scope.continue = true;
- $scope.isLoading = true;
- $scope.status = stateless_l10n.loading_non_library_objects;
+ if ( data.success ) {
+ if ( typeof callback === 'function' ) {
+ if ( typeof data.data !== 'undefined' ) {
+ $scope.objectIDs = data.data;
+ callback();
+ } else {
+ $scope.status = $scope.getError(response, stateless_l10n.ids_are_malformed);
+ $scope.error = true;
+ }
+ }
+ } else {
+ $scope.error = true;
+ $scope.status = $scope.getError(response, stateless_l10n.non_libraries_files_are_not_found);
+ }
- $http({
- method: 'GET',
- url: ajaxurl,
- params: {
- action: 'get_non_library_files_id',
- continue: cont
- }
- }).then(function(response){
- var data = response.data || {};
+ $scope.isLoading = false;
- if ( data.success ) {
- if ( typeof callback === 'function' ) {
- if ( typeof data.data !== 'undefined' ) {
- $scope.objectIDs = data.data;
- callback();
- } else {
- $scope.status = $scope.getError(response, stateless_l10n.ids_are_malformed);
- $scope.error = true;
- }
+ if(WP_DEBUG){
+ console.log("WP-Stateless get non library files:", response, typeof response.headers === 'function'?response.headers(): "");
}
- } else {
+ }, function(response) {
$scope.error = true;
- $scope.status = $scope.getError(response, stateless_l10n.non_libraries_files_are_not_found);
- }
+ $scope.status = $scope.getError(response, stateless_l10n.get_non_library_files_request_failed);
+ $scope.isLoading = false;
- $scope.isLoading = false;
+ if(WP_DEBUG){
+ console.log("WP-Stateless get non library files: Request failed", response, typeof response.headers === 'function'?response.headers(): "");
+ }
+ });
- if(WP_DEBUG){
- console.log("WP-Stateless get non library files:", response, typeof response.headers === 'function'?response.headers(): "");
+ };
+
+ /**
+ * Run sync for files
+ */
+ $scope.syncNonLibraryFiles = function() {
+ $scope.isRunning = true;
+ $scope.objectsTotal = $scope.objectIDs.length;
+ $scope.objectsCounter = 0;
+ $scope.status = stateless_l10n.processing_files + $scope.objectsTotal + stateless_l10n._total___;
+
+ jQuery("#regenthumbs-bar").progressbar("value", 0);
+ jQuery("#regenthumbs-bar-percent").html( "0%" );
+
+ if ( $scope.objectIDs.length ) {
+ //$scope.syncSingleNonLibraryFile( $scope.objectIDs.shift() );
+ $scope.chunkIDs = array_bulk( $scope.objectIDs, $scope.bulk_size );
+ for ( var i in $scope.chunkIDs ) {
+ $scope.syncSingleNonLibraryFile( $scope.chunkIDs[ i ].shift(), i );
+ }
}
- }, function(response) {
- $scope.error = true;
- $scope.status = $scope.getError(response, stateless_l10n.get_non_library_files_request_failed);
- $scope.isLoading = false;
+ }
- if(WP_DEBUG){
- console.log("WP-Stateless get non library files: Request failed", response, typeof response.headers === 'function'?response.headers(): "");
+ /**
+ * Run sync for files
+ */
+ $scope.syncFiles = function() {
+ $scope.isRunning = true;
+ $scope.objectsTotal = $scope.objectIDs.length;
+ $scope.objectsCounter = 0;
+ $scope.status = stateless_l10n.processing_files + $scope.objectsTotal + stateless_l10n._total___;
+
+ jQuery("#regenthumbs-bar").progressbar("value", 0);
+ jQuery("#regenthumbs-bar-percent").html( "0%" );
+
+ if ( $scope.objectIDs.length ) {
+ //$scope.syncSingleFile( $scope.objectIDs.shift() );
+ $scope.chunkIDs = array_bulk( $scope.objectIDs, $scope.bulk_size );
+ for ( var i in $scope.chunkIDs ) {
+ $scope.syncSingleFile( $scope.chunkIDs[ i ].shift(), $scope.use_wildcards, i );
+ }
}
- });
-
- };
-
- /**
- * Run sync for files
- */
- $scope.syncNonLibraryFiles = function() {
- $scope.isRunning = true;
- $scope.objectsTotal = $scope.objectIDs.length;
- $scope.objectsCounter = 0;
- $scope.status = stateless_l10n.processing_files + $scope.objectsTotal + stateless_l10n._total___;
-
- jQuery("#regenthumbs-bar").progressbar("value", 0);
- jQuery("#regenthumbs-bar-percent").html( "0%" );
+ }
- if ( $scope.objectIDs.length ) {
- //$scope.syncSingleNonLibraryFile( $scope.objectIDs.shift() );
- $scope.chunkIDs = array_bulk( $scope.objectIDs, $scope.bulk_size );
- for ( var i in $scope.chunkIDs ) {
- $scope.syncSingleNonLibraryFile( $scope.chunkIDs[ i ].shift(), i );
+ /**
+ * Run images regeneration
+ * @param ids
+ */
+ $scope.regenerateImages = function() {
+ $scope.isRunning = true;
+ $scope.objectsTotal = $scope.objectIDs.length;
+ $scope.objectsCounter = 0;
+ $scope.status = stateless_l10n.processing_images + $scope.objectsTotal + stateless_l10n._total___;
+
+ jQuery("#regenthumbs-bar").progressbar("value", 0);
+ jQuery("#regenthumbs-bar-percent").html( "0%" );
+
+ if ( $scope.objectIDs.length ) {
+ //$scope.regenerateSingle( $scope.objectIDs.shift() );
+ $scope.chunkIDs = array_bulk( $scope.objectIDs, $scope.bulk_size );
+ for ( var i in $scope.chunkIDs ) {
+ $scope.regenerateSingle( $scope.chunkIDs[ i ].shift(), $scope.use_wildcards, i );
+ }
}
- }
- }
+ };
- /**
- * Run sync for files
- */
- $scope.syncFiles = function() {
- $scope.isRunning = true;
- $scope.objectsTotal = $scope.objectIDs.length;
- $scope.objectsCounter = 0;
- $scope.status = stateless_l10n.processing_files + $scope.objectsTotal + stateless_l10n._total___;
+ /**
+ * Process Single Image
+ * @param id
+ */
+ $scope.regenerateSingle = function( id, use_wildcards, chunk_id ) {
- jQuery("#regenthumbs-bar").progressbar("value", 0);
- jQuery("#regenthumbs-bar-percent").html( "0%" );
+ $http({
+ method: 'GET',
+ url: ajaxurl,
+ params: {
+ action: "stateless_process_image",
+ id: id,
+ use_wildcards: use_wildcards
+ }
+ }).then(
+ function(response) {
+ var data = response.data || {};
+ $scope.log.push({message:data.data || stateless_l10n.regenerate_single_image_failed});
- if ( $scope.objectIDs.length ) {
- //$scope.syncSingleFile( $scope.objectIDs.shift() );
- $scope.chunkIDs = array_bulk( $scope.objectIDs, $scope.bulk_size );
- for ( var i in $scope.chunkIDs ) {
- $scope.syncSingleFile( $scope.chunkIDs[ i ].shift(), $scope.use_wildcards, i );
- }
- }
- }
+ jQuery("#regenthumbs-bar").progressbar( "value", ( ++$scope.objectsCounter / $scope.objectsTotal ) * 100 );
+ jQuery("#regenthumbs-bar-percent").html( Math.round( ( $scope.objectsCounter / $scope.objectsTotal ) * 1000 ) / 10 + "%" );
- /**
- * Run images regeneration
- * @param ids
- */
- $scope.regenerateImages = function() {
- $scope.isRunning = true;
- $scope.objectsTotal = $scope.objectIDs.length;
- $scope.objectsCounter = 0;
- $scope.status = stateless_l10n.processing_images + $scope.objectsTotal + stateless_l10n._total___;
+ if(typeof response.data.success == 'undefined' || response.data.success == false){
+ $scope.error = true;
+ $scope.status = $scope.getError(response, stateless_l10n.regenerate_single_image_failed);
+ // $scope.isRunning = false;
+ }
- jQuery("#regenthumbs-bar").progressbar("value", 0);
- jQuery("#regenthumbs-bar-percent").html( "0%" );
+ if ( 'undefined' !== typeof chunk_id ) {
+ if ( $scope.chunkIDs[ chunk_id ].length && $scope.continue ) {
+ $scope.regenerateSingle( $scope.chunkIDs[ chunk_id ].shift(), use_wildcards, chunk_id );
+ } else {
+ $scope.finishProcess( chunk_id );
+ }
+ } else {
+ if ( $scope.objectIDs.length && $scope.continue ) {
+ $scope.regenerateSingle( $scope.objectIDs.shift(), use_wildcards );
+ } else {
+ $scope.finishProcess();
+ }
+ }
+ if(WP_DEBUG){
+ console.log("WP-Stateless regenerate single image:", response, typeof response.headers === 'function'?response.headers(): "");
+ }
+ },
+ function(response) {
+ $scope.error = true;
+ $scope.status = $scope.getError(response, stateless_l10n.regenerate_single_image_request_failed);
+ $scope.isRunning = false;
+ if(WP_DEBUG){
+ console.log("WP-Stateless regenerate single image: Request failed", response, typeof response.headers === 'function'?response.headers(): "");
+ }
+ }
+ );
- if ( $scope.objectIDs.length ) {
- //$scope.regenerateSingle( $scope.objectIDs.shift() );
- $scope.chunkIDs = array_bulk( $scope.objectIDs, $scope.bulk_size );
- for ( var i in $scope.chunkIDs ) {
- $scope.regenerateSingle( $scope.chunkIDs[ i ].shift(), $scope.use_wildcards, i );
- }
}
- };
-
- /**
- * Process Single Image
- * @param id
- */
- $scope.regenerateSingle = function( id, use_wildcards, chunk_id ) {
-
- $http({
- method: 'GET',
- url: ajaxurl,
- params: {
- action: "stateless_process_image",
- id: id,
- use_wildcards: use_wildcards
- }
- }).then(
- function(response) {
- var data = response.data || {};
- $scope.log.push({message:data.data || stateless_l10n.regenerate_single_image_failed});
- jQuery("#regenthumbs-bar").progressbar( "value", ( ++$scope.objectsCounter / $scope.objectsTotal ) * 100 );
- jQuery("#regenthumbs-bar-percent").html( Math.round( ( $scope.objectsCounter / $scope.objectsTotal ) * 1000 ) / 10 + "%" );
+ /**
+ * Process single file
+ * @param id
+ */
+ $scope.syncSingleFile = function( id, use_wildcards, chunk_id ) {
- if(typeof response.data.success == 'undefined' || response.data.success == false){
- $scope.error = true;
- $scope.status = $scope.getError(response, stateless_l10n.regenerate_single_image_failed);
- // $scope.isRunning = false;
+ $http({
+ method: 'GET',
+ url: ajaxurl,
+ params: {
+ action: "stateless_process_file",
+ id: id,
+ use_wildcards: use_wildcards
}
+ }).then(
+ function(response) {
+ var data = response.data || {};
+ $scope.log.push({message: $scope.getError(response, stateless_l10n.sync_single_file_failed)});
- if ( 'undefined' !== typeof chunk_id ) {
- if ( $scope.chunkIDs[ chunk_id ].length && $scope.continue ) {
- $scope.regenerateSingle( $scope.chunkIDs[ chunk_id ].shift(), use_wildcards, chunk_id );
- } else {
- $scope.finishProcess( chunk_id );
+ jQuery("#regenthumbs-bar").progressbar( "value", ( ++$scope.objectsCounter / $scope.objectsTotal ) * 100 );
+ jQuery("#regenthumbs-bar-percent").html( Math.round( ( $scope.objectsCounter / $scope.objectsTotal ) * 1000 ) / 10 + "%" );
+
+ if(typeof response.data.success == 'undefined' || response.data.success == false){
+ $scope.error = true;
+ $scope.status = $scope.getError(response, stateless_l10n.sync_single_file_failed);
+ // $scope.isRunning = false;
}
- } else {
- if ( $scope.objectIDs.length && $scope.continue ) {
- $scope.regenerateSingle( $scope.objectIDs.shift(), use_wildcards );
+
+ if ( 'undefined' !== typeof chunk_id ) {
+ if ( $scope.chunkIDs[ chunk_id ].length && $scope.continue ) {
+ $scope.syncSingleFile( $scope.chunkIDs[ chunk_id ].shift(), use_wildcards, chunk_id );
+ } else {
+ $scope.finishProcess( chunk_id );
+ }
} else {
- $scope.finishProcess();
+ if ( $scope.objectIDs.length && $scope.continue ) {
+ $scope.syncSingleFile( $scope.objectIDs.shift(), use_wildcards );
+ } else {
+ $scope.finishProcess();
+ }
}
- }
- if(WP_DEBUG){
- console.log("WP-Stateless regenerate single image:", response, typeof response.headers === 'function'?response.headers(): "");
- }
- },
- function(response) {
- $scope.error = true;
- $scope.status = $scope.getError(response, stateless_l10n.regenerate_single_image_request_failed);
- $scope.isRunning = false;
- if(WP_DEBUG){
- console.log("WP-Stateless regenerate single image: Request failed", response, typeof response.headers === 'function'?response.headers(): "");
- }
- }
- );
- }
+ if(WP_DEBUG){
+ console.log("WP-Stateless sync single file:", response, typeof response.headers === 'function'?response.headers(): "");
+ }
+ },
+ function(response) {
+ $scope.error = true;
+ $scope.status = $scope.getError(response, stateless_l10n.sync_single_file_request_failed);
+ $scope.isRunning = false;
- /**
- * Process single file
- * @param id
- */
- $scope.syncSingleFile = function( id, use_wildcards, chunk_id ) {
-
- $http({
- method: 'GET',
- url: ajaxurl,
- params: {
- action: "stateless_process_file",
- id: id,
- use_wildcards: use_wildcards
- }
- }).then(
- function(response) {
- var data = response.data || {};
- $scope.log.push({message: $scope.getError(response, stateless_l10n.sync_single_file_failed)});
+ if(WP_DEBUG){
+ console.log("WP-Stateless sync single file: Request failed", response, typeof response.headers === 'function'?response.headers(): "");
+ }
+ }
+ );
- jQuery("#regenthumbs-bar").progressbar( "value", ( ++$scope.objectsCounter / $scope.objectsTotal ) * 100 );
- jQuery("#regenthumbs-bar-percent").html( Math.round( ( $scope.objectsCounter / $scope.objectsTotal ) * 1000 ) / 10 + "%" );
+ }
- if(typeof response.data.success == 'undefined' || response.data.success == false){
- $scope.error = true;
- $scope.status = $scope.getError(response, stateless_l10n.sync_single_file_failed);
- // $scope.isRunning = false;
+ /**
+ * Process single file
+ * @param id
+ */
+ $scope.syncSingleNonLibraryFile = function( id, chunk_id ) {
+
+ $http({
+ method: 'GET',
+ url: ajaxurl,
+ params: {
+ action: "stateless_process_non_library_file",
+ file_path: id
}
+ }).then(
+ function(response) {
+ var data = response.data || {};
+ $scope.log.push({message: $scope.getError(response, stateless_l10n.failed_to_sync + id)});
- if ( 'undefined' !== typeof chunk_id ) {
- if ( $scope.chunkIDs[ chunk_id ].length && $scope.continue ) {
- $scope.syncSingleFile( $scope.chunkIDs[ chunk_id ].shift(), use_wildcards, chunk_id );
- } else {
- $scope.finishProcess( chunk_id );
+ jQuery("#regenthumbs-bar").progressbar( "value", ( ++$scope.objectsCounter / $scope.objectsTotal ) * 100 );
+ jQuery("#regenthumbs-bar-percent").html( Math.round( ( $scope.objectsCounter / $scope.objectsTotal ) * 1000 ) / 10 + "%" );
+
+ if(typeof response.data.success == 'undefined' || response.data.success == false){
+ $scope.error = true;
+ $scope.status = $scope.getError(response, stateless_l10n.sync_non_library_file_failed);
+ // $scope.isRunning = false;
}
- } else {
- if ( $scope.objectIDs.length && $scope.continue ) {
- $scope.syncSingleFile( $scope.objectIDs.shift(), use_wildcards );
+
+ if ( 'undefined' !== typeof chunk_id ) {
+ if ( $scope.chunkIDs[ chunk_id ].length && $scope.continue ) {
+ $scope.syncSingleNonLibraryFile( $scope.chunkIDs[ chunk_id ].shift(), chunk_id );
+ } else {
+ $scope.finishProcess( chunk_id );
+ }
} else {
- $scope.finishProcess();
+ if ( $scope.objectIDs.length && $scope.continue ) {
+ $scope.syncSingleNonLibraryFile( $scope.objectIDs.shift() );
+ } else {
+ $scope.finishProcess();
+ }
}
- }
- if(WP_DEBUG){
- console.log("WP-Stateless sync single file:", response, typeof response.headers === 'function'?response.headers(): "");
- }
- },
- function(response) {
- $scope.error = true;
- $scope.status = $scope.getError(response, stateless_l10n.sync_single_file_request_failed);
- $scope.isRunning = false;
+ if(WP_DEBUG){
+ console.log("WP-Stateless sync non library file:", response, typeof response.headers === 'function'?response.headers(): "");
+ }
+ },
+ function(response) {
+ $scope.error = true;
+ $scope.status = $scope.getError(response, stateless_l10n.sync_non_library_file_request_failed);
+ $scope.isRunning = false;
- if(WP_DEBUG){
- console.log("WP-Stateless sync single file: Request failed", response, typeof response.headers === 'function'?response.headers(): "");
+ if(WP_DEBUG){
+ console.log("WP-Stateless sync non library file: Request failed", response, typeof response.headers === 'function'?response.headers():{});
+ }
}
- }
- );
+ );
- }
+ }
- /**
- * Process single file
- * @param id
- */
- $scope.syncSingleNonLibraryFile = function( id, chunk_id ) {
-
- $http({
- method: 'GET',
- url: ajaxurl,
- params: {
- action: "stateless_process_non_library_file",
- file_path: id
- }
- }).then(
- function(response) {
- var data = response.data || {};
- $scope.log.push({message: $scope.getError(response, stateless_l10n.failed_to_sync + id)});
+ }])
+ .controller('wpStatelessSettings', function($scope, $filter) {
+ $scope.backup = {};
+ $scope.sm = wp_stateless_settings || {};
+ $scope.sm.readonly = $scope.sm.readonly || {}
- jQuery("#regenthumbs-bar").progressbar( "value", ( ++$scope.objectsCounter / $scope.objectsTotal ) * 100 );
- jQuery("#regenthumbs-bar-percent").html( Math.round( ( $scope.objectsCounter / $scope.objectsTotal ) * 1000 ) / 10 + "%" );
+ if ($scope.sm.network_admin) {
+ $scope.sm.hashify_file_name = 'true';
+ $scope.sm.readonly.hashify_file_name = true;
+ }
- if(typeof response.data.success == 'undefined' || response.data.success == false){
- $scope.error = true;
- $scope.status = $scope.getError(response, stateless_l10n.sync_non_library_file_failed);
- // $scope.isRunning = false;
+ $scope.$watch('sm.mode', function(value) {
+ if( (value == 'stateless' || value == 'ephemeral') && $scope.sm.readonly.hashify_file_name != 'constant'){
+ $scope.backup.hashify_file_name = $scope.sm.hashify_file_name;
+ $scope.sm.hashify_file_name = 'true';
+ // $scope.apply();
+ }
+ else{
+ if($scope.backup.hashify_file_name){
+ $scope.sm.hashify_file_name = $scope.backup.hashify_file_name;
+ // $scope.apply();
}
+ }
- if ( 'undefined' !== typeof chunk_id ) {
- if ( $scope.chunkIDs[ chunk_id ].length && $scope.continue ) {
- $scope.syncSingleNonLibraryFile( $scope.chunkIDs[ chunk_id ].shift(), chunk_id );
- } else {
- $scope.finishProcess( chunk_id );
- }
+ /**
+ * For Stateless mode folder is required
+ */
+ if ( $scope.sm.mode == 'stateless' && $scope.sm.root_dir == '' && !$scope.sm.network_admin ) {
+ if ( $scope.sm.is_multisite ) {
+ $scope.sm.root_dir = '/sites/%site_id%/%date_year%/%date_month%/';
+ $scope.sm.bucket_folder_type = 'multi-site';
} else {
- if ( $scope.objectIDs.length && $scope.continue ) {
- $scope.syncSingleNonLibraryFile( $scope.objectIDs.shift() );
- } else {
- $scope.finishProcess();
- }
- }
-
- if(WP_DEBUG){
- console.log("WP-Stateless sync non library file:", response, typeof response.headers === 'function'?response.headers(): "");
+ $scope.sm.root_dir = '/%date_year%/%date_month%/';
+ $scope.sm.bucket_folder_type = 'single-site';
}
- },
- function(response) {
- $scope.error = true;
- $scope.status = $scope.getError(response, stateless_l10n.sync_non_library_file_request_failed);
- $scope.isRunning = false;
+ }
+ });
- if(WP_DEBUG){
- console.log("WP-Stateless sync non library file: Request failed", response, typeof response.headers === 'function'?response.headers():{});
- }
+ $scope.$watch('sm.bucket_folder_type', function(value) {
+ if(value == 'single-site'){
+ $scope.sm.root_dir = '/%date_year%/%date_month%/';
}
- );
+ else if(value == 'multi-site'){
+ $scope.sm.root_dir = '/sites/%site_id%/%date_year%/%date_month%/';
+ }
+ else if(value == '' && $scope.sm.network_admin){
+ $scope.sm.root_dir = '';
+ }
+ setTimeout(function(){
+ jQuery( '#permalink_structure' ).trigger('change');
+ }, 1);
+ });
- }
+ $scope.$watch('sm.root_dir', function(value) {
-}])
-.controller('wpStatelessSettings', function($scope, $filter) {
- $scope.backup = {};
- $scope.sm = wp_stateless_settings || {};
- $scope.sm.readonly = $scope.sm.readonly || {}
+ if(value == '/%date_year%/%date_month%/'){
+ $scope.sm.bucket_folder_type = 'single-site';
+ }
+ else if(value == '/sites/%site_id%/%date_year%/%date_month%/'){
+ $scope.sm.bucket_folder_type = 'multi-site';
+ }
+ else if(value == '' && $scope.sm.network_admin){
+ $scope.sm.bucket_folder_type = '';
+ }
+ else{
+ $scope.sm.bucket_folder_type = 'custom';
+ }
- if ($scope.sm.network_admin) {
- $scope.sm.hashify_file_name = 'true';
- $scope.sm.readonly.hashify_file_name = true;
- }
+ /**
+ * For Stateless mode folder is required
+ */
+ if ( $scope.sm.mode == 'stateless' && value == '' && !$scope.sm.network_admin ) {
+ if ( $scope.sm.is_multisite ) {
+ value = '/sites/%site_id%/%date_year%/%date_month%/';
+ $scope.sm.bucket_folder_type = 'multi-site';
+ } else {
+ value = '/%date_year%/%date_month%/';
+ $scope.sm.bucket_folder_type = 'single-site';
+ }
+ }
- $scope.$watch('sm.mode', function(value) {
- if(value == 'stateless' && $scope.sm.readonly.hashify_file_name != 'constant'){
- $scope.backup.hashify_file_name = $scope.sm.hashify_file_name;
- $scope.sm.hashify_file_name = 'true';
- // $scope.apply();
- }
- else{
- if($scope.backup.hashify_file_name){
- $scope.sm.hashify_file_name = $scope.backup.hashify_file_name;
- // $scope.apply();
+ let tags = [ "%date_year%", "%date_month%", "%site_id%", "%site_url%", "%site_url_host%", "%site_url_path%" ];
+ value_splitted = value.split("/");
+ for ( i = 0; i < value_splitted.length; i ++ ) {
+ if (! /^[a-zA-Z0-9_.]+$/.test(value_splitted[i]) && value_splitted[i] != '' && jQuery.inArray (value_splitted[i], tags) == -1) {
+ value_splitted[i] = value_splitted[i].replace(/[^a-zA-Z0-9_.]/g,'');
+ }
}
- }
- });
+ $scope.sm.root_dir = value_splitted.join('/');
+ setTimeout(function(){
+ jQuery( '#permalink_structure' ).trigger('change');
+ }, 1);
+ });
- $scope.$watch('sm.bucket_folder_type', function(value) {
- if(value == 'single-site'){
- $scope.sm.root_dir = '/%date_year%/%date_month%/';
- }
- else if(value == 'multi-site'){
- $scope.sm.root_dir = '/sites/%site_id%/%date_year%/%date_month%/';
+ var readonlyTag = $scope.sm.readonly.root_dir || false;
+ if(readonlyTag){
+ jQuery('.available-structure-tags .button').off('click').css('opacity', '.5');
}
- else if(value == '' && $scope.sm.network_admin){
- $scope.sm.root_dir = '';
+ $scope.tagClicked = function(){
+ if(readonlyTag) return false;
+ $scope.sm.bucket_folder_type = 'custom';
+ setTimeout(function(){
+ jQuery( '#permalink_structure' ).trigger('change');
+ }, 1);
}
- setTimeout(function(){
- jQuery( '#permalink_structure' ).trigger('change');
- }, 1);
- });
- $scope.$watch('sm.root_dir', function(value) {
- if(value == '/%date_year%/%date_month%/'){
- $scope.sm.bucket_folder_type = 'single-site';
- }
- else if(value == '/sites/%site_id%/%date_year%/%date_month%/'){
- $scope.sm.bucket_folder_type = 'multi-site';
- }
- else if(value == '' && $scope.sm.network_admin){
- $scope.sm.bucket_folder_type = '';
- }
- else{
- $scope.sm.bucket_folder_type = 'custom';
+ $scope.sm.showNotice = function(option){
+ if($scope.sm.readonly && $scope.sm.readonly[option]){
+ var slug = $scope.sm.readonly[option];
+ return $scope.sm.strings[slug];
+ }
}
- let tags = [ "%date_year%", "%date_month%", "%site_id%", "%site_url%", "%site_url_host%", "%site_url_path%" ];
- value_splitted = value.split("/");
- for ( i = 0; i < value_splitted.length; i ++ ) {
+
+ $scope.sm.generatePreviewUrl = function() {
+ $scope.sm.is_custom_domain = false;
+ var host = 'https://storage.googleapis.com/';
+ var hash = $scope.sm.hashify_file_name == 'true' ? Date.now().toString(36) + '-' : '';
+ var is_ssl = $scope.sm.custom_domain.indexOf('https://');
+ var custom_domain = $scope.sm.custom_domain.toString();
+ var root_dir = $scope.sm.root_dir ? $scope.sm.root_dir : '';
+
+ jQuery.each($scope.sm.wildcards, function(index, item){
+ var reg = new RegExp(index, 'g');
+ root_dir = root_dir.replace(reg, item[0]);
+ });
+ let tags = [ "%date_year%", "%date_month%", "%site_id%", "%site_url%", "%site_url_host%", "%site_url_path%" ];
+ let value_splitted = root_dir.split("/");
+ for ( let i = 0; i < value_splitted.length; i ++ ) {
if (! /^[a-zA-Z0-9_.]+$/.test(value_splitted[i]) && value_splitted[i] != '' && jQuery.inArray (value_splitted[i], tags) == -1) {
- value_splitted[i] = value_splitted[i].replace(/[^a-zA-Z0-9_.]/g,'');
+ value_splitted[i] = value_splitted[i].replace(/[^a-zA-Z0-9_.]/g,'');
}
- }
- $scope.sm.root_dir = value_splitted.join('/');
- setTimeout(function(){
- jQuery( '#permalink_structure' ).trigger('change');
- }, 1);
- });
-
- var readonlyTag = $scope.sm.readonly.root_dir || false;
- if(readonlyTag){
- jQuery('.available-structure-tags .button').off('click').css('opacity', '.5');
- }
- $scope.tagClicked = function(){
- if(readonlyTag) return false;
- $scope.sm.bucket_folder_type = 'custom';
- setTimeout(function(){
- jQuery( '#permalink_structure' ).trigger('change');
- }, 1);
- }
+ }
+ root_dir = value_splitted.join('/');
+ root_dir = root_dir.replace(/(\/+)/g, '/');
+ root_dir = root_dir.replace(/^\//, '');
+ root_dir = root_dir.replace(/\/$/, '');
+ if(root_dir){
+ root_dir = root_dir + "/";
+ }
- $scope.sm.showNotice = function(option){
- if($scope.sm.readonly && $scope.sm.readonly[option]){
- var slug = $scope.sm.readonly[option];
- return $scope.sm.strings[slug];
- }
- }
+ custom_domain = custom_domain.replace(/\/+$/, ''); // removing trailing slashes
+ custom_domain = custom_domain.replace(/https?:\/\//, ''); // removing http:// or https:// from the beginning.
+ host += $scope.sm.bucket ? $scope.sm.bucket : '{bucket-name}';
- $scope.sm.generatePreviewUrl = function() {
- $scope.sm.is_custom_domain = false;
- var host = 'https://storage.googleapis.com/';
- var hash = $scope.sm.hashify_file_name == 'true' ? Date.now().toString(36) + '-' : '';
- var is_ssl = $scope.sm.custom_domain.indexOf('https://');
- var custom_domain = $scope.sm.custom_domain.toString();
- var root_dir = $scope.sm.root_dir ? $scope.sm.root_dir : '';
-
- jQuery.each($scope.sm.wildcards, function(index, item){
- var reg = new RegExp(index, 'g');
- root_dir = root_dir.replace(reg, item[0]);
- });
- let tags = [ "%date_year%", "%date_month%", "%site_id%", "%site_url%", "%site_url_host%", "%site_url_path%" ];
- let value_splitted = root_dir.split("/");
- for ( let i = 0; i < value_splitted.length; i ++ ) {
- if (! /^[a-zA-Z0-9_.]+$/.test(value_splitted[i]) && value_splitted[i] != '' && jQuery.inArray (value_splitted[i], tags) == -1) {
- value_splitted[i] = value_splitted[i].replace(/[^a-zA-Z0-9_.]/g,'');
+ if ( custom_domain !== 'storage.googleapis.com' && $scope.sm.bucket && custom_domain && ( is_ssl === 0 || custom_domain == $scope.sm.bucket ) ) {
+ $scope.sm.is_custom_domain = true;
+ $scope.sm.is_ssl = is_ssl === 0 ? true : false;
+ host = is_ssl === 0 ? 'https://' : 'http://'; // bucketname will be host
+ host += custom_domain;
}
- }
- root_dir = value_splitted.join('/');
- root_dir = root_dir.replace(/(\/+)/g, '/');
- root_dir = root_dir.replace(/^\//, '');
- root_dir = root_dir.replace(/\/$/, '');
- if(root_dir){
- root_dir = root_dir + "/";
- }
-
- custom_domain = custom_domain.replace(/\/+$/, ''); // removing trailing slashes
- custom_domain = custom_domain.replace(/https?:\/\//, ''); // removing http:// or https:// from the beginning.
- host += $scope.sm.bucket ? $scope.sm.bucket : '{bucket-name}';
- if ( custom_domain !== 'storage.googleapis.com' && $scope.sm.bucket && custom_domain && ( is_ssl === 0 || custom_domain == $scope.sm.bucket ) ) {
- $scope.sm.is_custom_domain = true;
- $scope.sm.is_ssl = is_ssl === 0 ? true : false;
- host = is_ssl === 0 ? 'https://' : 'http://'; // bucketname will be host
- host += custom_domain;
+ $scope.sm.preview_url = host + "/" + root_dir + hash + "your-image-name.jpeg";
}
- $scope.sm.preview_url = host + "/" + root_dir + hash + "your-image-name.jpeg";
- }
+ $scope.sm.generatePreviewUrl();
- $scope.sm.generatePreviewUrl();
-
-})
-.controller('wpStatelessCompatibility', function($scope, $filter) {
- $scope.modules = wp_stateless_compatibility || {};
-})
-.controller('noJSWarning', function($scope, $filter) {
- $scope.jsLoaded = true;
-});
+ })
+ .controller('wpStatelessCompatibility', function($scope, $filter) {
+ $scope.modules = wp_stateless_compatibility || {};
+ })
+ .controller('noJSWarning', function($scope, $filter) {
+ $scope.jsLoaded = true;
+ });
wpStatelessApp.filter("trust", ['$sce', function($sce) {
return function(htmlCode){