> SQLite Integration >> Miscellaneous, and click the button "update" at the bottom of the page. Or else replace wp-content/db.php with the one in sqlite-integration directory manually.', 'sqlite-integration'); $current_version = defined('SQLITE_INTEGRATION_VERSION') ? SQLITE_INTEGRATION_VERSION : ''; if (version_compare($current_version, '1.6.2', '=')) return; $version = ''; if (defined('WP_CONTENT_DIR')) { $path = WP_CONTENT_DIR . '/db.php'; } else { $path = ABSPATH . 'wp-content/db.php'; } if (!$file_handle = @fopen($path, 'r')) return; while (($buffer = fgets($file_handle)) !== false) { if (stripos($buffer, '@version') !== false) { $version = str_ireplace('*@version ', '', $buffer); $version = trim($version); break; } } fclose($file_handle); if (empty($version) || version_compare($version, $current_version, '<')) { echo '
'.$notice_string.'
'; } } /** * Method to read a error log file and returns its contents. * * 'FQDBDIR/debug.txt' is the log file name. * If this file is not existent, returns false. * * @return string|boolean * @access private */ private function show_error_log() { $file = FQDBDIR . 'debug.txt'; if (file_exists($file)) { $contents = file_get_contents($file); return $contents; } else { return false; } } /** * Method to clear the contents of the error log file. * * @return boolean * @access private */ private function clear_log_file() { $result = false; $file = FQDBDIR . 'debug.txt'; $fh = fopen($file, "w+"); if ($fh) { if (flock($fh, LOCK_EX)) { if (ftruncate($fh, 0) === false) { return false; } flock($fh, LOCK_UN); } else { return false; } } fclose($fh); return true; } /** * Method to get system information from the server and returns its data. * * Returned value is an associative array of system informations. * * sys_info['WordPress'] => WordPress Version * sys_info['PHP'] => PHP Version * * * @return array * @access private */ private function get_system_info() { global $wp_version; $sys_info = array(); $sys_info['WordPress'] = $wp_version; $sys_info['PHP'] = PHP_VERSION; return $sys_info; } /** * Method to get database information from the database and returns its data. * * Returned value is an associative array. * * @return array * @access private */ private function get_database_status() { global $wpdb; $status = array(); $db_size = $this->get_database_size(); $encoding = $wpdb->get_var("PRAGMA encoding"); $integrity = $wpdb->get_var("PRAGMA integrity_check"); $page_size = $wpdb->get_var("PRAGMA page_size"); $page_count = $wpdb->get_var("PRAGMA page_count"); $unused_page = $wpdb->get_var("PRAGMA freelist_count"); $collation_list = $wpdb->get_results("PRAGMA collation_list"); $compile_options = $wpdb->get_results("PRAGMA compile_options"); foreach ($collation_list as $col) { $collations[] = $col->name; } foreach ($compile_options as $opt) { $options[] = $opt->compile_option; } $status['size'] = $db_size; $status['integrity'] = $integrity; $status['pagesize'] = $page_size; $status['page'] = $page_count; $status['unused'] = $unused_page; $status['encoding'] = $encoding; $status['collations'] = $collations; $status['options'] = $options; return $status; } /** * Method to get table information and returns its data. * * Returned value is an associative array like: * * array( table name => array( index name ( column name ))) * * for each table in the database * * @return array * @access private */ private function get_tables_info() { global $wpdb; $table_info = array(); $tables = $wpdb->get_col("SHOW TABLES"); foreach ($tables as $table) { $index_object = $wpdb->get_results("SHOW INDEX FROM $table"); if (empty($index_object)) { $table_info[$table][] = 'no index'; } else { foreach ($index_object as $index) { $table_info[$table][] = $index->Key_name . ' ( ' . $index->Column_name . ' )'; } } } $table_info = array_reverse($table_info); return $table_info; } /** * Method to get the autoincremented values of each table and returns it. * * The data is from sqlite_sequence table. * * @return assoc array name => sequence, or false * @access private */ private function get_sequence() { global $wpdb; $sequence_info = array(); $results = $wpdb->get_results("SELECT name, seq FROM sqlite_sequence"); if (is_null($results) || empty($results)) { return false; } else { foreach ($results as $result) { $sequence_info[$result->name] = $result->seq; } return $sequence_info; } } /** * Method to show the contents of 'wp-content/db.php' file. * * If this file is not existent, shows message and returns false. * * @return string * @access private */ private function show_db_php() { if (defined('WP_CONTENT_DIR')) { $file = WP_CONTENT_DIR . '/db.php'; } else { $file = ABSPATH . 'wp-content/db.php'; } if (file_exists($file)) { if (is_readable($file)) { $contents = file_get_contents($file); return $contents; } else { $contents = 'file is not readable'; } } else { $contents = 'file doesn\'t exist'; } return $contents; } /** * Method to get the textarea content and write it to db.php file. * * @param string $contents * @return boolean * @access private */ private function save_db_php($contents) { if (defined('WP_CONTENT_DIR')) { $file = WP_CONTENT_DIR . '/db.php'; } else { $file = ABSPATH . 'wp-content/db.php'; } $fh = fopen($file, "w+"); if ($fh) { if (flock($fh, LOCK_EX)) { if (fwrite($fh, $contents) === false) { return false; } flock($fh, LOCK_UN); } else { return false; } } fclose($fh); return true; } /** * Method to replace the old db.php with the new one. * * @return boolean * @access private */ private function update_db_file() { $new_file = PDODIR . 'db.php'; if (file_exists($new_file) && is_readable($new_file)) { $contents = file_get_contents($new_file); } else { return false; } if (defined('WP_CONTENT_DIR')) { $path = WP_CONTENT_DIR . '/db.php'; } else { $path = ABSPATH . 'wp-content/db.php'; } if (($handle = @fopen($path, 'w+')) && flock($handle, LOCK_EX)) { if (fwrite($handle, $contents) == false) { flock($handle, LOCK_UN); fclose($handle); return false; } flock($handle, LOCK_UN); fclose($handle); } else { return false; } return true; } /** * Method to optimize SQLite database. * * This only gives VACUUM command to SQLite database. This query is rewritten in * the query.class.php file. * * @return boolean * @access private */ private function optimize_db() { global $wpdb; $result = $wpdb->query("OPTIMIZE"); return $result; } /** * Method to get SQLite database file size. * * @return string * @access private */ private function get_database_size() { $db_file = FQDB; if (file_exists($db_file)) { $size = filesize($db_file); clearstatcache(true, $db_file); return $this->convert_to_formatted_number($size); } } /** * Method to format the file size number to the unit byte. * * @param integer $size * @return string * @access private */ private function convert_to_formatted_number($size) { $unim = array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'); $count = 0; while ($size >= 1024) { $count++; $size = $size / 1024; } return number_format($size, ($count ? 2 : 0), '.', ',') . ' ' . $unim[$count]; } /** * Method to echo plugins info table component. * * @return nothing returned. * @access private */ private function show_plugins_info() { $domain = $this->text_domain; if (file_exists(SQLiteListFile)) { $contents = file_get_contents(SQLiteListFile); $plugin_info_list = json_decode($contents); $plugins = get_plugins(); foreach ($plugins as $key => $data) { $name = ''.$data['Name'].''; foreach ($plugin_info_list as $plugin_info) { if ($data['Name'] == $plugin_info->name) { $class = 'class="'.$plugin_info->class.'"'; // for Internationalization... it's a redundant codes, mm... // I might have made a mistake to store data in json format... switch ($plugin_info->compat) { case 'Needs Patch': if (!empty($plugin_info->patch_url)) { $compat = ''.__('Needs Patch', $domain).''; } else { $compat = __('Needs Patch', $domain); } break; case 'Probably No': $compat = __('Probably No', $domain); break; case 'Probably Yes': $compat = __('Probably Yes', $domain); break; case 'No': $compat = __('No', $domain); break; case 'Checked': if (!empty($plugin_info->informed) && stripos($plugin_info->informed, 'Users\' Information') !== false) { $compat = __('Checked*', $domain); } else { $compat = __('Checked', $domain); } break; default: $compat = __('Not Checked', $domain); break; } break; } else { $class = 'class="compatible"'; $compat = __('Not Checked', $domain); } } if (is_plugin_active_for_network($key)) { echo '"; echo sprintf('%1$s%2$s%3$s', $name, __('Sitewide Active', $domain), $compat); } elseif (is_plugin_active($key)) { echo '"; echo sprintf('%1$s%2$s%3$s', $name, __('Active', $domain), $compat); } else { echo '"; echo sprintf('%1$s%2$s%3$s', $name, __('Inactive', $domain), $compat); } echo ''; } } } /** * Method to return output of phpinfo() as an array. * * @See PHP Manual * @return array * @access private */ private function parse_php_modules() { ob_start(); phpinfo(INFO_MODULES); $infos = ob_get_contents(); ob_end_clean(); $infos = strip_tags($infos, '

'); $infos = preg_replace('/]*>([^<]+)<\/th>/', "\\1", $infos); $infos = preg_replace('/]*>([^<]+)<\/td>/', "\\1", $infos); $info_array = preg_split('/(

[^<]+?<\/h2>)/', $infos, -1, PREG_SPLIT_DELIM_CAPTURE); $modules = array(); for ($i = 1; $i < count($info_array); $i++) { if (preg_match('/

