ajaxify archive generation

This commit is contained in:
Leon Stafford 2016-12-29 17:22:51 +13:00
parent 547e3bf2d6
commit 65c7b8475b
5 changed files with 22 additions and 25 deletions

BIN
images/dashinfinity.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View file

@ -97,6 +97,7 @@ class StaticHtmlOutput
{
add_action('admin_menu', array($instance, 'registerOptionsPage'));
add_action(self::HOOK . '-saveOptions', array($instance, 'saveOptions'));
}
return $instance;
@ -235,13 +236,6 @@ class StaticHtmlOutput
public function genArch()
{
// Protection
if (!isset($_POST['action']) || 'genArchive' != $_POST['action'])
{
return;
}
// Generate archive
$archiveUrl = $this->_generateArchive();
@ -259,12 +253,10 @@ class StaticHtmlOutput
}
}
echo 'Archive has been created... log...';
/*
$this->_view->setTemplate('message')
->assign('message', $message)
->assign('exportLog', $this->_exportLog)
->render();
*/
}
/**

View file

@ -5,6 +5,13 @@
* Copyright (c) 2011 Leon Stafford
*/
?>
<div class="updated fade">
<p><strong><?php echo $this->message ?></strong></p>
</div>
<p><strong><?php echo $this->message; ?></strong></p>
</div>
<?php if (is_array($this->exportLog) && count($this->exportLog)): ?>
<h3>Export Log</h3>
<pre class="wpsho-export-log"><?php echo implode("\n", array_keys($this->exportLog)) ?></pre>
<?php endif ?>

View file

@ -9,10 +9,10 @@
<script>
jQuery(document).ready(function($){
$('#generateArchiveButton').click(function() {
console.log('Generating archive...');
$('#results').show();
// set form action for generation vs saving options
$('#formActionHiddenField').val('my_action')
$('#formActionHiddenField').val('generate_archive')
data = $('#general-options').serialize();
@ -31,10 +31,6 @@ jQuery(document).ready(function($){
<h2><?= __('WP Static HTML Output - Configure & Run', 'static-html-output-plugin');?></h2>
<?php if (is_array($this->exportLog) && count($this->exportLog)): ?>
<h3>Export Log</h3>
<pre class="wpsho-export-log"><?php echo implode("\n", array_keys($this->exportLog)) ?></pre>
<?php endif ?>
<div class="postbox-container">
<div class="metabox-holder">
@ -119,13 +115,13 @@ jQuery(document).ready(function($){
<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>
<div id="results">
results go here...
<div id="results" style="display:none;">
<img src="<?php echo plugins_url('../images/dashinfinity.gif', __FILE__); ?>" />
</div>
<p class="submit">
<?php wp_nonce_field($this->onceAction) ?>
<input id="generateArchiveButton" class="button-primary" value="Start static site export (AJAX)" />
<input id="generateArchiveButton" class="button-primary" value="Start static site export" />
</p>
</p>
</div>

View file

@ -43,11 +43,13 @@ function myplugin_init() {
}
add_action('plugins_loaded', 'myplugin_init');
add_action( 'wp_ajax_my_action', 'my_action_callback' );
add_action( 'wp_ajax_generate_archive', 'generate_archive' );
function my_action_callback() {
function generate_archive() {
echo 'some response this is!';
$plugin = StaticHtmlOutput::getInstance();
wp_die(); // this is required to terminate immediately and return a proper response
$plugin->genArch();
wp_die();
}