Dotclear

source: admin/install/index.php @ 2319:abe2702e1585

Revision 2319:abe2702e1585, 14.5 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Move ex-daInstaller settings to core and install and upgrade

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 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     $rc_path = $_SERVER['DC_RC_PATH'];
15} elseif (isset($_SERVER['REDIRECT_DC_RC_PATH'])) {
16     $rc_path = $_SERVER['REDIRECT_DC_RC_PATH'];
17} else {
18     $rc_path = dirname(__FILE__).'/../../inc/config.php';
19}
20
21require dirname(__FILE__).'/../../inc/prepend.php';
22require dirname(__FILE__).'/check.php';
23
24$can_install = true;
25$err = '';
26
27# Loading locales for detected language
28$dlang = http::getAcceptLanguage();
29if ($dlang != 'en')
30{
31     l10n::init($dlang);
32     l10n::set(dirname(__FILE__).'/../../locales/'.$dlang.'/date');
33     l10n::set(dirname(__FILE__).'/../../locales/'.$dlang.'/main');
34     l10n::set(dirname(__FILE__).'/../../locales/'.$dlang.'/plugins');
35}
36
37if (!defined('DC_MASTER_KEY') || DC_MASTER_KEY == '') {
38     $can_install = false;
39     $err = '<p>'.__('Please set a master key (DC_MASTER_KEY) in configuration file.').'</p>';
40}
41
42# Check if dotclear is already installed
43$schema = dbSchema::init($core->con);
44if (in_array($core->prefix.'post',$schema->getTables())) {
45     $can_install = false;
46     $err = '<p>'.__('Dotclear is already installed.').'</p>';
47}
48
49# Check system capabilites
50if (!dcSystemCheck($core->con,$_e)) {
51     $can_install = false;
52     $err = '<p>'.__('Dotclear cannot be installed.').'</p><ul><li>'.implode('</li><li>',$_e).'</li></ul>';
53}
54
55# Get information and perform install
56$u_email = $u_firstname = $u_name = $u_login = $u_pwd = '';
57$mail_sent = false;
58if ($can_install && !empty($_POST))
59{
60     $u_email = !empty($_POST['u_email']) ? $_POST['u_email'] : null;
61     $u_firstname = !empty($_POST['u_firstname']) ? $_POST['u_firstname'] : null;
62     $u_name = !empty($_POST['u_name']) ? $_POST['u_name'] : null;
63     $u_login = !empty($_POST['u_login']) ? $_POST['u_login'] : null;
64     $u_pwd = !empty($_POST['u_pwd']) ? $_POST['u_pwd'] : null;
65     $u_pwd2 = !empty($_POST['u_pwd2']) ? $_POST['u_pwd2'] : null;
66     
67     try
68     {
69          # Check user information
70          if (empty($u_login)) {
71               throw new Exception(__('No user ID given'));
72          }
73          if (!preg_match('/^[A-Za-z0-9@._-]{2,}$/',$u_login)) {
74               throw new Exception(__('User ID must contain at least 2 characters using letters, numbers or symbols.'));
75          }
76          if ($u_email && !text::isEmail($u_email)) {
77               throw new Exception(__('Invalid email address'));
78          }
79         
80          if (empty($u_pwd)) {
81               throw new Exception(__('No password given'));
82          }
83          if ($u_pwd != $u_pwd2) {
84               throw new Exception(__("Passwords don't match"));
85          }
86          if (strlen($u_pwd) < 6) {
87               throw new Exception(__('Password must contain at least 6 characters.'));
88          }
89         
90          # Try to guess timezone
91          $default_tz = 'Europe/London';
92          if (!empty($_POST['u_date']) && function_exists('timezone_open'))
93          {
94               if (preg_match('/\((.+)\)$/',$_POST['u_date'],$_tz)) {
95                    $_tz = $_tz[1];
96                    $_tz = @timezone_open($_tz);
97                    if ($_tz instanceof DateTimeZone) {
98                         $_tz = @timezone_name_get($_tz);
99                         if ($_tz) {
100                              $default_tz = $_tz;
101                         }
102                    }
103                    unset($_tz);
104               }
105          }
106         
107          # Create schema
108          $_s = new dbStruct($core->con,$core->prefix);
109          require dirname(__FILE__).'/../../inc/dbschema/db-schema.php';
110         
111          $si = new dbStruct($core->con,$core->prefix);
112          $changes = $si->synchronize($_s);
113         
114          # Create user
115          $cur = $core->con->openCursor($core->prefix.'user');
116          $cur->user_id = $u_login;
117          $cur->user_super = 1;
118          $cur->user_pwd = crypt::hmac(DC_MASTER_KEY,$u_pwd);
119          $cur->user_name = (string) $u_name;
120          $cur->user_firstname = (string) $u_firstname;
121          $cur->user_email = (string) $u_email;
122          $cur->user_lang = $dlang;
123          $cur->user_tz = $default_tz;
124          $cur->user_creadt = date('Y-m-d H:i:s');
125          $cur->user_upddt = date('Y-m-d H:i:s');
126          $cur->user_options = serialize($core->userDefaults());
127          $cur->insert();
128         
129          $core->auth->checkUser($u_login);
130         
131          $admin_url = preg_replace('%install/index.php$%','',$_SERVER['REQUEST_URI']);
132          $root_url = preg_replace('%/admin/install/index.php$%','',$_SERVER['REQUEST_URI']);
133         
134          # Create blog
135          $cur = $core->con->openCursor($core->prefix.'blog');
136          $cur->blog_id = 'default';
137          $cur->blog_url = http::getHost().$root_url.'/index.php?';
138          $cur->blog_name = __('My first blog');
139          $core->addBlog($cur);
140          $core->blogDefaults($cur->blog_id);
141         
142          $blog_settings = new dcSettings($core,'default');
143          $blog_settings->addNamespace('system');
144          $blog_settings->system->put('blog_timezone',$default_tz);
145          $blog_settings->system->put('lang',$dlang);
146          $blog_settings->system->put('public_url',$root_url.'/public');
147          $blog_settings->system->put('themes_url',$root_url.'/themes');
148         
149          # date and time formats
150          $formatDate = __('%A, %B %e %Y');
151          $date_formats = array('%Y-%m-%d','%m/%d/%Y','%d/%m/%Y','%Y/%m/%d','%d.%m.%Y','%b %e %Y','%e %b %Y','%Y %b %e',
152          '%a, %Y-%m-%d','%a, %m/%d/%Y','%a, %d/%m/%Y','%a, %Y/%m/%d','%B %e, %Y','%e %B, %Y','%Y, %B %e','%e. %B %Y',
153          '%A, %B %e, %Y','%A, %e %B, %Y','%A, %Y, %B %e','%A, %Y, %B %e','%A, %e. %B %Y');
154          $time_formats = array('%H:%M','%I:%M','%l:%M','%Hh%M','%Ih%M','%lh%M');
155          if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
156               $formatDate = preg_replace('#(?<!%)((?:%%)*)%e#','\1%#d',$formatDate);
157               $date_formats = array_map(create_function('$f',
158                                               'return str_replace(\'%e\',\'%#d\',$f);'
159                                               ),$date_formats);
160          }
161          $blog_settings->system->put('date_format',$formatDate);
162          $blog_settings->system->put('date_formats',serialize($date_formats),'string','Date formats examples',true);
163          $blog_settings->system->put('time_formats',serialize($time_formats),'string','Time formats examples',true);
164         
165          # Add repository URL for themes and plugins
166          $blog_settings->system->put('store_plugin_url','http://update.dotaddict.org/dc2/plugins.xml','string','Plugins XML feed location',true);
167          $blog_settings->system->put('store_theme_url','http://update.dotaddict.org/dc2/themes.xml','string','Themes XML feed location',true);
168         
169          # Add Dotclear version
170          $cur = $core->con->openCursor($core->prefix.'version');
171          $cur->module = 'core';
172          $cur->version = (string) DC_VERSION;
173          $cur->insert();
174         
175          # Create first post
176          $core->setBlog('default');
177         
178          $cur = $core->con->openCursor($core->prefix.'post');
179          $cur->user_id = $u_login;
180          $cur->post_format = 'xhtml';
181          $cur->post_lang = $dlang;
182          $cur->post_title = __('Welcome to Dotclear!');
183          $cur->post_content = '<p>'.__('This is your first entry. When you\'re ready '.
184               'to blog, log in to edit or delete it.').'</p>';
185          $cur->post_content_xhtml = $cur->post_content;
186          $cur->post_status = 1;
187          $cur->post_open_comment = 1;
188          $cur->post_open_tb = 0;
189          $post_id = $core->blog->addPost($cur);
190         
191          # Add a comment to it
192          $cur = $core->con->openCursor($core->prefix.'comment');
193          $cur->post_id = $post_id;
194          $cur->comment_tz = $default_tz;
195          $cur->comment_author = __('Dotclear Team');
196          $cur->comment_email = 'contact@dotclear.net';
197          $cur->comment_site = 'http://www.dotclear.org/';
198          $cur->comment_content = __("<p>This is a comment.</p>\n<p>To delete it, log in and ".
199               "view your blog's comments. Then you might remove or edit it.</p>");
200          $core->blog->addComment($cur);
201         
202          #  Plugins initialization
203          define('DC_CONTEXT_ADMIN',true);
204          $core->plugins->loadModules(DC_PLUGINS_ROOT);
205          $plugins_install = $core->plugins->installModules();
206         
207          # Add dashboard module options
208          $core->auth->user_prefs->addWorkspace('dashboard');
209          $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean','',null,true);
210          $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean','',null,true);
211          $core->auth->user_prefs->dashboard->put('quickentry',true,'boolean','',null,true);
212
213          # Add accessibility options
214          $core->auth->user_prefs->addWorkspace('accessibility');
215          $core->auth->user_prefs->accessibility->put('nodragdrop',false,'boolean','',null,true);
216
217          # Add user interface options
218          $core->auth->user_prefs->addWorkspace('interface');
219          $core->auth->user_prefs->interface->put('enhanceduploader',true,'boolean','',null,true);
220
221          # Add default favorites
222          $core->favs = new dcFavorites($core);
223          $init_favs = array('posts','new_post','newpage','comments','categories','media','blog_theme','widgets','simpleMenu','prefs','help');
224          $core->favs->setFavoriteIDs($init_favs,true);
225
226          $step = 1;
227     }
228     catch (Exception $e)
229     {
230          $err = $e->getMessage();
231     }
232}
233
234if (!isset($step)) {
235     $step = 0;
236}
237header('Content-Type: text/html; charset=UTF-8');
238?>
239<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
240<html xmlns="http://www.w3.org/1999/xhtml"
241xml:lang="en" lang="en">
242<head>
243  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
244  <meta http-equiv="Content-Script-Type" content="text/javascript" />
245  <meta http-equiv="Content-Style-Type" content="text/css" />
246  <meta http-equiv="Content-Language" content="en" />
247  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />
248  <meta name="GOOGLEBOT" content="NOSNIPPET" />
249  <title><?php echo __('Dotclear Install'); ?></title>
250 
251     <link rel="stylesheet" href="../style/install.css" type="text/css" media="screen" />
252
253  <script type="text/javascript" src="../js/jquery/jquery.js"></script>
254  <?php echo dcPage::jsLoad('../js/jquery/jquery.pwstrength.js'); ?>
255  <script type="text/javascript">
256  //<![CDATA[
257  $(function() {
258    var login_re = new RegExp('[^A-Za-z0-9@._-]+','g');
259    $('#u_firstname').keyup(function() {
260      var login = this.value.toLowerCase().replace(login_re,'').substring(0,32);
261      $('#u_login').val(login);
262    });
263    $('#u_login').keyup(function() {
264      $(this).val(this.value.replace(login_re,''));
265    });
266   
267     <?php echo "\$('#u_pwd').pwstrength({texts: ['".
268                    sprintf(__('Password strength: %s'),__('very weak'))."', '".
269                    sprintf(__('Password strength: %s'),__('weak'))."', '".
270                    sprintf(__('Password strength: %s'),__('mediocre'))."', '".
271                    sprintf(__('Password strength: %s'),__('strong'))."', '".
272                    sprintf(__('Password strength: %s'),__('very strong'))."']});\n"; ?>
273   
274    $('#u_login').parent().after($('<input type="hidden" name="u_date" value="' + Date().toLocaleString() + '" />'));
275   
276    var password_link = $('<a href="#" id="obfus"><?php echo(__('show')); ?></a>').click(function() {
277               $('#password').show();
278               $(this).remove();
279               return false;
280          });
281    $('#password').hide().before(password_link);
282  });
283  //]]>
284  </script>
285</head>
286
287<body id="dotclear-admin" class="install">
288<div id="content">
289<?php
290echo
291'<h1>'.__('Dotclear installation').'</h1>'.
292'<div id="main">';
293
294if (!is_writable(DC_TPL_CACHE)) {
295     echo '<div class="error"><p>'.sprintf(__('Cache directory %s is not writable.'),DC_TPL_CACHE).'</p></div>';
296}
297
298if ($can_install && !empty($err)) {
299     echo '<div class="error"><p><strong>'.__('Errors:').'</strong></p>'.$err.'</div>';
300}
301
302if (!empty($_GET['wiz'])) {
303     echo '<p class="success">'.__('Configuration file has been successfully created.').'</p>';
304}
305
306if ($can_install && $step == 0)
307{
308     echo
309     '<h2>'.__('User information').'</h2>'.
310     
311     '<p>'.__('Please provide the following information needed to create the first user.').'</p>'.
312     
313     '<form action="index.php" method="post">'.
314     '<fieldset><legend>'.__('User information').'</legend>'.
315     '<p><label for="u_firstname">'.__('First Name:').'</label> '.
316     form::field('u_firstname',30,255,html::escapeHTML($u_firstname)).'</p>'.
317     '<p><label for="u_name">'.__('Last Name:').'</label> '.
318     form::field('u_name',30,255,html::escapeHTML($u_name)).'</p>'.
319     '<p><label for="u_email">'.__('Email:').'</label> '.
320     form::field('u_email',30,255,html::escapeHTML($u_email)).'</p>'.
321     '</fieldset>'.
322     
323     '<fieldset><legend>'.__('Username and password').'</legend>'.
324     '<p><label for="u_login" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Username:').' '.
325     form::field('u_login',30,32,html::escapeHTML($u_login)).'</label></p>'.
326     '<div class="pw-table">'.
327          '<p class="pw-cell">'.
328               '<label for="u_pwd" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('New password:').'</label>'.
329               form::password('u_pwd',30,255,'','','',false,' data-indicator="pwindicator" ').
330          '</p>'.
331          '<div id="pwindicator">'.
332          '    <div class="bar"></div>'.
333          '    <p class="label no-margin"></p>'.
334          '</div>'.
335     '</div>'.
336     '<p><label for="u_pwd2" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Confirm password:').' '.
337     form::password('u_pwd2',30,255).'</label></p>'.
338     '</fieldset>'.
339     
340     '<p><input type="submit" value="'.__('Save').'" /></p>'.
341     '</form>';
342}
343elseif ($can_install && $step == 1)
344{
345     # Plugins install messages
346     $plugins_install_result = '';
347     if (!empty($plugins_install['success']))
348     {
349          $plugins_install_result .= '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>';
350          foreach ($plugins_install['success'] as $k => $v) {
351               $plugins_install_result .= '<li>'.$k.'</li>';
352          }
353          $plugins_install_result .= '</ul></div>';
354     }
355     if (!empty($plugins_install['failure']))
356     {
357          $plugins_install_result .= '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
358          foreach ($plugins_install['failure'] as $k => $v) {
359               $plugins_install_result .= '<li>'.$k.' ('.$v.')</li>';
360          }
361          $plugins_install_result .= '</ul></div>';
362     }
363     
364     echo
365     '<h2>'.__('All done!').'</h2>'.
366     
367     $plugins_install_result.
368     
369     '<p class="success">'.__('Dotclear has been successfully installed. Here is some useful information you should keep.').'</p>'.
370     
371     '<h3>'.__('Your account').'</h3>'.
372     '<ul>'.
373     '<li>'.__('Username:').' <strong>'.html::escapeHTML($u_login).'</strong></li>'.
374     '<li>'.__('Password:').' <strong id="password">'.html::escapeHTML($u_pwd).'</strong></li>'.
375     '</ul>'.
376     
377     '<h3>'.__('Your blog').'</h3>'.
378     '<ul>'.
379     '<li>'.__('Blog address:').' <strong>'.html::escapeHTML(http::getHost().$root_url).'/index.php?</strong></li>'.
380     '<li>'.__('Administration interface:').' <strong>'.html::escapeHTML(http::getHost().$admin_url).'</strong></li>'.
381     '</ul>'.
382     
383     '<form action="../auth.php" method="post">'.
384     '<p><input type="submit" value="'.__('Manage your blog now').'" />'.
385     form::hidden(array('user_id'),html::escapeHTML($u_login)).
386     form::hidden(array('user_pwd'),html::escapeHTML($u_pwd)).
387     '</p>'.
388     '</form>';
389}
390elseif (!$can_install)
391{
392     echo '<h2>'.__('Installation can not be completed').'</h2>'.
393     '<div class="error"><p><strong>'.__('Errors:').'</strong></p>'.$err.'</div>'.
394     '<p>'.__('For the said reasons, Dotclear can not be installed. '.
395          'Please refer to <a href="http://dotclear.org/documentation/2.0/admin/install">'.
396          'the documentation</a> to learn how to correct the problem.').'</p>';
397}
398?>
399</div>
400</div>
401</body>
402</html>
Note: See TracBrowser for help on using the repository browser.

Sites map