HEX
Server: LiteSpeed
System: Linux atali.colombiahosting.com.co 5.14.0-570.12.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 13 06:11:55 EDT 2025 x86_64
User: coopserp (1713)
PHP: 8.2.29
Disabled: dl,exec,passthru,proc_open,proc_close,shell_exec,memory_limit,system,popen,curl_multi_exec,show_source,symlink,link,leak,listen,diskfreespace,tmpfile,ignore_user_abord,highlight_file,source,show_source,fpaththru,virtual,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setid,posix_times,posix_ttyname,posix_uname,proc_get_status,proc_nice,proc_terminate
Upload Files
File: /home/coopserp/www/admin.js.tar
home/coopserp/public_html/wp-content/plugins/siteseo/assets/js/admin.js000064400000057257151526426520022456 0ustar00jQuery(document).ready(function($){

	$('.tag-title-btn').on('click', function(e){
		e.preventDefault();

		let input_field = $(this).closest('.wrap-tags').prev('input[type="text"], textarea'),
		current_value = input_field.val(),
		tag = $(this).data('tag');
    
		current_value = current_value || '';
		
		// We need to add a space if there is some content
		if(current_value.length > 0){
			tag = ' ' + tag;
		}

		input_field.val(current_value + tag);
		input_field.focus();
	});

	$('.siteseo-container a').on('click', function(e){
        e.preventDefault(); 
        $('.siteseo-container a').removeClass('active');
        $(this).addClass('active');
    });

	$("[id^='siteseo-toggle-meta-']").on('click', function(){
		$(this).toggleClass('active');
		if($(this).hasClass('active')){
			$('#toggle_state_posts').text('Click to hide any SEO metaboxes / columns for this post type');
			$(this).closest('.siteseo-toggle-cnt').find('.siteseo-suboption-toggle').val("");
		} else{
			$('#toggle_state_posts').text(' Click to show any SEO metaboxes / columns for this post type');
			$(this).closest('.siteseo-toggle-cnt').find('.siteseo-suboption-toggle').val(true);
		}
	});

	$('#siteseo-dismiss-get-started').on('click', function(e){
		e.preventDefault();
		$(this).closest('.siteseo-dashbord-intro').slideUp();

		$.ajax({
			url : siteseoAdminAjax.url,
			type : 'POST',
			data : {
				action : 'siteseo_dismiss_intro',
				nonce : siteseoAdminAjax.nonce
			}
		})
	});

	// toggle handler function
	function handleToggle($toggle, toggleKey, action) {

		const $container = $toggle.closest('.siteseo-toggle-cnt');
		const $stateText = $container.find(`.toggle_state_${toggleKey}`);
		const $input = $(`#${toggleKey}`);

		$container.addClass('loading');
		$toggle.toggleClass('active');

		const newValue = $toggle.hasClass('active') ? '1' : '0';
		$input.val(newValue);
		$stateText.text($toggle.hasClass('active') ? 'Disable' : 'Enable');

		$.ajax({
			url: ajaxurl,
			type: 'POST',
			data: {
				action: action,
				toggle_value: newValue,
				nonce: $toggle.data('nonce')
			},
			success: function(response) {
				if (response.success) {
					// Show the custom toast message
					showToast('Your settings have been saved.');
				} else {
					console.error('Failed to save toggle state');
					toggleRollback($toggle, $input, $stateText);
					showToast(response.data.message || 'Failed to save toggle state', 'error');
				}
			},
			error: function() {
				console.error('Ajax request failed');
				toggleRollback($toggle, $input, $stateText);
				showToast('Unable to save settings', 'error');
			},
			complete: function() {
				$container.removeClass('loading');
			}
		});
	}

	// Rollback function in case of AJAX error
	function toggleRollback($toggle, $input, $stateText) {
		$toggle.toggleClass('active');
		$input.val($toggle.hasClass('active') ? '1' : '0');
		$stateText.text($toggle.hasClass('active') ? 'Disable' : 'Enable');
	}

	$('.siteseo-toggle-Sw').on('click', function() {
		const $toggle = $(this);
		const toggleKey = $toggle.data('toggle-key');
		const action = $toggle.data('action');

		handleToggle($toggle, toggleKey, action);
	});

	// toast msg
	function showToast(message, type = 'success') {
		const toast = $('<div>')
			.addClass('siteseo-toast')
			.addClass(type) 
			.html(`<span class="dashicons dashicons-yes"></span> ${message}`);

		$('body').append(toast); 

		// 3 seconds
		toast.fadeIn(300).delay(3000).fadeOut(300, function () {
			toast.remove();
		});
	}

	// default off
	$('.siteseo-suggetion').hide();

    $('.tag-select-btn').click(function(e){
        e.preventDefault();
        e.stopPropagation();
		
        $('.siteseo-suggetion').not($(this).siblings('.siteseo-suggestions-wrapper').find('.siteseo-suggetion')).hide();
        
        $(this).siblings('.siteseo-suggestions-wrapper').find('.siteseo-suggetion').toggle();
    });

    $('.siteseo-suggestions-container .section').click(function(e){
        e.preventDefault();
        e.stopPropagation();
        
        let tag = $(this).find('.tag').text();
    		let $wrapTags = $(this).closest('.siteseo-suggetion').closest('.wrap-tags');

    		let targetField = $wrapTags.prev('input[type="text"], textarea');

    		// for global schema
    		if(targetField.length === 0){
    			targetField = $wrapTags.find('input[type="text"], textarea');
    		}
        
        insertAtCursor(targetField, tag);
        
        $(this).closest('.siteseo-suggetion').hide();
    });

    $(document).click(function(e){
        if(!$(e.target).closest('.wrap-tags').length){
            $('.siteseo-suggetion').hide();
        }
    });

    $('.siteseo-search-box').on('input', function(){
        var searchText = $(this).val().toLowerCase();
        $(this).closest('.siteseo-suggetion').find('.section').each(function() {
            var sectionText = $(this).text().toLowerCase();
            $(this).toggle(sectionText.indexOf(searchText) > -1);
        });
    });
	
	function insertAtCursor(field, text){
		if(!field || field.length === 0) return;

		field = field[0];
		let scroll_pos = field.scrollTop || 0;
		let current_value = field.value;

		let caretPos = field.selectionStart,
			before = current_value.substring(0, caretPos),
			after = current_value.substring(caretPos);

		let hash_index = before.lastIndexOf('#');

		if(hash_index !== -1){
			// If '#' exists before the caret, replace the last '#' with a space and insert the text
			before = before.substring(0, hash_index) + " ";
			let new_value = before + text + after;
			field.value = new_value;

			// Set caret after inserted text
			let new_position = before.length + text.length;
			field.setSelectionRange(new_position, new_position);
		} else{
			// If no '#', insert at the end, normal case
			field.value = current_value + text;
			let new_position = field.value.length;
			field.setSelectionRange(new_position, new_position);
		}

		field.scrollTop = scroll_pos;
		field.focus();
	}

    $('.tag-title-btn').click(function(e){
        e.preventDefault();
        e.stopPropagation();

        var tag = '';
        var btnId = $(this).attr('id');
        if(btnId === 'tag-select-btn'){
            tag = '%%sitetitle%%'; // replace
        }
        
        if(tag){
            var targetField = $(this).closest('.wrap-tags').prev('input[type="text"], textarea');
            insertAtCursor(targetField, tag);
        }
    });

	// facebook upload Image
	$('#facebook_upload_logo').click(function(e){
		var mediaUploader;
		e.preventDefault();

		if(mediaUploader){
			mediaUploader.open();
			return;
		}

		mediaUploader = wp.media.frames.file_frame = wp.media({
			title: 'Media',
			button:{
				text: 'Select'
			},
			multiple: false
		});

		mediaUploader.on('select', function(){
			var attachment = mediaUploader.state().get('selection').first().toJSON();
			$('#facebook_org_image_url').val(attachment.url);
		});

		mediaUploader.open();
	});
	
	//twitter cart image
	$('#twitter_logo').click(function(e){
		var mediaUploader;
		e.preventDefault();

		if(mediaUploader){
			mediaUploader.open();
			return;
		}

		mediaUploader = wp.media.frames.file_frame = wp.media({
			title: 'Media',
			button:{
				text: 'Select'
			},
			multiple: false
		});

		mediaUploader.on('select', function(){
			var attachment = mediaUploader.state().get('selection').first().toJSON();
			$('#twitter_logo_url').val(attachment.url);
		});

		mediaUploader.open();
	});
	
	//knowledgen org
	$('#knowledge_org_logo').on('click', function(e){
		var mediaUploader;
		e.preventDefault();

		if(mediaUploader){
			mediaUploader.open();
			return;
		}

		mediaUploader = wp.media.frames.file_frame = wp.media({
			title: 'Media',
			button:{
				text: 'Select'
			},
			multiple: false
		});

		mediaUploader.on('select', function(){
			var attachment = mediaUploader.state().get('selection').first().toJSON();
			$('#knowledge_org_logo_url').val(attachment.url);
		});

		mediaUploader.open();
	});
	
	// get active tab
	function getDefaultTab(){
		return $('.siteseo-tab.active').attr('id') || 'tab_siteseo_home';
	}

	function setActiveTab(tabId){
		// Hide all first
		$('.siteseo-tab').hide();

		// remove classes
		$('.siteseo-nav-tab').removeClass('siteseo-nav-tab-active');
		$('.siteseo-tab').removeClass('active');

		if($('.siteseo-nav-tab[data-tab="' + tabId + '"]').length){
			$('[data-tab="' + tabId + '"]').addClass('siteseo-nav-tab-active');
		} else{
			$('#' + tabId + '-tab').addClass('siteseo-nav-tab-active');
		}
		$('#' + tabId).addClass('active').show(); // show active tab

		// Hide save button
		let exclude_tab = ['tab_siteseopro_robots_txt', 'tab_auto_schema', 'tab_siteseopro_htaccess'],
		is_pro_exits = (typeof siteseo_pro !== 'undefined' && siteseo_pro.schema) ? true : false,
		$save_btn = $('.siteseo-submit-button');

		if((is_pro_exits && exclude_tab.includes(tabId))){
			$save_btn.hide();
		} else {
			$save_btn.show();
		}
		// save ative tab 
		localStorage.setItem('siteseo_active_tab', tabId);
	}

	//get from localstorage
	var savedTab = localStorage.getItem('siteseo_active_tab');
	var defaultTab = getDefaultTab();

	// Check if the saved tab exists otherwise use the default tab
	if(savedTab && $('#' + savedTab).length){
		setActiveTab(savedTab);
	} else{
		setActiveTab(defaultTab);
	}

	// Click handler for navigation tabs
	$('.siteseo-nav-tab').on('click', function(e){
		e.preventDefault();
		var tabId = $(this).data('tab') || $(this).attr('id').replace('-tab', '');
		setActiveTab(tabId);
	});

	$('#siteseo-generate-api-key-btn').on('click', function(){
        var button = $(this);
        var inputField = $('#bing-api-key');
        
        // Disable button while processing
        button.prop('disabled', true);
        
        $.ajax({
            url: siteseoAdminAjax.url,
            type: 'POST',
            data: {
                action: 'siteseo_generate_bing_api_key',
                nonce: siteseoAdminAjax.nonce
            },
            success: function(response) {
                if (response.success) {
                    // Insert the generated key into the input field
                    inputField.val(response.data.api_key);
                    
                    // Optional: Add a subtle highlight effect
                    inputField.css('background-color', '#f0f9ff')
                           .animate({'background-color': '#ffffff'}, 1500);
                } else {
                    alert('Error generating API key. Please try again.');
                }
            },
            error: function() {
                alert('Error generating API key. Please try again.');
            },
            complete: function() {
                // Re-enable the button
                button.prop('disabled', false);
            }
        });
    });
	
	$('#siteseo-submit-urls-button').on('click', function(e){
		e.preventDefault();
		var $button = $(this);
		var $spinner = $('.spinner');
		var $responseDiv = $('#url-submitter-response');
		
		$button.prop('disabled', true);
		$spinner.addClass('is-active');
		$responseDiv.empty();

		//bing responce
		function getBingResponseMessage(code){
			switch(code){
				case 200:
					return 'URLs submitted successfully';
				case 202:
					return 'URL received. IndexNow key validation pending.';
				case 400:
					return 'Bad request: Invalid format';
				case 403:
					return 'Forbidden: Key not valid';
				case 422:
					return 'Unprocessable Entity: URLs don\'t belong to the host';
				case 429:
					return 'Too Many Requests: Potential Spam';
				default:
					return 'Something went wrong';
			}
		}

		$.ajax({
			url: siteseoAdminAjax.url,
			method: 'POST',		
			data:{
				action: 'siteseo_url_submitter_submit',
				nonce: siteseoAdminAjax.nonce,
				search_engine: $('input[name="siteseo_options[search_engine_google]"]:checked').val() || $('input[name="siteseo_options[search_engine_bing]"]:checked').val(),
				urls: $('textarea[name="siteseo_options[instant_indexing_batch]"]').val()
			},

			success: function(response){
				if(response.success){
					
					let failed_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" width="20px" height="20px" fill="#EA3323"><path d="M340.67-284 480-423.33 619.33-284 676-340.67 536.67-480 676-619.33 619.33-676 480-536.67 340.67-676 284-619.33 423.33-480 284-340.67 340.67-284ZM479.79-50.67q-88.43 0-167.26-33.27-78.82-33.27-137.07-91.52-58.25-58.25-91.52-137.07-33.27-78.82-33.27-167.38 0-89.24 33.33-167.66Q117.33-726 175.86-784.5q58.53-58.49 136.96-91.99Q391.26-910 479.56-910q89.33 0 168.08 33.44 78.75 33.43 137.03 91.82 58.27 58.39 91.8 137.01Q910-569.12 910-479.61q0 88.79-33.51 167-33.5 78.21-91.99 136.75Q726-117.33 647.57-84T479.79-50.67Zm-.02-106q134.74 0 229.15-94.09 94.41-94.1 94.41-229.01 0-134.74-94.18-229.15T479.9-803.33q-134.41 0-228.82 94.18T156.67-479.9q0 134.41 94.09 228.82 94.1 94.41 229.01 94.41ZM480-480Z"/></svg>',
					success_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" width="20px" height="20px" fill="#48752C"><path d="M480.33-50.67q-89.64 0-169.13-32.93-79.49-32.94-137.08-90.52-57.58-57.59-90.52-137.08-32.93-79.49-32.93-169.13 0-89.9 32.84-168.49 32.83-78.6 90.84-136.61 58-58.02 137.23-91.29Q390.81-910 480-910q71.29 0 134.65 20.31 63.37 20.31 115.68 58.69l-78 78.33q-36.41-22.64-79.83-36.65-43.42-14.01-92.5-14.01-136.85 0-230.09 92.64-93.24 92.65-93.24 230.34 0 137.68 93.13 230.68 93.14 93 229.84 93 136.69 0 230.19-92.75 93.5-92.74 93.5-230.58 0-20.98-3-40.3-3-19.32-8-38.37l86.34-86q15 38.55 23.16 79.21 8.17 40.65 8.17 84.53 0 90.6-33.28 169.59-33.27 78.99-91.29 136.99-58.01 58.01-136.61 90.84-78.59 32.84-168.49 32.84Zm-60.66-228.66-180.34-181 72-73L419.67-425 837-843.33l73.67 73-491 491Z"/></svg>';

					var responseHtml = '';
			
					//Bing 
					if(response.data.details.bing){
						responseHtml += `
						<div class="wrap-bing-response">
							<table class="form-table">
								<tr>
									<td><h4>Bing Response</h4>`;
						
						if(response.data.details.bing.status_code == 200 || response.data.details.bing.status_code == 202){
							responseHtml += success_svg;	
						} else{
							responseHtml +=  failed_svg;
						}
			
						responseHtml += `</td>
									<td><code>${getBingResponseMessage(response.data.details.bing.status_code)}</code></td>
								</tr>
							</table>
						</div>`;
					}
			
					// Google Response
					if(response.data.details.google){
						responseHtml += `
						<div class="wrap-google-response">
							<table class="form-table">`;
							responseHtml += `
							<tr>
								<td><h4>Google Response</h4>`;
								
								if(response.data.details.google.status_code == 200){
									responseHtml += success_svg;	
								} else{
									responseHtml +=  failed_svg;
								}
									
								responseHtml += `</td>
								<td>
									<strong>Status: ${response.data.details.google.status_code}</strong>
									<p>URL:</p>
									<p>
										${response.data.details.google.urls.map(function(url){
											return `<code style="display:inline-block;">${url}</code>`;
										})}
									
									</p>
								</td>
							</tr>`;
			
						responseHtml += `</table>
						</div>`;
					}
			
					$responseDiv.html(responseHtml);
				} else{
					var errorMessage = response.data && response.data.message ? response.data.message : 'An error occurred.';
					$responseDiv.html('<div class="notice notice-error"><p>' + errorMessage + '</p></div>');
				}
			},
			error: function (xhr){
				console.error(xhr.responseText);
				$responseDiv.html('<div class="notice notice-error"><p>Request failed: ' + xhr.statusText + '</p></div>');
			},
			complete: function(){
				$button.prop('disabled', false);
				$spinner.removeClass('is-active');
			}
		});
	});
	
	/** scroll screen**/
	$('.siteseo-container a').on('click', function(e){
		e.preventDefault();
		
		var $container = $(this).closest('.siteseo-container');
		var $table = $(this).closest('table');
		
		$('.siteseo-container a').removeClass('active');
		
		var targetId = $(this).attr('href');
		targetId = targetId.replace(/^[#-]/, '');
		
		var $targetSection = $table.find('#' + targetId);
		if($targetSection.length){
			$('html, body').animate({
				scrollTop: $targetSection.offset().top - 100
			}, 500);
			
			$(this).addClass('active');
		}
    });

    function isElementInViewport(el){
		var rect = el[0].getBoundingClientRect();
		var windowHeight = $(window).height();

		var elementMiddle = rect.top + (rect.height / 2);
		return elementMiddle >= 0 && elementMiddle <= windowHeight;
    }

    function updateActiveSection(){
		$('table').each(function(){
			var $table = $(this);
			var activeFound = false;
			
			$table.find('.siteseo-container a').each(function(){
				var targetId = $(this).attr('href').replace(/^[#-]/, '');
				var $targetSection = $table.find('#' + targetId);
				
				if($targetSection.length && isElementInViewport($targetSection)){
					$('.siteseo-container a').removeClass('active');
					$(this).addClass('active');
					activeFound = true;
					return false;
				}
			});
		});
    }

    var scrollTimeout;
	$(window).on('scroll', function(){
		clearTimeout(scrollTimeout);
		scrollTimeout = setTimeout(function(){
			updateActiveSection();
		}, 100);
    });
	
	updateActiveSection();
	

	/*** reset setting***/
	$('.siteseo-container a').on('click', function(e){
		e.preventDefault();
		
		var $container = $(this).closest('.siteseo-container');
		var $table = $(this).closest('table');
		
		$('.siteseo-container a').removeClass('active');
		$(this).addClass('active');
		
		var targetId = $(this).attr('href').replace(/^[#-]/, '');
		var $targetSection = $table.find('#' + targetId);
		
		if($targetSection.length) {
			$('html, body').animate({
				scrollTop: $targetSection.offset().top - 100
			}, 500);
		}
	});

	function updateActiveSection(){
		$('table').each(function(){
			var $table = $(this);
			var windowTop = $(window).scrollTop();
			var windowBottom = windowTop + $(window).height();
			var windowCenter = windowTop + ($(window).height() / 2);

			var $sections = $table.find('[id]');
			var currentSection = null;
			
			$sections.each(function(){
				var $section = $(this);
				var sectionTop = $section.offset().top;
				var sectionBottom = sectionTop + $section.outerHeight();
				
				if(sectionTop <= windowCenter && sectionBottom >= windowCenter){
					currentSection = $section;
					return false;
				}
			});
			
			if(currentSection){
				var sectionId = currentSection.attr('id');
				var $links = $table.find('.siteseo-container a');
				
				$links.removeClass('active');
				$links.each(function(){
					var href = $(this).attr('href').replace(/^[#-]/, '');
					if(href === sectionId){
						$(this).addClass('active');
					}
				});
			}
		});
	}

	var scrollTimeout;
	$(window).on('scroll', function(){
		if(scrollTimeout){
			clearTimeout(scrollTimeout);
		}
		scrollTimeout = setTimeout(function(){
			updateActiveSection();
		}, 100);
	});

	updateActiveSection();
	$('#siteseo-reset-settings').on('click', function(e){
		e.preventDefault();
		
		if(confirm('Are you sure you want to reset all settings?')){
			$.ajax({
				url: siteseoAdminAjax.url,
				type: 'POST',
				data:{
					action: 'siteseo_reset_settings',
					nonce: siteseoAdminAjax.nonce
				},
				success: function(response){
					if(response.success){
						alert('Settings reset successfully.');
					} else{
						alert('Failed to reset settings: ' + response.data.message);
					}
				},
				error: function(xhr, status, error){
					alert('An error occurred: ' + error);
				}
			});
		} else{
			return false;
		}
	});

	
	/*** export settings***/
	$('#siteseo-export-btn').on('click', function(e){
		e.preventDefault();
		
		$.ajax({
			url: siteseoAdminAjax.url,
			type: 'POST',
			data:{
				action: 'siteseo_export_settings',
				nonce: siteseoAdminAjax.nonce
			},
			success: function(response){
				
				const blob = new Blob([JSON.stringify(response)], {type: 'application/json'});
				const url = window.URL.createObjectURL(blob);
				
				const a = document.createElement('a');
				a.style.display = 'none';
				a.href = url;
				a.download = 'siteseo-settings-export-' + new Date().toLocaleDateString('en-US').replace(/\//g, '-') + '.json';
				
				document.body.appendChild(a);
				a.click();
				
				window.URL.revokeObjectURL(url);
				document.body.removeChild(a);
			},
			error: function(xhr, status, error){
				console.error('Export failed:', error);
				alert('Export failed. Please try again.');
			}
		});
	});
	
	/** import settings**/
	$('#siteseo-import-btn').on('click', function (e){
		e.preventDefault();

		const fileInput = $('#siteseo-import-file')[0];

		if(!fileInput.files || !fileInput.files[0]){
			alert('Please select a file to import.');
			return;
		}

		const formData = new FormData();
		formData.append('action', 'siteseo_import_settings');
		formData.append('nonce', siteseoAdminAjax.nonce);
		formData.append('import_file', fileInput.files[0]);

		$('#siteseo-import-btn').prop('disabled', true);

		$.ajax({
			url: siteseoAdminAjax.url,
			type: 'POST',
			data: formData,
			processData: false,
			contentType: false,
			success: function (response){
				if(response.success){
					alert('Success: ' + response.data.message);
					fileInput.value = '';

					setTimeout(function(){
						location.reload();
					}, 1500);
				} else{
					alert('Error: ' + response.data.message);
				}
			},
			error: function(xhr, status, error){
				alert('Error: Import failed. Please try again.');
			},
			complete: function(){
				$('#siteseo-import-btn').prop('disabled', false);
			}
		});
	});

	//migration
	$(".siteseo-section-tool").hide();
    
    $("#siteseo-plugin-selector").on('change', function(){
        var selectedTool = $(this).val();
        $(".siteseo-section-tool").hide();
        if(selectedTool !== "none"){
            $("#" + selectedTool).show();
        }
    });

	// ajax migrate from others
	 $('button[id^="siteseo-"][id$="-migrate"]').on('click', function(){
        const button = $(this);
        const plugin = button.attr('id').replace('siteseo-', '').replace('-migrate', '');
        const spinner = button.next('.spinner');
        const log = button.siblings('.log');

        button.prop('disabled', true);
        spinner.addClass('is-active');
        log.empty();

        $.ajax({
            url: siteseoAdminAjax.url,
            type: 'POST',
            data: {
                action: 'siteseo_migrate_seo',
                plugin: plugin,
                nonce: siteseoAdminAjax.nonce
            },
            success: function(response){
                if(response.success){
                    log.html('<div class="notice notice-success">' + response.data.message + '</div>');
                } else{
                    log.html('<div class="notice notice-error">' + response.data.message + '</div>');
                }
            },
            error: function(){
                log.html('<div class="notice notice-error">Migration failed. Please try again.</div>');
            },
            complete: function(){
                button.prop('disabled', false);
                spinner.removeClass('is-active');
            }
        });
    });
    
	// Clean indexing history
	$('#siteseo-clear-history').on('click', function(e){
		e.preventDefault();
		$.ajax({
			url: siteseoAdminAjax.url,
			type: 'POST',
			data: {
				action: 'siteseo_clear_indexing_history',
				nonce: siteseoAdminAjax.nonce
			},
			success: function(response){
				location.reload();
			}
		});
	});
  
	// Response code table guilde
	$('.siteseo-show-details').next('.siteseo-response-code-table').hide();

	$('.siteseo-show-details').on('click', function(e){
		let description = $(this).next('.siteseo-response-code-table'),
		icon = $(this).find('.dash-icon'); 

		if(description.is(':visible')){
			description.hide();
			icon.removeClass('dashicons-arrow-up-alt2').addClass('dashicons-arrow-down-alt2');
		} else{
			description.show();
			icon.removeClass('dashicons-arrow-down-alt2').addClass('dashicons-arrow-up-alt2');
		}
	});
  
});home/coopserp/public_html/wp-content/plugins/speedycache/assets/js/admin.js000064400000122006151526433370023242 0ustar00(function($){
	window.addEventListener('DOMContentLoaded', function(){
		speedycache_handle_tab();
		
		window.addEventListener('hashchange', speedycache_handle_tab);

		jQuery('.speedycache-save-settings-wrapper button, .speedycache-btn-spl-wrapper button').on('click', speedycache_save_settings);
		jQuery('#speedycache-analyze').on('click', speedycache_analyze_speed);
		
		jQuery('.speedycache-tooltip-link').on('mouseover', function(){
			let jEle = jQuery(this),
			tooltip = jEle.find('.speedycache-link-tooltip'),
			elementHeight = Math.ceil(tooltip.outerHeight()/2);

			tooltip.fadeIn('fast').css({
                top: `-${elementHeight+10}px`, // Position it above the parent
            });
		});
		
		jQuery('.speedycache-tooltip-link').on('mouseleave', function(){
			let jEle = jQuery(this);
			jEle.find('.speedycache-link-tooltip').hide();
		});
		
		// Delay JS
		jQuery('#speedycache_delay_js').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}

			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});

		jQuery('#speedycache_purge_varnish').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});
		
		jQuery('#speedycache_critical_images').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});
		
		jQuery('#speedycache_lazy_load_html').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});
		
		jQuery('#speedycache_preload').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});
		
		jQuery('#speedycache_dns_prefetch').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});

		jQuery('#speedycache_speculative_loading').on('change',function(){
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}

			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
			
			let instant_page = jQuery('#speedycache_instant_page');
			if(instant_page && instant_page.is(':checked')){
				instant_page.prop('checked', false);
				alert('Instant page and Speculation loading are similar feature, so you should not use them together');
			}
		})
		
		jQuery('#speedycache_preload_resources').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});

		jQuery('#speedycache_render_blocking').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});
		
		// Critical CSS Status
		jQuery('#speedycache_critical_css').on('change', function(e) {
			let prevent_open = true;

			if(e.isTrigger){
				prevent_open = false;			
			}
			
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}

			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this), prevent_open);
		});
		
		jQuery('#speedycache_pre_connect').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});
		
		jQuery('#speedycache_unused_css').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});
		
		jQuery('.speedycache-action-link').on('click', function(){
			let action_name = jQuery(this).attr('action-name');

			switch(action_name){
				case 'speedycache_critical_css':
					speedycache_critical_css();
					break;
			}
		});
		
		// Lazy Load
		jQuery('#speedycache_lazy_load').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});
		
		jQuery('#speedycache_update_heartbeat').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});
		
		jQuery('#speedycache_limit_post_revision').on('change', function() {
			if(!jQuery(this).is(':checked')){
				speedycache_toggle_settings_link(jQuery(this));
				return;
			}
			
			speedycache_toggle_settings_link(jQuery(this));
			speedycache_open_modal(jQuery(this));
		});

		// Add Suggested Scripts
		var $textarea = jQuery('#speedycache_delay_js_scripts');

		jQuery('.speedycache-delay-suggestions').on('click', function(event) {
			event.preventDefault();
			if($textarea.length){
				var $suggestions_text = jQuery('.speedycache-modal-scripts').text().trim().replace(/<br\s*\/?>/gi, '\n').replace(/\n\s+/g, '\n').replace(/\s+\n/g, '\n').replace(/\n+/g, '\n'),
				current_text = $textarea.val().trim(),
				new_text = current_text ? current_text + '\n' + $suggestions_text : $suggestions_text;
				//Only add unique values
				var unique_text = [...new Set(new_text.split('\n'))].join('\n');
				$textarea.val(unique_text);
			}
		});
		
		//Event Listener for Settings link for popup options
		jQuery('.speedycache-modal-settings-link').off('click').on('click', function() {
			var id = jQuery(this).attr('setting-id'),
			input = jQuery('#'+id);
			
			input.trigger('change');
		});
		
		// Add Excludes Btn
		jQuery('#speedycache_add_excludes').on('click', function() {
			speedycache_open_modal(jQuery(this));
		});
		
		jQuery('#speedycache-cdn-type').on('change', function(e){

			let cdn_type = jQuery(e.target).val(),
			cdn_key = jQuery('#speedycache-cdn-key').closest('.speedycache-stacked-option-wrap'),
			cdn_url = jQuery('#speedycache-cdn-url').closest('.speedycache-stacked-option-wrap');

			if(cdn_type == 'cloudflare'){
				cdn_url.hide();
				cdn_key.show();
				
				return;
			}else if(cdn_type == 'bunny'){
				cdn_url.show();
				cdn_key.show();

				return;
			}
			
			// For other we only need to show the URL field
			cdn_url.show();
			cdn_key.hide();
			
			return;
		});
		
		// Toggle exact time field of cache lifespan
		jQuery('#speedycache-run-exact-time').on('click', function(e){
			if(jQuery(this).is(':checked')){
				jQuery('#speedycache-exact-time-selector').css('display', 'flex');
				return;
			}

			jQuery('#speedycache-exact-time-selector').hide();
		});
		
		jQuery('#speedycache-ll-type').on('change', function(e){
			let type = jQuery(e.target).val(),
			custom_input = jQuery('#speedycache-custom-ll-url');

			if(type == 'default'){
				custom_input.hide();
				return;
			}
			
			custom_input.show();
		});

		jQuery('#speedycache-import-export').on('change', function(e){
      let task = jQuery(e.target).val(),
			import_block = jQuery('.speedycache-import-block'),
			export_block = jQuery('.speedycache-export-block');

			if(task == 'import'){
				import_block.show();
				export_block.hide();
			} else if(task == 'export'){
				export_block.show();
				import_block.hide();
			}
		})
		
		jQuery('#speedycache-cdn-type').trigger('change');
		
		jQuery('#speedycache-exclude-type').on('change', speedycache_update_excluded_options);
		jQuery('#speedycache-exclude-rule-prefix').on('change', speedycache_update_excluded_prefix);
		jQuery('.speedycache-exclude-btn-wrap button').on('click', speedycache_update_excludes);
		jQuery('#speedycache-type-filter').on('change', speedycache_filter_exclude_type);
		jQuery(document).on('click', '.speedycache-delete-rule', speedycache_delete_exclude_rule);
		jQuery('.speedycache-db-optm-btn').on('click', speedycache_db_optm);
		jQuery('.speedycache-preloading-add').on('click', speedycache_add_preload_resource);
		jQuery('.speedycache-preloading-table').on('click', '.dashicons-trash', speedycache_delete_preload_resource);
		jQuery('.speedycache-flush-db').on('click', speedycache_flush_objects);
		jQuery('.speedycache-import-settings').on('click', speedycache_import_settings);
		jQuery('.speedycache-export-settings').on('click', speedycache_export_settings);
		jQuery('#speedycache-license-btn').on('click', speedycache_verify_license);
	});
})(jQuery);

