CatPtain/wordpress
0
1<?php2/**3 * SQLite integration for WordPress4 * This file enables WordPress to use SQLite database instead of MySQL5 */6 7// Prevent direct access8if (!defined('ABSPATH')) {9 exit;10}11 12// Check if SQLite extension is available13if (!extension_loaded('pdo_sqlite')) {14 wp_die('SQLite PDO extension is not available. Please install php-sqlite3.');15}16 17// Define SQLite database path18if (!defined('DB_FILE')) {19 define('DB_FILE', ABSPATH . 'wp-content/database/wordpress.db');20}21 22// Create database directory if it doesn't exist23$db_dir = dirname(DB_FILE);24if (!file_exists($db_dir)) {25 wp_mkdir_p($db_dir);26}27 28/**29 * Custom database class for SQLite - WordPress wpdb compatible30 */31class SQLite_DB {32 public $pdo;33 public $last_error = '';34 public $error = '';35 public $insert_id = 0;36 public $num_rows = 0;37 public $last_query = '';38 public $last_result = null;39 public $prefix = 'wp_';40 41 // WordPress compatibility properties42 public $posts;43 public $users;44 public $options;45 public $postmeta;46 public $usermeta;47 public $terms;48 public $term_taxonomy;49 public $term_relationships;50 public $termmeta;51 public $comments;52 public $commentmeta;53 public $links;54 public $field_types = array();55 public $charset;56 public $collate;57 public $dbname;58 public $ready = false;59 public $suppress_errors = false;60 public $show_errors = true;61 public $time_start = 0;62 public $blogid = 1;63 public $base_prefix = 'wp_';64 65 public function __construct() {66 global $table_prefix;67 $this->prefix = isset($table_prefix) ? $table_prefix : 'wp_';68 $this->charset = 'utf8';69 $this->collate = '';70 $this->dbname = '/var/www/html/wp-content/database';71 $this->set_table_names();72 73 if ($this->connect()) {74 $this->ready = true;75 $this->base_prefix = $this->prefix;76 $this->timer_start();77 } else {78 $this->ready = false;79 // Don't bail here, let WordPress handle the connection error80 }81 }82 83 private function set_table_names() {84 $this->posts = $this->prefix . 'posts';85 $this->users = $this->prefix . 'users';86 $this->options = $this->prefix . 'options';87 $this->postmeta = $this->prefix . 'postmeta';88 $this->usermeta = $this->prefix . 'usermeta';89 $this->terms = $this->prefix . 'terms';90 $this->term_taxonomy = $this->prefix . 'term_taxonomy';91 $this->term_relationships = $this->prefix . 'term_relationships';92 $this->termmeta = $this->prefix . 'termmeta';93 $this->comments = $this->prefix . 'comments';94 $this->commentmeta = $this->prefix . 'commentmeta';95 $this->links = $this->prefix . 'links';96 }97 98 private function connect() {99 try {100 // Use in-memory SQLite database for Hugging Face Spaces101 // This avoids file permission issues and improves performance102 $this->pdo = new PDO('sqlite::memory:');103 $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);104 $this->pdo->exec('PRAGMA foreign_keys = ON');105 $this->pdo->exec('PRAGMA journal_mode = MEMORY');106 $this->pdo->exec('PRAGMA synchronous = OFF');107 $this->pdo->exec('PRAGMA cache_size = 10000');108 109 // Initialize WordPress tables in memory110 $this->create_wordpress_tables();111 112 return true;113 } catch (PDOException $e) {114 $this->last_error = $e->getMessage();115 $this->error = $e->getMessage();116 error_log("SQLite connection error: " . $e->getMessage());117 $this->ready = false;118 return false;119 }120 }121 122 public function query($sql) {123 $this->last_query = $sql;124 $this->last_error = '';125 $this->last_result = null;126 127 try {128 // Convert MySQL syntax to SQLite129 $sql = $this->mysql_to_sqlite($sql);130 131 $stmt = $this->pdo->prepare($sql);132 $result = $stmt->execute();133 134 if ($result) {135 $this->insert_id = $this->pdo->lastInsertId();136 $this->num_rows = $stmt->rowCount();137 $this->last_result = $stmt;138 139 // For SELECT queries, return the number of rows140 if (stripos(trim($sql), 'SELECT') === 0) {141 return $this->num_rows;142 }143 // For INSERT, UPDATE, DELETE, return true144 return true;145 }146 147 return false;148 } catch (PDOException $e) {149 $this->last_error = $e->getMessage();150 $this->error = $e->getMessage();151 152 if (!$this->suppress_errors) {153 if ($this->show_errors) {154 error_log("SQLite Error: " . $e->getMessage());155 }156 }157 158 return false;159 }160 }161 162 private function mysql_to_sqlite($sql) {163 // Basic MySQL to SQLite conversion164 $sql = str_replace('`', '"', $sql);165 $sql = preg_replace('/AUTO_INCREMENT/i', 'AUTOINCREMENT', $sql);166 $sql = preg_replace('/INT\(\d+\)/i', 'INTEGER', $sql);167 $sql = preg_replace('/TINYINT\(\d+\)/i', 'INTEGER', $sql);168 $sql = preg_replace('/BIGINT\(\d+\)/i', 'INTEGER', $sql);169 $sql = preg_replace('/VARCHAR\((\d+)\)/i', 'TEXT', $sql);170 $sql = preg_replace('/LONGTEXT/i', 'TEXT', $sql);171 $sql = preg_replace('/DATETIME/i', 'TEXT', $sql);172 $sql = preg_replace('/TIMESTAMP/i', 'TEXT', $sql);173 174 return $sql;175 }176 177 public function get_results($sql, $output = OBJECT) {178 $this->query($sql);179 if (!$this->last_result) return null;180 181 $results = [];182 while ($row = $this->last_result->fetch(PDO::FETCH_ASSOC)) {183 if ($output === OBJECT) {184 $results[] = (object) $row;185 } else {186 $results[] = $row;187 }188 }189 190 return $results;191 }192 193 public function get_row($sql, $output = OBJECT) {194 $this->query($sql);195 if (!$this->last_result) return null;196 197 $row = $this->last_result->fetch(PDO::FETCH_ASSOC);198 if (!$row) return null;199 200 if ($output === OBJECT) {201 return (object) $row;202 }203 204 return $row;205 }206 207 public function get_var($sql) {208 $this->query($sql);209 if (!$this->last_result) return null;210 211 $row = $this->last_result->fetch(PDO::FETCH_NUM);212 return $row ? $row[0] : null;213 }214 215 public function insert_id() {216 return $this->insert_id;217 }218 219 public function last_error() {220 return $this->last_error;221 }222 223 public function num_rows() {224 return $this->num_rows;225 }226 227 // WordPress compatibility methods228 public function prepare($query, ...$args) {229 if (empty($args)) {230 return $query;231 }232 233 $query = str_replace("'%s'", '%s', $query);234 $query = str_replace('"%s"', '%s', $query);235 $query = str_replace('%s', "'%s'", $query);236 $query = str_replace("'%d'", '%d', $query);237 $query = str_replace('"%d"', '%d', $query);238 239 return vsprintf($query, $args);240 }241 242 public function get_charset_collate() {243 return '';244 }245 246 public function esc_like($text) {247 return addcslashes($text, '\\%_');248 }249 250 public function _escape($data) {251 if (is_array($data)) {252 return array_map(array($this, '_escape'), $data);253 }254 255 if (is_string($data)) {256 return addslashes($data);257 }258 259 return $data;260 }261 262 public function _real_escape($data) {263 if (!is_scalar($data)) {264 return '';265 }266 267 // For SQLite, we use addslashes as there's no equivalent to mysqli_real_escape_string268 $escaped = addslashes($data);269 return $this->add_placeholder_escape($escaped);270 }271 272 public function _weak_escape($data) {273 if (func_num_args() === 1 && function_exists('_deprecated_function')) {274 _deprecated_function(__METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()');275 }276 return addslashes($data);277 }278 279 public function escape($data) {280 if (func_num_args() === 1 && function_exists('_deprecated_function')) {281 _deprecated_function(__METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()');282 }283 if (is_array($data)) {284 foreach ($data as $k => $v) {285 if (is_array($v)) {286 $data[$k] = $this->escape($v);287 } else {288 $data[$k] = $this->_weak_escape($v);289 }290 }291 } else {292 $data = $this->_weak_escape($data);293 }294 return $data;295 }296 297 public function add_placeholder_escape($query) {298 // Replace % with placeholder to prevent SQLi attacks299 return str_replace('%', $this->placeholder_escape(), $query);300 }301 302 public function placeholder_escape() {303 static $placeholder;304 if (!$placeholder) {305 // Generate a unique placeholder306 $placeholder = '{' . wp_generate_password(20, false) . '}';307 }308 return $placeholder;309 }310 311 public function print_error($str = '') {312 global $EZSQL_ERROR;313 314 if (!$str) {315 $str = $this->last_error;316 }317 318 $EZSQL_ERROR[] = array(319 'query' => $this->last_query,320 'error_str' => $str321 );322 323 if ($this->suppress_errors) {324 return false;325 }326 327 if ($this->show_errors) {328 if (function_exists('wp_die')) {329 wp_die($str);330 } else {331 die($str);332 }333 }334 335 return false;336 }337 338 public function bail($message, $error_code = '500') {339 if (!$this->show_errors) {340 if (class_exists('WP_Error')) {341 return new WP_Error($error_code, $message);342 } else {343 return false;344 }345 }346 347 if (function_exists('wp_die')) {348 wp_die($message);349 } else {350 die($message);351 }352 }353 354 // WordPress required methods355 public function set_prefix($prefix, $set_table_names = true) {356 if (preg_match('|[^a-z0-9_]|i', $prefix)) {357 // Return false instead of WP_Error since WP_Error might not be available yet358 return false;359 }360 361 $old_prefix = $this->prefix;362 $this->prefix = $prefix;363 364 if ($set_table_names) {365 $this->set_table_names();366 }367 368 return $old_prefix;369 }370 371 public function set_blog_id($blog_id, $network_id = 0) {372 // For single site, just return373 return $this->prefix;374 }375 376 public function tables($scope = 'all', $prefix = true, $blog_id = 0) {377 $tables = array(378 'posts', 'comments', 'links', 'options', 'postmeta',379 'terms', 'term_taxonomy', 'term_relationships', 'termmeta',380 'commentmeta', 'users', 'usermeta'381 );382 383 if ($prefix) {384 $prefixed_tables = array();385 foreach ($tables as $table) {386 $prefixed_tables[] = $this->prefix . $table;387 }388 return $prefixed_tables;389 }390 391 return $tables;392 }393 394 public function get_table_charset($table) {395 return 'utf8';396 }397 398 public function get_col_charset($table, $column) {399 return 'utf8';400 }401 402 public function check_connection($allow_bail = true) {403 if (!$this->pdo) {404 if ($allow_bail) {405 $this->bail('Error establishing a database connection');406 }407 return false;408 }409 410 try {411 // Test the connection with a simple query412 $this->pdo->query('SELECT 1');413 return true;414 } catch (PDOException $e) {415 $this->last_error = $e->getMessage();416 $this->error = $e->getMessage();417 418 if ($allow_bail) {419 $this->bail('Error establishing a database connection: ' . $e->getMessage());420 }421 return false;422 }423 }424 425 public function bail($message, $error_code = '500') {426 if (!$this->show_errors) {427 if (class_exists('WP_Error')) {428 $this->error = new WP_Error('db_connect_fail', $message);429 } else {430 $this->error = $message;431 }432 return false;433 }434 435 if (function_exists('wp_die')) {436 wp_die($message);437 } else {438 die($message);439 }440 }441 442 public function db_connect($allow_bail = true) {443 $this->ready = false;444 445 if ($this->connect()) {446 $this->ready = true;447 return true;448 }449 450 if ($allow_bail) {451 $this->bail('Error establishing a database connection');452 }453 454 return false;455 }456 457 public function db_version() {458 try {459 $result = $this->pdo->query('SELECT sqlite_version()');460 return $result->fetchColumn();461 } catch (PDOException $e) {462 return '0';463 }464 }465 466 // Additional WordPress methods467 public function get_col($query = null, $x = 0) {468 if ($query) {469 $this->query($query);470 }471 472 $new_array = array();473 if ($this->last_result) {474 for ($i = 0; $i < count($this->last_result); $i++) {475 $row = (array) $this->last_result[$i];476 $values = array_values($row);477 if (isset($values[$x]) && $values[$x] !== '') {478 $new_array[] = $values[$x];479 }480 }481 }482 return $new_array;483 }484 485 public function timer_start() {486 $this->time_start = microtime(true);487 return true;488 }489 490 public function timer_stop() {491 return (microtime(true) - $this->time_start);492 }493 494 public function get_blog_prefix($blog_id = null) {495 if (defined('MULTISITE') && MULTISITE) {496 if (null === $blog_id) {497 $blog_id = $this->blogid;498 }499 $blog_id = (int) $blog_id;500 if (0 == $blog_id || 1 == $blog_id) {501 return $this->base_prefix;502 } else {503 return $this->base_prefix . $blog_id . '_';504 }505 } else {506 return $this->prefix;507 }508 }509 510 public function flush() {511 $this->last_result = null;512 $this->last_query = null;513 $this->last_error = '';514 }515 516 public function close() {517 $this->pdo = null;518 return true;519 }520 521 public function has_cap($db_cap) {522 switch (strtolower($db_cap)) {523 case 'collation':524 case 'group_concat':525 case 'subqueries':526 return true;527 default:528 return false;529 }530 }531 532 public function get_caller() {533 if (function_exists('wp_debug_backtrace_summary')) {534 return wp_debug_backtrace_summary(__CLASS__);535 }536 return '';537 }538 539 public function init_charset() {540 // SQLite uses UTF-8 by default541 return true;542 }543 544 public function set_charset($dbh, $charset = null, $collate = null) {545 // SQLite uses UTF-8 by default546 return true;547 }548 549 // Error handling methods550 public function suppress_errors($suppress = true) {551 $errors_before = $this->suppress_errors;552 $this->suppress_errors = $suppress;553 return $errors_before;554 }555 556 public function hide_errors() {557 $show = $this->show_errors;558 $this->show_errors = false;559 return $show;560 }561 562 public function show_errors($show = true) {563 $errors_before = $this->show_errors;564 $this->show_errors = $show;565 return $errors_before;566 }567 568 // WordPress data manipulation methods569 public function insert($table, $data, $format = null) {570 return $this->_insert_replace_helper($table, $data, $format, 'INSERT');571 }572 573 public function replace($table, $data, $format = null) {574 return $this->_insert_replace_helper($table, $data, $format, 'REPLACE');575 }576 577 public function update($table, $data, $where, $format = null, $where_format = null) {578 if (!is_array($data) || !is_array($where)) {579 return false;580 }581 582 $formats = $format = (array) $format;583 $bits = $wheres = array();584 foreach ((array) array_keys($data) as $field) {585 if (!empty($formats)) {586 $form = ($form = array_shift($formats)) ? $form : $formats[0];587 } elseif (isset($this->field_types[$field])) {588 $form = $this->field_types[$field];589 } else {590 $form = '%s';591 }592 $bits[] = "`$field` = {$form}";593 }594 595 $where_formats = $where_format = (array) $where_format;596 foreach ((array) array_keys($where) as $field) {597 if (!empty($where_formats)) {598 $form = ($form = array_shift($where_formats)) ? $form : $where_formats[0];599 } elseif (isset($this->field_types[$field])) {600 $form = $this->field_types[$field];601 } else {602 $form = '%s';603 }604 $wheres[] = "`$field` = {$form}";605 }606 607 $sql = "UPDATE `$table` SET " . implode(', ', $bits) . ' WHERE ' . implode(' AND ', $wheres);608 return $this->query($this->prepare($sql, ...array_merge(array_values($data), array_values($where))));609 }610 611 public function delete($table, $where, $where_format = null) {612 if (!is_array($where)) {613 return false;614 }615 616 $where_formats = $where_format = (array) $where_format;617 $wheres = array();618 foreach (array_keys($where) as $field) {619 if (!empty($where_formats)) {620 $form = ($form = array_shift($where_formats)) ? $form : $where_formats[0];621 } elseif (isset($this->field_types[$field])) {622 $form = $this->field_types[$field];623 } else {624 $form = '%s';625 }626 $wheres[] = "`$field` = {$form}";627 }628 629 $sql = "DELETE FROM `$table` WHERE " . implode(' AND ', $wheres);630 return $this->query($this->prepare($sql, ...array_values($where)));631 }632 633 private function _insert_replace_helper($table, $data, $format = null, $type = 'INSERT') {634 if (!in_array(strtoupper($type), array('INSERT', 'REPLACE'))) {635 return false;636 }637 638 if (!is_array($data)) {639 return false;640 }641 642 $formats = $format = (array) $format;643 $fields = array_keys($data);644 $formatted_fields = array();645 646 foreach ($fields as $field) {647 if (!empty($formats)) {648 $form = ($form = array_shift($formats)) ? $form : $formats[0];649 } elseif (isset($this->field_types[$field])) {650 $form = $this->field_types[$field];651 } else {652 $form = '%s';653 }654 $formatted_fields[] = $form;655 }656 657 $sql = "$type INTO `$table` (`" . implode('`,`', $fields) . '`) VALUES (' . implode(',', $formatted_fields) . ')';658 return $this->query($this->prepare($sql, ...array_values($data)));659 }660 661 // Create WordPress tables in memory662 private function create_wordpress_tables() {663 $tables = array(664 // Posts table665 "CREATE TABLE IF NOT EXISTS {$this->prefix}posts (666 ID bigint(20) unsigned NOT NULL PRIMARY KEY,667 post_author bigint(20) unsigned NOT NULL DEFAULT 0,668 post_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',669 post_date_gmt datetime NOT NULL DEFAULT '0000-00-00 00:00:00',670 post_content longtext NOT NULL,671 post_title text NOT NULL,672 post_excerpt text NOT NULL,673 post_status varchar(20) NOT NULL DEFAULT 'publish',674 comment_status varchar(20) NOT NULL DEFAULT 'open',675 ping_status varchar(20) NOT NULL DEFAULT 'open',676 post_password varchar(255) NOT NULL DEFAULT '',677 post_name varchar(200) NOT NULL DEFAULT '',678 to_ping text NOT NULL,679 pinged text NOT NULL,680 post_modified datetime NOT NULL DEFAULT '0000-00-00 00:00:00',681 post_modified_gmt datetime NOT NULL DEFAULT '0000-00-00 00:00:00',682 post_content_filtered longtext NOT NULL,683 post_parent bigint(20) unsigned NOT NULL DEFAULT 0,684 guid varchar(255) NOT NULL DEFAULT '',685 menu_order int(11) NOT NULL DEFAULT 0,686 post_type varchar(20) NOT NULL DEFAULT 'post',687 post_mime_type varchar(100) NOT NULL DEFAULT '',688 comment_count bigint(20) NOT NULL DEFAULT 0689 )",690 691 // Users table692 "CREATE TABLE IF NOT EXISTS {$this->prefix}users (693 ID bigint(20) unsigned NOT NULL PRIMARY KEY,694 user_login varchar(60) NOT NULL DEFAULT '',695 user_pass varchar(255) NOT NULL DEFAULT '',696 user_nicename varchar(50) NOT NULL DEFAULT '',697 user_email varchar(100) NOT NULL DEFAULT '',698 user_url varchar(100) NOT NULL DEFAULT '',699 user_registered datetime NOT NULL DEFAULT '0000-00-00 00:00:00',700 user_activation_key varchar(255) NOT NULL DEFAULT '',701 user_status int(11) NOT NULL DEFAULT 0,702 display_name varchar(250) NOT NULL DEFAULT ''703 )",704 705 // Options table706 "CREATE TABLE IF NOT EXISTS {$this->prefix}options (707 option_id bigint(20) unsigned NOT NULL PRIMARY KEY,708 option_name varchar(191) NOT NULL DEFAULT '',709 option_value longtext NOT NULL,710 autoload varchar(20) NOT NULL DEFAULT 'yes'711 )",712 713 // Comments table714 "CREATE TABLE IF NOT EXISTS {$this->prefix}comments (715 comment_ID bigint(20) unsigned NOT NULL PRIMARY KEY,716 comment_post_ID bigint(20) unsigned NOT NULL DEFAULT 0,717 comment_author tinytext NOT NULL,718 comment_author_email varchar(100) NOT NULL DEFAULT '',719 comment_author_url varchar(200) NOT NULL DEFAULT '',720 comment_author_IP varchar(100) NOT NULL DEFAULT '',721 comment_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',722 comment_date_gmt datetime NOT NULL DEFAULT '0000-00-00 00:00:00',723 comment_content text NOT NULL,724 comment_karma int(11) NOT NULL DEFAULT 0,725 comment_approved varchar(20) NOT NULL DEFAULT '1',726 comment_agent varchar(255) NOT NULL DEFAULT '',727 comment_type varchar(20) NOT NULL DEFAULT 'comment',728 comment_parent bigint(20) unsigned NOT NULL DEFAULT 0,729 user_id bigint(20) unsigned NOT NULL DEFAULT 0730 )",731 732 // Terms table733 "CREATE TABLE IF NOT EXISTS {$this->prefix}terms (734 term_id bigint(20) unsigned NOT NULL PRIMARY KEY,735 name varchar(200) NOT NULL DEFAULT '',736 slug varchar(200) NOT NULL DEFAULT '',737 term_group bigint(10) NOT NULL DEFAULT 0738 )",739 740 // Term taxonomy table741 "CREATE TABLE IF NOT EXISTS {$this->prefix}term_taxonomy (742 term_taxonomy_id bigint(20) unsigned NOT NULL PRIMARY KEY,743 term_id bigint(20) unsigned NOT NULL DEFAULT 0,744 taxonomy varchar(32) NOT NULL DEFAULT '',745 description longtext NOT NULL,746 parent bigint(20) unsigned NOT NULL DEFAULT 0,747 count bigint(20) NOT NULL DEFAULT 0748 )",749 750 // Term relationships table751 "CREATE TABLE IF NOT EXISTS {$this->prefix}term_relationships (752 object_id bigint(20) unsigned NOT NULL DEFAULT 0,753 term_taxonomy_id bigint(20) unsigned NOT NULL DEFAULT 0,754 term_order int(11) NOT NULL DEFAULT 0,755 PRIMARY KEY (object_id, term_taxonomy_id)756 )"757 );758 759 foreach ($tables as $sql) {760 try {761 $this->pdo->exec($sql);762 } catch (PDOException $e) {763 error_log("Error creating table: " . $e->getMessage());764 }765 }766 767 // Insert default options768 $this->insert_default_options();769 }770 771 // Insert default WordPress options772 private function insert_default_options() {773 $default_options = array(774 array('option_name' => 'siteurl', 'option_value' => 'http://localhost', 'autoload' => 'yes'),775 array('option_name' => 'home', 'option_value' => 'http://localhost', 'autoload' => 'yes'),776 array('option_name' => 'blogname', 'option_value' => 'WordPress on Hugging Face', 'autoload' => 'yes'),777 array('option_name' => 'blogdescription', 'option_value' => 'Just another WordPress site', 'autoload' => 'yes'),778 array('option_name' => 'users_can_register', 'option_value' => '0', 'autoload' => 'yes'),779 array('option_name' => 'admin_email', 'option_value' => 'admin@example.com', 'autoload' => 'yes'),780 array('option_name' => 'start_of_week', 'option_value' => '1', 'autoload' => 'yes'),781 array('option_name' => 'use_balanceTags', 'option_value' => '0', 'autoload' => 'yes'),782 array('option_name' => 'use_smilies', 'option_value' => '1', 'autoload' => 'yes'),783 array('option_name' => 'require_name_email', 'option_value' => '1', 'autoload' => 'yes'),784 array('option_name' => 'comments_notify', 'option_value' => '1', 'autoload' => 'yes'),785 array('option_name' => 'posts_per_rss', 'option_value' => '10', 'autoload' => 'yes'),786 array('option_name' => 'rss_use_excerpt', 'option_value' => '0', 'autoload' => 'yes'),787 array('option_name' => 'mailserver_url', 'option_value' => 'mail.example.com', 'autoload' => 'yes'),788 array('option_name' => 'mailserver_login', 'option_value' => 'login@example.com', 'autoload' => 'yes'),789 array('option_name' => 'mailserver_pass', 'option_value' => 'password', 'autoload' => 'yes'),790 array('option_name' => 'mailserver_port', 'option_value' => '110', 'autoload' => 'yes'),791 array('option_name' => 'default_category', 'option_value' => '1', 'autoload' => 'yes'),792 array('option_name' => 'default_comment_status', 'option_value' => 'open', 'autoload' => 'yes'),793 array('option_name' => 'default_ping_status', 'option_value' => 'open', 'autoload' => 'yes'),794 array('option_name' => 'default_pingback_flag', 'option_value' => '1', 'autoload' => 'yes'),795 array('option_name' => 'posts_per_page', 'option_value' => '10', 'autoload' => 'yes'),796 array('option_name' => 'date_format', 'option_value' => 'F j, Y', 'autoload' => 'yes'),797 array('option_name' => 'time_format', 'option_value' => 'g:i a', 'autoload' => 'yes'),798 array('option_name' => 'links_updated_date_format', 'option_value' => 'F j, Y g:i a', 'autoload' => 'yes'),799 array('option_name' => 'comment_moderation', 'option_value' => '0', 'autoload' => 'yes'),800 array('option_name' => 'moderation_notify', 'option_value' => '1', 'autoload' => 'yes'),801 array('option_name' => 'permalink_structure', 'option_value' => '/%year%/%monthnum%/%day%/%postname%/', 'autoload' => 'yes'),802 array('option_name' => 'rewrite_rules', 'option_value' => '', 'autoload' => 'yes'),803 array('option_name' => 'hack_file', 'option_value' => '0', 'autoload' => 'yes'),804 array('option_name' => 'blog_charset', 'option_value' => 'UTF-8', 'autoload' => 'yes'),805 array('option_name' => 'moderation_keys', 'option_value' => '', 'autoload' => 'no'),806 array('option_name' => 'active_plugins', 'option_value' => 'a:0:{}', 'autoload' => 'yes'),807 array('option_name' => 'category_base', 'option_value' => '', 'autoload' => 'yes'),808 array('option_name' => 'ping_sites', 'option_value' => 'http://rpc.pingomatic.com/', 'autoload' => 'yes'),809 array('option_name' => 'comment_max_links', 'option_value' => '2', 'autoload' => 'yes'),810 array('option_name' => 'gmt_offset', 'option_value' => '0', 'autoload' => 'yes'),811 array('option_name' => 'default_email_category', 'option_value' => '1', 'autoload' => 'yes'),812 array('option_name' => 'recently_edited', 'option_value' => '', 'autoload' => 'no'),813 array('option_name' => 'template', 'option_value' => 'twentytwentyfour', 'autoload' => 'yes'),814 array('option_name' => 'stylesheet', 'option_value' => 'twentytwentyfour', 'autoload' => 'yes'),815 array('option_name' => 'comment_registration', 'option_value' => '0', 'autoload' => 'yes'),816 array('option_name' => 'html_type', 'option_value' => 'text/html', 'autoload' => 'yes'),817 array('option_name' => 'use_trackback', 'option_value' => '0', 'autoload' => 'yes'),818 array('option_name' => 'default_role', 'option_value' => 'subscriber', 'autoload' => 'yes'),819 array('option_name' => 'db_version', 'option_value' => '57155', 'autoload' => 'yes'),820 array('option_name' => 'uploads_use_yearmonth_folders', 'option_value' => '1', 'autoload' => 'yes'),821 array('option_name' => 'upload_path', 'option_value' => '', 'autoload' => 'yes'),822 array('option_name' => 'blog_public', 'option_value' => '1', 'autoload' => 'yes'),823 array('option_name' => 'default_link_category', 'option_value' => '2', 'autoload' => 'yes'),824 array('option_name' => 'show_on_front', 'option_value' => 'posts', 'autoload' => 'yes'),825 array('option_name' => 'tag_base', 'option_value' => '', 'autoload' => 'yes'),826 array('option_name' => 'show_avatars', 'option_value' => '1', 'autoload' => 'yes'),827 array('option_name' => 'avatar_rating', 'option_value' => 'G', 'autoload' => 'yes'),828 array('option_name' => 'upload_url_path', 'option_value' => '', 'autoload' => 'yes'),829 array('option_name' => 'thumbnail_size_w', 'option_value' => '150', 'autoload' => 'yes'),830 array('option_name' => 'thumbnail_size_h', 'option_value' => '150', 'autoload' => 'yes'),831 array('option_name' => 'thumbnail_crop', 'option_value' => '1', 'autoload' => 'yes'),832 array('option_name' => 'medium_size_w', 'option_value' => '300', 'autoload' => 'yes'),833 array('option_name' => 'medium_size_h', 'option_value' => '300', 'autoload' => 'yes'),834 array('option_name' => 'avatar_default', 'option_value' => 'mystery', 'autoload' => 'yes'),835 array('option_name' => 'large_size_w', 'option_value' => '1024', 'autoload' => 'yes'),836 array('option_name' => 'large_size_h', 'option_value' => '1024', 'autoload' => 'yes'),837 array('option_name' => 'image_default_link_type', 'option_value' => 'none', 'autoload' => 'yes'),838 array('option_name' => 'image_default_size', 'option_value' => '', 'autoload' => 'yes'),839 array('option_name' => 'image_default_align', 'option_value' => '', 'autoload' => 'yes'),840 array('option_name' => 'close_comments_for_old_posts', 'option_value' => '0', 'autoload' => 'yes'),841 array('option_name' => 'close_comments_days_old', 'option_value' => '14', 'autoload' => 'yes'),842 array('option_name' => 'thread_comments', 'option_value' => '1', 'autoload' => 'yes'),843 array('option_name' => 'thread_comments_depth', 'option_value' => '5', 'autoload' => 'yes'),844 array('option_name' => 'page_comments', 'option_value' => '0', 'autoload' => 'yes'),845 array('option_name' => 'comments_per_page', 'option_value' => '50', 'autoload' => 'yes'),846 array('option_name' => 'default_comments_page', 'option_value' => 'newest', 'autoload' => 'yes'),847 array('option_name' => 'comment_order', 'option_value' => 'asc', 'autoload' => 'yes'),848 array('option_name' => 'sticky_posts', 'option_value' => 'a:0:{}', 'autoload' => 'yes'),849 array('option_name' => 'widget_categories', 'option_value' => 'a:0:{}', 'autoload' => 'yes'),850 array('option_name' => 'widget_text', 'option_value' => 'a:0:{}', 'autoload' => 'yes'),851 array('option_name' => 'widget_rss', 'option_value' => 'a:0:{}', 'autoload' => 'yes'),852 array('option_name' => 'uninstall_plugins', 'option_value' => 'a:0:{}', 'autoload' => 'no'),853 array('option_name' => 'timezone_string', 'option_value' => '', 'autoload' => 'yes'),854 array('option_name' => 'page_for_posts', 'option_value' => '0', 'autoload' => 'yes'),855 array('option_name' => 'page_on_front', 'option_value' => '0', 'autoload' => 'yes'),856 array('option_name' => 'default_post_format', 'option_value' => '0', 'autoload' => 'yes'),857 array('option_name' => 'link_manager_enabled', 'option_value' => '0', 'autoload' => 'yes'),858 array('option_name' => 'finished_splitting_shared_terms', 'option_value' => '1', 'autoload' => 'yes'),859 array('option_name' => 'site_icon', 'option_value' => '0', 'autoload' => 'yes'),860 array('option_name' => 'medium_large_size_w', 'option_value' => '768', 'autoload' => 'yes'),861 array('option_name' => 'medium_large_size_h', 'option_value' => '0', 'autoload' => 'yes'),862 array('option_name' => 'wp_page_for_privacy_policy', 'option_value' => '3', 'autoload' => 'yes'),863 array('option_name' => 'show_comments_cookies_opt_in', 'option_value' => '1', 'autoload' => 'yes'),864 array('option_name' => 'admin_email_lifespan', 'option_value' => '1735689600', 'autoload' => 'yes'),865 array('option_name' => 'disallowed_keys', 'option_value' => '', 'autoload' => 'no'),866 array('option_name' => 'comment_previously_approved', 'option_value' => '1', 'autoload' => 'yes'),867 array('option_name' => 'auto_plugin_theme_update_emails', 'option_value' => 'a:0:{}', 'autoload' => 'no'),868 array('option_name' => 'auto_update_core_dev', 'option_value' => 'enabled', 'autoload' => 'yes'),869 array('option_name' => 'auto_update_core_minor', 'option_value' => 'enabled', 'autoload' => 'yes'),870 array('option_name' => 'auto_update_core_major', 'option_value' => 'enabled', 'autoload' => 'yes'),871 array('option_name' => 'wp_force_deactivated_plugins', 'option_value' => 'a:0:{}', 'autoload' => 'yes'),872 array('option_name' => 'initial_db_version', 'option_value' => '57155', 'autoload' => 'yes'),873 array('option_name' => 'wp_user_roles', 'option_value' => 'a:5:{s:13:"administrator";a:2:{s:4:"name";s:13:"Administrator";s:12:"capabilities";a:61:{s:13:"switch_themes";b:1;s:11:"edit_themes";b:1;s:16:"activate_plugins";b:1;s:12:"edit_plugins";b:1;s:10:"edit_users";b:1;s:10:"edit_files";b:1;s:14:"manage_options";b:1;s:17:"moderate_comments";b:1;s:17:"manage_categories";b:1;s:12:"manage_links";b:1;s:12:"upload_files";b:1;s:6:"import";b:1;s:15:"unfiltered_html";b:1;s:10:"edit_posts";b:1;s:17:"edit_others_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:10:"edit_pages";b:1;s:4:"read";b:1;s:8:"level_10";b:1;s:7:"level_9";b:1;s:7:"level_8";b:1;s:7:"level_7";b:1;s:7:"level_6";b:1;s:7:"level_5";b:1;s:7:"level_4";b:1;s:7:"level_3";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:17:"edit_others_pages";b:1;s:20:"edit_published_pages";b:1;s:13:"publish_pages";b:1;s:12:"delete_pages";b:1;s:19:"delete_others_pages";b:1;s:22:"delete_published_pages";b:1;s:12:"delete_posts";b:1;s:19:"delete_others_posts";b:1;s:22:"delete_published_posts";b:1;s:20:"delete_private_posts";b:1;s:18:"edit_private_posts";b:1;s:18:"read_private_posts";b:1;s:20:"delete_private_pages";b:1;s:18:"edit_private_pages";b:1;s:18:"read_private_pages";b:1;s:12:"delete_users";b:1;s:12:"create_users";b:1;s:17:"unfiltered_upload";b:1;s:14:"edit_dashboard";b:1;s:14:"update_plugins";b:1;s:14:"delete_plugins";b:1;s:15:"install_plugins";b:1;s:13:"update_themes";b:1;s:14:"install_themes";b:1;s:11:"update_core";b:1;s:10:"list_users";b:1;s:12:"remove_users";b:1;s:13:"promote_users";b:1;s:18:"edit_theme_options";b:1;s:13:"delete_themes";b:1;s:6:"export";b:1;}}s:6:"editor";a:2:{s:4:"name";s:6:"Editor";s:12:"capabilities";a:34:{s:17:"moderate_comments";b:1;s:17:"manage_categories";b:1;s:12:"manage_links";b:1;s:12:"upload_files";b:1;s:15:"unfiltered_html";b:1;s:10:"edit_posts";b:1;s:17:"edit_others_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:10:"edit_pages";b:1;s:4:"read";b:1;s:7:"level_7";b:1;s:7:"level_6";b:1;s:7:"level_5";b:1;s:7:"level_4";b:1;s:7:"level_3";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:17:"edit_others_pages";b:1;s:20:"edit_published_pages";b:1;s:13:"publish_pages";b:1;s:12:"delete_pages";b:1;s:19:"delete_others_pages";b:1;s:22:"delete_published_pages";b:1;s:12:"delete_posts";b:1;s:19:"delete_others_posts";b:1;s:22:"delete_published_posts";b:1;s:20:"delete_private_posts";b:1;s:18:"edit_private_posts";b:1;s:18:"read_private_posts";b:1;s:20:"delete_private_pages";b:1;s:18:"edit_private_pages";b:1;s:18:"read_private_pages";b:1;}}s:6:"author";a:2:{s:4:"name";s:6:"Author";s:12:"capabilities";a:10:{s:12:"upload_files";b:1;s:10:"edit_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:4:"read";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:12:"delete_posts";b:1;s:22:"delete_published_posts";b:1;}}s:11:"contributor";a:2:{s:4:"name";s:11:"Contributor";s:12:"capabilities";a:5:{s:10:"edit_posts";b:1;s:4:"read";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:12:"delete_posts";b:1;}}s:10:"subscriber";a:2:{s:4:"name";s:10:"Subscriber";s:12:"capabilities";a:2:{s:4:"read";b:1;s:7:"level_0";b:1;}}}', 'autoload' => 'yes'),874 array('option_name' => 'fresh_site', 'option_value' => '1', 'autoload' => 'yes')875 );876 877 foreach ($default_options as $option) {878 try {879 $this->insert($this->prefix . 'options', $option);880 } catch (Exception $e) {881 // Ignore duplicate key errors882 }883 }884 }885}886 887// Initialize SQLite database connection888$wpdb = new SQLite_DB();889 890// WordPress database compatibility891if (!isset($GLOBALS['wpdb'])) {892 $GLOBALS['wpdb'] = $wpdb;893}