mirror of
https://ghproxy.net/https://github.com/elementor/wp2static.git
synced 2025-09-08 22:42:57 +08:00
WIP saving all options as object
This commit is contained in:
parent
0140f9aa76
commit
2361bb5d5b
2 changed files with 73 additions and 3 deletions
|
@ -114,6 +114,8 @@ class StaticHtmlOutput
|
||||||
{
|
{
|
||||||
$this->_options
|
$this->_options
|
||||||
->setOption('version', self::VERSION)
|
->setOption('version', self::VERSION)
|
||||||
|
->setOption('static_export_settings', self::VERSION)
|
||||||
|
/*
|
||||||
->setOption('baseUrl', home_url())
|
->setOption('baseUrl', home_url())
|
||||||
->setOption('additionalUrls', '')
|
->setOption('additionalUrls', '')
|
||||||
->setOption('cleanMeta', '')
|
->setOption('cleanMeta', '')
|
||||||
|
@ -123,6 +125,7 @@ class StaticHtmlOutput
|
||||||
->setOption('ftpUsername', '')
|
->setOption('ftpUsername', '')
|
||||||
->setOption('ftpPassword', '')
|
->setOption('ftpPassword', '')
|
||||||
->setOption('ftpRemotePath', '')
|
->setOption('ftpRemotePath', '')
|
||||||
|
*/
|
||||||
->save();
|
->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,7 +169,7 @@ class StaticHtmlOutput
|
||||||
$supportsZipArchives = extension_loaded('zip');
|
$supportsZipArchives = extension_loaded('zip');
|
||||||
$permalinksStructureDefined = strlen(get_option('permalink_structure'));
|
$permalinksStructureDefined = strlen(get_option('permalink_structure'));
|
||||||
|
|
||||||
if (!$uploadsFolderWritable || !$supportsZipArchives ||!$permalinksStructureDefined)
|
if (!$uploadsFolderWritable || !$supportsZipArchives || !$permalinksStructureDefined)
|
||||||
{
|
{
|
||||||
$this->_view
|
$this->_view
|
||||||
->setTemplate('system-requirements')
|
->setTemplate('system-requirements')
|
||||||
|
@ -183,6 +186,8 @@ class StaticHtmlOutput
|
||||||
$this->_view
|
$this->_view
|
||||||
->setTemplate('options-page')
|
->setTemplate('options-page')
|
||||||
->assign('exportLog', $this->_exportLog)
|
->assign('exportLog', $this->_exportLog)
|
||||||
|
->assign('staticExportOption', $this->_options->getOption('static-export-options'))
|
||||||
|
/*
|
||||||
->assign('baseUrl', $this->_options->getOption('baseUrl'))
|
->assign('baseUrl', $this->_options->getOption('baseUrl'))
|
||||||
->assign('additionalUrls', $this->_options->getOption('additionalUrls'))
|
->assign('additionalUrls', $this->_options->getOption('additionalUrls'))
|
||||||
->assign('cleanMeta', $this->_options->getOption('cleanMeta'))
|
->assign('cleanMeta', $this->_options->getOption('cleanMeta'))
|
||||||
|
@ -191,6 +196,7 @@ class StaticHtmlOutput
|
||||||
->assign('ftpServer', $this->_options->getOption('ftpServer'))
|
->assign('ftpServer', $this->_options->getOption('ftpServer'))
|
||||||
->assign('ftpUsername', $this->_options->getOption('ftpUsername'))
|
->assign('ftpUsername', $this->_options->getOption('ftpUsername'))
|
||||||
->assign('ftpRemotePath', $this->_options->getOption('ftpRemotePath'))
|
->assign('ftpRemotePath', $this->_options->getOption('ftpRemotePath'))
|
||||||
|
*/
|
||||||
->assign('onceAction', self::HOOK . '-options')
|
->assign('onceAction', self::HOOK . '-options')
|
||||||
->render();
|
->render();
|
||||||
|
|
||||||
|
@ -216,6 +222,8 @@ class StaticHtmlOutput
|
||||||
|
|
||||||
// Save options
|
// Save options
|
||||||
$this->_options
|
$this->_options
|
||||||
|
->setOption('static-export-settings', filter_input(INPUT_POST, 'staticExportSettings', FILTER_SANITIZE_URL))
|
||||||
|
/*
|
||||||
->setOption('baseUrl', filter_input(INPUT_POST, 'baseUrl', FILTER_SANITIZE_URL))
|
->setOption('baseUrl', filter_input(INPUT_POST, 'baseUrl', FILTER_SANITIZE_URL))
|
||||||
->setOption('additionalUrls', filter_input(INPUT_POST, 'additionalUrls'))
|
->setOption('additionalUrls', filter_input(INPUT_POST, 'additionalUrls'))
|
||||||
->setOption('cleanMeta', filter_input(INPUT_POST, 'cleanMeta'))
|
->setOption('cleanMeta', filter_input(INPUT_POST, 'cleanMeta'))
|
||||||
|
@ -223,7 +231,8 @@ class StaticHtmlOutput
|
||||||
->setOption('sendViaFTP', filter_input(INPUT_POST, 'sendViaFTP'))
|
->setOption('sendViaFTP', filter_input(INPUT_POST, 'sendViaFTP'))
|
||||||
->setOption('ftpServer', filter_input(INPUT_POST, 'ftpServer'))
|
->setOption('ftpServer', filter_input(INPUT_POST, 'ftpServer'))
|
||||||
->setOption('ftpUsername', filter_input(INPUT_POST, 'ftpUsername'))
|
->setOption('ftpUsername', filter_input(INPUT_POST, 'ftpUsername'))
|
||||||
->setOption('ftpRemotePath', filter_input(INPUT_POST, 'ftpRemotePath'))
|
->setOption('ftpRemotePath', filter_input(INPUT_POST, 'ftpRemotePath'))
|
||||||
|
*/
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
$message = 'Options have been updated successfully.';
|
$message = 'Options have been updated successfully.';
|
||||||
|
|
|
@ -6,7 +6,18 @@
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$settings = esc_html($this->staticExportSettings);
|
||||||
|
if ($settings == '') {
|
||||||
|
$settings = 'banana';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
var settings = '<?php echo $settings; ?>';
|
||||||
|
|
||||||
jQuery(document).ready(function($){
|
jQuery(document).ready(function($){
|
||||||
|
|
||||||
var currentArchive = 1;
|
var currentArchive = 1;
|
||||||
|
@ -48,6 +59,46 @@ jQuery(document).ready(function($){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;});
|
||||||
|
|
||||||
|
console.log(newSettings);
|
||||||
|
|
||||||
|
// stick json encoded settings into hidden field within form(s)
|
||||||
|
$(".hiddenSettingsField").val(newSettings);
|
||||||
|
|
||||||
|
// base data on first form, so as to include nonces
|
||||||
|
data = $(archives[0]).serialize();
|
||||||
|
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: ajaxurl,
|
||||||
|
data: data,
|
||||||
|
dataType: 'html',
|
||||||
|
method: 'POST',
|
||||||
|
success: function(serverResponse) {
|
||||||
|
console.log('options saved');
|
||||||
|
$('#results').append(serverResponse);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#progress').hide();
|
||||||
|
}
|
||||||
|
|
||||||
$('#generateArchiveButton').click(function() {
|
$('#generateArchiveButton').click(function() {
|
||||||
|
|
||||||
$('#progress').show();
|
$('#progress').show();
|
||||||
|
@ -61,6 +112,15 @@ jQuery(document).ready(function($){
|
||||||
//$('#formActionHiddenField').val('generate')
|
//$('#formActionHiddenField').val('generate')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#saveSettingsButton').click(function() {
|
||||||
|
|
||||||
|
$('#progress').show();
|
||||||
|
|
||||||
|
saveOptions();
|
||||||
|
|
||||||
|
$('#results').html('');
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: set to on body event with button class as target, else need to reattach handler!
|
// TODO: set to on body event with button class as target, else need to reattach handler!
|
||||||
$('.wrap').on('click', '.addAnotherTargetButton', function(event) {
|
$('.wrap').on('click', '.addAnotherTargetButton', function(event) {
|
||||||
// TODO: needed prevention?
|
// TODO: needed prevention?
|
||||||
|
@ -149,7 +209,8 @@ jQuery(document).ready(function($){
|
||||||
<p class="submit">
|
<p class="submit">
|
||||||
<?php wp_nonce_field($this->onceAction) ?>
|
<?php wp_nonce_field($this->onceAction) ?>
|
||||||
<input id="formActionHiddenField" class="hiddenActionField" type="hidden" name="action" value="generate" />
|
<input id="formActionHiddenField" class="hiddenActionField" type="hidden" name="action" value="generate" />
|
||||||
<input class="button-primary" type="submit" name="submit" value="Save current options" />
|
<input name="staticExportSettings" class="hiddenSettingsField" type="hidden" name="action" value="" />
|
||||||
|
<input id="saveSettingsButton" class="button-primary" value="Save current options" />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue