]> git.mxchange.org Git - friendica.git/blob - mod/install.php
Docs: add a note on adding `use` on theme.php
[friendica.git] / mod / install.php
1 <?php
2 /**
3  * @file mod/install.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Install;
9 use Friendica\Core\System;
10 use Friendica\Database\DBM;
11 use Friendica\Util\Temporal;
12
13 $install_wizard_pass = 1;
14
15 function install_init(App $a) {
16
17         // $baseurl/install/testrwrite to test if rewite in .htaccess is working
18         if ($a->argc == 2 && $a->argv[1] == "testrewrite") {
19                 echo "ok";
20                 killme();
21         }
22
23         // We overwrite current theme css, because during install we could not have a working mod_rewrite
24         // so we could not have a css at all. Here we set a static css file for the install procedure pages
25         $a->config['system']['theme'] = "../install";
26         $a->theme['stylesheet'] = System::baseUrl()."/view/install/style.css";
27
28         Install::setInstallMode();
29
30         global $install_wizard_pass;
31         if (x($_POST, 'pass')) {
32                 $install_wizard_pass = intval($_POST['pass']);
33         }
34
35 }
36
37 function install_post(App $a) {
38         global $install_wizard_pass;
39
40         switch($install_wizard_pass) {
41                 case 1:
42                 case 2:
43                         return;
44                         break; // just in case return don't return :)
45                 case 3:
46                         $urlpath = $a->get_path();
47                         $dbhost = notags(trim($_POST['dbhost']));
48                         $dbuser = notags(trim($_POST['dbuser']));
49                         $dbpass = notags(trim($_POST['dbpass']));
50                         $dbdata = notags(trim($_POST['dbdata']));
51                         $phpath = notags(trim($_POST['phpath']));
52
53                         require_once("include/dba.php");
54                         if (!dba::connect($dbhost, $dbuser, $dbpass, $dbdata)) {
55                                 $a->data['db_conn_failed'] = true;
56                         }
57
58                         return;
59                         break;
60                 case 4:
61                         $urlpath = $a->get_path();
62                         $dbhost = notags(trim($_POST['dbhost']));
63                         $dbuser = notags(trim($_POST['dbuser']));
64                         $dbpass = notags(trim($_POST['dbpass']));
65                         $dbdata = notags(trim($_POST['dbdata']));
66                         $phpath = notags(trim($_POST['phpath']));
67                         $timezone = notags(trim($_POST['timezone']));
68                         $language = notags(trim($_POST['language']));
69                         $adminmail = notags(trim($_POST['adminmail']));
70                         $rino = 1;
71
72                         // connect to db
73                         dba::connect($dbhost, $dbuser, $dbpass, $dbdata);
74
75                         Install::install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail, $rino);
76
77                         return;
78                 break;
79         }
80 }
81
82 function install_content(App $a) {
83
84         global $install_wizard_pass;
85         $o = '';
86         $wizard_status = "";
87         $install_title = L10n::t('Friendica Communications Server - Setup');
88
89
90
91         if (x($a->data, 'db_conn_failed')) {
92                 $install_wizard_pass = 2;
93                 $wizard_status = L10n::t('Could not connect to database.');
94         }
95         if (x($a->data, 'db_create_failed')) {
96                 $install_wizard_pass = 2;
97                 $wizard_status = L10n::t('Could not create table.');
98         }
99
100         $db_return_text = "";
101         if (x($a->data, 'db_installed')) {
102                 $txt = '<p style="font-size: 130%;">';
103                 $txt .= L10n::t('Your Friendica site database has been installed.') . EOL;
104                 $db_return_text .= $txt;
105         }
106
107         if (x($a->data, 'db_failed')) {
108                 $txt = L10n::t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
109                 $txt .= L10n::t('Please see the file "INSTALL.txt".') . EOL ."<hr>";
110                 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL;
111                 $db_return_text .= $txt;
112         }
113
114         if (dba::$connected) {
115                 $r = q("SELECT COUNT(*) as `total` FROM `user`");
116                 if (DBM::is_result($r) && $r[0]['total']) {
117                         $tpl = get_markup_template('install.tpl');
118                         return replace_macros($tpl, [
119                                 '$title' => $install_title,
120                                 '$pass' => '',
121                                 '$status' => L10n::t('Database already in use.'),
122                                 '$text' => '',
123                         ]);
124                 }
125         }
126
127         if (x($a->data, 'txt') && strlen($a->data['txt'])) {
128                 $db_return_text .= manual_config($a);
129         }
130
131         if ($db_return_text != "") {
132                 $tpl = get_markup_template('install.tpl');
133                 return replace_macros($tpl, [
134                         '$title' => $install_title,
135                         '$pass' => "",
136                         '$text' => $db_return_text . what_next(),
137                 ]);
138         }
139
140         switch ($install_wizard_pass) {
141                 case 1: { // System check
142
143                         if (x($_POST, 'phpath')) {
144                                 $phpath = notags(trim($_POST['phpath']));
145                         }
146
147                         list($checks, $checkspassed) = Install::check($phpath);
148
149                         $tpl = get_markup_template('install_checks.tpl');
150                         $o .= replace_macros($tpl, [
151                                 '$title' => $install_title,
152                                 '$pass' => L10n::t('System check'),
153                                 '$checks' => $checks,
154                                 '$passed' => $checkspassed,
155                                 '$see_install' => L10n::t('Please see the file "INSTALL.txt".'),
156                                 '$next' => L10n::t('Next'),
157                                 '$reload' => L10n::t('Check again'),
158                                 '$phpath' => $phpath,
159                                 '$baseurl' => System::baseUrl(),
160                         ]);
161                         return $o;
162                 }; break;
163
164                 case 2: { // Database config
165
166                         $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
167                         $dbuser = notags(trim($_POST['dbuser']));
168                         $dbpass = notags(trim($_POST['dbpass']));
169                         $dbdata = notags(trim($_POST['dbdata']));
170                         $phpath = notags(trim($_POST['phpath']));
171
172                         $adminmail = notags(trim($_POST['adminmail']));
173
174                         $tpl = get_markup_template('install_db.tpl');
175                         $o .= replace_macros($tpl, [
176                                 '$title' => $install_title,
177                                 '$pass' => L10n::t('Database connection'),
178                                 '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
179                                 '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
180                                 '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
181
182                                 '$status' => $wizard_status,
183
184                                 '$dbhost' => ['dbhost', L10n::t('Database Server Name'), $dbhost, '', 'required'],
185                                 '$dbuser' => ['dbuser', L10n::t('Database Login Name'), $dbuser, '', 'required', 'autofocus'],
186                                 '$dbpass' => ['dbpass', L10n::t('Database Login Password'), $dbpass, L10n::t("For security reasons the password must not be empty"), 'required'],
187                                 '$dbdata' => ['dbdata', L10n::t('Database Name'), $dbdata, '', 'required'],
188                                 '$adminmail' => ['adminmail', L10n::t('Site administrator email address'), $adminmail, L10n::t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'],
189
190
191
192                                 '$lbl_10' => L10n::t('Please select a default timezone for your website'),
193
194                                 '$baseurl' => System::baseUrl(),
195
196                                 '$phpath' => $phpath,
197
198                                 '$submit' => L10n::t('Submit'),
199
200                         ]);
201                         return $o;
202                 }; break;
203                 case 3: { // Site settings
204                         $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
205                         $dbuser = notags(trim($_POST['dbuser']));
206                         $dbpass = notags(trim($_POST['dbpass']));
207                         $dbdata = notags(trim($_POST['dbdata']));
208                         $phpath = notags(trim($_POST['phpath']));
209
210                         $adminmail = notags(trim($_POST['adminmail']));
211                         $timezone = ((x($_POST, 'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
212                         /* Installed langs */
213                         $lang_choices = L10n::getAvailableLanguages();
214
215                         $tpl = get_markup_template('install_settings.tpl');
216                         $o .= replace_macros($tpl, [
217                                 '$title' => $install_title,
218                                 '$pass' => L10n::t('Site settings'),
219
220                                 '$status' => $wizard_status,
221
222                                 '$dbhost' => $dbhost,
223                                 '$dbuser' => $dbuser,
224                                 '$dbpass' => $dbpass,
225                                 '$dbdata' => $dbdata,
226                                 '$phpath' => $phpath,
227
228                                 '$adminmail' => ['adminmail', L10n::t('Site administrator email address'), $adminmail, L10n::t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'],
229
230
231                                 '$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''),
232                                 '$language' => ['language', L10n::t('System Language:'), 'en', L10n::t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices],
233                                 '$baseurl' => System::baseUrl(),
234
235
236
237                                 '$submit' => L10n::t('Submit'),
238
239                         ]);
240                         return $o;
241                 }; break;
242
243         }
244 }
245
246 function manual_config(App $a) {
247         $data = htmlentities($a->data['txt'],ENT_COMPAT, 'UTF-8');
248         $o = L10n::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.');
249         $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
250         return $o;
251 }
252
253 function load_database_rem($v, $i) {
254         $l = trim($i);
255         if (strlen($l)>1 && ($l[0] == "-" || ($l[0] == "/" && $l[1] == "*"))) {
256                 return $v;
257         } else  {
258                 return $v."\n".$i;
259         }
260 }
261
262 function what_next() {
263         $baseurl = System::baseUrl();
264         return
265                 L10n::t('<h1>What next</h1>')
266                 ."<p>".L10n::t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
267                 .L10n::t('Please see the file "INSTALL.txt".')
268                 ."</p><p>"
269                 .L10n::t('Go to your new Friendica node <a href="%s/register">registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.', $baseurl)
270                 ."</p>";
271 }