| 1 |
/* eslint complexity: ["error", 100] */ |
| 2 |
jQuery(document).on('click', '.item.extension-inactive', function () { |
| 3 |
jQuery('#mainwp-install-extensions-promo-modal').modal('show'); |
| 4 |
return false; |
| 5 |
}); |
| 6 |
|
| 7 |
jQuery(document).on('click', '#mainwp-extension-update-check-retry', function () { |
| 8 |
let button = jQuery(this); |
| 9 |
let status = jQuery('#mainwp-extension-update-check-retry-status'); |
| 10 |
let failedText = button.data('failed-text'); |
| 11 |
|
| 12 |
button.addClass('loading disabled').prop('disabled', true); |
| 13 |
status.text(''); |
| 14 |
|
| 15 |
jQuery.post(ajaxurl, mainwp_secure_data({ |
| 16 |
action: 'mainwp_extension_update_check_retry' |
| 17 |
}), function (response) { |
| 18 |
if (response && response.result === 'SUCCESS') { |
| 19 |
location.reload(); |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
status.text(response && response.error ? response.error : failedText); |
| 24 |
button.removeClass('loading disabled').prop('disabled', false); |
| 25 |
}, 'json').fail(function () { |
| 26 |
status.text(failedText); |
| 27 |
button.removeClass('loading disabled').prop('disabled', false); |
| 28 |
}); |
| 29 |
|
| 30 |
return false; |
| 31 |
}); |
| 32 |
|
| 33 |
jQuery(document).on('click', '#mainwp-extensions-show-all', function () { |
| 34 |
jQuery(this).addClass('green'); |
| 35 |
jQuery('#mainwp-extensions-show-extensions').removeClass('green'); |
| 36 |
jQuery('#mainwp-extensions-show-integrations').removeClass('green'); |
| 37 |
jQuery('#mainwp-extensions-list').find('.card[extension-model="integration"]').fadeIn(200); |
| 38 |
jQuery('#mainwp-extensions-list').find('.card[extension-model="extension"]').fadeIn(200); |
| 39 |
}); |
| 40 |
|
| 41 |
jQuery(document).on('click', '#mainwp-extensions-show-extensions', function () { |
| 42 |
jQuery(this).addClass('green'); |
| 43 |
jQuery('#mainwp-extensions-show-all').removeClass('green'); |
| 44 |
jQuery('#mainwp-extensions-show-integrations').removeClass('green'); |
| 45 |
jQuery('#mainwp-extensions-list').find('.card[extension-model="integration"]').fadeOut(200); |
| 46 |
jQuery('#mainwp-extensions-list').find('.card[extension-model="extension"]').fadeIn(200); |
| 47 |
}); |
| 48 |
|
| 49 |
jQuery(document).on('click', '#mainwp-extensions-show-integrations', function () { |
| 50 |
jQuery(this).addClass('green'); |
| 51 |
jQuery('#mainwp-extensions-show-extensions').removeClass('green'); |
| 52 |
jQuery('#mainwp-extensions-show-all').removeClass('green'); |
| 53 |
jQuery('#mainwp-extensions-list').find('.card[extension-model="integration"]').fadeIn(200); |
| 54 |
jQuery('#mainwp-extensions-list').find('.card[extension-model="extension"]').fadeOut(200); |
| 55 |
}); |
| 56 |
|
| 57 |
jQuery(document).on('click', '#mainwp-extensions-manage-toggle-on', function () { |
| 58 |
jQuery('#mainwp-manage-add-ons-buttons').hide(); |
| 59 |
jQuery('#mainwp-manage-license-buttons').removeClass('hidden').show(); |
| 60 |
jQuery('#mainwp_com_api_key').focus(); |
| 61 |
return false; |
| 62 |
}); |
| 63 |
|
| 64 |
jQuery(document).on('click', '#mainwp-extensions-manage-toggle-off', function () { |
| 65 |
jQuery('#mainwp-manage-license-buttons').hide(); |
| 66 |
jQuery('#mainwp-manage-add-ons-buttons').show(); |
| 67 |
mainwp_extensions_check_activate_button_state(); |
| 68 |
return false; |
| 69 |
}); |
| 70 |
|
| 71 |
function mainwp_extensions_check_activate_button_state() { |
| 72 |
let api_key = (jQuery('#mainwp_com_api_key').val() || '').trim(); |
| 73 |
if (api_key === '') { |
| 74 |
jQuery('#mainwp-extensions-grabkeys').addClass('disabled').attr('disabled', true); |
| 75 |
} else { |
| 76 |
jQuery('#mainwp-extensions-grabkeys').removeClass('disabled').attr('disabled', false); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
function mainwp_extensions_update_status_header() { |
| 81 |
let api_key = (jQuery('#mainwp_com_api_key').val() || '').trim(); |
| 82 |
let count_enabled = jQuery('#mainwp-extensions-list .card.mainwp-enabled-extension').length; |
| 83 |
let count_not_activated = jQuery('#mainwp-extensions-list .card.mainwp-enabled-extension[license-status="deactivated"]').length; |
| 84 |
let count_activated = count_enabled - count_not_activated; |
| 85 |
let headerHtml = ''; |
| 86 |
|
| 87 |
if (api_key === '') { |
| 88 |
headerHtml = '<h2 class="ui small header">' + |
| 89 |
'<i class="large yellow warning icon"></i>' + |
| 90 |
'<div class="content">' + |
| 91 |
'License Inactive' + |
| 92 |
'<div class="sub header">' + |
| 93 |
count_enabled + ' add-ons enabled • Missing License key • Updates Disabled' + |
| 94 |
'</div>' + |
| 95 |
'</div>' + |
| 96 |
'</h2>'; |
| 97 |
} else if (count_not_activated > 0) { |
| 98 |
let title = count_not_activated === 1 ? |
| 99 |
count_not_activated + ' add-on not activated' : |
| 100 |
count_not_activated + ' add-ons not activated'; |
| 101 |
headerHtml = '<h2 class="ui small header">' + |
| 102 |
'<i class="large yellow warning icon"></i>' + |
| 103 |
'<div class="content">' + |
| 104 |
title + |
| 105 |
'<div class="sub header">' + |
| 106 |
count_enabled + ' add-ons enabled • ' + count_activated + ' activated • Updates enabled for activated add-ons' + |
| 107 |
'</div>' + |
| 108 |
'</div>' + |
| 109 |
'</h2>'; |
| 110 |
} else { |
| 111 |
headerHtml = '<h2 class="ui small header">' + |
| 112 |
'<i class="large green check icon"></i>' + |
| 113 |
'<div class="content">' + |
| 114 |
'License Active' + |
| 115 |
'<div class="sub header">' + |
| 116 |
count_enabled + ' add-ons enabled • All activated • Updates enabled' + |
| 117 |
'</div>' + |
| 118 |
'</div>' + |
| 119 |
'</h2>'; |
| 120 |
} |
| 121 |
|
| 122 |
jQuery('#mainwp-extensions-status-header').html(headerHtml); |
| 123 |
} |
| 124 |
|
| 125 |
// Run a callback after a delay. |
| 126 |
function run_after_delay(callback, delay = 3000) { |
| 127 |
if (typeof callback !== 'function') { |
| 128 |
return; |
| 129 |
} |
| 130 |
setTimeout(callback, delay); |
| 131 |
} |
| 132 |
|
| 133 |
jQuery(document).ready(function () { |
| 134 |
mainwp_extensions_check_activate_button_state(); |
| 135 |
jQuery('#mainwp_com_api_key').on('input', function () { |
| 136 |
mainwp_extensions_check_activate_button_state(); |
| 137 |
}); |
| 138 |
}); |
| 139 |
|
| 140 |
jQuery(document).on('click', '.mainwp-extensions-add-menu', function () { |
| 141 |
let extensionSlug = jQuery(this).parents('.plugin-card').attr('extension_slug'); |
| 142 |
let data = mainwp_secure_data({ |
| 143 |
action: 'mainwp_extension_add_menu', |
| 144 |
slug: extensionSlug |
| 145 |
}); |
| 146 |
|
| 147 |
jQuery.post(ajaxurl, data, function (response) { |
| 148 |
if (response.result == 'SUCCESS') |
| 149 |
location.reload(); |
| 150 |
else if (response.error) { |
| 151 |
alert(response.error); |
| 152 |
} |
| 153 |
}, 'json'); |
| 154 |
|
| 155 |
return false; |
| 156 |
}); |
| 157 |
|
| 158 |
jQuery(document).on('click', '.mainwp-extensions-remove-menu', function () { |
| 159 |
let extensionSlug = jQuery(this).parents('.plugin-card').attr('extension_slug'); |
| 160 |
let data = mainwp_secure_data({ |
| 161 |
action: 'mainwp_extension_remove_menu', |
| 162 |
slug: extensionSlug |
| 163 |
}); |
| 164 |
|
| 165 |
jQuery.post(ajaxurl, data, function (response) { |
| 166 |
if (response.result == 'SUCCESS') |
| 167 |
location.reload(); |
| 168 |
}, 'json'); |
| 169 |
|
| 170 |
return false; |
| 171 |
}); |
| 172 |
|
| 173 |
jQuery(function () { // NOSONAR - levels deep ok. |
| 174 |
jQuery(document).on('click', '.mainwp-manage-extension-license', function () { |
| 175 |
let currentCard = jQuery(this).closest(".card"); |
| 176 |
currentCard.find("#mainwp-extensions-api-form").toggle(); |
| 177 |
if (jQuery(this).attr('api-actived') == '0') { |
| 178 |
extensions_activate_next(currentCard, false); |
| 179 |
} |
| 180 |
return false; |
| 181 |
}); |
| 182 |
|
| 183 |
jQuery(document).on('click', '.extension-privacy-info-link', function () { |
| 184 |
let slug = jQuery(this).attr('base-slug'); |
| 185 |
let title = ''; |
| 186 |
if (jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").length > 0) { |
| 187 |
title = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('extension_title'); |
| 188 |
} else { |
| 189 |
title = jQuery(this).closest('.ui.card').attr('extension-title'); |
| 190 |
} |
| 191 |
let privacy = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('privacy'); |
| 192 |
let integration = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration'); |
| 193 |
let integration_url = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration_url'); |
| 194 |
let integration_owner = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration_owner'); |
| 195 |
let integration_owner_pp = jQuery('#mainwp-extensions-privacy-info').find("input[base-slug='" + slug + "']").attr('integration_owner_pp'); |
| 196 |
|
| 197 |
jQuery('#mainwp-privacy-info-modal').modal({ |
| 198 |
allowMultiple: true, |
| 199 |
onShow: function () { |
| 200 |
jQuery('#mainwp-privacy-info-modal').find('.header').html(title + ' Privacy Info'); |
| 201 |
if (0 == privacy) { |
| 202 |
jQuery('#mainwp-privacy-info-modal').find('.content').html('Standalone Add-on. This Add-on does not use any 3rd party plugins or API\'s to integrate with your Dashboard. This add-on falls under the <a href="https://mainwp.com/mainwp-plugin-privacy-policy/" target="_blank">MainWP Plugin Privacy Policy</a>.'); // NOSONAR - noopener - open safe. |
| 203 |
} else if (1 == privacy) { |
| 204 |
if (slug == 'advanced-uptime-monitor-extension') { |
| 205 |
jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party API.</strong>'); |
| 206 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 207 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="' + integration_url + '" target="_blank">' + integration + '</a>'); |
| 208 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 209 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| 210 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 211 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://betteruptime.com/" target="_blank">Better Uptime API</a>'); |
| 212 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 213 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://betterstack.com/privacy" target="_blank">Better Stack, Inc.</a>'); |
| 214 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 215 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://nodeping.com" target="_blank">NodePing API</a>'); |
| 216 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 217 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://nodeping.com/privacy.html" target="_blank">NodePing LLC</a>'); |
| 218 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 219 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://www.site24x7.com/" target="_blank">Site24x7 API</a>'); |
| 220 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 221 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://www.zoho.com/privacy.html" target="_blank">Zoho Corporation Pvt. Ltd.</a>'); |
| 222 |
} else if (slug == 'mainwp-vulnerability-checker-extension') { |
| 223 |
jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party API.</strong>'); |
| 224 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 225 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="' + integration_url + '" target="_blank">' + integration + '</a>'); |
| 226 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 227 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| 228 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 229 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://nvd.nist.gov/" target="_blank">NVD NIST API</a>'); |
| 230 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 231 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://www.nist.gov/privacy-policy" target="_blank">National Institute of Standards and Technology</a>'); |
| 232 |
} else if (slug == 'mainwp-api-backups-extension') { |
| 233 |
jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party API.</strong>'); |
| 234 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 235 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="' + integration_url + '" target="_blank">' + integration + '</a>'); |
| 236 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 237 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| 238 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 239 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://gridpane.com/" target="_blank">GridPane API</a>'); |
| 240 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 241 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://gridpane.com/privacy/" target="_blank">GridPane Inc.</a>'); |
| 242 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 243 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://www.digitalocean.com/" target="_blank">Digital Ocean API</a>'); |
| 244 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 245 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://www.digitalocean.com/legal/privacy-policy" target="_blank">DigitalOcean, LLC.</a>'); |
| 246 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 247 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://www.linode.com/" target="_blank">Linode API</a>'); |
| 248 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 249 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://www.linode.com/legal-privacy/" target="_blank">Akamai Technologies</a>'); |
| 250 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 251 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://www.vultr.com/" target="_blank">Vultr API</a>'); |
| 252 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 253 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://www.vultr.com/legal/privacy/" target="_blank">Constant Company, LLC.</a>'); |
| 254 |
} else { |
| 255 |
jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party API.</strong>'); |
| 256 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 257 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="' + integration_url + '" target="_blank">' + integration + '</a>'); |
| 258 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 259 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| 260 |
} |
| 261 |
} else if (2 == privacy) { |
| 262 |
jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party Plugin.</strong>'); |
| 263 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 264 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="' + integration_url + '" target="_blank">' + integration + '</a>'); |
| 265 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 266 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="' + integration_owner_pp + '" target="_blank">' + integration_owner + '</a>'); |
| 267 |
} else if (slug == 'mainwp-page-speed-extension') { |
| 268 |
jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>Add-on integrates with a 3rd party Plugin.</strong>'); |
| 269 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<div class="ui hidden divider"></div>'); |
| 270 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Integrates with: <a href="https://wordpress.org/plugins/google-pagespeed-insights/" target="_blank">Insights from Google PageSpeed</a>'); |
| 271 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('<br/>'); |
| 272 |
jQuery('#mainwp-privacy-info-modal').find('.content').append('Owned by: <a href="https://mattkeys.me/" target="_blank">Matt Keys</a>'); |
| 273 |
} else { |
| 274 |
jQuery('#mainwp-privacy-info-modal').find('.content').html('<strong>This add-on is not developed by MainWP. Privacy info is not available.</strong>'); |
| 275 |
} |
| 276 |
}, |
| 277 |
onHide: function () { |
| 278 |
jQuery('#mainwp-privacy-info-modal').find('.header').html(''); |
| 279 |
jQuery('#mainwp-privacy-info-modal').find('.content').html(''); |
| 280 |
}, |
| 281 |
}).modal('show'); |
| 282 |
|
| 283 |
return false; |
| 284 |
}); |
| 285 |
|
| 286 |
jQuery(document).on('click', '.extension-the-plugin-action', function () { // eslint-disable-line unicorn/no-nested-ternary |
| 287 |
let parent = jQuery(this).closest(".card"); |
| 288 |
let slug = jQuery(parent).attr('extension-slug'); |
| 289 |
let loadingEl = parent.find(".action-feedback"); |
| 290 |
let whatAct = jQuery(this).attr("plugin-action"); |
| 291 |
|
| 292 |
let _callback = function () { |
| 293 |
let $btn = jQuery(this); // � |
| 294 |
store correct context |
| 295 |
|
| 296 |
loadingEl.show(); |
| 297 |
|
| 298 |
let msg = MainWP.I18n.t('Disabling add-on...'); |
| 299 |
if (whatAct === 'active') { |
| 300 |
msg = MainWP.I18n.t('Enabling add-on...'); |
| 301 |
} else if (whatAct === 'remove') { |
| 302 |
msg = MainWP.I18n.t('Removing add-on...'); |
| 303 |
} |
| 304 |
|
| 305 |
loadingEl.find('.ui.text.loader').html(msg); |
| 306 |
|
| 307 |
let data = mainwp_secure_data({ |
| 308 |
action: 'mainwp_extension_plugin_action', |
| 309 |
slug: slug, |
| 310 |
what: whatAct, |
| 311 |
}); |
| 312 |
|
| 313 |
function handleAddonResponse(response) { |
| 314 |
$btn.attr('disabled', false); // � |
| 315 |
correct button |
| 316 |
|
| 317 |
if (!response) { |
| 318 |
showError(MainWP.I18n.t('Undefined error')); |
| 319 |
return; |
| 320 |
} |
| 321 |
|
| 322 |
if (response.result === 'SUCCESS') { |
| 323 |
handleSuccess(); |
| 324 |
return; |
| 325 |
} |
| 326 |
|
| 327 |
if (response.error) { |
| 328 |
showError(response.error); |
| 329 |
return; |
| 330 |
} |
| 331 |
|
| 332 |
showError(MainWP.I18n.t('Undefined error')); |
| 333 |
} |
| 334 |
|
| 335 |
function handleSuccess() { |
| 336 |
let msg = MainWP.I18n.t('Add-on disabled'); |
| 337 |
|
| 338 |
if (whatAct === 'active') { |
| 339 |
msg = MainWP.I18n.t('Add-on enabled'); |
| 340 |
} else if (whatAct === 'remove') { |
| 341 |
msg = MainWP.I18n.t('Add-on removed'); |
| 342 |
} |
| 343 |
|
| 344 |
loadingEl.find('.ui.text.loader').html(msg); |
| 345 |
|
| 346 |
run_after_delay(() => { |
| 347 |
mainwp_forceReload('admin.php?page=Extensions'); |
| 348 |
}, 2000); |
| 349 |
} |
| 350 |
|
| 351 |
function showError(message) { |
| 352 |
loadingEl.find('.ui.text.loader').html(message); |
| 353 |
|
| 354 |
run_after_delay(() => { |
| 355 |
loadingEl.hide(); |
| 356 |
}); |
| 357 |
} |
| 358 |
|
| 359 |
$btn.attr('disabled', true); |
| 360 |
|
| 361 |
jQuery.post(ajaxurl, data, handleAddonResponse, 'json'); |
| 362 |
}; |
| 363 |
|
| 364 |
if ('remove' === whatAct) { |
| 365 |
let msg = MainWP.I18n.t('Are you sure you want to remove this add-on?'); |
| 366 |
mainwp_confirm(msg, _callback); |
| 367 |
} else { |
| 368 |
_callback(); |
| 369 |
} |
| 370 |
return false; |
| 371 |
}); |
| 372 |
}); |
| 373 |
|
| 374 |
jQuery(document).on('click', '.mainwp-extensions-activate', function () { |
| 375 |
mainwp_extensions_activate(this, false); |
| 376 |
}); |
| 377 |
|
| 378 |
function mainwp_extensions_activate(pObj, retring) { |
| 379 |
let apiEl = jQuery(pObj).closest(".card"); |
| 380 |
let statusEl = apiEl.find(".activate-api-status"); |
| 381 |
let loadingEl = apiEl.find(".api-feedback"); |
| 382 |
|
| 383 |
loadingEl.hide(); |
| 384 |
|
| 385 |
if (jQuery(pObj).attr('license-status') == 'activated') { |
| 386 |
return; |
| 387 |
} |
| 388 |
|
| 389 |
let data = false; |
| 390 |
|
| 391 |
if (retring) { |
| 392 |
loadingEl.show(); |
| 393 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Connection error detected. The Verify Certificate option has been switched to NO. Retrying...')); |
| 394 |
} else { |
| 395 |
let extensionSlug = jQuery(apiEl).attr('extension-slug'); |
| 396 |
let key = apiEl.find('input[type="text"].extension-api-key').val(); |
| 397 |
let email = apiEl.find('input[type="text"].extension-api-email').val(); |
| 398 |
|
| 399 |
if (key == '') |
| 400 |
return; |
| 401 |
|
| 402 |
data = mainwp_secure_data({ |
| 403 |
action: 'mainwp_extension_api_activate', |
| 404 |
slug: extensionSlug, |
| 405 |
key: key, |
| 406 |
email: email |
| 407 |
}); |
| 408 |
} |
| 409 |
|
| 410 |
loadingEl.show(); |
| 411 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Activating license...')); |
| 412 |
|
| 413 |
jQuery.post(ajaxurl, data, function (response) { |
| 414 |
|
| 415 |
let success = false; |
| 416 |
|
| 417 |
if (response) { |
| 418 |
if (response.result == 'SUCCESS') { |
| 419 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('License activated')); |
| 420 |
statusEl.html('<i class="green key icon"></i> Licensed'); |
| 421 |
success = true; |
| 422 |
} else if (response.error) { |
| 423 |
loadingEl.find('.ui.text.loader').html(response.error); |
| 424 |
} else if (response.retry_action && response.retry_action == 1) { |
| 425 |
jQuery("#mainwp_api_sslVerifyCertificate").val(0); |
| 426 |
mainwp_extensions_activate(pObj, true); |
| 427 |
return false; |
| 428 |
} else { |
| 429 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); |
| 430 |
setTimeout(function () { |
| 431 |
loadingEl.hide(); |
| 432 |
}, 3000); |
| 433 |
} |
| 434 |
} else { |
| 435 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); |
| 436 |
setTimeout(function () { |
| 437 |
loadingEl.hide(); |
| 438 |
}, 3000); |
| 439 |
} |
| 440 |
|
| 441 |
if (success) { |
| 442 |
setTimeout(function () { |
| 443 |
mainwp_forceReload('admin.php?page=Extensions'); |
| 444 |
}, 2000); |
| 445 |
} |
| 446 |
}, 'json'); |
| 447 |
return false; |
| 448 |
} |
| 449 |
|
| 450 |
jQuery(document).on('click', '.mainwp-extension-license-cancel', function () { |
| 451 |
let currentCard = jQuery(this).closest(".card"); |
| 452 |
currentCard.find("#mainwp-extensions-api-form").hide(); |
| 453 |
return false; |
| 454 |
}); |
| 455 |
|
| 456 |
jQuery(document).on('click', '.mainwp-extensions-deactivate', function () { |
| 457 |
let apiEl = jQuery(this).closest(".card"); |
| 458 |
let statusEl = apiEl.find(".activate-api-status"); |
| 459 |
let loadingEl = apiEl.find(".api-feedback"); |
| 460 |
let formEl = apiEl.find("#mainwp-extensions-api-form"); |
| 461 |
|
| 462 |
loadingEl.hide(); |
| 463 |
formEl.hide(); |
| 464 |
|
| 465 |
let extensionSlug = jQuery(apiEl).attr('extension-slug'); |
| 466 |
let extensionApiKey = jQuery(apiEl).find('.extension-api-key').val(); |
| 467 |
let data = mainwp_secure_data({ |
| 468 |
action: 'mainwp_extension_deactivate', |
| 469 |
slug: extensionSlug, |
| 470 |
api_key: extensionApiKey |
| 471 |
}); |
| 472 |
|
| 473 |
loadingEl.show(); |
| 474 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Deactivating license...')); |
| 475 |
|
| 476 |
jQuery.post(ajaxurl, data, function (response) { |
| 477 |
|
| 478 |
if (response) { |
| 479 |
if (response.result == 'SUCCESS') { |
| 480 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('License deactivated')); |
| 481 |
statusEl.html('<i class="red key icon"></i> ' + MainWP.I18n.t('Activate License')); |
| 482 |
statusEl.attr('api-actived', '0'); |
| 483 |
} else if (response.error) { |
| 484 |
loadingEl.find('.ui.text.loader').html(response.error); |
| 485 |
setTimeout(function () { |
| 486 |
loadingEl.hide(); |
| 487 |
}, 3000); |
| 488 |
} else { |
| 489 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); |
| 490 |
setTimeout(function () { |
| 491 |
loadingEl.hide(); |
| 492 |
}, 3000); |
| 493 |
} |
| 494 |
} else { |
| 495 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); |
| 496 |
setTimeout(function () { |
| 497 |
loadingEl.hide(); |
| 498 |
}, 3000); |
| 499 |
} |
| 500 |
|
| 501 |
setTimeout(function () { |
| 502 |
mainwp_forceReload('admin.php?page=Extensions'); |
| 503 |
}, 2000); |
| 504 |
}, 'json'); |
| 505 |
}); |
| 506 |
|
| 507 |
|
| 508 |
// Verify mainwp.com login credentials |
| 509 |
jQuery(document).on('click', '#mainwp-extensions-savelogin', function () { |
| 510 |
let autoTriggerInstall = jQuery(this).attr('data-context') === 'intro-notice'; |
| 511 |
mainwp_extensions_savelogin(false, autoTriggerInstall); |
| 512 |
}); |
| 513 |
|
| 514 |
function mainwp_extensions_savelogin(retring, autoTriggerInstall) { |
| 515 |
let api_key = jQuery('#mainwp_com_api_key').val() || ''; |
| 516 |
let statusEl = jQuery(".mainwp-extensions-api-loading"); |
| 517 |
let data = mainwp_secure_data({ |
| 518 |
action: 'mainwp_extension_saveextensionapilogin', |
| 519 |
api_key: api_key, |
| 520 |
saveLogin: jQuery('#extensions_api_savemylogin_chk').is(':checked') ? 1 : 0 |
| 521 |
}); |
| 522 |
|
| 523 |
if (retring) { |
| 524 |
statusEl.find('.text').html(MainWP.I18n.t("Connection error detected. The Verify Certificate option has been switched to NO. Retrying...")).fadeIn(); |
| 525 |
} else { |
| 526 |
|
| 527 |
statusEl.find('.text').html(MainWP.I18n.t('Validating...')); |
| 528 |
} |
| 529 |
|
| 530 |
statusEl.show(); |
| 531 |
|
| 532 |
jQuery.post(ajaxurl, data, function (response) { // NOSONAR - Complexity. |
| 533 |
let undefError = false; |
| 534 |
let isSuccess = false; |
| 535 |
if (response) { |
| 536 |
if (response.saved) { |
| 537 |
isSuccess = true; |
| 538 |
if (autoTriggerInstall) { |
| 539 |
statusEl.find('.text').html(MainWP.I18n.t('Loading add-ons info...')); |
| 540 |
mainwp_extension_grab_purchased(false); |
| 541 |
} else { |
| 542 |
statusEl.find('.text').html('Your API license key has been successfully saved!'); |
| 543 |
} |
| 544 |
} else if (response.result == 'SUCCESS') { |
| 545 |
isSuccess = true; |
| 546 |
if (autoTriggerInstall) { |
| 547 |
statusEl.find('.text').html(MainWP.I18n.t('Loading add-ons info...')); |
| 548 |
mainwp_extension_grab_purchased(false); |
| 549 |
} else { |
| 550 |
statusEl.find('.text').html('API license key verification successful!'); |
| 551 |
} |
| 552 |
} else if (response.error) { |
| 553 |
statusEl.find('.text').html(response.error); |
| 554 |
} else if (response.retry_action && response.retry_action == 1) { |
| 555 |
jQuery("#mainwp_api_sslVerifyCertificate").val(0); |
| 556 |
statusEl.fadeOut(); |
| 557 |
mainwp_extensions_savelogin(true, autoTriggerInstall); |
| 558 |
return false; |
| 559 |
} else { |
| 560 |
undefError = true; |
| 561 |
} |
| 562 |
} else { |
| 563 |
undefError = true; |
| 564 |
} |
| 565 |
|
| 566 |
if (undefError) { |
| 567 |
statusEl.find('.text').html(MainWP.I18n.t('Undefined error. Please try again.')); |
| 568 |
} |
| 569 |
|
| 570 |
if (!autoTriggerInstall || response.error || undefError) { |
| 571 |
setTimeout(function () { |
| 572 |
statusEl.fadeOut(); |
| 573 |
if (isSuccess) { |
| 574 |
jQuery('#mainwp-manage-license-buttons').hide(); |
| 575 |
jQuery('#mainwp-manage-add-ons-buttons').show(); |
| 576 |
mainwp_extensions_check_activate_button_state(); |
| 577 |
mainwp_extensions_update_status_header(); |
| 578 |
} |
| 579 |
}, 3000); |
| 580 |
} |
| 581 |
|
| 582 |
}, 'json'); |
| 583 |
return false; |
| 584 |
} |
| 585 |
|
| 586 |
let maxActivateThreads = 8; |
| 587 |
let totalActivateThreads = 0; |
| 588 |
let currentActivateThreads = 0; |
| 589 |
let finishedActivateThreads = 0; |
| 590 |
let countSuccessActivation = 0; |
| 591 |
|
| 592 |
// Bulk grab API keys |
| 593 |
jQuery(document).on('click', '#mainwp-extensions-grabkeys', function () { |
| 594 |
totalActivateThreads = jQuery('#mainwp-extensions-list .card[status="queue"]').length; |
| 595 |
if (totalActivateThreads > 0) { |
| 596 |
extensions_loop_next(); |
| 597 |
} |
| 598 |
}); |
| 599 |
|
| 600 |
let extensions_loop_next = function () { |
| 601 |
let extToActivate = jQuery('#mainwp-extensions-list .card[status="queue"]:first'); |
| 602 |
while (extToActivate.length > 0 && currentActivateThreads < maxActivateThreads) { // NOSONAR - variable modified outside the function. |
| 603 |
extensions_activate_next(extToActivate, true); |
| 604 |
extToActivate = jQuery('#mainwp-extensions-list .card[status="queue"]:first'); |
| 605 |
} |
| 606 |
if (finishedActivateThreads == totalActivateThreads) { |
| 607 |
if (countSuccessActivation == totalActivateThreads) { |
| 608 |
setTimeout(function () { |
| 609 |
mainwp_forceReload('admin.php?page=Extensions'); |
| 610 |
}, 2000); |
| 611 |
} else { |
| 612 |
mainwp_extensions_update_status_header(); |
| 613 |
} |
| 614 |
} |
| 615 |
}; |
| 616 |
|
| 617 |
let extensions_activate_next = function (pObj, bulkAct) { |
| 618 |
pObj.attr("status", "running"); |
| 619 |
|
| 620 |
let apiEl = pObj; |
| 621 |
let statusEl = apiEl.find(".activate-api-status"); |
| 622 |
let loadingEl = apiEl.find(".api-feedback"); |
| 623 |
|
| 624 |
let master_api_key = jQuery('#mainwp_com_api_key').val() || ''; |
| 625 |
|
| 626 |
|
| 627 |
let extensionSlug = apiEl.attr('extension-slug'); |
| 628 |
let data = mainwp_secure_data({ |
| 629 |
action: 'mainwp_extension_grabapikey', |
| 630 |
master_api_key: master_api_key, |
| 631 |
slug: extensionSlug |
| 632 |
}); |
| 633 |
|
| 634 |
currentActivateThreads++; |
| 635 |
|
| 636 |
loadingEl.show(); |
| 637 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Activating license...')); |
| 638 |
|
| 639 |
if (apiEl.attr('license-status') == 'activated') { |
| 640 |
finishedActivateThreads++; |
| 641 |
currentActivateThreads--; |
| 642 |
loadingEl.hide(); |
| 643 |
countSuccessActivation++; |
| 644 |
if (bulkAct) { |
| 645 |
extensions_loop_next(); |
| 646 |
} |
| 647 |
return; |
| 648 |
} |
| 649 |
|
| 650 |
jQuery.post(ajaxurl, data, function (response) { |
| 651 |
finishedActivateThreads++; |
| 652 |
currentActivateThreads--; |
| 653 |
|
| 654 |
if (response) { |
| 655 |
if (response.result == 'SUCCESS') { |
| 656 |
countSuccessActivation++; |
| 657 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('License activated')); |
| 658 |
statusEl.html('<i class="green key icon"></i> Licensed'); |
| 659 |
apiEl.attr('license-status', 'activated'); |
| 660 |
loadingEl.hide(); |
| 661 |
if (!bulkAct) { |
| 662 |
setTimeout(function () { |
| 663 |
mainwp_forceReload('admin.php?page=Extensions'); |
| 664 |
}, 2000); |
| 665 |
} |
| 666 |
} else if (response.error) { |
| 667 |
loadingEl.find('.ui.text.loader').html(response.error); |
| 668 |
setTimeout(function () { |
| 669 |
loadingEl.hide(); |
| 670 |
}, 3000); |
| 671 |
} else { |
| 672 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); |
| 673 |
setTimeout(function () { |
| 674 |
loadingEl.hide(); |
| 675 |
}, 3000); |
| 676 |
} |
| 677 |
} else { |
| 678 |
loadingEl.find('.ui.text.loader').html(MainWP.I18n.t('Undefined error')); |
| 679 |
setTimeout(function () { |
| 680 |
loadingEl.hide(); |
| 681 |
}, 3000); |
| 682 |
} |
| 683 |
if (bulkAct) { |
| 684 |
extensions_loop_next(); |
| 685 |
} |
| 686 |
}, 'json'); |
| 687 |
}; |
| 688 |
|
| 689 |
jQuery(document).on('click', '#mainwp-extensions-bulkinstall, #mainwp-extensions-message-bulkinstall', function () { |
| 690 |
let api_key = (jQuery('#mainwp_com_api_key').val() || '').trim(); |
| 691 |
if (api_key == '') { |
| 692 |
mainwp_extension_grab_org_extensions(); |
| 693 |
} else { |
| 694 |
mainwp_extension_grab_purchased(false); |
| 695 |
} |
| 696 |
}) |
| 697 |
|
| 698 |
let mainwp_extension_grab_purchased = function (retring) { |
| 699 |
|
| 700 |
let api_key = (jQuery('#mainwp_com_api_key').val() || '').trim(); |
| 701 |
|
| 702 |
let statusEl = jQuery(".mainwp-extensions-api-loading"); |
| 703 |
let data = mainwp_secure_data({ |
| 704 |
action: 'mainwp_extension_getpurchased', |
| 705 |
api_key: api_key |
| 706 |
}); |
| 707 |
|
| 708 |
|
| 709 |
if (api_key == '') { |
| 710 |
statusEl.find('.text').html(MainWP.I18n.t("Main API Key is required.")); |
| 711 |
statusEl.show(); |
| 712 |
setTimeout(function () { |
| 713 |
statusEl.fadeOut(); |
| 714 |
}, 3000); |
| 715 |
} else if (retring) { |
| 716 |
statusEl.find('.text').html(MainWP.I18n.t("Connection error detected. The Verify Certificate option has been switched to NO. Retrying...")); |
| 717 |
setTimeout(function () { |
| 718 |
statusEl.fadeOut(); |
| 719 |
}, 3000); |
| 720 |
} else { |
| 721 |
statusEl.show(); |
| 722 |
statusEl.find('.text').html(MainWP.I18n.t('Loading add-ons info...')); |
| 723 |
jQuery.post(ajaxurl, data, function (response) { |
| 724 |
let undefError = false; |
| 725 |
if (response) { |
| 726 |
if (response.result == 'SUCCESS') { |
| 727 |
statusEl.hide(); |
| 728 |
jQuery('#mainwp-get-purchased-extensions-modal').modal({ |
| 729 |
allowMultiple: true, |
| 730 |
closable: false, |
| 731 |
onHide: function () { |
| 732 |
mainwp_forceReload('admin.php?page=Extensions'); |
| 733 |
} |
| 734 |
}).modal('show'); |
| 735 |
jQuery('#mainwp-get-purchased-extensions-modal').find('.content').html(response.data); |
| 736 |
if (jQuery('#extension_install_ext_slug').length > 0) { |
| 737 |
mainwp_extension_select_to_install(); |
| 738 |
} |
| 739 |
} else if (response.error) { |
| 740 |
statusEl.find('.text').html(response.error); |
| 741 |
} else if (response.retry_action && response.retry_action == 1) { |
| 742 |
jQuery("#mainwp_api_sslVerifyCertificate").val(0); |
| 743 |
statusEl.fadeOut(); |
| 744 |
mainwp_extension_grab_purchased(true); |
| 745 |
return false; |
| 746 |
} else { |
| 747 |
undefError = true; |
| 748 |
} |
| 749 |
} else { |
| 750 |
undefError = true; |
| 751 |
} |
| 752 |
if (undefError) { |
| 753 |
statusEl.find('.text').html(MainWP.I18n.t('Undefined error occurred. Please try again.')); |
| 754 |
} |
| 755 |
setTimeout(function () { |
| 756 |
statusEl.fadeOut(); |
| 757 |
}, 3000); |
| 758 |
}, 'json'); |
| 759 |
} |
| 760 |
return false; |
| 761 |
} |
| 762 |
|
| 763 |
let mainwp_extension_select_to_install = function () { |
| 764 |
let inst_ext = jQuery('.item.extension[slug="' + jQuery('#extension_install_ext_slug').val() + '"]'); |
| 765 |
if (jQuery(inst_ext).length > 0) { |
| 766 |
jQuery('mainwp-installing-extensions .ui.tab').removeClass('active'); |
| 767 |
let curtab = jQuery(inst_ext[0]).closest('.ui.tab').attr('data-tab'); |
| 768 |
jQuery('#mainwp-install-extensions-menu .item[data-tab=' + curtab + ']').trigger('click'); |
| 769 |
let install_chk = jQuery(inst_ext).find('input[type=checkbox]'); |
| 770 |
if (install_chk.length > 0) { |
| 771 |
jQuery(install_chk[0]).trigger('click'); |
| 772 |
} |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
let mainwp_extension_grab_org_extensions = function () { |
| 777 |
|
| 778 |
let statusEl = jQuery(".mainwp-extensions-api-loading"); |
| 779 |
let data = mainwp_secure_data({ |
| 780 |
action: 'mainwp_extension_getpurchased', |
| 781 |
}); |
| 782 |
|
| 783 |
statusEl.removeClass('green'); |
| 784 |
statusEl.removeClass('yellow'); |
| 785 |
statusEl.show(); |
| 786 |
statusEl.find('.text').html(MainWP.I18n.t('Running. Please wait...')); |
| 787 |
jQuery.post(ajaxurl, data, function (response) { |
| 788 |
let undefError = false; |
| 789 |
if (response) { |
| 790 |
if (response.result == 'SUCCESS') { |
| 791 |
jQuery('#mainwp-get-purchased-extensions-modal').modal({ |
| 792 |
allowMultiple: true, |
| 793 |
closable: false, |
| 794 |
onHide: function () { |
| 795 |
mainwp_forceReload('admin.php?page=Extensions'); |
| 796 |
} |
| 797 |
}).modal('show'); |
| 798 |
jQuery('#mainwp-get-purchased-extensions-modal').find('.content').html(response.data); |
| 799 |
if (jQuery('#extension_install_ext_slug').length > 0) { |
| 800 |
mainwp_extension_select_to_install(); |
| 801 |
} |
| 802 |
statusEl.hide(); |
| 803 |
} else if (response.error) { |
| 804 |
statusEl.addClass('red'); |
| 805 |
statusEl.find('.text').html(response.error).fadeIn(); |
| 806 |
} else { |
| 807 |
undefError = true; |
| 808 |
} |
| 809 |
} else { |
| 810 |
undefError = true; |
| 811 |
} |
| 812 |
|
| 813 |
if (undefError) { |
| 814 |
statusEl.addClass('red'); |
| 815 |
statusEl.find('.text').html(MainWP.I18n.t('Undefined error. Please try again.')).fadeIn(); |
| 816 |
} |
| 817 |
setTimeout(function () { |
| 818 |
statusEl.fadeOut(); |
| 819 |
}, 3000); |
| 820 |
}, 'json'); |
| 821 |
|
| 822 |
return false; |
| 823 |
} |
| 824 |
|
| 825 |
|
| 826 |
jQuery(document).on('click', '#mainwp-extensions-installnow', function () { |
| 827 |
mainwp_extension_bulk_install(); |
| 828 |
return false; |
| 829 |
}) |
| 830 |
|
| 831 |
let bulkExtensionsMaxThreads = mainwpParams['maximumInstallUpdateRequests'] == undefined ? 3 : mainwpParams['maximumInstallUpdateRequests']; |
| 832 |
let bulkExtensionsCurrentThreads = 0; |
| 833 |
let bulkExtensionsTotal = 0; |
| 834 |
let bulkExtensionsFinished = 0; |
| 835 |
let bulkExtensionsRunning = false; |
| 836 |
|
| 837 |
let mainwp_extension_bulk_install = function () { |
| 838 |
if (bulkExtensionsRunning) |
| 839 |
return; |
| 840 |
|
| 841 |
jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:not(:checked)').closest('.extension-to-install').find('.installing-extension[status="queue"]').html('<span data-tooltip="Skipped" data-position="left center" data-inverted=""><i class="ban grey icon"></i></span>'); |
| 842 |
|
| 843 |
bulkExtensionsTotal = jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:checked').length; |
| 844 |
|
| 845 |
if (bulkExtensionsTotal == 0) |
| 846 |
return false; |
| 847 |
|
| 848 |
jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:checked').closest('.extension-to-install').find('.installing-extension[status="queue"]').html('<i class="clock outline icon"></i> ' + MainWP.I18n.t('Queued')); |
| 849 |
|
| 850 |
mainwp_extension_bulk_install_next(); |
| 851 |
} |
| 852 |
|
| 853 |
let mainwp_extension_bulk_install_next = function () { |
| 854 |
while ((extToInstall = jQuery('.mainwp-installing-extensions input[type="checkbox"][status="queue"]:checked:first').closest('.extension-to-install')) && (extToInstall.length > 0) && (bulkExtensionsCurrentThreads < bulkExtensionsMaxThreads)) { // NOSONAR -- modified out side the function. |
| 855 |
mainwp_extension_bulk_install_specific(extToInstall); |
| 856 |
} |
| 857 |
|
| 858 |
if ((bulkExtensionsTotal > 0) && (bulkExtensionsFinished == bulkExtensionsTotal)) { // NOSONAR -- modified out side the function. |
| 859 |
mainwp_extension_bulk_activate(); |
| 860 |
} |
| 861 |
} |
| 862 |
|
| 863 |
let mainwp_extension_bulk_install_specific = function (pExtToInstall) { |
| 864 |
bulkExtensionsRunning = true; |
| 865 |
pExtToInstall.find('input[type="checkbox"]').attr('status', 'running'); |
| 866 |
bulkExtensionsCurrentThreads++; |
| 867 |
|
| 868 |
let statusEl = pExtToInstall.find('.installing-extension'); |
| 869 |
|
| 870 |
statusEl.html('<span data-tooltip="Installing add-on. Please wait..." data-position="left center" data-inverted=""><i class="notched circle loading icon"></i></span>'); |
| 871 |
|
| 872 |
let data = mainwp_secure_data({ |
| 873 |
action: 'mainwp_extension_downloadandinstall', |
| 874 |
download_link: pExtToInstall.attr('download-link'), |
| 875 |
plugin_slug: pExtToInstall.attr('plugin-slug') |
| 876 |
}); |
| 877 |
|
| 878 |
jQuery.ajax({ |
| 879 |
type: 'POST', |
| 880 |
url: ajaxurl, |
| 881 |
data: data, |
| 882 |
success: function () { |
| 883 |
return function (res_data) { |
| 884 |
bulkExtensionsCurrentThreads--; |
| 885 |
bulkExtensionsFinished++; |
| 886 |
|
| 887 |
statusEl.html(''); |
| 888 |
|
| 889 |
let matches = res_data.match('<mainwp>(.*)</mainwp>'); |
| 890 |
let response = ''; |
| 891 |
|
| 892 |
if (matches) { |
| 893 |
let response_json = matches[1]; |
| 894 |
response = JSON.parse(response_json); |
| 895 |
} |
| 896 |
|
| 897 |
if (response == '') { |
| 898 |
statusEl.html('<span data-tooltip="Undefined error occurred. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>'); |
| 899 |
} else if (response.result == 'SUCCESS') { |
| 900 |
statusEl.html('<span data-tooltip="' + response.output + '" data-inverted="" data-position="left center"><i class="check green icon"></i></span>'); |
| 901 |
jQuery('.mainwp-installing-extensions').append('<span class="extension-installed-success" slug="' + response.slug + '"></span>') |
| 902 |
} else if (response.error) { |
| 903 |
statusEl.html('<span data-tooltip="' + response.error + '" data-inverted="" data-position="left center"><i class="times red icon"></i></span>'); |
| 904 |
} else { |
| 905 |
statusEl.html('<span data-tooltip="Undefined error occurred. Please try again." data-inverted="" data-position="left center"><i class="times red icon"></i></span>'); |
| 906 |
} |
| 907 |
|
| 908 |
mainwp_extension_bulk_install_next(); |
| 909 |
} |
| 910 |
}() |
| 911 |
}); |
| 912 |
|
| 913 |
return false; |
| 914 |
} |
| 915 |
|
| 916 |
let mainwp_extension_bulk_activate = function () { |
| 917 |
let plugins = []; |
| 918 |
|
| 919 |
jQuery('.extension-installed-success').each(function () { |
| 920 |
plugins.push(jQuery(this).attr('slug')); |
| 921 |
}); |
| 922 |
|
| 923 |
if (plugins.length == 0) { |
| 924 |
mainwp_extension_bulk_install_done(); |
| 925 |
return; |
| 926 |
} |
| 927 |
|
| 928 |
let data = mainwp_secure_data({ |
| 929 |
action: 'mainwp_extension_bulk_activate', |
| 930 |
plugins: plugins |
| 931 |
}); |
| 932 |
|
| 933 |
let statusEl = jQuery('#mainwp-bulk-activating-extensions-status'); |
| 934 |
|
| 935 |
statusEl.html('<i class="notched circle loading icon"></i>' + MainWP.I18n.t('Activating add-ons. Please wait...')).show(); |
| 936 |
jQuery.post(ajaxurl, data, function (response) { |
| 937 |
statusEl.html(''); |
| 938 |
if (response == 'SUCCESS') { |
| 939 |
statusEl.addClass('green'); |
| 940 |
statusEl.html(MainWP.I18n.t('Add-ons have been activated successfully!')); |
| 941 |
statusEl.fadeOut(3000); |
| 942 |
} |
| 943 |
mainwp_extension_bulk_install_done(); |
| 944 |
}); |
| 945 |
} |
| 946 |
|
| 947 |
let mainwp_extension_bulk_install_done = function () { |
| 948 |
bulkExtensionsRunning = false; |
| 949 |
|
| 950 |
let statusEl = jQuery('#mainwp-bulk-activating-extensions-status'); |
| 951 |
|
| 952 |
statusEl.addClass('green'); |
| 953 |
statusEl.html(MainWP.I18n.t("Installation completed successfully. Page will reload automatically in 3 seconds.")).show(); |
| 954 |
if (jQuery('.extension-installed-success').length == bulkExtensionsFinished) { |
| 955 |
setTimeout(function () { |
| 956 |
mainwp_forceReload('admin.php?page=Extensions'); |
| 957 |
}, 3000); |
| 958 |
} |
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
// Is this function still in use??? |
| 963 |
jQuery(document).on('click', '#mainwp-extensions-api-sslverify-certificate', function () { |
| 964 |
|
| 965 |
let parent = jQuery(this).closest(".extension_api_sslverify_loading"); |
| 966 |
let statusEl = parent.find('span.status'); |
| 967 |
let loadingEl = parent.find("i"); |
| 968 |
|
| 969 |
let data = mainwp_secure_data({ |
| 970 |
action: 'mainwp_extension_apisslverifycertificate', |
| 971 |
api_sslverify: jQuery("#mainwp_api_sslVerifyCertificate").val() |
| 972 |
}); |
| 973 |
|
| 974 |
statusEl.hide(); |
| 975 |
loadingEl.show(); |
| 976 |
jQuery.post(ajaxurl, data, function (response) { |
| 977 |
loadingEl.hide(); |
| 978 |
let undefError = false; |
| 979 |
if (response) { |
| 980 |
if (response.saved) { |
| 981 |
statusEl.css('color', '#0074a2'); |
| 982 |
statusEl.html('MainWP Main API Key saved!').fadeIn(); |
| 983 |
setTimeout(function () { |
| 984 |
statusEl.fadeOut(); |
| 985 |
}, 3000); |
| 986 |
} else if (response.error) { |
| 987 |
statusEl.css('color', 'red'); |
| 988 |
statusEl.html(response.error).fadeIn(); |
| 989 |
} else { |
| 990 |
undefError = true; |
| 991 |
} |
| 992 |
} else { |
| 993 |
undefError = true; |
| 994 |
} |
| 995 |
|
| 996 |
if (undefError) { |
| 997 |
statusEl.css('color', 'red'); |
| 998 |
statusEl.html('<i class="exclamation circle icon"></i> Undefined error').fadeIn(); |
| 999 |
} |
| 1000 |
}, 'json'); |
| 1001 |
return false; |
| 1002 |
}); |
| 1003 |
|
| 1004 |
jQuery(function ($) { |
| 1005 |
jQuery(document).on('click', '#mainwp-check-all-sync-ext', function () { |
| 1006 |
$('.sync-ext-row').find("input:checkbox").each(function () { |
| 1007 |
$(this).attr('checked', true); |
| 1008 |
}); |
| 1009 |
}); |
| 1010 |
jQuery(document).on('click', '#mainwp-uncheck-all-sync-ext', function () { |
| 1011 |
$('.sync-ext-row').find("input:checkbox").each(function () { |
| 1012 |
$(this).attr('checked', false); |
| 1013 |
}); |
| 1014 |
}); |
| 1015 |
|
| 1016 |
jQuery(document).on('click', '.mainwp-show-extensions', function () { |
| 1017 |
$('a.mainwp-show-extensions').removeClass('mainwp_action_down'); |
| 1018 |
$(this).addClass('mainwp_action_down'); |
| 1019 |
|
| 1020 |
let gr = $(this).attr('group'); |
| 1021 |
let selectedEl = $('#mainwp-available-extensions-list .mainwp-availbale-extension-holder.group-' + gr); |
| 1022 |
let installedGroup = $('.installed-group-exts'); |
| 1023 |
installedGroup.hide(); |
| 1024 |
|
| 1025 |
if (gr == 'all') { |
| 1026 |
$('#mainwp-available-extensions-list .mainwp-availbale-extension-holder').fadeIn(500); |
| 1027 |
} else { |
| 1028 |
$('#mainwp-available-extensions-list .mainwp-availbale-extension-holder').hide(); |
| 1029 |
if (selectedEl.length > 0) { |
| 1030 |
selectedEl.fadeIn(500); |
| 1031 |
} else { |
| 1032 |
installedGroup.fadeIn(500); |
| 1033 |
} |
| 1034 |
} |
| 1035 |
|
| 1036 |
return false; |
| 1037 |
}); |
| 1038 |
}); |
| 1039 |
|