mirror of
https://ghproxy.net/https://github.com/elementor/wp2static.git
synced 2025-08-30 19:39:43 +08:00
335 lines
13 KiB
PHTML
335 lines
13 KiB
PHTML
<?php
|
|
/**
|
|
* @package WP Static HTML Output
|
|
*
|
|
* Copyright (c) 2011 Leon Stafford
|
|
*/
|
|
|
|
error_log('loading options page');
|
|
?>
|
|
|
|
<?php
|
|
|
|
$settings = esc_html($this->staticExportSettings);
|
|
if ($settings == '') {
|
|
$settings = 'banana';
|
|
}
|
|
?>
|
|
|
|
<script>
|
|
|
|
var settings = '<?php echo $settings; ?>';
|
|
|
|
jQuery(document).ready(function($){
|
|
|
|
var currentArchive = 1;
|
|
|
|
function processArchives() {
|
|
// set form action for generation vs saving options
|
|
$('.hiddenActionField').val('generate_archive');
|
|
|
|
console.log('processing archive');
|
|
console.log('current archive: ' + currentArchive);
|
|
|
|
archives = $('.options-form');
|
|
numberOfArchives = archives.length;
|
|
|
|
console.log('number of archives: ' + numberOfArchives);
|
|
|
|
if (currentArchive <= numberOfArchives) {
|
|
|
|
data = $(archives[currentArchive - 1]).serialize();
|
|
|
|
$.ajax({
|
|
url: ajaxurl,
|
|
data: data,
|
|
dataType: 'html',
|
|
method: 'POST',
|
|
success: function(serverResponse) {
|
|
console.log('processed archive ' + currentArchive + ' / ' + numberOfArchives);
|
|
$('#results').append(serverResponse);
|
|
currentArchive += 1;
|
|
processArchives();
|
|
}
|
|
|
|
|
|
});
|
|
} else {
|
|
currentArchive = 0;
|
|
// all archives processed
|
|
$('#progress').hide();
|
|
}
|
|
}
|
|
|
|
function saveOptions() {
|
|
// toggles between saving and generating
|
|
$('.hiddenActionField').val('generate');
|
|
|
|
console.log('saving options');
|
|
|
|
archives = $('.options-form');
|
|
numberOfArchives = archives.length;
|
|
|
|
console.log('number of archives: ' + numberOfArchives);
|
|
|
|
|
|
//var newSettings = {};
|
|
//$(".options-form").serializeArray().map(function(x){newSettings[x.name] = x.value;});
|
|
var newSettings = $(".options-form").serialize();
|
|
|
|
console.log(newSettings);
|
|
|
|
// stick json encoded settings into hidden field within form(s)
|
|
$(".hiddenSettingsField").val(newSettings);
|
|
|
|
// just submit form as usual
|
|
$(archives[0]).submit();
|
|
}
|
|
|
|
$('#generateArchiveButton').click(function() {
|
|
|
|
$('#progress').show();
|
|
|
|
processArchives();
|
|
|
|
$('#results').html('');
|
|
|
|
// TODO: renable this upon all complete
|
|
// revert form action for saving options vs generation
|
|
//$('#formActionHiddenField').val('generate')
|
|
});
|
|
|
|
$('.wrap').on('click', '.removeTargetButton', function(event) {
|
|
event.preventDefault();
|
|
|
|
console.log($('.options-form').length);
|
|
|
|
// check if only settings block, prevent deleting it
|
|
if ($('.options-form').length === 1) {
|
|
alert("Sorry, got to keep at least one settings block around. But, you can delete the values if you like");
|
|
} else {
|
|
// delete target block
|
|
$(event.target).closest('.options-form').remove();
|
|
}
|
|
});
|
|
|
|
$('.wrap').on('click', '.saveSettingsButton', function(event) {
|
|
// TODO: needed prevention?
|
|
event.preventDefault();
|
|
|
|
$('#progress').show();
|
|
|
|
saveOptions();
|
|
|
|
$('#results').html('');
|
|
|
|
});
|
|
|
|
$('.wrap').on('click', '.addAnotherTargetButton', function(event) {
|
|
// TODO: needed prevention?
|
|
event.preventDefault();
|
|
|
|
// append copy of form below current one
|
|
$('.options-form:last').clone().insertAfter('.options-form:last');
|
|
|
|
});
|
|
|
|
// load existing settings
|
|
if (settings != 'banana') {
|
|
console.log('existing settings found, lets use those');
|
|
|
|
archives = settings.split('baseUrl=');
|
|
// remove crufty first element
|
|
archives.shift();
|
|
console.log(archives);
|
|
|
|
// first run, will populate only form on page
|
|
var targetExportSettingsBlock = $('.options-form')[0];
|
|
|
|
// iterate each saved settings chunk and create forms for them
|
|
$.each(archives, function(index, value) {
|
|
|
|
renderedExportSettingsBlocks = $('.options-form').length;
|
|
console.log('currently, there are n forms on page: ' + renderedExportSettingsBlocks);
|
|
|
|
// always target the last rendered block
|
|
targetExportSettingsBlock = $('.options-form:last');
|
|
|
|
// add back in the 'baseUrl='
|
|
archive = 'baseUrl=' + value;
|
|
// trim trailing field
|
|
//archive = archive.substring(0, archive.indexOf('&staticExportSettings=&'));
|
|
archive = archive.substring(0, archive.indexOf('&staticExportSettings='));
|
|
//archive = archive.substring(0, archive.indexOf('staticExportSettings='));
|
|
console.log(archive);
|
|
|
|
settingsBlock = JSON.parse('{"' + decodeURI(archive).replace(/\n/g, ",").replace(/\r/g, ",").replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
|
|
|
|
console.log(settingsBlock);
|
|
|
|
// populate fields in target form with this archive's values
|
|
// baseUrl
|
|
$(targetExportSettingsBlock).find('#baseUrl').first().val(decodeURIComponent(settingsBlock.baseUrl));
|
|
|
|
// convert additionalurls back into line-separated decoded uri's
|
|
// TODO: use single map function
|
|
additionalUrls = settingsBlock.additionalUrls.split(',');
|
|
|
|
newAdditionalUrls = '';
|
|
|
|
$.each(additionalUrls, function(index, value) {
|
|
if (value != '') {
|
|
newAdditionalUrls += decodeURIComponent(value) + "\n";
|
|
}
|
|
});
|
|
|
|
$(targetExportSettingsBlock).find('#additionalUrls').val(newAdditionalUrls);
|
|
|
|
$(targetExportSettingsBlock).find('#cleanMeta')[0].checked = settingsBlock.cleanMeta;
|
|
$(targetExportSettingsBlock).find('#retainStaticFiles')[0].checked = settingsBlock.retainStaticFiles;
|
|
$(targetExportSettingsBlock).find('#sendViaFTP')[0].checked = settingsBlock.sendViaFTP;
|
|
$(targetExportSettingsBlock).find('#ftpServer').first().val(decodeURIComponent(settingsBlock.ftpServer));
|
|
$(targetExportSettingsBlock).find('#ftpUsername').first().val(decodeURIComponent(settingsBlock.ftpUsername));
|
|
$(targetExportSettingsBlock).find('#ftpPassword').first().val(decodeURIComponent(settingsBlock.ftpPassword));
|
|
$(targetExportSettingsBlock).find('#ftpRemotePath').first().val(decodeURIComponent(settingsBlock.ftpRemotePath));
|
|
|
|
console.log('total settingsBlocks to render: ' + archives.length);
|
|
console.log('current settingsBlock: ' + index);
|
|
|
|
// if there are more to come, clone and set target
|
|
if (index < (archives.length -1)) {
|
|
// clone last form
|
|
$('.options-form:last').clone().insertAfter('.options-form:last');
|
|
|
|
// set as target
|
|
targetExportSettingsBlock = $('.options-form:last');
|
|
|
|
// clear values
|
|
$(targetExportSettingsBlock).find('#baseUrl').first().val('');
|
|
|
|
$(targetExportSettingsBlock).find('#additionalUrls').val('');
|
|
$(targetExportSettingsBlock).find('#cleanMeta').first().prop('checked', false);
|
|
$(targetExportSettingsBlock).find('#retainStaticFiles').first().prop('checked', false);
|
|
$(targetExportSettingsBlock).find('#sendViaFTP').first().prop('checked', false);
|
|
$(targetExportSettingsBlock).find('#ftpServer').val('');
|
|
$(targetExportSettingsBlock).find('#ftpUsername').val('');
|
|
$(targetExportSettingsBlock).find('#ftpPassword').val('');
|
|
$(targetExportSettingsBlock).find('#ftpRemotePath').val('');
|
|
}
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<div class="wrap">
|
|
|
|
<h2><?= __('WP Static HTML Output - Configure & Run', 'static-html-output-plugin');?></h2>
|
|
|
|
<div class="postbox-container">
|
|
<div class="metabox-holder">
|
|
<div class="meta-box-sortables ui-sortable">
|
|
|
|
<form id="general-options" class="options-form" method="post" action="">
|
|
|
|
<div class="postbox">
|
|
<!--<div class="handlediv" title="Click to toggle"><br /></div>-->
|
|
|
|
<h3>
|
|
<span><?= __('Configurable options', 'static-html-output-plugin');?></span>
|
|
<button class="addAnotherTargetButton">Add another export target</button>
|
|
<button class="removeTargetButton">Remove this export target</button>
|
|
</h3>
|
|
|
|
<div class="inside">
|
|
<p>
|
|
<strong><label for="baseUrl"><?= __('Base Url', 'static-html-output-plugin');?></label></strong>
|
|
<p>
|
|
<i>This defaults to your WordPress Site URL. If you know the URL of where you'll be hosting the static version of your site, it will be good to change this to that, ie http://mystaticsite.github.io</i>
|
|
</p>
|
|
<input type="text" id="baseUrl" name="baseUrl" value="<?php echo esc_attr($this->baseUrl) ?>" size="50" />
|
|
</p>
|
|
|
|
<p>
|
|
<strong><label for="additionalUrls"><?= __('Additional Urls', 'static-html-output-plugin');?></label></strong>
|
|
<p>
|
|
<i>For a few themes, certain files may not be detected as part of the export process. Enter any such files here, one per line. </i>
|
|
</p>
|
|
<textarea class="widefat" name="additionalUrls" id="additionalUrls" rows="5" cols="10"><?php echo esc_html($this->additionalUrls) ?></textarea>
|
|
</p>
|
|
|
|
<p>
|
|
<input name="cleanMeta" id="cleanMeta" value="1" type="checkbox" <?php if ($this->cleanMeta == 1) echo "checked"; ?> />
|
|
<label for="cleanMeta"><?= __('Strip out unneeded WordPress meta tags', 'static-html-output-plugin');?></label>
|
|
</p>
|
|
|
|
<p>
|
|
<input name="retainStaticFiles" id="retainStaticFiles" value="1" type="checkbox" <?php if ($this->retainStaticFiles == 1) echo "checked"; ?> />
|
|
<label for="retainStaticFiles"><?= __('Retain generated static files on server', 'static-html-output-plugin');?></label>
|
|
</p>
|
|
|
|
<p>
|
|
<input name="sendViaFTP" id="sendViaFTP" value="1" type="checkbox" <?php if ($this->sendViaFTP == 1) echo "checked"; ?> />
|
|
<label for="sendViaFTP"><?= __('Transfer files via FTP', 'static-html-output-plugin');?></label>
|
|
<br /><b><span style="color:red;"><?= __('FTP functionality is in Beta testing: For large sites, page may seem unresponsive until complete. If in doubt, check your remote FTP directory for activity.', 'static-html-output-plugin');?> </span></b>
|
|
</p>
|
|
|
|
<p>
|
|
<label for="ftpServer"><?= __('FTP Server', 'static-html-output-plugin');?>:</label><br />
|
|
<input name="ftpServer" id="ftpServer" value="<?php echo esc_attr($this->ftpServer) ?>" size="30" />
|
|
</p>
|
|
|
|
<p>
|
|
<label for="ftpUsername"><?= __('FTP Username', 'static-html-output-plugin');?>:</label><br />
|
|
<input name="ftpUsername" id="ftpUsername" value="<?php echo esc_attr($this->ftpUsername) ?>" size="30" />
|
|
</p>
|
|
|
|
<p>
|
|
<label for="ftpPassword"><?= __('FTP Password', 'static-html-output-plugin');?>:</label><br />
|
|
<input name="ftpPassword" id="ftpPassword" type="password" value="" size="30" />
|
|
</p>
|
|
|
|
<p>
|
|
<label for="ftpRemotePath"><?= __('FTP Remote Path', 'static-html-output-plugin');?>:</label><br />
|
|
<input name="ftpRemotePath" id="ftpRemotePath" value="<?php echo esc_attr($this->ftpRemotePath) ?>" size="30" />
|
|
</p>
|
|
|
|
<p class="submit">
|
|
<?php wp_nonce_field($this->onceAction) ?>
|
|
<input id="formActionHiddenField" class="hiddenActionField" type="hidden" name="action" value="generate" />
|
|
<input name="staticExportSettings" class="hiddenSettingsField" type="hidden" name="action" value="" />
|
|
<input class="saveSettingsButton button-primary" value="Save current options" />
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
</form>
|
|
<div class="postbox">
|
|
<div class="handlediv" title="Click to toggle"><br /></div>
|
|
|
|
<h3 class="hndle"><span><?= __('Export your site', 'static-html-output-plugin');?></span></h3>
|
|
|
|
<div class="inside">
|
|
<p>
|
|
|
|
<div id="progress" style="display:none;">
|
|
<img src="<?php echo plugins_url('../images/dashinfinity.gif', __FILE__); ?>" />
|
|
</div>
|
|
|
|
<div id="results">
|
|
</div>
|
|
|
|
<p>
|
|
<i>Clicking the button below will start the process of generating a static site from your WordPress installation. Depending on the size of your website, this process may take some time.</i>
|
|
</p>
|
|
|
|
<p class="submit">
|
|
<?php wp_nonce_field($this->onceAction) ?>
|
|
<input id="generateArchiveButton" class="button-primary" value="Start static site export" />
|
|
</p>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|