wp2static/views/options-page.phtml

355 lines
17 KiB
PHTML
Raw Normal View History

2016-12-27 14:30:54 +13:00
<?php
/**
* @package WP Static HTML Output
*
* Copyright (c) 2011 Leon Stafford
*/
2017-03-07 13:26:34 +13:00
2017-03-07 12:13:28 +13:00
$settings = esc_html($this->staticExportSettings);
if ($settings == '') {
2017-03-11 15:18:56 +13:00
$settings = 'no existing settings found';
2017-03-07 12:13:28 +13:00
}
?>
2016-12-29 14:37:09 +13:00
<script>
2017-03-07 12:13:28 +13:00
var settings = '<?php echo $settings; ?>';
2016-12-29 14:37:09 +13:00
jQuery(document).ready(function($){
2017-03-10 23:05:30 +13:00
if (Notification.permission !== "granted") {
Notification.requestPermission();
}
function notifyMe() {
if (!Notification) {
alert('All exports are complete!.');
return;
}
2017-03-11 15:18:56 +13:00
if (Notification.permission !== "granted") {
2017-03-10 23:05:30 +13:00
Notification.requestPermission();
2017-03-11 15:18:56 +13:00
} else {
2017-03-10 23:05:30 +13:00
var notification = new Notification('WP Static HTML Export', {
icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/Wordpress_Shiny_Icon.svg/768px-Wordpress_Shiny_Icon.svg.png',
body: "Exports have finished!",
});
notification.onclick = function () {
parent.focus();
window.focus();
this.close();
};
}
}
2016-12-29 16:20:49 +13:00
2017-02-20 23:34:03 +13:00
var currentArchive = 1;
function processArchives() {
$('.hiddenActionField').val('generate_archive');
archives = $('.options-form');
numberOfArchives = archives.length;
if (currentArchive <= numberOfArchives) {
data = $(archives[currentArchive - 1]).serialize();
$.ajax({
url: ajaxurl,
data: data,
dataType: 'html',
method: 'POST',
success: function(serverResponse) {
$('#results').append(serverResponse);
currentArchive += 1;
processArchives();
}
});
} else {
currentArchive = 0;
// all archives processed
$('#progress').hide();
2017-03-10 23:05:30 +13:00
notifyMe();
2017-02-20 23:34:03 +13:00
}
}
2016-12-29 16:20:49 +13:00
2017-03-07 12:13:28 +13:00
function saveOptions() {
2017-03-11 15:18:56 +13:00
// toggles between saving and generating archives
// TODO: 'save' would be better name here....
2017-03-07 12:13:28 +13:00
$('.hiddenActionField').val('generate');
archives = $('.options-form');
numberOfArchives = archives.length;
2017-03-07 13:26:34 +13:00
var newSettings = $(".options-form").serialize();
2017-03-07 12:13:28 +13:00
// stick json encoded settings into hidden field within form(s)
$(".hiddenSettingsField").val(newSettings);
2017-03-11 15:18:56 +13:00
// submit first form which encapsulates all others
2017-03-07 13:26:34 +13:00
$(archives[0]).submit();
2017-03-07 12:13:28 +13:00
}
2017-02-20 23:34:03 +13:00
$('#generateArchiveButton').click(function() {
$('#progress').show();
processArchives();
$('#results').html('');
});
2017-03-10 12:55:50 +13:00
$('.wrap').on('click', '.removeTargetButton', function(event) {
event.preventDefault();
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 {
$(event.target).closest('.options-form').remove();
}
});
2017-03-07 13:26:34 +13:00
$('.wrap').on('click', '.saveSettingsButton', function(event) {
// TODO: needed prevention?
event.preventDefault();
2017-03-07 12:13:28 +13:00
$('#progress').show();
saveOptions();
$('#results').html('');
});
2017-02-20 23:34:03 +13:00
$('.wrap').on('click', '.addAnotherTargetButton', function(event) {
event.preventDefault();
$('.options-form:last').clone().insertAfter('.options-form:last');
2016-12-29 14:37:09 +13:00
});
2017-03-07 13:59:55 +13:00
// load existing settings
2017-03-11 15:18:56 +13:00
if (settings != 'no existing settings found') {
2017-03-07 13:59:55 +13:00
archives = settings.split('baseUrl=');
// remove crufty first element
archives.shift();
// first run, will populate only form on page
var targetExportSettingsBlock = $('.options-form')[0];
2017-03-07 13:59:55 +13:00
// iterate each saved settings chunk and create forms for them
$.each(archives, function(index, value) {
2017-03-08 18:46:10 +13:00
renderedExportSettingsBlocks = $('.options-form').length;
targetExportSettingsBlock = $('.options-form:last');
2017-03-07 13:59:55 +13:00
archive = 'baseUrl=' + value;
archive = archive.substring(0, archive.indexOf('&amp;staticExportSettings='));
settingsBlock = JSON.parse('{"' + decodeURI(archive).replace(/\n/g, ",").replace(/\r/g, ",").replace(/"/g, '\\"').replace(/&amp;/g, '","').replace(/=/g,'":"') + '"}');
$(targetExportSettingsBlock).find('#baseUrl').first().val(decodeURIComponent(settingsBlock.baseUrl));
2017-03-08 18:46:10 +13:00
2017-03-10 12:25:52 +13:00
additionalUrls = settingsBlock.additionalUrls.split(',');
newAdditionalUrls = '';
2017-03-08 18:46:10 +13:00
2017-03-10 12:25:52 +13:00
$.each(additionalUrls, function(index, value) {
if (value != '') {
newAdditionalUrls += decodeURIComponent(value) + "\n";
}
});
2017-03-08 18:46:10 +13:00
2017-03-10 12:25:52 +13:00
$(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));
2017-03-10 15:25:19 +13:00
$(targetExportSettingsBlock).find('#ftpUsername').first().val(decodeURIComponent(settingsBlock.ftpUsername));
$(targetExportSettingsBlock).find('#ftpPassword').first().val(decodeURIComponent(settingsBlock.ftpPassword));
2017-03-10 12:25:52 +13:00
$(targetExportSettingsBlock).find('#ftpRemotePath').first().val(decodeURIComponent(settingsBlock.ftpRemotePath));
2017-03-11 21:25:38 +13:00
$(targetExportSettingsBlock).find('#sendViaS3')[0].checked = settingsBlock.sendViaS3;
$(targetExportSettingsBlock).find('#s3Key').first().val(decodeURIComponent(settingsBlock.s3Key));
$(targetExportSettingsBlock).find('#s3Secret').first().val(decodeURIComponent(settingsBlock.s3Secret));
$(targetExportSettingsBlock).find('#s3Region').first().val(decodeURIComponent(settingsBlock.s3Region));
$(targetExportSettingsBlock).find('#s3Bucket').first().val(decodeURIComponent(settingsBlock.s3Bucket));
2017-03-12 17:54:22 +13:00
$(targetExportSettingsBlock).find('#sendViaDropbox')[0].checked = settingsBlock.sendViaDropbox;
$(targetExportSettingsBlock).find('#dropboxAccessToken').first().val(decodeURIComponent(settingsBlock.dropboxAccessToken));
$(targetExportSettingsBlock).find('#dropboxFolder').first().val(decodeURIComponent(settingsBlock.dropboxFolder));
2017-03-07 13:59:55 +13:00
// if there are more to come, clone and set target
if (index < (archives.length -1)) {
$('.options-form:last').clone().insertAfter('.options-form:last');
targetExportSettingsBlock = $('.options-form:last');
$(targetExportSettingsBlock).find('#baseUrl').first().val('');
2017-03-10 12:55:50 +13:00
$(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('');
2017-03-11 21:25:38 +13:00
$(targetExportSettingsBlock).find('#sendViaS3').first().prop('checked', false);
$(targetExportSettingsBlock).find('#s3Key').val('');
$(targetExportSettingsBlock).find('#s3Secret').val('');
$(targetExportSettingsBlock).find('#s3Region').val('');
$(targetExportSettingsBlock).find('#s3Bucket').val('');
2017-03-12 17:54:22 +13:00
$(targetExportSettingsBlock).find('#sendViaDropbox').first().prop('checked', false);
$(targetExportSettingsBlock).find('#dropboxAccessToken').val('');
$(targetExportSettingsBlock).find('#dropboxFolder').val('');
}
});
2017-03-07 13:59:55 +13:00
}
2016-12-29 14:37:09 +13:00
});
</script>
2016-12-27 14:30:54 +13:00
<div class="wrap">
2016-12-27 20:39:13 +13:00
<h2><?= __('WP Static HTML Output - Configure & Run', 'static-html-output-plugin');?></h2>
2016-12-29 14:37:09 +13:00
2016-12-27 14:30:54 +13:00
<div class="postbox-container">
<div class="metabox-holder">
<div class="meta-box-sortables ui-sortable">
2017-02-20 23:34:03 +13:00
<form id="general-options" class="options-form" method="post" action="">
2016-12-27 14:30:54 +13:00
<div class="postbox">
2017-02-20 23:34:03 +13:00
<h3>
<span><?= __('Configurable options', 'static-html-output-plugin');?></span>
</h3>
2016-12-27 14:30:54 +13:00
<div class="inside">
<p>
2016-12-27 20:39:13 +13:00
<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>
2016-12-27 14:30:54 +13:00
<input type="text" id="baseUrl" name="baseUrl" value="<?php echo esc_attr($this->baseUrl) ?>" size="50" />
</p>
<p>
2016-12-27 20:39:13 +13:00
<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>
2016-12-27 14:30:54 +13:00
<textarea class="widefat" name="additionalUrls" id="additionalUrls" rows="5" cols="10"><?php echo esc_html($this->additionalUrls) ?></textarea>
</p>
2017-03-11 15:46:27 +13:00
<fieldset>
<label for="cleanMeta">
<input name="cleanMeta" id="cleanMeta" value="1" type="checkbox" <?php if ($this->cleanMeta == 1) echo "checked"; ?> />
2017-03-11 15:54:33 +13:00
<span><?= __('Strip out unneeded WordPress meta tags, ie &lt;meta name="generator" content="WordPress...', 'static-html-output-plugin');?></span>
2017-03-11 15:46:27 +13:00
</label>
</fieldset>
2016-12-27 14:30:54 +13:00
2017-03-11 15:46:27 +13:00
<fieldset>
<label for="retainStaticFiles">
<input name="retainStaticFiles" id="retainStaticFiles" value="1" type="checkbox" <?php if ($this->retainStaticFiles == 1) echo "checked"; ?> />
<span><?= __('Retain generated static files on server', 'static-html-output-plugin');?></span>
</label>
</fieldset>
<fieldset>
<label for="sendViaFTP">
2016-12-29 14:02:55 +13:00
<input name="sendViaFTP" id="sendViaFTP" value="1" type="checkbox" <?php if ($this->sendViaFTP == 1) echo "checked"; ?> />
2017-03-11 15:46:27 +13:00
<span><?= __('Transfer files via FTP', 'static-html-output-plugin');?></span>
</label>
</fieldset>
2016-12-29 14:02:55 +13:00
2017-03-11 15:46:27 +13:00
<input name="ftpServer" class="regular-text" id="ftpServer" value="<?php echo esc_attr($this->ftpServer) ?>" placeholder="<?= __('FTP Server', 'static-html-output-plugin');?>" />
<span class="description">ie, localhost, 192.168.1.7, ftp.mydomain.com, etc</span>
<br>
2016-12-29 14:02:55 +13:00
2017-03-11 15:46:27 +13:00
<input name="ftpUsername" class="regular-text" id="ftpUsername" value="<?php echo esc_attr($this->ftpUsername) ?>" placeholder="<?= __('FTP Username', 'static-html-output-plugin');?>" />
<br>
2016-12-29 14:02:55 +13:00
2017-03-11 15:46:27 +13:00
<input class="regular-text" name="ftpPassword" id="ftpPassword" type="password" value="" placeholder="<?= __('FTP Password', 'static-html-output-plugin');?>" />
<br>
2016-12-29 14:02:55 +13:00
2017-03-11 15:46:27 +13:00
<input class="regular-text" name="ftpRemotePath" id="ftpRemotePath" value="<?php echo esc_attr($this->ftpRemotePath) ?>" placeholder="<?= __('FTP Remote Path', 'static-html-output-plugin');?>" />
<span class="description">will attempt to create folder recursively if non-existent</span>
<br>
2017-03-11 21:25:38 +13:00
<br>
<fieldset>
<label for="sendViaS3">
<input name="sendViaS3" id="sendViaS3" value="1" type="checkbox" <?php if ($this->sendViaS3 == 1) echo "checked"; ?> />
<span><?= __('Transfer files via S3', 'static-html-output-plugin');?></span>
</label>
</fieldset>
<input name="s3Key" class="regular-text" id="s3Key" value="<?php echo esc_attr($this->s3Key) ?>" placeholder="<?= __('S3 Key', 'static-html-output-plugin');?>" />
<span class="description">ie, AKIAIOSFODNN7EXAMPLE</span>
<br>
<input name="s3Secret" class="regular-text" id="s3Secret" value="<?php echo esc_attr($this->s3Secret) ?>" placeholder="<?= __('S3 Secret', 'static-html-output-plugin');?>" />
<span class="description">ie, wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY</span>
<br>
<select name="s3Region" id="s3Region">
<option value="us-east-1">US East (N. Virginia)</option>
<option value="us-east-2">US East (Ohio)</option>
<option value="us-west-1">US West (N. California)</option>
<option value="us-west-2">US West (Oregon)</option>
<option value="ca-central-1">Canada (Central)</option>
<option value="ap-south-1">Asia Pacific (Mumbai)</option>
<option value="ap-northeast-2">Asia Pacific (Seoul)</option>
<option value="ap-southeast-1">Asia Pacific (Singapore)</option>
<option value="ap-southeast-2">Asia Pacific (Sydney)</option>
<option value="ap-northeast-1">Asia Pacific (Tokyo)</option>
<option value="eu-central-1">EU (Frankfurt)</option>
<option value="eu-west-1">EU (Ireland)</option>
<option value="eu-west-2">EU (London)</option>
<option value="sa-east-1">South America (São Paulo)</option>
</select>
<span class="description">choose the region your bucket is in</span>
<br>
<input name="s3Bucket" class="regular-text" id="s3Bucket" value="<?php echo esc_attr($this->s3Bucket) ?>" placeholder="<?= __('S3 Bucket name', 'static-html-output-plugin');?>" />
<span class="description">ie, my-static-site</span>
2017-03-12 17:54:22 +13:00
<br>
<br>
<fieldset>
<label for="sendViaDropbox">
<input name="sendViaDropbox" id="sendViaDropbox" value="1" type="checkbox" <?php if ($this->sendViaDropbox == 1) echo "checked"; ?> />
<span><?= __('Transfer files via Dropbox', 'static-html-output-plugin');?></span>
</label>
</fieldset>
<input name="dropboxAccessToken" class="regular-text" id="dropboxAccessToken" value="<?php echo esc_attr($this->dropboxAccessToken) ?>" placeholder="<?= __('Dropbox access token', 'static-html-output-plugin');?>" />
<span class="description"><a href="https://blogs.dropbox.com/developers/2014/05/generate-an-access-token-for-your-own-account/" target="_blank">How do I get this?</a></span>
<br>
<input name="dropboxFolder" class="regular-text" id="dropboxFolder" value="<?php echo esc_attr($this->dropboxFolder) ?>" placeholder="<?= __('Dropbox folder', 'static-html-output-plugin');?>" />
<span class="description">ie, where you want this to appear in your Dropbox account</span>
2017-03-11 21:25:38 +13:00
<br>
<p class="submit">
<?php wp_nonce_field($this->onceAction) ?>
2017-02-20 23:34:03 +13:00
<input id="formActionHiddenField" class="hiddenActionField" type="hidden" name="action" value="generate" />
2017-03-07 12:13:28 +13:00
<input name="staticExportSettings" class="hiddenSettingsField" type="hidden" name="action" value="" />
2017-03-07 13:26:34 +13:00
<input class="saveSettingsButton button-primary" value="Save current options" />
2017-03-11 15:46:27 +13:00
<button class="button addAnotherTargetButton">Add another export target</button>
<button class="button removeTargetButton">Remove this export target</button>
</p>
2016-12-27 14:30:54 +13:00
</div>
</div>
2016-12-27 20:39:13 +13:00
2017-02-20 23:34:03 +13:00
</form>
2016-12-27 20:39:13 +13:00
<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>
2017-02-20 23:34:03 +13:00
<div id="progress" style="display:none;">
2016-12-29 17:22:51 +13:00
<img src="<?php echo plugins_url('../images/dashinfinity.gif', __FILE__); ?>" />
</div>
2016-12-29 14:37:09 +13:00
2017-02-20 23:34:03 +13:00
<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>
2016-12-29 14:37:09 +13:00
<p class="submit">
<?php wp_nonce_field($this->onceAction) ?>
2016-12-29 17:22:51 +13:00
<input id="generateArchiveButton" class="button-primary" value="Start static site export" />
2016-12-29 14:37:09 +13:00
</p>
2016-12-27 20:39:13 +13:00
</p>
</div>
</div>
2016-12-27 14:30:54 +13:00
</div>
</div>
</div>
</div>