function speedycache_handle_tab(){

	let hash = location.hash.trim().replace('#', ''),
	nav = jQuery('#speedycache-navigation');

	if(!hash.length){
		let tab = jQuery('#speedycache-dashboard');
		
		tab.siblings().hide();
		tab.css('display', 'flex');
		nav.find('.speedycache-nav-selected').removeClass('speedycache-nav-selected');
		nav.find('a[href=\\#'+hash+']').addClass('speedycache-nav-selected')
		return
	}
	
	let tab = jQuery('#speedycache-'+hash);
	
	// Loading the stats for DB tab
	if(hash == 'db' && typeof speedycache_pro_get_db_optm === 'function'){
		speedycache_pro_get_db_optm();
	}
	
	// Loading the stats for image optm tab
	if(hash == 'image' && !speedycache_ajax.load_img){
		speedycache_ajax.load_img = true;
		speedycache_image_optimization();
	}

	tab.siblings().hide();
	tab.css('display', 'flex');
	nav.find('.speedycache-nav-selected').removeClass('speedycache-nav-selected');
	nav.find('a[href=\\#'+hash+']').addClass('speedycache-nav-selected')

}

function speedycache_save_settings(){
	event.preventDefault();

	let jEle = jQuery(event.target),
	has_error = false;
	
	jEle.find('span.speedycache-spinner').addClass('speedycache-spinner-active');
	
	form_data = jEle.closest('form').serializeArray();

	jQuery.ajax({
		url : speedycache_ajax.url,
		method : "POST",
		data : form_data,
		success: function(res){
			if(res.success){
				return;
			}
			
			has_error = true;
			if(res.data){
				alert(res.data);
			}
			
			alert("Something went wrong");
		}
	}).always(function(){
		jEle.find('span.speedycache-spinner')?.removeClass('speedycache-spinner-active');
		
		// Need to show a tick if the save was success
		if(!has_error){
			let check = jEle.find('svg.speedycache-spinner-done');
      if(check){
  			check.addClass('speedycache-spinner-done-active');
  			setTimeout(() => {
  				check.removeClass('speedycache-spinner-done-active');
  			}, 2000);
      }
		}
	});
}

