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

53
db.php
View File

@ -34,13 +34,12 @@ if (!defined('ABSPATH')) { // Oh, you are not WordPress!
if (defined('USE_MYSQL') && USE_MYSQL) return;
function pdo_log_error($message, $data = null) {
if (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin') !== false) {
$admin_dir = '';
} else {
$admin_dir = 'wp-admin/';
}
die(<<<HTML
if (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin') !== false) {
$admin_dir = '';
} else {
$admin_dir = 'wp-admin/';
}
die(<<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
@ -84,47 +83,47 @@ if (!extension_loaded('pdo_sqlite')) {
* PDODIR is SQLite Integration installed directory.
*/
if (defined('WP_PLUGIN_DIR')) {
define('PDODIR', WP_PLUGIN_DIR . '/sqlite-integration/');
define('PDODIR', WP_PLUGIN_DIR . '/sqlite-integration/');
} else {
if (defined('WP_CONTENT_DIR')) {
define('PDODIR', WP_CONTENT_DIR . '/plugins/sqlite-integration/');
} else {
define('PDODIR', ABSPATH . 'wp-content/plugins/sqlite-integration/');
}
if (defined('WP_CONTENT_DIR')) {
define('PDODIR', WP_CONTENT_DIR . '/plugins/sqlite-integration/');
} else {
define('PDODIR', ABSPATH . 'wp-content/plugins/sqlite-integration/');
}
}
/*
* FQDBDIR is a directory where the sqlite database file is placed.
* If DB_DIR is defined, it is used as FQDBDIR.
*/
if (defined('DB_DIR')) {
if (substr(DB_DIR, -1, 1) != '/') {
define('FQDBDIR', DB_DIR . '/');
} else {
define('FQDBDIR', DB_DIR);
}
if (substr(DB_DIR, -1, 1) != '/') {
define('FQDBDIR', DB_DIR . '/');
} else {
define('FQDBDIR', DB_DIR);
}
} else {
if (defined('WP_CONTENT_DIR')) {
define('FQDBDIR', WP_CONTENT_DIR . '/database/');
} else {
define('FQDBDIR', ABSPATH . 'wp-content/database/');
}
if (defined('WP_CONTENT_DIR')) {
define('FQDBDIR', WP_CONTENT_DIR . '/database/');
} else {
define('FQDBDIR', ABSPATH . 'wp-content/database/');
}
}
/*
* FQDB is a database file name. If DB_FILE is defined, it is used
* as FQDB.
*/
if ( defined('DB_FILE' )) {
define('FQDB', FQDBDIR . DB_FILE);
define('FQDB', FQDBDIR . DB_FILE);
} else {
define('FQDB', FQDBDIR . '.ht.sqlite');
define('FQDB', FQDBDIR . '.ht.sqlite');
}
/*
* UDF_FILE is a file that contains user defined functions.
*/
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', '>=')) {
define('UDF_FILE', PDODIR . 'functions.php');
define('UDF_FILE', PDODIR . 'functions.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

@ -16,63 +16,63 @@ if (!defined('ABSPATH')) {
* This function overrides wp_install() in wp-admin/includes/upgrade.php
*/
function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') {
if (!empty($deprecated))
_deprecated_argument(__FUNCTION__, '2.6');
if (!empty($deprecated))
_deprecated_argument(__FUNCTION__, '2.6');
wp_check_mysql_version();
wp_cache_flush();
/* changes */
require_once PDODIR . 'schema.php';
make_db_sqlite();
/* changes */
populate_options();
populate_roles();
wp_check_mysql_version();
wp_cache_flush();
/* changes */
require_once PDODIR . 'schema.php';
make_db_sqlite();
/* changes */
populate_options();
populate_roles();
update_option('blogname', $blog_title);
update_option('admin_email', $user_email);
update_option('blog_public', $public);
update_option('blogname', $blog_title);
update_option('admin_email', $user_email);
update_option('blog_public', $public);
$guessurl = wp_guess_url();
$guessurl = wp_guess_url();
update_option('siteurl', $guessurl);
update_option('siteurl', $guessurl);
if (!$public)
update_option('default_pingback_flag', 0);
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_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');
$user = new WP_User($user_id);
$user->set_role('administrator');
wp_install_defaults($user_id);
wp_install_defaults($user_id);
flush_rewrite_rules();
flush_rewrite_rules();
wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.')));
wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.')));
wp_cache_flush();
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>';
}
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);
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
.wrapInner('<a href="#"></a>')
.addClass('sort');
.wrapInner('<a href="#"></a>')
.addClass('sort');
var rows = $table.find('tbody > tr').get();
$headers.bind('click', function(event) {
event.preventDefault();
var $header = $(this),
sortKey = $header.data('sort').key,
sortDirection = 1;
sortKey = $header.data('sort').key,
sortDirection = 1;
if ($header.hasClass('sorted-asc')) {
sortDirection = -1;
}
@ -70,14 +70,14 @@ jQuery(document).ready(function($) {
var $table = $('#plugins-info');
var $headers = $table.find('thead th').slice(0);
$headers
.wrapInner('<a href="#"></a>')
.addClass('sort');
.wrapInner('<a href="#"></a>')
.addClass('sort');
var rows = $table.find('tbody > tr').get();
$headers.bind('click', function(event) {
event.preventDefault();
var $header = $(this),
sortKey = $header.data('sort').key,
sortDirection = 1;
sortKey = $header.data('sort').key,
sortDirection = 1;
if ($header.hasClass('sorted-asc')) {
sortDirection = -1;
}

View File

@ -18,7 +18,7 @@ if (!defined('SAVEQUERIES')){
define ('SAVEQUERIES', false);
}
if(!defined('PDO_DEBUG')){
define('PDO_DEBUG', false);
define('PDO_DEBUG', false);
}
/**
@ -33,137 +33,137 @@ class PDODB extends wpdb {
* @var reference to the object of PDOEngine class.
* @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'));
/**
* 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();
if (WP_DEBUG)
$this->show_errors();
$this->init_charset();
$this->init_charset();
$this->db_connect();
}
/**
* Desctructor
*
* This overrides wpdb::__destruct(), but does nothing but return true.
*
* @see wpdb::__destruct()
*/
function __destruct() {
return true;
}
$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 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;
/**
* 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 (!$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;
if ($this->suppress_errors)
return false;
wp_load_translations_early();
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);
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);
error_log($error_str);
if (!$this->show_errors)
return false;
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);
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'>
<p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br />
<code>$query</code></p>
</div>";
}
}
}
}
/**
* Method to flush cached data.
*
@ -172,161 +172,161 @@ class PDODB extends wpdb {
*
* @see wpdb::flush
*/
function flush() {
$this->last_result = array();
$this->col_info = null;
$this->last_query = null;
$this->rows_affected = $this->num_rows = 0;
$this->last_error = '';
function flush() {
$this->last_result = array();
$this->col_info = null;
$this->last_query = null;
$this->rows_affected = $this->num_rows = 0;
$this->last_error = '';
$this->result = null;
}
/**
* Method to do the database connection.
*
* This overrides wpdb::db_connect() to avoid using MySQL function.
*
* @see wpdb::db_connect()
*/
function db_connect($allow_bail=true) {
if (WP_DEBUG) {
$this->dbh = new PDOEngine();
} else {
// WP_DEBUG or not, we don't use @ which causes the slow execution
// PDOEngine class will take the Exception handling.
$this->dbh = new PDOEngine();
}
if (!$this->dbh) {
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()));
return;
}
$is_enabled_foreign_keys = @$this->get_var('PRAGMA foreign_keys');
if ($is_enabled_foreign_keys == '0') @$this->query('PRAGMA foreign_keys = ON');
$this->ready = true;
}
/**
* Method to dummy out wpdb::check_connection()
*
*/
function check_connection($allow_bail=true) {
return true;
}
/**
* Method to execute the query.
*
* This overrides wpdb::query(). In fact, this method does all the database
* access jobs.
*
* @see wpdb::query()
*/
function query($query) {
if (!$this->ready)
return false;
}
/**
* Method to do the database connection.
*
* This overrides wpdb::db_connect() to avoid using MySQL function.
*
* @see wpdb::db_connect()
*/
function db_connect($allow_bail=true) {
if (WP_DEBUG) {
$this->dbh = new PDOEngine();
} else {
// WP_DEBUG or not, we don't use @ which causes the slow execution
// PDOEngine class will take the Exception handling.
$this->dbh = new PDOEngine();
}
if (!$this->dbh) {
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()));
return;
}
$is_enabled_foreign_keys = @$this->get_var('PRAGMA foreign_keys');
if ($is_enabled_foreign_keys == '0') @$this->query('PRAGMA foreign_keys = ON');
$this->ready = true;
}
/**
* Method to dummy out wpdb::check_connection()
*
*/
function check_connection($allow_bail=true) {
return true;
}
/**
* Method to execute the query.
*
* This overrides wpdb::query(). In fact, this method does all the database
* access jobs.
*
* @see wpdb::query()
*/
function query($query) {
if (!$this->ready)
return false;
$query = apply_filters('query', $query);
$query = apply_filters('query', $query);
$return_val = 0;
$this->flush();
$return_val = 0;
$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)
$this->timer_start();
if (defined('SAVEQUERIES') && SAVEQUERIES)
$this->timer_start();
$this->result = $this->dbh->query($query);
$this->num_queries++;
$this->result = $this->dbh->query($query);
$this->num_queries++;
if (defined('SAVEQUERIES') && SAVEQUERIES)
$this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
if (defined('SAVEQUERIES') && SAVEQUERIES)
$this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
if ($this->last_error = $this->dbh->get_error_message()) {
if (defined('WP_INSTALLING') && WP_INSTALLING) {
//$this->suppress_errors();
} else {
$this->print_error($this->last_error);
return false;
}
}
if ($this->last_error = $this->dbh->get_error_message()) {
if (defined('WP_INSTALLING') && WP_INSTALLING) {
//$this->suppress_errors();
} else {
$this->print_error($this->last_error);
return false;
}
}
if (preg_match('/^\\s*(create|alter|truncate|drop|optimize)\\s*/i', $query)) {
// $return_val = $this->result;
$return_val = $this->dbh->get_return_value();
} elseif (preg_match('/^\\s*(insert|delete|update|replace)\s/i', $query)) {
$this->rows_affected = $this->dbh->get_affected_rows();
if (preg_match('/^\s*(insert|replace)\s/i', $query)) {
$this->insert_id = $this->dbh->get_insert_id();
}
$return_val = $this->rows_affected;
} else {
$this->last_result = $this->dbh->get_query_results();
$this->num_rows = $this->dbh->get_num_rows();
$return_val = $this->num_rows;
}
return $return_val;
}
/**
*
*/
private function _do_query($query) {
if (defined('SAVEQUERIES') && SAVEQUERIES) {
$this->timer_start();
}
$this->result = $this->dbh->query($query);
$this->num_queries++;
if (defined('SAVEQUERIES') && SAVEQUERIES) {
$this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
}
}
/**
* Method to set the class variable $col_info.
*
* This overrides wpdb::load_col_info(), which uses a mysql function.
*
* @see wpdb::load_col_info()
* @access protected
*/
protected function load_col_info() {
if ($this->col_info)
return;
$this->col_info = $this->dbh->get_columns();
}
if (preg_match('/^\\s*(create|alter|truncate|drop|optimize)\\s*/i', $query)) {
//$return_val = $this->result;
$return_val = $this->dbh->get_return_value();
} elseif (preg_match('/^\\s*(insert|delete|update|replace)\s/i', $query)) {
$this->rows_affected = $this->dbh->get_affected_rows();
if (preg_match('/^\s*(insert|replace)\s/i', $query)) {
$this->insert_id = $this->dbh->get_insert_id();
}
$return_val = $this->rows_affected;
} else {
$this->last_result = $this->dbh->get_query_results();
$this->num_rows = $this->dbh->get_num_rows();
$return_val = $this->num_rows;
}
return $return_val;
}
/**
*
*/
private function _do_query($query) {
if (defined('SAVEQUERIES') && SAVEQUERIES) {
$this->timer_start();
}
$this->result = $this->dbh->query($query);
$this->num_queries++;
if (defined('SAVEQUERIES') && SAVEQUERIES) {
$this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
}
}
/**
* Method to set the class variable $col_info.
*
* This overrides wpdb::load_col_info(), which uses a mysql function.
*
* @see wpdb::load_col_info()
* @access protected
*/
protected function load_col_info() {
if ($this->col_info)
return;
$this->col_info = $this->dbh->get_columns();
}
/**
* Method to return what the database can do.
*
* This overrides wpdb::has_cap() to avoid using MySQL functions.
* SQLite supports subqueries, but not support collation, group_concat and set_charset.
*
* @see wpdb::has_cap()
*/
function has_cap($db_cap) {
switch(strtolower($db_cap)) {
case 'collation':
case 'group_concat':
case 'set_charset':
return false;
case 'subqueries':
return true;
default:
return false;
}
}
/**
* Method to return database version number.
*
* This overrides wpdb::db_version() to avoid using MySQL function.
* It returns mysql version number, but it means nothing for SQLite.
* So it return the newest mysql version.
*
* @see wpdb::db_version()
*/
function db_version() {
// global $required_mysql_version;
// return $required_mysql_version;
/**
* Method to return what the database can do.
*
* This overrides wpdb::has_cap() to avoid using MySQL functions.
* SQLite supports subqueries, but not support collation, group_concat and set_charset.
*
* @see wpdb::has_cap()
*/
function has_cap($db_cap) {
switch(strtolower($db_cap)) {
case 'collation':
case 'group_concat':
case 'set_charset':
return false;
case 'subqueries':
return true;
default:
return false;
}
}
/**
* Method to return database version number.
*
* This overrides wpdb::db_version() to avoid using MySQL function.
* It returns mysql version number, but it means nothing for SQLite.
* So it return the newest mysql version.
*
* @see wpdb::db_version()
*/
function db_version() {
//global $required_mysql_version;
//return $required_mysql_version;
return '5.5';
}
}
}
/*

File diff suppressed because it is too large Load Diff

View File

@ -48,6 +48,12 @@ class PDOSQLiteDriver {
* @var boolean
*/
private $rewrite_between = false;
/**
* Variable to check how many times rewriting BETWEEN is needed.
*
* @var integer
*/
private $num_of_rewrite_between = 0;
/**
* Method to rewrite a query string for SQLite to execute.
*
@ -57,82 +63,82 @@ class PDOSQLiteDriver {
*/
public function rewrite_query($query, $query_type){
$this->query_type = $query_type;
$this->_query = $query;
$this->parse_query();
$this->_query = $query;
$this->parse_query();
switch ($this->query_type) {
case 'truncate':
$this->handle_truncate_query();
break;
case 'alter':
$this->handle_alter_query();
break;
case 'create':
$this->handle_create_query();
break;
case 'describe':
case 'desc':
$this->handle_describe_query();
break;
case 'show':
$this->handle_show_query();
break;
case 'showcolumns':
$this->handle_show_columns_query();
break;
case 'showindex':
$this->handle_show_index();
break;
case 'select':
//$this->strip_backticks();
$this->handle_sql_count();
$this->rewrite_date_sub();
$this->delete_index_hints();
$this->rewrite_regexp();
//$this->rewrite_boolean();
$this->fix_date_quoting();
$this->rewrite_between();
break;
case 'insert':
//$this->safe_strip_backticks();
$this->execute_duplicate_key_update();
$this->rewrite_insert_ignore();
$this->rewrite_regexp();
$this->fix_date_quoting();
break;
case 'update':
//$this->safe_strip_backticks();
$this->rewrite_update_ignore();
// $this->_rewrite_date_sub();
$this->rewrite_limit_usage();
$this->rewrite_order_by_usage();
$this->rewrite_regexp();
$this->rewrite_between();
break;
case 'delete':
//$this->strip_backticks();
$this->rewrite_limit_usage();
$this->rewrite_order_by_usage();
$this->rewrite_date_sub();
$this->rewrite_regexp();
$this->delete_workaround();
break;
case 'replace':
//$this->safe_strip_backticks();
$this->rewrite_date_sub();
$this->rewrite_regexp();
break;
case 'optimize':
$this->rewrite_optimize();
break;
case 'pragma':
break;
default:
if (defined(WP_DEBUG) && WP_DEBUG) {
break;
} else {
$this->return_true();
break;
}
case 'truncate':
$this->handle_truncate_query();
break;
case 'alter':
$this->handle_alter_query();
break;
case 'create':
$this->handle_create_query();
break;
case 'describe':
case 'desc':
$this->handle_describe_query();
break;
case 'show':
$this->handle_show_query();
break;
case 'showcolumns':
$this->handle_show_columns_query();
break;
case 'showindex':
$this->handle_show_index();
break;
case 'select':
//$this->strip_backticks();
$this->handle_sql_count();
$this->rewrite_date_sub();
$this->delete_index_hints();
$this->rewrite_regexp();
//$this->rewrite_boolean();
$this->fix_date_quoting();
$this->rewrite_between();
break;
case 'insert':
//$this->safe_strip_backticks();
$this->execute_duplicate_key_update();
$this->rewrite_insert_ignore();
$this->rewrite_regexp();
$this->fix_date_quoting();
break;
case 'update':
//$this->safe_strip_backticks();
$this->rewrite_update_ignore();
//$this->_rewrite_date_sub();
$this->rewrite_limit_usage();
$this->rewrite_order_by_usage();
$this->rewrite_regexp();
$this->rewrite_between();
break;
case 'delete':
//$this->strip_backticks();
$this->rewrite_limit_usage();
$this->rewrite_order_by_usage();
$this->rewrite_date_sub();
$this->rewrite_regexp();
$this->delete_workaround();
break;
case 'replace':
//$this->safe_strip_backticks();
$this->rewrite_date_sub();
$this->rewrite_regexp();
break;
case 'optimize':
$this->rewrite_optimize();
break;
case 'pragma':
break;
default:
if (defined(WP_DEBUG) && WP_DEBUG) {
break;
} else {
$this->return_true();
break;
}
}
return $this->_query;
}
@ -161,29 +167,30 @@ class PDOSQLiteDriver {
if (strpos($token, '`') !== false) {
$token = str_replace('`', '', $token);
}
if (preg_match('/\\bTRUE\\b/i', $token)) {
$token = str_ireplace('TRUE', '1', $token);
}
if (preg_match('/\\bFALSE\\b/i', $token)) {
$token = str_ireplace('FALSE', '0', $token);
}
if (stripos($token, 'SQL_CALC_FOUND_ROWS') !== false) {
if (preg_match('/\\bTRUE\\b/i', $token)) {
$token = str_ireplace('TRUE', '1', $token);
}
if (preg_match('/\\bFALSE\\b/i', $token)) {
$token = str_ireplace('FALSE', '0', $token);
}
if (stripos($token, 'SQL_CALC_FOUND_ROWS') !== false) {
$this->rewrite_calc_found = true;
}
if (stripos($token, 'ON DUPLICATE KEY UPDATE') !== false) {
if (stripos($token, 'ON DUPLICATE KEY UPDATE') !== false) {
$this->rewrite_duplicate_key = true;
}
if (stripos($token, 'USE INDEX') !== false) {
if (stripos($token, 'USE INDEX') !== false) {
$this->rewrite_index_hint = true;
}
if (stripos($token, 'IGNORE INDEX') !== false) {
if (stripos($token, 'IGNORE INDEX') !== false) {
$this->rewrite_index_hint = true;
}
if (stripos($token, 'FORCE INDEX') !== false) {
if (stripos($token, 'FORCE INDEX') !== false) {
$this->rewrite_index_hint = true;
}
if (stripos($token, 'BETWEEN') !== false) {
if (stripos($token, 'BETWEEN') !== false) {
$this->rewrite_between = true;
$this->num_of_rewrite_between++;
}
}
}
@ -197,11 +204,11 @@ class PDOSQLiteDriver {
* @access private
*/
private function handle_show_query(){
$this->_query = str_ireplace(' FULL', '', $this->_query);
$table_name = '';
$this->_query = str_ireplace(' FULL', '', $this->_query);
$table_name = '';
$pattern = '/^\\s*SHOW\\s*TABLES\\s*.*?(LIKE\\s*(.*))$/im';
if (preg_match($pattern, $this->_query, $matches)) {
$table_name = str_replace(array("'", ';'), '', $matches[2]);
$table_name = str_replace(array("'", ';'), '', $matches[2]);
}
if (!empty($table_name)) {
$suffix = ' AND name LIKE '. "'" . $table_name . "'";
@ -276,8 +283,8 @@ class PDOSQLiteDriver {
$this->_query = str_ireplace('SQL_CALC_FOUND_ROWS', '', $this->_query);
// we make the data for next SELECE FOUND_ROWS() statement
$unlimited_query = preg_replace('/\\bLIMIT\\s*.*/imsx', '', $this->_query);
//$unlimited_query = preg_replace('/\\bGROUP\\s*BY\\s*.*/imsx', '', $unlimited_query);
// we no longer use SELECT COUNT query
//$unlimited_query = preg_replace('/\\bGROUP\\s*BY\\s*.*/imsx', '', $unlimited_query);
// we no longer use SELECT COUNT query
//$unlimited_query = $this->_transform_to_count($unlimited_query);
$_wpdb = new PDODB();
$result = $_wpdb->query($unlimited_query);
@ -325,10 +332,10 @@ class PDOSQLiteDriver {
private function rewrite_date_add(){
//(date,interval expression unit)
$pattern = '/\\s*date_add\\s*\(([^,]*),([^\)]*)\)/imsx';
if (preg_match($pattern, $this->_query, $matches)) {
$expression = "'".trim($matches[2])."'";
$this->_query = preg_replace($pattern, " date_add($matches[1], $expression) ", $this->_query);
}
if (preg_match($pattern, $this->_query, $matches)) {
$expression = "'".trim($matches[2])."'";
$this->_query = preg_replace($pattern, " date_add($matches[1], $expression) ", $this->_query);
}
}
/**
* Method to rewrite DATE_SUB() function.
@ -341,10 +348,10 @@ class PDOSQLiteDriver {
private function rewrite_date_sub(){
//(date,interval expression unit)
$pattern = '/\\s*date_sub\\s*\(([^,]*),([^\)]*)\)/imsx';
if (preg_match($pattern, $this->_query, $matches)) {
$expression = "'".trim($matches[2])."'";
$this->_query = preg_replace($pattern, " date_sub($matches[1], $expression) ", $this->_query);
}
if (preg_match($pattern, $this->_query, $matches)) {
$expression = "'".trim($matches[2])."'";
$this->_query = preg_replace($pattern, " date_sub($matches[1], $expression) ", $this->_query);
}
}
/**
* Method to handle CREATE query.
@ -370,10 +377,10 @@ class PDOSQLiteDriver {
* @access private
*/
private function handle_alter_query(){
require_once PDODIR . 'query_alter.class.php';
$engine = new AlterQuery();
$this->_query = $engine->rewrite_query($this->_query, 'alter');
$engine = null;
require_once PDODIR . 'query_alter.class.php';
$engine = new AlterQuery();
$this->_query = $engine->rewrite_query($this->_query, 'alter');
$engine = null;
}
/**
@ -385,11 +392,10 @@ class PDOSQLiteDriver {
* @access private
*/
private function handle_describe_query(){
// $this->_query = "select 1=1";
$pattern = '/^\\s*(DESCRIBE|DESC)\\s*(.*)/i';
if (preg_match($pattern, $this->_query, $match)) {
$tablename = preg_replace('/[\';]/', '', $match[2]);
$this->_query = "PRAGMA table_info($tablename)";
$tablename = preg_replace('/[\';]/', '', $match[2]);
$this->_query = "PRAGMA table_info($tablename)";
}
}
/**
@ -409,9 +415,9 @@ class PDOSQLiteDriver {
foreach ($options as $opt) {
if (stripos($opt->compile_option, 'ENABLE_UPDATE_DELETE_LIMIT') !== false) return;
}
if (stripos($this->_query, '(select') === false) {
$this->_query = preg_replace('/\\s*LIMIT\\s*[0-9]$/i', '', $this->_query);
}
if (stripos($this->_query, '(select') === false) {
$this->_query = preg_replace('/\\s*LIMIT\\s*[0-9]$/i', '', $this->_query);
}
}
/**
* Method to remove ORDER BY clause from DELETE or UPDATE query.
@ -428,9 +434,9 @@ class PDOSQLiteDriver {
foreach ($options as $opt) {
if (stripos($opt->compile_option, 'ENABLE_UPDATE_DELETE_LIMIT') !== false) return;
}
if (stripos($this->_query, '(select') === false) {
$this->_query = preg_replace('/\\s*ORDER\\s*BY\\s*.*$/i', '', $this->_query);
}
if (stripos($this->_query, '(select') === false) {
$this->_query = preg_replace('/\\s+ORDER\\s+BY\\s*.*$/i', '', $this->_query);
}
}
/**
* Method to handle TRUNCATE query.
@ -529,241 +535,241 @@ class PDOSQLiteDriver {
* @access private
*/
private function rewrite_boolean() {
$query = str_ireplace('TRUE', "1", $this->_query);
$query = str_ireplace('FALSE', "0", $query);
$this->_query = $query;
$query = str_ireplace('TRUE', "1", $this->_query);
$query = str_ireplace('FALSE', "0", $query);
$this->_query = $query;
}
/**
* Method to handl SHOW COLUMN query.
*
* @access private
*/
private function handle_show_columns_query() {
$this->_query = str_ireplace(' FULL', '', $this->_query);
$pattern_like = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?\\s*LIKE\\s*(.*)?/i';
$pattern = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?/i';
if (preg_match($pattern_like, $this->_query, $matches)) {
$table_name = str_replace("'", "", trim($matches[2]));
$column_name = str_replace("'", "", trim($matches[3]));
$query_string = "SELECT sql FROM sqlite_master WHERE tbl_name='$table_name' AND sql LIKE '%$column_name%'";
$this->_query = $query_string;
} elseif (preg_match($pattern, $this->_query, $matches)) {
$table_name = $matches[2];
$query_string = preg_replace($pattern, "PRAGMA table_info($table_name)", $this->_query);
$this->_query = $query_string;
}
}
/**
* Method to handle SHOW INDEX query.
*
* Moved the WHERE clause manipulation to pdoengin.class.php (ver 1.3.1)
*
* @access private
*/
private function handle_show_index() {
$pattern = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?/im';
if (preg_match($pattern, $this->_query, $match)) {
$table_name = preg_replace("/[\';]/", '', $match[1]);
$table_name = trim($table_name);
$this->_query = "SELECT * FROM sqlite_master WHERE tbl_name='$table_name'";
}
}
/**
* Method to handle ON DUPLICATE KEY UPDATE statement.
*
* First we use SELECT query and check if INSERT is allowed or not.
* Rewriting procedure looks like a detour, but I've got no other ways.
*
* Added the literal check since the version 1.5.1.
*
* @return void
* @access private
*/
private function execute_duplicate_key_update() {
if (!$this->rewrite_duplicate_key) return;
$unique_keys_for_cond = array();
$unique_keys_for_check = array();
$pattern = '/^\\s*INSERT\\s*INTO\\s*(\\w+)?\\s*(.*)\\s*ON\\s*DUPLICATE\\s*KEY\\s*UPDATE\\s*(.*)$/ims';
if (preg_match($pattern, $this->_query, $match_0)) {
$table_name = trim($match_0[1]);
$insert_data = trim($match_0[2]);
$update_data = trim($match_0[3]);
// prepare two unique key data for the table
// 1. array('col1', 'col2, col3', etc) 2. array('col1', 'col2', 'col3', etc)
$_wpdb = new PDODB();
$indexes = $_wpdb->get_results("SHOW INDEX FROM {$table_name}");
if (!empty($indexes)) {
foreach ($indexes as $index) {
if ($index->Non_unique == 0) {
$unique_keys_for_cond[] = $index->Column_name;
if (strpos($index->Column_name, ',') !== false) {
$unique_keys_for_check = array_merge($unique_keys_for_check, explode(',', $index->Column_name));
} else {
$unique_keys_for_check[] = $index->Column_name;
}
}
}
$unique_keys_for_check = array_map('trim', $unique_keys_for_check);
} else {
// Without unique key or primary key, UPDATE statement will affect all the rows!
$query = 'INSERT INTO '.$table_name.' '.$insert_data;
$this->_query = $query;
$_wpdb = null;
return;
}
// data check
if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/ims', $insert_data, $match_1)) {
$col_array = explode(',', $match_1[1]);
$ins_data_array = explode(',', $match_1[2]);
foreach ($col_array as $col) {
$val = trim(array_shift($ins_data_array));
$ins_data_assoc[trim($col)] = $val;
}
// $ins_data_assoc = array_combine($col_array, $ins_array);
$condition = '';
foreach ($unique_keys_for_cond as $unique_key) {
if (strpos($unique_key, ',') !== false) {
$unique_key_array = explode(',', $unique_key);
$counter = count($unique_key_array);
for ($i = 0; $i < $counter; ++$i) {
$col = trim($unique_key_array[$i]);
if (isset($ins_data_assoc[$col]) && $i == $counter - 1) {
$condition .= $col . '=' . $ins_data_assoc[$col] . ' OR ';
} elseif (isset($ins_data_assoc[$col])) {
$condition .= $col . '=' . $ins_data_assoc[$col] . ' AND ';
} else {
continue;
}
}
// $condition = rtrim($condition, ' AND ');
} else {
$col = trim($unique_key);
if (isset($ins_data_assoc[$col])) {
$condition .= $col . '=' . $ins_data_assoc[$col] . ' OR ';
} else {
continue;
}
}
}
$condition = rtrim($condition, ' OR ');
$test_query = "SELECT * FROM {$table_name} WHERE {$condition}";
$results = $_wpdb->query($test_query);
$_wpdb = null;
if ($results == 0) {
$this->_query = 'INSERT INTO '.$table_name.' '.$insert_data;
return;
} else {
// change (col, col...) values (data, data...) to array(col=>data, col=>data...)
if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/im', $insert_data, $match_2)) {
$col_array = explode(',', $match_2[1]);
$ins_array = explode(',', $match_2[2]);
$count = count($col_array);
for ($i = 0; $i < $count; $i++) {
$col = trim($col_array[$i]);
$val = trim($ins_array[$i]);
$ins_array_assoc[$col] = $val;
}
}
// change col = data, col = data to array(col=>data, col=>data)
// some plugins have semi-colon at the end of the query
$update_data = rtrim($update_data, ';');
$tmp_array = explode(',', $update_data);
foreach ($tmp_array as $pair) {
list($col, $value) = explode('=', $pair);
$col = trim($col);
$value = trim($value);
$update_array_assoc[$col] = $value;
}
// change array(col=>values(col)) to array(col=>data)
foreach ($update_array_assoc as $key => &$value) {
if (preg_match('/^VALUES\\s*\((.*)\)$/im', $value, $match_3)) {
$col = trim($match_3[1]);
$value = $ins_array_assoc[$col];
}
}
foreach ($ins_array_assoc as $key => $val) {
if (in_array($key, $unique_keys_for_check)) {
$where_array[] = $key . '=' . $val;
}
}
$update_strings = '';
foreach ($update_array_assoc as $key => $val) {
if (in_array($key, $unique_keys_for_check)) {
$where_array[] = $key . '=' . $val;
} else {
$update_strings .= $key . '=' . $val . ',';
}
}
$update_strings = rtrim($update_strings, ',');
$unique_where = array_unique($where_array, SORT_REGULAR);
$where_string = ' WHERE ' . implode(' AND ', $unique_where);
// $where_string = ' WHERE ' . rtrim($where_string, ',');
$update_query = 'UPDATE ' . $table_name . ' SET ' . $update_strings . $where_string;
$this->_query = $update_query;
}
}
}
// else {
// $pattern = '/ ON DUPLICATE KEY UPDATE.*$/im';
// $replace_query = preg_replace($pattern, '', $this->_query);
// $replace_query = str_ireplace('INSERT ', 'INSERT OR REPLACE ', $replace_query);
// $this->_query = $replace_query;
// }
}
/**
* Method to rewrite BETWEEN A AND B clause.
*
* This clause is the same form as natural language, so we have to check if it is
* in the data or SQL statement.
*
* @access private
*/
private function rewrite_between() {
if (!$this->rewrite_between) return;
$pattern = '/\\s*(CAST\([^\)]+?\)|[^\\s\(]*)?\\s*BETWEEN\\s*([^\\s]*)?\\s*AND\\s*([^\\s\)]*)?\\s*/ims';
if (preg_match($pattern, $this->_query, $match)) {
$column_name = trim($match[1]);
$min_value = trim($match[2]);
$max_value = trim($match[3]);
$max_value = rtrim($max_value);
$replacement = " $column_name >= $min_value AND $column_name <= $max_value";
$this->_query = str_ireplace($match[0], $replacement, $this->_query);
$this->rewrite_between = false;
}
$this->parse_query();
$this->rewrite_between();
}
/**
* Method to avoid DELETE with JOIN statement.
*
* wp-admin/includes/upgrade.php contains 'DELETE ... JOIN' statement.
* This query can't be replaced with regular expression or udf, so we
* replace all the statement with another. But this query was used in
* the very old version of WordPress when it was upgraded. So we won't
* have no chance that this method should be used.
*
* @access private
*/
private function delete_workaround() {
global $wpdb;
// $pattern = "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (option_name) WHERE o2.option_id > o1.option_id";
private function handle_show_columns_query() {
$this->_query = str_ireplace(' FULL', '', $this->_query);
$pattern_like = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?\\s*LIKE\\s*(.*)?/i';
$pattern = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?/i';
if (preg_match($pattern_like, $this->_query, $matches)) {
$table_name = str_replace("'", "", trim($matches[2]));
$column_name = str_replace("'", "", trim($matches[3]));
$query_string = "SELECT sql FROM sqlite_master WHERE tbl_name='$table_name' AND sql LIKE '%$column_name%'";
$this->_query = $query_string;
} elseif (preg_match($pattern, $this->_query, $matches)) {
$table_name = $matches[2];
$query_string = preg_replace($pattern, "PRAGMA table_info($table_name)", $this->_query);
$this->_query = $query_string;
}
}
/**
* Method to handle SHOW INDEX query.
*
* Moved the WHERE clause manipulation to pdoengin.class.php (ver 1.3.1)
*
* @access private
*/
private function handle_show_index() {
$pattern = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?/im';
if (preg_match($pattern, $this->_query, $match)) {
$table_name = preg_replace("/[\';]/", '', $match[1]);
$table_name = trim($table_name);
$this->_query = "SELECT * FROM sqlite_master WHERE tbl_name='$table_name'";
}
}
/**
* Method to handle ON DUPLICATE KEY UPDATE statement.
*
* First we use SELECT query and check if INSERT is allowed or not.
* Rewriting procedure looks like a detour, but I've got no other ways.
*
* Added the literal check since the version 1.5.1.
*
* @return void
* @access private
*/
private function execute_duplicate_key_update() {
if (!$this->rewrite_duplicate_key) return;
$unique_keys_for_cond = array();
$unique_keys_for_check = array();
$pattern = '/^\\s*INSERT\\s*INTO\\s*(\\w+)?\\s*(.*)\\s*ON\\s*DUPLICATE\\s*KEY\\s*UPDATE\\s*(.*)$/ims';
if (preg_match($pattern, $this->_query, $match_0)) {
$table_name = trim($match_0[1]);
$insert_data = trim($match_0[2]);
$update_data = trim($match_0[3]);
// prepare two unique key data for the table
// 1. array('col1', 'col2, col3', etc) 2. array('col1', 'col2', 'col3', etc)
$_wpdb = new PDODB();
$indexes = $_wpdb->get_results("SHOW INDEX FROM {$table_name}");
if (!empty($indexes)) {
foreach ($indexes as $index) {
if ($index->Non_unique == 0) {
$unique_keys_for_cond[] = $index->Column_name;
if (strpos($index->Column_name, ',') !== false) {
$unique_keys_for_check = array_merge($unique_keys_for_check, explode(',', $index->Column_name));
} else {
$unique_keys_for_check[] = $index->Column_name;
}
}
}
$unique_keys_for_check = array_map('trim', $unique_keys_for_check);
} else {
// Without unique key or primary key, UPDATE statement will affect all the rows!
$query = 'INSERT INTO '.$table_name.' '.$insert_data;
$this->_query = $query;
$_wpdb = null;
return;
}
// data check
if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/ims', $insert_data, $match_1)) {
$col_array = explode(',', $match_1[1]);
$ins_data_array = explode(',', $match_1[2]);
foreach ($col_array as $col) {
$val = trim(array_shift($ins_data_array));
$ins_data_assoc[trim($col)] = $val;
}
$ins_data_assoc = array_combine($col_array, $ins_array);
$condition = '';
foreach ($unique_keys_for_cond as $unique_key) {
if (strpos($unique_key, ',') !== false) {
$unique_key_array = explode(',', $unique_key);
$counter = count($unique_key_array);
for ($i = 0; $i < $counter; ++$i) {
$col = trim($unique_key_array[$i]);
if (isset($ins_data_assoc[$col]) && $i == $counter - 1) {
$condition .= $col . '=' . $ins_data_assoc[$col] . ' OR ';
} elseif (isset($ins_data_assoc[$col])) {
$condition .= $col . '=' . $ins_data_assoc[$col] . ' AND ';
} else {
continue;
}
}
$condition = rtrim($condition, ' AND ');
} else {
$col = trim($unique_key);
if (isset($ins_data_assoc[$col])) {
$condition .= $col . '=' . $ins_data_assoc[$col] . ' OR ';
} else {
continue;
}
}
}
$condition = rtrim($condition, ' OR ');
$test_query = "SELECT * FROM {$table_name} WHERE {$condition}";
$results = $_wpdb->query($test_query);
$_wpdb = null;
if ($results == 0) {
$this->_query = 'INSERT INTO '.$table_name.' '.$insert_data;
return;
} else {
if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/im', $insert_data, $match_2)) {
$col_array = explode(',', $match_2[1]);
$ins_array = explode(',', $match_2[2]);
$count = count($col_array);
for ($i = 0; $i < $count; $i++) {
$col = trim($col_array[$i]);
$val = trim($ins_array[$i]);
$ins_array_assoc[$col] = $val;
}
}
$update_data = rtrim($update_data, ';');
$tmp_array = explode(',', $update_data);
foreach ($tmp_array as $pair) {
list($col, $value) = explode('=', $pair);
$col = trim($col);
$value = trim($value);
$update_array_assoc[$col] = $value;
}
foreach ($update_array_assoc as $key => &$value) {
if (preg_match('/^VALUES\\s*\((.*)\)$/im', $value, $match_3)) {
$col = trim($match_3[1]);
$value = $ins_array_assoc[$col];
}
}
foreach ($ins_array_assoc as $key => $val) {
if (in_array($key, $unique_keys_for_check)) {
$where_array[] = $key . '=' . $val;
}
}
$update_strings = '';
foreach ($update_array_assoc as $key => $val) {
if (in_array($key, $unique_keys_for_check)) {
$where_array[] = $key . '=' . $val;
} else {
$update_strings .= $key . '=' . $val . ',';
}
}
$update_strings = rtrim($update_strings, ',');
$unique_where = array_unique($where_array, SORT_REGULAR);
$where_string = ' WHERE ' . implode(' AND ', $unique_where);
$update_query = 'UPDATE ' . $table_name . ' SET ' . $update_strings . $where_string;
$this->_query = $update_query;
}
}
}
}
/**
* Method to rewrite BETWEEN A AND B clause.
*
* This clause is the same form as natural language, so we have to check if it is
* in the data or SQL statement.
*
* @access private
*/
private function rewrite_between() {
if (!$this->rewrite_between) return;
$pattern = '/\\s*(CAST\([^\)]+?\)|[^\\s\(]*)?\\s*BETWEEN\\s*([^\\s]*)?\\s*AND\\s*([^\\s\)]*)?\\s*/ims';
do {
if (preg_match($pattern, $this->_query, $match)) {
$column_name = trim($match[1]);
$min_value = trim($match[2]);
$max_value = trim($match[3]);
$max_value = rtrim($max_value);
$replacement = " ($column_name >= $min_value AND $column_name <= $max_value)";
$this->_query = str_ireplace($match[0], $replacement, $this->_query);
}
$this->num_of_rewrite_between--;
} while ($this->num_of_rewrite_between > 0);
}
/**
* Method to avoid DELETE with JOIN statement.
*
* wp-admin/includes/upgrade.php contains 'DELETE ... JOIN' statement.
* This query can't be replaced with regular expression or udf, so we
* replace all the statement with another. But this query was used in
* the very old version of WordPress when it was upgraded. So we won't
* have no chance that this method should be used.
*
* @access private
*/
private function delete_workaround() {
global $wpdb;
$pattern = "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2";
$rewritten = "DELETE FROM $wpdb->options WHERE option_id IN (SELECT MIN(option_id) FROM $wpdb->options GROUP BY option_name HAVING COUNT(*) > 1)";
if (stripos($this->_query, $pattern) !== false) {
$this->_query = $rewritten;
}
}
/**
* Method to suppress errors.
*
* When the query string is the one that this class can't manipulate,
* the query string is replaced with the one that always returns true
* and does nothing.
*
* @access private
*/
private function return_true() {
$this->_query = 'SELECT 1=1';
}
$pattern2 = "DELETE a, b FROM $wpdb->sitemeta AS a, $wpdb->sitemeta AS b";
$rewritten = "DELETE FROM $wpdb->options WHERE option_id IN (SELECT MIN(option_id) FROM $wpdb->options GROUP BY option_name HAVING COUNT(*) > 1)";
if (stripos($this->_query, $pattern) !== false) {
$this->_query = $rewritten;
} else if (stripos($this->_query, $pattern2) !== false) {
$time = time();
$prep_query = "SELECT a.meta_id AS aid, b.meta_id AS bid FROM $wpdb->sitemeta AS a INNER JOIN $wpdb->sitemeta AS b ON a.meta_key='_site_transient_timeout_'||substr(b.meta_key, 17) WHERE b.meta_key='_site_transient_'||substr(a.meta_key, 25) AND a.meta_value < $time";
$_wpdb = new PDODB();
$ids = $_wpdb->get_results($prep_query);
foreach ($ids as $id) {
$ids_to_delete[] = $id->aid;
$ids_to_delete[] = $id->bid;
}
$rewritten = "DELETE FROM $wpdb->sitemeta WHERE meta_id IN (".implode(',', $ids_to_delete).")";
$this->_query = $rewritten;
}
}
/**
* Method to suppress errors.
*
* When the query string is the one that this class can't manipulate,
* the query string is replaced with the one that always returns true
* and does nothing.
*
* @access private
*/
private function return_true() {
$this->_query = 'SELECT 1=1';
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -98,10 +98,10 @@ class CreateQuery{
*/
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\\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)) {
$this->table_name = trim($matches[1]);
}
$this->table_name = trim($matches[1]);
}
}
/**
* Method to change the MySQL field types to SQLite compatible types.
@ -112,23 +112,23 @@ class CreateQuery{
*/
private function rewrite_field_types(){
$array_types = array (
'bit' => 'integer', 'bool' => 'integer',
'boolean' => 'integer', 'tinyint' => 'integer',
'smallint' => 'integer', 'mediumint' => 'integer',
'int' => 'integer', 'integer' => 'integer',
'bigint' => 'integer', 'float' => 'real',
'double' => 'real', 'decimal' => 'real',
'dec' => 'real', 'numeric' => 'real',
'fixed' => 'real', 'date' => 'text',
'datetime' => 'text', 'timestamp' => 'text',
'time' => 'text', 'year' => 'text',
'char' => 'text', 'varchar' => 'text',
'binary' => 'integer', 'varbinary' => 'blob',
'tinyblob' => 'blob', 'tinytext' => 'text',
'blob' => 'blob', 'text' => 'text',
'mediumblob' => 'blob', 'mediumtext' => 'text',
'longblob' => 'blob', 'longtext' => 'text'
);
'bit' => 'integer', 'bool' => 'integer',
'boolean' => 'integer', 'tinyint' => 'integer',
'smallint' => 'integer', 'mediumint' => 'integer',
'int' => 'integer', 'integer' => 'integer',
'bigint' => 'integer', 'float' => 'real',
'double' => 'real', 'decimal' => 'real',
'dec' => 'real', 'numeric' => 'real',
'fixed' => 'real', 'date' => 'text',
'datetime' => 'text', 'timestamp' => 'text',
'time' => 'text', 'year' => 'text',
'char' => 'text', 'varchar' => 'text',
'binary' => 'integer', 'varbinary' => 'blob',
'tinyblob' => 'blob', 'tinytext' => 'text',
'blob' => 'blob', 'text' => 'text',
'mediumblob' => 'blob', 'mediumtext' => 'text',
'longblob' => 'blob', 'longtext' => 'text'
);
foreach ($array_types as $o=>$r){
$pattern = "/\\b(?<!`)$o\\b\\s*(\([^\)]*\)*)?\\s*/ims";
if (preg_match("/^\\s*.*?\\s*\(.*?$o.*?\)/im", $this->_query)) {
@ -193,23 +193,23 @@ class CreateQuery{
if ($this->has_primary_key) {
$this->_query = preg_replace('/\\s*primary key\\s*.*?\([^\)]*\)\\s*(,|)/i', ' ', $this->_query);
} else {
// 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);
// 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);
}
}
/**
* 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.
*
@ -225,24 +225,24 @@ class CreateQuery{
* @access private
*/
private function _rewrite_unique_key($matches){
$index_name = trim($matches[1]);
$col_name = trim($matches[2]);
$tbl_name = $this->table_name;
if (preg_match('/\(\\d+?\)/', $col_name)) {
$col_name = preg_replace('/\(\\d+?\)/', '', $col_name);
}
$_wpdb = new PDODB();
$results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'");
$_wpdb = null;
if ($results) {
foreach ($results as $result) {
if ($result->name == $index_name) {
$r = rand(0, 50);
$index_name = $index_name . "_$r";
break;
}
}
}
$index_name = trim($matches[1]);
$col_name = trim($matches[2]);
$tbl_name = $this->table_name;
if (preg_match('/\(\\d+?\)/', $col_name)) {
$col_name = preg_replace('/\(\\d+?\)/', '', $col_name);
}
$_wpdb = new PDODB();
$results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'");
$_wpdb = null;
if ($results) {
foreach ($results as $result) {
if ($result->name == $index_name) {
$r = rand(0, 50);
$index_name = $index_name . "_$r";
break;
}
}
}
$index_name = str_replace(' ', '', $index_name);
$this->index_queries[] = "CREATE UNIQUE INDEX $index_name ON " . $tbl_name .$col_name;
return '';
@ -296,24 +296,24 @@ class CreateQuery{
* @access private
*/
private function _rewrite_key($matches){
$index_name = trim($matches[2]);
$col_name = trim($matches[3]);
if (preg_match('/\([0-9]+?\)/', $col_name, $match)) {
$col_name = preg_replace_callback('/\([0-9]+?\)/', array($this, '_remove_length'), $col_name);
}
$tbl_name = $this->table_name;
$_wpdb = new PDODB();
$results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'");
$_wpdb = null;
if ($results) {
foreach ($results as $result) {
if ($result->name == $index_name) {
$r = rand(0, 50);
$index_name = $index_name . "_$r";
break;
}
}
}
$index_name = trim($matches[2]);
$col_name = trim($matches[3]);
if (preg_match('/\([0-9]+?\)/', $col_name, $match)) {
$col_name = preg_replace_callback('/\([0-9]+?\)/', array($this, '_remove_length'), $col_name);
}
$tbl_name = $this->table_name;
$_wpdb = new PDODB();
$results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'");
$_wpdb = null;
if ($results) {
foreach ($results as $result) {
if ($result->name == $index_name) {
$r = rand(0, 50);
$index_name = $index_name . "_$r";
break;
}
}
}
$this->index_queries[] = 'CREATE INDEX '. $index_name . ' ON ' . $tbl_name . $col_name ;
return '';
}
@ -327,7 +327,7 @@ class CreateQuery{
* @access private
*/
private function _remove_length($match) {
return '';
return '';
}
/**
* Method to assemble the main query and index queries into an array.
@ -337,19 +337,19 @@ class CreateQuery{
* @return array
* @access private
*/
private function post_process(){
private function post_process() {
$mainquery = $this->_query;
do{
$count = 0;
$mainquery = preg_replace('/,\\s*\)/imsx',')', $mainquery, -1, $count);
} while ($count > 0);
do {
$count = 0;
$mainquery = preg_replace('/\(\\s*?,/imsx', '(', $mainquery, -1, $count);
$count = 0;
$mainquery = preg_replace('/\(\\s*?,/imsx', '(', $mainquery, -1, $count);
} while ($count > 0);
$return_val[] = $mainquery;
$return_val = array_merge($return_val, $this->index_queries);
return $return_val;
return $return_val;
}
/**
* Method to add IF NOT EXISTS to query string.
@ -364,7 +364,7 @@ class CreateQuery{
$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';
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]);
}
}
/**
@ -374,9 +374,9 @@ class CreateQuery{
*/
private function strip_backticks(){
$this->_query = str_replace('`', '', $this->_query);
foreach ($this->index_queries as &$query) {
$query = str_replace('`', '', $query);
}
foreach ($this->index_queries as &$query) {
$query = str_replace('`', '', $query);
}
}
/**
* Method to remove the character set information from within mysql queries.
@ -389,8 +389,8 @@ class CreateQuery{
private function rewrite_character_set(){
$pattern_charset = '/\\b(default\\s*character\\s*set|default\\s*charset|character\\s*set)\\s*(?<!\()[^ ]*/im';
$pattern_collate1 = '/\\s*collate\\s*[^ ]*(?=,)/im';
$pattern_collate2 = '/\\s*collate\\s*[^ ]*(?<!;)/im';
$patterns = array($pattern_charset, $pattern_collate1, $pattern_collate2);
$pattern_collate2 = '/\\s*collate\\s*[^ ]*(?<!;)/im';
$patterns = array($pattern_charset, $pattern_collate1, $pattern_collate2);
$this->_query = preg_replace($patterns, '', $this->_query);
}
}

View File

@ -18,75 +18,75 @@ if (!defined('ABSPATH')) {
* @return boolean
*/
function make_db_sqlite() {
include_once PDODIR . 'query_create.class.php';
include_once ABSPATH . 'wp-admin/includes/schema.php';
$index_array = array();
include_once PDODIR . 'query_create.class.php';
include_once ABSPATH . 'wp-admin/includes/schema.php';
$index_array = array();
// ob_end_clean();
$table_schemas = wp_get_db_schema();
//ob_end_clean();
$table_schemas = wp_get_db_schema();
$queries = explode (";", $table_schemas);
$query_parser = new CreateQuery();
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) {
$err_data = $err->errorInfo;
$message = 'Database connection error!<br />';
$message .= sprintf("Error message is: %s", $err_data[2]);
wp_die($message, 'Database Error!');
$err_data = $err->errorInfo;
$message = 'Database connection error!<br />';
$message .= sprintf("Error message is: %s", $err_data[2]);
wp_die($message, 'Database Error!');
}
try {
$pdo->beginTransaction();
foreach ($queries as $query) {
$query = trim($query);
if (empty($query))
continue;
$rewritten_query = $query_parser->rewrite_query($query);
if (is_array($rewritten_query)) {
$table_query = array_shift($rewritten_query);
$index_queries = $rewritten_query;
$table_query = trim($table_query);
$pdo->exec($table_query);
// foreach($rewritten_query as $single_query) {
// $single_query = trim($single_query);
// $pdo->exec($single_query);
// }
} else {
$rewritten_query = trim($rewritten_query);
$pdo->exec($rewritten_query);
}
}
$pdo->commit();
if ($index_queries) {
// $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';
$pdo->beginTransaction();
foreach ($index_queries as $index_query) {
preg_match($pattern, $index_query, $match);
$index_name = trim($match[2]);
if (in_array($index_name, $index_array)) {
$r = rand(0, 50);
$replacement = $index_name . "_$r";
$index_query = str_ireplace('EXISTS '.$index_name, 'EXISTS '.$replacement, $index_query);
} else {
$index_array[] = $index_name;
}
$pdo->exec($index_query);
}
$pdo->commit();
}
$pdo->beginTransaction();
foreach ($queries as $query) {
$query = trim($query);
if (empty($query))
continue;
$rewritten_query = $query_parser->rewrite_query($query);
if (is_array($rewritten_query)) {
$table_query = array_shift($rewritten_query);
$index_queries = $rewritten_query;
$table_query = trim($table_query);
$pdo->exec($table_query);
//foreach($rewritten_query as $single_query) {
// $single_query = trim($single_query);
// $pdo->exec($single_query);
//}
} else {
$rewritten_query = trim($rewritten_query);
$pdo->exec($rewritten_query);
}
}
$pdo->commit();
if ($index_queries) {
// $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';
$pdo->beginTransaction();
foreach ($index_queries as $index_query) {
preg_match($pattern, $index_query, $match);
$index_name = trim($match[2]);
if (in_array($index_name, $index_array)) {
$r = rand(0, 50);
$replacement = $index_name . "_$r";
$index_query = str_ireplace('EXISTS '.$index_name, 'EXISTS '.$replacement, $index_query);
} else {
$index_array[] = $index_name;
}
$pdo->exec($index_query);
}
$pdo->commit();
}
} catch (PDOException $err) {
$err_data = $err->errorInfo;
$err_code = $err_data[1];
if (5 == $err_code || 6 == $err_code) {
// if the database is locked, commit again
$pdo->commit();
} else {
$pdo->rollBack();
$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]);
wp_die($message, 'Database Error!');
}
$err_data = $err->errorInfo;
$err_code = $err_data[1];
if (5 == $err_code || 6 == $err_code) {
// if the database is locked, commit again
$pdo->commit();
} else {
$pdo->rollBack();
$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]);
wp_die($message, 'Database Error!');
}
}
$query_parser = null;

View File

@ -57,13 +57,13 @@ if (defined('WP_PLUGIN_URL')) {
* Defines patch file upload directory.
*/
if (defined('UPLOADS')) {
define('SQLitePatchDir', UPLOADS . '/patches');
define('SQLitePatchDir', UPLOADS . '/patches');
} else {
if (defined('WP_CONTENT_DIR')) {
define('SQLitePatchDir', WP_CONTENT_DIR . '/uploads/patches');
} else {
define('SQLitePatchDir', ABSPATH . 'wp-content/uploads/patches');
}
if (defined('WP_CONTENT_DIR')) {
define('SQLitePatchDir', WP_CONTENT_DIR . '/uploads/patches');
} else {
define('SQLitePatchDir', ABSPATH . 'wp-content/uploads/patches');
}
}
/*
* Plugin compatibility file in json format.
@ -73,16 +73,16 @@ define('SQLiteListFile', SQLiteFilePath . '/utilities/plugin_lists.json');
* Instantiates utility classes.
*/
if (!class_exists('SQLiteIntegrationUtils')) {
require_once SQLiteFilePath . '/utilities/utility.php';
$utils = new SQLiteIntegrationUtils();
require_once SQLiteFilePath . '/utilities/utility.php';
$utils = new SQLiteIntegrationUtils();
}
if (!class_exists('SQLiteIntegrationDocument')) {
require_once SQLiteFilePath . '/utilities/documentation.php';
$doc = new SQLiteIntegrationDocument();
require_once SQLiteFilePath . '/utilities/documentation.php';
$doc = new SQLiteIntegrationDocument();
}
if (!class_exists('PatchUtils')) {
require_once SQLiteFilePath . '/utilities/patch.php';
$patch_utils = new PatchUtils();
require_once SQLiteFilePath . '/utilities/patch.php';
$patch_utils = new PatchUtils();
}
if (!class_exists('DatabaseMaintenance')) {
require_once SQLiteFilePath . '/utilities/database_maintenance.php';
@ -97,226 +97,227 @@ if (!class_exists('DatabaseMaintenance')) {
*
*/
class SQLiteIntegration {
/**
* Constructor.
*
* This constructor does everything needed for the administration panel.
*
* @param no parameter is provided.
*/
function __construct() {
if (function_exists('register_activation_hook')) {
register_activation_hook(__FILE__, array($this, 'install'));
}
if (function_exists('register_deactivation_hook')) {
}
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'));
add_action('network_admin_notices', array('SQLiteIntegrationUtils', 'show_admin_notice'));
} else {
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.
add_action('admin_init', array('SQLiteIntegrationUtils', 'download_backup_db'));
add_action('plugins_loaded', array($this, 'textdomain_init'));
}
/**
* Constructor.
*
* This constructor does everything needed for the administration panel.
*
* @param no parameter is provided.
*/
function __construct() {
if (function_exists('register_activation_hook')) {
register_activation_hook(__FILE__, array($this, 'install'));
}
if (function_exists('register_deactivation_hook')) {
;
}
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'));
add_action('network_admin_notices', array('SQLiteIntegrationUtils', 'show_admin_notice'));
} else {
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.
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.
*
* There really is nothing to install for now. It is for future use...
*
* @param no parameter is provided.
* @return returns null.
*/
function install() {
global $wpdb;
if (function_exists('is_multisite') && is_multisite()) {
$old_blog = $wpdb->blogid;
$blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach ($blog_ids as $blog_id) {
switch_to_blog($blog_id);
$this->_install();
}
switch_to_blog($old_blog);
return;
} else {
$this->_install();
return;
}
}
/**
* Method to install on multisite or single site.
*
* There really is nothing to install for now. It is for future use...
*
* @param no parameter is provided.
* @return returns null.
*/
function install() {
global $wpdb;
if (function_exists('is_multisite') && is_multisite()) {
$old_blog = $wpdb->blogid;
$blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach ($blog_ids as $blog_id) {
switch_to_blog($blog_id);
$this->_install();
}
switch_to_blog($old_blog);
return;
} else {
$this->_install();
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 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 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 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 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 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');
}
}
/**
* 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 */

View File

@ -32,134 +32,134 @@ class DatabaseMaintenance {
$results_table = array();
$columns_to_check = array(
$wpdb->prefix.'commentmeta' => array(
'comment_id' => '\'0\'',
'meta_key' => 'NULL'
'comment_id' => '\'0\'',
'meta_key' => 'NULL'
),
$wpdb->prefix.'comments' => array(
'comment_post_ID' => '\'0\'',
'comment_author_email' => '\'\'',
'comment_author_url' => '\'\'',
'comment_author_IP' => '\'\'',
'comment_date_gmt' => '\'0000-00-00 00:00:00\'',
'comment_date' => '\'0000-00-00 00:00:00\'',
'comment_karma' => '\'0\'',
'comment_approved' => '\'1\'',
'comment_agent' => '\'\'',
'comment_type' => '\'\'',
'comment_parent' => '\'0\'',
'user_id' => '\'0\''
'comment_post_ID' => '\'0\'',
'comment_author_email' => '\'\'',
'comment_author_url' => '\'\'',
'comment_author_IP' => '\'\'',
'comment_date_gmt' => '\'0000-00-00 00:00:00\'',
'comment_date' => '\'0000-00-00 00:00:00\'',
'comment_karma' => '\'0\'',
'comment_approved' => '\'1\'',
'comment_agent' => '\'\'',
'comment_type' => '\'\'',
'comment_parent' => '\'0\'',
'user_id' => '\'0\''
),
$wpdb->prefix.'links' => array(
'link_url' => '\'\'',
'link_name' => '\'\'',
'link_image' => '\'\'',
'link_target' => '\'\'',
'link_description' => '\'\'',
'link_visible' => '\'Y\'',
'link_owner' => '\'1\'',
'link_rating' => '\'0\'',
'link_updated' => '\'0000-00-00 00:00:00\'',
'link_rel' => '\'\'',
'link_rss' => '\'\''
'link_url' => '\'\'',
'link_name' => '\'\'',
'link_image' => '\'\'',
'link_target' => '\'\'',
'link_description' => '\'\'',
'link_visible' => '\'Y\'',
'link_owner' => '\'1\'',
'link_rating' => '\'0\'',
'link_updated' => '\'0000-00-00 00:00:00\'',
'link_rel' => '\'\'',
'link_rss' => '\'\''
),
$wpdb->prefix.'options' => array(
'option_name' => '\'\'',
'autoload' => '\'yes\''
'option_name' => '\'\'',
'autoload' => '\'yes\''
),
$wpdb->prefix.'postmeta' => array(
'post_id' => '\'0\'',
'meta_key' => 'NULL'
'post_id' => '\'0\'',
'meta_key' => 'NULL'
),
$wpdb->prefix.'posts' => array(
'post_author' => '\'0\'',
'post_date_gmt' => '\'0000-00-00 00:00:00\'',
'post_date' => '\'0000-00-00 00:00:00\'',
'post_status' => '\'publish\'',
'comment_status' => '\'open\'',
'ping_status' => '\'open\'',
'post_password' => '\'\'',
'post_name' => '\'\'',
'post_modified_gmt' => '\'0000-00-00 00:00:00\'',
'post_modified' => '\'0000-00-00 00:00:00\'',
'post_parent' => '\'0\'',
'guid' => '\'\'',
'menu_order' => '\'0\'',
'post_type' => '\'post\'',
'post_mime_type' => '\'\'',
'comment_count' => '\'0\''
'post_author' => '\'0\'',
'post_date_gmt' => '\'0000-00-00 00:00:00\'',
'post_date' => '\'0000-00-00 00:00:00\'',
'post_status' => '\'publish\'',
'comment_status' => '\'open\'',
'ping_status' => '\'open\'',
'post_password' => '\'\'',
'post_name' => '\'\'',
'post_modified_gmt' => '\'0000-00-00 00:00:00\'',
'post_modified' => '\'0000-00-00 00:00:00\'',
'post_parent' => '\'0\'',
'guid' => '\'\'',
'menu_order' => '\'0\'',
'post_type' => '\'post\'',
'post_mime_type' => '\'\'',
'comment_count' => '\'0\''
),
$wpdb->prefix.'term_relationships' => array(
'term_order' => '0'
'term_order' => '0'
),
$wpdb->prefix.'term_taxonomy' => array(
'taxonomy' => '\'\'',
'parent' => '0',
'count' => '0'
'taxonomy' => '\'\'',
'parent' => '0',
'count' => '0'
),
$wpdb->prefix.'terms' => array(
'name' => '\'\'',
'slug' => '\'\'',
'term_group' => '0'
'name' => '\'\'',
'slug' => '\'\'',
'term_group' => '0'
),
$wpdb->prefix.'users' => array(
'user_login' => '\'\'',
'user_pass' => '\'\'',
'user_nicename' => '\'\'',
'user_email' => '\'\'',
'user_url' => '\'\'',
'user_registered' => '\'0000-00-00 00:00:00\'',
'user_activation_key' => '\'\'',
'user_status' => '\'0\'',
'display_name' => '\'\'',
// for network install
'spam' => '\'0\'',
'deleted' => '\'0\''
'user_login' => '\'\'',
'user_pass' => '\'\'',
'user_nicename' => '\'\'',
'user_email' => '\'\'',
'user_url' => '\'\'',
'user_registered' => '\'0000-00-00 00:00:00\'',
'user_activation_key' => '\'\'',
'user_status' => '\'0\'',
'display_name' => '\'\'',
// for network install
'spam' => '\'0\'',
'deleted' => '\'0\''
),
$wpdb->prefix.'usermeta' => array(
'user_id' => '\'0\'',
'meta_key' => 'NULL',
'user_id' => '\'0\'',
'meta_key' => 'NULL',
),
// for network install
$wpdb->prefix.'blog_versions' => array(
'blog_id' => '\'0\'',
'db_version' => '\'\'',
'last_updated' => '\'0000-00-00 00:00:00\''
'blog_id' => '\'0\'',
'db_version' => '\'\'',
'last_updated' => '\'0000-00-00 00:00:00\''
),
$wpdb->prefix.'blogs' => array(
'site_id' => '\'0\'',
'domain' => '\'\'',
'path' => '\'\'',
'registered' => '\'0000-00-00 00:00:00\'',
'last_updated' => '\'0000-00-00 00:00:00\'',
'public' => '\'1\'',
'mature' => '\'0\'',
'spam' => '\'0\'',
'deleted' => '\'0\'',
'lang_id' => '\'0\''
'site_id' => '\'0\'',
'domain' => '\'\'',
'path' => '\'\'',
'registered' => '\'0000-00-00 00:00:00\'',
'last_updated' => '\'0000-00-00 00:00:00\'',
'public' => '\'1\'',
'mature' => '\'0\'',
'spam' => '\'0\'',
'deleted' => '\'0\'',
'lang_id' => '\'0\''
),
$wpdb->prefix.'registration_log' => array(
'email' => '\'\'',
'IP' => '\'\'',
'blog_id' => '\'0\'',
'date_registered' => '\'0000-00-00 00:00:00\''
'email' => '\'\'',
'IP' => '\'\'',
'blog_id' => '\'0\'',
'date_registered' => '\'0000-00-00 00:00:00\''
),
$wpdb->prefix.'signups' => array(
'domain' => '\'\'',
'path' => '\'\'',
'user_login' => '\'\'',
'user_email' => '\'\'',
'registered' => '\'0000-00-00 00:00:00\'',
'activated' => '\'0000-00-00 00:00:00\'',
'active' => '\'0\'',
'activation_key' => '\'\'',
'domain' => '\'\'',
'path' => '\'\'',
'user_login' => '\'\'',
'user_email' => '\'\'',
'registered' => '\'0000-00-00 00:00:00\'',
'activated' => '\'0000-00-00 00:00:00\'',
'active' => '\'0\'',
'activation_key' => '\'\'',
),
$wpdb->prefix.'site' => array(
'domain' => '\'\'',
'path' => '\'\''
'domain' => '\'\'',
'path' => '\'\''
),
$wpdb->prefix.'sitemeta' => array(
'site_id' => '\'0\'',
'meta_key' => 'NULL',
'site_id' => '\'0\'',
'meta_key' => 'NULL',
)
);
$tables = $wpdb->tables('all');
@ -191,148 +191,148 @@ class DatabaseMaintenance {
global $wpdb, $wp_version, $utils;
$global_schema_to_change = array(
$wpdb->prefix.'commentmeta' => array(
"comment_id bigint(20) unsigned NOT NULL default '0'",
"meta_key varchar(255) default NULL",
"meta_value longtext"
"comment_id bigint(20) unsigned NOT NULL default '0'",
"meta_key varchar(255) default NULL",
"meta_value longtext"
),
$wpdb->prefix.'comments' => array(
"comment_post_ID bigint(20) unsigned NOT NULL default '0'",
"comment_author_email varchar(100) NOT NULL default ''",
"comment_author_url varchar(200) 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_gmt datetime NOT NULL default '0000-00-00 00:00:00'",
"comment_karma int(11) NOT NULL default '0'",
"comment_approved varchar(20) NOT NULL default '1'",
"comment_agent varchar(255) NOT NULL default ''",
"comment_type varchar(20) NOT NULL default ''",
"comment_parent bigint(20) unsigned NOT NULL default '0'",
"user_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_url varchar(200) 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_gmt datetime NOT NULL default '0000-00-00 00:00:00'",
"comment_karma int(11) NOT NULL default '0'",
"comment_approved varchar(20) NOT NULL default '1'",
"comment_agent varchar(255) NOT NULL default ''",
"comment_type varchar(20) NOT NULL default ''",
"comment_parent bigint(20) unsigned NOT NULL default '0'",
"user_id bigint(20) unsigned NOT NULL default '0'"
),
$wpdb->prefix.'links' => array(
"link_url varchar(255) NOT NULL default ''",
"link_name varchar(255) NOT NULL default ''",
"link_image varchar(255) NOT NULL default ''",
"link_target varchar(25) NOT NULL default ''",
"link_description varchar(255) NOT NULL default ''",
"link_visible varchar(20) NOT NULL default 'Y'",
"link_owner bigint(20) unsigned NOT NULL default '1'",
"link_rating int(11) NOT NULL default '0'",
"link_updated datetime NOT NULL default '0000-00-00 00:00:00'",
"link_rel varchar(255) NOT NULL default ''",
"link_notes mediumtext NOT NULL",
"link_rss varchar(255) NOT NULL default ''"
"link_url varchar(255) NOT NULL default ''",
"link_name varchar(255) NOT NULL default ''",
"link_image varchar(255) NOT NULL default ''",
"link_target varchar(25) NOT NULL default ''",
"link_description varchar(255) NOT NULL default ''",
"link_visible varchar(20) NOT NULL default 'Y'",
"link_owner bigint(20) unsigned NOT NULL default '1'",
"link_rating int(11) NOT NULL default '0'",
"link_updated datetime NOT NULL default '0000-00-00 00:00:00'",
"link_rel varchar(255) NOT NULL default ''",
"link_notes mediumtext NOT NULL",
"link_rss varchar(255) NOT NULL default ''"
),
$wpdb->prefix.'options' => array(
"option_name varchar(64) NOT NULL default ''",
"option_value longtext NOT NULL",
"autoload varchar(20) NOT NULL default 'yes'"
"option_name varchar(64) NOT NULL default ''",
"option_value longtext NOT NULL",
"autoload varchar(20) NOT NULL default 'yes'"
),
$wpdb->prefix.'postmeta' => array(
"post_id bigint(20) unsigned NOT NULL default '0'",
"meta_key varchar(255) default NULL",
"meta_value longtext"
"post_id bigint(20) unsigned NOT NULL default '0'",
"meta_key varchar(255) default NULL",
"meta_value longtext"
),
$wpdb->prefix.'posts' => array(
"post_author bigint(20) unsigned NOT NULL default '0'",
"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_status varchar(20) NOT NULL default 'publish'",
"comment_status varchar(20) NOT NULL default 'open'",
"ping_status varchar(20) NOT NULL default 'open'",
"post_password varchar(20) NOT NULL default ''",
"post_name varchar(200) NOT NULL default ''",
"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_content_filtered longtext NOT NULL",
"post_parent bigint(20) unsigned NOT NULL default '0'",
"guid varchar(255) NOT NULL default ''",
"menu_order int(11) NOT NULL default '0'",
"post_type varchar(20) NOT NULL default 'post'",
"post_mime_type varchar(100) NOT NULL default ''",
"comment_count bigint(20) 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_gmt datetime NOT NULL default '0000-00-00 00:00:00'",
"post_status varchar(20) NOT NULL default 'publish'",
"comment_status varchar(20) NOT NULL default 'open'",
"ping_status varchar(20) NOT NULL default 'open'",
"post_password varchar(20) NOT NULL default ''",
"post_name varchar(200) NOT NULL default ''",
"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_content_filtered longtext NOT NULL",
"post_parent bigint(20) unsigned NOT NULL default '0'",
"guid varchar(255) NOT NULL default ''",
"menu_order int(11) NOT NULL default '0'",
"post_type varchar(20) NOT NULL default 'post'",
"post_mime_type varchar(100) NOT NULL default ''",
"comment_count bigint(20) NOT NULL default '0'"
),
$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(
"taxonomy varchar(32) NOT NULL default ''",
"description longtext NOT NULL",
"parent bigint(20) unsigned NOT NULL default 0",
"count bigint(20) NOT NULL default 0"
"taxonomy varchar(32) NOT NULL default ''",
"description longtext NOT NULL",
"parent bigint(20) unsigned NOT NULL default 0",
"count bigint(20) NOT NULL default 0"
),
$wpdb->prefix.'terms' => array(
"name varchar(200) NOT NULL default ''",
"slug varchar(200) NOT NULL default ''",
"term_group bigint(10) NOT NULL default 0"
"name varchar(200) NOT NULL default ''",
"slug varchar(200) NOT NULL default ''",
"term_group bigint(10) NOT NULL default 0"
),
$wpdb->prefix.'users' => array(
"user_login varchar(60) NOT NULL default ''",
"user_pass varchar(64) NOT NULL default ''",
"user_nicename varchar(50) NOT NULL default ''",
"user_email 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_activation_key varchar(60) NOT NULL default ''",
"user_status int(11) NOT NULL default '0'",
"display_name varchar(250) NOT NULL default ''"
"user_login varchar(60) NOT NULL default ''",
"user_pass varchar(64) NOT NULL default ''",
"user_nicename varchar(50) NOT NULL default ''",
"user_email 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_activation_key varchar(60) NOT NULL default ''",
"user_status int(11) NOT NULL default '0'",
"display_name varchar(250) NOT NULL default ''"
),
$wpdb->prefix.'usermeta' => array(
"user_id bigint(20) unsigned NOT NULL default '0'",
"meta_key varchar(255) default NULL",
"meta_value longtext"
"user_id bigint(20) unsigned NOT NULL default '0'",
"meta_key varchar(255) default NULL",
"meta_value longtext"
)
);
$network_schema_to_change = array(
$wpdb->prefix.'blog_versions' => array(
"blog_id bigint(20) NOT NULL default '0'",
"db_version varchar(20) NOT NULL default ''",
"last_updated datetime NOT NULL default '0000-00-00 00:00:00'"
"blog_id bigint(20) NOT NULL default '0'",
"db_version varchar(20) NOT NULL default ''",
"last_updated datetime NOT NULL default '0000-00-00 00:00:00'"
),
$wpdb->prefix.'blogs' => array(
"site_id bigint(20) NOT NULL default '0'",
"domain varchar(200) NOT NULL default ''",
"path varchar(100) NOT NULL default ''",
"registered 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'",
"mature tinyint(2) NOT NULL default '0'",
"spam tinyint(2) NOT NULL default '0'",
"deleted tinyint(2) NOT NULL default '0'",
"lang_id int(11) NOT NULL default '0'"
"site_id bigint(20) NOT NULL default '0'",
"domain varchar(200) NOT NULL default ''",
"path varchar(100) NOT NULL default ''",
"registered 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'",
"mature tinyint(2) NOT NULL default '0'",
"spam tinyint(2) NOT NULL default '0'",
"deleted tinyint(2) NOT NULL default '0'",
"lang_id int(11) NOT NULL default '0'"
),
$wpdb->prefix.'registration_log' => array(
"email varchar(255) NOT NULL default ''",
"IP varchar(30) NOT NULL default ''",
"blog_id bigint(20) NOT NULL default '0'",
"date_registered datetime NOT NULL default '0000-00-00 00:00:00'"
"email varchar(255) NOT NULL default ''",
"IP varchar(30) NOT NULL default ''",
"blog_id bigint(20) NOT NULL default '0'",
"date_registered datetime NOT NULL default '0000-00-00 00:00:00'"
),
$wpdb->prefix.'signups' => array(
"domain varchar(200) NOT NULL default ''",
"path varchar(100) NOT NULL default ''",
"title longtext NOT NULL",
"user_login varchar(60) NOT NULL default ''",
"user_email varchar(100) NOT NULL default ''",
"registered 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'",
"activation_key varchar(50) NOT NULL default ''",
"meta longtext"
"domain varchar(200) NOT NULL default ''",
"path varchar(100) NOT NULL default ''",
"title longtext NOT NULL",
"user_login varchar(60) NOT NULL default ''",
"user_email varchar(100) NOT NULL default ''",
"registered 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'",
"activation_key varchar(50) NOT NULL default ''",
"meta longtext"
),
$wpdb->prefix.'site' => array(
"domain varchar(200) NOT NULL default ''",
"path varchar(100) NOT NULL default ''"
"domain varchar(200) NOT NULL default ''",
"path varchar(100) NOT NULL default ''"
),
$wpdb->prefix.'sitemeta' => array(
"site_id bigint(20) NOT NULL default '0'",
"meta_key varchar(255) default NULL",
"meta_value longtext"
"site_id bigint(20) NOT NULL default '0'",
"meta_key varchar(255) default NULL",
"meta_value longtext"
),
$wpdb->prefix.'users' => array(
"user_login varchar(60) NOT NULL default ''",
"spam tinyint(2) NOT NULL default '0'",
"deleted tinyint(2) NOT NULL default '0'"
"user_login varchar(60) NOT NULL default ''",
"spam tinyint(2) NOT NULL default '0'",
"deleted tinyint(2) NOT NULL default '0'"
)
);
if (version_compare($wp_version, '3.6', '<')) return false;
@ -447,133 +447,133 @@ class DatabaseMaintenance {
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to access this page!', $domain));
}
if (isset($_GET['page']) && $_GET['page'] == 'maintenance') : ?>
<div class="navigation">
<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=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=patch"><?php _e('Patch Utility', $domain);?></a></li>
<li class="menu-selected"><?php _e('Maintenance', $domain);?></li>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Database Maintenace', $domain);?></h2>
<h3><?php _e('Important Notice', $domain);?></h3>
<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>
<?php _e('This page provide you the database sanity check utility and the restore utility.', $domain);?>
</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);?>
</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);?>
</p>
<p>
<?php _e('If you installed WordPress 3.6 (not upgraded), you don\'t have to restore the database.', $domain);?>
</p>
if (isset($_GET['page']) && $_GET['page'] == 'maintenance') : ?>
<div class="navigation">
<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=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=patch"><?php _e('Patch Utility', $domain);?></a></li>
<li class="menu-selected"><?php _e('Maintenance', $domain);?></li>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Database Maintenace', $domain);?></h2>
<h3><?php _e('Important Notice', $domain);?></h3>
<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>
<?php _e('This page provide you the database sanity check utility and the restore utility.', $domain);?>
</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);?>
</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);?>
</p>
<p>
<?php _e('If you installed WordPress 3.6 (not upgraded), you don\'t have to restore the database.', $domain);?>
</p>
<form action="" method="post">
<?php
if (function_exists('wp_nonce_field')) {
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="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 action="" method="post">
<?php
if (function_exists('wp_nonce_field')) {
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="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>
<?php if (defined('WP_DEBUG') && WP_DEBUG == true) : ?>
<h3><?php _e('Columns Information', $domain);?></h3>
<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);?>
</p>
<?php if (defined('WP_DEBUG') && WP_DEBUG == true) : ?>
<h3><?php _e('Columns Information', $domain);?></h3>
<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);?>
</p>
<?php
$wp_tables = $wpdb->tables('all');
?>
<form action="" method="post">
<?php
if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqliteintegration-database-manip-stats');
}
?>
<label for="table"/><?php _e('Table Name: ', $domain);?></label>
<select name="table" id="table">
<?php foreach ($wp_tables as $table) :?>
<option value="<?php echo $table;?>"><?php echo $table;?></option>
<?php endforeach;?>
</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);?>')" />
</form>
<?php endif; ?>
<form action="" method="post">
<?php
if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqliteintegration-database-manip-stats');
}
?>
<label for="table"/><?php _e('Table Name: ', $domain);?></label>
<select name="table" id="table">
<?php foreach ($wp_tables as $table) :?>
<option value="<?php echo $table;?>"><?php echo $table;?></option>
<?php endforeach;?>
</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);?>')" />
</form>
<?php endif; ?>
</div>
<?php endif;
</div>
<?php endif;
if (isset($_POST['do-fix-database'])) {
check_admin_referer('sqliteintegration-database-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$fix_results = $this->do_fix_database();
if (is_array($fix_results)) {
if (isset($_POST['do-fix-database'])) {
check_admin_referer('sqliteintegration-database-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$fix_results = $this->do_fix_database();
if (is_array($fix_results)) {
$title = '<h3>'. __('Results', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title;
echo '<ul>';
foreach ($fix_results as $result) {
echo '<li>' . $result . '</li>';
}
echo '</ul>';
echo '</div>';
} else {
foreach ($fix_results as $result) {
echo '<li>' . $result . '</li>';
}
echo '</ul>';
echo '</div>';
} else {
$title = '<h3>'. __('Results', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title;
echo '<p>'.$fix_results.'</p>';
echo '</div>';
}
}
if (isset($_POST['sanity-check'])) {
check_admin_referer('sqliteintegration-database-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$check_results = $this->sanity_check();
if ($check_results !== true) {
}
if (isset($_POST['sanity-check'])) {
check_admin_referer('sqliteintegration-database-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$check_results = $this->sanity_check();
if ($check_results !== true) {
$title = '<h3>'. __('Checked Results', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title;
echo '<ul>';
foreach ($check_results as $table => $damaged) {
$message = __(' needs restoring.', $domain);
echo '<li><span class="em">' . $table . '</span>' . $message . '</li>';
}
echo '</ul>';
echo '</div>';
} else {
foreach ($check_results as $table => $damaged) {
$message = __(' needs restoring.', $domain);
echo '<li><span class="em">' . $table . '</span>' . $message . '</li>';
}
echo '</ul>';
echo '</div>';
} else {
$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 $title;
echo $title;
echo '<p>'.$message.'</p>';
echo '</div>';
}
}
if (isset($_POST['show-columns'])) {
echo '</div>';
}
}
if (isset($_POST['show-columns'])) {
check_admin_referer('sqliteintegration-database-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$results = $this->show_columns();
if (is_array($results)) {
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$results = $this->show_columns();
if (is_array($results)) {
$title = '<h3>'. sprintf(__('Columns In %s', $domain), $_POST['table']) . '</h3>';
$column_header = __('Column', $domain);
$type_header = __('Type', $domain);

View File

@ -15,137 +15,137 @@ class SQLiteIntegrationDocument {
* Method to display the document page.
*
*/
function show_doc() {
// textdomain is defined in the utils class
global $utils;
$domain = $utils->text_domain;
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to access this page!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to access this page!', $domain));
}
if (isset($_GET['page']) && $_GET['page'] == 'doc') :?>
<div class="navigation">
<ul class="navi-menu">
<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=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=maintenance"><?php _e('Maintenance', $domain);?></a></li>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Documentation', $domain); ?></h2>
<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);?>
</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);?>
</p>
function show_doc() {
// textdomain is defined in the utils class
global $utils;
$domain = $utils->text_domain;
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to access this page!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to access this page!', $domain));
}
if (isset($_GET['page']) && $_GET['page'] == 'doc') :?>
<div class="navigation">
<ul class="navi-menu">
<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=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=maintenance"><?php _e('Maintenance', $domain);?></a></li>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Documentation', $domain); ?></h2>
<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);?>
</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);?>
</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('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('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('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>
<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;
}
<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

@ -10,412 +10,412 @@
*
*/
class PatchUtils {
/**
* 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.
* If directory contains none, returns empty array.
*
* @return array
* @access private
*/
private function get_patch_files() {
$patch_files = array();
if (!is_dir(SQLitePatchDir)) {
return $patch_files;
} else {
if ($dir_handle = opendir(SQLitePatchDir)) {
while (($file_name = readdir($dir_handle)) !== false) {
if ($file_name == '.' || $file_name == '..' || $file_name == '.htaccess')
continue;
$patch_files[] = $file_name;
}
}
return $patch_files;
}
}
/**
* Method to apply patch to the plugins.
*
* It executes patch command and apply it to the target plugins.
* If patch file(s) is not selected, returns false.
* Or else returns array contains messages.
*
* @return boolean|array
* @access private
*/
private function apply_patches() {
global $utils;
$domain = $utils->text_domain;
$installed_plugins = array();
$file_names = array();
$output = array();
$retval = 0;
$patch_results = array();
$message = '';
if (isset($_POST['plugin_checked'])) {
$file_names = $_POST['plugin_checked'];
} else {
return false;
}
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
exec('where patch 2>&1', $out, $val);
} else {
exec('which patch 2>&1', $out, $val);
}
if ($val != 0) {
$patch_results['error'] = __('Patch command is not found', $domain);
return $patch_results;
} elseif (!is_executable(trim($out[0]))) {
$patch_results['error'] = __('Patch command is not executable', $domain);
return $patch_results;
} else {
$patch_command = trim($out[0]) . ' -s -N -p1';
}
$installed_plugins = get_plugins();
foreach ($file_names as $file) {
if (preg_match('/_(.*)\.patch/i', $file, $match)) {
$plugin_version = trim($match[1]);
$plugin_basename = preg_replace('/_.*\.patch$/i', '', $file);
foreach (array_keys($installed_plugins) as $key) {
if (stripos($key, $plugin_basename) !== false) {
$installed_plugin_version = $installed_plugins[$key]['Version'];
break;
}
}
} else {
$patch_results['error'] = __('Patch file name is invalid', $domain);
break;
}
if (version_compare($installed_plugin_version, $plugin_version, '!=')) {
$patch_results['error'] = __('Patch file version does not match with that of your plugin.', $domain);
break;
}
$plugin_dir = WP_PLUGIN_DIR.'/'.$plugin_basename;
$patch_file = SQLitePatchDir.'/'.$file;
$command = $patch_command.' <'.$patch_file.' 2>&1';
if (chdir($plugin_dir)) {
exec("$command", $output, $retval);
} else {
$patch_results[$file] = __('Error! Plugin directory is not accessible.', $domain);
}
if ($retval == 0) {
$patch_results[$file] = __('is patched successfully.', $domain);
} else {
foreach ($output as $val) {
$message .= $val.'<br />';
}
$patch_results[$file] = sprintf(__('Error! Messages: %s', $domain), $message);
}
}
return $patch_results;
}
/**
* Method to remove patch file(s) from the server.
*
* It deletes uploaded patch file(s).
* If patch file(s) is not selected, returns false.
* Or else returns array contains messages.
*
* @return boolean|array
* @access private
*/
private function delete_patch_files() {
global $utils;
$domain = $utils->text_domain;
$file_names = array();
$rm_results = array();
if (isset($_POST['plugin_checked'])) {
$file_names = $_POST['plugin_checked'];
} else {
return false;
}
if (chdir(SQLitePatchDir)) {
foreach ($file_names as $file) {
if (unlink($file)) {
$rm_results[$file] = sprintf(__('File %s is deleted.', $domain), $file);
} else {
$rm_results[$file] = sprintf(__('Error! File %s is not deleted.', $domain), $file);
}
}
} else {
$rm_results[$file] = __('Error!: patches directory is not accessible.', $domain);
}
return $rm_results;
}
/**
* 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
* temporary directory. If there isn't SQLitePatchDir, this method will create it and
* set the permission to 0707.
*
* No return values.
*
* @return boolean
* @access private
*/
private function upload_file() {
global $utils;
$domain = $utils->text_domain;
if (!file_exists(SQLitePatchDir) || !is_dir(SQLitePatchDir)) {
if (!mkdir(SQLitePatchDir, 0707, true)) {
$message = __('Unable to create a patch directory.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
return false;
}
}
if (!is_file(SQLitePatchDir . '/.htaccess')) {
$fp = fopen(SQLitePatchDir . '/.htaccess', 'w');
if (!$fp) {
$message = __('Unable to create a .htaccess file.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
return false;
}
fwrite($fp, 'DENY FROM ALL');
fclose($fp);
}
if (!isset($_FILES['upfile']['error']) || !is_int($_FILES['upfile']['error'])) {
$message = __('Invalid operation.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
return false;
} elseif ($_FILES['upfile']['error'] != UPLOAD_ERR_OK) {
switch ($_FILES['upfile']['error']) {
case UPLOAD_ERR_FORM_SIZE:
$message = __('File is too large to upload.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
break;
case UPLOAD_ERR_PARTIAL:
$message = __('File upload is not complete.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
break;
case UPLOAD_ERR_NO_FILE:
$message = __('File is not uploaded.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$message = __('Temporary directory is not writable.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
break;
case UPLOAD_ERR_CANT_WRITE:
$message = __('File cannot be written on the disk.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
break;
default:
$message = __('Unknown error.', $domain);
break;
}
return false;
}
if (is_uploaded_file($_FILES['upfile']['tmp_name'])) {
$file_full_path = SQLitePatchDir . '/' . $_FILES['upfile']['name'];
if (move_uploaded_file($_FILES['upfile']['tmp_name'], $file_full_path)) {
$message = __('File is successfully uploaded.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
chmod(SQLitePatchDir.'/'.$_FILES['upfile']['name'], 0606);
} else {
$message = __('File upload failed. Possible file upload attack.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
return false;
}
} else {
$message = __('File is not selected', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
return false;
}
return true;
}
/**
* Method to display the patch utility page on the admin panel.
*
*/
function show_patch_page() {
global $utils;
$domain = $utils->text_domain;
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to access this page!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to access this page!', $domain));
}
if (isset($_POST['apply_patch'])) {
check_admin_referer('sqlitewordpress-plugin-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$result = $this->apply_patches();
if ($result === false) {
$message = __('Please select patch file(s)', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
} elseif (is_array($result) && count($result) > 0) {
echo '<div id="message" class="updated fade">';
foreach ($result as $key => $val) {
echo $key.' => '.$val.'<br />';
}
echo '</div>';
} else {
$message = __('None of the patches is applied!');
echo '<div id="message" class="updated fade">'.$message.'</div>';
}
}
if (isset($_POST['patch_file_delete'])) {
check_admin_referer('sqlitewordpress-plugin-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$result = $this->delete_patch_files();
if ($result === false) {
$message = __('Please select patch file(s)', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
} elseif (is_array($result) && count($result) > 0) {
echo '<div id="message" class="updated fade">';
foreach ($result as $key => $val) {
echo $key.' => '.$val.'<br />';
}
echo '</div>';
} else {
$message = __('Error! Please remove files manually', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
}
}
if (isset($_POST['upload'])) {
check_admin_referer('sqlitewordpress-plugin-patch-file-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$result = $this->upload_file();
}
if (isset($_GET['page']) && $_GET['page'] == 'patch') : ?>
<div class="navigation">
<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=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-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>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Patch Files Upload and Apply', $domain);?></h2>
<h3><?php _e('What you can do in this page', $domain);?></h3>
<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);?>
</p>
<p>
<?php _e('In this page, you can upload patch files and apply them automatically. But there are some requirements.', $domain)?>
</p>
<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('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 script can execute &quot;patch&quot; shell command.(Script will check if it is executable or not.)', $domain);?></li>
</ol>
<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)?>
</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);?>
</p>
<ol>
<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 suffix .patch.', $domain);?></li>
<li><?php _e('Use diff command options &quot;-Naur&quot;.', $domain);?></li>
</ol>
<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);?>
</p>
/**
* 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.
* If directory contains none, returns empty array.
*
* @return array
* @access private
*/
private function get_patch_files() {
$patch_files = array();
if (!is_dir(SQLitePatchDir)) {
return $patch_files;
} else {
if ($dir_handle = opendir(SQLitePatchDir)) {
while (($file_name = readdir($dir_handle)) !== false) {
if ($file_name == '.' || $file_name == '..' || $file_name == '.htaccess')
continue;
$patch_files[] = $file_name;
}
}
return $patch_files;
}
}
/**
* Method to apply patch to the plugins.
*
* It executes patch command and apply it to the target plugins.
* If patch file(s) is not selected, returns false.
* Or else returns array contains messages.
*
* @return boolean|array
* @access private
*/
private function apply_patches() {
global $utils;
$domain = $utils->text_domain;
$installed_plugins = array();
$file_names = array();
$output = array();
$retval = 0;
$patch_results = array();
$message = '';
if (isset($_POST['plugin_checked'])) {
$file_names = $_POST['plugin_checked'];
} else {
return false;
}
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
exec('where patch 2>&1', $out, $val);
} else {
exec('which patch 2>&1', $out, $val);
}
if ($val != 0) {
$patch_results['error'] = __('Patch command is not found', $domain);
return $patch_results;
} elseif (!is_executable(trim($out[0]))) {
$patch_results['error'] = __('Patch command is not executable', $domain);
return $patch_results;
} else {
$patch_command = trim($out[0]) . ' -s -N -p1';
}
$installed_plugins = get_plugins();
foreach ($file_names as $file) {
if (preg_match('/_(.*)\.patch/i', $file, $match)) {
$plugin_version = trim($match[1]);
$plugin_basename = preg_replace('/_.*\.patch$/i', '', $file);
foreach (array_keys($installed_plugins) as $key) {
if (stripos($key, $plugin_basename) !== false) {
$installed_plugin_version = $installed_plugins[$key]['Version'];
break;
}
}
} else {
$patch_results['error'] = __('Patch file name is invalid', $domain);
break;
}
if (version_compare($installed_plugin_version, $plugin_version, '!=')) {
$patch_results['error'] = __('Patch file version does not match with that of your plugin.', $domain);
break;
}
$plugin_dir = WP_PLUGIN_DIR.'/'.$plugin_basename;
$patch_file = SQLitePatchDir.'/'.$file;
$command = $patch_command.' <'.$patch_file.' 2>&1';
if (chdir($plugin_dir)) {
exec("$command", $output, $retval);
} else {
$patch_results[$file] = __('Error! Plugin directory is not accessible.', $domain);
}
if ($retval == 0) {
$patch_results[$file] = __('is patched successfully.', $domain);
} else {
foreach ($output as $val) {
$message .= $val.'<br />';
}
$patch_results[$file] = sprintf(__('Error! Messages: %s', $domain), $message);
}
}
return $patch_results;
}
/**
* Method to remove patch file(s) from the server.
*
* It deletes uploaded patch file(s).
* If patch file(s) is not selected, returns false.
* Or else returns array contains messages.
*
* @return boolean|array
* @access private
*/
private function delete_patch_files() {
global $utils;
$domain = $utils->text_domain;
$file_names = array();
$rm_results = array();
if (isset($_POST['plugin_checked'])) {
$file_names = $_POST['plugin_checked'];
} else {
return false;
}
if (chdir(SQLitePatchDir)) {
foreach ($file_names as $file) {
if (unlink($file)) {
$rm_results[$file] = sprintf(__('File %s is deleted.', $domain), $file);
} else {
$rm_results[$file] = sprintf(__('Error! File %s is not deleted.', $domain), $file);
}
}
} else {
$rm_results[$file] = __('Error!: patches directory is not accessible.', $domain);
}
return $rm_results;
}
/**
* 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
* temporary directory. If there isn't SQLitePatchDir, this method will create it and
* set the permission to 0707.
*
* No return values.
*
* @return boolean
* @access private
*/
private function upload_file() {
global $utils;
$domain = $utils->text_domain;
if (!file_exists(SQLitePatchDir) || !is_dir(SQLitePatchDir)) {
if (!mkdir(SQLitePatchDir, 0707, true)) {
$message = __('Unable to create a patch directory.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
return false;
}
}
if (!is_file(SQLitePatchDir . '/.htaccess')) {
$fp = fopen(SQLitePatchDir . '/.htaccess', 'w');
if (!$fp) {
$message = __('Unable to create a .htaccess file.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
return false;
}
fwrite($fp, 'DENY FROM ALL');
fclose($fp);
}
if (!isset($_FILES['upfile']['error']) || !is_int($_FILES['upfile']['error'])) {
$message = __('Invalid operation.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
return false;
} elseif ($_FILES['upfile']['error'] != UPLOAD_ERR_OK) {
switch ($_FILES['upfile']['error']) {
case UPLOAD_ERR_FORM_SIZE:
$message = __('File is too large to upload.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
break;
case UPLOAD_ERR_PARTIAL:
$message = __('File upload is not complete.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
break;
case UPLOAD_ERR_NO_FILE:
$message = __('File is not uploaded.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$message = __('Temporary directory is not writable.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
break;
case UPLOAD_ERR_CANT_WRITE:
$message = __('File cannot be written on the disk.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
break;
default:
$message = __('Unknown error.', $domain);
break;
}
return false;
}
if (is_uploaded_file($_FILES['upfile']['tmp_name'])) {
$file_full_path = SQLitePatchDir . '/' . $_FILES['upfile']['name'];
if (move_uploaded_file($_FILES['upfile']['tmp_name'], $file_full_path)) {
$message = __('File is successfully uploaded.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
chmod(SQLitePatchDir.'/'.$_FILES['upfile']['name'], 0606);
} else {
$message = __('File upload failed. Possible file upload attack.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
return false;
}
} else {
$message = __('File is not selected', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
return false;
}
return true;
}
/**
* Method to display the patch utility page on the admin panel.
*
*/
function show_patch_page() {
global $utils;
$domain = $utils->text_domain;
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to access this page!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to access this page!', $domain));
}
if (isset($_POST['apply_patch'])) {
check_admin_referer('sqlitewordpress-plugin-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$result = $this->apply_patches();
if ($result === false) {
$message = __('Please select patch file(s)', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
} elseif (is_array($result) && count($result) > 0) {
echo '<div id="message" class="updated fade">';
foreach ($result as $key => $val) {
echo $key.' => '.$val.'<br />';
}
echo '</div>';
} else {
$message = __('None of the patches is applied!');
echo '<div id="message" class="updated fade">'.$message.'</div>';
}
}
if (isset($_POST['patch_file_delete'])) {
check_admin_referer('sqlitewordpress-plugin-manip-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$result = $this->delete_patch_files();
if ($result === false) {
$message = __('Please select patch file(s)', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
} elseif (is_array($result) && count($result) > 0) {
echo '<div id="message" class="updated fade">';
foreach ($result as $key => $val) {
echo $key.' => '.$val.'<br />';
}
echo '</div>';
} else {
$message = __('Error! Please remove files manually', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
}
}
if (isset($_POST['upload'])) {
check_admin_referer('sqlitewordpress-plugin-patch-file-stats');
if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to do this operation!', $domain));
} elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to do this operation!', $domain));
}
$result = $this->upload_file();
}
if (isset($_GET['page']) && $_GET['page'] == 'patch') : ?>
<div class="navigation">
<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=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-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>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Patch Files Upload and Apply', $domain);?></h2>
<h3><?php _e('What you can do in this page', $domain);?></h3>
<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);?>
</p>
<p>
<?php _e('In this page, you can upload patch files and apply them automatically. But there are some requirements.', $domain)?>
</p>
<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('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 script can execute &quot;patch&quot; shell command.(Script will check if it is executable or not.)', $domain);?></li>
</ol>
<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)?>
</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);?>
</p>
<ol>
<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 suffix .patch.', $domain);?></li>
<li><?php _e('Use diff command options &quot;-Naur&quot;.', $domain);?></li>
</ol>
<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);?>
</p>
<h3><?php _e('How to install, patch and activate plugins', $domain);?></h3>
<ol>
<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('Back to the installed plugin page and activate it', $domain);?></li>
</ol>
<h3><?php _e('How to upgrade plugins', $domain);?></h3>
<p>
<?php _e('When upgrading the plugin, it will be safer to follow next steps.', $domain);?>
</p>
<ol>
<li><?php _e('Deactivate 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('Reactivate the plugin', $domain);?></li>
</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>
<h3><?php _e('Upload and Apply', $domain)?></h3>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><?php _e('File Select', $domain);?></th>
<td>
<form action="" id="upload-form" class="wp-upload-form" method="post" enctype="multipart/form-data">
<?php if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqlitewordpress-plugin-patch-file-stats');
}
?>
<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 />
<input type="file" id="upload" name="upfile" size="60"/>
<input type="submit" name="upload" id="submit-upload" class="button" value="<?php _e('Upload', $domain)?>" />
</form>
</td>
</tr>
<tr>
<th scope="row"><?php _e('Patch files uploaded', $domain)?></th>
<td>
<form action="" method="post">
<?php if (function_exists('wp_nonce_field')) {
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>
<table class="widefat page fixed" id="patch-files">
<thead>
<tr>
<th class="item"><?php _e('Apply/Hold', $domain)?></th>
<th data-sort='{"key":"name"}'><?php _e('Patch files to apply', $domain)?></th>
</tr>
</thead>
<tbody>
<?php $files = $this->get_patch_files();
if (!empty($files)) : ?>
<?php foreach ($files as $file) : ?>
<tr data-table='{"name":"<?php echo $file ?>"}'>
<td><input type="checkbox" id="plugin_check" name="plugin_checked[]" value="<?php echo $file ?>"/></td>
<td><?php echo $file ?></td>
</tr>
<?php endforeach;?>
<?php endif;?>
</tbody>
</table>
<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="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>
</form>
</td>
</tr>
</tbody>
</table>
</div>
<h3><?php _e('How to install, patch and activate plugins', $domain);?></h3>
<ol>
<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('Back to the installed plugin page and activate it', $domain);?></li>
</ol>
<h3><?php _e('How to upgrade plugins', $domain);?></h3>
<p>
<?php _e('When upgrading the plugin, it will be safer to follow next steps.', $domain);?>
</p>
<ol>
<li><?php _e('Deactivate 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('Reactivate the plugin', $domain);?></li>
</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>
<h3><?php _e('Upload and Apply', $domain)?></h3>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><?php _e('File Select', $domain);?></th>
<td>
<form action="" id="upload-form" class="wp-upload-form" method="post" enctype="multipart/form-data">
<?php if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqlitewordpress-plugin-patch-file-stats');
}
?>
<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 />
<input type="file" id="upload" name="upfile" size="60"/>
<input type="submit" name="upload" id="submit-upload" class="button" value="<?php _e('Upload', $domain)?>" />
</form>
</td>
</tr>
<tr>
<th scope="row"><?php _e('Patch files uploaded', $domain)?></th>
<td>
<form action="" method="post">
<?php if (function_exists('wp_nonce_field')) {
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>
<table class="widefat page fixed" id="patch-files">
<thead>
<tr>
<th class="item"><?php _e('Apply/Hold', $domain)?></th>
<th data-sort='{"key":"name"}'><?php _e('Patch files to apply', $domain)?></th>
</tr>
</thead>
<tbody>
<?php $files = $this->get_patch_files();
if (!empty($files)) : ?>
<?php foreach ($files as $file) : ?>
<tr data-table='{"name":"<?php echo $file ?>"}'>
<td><input type="checkbox" id="plugin_check" name="plugin_checked[]" value="<?php echo $file ?>"/></td>
<td><?php echo $file ?></td>
</tr>
<?php endforeach;?>
<?php endif;?>
</tbody>
</table>
<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="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>
</form>
</td>
</tr>
</tbody>
</table>
</div>
<div class="wrap" id="sqlite-admin-side-wrap">
<div class="alert">
<?php _e('Caution about your patch file(s)', $domain);?>
</div>
<blockquote class="caution">
<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);?>
</p>
</blockquote>
</div>
<?php endif;
}
<div class="wrap" id="sqlite-admin-side-wrap">
<div class="alert">
<?php _e('Caution about your patch file(s)', $domain);?>
</div>
<blockquote class="caution">
<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);?>
</p>
</blockquote>
</div>
<?php endif;
}
}
?>

File diff suppressed because it is too large Load Diff