mirror of
https://ghproxy.net/https://github.com/elementor/wp2static.git
synced 2025-08-30 13:43:54 +08:00
initial commit
This commit is contained in:
commit
8be5cbc5e0
19 changed files with 1745 additions and 0 deletions
33
css/wp-static-html-output.css
Normal file
33
css/wp-static-html-output.css
Normal file
|
@ -0,0 +1,33 @@
|
|||
@CHARSET "UTF-8";
|
||||
|
||||
div.postbox-container {
|
||||
float: none;
|
||||
padding: 0;
|
||||
min-width: 650px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.postbox div.inside {
|
||||
margin: 14px 18px 18px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.wpsho-report ul {
|
||||
list-style: disc;
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
.wpsho-report ul li {
|
||||
padding-left: 2em;
|
||||
}
|
||||
|
||||
.wpsho-export-log {
|
||||
height: 200px;
|
||||
overflow: auto;
|
||||
border: 1px solid #DFDFDF;
|
||||
color: #000;
|
||||
background: #fff;
|
||||
margin: 0 0 15px;
|
||||
padding: 3px 4px;
|
||||
width: 95%;
|
||||
}
|
BIN
languages/static-html-output-plugin-ja_UTF.mo
Normal file
BIN
languages/static-html-output-plugin-ja_UTF.mo
Normal file
Binary file not shown.
74
languages/static-html-output-plugin-ja_UTF.po
Normal file
74
languages/static-html-output-plugin-ja_UTF.po
Normal file
|
@ -0,0 +1,74 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WP Static HTML Output Plugin\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2012-08-11 05:47+0800\n"
|
||||
"PO-Revision-Date: 2012-08-11 05:48+0800\n"
|
||||
"Last-Translator: Leon Stafford <leon.stafford@mac.com>\n"
|
||||
"Language-Team: Leon Stafford <leon.stafford@mac.com>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e\n"
|
||||
"X-Poedit-Basepath: .\n"
|
||||
"X-Poedit-Language: Japanese\n"
|
||||
"X-Poedit-Country: JAPAN\n"
|
||||
"X-Poedit-SearchPath-0: ..\n"
|
||||
|
||||
#: ../wp-static-html-output.php:30
|
||||
msgid "Settings"
|
||||
msgstr "設定"
|
||||
|
||||
#: ../library/StaticHtmlOutput.php:135
|
||||
msgid "WP Static HTML Output"
|
||||
msgstr "WordPress静的HTML出力"
|
||||
|
||||
#: ../views/options-page.phtml:11
|
||||
msgid "WP Static HTML Output Plugin"
|
||||
msgstr "WordPress静的HTML出力プラグイン"
|
||||
|
||||
#: ../views/options-page.phtml:26
|
||||
msgid "Export Options"
|
||||
msgstr "静的HTML化設定"
|
||||
|
||||
#: ../views/options-page.phtml:29
|
||||
msgid "Base Url"
|
||||
msgstr "ベースURL"
|
||||
|
||||
#: ../views/options-page.phtml:34
|
||||
msgid "Additional Urls"
|
||||
msgstr "その他のファイル"
|
||||
|
||||
#: ../views/options-page.phtml:40
|
||||
msgid "Generate Zip archive of whole site"
|
||||
msgstr "サイト全体をZIPファイルに圧縮する"
|
||||
|
||||
#: ../views/options-page.phtml:45
|
||||
msgid "Retain generated static files on server"
|
||||
msgstr "現場サーバーに書き出されたHTMLファイルを保存する"
|
||||
|
||||
#: ../views/options-page.phtml:50
|
||||
msgid "Transfer files via FTP"
|
||||
msgstr "FTPサーバーに送信する"
|
||||
|
||||
#: ../views/options-page.phtml:51
|
||||
msgid "FTP functionality is in Beta testing: For large sites, page may seem unresponsive until complete. If in doubt, check your remote FTP directory for activity."
|
||||
msgstr "FTPサーバーに送信する機能がまだテスト中なので不安定の場合もございます"
|
||||
|
||||
#: ../views/options-page.phtml:55
|
||||
msgid "FTP Server"
|
||||
msgstr "FTPサーバーアドレス"
|
||||
|
||||
#: ../views/options-page.phtml:60
|
||||
msgid "FTP Username"
|
||||
msgstr "FTPユーザ名"
|
||||
|
||||
#: ../views/options-page.phtml:65
|
||||
msgid "FTP Password"
|
||||
msgstr "FTPパスワード"
|
||||
|
||||
#: ../views/options-page.phtml:70
|
||||
msgid "FTP Remote Path"
|
||||
msgstr "FTPのリモートパス"
|
||||
|
17
languages/static-html-output-plugin.pot
Normal file
17
languages/static-html-output-plugin.pot
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Copyright (C) 2012
|
||||
# This file is distributed under the same license as the package.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: http://wordpress.org/tag/static-html-output-plugin\n"
|
||||
"POT-Creation-Date: 2012-08-10 20:50:49+00:00\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"PO-Revision-Date: 2012-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
||||
#: wp-static-html-output.php:29
|
||||
msgid "Settings"
|
||||
msgstr ""
|
2
library/.htaccess
Normal file
2
library/.htaccess
Normal file
|
@ -0,0 +1,2 @@
|
|||
Order deny,allow
|
||||
Deny from all
|
466
library/FTP/ftp.php
Normal file
466
library/FTP/ftp.php
Normal file
|
@ -0,0 +1,466 @@
|
|||
<?php
|
||||
/**
|
||||
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
* Version 2, December 2004
|
||||
*
|
||||
* Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
*
|
||||
* Everyone is permitted to copy and distribute verbatim or modified
|
||||
* copies of this license document, and changing it is allowed as long
|
||||
* as the name is changed.
|
||||
*
|
||||
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
* TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
*
|
||||
* 0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Ftp class for recursive upload and download files via ftp protocol
|
||||
*
|
||||
* @author Kristian Feldsam - iKFSystems, info@ikfsystems.sk
|
||||
* @web http://www.ikfsystems.sk
|
||||
*/
|
||||
|
||||
class ftp {
|
||||
private $conn, $login_result, $logData, $ftpUser, $ftpPass, $ftpHost, $retry, $ftpPasv, $ftpMode, $verbose, $logPath, $createMask;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Construct method
|
||||
*
|
||||
* @param array keys[passive_mode(true|false)|transfer_mode(FTP_ASCII|FTP_BINARY)|reattempts(int)|log_path|verbose(true|false)|create_mask(default:0777)]
|
||||
* @return void
|
||||
*/
|
||||
function __construct($o)
|
||||
{
|
||||
$this->retry = (isset($o['reattempts'])) ? $o['reattempts'] : 3;
|
||||
$this->ftpPasv = (isset($o['passive_mode'])) ? $o['passive_mode'] : true;
|
||||
$this->ftpMode = (isset($o['transfer_mode'])) ? $o['transfer_mode'] : FTP_BINARY;
|
||||
$this->verbose = (isset($o['verbose'])) ? $o['verbose'] : false;
|
||||
$this->logPath = (isset($o['log_path'])) ? $o['log_path'] : false;
|
||||
$this->createMask = (isset($o['create_mask'])) ? $o['create_mask'] : 0777;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Connection method
|
||||
*
|
||||
* @param string hostname
|
||||
* @param string username
|
||||
* @param string password
|
||||
* @return void
|
||||
*/
|
||||
public function conn($hostname, $username, $password)
|
||||
{
|
||||
$this->ftpUser = $username;
|
||||
$this->ftpPass = $password;
|
||||
$this->ftpHost = $hostname;
|
||||
|
||||
$this->initConn();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Init connection method - connect to ftp server and set passive mode
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function initConn()
|
||||
{
|
||||
$this->conn = ftp_connect($this->ftpHost);
|
||||
$this->login_result = ftp_login($this->conn, $this->ftpUser, $this->ftpPass);
|
||||
if($this->conn && $this->login_result)
|
||||
{
|
||||
ftp_pasv($this->conn, $this->ftpPasv);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Put method - upload files(folders) to ftp server
|
||||
*
|
||||
* @param string path to destionation file/folder on ftp
|
||||
* @param string path to source file/folder on local disk
|
||||
* @param int only for identify reattempt, dont use this param
|
||||
* @return bool
|
||||
*/
|
||||
public function put($destinationFile, $sourceFile, $retry = 0)
|
||||
{
|
||||
if(file_exists($sourceFile))
|
||||
{
|
||||
if(!$this->isDir($sourceFile, true))
|
||||
{
|
||||
$this->createSubDirs($destinationFile);
|
||||
if(!ftp_put($this->conn, $destinationFile, $sourceFile, $this->ftpMode))
|
||||
{
|
||||
$retry++;
|
||||
if($retry > $this->retry)
|
||||
{
|
||||
$this->logData('Error when uploading file: '.$sourceFile.' => '.$destinationFile, 'error');
|
||||
return false;
|
||||
}
|
||||
if($this->verbose) echo 'Retry: '.$retry."\n";
|
||||
$this->reconnect();
|
||||
$this->put($destinationFile, $sourceFile, $retry);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->logData($sourceFile.' => '.$destinationFile, 'ok');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->recursive($destinationFile, $sourceFile, 'put');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get method - download files(folders) from ftp server
|
||||
*
|
||||
* @param string path to destionation file/folder on local disk
|
||||
* @param string path to source file/folder on ftp server
|
||||
* @param int only for identify reattempt, dont use this param
|
||||
* @return bool
|
||||
*/
|
||||
public function get($destinationFile, $sourceFile, $retry = 0)
|
||||
{
|
||||
if(!$this->isDir($sourceFile, false))
|
||||
{
|
||||
if($this->verbose)echo $sourceFile.' => '.$destinationFile."\n";
|
||||
$this->createSubDirs($destinationFile, false, true);
|
||||
if(!ftp_get($this->conn, $destinationFile, $sourceFile, $this->ftpMode))
|
||||
{
|
||||
$retry++;
|
||||
if($retry > $this->retry)
|
||||
{
|
||||
$this->logData('Error when downloading file: '.$sourceFile.' => '.$destinationFile, 'error');
|
||||
return false;
|
||||
}
|
||||
if($this->verbose) echo 'Retry: '.$retry."\n";
|
||||
$this->reconnect();
|
||||
$this->get($destinationFile, $sourceFile, $retry);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->logData($sourceFile.' => '.$destinationFile, 'ok');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->recursive($destinationFile, $sourceFile, 'get');
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Make dir method - make folder on ftp server or local disk
|
||||
*
|
||||
* @param string path to destionation folder on ftp or local disk
|
||||
* @param bool true for local, false for ftp
|
||||
* @return bool
|
||||
*/
|
||||
public function makeDir($dir, $local = false)
|
||||
{
|
||||
if($local)
|
||||
{
|
||||
if(!file_exists($dir) && !is_dir($dir))return mkdir($dir, $this->createMask); else return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ftp_mkdir($this->conn,$dir);
|
||||
return ftp_chmod($this->conn, $this->createMask, $dir);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cd up method - change working dir up
|
||||
*
|
||||
* @param bool true for local, false for ftp
|
||||
* @return bool
|
||||
*/
|
||||
public function cdUp($local)
|
||||
{
|
||||
return $local ? chdir('..') : ftp_cdup($this->conn);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List contents of dir method - list all files in specified directory
|
||||
*
|
||||
* @param string path to destionation folder on ftp or local disk
|
||||
* @param bool true for local, false for ftp
|
||||
* @return bool
|
||||
*/
|
||||
public function listFiles($file, $local = false)
|
||||
{
|
||||
if(!$this->isDir($file, $local))return false;
|
||||
if($local)
|
||||
{
|
||||
return scandir($file);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!preg_match('/\//', $file))
|
||||
{
|
||||
return ftp_nlist($this->conn, $file);
|
||||
}else
|
||||
{
|
||||
$dirs = explode('/', $file);
|
||||
foreach($dirs as $dir)
|
||||
{
|
||||
$this->changeDir($dir, $local);
|
||||
}
|
||||
$last = count($dirs)-1;
|
||||
$this->cdUp($local);
|
||||
$list = ftp_nlist($this->conn, $dirs[$last]);
|
||||
$i = 0;
|
||||
foreach($dirs as $dir)
|
||||
{
|
||||
if($i < $last) $this->cdUp($local);
|
||||
$i++;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns current working directory
|
||||
*
|
||||
* @param bool true for local, false for ftp
|
||||
* @return bool
|
||||
*/
|
||||
public function pwd($local = false)
|
||||
{
|
||||
return $local ? getcwd() : ftp_pwd($this->conn);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Change current working directory
|
||||
*
|
||||
* @param string dir name
|
||||
* @param bool true for local, false for ftp
|
||||
* @return bool
|
||||
*/
|
||||
public function changeDir($dir, $local = false)
|
||||
{
|
||||
return $local ? chdir($dir) : @ftp_chdir($this->conn, $dir);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create subdirectories
|
||||
*
|
||||
* @param string path
|
||||
* @param bool
|
||||
* @param bool true for local, false for ftp
|
||||
* @param bool change current working directory back
|
||||
* @return void
|
||||
*/
|
||||
function createSubDirs($file, $last = false, $local = false, $chDirBack = true)
|
||||
{
|
||||
if(preg_match('/\//',$file))
|
||||
{
|
||||
$origin = $this->pwd($local);
|
||||
if(!$last) $file = substr($file, 0, strrpos($file,'/'));
|
||||
$dirs = explode('/',$file);
|
||||
foreach($dirs as $dir)
|
||||
{
|
||||
if(!$this->isDir($dir, $local))
|
||||
{
|
||||
$this->makeDir($dir, $local);
|
||||
$this->changeDir($dir, $local);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->changeDir($dir, $local);
|
||||
}
|
||||
}
|
||||
if($chDirBack) $this->changeDir($origin, $local);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Recursion
|
||||
*
|
||||
* @param string destionation file/folder
|
||||
* @param string source file/folder
|
||||
* @param string put or get
|
||||
* @return void
|
||||
*/
|
||||
function recursive($destinationFile, $sourceFile, $mode)
|
||||
{
|
||||
$local = ($mode == 'put') ? true : false;
|
||||
$list = $this->listFiles($sourceFile, $local);
|
||||
if($this->verbose) echo "\n".'Folder: '.$sourceFile."\n";
|
||||
if($this->verbose) print_r($list);
|
||||
$x=0;
|
||||
$z=0;
|
||||
foreach($list as $file)
|
||||
{
|
||||
if($file == '.' || $file == '..')continue;
|
||||
$destFile = $destinationFile.'/'.$file;
|
||||
$srcFile = $sourceFile.'/'.$file;
|
||||
if($this->isDir($srcFile,$local))
|
||||
{
|
||||
$this->recursive($destFile, $srcFile, $mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($local)
|
||||
{
|
||||
$this->put($destFile, $srcFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->get($destFile, $srcFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Check if is dir
|
||||
*
|
||||
* @param string path to folder
|
||||
* @return bool
|
||||
*/
|
||||
public function isDir($dir, $local)
|
||||
{
|
||||
if($local) return is_dir($dir);
|
||||
if($this->changeDir($dir))return $this->cdUp(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Save log data to array
|
||||
*
|
||||
* @param string data
|
||||
* @param string type(error|ok)
|
||||
* @return void
|
||||
*/
|
||||
function logData($data, $type)
|
||||
{
|
||||
$this->logData[$type][] = $data;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get log data array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLogData()
|
||||
{
|
||||
return $this->logData;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Save log data to file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function logDataToFiles()
|
||||
{
|
||||
if(!$this->logPath) return false;
|
||||
$ftp->makeDir($this->logPath, true);
|
||||
$log = $ftp->getLogData();
|
||||
$sep = "\n".date('y-m-d H-i-s').' ';
|
||||
$logc = date('y-m-d H-i-s').' '.join($sep,$log['error'])."\n";
|
||||
$this->addToFile($this->logPath.'/'.$config->name.'-error.log',$logc);
|
||||
$logc = date('y-m-d H-i-s').' '.join($sep,$log['ok'])."\n";
|
||||
$this->addToFile($this->logPath.'/'.$config->name.'-ok.log',$logc);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reconnect method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reconnect()
|
||||
{
|
||||
$this->closeConn();
|
||||
$this->initConn();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close connection method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function closeConn()
|
||||
{
|
||||
return ftp_close($this->conn);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Write to file
|
||||
*
|
||||
* @param string path to file
|
||||
* @param string text
|
||||
* @param string fopen mode
|
||||
* @return void
|
||||
*/
|
||||
function addToFile($file, $ins, $mode = 'a')
|
||||
{
|
||||
$fp = fopen($file, $mode);
|
||||
fwrite($fp,$ins);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Destruct method - close connection and save log data to file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __destruct()
|
||||
{
|
||||
$this->closeConn();
|
||||
$this->logDataToFiles();
|
||||
}
|
||||
}
|
||||
|
||||
// END ftp class
|
||||
|
||||
/* End of file ftp.php */
|
||||
/* Location: ftp.php */
|
434
library/StaticHtmlOutput.php
Normal file
434
library/StaticHtmlOutput.php
Normal file
|
@ -0,0 +1,434 @@
|
|||
<?php
|
||||
/**
|
||||
* @package WP Static HTML Output
|
||||
*
|
||||
* Copyright (c) 2011 Leon Stafford
|
||||
*/
|
||||
|
||||
/**
|
||||
* WP Static HTML Output Plugin
|
||||
*/
|
||||
class StaticHtmlOutput
|
||||
{
|
||||
/**
|
||||
* Plugin version
|
||||
*/
|
||||
const VERSION = '1.1.2';
|
||||
|
||||
/**
|
||||
* The lookup key used to locate the options record in the wp_options table
|
||||
*/
|
||||
const OPTIONS_KEY = 'wp-static-html-output-options';
|
||||
|
||||
/**
|
||||
* The hook used in all actions and filters
|
||||
*/
|
||||
const HOOK = 'wp-static-html-output';
|
||||
|
||||
/**
|
||||
* Singleton instance
|
||||
* @var StaticHtmlOutput
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* An instance of the options structure containing all options for this plugin
|
||||
* @var StaticHtmlOutput_Options
|
||||
*/
|
||||
protected $_options = null;
|
||||
|
||||
/**
|
||||
* View object
|
||||
* @var StaticHtmlOutput_View
|
||||
*/
|
||||
protected $_view = null;
|
||||
|
||||
/**
|
||||
* Export log (list of processed urls)
|
||||
* @var array
|
||||
*/
|
||||
protected $_exportLog = array();
|
||||
|
||||
/**
|
||||
* Singleton pattern implementation makes "new" unavailable
|
||||
* @return void
|
||||
*/
|
||||
protected function __construct()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Singleton pattern implementation makes "clone" unavailable
|
||||
* @return void
|
||||
*/
|
||||
protected function __clone()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Returns an instance of WP Static HTML Output Plugin
|
||||
* Singleton pattern implementation
|
||||
* @return StaticHtmlOutput
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (null === self::$_instance)
|
||||
{
|
||||
self::$_instance = new self();
|
||||
self::$_instance->_options = new StaticHtmlOutput_Options(self::OPTIONS_KEY);
|
||||
self::$_instance->_view = new StaticHtmlOutput_View();
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes singleton instance and assigns hooks callbacks
|
||||
* @param string $bootstrapFile
|
||||
* @return StaticHtmlOutput
|
||||
*/
|
||||
public static function init($bootstrapFile)
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
|
||||
// Activation
|
||||
register_activation_hook($bootstrapFile, array($instance, 'activate'));
|
||||
|
||||
// Backend hooks and action callbacks
|
||||
if (is_admin())
|
||||
{
|
||||
add_action('admin_menu', array($instance, 'registerOptionsPage'));
|
||||
add_action(self::HOOK . '-saveOptions', array($instance, 'saveOptions'));
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs activation
|
||||
* @return void
|
||||
*/
|
||||
public function activate()
|
||||
{
|
||||
// Not installed?
|
||||
if (null === $this->_options->getOption('version'))
|
||||
{
|
||||
$this->_options
|
||||
->setOption('version', self::VERSION)
|
||||
->setOption('baseUrl', home_url())
|
||||
->setOption('additionalUrls', '')
|
||||
->setOption('generateZip', '')
|
||||
->setOption('retainStaticFiles', '')
|
||||
->setOption('sendViaFTP', '')
|
||||
->setOption('ftpServer', '')
|
||||
->setOption('ftpUsername', '')
|
||||
->setOption('ftpPassword', '')
|
||||
->setOption('ftpRemotePath', '')
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds menu navigation items for this plugin
|
||||
* @return void
|
||||
*/
|
||||
public function registerOptionsPage()
|
||||
{
|
||||
$page = add_submenu_page('tools.php', __('WP Static HTML Output', 'static-html-output-plugin'), __('WP Static HTML Output', 'static-html-output-plugin'), 'manage_options', self::HOOK . '-options', array($this, 'renderOptionsPage'));
|
||||
add_action('admin_print_styles-' . $page, array($this, 'enqueueAdminStyles'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues CSS files required for this plugin
|
||||
* @return void
|
||||
*/
|
||||
public function enqueueAdminStyles()
|
||||
{
|
||||
$pluginDirUrl = plugin_dir_url(dirname(__FILE__));
|
||||
wp_enqueue_style(self::HOOK . '-admin', $pluginDirUrl . '/css/wp-static-html-output.css');
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the general options page.
|
||||
* Fires saveOptions action hook.
|
||||
* @return void
|
||||
*/
|
||||
public function renderOptionsPage()
|
||||
{
|
||||
// Check system requirements
|
||||
$uploadDir = wp_upload_dir();
|
||||
$uploadsFolderWritable = $uploadDir && is_writable($uploadDir['path']);
|
||||
$supportsZipArchives = extension_loaded('zip');
|
||||
$permalinksStructureDefined = strlen(get_option('permalink_structure'));
|
||||
|
||||
if (!$uploadsFolderWritable || !$supportsZipArchives ||!$permalinksStructureDefined)
|
||||
{
|
||||
$this->_view
|
||||
->setTemplate('system-requirements')
|
||||
->assign('uploadsFolderWritable', $uploadsFolderWritable)
|
||||
->assign('supportsZipArchives', $supportsZipArchives)
|
||||
->assign('permalinksStructureDefined', $permalinksStructureDefined)
|
||||
->render();
|
||||
}
|
||||
else
|
||||
{
|
||||
do_action(self::HOOK . '-saveOptions');
|
||||
|
||||
$this->_view
|
||||
->setTemplate('options-page')
|
||||
->assign('exportLog', $this->_exportLog)
|
||||
->assign('baseUrl', $this->_options->getOption('baseUrl'))
|
||||
->assign('additionalUrls', $this->_options->getOption('additionalUrls'))
|
||||
->assign('generateZip', $this->_options->getOption('generateZip'))
|
||||
->assign('retainStaticFiles', $this->_options->getOption('retainStaticFiles'))
|
||||
->assign('sendViaFTP', $this->_options->getOption('sendViaFTP'))
|
||||
->assign('ftpServer', $this->_options->getOption('ftpServer'))
|
||||
->assign('ftpUsername', $this->_options->getOption('ftpUsername'))
|
||||
->assign('ftpRemotePath', $this->_options->getOption('ftpRemotePath'))
|
||||
->assign('onceAction', self::HOOK . '-options')
|
||||
->render();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the options
|
||||
* @return void
|
||||
*/
|
||||
public function saveOptions()
|
||||
{
|
||||
// Protection
|
||||
if (!isset($_POST['action']) || 'generate' != $_POST['action'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!check_admin_referer(self::HOOK . '-options') || !current_user_can('manage_options'))
|
||||
{
|
||||
exit('You cannot change WP Static HTML Output Plugin options.');
|
||||
}
|
||||
|
||||
// Save options
|
||||
$this->_options
|
||||
->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('retainStaticFiles', filter_input(INPUT_POST, 'retainStaticFiles'))
|
||||
->setOption('sendViaFTP', filter_input(INPUT_POST, 'sendViaFTP'))
|
||||
->setOption('ftpServer', filter_input(INPUT_POST, 'ftpServer'))
|
||||
->setOption('ftpUsername', filter_input(INPUT_POST, 'ftpUsername'))
|
||||
->setOption('ftpRemotePath', filter_input(INPUT_POST, 'ftpRemotePath'))
|
||||
->save();
|
||||
|
||||
// Generate archive
|
||||
$archiveUrl = $this->_generateArchive();
|
||||
|
||||
// Render the message
|
||||
if (is_wp_error($archiveUrl))
|
||||
{
|
||||
$message = 'Error: ' . $archiveUrl->get_error_code;
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = sprintf('Archive created successfully: <a href="%s">Download archive</a>', $archiveUrl);
|
||||
if ($this->_options->getOption('retainStaticFiles') == 1)
|
||||
{
|
||||
$message .= sprintf('<br />Static files retained at: %s/', str_replace(home_url(),'',substr($archiveUrl,0,-4)));
|
||||
}
|
||||
}
|
||||
|
||||
$this->_view->setTemplate('message')
|
||||
->assign('message', $message)
|
||||
->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates ZIP archive
|
||||
* @return string|WP_Error
|
||||
*/
|
||||
protected function _generateArchive()
|
||||
{
|
||||
global $blog_id;
|
||||
set_time_limit(0);
|
||||
|
||||
// Prepare archive directory
|
||||
$uploadDir = wp_upload_dir();
|
||||
$exporter = wp_get_current_user();
|
||||
$archiveName = $uploadDir['path'] . '/' . self::HOOK . '-' . $blog_id . '-' . time() . '-' . $exporter->user_login;
|
||||
$archiveDir = $archiveName . '/';
|
||||
if (!file_exists($archiveDir))
|
||||
{
|
||||
wp_mkdir_p($archiveDir);
|
||||
}
|
||||
|
||||
// Prepare queue
|
||||
$baseUrl = untrailingslashit(home_url());
|
||||
$newBaseUrl = untrailingslashit($this->_options->getOption('baseUrl'));
|
||||
$urlsQueue = array_unique(array_merge(
|
||||
array(trailingslashit($baseUrl)),
|
||||
$this->_getListOfLocalFilesByUrl(array(get_template_directory_uri())),
|
||||
$this->_getListOfLocalFilesByUrl(explode("\n", $this->_options->getOption('additionalUrls')))
|
||||
));
|
||||
|
||||
// Process queue
|
||||
$this->_exportLog = array();
|
||||
while (count($urlsQueue))
|
||||
{
|
||||
$currentUrl = array_shift($urlsQueue);
|
||||
|
||||
//echo "Processing ". $currentUrl."<br />";
|
||||
|
||||
$urlResponse = new StaticHtmlOutput_UrlRequest($currentUrl);
|
||||
$urlResponse->cleanup();
|
||||
|
||||
// Add current url to the list of processed urls
|
||||
$this->_exportLog[$currentUrl] = true;
|
||||
|
||||
|
||||
// Add new urls to the queue
|
||||
|
||||
foreach ($urlResponse->extractAllUrls($baseUrl) as $newUrl)
|
||||
{
|
||||
if (!isset($this->_exportLog[$newUrl]) && $newUrl != $currentUrl && !in_array($newUrl,$urlsQueue))
|
||||
{
|
||||
//echo "Adding ".$newUrl." to the list<br />";
|
||||
$urlsQueue[] = $newUrl;
|
||||
}
|
||||
}
|
||||
|
||||
// Save url data
|
||||
$urlResponse->replaceBaseUlr($baseUrl, $newBaseUrl);
|
||||
$this->_saveUrlData($urlResponse, $archiveDir);
|
||||
|
||||
}
|
||||
|
||||
// Create archive object
|
||||
$tempZip = $archiveName . '.tmp';
|
||||
$zipArchive = new ZipArchive();
|
||||
if ($zipArchive->open($tempZip, ZIPARCHIVE::CREATE) !== true)
|
||||
{
|
||||
return new WP_Error('Could not create archive');
|
||||
}
|
||||
|
||||
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($archiveDir));
|
||||
foreach ($iterator as $fileName => $fileObject)
|
||||
{
|
||||
|
||||
$baseName = basename($fileName);
|
||||
if($baseName != '.' && $baseName != '..')
|
||||
{
|
||||
if (!$zipArchive->addFile(realpath($fileName), str_replace($archiveDir, '', $fileName)))
|
||||
{
|
||||
return new WP_Error('Could not add file: ' . $fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$zipArchive->close();
|
||||
rename($tempZip, $archiveName . '.zip');
|
||||
|
||||
if($this->_options->getOption('sendViaFTP') == 1)
|
||||
{
|
||||
|
||||
//crude FTP addition
|
||||
require_once '/home/leon/leonwp/wp-content/plugins/static-html-output-plugin/library/FTP/ftp.php';
|
||||
$config = array();//keys[passive_mode(true|false)|transfer_mode(FTP_ASCII|FTP_BINARY)|reattempts(int)|log_path|verbose(true|false)|create_mask(default:0777)]
|
||||
$ftp = new ftp($config);
|
||||
$ftp->conn($this->_options->getOption('ftpServer'), $this->_options->getOption('ftpUsername'), filter_input(INPUT_POST, 'ftpPassword'));
|
||||
|
||||
//Crude FTP
|
||||
$ftp->put($this->_options->getOption('ftpRemotePath'), $archiveName . '/');
|
||||
|
||||
unset($ftp);
|
||||
}
|
||||
|
||||
// Remove temporary files unless user requested to keep or needed for FTP transfer
|
||||
if ($this->_options->getOption('retainStaticFiles') != 1)
|
||||
{
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($archiveDir), RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($iterator as $fileName => $fileObject)
|
||||
{
|
||||
|
||||
// Remove file
|
||||
if ($fileObject->isDir())
|
||||
{
|
||||
// Ignore special dirs
|
||||
$dirName = basename($fileName);
|
||||
if($dirName != '.' && $dirName != '..') {
|
||||
rmdir($fileName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink($fileName);
|
||||
}
|
||||
}
|
||||
rmdir($archiveDir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return str_replace(ABSPATH, trailingslashit(home_url()), $archiveName . '.zip');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of local files
|
||||
* @param array $urls
|
||||
* @return array
|
||||
*/
|
||||
protected function _getListOfLocalFilesByUrl(array $urls)
|
||||
{
|
||||
$files = array();
|
||||
|
||||
foreach ($urls as $url)
|
||||
{
|
||||
$directory = str_replace(home_url('/'), ABSPATH, $url);
|
||||
|
||||
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')))
|
||||
{
|
||||
array_push($files, home_url(str_replace(ABSPATH, '', $fileName)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves url data in temporary archive directory
|
||||
* @param StaticHtmlOutput_UrlRequest $url
|
||||
* @param string $archiveDir
|
||||
* @return void
|
||||
*/
|
||||
protected function _saveUrlData(StaticHtmlOutput_UrlRequest $url, $archiveDir)
|
||||
{
|
||||
$urlInfo = parse_url($url->getUrl());
|
||||
$pathInfo = pathinfo(isset($urlInfo['path']) && $urlInfo['path'] != '/' ? $urlInfo['path'] : 'index.html');
|
||||
|
||||
// Prepare file directory and create it if it doesn't exist
|
||||
$fileDir = $archiveDir . (isset($pathInfo['dirname']) ? $pathInfo['dirname'] : '');
|
||||
if (empty($pathInfo['extension']) && $pathInfo['basename'] == $pathInfo['filename'])
|
||||
{
|
||||
$fileDir .= '/' . $pathInfo['basename'];
|
||||
$pathInfo['filename'] = 'index';
|
||||
}
|
||||
if (!file_exists($fileDir))
|
||||
{
|
||||
wp_mkdir_p($fileDir);
|
||||
}
|
||||
|
||||
// Prepare file name and save file contents
|
||||
$fileExtension = ($url->isHtml() || !isset($pathInfo['extension']) ? 'html' : $pathInfo['extension']);
|
||||
$fileName = $fileDir . '/' . $pathInfo['filename'] . '.' . $fileExtension;
|
||||
file_put_contents($fileName, $url->getResponseBody());
|
||||
}
|
||||
}
|
12
library/StaticHtmlOutput/Exception.php
Normal file
12
library/StaticHtmlOutput/Exception.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* @package WP Static HTML Output
|
||||
*
|
||||
* Copyright (c) 2011 Leon Stafford
|
||||
*/
|
||||
|
||||
/**
|
||||
* WP Static HTML Output exceptions class
|
||||
*/
|
||||
class StaticHtmlOutput_Exception extends Exception
|
||||
{}
|
115
library/StaticHtmlOutput/Options.php
Normal file
115
library/StaticHtmlOutput/Options.php
Normal file
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/**
|
||||
* @package WP Static HTML Output
|
||||
*
|
||||
* Copyright (c) 2011 Leon Stafford
|
||||
*/
|
||||
|
||||
/**
|
||||
* WP Static HTML Output options management class
|
||||
*/
|
||||
class StaticHtmlOutput_Options
|
||||
{
|
||||
/**
|
||||
* Options array
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* Defines options record in the wp_options table
|
||||
* @var string
|
||||
*/
|
||||
protected $_optionKey = null;
|
||||
|
||||
/**
|
||||
* Performs initializion of the options structure
|
||||
*
|
||||
* @param string $optionKey The options key name
|
||||
*/
|
||||
public function __construct($optionKey)
|
||||
{
|
||||
$options = get_option($optionKey);
|
||||
|
||||
if (false === $options)
|
||||
{
|
||||
$options = array();
|
||||
}
|
||||
|
||||
$this->_options = $options;
|
||||
$this->_optionKey = $optionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the option identified by $name with the value provided in $value
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param mixed $value The option value
|
||||
* @return StaticHtmlOutput_Options
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->_options[$name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the option identified by $name with the value provided in $value
|
||||
*
|
||||
* This is an alias for {@link __set()}
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param mixed $value The option value
|
||||
* @return StaticHtmlOutput_Options
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
return $this->__set($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of the option identified by $name
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
$value = array_key_exists($name, $this->_options) ? $this->_options[$name] : null;
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of the option identified by $name
|
||||
*
|
||||
* This is an alias for {@link __get()}
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
return $this->__get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the internal options data to the wp_options table using the stored $optionKey value as the key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
return update_option($this->_optionKey, $this->_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the internal options data from the wp_options table.
|
||||
* This method is intended to be used as part of the uninstall process.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
return delete_option($this->_optionKey);
|
||||
}
|
||||
}
|
131
library/StaticHtmlOutput/UrlRequest.php
Normal file
131
library/StaticHtmlOutput/UrlRequest.php
Normal file
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
/**
|
||||
* @package WP Static HTML Output
|
||||
*
|
||||
* Copyright (c) 2011 Leon Stafford
|
||||
*/
|
||||
|
||||
/**
|
||||
* Url request class
|
||||
*/
|
||||
class StaticHtmlOutput_UrlRequest
|
||||
{
|
||||
/**
|
||||
* The URI resource
|
||||
* @var string
|
||||
*/
|
||||
protected $_url;
|
||||
|
||||
/**
|
||||
* The raw response from the HTTP request
|
||||
* @var string
|
||||
*/
|
||||
protected $_response;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param string $url URI resource
|
||||
*/
|
||||
public function __construct($url)
|
||||
{
|
||||
$this->_url = filter_var($url, FILTER_VALIDATE_URL);
|
||||
$response = wp_remote_get($this->_url,array('timeout'=>300)); //set a long time out
|
||||
$this->_response = (is_wp_error($response) ? '' : $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sanitized url
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to override the HTTP response body
|
||||
* @param string $newBody
|
||||
* @return void
|
||||
*/
|
||||
public function setResponseBody($newBody)
|
||||
{
|
||||
if (is_array($this->_response))
|
||||
{
|
||||
$this->_response['body'] = $newBody;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTTP response body
|
||||
* @return string
|
||||
*/
|
||||
public function getResponseBody()
|
||||
{
|
||||
return isset($this->_response['body']) ? $this->_response['body'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content type
|
||||
* @return string
|
||||
*/
|
||||
public function getContentType()
|
||||
{
|
||||
return isset($this->_response['headers']['content-type']) ? $this->_response['headers']['content-type'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if content type is html
|
||||
* @return bool
|
||||
*/
|
||||
public function isHtml()
|
||||
{
|
||||
return stripos($this->getContentType(), 'html') !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes WordPress-specific meta tags
|
||||
* @return void
|
||||
*/
|
||||
public function cleanup()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the list of unique urls
|
||||
* @param string $baseUrl Base url of site. Used to extract urls that relate only to the current site.
|
||||
* @return array
|
||||
*/
|
||||
public function extractAllUrls($baseUrl)
|
||||
{
|
||||
$allUrls = array();
|
||||
|
||||
if ($this->isHtml() && preg_match_all('/' . str_replace('/', '\/', $baseUrl) . '[^"\'#\? ]+/i', $this->_response['body'], $matches))
|
||||
{
|
||||
$allUrls = array_unique($matches[0]);
|
||||
}
|
||||
|
||||
return $allUrls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces base url
|
||||
* @param string $oldBaseUrl
|
||||
* @param string $newBaseUrl
|
||||
* @return void
|
||||
*/
|
||||
public function replaceBaseUlr($oldBaseUrl, $newBaseUrl)
|
||||
{
|
||||
if ($this->isHtml())
|
||||
{
|
||||
$responseBody = str_replace($oldBaseUrl, $newBaseUrl, $this->getResponseBody());
|
||||
$responseBody = str_replace('<head>', "<head>\n<base href=\"" . esc_attr($newBaseUrl) . "\" />\n", $responseBody);
|
||||
$this->setResponseBody($responseBody);
|
||||
}
|
||||
}
|
||||
}
|
146
library/StaticHtmlOutput/View.php
Normal file
146
library/StaticHtmlOutput/View.php
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
/**
|
||||
* @package WP Static HTML Output
|
||||
*
|
||||
* Copyright (c) 2011 Leon Stafford
|
||||
*/
|
||||
|
||||
/**
|
||||
* WP Static HTML Output view class
|
||||
*/
|
||||
class StaticHtmlOutput_View
|
||||
{
|
||||
/**
|
||||
* View variables array
|
||||
* @var array
|
||||
*/
|
||||
protected $_variables = array();
|
||||
|
||||
/**
|
||||
* Absolute path for view
|
||||
* @var string
|
||||
*/
|
||||
protected $_path = null;
|
||||
|
||||
/**
|
||||
* Base directory for views
|
||||
* @var string
|
||||
*/
|
||||
protected $_directory = 'views';
|
||||
|
||||
/**
|
||||
* View script extension
|
||||
* @var string
|
||||
*/
|
||||
protected $_extension = '.phtml';
|
||||
|
||||
/**
|
||||
* Template file name to render
|
||||
* @var string
|
||||
*/
|
||||
protected $_template = null;
|
||||
|
||||
/**
|
||||
* Performs initialization of the absolute path for views
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Looking for a basic directory where plugin resides
|
||||
list($pluginDir) = explode('/', plugin_basename(__FILE__));
|
||||
|
||||
// making up an absolute path to views directory
|
||||
$pathArray = array(WP_PLUGIN_DIR, $pluginDir, $this->_directory);
|
||||
|
||||
$this->_path = implode('/', $pathArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a template filename that will be used later in render() method.
|
||||
* Performs a reset of the view variables
|
||||
*
|
||||
* @param string $template The template filename, without extension
|
||||
* @return StaticHtmlOutput_View
|
||||
*/
|
||||
public function setTemplate($template)
|
||||
{
|
||||
$this->_template = $template;
|
||||
$this->_variables = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the view variable identified by $name with the value provided in $value
|
||||
*
|
||||
* @param string $name The variable name
|
||||
* @param mixed $value The variable value
|
||||
* @return StaticHtmlOutput_View
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->_variables[$name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the view variable identified by $name with the value provided in $value
|
||||
*
|
||||
* This is an alias for {@link __set()}
|
||||
*
|
||||
* @param string $name The variable name
|
||||
* @param mixed $value The variable value
|
||||
* @return StaticHtmlOutput_View
|
||||
*/
|
||||
public function assign($name, $value)
|
||||
{
|
||||
return $this->__set($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of the option identified by $name
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
$value = array_key_exists($name, $this->_variables) ? $this->_variables[$name] : null;
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the view script
|
||||
*
|
||||
* @throws StaticHtmlOutput_Exception
|
||||
* @return StaticHtmlOutput_View
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$file = $this->_path . '/' . $this->_template . $this->_extension;
|
||||
|
||||
if (!is_readable($file))
|
||||
{
|
||||
throw new StaticHtmlOutput_Exception('Can\'t find view template: ' . $file);
|
||||
}
|
||||
|
||||
include $file;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rendered view script
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
ob_start();
|
||||
|
||||
$this->render();
|
||||
$contents = ob_get_contents();
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
return $contents;
|
||||
}
|
||||
}
|
142
readme.txt
Normal file
142
readme.txt
Normal file
|
@ -0,0 +1,142 @@
|
|||
=== WP Static HTML Output ===
|
||||
Contributors: leonstafford
|
||||
Donate link: http://leonstafford.github.io
|
||||
Tags: static,html,export
|
||||
Requires at least: 3.2
|
||||
Tested up to: 4.7
|
||||
Stable tag: 1.1.2
|
||||
|
||||
Produces a static HTML version of your Wordpress install and adjusts URL accordingly
|
||||
|
||||
== Description ==
|
||||
|
||||
[About the author](http://leonstafford.github.io/)
|
||||
|
||||
This plugin produces a static HTML version of your wordpress install, incredibly useful for anyone who would like the publishing power of wordpress but whose webhost doesn't allow dynamic PHP driven sites - such as MobileMe. You can run your development site on a different domain or offline, and the plugin will change all relevant URLs when you publish your site. It's a simple but powerful plugin, and after hitting the publish button, the plugin will output a ZIP file of your entire site, ready to upload straight to it's new home.
|
||||
|
||||
An example of a website which has been generated by this plugin and is now running in a static mode can be seen here:[Leon Stafford](http://leonstafford.github.io "Leon Stafford"). Please note that I'm currently running a very stripped down theme for testing, though this will work with most all WordPress themes with some slight tweaking for comments/RSS serving.
|
||||
|
||||
Limitations:
|
||||
* The nature of a static site implies that any dynamic elements of your wordpress install that reply upon Wordpress plugins or internal functions to operate dynamically will no longer work. Significantly, this means comments. You can workaround this by including a non-Wordpress version of an external comments provider into your theme code, such as the Disqus comment system. Any page elements that rely upon Javascript will function normally.
|
||||
* inability to correctly capture some relative links in posts
|
||||
* inability to detect assets dynamically loaded via javascript after page load, these will need to specified separately (but will work)
|
||||
|
||||
Premium Options:
|
||||
* Free domain name of your choosing (.com, .net, .org, etc)
|
||||
* One click deployment from your WordPress control panel
|
||||
* UNLIMITED filestorage for your whole WordPress site, including all attachments, etc.
|
||||
* Maximum redundancy so you never lose your static site
|
||||
* Premium support for the WP Static HTML Output Plugin via email with 24 hr response time
|
||||
|
||||
|
||||
|
||||
Planned upgrades:
|
||||
* one-click transfer to your destination server via FTP,SFTP,WebDAV, etc<br />
|
||||
* progress meter to show % of .ZIP creation
|
||||
* speed improvements
|
||||
|
||||
Developed by [**Leon Stafford**](http://leonstafford.github.io), Leon Stafford. If you have any questions about this plugin's usage, installation or development, please email me at: [leon.stafford@mac.com](mailto:leon.stafford@mac.com)
|
||||
|
||||
== Installation ==
|
||||
|
||||
This section describes how to install the plugin and get it working.
|
||||
|
||||
e.g.
|
||||
|
||||
1. Upload the static-html-output directory to the `/wp-content/plugins/` directory, or install via the wordpress interface "add new" or "upload" the zip file
|
||||
2. Activate the plugin through the 'Plugins' menu in WordPress
|
||||
3. Access the plugin settings from the "tools" menu
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Where can I publish my static site to? =
|
||||
|
||||
Anywhere that allows HTML files to be uploaded.
|
||||
|
||||
= My comments don't work anymore! =
|
||||
|
||||
See the readme. In brief: you can't use dynamic wordpress functions such as comments on a static site. Use an external comments provider such as Disqus, or live without them.
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. The main interface
|
||||
2. The main interface (Japanese)
|
||||
|
||||
|
||||
== Changelog ==
|
||||
= 1.1.2 =
|
||||
|
||||
* Version bump for supporting latest WP (4.7)
|
||||
|
||||
= 1.1.1 =
|
||||
|
||||
Added Features
|
||||
|
||||
* Updated author URL
|
||||
|
||||
Removed Features
|
||||
|
||||
* Premium options for One-Click publishing to provided hosting and domain
|
||||
|
||||
= 1.1.0 =
|
||||
|
||||
Added Features
|
||||
|
||||
* Premium options for One-Click publishing to provided hosting and domain
|
||||
|
||||
= 1.0.9 =
|
||||
|
||||
Added Features
|
||||
|
||||
* Japanese localization added (ja_UTF)
|
||||
|
||||
= 1.0.8 =
|
||||
|
||||
Added Features
|
||||
|
||||
* long-awaited FTP transfer option integrated with basic functionality
|
||||
* option to save generated static HTML files on server
|
||||
|
||||
= 1.0.7 =
|
||||
|
||||
Fixed bug introduced with previous version. Applied following modifications contributed by Brian Coca (https://github.com/bcoca):
|
||||
|
||||
Added Features
|
||||
|
||||
* zip is now written atomically (write tmp file first, then rename to zip) which now allows polling scripts to only deal with completed zip file.
|
||||
* username and blog id are now part of the file name. For auditing and handling
|
||||
multi site exports.
|
||||
|
||||
Bug fixes
|
||||
|
||||
* . and .. special directory entries are now ignored
|
||||
* dirname is checked before access avoiding uninitialized warning
|
||||
|
||||
= 1.0.6 =
|
||||
|
||||
Added shortcut to Settings page with Plugin Action Links
|
||||
|
||||
= 1.0.5 =
|
||||
|
||||
Added link to relevant Settings page when permalinks structure is not set.
|
||||
|
||||
= 1.0.4 =
|
||||
|
||||
Added a timeout value to URL request which was breaking for slow sites
|
||||
|
||||
= 1.0.3 =
|
||||
|
||||
Altered main codebase to fix recursion bug and endless loop. Essential upgrade.
|
||||
|
||||
= 1.0.2 =
|
||||
|
||||
Initial release to Wordpress community
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 1.1.2 =
|
||||
|
||||
Minor version bump after compatibility checking with latest WordPress (4.7).
|
||||
|
||||
= 1.1.0 =
|
||||
Premium VIP subscription option added, providing static optimized hosting and a domain for your website.
|
BIN
screenshot-1.jpg
Normal file
BIN
screenshot-1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 86 KiB |
BIN
screenshot-2.jpg
Normal file
BIN
screenshot-2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 80 KiB |
2
views/.htaccess
Normal file
2
views/.htaccess
Normal file
|
@ -0,0 +1,2 @@
|
|||
Order deny,allow
|
||||
Deny from all
|
10
views/message.phtml
Normal file
10
views/message.phtml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* @package WP Static HTML Output
|
||||
*
|
||||
* Copyright (c) 2011 Leon Stafford
|
||||
*/
|
||||
?>
|
||||
<div class="updated fade">
|
||||
<p><strong><?php echo $this->message ?></strong></p>
|
||||
</div>
|
65
views/options-page.phtml
Normal file
65
views/options-page.phtml
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/**
|
||||
* @package WP Static HTML Output
|
||||
*
|
||||
* Copyright (c) 2011 Leon Stafford
|
||||
*/
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
|
||||
<h2><?= __('WP Static HTML Output Plugin', '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">
|
||||
<div class="meta-box-sortables ui-sortable">
|
||||
|
||||
<form id="general-options" method="post" action="">
|
||||
|
||||
<div class="postbox">
|
||||
<div class="handlediv" title="Click to toggle"><br /></div>
|
||||
|
||||
<h3 class="hndle"><span><?= __('Export Options', 'static-html-output-plugin');?></span></h3>
|
||||
|
||||
<div class="inside">
|
||||
<p>
|
||||
<label for="baseUrl"><?= __('Base Url', 'static-html-output-plugin');?>:</label>
|
||||
<input type="text" id="baseUrl" name="baseUrl" value="<?php echo esc_attr($this->baseUrl) ?>" size="50" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="additionalUrls"><?= __('Additional Urls', 'static-html-output-plugin');?>:</label>
|
||||
<textarea class="widefat" name="additionalUrls" id="additionalUrls" rows="5" cols="10"><?php echo esc_html($this->additionalUrls) ?></textarea>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input name="generateZip" id="generateZip" value="1" type="checkbox" <?php if ($this->generateZip == 1) echo "checked"; ?> />
|
||||
<label for="generateZip"><?= __('Generate Zip archive of whole site', 'static-html-output-plugin');?></label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input name="retainStaticFiles" id="retainStaticFiles" value="1" type="checkbox" <?php if ($this->retainStaticFiles == 1) echo "checked"; ?> />
|
||||
<label for="retainStaticFiles"><?= __('Retain generated static files on server', 'static-html-output-plugin');?></label>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="submit">
|
||||
<?php wp_nonce_field($this->onceAction) ?>
|
||||
<input type="hidden" name="action" value="generate" />
|
||||
<input class="button-primary" type="submit" name="submit" value="Generate" />
|
||||
</p>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
52
views/system-requirements.phtml
Normal file
52
views/system-requirements.phtml
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* @package WP Static HTML Output
|
||||
*
|
||||
* Copyright (c) 2011 Leon Stafford
|
||||
*/
|
||||
|
||||
$fail = array();
|
||||
$pass = array();
|
||||
|
||||
if (!$this->supportsZipArchives):
|
||||
$fail[] = 'You are missing the <strong>zip</strong> extension';
|
||||
else:
|
||||
$pass[] = 'You have the <strong>zip</strong> extension';
|
||||
endif;
|
||||
|
||||
if (!$this->uploadsFolderWritable):
|
||||
$fail[] = 'Your uploads folder is not writable.';
|
||||
else:
|
||||
$pass[] = 'Your uploads folder is writable';
|
||||
endif;
|
||||
|
||||
if (!$this->permalinksStructureDefined):
|
||||
$fail[] = 'Your permalinks structure is undefined. Please set your permalinks structure here: <a href="'.admin_url( 'options-permalink.php' ).'">Permalink Settings</a>';
|
||||
else:
|
||||
$pass[] = 'Your permalinks structure is ok.';
|
||||
endif;
|
||||
?>
|
||||
|
||||
<div class="wrap wpsho-report">
|
||||
|
||||
<h2>System Requirements Report</h2>
|
||||
|
||||
<p><strong>Your server does not meet the following requirements in order to use this plugin.</strong></p>
|
||||
|
||||
<p>
|
||||
The following requirements failed, please contact your hosting provider in order to receive assistance with meeting the system requirements for this plugin:
|
||||
<ul>
|
||||
<li><?php echo implode('</li><li>', $fail) ?></li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<?php if (count($pass)): ?>
|
||||
<p>
|
||||
The following requirements were successfully met:
|
||||
<ul>
|
||||
<li><?php echo implode('</li><li>', $pass) ?></li>
|
||||
</ul>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
|
||||
</div>
|
44
wp-static-html-output.php
Normal file
44
wp-static-html-output.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/*
|
||||
Plugin Name: WP Static HTML Output
|
||||
Plugin URI: https://leonstafford.github.io
|
||||
Description: WP Static HTML Output Plugin.
|
||||
Version: 1.1.2
|
||||
Author: Leon Stafford
|
||||
Author URI: https://leonstafford.github.io
|
||||
Text Domain: static-html-output-plugin
|
||||
|
||||
Copyright (c) 2011 Leon Stafford
|
||||
*/
|
||||
|
||||
require_once 'library/StaticHtmlOutput/Exception.php';
|
||||
require_once 'library/StaticHtmlOutput/Options.php';
|
||||
require_once 'library/StaticHtmlOutput/View.php';
|
||||
require_once 'library/StaticHtmlOutput/UrlRequest.php';
|
||||
require_once 'library/StaticHtmlOutput.php';
|
||||
|
||||
StaticHtmlOutput::init(__FILE__);
|
||||
|
||||
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'pluginActionLinks');
|
||||
|
||||
/**
|
||||
* Adds link to options page from Plugins list
|
||||
* @return array
|
||||
*/
|
||||
function pluginActionLinks($links)
|
||||
{
|
||||
$settings_link = '<a href="tools.php?page=wp-static-html-output-options">' . __('Settings', 'static-html-output-plugin') . '</a>';
|
||||
array_unshift( $links, $settings_link );
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes localization
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function myplugin_init() {
|
||||
|
||||
load_plugin_textdomain( 'static-html-output-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
||||
}
|
||||
add_action('plugins_loaded', 'myplugin_init');
|
Loading…
Add table
Add a link
Reference in a new issue