([^<]+)<\/h2>/', $info_array[$i], $match)) { $name = trim($match[1]); $info_array2 = explode("\n", $info_array[$i+1]); foreach ($info_array2 as $info) { $pattern = '([^<]+)<\/info>'; $pattern3 = "/$pattern\\s*$pattern\\s*$pattern/"; $pattern2 = "/$pattern\\s*$pattern/"; if (preg_match($pattern3, $info, $match)) { $modules[$name][trim($match[1])] = array(trim($match[2]), trim($match[3])); } elseif (preg_match($pattern2, $info, $match)) { $modules[$name][trim($match[1])] = trim($match[2]); } } } } return $modules; } /** * Method to echo PHP module info. * * @param string $module_name * @param string $setting_name * @access private */ private function get_module_setting($module_name, $setting_name) { $module_info = $this->parse_php_modules(); echo $module_info[$module_name][$setting_name]; } function show_parent() { if (function_exists('is_multisite') && is_multisite()) { return 'settings.php'; } else { return 'options-general.php'; } } /** * Method to parse FQDBDIR and return backup database files. * * @return nothing returned. * @access private */ private function get_backup_files() { $db_name = basename(FQDB); $names_to_exclude = array('.', '..', '.htaccess', 'debug.txt', '.ht.sqlite', 'index.php', $db_name); $backup_files = array(); if (is_dir(FQDBDIR)) { if ($dir_handle = opendir(FQDBDIR)) { while (($file_name = readdir($dir_handle)) !== false) { if (in_array($file_name, $names_to_exclude)) continue; $backup_files[] = $file_name; } } } return $backup_files; } /** * Method to create backup database file. * * @return string array * @access private */ private function backup_db() { $domain = $this->text_domain; $result = array(); $database_file = FQDB; $db_name = basename(FQDB); if (!file_exists($database_file)) { return false; } $today = date("Ymd"); if (!extension_loaded('zip')) { $backup_file = $database_file . '.' . $today . '.back'; if (copy($database_file, $backup_file)) { $result['success'] = basename($backup_file) . __(' was created.', $domain); } else { $result['error'] = basename($backup_file) . __(' was not created.', $domain); } } else { $backup_file = $database_file . '.' . $today . '.zip'; $zip = new ZipArchive(); $res = $zip->open($backup_file, ZipArchive::CREATE | ZipArchive::OVERWRITE); if ($res === true) { $zip->addFile($database_file, $db_name); $result['success'] = basename($backup_file) . __(' was created.', $domain); } else { $result['error'] = basename($backup_file) . __(' was not created.', $domain); } $zip->close(); } return $result; } /** * Method to delete backup database file(s). * * Users can delete multiple files at a time. * * @return false if file names aren't checked, empty array if failed, array of messages if succeeded. * @access private */ private function delete_backup_db() { $domain = $this->text_domain; $file_names = array(); $results = array(); if (isset($_POST['backup_checked'])) { $file_names = $_POST['backup_checked']; } else { return false; } if (chdir(FQDBDIR)) { foreach ($file_names as $file) { if (unlink($file)) { $results[$file] = sprintf(__('File %s was deleted.', $domain), $file); } else { $results[$file] = sprintf(__('Error! File was not deleted.', $domain), $file); } } } return $results; } /** * Method to download a backup file. * * This method uses header() function, so we have to register this function using * admin_init action hook. It must also be declared as public. We check HTTP_REFERER * and input button name, and ,after that, wp_nonce. When the admin_init is executed * it only returns true. * * The database file might be several hundred mega bytes, so we don't use readfile() * but use fread() instead. * * Users can download one file at a time. * * @return 1 if the file name isn't checked, 2 if multiple files are checked, true if succeeded. */ static function download_backup_db() { if (is_multisite()) { $script_url = network_admin_url('settings.php?page=setting-file'); } else { $script_url = admin_url('options-general.php?page=setting-file'); } if (isset($_POST['download_backup_file']) && stripos($_SERVER['HTTP_REFERER'], $script_url) !== false) { check_admin_referer('sqliteintegration-backup-manip-stats'); if (!isset($_POST['backup_checked'])) return 1; $file_names = array(); $file_names = $_POST['backup_checked']; if (count($file_names) != 1) return 2; $file_name = $file_names[0]; $file_path = FQDBDIR . $file_name; $blog_name = str_replace(array(' ', ' ', ';'), array('_', '_', '_'), get_bloginfo('name')); $download_file_name = $blog_name . '_' . $file_name; header('Pragma: public'); header('Cache-Control: must-revalidate,post-check=0,pre-check=0'); header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream'); header('Content-Type: application/download'); header('Content-Disposition: attachment; filename='.$download_file_name.';'); header('Content-Transfer-Encoding: binary'); header('Content-Length: '.filesize($file_path)); $fp = fopen($file_path, 'r'); while (!feof($fp)) { echo fread($fp, 65536); flush(); } fclose($fp); } return true; } /** * Method to show Welcome page. * */ function welcome() { $domain = $this->text_domain; if (isset($_GET['page']) && $_GET['page'] == 'sqlite-integration') :?>

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'] == 'sys-info') :?>

get_system_info(); ?>
get_module_setting('PDO', 'PDO support');?>
get_module_setting('PDO', 'PDO drivers');?>
get_module_setting('pdo_sqlite', 'PDO Driver for SQLite 3.x');?>
get_module_setting('pdo_sqlite', 'SQLite Library');?>

get_database_status();?>
'; echo ($i+1).'. '.$col; $i++; } ?>
'; echo ($i+1).'. '.$op; $i++; } ?>

get_tables_info(); $table_seq = $this->get_sequence(); $network_tables = array(); if (is_multisite()) { $tmp_tables = $wpdb->tables('blog', false); $blogs = $wpdb->get_col("SELECT * FROM {$wpdb->prefix}blogs"); if (count($blogs) > 1) { foreach ($blogs as $id) { if ($id == 1) continue; foreach ($tmp_tables as $tmp_tbl) { $network_tables[] = $wpdb->prefix.$id.'_'.$tmp_tbl; } } } } foreach ($table_info as $tbl_name => $index) : ?> tables('all', true)) || in_array($tbl_name, $network_tables) || $tbl_name == 'sqlite_sequence') { $which_table = 'system'; } else { $which_table = 'user'; } echo ''; if (array_key_exists($tbl_name, $table_seq)) $tbl_name .= " ($table_seq[$tbl_name])"; echo ''; echo '';?>
' . $tbl_name . '' . $which_table . ' table';} ?>

