예제 #1
0
파일: db-common.php 프로젝트: alx/blogsfera
function fs_get_db_status($fsdb = null)
{
    if (fs_get_db_config_type() == FS_DB_CONFIG_UNAVAILABLE) {
        return array('status' => FS_DB_NOT_CONFIGURED, 'ver' => 0);
    }
    if (!$fsdb) {
        $fsdb =& fs_get_db_conn();
    }
    if (!$fsdb) {
        return array('status' => FS_DB_NOT_INSTALLED, 'ver' => 0);
    }
    if (!$fsdb->is_connected()) {
        return array('status' => FS_DB_CONNECTION_ERROR, 'ver' => 0);
    }
    $version_table = fs_version_table();
    $sql = "SHOW TABLES LIKE '{$version_table}'";
    $results = $fsdb->query($sql);
    if ($results === FALSE) {
        return array('status' => FS_DB_GENERAL_ERROR, 'ver' => 0);
    }
    if ($results == 0) {
        return array('status' => FS_DB_NOT_INSTALLED, 'ver' => 0);
    }
    $ver = (int) $fsdb->get_var("SELECT `version` FROM `{$version_table}`");
    if ($ver == 0) {
        return array('status' => FS_DB_NOT_INSTALLED, 'ver' => 0);
    } else {
        if ($ver == FS_REQUIRED_DB_VERSION) {
            return array('status' => FS_DB_VALID, 'ver' => $ver);
        } else {
            if ($ver < FS_REQUIRED_DB_VERSION) {
                return array('status' => FS_DB_NEED_UPGRADE, 'ver' => $ver);
            } else {
                if ($ver > FS_REQUIRED_DB_VERSION) {
                    return array('status' => FS_DB_IS_NEWER_THAN_CODE, 'ver' => $ver);
                }
            }
        }
    }
    die('Logic is broken, life sucks');
}
예제 #2
0
<?php

@header('Content-type: text/html; charset=utf-8');
require_once dirname(__FILE__) . '/init.php';
require_once dirname(__FILE__) . '/db-config-utils.php';
require_once dirname(__FILE__) . '/db-common.php';
$db_config_type = fs_get_db_config_type();
$cfg_source = fs_get_config_source_desc();
?>
<!-- if the javascript for this page was not already loaded, load it now -->
<script type="text/javascript">
//<![CDATA[
if (typeof(testDBConnection) != "function")
{
	FS.loadJavaScript("<?php 
echo fs_js_url('js/page-database.js.php');
?>
");
}
//]]>
</script>


<?php 
fs_load_config();
?>
<div>
<table>
	<tr>
		<td>
		<?php 
예제 #3
0
function fs_ajax_useWordpressDB(&$response)
{
    if (!fs_ajax_assert_admin($response)) {
        return;
    }
    if (fs_get_db_config_type() != FS_DB_CONFIG_FILE) {
        $response['status'] = 'error';
        $response['message'] = fs_r('Not using configuration file');
        return;
    }
    if (!fs_in_wordpress()) {
        ajax_error($response, fs_r('Not installed inside Wordpress'));
        return;
    }
    ob_start();
    $res = unlink(FS_ABS_PATH . '/php/fs-config.php');
    $output = ob_get_clean();
    if (!$res) {
        ajax_error($response, sprintf(fs_r('Failed to delete fs-config.php : %s'), $output));
    } else {
        $response['db_status'] = 'ok';
        fs_sendDBConfig($response);
        $response['styles']['switch_to_external_system']['display'] = 'none';
    }
}
예제 #4
0
function fs_load_config()
{
    $db_config_type = fs_get_db_config_type();
    if ($db_config_type == FS_DB_CONFIG_FILE) {
        // note:
        // this is not require_once on purpose!
        // we need this to be included even if it was included before.
        require dirname(__FILE__) . '/fs-config.php';
    } else {
        if ($db_config_type == FS_DB_CONFIG_WORDPRESS) {
            require_once fs_get_wp_config_path();
            $fs_config['DB_NAME'] = DB_NAME;
            if (!fs_is_wpmu()) {
                global $table_prefix;
                $db_prefix = isset($table_prefix) ? $table_prefix : '';
            } else {
                global $wpmuBaseTablePrefix;
                $db_prefix = isset($wpmuBaseTablePrefix) ? $wpmuBaseTablePrefix : '';
            }
            $fs_config['DB_PREFIX'] = $db_prefix;
            $fs_config['DB_USER'] = DB_USER;
            $fs_config['DB_PASS'] = DB_PASSWORD;
            $fs_config['DB_HOST'] = DB_HOST;
            $GLOBALS['fs_config'] = $fs_config;
        } else {
            // load default values
            $fs_config['DB_NAME'] = 'firestats';
            $fs_config['DB_PREFIX'] = '';
            $fs_config['DB_USER'] = '';
            $fs_config['DB_PASS'] = '';
            $fs_config['DB_HOST'] = 'localhost';
            $GLOBALS['fs_config'] = $fs_config;
        }
    }
}