first commit
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
use Duplicator\Libs\WpUtils\WpDbUtils;
|
||||
|
||||
?>
|
||||
<script>
|
||||
/*! ============================================================================
|
||||
* UI NAMESPACE: All methods at the top of the Duplicator Namespace
|
||||
* =========================================================================== */
|
||||
(function($) {
|
||||
/**
|
||||
* Indicates if we have any form changes.
|
||||
* Primarily used to prevent the user from navigating away from a page with unsaved changes.
|
||||
* @type {boolean}
|
||||
*/
|
||||
DupliJs.UI.hasUnsavedChanges = false;
|
||||
|
||||
/* Stores the state of a view into the database */
|
||||
DupliJs.UI.SaveViewStateByPost = function(key, value) {
|
||||
if (key != undefined && value != undefined) {
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: "json",
|
||||
data: {
|
||||
action: 'duplicator_view_state_update',
|
||||
key: key,
|
||||
value: value,
|
||||
nonce: '<?php echo esc_js(wp_create_nonce('duplicator_view_state_update')); ?>'
|
||||
},
|
||||
success: function(data) {},
|
||||
error: function(data) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
DupliJs.UI.SaveMulViewStatesByPost = function(states) {
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: "json",
|
||||
data: {
|
||||
action: 'duplicator_view_state_update',
|
||||
states: states,
|
||||
nonce: '<?php echo esc_js(wp_create_nonce('duplicator_view_state_update')); ?>'
|
||||
},
|
||||
success: function(data) {},
|
||||
error: function(data) {}
|
||||
});
|
||||
}
|
||||
|
||||
DupliJs.UI.SetScanMode = function() {
|
||||
var scanMode = jQuery('#scan-mode').val();
|
||||
|
||||
if (scanMode == <?php echo (int) WpDbUtils::PHPDUMP_MODE_MULTI; ?>) {
|
||||
jQuery('#scan-multithread-size').show();
|
||||
jQuery('#scan-chunk-size-label').show();
|
||||
} else {
|
||||
jQuery('#scan-multithread-size').hide();
|
||||
jQuery('#scan-chunk-size-label').hide();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DupliJs.UI.IsSaveViewState = true;
|
||||
/* Toggle MetaBoxes */
|
||||
DupliJs.UI.ToggleMetaBox = function() {
|
||||
var $title = jQuery(this);
|
||||
var $panel = $title.parent().find('.dup-box-panel');
|
||||
var $arrowParent = $title.parent().find('.dup-box-arrow');
|
||||
var $arrow = $title.parent().find('.dup-box-arrow i');
|
||||
var key = $panel.attr('id');
|
||||
var value = $panel.is(":visible") ? 0 : 1;
|
||||
|
||||
if (DupliJs.UI.IsSaveViewState) {
|
||||
DupliJs.UI.SaveViewStateByPost(key, value);
|
||||
}
|
||||
|
||||
if (value) {
|
||||
$panel.removeClass('no-display');
|
||||
$panel.show();
|
||||
$arrowParent.attr("aria-expanded", true);
|
||||
$arrow.removeClass().addClass('fa fa-caret-up');
|
||||
} else {
|
||||
$panel.hide();
|
||||
$arrowParent.attr("aria-expanded", false);
|
||||
$arrow.removeClass().addClass('fa fa-caret-down');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
DupliJs.UI.ClearTraceLog = function(reload) {
|
||||
var reload = reload || 0;
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: 'duplicator_delete_trace_log',
|
||||
nonce: '<?php echo esc_js(wp_create_nonce('duplicator_delete_trace_log')); ?>'
|
||||
},
|
||||
success: function(respData) {
|
||||
if (reload && respData.success) {
|
||||
window.location.reload();
|
||||
}
|
||||
},
|
||||
error: function(data) {}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Clock generator, used to show an active clock.
|
||||
* Intended use is to be called once per page load
|
||||
* such as:
|
||||
* <div id="dupli-clock-container"></div>
|
||||
* DupliJs.UI.Clock(DupliJs._WordPressInitTime); */
|
||||
DupliJs.UI.Clock = function() {
|
||||
var timeDiff;
|
||||
var timeout;
|
||||
|
||||
function addZ(n) {
|
||||
return (n < 10 ? '0' : '') + n;
|
||||
}
|
||||
|
||||
function formatTime(d) {
|
||||
return addZ(d.getHours()) + ':' + addZ(d.getMinutes()) + ':' + addZ(d.getSeconds());
|
||||
}
|
||||
|
||||
return function(s) {
|
||||
|
||||
var now = new Date();
|
||||
var then;
|
||||
// Set lag to just after next full second
|
||||
var lag = 1015 - now.getMilliseconds();
|
||||
|
||||
// Get the time difference when first run
|
||||
if (s) {
|
||||
s = s.split(':');
|
||||
then = new Date(now);
|
||||
then.setHours(+s[0], +s[1], +s[2], 0);
|
||||
timeDiff = now - then;
|
||||
}
|
||||
|
||||
now = new Date(now - timeDiff);
|
||||
jQuery('#dupli-clock-container').html(formatTime(now));
|
||||
timeout = setTimeout(DupliJs.UI.Clock, lag);
|
||||
};
|
||||
}();
|
||||
|
||||
/* Runs callback function when form values change */
|
||||
DupliJs.UI.formOnChangeValues = function(form, callback) {
|
||||
let previousValues = form.serialize();
|
||||
|
||||
$('form :input').on('change input', function() {
|
||||
if (previousValues !== form.serialize()) {
|
||||
previousValues = form.serialize();
|
||||
callback();
|
||||
}
|
||||
});
|
||||
|
||||
$('.dup-pseudo-checkbox, #dbnone, #dball').on('click', function() {
|
||||
// Since the pseudo checkbox is not a form input,
|
||||
// assume the state is changed on click
|
||||
callback();
|
||||
});
|
||||
};
|
||||
})(jQuery);
|
||||
</script>
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/*! ============================================================================
|
||||
* UTIL NAMESPACE: All methods at the top of the Duplicator Namespace
|
||||
* =========================================================================== */
|
||||
defined("ABSPATH") or die("");
|
||||
?>
|
||||
|
||||
<script>
|
||||
DupliJs.Util.ajaxProgress = null;
|
||||
|
||||
DupliJs.Util.ajaxProgressShow = function() {
|
||||
if (DupliJs.Util.ajaxProgress === null) {
|
||||
DupliJs.Util.ajaxProgress = jQuery('#dup-ajax-loader')
|
||||
}
|
||||
DupliJs.Util.ajaxProgress
|
||||
.stop(true, true)
|
||||
.css('display', 'block')
|
||||
.delay(1000)
|
||||
.animate({
|
||||
opacity: 1
|
||||
}, 500);
|
||||
}
|
||||
|
||||
DupliJs.Util.ajaxProgressHide = function() {
|
||||
if (DupliJs.Util.ajaxProgress === null) {
|
||||
return;
|
||||
}
|
||||
DupliJs.Util.ajaxProgress
|
||||
.stop(true, true)
|
||||
.delay(500)
|
||||
.animate({
|
||||
opacity: 0
|
||||
}, 300, function() {
|
||||
jQuery(this).css({
|
||||
'display': 'none'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
DupliJs.Util.ajaxWrapper = function(ajaxData, callbackSuccess, callbackFail, options = {}) {
|
||||
let opts = jQuery.extend({
|
||||
showProgress: true, // Is true show the ajax loader, can be disabled for custom progress handling
|
||||
timeout: 30000
|
||||
}, options);
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
timeout: opts.timeout,
|
||||
dataType: "json",
|
||||
data: ajaxData,
|
||||
beforeSend: function(xhr) {
|
||||
if (opts.showProgress) {
|
||||
DupliJs.Util.ajaxProgressShow();
|
||||
}
|
||||
},
|
||||
success: function(result, textStatus, jqXHR) {
|
||||
var message = '';
|
||||
if (result.success) {
|
||||
if (typeof callbackSuccess === "function") {
|
||||
try {
|
||||
message = callbackSuccess(result, result.data, result.data.funcData, textStatus, jqXHR);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
DupliJs.addAdminMessage(error.message, 'error');
|
||||
message = '';
|
||||
}
|
||||
} else {
|
||||
message = '<?php echo esc_js(__('RESPONSE SUCCESS', 'duplicator-pro')); ?>';
|
||||
}
|
||||
if (message != null && String(message).length) {
|
||||
DupliJs.addAdminMessage(message, 'notice');
|
||||
}
|
||||
} else {
|
||||
if (typeof callbackFail === "function") {
|
||||
try {
|
||||
message = callbackFail(result, result.data, result.data.funcData, textStatus, jqXHR);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message = error.message;
|
||||
}
|
||||
} else {
|
||||
message = '<?php echo esc_js(__('RESPONSE ERROR!', 'duplicator-pro')); ?>' + '<br><br>' + result.data.message;
|
||||
}
|
||||
if (message != null && String(message).length) {
|
||||
DupliJs.addAdminMessage(message, 'error');
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(result) {
|
||||
// Make sure the progress is hidden even if the request fails
|
||||
DupliJs.Util.ajaxProgressHide();
|
||||
DupliJs.addAdminMessage(
|
||||
<?php echo wp_json_encode(__('AJAX ERROR! <br> Ajax request error', 'duplicator-pro')); ?>,
|
||||
'error'
|
||||
);
|
||||
},
|
||||
complete: function() {
|
||||
if (opts.showProgress) {
|
||||
DupliJs.Util.ajaxProgressHide();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get human size from bytes number.
|
||||
* Is size is -1 return unknown
|
||||
*
|
||||
* @param {size} int bytes size
|
||||
*/
|
||||
DupliJs.Util.humanFileSize = function(size) {
|
||||
if (size < 0) {
|
||||
return "unknown";
|
||||
} else if (size == 0) {
|
||||
return "0";
|
||||
} else {
|
||||
var i = Math.floor(Math.log(size) / Math.log(1024));
|
||||
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
||||
}
|
||||
};
|
||||
|
||||
DupliJs.Util.isEmpty = function(val) {
|
||||
return (val === undefined || val == null || val.length <= 0) ? true : false;
|
||||
};
|
||||
|
||||
DupliJs.Util.toggleShow = function(selector, show = 'auto') {
|
||||
var element = jQuery(selector);
|
||||
if (show === 'auto') {
|
||||
show = !element.is(":visible");
|
||||
}
|
||||
|
||||
if (show) {
|
||||
element.hide().removeClass('no-display');
|
||||
element.fadeIn();
|
||||
} else {
|
||||
element.fadeOut();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
DupliJs.Util.dynamicFormSubmit = function(url, method, params) {
|
||||
var form = jQuery('<form>', {
|
||||
method: method,
|
||||
action: url
|
||||
});
|
||||
|
||||
jQuery.each(params, function(key, value) {
|
||||
form.append(jQuery('<input>', {
|
||||
'type': 'hidden',
|
||||
'name': key,
|
||||
'value': value
|
||||
}));
|
||||
});
|
||||
|
||||
jQuery("body").append(form);
|
||||
form.submit();
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user