clean WP meta option is now configurable

This commit is contained in:
Leon Stafford 2016-12-27 22:04:57 +13:00
parent 0a0c957d26
commit eb6ae823d6
3 changed files with 18 additions and 6 deletions

View file

@ -116,6 +116,7 @@ class StaticHtmlOutput
->setOption('baseUrl', home_url())
->setOption('additionalUrls', '')
->setOption('generateZip', '')
->setOption('cleanMeta', '')
->setOption('retainStaticFiles', '')
->setOption('sendViaFTP', '')
->setOption('ftpServer', '')
@ -179,6 +180,7 @@ class StaticHtmlOutput
->assign('baseUrl', $this->_options->getOption('baseUrl'))
->assign('additionalUrls', $this->_options->getOption('additionalUrls'))
->assign('generateZip', $this->_options->getOption('generateZip'))
->assign('cleanMeta', $this->_options->getOption('cleanMeta'))
->assign('retainStaticFiles', $this->_options->getOption('retainStaticFiles'))
->assign('sendViaFTP', $this->_options->getOption('sendViaFTP'))
->assign('ftpServer', $this->_options->getOption('ftpServer'))
@ -211,6 +213,7 @@ class StaticHtmlOutput
->setOption('baseUrl', filter_input(INPUT_POST, 'baseUrl', FILTER_SANITIZE_URL))
->setOption('additionalUrls', filter_input(INPUT_POST, 'additionalUrls'))
->setOption('generateZip', filter_input(INPUT_POST, 'generateZip'))
->setOption('cleanMeta', filter_input(INPUT_POST, 'cleanMeta'))
->setOption('retainStaticFiles', filter_input(INPUT_POST, 'retainStaticFiles'))
->setOption('sendViaFTP', filter_input(INPUT_POST, 'sendViaFTP'))
->setOption('ftpServer', filter_input(INPUT_POST, 'ftpServer'))
@ -276,7 +279,7 @@ class StaticHtmlOutput
//echo "Processing ". $currentUrl."<br />";
$urlResponse = new StaticHtmlOutput_UrlRequest($currentUrl);
$urlResponse = new StaticHtmlOutput_UrlRequest($currentUrl, $this->_options->getOption('cleanMeta'));
$urlResponse->cleanup();
// Add current url to the list of processed urls

View file

@ -26,9 +26,10 @@ class StaticHtmlOutput_UrlRequest
* Constructor
* @param string $url URI resource
*/
public function __construct($url)
public function __construct($url, $cleanMeta = false)
{
$this->_url = filter_var($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);
}
@ -90,9 +91,12 @@ class StaticHtmlOutput_UrlRequest
{
if ($this->isHtml())
{
$responseBody = preg_replace('/<link rel=["\' ](pingback|alternate|EditURI|wlwmanifest|index|profile|prev)["\' ](.*?)>/si', '', $this->getResponseBody());
$responseBody = preg_replace('/<meta name=["\' ]generator["\' ](.*?)>/si', '', $responseBody);
$this->setResponseBody($responseBody);
if ($this->_cleanMeta)
{
$responseBody = preg_replace('/<link rel=["\' ](pingback|alternate|EditURI|wlwmanifest|index|profile|prev)["\' ](.*?)>/si', '', $this->getResponseBody());
$responseBody = preg_replace('/<meta name=["\' ]generator["\' ](.*?)>/si', '', $responseBody);
$this->setResponseBody($responseBody);
}
}
}
@ -128,4 +132,4 @@ class StaticHtmlOutput_UrlRequest
$this->setResponseBody($responseBody);
}
}
}
}

View file

@ -42,6 +42,11 @@
</p>
<textarea class="widefat" name="additionalUrls" id="additionalUrls" rows="5" cols="10"><?php echo esc_html($this->additionalUrls) ?></textarea>
</p>
<p>
<input name="cleanMeta" id="cleanMeta" value="1" type="checkbox" <?php if ($this->cleanMeta == 1) echo "checked"; ?> />
<label for="cleanMeta"><?= __('Strip out unneeded WordPress meta tags', 'static-html-output-plugin');?></label>
</p>
<p>
<input name="generateZip" id="generateZip" value="1" type="checkbox" <?php if ($this->generateZip == 1) echo "checked"; ?> />