PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.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 5.2.1 5.2.2 5.3 All 153 releases
mainwp / assets / js / mainwp.js

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

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