]> git.mxchange.org Git - friendica.git/blob - mod/install.php
project rename
[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                 require_once('session.php');
48                 session_start();
49                 $_SESSION['sysmsg'] = '';
50
51                 notice( t('Database import succeeded.') . EOL 
52                         . t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL 
53                         . t('Please see the file INSTALL.') . EOL );
54                 goaway($a->get_baseurl());
55         }
56         else {
57                 $db = null; // start fresh
58                 notice( t('Database import failed.') . EOL
59                         . t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL
60                         . t('Please see the file INSTALL.') . EOL );
61         }
62 }
63
64
65 function install_content(&$a) {
66
67         notice( t('Welcome to Friendika.') . EOL);
68
69         $o .= check_htconfig();
70         if(strlen($o))
71                 return $o;
72
73         if(strlen($a->data)) {
74                 $o .= manual_config($a);
75                 return;
76         }
77
78         $o .= check_php($phpath);
79
80         require_once('datetime.php');
81
82         $tpl = load_view_file('view/install_db.tpl');
83         $o .= replace_macros($tpl, array(
84                 '$tzselect' => ((x($_POST,'timezone')) ? select_timezone($_POST['timezone']) : select_timezone()),
85                 '$submit' => t('Submit'),
86                 '$dbhost' => ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'),
87                 '$dbuser' => notags(trim($_POST['dbuser'])),
88                 '$dbpass' => notags(trim($_POST['dbpass'])),
89                 '$dbdata' => notags(trim($_POST['dbdata'])),
90                 '$phpath' => $phpath
91         ));
92
93         return $o;
94 }
95
96 function check_php(&$phpath) {
97         $phpath = trim(shell_exec('which php'));
98         if(! strlen($phpath)) {
99                 $o .= <<< EOT
100 Could not find a command line version of PHP in the web server PATH. This is required. Please adjust the configuration file .htconfig.php accordingly.
101
102 EOT;
103         }
104         return $o;
105 }
106
107 function check_htconfig() {
108
109         if(((file_exists('.htconfig.php')) && (! is_writable('.htconfig.php')))
110                 || (! is_writable('.'))) {
111
112 $o .= <<< EOT
113
114 The web installer needs to be able to create a file called ".htconfig.php" in the top folder of 
115 your web server. It is unable to do so. This is most often a permission setting, as the web server 
116 may not be able to write files in your folder (even if you can).
117
118 Please check with your site documentation or support people to see if this situation can be corrected. 
119 If not, you may be required to perform a manual installation. Please see the file "INSTALL" for instructions. 
120
121 EOT;
122         }
123
124 return $o;
125 }
126
127         
128 function manual_config(&$a) {
129 $o .= <<< EOT
130 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.
131
132 <textarea rows="24" cols="80" >{$a->data}</textarea>
133 EOT;
134 return $o;
135 }
136
137
138 function load_database($db) {
139
140         $str = file_get_contents('database.sql');
141         $arr = explode(';',$str);
142         $errors = 0;
143         foreach($arr as $a) {
144                 if(strlen(trim($a))) {  
145                         $r = @$db->q(trim($a));
146                         if(! $r) {
147                                 notice( t('Errors encountered creating database tables.') . $a . EOL);
148                                 $errors ++;
149                         }
150                 }
151         }
152         return $errors;
153 }