function speedycache_filter_exclude_type(){
	let jEle = jQuery(event.target),
	list = jQuery('.speedycache-exclude-list'),
	filter = jEle.val();

	list.find('tbody tr').filter(function(){
		jQuery(this).toggle(jQuery(this).find('td').eq(0).text().toLowerCase().indexOf(filter) > - 1);
	});
}

function speedycache_delete_exclude_rule(){
	event.preventDefault();

	let jEle = jQuery(event.target),
	tr = jEle.closest('tr'),
	rule_id = tr.data('id')
	
	jEle.find('span').addClass('speedycache-spinner-active');
	

	jQuery.ajax({
		url : speedycache_ajax.url,
		method : "POST",
		data : {
			'_ajax_nonce' : speedycache_ajax.nonce,
			'action' : 'speedycache_delete_exclude_rule',
			'rule_id' : rule_id			
		},
		success: function(res){
			if(res.success){
				tr.slideUp();
				return;
			}
			
			if(res.data){
				alert(res.data);
				return;
			}

			alert('Something went wrong deleting the rule');
		}
	}).always(function(){
		jEle.find('span').removeClass('speedycache-spinner-active');
	});
}

function speedycache_toggle_settings_link(jEle) {
	var wrap = jEle.closest('.speedycache-option-wrap'),
	setting = wrap.find('.speedycache-modal-settings-link, .speedycache-action-link');
	
	if(jEle.is(':checked')) {
		setting.show();
		return;
	}
	
	setting.hide();
}

