| @@ -1,210 +1,343 @@ | ||
| 1 | -/* eslint complexity: ["error", 100] */ | |
| 1 | +/* eslint-disable complexity */ | |
| 2 | 2 | // current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 3 | 3 | |
| 4 | -jQuery(document).ready(function ($) { | |
| 4 | +globalThis.mainwpVars = globalThis.mainwpVars || {}; | |
| 5 | 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 | - }); | |
| 6 | +jQuery(function ($) { | |
| 15 | 7 | |
| 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(); | |
| 8 | + if (jQuery('.mainwp-ui-page').length) { | |
| 9 | + jQuery('.mainwp-popup-tooltip').popup() | |
| 29 | 10 | } |
| 30 | - }); | |
| 31 | 11 | |
| 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 | - }); | |
| 12 | + jQuery(document).on('click', '#mainwp-help-menu-item, #mainwp-help-menu-item-mobile', function () { | |
| 13 | + jQuery('#mainwp-help-modal').modal({ | |
| 14 | + inverted: true, | |
| 15 | + blurring: false, | |
| 16 | + closable: false, | |
| 17 | + onShow: function () { | |
| 18 | + jQuery('#mainwp-help-modal').parent('.ui.dimmer').removeClass('dimmer'); | |
| 19 | + jQuery('#mainwp-help-modal').css({ | |
| 20 | + 'top': (jQuery(globalThis).height() - jQuery('#mainwp-help-modal').outerHeight()) / 2 + 'px', | |
| 21 | + 'left': (jQuery(globalThis).width() - jQuery('#mainwp-help-modal').outerWidth()) / 2 + 'px' | |
| 22 | + }); | |
| 23 | + }, | |
| 40 | 24 | |
| 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 | - }); | |
| 25 | + }).modal('show').draggable().resizable({ | |
| 26 | + handles: "n, e, s, w, ne, nw, se, sw", // Allows resizing from all edges | |
| 27 | + minWidth: 300, // Set minimum width | |
| 28 | + minHeight: 640, // Set minimum height | |
| 29 | + }); | |
| 30 | + return false; | |
| 31 | + }); | |
| 46 | 32 | |
| 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 () { | |
| 33 | + // review for new UI update | |
| 34 | + jQuery(document).on('click', '#mainwp-category-add-submit', function () { | |
| 35 | + let newCat = jQuery('#newcategory').val(); | |
| 36 | + newCat = encodeURIComponent(newCat).replaceAll('%20', ' '); | |
| 51 | 37 | |
| 52 | - feedback('mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + __('Removing the site. Please wait...', 'mainwp'), ''); | |
| 38 | + if (jQuery('#categorychecklist .menu').find('.item[data-value="' + newCat + '"]').length > 0) { | |
| 39 | + jQuery('#newcategory').val(''); | |
| 40 | + return; | |
| 41 | + } | |
| 42 | + let selected_categories = jQuery('#categorychecklist').dropdown('get value'); | |
| 43 | + jQuery('#categorychecklist .menu').append('<div class="item" data-value="' + newCat + '">' + newCat + '</div>'); | |
| 44 | + jQuery('#categorychecklist .menu').dropdown('set selected', selected_categories); // to refresh. | |
| 45 | + jQuery('#newcategory').val(''); | |
| 46 | + }); | |
| 53 | 47 | |
| 54 | - var data = mainwp_secure_data({ | |
| 55 | - action: 'mainwp_removesite', | |
| 56 | - id: side_id | |
| 57 | - }); | |
| 48 | + // Show/Hide new category field and button | |
| 49 | + jQuery(document).on('click', '#category-add-toggle', function () { | |
| 50 | + jQuery('#newcategory-field').toggle(); | |
| 51 | + jQuery('#mainwp-category-add-submit-field').toggle(); | |
| 52 | + return false; | |
| 53 | + }); | |
| 58 | 54 | |
| 59 | - jQuery.post(ajaxurl, data, function (response) { | |
| 55 | + // Manage Child options | |
| 56 | + $('.mainwp-parent-toggle input[type="checkbox"]').on('change', function () { | |
| 57 | + if (this.checked) { | |
| 58 | + $(this).closest('.mainwp-parent-toggle').next('.mainwp-child-field').fadeIn(); | |
| 59 | + } else { | |
| 60 | + $(this).closest('.mainwp-parent-toggle').next('.mainwp-child-field').fadeOut(); | |
| 61 | + } | |
| 62 | + }); | |
| 60 | 63 | |
| 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; | |
| 64 | + //Toggle Add Site form | |
| 65 | + jQuery('#mainwp_managesites_verify_installed_child').on('change', function () { | |
| 66 | + if (jQuery(this).is(':checked')) { | |
| 67 | + jQuery('#mainwp-add-site-hidden-form').fadeIn(500); | |
| 70 | 68 | } 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'); | |
| 69 | + jQuery('#mainwp-add-site-hidden-form').fadeOut(500); | |
| 72 | 70 | } |
| 71 | + }); | |
| 73 | 72 | |
| 74 | - if (error == false) { | |
| 75 | - setTimeout(function () { | |
| 76 | - window.location = 'admin.php?page=managesites'; | |
| 77 | - }, 3000); | |
| 78 | - } | |
| 73 | + // Toggle Add Site / Optional Settings section | |
| 74 | + jQuery('#mainwp-add-site-advanced-options-toggle').on('click', function () { | |
| 75 | + jQuery('#mainwp-add-site-advanced-options').toggle(500); | |
| 76 | + return false; | |
| 77 | + }); | |
| 79 | 78 | |
| 80 | - }, 'json'); | |
| 81 | - }, false, false, false, 'REMOVE'); | |
| 79 | + jQuery('.mainwp-remove-site-button').on('click', function () { | |
| 80 | + let side_id = jQuery(this).attr('site-id'); | |
| 81 | + let confirmation = "Are you sure you want to remove this site from your MainWP Dashboard?"; | |
| 82 | 82 | |
| 83 | - return false; | |
| 84 | - }); | |
| 83 | + let _confirm_callback = mainwp_get_remove_calback(side_id); | |
| 85 | 84 | |
| 85 | + mainwp_confirm(confirmation, _confirm_callback, false, false, false, 'REMOVE'); | |
| 86 | + | |
| 87 | + return false; | |
| 88 | + }); | |
| 89 | + | |
| 86 | 90 | }); |
| 87 | 91 | |
| 92 | +let mainwp_get_remove_calback = function (side_id) { | |
| 93 | + return function () { | |
| 94 | + feedback('mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Removing the site. Please wait...'), ''); | |
| 95 | + let data = mainwp_secure_data({ | |
| 96 | + action: 'mainwp_removesite', | |
| 97 | + id: side_id | |
| 98 | + }); | |
| 99 | + | |
| 100 | + jQuery.ajax({ | |
| 101 | + url: ajaxurl, | |
| 102 | + data: data, | |
| 103 | + timeout: 180000, // 3 minutes. Slightly longer than the PHP server timeout (2 minutes). | |
| 104 | + method: 'POST', | |
| 105 | + success: function (response) { | |
| 106 | + | |
| 107 | + const removed_site = response?.removed_site ?? false; | |
| 108 | + let msg_not_removed = MainWP.I18n.t('Site could not be removed. Please reload the page and try again.'); | |
| 109 | + | |
| 110 | + let error_msg = ''; | |
| 111 | + | |
| 112 | + if (typeof response?.error === 'string' && response.error.trim() !== '') { | |
| 113 | + error_msg = MainWP.I18n.t('Details:') + ' ' + response.error; | |
| 114 | + msg_not_removed += ' ' + error_msg; | |
| 115 | + } | |
| 116 | + | |
| 117 | + if (response?.undefined_error) { | |
| 118 | + if (!removed_site) { | |
| 119 | + feedback( | |
| 120 | + 'mainwp-message-zone', | |
| 121 | + msg_not_removed, | |
| 122 | + 'red' | |
| 123 | + ); | |
| 124 | + return; | |
| 125 | + } | |
| 126 | + feedback( | |
| 127 | + 'mainwp-message-zone', | |
| 128 | + MainWP.I18n.t('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.'), | |
| 129 | + 'red' | |
| 130 | + ); | |
| 131 | + } else if (!removed_site) { | |
| 132 | + feedback( | |
| 133 | + 'mainwp-message-zone', | |
| 134 | + msg_not_removed, | |
| 135 | + 'red' | |
| 136 | + ); | |
| 137 | + return; | |
| 138 | + } else if (response?.error) { | |
| 139 | + let message = MainWP.I18n.t('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.'); | |
| 140 | + if (error_msg) { | |
| 141 | + message += ' ' + error_msg; | |
| 142 | + } | |
| 143 | + feedback('mainwp-message-zone', message, 'red'); | |
| 144 | + } else { | |
| 145 | + switch (response?.result) { | |
| 146 | + case 'SUCCESS': | |
| 147 | + feedback( | |
| 148 | + 'mainwp-message-zone', | |
| 149 | + MainWP.I18n.t('The site has been removed and the MainWP Child plugin has been disabled. You will be redirected to the Sites page right away.'), | |
| 150 | + 'green' | |
| 151 | + ); | |
| 152 | + break; | |
| 153 | + case 'REMOVED': // for demo sites. | |
| 154 | + feedback( | |
| 155 | + 'mainwp-message-zone', | |
| 156 | + MainWP.I18n.t('The site has been removed. You will be redirected to the Sites page right away.'), | |
| 157 | + 'green' | |
| 158 | + ); | |
| 159 | + break; | |
| 160 | + case 'NOSITE': | |
| 161 | + feedback( | |
| 162 | + 'mainwp-message-zone', | |
| 163 | + msg_not_removed, | |
| 164 | + 'red' | |
| 165 | + ); | |
| 166 | + return; | |
| 167 | + default: | |
| 168 | + feedback( | |
| 169 | + 'mainwp-message-zone', | |
| 170 | + MainWP.I18n.t('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.'), | |
| 171 | + 'green' | |
| 172 | + ); | |
| 173 | + } | |
| 174 | + } | |
| 175 | + setTimeout(function () { | |
| 176 | + mainwp_forceReload('admin.php?page=managesites'); | |
| 177 | + }, 3000); | |
| 178 | + }, | |
| 179 | + error: function (xhr, textStatus) { | |
| 180 | + if (textStatus === 'timeout') { | |
| 181 | + feedback( | |
| 182 | + 'mainwp-message-zone', | |
| 183 | + MainWP.I18n.t('The request timed out. Please make sure that the MainWP Child plugin has been deactivated properly.'), | |
| 184 | + 'red' | |
| 185 | + ); | |
| 186 | + return; | |
| 187 | + } | |
| 188 | + | |
| 189 | + feedback( | |
| 190 | + 'mainwp-message-zone', | |
| 191 | + MainWP.I18n.t('An unexpected error occurred. Please reload the page and try again.'), | |
| 192 | + 'red' | |
| 193 | + ); | |
| 194 | + }, | |
| 195 | + dataType: 'json' | |
| 196 | + }); | |
| 197 | + } | |
| 198 | + | |
| 199 | +} | |
| 200 | + | |
| 201 | +globalThis.mainwp_set_message_zone = globalThis.mainwp_set_message_zone || function (zone_selector, msg_html, colors, show) { | |
| 202 | + if (msg_html) { | |
| 203 | + jQuery(zone_selector).html(msg_html); | |
| 204 | + } else if (msg_html === '' || msg_html === undefined) { | |
| 205 | + jQuery(zone_selector).html(''); | |
| 206 | + } | |
| 207 | + | |
| 208 | + if (colors !== undefined && colors != '') { | |
| 209 | + jQuery(zone_selector).removeClass('green yellow red'); | |
| 210 | + jQuery(zone_selector).addClass(colors); | |
| 211 | + } else if (colors === '' || colors === undefined) { | |
| 212 | + jQuery(zone_selector).removeClass('green yellow red'); | |
| 213 | + } | |
| 214 | + | |
| 215 | + if (true === show || (false !== show && msg_html)) { | |
| 216 | + jQuery(zone_selector).show(); | |
| 217 | + } else { | |
| 218 | + jQuery(zone_selector).hide(); | |
| 219 | + } | |
| 220 | +}; | |
| 221 | + | |
| 222 | +let bulkInstallMaxThreads = mainwpParams['maximumInstallUpdateRequests'] == undefined ? 3 : mainwpParams['maximumInstallUpdateRequests']; | |
| 223 | +let bulkInstallCurrentThreads = 0; | |
| 224 | +let bulkInstallDone = 0; | |
| 225 | + | |
| 88 | 226 | /** |
| 89 | 227 | * Global |
| 90 | 228 | */ |
| 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 | - }); | |
| 229 | +jQuery(function () { | |
| 230 | + jQuery('.mainwp-row').on({ | |
| 231 | + mouseenter: function () { | |
| 232 | + rowMouseEnter(this); | |
| 233 | + }, | |
| 234 | + mouseleave: function () { | |
| 235 | + rowMouseLeave(this); | |
| 236 | + } | |
| 237 | + }); | |
| 100 | 238 | }); |
| 101 | -rowMouseEnter = function (elem) { | |
| 102 | - if (!jQuery(elem).children('.mainwp-row-actions-working').is(":visible")) | |
| 103 | - jQuery(elem).children('.mainwp-row-actions').show(); | |
| 239 | +let rowMouseEnter = function (elem) { | |
| 240 | + if (!jQuery(elem).children('.mainwp-row-actions-working').is(":visible")) | |
| 241 | + jQuery(elem).children('.mainwp-row-actions').show(); | |
| 104 | 242 | }; |
| 105 | -rowMouseLeave = function (elem) { | |
| 106 | - if (jQuery(elem).children('.mainwp-row-actions').is(":visible")) | |
| 107 | - jQuery(elem).children('.mainwp-row-actions').hide(); | |
| 243 | +let rowMouseLeave = function (elem) { | |
| 244 | + if (jQuery(elem).children('.mainwp-row-actions').is(":visible")) | |
| 245 | + jQuery(elem).children('.mainwp-row-actions').hide(); | |
| 108 | 246 | }; |
| 109 | 247 | |
| 110 | - | |
| 111 | -mainwp_sidebar_position_onchange = function (me) { | |
| 112 | - jQuery(me).closest("form").submit(); | |
| 113 | -} | |
| 114 | - | |
| 115 | 248 | /** |
| 116 | 249 | * Recent posts |
| 117 | 250 | */ |
| 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 | - }); | |
| 251 | +jQuery(function () { | |
| 252 | + jQuery(document).on('click', '.mainwp-post-unpublish', function () { | |
| 253 | + postAction(jQuery(this), 'unpublish'); | |
| 254 | + return false; | |
| 255 | + }); | |
| 256 | + jQuery(document).on('click', '.mainwp-post-publish', function () { | |
| 257 | + postAction(jQuery(this), 'publish'); | |
| 258 | + return false; | |
| 259 | + }); | |
| 260 | + jQuery(document).on('click', '.mainwp-post-trash', function () { | |
| 261 | + postAction(jQuery(this), 'trash'); | |
| 262 | + return false; | |
| 263 | + }); | |
| 264 | + jQuery(document).on('click', '.mainwp-post-restore', function () { | |
| 265 | + postAction(jQuery(this), 'restore'); | |
| 266 | + return false; | |
| 267 | + }); | |
| 268 | + jQuery(document).on('click', '.mainwp-post-delete', function () { | |
| 269 | + postAction(jQuery(this), 'delete'); | |
| 270 | + return false; | |
| 271 | + }); | |
| 139 | 272 | |
| 140 | 273 | }); |
| 141 | 274 | |
| 142 | 275 | // 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(); | |
| 276 | +let postAction = function (elem, what) { | |
| 277 | + let rowElement = jQuery(elem).closest('.grid'); | |
| 278 | + let postId = rowElement.children('.postId').val(); | |
| 279 | + let websiteId = rowElement.children('.websiteId').val(); | |
| 147 | 280 | |
| 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; | |
| 281 | + let data = mainwp_secure_data({ | |
| 282 | + action: 'mainwp_post_' + what, | |
| 283 | + postId: postId, | |
| 284 | + websiteId: websiteId | |
| 285 | + }); | |
| 286 | + rowElement.hide(); | |
| 287 | + rowElement.next('.mainwp-row-actions-working').show(); | |
| 288 | + jQuery.post(ajaxurl, data, function (response) { | |
| 289 | + if (response.error) { | |
| 290 | + rowElement.show(); | |
| 291 | + rowElement.next('.mainwp-row-actions-working').hide(); | |
| 292 | + rowElement.html('<div class="sixteen wide column"><i class="times red icon"></i> ' + response.error + '</div>'); | |
| 293 | + } else if (response.result) { | |
| 294 | + rowElement.show(); | |
| 295 | + rowElement.next('.mainwp-row-actions-working').hide(); | |
| 296 | + rowElement.html('<div class="sixteen wide column"><i class="check green icon"></i>' + response.result + '</div>'); | |
| 297 | + } else { | |
| 298 | + rowElement.show(); | |
| 299 | + rowElement.next('.mainwp-row-actions-working').hide(); | |
| 300 | + } | |
| 301 | + }, 'json'); | |
| 302 | + return false; | |
| 170 | 303 | }; |
| 171 | 304 | |
| 172 | 305 | |
| 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 | - } | |
| 306 | +let mainwp_post_posting_start_next = function (start) { | |
| 307 | + if (start !== undefined && start) { | |
| 308 | + bulkInstallDone = 0; | |
| 309 | + bulkInstallCurrentThreads = 0; | |
| 310 | + mainwpVars.bulkInstallTotal = jQuery('.site-bulk-posting[status="queue"]').length; | |
| 311 | + } | |
| 312 | + while ((siteToPosting = jQuery('.site-bulk-posting[status="queue"]:first')) && (siteToPosting.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { // NOSONAR -- modified out side the function. | |
| 313 | + mainwp_post_posting_start_specific(siteToPosting); | |
| 314 | + } | |
| 182 | 315 | }; |
| 183 | 316 | |
| 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'); | |
| 317 | +let mainwp_post_posting_start_specific = function (siteToPosting) { | |
| 318 | + siteToPosting.attr('status', 'progress'); | |
| 319 | + bulkInstallDone++; | |
| 320 | + bulkInstallCurrentThreads++; | |
| 321 | + let data = mainwp_secure_data({ | |
| 322 | + action: 'mainwp_post_postingbulk', | |
| 323 | + post_id: jQuery('#bulk_posting_id').val(), | |
| 324 | + site_id: jQuery(siteToPosting).attr('site-id'), | |
| 325 | + count: bulkInstallDone, | |
| 326 | + total: mainwpVars.bulkInstallTotal, | |
| 327 | + delete_bulkpost: (bulkInstallDone == mainwpVars.bulkInstallTotal) | |
| 328 | + }); | |
| 329 | + siteToPosting.find('.progress').html('<i class="notched circle loading icon"></i>'); | |
| 330 | + jQuery.post(ajaxurl, data, function (response) { | |
| 331 | + bulkInstallCurrentThreads--; | |
| 332 | + if (response?.result) { | |
| 333 | + siteToPosting.find('.progress').html(response.result); | |
| 334 | + if (response.edit_link !== '') { | |
| 335 | + siteToPosting.after(response.edit_link); | |
| 336 | + } | |
| 337 | + } | |
| 338 | + mainwp_post_posting_start_next(); | |
| 339 | + }, 'json'); | |
| 207 | 340 | } |
| 208 | 341 | |
| 209 | 342 | |
| 210 | 343 | /** |
| @@ -209,206 +342,211 @@ | ||
| 209 | 342 | |
| 210 | 343 | /** |
| 211 | 344 | * Plugins Widget |
| 212 | 345 | */ |
| 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 | - }); | |
| 346 | +jQuery(function () { | |
| 347 | + jQuery(document).on('click', '.mainwp-plugin-deactivate', function () { | |
| 348 | + pluginAction(jQuery(this), 'deactivate'); | |
| 349 | + return false; | |
| 350 | + }); | |
| 351 | + jQuery(document).on('click', '.mainwp-plugin-activate', function () { | |
| 352 | + pluginAction(jQuery(this), 'activate'); | |
| 353 | + return false; | |
| 354 | + }); | |
| 355 | + jQuery(document).on('click', '.mainwp-plugin-delete', function () { | |
| 356 | + let name = jQuery(this).closest('.row-manage-item').attr('plugin-title'); | |
| 357 | + let confirmMsg = MainWP.I18n.t('You are about to delete the %1?', name); | |
| 358 | + mainwp_confirm(confirmMsg, () => { | |
| 359 | + pluginAction(jQuery(this), 'delete'); | |
| 360 | + }); | |
| 361 | + return false; | |
| 362 | + }); | |
| 226 | 363 | }); |
| 227 | 364 | |
| 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 | 365 | |
| 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'); | |
| 366 | +let pluginAction = function (elem, what) { | |
| 367 | + let rowElement = jQuery(elem).closest('.row-manage-item'); | |
| 368 | + let plugin = rowElement.children('.pluginSlug').val(); | |
| 369 | + let websiteId = rowElement.children('.websiteId').val(); | |
| 251 | 370 | |
| 252 | - return false; | |
| 371 | + let data = mainwp_secure_data({ | |
| 372 | + action: 'mainwp_widget_plugin_' + what, | |
| 373 | + plugin: plugin, | |
| 374 | + websiteId: websiteId | |
| 375 | + }); | |
| 376 | + plugin_theme_doAction(data, rowElement); | |
| 377 | + return false; | |
| 253 | 378 | }; |
| 254 | 379 | |
| 255 | 380 | /** |
| 256 | 381 | * Themes Widget |
| 257 | 382 | */ |
| 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 | - }); | |
| 383 | +jQuery(function () { | |
| 384 | + jQuery(document).on('click', '.mainwp-theme-activate', function () { | |
| 385 | + themeAction(jQuery(this), 'activate'); | |
| 386 | + return false; | |
| 387 | + }); | |
| 388 | + jQuery(document).on('click', '.mainwp-theme-delete', function () { | |
| 389 | + let name = jQuery(this).closest('.row-manage-item').children('.themeName').val(); | |
| 390 | + let confirmMsg = MainWP.I18n.t('You are about to delete the %1?', name); | |
| 391 | + mainwp_confirm(confirmMsg, () => { | |
| 392 | + themeAction(jQuery(this), 'delete'); | |
| 393 | + }); | |
| 394 | + return false; | |
| 395 | + }); | |
| 267 | 396 | }); |
| 268 | 397 | |
| 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(); | |
| 398 | +let themeAction = function (elem, what) { | |
| 399 | + let rowElement = jQuery(elem).closest('.row-manage-item'); | |
| 400 | + let theme = rowElement.children('.themeSlug').val(); | |
| 401 | + let websiteId = rowElement.children('.websiteId').val(); | |
| 402 | + let data = mainwp_secure_data({ | |
| 403 | + action: 'mainwp_widget_theme_' + what, | |
| 404 | + theme: theme, | |
| 405 | + websiteId: websiteId | |
| 406 | + }); | |
| 407 | + plugin_theme_doAction(data, rowElement); | |
| 408 | + return false; | |
| 409 | +}; | |
| 273 | 410 | |
| 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'); | |
| 411 | +let plugin_theme_doAction = function (data, rowElement) { | |
| 412 | + rowElement.children().hide(); | |
| 413 | + rowElement.children('.mainwp-row-actions-working').show(); | |
| 414 | + jQuery.post(ajaxurl, data, function (response) { | |
| 415 | + if (response?.error) { | |
| 416 | + rowElement.children().show(); | |
| 417 | + rowElement.html(response.error); | |
| 418 | + } else if (response?.result) { | |
| 419 | + rowElement.children().show(); | |
| 420 | + rowElement.html(response.result); | |
| 421 | + } else { | |
| 422 | + rowElement.children('.mainwp-row-actions-working').hide(); | |
| 423 | + } | |
| 424 | + }, 'json'); | |
| 425 | +}; | |
| 292 | 426 | |
| 293 | - return false; | |
| 294 | -}; | |
| 295 | 427 | |
| 296 | 428 | // offsetRelative (or, if you prefer, positionRelative) |
| 297 | 429 | (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)); | |
| 430 | + $.fn.offsetRelative = function (top) { | |
| 431 | + let $this = $(this); | |
| 432 | + let $parent = $this.offsetParent(); | |
| 433 | + let offset = $this.position(); | |
| 434 | + if (!top) | |
| 435 | + return offset; // Didn't pass a 'top' element | |
| 436 | + else if ($parent.get(0).tagName == "BODY") | |
| 437 | + return offset; // Reached top of document | |
| 438 | + else if ($(top, $parent).length) | |
| 439 | + return offset; // Parent element contains the 'top' element we want the offset to be relative to | |
| 440 | + else if ($parent[0] == $(top)[0]) | |
| 441 | + return offset; // Reached the 'top' element we want the offset to be relative to | |
| 442 | + else { // Get parent's relative offset | |
| 443 | + let parent_offset = $parent.offsetRelative(top); | |
| 444 | + offset.top += parent_offset.top; | |
| 445 | + offset.left += parent_offset.left; | |
| 446 | + return offset; | |
| 447 | + } | |
| 448 | + }; | |
| 449 | + $.fn.positionRelative = function (top) { | |
| 450 | + return $(this).offsetRelative(top); | |
| 451 | + }; | |
| 452 | +})(jQuery); | |
| 321 | 453 | |
| 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]]); | |
| 454 | +let hidingSubMenuTimers = {}; | |
| 455 | +jQuery(function () { | |
| 456 | + jQuery('.mainwp-submenu-wrapper').on({ | |
| 457 | + mouseenter: function () { | |
| 458 | + let spanId = /^menu-mainwp-(.*)$/.exec(jQuery(this).attr('id')); | |
| 459 | + if (spanId) { | |
| 460 | + if (hidingSubMenuTimers[spanId[1]]) { | |
| 461 | + clearTimeout(hidingSubMenuTimers[spanId[1]]); | |
| 462 | + } | |
| 463 | + } | |
| 464 | + }, | |
| 465 | + mouseleave: function () { | |
| 466 | + let spanId = /^menu-mainwp-(.*)$/.exec(jQuery(this).attr('id')); | |
| 467 | + if (spanId) { | |
| 468 | + hidingSubMenuTimers[spanId[1]] = setTimeout(function (span) { | |
| 469 | + return function () { | |
| 470 | + subMenuOut(span); | |
| 471 | + }; | |
| 472 | + }(spanId[1]), 30); | |
| 473 | + } | |
| 357 | 474 | } |
| 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 | - }); | |
| 475 | + }); | |
| 371 | 476 | }); |
| 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'); | |
| 477 | +let subMenuOut = function (subName) { | |
| 478 | + jQuery('#menu-mainwp-' + subName).hide(); | |
| 479 | + jQuery('#mainwp-' + subName).parent().parent().css('background-color', ''); | |
| 480 | + jQuery('#mainwp-' + subName).parent().parent().removeClass('hoverli'); | |
| 481 | + jQuery('#mainwp-' + subName).css('color', ''); | |
| 377 | 482 | }; |
| 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 | -}; | |
| 483 | +// eslint-disable-next-line complexity | |
| 484 | +globalThis.mainwp_js_get_error_not_detected_connect = function (jsonStr, what, elemId, retErrText) { // NOSONAR - complexity. | |
| 485 | + if (undefined !== jsonStr && '' != jsonStr && undefined !== what && 'html_msg' === what) { | |
| 486 | + try { | |
| 487 | + let obj_err = JSON.parse(jsonStr); | |
| 488 | + if (typeof obj_err === 'object') { | |
| 489 | + if (obj_err?.el_before && obj_err?.el_link && obj_err?.el_text) { | |
| 490 | + let elafter = obj_err.el_after === undefined ? '' : obj_err.el_after; | |
| 491 | + if (true === retErrText) { | |
| 492 | + return obj_err.el_before + obj_err.el_text + elafter; | |
| 493 | + } | |
| 494 | + if (undefined !== elemId && '' != elemId) { | |
| 495 | + let el = document.createElement('a'); | |
| 496 | + el.text = obj_err.el_text; | |
| 497 | + el.href = obj_err.el_link; | |
| 498 | + el.target = "_blank"; | |
| 499 | + console.log(el); | |
| 500 | + jQuery('#' + elemId).html('').append(document.createTextNode(obj_err.el_before), el, document.createTextNode(elafter)); | |
| 501 | + feedback_scroll(elemId, 'red'); | |
| 502 | + } | |
| 503 | + return true; | |
| 504 | + } | |
| 505 | + } else { | |
| 506 | + return false; // it is not or invalid json. | |
| 507 | + } | |
| 508 | + } catch (e) { | |
| 509 | + console.log(e); | |
| 510 | + return false; // it is not or invalid json. | |
| 511 | + } | |
| 512 | + } | |
| 513 | + return MainWP.I18n.t('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.'); | |
| 514 | +} | |
| 384 | 515 | |
| 516 | +globalThis.mainwp_get_reconnect_error = function (response, siteId) { // NOSONAR - complexity. | |
| 517 | + if ('reconnect_failed' === response) { | |
| 518 | + return MainWP.I18n.t('Reconnect failed. Please try again from the %1Site Settings page%2.', '<a href="admin.php?page=managesites&id=' + siteId + '">', '</a>'); | |
| 519 | + } else { | |
| 520 | + return response; | |
| 521 | + } | |
| 522 | +} | |
| 385 | 523 | |
| 386 | 524 | function shake_element(select) { |
| 387 | - var pos = jQuery(select).position(); | |
| 388 | - var type = jQuery(select).css('position'); | |
| 525 | + let pos = jQuery(select).position(); | |
| 526 | + let type = jQuery(select).css('position'); | |
| 389 | 527 | |
| 390 | - if (type == 'static') { | |
| 391 | - jQuery(select).css({ | |
| 392 | - position: 'relative' | |
| 393 | - }); | |
| 394 | - } | |
| 528 | + if (type == 'static') { | |
| 529 | + jQuery(select).css({ | |
| 530 | + position: 'relative' | |
| 531 | + }); | |
| 532 | + } | |
| 395 | 533 | |
| 396 | - if (type == 'static' || type == 'relative') { | |
| 397 | - pos.top = 0; | |
| 398 | - pos.left = 0; | |
| 399 | - } | |
| 534 | + if (type == 'static' || type == 'relative') { | |
| 535 | + pos.top = 0; | |
| 536 | + pos.left = 0; | |
| 537 | + } | |
| 400 | 538 | |
| 401 | - jQuery(select).data('init-type', type); | |
| 539 | + jQuery(select).data('init-type', type); | |
| 402 | 540 | |
| 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]]; | |
| 541 | + let 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 | 542 | |
| 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 | - } | |
| 543 | + for (let s of shake) { | |
| 544 | + jQuery(select).animate({ | |
| 545 | + top: pos.top + s[0], | |
| 546 | + left: pos.left + s[1] | |
| 547 | + }, s[2], 'linear'); | |
| 548 | + } | |
| 411 | 549 | } |
| 412 | 550 | |
| 413 | 551 | |
| 414 | 552 | /** |
| @@ -413,54 +551,93 @@ | ||
| 413 | 551 | |
| 414 | 552 | /** |
| 415 | 553 | * Required |
| 416 | 554 | */ |
| 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; | |
| 555 | +globalThis.feedback = function (id, text, type, append) { | |
| 556 | + if (append) { | |
| 557 | + let currentHtml = jQuery('#' + id).html(); | |
| 558 | + if (currentHtml == null) | |
| 559 | + currentHtml = ""; | |
| 560 | + if (currentHtml == '') { | |
| 561 | + currentHtml = text; | |
| 562 | + } else { | |
| 563 | + currentHtml += '<br />' + text; | |
| 564 | + } | |
| 565 | + jQuery('#' + id).html(currentHtml); | |
| 566 | + jQuery('#' + id).removeClass('yellow'); | |
| 567 | + jQuery('#' + id).removeClass('green'); | |
| 568 | + jQuery('#' + id).removeClass('red'); | |
| 569 | + jQuery('#' + id).addClass(type); | |
| 424 | 570 | } else { |
| 425 | - currentHtml = text; | |
| 571 | + jQuery('#' + id).html(text); | |
| 572 | + jQuery('#' + id).removeClass('yellow'); | |
| 573 | + jQuery('#' + id).removeClass('green'); | |
| 574 | + jQuery('#' + id).removeClass('red'); | |
| 575 | + jQuery('#' + id).addClass(type); | |
| 426 | 576 | } |
| 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(); | |
| 577 | + jQuery('#' + id).show(); | |
| 440 | 578 | |
| 441 | - // automatically scroll to error message if it's not visible | |
| 442 | - scrollElementTop(id); | |
| 579 | + // automatically scroll to error message if it's not visible | |
| 580 | + scrollElementTop(id); | |
| 443 | 581 | }; |
| 444 | 582 | |
| 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 :) | |
| 583 | +globalThis.feedback_scroll = function (id, color) { | |
| 584 | + jQuery('#' + id).removeClass('green red yellow'); | |
| 585 | + jQuery('#' + id).addClass(color); | |
| 586 | + jQuery('#' + id).show(); | |
| 587 | + // automatically scroll to error message if it's not visible | |
| 588 | + scrollElementTop(id); | |
| 459 | 589 | } |
| 460 | 590 | |
| 461 | -jQuery(document).ready(function () { | |
| 462 | - jQuery('div.mainwp-hidden').parent().parent().css("display", "none"); | |
| 591 | +globalThis.scrollElementTop = function (id) { | |
| 592 | + let scrolltop = jQuery(globalThis).scrollTop(); | |
| 593 | + if (jQuery('#' + id).length == 0) { | |
| 594 | + return; | |
| 595 | + } | |
| 596 | + let off = jQuery('#' + id).offset(); | |
| 597 | + if (scrolltop > off.top - 40) | |
| 598 | + jQuery('html, body').animate({ | |
| 599 | + scrollTop: off.top - 40 | |
| 600 | + }, 1000, function () { | |
| 601 | + shake_element('#' + id) | |
| 602 | + }); | |
| 603 | + else | |
| 604 | + shake_element('#' + id); // shake the error message to get attention :) | |
| 605 | +} | |
| 606 | + | |
| 607 | +globalThis.mainwp_showhide_message = function (id, content, cls, append, scroll) { | |
| 608 | + | |
| 609 | + if ('' === content) { | |
| 610 | + jQuery('#' + id).html('').fadeOut(500); | |
| 611 | + return; | |
| 612 | + } | |
| 613 | + | |
| 614 | + if (append) { | |
| 615 | + let html = jQuery('#' + id).html(); | |
| 616 | + if (html == null) | |
| 617 | + html = ""; | |
| 618 | + if (html == '') { | |
| 619 | + html = content; | |
| 620 | + } else { | |
| 621 | + html += '<br />' + content; | |
| 622 | + } | |
| 623 | + jQuery('#' + id).html(html); | |
| 624 | + } else { | |
| 625 | + jQuery('#' + id).html(content); | |
| 626 | + } | |
| 627 | + | |
| 628 | + jQuery('#' + id).removeClass('yellow green red'); | |
| 629 | + jQuery('#' + id).addClass(cls); | |
| 630 | + jQuery('#' + id).show(); | |
| 631 | + | |
| 632 | + if (scroll === undefined && scroll) { | |
| 633 | + scrollElementTop(id); | |
| 634 | + } | |
| 635 | + | |
| 636 | +}; | |
| 637 | + | |
| 638 | +jQuery(function () { | |
| 639 | + jQuery('div.mainwp-hidden').parent().parent().css("display", "none"); | |
| 463 | 640 | }); |
| 464 | 641 | |
| 465 | 642 | /** |
| 466 | 643 | * Security Issues |
| @@ -465,1846 +642,2016 @@ | ||
| 465 | 642 | /** |
| 466 | 643 | * Security Issues |
| 467 | 644 | */ |
| 468 | 645 | |
| 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 | - }); | |
| 646 | +let securityIssues_fixes = ['core_updates', 'plugin_updates', 'theme_updates', 'db_reporting', 'php_reporting', 'wp_uptodate', 'phpversion_matched', 'sslprotocol', 'debug_disabled', 'sec_outdated_plugins', 'sec_inactive_plugins', 'sec_outdated_themes', 'sec_inactive_themes']; | |
| 647 | +jQuery(function () { | |
| 648 | + let securityIssueSite = jQuery('#securityIssueSite'); | |
| 649 | + if ((securityIssueSite.val() != null) && (securityIssueSite.val() != "")) { | |
| 650 | + jQuery(document).on('click', '#securityIssues_refresh', function () { | |
| 651 | + for (let ise of securityIssues_fixes) { | |
| 652 | + let securityIssueCurrentIssue = jQuery('#' + ise + '_fix'); | |
| 653 | + if (securityIssueCurrentIssue) { | |
| 654 | + securityIssueCurrentIssue.hide(); | |
| 655 | + } | |
| 656 | + jQuery('#' + ise + '_extra').hide(); | |
| 657 | + jQuery('#' + ise + '_ok').hide(); | |
| 658 | + jQuery('#' + ise + '_nok').hide(); | |
| 659 | + jQuery('#' + ise + '_loading').show(); | |
| 660 | + } | |
| 661 | + securityIssues_request(jQuery('#securityIssueSite').val()); | |
| 662 | + }); | |
| 476 | 663 | |
| 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 | - }); | |
| 664 | + for (let ise of securityIssues_fixes) { | |
| 665 | + if (ise === 'wp_uptodate' || ise === 'sec_inactive_themes' || ise === 'sec_inactive_plugins' || ise === 'sec_outdated_plugins' || ise === 'sec_outdated_themes') { | |
| 666 | + continue; | |
| 667 | + } | |
| 668 | + jQuery('#' + ise + '_fix').on('click', function (what) { | |
| 669 | + return function () { | |
| 670 | + securityIssues_fix(what); | |
| 671 | + return false; | |
| 672 | + } | |
| 673 | + }(ise)); | |
| 490 | 674 | |
| 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; | |
| 675 | + jQuery('#' + ise + '_unfix').on('click', function (what) { | |
| 676 | + return function () { | |
| 677 | + securityIssues_unfix(what); | |
| 678 | + return false; | |
| 679 | + } | |
| 680 | + }(ise)); | |
| 496 | 681 | } |
| 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])); | |
| 682 | + securityIssues_request(securityIssueSite.val()); | |
| 505 | 683 | } |
| 506 | - securityIssues_request(securityIssueSite.val()); | |
| 507 | - } | |
| 508 | 684 | }); |
| 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 { | |
| 685 | +globalThis.securityIssues_fix = function (feature) { | |
| 523 | 686 | if (jQuery('#' + feature + '_fix')) { |
| 524 | - jQuery('#' + feature + '_fix').hide(); | |
| 687 | + jQuery('#' + feature + '_fix').hide(); | |
| 525 | 688 | } |
| 526 | 689 | jQuery('#' + feature + '_extra').hide(); |
| 527 | 690 | jQuery('#' + feature + '_ok').hide(); |
| 528 | 691 | jQuery('#' + feature + '_nok').hide(); |
| 529 | 692 | jQuery('#' + feature + '_loading').show(); |
| 530 | - } | |
| 531 | 693 | |
| 532 | - var data = mainwp_secure_data({ | |
| 533 | - action: 'mainwp_security_issues_fix', | |
| 534 | - feature: feature, | |
| 535 | - id: jQuery('#securityIssueSite').val() | |
| 536 | - }); | |
| 694 | + let data = mainwp_secure_data({ | |
| 695 | + action: 'mainwp_security_issues_fix', | |
| 696 | + feature: feature, | |
| 697 | + id: jQuery('#securityIssueSite').val() | |
| 698 | + }); | |
| 537 | 699 | |
| 538 | - jQuery.post(ajaxurl, data, function (response) { | |
| 539 | - securityIssues_handle(response); | |
| 540 | - }, 'json'); | |
| 700 | + jQuery.post(ajaxurl, data, function (response) { | |
| 701 | + securityIssues_handle(response); | |
| 702 | + }, 'json'); | |
| 541 | 703 | }; |
| 542 | 704 | |
| 543 | -// Securtiy issues Widget | |
| 705 | +let securityIssues_unfix = function (feature) { | |
| 706 | + if (jQuery('#' + feature + '_unfix')) { | |
| 707 | + jQuery('#' + feature + '_unfix').hide(); | |
| 708 | + } | |
| 709 | + jQuery('#' + feature + '_extra').hide(); | |
| 710 | + jQuery('#' + feature + '_ok').hide(); | |
| 711 | + jQuery('#' + feature + '_nok').hide(); | |
| 712 | + jQuery('#' + feature + '_loading').show(); | |
| 544 | 713 | |
| 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 | -}); | |
| 714 | + let data = mainwp_secure_data({ | |
| 715 | + action: 'mainwp_security_issues_unfix', | |
| 716 | + feature: feature, | |
| 717 | + id: jQuery('#securityIssueSite').val() | |
| 718 | + }); | |
| 719 | + jQuery.post(ajaxurl, data, function (response) { | |
| 720 | + securityIssues_handle(response); | |
| 721 | + }, 'json'); | |
| 722 | +}; | |
| 723 | +let securityIssues_request = function (websiteId) { | |
| 724 | + let data = mainwp_secure_data({ | |
| 725 | + action: 'mainwp_security_issues_request', | |
| 726 | + id: websiteId | |
| 727 | + }); | |
| 728 | + jQuery.post(ajaxurl, data, function (response) { | |
| 729 | + securityIssues_handle(response); | |
| 730 | + }, 'json'); | |
| 731 | +}; | |
| 732 | +// eslint-disable-next-line complexity | |
| 733 | +let securityIssues_handle = function (response) { // NOSONAR - complex. | |
| 734 | + let result = ''; | |
| 735 | + if (response.error) { | |
| 736 | + result = getErrorMessage(response.error); | |
| 737 | + } else { | |
| 738 | + try { | |
| 739 | + let res = response.result; | |
| 740 | + for (let issue in res) { | |
| 741 | + if (jQuery('#' + issue + '_loading')) { | |
| 742 | + jQuery('#' + issue + '_loading').hide(); | |
| 743 | + if (res[issue] == 'Y' || res[issue] == 'Y_UNABLE') { | |
| 744 | + jQuery('#' + issue + '_extra').hide(); | |
| 745 | + jQuery('#' + issue + '_nok').hide(); | |
| 746 | + if (jQuery('#' + issue + '_fix')) { | |
| 747 | + jQuery('#' + issue + '_fix').hide(); | |
| 748 | + } | |
| 550 | 749 | |
| 551 | -// Fix all sites all security issues | |
| 552 | -jQuery(document).on('click', '.fix-all-security-issues', function () { | |
| 750 | + if (jQuery('#' + issue + '_unfix')) { | |
| 751 | + jQuery('#' + issue + '_unfix').show(); | |
| 752 | + if (res[issue] == 'Y_UNABLE') { // Y_UNABLE will disable unfix. | |
| 753 | + jQuery('#' + issue + '_unfix').hide(); | |
| 754 | + } | |
| 755 | + } | |
| 553 | 756 | |
| 554 | - jQuery('#mainwp-secuirty-issues-loader').show(); | |
| 757 | + jQuery('#' + issue + '_ok').show(); | |
| 758 | + jQuery('#' + issue + '-status-ok').show(); | |
| 759 | + jQuery('#' + issue + '-status-nok').hide(); | |
| 760 | + } else if (res[issue] == 'N' || res[issue] == 'N_UNABLE') { | |
| 761 | + jQuery('#' + issue + '_extra').hide(); | |
| 762 | + jQuery('#' + issue + '_ok').hide(); | |
| 763 | + jQuery('#' + issue + '_nok').show(); | |
| 555 | 764 | |
| 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 | -}); | |
| 765 | + if (jQuery('#' + issue + '_fix')) { | |
| 766 | + jQuery('#' + issue + '_fix').show(); | |
| 767 | + if (res[issue] == 'N_UNABLE') { // N_UNABLE will disable fix. | |
| 768 | + jQuery('#' + issue + '_fix').hide().after('<a href="javascript:void(0);" class="ui mini fluid button" disabled="disabled">fix</a>'); | |
| 769 | + } | |
| 770 | + } | |
| 562 | 771 | |
| 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 | - } | |
| 772 | + if (jQuery('#' + issue + '_unfix')) { | |
| 773 | + jQuery('#' + issue + '_unfix').hide(); | |
| 774 | + } | |
| 775 | + if (res[issue] != 'N') { | |
| 776 | + jQuery('#' + issue + '_extra').html(res[issue]); | |
| 777 | + jQuery('#' + issue + '_extra').show(); | |
| 778 | + } | |
| 779 | + | |
| 780 | + if ('wp_uptodate' === issue) { | |
| 781 | + jQuery('#wp_upgrades').find('div[updated="-1"]').each(function () { | |
| 782 | + jQuery(this).attr('updated', 0); | |
| 783 | + }); | |
| 784 | + } | |
| 785 | + jQuery('#' + issue + '-status-ok').hide(); | |
| 786 | + jQuery('#' + issue + '-status-nok').show(); | |
| 787 | + } | |
| 788 | + } | |
| 789 | + } | |
| 790 | + } catch { | |
| 791 | + result = '<i class="exclamation circle icon"></i> ' + MainWP.I18n.t('Undefined error!'); | |
| 792 | + } | |
| 793 | + } | |
| 794 | + if (result != '') { | |
| 795 | + //show error! | |
| 796 | + } | |
| 797 | +}; | |
| 798 | + | |
| 799 | +globalThis.updatesoverview_bulk_check_abandoned = function (which) { | |
| 800 | + let confirmMsg; | |
| 801 | + if ('plugin' == which) { | |
| 802 | + confirmMsg = MainWP.I18n.t("You are about to check abandoned plugins on the sites?"); | |
| 803 | + } else { | |
| 804 | + confirmMsg = MainWP.I18n.t("You are about to check abandoned themes on the sites?"); | |
| 805 | + } | |
| 806 | + mainwp_confirm(confirmMsg, function () { mainwp_managesites_bulk_check_abandoned('all', which); }); | |
| 567 | 807 | } |
| 568 | 808 | |
| 569 | -mainwp_fix_all_security_issues_specific = function (siteToFix) { | |
| 809 | +globalThis.mainwp_managesites_bulk_check_abandoned = function (siteIds, which) { | |
| 810 | + let allWebsiteIds = jQuery('.dashboard_wp_id[error-status=0]').map(function (indx, el) { | |
| 811 | + return jQuery(el).val(); | |
| 812 | + }); | |
| 570 | 813 | |
| 571 | - bulkInstallCurrentThreads++; | |
| 814 | + if ('all' == siteIds) { | |
| 815 | + siteIds = allWebsiteIds; | |
| 816 | + } | |
| 572 | 817 | |
| 573 | - siteToFix.attr('status', 'progress'); | |
| 818 | + let selectedIds = [], excludeIds = []; | |
| 819 | + if (Array.isArray(siteIds)) { | |
| 820 | + jQuery.grep(allWebsiteIds, function (el) { | |
| 821 | + if (jQuery.inArray(el, siteIds) === -1) { | |
| 822 | + excludeIds.push(el); | |
| 823 | + } else { | |
| 824 | + selectedIds.push(el); | |
| 825 | + } | |
| 826 | + }); | |
| 827 | + for (let id of excludeIds) { | |
| 828 | + dashboard_update_site_hide(id); | |
| 829 | + } | |
| 830 | + allWebsiteIds = selectedIds; | |
| 831 | + } | |
| 574 | 832 | |
| 575 | - var data = mainwp_secure_data({ | |
| 576 | - action: 'mainwp_security_issues_fix', | |
| 577 | - feature: 'all', | |
| 578 | - id: siteToFix.attr('siteid') | |
| 579 | - }); | |
| 833 | + let nrOfWebsites = allWebsiteIds.length; | |
| 580 | 834 | |
| 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(); | |
| 835 | + if (nrOfWebsites == 0) { | |
| 836 | + managesites_reset_bulk_actions_params(); | |
| 837 | + return; | |
| 594 | 838 | } |
| 595 | - }(), 'json'); | |
| 596 | -} | |
| 597 | 839 | |
| 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 | -}); | |
| 840 | + let siteNames = {}; | |
| 603 | 841 | |
| 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 | - }); | |
| 842 | + for (let id of allWebsiteIds) { | |
| 843 | + dashboard_update_site_status(id, '<i class="clock outline icon"></i>'); | |
| 844 | + siteNames[id] = jQuery('.sync-site-status[siteid="' + id + '"]').attr('niceurl'); | |
| 845 | + } | |
| 846 | + let initData = { | |
| 847 | + progressMax: nrOfWebsites, | |
| 848 | + title: 'Check abandoned ' + ('plugin' == which ? 'plugins' : 'themes'), | |
| 849 | + statusText: MainWP.I18n.t('started'), | |
| 850 | + callback: function () { | |
| 851 | + mainwpVars.bulkManageSitesTaskRunning = false; | |
| 852 | + mainwp_forceReload(); | |
| 853 | + } | |
| 854 | + }; | |
| 855 | + mainwpPopup('#mainwp-sync-sites-modal').init(initData); | |
| 610 | 856 | |
| 611 | - var el = jQuery('#mainwp-security-issues-widget-list .item[siteid="' + siteId + '"] .fix-all-site-security-issues'); | |
| 857 | + mainwp_managesites_check_abandoned_all_int(allWebsiteIds, which); | |
| 858 | +}; | |
| 612 | 859 | |
| 613 | - el.hide(); | |
| 860 | +let mainwp_managesites_check_abandoned_all_int = function (websiteIds, which) { | |
| 861 | + mainwpVars.websitesToUpgrade = websiteIds; | |
| 862 | + mainwpVars.currentWebsite = 0; | |
| 863 | + mainwpVars.websitesDone = 0; | |
| 864 | + mainwpVars.websitesTotal = mainwpVars.websitesToUpgrade.length; | |
| 865 | + mainwpVars.websitesLeft = mainwpVars.websitesToUpgrade.length; | |
| 614 | 866 | |
| 615 | - jQuery('.fix-all-site-security-issues').addClass('disabled'); | |
| 616 | - jQuery('.unfix-all-site-security-issues').addClass('disabled'); | |
| 867 | + mainwpVars.bulkTaskRunning = true; | |
| 868 | + mainwp_managesites_check_abandoned_all_loop_next(which); | |
| 869 | +}; | |
| 617 | 870 | |
| 618 | - jQuery.post(ajaxurl, data, function (pRefresh) { | |
| 619 | - return function () { | |
| 620 | - el.show(); | |
| 621 | - if (pRefresh) { | |
| 622 | - window.location.href = location.href; | |
| 623 | - } | |
| 871 | +let mainwp_managesites_check_abandoned_all_loop_next = function (which) { | |
| 872 | + while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxThreads) && (mainwpVars.websitesLeft > 0)) { | |
| 873 | + mainwp_managesites_check_abandoned_all_upgrade_next(which); | |
| 624 | 874 | } |
| 625 | - }(refresh, el), 'json'); | |
| 626 | 875 | }; |
| 876 | +let mainwp_managesites_check_abandoned_all_upgrade_next = function (which) { | |
| 877 | + mainwpVars.currentThreads++; | |
| 878 | + mainwpVars.websitesLeft--; | |
| 627 | 879 | |
| 628 | -jQuery(document).on('click', '.unfix-all-site-security-issues', function () { | |
| 880 | + let websiteId = mainwpVars.websitesToUpgrade[mainwpVars.currentWebsite++]; | |
| 881 | + dashboard_update_site_status(websiteId, '<i class="sync alternate loading icon"></i>'); | |
| 629 | 882 | |
| 630 | - jQuery('#mainwp-secuirty-issues-loader').show(); | |
| 883 | + mainwp_managesites_check_abandoned_int(websiteId, which); | |
| 884 | +}; | |
| 631 | 885 | |
| 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 | - }); | |
| 886 | +let mainwp_managesites_check_abandoned_int = function (siteid, which) { | |
| 637 | 887 | |
| 638 | - jQuery(this).hide(); | |
| 639 | - jQuery('.fix-all-site-security-issues').addClass('disabled'); | |
| 640 | - jQuery('.unfix-all-site-security-issues').addClass('disabled'); | |
| 888 | + let data = mainwp_secure_data({ | |
| 889 | + action: 'mainwp_check_abandoned', | |
| 890 | + siteId: siteid, | |
| 891 | + which: which | |
| 892 | + }); | |
| 641 | 893 | |
| 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(); | |
| 894 | + jQuery.ajax({ | |
| 895 | + type: 'POST', | |
| 896 | + url: ajaxurl, | |
| 897 | + data: data, | |
| 898 | + success: function (pSiteid) { | |
| 899 | + return function (response) { | |
| 900 | + mainwpVars.currentThreads--; | |
| 901 | + mainwpVars.websitesDone++; | |
| 902 | + mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); | |
| 903 | + if (response.error != undefined) { | |
| 904 | + dashboard_update_site_status(pSiteid, '<i class="red times icon"></i>'); | |
| 905 | + } else if (response.result && response.result == 'success') { | |
| 906 | + dashboard_update_site_status(pSiteid, '<i class="green check icon"></i>', true); | |
| 907 | + } else { | |
| 908 | + dashboard_update_site_status(pSiteid, '<i class="red times icon"></i>'); | |
| 909 | + } | |
| 910 | + mainwp_managesites_check_abandoned_all_loop_next(which); | |
| 911 | + } | |
| 912 | + }(siteid), | |
| 913 | + dataType: 'json' | |
| 914 | + }); | |
| 915 | +}; | |
| 654 | 916 | |
| 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(); | |
| 917 | +/** | |
| 918 | + * MainWP UI. | |
| 919 | + */ | |
| 920 | +jQuery(function () { | |
| 921 | + jQuery('#reset-overview-settings').on('click', function () { | |
| 922 | + mainwp_confirm(MainWP.I18n.t('Are you sure?'), function () { | |
| 923 | + let which_set = jQuery('input[name=reset_overview_which_settings]').val(); | |
| 924 | + if ('sidebar_settings' == which_set) { | |
| 925 | + jQuery('#mainwp_sidebarPosition').dropdown('set selected', 1); | |
| 926 | + } else if ('overview_settings' == which_set) { | |
| 927 | + jQuery('input[name=hide_update_everything]').prop('checked', false); | |
| 928 | + jQuery('.mainwp_hide_wpmenu_checkboxes input[name="mainwp_show_widgets[]"]').prop('checked', true); | |
| 688 | 929 | } |
| 689 | - if (jQuery('#' + issue + '_unfix')) { | |
| 690 | - jQuery('#' + issue + '_unfix').show(); | |
| 930 | + 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) { | |
| 931 | + jQuery('input[name="mainwp_show_columns[]"]').prop('checked', true); | |
| 691 | 932 | } |
| 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 | - } | |
| 933 | + jQuery('input[name=reset_overview_settings]').attr('value', 1); | |
| 934 | + jQuery('#submit-overview-settings').click(); | |
| 935 | + }, false, false, true); | |
| 936 | + return false; | |
| 937 | + }); | |
| 938 | +}); | |
| 708 | 939 | |
| 709 | - if (res[issue] != 'N') { | |
| 710 | - jQuery('#' + issue + '_extra').html(res[issue]); | |
| 711 | - jQuery('#' + issue + '_extra').show(); | |
| 940 | +/** | |
| 941 | + * Sync Sites | |
| 942 | + */ | |
| 943 | + | |
| 944 | +jQuery(function () { | |
| 945 | + jQuery('#mainwp-sync-sites').on('click', function () { | |
| 946 | + mainwp_sync_sites_data(); | |
| 947 | + }); | |
| 948 | + | |
| 949 | + // to compatible with extensions | |
| 950 | + jQuery('#dashboard_refresh').on('click', function () { | |
| 951 | + mainwp_sync_sites_data(); | |
| 952 | + }); | |
| 953 | + jQuery('.mainwp-sync-this-site').on('click', function () { | |
| 954 | + let syncSiteIds = []; | |
| 955 | + syncSiteIds.push(jQuery(this).attr('site-id')); | |
| 956 | + mainwp_sync_sites_data(syncSiteIds); | |
| 957 | + }); | |
| 958 | +}); | |
| 959 | + | |
| 960 | +globalThis.mainwp_sync_sites_data = function (syncSiteIds, pAction) { | |
| 961 | + let allWebsiteIds = []; | |
| 962 | + jQuery('.dashboard_wp_id[error-status=0]').map(function (indx, el) { | |
| 963 | + allWebsiteIds.push(jQuery(el).val()); | |
| 964 | + }); | |
| 965 | + let globalSync = true; | |
| 966 | + let selectedIds = [], excludeIds = []; | |
| 967 | + if (Array.isArray(syncSiteIds)) { | |
| 968 | + jQuery.grep(allWebsiteIds, function (el) { | |
| 969 | + if (jQuery.inArray(el, syncSiteIds) === -1) { | |
| 970 | + excludeIds.push(el); | |
| 971 | + } else { | |
| 972 | + selectedIds.push(el); | |
| 712 | 973 | } |
| 713 | - } | |
| 974 | + }); | |
| 975 | + for (let id of excludeIds) { | |
| 976 | + dashboard_update_site_hide(id); | |
| 714 | 977 | } |
| 715 | - } | |
| 978 | + allWebsiteIds = selectedIds; | |
| 979 | + globalSync = false; | |
| 980 | + } | |
| 716 | 981 | |
| 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 | - } | |
| 982 | + for (let id of allWebsiteIds) { | |
| 983 | + dashboard_update_site_status(id, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Pending') + '"><i class="clock outline icon"></i></span>'); | |
| 984 | + } | |
| 985 | + | |
| 986 | + let nrOfWebsites = allWebsiteIds.length; | |
| 987 | + | |
| 988 | + mainwpPopup('#mainwp-sync-sites-modal').init({ | |
| 989 | + title: (pAction == 'checknow' ? MainWP.I18n.t('Check Now') : MainWP.I18n.t('Data Synchronization')), | |
| 990 | + progressMax: nrOfWebsites, | |
| 991 | + statusText: (pAction == 'checknow' ? 'checked' : 'synced'), | |
| 992 | + callback: function () { | |
| 993 | + mainwpVars.bulkTaskRunning = false; | |
| 994 | + history.pushState("", document.title, globalThis.location.pathname + globalThis.location.search); // to fix issue for url with hash | |
| 995 | + mainwp_forceReload(); | |
| 728 | 996 | } |
| 729 | - } | |
| 997 | + }); | |
| 730 | 998 | |
| 731 | - } catch (err) { | |
| 732 | - result = '<i class="exclamation circle icon"></i> ' + __('Undefined error!'); | |
| 999 | + if (jQuery('#mainwp-sync-sites-modal').attr('current-wpid') > 0) { | |
| 1000 | + globalSync = false; | |
| 733 | 1001 | } |
| 734 | - } | |
| 735 | - if (result != '') { | |
| 736 | - //show error! | |
| 737 | - } | |
| 738 | -}; | |
| 739 | 1002 | |
| 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 | -} | |
| 1003 | + dashboard_update(allWebsiteIds, globalSync, pAction); | |
| 748 | 1004 | |
| 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 | - }); | |
| 1005 | + if (pAction != 'checknow') { | |
| 1006 | + if (nrOfWebsites > 0) { | |
| 1007 | + let data = { | |
| 1008 | + action: 'mainwp_status_saving', | |
| 1009 | + status: 'last_sync_sites', | |
| 1010 | + isGlobalSync: globalSync ? 1 : 0 | |
| 1011 | + }; | |
| 1012 | + jQuery.post(ajaxurl, mainwp_secure_data(data), function () { | |
| 753 | 1013 | |
| 754 | - if ('all' == siteIds) { | |
| 755 | - siteIds = allWebsiteIds; | |
| 756 | - } | |
| 1014 | + }); | |
| 1015 | + } | |
| 1016 | + } | |
| 1017 | +}; | |
| 757 | 1018 | |
| 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 | - } | |
| 1019 | +mainwpVars.websitesToUpdate = []; | |
| 1020 | +mainwpVars.websitesTotal = 0; | |
| 1021 | +mainwpVars.websitesLeft = 0; | |
| 1022 | +mainwpVars.websitesDone = 0; | |
| 1023 | +mainwpVars.currentWebsite = 0; | |
| 1024 | +mainwpVars.bulkTaskRunning = false; | |
| 1025 | +mainwpVars.currentThreads = 0; | |
| 1026 | +mainwpVars.maxThreads = mainwpParams['maximumSyncRequests'] == undefined ? 8 : mainwpParams['maximumSyncRequests']; | |
| 1027 | +mainwpVars.maxUpdateThreads = mainwpParams['maximumInstallUpdateRequests'] == undefined ? 3 : mainwpParams['maximumInstallUpdateRequests']; | |
| 773 | 1028 | |
| 774 | - var nrOfWebsites = allWebsiteIds.length; | |
| 1029 | +let globalSync = true; | |
| 775 | 1030 | |
| 776 | - if (nrOfWebsites == 0) | |
| 777 | - return false; | |
| 1031 | +globalThis.dashboard_update = function (websiteIds, isGlobalSync, pAction) { | |
| 1032 | + mainwpVars.websitesToUpdate = websiteIds; | |
| 1033 | + mainwpVars.currentWebsite = 0; | |
| 1034 | + mainwpVars.websitesDone = 0; | |
| 1035 | + mainwpVars.successCount = 0; | |
| 1036 | + mainwpVars.websitesTotal = mainwpVars.websitesLeft = mainwpVars.websitesToUpdate.length; | |
| 1037 | + globalSync = isGlobalSync; | |
| 778 | 1038 | |
| 779 | - var siteNames = {}; | |
| 1039 | + mainwpVars.bulkTaskRunning = true; | |
| 780 | 1040 | |
| 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; | |
| 1041 | + if (mainwpVars.websitesTotal == 0) { | |
| 1042 | + dashboard_update_done(pAction); | |
| 1043 | + } else { | |
| 1044 | + dashboard_loop_next(pAction); | |
| 792 | 1045 | } |
| 793 | - }; | |
| 794 | - mainwpPopup('#mainwp-sync-sites-modal').init(initData); | |
| 795 | - | |
| 796 | - mainwp_managesites_check_abandoned_all_int(allWebsiteIds, which); | |
| 797 | 1046 | }; |
| 798 | 1047 | |
| 799 | -mainwp_managesites_check_abandoned_all_int = function (websiteIds, which) { | |
| 800 | - websitesToUpgrade = websiteIds; | |
| 801 | - currentWebsite = 0; | |
| 802 | - websitesDone = 0; | |
| 803 | - websitesTotal = websitesLeft = websitesToUpgrade.length; | |
| 1048 | +(function () { | |
| 1049 | + // Create global namespace | |
| 1050 | + const sync = globalThis.dashboardSync = globalThis.dashboardSync || { | |
| 1051 | + container: null, | |
| 1052 | + statusMap: new Map(), | |
| 1053 | + rowMap: new Map(), | |
| 804 | 1054 | |
| 805 | - bulkTaskRunning = true; | |
| 806 | - mainwp_managesites_check_abandoned_all_loop_next(which); | |
| 807 | -}; | |
| 1055 | + data: new Map(), | |
| 1056 | + queue: [], | |
| 808 | 1057 | |
| 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--; | |
| 1058 | + scheduled: false, | |
| 1059 | + initialized: false, | |
| 817 | 1060 | |
| 818 | - var websiteId = websitesToUpgrade[currentWebsite++]; | |
| 819 | - dashboard_update_site_status(websiteId, '<i class="sync alternate loading icon"></i>'); | |
| 1061 | + BATCH_SIZE: 50 | |
| 1062 | + }; | |
| 820 | 1063 | |
| 821 | - mainwp_managesites_check_abandoned_int(websiteId, which); | |
| 822 | -}; | |
| 1064 | + // ----------------------------- | |
| 1065 | + // INIT CACHE | |
| 1066 | + // ----------------------------- | |
| 1067 | + function init() { | |
| 1068 | + if (sync.initialized) return; | |
| 823 | 1069 | |
| 824 | -mainwp_managesites_check_abandoned_int = function (siteid, which) { | |
| 1070 | + sync.container = document.getElementById('sync-sites-status'); | |
| 1071 | + if (!sync.container) return; | |
| 825 | 1072 | |
| 826 | - var data = mainwp_secure_data({ | |
| 827 | - action: 'mainwp_check_abandoned', | |
| 828 | - siteId: siteid, | |
| 829 | - which: which | |
| 830 | - }); | |
| 1073 | + const nodes = sync.container.querySelectorAll('.sync-site-status'); | |
| 831 | 1074 | |
| 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>'); | |
| 1075 | + for (const el of nodes) { | |
| 1076 | + const siteId = el.getAttribute('siteid'); | |
| 1077 | + sync.statusMap.set(siteId, el); | |
| 1078 | + sync.rowMap.set(siteId, el.closest('.item')); | |
| 847 | 1079 | } |
| 848 | - mainwp_managesites_check_abandoned_all_loop_next(which); | |
| 849 | - } | |
| 850 | - }(siteid), | |
| 851 | - dataType: 'json' | |
| 852 | - }); | |
| 853 | - return false; | |
| 854 | -}; | |
| 855 | 1080 | |
| 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 | -}); | |
| 1081 | + sync.initialized = true; | |
| 1082 | + } | |
| 878 | 1083 | |
| 879 | -/** | |
| 880 | - * Sync Sites | |
| 881 | - */ | |
| 1084 | + // Ensure DOM ready | |
| 1085 | + if (document.readyState === 'loading') { | |
| 1086 | + document.addEventListener('DOMContentLoaded', init); | |
| 1087 | + } else { | |
| 1088 | + init(); | |
| 1089 | + } | |
| 882 | 1090 | |
| 883 | -jQuery(document).ready(function () { | |
| 884 | - jQuery('#mainwp-sync-sites').on('click', function () { | |
| 885 | - mainwp_sync_sites_data(); | |
| 886 | - }); | |
| 1091 | + // ----------------------------- | |
| 1092 | + // PUBLIC API | |
| 1093 | + // ----------------------------- | |
| 1094 | + globalThis.dashboard_update_site_status = function (siteId, newStatus, isSuccess) { | |
| 1095 | + if (!sync.initialized) return; | |
| 887 | 1096 | |
| 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 | -}); | |
| 1097 | + sync.data.set(siteId, { | |
| 1098 | + status: newStatus, | |
| 1099 | + success: isSuccess | |
| 1100 | + }); | |
| 898 | 1101 | |
| 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 | - } | |
| 1102 | + sync.queue.push(siteId); | |
| 919 | 1103 | |
| 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 | - } | |
| 1104 | + // ✅ increment success count ONCE | |
| 1105 | + if (isSuccess) { | |
| 1106 | + mainwpVars.successCount = (mainwpVars.successCount || 0) + 1; | |
| 1107 | + } | |
| 923 | 1108 | |
| 924 | - var nrOfWebsites = allWebsiteIds.length; | |
| 1109 | + if (!sync.scheduled) { | |
| 1110 | + sync.scheduled = true; | |
| 1111 | + requestAnimationFrame(processQueue); | |
| 1112 | + } | |
| 1113 | + }; | |
| 925 | 1114 | |
| 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 | - }); | |
| 1115 | + globalThis.dashboard_update_site_hide = function (siteId) { | |
| 1116 | + const sync = globalThis.dashboardSync; | |
| 1117 | + if (!sync?.initialized) return; | |
| 936 | 1118 | |
| 937 | - if (jQuery('#mainwp-sync-sites-modal').attr('current-wpid') > 0) { | |
| 938 | - globalSync = false; | |
| 939 | - } | |
| 1119 | + const rowEl = sync.rowMap.get(siteId); | |
| 1120 | + if (!rowEl) return; | |
| 940 | 1121 | |
| 941 | - dashboard_update(allWebsiteIds, globalSync, pAction); | |
| 1122 | + rowEl.style.display = 'none'; | |
| 1123 | + }; | |
| 942 | 1124 | |
| 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 () { | |
| 1125 | + // ----------------------------- | |
| 1126 | + // PROCESS QUEUE (BATCHED) | |
| 1127 | + // ----------------------------- | |
| 1128 | + function processQueue() { | |
| 1129 | + sync.scheduled = false; | |
| 951 | 1130 | |
| 952 | - }); | |
| 953 | - } | |
| 954 | - } | |
| 955 | -}; | |
| 1131 | + let count = 0; | |
| 956 | 1132 | |
| 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; | |
| 1133 | + while (sync.queue.length && count < sync.BATCH_SIZE) { | |
| 1134 | + const siteId = sync.queue.shift(); | |
| 1135 | + const data = sync.data.get(siteId); | |
| 966 | 1136 | |
| 967 | -dashboard_update = function (websiteIds, isGlobalSync, pAction) { | |
| 968 | - websitesToUpdate = websiteIds; | |
| 969 | - currentWebsite = 0; | |
| 970 | - websitesDone = 0; | |
| 971 | - websitesTotal = websitesLeft = websitesToUpdate.length; | |
| 972 | - globalSync = isGlobalSync; | |
| 1137 | + const statusEl = sync.statusMap.get(siteId); | |
| 1138 | + const rowEl = sync.rowMap.get(siteId); | |
| 973 | 1139 | |
| 974 | - bulkTaskRunning = true; | |
| 1140 | + if (!statusEl || !rowEl) continue; | |
| 975 | 1141 | |
| 976 | - if (websitesTotal == 0) { | |
| 977 | - dashboard_update_done(pAction); | |
| 978 | - } else { | |
| 979 | - dashboard_loop_next(pAction); | |
| 980 | - } | |
| 981 | -}; | |
| 1142 | + // Avoid DOM read → use dataset cache | |
| 1143 | + if (statusEl.dataset.last !== data.status) { | |
| 1144 | + statusEl.innerHTML = data.status; | |
| 1145 | + statusEl.dataset.last = data.status; | |
| 1146 | + } | |
| 982 | 1147 | |
| 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 | - } | |
| 1148 | + // No DOM move → just class toggle | |
| 1149 | + if (data.success) { | |
| 1150 | + rowEl.classList.add('is-success'); | |
| 1151 | + } | |
| 1152 | + | |
| 1153 | + count++; | |
| 1154 | + } | |
| 1155 | + | |
| 1156 | + // Continue next frame if still pending | |
| 1157 | + if (sync.queue.length) { | |
| 1158 | + requestAnimationFrame(processQueue); | |
| 1159 | + } | |
| 1160 | + } | |
| 1161 | +})(); | |
| 1162 | + | |
| 1163 | +globalThis.dashboard_update_site_status_legacy = function (siteId, newStatus, isSuccess) { | |
| 1164 | + jQuery('.sync-site-status[siteid="' + siteId + '"]').html(newStatus); | |
| 1165 | + // Move successfully synced site to the bottom of the sync list | |
| 1166 | + if (isSuccess !== undefined && isSuccess) { | |
| 1167 | + let row = jQuery('.sync-site-status[siteid="' + siteId + '"]').closest('.item'); | |
| 1168 | + jQuery(row).insertAfter(jQuery("#sync-sites-status .item").not('.disconnected-site').last()); | |
| 1169 | + } | |
| 990 | 1170 | }; |
| 991 | 1171 | |
| 992 | -dashboard_update_site_hide = function (siteId) { | |
| 993 | - jQuery('.sync-site-status[siteid="' + siteId + '"]').closest('.item').hide(); | |
| 1172 | +globalThis.dashboard_update_site_hide_legacy = function (siteId) { | |
| 1173 | + jQuery('.sync-site-status[siteid="' + siteId + '"]').closest('.item').hide(); | |
| 994 | 1174 | }; |
| 995 | 1175 | |
| 996 | -dashboard_loop_next = function (pAction) { | |
| 997 | - while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { | |
| 998 | - dashboard_update_next(pAction); | |
| 999 | - } | |
| 1176 | +let dashboard_loop_next = function (pAction) { | |
| 1177 | + while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxThreads) && (mainwpVars.websitesLeft > 0)) { | |
| 1178 | + dashboard_update_next(pAction); | |
| 1179 | + } | |
| 1000 | 1180 | }; |
| 1001 | 1181 | |
| 1002 | -dashboard_update_done = function (pAction) { | |
| 1003 | - currentThreads--; | |
| 1004 | - if (!bulkTaskRunning) | |
| 1005 | - return; | |
| 1006 | - websitesDone++; | |
| 1007 | - if (websitesDone > websitesTotal) | |
| 1008 | - websitesDone = websitesTotal; | |
| 1182 | +let dashboard_update_done = function (pAction) { | |
| 1183 | + mainwpVars.currentThreads--; | |
| 1009 | 1184 | |
| 1010 | - mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(websitesDone); | |
| 1185 | + if (!mainwpVars.bulkTaskRunning) return; | |
| 1011 | 1186 | |
| 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; | |
| 1187 | + mainwpVars.websitesDone++; | |
| 1188 | + if (mainwpVars.websitesDone > mainwpVars.websitesTotal) { | |
| 1189 | + mainwpVars.websitesDone = mainwpVars.websitesTotal; | |
| 1021 | 1190 | } |
| 1022 | - return; | |
| 1023 | - } | |
| 1024 | 1191 | |
| 1025 | - dashboard_loop_next(pAction); | |
| 1026 | -}; | |
| 1192 | + // ✅ Cache popup instance (avoid re-query) | |
| 1193 | + const popup = mainwpVars._popup || ( | |
| 1194 | + mainwpVars._popup = mainwpPopup('#mainwp-sync-sites-modal') | |
| 1195 | + ); | |
| 1027 | 1196 | |
| 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 | - }); | |
| 1197 | + popup.setProgressSite(mainwpVars.websitesDone); | |
| 1038 | 1198 | |
| 1199 | + // ✅ Avoid DOM query for success count → track in JS | |
| 1200 | + if (mainwpVars.websitesDone === mainwpVars.websitesTotal) { | |
| 1039 | 1201 | |
| 1202 | + const successSites = mainwpVars.successCount || 0; | |
| 1040 | 1203 | |
| 1041 | - dashboard_update_next_int(websiteId, data, 0, pAction); | |
| 1204 | + mainwpVars.bulkTaskRunning = false; | |
| 1205 | + | |
| 1206 | + if (mainwpVars.websitesDone === successSites) { | |
| 1207 | + setTimeout(() => popup.close(true), 3000); | |
| 1208 | + } | |
| 1209 | + | |
| 1210 | + return; | |
| 1211 | + } | |
| 1212 | + | |
| 1213 | + dashboard_loop_next(pAction); | |
| 1042 | 1214 | }; |
| 1043 | 1215 | |
| 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>'); | |
| 1216 | +let dashboard_update_done_legacy = function (pAction) { | |
| 1217 | + mainwpVars.currentThreads--; | |
| 1218 | + if (!mainwpVars.bulkTaskRunning) | |
| 1219 | + return; | |
| 1220 | + mainwpVars.websitesDone++; | |
| 1221 | + if (mainwpVars.websitesDone > mainwpVars.websitesTotal) | |
| 1222 | + mainwpVars.websitesDone = mainwpVars.websitesTotal; | |
| 1223 | + | |
| 1224 | + mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); | |
| 1225 | + | |
| 1226 | + if (mainwpVars.websitesDone == mainwpVars.websitesTotal) { | |
| 1227 | + let successSites = jQuery('#mainwp-sync-sites-modal .check.green.icon').length; | |
| 1228 | + if (mainwpVars.websitesDone == successSites) { | |
| 1229 | + mainwpVars.bulkTaskRunning = false; | |
| 1230 | + setTimeout(function () { | |
| 1231 | + mainwpPopup('#mainwp-sync-sites-modal').close(true); | |
| 1232 | + }, 3000); | |
| 1054 | 1233 | } 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); | |
| 1234 | + mainwpVars.bulkTaskRunning = false; | |
| 1056 | 1235 | } |
| 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 | - }); | |
| 1236 | + return; | |
| 1237 | + } | |
| 1238 | + | |
| 1239 | + dashboard_loop_next(pAction); | |
| 1073 | 1240 | }; |
| 1074 | 1241 | |
| 1242 | +let dashboard_update_next = function (pAction) { | |
| 1243 | + mainwpVars.currentThreads++; | |
| 1244 | + mainwpVars.websitesLeft--; | |
| 1245 | + let websiteId = mainwpVars.websitesToUpdate[mainwpVars.currentWebsite++]; | |
| 1246 | + if ('checknow' == pAction) { | |
| 1247 | + dashboard_update_site_status(websiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Checking uptime status...') + '"><i class="sync alternate loading icon"></i></span>'); | |
| 1248 | + } else { | |
| 1249 | + dashboard_update_site_status(websiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Syncing data...') + '"><i class="sync alternate loading icon"></i></span>'); | |
| 1250 | + } | |
| 1075 | 1251 | |
| 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 | - } | |
| 1252 | + let data = mainwp_secure_data({ | |
| 1253 | + action: ('checknow' == pAction ? 'mainwp_checksites' : 'mainwp_syncsites'), | |
| 1254 | + wp_id: websiteId, | |
| 1255 | + isGlobalSync: globalSync, | |
| 1256 | + bulkSync: mainwpVars.websitesTotal > 1 ? 1 : 0 | |
| 1091 | 1257 | }); |
| 1092 | - for (var i = 0; i < excludeIds.length; i++) { | |
| 1093 | - dashboard_update_site_hide(excludeIds[i]); | |
| 1094 | - } | |
| 1095 | - allWebsiteIds = selectedIds; | |
| 1096 | - } | |
| 1097 | 1258 | |
| 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 | 1259 | |
| 1102 | - var nrOfWebsites = allWebsiteIds.length; | |
| 1103 | 1260 | |
| 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); | |
| 1261 | + dashboard_update_next_int(websiteId, data, 0, pAction); | |
| 1115 | 1262 | }; |
| 1116 | 1263 | |
| 1264 | +let dashboard_update_next_int = function (websiteId, data, errors, action) { | |
| 1265 | + jQuery.ajax({ | |
| 1266 | + type: 'POST', | |
| 1267 | + url: ajaxurl, | |
| 1268 | + data: data, | |
| 1269 | + success: function (pWebsiteId, pAction) { | |
| 1270 | + return function (response) { | |
| 1271 | + if (response.error) { | |
| 1272 | + let extErr = response.error; | |
| 1273 | + dashboard_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + extErr + '"><i class="exclamation red icon"></i></span>'); | |
| 1274 | + } else { | |
| 1275 | + dashboard_update_site_status(websiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Synchronization process completed successfully.') + '"><i class="check green icon"></i></span>', true); | |
| 1276 | + } | |
| 1277 | + dashboard_update_done(pAction); | |
| 1278 | + } | |
| 1279 | + }(websiteId, action), | |
| 1280 | + error: function (pWebsiteId, pData, pErrors, pAction) { | |
| 1281 | + return function () { | |
| 1282 | + if (pErrors > 5) { | |
| 1283 | + dashboard_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Process timed out. Please try again.') + '"><i class="exclamation yellow icon"></i></span>'); | |
| 1284 | + dashboard_update_done(pAction); | |
| 1285 | + } else { | |
| 1286 | + pErrors++; | |
| 1287 | + dashboard_update_next_int(pWebsiteId, pData, pErrors, pAction); | |
| 1288 | + } | |
| 1289 | + } | |
| 1290 | + }(websiteId, data, errors, action), | |
| 1291 | + dataType: 'json' | |
| 1292 | + }); | |
| 1293 | +}; | |
| 1117 | 1294 | |
| 1118 | -mainwp_delete_nonmainwp_data_start_next = function (websiteIds) { | |
| 1119 | - websitesToUpdate = websiteIds; | |
| 1120 | - currentWebsite = 0; | |
| 1121 | - websitesDone = 0; | |
| 1122 | - websitesTotal = websitesLeft = websitesToUpdate.length; | |
| 1123 | 1295 | |
| 1124 | - bulkTaskRunning = true; | |
| 1296 | +/** | |
| 1297 | + * Delete site changes actions. | |
| 1298 | + */ | |
| 1125 | 1299 | |
| 1126 | - if (websitesTotal == 0) { | |
| 1127 | - mainwp_delete_nonmainwp_data_done(); | |
| 1128 | - } else { | |
| 1129 | - mainwp_delete_nonmainwp_data_loop_next(); | |
| 1130 | - } | |
| 1131 | -}; | |
| 1300 | +let mainwp_delete_nonmainwp_data_start = function () { | |
| 1301 | + mainwp_delete_nonmainwp_data_start_next(); | |
| 1302 | +} | |
| 1132 | 1303 | |
| 1304 | +let mainwp_delete_nonmainwp_data_start_next = function () { | |
| 1305 | + while ((checkedBox = jQuery('#mainwp-module-log-records-body-table .check-column INPUT:checkbox:checked:first')) && (checkedBox.length > 0) && (bulkManageClientsCurrentThreads < bulkManageClientsMaxThreads)) { // NOSONAR -- modified out side the function. | |
| 1306 | + mainwp_delete_nonmainwp_data_next(); | |
| 1307 | + } | |
| 1308 | +} | |
| 1133 | 1309 | |
| 1134 | -mainwp_delete_nonmainwp_data_loop_next = function () { | |
| 1135 | - while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { | |
| 1136 | - mainwp_delete_nonmainwp_data_next(); | |
| 1137 | - } | |
| 1310 | +let mainwp_delete_nonmainwp_data_next = function () { | |
| 1311 | + mainwpVars.currentThreads++; | |
| 1312 | + mainwpVars.websitesLeft--; | |
| 1313 | + let websiteId = mainwpVars.websitesToUpdate[mainwpVars.currentWebsite++]; | |
| 1314 | + dashboard_update_site_status(websiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Deleting...') + '"><i class="sync alternate loading icon"></i></span>'); | |
| 1315 | + let data = mainwp_secure_data({ | |
| 1316 | + action: 'mainwp_delete_non_mainwp_actions', | |
| 1317 | + wp_id: websiteId, | |
| 1318 | + }); | |
| 1319 | + mainwp_delete_nonmainwp_data_next_int(websiteId, data, 0); | |
| 1138 | 1320 | }; |
| 1139 | 1321 | |
| 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); | |
| 1322 | +let mainwp_delete_nonmainwp_data_next_int = function (websiteId, data, errors) { | |
| 1323 | + jQuery.ajax({ | |
| 1324 | + type: 'POST', | |
| 1325 | + url: ajaxurl, | |
| 1326 | + data: data, | |
| 1327 | + success: function (pWebsiteId) { | |
| 1328 | + return function (response) { | |
| 1329 | + if (response.error) { | |
| 1330 | + let extErr = response.error; | |
| 1331 | + dashboard_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + extErr + '"><i class="exclamation red icon"></i></span>'); | |
| 1332 | + } else { | |
| 1333 | + dashboard_update_site_status(websiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Process completed successfully.') + '"><i class="check green icon"></i></span>', true); | |
| 1334 | + } | |
| 1335 | + mainwp_delete_nonmainwp_data_done(); | |
| 1336 | + } | |
| 1337 | + }(websiteId), | |
| 1338 | + error: function (pWebsiteId, pData, pErrors) { | |
| 1339 | + return function () { | |
| 1340 | + if (pErrors > 5) { | |
| 1341 | + dashboard_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Process timed out. Please try again.') + '"><i class="exclamation yellow icon"></i></span>'); | |
| 1342 | + mainwp_delete_nonmainwp_data_done(); | |
| 1343 | + } else { | |
| 1344 | + pErrors++; | |
| 1345 | + mainwp_delete_nonmainwp_data_next_int(pWebsiteId, pData, pErrors); | |
| 1346 | + } | |
| 1347 | + } | |
| 1348 | + }(websiteId, data, errors), | |
| 1349 | + dataType: 'json' | |
| 1350 | + }); | |
| 1150 | 1351 | }; |
| 1151 | 1352 | |
| 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 | 1353 | |
| 1354 | +let mainwp_delete_nonmainwp_data_done = function () { | |
| 1355 | + mainwpVars.currentThreads--; | |
| 1356 | + if (!mainwpVars.bulkTaskRunning) | |
| 1357 | + return; | |
| 1358 | + mainwpVars.websitesDone++; | |
| 1359 | + if (mainwpVars.websitesDone > mainwpVars.websitesTotal) | |
| 1360 | + mainwpVars.websitesDone = mainwpVars.websitesTotal; | |
| 1183 | 1361 | |
| 1184 | -mainwp_delete_nonmainwp_data_done = function () { | |
| 1185 | - currentThreads--; | |
| 1186 | - if (!bulkTaskRunning) | |
| 1187 | - return; | |
| 1188 | - websitesDone++; | |
| 1189 | - if (websitesDone > websitesTotal) | |
| 1190 | - websitesDone = websitesTotal; | |
| 1362 | + mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); | |
| 1191 | 1363 | |
| 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; | |
| 1364 | + if (mainwpVars.websitesDone == mainwpVars.websitesTotal) { | |
| 1365 | + jQuery("#mainwp-non-mainwp-changes-table tbody").fadeOut("slow"); | |
| 1366 | + let successSites = jQuery('#mainwp-sync-sites-modal .check.green.icon').length; | |
| 1367 | + if (mainwpVars.websitesDone == successSites) { | |
| 1368 | + mainwpVars.bulkTaskRunning = false; | |
| 1369 | + setTimeout(function () { | |
| 1370 | + mainwpPopup('#mainwp-sync-sites-modal').close(true); | |
| 1371 | + }, 3000); | |
| 1372 | + } else { | |
| 1373 | + mainwpVars.bulkTaskRunning = false; | |
| 1374 | + } | |
| 1375 | + return; | |
| 1204 | 1376 | } |
| 1205 | - return; | |
| 1206 | - } | |
| 1207 | - mainwp_delete_nonmainwp_data_loop_next(); | |
| 1377 | + mainwp_delete_nonmainwp_data_loop_next(); | |
| 1208 | 1378 | }; |
| 1209 | 1379 | |
| 1210 | 1380 | |
| 1211 | -mainwp_tool_disconnect_sites = function () { | |
| 1381 | +let mainwp_tool_disconnect_sites = function () { | |
| 1212 | 1382 | |
| 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 | - }); | |
| 1383 | + 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 () { | |
| 1384 | + let allWebsiteIds = jQuery('.dashboard_wp_id[error-status=0]').map(function (indx, el) { | |
| 1385 | + return jQuery(el).val(); | |
| 1386 | + }); | |
| 1217 | 1387 | |
| 1218 | - for (var i = 0; i < allWebsiteIds.length; i++) { | |
| 1219 | - dashboard_update_site_status(allWebsiteIds[i], '<i class="clock outline icon"></i>'); | |
| 1220 | - } | |
| 1388 | + for (let id of allWebsiteIds) { | |
| 1389 | + dashboard_update_site_status(id, '<i class="clock outline icon"></i>'); | |
| 1390 | + } | |
| 1221 | 1391 | |
| 1222 | - var nrOfWebsites = allWebsiteIds.length; | |
| 1392 | + let nrOfWebsites = allWebsiteIds.length; | |
| 1223 | 1393 | |
| 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 | - }); | |
| 1394 | + mainwpPopup('#mainwp-sync-sites-modal').init({ | |
| 1395 | + title: MainWP.I18n.t('Disconnect All Sites'), | |
| 1396 | + progressMax: nrOfWebsites, | |
| 1397 | + statusText: MainWP.I18n.t('disconnected'), | |
| 1398 | + callback: function () { | |
| 1399 | + mainwp_forceReload(); | |
| 1400 | + } | |
| 1401 | + }); | |
| 1232 | 1402 | |
| 1233 | - websitesToUpdate = allWebsiteIds; | |
| 1234 | - currentWebsite = 0; | |
| 1235 | - websitesDone = 0; | |
| 1236 | - websitesTotal = websitesLeft = websitesToUpdate.length; | |
| 1403 | + mainwpVars.websitesToUpdate = allWebsiteIds; | |
| 1404 | + mainwpVars.currentWebsite = 0; | |
| 1405 | + mainwpVars.websitesDone = 0; | |
| 1406 | + mainwpVars.websitesTotal = mainwpVars.websitesLeft = mainwpVars.websitesToUpdate.length; | |
| 1237 | 1407 | |
| 1238 | - bulkTaskRunning = true; | |
| 1408 | + mainwpVars.bulkTaskRunning = true; | |
| 1239 | 1409 | |
| 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'); | |
| 1410 | + if (mainwpVars.websitesTotal == 0) { | |
| 1411 | + mainwp_tool_disconnect_sites_done(); | |
| 1412 | + } else { | |
| 1413 | + mainwp_tool_disconnect_sites_loop_next(); | |
| 1414 | + } | |
| 1415 | + }, false, false, false, 'DISCONNECT'); | |
| 1246 | 1416 | }; |
| 1247 | 1417 | |
| 1248 | -mainwp_tool_disconnect_sites_done = function () { | |
| 1249 | - currentThreads--; | |
| 1250 | - if (!bulkTaskRunning) | |
| 1251 | - return; | |
| 1252 | - websitesDone++; | |
| 1253 | - if (websitesDone > websitesTotal) | |
| 1254 | - websitesDone = websitesTotal; | |
| 1418 | +let mainwp_tool_disconnect_sites_done = function () { | |
| 1419 | + mainwpVars.currentThreads--; | |
| 1420 | + if (!mainwpVars.bulkTaskRunning) | |
| 1421 | + return; | |
| 1422 | + mainwpVars.websitesDone++; | |
| 1423 | + if (mainwpVars.websitesDone > mainwpVars.websitesTotal) | |
| 1424 | + mainwpVars.websitesDone = mainwpVars.websitesTotal; | |
| 1255 | 1425 | |
| 1256 | - mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(websitesDone); | |
| 1426 | + mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); | |
| 1257 | 1427 | |
| 1258 | - mainwp_tool_disconnect_sites_loop_next(); | |
| 1428 | + mainwp_tool_disconnect_sites_loop_next(); | |
| 1259 | 1429 | }; |
| 1260 | 1430 | |
| 1261 | -mainwp_tool_disconnect_sites_loop_next = function () { | |
| 1262 | - while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { | |
| 1263 | - mainwp_tool_disconnect_sites_next(); | |
| 1264 | - } | |
| 1431 | +let mainwp_tool_disconnect_sites_loop_next = function () { | |
| 1432 | + while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxThreads) && (mainwpVars.websitesLeft > 0)) { // NOSONAR - vars modified outside function. | |
| 1433 | + mainwp_tool_disconnect_sites_next(); | |
| 1434 | + } | |
| 1265 | 1435 | }; |
| 1266 | 1436 | |
| 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); | |
| 1437 | +let mainwp_tool_disconnect_sites_next = function () { | |
| 1438 | + mainwpVars.currentThreads++; | |
| 1439 | + mainwpVars.websitesLeft--; | |
| 1440 | + let websiteId = mainwpVars.websitesToUpdate[mainwpVars.currentWebsite++]; | |
| 1441 | + dashboard_update_site_status(websiteId, '<i class="sync alternate loading icon"></i>'); | |
| 1442 | + let data = mainwp_secure_data({ | |
| 1443 | + action: 'mainwp_disconnect_site', | |
| 1444 | + wp_id: websiteId | |
| 1445 | + }); | |
| 1446 | + mainwp_tool_disconnect_sites_next_int(websiteId, data, 0); | |
| 1277 | 1447 | }; |
| 1278 | 1448 | |
| 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 | - }); | |
| 1449 | +let mainwp_tool_disconnect_sites_next_int = function (websiteId, data, errors) { | |
| 1450 | + jQuery.ajax({ | |
| 1451 | + type: 'POST', | |
| 1452 | + url: ajaxurl, | |
| 1453 | + data: data, | |
| 1454 | + success: function (pWebsiteId) { | |
| 1455 | + return function (response) { | |
| 1456 | + if (response?.error) { | |
| 1457 | + dashboard_update_site_status(pWebsiteId, response.error + '<i class="exclamation red icon"></i>'); | |
| 1458 | + } else if (response?.result == 'success') { | |
| 1459 | + dashboard_update_site_status(websiteId, '<i class="check green icon"></i>', true); | |
| 1460 | + } else { | |
| 1461 | + dashboard_update_site_status(pWebsiteId, MainWP.I18n.t('Undefined error!') + ' <i class="exclamation red icon"></i>'); | |
| 1462 | + } | |
| 1463 | + mainwp_tool_disconnect_sites_done(); | |
| 1464 | + } | |
| 1465 | + }(websiteId), | |
| 1466 | + error: function (pWebsiteId, pData, pErrors) { | |
| 1467 | + return function () { | |
| 1468 | + if (pErrors > 5) { | |
| 1469 | + dashboard_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Process timed out. Please try again.') + '"><i class="exclamation yellow icon"></i></span>'); | |
| 1470 | + mainwp_tool_disconnect_sites_done(); | |
| 1471 | + } else { | |
| 1472 | + pErrors++; | |
| 1473 | + mainwp_tool_disconnect_sites_next_int(pWebsiteId, pData, pErrors); | |
| 1474 | + } | |
| 1475 | + } | |
| 1476 | + }(websiteId, data, errors), | |
| 1477 | + dataType: 'json' | |
| 1478 | + }); | |
| 1309 | 1479 | }; |
| 1310 | 1480 | |
| 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 | - }); | |
| 1481 | +let mainwp_tool_confirm_to_process = function (pObj) { | |
| 1482 | + let loc = jQuery(pObj).attr('href'); | |
| 1483 | + mainwp_confirm('Are you sure?', function () { | |
| 1484 | + globalThis.location = loc; | |
| 1485 | + }); | |
| 1316 | 1486 | }; |
| 1317 | 1487 | |
| 1488 | + | |
| 1318 | 1489 | /** |
| 1319 | 1490 | * Manage sites page |
| 1320 | 1491 | */ |
| 1321 | 1492 | |
| 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 | - }); | |
| 1493 | +jQuery(function ($) { | |
| 1494 | + jQuery('#mainwp-backup-type').on('change', function () { | |
| 1495 | + if (jQuery(this).val() == 'full') | |
| 1496 | + jQuery('.mainwp-backup-full-exclude').show(); | |
| 1497 | + else | |
| 1498 | + jQuery('.mainwp-backup-full-exclude').hide(); | |
| 1499 | + }); | |
| 1500 | + jQuery('.mainwp-checkbox-showhide-elements').on('click', function () { | |
| 1501 | + let hiel = $(this).attr('hide-parent'); | |
| 1502 | + if (hiel !== undefined && hiel !== '') { | |
| 1503 | + // support multi hide values. | |
| 1504 | + hiel.split(';').forEach((hi) => { | |
| 1505 | + mainwp_showhide_elements(hi, $(this).find('input').is(':checked')); | |
| 1506 | + }); | |
| 1507 | + } | |
| 1508 | + let hideEvent = $(this).attr('fire-event-parent') ?? ''; | |
| 1509 | + if (hideEvent != '') { | |
| 1510 | + // to sure click events finished. | |
| 1511 | + setTimeout(function () { | |
| 1512 | + document.dispatchEvent(new Event(hideEvent)); | |
| 1513 | + }, 200); | |
| 1514 | + } | |
| 1515 | + }); | |
| 1333 | 1516 | |
| 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 | - }); | |
| 1517 | + jQuery('.mainwp-selecter-showhide-elements').on('change', function () { | |
| 1518 | + let hiel = $(this).attr('hide-parent'); | |
| 1519 | + let hival = $(this).attr('hide-value'); | |
| 1520 | + hival = hival.split(';'); // support multi hide values. | |
| 1521 | + let selectedval = $(this).val(); | |
| 1522 | + mainwp_showhide_elements(hiel, hival.includes(selectedval)); | |
| 1523 | + }); | |
| 1341 | 1524 | }); |
| 1342 | 1525 | |
| 1343 | 1526 | 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 | - } | |
| 1527 | + // support multi attr to hide. | |
| 1528 | + if (valHi) { | |
| 1529 | + attEl.split(';').forEach(function (att) { | |
| 1530 | + jQuery('[hide-element=' + att.trim() + ']').fadeOut(300); | |
| 1531 | + jQuery('[hide-sub-element=' + att.trim() + ']').fadeOut(300); | |
| 1532 | + }); | |
| 1533 | + } else { | |
| 1534 | + attEl.split(';').forEach(function (att) { | |
| 1535 | + jQuery('[hide-element=' + att.trim() + ']').fadeIn(300); | |
| 1536 | + jQuery('[hide-sub-element=' + att.trim() + ']').fadeIn(300); | |
| 1537 | + }); | |
| 1538 | + } | |
| 1349 | 1539 | } |
| 1350 | 1540 | |
| 1351 | 1541 | |
| 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 | - }); | |
| 1542 | +jQuery(function ($) { | |
| 1543 | + $('#mainwp_settings_verify_connection_method').on('change', function () { | |
| 1544 | + let selectedval = $(this).val(); | |
| 1545 | + if (selectedval == 2) { // phpseclib. | |
| 1546 | + $('.mainwp-hide-elemenent-sign-algo').fadeOut(200); | |
| 1547 | + } else { | |
| 1548 | + $('.mainwp-hide-elemenent-sign-algo').fadeIn(200); | |
| 1549 | + } | |
| 1550 | + }); | |
| 1362 | 1551 | |
| 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 | - }); | |
| 1552 | + $('#mainwp_managesites_edit_verify_connection_method').on('change', function () { | |
| 1553 | + let selectedval = $(this).val(); | |
| 1554 | + if (selectedval == 2 || selectedval == 3) { // phpseclib. | |
| 1555 | + $('.mainwp-hide-elemenent-sign-algo').fadeOut(200); | |
| 1556 | + } else { | |
| 1557 | + $('.mainwp-hide-elemenent-sign-algo').fadeIn(200); | |
| 1558 | + } | |
| 1559 | + }); | |
| 1371 | 1560 | |
| 1372 | 1561 | |
| 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 | - }); | |
| 1562 | + $('#mainwp_managesites_edit_openssl_alg').on('change', function () { | |
| 1563 | + let selectedval = $(this).val(); | |
| 1564 | + if (selectedval == 1) { | |
| 1565 | + $('.mainwp-hide-elemenent-sign-algo-note').fadeIn(200); | |
| 1566 | + } else { | |
| 1567 | + $('.mainwp-hide-elemenent-sign-algo-note').fadeOut(200); | |
| 1568 | + } | |
| 1569 | + }); | |
| 1381 | 1570 | |
| 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 | - }); | |
| 1571 | + $('#mainwp_settings_openssl_alg').on('change', function () { | |
| 1572 | + let selectedval = $(this).val(); | |
| 1573 | + if (selectedval == 1) { | |
| 1574 | + $('.mainwp-hide-elemenent-sign-algo-note').fadeIn(200); | |
| 1575 | + } else { | |
| 1576 | + $('.mainwp-hide-elemenent-sign-algo-note').fadeOut(200); | |
| 1577 | + } | |
| 1578 | + }); | |
| 1390 | 1579 | |
| 1391 | 1580 | }) |
| 1392 | 1581 | |
| 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(); | |
| 1582 | +jQuery(function () { | |
| 1583 | + jQuery(document).on('change', '#mainwp_managesites_add_wpurl', function () { | |
| 1584 | + let url = jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 1585 | + let protocol = jQuery('#mainwp_managesites_add_wpurl_protocol').val(); | |
| 1397 | 1586 | |
| 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 | - } | |
| 1587 | + if (url.lastIndexOf('http://') === 0) { | |
| 1588 | + protocol = 'http'; | |
| 1589 | + url = url.substring(7); | |
| 1590 | + } else if (url.lastIndexOf('https://') === 0) { | |
| 1591 | + protocol = 'https'; | |
| 1592 | + url = url.substring(8); | |
| 1593 | + } | |
| 1405 | 1594 | |
| 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 | - }); | |
| 1595 | + if (jQuery('#mainwp_managesites_add_wpname').val() == '') { | |
| 1596 | + jQuery('#mainwp_managesites_add_wpname').val(url); | |
| 1597 | + } | |
| 1598 | + jQuery('#mainwp_managesites_add_wpurl').val(url); | |
| 1599 | + jQuery('#mainwp_managesites_add_wpurl_protocol').val(protocol).trigger("change"); | |
| 1600 | + }); | |
| 1412 | 1601 | |
| 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 | - }); | |
| 1602 | + // Trigger the single site reconnect process | |
| 1603 | + jQuery('.mainwp-manage-wpsites-table').on('click', '.mainwp_site_reconnect', function () { | |
| 1604 | + mainwp_managesites_reconnect(jQuery(this)); | |
| 1605 | + return false; | |
| 1606 | + }); | |
| 1418 | 1607 | |
| 1419 | - jQuery('#mainwp-sites-previews').on('click', '.mainwp_site_card_reconnect', function () { | |
| 1420 | - mainwp_managesites_cards_reconnect(jQuery(this)); | |
| 1421 | - return false; | |
| 1422 | - }); | |
| 1608 | + jQuery('#mainwp-sites-previews').on('click', '.mainwp_site_card_reconnect', function () { | |
| 1609 | + mainwp_managesites_cards_reconnect(jQuery(this)); | |
| 1610 | + return false; | |
| 1611 | + }); | |
| 1423 | 1612 | |
| 1424 | - jQuery('.mainwp-updates-overview-reconnect-site').on('click', function () { | |
| 1425 | - mainwp_site_overview_reconnect(jQuery(this)); | |
| 1426 | - return false; | |
| 1427 | - }); | |
| 1613 | + jQuery(document).on('click', '.mainwp-updates-overview-reconnect-site', function () { | |
| 1614 | + mainwp_site_overview_reconnect(jQuery(this)); | |
| 1615 | + return false; | |
| 1616 | + }); | |
| 1428 | 1617 | |
| 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 | - }); | |
| 1618 | + jQuery(".chk-sync-install-plugin").on('change', function () { | |
| 1619 | + let parent = jQuery(this).closest('.sync-ext-row'); | |
| 1620 | + let opts = parent.find(".sync-options input[type='checkbox']"); | |
| 1621 | + if (jQuery(this).is(':checked')) { | |
| 1622 | + opts.prop("checked", true); | |
| 1623 | + } else { | |
| 1624 | + opts.prop("checked", false); | |
| 1625 | + ///opts.attr( "disabled", "disabled" ); | |
| 1626 | + } | |
| 1627 | + }); | |
| 1440 | 1628 | |
| 1441 | - managesites_init(); | |
| 1629 | + managesites_init(); | |
| 1442 | 1630 | }); |
| 1443 | 1631 | |
| 1444 | 1632 | 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 | - } | |
| 1633 | + if (jQuery(this).is(':checked')) { | |
| 1634 | + jQuery('#mainwp_message_verify_installed_child').hide(); | |
| 1635 | + } | |
| 1448 | 1636 | }); |
| 1449 | 1637 | |
| 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'); | |
| 1638 | +globalThis.managesites_init = function () { | |
| 1639 | + mainwp_set_message_zone('#mainwp-message-zone'); | |
| 1640 | + jQuery('.sync-ext-row span.status').html(''); | |
| 1641 | + jQuery('.sync-ext-row span.status').css('color', '#0073aa'); | |
| 1454 | 1642 | }; |
| 1455 | 1643 | |
| 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 | - }); | |
| 1644 | +let mainwp_site_overview_reconnect = function (pElement) { | |
| 1645 | + feedback('mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + 'Trying to reconnect. Please wait...', ''); | |
| 1646 | + let data = mainwp_secure_data({ | |
| 1647 | + action: 'mainwp_reconnectwp', | |
| 1648 | + siteid: pElement.attr('siteid') | |
| 1649 | + }); | |
| 1462 | 1650 | |
| 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>.'; | |
| 1651 | + jQuery.post(ajaxurl, data, function () { | |
| 1652 | + return function (response) { | |
| 1653 | + response = response.trim(); | |
| 1654 | + if (response.substring(0, 5) == 'ERROR') { | |
| 1655 | + let error; | |
| 1656 | + if (response.length == 5) { | |
| 1657 | + error = 'Undefined error! Please try again. If the process keeps failing, please review <a href="https://docs.mainwp.com/">MainWP Knowledgebase</a>, and if you still have issues, please let us know in the <a href="https://community.mainwp.com/c/community-support/5">MainWP Community</a>.'; // NOSONAR - noopener - open safe. | |
| 1658 | + feedback('mainwp-message-zone', error, 'red'); | |
| 1659 | + } else { | |
| 1660 | + error = response.substring(6); | |
| 1661 | + let err = mainwp_js_get_error_not_detected_connect(error, 'html_msg', 'mainwp-message-zone'); | |
| 1662 | + if (false === err) { | |
| 1663 | + feedback('mainwp-message-zone', error, 'red'); // it is not json error string. | |
| 1664 | + } | |
| 1665 | + } | |
| 1666 | + } else if ('reconnect_failed' === response) { | |
| 1667 | + mainwp_set_message_zone('#mainwp-message-zone'); | |
| 1668 | + | |
| 1669 | + jQuery('#mainwp-reconnect-site-with-user-passwd-modal').modal({ | |
| 1670 | + onHide: function () { | |
| 1671 | + mainwp_forceReload(); | |
| 1672 | + }, | |
| 1673 | + closable: false | |
| 1674 | + }).modal('show'); | |
| 1675 | + jQuery('#mainwp_managesites_add_wpadmin').val(pElement.attr('adminuser')); | |
| 1676 | + jQuery(document).on('click', '#mainwp-popup-reconnect-site-btn', function () { | |
| 1677 | + mainwp_reconnect_with_pw(pElement.attr('siteid')); | |
| 1678 | + return false; | |
| 1679 | + }); | |
| 1680 | + } else { | |
| 1681 | + mainwp_set_message_zone('#mainwp-message-zone'); | |
| 1682 | + mainwp_forceReload(); | |
| 1683 | + } | |
| 1684 | + } | |
| 1685 | + }()); | |
| 1686 | +}; | |
| 1687 | + | |
| 1688 | +let mainwp_reconnect_with_pw = function (siteid) { | |
| 1689 | + mainwp_set_message_zone('#mainwp-message-zone-reconnect'); | |
| 1690 | + let errors = []; | |
| 1691 | + if (jQuery('#mainwp_managesites_add_wpadmin').val().trim() == '') { | |
| 1692 | + errors.push('Please enter a username of the website administrator.'); | |
| 1693 | + } | |
| 1694 | + | |
| 1695 | + if (jQuery('#mainwp_managesites_add_admin_pwd').val().trim() == '') { | |
| 1696 | + errors.push('Please enter password of the website administrator.'); | |
| 1697 | + } | |
| 1698 | + | |
| 1699 | + if (errors.length > 0) { | |
| 1700 | + mainwp_set_message_zone('#mainwp-message-zone-reconnect', errors.join('</br>'), 'red'); | |
| 1701 | + return; | |
| 1702 | + } | |
| 1703 | + | |
| 1704 | + mainwp_set_message_zone('#mainwp-message-zone-reconnect', '<i class="notched circle loading icon"></i> ' + 'Trying to reconnect. Please wait...', 'green'); | |
| 1705 | + let data = mainwp_secure_data({ | |
| 1706 | + action: 'mainwp_reconnectwp', | |
| 1707 | + managesites_add_wpadmin: jQuery('#mainwp_managesites_add_wpadmin').val(), | |
| 1708 | + managesites_add_adminpwd: encodeURIComponent(jQuery('#mainwp_managesites_add_admin_pwd').val()), | |
| 1709 | + siteid: siteid | |
| 1710 | + }); | |
| 1711 | + | |
| 1712 | + jQuery.post(ajaxurl, data, function (response) { | |
| 1713 | + response = response.trim(); | |
| 1714 | + mainwp_set_message_zone('#mainwp-message-zone-reconnect'); | |
| 1715 | + if (response.substring(0, 5) == 'ERROR') { | |
| 1716 | + let error; | |
| 1717 | + if (response.length == 5) { | |
| 1718 | + error = 'Undefined error! Please try again. If the process keeps failing, please review this <a href="https://docs.mainwp.com/troubleshooting/potential-issues">Knowledgebase document</a>, and if you still have issues, please let us know in the <a href="https://community.mainwp.com/c/community-support/5">MainWP Community</a>.'; // NOSONAR - noopener - open safe. | |
| 1719 | + mainwp_set_message_zone('#mainwp-message-zone-reconnect', error, 'red'); | |
| 1720 | + } else { | |
| 1721 | + error = response.substring(6); | |
| 1722 | + let err = mainwp_js_get_error_not_detected_connect(error, 'html_msg', 'mainwp-message-zone-reconnect'); | |
| 1723 | + if (false === err) { | |
| 1724 | + mainwp_set_message_zone('#mainwp-message-zone-reconnect', error, 'red'); // it is not json error string. | |
| 1725 | + } | |
| 1726 | + } | |
| 1727 | + } else if ('reconnect_failed' === response) { | |
| 1728 | + // do not show reconnect popup again. | |
| 1729 | + mainwp_set_message_zone('#mainwp-message-zone-reconnect', mainwp_get_reconnect_error(response, siteid), 'red'); | |
| 1470 | 1730 | } else { |
| 1471 | - error = response.substr(6); | |
| 1731 | + mainwp_set_message_zone('#mainwp-message-zone-reconnect', response, 'green'); | |
| 1732 | + mainwp_forceReload(); | |
| 1472 | 1733 | } |
| 1473 | - feedback('mainwp-message-zone', error, 'red'); | |
| 1474 | - } else { | |
| 1475 | - location.reload(); | |
| 1476 | - } | |
| 1477 | - } | |
| 1478 | - }()); | |
| 1734 | + }); | |
| 1479 | 1735 | }; |
| 1480 | 1736 | |
| 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 | 1737 | |
| 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); | |
| 1738 | +let mainwp_managesites_reconnect = function (pElement) { | |
| 1739 | + let wrapElement = pElement.closest('tr'); | |
| 1740 | + wrapElement.html('<td colspan="999"><i class="notched circle loading icon"></i> ' + 'Trying to reconnect. Please wait...' + '</td>'); | |
| 1741 | + let siteid = wrapElement.attr('siteid'); | |
| 1742 | + let data = mainwp_secure_data({ | |
| 1743 | + action: 'mainwp_reconnectwp', | |
| 1744 | + siteid: siteid | |
| 1745 | + }); | |
| 1746 | + | |
| 1747 | + jQuery.post(ajaxurl, data, function (pWrapElement) { | |
| 1748 | + return function (response) { | |
| 1749 | + response = response.trim(); | |
| 1750 | + pWrapElement.hide(); // hide reconnect item | |
| 1751 | + if (response.substring(0, 5) == 'ERROR') { | |
| 1752 | + let error; | |
| 1753 | + if (response.length == 5) { | |
| 1754 | + error = 'Undefined error! Please try again. If the process keeps failing, please review this <a href="https://docs.mainwp.com/troubleshooting/potential-issues">Knowledgebase document</a>, and if you still have issues, please let us know in the <a href="https://community.mainwp.com/c/community-support/5">MainWP Community</a>.'; // NOSONAR - noopener - open safe. | |
| 1755 | + feedback('mainwp-message-zone', error, 'red'); | |
| 1756 | + } else { | |
| 1757 | + error = response.substring(6); | |
| 1758 | + let err = mainwp_js_get_error_not_detected_connect(error, 'html_msg', 'mainwp-message-zone'); | |
| 1759 | + if (false === err) { | |
| 1760 | + feedback('mainwp-message-zone', error, 'red'); // it is not json error string. | |
| 1761 | + } | |
| 1762 | + } | |
| 1763 | + } else if ('reconnect_failed' === response) { | |
| 1764 | + feedback('mainwp-message-zone', mainwp_get_reconnect_error(response, siteid), 'error'); | |
| 1765 | + } else { | |
| 1766 | + feedback('mainwp-message-zone', response, 'green'); | |
| 1767 | + } | |
| 1768 | + setTimeout(function () { | |
| 1769 | + mainwp_forceReload(); | |
| 1770 | + }, 6000); | |
| 1499 | 1771 | } |
| 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 | 1772 | |
| 1509 | - }(wrapElement)); | |
| 1773 | + }(wrapElement)); | |
| 1510 | 1774 | }; |
| 1511 | 1775 | |
| 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 | - }); | |
| 1776 | +let mainwp_managesites_cards_reconnect = function (element) { | |
| 1777 | + element.html('<i class="notched loading circle icon"></i> Reconnecting...'); | |
| 1778 | + let siteid = element.attr('site-id'); | |
| 1779 | + let data = mainwp_secure_data({ | |
| 1780 | + action: 'mainwp_reconnectwp', | |
| 1781 | + siteid: siteid | |
| 1782 | + }); | |
| 1518 | 1783 | |
| 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); | |
| 1784 | + jQuery.post(ajaxurl, data, function (element) { | |
| 1785 | + return function (response) { | |
| 1786 | + response = response.trim(); | |
| 1787 | + element.hide(); | |
| 1788 | + if (response.substring(0, 5) == 'ERROR') { | |
| 1789 | + let error; | |
| 1790 | + if (response.length == 5) { | |
| 1791 | + error = 'Undefined error! Please try again. If the process keeps failing, please review this <a href="https://docs.mainwp.com/troubleshooting/potential-issues">Knowledgebase document</a>, and if you still have issues, please let us know in the <a href="https://community.mainwp.com/c/community-support/5">MainWP Community</a>.'; // NOSONAR - noopener - open safe. | |
| 1792 | + feedback('mainwp-message-zone', error, 'red'); | |
| 1793 | + } else { | |
| 1794 | + error = response.substring(6); | |
| 1795 | + let err = mainwp_js_get_error_not_detected_connect(error, 'html_msg', 'mainwp-message-zone'); | |
| 1796 | + if (false === err) { | |
| 1797 | + feedback('mainwp-message-zone', error, 'red'); // it is not json error string. | |
| 1798 | + } | |
| 1799 | + } | |
| 1800 | + } else if ('reconnect_failed' === response) { | |
| 1801 | + feedback('mainwp-message-zone', mainwp_get_reconnect_error(response, siteid), 'error'); | |
| 1802 | + } else { | |
| 1803 | + feedback('mainwp-message-zone', response, 'green'); | |
| 1804 | + } | |
| 1805 | + setTimeout(function () { | |
| 1806 | + mainwp_forceReload(); | |
| 1807 | + }, 6000); | |
| 1529 | 1808 | } |
| 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 | 1809 | |
| 1539 | - }(element)); | |
| 1810 | + }(element)); | |
| 1540 | 1811 | }; |
| 1541 | 1812 | |
| 1542 | 1813 | // 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 | - } | |
| 1814 | +let mainwp_managesites_add = function () { | |
| 1552 | 1815 | |
| 1553 | - var errors = []; | |
| 1816 | + managesites_init(); | |
| 1554 | 1817 | |
| 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 | - } | |
| 1818 | + let valid_input = mainwp_managesites_add_valid(); | |
| 1565 | 1819 | |
| 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.')); | |
| 1820 | + if (!valid_input) { | |
| 1821 | + return; | |
| 1570 | 1822 | } |
| 1571 | - } | |
| 1572 | - if (jQuery('#mainwp_managesites_add_wpadmin').val().trim() == '') { | |
| 1573 | - errors.push(__('Please enter a username of the website administrator.')); | |
| 1574 | - } | |
| 1575 | 1823 | |
| 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'); | |
| 1824 | + feedback('mainwp-message-zone', MainWP.I18n.t('Adding the site to your MainWP Dashboard. Please wait...'), 'green'); | |
| 1580 | 1825 | |
| 1581 | 1826 | jQuery('#mainwp_managesites_add').attr('disabled', 'true'); //disable button to add.. |
| 1582 | 1827 | |
| 1583 | 1828 | //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 += '/'; | |
| 1829 | + let url = jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 1830 | + | |
| 1831 | + if (!url.endsWith('/')) { | |
| 1832 | + url += '/'; | |
| 1587 | 1833 | } |
| 1588 | 1834 | |
| 1589 | - var name = jQuery('#mainwp_managesites_add_wpname').val().trim(); | |
| 1590 | - name = name.replace(/"/g, '"'); | |
| 1835 | + let name = jQuery('#mainwp_managesites_add_wpname').val().trim(); | |
| 1836 | + name = name.replaceAll('"', '"'); | |
| 1591 | 1837 | |
| 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() | |
| 1838 | + let data = mainwp_secure_data({ | |
| 1839 | + action: 'mainwp_checkwp', | |
| 1840 | + name: name, | |
| 1841 | + url: url, | |
| 1842 | + admin: jQuery('#mainwp_managesites_add_wpadmin').val().trim(), | |
| 1843 | + verify_certificate: jQuery('#mainwp_managesites_verify_certificate').is(':checked') ? 1 : 0, | |
| 1844 | + ssl_version: jQuery('#mainwp_managesites_add_ssl_version').val(), | |
| 1845 | + http_user: jQuery('#mainwp_managesites_add_http_user').val().trim(), | |
| 1846 | + http_pass: jQuery('#mainwp_managesites_add_http_pass').val().trim() | |
| 1601 | 1847 | }); |
| 1602 | 1848 | |
| 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, '"'); | |
| 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)); | |
| 1849 | + jQuery.post(ajaxurl, data, function (res_things) { // NOSONAR - function complexity. | |
| 1850 | + let response = res_things.response; | |
| 1851 | + response = response.trim(); | |
| 1852 | + let errors = []; | |
| 1853 | + let url = jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 1854 | + if (!url.endsWith('/')) { | |
| 1855 | + url += '/'; | |
| 1630 | 1856 | } |
| 1631 | - } else if (response == 'OK') { | |
| 1632 | - jQuery('#mainwp_managesites_add').attr('disabled', 'true'); //Disable add button | |
| 1633 | 1857 | |
| 1634 | - var name = jQuery('#mainwp_managesites_add_wpname').val(); | |
| 1635 | - name = name.replace(/"/g, '"'); | |
| 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 | - }); | |
| 1858 | + url = url.replaceAll('"', '"'); | |
| 1651 | 1859 | |
| 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 | - }); | |
| 1860 | + let show_resp = MainWP.I18n.t('Click %1here%2 to see response from the child site.', '<a href="javascript:void(0)" class="mainwp-show-response">', '</a>'); | |
| 1658 | 1861 | |
| 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) { | |
| 1862 | + let resp_data = res_things.resp_data ? res_things.resp_data : ''; | |
| 1863 | + if ('0' == resp_data) { | |
| 1679 | 1864 | resp_data = ''; |
| 1680 | - } | |
| 1681 | - jQuery('#mainwp-response-data-container').attr('resp-data', resp_data); | |
| 1865 | + } | |
| 1866 | + jQuery('#mainwp-response-data-container').attr('resp-data', resp_data); | |
| 1682 | 1867 | |
| 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); | |
| 1868 | + if (response == 'HTTPERROR') { | |
| 1869 | + errors.push(MainWP.I18n.t('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://docs.mainwp.com/troubleshooting/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>.')); // NOSONAR - noopener - open safe. | |
| 1870 | + } else if (response == 'NOMAINWP') { | |
| 1871 | + errors.push(mainwp_js_get_error_not_detected_connect()); | |
| 1872 | + } else if (response.substring(0, 5) == 'ERROR') { | |
| 1873 | + if (response.length == 5) { | |
| 1874 | + errors.push(MainWP.I18n.t('Undefined error occurred. Please try again. If the issue does not resolve, please review this <a href="https://docs.mainwp.com/troubleshooting/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>.')); // NOSONAR - noopener - open safe. | |
| 1875 | + } else { | |
| 1876 | + errors.push(MainWP.I18n.t('Error detected: ') + response.substring(6)); | |
| 1696 | 1877 | } |
| 1878 | + } else if (response == 'OK') { | |
| 1879 | + jQuery('#mainwp_managesites_add').attr('disabled', 'true'); //Disable add button | |
| 1697 | 1880 | |
| 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); | |
| 1881 | + let name = jQuery('#mainwp_managesites_add_wpname').val(); | |
| 1882 | + name = name.replaceAll('"', '"'); | |
| 1883 | + let group_ids = jQuery('#mainwp_managesites_add_addgroups').dropdown('get value'); | |
| 1884 | + let client_id = jQuery('#mainwp_managesites_add_client_id').length ? jQuery('#mainwp_managesites_add_client_id').dropdown('get value') : 0; | |
| 1885 | + let data = mainwp_secure_data({ | |
| 1886 | + action: 'mainwp_addwp', | |
| 1887 | + managesites_add_wpname: name, | |
| 1888 | + managesites_add_wpurl: url, | |
| 1889 | + managesites_add_wpadmin: jQuery('#mainwp_managesites_add_wpadmin').val(), | |
| 1890 | + managesites_add_adminpwd: encodeURIComponent(jQuery('#mainwp_managesites_add_admin_pwd').val().trim()), | |
| 1891 | + managesites_add_uniqueId: jQuery('#mainwp_managesites_add_uniqueId').val(), | |
| 1892 | + ssl_verify: jQuery('#mainwp_managesites_verify_certificate').is(':checked') ? 1 : 0, | |
| 1893 | + ssl_version: jQuery('#mainwp_managesites_add_ssl_version').val(), | |
| 1894 | + groupids: group_ids, | |
| 1895 | + clientid: client_id, | |
| 1896 | + selected_icon: jQuery('#mainwp_managesites_add_site_select_icon_hidden').val(), | |
| 1897 | + cust_color: jQuery('#mainwp_managesites_add_site_color').val(), | |
| 1898 | + uploaded_icon: jQuery('#mainwp_managesites_add_site_uploaded_icon_hidden').val(), | |
| 1899 | + managesites_add_http_user: jQuery('#mainwp_managesites_add_http_user').val(), | |
| 1900 | + managesites_add_http_pass: jQuery('#mainwp_managesites_add_http_pass').val(), | |
| 1901 | + }); | |
| 1706 | 1902 | |
| 1903 | + // to support add client reports tokens values | |
| 1707 | 1904 | jQuery("input[name^='creport_token_']").each(function () { |
| 1708 | - jQuery(this).val(''); | |
| 1905 | + let tname = jQuery(this).attr('name'); | |
| 1906 | + let tvalue = jQuery(this).val(); | |
| 1907 | + data[tname] = tvalue; | |
| 1709 | 1908 | }); |
| 1710 | 1909 | |
| 1711 | 1910 | // support hooks fields |
| 1712 | 1911 | jQuery(".mainwp_addition_fields_addsite input").each(function () { |
| 1713 | - jQuery(this).val(''); | |
| 1912 | + let tname = jQuery(this).attr('name'); | |
| 1913 | + let tvalue = jQuery(this).val(); | |
| 1914 | + data[tname] = tvalue; | |
| 1714 | 1915 | }); |
| 1715 | - } | |
| 1716 | 1916 | |
| 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); | |
| 1917 | + jQuery.post(ajaxurl, data, function (res_things) { | |
| 1918 | + let site_id = 0; | |
| 1919 | + if (res_things.error) { | |
| 1920 | + response = 'Error detected: ' + res_things.error; | |
| 1921 | + } else { | |
| 1922 | + response = res_things.response; | |
| 1923 | + site_id = res_things.siteid; | |
| 1924 | + } | |
| 1925 | + response = response.trim(); | |
| 1926 | + managesites_init(); | |
| 1927 | + | |
| 1928 | + resp_data = res_things.resp_data ? res_things.resp_data : ''; | |
| 1929 | + if ('0' == resp_data) { | |
| 1930 | + resp_data = ''; | |
| 1931 | + } | |
| 1932 | + jQuery('#mainwp-response-data-container').attr('resp-data', resp_data); | |
| 1933 | + | |
| 1934 | + if (response.substring(0, 5) == 'ERROR') { | |
| 1935 | + mainwp_set_message_zone('#mainwp-message-zone', '', '', true); | |
| 1936 | + feedback('mainwp-message-zone', response.substring(6) + (resp_data == '' ? '' : '<br>' + show_resp), 'red'); | |
| 1937 | + } else { | |
| 1938 | + mainwp_set_message_zone('#mainwp-message-zone', '', '', true); | |
| 1939 | + feedback('mainwp-message-zone', response, 'green'); | |
| 1940 | + | |
| 1941 | + if (site_id > 0) { | |
| 1942 | + jQuery('.sync-ext-row').attr('status', 'queue'); | |
| 1943 | + setTimeout(function () { | |
| 1944 | + mainwp_managesites_sync_extension_start_next(site_id); | |
| 1945 | + }, 1000); | |
| 1946 | + } | |
| 1947 | + | |
| 1948 | + //Reset fields | |
| 1949 | + jQuery('#mainwp_managesites_add_wpname').val(''); | |
| 1950 | + jQuery('#mainwp_managesites_add_wpurl').val(''); | |
| 1951 | + jQuery('#mainwp_managesites_add_wpurl_protocol').val('https'); | |
| 1952 | + jQuery('#mainwp_managesites_add_wpadmin').val(''); | |
| 1953 | + jQuery('#mainwp_managesites_add_admin_pwd').val(''); | |
| 1954 | + jQuery('#mainwp_managesites_add_uniqueId').val(''); | |
| 1955 | + jQuery('#mainwp_managesites_add_addgroups').dropdown('clear'); | |
| 1956 | + jQuery('#mainwp_managesites_verify_certificate').val(1); | |
| 1957 | + | |
| 1958 | + jQuery("input[name^='creport_token_']").each(function () { | |
| 1959 | + jQuery(this).val(''); | |
| 1960 | + }); | |
| 1961 | + | |
| 1962 | + // support hooks fields | |
| 1963 | + jQuery(".mainwp_addition_fields_addsite input").each(function () { | |
| 1964 | + jQuery(this).val(''); | |
| 1965 | + }); | |
| 1966 | + } | |
| 1967 | + | |
| 1968 | + jQuery('#mainwp_managesites_add').prop("disabled", false); //Enable add button | |
| 1969 | + }, 'json'); | |
| 1726 | 1970 | } |
| 1727 | - feedback('mainwp-message-zone', errors.join('<br />'), 'red'); | |
| 1728 | - } | |
| 1971 | + if (errors.length > 0) { | |
| 1972 | + mainwp_set_message_zone('#mainwp-message-zone', '', '', true); | |
| 1973 | + managesites_init(); | |
| 1974 | + jQuery('#mainwp_managesites_add').prop("disabled", false); //Enable add button | |
| 1975 | + if (resp_data != '') { | |
| 1976 | + errors.push(show_resp); | |
| 1977 | + } | |
| 1978 | + feedback('mainwp-message-zone', errors.join('<br />'), 'red'); | |
| 1979 | + } | |
| 1729 | 1980 | }, 'json'); |
| 1730 | - } | |
| 1731 | 1981 | }; |
| 1732 | 1982 | |
| 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 | - } | |
| 1983 | +let mainwp_managesites_add_valid = function () { | |
| 1737 | 1984 | |
| 1738 | - if ((pluginToInstall.length == 0) && (bulkInstallCurrentThreads == 0)) { | |
| 1739 | - jQuery('#mwp_applying_ext_settings').remove(); | |
| 1740 | - } | |
| 1985 | + if (jQuery('#mainwp_managesites_verify_installed_child').is(':checked')) { | |
| 1986 | + jQuery('#mainwp_message_verify_installed_child').hide(); | |
| 1987 | + } else { | |
| 1988 | + jQuery('#mainwp_message_verify_installed_child').show(); | |
| 1989 | + scrollElementTop('mainwp_message_verify_installed_child'); | |
| 1990 | + return false; | |
| 1991 | + } | |
| 1992 | + | |
| 1993 | + let errors = []; | |
| 1994 | + | |
| 1995 | + if (jQuery('#mainwp_managesites_add_wpname').val().trim() == '') { | |
| 1996 | + errors.push(MainWP.I18n.t('Please enter a name for the website.')); | |
| 1997 | + } | |
| 1998 | + if (jQuery('#mainwp_managesites_add_wpurl').val().trim() == '') { | |
| 1999 | + errors.push(MainWP.I18n.t('Please enter a valid URL for your site.')); | |
| 2000 | + } else { | |
| 2001 | + let url = jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 2002 | + if (!url.endsWith('/')) { | |
| 2003 | + url += '/'; | |
| 2004 | + } | |
| 2005 | + | |
| 2006 | + jQuery('#mainwp_managesites_add_wpurl').val(url); | |
| 2007 | + | |
| 2008 | + if (!isUrl(jQuery('#mainwp_managesites_add_wpurl_protocol').val() + '://' + jQuery('#mainwp_managesites_add_wpurl').val())) { | |
| 2009 | + errors.push(MainWP.I18n.t('Please enter a valid URL for your site.')); | |
| 2010 | + } | |
| 2011 | + } | |
| 2012 | + if (jQuery('#mainwp_managesites_add_wpadmin').val().trim() == '') { | |
| 2013 | + errors.push(MainWP.I18n.t('Please enter a username of the website administrator.')); | |
| 2014 | + } | |
| 2015 | + | |
| 2016 | + if (errors.length > 0) { | |
| 2017 | + feedback('mainwp-message-zone', errors.join('<br />'), 'yellow'); | |
| 2018 | + return false; | |
| 2019 | + } | |
| 2020 | + return true; | |
| 2021 | +} | |
| 2022 | + | |
| 2023 | + | |
| 2024 | +let mainwp_managesites_sync_extension_start_next = function (siteId) { | |
| 2025 | + let pluginToInstall = jQuery('.sync-ext-row[status="queue"]:first') | |
| 2026 | + while (pluginToInstall && (pluginToInstall.length > 0) && (bulkInstallCurrentThreads < 1)) { // NOSONAR - modified outside the function, bulkInstallMaxThreads - to fix install plugins and apply settings failed issue. | |
| 2027 | + pluginToInstall.attr('status', 'progress'); | |
| 2028 | + mainwp_managesites_sync_extension_start_specific(pluginToInstall, siteId); | |
| 2029 | + pluginToInstall = jQuery('.sync-ext-row[status="queue"]:first'); | |
| 2030 | + } | |
| 2031 | + | |
| 2032 | + if ((pluginToInstall.length == 0) && (bulkInstallCurrentThreads == 0)) { // NOSONAR - modified outside the function. | |
| 2033 | + jQuery('#mwp_applying_ext_settings').remove(); | |
| 2034 | + } | |
| 1741 | 2035 | }; |
| 1742 | 2036 | |
| 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; | |
| 2037 | +let mainwp_managesites_sync_extension_start_specific = function (pPluginToInstall, pSiteId) { | |
| 2038 | + let syncGlobalSettings = pPluginToInstall.find(".sync-global-options input[type='checkbox']:checked").length > 0; | |
| 2039 | + let install_plugin = pPluginToInstall.find(".sync-install-plugin input[type='checkbox']:checked").length > 0; | |
| 2040 | + let apply_settings = pPluginToInstall.find(".sync-options input[type='checkbox']:checked").length > 0; | |
| 1748 | 2041 | |
| 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 | - } | |
| 2042 | + if (syncGlobalSettings) { | |
| 2043 | + mainwp_extension_apply_plugin_settings(pPluginToInstall, pSiteId, true); | |
| 2044 | + } else if (install_plugin) { | |
| 2045 | + mainwp_extension_prepareinstallplugin(pPluginToInstall, pSiteId); | |
| 2046 | + } else if (apply_settings) { | |
| 2047 | + mainwp_extension_apply_plugin_settings(pPluginToInstall, pSiteId, false); | |
| 2048 | + } else { | |
| 2049 | + mainwp_managesites_sync_extension_start_next(pSiteId); | |
| 2050 | + return; | |
| 2051 | + } | |
| 1759 | 2052 | }; |
| 1760 | 2053 | |
| 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"); | |
| 2054 | +let mainwp_extension_prepareinstallplugin = function (pPluginToInstall, pSiteId) { | |
| 2055 | + let site_Ids = []; | |
| 2056 | + site_Ids.push(pSiteId); | |
| 2057 | + bulkInstallCurrentThreads++; | |
| 2058 | + let plugin_slug = pPluginToInstall.find(".sync-install-plugin").attr('slug'); | |
| 2059 | + let workingEl = pPluginToInstall.find(".sync-install-plugin i"); | |
| 2060 | + let statusEl = pPluginToInstall.find(".sync-install-plugin span.status"); | |
| 1768 | 2061 | |
| 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 | - }; | |
| 2062 | + let data = { | |
| 2063 | + action: 'mainwp_ext_prepareinstallplugintheme', | |
| 2064 | + type: 'plugin', | |
| 2065 | + slug: plugin_slug, | |
| 2066 | + 'selected_sites[]': site_Ids, | |
| 2067 | + selected_by: 'site', | |
| 2068 | + }; | |
| 1776 | 2069 | |
| 1777 | - workingEl.show(); | |
| 1778 | - statusEl.html(__('Preparing for installation...')); | |
| 2070 | + workingEl.show(); | |
| 2071 | + statusEl.html(MainWP.I18n.t('Preparing for installation...')); | |
| 1779 | 2072 | |
| 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) { | |
| 2073 | + jQuery.post(ajaxurl, data, function (response) { | |
| 1794 | 2074 | 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'); | |
| 2075 | + if (response?.sites[pSiteId] === undefined) { | |
| 2076 | + statusEl.css('color', 'red'); | |
| 2077 | + statusEl.html(MainWP.I18n.t('Error while preparing the installation. Please, try again.')); | |
| 2078 | + bulkInstallCurrentThreads--; | |
| 1810 | 2079 | } else { |
| 1811 | - syc_msg = __('Installation failed!'); | |
| 1812 | - statusEl.html(syc_msg); | |
| 1813 | - statusEl.css('color', 'red'); | |
| 2080 | + statusEl.html(MainWP.I18n.t('Installing...')); | |
| 2081 | + let data = mainwp_secure_data({ | |
| 2082 | + action: 'mainwp_ext_performinstallplugintheme', | |
| 2083 | + type: 'plugin', | |
| 2084 | + url: response.url, | |
| 2085 | + siteId: pSiteId, | |
| 2086 | + activatePlugin: true, | |
| 2087 | + overwrite: false, | |
| 2088 | + }); | |
| 2089 | + workingEl.show(); | |
| 2090 | + jQuery.post(ajaxurl, data, function (response) { | |
| 2091 | + workingEl.hide(); | |
| 2092 | + let apply_settings = false; | |
| 2093 | + let syc_msg = ''; | |
| 2094 | + let _success = false; | |
| 2095 | + if ((response?.ok[pSiteId] != undefined)) { | |
| 2096 | + syc_msg = MainWP.I18n.t('Installation successful!'); | |
| 2097 | + statusEl.html(syc_msg); | |
| 2098 | + apply_settings = pPluginToInstall.find(".sync-options input[type='checkbox']:checked").length > 0; | |
| 2099 | + if (apply_settings) { | |
| 2100 | + mainwp_extension_apply_plugin_settings(pPluginToInstall, pSiteId, false); | |
| 2101 | + } | |
| 2102 | + _success = true; | |
| 2103 | + } else if (response?.errors[pSiteId] === undefined) { | |
| 2104 | + syc_msg = MainWP.I18n.t('Installation failed!'); | |
| 2105 | + statusEl.html(syc_msg); | |
| 2106 | + statusEl.css('color', 'red'); | |
| 2107 | + } else { | |
| 2108 | + syc_msg = MainWP.I18n.t('Installation failed!') + ': ' + response.errors[pSiteId][1]; | |
| 2109 | + statusEl.html(syc_msg); | |
| 2110 | + statusEl.css('color', 'red'); | |
| 2111 | + } | |
| 2112 | + | |
| 2113 | + if (syc_msg != '') { | |
| 2114 | + if (_success) | |
| 2115 | + syc_msg = '<span style="color:#0073aa">' + syc_msg + '!</span>'; | |
| 2116 | + else | |
| 2117 | + syc_msg = '<span style="color:red">' + syc_msg + '!</span>'; | |
| 2118 | + jQuery('#mainwp-message-zone').append('<br/>' + pPluginToInstall.find(".sync-install-plugin").attr('plugin_name') + ' ' + syc_msg); | |
| 2119 | + } | |
| 2120 | + | |
| 2121 | + if (!apply_settings) { | |
| 2122 | + bulkInstallCurrentThreads--; | |
| 2123 | + mainwp_managesites_sync_extension_start_next(pSiteId); | |
| 2124 | + } | |
| 2125 | + }, 'json'); | |
| 1814 | 2126 | } |
| 2127 | + }, 'json'); | |
| 2128 | +} | |
| 1815 | 2129 | |
| 2130 | +let mainwp_extension_apply_plugin_settings = function (pPluginToInstall, pSiteId, pGlobal) { | |
| 2131 | + let extSlug = pPluginToInstall.attr('slug'); | |
| 2132 | + let workingEl = pPluginToInstall.find(".options-row i"); | |
| 2133 | + let statusEl = pPluginToInstall.find(".options-row span.status"); | |
| 2134 | + if (pGlobal) | |
| 2135 | + bulkInstallCurrentThreads++; | |
| 2136 | + | |
| 2137 | + let data = mainwp_secure_data({ | |
| 2138 | + action: 'mainwp_ext_applypluginsettings', | |
| 2139 | + ext_dir_slug: extSlug, | |
| 2140 | + siteId: pSiteId | |
| 2141 | + }); | |
| 2142 | + | |
| 2143 | + workingEl.show(); | |
| 2144 | + statusEl.html(MainWP.I18n.t('Applying settings...')); | |
| 2145 | + jQuery.post(ajaxurl, data, function (response) { // NOSONAR - complex. | |
| 2146 | + workingEl.hide(); | |
| 2147 | + let syc_msg = ''; | |
| 2148 | + let _success = false; | |
| 2149 | + if (response) { | |
| 2150 | + if (response.result && response.result == 'success') { | |
| 2151 | + let msg = ''; | |
| 2152 | + if (response.message != undefined) { | |
| 2153 | + msg = ' ' + response.message; | |
| 2154 | + } | |
| 2155 | + statusEl.html(MainWP.I18n.t('Applying settings successful!') + msg); | |
| 2156 | + syc_msg = MainWP.I18n.t('Successful'); | |
| 2157 | + _success = true | |
| 2158 | + } else if (response.error === undefined) { | |
| 2159 | + statusEl.html(MainWP.I18n.t('Applying settings failed!')); | |
| 2160 | + statusEl.css('color', 'red'); | |
| 2161 | + syc_msg = MainWP.I18n.t('failed'); | |
| 2162 | + } else { | |
| 2163 | + statusEl.html(response.error); | |
| 2164 | + statusEl.css('color', 'red'); | |
| 2165 | + syc_msg = response.error; | |
| 2166 | + } | |
| 2167 | + } else { | |
| 2168 | + statusEl.html(MainWP.I18n.t('Undefined error!')); | |
| 2169 | + statusEl.css('color', 'red'); | |
| 2170 | + syc_msg = MainWP.I18n.t('failed'); | |
| 2171 | + } | |
| 2172 | + | |
| 1816 | 2173 | 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/>'); | |
| 2174 | + if (_success) | |
| 2175 | + syc_msg = '<span style="color:#0073aa">' + syc_msg + '!</span>'; | |
| 2176 | + else | |
| 2177 | + syc_msg = '<span style="color:red">' + syc_msg + '!</span>'; | |
| 2178 | + if (pGlobal) { | |
| 2179 | + syc_msg = MainWP.I18n.t('Apply global %1 options', pPluginToInstall.attr('ext_name')) + ' ' + syc_msg; | |
| 2180 | + } else { | |
| 2181 | + syc_msg = MainWP.I18n.t('Apply %1 settings', pPluginToInstall.find('.sync-install-plugin').attr('plugin_name')) + ' ' + syc_msg; | |
| 2182 | + } | |
| 2183 | + jQuery('#mainwp-message-zone').append('<br/>' + syc_msg); | |
| 1822 | 2184 | } |
| 2185 | + bulkInstallCurrentThreads--; | |
| 2186 | + mainwp_managesites_sync_extension_start_next(pSiteId); | |
| 2187 | + }, 'json'); | |
| 2188 | +} | |
| 1823 | 2189 | |
| 1824 | - if (!apply_settings) { | |
| 1825 | - bulkInstallCurrentThreads--; | |
| 1826 | - mainwp_managesites_sync_extension_start_next(pSiteId); | |
| 2190 | +// Test Connection (Add Site Page) | |
| 2191 | +let mainwp_managesites_test = function () { | |
| 2192 | + | |
| 2193 | + let errors = []; | |
| 2194 | + | |
| 2195 | + if (jQuery('#mainwp_managesites_add_wpurl').val().trim() == '') { | |
| 2196 | + errors.push(MainWP.I18n.t('Please enter a valid URL for your site.')); | |
| 2197 | + } else { | |
| 2198 | + let clean_url = jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 2199 | + let protocol = jQuery('#mainwp_managesites_add_wpurl_protocol').val(); | |
| 2200 | + let url = protocol + '://' + clean_url; | |
| 2201 | + if (!url.endsWith('/')) { | |
| 2202 | + url += '/'; | |
| 1827 | 2203 | } |
| 1828 | - }, 'json'); | |
| 1829 | - } else { | |
| 1830 | - statusEl.css('color', 'red'); | |
| 1831 | - statusEl.html(__('Error while preparing the installation. Please, try again.')); | |
| 1832 | - bulkInstallCurrentThreads--; | |
| 2204 | + | |
| 2205 | + if (!isUrl(url)) { | |
| 2206 | + errors.push(MainWP.I18n.t('Please enter a valid URL for your site')); | |
| 2207 | + } | |
| 1833 | 2208 | } |
| 1834 | - }, 'json'); | |
| 1835 | -} | |
| 1836 | 2209 | |
| 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++; | |
| 2210 | + if (errors.length > 0) { | |
| 2211 | + feedback('mainwp-message-zone', errors.join('<br />'), 'red'); | |
| 2212 | + } else { | |
| 2213 | + jQuery('#mainwp-test-connection-modal').modal('setting', 'closable', false).modal('show'); | |
| 2214 | + jQuery('#mainwp-test-connection-modal .dimmer').show(); | |
| 2215 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').hide(); | |
| 1843 | 2216 | |
| 1844 | - var data = mainwp_secure_data({ | |
| 1845 | - action: 'mainwp_ext_applypluginsettings', | |
| 1846 | - ext_dir_slug: extSlug, | |
| 1847 | - siteId: pSiteId | |
| 1848 | - }); | |
| 2217 | + let clean_url = jQuery('#mainwp_managesites_add_wpurl').val().trim(); | |
| 2218 | + let protocol = jQuery('#mainwp_managesites_add_wpurl_protocol').val(); | |
| 2219 | + let url = protocol + '://' + clean_url; | |
| 1849 | 2220 | |
| 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; | |
| 2221 | + if (!url.endsWith('/')) { | |
| 2222 | + url += '/'; | |
| 1861 | 2223 | } |
| 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 | 2224 | |
| 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); | |
| 2225 | + let data = mainwp_secure_data({ | |
| 2226 | + action: 'mainwp_testwp', | |
| 2227 | + url: url, | |
| 2228 | + test_verify_cert: jQuery('#mainwp_managesites_verify_certificate').is(':checked') ? 1 : 0, | |
| 2229 | + ssl_version: jQuery('#mainwp_managesites_add_ssl_version').val(), | |
| 2230 | + http_user: jQuery('#mainwp_managesites_add_http_user').val(), | |
| 2231 | + http_pass: jQuery('#mainwp_managesites_add_http_pass').val() | |
| 2232 | + }); | |
| 2233 | + | |
| 2234 | + jQuery.post(ajaxurl, data, function (response) { // NOSONAR - complex. | |
| 2235 | + jQuery('#mainwp-test-connection-modal .dimmer').hide(); | |
| 2236 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').removeClass('red green check times'); | |
| 2237 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(''); | |
| 2238 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(''); | |
| 2239 | + if (response.error) { | |
| 2240 | + if (response.httpCode) { | |
| 2241 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); | |
| 2242 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); | |
| 2243 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(MainWP.I18n.t('Connection failed!')); | |
| 2244 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(MainWP.I18n.t('URL:') + ' ' + response.host + ' - ' + MainWP.I18n.t('HTTP-code:') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '') + ' - ' + MainWP.I18n.t('Error message: ') + ' ' + response.error); | |
| 2245 | + } else { | |
| 2246 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); | |
| 2247 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); | |
| 2248 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(MainWP.I18n.t('Connection test failed.')); | |
| 2249 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(MainWP.I18n.t('Error message:') + ' ' + response.error); | |
| 2250 | + } | |
| 2251 | + } else if (response.httpCode) { | |
| 2252 | + if (response.httpCode == '200') { | |
| 2253 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); | |
| 2254 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('green check'); | |
| 2255 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(MainWP.I18n.t('Connection successful!')); | |
| 2256 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(MainWP.I18n.t('URL:') + ' ' + response.host + (response.ip === undefined ? '' : ' (IP: ' + response.ip + ')') + ' - ' + MainWP.I18n.t('Received HTTP-code') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '')); | |
| 2257 | + } else { | |
| 2258 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); | |
| 2259 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); | |
| 2260 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(MainWP.I18n.t('Connection test failed.')); | |
| 2261 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(MainWP.I18n.t('URL:') + ' ' + response.host + (response.ip === undefined ? '' : ' (IP: ' + response.ip + ')') + ' - ' + MainWP.I18n.t('Received HTTP-code:') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '')); | |
| 2262 | + } | |
| 2263 | + } else { | |
| 2264 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(''); | |
| 2265 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); | |
| 2266 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(MainWP.I18n.t('Connection test failed.')); | |
| 2267 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(MainWP.I18n.t('Invalid response from the server, please try again.')); | |
| 2268 | + } | |
| 2269 | + }, 'json'); | |
| 1891 | 2270 | } |
| 1892 | - bulkInstallCurrentThreads--; | |
| 1893 | - mainwp_managesites_sync_extension_start_next(pSiteId); | |
| 1894 | - }, 'json'); | |
| 1895 | -} | |
| 2271 | +}; | |
| 1896 | 2272 | |
| 1897 | -// Test Connection (Add Site Page) | |
| 1898 | -mainwp_managesites_test = function () { | |
| 2273 | +// Test Connection (Edit Site Page) | |
| 2274 | +let mainwp_managesites_edit_test = function () { | |
| 1899 | 2275 | |
| 1900 | - var errors = []; | |
| 2276 | + let clean_url = jQuery('#mainwp_managesites_edit_siteurl').val(); | |
| 2277 | + let protocol = jQuery('#mainwp_managesites_edit_siteurl_protocol').val(); | |
| 2278 | + let with_www = jQuery('input[name=mainwp_managesites_edit_wpurl_with_www]').val(); | |
| 2279 | + with_www = with_www === 'www' ? with_www + '.' : ''; | |
| 1901 | 2280 | |
| 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 | - } | |
| 2281 | + let url = protocol + '://' + with_www + clean_url; | |
| 1911 | 2282 | |
| 1912 | - if (!isUrl(url)) { | |
| 1913 | - errors.push(__('Please enter a valid URL for your site')); | |
| 2283 | + if (!url.endsWith('/')) { | |
| 2284 | + url += '/'; | |
| 1914 | 2285 | } |
| 1915 | - } | |
| 1916 | 2286 | |
| 1917 | - if (errors.length > 0) { | |
| 1918 | - feedback('mainwp-message-zone', errors.join('<br />'), 'red'); | |
| 1919 | - } else { | |
| 1920 | 2287 | jQuery('#mainwp-test-connection-modal').modal('setting', 'closable', false).modal('show'); |
| 1921 | 2288 | jQuery('#mainwp-test-connection-modal .dimmer').show(); |
| 1922 | 2289 | jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').hide(); |
| 1923 | 2290 | |
| 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() | |
| 2291 | + let data = mainwp_secure_data({ | |
| 2292 | + action: 'mainwp_testwp', | |
| 2293 | + url: url, | |
| 2294 | + test_verify_cert: jQuery('#mainwp_managesites_edit_verifycertificate').val(), | |
| 2295 | + ssl_version: jQuery('#mainwp_managesites_edit_ssl_version').val(), | |
| 2296 | + http_user: jQuery('#mainwp_managesites_edit_http_user').val(), | |
| 2297 | + http_pass: jQuery('#mainwp_managesites_edit_http_pass').val() | |
| 1939 | 2298 | }); |
| 1940 | 2299 | |
| 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); | |
| 2300 | + jQuery.post(ajaxurl, data, function (response) { // NOSONAR - complex. | |
| 2301 | + jQuery('#mainwp-test-connection-modal .dimmer').hide(); | |
| 2302 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').removeClass('red green check times'); | |
| 2303 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(''); | |
| 2304 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(''); | |
| 2305 | + if (response.error) { | |
| 2306 | + if (response.httpCode) { | |
| 2307 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); | |
| 2308 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); | |
| 2309 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(MainWP.I18n.t('Connection failed!')); | |
| 2310 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(MainWP.I18n.t('URL:') + ' ' + response.host + ' - ' + MainWP.I18n.t('HTTP-code:') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '') + ' - ' + MainWP.I18n.t('Error message: ') + ' ' + response.error); | |
| 2311 | + } else { | |
| 2312 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); | |
| 2313 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); | |
| 2314 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(MainWP.I18n.t('Connection test failed.')); | |
| 2315 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(MainWP.I18n.t('Error message:') + ' ' + response.error); | |
| 2316 | + } | |
| 2317 | + } else if (response.httpCode) { | |
| 2318 | + if (response.httpCode == '200') { | |
| 2319 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); | |
| 2320 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('green check'); | |
| 2321 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(MainWP.I18n.t('Connection successful!')); | |
| 2322 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(MainWP.I18n.t('URL:') + ' ' + response.host + (response.ip === undefined ? '' : ' (IP: ' + response.ip + ')') + ' - ' + MainWP.I18n.t('Received HTTP-code') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '')); | |
| 2323 | + } else { | |
| 2324 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(); | |
| 2325 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); | |
| 2326 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(MainWP.I18n.t('Connection test failed.')); | |
| 2327 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(MainWP.I18n.t('URL:') + ' ' + response.host + (response.ip === undefined ? '' : ' (IP: ' + response.ip + ')') + ' - ' + MainWP.I18n.t('Received HTTP-code:') + ' ' + response.httpCode + (response.httpCodeString ? ' (' + response.httpCodeString + ')' : '')); | |
| 2328 | + } | |
| 1952 | 2329 | } 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); | |
| 2330 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result').show(''); | |
| 2331 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result i').addClass('red times'); | |
| 2332 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content span').html(MainWP.I18n.t('Connection test failed.')); | |
| 2333 | + jQuery('#mainwp-test-connection-modal .content #mainwp-test-connection-result .content .sub.header').html(MainWP.I18n.t('Invalid response from the server, please try again.')); | |
| 1957 | 2334 | } |
| 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 | 2335 | }, 'json'); |
| 1977 | - } | |
| 1978 | 2336 | }; |
| 1979 | 2337 | |
| 1980 | -// Test Connection (Edit Site Page) | |
| 1981 | -mainwp_managesites_edit_test = function () { | |
| 2338 | +let managesites_remove = function (obj) { | |
| 2339 | + managesites_init(); | |
| 1982 | 2340 | |
| 1983 | - var clean_url = jQuery('#mainwp_managesites_edit_siteurl').val(); | |
| 1984 | - var protocol = jQuery('#mainwp_managesites_edit_siteurl_protocol').val(); | |
| 2341 | + let name = jQuery(obj).attr('site-name'); | |
| 2342 | + let id = jQuery(obj).attr('site-id'); | |
| 1985 | 2343 | |
| 1986 | - url = protocol + '://' + clean_url; | |
| 2344 | + let msg = MainWP.I18n.t('Are you sure you want to remove') + ' ' + name + ' ' + MainWP.I18n.t('from your MainWP Dashboard?'); | |
| 1987 | 2345 | |
| 1988 | - if (url.substr(-1) != '/') { | |
| 1989 | - url += '/'; | |
| 1990 | - } | |
| 2346 | + mainwp_confirm(msg, function () { | |
| 2347 | + 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>'); | |
| 2348 | + let data = mainwp_secure_data({ | |
| 2349 | + action: 'mainwp_removesite', | |
| 2350 | + id: id | |
| 2351 | + }); | |
| 1991 | 2352 | |
| 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(); | |
| 2353 | + jQuery.post(ajaxurl, data, function (response) { | |
| 1995 | 2354 | |
| 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 | - }); | |
| 2355 | + managesites_init(); | |
| 2004 | 2356 | |
| 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 | -}; | |
| 2357 | + let result = ''; | |
| 2358 | + let error = ''; | |
| 2042 | 2359 | |
| 2043 | -managesites_remove = function (obj) { | |
| 2044 | - managesites_init(); | |
| 2360 | + if (response.error != undefined) { | |
| 2361 | + error = response.error; | |
| 2362 | + } else if (response.result == 'SUCCESS') { | |
| 2363 | + result = '<i class="close icon"></i>' + MainWP.I18n.t('The site has been removed and the MainWP Child plugin has been disabled.'); | |
| 2364 | + } else if (response.result == 'NOSITE') { | |
| 2365 | + error = '<i class="close icon"></i>' + MainWP.I18n.t('The requested site has not been found.'); | |
| 2366 | + } else { | |
| 2367 | + result = '<i class="close icon"></i>' + MainWP.I18n.t('The site has been removed. Please make sure that the MainWP Child plugin has been deactivated properly.'); | |
| 2368 | + } | |
| 2045 | 2369 | |
| 2046 | - var name = jQuery(obj).attr('site-name'); | |
| 2047 | - var id = jQuery(obj).attr('site-id'); | |
| 2370 | + if (error != '') { | |
| 2371 | + feedback('mainwp-message-zone', error, 'red'); | |
| 2372 | + } | |
| 2048 | 2373 | |
| 2049 | - var msg = sprintf(__('Are you sure you want to remove %1 from your MainWP Dashboard?', name)); | |
| 2374 | + if (result != '') { | |
| 2375 | + feedback('mainwp-message-zone', result, 'green'); | |
| 2376 | + } | |
| 2050 | 2377 | |
| 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 | - }); | |
| 2378 | + jQuery('tr#child-site-' + id).remove(); | |
| 2057 | 2379 | |
| 2058 | - jQuery.post(ajaxurl, data, function (response) { | |
| 2380 | + }, 'json'); | |
| 2381 | + }, false, false, false, 'REMOVE'); | |
| 2382 | + return false; | |
| 2383 | +}; | |
| 2059 | 2384 | |
| 2060 | - managesites_init(); | |
| 2385 | +jQuery(function () { | |
| 2061 | 2386 | |
| 2062 | - var result = ''; | |
| 2063 | - var error = ''; | |
| 2387 | + jQuery(document).on('click', '#mainwp_managesites_add', function () { | |
| 2388 | + mainwp_managesites_add(); | |
| 2389 | + }); | |
| 2064 | 2390 | |
| 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 | - } | |
| 2391 | + // Hanlde click submit form import website | |
| 2392 | + jQuery(document).on('click', '#mainwp_managesites_bulkadd', function () { | |
| 2074 | 2393 | |
| 2075 | - if (error != '') { | |
| 2076 | - feedback('mainwp-message-zone', error, 'red'); | |
| 2077 | - } | |
| 2394 | + let error_messages = mainwp_managesites_import_handle_form_before_submit(); | |
| 2395 | + // If there is an error, prevent submission and display the error | |
| 2396 | + if (error_messages.length > 0) { | |
| 2397 | + feedback('mainwp-message-zone', error_messages.join("<br/>"), "red"); | |
| 2398 | + } else { | |
| 2399 | + jQuery('#mainwp_managesites_bulkadd_form').submit(); | |
| 2400 | + } | |
| 2401 | + return false; | |
| 2402 | + }); | |
| 2078 | 2403 | |
| 2079 | - if (result != '') { | |
| 2080 | - feedback('mainwp-message-zone', result, 'green'); | |
| 2081 | - } | |
| 2404 | + // Trigger Connection Test (Add Site Page) | |
| 2405 | + jQuery(document).on('click', '#mainwp_managesites_test', function () { | |
| 2406 | + mainwp_managesites_test(); | |
| 2407 | + }); | |
| 2082 | 2408 | |
| 2083 | - jQuery('tr#child-site-' + id).remove(); | |
| 2409 | + // Trigger Connection Test (Edit Site Page) | |
| 2410 | + jQuery(document).on('click', '#mainwp_managesites_edit_test', function () { | |
| 2411 | + mainwp_managesites_edit_test(); | |
| 2412 | + }); | |
| 2084 | 2413 | |
| 2085 | - }, 'json'); | |
| 2086 | - }, false, false, false, 'REMOVE'); | |
| 2087 | - return false; | |
| 2088 | -}; | |
| 2414 | + // Use detected URL (Edit Site Page): set the protocol and www selectors to the child-reported address; no autosave. | |
| 2415 | + jQuery(document).on('click', '#mainwp_managesites_edit_use_detected', function () { | |
| 2416 | + let scheme = jQuery(this).attr('data-scheme'); | |
| 2417 | + let with_www = jQuery(this).attr('data-www'); | |
| 2418 | + if (scheme === 'http' || scheme === 'https') { | |
| 2419 | + jQuery('#mainwp_managesites_edit_siteurl_protocol').dropdown('set selected', scheme); | |
| 2420 | + } | |
| 2421 | + if (with_www === 'www' || with_www === 'none-www') { | |
| 2422 | + jQuery('#mainwp-edit-site-edit-url-www').dropdown('set selected', with_www); | |
| 2423 | + } | |
| 2424 | + return false; | |
| 2425 | + }); | |
| 2089 | 2426 | |
| 2090 | -jQuery(document).ready(function () { | |
| 2427 | + // Handle submit add multi website | |
| 2428 | + jQuery(document).on('click', '#mainwp_managesites_add_multi_site', function () { | |
| 2429 | + let error_messages = []; | |
| 2430 | + let has_table_data = false; | |
| 2431 | + has_table_data = mainwp_managesites_validate_import_rows(error_messages, true); | |
| 2432 | + // If there is an error, prevent submission and display the error | |
| 2433 | + if (error_messages.length > 0 && !has_table_data) { | |
| 2434 | + feedback('mainwp-add-multi-new-site-message-zone', error_messages.join("<br/>"), "red"); | |
| 2435 | + } else { | |
| 2436 | + jQuery('#mainwp_managesites_add_form').submit(); | |
| 2437 | + } | |
| 2438 | + return false; | |
| 2439 | + }); | |
| 2091 | 2440 | |
| 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 | - | |
| 2441 | + // Handle click remove website on management webiste. | |
| 2442 | + jQuery(document).on('click', '#mainwp-managesites-remove-site', function () { | |
| 2443 | + jQuery('#mainwp-remove-site-button').trigger('click'); | |
| 2444 | + }); | |
| 2115 | 2445 | }); |
| 2116 | 2446 | |
| 2117 | 2447 | /** |
| 2118 | 2448 | * Add new user |
| 2119 | 2449 | */ |
| 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 | - }); | |
| 2450 | +function mainwp_gen_passsword(len = 24) { | |
| 2451 | + const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+{}[]<>?'; | |
| 2452 | + const arr = new Uint32Array(len); | |
| 2453 | + crypto.getRandomValues(arr); | |
| 2454 | + return Array.from(arr, x => chars[x % chars.length]).join(''); | |
| 2455 | +} | |
| 2456 | + | |
| 2457 | +jQuery('.mainwp-generate-password-button').on('click', function (e) { | |
| 2458 | + e.preventDefault(); | |
| 2459 | + jQuery('#createuser #password, #mainwp-update-admin-password-form #password').val(mainwp_gen_passsword(24)).trigger('change'); | |
| 2127 | 2460 | }); |
| 2128 | 2461 | |
| 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 | - } | |
| 2462 | +jQuery(function () { | |
| 2463 | + jQuery(document).on('click', '#bulk_add_createuser', function () { | |
| 2464 | + mainwp_createuser(); | |
| 2465 | + }); | |
| 2466 | + jQuery('#bulk_import_createuser').on('click', function () { | |
| 2467 | + mainwp_bulkupload_users(); | |
| 2468 | + }); | |
| 2469 | +}); | |
| 2135 | 2470 | |
| 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 | - } | |
| 2471 | +let mainwp_createuser = function () { | |
| 2472 | + let cont = true; | |
| 2473 | + if (jQuery('#user_login').val() == '') { | |
| 2474 | + feedback('mainwp-message-zone', MainWP.I18n.t('Username field is required! Please enter a username.'), 'yellow'); | |
| 2475 | + cont = false; | |
| 2476 | + } | |
| 2140 | 2477 | |
| 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 | - } | |
| 2478 | + if (jQuery('#email').val() == '') { | |
| 2479 | + feedback('mainwp-message-zone', MainWP.I18n.t('E-mail field is required! Please enter an email address.'), 'yellow'); | |
| 2480 | + cont = false; | |
| 2481 | + } | |
| 2145 | 2482 | |
| 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; | |
| 2483 | + if (jQuery('#password').val() == '') { | |
| 2484 | + feedback('mainwp-message-zone', MainWP.I18n.t('Password field is required! Please enter the wanted password or generate a random one.'), 'yellow'); | |
| 2485 | + cont = false; | |
| 2154 | 2486 | } |
| 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 | 2487 | |
| 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 | - }); | |
| 2488 | + let selected_sites = []; | |
| 2489 | + let selected_clients = []; | |
| 2490 | + let selected_groups = []; | |
| 2197 | 2491 | |
| 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 | - } | |
| 2492 | + if (jQuery('input[name="select_by"]').val() == 'site') { | |
| 2493 | + jQuery("input[name='selected_sites[]']:checked").each(function () { | |
| 2494 | + selected_sites.push(jQuery(this).val()); | |
| 2495 | + }); | |
| 2496 | + if (selected_sites.length == 0) { | |
| 2497 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website or group or client.'), 'yellow'); | |
| 2498 | + cont = false; | |
| 2215 | 2499 | } |
| 2216 | - } else { | |
| 2217 | - jQuery('#mainwp-add-new-user-form').append(response); | |
| 2218 | - jQuery('#mainwp-creating-new-user-modal').modal('setting', 'closable', false).modal('show'); | |
| 2500 | + } else if (jQuery('input[name="select_by"]').val() == 'client') { | |
| 2501 | + jQuery("input[name='selected_clients[]']:checked").each(function () { | |
| 2502 | + selected_clients.push(jQuery(this).val()); | |
| 2503 | + }); | |
| 2504 | + if (selected_clients.length == 0) { | |
| 2505 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website or group or client.'), 'yellow'); | |
| 2506 | + cont = false; | |
| 2507 | + } | |
| 2508 | + } else { | |
| 2509 | + jQuery("input[name='selected_groups[]']:checked").each(function () { | |
| 2510 | + selected_groups.push(jQuery(this).val()); | |
| 2511 | + }); | |
| 2512 | + if (selected_groups.length == 0) { | |
| 2513 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website or group or client.'), 'yellow'); | |
| 2514 | + cont = false; | |
| 2515 | + } | |
| 2516 | + } | |
| 2219 | 2517 | |
| 2220 | - } | |
| 2221 | - }); | |
| 2222 | - } | |
| 2518 | + if (cont) { | |
| 2519 | + mainwp_set_message_zone('#mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Creating the user. Please wait...'), '', true); | |
| 2520 | + jQuery('#bulk_add_createuser').attr('disabled', 'disabled'); | |
| 2521 | + const is_send_password = jQuery('#send_password').is(':checked') ? 1 : 0; | |
| 2522 | + //Add user via ajax!! | |
| 2523 | + let data = mainwp_secure_data({ | |
| 2524 | + action: "mainwp_bulkadduser", | |
| 2525 | + select_by: jQuery("input[name='select_by']").val(), | |
| 2526 | + "selected_groups[]": selected_groups, | |
| 2527 | + "selected_sites[]": selected_sites, | |
| 2528 | + "selected_clients[]": selected_clients, | |
| 2529 | + user_login: jQuery("#user_login").val(), | |
| 2530 | + email: jQuery("#email").val(), | |
| 2531 | + url: jQuery("#url").val(), | |
| 2532 | + first_name: jQuery("#first_name").val(), | |
| 2533 | + last_name: jQuery("#last_name").val(), | |
| 2534 | + pass1: jQuery("#password").val(), | |
| 2535 | + pass2: jQuery("#password").val(), | |
| 2536 | + send_password: is_send_password, | |
| 2537 | + role: jQuery("#role").val(), | |
| 2538 | + }); | |
| 2539 | + | |
| 2540 | + jQuery.post(ajaxurl, data, function (response) { | |
| 2541 | + response = response.trim(); | |
| 2542 | + mainwp_set_message_zone('#mainwp-message-zone'); | |
| 2543 | + jQuery('#bulk_add_createuser').prop("disabled", false); | |
| 2544 | + if (response.substring(0, 5) == 'ERROR') { | |
| 2545 | + let responseObj = JSON.parse(response.substring(6)); | |
| 2546 | + if (responseObj.error == undefined) { | |
| 2547 | + let errorMessageList = responseObj[1]; | |
| 2548 | + let errorMessage = ''; | |
| 2549 | + for (let iem of errorMessageList) { | |
| 2550 | + if (errorMessage != '') { | |
| 2551 | + errorMessage = errorMessage + "<br />"; | |
| 2552 | + } | |
| 2553 | + errorMessage = errorMessage + iem; | |
| 2554 | + } | |
| 2555 | + if (errorMessage != '') { | |
| 2556 | + feedback('mainwp-message-zone', errorMessage, 'red'); | |
| 2557 | + } | |
| 2558 | + } | |
| 2559 | + } else { | |
| 2560 | + jQuery('#mainwp-add-new-user-form').append(response); | |
| 2561 | + jQuery('#mainwp-creating-new-user-modal').modal({ | |
| 2562 | + closable: false, | |
| 2563 | + }).modal('show'); | |
| 2564 | + } | |
| 2565 | + }); | |
| 2566 | + } | |
| 2223 | 2567 | }; |
| 2224 | 2568 | |
| 2225 | 2569 | /** |
| 2226 | 2570 | * InstallPlugins/Themes |
| 2227 | 2571 | */ |
| 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 | - }); | |
| 2572 | +jQuery(function () { | |
| 2573 | + jQuery('#MainWPInstallBulkNavSearch').on('click', function (event) { | |
| 2574 | + event.preventDefault(); | |
| 2575 | + jQuery('#mainwp_plugin_bulk_install_btn').attr('bulk-action', 'install'); | |
| 2576 | + jQuery('.mainwp-bulk-install-showhide-content').hide(); | |
| 2577 | + jQuery('.mainwp-browse-plugins').show(); | |
| 2578 | + jQuery('#mainwp-search-plugins-form').show(); | |
| 2579 | + jQuery('.mainwp-bulk-install-tabs-header-btn').removeClass('green'); | |
| 2580 | + jQuery(this).addClass('green'); | |
| 2581 | + }); | |
| 2582 | + jQuery('#MainWPInstallBulkNavUpload').on('click', function (event) { | |
| 2583 | + event.preventDefault(); | |
| 2584 | + jQuery('#mainwp_plugin_bulk_install_btn').attr('bulk-action', 'upload'); | |
| 2585 | + jQuery('.mainwp-bulk-install-showhide-content').hide(); | |
| 2586 | + jQuery('.mainwp-upload-plugin').show(); | |
| 2587 | + jQuery('.mainwp-bulk-install-tabs-header-btn').removeClass('green'); | |
| 2588 | + jQuery(this).addClass('green'); | |
| 2589 | + }); | |
| 2243 | 2590 | |
| 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 | - }); | |
| 2591 | + // not used? | |
| 2592 | + jQuery(document).on('click', '.filter-links li.plugin-install a', function (event) { | |
| 2593 | + event.preventDefault(); | |
| 2594 | + jQuery('.filter-links li.plugin-install a').removeClass('current'); | |
| 2595 | + jQuery(this).addClass('current'); | |
| 2596 | + let tab = jQuery(this).parent().attr('tab'); | |
| 2597 | + if (tab == 'search') { | |
| 2598 | + mainwp_install_search(event); | |
| 2599 | + } else { | |
| 2600 | + jQuery('#mainwp_installbulk_s').val(''); | |
| 2601 | + jQuery('#mainwp_installbulk_tab').val(tab); | |
| 2602 | + mainwp_install_plugin_tab_search('tab:' + tab); | |
| 2603 | + } | |
| 2604 | + }); | |
| 2258 | 2605 | |
| 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')); | |
| 2606 | + jQuery(document).on('click', '#mainwp_plugin_bulk_install_btn', function () { | |
| 2607 | + let act = jQuery(this).attr('bulk-action'); | |
| 2608 | + if (act == 'install') { | |
| 2609 | + let selected = jQuery("input[type='radio'][name='install-plugin']:checked"); | |
| 2610 | + if (selected.length == 0) { | |
| 2611 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select plugin to install files.'), 'yellow'); | |
| 2612 | + } else { | |
| 2613 | + let selectedId = /^install-([^-]*)-(.*)$/.exec(selected.attr('id')); | |
| 2614 | + if (selectedId) { | |
| 2615 | + mainwp_install_bulk('plugin', selectedId[2], selected.attr('plugin-name')); | |
| 2616 | + } | |
| 2617 | + } | |
| 2618 | + } else if (act == 'upload') { | |
| 2619 | + mainwp_upload_bulk('plugins'); | |
| 2269 | 2620 | } |
| 2270 | - } | |
| 2271 | - } else if (act == 'upload') { | |
| 2272 | - mainwp_upload_bulk('plugins'); | |
| 2273 | - } | |
| 2274 | 2621 | |
| 2275 | - return false; | |
| 2276 | - }); | |
| 2622 | + return false; | |
| 2623 | + }); | |
| 2277 | 2624 | |
| 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 | - }); | |
| 2625 | + jQuery(document).on('click', '#mainwp_theme_bulk_install_btn', function () { | |
| 2626 | + let act = jQuery(this).attr('bulk-action'); | |
| 2627 | + if (act == 'install') { | |
| 2628 | + let selected = jQuery("input[type='radio'][name='install-theme']:checked"); | |
| 2629 | + if (selected.length == 0) { | |
| 2630 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select theme to install files.'), 'yellow'); | |
| 2631 | + } else { | |
| 2632 | + let selectedId = /^install-([^-]*)-(.*)$/.exec(selected.attr('id')); | |
| 2633 | + if (selectedId) | |
| 2634 | + mainwp_install_bulk('theme', selectedId[2], selected.attr('theme-name')); | |
| 2635 | + } | |
| 2636 | + } else if (act == 'upload') { | |
| 2637 | + mainwp_upload_bulk('themes'); | |
| 2638 | + } | |
| 2639 | + return false; | |
| 2640 | + }); | |
| 2294 | 2641 | }); |
| 2295 | 2642 | |
| 2296 | 2643 | // 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; | |
| 2644 | +globalThis.mainwp_links_visit_site_and_admin = function (url, siteId) { | |
| 2645 | + let links = ''; | |
| 2646 | + if (url != '') { | |
| 2647 | + links += '<a href="' + url + '" target="_blank" class="mainwp-may-hide-referrer"><i class="external alternate icon"></i></a> '; | |
| 2648 | + } | |
| 2649 | + links += '<a href="admin.php?page=SiteOpen&newWindow=yes&websiteid=' + siteId + '&_opennonce=' + mainwpParams._wpnonce + '" target="_blank"><i class="sign in alternate icon"></i></a>'; | |
| 2650 | + return links; | |
| 2304 | 2651 | } |
| 2305 | 2652 | |
| 2306 | -bulkInstallTotal = 0; | |
| 2653 | +mainwpVars.bulkInstallTotal = 0; | |
| 2307 | 2654 | bulkInstallDone = 0; |
| 2308 | 2655 | |
| 2309 | 2656 | /** |
| 2310 | 2657 | * Install Plugin/Theme from WP.org. |
| @@ -2315,100 +2662,98 @@ | ||
| 2315 | 2662 | * @param string slug Plugin or theme slug. |
| 2316 | 2663 | * |
| 2317 | 2664 | * @return void |
| 2318 | 2665 | */ |
| 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>'; | |
| 2666 | +let mainwp_install_bulk = function (type, slug, name) { | |
| 2667 | + let data = mainwp_secure_data({ | |
| 2668 | + action: 'mainwp_preparebulkinstallplugintheme', | |
| 2669 | + type: type, | |
| 2670 | + slug: slug, | |
| 2671 | + name: name, | |
| 2672 | + selected_by: jQuery('input[name="select_by"]').val() | |
| 2673 | + }); | |
| 2674 | + let 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 | 2675 | |
| 2329 | - if (jQuery('#select_by').val() == 'site') { | |
| 2676 | + if (jQuery('input[name="select_by"]').val() == 'site') { | |
| 2330 | 2677 | |
| 2331 | - var selected_sites = []; | |
| 2678 | + let selected_sites = []; | |
| 2332 | 2679 | |
| 2333 | - jQuery("input[name='selected_sites[]']:checked").each(function () { | |
| 2334 | - selected_sites.push(jQuery(this).val()); | |
| 2335 | - }); | |
| 2680 | + jQuery("input[name='selected_sites[]']:checked").each(function () { | |
| 2681 | + selected_sites.push(jQuery(this).val()); | |
| 2682 | + }); | |
| 2336 | 2683 | |
| 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 | - } | |
| 2684 | + if (selected_sites.length == 0) { | |
| 2685 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website or a group or client.'), 'yellow'); | |
| 2686 | + return; | |
| 2687 | + } | |
| 2341 | 2688 | |
| 2342 | - data['selected_sites[]'] = selected_sites; | |
| 2689 | + data['selected_sites[]'] = selected_sites; | |
| 2343 | 2690 | |
| 2344 | - } else if (jQuery('#select_by').val() == 'client') { | |
| 2691 | + } else if (jQuery('input[name="select_by"]').val() == 'client') { | |
| 2345 | 2692 | |
| 2346 | - var selected_clients = []; | |
| 2693 | + let selected_clients = []; | |
| 2347 | 2694 | |
| 2348 | - jQuery("input[name='selected_clients[]']:checked").each(function () { | |
| 2349 | - selected_clients.push(jQuery(this).val()); | |
| 2350 | - }); | |
| 2695 | + jQuery("input[name='selected_clients[]']:checked").each(function () { | |
| 2696 | + selected_clients.push(jQuery(this).val()); | |
| 2697 | + }); | |
| 2351 | 2698 | |
| 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 | - } | |
| 2699 | + if (selected_clients.length == 0) { | |
| 2700 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website or a group or client.'), 'yellow'); | |
| 2701 | + return; | |
| 2702 | + } | |
| 2356 | 2703 | |
| 2357 | - data['selected_clients[]'] = selected_clients; | |
| 2704 | + data['selected_clients[]'] = selected_clients; | |
| 2358 | 2705 | |
| 2359 | - } else { | |
| 2360 | - var selected_groups = []; | |
| 2706 | + } else { | |
| 2707 | + let selected_groups = []; | |
| 2361 | 2708 | |
| 2362 | - jQuery("input[name='selected_groups[]']:checked").each(function () { | |
| 2363 | - selected_groups.push(jQuery(this).val()); | |
| 2364 | - }); | |
| 2709 | + jQuery("input[name='selected_groups[]']:checked").each(function () { | |
| 2710 | + selected_groups.push(jQuery(this).val()); | |
| 2711 | + }); | |
| 2365 | 2712 | |
| 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 | - } | |
| 2713 | + if (selected_groups.length == 0) { | |
| 2714 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website or a group or client.'), 'yellow'); | |
| 2715 | + return; | |
| 2716 | + } | |
| 2370 | 2717 | |
| 2371 | - data['selected_groups[]'] = selected_groups; | |
| 2718 | + data['selected_groups[]'] = selected_groups; | |
| 2372 | 2719 | |
| 2373 | - } | |
| 2720 | + } | |
| 2374 | 2721 | |
| 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">'; | |
| 2722 | + jQuery('#plugintheme-installation-queue').html(placeholder); | |
| 2723 | + jQuery.post(ajaxurl, data, function (type, activatePlugin, overwrite) { | |
| 2724 | + return function (response) { | |
| 2725 | + let installQueueContent = ''; | |
| 2726 | + bulkInstallDone = 0; | |
| 2727 | + installQueueContent += '<div id="bulk_install_info"></div>'; | |
| 2728 | + installQueueContent += '<div class="ui middle aligned divided list">'; | |
| 2382 | 2729 | |
| 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 | - } | |
| 2730 | + for (let siteId in response.sites) { | |
| 2731 | + let site = response.sites[siteId]; | |
| 2732 | + installQueueContent += | |
| 2733 | + '<div class="siteBulkInstall item" siteid="' + siteId + '" status="queue">' + | |
| 2734 | + '<div class="right floated content">' + | |
| 2735 | + '<span class="queue" data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Queued') + '"><i class="clock outline icon"></i></span>' + | |
| 2736 | + '<span class="progress" data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Installing...') + '" style="display:none"><i class="notched circle loading icon"></i></span>' + | |
| 2737 | + '<span class="status"></span>' + | |
| 2738 | + '</div>' + | |
| 2739 | + '<div class="content">' + mainwp_links_visit_site_and_admin('', siteId) + ' ' + '<a href="' + site['url'] + '">' + site.name.replace(/\\(.)/g, '$1') + '</a></div>' + // NOSONAR - no safe replaceAll alternative. | |
| 2740 | + '</div>'; | |
| 2741 | + mainwpVars.bulkInstallTotal++; | |
| 2742 | + } | |
| 2396 | 2743 | |
| 2397 | - installQueueContent += '</div>'; | |
| 2744 | + installQueueContent += '</div>'; | |
| 2398 | 2745 | |
| 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'); | |
| 2746 | + jQuery('#plugintheme-installation-queue').html(installQueueContent); | |
| 2747 | + jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').progress({ value: 0, total: mainwpVars.bulkInstallTotal }); | |
| 2748 | + mainwp_install_bulk_start_next(type, response.url, activatePlugin, overwrite, slug, response); | |
| 2749 | + } | |
| 2750 | + }(type, jQuery('#chk_activate_plugin').is(':checked'), jQuery('#chk_overwrite').is(':checked')), 'json'); | |
| 2404 | 2751 | |
| 2405 | - jQuery('#plugintheme-installation-progress-modal').modal('setting', 'closable', false).modal('show'); | |
| 2752 | + jQuery('#plugintheme-installation-progress-modal').modal('setting', 'closable', false).modal('show'); | |
| 2406 | 2753 | |
| 2407 | 2754 | }; |
| 2408 | 2755 | |
| 2409 | -bulkInstallMaxThreads = mainwpParams['maximumInstallUpdateRequests'] == undefined ? 3 : mainwpParams['maximumInstallUpdateRequests']; | |
| 2410 | -bulkInstallCurrentThreads = 0; | |
| 2411 | 2756 | |
| 2412 | 2757 | /** |
| 2413 | 2758 | * Install Plugin/Theme from WP.org. |
| 2414 | 2759 | * |
| @@ -2420,32 +2765,32 @@ | ||
| 2420 | 2765 | * @param bool overwrite Determines if the item should overwrite exisitng version. |
| 2421 | 2766 | * |
| 2422 | 2767 | * @return void |
| 2423 | 2768 | */ |
| 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')); | |
| 2769 | +let mainwp_install_bulk_start_next = function (type, url, activatePlugin, overwrite, slug, installResults) { // NOSONAR - complex. | |
| 2770 | + while ((siteToInstall = jQuery('.siteBulkInstall[status="queue"]:first')) && (siteToInstall.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { // NOSONAR - modified outside the function. | |
| 2771 | + mainwp_install_bulk_start_specific(type, url, activatePlugin, overwrite, siteToInstall, slug, installResults); | |
| 2772 | + } | |
| 2773 | + if (bulkInstallDone == mainwpVars.bulkInstallTotal && mainwpVars.bulkInstallTotal != 0) { | |
| 2774 | + jQuery('#bulk_install_info').before('<div class="ui info message">' + mainwp_install_bulk_you_know_msg(type, 1) + '</div>'); | |
| 2775 | + if (jQuery('.mainwp-cost-tracker-assistant-add-to-cost-tracker-button').length > 0) { // to support add to cost tracker pro. | |
| 2776 | + if (installResults.add_to_cost_tracker_id != undefined) { | |
| 2777 | + if (installResults.add_to_cost_tracker_id > 0) { | |
| 2778 | + jQuery('.mainwp-cost-tracker-assistant-add-to-cost-tracker-button').text(_('Edit Cost Tracker')); | |
| 2779 | + jQuery('#mainwp-cost-tracker-assistant-add-to-tracker-modal .header').text(_('Edit Cost Tracker')); | |
| 2780 | + } | |
| 2781 | + jQuery('.mainwp-cost-tracker-assistant-add-to-cost-tracker-button').attr('disabled', false); | |
| 2782 | + jQuery('.mainwp-cost-tracker-assistant-add-to-cost-tracker-button').removeClass('disabled'); | |
| 2783 | + jQuery('.mainwp-cost-tracker-assistant-add-to-cost-tracker-button').attr('item-slug', slug); | |
| 2784 | + jQuery('.mainwp-cost-tracker-assistant-add-to-cost-tracker-button').attr('item-type', type); | |
| 2785 | + jQuery('.mainwp-cost-tracker-assistant-add-to-cost-tracker-button').attr('item-name', installResults.name); | |
| 2786 | + jQuery('.mainwp-cost-tracker-assistant-add-to-cost-tracker-button').attr('cost-id', installResults.add_to_cost_tracker_id); | |
| 2787 | + if (installResults.installed_sites != undefined) { | |
| 2788 | + jQuery('.mainwp-cost-tracker-assistant-add-to-cost-tracker-button').attr('installed-sites', installResults.installed_sites.join(',')); | |
| 2789 | + } | |
| 2790 | + } | |
| 2435 | 2791 | } |
| 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 | 2792 | } |
| 2447 | - } | |
| 2448 | 2793 | }; |
| 2449 | 2794 | |
| 2450 | 2795 | /** |
| 2451 | 2796 | * Install Plugin/Theme from WP.org. |
| @@ -2459,92 +2804,86 @@ | ||
| 2459 | 2804 | * @param object siteToInstall Site to install the item to. |
| 2460 | 2805 | * |
| 2461 | 2806 | * @return void |
| 2462 | 2807 | */ |
| 2463 | -mainwp_install_bulk_start_specific = function (type, url, activatePlugin, overwrite, siteToInstall, slug, installResults) { | |
| 2464 | - bulkInstallCurrentThreads++; | |
| 2808 | +let mainwp_install_bulk_start_specific = function (type, url, activatePlugin, overwrite, siteToInstall, slug, installResults) { | |
| 2809 | + bulkInstallCurrentThreads++; | |
| 2465 | 2810 | |
| 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 | - }); | |
| 2811 | + siteToInstall.attr('status', 'progress'); | |
| 2812 | + siteToInstall.find('.queue').hide(); | |
| 2813 | + siteToInstall.find('.progress').show(); | |
| 2814 | + let data = mainwp_secure_data({ | |
| 2815 | + action: 'mainwp_installbulkinstallplugintheme', | |
| 2816 | + type: type, | |
| 2817 | + url: url, | |
| 2818 | + activatePlugin: activatePlugin, | |
| 2819 | + overwrite: overwrite, | |
| 2820 | + siteId: siteToInstall.attr('siteid') | |
| 2821 | + }); | |
| 2477 | 2822 | |
| 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(); | |
| 2823 | + jQuery.post(ajaxurl, data, function (type, url, activatePlugin, overwrite, siteToInstall) { | |
| 2824 | + return function (response) { | |
| 2825 | + siteToInstall.attr('status', 'done'); | |
| 2826 | + siteToInstall.find('.progress').hide(); | |
| 2827 | + let statusEl = siteToInstall.find('.status'); | |
| 2828 | + statusEl.show(); | |
| 2829 | + let _error = ''; | |
| 2830 | + if (response.error != undefined) { | |
| 2831 | + statusEl.html(response.error); | |
| 2832 | + statusEl.css('color', 'red'); | |
| 2833 | + } else if (response?.ok[siteToInstall.attr('siteid')]) { | |
| 2834 | + statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Installation completed successfully.') + '"><i class="check green icon"></i></span>'); | |
| 2835 | + if (installResults.installed_sites == undefined) { | |
| 2836 | + installResults.installed_sites = []; | |
| 2837 | + } | |
| 2838 | + installResults.installed_sites.push(siteToInstall.attr('siteid')); | |
| 2839 | + } else if (response?.errors[siteToInstall.attr('siteid')]) { | |
| 2840 | + _error = response.errors[siteToInstall.attr('siteid')][1]; | |
| 2841 | + } else { | |
| 2842 | + _error = MainWP.I18n.t('Undefined error occurred. Please try again.'); | |
| 2843 | + } | |
| 2482 | 2844 | |
| 2483 | - var statusEl = siteToInstall.find('.status'); | |
| 2484 | - statusEl.show(); | |
| 2845 | + if (_error !== '') { | |
| 2846 | + statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + _error + '"><i class="times red icon"></i></span>'); | |
| 2847 | + } | |
| 2485 | 2848 | |
| 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 = []; | |
| 2849 | + bulkInstallCurrentThreads--; | |
| 2850 | + bulkInstallDone++; | |
| 2851 | + | |
| 2852 | + jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').progress('set progress', bulkInstallDone); | |
| 2853 | + jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').find('.label').html(bulkInstallDone + '/' + mainwpVars.bulkInstallTotal + ' ' + MainWP.I18n.t('Installed')); | |
| 2854 | + mainwp_install_bulk_start_next(type, url, activatePlugin, overwrite, slug, installResults); | |
| 2496 | 2855 | } |
| 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'); | |
| 2856 | + }(type, url, activatePlugin, overwrite, siteToInstall), 'json'); | |
| 2516 | 2857 | }; |
| 2517 | 2858 | |
| 2518 | 2859 | |
| 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>'); | |
| 2860 | +let mainwp_install_bulk_you_know_msg = function (type, total) { // NOSONAR - complex. | |
| 2861 | + let msg = ''; | |
| 2862 | + if (mainwpParams.installedBulkSettingsManager && mainwpParams.installedBulkSettingsManager == 1) { | |
| 2863 | + if (type == 'plugin') { | |
| 2864 | + if (total == 1) | |
| 2865 | + msg = MainWP.I18n.t('Would you like to use the Bulk Settings Manager with this plugin? Check out the %1Documentation%2.', '<a href="https://docs.mainwp.com/add-ons/administrative/bulk-settings-manager-extension" target="_blank">', '</a>'); // NOSONAR - noopener - open safe. | |
| 2866 | + else | |
| 2867 | + msg = MainWP.I18n.t('Would you like to use the Bulk Settings Manager with these plugins? Check out the %1Documentation%2.', '<a href="https://docs.mainwp.com/add-ons/administrative/bulk-settings-manager-extension" target="_blank">', '</a>'); // NOSONAR - noopener - open safe. | |
| 2868 | + } else if (type == 'theme') { | |
| 2869 | + if (total == 1) | |
| 2870 | + msg = MainWP.I18n.t('Would you like to use the Bulk Settings Manager with this theme? Check out the %1Documentation%2.', '<a href="https://docs.mainwp.com/add-ons/administrative/bulk-settings-manager-extension" target="_blank">', '</a>'); // NOSONAR - noopener - open safe. | |
| 2871 | + else | |
| 2872 | + msg = MainWP.I18n.t('Would you like to use the Bulk Settings Manager with these themes? Check out the %1Documentation%2.', '<a href="https://docs.mainwp.com/add-ons/administrative/bulk-settings-manager-extension" target="_blank">', '</a>'); // NOSONAR - noopener - open safe. | |
| 2873 | + } | |
| 2874 | + } else if (type == 'plugin') { | |
| 2875 | + if (total == 1) | |
| 2876 | + msg = MainWP.I18n.t('Did you know with the %1 you can control the settings of this plugin directly from your MainWP Dashboard?', '<a href="https://mainwp.com/add-on/bulk-settings-manager/" target="_blank">Bulk Settings Extension</a>'); // NOSONAR - noopener - open safe. | |
| 2877 | + else | |
| 2878 | + msg = MainWP.I18n.t('Did you know with the %1 you can control the settings of these plugins directly from your MainWP Dashboard?', '<a href="https://mainwp.com/add-on/bulk-settings-manager/" target="_blank">Bulk Settings Extension</a>'); // NOSONAR - noopener - open safe. | |
| 2879 | + } else if (type == 'theme') { | |
| 2880 | + if (total == 1) | |
| 2881 | + msg = MainWP.I18n.t('Did you know with the %1 you can control the settings of this theme directly from your MainWP Dashboard?', '<a href="https://mainwp.com/add-on/bulk-settings-manager/" target="_blank">Bulk Settings Extension</a>'); // NOSONAR - noopener - open safe. | |
| 2882 | + else | |
| 2883 | + msg = MainWP.I18n.t('Did you know with the %1 you can control the settings of these themes directly from your MainWP Dashboard?', '<a href="https://mainwp.com/add-on/bulk-settings-manager/" target="_blank">Bulk Settings Extension</a>'); // NOSONAR - noopener - open safe. | |
| 2532 | 2884 | } |
| 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; | |
| 2885 | + return msg; | |
| 2547 | 2886 | } |
| 2548 | 2887 | |
| 2549 | 2888 | /** |
| 2550 | 2889 | * Install Plugin/Theme by Upload. |
| @@ -2554,117 +2893,117 @@ | ||
| 2554 | 2893 | * @param string type Plugin or theme. |
| 2555 | 2894 | * |
| 2556 | 2895 | * @return void |
| 2557 | 2896 | */ |
| 2558 | -mainwp_upload_bulk = function (type) { | |
| 2897 | +let mainwp_upload_bulk = function (type) { | |
| 2559 | 2898 | |
| 2560 | - if (type == 'plugins') { | |
| 2561 | - type = 'plugin'; | |
| 2562 | - } else { | |
| 2563 | - type = 'theme'; | |
| 2564 | - } | |
| 2899 | + if (type == 'plugins') { | |
| 2900 | + type = 'plugin'; | |
| 2901 | + } else { | |
| 2902 | + type = 'theme'; | |
| 2903 | + } | |
| 2565 | 2904 | |
| 2566 | - var files = []; | |
| 2905 | + let files = []; | |
| 2567 | 2906 | |
| 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 | - }); | |
| 2907 | + jQuery(".qq-upload-file").each(function () { | |
| 2908 | + if (jQuery(this).closest('.file-uploaded-item').hasClass('qq-upload-success')) { | |
| 2909 | + files.push(jQuery(this).attr('filename')); | |
| 2910 | + } | |
| 2911 | + }); | |
| 2573 | 2912 | |
| 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'); | |
| 2913 | + if (files.length == 0) { | |
| 2914 | + if (type == 'plugin') { | |
| 2915 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please upload at least one plugin to install.'), 'yellow'); | |
| 2916 | + } else { | |
| 2917 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please upload at least one theme to install.'), 'yellow'); | |
| 2918 | + } | |
| 2919 | + return; | |
| 2579 | 2920 | } |
| 2580 | - return; | |
| 2581 | - } | |
| 2582 | 2921 | |
| 2583 | - var data = mainwp_secure_data({ | |
| 2584 | - action: 'mainwp_preparebulkuploadplugintheme', | |
| 2585 | - type: type, | |
| 2586 | - selected_by: jQuery('#select_by').val() | |
| 2587 | - }); | |
| 2922 | + let data = mainwp_secure_data({ | |
| 2923 | + action: 'mainwp_preparebulkuploadplugintheme', | |
| 2924 | + type: type, | |
| 2925 | + selected_by: jQuery('input[name="select_by"]').val() | |
| 2926 | + }); | |
| 2588 | 2927 | |
| 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>'; | |
| 2928 | + let 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 | 2929 | |
| 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 | - }); | |
| 2930 | + if (jQuery('input[name="select_by"]').val() == 'site') { | |
| 2931 | + let selected_sites = []; | |
| 2932 | + jQuery("input[name='selected_sites[]']:checked").each(function () { | |
| 2933 | + selected_sites.push(jQuery(this).val()); | |
| 2934 | + }); | |
| 2596 | 2935 | |
| 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 | - }); | |
| 2936 | + if (selected_sites.length == 0) { | |
| 2937 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website or a group or client.'), 'yellow'); | |
| 2938 | + return; | |
| 2939 | + } | |
| 2940 | + data['selected_sites[]'] = selected_sites; | |
| 2941 | + } else if (jQuery('input[name="select_by"]').val() == 'client') { | |
| 2942 | + let selected_clients = []; | |
| 2943 | + jQuery("input[name='selected_clients[]']:checked").each(function () { | |
| 2944 | + selected_clients.push(jQuery(this).val()); | |
| 2945 | + }); | |
| 2607 | 2946 | |
| 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; | |
| 2947 | + if (selected_clients.length == 0) { | |
| 2948 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website or a group or client.'), 'yellow'); | |
| 2949 | + return; | |
| 2950 | + } | |
| 2951 | + data['selected_clients[]'] = selected_clients; | |
| 2952 | + } else { | |
| 2953 | + let selected_groups = []; | |
| 2954 | + jQuery("input[name='selected_groups[]']:checked").each(function () { | |
| 2955 | + selected_groups.push(jQuery(this).val()); | |
| 2956 | + }); | |
| 2957 | + if (selected_groups.length == 0) { | |
| 2958 | + feedback('mainwp-message-zone', MainWP.I18n.t('Please select at least one website or a group or client.'), 'yellow'); | |
| 2959 | + return; | |
| 2960 | + } | |
| 2961 | + data['selected_groups[]'] = selected_groups; | |
| 2611 | 2962 | } |
| 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 | 2963 | |
| 2625 | - data['files[]'] = files; | |
| 2964 | + data['files[]'] = files; | |
| 2626 | 2965 | |
| 2627 | - jQuery('#plugintheme-installation-queue').html(placeholder); | |
| 2966 | + jQuery('#plugintheme-installation-queue').html(placeholder); | |
| 2628 | 2967 | |
| 2629 | - jQuery.post(ajaxurl, data, function (type, files, activatePlugin, overwrite) { | |
| 2630 | - return function (response) { | |
| 2631 | - var installQueue = ''; | |
| 2632 | - bulkInstallTotal = 0; | |
| 2633 | - bulkInstallDone = 0; | |
| 2968 | + jQuery.post(ajaxurl, data, function (type, files, activatePlugin, overwrite) { | |
| 2969 | + return function (response) { | |
| 2970 | + let installQueue = ''; | |
| 2971 | + mainwpVars.bulkInstallTotal = 0; | |
| 2972 | + bulkInstallDone = 0; | |
| 2634 | 2973 | |
| 2635 | - installQueue += '<div class="ui middle aligned selection divided list">'; | |
| 2974 | + installQueue += '<div class="ui middle aligned selection divided list">'; | |
| 2636 | 2975 | |
| 2637 | - for (var siteId in response.sites) { | |
| 2638 | - var site = response.sites[siteId]; | |
| 2976 | + for (let siteId in response.sites) { | |
| 2977 | + let site = response.sites[siteId]; | |
| 2639 | 2978 | |
| 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 | - } | |
| 2979 | + installQueue += | |
| 2980 | + '<div class="siteBulkInstall item" siteid="' + siteId + '" status="queue">' + | |
| 2981 | + '<div class="right floated content">' + | |
| 2982 | + '<span class="queue" data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Queued') + '"><i class="clock outline icon"></i></span>' + | |
| 2983 | + '<span class="progress" data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Installing...') + '" style="display:none"><i class="notched circle loading icon"></i></span>' + | |
| 2984 | + '<span class="status"></span>' + | |
| 2985 | + '</div>' + | |
| 2986 | + '<div class="content">' + mainwp_links_visit_site_and_admin('', siteId) + ' ' + '<a href="' + site['url'] + '">' + site.name.replace(/\\(.)/g, '$1') + '</a></div>' + // NOSONAR - no safe replaceAll alternative. | |
| 2987 | + '<div class="installation-entries"></div>' + | |
| 2988 | + '</div>'; | |
| 2989 | + mainwpVars.bulkInstallTotal++; | |
| 2990 | + } | |
| 2652 | 2991 | |
| 2653 | - installQueue += '</div>'; | |
| 2992 | + installQueue += '</div>'; | |
| 2654 | 2993 | |
| 2655 | - jQuery('#plugintheme-installation-queue').html(installQueue); | |
| 2994 | + jQuery('#plugintheme-installation-queue').html(installQueue); | |
| 2656 | 2995 | |
| 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'); | |
| 2996 | + jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').progress({ value: 0, total: mainwpVars.bulkInstallTotal }); | |
| 2997 | + mainwp_upload_bulk_start_next(type, response.urls, activatePlugin, overwrite); | |
| 2998 | + } | |
| 2999 | + }(type, files, jQuery('#chk_activate_plugin').is(':checked'), jQuery('#chk_overwrite').is(':checked')), 'json'); | |
| 2661 | 3000 | |
| 2662 | - jQuery('#plugintheme-installation-progress-modal').modal('setting', 'closable', false).modal('show'); | |
| 3001 | + jQuery('#plugintheme-installation-progress-modal').modal('setting', 'closable', false).modal('show'); | |
| 2663 | 3002 | |
| 2664 | - jQuery('.qq-upload-list').html(''); // empty files list! | |
| 3003 | + jQuery('.qq-upload-list').html(''); // empty files list! | |
| 2665 | 3004 | |
| 2666 | - return false; | |
| 3005 | + return false; | |
| 2667 | 3006 | }; |
| 2668 | 3007 | |
| 2669 | 3008 | /** |
| 2670 | 3009 | * Install Plugin/Theme by Upload. |
| @@ -2677,52 +3016,56 @@ | ||
| 2677 | 3016 | * @param bool overwrite Determines if the item should overwrite exisitng version. |
| 2678 | 3017 | * |
| 2679 | 3018 | * @return void |
| 2680 | 3019 | */ |
| 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 | - } | |
| 3020 | +let mainwp_upload_bulk_start_next = function (type, urls, activatePlugin, overwrite) { | |
| 3021 | + while ((siteToInstall = jQuery('.siteBulkInstall[status="queue"]:first')) && (siteToInstall.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { // NOSONAR - modified outside the function. | |
| 3022 | + mainwp_upload_bulk_start_specific(type, urls, activatePlugin, overwrite, siteToInstall); | |
| 3023 | + } | |
| 2685 | 3024 | |
| 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')); | |
| 3025 | + if ((siteToInstall.length == 0) && (bulkInstallCurrentThreads == 0)) { // NOSONAR - modified outside the function. | |
| 3026 | + let data = mainwp_secure_data({ | |
| 3027 | + action: 'mainwp_cleanbulkuploadplugintheme', | |
| 3028 | + }); | |
| 2692 | 3029 | |
| 2693 | - jQuery('#bulk_upload_info').html('<div class="mainwp-notice mainwp-notice-blue">' + msg + '</div>'); | |
| 3030 | + jQuery.post(ajaxurl, data, function () { | |
| 3031 | + jQuery('.file-uploaded-item.qq-upload-completed').remove(); | |
| 3032 | + }); | |
| 2694 | 3033 | |
| 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); | |
| 3034 | + let msg = mainwp_install_bulk_you_know_msg(type, jQuery('#bulk_upload_info').attr('number-files')); | |
| 3035 | + | |
| 3036 | + jQuery('#bulk_upload_info').html('<div class="bui blue message">' + msg + '</div>'); | |
| 3037 | + | |
| 3038 | + if (jQuery('.mainwp_cost_tracker_assistant_installed_items').length > 0) { // to support add to cost tracker pro. | |
| 3039 | + let cost_tracker_items = []; | |
| 3040 | + let cost_tracker_check_slugs = []; | |
| 3041 | + jQuery('.mainwp_cost_tracker_assistant_installed_items').each(function () { | |
| 3042 | + let slug = jQuery(this).attr('item-slug'); | |
| 3043 | + let items_slug = {}; | |
| 3044 | + if (!cost_tracker_check_slugs.includes(slug)) { | |
| 3045 | + cost_tracker_check_slugs.push(slug); | |
| 3046 | + let siteids = []; | |
| 3047 | + jQuery('.mainwp_cost_tracker_assistant_installed_items[item-slug="' + slug + '"]').each(function () { | |
| 3048 | + siteids.push(jQuery(this).attr('item-siteid')); | |
| 3049 | + }); | |
| 3050 | + items_slug.slug = slug; | |
| 3051 | + items_slug.name = jQuery(this).attr('item-name'); | |
| 3052 | + items_slug.type = jQuery(this).attr('item-type'); | |
| 3053 | + items_slug.cost_id = jQuery(this).attr('cost-id'); | |
| 3054 | + items_slug.sites_ids = siteids; | |
| 3055 | + cost_tracker_items.push(items_slug); | |
| 3056 | + } | |
| 3057 | + }); | |
| 3058 | + | |
| 3059 | + if (cost_tracker_items.length > 0) { | |
| 3060 | + jQuery('.mainwp-cost-tracker-assistant-add-buttons-wrapper').html(''); | |
| 3061 | + let multiAddTo = cost_tracker_items.length > 1 ? 1 : 0; | |
| 3062 | + cost_tracker_items.forEach(item => { | |
| 3063 | + 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) ? MainWP.I18n.t('Edit Cost Tracker') + ' (' + item.name + ')' : MainWP.I18n.t('Add to Cost Tracker') + ' (' + item.name + ')') + '</a>'); | |
| 3064 | + }); | |
| 3065 | + } | |
| 2713 | 3066 | } |
| 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 | 3067 | } |
| 2724 | - } | |
| 2725 | 3068 | }; |
| 2726 | 3069 | |
| 2727 | 3070 | /** |
| 2728 | 3071 | * Install Plugin/Theme by Upload. |
| @@ -2736,194 +3079,705 @@ | ||
| 2736 | 3079 | * @param object siteToInstall Site to install the item to. |
| 2737 | 3080 | * |
| 2738 | 3081 | * @return void |
| 2739 | 3082 | */ |
| 2740 | -mainwp_upload_bulk_start_specific = function (type, urls, activatePlugin, overwrite, siteToInstall) { | |
| 2741 | - bulkInstallCurrentThreads++; | |
| 2742 | - siteToInstall.attr('status', 'progress'); | |
| 3083 | +let mainwp_upload_bulk_start_specific = function (type, urls, activatePlugin, overwrite, siteToInstall) { | |
| 3084 | + bulkInstallCurrentThreads++; | |
| 3085 | + siteToInstall.attr('status', 'progress'); | |
| 2743 | 3086 | |
| 2744 | - siteToInstall.find('.queue').hide(); | |
| 2745 | - siteToInstall.find('.progress').show(); | |
| 3087 | + siteToInstall.find('.queue').hide(); | |
| 3088 | + siteToInstall.find('.progress').show(); | |
| 2746 | 3089 | |
| 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 | - }); | |
| 3090 | + let data = mainwp_secure_data({ | |
| 3091 | + action: 'mainwp_installbulkuploadplugintheme', | |
| 3092 | + type: type, | |
| 3093 | + urls: urls, | |
| 3094 | + activatePlugin: activatePlugin, | |
| 3095 | + overwrite: overwrite, | |
| 3096 | + siteId: siteToInstall.attr('siteid') | |
| 3097 | + }); | |
| 2755 | 3098 | |
| 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(); | |
| 3099 | + jQuery.post(ajaxurl, data, function (type, urls, activatePlugin, overwrite, siteToInstall) { | |
| 3100 | + return function (response) { | |
| 3101 | + siteToInstall.attr('status', 'done'); | |
| 3102 | + siteToInstall.find('.progress').hide(); | |
| 3103 | + let statusEl = siteToInstall.find('.status'); | |
| 3104 | + let siteid = siteToInstall.attr('siteid'); | |
| 3105 | + statusEl.show(); | |
| 2763 | 3106 | |
| 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>'; | |
| 3107 | + if (response.error != undefined) { | |
| 3108 | + statusEl.html(response.error); | |
| 3109 | + statusEl.css('color', 'red'); | |
| 3110 | + } else if (response?.ok[siteid] != undefined) { | |
| 3111 | + let results = ''; | |
| 3112 | + if (response?.results[siteid] != undefined) { | |
| 3113 | + let entries = Object.entries(response.results[siteid]); | |
| 3114 | + results += '<div class="ui tiny middle aligned list">'; | |
| 3115 | + for (let entry of entries) { | |
| 3116 | + 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>'; | |
| 3117 | + } | |
| 3118 | + results += '</div>'; | |
| 3119 | + } | |
| 3120 | + jQuery('div[siteId="' + siteid + '"] .installation-entries').html(results); | |
| 3121 | + if (response.cost_tracker_installed_info != undefined) { // to support add to cost tracker pro. | |
| 3122 | + jQuery('div[siteId="' + siteid + '"] .installation-entries').after(response.cost_tracker_installed_info); | |
| 3123 | + } | |
| 3124 | + statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Installation completed successfully.') + '"><i class="check green icon"></i></span>'); | |
| 3125 | + } else if (response?.errors[siteid] === undefined) { | |
| 3126 | + statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Undefined error occurred. Please try again.') + '"><i class="times red icon"></i></span>'); | |
| 3127 | + } else { | |
| 3128 | + statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + response.errors[siteid][1] + '"><i class="times red icon"></i></span>'); | |
| 3129 | + } | |
| 3130 | + | |
| 3131 | + bulkInstallCurrentThreads--; | |
| 3132 | + bulkInstallDone++; | |
| 3133 | + jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').progress('set progress', bulkInstallDone); | |
| 3134 | + jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').find('.label').html(bulkInstallDone + '/' + mainwpVars.bulkInstallTotal + ' ' + MainWP.I18n.t('Installed')); | |
| 3135 | + mainwp_upload_bulk_start_next(type, urls, activatePlugin, overwrite); | |
| 2776 | 3136 | } |
| 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); | |
| 3137 | + }(type, urls, activatePlugin, overwrite, siteToInstall), 'json'); | |
| 3138 | +}; | |
| 3139 | + | |
| 3140 | +jQuery(function ($) { | |
| 3141 | + jQuery(document).on('click', '.open-plugin-details-modal', (event) => { | |
| 3142 | + | |
| 3143 | + const $el = jQuery(event.currentTarget); | |
| 3144 | + | |
| 3145 | + const openwpp = $el.attr('open-wpplugin'); | |
| 3146 | + let openwpp_site = ''; | |
| 3147 | + | |
| 3148 | + if (openwpp === 'yes') { | |
| 3149 | + const findNext = $el | |
| 3150 | + .closest('tr') | |
| 3151 | + .next() | |
| 3152 | + .find('tr[open-wpplugin-siteid]'); | |
| 3153 | + | |
| 3154 | + if (findNext.length > 0) { | |
| 3155 | + openwpp_site = | |
| 3156 | + '&wpplugin=' + findNext.attr('open-wpplugin-siteid'); | |
| 3157 | + } | |
| 2780 | 3158 | } |
| 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 | 3159 | |
| 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); | |
| 3160 | + $('#mainwp-plugin-details-modal') | |
| 3161 | + .modal({ | |
| 3162 | + onHide: function () { }, | |
| 3163 | + onShow: () => { | |
| 3164 | + $('#mainwp-plugin-details-modal') | |
| 3165 | + .find('.ui.embed') | |
| 3166 | + .embed({ | |
| 3167 | + source: 'WP', | |
| 3168 | + url: $el.attr('href') + openwpp_site, | |
| 3169 | + }); | |
| 3170 | + } | |
| 3171 | + }) | |
| 3172 | + .modal('show'); | |
| 3173 | + | |
| 3174 | + return false; | |
| 3175 | + }); | |
| 3176 | +}); | |
| 3177 | + | |
| 3178 | + | |
| 3179 | +/** | |
| 3180 | + * | |
| 3181 | + * Widget plugins/themes changes history | |
| 3182 | + * | |
| 3183 | + */ | |
| 3184 | + | |
| 3185 | +let pluginChangesLoadData = {}; | |
| 3186 | +let themeChangesLoadData = {}; | |
| 3187 | + | |
| 3188 | +jQuery(function ($) { | |
| 3189 | + | |
| 3190 | + $(document).on('click', '.mainwp-show-history', function (e) { | |
| 3191 | + | |
| 3192 | + e.preventDefault(); | |
| 3193 | + e.stopPropagation(); | |
| 3194 | + | |
| 3195 | + const view = $(this).attr('history-view'); | |
| 3196 | + let parent = false; | |
| 3197 | + let type = 'plugin'; // default. | |
| 3198 | + let title = ''; | |
| 3199 | + let info = ''; | |
| 3200 | + let name = ''; | |
| 3201 | + let slug = ''; | |
| 3202 | + let siteId = 0; | |
| 3203 | + | |
| 3204 | + switch (view) { | |
| 3205 | + case 'update-plugins-individual': | |
| 3206 | + parent = $(this).closest('.plugins-bulk-updates'); | |
| 3207 | + siteId = $(parent).attr('site_id'); | |
| 3208 | + info = $(parent).attr('site_name') + ' (' + $(parent).attr('site_url') + ') ' + $(parent).attr('tz-info'); | |
| 3209 | + title = $(this).closest('tr').attr('plugin_name'); | |
| 3210 | + slug = decodeURIComponent($(this).closest('tr').attr('plugin_slug')); | |
| 3211 | + name = $(this).closest('tr').attr('plugin_name'); | |
| 3212 | + break; | |
| 3213 | + case 'update-themes-individual': | |
| 3214 | + parent = $(this).closest('.themes-bulk-updates'); | |
| 3215 | + siteId = $(parent).attr('site_id'); | |
| 3216 | + info = $(parent).attr('site_name') + ' (' + $(parent).attr('site_url') + ') ' + $(parent).attr('tz-info'); | |
| 3217 | + title = $(this).closest('tr').attr('theme_name'); | |
| 3218 | + slug = $(this).closest('tr').attr('theme_slug'); | |
| 3219 | + name = $(this).closest('tr').attr('theme_name'); | |
| 3220 | + type = 'theme'; | |
| 3221 | + break; | |
| 3222 | + case 'manage-plugins-per-sites': | |
| 3223 | + case 'manage-plugins-per-items': | |
| 3224 | + parent = $(this).closest('.mainwp-manage-plugin-item-website'); | |
| 3225 | + title = $(parent).attr('plugin-name'); | |
| 3226 | + info = $(parent).attr('site-name') + ' (' + $(parent).attr('site-url') + ') ' + $(parent).attr('tz-info'); | |
| 3227 | + slug = decodeURIComponent($(parent).attr('plugin-slug')); | |
| 3228 | + siteId = $(parent).attr('site-id'); | |
| 3229 | + break; | |
| 3230 | + case 'manage-themes-per-sites': | |
| 3231 | + case 'manage-themes-per-items': | |
| 3232 | + parent = $(this).closest('.mainwp-manage-theme-item-website'); | |
| 3233 | + title = $(parent).attr('theme-name'); | |
| 3234 | + name = $(parent).attr('theme-name'); | |
| 3235 | + info = $(parent).attr('site-name') + ' (' + $(parent).attr('site-url') + ') ' + $(parent).attr('tz-info'); | |
| 3236 | + slug = decodeURIComponent($(parent).attr('theme-slug')); | |
| 3237 | + siteId = $(parent).attr('site-id'); | |
| 3238 | + type = 'theme'; | |
| 3239 | + break; | |
| 3240 | + case 'widget-plugins': | |
| 3241 | + parent = $(this).closest('.row-manage-item'); | |
| 3242 | + title = $(parent).attr('plugin-name'); | |
| 3243 | + info = $('#mainwp-widget-active-plugins').attr('site-info'); | |
| 3244 | + slug = $(parent).attr('plugin-slug'); | |
| 3245 | + siteId = $('#mainwp-widget-active-plugins').attr('site-id'); | |
| 3246 | + break; | |
| 3247 | + case 'widget-themes': | |
| 3248 | + parent = $(this).closest('.row-manage-item'); | |
| 3249 | + title = $(parent).find('.themeName').val(); | |
| 3250 | + info = $('#mainwp-widget-inactive-themes').attr('site-info'); | |
| 3251 | + slug = $(parent).find('.themeSlug').val(); | |
| 3252 | + name = $(parent).find('.themeName').val(); | |
| 3253 | + siteId = $('#mainwp-widget-inactive-themes').attr('site-id'); | |
| 3254 | + type = 'theme'; | |
| 3255 | + break; | |
| 3256 | + case 'update-plugin-per-item': | |
| 3257 | + parent = $(this).closest('tr'); | |
| 3258 | + siteId = $(parent).attr('site_id'); | |
| 3259 | + info = $(parent).attr('site_name') + ' (' + $(parent).attr('site_url') + ') ' + $(parent).attr('tz-info'); | |
| 3260 | + title = $(parent).attr('plugin_name'); | |
| 3261 | + slug = decodeURIComponent($(parent).attr('plugin_slug')); | |
| 3262 | + break; | |
| 3263 | + case 'update-theme-per-item': | |
| 3264 | + parent = $(this).closest('tr'); | |
| 3265 | + siteId = $(parent).attr('site_id'); | |
| 3266 | + info = $(parent).attr('site_name') + ' (' + decodeURIComponent($(parent).attr('site_url')) + ') ' + $(parent).attr('tz-info'); | |
| 3267 | + title = $(parent).attr('theme_name'); | |
| 3268 | + name = $(parent).attr('theme_name'); | |
| 3269 | + slug = decodeURIComponent($(parent).attr('theme_slug')); | |
| 3270 | + type = 'theme'; | |
| 3271 | + break; | |
| 3272 | + case 'update-plugin-per-site': // NOSONAR - same as above. | |
| 3273 | + parent = $(this).closest('.plugins-bulk-updates'); | |
| 3274 | + siteId = $(parent).attr('site_id'); | |
| 3275 | + info = $(parent).attr('site_name') + ' (' + $(parent).attr('site_url') + ') ' + $(parent).attr('tz-info'); | |
| 3276 | + title = $(this).closest('tr').attr('plugin_name'); | |
| 3277 | + slug = decodeURIComponent($(this).closest('tr').attr('plugin_slug')); | |
| 3278 | + name = $(this).closest('tr').attr('plugin_name'); | |
| 3279 | + break; | |
| 3280 | + case 'update-theme-per-site': // NOSONAR - same above. | |
| 3281 | + parent = $(this).closest('.themes-bulk-updates'); | |
| 3282 | + siteId = $(parent).attr('site_id'); | |
| 3283 | + info = $(parent).attr('site_name') + ' (' + $(parent).attr('site_url') + ') ' + $(parent).attr('tz-info'); | |
| 3284 | + title = $(this).closest('tr').attr('theme_name'); | |
| 3285 | + slug = $(this).closest('tr').attr('theme_slug'); | |
| 3286 | + name = $(this).closest('tr').attr('theme_name'); | |
| 3287 | + type = 'theme'; | |
| 3288 | + break; | |
| 3289 | + case 'update-plugin-per-tag': | |
| 3290 | + parent = $(this).closest('.plugins-bulk-updates'); | |
| 3291 | + siteId = $(parent).attr('site_id'); | |
| 3292 | + info = $(parent).attr('site_name') + ' (' + $(parent).attr('site_url') + ') ' + $(parent).attr('tz-info'); | |
| 3293 | + title = $(this).closest('tr').attr('plugin_name'); | |
| 3294 | + slug = decodeURIComponent($(this).closest('tr').attr('plugin_slug')); | |
| 3295 | + break; | |
| 3296 | + case 'update-theme-per-tag': | |
| 3297 | + parent = $(this).closest('.themes-bulk-updates'); | |
| 3298 | + siteId = $(parent).attr('site_id'); | |
| 3299 | + info = $(parent).attr('site_name') + ' (' + $(parent).attr('site_url') + ') ' + $(parent).attr('tz-info'); | |
| 3300 | + title = $(this).closest('tr').attr('theme_name'); | |
| 3301 | + name = $(this).closest('tr').attr('theme_name'); | |
| 3302 | + slug = $(this).closest('tr').attr('theme_slug'); | |
| 3303 | + type = 'theme'; | |
| 3304 | + break; | |
| 3305 | + } | |
| 3306 | + | |
| 3307 | + if (type === 'plugin') { | |
| 3308 | + pluginChangesLoadData = mainwp_secure_data({ | |
| 3309 | + action: 'mainwp_changes_logs_get_item_changes', | |
| 3310 | + type: 'plugin', | |
| 3311 | + slug: slug, | |
| 3312 | + siteId: siteId, | |
| 3313 | + from_date: '' // current date. | |
| 3314 | + }); | |
| 3315 | + } else if (type === 'theme') { | |
| 3316 | + themeChangesLoadData = mainwp_secure_data({ | |
| 3317 | + action: 'mainwp_changes_logs_get_item_changes', | |
| 3318 | + type: 'theme', | |
| 3319 | + slug: slug, | |
| 3320 | + siteId: siteId, | |
| 3321 | + name: name, | |
| 3322 | + from_date: '' // current date. | |
| 3323 | + }); | |
| 3324 | + } | |
| 3325 | + | |
| 3326 | + $('#mainwp-plugin-theme-history-changes-modal').modal({ | |
| 3327 | + onHide: function () { | |
| 3328 | + }, | |
| 3329 | + onShow: function () { | |
| 3330 | + mainwp_changes_history_box_init(type, title, info); | |
| 3331 | + jQuery('#mainwp-plugin-theme-history-changes-modal').find('.content.ui').html('<div class="ui active centered inline loader history-actions-loading"></div>'); | |
| 3332 | + mainwp_item_changes_load(); | |
| 3333 | + } | |
| 3334 | + }).modal('show'); | |
| 3335 | + }); | |
| 3336 | +}); | |
| 3337 | + | |
| 3338 | +let mainwp_changes_history_box_init = function (type, title, info) { | |
| 3339 | + const hd = jQuery('#mainwp-plugin-theme-history-changes-modal > div.header'); | |
| 3340 | + hd.find('.main-text').text(title + ' ' + MainWP.I18n.t('History')); // safe for escape. | |
| 3341 | + hd.find('.sub.header').text(info).show(); | |
| 3342 | + jQuery('#mainwp-plugin-theme-history-changes-modal').attr('history-type', type); | |
| 3343 | + jQuery('#mainwp-plugin-theme-history-changes-modal').find('.scrolling.content').html(''); | |
| 3344 | +} | |
| 3345 | + | |
| 3346 | +let mainwp_item_changes_load = function (btnObj, load_more_date = '') { | |
| 3347 | + | |
| 3348 | + let md = jQuery('#mainwp-plugin-theme-history-changes-modal'); | |
| 3349 | + let parentContent = false; | |
| 3350 | + if (btnObj) { | |
| 3351 | + parentContent = jQuery(btnObj).closest('.ui.accordion').find('.ui.content'); | |
| 3352 | + } else { | |
| 3353 | + parentContent = jQuery(md).find('.scrolling.content') | |
| 2793 | 3354 | } |
| 2794 | - }(type, urls, activatePlugin, overwrite, siteToInstall), 'json'); | |
| 2795 | -}; | |
| 2796 | 3355 | |
| 2797 | -jQuery(document).ready(function ($) { | |
| 2798 | - jQuery(document).on('click', '.open-plugin-details-modal', function () { | |
| 2799 | - var itemDetail = this; | |
| 3356 | + jQuery(md).find('.actions .col-left').html(''); | |
| 3357 | + jQuery(md).find('.actions .col-right').html(''); | |
| 2800 | 3358 | |
| 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 | - } | |
| 3359 | + const type = jQuery(md).attr('history-type'); | |
| 3360 | + let load_more = false; | |
| 3361 | + | |
| 3362 | + // set load date if provided | |
| 3363 | + if (typeof load_more_date === 'string' && load_more_date !== '') { | |
| 3364 | + if ('theme' === type) { | |
| 3365 | + themeChangesLoadData.from_date = load_more_date; | |
| 3366 | + } else { | |
| 3367 | + pluginChangesLoadData.from_date = load_more_date; | |
| 3368 | + } | |
| 3369 | + load_more = true; | |
| 2808 | 3370 | } |
| 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'); | |
| 3371 | + | |
| 3372 | + let data = 'plugin' === type ? pluginChangesLoadData : themeChangesLoadData; | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + jQuery.post(ajaxurl, data, function (response) { // NOSONAR - complex. | |
| 3376 | + jQuery(md).find('.history-actions-loading').remove(); | |
| 3377 | + if (response?.error) { | |
| 3378 | + if (parentContent) { | |
| 3379 | + let err_content = '<div class="ui message red">' + response.error + '</div>'; | |
| 3380 | + jQuery(parentContent).html(err_content); | |
| 3381 | + } | |
| 3382 | + } else if (response?.list) { | |
| 3383 | + if (response.list.length == 0) { | |
| 3384 | + let msg = MainWP.I18n.t('This plugin has no recorded activity in Dashboard Insights.'); | |
| 3385 | + if ('theme' === type) { | |
| 3386 | + msg = MainWP.I18n.t('This theme has no recorded activity in Dashboard Insights.'); | |
| 3387 | + } | |
| 3388 | + if (parentContent) { | |
| 3389 | + let msg_content = '<div class="ui info message">' + msg + '</div>'; | |
| 3390 | + jQuery(parentContent).html(msg_content); | |
| 3391 | + } | |
| 3392 | + } else { | |
| 3393 | + let content = ''; | |
| 3394 | + Object.entries(response.list).forEach(([indexdt, records]) => { | |
| 3395 | + const dt = records[0].date; | |
| 3396 | + content += `<div class="ui accordion" data-date="${indexdt}"> | |
| 3397 | + <div class="title" format-date="${dt}"> | |
| 3398 | + <div class="ui container"> | |
| 3399 | + <div class="ui grid"> | |
| 3400 | + <div class="ten wide column middle aligned"> | |
| 3401 | + <i class="dropdown icon"></i> | |
| 3402 | + ${dt} | |
| 3403 | + </div> | |
| 3404 | + <div class="six wide column right aligned"> | |
| 3405 | + <button type="button" class="ui circular blue mini button mainwp-day-history-switch-view">` + MainWP.I18n.t('Day History') + `</button> <button class="ui basic mini button actions-count1">${records.length} ` + MainWP.I18n.t('Actions') + `</button> | |
| 3406 | + </div> | |
| 3407 | + </div> | |
| 3408 | + </div> | |
| 3409 | + </div> | |
| 3410 | + <div class="content ui list">`; | |
| 3411 | + records.forEach(record => { | |
| 3412 | + content += `<div class="item" log-id="${record.details.log_id}"> | |
| 3413 | + <div class="ui grid"> | |
| 3414 | + <div class="eight wide column middle aligned"> | |
| 3415 | + <i class="` + get_icon_history_event(record.details.action) + ` icon"></i> | |
| 3416 | + <span class="ui text ` + get_color_changes_event(record.details.action) + `">${record.details.event}</span> ` + MainWP.I18n.t('by') + ` <strong>${record.details.author_name}</strong> ` + MainWP.I18n.t('from') + ` | |
| 3417 | + <strong>${record.details.source}</strong> | |
| 3418 | + </div> | |
| 3419 | + <div class="six wide column middle aligned"> | |
| 3420 | + ` + (record.details?.old_version && record.details?.version ? record.details.old_version + '→' + record.details.version : '') + ` | |
| 3421 | + </div> | |
| 3422 | + <div class="two wide column right aligned"> | |
| 3423 | + ${record.details.at_hour} | |
| 3424 | + </div> | |
| 3425 | + </div> | |
| 3426 | + </div>`; | |
| 3427 | + }); | |
| 3428 | + content += `</div> | |
| 3429 | + </div>`; | |
| 3430 | + }); | |
| 3431 | + | |
| 3432 | + if ('' !== content) { | |
| 3433 | + let accordWrapper = jQuery("<div>", { | |
| 3434 | + id: "change-history-according-wrapper", | |
| 3435 | + html: content | |
| 3436 | + }); | |
| 3437 | + | |
| 3438 | + let name_title = ''; | |
| 3439 | + | |
| 3440 | + if ((data?.name || data?.slug) && response?.name_title) { | |
| 3441 | + name_title = response.name_title; | |
| 3442 | + } | |
| 3443 | + | |
| 3444 | + if (name_title != '') { | |
| 3445 | + jQuery(md).find('.ui.header .main-text').text(name_title + ' ' + MainWP.I18n.t('History')); | |
| 3446 | + } | |
| 3447 | + | |
| 3448 | + if (load_more) { | |
| 3449 | + jQuery(md).find('.scrolling.content').append(accordWrapper); | |
| 3450 | + } else { | |
| 3451 | + jQuery(md).find('.scrolling.content').html(accordWrapper); | |
| 3452 | + } | |
| 3453 | + | |
| 3454 | + jQuery('#change-history-according-wrapper .ui.accordion').accordion({ exclusive: true }); | |
| 3455 | + | |
| 3456 | + jQuery('.mainwp-day-history-switch-view').off('click.accordionFix').on('click.accordionFix', function (e) { | |
| 3457 | + e.preventDefault(); | |
| 3458 | + e.stopPropagation(); // now it runs before ancestor handlers | |
| 3459 | + dayHistory_SwitchViewHandler(this); | |
| 3460 | + return false; | |
| 3461 | + }); | |
| 3462 | + } | |
| 3463 | + | |
| 3464 | + if (response?.onward_date) { | |
| 3465 | + jQuery(md).find('.actions .col-left').html('Data available from ' + response.onward_date + ' onward.'); | |
| 3466 | + } | |
| 3467 | + if (response?.more_date) { | |
| 3468 | + jQuery(md).find('.actions .col-right').html('<a href="javascript:void(0);" onclick="mainwp_item_changes_load(false,\'' + (response.more_date ?? get_local_date_string()) + '\');return false;">' + MainWP.I18n.t('Load More') + '</a>'); | |
| 3469 | + } | |
| 3470 | + } | |
| 3471 | + } else if (parentContent) { | |
| 3472 | + let err_content = '<div class="ui message red">' + MainWP.I18n.t('Undefined error occurred. Please try again.') + '</div>'; | |
| 3473 | + jQuery(parentContent).html(err_content); | |
| 3474 | + } | |
| 3475 | + }, 'json'); | |
| 3476 | +} | |
| 3477 | + | |
| 3478 | +let get_icon_history_event = function (act) { | |
| 3479 | + let icon = ''; | |
| 3480 | + | |
| 3481 | + if (act === 'delete' || act === 'deleted') { | |
| 3482 | + icon = 'trash red'; | |
| 3483 | + } else if (act === 'deactivated' || act === 'deactivate') { | |
| 3484 | + icon = 'toggle off red'; | |
| 3485 | + } else if (act === 'activated' || act === 'activate') { | |
| 3486 | + icon = 'toggle on green'; | |
| 3487 | + } else if (act === 'updated' || act === 'update') { | |
| 3488 | + icon = 'sync orange'; | |
| 3489 | + } else if (act === 'installed' || act === 'install') { | |
| 3490 | + icon = 'download teal'; | |
| 3491 | + } else { | |
| 3492 | + icon = 'circle grey'; | |
| 3493 | + } | |
| 3494 | + | |
| 3495 | + return icon; | |
| 3496 | +} | |
| 3497 | + | |
| 3498 | +let get_color_changes_event = function (act) { | |
| 3499 | + const actColorMap = { | |
| 3500 | + red: ['deleted', 'removed', 'revoked', 'delete', 'deactivated', 'disabled', 'suspended', 'deactivate'], | |
| 3501 | + orange: ['updated', 'modified', 'update'], | |
| 3502 | + grey: ['opened'], | |
| 3503 | + blue: ['logged-in', 'logged-out'], | |
| 3504 | + teal: ['sync', 'installed', 'install', 'uploaded'], | |
| 3505 | + green: ['activated', 'activate', 'created', 'published', 'enabled', 'added'] | |
| 3506 | + }; | |
| 3507 | + | |
| 3508 | + let color = ''; | |
| 3509 | + | |
| 3510 | + for (const [c, acts] of Object.entries(actColorMap)) { | |
| 3511 | + if (acts.includes(act)) { | |
| 3512 | + color = c; | |
| 3513 | + break; | |
| 3514 | + } | |
| 3515 | + } | |
| 3516 | + return color; | |
| 3517 | +} | |
| 3518 | + | |
| 3519 | +let dayHistory_SwitchViewHandler = function (btn) { | |
| 3520 | + | |
| 3521 | + const parent = jQuery(btn).closest('.ui.accordion'); | |
| 3522 | + const his_date = jQuery(btn).closest('.title').attr('format-date'); | |
| 3523 | + | |
| 3524 | + jQuery(btn).closest('.title').hasClass('active') || jQuery(btn).closest('.title').trigger('click'); | |
| 3525 | + | |
| 3526 | + jQuery(parent).find('.content.ui').html('<div class="ui active centered inline loader history-actions-loading"></div>'); | |
| 3527 | + | |
| 3528 | + const dt = jQuery(parent).data('date'); | |
| 3529 | + let md = jQuery('#mainwp-plugin-theme-history-changes-modal'); | |
| 3530 | + const type = jQuery(md).attr('history-type'); | |
| 3531 | + | |
| 3532 | + let siteId = ('plugin' === type ? pluginChangesLoadData.siteId : themeChangesLoadData.siteId) || 0; | |
| 3533 | + | |
| 3534 | + let data = mainwp_secure_data({ | |
| 3535 | + action: 'mainwp_changes_logs_get_item_changes', | |
| 3536 | + type: type, | |
| 3537 | + target_date: dt, | |
| 3538 | + siteId: siteId | |
| 3539 | + }); | |
| 3540 | + | |
| 3541 | + jQuery.post(ajaxurl, data, function (response) { // NOSONAR - complex. | |
| 3542 | + | |
| 3543 | + jQuery(parent).find('.history-actions-loading').remove(); | |
| 3544 | + | |
| 3545 | + let dayContent = jQuery(parent).find('.content'); | |
| 3546 | + | |
| 3547 | + if (response.error != undefined) { | |
| 3548 | + dayContent.append('<div class="ui message red changes-history-status">' + response.error + '</div>'); | |
| 3549 | + } else if (response?.list) { | |
| 3550 | + if (response.list.length == 0) { | |
| 3551 | + let msg = MainWP.I18n.t('This plugin has no recorded activity in Dashboard Insights.'); | |
| 3552 | + if ('theme' === type && '' === dt) { | |
| 3553 | + msg = MainWP.I18n.t('This theme has no recorded activity in Dashboard Insights.'); | |
| 3554 | + } else if ('' !== dt) { | |
| 3555 | + if ('plugin' === type) { | |
| 3556 | + msg = MainWP.I18n.t('No history changes found for the plugin on this day.'); | |
| 3557 | + } else { | |
| 3558 | + msg = MainWP.I18n.t('No history changes found for the theme on this day.'); | |
| 3559 | + } | |
| 3560 | + } | |
| 3561 | + dayContent.append('<div class="ui message changes-history-status">' + msg + '</div>'); | |
| 3562 | + } else { | |
| 3563 | + let content = ''; | |
| 3564 | + let count_acts = 0; | |
| 3565 | + Object.entries(response.list).forEach(([idxslug, records]) => { | |
| 3566 | + const name = records[0].name; | |
| 3567 | + content += `<div class="ui accordion list-all-actions-in-day" data-slug="${records[0].item_slug}" data-name="${records[0].item_name}" data-siteid="${records[0].site_id}"> | |
| 3568 | + <div class="title"> | |
| 3569 | + <div class="ui container"> | |
| 3570 | + <div class="ui grid"> | |
| 3571 | + <div class="ten wide column middle aligned"> | |
| 3572 | + <i class="dropdown icon"></i> | |
| 3573 | + ${name} | |
| 3574 | + </div> | |
| 3575 | + <div class="six wide column right aligned"> | |
| 3576 | + <button type="button" class="ui circular blue mini button mainwp-list-history-switch-view">` + ('plugin' === type ? MainWP.I18n.t('Plugin History') : MainWP.I18n.t('Theme History')) + `</button> <button class="ui basic mini button ">${records.length} ` + MainWP.I18n.t('Actions') + `</button> | |
| 3577 | + </div> | |
| 3578 | + </div> | |
| 3579 | + </div> | |
| 3580 | + </div> | |
| 3581 | + <div class="content ui list">`; | |
| 3582 | + records.forEach(record => { | |
| 3583 | + content += `<div class="item" log-id="${record.details.log_id}"> | |
| 3584 | + <div class="ui grid"> | |
| 3585 | + <div class="eight wide column middle aligned"> | |
| 3586 | + <i class="` + get_icon_history_event(record.details.action) + ` icon"></i> | |
| 3587 | + <span class="ui text ` + get_color_changes_event(record.details.action) + `">${record.details.event}</span> ` + MainWP.I18n.t('by') + ` <strong>${record.details.author_name}</strong> ` + MainWP.I18n.t('from') + ` | |
| 3588 | + <strong>${record.details.source}</strong> | |
| 3589 | + </div> | |
| 3590 | + <div class="six wide column middle aligned"> | |
| 3591 | + ` + (record.details?.old_version && record.details?.version ? record.details.old_version + '→' + record.details.version : '') + ` | |
| 3592 | + </div> | |
| 3593 | + <div class="two wide column right aligned"> | |
| 3594 | + ${record.details.at_hour} | |
| 3595 | + </div> | |
| 3596 | + </div> | |
| 3597 | + </div>`; | |
| 3598 | + count_acts++; | |
| 3599 | + }); | |
| 3600 | + content += `</div> | |
| 3601 | + </div>`; | |
| 3602 | + }); | |
| 3603 | + | |
| 3604 | + if ('' !== content) { | |
| 3605 | + jQuery(md).find('.ui.header .main-text').text(his_date + ' ' + MainWP.I18n.t('History')); | |
| 3606 | + let accordWrapper = jQuery("<div>", { | |
| 3607 | + id: "change-history-according-wrapper", | |
| 3608 | + html: content | |
| 3609 | + }); | |
| 3610 | + jQuery(md).find('.scrolling.content').html(accordWrapper); | |
| 3611 | + jQuery('#change-history-according-wrapper .ui.accordion').accordion({ exclusive: true }); | |
| 3612 | + | |
| 3613 | + jQuery('.mainwp-list-history-switch-view').off('click.accordionFix2').on('click.accordionFix2', function (e) { | |
| 3614 | + e.preventDefault(); | |
| 3615 | + e.stopPropagation(); // now it runs before ancestor handlers | |
| 3616 | + listHistory_SwitchViewHandler(this); | |
| 3617 | + return false; | |
| 3618 | + }); | |
| 3619 | + } | |
| 3620 | + } | |
| 3621 | + } else { | |
| 3622 | + dayContent.html('<div class="ui message red changes-history-status">' + MainWP.I18n.t('Undefined error occurred. Please try again.') + '</div>'); | |
| 3623 | + } | |
| 3624 | + }, 'json'); | |
| 3625 | + | |
| 2819 | 3626 | return false; |
| 2820 | - }); | |
| 2821 | -}); | |
| 3627 | +} | |
| 2822 | 3628 | |
| 2823 | 3629 | |
| 3630 | +let listHistory_SwitchViewHandler = function (btn) { | |
| 3631 | + | |
| 3632 | + const parent = jQuery(btn).closest('.ui.accordion'); | |
| 3633 | + | |
| 3634 | + jQuery(btn).closest('.title').hasClass('active') || jQuery(btn).closest('.title').trigger('click'); | |
| 3635 | + | |
| 3636 | + jQuery(parent).find('.content.ui').html('<div class="ui active centered inline loader history-actions-loading"></div>'); | |
| 3637 | + | |
| 3638 | + let md = jQuery('#mainwp-plugin-theme-history-changes-modal'); | |
| 3639 | + const type = jQuery(md).attr('history-type'); | |
| 3640 | + | |
| 3641 | + if ('theme' === type) { | |
| 3642 | + themeChangesLoadData.slug = jQuery(parent).data('slug'); | |
| 3643 | + themeChangesLoadData.name = jQuery(parent).data('name'); | |
| 3644 | + themeChangesLoadData.siteId = jQuery(parent).data('siteid'); | |
| 3645 | + themeChangesLoadData.from_date = ''; | |
| 3646 | + } else { | |
| 3647 | + pluginChangesLoadData.slug = jQuery(parent).data('slug');; | |
| 3648 | + pluginChangesLoadData.siteId = jQuery(parent).data('siteid');; | |
| 3649 | + pluginChangesLoadData.from_date = ''; | |
| 3650 | + } | |
| 3651 | + mainwp_item_changes_load(btn); | |
| 3652 | +} | |
| 3653 | + | |
| 3654 | + | |
| 2824 | 3655 | /** |
| 2825 | 3656 | * Install check plugins. |
| 2826 | 3657 | * |
| 2827 | 3658 | */ |
| 2828 | 3659 | |
| 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'); | |
| 3660 | +globalThis.mainwp_install_check_plugin_prepare = function (slug) { | |
| 3661 | + let selected = jQuery("input[name='install_checker[]']:checked"); | |
| 3662 | + if (selected.length == 0) { | |
| 3663 | + feedback('mainwp-message-zone-install', MainWP.I18n.t('Please select website to install plugin.'), 'yellow'); | |
| 3664 | + return; | |
| 3665 | + } else { | |
| 3666 | + selected.each(function () { | |
| 3667 | + jQuery(this).closest('.siteBulkInstall').attr('status', 'queue'); | |
| 3668 | + }); | |
| 3669 | + } | |
| 3670 | + jQuery('#mainwp-install-check-btn').addClass('disabled'); | |
| 3671 | + mainwp_set_message_zone('#mainwp-message-zone-install', '<i class="notched circle loading icon"></i> ', false, true); // false: not change the color class. | |
| 3672 | + let data = mainwp_secure_data({ | |
| 3673 | + action: 'mainwp_preparebulkinstallcheckplugin', | |
| 3674 | + slug: slug, | |
| 2837 | 3675 | }); |
| 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'); | |
| 3676 | + jQuery.post(ajaxurl, data, function (response) { | |
| 3677 | + mainwp_set_message_zone('#mainwp-message-zone-install'); | |
| 3678 | + mainwp_install_check_plugin_start_next(response.url); | |
| 3679 | + }, 'json'); | |
| 2849 | 3680 | }; |
| 2850 | 3681 | |
| 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 | - } | |
| 3682 | +let mainwp_install_check_plugin_start_next = function (url) { | |
| 3683 | + while ((siteToInstall = jQuery('.siteBulkInstall[status="queue"]:first')) && (siteToInstall.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { // NOSONAR - modified outside the function. | |
| 3684 | + mainwp_install_check_plugin_start_specific(url, siteToInstall); | |
| 3685 | + } | |
| 2855 | 3686 | }; |
| 2856 | 3687 | |
| 2857 | -mainwp_install_check_plugin_start_specific = function (url, siteToInstall) { | |
| 2858 | - bulkInstallCurrentThreads++; | |
| 3688 | +let mainwp_install_check_plugin_start_specific = function (url, siteToInstall) { | |
| 3689 | + bulkInstallCurrentThreads++; | |
| 2859 | 3690 | |
| 2860 | - siteToInstall.attr('status', 'progress'); | |
| 2861 | - siteToInstall.find('.queue').hide(); | |
| 2862 | - siteToInstall.find('.progress').show(); | |
| 3691 | + siteToInstall.attr('status', 'progress'); | |
| 3692 | + siteToInstall.find('.queue').hide(); | |
| 3693 | + siteToInstall.find('.progress').show(); | |
| 2863 | 3694 | |
| 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 | - }); | |
| 3695 | + let data = mainwp_secure_data({ | |
| 3696 | + action: 'mainwp_installbulkinstallplugintheme', | |
| 3697 | + type: 'plugin', | |
| 3698 | + url: url, | |
| 3699 | + activatePlugin: 'true', | |
| 3700 | + siteId: siteToInstall.attr('siteid') | |
| 3701 | + }); | |
| 2871 | 3702 | |
| 2872 | - jQuery.post(ajaxurl, data, function (url, siteToInstall) { | |
| 2873 | - return function (response) { | |
| 2874 | - siteToInstall.attr('status', 'done'); | |
| 2875 | - siteToInstall.find('.progress').hide(); | |
| 3703 | + jQuery.post(ajaxurl, data, function (url, siteToInstall) { | |
| 3704 | + return function (response) { | |
| 3705 | + siteToInstall.attr('status', 'done'); | |
| 3706 | + siteToInstall.find('.progress').hide(); | |
| 2876 | 3707 | |
| 2877 | - var statusEl = siteToInstall.find('.status'); | |
| 2878 | - statusEl.show(); | |
| 3708 | + let statusEl = siteToInstall.find('.status'); | |
| 3709 | + statusEl.show(); | |
| 2879 | 3710 | |
| 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 | - } | |
| 3711 | + if (response.error != undefined) { | |
| 3712 | + statusEl.html(response.error); | |
| 3713 | + statusEl.css('color', 'red'); | |
| 3714 | + } else if (response?.ok[siteToInstall.attr('siteid')]) { | |
| 3715 | + statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Installation completed successfully.') + '"><i class="check green icon"></i></span>'); | |
| 3716 | + } else if (response?.errors[siteToInstall.attr('siteid')]) { | |
| 3717 | + statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + response.errors[siteToInstall.attr('siteid')][1] + '"><i class="times red icon"></i></span>'); | |
| 3718 | + } else { | |
| 3719 | + statusEl.html('<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Undefined error occurred. Please try again.') + '"><i class="times red icon"></i></span>'); | |
| 3720 | + } | |
| 2890 | 3721 | |
| 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'); | |
| 3722 | + bulkInstallCurrentThreads--; | |
| 3723 | + bulkInstallDone++; | |
| 3724 | + jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').progress('set progress', bulkInstallDone); | |
| 3725 | + jQuery('#plugintheme-installation-progress-modal .mainwp-modal-progress').find('.label').html(bulkInstallDone + '/' + mainwpVars.bulkInstallTotal + ' ' + MainWP.I18n.t('Installed')); | |
| 3726 | + mainwp_install_check_plugin_start_next(url); | |
| 3727 | + } | |
| 3728 | + }(url, siteToInstall), 'json'); | |
| 2898 | 3729 | }; |
| 2899 | 3730 | |
| 3731 | +function isUrl(url) { | |
| 3732 | + try { | |
| 3733 | + new URL(url); | |
| 3734 | + return true; | |
| 3735 | + } catch (e) { | |
| 3736 | + console.log(e); | |
| 3737 | + } | |
| 3738 | + return false; | |
| 3739 | +} | |
| 2900 | 3740 | |
| 3741 | +function removeUrlParams(url, params) { | |
| 3742 | + try { | |
| 3743 | + const urlObj = new URL(url); | |
| 3744 | + jQuery(params).each(function (idx, param) { | |
| 3745 | + urlObj.searchParams.delete(param); | |
| 3746 | + }); | |
| 3747 | + return urlObj.toString(); | |
| 3748 | + } catch (e) { | |
| 3749 | + console.log(e); | |
| 3750 | + } | |
| 3751 | + return ''; | |
| 3752 | +} | |
| 2901 | 3753 | |
| 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); | |
| 3754 | +function setVisible(what, vis) { | |
| 3755 | + if (vis) { | |
| 3756 | + jQuery(what).show(); | |
| 3757 | + } else { | |
| 3758 | + jQuery(what).hide(); | |
| 3759 | + } | |
| 2908 | 3760 | } |
| 2909 | -function setVisible(what, vis) { | |
| 2910 | - if (vis) { | |
| 2911 | - jQuery(what).show(); | |
| 2912 | - } else { | |
| 2913 | - jQuery(what).hide(); | |
| 2914 | - } | |
| 3761 | + | |
| 3762 | +const mainwp_scrollToElement = () => { | |
| 3763 | + jQuery('html,body').animate({ | |
| 3764 | + scrollTop: 0 | |
| 3765 | + }, 1000); | |
| 3766 | + | |
| 3767 | + return false; | |
| 2915 | 3768 | } |
| 3769 | + | |
| 2916 | 3770 | function setHtml(what, text, ptag) { |
| 2917 | - if (typeof ptag == "undefined") | |
| 2918 | - ptag = true; | |
| 3771 | + if (ptag === undefined) | |
| 3772 | + ptag = true; | |
| 2919 | 3773 | |
| 2920 | - setVisible(what, true); | |
| 2921 | - if (ptag) | |
| 2922 | - jQuery(what).html('<span>' + text + '</span>'); | |
| 2923 | - else | |
| 2924 | - jQuery(what).html(text); | |
| 2925 | - scrollToElement(what); | |
| 3774 | + setVisible(what, true); | |
| 3775 | + if (ptag) | |
| 3776 | + jQuery(what).html('<span>' + text + '</span>'); | |
| 3777 | + else | |
| 3778 | + jQuery(what).html(text); | |
| 3779 | + mainwp_scrollToElement(); // to fix js conflict error from some other add-ons. | |
| 2926 | 3780 | } |
| 2927 | 3781 | |
| 2928 | 3782 | |
| 2929 | 3783 | /** |
| @@ -2928,288 +3782,304 @@ | ||
| 2928 | 3782 | |
| 2929 | 3783 | /** |
| 2930 | 3784 | * Notes |
| 2931 | 3785 | */ |
| 2932 | -jQuery(document).ready(function () { | |
| 3786 | +jQuery(function () { | |
| 2933 | 3787 | |
| 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 | - }); | |
| 3788 | + jQuery(document).on('click', '#mainwp-notes-cancel', function () { | |
| 3789 | + jQuery('#mainwp-notes-status').html(''); | |
| 3790 | + jQuery('#mainwp-notes-status').removeClass('red green'); | |
| 3791 | + mainwp_notes_hide(); | |
| 3792 | + return false; | |
| 3793 | + }); | |
| 2940 | 3794 | |
| 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 | - }); | |
| 3795 | + jQuery(document).on('click', '#mainwp-notes-save', function () { | |
| 3796 | + let which = jQuery('#mainwp-which-note').val(); | |
| 3797 | + if (which == 'site') { | |
| 3798 | + mainwp_notes_site_save(); | |
| 3799 | + } else if (which == 'theme') { | |
| 3800 | + mainwp_notes_theme_save(); | |
| 3801 | + } else if (which == 'plugin') { | |
| 3802 | + mainwp_notes_plugin_save(); | |
| 3803 | + } else if (which == 'client') { | |
| 3804 | + mainwp_notes_client_save(); | |
| 3805 | + } | |
| 3806 | + return false; | |
| 3807 | + }); | |
| 2956 | 3808 | |
| 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 | - }); | |
| 3809 | + jQuery(document).on('click', '.mainwp-edit-site-note', function () { | |
| 3810 | + let id = jQuery(this).attr('id').substring(13); | |
| 3811 | + let note = jQuery('#mainwp-notes-' + id + '-note').html(); | |
| 3812 | + jQuery('#mainwp-notes-html').html(note == '' ? MainWP.I18n.t('No saved notes. Click the Edit button to edit site notes.') : note); | |
| 3813 | + jQuery('#mainwp-notes-note').val(note); | |
| 3814 | + jQuery('#mainwp-notes-websiteid').val(id); | |
| 3815 | + jQuery('#mainwp-which-note').val('site'); // to fix conflict. | |
| 3816 | + mainwp_notes_show(); | |
| 3817 | + if (jQuery(this).attr('add-new')) { | |
| 3818 | + jQuery('#mainwp-notes-edit').trigger("click"); | |
| 3819 | + } | |
| 3820 | + return false; | |
| 3821 | + }); | |
| 2967 | 3822 | |
| 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 | - } | |
| 3823 | + jQuery(document).on('click', '#mainwp-notes-edit', function () { | |
| 3824 | + jQuery('#mainwp-notes-html').hide(); | |
| 3825 | + jQuery('#mainwp-notes-editor').show(); | |
| 3826 | + jQuery(this).hide(); | |
| 3827 | + jQuery('#mainwp-notes-save').show(); | |
| 3828 | + jQuery('#mainwp-notes-status').html(''); | |
| 3829 | + jQuery('#mainwp-notes-status').removeClass('red green'); | |
| 3830 | + return false; | |
| 3831 | + }); | |
| 3832 | + jQuery('#redirectForm').trigger("submit"); | |
| 3833 | + if (jQuery('div.ui.open-site-close-window').length > 0) { | |
| 3834 | + setTimeout(function () { | |
| 3835 | + globalThis.close() | |
| 3836 | + }, 3000); | |
| 3837 | + } | |
| 2983 | 3838 | }); |
| 2984 | 3839 | |
| 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 | - } | |
| 3840 | +globalThis.mainwp_notes_show = function (reloadClose) { | |
| 3841 | + if (reloadClose) { | |
| 3842 | + jQuery('#mainwp-notes-modal').modal({ | |
| 3843 | + onHide: function () { | |
| 3844 | + mainwp_forceReload(); | |
| 3845 | + } | |
| 3846 | + }).modal('show'); | |
| 3847 | + } else { | |
| 3848 | + jQuery('#mainwp-notes-modal').modal({ closable: false }).modal('show'); | |
| 3849 | + } | |
| 2995 | 3850 | |
| 2996 | - jQuery('#mainwp-notes-html').show(); | |
| 2997 | - jQuery('#mainwp-notes-editor').hide(); | |
| 2998 | - jQuery('#mainwp-notes-save').hide(); | |
| 2999 | - jQuery('#mainwp-notes-edit').show(); | |
| 3851 | + jQuery('#mainwp-notes-html').show(); | |
| 3852 | + jQuery('#mainwp-notes-editor').hide(); | |
| 3853 | + jQuery('#mainwp-notes-save').hide(); | |
| 3854 | + jQuery('#mainwp-notes-edit').show(); | |
| 3000 | 3855 | }; |
| 3001 | -mainwp_notes_hide = function () { | |
| 3002 | - jQuery('#mainwp-notes-modal').modal('hide'); | |
| 3856 | +let mainwp_notes_hide = function () { | |
| 3857 | + jQuery('#mainwp-notes-modal').modal('hide'); | |
| 3003 | 3858 | }; |
| 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 | - }); | |
| 3859 | +let mainwp_notes_site_save = function () { | |
| 3860 | + let normalid = jQuery('#mainwp-notes-websiteid').val(); | |
| 3861 | + let newnote = jQuery('#mainwp-notes-note').val(); | |
| 3862 | + newnote = newnote.replaceAll(/\r\n|\r|\n/g, '<br>'); | |
| 3863 | + let data = mainwp_secure_data({ | |
| 3864 | + action: 'mainwp_notes_save', | |
| 3865 | + websiteid: normalid, | |
| 3866 | + note: newnote | |
| 3867 | + }); | |
| 3013 | 3868 | |
| 3014 | - jQuery('#mainwp-notes-status').html('<i class="notched circle loading icon"></i> ' + __('Saving note. Please wait...')).show(); | |
| 3869 | + jQuery('#mainwp-notes-status').html('<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Saving note. Please wait...')).show(); | |
| 3015 | 3870 | |
| 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'); | |
| 3871 | + jQuery.post(ajaxurl, data, function (response) { | |
| 3872 | + if (response.error != undefined) { | |
| 3873 | + jQuery('#mainwp-notes-status').html(response.error).addClass('red'); | |
| 3874 | + } else if (response.result == 'SUCCESS') { | |
| 3875 | + jQuery('#mainwp-notes-status').html(MainWP.I18n.t('Note saved successfully.')).addClass('green'); | |
| 3876 | + if (jQuery('#mainwp-notes-' + normalid + '-note').length > 0) { | |
| 3877 | + jQuery('#mainwp-notes-' + normalid + '-note').html(response?.esc_note_content ?? ''); | |
| 3878 | + jQuery('#mainwp-notes-html').html(response?.esc_note_content ?? ''); | |
| 3879 | + } | |
| 3880 | + } else { | |
| 3881 | + jQuery('#mainwp-notes-status').html(MainWP.I18n.t('Undefined error occurred while saving your note!')).addClass('red'); | |
| 3882 | + } | |
| 3883 | + }, 'json'); | |
| 3028 | 3884 | |
| 3029 | - setTimeout(function () { | |
| 3030 | - jQuery('#mainwp-notes-status').fadeOut(300); | |
| 3031 | - }, 3000); | |
| 3885 | + setTimeout(function () { | |
| 3886 | + jQuery('#mainwp-notes-status').fadeOut(300); | |
| 3887 | + }, 3000); | |
| 3032 | 3888 | |
| 3033 | - jQuery('#mainwp-notes-html').show(); | |
| 3034 | - jQuery('#mainwp-notes-editor').hide(); | |
| 3035 | - jQuery('#mainwp-notes-save').hide(); | |
| 3036 | - jQuery('#mainwp-notes-edit').show(); | |
| 3889 | + jQuery('#mainwp-notes-html').show(); | |
| 3890 | + jQuery('#mainwp-notes-editor').hide(); | |
| 3891 | + jQuery('#mainwp-notes-save').hide(); | |
| 3892 | + jQuery('#mainwp-notes-edit').show(); | |
| 3037 | 3893 | |
| 3038 | 3894 | }; |
| 3039 | 3895 | |
| 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 | - } | |
| 3896 | +globalThis.getErrorMessage = function (pError, msgOnly) { // NOSONAR - complex. | |
| 3897 | + if (pError.message == 'HTTPERROR') { | |
| 3898 | + return MainWP.I18n.t('HTTP error') + '! ' + pError.extra; | |
| 3899 | + } else if (pError.message == 'NOMAINWP' || pError == 'NOMAINWP') { | |
| 3900 | + return mainwp_js_get_error_not_detected_connect(); | |
| 3901 | + } else if (pError.message == 'ERROR') { | |
| 3902 | + return 'ERROR' + ((pError.extra != '') && (pError.extra != undefined) ? ': ' + pError.extra : ''); | |
| 3903 | + } else if (pError.message == 'WPERROR') { | |
| 3904 | + let extrMsg = (pError.extra != '') && (pError.extra != undefined) ? pError.extra : ''; | |
| 3905 | + if (msgOnly != undefined && msgOnly && extrMsg != '') { | |
| 3906 | + return extrMsg; | |
| 3907 | + } else { | |
| 3908 | + return MainWP.I18n.t('ERROR on the child site') + ': ' + extrMsg; | |
| 3909 | + } | |
| 3050 | 3910 | |
| 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; | |
| 3911 | + } else if (pError.message != undefined && pError.message != '') { | |
| 3912 | + return pError.message; | |
| 3058 | 3913 | } else { |
| 3059 | - return __('ERROR on the child site') + ': ' + extrMsg; | |
| 3914 | + return pError; | |
| 3060 | 3915 | } |
| 3061 | - | |
| 3062 | - } else if (pError.message != undefined && pError.message != '') { | |
| 3063 | - return pError.message; | |
| 3064 | - } else { | |
| 3065 | - return pError; | |
| 3066 | - } | |
| 3067 | 3916 | }; |
| 3068 | 3917 | |
| 3069 | -getErrorMessageInfo = function (repError, outputType) { | |
| 3070 | - var msg = ''; | |
| 3071 | - var msgUI = '<i class="red times icon"></i>'; | |
| 3918 | +globalThis.getErrorMessageInfo = function (repError, outputType) { // NOSONAR - complex. | |
| 3919 | + let msg = ''; | |
| 3920 | + let msgUI = '<i class="red times icon"></i>'; | |
| 3072 | 3921 | |
| 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 | - } | |
| 3922 | + if (repError.errorCode != undefined && repError.errorCode == 'SUSPENDED_SITE') { | |
| 3923 | + msg = MainWP.I18n.t('Suspended site.'); | |
| 3924 | + msgUI = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Suspended site.') + '"><i class="pause yellow icon"></i></span>'; | |
| 3925 | + } | |
| 3077 | 3926 | |
| 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>'; | |
| 3927 | + if (repError.errorCode != undefined && repError.errorCode == 'MAINWP_NOTICE') { | |
| 3928 | + if (repError.message != undefined) { | |
| 3929 | + msg = repError.message; | |
| 3930 | + msgUI = '<span data-inverted="" data-position="left center" data-tooltip="' + msg + '"><i class="pause circular yellow inverted icon"></i></span>'; | |
| 3931 | + } | |
| 3082 | 3932 | } |
| 3083 | - } | |
| 3084 | 3933 | |
| 3085 | - if (msg == '') { | |
| 3086 | - msg = getErrorMessage(repError); | |
| 3934 | + if (msg == '') { | |
| 3935 | + msg = getErrorMessage(repError); | |
| 3087 | 3936 | |
| 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.'); | |
| 3937 | + if (repError.message == 'NOMAINWP' || repError == 'NOMAINWP') { | |
| 3938 | + msg = mainwp_js_get_error_not_detected_connect(); | |
| 3939 | + } | |
| 3940 | + | |
| 3941 | + if (msg != '') { | |
| 3942 | + msgUI = '<span data-inverted="" data-position="left center" data-tooltip="' + msg + '"><i class="red times icon"></i></span>'; | |
| 3943 | + } | |
| 3090 | 3944 | } |
| 3091 | 3945 | |
| 3092 | 3946 | if (msg != '') { |
| 3093 | - msgUI = '<span data-inverted="" data-position="left center" data-tooltip="' + msg + '"><i class="red times icon"></i></span>'; | |
| 3947 | + if (outputType != undefined && outputType == 'ui') { | |
| 3948 | + return msgUI; | |
| 3949 | + } else { | |
| 3950 | + return msg; | |
| 3951 | + } | |
| 3094 | 3952 | } |
| 3095 | - } | |
| 3096 | 3953 | |
| 3097 | - if (msg != '') { | |
| 3098 | - if (outputType != undefined && outputType == 'ui') { | |
| 3099 | - return msgUI; | |
| 3100 | - } else { | |
| 3101 | - return msg; | |
| 3102 | - } | |
| 3103 | - } | |
| 3104 | - | |
| 3105 | - return repError; | |
| 3954 | + return repError; | |
| 3106 | 3955 | } |
| 3107 | 3956 | |
| 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); | |
| 3957 | +globalThis.dateToHMS = function (date) { | |
| 3958 | + if (mainwpParams?.time_format) { | |
| 3959 | + let time = moment(date); | |
| 3960 | + let format = mainwpParams['time_format']; | |
| 3961 | + format = format.replaceAll('g', 'h'); | |
| 3962 | + format = format.replaceAll('i', 'mm'); | |
| 3963 | + format = format.replaceAll('s', 'ss'); | |
| 3964 | + format = format.replaceAll('F', 'MMMM'); | |
| 3965 | + format = format.replaceAll('j', 'D'); | |
| 3966 | + format = format.replaceAll('Y', 'YYYY'); | |
| 3967 | + return time.format(format); | |
| 3968 | + } | |
| 3969 | + let h = date.getHours(); | |
| 3970 | + let m = date.getMinutes(); | |
| 3971 | + let s = date.getSeconds(); | |
| 3972 | + return '' + (h <= 9 ? '0' + h : h) + ':' + (m <= 9 ? '0' + m : m) + ':' + (s <= 9 ? '0' + s : s); | |
| 3124 | 3973 | }; |
| 3125 | -appendToDiv = function (pSelector, pText, pScrolldown, pShowTime) { | |
| 3126 | - if (pScrolldown == undefined) | |
| 3127 | - pScrolldown = true; | |
| 3128 | - if (pShowTime == undefined) | |
| 3129 | - pShowTime = true; | |
| 3974 | +globalThis.appendToDiv = function (pSelector, pText, pScrolldown, pShowTime) { | |
| 3975 | + if (pScrolldown == undefined) | |
| 3976 | + pScrolldown = true; | |
| 3977 | + if (pShowTime == undefined) | |
| 3978 | + pShowTime = true; | |
| 3130 | 3979 | |
| 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); | |
| 3980 | + let theDiv = jQuery(pSelector); | |
| 3981 | + theDiv.append('<br />' + (pShowTime ? dateToHMS(new Date()) + ' ' : '') + pText); | |
| 3982 | + if (pScrolldown) | |
| 3983 | + theDiv.animate({ scrollTop: theDiv.prop("scrollHeight") }, 100); | |
| 3135 | 3984 | }; |
| 3136 | 3985 | |
| 3137 | 3986 | jQuery.fn.exists = function () { |
| 3138 | - return (this.length !== 0); | |
| 3987 | + return (this.length !== 0); | |
| 3139 | 3988 | }; |
| 3140 | 3989 | |
| 3141 | 3990 | |
| 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, ''); | |
| 3991 | +globalThis.MainWP = globalThis.MainWP || {}; | |
| 3992 | +globalThis.MainWP.I18n = globalThis.MainWP.I18n || {}; | |
| 3147 | 3993 | |
| 3148 | - if (strippedText == '') | |
| 3149 | - return text.replace('%1', _var1).replace('%2', _var2).replace('%3', _var3); | |
| 3994 | +MainWP.I18n.t = function (text, ...args) { | |
| 3995 | + if (!text) { | |
| 3996 | + return text; | |
| 3997 | + } | |
| 3150 | 3998 | |
| 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); | |
| 3999 | + // Replace non-alphanumeric characters (including Unicode/accented characters) with '_' | |
| 4000 | + const strippedText = text.replace(/[^\p{L}\p{N}_]/gu, '_'); | |
| 3155 | 4001 | |
| 3156 | - return mainwpTranslations[strippedText].replace('%1', _var1).replace('%2', _var2).replace('%3', _var3); | |
| 4002 | + let translated = text; | |
| 4003 | + | |
| 4004 | + if ( | |
| 4005 | + strippedText && | |
| 4006 | + typeof mainwpTranslations !== 'undefined' && | |
| 4007 | + mainwpTranslations[strippedText] !== undefined | |
| 4008 | + ) { | |
| 4009 | + translated = mainwpTranslations[strippedText]; | |
| 4010 | + } | |
| 4011 | + | |
| 4012 | + if (args.length === 0) { | |
| 4013 | + return translated; | |
| 4014 | + } | |
| 4015 | + | |
| 4016 | + // Single-pass replacement to avoid placeholder collision issues | |
| 4017 | + return translated.replace(/%(\d+)/g, (match, index) => { | |
| 4018 | + const argIdx = parseInt(index, 10) - 1; | |
| 4019 | + return args[argIdx] !== undefined ? args[argIdx] : match; | |
| 4020 | + }); | |
| 4021 | +}; | |
| 4022 | + | |
| 4023 | +// Deprecated. Remove in a future release. | |
| 4024 | +if (typeof globalThis.__ !== 'function') { | |
| 4025 | + globalThis.__ = function (text, ...args) { | |
| 4026 | + return globalThis.MainWP.I18n.t(text, ...args); | |
| 4027 | + }; | |
| 3157 | 4028 | } |
| 3158 | 4029 | |
| 3159 | -mainwp_secure_data = function (data, includeDts) { | |
| 3160 | - if (data['action'] == undefined) | |
| 3161 | - return data; | |
| 4030 | +globalThis.mainwp_secure_data = function (data, includeDts) { | |
| 4031 | + if (data['action'] == undefined) | |
| 4032 | + return data; | |
| 3162 | 4033 | |
| 3163 | - if (security_nonces[data['action']] == undefined) | |
| 4034 | + if (security_nonces[data['action']] == undefined) | |
| 4035 | + return data; | |
| 4036 | + | |
| 4037 | + data['security'] = security_nonces[data['action']]; | |
| 4038 | + if (includeDts) | |
| 4039 | + data['dts'] = Math.round(Date.now() / 1000); | |
| 3164 | 4040 | 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 | 4041 | }; |
| 3171 | 4042 | |
| 3172 | 4043 | |
| 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); | |
| 4044 | +globalThis.mainwp_uid = function () { | |
| 4045 | + // always start with a letter (for DOM friendlyness) | |
| 4046 | + let idstr = String.fromCodePoint(Math.floor((Math.random() * 25) + 65)); // NOSONAR - safe, it's id. | |
| 4047 | + do { | |
| 4048 | + // between numbers and characters (48 is 0 and 90 is Z (42-48 = 90) | |
| 4049 | + let ascicode = Math.floor((Math.random() * 42) + 48); // NOSONAR - safe, it's id. | |
| 4050 | + if (ascicode < 58 || ascicode > 64) { | |
| 4051 | + // exclude all chars between : (58) and @ (64) | |
| 4052 | + idstr += String.fromCodePoint(ascicode); | |
| 4053 | + } | |
| 4054 | + } while (idstr.length < 32); | |
| 3184 | 4055 | |
| 3185 | - return (idstr); | |
| 4056 | + return (idstr); | |
| 3186 | 4057 | }; |
| 3187 | 4058 | |
| 3188 | -scrollToElement = function () { | |
| 3189 | - jQuery('html,body').animate({ | |
| 3190 | - scrollTop: 0 | |
| 3191 | - }, 1000); | |
| 4059 | +globalThis.scrollToElement = function () { | |
| 4060 | + jQuery('html,body').animate({ | |
| 4061 | + scrollTop: 0 | |
| 4062 | + }, 1000); | |
| 3192 | 4063 | |
| 3193 | - return false; | |
| 4064 | + return false; | |
| 3194 | 4065 | }; |
| 3195 | 4066 | |
| 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 | - }); | |
| 4067 | +jQuery(function () { | |
| 4068 | + jQuery('#backup_filename').on('keypress', function (e) { | |
| 4069 | + let chr = String.fromCodePoint(e.which); | |
| 4070 | + return !"$^&*/".includes(chr); | |
| 4071 | + }); | |
| 4072 | + jQuery('#backup_filename').on('change', function () { | |
| 4073 | + let value = jQuery(this).val(); | |
| 4074 | + let notAllowed = ['$', '^', '&', '*', '/']; | |
| 4075 | + for (let char of notAllowed) { | |
| 4076 | + if (value.includes(char)) { | |
| 4077 | + value = value.replaceAll(char, ''); | |
| 4078 | + jQuery(this).val(value); | |
| 4079 | + } | |
| 4080 | + } | |
| 4081 | + }); | |
| 3212 | 4082 | }); |
| 3213 | 4083 | |
| 3214 | 4084 | /* |
| 3215 | 4085 | * Server Info |
| @@ -3214,1063 +4084,1641 @@ | ||
| 3214 | 4084 | /* |
| 3215 | 4085 | * Server Info |
| 3216 | 4086 | */ |
| 3217 | 4087 | |
| 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 | - }); | |
| 4088 | +globalThis.serverinfo_prepare_download_info = function (communi) { | |
| 4089 | + let report = ""; | |
| 4090 | + jQuery('.mainwp-system-info-table thead, .mainwp-system-info-table tbody').each(function () { | |
| 4091 | + let td_len = [35, 55, 45, 12, 12]; | |
| 4092 | + let th_count = 0; | |
| 4093 | + let i; | |
| 4094 | + if (jQuery(this).is('thead')) { | |
| 4095 | + i = 0; | |
| 4096 | + report = report + "\n### "; | |
| 4097 | + th_count = jQuery(this).find('th:not(".mwp-not-generate-row")').length; | |
| 4098 | + jQuery(this).find('th:not(".mwp-not-generate-row")').each(function () { | |
| 4099 | + let len = td_len[i]; | |
| 4100 | + if (i == 0 || i == th_count - 1) | |
| 4101 | + len = len - 4; | |
| 4102 | + report = report + jQuery.mwp_strCut(jQuery.mwp_get_serverinfo_export_text(jQuery(this), communi), len, ' '); | |
| 4103 | + i++; | |
| 4104 | + }); | |
| 4105 | + report = report + " ###\n\n"; | |
| 4106 | + } else { | |
| 4107 | + jQuery('tr', jQuery(this)).each(function () { | |
| 4108 | + if (communi && jQuery(this).hasClass('mwp-not-generate-row')) | |
| 4109 | + return; | |
| 4110 | + i = 0; | |
| 4111 | + jQuery(this).find('td:not(".mwp-not-generate-row")').each(function () { | |
| 4112 | + if (jQuery(this).hasClass('mwp-hide-generate-row')) { | |
| 4113 | + report = report + jQuery.mwp_strCut(' ', td_len[i], ' '); | |
| 4114 | + i++; | |
| 4115 | + return; | |
| 4116 | + } | |
| 4117 | + let outputText = jQuery.mwp_get_serverinfo_export_text(jQuery(this), communi); | |
| 4118 | + report = report + jQuery.mwp_strCut(outputText, td_len[i], ' '); | |
| 4119 | + i++; | |
| 4120 | + }); | |
| 4121 | + report = report + "\n"; | |
| 4122 | + }); | |
| 3252 | 4123 | |
| 4124 | + } | |
| 4125 | + }); | |
| 4126 | + | |
| 4127 | + try { | |
| 4128 | + if (communi) { | |
| 4129 | + report = '```' + "\n" + report + "\n" + '```'; | |
| 4130 | + } | |
| 4131 | + jQuery("#download-server-information textarea").val(report).trigger("select"); | |
| 4132 | + } catch { | |
| 4133 | + console.log('Error:'); | |
| 3253 | 4134 | } |
| 3254 | - }); | |
| 4135 | + return false; | |
| 4136 | +} | |
| 3255 | 4137 | |
| 3256 | - try { | |
| 3257 | - if (communi) { | |
| 3258 | - report = '```' + "\n" + report + "\n" + '```'; | |
| 4138 | +jQuery.mwp_get_serverinfo_export_text = function (element, communi) { | |
| 4139 | + let cellExportText = element.attr('data-export-text'); | |
| 4140 | + if (typeof cellExportText !== 'undefined' && cellExportText !== '') { | |
| 4141 | + return cellExportText.trim(); | |
| 3259 | 4142 | } |
| 3260 | - jQuery("#download-server-information textarea").val(report).trigger("select"); | |
| 3261 | - } catch (e) { | |
| 3262 | - console.log('Error:'); | |
| 3263 | - } | |
| 3264 | - return false; | |
| 4143 | + | |
| 4144 | + let descendantExportElement = element.find('[data-export-text]').first(); | |
| 4145 | + if (descendantExportElement.length > 0) { | |
| 4146 | + let descendantExportText = descendantExportElement.attr('data-export-text'); | |
| 4147 | + if (typeof descendantExportText !== 'undefined' && descendantExportText !== '') { | |
| 4148 | + return descendantExportText.trim(); | |
| 4149 | + } | |
| 4150 | + } | |
| 4151 | + | |
| 4152 | + let communityValue = element.attr('data-community-value'); | |
| 4153 | + if (communi && typeof communityValue !== 'undefined') { | |
| 4154 | + return communityValue; | |
| 4155 | + } | |
| 4156 | + | |
| 4157 | + return element.text().trim(); | |
| 3265 | 4158 | } |
| 3266 | 4159 | |
| 3267 | 4160 | 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; | |
| 4161 | + serverinfo_prepare_download_info(false); | |
| 4162 | + let server_info = jQuery('#download-server-information textarea').val(); | |
| 4163 | + let blob = new Blob([server_info], { type: "text/plain;charset=utf-8" }); | |
| 4164 | + saveAs(blob, "mainwp-system-report.txt"); | |
| 4165 | + return false; | |
| 3273 | 4166 | }); |
| 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; | |
| 4167 | +jQuery(document).on('click', '#mainwp-download-community-system-report', function () { | |
| 4168 | + serverinfo_prepare_download_info(true); | |
| 4169 | + let server_info = jQuery('#download-server-information textarea').val(); | |
| 4170 | + let blob = new Blob([server_info], { type: "text/plain;charset=utf-8" }); | |
| 4171 | + saveAs(blob, "mainwp-community-system-report.txt"); | |
| 4172 | + return false; | |
| 3287 | 4173 | }); |
| 3288 | 4174 | |
| 3289 | 4175 | |
| 3290 | 4176 | 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; | |
| 4177 | + let o = i.toString(); | |
| 4178 | + if (!s) { | |
| 4179 | + s = '0'; | |
| 3301 | 4180 | } |
| 3302 | - } | |
| 3303 | - return o; | |
| 4181 | + while (o.length < Number.parseInt(l)) { | |
| 4182 | + // empty | |
| 4183 | + if (w == 'undefined') { | |
| 4184 | + o = s + o; | |
| 4185 | + } else { | |
| 4186 | + o = o + s; | |
| 4187 | + } | |
| 4188 | + } | |
| 4189 | + return o; | |
| 3304 | 4190 | }; |
| 3305 | 4191 | |
| 3306 | -updateExcludedFolders = function () { | |
| 3307 | - var excludedBackupFiles = jQuery('#excludedBackupFiles').html(); | |
| 3308 | - jQuery('#mainwp-kbl-content').val(excludedBackupFiles == undefined ? '' : excludedBackupFiles); | |
| 4192 | +globalThis.updateExcludedFolders = function () { | |
| 4193 | + let excludedBackupFiles = jQuery('#excludedBackupFiles').html(); | |
| 4194 | + jQuery('#mainwp-kbl-content').val(excludedBackupFiles == undefined ? '' : excludedBackupFiles); | |
| 3309 | 4195 | |
| 3310 | - var excludedCacheFiles = jQuery('#excludedCacheFiles').html(); | |
| 3311 | - jQuery('#mainwp-kcl-content').val(excludedCacheFiles == undefined ? '' : excludedCacheFiles); | |
| 4196 | + let excludedCacheFiles = jQuery('#excludedCacheFiles').html(); | |
| 4197 | + jQuery('#mainwp-kcl-content').val(excludedCacheFiles == undefined ? '' : excludedCacheFiles); | |
| 3312 | 4198 | |
| 3313 | - var excludedNonWPFiles = jQuery('#excludedNonWPFiles').html(); | |
| 3314 | - jQuery('#mainwp-nwl-content').val(excludedNonWPFiles == undefined ? '' : excludedNonWPFiles); | |
| 4199 | + let excludedNonWPFiles = jQuery('#excludedNonWPFiles').html(); | |
| 4200 | + jQuery('#mainwp-nwl-content').val(excludedNonWPFiles == undefined ? '' : excludedNonWPFiles); | |
| 3315 | 4201 | }; |
| 3316 | 4202 | |
| 3317 | 4203 | |
| 3318 | 4204 | 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; | |
| 4205 | + let notice = jQuery(this).attr('notice'); | |
| 4206 | + jQuery(this).closest('.ui.message').fadeOut(500); | |
| 4207 | + let data = mainwp_secure_data({ | |
| 4208 | + action: 'mainwp_events_notice_hide', | |
| 4209 | + notice: notice | |
| 4210 | + }); | |
| 4211 | + jQuery.post(ajaxurl, data, function () { | |
| 4212 | + }); | |
| 4213 | + return false; | |
| 3328 | 4214 | }); |
| 3329 | 4215 | |
| 3330 | 4216 | // Turn On child plugin auto update |
| 3331 | 4217 | 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; | |
| 4218 | + jQuery(this).attr('disabled', 'true'); | |
| 4219 | + let data = mainwp_secure_data({ | |
| 4220 | + action: 'mainwp_autoupdate_and_trust_child' | |
| 4221 | + }); | |
| 4222 | + jQuery.post(ajaxurl, data, function (res) { | |
| 4223 | + if (res == 'ok') { | |
| 4224 | + location.reload(true); | |
| 4225 | + } else { | |
| 4226 | + jQuery(this).prop("disabled", false); | |
| 4227 | + } | |
| 4228 | + }); | |
| 4229 | + return false; | |
| 3344 | 4230 | }); |
| 3345 | 4231 | |
| 3346 | 4232 | // Hide installation warning |
| 3347 | 4233 | 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; | |
| 4234 | + jQuery(this).closest('.ui.message').fadeOut("slow"); | |
| 4235 | + let data = mainwp_secure_data({ | |
| 4236 | + action: 'mainwp_installation_warning_hide' | |
| 4237 | + }); | |
| 4238 | + jQuery.post(ajaxurl, data, function () { }); | |
| 4239 | + return false; | |
| 3354 | 4240 | }); |
| 3355 | 4241 | |
| 3356 | 4242 | jQuery(document).on('click', '.mainwp-notice-hide', function () { |
| 3357 | - jQuery(this).closest('.ui.message').fadeOut("slow"); | |
| 3358 | - return false; | |
| 4243 | + jQuery(this).closest('.ui.message').fadeOut("slow"); | |
| 4244 | + return false; | |
| 3359 | 4245 | }); |
| 3360 | 4246 | |
| 3361 | 4247 | // Hide after installtion notices (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning) |
| 3362 | 4248 | 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; | |
| 4249 | + let notice_id = jQuery(this).attr('notice-id'); | |
| 4250 | + let shortterm = jQuery(this).attr('shortterm-notice'); | |
| 4251 | + | |
| 4252 | + jQuery(this).closest('.ui.message').fadeOut("slow"); | |
| 4253 | + let data = { | |
| 4254 | + action: 'mainwp_notice_status_update' | |
| 4255 | + }; | |
| 4256 | + data['notice_id'] = notice_id; | |
| 4257 | + if(shortterm === '1'){ | |
| 4258 | + data['short_term'] = 1; | |
| 4259 | + } | |
| 4260 | + jQuery.post(ajaxurl, mainwp_secure_data(data), function () { }); | |
| 4261 | + return false; | |
| 3371 | 4262 | }); |
| 3372 | 4263 | |
| 3373 | 4264 | |
| 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; | |
| 4265 | +globalThis.mainwp_notice_dismiss = function (notice_id, time_set) { | |
| 4266 | + let data = { | |
| 4267 | + action: 'mainwp_notice_status_update' | |
| 4268 | + }; | |
| 4269 | + data['notice_id'] = notice_id; | |
| 4270 | + if (time_set !== undefined) { | |
| 4271 | + data['time_set'] = time_set ? 1 : 0; | |
| 4272 | + } | |
| 4273 | + jQuery.post(ajaxurl, mainwp_secure_data(data), function () { | |
| 4274 | + }); | |
| 4275 | + return false; | |
| 3386 | 4276 | } |
| 3387 | 4277 | |
| 3388 | 4278 | |
| 3389 | 4279 | 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; | |
| 4280 | + jQuery(this).closest('tr').fadeOut("slow"); | |
| 4281 | + let data = mainwp_secure_data({ | |
| 4282 | + action: 'mainwp_dismiss_activate_notice', | |
| 4283 | + slug: jQuery(this).closest('tr').attr('slug') | |
| 4284 | + }); | |
| 4285 | + jQuery.post(ajaxurl, data, function () { | |
| 4286 | + }); | |
| 4287 | + return false; | |
| 3398 | 4288 | }); |
| 3399 | 4289 | |
| 3400 | 4290 | 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; | |
| 4291 | + let notice_id = jQuery(this).attr('notice-id'); | |
| 4292 | + jQuery(this).closest('.ui.message').fadeOut("slow"); | |
| 4293 | + let data = { | |
| 4294 | + action: 'mainwp_notice_status_update' | |
| 4295 | + }; | |
| 4296 | + data['notice_id'] = notice_id; | |
| 4297 | + jQuery.post(ajaxurl, mainwp_secure_data(data), function () { }); | |
| 4298 | + return false; | |
| 3409 | 4299 | }); |
| 3410 | 4300 | |
| 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; | |
| 4301 | +jQuery(document).on('click', '#mainwp-dismiss-sites-changes-actions-button', function () { | |
| 4302 | + mainwp_confirm('You are about to dismiss the selected changes?', function () { | |
| 4303 | + mainwp_delete_nonmainwp_data_start(); | |
| 4304 | + }); | |
| 4305 | + return false; | |
| 3422 | 4306 | }); |
| 3423 | 4307 | |
| 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; | |
| 4308 | +let mainwp_managesites_update_childsite_value = function (siteId, uniqueId) { | |
| 4309 | + let data = mainwp_secure_data({ | |
| 4310 | + action: 'mainwp_updatechildsite_value', | |
| 4311 | + site_id: siteId, | |
| 4312 | + unique_id: uniqueId | |
| 4313 | + }); | |
| 4314 | + jQuery.post(ajaxurl, data, function () { | |
| 4315 | + }); | |
| 4316 | + return false; | |
| 3440 | 4317 | }; |
| 3441 | 4318 | |
| 3442 | 4319 | 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(); | |
| 4320 | + let filter = jQuery(this).val(); | |
| 4321 | + let groupItems = jQuery(this).parent().parent().find('li.managegroups-listitem'); | |
| 4322 | + for (let igr of groupItems) { | |
| 4323 | + let currentElement = jQuery(igr); | |
| 4324 | + if (currentElement.hasClass('managegroups-group-add')) { | |
| 4325 | + continue; | |
| 4326 | + } | |
| 4327 | + let value = currentElement.find('span.text').text(); | |
| 4328 | + if (value.includes(filter)) { | |
| 4329 | + currentElement.show(); | |
| 4330 | + } else { | |
| 4331 | + currentElement.hide(); | |
| 4332 | + } | |
| 3454 | 4333 | } |
| 3455 | - } | |
| 3456 | 4334 | }); |
| 3457 | 4335 | |
| 3458 | 4336 | // for normal checkboxes |
| 3459 | 4337 | 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'); | |
| 4338 | + let $this = jQuery(this), $table, controlChecked = $this.prop('checked'); | |
| 3463 | 4339 | |
| 3464 | - if ($table.length == 0) | |
| 3465 | - return false; | |
| 4340 | + $table = $this.closest('.dt-scroll').find('.dt-scroll-body table'); // for dt with scroll enabled. | |
| 3466 | 4341 | |
| 3467 | - $table.children('tbody').filter(':visible') | |
| 3468 | - .children().children('.check-column').find(':checkbox') | |
| 3469 | - .prop('checked', function () { | |
| 3470 | - if (jQuery(this).is(':hidden,:disabled')) { | |
| 4342 | + // if no scrollable table. | |
| 4343 | + if ($table.length == 0) { | |
| 4344 | + $table = $this.closest('table.table.dataTable'); | |
| 4345 | + } | |
| 4346 | + | |
| 4347 | + if ($table.length == 0) | |
| 3471 | 4348 | return false; |
| 3472 | - } | |
| 3473 | - if (controlChecked) { | |
| 3474 | - return true; | |
| 3475 | - } | |
| 3476 | - return false; | |
| 3477 | - }); | |
| 3478 | 4349 | |
| 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 | - }); | |
| 4350 | + $table.children('tbody').filter(':visible') | |
| 4351 | + .children().children('.check-column').find(':checkbox') | |
| 4352 | + .prop('checked', function () { | |
| 4353 | + if (jQuery(this).is(':hidden,:disabled')) { | |
| 4354 | + return false; | |
| 4355 | + } | |
| 4356 | + if (controlChecked) { | |
| 4357 | + jQuery(this).closest('tr').addClass('selected'); | |
| 4358 | + return true; | |
| 4359 | + } | |
| 4360 | + jQuery(this).closest('tr').removeClass('selected'); | |
| 4361 | + return false; | |
| 4362 | + }); | |
| 4363 | + | |
| 4364 | + $table.children('thead, tfoot').filter(':visible') | |
| 4365 | + .children().children('.check-column').find(':checkbox') | |
| 4366 | + .prop('checked', function () { | |
| 4367 | + if (controlChecked) { | |
| 4368 | + jQuery(this).closest('tr').addClass('selected'); | |
| 4369 | + return true; | |
| 4370 | + } | |
| 4371 | + jQuery(this).closest('tr').removeClass('selected'); | |
| 4372 | + return false; | |
| 4373 | + }); | |
| 4374 | + let dtApi = jQuery($table).dataTable().api(); | |
| 4375 | + let setStatus = controlChecked ? 'selected' : 'deselected'; | |
| 4376 | + mainwp_datatable_fix_to_update_selected_rows_status(dtApi, setStatus); | |
| 3487 | 4377 | }); |
| 3488 | 4378 | |
| 3489 | 4379 | |
| 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; | |
| 4380 | +jQuery(document).on('change', '.cb-select-all-parent-top, .cb-select-all-parent-bottom', function () { | |
| 4381 | + | |
| 4382 | + let parentChecked = jQuery(this).is(":checked"); | |
| 4383 | + let parentSelector = jQuery(this).attr('cb-parent-selector') ?? false; | |
| 4384 | + | |
| 4385 | + if (false === parentSelector) { | |
| 4386 | + return; | |
| 3502 | 4387 | } |
| 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 | - }); | |
| 4388 | + jQuery(parentSelector + ' .ui.checkbox').find(':checkbox') | |
| 4389 | + .prop('checked', function () { | |
| 4390 | + if (parentChecked) { | |
| 4391 | + jQuery(this).closest('tr').addClass('selected'); | |
| 4392 | + return true; | |
| 4393 | + } | |
| 4394 | + jQuery(this).closest('tr').removeClass('selected'); | |
| 4395 | + return false; | |
| 4396 | + }); | |
| 3509 | 4397 | |
| 4398 | +}); | |
| 3510 | 4399 | |
| 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>'); | |
| 4400 | +jQuery(function ($) { | |
| 4401 | + // Trigger the bulk actions | |
| 4402 | + $('#mainwp_sites_changes_bulk_dismiss_selected_btn').on('click', function () { | |
| 4403 | + if (jQuery('#mainwp-module-log-records-body-table tr').find('input[type="checkbox"]:checked').length == 0) { | |
| 4404 | + return; | |
| 3534 | 4405 | } |
| 3535 | - }, 'json'); | |
| 4406 | + let confirmMsg = MainWP.I18n.t("You are about to dismiss the selected changes?"); | |
| 4407 | + mainwp_confirm(confirmMsg, function () { mainwp_sites_changes_actions_bulk_action('dismiss-selected'); }); | |
| 3536 | 4408 | }); |
| 3537 | 4409 | |
| 3538 | - return false; | |
| 3539 | - }); | |
| 4410 | + $('#mainwp_sites_changes_bulk_dismiss_all_btn').on('click', function () { | |
| 4411 | + let confirmMsg = MainWP.I18n.t("You are about to dismiss all changes?"); | |
| 4412 | + mainwp_confirm(confirmMsg, function () { mainwp_sites_changes_actions_bulk_action('dismiss-all'); }); | |
| 4413 | + }); | |
| 3540 | 4414 | |
| 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?"); | |
| 4415 | + // Trigger the bulk actions | |
| 4416 | + $('#mainwp_widget_sites_changes_bulk_dismiss_selected_btn').on('click', function () { | |
| 4417 | + if (jQuery('#mainwp-module-log-records-body-table tr').find('input[type="checkbox"]:checked').length == 0) { | |
| 4418 | + return; | |
| 4419 | + } | |
| 4420 | + let confirmMsg = MainWP.I18n.t("You are about to dismiss the selected changes?"); | |
| 4421 | + mainwp_confirm(confirmMsg, function () { mainwp_sites_changes_actions_bulk_action('dismiss-selected', 'widget'); }); | |
| 4422 | + }); | |
| 3544 | 4423 | |
| 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 | - } | |
| 4424 | + $(document).on('click', '.insights-actions-row-dismiss', function () { | |
| 4425 | + return mainwp_insights_row_actions_dismiss(this); | |
| 4426 | + }); | |
| 4427 | + | |
| 4428 | + globalThis.mainwp_sites_changes_update_dismiss_button_state = function () { | |
| 4429 | + let checkedCount = jQuery('#mainwp-module-log-records-body-table tr').find('input[type="checkbox"]:checked').length; | |
| 4430 | + let totalRows = jQuery('#mainwp-module-log-records-body-table tr').not('.dt-empty').length; | |
| 4431 | + | |
| 4432 | + if (checkedCount > 0) { | |
| 4433 | + jQuery('#mainwp_sites_changes_bulk_dismiss_selected_btn').removeClass('disabled'); | |
| 3563 | 4434 | } else { |
| 3564 | - row.html('<td></td><td colspan="999"><i class="times red icon"></i> Failed. Please try again.</td>'); | |
| 4435 | + jQuery('#mainwp_sites_changes_bulk_dismiss_selected_btn').addClass('disabled'); | |
| 3565 | 4436 | } |
| 3566 | - }, 'json'); | |
| 4437 | + | |
| 4438 | + if (totalRows > 0) { | |
| 4439 | + jQuery('#mainwp_sites_changes_bulk_dismiss_all_btn').removeClass('disabled'); | |
| 4440 | + } else { | |
| 4441 | + jQuery('#mainwp_sites_changes_bulk_dismiss_all_btn').addClass('disabled'); | |
| 4442 | + } | |
| 4443 | + } | |
| 4444 | + | |
| 4445 | + jQuery(document).on('change', '#mainwp-module-log-records-body-table input[type="checkbox"]', function () { | |
| 4446 | + mainwp_sites_changes_update_dismiss_button_state(); | |
| 3567 | 4447 | }); |
| 3568 | - return false; | |
| 3569 | - }); | |
| 3570 | 4448 | |
| 4449 | + jQuery(document).on('change', '#cb-select-all-top, #cb-select-all-bottom', function () { | |
| 4450 | + mainwp_sites_changes_update_dismiss_button_state(); | |
| 4451 | + }); | |
| 3571 | 4452 | }) |
| 3572 | 4453 | |
| 4454 | +let mainwp_insights_row_actions_dismiss = function (obj) { | |
| 4455 | + let row = jQuery(obj).closest('tr'); | |
| 4456 | + let confirmMsg = MainWP.I18n.t("You are about to dismiss the selected change?"); | |
| 3573 | 4457 | |
| 4458 | + const renderMessage = (icon, message) => { | |
| 4459 | + row.html( | |
| 4460 | + '<td></td><td colspan="999"><i class="' + | |
| 4461 | + icon + | |
| 4462 | + ' icon"></i> ' + | |
| 4463 | + message + | |
| 4464 | + '</td>' | |
| 4465 | + ); | |
| 4466 | + }; | |
| 4467 | + | |
| 4468 | + const updateDismissButtonState = () => { | |
| 4469 | + if (typeof mainwp_sites_changes_update_dismiss_button_state !== 'undefined') { | |
| 4470 | + mainwp_sites_changes_update_dismiss_button_state(); | |
| 4471 | + } | |
| 4472 | + }; | |
| 4473 | + | |
| 4474 | + const fadeRow = () => { | |
| 4475 | + setTimeout(() => { | |
| 4476 | + jQuery(row).fadeOut('slow', updateDismissButtonState); | |
| 4477 | + }, 2000); | |
| 4478 | + }; | |
| 4479 | + | |
| 4480 | + let _callback = () => { | |
| 4481 | + row.html('<td></td><td colspan="999"><i class="notched circle loading icon"></i> Please wait...</td>'); | |
| 4482 | + let data = mainwp_secure_data({ | |
| 4483 | + action: 'mainwp_insight_events_dismiss_actions', | |
| 4484 | + log_id: jQuery(row).attr('log-id') | |
| 4485 | + }); | |
| 4486 | + jQuery.post(ajaxurl, data, function (response) { | |
| 4487 | + if (response?.success !== 'yes') { | |
| 4488 | + | |
| 4489 | + if (response?.error) { | |
| 4490 | + renderMessage('times red', response.error); | |
| 4491 | + } else { | |
| 4492 | + renderMessage('times red', 'The change could not be dismissed.'); | |
| 4493 | + } | |
| 4494 | + | |
| 4495 | + return; | |
| 4496 | + } | |
| 4497 | + renderMessage('green check', 'The change has been dismissed.'); | |
| 4498 | + fadeRow(); | |
| 4499 | + }, 'json'); | |
| 4500 | + }; | |
| 4501 | + mainwp_confirm(confirmMsg, _callback); | |
| 4502 | + return false; | |
| 4503 | +} | |
| 4504 | + | |
| 4505 | + | |
| 3574 | 4506 | // 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 | - } | |
| 4507 | +let mainwp_sites_changes_actions_bulk_action = function (act, which_act) { | |
| 4508 | + mainwpVars.bulkInstallTotal = 0; | |
| 4509 | + bulkInstallCurrentThreads = 0; | |
| 4510 | + bulkInstallDone = 0; | |
| 4511 | + mainwpVars.bulkActionIndent = ''; | |
| 4512 | + if (which_act === 'widget') { | |
| 4513 | + mainwpVars.bulkActionIndent = 'widget'; | |
| 4514 | + } | |
| 4515 | + if (act === 'dismiss-selected') { | |
| 4516 | + jQuery('#mainwp_sites_changes_bulk_dismiss_selected_btn').addClass('disabled'); | |
| 4517 | + let selector = '#mainwp-module-log-records-body-table tr'; | |
| 4518 | + mainwpVars.bulkInstallTotal = jQuery(selector).find('input[type="checkbox"]:checked').length; | |
| 4519 | + jQuery(selector).addClass('queue'); | |
| 4520 | + if (jQuery(selector).length) { | |
| 4521 | + if (mainwpVars.bulkActionIndent === 'widget') { | |
| 4522 | + jQuery('#mainwp_widget_sites_changes_bulk_dismiss_selected_btn').addClass('disabled'); | |
| 4523 | + } else { | |
| 4524 | + jQuery('#mainwp_sites_changes_bulk_dismiss_selected_btn').addClass('disabled'); | |
| 4525 | + } | |
| 4526 | + } | |
| 4527 | + mainwp_sites_changes_actions_dismiss_start_next(selector); | |
| 4528 | + } else if (act === 'dismiss-all') { | |
| 4529 | + jQuery('#mainwp_sites_changes_bulk_dismiss_all_btn').addClass('disabled'); | |
| 4530 | + mainwp_sites_changes_actions_dismiss_all(); | |
| 4531 | + } | |
| 3592 | 4532 | } |
| 3593 | 4533 | |
| 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; | |
| 4534 | +let mainwp_sites_changes_actions_dismiss_start_next = function (selector) { | |
| 4535 | + while ((objProcess = jQuery(selector + '.queue:first')) && (objProcess.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { // NOSONAR - modified outside the function. | |
| 4536 | + objProcess.removeClass('queue'); | |
| 4537 | + if (objProcess.closest('tr').find('input[type="checkbox"]:checked').length == 0) { | |
| 4538 | + continue; | |
| 4539 | + } | |
| 4540 | + mainwp_sites_changes_actions_dismiss_specific(objProcess, selector); | |
| 3602 | 4541 | } |
| 3603 | - mainwp_non_mainwp_actions_delete_specific(objProcess, selector, true); | |
| 3604 | - } | |
| 4542 | + | |
| 4543 | + if (mainwpVars.bulkInstallTotal == bulkInstallDone) { | |
| 4544 | + if (mainwpVars.bulkActionIndent === 'widget') { | |
| 4545 | + jQuery('#mainwp_widget_sites_changes_bulk_dismiss_selected_btn').removeClass('disabled'); | |
| 4546 | + } else { | |
| 4547 | + jQuery('#mainwp_sites_changes_bulk_dismiss_selected_btn').removeClass('disabled'); | |
| 4548 | + } | |
| 4549 | + if (typeof mainwp_sites_changes_update_dismiss_button_state !== 'undefined') { | |
| 4550 | + mainwp_sites_changes_update_dismiss_button_state(); | |
| 4551 | + } | |
| 4552 | + } | |
| 3605 | 4553 | } |
| 3606 | 4554 | |
| 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; | |
| 4555 | +let mainwp_sites_changes_actions_dismiss_specific = function (pObj, selector) { | |
| 4556 | + let row = pObj.closest('tr'); | |
| 4557 | + let act_id = jQuery(row).attr('log-id'); | |
| 3611 | 4558 | |
| 3612 | - if (bulk) { | |
| 3613 | 4559 | bulkInstallCurrentThreads++; |
| 3614 | - } | |
| 3615 | 4560 | |
| 3616 | - var data = mainwp_secure_data({ | |
| 3617 | - action: 'mainwp_non_mainwp_changes_delete_actions', | |
| 3618 | - act_id: act_id, | |
| 3619 | - }); | |
| 4561 | + let data = mainwp_secure_data({ | |
| 4562 | + action: 'mainwp_insight_events_dismiss_actions', | |
| 4563 | + log_id: act_id | |
| 4564 | + }); | |
| 3620 | 4565 | |
| 3621 | - row.html('<td></td><td colspan="999"><i class="notched circle loading icon"></i> Please wait...</td>'); | |
| 4566 | + row.html('<td></td><td colspan="999"><i class="notched circle loading icon"></i> Please wait...</td>'); | |
| 3622 | 4567 | |
| 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 | - } | |
| 4568 | + jQuery.post(ajaxurl, data, function (response) { | |
| 4569 | + pObj.removeClass('queue'); | |
| 4570 | + if (response) { | |
| 4571 | + if (response['error']) { | |
| 4572 | + row.html('<td></td><td colspan="999"><i class="times red icon"></i> ' + response['error'] + '</td>'); | |
| 4573 | + } else if (response['success'] == 'yes') { | |
| 4574 | + row.html('<td></td><td colspan="999"><i class="green check icon"></i> The change has been dismissed.</td>'); | |
| 4575 | + setTimeout(function () { | |
| 4576 | + jQuery(row).fadeOut("slow"); | |
| 4577 | + }, 2000); | |
| 4578 | + } else { | |
| 4579 | + row.html('<td></td><td colspan="999"><i class="times red icon"></i> Failed. Please try again.</td>'); | |
| 4580 | + } | |
| 4581 | + } else { | |
| 4582 | + row.html('<td></td><td colspan="999"><i class="times red icon"></i> Failed. Please try again.</td>'); | |
| 4583 | + } | |
| 3639 | 4584 | |
| 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 | - } | |
| 4585 | + bulkInstallCurrentThreads--; | |
| 4586 | + bulkInstallDone++; | |
| 4587 | + mainwp_sites_changes_actions_dismiss_start_next(selector); | |
| 4588 | + }, 'json'); | |
| 4589 | + return false; | |
| 4590 | +} | |
| 3650 | 4591 | |
| 3651 | - }, 'json'); | |
| 3652 | - return false; | |
| 4592 | +let mainwp_sites_changes_actions_dismiss_all = function () { | |
| 4593 | + let data = mainwp_secure_data({ | |
| 4594 | + action: 'mainwp_insight_events_dismiss_all', | |
| 4595 | + }); | |
| 4596 | + mainwp_showhide_message('mainwp-message-zone-top', '<i class="notched circle loading icon"></i> Please wait...', ''); | |
| 4597 | + jQuery.post(ajaxurl, data, function (response) { | |
| 4598 | + if (response) { | |
| 4599 | + if (response['error']) { | |
| 4600 | + mainwp_showhide_message('mainwp-message-zone-top', response['error'], 'red'); | |
| 4601 | + } else if (response['success'] == 'yes') { | |
| 4602 | + mainwp_showhide_message('mainwp-message-zone-top', 'All changes have been dismissed.', 'green'); | |
| 4603 | + setTimeout(function () { | |
| 4604 | + mainwp_forceReload(); | |
| 4605 | + }, 2000); | |
| 4606 | + } else { | |
| 4607 | + mainwp_showhide_message('mainwp-message-zone-top', 'Failed. Please try again.', 'red'); | |
| 4608 | + } | |
| 4609 | + } else { | |
| 4610 | + mainwp_showhide_message('mainwp-message-zone-top', 'Failed. Please try again.', 'red'); | |
| 4611 | + } | |
| 4612 | + }, 'json'); | |
| 4613 | + return false; | |
| 4614 | + | |
| 3653 | 4615 | } |
| 3654 | 4616 | |
| 3655 | 4617 | |
| 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; | |
| 4618 | +globalThis.mainwp_datatable_fix_to_update_selected_rows_status = function (dtApi, setStatus) { | |
| 4619 | + if (dtApi) { | |
| 4620 | + if ('selected' === setStatus) { | |
| 4621 | + dtApi.rows('.selected').select(); // update selected status. | |
| 4622 | + } else if ('deselected' === setStatus) { | |
| 4623 | + dtApi.rows().deselect(); // update deselected status. | |
| 4624 | + } | |
| 3665 | 4625 | } |
| 3666 | - mainwp_non_mainwp_actions_dismiss_specific(objProcess, selector, true); | |
| 3667 | - } | |
| 3668 | 4626 | } |
| 3669 | 4627 | |
| 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; | |
| 4628 | +globalThis.mainwp_datatable_fix_to_update_rows_state = function (tblSelect) { | |
| 4629 | + if (jQuery(tblSelect).length) { | |
| 4630 | + let $table = jQuery(tblSelect); | |
| 3674 | 4631 | |
| 3675 | - if (bulk) { | |
| 3676 | - bulkInstallCurrentThreads++; | |
| 3677 | - } | |
| 4632 | + let dtApi = jQuery($table).dataTable().api(); // NOTE: not use DataTable(). | |
| 3678 | 4633 | |
| 3679 | - var data = mainwp_secure_data({ | |
| 3680 | - action: 'mainwp_non_mainwp_changes_dismiss_actions', | |
| 3681 | - act_id: act_id, | |
| 3682 | - }); | |
| 4634 | + mainwp_datatable_fix_to_update_selected_rows_status(dtApi, 'deselected'); // clear saved state. | |
| 3683 | 4635 | |
| 3684 | - row.html('<td></td><td colspan="999"><i class="notched circle loading icon"></i> Please wait...</td>'); | |
| 4636 | + $table.children('tbody').filter(':visible').find('tr').each(function () { | |
| 4637 | + if (jQuery(this).children('.check-column').find(':checkbox').is(':checked')) { | |
| 4638 | + jQuery(this).addClass('selected'); | |
| 4639 | + } else if (jQuery(this).hasClass('selected')) { | |
| 4640 | + jQuery(this).removeClass('selected'); | |
| 4641 | + } | |
| 4642 | + }); | |
| 3685 | 4643 | |
| 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>'); | |
| 4644 | + mainwp_datatable_fix_to_update_selected_rows_status(dtApi, 'selected'); // to update selected state. | |
| 3701 | 4645 | } |
| 4646 | +} | |
| 3702 | 4647 | |
| 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 | - } | |
| 4648 | +globalThis.mainwp_datatable_fix_reorder_selected_rows_status = function () { | |
| 4649 | + jQuery('.table.dataTable tbody').filter(':visible').children('tr.selected').find(':checkbox').prop('checked', true); | |
| 4650 | +}; | |
| 4651 | + | |
| 4652 | +// fix menu overflow with scroll tables. | |
| 4653 | +globalThis.mainwp_datatable_fix_menu_overflow = function (pTableSelector, pTop, pRight) { | |
| 4654 | + if (pTableSelector === undefined) { | |
| 4655 | + console.warn('mainwp_datatable_fix_menu_overflow: requires params - $pTableSelector'); | |
| 3712 | 4656 | } |
| 4657 | + let dtScrollBdCls = '.dt-scroll-body'; | |
| 4658 | + let dtScrollCls = '.dt-scroll'; | |
| 4659 | + let fix_overflow = jQuery('.mainwp-content-wrap').attr('menu-overflow'); | |
| 4660 | + jQuery(document).on('click', 'table td.check-column.dtr-control', function () { | |
| 4661 | + if (jQuery(this).parent().hasClass('parent')) { | |
| 4662 | + let chilRow = jQuery(this).parent().next(); | |
| 4663 | + jQuery(chilRow).find('.ui.dropdown').dropdown(); | |
| 4664 | + mainwp_datatable_fix_child_menu_overflow(chilRow, fix_overflow); | |
| 4665 | + } | |
| 4666 | + }); | |
| 4667 | + let tblSelect = pTableSelector ?? 'table'; | |
| 3713 | 4668 | |
| 3714 | - }, 'json'); | |
| 3715 | - return false; | |
| 3716 | -} | |
| 4669 | + // to prevent double events. | |
| 4670 | + jQuery(tblSelect + ' tr td .ui.right.pointing.dropdown').each(function () { | |
| 4671 | + let parentTB = jQuery(this).closest('table'); | |
| 4672 | + if (parentTB.attr('fixed-menu-overflow') === undefined) { | |
| 4673 | + parentTB.attr('fixed-menu-overflow', 'no'); // to init click menu events. | |
| 4674 | + } | |
| 4675 | + }); | |
| 3717 | 4676 | |
| 4677 | + jQuery(tblSelect + ' tr td .ui.left.pointing.dropdown').each(function () { | |
| 4678 | + let parentTB = jQuery(this).closest('table'); | |
| 4679 | + if (parentTB.attr('fixed-menu-overflow') === undefined) { | |
| 4680 | + parentTB.attr('fixed-menu-overflow', 'no'); // to init click menu events. | |
| 4681 | + } | |
| 4682 | + }); | |
| 3718 | 4683 | |
| 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); | |
| 4684 | + // if table selector specific. | |
| 4685 | + if (pTableSelector !== undefined) { | |
| 4686 | + if (jQuery(pTableSelector + '[fixed-menu-overflow="yes"]').length) { | |
| 4687 | + jQuery(pTableSelector + '[fixed-menu-overflow="yes"]').attr('fixed-menu-overflow', 'no'); // to init menus events click. | |
| 4688 | + } | |
| 3727 | 4689 | } |
| 3728 | - }); | |
| 3729 | - var tblSelect = pTableSelector !== '' && pTableSelector !== undefined && pTableSelector !== false ? pTableSelector : 'table'; | |
| 3730 | 4690 | |
| 3731 | - console.log('mainwp_datatable_fix_menu_overflow :: ' + tblSelect); | |
| 3732 | 4691 | |
| 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 | - }); | |
| 4692 | + // Fix the overflow prbolem for the actions menu element (right pointing menu). | |
| 4693 | + jQuery(tblSelect + '[fixed-menu-overflow="no"] tr td .ui.right.pointing.dropdown').on('click', function () { | |
| 4694 | + jQuery(this).closest(dtScrollBdCls).css('position', ''); | |
| 4695 | + jQuery(this).closest(dtScrollCls).css('position', 'relative'); | |
| 4696 | + jQuery(this).css('position', 'static'); | |
| 4697 | + let fix_overflow = jQuery('.mainwp-content-wrap').attr('menu-overflow'); | |
| 4698 | + let position = jQuery(this).position(); | |
| 4699 | + let top = position.top; | |
| 4700 | + let right = 50; | |
| 4701 | + if (fix_overflow > 1) { | |
| 4702 | + position = jQuery(this).closest('td').position(); | |
| 4703 | + top = position.top + 85; //85 | |
| 4704 | + } | |
| 3759 | 4705 | |
| 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; | |
| 4706 | + if (pTop !== undefined) { | |
| 4707 | + top = top + pTop; | |
| 4708 | + } | |
| 4709 | + if (pRight !== undefined) { | |
| 4710 | + right = right + pRight; | |
| 4711 | + } | |
| 3768 | 4712 | |
| 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 | - } | |
| 4713 | + jQuery(this).find('.menu').css('min-width', '170px'); | |
| 4714 | + jQuery(this).find('.menu').css('top', top); | |
| 4715 | + jQuery(this).find('.menu')[0].style.setProperty('right', right + 'px', 'important'); | |
| 4716 | + }); | |
| 3775 | 4717 | |
| 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); | |
| 4718 | + // Fix the overflow prbolem for the actions menu element (left pointing menu). | |
| 4719 | + jQuery(tblSelect + '[fixed-menu-overflow="no"] tr td .ui.left.pointing.dropdown').on('click', function () { | |
| 4720 | + jQuery(this).closest(dtScrollBdCls).css('position', ''); | |
| 4721 | + jQuery(this).closest(dtScrollCls).css('position', 'relative'); | |
| 4722 | + jQuery(this).css('position', 'static'); | |
| 4723 | + let position = jQuery(this).position(); | |
| 3784 | 4724 | |
| 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 | - }); | |
| 4725 | + let top = position.top; | |
| 4726 | + let left = position.left - 159; | |
| 4727 | + | |
| 4728 | + if (fix_overflow > 1) { | |
| 4729 | + position = jQuery(this).closest('td').position(); | |
| 4730 | + let scroll_left = jQuery(this).closest(dtScrollBdCls).scrollLeft(); | |
| 4731 | + top = position.top + 85; | |
| 4732 | + left = position.left - scroll_left - 145; | |
| 4733 | + } | |
| 4734 | + | |
| 4735 | + if (pTop !== undefined) { | |
| 4736 | + top = top + pTop; | |
| 4737 | + } | |
| 4738 | + | |
| 4739 | + jQuery(this).find('.menu').css('min-width', '150px'); | |
| 4740 | + jQuery(this).removeClass('left'); | |
| 4741 | + jQuery(this).addClass('right'); | |
| 4742 | + jQuery(this).find('.menu').css('top', top); | |
| 4743 | + jQuery(this).find('.menu')[0].style.setProperty('left', left + 'px', 'important'); | |
| 4744 | + }); | |
| 4745 | + | |
| 4746 | + jQuery(tblSelect + '[fixed-menu-overflow="no"]').each(function () { | |
| 4747 | + jQuery(this).attr('fixed-menu-overflow', 'yes'); | |
| 4748 | + }); | |
| 4749 | + | |
| 4750 | + mainwp_datatable_fix_reorder_selected_rows_status(); | |
| 3792 | 4751 | } |
| 3793 | 4752 | |
| 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 | 4753 | |
| 3798 | - var position = jQuery(this).position(); | |
| 3799 | - var left = position.left + 30; | |
| 3800 | - var top = position.top; | |
| 4754 | +let mainwp_datatable_fix_child_menu_overflow = function (chilRow, fix_overflow) { | |
| 4755 | + let dtScrollBdCls = '.dt-scroll-body'; | |
| 4756 | + let dtScrollCls = '.dt-scroll'; | |
| 4757 | + // Fix the overflow prbolem for the actions child menu element (pointing menu). | |
| 4758 | + jQuery(chilRow).find('.ui.pointing.dropdown').on('click', function () { | |
| 3801 | 4759 | |
| 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 | - } | |
| 4760 | + let position = jQuery(this).position(); | |
| 4761 | + let left = position.left + 30; | |
| 4762 | + let top = position.top; | |
| 3806 | 4763 | |
| 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 | - }); | |
| 4764 | + if (fix_overflow > 1) { | |
| 4765 | + position = jQuery(this).closest('td.child').position(); | |
| 4766 | + top = position.top + jQuery(this).closest('td.child').height() + 85; | |
| 4767 | + } | |
| 4768 | + | |
| 4769 | + jQuery(this).closest(dtScrollBdCls).css('position', ''); | |
| 4770 | + jQuery(this).closest(dtScrollCls).css('position', 'relative'); | |
| 4771 | + jQuery(this).css('position', 'static'); | |
| 4772 | + jQuery(this).find('.menu').css('top', top); | |
| 4773 | + jQuery(this).find('.menu').css('left', left); | |
| 4774 | + jQuery(this).find('.menu').css('min-width', '170px'); | |
| 4775 | + }); | |
| 3815 | 4776 | } |
| 3816 | 4777 | |
| 3817 | 4778 | |
| 3818 | -mainwp_responsive_fix_remove_child_row = function (el) { | |
| 3819 | - if (jQuery(el).hasClass('dt-hasChild')) { // to fix. | |
| 3820 | - jQuery(el).next().remove(); | |
| 3821 | - } | |
| 4779 | +globalThis.mainwp_responsive_fix_remove_child_row = function (el) { | |
| 4780 | + if (jQuery(el).hasClass('dt-hasChild')) { // to fix. | |
| 4781 | + jQuery(el).next().remove(); | |
| 4782 | + } | |
| 3822 | 4783 | } |
| 3823 | 4784 | |
| 3824 | 4785 | /* 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 | - } | |
| 4786 | +function mainwp_according_table_sorting(pObj) { // NOSONAR - complex. | |
| 4787 | + let table, th, rows, switching, i, x, y, xVal, yVal, campare = false, shouldSwitch = false, dir, switchcount = 0, n, skip = 1; | |
| 4788 | + table = jQuery(pObj).closest('table')[0]; | |
| 4789 | + let subline_skip = 2; | |
| 4790 | + if ('mainwp-wordpress-updates-table' == jQuery(table).attr('id')) { | |
| 4791 | + subline_skip = 1; // for rows without subline. | |
| 4792 | + skip = 0; | |
| 4793 | + } | |
| 3833 | 4794 | |
| 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 | - } | |
| 4795 | + // get TH element | |
| 4796 | + if (jQuery(pObj)[0].tagName == 'TH') { | |
| 4797 | + th = jQuery(pObj)[0]; | |
| 4798 | + } else { | |
| 4799 | + th = jQuery(pObj).closest('th')[0]; | |
| 4800 | + } | |
| 3840 | 4801 | |
| 3841 | - n = th.cellIndex; | |
| 3842 | - switching = true; | |
| 4802 | + n = th.cellIndex; | |
| 4803 | + switching = true; | |
| 3843 | 4804 | |
| 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 | |
| 4805 | + // check header and footer of according table | |
| 4806 | + if (jQuery(table).children('thead,tfoot').length > 0) | |
| 4807 | + skip += jQuery(table).children('thead,tfoot').length; // skip sorting header, footer | |
| 3847 | 4808 | |
| 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]; | |
| 4809 | + dir = "asc"; | |
| 4810 | + /* loop until switching has been done: */ | |
| 4811 | + while (switching) { | |
| 4812 | + switching = false; | |
| 4813 | + rows = table.rows; | |
| 4814 | + /* Loop through all table rows */ | |
| 4815 | + for (i = 1; i < (rows.length - skip); i += subline_skip) { // skip content according rows, sort by title rows only | |
| 4816 | + shouldSwitch = false; | |
| 4817 | + /* Get the two elements you want to compare, | |
| 4818 | + one from current row and one from the next-next: */ | |
| 4819 | + x = rows[i].getElementsByTagName("TD")[n]; | |
| 4820 | + y = rows[i + subline_skip].getElementsByTagName("TD")[n]; | |
| 3860 | 4821 | |
| 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 | - } | |
| 4822 | + // if sort value attribute existed then sorting on that else sorting on cell value | |
| 4823 | + if (x.hasAttribute('sort-value')) { | |
| 4824 | + xVal = Number.parseInt(x.getAttribute('sort-value')); | |
| 4825 | + yVal = Number.parseInt(y.getAttribute('sort-value')); | |
| 4826 | + let tmp = xVal > yVal ? -1 : 1; | |
| 4827 | + campare = (xVal == yVal) ? 0 : tmp; | |
| 4828 | + } else { | |
| 4829 | + // to prevent text() clear text content | |
| 4830 | + xVal = '<p>' + x.innerHTML + '</p>'; | |
| 4831 | + yVal = '<p>' + y.innerHTML + '</p>'; | |
| 4832 | + xVal = jQuery(xVal).text().trim().toLowerCase(); | |
| 4833 | + yVal = jQuery(yVal).text().trim().toLowerCase(); | |
| 4834 | + campare = yVal.localeCompare(xVal); | |
| 4835 | + } | |
| 3874 | 4836 | |
| 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; | |
| 4837 | + /* Check if the two rows should switch place */ | |
| 4838 | + if (dir == "asc") { | |
| 4839 | + if (campare < 0) { //xVal > yVal | |
| 4840 | + shouldSwitch = true; | |
| 4841 | + // break the loop: | |
| 4842 | + break; | |
| 4843 | + } | |
| 4844 | + } else if (dir == "desc") { | |
| 4845 | + if (campare > 0) { //xVal < yVal | |
| 4846 | + // break the loop: | |
| 4847 | + shouldSwitch = true; | |
| 4848 | + break; | |
| 4849 | + } | |
| 4850 | + } | |
| 3881 | 4851 | } |
| 3882 | - } else if (dir == "desc") { | |
| 3883 | - if (campare > 0) { //xVal < yVal | |
| 3884 | - // break the loop: | |
| 3885 | - shouldSwitch = true; | |
| 3886 | - break; | |
| 4852 | + if (shouldSwitch) { | |
| 4853 | + if (2 == subline_skip) { | |
| 4854 | + rows[i].parentNode.insertBefore(rows[i + 2], rows[i]); | |
| 4855 | + rows[i + 1].parentNode.insertBefore(rows[i + 3], rows[i + 1]); | |
| 4856 | + } else { | |
| 4857 | + rows[i].parentNode.insertBefore(rows[i + 1], rows[i]); // switch 2 rows. | |
| 4858 | + } | |
| 4859 | + switching = true; | |
| 4860 | + // increase this count by 1, that is ok | |
| 4861 | + switchcount++; | |
| 4862 | + } else if (switchcount == 0 && dir == "asc") { | |
| 4863 | + /* If no switching has been done AND the direction is "asc", | |
| 4864 | + set the direction to "desc" and run the while loop again. */ | |
| 4865 | + dir = "desc"; | |
| 4866 | + switching = true; | |
| 3887 | 4867 | } |
| 3888 | - } | |
| 3889 | 4868 | } |
| 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 | - } | |
| 4869 | + | |
| 4870 | + // no row sorting so change direction for arrows switch | |
| 4871 | + if (switchcount == 0) { | |
| 4872 | + if (jQuery(pObj).hasClass('ascending')) { | |
| 4873 | + dir = "desc"; | |
| 4874 | + } else { | |
| 4875 | + dir = "asc"; | |
| 4876 | + } | |
| 3907 | 4877 | } |
| 3908 | - } | |
| 3909 | 4878 | |
| 3910 | - // no row sorting so change direction for arrows switch | |
| 3911 | - if (switchcount == 0) { | |
| 3912 | - if (jQuery(pObj).hasClass('ascending')) { | |
| 3913 | - dir = "desc"; | |
| 4879 | + // add/remove class for arrows displaying | |
| 4880 | + if (dir == "asc") { | |
| 4881 | + jQuery(pObj).addClass('ascending'); | |
| 4882 | + jQuery(pObj).removeClass('descending'); | |
| 3914 | 4883 | } else { |
| 3915 | - dir = "asc"; | |
| 4884 | + jQuery(pObj).removeClass('ascending'); | |
| 4885 | + jQuery(pObj).addClass('descending'); | |
| 3916 | 4886 | } |
| 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 | 4887 | } |
| 3928 | 4888 | /* eslint-enable complexity */ |
| 3929 | 4889 | |
| 3930 | -jQuery(document).ready(function () { | |
| 3931 | - jQuery('.handle-accordion-sorting').on('click', function () { | |
| 3932 | - mainwp_according_table_sorting(this); | |
| 3933 | - return false; | |
| 3934 | - }); | |
| 4890 | +jQuery(function () { | |
| 4891 | + jQuery('.handle-accordion-sorting').on('click', function () { | |
| 4892 | + mainwp_according_table_sorting(this); | |
| 4893 | + return false; | |
| 4894 | + }); | |
| 3935 | 4895 | }); |
| 3936 | 4896 | |
| 3937 | 4897 | // 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(); | |
| 4898 | +let mainwp_force_destroy_sessions = function () { | |
| 4899 | + let confirmMsg = MainWP.I18n.t('Are you sure you want to force your MainWP Dashboard to reconnect with your child sites?'); | |
| 4900 | + mainwp_confirm(confirmMsg, function () { | |
| 4901 | + mainwp_force_destroy_sessions_websites = jQuery('.dashboard_wp_id[error-status=0]').map(function (indx, el) { | |
| 4902 | + return jQuery(el).val(); | |
| 4903 | + }); | |
| 4904 | + mainwpPopup('#mainwp-sync-sites-modal').setTitle(MainWP.I18n.t('Re-establish Connection')); // popup displayed. | |
| 4905 | + mainwpPopup('#mainwp-sync-sites-modal').init({ progressMax: mainwp_force_destroy_sessions_websites.length }); | |
| 4906 | + mainwp_force_destroy_sessions_part_2(0); | |
| 3943 | 4907 | }); |
| 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 | 4908 | }; |
| 3949 | 4909 | |
| 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 () { | |
| 4910 | +let mainwp_force_destroy_sessions_part_2 = function (id) { | |
| 4911 | + if (id >= mainwp_force_destroy_sessions_websites.length) { | |
| 4912 | + mainwp_force_destroy_sessions_websites = []; | |
| 4913 | + if (mainwp_force_destroy_sessions_successed == mainwp_force_destroy_sessions_websites.length) { | |
| 4914 | + setTimeout(function () { | |
| 4915 | + mainwpPopup('#mainwp-sync-sites-modal').close(true); | |
| 4916 | + }, 3000); | |
| 4917 | + } | |
| 3955 | 4918 | mainwpPopup('#mainwp-sync-sites-modal').close(true); |
| 3956 | - }, 3000); | |
| 4919 | + return; | |
| 3957 | 4920 | } |
| 3958 | - mainwpPopup('#mainwp-sync-sites-modal').close(true); | |
| 3959 | - return; | |
| 3960 | - } | |
| 3961 | 4921 | |
| 3962 | - var website_id = mainwp_force_destroy_sessions_websites[id]; | |
| 3963 | - dashboard_update_site_status(website_id, '<i class="sync alternate loading icon"></i>'); | |
| 4922 | + let website_id = mainwp_force_destroy_sessions_websites[id]; | |
| 4923 | + dashboard_update_site_status(website_id, '<i class="sync alternate loading icon"></i>'); | |
| 3964 | 4924 | |
| 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); | |
| 4925 | + jQuery.post(ajaxurl, { 'action': 'mainwp_force_destroy_sessions', 'website_id': website_id, 'security': security_nonces['mainwp_force_destroy_sessions'] }, function (response) { | |
| 4926 | + let counter = id + 1; | |
| 4927 | + mainwp_force_destroy_sessions_part_2(counter); | |
| 3968 | 4928 | |
| 3969 | - mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(counter); | |
| 4929 | + mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(counter); | |
| 3970 | 4930 | |
| 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); | |
| 4931 | + if ('error' in response) { | |
| 4932 | + dashboard_update_site_status(website_id, '<i class="exclamation red icon"></i>'); | |
| 4933 | + } else if ('success' in response) { | |
| 4934 | + mainwp_force_destroy_sessions_successed += 1; | |
| 4935 | + dashboard_update_site_status(website_id, '<i class="check green icon"></i>', true); | |
| 4936 | + } else { | |
| 4937 | + dashboard_update_site_status(website_id, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Process timed out. Please try again.') + '">'); | |
| 4938 | + } | |
| 4939 | + }, 'json').fail(function () { | |
| 4940 | + let counter = id + 1; | |
| 4941 | + mainwp_force_destroy_sessions_part_2(counter); | |
| 4942 | + mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(counter); | |
| 3983 | 4943 | |
| 3984 | - dashboard_update_site_status(website_id, '<i class="exclamation red icon"></i>'); | |
| 3985 | - }); | |
| 4944 | + dashboard_update_site_status(website_id, '<i class="exclamation red icon"></i>'); | |
| 4945 | + }); | |
| 3986 | 4946 | |
| 3987 | 4947 | }; |
| 3988 | 4948 | |
| 3989 | -var mainwp_force_destroy_sessions_successed = 0; | |
| 3990 | -var mainwp_force_destroy_sessions_websites = []; | |
| 4949 | +let mainwp_force_destroy_sessions_successed = 0; | |
| 4950 | +let mainwp_force_destroy_sessions_websites = []; | |
| 3991 | 4951 | |
| 3992 | 4952 | |
| 3993 | 4953 | 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(); | |
| 4954 | + let zipMethod = jQuery(this).val(); | |
| 4955 | + zipMethod = zipMethod.replaceAll('.', '\\.'); // NOSONAR - escape is correct. | |
| 4956 | + jQuery('span.archive_info').hide(); | |
| 4957 | + jQuery('span#info_' + zipMethod).show(); | |
| 3998 | 4958 | |
| 3999 | - jQuery('tr.archive_method').hide(); | |
| 4000 | - jQuery('tr.archive_' + zipMethod).show(); | |
| 4959 | + jQuery('tr.archive_method').hide(); | |
| 4960 | + jQuery('tr.archive_' + zipMethod).show(); | |
| 4001 | 4961 | |
| 4002 | - // compare new layout | |
| 4003 | - jQuery('div.archive_method').hide(); | |
| 4004 | - jQuery('div.archive_' + zipMethod).show(); | |
| 4962 | + // compare new layout | |
| 4963 | + jQuery('div.archive_method').hide(); | |
| 4964 | + jQuery('div.archive_' + zipMethod).show(); | |
| 4005 | 4965 | }); |
| 4006 | 4966 | |
| 4967 | +let mainwp_import_demo_data_action = function (obj) { | |
| 4968 | + let confirmation = "Are you sure you want to import demo content into your MainWP Dashboard?"; | |
| 4969 | + let msg_import = (jQuery(obj).attr('page-import') == 'qsw-import') ? '&message=qsw-import' : ''; | |
| 4970 | + mainwp_confirm(confirmation, function () { | |
| 4971 | + feedback('mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Importing. Please wait...'), ''); | |
| 4972 | + let data = mainwp_secure_data({ | |
| 4973 | + action: 'mainwp_import_demo_data', | |
| 4974 | + }); | |
| 4007 | 4975 | |
| 4976 | + jQuery.post(ajaxurl, data, function (response) { | |
| 4977 | + let error = false; | |
| 4978 | + if (response.count === undefined) { | |
| 4979 | + error = true; | |
| 4980 | + feedback('mainwp-message-zone', MainWP.I18n.t('Undefined error. Please try again.'), 'green'); | |
| 4981 | + } else { | |
| 4982 | + feedback('mainwp-message-zone', MainWP.I18n.t('The demo content has been imported into your MainWP Dashboard.'), 'green'); | |
| 4983 | + } | |
| 4984 | + | |
| 4985 | + if (!error) { | |
| 4986 | + setTimeout(function () { | |
| 4987 | + mainwp_forceReload('admin.php?page=mainwp_tab' + msg_import); | |
| 4988 | + }, 3000); | |
| 4989 | + } | |
| 4990 | + }, 'json'); | |
| 4991 | + }); | |
| 4992 | +} | |
| 4993 | + | |
| 4994 | +let mainwp_remove_demo_data_action = function () { | |
| 4995 | + let confirmation = "Are you sure you want to delete demo content from your MainWP Dashboard?"; | |
| 4996 | + mainwp_confirm(confirmation, function () { | |
| 4997 | + feedback('mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Deleting. Please wait...'), ''); | |
| 4998 | + let data = mainwp_secure_data({ | |
| 4999 | + action: 'mainwp_delete_demo_data', | |
| 5000 | + }); | |
| 5001 | + jQuery.post(ajaxurl, data, function (response) { | |
| 5002 | + let error = false; | |
| 5003 | + if (response.success === undefined) { | |
| 5004 | + error = true; | |
| 5005 | + feedback('mainwp-message-zone', MainWP.I18n.t('Undefined error. Please try again.'), 'green'); | |
| 5006 | + } else { | |
| 5007 | + feedback('mainwp-message-zone', MainWP.I18n.t('The demo content has been deleted from your MainWP Dashboard.'), 'green'); | |
| 5008 | + } | |
| 5009 | + | |
| 5010 | + if (!error) { | |
| 5011 | + setTimeout(function () { | |
| 5012 | + mainwp_forceReload('admin.php?page=mainwp-setup'); | |
| 5013 | + }, 3000); | |
| 5014 | + } | |
| 5015 | + | |
| 5016 | + }, 'json'); | |
| 5017 | + }); | |
| 5018 | +} | |
| 5019 | + | |
| 4008 | 5020 | // MainWP Tools |
| 4009 | 5021 | jQuery(function () { |
| 4010 | - jQuery(document).on('click', '#force-destroy-sessions-button', function () { | |
| 4011 | - mainwp_force_destroy_sessions(); | |
| 4012 | - }); | |
| 5022 | + jQuery(document).on('click', '#force-destroy-sessions-button', function () { | |
| 5023 | + mainwp_force_destroy_sessions(); | |
| 5024 | + }); | |
| 4013 | 5025 | |
| 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 | - }); | |
| 5026 | + jQuery(document).on('click', '.mainwp-import-demo-data-button', function (event) { | |
| 5027 | + mainwp_import_demo_data_action(this); | |
| 5028 | + event.preventDefault(); | |
| 5029 | + }); | |
| 4022 | 5030 | |
| 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'); | |
| 5031 | + jQuery(document).on('click', '.mainwp-remove-demo-data-button', function () { | |
| 5032 | + mainwp_remove_demo_data_action(); | |
| 5033 | + return false; //required this return. | |
| 5034 | + }); | |
| 5035 | +}); | |
| 5036 | + | |
| 5037 | + | |
| 5038 | +let mainwp_tool_renew_connections_show = function () { | |
| 5039 | + jQuery('#mainwp-tool-renew-connect-modal').modal({ | |
| 5040 | + allowMultiple: true, | |
| 5041 | + closable: false, | |
| 5042 | + onHide: function () { | |
| 5043 | + mainwp_forceReload('admin.php?page=MainWPTools'); | |
| 5044 | + }, | |
| 5045 | + onShow: function () { | |
| 5046 | + if (jQuery('#mainwp-tool-renew-connect-modal .mainwp_selected_sites_item.item.warning').length == 0) { | |
| 5047 | + jQuery('#mainwp-tool-renew-connect-modal .mainwp-ss-select-disconnected').hide(); | |
| 5048 | + jQuery('#mainwp-tool-renew-connect-modal .mainwp-ss-deselect-disconnected').hide(); | |
| 5049 | + } | |
| 4030 | 5050 | } |
| 4031 | - if (error == false) { | |
| 4032 | - setTimeout(function () { | |
| 4033 | - window.location = 'admin.php?page=mainwp_tab' + msg_import; | |
| 4034 | - }, 3000); | |
| 4035 | - } | |
| 4036 | - }, 'json'); | |
| 5051 | + }).modal('show'); | |
| 5052 | +}; | |
| 5053 | + | |
| 5054 | +let mainwp_tool_prepare_renew_connections = function (objBtn) { | |
| 5055 | + | |
| 5056 | + let errors = []; | |
| 5057 | + let selected_sites = []; | |
| 5058 | + mainwp_set_message_zone('#mainwp-message-zone-modal'); | |
| 5059 | + | |
| 5060 | + jQuery("input[name='selected_sites[]']:checked").each(function () { | |
| 5061 | + selected_sites.push(jQuery(this).val()); | |
| 4037 | 5062 | }); |
| 4038 | - return false; | |
| 4039 | - }); | |
| 5063 | + if (selected_sites.length == 0) { | |
| 5064 | + errors.push(MainWP.I18n.t('Please select at least one website to start.')); | |
| 5065 | + } | |
| 4040 | 5066 | |
| 4041 | - jQuery(document).on('click', '.mainwp-remove-demo-data-button', function () { | |
| 5067 | + if (errors.length > 0) { | |
| 5068 | + mainwp_set_message_zone('#mainwp-message-zone-modal', errors.join('<br />'), 'yellow'); | |
| 5069 | + return; | |
| 5070 | + } else { | |
| 5071 | + mainwp_set_message_zone('#mainwp-message-zone-modal'); | |
| 5072 | + } | |
| 4042 | 5073 | |
| 4043 | - var confirmation = "Are you sure you want to delete demo content from your MainWP Dashboard?"; | |
| 5074 | + let confirmation = MainWP.I18n.t("This process will create a new OpenSSL Key Pair on your MainWP Dashboard and Set the new Public Key to your Child site(s). Are you sure you want to proceed?"); | |
| 5075 | + | |
| 4044 | 5076 | mainwp_confirm(confirmation, function () { |
| 5077 | + jQuery(objBtn).attr('disabled', true); | |
| 4045 | 5078 | |
| 4046 | - feedback('mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + __('Deleting. Please wait...', 'mainwp'), ''); | |
| 5079 | + jQuery('#mainwp-tool-renew-connect-modal .mainwp-select-sites-wrapper').hide(); | |
| 4047 | 5080 | |
| 4048 | - var data = mainwp_secure_data({ | |
| 4049 | - action: 'mainwp_delete_demo_data', | |
| 4050 | - }); | |
| 5081 | + let statusEl = jQuery('#mainwp-message-zone-modal'); | |
| 5082 | + statusEl.html('<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Please wait...')); | |
| 5083 | + statusEl.show(); | |
| 4051 | 5084 | |
| 4052 | - jQuery.post(ajaxurl, data, function (response) { | |
| 5085 | + let data = mainwp_secure_data({ | |
| 5086 | + action: 'mainwp_prepare_renew_connections', | |
| 5087 | + 'sites[]': selected_sites, | |
| 5088 | + }); | |
| 4053 | 5089 | |
| 4054 | - var error = false; | |
| 5090 | + jQuery.post(ajaxurl, data, function (response) { | |
| 5091 | + let undefError = false; | |
| 5092 | + if (response) { | |
| 5093 | + if (response.result != '') { | |
| 5094 | + jQuery('#mainwp-tool-renew-connect-modal').find('#mainwp-renew-connections-list').html(response.result); | |
| 5095 | + mainwpVars.bulkInstallTotal = jQuery('#mainwp-renew-connections-list .item').length; | |
| 5096 | + jQuery('#mainwp-tool-renew-connect-modal .mainwp-modal-progress').show(); | |
| 5097 | + jQuery('#mainwp-tool-renew-connect-modal .mainwp-modal-progress').progress({ value: 0, total: mainwpVars.bulkInstallTotal }); | |
| 5098 | + mainwp_tool_renew_connections_start_next(); | |
| 5099 | + statusEl.hide(); | |
| 5100 | + } else if (response.error) { | |
| 5101 | + statusEl.addClass('red'); | |
| 5102 | + statusEl.html(response.error).fadeIn(); | |
| 5103 | + } else { | |
| 5104 | + undefError = true; | |
| 5105 | + } | |
| 5106 | + } else { | |
| 5107 | + undefError = true; | |
| 5108 | + } | |
| 4055 | 5109 | |
| 4056 | - if (response.success != undefined) { | |
| 4057 | - feedback('mainwp-message-zone', __('The demo content has been deleted from your MainWP Dashboard.', 'mainwp'), 'green'); | |
| 5110 | + if (undefError) { | |
| 5111 | + statusEl.addClass('red'); | |
| 5112 | + statusEl.html(MainWP.I18n.t('Undefined error occurred. Please try again.')).fadeIn(); | |
| 5113 | + } | |
| 5114 | + }, 'json'); | |
| 5115 | + }, false, false, true); | |
| 5116 | +} | |
| 5117 | + | |
| 5118 | +let connection_renew_status = function (siteId, newStatus) { | |
| 5119 | + jQuery('#mainwp-renew-connections-list .renew-site-status[siteid="' + siteId + '"]').html(newStatus); | |
| 5120 | +}; | |
| 5121 | + | |
| 5122 | +let mainwp_tool_renew_connections_start_next = function () { | |
| 5123 | + while ((siteToReNew = jQuery('#mainwp-renew-connections-list .item[status="queue"]:first')) && (siteToReNew.length > 0) && (bulkInstallCurrentThreads < bulkInstallMaxThreads)) { // NOSONAR - modified outside the function. | |
| 5124 | + mainwp_tool_renew_connections_start_specific(siteToReNew); | |
| 5125 | + } | |
| 5126 | +} | |
| 5127 | + | |
| 5128 | +let mainwp_tool_renew_connections_start_specific = function (siteItem) { | |
| 5129 | + | |
| 5130 | + bulkInstallCurrentThreads++; | |
| 5131 | + | |
| 5132 | + siteItem.attr('status', 'progress'); | |
| 5133 | + let siteId = siteItem.find('.renew-site-status').attr('siteid'); | |
| 5134 | + | |
| 5135 | + let data = mainwp_secure_data({ | |
| 5136 | + action: 'mainwp_renew_connections', | |
| 5137 | + siteid: siteId | |
| 5138 | + }); | |
| 5139 | + | |
| 5140 | + connection_renew_status(siteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Processing...') + '"><i class="sync alternate loading icon"></i></span>'); | |
| 5141 | + jQuery.post(ajaxurl, data, function (response) { | |
| 5142 | + if (response.error) { | |
| 5143 | + connection_renew_status(siteId, '<span data-inverted="" data-position="left center" data-tooltip="' + response.error + '"><i class="times red icon"></i></span>'); | |
| 5144 | + } else if (response.result == 'success') { | |
| 5145 | + connection_renew_status(siteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Renew connnection process completed successfully.') + '"><i class="check green icon"></i></span>'); | |
| 4058 | 5146 | } else { |
| 4059 | - error = true; | |
| 4060 | - feedback('mainwp-message-zone', __('Undefined error. Please try again.', 'mainwp'), 'green'); | |
| 5147 | + connection_renew_status(siteId, '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Undefined error.') + '"><i class="times red icon"></i></span>'); | |
| 5148 | + | |
| 4061 | 5149 | } |
| 5150 | + bulkInstallCurrentThreads--; | |
| 5151 | + bulkInstallDone++; | |
| 5152 | + jQuery('#mainwp-tool-renew-connect-modal .mainwp-modal-progress').progress('set progress', bulkInstallDone); | |
| 5153 | + jQuery('#mainwp-tool-renew-connect-modal .mainwp-modal-progress').find('.label').html(bulkInstallDone + '/' + mainwpVars.bulkInstallTotal + ' ' + MainWP.I18n.t('Processed')); | |
| 5154 | + mainwp_tool_renew_connections_start_next(); | |
| 5155 | + }, 'json'); | |
| 5156 | +} | |
| 4062 | 5157 | |
| 4063 | - if (error == false) { | |
| 4064 | - setTimeout(function () { | |
| 4065 | - window.location = 'admin.php?page=mainwp-setup'; | |
| 4066 | - }, 3000); | |
| 5158 | + | |
| 5159 | +jQuery(function () { | |
| 5160 | + if (jQuery('body.mainwp-ui').length > 0) { | |
| 5161 | + jQuery('.mainwp-ui-page .ui.dropdown:not(.not-auto-init)').dropdown(); | |
| 5162 | + jQuery('.mainwp-ui-page .ui.checkbox:not(.not-auto-init)').checkbox(); | |
| 5163 | + jQuery('.mainwp-ui-page .ui.dropdown').filter('[init-value]').each(function () { | |
| 5164 | + let values = jQuery(this).attr('init-value').split(','); | |
| 5165 | + jQuery(this).dropdown('set selected', values); | |
| 5166 | + }); | |
| 5167 | + } | |
| 5168 | +}); | |
| 5169 | + | |
| 5170 | +// MainWP Action Logs | |
| 5171 | +jQuery(document).on('click', '.mainwp-action-log-show-more', function () { | |
| 5172 | + let content = jQuery(this).closest('.item').find('.mainwp-action-log-site-response').text(); | |
| 5173 | + jQuery('#mainwp-action-log-response-modal').modal({ | |
| 5174 | + closable: false, | |
| 5175 | + onHide: function () { | |
| 5176 | + location.reload(); | |
| 4067 | 5177 | } |
| 5178 | + }).modal('show'); | |
| 5179 | + jQuery('#mainwp-action-log-response-modal .content-response').text(content); | |
| 5180 | +}); | |
| 4068 | 5181 | |
| 4069 | - }, 'json'); | |
| 4070 | - }); | |
| 5182 | +// MainWP Show Response | |
| 5183 | +jQuery(document).on('click', '.mainwp-show-response', function () { | |
| 5184 | + let content = jQuery('#mainwp-response-data-container').attr('resp-data'); | |
| 5185 | + jQuery('#mainwp-response-data-modal').modal({ | |
| 5186 | + closable: false, | |
| 5187 | + onHide: function () { | |
| 5188 | + jQuery('#mainwp-response-data-modal .content-response').text(''); | |
| 5189 | + } | |
| 5190 | + }).modal('show'); | |
| 5191 | + jQuery('#mainwp-response-data-modal .content-response').text(content); | |
| 5192 | +}); | |
| 5193 | + | |
| 5194 | +// Copy to clipboard for response modals. | |
| 5195 | +jQuery(document).on('click', '.mainwp-response-copy-button', function (event) { | |
| 5196 | + let modal = jQuery(this).closest('.ui.modal'); | |
| 5197 | + let data = jQuery(modal).find('.content.content-response').text(); | |
| 5198 | + let $temp_txtarea = jQuery('<textarea style="opacity:0">'); | |
| 5199 | + jQuery('body').append($temp_txtarea); | |
| 5200 | + $temp_txtarea.val(data).trigger("select"); // to support 'copy' method. | |
| 5201 | + mainwp_copy_to_clipboard(data, event); | |
| 5202 | + $temp_txtarea.remove(); | |
| 4071 | 5203 | return false; |
| 4072 | - }); | |
| 5204 | +}); | |
| 4073 | 5205 | |
| 5206 | +jQuery(function () { | |
| 5207 | + if (typeof postboxes !== "undefined" && typeof mainwp_postbox_page !== "undefined") { | |
| 5208 | + postboxes.add_postbox_toggles(mainwp_postbox_page); | |
| 5209 | + } | |
| 5210 | + mainwp_setCookie(); | |
| 5211 | + mainwp_getCookie(); | |
| 5212 | +}); | |
| 4074 | 5213 | |
| 5214 | +jQuery(document).on('click', '.close.icon', function () { | |
| 5215 | + jQuery(this).parent().hide(); | |
| 4075 | 5216 | }); |
| 4076 | 5217 | |
| 5218 | +/* | |
| 5219 | + * to compatible | |
| 5220 | + */ | |
| 5221 | +function mainwp_setCookie() { | |
| 5222 | + return false; | |
| 5223 | +} | |
| 4077 | 5224 | |
| 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 | - } | |
| 5225 | +function mainwp_getCookie() { | |
| 5226 | + return false; | |
| 5227 | +} | |
| 5228 | + | |
| 5229 | +let mainwp_setttings_fields_indicator_show = function (specific_header_indicator) { | |
| 5230 | + if (specific_header_indicator !== undefined) { | |
| 5231 | + mainwp_setttings_fields_indicator_specific_show(specific_header_indicator); | |
| 5232 | + return; | |
| 4090 | 5233 | } |
| 4091 | - }).modal('show'); | |
| 5234 | + // for each header indicator. | |
| 5235 | + jQuery('.settings-field-header-indicator').each(function () { | |
| 5236 | + mainwp_setttings_fields_indicator_specific_show(this); | |
| 5237 | + }); | |
| 5238 | +} | |
| 5239 | + | |
| 5240 | +let mainwp_setttings_fields_indicator_specific_show = function (obj) { | |
| 5241 | + let cls = jQuery(obj).attr('field-indicator-wrapper-class'); | |
| 5242 | + if ('' != cls && jQuery('.' + cls + ' .settings-field-icon-indicator.visible-indicator').length > 0) { | |
| 5243 | + jQuery(this).attr('style', 'display:inline-block;'); | |
| 5244 | + jQuery(this).addClass('visible-indicator'); | |
| 5245 | + } | |
| 5246 | +} | |
| 5247 | + | |
| 5248 | + | |
| 5249 | +jQuery(function ($) { | |
| 5250 | + if (jQuery('.mainwp-ui-page').length) { | |
| 5251 | + mainwp_setttings_fields_indicator_show(); | |
| 5252 | + } | |
| 5253 | + | |
| 5254 | + jQuery(document).on('input', '.settings-field-value-change-handler', function () { | |
| 5255 | + let val = $(this).val(); | |
| 5256 | + mainwp_settings_fields_value_on_change(this, val); | |
| 5257 | + }); | |
| 5258 | + | |
| 5259 | + jQuery(document).on('change', '.settings-field-value-change-handler', function () { // NOSONAR - complex ok. | |
| 5260 | + let objName = $(this).prop('tagName'), val; | |
| 5261 | + let me; // to fix some special case indicator not at same level with input, need to find by name. | |
| 5262 | + | |
| 5263 | + if ('DIV' === objName) { // ui dropdown select. | |
| 5264 | + val = $(this).dropdown('get value'); | |
| 5265 | + } else if ($(this).is(':checkbox')) { | |
| 5266 | + val = $(this).is(":checked") ? '1' : '0'; | |
| 5267 | + if ($(this).attr('name') === 'mainwp_show_widgets[]') { | |
| 5268 | + if ($('input[type="checkbox"][name="mainwp_show_widgets[]"]:not(:checked)').length == 0) { | |
| 5269 | + val = 'all'; | |
| 5270 | + } | |
| 5271 | + } else if ($(this).attr('inverted-value')) { | |
| 5272 | + val = val === '1' ? '0' : '1'; // to fix compatible with some case checked is disable, value is 0. | |
| 5273 | + } | |
| 5274 | + } else { | |
| 5275 | + val = $(this).val(); | |
| 5276 | + if ($(this).attr('name') === 'mainwp_rest_api_key_edit_pers') { | |
| 5277 | + val = val.split(',').length; | |
| 5278 | + } else if ($(this).attr('name') === 'cost_tracker_custom_product_types[title][]') { | |
| 5279 | + val = $('input[name="cost_tracker_custom_product_types[title][]"]').length; // default 0. | |
| 5280 | + me = $('.settings-field-indicator-wrapper.default-product-categories'); | |
| 5281 | + } else if ($(this).attr('name') === 'cost_tracker_custom_payment_methods[title][]') { | |
| 5282 | + val = $('input[name="cost_tracker_custom_payment_methods[title][]"]').length; // default 0. | |
| 5283 | + me = $('.settings-field-indicator-wrapper.custom-payment-methods'); | |
| 5284 | + } | |
| 5285 | + } | |
| 5286 | + | |
| 5287 | + if (me === undefined) { | |
| 5288 | + mainwp_settings_fields_value_on_change(this, val); | |
| 5289 | + } else { | |
| 5290 | + mainwp_settings_fields_value_on_change(me, val); | |
| 5291 | + } | |
| 5292 | + }); | |
| 5293 | + | |
| 5294 | + let mainwp_settings_fields_value_on_change = function (obj, val) { | |
| 5295 | + let parent = $(obj).closest('.settings-field-indicator-wrapper'); | |
| 5296 | + if (parent.length) { | |
| 5297 | + let defval = $(parent).attr('default-indi-value') ?? ''; // put default-indi-value at wrapper because semantic ui some case move class of input too input's parent. | |
| 5298 | + let indiObj = parent.find('.settings-field-icon-indicator'); | |
| 5299 | + if (indiObj.length) { | |
| 5300 | + if (val == defval || ('0' == val && '' === defval)) { // empty and zero are same. | |
| 5301 | + $(indiObj).removeClass('visible-indicator'); | |
| 5302 | + } else { | |
| 5303 | + $(indiObj).addClass('visible-indicator'); | |
| 5304 | + } | |
| 5305 | + } | |
| 5306 | + } | |
| 5307 | + } | |
| 5308 | +}); | |
| 5309 | + | |
| 5310 | + | |
| 5311 | + | |
| 5312 | +let mainwp_common_filter_show_segments_modal = function (loadCallback) { | |
| 5313 | + jQuery('#mainwp-common-filter-segment-modal').modal({ | |
| 5314 | + allowMultiple: false, | |
| 5315 | + onShow: function () { | |
| 5316 | + if (typeof loadCallback == 'function') { | |
| 5317 | + loadCallback(); | |
| 5318 | + } | |
| 5319 | + } | |
| 5320 | + }).modal('show'); | |
| 4092 | 5321 | }; |
| 4093 | 5322 | |
| 4094 | -mainwp_tool_prepare_renew_connections = function (objBtn) { | |
| 5323 | +jQuery(function ($) { | |
| 5324 | + if (!globalThis.mainwpSegmentModalUiHandle) { | |
| 5325 | + globalThis.mainwpSegmentModalUiHandle = (function () { | |
| 5326 | + let _instance = { | |
| 5327 | + loadingStatus: function () { | |
| 5328 | + $('#mainwp-common-filter-edit-segment-status').html('<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Loading segments. Please wait...')).show(); | |
| 5329 | + }, | |
| 5330 | + savingStatus: function () { | |
| 5331 | + $('#mainwp-common-filter-edit-segment-status').html('<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Saving segment. Please wait...')).show(); | |
| 5332 | + }, | |
| 5333 | + deletingStatus: function () { | |
| 5334 | + $('#mainwp-common-filter-edit-segment-status').html('<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Deleting segment. Please wait...')).show(); | |
| 4095 | 5335 | |
| 4096 | - var errors = []; | |
| 4097 | - var selected_sites = []; | |
| 5336 | + }, | |
| 5337 | + showStatus: function (status, addClass) { | |
| 5338 | + if (addClass) { | |
| 5339 | + $('#mainwp-common-filter-edit-segment-status').addClass(addClass); | |
| 5340 | + } | |
| 5341 | + $('#mainwp-common-filter-edit-segment-status').html(status).show(); | |
| 5342 | + }, | |
| 5343 | + hideSegmentStatus: function () { | |
| 5344 | + $('#mainwp-common-filter-edit-segment-status').removeClass('red green').hide(); | |
| 5345 | + }, | |
| 5346 | + showSegment: function (btnObj) { | |
| 5347 | + jQuery('#mainwp-common-filter-segment-modal > div.header').html(MainWP.I18n.t('Save Segment')); | |
| 5348 | + jQuery('#mainwp-common-filter-segment-edit-fields').show(); | |
| 5349 | + jQuery('#mainwp-common-filter-edit-segment-save').show(); | |
| 5350 | + jQuery('#mainwp-common-filter-segment-select-fields').hide(); | |
| 5351 | + jQuery('#mainwp-common-filter-select-segment-choose-button').hide(); | |
| 5352 | + jQuery('#mainwp-common-filter-select-segment-delete-button').hide(); | |
| 5353 | + jQuery('#mainwp-common-filter-edit-segment-name').val(jQuery(btnObj).attr('selected-segment-name')); | |
| 5354 | + this.hideSegmentStatus(); | |
| 5355 | + mainwp_common_filter_show_segments_modal(); | |
| 5356 | + }, | |
| 5357 | + loadSegment: function (loadCallback) { | |
| 5358 | + jQuery('#mainwp-common-filter-segment-edit-fields').hide(); | |
| 5359 | + jQuery('#mainwp-common-filter-edit-segment-save').hide(); | |
| 5360 | + jQuery('#mainwp-common-filter-segment-modal > div.header').html(MainWP.I18n.t('Load Segment')); | |
| 5361 | + jQuery('#mainwp-common-filter-segment-select-fields').show(); | |
| 5362 | + jQuery('#mainwp-common-filter-select-segment-choose-button').show(); | |
| 5363 | + jQuery('#mainwp-common-filter-select-segment-delete-button').show(); | |
| 5364 | + this.hideSegmentStatus(); | |
| 5365 | + mainwp_common_filter_show_segments_modal(loadCallback); | |
| 5366 | + }, | |
| 5367 | + showResults: function (result) { | |
| 5368 | + jQuery('#mainwp-common-filter-edit-segment-status').hide(); | |
| 5369 | + jQuery('#mainwp-common-filter-segments-lists-wrapper').html(result); | |
| 5370 | + jQuery('#mainwp-common-filter-segments-lists-wrapper .ui.dropdown').dropdown(); | |
| 5371 | + jQuery('#mainwp-common-filter-segment-select-fields').show(); | |
| 5372 | + } | |
| 5373 | + } | |
| 5374 | + return _instance; | |
| 5375 | + })(); | |
| 5376 | + } | |
| 4098 | 5377 | |
| 4099 | - jQuery('#mainwp-message-zone-modal').removeClass('yellow ').hide(); | |
| 5378 | +}); | |
| 4100 | 5379 | |
| 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 | - } | |
| 5380 | +let mainwp_overview_gridstack_save_layout = function (item_id, grid) { | |
| 4107 | 5381 | |
| 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 | - } | |
| 5382 | + if (!grid?.engine?.nodes) { | |
| 5383 | + return; | |
| 5384 | + } | |
| 4116 | 5385 | |
| 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?"); | |
| 5386 | + let orders = []; | |
| 5387 | + let wgIds = []; | |
| 4118 | 5388 | |
| 4119 | - mainwp_confirm(confirmation, function () { | |
| 4120 | - jQuery(objBtn).attr('disabled', true); | |
| 5389 | + grid.engine.nodes.forEach(function (node) { | |
| 5390 | + if (!node?.el?.id) { | |
| 5391 | + return; | |
| 5392 | + } | |
| 4121 | 5393 | |
| 4122 | - jQuery('#mainwp-tool-renew-connect-modal .mainwp-select-sites-wrapper').hide(); | |
| 5394 | + let obj = { | |
| 5395 | + "x": node.x ?? 0, | |
| 5396 | + "y": node.y ?? 0, | |
| 5397 | + "w": node.w ?? 4, | |
| 5398 | + "h": node.h ?? 4 | |
| 5399 | + }; | |
| 5400 | + orders.push(obj); | |
| 5401 | + wgIds.push(node.el.id); | |
| 5402 | + }); | |
| 4123 | 5403 | |
| 4124 | - var statusEl = jQuery('#mainwp-message-zone-modal'); | |
| 4125 | - statusEl.html('<i class="notched circle loading icon"></i> ' + __('Please wait...')); | |
| 4126 | - statusEl.show(); | |
| 5404 | + if (wgIds.length === 0) { | |
| 5405 | + return; | |
| 5406 | + } | |
| 4127 | 5407 | |
| 4128 | - var data = mainwp_secure_data({ | |
| 4129 | - action: 'mainwp_prepare_renew_connections', | |
| 4130 | - 'sites[]': selected_sites, | |
| 4131 | - }); | |
| 5408 | + let postVars = { | |
| 5409 | + action: 'mainwp_widgets_order', | |
| 5410 | + page: page_sortablewidgets, | |
| 5411 | + order: JSON.stringify(orders), | |
| 5412 | + wgids: JSON.stringify(wgIds), | |
| 5413 | + item_id: item_id, | |
| 5414 | + page_widget: page_widget | |
| 5415 | + }; | |
| 5416 | + jQuery.post(ajaxurl, mainwp_secure_data(postVars), function () { }); | |
| 5417 | +} | |
| 4132 | 5418 | |
| 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; | |
| 5419 | +globalThis.mainwp_init_ui_calendar = ($selectors) => { | |
| 5420 | + jQuery($selectors).calendar({ | |
| 5421 | + type: 'date', | |
| 5422 | + monthFirst: false, | |
| 5423 | + today: true, | |
| 5424 | + touchReadonly: false, | |
| 5425 | + formatter: { | |
| 5426 | + date: function (date) { | |
| 5427 | + if (!date) return ''; | |
| 5428 | + let day = date.getDate(); | |
| 5429 | + let month = date.getMonth() + 1; | |
| 5430 | + let year = date.getFullYear(); | |
| 5431 | + | |
| 5432 | + if (month < 10) { | |
| 5433 | + month = '0' + month; | |
| 5434 | + } | |
| 5435 | + if (day < 10) { | |
| 5436 | + day = '0' + day; | |
| 5437 | + } | |
| 5438 | + return year + '-' + month + '-' + day; | |
| 5439 | + } | |
| 4148 | 5440 | } |
| 4149 | - } else { | |
| 4150 | - undefError = true; | |
| 4151 | - } | |
| 5441 | + }); | |
| 4152 | 5442 | |
| 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 | 5443 | } |
| 4160 | 5444 | |
| 4161 | -connection_renew_status = function (siteId, newStatus) { | |
| 4162 | - jQuery('#mainwp-renew-connections-list .renew-site-status[siteid="' + siteId + '"]').html(newStatus); | |
| 4163 | -}; | |
| 4164 | 5445 | |
| 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 | - } | |
| 5446 | +jQuery(document).ready(function () { | |
| 5447 | + jQuery('.dt-scroll-head').css({ | |
| 5448 | + 'overflow-x': 'auto' | |
| 5449 | + }).on('scroll', function () { | |
| 5450 | + let scrollBody = jQuery(this).parent().find('.dt-scroll-body').get(0); | |
| 5451 | + scrollBody.scrollLeft = this.scrollLeft; | |
| 5452 | + jQuery(scrollBody).trigger('scroll'); | |
| 5453 | + }); | |
| 5454 | +}); | |
| 5455 | + | |
| 5456 | +// Function to check valid email using regular expression. | |
| 5457 | +const mainwp_validate_email = function (email) { | |
| 5458 | + const re = /^[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]{1,255}\.[A-Za-z]{2,}$/; | |
| 5459 | + return re.test(email); | |
| 4169 | 5460 | } |
| 4170 | 5461 | |
| 4171 | -mainwp_tool_renew_connections_start_specific = function (siteItem) { | |
| 4172 | 5462 | |
| 4173 | - bulkInstallCurrentThreads++; | |
| 5463 | +jQuery(function ($) { | |
| 4174 | 5464 | |
| 4175 | - siteItem.attr('status', 'progress'); | |
| 4176 | - var siteId = siteItem.find('.renew-site-status').attr('siteid'); | |
| 5465 | + $(document).on('click', '#delete_uptime_monitor_btn', function () { | |
| 5466 | + let is_sub = $('#monitor_edit_is_sub_url')?.val(); | |
| 4177 | 5467 | |
| 4178 | - var data = mainwp_secure_data({ | |
| 4179 | - action: 'mainwp_renew_connections', | |
| 4180 | - siteid: siteId | |
| 4181 | - }); | |
| 5468 | + let confirmation = MainWP.I18n.t("Are you sure you want to delete this uptime monitor?"); | |
| 4182 | 5469 | |
| 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>'); | |
| 5470 | + if (is_sub) { | |
| 5471 | + confirmation = MainWP.I18n.t("Are you sure you want to delete this uptime sub-page monitor?"); | |
| 5472 | + } | |
| 4191 | 5473 | |
| 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 | -} | |
| 5474 | + mainwp_confirm(confirmation, () => { | |
| 5475 | + let wpid = $('#mainwp_edit_monitor_site_id').val(); | |
| 5476 | + let moid = $('#mainwp_edit_monitor_id').val(); | |
| 4200 | 5477 | |
| 5478 | + mainwp_uptime_monitoring_remove(wpid, moid); | |
| 5479 | + }, false, false, true); | |
| 5480 | + }); | |
| 4201 | 5481 | |
| 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); | |
| 5482 | + let mainwp_uptime_monitoring_remove = function (wpid, moid) { | |
| 5483 | + | |
| 5484 | + feedback('mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Removing Uptime Monitor...'), 'green'); | |
| 5485 | + | |
| 5486 | + let data = mainwp_secure_data({ | |
| 5487 | + action: 'mainwp_uptime_monitoring_remove_monitor', | |
| 5488 | + wpid: wpid, | |
| 5489 | + moid: moid | |
| 5490 | + }); | |
| 5491 | + | |
| 5492 | + jQuery.post(ajaxurl, data, function (response) { | |
| 5493 | + if (response?.success) { | |
| 5494 | + feedback('mainwp-message-zone', MainWP.I18n.t('Monitor have been removed.'), 'green'); | |
| 5495 | + setTimeout(function () { | |
| 5496 | + mainwp_forceReload('admin.php?page=managesites&id=' + wpid); | |
| 5497 | + }, 2000); | |
| 5498 | + | |
| 5499 | + } else if (response?.error) { | |
| 5500 | + feedback('mainwp-message-zone', response.error, 'red'); | |
| 5501 | + } else { | |
| 5502 | + feedback('mainwp-message-zone', MainWP.I18n.t('Undefined error. Please try again.'), 'red'); | |
| 5503 | + } | |
| 5504 | + }, 'json'); | |
| 5505 | + return false; | |
| 5506 | + }; | |
| 5507 | + | |
| 5508 | + $(document).on('click', '#increase-connection-security-btn', function () { | |
| 5509 | + feedback('mainwp-message-zone', '<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Encryption in progress! Securing your OpenSSL private keys, this may take a few moments. Please wait until completed.'), 'green'); | |
| 5510 | + let data = mainwp_secure_data({ | |
| 5511 | + action: 'mainwp_increase_connection_security', | |
| 5512 | + }); | |
| 5513 | + jQuery.post(ajaxurl, data, function (response) { | |
| 5514 | + if (response?.success) { | |
| 5515 | + setTimeout(function () { | |
| 5516 | + mainwp_forceReload(); | |
| 5517 | + }, 2000); | |
| 5518 | + | |
| 5519 | + } else if (response?.error) { | |
| 5520 | + feedback('mainwp-message-zone', response.error, 'red'); | |
| 5521 | + } else { | |
| 5522 | + feedback('mainwp-message-zone', MainWP.I18n.t('Undefined error. Please try again.'), 'red'); | |
| 5523 | + } | |
| 5524 | + }, 'json'); | |
| 5525 | + return false; | |
| 4209 | 5526 | }); |
| 4210 | - } | |
| 5527 | + jQuery('#module-update-logs-db-requirement').on('click', function () { | |
| 5528 | + let msg = MainWP.I18n.t('Are you sure?'); | |
| 5529 | + mainwp_confirm(msg, () => { | |
| 5530 | + jQuery(this).closest('.ui.message').fadeOut(); | |
| 5531 | + mainwp_module_logs_start_update_dismissed_db(); | |
| 5532 | + }); | |
| 5533 | + return false; | |
| 5534 | + }); | |
| 4211 | 5535 | }); |
| 4212 | 5536 | |
| 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); | |
| 5537 | + | |
| 5538 | +jQuery(document).on('click', '#mainwp-sites-changes-filter-toggle-button', function () { | |
| 5539 | + jQuery('#mainwp-module-log-filters-row').toggle(300); | |
| 5540 | + return false; | |
| 4223 | 5541 | }); |
| 4224 | 5542 | |
| 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(''); | |
| 5543 | +jQuery(document).on('click', '#mainwp-insights-filter-toggle-button', function () { | |
| 5544 | + jQuery('#mainwp-module-log-overview-sub-header').toggle(300); | |
| 5545 | + return false; | |
| 5546 | +}); | |
| 5547 | + | |
| 5548 | + | |
| 5549 | + | |
| 5550 | +let logs_update_db_cancelled = false; | |
| 5551 | +let mainwp_module_logs_start_update_dismissed_db = function () { | |
| 5552 | + let data = mainwp_secure_data({ | |
| 5553 | + action: 'mainwp_module_log_update_dismissed_db', | |
| 5554 | + }); | |
| 5555 | + if (logs_update_db_cancelled) { | |
| 5556 | + mainwp_set_message_zone('#module-log-update-dissmised-logs-running', '<i class="close icon"></i>' + MainWP.I18n.t("User cancelled the 'Sites Changes' database update process."), 'green'); | |
| 5557 | + } else { | |
| 5558 | + mainwp_set_message_zone('#module-log-update-dissmised-logs-running', '<i class="ui active inline loader tiny"></i> ' + MainWP.I18n.t('Updating the \'Sites Changes\' database. Click %1here%2 to cancel.', '<a href="javascript:void(0);" id="module-update-logs-db-cancel">', '</a>'), 'green'); | |
| 4232 | 5559 | } |
| 4233 | - }).modal('show'); | |
| 4234 | - jQuery('#mainwp-response-data-modal .content-response').text(content); | |
| 5560 | + jQuery.post(ajaxurl, data, function (response) { | |
| 5561 | + let status = response?.status ?? ''; | |
| 5562 | + if (response.error) { | |
| 5563 | + mainwp_set_message_zone('#module-log-update-dissmised-logs-running', '<i class="close icon"></i>' + response.error, 'red'); | |
| 5564 | + } else if (status === 'finished') { | |
| 5565 | + mainwp_set_message_zone('#module-log-update-dissmised-logs-running', '<i class="close icon"></i>' + MainWP.I18n.t('Logs records has been updated successfully.'), 'green'); | |
| 5566 | + } else if (status === 'running' && !logs_update_db_cancelled) { | |
| 5567 | + setTimeout(function () { | |
| 5568 | + mainwp_module_logs_start_update_dismissed_db(); | |
| 5569 | + }, 500); | |
| 5570 | + } | |
| 5571 | + }, 'json'); | |
| 5572 | +} | |
| 5573 | + | |
| 5574 | +jQuery(document).on('click', '#module-update-logs-db-cancel', function () { | |
| 5575 | + logs_update_db_cancelled = true; | |
| 5576 | + let data = mainwp_secure_data({ | |
| 5577 | + action: 'mainwp_module_log_cancel_update_dismissed_db', | |
| 5578 | + }); | |
| 5579 | + jQuery(this).closest('.ui.message').fadeOut(300); | |
| 5580 | + jQuery.post(ajaxurl, data, function (response) { | |
| 5581 | + //ok. | |
| 5582 | + }, 'json'); | |
| 5583 | + return false; | |
| 4235 | 5584 | }); |
| 4236 | 5585 | |
| 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 | 5586 | |
| 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 | 5587 | |
| 4263 | -jQuery(document).on('click', '.close.icon', function () { | |
| 4264 | - jQuery(this).parent().hide(); | |
| 4265 | -}); | |
| 5588 | +let get_local_date_string = function () { | |
| 5589 | + const today = new Date(); | |
| 5590 | + const y = today.getFullYear(); | |
| 5591 | + const m = String(today.getMonth() + 1).padStart(2, '0'); // month starts from 0 | |
| 5592 | + const d = String(today.getDate()).padStart(2, '0'); | |
| 5593 | + return `${y}-${m}-${d}`; | |
| 5594 | +} | |
| 4266 | 5595 | |
| 4267 | -/* | |
| 4268 | - * to compatible | |
| 4269 | - */ | |
| 4270 | -function mainwp_setCookie() { | |
| 4271 | - return false; | |
| 5596 | +function mainwp_forceReload(targetUrl) { | |
| 5597 | + const url = targetUrl || globalThis.location.href; | |
| 5598 | + // Navigate to URL (force reload from server) | |
| 5599 | + globalThis.location.href = url; | |
| 4272 | 5600 | } |
| 4273 | 5601 | |
| 4274 | -function mainwp_getCookie() { | |
| 4275 | - return false; | |
| 5602 | +class TablePersistentState { | |
| 5603 | + constructor(table, options = {}) { | |
| 5604 | + if (!table || !(table instanceof HTMLElement)) { | |
| 5605 | + throw new Error('TablePersistentState requires a table element'); | |
| 5606 | + } | |
| 5607 | + | |
| 5608 | + this.table = table; | |
| 5609 | + this.tableId = table.id; | |
| 5610 | + this.headers = table.querySelectorAll( | |
| 5611 | + options.headerSelector || '.handle-cols-sorting' | |
| 5612 | + ); | |
| 5613 | + | |
| 5614 | + this.options = { | |
| 5615 | + storage: options.storage !== false, // default true | |
| 5616 | + storagePrefix: options.storagePrefix || 'mainwp_tables_sort_state', | |
| 5617 | + onPersist: options.onPersist || null, | |
| 5618 | + defaultSort: options.defaultSort || null, // column, direction | |
| 5619 | + }; | |
| 5620 | + | |
| 5621 | + this.init(); | |
| 5622 | + } | |
| 5623 | + | |
| 5624 | + /* ---------- Storage ---------- */ | |
| 5625 | + | |
| 5626 | + get storageKey() { | |
| 5627 | + return `${this.options.storagePrefix}:${this.tableId}`; | |
| 5628 | + } | |
| 5629 | + | |
| 5630 | + saveState(column, direction) { | |
| 5631 | + if (!this.options.storage || !this.tableId) return; | |
| 5632 | + | |
| 5633 | + localStorage.setItem( | |
| 5634 | + this.storageKey, | |
| 5635 | + JSON.stringify({ column, direction }) | |
| 5636 | + ); | |
| 5637 | + } | |
| 5638 | + | |
| 5639 | + loadState() { | |
| 5640 | + if (!this.options.storage || !this.tableId) return null; | |
| 5641 | + | |
| 5642 | + try { | |
| 5643 | + return JSON.parse(localStorage.getItem(this.storageKey)); | |
| 5644 | + } catch { | |
| 5645 | + return null; | |
| 5646 | + } | |
| 5647 | + } | |
| 5648 | + | |
| 5649 | + /* ---------- UI helpers ---------- */ | |
| 5650 | + | |
| 5651 | + clearIndicators() { | |
| 5652 | + this.headers.forEach(th => { | |
| 5653 | + th.classList.remove('sorted-asc', 'sorted-desc'); | |
| 5654 | + th.removeAttribute('aria-sort'); | |
| 5655 | + }); | |
| 5656 | + } | |
| 5657 | + | |
| 5658 | + applyIndicator(th, direction) { | |
| 5659 | + th.classList.add(direction === 'asc' ? 'sorted-asc' : 'sorted-desc'); | |
| 5660 | + th.setAttribute('aria-sort', direction); | |
| 5661 | + } | |
| 5662 | + | |
| 5663 | + toggleDirection(current) { | |
| 5664 | + return current === 'asc' ? 'desc' : 'asc'; | |
| 5665 | + } | |
| 5666 | + | |
| 5667 | + /* ---------- Sorting flow ---------- */ | |
| 5668 | + | |
| 5669 | + persistState(column, direction, th = null, persist = true, isrestore = false) { | |
| 5670 | + if (th) { | |
| 5671 | + this.clearIndicators(); | |
| 5672 | + this.applyIndicator(th, direction); | |
| 5673 | + } | |
| 5674 | + | |
| 5675 | + if (persist) { | |
| 5676 | + this.saveState(column, direction); | |
| 5677 | + } | |
| 5678 | + | |
| 5679 | + if (typeof this.options.onPersist === 'function') { | |
| 5680 | + this.options.onPersist({ | |
| 5681 | + table: this.table, | |
| 5682 | + column, | |
| 5683 | + direction, | |
| 5684 | + isrestore | |
| 5685 | + }); | |
| 5686 | + } | |
| 5687 | + } | |
| 5688 | + | |
| 5689 | + /* ---------- Init ---------- */ | |
| 5690 | + | |
| 5691 | + restore() { | |
| 5692 | + const saved = this.loadState() || this.options.defaultSort; | |
| 5693 | + if (!saved) return; | |
| 5694 | + | |
| 5695 | + const th = this.table.querySelector( | |
| 5696 | + `[data-key="${saved.column}"]` | |
| 5697 | + ); | |
| 5698 | + | |
| 5699 | + if (th) { | |
| 5700 | + this.persistState(saved.column, saved.direction, th, false, true); | |
| 5701 | + } | |
| 5702 | + } | |
| 5703 | + | |
| 5704 | + bindEvents() { | |
| 5705 | + this.headers.forEach(th => { | |
| 5706 | + th.addEventListener('click', () => { | |
| 5707 | + const column = th.dataset.key; | |
| 5708 | + const isAsc = th.classList.contains('sorted-asc'); | |
| 5709 | + const direction = this.toggleDirection(isAsc ? 'asc' : 'desc'); | |
| 5710 | + | |
| 5711 | + this.persistState(column, direction, th); | |
| 5712 | + }); | |
| 5713 | + }); | |
| 5714 | + } | |
| 5715 | + | |
| 5716 | + init() { | |
| 5717 | + if (!this.tableId && this.options.storage) { | |
| 5718 | + console.warn('TablePersistentState: table has no id, storage disabled'); | |
| 5719 | + } | |
| 5720 | + | |
| 5721 | + this.restore(); | |
| 5722 | + this.bindEvents(); | |
| 5723 | + } | |
| 4276 | 5724 | } |