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 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
21 if(! mysql_connect_errno()) {
22 $r = q("CREATE DATABASE '%s'",
26 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, $true);
28 if(mysqli_connect_errno()) {
29 notice( t('Could not create/connect to database.') . EOL);
34 notice( t('Connected to database.') . EOL);
36 $tpl = load_view_file('view/htconfig.tpl');
37 $txt = replace_macros($tpl,array(
42 '$timezone' => $timezone,
45 $result = file_put_contents('.htconfig.php', $txt);
50 $errors = load_database($db);
52 // Our sessions normally are stored in the database. But as we have only managed
53 // to get it bootstrapped milliseconds ago, we have to apply a bit of trickery so
54 // that you'll see the following important notice (which is stored in the session).
56 session_write_close();
58 require_once('session.php');
60 session_regenerate_id();
62 $_SESSION['sysmsg'] = '';
64 notice( t('Database import succeeded.') . EOL
65 . t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL
66 . t('Please see the file INSTALL.') . EOL );
67 goaway($a->get_baseurl() . '/register' );
70 $db = null; // start fresh
71 notice( t('Database import failed.') . EOL
72 . t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL
73 . t('Please see the file INSTALL.') . EOL );
78 function install_content(&$a) {
82 notice( t('Welcome to Friendika.') . EOL);
87 $o .= check_htconfig();
91 if(strlen($a->data)) {
92 $o .= manual_config($a);
96 $o .= check_php($phpath);
98 require_once('datetime.php');
100 $tpl = load_view_file('view/install_db.tpl');
101 $o .= replace_macros($tpl, array(
102 '$tzselect' => ((x($_POST,'timezone')) ? select_timezone($_POST['timezone']) : select_timezone()),
103 '$submit' => t('Submit'),
104 '$dbhost' => ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'),
105 '$dbuser' => notags(trim($_POST['dbuser'])),
106 '$dbpass' => notags(trim($_POST['dbpass'])),
107 '$dbdata' => notags(trim($_POST['dbdata'])),
114 function check_php(&$phpath) {
116 $phpath = trim(shell_exec('which php'));
117 if(! strlen($phpath)) {
118 $o .= t('Could not find a command line version of PHP in the web server PATH.');
119 $o .= t('This is required. Please adjust the configuration file .htconfig.php accordingly.');
124 function check_funcs() {
125 if(! function_exists('curl_init'))
126 notice( t('Error: libCURL PHP module required but not installed.') . EOL);
127 if(! function_exists('imagecreatefromjpeg'))
128 notice( t('Error: GD graphics PHP module with JPEG support required but not installed.') . EOL);
129 if(! function_exists('openssl_public_encrypt'))
130 notice( t('Error: openssl PHP module required but not installed.') . EOL);
131 if(! function_exists('mysqli_connect'))
132 notice( t('Error: mysqli PHP module required but not installed.') . EOL);
136 function check_htconfig() {
138 if(((file_exists('.htconfig.php')) && (! is_writable('.htconfig.php')))
139 || (! is_writable('.'))) {
141 $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.');
142 $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.');
143 $o .= t('Please check with your site documentation or support people to see if this situation can be corrected.');
144 $o .= t('If not, you may be required to perform a manual installation. Please see the file "INSTALL" for instructions.');
151 function manual_config(&$a) {
152 $data = htmlentities($a->data);
153 $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.');
154 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
159 function load_database($db) {
161 $str = file_get_contents('database.sql');
162 $arr = explode(';',$str);
164 foreach($arr as $a) {
165 if(strlen(trim($a))) {
166 $r = @$db->q(trim($a));
168 notice( t('Errors encountered creating database tables.') . $a . EOL);