function speedycache_open_modal(jEle, prevent_open) {
	var id_attr = 'id';
	
	if(prevent_open){
		return;
	}
	
	if(jEle.attr('modal-id')) {
		id_attr = 'modal-id'
	}
	
	//For Settings Link
	if(jEle.attr('setting-id')) {
		id_attr = 'setting-id';
	}
	
	var modal_id = jEle.attr(id_attr),
	speedycache_modal = jQuery("div[modal-id='"+modal_id+"']");
	
	if(speedycache_modal && speedycache_modal.css('visibility') === 'hidden') {
		speedycache_modal.css('visibility','visible');
		speedycache_close_modal();
	}
}

function speedycache_update_excluded_options(){
	let jEle = jQuery(event.target),
	prefix = jQuery('#speedycache-exclude-rule-prefix'),
	exclude_type = jEle.val();

	prefix.val(""); // Resets to select value option
	prefix.find('option').filter(function(){
		jQuery(this).toggle(jQuery(this).data('partof').toLowerCase().indexOf(exclude_type) > - 1);
	});
}

// Toggles content input of excludes settings
function speedycache_update_excluded_prefix(){
	let jEle = jQuery(event.target),
	val = jEle.val(),
	content = jQuery('[for="speedycache-exclude-rule-content"]').closest('.speedycache-input-wrap');
	
	if(val == 'contain' || val == 'exact' || val == 'startwith' || val == 'post_id' || val == 'shortcode'){
		content.show();
		content.find('textarea, input')?.remove();
		let input = jQuery('<input>', {
			type: 'text',
			name: 'content',
			id: 'speedycache-exclude-rule-content',
			'class': 'speedycache-100',
		});
		content.append(input);
		return;
	}

	content.hide();
}