show_plugins_info();?>

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['sqlitewordpress_log_reset'])) { check_admin_referer('sqlitewordpress-log-reset-stats'); if ($this->clear_log_file()) { $messages = __('Log cleared', $domain); echo '
'.$messages.'
'; } else { $messages = __('Log not cleared', $domain); echo '
'.$messages.'
'; } } if (isset($_POST['sqlitewordpress_db_save'])) { check_admin_referer('sqlitewordpress-db-save-stats'); if (isset($_POST['dbfile'])) { $contents = $_POST['dbfile']; if (get_magic_quotes_gpc() || version_compare(PHP_VERSION, '5.4', '>=')) { $contents = stripslashes($contents); } if ($this->save_db_php($contents)) { $messages = __('db.php was saved', $domain); echo '
'.$messages.'
'; } else { $messages = __('Error! db.php couldn\'t be saved', $domain); echo '
'.$messages.'
'; } } } if (isset($_POST['sqlitewordpress_db_optimize'])) { check_admin_referer('sqlitewordpress-db-optimize-stats'); $size_before = $this->get_database_size(); $result = $this->optimize_db(); if ($result) { $size_after = $this->get_database_size(); $messages = sprintf(__('Optimization finished. Before optimization: %1$s, After optimization: %2$s.', $domain), $size_before, $size_after); echo '
'.$messages.'
'; } else { $messages = __('Optimization failed', $domain); echo '
'.$messages.'
'; } } if (isset($_POST['backup_db'])) { check_admin_referer('sqliteintegration-backup-manip-stats'); $results = $this->backup_db(); if ($results === false) { $message = __('Couldn\'t find your database file.'); echo '
'.$message.'
'; } elseif (is_array($results) && array_key_exists('success', $results)) { echo '
'.$results['success'].'
'; } else { echo '
'.$results['error'].'
'; } } if (isset($_POST['delete_backup_files'])) { check_admin_referer('sqliteintegration-backup-manip-stats'); $results = $this->delete_backup_db(); if ($results === false) { $message = __('Please select backup file(s).', $domain); echo '
'.$message.'
'; } elseif (is_array($results) && count($results) > 0) { echo '
'; foreach ($results as $key => $val) { echo $val.'
'; } echo '
'; } else { $message = __('Error! Please remove file(s) manyally.', $domain); echo '
'.$message.'
'; } } if (isset($_POST['download_backup_file'])) { check_admin_referer('sqliteintegration-backup-manip-stats'); $message = ''; $result = self::download_backup_db(); if ($result !== true) { switch($result) { case 1: $message = __('Please select backup file.', $domain); break; case 2: $message = __('Please select one file at a time.', $domain); break; default: break; } echo '
' . $message . '
'; } } if (isset($_POST['sqliteintegration_update_db_file'])) { check_admin_referer('sqliteintegration-db-update-stats'); $result = $this->update_db_file(); if ($result === false) { $message = __('Couldn"t update db.php file. Please replace it manually.', $domain); echo '
'.$message.'
'; } else { echo << // JS; $message = __('Your db.php is updated.', $domain); echo '
'.$message.'
'; } } if (isset($_GET['page']) && $_GET['page'] == 'setting-file') :?>

get_backup_files();?>

show_error_log(); if ($ret_val === false || empty($ret_val)) { $ret_val = __('No error messages are found', $domain); } ?>

';?>

'; ?> If you don\'t understand well, please don\'t edit this file.', $domain)?> '; ?> '; ?> show_db_php();?> '.$db_contents.'

'; ?> ', __('Save', $domain), __('Are you sure to save this file?\n\nClick [Cancel] to stop, [OK] to continue.', $domain)); ?> '; ?>

', __('Update', $domain), __('Are you sure to update this file?\n\nClick [Cancel] to stop, [OK] to continue.', $domain));?>