]> git.mxchange.org Git - friendica.git/blob - mod/install.php
redirect to registration (rather than login) upon install complete
[friendica.git] / mod / install.php
1 <?php
2
3
4 function install_post(&$a) {
5
6         global $db;
7
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']));
14
15         require_once("dba.php");
16
17         $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, $true);
18
19         if(mysqli_connect_errno()) {
20                 notice( t('Could not connect to database.') . EOL);
21                 return;
22         }
23         else
24                 notice( t('Connected to database.') . EOL);
25
26         $tpl = load_view_file('view/htconfig.tpl');
27         $txt = replace_macros($tpl,array(
28                 '$dbhost' => $dbhost,
29                 '$dbuser' => $dbuser,
30                 '$dbpass' => $dbpass,
31                 '$dbdata' => $dbdata,
32                 '$timezone' => $timezone,
33                 '$phpath' => $phpath
34         ));
35         $result = file_put_contents('.htconfig.php', $txt);
36         if(! $result) {
37                 $a->data = $txt;
38         }
39
40         $errors = load_database($db);
41         if(! $errors) {
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). 
45
46                 session_write_close();
47
48                 require_once('session.php');
49                 session_start();
50                 session_regenerate_id();
51
52                 $_SESSION['sysmsg'] = '';
53
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() . '/register' );
58         }
59         else {
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 );
64         }
65 }
66
67
68 function install_content(&$a) {
69
70         notice( t('Welcome to Friendika.') . EOL);
71
72         $o .= check_htconfig();
73         if(strlen($o))
74                 return $o;
75
76         if(strlen($a->data)) {
77                 $o .= manual_config($a);
78                 return;
79         }
80
81         $o .= check_php($phpath);
82
83         require_once('datetime.php');
84
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'])),
93                 '$phpath' => $phpath
94         ));
95
96         return $o;
97 }
98
99 function check_php(&$phpath) {
100         $o = '';
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.');
105         }
106         return $o;
107 }
108
109 function check_htconfig() {
110
111         if(((file_exists('.htconfig.php')) && (! is_writable('.htconfig.php')))
112                 || (! is_writable('.'))) {
113
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.'); 
118         }
119
120 return $o;
121 }
122
123         
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>";
127         return $o;
128 }
129
130
131 function load_database($db) {
132
133         $str = file_get_contents('database.sql');
134         $arr = explode(';',$str);
135         $errors = 0;
136         foreach($arr as $a) {
137                 if(strlen(trim($a))) {  
138                         $r = @$db->q(trim($a));
139                         if(! $r) {
140                                 notice( t('Errors encountered creating database tables.') . $a . EOL);
141                                 $errors ++;
142                         }
143                 }
144         }
145         return $errors;
146 }