function speedycache_update_excludes(){
	event.preventDefault();
	
	let jEle = jQuery(event.target),
	form = jEle.closest('form');
	
	jEle.find('span').addClass('speedycache-spinner-active');
	
	form_data = form.serializeArray();
	let prefix_field = form_data.find(field => field.name === 'prefix');
	let content_field = form_data.find(field => field.name === 'content');

	if (prefix_field && prefix_field.value === 'post_id' && content_field) {
		if (!/^\d+(,\d+)*$/.test(content_field.value)) {
			alert("Invalid format! Only numbers and commas are allowed, without starting, ending, or consecutive commas.");
			jEle.find('span').removeClass('speedycache-spinner-active');
			return;
		}
	}

	jQuery.ajax({
		url : speedycache_ajax.url,
		method : "POST",
		data : form_data,
		success: function(res){
			
			if(res.success){
				form.trigger('reset');
				jQuery('#speedycache-exclude-list').load(window.location.href + ' #speedycache-exclude-list');
				return;
			}
			
			if(res.data){
				alert(res.data);
				return;
			}

			alert('Something went wrong saving the details');
			
		}
	}).always(function(){
		jEle.find('span').removeClass('speedycache-spinner-active');
	});
}

//Close SpeedyCache Modal
function speedycache_close_modal() {
	jQuery('.speedycache-modal-footer > button, .speedycache-close-modal').on('click', function() {

		//Remove duplicate entries when Submit or Close Button is clicked
		var $textarea = jQuery(this).closest('.speedycache-modal').find('#speedycache_delay_js_scripts');
		if ($textarea.length) {
			var current_text = $textarea.val().trim();
			var unique_text = [...new Set(current_text.split('\n'))].join('\n');
			$textarea.val(unique_text);
		}

		jQuery(this).closest('.speedycache-modal').find('form').trigger('reset');
		jQuery(this).closest('.speedycache-modal *').off();
		jQuery(this).closest('.speedycache-modal').css('visibility','hidden');
	});
}

function speedycache_analyze_speed(){
	jEle = jQuery(event.target);
	jEle.text('[Analysing...]');
	
	jQuery.ajax({
		url : speedycache_ajax.url,
		method : 'GET',
		data : {
			security : speedycache_ajax.nonce,
			action : 'speedycache_test_pagespeed',
		},
		success : function(res){

			if(!res.data || !res.data['score']){
				return
			}

			let donut = jQuery('.speedycache-perf-score-donut'),
			tspan = donut.find('tspan'),
			lowerCircle = donut.find('circle:first-child'),
			strokeCircle = lowerCircle.next();

			lowerCircle.attr('fill', res.data['color'][1]);
			strokeCircle.css('stroke', res.data['color'][0]);
			strokeCircle.attr('stroke-dasharray', res.data['score']+' '+(100 - res.data['score']));

			tspan.text(res.data['score']); // Updated the score
			tspan.css('fill', res.data['color'][2]);
			
		}
	}).always(function(){
		jEle.text('[Updating results]');
		setTimeout(() => {jEle.text('[Analyse]')}, 1000)
		
	});
}

function speedycache_db_optm(){
	event.preventDefault();
	
	let proceed = confirm('Are you sure you want to proceed with this DB optimization action');

	if(!proceed){
		return;
	}
	
	let jEle = jQuery(event.target),
	db_action = jEle.closest('.speedycache-db-row').attr('speedycache-db-name'),
	spinner = jEle.find('.speedycache-spinner');
	spinner.addClass('speedycache-spinner-active');

	jQuery.ajax({
		url : speedycache_ajax.url,
		method : 'POST',
		data : {
			security : speedycache_ajax.nonce,
			action : 'speedycache_optm_db',
			db_action : db_action,
		},
		success: function(res){			
			if(res.success){
				// TODO: make this update the UI too chaning the numbers.
				return false;
			}
			
			if(res.message){
				alert(res.message);
				return;
			}

			alert("Something went wrong unable to optimize this option");
		}
	}).always(function(){
		spinner.removeClass('speedycache-spinner-active');
	});
}

function speedycache_add_preload_resource() {
	event.preventDefault();
	
	let ele = jQuery(event.target),
	loader = ele.find('.speedycache-spinner'),
	form = ele.closest('form'),
	error = false;

	if(!form){
		alert('Unable to get the form details!');
		return;
	}
	
	let form_type = form.data('type');

	// Disabling Add Button
	ele.prop('disabled', true);

	let form_val = {};
	form_data = form.serializeArray();
	
	form_data.forEach((field) => {
		form_val[field.name] = field.value;
		
		let non_required_fields = ['fetch_priority', 'device'];
		if(!field.value && !non_required_fields.includes(field.name)){
			error = true;
		}
	});

	if(error){
		alert('Fill all the fields before adding');
		ele.prop('disabled', false);
		return;
	}
	loader.addClass('speedycache-spinner-active');

	jQuery.ajax({
		'method' : 'POST',
		'url' : speedycache_ajax.url,
		'data' : {
			action : 'speedycache_preloading_add_settings',
			settings : form_val,
			type : form_type,
			security : speedycache_ajax.nonce
		},
		'success' : function(res){
			ele.prop('disabled', false);
			
			if(!res){
				alert('Something went wrong, the response returned is empty');
				return;
			}
			
			if(!res.success){
				alert(res.data);
				return;
			}
			
			let table = ele.closest('.speedycache-modal-content').find('table');
			
			html = `<td>${form_val.resource}</td>
				
				${form_type != 'pre_connect_list' ? '<td>'+form_val.type+'</td>' : ''} 
				<td>${form_val.crossorigin ? 'Yes' : 'No'}</td>
				${form_type != 'pre_connect_list' ? '<td>'+(form_val.fetch_priority ? form_val.fetch_priority : 'Auto')+'</td><td>'+(form_val.device ? form_val.device : 'All')+'</td>' : ''}
				<td data-key="${res.data}"><span class="dashicons dashicons-trash"></span></td>`;
			
			
			if(table.find('.speedycache-preloading-empty').length  > 0){
				let tr = table.find('.speedycache-preloading-empty').closest('tr');
				table.find('.speedycache-preloading-empty').remove();
				
				tr.append(html);
			} else {
				let tbody = table.find('tbody');

				tbody.append('<tr>'+html+'</tr>');
			}
			
			// Resetting the form
			form.find('input, select').map(function(){
				let type = jQuery(this).prop('type');
				
				if(type == 'checkbox'){
					jQuery(this).prop('checked', false);
					return;
				} else 
				
				jQuery(this).val('');
				
			});

			alert('Settings Saved Successfully');
		}
	}).always(function(){
		loader.removeClass('speedycache-spinner-active');
	});
}

