Skip to content
This repository
tree: 5bddd97947
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 140 lines (109 sloc) 3.284 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
<?php

class config {
    public static $vars = array();
}

config::$vars['coscms_main'] = array();

$path = realpath('..');
if (DIRECTORY_SEPARATOR != '/') {
$path = str_replace ('\\', '/', $path);
}

define('_COS_PATH', $path);

// global array used as registry for holding debug info
$_COS_DEBUG = array();

// start timer
$_COS_DEBUG['timer']['start'] = microtime();

// set base path in debug info
$_COS_DEBUG['cos_base_path'] = _COS_PATH;

// set include path
$ini_path = ini_get('include_path');
ini_set('include_path',
    _COS_PATH . PATH_SEPARATOR . "." . PATH_SEPARATOR .
    _COS_PATH . '/lib/vendor' . PATH_SEPARATOR .
    _COS_PATH . "/lib");

// parse main config.ini file
$_COS_DEBUG['include_path'] = ini_get('include_path');

include_once "common.php";

// register::$vars['coscms_main'] is used as a register for holding global settings.
config::$vars['coscms_main'] = config::getIniFileArray(_COS_PATH . '/config/config.ini', true);

include_once "db.php";
include_once "moduleInstaller.php";

/**
*
* @param <string> $module name of module to be installed.
*/
function install_module($module){
    $install = new moduleInstaller($module);
    $ret = $install->install();
    if (!$ret) {
        print $install->error . "<br />";
    } else {
        print $install->confirm . "<br />";
    }
}

/**
* class installDb
* Only method change is connect.
* We don't try and catch in the e class
*/
class installDb extends db {
    public $sql;
    
    function __construct(){
        // make sure we have a connection
        $this->connect();
    }

    function readSql(){
        $file = _COS_PATH . '/scripts/default.sql';
        $this->sql = file_get_contents($file);
        return $this->sql;
    }
}


$version = "5.2.0";
if (version_compare( $version, phpversion(), ">=")) {
    echo 'We need PHP version 5.2.0 or higher, my version: ' . PHP_VERSION . " ERROR<br>";
} else {
    echo "Version " . phpversion() . " OK. We need $version<br />";
}



$ary = get_loaded_extensions();
if (in_array('PDO', $ary)){
    echo "PDO is installed. OK<br>";
}

if (in_array('pdo_mysql', $ary)){
    echo "PDO MySql is installed. OK<br>";
}

if (get_magic_quotes_gpc()){
    echo "magic_quotes_gpc is on. Error";
    die();

} else {
    echo "magic_quotes_gpc is off. OK<br>";
}

// try if we can connect to db given in config.ini
try {
    $db = new installDb();
} catch (PDOException $e) {
    echo "Could not connect to db with the data given in config/config.ini. Error";
    die();
}

// check to see if an install have been made.
// home menu item in table 'menus' will be set if an install has been made.
// we check if there are rows in 'menus'


try {
    $num_rows = $db->getNumRows('menus');
} catch (PDOException $e) {
    $num_rows = 0;
}

if ($num_rows == 0){
    echo "No tables or data in database. OK<br>";
    // read default sql and execute it.
    $sql = $db->readSql();
    $res = $db->rawQuery($sql);

    // if positive we install base modules.
    if ($res){
        echo install_module('error');
        echo install_module('settings');
        echo install_module('account');
        echo install_module('path_manip');
        echo install_module('content');
    }
} else {
    print "System is already installed! Error<br>";
}
Something went wrong with that request. Please try again.