Add an optional target output directory

Former-commit-id: 6bf0bb0faa
This commit is contained in:
Adrian Gonzales 2017-05-26 14:49:32 -05:00
parent 95f0334409
commit 3610ab7521
2 changed files with 49 additions and 6 deletions

View file

@ -1,4 +1,10 @@
<?php
/**
* @package WP Static HTML Output
*
* Copyright (c) 2011 Leon Stafford
*/
class StaticHtmlOutput {
const VERSION = '1.9';
const OPTIONS_KEY = 'wp-static-html-output-options';
@ -60,8 +66,8 @@ class StaticHtmlOutput {
public function renderOptionsPage() {
// Check system requirements
$uploadDir = wp_upload_dir();
$uploadsFolderWritable = $uploadDir && is_writable($uploadDir['path']);
$uploadDir = $this->get_write_directory();
$uploadsFolderWritable = $uploadDir && is_writable($uploadDir);
$supportsZipArchives = extension_loaded('zip');
$permalinksStructureDefined = strlen(get_option('permalink_structure'));
@ -107,6 +113,26 @@ class StaticHtmlOutput {
->render();
}
public function get_write_directory(){
$outputDir = filter_input(INPUT_POST, 'outputDirectory');
// Check to see if the directory exists
if ( $outputDir && !file_exists($outputDir)) {
// If not, try to create it
wp_mkdir_p($outputDir);
// Makes sure it's writable
if( is_writable( $outputDir ) ){
return $outputDir;
}
}
// Default WP Upload Location
$wp_upload_dir = wp_upload_dir();
return $wp_upload_dir['path'];
}
public function genArch() {
$archiveUrl = $this->_generateArchive();
@ -131,9 +157,9 @@ class StaticHtmlOutput {
global $blog_id;
set_time_limit(0);
$uploadDir = wp_upload_dir();
$uploadDir = $this->get_write_directory();
$exporter = wp_get_current_user();
$archiveName = $uploadDir['path'] . '/' . self::HOOK . '-' . $blog_id . '-' . time() . '-' . $exporter->user_login;
$archiveName = $uploadDir . '/' . self::HOOK . '-' . $blog_id . '-' . time() . '-' . $exporter->user_login;
$archiveDir = $archiveName . '/';
if (!file_exists($archiveDir))
{
@ -257,7 +283,7 @@ class StaticHtmlOutput {
$files = scandir($dir);
foreach($files as $item){
if($item != '.' && $item != '..'){
$ContentType = GuessMimeType($item);
$ContentType = GuessType($item);
if(is_dir($dir.'/'.$item)) {
UploadDirectory($S3, $Bucket, $dir.'/'.$item, $siteroot);
} else if(is_file($dir.'/'.$item)) {
@ -275,7 +301,13 @@ class StaticHtmlOutput {
}
}
function GuessMimeType($File) {
/*
* GuessType -
*
* Make a simple guess as to the file's content type,
* and return a MIME type.
*/
function GuessType($File) {
$Info = pathinfo($File, PATHINFO_EXTENSION);
switch (strtolower($Info))
{

View file

@ -131,6 +131,8 @@ jQuery(document).ready(function($){
$(targetExportSettingsBlock).find('#baseUrl').first().val(decodeURIComponent(settingsBlock.baseUrl));
$(targetExportSettingsBlock).find('#outputDirectory').val(decodeURIComponent(settingsBlock.outputDirectory));
additionalUrls = settingsBlock.additionalUrls.split(',');
newAdditionalUrls = '';
@ -163,6 +165,7 @@ jQuery(document).ready(function($){
$('.options-form:last').clone().insertAfter('.options-form:last');
targetExportSettingsBlock = $('.options-form:last');
$(targetExportSettingsBlock).find('#baseUrl').first().val('');
$(targetExportSettingsBlock).find('#outputDirectory').val('');
$(targetExportSettingsBlock).find('#additionalUrls').val('');
$(targetExportSettingsBlock).find('#cleanMeta').first().prop('checked', false);
$(targetExportSettingsBlock).find('#retainStaticFiles').first().prop('checked', false);
@ -209,6 +212,14 @@ jQuery(document).ready(function($){
</p>
<input type="text" id="baseUrl" name="baseUrl" value="<?php echo esc_attr($this->baseUrl) ?>" size="50" />
</p>
<p>
<strong><label for="outputDirectory"><?php echo __('Output Directory', 'static-html-output-plugin');?></label></strong>
<p>
<i>This defaults to your WordPress uploads directory. Ex: <?php $default_upload_dir = wp_upload_dir(); echo $default_upload_dir['path']; ?></i>
</p>
<input type="text" id="outputDirectory" name="outputDirectory" value="<?php echo esc_html($this->outputDirectory) ?>" size="50" />
</p>
<p>
<strong><label for="additionalUrls"><?php echo __('Additional Urls', 'static-html-output-plugin');?></label></strong>