function speedycache_delete_preload_resource(){
	let ele = jQuery(event.target),
	key = ele.closest('td').data('key'),
	type = ele.closest('table').data('type'),
	tr = ele.closest('tr');

	tr.css('backgroundColor', 'rgba(255,0,0,0.2)');

	jQuery.ajax({
		'method' : 'POST',
		'url' : speedycache_ajax.url,
		'data' : {
			action : 'speedycache_preloading_delete_resource',
			type : type,
			key : key,
			security : speedycache_ajax.nonce
		},
		success : function(res){
			if(!res || !res.success){
				alert(res.data ? res.data : 'Unable to delete this resource');
				return;
			}
			
			ele.closest('tr').remove();
		}
	});
}

function speedycache_flush_objects() {
	event.preventDefault();

	let jEle = jQuery(event.target),
	spinner = jEle.find('.speedycache-spinner');
	spinner.addClass('speedycache-spinner-active');
	
	jQuery.ajax({
		'method' : 'GET',
		'url' : speedycache_ajax.url + '?action=speedycache_flush_objects&security='+speedycache_ajax.nonce,
		'success' : function(res){
			if(res.success){
				return;
			}
			
			if(res.data){
				alert(res.data);
				return;
			}
			
			alert("Unable to flush Object Cache");
			
		}
  }).always(function(){
		spinner.removeClass('speedycache-spinner-active');
	});
}

function speedycache_import_settings(){
	event.preventDefault();

	let jEle = jQuery(event.target),
	spinner = jEle.find('.speedycache-spinner');
	spinner.addClass('.speedycache-spinner-active');
	let fileInput = jQuery('#speedycache_import_file')[0];

	if(!fileInput.files.length){
		alert('Please select a JSON file to import.');
		return;
	}
	
	if(fileInput.files[0].type && fileInput.files[0].type != 'application/json'){
		alert('The file you have uploaded is not a JSON file.');
		return;
	}

	if(!fileInput.files[0].size){
		alert('Your settings file is empty.');
		return;
	}
	
	let expected_file_name_reg = /speedycache-settings-\d{4}-\d{2}-\d{2}.*\.json/;
	if(fileInput.files[0].name && !expected_file_name_reg.test(fileInput.files[0].name)){
		alert('The format of the name of the file is not valid.');
		return;
	}

	let formData = new FormData();
	formData.append('security', speedycache_ajax.nonce);
	formData.append('file', fileInput.files[0]);

	jQuery.ajax({
		url : speedycache_ajax.url + '?action=speedycache_import_settings',
		type : 'POST',
		data : formData,
		processData : false,
		contentType : false,
		success : function(response){
			if(response.success){
				alert('Settings imported successfully');
				location.reload();
			} else {
				alert(response.data || 'Something went wrong while importing.');
			}
		},
		error: function(){
			alert('Ajax error occurred');
		}
	}).always(function(){
		spinner.removeClass('speedycache-spinner-active');
	})
}

function speedycache_export_settings(){
  event.preventDefault();

	let jEle = jQuery(event.target),
	spinner = jEle.find('.speedycache-spinner');
	spinner.addClass('speedycache-spinner-active');

	jQuery.ajax({
		url : speedycache_ajax.url + '?action=speedycache_export_settings',
		type : 'POST',
		data : {
			'security' : speedycache_ajax.nonce
		},
		success: function(response){
			const blob = new Blob([JSON.stringify(response.data, null, 2)], { type: 'application/json' });
			const link = document.createElement('a');
			link.href = URL.createObjectURL(blob);
			link.download = 'speedycache-settings-' + new Date().toISOString().slice(0,10) + '.json';
			document.body.appendChild(link);
			link.click();
			document.body.removeChild(link);
		},
		error: function(){
			alert('Export failed. Please try again.');
		}
	}).always(function(){
		spinner.removeClass('speedycache-spinner-active');
	});
}

