diff --git a/library/StaticHtmlOutput.php b/library/StaticHtmlOutput.php index 1e992d41..5401f428 100644 --- a/library/StaticHtmlOutput.php +++ b/library/StaticHtmlOutput.php @@ -141,7 +141,6 @@ class StaticHtmlOutput { public function saveOptions() { if (!isset($_POST['action']) || 'generate' != $_POST['action']) { - error_log('didnt detect the generate action'); return; } @@ -154,8 +153,6 @@ class StaticHtmlOutput { ->setOption('static-export-settings', filter_input(INPUT_POST, 'staticExportSettings', FILTER_SANITIZE_URL)) ->save(); - error_log('saving options!!!'); - $message = 'Options have been updated successfully.'; $this->_view->setTemplate('message') @@ -205,23 +202,26 @@ class StaticHtmlOutput { $urlsQueue = array_unique(array_merge( array(trailingslashit($baseUrl)), $this->_getListOfLocalFilesByUrl(array(get_template_directory_uri())), - $this->_getListOfLocalFilesByUrl(explode("\n", filter_input(INPUT_POST, 'additionalUrls'))) + explode("\n", filter_input(INPUT_POST, 'additionalUrls')) )); - + $this->_exportLog = array(); + while (count($urlsQueue)) { $currentUrl = array_shift($urlsQueue); - - //echo "Processing ". $currentUrl."
"; - + $urlResponse = new StaticHtmlOutput_UrlRequest($currentUrl, filter_input(INPUT_POST, 'cleanMeta')); - $urlResponse->cleanup(); - - // Add current url to the list of processed urls - $this->_exportLog[$currentUrl] = true; - - + + if ($urlResponse->checkResponse() == 'FAIL') { + // that sucks, should add to error log... + } else { + // Add current url to the list of processed urls + $this->_exportLog[$currentUrl] = true; + } + + $urlResponse->cleanup(); + foreach ($urlResponse->extractAllUrls($baseUrl) as $newUrl) { if (!isset($this->_exportLog[$newUrl]) && $newUrl != $currentUrl && !in_array($newUrl,$urlsQueue)) { //echo "Adding ".$newUrl." to the list
"; @@ -291,9 +291,6 @@ class StaticHtmlOutput { // Where the files will be transferred to $dest = 's3://' . filter_input(INPUT_POST, 's3Bucket'); - error_log($source); - error_log($dest); - // Create a transfer object. $manager = new \Aws\S3\Transfer($s3Client, $source, $dest); @@ -367,13 +364,15 @@ class StaticHtmlOutput { protected function _getListOfLocalFilesByUrl(array $urls) { $files = array(); - + foreach ($urls as $url) { $directory = str_replace(home_url('/'), ABSPATH, $url); - + + // checking if url contains the WP site url at first position and is a directory if (stripos($url, home_url('/')) === 0 && is_dir($directory)) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); foreach ($iterator as $fileName => $fileObject) { + if (is_file($fileName)) { $pathinfo = pathinfo($fileName); if (isset($pathinfo['extension']) && !in_array($pathinfo['extension'], array('php', 'phtml', 'tpl'))) { @@ -381,9 +380,14 @@ class StaticHtmlOutput { } } } - } + } else { + // if is not empty, add full path to $files list + if ($url != '') { + array_push($files, $url); + } + } } - + return $files; } diff --git a/library/StaticHtmlOutput/UrlRequest.php b/library/StaticHtmlOutput/UrlRequest.php index d258b53d..6eb291a7 100644 --- a/library/StaticHtmlOutput/UrlRequest.php +++ b/library/StaticHtmlOutput/UrlRequest.php @@ -28,10 +28,21 @@ class StaticHtmlOutput_UrlRequest */ public function __construct($url, $cleanMeta = false) { - $this->_url = filter_var($url, FILTER_VALIDATE_URL); + $this->_url = filter_var(trim($url), FILTER_VALIDATE_URL); $this->_cleanMeta = $cleanMeta; + $response = wp_remote_get($this->_url,array('timeout'=>300)); //set a long time out - $this->_response = (is_wp_error($response) ? '' : $response); + + $this->_response = ''; + + if (is_wp_error($response)) { + error_log('WP_ERROR'); + error_log(print_r($response, true)); + $this->_response = 'FAIL'; + } else { + $this->_response = $response; + } + } /** @@ -42,6 +53,11 @@ class StaticHtmlOutput_UrlRequest { return $this->_url; } + + public function checkResponse() + { + return $this->_response; + } /** * Allows to override the HTTP response body diff --git a/views/options-page.phtml b/views/options-page.phtml index c78ee8c1..617aa4a9 100644 --- a/views/options-page.phtml +++ b/views/options-page.phtml @@ -213,7 +213,11 @@ jQuery(document).ready(function($){

- For a few themes, certain files may not be detected as part of the export process. Enter any such files here, one per line. + For a few themes, certain files may not be detected as part of the export process. Enter any such files here, one per line. + + Enter them as the full URL, including your WordPress site url, ie: +

http://localhost/wp-content/themes/twentyseventeen/banana.jpg
+http://172.17.0.3/my_pricelist.pdf