web/wp-content/plugins/duplicator/inc/javascript.php
changeset 195 c7c0fbc09788
child 204 09a1c134465b
equal deleted inserted replaced
194:32102edaa81b 195:c7c0fbc09788
       
     1 <script type="text/javascript">
       
     2 
       
     3 jQuery.noConflict()(function($) {
       
     4 	jQuery(document).ready(function() {
       
     5 	
       
     6 	//Unique namespace
       
     7 	Duplicator = new Object();
       
     8 	Duplicator.DEBUG_AJAX_RESPONSE = false;
       
     9 	Duplicator.AJAX_TIMER = null;
       
    10 	
       
    11 	Duplicator.startAjaxTimer = function() {
       
    12 		Duplicator.AJAX_TIMER = new Date();
       
    13 	}
       
    14 	
       
    15 	Duplicator.endAjaxTimer = function() {
       
    16 		var endTime = new Date();
       
    17 		Duplicator.AJAX_TIMER =  (endTime.getTime()  - Duplicator.AJAX_TIMER) /1000;
       
    18 	}
       
    19 	
       
    20 	/** **********************************************
       
    21 	*  METHOD: Duplicator.setStatus  
       
    22 	*  Sets the status of the Duplicator status bar */
       
    23 	Duplicator.setStatus = function(msg, img, postmsg) {
       
    24 		//Clean Status Bar
       
    25 		$("#img-status-error").hide();
       
    26 		$("#img-status-progress").hide();
       
    27 		
       
    28 		$('#span-status').html(msg);
       
    29 		switch (img) {
       
    30 			case 'error' 	: $("#img-status-error").show('slow'); break;
       
    31 			case 'progress' : $("#img-status-progress").show('slow'); break;
       
    32 		}
       
    33 		$('#span-status-post').html(postmsg);
       
    34 	}
       
    35 	
       
    36 
       
    37 	/** **********************************************
       
    38 	*  METHOD: Duplicator.toggleToolbarState  
       
    39 	*  Disables or enables the toolbar
       
    40 	*  @param state		Disabled/Enabled */ 
       
    41 	Duplicator.toggleToolbarState = function(state) {
       
    42 		if (state == "DISABLED") {
       
    43 			$('#toolbar-table input, div#duplicator-installer').attr("disabled", "true");
       
    44 			$('#toolbar-table input, div#duplicator-installer').css("background-color", "#efefef");
       
    45 		} else {
       
    46 			$('#toolbar-table input, div#duplicator-installer').removeAttr("disabled");
       
    47 			$('#toolbar-table input, div#duplicator-installer').css("background-color", "#f9f9f9");
       
    48 		}	
       
    49 	}
       
    50 	
       
    51 
       
    52 	/** **********************************************
       
    53 	*  METHOD: Duplicator.reload  
       
    54 	*  Performs reloading the page and diagnotic handleing */
       
    55 	Duplicator.reload = function(data) {
       
    56 		if (Duplicator.DEBUG_AJAX_RESPONSE) {
       
    57 			Duplicator.showSystemError('debug on', data);
       
    58 		} else {
       
    59 			Duplicator.toggleToolbarState("ENABLED");
       
    60 			window.location.reload();
       
    61 		}
       
    62 	}
       
    63 	
       
    64 
       
    65 	/** **********************************************
       
    66 	*  METHOD: Duplicator.createPackage  
       
    67 	*  Performs Ajax post to create a new package
       
    68 	*  Timeout (10000000 = 166 minutes) */
       
    69 	Duplicator.createPackage = function(packname) {
       
    70 		Duplicator.toggleToolbarState("DISABLED");
       
    71 
       
    72 		$.ajax({
       
    73 			type: "POST",
       
    74 			url: ajaxurl,
       
    75 			timeout: 10000000,
       
    76 			data: "package_name=" + packname +"&action=duplicator_create",
       
    77 			beforeSend: function() {Duplicator.startAjaxTimer(); },
       
    78 			complete: function() {Duplicator.endAjaxTimer(); },
       
    79 			success:    function(data) { 
       
    80 				Duplicator.reload(data);
       
    81 			},
       
    82 			error:      function(data) { 
       
    83 				Duplicator.showSystemError('Duplicator.createPackage', data);
       
    84 				Duplicator.toggleToolbarState("ENABLED");
       
    85 			}
       
    86 		});
       
    87 	}
       
    88 
       
    89 
       
    90 	/** **********************************************
       
    91 	 *  METHOD: Save Settings
       
    92 	 *  Saves the Settings */
       
    93 	Duplicator.saveSettings = function() {
       
    94 		var q;
       
    95 		var email_me   		= $('#email-me').is(':checked') ? 1 : 0;
       
    96 		var dbiconv    		= $('#dbiconv').is(':checked')  ? 1 : 0;
       
    97 		var log_level  		= $("select#log_level").val() ? $("select#log_level").val() : 0;
       
    98 		var email_others	= $("input#email_others").val();
       
    99 		var dir_bypass 		= $("textarea#dir_bypass").val();
       
   100 		var rm_snapshot   	= $('#rm_snapshot').is(':checked') ? 1 : 0;
       
   101 
       
   102 		//append semicolon if user forgot
       
   103 		if (dir_bypass.length > 1) {
       
   104 			var has_semicolon	= dir_bypass.charAt(dir_bypass.length - 1) == ";";
       
   105 			var dir_bypass		= (has_semicolon) ? dir_bypass : dir_bypass + ";";
       
   106 			$("textarea#dir_bypass").val(dir_bypass);
       
   107 		}
       
   108 
       
   109 		$.ajax({
       
   110 			type: "POST",
       
   111 			url: ajaxurl,
       
   112 			timeout: 10000000,
       
   113 			data: 
       
   114 			{
       
   115 				'action'  		: 'duplicator_settings',
       
   116 				'dbhost' 		: $("input#dbhost").val(),
       
   117 				'dbname'  		: $("input#dbname").val(),
       
   118 				'dbuser'  		: $("input#dbuser").val(),
       
   119 				'nurl'  		: $("input#nurl").val(),
       
   120 				'dbiconv'  		: dbiconv,
       
   121 				'email-me'  	: email_me,
       
   122 				'email_others'  : email_others,
       
   123 				'max_time'  	: $("input#max_time").val(),
       
   124 				'max_memory'  	: $("input#max_memory").val(),
       
   125 				'skip_ext'  	: $("input#skip_ext").val(),
       
   126 				'dir_bypass'  	: $("textarea#dir_bypass").val(),
       
   127 				'log_level'  	: log_level,
       
   128 				'rm_snapshot'  	: rm_snapshot
       
   129 			},
       
   130 			beforeSend: function() {Duplicator.startAjaxTimer(); },
       
   131 			complete: function() {Duplicator.endAjaxTimer(); },
       
   132 			success: function(data) { 
       
   133 				$('#opts-save-btn').val("<?php _e('Saving', 'wpduplicator') ?>...");
       
   134 				window.location.reload();
       
   135 			},
       
   136 			error: function(data) { 
       
   137 				Duplicator.showSystemError('Duplicator.saveSettings', data);
       
   138 			}
       
   139 		});
       
   140 	 }
       
   141 
       
   142 
       
   143 	/** **********************************************
       
   144 	 *  METHOD: Delete Package
       
   145 	 *  Removes all selected package sets */
       
   146 	Duplicator.deletePackage = function (event) {
       
   147 		var arr = new Array;
       
   148 		var count = 0;
       
   149 		$("input[name=delete_confirm]").each(function() {
       
   150 			 if (this.checked) { arr[count++] = this.id; }
       
   151 		});
       
   152 		var list = arr.join(',');
       
   153 		if (list.length == 0) {
       
   154 			alert("<?php _e('Please select at least one package to delete.', 'wpduplicator') ?>");
       
   155 			return;
       
   156 		}
       
   157 		
       
   158 		var answer = confirm("<?php _e('Are you sure, you want to delete the selected package(s)?', 'wpduplicator') ?>");
       
   159 		if (answer){
       
   160 			$.ajax({
       
   161 				type: "POST",
       
   162 				url: ajaxurl,
       
   163 				data: "duplicator_delid="+list+"&action=duplicator_delete",
       
   164 				beforeSend: function() {Duplicator.startAjaxTimer(); },
       
   165 				complete: function() {Duplicator.endAjaxTimer(); },
       
   166 				success: function(data) { 
       
   167 					Duplicator.reload(data); 
       
   168 				},
       
   169 				error: function(data) { 
       
   170 					Duplicator.showSystemError('Duplicator.deletePackage', data);
       
   171 				}
       
   172 			});
       
   173 		} else {
       
   174 			Duplicator.setStatus("<?php _e('Ready to create new package.', 'wpduplicator') ?>");
       
   175 		}
       
   176 		if (event)
       
   177 			event.preventDefault(); 
       
   178 	};
       
   179 
       
   180 
       
   181 	/** **********************************************
       
   182 	 *  ATTACHED EVENT: Submit Main Form
       
   183 	 *  Process Package and Installer */
       
   184 	$("#form-duplicator").submit(function (event) {
       
   185 		event.preventDefault();   
       
   186 		
       
   187 		//Validate length test
       
   188 		if ($("input[name=package_name]").val().length <= 0) 	{
       
   189 			Duplicator.setStatus("<?php _e('Please enter a backup name.', 'wpduplicator') ?>", "error");
       
   190 			return;
       
   191 		}
       
   192 		
       
   193 		//Vatlidate alphanumeric test
       
   194 		var newstring = $("input[name=package_name]").val().replace(/ /g, "");
       
   195 		$("input[name=package_name]").val(newstring)
       
   196 		if ( ! /^[0-9A-Za-z|_]+$/.test($("input[name=package_name]").val())) {
       
   197 			Duplicator.setStatus("<?php _e('Alpanumeric characters only on package name', 'wpduplicator') ?>", "error");
       
   198 			return;
       
   199 		}
       
   200 		
       
   201 		var packname = $("input[name=package_name]").val();
       
   202 		
       
   203 		$.ajax({
       
   204 			type: "POST",
       
   205 			url: ajaxurl,
       
   206 			dataType: "json",
       
   207 			timeout: 10000000,
       
   208 			data: "duplicator_new="+ packname +"&action=duplicator_system_check",
       
   209 			beforeSend: function() {
       
   210 				Duplicator.setStatus("<?php _e("Evaluating WordPress Setup. Please Wait", 'wpduplicator') ?>...", 'progress');
       
   211 			},
       
   212 			success: function(data) {
       
   213 				Duplicator.setStatus("<?php _e('Ready to create new package.', 'wpduplicator') ?>");
       
   214 				if (data.Success) {
       
   215 					Duplicator.showCreateConfirmation(packname);
       
   216 				} else {
       
   217 					Duplicator.showSystemCheck(data);
       
   218 				}
       
   219 			},
       
   220 			error: function(data) { 
       
   221 				Duplicator.showSystemError('form-duplicator submit', data);
       
   222 			}
       
   223 		});
       
   224 	});
       
   225 
       
   226 
       
   227 	/*  ============================================================================
       
   228 	MAIN GRID
       
   229 	Actions that revolve around the main grid */
       
   230 	$("input#select-all").click(function (event) {
       
   231 		var state = $('input#select-all').is(':checked') ? 1 : 0;
       
   232 		$("input[name=delete_confirm]").each(function() {
       
   233 			 this.checked = (state) ? true : false;
       
   234 			 Duplicator.rowColor(this);
       
   235 		});
       
   236 	});
       
   237 
       
   238 	Duplicator.rowColor = function(chk) {
       
   239 		if (chk.checked) {
       
   240 			$(chk).parent().parent().css("text-decoration", "line-through");
       
   241 		} else {
       
   242 			$(chk).parent().parent().css("text-decoration", "none");
       
   243 		}
       
   244 	}
       
   245 	
       
   246 	Duplicator.toggleDetail = function(id) {
       
   247 		$('#' + id).toggle();
       
   248 		return false;
       
   249 	}
       
   250 	
       
   251 		
       
   252 	Duplicator.downloadFile = function(name, button) {
       
   253 		$(button).addClass('dup-button-selected');
       
   254 		window.open(name, '_self'); 
       
   255 		return false;
       
   256 	}
       
   257 	
       
   258 
       
   259 
       
   260 	/*  ============================================================================
       
   261 	DIALOG: WINDOWS
       
   262 	Browser Specific. IE9 does not support modal correctly this is a workaround  */
       
   263 	Duplicator._dlgCreate = function(evt, ui) {
       
   264 		if (! $.browser.msie) {
       
   265 			$('#' + this.id).dialog('option', 'modal',  	true);
       
   266 			$('#' + this.id).dialog('option', 'draggable',  true);
       
   267 		} else {
       
   268 			$('#' + this.id).dialog('option', 'draggable',  false);
       
   269 			$('#' + this.id).dialog('option', 'open',  function() {$("div#wpwrap").addClass('ie-simulated-overlay');} );
       
   270 		}
       
   271 	}
       
   272 	Duplicator._dlgClose = function(evt, ui) {
       
   273 		if ($.browser.msie) {$("div#wpwrap").removeClass('ie-simulated-overlay');}
       
   274 	}
       
   275 	$("#dialog-options").dialog( {autoOpen:false, height:610, width:750, create:Duplicator._dlgCreate, close:Duplicator._dlgClose });
       
   276 	$("#dup-dlg-system-check").dialog({autoOpen:false, height:600, width:700, create:Duplicator._dlgCreate, close:Duplicator._dlgClose, modal: true, buttons: {<?php _e("Cancel", 'wpduplicator') ?>: function() { $(this).dialog("close");}}});
       
   277 	$("#dup-dlg-system-error").dialog({autoOpen:false, height:550, width:650, create:Duplicator._dlgCreate, close:Duplicator._dlgClose });	
       
   278 	$("#dup-dlg-quick-path").dialog({autoOpen:false, height:355, width:800, create:Duplicator._dlgCreate, close:Duplicator._dlgClose });	
       
   279 	$("#dup-dlg-package-confirm").dialog(
       
   280 		{autoOpen:false, height:285, width:625, create:Duplicator._dlgCreate, close:Duplicator._dlgClose,
       
   281 		buttons: {
       
   282 				"<?php _e('Create Package Set', 'wpduplicator') ?>" : function() {
       
   283 					$(this).dialog("close");
       
   284 					Duplicator.processCreateConfirmation(true);
       
   285 				},
       
   286 				Cancel: function() {
       
   287 					$(this).dialog("close");
       
   288 					Duplicator.processCreateConfirmation(false);
       
   289 				}
       
   290 			}
       
   291 		}
       
   292 	);	
       
   293 	
       
   294 
       
   295 	/*  ============================================================================
       
   296 	DIALOG:	OPTIONS DIALOG 
       
   297 	Actions that revolve around the options dialog */
       
   298 	$("#dup-tabs-opts").tabs();
       
   299 	Duplicator.optionsAppendByPassList = function(path) {
       
   300 		Duplicator.optionsOpen();
       
   301 		 $('#dir_bypass').append(path + ";");
       
   302 		 $('#dup-tabs-opts').tabs('option', 'selected', 0);
       
   303 		 $('#dir_bypass').animate({ borderColor: "blue", borderWidth: 2 }, 3000);
       
   304 		 $('#dir_bypass').animate({ borderColor: "#dfdfdf", borderWidth: 1  }, 100);
       
   305 	}
       
   306 	Duplicator.optionsOpen  = function() {$("div#dialog-options").dialog("open");}
       
   307 	Duplicator.optionsClose = function() {$('div#dialog-options').dialog('close');}
       
   308 
       
   309 
       
   310 	/*  ============================================================================
       
   311 	DIALOG: SYSTEM-CHECKS
       
   312 	Actions that revolve around the systems check dialog */
       
   313 	Duplicator.showSystemCheck = function(data) {
       
   314 		//Set Pass/Fail Flags
       
   315 		for (key in data) {
       
   316 			var html = (data[key] == 'Fail') ? "<div class='dup-sys-fail'>Fail</div>" : "<div class='dup-sys-pass'>Pass</div>";
       
   317 			$("#" + key).html(html)
       
   318 		}
       
   319 
       
   320 		$('#system-check-msg').animate({ scrollTop: $('#system-check-msg').attr("scrollHeight") }, 2000)
       
   321 		$("#dup-dlg-system-check").dialog("open");
       
   322 		Duplicator.setStatus("<?php _e('Ready to create new package.', 'wpduplicator'); ?>");
       
   323 	}	
       
   324 
       
   325 	//Performs the ajax request for a system check
       
   326 	Duplicator.getSystemCheck = function() {
       
   327 		Duplicator.setStatus("<?php _e('Checking System Status.  Please Wait!', 'wpduplicator'); ?>", 'progress');
       
   328 		$.ajax({
       
   329 			type: "POST",
       
   330 			url: ajaxurl,
       
   331 			dataType: "json",
       
   332 			timeout: 10000000,
       
   333 			data: "action=duplicator_system_check",
       
   334 			beforeSend: function() {Duplicator.startAjaxTimer(); },
       
   335 			complete: function() {Duplicator.endAjaxTimer(); },			
       
   336 			success: function(data) {Duplicator.showSystemCheck(data);},
       
   337 			error: function(data)   {
       
   338 				Duplicator.showSystemError('Duplicator.getSystemCheck', data);
       
   339 			}
       
   340 		});
       
   341 	}
       
   342 	
       
   343 	//Show the size and file count of the directory to be zipped
       
   344 	Duplicator.getSystemDirectory = function() {
       
   345 		$.ajax({
       
   346 			type: "POST",
       
   347 			url: ajaxurl,
       
   348 			dataType: "json",
       
   349 			timeout: 10000000,
       
   350 			data: "action=duplicator_system_directory",
       
   351 			beforeSend: function() { 
       
   352 				Duplicator.startAjaxTimer(); 
       
   353 				var html = "<?php _e('Scanning Please Wait', 'wpduplicator'); ?>... " + "<img src='<?php echo DUPLICATOR_PLUGIN_URL  ?>img/progress.gif' style='height:7px; width:46px;'  />" ;
       
   354 				$('#dup-sys-scannow-data, #dup-dlg-package-confirm-scannow-data').html(html);	
       
   355 			},
       
   356 			complete: function() {Duplicator.endAjaxTimer(); },
       
   357 			success: function(data) {
       
   358 				var size    =  data.size 	|| "<?php _e('unreadable', 'wpduplicator'); ?>";
       
   359 				var count   =  data.count 	|| "<?php _e('unreadable', 'wpduplicator'); ?>";
       
   360 				var folders =  data.folders || "<?php _e('unreadable', 'wpduplicator'); ?>";
       
   361 				var flag    =  (data.flag || size.indexOf("-") != -1) ? "<?php _e('*Scan Error', 'wpduplicator'); ?>" : "";
       
   362 				var html    =  size + " " + count +  " <?php _e('Files', 'wpduplicator'); ?>, " + folders +  " <?php _e('Folders', 'wpduplicator'); ?> " + flag; 
       
   363 				$('#dup-sys-scannow-data, #dup-dlg-package-confirm-scannow-data').html("<i>" + html + "</i>");
       
   364 				
       
   365 			},
       
   366 			error: function(data)   {
       
   367 				$('#dup-sys-scannow-data, #dup-dlg-package-confirm-scannow-data').html("<?php _e('error scanning directory', 'wpduplicator'); ?>");
       
   368 				Duplicator.showSystemError('Duplicator.getSystemDirectory', data);
       
   369 			}
       
   370 		});
       
   371 	}
       
   372 	
       
   373 	//Toggle the system requirment details
       
   374 	Duplicator.showSystemDetails = function() {
       
   375 		if ($(this).parents('li').children('div.dup-sys-check-data-details').is(":hidden")) {
       
   376 			$(this).children('span').addClass('ui-icon-triangle-1-s').removeClass('ui-icon-triangle-1-e');;
       
   377 			$(this).parents('li').children('div.dup-sys-check-data-details').show(250);
       
   378 		} else {
       
   379 			$(this).children('span').addClass('ui-icon-triangle-1-e').removeClass('ui-icon-triangle-1-s');
       
   380 			$(this).parents('li').children('div.dup-sys-check-data-details').hide(250);
       
   381 		}
       
   382 	}
       
   383 
       
   384 	//Make the system requirments toggle
       
   385 	$('#dup-sys-check-data-reqs a').each(function() {
       
   386 		$(this).attr('href', 'javascript:void(0)');
       
   387 		$(this).click(Duplicator.showSystemDetails);
       
   388 		$(this).prepend("<span class='ui-icon ui-icon-triangle-1-e dup-toggle' />");
       
   389 	});
       
   390 	
       
   391 	/*  ============================================================================
       
   392 	DIALOG: QUICK PATH
       
   393 	Shows the Quick Path Dialog 'Show Download Links' */
       
   394 	Duplicator.showQuickPath = function(db, install, pack) {
       
   395 		$("#dup-dlg-quick-path").dialog("open");
       
   396 		var msg = <?php printf('"%s:\n" + db + "\n\n%s:\n" + install + "\n\n%s:\n" + pack;', 
       
   397 		__("DATABASE",  'wpduplicator'), 
       
   398 		__("PACKAGE", 'wpduplicator'), 
       
   399 		__("INSTALLER",   'wpduplicator')); 
       
   400 		?>
       
   401 		$("#dup-dlg-quick-path-data").val(msg);
       
   402 
       
   403 		return false;
       
   404 	}
       
   405 	
       
   406 	Duplicator.selectQuickPath = function() {$('#dup-dlg-quick-path-data').select();}
       
   407 	$(".dup-dlg-quick-path-download-link").button({ icons: {primary: "ui-icon-locked"} });
       
   408 	$(".dup-dlg-quick-path-database-link").button({ icons: {primary: "ui-icon-script"} });
       
   409 	$(".dup-installer-btn").button({ icons: {primary: "ui-icon-disk"} });
       
   410 	
       
   411 	
       
   412 	/*  ============================================================================
       
   413 	DIALOG: SYSTEM ERROR
       
   414 	Show the Sytem Error Dialog */
       
   415 	Duplicator.showSystemError = function(action, xhrData) {
       
   416 		Duplicator.endAjaxTimer();
       
   417 		var time = Duplicator.AJAX_TIMER || 'not set';
       
   418 		var msg  = '<?php _e('AJAX Response', 'wpduplicator') ?>' + ' ' + action + '<br/>';
       
   419 		msg += "duration: " + time + " secs<br/>code: " + xhrData.status + "<br/>status: " + xhrData.statusText + "<br/>response: " +  xhrData.responseText;
       
   420 		$("#dup-system-err-msg2").html(msg);
       
   421 		$("#dup-dlg-system-error").dialog("open");
       
   422 		Duplicator.setStatus("<?php _e('Ready to create new package.', 'wpduplicator'); ?>");
       
   423 	}
       
   424 	
       
   425 	
       
   426 	/*  ============================================================================
       
   427 	DIALOG: CREATE PACKAGE CONFIRMATION
       
   428 	Show the Create package dialog */
       
   429 	Duplicator.showCreateConfirmation = function(packname) {
       
   430 		$("#dup-dlg-package-confirm-msg").html(packname);
       
   431 		$("#dup-dlg-package-confirm").dialog('open');
       
   432 	}
       
   433 	
       
   434 	Duplicator.processCreateConfirmation = function(result) {
       
   435 		if (result) {
       
   436 			var msg = "<?php _e('Creating package may take several minutes. Please Wait... ', 'wpduplicator'); ?>";
       
   437 			var postmsg = "<?php printf(" &nbsp; <a href='javascript:void(0)' onclick='Duplicator.openLog()'>[%s]</a>", 	__('Preview Log', 'wpduplicator'));?>";
       
   438 			Duplicator.setStatus(msg, 'progress', postmsg);
       
   439 			Duplicator.createPackage($("input[name=package_name]").val());
       
   440 		} else {
       
   441 			Duplicator.setStatus("<?php _e('Ready to create new package.', 'wpduplicator') ?>");
       
   442 		}
       
   443 		return result;
       
   444 	}
       
   445 	
       
   446 
       
   447 	/*  ============================================================================
       
   448 	MISC ROUTINES */
       
   449 	$("div#div-render-blanket").show();
       
   450 	Duplicator.newWindow = function(url) {window.open(url);}
       
   451 
       
   452 	Duplicator.openLog = function() { 				
       
   453 		window.open('<?php echo DUPLICATOR_PLUGIN_URL .'files/log-view.php'; ?>', 'duplicator_logs');
       
   454 	}
       
   455 
       
   456 
       
   457 
       
   458 	});
       
   459 });
       
   460 </script>