function speedycache_image_optimization() {
	var stats,
		total_page = {
			value: 0,
			set: function (value) {
				this.value = value;
				this.update_num();
				disabling_paging_btn(jQuery('#speedycache-image-list'));
			},
			update_num : function(){
				jQuery('.speedycache-total-pages').text(this.value);
			}
		},
		current_page = {
			value: 0,
			set: function (value) {
				this.value = value;
				this.update_num();
				disabling_paging_btn(jQuery('#speedycache-image-list'));
			},
			update_num : function(){
				jQuery('.speedycache-current-page').text(this.value+1);
			}
		};
	
	//Gets Stats
	var get_stats = function(onload = false) {
		jQuery.ajax({
			type : 'GET',
			url : speedycache_ajax.url + '?action=speedycache_statics_ajax_request',
			cache : false,
			data : {
				'security' : speedycache_ajax.nonce
			},
			beforeSend: function(){
				jQuery('.speedycache-img-stat-update-status').show();	
			},
			success : function(res){
				stats = res;

				jQuery('.speedycache-img-stat-update-status').hide();

				//For pagination
				var $total_page = jQuery('.speedycache-total-pages'),
				optimized = res.optimized
				$total_page.text(Math.ceil(optimized/5));
				total_page.set($total_page.text());
				
				if(total_page == '1') {
					jQuery('.speedycache-image-list-next-page').addClass('disabled');
					jQuery('.speedycache-image-list-last-page').addClass('disabled');
				}
			
				if(!onload) {
					optm_count = `${optimized}/${stats.total_image_number}`;
					jQuery('.speedycache-img-optm-count').text(optm_count);
					
					reduction = res.reduction > 10000 ? (res.reduction/1000).toFixed(2) + 'MB' : res.reduction.toFixed(2) + 'KB';

					var stat_block = jQuery('.speedycache-img-stats');
					
					stat_block.find('.speedycache-img-reduced-size').text(reduction);
					stat_block.find('.speedycache-donut-percent').text(res.percent + '%');
					stat_block.find('.speedycache-img-success-per').text(res.percent + '%');
					stat_block.find('.speedycache-img-error-count').text(res.error);
					
					var sub = 100 - parseInt(res.percent);
					
					stat_block.find('.speedycache-donut-segment-2').attr('stroke-dasharray', res.percent+' '+sub);
					var donut_style = stat_block.closest('.speedycache-tab-image').find('style').eq(0);
					
					//this regex wont work in PHP as it dosent supports look behind without fixed size
					var dash_array = donut_style.text();
					
					//(?<=100%\s*{(?:\s*|\n)stroke-dasharray\s*:\s*)([\d]+\s*[\d]+[^;]) this reg ex can be used too its more precise and gets just numbers but need to update it to handle floats
					dash_array = dash_array.replace(/100%.*(?:[\d]|[\d]+\.[\d]+)[^;]/, `100%{stroke-dasharray:${res.percent}, ${sub}`);
				
					var segment = stat_block.find('.speedycache-donut-segment-2');
					segment.removeClass('speedycache-donut-segment-2');
					segment.addClass('speedycache-donut-segment-2');
					
					donut_style.text(dash_array);
				}
			
				if(res.uncompressed > 0) {
					jQuery('.speedycache_img_optm_status').css('backgroundColor', '#EED202');
					jQuery('.speedycache_img_optm_status').next().text(`${res.uncompressed} File(s) needed to be optimized`);
				}else {
					jQuery('.speedycache_img_optm_status').css('backgroundColor', '#90ee90');
					jQuery('.speedycache_img_optm_status').next().text(`All images are optimized`);
				}
			}
		});
	}

	//Updates Image Optimization Stats on load
	get_stats();
	
	jQuery('.speedycache-img-opt-settings input').on('change', function() {
		
		var settings = jQuery('.speedycache-img-opt-settings').serializeArray();
		settings = speedycache_convert_serialized(settings);
		
		jQuery.ajax({
			type: 'POST',
			url : speedycache_ajax.url + '?action=speedycache_update_image_settings',
			data : {
				'security' : speedycache_ajax.nonce,
				'settings' : settings
			},
			success: function(res) {
				//Succeed or Fail silently
			}
		});
	});
	
	var file_counter = 1,
	optm_stopped = false,
	optm_ajax;
	
	jQuery('.speedycache-img-optm-btn').on('click', function() {
		if(optm_ajax && optm_stopped) {
			optm_ajax.abort();
			optm_stopped = false;
			file_counter = 1;

			return;
		}
		
		var inner_content = `
			<div class="speedycache-img-optm-counter">${file_counter - 1}/${stats.uncompressed}</div>
			<div class="speedycache-progress">
				<div class="speedycache-progress-value"></div>
			</div>
			<div class="speedycache-optm-close">
				<button class="speedycache-button speedycache-image-optm-stop speedycache-btn-black">Stop</button>
				<button class="speedycache-button speedycache-img-optm-close">Close</button></div>
			</div>`;
		
		
		//If all images are optimized
		if(stats.uncompressed == 0) {
			inner_content = `
			<div class="speedycache-already-optm">
				<span class="dashicons dashicons-yes-alt"></span>
				<span>All images are Optimized</span>
			</div>
			<div class="speedycache-optm-close">
				<button class="speedycache-btn speedycache-btn-success speedycache-img-optm-close" style="display:block;">Close</button></div>
			</div>
			`;
		}
		
		var inc_per = parseInt(100/stats.uncompressed),
		modal_html = `<div modal-id="speedycache-modal-optimize-all" class="speedycache-modal">
			<div class="speedycache-modal-wrap" style="padding:10px;">
				<div style="text-align:center;"><h2>Optimizing Images</h2></div>
					<div class="speedycache-optm-prog-list">
					</div>
					${inner_content}
			</div>
		</div>`;
		
		var optm_modal = jQuery('[modal-id="speedycache-modal-optimize-all"]');
		
		if(optm_modal.length == 0) {
			jQuery('body').append(modal_html);
			speedycache_open_modal(jQuery(this));
			optm_modal = jQuery('[modal-id="speedycache-modal-optimize-all"]');
		}
		
		optm_modal.find('.speedycache-optm-close button').off('click').on('click', function() {
			optm_modal.remove();
			speedycache_update_list();
			get_stats();
			
			if(stats.uncompressed != 0) {
				optm_stopped = true;
			}
			
			file_counter++;
		});
		
		optm_ajax = jQuery.ajax({
			type : 'POST',
			url : speedycache_ajax.url + '?action=speedycache_optimize_image_ajax_request',
			data : {
				'id' : null,
				'security' : speedycache_ajax.nonce
			},
			success: function(res) {
				var progress = jQuery('[modal-id="speedycache-modal-optimize-all"] .speedycache-progress-value'),
				new_per = file_counter * inc_per;
				progress.css('width', `${new_per}%`);
				
				file_counter++
				
				var modal = progress.closest('.speedycache-modal-wrap');
				
				if(!res.id && res.message != 'finish') {
					var error_html = `<div class="speedycache-img-optm-error">
						<p>Something Went Wrong<br/>
							${res.message}
						</p>
					</div>`;
					
					progress.parent().before(error_html);
					progress.css({'width': '100%', 'backgroundColor' : 'var(--speedycache-red)'});
					
					setTimeout( () => {
						optm_modal.find('.speedycache-img-optm-close').show();
						optm_modal.find('.speedycache-image-optm-stop').hide();
					},700);
					
					return;
				} 
	
				if(res.message != 'finish' && file_counter <= stats.uncompressed + 1) {
					modal.find('.speedycache-img-optm-counter').text((file_counter) - 1 +'/'+stats.uncompressed);
					
					jQuery('.speedycache-img-optm-btn').trigger('click');
					return;
				}
				
				progress.css('width', '100%');
				
				//To show when Optimization completes
				var success_html = `
				<div class="speedycache-already-optm" style="display:none;">
					<span class="dashicons dashicons-yes-alt"></span>
					<span>Images optimized Successfully</span>
				</div>
				`;
				
				progress.parent().before(success_html);
				modal.find('.speedycache-img-optm-counter').hide('slow');
				modal.find('.speedycache-already-optm').show('slow');
				
				setTimeout( () => {
					optm_modal.find('.speedycache-img-optm-close').show();
					optm_modal.find('.speedycache-image-optm-stop').hide();
				},700);
			}
		});
	});
	
	//revert Image
	var revert_image = function() {
		var jEle = jQuery(this),
		post_id = jEle.find('input').val();
	
		if(!post_id) {
			return;
		}
		
		//speedycache_add_loader();
		
		jQuery.ajax({
			type : 'GET',
			url : speedycache_ajax.url + '?action=speedycache_revert_image_ajax_request&id='+post_id,
			data : {
				'security' : speedycache_ajax.nonce,
			},
			beforeSend : function(){
				jEle.closest('tr').css('backgroundColor', 'rgba(255,0,0,0.2)');
			},
			success : function(res) {
				speedycache_update_list(jEle);
				get_stats();
				//speedycache_hide_loader();
			},
			error: function(err) {
				//speedycache_hide_loader();
				jEle.closest('tr').css('backgroundColor', 'rgb(255,255,255)');
			}
		});
	}
	
	//Revert the image conversion listener
	jQuery('.speedycache-revert').on('click', revert_image);
	
	jQuery('.speedycache-img-delete-all-conv').on('click', function(e) {
		e.preventDefault();
		
		var confirm_modal = jQuery('[modal-id="speedycache-modal-all-img-revert"]');
		
		if(confirm_modal.length == 0) {
			return;
		}
		
		speedycache_open_modal(confirm_modal);
		
		confirm_modal.find('.speedycache-db-confirm-yes').off().on('click', function() {
			//speedycache_add_loader();
			confirm_modal.css('visibility','hidden');
			
			jQuery.ajax({
				type : 'GET',
				url : speedycache_ajax.url + '?action=speedycache_img_revert_all',
				data : {
					'security' : speedycache_ajax.nonce
				},
				success : function(res) {
					
					if(res.success) {
						//speedycache_hide_loader();
						speedycache_update_list();
						get_stats();
						return;
					}
				
					//speedycache_hide_loader();
					alert(res.message);
				}
			});
		});
		
		confirm_modal.find('.speedycache-db-confirm-no').off().on('click', function() {
			confirm_modal.css('visibility','hidden');
		});
	});	
	
	var speedycache_update_list = function(jEle = null) {
		var img_list = jQuery('#speedycache-image-list'),
			search = img_list.find('#speedycache-image-search-input'),
			per_page = img_list.find('#speedycache-image-per-page'),
			per_page_val = per_page.val() ? per_page.val() : 5,
			filter = img_list.find('#speedycache-image-list-filter'),
			page = 0;
			
		if(jEle) {	
			if(jEle.hasClass('disabled')) {
				return;
			}	
			
			if(jEle.data('page-action')) {
				switch(jEle.data('page-action')) {
					case 'last-page':
						current_page.set(total_page.value - 1);
						break;
						
					case 'next-page':
						current_page.set(current_page.value + 1);
						break;
					
					case 'first-page':
						current_page.set(0);
						break;
					
					case 'prev-page':
						current_page.set(current_page.value > 0 ? current_page.value - 1 : 0);
						break;
				}
			}
		}
		
		var optimized = stats.total_image_number - stats.uncompressed;
		
		if(optimized <= per_page_val) {
			current_page.set(0);
		}
		
		jQuery.ajax({
			type : 'GET',
			url : speedycache_ajax.url + '?action=speedycache_update_image_list_ajax_request',
			data : {
				'search' : search.val(),
				'per_page' : per_page_val,
				'filter' : filter.val(),
				'page' : current_page.value,
				'security' : speedycache_ajax.nonce
			},
			success: function(res) {
				if(!res.content) {
					return;
				}
				
				total_page.set(Math.ceil(res.result_count/per_page_val));
				
				if(total_page.value - 1 == current_page.value) {
					img_list.find('.speedycache-image-list-next-page').addClass('disabled');
					img_list.find('.speedycache-image-list-last-page').addClass('disabled');
				}
				
				jQuery('#speedycache-image-list tbody').empty();
				jQuery('#speedycache-image-list tbody').append(res.content);
				jQuery('.speedycache-revert').on('click', revert_image);
				jQuery('.speedycache-open-image-details').on('click', open_img_details);
			}
		});
	}
	
	var disabling_paging_btn = function(img_list) {
		if(current_page.value == 0 && total_page.value - 1 == 0) {
			img_list.find('.speedycache-image-list-first-page').addClass('disabled');
			img_list.find('.speedycache-image-list-prev-page').addClass('disabled');
			img_list.find('.speedycache-image-list-last-page').addClass('disabled');
			img_list.find('.speedycache-image-list-next-page').addClass('disabled');
		}else if(current_page.value == 0) {
			img_list.find('.speedycache-image-list-first-page').addClass('disabled');
			img_list.find('.speedycache-image-list-prev-page').addClass('disabled');
			img_list.find('.speedycache-image-list-last-page').removeClass('disabled');
			img_list.find('.speedycache-image-list-next-page').removeClass('disabled');
		} else if(current_page.value == total_page.value - 1) {
			img_list.find('.speedycache-image-list-first-page').removeClass('disabled');
			img_list.find('.speedycache-image-list-prev-page').removeClass('disabled');
			img_list.find('.speedycache-image-list-last-page').addClass('disabled');
			img_list.find('.speedycache-image-list-next-page').addClass('disabled');
		} else {
			img_list.find('.speedycache-image-list-first-page').removeClass('disabled');
			img_list.find('.speedycache-image-list-prev-page').removeClass('disabled');
			img_list.find('.speedycache-image-list-last-page').removeClass('disabled');
			img_list.find('.speedycache-image-list-next-page').removeClass('disabled');
		}
	}
	
	//Toggles the image variants
	var open_img_details = function() {
		var post_id = jQuery(this).closest('tr').attr('post-id');
		
		if(!post_id) {
			return;
		}
		
		var details = jQuery('tr[post-id="'+post_id+'"][post-type="detail"]');
		
		if(details.is(':hidden')) {
			details.show();
			jQuery(this).find("span").attr('class', 'dashicons dashicons-arrow-up-alt2')
		} else {
			details.hide();
			jQuery(this).find("span").attr('class', 'dashicons dashicons-arrow-down-alt2');
		}
	}
	
	//Downloading cwebp
	jQuery('button.speedycache-webp-download').on('click', function(e) {
		e.preventDefault();
		
		type = jQuery(this).data('type') ? jQuery(this).data('type') : 'cwebp';
		
		jQuery.ajax({
			url : speedycache_ajax.url + '?action=speedycache_download_cwebp',
			type : 'GET',
			data : {
				security : speedycache_ajax.nonce,
				type : type
			},
			beforeSend : function() {
				//speedycache_add_loader();
			},
			success : function(res) {
				//speedycache_hide_loader();
				
				if(res.success) {
					location.reload();
					return;
				}
				
				if(!res.error_message) {
					alert('Something went wrong try again later!');
				}
				
				alert(res.error_message);
			}
		})
	});
	
	//Listener For Scheduled Count
	jQuery('span.speedycache-scheduled-count').on('click', function() {
		speedycache_open_modal(jQuery(this));
	});
	
	//Listeners Starts here
	
	//Search button listener
	jQuery('#speedycache-image-search-button').on('click', function() {
		speedycache_update_list(jQuery(this));
	});
	
	//All or Error image filter
	jQuery('#speedycache-image-list-filter').on('change', function() {
		speedycache_update_list(jQuery(this));
	});
	
	//Per page listener
	jQuery('#speedycache-image-per-page').on('change', function() {
		speedycache_update_list(jQuery(this));
	});
	
	//Paging Number Listeners
	jQuery('.speedycache-image-list-first-page, .speedycache-image-list-prev-page, .speedycache-image-list-next-page, .speedycache-image-list-last-page').on('click', function() {
		speedycache_update_list(jQuery(this));
	});
	
	//Toggles the image variants Listener
	jQuery('.speedycache-open-image-details').on('click', open_img_details);
}

