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