4 function install_post(&$a) {
8 $dbhost = notags(trim($_POST['dbhost']));
9 $dbuser = notags(trim($_POST['dbuser']));
10 $dbpass = notags(trim($_POST['dbpass']));
11 $dbdata = notags(trim($_POST['dbdata']));
12 $timezone = notags(trim($_POST['timezone']));
13 $phpath = notags(trim($_POST['phpath']));
15 require_once("dba.php");
17 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, $true);
19 if(mysqli_connect_errno()) {
20 notice( t('Could not connect to database.') . EOL);
24 notice( t('Connected to database.') . EOL);
26 $tpl = load_view_file('view/htconfig.tpl');
27 $txt = replace_macros($tpl,array(
32 '$timezone' => $timezone,
35 $result = file_put_contents('.htconfig.php', $txt);
40 $errors = load_database($db);
42 // Our sessions normally are stored in the database. But as we have only managed
43 // to get it bootstrapped milliseconds ago, we have to apply a bit of trickery so
44 // that you'll see the following important notice (which is stored in the session).
46 session_write_close();
48 require_once('session.php');
50 session_regenerate_id();
52 $_SESSION['sysmsg'] = '';
54 notice( t('Database import succeeded.') . EOL
55 . t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL
56 . t('Please see the file INSTALL.') . EOL );
57 goaway($a->get_baseurl());
60 $db = null; // start fresh
61 notice( t('Database import failed.') . EOL
62 . t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL
63 . t('Please see the file INSTALL.') . EOL );
68 function install_content(&$a) {
70 notice( t('Welcome to Friendika.') . EOL);
72 $o .= check_htconfig();
76 if(strlen($a->data)) {
77 $o .= manual_config($a);
81 $o .= check_php($phpath);
83 require_once('datetime.php');
85 $tpl = load_view_file('view/install_db.tpl');
86 $o .= replace_macros($tpl, array(
87 '$tzselect' => ((x($_POST,'timezone')) ? select_timezone($_POST['timezone']) : select_timezone()),
88 '$submit' => t('Submit'),
89 '$dbhost' => ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'),
90 '$dbuser' => notags(trim($_POST['dbuser'])),
91 '$dbpass' => notags(trim($_POST['dbpass'])),
92 '$dbdata' => notags(trim($_POST['dbdata'])),
99 function check_php(&$phpath) {
101 $phpath = trim(shell_exec('which php'));
102 if(! strlen($phpath)) {
103 $o .= t('Could not find a command line version of PHP in the web server PATH.');
104 $o .= t('This is required. Please adjust the configuration file .htconfig.php accordingly.');
109 function check_htconfig() {
111 if(((file_exists('.htconfig.php')) && (! is_writable('.htconfig.php')))
112 || (! is_writable('.'))) {
114 $o = t('The web installer needs to be able to create a file called ".htconfig.php" in the top folder of your web server and it is unable to do so.');
115 $o .= t('This is most often a permission setting, as the web server may not be able to write files in your folder - even if you can.');
116 $o .= t('Please check with your site documentation or support people to see if this situation can be corrected.');
117 $o .= t('If not, you may be required to perform a manual installation. Please see the file "INSTALL" for instructions.');
124 function manual_config(&$a) {
125 $o = t('The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.');
126 $o .= "<textarea rows=\"24\" cols=\"80\" >{$a->data}</textarea>";
131 function load_database($db) {
133 $str = file_get_contents('database.sql');
134 $arr = explode(';',$str);
136 foreach($arr as $a) {
137 if(strlen(trim($a))) {
138 $r = @$db->q(trim($a));
140 notice( t('Errors encountered creating database tables.') . $a . EOL);