/*
	Converts the format of jQuery serializeArray
	i.e, [ 0:{name:someName, value:expectedvalue} ] to
	{ someName:expectedvalue }
*/
function speedycache_convert_serialized(arr) {
	var converted_obj = {};
	
	for(var i of arr) {
		converted_obj[i.name] = i.value;
	}
	
	return converted_obj;
}

function speedycache_critical_css(){
	jQuery.ajax({
		type: 'GET',
		url : speedycache_ajax.url + '?action=speedycache_critical_css&security='+speedycache_ajax.nonce,
		success: function(res){
			if(!res.success){
				alert(res.data.message ? res.data.message : 'Something went wrong ! Unable to intitiate Critical CSS!');
				return;
			}
			
			alert(res.data.message);
		}
	})
}

function speedycache_verify_license(){
	event.preventDefault();
	let jEle = jQuery(event.target),
	form = jEle.closest('form'),
	form_data = form.serializeArray(),
	spinner = jEle.find('.speedycache-spinner');
	
	spinner.addClass('speedycache-spinner-active');
	
	jQuery.ajax({
		type: 'GET',
		url : speedycache_ajax.url,
		data : form_data,
		success: function(res){
			if(res.success){
				alert('License verified, please reload the page');
				return;
			}
			
			if(res.data){
				alert(res.data);
				return;
			}
			
			alert('Something went wrong when trying to verify license');
		}
	}).always(function(){
		spinner.removeClass('speedycache-spinner-active');
	})
}
home/coopserp/public_html/wp-content/plugins/speedycache-pro/assets/js/admin.js000064400000001512151526435610024035 0ustar00jQuery(document).ready(function($) {
	$('.speedycache-test-notice .speedycache-custom-dismiss').click(function(e) {
		e.preventDefault();
		$('.speedycache-test-notice').slideUp();
			$.ajax({
				url: speedycache_pro_ajax.url,
				type: 'POST',
				data: {
					action: 'speedycache_dismiss_test_notice',
					security: speedycache_pro_ajax.nonce
				}
			});
		});	

	$('.speedycache-copy-test-settings').click(function(e){
		e.preventDefault();
		$.ajax({
			method : 'GET',
			url : speedycache_pro_ajax.url + '?action=speedycache_copy_test_settings&security='+speedycache_pro_ajax.nonce,
			success: function(res){
				if(res.success){
					alert('The settings has been successfully saved!');
					location.reload(true);
					return;
				}
				if(res.data){
					alert(res.data);
				}
			}
		});
	});
})
home/coopserp/public_html/wp-content/plugins/softaculous-pro/assets/js/admin.js000064400000006765151526436270024151 0ustar00(function($, nonce, admin_url, ajax_url){
$(document).ready(function(){

	$(document).on("click", ".my-soft-pro-dismiss-notice .notice-dismiss", function(){
		var data = {
			action: "softaculous_pro_wp_ajax",
			softaculous_pro_security: nonce
		};
		$.post(ajax_url, data, function(response){});
	});

	//View connection key script
	var soft_pro_conn_key_dialog = $("#soft_pro_connection_key_dialog");
	$("#soft_pro_connection_key").click(function(e) {
		e.preventDefault();
		soft_pro_conn_key_dialog.dialog({
			draggable: false,
			resizable: false,
			modal: true,
			width: "1070px",
			height: "auto",
			title: "Softaculous Connection Key",
			close: function() {
				$(this).dialog("destroy");
			}
		});
	});

	$("#soft_pro_promo .soft_pro_promo-close").click(function(){
		var data = {
			softaculous_pro_security: nonce
		};

		// Hide it
		$("#soft_pro_promo").hide();
		
		// Save this preference
		$.post(admin_url + '?softaculous_pro_promo=0', data, function(response) {
			//alert(response);
		});
	});

	function dotweet(ele){
		window.open($("#"+ele.id).attr("action")+"?"+$("#"+ele.id).serialize(), "_blank", "scrollbars=no, menubar=no, height=400, width=500, resizable=yes, toolbar=no, status=no");
		return false;
	}
		
	$('.spro-plugin-install-btn').click(function(){

		$(this).replaceWith('<i class="fa fa-spin fa-2x fa-circle-notch sp-2 smr-3"></i>');

		var data = {
			action: "softaculous_pro_wp_ajax",
			softaculous_pro_install_plugin: 1,
			plugin: $(this).attr("name"),
			softaculous_pro_security: soft_pro_obj.nonce
		};

		$.post(soft_pro_obj.ajax_url, data, function(response){
			if(!response.data || !response.data.form){
				return;
			}

			// Handling FTP Form
			$('body').append(response.data.form);

			var ftp_modal = $('#request-filesystem-credentials-dialog');
			ftp_modal.show();

			// Handling the close btn of the FTP form.
			ftp_modal.find('.cancel-button').on('click', function(event){
				event.preventDefault();
				ftp_modal.hide();
				window.location.reload();
			});

			ftp_modal.on('submit', 'form', function(event){
				event.preventDefault();

				data['hostname'] = ftp_modal.find('#hostname').val();
				data['username'] = ftp_modal.find('#username').val();
				data['password'] = ftp_modal.find('#password').val();
				data['connection_type'] = ftp_modal.find('input[name="connection_type"]:checked').val();
				data['public_key'] = ftp_modal.find('#public_key').val();
				data['private_key'] = ftp_modal.find('#private_key').val();
				data['_fs_nonce'] = ftp_modal.find('#_fs_nonce').val();

				ftp_modal.hide()
				spro_install_plugin_with_ftp(data);
			});
		})
		.done(function(res){
			if(!res.data || !res.data.form){
				window.location.reload();
			}
		});
	});
});
})(jQuery, soft_pro_obj.nonce, soft_pro_obj.admin_url, soft_pro_obj.ajax_url);


// Plugin install request with FTP credentials
function spro_install_plugin_with_ftp(data){
	jQuery.post(soft_pro_obj.ajax_url, data, function(response){})
	.done(function(res){
		window.location.reload();
	});
}

//Cookie setter
function spro_setcookie(name, value, duration){
	value = escape(value);
	if(duration){
		var date = new Date();
		date.setTime(date.getTime() + (duration * 86400000));
		value += "; expires=" + date.toGMTString();
	}
	document.cookie = name + "=" + value;
};

//Gets the cookie value
function spro_getcookie(name){
	value = document.cookie.match('(?:^|;)\\s*'+name+'=([^;]*)');
	return value ? unescape(value[1]) : false;
};

//Removes the cookies
function spro_removecookie(name){
	spro_setcookie(name, '', -1);
};