WordPress Version * sys_info['PHP'] => PHP Version * @return array */ private function get_system_info() { global $wp_version; $sys_info = array(); $sys_info['WordPress'] = $wp_version; $sys_info['PHP'] = PHP_VERSION; return $sys_info; } /** * function to return various database information * @return assoc array */ 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; } /** * function to return associative array * array( table name => array( index name ( column name ))) * for each table in the database * @return array */ 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; } /** * function to return the autoincremented values of each table * @return assoc array name => sequence, or false */ 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; } } /** * function to return contents of 'wp-content/db.php' file * if the file is not existent, returns false. * @return string|boolean */ 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); echo $contents; } else { echo 'file is not readable'; } } else { echo 'file doesn\'t exist'; return false; } } /** * function to get the textarea contents and write into db.php file * @param string $contents * @return boolean */ 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; } /** * function to optimize database file * only to give vacuum command to SQLite * @return boolean */ private function optimize_db() { global $wpdb; $result = $wpdb->query("OPTIMIZE"); return $result; } /** * function to get SQLite database file size * @return string */ 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); } } /** * function to format file size to unit byte * @param integer $size * @return string */ 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]; } /** * function to echo plugins info table component */ 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': $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 ''; } } } /** * function to return output of phpinfo() as an array * See PHP Manual * @return array */ 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; } /** * function to echo PHP module info * @param string $module_name * @param string $setting_name */ 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'; } } /** * function to parse FQDBDIR and return backup database files */ private function get_backup_files() { $db_name = basename(FQDB); $names_to_exclude = array('.', '..', '.htaccess', 'debug.txt', '.ht.sqlite', $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; } /** * function to create backup file */ private function backup_db() { $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; } private function delete_backup_db() { global $utils; $domain = $utils->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; } 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($_GET['page']) && $_GET['page'] == 'setting-file') :?>

get_backup_files();?>

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