change the algorithm for manipulating multiple meta query

git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@948014 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
kjmtsh 2014-07-14 08:46:32 +00:00
parent e5f495a745
commit 61e6960b40
16 changed files with 5853 additions and 5867 deletions

63
db.php
View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* This file defines some constant required for SQLite Integration. * This file defines some constant required for SQLite Integration.
* *
* This file must be placed in the directory wordpress/wp-content/db.php. * This file must be placed in the directory wordpress/wp-content/db.php.
* WordPress loads this file automatically. * WordPress loads this file automatically.
* *
* @version 1.6.2 * @version 1.6.2
* @package SQLite Integration * @package SQLite Integration
* @author Kojima Toshiyasu * @author Kojima Toshiyasu
@ -19,14 +19,14 @@ if (!defined('ABSPATH')) { // Oh, you are not WordPress!
* USE_MYSQL is a directive for using MySQL for database. * USE_MYSQL is a directive for using MySQL for database.
* If you want to change the database from SQLite to MySQL or from MySQL to SQLite, * If you want to change the database from SQLite to MySQL or from MySQL to SQLite,
* the line below in the wp-config.php will enable you to use MySQL. * the line below in the wp-config.php will enable you to use MySQL.
* *
* <code> * <code>
* define('USE_MYSQL', true); * define('USE_MYSQL', true);
* </code> * </code>
* *
* If you want to use SQLite, the line below will do. Or simply removing the line will * If you want to use SQLite, the line below will do. Or simply removing the line will
* be enough. * be enough.
* *
* <code> * <code>
* define('USE_MYSQL', false); * define('USE_MYSQL', false);
* </code> * </code>
@ -34,13 +34,12 @@ if (!defined('ABSPATH')) { // Oh, you are not WordPress!
if (defined('USE_MYSQL') && USE_MYSQL) return; if (defined('USE_MYSQL') && USE_MYSQL) return;
function pdo_log_error($message, $data = null) { function pdo_log_error($message, $data = null) {
if (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin') !== false) {
if (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin') !== false) { $admin_dir = '';
$admin_dir = ''; } else {
} else { $admin_dir = 'wp-admin/';
$admin_dir = 'wp-admin/'; }
} die(<<<HTML
die(<<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
@ -84,47 +83,47 @@ if (!extension_loaded('pdo_sqlite')) {
* PDODIR is SQLite Integration installed directory. * PDODIR is SQLite Integration installed directory.
*/ */
if (defined('WP_PLUGIN_DIR')) { if (defined('WP_PLUGIN_DIR')) {
define('PDODIR', WP_PLUGIN_DIR . '/sqlite-integration/'); define('PDODIR', WP_PLUGIN_DIR . '/sqlite-integration/');
} else { } else {
if (defined('WP_CONTENT_DIR')) { if (defined('WP_CONTENT_DIR')) {
define('PDODIR', WP_CONTENT_DIR . '/plugins/sqlite-integration/'); define('PDODIR', WP_CONTENT_DIR . '/plugins/sqlite-integration/');
} else { } else {
define('PDODIR', ABSPATH . 'wp-content/plugins/sqlite-integration/'); define('PDODIR', ABSPATH . 'wp-content/plugins/sqlite-integration/');
} }
} }
/* /*
* FQDBDIR is a directory where the sqlite database file is placed. * FQDBDIR is a directory where the sqlite database file is placed.
* If DB_DIR is defined, it is used as FQDBDIR. * If DB_DIR is defined, it is used as FQDBDIR.
*/ */
if (defined('DB_DIR')) { if (defined('DB_DIR')) {
if (substr(DB_DIR, -1, 1) != '/') { if (substr(DB_DIR, -1, 1) != '/') {
define('FQDBDIR', DB_DIR . '/'); define('FQDBDIR', DB_DIR . '/');
} else { } else {
define('FQDBDIR', DB_DIR); define('FQDBDIR', DB_DIR);
} }
} else { } else {
if (defined('WP_CONTENT_DIR')) { if (defined('WP_CONTENT_DIR')) {
define('FQDBDIR', WP_CONTENT_DIR . '/database/'); define('FQDBDIR', WP_CONTENT_DIR . '/database/');
} else { } else {
define('FQDBDIR', ABSPATH . 'wp-content/database/'); define('FQDBDIR', ABSPATH . 'wp-content/database/');
} }
} }
/* /*
* FQDB is a database file name. If DB_FILE is defined, it is used * FQDB is a database file name. If DB_FILE is defined, it is used
* as FQDB. * as FQDB.
*/ */
if ( defined('DB_FILE' )) { if ( defined('DB_FILE' )) {
define('FQDB', FQDBDIR . DB_FILE); define('FQDB', FQDBDIR . DB_FILE);
} else { } else {
define('FQDB', FQDBDIR . '.ht.sqlite'); define('FQDB', FQDBDIR . '.ht.sqlite');
} }
/* /*
* UDF_FILE is a file that contains user defined functions. * UDF_FILE is a file that contains user defined functions.
*/ */
if (version_compare(PHP_VERSION, '5.3', '<')) { if (version_compare(PHP_VERSION, '5.3', '<')) {
define('UDF_FILE', PDODIR . 'functions-5-2.php'); define('UDF_FILE', PDODIR . 'functions-5-2.php');
} elseif (version_compare(PHP_VERSION, '5.3', '>=')) { } elseif (version_compare(PHP_VERSION, '5.3', '>=')) {
define('UDF_FILE', PDODIR . 'functions.php'); define('UDF_FILE', PDODIR . 'functions.php');
} }
require_once PDODIR . 'pdodb.class.php'; require_once PDODIR . 'pdodb.class.php';

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* This file contains the only one function wp_install(). * This file contains the only one function wp_install().
* *
* @package SQLite Integration * @package SQLite Integration
* @author Kojima Toshiyasu, Justin Adie * @author Kojima Toshiyasu, Justin Adie
* *
@ -16,63 +16,63 @@ if (!defined('ABSPATH')) {
* This function overrides wp_install() in wp-admin/includes/upgrade.php * This function overrides wp_install() in wp-admin/includes/upgrade.php
*/ */
function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') { function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') {
if (!empty($deprecated)) if (!empty($deprecated))
_deprecated_argument(__FUNCTION__, '2.6'); _deprecated_argument(__FUNCTION__, '2.6');
wp_check_mysql_version(); wp_check_mysql_version();
wp_cache_flush(); wp_cache_flush();
/* changes */ /* changes */
require_once PDODIR . 'schema.php'; require_once PDODIR . 'schema.php';
make_db_sqlite(); make_db_sqlite();
/* changes */ /* changes */
populate_options(); populate_options();
populate_roles(); populate_roles();
update_option('blogname', $blog_title);
update_option('admin_email', $user_email);
update_option('blog_public', $public);
$guessurl = wp_guess_url();
update_option('siteurl', $guessurl);
if (!$public) update_option('blogname', $blog_title);
update_option('default_pingback_flag', 0); update_option('admin_email', $user_email);
update_option('blog_public', $public);
$user_id = username_exists($user_name);
$user_password = trim($user_password);
$email_password = false;
if (!$user_id && empty($user_password)) {
$user_password = wp_generate_password(12, false);
$message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
$user_id = wp_create_user($user_name, $user_password, $user_email);
update_user_option($user_id, 'default_password_nag', true, true);
$email_password = true;
} else if (!$user_id) {
$message = '<em>'.__('Your chosen password.').'</em>';
$user_id = wp_create_user($user_name, $user_password, $user_email);
}
$user = new WP_User($user_id);
$user->set_role('administrator');
wp_install_defaults($user_id);
flush_rewrite_rules();
wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.')));
wp_cache_flush();
if (isset($_SERVER['SERVER_SOFTWARE']) && stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false || isset($_SERVER['SERVER_SIGNATURE']) && stripos($_SERVER['SERVER_SIGNATURE'], 'apache') !== false) { $guessurl = wp_guess_url();
;// Your server is Apache. Nothing to do more.
} else {
$server_message = sprintf('Your webserver doesn\'t seem to be Apache. So the database directory access restriction by the .htaccess file may not function. We strongly recommend that you should restrict the access to the directory %s in some other way.', FQDBDIR);
echo '<div style="position: absolute; margin-top: 250px; width: 700px; border: .5px dashed rgb(0, 0, 0);"><p style="margin: 10px;">';
echo $server_message;
echo '</p></div>';
}
return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message); update_option('siteurl', $guessurl);
if (!$public)
update_option('default_pingback_flag', 0);
$user_id = username_exists($user_name);
$user_password = trim($user_password);
$email_password = false;
if (!$user_id && empty($user_password)) {
$user_password = wp_generate_password(12, false);
$message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
$user_id = wp_create_user($user_name, $user_password, $user_email);
update_user_option($user_id, 'default_password_nag', true, true);
$email_password = true;
} else if (!$user_id) {
$message = '<em>'.__('Your chosen password.').'</em>';
$user_id = wp_create_user($user_name, $user_password, $user_email);
}
$user = new WP_User($user_id);
$user->set_role('administrator');
wp_install_defaults($user_id);
flush_rewrite_rules();
wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.')));
wp_cache_flush();
if (isset($_SERVER['SERVER_SOFTWARE']) && stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false || isset($_SERVER['SERVER_SIGNATURE']) && stripos($_SERVER['SERVER_SIGNATURE'], 'apache') !== false) {
;// Your server is Apache. Nothing to do more.
} else {
$server_message = sprintf('Your webserver doesn\'t seem to be Apache. So the database directory access restriction by the .htaccess file may not function. We strongly recommend that you should restrict the access to the directory %s in some other way.', FQDBDIR);
echo '<div style="position: absolute; margin-top: 250px; width: 700px; border: .5px dashed rgb(0, 0, 0);"><p style="margin: 10px;">';
echo $server_message;
echo '</p></div>';
}
return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
} }
?> ?>

View File

@ -23,14 +23,14 @@ jQuery(document).ready(function($) {
$headers = $table.find('thead th').slice(1); $headers = $table.find('thead th').slice(1);
} }
$headers $headers
.wrapInner('<a href="#"></a>') .wrapInner('<a href="#"></a>')
.addClass('sort'); .addClass('sort');
var rows = $table.find('tbody > tr').get(); var rows = $table.find('tbody > tr').get();
$headers.bind('click', function(event) { $headers.bind('click', function(event) {
event.preventDefault(); event.preventDefault();
var $header = $(this), var $header = $(this),
sortKey = $header.data('sort').key, sortKey = $header.data('sort').key,
sortDirection = 1; sortDirection = 1;
if ($header.hasClass('sorted-asc')) { if ($header.hasClass('sorted-asc')) {
sortDirection = -1; sortDirection = -1;
} }
@ -70,14 +70,14 @@ jQuery(document).ready(function($) {
var $table = $('#plugins-info'); var $table = $('#plugins-info');
var $headers = $table.find('thead th').slice(0); var $headers = $table.find('thead th').slice(0);
$headers $headers
.wrapInner('<a href="#"></a>') .wrapInner('<a href="#"></a>')
.addClass('sort'); .addClass('sort');
var rows = $table.find('tbody > tr').get(); var rows = $table.find('tbody > tr').get();
$headers.bind('click', function(event) { $headers.bind('click', function(event) {
event.preventDefault(); event.preventDefault();
var $header = $(this), var $header = $(this),
sortKey = $header.data('sort').key, sortKey = $header.data('sort').key,
sortDirection = 1; sortDirection = 1;
if ($header.hasClass('sorted-asc')) { if ($header.hasClass('sorted-asc')) {
sortDirection = -1; sortDirection = -1;
} }

View File

@ -2,7 +2,7 @@
/** /**
* This file defines PDODB class, which inherits wpdb class and replaces it * This file defines PDODB class, which inherits wpdb class and replaces it
* global $wpdb variable. * global $wpdb variable.
* *
* @package SQLite Integration * @package SQLite Integration
* @author Kojima Toshiyasu * @author Kojima Toshiyasu
* *
@ -18,315 +18,315 @@ if (!defined('SAVEQUERIES')){
define ('SAVEQUERIES', false); define ('SAVEQUERIES', false);
} }
if(!defined('PDO_DEBUG')){ if(!defined('PDO_DEBUG')){
define('PDO_DEBUG', false); define('PDO_DEBUG', false);
} }
/** /**
* This class extends wpdb and replaces it. * This class extends wpdb and replaces it.
* *
* It also rewrites some methods that use mysql specific functions. * It also rewrites some methods that use mysql specific functions.
* *
*/ */
class PDODB extends wpdb { class PDODB extends wpdb {
/** /**
* *
* @var reference to the object of PDOEngine class. * @var reference to the object of PDOEngine class.
* @access protected * @access protected
*/ */
protected $dbh = null; protected $dbh = null;
/**
* Constructor
*
* This overrides wpdb::__construct() which has database server, username and
* password as arguments. This class doesn't use them.
*
* @see wpdb::__construct()
*/
function __construct() {
register_shutdown_function(array($this, '__destruct'));
if (WP_DEBUG) /**
$this->show_errors(); * Constructor
*
$this->init_charset(); * This overrides wpdb::__construct() which has database server, username and
* password as arguments. This class doesn't use them.
*
* @see wpdb::__construct()
*/
function __construct() {
register_shutdown_function(array($this, '__destruct'));
if (WP_DEBUG)
$this->show_errors();
$this->init_charset();
$this->db_connect();
}
/**
* Desctructor
*
* This overrides wpdb::__destruct(), but does nothing but return true.
*
* @see wpdb::__destruct()
*/
function __destruct() {
return true;
}
/**
* Method to set character set for the database.
*
* This overrides wpdb::set_charset(), only to dummy out the MySQL function.
*
* @see wpdb::set_charset()
*/
function set_charset($dbh, $charset = null, $collate = null) {
if ( ! isset( $charset ) )
$charset = $this->charset;
if ( ! isset( $collate ) )
$collate = $this->collate;
}
/**
* Method to dummy out wpdb::set_sql_mode()
*
* @see wpdb::set_sql_mode()
*/
function set_sql_mode($modes = array()) {
unset($modes);
return;
}
/**
* Method to select the database connection.
*
* This overrides wpdb::select(), only to dummy out the MySQL function.
*
* @see wpdb::select()
*/
function select($db, $dbh = null) {
if (is_null($dbh))
$dbh = $this->dbh;
$this->ready = true;
return;
}
/**
* Method to dummy out wpdb::_weak_escape()
*
*/
function _weak_escape($string) {
return addslashes($string);
}
/**
* Method to escape characters.
*
* This overrides wpdb::_real_escape() to avoid using mysql_real_escape_string().
*
* @see wpdb::_real_escape()
*/
function _real_escape($string) {
return addslashes($string);
}
/**
* Method to put out the error message.
*
* This overrides wpdb::print_error(), for we can't use the parent class method.
*
* @see wpdb::print_error()
*/
function print_error($str = '') {
global $EZSQL_ERROR;
if (!$str) {
$err = $this->dbh->get_error_message() ? $this->dbh->get_error_message() : '';
if (!empty($err)) $str = $err[2]; else $str = '';
}
$EZSQL_ERROR[] = array('query' => $this->last_query, 'error_str' => $str);
if ($this->suppress_errors)
return false;
wp_load_translations_early();
if ($caller = $this->get_caller())
$error_str = sprintf(__('WordPress database error %1$s for query %2$s made by %3$s'), $str, $this->last_query, $caller);
else
$error_str = sprintf(__('WordPress database error %1$s for query %2$s'), $str, $this->last_query);
error_log($error_str);
if (!$this->show_errors)
return false;
if (is_multisite()) {
$msg = "WordPress database error: [$str]\n{$this->last_query}\n";
if (defined('ERRORLOGFILE'))
error_log($msg, 3, ERRORLOGFILE);
if (defined('DIEONDBERROR'))
wp_die($msg);
} else {
$str = htmlspecialchars($str, ENT_QUOTES);
$query = htmlspecialchars($this->last_query, ENT_QUOTES);
$this->db_connect();
}
/**
* Desctructor
*
* This overrides wpdb::__destruct(), but does nothing but return true.
*
* @see wpdb::__destruct()
*/
function __destruct() {
return true;
}
/**
* Method to set character set for the database.
*
* This overrides wpdb::set_charset(), only to dummy out the MySQL function.
*
* @see wpdb::set_charset()
*/
function set_charset($dbh, $charset = null, $collate = null) {
if ( ! isset( $charset ) )
$charset = $this->charset;
if ( ! isset( $collate ) )
$collate = $this->collate;
}
/**
* Method to dummy out wpdb::set_sql_mode()
*
* @see wpdb::set_sql_mode()
*/
function set_sql_mode($modes = array()) {
unset($modes);
return;
}
/**
* Method to select the database connection.
*
* This overrides wpdb::select(), only to dummy out the MySQL function.
*
* @see wpdb::select()
*/
function select($db, $dbh = null) {
if (is_null($dbh))
$dbh = $this->dbh;
$this->ready = true;
return;
}
/**
* Method to dummy out wpdb::_weak_escape()
*
*/
function _weak_escape($string) {
return addslashes($string);
}
/**
* Method to escape characters.
*
* This overrides wpdb::_real_escape() to avoid using mysql_real_escape_string().
*
* @see wpdb::_real_escape()
*/
function _real_escape($string) {
return addslashes($string);
}
/**
* Method to put out the error message.
*
* This overrides wpdb::print_error(), for we can't use the parent class method.
*
* @see wpdb::print_error()
*/
function print_error($str = '') {
global $EZSQL_ERROR;
if (!$str) {
$err = $this->dbh->get_error_message() ? $this->dbh->get_error_message() : '';
if (!empty($err)) $str = $err[2]; else $str = '';
}
$EZSQL_ERROR[] = array('query' => $this->last_query, 'error_str' => $str);
if ($this->suppress_errors)
return false;
wp_load_translations_early();
if ($caller = $this->get_caller())
$error_str = sprintf(__('WordPress database error %1$s for query %2$s made by %3$s'), $str, $this->last_query, $caller);
else
$error_str = sprintf(__('WordPress database error %1$s for query %2$s'), $str, $this->last_query);
error_log($error_str);
if (!$this->show_errors)
return false;
if (is_multisite()) {
$msg = "WordPress database error: [$str]\n{$this->last_query}\n";
if (defined('ERRORLOGFILE'))
error_log($msg, 3, ERRORLOGFILE);
if (defined('DIEONDBERROR'))
wp_die($msg);
} else {
$str = htmlspecialchars($str, ENT_QUOTES);
$query = htmlspecialchars($this->last_query, ENT_QUOTES);
print "<div id='error'> print "<div id='error'>
<p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br /> <p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br />
<code>$query</code></p> <code>$query</code></p>
</div>"; </div>";
} }
} }
/** /**
* Method to flush cached data. * Method to flush cached data.
* *
* This overrides wpdb::flush(). This is not necessarily overridden, because * This overrides wpdb::flush(). This is not necessarily overridden, because
* $result will never be resource. * $result will never be resource.
* *
* @see wpdb::flush * @see wpdb::flush
*/ */
function flush() { function flush() {
$this->last_result = array(); $this->last_result = array();
$this->col_info = null; $this->col_info = null;
$this->last_query = null; $this->last_query = null;
$this->rows_affected = $this->num_rows = 0; $this->rows_affected = $this->num_rows = 0;
$this->last_error = ''; $this->last_error = '';
$this->result = null; $this->result = null;
} }
/** /**
* Method to do the database connection. * Method to do the database connection.
* *
* This overrides wpdb::db_connect() to avoid using MySQL function. * This overrides wpdb::db_connect() to avoid using MySQL function.
* *
* @see wpdb::db_connect() * @see wpdb::db_connect()
*/ */
function db_connect($allow_bail=true) { function db_connect($allow_bail=true) {
if (WP_DEBUG) { if (WP_DEBUG) {
$this->dbh = new PDOEngine(); $this->dbh = new PDOEngine();
} else { } else {
// WP_DEBUG or not, we don't use @ which causes the slow execution // WP_DEBUG or not, we don't use @ which causes the slow execution
// PDOEngine class will take the Exception handling. // PDOEngine class will take the Exception handling.
$this->dbh = new PDOEngine(); $this->dbh = new PDOEngine();
} }
if (!$this->dbh) { if (!$this->dbh) {
wp_load_translations_early();//probably there's no translations wp_load_translations_early();//probably there's no translations
$this->bail(sprintf(__("<h1>Error establlishing a database connection</h1><p>We have been unable to connect to the specified database. <br />The error message received was %s"), $this->dbh->errorInfo())); $this->bail(sprintf(__("<h1>Error establlishing a database connection</h1><p>We have been unable to connect to the specified database. <br />The error message received was %s"), $this->dbh->errorInfo()));
return; return;
} }
$is_enabled_foreign_keys = @$this->get_var('PRAGMA foreign_keys'); $is_enabled_foreign_keys = @$this->get_var('PRAGMA foreign_keys');
if ($is_enabled_foreign_keys == '0') @$this->query('PRAGMA foreign_keys = ON'); if ($is_enabled_foreign_keys == '0') @$this->query('PRAGMA foreign_keys = ON');
$this->ready = true; $this->ready = true;
} }
/** /**
* Method to dummy out wpdb::check_connection() * Method to dummy out wpdb::check_connection()
* *
*/ */
function check_connection($allow_bail=true) { function check_connection($allow_bail=true) {
return true; return true;
} }
/** /**
* Method to execute the query. * Method to execute the query.
* *
* This overrides wpdb::query(). In fact, this method does all the database * This overrides wpdb::query(). In fact, this method does all the database
* access jobs. * access jobs.
* *
* @see wpdb::query() * @see wpdb::query()
*/ */
function query($query) { function query($query) {
if (!$this->ready) if (!$this->ready)
return false; return false;
$query = apply_filters('query', $query); $query = apply_filters('query', $query);
$return_val = 0; $return_val = 0;
$this->flush(); $this->flush();
$this->func_call = "\$db->query(\"$query\")"; $this->func_call = "\$db->query(\"$query\")";
$this->last_query = $query; $this->last_query = $query;
if (defined('SAVEQUERIES') && SAVEQUERIES) if (defined('SAVEQUERIES') && SAVEQUERIES)
$this->timer_start(); $this->timer_start();
$this->result = $this->dbh->query($query); $this->result = $this->dbh->query($query);
$this->num_queries++; $this->num_queries++;
if (defined('SAVEQUERIES') && SAVEQUERIES) if (defined('SAVEQUERIES') && SAVEQUERIES)
$this->queries[] = array($query, $this->timer_stop(), $this->get_caller()); $this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
if ($this->last_error = $this->dbh->get_error_message()) { if ($this->last_error = $this->dbh->get_error_message()) {
if (defined('WP_INSTALLING') && WP_INSTALLING) { if (defined('WP_INSTALLING') && WP_INSTALLING) {
//$this->suppress_errors(); //$this->suppress_errors();
} else { } else {
$this->print_error($this->last_error); $this->print_error($this->last_error);
return false; return false;
} }
} }
if (preg_match('/^\\s*(create|alter|truncate|drop|optimize)\\s*/i', $query)) { if (preg_match('/^\\s*(create|alter|truncate|drop|optimize)\\s*/i', $query)) {
// $return_val = $this->result; //$return_val = $this->result;
$return_val = $this->dbh->get_return_value(); $return_val = $this->dbh->get_return_value();
} elseif (preg_match('/^\\s*(insert|delete|update|replace)\s/i', $query)) { } elseif (preg_match('/^\\s*(insert|delete|update|replace)\s/i', $query)) {
$this->rows_affected = $this->dbh->get_affected_rows(); $this->rows_affected = $this->dbh->get_affected_rows();
if (preg_match('/^\s*(insert|replace)\s/i', $query)) { if (preg_match('/^\s*(insert|replace)\s/i', $query)) {
$this->insert_id = $this->dbh->get_insert_id(); $this->insert_id = $this->dbh->get_insert_id();
} }
$return_val = $this->rows_affected; $return_val = $this->rows_affected;
} else { } else {
$this->last_result = $this->dbh->get_query_results(); $this->last_result = $this->dbh->get_query_results();
$this->num_rows = $this->dbh->get_num_rows(); $this->num_rows = $this->dbh->get_num_rows();
$return_val = $this->num_rows; $return_val = $this->num_rows;
} }
return $return_val; return $return_val;
} }
/** /**
* *
*/ */
private function _do_query($query) { private function _do_query($query) {
if (defined('SAVEQUERIES') && SAVEQUERIES) { if (defined('SAVEQUERIES') && SAVEQUERIES) {
$this->timer_start(); $this->timer_start();
} }
$this->result = $this->dbh->query($query); $this->result = $this->dbh->query($query);
$this->num_queries++; $this->num_queries++;
if (defined('SAVEQUERIES') && SAVEQUERIES) { if (defined('SAVEQUERIES') && SAVEQUERIES) {
$this->queries[] = array($query, $this->timer_stop(), $this->get_caller()); $this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
} }
} }
/** /**
* Method to set the class variable $col_info. * Method to set the class variable $col_info.
* *
* This overrides wpdb::load_col_info(), which uses a mysql function. * This overrides wpdb::load_col_info(), which uses a mysql function.
* *
* @see wpdb::load_col_info() * @see wpdb::load_col_info()
* @access protected * @access protected
*/ */
protected function load_col_info() { protected function load_col_info() {
if ($this->col_info) if ($this->col_info)
return; return;
$this->col_info = $this->dbh->get_columns(); $this->col_info = $this->dbh->get_columns();
} }
/** /**
* Method to return what the database can do. * Method to return what the database can do.
* *
* This overrides wpdb::has_cap() to avoid using MySQL functions. * This overrides wpdb::has_cap() to avoid using MySQL functions.
* SQLite supports subqueries, but not support collation, group_concat and set_charset. * SQLite supports subqueries, but not support collation, group_concat and set_charset.
* *
* @see wpdb::has_cap() * @see wpdb::has_cap()
*/ */
function has_cap($db_cap) { function has_cap($db_cap) {
switch(strtolower($db_cap)) { switch(strtolower($db_cap)) {
case 'collation': case 'collation':
case 'group_concat': case 'group_concat':
case 'set_charset': case 'set_charset':
return false; return false;
case 'subqueries': case 'subqueries':
return true; return true;
default: default:
return false; return false;
} }
} }
/** /**
* Method to return database version number. * Method to return database version number.
* *
* This overrides wpdb::db_version() to avoid using MySQL function. * This overrides wpdb::db_version() to avoid using MySQL function.
* It returns mysql version number, but it means nothing for SQLite. * It returns mysql version number, but it means nothing for SQLite.
* So it return the newest mysql version. * So it return the newest mysql version.
* *
* @see wpdb::db_version() * @see wpdb::db_version()
*/ */
function db_version() { function db_version() {
// global $required_mysql_version; //global $required_mysql_version;
// return $required_mysql_version; //return $required_mysql_version;
return '5.5'; return '5.5';
} }
} }
/* /*

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,56 +1,56 @@
<?php <?php
/** /**
* This file defines CreateQuery class. * This file defines CreateQuery class.
* *
* @package SQLite Integration * @package SQLite Integration
* @author Kojima Toshiyasu * @author Kojima Toshiyasu
*/ */
/** /**
* This class provides a function to rewrite CREATE query. * This class provides a function to rewrite CREATE query.
* *
*/ */
class CreateQuery{ class CreateQuery{
/** /**
* The query string to be rewritten in this class. * The query string to be rewritten in this class.
* *
* @var string * @var string
* @access private * @access private
*/ */
private $_query = ''; private $_query = '';
/** /**
* The array to contain CREATE INDEX queries. * The array to contain CREATE INDEX queries.
* *
* @var array of strings * @var array of strings
* @access private * @access private
*/ */
private $index_queries = array(); private $index_queries = array();
/** /**
* The array to contain error messages. * The array to contain error messages.
* *
* @var array of string * @var array of string
* @access private * @access private
*/ */
private $_errors = array(); private $_errors = array();
/** /**
* Variable to have the table name to be executed. * Variable to have the table name to be executed.
* *
* @var string * @var string
* @access private * @access private
*/ */
private $table_name = ''; private $table_name = '';
/** /**
* Variable to check if the query has the primary key. * Variable to check if the query has the primary key.
* *
* @var boolean * @var boolean
* @access private * @access private
*/ */
private $has_primary_key = false; private $has_primary_key = false;
/** /**
* Function to rewrite query. * Function to rewrite query.
* *
* @param string $query the query being processed * @param string $query the query being processed
* @return string|array the processed (rewritten) query * @return string|array the processed (rewritten) query
*/ */
@ -85,50 +85,50 @@ class CreateQuery{
$this->rewrite_set(); $this->rewrite_set();
$this->rewrite_key(); $this->rewrite_key();
$this->add_if_not_exists(); $this->add_if_not_exists();
return $this->post_process(); return $this->post_process();
} }
/** /**
* Method to get table name from the query string. * Method to get table name from the query string.
* *
* 'IF NOT EXISTS' clause is removed for the easy regular expression usage. * 'IF NOT EXISTS' clause is removed for the easy regular expression usage.
* It will be added at the end of the process. * It will be added at the end of the process.
* *
* @access private * @access private
*/ */
private function get_table_name(){ private function get_table_name(){
// $pattern = '/^\\s*CREATE\\s*(TEMP|TEMPORARY)?\\s*TABLE\\s*(IF NOT EXISTS)?\\s*([^\(]*)/imsx'; // $pattern = '/^\\s*CREATE\\s*(TEMP|TEMPORARY)?\\s*TABLE\\s*(IF NOT EXISTS)?\\s*([^\(]*)/imsx';
$pattern = '/^\\s*CREATE\\s*(?:TEMP|TEMPORARY)?\\s*TABLE\\s*(?:IF\\s*NOT\\s*EXISTS)?\\s*([^\(]*)/imsx'; $pattern = '/^\\s*CREATE\\s*(?:TEMP|TEMPORARY)?\\s*TABLE\\s*(?:IF\\s*NOT\\s*EXISTS)?\\s*([^\(]*)/imsx';
if (preg_match($pattern, $this->_query, $matches)) { if (preg_match($pattern, $this->_query, $matches)) {
$this->table_name = trim($matches[1]); $this->table_name = trim($matches[1]);
} }
} }
/** /**
* Method to change the MySQL field types to SQLite compatible types. * Method to change the MySQL field types to SQLite compatible types.
* *
* Order of the key value is important. Don't change it. * Order of the key value is important. Don't change it.
* *
* @access private * @access private
*/ */
private function rewrite_field_types(){ private function rewrite_field_types(){
$array_types = array ( $array_types = array (
'bit' => 'integer', 'bool' => 'integer', 'bit' => 'integer', 'bool' => 'integer',
'boolean' => 'integer', 'tinyint' => 'integer', 'boolean' => 'integer', 'tinyint' => 'integer',
'smallint' => 'integer', 'mediumint' => 'integer', 'smallint' => 'integer', 'mediumint' => 'integer',
'int' => 'integer', 'integer' => 'integer', 'int' => 'integer', 'integer' => 'integer',
'bigint' => 'integer', 'float' => 'real', 'bigint' => 'integer', 'float' => 'real',
'double' => 'real', 'decimal' => 'real', 'double' => 'real', 'decimal' => 'real',
'dec' => 'real', 'numeric' => 'real', 'dec' => 'real', 'numeric' => 'real',
'fixed' => 'real', 'date' => 'text', 'fixed' => 'real', 'date' => 'text',
'datetime' => 'text', 'timestamp' => 'text', 'datetime' => 'text', 'timestamp' => 'text',
'time' => 'text', 'year' => 'text', 'time' => 'text', 'year' => 'text',
'char' => 'text', 'varchar' => 'text', 'char' => 'text', 'varchar' => 'text',
'binary' => 'integer', 'varbinary' => 'blob', 'binary' => 'integer', 'varbinary' => 'blob',
'tinyblob' => 'blob', 'tinytext' => 'text', 'tinyblob' => 'blob', 'tinytext' => 'text',
'blob' => 'blob', 'text' => 'text', 'blob' => 'blob', 'text' => 'text',
'mediumblob' => 'blob', 'mediumtext' => 'text', 'mediumblob' => 'blob', 'mediumtext' => 'text',
'longblob' => 'blob', 'longtext' => 'text' 'longblob' => 'blob', 'longtext' => 'text'
); );
foreach ($array_types as $o=>$r){ foreach ($array_types as $o=>$r){
$pattern = "/\\b(?<!`)$o\\b\\s*(\([^\)]*\)*)?\\s*/ims"; $pattern = "/\\b(?<!`)$o\\b\\s*(\([^\)]*\)*)?\\s*/ims";
if (preg_match("/^\\s*.*?\\s*\(.*?$o.*?\)/im", $this->_query)) { if (preg_match("/^\\s*.*?\\s*\(.*?$o.*?\)/im", $this->_query)) {
@ -140,43 +140,43 @@ class CreateQuery{
} }
/** /**
* Method for stripping the comments from the SQL statement. * Method for stripping the comments from the SQL statement.
* *
* @access private * @access private
*/ */
private function rewrite_comments(){ private function rewrite_comments(){
$this->_query = preg_replace("/# --------------------------------------------------------/","-- ******************************************************",$this->_query); $this->_query = preg_replace("/# --------------------------------------------------------/","-- ******************************************************",$this->_query);
$this->_query = preg_replace("/#/","--",$this->_query); $this->_query = preg_replace("/#/","--",$this->_query);
} }
/** /**
* Method for stripping the engine and other stuffs. * Method for stripping the engine and other stuffs.
* *
* TYPE, ENGINE and AUTO_INCREMENT are removed here. * TYPE, ENGINE and AUTO_INCREMENT are removed here.
* @access private * @access private
*/ */
private function rewrite_engine_info(){ private function rewrite_engine_info(){
$this->_query = preg_replace("/\\s*(TYPE|ENGINE)\\s*=\\s*.*(?<!;)/ims",'',$this->_query); $this->_query = preg_replace("/\\s*(TYPE|ENGINE)\\s*=\\s*.*(?<!;)/ims",'',$this->_query);
$this->_query = preg_replace("/ AUTO_INCREMENT\\s*=\\s*[0-9]*/ims",'',$this->_query); $this->_query = preg_replace("/ AUTO_INCREMENT\\s*=\\s*[0-9]*/ims",'',$this->_query);
} }
/** /**
* Method for stripping unsigned. * Method for stripping unsigned.
* *
* SQLite doesn't have unsigned int data type. So UNSIGNED INT(EGER) is converted * SQLite doesn't have unsigned int data type. So UNSIGNED INT(EGER) is converted
* to INTEGER here. * to INTEGER here.
* *
* @access private * @access private
*/ */
private function rewrite_unsigned(){ private function rewrite_unsigned(){
$this->_query = preg_replace('/\\bunsigned\\b/ims', ' ', $this->_query); $this->_query = preg_replace('/\\bunsigned\\b/ims', ' ', $this->_query);
} }
/** /**
* Method for rewriting primary key auto_increment. * Method for rewriting primary key auto_increment.
* *
* If the field type is 'INTEGER PRIMARY KEY', it is automatically autoincremented * If the field type is 'INTEGER PRIMARY KEY', it is automatically autoincremented
* by SQLite. There's a little difference between PRIMARY KEY and AUTOINCREMENT, so * by SQLite. There's a little difference between PRIMARY KEY and AUTOINCREMENT, so
* we may well convert to PRIMARY KEY only. * we may well convert to PRIMARY KEY only.
* *
* @access private * @access private
*/ */
private function rewrite_autoincrement(){ private function rewrite_autoincrement(){
$this->_query = preg_replace('/\\bauto_increment\\s*primary\\s*key\\s*(,)?/ims', ' PRIMARY KEY AUTOINCREMENT \\1', $this->_query, -1, $count); $this->_query = preg_replace('/\\bauto_increment\\s*primary\\s*key\\s*(,)?/ims', ' PRIMARY KEY AUTOINCREMENT \\1', $this->_query, -1, $count);
$this->_query = preg_replace('/\\bauto_increment\\b\\s*(,)?/ims', ' PRIMARY KEY AUTOINCREMENT $1', $this->_query, -1, $count); $this->_query = preg_replace('/\\bauto_increment\\b\\s*(,)?/ims', ' PRIMARY KEY AUTOINCREMENT $1', $this->_query, -1, $count);
@ -186,72 +186,72 @@ class CreateQuery{
} }
/** /**
* Method for rewriting primary key. * Method for rewriting primary key.
* *
* @access private * @access private
*/ */
private function rewrite_primary_key(){ private function rewrite_primary_key(){
if ($this->has_primary_key) { if ($this->has_primary_key) {
$this->_query = preg_replace('/\\s*primary key\\s*.*?\([^\)]*\)\\s*(,|)/i', ' ', $this->_query); $this->_query = preg_replace('/\\s*primary key\\s*.*?\([^\)]*\)\\s*(,|)/i', ' ', $this->_query);
} else { } else {
// If primary key has an index name, we remove that name. // If primary key has an index name, we remove that name.
$this->_query = preg_replace('/\\bprimary\\s*key\\s*.*?\\s*(\(.*?\))/im', 'PRIMARY KEY \\1', $this->_query); $this->_query = preg_replace('/\\bprimary\\s*key\\s*.*?\\s*(\(.*?\))/im', 'PRIMARY KEY \\1', $this->_query);
}
}
/**
* Method for rewriting foreign key.
*
* @access private
*/
private function rewrite_foreign_key() {
$pattern = '/\\s*foreign\\s*key\\s*(|.*?)\([^\)]+?\)\\s*references\\s*.*/i';
if (preg_match_all($pattern, $this->_query, $match)) {
if (isset($match[1])) {
$this->_query = str_ireplace($match[1], '', $this->_query);
}
} }
} }
/**
* Method for rewriting foreign key.
*
* @access private
*/
private function rewrite_foreign_key() {
$pattern = '/\\s*foreign\\s*key\\s*(|.*?)\([^\)]+?\)\\s*references\\s*.*/i';
if (preg_match_all($pattern, $this->_query, $match)) {
if (isset($match[1])) {
$this->_query = str_ireplace($match[1], '', $this->_query);
}
}
}
/** /**
* Method for rewriting unique key. * Method for rewriting unique key.
* *
* @access private * @access private
*/ */
private function rewrite_unique_key(){ private function rewrite_unique_key(){
$this->_query = preg_replace_callback('/\\bunique key\\b([^\(]*)(\(.*\))/im', array($this, '_rewrite_unique_key'), $this->_query); $this->_query = preg_replace_callback('/\\bunique key\\b([^\(]*)(\(.*\))/im', array($this, '_rewrite_unique_key'), $this->_query);
} }
/** /**
* Callback method for rewrite_unique_key. * Callback method for rewrite_unique_key.
* *
* @param array $matches an array of matches from the Regex * @param array $matches an array of matches from the Regex
* @access private * @access private
*/ */
private function _rewrite_unique_key($matches){ private function _rewrite_unique_key($matches){
$index_name = trim($matches[1]); $index_name = trim($matches[1]);
$col_name = trim($matches[2]); $col_name = trim($matches[2]);
$tbl_name = $this->table_name; $tbl_name = $this->table_name;
if (preg_match('/\(\\d+?\)/', $col_name)) { if (preg_match('/\(\\d+?\)/', $col_name)) {
$col_name = preg_replace('/\(\\d+?\)/', '', $col_name); $col_name = preg_replace('/\(\\d+?\)/', '', $col_name);
} }
$_wpdb = new PDODB(); $_wpdb = new PDODB();
$results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'"); $results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'");
$_wpdb = null; $_wpdb = null;
if ($results) { if ($results) {
foreach ($results as $result) { foreach ($results as $result) {
if ($result->name == $index_name) { if ($result->name == $index_name) {
$r = rand(0, 50); $r = rand(0, 50);
$index_name = $index_name . "_$r"; $index_name = $index_name . "_$r";
break; break;
} }
} }
} }
$index_name = str_replace(' ', '', $index_name); $index_name = str_replace(' ', '', $index_name);
$this->index_queries[] = "CREATE UNIQUE INDEX $index_name ON " . $tbl_name .$col_name; $this->index_queries[] = "CREATE UNIQUE INDEX $index_name ON " . $tbl_name .$col_name;
return ''; return '';
} }
/** /**
* Method for handling ENUM fields. * Method for handling ENUM fields.
* *
* SQLite doesn't support enum, so we change it to check constraint. * SQLite doesn't support enum, so we change it to check constraint.
* *
* @access private * @access private
*/ */
private function rewrite_enum(){ private function rewrite_enum(){
@ -260,7 +260,7 @@ class CreateQuery{
} }
/** /**
* Call back method for rewrite_enum() and rewrite_set(). * Call back method for rewrite_enum() and rewrite_set().
* *
* @access private * @access private
*/ */
private function _rewrite_enum($matches){ private function _rewrite_enum($matches){
@ -269,9 +269,9 @@ class CreateQuery{
} }
/** /**
* Method for rewriting usage of set. * Method for rewriting usage of set.
* *
* It is similar but not identical to enum. SQLite does not support either. * It is similar but not identical to enum. SQLite does not support either.
* *
* @access private * @access private
*/ */
private function rewrite_set(){ private function rewrite_set(){
@ -280,10 +280,10 @@ class CreateQuery{
} }
/** /**
* Method for rewriting usage of key to create an index. * Method for rewriting usage of key to create an index.
* *
* SQLite cannot create non-unique indices as part of the create query, * SQLite cannot create non-unique indices as part of the create query,
* so we need to create an index by hand and append it to the create query. * so we need to create an index by hand and append it to the create query.
* *
* @access private * @access private
*/ */
private function rewrite_key(){ private function rewrite_key(){
@ -291,72 +291,72 @@ class CreateQuery{
} }
/** /**
* Callback method for rewrite_key. * Callback method for rewrite_key.
* *
* @param array $matches an array of matches from the Regex * @param array $matches an array of matches from the Regex
* @access private * @access private
*/ */
private function _rewrite_key($matches){ private function _rewrite_key($matches){
$index_name = trim($matches[2]); $index_name = trim($matches[2]);
$col_name = trim($matches[3]); $col_name = trim($matches[3]);
if (preg_match('/\([0-9]+?\)/', $col_name, $match)) { if (preg_match('/\([0-9]+?\)/', $col_name, $match)) {
$col_name = preg_replace_callback('/\([0-9]+?\)/', array($this, '_remove_length'), $col_name); $col_name = preg_replace_callback('/\([0-9]+?\)/', array($this, '_remove_length'), $col_name);
} }
$tbl_name = $this->table_name; $tbl_name = $this->table_name;
$_wpdb = new PDODB(); $_wpdb = new PDODB();
$results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'"); $results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'");
$_wpdb = null; $_wpdb = null;
if ($results) { if ($results) {
foreach ($results as $result) { foreach ($results as $result) {
if ($result->name == $index_name) { if ($result->name == $index_name) {
$r = rand(0, 50); $r = rand(0, 50);
$index_name = $index_name . "_$r"; $index_name = $index_name . "_$r";
break; break;
} }
} }
} }
$this->index_queries[] = 'CREATE INDEX '. $index_name . ' ON ' . $tbl_name . $col_name ; $this->index_queries[] = 'CREATE INDEX '. $index_name . ' ON ' . $tbl_name . $col_name ;
return ''; return '';
} }
/** /**
* Call back method to remove unnecessary string. * Call back method to remove unnecessary string.
* *
* This method is deprecated. * This method is deprecated.
* *
* @param string $match * @param string $match
* @return string whose length is zero * @return string whose length is zero
* @access private * @access private
*/ */
private function _remove_length($match) { private function _remove_length($match) {
return ''; return '';
} }
/** /**
* Method to assemble the main query and index queries into an array. * Method to assemble the main query and index queries into an array.
* *
* It return the array of the queries to be executed separately. * It return the array of the queries to be executed separately.
* *
* @return array * @return array
* @access private * @access private
*/ */
private function post_process(){ private function post_process() {
$mainquery = $this->_query; $mainquery = $this->_query;
do{ do{
$count = 0; $count = 0;
$mainquery = preg_replace('/,\\s*\)/imsx',')', $mainquery, -1, $count); $mainquery = preg_replace('/,\\s*\)/imsx',')', $mainquery, -1, $count);
} while ($count > 0); } while ($count > 0);
do { do {
$count = 0; $count = 0;
$mainquery = preg_replace('/\(\\s*?,/imsx', '(', $mainquery, -1, $count); $mainquery = preg_replace('/\(\\s*?,/imsx', '(', $mainquery, -1, $count);
} while ($count > 0); } while ($count > 0);
$return_val[] = $mainquery; $return_val[] = $mainquery;
$return_val = array_merge($return_val, $this->index_queries); $return_val = array_merge($return_val, $this->index_queries);
return $return_val; return $return_val;
} }
/** /**
* Method to add IF NOT EXISTS to query string. * Method to add IF NOT EXISTS to query string.
* *
* This adds IF NOT EXISTS to every query string, which prevent the exception * This adds IF NOT EXISTS to every query string, which prevent the exception
* from being thrown. * from being thrown.
* *
* @access private * @access private
*/ */
private function add_if_not_exists(){ private function add_if_not_exists(){
@ -364,33 +364,33 @@ class CreateQuery{
$this->_query = preg_replace($pattern_table, 'CREATE $1 TABLE IF NOT EXISTS ', $this->_query); $this->_query = preg_replace($pattern_table, 'CREATE $1 TABLE IF NOT EXISTS ', $this->_query);
$pattern_index = '/^\\s*CREATE\\s*(UNIQUE)?\\s*INDEX\\s*(IF NOT EXISTS)?\\s*/ims'; $pattern_index = '/^\\s*CREATE\\s*(UNIQUE)?\\s*INDEX\\s*(IF NOT EXISTS)?\\s*/ims';
for ($i = 0; $i < count($this->index_queries); $i++) { for ($i = 0; $i < count($this->index_queries); $i++) {
$this->index_queries[$i] = preg_replace($pattern_index, 'CREATE $1 INDEX IF NOT EXISTS ', $this->index_queries[$i]); $this->index_queries[$i] = preg_replace($pattern_index, 'CREATE $1 INDEX IF NOT EXISTS ', $this->index_queries[$i]);
} }
} }
/** /**
* Method to strip back quotes. * Method to strip back quotes.
* *
* @access private * @access private
*/ */
private function strip_backticks(){ private function strip_backticks(){
$this->_query = str_replace('`', '', $this->_query); $this->_query = str_replace('`', '', $this->_query);
foreach ($this->index_queries as &$query) { foreach ($this->index_queries as &$query) {
$query = str_replace('`', '', $query); $query = str_replace('`', '', $query);
} }
} }
/** /**
* Method to remove the character set information from within mysql queries. * Method to remove the character set information from within mysql queries.
* *
* This removes DEFAULT CHAR(ACTER) SET and COLLATE, which is meaningless for * This removes DEFAULT CHAR(ACTER) SET and COLLATE, which is meaningless for
* SQLite. * SQLite.
* *
* @access private * @access private
*/ */
private function rewrite_character_set(){ private function rewrite_character_set(){
$pattern_charset = '/\\b(default\\s*character\\s*set|default\\s*charset|character\\s*set)\\s*(?<!\()[^ ]*/im'; $pattern_charset = '/\\b(default\\s*character\\s*set|default\\s*charset|character\\s*set)\\s*(?<!\()[^ ]*/im';
$pattern_collate1 = '/\\s*collate\\s*[^ ]*(?=,)/im'; $pattern_collate1 = '/\\s*collate\\s*[^ ]*(?=,)/im';
$pattern_collate2 = '/\\s*collate\\s*[^ ]*(?<!;)/im'; $pattern_collate2 = '/\\s*collate\\s*[^ ]*(?<!;)/im';
$patterns = array($pattern_charset, $pattern_collate1, $pattern_collate2); $patterns = array($pattern_charset, $pattern_collate1, $pattern_collate2);
$this->_query = preg_replace($patterns, '', $this->_query); $this->_query = preg_replace($patterns, '', $this->_query);
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* This file defines the make_db_sqlite() function. * This file defines the make_db_sqlite() function.
* *
* @package SQLite Integration * @package SQLite Integration
* @author Kojima Toshiyasu * @author Kojima Toshiyasu
*/ */
@ -12,81 +12,81 @@ if (!defined('ABSPATH')) {
} }
/** /**
* Function to create tables according to the schemas of WordPress. * Function to create tables according to the schemas of WordPress.
* *
* This is executed only once while installation. * This is executed only once while installation.
* *
* @return boolean * @return boolean
*/ */
function make_db_sqlite() { function make_db_sqlite() {
include_once PDODIR . 'query_create.class.php'; include_once PDODIR . 'query_create.class.php';
include_once ABSPATH . 'wp-admin/includes/schema.php'; include_once ABSPATH . 'wp-admin/includes/schema.php';
$index_array = array(); $index_array = array();
// ob_end_clean(); //ob_end_clean();
$table_schemas = wp_get_db_schema(); $table_schemas = wp_get_db_schema();
$queries = explode (";", $table_schemas); $queries = explode (";", $table_schemas);
$query_parser = new CreateQuery(); $query_parser = new CreateQuery();
try { try {
$pdo = new PDO('sqlite:'.FQDB, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $pdo = new PDO('sqlite:'.FQDB, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch (PDOException $err) { } catch (PDOException $err) {
$err_data = $err->errorInfo; $err_data = $err->errorInfo;
$message = 'Database connection error!<br />'; $message = 'Database connection error!<br />';
$message .= sprintf("Error message is: %s", $err_data[2]); $message .= sprintf("Error message is: %s", $err_data[2]);
wp_die($message, 'Database Error!'); wp_die($message, 'Database Error!');
} }
try { try {
$pdo->beginTransaction(); $pdo->beginTransaction();
foreach ($queries as $query) { foreach ($queries as $query) {
$query = trim($query); $query = trim($query);
if (empty($query)) if (empty($query))
continue; continue;
$rewritten_query = $query_parser->rewrite_query($query); $rewritten_query = $query_parser->rewrite_query($query);
if (is_array($rewritten_query)) { if (is_array($rewritten_query)) {
$table_query = array_shift($rewritten_query); $table_query = array_shift($rewritten_query);
$index_queries = $rewritten_query; $index_queries = $rewritten_query;
$table_query = trim($table_query); $table_query = trim($table_query);
$pdo->exec($table_query); $pdo->exec($table_query);
// foreach($rewritten_query as $single_query) { //foreach($rewritten_query as $single_query) {
// $single_query = trim($single_query); // $single_query = trim($single_query);
// $pdo->exec($single_query); // $pdo->exec($single_query);
// } //}
} else { } else {
$rewritten_query = trim($rewritten_query); $rewritten_query = trim($rewritten_query);
$pdo->exec($rewritten_query); $pdo->exec($rewritten_query);
} }
} }
$pdo->commit(); $pdo->commit();
if ($index_queries) { if ($index_queries) {
// $query_parser rewrites KEY to INDEX, so we don't need KEY pattern // $query_parser rewrites KEY to INDEX, so we don't need KEY pattern
$pattern = '/CREATE\\s*(UNIQUE\\s*INDEX|INDEX)\\s*IF\\s*NOT\\s*EXISTS\\s*(\\w+)?\\s*.*/im'; $pattern = '/CREATE\\s*(UNIQUE\\s*INDEX|INDEX)\\s*IF\\s*NOT\\s*EXISTS\\s*(\\w+)?\\s*.*/im';
$pdo->beginTransaction(); $pdo->beginTransaction();
foreach ($index_queries as $index_query) { foreach ($index_queries as $index_query) {
preg_match($pattern, $index_query, $match); preg_match($pattern, $index_query, $match);
$index_name = trim($match[2]); $index_name = trim($match[2]);
if (in_array($index_name, $index_array)) { if (in_array($index_name, $index_array)) {
$r = rand(0, 50); $r = rand(0, 50);
$replacement = $index_name . "_$r"; $replacement = $index_name . "_$r";
$index_query = str_ireplace('EXISTS '.$index_name, 'EXISTS '.$replacement, $index_query); $index_query = str_ireplace('EXISTS '.$index_name, 'EXISTS '.$replacement, $index_query);
} else { } else {
$index_array[] = $index_name; $index_array[] = $index_name;
} }
$pdo->exec($index_query); $pdo->exec($index_query);
} }
$pdo->commit(); $pdo->commit();
} }
} catch (PDOException $err) { } catch (PDOException $err) {
$err_data = $err->errorInfo; $err_data = $err->errorInfo;
$err_code = $err_data[1]; $err_code = $err_data[1];
if (5 == $err_code || 6 == $err_code) { if (5 == $err_code || 6 == $err_code) {
// if the database is locked, commit again // if the database is locked, commit again
$pdo->commit(); $pdo->commit();
} else { } else {
$pdo->rollBack(); $pdo->rollBack();
$message = sprintf("Error occured while creating tables or indexes...<br />Query was: %s<br />", var_export($rewritten_query, true)); $message = sprintf("Error occured while creating tables or indexes...<br />Query was: %s<br />", var_export($rewritten_query, true));
$message .= sprintf("Error message is: %s", $err_data[2]); $message .= sprintf("Error message is: %s", $err_data[2]);
wp_die($message, 'Database Error!'); wp_die($message, 'Database Error!');
} }
} }
$query_parser = null; $query_parser = null;

View File

@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
/** /**
* This file defines global constants and defines SQLiteIntegration class. * This file defines global constants and defines SQLiteIntegration class.
* *
* @package SQLite Integration * @package SQLite Integration
* @author Kojima Toshiyasu * @author Kojima Toshiyasu
*/ */
@ -57,13 +57,13 @@ if (defined('WP_PLUGIN_URL')) {
* Defines patch file upload directory. * Defines patch file upload directory.
*/ */
if (defined('UPLOADS')) { if (defined('UPLOADS')) {
define('SQLitePatchDir', UPLOADS . '/patches'); define('SQLitePatchDir', UPLOADS . '/patches');
} else { } else {
if (defined('WP_CONTENT_DIR')) { if (defined('WP_CONTENT_DIR')) {
define('SQLitePatchDir', WP_CONTENT_DIR . '/uploads/patches'); define('SQLitePatchDir', WP_CONTENT_DIR . '/uploads/patches');
} else { } else {
define('SQLitePatchDir', ABSPATH . 'wp-content/uploads/patches'); define('SQLitePatchDir', ABSPATH . 'wp-content/uploads/patches');
} }
} }
/* /*
* Plugin compatibility file in json format. * Plugin compatibility file in json format.
@ -73,16 +73,16 @@ define('SQLiteListFile', SQLiteFilePath . '/utilities/plugin_lists.json');
* Instantiates utility classes. * Instantiates utility classes.
*/ */
if (!class_exists('SQLiteIntegrationUtils')) { if (!class_exists('SQLiteIntegrationUtils')) {
require_once SQLiteFilePath . '/utilities/utility.php'; require_once SQLiteFilePath . '/utilities/utility.php';
$utils = new SQLiteIntegrationUtils(); $utils = new SQLiteIntegrationUtils();
} }
if (!class_exists('SQLiteIntegrationDocument')) { if (!class_exists('SQLiteIntegrationDocument')) {
require_once SQLiteFilePath . '/utilities/documentation.php'; require_once SQLiteFilePath . '/utilities/documentation.php';
$doc = new SQLiteIntegrationDocument(); $doc = new SQLiteIntegrationDocument();
} }
if (!class_exists('PatchUtils')) { if (!class_exists('PatchUtils')) {
require_once SQLiteFilePath . '/utilities/patch.php'; require_once SQLiteFilePath . '/utilities/patch.php';
$patch_utils = new PatchUtils(); $patch_utils = new PatchUtils();
} }
if (!class_exists('DatabaseMaintenance')) { if (!class_exists('DatabaseMaintenance')) {
require_once SQLiteFilePath . '/utilities/database_maintenance.php'; require_once SQLiteFilePath . '/utilities/database_maintenance.php';
@ -91,232 +91,233 @@ if (!class_exists('DatabaseMaintenance')) {
/** /**
* This class is for WordPress Administration Panel. * This class is for WordPress Administration Panel.
* *
* This class and other utility classes don't affect the base functionality * This class and other utility classes don't affect the base functionality
* of the plugin. * of the plugin.
* *
*/ */
class SQLiteIntegration { class SQLiteIntegration {
/** /**
* Constructor. * Constructor.
* *
* This constructor does everything needed for the administration panel. * This constructor does everything needed for the administration panel.
* *
* @param no parameter is provided. * @param no parameter is provided.
*/ */
function __construct() { function __construct() {
if (function_exists('register_activation_hook')) { if (function_exists('register_activation_hook')) {
register_activation_hook(__FILE__, array($this, 'install')); register_activation_hook(__FILE__, array($this, 'install'));
} }
if (function_exists('register_deactivation_hook')) { if (function_exists('register_deactivation_hook')) {
} ;
if (function_exists('register_uninstall_hook')) { }
register_uninstall_hook(__FILE__, array('SQLiteIntegration', 'uninstall')); if (function_exists('register_uninstall_hook')) {
} register_uninstall_hook(__FILE__, array('SQLiteIntegration', 'uninstall'));
if (function_exists('is_multisite') && is_multisite()) { }
add_action('network_admin_menu', array($this, 'add_network_pages')); if (function_exists('is_multisite') && is_multisite()) {
add_action('network_admin_notices', array('SQLiteIntegrationUtils', 'show_admin_notice')); add_action('network_admin_menu', array($this, 'add_network_pages'));
} else { add_action('network_admin_notices', array('SQLiteIntegrationUtils', 'show_admin_notice'));
add_action('admin_menu', array($this, 'add_pages')); } else {
add_action('admin_notices', array('SQLiteIntegrationUtils', 'show_admin_notice')); add_action('admin_menu', array($this, 'add_pages'));
} add_action('admin_notices', array('SQLiteIntegrationUtils', 'show_admin_notice'));
// See the docstring for download_backup_db() in utilities/utility.php }
// We need this registration process. // See the docstring for download_backup_db() in utilities/utility.php
add_action('admin_init', array('SQLiteIntegrationUtils', 'download_backup_db')); // We need this registration process.
add_action('plugins_loaded', array($this, 'textdomain_init')); add_action('admin_init', array('SQLiteIntegrationUtils', 'download_backup_db'));
} add_action('plugins_loaded', array($this, 'textdomain_init'));
}
/** /**
* Method to install on multisite or single site. * Method to install on multisite or single site.
* *
* There really is nothing to install for now. It is for future use... * There really is nothing to install for now. It is for future use...
* *
* @param no parameter is provided. * @param no parameter is provided.
* @return returns null. * @return returns null.
*/ */
function install() { function install() {
global $wpdb; global $wpdb;
if (function_exists('is_multisite') && is_multisite()) { if (function_exists('is_multisite') && is_multisite()) {
$old_blog = $wpdb->blogid; $old_blog = $wpdb->blogid;
$blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach ($blog_ids as $blog_id) { foreach ($blog_ids as $blog_id) {
switch_to_blog($blog_id); switch_to_blog($blog_id);
$this->_install(); $this->_install();
} }
switch_to_blog($old_blog); switch_to_blog($old_blog);
return; return;
} else { } else {
$this->_install(); $this->_install();
return; return;
} }
} }
/**
* Method to install something.
*
* We have nothing to do for now.
* We show menu and documents only to the network administrator.
*
* @param no parameter is provided.
* @return no return values.
*/
function _install() {
}
/**
* Method to uninstall plugin.
*
* This will remove wp-content/db.php and wp-content/patches direcotry.
* If you migrate the site to the sever with MySQL, you have only to
* migrate the data in the database.
*
* @param no parameter is provided.
* @return no return values.
*/
function uninstall() {
// remove patch files and patch directory
if (file_exists(SQLitePatchDir) && is_dir(SQLitePatchDir)) {
$dir_handle = opendir(SQLitePatchDir);
while (($file_name = readdir($dir_handle)) !== false) {
if ($file_name != '.' && $file_name != '..') {
unlink(SQLitePatchDir.'/'.$file_name);
}
}
rmdir(SQLitePatchDir);
}
// remove wp-content/db.php
if (defined('WP_CONTENT_DIR')) {
$target = WP_CONTENT_DIR . 'db.php';
} else {
$target = ABSPATH . 'wp-content/db.php';
}
if (file_exists($target)) {
unlink($target);
}
}
/**
* Method to manipulate the admin panel, stylesheet and JavaScript.
*
* We use class method to show pages and want to load style files and script
* files only in our plugin documents, so we need add_submenu_page with parent
* slug set to null. This means that menu items are added but hidden from the
* users.
*
* @param no parameter is provided.
* @return no return values.
*/
function add_pages() {
global $utils, $doc, $patch_utils, $maintenance;
if (function_exists('add_options_page')) {
$welcome_page = add_options_page(__('SQLite Integration'), __('SQLite Integration'), 'manage_options', 'sqlite-integration', array($utils, 'welcome'));
$util_page = add_submenu_page(null, 'System Info', 'System Info', 'manage_options', 'sys-info', array($utils, 'show_utils'));
$edit_db = add_submenu_page(null, 'Setting File', 'Setting File', 'manage_options', 'setting-file', array($utils, 'edit_db_file'));
$doc_page = add_submenu_page(null, 'Documentation', 'Documentation', 'manage_options', 'doc', array($doc, 'show_doc'));
$patch_page = add_submenu_page(null, 'Patch Utility', 'Patch Utility', 'manage_options', 'patch', array($patch_utils, 'show_patch_page'));
$maintenance_page = add_submenu_page(null, 'DB Maintenance', 'DB Maintenance', 'manage_options', 'maintenance', array($maintenance, 'show_maintenance_page'));
add_action('admin_print_styles-'.$welcome_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$util_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$edit_db, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$doc_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$patch_page, array($this, 'add_style_sheet'));
add_action('admin_print_scripts-'.$util_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$doc_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$patch_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$edit_db, array($this, 'add_sqlite_script'));
add_action('admin_print_styles-'.$maintenance_page, array($this, 'add_style_sheet'));
}
}
/**
* Method to manipulate network admin panel.
*
* Capability is set to manage_network_options.
*
* @param no parameter is provided.
* @return no return values.
*/
function add_network_pages() {
global $utils, $doc, $patch_utils, $maintenance;
if (function_exists('add_options_page')) {
$welcome_page = add_submenu_page('settings.php', __('SQLite Integration'), __('SQLite Integration'), 'manage_network_options', 'sqlite-integration', array($utils, 'welcome'));
$util_page = add_submenu_page(null, 'System Info', 'System Info', 'manage_network_options', 'sys-info', array($utils, 'show_utils'));
$edit_db = add_submenu_page(null, 'Setting File', 'Setting File', 'manage_network_options', 'setting-file', array($utils, 'edit_db_file'));
$doc_page = add_submenu_page(null, 'Documentation', 'Documentation', 'manage_network_options', 'doc', array($doc, 'show_doc'));
$patch_page = add_submenu_page(null, 'Patch Utility', 'Patch Utility', 'manage_network_options', 'patch', array($patch_utils, 'show_patch_page'));
$maintenance_page = add_submenu_page(null, 'DB Maintenance', 'DB Maintenance', 'manage_network_options', 'maintenance', array($maintenance, 'show_maintenance_page'));
add_action('admin_print_styles-'.$welcome_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$util_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$edit_db, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$doc_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$patch_page, array($this, 'add_style_sheet'));
add_action('admin_print_scripts-'.$util_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$doc_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$patch_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$edit_db, array($this, 'add_sqlite_script'));
add_action('admin_print_styles-'.$maintenance_page, array($this, 'add_style_sheet'));
}
}
/**
* Method to initialize textdomain.
*
* Japanese catalog is only available.
*
* @param no parameter is provided.
* @return no return values.
*/
function textdomain_init() {
global $utils;
// $current_locale = get_locale();
// if (!empty($current_locale)) {
// $moFile = dirname(__FILE__) . "/languages/sqlite-wordpress-" . $current_locale . ".mo";
// if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('sqlite-wordpress', $moFile);
// }
load_plugin_textdomain($utils->text_domain, false, SQLiteDir.'/languages/');
}
/** /**
* Method to initialize stylesheet on the admin panel. * Method to install something.
* *
* This determines which stylesheet to use depending on the users' choice * We have nothing to do for now.
* of admin_color. Each stylesheet imports style.css and change the color * We show menu and documents only to the network administrator.
* of the admin dashboard. *
* * @param no parameter is provided.
* @param no parameter is provided. * @return no return values.
* @return no return values. */
*/ function _install() {
function add_style_sheet() { }
global $current_user;
get_currentuserinfo(); /**
$admin_color = get_user_meta($current_user->ID, 'admin_color', true); * Method to uninstall plugin.
if ($admin_color == 'fresh') { *
$stylesheet_file = 'style.min.css'; * This will remove wp-content/db.php and wp-content/patches direcotry.
} else { * If you migrate the site to the sever with MySQL, you have only to
$stylesheet_file = $admin_color . '.min.css'; * migrate the data in the database.
} *
$style_url = SQLiteUrl . '/styles/' . $stylesheet_file; * @param no parameter is provided.
$style_file = SQLiteFilePath . '/styles/' . $stylesheet_file; * @return no return values.
if (file_exists($style_file)) { */
wp_enqueue_style('sqlite_integration_stylesheet', $style_url); function uninstall() {
} // remove patch files and patch directory
} if (file_exists(SQLitePatchDir) && is_dir(SQLitePatchDir)) {
/** $dir_handle = opendir(SQLitePatchDir);
* Method to register the JavaScript file. while (($file_name = readdir($dir_handle)) !== false) {
* if ($file_name != '.' && $file_name != '..') {
* To register the JavaScript file. It's only for the admin dashboard. unlink(SQLitePatchDir.'/'.$file_name);
* It won't included in web pages. }
* }
* @param no parameter is provided. rmdir(SQLitePatchDir);
* @return no return value. }
*/ // remove wp-content/db.php
function add_sqlite_script() { if (defined('WP_CONTENT_DIR')) {
$script_url = SQLiteUrl . '/js/sqlite.min.js'; $target = WP_CONTENT_DIR . 'db.php';
$script_file = SQLiteFilePath . '/js/sqlite.min.js'; } else {
if (file_exists($script_file)) { $target = ABSPATH . 'wp-content/db.php';
wp_enqueue_script('sqlite-integration', $script_url, 'jquery'); }
} if (file_exists($target)) {
} unlink($target);
}
}
/**
* Method to manipulate the admin panel, stylesheet and JavaScript.
*
* We use class method to show pages and want to load style files and script
* files only in our plugin documents, so we need add_submenu_page with parent
* slug set to null. This means that menu items are added but hidden from the
* users.
*
* @param no parameter is provided.
* @return no return values.
*/
function add_pages() {
global $utils, $doc, $patch_utils, $maintenance;
if (function_exists('add_options_page')) {
$welcome_page = add_options_page(__('SQLite Integration'), __('SQLite Integration'), 'manage_options', 'sqlite-integration', array($utils, 'welcome'));
$util_page = add_submenu_page(null, 'System Info', 'System Info', 'manage_options', 'sys-info', array($utils, 'show_utils'));
$edit_db = add_submenu_page(null, 'Setting File', 'Setting File', 'manage_options', 'setting-file', array($utils, 'edit_db_file'));
$doc_page = add_submenu_page(null, 'Documentation', 'Documentation', 'manage_options', 'doc', array($doc, 'show_doc'));
$patch_page = add_submenu_page(null, 'Patch Utility', 'Patch Utility', 'manage_options', 'patch', array($patch_utils, 'show_patch_page'));
$maintenance_page = add_submenu_page(null, 'DB Maintenance', 'DB Maintenance', 'manage_options', 'maintenance', array($maintenance, 'show_maintenance_page'));
add_action('admin_print_styles-'.$welcome_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$util_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$edit_db, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$doc_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$patch_page, array($this, 'add_style_sheet'));
add_action('admin_print_scripts-'.$util_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$doc_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$patch_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$edit_db, array($this, 'add_sqlite_script'));
add_action('admin_print_styles-'.$maintenance_page, array($this, 'add_style_sheet'));
}
}
/**
* Method to manipulate network admin panel.
*
* Capability is set to manage_network_options.
*
* @param no parameter is provided.
* @return no return values.
*/
function add_network_pages() {
global $utils, $doc, $patch_utils, $maintenance;
if (function_exists('add_options_page')) {
$welcome_page = add_submenu_page('settings.php', __('SQLite Integration'), __('SQLite Integration'), 'manage_network_options', 'sqlite-integration', array($utils, 'welcome'));
$util_page = add_submenu_page(null, 'System Info', 'System Info', 'manage_network_options', 'sys-info', array($utils, 'show_utils'));
$edit_db = add_submenu_page(null, 'Setting File', 'Setting File', 'manage_network_options', 'setting-file', array($utils, 'edit_db_file'));
$doc_page = add_submenu_page(null, 'Documentation', 'Documentation', 'manage_network_options', 'doc', array($doc, 'show_doc'));
$patch_page = add_submenu_page(null, 'Patch Utility', 'Patch Utility', 'manage_network_options', 'patch', array($patch_utils, 'show_patch_page'));
$maintenance_page = add_submenu_page(null, 'DB Maintenance', 'DB Maintenance', 'manage_network_options', 'maintenance', array($maintenance, 'show_maintenance_page'));
add_action('admin_print_styles-'.$welcome_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$util_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$edit_db, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$doc_page, array($this, 'add_style_sheet'));
add_action('admin_print_styles-'.$patch_page, array($this, 'add_style_sheet'));
add_action('admin_print_scripts-'.$util_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$doc_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$patch_page, array($this, 'add_sqlite_script'));
add_action('admin_print_scripts-'.$edit_db, array($this, 'add_sqlite_script'));
add_action('admin_print_styles-'.$maintenance_page, array($this, 'add_style_sheet'));
}
}
/**
* Method to initialize textdomain.
*
* Japanese catalog is only available.
*
* @param no parameter is provided.
* @return no return values.
*/
function textdomain_init() {
global $utils;
//$current_locale = get_locale();
//if (!empty($current_locale)) {
// $moFile = dirname(__FILE__) . "/languages/sqlite-wordpress-" . $current_locale . ".mo";
// if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('sqlite-wordpress', $moFile);
//}
load_plugin_textdomain($utils->text_domain, false, SQLiteDir.'/languages/');
}
/**
* Method to initialize stylesheet on the admin panel.
*
* This determines which stylesheet to use depending on the users' choice
* of admin_color. Each stylesheet imports style.css and change the color
* of the admin dashboard.
*
* @param no parameter is provided.
* @return no return values.
*/
function add_style_sheet() {
global $current_user;
get_currentuserinfo();
$admin_color = get_user_meta($current_user->ID, 'admin_color', true);
if ($admin_color == 'fresh') {
$stylesheet_file = 'style.min.css';
} else {
$stylesheet_file = $admin_color . '.min.css';
}
$style_url = SQLiteUrl . '/styles/' . $stylesheet_file;
$style_file = SQLiteFilePath . '/styles/' . $stylesheet_file;
if (file_exists($style_file)) {
wp_enqueue_style('sqlite_integration_stylesheet', $style_url);
}
}
/**
* Method to register the JavaScript file.
*
* To register the JavaScript file. It's only for the admin dashboard.
* It won't included in web pages.
*
* @param no parameter is provided.
* @return no return value.
*/
function add_sqlite_script() {
$script_url = SQLiteUrl . '/js/sqlite.min.js';
$script_file = SQLiteFilePath . '/js/sqlite.min.js';
if (file_exists($script_file)) {
wp_enqueue_script('sqlite-integration', $script_url, 'jquery');
}
}
} }
/* this is enough for initialization */ /* this is enough for initialization */

View File

@ -1,29 +1,29 @@
<?php <?php
/** /**
* This file defines DatabaseMaintenance class. * This file defines DatabaseMaintenance class.
* *
* When WordPress was upgraded from 3.5.x to 3.6, SQLite Integration couldn't manipulate * When WordPress was upgraded from 3.5.x to 3.6, SQLite Integration couldn't manipulate
* dbDelta() function of WordPress as expected. As a result, there are some tables whose * dbDelta() function of WordPress as expected. As a result, there are some tables whose
* default values are missing. * default values are missing.
* *
* This file is for temporary use and will be removed or changed in the future release. * This file is for temporary use and will be removed or changed in the future release.
* *
* @package SQLite Integration * @package SQLite Integration
* @author Kojima Toshiyasu * @author Kojima Toshiyasu
*/ */
/** /**
* This class provide the methods to check the table schemas and restore if necessary. * This class provide the methods to check the table schemas and restore if necessary.
* *
* Each method is a private function except the one to show admin page. * Each method is a private function except the one to show admin page.
* *
*/ */
class DatabaseMaintenance { class DatabaseMaintenance {
/** /**
* Method to check the table schemas. * Method to check the table schemas.
* *
* If there are any broken tables, it returns the array of the table names to be fixed. * If there are any broken tables, it returns the array of the table names to be fixed.
* If not, it returns true. * If not, it returns true.
* *
* @return boolean|multitype:string * @return boolean|multitype:string
* @access private * @access private
*/ */
@ -32,134 +32,134 @@ class DatabaseMaintenance {
$results_table = array(); $results_table = array();
$columns_to_check = array( $columns_to_check = array(
$wpdb->prefix.'commentmeta' => array( $wpdb->prefix.'commentmeta' => array(
'comment_id' => '\'0\'', 'comment_id' => '\'0\'',
'meta_key' => 'NULL' 'meta_key' => 'NULL'
), ),
$wpdb->prefix.'comments' => array( $wpdb->prefix.'comments' => array(
'comment_post_ID' => '\'0\'', 'comment_post_ID' => '\'0\'',
'comment_author_email' => '\'\'', 'comment_author_email' => '\'\'',
'comment_author_url' => '\'\'', 'comment_author_url' => '\'\'',
'comment_author_IP' => '\'\'', 'comment_author_IP' => '\'\'',
'comment_date_gmt' => '\'0000-00-00 00:00:00\'', 'comment_date_gmt' => '\'0000-00-00 00:00:00\'',
'comment_date' => '\'0000-00-00 00:00:00\'', 'comment_date' => '\'0000-00-00 00:00:00\'',
'comment_karma' => '\'0\'', 'comment_karma' => '\'0\'',
'comment_approved' => '\'1\'', 'comment_approved' => '\'1\'',
'comment_agent' => '\'\'', 'comment_agent' => '\'\'',
'comment_type' => '\'\'', 'comment_type' => '\'\'',
'comment_parent' => '\'0\'', 'comment_parent' => '\'0\'',
'user_id' => '\'0\'' 'user_id' => '\'0\''
), ),
$wpdb->prefix.'links' => array( $wpdb->prefix.'links' => array(
'link_url' => '\'\'', 'link_url' => '\'\'',
'link_name' => '\'\'', 'link_name' => '\'\'',
'link_image' => '\'\'', 'link_image' => '\'\'',
'link_target' => '\'\'', 'link_target' => '\'\'',
'link_description' => '\'\'', 'link_description' => '\'\'',
'link_visible' => '\'Y\'', 'link_visible' => '\'Y\'',
'link_owner' => '\'1\'', 'link_owner' => '\'1\'',
'link_rating' => '\'0\'', 'link_rating' => '\'0\'',
'link_updated' => '\'0000-00-00 00:00:00\'', 'link_updated' => '\'0000-00-00 00:00:00\'',
'link_rel' => '\'\'', 'link_rel' => '\'\'',
'link_rss' => '\'\'' 'link_rss' => '\'\''
), ),
$wpdb->prefix.'options' => array( $wpdb->prefix.'options' => array(
'option_name' => '\'\'', 'option_name' => '\'\'',
'autoload' => '\'yes\'' 'autoload' => '\'yes\''
), ),
$wpdb->prefix.'postmeta' => array( $wpdb->prefix.'postmeta' => array(
'post_id' => '\'0\'', 'post_id' => '\'0\'',
'meta_key' => 'NULL' 'meta_key' => 'NULL'
), ),
$wpdb->prefix.'posts' => array( $wpdb->prefix.'posts' => array(
'post_author' => '\'0\'', 'post_author' => '\'0\'',
'post_date_gmt' => '\'0000-00-00 00:00:00\'', 'post_date_gmt' => '\'0000-00-00 00:00:00\'',
'post_date' => '\'0000-00-00 00:00:00\'', 'post_date' => '\'0000-00-00 00:00:00\'',
'post_status' => '\'publish\'', 'post_status' => '\'publish\'',
'comment_status' => '\'open\'', 'comment_status' => '\'open\'',
'ping_status' => '\'open\'', 'ping_status' => '\'open\'',
'post_password' => '\'\'', 'post_password' => '\'\'',
'post_name' => '\'\'', 'post_name' => '\'\'',
'post_modified_gmt' => '\'0000-00-00 00:00:00\'', 'post_modified_gmt' => '\'0000-00-00 00:00:00\'',
'post_modified' => '\'0000-00-00 00:00:00\'', 'post_modified' => '\'0000-00-00 00:00:00\'',
'post_parent' => '\'0\'', 'post_parent' => '\'0\'',
'guid' => '\'\'', 'guid' => '\'\'',
'menu_order' => '\'0\'', 'menu_order' => '\'0\'',
'post_type' => '\'post\'', 'post_type' => '\'post\'',
'post_mime_type' => '\'\'', 'post_mime_type' => '\'\'',
'comment_count' => '\'0\'' 'comment_count' => '\'0\''
), ),
$wpdb->prefix.'term_relationships' => array( $wpdb->prefix.'term_relationships' => array(
'term_order' => '0' 'term_order' => '0'
), ),
$wpdb->prefix.'term_taxonomy' => array( $wpdb->prefix.'term_taxonomy' => array(
'taxonomy' => '\'\'', 'taxonomy' => '\'\'',
'parent' => '0', 'parent' => '0',
'count' => '0' 'count' => '0'
), ),
$wpdb->prefix.'terms' => array( $wpdb->prefix.'terms' => array(
'name' => '\'\'', 'name' => '\'\'',
'slug' => '\'\'', 'slug' => '\'\'',
'term_group' => '0' 'term_group' => '0'
), ),
$wpdb->prefix.'users' => array( $wpdb->prefix.'users' => array(
'user_login' => '\'\'', 'user_login' => '\'\'',
'user_pass' => '\'\'', 'user_pass' => '\'\'',
'user_nicename' => '\'\'', 'user_nicename' => '\'\'',
'user_email' => '\'\'', 'user_email' => '\'\'',
'user_url' => '\'\'', 'user_url' => '\'\'',
'user_registered' => '\'0000-00-00 00:00:00\'', 'user_registered' => '\'0000-00-00 00:00:00\'',
'user_activation_key' => '\'\'', 'user_activation_key' => '\'\'',
'user_status' => '\'0\'', 'user_status' => '\'0\'',
'display_name' => '\'\'', 'display_name' => '\'\'',
// for network install // for network install
'spam' => '\'0\'', 'spam' => '\'0\'',
'deleted' => '\'0\'' 'deleted' => '\'0\''
), ),
$wpdb->prefix.'usermeta' => array( $wpdb->prefix.'usermeta' => array(
'user_id' => '\'0\'', 'user_id' => '\'0\'',
'meta_key' => 'NULL', 'meta_key' => 'NULL',
), ),
// for network install // for network install
$wpdb->prefix.'blog_versions' => array( $wpdb->prefix.'blog_versions' => array(
'blog_id' => '\'0\'', 'blog_id' => '\'0\'',
'db_version' => '\'\'', 'db_version' => '\'\'',
'last_updated' => '\'0000-00-00 00:00:00\'' 'last_updated' => '\'0000-00-00 00:00:00\''
), ),
$wpdb->prefix.'blogs' => array( $wpdb->prefix.'blogs' => array(
'site_id' => '\'0\'', 'site_id' => '\'0\'',
'domain' => '\'\'', 'domain' => '\'\'',
'path' => '\'\'', 'path' => '\'\'',
'registered' => '\'0000-00-00 00:00:00\'', 'registered' => '\'0000-00-00 00:00:00\'',
'last_updated' => '\'0000-00-00 00:00:00\'', 'last_updated' => '\'0000-00-00 00:00:00\'',
'public' => '\'1\'', 'public' => '\'1\'',
'mature' => '\'0\'', 'mature' => '\'0\'',
'spam' => '\'0\'', 'spam' => '\'0\'',
'deleted' => '\'0\'', 'deleted' => '\'0\'',
'lang_id' => '\'0\'' 'lang_id' => '\'0\''
), ),
$wpdb->prefix.'registration_log' => array( $wpdb->prefix.'registration_log' => array(
'email' => '\'\'', 'email' => '\'\'',
'IP' => '\'\'', 'IP' => '\'\'',
'blog_id' => '\'0\'', 'blog_id' => '\'0\'',
'date_registered' => '\'0000-00-00 00:00:00\'' 'date_registered' => '\'0000-00-00 00:00:00\''
), ),
$wpdb->prefix.'signups' => array( $wpdb->prefix.'signups' => array(
'domain' => '\'\'', 'domain' => '\'\'',
'path' => '\'\'', 'path' => '\'\'',
'user_login' => '\'\'', 'user_login' => '\'\'',
'user_email' => '\'\'', 'user_email' => '\'\'',
'registered' => '\'0000-00-00 00:00:00\'', 'registered' => '\'0000-00-00 00:00:00\'',
'activated' => '\'0000-00-00 00:00:00\'', 'activated' => '\'0000-00-00 00:00:00\'',
'active' => '\'0\'', 'active' => '\'0\'',
'activation_key' => '\'\'', 'activation_key' => '\'\'',
), ),
$wpdb->prefix.'site' => array( $wpdb->prefix.'site' => array(
'domain' => '\'\'', 'domain' => '\'\'',
'path' => '\'\'' 'path' => '\'\''
), ),
$wpdb->prefix.'sitemeta' => array( $wpdb->prefix.'sitemeta' => array(
'site_id' => '\'0\'', 'site_id' => '\'0\'',
'meta_key' => 'NULL', 'meta_key' => 'NULL',
) )
); );
$tables = $wpdb->tables('all'); $tables = $wpdb->tables('all');
@ -180,10 +180,10 @@ class DatabaseMaintenance {
} }
/** /**
* Method to do the fixing job to the broken tables. * Method to do the fixing job to the broken tables.
* *
* If the job succeeded, it returns string of success message. * If the job succeeded, it returns string of success message.
* If failed, it returns the array of the failed query for debugging. * If failed, it returns the array of the failed query for debugging.
* *
* @return string|array of string * @return string|array of string
* @access private * @access private
*/ */
@ -191,148 +191,148 @@ class DatabaseMaintenance {
global $wpdb, $wp_version, $utils; global $wpdb, $wp_version, $utils;
$global_schema_to_change = array( $global_schema_to_change = array(
$wpdb->prefix.'commentmeta' => array( $wpdb->prefix.'commentmeta' => array(
"comment_id bigint(20) unsigned NOT NULL default '0'", "comment_id bigint(20) unsigned NOT NULL default '0'",
"meta_key varchar(255) default NULL", "meta_key varchar(255) default NULL",
"meta_value longtext" "meta_value longtext"
), ),
$wpdb->prefix.'comments' => array( $wpdb->prefix.'comments' => array(
"comment_post_ID bigint(20) unsigned NOT NULL default '0'", "comment_post_ID bigint(20) unsigned NOT NULL default '0'",
"comment_author_email varchar(100) NOT NULL default ''", "comment_author_email varchar(100) NOT NULL default ''",
"comment_author_url varchar(200) NOT NULL default ''", "comment_author_url varchar(200) NOT NULL default ''",
"comment_author_IP varchar(100) NOT NULL default ''", "comment_author_IP varchar(100) NOT NULL default ''",
"comment_date datetime NOT NULL default '0000-00-00 00:00:00'", "comment_date datetime NOT NULL default '0000-00-00 00:00:00'",
"comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00'", "comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00'",
"comment_karma int(11) NOT NULL default '0'", "comment_karma int(11) NOT NULL default '0'",
"comment_approved varchar(20) NOT NULL default '1'", "comment_approved varchar(20) NOT NULL default '1'",
"comment_agent varchar(255) NOT NULL default ''", "comment_agent varchar(255) NOT NULL default ''",
"comment_type varchar(20) NOT NULL default ''", "comment_type varchar(20) NOT NULL default ''",
"comment_parent bigint(20) unsigned NOT NULL default '0'", "comment_parent bigint(20) unsigned NOT NULL default '0'",
"user_id bigint(20) unsigned NOT NULL default '0'" "user_id bigint(20) unsigned NOT NULL default '0'"
), ),
$wpdb->prefix.'links' => array( $wpdb->prefix.'links' => array(
"link_url varchar(255) NOT NULL default ''", "link_url varchar(255) NOT NULL default ''",
"link_name varchar(255) NOT NULL default ''", "link_name varchar(255) NOT NULL default ''",
"link_image varchar(255) NOT NULL default ''", "link_image varchar(255) NOT NULL default ''",
"link_target varchar(25) NOT NULL default ''", "link_target varchar(25) NOT NULL default ''",
"link_description varchar(255) NOT NULL default ''", "link_description varchar(255) NOT NULL default ''",
"link_visible varchar(20) NOT NULL default 'Y'", "link_visible varchar(20) NOT NULL default 'Y'",
"link_owner bigint(20) unsigned NOT NULL default '1'", "link_owner bigint(20) unsigned NOT NULL default '1'",
"link_rating int(11) NOT NULL default '0'", "link_rating int(11) NOT NULL default '0'",
"link_updated datetime NOT NULL default '0000-00-00 00:00:00'", "link_updated datetime NOT NULL default '0000-00-00 00:00:00'",
"link_rel varchar(255) NOT NULL default ''", "link_rel varchar(255) NOT NULL default ''",
"link_notes mediumtext NOT NULL", "link_notes mediumtext NOT NULL",
"link_rss varchar(255) NOT NULL default ''" "link_rss varchar(255) NOT NULL default ''"
), ),
$wpdb->prefix.'options' => array( $wpdb->prefix.'options' => array(
"option_name varchar(64) NOT NULL default ''", "option_name varchar(64) NOT NULL default ''",
"option_value longtext NOT NULL", "option_value longtext NOT NULL",
"autoload varchar(20) NOT NULL default 'yes'" "autoload varchar(20) NOT NULL default 'yes'"
), ),
$wpdb->prefix.'postmeta' => array( $wpdb->prefix.'postmeta' => array(
"post_id bigint(20) unsigned NOT NULL default '0'", "post_id bigint(20) unsigned NOT NULL default '0'",
"meta_key varchar(255) default NULL", "meta_key varchar(255) default NULL",
"meta_value longtext" "meta_value longtext"
), ),
$wpdb->prefix.'posts' => array( $wpdb->prefix.'posts' => array(
"post_author bigint(20) unsigned NOT NULL default '0'", "post_author bigint(20) unsigned NOT NULL default '0'",
"post_date datetime NOT NULL default '0000-00-00 00:00:00'", "post_date datetime NOT NULL default '0000-00-00 00:00:00'",
"post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00'", "post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00'",
"post_status varchar(20) NOT NULL default 'publish'", "post_status varchar(20) NOT NULL default 'publish'",
"comment_status varchar(20) NOT NULL default 'open'", "comment_status varchar(20) NOT NULL default 'open'",
"ping_status varchar(20) NOT NULL default 'open'", "ping_status varchar(20) NOT NULL default 'open'",
"post_password varchar(20) NOT NULL default ''", "post_password varchar(20) NOT NULL default ''",
"post_name varchar(200) NOT NULL default ''", "post_name varchar(200) NOT NULL default ''",
"post_modified datetime NOT NULL default '0000-00-00 00:00:00'", "post_modified datetime NOT NULL default '0000-00-00 00:00:00'",
"post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00'", "post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00'",
"post_content_filtered longtext NOT NULL", "post_content_filtered longtext NOT NULL",
"post_parent bigint(20) unsigned NOT NULL default '0'", "post_parent bigint(20) unsigned NOT NULL default '0'",
"guid varchar(255) NOT NULL default ''", "guid varchar(255) NOT NULL default ''",
"menu_order int(11) NOT NULL default '0'", "menu_order int(11) NOT NULL default '0'",
"post_type varchar(20) NOT NULL default 'post'", "post_type varchar(20) NOT NULL default 'post'",
"post_mime_type varchar(100) NOT NULL default ''", "post_mime_type varchar(100) NOT NULL default ''",
"comment_count bigint(20) NOT NULL default '0'" "comment_count bigint(20) NOT NULL default '0'"
), ),
$wpdb->prefix.'term_relationships' => array( $wpdb->prefix.'term_relationships' => array(
"term_order int(11) NOT NULL default 0" "term_order int(11) NOT NULL default 0"
), ),
$wpdb->prefix.'term_taxonomy' => array( $wpdb->prefix.'term_taxonomy' => array(
"taxonomy varchar(32) NOT NULL default ''", "taxonomy varchar(32) NOT NULL default ''",
"description longtext NOT NULL", "description longtext NOT NULL",
"parent bigint(20) unsigned NOT NULL default 0", "parent bigint(20) unsigned NOT NULL default 0",
"count bigint(20) NOT NULL default 0" "count bigint(20) NOT NULL default 0"
), ),
$wpdb->prefix.'terms' => array( $wpdb->prefix.'terms' => array(
"name varchar(200) NOT NULL default ''", "name varchar(200) NOT NULL default ''",
"slug varchar(200) NOT NULL default ''", "slug varchar(200) NOT NULL default ''",
"term_group bigint(10) NOT NULL default 0" "term_group bigint(10) NOT NULL default 0"
), ),
$wpdb->prefix.'users' => array( $wpdb->prefix.'users' => array(
"user_login varchar(60) NOT NULL default ''", "user_login varchar(60) NOT NULL default ''",
"user_pass varchar(64) NOT NULL default ''", "user_pass varchar(64) NOT NULL default ''",
"user_nicename varchar(50) NOT NULL default ''", "user_nicename varchar(50) NOT NULL default ''",
"user_email varchar(100) NOT NULL default ''", "user_email varchar(100) NOT NULL default ''",
"user_url varchar(100) NOT NULL default ''", "user_url varchar(100) NOT NULL default ''",
"user_registered datetime NOT NULL default '0000-00-00 00:00:00'", "user_registered datetime NOT NULL default '0000-00-00 00:00:00'",
"user_activation_key varchar(60) NOT NULL default ''", "user_activation_key varchar(60) NOT NULL default ''",
"user_status int(11) NOT NULL default '0'", "user_status int(11) NOT NULL default '0'",
"display_name varchar(250) NOT NULL default ''" "display_name varchar(250) NOT NULL default ''"
), ),
$wpdb->prefix.'usermeta' => array( $wpdb->prefix.'usermeta' => array(
"user_id bigint(20) unsigned NOT NULL default '0'", "user_id bigint(20) unsigned NOT NULL default '0'",
"meta_key varchar(255) default NULL", "meta_key varchar(255) default NULL",
"meta_value longtext" "meta_value longtext"
) )
); );
$network_schema_to_change = array( $network_schema_to_change = array(
$wpdb->prefix.'blog_versions' => array( $wpdb->prefix.'blog_versions' => array(
"blog_id bigint(20) NOT NULL default '0'", "blog_id bigint(20) NOT NULL default '0'",
"db_version varchar(20) NOT NULL default ''", "db_version varchar(20) NOT NULL default ''",
"last_updated datetime NOT NULL default '0000-00-00 00:00:00'" "last_updated datetime NOT NULL default '0000-00-00 00:00:00'"
), ),
$wpdb->prefix.'blogs' => array( $wpdb->prefix.'blogs' => array(
"site_id bigint(20) NOT NULL default '0'", "site_id bigint(20) NOT NULL default '0'",
"domain varchar(200) NOT NULL default ''", "domain varchar(200) NOT NULL default ''",
"path varchar(100) NOT NULL default ''", "path varchar(100) NOT NULL default ''",
"registered datetime NOT NULL default '0000-00-00 00:00:00'", "registered datetime NOT NULL default '0000-00-00 00:00:00'",
"last_updated datetime NOT NULL default '0000-00-00 00:00:00'", "last_updated datetime NOT NULL default '0000-00-00 00:00:00'",
"public tinyint(2) NOT NULL default '1'", "public tinyint(2) NOT NULL default '1'",
"mature tinyint(2) NOT NULL default '0'", "mature tinyint(2) NOT NULL default '0'",
"spam tinyint(2) NOT NULL default '0'", "spam tinyint(2) NOT NULL default '0'",
"deleted tinyint(2) NOT NULL default '0'", "deleted tinyint(2) NOT NULL default '0'",
"lang_id int(11) NOT NULL default '0'" "lang_id int(11) NOT NULL default '0'"
), ),
$wpdb->prefix.'registration_log' => array( $wpdb->prefix.'registration_log' => array(
"email varchar(255) NOT NULL default ''", "email varchar(255) NOT NULL default ''",
"IP varchar(30) NOT NULL default ''", "IP varchar(30) NOT NULL default ''",
"blog_id bigint(20) NOT NULL default '0'", "blog_id bigint(20) NOT NULL default '0'",
"date_registered datetime NOT NULL default '0000-00-00 00:00:00'" "date_registered datetime NOT NULL default '0000-00-00 00:00:00'"
), ),
$wpdb->prefix.'signups' => array( $wpdb->prefix.'signups' => array(
"domain varchar(200) NOT NULL default ''", "domain varchar(200) NOT NULL default ''",
"path varchar(100) NOT NULL default ''", "path varchar(100) NOT NULL default ''",
"title longtext NOT NULL", "title longtext NOT NULL",
"user_login varchar(60) NOT NULL default ''", "user_login varchar(60) NOT NULL default ''",
"user_email varchar(100) NOT NULL default ''", "user_email varchar(100) NOT NULL default ''",
"registered datetime NOT NULL default '0000-00-00 00:00:00'", "registered datetime NOT NULL default '0000-00-00 00:00:00'",
"activated datetime NOT NULL default '0000-00-00 00:00:00'", "activated datetime NOT NULL default '0000-00-00 00:00:00'",
"active tinyint(1) NOT NULL default '0'", "active tinyint(1) NOT NULL default '0'",
"activation_key varchar(50) NOT NULL default ''", "activation_key varchar(50) NOT NULL default ''",
"meta longtext" "meta longtext"
), ),
$wpdb->prefix.'site' => array( $wpdb->prefix.'site' => array(
"domain varchar(200) NOT NULL default ''", "domain varchar(200) NOT NULL default ''",
"path varchar(100) NOT NULL default ''" "path varchar(100) NOT NULL default ''"
), ),
$wpdb->prefix.'sitemeta' => array( $wpdb->prefix.'sitemeta' => array(
"site_id bigint(20) NOT NULL default '0'", "site_id bigint(20) NOT NULL default '0'",
"meta_key varchar(255) default NULL", "meta_key varchar(255) default NULL",
"meta_value longtext" "meta_value longtext"
), ),
$wpdb->prefix.'users' => array( $wpdb->prefix.'users' => array(
"user_login varchar(60) NOT NULL default ''", "user_login varchar(60) NOT NULL default ''",
"spam tinyint(2) NOT NULL default '0'", "spam tinyint(2) NOT NULL default '0'",
"deleted tinyint(2) NOT NULL default '0'" "deleted tinyint(2) NOT NULL default '0'"
) )
); );
if (version_compare($wp_version, '3.6', '<')) return false; if (version_compare($wp_version, '3.6', '<')) return false;
@ -377,10 +377,10 @@ class DatabaseMaintenance {
} }
/** /**
* Method to return the result of SHOW COLUMNS query. * Method to return the result of SHOW COLUMNS query.
* *
* It returns the result of SHOW COLUMNS query as an object if the table exists. * It returns the result of SHOW COLUMNS query as an object if the table exists.
* It returns the error message if the table doesn't exist. * It returns the error message if the table doesn't exist.
* *
* @return string|object * @return string|object
*/ */
private function show_columns() { private function show_columns() {
@ -401,9 +401,9 @@ class DatabaseMaintenance {
} }
/** /**
* Method to create a back up file of the database. * Method to create a back up file of the database.
* *
* It returns true if success, false if failure. * It returns true if success, false if failure.
* *
* @return boolean * @return boolean
*/ */
private function maintenance_backup() { private function maintenance_backup() {
@ -437,7 +437,7 @@ class DatabaseMaintenance {
} }
/** /**
* Method to display the maintenance page on the admin panel. * Method to display the maintenance page on the admin panel.
* *
*/ */
function show_maintenance_page() { function show_maintenance_page() {
global $utils, $wpdb; global $utils, $wpdb;
@ -447,133 +447,133 @@ class DatabaseMaintenance {
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to access this page!', $domain)); die(__('You are not allowed to access this page!', $domain));
} }
if (isset($_GET['page']) && $_GET['page'] == 'maintenance') : ?> if (isset($_GET['page']) && $_GET['page'] == 'maintenance') : ?>
<div class="navigation"> <div class="navigation">
<ul class="navi-menu"> <ul class="navi-menu">
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=doc"><?php _e('Documentation', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=doc"><?php _e('Documentation', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain);?></a></li>
<li class="menu-selected"><?php _e('Maintenance', $domain);?></li> <li class="menu-selected"><?php _e('Maintenance', $domain);?></li>
</ul> </ul>
</div> </div>
<div class="wrap" id="sqlite-admin-wrap"> <div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Database Maintenace', $domain);?></h2> <h2><?php _e('Database Maintenace', $domain);?></h2>
<h3><?php _e('Important Notice', $domain);?></h3> <h3><?php _e('Important Notice', $domain);?></h3>
<p> <p>
<span style="color: red;"><?php _e('When you installed WordPress 3.5.x with SQLite Integration and upgraded to 3.6, your database might not function as expected.', $domain);?></span> <span style="color: red;"><?php _e('When you installed WordPress 3.5.x with SQLite Integration and upgraded to 3.6, your database might not function as expected.', $domain);?></span>
<?php _e('This page provide you the database sanity check utility and the restore utility.', $domain);?> <?php _e('This page provide you the database sanity check utility and the restore utility.', $domain);?>
</p> </p>
<p> <p>
<?php _e('Click "Sanity Check" button first, and see if you need to fix database or not. If needed, click "Fix Database" button. Afterward you may go to Miscellaneous page and optimize database (this is not required).', $domain);?> <?php _e('Click "Sanity Check" button first, and see if you need to fix database or not. If needed, click "Fix Database" button. Afterward you may go to Miscellaneous page and optimize database (this is not required).', $domain);?>
</p> </p>
<p> <p>
<?php _e('Fix Database procedure will create a database backup file each time the button clicked. The backup file is named with "maintenance-backup", so you can remove it if you don\'t need it. Please go to Miscellaneous page and check if there is one.', $domain);?> <?php _e('Fix Database procedure will create a database backup file each time the button clicked. The backup file is named with "maintenance-backup", so you can remove it if you don\'t need it. Please go to Miscellaneous page and check if there is one.', $domain);?>
</p> </p>
<p> <p>
<?php _e('If you installed WordPress 3.6 (not upgraded), you don\'t have to restore the database.', $domain);?> <?php _e('If you installed WordPress 3.6 (not upgraded), you don\'t have to restore the database.', $domain);?>
</p> </p>
<form action="" method="post"> <form action="" method="post">
<?php <?php
if (function_exists('wp_nonce_field')) { if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqliteintegration-database-manip-stats'); wp_nonce_field('sqliteintegration-database-manip-stats');
} }
?> ?>
<input type="submit" name="sanity-check" class="button-primary" value="<?php _e('Sanity Check', $domain);?>" onclick="return confirm('<?php _e('Are you sure to check the database? This will take some time.\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" /> <input type="submit" name="sanity-check" class="button-primary" value="<?php _e('Sanity Check', $domain);?>" onclick="return confirm('<?php _e('Are you sure to check the database? This will take some time.\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" />
<input type="submit" name="do-fix-database" class="button-primary" value="<?php _e('Fix database', $domain);?>" onclick="return confirm('<?php _e('Are you sure to do fix the database? This will take some time.\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" /> <input type="submit" name="do-fix-database" class="button-primary" value="<?php _e('Fix database', $domain);?>" onclick="return confirm('<?php _e('Are you sure to do fix the database? This will take some time.\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" />
</form> </form>
<?php if (defined('WP_DEBUG') && WP_DEBUG == true) : ?> <?php if (defined('WP_DEBUG') && WP_DEBUG == true) : ?>
<h3><?php _e('Columns Information', $domain);?></h3> <h3><?php _e('Columns Information', $domain);?></h3>
<p> <p>
<?php _e('Select a table name and click "Display Columns" button, and you\'ll see the column property of that table. This information is for debug use.', $domain);?> <?php _e('Select a table name and click "Display Columns" button, and you\'ll see the column property of that table. This information is for debug use.', $domain);?>
</p> </p>
<?php <?php
$wp_tables = $wpdb->tables('all'); $wp_tables = $wpdb->tables('all');
?> ?>
<form action="" method="post"> <form action="" method="post">
<?php <?php
if (function_exists('wp_nonce_field')) { if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqliteintegration-database-manip-stats'); wp_nonce_field('sqliteintegration-database-manip-stats');
} }
?> ?>
<label for="table"/><?php _e('Table Name: ', $domain);?></label> <label for="table"/><?php _e('Table Name: ', $domain);?></label>
<select name="table" id="table"> <select name="table" id="table">
<?php foreach ($wp_tables as $table) :?> <?php foreach ($wp_tables as $table) :?>
<option value="<?php echo $table;?>"><?php echo $table;?></option> <option value="<?php echo $table;?>"><?php echo $table;?></option>
<?php endforeach;?> <?php endforeach;?>
</select> </select>
<input type="submit" name="show-columns" class="button-secondary" value="<?php _e('Display Columns', $domain);?>" onclick="return confirm('<?php _e('Display columns in the selected table.\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" /> <input type="submit" name="show-columns" class="button-secondary" value="<?php _e('Display Columns', $domain);?>" onclick="return confirm('<?php _e('Display columns in the selected table.\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" />
</form> </form>
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php endif; <?php endif;
if (isset($_POST['do-fix-database'])) { if (isset($_POST['do-fix-database'])) {
check_admin_referer('sqliteintegration-database-manip-stats'); check_admin_referer('sqliteintegration-database-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) { if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} }
$fix_results = $this->do_fix_database(); $fix_results = $this->do_fix_database();
if (is_array($fix_results)) { if (is_array($fix_results)) {
$title = '<h3>'. __('Results', $domain) . '</h3>'; $title = '<h3>'. __('Results', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">'; echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title; echo $title;
echo '<ul>'; echo '<ul>';
foreach ($fix_results as $result) { foreach ($fix_results as $result) {
echo '<li>' . $result . '</li>'; echo '<li>' . $result . '</li>';
} }
echo '</ul>'; echo '</ul>';
echo '</div>'; echo '</div>';
} else { } else {
$title = '<h3>'. __('Results', $domain) . '</h3>'; $title = '<h3>'. __('Results', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">'; echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title; echo $title;
echo '<p>'.$fix_results.'</p>'; echo '<p>'.$fix_results.'</p>';
echo '</div>'; echo '</div>';
} }
} }
if (isset($_POST['sanity-check'])) { if (isset($_POST['sanity-check'])) {
check_admin_referer('sqliteintegration-database-manip-stats'); check_admin_referer('sqliteintegration-database-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) { if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} }
$check_results = $this->sanity_check(); $check_results = $this->sanity_check();
if ($check_results !== true) { if ($check_results !== true) {
$title = '<h3>'. __('Checked Results', $domain) . '</h3>'; $title = '<h3>'. __('Checked Results', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">'; echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title; echo $title;
echo '<ul>'; echo '<ul>';
foreach ($check_results as $table => $damaged) { foreach ($check_results as $table => $damaged) {
$message = __(' needs restoring.', $domain); $message = __(' needs restoring.', $domain);
echo '<li><span class="em">' . $table . '</span>' . $message . '</li>'; echo '<li><span class="em">' . $table . '</span>' . $message . '</li>';
} }
echo '</ul>'; echo '</ul>';
echo '</div>'; echo '</div>';
} else { } else {
$title = '<h3>'. __('Checked Results', $domain) . '</h3>'; $title = '<h3>'. __('Checked Results', $domain) . '</h3>';
$message = __('Your database is OK. You don\'t have to restore it.', $domain); $message = __('Your database is OK. You don\'t have to restore it.', $domain);
echo '<div class="wrap" id="sqlite-admin-side-wrap">'; echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title; echo $title;
echo '<p>'.$message.'</p>'; echo '<p>'.$message.'</p>';
echo '</div>'; echo '</div>';
} }
} }
if (isset($_POST['show-columns'])) { if (isset($_POST['show-columns'])) {
check_admin_referer('sqliteintegration-database-manip-stats'); check_admin_referer('sqliteintegration-database-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) { if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} }
$results = $this->show_columns(); $results = $this->show_columns();
if (is_array($results)) { if (is_array($results)) {
$title = '<h3>'. sprintf(__('Columns In %s', $domain), $_POST['table']) . '</h3>'; $title = '<h3>'. sprintf(__('Columns In %s', $domain), $_POST['table']) . '</h3>';
$column_header = __('Column', $domain); $column_header = __('Column', $domain);
$type_header = __('Type', $domain); $type_header = __('Type', $domain);

View File

@ -1,151 +1,151 @@
<?php <?php
/** /**
* This file defines SQLiteIntegrationDocument class. * This file defines SQLiteIntegrationDocument class.
* *
* @package SQLite Integration * @package SQLite Integration
* @author Kojima Toshiyasu * @author Kojima Toshiyasu
*/ */
/** /**
* This class defines the methods to display the documentation page on the admin panel. * This class defines the methods to display the documentation page on the admin panel.
* *
* TODO: separate database access methods and display methods for maintenance * TODO: separate database access methods and display methods for maintenance
*/ */
class SQLiteIntegrationDocument { class SQLiteIntegrationDocument {
/** /**
* Method to display the document page. * Method to display the document page.
* *
*/ */
function show_doc() { function show_doc() {
// textdomain is defined in the utils class // textdomain is defined in the utils class
global $utils; global $utils;
$domain = $utils->text_domain; $domain = $utils->text_domain;
if (is_multisite() && !current_user_can('manage_network_options')) { if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to access this page!', $domain)); die(__('You are not allowed to access this page!', $domain));
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to access this page!', $domain)); die(__('You are not allowed to access this page!', $domain));
} }
if (isset($_GET['page']) && $_GET['page'] == 'doc') :?> if (isset($_GET['page']) && $_GET['page'] == 'doc') :?>
<div class="navigation"> <div class="navigation">
<ul class="navi-menu"> <ul class="navi-menu">
<li class="menu-selected"><?php _e('Documentation', $domain);?></li> <li class="menu-selected"><?php _e('Documentation', $domain);?></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain); ?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain); ?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></li>
</ul> </ul>
</div> </div>
<div class="wrap" id="sqlite-admin-wrap"> <div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Documentation', $domain); ?></h2> <h2><?php _e('Documentation', $domain); ?></h2>
<p> <p>
<?php _e('This is a brief documentation about this plugin. For more details, see also the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration/">SQLite Integration page</a>.', $domain);?> <?php _e('This is a brief documentation about this plugin. For more details, see also the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration/">SQLite Integration page</a>.', $domain);?>
</p> </p>
<p> <p>
<?php _e('Please don\'t forget: WordPress DOES NOT OFFICIALLY SUPPORT any database other than MySQL. So if you ask about this plugin in the Forum, it\'s not unlikely that you won\'t get no answers at all.', $domain);?> <?php _e('Please don\'t forget: WordPress DOES NOT OFFICIALLY SUPPORT any database other than MySQL. So if you ask about this plugin in the Forum, it\'s not unlikely that you won\'t get no answers at all.', $domain);?>
</p> </p>
<h3><?php _e('Features', $domain);?></h3>
<p>
<?php _e('This plugin is a successor to <a href="http://wordpress.org/extend/plugins/pdo-for-wordpress/">PDO for WordPress</a>, which enabled WordPress to use SQLite for its database. But PDO for WordPress doesn\'t seem to be maintained any more only to be outdated. SQLite Integration makes use of the basic ideas and framework of PDO for WordPress, adds some new features and updates it to be able to work with the newest version of WordPress(3.8.1).', $domain); ?>
</p>
<p>
<?php _e('<a href="http://www.sqlite.org/">SQLite Web Page</a> says &mdash; SQLite is a &quot;software library that implements selfcontained, serverless, zero-configuration, transactional SQL database engine&quot;. It is &quot;a good choice for small to medium size websites&quot;. It\'s small and portable, and you don\'t need any database server system.', $domain); ?>
</p>
<p>
<?php _e('Unfortunately enough, WordPress only supports MySQL. Consequently it doesn\'t provide any APIs for SQLite. So if you want to create a website using WordPress without a database server, you\'ve got to write a kind of wrapper program yourself to use SQLite. This is the way SQLite Integration goes.', $domain);?>
</p>
<p>
<?php _e('SQLite Integration does the work as follows:', $domain); ?>
</p>
<ol>
<li><?php _e('Intercepts SQL statement for MySQL from WordPress', $domain); ?></li>
<li><?php _e('Rewrites it as SQLite can execute', $domain); ?></li>
<li><?php _e('Gives it to SQLite', $domain); ?></li>
<li><?php _e('Gets the results from SQLite', $domain); ?></li>
<li><?php _e('Format the results as MySQL returns, if necessary', $domain);?></li>
<li><?php _e('Gives back the results to WordPress', $domain); ?></li>
</ol>
<p>
<?php _e('WordPress doesn\'t know what has happened in the background and will be happy with it.', $domain);?>
</p>
<h3><?php _e('Limitations', $domain);?></h3>
<p>
<?php _e('SQLite Integration uses SQLite, so the limitations of SQLite is, as it is, those of SQLite Integration. MySQL is far from a simple SQL engine and has many extended features and functionalities. WordPress uses some of them. Among those are some SQLite doesn\'t implement. For those features that WordPress uses, I made them work with SQLite Integration. But for others that some plugins are using, SQLite Integration can\'t manipulate. So...', $domain); ?>
</p>
<ol>
<li><strong><?php _e('There are some plugins that you can\'t use. No way around.<br />', $domain);?></strong>
<?php _e('Some plugins can\'t be activated or work properly. See the &quot;Plugin Compatibility/Incompatibility&quot; section.', $domain);?></li>
<li><strong><?php _e('There are some plugins that you can\'t use without rewriting some codes in them.<br />', $domain);?></strong>
<?php echo sprintf(__('Some plugins do work fine if you rewrite MySQL functions. I made some patch files and <a href="%s?page=patch">Patch Utility</a>. See also the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration/#plugin-compat">SQLite Integration Page</a> for more details.', $domain), $utils->show_parent());?></li>
</ol>
<p>
<?php _e('And there may be other problems I overlooked. If you find malfunctionality, please let me know at the <a href="http://wordpress.org/support/plugin/sqlite-integration">Support Forum</a>.', $domain);?>
</p>
<h3><?php _e('User Defined Functions', $domain); ?></h3>
<p>
<?php _e('SQLite Integration replaces some functions of MySQL with the user defined functions built in PHP PDO library. But some of the functions are meaningless in SQLite database: e.g. get_lock() or release_lock(). When SQLite Integration meets those functions, it does nothing but prevent the error.', $domain); ?>
</p>
<p>
<?php _e('If you want SQLite Integration to execute more functions, you can add the definition in the file sqlite-integration/functions.php (functions-5-2.php is for PHP 5.2 or lesser).', $domain);?>
</p>
<h3><?php _e('Database Administration and Maintenance', $domain);?></h3>
<p>
<?php _e('SQLite Integration doesn\'t contain database maintenace functionality, because there are some other free or proprietary softwares that give you such functionalities. For example, these are among free softwares:', $domain);?>
</p>
<ul class="in-body-list">
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/">SQLite Manager Mozilla Addon</a>(<?php _e('my recommendation', $domain);?>)</li>
<li><a href="http://www.sqlitemanager.org/">SQLiteManager</a>(<?php _e('unfortunately seems not to maintained...', $domain); ?>)</li>
</ul>
<p>
<?php _e('I\'m not sure if future release may have some of the database maintenance functionality.', $domain);?>
</p>
</div>
<h3><?php _e('Features', $domain);?></h3>
<div class="wrap" id="sqlite-admin-side-wrap"> <p>
<h2><?php _e('Plugin Compatibility/Incompatibility', $domain);?></h2> <?php _e('This plugin is a successor to <a href="http://wordpress.org/extend/plugins/pdo-for-wordpress/">PDO for WordPress</a>, which enabled WordPress to use SQLite for its database. But PDO for WordPress doesn\'t seem to be maintained any more only to be outdated. SQLite Integration makes use of the basic ideas and framework of PDO for WordPress, adds some new features and updates it to be able to work with the newest version of WordPress(3.8.1).', $domain); ?>
<p> </p>
<?php _e('WordPress without its plugins is a king without people. Of course, you need plugins, I know.', $domain);?> <p>
</p> <?php _e('<a href="http://www.sqlite.org/">SQLite Web Page</a> says &mdash; SQLite is a &quot;software library that implements selfcontained, serverless, zero-configuration, transactional SQL database engine&quot;. It is &quot;a good choice for small to medium size websites&quot;. It\'s small and portable, and you don\'t need any database server system.', $domain); ?>
<p> </p>
<?php echo sprintf(__('This is the list of the problematic plugins (far from complete). You can see informations about your installed plugins in the <a href="%s?page=sys-info">System Info</a> page. To see more details, please visit the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration">Plugin Page</a>.', $domain), $utils->show_parent());?> <p>
</p> <?php _e('Unfortunately enough, WordPress only supports MySQL. Consequently it doesn\'t provide any APIs for SQLite. So if you want to create a website using WordPress without a database server, you\'ve got to write a kind of wrapper program yourself to use SQLite. This is the way SQLite Integration goes.', $domain);?>
</p>
<table class="widefat page fixed" id="plugins-table"> <p>
<thead> <?php _e('SQLite Integration does the work as follows:', $domain); ?>
<tr> </p>
<th data-sort='{"key":"name"}' class="item"><?php _e('Plugins Name', $domain); ?></th> <ol>
<th data-sort='{"key":"compat"}' class="compat"><?php _e('Compatibility', $domain); ?></th> <li><?php _e('Intercepts SQL statement for MySQL from WordPress', $domain); ?></li>
<th data-sort='{"key":"reason"}' class="reason"><?php _e('Reasons', $domain);?></th> <li><?php _e('Rewrites it as SQLite can execute', $domain); ?></li>
</tr> <li><?php _e('Gives it to SQLite', $domain); ?></li>
</thead> <li><?php _e('Gets the results from SQLite', $domain); ?></li>
<tbody> <li><?php _e('Format the results as MySQL returns, if necessary', $domain);?></li>
<?php <li><?php _e('Gives back the results to WordPress', $domain); ?></li>
if (file_exists(SQLiteListFile)) :?> </ol>
<?php <p>
$contents = file_get_contents(SQLiteListFile); <?php _e('WordPress doesn\'t know what has happened in the background and will be happy with it.', $domain);?>
$plugin_info_list = json_decode($contents); </p>
foreach ($plugin_info_list as $plugin_info) :?>
<?php if (in_array($plugin_info->compat, array('No', 'Probably No', 'Needs Patch'))) :?> <h3><?php _e('Limitations', $domain);?></h3>
<tr data-table='{"name":"<?php echo $plugin_info->name;?>", "compat":"<?php echo $plugin_info->compat;?>", "reason":"<?php echo $plugin_info->reason;?>"}'> <p>
<td><?php echo $plugin_info->name;?></a></td> <?php _e('SQLite Integration uses SQLite, so the limitations of SQLite is, as it is, those of SQLite Integration. MySQL is far from a simple SQL engine and has many extended features and functionalities. WordPress uses some of them. Among those are some SQLite doesn\'t implement. For those features that WordPress uses, I made them work with SQLite Integration. But for others that some plugins are using, SQLite Integration can\'t manipulate. So...', $domain); ?>
<?php if (stripos($plugin_info->compat, 'patch') !== false) :?> </p>
<td><a href="<?php echo $plugin_info->patch_url;?>"><?php _e('Needs Patch', $domain);?></a></td> <ol>
<?php elseif (stripos($plugin_info->compat, 'probably no')) :?> <li><strong><?php _e('There are some plugins that you can\'t use. No way around.<br />', $domain);?></strong>
<td><?php _e('Probably No', $domain);?></td> <?php _e('Some plugins can\'t be activated or work properly. See the &quot;Plugin Compatibility/Incompatibility&quot; section.', $domain);?></li>
<?php else :?> <li><strong><?php _e('There are some plugins that you can\'t use without rewriting some codes in them.<br />', $domain);?></strong>
<td><?php _e('No', $domain);?></td> <?php echo sprintf(__('Some plugins do work fine if you rewrite MySQL functions. I made some patch files and <a href="%s?page=patch">Patch Utility</a>. See also the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration/#plugin-compat">SQLite Integration Page</a> for more details.', $domain), $utils->show_parent());?></li>
<?php endif;?> </ol>
<td><?php echo $plugin_info->reason;?></td> <p>
</tr> <?php _e('And there may be other problems I overlooked. If you find malfunctionality, please let me know at the <a href="http://wordpress.org/support/plugin/sqlite-integration">Support Forum</a>.', $domain);?>
<?php endif;?> </p>
<?php endforeach;?> <h3><?php _e('User Defined Functions', $domain); ?></h3>
<?php endif;?> <p>
</tbody> <?php _e('SQLite Integration replaces some functions of MySQL with the user defined functions built in PHP PDO library. But some of the functions are meaningless in SQLite database: e.g. get_lock() or release_lock(). When SQLite Integration meets those functions, it does nothing but prevent the error.', $domain); ?>
</table> </p>
</div> <p>
<?php endif; <?php _e('If you want SQLite Integration to execute more functions, you can add the definition in the file sqlite-integration/functions.php (functions-5-2.php is for PHP 5.2 or lesser).', $domain);?>
} </p>
<h3><?php _e('Database Administration and Maintenance', $domain);?></h3>
<p>
<?php _e('SQLite Integration doesn\'t contain database maintenace functionality, because there are some other free or proprietary softwares that give you such functionalities. For example, these are among free softwares:', $domain);?>
</p>
<ul class="in-body-list">
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/">SQLite Manager Mozilla Addon</a>(<?php _e('my recommendation', $domain);?>)</li>
<li><a href="http://www.sqlitemanager.org/">SQLiteManager</a>(<?php _e('unfortunately seems not to maintained...', $domain); ?>)</li>
</ul>
<p>
<?php _e('I\'m not sure if future release may have some of the database maintenance functionality.', $domain);?>
</p>
</div>
<div class="wrap" id="sqlite-admin-side-wrap">
<h2><?php _e('Plugin Compatibility/Incompatibility', $domain);?></h2>
<p>
<?php _e('WordPress without its plugins is a king without people. Of course, you need plugins, I know.', $domain);?>
</p>
<p>
<?php echo sprintf(__('This is the list of the problematic plugins (far from complete). You can see informations about your installed plugins in the <a href="%s?page=sys-info">System Info</a> page. To see more details, please visit the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration">Plugin Page</a>.', $domain), $utils->show_parent());?>
</p>
<table class="widefat page fixed" id="plugins-table">
<thead>
<tr>
<th data-sort='{"key":"name"}' class="item"><?php _e('Plugins Name', $domain); ?></th>
<th data-sort='{"key":"compat"}' class="compat"><?php _e('Compatibility', $domain); ?></th>
<th data-sort='{"key":"reason"}' class="reason"><?php _e('Reasons', $domain);?></th>
</tr>
</thead>
<tbody>
<?php
if (file_exists(SQLiteListFile)) :?>
<?php
$contents = file_get_contents(SQLiteListFile);
$plugin_info_list = json_decode($contents);
foreach ($plugin_info_list as $plugin_info) :?>
<?php if (in_array($plugin_info->compat, array('No', 'Probably No', 'Needs Patch'))) :?>
<tr data-table='{"name":"<?php echo $plugin_info->name;?>", "compat":"<?php echo $plugin_info->compat;?>", "reason":"<?php echo $plugin_info->reason;?>"}'>
<td><?php echo $plugin_info->name;?></a></td>
<?php if (stripos($plugin_info->compat, 'patch') !== false) :?>
<td><a href="<?php echo $plugin_info->patch_url;?>"><?php _e('Needs Patch', $domain);?></a></td>
<?php elseif (stripos($plugin_info->compat, 'probably no')) :?>
<td><?php _e('Probably No', $domain);?></td>
<?php else :?>
<td><?php _e('No', $domain);?></td>
<?php endif;?>
<td><?php echo $plugin_info->reason;?></td>
</tr>
<?php endif;?>
<?php endforeach;?>
<?php endif;?>
</tbody>
</table>
</div>
<?php endif;
}
} }
?> ?>

View File

@ -1,421 +1,421 @@
<?php <?php
/** /**
* This file defines PatchUtils class. * This file defines PatchUtils class.
* *
* @package SQLite Integration * @package SQLite Integration
* @author Kojima Toshiyasu * @author Kojima Toshiyasu
*/ */
/** /**
* This class provides the methods for patching utilities. * This class provides the methods for patching utilities.
* *
*/ */
class PatchUtils { class PatchUtils {
/** /**
* Method to read the patch directory and returns the list of the files in it. * Method to read the patch directory and returns the list of the files in it.
* *
* It reads wp-content/uploads/patches directory and returns file names in it. * It reads wp-content/uploads/patches directory and returns file names in it.
* If directory contains none, returns empty array. * If directory contains none, returns empty array.
* *
* @return array * @return array
* @access private * @access private
*/ */
private function get_patch_files() { private function get_patch_files() {
$patch_files = array(); $patch_files = array();
if (!is_dir(SQLitePatchDir)) { if (!is_dir(SQLitePatchDir)) {
return $patch_files; return $patch_files;
} else { } else {
if ($dir_handle = opendir(SQLitePatchDir)) { if ($dir_handle = opendir(SQLitePatchDir)) {
while (($file_name = readdir($dir_handle)) !== false) { while (($file_name = readdir($dir_handle)) !== false) {
if ($file_name == '.' || $file_name == '..' || $file_name == '.htaccess') if ($file_name == '.' || $file_name == '..' || $file_name == '.htaccess')
continue; continue;
$patch_files[] = $file_name; $patch_files[] = $file_name;
} }
} }
return $patch_files; return $patch_files;
} }
} }
/** /**
* Method to apply patch to the plugins. * Method to apply patch to the plugins.
* *
* It executes patch command and apply it to the target plugins. * It executes patch command and apply it to the target plugins.
* If patch file(s) is not selected, returns false. * If patch file(s) is not selected, returns false.
* Or else returns array contains messages. * Or else returns array contains messages.
* *
* @return boolean|array * @return boolean|array
* @access private * @access private
*/ */
private function apply_patches() { private function apply_patches() {
global $utils; global $utils;
$domain = $utils->text_domain; $domain = $utils->text_domain;
$installed_plugins = array(); $installed_plugins = array();
$file_names = array(); $file_names = array();
$output = array(); $output = array();
$retval = 0; $retval = 0;
$patch_results = array(); $patch_results = array();
$message = ''; $message = '';
if (isset($_POST['plugin_checked'])) { if (isset($_POST['plugin_checked'])) {
$file_names = $_POST['plugin_checked']; $file_names = $_POST['plugin_checked'];
} else { } else {
return false; return false;
} }
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
exec('where patch 2>&1', $out, $val); exec('where patch 2>&1', $out, $val);
} else { } else {
exec('which patch 2>&1', $out, $val); exec('which patch 2>&1', $out, $val);
} }
if ($val != 0) { if ($val != 0) {
$patch_results['error'] = __('Patch command is not found', $domain); $patch_results['error'] = __('Patch command is not found', $domain);
return $patch_results; return $patch_results;
} elseif (!is_executable(trim($out[0]))) { } elseif (!is_executable(trim($out[0]))) {
$patch_results['error'] = __('Patch command is not executable', $domain); $patch_results['error'] = __('Patch command is not executable', $domain);
return $patch_results; return $patch_results;
} else { } else {
$patch_command = trim($out[0]) . ' -s -N -p1'; $patch_command = trim($out[0]) . ' -s -N -p1';
} }
$installed_plugins = get_plugins(); $installed_plugins = get_plugins();
foreach ($file_names as $file) { foreach ($file_names as $file) {
if (preg_match('/_(.*)\.patch/i', $file, $match)) { if (preg_match('/_(.*)\.patch/i', $file, $match)) {
$plugin_version = trim($match[1]); $plugin_version = trim($match[1]);
$plugin_basename = preg_replace('/_.*\.patch$/i', '', $file); $plugin_basename = preg_replace('/_.*\.patch$/i', '', $file);
foreach (array_keys($installed_plugins) as $key) { foreach (array_keys($installed_plugins) as $key) {
if (stripos($key, $plugin_basename) !== false) { if (stripos($key, $plugin_basename) !== false) {
$installed_plugin_version = $installed_plugins[$key]['Version']; $installed_plugin_version = $installed_plugins[$key]['Version'];
break; break;
} }
} }
} else { } else {
$patch_results['error'] = __('Patch file name is invalid', $domain); $patch_results['error'] = __('Patch file name is invalid', $domain);
break; break;
} }
if (version_compare($installed_plugin_version, $plugin_version, '!=')) { if (version_compare($installed_plugin_version, $plugin_version, '!=')) {
$patch_results['error'] = __('Patch file version does not match with that of your plugin.', $domain); $patch_results['error'] = __('Patch file version does not match with that of your plugin.', $domain);
break; break;
} }
$plugin_dir = WP_PLUGIN_DIR.'/'.$plugin_basename; $plugin_dir = WP_PLUGIN_DIR.'/'.$plugin_basename;
$patch_file = SQLitePatchDir.'/'.$file; $patch_file = SQLitePatchDir.'/'.$file;
$command = $patch_command.' <'.$patch_file.' 2>&1'; $command = $patch_command.' <'.$patch_file.' 2>&1';
if (chdir($plugin_dir)) { if (chdir($plugin_dir)) {
exec("$command", $output, $retval); exec("$command", $output, $retval);
} else { } else {
$patch_results[$file] = __('Error! Plugin directory is not accessible.', $domain); $patch_results[$file] = __('Error! Plugin directory is not accessible.', $domain);
} }
if ($retval == 0) { if ($retval == 0) {
$patch_results[$file] = __('is patched successfully.', $domain); $patch_results[$file] = __('is patched successfully.', $domain);
} else { } else {
foreach ($output as $val) { foreach ($output as $val) {
$message .= $val.'<br />'; $message .= $val.'<br />';
} }
$patch_results[$file] = sprintf(__('Error! Messages: %s', $domain), $message); $patch_results[$file] = sprintf(__('Error! Messages: %s', $domain), $message);
} }
} }
return $patch_results; return $patch_results;
} }
/** /**
* Method to remove patch file(s) from the server. * Method to remove patch file(s) from the server.
* *
* It deletes uploaded patch file(s). * It deletes uploaded patch file(s).
* If patch file(s) is not selected, returns false. * If patch file(s) is not selected, returns false.
* Or else returns array contains messages. * Or else returns array contains messages.
* *
* @return boolean|array * @return boolean|array
* @access private * @access private
*/ */
private function delete_patch_files() { private function delete_patch_files() {
global $utils; global $utils;
$domain = $utils->text_domain; $domain = $utils->text_domain;
$file_names = array(); $file_names = array();
$rm_results = array(); $rm_results = array();
if (isset($_POST['plugin_checked'])) { if (isset($_POST['plugin_checked'])) {
$file_names = $_POST['plugin_checked']; $file_names = $_POST['plugin_checked'];
} else { } else {
return false; return false;
} }
if (chdir(SQLitePatchDir)) { if (chdir(SQLitePatchDir)) {
foreach ($file_names as $file) { foreach ($file_names as $file) {
if (unlink($file)) { if (unlink($file)) {
$rm_results[$file] = sprintf(__('File %s is deleted.', $domain), $file); $rm_results[$file] = sprintf(__('File %s is deleted.', $domain), $file);
} else { } else {
$rm_results[$file] = sprintf(__('Error! File %s is not deleted.', $domain), $file); $rm_results[$file] = sprintf(__('Error! File %s is not deleted.', $domain), $file);
} }
} }
} else { } else {
$rm_results[$file] = __('Error!: patches directory is not accessible.', $domain); $rm_results[$file] = __('Error!: patches directory is not accessible.', $domain);
} }
return $rm_results; return $rm_results;
} }
/** /**
* Method to upload patch file(s) to the server. * Method to upload patch file(s) to the server.
* *
* It uploads a patch file to the server. You must have the permission to write to the * It uploads a patch file to the server. You must have the permission to write to the
* temporary directory. If there isn't SQLitePatchDir, this method will create it and * temporary directory. If there isn't SQLitePatchDir, this method will create it and
* set the permission to 0707. * set the permission to 0707.
* *
* No return values. * No return values.
* *
* @return boolean * @return boolean
* @access private * @access private
*/ */
private function upload_file() { private function upload_file() {
global $utils; global $utils;
$domain = $utils->text_domain; $domain = $utils->text_domain;
if (!file_exists(SQLitePatchDir) || !is_dir(SQLitePatchDir)) { if (!file_exists(SQLitePatchDir) || !is_dir(SQLitePatchDir)) {
if (!mkdir(SQLitePatchDir, 0707, true)) { if (!mkdir(SQLitePatchDir, 0707, true)) {
$message = __('Unable to create a patch directory.', $domain); $message = __('Unable to create a patch directory.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
return false; return false;
} }
} }
if (!is_file(SQLitePatchDir . '/.htaccess')) { if (!is_file(SQLitePatchDir . '/.htaccess')) {
$fp = fopen(SQLitePatchDir . '/.htaccess', 'w'); $fp = fopen(SQLitePatchDir . '/.htaccess', 'w');
if (!$fp) { if (!$fp) {
$message = __('Unable to create a .htaccess file.', $domain); $message = __('Unable to create a .htaccess file.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
return false; return false;
} }
fwrite($fp, 'DENY FROM ALL'); fwrite($fp, 'DENY FROM ALL');
fclose($fp); fclose($fp);
} }
if (!isset($_FILES['upfile']['error']) || !is_int($_FILES['upfile']['error'])) { if (!isset($_FILES['upfile']['error']) || !is_int($_FILES['upfile']['error'])) {
$message = __('Invalid operation.', $domain); $message = __('Invalid operation.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
return false; return false;
} elseif ($_FILES['upfile']['error'] != UPLOAD_ERR_OK) { } elseif ($_FILES['upfile']['error'] != UPLOAD_ERR_OK) {
switch ($_FILES['upfile']['error']) { switch ($_FILES['upfile']['error']) {
case UPLOAD_ERR_FORM_SIZE: case UPLOAD_ERR_FORM_SIZE:
$message = __('File is too large to upload.', $domain); $message = __('File is too large to upload.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
break; break;
case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_PARTIAL:
$message = __('File upload is not complete.', $domain); $message = __('File upload is not complete.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
break; break;
case UPLOAD_ERR_NO_FILE: case UPLOAD_ERR_NO_FILE:
$message = __('File is not uploaded.', $domain); $message = __('File is not uploaded.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
break; break;
case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_NO_TMP_DIR:
$message = __('Temporary directory is not writable.', $domain); $message = __('Temporary directory is not writable.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
break; break;
case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_CANT_WRITE:
$message = __('File cannot be written on the disk.', $domain); $message = __('File cannot be written on the disk.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
break; break;
default: default:
$message = __('Unknown error.', $domain); $message = __('Unknown error.', $domain);
break; break;
} }
return false; return false;
} }
if (is_uploaded_file($_FILES['upfile']['tmp_name'])) { if (is_uploaded_file($_FILES['upfile']['tmp_name'])) {
$file_full_path = SQLitePatchDir . '/' . $_FILES['upfile']['name']; $file_full_path = SQLitePatchDir . '/' . $_FILES['upfile']['name'];
if (move_uploaded_file($_FILES['upfile']['tmp_name'], $file_full_path)) { if (move_uploaded_file($_FILES['upfile']['tmp_name'], $file_full_path)) {
$message = __('File is successfully uploaded.', $domain); $message = __('File is successfully uploaded.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
chmod(SQLitePatchDir.'/'.$_FILES['upfile']['name'], 0606); chmod(SQLitePatchDir.'/'.$_FILES['upfile']['name'], 0606);
} else { } else {
$message = __('File upload failed. Possible file upload attack.', $domain); $message = __('File upload failed. Possible file upload attack.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
return false; return false;
} }
} else { } else {
$message = __('File is not selected', $domain); $message = __('File is not selected', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
return false; return false;
} }
return true; return true;
} }
/** /**
* Method to display the patch utility page on the admin panel. * Method to display the patch utility page on the admin panel.
* *
*/ */
function show_patch_page() { function show_patch_page() {
global $utils; global $utils;
$domain = $utils->text_domain; $domain = $utils->text_domain;
if (is_multisite() && !current_user_can('manage_network_options')) { if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to access this page!', $domain)); die(__('You are not allowed to access this page!', $domain));
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to access this page!', $domain)); die(__('You are not allowed to access this page!', $domain));
} }
if (isset($_POST['apply_patch'])) { if (isset($_POST['apply_patch'])) {
check_admin_referer('sqlitewordpress-plugin-manip-stats'); check_admin_referer('sqlitewordpress-plugin-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) { if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} }
$result = $this->apply_patches(); $result = $this->apply_patches();
if ($result === false) { if ($result === false) {
$message = __('Please select patch file(s)', $domain); $message = __('Please select patch file(s)', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
} elseif (is_array($result) && count($result) > 0) { } elseif (is_array($result) && count($result) > 0) {
echo '<div id="message" class="updated fade">'; echo '<div id="message" class="updated fade">';
foreach ($result as $key => $val) { foreach ($result as $key => $val) {
echo $key.' => '.$val.'<br />'; echo $key.' => '.$val.'<br />';
} }
echo '</div>'; echo '</div>';
} else { } else {
$message = __('None of the patches is applied!'); $message = __('None of the patches is applied!');
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
} }
} }
if (isset($_POST['patch_file_delete'])) { if (isset($_POST['patch_file_delete'])) {
check_admin_referer('sqlitewordpress-plugin-manip-stats'); check_admin_referer('sqlitewordpress-plugin-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) { if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} }
$result = $this->delete_patch_files(); $result = $this->delete_patch_files();
if ($result === false) { if ($result === false) {
$message = __('Please select patch file(s)', $domain); $message = __('Please select patch file(s)', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
} elseif (is_array($result) && count($result) > 0) { } elseif (is_array($result) && count($result) > 0) {
echo '<div id="message" class="updated fade">'; echo '<div id="message" class="updated fade">';
foreach ($result as $key => $val) { foreach ($result as $key => $val) {
echo $key.' => '.$val.'<br />'; echo $key.' => '.$val.'<br />';
} }
echo '</div>'; echo '</div>';
} else { } else {
$message = __('Error! Please remove files manually', $domain); $message = __('Error! Please remove files manually', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>'; echo '<div id="message" class="updated fade">'.$message.'</div>';
} }
} }
if (isset($_POST['upload'])) { if (isset($_POST['upload'])) {
check_admin_referer('sqlitewordpress-plugin-patch-file-stats'); check_admin_referer('sqlitewordpress-plugin-patch-file-stats');
if (is_multisite() && !current_user_can('manage_network_options')) { if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain)); die(__('You are not allowed to do this operation!', $domain));
} }
$result = $this->upload_file(); $result = $this->upload_file();
} }
if (isset($_GET['page']) && $_GET['page'] == 'patch') : ?> if (isset($_GET['page']) && $_GET['page'] == 'patch') : ?>
<div class="navigation"> <div class="navigation">
<ul class="navi-menu"> <ul class="navi-menu">
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=doc"><?php _e('Documentation', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=doc"><?php _e('Documentation', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li>
<li class="menu-selected"><?php _e('Patch Utility', $domain);?></li> <li class="menu-selected"><?php _e('Patch Utility', $domain);?></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></li>
</ul> </ul>
</div> </div>
<div class="wrap" id="sqlite-admin-wrap"> <div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Patch Files Upload and Apply', $domain);?></h2> <h2><?php _e('Patch Files Upload and Apply', $domain);?></h2>
<h3><?php _e('What you can do in this page', $domain);?></h3> <h3><?php _e('What you can do in this page', $domain);?></h3>
<p> <p>
<?php _e('I made patch files for some plugins that are incompatible with SQLite Integration and need rewriting. And I wrote in the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration">Plugin Page</a> about how to apply a patch file to the plugin. But the command line interface sometimes embarrasses some people, especially newbies.', $domain);?> <?php _e('I made patch files for some plugins that are incompatible with SQLite Integration and need rewriting. And I wrote in the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration">Plugin Page</a> about how to apply a patch file to the plugin. But the command line interface sometimes embarrasses some people, especially newbies.', $domain);?>
</p> </p>
<p> <p>
<?php _e('In this page, you can upload patch files and apply them automatically. But there are some requirements.', $domain)?> <?php _e('In this page, you can upload patch files and apply them automatically. But there are some requirements.', $domain)?>
</p> </p>
<ol> <ol>
<li><?php _e('Think before you leap. Is the plugin to which you are going to apply patch really necessary for your site? Did you search in the <a href="http://wordpress.org/extend/plugins/">Plugin Directory</a> for the substitutes?', $domain)?></li> <li><?php _e('Think before you leap. Is the plugin to which you are going to apply patch really necessary for your site? Did you search in the <a href="http://wordpress.org/extend/plugins/">Plugin Directory</a> for the substitutes?', $domain)?></li>
<li><?php _e('Your PHP script has the permission to create a directory and write a file in it.', $domain);?></li> <li><?php _e('Your PHP script has the permission to create a directory and write a file in it.', $domain);?></li>
<li><?php _e('Your PHP scripts can execute exec() function on the server.', $domain);?></li> <li><?php _e('Your PHP scripts can execute exec() function on the server.', $domain);?></li>
<li><?php _e('Your PHP script can execute &quot;patch&quot; shell command.(Script will check if it is executable or not.)', $domain);?></li> <li><?php _e('Your PHP script can execute &quot;patch&quot; shell command.(Script will check if it is executable or not.)', $domain);?></li>
</ol> </ol>
<p> <p>
<?php _e('If uploading fails, it\' very likely that application will fail. When you try uploading with FTP client, the patch files must be put into the directory wp-content/uploads/patches/. When constant UPLOADS is defined, script follows it.', $domain)?> <?php _e('If uploading fails, it\' very likely that application will fail. When you try uploading with FTP client, the patch files must be put into the directory wp-content/uploads/patches/. When constant UPLOADS is defined, script follows it.', $domain)?>
</p> </p>
<p> <p>
<?php _e('You can create your patch file yourself. When you create one, please test it on your local server first and check if it works fine without PHP error or notice ( set error_reporting(E_ALL) ). If you use this utility, name your patch file as follows:', $domain);?> <?php _e('You can create your patch file yourself. When you create one, please test it on your local server first and check if it works fine without PHP error or notice ( set error_reporting(E_ALL) ). If you use this utility, name your patch file as follows:', $domain);?>
</p> </p>
<ol> <ol>
<li><?php _e('Use the file name beginning with the plugin directory name.', $domain);?></li> <li><?php _e('Use the file name beginning with the plugin directory name.', $domain);?></li>
<li><?php _e('Use the plugin version number after the directory name with underscore.', $domain);?></li> <li><?php _e('Use the plugin version number after the directory name with underscore.', $domain);?></li>
<li><?php _e('Use the suffix .patch.', $domain);?></li> <li><?php _e('Use the suffix .patch.', $domain);?></li>
<li><?php _e('Use diff command options &quot;-Naur&quot;.', $domain);?></li> <li><?php _e('Use diff command options &quot;-Naur&quot;.', $domain);?></li>
</ol> </ol>
<p> <p>
<?php _e('For example, the patch file for the plugin &quot;Debug Bar&quot; is &quot;debug-bar_0.8.patch&quot;. Script interprets &quot;debug-bar&quot; as the target directory and &quot;0.8&quot; as the target version. If the version number doesn\'t match with the target, script shows the error message and skip applying the patch file. And script will reject any other file name.', $domain);?> <?php _e('For example, the patch file for the plugin &quot;Debug Bar&quot; is &quot;debug-bar_0.8.patch&quot;. Script interprets &quot;debug-bar&quot; as the target directory and &quot;0.8&quot; as the target version. If the version number doesn\'t match with the target, script shows the error message and skip applying the patch file. And script will reject any other file name.', $domain);?>
</p> </p>
<h3><?php _e('How to install, patch and activate plugins', $domain);?></h3> <h3><?php _e('How to install, patch and activate plugins', $domain);?></h3>
<ol> <ol>
<li><?php _e('Install the plugin (not yet activate it)', $domain);?></li> <li><?php _e('Install the plugin (not yet activate it)', $domain);?></li>
<li><?php _e('Upload the patch file (if any) to the server and ppply it in this page', $domain);?></li> <li><?php _e('Upload the patch file (if any) to the server and ppply it in this page', $domain);?></li>
<li><?php _e('Back to the installed plugin page and activate it', $domain);?></li> <li><?php _e('Back to the installed plugin page and activate it', $domain);?></li>
</ol> </ol>
<h3><?php _e('How to upgrade plugins', $domain);?></h3> <h3><?php _e('How to upgrade plugins', $domain);?></h3>
<p> <p>
<?php _e('When upgrading the plugin, it will be safer to follow next steps.', $domain);?> <?php _e('When upgrading the plugin, it will be safer to follow next steps.', $domain);?>
</p> </p>
<ol> <ol>
<li><?php _e('Deactivate the plugin', $domain);?></li> <li><?php _e('Deactivate the plugin', $domain);?></li>
<li><?php _e('Upgrade the plugin', $domain);?></li> <li><?php _e('Upgrade the plugin', $domain);?></li>
<li><?php _e('Upload the patch file (if any) and apply it', $domain);?></li> <li><?php _e('Upload the patch file (if any) and apply it', $domain);?></li>
<li><?php _e('Reactivate the plugin', $domain);?></li> <li><?php _e('Reactivate the plugin', $domain);?></li>
</ol> </ol>
<p><?php _e('If there isn\'t a patch file to match with the newest version of the plugin, it won\'t work properly. Please wait for somebody to make one or rewrite the codes checking the patch file for the previous version (it\'s not so difficult a matter, I guess, for almost all the cases, you\'ll have only to replace the MySQL functions with the WordPress built-in functions).', $domain);?></p> <p><?php _e('If there isn\'t a patch file to match with the newest version of the plugin, it won\'t work properly. Please wait for somebody to make one or rewrite the codes checking the patch file for the previous version (it\'s not so difficult a matter, I guess, for almost all the cases, you\'ll have only to replace the MySQL functions with the WordPress built-in functions).', $domain);?></p>
<h3><?php _e('Upload and Apply', $domain)?></h3> <h3><?php _e('Upload and Apply', $domain)?></h3>
<table class="form-table"> <table class="form-table">
<tbody> <tbody>
<tr> <tr>
<th scope="row"><?php _e('File Select', $domain);?></th> <th scope="row"><?php _e('File Select', $domain);?></th>
<td> <td>
<form action="" id="upload-form" class="wp-upload-form" method="post" enctype="multipart/form-data"> <form action="" id="upload-form" class="wp-upload-form" method="post" enctype="multipart/form-data">
<?php if (function_exists('wp_nonce_field')) { <?php if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqlitewordpress-plugin-patch-file-stats'); wp_nonce_field('sqlitewordpress-plugin-patch-file-stats');
} }
?> ?>
<input type="hidden" name="MAX_FILE_SIZE" value="500000" /> <input type="hidden" name="MAX_FILE_SIZE" value="500000" />
<label for="upload"><?php _e('Select file from your computer. If the file name is the same as existent file, this operation will override it. You can\'t upload the file whose size is over 500kB.', $domain);?></label><br /> <label for="upload"><?php _e('Select file from your computer. If the file name is the same as existent file, this operation will override it. You can\'t upload the file whose size is over 500kB.', $domain);?></label><br />
<input type="file" id="upload" name="upfile" size="60"/> <input type="file" id="upload" name="upfile" size="60"/>
<input type="submit" name="upload" id="submit-upload" class="button" value="<?php _e('Upload', $domain)?>" /> <input type="submit" name="upload" id="submit-upload" class="button" value="<?php _e('Upload', $domain)?>" />
</form> </form>
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope="row"><?php _e('Patch files uploaded', $domain)?></th> <th scope="row"><?php _e('Patch files uploaded', $domain)?></th>
<td> <td>
<form action="" method="post"> <form action="" method="post">
<?php if (function_exists('wp_nonce_field')) { <?php if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqlitewordpress-plugin-manip-stats'); wp_nonce_field('sqlitewordpress-plugin-manip-stats');
} }
?> ?>
<label for="plugin_check"><?php _e('Select the file(s) you want to apply to the plugin(s) or you want to delete. You can select multiple files.', $domain);?></label> <label for="plugin_check"><?php _e('Select the file(s) you want to apply to the plugin(s) or you want to delete. You can select multiple files.', $domain);?></label>
<table class="widefat page fixed" id="patch-files"> <table class="widefat page fixed" id="patch-files">
<thead> <thead>
<tr> <tr>
<th class="item"><?php _e('Apply/Hold', $domain)?></th> <th class="item"><?php _e('Apply/Hold', $domain)?></th>
<th data-sort='{"key":"name"}'><?php _e('Patch files to apply', $domain)?></th> <th data-sort='{"key":"name"}'><?php _e('Patch files to apply', $domain)?></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php $files = $this->get_patch_files(); <?php $files = $this->get_patch_files();
if (!empty($files)) : ?> if (!empty($files)) : ?>
<?php foreach ($files as $file) : ?> <?php foreach ($files as $file) : ?>
<tr data-table='{"name":"<?php echo $file ?>"}'> <tr data-table='{"name":"<?php echo $file ?>"}'>
<td><input type="checkbox" id="plugin_check" name="plugin_checked[]" value="<?php echo $file ?>"/></td> <td><input type="checkbox" id="plugin_check" name="plugin_checked[]" value="<?php echo $file ?>"/></td>
<td><?php echo $file ?></td> <td><?php echo $file ?></td>
</tr> </tr>
<?php endforeach;?> <?php endforeach;?>
<?php endif;?> <?php endif;?>
</tbody> </tbody>
</table> </table>
<p> <p>
<input type="submit" name="apply_patch" class="button-primary" value="<?php _e('Apply patch', $domain);?>" onclick="return confirm('<?php _e('Are you sure to apply patch files?\n\nClick [Cancel] to stop,[OK] to continue.', $domain);?>')" /> <input type="submit" name="apply_patch" class="button-primary" value="<?php _e('Apply patch', $domain);?>" onclick="return confirm('<?php _e('Are you sure to apply patch files?\n\nClick [Cancel] to stop,[OK] to continue.', $domain);?>')" />
<input type="submit" name="patch_file_delete" class="button-primary" value="<?php _e('Delete file', $domain);?>" onclick="return confirm('<?php _e('Are you sure to delete patch files?\n\nClick [Cancel] to stop,[OK] to continue.', $domain);?>')" /> <input type="submit" name="patch_file_delete" class="button-primary" value="<?php _e('Delete file', $domain);?>" onclick="return confirm('<?php _e('Are you sure to delete patch files?\n\nClick [Cancel] to stop,[OK] to continue.', $domain);?>')" />
</p> </p>
</form> </form>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="wrap" id="sqlite-admin-side-wrap"> <div class="wrap" id="sqlite-admin-side-wrap">
<div class="alert"> <div class="alert">
<?php _e('Caution about your patch file(s)', $domain);?> <?php _e('Caution about your patch file(s)', $domain);?>
</div> </div>
<blockquote class="caution"> <blockquote class="caution">
<p> <p>
<?php _e('If you don\'t know where it comes from or who created it, I strongly recommend that you should see and check the contents of the file. If a person who created it secretly inserted a malicious codes, it will be executed by the plugin and may damage your site or your server, for which damage I don\'t incur any liability. If you don\'t understand well, you\'d better use the substitute plugins. Take your own risk, please.', $domain);?> <?php _e('If you don\'t know where it comes from or who created it, I strongly recommend that you should see and check the contents of the file. If a person who created it secretly inserted a malicious codes, it will be executed by the plugin and may damage your site or your server, for which damage I don\'t incur any liability. If you don\'t understand well, you\'d better use the substitute plugins. Take your own risk, please.', $domain);?>
</p> </p>
</blockquote> </blockquote>
</div> </div>
<?php endif; <?php endif;
} }
} }
?> ?>

File diff suppressed because it is too large Load Diff