PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.2
6.2.3 6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 All 156 releases
mainwp / assets / js / mainwp.js

mainwp.js in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.0.2, at assets/js/mainwp.js

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