Dotclear

source: admin/install/wizard.php @ 217:dd9a10b462ea

Revision 217:dd9a10b462ea, 6.6 KB checked in by kozlika, 14 years ago (diff)

save -> Save (Now all "Save" button are capitalized)

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13if (isset($_SERVER['DC_RC_PATH'])) {
14     define('DC_RC_PATH',$_SERVER['DC_RC_PATH']);
15} elseif (isset($_SERVER['REDIRECT_DC_RC_PATH'])) {
16     define('DC_RC_PATH',$_SERVER['REDIRECT_DC_RC_PATH']);
17} else {
18     define('DC_RC_PATH',dirname(__FILE__).'/../../inc/config.php');
19}
20
21#  ClearBricks and DotClear classes auto-loader
22if (@is_dir('/usr/lib/clearbricks')) {
23     define('CLEARBRICKS_PATH','/usr/lib/clearbricks');
24} elseif (is_dir(dirname(__FILE__).'/../../inc/libs/clearbricks')) {
25     define('CLEARBRICKS_PATH',dirname(__FILE__).'/../../inc/libs/clearbricks');
26} elseif (isset($_SERVER['CLEARBRICKS_PATH']) && is_dir($_SERVER['CLEARBRICKS_PATH'])) {
27     define('CLEARBRICKS_PATH',$_SERVER['CLEARBRICKS_PATH']);
28}
29
30if (!defined('CLEARBRICKS_PATH') || !is_dir(CLEARBRICKS_PATH)) {
31     exit('No clearbricks path defined');
32}
33
34require CLEARBRICKS_PATH.'/_common.php';
35
36# Loading locales for detected language
37$dlang = http::getAcceptLanguage();
38if ($dlang != 'en')
39{
40     l10n::init();
41     l10n::set(dirname(__FILE__).'/../../locales/'.$dlang.'/main');
42}
43
44if (is_file(DC_RC_PATH)) {
45     http::redirect('index.php');
46}
47
48$DBDRIVER = !empty($_POST['DBDRIVER']) ? $_POST['DBDRIVER'] : 'mysql';
49$DBHOST = !empty($_POST['DBHOST']) ? $_POST['DBHOST'] : '';
50$DBNAME = !empty($_POST['DBNAME']) ? $_POST['DBNAME'] : '';
51$DBUSER = !empty($_POST['DBUSER']) ? $_POST['DBUSER'] : '';
52$DBPASSWORD = !empty($_POST['DBPASSWORD']) ? $_POST['DBPASSWORD'] : '';
53$DBPREFIX = !empty($_POST['DBPREFIX']) ? $_POST['DBPREFIX'] : 'dc_';
54
55if (!empty($_POST))
56{
57     try
58     {
59          # Tries to connect to database
60          try {
61               $con = dbLayer::init($DBDRIVER,$DBHOST,$DBNAME,$DBUSER,$DBPASSWORD);
62          } catch (Exception $e) {
63               throw new Exception('<p>' . __($e->getMessage()) . '</p>');
64          }
65         
66          # Checks system capabilites
67          require dirname(__FILE__).'/check.php';
68          if (!dcSystemCheck($con,$_e)) {
69               $can_install = false;
70               throw new Exception('<p>'.__('Dotclear cannot be installed.').'</p><ul><li>'.implode('</li><li>',$_e).'</li></ul>');
71          }
72         
73          # Check if dotclear is already installed
74          $schema = dbSchema::init($con);
75          if (in_array($DBPREFIX.'version',$schema->getTables())) {
76               throw new Exception(__('Dotclear is already installed.'));
77          }
78         
79          # Does config.php.in exist?
80          $config_in = dirname(__FILE__).'/../../inc/config.php.in';
81          if (!is_file($config_in)) {
82               throw new Exception(sprintf(__('File %s does not exist.'),$config_in));
83          }
84         
85          # Can we write config.php
86          if (!is_writable(dirname(DC_RC_PATH))) {
87               throw new Exception(sprintf(__('Cannot write %s file.'),DC_RC_PATH));
88          }
89         
90          # Creates config.php file
91          $full_conf = file_get_contents($config_in);
92         
93          writeConfigValue('DC_DBDRIVER',$DBDRIVER,$full_conf);
94          writeConfigValue('DC_DBHOST',$DBHOST,$full_conf);
95          writeConfigValue('DC_DBUSER',$DBUSER,$full_conf);
96          writeConfigValue('DC_DBPASSWORD',$DBPASSWORD,$full_conf);
97          writeConfigValue('DC_DBNAME',$DBNAME,$full_conf);
98          writeConfigValue('DC_DBPREFIX',$DBPREFIX,$full_conf);
99         
100          $admin_url = preg_replace('%install/wizard.php$%','',$_SERVER['REQUEST_URI']);
101          writeConfigValue('DC_ADMIN_URL',http::getHost().$admin_url,$full_conf);
102          writeConfigValue('DC_MASTER_KEY',md5(uniqid()),$full_conf);
103         
104          $fp = @fopen(DC_RC_PATH,'wb');
105          if ($fp === false) {
106               throw new Exception(sprintf(__('Cannot write %s file.'),DC_RC_PATH));
107          }
108          fwrite($fp,$full_conf);
109          fclose($fp);
110          chmod(DC_RC_PATH, 0666);
111         
112          $con->close();
113          http::redirect('index.php?wiz=1');
114     }
115     catch (Exception $e)
116     {
117          $err = $e->getMessage();
118     }
119}
120
121function writeConfigValue($name,$val,&$str)
122{
123     $val = str_replace("'","\'",$val);
124     $str = preg_replace('/(\''.$name.'\')(.*?)$/ms','$1,\''.$val.'\');',$str);
125}
126
127header('Content-Type: text/html; charset=UTF-8');
128?>
129<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
130<html xmlns="http://www.w3.org/1999/xhtml"
131xml:lang="en" lang="en">
132<head>
133  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
134  <meta http-equiv="Content-Script-Type" content="text/javascript" />
135  <meta http-equiv="Content-Style-Type" content="text/css" />
136  <meta http-equiv="Content-Language" content="en" />
137  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />
138  <meta name="GOOGLEBOT" content="NOSNIPPET" />
139  <title><?php echo __('Dotclear installation wizard'); ?></title>
140 
141  <style type="text/css">
142  @import url(../style/install.css);
143  </style>
144</head>
145
146<body id="dotclear-admin" class="install">
147<div id="content">
148<?php
149echo
150'<h1>'.__('Dotclear installation wizard').'</h1>'.
151'<div id="main">';
152
153if (!empty($err)) {
154     echo '<div class="error"><p><strong>'.__('Errors:').'</strong></p>'.$err.'</div>';
155} else {
156     echo '<h2>'.__('Welcome').'</h2>'.
157          '<p>'.__('To complete your Dotclear installation and start writing on your blog, '.
158               'we just need to know how to access your database and who you are. '.
159               'Just fill this two steps wizard with this information and we will be done.').'</p>'.
160          '<p class="message"><strong>'.__('Attention:').'</strong> '.
161          __('this wizard may not function on every host. If it does not work for you, '.
162               'please refer to <a href="http://dotclear.org/documentation/2.0/admin/install">'.
163               'the documentation</a> to learn how to create the <strong>config.php</strong> '.
164               'file manually.').'</p>';
165}
166
167echo
168'<h2>'.__('System information').'</h2>'.
169
170'<p>'.__('Please provide the following information needed to create your configuration file.').'</p>'.
171
172'<form action="wizard.php" method="post">'.
173'<p><label class="required" title="'.__('Required field').'">'.__('Database type:').' '.
174form::combo('DBDRIVER',array('MySQL'=>'mysql','PostgreSQL'=>'pgsql'),$DBDRIVER).'</label></p>'.
175'<p><label>'.__('Database Host Name:').' '.
176form::field('DBHOST',30,255,html::escapeHTML($DBHOST)).'</label></p>'.
177'<p><label>'.__('Database Name:').' '.
178form::field('DBNAME',30,255,html::escapeHTML($DBNAME)).'</label></p>'.
179'<p><label>'.__('Database User Name:').' '.
180form::field('DBUSER',30,255,html::escapeHTML($DBUSER)).'</label></p>'.
181'<p><label>'.__('Database Password:').' '.
182form::password('DBPASSWORD',30,255).'</label></p>'.
183'<p><label class="required" title="'.__('Required field').'">'.__('Database Tables Prefix:').' '.
184form::field('DBPREFIX',30,255,html::escapeHTML($DBPREFIX)).'</label></p>'.
185
186'<p><input type="submit" value="'.__('Save').'" /></p>'.
187'</form>';
188?>
189</div>
190</div>
191</body>
192</html>
Note: See TracBrowser for help on using the repository browser.

Sites map