change the algorithm for manipulating multiple meta query

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

63
db.php
View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff