first release

git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@737264 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
kjmtsh 2013-07-07 06:49:38 +00:00
parent 290bd89db5
commit e8312985a2
24 changed files with 8174 additions and 0 deletions

96
db.php Normal file
View File

@ -0,0 +1,96 @@
<?php
/**
* This file must be placed in the directory
*
* wordpress/wp-content/db.php
*
* @package SQLite Integration
* @version 1.0
* @author Kojima Toshiyasu, Justin Adie
*
*/
function pdo_log_erro($message, $data = null) {
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">
<head>
<title>WordPress &rsaquo; Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="{$admin_dir}install.css" type="text/css" />
</head>
<body>
<h1 id="logo"><img alt="WordPress" src="{$admin_dir}images/wordpress-logo.png" /></h1>
<p>$message</p>
<p>$data</p>
</body>
<html>
HTML
);
}
if (version_compare( PHP_VERSION, '5.2.4', '<')) {
pdo_log_erro(__('PHP version on this server is too old.'), sprinf(__("Your server is running PHP version %d but this version of WordPress requires at least 5.2.4"), phpversion()));
}
if (!extension_loaded('pdo')) {
pdo_log_erro(__('PHP PDO Extension is not loaded.'), __('Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress.'));
}
if (!extension_loaded('pdo_sqlite')) {
pdo_log_erro(__('PDO Driver for SQLite is missing.'), __('Your PHP installtion appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.'));
}
/**
* Notice:
* Your scripts have the permission to create directories or files on your server.
* If you write in your wp-config.php like below, we take these definitions.
* define('DB_DIR', '/full_path_to_the_database_directory/');
* define('DB_FILE', 'database_file_name');
*/
if (defined('WP_PLUGIN_DIR')) {
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('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('DB_FILE' )) {
define('FQDB', FQDBDIR . DB_FILE);
} else {
define('FQDB', FQDBDIR . '.ht.sqlite');
}
if (version_compare(PHP_VERSION, '5.3', '<')) {
define('UDF_FILE', PDODIR . 'functions-5-2.php');
} elseif (version_compare(PHP_VERSION, '5.3', '>=')) {
define('UDF_FILE', PDODIR . 'functions.php');
}
require_once PDODIR . 'pdodb.class.php';
?>

370
functions-5-2.php Normal file
View File

@ -0,0 +1,370 @@
<?php
/**
* @package SQLite Integration
* @version 1.0
* @author Kojima Toshiyasu, Justin Adie
*
*/
/**
* This class defines user defined functions(UDFs) for PDO
* This replaces the functions used in the SQL statement with the PHP functions.
* If you want another, add the name in the array and define the function with
* PHP script.
*/
class PDOSQLiteUDFS {
public function __construct(&$pdo){
foreach ($this->functions as $f=>$t) {
$pdo->sqliteCreateFunction($f, array($this, $t));
}
}
private $functions = array(
'month' => 'month',
'year' => 'year',
'day' => 'day',
'unix_timestamp' => 'unix_timestamp',
'now' => 'now',
'char_length' => 'char_length',
'md5' => 'md5',
'curdate' => 'curdate',
'rand' => 'rand',
'substring' => 'substring',
'dayofmonth' => 'day',
'second' => 'second',
'minute' => 'minute',
'hour' => 'hour',
'date_format' => 'dateformat',
'from_unixtime' => 'from_unixtime',
'date_add' => 'date_add',
'date_sub' => 'date_sub',
'adddate' => 'date_add',
'subdate' => 'date_sub',
'localtime' => 'now',
'localtimestamp' => 'now',
//'date'=>'date',
'isnull' => 'isnull',
'if' => '_if',
'regexpp' => 'regexp',
'concat' => 'concat',
'field' => 'field',
'log' => 'log',
'least' => 'least',
'get_lock' => 'get_lock',
'release_lock' => 'release_lock',
'ucase' => 'ucase',
'lcase' => 'lcase',
'inet_ntoa' => 'inet_ntoa',
'inet_aton' => 'inet_aton',
'datediff' => 'datediff'
);
public function month($field){
$t = strtotime($field);
return date('n', $t);
}
public function year($field){
$t = strtotime($field);
return date('Y', $t);
}
public function day($field){
$t = strtotime($field);
return date('j', $t);
}
public function unix_timestamp($field = null){
return is_null($field) ? time() : strtotime($field);
}
public function second($field){
$t = strtotime($field);
return intval( date("s", $t) );
}
public function minute($field){
$t = strtotime($field);
return intval(date("i", $t));
}
public function hour($time){
list($hours, $minutes, $seconds) = explode(":", $time);
return intval($hours);
}
public function from_unixtime($field, $format=null){
// $field is a timestamp
//convert to ISO time
$date = date("Y-m-d H:i:s", $field);
//now submit to dateformat
return is_null($format) ? $date : $self->dateformat($date, $format);
}
public function now(){
return date("Y-m-d H:i:s");
}
public function curdate() {
return date("Y-m-d");
}
public function char_length($field){
return strlen($field);
}
public function md5($field){
return md5($field);
}
public function rand(){
return rand(0,1);
}
public function substring($text, $pos, $len=null){
if (is_null($len)) return substr($text, $pos-1);
else return substr($text, $pos-1, $len);
}
public function dateformat($date, $format){
$mysql_php_dateformats = array ( '%a' => 'D', '%b' => 'M', '%c' => 'n', '%D' => 'jS', '%d' => 'd', '%e' => 'j', '%H' => 'H', '%h' => 'h', '%I' => 'h', '%i' => 'i', '%j' => 'z', '%k' => 'G', '%l' => 'g', '%M' => 'F', '%m' => 'm', '%p' => 'A', '%r' => 'h:i:s A', '%S' => 's', '%s' => 's', '%T' => 'H:i:s', '%U' => 'W', '%u' => 'W', '%V' => 'W', '%v' => 'W', '%W' => 'l', '%w' => 'w', '%X' => 'Y', '%x' => 'o', '%Y' => 'Y', '%y' => 'y', );
$t = strtotime($date);
$format = strtr($format, $mysql_php_dateformats);
$output = date($format, $t);
return $output;
}
public function date_add($date, $interval) {
$interval = $this->deriveInterval($interval);
switch (strtolower($date)) {
case "curdate()":
$objDate = new Datetime($this->curdate());
$objDate->add(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d");
break;
case "now()":
$objDate = new Datetime($this->now());
$objDate->add(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d H:i:s");
break;
default:
$objDate = new Datetime($date);
$objDate->add(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d H:i:s");
}
return $returnval;
}
public function date_sub($date, $interval) {
$interval = $this->deriveInterval($interval);
switch (strtolower($date)) {
case "curdate()":
$objDate = new Datetime($this->curdate());
$objDate->sub(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d");
break;
case "now()":
$objDate = new Datetime($this->now());
$objDate->sub(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d H:i:s");
break;
default:
$objDate = new Datetime($date);
$objDate->sub(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d H:i:s");
}
return $returnval;
}
private function deriveInterval($interval){
$interval = trim(substr(trim($interval), 8));
$parts = explode(' ', $interval);
foreach($parts as $part){
if (!empty($part)){
$_parts[] = $part;
}
}
$type = strtolower(end($_parts));
switch ($type){
case "second":
case "minute":
case "hour":
case "day":
case "week":
case "month":
case "year":
if (intval($_parts[0]) > 1){
$type .= 's';
}
return "$_parts[0] $_parts[1]";
break;
case "minute_second":
list($minutes, $seconds) = explode (':', $_parts[0]);
$minutes = intval($minutes);
$seconds = intval($seconds);
$minutes = ($minutes > 1) ? "$minutes minutes" : "$minutes minute";
$seconds = ($seconds > 1) ? "$seconds seconds" : "$seconds second";
return "$minutes $seconds";
break;
case "hour_second":
list($hours, $minutes, $seconds) = explode (':', $_parts[0]);
$hours = intval($hours);
$minutes = intval($minutes);
$seconds = intval($seconds);
$hours = ($hours > 1) ? "$hours hours" : "$hours hour";
$minutes = ($minutes > 1) ? "$minutes minutes" : "$minutes minute";
$seconds = ($seconds > 1) ? "$seconds seconds" : "$seconds second";
return "$hours $minutes $seconds";
break;
case "hour_minute":
list($hours, $minutes) = explode (':', $_parts[0]);
$hours = intval($hours);
$minutes = intval($minutes);
$hours = ($hours > 1) ? "$hours hours" : "$hours hour";
$minutes = ($minutes > 1) ? "$minutes minutes" : "$minutes minute";
return "$hours $minutes";
break;
case "day_second":
$days = intval($_parts[0]);
list($hours, $minutes, $seconds) = explode (':', $_parts[1]);
$hours = intval($hours);
$minutes = intval($minutes);
$seconds = intval($seconds);
$days = $days > 1 ? "$days days" : "$days day";
$hours = ($hours > 1) ? "$hours hours" : "$hours hour";
$minutes = ($minutes > 1) ? "$minutes minutes" : "$minutes minute";
$seconds = ($seconds > 1) ? "$seconds seconds" : "$seconds second";
return "$days $hours $minutes $seconds";
break;
case "day_minute":
$days = intval($_parts[0]);
list($hours, $minutes) = explode (':', $_parts[1]);
$hours = intval($hours);
$minutes = intval($minutes);
$days = $days > 1 ? "$days days" : "$days day";
$hours = ($hours > 1) ? "$hours hours" : "$hours hour";
$minutes = ($minutes > 1) ? "$minutes minutes" : "$minutes minute";
return "$days $hours $minutes";
break;
case "day_hour":
$days = intval($_parts[0]);
$hours = intval($_parts[1]);
$days = $days > 1 ? "$days days" : "$days day";
$hours = ($hours > 1) ? "$hours hours" : "$hours hour";
return "$days $hours";
break;
case "year_month":
list($years, $months) = explode ('-', $_parts[0]);
$years = intval($years);
$months = intval($months);
$years = ($years > 1) ? "$years years" : "$years year";
$months = ($months > 1) ? "$months months": "$months month";
return "$years $months";
break;
default:
return false;
}
}
public function date($date){
return date("Y-m-d", strtotime($date));
}
public function isnull($field){
return is_null($field);
}
public function _if($expression, $true, $false){
return ($expression == true) ? $true : $false;
}
public function regexp($field, $pattern){
$pattern = str_replace('/', '\/', $pattern);
$pattern = "/" . $pattern ."/i";
return preg_match ($pattern, $field);
}
public function concat() {
$returnValue = "";
$argsNum = func_num_args();
$argsList = func_get_args();
for ($i = 0; $i < $argsNum; $i++) {
if (is_null($argsList[$i])) {
return null;
}
$returnValue .= $argsList[$i];
}
return $returnValue;
}
public function field() {
$numArgs = func_num_args();
if ($numArgs < 2 or is_null(func_get_arg(0))) {
return null;
}
$arr = func_get_args();
$searchString = strtolower(array_shift($arr));
for ($i = 0; $i < $numArgs-1; $i++) {
if ($searchString === strtolower($arr[$i])) return $i + 1;
}
return null;
}
public function log() {
$numArgs = func_num_args();
if ($numArgs == 1) {
$arg1 = func_get_arg(0);
return log($arg1);
} else if ($numArgs == 2) {
$arg1 = func_get_arg(0);
$arg2 = func_get_arg(1);
return log($arg1)/log($arg2);
} else {
return false;
}
}
public function least() {
$arr = func_get_args();
return min($arr);
}
/**
* These two functions are meaningless in SQLite
* So we return meaningless statement and do nothing
* @param string $name
* @param integer $timeout
* @return string
*/
public function get_lock($name, $timeout) {
return '1=1';
}
public function release_lock($name) {
return '1=1';
}
/**
* MySQL aliases for upper and lower functions
* @param unknown $string
* @return string
*/
public function ucase($string) {
return "upper($string)";
}
public function lcase($string) {
return "lower($string)";
}
/**
* MySQL aliases for INET_NTOA and INET_ATON functions
* @param unsigned integer, string respectively
* @return string, unsigned integer respectively
*/
public function inet_ntoa($num) {
return long2ip($num);
}
public function inet_aton($addr) {
$int_data = ip2long($addr);
$unsigned_int_data = sprintf('%u', $address);
return $unsigned_int_data;
}
/**
* MySQL aliase for DATEDIFF function
* @param string, string
* @return string
*/
public function datediff($start, $end) {
$start_date = strtotime($start);
$end_date = strtotime($end);
$interval = floor(($end_date - $start_date)/(3600*24));
return $interval;
}
}
?>

344
functions.php Normal file
View File

@ -0,0 +1,344 @@
<?php
/**
* @package SQLite Integration
* @version 1.0
* @author Kojima Toshiyasu, Justin Adie
*
*/
/**
* This class defines user defined functions(UDFs) for PDO
* This replaces the functions used in the SQL statement with the PHP functions.
* If you want another, add the name in the array and define the function with
* PHP script.
*/
class PDOSQLiteUDFS {
public function __construct(&$pdo){
foreach ($this->functions as $f=>$t) {
$pdo->sqliteCreateFunction($f, array($this, $t));
}
}
private $functions = array(
'month' => 'month',
'year' => 'year',
'day' => 'day',
'unix_timestamp' => 'unix_timestamp',
'now' => 'now',
'char_length' => 'char_length',
'md5' => 'md5',
'curdate' => 'curdate',
'rand' => 'rand',
'substring' => 'substring',
'dayofmonth' => 'day',
'second' => 'second',
'minute' => 'minute',
'hour' => 'hour',
'date_format' => 'dateformat',
'from_unixtime' => 'from_unixtime',
'date_add' => 'date_add',
'date_sub' => 'date_sub',
'adddate' => 'date_add',
'subdate' => 'date_sub',
'localtime' => 'now',
'localtimestamp' => 'now',
//'date'=>'date',
'isnull' => 'isnull',
'if' => '_if',
'regexpp' => 'regexp',
'concat' => 'concat',
'field' => 'field',
'log' => 'log',
'least' => 'least',
'replace' => 'replace',
'get_lock' => 'get_lock',
'release_lock' => 'release_lock',
'ucase' => 'ucase',
'lcase' => 'lcase',
'inet_ntoa' => 'inet_ntoa',
'inet_aton' => 'inet_aton',
'datediff' => 'datediff'
);
public function month($field){
$t = strtotime($field);
return date('n', $t);
}
public function year($field){
$t = strtotime($field);
return date('Y', $t);
}
public function day($field){
$t = strtotime($field);
return date('j', $t);
}
public function unix_timestamp($field = null){
return is_null($field) ? time() : strtotime($field);
}
public function second($field){
$t = strtotime($field);
return intval( date("s", $t) );
}
public function minute($field){
$t = strtotime($field);
return intval(date("i", $t));
}
public function hour($time){
list($hours, $minutes, $seconds) = explode(":", $time);
return intval($hours);
}
public function from_unixtime($field, $format=null){
// $field is a timestamp
//convert to ISO time
$date = date("Y-m-d H:i:s", $field);
//now submit to dateformat
return is_null($format) ? $date : $self->dateformat($date, $format);
}
public function now(){
return date("Y-m-d H:i:s");
}
public function curdate() {
return date("Y-m-d");
}
public function char_length($field){
return strlen($field);
}
public function md5($field){
return md5($field);
}
public function rand(){
return rand(0,1);
}
public function substring($text, $pos, $len=null){
if (is_null($len)) return substr($text, $pos-1);
else return substr($text, $pos-1, $len);
}
public function dateformat($date, $format){
$mysql_php_dateformats = array ( '%a' => 'D', '%b' => 'M', '%c' => 'n', '%D' => 'jS', '%d' => 'd', '%e' => 'j', '%H' => 'H', '%h' => 'h', '%I' => 'h', '%i' => 'i', '%j' => 'z', '%k' => 'G', '%l' => 'g', '%M' => 'F', '%m' => 'm', '%p' => 'A', '%r' => 'h:i:s A', '%S' => 's', '%s' => 's', '%T' => 'H:i:s', '%U' => 'W', '%u' => 'W', '%V' => 'W', '%v' => 'W', '%W' => 'l', '%w' => 'w', '%X' => 'Y', '%x' => 'o', '%Y' => 'Y', '%y' => 'y', );
$t = strtotime($date);
$format = strtr($format, $mysql_php_dateformats);
$output = date($format, $t);
return $output;
}
public function date_add($date, $interval) {
$interval = $this->deriveInterval($interval);
switch (strtolower($date)) {
case "curdate()":
$objDate = new Datetime($this->curdate());
$objDate->add(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d");
break;
case "now()":
$objDate = new Datetime($this->now());
$objDate->add(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d H:i:s");
break;
default:
$objDate = new Datetime($date);
$objDate->add(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d H:i:s");
}
return $returnval;
}
public function date_sub($date, $interval) {
$interval = $this->deriveInterval($interval);
switch (strtolower($date)) {
case "curdate()":
$objDate = new Datetime($this->curdate());
$objDate->sub(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d");
break;
case "now()":
$objDate = new Datetime($this->now());
$objDate->sub(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d H:i:s");
break;
default:
$objDate = new Datetime($date);
$objDate->sub(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d H:i:s");
}
return $returnval;
}
private function deriveInterval($interval) {
$interval = trim(substr(trim($interval), 8));
$parts = explode(' ', $interval);
foreach ($parts as $part) {
if (!empty($part)) {
$_parts[] = $part;
}
}
$type = strtolower(end($_parts));
switch ($type) {
case "second": $unit = 'S'; return 'PT' . $_parts[0] . $unit; break;
case "minute": $unit = 'M'; return 'PT' . $_parts[0] . $unit; break;
case "hour": $unit = 'H'; return 'PT' . $_parts[0] . $unit; break;
case "day": $unit = 'D'; return 'P' . $_parts[0] . $unit; break;
case "week": $unit = 'W'; return 'P' . $_parts[0] . $unit; break;
case "month": $unit = 'M'; return 'P' . $_parts[0] . $unit; break;
case "year": $unit = 'Y'; return 'P' . $_parts[0] . $unit; break;
case "minute_second":
list($minutes, $seconds) = explode(':', $_parts[0]);
return 'PT' . $minutes . 'M' . $seconds . 'S';
break;
case "hour_second":
list($hours, $minutes, $seconds) = explode (':', $_parts[0]);
return 'PT' . $hours . 'H' . $minutes . 'M' . $seconds . 'S';
break;
case "hour_minute":
list($hours, $minutes) = explode (':', $_parts[0]);
return 'PT' . $hours . 'H' . $minutes . 'M';
break;
case "day_second":
$days = intval($_parts[0]);
list($hours, $minutes, $seconds) = explode (':', $_parts[1]);
return 'P' . $days . 'D' . 'T' . $hours . 'H' . $minutes . 'M' . $seconds . 'S';
break;
case "day_minute":
$days = intval($_parts[0]);
list($hours, $minutes) = explode(':', $parts[1]);
return 'P' . $days . 'D' . 'T' . $hours . 'H' . $minutes . 'M';
break;
case "day_hour":
$days = intval($_parts[0]);
$hours = intval($_parts[1]);
return 'P' . $days . 'D' . 'T' . $hours . 'H';
break;
case "year_month":
list($years, $months) = explode ('-', $_parts[0]);
return 'P' . $years . 'Y' . $months . 'M';
break;
}
}
public function date($date){
return date("Y-m-d", strtotime($date));
}
public function isnull($field){
return is_null($field);
}
public function _if($expression, $true, $false){
return ($expression == true) ? $true : $false;
}
public function regexp($field, $pattern){
$pattern = str_replace('/', '\/', $pattern);
$pattern = "/" . $pattern ."/i";
return preg_match ($pattern, $field);
}
public function concat() {
$returnValue = "";
$argsNum = func_num_args();
$argsList = func_get_args();
for ($i = 0; $i < $argsNum; $i++) {
if (is_null($argsList[$i])) {
return null;
}
$returnValue .= $argsList[$i];
}
return $returnValue;
}
public function field() {
$numArgs = func_num_args();
if ($numArgs < 2 or is_null(func_get_arg(0))) {
return null;
}
$arr = func_get_args();
$searchString = strtolower(array_shift($arr));
for ($i = 0; $i < $numArgs-1; $i++) {
if ($searchString === strtolower($arr[$i])) return $i + 1;
}
return null;
}
public function log() {
$numArgs = func_num_args();
if ($numArgs == 1) {
$arg1 = func_get_arg(0);
return log($arg1);
} else if ($numArgs == 2) {
$arg1 = func_get_arg(0);
$arg2 = func_get_arg(1);
return log($arg1)/log($arg2);
} else {
return false;
}
}
public function least() {
$arr = func_get_args();
return min($arr);
}
public function replace($haystack, $needle, $replace) {
return str_replace($needle, $replace, $haystack);
}
/**
* These two functions are meaningless in SQLite
* So we return meaningless statement and do nothing
* @param string $name
* @param integer $timeout
* @return string
*/
public function get_lock($name, $timeout) {
return '1=1';
}
public function release_lock($name) {
return '1=1';
}
/**
* MySQL aliases for upper and lower functions
* @param $string
* @return string
*/
public function ucase($string) {
return "upper($string)";
}
public function lcase($string) {
return "lower($string)";
}
/**
* MySQL aliases for INET_NTOA and INET_ATON functions
* @param unsigned integer, string respectively
* @return string, unsigned integer respectively
*/
public function inet_ntoa($num) {
return long2ip($num);
}
public function inet_aton($addr) {
$int_data = ip2long($addr);
$unsigned_int_data = sprintf('%u', $address);
return $unsigned_int_data;
}
/**
* MySQL aliase for DATEDIFF function
* @param string, string
* @return string
*/
public function datediff($start, $end) {
/* PHP 5.3.2 has a serious bug in DateTime::diff()
* see https://bugs.php.net/bug.php?id=51184
*/
if (version_compare(PHP_VERSION, '5.3.2', '==')) {
$start_date = strtotime($start);
$end_date = strtotime($end);
$interval = floor(($start_date - $end_date)/(3600*24));
return $interval;
} else {
$start_date = new DateTime($start);
$end_date = new DateTime($end);
$interval = $end_date->diff($start_date, false);
return $interval->format('%r%a');
}
}
}
?>

63
install.php Normal file
View File

@ -0,0 +1,63 @@
<?php
/**
* @package SQLite Integration
* @version 1.0
* @author Kojima Toshiyasu, Justin Adie
*
*/
/**
* This function overrides wp_install() in wp-admin/upgrade.php
*/
function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') {
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);
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();
return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
}
?>

101
js/sqlite.js Normal file
View File

@ -0,0 +1,101 @@
/*
* script for SQLite Integration
* this file is only included on the documentation page and the utilities page
*/
jQuery(document).ready(function($) {
var $table = null;
var $headers = null;
if (document.getElementById("sqlite-table") != null) {
$table = $('#sqlite-table');
$headers = $table.find('thead th').slice(0,2);
} else if (document.getElementById("plugins-table") != null) {
$table = $('#plugins-table');
$headers = $table.find('thead th').slice(0);
} else if (document.getElementById("patch-files") != null) {
$table = $('#patch-files');
$headers = $table.find('thead th').slice(1);
}
$headers
.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;
if ($header.hasClass('sorted-asc')) {
sortDirection = -1;
}
rows.sort(function(a, b) {
var keyA = $(a).data('table')[sortKey];
var keyB = $(b).data('table')[sortKey];
if (keyA < keyB) return -sortDirection;
if (keyA > keyB) return sortDirection;
return 0;
});
$headers.removeClass('sorted-asc sortd-desc');
$headers.addClass(sortDirection == 1 ? 'sorted-asc' : 'sorted-desc');
$.each(rows, function(index, row) {
$table.children('tbody').append(row);
});
stripe('#plugins-table');
stripe('#sqlite-table');
stripe('#patch-files');
});
function stripe(arg) {
$(arg).find('tr.alt').removeClass('alt');
var $args = arg + ' tbody';
$($args).each(function() {
$(this).children(':visible').has('td').filter(function(index) {
return (index % 2) == 1;
}).addClass('alt');
});
}
stripe('#plugins-table');
stripe('#sys-info');
stripe('#sqlite-table');
stripe('#status');
stripe('#patch-files');
});
jQuery(document).ready(function($) {
var $table = $('#plugins-info');
var $headers = $table.find('thead th').slice(0);
$headers
.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;
if ($header.hasClass('sorted-asc')) {
sortDirection = -1;
}
rows.sort(function(a, b) {
var keyA = $(a).data('table')[sortKey];
var keyB = $(b).data('table')[sortKey];
if (keyA < keyB) return -sortDirection;
if (keyA > keyB) return sortDirection;
return 0;
});
$headers.removeClass('sorted-asc sortd-desc');
$headers.addClass(sortDirection == 1 ? 'sorted-asc' : 'sorted-desc');
$.each(rows, function(index, row) {
$table.children('tbody').append(row);
});
stripe('#plugins-info');
});
function stripe(arg) {
$(arg).find('tr.alt').removeClass('alt');
var $args = arg + ' tbody';
$($args).each(function() {
$(this).children(':visible').has('td').filter(function(index) {
return (index % 2) == 1;
}).addClass('alt');
});
}
stripe('#plugins-info');
});

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

240
pdodb.class.php Normal file
View File

@ -0,0 +1,240 @@
<?php
/**
* @package SQLite Integration
* @version 1.0
* @author Kojima Toshiyasu, Justin Adie
*
*/
require_once PDODIR . 'pdoengine.class.php';
require_once PDODIR . 'install.php';
if (!defined('SAVEQUERIES')){
define ('SAVEQUERIES', false);
}
if(!defined('PDO_DEBUG')){
define('PDO_DEBUG', false);
}
if (!isset($wpdb)){
global $wpdb;
$wpdb = 'somevar';
require_once ABSPATH . 'wp-includes/wp-db.php';
unset($wpdb);
}
/**
* This class extends wpdb and replaces it.
* It also rewrites some functions that use mysql specific functions.
*
*/
class PDODB extends wpdb {
protected $dbh = null;
/**
* Constructor: emulates wpdb but this gets another parameter $db_type,
* which is given by the constant 'DB_TYPE' defined in wp-config.php.
* SQLite uses only $db_type and all the others are simply ignored.
*
*/
function __construct() {
register_shutdown_function(array($this, '__destruct'));
if (WP_DEBUG)
$this->show_errors();
$this->init_charset();
$this->db_connect();
}
function __destruct() {
return true;
}
/**
* dummy out the MySQL function
* @see wpdb::select()
*/
function select($db, $dbh = null) {
if (is_null($dbh))
$dbh = $this->dbh;
$this->ready = true;
return;
}
/**
* overrides wpdb::_real_escape(), which uses mysql_real_escape_string().
* @see wpdb::_real_escape()
*/
function _real_escape($string) {
if ($this->dbh && $this->real_escape)
return $this->dbh->quote($string);
else
return addslashes($string);
}
/**
* overrides wpdb::print_error()
* @see wpdb::print_error()
*/
function print_error($str = '') {
global $EZSQL_ERROR;
if (!$str) {
$err = $this->dbh->get_error_message() ? $this->dbh->get_error_message() : '';
$str = $err[2];
}
$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>";
}
}
/**
* overrides wpdb::db_connect()
* @see wpdb::db_connect()
*/
function db_connect() {
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;
}
$this->ready = true;
}
/**
* overrides wpdb::query()
* @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;
}
/**
* overrides wpdb::load_col_info(), which uses a mysql function.
* @see wpdb::load_col_info()
*/
function load_col_info() {
if ($this->col_info)
return;
$this->col_info = $this->dbh->get_columns();
}
/**
* overrides wpdb::has_cap()
* We don't support collation, group_concat, 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;
}
}
/**
* overrides wpdb::db_version()
* Returns mysql version number but it means nothing for SQLite.
* @see wpdb::db_version()
*/
function db_version() {
global $required_mysql_version;
return $required_mysql_version;
}
}
/**
* Initialize $wpdb with PDODB class
*/
if (!isset($wpdb)) {
global $wpdb;
$wpdb = new PDODB();
}
?>

898
pdoengine.class.php Normal file
View File

@ -0,0 +1,898 @@
<?php
/**
* @package SQLite Integration
* @version 1.0
* @author Kojima Toshiyasu, Justin Adie
*
*/
/**
* This class does the real work
* accepts a request from wpdb class, initialize PDO instance,
* execute SQL statement, and returns the results to wpdb class.
*/
class PDOEngine extends PDO {
public $is_error = false;
public $found_rows_result;
private $rewritten_query;
private $query_type;
private $results = null;
private $_results = null;
private $pdo;
private $prepared_query;
private $extracted_variables = array();
private $error_messages = array();
private $errors;
public $queries = array();
private $last_insert_id;
private $affected_rows;
private $column_names;
private $num_rows;
private $return_value;
private $can_insert_multiple_rows = false;
private $param_num;
protected $has_active_transaction = false;
/**
* Constructor
* registers __destruct function and initialize the database environment
* @param array $DatabaseParams
*/
function __construct() {
register_shutdown_function(array($this, '__destruct'));
$this->init();
}
function __destruct() {
$this->pdo = null;
return true;
}
/**
* Function to initialize database
* checks if there's a database directory and database file, creates the tables,
* and binds the user defined function to the pdo object
* @return boolean
*/
private function init() {
$dsn = 'sqlite:' . FQDB;
$result = $this->prepare_directory();
if (!$result) return false;
if (is_file(FQDB)) {
$locked = false;
do {
try {
if ($locked) $locked = false;
$this->pdo = new PDO(
$dsn, // data source name
null, // user name
null, // user password
array( // PDO options
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
$statement = $this->pdo->query("SELECT COUNT(*) FROM sqlite_master WHERE type='table'");
$number_of_tables = $statement->fetchColumn(0);
$statement = null;
if ($number_of_tables == 0) {
$this->make_sqlite_tables();
}
} catch (PDOException $err) {
$status = $err->getCode();
// code 5 => The database file is locked
// code 6 => A table in the database is locked
if ($status == 5 || $status == 6) {
$locked = true;
} else {
$message = __("Database connection error!<br />", 'sqlite-integration');
$message .= sprintf(__("Error message is: ", 'sqlite-integration'), $err->getMessage());
$this->set_error(__LINE__, __FUNCTION__, $message);
return false;
}
}
} while ($locked);
require_once UDF_FILE;
new PDOSQLiteUDFS($this->pdo);
if (version_compare($this->get_sqlite_version(), '3.7.11', '>=')) {
$this->can_insert_multiple_rows = true;
}
} else { // database file is not found, so we make it and create tables...
try {
$this->pdo = new PDO($dsn, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch (PDOException $err) {
$message = __("Database connection error!<br />", 'sqlite-integration');
$message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err->getMessage());
$this->set_error(__LINE__, __FUNCTION__, $message);
return false;
}
$this->make_sqlite_tables();
}
}
/**
* Make database direcotry and .htaccess file
* executed once while installation process
*/
private function prepare_directory() {
global $wpdb;
$u = umask(0000);
if (!is_dir(FQDBDIR)) {
if (!@mkdir(FQDBDIR, 0777, true)) {
umask($u);
$message = __('Unable to create the required directory! Please check your server settings.', 'sqlite-integration');
echo $message;
return false;
}
}
if (!is_writable(FQDBDIR)) {
umask($u);
$message = __('Unable to create a file in the directory! Please check your server settings.', 'sqlite-integration');
echo $message;
return false;
}
if (!is_file(FQDBDIR . '.htaccess')) {
$fh = fopen(FQDBDIR . '.htaccess', "w");
if (!$fh) {
umask($u);
$message = __('Unable to create a file in the directory! Please check your server settings.', 'sqlite-integration');
echo $message;
return false;
}
fwrite($fh, "DENY FROM ALL");
fclose($fh);
}
umask($u);
return true;
}
/**
* Make database file itself and WordPress tables
* executed once while installation process
*/
private function make_sqlite_tables() {
require_once PDODIR . "install.php";
}
public function query($query) {
$this->flush();
$this->queries[] = "Raw query:\t$query";
$res = $this->determine_query_type($query);
if (!$res) {
$bailoutString = sprintf(__("<h1>Unknown query type</h1><p>Sorry, we cannot determine the type of query that is requested.</p><p>The query is %s</p>", 'sqlite-integration'), $query);
$this->set_error(__LINE__, __FUNCTION__, $bailoutString);
}
switch (strtolower($this->query_type)) {
case 'foundrows':
$this->results = $this->found_rows_result;
$this->num_rows = count($this->results);
$this->found_rows_result = null;
break;
case 'insert':
if ($this->can_insert_multiple_rows) {
$this->execute_insert_query_new($query);
} else {
$this->execute_insert_query($query);
}
break;
case 'create':
$result = $this->execute_create_query($query);
$this->return_value = $result;
break;
case 'alter':
$result = $this->execute_alter_query($query);
$this->return_value = $result;
break;
case 'show_variables':
$result = $this->show_variables_workaround($query);
break;
default:
$engine = $this->prepare_engine($this->query_type);
$this->rewritten_query = $engine->rewrite_query($query, $this->query_type);
$this->queries[] = "Rewritten: $this->rewritten_query";
$this->extract_variables();
$statement = $this->prepare_query();
$this->execute_query($statement);
if (!$this->is_error) {
$this->process_results($engine);
} else {// Error
;
}
break;
}
if (defined('PDO_DEBUG') && PDO_DEBUG === true) {
file_put_contents(FQDBDIR . 'debug.txt', $this->get_debug_info(), FLIE_APPEND);
}
return $this->return_value;
}
public function get_insert_id() {
return $this->last_insert_id;
}
public function get_affected_rows() {
return $this->affected_rows;
}
public function get_columns() {
return $this->column_names;
}
public function get_query_results() {
return $this->results;
}
public function get_num_rows() {
return $this->num_rows;
}
public function get_return_value() {
return $this->return_value;
}
public function get_error_message(){
if (count($this->error_messages) === 0){
$this->is_error = false;
$this->error_messages = array();
return '';
}
$output = '<div style="clear:both">&nbsp;</div>';
if ($this->is_error === false){
// return $output;
return '';
}
$output .= "<div class=\"queries\" style=\"clear:both; margin_bottom:2px; border: red dotted thin;\">Queries made or created this session were<br/>\r\n\t<ol>\r\n";
foreach ($this->queries as $q){
$output .= "\t\t<li>".$q."</li>\r\n";
}
$output .= "\t</ol>\r\n</div>";
foreach ($this->error_messages as $num=>$m){
$output .= "<div style=\"clear:both; margin_bottom:2px; border: red dotted thin;\" class=\"error_message\" style=\"border-bottom:dotted blue thin;\">Error occurred at line {$this->errors[$num]['line']} in Function {$this->errors[$num]['function']}. <br/> Error message was: $m </div>";
}
ob_start();
debug_print_backtrace();
$output .= "<pre>" . ob_get_contents() . "</pre>";
ob_end_clean();
return $output;
}
private function get_debug_info(){
$output = '';
foreach ($this->queries as $q){