", {
id: "change-history-according-wrapper",
html: content
});
let name_title = '';
if ((data?.name || data?.slug) && response?.name_title) {
name_title = response.name_title;
}
if (name_title != '') {
jQuery(md).find('.ui.header .main-text').text(name_title + ' ' + MainWP.I18n.t('History'));
}
if (load_more) {
jQuery(md).find('.scrolling.content').append(accordWrapper);
} else {
jQuery(md).find('.scrolling.content').html(accordWrapper);
}
jQuery('#change-history-according-wrapper .ui.accordion').accordion({ exclusive: true });
jQuery('.mainwp-day-history-switch-view').off('click.accordionFix').on('click.accordionFix', function (e) {
e.preventDefault();
e.stopPropagation(); // now it runs before ancestor handlers
dayHistory_SwitchViewHandler(this);
return false;
});
}
if (response?.onward_date) {
jQuery(md).find('.actions .col-left').html('Data available from ' + response.onward_date + ' onward.');
}
if (response?.more_date) {
jQuery(md).find('.actions .col-right').html('
');
}
}
} else if (parentContent) {
let err_content = '
' + MainWP.I18n.t('Undefined error occurred. Please try again.') + '
';
jQuery(parentContent).html(err_content);
}
}, 'json');
}
let get_icon_history_event = function (act) {
let icon = '';
if (act === 'delete' || act === 'deleted') {
icon = 'trash red';
} else if (act === 'deactivated' || act === 'deactivate') {
icon = 'toggle off red';
} else if (act === 'activated' || act === 'activate') {
icon = 'toggle on green';
} else if (act === 'updated' || act === 'update') {
icon = 'sync orange';
} else if (act === 'installed' || act === 'install') {
icon = 'download teal';
} else {
icon = 'circle grey';
}
return icon;
}
let get_color_changes_event = function (act) {
const actColorMap = {
red: ['deleted', 'removed', 'revoked', 'delete', 'deactivated', 'disabled', 'suspended', 'deactivate'],
orange: ['updated', 'modified', 'update'],
grey: ['opened'],
blue: ['logged-in', 'logged-out'],
teal: ['sync', 'installed', 'install', 'uploaded'],
green: ['activated', 'activate', 'created', 'published', 'enabled', 'added']
};
let color = '';
for (const [c, acts] of Object.entries(actColorMap)) {
if (acts.includes(act)) {
color = c;
break;
}
}
return color;
}
let dayHistory_SwitchViewHandler = function (btn) {
const parent = jQuery(btn).closest('.ui.accordion');
const his_date = jQuery(btn).closest('.title').attr('format-date');
jQuery(btn).closest('.title').hasClass('active') || jQuery(btn).closest('.title').trigger('click');
jQuery(parent).find('.content.ui').html('
');
const dt = jQuery(parent).data('date');
let md = jQuery('#mainwp-plugin-theme-history-changes-modal');
const type = jQuery(md).attr('history-type');
let siteId = ('plugin' === type ? pluginChangesLoadData.siteId : themeChangesLoadData.siteId) || 0;
let data = mainwp_secure_data({
action: 'mainwp_changes_logs_get_item_changes',
type: type,
target_date: dt,
siteId: siteId
});
jQuery.post(ajaxurl, data, function (response) { // NOSONAR - complex.
jQuery(parent).find('.history-actions-loading').remove();
let dayContent = jQuery(parent).find('.content');
if (response.error != undefined) {
dayContent.append('
');
} else if (response?.list) {
if (response.list.length == 0) {
let msg = MainWP.I18n.t('This plugin has no recorded activity in Dashboard Insights.');
if ('theme' === type && '' === dt) {
msg = MainWP.I18n.t('This theme has no recorded activity in Dashboard Insights.');
} else if ('' !== dt) {
if ('plugin' === type) {
msg = MainWP.I18n.t('No history changes found for the plugin on this day.');
} else {
msg = MainWP.I18n.t('No history changes found for the theme on this day.');
}
}
dayContent.append('
');
} else {
let content = '';
let count_acts = 0;
Object.entries(response.list).forEach(([idxslug, records]) => {
const name = records[0].name;
content += `
`;
});
if ('' !== content) {
jQuery(md).find('.ui.header .main-text').text(his_date + ' ' + MainWP.I18n.t('History'));
let accordWrapper = jQuery("
", {
id: "change-history-according-wrapper",
html: content
});
jQuery(md).find('.scrolling.content').html(accordWrapper);
jQuery('#change-history-according-wrapper .ui.accordion').accordion({ exclusive: true });
jQuery('.mainwp-list-history-switch-view').off('click.accordionFix2').on('click.accordionFix2', function (e) {
e.preventDefault();
e.stopPropagation(); // now it runs before ancestor handlers
listHistory_SwitchViewHandler(this);
return false;
});
}
}
} else {
dayContent.html('
' + MainWP.I18n.t('Undefined error occurred. Please try again.') + '
');
}
}, 'json');
return false;
}
let listHistory_SwitchViewHandler = function (btn) {
const parent = jQuery(btn).closest('.ui.accordion');
jQuery(btn).closest('.title').hasClass('active') || jQuery(btn).closest('.title').trigger('click');
jQuery(parent).find('.content.ui').html('
');
let md = jQuery('#mainwp-plugin-theme-history-changes-modal');
const type = jQuery(md).attr('history-type');
if ('theme' === type) {
themeChangesLoadData.slug = jQuery(parent).data('slug');
themeChangesLoadData.name = jQuery(parent).data('name');
themeChangesLoadData.siteId = jQuery(parent).data('siteid');
themeChangesLoadData.from_date = '';
} else {
pluginChangesLoadData.slug = jQuery(parent).data('slug');;
pluginChangesLoadData.siteId = jQuery(parent).data('siteid');;
pluginChangesLoadData.from_date = '';
}
mainwp_item_changes_load(btn);
}
/**
* Install check plugins.
*
*/
globalThis.mainwp_install_check_plugin_prepare = function (slug) {
let selected = jQuery("input[name='install_checker[]']:checked");
if (selected.length == 0) {
feedback('mainwp-message-zone-install', MainWP.I18n.t('Please select website to install plugin.'), 'yellow');
return;
} else {
selected.each(function () {
jQuery(this).closest('.siteBulkInstall').attr('status', 'queue');
});
}
jQuery('#mainwp-install-check-btn').addClass('disabled');
mainwp_set_message_zone('#mainwp-message-zone-install', '
', false, true); // false: not change the color class.
let data = mainwp_secure_data({
action: 'mainwp_preparebulkinstallcheckplugin',
slug: slug,
});
jQuery.post(ajaxurl, data, function (response) {
mainwp_set_message_zone('#mainwp-message-zone-install');
mainwp_install_check_plugin_start_next(response.url);
}, 'json');
};
let mainwp_install_check_plugin_start_next = function (url) {
while ((siteToInstall = jQuery('.siteBulkInstall[status="queue"]:first')) && (siteToInstall.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { // NOSONAR - modified outside the function.
mainwp_install_check_plugin_start_specific(url, siteToInstall);
}
};
let mainwp_install_check_plugin_start_specific = function (url, siteToInstall) {
bulkInstallCurrentThreads++;
siteToInstall.attr('status', 'progress');
siteToInstall.find('.queue').hide();
siteToInstall.find('.progress').show();
let data = mainwp_secure_data({
action: 'mainwp_installbulkinstallplugintheme',
type: 'plugin',
url: url,
activatePlugin: 'true',
siteId: siteToInstall.attr('siteid')
});
jQuery.post(ajaxurl, data, function (url, siteToInstall) {
return function (response) {
siteToInstall.attr('status', 'done');
siteToInstall.find('.progress').hide();
let statusEl = siteToInstall.find('.status');
statusEl.show();
if (response.error != undefined) {
statusEl.html(response.error);
statusEl.css('color', 'red');
} else if (response?.ok[siteToInstall.attr('siteid')]) {
statusEl.html('
');
} else if (response?.errors[siteToInstall.attr('siteid')]) {
statusEl.html('
');
} else {
statusEl.html('
');
}
bulkInstallCurrentThreads--;
bulkInstallDone++;
jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').progress('set progress', bulkInstallDone);
jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').find('.label').html(bulkInstallDone + '/' + mainwpVars.bulkInstallTotal + ' ' + MainWP.I18n.t('Installed'));
mainwp_install_check_plugin_start_next(url);
}
}(url, siteToInstall), 'json');
};
function isUrl(url) {
try {
new URL(url);
return true;
} catch (e) {
console.log(e);
}
return false;
}
function removeUrlParams(url, params) {
try {
const urlObj = new URL(url);
jQuery(params).each(function (idx, param) {
urlObj.searchParams.delete(param);
});
return urlObj.toString();
} catch (e) {
console.log(e);
}
return '';
}
function setVisible(what, vis) {
if (vis) {
jQuery(what).show();
} else {
jQuery(what).hide();
}
}
const mainwp_scrollToElement = () => {
jQuery('html,body').animate({
scrollTop: 0
}, 1000);
return false;
}
function setHtml(what, text, ptag) {
if (ptag === undefined)
ptag = true;
setVisible(what, true);
if (ptag)
jQuery(what).html('
' + text + '');
else
jQuery(what).html(text);
mainwp_scrollToElement(); // to fix js conflict error from some other add-ons.
}
/**
* Notes
*/
jQuery(function () {
jQuery(document).on('click', '#mainwp-notes-cancel', function () {
jQuery('#mainwp-notes-status').html('');
jQuery('#mainwp-notes-status').removeClass('red green');
mainwp_notes_hide();
return false;
});
jQuery(document).on('click', '#mainwp-notes-save', function () {
let which = jQuery('#mainwp-which-note').val();
if (which == 'site') {
mainwp_notes_site_save();
} else if (which == 'theme') {
mainwp_notes_theme_save();
} else if (which == 'plugin') {
mainwp_notes_plugin_save();
} else if (which == 'client') {
mainwp_notes_client_save();
}
return false;
});
jQuery(document).on('click', '.mainwp-edit-site-note', function () {
let id = jQuery(this).attr('id').substring(13);
let note = jQuery('#mainwp-notes-' + id + '-note').html();
jQuery('#mainwp-notes-html').html(note == '' ? MainWP.I18n.t('No saved notes. Click the Edit button to edit site notes.') : note);
jQuery('#mainwp-notes-note').val(note);
jQuery('#mainwp-notes-websiteid').val(id);
jQuery('#mainwp-which-note').val('site'); // to fix conflict.
mainwp_notes_show();
if (jQuery(this).attr('add-new')) {
jQuery('#mainwp-notes-edit').trigger("click");
}
return false;
});
jQuery(document).on('click', '#mainwp-notes-edit', function () {
jQuery('#mainwp-notes-html').hide();
jQuery('#mainwp-notes-editor').show();
jQuery(this).hide();
jQuery('#mainwp-notes-save').show();
jQuery('#mainwp-notes-status').html('');
jQuery('#mainwp-notes-status').removeClass('red green');
return false;
});
jQuery('#redirectForm').trigger("submit");
if (jQuery('div.ui.open-site-close-window').length > 0) {
setTimeout(function () {
globalThis.close()
}, 3000);
}
});
globalThis.mainwp_notes_show = function (reloadClose) {
if (reloadClose) {
jQuery('#mainwp-notes-modal').modal({
onHide: function () {
mainwp_forceReload();
}
}).modal('show');
} else {
jQuery('#mainwp-notes-modal').modal({ closable: false }).modal('show');
}
jQuery('#mainwp-notes-html').show();
jQuery('#mainwp-notes-editor').hide();
jQuery('#mainwp-notes-save').hide();
jQuery('#mainwp-notes-edit').show();
};
let mainwp_notes_hide = function () {
jQuery('#mainwp-notes-modal').modal('hide');
};
let mainwp_notes_site_save = function () {
let normalid = jQuery('#mainwp-notes-websiteid').val();
let newnote = jQuery('#mainwp-notes-note').val();
newnote = newnote.replaceAll(/\r\n|\r|\n/g, '
');
let data = mainwp_secure_data({
action: 'mainwp_notes_save',
websiteid: normalid,
note: newnote
});
jQuery('#mainwp-notes-status').html('
' + MainWP.I18n.t('Saving note. Please wait...')).show();
jQuery.post(ajaxurl, data, function (response) {
if (response.error != undefined) {
jQuery('#mainwp-notes-status').html(response.error).addClass('red');
} else if (response.result == 'SUCCESS') {
jQuery('#mainwp-notes-status').html(MainWP.I18n.t('Note saved successfully.')).addClass('green');
if (jQuery('#mainwp-notes-' + normalid + '-note').length > 0) {
jQuery('#mainwp-notes-' + normalid + '-note').html(response?.esc_note_content ?? '');
jQuery('#mainwp-notes-html').html(response?.esc_note_content ?? '');
}
} else {
jQuery('#mainwp-notes-status').html(MainWP.I18n.t('Undefined error occurred while saving your note!')).addClass('red');
}
}, 'json');
setTimeout(function () {
jQuery('#mainwp-notes-status').fadeOut(300);
}, 3000);
jQuery('#mainwp-notes-html').show();
jQuery('#mainwp-notes-editor').hide();
jQuery('#mainwp-notes-save').hide();
jQuery('#mainwp-notes-edit').show();
};
globalThis.getErrorMessage = function (pError, msgOnly) { // NOSONAR - complex.
if (pError.message == 'HTTPERROR') {
return MainWP.I18n.t('HTTP error') + '! ' + pError.extra;
} else if (pError.message == 'NOMAINWP' || pError == 'NOMAINWP') {
return mainwp_js_get_error_not_detected_connect();
} else if (pError.message == 'ERROR') {
return 'ERROR' + ((pError.extra != '') && (pError.extra != undefined) ? ': ' + pError.extra : '');
} else if (pError.message == 'WPERROR') {
let extrMsg = (pError.extra != '') && (pError.extra != undefined) ? pError.extra : '';
if (msgOnly != undefined && msgOnly && extrMsg != '') {
return extrMsg;
} else {
return MainWP.I18n.t('ERROR on the child site') + ': ' + extrMsg;
}
} else if (pError.message != undefined && pError.message != '') {
return pError.message;
} else {
return pError;
}
};
globalThis.getErrorMessageInfo = function (repError, outputType) { // NOSONAR - complex.
let msg = '';
let msgUI = '
';
if (repError.errorCode != undefined && repError.errorCode == 'SUSPENDED_SITE') {
msg = MainWP.I18n.t('Suspended site.');
msgUI = '
';
}
if (repError.errorCode != undefined && repError.errorCode == 'MAINWP_NOTICE') {
if (repError.message != undefined) {
msg = repError.message;
msgUI = '
';
}
}
if (msg == '') {
msg = getErrorMessage(repError);
if (repError.message == 'NOMAINWP' || repError == 'NOMAINWP') {
msg = mainwp_js_get_error_not_detected_connect();
}
if (msg != '') {
msgUI = '
';
}
}
if (msg != '') {
if (outputType != undefined && outputType == 'ui') {
return msgUI;
} else {
return msg;
}
}
return repError;
}
globalThis.dateToHMS = function (date) {
if (mainwpParams?.time_format) {
let time = moment(date);
let format = mainwpParams['time_format'];
format = format.replaceAll('g', 'h');
format = format.replaceAll('i', 'mm');
format = format.replaceAll('s', 'ss');
format = format.replaceAll('F', 'MMMM');
format = format.replaceAll('j', 'D');
format = format.replaceAll('Y', 'YYYY');
return time.format(format);
}
let h = date.getHours();
let m = date.getMinutes();
let s = date.getSeconds();
return '' + (h <= 9 ? '0' + h : h) + ':' + (m <= 9 ? '0' + m : m) + ':' + (s <= 9 ? '0' + s : s);
};
globalThis.appendToDiv = function (pSelector, pText, pScrolldown, pShowTime) {
if (pScrolldown == undefined)
pScrolldown = true;
if (pShowTime == undefined)
pShowTime = true;
let theDiv = jQuery(pSelector);
theDiv.append('
' + (pShowTime ? dateToHMS(new Date()) + ' ' : '') + pText);
if (pScrolldown)
theDiv.animate({ scrollTop: theDiv.prop("scrollHeight") }, 100);
};
jQuery.fn.exists = function () {
return (this.length !== 0);
};
globalThis.MainWP = globalThis.MainWP || {};
globalThis.MainWP.I18n = globalThis.MainWP.I18n || {};
MainWP.I18n.t = function (text, ...args) {
if (!text) {
return text;
}
// Replace non-alphanumeric characters (including Unicode/accented characters) with '_'
const strippedText = text.replace(/[^\p{L}\p{N}_]/gu, '_');
let translated = text;
if (
strippedText &&
typeof mainwpTranslations !== 'undefined' &&
mainwpTranslations[strippedText] !== undefined
) {
translated = mainwpTranslations[strippedText];
}
if (args.length === 0) {
return translated;
}
// Single-pass replacement to avoid placeholder collision issues
return translated.replace(/%(\d+)/g, (match, index) => {
const argIdx = parseInt(index, 10) - 1;
return args[argIdx] !== undefined ? args[argIdx] : match;
});
};
// Deprecated. Remove in a future release.
if (typeof globalThis.__ !== 'function') {
globalThis.__ = function (text, ...args) {
return globalThis.MainWP.I18n.t(text, ...args);
};
}
globalThis.mainwp_secure_data = function (data, includeDts) {
if (data['action'] == undefined)
return data;
if (security_nonces[data['action']] == undefined)
return data;
data['security'] = security_nonces[data['action']];
if (includeDts)
data['dts'] = Math.round(Date.now() / 1000);
return data;
};
globalThis.mainwp_uid = function () {
// always start with a letter (for DOM friendlyness)
let idstr = String.fromCodePoint(Math.floor((Math.random() * 25) + 65)); // NOSONAR - safe, it's id.
do {
// between numbers and characters (48 is 0 and 90 is Z (42-48 = 90)
let ascicode = Math.floor((Math.random() * 42) + 48); // NOSONAR - safe, it's id.
if (ascicode < 58 || ascicode > 64) {
// exclude all chars between : (58) and @ (64)
idstr += String.fromCodePoint(ascicode);
}
} while (idstr.length < 32);
return (idstr);
};
globalThis.scrollToElement = function () {
jQuery('html,body').animate({
scrollTop: 0
}, 1000);
return false;
};
jQuery(function () {
jQuery('#backup_filename').on('keypress', function (e) {
let chr = String.fromCodePoint(e.which);
return !"$^&*/".includes(chr);
});
jQuery('#backup_filename').on('change', function () {
let value = jQuery(this).val();
let notAllowed = ['$', '^', '&', '*', '/'];
for (let char of notAllowed) {
if (value.includes(char)) {
value = value.replaceAll(char, '');
jQuery(this).val(value);
}
}
});
});
/*
* Server Info
*/
globalThis.serverinfo_prepare_download_info = function (communi) {
let report = "";
jQuery('.mainwp-system-info-table thead, .mainwp-system-info-table tbody').each(function () {
let td_len = [35, 55, 45, 12, 12];
let th_count = 0;
let i;
if (jQuery(this).is('thead')) {
i = 0;
report = report + "\n### ";
th_count = jQuery(this).find('th:not(".mwp-not-generate-row")').length;
jQuery(this).find('th:not(".mwp-not-generate-row")').each(function () {
let len = td_len[i];
if (i == 0 || i == th_count - 1)
len = len - 4;
report = report + jQuery.mwp_strCut(jQuery.mwp_get_serverinfo_export_text(jQuery(this), communi), len, ' ');
i++;
});
report = report + " ###\n\n";
} else {
jQuery('tr', jQuery(this)).each(function () {
if (communi && jQuery(this).hasClass('mwp-not-generate-row'))
return;
i = 0;
jQuery(this).find('td:not(".mwp-not-generate-row")').each(function () {
if (jQuery(this).hasClass('mwp-hide-generate-row')) {
report = report + jQuery.mwp_strCut(' ', td_len[i], ' ');
i++;
return;
}
let outputText = jQuery.mwp_get_serverinfo_export_text(jQuery(this), communi);
report = report + jQuery.mwp_strCut(outputText, td_len[i], ' ');
i++;
});
report = report + "\n";
});
}
});
try {
if (communi) {
report = '```' + "\n" + report + "\n" + '```';
}
jQuery("#download-server-information textarea").val(report).trigger("select");
} catch {
console.log('Error:');
}
return false;
}
jQuery.mwp_get_serverinfo_export_text = function (element, communi) {
let cellExportText = element.attr('data-export-text');
if (typeof cellExportText !== 'undefined' && cellExportText !== '') {
return cellExportText.trim();
}
let descendantExportElement = element.find('[data-export-text]').first();
if (descendantExportElement.length > 0) {
let descendantExportText = descendantExportElement.attr('data-export-text');
if (typeof descendantExportText !== 'undefined' && descendantExportText !== '') {
return descendantExportText.trim();
}
}
let communityValue = element.attr('data-community-value');
if (communi && typeof communityValue !== 'undefined') {
return communityValue;
}
return element.text().trim();
}
jQuery(document).on('click', '#mainwp-download-system-report', function () {
serverinfo_prepare_download_info(false);
let server_info = jQuery('#download-server-information textarea').val();
let blob = new Blob([server_info], { type: "text/plain;charset=utf-8" });
saveAs(blob, "mainwp-system-report.txt");
return false;
});
jQuery(document).on('click', '#mainwp-download-community-system-report', function () {
serverinfo_prepare_download_info(true);
let server_info = jQuery('#download-server-information textarea').val();
let blob = new Blob([server_info], { type: "text/plain;charset=utf-8" });
saveAs(blob, "mainwp-community-system-report.txt");
return false;
});
jQuery.mwp_strCut = function (i, l, s, w) {
let o = i.toString();
if (!s) {
s = '0';
}
while (o.length < Number.parseInt(l)) {
// empty
if (w == 'undefined') {
o = s + o;
} else {
o = o + s;
}
}
return o;
};
globalThis.updateExcludedFolders = function () {
let excludedBackupFiles = jQuery('#excludedBackupFiles').html();
jQuery('#mainwp-kbl-content').val(excludedBackupFiles == undefined ? '' : excludedBackupFiles);
let excludedCacheFiles = jQuery('#excludedCacheFiles').html();
jQuery('#mainwp-kcl-content').val(excludedCacheFiles == undefined ? '' : excludedCacheFiles);
let excludedNonWPFiles = jQuery('#excludedNonWPFiles').html();
jQuery('#mainwp-nwl-content').val(excludedNonWPFiles == undefined ? '' : excludedNonWPFiles);
};
jQuery(document).on('click', '.mainwp-events-notice-dismiss', function () {
let notice = jQuery(this).attr('notice');
jQuery(this).closest('.ui.message').fadeOut(500);
let data = mainwp_secure_data({
action: 'mainwp_events_notice_hide',
notice: notice
});
jQuery.post(ajaxurl, data, function () {
});
return false;
});
// Turn On child plugin auto update
jQuery(document).on('click', '#mainwp_btn_autoupdate_and_trust', function () {
jQuery(this).attr('disabled', 'true');
let data = mainwp_secure_data({
action: 'mainwp_autoupdate_and_trust_child'
});
jQuery.post(ajaxurl, data, function (res) {
if (res == 'ok') {
location.reload(true);
} else {
jQuery(this).prop("disabled", false);
}
});
return false;
});
// Hide installation warning
jQuery(document).on('click', '#remove-mainwp-installation-warning', function () {
jQuery(this).closest('.ui.message').fadeOut("slow");
let data = mainwp_secure_data({
action: 'mainwp_installation_warning_hide'
});
jQuery.post(ajaxurl, data, function () { });
return false;
});
jQuery(document).on('click', '.mainwp-notice-hide', function () {
jQuery(this).closest('.ui.message').fadeOut("slow");
return false;
});
// Hide after installtion notices (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning)
jQuery(document).on('click', '.mainwp-notice-dismiss', function () {
let notice_id = jQuery(this).attr('notice-id');
let shortterm = jQuery(this).attr('shortterm-notice');
jQuery(this).closest('.ui.message').fadeOut("slow");
let data = {
action: 'mainwp_notice_status_update'
};
data['notice_id'] = notice_id;
if(shortterm === '1'){
data['short_term'] = 1;
}
jQuery.post(ajaxurl, mainwp_secure_data(data), function () { });
return false;
});
globalThis.mainwp_notice_dismiss = function (notice_id, time_set) {
let data = {
action: 'mainwp_notice_status_update'
};
data['notice_id'] = notice_id;
if (time_set !== undefined) {
data['time_set'] = time_set ? 1 : 0;
}
jQuery.post(ajaxurl, mainwp_secure_data(data), function () {
});
return false;
}
jQuery(document).on('click', '.mainwp-activate-notice-dismiss', function () {
jQuery(this).closest('tr').fadeOut("slow");
let data = mainwp_secure_data({
action: 'mainwp_dismiss_activate_notice',
slug: jQuery(this).closest('tr').attr('slug')
});
jQuery.post(ajaxurl, data, function () {
});
return false;
});
jQuery(document).on('click', '.mainwp-install-check-dismiss', function () {
let notice_id = jQuery(this).attr('notice-id');
jQuery(this).closest('.ui.message').fadeOut("slow");
let data = {
action: 'mainwp_notice_status_update'
};
data['notice_id'] = notice_id;
jQuery.post(ajaxurl, mainwp_secure_data(data), function () { });
return false;
});
jQuery(document).on('click', '#mainwp-dismiss-sites-changes-actions-button', function () {
mainwp_confirm('You are about to dismiss the selected changes?', function () {
mainwp_delete_nonmainwp_data_start();
});
return false;
});
let mainwp_managesites_update_childsite_value = function (siteId, uniqueId) {
let data = mainwp_secure_data({
action: 'mainwp_updatechildsite_value',
site_id: siteId,
unique_id: uniqueId
});
jQuery.post(ajaxurl, data, function () {
});
return false;
};
jQuery(document).on('keyup', '#managegroups-filter', function () {
let filter = jQuery(this).val();
let groupItems = jQuery(this).parent().parent().find('li.managegroups-listitem');
for (let igr of groupItems) {
let currentElement = jQuery(igr);
if (currentElement.hasClass('managegroups-group-add')) {
continue;
}
let value = currentElement.find('span.text').text();
if (value.includes(filter)) {
currentElement.show();
} else {
currentElement.hide();
}
}
});
// for normal checkboxes
jQuery(document).on('change', '#cb-select-all-top, #cb-select-all-bottom', function () {
let $this = jQuery(this), $table, controlChecked = $this.prop('checked');
$table = $this.closest('.dt-scroll').find('.dt-scroll-body table'); // for dt with scroll enabled.
// if no scrollable table.
if ($table.length == 0) {
$table = $this.closest('table.table.dataTable');
}
if ($table.length == 0)
return false;
$table.children('tbody').filter(':visible')
.children().children('.check-column').find(':checkbox')
.prop('checked', function () {
if (jQuery(this).is(':hidden,:disabled')) {
return false;
}
if (controlChecked) {
jQuery(this).closest('tr').addClass('selected');
return true;
}
jQuery(this).closest('tr').removeClass('selected');
return false;
});
$table.children('thead, tfoot').filter(':visible')
.children().children('.check-column').find(':checkbox')
.prop('checked', function () {
if (controlChecked) {
jQuery(this).closest('tr').addClass('selected');
return true;
}
jQuery(this).closest('tr').removeClass('selected');
return false;
});
let dtApi = jQuery($table).dataTable().api();
let setStatus = controlChecked ? 'selected' : 'deselected';
mainwp_datatable_fix_to_update_selected_rows_status(dtApi, setStatus);
});
jQuery(document).on('change', '.cb-select-all-parent-top, .cb-select-all-parent-bottom', function () {
let parentChecked = jQuery(this).is(":checked");
let parentSelector = jQuery(this).attr('cb-parent-selector') ?? false;
if (false === parentSelector) {
return;
}
jQuery(parentSelector + ' .ui.checkbox').find(':checkbox')
.prop('checked', function () {
if (parentChecked) {
jQuery(this).closest('tr').addClass('selected');
return true;
}
jQuery(this).closest('tr').removeClass('selected');
return false;
});
});
jQuery(function ($) {
// Trigger the bulk actions
$('#mainwp_sites_changes_bulk_dismiss_selected_btn').on('click', function () {
if (jQuery('#mainwp-module-log-records-body-table tr').find('input[type="checkbox"]:checked').length == 0) {
return;
}
let confirmMsg = MainWP.I18n.t("You are about to dismiss the selected changes?");
mainwp_confirm(confirmMsg, function () { mainwp_sites_changes_actions_bulk_action('dismiss-selected'); });
});
$('#mainwp_sites_changes_bulk_dismiss_all_btn').on('click', function () {
let confirmMsg = MainWP.I18n.t("You are about to dismiss all changes?");
mainwp_confirm(confirmMsg, function () { mainwp_sites_changes_actions_bulk_action('dismiss-all'); });
});
// Trigger the bulk actions
$('#mainwp_widget_sites_changes_bulk_dismiss_selected_btn').on('click', function () {
if (jQuery('#mainwp-module-log-records-body-table tr').find('input[type="checkbox"]:checked').length == 0) {
return;
}
let confirmMsg = MainWP.I18n.t("You are about to dismiss the selected changes?");
mainwp_confirm(confirmMsg, function () { mainwp_sites_changes_actions_bulk_action('dismiss-selected', 'widget'); });
});
$(document).on('click', '.insights-actions-row-dismiss', function () {
return mainwp_insights_row_actions_dismiss(this);
});
globalThis.mainwp_sites_changes_update_dismiss_button_state = function () {
let checkedCount = jQuery('#mainwp-module-log-records-body-table tr').find('input[type="checkbox"]:checked').length;
let totalRows = jQuery('#mainwp-module-log-records-body-table tr').not('.dt-empty').length;
if (checkedCount > 0) {
jQuery('#mainwp_sites_changes_bulk_dismiss_selected_btn').removeClass('disabled');
} else {
jQuery('#mainwp_sites_changes_bulk_dismiss_selected_btn').addClass('disabled');
}
if (totalRows > 0) {
jQuery('#mainwp_sites_changes_bulk_dismiss_all_btn').removeClass('disabled');
} else {
jQuery('#mainwp_sites_changes_bulk_dismiss_all_btn').addClass('disabled');
}
}
jQuery(document).on('change', '#mainwp-module-log-records-body-table input[type="checkbox"]', function () {
mainwp_sites_changes_update_dismiss_button_state();
});
jQuery(document).on('change', '#cb-select-all-top, #cb-select-all-bottom', function () {
mainwp_sites_changes_update_dismiss_button_state();
});
})
let mainwp_insights_row_actions_dismiss = function (obj) {
let row = jQuery(obj).closest('tr');
let confirmMsg = MainWP.I18n.t("You are about to dismiss the selected change?");
const renderMessage = (icon, message) => {
row.html(
'
| ' +
message +
' | '
);
};
const updateDismissButtonState = () => {
if (typeof mainwp_sites_changes_update_dismiss_button_state !== 'undefined') {
mainwp_sites_changes_update_dismiss_button_state();
}
};
const fadeRow = () => {
setTimeout(() => {
jQuery(row).fadeOut('slow', updateDismissButtonState);
}, 2000);
};
let _callback = () => {
row.html('
| Please wait... | ');
let data = mainwp_secure_data({
action: 'mainwp_insight_events_dismiss_actions',
log_id: jQuery(row).attr('log-id')
});
jQuery.post(ajaxurl, data, function (response) {
if (response?.success !== 'yes') {
if (response?.error) {
renderMessage('times red', response.error);
} else {
renderMessage('times red', 'The change could not be dismissed.');
}
return;
}
renderMessage('green check', 'The change has been dismissed.');
fadeRow();
}, 'json');
};
mainwp_confirm(confirmMsg, _callback);
return false;
}
// Manage Bulk Actions
let mainwp_sites_changes_actions_bulk_action = function (act, which_act) {
mainwpVars.bulkInstallTotal = 0;
bulkInstallCurrentThreads = 0;
bulkInstallDone = 0;
mainwpVars.bulkActionIndent = '';
if (which_act === 'widget') {
mainwpVars.bulkActionIndent = 'widget';
}
if (act === 'dismiss-selected') {
jQuery('#mainwp_sites_changes_bulk_dismiss_selected_btn').addClass('disabled');
let selector = '#mainwp-module-log-records-body-table tr';
mainwpVars.bulkInstallTotal = jQuery(selector).find('input[type="checkbox"]:checked').length;
jQuery(selector).addClass('queue');
if (jQuery(selector).length) {
if (mainwpVars.bulkActionIndent === 'widget') {
jQuery('#mainwp_widget_sites_changes_bulk_dismiss_selected_btn').addClass('disabled');
} else {
jQuery('#mainwp_sites_changes_bulk_dismiss_selected_btn').addClass('disabled');
}
}
mainwp_sites_changes_actions_dismiss_start_next(selector);
} else if (act === 'dismiss-all') {
jQuery('#mainwp_sites_changes_bulk_dismiss_all_btn').addClass('disabled');
mainwp_sites_changes_actions_dismiss_all();
}
}
let mainwp_sites_changes_actions_dismiss_start_next = function (selector) {
while ((objProcess = jQuery(selector + '.queue:first')) && (objProcess.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { // NOSONAR - modified outside the function.
objProcess.removeClass('queue');
if (objProcess.closest('tr').find('input[type="checkbox"]:checked').length == 0) {
continue;
}
mainwp_sites_changes_actions_dismiss_specific(objProcess, selector);
}
if (mainwpVars.bulkInstallTotal == bulkInstallDone) {
if (mainwpVars.bulkActionIndent === 'widget') {
jQuery('#mainwp_widget_sites_changes_bulk_dismiss_selected_btn').removeClass('disabled');
} else {
jQuery('#mainwp_sites_changes_bulk_dismiss_selected_btn').removeClass('disabled');
}
if (typeof mainwp_sites_changes_update_dismiss_button_state !== 'undefined') {
mainwp_sites_changes_update_dismiss_button_state();
}
}
}
let mainwp_sites_changes_actions_dismiss_specific = function (pObj, selector) {
let row = pObj.closest('tr');
let act_id = jQuery(row).attr('log-id');
bulkInstallCurrentThreads++;
let data = mainwp_secure_data({
action: 'mainwp_insight_events_dismiss_actions',
log_id: act_id
});
row.html('
| Please wait... | ');
jQuery.post(ajaxurl, data, function (response) {
pObj.removeClass('queue');
if (response) {
if (response['error']) {
row.html('
| ' + response['error'] + ' | ');
} else if (response['success'] == 'yes') {
row.html('
| The change has been dismissed. | ');
setTimeout(function () {
jQuery(row).fadeOut("slow");
}, 2000);
} else {
row.html('
| Failed. Please try again. | ');
}
} else {
row.html('
| Failed. Please try again. | ');
}
bulkInstallCurrentThreads--;
bulkInstallDone++;
mainwp_sites_changes_actions_dismiss_start_next(selector);
}, 'json');
return false;
}
let mainwp_sites_changes_actions_dismiss_all = function () {
let data = mainwp_secure_data({
action: 'mainwp_insight_events_dismiss_all',
});
mainwp_showhide_message('mainwp-message-zone-top', '
Please wait...', '');
jQuery.post(ajaxurl, data, function (response) {
if (response) {
if (response['error']) {
mainwp_showhide_message('mainwp-message-zone-top', response['error'], 'red');
} else if (response['success'] == 'yes') {
mainwp_showhide_message('mainwp-message-zone-top', 'All changes have been dismissed.', 'green');
setTimeout(function () {
mainwp_forceReload();
}, 2000);
} else {
mainwp_showhide_message('mainwp-message-zone-top', 'Failed. Please try again.', 'red');
}
} else {
mainwp_showhide_message('mainwp-message-zone-top', 'Failed. Please try again.', 'red');
}
}, 'json');
return false;
}
globalThis.mainwp_datatable_fix_to_update_selected_rows_status = function (dtApi, setStatus) {
if (dtApi) {
if ('selected' === setStatus) {
dtApi.rows('.selected').select(); // update selected status.
} else if ('deselected' === setStatus) {
dtApi.rows().deselect(); // update deselected status.
}
}
}
globalThis.mainwp_datatable_fix_to_update_rows_state = function (tblSelect) {
if (jQuery(tblSelect).length) {
let $table = jQuery(tblSelect);
let dtApi = jQuery($table).dataTable().api(); // NOTE: not use DataTable().
mainwp_datatable_fix_to_update_selected_rows_status(dtApi, 'deselected'); // clear saved state.
$table.children('tbody').filter(':visible').find('tr').each(function () {
if (jQuery(this).children('.check-column').find(':checkbox').is(':checked')) {
jQuery(this).addClass('selected');
} else if (jQuery(this).hasClass('selected')) {
jQuery(this).removeClass('selected');
}
});
mainwp_datatable_fix_to_update_selected_rows_status(dtApi, 'selected'); // to update selected state.
}
}
globalThis.mainwp_datatable_fix_reorder_selected_rows_status = function () {
jQuery('.table.dataTable tbody').filter(':visible').children('tr.selected').find(':checkbox').prop('checked', true);
};
// fix menu overflow with scroll tables.
globalThis.mainwp_datatable_fix_menu_overflow = function (pTableSelector, pTop, pRight) {
if (pTableSelector === undefined) {
console.warn('mainwp_datatable_fix_menu_overflow: requires params - $pTableSelector');
}
let dtScrollBdCls = '.dt-scroll-body';
let dtScrollCls = '.dt-scroll';
let fix_overflow = jQuery('.mainwp-content-wrap').attr('menu-overflow');
jQuery(document).on('click', 'table td.check-column.dtr-control', function () {
if (jQuery(this).parent().hasClass('parent')) {
let chilRow = jQuery(this).parent().next();
jQuery(chilRow).find('.ui.dropdown').dropdown();
mainwp_datatable_fix_child_menu_overflow(chilRow, fix_overflow);
}
});
let tblSelect = pTableSelector ?? 'table';
// to prevent double events.
jQuery(tblSelect + ' tr td .ui.right.pointing.dropdown').each(function () {
let parentTB = jQuery(this).closest('table');
if (parentTB.attr('fixed-menu-overflow') === undefined) {
parentTB.attr('fixed-menu-overflow', 'no'); // to init click menu events.
}
});
jQuery(tblSelect + ' tr td .ui.left.pointing.dropdown').each(function () {
let parentTB = jQuery(this).closest('table');
if (parentTB.attr('fixed-menu-overflow') === undefined) {
parentTB.attr('fixed-menu-overflow', 'no'); // to init click menu events.
}
});
// if table selector specific.
if (pTableSelector !== undefined) {
if (jQuery(pTableSelector + '[fixed-menu-overflow="yes"]').length) {
jQuery(pTableSelector + '[fixed-menu-overflow="yes"]').attr('fixed-menu-overflow', 'no'); // to init menus events click.
}
}
// Fix the overflow prbolem for the actions menu element (right pointing menu).
jQuery(tblSelect + '[fixed-menu-overflow="no"] tr td .ui.right.pointing.dropdown').on('click', function () {
jQuery(this).closest(dtScrollBdCls).css('position', '');
jQuery(this).closest(dtScrollCls).css('position', 'relative');
jQuery(this).css('position', 'static');
let fix_overflow = jQuery('.mainwp-content-wrap').attr('menu-overflow');
let position = jQuery(this).position();
let top = position.top;
let right = 50;
if (fix_overflow > 1) {
position = jQuery(this).closest('td').position();
top = position.top + 85; //85
}
if (pTop !== undefined) {
top = top + pTop;
}
if (pRight !== undefined) {
right = right + pRight;
}
jQuery(this).find('.menu').css('min-width', '170px');
jQuery(this).find('.menu').css('top', top);
jQuery(this).find('.menu')[0].style.setProperty('right', right + 'px', 'important');
});
// Fix the overflow prbolem for the actions menu element (left pointing menu).
jQuery(tblSelect + '[fixed-menu-overflow="no"] tr td .ui.left.pointing.dropdown').on('click', function () {
jQuery(this).closest(dtScrollBdCls).css('position', '');
jQuery(this).closest(dtScrollCls).css('position', 'relative');
jQuery(this).css('position', 'static');
let position = jQuery(this).position();
let top = position.top;
let left = position.left - 159;
if (fix_overflow > 1) {
position = jQuery(this).closest('td').position();
let scroll_left = jQuery(this).closest(dtScrollBdCls).scrollLeft();
top = position.top + 85;
left = position.left - scroll_left - 145;
}
if (pTop !== undefined) {
top = top + pTop;
}
jQuery(this).find('.menu').css('min-width', '150px');
jQuery(this).removeClass('left');
jQuery(this).addClass('right');
jQuery(this).find('.menu').css('top', top);
jQuery(this).find('.menu')[0].style.setProperty('left', left + 'px', 'important');
});
jQuery(tblSelect + '[fixed-menu-overflow="no"]').each(function () {
jQuery(this).attr('fixed-menu-overflow', 'yes');
});
mainwp_datatable_fix_reorder_selected_rows_status();
}
let mainwp_datatable_fix_child_menu_overflow = function (chilRow, fix_overflow) {
let dtScrollBdCls = '.dt-scroll-body';
let dtScrollCls = '.dt-scroll';
// Fix the overflow prbolem for the actions child menu element (pointing menu).
jQuery(chilRow).find('.ui.pointing.dropdown').on('click', function () {
let position = jQuery(this).position();
let left = position.left + 30;
let top = position.top;
if (fix_overflow > 1) {
position = jQuery(this).closest('td.child').position();
top = position.top + jQuery(this).closest('td.child').height() + 85;
}
jQuery(this).closest(dtScrollBdCls).css('position', '');
jQuery(this).closest(dtScrollCls).css('position', 'relative');
jQuery(this).css('position', 'static');
jQuery(this).find('.menu').css('top', top);
jQuery(this).find('.menu').css('left', left);
jQuery(this).find('.menu').css('min-width', '170px');
});
}
globalThis.mainwp_responsive_fix_remove_child_row = function (el) {
if (jQuery(el).hasClass('dt-hasChild')) { // to fix.
jQuery(el).next().remove();
}
}
/* eslint-disable complexity */
function mainwp_according_table_sorting(pObj) { // NOSONAR - complex.
let table, th, rows, switching, i, x, y, xVal, yVal, campare = false, shouldSwitch = false, dir, switchcount = 0, n, skip = 1;
table = jQuery(pObj).closest('table')[0];
let subline_skip = 2;
if ('mainwp-wordpress-updates-table' == jQuery(table).attr('id')) {
subline_skip = 1; // for rows without subline.
skip = 0;
}
// get TH element
if (jQuery(pObj)[0].tagName == 'TH') {
th = jQuery(pObj)[0];
} else {
th = jQuery(pObj).closest('th')[0];
}
n = th.cellIndex;
switching = true;
// check header and footer of according table
if (jQuery(table).children('thead,tfoot').length > 0)
skip += jQuery(table).children('thead,tfoot').length; // skip sorting header, footer
dir = "asc";
/* loop until switching has been done: */
while (switching) {
switching = false;
rows = table.rows;
/* Loop through all table rows */
for (i = 1; i < (rows.length - skip); i += subline_skip) { // skip content according rows, sort by title rows only
shouldSwitch = false;
/* Get the two elements you want to compare,
one from current row and one from the next-next: */
x = rows[i].getElementsByTagName("TD")[n];
y = rows[i + subline_skip].getElementsByTagName("TD")[n];
// if sort value attribute existed then sorting on that else sorting on cell value
if (x.hasAttribute('sort-value')) {
xVal = Number.parseInt(x.getAttribute('sort-value'));
yVal = Number.parseInt(y.getAttribute('sort-value'));
let tmp = xVal > yVal ? -1 : 1;
campare = (xVal == yVal) ? 0 : tmp;
} else {
// to prevent text() clear text content
xVal = '
' + x.innerHTML + '
';
yVal = '
' + y.innerHTML + '
';
xVal = jQuery(xVal).text().trim().toLowerCase();
yVal = jQuery(yVal).text().trim().toLowerCase();
campare = yVal.localeCompare(xVal);
}
/* Check if the two rows should switch place */
if (dir == "asc") {
if (campare < 0) { //xVal > yVal
shouldSwitch = true;
// break the loop:
break;
}
} else if (dir == "desc") {
if (campare > 0) { //xVal < yVal
// break the loop:
shouldSwitch = true;
break;
}
}
}
if (shouldSwitch) {
if (2 == subline_skip) {
rows[i].parentNode.insertBefore(rows[i + 2], rows[i]);
rows[i + 1].parentNode.insertBefore(rows[i + 3], rows[i + 1]);
} else {
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]); // switch 2 rows.
}
switching = true;
// increase this count by 1, that is ok
switchcount++;
} else if (switchcount == 0 && dir == "asc") {
/* If no switching has been done AND the direction is "asc",
set the direction to "desc" and run the while loop again. */
dir = "desc";
switching = true;
}
}
// no row sorting so change direction for arrows switch
if (switchcount == 0) {
if (jQuery(pObj).hasClass('ascending')) {
dir = "desc";
} else {
dir = "asc";
}
}
// add/remove class for arrows displaying
if (dir == "asc") {
jQuery(pObj).addClass('ascending');
jQuery(pObj).removeClass('descending');
} else {
jQuery(pObj).removeClass('ascending');
jQuery(pObj).addClass('descending');
}
}
/* eslint-enable complexity */
jQuery(function () {
jQuery('.handle-accordion-sorting').on('click', function () {
mainwp_according_table_sorting(this);
return false;
});
});
// Force Dashboard to reestablish connection by destroying sessions - Part 1
let mainwp_force_destroy_sessions = function () {
let confirmMsg = MainWP.I18n.t('Are you sure you want to force your MainWP Dashboard to reconnect with your child sites?');
mainwp_confirm(confirmMsg, function () {
mainwp_force_destroy_sessions_websites = jQuery('.dashboard_wp_id[error-status=0]').map(function (indx, el) {
return jQuery(el).val();
});
mainwpPopup('#mainwp-sync-sites-modal').setTitle(MainWP.I18n.t('Re-establish Connection')); // popup displayed.
mainwpPopup('#mainwp-sync-sites-modal').init({ progressMax: mainwp_force_destroy_sessions_websites.length });
mainwp_force_destroy_sessions_part_2(0);
});
};
let mainwp_force_destroy_sessions_part_2 = function (id) {
if (id >= mainwp_force_destroy_sessions_websites.length) {
mainwp_force_destroy_sessions_websites = [];
if (mainwp_force_destroy_sessions_successed == mainwp_force_destroy_sessions_websites.length) {
setTimeout(function () {
mainwpPopup('#mainwp-sync-sites-modal').close(true);
}, 3000);
}
mainwpPopup('#mainwp-sync-sites-modal').close(true);
return;
}
let website_id = mainwp_force_destroy_sessions_websites[id];
dashboard_update_site_status(website_id, '
');
jQuery.post(ajaxurl, { 'action': 'mainwp_force_destroy_sessions', 'website_id': website_id, 'security': security_nonces['mainwp_force_destroy_sessions'] }, function (response) {
let counter = id + 1;
mainwp_force_destroy_sessions_part_2(counter);
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(counter);
if ('error' in response) {
dashboard_update_site_status(website_id, '
');
} else if ('success' in response) {
mainwp_force_destroy_sessions_successed += 1;
dashboard_update_site_status(website_id, '
', true);
} else {
dashboard_update_site_status(website_id, '
');
}
}, 'json').fail(function () {
let counter = id + 1;
mainwp_force_destroy_sessions_part_2(counter);
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(counter);
dashboard_update_site_status(website_id, '');
});
};
let mainwp_force_destroy_sessions_successed = 0;
let mainwp_force_destroy_sessions_websites = [];
jQuery(document).on('change', '#mainwp_archiveFormat', function () {
let zipMethod = jQuery(this).val();
zipMethod = zipMethod.replaceAll('.', '\\.'); // NOSONAR - escape is correct.
jQuery('span.archive_info').hide();
jQuery('span#info_' + zipMethod).show();
jQuery('tr.archive_method').hide();
jQuery('tr.archive_' + zipMethod).show();
// compare new layout
jQuery('div.archive_method').hide();
jQuery('div.archive_' + zipMethod).show();
});
let mainwp_import_demo_data_action = function (obj) {
let confirmation = "Are you sure you want to import demo content into your MainWP Dashboard?";
let msg_import = (jQuery(obj).attr('page-import') == 'qsw-import') ? '&message=qsw-import' : '';
mainwp_confirm(confirmation, function () {
feedback('mainwp-message-zone', ' ' + MainWP.I18n.t('Importing. Please wait...'), '');
let data = mainwp_secure_data({
action: 'mainwp_import_demo_data',
});
jQuery.post(ajaxurl, data, function (response) {
let error = false;
if (response.count === undefined) {
error = true;
feedback('mainwp-message-zone', MainWP.I18n.t('Undefined error. Please try again.'), 'green');
} else {
feedback('mainwp-message-zone', MainWP.I18n.t('The demo content has been imported into your MainWP Dashboard.'), 'green');
}
if (!error) {
setTimeout(function () {
mainwp_forceReload('admin.php?page=mainwp_tab' + msg_import);
}, 3000);
}
}, 'json');
});
}
let mainwp_remove_demo_data_action = function () {
let confirmation = "Are you sure you want to delete demo content from your MainWP Dashboard?";
mainwp_confirm(confirmation, function () {
feedback('mainwp-message-zone', ' ' + MainWP.I18n.t('Deleting. Please wait...'), '');
let data = mainwp_secure_data({
action: 'mainwp_delete_demo_data',
});
jQuery.post(ajaxurl, data, function (response) {
let error = false;
if (response.success === undefined) {
error = true;
feedback('mainwp-message-zone', MainWP.I18n.t('Undefined error. Please try again.'), 'green');
} else {
feedback('mainwp-message-zone', MainWP.I18n.t('The demo content has been deleted from your MainWP Dashboard.'), 'green');
}
if (!error) {
setTimeout(function () {
mainwp_forceReload('admin.php?page=mainwp-setup');
}, 3000);
}
}, 'json');
});
}
// MainWP Tools
jQuery(function () {
jQuery(document).on('click', '#force-destroy-sessions-button', function () {
mainwp_force_destroy_sessions();
});
jQuery(document).on('click', '.mainwp-import-demo-data-button', function (event) {
mainwp_import_demo_data_action(this);
event.preventDefault();
});
jQuery(document).on('click', '.mainwp-remove-demo-data-button', function () {
mainwp_remove_demo_data_action();
return false; //required this return.
});
});
let mainwp_tool_renew_connections_show = function () {
jQuery('#mainwp-tool-renew-connect-modal').modal({
allowMultiple: true,
closable: false,
onHide: function () {
mainwp_forceReload('admin.php?page=MainWPTools');
},
onShow: function () {
if (jQuery('#mainwp-tool-renew-connect-modal .mainwp_selected_sites_item.item.warning').length == 0) {
jQuery('#mainwp-tool-renew-connect-modal .mainwp-ss-select-disconnected').hide();
jQuery('#mainwp-tool-renew-connect-modal .mainwp-ss-deselect-disconnected').hide();
}
}
}).modal('show');
};
let mainwp_tool_prepare_renew_connections = function (objBtn) {
let errors = [];
let selected_sites = [];
mainwp_set_message_zone('#mainwp-message-zone-modal');
jQuery("input[name='selected_sites[]']:checked").each(function () {
selected_sites.push(jQuery(this).val());
});
if (selected_sites.length == 0) {
errors.push(MainWP.I18n.t('Please select at least one website to start.'));
}
if (errors.length > 0) {
mainwp_set_message_zone('#mainwp-message-zone-modal', errors.join('
'), 'yellow');
return;
} else {
mainwp_set_message_zone('#mainwp-message-zone-modal');
}
let confirmation = MainWP.I18n.t("This process will create a new OpenSSL Key Pair on your MainWP Dashboard and Set the new Public Key to your Child site(s). Are you sure you want to proceed?");
mainwp_confirm(confirmation, function () {
jQuery(objBtn).attr('disabled', true);
jQuery('#mainwp-tool-renew-connect-modal .mainwp-select-sites-wrapper').hide();
let statusEl = jQuery('#mainwp-message-zone-modal');
statusEl.html(' ' + MainWP.I18n.t('Please wait...'));
statusEl.show();
let data = mainwp_secure_data({
action: 'mainwp_prepare_renew_connections',
'sites[]': selected_sites,
});
jQuery.post(ajaxurl, data, function (response) {
let undefError = false;
if (response) {
if (response.result != '') {
jQuery('#mainwp-tool-renew-connect-modal').find('#mainwp-renew-connections-list').html(response.result);
mainwpVars.bulkInstallTotal = jQuery('#mainwp-renew-connections-list .item').length;
jQuery('#mainwp-tool-renew-connect-modal .mainwp-modal-progress').show();
jQuery('#mainwp-tool-renew-connect-modal .mainwp-modal-progress').progress({ value: 0, total: mainwpVars.bulkInstallTotal });
mainwp_tool_renew_connections_start_next();
statusEl.hide();
} else if (response.error) {
statusEl.addClass('red');
statusEl.html(response.error).fadeIn();
} else {
undefError = true;
}
} else {
undefError = true;
}
if (undefError) {
statusEl.addClass('red');
statusEl.html(MainWP.I18n.t('Undefined error occurred. Please try again.')).fadeIn();
}
}, 'json');
}, false, false, true);
}
let connection_renew_status = function (siteId, newStatus) {
jQuery('#mainwp-renew-connections-list .renew-site-status[siteid="' + siteId + '"]').html(newStatus);
};
let mainwp_tool_renew_connections_start_next = function () {
while ((siteToReNew = jQuery('#mainwp-renew-connections-list .item[status="queue"]:first')) && (siteToReNew.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { // NOSONAR - modified outside the function.
mainwp_tool_renew_connections_start_specific(siteToReNew);
}
}
let mainwp_tool_renew_connections_start_specific = function (siteItem) {
bulkInstallCurrentThreads++;
siteItem.attr('status', 'progress');
let siteId = siteItem.find('.renew-site-status').attr('siteid');
let data = mainwp_secure_data({
action: 'mainwp_renew_connections',
siteid: siteId
});
connection_renew_status(siteId, '');
jQuery.post(ajaxurl, data, function (response) {
if (response.error) {
connection_renew_status(siteId, '');
} else if (response.result == 'success') {
connection_renew_status(siteId, '');
} else {
connection_renew_status(siteId, '');
}
bulkInstallCurrentThreads--;
bulkInstallDone++;
jQuery('#mainwp-tool-renew-connect-modal .mainwp-modal-progress').progress('set progress', bulkInstallDone);
jQuery('#mainwp-tool-renew-connect-modal .mainwp-modal-progress').find('.label').html(bulkInstallDone + '/' + mainwpVars.bulkInstallTotal + ' ' + MainWP.I18n.t('Processed'));
mainwp_tool_renew_connections_start_next();
}, 'json');
}
jQuery(function () {
if (jQuery('body.mainwp-ui').length > 0) {
jQuery('.mainwp-ui-page .ui.dropdown:not(.not-auto-init)').dropdown();
jQuery('.mainwp-ui-page .ui.checkbox:not(.not-auto-init)').checkbox();
jQuery('.mainwp-ui-page .ui.dropdown').filter('[init-value]').each(function () {
let values = jQuery(this).attr('init-value').split(',');
jQuery(this).dropdown('set selected', values);
});
}
});
// MainWP Action Logs
jQuery(document).on('click', '.mainwp-action-log-show-more', function () {
let content = jQuery(this).closest('.item').find('.mainwp-action-log-site-response').text();
jQuery('#mainwp-action-log-response-modal').modal({
closable: false,
onHide: function () {
location.reload();
}
}).modal('show');
jQuery('#mainwp-action-log-response-modal .content-response').text(content);
});
// MainWP Show Response
jQuery(document).on('click', '.mainwp-show-response', function () {
let content = jQuery('#mainwp-response-data-container').attr('resp-data');
jQuery('#mainwp-response-data-modal').modal({
closable: false,
onHide: function () {
jQuery('#mainwp-response-data-modal .content-response').text('');
}
}).modal('show');
jQuery('#mainwp-response-data-modal .content-response').text(content);
});
// Copy to clipboard for response modals.
jQuery(document).on('click', '.mainwp-response-copy-button', function (event) {
let modal = jQuery(this).closest('.ui.modal');
let data = jQuery(modal).find('.content.content-response').text();
let $temp_txtarea = jQuery('