| 1 |
/* eslint complexity: ["error", 100] */ |
| 2 |
// current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 3 |
|
| 4 |
jQuery(document).ready(function ($) { |
| 5 |
|
| 6 |
// review for new UI update |
| 7 |
jQuery(document).on('click', '#mainwp-category-add-submit', function () { |
| 8 |
var newCat = jQuery('#newcategory').val(); |
| 9 |
if (jQuery('#categorychecklist').find('option[value="' + encodeURIComponent(newCat) + '"]').length > 0) |
| 10 |
return; |
| 11 |
jQuery('#categorychecklist').append('<option value="' + encodeURIComponent(newCat) + '">' + newCat + '</option>'); |
| 12 |
jQuery('#category-adder').addClass('wp-hidden-children'); |
| 13 |
jQuery('#newcategory').val(''); |
| 14 |
}); |
| 15 |
|
| 16 |
// Show/Hide new category field and button |
| 17 |
jQuery('#category-add-toggle').on('click', function () { |
| 18 |
jQuery('#newcategory-field').toggle(); |
| 19 |
jQuery('#mainwp-category-add-submit-field').toggle(); |
| 20 |
return false; |
| 21 |
}); |
| 22 |
|
| 23 |
// Manage Child options |
| 24 |
$('.mainwp-parent-toggle input[type="checkbox"]').change(function () { |
| 25 |
if (this.checked) { |
| 26 |
$(this).closest('.mainwp-parent-toggle').next('.mainwp-child-field').fadeIn(); |
| 27 |
} else { |
| 28 |
$(this).closest('.mainwp-parent-toggle').next('.mainwp-child-field').fadeOut(); |
| 29 |
} |
| 30 |
}); |
| 31 |
|
| 32 |
//Toggle Add Site form |
| 33 |
jQuery('#mainwp_managesites_verify_installed_child').change(function () { |
| 34 |
if (jQuery(this).is(':checked')) { |
| 35 |
jQuery('#mainwp-add-site-hidden-form').fadeIn(500); |
| 36 |
} else { |
| 37 |
jQuery('#mainwp-add-site-hidden-form').fadeOut(500); |
| 38 |
} |
| 39 |
}); |
| 40 |
|
| 41 |
// Toggle Add Site / Optional Settings section |
| 42 |
jQuery('#mainwp-add-site-advanced-options-toggle').on('click', function () { |
| 43 |
jQuery('#mainwp-add-site-advanced-options').toggle(500); |
| 44 |
return false; |
| 45 |
}); |
| 46 |
|
| 47 |
jQuery('.mainwp-remove-site-button').on('click', function () { |
| 48 |
var side_id = jQuery(this).attr('site-id'); |
| 49 |
var confirmation = "Are you sure you want to remove this site from your MainWP Dashboard?"; |
| 50 |
mainwp_confirm(confirmation, function () { |
| 51 |
|
| 52 |
feedback('mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + __('Removing the site. Please wait...', 'mainwp'), ''); |
| 53 |
|
| 54 |
var data = mainwp_secure_data({ |
| 55 |
action: 'mainwp_removesite', |
| 56 |
id: side_id |
| 57 |
}); |
| 58 |
|
| 59 |
jQuery.post(ajaxurl, data, function (response) { |
| 60 |
|
| 61 |
var error = false; |
| 62 |
|
| 63 |
if (response.error != undefined) { |
| 64 |
error = response.error; |
| 65 |
} else if (response.result == 'SUCCESS') { |
| 66 |
feedback('mainwp-message-zone', __('The site has been removed and the MainWP Child plugin has been disabled. You will be redirected to the Sites page right away.', 'mainwp'), 'green'); |
| 67 |
} else if (response.result == 'NOSITE') { |
| 68 |
feedback('mainwp-message-zone', __('Site could not be removed. Please reload the page and try again.', 'mainwp'), 'red'); |
| 69 |
error = true; |
| 70 |
} else { |
| 71 |
feedback('mainwp-message-zone', __('The site has been removed. Please make sure that the MainWP Child plugin has been deactivated properly. You will be redirected to the Sites page right away.', 'mainwp'), 'green'); |
| 72 |
} |
| 73 |
|
| 74 |
if (error == false) { |
| 75 |
setTimeout(function () { |
| 76 |
window.location = 'admin.php?page=managesites'; |
| 77 |
}, 3000); |
| 78 |
} |
| 79 |
|
| 80 |
}, 'json'); |
| 81 |
}, false, false, false, 'REMOVE'); |
| 82 |
|
| 83 |
return false; |
| 84 |
}); |
| 85 |
|
| 86 |
}); |
| 87 |
|
| 88 |
/** |
| 89 |
* Global |
| 90 |
*/ |
| 91 |
jQuery(document).ready(function () { |
| 92 |
jQuery('.mainwp-row').on({ |
| 93 |
mouseenter: function () { |
| 94 |
rowMouseEnter(this); |
| 95 |
}, |
| 96 |
mouseleave: function () { |
| 97 |
rowMouseLeave(this); |
| 98 |
} |
| 99 |
}); |
| 100 |
}); |
| 101 |
rowMouseEnter = function (elem) { |
| 102 |
if (!jQuery(elem).children('.mainwp-row-actions-working').is(":visible")) |
| 103 |
jQuery(elem).children('.mainwp-row-actions').show(); |
| 104 |
}; |
| 105 |
rowMouseLeave = function (elem) { |
| 106 |
if (jQuery(elem).children('.mainwp-row-actions').is(":visible")) |
| 107 |
jQuery(elem).children('.mainwp-row-actions').hide(); |
| 108 |
}; |
| 109 |
|
| 110 |
|
| 111 |
mainwp_sidebar_position_onchange = function (me) { |
| 112 |
jQuery(me).closest("form").submit(); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Recent posts |
| 117 |
*/ |
| 118 |
jQuery(document).ready(function () { |
| 119 |
jQuery(document).on('click', '.mainwp-post-unpublish', function () { |
| 120 |
postAction(jQuery(this), 'unpublish'); |
| 121 |
return false; |
| 122 |
}); |
| 123 |
jQuery(document).on('click', '.mainwp-post-publish', function () { |
| 124 |
postAction(jQuery(this), 'publish'); |
| 125 |
return false; |
| 126 |
}); |
| 127 |
jQuery(document).on('click', '.mainwp-post-trash', function () { |
| 128 |
postAction(jQuery(this), 'trash'); |
| 129 |
return false; |
| 130 |
}); |
| 131 |
jQuery(document).on('click', '.mainwp-post-restore', function () { |
| 132 |
postAction(jQuery(this), 'restore'); |
| 133 |
return false; |
| 134 |
}); |
| 135 |
jQuery(document).on('click', '.mainwp-post-delete', function () { |
| 136 |
postAction(jQuery(this), 'delete'); |
| 137 |
return false; |
| 138 |
}); |
| 139 |
|
| 140 |
}); |
| 141 |
|
| 142 |
// Publish, Unpublish, Trash, ... posts and pages |
| 143 |
postAction = function (elem, what) { |
| 144 |
var rowElement = jQuery(elem).closest('.grid'); |
| 145 |
var postId = rowElement.children('.postId').val(); |
| 146 |
var websiteId = rowElement.children('.websiteId').val(); |
| 147 |
|
| 148 |
var data = mainwp_secure_data({ |
| 149 |
action: 'mainwp_post_' + what, |
| 150 |
postId: postId, |
| 151 |
websiteId: websiteId |
| 152 |
}); |
| 153 |
rowElement.hide(); |
| 154 |
rowElement.next('.mainwp-row-actions-working').show(); |
| 155 |
jQuery.post(ajaxurl, data, function (response) { |
| 156 |
if (response.error) { |
| 157 |
rowElement.show(); |
| 158 |
rowElement.next('.mainwp-row-actions-working').hide(); |
| 159 |
rowElement.html('<div class="sixteen wide column"><i class="times circle red icon"></i> ' + response.error + '</div>'); |
| 160 |
} else if (response.result) { |
| 161 |
rowElement.show(); |
| 162 |
rowElement.next('.mainwp-row-actions-working').hide(); |
| 163 |
rowElement.html('<div class="sixteen wide column"><i class="check circle green icon"></i>' + response.result + '</div>'); |
| 164 |
} else { |
| 165 |
rowElement.show(); |
| 166 |
rowElement.next('.mainwp-row-actions-working').hide(); |
| 167 |
} |
| 168 |
}, 'json'); |
| 169 |
return false; |
| 170 |
}; |
| 171 |
|
| 172 |
|
| 173 |
mainwp_post_posting_start_next = function (start) { |
| 174 |
if (typeof start !== "undefined" && start) { |
| 175 |
bulkInstallDone = 0; |
| 176 |
bulkInstallCurrentThreads = 0; |
| 177 |
bulkInstallTotal = jQuery('.site-bulk-posting[status="queue"]').length; |
| 178 |
} |
| 179 |
while ((siteToPosting = jQuery('.site-bulk-posting[status="queue"]:first')) && (siteToPosting.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { |
| 180 |
mainwp_post_posting_start_specific(siteToPosting); |
| 181 |
} |
| 182 |
}; |
| 183 |
|
| 184 |
mainwp_post_posting_start_specific = function (siteToPosting) { |
| 185 |
siteToPosting.attr('status', 'progress'); |
| 186 |
bulkInstallDone++; |
| 187 |
bulkInstallCurrentThreads++; |
| 188 |
var data = mainwp_secure_data({ |
| 189 |
action: 'mainwp_post_postingbulk', |
| 190 |
post_id: jQuery('#bulk_posting_id').val(), |
| 191 |
site_id: jQuery(siteToPosting).attr('site-id'), |
| 192 |
count: bulkInstallDone, |
| 193 |
total: bulkInstallTotal, |
| 194 |
delete_bulkpost: (bulkInstallDone == bulkInstallTotal) ? true : false |
| 195 |
}); |
| 196 |
siteToPosting.find('.progress').html('<i class="notched circle loading icon"></i>'); |
| 197 |
jQuery.post(ajaxurl, data, function (response) { |
| 198 |
bulkInstallCurrentThreads--; |
| 199 |
if (response && response.result) { |
| 200 |
siteToPosting.find('.progress').html(response.result); |
| 201 |
if (response.edit_link !== '') { |
| 202 |
siteToPosting.after(response.edit_link); |
| 203 |
} |
| 204 |
} |
| 205 |
mainwp_post_posting_start_next(); |
| 206 |
}, 'json'); |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
/** |
| 211 |
* Plugins Widget |
| 212 |
*/ |
| 213 |
jQuery(document).ready(function () { |
| 214 |
jQuery(document).on('click', '.mainwp-plugin-deactivate', function () { |
| 215 |
pluginAction(jQuery(this), 'deactivate'); |
| 216 |
return false; |
| 217 |
}); |
| 218 |
jQuery(document).on('click', '.mainwp-plugin-activate', function () { |
| 219 |
pluginAction(jQuery(this), 'activate'); |
| 220 |
return false; |
| 221 |
}); |
| 222 |
jQuery(document).on('click', '.mainwp-plugin-delete', function () { |
| 223 |
pluginAction(jQuery(this), 'delete'); |
| 224 |
return false; |
| 225 |
}); |
| 226 |
}); |
| 227 |
|
| 228 |
pluginAction = function (elem, what) { |
| 229 |
var rowElement = jQuery(elem).parent().parent(); |
| 230 |
var plugin = rowElement.children('.pluginSlug').val(); |
| 231 |
var websiteId = rowElement.children('.websiteId').val(); |
| 232 |
|
| 233 |
var data = mainwp_secure_data({ |
| 234 |
action: 'mainwp_widget_plugin_' + what, |
| 235 |
plugin: plugin, |
| 236 |
websiteId: websiteId |
| 237 |
}); |
| 238 |
rowElement.children().hide(); |
| 239 |
rowElement.children('.mainwp-row-actions-working').show(); |
| 240 |
jQuery.post(ajaxurl, data, function (response) { |
| 241 |
if (response && response.error) { |
| 242 |
rowElement.children().show(); |
| 243 |
rowElement.html(response.error); |
| 244 |
} else if (response && response.result) { |
| 245 |
rowElement.children().show(); |
| 246 |
rowElement.html(response.result); |
| 247 |
} else { |
| 248 |
rowElement.children('.mainwp-row-actions-working').hide(); |
| 249 |
} |
| 250 |
}, 'json'); |
| 251 |
|
| 252 |
return false; |
| 253 |
}; |
| 254 |
|
| 255 |
/** |
| 256 |
* Themes Widget |
| 257 |
*/ |
| 258 |
jQuery(document).ready(function () { |
| 259 |
jQuery(document).on('click', '.mainwp-theme-activate', function () { |
| 260 |
themeAction(jQuery(this), 'activate'); |
| 261 |
return false; |
| 262 |
}); |
| 263 |
jQuery(document).on('click', '.mainwp-theme-delete', function () { |
| 264 |
themeAction(jQuery(this), 'delete'); |
| 265 |
return false; |
| 266 |
}); |
| 267 |
}); |
| 268 |
|
| 269 |
themeAction = function (elem, what) { |
| 270 |
var rowElement = jQuery(elem).parent().parent(); |
| 271 |
var theme = rowElement.children('.themeSlug').val(); |
| 272 |
var websiteId = rowElement.children('.websiteId').val(); |
| 273 |
|
| 274 |
var data = mainwp_secure_data({ |
| 275 |
action: 'mainwp_widget_theme_' + what, |
| 276 |
theme: theme, |
| 277 |
websiteId: websiteId |
| 278 |
}); |
| 279 |
rowElement.children().hide(); |
| 280 |
rowElement.children('.mainwp-row-actions-working').show(); |
| 281 |
jQuery.post(ajaxurl, data, function (response) { |
| 282 |
if (response && response.error) { |
| 283 |
rowElement.children().show(); |
| 284 |
rowElement.html(response.error); |
| 285 |
} else if (response && response.result) { |
| 286 |
rowElement.children().show(); |
| 287 |
rowElement.html(response.result); |
| 288 |
} else { |
| 289 |
rowElement.children('.mainwp-row-actions-working').hide(); |
| 290 |
} |
| 291 |
}, 'json'); |
| 292 |
|
| 293 |
return false; |
| 294 |
}; |
| 295 |
|
| 296 |
// offsetRelative (or, if you prefer, positionRelative) |
| 297 |
(function ($) { |
| 298 |
$.fn.offsetRelative = function (top) { |
| 299 |
var $this = $(this); |
| 300 |
var $parent = $this.offsetParent(); |
| 301 |
var offset = $this.position(); |
| 302 |
if (!top) |
| 303 |
return offset; // Didn't pass a 'top' element |
| 304 |
else if ($parent.get(0).tagName == "BODY") |
| 305 |
return offset; // Reached top of document |
| 306 |
else if ($(top, $parent).length) |
| 307 |
return offset; // Parent element contains the 'top' element we want the offset to be relative to |
| 308 |
else if ($parent[0] == $(top)[0]) |
| 309 |
return offset; // Reached the 'top' element we want the offset to be relative to |
| 310 |
else { // Get parent's relative offset |
| 311 |
var parent_offset = $parent.offsetRelative(top); |
| 312 |
offset.top += parent_offset.top; |
| 313 |
offset.left += parent_offset.left; |
| 314 |
return offset; |
| 315 |
} |
| 316 |
}; |
| 317 |
$.fn.positionRelative = function (top) { |
| 318 |
return $(this).offsetRelative(top); |
| 319 |
}; |
| 320 |
}(jQuery)); |
| 321 |
|
| 322 |
var hidingSubMenuTimers = {}; |
| 323 |
jQuery(document).ready(function () { |
| 324 |
jQuery('span[id^=mainwp]').each(function () { |
| 325 |
jQuery(this).parent().parent().hover(function () { |
| 326 |
var spanEl = jQuery(this).find('span[id^=mainwp]'); |
| 327 |
var spanId = /^mainwp-(.*)$/.exec(spanEl.attr('id')); |
| 328 |
if (spanId) { |
| 329 |
if (hidingSubMenuTimers[spanId[1]]) { |
| 330 |
clearTimeout(hidingSubMenuTimers[spanId[1]]); |
| 331 |
} |
| 332 |
var currentMenu = jQuery('#menu-mainwp-' + spanId[1]); |
| 333 |
var offsetVal = jQuery(this).offset(); |
| 334 |
currentMenu.css('left', offsetVal.left + jQuery(this).outerWidth() - 30); |
| 335 |
|
| 336 |
currentMenu.css('top', offsetVal.top - 15 - jQuery(this).outerHeight()); // + tmp); |
| 337 |
subMenuIn(spanId[1]); |
| 338 |
} |
| 339 |
}, function () { |
| 340 |
var spanEl = jQuery(this).find('span[id^=mainwp]'); |
| 341 |
var spanId = /^mainwp-(.*)$/.exec(spanEl.attr('id')); |
| 342 |
if (spanId) { |
| 343 |
hidingSubMenuTimers[spanId[1]] = setTimeout(function (span) { |
| 344 |
return function () { |
| 345 |
subMenuOut(span); |
| 346 |
}; |
| 347 |
}(spanId[1]), 30); |
| 348 |
} |
| 349 |
}); |
| 350 |
}); |
| 351 |
jQuery('.mainwp-submenu-wrapper').on({ |
| 352 |
mouseenter: function () { |
| 353 |
var spanId = /^menu-mainwp-(.*)$/.exec(jQuery(this).attr('id')); |
| 354 |
if (spanId) { |
| 355 |
if (hidingSubMenuTimers[spanId[1]]) { |
| 356 |
clearTimeout(hidingSubMenuTimers[spanId[1]]); |
| 357 |
} |
| 358 |
} |
| 359 |
}, |
| 360 |
mouseleave: function () { |
| 361 |
var spanId = /^menu-mainwp-(.*)$/.exec(jQuery(this).attr('id')); |
| 362 |
if (spanId) { |
| 363 |
hidingSubMenuTimers[spanId[1]] = setTimeout(function (span) { |
| 364 |
return function () { |
| 365 |
subMenuOut(span); |
| 366 |
}; |
| 367 |
}(spanId[1]), 30); |
| 368 |
} |
| 369 |
} |
| 370 |
}); |
| 371 |
}); |
| 372 |
subMenuIn = function (subName) { |
| 373 |
jQuery('#menu-mainwp-' + subName).show(); |
| 374 |
jQuery('#mainwp-' + subName).parent().parent().addClass('hoverli'); |
| 375 |
jQuery('#mainwp-' + subName).parent().parent().css('background-color', '#EAF2FA'); |
| 376 |
jQuery('#mainwp-' + subName).css('color', '#333'); |
| 377 |
}; |
| 378 |
subMenuOut = function (subName) { |
| 379 |
jQuery('#menu-mainwp-' + subName).hide(); |
| 380 |
jQuery('#mainwp-' + subName).parent().parent().css('background-color', ''); |
| 381 |
jQuery('#mainwp-' + subName).parent().parent().removeClass('hoverli'); |
| 382 |
jQuery('#mainwp-' + subName).css('color', ''); |
| 383 |
}; |
| 384 |
|
| 385 |
|
| 386 |
function shake_element(select) { |
| 387 |
var pos = jQuery(select).position(); |
| 388 |
var type = jQuery(select).css('position'); |
| 389 |
|
| 390 |
if (type == 'static') { |
| 391 |
jQuery(select).css({ |
| 392 |
position: 'relative' |
| 393 |
}); |
| 394 |
} |
| 395 |
|
| 396 |
if (type == 'static' || type == 'relative') { |
| 397 |
pos.top = 0; |
| 398 |
pos.left = 0; |
| 399 |
} |
| 400 |
|
| 401 |
jQuery(select).data('init-type', type); |
| 402 |
|
| 403 |
var shake = [[0, 5, 60], [0, 0, 60], [0, -5, 60], [0, 0, 60], [0, 2, 30], [0, 0, 30], [0, -2, 30], [0, 0, 30]]; |
| 404 |
|
| 405 |
for (s = 0; s < shake.length; s++) { |
| 406 |
jQuery(select).animate({ |
| 407 |
top: pos.top + shake[s][0], |
| 408 |
left: pos.left + shake[s][1] |
| 409 |
}, shake[s][2], 'linear'); |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
/** |
| 415 |
* Required |
| 416 |
*/ |
| 417 |
feedback = function (id, text, type, append) { |
| 418 |
if (append == true) { |
| 419 |
var currentHtml = jQuery('#' + id).html(); |
| 420 |
if (currentHtml == null) |
| 421 |
currentHtml = ""; |
| 422 |
if (currentHtml != '') { |
| 423 |
currentHtml += '<br />' + text; |
| 424 |
} else { |
| 425 |
currentHtml = text; |
| 426 |
} |
| 427 |
jQuery('#' + id).html(currentHtml); |
| 428 |
jQuery('#' + id).removeClass('yellow'); |
| 429 |
jQuery('#' + id).removeClass('green'); |
| 430 |
jQuery('#' + id).removeClass('red'); |
| 431 |
jQuery('#' + id).addClass(type); |
| 432 |
} else { |
| 433 |
jQuery('#' + id).html(text); |
| 434 |
jQuery('#' + id).removeClass('yellow'); |
| 435 |
jQuery('#' + id).removeClass('green'); |
| 436 |
jQuery('#' + id).removeClass('red'); |
| 437 |
jQuery('#' + id).addClass(type); |
| 438 |
} |
| 439 |
jQuery('#' + id).show(); |
| 440 |
|
| 441 |
// automatically scroll to error message if it's not visible |
| 442 |
scrollElementTop(id); |
| 443 |
}; |
| 444 |
|
| 445 |
scrollElementTop = function (id) { |
| 446 |
var scrolltop = jQuery(window).scrollTop(); |
| 447 |
var off = jQuery('#' + id).offset(); |
| 448 |
if (scrolltop > off.top - 40) |
| 449 |
jQuery('html, body').animate({ |
| 450 |
scrollTop: off.top - 40 |
| 451 |
}, 1000, function () { |
| 452 |
shake_element('#' + id) |
| 453 |
}); |
| 454 |
else |
| 455 |
shake_element('#' + id); // shake the error message to get attention :) |
| 456 |
} |
| 457 |
|
| 458 |
jQuery(document).ready(function () { |
| 459 |
jQuery('div.mainwp-hidden').parent().parent().css("display", "none"); |
| 460 |
}); |
| 461 |
|
| 462 |
/** |
| 463 |
* Security Issues |
| 464 |
*/ |
| 465 |
|
| 466 |
var securityIssues_fixes = ['listing', 'wp_version', 'rsd', 'wlw', 'core_updates', 'plugin_updates', 'theme_updates', 'db_reporting', 'php_reporting', 'versions', 'registered_versions', 'admin', 'readme', 'wp_uptodate', 'phpversion_matched', 'sslprotocol', 'debug_disabled']; |
| 467 |
jQuery(document).ready(function () { |
| 468 |
var securityIssueSite = jQuery('#securityIssueSite'); |
| 469 |
if ((securityIssueSite.val() != null) && (securityIssueSite.val() != "")) { |
| 470 |
jQuery(document).on('click', '#securityIssues_fixAll', function () { |
| 471 |
securityIssues_fix('all'); |
| 472 |
}); |
| 473 |
|
| 474 |
jQuery(document).on('click', '#securityIssues_refresh', function () { |
| 475 |
for (var i = 0; i < securityIssues_fixes.length; i++) { |
| 476 |
var securityIssueCurrentIssue = jQuery('#' + securityIssues_fixes[i] + '_fix'); |
| 477 |
if (securityIssueCurrentIssue) { |
| 478 |
securityIssueCurrentIssue.hide(); |
| 479 |
} |
| 480 |
jQuery('#' + securityIssues_fixes[i] + '_extra').hide(); |
| 481 |
jQuery('#' + securityIssues_fixes[i] + '_ok').hide(); |
| 482 |
jQuery('#' + securityIssues_fixes[i] + '_nok').hide(); |
| 483 |
jQuery('#' + securityIssues_fixes[i] + '_loading').show(); |
| 484 |
} |
| 485 |
securityIssues_request(jQuery('#securityIssueSite').val()); |
| 486 |
}); |
| 487 |
|
| 488 |
for (var i = 0; i < securityIssues_fixes.length; i++) { |
| 489 |
jQuery('#' + securityIssues_fixes[i] + '_fix').bind('click', function (what) { |
| 490 |
return function () { |
| 491 |
securityIssues_fix(what); |
| 492 |
return false; |
| 493 |
} |
| 494 |
}(securityIssues_fixes[i])); |
| 495 |
|
| 496 |
jQuery('#' + securityIssues_fixes[i] + '_unfix').bind('click', function (what) { |
| 497 |
return function () { |
| 498 |
securityIssues_unfix(what); |
| 499 |
return false; |
| 500 |
} |
| 501 |
}(securityIssues_fixes[i])); |
| 502 |
} |
| 503 |
securityIssues_request(securityIssueSite.val()); |
| 504 |
} |
| 505 |
}); |
| 506 |
securityIssues_fix = function (feature) { |
| 507 |
if (feature == 'all') { |
| 508 |
for (var i = 0; i < securityIssues_fixes.length; i++) { |
| 509 |
if (jQuery('#' + securityIssues_fixes[i] + '_nok').css('display') != 'none') { |
| 510 |
if (jQuery('#' + securityIssues_fixes[i] + '_fix')) { |
| 511 |
jQuery('#' + securityIssues_fixes[i] + '_fix').hide(); |
| 512 |
} |
| 513 |
jQuery('#' + securityIssues_fixes[i] + '_extra').hide(); |
| 514 |
jQuery('#' + securityIssues_fixes[i] + '_ok').hide(); |
| 515 |
jQuery('#' + securityIssues_fixes[i] + '_nok').hide(); |
| 516 |
jQuery('#' + securityIssues_fixes[i] + '_loading').show(); |
| 517 |
} |
| 518 |
} |
| 519 |
} else { |
| 520 |
if (jQuery('#' + feature + '_fix')) { |
| 521 |
jQuery('#' + feature + '_fix').hide(); |
| 522 |
} |
| 523 |
jQuery('#' + feature + '_extra').hide(); |
| 524 |
jQuery('#' + feature + '_ok').hide(); |
| 525 |
jQuery('#' + feature + '_nok').hide(); |
| 526 |
jQuery('#' + feature + '_loading').show(); |
| 527 |
} |
| 528 |
|
| 529 |
var data = mainwp_secure_data({ |
| 530 |
action: 'mainwp_security_issues_fix', |
| 531 |
feature: feature, |
| 532 |
id: jQuery('#securityIssueSite').val() |
| 533 |
}); |
| 534 |
|
| 535 |
jQuery.post(ajaxurl, data, function (response) { |
| 536 |
securityIssues_handle(response); |
| 537 |
}, 'json'); |
| 538 |
}; |
| 539 |
|
| 540 |
// Securtiy issues Widget |
| 541 |
|
| 542 |
// Show/Hide the list |
| 543 |
jQuery(document).on('click', '#show-security-issues-widget-list', function () { |
| 544 |
jQuery('#mainwp-security-issues-widget-list').toggle(); |
| 545 |
return false; |
| 546 |
}); |
| 547 |
|
| 548 |
// Fix all sites all security issues |
| 549 |
jQuery(document).on('click', '.fix-all-security-issues', function () { |
| 550 |
|
| 551 |
jQuery('#mainwp-secuirty-issues-loader').show(); |
| 552 |
|
| 553 |
jQuery('#mainwp-security-issues-widget-list').show(); |
| 554 |
bulkInstallTotal = jQuery('#mainwp-security-issues-widget-list .item[status="queue"]').length; |
| 555 |
jQuery('.fix-all-site-security-issues').addClass('disabled'); |
| 556 |
jQuery('.unfix-all-site-security-issues').addClass('disabled'); |
| 557 |
mainwp_fix_all_security_issues_start_next(); |
| 558 |
}); |
| 559 |
|
| 560 |
mainwp_fix_all_security_issues_start_next = function () { |
| 561 |
while ((siteToFix = jQuery('#mainwp-security-issues-widget-list .item[status="queue"]:first')) && (siteToFix.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { |
| 562 |
mainwp_fix_all_security_issues_specific(siteToFix); |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
mainwp_fix_all_security_issues_specific = function (siteToFix) { |
| 567 |
|
| 568 |
bulkInstallCurrentThreads++; |
| 569 |
|
| 570 |
siteToFix.attr('status', 'progress'); |
| 571 |
|
| 572 |
var data = mainwp_secure_data({ |
| 573 |
action: 'mainwp_security_issues_fix', |
| 574 |
feature: 'all', |
| 575 |
id: siteToFix.attr('siteid') |
| 576 |
}); |
| 577 |
|
| 578 |
var el = siteToFix.find('.fix-all-site-security-issues'); |
| 579 |
el.hide(); |
| 580 |
|
| 581 |
jQuery.post(ajaxurl, data, function () { |
| 582 |
return function () { |
| 583 |
siteToFix.attr('status', 'done'); |
| 584 |
el.show(); |
| 585 |
bulkInstallCurrentThreads--; |
| 586 |
bulkInstallDone++; |
| 587 |
if (bulkInstallDone != 0 && (bulkInstallTotal == 1 || (bulkInstallDone >= bulkInstallTotal))) { |
| 588 |
window.location.href = location.href; |
| 589 |
} |
| 590 |
mainwp_fix_all_security_issues_start_next(); |
| 591 |
} |
| 592 |
}(), 'json'); |
| 593 |
} |
| 594 |
|
| 595 |
// Fix all securtiy issues for a site |
| 596 |
jQuery(document).on('click', '.fix-all-site-security-issues', function () { |
| 597 |
jQuery('#mainwp-secuirty-issues-loader').show(); |
| 598 |
mainwp_fix_all_security_issues(jQuery(this).closest('.item').attr('siteid'), true); |
| 599 |
}); |
| 600 |
|
| 601 |
mainwp_fix_all_security_issues = function (siteId, refresh) { |
| 602 |
var data = mainwp_secure_data({ |
| 603 |
action: 'mainwp_security_issues_fix', |
| 604 |
feature: 'all', |
| 605 |
id: siteId |
| 606 |
}); |
| 607 |
|
| 608 |
var el = jQuery('#mainwp-security-issues-widget-list .item[siteid="' + siteId + '"] .fix-all-site-security-issues'); |
| 609 |
|
| 610 |
el.hide(); |
| 611 |
|
| 612 |
jQuery('.fix-all-site-security-issues').addClass('disabled'); |
| 613 |
jQuery('.unfix-all-site-security-issues').addClass('disabled'); |
| 614 |
|
| 615 |
jQuery.post(ajaxurl, data, function (pRefresh) { |
| 616 |
return function () { |
| 617 |
el.show(); |
| 618 |
if (pRefresh) { |
| 619 |
window.location.href = location.href; |
| 620 |
} |
| 621 |
} |
| 622 |
}(refresh, el), 'json'); |
| 623 |
}; |
| 624 |
|
| 625 |
jQuery(document).on('click', '.unfix-all-site-security-issues', function () { |
| 626 |
|
| 627 |
jQuery('#mainwp-secuirty-issues-loader').show(); |
| 628 |
|
| 629 |
var data = mainwp_secure_data({ |
| 630 |
action: 'mainwp_security_issues_unfix', |
| 631 |
feature: 'all', |
| 632 |
id: jQuery(jQuery(this).parents('.item')[0]).attr('siteid') |
| 633 |
}); |
| 634 |
|
| 635 |
jQuery(this).hide(); |
| 636 |
jQuery('.fix-all-site-security-issues').addClass('disabled'); |
| 637 |
jQuery('.unfix-all-site-security-issues').addClass('disabled'); |
| 638 |
|
| 639 |
jQuery.post(ajaxurl, data, function () { |
| 640 |
window.location.href = location.href; |
| 641 |
}, 'json'); |
| 642 |
}); |
| 643 |
securityIssues_unfix = function (feature) { |
| 644 |
if (jQuery('#' + feature + '_unfix')) { |
| 645 |
jQuery('#' + feature + '_unfix').hide(); |
| 646 |
} |
| 647 |
jQuery('#' + feature + '_extra').hide(); |
| 648 |
jQuery('#' + feature + '_ok').hide(); |
| 649 |
jQuery('#' + feature + '_nok').hide(); |
| 650 |
jQuery('#' + feature + '_loading').show(); |
| 651 |
|
| 652 |
var data = mainwp_secure_data({ |
| 653 |
action: 'mainwp_security_issues_unfix', |
| 654 |
feature: feature, |
| 655 |
id: jQuery('#securityIssueSite').val() |
| 656 |
}); |
| 657 |
jQuery.post(ajaxurl, data, function (response) { |
| 658 |
securityIssues_handle(response); |
| 659 |
}, 'json'); |
| 660 |
}; |
| 661 |
securityIssues_request = function (websiteId) { |
| 662 |
var data = mainwp_secure_data({ |
| 663 |
action: 'mainwp_security_issues_request', |
| 664 |
id: websiteId |
| 665 |
}); |
| 666 |
jQuery.post(ajaxurl, data, function (response) { |
| 667 |
securityIssues_handle(response); |
| 668 |
}, 'json'); |
| 669 |
}; |
| 670 |
securityIssues_handle = function (response) { |
| 671 |
var result = ''; |
| 672 |
if (response.error) { |
| 673 |
result = getErrorMessage(response.error); |
| 674 |
} else { |
| 675 |
try { |
| 676 |
var res = response.result; |
| 677 |
for (var issue in res) { |
| 678 |
if (jQuery('#' + issue + '_loading')) { |
| 679 |
jQuery('#' + issue + '_loading').hide(); |
| 680 |
if (res[issue] == 'Y') { |
| 681 |
jQuery('#' + issue + '_extra').hide(); |
| 682 |
jQuery('#' + issue + '_nok').hide(); |
| 683 |
if (jQuery('#' + issue + '_fix')) { |
| 684 |
jQuery('#' + issue + '_fix').hide(); |
| 685 |
} |
| 686 |
if (jQuery('#' + issue + '_unfix')) { |
| 687 |
jQuery('#' + issue + '_unfix').show(); |
| 688 |
} |
| 689 |
jQuery('#' + issue + '_ok').show(); |
| 690 |
jQuery('#' + issue + '-status-ok').show(); |
| 691 |
jQuery('#' + issue + '-status-nok').hide(); |
| 692 |
if (issue == 'readme') { |
| 693 |
jQuery('#readme-wpe-nok').hide(); |
| 694 |
} |
| 695 |
} else { |
| 696 |
jQuery('#' + issue + '_extra').hide(); |
| 697 |
jQuery('#' + issue + '_ok').hide(); |
| 698 |
jQuery('#' + issue + '_nok').show(); |
| 699 |
if (jQuery('#' + issue + '_fix')) { |
| 700 |
jQuery('#' + issue + '_fix').show(); |
| 701 |
} |
| 702 |
if (jQuery('#' + issue + '_unfix')) { |
| 703 |
jQuery('#' + issue + '_unfix').hide(); |
| 704 |
} |
| 705 |
|
| 706 |
if (res[issue] != 'N') { |
| 707 |
jQuery('#' + issue + '_extra').html(res[issue]); |
| 708 |
jQuery('#' + issue + '_extra').show(); |
| 709 |
} |
| 710 |
} |
| 711 |
} |
| 712 |
} |
| 713 |
|
| 714 |
var unSetFeatures = jQuery('#mainwp-security-issues-table').attr('un-set'); |
| 715 |
if (unSetFeatures != '') { |
| 716 |
unSetFeatures = unSetFeatures.split(','); |
| 717 |
if (unSetFeatures.length > 0) { |
| 718 |
for (var ival in unSetFeatures) { |
| 719 |
issue = unSetFeatures[ival]; |
| 720 |
console.log(res[issue]); |
| 721 |
if (res[issue] == 'Y') { |
| 722 |
securityIssues_unfix(issue); |
| 723 |
} |
| 724 |
} |
| 725 |
} |
| 726 |
} |
| 727 |
|
| 728 |
} catch (err) { |
| 729 |
result = '<i class="exclamation circle icon"></i> ' + __('Undefined error!'); |
| 730 |
} |
| 731 |
} |
| 732 |
if (result != '') { |
| 733 |
//show error! |
| 734 |
} |
| 735 |
}; |
| 736 |
|
| 737 |
updatesoverview_bulk_check_abandoned = function (which) { |
| 738 |
if ('plugin' == which) { |
| 739 |
confirmMsg = __("You are about to check abandoned plugins on the sites?"); |
| 740 |
} else { |
| 741 |
confirmMsg = __("You are about to check abandoned themes on the sites?"); |
| 742 |
} |
| 743 |
mainwp_confirm(confirmMsg, _callback = function () { mainwp_managesites_bulk_check_abandoned('all', which); }); |
| 744 |
} |
| 745 |
|
| 746 |
mainwp_managesites_bulk_check_abandoned = function (siteIds, which) { |
| 747 |
var allWebsiteIds = jQuery('.dashboard_wp_id').map(function (indx, el) { |
| 748 |
return jQuery(el).val(); |
| 749 |
}); |
| 750 |
|
| 751 |
if ('all' == siteIds) { |
| 752 |
siteIds = allWebsiteIds; |
| 753 |
} |
| 754 |
|
| 755 |
var selectedIds = [], excludeIds = []; |
| 756 |
if (siteIds instanceof Array) { |
| 757 |
jQuery.grep(allWebsiteIds, function (el) { |
| 758 |
if (jQuery.inArray(el, siteIds) !== -1) { |
| 759 |
selectedIds.push(el); |
| 760 |
} else { |
| 761 |
excludeIds.push(el); |
| 762 |
} |
| 763 |
}); |
| 764 |
for (var i = 0; i < excludeIds.length; i++) { |
| 765 |
dashboard_update_site_hide(excludeIds[i]); |
| 766 |
} |
| 767 |
allWebsiteIds = selectedIds; |
| 768 |
//jQuery('#refresh-status-total').text(allWebsiteIds.length); |
| 769 |
} |
| 770 |
|
| 771 |
var nrOfWebsites = allWebsiteIds.length; |
| 772 |
|
| 773 |
if (nrOfWebsites == 0) |
| 774 |
return false; |
| 775 |
|
| 776 |
var siteNames = {}; |
| 777 |
|
| 778 |
for (var i = 0; i < allWebsiteIds.length; i++) { |
| 779 |
dashboard_update_site_status(allWebsiteIds[i], '<i class="clock outline icon"></i>'); |
| 780 |
siteNames[allWebsiteIds[i]] = jQuery('.sync-site-status[siteid="' + allWebsiteIds[i] + '"]').attr('niceurl'); |
| 781 |
} |
| 782 |
var initData = { |
| 783 |
progressMax: nrOfWebsites, |
| 784 |
title: 'Check abandoned ' + ('plugin' == which ? 'plugins' : 'themes'), |
| 785 |
statusText: __('started'), |
| 786 |
callback: function () { |
| 787 |
bulkManageSitesTaskRunning = false; |
| 788 |
window.location.href = location.href; |
| 789 |
} |
| 790 |
}; |
| 791 |
mainwpPopup('#mainwp-sync-sites-modal').init(initData); |
| 792 |
|
| 793 |
mainwp_managesites_check_abandoned_all_int(allWebsiteIds, which); |
| 794 |
}; |
| 795 |
|
| 796 |
mainwp_managesites_check_abandoned_all_int = function (websiteIds, which) { |
| 797 |
websitesToUpgrade = websiteIds; |
| 798 |
currentWebsite = 0; |
| 799 |
websitesDone = 0; |
| 800 |
websitesTotal = websitesLeft = websitesToUpgrade.length; |
| 801 |
|
| 802 |
bulkTaskRunning = true; |
| 803 |
mainwp_managesites_check_abandoned_all_loop_next(which); |
| 804 |
}; |
| 805 |
|
| 806 |
mainwp_managesites_check_abandoned_all_loop_next = function (which) { |
| 807 |
while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { |
| 808 |
mainwp_managesites_check_abandoned_all_upgrade_next(which); |
| 809 |
} |
| 810 |
}; |
| 811 |
mainwp_managesites_check_abandoned_all_upgrade_next = function (which) { |
| 812 |
currentThreads++; |
| 813 |
websitesLeft--; |
| 814 |
|
| 815 |
var websiteId = websitesToUpgrade[currentWebsite++]; |
| 816 |
dashboard_update_site_status(websiteId, '<i class="sync alternate loading icon"></i>'); |
| 817 |
|
| 818 |
mainwp_managesites_check_abandoned_int(websiteId, which); |
| 819 |
}; |
| 820 |
|
| 821 |
mainwp_managesites_check_abandoned_int = function (siteid, which) { |
| 822 |
|
| 823 |
var data = mainwp_secure_data({ |
| 824 |
action: 'mainwp_check_abandoned', |
| 825 |
siteId: siteid, |
| 826 |
which: which |
| 827 |
}); |
| 828 |
|
| 829 |
jQuery.ajax({ |
| 830 |
type: 'POST', |
| 831 |
url: ajaxurl, |
| 832 |
data: data, |
| 833 |
success: function (pSiteid) { |
| 834 |
return function (response) { |
| 835 |
currentThreads--; |
| 836 |
websitesDone++; |
| 837 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(websitesDone); |
| 838 |
if (response.error != undefined) { |
| 839 |
dashboard_update_site_status(pSiteid, '<i class="red times icon"></i>'); |
| 840 |
} else if (response.result && response.result == 'success') { |
| 841 |
dashboard_update_site_status(pSiteid, '<i class="green check icon"></i>', true); |
| 842 |
} else { |
| 843 |
dashboard_update_site_status(pSiteid, '<i class="red times icon"></i>'); |
| 844 |
} |
| 845 |
mainwp_managesites_check_abandoned_all_loop_next(which); |
| 846 |
} |
| 847 |
}(siteid), |
| 848 |
dataType: 'json' |
| 849 |
}); |
| 850 |
return false; |
| 851 |
}; |
| 852 |
|
| 853 |
/** |
| 854 |
* MainWP UI. |
| 855 |
*/ |
| 856 |
jQuery(document).ready(function () { |
| 857 |
jQuery('#reset-overview-settings').on('click', function () { |
| 858 |
mainwp_confirm(__('Are you sure.'), function () { |
| 859 |
var which_set = jQuery('input[name=reset_overview_which_settings]').val(); |
| 860 |
if ('sidebar_settings' == which_set) { |
| 861 |
jQuery('#mainwp_sidebarPosition').dropdown('set selected', 1); |
| 862 |
} else if ('overview_settings' == which_set) { |
| 863 |
jQuery('input[name=hide_update_everything]').prop('checked', false); |
| 864 |
jQuery('input[name=number_overview_columns][value=2]').prop('checked', true); |
| 865 |
jQuery('.mainwp_hide_wpmenu_checkboxes input[name="mainwp_show_widgets[]"]').prop('checked', true); |
| 866 |
} |
| 867 |
jQuery('input[name=reset_overview_settings]').attr('value', 1); |
| 868 |
jQuery('#submit-overview-settings').click(); |
| 869 |
}, false, false, true); |
| 870 |
return false; |
| 871 |
}); |
| 872 |
}); |
| 873 |
|
| 874 |
/** |
| 875 |
* Sync Sites |
| 876 |
*/ |
| 877 |
|
| 878 |
jQuery(document).ready(function () { |
| 879 |
jQuery('#mainwp-sync-sites').on('click', function () { |
| 880 |
mainwp_sync_sites_data(); |
| 881 |
}); |
| 882 |
|
| 883 |
// to compatible with extensions |
| 884 |
jQuery('#dashboard_refresh').on('click', function () { |
| 885 |
mainwp_sync_sites_data(); |
| 886 |
}); |
| 887 |
jQuery('.mainwp-sync-this-site').on('click', function () { |
| 888 |
var syncSiteIds = []; |
| 889 |
syncSiteIds.push(jQuery(this).attr('site-id')); |
| 890 |
mainwp_sync_sites_data(syncSiteIds); |
| 891 |
}); |
| 892 |
}); |
| 893 |
|
| 894 |
mainwp_sync_sites_data = function (syncSiteIds, pAction) { |
| 895 |
var allWebsiteIds = jQuery('.dashboard_wp_id').map(function (indx, el) { |
| 896 |
return jQuery(el).val(); |
| 897 |
}); |
| 898 |
var globalSync = true; |
| 899 |
var selectedIds = [], excludeIds = []; |
| 900 |
if (syncSiteIds instanceof Array) { |
| 901 |
jQuery.grep(allWebsiteIds, function (el) { |
| 902 |
if (jQuery.inArray(el, syncSiteIds) !== -1) { |
| 903 |
selectedIds.push(el); |
| 904 |
} else { |
| 905 |
excludeIds.push(el); |
| 906 |
} |
| 907 |
}); |
| 908 |
for (var i = 0; i < excludeIds.length; i++) { |
| 909 |
dashboard_update_site_hide(excludeIds[i]); |
| 910 |
} |
| 911 |
allWebsiteIds = selectedIds; |
| 912 |
globalSync = false; |
| 913 |
} |
| 914 |
|
| 915 |
for (var i = 0; i < allWebsiteIds.length; i++) { |
| 916 |
dashboard_update_site_status(allWebsiteIds[i], '<span data-inverted="" data-position="left center" data-tooltip="' + __('Pending', 'mainwp') + '"><i class="clock outline icon"></i></span>'); |
| 917 |
} |
| 918 |
|
| 919 |
var nrOfWebsites = allWebsiteIds.length; |
| 920 |
|
| 921 |
mainwpPopup('#mainwp-sync-sites-modal').init({ |
| 922 |
title: (pAction == 'checknow' ? __('Check Now') : __('Data Synchronization')), |
| 923 |
progressMax: nrOfWebsites, |
| 924 |
statusText: (pAction == 'checknow' ? 'checked' : 'synced'), |
| 925 |
callback: function () { |
| 926 |
bulkTaskRunning = false; |
| 927 |
history.pushState("", document.title, window.location.pathname + window.location.search); // to fix issue for url with hash |
| 928 |
window.location.href = location.href; |
| 929 |
} |
| 930 |
}); |
| 931 |
|
| 932 |
if (jQuery('#mainwp-sync-sites-modal').attr('current-wpid') > 0) { |
| 933 |
globalSync = false; |
| 934 |
} |
| 935 |
|
| 936 |
dashboard_update(allWebsiteIds, globalSync, pAction); |
| 937 |
|
| 938 |
if (pAction != 'checknow') { |
| 939 |
if (nrOfWebsites > 0) { |
| 940 |
var data = { |
| 941 |
action: 'mainwp_status_saving', |
| 942 |
status: 'last_sync_sites', |
| 943 |
isGlobalSync: globalSync ? 1 : 0 |
| 944 |
}; |
| 945 |
jQuery.post(ajaxurl, mainwp_secure_data(data), function () { |
| 946 |
|
| 947 |
}); |
| 948 |
} |
| 949 |
} |
| 950 |
}; |
| 951 |
|
| 952 |
var websitesToUpdate = []; |
| 953 |
var websitesTotal = 0; |
| 954 |
var websitesLeft = 0; |
| 955 |
var websitesDone = 0; |
| 956 |
var currentWebsite = 0; |
| 957 |
var bulkTaskRunning = false; |
| 958 |
var currentThreads = 0; |
| 959 |
var maxThreads = mainwpParams['maximumSyncRequests'] == undefined ? 8 : mainwpParams['maximumSyncRequests']; |
| 960 |
var globalSync = true; |
| 961 |
|
| 962 |
dashboard_update = function (websiteIds, isGlobalSync, pAction) { |
| 963 |
websitesToUpdate = websiteIds; |
| 964 |
currentWebsite = 0; |
| 965 |
websitesDone = 0; |
| 966 |
websitesTotal = websitesLeft = websitesToUpdate.length; |
| 967 |
globalSync = isGlobalSync; |
| 968 |
|
| 969 |
bulkTaskRunning = true; |
| 970 |
|
| 971 |
if (websitesTotal == 0) { |
| 972 |
dashboard_update_done(pAction); |
| 973 |
} else { |
| 974 |
dashboard_loop_next(pAction); |
| 975 |
} |
| 976 |
}; |
| 977 |
|
| 978 |
dashboard_update_site_status = function (siteId, newStatus, isSuccess) { |
| 979 |
jQuery('.sync-site-status[siteid="' + siteId + '"]').html(newStatus); |
| 980 |
// Move successfully synced site to the bottom of the sync list |
| 981 |
if (typeof isSuccess !== 'undefined' && isSuccess) { |
| 982 |
var row = jQuery('.sync-site-status[siteid="' + siteId + '"]').closest('.item'); |
| 983 |
jQuery(row).insertAfter(jQuery("#sync-sites-status .item").not('.disconnected-site').last()); |
| 984 |
} |
| 985 |
}; |
| 986 |
|
| 987 |
dashboard_update_site_hide = function (siteId) { |
| 988 |
jQuery('.sync-site-status[siteid="' + siteId + '"]').closest('.item').hide(); |
| 989 |
}; |
| 990 |
|
| 991 |
dashboard_loop_next = function (pAction) { |
| 992 |
while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { |
| 993 |
dashboard_update_next(pAction); |
| 994 |
} |
| 995 |
}; |
| 996 |
|
| 997 |
dashboard_update_done = function (pAction) { |
| 998 |
currentThreads--; |
| 999 |
if (!bulkTaskRunning) |
| 1000 |
return; |
| 1001 |
websitesDone++; |
| 1002 |
if (websitesDone > websitesTotal) |
| 1003 |
websitesDone = websitesTotal; |
| 1004 |
|
| 1005 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(websitesDone); |
| 1006 |
|
| 1007 |
if (websitesDone == websitesTotal) { |
| 1008 |
setTimeout(function () { |
| 1009 |
bulkTaskRunning = false; |
| 1010 |
mainwpPopup('#mainwp-sync-sites-modal').close(true); |
| 1011 |
}, 3000); |
| 1012 |
return; |
| 1013 |
} |
| 1014 |
|
| 1015 |
dashboard_loop_next(pAction); |
| 1016 |
}; |
| 1017 |
|
| 1018 |
dashboard_update_next = function (pAction) { |
| 1019 |
currentThreads++; |
| 1020 |
websitesLeft--; |
| 1021 |
var websiteId = websitesToUpdate[currentWebsite++]; |
| 1022 |
dashboard_update_site_status(websiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + __('Syncing...', 'mainwp') + '"><i class="sync alternate loading icon"></i></span>'); |
| 1023 |
var data = mainwp_secure_data({ |
| 1024 |
action: ('checknow' == pAction ? 'mainwp_checksites' : 'mainwp_syncsites'), |
| 1025 |
wp_id: websiteId, |
| 1026 |
isGlobalSync: globalSync |
| 1027 |
}); |
| 1028 |
dashboard_update_next_int(websiteId, data, 0, pAction); |
| 1029 |
}; |
| 1030 |
|
| 1031 |
dashboard_update_next_int = function (websiteId, data, errors, action) { |
| 1032 |
jQuery.ajax({ |
| 1033 |
type: 'POST', |
| 1034 |
url: ajaxurl, |
| 1035 |
data: data, |
| 1036 |
success: function (pWebsiteId, pAction) { |
| 1037 |
return function (response) { |
| 1038 |
if (response.error) { |
| 1039 |
var extErr = response.error; |
| 1040 |
dashboard_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + extErr + '"><i class="exclamation red icon"></i></span>'); |
| 1041 |
} else { |
| 1042 |
dashboard_update_site_status(websiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + __('Synchronization process completed successfully.', 'mainwp') + '"><i class="check green icon"></i></span>', true); |
| 1043 |
} |
| 1044 |
dashboard_update_done(pAction); |
| 1045 |
} |
| 1046 |
}(websiteId, action), |
| 1047 |
error: function (pWebsiteId, pData, pErrors, pAction) { |
| 1048 |
return function () { |
| 1049 |
if (pErrors > 5) { |
| 1050 |
dashboard_update_site_status(pWebsiteId, '<i class="exclamation yellow icon"></i>'); |
| 1051 |
dashboard_update_done(pAction); |
| 1052 |
} else { |
| 1053 |
pErrors++; |
| 1054 |
dashboard_update_next_int(pWebsiteId, pData, pErrors, pAction); |
| 1055 |
} |
| 1056 |
} |
| 1057 |
}(websiteId, data, errors, action), |
| 1058 |
dataType: 'json' |
| 1059 |
}); |
| 1060 |
}; |
| 1061 |
|
| 1062 |
|
| 1063 |
mainwp_tool_disconnect_sites = function () { |
| 1064 |
|
| 1065 |
mainwp_confirm('Are you sure that you want to disconnect your sites? This will function will break the connection and leave the MainWP Child plugin active and which makes your sites vulnerable.', function () { |
| 1066 |
var allWebsiteIds = jQuery('.dashboard_wp_id').map(function (indx, el) { |
| 1067 |
return jQuery(el).val(); |
| 1068 |
}); |
| 1069 |
|
| 1070 |
for (var i = 0; i < allWebsiteIds.length; i++) { |
| 1071 |
dashboard_update_site_status(allWebsiteIds[i], '<i class="clock outline icon"></i>'); |
| 1072 |
} |
| 1073 |
|
| 1074 |
var nrOfWebsites = allWebsiteIds.length; |
| 1075 |
|
| 1076 |
mainwpPopup('#mainwp-sync-sites-modal').init({ |
| 1077 |
title: __('Disconnect All Sites'), |
| 1078 |
progressMax: nrOfWebsites, |
| 1079 |
statusText: __('disconnected'), |
| 1080 |
callback: function () { |
| 1081 |
window.location.href = location.href; |
| 1082 |
} |
| 1083 |
}); |
| 1084 |
|
| 1085 |
websitesToUpdate = allWebsiteIds; |
| 1086 |
currentWebsite = 0; |
| 1087 |
websitesDone = 0; |
| 1088 |
websitesTotal = websitesLeft = websitesToUpdate.length; |
| 1089 |
|
| 1090 |
bulkTaskRunning = true; |
| 1091 |
|
| 1092 |
if (websitesTotal == 0) { |
| 1093 |
mainwp_tool_disconnect_sites_done(); |
| 1094 |
} else { |
| 1095 |
mainwp_tool_disconnect_sites_loop_next(); |
| 1096 |
} |
| 1097 |
}, false, false, false, 'DISCONNECT'); |
| 1098 |
}; |
| 1099 |
|
| 1100 |
mainwp_tool_disconnect_sites_done = function () { |
| 1101 |
currentThreads--; |
| 1102 |
if (!bulkTaskRunning) |
| 1103 |
return; |
| 1104 |
websitesDone++; |
| 1105 |
if (websitesDone > websitesTotal) |
| 1106 |
websitesDone = websitesTotal; |
| 1107 |
|
| 1108 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(websitesDone); |
| 1109 |
|
| 1110 |
mainwp_tool_disconnect_sites_loop_next(); |
| 1111 |
}; |
| 1112 |
|
| 1113 |
mainwp_tool_disconnect_sites_loop_next = function () { |
| 1114 |
while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { |
| 1115 |
mainwp_tool_disconnect_sites_next(); |
| 1116 |
} |
| 1117 |
}; |
| 1118 |
|
| 1119 |
mainwp_tool_disconnect_sites_next = function () { |
| 1120 |
currentThreads++; |
| 1121 |
websitesLeft--; |
| 1122 |
var websiteId = websitesToUpdate[currentWebsite++]; |
| 1123 |
dashboard_update_site_status(websiteId, '<i class="sync alternate loading icon"></i>'); |
| 1124 |
var data = mainwp_secure_data({ |
| 1125 |
action: 'mainwp_disconnect_site', |
| 1126 |
wp_id: websiteId |
| 1127 |
}); |
| 1128 |
mainwp_tool_disconnect_sites_next_int(websiteId, data, 0); |
| 1129 |
}; |
| 1130 |
|
| 1131 |
mainwp_tool_disconnect_sites_next_int = function (websiteId, data, errors) { |
| 1132 |
jQuery.ajax({ |
| 1133 |
type: 'POST', |
| 1134 |
url: ajaxurl, |
| 1135 |
data: data, |
| 1136 |
success: function (pWebsiteId) { |
| 1137 |
return function (response) { |
| 1138 |
if (response && response.error) { |
| 1139 |
dashboard_update_site_status(pWebsiteId, response.error + '<i class="exclamation red icon"></i>'); |
| 1140 |
} else if (response && response.result == 'success') { |
| 1141 |
dashboard_update_site_status(websiteId, '<i class="check green icon"></i>', true); |
| 1142 |
} else { |
| 1143 |
dashboard_update_site_status(pWebsiteId, __('Undefined error!') + ' <i class="exclamation red icon"></i>'); |
| 1144 |
} |
| 1145 |
mainwp_tool_disconnect_sites_done(); |
| 1146 |
} |
| 1147 |
}(websiteId), |
| 1148 |
error: function (pWebsiteId, pData, pErrors) { |
| 1149 |
return function () { |
| 1150 |
if (pErrors > 5) { |
| 1151 |
dashboard_update_site_status(pWebsiteId, '<i class="exclamation yellow icon"></i>'); |
| 1152 |
mainwp_tool_disconnect_sites_done(); |
| 1153 |
} else { |
| 1154 |
pErrors++; |
| 1155 |
mainwp_tool_disconnect_sites_next_int(pWebsiteId, pData, pErrors); |
| 1156 |
} |
| 1157 |
} |
| 1158 |
}(websiteId, data, errors), |
| 1159 |
dataType: 'json' |
| 1160 |
}); |
| 1161 |
}; |
| 1162 |
|
| 1163 |
mainwp_tool_clear_activation_data = function (pObj) { |
| 1164 |
var loc = jQuery(pObj).attr('href'); |
| 1165 |
mainwp_confirm('Are you sure?', function () { |
| 1166 |
window.location = loc; |
| 1167 |
}); |
| 1168 |
}; |
| 1169 |
|
| 1170 |
/** |
| 1171 |
* Manage sites page |
| 1172 |
*/ |
| 1173 |
|
| 1174 |
jQuery(document).ready(function ($) { |
| 1175 |
jQuery('#mainwp-backup-type').change(function () { |
| 1176 |
if (jQuery(this).val() == 'full') |
| 1177 |
jQuery('.mainwp-backup-full-exclude').show(); |
| 1178 |
else |
| 1179 |
jQuery('.mainwp-backup-full-exclude').hide(); |
| 1180 |
}); |
| 1181 |
jQuery('.mainwp-checkbox-showhide-elements').on('click', function () { |
| 1182 |
var hiel = $(this).attr('hide-parent'); |
| 1183 |
// if semantic ui checkbox is checked. |
| 1184 |
if ($(this).find('input').is(':checked')) { |
| 1185 |
$('[hide-element=' + hiel + ']').fadeOut(200); |
| 1186 |
} else { |
| 1187 |
$('[hide-element=' + hiel + ']').fadeIn(300); |
| 1188 |
} |
| 1189 |
}); |
| 1190 |
|
| 1191 |
jQuery('.mainwp-selecter-showhide-elements').on('change', function () { |
| 1192 |
var hiel = $(this).attr('hide-parent'); |
| 1193 |
var hival = $(this).attr('hide-value'); |
| 1194 |
hival = hival.split('-'); // support multi hide values. |
| 1195 |
var selval = $(this).val(); |
| 1196 |
// if selected hide value. |
| 1197 |
if (hival.includes(selval)) { |
| 1198 |
$('[hide-element=' + hiel + ']').fadeOut(300); |
| 1199 |
} else { |
| 1200 |
$('[hide-element=' + hiel + ']').fadeIn(200); |
| 1201 |
} |
| 1202 |
}); |
| 1203 |
}); |
| 1204 |
|
| 1205 |
|
| 1206 |
jQuery(document).ready(function () { |
| 1207 |
jQuery(document).on('change', '#mainwp_managesites_add_wpurl', function () { |
| 1208 |
var url = jQuery('#mainwp_managesites_add_wpurl').val(); |
| 1209 |
var protocol = jQuery('#mainwp_managesites_add_wpurl_protocol').val(); |
| 1210 |
|
| 1211 |
if (url.lastIndexOf('http://') === 0) { |
| 1212 |
protocol = 'http'; |
| 1213 |
url = url.substring(7); |
| 1214 |
} else if (url.lastIndexOf('https://') === 0) { |
| 1215 |
protocol = 'https'; |
| 1216 |
url = url.substring(8); |
| 1217 |
} |
| 1218 |
|
| 1219 |
if (jQuery('#mainwp_managesites_add_wpname').val() == '') { |
| 1220 |
jQuery('#mainwp_managesites_add_wpname').val(url); |
| 1221 |
} |
| 1222 |
jQuery('#mainwp_managesites_add_wpurl').val(url); |
| 1223 |
jQuery('#mainwp_managesites_add_wpurl_protocol').val(protocol).trigger("change"); |
| 1224 |
}); |
| 1225 |
|
| 1226 |
// Trigger the single site reconnect process |
| 1227 |
jQuery('#mainwp-manage-sites-table').on('click', '.mainwp_site_reconnect', function () { |
| 1228 |
mainwp_managesites_reconnect(jQuery(this)); |
| 1229 |
return false; |
| 1230 |
}); |
| 1231 |
|
| 1232 |
jQuery('#mainwp-sites-previews').on('click', '.mainwp_site_card_reconnect', function () { |
| 1233 |
mainwp_managesites_cards_reconnect(jQuery(this)); |
| 1234 |
return false; |
| 1235 |
}); |
| 1236 |
|
| 1237 |
jQuery('.mainwp-updates-overview-reconnect-site').on('click', function () { |
| 1238 |
mainwp_site_overview_reconnect(jQuery(this)); |
| 1239 |
return false; |
| 1240 |
}); |
| 1241 |
|
| 1242 |
jQuery(".chk-sync-install-plugin").change(function () { |
| 1243 |
var parent = jQuery(this).closest('.sync-ext-row'); |
| 1244 |
var opts = parent.find(".sync-options input[type='checkbox']"); |
| 1245 |
if (jQuery(this).is(':checked')) { |
| 1246 |
//opts.removeAttr( "disabled" ); |
| 1247 |
opts.prop("checked", true); |
| 1248 |
} else { |
| 1249 |
opts.prop("checked", false); |
| 1250 |
///opts.attr( "disabled", "disabled" ); |
| 1251 |
} |
| 1252 |
}); |
| 1253 |
|
| 1254 |
managesites_init(); |
| 1255 |
}); |
| 1256 |
|
| 1257 |
jQuery(document).on('change', '#mainwp_managesites_verify_installed_child', function () { |
| 1258 |
if (jQuery(this).is(':checked')) { |
| 1259 |
jQuery('#mainwp_message_verify_installed_child').hide(); |
| 1260 |
} |
| 1261 |
}); |
| 1262 |
|
| 1263 |
managesites_init = function () { |
| 1264 |
jQuery('#mainwp-message-zone').hide(); |
| 1265 |
jQuery('.sync-ext-row span.status').html(''); |
| 1266 |
jQuery('.sync-ext-row span.status').css('color', '#0073aa'); |
| 1267 |
}; |
| 1268 |
|
| 1269 |
mainwp_site_overview_reconnect = function (pElement) { |
| 1270 |
feedback('mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + 'Trying to reconnect. Please wait...', ''); |
| 1271 |
var data = mainwp_secure_data({ |
| 1272 |
action: 'mainwp_reconnectwp', |
| 1273 |
siteid: pElement.attr('siteid') |
| 1274 |
}); |
| 1275 |
|
| 1276 |
jQuery.post(ajaxurl, data, function () { |
| 1277 |
return function (response) { |
| 1278 |
response = jQuery.trim(response); |
| 1279 |
if (response.substr(0, 5) == 'ERROR') { |
| 1280 |
var error; |
| 1281 |
if (response.length == 5) { |
| 1282 |
error = 'Undefined error! Please try again. If the process keeps failing, please review <a href="https://kb.mainwp.com/">MainWP Knowledgebase</a>, and if you still have issues, please let us know in the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a>.'; |
| 1283 |
} else { |
| 1284 |
error = response.substr(6); |
| 1285 |
} |
| 1286 |
feedback('mainwp-message-zone', error, 'red'); |
| 1287 |
} else { |
| 1288 |
location.reload(); |
| 1289 |
} |
| 1290 |
} |
| 1291 |
}()); |
| 1292 |
}; |
| 1293 |
|
| 1294 |
mainwp_managesites_reconnect = function (pElement) { |
| 1295 |
var wrapElement = pElement.closest('tr'); |
| 1296 |
wrapElement.html('<td colspan="999"><i class="notched circle loading icon"></i> ' + 'Trying to reconnect. Please wait...' + '</td>'); |
| 1297 |
var data = mainwp_secure_data({ |
| 1298 |
action: 'mainwp_reconnectwp', |
| 1299 |
siteid: wrapElement.attr('siteid') |
| 1300 |
}); |
| 1301 |
|
| 1302 |
jQuery.post(ajaxurl, data, function (pWrapElement) { |
| 1303 |
return function (response) { |
| 1304 |
response = jQuery.trim(response); |
| 1305 |
pWrapElement.hide(); // hide reconnect item |
| 1306 |
if (response.substr(0, 5) == 'ERROR') { |
| 1307 |
var error; |
| 1308 |
if (response.length == 5) { |
| 1309 |
error = 'Undefined error! Please try again. If the process keeps failing, please review this <a href="https://kb.mainwp.com/docs/potential-issues/">Knowledgebase document</a>, and if you still have issues, please let us know in the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a>.'; |
| 1310 |
} else { |
| 1311 |
error = response.substr(6); |
| 1312 |
} |
| 1313 |
feedback('mainwp-message-zone', error, 'red'); |
| 1314 |
} else { |
| 1315 |
feedback('mainwp-message-zone', response, 'green'); |
| 1316 |
} |
| 1317 |
setTimeout(function () { |
| 1318 |
window.location.reload() |
| 1319 |
}, 6000); |
| 1320 |
} |
| 1321 |
|
| 1322 |
}(wrapElement)); |
| 1323 |
}; |
| 1324 |
|
| 1325 |
mainwp_managesites_cards_reconnect = function (element) { |
| 1326 |
element.html('<i class="notched loading circle icon"></i> Reconnecting...'); |
| 1327 |
var data = mainwp_secure_data({ |
| 1328 |
action: 'mainwp_reconnectwp', |
| 1329 |
siteid: element.attr('site-id') |
| 1330 |
}); |
| 1331 |
|
| 1332 |
jQuery.post(ajaxurl, data, function (element) { |
| 1333 |
return function (response) { |
| 1334 |
response = jQuery.trim(response); |
| 1335 |
element.hide(); |
| 1336 |
if (response.substr(0, 5) == 'ERROR') { |
| 1337 |
var error; |
| 1338 |
if (response.length == 5) { |
| 1339 |
error = 'Undefined error! Please try again. If the process keeps failing, please review this <a href="https://kb.mainwp.com/docs/potential-issues/">Knowledgebase document</a>, and if you still have issues, please let us know in the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a>.'; |
| 1340 |
} else { |
| 1341 |
error = response.substr(6); |
| 1342 |
} |
| 1343 |
feedback('mainwp-message-zone', error, 'red'); |
| 1344 |
} else { |
| 1345 |
feedback('mainwp-message-zone', response, 'green'); |
| 1346 |
} |
| 1347 |
setTimeout(function () { |
| 1348 |
window.location.reload() |
| 1349 |
}, 6000); |
| 1350 |
} |
| 1351 |
|
| 1352 |
}(element)); |
| 1353 |
}; |
| 1354 |
|
| 1355 |
// Connect a new website |
| 1356 |
mainwp_managesites_add = function () { |
| 1357 |
managesites_init(); |
| 1358 |
if (!jQuery('#mainwp_managesites_verify_installed_child').is(':checked')) { |
| 1359 |
jQuery('#mainwp_message_verify_installed_child').show(); |
| 1360 |
scrollElementTop('mainwp_message_verify_installed_child'); |
| 1361 |
return; |
| 1362 |
} else { |
| 1363 |
jQuery('#mainwp_message_verify_installed_child').hide(); |
| 1364 |
} |
| 1365 |
|
| 1366 |
var errors = []; |
| 1367 |
|
| 1368 |
if (jQuery('#mainwp_managesites_add_wpname').val() == '') { |
| 1369 |
errors.push(__('Please enter a name for the website.')); |
| 1370 |
} |
| 1371 |
if (jQuery('#mainwp_managesites_add_wpurl').val() == '') { |
| 1372 |
errors.push(__('Please enter a valid URL for your site.')); |
| 1373 |
} else { |
| 1374 |
var url = jQuery('#mainwp_managesites_add_wpurl').val(); |
| 1375 |
if (url.substr(-1) != '/') { |
| 1376 |
url += '/'; |
| 1377 |
} |
| 1378 |
|
| 1379 |
jQuery('#mainwp_managesites_add_wpurl').val(url); |
| 1380 |
|
| 1381 |
if (!isUrl(jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val())) { |
| 1382 |
errors.push(__('Please enter a valid URL for your site.')); |
| 1383 |
} |
| 1384 |
} |
| 1385 |
if (jQuery('#mainwp_managesites_add_wpadmin').val() == '') { |
| 1386 |
errors.push(__('Please enter a username of the website administrator.')); |
| 1387 |
} |
| 1388 |
|
| 1389 |
if (errors.length > 0) { |
| 1390 |
feedback('mainwp-message-zone', errors.join('<br />'), 'yellow'); |
| 1391 |
} else { |
| 1392 |
feedback('mainwp-message-zone', __('Adding the site to your MainWP Dashboard. Please wait...'), 'green'); |
| 1393 |
|
| 1394 |
jQuery('#mainwp_managesites_add').attr('disabled', 'true'); //disable button to add.. |
| 1395 |
|
| 1396 |
//Check if valid user & rulewp is installed? |
| 1397 |
var url = jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val(); |
| 1398 |
if (url.substr(-1) != '/') { |
| 1399 |
url += '/'; |
| 1400 |
} |
| 1401 |
|
| 1402 |
var name = jQuery('#mainwp_managesites_add_wpname').val(); |
| 1403 |
name = name.replace(/"/g, '"'); |
| 1404 |
|
| 1405 |
var data = mainwp_secure_data({ |
| 1406 |
action: 'mainwp_checkwp', |
| 1407 |
name: name, |
| 1408 |
url: url, |
| 1409 |
admin: jQuery('#mainwp_managesites_add_wpadmin').val(), |
| 1410 |
verify_certificate: jQuery('#mainwp_managesites_verify_certificate').is(':checked') ? 1 : 0, |
| 1411 |
http_user: jQuery('#mainwp_managesites_add_http_user').val(), |
| 1412 |
http_pass: jQuery('#mainwp_managesites_add_http_pass').val() |
| 1413 |
}); |
| 1414 |
|
| 1415 |
jQuery.post(ajaxurl, data, function (res_things) { |
| 1416 |
response = res_things.response; |
| 1417 |
response = jQuery.trim(response); |
| 1418 |
var url = jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val(); |
| 1419 |
if (url.substr(-1) != '/') { |
| 1420 |
url += '/'; |
| 1421 |
} |
| 1422 |
|
| 1423 |
url = url.replace(/"/g, '"'); |
| 1424 |
|
| 1425 |
var show_resp = __('Click %1here%2 to see response from the child site.', '<a href="javascript:void(0)" class="mainwp-show-response">', '</a>'); |
| 1426 |
|
| 1427 |
var resp_data = res_things.resp_data ? res_things.resp_data : ''; |
| 1428 |
if ('0' == resp_data) { |
| 1429 |
resp_data = ''; |
| 1430 |
} |
| 1431 |
jQuery('#mainwp-response-data-container').attr('resp-data', resp_data); |
| 1432 |
|
| 1433 |
if (response == 'HTTPERROR') { |
| 1434 |
errors.push(__('This site can not be reached! Please use the Test Connection feature and see if the positive response will be returned. For additional help, please review this <a href="https://kb.mainwp.com/docs/potential-issues/">Knowledgebase document</a>, and if you still have issues, please let us know in the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a>.')); |
| 1435 |
} else if (response == 'NOMAINWP') { |
| 1436 |
errors.push(__('MainWP Child plugin not detected or could not be reached! Ensure the MainWP Child plugin is installed and activated on the child site, and there are no security rules blocking requests. If you continue experiencing this issue, please review this <a href="https://kb.mainwp.com/docs/potential-issues/">Knowledgebase document</a>, and if you still have issues, please let us know in the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a>.')); |
| 1437 |
} else if (response.substr(0, 5) == 'ERROR') { |
| 1438 |
if (response.length == 5) { |
| 1439 |
errors.push(__('Undefined error occurred. Please try again. If the issue does not resolve, please review this <a href="https://kb.mainwp.com/docs/potential-issues/">Knowledgebase document</a>, and if you still have issues, please let us know in the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a>.')); |
| 1440 |
} else { |
| 1441 |
errors.push(__('Error detected: ') + response.substr(6)); |
| 1442 |
} |
| 1443 |
} else if (response == 'OK') { |
| 1444 |
jQuery('#mainwp_managesites_add').attr('disabled', 'true'); //Disable add button |
| 1445 |
|
| 1446 |
var name = jQuery('#mainwp_managesites_add_wpname').val(); |
| 1447 |
name = name.replace(/"/g, '"'); |
| 1448 |
var group_ids = jQuery('#mainwp_managesites_add_addgroups').dropdown('get value'); |
| 1449 |
var client_id = jQuery('#mainwp_managesites_add_client_id').dropdown('get value'); |
| 1450 |
var data = mainwp_secure_data({ |
| 1451 |
action: 'mainwp_addwp', |
| 1452 |
managesites_add_wpname: name, |
| 1453 |
managesites_add_wpurl: url, |
| 1454 |
managesites_add_wpadmin: jQuery('#mainwp_managesites_add_wpadmin').val(), |
| 1455 |
managesites_add_uniqueId: jQuery('#mainwp_managesites_add_uniqueId').val(), |
| 1456 |
groupids: group_ids, |
| 1457 |
clientid: client_id, |
| 1458 |
managesites_add_http_user: jQuery('#mainwp_managesites_add_http_user').val(), |
| 1459 |
managesites_add_http_pass: jQuery('#mainwp_managesites_add_http_pass').val(), |
| 1460 |
}); |
| 1461 |
|
| 1462 |
// to support add client reports tokens values |
| 1463 |
jQuery("input[name^='creport_token_']").each(function () { |
| 1464 |
var tname = jQuery(this).attr('name'); |
| 1465 |
var tvalue = jQuery(this).val(); |
| 1466 |
data[tname] = tvalue; |
| 1467 |
}); |
| 1468 |
|
| 1469 |
// support hooks fields |
| 1470 |
jQuery(".mainwp_addition_fields_addsite input").each(function () { |
| 1471 |
var tname = jQuery(this).attr('name'); |
| 1472 |
var tvalue = jQuery(this).val(); |
| 1473 |
data[tname] = tvalue; |
| 1474 |
}); |
| 1475 |
|
| 1476 |
jQuery.post(ajaxurl, data, function (res_things) { |
| 1477 |
var site_id = 0; |
| 1478 |
if (res_things.error) { |
| 1479 |
response = 'Error detected: ' + res_things.error; |
| 1480 |
} else { |
| 1481 |
response = res_things.response; |
| 1482 |
site_id = res_things.siteid; |
| 1483 |
} |
| 1484 |
response = jQuery.trim(response); |
| 1485 |
managesites_init(); |
| 1486 |
|
| 1487 |
resp_data = res_things.resp_data ? res_things.resp_data : ''; |
| 1488 |
if ('0' == resp_data) { |
| 1489 |
resp_data = ''; |
| 1490 |
} |
| 1491 |
jQuery('#mainwp-response-data-container').attr('resp-data', resp_data); |
| 1492 |
|
| 1493 |
if (response.substr(0, 5) == 'ERROR') { |
| 1494 |
jQuery('#mainwp-message-zone').removeClass('green'); |
| 1495 |
feedback('mainwp-message-zone', response.substr(6) + (resp_data != '' ? '<br>' + show_resp : ''), 'red'); |
| 1496 |
} else { |
| 1497 |
//Message the WP was added |
| 1498 |
jQuery('#mainwp-message-zone').removeClass('red'); |
| 1499 |
feedback('mainwp-message-zone', response, 'green'); |
| 1500 |
|
| 1501 |
if (site_id > 0) { |
| 1502 |
jQuery('.sync-ext-row').attr('status', 'queue'); |
| 1503 |
setTimeout(function () { |
| 1504 |
mainwp_managesites_sync_extension_start_next(site_id); |
| 1505 |
}, 1000); |
| 1506 |
} |
| 1507 |
|
| 1508 |
//Reset fields |
| 1509 |
jQuery('#mainwp_managesites_add_wpname').val(''); |
| 1510 |
jQuery('#mainwp_managesites_add_wpurl').val(''); |
| 1511 |
jQuery('#mainwp_managesites_add_wpurl_protocol').val('https'); |
| 1512 |
jQuery('#mainwp_managesites_add_wpadmin').val(''); |
| 1513 |
jQuery('#mainwp_managesites_add_uniqueId').val(''); |
| 1514 |
jQuery('#mainwp_managesites_add_addgroups').dropdown('clear'); |
| 1515 |
jQuery('#mainwp_managesites_verify_certificate').val(1); |
| 1516 |
|
| 1517 |
jQuery("input[name^='creport_token_']").each(function () { |
| 1518 |
jQuery(this).val(''); |
| 1519 |
}); |
| 1520 |
|
| 1521 |
// support hooks fields |
| 1522 |
jQuery(".mainwp_addition_fields_addsite input").each(function () { |
| 1523 |
jQuery(this).val(''); |
| 1524 |
}); |
| 1525 |
} |
| 1526 |
|
| 1527 |
jQuery('#mainwp_managesites_add').removeAttr('disabled'); //Enable add button |
| 1528 |
}, 'json'); |
| 1529 |
} |
| 1530 |
if (errors.length > 0) { |
| 1531 |
jQuery('#mainwp-message-zone').removeClass('green'); |
| 1532 |
managesites_init(); |
| 1533 |
jQuery('#mainwp_managesites_add').removeAttr('disabled'); //Enable add button |
| 1534 |
if (resp_data != '') { |
| 1535 |
errors.push(show_resp); |
| 1536 |
} |
| 1537 |
feedback('mainwp-message-zone', errors.join('<br />'), 'red'); |
| 1538 |
} |
| 1539 |
}, 'json'); |
| 1540 |
} |
| 1541 |
}; |
| 1542 |
|
| 1543 |
mainwp_managesites_sync_extension_start_next = function (siteId) { |
| 1544 |
while ((pluginToInstall = jQuery('.sync-ext-row[status="queue"]:first')) && (pluginToInstall.length > 0) && (bulkInstallCurrentThreads < 1 /* bulkInstallMaxThreads // to fix install plugins and apply settings failed issue */)) { |
| 1545 |
mainwp_managesites_sync_extension_start_specific(pluginToInstall, siteId); |
| 1546 |
} |
| 1547 |
|
| 1548 |
if ((pluginToInstall.length == 0) && (bulkInstallCurrentThreads == 0)) { |
| 1549 |
jQuery('#mwp_applying_ext_settings').remove(); |
| 1550 |
} |
| 1551 |
}; |
| 1552 |
|
| 1553 |
mainwp_managesites_sync_extension_start_specific = function (pPluginToInstall, pSiteId) { |
| 1554 |
pPluginToInstall.attr('status', 'progress'); |
| 1555 |
var syncGlobalSettings = pPluginToInstall.find(".sync-global-options input[type='checkbox']:checked").length > 0 ? true : false; |
| 1556 |
var install_plugin = pPluginToInstall.find(".sync-install-plugin input[type='checkbox']:checked").length > 0 ? true : false; |
| 1557 |
var apply_settings = pPluginToInstall.find(".sync-options input[type='checkbox']:checked").length > 0 ? true : false; |
| 1558 |
|
| 1559 |
if (syncGlobalSettings) { |
| 1560 |
mainwp_extension_apply_plugin_settings(pPluginToInstall, pSiteId, true); |
| 1561 |
} else if (install_plugin) { |
| 1562 |
mainwp_extension_prepareinstallplugin(pPluginToInstall, pSiteId); |
| 1563 |
} else if (apply_settings) { |
| 1564 |
mainwp_extension_apply_plugin_settings(pPluginToInstall, pSiteId, false); |
| 1565 |
} else { |
| 1566 |
mainwp_managesites_sync_extension_start_next(pSiteId); |
| 1567 |
return; |
| 1568 |
} |
| 1569 |
}; |
| 1570 |
|
| 1571 |
mainwp_extension_prepareinstallplugin = function (pPluginToInstall, pSiteId) { |
| 1572 |
var site_Ids = []; |
| 1573 |
site_Ids.push(pSiteId); |
| 1574 |
bulkInstallCurrentThreads++; |
| 1575 |
var plugin_slug = pPluginToInstall.find(".sync-install-plugin").attr('slug'); |
| 1576 |
var workingEl = pPluginToInstall.find(".sync-install-plugin i"); |
| 1577 |
var statusEl = pPluginToInstall.find(".sync-install-plugin span.status"); |
| 1578 |
|
| 1579 |
var data = { |
| 1580 |
action: 'mainwp_ext_prepareinstallplugintheme', |
| 1581 |
type: 'plugin', |
| 1582 |
slug: plugin_slug, |
| 1583 |
'selected_sites[]': site_Ids, |
| 1584 |
selected_by: 'site', |
| 1585 |
}; |
| 1586 |
|
| 1587 |
workingEl.show(); |
| 1588 |
statusEl.html(__('Preparing for installation...')); |
| 1589 |
|
| 1590 |
jQuery.post(ajaxurl, data, function (response) { |
| 1591 |
workingEl.hide(); |
| 1592 |
if (response.sites && response.sites[pSiteId]) { |
| 1593 |
statusEl.html(__('Installing...')); |
| 1594 |
var data = mainwp_secure_data({ |
| 1595 |
action: 'mainwp_ext_performinstallplugintheme', |
| 1596 |
type: 'plugin', |
| 1597 |
url: response.url, |
| 1598 |
siteId: pSiteId, |
| 1599 |
activatePlugin: true, |
| 1600 |
overwrite: false, |
| 1601 |
}); |
| 1602 |
workingEl.show(); |
| 1603 |
jQuery.post(ajaxurl, data, function (response) { |
| 1604 |
workingEl.hide(); |
| 1605 |
var apply_settings = false; |
| 1606 |
var syc_msg = ''; |
| 1607 |
var _success = false; |
| 1608 |
if ((response.ok != undefined) && (response.ok[pSiteId] != undefined)) { |
| 1609 |
syc_msg = __('Installation successful!'); |
| 1610 |
statusEl.html(syc_msg); |
| 1611 |
apply_settings = pPluginToInstall.find(".sync-options input[type='checkbox']:checked").length > 0 ? true : false; |
| 1612 |
if (apply_settings) { |
| 1613 |
mainwp_extension_apply_plugin_settings(pPluginToInstall, pSiteId, false); |
| 1614 |
} |
| 1615 |
_success = true; |
| 1616 |
} else if ((response.errors != undefined) && (response.errors[pSiteId] != undefined)) { |
| 1617 |
syc_msg = __('Installation failed!') + ': ' + response.errors[pSiteId][1]; |
| 1618 |
statusEl.html(syc_msg); |
| 1619 |
statusEl.css('color', 'red'); |
| 1620 |
} else { |
| 1621 |
syc_msg = __('Installation failed!'); |
| 1622 |
statusEl.html(syc_msg); |
| 1623 |
statusEl.css('color', 'red'); |
| 1624 |
} |
| 1625 |
|
| 1626 |
if (syc_msg != '') { |
| 1627 |
if (_success) |
| 1628 |
syc_msg = '<span style="color:#0073aa">' + syc_msg + '!</span>'; |
| 1629 |
else |
| 1630 |
syc_msg = '<span style="color:red">' + syc_msg + '!</span>'; |
| 1631 |
jQuery('#mainwp-message-zone').append(pPluginToInstall.find(".sync-install-plugin").attr('plugin_name') + ' ' + syc_msg + '<br/>'); |
| 1632 |
} |
| 1633 |
|
| 1634 |
if (!apply_settings) { |
| 1635 |
bulkInstallCurrentThreads--; |
| 1636 |
mainwp_managesites_sync_extension_start_next(pSiteId); |
| 1637 |
} |
| 1638 |
}, 'json'); |
| 1639 |
} else { |
| 1640 |
statusEl.css('color', 'red'); |
| 1641 |
statusEl.html(__('Error while preparing the installation. Please, try again.')); |
| 1642 |
bulkInstallCurrentThreads--; |
| 1643 |
} |
| 1644 |
}, 'json'); |
| 1645 |
} |
| 1646 |
|
| 1647 |
mainwp_extension_apply_plugin_settings = function (pPluginToInstall, pSiteId, pGlobal) { |
| 1648 |
var extSlug = pPluginToInstall.attr('slug'); |
| 1649 |
var workingEl = pPluginToInstall.find(".options-row i"); |
| 1650 |
var statusEl = pPluginToInstall.find(".options-row span.status"); |
| 1651 |
if (pGlobal) |
| 1652 |
bulkInstallCurrentThreads++; |
| 1653 |
|
| 1654 |
var data = mainwp_secure_data({ |
| 1655 |
action: 'mainwp_ext_applypluginsettings', |
| 1656 |
ext_dir_slug: extSlug, |
| 1657 |
siteId: pSiteId |
| 1658 |
}); |
| 1659 |
|
| 1660 |
workingEl.show(); |
| 1661 |
statusEl.html(__('Applying settings...')); |
| 1662 |
jQuery.post(ajaxurl, data, function (response) { |
| 1663 |
workingEl.hide(); |
| 1664 |
var syc_msg = ''; |
| 1665 |
var _success = false; |
| 1666 |
if (response) { |
| 1667 |
if (response.result && response.result == 'success') { |
| 1668 |
var msg = ''; |
| 1669 |
if (response.message != undefined) { |
| 1670 |
msg = ' ' + response.message; |
| 1671 |
} |
| 1672 |
statusEl.html(__('Applying settings successful!') + msg); |
| 1673 |
syc_msg = __('Successful'); |
| 1674 |
_success = true |
| 1675 |
} else if (response.error != undefined) { |
| 1676 |
statusEl.html(__('Applying settings failed!') + ': ' + response.error); |
| 1677 |
statusEl.css('color', 'red'); |
| 1678 |
syc_msg = __('failed'); |
| 1679 |
} else { |
| 1680 |
statusEl.html(__('Applying settings failed!')); |
| 1681 |
statusEl.css('color', 'red'); |
| 1682 |
syc_msg = __('failed'); |
| 1683 |
} |
| 1684 |
} else { |
| 1685 |
statusEl.html(__('Undefined error!')); |
| 1686 |
statusEl.css('color', 'red'); |
| 1687 |
syc_msg = __('failed'); |
| 1688 |
} |
| 1689 |
|
| 1690 |
if (syc_msg != '') { |
| 1691 |
if (_success) |
| 1692 |
syc_msg = '<span style="color:#0073aa">' + syc_msg + '!</span>'; |
| 1693 |
else |
| 1694 |
syc_msg = '<span style="color:red">' + syc_msg + '!</span>'; |
| 1695 |
if (pGlobal) { |
| 1696 |
syc_msg = __('Apply global %1 options', pPluginToInstall.attr('ext_name')) + ' ' + syc_msg + '<br/>'; |
| 1697 |
} else { |
| 1698 |
syc_msg = __('Apply %1 settings', pPluginToInstall.find('.sync-install-plugin').attr('plugin_name')) + ' ' + syc_msg + '<br/>'; |
| 1699 |
} |
| 1700 |
jQuery('#mainwp-message-zone').append(syc_msg); |
| 1701 |
} |
| 1702 |
bulkInstallCurrentThreads--; |
| 1703 |
mainwp_managesites_sync_extension_start_next(pSiteId); |
| 1704 |
}, 'json'); |
| 1705 |
} |
| 1706 |
|
| 1707 |
// Test Connection (Add Site Page) |
| 1708 |
mainwp_managesites_test = function () { |
| 1709 |
|
| 1710 |
var errors = []; |
| 1711 |
|
| 1712 |
if (jQuery('#mainwp_managesites_add_wpurl').val() == '') { |
| 1713 |
errors.push(__('Please enter a valid URL for your site.')); |
| 1714 |
} else { |
| 1715 |
var clean_url = jQuery('#mainwp_managesites_add_wpurl').val(); |
| 1716 |
var protocol = jQuery('#mainwp_managesites_add_wpurl_protocol').val(); |
| 1717 |
url = protocol + '://' + clean_url; |
| 1718 |
if (url.substr(-1) != '/') { |
| 1719 |
url += '/'; |
| 1720 |
} |
| 1721 |
|
| 1722 |
if (!isUrl(url)) { |
| 1723 |
errors.push(__('Please enter a valid URL for your site')); |
| 1724 |
} |
| 1725 |
} |
| 1726 |
|
| 1727 |
if (errors.length > 0) { |
| 1728 |
feedback('mainwp-message-zone', errors.join('<br />'), 'red'); |
| 1729 |
} else { |
| 1730 |
jQuery('#mainwp-test-connection-modal').modal('setting', 'closable', false).modal('show'); |
| 1731 |
jQuery('#mainwp-test-connection-modal .dimmer').show(); |
| 1732 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').hide(); |
| 1733 |
|
| 1734 |
var clean_url = jQuery('#mainwp_managesites_add_wpurl').val(); |
| 1735 |
var protocol = jQuery('#mainwp_managesites_add_wpurl_protocol').val(); |
| 1736 |
url = protocol + '://' + clean_url; |
| 1737 |
|
| 1738 |
if (url.substr(-1) != '/') { |
| 1739 |
url += '/'; |
| 1740 |
} |
| 1741 |
|
| 1742 |
var data = mainwp_secure_data({ |
| 1743 |
action: 'mainwp_testwp', |
| 1744 |
url: url, |
| 1745 |
test_verify_cert: jQuery('#mainwp_managesites_verify_certificate').val(), |
| 1746 |
http_user: jQuery('#mainwp_managesites_add_http_user').val(), |
| 1747 |
http_pass: jQuery('#mainwp_managesites_add_http_pass').val() |
| 1748 |
}); |
| 1749 |
|
| 1750 |
jQuery.post(ajaxurl, data, function (response) { |
| 1751 |
jQuery('#mainwp-test-connection-modal .dimmer').hide(); |
| 1752 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').removeClass('red green check times'); |
| 1753 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(''); |
| 1754 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(''); |
| 1755 |
if (response.error) { |
| 1756 |
if (response.httpCode) { |
| 1757 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); |
| 1758 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); |
| 1759 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(__('Connection failed!')); |
| 1760 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(__('URL:') + ' ' + response.host + ' - ' + __('HTTP-code:') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '') + ' - ' + __('Error message: ') + ' ' + response.error); |
| 1761 |
} else { |
| 1762 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); |
| 1763 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); |
| 1764 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(__('Connection test failed.')); |
| 1765 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(__('Error message:') + ' ' + response.error); |
| 1766 |
} |
| 1767 |
} else if (response.httpCode) { |
| 1768 |
if (response.httpCode == '200') { |
| 1769 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); |
| 1770 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('green check'); |
| 1771 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(__('Connection successful!')); |
| 1772 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(__('URL:') + ' ' + response.host + (response.ip != undefined ? ' (IP: ' + response.ip + ')' : '') + ' - ' + __('Received HTTP-code') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '')); |
| 1773 |
} else { |
| 1774 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); |
| 1775 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); |
| 1776 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(__('Connection test failed.')); |
| 1777 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(__('URL:') + ' ' + response.host + (response.ip != undefined ? ' (IP: ' + response.ip + ')' : '') + ' - ' + __('Received HTTP-code:') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '')); |
| 1778 |
} |
| 1779 |
} else { |
| 1780 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(''); |
| 1781 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); |
| 1782 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(__('Connection test failed.')); |
| 1783 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(__('Invalid response from the server, please try again.')); |
| 1784 |
} |
| 1785 |
}, 'json'); |
| 1786 |
} |
| 1787 |
}; |
| 1788 |
|
| 1789 |
// Test Connection (Edit Site Page) |
| 1790 |
mainwp_managesites_edit_test = function () { |
| 1791 |
|
| 1792 |
var clean_url = jQuery('#mainwp_managesites_edit_siteurl').val(); |
| 1793 |
var protocol = jQuery('#mainwp_managesites_edit_siteurl_protocol').val(); |
| 1794 |
|
| 1795 |
url = protocol + '://' + clean_url; |
| 1796 |
|
| 1797 |
if (url.substr(-1) != '/') { |
| 1798 |
url += '/'; |
| 1799 |
} |
| 1800 |
|
| 1801 |
jQuery('#mainwp-test-connection-modal').modal('setting', 'closable', false).modal('show'); |
| 1802 |
jQuery('#mainwp-test-connection-modal .dimmer').show(); |
| 1803 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').hide(); |
| 1804 |
|
| 1805 |
var data = mainwp_secure_data({ |
| 1806 |
action: 'mainwp_testwp', |
| 1807 |
url: url, |
| 1808 |
test_verify_cert: jQuery('#mainwp_managesites_edit_verifycertificate').val(), |
| 1809 |
http_user: jQuery('#mainwp_managesites_edit_http_user').val(), |
| 1810 |
http_pass: jQuery('#mainwp_managesites_edit_http_pass').val() |
| 1811 |
}); |
| 1812 |
|
| 1813 |
jQuery.post(ajaxurl, data, function (response) { |
| 1814 |
jQuery('#mainwp-test-connection-modal .dimmer').hide(); |
| 1815 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').removeClass('red green check times'); |
| 1816 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(''); |
| 1817 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(''); |
| 1818 |
if (response.error) { |
| 1819 |
if (response.httpCode) { |
| 1820 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); |
| 1821 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); |
| 1822 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(__('Connection failed!')); |
| 1823 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(__('URL:') + ' ' + response.host + ' - ' + __('HTTP-code:') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '') + ' - ' + __('Error message: ') + ' ' + response.error); |
| 1824 |
} else { |
| 1825 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); |
| 1826 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); |
| 1827 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(__('Connection test failed.')); |
| 1828 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(__('Error message:') + ' ' + response.error); |
| 1829 |
} |
| 1830 |
} else if (response.httpCode) { |
| 1831 |
if (response.httpCode == '200') { |
| 1832 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); |
| 1833 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('green check'); |
| 1834 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(__('Connection successful!')); |
| 1835 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(__('URL:') + ' ' + response.host + (response.ip != undefined ? ' (IP: ' + response.ip + ')' : '') + ' - ' + __('Received HTTP-code') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '')); |
| 1836 |
} else { |
| 1837 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); |
| 1838 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); |
| 1839 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(__('Connection test failed.')); |
| 1840 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(__('URL:') + ' ' + response.host + (response.ip != undefined ? ' (IP: ' + response.ip + ')' : '') + ' - ' + __('Received HTTP-code:') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '')); |
| 1841 |
} |
| 1842 |
} else { |
| 1843 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(''); |
| 1844 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); |
| 1845 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(__('Connection test failed.')); |
| 1846 |
jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(__('Invalid response from the server, please try again.')); |
| 1847 |
} |
| 1848 |
}, 'json'); |
| 1849 |
}; |
| 1850 |
|
| 1851 |
managesites_remove = function (obj) { |
| 1852 |
managesites_init(); |
| 1853 |
|
| 1854 |
var name = jQuery(obj).attr('site-name'); |
| 1855 |
var id = jQuery(obj).attr('site-id'); |
| 1856 |
|
| 1857 |
var msg = sprintf(__('Are you sure you want to remove %1 from your MainWP Dashboard?', name)); |
| 1858 |
|
| 1859 |
mainwp_confirm(msg, function () { |
| 1860 |
jQuery('tr#child-site-' + id).html('<td colspan="999"><i class="notched circle loading icon"></i> ' + 'Removing and deactivating the MainWP Child plugin! Please wait...' + '</td>'); |
| 1861 |
var data = mainwp_secure_data({ |
| 1862 |
action: 'mainwp_removesite', |
| 1863 |
id: id |
| 1864 |
}); |
| 1865 |
|
| 1866 |
jQuery.post(ajaxurl, data, function (response) { |
| 1867 |
|
| 1868 |
managesites_init(); |
| 1869 |
|
| 1870 |
var result = ''; |
| 1871 |
var error = ''; |
| 1872 |
|
| 1873 |
if (response.error != undefined) { |
| 1874 |
error = response.error; |
| 1875 |
} else if (response.result == 'SUCCESS') { |
| 1876 |
result = '<i class="close icon"></i>' + __('The site has been removed and the MainWP Child plugin has been disabled.'); |
| 1877 |
} else if (response.result == 'NOSITE') { |
| 1878 |
error = '<i class="close icon"></i>' + __('The requested site has not been found.'); |
| 1879 |
} else { |
| 1880 |
result = '<i class="close icon"></i>' + __('The site has been removed. Please make sure that the MainWP Child plugin has been deactivated properly.'); |
| 1881 |
} |
| 1882 |
|
| 1883 |
if (error != '') { |
| 1884 |
feedback('mainwp-message-zone', error, 'red'); |
| 1885 |
} |
| 1886 |
|
| 1887 |
if (result != '') { |
| 1888 |
feedback('mainwp-message-zone', result, 'green'); |
| 1889 |
} |
| 1890 |
|
| 1891 |
jQuery('tr#child-site-' + id).remove(); |
| 1892 |
|
| 1893 |
}, 'json'); |
| 1894 |
}, false, false, false, 'REMOVE'); |
| 1895 |
return false; |
| 1896 |
}; |
| 1897 |
|
| 1898 |
jQuery(document).ready(function () { |
| 1899 |
|
| 1900 |
jQuery(document).on('click', '#mainwp_managesites_add', function (event) { |
| 1901 |
mainwp_managesites_add(event); |
| 1902 |
}); |
| 1903 |
|
| 1904 |
jQuery(document).on('click', '#mainwp_managesites_bulkadd', function () { |
| 1905 |
if (jQuery('#mainwp_managesites_file_bulkupload').val() == '') { |
| 1906 |
setHtml('#mainwp-message-zone', __('Please enter csv file for upload.'), false); |
| 1907 |
} else { |
| 1908 |
jQuery('#mainwp_managesites_bulkadd_form').submit(); |
| 1909 |
} |
| 1910 |
return false; |
| 1911 |
}); |
| 1912 |
|
| 1913 |
// Trigger Connection Test (Add Site Page) |
| 1914 |
jQuery(document).on('click', '#mainwp_managesites_test', function (event) { |
| 1915 |
mainwp_managesites_test(event); |
| 1916 |
}); |
| 1917 |
|
| 1918 |
// Trigger Connection Test (Edit Site Page) |
| 1919 |
jQuery(document).on('click', '#mainwp_managesites_edit_test', function (event) { |
| 1920 |
mainwp_managesites_edit_test(event); |
| 1921 |
}); |
| 1922 |
|
| 1923 |
}); |
| 1924 |
|
| 1925 |
/** |
| 1926 |
* Add new user |
| 1927 |
*/ |
| 1928 |
jQuery(document).ready(function () { |
| 1929 |
jQuery(document).on('click', '#bulk_add_createuser', function (event) { |
| 1930 |
mainwp_createuser(event); |
| 1931 |
}); |
| 1932 |
jQuery('#bulk_import_createuser').on('click', function () { |
| 1933 |
mainwp_bulkupload_users(); |
| 1934 |
}); |
| 1935 |
}); |
| 1936 |
|
| 1937 |
mainwp_createuser = function () { |
| 1938 |
var cont = true; |
| 1939 |
if (jQuery('#user_login').val() == '') { |
| 1940 |
feedback('mainwp-message-zone', __('Username field is required! Please enter a username.'), 'yellow'); |
| 1941 |
cont = false; |
| 1942 |
} |
| 1943 |
|
| 1944 |
if (jQuery('#email').val() == '') { |
| 1945 |
feedback('mainwp-message-zone', __('E-mail field is required! Please enter an email address.'), 'yellow'); |
| 1946 |
cont = false; |
| 1947 |
} |
| 1948 |
|
| 1949 |
if (jQuery('#password').val() == '') { |
| 1950 |
feedback('mainwp-message-zone', __('Password field is required! Please enter the wanted password or generate a random one.'), 'yellow'); |
| 1951 |
cont = false; |
| 1952 |
} |
| 1953 |
|
| 1954 |
if (jQuery('#select_by').val() == 'site') { |
| 1955 |
var selected_sites = []; |
| 1956 |
jQuery("input[name='selected_sites[]']:checked").each(function () { |
| 1957 |
selected_sites.push(jQuery(this).val()); |
| 1958 |
}); |
| 1959 |
if (selected_sites.length == 0) { |
| 1960 |
feedback('mainwp-message-zone', __('Please select at least one website or group or client.'), 'yellow'); |
| 1961 |
cont = false; |
| 1962 |
} |
| 1963 |
} else if (jQuery('#select_by').val() == 'client') { |
| 1964 |
var selected_clients = []; |
| 1965 |
jQuery("input[name='selected_clients[]']:checked").each(function () { |
| 1966 |
selected_clients.push(jQuery(this).val()); |
| 1967 |
}); |
| 1968 |
if (selected_clients.length == 0) { |
| 1969 |
feedback('mainwp-message-zone', __('Please select at least one website or group or client.'), 'yellow'); |
| 1970 |
cont = false; |
| 1971 |
} |
| 1972 |
} else { |
| 1973 |
var selected_groups = []; |
| 1974 |
jQuery("input[name='selected_groups[]']:checked").each(function () { |
| 1975 |
selected_groups.push(jQuery(this).val()); |
| 1976 |
}); |
| 1977 |
if (selected_groups.length == 0) { |
| 1978 |
feedback('mainwp-message-zone', __('Please select at least one website or group or client.'), 'yellow'); |
| 1979 |
cont = false; |
| 1980 |
} |
| 1981 |
} |
| 1982 |
|
| 1983 |
if (cont) { |
| 1984 |
jQuery('#mainwp-message-zone').removeClass('red green yellow'); |
| 1985 |
jQuery('#mainwp-message-zone').html('<i class="notched circle loading icon"></i> ' + __('Creating the user. Please wait...')); |
| 1986 |
jQuery('#mainwp-message-zone').show(); |
| 1987 |
jQuery('#bulk_add_createuser').attr('disabled', 'disabled'); |
| 1988 |
//Add user via ajax!! |
| 1989 |
var data = mainwp_secure_data({ |
| 1990 |
action: 'mainwp_bulkadduser', |
| 1991 |
'select_by': jQuery('#select_by').val(), |
| 1992 |
'selected_groups[]': selected_groups, |
| 1993 |
'selected_sites[]': selected_sites, |
| 1994 |
'selected_clients[]': selected_clients, |
| 1995 |
'user_login': jQuery('#user_login').val(), |
| 1996 |
'email': jQuery('#email').val(), |
| 1997 |
'url': jQuery('#url').val(), |
| 1998 |
'first_name': jQuery('#first_name').val(), |
| 1999 |
'last_name': jQuery('#last_name').val(), |
| 2000 |
'pass1': jQuery('#password').val(), |
| 2001 |
'pass2': jQuery('#password').val(), |
| 2002 |
'send_password': jQuery('#send_password').attr('checked'), |
| 2003 |
'role': jQuery('#role').val() |
| 2004 |
}); |
| 2005 |
|
| 2006 |
jQuery.post(ajaxurl, data, function (response) { |
| 2007 |
response = jQuery.trim(response); |
| 2008 |
jQuery('#mainwp-message-zone').hide(); |
| 2009 |
jQuery('#bulk_add_createuser').removeAttr('disabled'); |
| 2010 |
if (response.substring(0, 5) == 'ERROR') { |
| 2011 |
var responseObj = jQuery.parseJSON(response.substring(6)); |
| 2012 |
if (responseObj.error == undefined) { |
| 2013 |
var errorMessageList = responseObj[1]; |
| 2014 |
var errorMessage = ''; |
| 2015 |
for (var i = 0; i < errorMessageList.length; i++) { |
| 2016 |
if (errorMessage != '') |
| 2017 |
errorMessage = errorMessage + "<br />"; |
| 2018 |
errorMessage = errorMessage + errorMessageList[i]; |
| 2019 |
} |
| 2020 |
if (errorMessage != '') { |
| 2021 |
feedback('mainwp-message-zone', errorMessage, 'red'); |
| 2022 |
} |
| 2023 |
} |
| 2024 |
} else { |
| 2025 |
jQuery('#mainwp-add-new-user-form').append(response); |
| 2026 |
jQuery('#mainwp-creating-new-user-modal').modal('setting', 'closable', false).modal('show'); |
| 2027 |
|
| 2028 |
} |
| 2029 |
}); |
| 2030 |
} |
| 2031 |
}; |
| 2032 |
|
| 2033 |
/** |
| 2034 |
* InstallPlugins/Themes |
| 2035 |
*/ |
| 2036 |
jQuery(document).ready(function () { |
| 2037 |
jQuery('#MainWPInstallBulkNavSearch').on('click', function (event) { |
| 2038 |
event.preventDefault(); |
| 2039 |
jQuery('#mainwp_plugin_bulk_install_btn').attr('bulk-action', 'install'); |
| 2040 |
jQuery('.mainwp-browse-plugins').show(); |
| 2041 |
jQuery('.mainwp-upload-plugin').hide(); |
| 2042 |
jQuery('#mainwp-search-plugins-form').show(); |
| 2043 |
}); |
| 2044 |
jQuery('#MainWPInstallBulkNavUpload').on('click', function (event) { |
| 2045 |
event.preventDefault(); |
| 2046 |
jQuery('#mainwp_plugin_bulk_install_btn').attr('bulk-action', 'upload'); |
| 2047 |
jQuery('.mainwp-upload-plugin').show(); |
| 2048 |
jQuery('.mainwp-browse-plugins').hide(); |
| 2049 |
jQuery('#mainwp-search-plugins-form').hide(); |
| 2050 |
}); |
| 2051 |
|
| 2052 |
// not used? |
| 2053 |
jQuery(document).on('click', '.filter-links li.plugin-install a', function (event) { |
| 2054 |
event.preventDefault(); |
| 2055 |
jQuery('.filter-links li.plugin-install a').removeClass('current'); |
| 2056 |
jQuery(this).addClass('current'); |
| 2057 |
var tab = jQuery(this).parent().attr('tab'); |
| 2058 |
if (tab == 'search') { |
| 2059 |
mainwp_install_search(event); |
| 2060 |
} else { |
| 2061 |
jQuery('#mainwp_installbulk_s').val(''); |
| 2062 |
jQuery('#mainwp_installbulk_tab').val(tab); |
| 2063 |
mainwp_install_plugin_tab_search('tab:' + tab); |
| 2064 |
} |
| 2065 |
}); |
| 2066 |
|
| 2067 |
jQuery(document).on('click', '#mainwp_plugin_bulk_install_btn', function () { |
| 2068 |
var act = jQuery(this).attr('bulk-action'); |
| 2069 |
if (act == 'install') { |
| 2070 |
var selected = jQuery("input[type='radio'][name='install-plugin']:checked"); |
| 2071 |
if (selected.length == 0) { |
| 2072 |
feedback('mainwp-message-zone', __('Please select plugin to install files.'), 'yellow'); |
| 2073 |
} else { |
| 2074 |
var selectedId = /^install-([^-]*)-(.*)$/.exec(selected.attr('id')); |
| 2075 |
if (selectedId) { |
| 2076 |
mainwp_install_bulk('plugin', selectedId[2]); |
| 2077 |
} |
| 2078 |
} |
| 2079 |
} else if (act == 'upload') { |
| 2080 |
mainwp_upload_bulk('plugins'); |
| 2081 |
} |
| 2082 |
|
| 2083 |
return false; |
| 2084 |
}); |
| 2085 |
|
| 2086 |
jQuery(document).on('click', '#mainwp_theme_bulk_install_btn', function () { |
| 2087 |
var act = jQuery(this).attr('bulk-action'); |
| 2088 |
if (act == 'install') { |
| 2089 |
var selected = jQuery("input[type='radio'][name='install-theme']:checked"); |
| 2090 |
if (selected.length == 0) { |
| 2091 |
feedback('mainwp-message-zone', __('Please select theme to install files.'), 'yellow'); |
| 2092 |
} else { |
| 2093 |
var selectedId = /^install-([^-]*)-(.*)$/.exec(selected.attr('id')); |
| 2094 |
if (selectedId) |
| 2095 |
mainwp_install_bulk('theme', selectedId[2]); |
| 2096 |
} |
| 2097 |
} else if (act == 'upload') { |
| 2098 |
mainwp_upload_bulk('themes'); |
| 2099 |
} |
| 2100 |
return false; |
| 2101 |
}); |
| 2102 |
}); |
| 2103 |
|
| 2104 |
// Generate the Go to WP Admin link |
| 2105 |
mainwp_links_visit_site_and_admin = function (url, siteId) { |
| 2106 |
var links = ''; |
| 2107 |
if (url != '') { |
| 2108 |
links += '<a href="' + url + '" target="_blank" class="mainwp-may-hide-referrer"><i class="external alternate icon"></i></a> '; |
| 2109 |
} |
| 2110 |
links += '<a href="admin.php?page=SiteOpen&newWindow=yes&websiteid=' + siteId + '&_opennonce=' + mainwpParams._wpnonce + '" target="_blank"><i class="sign in alternate icon"></i></a>'; |
| 2111 |
return links; |
| 2112 |
} |
| 2113 |
|
| 2114 |
bulkInstallTotal = 0; |
| 2115 |
bulkInstallDone = 0; |
| 2116 |
|
| 2117 |
/** |
| 2118 |
* Install Plugin/Theme from WP.org. |
| 2119 |
* |
| 2120 |
* Initiate the process. |
| 2121 |
* |
| 2122 |
* @param string type Plugin or theme. |
| 2123 |
* @param string slug Plugin or theme slug. |
| 2124 |
* |
| 2125 |
* @return void |
| 2126 |
*/ |
| 2127 |
mainwp_install_bulk = function (type, slug) { |
| 2128 |
var data = mainwp_secure_data({ |
| 2129 |
action: 'mainwp_preparebulkinstallplugintheme', |
| 2130 |
type: type, |
| 2131 |
slug: slug, |
| 2132 |
selected_by: jQuery('#select_by').val() |
| 2133 |
}); |
| 2134 |
|
| 2135 |
var placeholder = '<div class="ui placeholder"><div class="paragraph"><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div></div></div>'; |
| 2136 |
|
| 2137 |
if (jQuery('#select_by').val() == 'site') { |
| 2138 |
|
| 2139 |
var selected_sites = []; |
| 2140 |
|
| 2141 |
jQuery("input[name='selected_sites[]']:checked").each(function () { |
| 2142 |
selected_sites.push(jQuery(this).val()); |
| 2143 |
}); |
| 2144 |
|
| 2145 |
if (selected_sites.length == 0) { |
| 2146 |
feedback('mainwp-message-zone', __('Please select at least one website or a group or client.', 'mainwp'), 'yellow'); |
| 2147 |
return; |
| 2148 |
} |
| 2149 |
|
| 2150 |
data['selected_sites[]'] = selected_sites; |
| 2151 |
|
| 2152 |
} else if (jQuery('#select_by').val() == 'client') { |
| 2153 |
|
| 2154 |
var selected_clients = []; |
| 2155 |
|
| 2156 |
jQuery("input[name='selected_clients[]']:checked").each(function () { |
| 2157 |
selected_clients.push(jQuery(this).val()); |
| 2158 |
}); |
| 2159 |
|
| 2160 |
if (selected_clients.length == 0) { |
| 2161 |
feedback('mainwp-message-zone', __('Please select at least one website or a group or client.', 'mainwp'), 'yellow'); |
| 2162 |
return; |
| 2163 |
} |
| 2164 |
|
| 2165 |
data['selected_clients[]'] = selected_clients; |
| 2166 |
|
| 2167 |
} else { |
| 2168 |
var selected_groups = []; |
| 2169 |
|
| 2170 |
jQuery("input[name='selected_groups[]']:checked").each(function () { |
| 2171 |
selected_groups.push(jQuery(this).val()); |
| 2172 |
}); |
| 2173 |
|
| 2174 |
if (selected_groups.length == 0) { |
| 2175 |
feedback('mainwp-message-zone', __('Please select at least one website or a group or client.', 'mainwp'), 'yellow'); |
| 2176 |
return; |
| 2177 |
} |
| 2178 |
|
| 2179 |
data['selected_groups[]'] = selected_groups; |
| 2180 |
|
| 2181 |
} |
| 2182 |
|
| 2183 |
jQuery('#plugintheme-installation-queue').html(placeholder); |
| 2184 |
|
| 2185 |
jQuery.post(ajaxurl, data, function (type, activatePlugin, overwrite) { |
| 2186 |
return function (response) { |
| 2187 |
var installQueueContent = ''; |
| 2188 |
var dateObj = new Date(); |
| 2189 |
|
| 2190 |
starttimeDashboardAction = dateObj.getTime(); |
| 2191 |
|
| 2192 |
if (type == 'plugin') { |
| 2193 |
dashboardActionName = 'installing_new_plugin'; |
| 2194 |
} else { |
| 2195 |
dashboardActionName = 'installing_new_theme'; |
| 2196 |
} |
| 2197 |
|
| 2198 |
countRealItemsUpdated = 0; |
| 2199 |
|
| 2200 |
bulkInstallDone = 0; |
| 2201 |
|
| 2202 |
installQueueContent += '<div id="bulk_install_info"></div>'; |
| 2203 |
installQueueContent += '<div class="ui middle aligned divided selection list">'; |
| 2204 |
|
| 2205 |
for (var siteId in response.sites) { |
| 2206 |
var site = response.sites[siteId]; |
| 2207 |
installQueueContent += |
| 2208 |
'<div class="siteBulkInstall item" siteid="' + siteId + '" status="queue">' + |
| 2209 |
'<div class="right floated content">' + |
| 2210 |
'<span class="queue" data-inverted="" data-position="left center" data-tooltip="' + __('Queued', 'mainwp') + '"><i class="clock outline icon"></i></span>' + |
| 2211 |
'<span class="progress" data-inverted="" data-position="left center" data-tooltip="' + __('Installing...', 'mainwp') + '" style="display:none"><i class="notched circle loading icon"></i></span>' + |
| 2212 |
'<span class="status"></span>' + |
| 2213 |
'</div>' + |
| 2214 |
'<div class="content">' + mainwp_links_visit_site_and_admin('', siteId) + ' ' + '<a href="' + site['url'] + '">' + site['name'].replace(/\\(.)/mg, "$1") + '</a></div>' + |
| 2215 |
'</div>'; |
| 2216 |
bulkInstallTotal++; |
| 2217 |
} |
| 2218 |
|
| 2219 |
installQueueContent += '</div>'; |
| 2220 |
|
| 2221 |
jQuery('#plugintheme-installation-queue').html(installQueueContent); |
| 2222 |
jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').progress({ value: 0, total: bulkInstallTotal }); |
| 2223 |
mainwp_install_bulk_start_next(type, response.url, activatePlugin, overwrite); |
| 2224 |
} |
| 2225 |
}(type, jQuery('#chk_activate_plugin').is(':checked'), jQuery('#chk_overwrite').is(':checked')), 'json'); |
| 2226 |
|
| 2227 |
jQuery('#plugintheme-installation-progress-modal').modal('setting', 'closable', false).modal('show'); |
| 2228 |
|
| 2229 |
}; |
| 2230 |
|
| 2231 |
bulkInstallMaxThreads = mainwpParams['maximumInstallUpdateRequests'] == undefined ? 3 : mainwpParams['maximumInstallUpdateRequests']; |
| 2232 |
bulkInstallCurrentThreads = 0; |
| 2233 |
|
| 2234 |
/** |
| 2235 |
* Install Plugin/Theme from WP.org. |
| 2236 |
* |
| 2237 |
* Loop through sites. |
| 2238 |
* |
| 2239 |
* @param string type Plugin or theme. |
| 2240 |
* @param string url URL. |
| 2241 |
* @param bool activatePlugin Determines if the item should be activated or not upon installation. |
| 2242 |
* @param bool overwrite Determines if the item should overwrite exisitng version. |
| 2243 |
* |
| 2244 |
* @return void |
| 2245 |
*/ |
| 2246 |
mainwp_install_bulk_start_next = function (type, url, activatePlugin, overwrite) { |
| 2247 |
while ((siteToInstall = jQuery('.siteBulkInstall[status="queue"]:first')) && (siteToInstall.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { |
| 2248 |
mainwp_install_bulk_start_specific(type, url, activatePlugin, overwrite, siteToInstall); |
| 2249 |
} |
| 2250 |
|
| 2251 |
if (bulkInstallDone == bulkInstallTotal && bulkInstallTotal != 0) { |
| 2252 |
if (mainwpParams.enabledTwit == true) { |
| 2253 |
var dateObj = new Date(); |
| 2254 |
var countSec = (dateObj.getTime() - starttimeDashboardAction) / 1000; |
| 2255 |
if (countSec <= mainwpParams.maxSecondsTwit) { |
| 2256 |
var data = mainwp_secure_data({ |
| 2257 |
action: 'mainwp_twitter_dashboard_action', |
| 2258 |
actionName: dashboardActionName, |
| 2259 |
countSites: countRealItemsUpdated, |
| 2260 |
countSeconds: countSec, |
| 2261 |
countItems: 1, |
| 2262 |
countRealItems: countRealItemsUpdated, |
| 2263 |
showNotice: 1 |
| 2264 |
}); |
| 2265 |
jQuery.post(ajaxurl, data, function (res) { |
| 2266 |
if (res && res != '') { |
| 2267 |
jQuery('#bulk_install_info').html(res); |
| 2268 |
if (typeof twttr !== "undefined") |
| 2269 |
twttr.widgets.load(); |
| 2270 |
} else { |
| 2271 |
jQuery('#bulk_install_info').html(''); |
| 2272 |
} |
| 2273 |
}); |
| 2274 |
} |
| 2275 |
} |
| 2276 |
jQuery('#bulk_install_info').before('<div class="ui info message">' + mainwp_install_bulk_you_know_msg(type, 1) + '</div>'); |
| 2277 |
} |
| 2278 |
|
| 2279 |
}; |
| 2280 |
|
| 2281 |
/** |
| 2282 |
* Install Plugin/Theme from WP.org. |
| 2283 |
* |
| 2284 |
* Install specific item. |
| 2285 |
* |
| 2286 |
* @param string type Plugin or theme. |
| 2287 |
* @param string url URL. |
| 2288 |
* @param bool activatePlugin Determines if the item should be activated or not upon installation. |
| 2289 |
* @param bool overwrite Determines if the item should overwrite exisitng version. |
| 2290 |
* @param object siteToInstall Site to install the item to. |
| 2291 |
* |
| 2292 |
* @return void |
| 2293 |
*/ |
| 2294 |
mainwp_install_bulk_start_specific = function (type, url, activatePlugin, overwrite, siteToInstall) { |
| 2295 |
bulkInstallCurrentThreads++; |
| 2296 |
|
| 2297 |
siteToInstall.attr('status', 'progress'); |
| 2298 |
siteToInstall.find('.queue').hide(); |
| 2299 |
siteToInstall.find('.progress').show(); |
| 2300 |
|
| 2301 |
var data = mainwp_secure_data({ |
| 2302 |
action: 'mainwp_installbulkinstallplugintheme', |
| 2303 |
type: type, |
| 2304 |
url: url, |
| 2305 |
activatePlugin: activatePlugin, |
| 2306 |
overwrite: overwrite, |
| 2307 |
siteId: siteToInstall.attr('siteid') |
| 2308 |
}); |
| 2309 |
|
| 2310 |
jQuery.post(ajaxurl, data, function (type, url, activatePlugin, overwrite, siteToInstall) { |
| 2311 |
return function (response) { |
| 2312 |
siteToInstall.attr('status', 'done'); |
| 2313 |
siteToInstall.find('.progress').hide(); |
| 2314 |
|
| 2315 |
var statusEl = siteToInstall.find('.status'); |
| 2316 |
statusEl.show(); |
| 2317 |
|
| 2318 |
if (response.error != undefined) { |
| 2319 |
statusEl.html(response.error); |
| 2320 |
statusEl.css('color', 'red'); |
| 2321 |
} else if ((response.ok != undefined) && (response.ok[siteToInstall.attr('siteid')] != undefined)) { |
| 2322 |
statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Installation completed successfully.', 'mainwp') + '"><i class="check green icon"></i></span>'); |
| 2323 |
countRealItemsUpdated++; |
| 2324 |
} else if ((response.errors != undefined) && (response.errors[siteToInstall.attr('siteid')] != undefined)) { |
| 2325 |
statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + response.errors[siteToInstall.attr('siteid')][1] + '"><i class="times red icon"></i></span>'); |
| 2326 |
} else { |
| 2327 |
statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Undefined error occurred. Please try again.', 'mainwp') + '"><i class="times red icon"></i></span>'); |
| 2328 |
} |
| 2329 |
|
| 2330 |
bulkInstallCurrentThreads--; |
| 2331 |
bulkInstallDone++; |
| 2332 |
jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').progress('set progress', bulkInstallDone); |
| 2333 |
jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').find('.label').html(bulkInstallDone + '/' + bulkInstallTotal + ' ' + __('Installed')); |
| 2334 |
mainwp_install_bulk_start_next(type, url, activatePlugin, overwrite); |
| 2335 |
} |
| 2336 |
}(type, url, activatePlugin, overwrite, siteToInstall), 'json'); |
| 2337 |
}; |
| 2338 |
|
| 2339 |
|
| 2340 |
mainwp_install_bulk_you_know_msg = function (type, total) { |
| 2341 |
var msg = ''; |
| 2342 |
if (mainwpParams.installedBulkSettingsManager && mainwpParams.installedBulkSettingsManager == 1) { |
| 2343 |
if (type == 'plugin') { |
| 2344 |
if (total == 1) |
| 2345 |
msg = __('Would you like to use the Bulk Settings Manager with this plugin? Check out the %1Documentation%2.', '<a href="https://kb.mainwp.com/docs/bulk-settings-manager-extension/" target="_blank">', '</a>'); |
| 2346 |
else |
| 2347 |
msg = __('Would you like to use the Bulk Settings Manager with these plugins? Check out the %1Documentation%2.', '<a href="https://kb.mainwp.com/docs/bulk-settings-manager-extension/" target="_blank">', '</a>'); |
| 2348 |
} else { |
| 2349 |
if (total == 1) |
| 2350 |
msg = __('Would you like to use the Bulk Settings Manager with this theme? Check out the %1Documentation%2.', '<a href="https://kb.mainwp.com/docs/bulk-settings-manager-extension/" target="_blank">', '</a>'); |
| 2351 |
else |
| 2352 |
msg = __('Would you like to use the Bulk Settings Manager with these themes? Check out the %1Documentation%2.', '<a href="https://kb.mainwp.com/docs/bulk-settings-manager-extension/" target="_blank">', '</a>'); |
| 2353 |
} |
| 2354 |
} else { |
| 2355 |
if (type == 'plugin') { |
| 2356 |
if (total == 1) |
| 2357 |
msg = __('Did you know with the %1 you can control the settings of this plugin directly from your MainWP Dashboard?', '<a href="https://mainwp.com/extension/bulk-settings-manager/" target="_blank">Bulk Settings Extension</a>'); |
| 2358 |
else |
| 2359 |
msg = __('Did you know with the %1 you can control the settings of these plugins directly from your MainWP Dashboard?', '<a href="https://mainwp.com/extension/bulk-settings-manager/" target="_blank">Bulk Settings Extension</a>'); |
| 2360 |
} else { |
| 2361 |
if (total == 1) |
| 2362 |
msg = __('Did you know with the %1 you can control the settings of this theme directly from your MainWP Dashboard?', '<a href="https://mainwp.com/extension/bulk-settings-manager/" target="_blank">Bulk Settings Extension</a>'); |
| 2363 |
else |
| 2364 |
msg = __('Did you know with the %1 you can control the settings of these themes directly from your MainWP Dashboard?', '<a href="https://mainwp.com/extension/bulk-settings-manager/" target="_blank">Bulk Settings Extension</a>'); |
| 2365 |
} |
| 2366 |
} |
| 2367 |
return msg; |
| 2368 |
} |
| 2369 |
|
| 2370 |
/** |
| 2371 |
* Install Plugin/Theme by Upload. |
| 2372 |
* |
| 2373 |
* Initiate the process. |
| 2374 |
* |
| 2375 |
* @param string type Plugin or theme. |
| 2376 |
* |
| 2377 |
* @return void |
| 2378 |
*/ |
| 2379 |
mainwp_upload_bulk = function (type) { |
| 2380 |
|
| 2381 |
if (type == 'plugins') { |
| 2382 |
type = 'plugin'; |
| 2383 |
} else { |
| 2384 |
type = 'theme'; |
| 2385 |
} |
| 2386 |
|
| 2387 |
var files = []; |
| 2388 |
|
| 2389 |
jQuery(".qq-upload-file").each(function () { |
| 2390 |
if (jQuery(this).closest('.file-uploaded-item').hasClass('qq-upload-success')) { |
| 2391 |
files.push(jQuery(this).attr('filename')); |
| 2392 |
} |
| 2393 |
}); |
| 2394 |
|
| 2395 |
if (files.length == 0) { |
| 2396 |
if (type == 'plugin') { |
| 2397 |
feedback('mainwp-message-zone', __('Please upload at least one plugin to install.', 'mainwp'), 'yellow'); |
| 2398 |
} else { |
| 2399 |
feedback('mainwp-message-zone', __('Please upload at least one theme to install.', 'mainwp'), 'yellow'); |
| 2400 |
} |
| 2401 |
return; |
| 2402 |
} |
| 2403 |
|
| 2404 |
var data = mainwp_secure_data({ |
| 2405 |
action: 'mainwp_preparebulkuploadplugintheme', |
| 2406 |
type: type, |
| 2407 |
selected_by: jQuery('#select_by').val() |
| 2408 |
}); |
| 2409 |
|
| 2410 |
var placeholder = '<div class="ui placeholder"><div class="paragraph"><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div></div></div>'; |
| 2411 |
|
| 2412 |
if (jQuery('#select_by').val() == 'site') { |
| 2413 |
var selected_sites = []; |
| 2414 |
jQuery("input[name='selected_sites[]']:checked").each(function () { |
| 2415 |
selected_sites.push(jQuery(this).val()); |
| 2416 |
}); |
| 2417 |
|
| 2418 |
if (selected_sites.length == 0) { |
| 2419 |
feedback('mainwp-message-zone', __('Please select at least one website or a group or client.', 'mainwp'), 'yellow'); |
| 2420 |
return; |
| 2421 |
} |
| 2422 |
data['selected_sites[]'] = selected_sites; |
| 2423 |
} else if (jQuery('#select_by').val() == 'client') { |
| 2424 |
var selected_clients = []; |
| 2425 |
jQuery("input[name='selected_clients[]']:checked").each(function () { |
| 2426 |
selected_clients.push(jQuery(this).val()); |
| 2427 |
}); |
| 2428 |
|
| 2429 |
if (selected_clients.length == 0) { |
| 2430 |
feedback('mainwp-message-zone', __('Please select at least one website or a group or client.', 'mainwp'), 'yellow'); |
| 2431 |
return; |
| 2432 |
} |
| 2433 |
data['selected_clients[]'] = selected_clients; |
| 2434 |
} else { |
| 2435 |
var selected_groups = []; |
| 2436 |
jQuery("input[name='selected_groups[]']:checked").each(function () { |
| 2437 |
selected_groups.push(jQuery(this).val()); |
| 2438 |
}); |
| 2439 |
if (selected_groups.length == 0) { |
| 2440 |
feedback('mainwp-message-zone', __('Please select at least one website or a group or client.', 'mainwp'), 'yellow'); |
| 2441 |
return; |
| 2442 |
} |
| 2443 |
data['selected_groups[]'] = selected_groups; |
| 2444 |
} |
| 2445 |
|
| 2446 |
data['files[]'] = files; |
| 2447 |
|
| 2448 |
jQuery('#plugintheme-installation-queue').html(placeholder); |
| 2449 |
|
| 2450 |
jQuery.post(ajaxurl, data, function (type, files, activatePlugin, overwrite) { |
| 2451 |
return function (response) { |
| 2452 |
var installQueue = ''; |
| 2453 |
bulkInstallTotal = 0; |
| 2454 |
bulkInstallDone = 0; |
| 2455 |
|
| 2456 |
installQueue += '<div class="ui middle aligned selection divided list">'; |
| 2457 |
|
| 2458 |
for (var siteId in response.sites) { |
| 2459 |
var site = response.sites[siteId]; |
| 2460 |
|
| 2461 |
installQueue += |
| 2462 |
'<div class="siteBulkInstall item" siteid="' + siteId + '" status="queue">' + |
| 2463 |
'<div class="right floated content">' + |
| 2464 |
'<span class="queue" data-inverted="" data-position="left center" data-tooltip="' + __('Queued', 'mainwp') + '"><i class="clock outline icon"></i></span>' + |
| 2465 |
'<span class="progress" data-inverted="" data-position="left center" data-tooltip="' + __('Installing...', 'mainwp') + '" style="display:none"><i class="notched circle loading icon"></i></span>' + |
| 2466 |
'<span class="status"></span>' + |
| 2467 |
'</div>' + |
| 2468 |
'<div class="content">' + mainwp_links_visit_site_and_admin('', siteId) + ' ' + '<a href="' + site['url'] + '">' + site['name'].replace(/\\(.)/mg, "$1") + '</a></div>' + |
| 2469 |
'<div class="installation-entries"></div>' + |
| 2470 |
'</div>'; |
| 2471 |
bulkInstallTotal++; |
| 2472 |
} |
| 2473 |
|
| 2474 |
installQueue += '</div>'; |
| 2475 |
|
| 2476 |
jQuery('#plugintheme-installation-queue').html(installQueue); |
| 2477 |
|
| 2478 |
jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').progress({ value: 0, total: bulkInstallTotal }); |
| 2479 |
mainwp_upload_bulk_start_next(type, response.urls, activatePlugin, overwrite); |
| 2480 |
} |
| 2481 |
}(type, files, jQuery('#chk_activate_plugin').is(':checked'), jQuery('#chk_overwrite').is(':checked')), 'json'); |
| 2482 |
|
| 2483 |
jQuery('#plugintheme-installation-progress-modal').modal('setting', 'closable', false).modal('show'); |
| 2484 |
|
| 2485 |
jQuery('.qq-upload-list').html(''); // empty files list! |
| 2486 |
|
| 2487 |
return false; |
| 2488 |
}; |
| 2489 |
|
| 2490 |
/** |
| 2491 |
* Install Plugin/Theme by Upload. |
| 2492 |
* |
| 2493 |
* Loop through sites. |
| 2494 |
* |
| 2495 |
* @param string type Plugin or theme. |
| 2496 |
* @param string urls URLs. |
| 2497 |
* @param bool activatePlugin Determines if the item should be activated or not upon installation. |
| 2498 |
* @param bool overwrite Determines if the item should overwrite exisitng version. |
| 2499 |
* |
| 2500 |
* @return void |
| 2501 |
*/ |
| 2502 |
mainwp_upload_bulk_start_next = function (type, urls, activatePlugin, overwrite) { |
| 2503 |
while ((siteToInstall = jQuery('.siteBulkInstall[status="queue"]:first')) && (siteToInstall.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { |
| 2504 |
mainwp_upload_bulk_start_specific(type, urls, activatePlugin, overwrite, siteToInstall); |
| 2505 |
} |
| 2506 |
|
| 2507 |
if ((siteToInstall.length == 0) && (bulkInstallCurrentThreads == 0)) { |
| 2508 |
var data = mainwp_secure_data({ |
| 2509 |
action: 'mainwp_cleanbulkuploadplugintheme' |
| 2510 |
}); |
| 2511 |
jQuery.post(ajaxurl, data, function () { }); |
| 2512 |
var msg = mainwp_install_bulk_you_know_msg(type, jQuery('#bulk_upload_info').attr('number-files')); |
| 2513 |
|
| 2514 |
jQuery('#bulk_upload_info').html('<div class="mainwp-notice mainwp-notice-blue">' + msg + '</div>'); |
| 2515 |
} |
| 2516 |
}; |
| 2517 |
|
| 2518 |
/** |
| 2519 |
* Install Plugin/Theme by Upload. |
| 2520 |
* |
| 2521 |
* Install specific item. |
| 2522 |
* |
| 2523 |
* @param string type Plugin or theme. |
| 2524 |
* @param string urls URLs. |
| 2525 |
* @param bool activatePlugin Determines if the item should be activated or not upon installation. |
| 2526 |
* @param bool overwrite Determines if the item should overwrite exisitng version. |
| 2527 |
* @param object siteToInstall Site to install the item to. |
| 2528 |
* |
| 2529 |
* @return void |
| 2530 |
*/ |
| 2531 |
mainwp_upload_bulk_start_specific = function (type, urls, activatePlugin, overwrite, siteToInstall) { |
| 2532 |
bulkInstallCurrentThreads++; |
| 2533 |
siteToInstall.attr('status', 'progress'); |
| 2534 |
|
| 2535 |
siteToInstall.find('.queue').hide(); |
| 2536 |
siteToInstall.find('.progress').show(); |
| 2537 |
|
| 2538 |
var data = mainwp_secure_data({ |
| 2539 |
action: 'mainwp_installbulkuploadplugintheme', |
| 2540 |
type: type, |
| 2541 |
urls: urls, |
| 2542 |
activatePlugin: activatePlugin, |
| 2543 |
overwrite: overwrite, |
| 2544 |
siteId: siteToInstall.attr('siteid') |
| 2545 |
}); |
| 2546 |
|
| 2547 |
jQuery.post(ajaxurl, data, function (type, urls, activatePlugin, overwrite, siteToInstall) { |
| 2548 |
return function (response) { |
| 2549 |
siteToInstall.attr('status', 'done'); |
| 2550 |
siteToInstall.find('.progress').hide(); |
| 2551 |
var statusEl = siteToInstall.find('.status'); |
| 2552 |
var siteid = siteToInstall.attr('siteid'); |
| 2553 |
statusEl.show(); |
| 2554 |
|
| 2555 |
if (response.error != undefined) { |
| 2556 |
statusEl.html(response.error); |
| 2557 |
statusEl.css('color', 'red'); |
| 2558 |
} else if ((response.ok != undefined) && (response.ok[siteid] != undefined)) { |
| 2559 |
var results = ''; |
| 2560 |
if ((response.results != undefined) && (response.results[siteid] != undefined)) { |
| 2561 |
entries = Object.entries(response.results[siteid]); |
| 2562 |
results += '<div class="ui tiny middle aligned selection list">'; |
| 2563 |
for (var entry of entries) { |
| 2564 |
results += '<div class="item"><div class="right floated content">' + (entry[1] ? '<i class="check green icon"></i>' : '<i class="times red icon"></i>') + '</div><div class="content">' + entry[0] + '</div></div>'; |
| 2565 |
} |
| 2566 |
results += '</div>'; |
| 2567 |
} |
| 2568 |
jQuery('div[siteId="' + siteid + '"] .installation-entries').html(results); |
| 2569 |
statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Installation completed successfully.', 'mainwp') + '"><i class="check green icon"></i></span>'); |
| 2570 |
} else if ((response.errors != undefined) && (response.errors[siteid] != undefined)) { |
| 2571 |
statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + response.errors[siteid][1] + '"><i class="times red icon"></i></span>'); |
| 2572 |
} else { |
| 2573 |
statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Undefined error occurred. Please try again.', 'mainwp') + '"><i class="times red icon"></i></span>'); |
| 2574 |
} |
| 2575 |
|
| 2576 |
bulkInstallCurrentThreads--; |
| 2577 |
bulkInstallDone++; |
| 2578 |
jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').progress('set progress', bulkInstallDone); |
| 2579 |
jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').find('.label').html(bulkInstallDone + '/' + bulkInstallTotal + ' ' + __('Installed')); |
| 2580 |
mainwp_upload_bulk_start_next(type, urls, activatePlugin, overwrite); |
| 2581 |
} |
| 2582 |
}(type, urls, activatePlugin, overwrite, siteToInstall), 'json'); |
| 2583 |
}; |
| 2584 |
|
| 2585 |
jQuery(document).ready(function ($) { |
| 2586 |
jQuery(document).on('click', '.open-plugin-details-modal', function () { |
| 2587 |
var itemDetail = this; |
| 2588 |
$('#mainwp-plugin-details-modal').modal({ |
| 2589 |
onHide: function () { |
| 2590 |
}, |
| 2591 |
onShow: function () { |
| 2592 |
$('#mainwp-plugin-details-modal').find('.ui.embed').embed({ |
| 2593 |
source: 'WP', |
| 2594 |
url: $(itemDetail).attr('href'), |
| 2595 |
}); |
| 2596 |
return false; |
| 2597 |
} |
| 2598 |
}).modal('show'); |
| 2599 |
return false; |
| 2600 |
}); |
| 2601 |
}); |
| 2602 |
|
| 2603 |
|
| 2604 |
/** |
| 2605 |
* Utility |
| 2606 |
*/ |
| 2607 |
function isUrl(s) { |
| 2608 |
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/; |
| 2609 |
return regexp.test(s); |
| 2610 |
} |
| 2611 |
function setVisible(what, vis) { |
| 2612 |
if (vis) { |
| 2613 |
jQuery(what).show(); |
| 2614 |
} else { |
| 2615 |
jQuery(what).hide(); |
| 2616 |
} |
| 2617 |
} |
| 2618 |
function setHtml(what, text, ptag) { |
| 2619 |
if (typeof ptag == "undefined") |
| 2620 |
ptag = true; |
| 2621 |
|
| 2622 |
setVisible(what, true); |
| 2623 |
if (ptag) |
| 2624 |
jQuery(what).html('<span>' + text + '</span>'); |
| 2625 |
else |
| 2626 |
jQuery(what).html(text); |
| 2627 |
scrollToElement(what); |
| 2628 |
} |
| 2629 |
|
| 2630 |
|
| 2631 |
/** |
| 2632 |
* Notes |
| 2633 |
*/ |
| 2634 |
jQuery(document).ready(function () { |
| 2635 |
|
| 2636 |
jQuery(document).on('click', '#mainwp-notes-cancel', function () { |
| 2637 |
jQuery('#mainwp-notes-status').html(''); |
| 2638 |
jQuery('#mainwp-notes-status').removeClass('red green'); |
| 2639 |
mainwp_notes_hide(); |
| 2640 |
return false; |
| 2641 |
}); |
| 2642 |
|
| 2643 |
jQuery(document).on('click', '#mainwp-notes-save', function () { |
| 2644 |
var which = jQuery('#mainwp-which-note').val(); |
| 2645 |
if (which == 'site') { |
| 2646 |
mainwp_notes_site_save(); |
| 2647 |
} else if (which == 'theme') { |
| 2648 |
mainwp_notes_theme_save(); |
| 2649 |
} else if (which == 'plugin') { |
| 2650 |
mainwp_notes_plugin_save() |
| 2651 |
} else if (which == 'client') { |
| 2652 |
mainwp_notes_client_save() |
| 2653 |
} |
| 2654 |
var newnote = jQuery('#mainwp-notes-note').val(); |
| 2655 |
jQuery('#mainwp-notes-html').html(newnote); |
| 2656 |
return false; |
| 2657 |
}); |
| 2658 |
|
| 2659 |
jQuery(document).on('click', '.mainwp-edit-site-note', function () { |
| 2660 |
var id = jQuery(this).attr('id').substr(13); |
| 2661 |
var note = jQuery('#mainwp-notes-' + id + '-note').html(); |
| 2662 |
jQuery('#mainwp-notes-html').html(note == '' ? __('No saved notes. Click the Edit button to edit site notes.') : note); |
| 2663 |
jQuery('#mainwp-notes-note').val(note); |
| 2664 |
jQuery('#mainwp-notes-websiteid').val(id); |
| 2665 |
jQuery('#mainwp-which-note').val('site'); // to fix conflict. |
| 2666 |
mainwp_notes_show(); |
| 2667 |
return false; |
| 2668 |
}); |
| 2669 |
|
| 2670 |
jQuery(document).on('click', '#mainwp-notes-edit', function () { |
| 2671 |
jQuery('#mainwp-notes-html').hide(); |
| 2672 |
jQuery('#mainwp-notes-editor').show(); |
| 2673 |
jQuery(this).hide(); |
| 2674 |
jQuery('#mainwp-notes-save').show(); |
| 2675 |
jQuery('#mainwp-notes-status').html(''); |
| 2676 |
jQuery('#mainwp-notes-status').removeClass('red green'); |
| 2677 |
return false; |
| 2678 |
}); |
| 2679 |
jQuery('#redirectForm').submit(); |
| 2680 |
}); |
| 2681 |
|
| 2682 |
mainwp_notes_show = function (reloadClose) { |
| 2683 |
if (reloadClose) { |
| 2684 |
jQuery('#mainwp-notes-modal').modal({ |
| 2685 |
onHide: function () { |
| 2686 |
window.location.href = location.href |
| 2687 |
} |
| 2688 |
}).modal('show'); |
| 2689 |
} else { |
| 2690 |
jQuery('#mainwp-notes-modal').modal({ closable: false }).modal('show'); |
| 2691 |
} |
| 2692 |
|
| 2693 |
jQuery('#mainwp-notes-html').show(); |
| 2694 |
jQuery('#mainwp-notes-editor').hide(); |
| 2695 |
jQuery('#mainwp-notes-save').hide(); |
| 2696 |
jQuery('#mainwp-notes-edit').show(); |
| 2697 |
}; |
| 2698 |
mainwp_notes_hide = function () { |
| 2699 |
jQuery('#mainwp-notes-modal').modal('hide'); |
| 2700 |
}; |
| 2701 |
mainwp_notes_site_save = function () { |
| 2702 |
var normalid = jQuery('#mainwp-notes-websiteid').val(); |
| 2703 |
var newnote = jQuery('#mainwp-notes-note').val(); |
| 2704 |
newnote = newnote.replace(/(?:\r\n|\r|\n)/g, '<br>'); |
| 2705 |
var data = mainwp_secure_data({ |
| 2706 |
action: 'mainwp_notes_save', |
| 2707 |
websiteid: normalid, |
| 2708 |
note: newnote |
| 2709 |
}); |
| 2710 |
|
| 2711 |
jQuery('#mainwp-notes-status').html('<i class="notched circle loading icon"></i> ' + __('Saving note. Please wait...')).show(); |
| 2712 |
|
| 2713 |
jQuery.post(ajaxurl, data, function (response) { |
| 2714 |
if (response.error != undefined) { |
| 2715 |
jQuery('#mainwp-notes-status').html(response.error).addClass('red'); |
| 2716 |
} else if (response.result == 'SUCCESS') { |
| 2717 |
jQuery('#mainwp-notes-status').html(__('Note saved successfully.')).addClass('green'); |
| 2718 |
if (jQuery('#mainwp-notes-' + normalid + '-note').length > 0) { |
| 2719 |
jQuery('#mainwp-notes-' + normalid + '-note').html(jQuery('#mainwp-notes-note').val()); |
| 2720 |
} |
| 2721 |
} else { |
| 2722 |
jQuery('#mainwp-notes-status').html(__('Undefined error occured while saving your note!')).addClass('red'); |
| 2723 |
} |
| 2724 |
}, 'json'); |
| 2725 |
|
| 2726 |
setTimeout(function () { |
| 2727 |
jQuery('#mainwp-notes-status').fadeOut(300); |
| 2728 |
}, 3000); |
| 2729 |
|
| 2730 |
jQuery('#mainwp-notes-html').show(); |
| 2731 |
jQuery('#mainwp-notes-editor').hide(); |
| 2732 |
jQuery('#mainwp-notes-save').hide(); |
| 2733 |
jQuery('#mainwp-notes-edit').show(); |
| 2734 |
|
| 2735 |
}; |
| 2736 |
|
| 2737 |
getErrorMessage = function (pError, msgOnly) { |
| 2738 |
if (pError.message == 'HTTPERROR') { |
| 2739 |
return __('HTTP error') + '! ' + pError.extra; |
| 2740 |
} else if (pError.message == 'NOMAINWP' || pError == 'NOMAINWP') { |
| 2741 |
var error = ''; |
| 2742 |
if (pError.extra) { |
| 2743 |
error = __('MainWP Child plugin not detected or could not be reached! Ensure the MainWP Child plugin is installed and activated on the child site, and there are no security rules blocking requests. If you continue experiencing this issue, check the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a> for help.', pError.extra); // to fix incorrect encoding |
| 2744 |
} else { |
| 2745 |
error = __('MainWP Child plugin not detected or could not be reached! Ensure the MainWP Child plugin is installed and activated on the child site, and there are no security rules blocking requests. If you continue experiencing this issue, check the <a href="https://managers.mainwp.com/c/community-support/5">MainWP Community</a> for help.'); |
| 2746 |
} |
| 2747 |
|
| 2748 |
return error; |
| 2749 |
} else if (pError.message == 'ERROR') { |
| 2750 |
return 'ERROR' + ((pError.extra != '') && (pError.extra != undefined) ? ': ' + pError.extra : ''); |
| 2751 |
} else if (pError.message == 'WPERROR') { |
| 2752 |
var extrMsg = (pError.extra != '') && (pError.extra != undefined) ? pError.extra : ''; |
| 2753 |
if (msgOnly != undefined && msgOnly && extrMsg != '') { |
| 2754 |
return extrMsg; |
| 2755 |
} else { |
| 2756 |
return __('ERROR on the child site') + ': ' + extrMsg; |
| 2757 |
} |
| 2758 |
|
| 2759 |
} else if (pError.message != undefined && pError.message != '') { |
| 2760 |
return pError.message; |
| 2761 |
} else { |
| 2762 |
return pError; |
| 2763 |
} |
| 2764 |
}; |
| 2765 |
|
| 2766 |
dateToHMS = function (date) { |
| 2767 |
if (mainwpParams != undefined && mainwpParams['time_format'] != undefined) { |
| 2768 |
var time = moment(date); |
| 2769 |
var format = mainwpParams['time_format']; |
| 2770 |
format = format.replace('g', 'h'); |
| 2771 |
format = format.replace('i', 'mm'); |
| 2772 |
format = format.replace('s', 'ss'); |
| 2773 |
format = format.replace('F', 'MMMM'); |
| 2774 |
format = format.replace('j', 'D'); |
| 2775 |
format = format.replace('Y', 'YYYY'); |
| 2776 |
return time.format(format); |
| 2777 |
} |
| 2778 |
var h = date.getHours(); |
| 2779 |
var m = date.getMinutes(); |
| 2780 |
var s = date.getSeconds(); |
| 2781 |
return '' + (h <= 9 ? '0' + h : h) + ':' + (m <= 9 ? '0' + m : m) + ':' + (s <= 9 ? '0' + s : s); |
| 2782 |
}; |
| 2783 |
appendToDiv = function (pSelector, pText, pScrolldown, pShowTime) { |
| 2784 |
if (pScrolldown == undefined) |
| 2785 |
pScrolldown = true; |
| 2786 |
if (pShowTime == undefined) |
| 2787 |
pShowTime = true; |
| 2788 |
|
| 2789 |
var theDiv = jQuery(pSelector); |
| 2790 |
theDiv.append('<br />' + (pShowTime ? dateToHMS(new Date()) + ' ' : '') + pText); |
| 2791 |
if (pScrolldown) |
| 2792 |
theDiv.animate({ scrollTop: theDiv.prop("scrollHeight") }, 100); |
| 2793 |
}; |
| 2794 |
|
| 2795 |
jQuery.fn.exists = function () { |
| 2796 |
return (this.length !== 0); |
| 2797 |
}; |
| 2798 |
|
| 2799 |
|
| 2800 |
function __(text, _var1, _var2, _var3) { |
| 2801 |
if (text == undefined || text == '') |
| 2802 |
return text; |
| 2803 |
var strippedText = text.replace(/ /g, '_'); |
| 2804 |
strippedText = strippedText.replace(/[^A-Za-z0-9_]/g, ''); |
| 2805 |
|
| 2806 |
if (strippedText == '') |
| 2807 |
return text.replace('%1', _var1).replace('%2', _var2).replace('%3', _var3); |
| 2808 |
|
| 2809 |
if (mainwpTranslations == undefined) |
| 2810 |
return text.replace('%1', _var1).replace('%2', _var2).replace('%3', _var3); |
| 2811 |
if (mainwpTranslations[strippedText] == undefined) |
| 2812 |
return text.replace('%1', _var1).replace('%2', _var2).replace('%3', _var3); |
| 2813 |
|
| 2814 |
return mainwpTranslations[strippedText].replace('%1', _var1).replace('%2', _var2).replace('%3', _var3); |
| 2815 |
} |
| 2816 |
|
| 2817 |
mainwp_secure_data = function (data, includeDts) { |
| 2818 |
if (data['action'] == undefined) |
| 2819 |
return data; |
| 2820 |
|
| 2821 |
if (security_nonces[data['action']] == undefined) |
| 2822 |
return data; |
| 2823 |
|
| 2824 |
data['security'] = security_nonces[data['action']]; |
| 2825 |
if (includeDts) |
| 2826 |
data['dts'] = Math.round(new Date().getTime() / 1000); |
| 2827 |
return data; |
| 2828 |
}; |
| 2829 |
|
| 2830 |
|
| 2831 |
mainwp_uid = function () { |
| 2832 |
// always start with a letter (for DOM friendlyness) |
| 2833 |
var idstr = String.fromCharCode(Math.floor((Math.random() * 25) + 65)); |
| 2834 |
do { |
| 2835 |
// between numbers and characters (48 is 0 and 90 is Z (42-48 = 90) |
| 2836 |
var ascicode = Math.floor((Math.random() * 42) + 48); |
| 2837 |
if (ascicode < 58 || ascicode > 64) { |
| 2838 |
// exclude all chars between : (58) and @ (64) |
| 2839 |
idstr += String.fromCharCode(ascicode); |
| 2840 |
} |
| 2841 |
} while (idstr.length < 32); |
| 2842 |
|
| 2843 |
return (idstr); |
| 2844 |
}; |
| 2845 |
|
| 2846 |
scrollToElement = function () { |
| 2847 |
jQuery('html,body').animate({ |
| 2848 |
scrollTop: 0 |
| 2849 |
}, 1000); |
| 2850 |
|
| 2851 |
return false; |
| 2852 |
}; |
| 2853 |
|
| 2854 |
jQuery(document).ready(function () { |
| 2855 |
jQuery('#backup_filename').keypress(function (e) { |
| 2856 |
var chr = String.fromCharCode(e.which); |
| 2857 |
return ("$^&*/".indexOf(chr) < 0); |
| 2858 |
}); |
| 2859 |
jQuery('#backup_filename').change(function () { |
| 2860 |
var value = jQuery(this).val(); |
| 2861 |
var notAllowed = ['$', '^', '&', '*', '/']; |
| 2862 |
for (var i = 0; i < notAllowed.length; i++) { |
| 2863 |
var char = notAllowed[i]; |
| 2864 |
if (value.indexOf(char) >= 0) { |
| 2865 |
value = value.replace(new RegExp('\\' + char, 'g'), ''); |
| 2866 |
jQuery(this).val(value); |
| 2867 |
} |
| 2868 |
} |
| 2869 |
}); |
| 2870 |
}); |
| 2871 |
|
| 2872 |
/* |
| 2873 |
* Server Info |
| 2874 |
*/ |
| 2875 |
|
| 2876 |
serverinfo_prepare_download_info = function (communi) { |
| 2877 |
var report = ""; |
| 2878 |
jQuery('.mainwp-system-info-table thead, .mainwp-system-info-table tbody').each(function () { |
| 2879 |
var td_len = [35, 55, 45, 12, 12]; |
| 2880 |
var th_count = 0; |
| 2881 |
var i; |
| 2882 |
if (jQuery(this).is('thead')) { |
| 2883 |
i = 0; |
| 2884 |
report = report + "\n### "; |
| 2885 |
th_count = jQuery(this).find('th:not(".mwp-not-generate-row")').length; |
| 2886 |
jQuery(this).find('th:not(".mwp-not-generate-row")').each(function () { |
| 2887 |
var len = td_len[i]; |
| 2888 |
if (i == 0 || i == th_count - 1) |
| 2889 |
len = len - 4; |
| 2890 |
report = report + jQuery.mwp_strCut(jQuery.trim(jQuery(this).text()), len, ' '); |
| 2891 |
i++; |
| 2892 |
}); |
| 2893 |
report = report + " ###\n\n"; |
| 2894 |
} else { |
| 2895 |
jQuery('tr', jQuery(this)).each(function () { |
| 2896 |
if (communi && jQuery(this).hasClass('mwp-not-generate-row')) |
| 2897 |
return; |
| 2898 |
i = 0; |
| 2899 |
jQuery(this).find('td:not(".mwp-not-generate-row")').each(function () { |
| 2900 |
if (jQuery(this).hasClass('mwp-hide-generate-row')) { |
| 2901 |
report = report + jQuery.mwp_strCut(' ', td_len[i], ' '); |
| 2902 |
i++; |
| 2903 |
return; |
| 2904 |
} |
| 2905 |
report = report + jQuery.mwp_strCut(jQuery.trim(jQuery(this).text()), td_len[i], ' '); |
| 2906 |
i++; |
| 2907 |
}); |
| 2908 |
report = report + "\n"; |
| 2909 |
}); |
| 2910 |
|
| 2911 |
} |
| 2912 |
}); |
| 2913 |
|
| 2914 |
try { |
| 2915 |
if (communi) { |
| 2916 |
report = '```' + "\n" + report + "\n" + '```'; |
| 2917 |
} |
| 2918 |
jQuery("#download-server-information textarea").val(report).select(); |
| 2919 |
} catch (e) { |
| 2920 |
console.log('Error:'); |
| 2921 |
} |
| 2922 |
return false; |
| 2923 |
} |
| 2924 |
|
| 2925 |
jQuery(document).on('click', '#mainwp-download-system-report', function () { |
| 2926 |
serverinfo_prepare_download_info(false); |
| 2927 |
var server_info = jQuery('#download-server-information textarea').val(); |
| 2928 |
var blob = new Blob([server_info], { type: "text/plain;charset=utf-8" }); |
| 2929 |
saveAs(blob, "mainwp-system-report.txt"); |
| 2930 |
return false; |
| 2931 |
}); |
| 2932 |
|
| 2933 |
jQuery(document).on('click', '#mainwp-copy-meta-system-report', function () { |
| 2934 |
jQuery("#download-server-information").slideDown(); // to able to select and copy |
| 2935 |
serverinfo_prepare_download_info(true); |
| 2936 |
jQuery("#download-server-information").slideUp(); |
| 2937 |
try { |
| 2938 |
var successful = document.execCommand('copy'); |
| 2939 |
var msg = successful ? 'successful' : 'unsuccessful'; |
| 2940 |
console.log('Copying text command was ' + msg); |
| 2941 |
} catch (err) { |
| 2942 |
console.log('Oops, unable to copy'); |
| 2943 |
} |
| 2944 |
return false; |
| 2945 |
}); |
| 2946 |
|
| 2947 |
|
| 2948 |
jQuery.mwp_strCut = function (i, l, s, w) { |
| 2949 |
var o = i.toString(); |
| 2950 |
if (!s) { |
| 2951 |
s = '0'; |
| 2952 |
} |
| 2953 |
while (o.length < parseInt(l)) { |
| 2954 |
// empty |
| 2955 |
if (w == 'undefined') { |
| 2956 |
o = s + o; |
| 2957 |
} else { |
| 2958 |
o = o + s; |
| 2959 |
} |
| 2960 |
} |
| 2961 |
return o; |
| 2962 |
}; |
| 2963 |
|
| 2964 |
updateExcludedFolders = function () { |
| 2965 |
var excludedBackupFiles = jQuery('#excludedBackupFiles').html(); |
| 2966 |
jQuery('#mainwp-kbl-content').val(excludedBackupFiles == undefined ? '' : excludedBackupFiles); |
| 2967 |
|
| 2968 |
var excludedCacheFiles = jQuery('#excludedCacheFiles').html(); |
| 2969 |
jQuery('#mainwp-kcl-content').val(excludedCacheFiles == undefined ? '' : excludedCacheFiles); |
| 2970 |
|
| 2971 |
var excludedNonWPFiles = jQuery('#excludedNonWPFiles').html(); |
| 2972 |
jQuery('#mainwp-nwl-content').val(excludedNonWPFiles == undefined ? '' : excludedNonWPFiles); |
| 2973 |
}; |
| 2974 |
|
| 2975 |
|
| 2976 |
jQuery(document).on('click', '.mainwp-events-notice-dismiss', function () { |
| 2977 |
var notice = jQuery(this).attr('notice'); |
| 2978 |
jQuery(this).closest('.ui.message').fadeOut(500); |
| 2979 |
var data = mainwp_secure_data({ |
| 2980 |
action: 'mainwp_events_notice_hide', |
| 2981 |
notice: notice |
| 2982 |
}); |
| 2983 |
jQuery.post(ajaxurl, data, function () { |
| 2984 |
}); |
| 2985 |
return false; |
| 2986 |
}); |
| 2987 |
|
| 2988 |
// Turn On child plugin auto update |
| 2989 |
jQuery(document).on('click', '#mainwp_btn_autoupdate_and_trust', function () { |
| 2990 |
jQuery(this).attr('disabled', 'true'); |
| 2991 |
var data = mainwp_secure_data({ |
| 2992 |
action: 'mainwp_autoupdate_and_trust_child' |
| 2993 |
}); |
| 2994 |
jQuery.post(ajaxurl, data, function (res) { |
| 2995 |
if (res == 'ok') { |
| 2996 |
location.reload(true); |
| 2997 |
} else { |
| 2998 |
jQuery(this).removeAttr('disabled'); |
| 2999 |
} |
| 3000 |
}); |
| 3001 |
return false; |
| 3002 |
}); |
| 3003 |
|
| 3004 |
// Hide installation warning |
| 3005 |
jQuery(document).on('click', '#remove-mainwp-installation-warning', function () { |
| 3006 |
jQuery(this).closest('.ui.message').fadeOut("slow"); |
| 3007 |
var data = mainwp_secure_data({ |
| 3008 |
action: 'mainwp_installation_warning_hide' |
| 3009 |
}); |
| 3010 |
jQuery.post(ajaxurl, data, function () { }); |
| 3011 |
return false; |
| 3012 |
}); |
| 3013 |
|
| 3014 |
jQuery(document).on('click', '.mainwp-notice-hide', function () { |
| 3015 |
jQuery(this).closest('.ui.message').fadeOut("slow"); |
| 3016 |
return false; |
| 3017 |
}); |
| 3018 |
|
| 3019 |
// Hide after installtion notices (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning) |
| 3020 |
jQuery(document).on('click', '.mainwp-notice-dismiss', function () { |
| 3021 |
var notice_id = jQuery(this).attr('notice-id'); |
| 3022 |
jQuery(this).closest('.ui.message').fadeOut("slow"); |
| 3023 |
var data = { |
| 3024 |
action: 'mainwp_notice_status_update' |
| 3025 |
}; |
| 3026 |
data['notice_id'] = notice_id; |
| 3027 |
jQuery.post(ajaxurl, mainwp_secure_data(data), function () { }); |
| 3028 |
return false; |
| 3029 |
}); |
| 3030 |
|
| 3031 |
jQuery(document).on('click', '.mainwp-activate-notice-dismiss', function () { |
| 3032 |
jQuery(this).closest('tr').fadeOut("slow"); |
| 3033 |
var data = mainwp_secure_data({ |
| 3034 |
action: 'mainwp_dismiss_activate_notice', |
| 3035 |
slug: jQuery(this).closest('tr').attr('slug') |
| 3036 |
}); |
| 3037 |
jQuery.post(ajaxurl, data, function () { |
| 3038 |
}); |
| 3039 |
return false; |
| 3040 |
}); |
| 3041 |
|
| 3042 |
|
| 3043 |
jQuery(document).on('click', '.mainwp-dismiss-twit', function () { |
| 3044 |
jQuery(this).closest('.mainwp-tips').fadeOut("slow"); |
| 3045 |
mainwp_twitter_dismiss(this); |
| 3046 |
return false; |
| 3047 |
}); |
| 3048 |
|
| 3049 |
mainwp_twitter_dismiss = function (obj) { |
| 3050 |
var data = mainwp_secure_data({ |
| 3051 |
action: 'mainwp_dismiss_twit', |
| 3052 |
twitId: jQuery(obj).closest('.mainwp-tips').find('.mainwp-tip').attr('twit-id'), |
| 3053 |
what: jQuery(obj).closest('.mainwp-tips').find('.mainwp-tip').attr('twit-what') |
| 3054 |
}); |
| 3055 |
|
| 3056 |
jQuery.post(ajaxurl, data, function () { |
| 3057 |
// Ok. |
| 3058 |
}); |
| 3059 |
}; |
| 3060 |
|
| 3061 |
jQuery(document).on('click', 'button.mainwp_tweet_this', function () { |
| 3062 |
var url = mainwpTweetUrlBuilder({ |
| 3063 |
text: jQuery(this).attr('msg') |
| 3064 |
}); |
| 3065 |
window.open(url, 'Tweet', 'height=450,width=700'); |
| 3066 |
mainwp_twitter_dismiss(this); |
| 3067 |
}); |
| 3068 |
|
| 3069 |
mainwpTweetUrlBuilder = function (o) { |
| 3070 |
return [ |
| 3071 |
'https://twitter.com/intent/tweet?tw_p=tweetbutton', |
| 3072 |
'&url=" "', |
| 3073 |
'&text=', o.text |
| 3074 |
].join(''); |
| 3075 |
}; |
| 3076 |
|
| 3077 |
jQuery(document).on('click', '.mainwp-action-dismiss', function () { |
| 3078 |
var action_id = jQuery(this).attr('action-id'); |
| 3079 |
jQuery(this).closest('tr').fadeOut("slow"); |
| 3080 |
var data = { |
| 3081 |
action: 'mainwp_site_actions_dismiss' |
| 3082 |
}; |
| 3083 |
data['action_id'] = action_id; |
| 3084 |
jQuery.post(ajaxurl, mainwp_secure_data(data), function () { |
| 3085 |
|
| 3086 |
}); |
| 3087 |
return false; |
| 3088 |
}); |
| 3089 |
|
| 3090 |
mainwp_managesites_update_childsite_value = function (siteId, uniqueId) { |
| 3091 |
var data = mainwp_secure_data({ |
| 3092 |
action: 'mainwp_updatechildsite_value', |
| 3093 |
site_id: siteId, |
| 3094 |
unique_id: uniqueId |
| 3095 |
}); |
| 3096 |
jQuery.post(ajaxurl, data, function () { |
| 3097 |
}); |
| 3098 |
return false; |
| 3099 |
}; |
| 3100 |
|
| 3101 |
jQuery(document).on('keyup', '#managegroups-filter', function () { |
| 3102 |
var filter = jQuery(this).val(); |
| 3103 |
var groupItems = jQuery(this).parent().parent().find('li.managegroups-listitem'); |
| 3104 |
for (var i = 0; i < groupItems.length; i++) { |
| 3105 |
var currentElement = jQuery(groupItems[i]); |
| 3106 |
if (currentElement.hasClass('managegroups-group-add')) |
| 3107 |
continue; |
| 3108 |
var value = currentElement.find('span.text').text(); |
| 3109 |
if (value.indexOf(filter) > -1) { |
| 3110 |
currentElement.show(); |
| 3111 |
} else { |
| 3112 |
currentElement.hide(); |
| 3113 |
} |
| 3114 |
} |
| 3115 |
}); |
| 3116 |
|
| 3117 |
// for normal checkboxes |
| 3118 |
jQuery(document).on('change', '#cb-select-all-top, #cb-select-all-bottom', function () { |
| 3119 |
var $this = jQuery(this), |
| 3120 |
$table = $this.closest('table'), |
| 3121 |
controlChecked = $this.prop('checked'); |
| 3122 |
|
| 3123 |
if ($table.length == 0) |
| 3124 |
return false; |
| 3125 |
|
| 3126 |
$table.children('tbody').filter(':visible') |
| 3127 |
.children().children('.check-column').find(':checkbox') |
| 3128 |
.prop('checked', function () { |
| 3129 |
if (jQuery(this).is(':hidden,:disabled')) { |
| 3130 |
return false; |
| 3131 |
} |
| 3132 |
if (controlChecked) { |
| 3133 |
return true; |
| 3134 |
} |
| 3135 |
return false; |
| 3136 |
}); |
| 3137 |
|
| 3138 |
$table.children('thead, tfoot').filter(':visible') |
| 3139 |
.children().children('.check-column').find(':checkbox') |
| 3140 |
.prop('checked', function () { |
| 3141 |
if (controlChecked) { |
| 3142 |
return true; |
| 3143 |
} |
| 3144 |
return false; |
| 3145 |
}); |
| 3146 |
}); |
| 3147 |
|
| 3148 |
|
| 3149 |
updatesoverview_send_twitt_info = function () { |
| 3150 |
var send = false; |
| 3151 |
if (mainwpParams.enabledTwit == true) { |
| 3152 |
var dateObj = new Date(); |
| 3153 |
var countSec = (dateObj.getTime() - starttimeDashboardAction) / 1000; |
| 3154 |
if (countSec <= mainwpParams.maxSecondsTwit) { |
| 3155 |
send = true; |
| 3156 |
var data = mainwp_secure_data({ |
| 3157 |
action: 'mainwp_twitter_dashboard_action', |
| 3158 |
actionName: dashboardActionName, |
| 3159 |
countSites: websitesDone, |
| 3160 |
countSeconds: countSec, |
| 3161 |
countItems: couttItemsToUpdate, |
| 3162 |
countRealItems: countRealItemsUpdated |
| 3163 |
}); |
| 3164 |
jQuery.post(ajaxurl, data, function () { |
| 3165 |
}); |
| 3166 |
} |
| 3167 |
} |
| 3168 |
return send; |
| 3169 |
}; |
| 3170 |
|
| 3171 |
// fix menu overflow with scroll tables. |
| 3172 |
mainwp_datatable_fix_menu_overflow = function () { |
| 3173 |
var fix_overflow = jQuery('.mainwp-content-wrap').attr('menu-overflow'); |
| 3174 |
console.log('fix_overflow: ' + fix_overflow); |
| 3175 |
jQuery(document).on('click', 'table td.check-column.dtr-control', function () { |
| 3176 |
if (jQuery(this).parent().hasClass('parent')) { |
| 3177 |
var chilRow = jQuery(this).parent().next(); |
| 3178 |
jQuery(chilRow).find('.ui.dropdown').dropdown(); |
| 3179 |
mainwp_datatable_fix_child_menu_overflow(chilRow, fix_overflow); |
| 3180 |
} |
| 3181 |
}); |
| 3182 |
|
| 3183 |
// Fix the overflow prbolem for the actions menu element (right pointing menu). |
| 3184 |
jQuery('table tr td .ui.right.pointing.dropdown.button').on('click', function () { |
| 3185 |
jQuery(this).closest('.dataTables_scrollBody').css('position', ''); |
| 3186 |
jQuery(this).closest('.dataTables_scroll').css('position', 'relative'); |
| 3187 |
jQuery(this).css('position', 'static'); |
| 3188 |
var fix_overflow = jQuery('.mainwp-content-wrap').attr('menu-overflow'); |
| 3189 |
var position = jQuery(this).position(); |
| 3190 |
var top = position.top; |
| 3191 |
var right = 48; |
| 3192 |
if (fix_overflow > 1) { |
| 3193 |
position = jQuery(this).closest('td').position(); |
| 3194 |
top = position.top + 85; |
| 3195 |
} |
| 3196 |
console.log('right'); |
| 3197 |
console.log('top: ' + position.top); |
| 3198 |
//return false; |
| 3199 |
jQuery(this).find('.menu').css('min-width', '170px'); |
| 3200 |
jQuery(this).find('.menu').css('top', top); |
| 3201 |
jQuery(this).find('.menu').css('right', right); |
| 3202 |
}); |
| 3203 |
|
| 3204 |
// Fix the overflow prbolem for the actions menu element (left pointing menu). |
| 3205 |
jQuery('table tr td .ui.left.pointing.dropdown.button').on('click', function () { |
| 3206 |
jQuery(this).closest('.dataTables_scrollBody').css('position', ''); |
| 3207 |
jQuery(this).closest('.dataTables_scroll').css('position', 'relative'); |
| 3208 |
jQuery(this).css('position', 'static'); |
| 3209 |
var position = jQuery(this).position(); |
| 3210 |
var top = position.top; |
| 3211 |
var left = position.left - 159; |
| 3212 |
|
| 3213 |
if (fix_overflow > 1) { |
| 3214 |
position = jQuery(this).closest('td').position(); |
| 3215 |
var scroll_left = jQuery(this).closest('.dataTables_scrollBody').scrollLeft(); |
| 3216 |
top = position.top + 85; |
| 3217 |
left = position.left - scroll_left - 145; |
| 3218 |
} |
| 3219 |
|
| 3220 |
console.log('left'); |
| 3221 |
console.log('top: ' + top + ' left: ' + left); |
| 3222 |
|
| 3223 |
jQuery(this).find('.menu').css('min-width', '150px'); |
| 3224 |
jQuery(this).removeClass('left'); |
| 3225 |
jQuery(this).addClass('right'); |
| 3226 |
//return false; |
| 3227 |
jQuery(this).find('.menu').css('top', top); |
| 3228 |
jQuery(this).find('.menu').css('left', left); |
| 3229 |
}); |
| 3230 |
} |
| 3231 |
|
| 3232 |
mainwp_datatable_fix_child_menu_overflow = function (chilRow, fix_overflow) { |
| 3233 |
// Fix the overflow prbolem for the actions child menu element (pointing menu). |
| 3234 |
jQuery(chilRow).find('.ui.pointing.dropdown.button').on('click', function () { |
| 3235 |
|
| 3236 |
var position = jQuery(this).position(); |
| 3237 |
var left = position.left + 30; |
| 3238 |
var top = position.top; |
| 3239 |
|
| 3240 |
if (fix_overflow > 1) { |
| 3241 |
position = jQuery(this).closest('td.child').position(); |
| 3242 |
top = position.top + jQuery(this).closest('td.child').height() + 85; |
| 3243 |
} |
| 3244 |
|
| 3245 |
jQuery(this).closest('.dataTables_scrollBody').css('position', ''); |
| 3246 |
jQuery(this).closest('.dataTables_scroll').css('position', 'relative'); |
| 3247 |
jQuery(this).css('position', 'static'); |
| 3248 |
jQuery(this).find('.menu').css('top', top); |
| 3249 |
jQuery(this).find('.menu').css('left', left); |
| 3250 |
jQuery(this).find('.menu').css('min-width', '170px'); |
| 3251 |
console.log('top:' + top); |
| 3252 |
}); |
| 3253 |
} |
| 3254 |
|
| 3255 |
|
| 3256 |
mainwp_responsive_fix_remove_child_row = function (el) { |
| 3257 |
if (jQuery(el).hasClass('dt-hasChild')) { // to fix. |
| 3258 |
jQuery(el).next().remove(); |
| 3259 |
} |
| 3260 |
} |
| 3261 |
|
| 3262 |
/* eslint-disable complexity */ |
| 3263 |
function mainwp_according_table_sorting(pObj) { |
| 3264 |
var table, th, rows, switching, i, x, y, xVal, yVal, campare = false, shouldSwitch = false, dir, switchcount = 0, n, skip = 1; |
| 3265 |
table = jQuery(pObj).closest('table')[0]; |
| 3266 |
var subline_skip = 2; |
| 3267 |
if ('mainwp-wordpress-updates-table' == jQuery(table).attr('id')) { |
| 3268 |
subline_skip = 1; // for rows without subline. |
| 3269 |
skip = 0; |
| 3270 |
} |
| 3271 |
|
| 3272 |
// get TH element |
| 3273 |
if (jQuery(pObj)[0].tagName == 'TH') { |
| 3274 |
th = jQuery(pObj)[0]; |
| 3275 |
} else { |
| 3276 |
th = jQuery(pObj).closest('th')[0]; |
| 3277 |
} |
| 3278 |
|
| 3279 |
n = th.cellIndex; |
| 3280 |
switching = true; |
| 3281 |
|
| 3282 |
// check header and footer of according table |
| 3283 |
if (jQuery(table).children('thead,tfoot').length > 0) |
| 3284 |
skip += jQuery(table).children('thead,tfoot').length; // skip sorting header, footer |
| 3285 |
|
| 3286 |
dir = "asc"; |
| 3287 |
/* loop until switching has been done: */ |
| 3288 |
while (switching) { |
| 3289 |
switching = false; |
| 3290 |
rows = table.rows; |
| 3291 |
/* Loop through all table rows */ |
| 3292 |
for (i = 1; i < (rows.length - skip); i += subline_skip) { // skip content according rows, sort by title rows only |
| 3293 |
shouldSwitch = false; |
| 3294 |
/* Get the two elements you want to compare, |
| 3295 |
one from current row and one from the next-next: */ |
| 3296 |
x = rows[i].getElementsByTagName("TD")[n]; |
| 3297 |
y = rows[i + subline_skip].getElementsByTagName("TD")[n]; |
| 3298 |
|
| 3299 |
// if sort value attribute existed then sorting on that else sorting on cell value |
| 3300 |
if (x.hasAttribute('sort-value')) { |
| 3301 |
xVal = parseInt(x.getAttribute('sort-value')); |
| 3302 |
yVal = parseInt(y.getAttribute('sort-value')); |
| 3303 |
campare = (xVal == yVal) ? 0 : (xVal > yVal ? -1 : 1); |
| 3304 |
} else { |
| 3305 |
// to prevent text() clear text content |
| 3306 |
xVal = '<p>' + x.innerHTML + '</p>'; |
| 3307 |
yVal = '<p>' + y.innerHTML + '</p>'; |
| 3308 |
xVal = jQuery(xVal).text().trim().toLowerCase(); |
| 3309 |
yVal = jQuery(yVal).text().trim().toLowerCase(); |
| 3310 |
campare = yVal.localeCompare(xVal); |
| 3311 |
} |
| 3312 |
|
| 3313 |
/* Check if the two rows should switch place */ |
| 3314 |
if (dir == "asc") { |
| 3315 |
if (campare < 0) { //xVal > yVal |
| 3316 |
shouldSwitch = true; |
| 3317 |
// break the loop: |
| 3318 |
break; |
| 3319 |
} |
| 3320 |
} else if (dir == "desc") { |
| 3321 |
if (campare > 0) { //xVal < yVal |
| 3322 |
// break the loop: |
| 3323 |
shouldSwitch = true; |
| 3324 |
break; |
| 3325 |
} |
| 3326 |
} |
| 3327 |
} |
| 3328 |
if (shouldSwitch) { |
| 3329 |
if (2 == subline_skip) { |
| 3330 |
rows[i].parentNode.insertBefore(rows[i + 2], rows[i]); |
| 3331 |
rows[i + 1].parentNode.insertBefore(rows[i + 3], rows[i + 1]); |
| 3332 |
} else { |
| 3333 |
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]); // switch 2 rows. |
| 3334 |
} |
| 3335 |
switching = true; |
| 3336 |
// increase this count by 1, that is ok |
| 3337 |
switchcount++; |
| 3338 |
} else { |
| 3339 |
/* If no switching has been done AND the direction is "asc", |
| 3340 |
set the direction to "desc" and run the while loop again. */ |
| 3341 |
if (switchcount == 0 && dir == "asc") { |
| 3342 |
dir = "desc"; |
| 3343 |
switching = true; |
| 3344 |
} |
| 3345 |
} |
| 3346 |
} |
| 3347 |
|
| 3348 |
// no row sorting so change direction for arrows switch |
| 3349 |
if (switchcount == 0) { |
| 3350 |
if (jQuery(pObj).hasClass('ascending')) { |
| 3351 |
dir = "desc"; |
| 3352 |
} else { |
| 3353 |
dir = "asc"; |
| 3354 |
} |
| 3355 |
} |
| 3356 |
|
| 3357 |
// add/remove class for arrows displaying |
| 3358 |
if (dir == "asc") { |
| 3359 |
jQuery(pObj).addClass('ascending'); |
| 3360 |
jQuery(pObj).removeClass('descending'); |
| 3361 |
} else { |
| 3362 |
jQuery(pObj).removeClass('ascending'); |
| 3363 |
jQuery(pObj).addClass('descending'); |
| 3364 |
} |
| 3365 |
} |
| 3366 |
/* eslint-enable complexity */ |
| 3367 |
|
| 3368 |
jQuery(document).ready(function () { |
| 3369 |
jQuery('.handle-accordion-sorting').on('click', function () { |
| 3370 |
mainwp_according_table_sorting(this); |
| 3371 |
return false; |
| 3372 |
}); |
| 3373 |
}); |
| 3374 |
|
| 3375 |
// Force Dashboard to reestablish connection by destroying sessions - Part 1 |
| 3376 |
mainwp_force_destroy_sessions = function () { |
| 3377 |
var confirmMsg = __('Are you sure you want to force your MainWP Dashboard to reconnect with your child sites?'); |
| 3378 |
mainwp_confirm(confirmMsg, function () { |
| 3379 |
mainwp_force_destroy_sessions_websites = jQuery('.dashboard_wp_id').map(function (indx, el) { |
| 3380 |
return jQuery(el).val(); |
| 3381 |
}); |
| 3382 |
mainwpPopup('#mainwp-sync-sites-modal').init({ progressMax: mainwp_force_destroy_sessions_websites.length }); |
| 3383 |
mainwp_force_destroy_sessions_part_2(0); |
| 3384 |
}); |
| 3385 |
}; |
| 3386 |
|
| 3387 |
mainwp_force_destroy_sessions_part_2 = function (id) { |
| 3388 |
if (id >= mainwp_force_destroy_sessions_websites.length) { |
| 3389 |
mainwp_force_destroy_sessions_websites = []; |
| 3390 |
if (mainwp_force_destroy_sessions_successed == mainwp_force_destroy_sessions_websites.length) { |
| 3391 |
setTimeout(function () { |
| 3392 |
mainwpPopup('#mainwp-sync-sites-modal').close(true); |
| 3393 |
}, 3000); |
| 3394 |
} |
| 3395 |
mainwpPopup('#mainwp-sync-sites-modal').close(true); |
| 3396 |
return; |
| 3397 |
} |
| 3398 |
|
| 3399 |
var website_id = mainwp_force_destroy_sessions_websites[id]; |
| 3400 |
dashboard_update_site_status(website_id, '<i class="sync alternate loading icon"></i>'); |
| 3401 |
|
| 3402 |
jQuery.post(ajaxurl, { 'action': 'mainwp_force_destroy_sessions', 'website_id': website_id, 'security': security_nonces['mainwp_force_destroy_sessions'] }, function (response) { |
| 3403 |
var counter = id + 1; |
| 3404 |
mainwp_force_destroy_sessions_part_2(counter); |
| 3405 |
|
| 3406 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(counter); |
| 3407 |
|
| 3408 |
if ('error' in response) { |
| 3409 |
dashboard_update_site_status(website_id, '<i class="exclamation red icon"></i>'); |
| 3410 |
} else if ('success' in response) { |
| 3411 |
mainwp_force_destroy_sessions_successed += 1; |
| 3412 |
dashboard_update_site_status(website_id, '<i class="check green icon"></i>', true); |
| 3413 |
} else { |
| 3414 |
dashboard_update_site_status(website_id, '<i class="exclamation yellow icon"></i>'); |
| 3415 |
} |
| 3416 |
}, 'json').fail(function () { |
| 3417 |
var counter = id + 1; |
| 3418 |
mainwp_force_destroy_sessions_part_2(counter); |
| 3419 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(counter); |
| 3420 |
|
| 3421 |
dashboard_update_site_status(website_id, '<i class="exclamation red icon"></i>'); |
| 3422 |
}); |
| 3423 |
|
| 3424 |
}; |
| 3425 |
|
| 3426 |
var mainwp_force_destroy_sessions_successed = 0; |
| 3427 |
var mainwp_force_destroy_sessions_websites = []; |
| 3428 |
|
| 3429 |
|
| 3430 |
jQuery(document).on('change', '#mainwp_archiveFormat', function () { |
| 3431 |
var zipMethod = jQuery(this).val(); |
| 3432 |
zipMethod = zipMethod.replace(/\./g, '\\.'); |
| 3433 |
jQuery('span.archive_info').hide(); |
| 3434 |
jQuery('span#info_' + zipMethod).show(); |
| 3435 |
|
| 3436 |
jQuery('tr.archive_method').hide(); |
| 3437 |
jQuery('tr.archive_' + zipMethod).show(); |
| 3438 |
|
| 3439 |
// compare new layout |
| 3440 |
jQuery('div.archive_method').hide(); |
| 3441 |
jQuery('div.archive_' + zipMethod).show(); |
| 3442 |
}); |
| 3443 |
|
| 3444 |
|
| 3445 |
// MainWP Tools |
| 3446 |
jQuery(document).ready(function () { |
| 3447 |
jQuery(document).on('click', '#force-destroy-sessions-button', function () { |
| 3448 |
mainwp_force_destroy_sessions(); |
| 3449 |
}); |
| 3450 |
}); |
| 3451 |
|
| 3452 |
jQuery(document).ready(function () { |
| 3453 |
if (jQuery('body.mainwp-ui').length > 0) { |
| 3454 |
jQuery('.mainwp-ui-page .ui.dropdown:not(.not-auto-init)').dropdown(); |
| 3455 |
jQuery('.mainwp-ui-page .ui.checkbox:not(.not-auto-init)').checkbox(); |
| 3456 |
jQuery('.mainwp-ui-page .ui.dropdown').filter('[init-value]').each(function () { |
| 3457 |
var values = jQuery(this).attr('init-value').split(','); |
| 3458 |
jQuery(this).dropdown('set selected', values); |
| 3459 |
}); |
| 3460 |
console.log('init ui element.'); |
| 3461 |
} |
| 3462 |
}); |
| 3463 |
|
| 3464 |
// MainWP Action Logs |
| 3465 |
jQuery(document).on('click', '.mainwp-action-log-show-more', function () { |
| 3466 |
var content = jQuery(this).closest('.item').find('.mainwp-action-log-site-response').text(); |
| 3467 |
jQuery('#mainwp-action-log-response-modal').modal({ |
| 3468 |
closable: false, |
| 3469 |
onHide: function () { |
| 3470 |
location.reload(); |
| 3471 |
} |
| 3472 |
}).modal('show'); |
| 3473 |
jQuery('#mainwp-action-log-response-modal .content-response').text(content); |
| 3474 |
}); |
| 3475 |
|
| 3476 |
// MainWP Show Response |
| 3477 |
jQuery(document).on('click', '.mainwp-show-response', function () { |
| 3478 |
var content = jQuery('#mainwp-response-data-container').attr('resp-data'); |
| 3479 |
jQuery('#mainwp-response-data-modal').modal({ |
| 3480 |
closable: false, |
| 3481 |
onHide: function () { |
| 3482 |
jQuery('#mainwp-response-data-modal .content-response').text(''); |
| 3483 |
} |
| 3484 |
}).modal('show'); |
| 3485 |
jQuery('#mainwp-response-data-modal .content-response').text(content); |
| 3486 |
}); |
| 3487 |
|
| 3488 |
// Copy to clipboard for response modals. |
| 3489 |
jQuery(document).on('click', '.mainwp-response-copy-button', function () { |
| 3490 |
var modal = jQuery(this).closest('.ui.modal'); |
| 3491 |
var data = jQuery(modal).find('.content.content-response').text(); |
| 3492 |
var $temp_txtarea = jQuery('<textarea style="opacity:0">'); |
| 3493 |
jQuery('body').append($temp_txtarea); |
| 3494 |
$temp_txtarea.val(data).select(); |
| 3495 |
try { |
| 3496 |
var successful = document.execCommand('copy'); |
| 3497 |
var msg = successful ? 'successful' : 'unsuccessful'; |
| 3498 |
console.log('Copying text command was ' + msg); |
| 3499 |
} catch (err) { |
| 3500 |
console.log('Oops, unable to copy'); |
| 3501 |
} |
| 3502 |
$temp_txtarea.remove(); |
| 3503 |
return false; |
| 3504 |
}); |
| 3505 |
|
| 3506 |
jQuery(document).ready(function () { |
| 3507 |
if (typeof postboxes !== "undefined" && typeof mainwp_postbox_page !== "undefined") { |
| 3508 |
postboxes.add_postbox_toggles(mainwp_postbox_page); |
| 3509 |
} |
| 3510 |
mainwp_setCookie(); |
| 3511 |
mainwp_getCookie(); |
| 3512 |
}); |
| 3513 |
|
| 3514 |
jQuery(document).on('click', '.close.icon', function () { |
| 3515 |
jQuery(this).parent().hide(); |
| 3516 |
}); |
| 3517 |
|
| 3518 |
/* |
| 3519 |
* to compatible |
| 3520 |
*/ |
| 3521 |
function mainwp_setCookie() { |
| 3522 |
return false; |
| 3523 |
} |
| 3524 |
|
| 3525 |
function mainwp_getCookie() { |
| 3526 |
return false; |
| 3527 |
} |
| 3528 |
|