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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -16,63 +16,63 @@ if (!defined('ABSPATH')) {
* This function overrides wp_install() in wp-admin/includes/upgrade.php * This function overrides wp_install() in wp-admin/includes/upgrade.php
*/ */
function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') { function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') {
if (!empty($deprecated)) if (!empty($deprecated))
_deprecated_argument(__FUNCTION__, '2.6'); _deprecated_argument(__FUNCTION__, '2.6');
wp_check_mysql_version(); wp_check_mysql_version();
wp_cache_flush(); wp_cache_flush();
/* changes */ /* changes */
require_once PDODIR . 'schema.php'; require_once PDODIR . 'schema.php';
make_db_sqlite(); make_db_sqlite();
/* changes */ /* changes */
populate_options(); populate_options();
populate_roles(); populate_roles();
update_option('blogname', $blog_title); update_option('blogname', $blog_title);
update_option('admin_email', $user_email); update_option('admin_email', $user_email);
update_option('blog_public', $public); update_option('blog_public', $public);
$guessurl = wp_guess_url(); $guessurl = wp_guess_url();
update_option('siteurl', $guessurl); update_option('siteurl', $guessurl);
if (!$public) if (!$public)
update_option('default_pingback_flag', 0); update_option('default_pingback_flag', 0);
$user_id = username_exists($user_name); $user_id = username_exists($user_name);
$user_password = trim($user_password); $user_password = trim($user_password);
$email_password = false; $email_password = false;
if (!$user_id && empty($user_password)) { if (!$user_id && empty($user_password)) {
$user_password = wp_generate_password(12, false); $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.'); $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); $user_id = wp_create_user($user_name, $user_password, $user_email);
update_user_option($user_id, 'default_password_nag', true, true); update_user_option($user_id, 'default_password_nag', true, true);
$email_password = true; $email_password = true;
} else if (!$user_id) { } else if (!$user_id) {
$message = '<em>'.__('Your chosen password.').'</em>'; $message = '<em>'.__('Your chosen password.').'</em>';
$user_id = wp_create_user($user_name, $user_password, $user_email); $user_id = wp_create_user($user_name, $user_password, $user_email);
} }
$user = new WP_User($user_id); $user = new WP_User($user_id);
$user->set_role('administrator'); $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) { 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. ;// Your server is Apache. Nothing to do more.
} else { } 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); $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 '<div style="position: absolute; margin-top: 250px; width: 700px; border: .5px dashed rgb(0, 0, 0);"><p style="margin: 10px;">';
echo $server_message; echo $server_message;
echo '</p></div>'; 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 = $table.find('thead th').slice(1);
} }
$headers $headers
.wrapInner('<a href="#"></a>') .wrapInner('<a href="#"></a>')
.addClass('sort'); .addClass('sort');
var rows = $table.find('tbody > tr').get(); var rows = $table.find('tbody > tr').get();
$headers.bind('click', function(event) { $headers.bind('click', function(event) {
event.preventDefault(); event.preventDefault();
var $header = $(this), var $header = $(this),
sortKey = $header.data('sort').key, sortKey = $header.data('sort').key,
sortDirection = 1; sortDirection = 1;
if ($header.hasClass('sorted-asc')) { if ($header.hasClass('sorted-asc')) {
sortDirection = -1; sortDirection = -1;
} }
@ -70,14 +70,14 @@ jQuery(document).ready(function($) {
var $table = $('#plugins-info'); var $table = $('#plugins-info');
var $headers = $table.find('thead th').slice(0); var $headers = $table.find('thead th').slice(0);
$headers $headers
.wrapInner('<a href="#"></a>') .wrapInner('<a href="#"></a>')
.addClass('sort'); .addClass('sort');
var rows = $table.find('tbody > tr').get(); var rows = $table.find('tbody > tr').get();
$headers.bind('click', function(event) { $headers.bind('click', function(event) {
event.preventDefault(); event.preventDefault();
var $header = $(this), var $header = $(this),
sortKey = $header.data('sort').key, sortKey = $header.data('sort').key,
sortDirection = 1; sortDirection = 1;
if ($header.hasClass('sorted-asc')) { if ($header.hasClass('sorted-asc')) {
sortDirection = -1; sortDirection = -1;
} }

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -48,6 +48,12 @@ class PDOSQLiteDriver {
* @var boolean * @var boolean
*/ */
private $rewrite_between = false; 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. * Method to rewrite a query string for SQLite to execute.
* *
@ -57,82 +63,82 @@ class PDOSQLiteDriver {
*/ */
public function rewrite_query($query, $query_type){ public function rewrite_query($query, $query_type){
$this->query_type = $query_type; $this->query_type = $query_type;
$this->_query = $query; $this->_query = $query;
$this->parse_query(); $this->parse_query();
switch ($this->query_type) { switch ($this->query_type) {
case 'truncate': case 'truncate':
$this->handle_truncate_query(); $this->handle_truncate_query();
break; break;
case 'alter': case 'alter':
$this->handle_alter_query(); $this->handle_alter_query();
break; break;
case 'create': case 'create':
$this->handle_create_query(); $this->handle_create_query();
break; break;
case 'describe': case 'describe':
case 'desc': case 'desc':
$this->handle_describe_query(); $this->handle_describe_query();
break; break;
case 'show': case 'show':
$this->handle_show_query(); $this->handle_show_query();
break; break;
case 'showcolumns': case 'showcolumns':
$this->handle_show_columns_query(); $this->handle_show_columns_query();
break; break;
case 'showindex': case 'showindex':
$this->handle_show_index(); $this->handle_show_index();
break; break;
case 'select': case 'select':
//$this->strip_backticks(); //$this->strip_backticks();
$this->handle_sql_count(); $this->handle_sql_count();
$this->rewrite_date_sub(); $this->rewrite_date_sub();
$this->delete_index_hints(); $this->delete_index_hints();
$this->rewrite_regexp(); $this->rewrite_regexp();
//$this->rewrite_boolean(); //$this->rewrite_boolean();
$this->fix_date_quoting(); $this->fix_date_quoting();
$this->rewrite_between(); $this->rewrite_between();
break; break;
case 'insert': case 'insert':
//$this->safe_strip_backticks(); //$this->safe_strip_backticks();
$this->execute_duplicate_key_update(); $this->execute_duplicate_key_update();
$this->rewrite_insert_ignore(); $this->rewrite_insert_ignore();
$this->rewrite_regexp(); $this->rewrite_regexp();
$this->fix_date_quoting(); $this->fix_date_quoting();
break; break;
case 'update': case 'update':
//$this->safe_strip_backticks(); //$this->safe_strip_backticks();
$this->rewrite_update_ignore(); $this->rewrite_update_ignore();
// $this->_rewrite_date_sub(); //$this->_rewrite_date_sub();
$this->rewrite_limit_usage(); $this->rewrite_limit_usage();
$this->rewrite_order_by_usage(); $this->rewrite_order_by_usage();
$this->rewrite_regexp(); $this->rewrite_regexp();
$this->rewrite_between(); $this->rewrite_between();
break; break;
case 'delete': case 'delete':
//$this->strip_backticks(); //$this->strip_backticks();
$this->rewrite_limit_usage(); $this->rewrite_limit_usage();
$this->rewrite_order_by_usage(); $this->rewrite_order_by_usage();
$this->rewrite_date_sub(); $this->rewrite_date_sub();
$this->rewrite_regexp(); $this->rewrite_regexp();
$this->delete_workaround(); $this->delete_workaround();
break; break;
case 'replace': case 'replace':
//$this->safe_strip_backticks(); //$this->safe_strip_backticks();
$this->rewrite_date_sub(); $this->rewrite_date_sub();
$this->rewrite_regexp(); $this->rewrite_regexp();
break; break;
case 'optimize': case 'optimize':
$this->rewrite_optimize(); $this->rewrite_optimize();
break; break;
case 'pragma': case 'pragma':
break; break;
default: default:
if (defined(WP_DEBUG) && WP_DEBUG) { if (defined(WP_DEBUG) && WP_DEBUG) {
break; break;
} else { } else {
$this->return_true(); $this->return_true();
break; break;
} }
} }
return $this->_query; return $this->_query;
} }
@ -161,29 +167,30 @@ class PDOSQLiteDriver {
if (strpos($token, '`') !== false) { if (strpos($token, '`') !== false) {
$token = str_replace('`', '', $token); $token = str_replace('`', '', $token);
} }
if (preg_match('/\\bTRUE\\b/i', $token)) { if (preg_match('/\\bTRUE\\b/i', $token)) {
$token = str_ireplace('TRUE', '1', $token); $token = str_ireplace('TRUE', '1', $token);
} }
if (preg_match('/\\bFALSE\\b/i', $token)) { if (preg_match('/\\bFALSE\\b/i', $token)) {
$token = str_ireplace('FALSE', '0', $token); $token = str_ireplace('FALSE', '0', $token);
} }
if (stripos($token, 'SQL_CALC_FOUND_ROWS') !== false) { if (stripos($token, 'SQL_CALC_FOUND_ROWS') !== false) {
$this->rewrite_calc_found = true; $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; $this->rewrite_duplicate_key = true;
} }
if (stripos($token, 'USE INDEX') !== false) { if (stripos($token, 'USE INDEX') !== false) {
$this->rewrite_index_hint = true; $this->rewrite_index_hint = true;
} }
if (stripos($token, 'IGNORE INDEX') !== false) { if (stripos($token, 'IGNORE INDEX') !== false) {
$this->rewrite_index_hint = true; $this->rewrite_index_hint = true;
} }
if (stripos($token, 'FORCE INDEX') !== false) { if (stripos($token, 'FORCE INDEX') !== false) {
$this->rewrite_index_hint = true; $this->rewrite_index_hint = true;
} }
if (stripos($token, 'BETWEEN') !== false) { if (stripos($token, 'BETWEEN') !== false) {
$this->rewrite_between = true; $this->rewrite_between = true;
$this->num_of_rewrite_between++;
} }
} }
} }
@ -197,11 +204,11 @@ class PDOSQLiteDriver {
* @access private * @access private
*/ */
private function handle_show_query(){ private function handle_show_query(){
$this->_query = str_ireplace(' FULL', '', $this->_query); $this->_query = str_ireplace(' FULL', '', $this->_query);
$table_name = ''; $table_name = '';
$pattern = '/^\\s*SHOW\\s*TABLES\\s*.*?(LIKE\\s*(.*))$/im'; $pattern = '/^\\s*SHOW\\s*TABLES\\s*.*?(LIKE\\s*(.*))$/im';
if (preg_match($pattern, $this->_query, $matches)) { 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)) { if (!empty($table_name)) {
$suffix = ' AND name LIKE '. "'" . $table_name . "'"; $suffix = ' AND name LIKE '. "'" . $table_name . "'";
@ -276,8 +283,8 @@ class PDOSQLiteDriver {
$this->_query = str_ireplace('SQL_CALC_FOUND_ROWS', '', $this->_query); $this->_query = str_ireplace('SQL_CALC_FOUND_ROWS', '', $this->_query);
// we make the data for next SELECE FOUND_ROWS() statement // we make the data for next SELECE FOUND_ROWS() statement
$unlimited_query = preg_replace('/\\bLIMIT\\s*.*/imsx', '', $this->_query); $unlimited_query = preg_replace('/\\bLIMIT\\s*.*/imsx', '', $this->_query);
//$unlimited_query = preg_replace('/\\bGROUP\\s*BY\\s*.*/imsx', '', $unlimited_query); //$unlimited_query = preg_replace('/\\bGROUP\\s*BY\\s*.*/imsx', '', $unlimited_query);
// we no longer use SELECT COUNT query // we no longer use SELECT COUNT query
//$unlimited_query = $this->_transform_to_count($unlimited_query); //$unlimited_query = $this->_transform_to_count($unlimited_query);
$_wpdb = new PDODB(); $_wpdb = new PDODB();
$result = $_wpdb->query($unlimited_query); $result = $_wpdb->query($unlimited_query);
@ -325,10 +332,10 @@ class PDOSQLiteDriver {
private function rewrite_date_add(){ private function rewrite_date_add(){
//(date,interval expression unit) //(date,interval expression unit)
$pattern = '/\\s*date_add\\s*\(([^,]*),([^\)]*)\)/imsx'; $pattern = '/\\s*date_add\\s*\(([^,]*),([^\)]*)\)/imsx';
if (preg_match($pattern, $this->_query, $matches)) { if (preg_match($pattern, $this->_query, $matches)) {
$expression = "'".trim($matches[2])."'"; $expression = "'".trim($matches[2])."'";
$this->_query = preg_replace($pattern, " date_add($matches[1], $expression) ", $this->_query); $this->_query = preg_replace($pattern, " date_add($matches[1], $expression) ", $this->_query);
} }
} }
/** /**
* Method to rewrite DATE_SUB() function. * Method to rewrite DATE_SUB() function.
@ -341,10 +348,10 @@ class PDOSQLiteDriver {
private function rewrite_date_sub(){ private function rewrite_date_sub(){
//(date,interval expression unit) //(date,interval expression unit)
$pattern = '/\\s*date_sub\\s*\(([^,]*),([^\)]*)\)/imsx'; $pattern = '/\\s*date_sub\\s*\(([^,]*),([^\)]*)\)/imsx';
if (preg_match($pattern, $this->_query, $matches)) { if (preg_match($pattern, $this->_query, $matches)) {
$expression = "'".trim($matches[2])."'"; $expression = "'".trim($matches[2])."'";
$this->_query = preg_replace($pattern, " date_sub($matches[1], $expression) ", $this->_query); $this->_query = preg_replace($pattern, " date_sub($matches[1], $expression) ", $this->_query);
} }
} }
/** /**
* Method to handle CREATE query. * Method to handle CREATE query.
@ -370,10 +377,10 @@ class PDOSQLiteDriver {
* @access private * @access private
*/ */
private function handle_alter_query(){ private function handle_alter_query(){
require_once PDODIR . 'query_alter.class.php'; require_once PDODIR . 'query_alter.class.php';
$engine = new AlterQuery(); $engine = new AlterQuery();
$this->_query = $engine->rewrite_query($this->_query, 'alter'); $this->_query = $engine->rewrite_query($this->_query, 'alter');
$engine = null; $engine = null;
} }
/** /**
@ -385,11 +392,10 @@ class PDOSQLiteDriver {
* @access private * @access private
*/ */
private function handle_describe_query(){ private function handle_describe_query(){
// $this->_query = "select 1=1";
$pattern = '/^\\s*(DESCRIBE|DESC)\\s*(.*)/i'; $pattern = '/^\\s*(DESCRIBE|DESC)\\s*(.*)/i';
if (preg_match($pattern, $this->_query, $match)) { if (preg_match($pattern, $this->_query, $match)) {
$tablename = preg_replace('/[\';]/', '', $match[2]); $tablename = preg_replace('/[\';]/', '', $match[2]);
$this->_query = "PRAGMA table_info($tablename)"; $this->_query = "PRAGMA table_info($tablename)";
} }
} }
/** /**
@ -409,9 +415,9 @@ class PDOSQLiteDriver {
foreach ($options as $opt) { foreach ($options as $opt) {
if (stripos($opt->compile_option, 'ENABLE_UPDATE_DELETE_LIMIT') !== false) return; if (stripos($opt->compile_option, 'ENABLE_UPDATE_DELETE_LIMIT') !== false) return;
} }
if (stripos($this->_query, '(select') === false) { if (stripos($this->_query, '(select') === false) {
$this->_query = preg_replace('/\\s*LIMIT\\s*[0-9]$/i', '', $this->_query); $this->_query = preg_replace('/\\s*LIMIT\\s*[0-9]$/i', '', $this->_query);
} }
} }
/** /**
* Method to remove ORDER BY clause from DELETE or UPDATE query. * Method to remove ORDER BY clause from DELETE or UPDATE query.
@ -428,9 +434,9 @@ class PDOSQLiteDriver {
foreach ($options as $opt) { foreach ($options as $opt) {
if (stripos($opt->compile_option, 'ENABLE_UPDATE_DELETE_LIMIT') !== false) return; if (stripos($opt->compile_option, 'ENABLE_UPDATE_DELETE_LIMIT') !== false) return;
} }
if (stripos($this->_query, '(select') === false) { if (stripos($this->_query, '(select') === false) {
$this->_query = preg_replace('/\\s*ORDER\\s*BY\\s*.*$/i', '', $this->_query); $this->_query = preg_replace('/\\s+ORDER\\s+BY\\s*.*$/i', '', $this->_query);
} }
} }
/** /**
* Method to handle TRUNCATE query. * Method to handle TRUNCATE query.
@ -529,241 +535,241 @@ class PDOSQLiteDriver {
* @access private * @access private
*/ */
private function rewrite_boolean() { private function rewrite_boolean() {
$query = str_ireplace('TRUE', "1", $this->_query); $query = str_ireplace('TRUE', "1", $this->_query);
$query = str_ireplace('FALSE', "0", $query); $query = str_ireplace('FALSE', "0", $query);
$this->_query = $query; $this->_query = $query;
} }
/** /**
* Method to handl SHOW COLUMN query. * Method to handl SHOW COLUMN query.
* *
* @access private * @access private
*/ */
private function handle_show_columns_query() { private function handle_show_columns_query() {
$this->_query = str_ireplace(' FULL', '', $this->_query); $this->_query = str_ireplace(' FULL', '', $this->_query);
$pattern_like = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?\\s*LIKE\\s*(.*)?/i'; $pattern_like = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?\\s*LIKE\\s*(.*)?/i';
$pattern = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?/i'; $pattern = '/^\\s*SHOW\\s*(COLUMNS|FIELDS)\\s*FROM\\s*(.*)?/i';
if (preg_match($pattern_like, $this->_query, $matches)) { if (preg_match($pattern_like, $this->_query, $matches)) {
$table_name = str_replace("'", "", trim($matches[2])); $table_name = str_replace("'", "", trim($matches[2]));
$column_name = str_replace("'", "", trim($matches[3])); $column_name = str_replace("'", "", trim($matches[3]));
$query_string = "SELECT sql FROM sqlite_master WHERE tbl_name='$table_name' AND sql LIKE '%$column_name%'"; $query_string = "SELECT sql FROM sqlite_master WHERE tbl_name='$table_name' AND sql LIKE '%$column_name%'";
$this->_query = $query_string; $this->_query = $query_string;
} elseif (preg_match($pattern, $this->_query, $matches)) { } elseif (preg_match($pattern, $this->_query, $matches)) {
$table_name = $matches[2]; $table_name = $matches[2];
$query_string = preg_replace($pattern, "PRAGMA table_info($table_name)", $this->_query); $query_string = preg_replace($pattern, "PRAGMA table_info($table_name)", $this->_query);
$this->_query = $query_string; $this->_query = $query_string;
} }
} }
/** /**
* Method to handle SHOW INDEX query. * Method to handle SHOW INDEX query.
* *
* Moved the WHERE clause manipulation to pdoengin.class.php (ver 1.3.1) * Moved the WHERE clause manipulation to pdoengin.class.php (ver 1.3.1)
* *
* @access private * @access private
*/ */
private function handle_show_index() { private function handle_show_index() {
$pattern = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?/im'; $pattern = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?/im';
if (preg_match($pattern, $this->_query, $match)) { if (preg_match($pattern, $this->_query, $match)) {
$table_name = preg_replace("/[\';]/", '', $match[1]); $table_name = preg_replace("/[\';]/", '', $match[1]);
$table_name = trim($table_name); $table_name = trim($table_name);
$this->_query = "SELECT * FROM sqlite_master WHERE tbl_name='$table_name'"; $this->_query = "SELECT * FROM sqlite_master WHERE tbl_name='$table_name'";
} }
} }
/** /**
* Method to handle ON DUPLICATE KEY UPDATE statement. * Method to handle ON DUPLICATE KEY UPDATE statement.
* *
* First we use SELECT query and check if INSERT is allowed or not. * 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. * Rewriting procedure looks like a detour, but I've got no other ways.
* *
* Added the literal check since the version 1.5.1. * Added the literal check since the version 1.5.1.
* *
* @return void * @return void
* @access private * @access private
*/ */
private function execute_duplicate_key_update() { private function execute_duplicate_key_update() {
if (!$this->rewrite_duplicate_key) return; if (!$this->rewrite_duplicate_key) return;
$unique_keys_for_cond = array(); $unique_keys_for_cond = array();
$unique_keys_for_check = array(); $unique_keys_for_check = array();
$pattern = '/^\\s*INSERT\\s*INTO\\s*(\\w+)?\\s*(.*)\\s*ON\\s*DUPLICATE\\s*KEY\\s*UPDATE\\s*(.*)$/ims'; $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)) { if (preg_match($pattern, $this->_query, $match_0)) {
$table_name = trim($match_0[1]); $table_name = trim($match_0[1]);
$insert_data = trim($match_0[2]); $insert_data = trim($match_0[2]);
$update_data = trim($match_0[3]); $update_data = trim($match_0[3]);
// prepare two unique key data for the table // prepare two unique key data for the table
// 1. array('col1', 'col2, col3', etc) 2. array('col1', 'col2', 'col3', etc) // 1. array('col1', 'col2, col3', etc) 2. array('col1', 'col2', 'col3', etc)
$_wpdb = new PDODB(); $_wpdb = new PDODB();
$indexes = $_wpdb->get_results("SHOW INDEX FROM {$table_name}"); $indexes = $_wpdb->get_results("SHOW INDEX FROM {$table_name}");
if (!empty($indexes)) { if (!empty($indexes)) {
foreach ($indexes as $index) { foreach ($indexes as $index) {
if ($index->Non_unique == 0) { if ($index->Non_unique == 0) {
$unique_keys_for_cond[] = $index->Column_name; $unique_keys_for_cond[] = $index->Column_name;
if (strpos($index->Column_name, ',') !== false) { if (strpos($index->Column_name, ',') !== false) {
$unique_keys_for_check = array_merge($unique_keys_for_check, explode(',', $index->Column_name)); $unique_keys_for_check = array_merge($unique_keys_for_check, explode(',', $index->Column_name));
} else { } else {
$unique_keys_for_check[] = $index->Column_name; $unique_keys_for_check[] = $index->Column_name;
} }
} }
} }
$unique_keys_for_check = array_map('trim', $unique_keys_for_check); $unique_keys_for_check = array_map('trim', $unique_keys_for_check);
} else { } else {
// Without unique key or primary key, UPDATE statement will affect all the rows! // Without unique key or primary key, UPDATE statement will affect all the rows!
$query = 'INSERT INTO '.$table_name.' '.$insert_data; $query = 'INSERT INTO '.$table_name.' '.$insert_data;
$this->_query = $query; $this->_query = $query;
$_wpdb = null; $_wpdb = null;
return; return;
} }
// data check // data check
if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/ims', $insert_data, $match_1)) { if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/ims', $insert_data, $match_1)) {
$col_array = explode(',', $match_1[1]); $col_array = explode(',', $match_1[1]);
$ins_data_array = explode(',', $match_1[2]); $ins_data_array = explode(',', $match_1[2]);
foreach ($col_array as $col) { foreach ($col_array as $col) {
$val = trim(array_shift($ins_data_array)); $val = trim(array_shift($ins_data_array));
$ins_data_assoc[trim($col)] = $val; $ins_data_assoc[trim($col)] = $val;
} }
// $ins_data_assoc = array_combine($col_array, $ins_array); $ins_data_assoc = array_combine($col_array, $ins_array);
$condition = ''; $condition = '';
foreach ($unique_keys_for_cond as $unique_key) { foreach ($unique_keys_for_cond as $unique_key) {
if (strpos($unique_key, ',') !== false) { if (strpos($unique_key, ',') !== false) {
$unique_key_array = explode(',', $unique_key); $unique_key_array = explode(',', $unique_key);
$counter = count($unique_key_array); $counter = count($unique_key_array);
for ($i = 0; $i < $counter; ++$i) { for ($i = 0; $i < $counter; ++$i) {
$col = trim($unique_key_array[$i]); $col = trim($unique_key_array[$i]);
if (isset($ins_data_assoc[$col]) && $i == $counter - 1) { if (isset($ins_data_assoc[$col]) && $i == $counter - 1) {
$condition .= $col . '=' . $ins_data_assoc[$col] . ' OR '; $condition .= $col . '=' . $ins_data_assoc[$col] . ' OR ';
} elseif (isset($ins_data_assoc[$col])) { } elseif (isset($ins_data_assoc[$col])) {
$condition .= $col . '=' . $ins_data_assoc[$col] . ' AND '; $condition .= $col . '=' . $ins_data_assoc[$col] . ' AND ';
} else { } else {
continue; continue;
} }
} }
// $condition = rtrim($condition, ' AND '); $condition = rtrim($condition, ' AND ');
} else { } else {
$col = trim($unique_key); $col = trim($unique_key);
if (isset($ins_data_assoc[$col])) { if (isset($ins_data_assoc[$col])) {
$condition .= $col . '=' . $ins_data_assoc[$col] . ' OR '; $condition .= $col . '=' . $ins_data_assoc[$col] . ' OR ';
} else { } else {
continue; continue;
} }
} }
} }
$condition = rtrim($condition, ' OR '); $condition = rtrim($condition, ' OR ');
$test_query = "SELECT * FROM {$table_name} WHERE {$condition}"; $test_query = "SELECT * FROM {$table_name} WHERE {$condition}";
$results = $_wpdb->query($test_query); $results = $_wpdb->query($test_query);
$_wpdb = null; $_wpdb = null;
if ($results == 0) { if ($results == 0) {
$this->_query = 'INSERT INTO '.$table_name.' '.$insert_data; $this->_query = 'INSERT INTO '.$table_name.' '.$insert_data;
return; return;
} else { } else {
// change (col, col...) values (data, data...) to array(col=>data, col=>data...) if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/im', $insert_data, $match_2)) {
if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/im', $insert_data, $match_2)) { $col_array = explode(',', $match_2[1]);
$col_array = explode(',', $match_2[1]); $ins_array = explode(',', $match_2[2]);
$ins_array = explode(',', $match_2[2]); $count = count($col_array);
$count = count($col_array); for ($i = 0; $i < $count; $i++) {
for ($i = 0; $i < $count; $i++) { $col = trim($col_array[$i]);
$col = trim($col_array[$i]); $val = trim($ins_array[$i]);
$val = trim($ins_array[$i]); $ins_array_assoc[$col] = $val;
$ins_array_assoc[$col] = $val; }
} }
} $update_data = rtrim($update_data, ';');
// change col = data, col = data to array(col=>data, col=>data) $tmp_array = explode(',', $update_data);
// some plugins have semi-colon at the end of the query foreach ($tmp_array as $pair) {
$update_data = rtrim($update_data, ';'); list($col, $value) = explode('=', $pair);
$tmp_array = explode(',', $update_data); $col = trim($col);
foreach ($tmp_array as $pair) { $value = trim($value);
list($col, $value) = explode('=', $pair); $update_array_assoc[$col] = $value;
$col = trim($col); }
$value = trim($value); foreach ($update_array_assoc as $key => &$value) {
$update_array_assoc[$col] = $value; if (preg_match('/^VALUES\\s*\((.*)\)$/im', $value, $match_3)) {
} $col = trim($match_3[1]);
// change array(col=>values(col)) to array(col=>data) $value = $ins_array_assoc[$col];
foreach ($update_array_assoc as $key => &$value) { }
if (preg_match('/^VALUES\\s*\((.*)\)$/im', $value, $match_3)) { }
$col = trim($match_3[1]); foreach ($ins_array_assoc as $key => $val) {
$value = $ins_array_assoc[$col]; if (in_array($key, $unique_keys_for_check)) {
} $where_array[] = $key . '=' . $val;
} }
foreach ($ins_array_assoc as $key => $val) { }
if (in_array($key, $unique_keys_for_check)) { $update_strings = '';
$where_array[] = $key . '=' . $val; foreach ($update_array_assoc as $key => $val) {
} if (in_array($key, $unique_keys_for_check)) {
} $where_array[] = $key . '=' . $val;
$update_strings = ''; } else {
foreach ($update_array_assoc as $key => $val) { $update_strings .= $key . '=' . $val . ',';
if (in_array($key, $unique_keys_for_check)) { }
$where_array[] = $key . '=' . $val; }
} else { $update_strings = rtrim($update_strings, ',');
$update_strings .= $key . '=' . $val . ','; $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;
$update_strings = rtrim($update_strings, ','); $this->_query = $update_query;
$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; /**
} * 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
// else { * in the data or SQL statement.
// $pattern = '/ ON DUPLICATE KEY UPDATE.*$/im'; *
// $replace_query = preg_replace($pattern, '', $this->_query); * @access private
// $replace_query = str_ireplace('INSERT ', 'INSERT OR REPLACE ', $replace_query); */
// $this->_query = $replace_query; private function rewrite_between() {
// } if (!$this->rewrite_between) return;
} $pattern = '/\\s*(CAST\([^\)]+?\)|[^\\s\(]*)?\\s*BETWEEN\\s*([^\\s]*)?\\s*AND\\s*([^\\s\)]*)?\\s*/ims';
/** do {
* Method to rewrite BETWEEN A AND B clause. if (preg_match($pattern, $this->_query, $match)) {
* $column_name = trim($match[1]);
* This clause is the same form as natural language, so we have to check if it is $min_value = trim($match[2]);
* in the data or SQL statement. $max_value = trim($match[3]);
* $max_value = rtrim($max_value);
* @access private $replacement = " ($column_name >= $min_value AND $column_name <= $max_value)";
*/ $this->_query = str_ireplace($match[0], $replacement, $this->_query);
private function rewrite_between() { }
if (!$this->rewrite_between) return; $this->num_of_rewrite_between--;
$pattern = '/\\s*(CAST\([^\)]+?\)|[^\\s\(]*)?\\s*BETWEEN\\s*([^\\s]*)?\\s*AND\\s*([^\\s\)]*)?\\s*/ims'; } while ($this->num_of_rewrite_between > 0);
if (preg_match($pattern, $this->_query, $match)) { }
$column_name = trim($match[1]); /**
$min_value = trim($match[2]); * Method to avoid DELETE with JOIN statement.
$max_value = trim($match[3]); *
$max_value = rtrim($max_value); * wp-admin/includes/upgrade.php contains 'DELETE ... JOIN' statement.
$replacement = " $column_name >= $min_value AND $column_name <= $max_value"; * This query can't be replaced with regular expression or udf, so we
$this->_query = str_ireplace($match[0], $replacement, $this->_query); * replace all the statement with another. But this query was used in
$this->rewrite_between = false; * the very old version of WordPress when it was upgraded. So we won't
} * have no chance that this method should be used.
$this->parse_query(); *
$this->rewrite_between(); * @access private
} */
/** private function delete_workaround() {
* Method to avoid DELETE with JOIN statement. global $wpdb;
*
* 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";
$pattern = "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2"; $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)"; $pattern2 = "DELETE a, b FROM $wpdb->sitemeta AS a, $wpdb->sitemeta AS b";
if (stripos($this->_query, $pattern) !== false) { $rewritten = "DELETE FROM $wpdb->options WHERE option_id IN (SELECT MIN(option_id) FROM $wpdb->options GROUP BY option_name HAVING COUNT(*) > 1)";
$this->_query = $rewritten; if (stripos($this->_query, $pattern) !== false) {
} $this->_query = $rewritten;
} } else if (stripos($this->_query, $pattern2) !== false) {
/** $time = time();
* Method to suppress errors. $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();
* When the query string is the one that this class can't manipulate, $ids = $_wpdb->get_results($prep_query);
* the query string is replaced with the one that always returns true foreach ($ids as $id) {
* and does nothing. $ids_to_delete[] = $id->aid;
* $ids_to_delete[] = $id->bid;
* @access private }
*/ $rewritten = "DELETE FROM $wpdb->sitemeta WHERE meta_id IN (".implode(',', $ids_to_delete).")";
private function return_true() { $this->_query = $rewritten;
$this->_query = 'SELECT 1=1'; }
} }
/**
* 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(){ private function get_table_name(){
// $pattern = '/^\\s*CREATE\\s*(TEMP|TEMPORARY)?\\s*TABLE\\s*(IF NOT EXISTS)?\\s*([^\(]*)/imsx'; // $pattern = '/^\\s*CREATE\\s*(TEMP|TEMPORARY)?\\s*TABLE\\s*(IF NOT EXISTS)?\\s*([^\(]*)/imsx';
$pattern = '/^\\s*CREATE\\s*(?:TEMP|TEMPORARY)?\\s*TABLE\\s*(?:IF\\s*NOT\\s*EXISTS)?\\s*([^\(]*)/imsx'; $pattern = '/^\\s*CREATE\\s*(?:TEMP|TEMPORARY)?\\s*TABLE\\s*(?:IF\\s*NOT\\s*EXISTS)?\\s*([^\(]*)/imsx';
if (preg_match($pattern, $this->_query, $matches)) { if (preg_match($pattern, $this->_query, $matches)) {
$this->table_name = trim($matches[1]); $this->table_name = trim($matches[1]);
} }
} }
/** /**
* Method to change the MySQL field types to SQLite compatible types. * Method to change the MySQL field types to SQLite compatible types.
@ -112,23 +112,23 @@ class CreateQuery{
*/ */
private function rewrite_field_types(){ private function rewrite_field_types(){
$array_types = array ( $array_types = array (
'bit' => 'integer', 'bool' => 'integer', 'bit' => 'integer', 'bool' => 'integer',
'boolean' => 'integer', 'tinyint' => 'integer', 'boolean' => 'integer', 'tinyint' => 'integer',
'smallint' => 'integer', 'mediumint' => 'integer', 'smallint' => 'integer', 'mediumint' => 'integer',
'int' => 'integer', 'integer' => 'integer', 'int' => 'integer', 'integer' => 'integer',
'bigint' => 'integer', 'float' => 'real', 'bigint' => 'integer', 'float' => 'real',
'double' => 'real', 'decimal' => 'real', 'double' => 'real', 'decimal' => 'real',
'dec' => 'real', 'numeric' => 'real', 'dec' => 'real', 'numeric' => 'real',
'fixed' => 'real', 'date' => 'text', 'fixed' => 'real', 'date' => 'text',
'datetime' => 'text', 'timestamp' => 'text', 'datetime' => 'text', 'timestamp' => 'text',
'time' => 'text', 'year' => 'text', 'time' => 'text', 'year' => 'text',
'char' => 'text', 'varchar' => 'text', 'char' => 'text', 'varchar' => 'text',
'binary' => 'integer', 'varbinary' => 'blob', 'binary' => 'integer', 'varbinary' => 'blob',
'tinyblob' => 'blob', 'tinytext' => 'text', 'tinyblob' => 'blob', 'tinytext' => 'text',
'blob' => 'blob', 'text' => 'text', 'blob' => 'blob', 'text' => 'text',
'mediumblob' => 'blob', 'mediumtext' => 'text', 'mediumblob' => 'blob', 'mediumtext' => 'text',
'longblob' => 'blob', 'longtext' => 'text' 'longblob' => 'blob', 'longtext' => 'text'
); );
foreach ($array_types as $o=>$r){ foreach ($array_types as $o=>$r){
$pattern = "/\\b(?<!`)$o\\b\\s*(\([^\)]*\)*)?\\s*/ims"; $pattern = "/\\b(?<!`)$o\\b\\s*(\([^\)]*\)*)?\\s*/ims";
if (preg_match("/^\\s*.*?\\s*\(.*?$o.*?\)/im", $this->_query)) { if (preg_match("/^\\s*.*?\\s*\(.*?$o.*?\)/im", $this->_query)) {
@ -193,23 +193,23 @@ class CreateQuery{
if ($this->has_primary_key) { if ($this->has_primary_key) {
$this->_query = preg_replace('/\\s*primary key\\s*.*?\([^\)]*\)\\s*(,|)/i', ' ', $this->_query); $this->_query = preg_replace('/\\s*primary key\\s*.*?\([^\)]*\)\\s*(,|)/i', ' ', $this->_query);
} else { } else {
// If primary key has an index name, we remove that name. // If primary key has an index name, we remove that name.
$this->_query = preg_replace('/\\bprimary\\s*key\\s*.*?\\s*(\(.*?\))/im', 'PRIMARY KEY \\1', $this->_query); $this->_query = preg_replace('/\\bprimary\\s*key\\s*.*?\\s*(\(.*?\))/im', 'PRIMARY KEY \\1', $this->_query);
}
}
/**
* Method for rewriting foreign key.
*
* @access private
*/
private function rewrite_foreign_key() {
$pattern = '/\\s*foreign\\s*key\\s*(|.*?)\([^\)]+?\)\\s*references\\s*.*/i';
if (preg_match_all($pattern, $this->_query, $match)) {
if (isset($match[1])) {
$this->_query = str_ireplace($match[1], '', $this->_query);
}
} }
} }
/**
* Method for rewriting foreign key.
*
* @access private
*/
private function rewrite_foreign_key() {
$pattern = '/\\s*foreign\\s*key\\s*(|.*?)\([^\)]+?\)\\s*references\\s*.*/i';
if (preg_match_all($pattern, $this->_query, $match)) {
if (isset($match[1])) {
$this->_query = str_ireplace($match[1], '', $this->_query);
}
}
}
/** /**
* Method for rewriting unique key. * Method for rewriting unique key.
* *
@ -225,24 +225,24 @@ class CreateQuery{
* @access private * @access private
*/ */
private function _rewrite_unique_key($matches){ private function _rewrite_unique_key($matches){
$index_name = trim($matches[1]); $index_name = trim($matches[1]);
$col_name = trim($matches[2]); $col_name = trim($matches[2]);
$tbl_name = $this->table_name; $tbl_name = $this->table_name;
if (preg_match('/\(\\d+?\)/', $col_name)) { if (preg_match('/\(\\d+?\)/', $col_name)) {
$col_name = preg_replace('/\(\\d+?\)/', '', $col_name); $col_name = preg_replace('/\(\\d+?\)/', '', $col_name);
} }
$_wpdb = new PDODB(); $_wpdb = new PDODB();
$results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'"); $results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'");
$_wpdb = null; $_wpdb = null;
if ($results) { if ($results) {
foreach ($results as $result) { foreach ($results as $result) {
if ($result->name == $index_name) { if ($result->name == $index_name) {
$r = rand(0, 50); $r = rand(0, 50);
$index_name = $index_name . "_$r"; $index_name = $index_name . "_$r";
break; break;
} }
} }
} }
$index_name = str_replace(' ', '', $index_name); $index_name = str_replace(' ', '', $index_name);
$this->index_queries[] = "CREATE UNIQUE INDEX $index_name ON " . $tbl_name .$col_name; $this->index_queries[] = "CREATE UNIQUE INDEX $index_name ON " . $tbl_name .$col_name;
return ''; return '';
@ -296,24 +296,24 @@ class CreateQuery{
* @access private * @access private
*/ */
private function _rewrite_key($matches){ private function _rewrite_key($matches){
$index_name = trim($matches[2]); $index_name = trim($matches[2]);
$col_name = trim($matches[3]); $col_name = trim($matches[3]);
if (preg_match('/\([0-9]+?\)/', $col_name, $match)) { if (preg_match('/\([0-9]+?\)/', $col_name, $match)) {
$col_name = preg_replace_callback('/\([0-9]+?\)/', array($this, '_remove_length'), $col_name); $col_name = preg_replace_callback('/\([0-9]+?\)/', array($this, '_remove_length'), $col_name);
} }
$tbl_name = $this->table_name; $tbl_name = $this->table_name;
$_wpdb = new PDODB(); $_wpdb = new PDODB();
$results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'"); $results = $_wpdb->get_results("SELECT name FROM sqlite_master WHERE type='index'");
$_wpdb = null; $_wpdb = null;
if ($results) { if ($results) {
foreach ($results as $result) { foreach ($results as $result) {
if ($result->name == $index_name) { if ($result->name == $index_name) {
$r = rand(0, 50); $r = rand(0, 50);
$index_name = $index_name . "_$r"; $index_name = $index_name . "_$r";
break; break;
} }
} }
} }
$this->index_queries[] = 'CREATE INDEX '. $index_name . ' ON ' . $tbl_name . $col_name ; $this->index_queries[] = 'CREATE INDEX '. $index_name . ' ON ' . $tbl_name . $col_name ;
return ''; return '';
} }
@ -327,7 +327,7 @@ class CreateQuery{
* @access private * @access private
*/ */
private function _remove_length($match) { private function _remove_length($match) {
return ''; return '';
} }
/** /**
* Method to assemble the main query and index queries into an array. * Method to assemble the main query and index queries into an array.
@ -337,19 +337,19 @@ class CreateQuery{
* @return array * @return array
* @access private * @access private
*/ */
private function post_process(){ private function post_process() {
$mainquery = $this->_query; $mainquery = $this->_query;
do{ do{
$count = 0; $count = 0;
$mainquery = preg_replace('/,\\s*\)/imsx',')', $mainquery, -1, $count); $mainquery = preg_replace('/,\\s*\)/imsx',')', $mainquery, -1, $count);
} while ($count > 0); } while ($count > 0);
do { do {
$count = 0; $count = 0;
$mainquery = preg_replace('/\(\\s*?,/imsx', '(', $mainquery, -1, $count); $mainquery = preg_replace('/\(\\s*?,/imsx', '(', $mainquery, -1, $count);
} while ($count > 0); } while ($count > 0);
$return_val[] = $mainquery; $return_val[] = $mainquery;
$return_val = array_merge($return_val, $this->index_queries); $return_val = array_merge($return_val, $this->index_queries);
return $return_val; return $return_val;
} }
/** /**
* Method to add IF NOT EXISTS to query string. * Method to add IF NOT EXISTS to query string.
@ -364,7 +364,7 @@ class CreateQuery{
$this->_query = preg_replace($pattern_table, 'CREATE $1 TABLE IF NOT EXISTS ', $this->_query); $this->_query = preg_replace($pattern_table, 'CREATE $1 TABLE IF NOT EXISTS ', $this->_query);
$pattern_index = '/^\\s*CREATE\\s*(UNIQUE)?\\s*INDEX\\s*(IF NOT EXISTS)?\\s*/ims'; $pattern_index = '/^\\s*CREATE\\s*(UNIQUE)?\\s*INDEX\\s*(IF NOT EXISTS)?\\s*/ims';
for ($i = 0; $i < count($this->index_queries); $i++) { for ($i = 0; $i < count($this->index_queries); $i++) {
$this->index_queries[$i] = preg_replace($pattern_index, 'CREATE $1 INDEX IF NOT EXISTS ', $this->index_queries[$i]); $this->index_queries[$i] = preg_replace($pattern_index, 'CREATE $1 INDEX IF NOT EXISTS ', $this->index_queries[$i]);
} }
} }
/** /**
@ -374,9 +374,9 @@ class CreateQuery{
*/ */
private function strip_backticks(){ private function strip_backticks(){
$this->_query = str_replace('`', '', $this->_query); $this->_query = str_replace('`', '', $this->_query);
foreach ($this->index_queries as &$query) { foreach ($this->index_queries as &$query) {
$query = str_replace('`', '', $query); $query = str_replace('`', '', $query);
} }
} }
/** /**
* Method to remove the character set information from within mysql queries. * Method to remove the character set information from within mysql queries.
@ -389,8 +389,8 @@ class CreateQuery{
private function rewrite_character_set(){ private function rewrite_character_set(){
$pattern_charset = '/\\b(default\\s*character\\s*set|default\\s*charset|character\\s*set)\\s*(?<!\()[^ ]*/im'; $pattern_charset = '/\\b(default\\s*character\\s*set|default\\s*charset|character\\s*set)\\s*(?<!\()[^ ]*/im';
$pattern_collate1 = '/\\s*collate\\s*[^ ]*(?=,)/im'; $pattern_collate1 = '/\\s*collate\\s*[^ ]*(?=,)/im';
$pattern_collate2 = '/\\s*collate\\s*[^ ]*(?<!;)/im'; $pattern_collate2 = '/\\s*collate\\s*[^ ]*(?<!;)/im';
$patterns = array($pattern_charset, $pattern_collate1, $pattern_collate2); $patterns = array($pattern_charset, $pattern_collate1, $pattern_collate2);
$this->_query = preg_replace($patterns, '', $this->_query); $this->_query = preg_replace($patterns, '', $this->_query);
} }
} }

View File

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

View File

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

View File

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

View File

@ -15,137 +15,137 @@ class SQLiteIntegrationDocument {
* Method to display the document page. * Method to display the document page.
* *
*/ */
function show_doc() { function show_doc() {
// textdomain is defined in the utils class // textdomain is defined in the utils class
global $utils; global $utils;
$domain = $utils->text_domain; $domain = $utils->text_domain;
if (is_multisite() && !current_user_can('manage_network_options')) { if (is_multisite() && !current_user_can('manage_network_options')) {
die(__('You are not allowed to access this page!', $domain)); die(__('You are not allowed to access this page!', $domain));
} elseif (!current_user_can('manage_options')) { } elseif (!current_user_can('manage_options')) {
die(__('You are not allowed to access this page!', $domain)); die(__('You are not allowed to access this page!', $domain));
} }
if (isset($_GET['page']) && $_GET['page'] == 'doc') :?> if (isset($_GET['page']) && $_GET['page'] == 'doc') :?>
<div class="navigation"> <div class="navigation">
<ul class="navi-menu"> <ul class="navi-menu">
<li class="menu-selected"><?php _e('Documentation', $domain);?></li> <li class="menu-selected"><?php _e('Documentation', $domain);?></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain); ?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain); ?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></li> <li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></li>
</ul> </ul>
</div> </div>
<div class="wrap" id="sqlite-admin-wrap"> <div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Documentation', $domain); ?></h2> <h2><?php _e('Documentation', $domain); ?></h2>
<p> <p>
<?php _e('This is a brief documentation about this plugin. For more details, see also the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration/">SQLite Integration page</a>.', $domain);?> <?php _e('This is a brief documentation about this plugin. For more details, see also the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration/">SQLite Integration page</a>.', $domain);?>
</p> </p>
<p> <p>
<?php _e('Please don\'t forget: WordPress DOES NOT OFFICIALLY SUPPORT any database other than MySQL. So if you ask about this plugin in the Forum, it\'s not unlikely that you won\'t get no answers at all.', $domain);?> <?php _e('Please don\'t forget: WordPress DOES NOT OFFICIALLY SUPPORT any database other than MySQL. So if you ask about this plugin in the Forum, it\'s not unlikely that you won\'t get no answers at all.', $domain);?>
</p> </p>
<h3><?php _e('Features', $domain);?></h3> <h3><?php _e('Features', $domain);?></h3>
<p> <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); ?> <?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>
<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); ?> <?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>
<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);?> <?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>
<p> <p>
<?php _e('SQLite Integration does the work as follows:', $domain); ?> <?php _e('SQLite Integration does the work as follows:', $domain); ?>
</p> </p>
<ol> <ol>
<li><?php _e('Intercepts SQL statement for MySQL from WordPress', $domain); ?></li> <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('Rewrites it as SQLite can execute', $domain); ?></li>
<li><?php _e('Gives it to SQLite', $domain); ?></li> <li><?php _e('Gives it to SQLite', $domain); ?></li>
<li><?php _e('Gets the results from 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('Format the results as MySQL returns, if necessary', $domain);?></li>
<li><?php _e('Gives back the results to WordPress', $domain); ?></li> <li><?php _e('Gives back the results to WordPress', $domain); ?></li>
</ol> </ol>
<p> <p>
<?php _e('WordPress doesn\'t know what has happened in the background and will be happy with it.', $domain);?> <?php _e('WordPress doesn\'t know what has happened in the background and will be happy with it.', $domain);?>
</p> </p>
<h3><?php _e('Limitations', $domain);?></h3> <h3><?php _e('Limitations', $domain);?></h3>
<p> <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); ?> <?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> </p>
<ol> <ol>
<li><strong><?php _e('There are some plugins that you can\'t use. No way around.<br />', $domain);?></strong> <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> <?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> <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> <?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> </ol>
<p> <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);?> <?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> </p>
<h3><?php _e('User Defined Functions', $domain); ?></h3> <h3><?php _e('User Defined Functions', $domain); ?></h3>
<p> <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); ?> <?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>
<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);?> <?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> </p>
<h3><?php _e('Database Administration and Maintenance', $domain);?></h3> <h3><?php _e('Database Administration and Maintenance', $domain);?></h3>
<p> <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);?> <?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> </p>
<ul class="in-body-list"> <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="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> <li><a href="http://www.sqlitemanager.org/">SQLiteManager</a>(<?php _e('unfortunately seems not to maintained...', $domain); ?>)</li>
</ul> </ul>
<p> <p>
<?php _e('I\'m not sure if future release may have some of the database maintenance functionality.', $domain);?> <?php _e('I\'m not sure if future release may have some of the database maintenance functionality.', $domain);?>
</p> </p>
</div> </div>
<div class="wrap" id="sqlite-admin-side-wrap"> <div class="wrap" id="sqlite-admin-side-wrap">
<h2><?php _e('Plugin Compatibility/Incompatibility', $domain);?></h2> <h2><?php _e('Plugin Compatibility/Incompatibility', $domain);?></h2>
<p> <p>
<?php _e('WordPress without its plugins is a king without people. Of course, you need plugins, I know.', $domain);?> <?php _e('WordPress without its plugins is a king without people. Of course, you need plugins, I know.', $domain);?>
</p> </p>
<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());?> <?php echo sprintf(__('This is the list of the problematic plugins (far from complete). You can see informations about your installed plugins in the <a href="%s?page=sys-info">System Info</a> page. To see more details, please visit the <a href="http://dogwood.skr.jp/wordpress/sqlite-integration">Plugin Page</a>.', $domain), $utils->show_parent());?>
</p> </p>
<table class="widefat page fixed" id="plugins-table"> <table class="widefat page fixed" id="plugins-table">
<thead> <thead>
<tr> <tr>
<th data-sort='{"key":"name"}' class="item"><?php _e('Plugins Name', $domain); ?></th> <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":"compat"}' class="compat"><?php _e('Compatibility', $domain); ?></th>
<th data-sort='{"key":"reason"}' class="reason"><?php _e('Reasons', $domain);?></th> <th data-sort='{"key":"reason"}' class="reason"><?php _e('Reasons', $domain);?></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php <?php
if (file_exists(SQLiteListFile)) :?> if (file_exists(SQLiteListFile)) :?>
<?php <?php
$contents = file_get_contents(SQLiteListFile); $contents = file_get_contents(SQLiteListFile);
$plugin_info_list = json_decode($contents); $plugin_info_list = json_decode($contents);
foreach ($plugin_info_list as $plugin_info) :?> foreach ($plugin_info_list as $plugin_info) :?>
<?php if (in_array($plugin_info->compat, array('No', 'Probably No', 'Needs Patch'))) :?> <?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;?>"}'> <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> <td><?php echo $plugin_info->name;?></a></td>
<?php if (stripos($plugin_info->compat, 'patch') !== false) :?> <?php if (stripos($plugin_info->compat, 'patch') !== false) :?>
<td><a href="<?php echo $plugin_info->patch_url;?>"><?php _e('Needs Patch', $domain);?></a></td> <td><a href="<?php echo $plugin_info->patch_url;?>"><?php _e('Needs Patch', $domain);?></a></td>
<?php elseif (stripos($plugin_info->compat, 'probably no')) :?> <?php elseif (stripos($plugin_info->compat, 'probably no')) :?>
<td><?php _e('Probably No', $domain);?></td> <td><?php _e('Probably No', $domain);?></td>
<?php else :?> <?php else :?>
<td><?php _e('No', $domain);?></td> <td><?php _e('No', $domain);?></td>
<?php endif;?> <?php endif;?>
<td><?php echo $plugin_info->reason;?></td> <td><?php echo $plugin_info->reason;?></td>
</tr> </tr>
<?php endif;?> <?php endif;?>
<?php endforeach;?> <?php endforeach;?>
<?php endif;?> <?php endif;?>
</tbody> </tbody>
</table> </table>
</div> </div>
<?php endif; <?php endif;
} }
} }
?> ?>

View File

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

File diff suppressed because it is too large Load Diff