4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2012 The Nucleus Group
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
11 * (see nucleus/documentation/index.html#license for more info)
\r
13 * This script will install the Nucleus tables in your SQL-database,
\r
14 * and initialize the data in those tables.
\r
18 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
19 * @copyright Copyright (C) 2002-2012 The Nucleus Group
\r
20 * @version $Id: index.php 1745 2012-04-12 23:45:47Z sakamocchi $
\r
23 /* global values initialize */
\r
26 /* reporting all errors for support */
\r
27 error_reporting(E_ALL);
\r
29 $minimum_php_version = '5.0.6';
\r
30 $minimum_mysql_version = '3.23';
\r
32 $page_footer_copyright = '© 2001-2012 The Nucleus Groupe . Running Nucleus CMS v4.00';
\r
34 // begin if: server's PHP version is below the minimum; halt installation
\r
35 if ( version_compare(PHP_VERSION, $minimum_php_version, '<') )
\r
37 exit('<div style="font-size: xx-large;"> Nucleus requires at least PHP version ' . $minimum_php_version . '</div>');
\r
40 // make sure there's no unnecessary escaping: # set_magic_quotes_runtime(0);
\r
41 if ( version_compare(PHP_VERSION, '5.3.0', '<') )
\r
43 ini_set('magic_quotes_runtime', '0');
\r
46 /* default installed plugins and skins */
\r
47 $aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles');
\r
48 $aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default');
\r
50 // Check if some important files
\r
53 /* i18n class is needed for internationalization */
\r
54 include_once('../nucleus/libs/i18n.php');
\r
55 if ( !i18n::init('UTF-8', '../nucleus/locales') )
\r
57 exit('<div style="font-size: xx-large;"> Failed to initialize iconv or mbstring extension. Would you please contact the administrator of your PHP server? </div>');
\r
60 // include core classes that are needed for login & plugin handling
\r
62 // added for 3.5 sql_* wrapper
\r
63 global $MYSQL_HANDLER;
\r
65 if ( !isset($MYSQL_HANDLER) )
\r
67 $MYSQL_HANDLER = array('mysql', '');
\r
69 // check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x
\r
70 if ( !function_exists('mysql_query') && !function_exists('mysqli_query') )
\r
72 exit('<div style="font-size: xx-large;"> Your PHP version does not have support for MySQL :( </div>');
\r
75 include_once('../nucleus/libs/sql/sql.php');
\r
78 if ( count($_GET) == 0 && count($_POST) == 0 )
\r
80 unset($_SESSION['param_manager']);
\r
83 // restore the $param from the session
\r
84 if ( array_key_exists('param_manager', $_SESSION) )
\r
86 $param = $_SESSION['param_manager'];
\r
90 $param = new ParamManager();
\r
93 // include translation file
\r
94 if ( array_key_exists('locale', $_POST) ) $param->set_locale();
\r
95 i18n::set_current_locale($param->locale);
\r
96 $translation_file = './locales/' . i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php';
\r
97 if ( !file_exists($translation_file) )
\r
99 $translation_file = './locales/en_Latn_US.UTF-8.php';
\r
101 include($translation_file);
\r
105 // $param is saved to the session
\r
106 if ( isset($param) )
\r
108 $_SESSION['param_manager'] = $param;
\r
112 unset($_SESSION['param_manager']);
\r
119 function do_action()
\r
123 if ( array_key_exists('action', $_POST) )
\r
125 $isPostback = true;
\r
129 $isPostback = false;
\r
133 if ( array_key_exists('mode', $_REQUEST) )
\r
135 if ( $_REQUEST['mode'] == 'detail' )
\r
137 $param->set_state('detail');
\r
139 elseif ( $_REQUEST['mode'] == 'simple' )
\r
141 $param->set_state('mysql');
\r
145 // input parameter check
\r
148 switch ( $param->state )
\r
151 $param->set_locale();
\r
152 $param->set_state('mysql');
\r
153 $isPostback = false;
\r
156 if ( count($param->check_mysql_parameters()) == 0 )
\r
158 $param->set_state('weblog');
\r
159 $isPostback = false;
\r
163 if ( count($param->check_user_parameters()) == 0
\r
164 && count($param->check_weblog_parameters()) == 0 )
\r
166 $param->set_state('install');
\r
167 $isPostback = false;
\r
171 if ( $param->check_all_parameters() )
\r
173 $param->set_state('install');
\r
174 $isPostback = false;
\r
182 switch ( $param->state )
\r
185 show_select_locale_form();
\r
188 show_database_setting_form($isPostback);
\r
191 show_blog_setting_form($isPostback);
\r
194 show_detail_setting_form($isPostback);
\r
197 show_install_complete_form();
\r
204 * header tag of the installation screens
\r
206 function show_header()
\r
210 /* HTTP 1.1 application for no caching */
\r
211 header("Cache-Control: no-cache, must-revalidate");
\r
212 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
\r
213 header('Content-Type: text/html; charset=' . i18n::get_current_charset());
\r
215 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
\r
216 <html xmlns="http://www.w3.org/1999/xhtml">
\r
218 <title><?php echo _TITLE; ?></title>
\r
219 <link rel="stylesheet" type="text/css" href="./styles/inst.css" />
\r
220 <style type="text/css">
\r
222 <?php echo _BODYFONTSTYLE; ?>
\r
225 <script type="text/javascript">
\r
226 function SelectText( element ) {
\r
227 window.setTimeout( function() { element.select() }, 0 );
\r
229 var isSubmit = false;
\r
230 function OnceSubmit() {
\r
233 window.setTimeout( function() { isSubmit = false; }, 10000 );
\r
242 <div id="navigation">
\r
243 <h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>
\r
246 if ( in_array($param->state, array('mysql', 'weblog', 'install')) )
\r
248 echo '<li>', _STEP1, '</li><li';
\r
249 if ( $param->state == 'mysql' )
\r
251 echo ' class="gry"';
\r
253 echo '> > ', _STEP2, '</li><li';
\r
254 if ( in_array($param->state, array('mysql', 'weblog')) )
\r
256 echo ' class="gry"';
\r
258 echo '> > ', _STEP3, "</li>\n";
\r
260 if ( in_array($param->state, array('mysql', 'weblog', 'detail')) )
\r
262 echo '<li class="rightbox">';
\r
263 if ( in_array($param->state, array('mysql', 'weblog')) )
\r
265 echo '<a href="./?mode=detail">', _MODE2, '</a>';
\r
269 echo '<a href="./?mode=simple">', _MODE1, '</a>';
\r
281 * footer tag of the installation screens
\r
283 function show_footer()
\r
285 global $page_footer_copyright;
\r
288 <?php echo $page_footer_copyright; ?>
\r
296 * Display the form for language select
\r
298 function show_select_locale_form()
\r
301 $localelist = i18n::get_available_locale_list();
\r
302 $locales = array();
\r
303 foreach ( $localelist as $locale ) {
\r
304 $checkfile = './locales/' . $locale . '.' . i18n::get_current_charset() . '.php';
\r
305 $locales[] = array( $locale, (!file_exists($checkfile) ? '* ' : '') . $locale );
\r
308 <div id="container">
\r
309 <p style="font-size:152%;font-weight:bold;">
\r
310 Select your locale:
\r
312 <form method="post" action="./index.php">
\r
315 <select name="locale">
\r
317 // Get the browser language that can be displayed
\r
318 // TODO: default locale select simple implementation
\r
319 $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
\r
320 $language = (is_array($languages) && count($languages) > 0) ? preg_replace('#^([\w]+).*$#', '$1', $languages[0]) : '';
\r
322 foreach ( $locales as $locale )
\r
324 echo "<option value=\"$locale[0]\"";
\r
325 if ( i18n::strpos($locale[0], $language) === 0 )
\r
329 echo ">$locale[1]</option>\n";
\r
333 <p>Nucleus is installed in the selected locale, the locale of the Asterisk prefixed will be displayed in English because there is no translation of the installer file.</p>
\r
334 <p>We will wait for the translator by volunteers!</p>
\r
337 <button type="submit" name="action" value="locale" class="sbt_arw">START</button>
\r
346 * Display the form to set up a database
\r
347 * @param bool $isPostback
\r
349 function show_database_setting_form($isPostback)
\r
351 global $param, $minimum_mysql_version;
\r
353 $config_writable = canConfigFileWritable();
\r
354 $mysql_version = getMySqlVersion();
\r
356 <div id="container">
\r
359 echo _SIMPLE_NAVI1;
\r
360 if ( $config_writable != '' )
\r
362 echo '<span class="err">', $config_writable, '</span>';
\r
364 if ( $mysql_version == '0.0.0' )
\r
366 echo '<span class="err">', _DBVERSION_UNKOWN, '</span>';
\r
368 elseif ( version_compare($mysql_version, $minimum_mysql_version, '<') )
\r
370 echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';
\r
374 <form method="post" action="./index.php">
\r
376 <h2><?php echo _DB_HEADER; ?></h2>
\r
381 $errors = $param->check_mysql_parameters();
\r
382 if ( is_array($errors) )
\r
384 foreach ( $errors as $error )
\r
386 echo '<span class="err">', $error, "</span>\n";
\r
394 <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>
\r
395 <td><input type="text" name="mysql_host" value="<?php echo $param->mysql_host; ?>" /></td>
\r
398 <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>
\r
399 <td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>
\r
402 <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>
\r
403 <td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>
\r
406 <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>
\r
407 <td><input type="text" name="mysql_database" value="<?php echo $param->mysql_database; ?>" /></td>
\r
411 <button type="submit" name="mode" value="detail" class="sbt_sqr"><?php echo _MODE2; ?></button>
\r
412 <button type="submit" name="action" value="mysql" class="sbt_arw"><?php echo _NEXT; ?></button>
\r
415 <?php echo _DB_TEXT1; ?>
\r
424 * Displays a form to the blog settings
\r
425 * @param bool $isPostback
\r
427 function show_blog_setting_form($isPostback)
\r
431 <div id="container">
\r
433 <?php echo _SIMPLE_NAVI2; ?>
\r
435 <form method="post" action="./index.php">
\r
437 <h2><?php echo _BLOG_HEADER; ?></h2>
\r
442 $errors = $param->check_weblog_parameters();
\r
443 if ( is_array($errors) )
\r
445 foreach ( $errors as $error )
\r
447 echo '<span class="err">', $error, "</span>\n";
\r
455 <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>
\r
456 <td><input type="text" name="blog_name" value="<?php echo $param->blog_name; ?>" /></td>
\r
459 <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>
\r
460 <td><input type="text" name="blog_shortname" value="<?php echo $param->blog_shortname; ?>" /></td>
\r
466 <h2><?php echo _ADMIN_HEADER; ?></h2>
\r
471 $errors = $param->check_user_parameters();
\r
472 if ( is_array($errors) )
\r
474 foreach ( $errors as $error )
\r
476 echo '<span class="err">', $error, "</span>\n";
\r
484 <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>
\r
485 <td><input type="text" name="user_realname" value="<?php echo $param->user_realname; ?>" /></td>
\r
488 <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>
\r
489 <td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>
\r
492 <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>
\r
493 <td><input type="password" name="user_password" /></td>
\r
496 <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>
\r
497 <td><input type="password" name="user_password2" /></td>
\r
500 <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>
\r
501 <td><input type="text" name="user_email" value="<?php echo $param->user_email; ?>" /></td>
\r
505 <button type="submit" name="action" value="weblog" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>
\r
514 * Displays a form to the detail settings
\r
515 * @param bool $isPostback
\r
517 function show_detail_setting_form($isPostback)
\r
519 global $param, $minimum_mysql_version;
\r
521 $mysql_version = getMySqlVersion();
\r
523 <div id="container_detailed">
\r
525 <?php echo _DETAIL_NAVI1; ?>
\r
527 if ( $isPostback && !$param->check_all_parameters() )
\r
529 echo '<span class="err">', _VALID_ERROR, "</span>\n";
\r
534 <li>PHP: <?php echo phpversion(); ?></li>
\r
537 echo ($mysql_version == '0.0.0') ? _DBVERSION_UNKOWN : $mysql_version;
\r
538 if ( version_compare($mysql_version, $minimum_mysql_version, '<') )
\r
540 echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';
\r
544 <form method="post" action="">
\r
547 <h2><?php echo _DETAIL_HEADER1; ?></h2>
\r
552 $errors = $param->check_mysql_parameters();
\r
553 if ( is_array($errors) )
\r
555 foreach ( $errors as $error )
\r
557 echo '<span class="err">', $error, "</span>\n";
\r
565 <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>
\r
566 <td><input type="text" name="mysql_host" value="<?php echo $param->mysql_host; ?>" /></td>
\r
569 <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>
\r
570 <td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>
\r
573 <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>
\r
574 <td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>
\r
577 <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>
\r
578 <td><input type="text" name="mysql_database" value="<?php echo $param->mysql_database; ?>" /></td>
\r
581 <th><span class="nam"><?php echo _DB_FIELD5; ?></span><span class="sub"><?php echo _DB_FIELD5_DESC; ?></span></th>
\r
582 <td><input type="text" name="mysql_tablePrefix" value="<?php echo $param->mysql_tablePrefix; ?>" /></td>
\r
586 <h2><?php echo _DETAIL_HEADER2; ?></h2>
\r
591 $errors = $param->check_uri_parameters();
\r
592 if ( is_array($errors) )
\r
594 foreach ( $errors as $error )
\r
596 echo '<span class="err">', $error, "</span>\n";
\r
599 $errors = $param->check_path_parameters();
\r
600 if ( is_array($errors) )
\r
602 foreach ( $errors as $error )
\r
604 echo '<span class="err">', $error, "</span>\n";
\r
612 <th><span class="nam"><?php echo _PATH_FIELD1; ?></span></th>
\r
613 <td><input type="text" name="IndexURL" value="<?php echo $param->IndexURL; ?>" /></td>
\r
616 <th><span class="nam"><?php echo _PATH_FIELD2; ?></span></th>
\r
617 <td><input type="text" name="AdminURL" value="<?php echo $param->AdminURL; ?>" /></td>
\r
620 <th><span class="nam"><?php echo _PATH_FIELD3; ?></span></th>
\r
621 <td><input type="text" name="AdminPath" value="<?php echo $param->AdminPath; ?>" /></td>
\r
624 <th><span class="nam"><?php echo _PATH_FIELD4; ?></span></th>
\r
625 <td><input type="text" name="MediaURL" value="<?php echo $param->MediaURL; ?>" /></td>
\r
628 <th><span class="nam"><?php echo _PATH_FIELD5; ?></span></th>
\r
629 <td><input type="text" name="MediaPath" value="<?php echo $param->MediaPath; ?>" /></td>
\r
632 <th><span class="nam"><?php echo _PATH_FIELD6; ?></span></th>
\r
633 <td><input type="text" name="SkinsURL" value="<?php echo $param->SkinsURL; ?>" /></td>
\r
636 <th><span class="nam"><?php echo _PATH_FIELD7; ?></span></th>
\r
637 <td><input type="text" name="SkinsPath" value="<?php echo $param->SkinsPath; ?>" /></td>
\r
640 <th><span class="nam"><?php echo _PATH_FIELD8; ?></span></th>
\r
641 <td><input type="text" name="PluginURL" value="<?php echo $param->PluginURL; ?>" /></td>
\r
644 <th><span class="nam"><?php echo _PATH_FIELD9; ?></span></th>
\r
645 <td><input type="text" name="ActionURL" value="<?php echo $param->ActionURL; ?>" /></td>
\r
649 <?php echo _DETAIL_TEXT3; ?>
\r
652 <h2><?php echo _DETAIL_HEADER3; ?></h2>
\r
655 echo _DETAIL_TEXT4;
\r
658 $errors = $param->check_user_parameters();
\r
659 if ( is_array($errors) )
\r
661 foreach ( $errors as $error )
\r
663 echo '<span class="err">', $error, "</span>\n";
\r
671 <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>
\r
672 <td><input type="text" name="user_realname" value="<?php echo $param->user_realname; ?>" /></td>
\r
675 <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>
\r
676 <td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>
\r
679 <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>
\r
680 <td><input type="password" name="user_password" /></td>
\r
683 <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>
\r
684 <td><input type="password" name="user_password2" /></td>
\r
687 <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>
\r
688 <td><input type="text" name="user_email" value="<?php echo $param->user_email; ?>" /></td>
\r
692 <h2><?php echo _DETAIL_HEADER4; ?></h2>
\r
695 echo _DETAIL_TEXT5;
\r
698 $errors = $param->check_weblog_parameters();
\r
699 if ( is_array($errors) )
\r
701 foreach ( $errors as $error )
\r
703 echo '<span class="err">', $error, "</span>\n";
\r
711 <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>
\r
712 <td><input type="text" name="blog_name" value="<?php echo $param->blog_name; ?>" /></td>
\r
715 <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>
\r
716 <td><input type="text" name="blog_shortname" value="<?php echo $param->blog_shortname; ?>" /></td>
\r
721 <?php echo _DETAIL_TEXT6; ?>
\r
725 <button type="submit" name="action" value="detail" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>
\r
734 * Displays a screen to signal the completion of the installation
\r
736 function show_install_complete_form()
\r
738 global $MYSQL_HANDLER, $param;
\r
739 $errors = do_install();
\r
741 <div id="container">
\r
744 if ( is_array($errors) && count($errors) > 0 )
\r
747 foreach ( $errors as $error )
\r
749 echo '<span class="err">', $error, "</span>\n";
\r
755 if ( array_key_exists('config_data', $_SESSION) )
\r
757 echo '<span class="err">', _INST_TEXT4, '</span>';
\r
759 <textarea id="config_text" readonly="readonly" onfocus="SelectText(this);"><?php echo htmlentities($_SESSION['config_data'], null, i18n::get_current_charset()) ?></textarea>
\r
764 echo '<span class="err">', _INST_TEXT5, '</span>';
\r
768 <form method="post" action="./index.php">
\r
770 <h2><?php echo _INST_HEADER1; ?></h2>
\r
772 <?php echo sprintf(_INST_TEXT1, $param->blog_name); ?>
\r
775 <button type="button" name="toBlog" onclick="location.href='<?php echo $param->IndexURL; ?>';" class="sbt_arw"><?php echo _INST_BUTTON1; ?></button>
\r
780 <h2><?php echo _INST_HEADER2; ?></h2>
\r
782 <?php echo _INST_TEXT2; ?>
\r
785 <button type="button" name="toMng" onclick="location.href='<?php echo $param->AdminURL; ?>';" class="sbt_arw"><?php echo _INST_BUTTON2; ?></button>
\r
790 <h2><?php echo _INST_HEADER3; ?></h2>
\r
792 <?php echo _INST_TEXT3; ?>
\r
795 <button type="button" name="toAddBlog" onclick="location.href='<?php echo $param->AdminURL; ?>index.php?action=createnewlog';" class="sbt_arw"><?php echo _INST_BUTTON3; ?></button>
\r
808 * The installation process itself
\r
809 * @return array error messages
\r
811 function do_install()
\r
814 global $MYSQL_HANDLER, $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX, $MYSQL_CONN;
\r
815 global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;
\r
819 * 1. put all param-vars into vars
\r
821 $MYSQL_HOST = $param->mysql_host;
\r
822 $MYSQL_USER = $param->mysql_user;
\r
823 $MYSQL_PASSWORD = $param->mysql_password;
\r
824 $MYSQL_DATABASE = $param->mysql_database;
\r
825 $MYSQL_PREFIX = $param->mysql_tablePrefix;
\r
827 $DIR_NUCLEUS = $param->AdminPath;
\r
828 $DIR_MEDIA = $param->MediaPath;
\r
829 $DIR_SKINS = $param->SkinsPath;
\r
830 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
\r
831 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
\r
832 $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
\r
835 * 2.open mySQL connection
\r
837 $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
\r
838 if ( $MYSQL_CONN == FALSE )
\r
840 $errors[] = _DBCONNECT_ERROR;
\r
845 * 3. try to create database if needed
\r
847 if ( DB::execute("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") === FALSE )
\r
849 $errinfo = DB::getError();
\r
850 $errors[] = _INST_ERROR1 . ': ' . $errinfo[2];
\r
854 * 4. try to select database
\r
856 $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE);
\r
857 if ( !$MYSQL_CONN )
\r
859 $errors[] = _INST_ERROR2;
\r
862 if ( count($errors) > 0 )
\r
868 * 5. execute queries
\r
870 $table_names = array(
\r
871 'nucleus_actionlog',
\r
874 'nucleus_category',
\r
882 'nucleus_template',
\r
884 'nucleus_activation',
\r
888 $prefixed_table_names = array();
\r
889 foreach ( $table_names as $table_name )
\r
891 $prefixed_table_names[] = $MYSQL_PREFIX . $table_name;
\r
894 // table exists check
\r
895 $result = DB::getResult('SHOW TABLES');
\r
896 foreach ( $result as $row )
\r
898 if ( in_array($row[0], $prefixed_table_names) )
\r
900 $errors[] = _INST_ERROR3;
\r
904 if ( count($errors) > 0 )
\r
909 $filename = 'install.sql';
\r
910 $fd = fopen($filename, 'r');
\r
911 $queries = fread($fd, filesize($filename));
\r
914 $queries = preg_split('#(;\n|;\r)#', $queries);
\r
916 foreach ( $queries as $query )
\r
918 if ( preg_match('/\w+/', $query) )
\r
920 if ( $MYSQL_PREFIX )
\r
922 $query = str_replace($table_names, $prefixed_table_names, $query);
\r
925 if ( DB::execute($query) === FALSE )
\r
927 $errinfo = DB::getError();
\r
928 $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . $errinfo[2];
\r
934 * 6. put needed records
\r
936 /* push first post */
\r
937 $query = "INSERT INTO %s VALUES (1, %s, %s, %s, 1, 1, %s, 0, 0, 0, 1, 0, 1)";
\r
938 $query = sprintf($query,
\r
939 tableName('nucleus_item'),
\r
940 DB::quoteValue(_1ST_POST_TITLE),
\r
941 DB::quoteValue(_1ST_POST),
\r
942 DB::quoteValue(_1ST_POST2),
\r
943 DB::formatDateTime()
\r
945 if ( DB::execute($query) === FALSE )
\r
947 $errinfo = DB::getError();
\r
948 $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . $errinfo[2];
\r
951 /* push configurations */
\r
952 array_merge($errors, updateConfig('IndexURL', $param->IndexURL));
\r
953 array_merge($errors, updateConfig('AdminURL', $param->AdminURL));
\r
954 array_merge($errors, updateConfig('MediaURL', $param->MediaURL));
\r
955 array_merge($errors, updateConfig('SkinsURL', $param->SkinsURL));
\r
956 array_merge($errors, updateConfig('PluginURL', $param->PluginURL));
\r
957 array_merge($errors, updateConfig('ActionURL', $param->ActionURL));
\r
958 array_merge($errors, updateConfig('AdminEmail', $param->user_email));
\r
959 array_merge($errors, updateConfig('SiteName', $param->blog_name));
\r
960 array_merge($errors, updateConfig('Locale', i18n::get_current_locale()));
\r
962 /* push super admin */
\r
963 $query = "UPDATE %s SET mname = %s, mrealname = %s, mpassword = %s, memail = %s, murl = %s, madmin = 1, mcanlogin = 1 WHERE mnumber = 1";
\r
964 $query = sprintf($query,
\r
965 tableName('nucleus_member'),
\r
966 DB::quoteValue($param->user_name),
\r
967 DB::quoteValue($param->user_realname),
\r
968 DB::quoteValue(md5($param->user_password)),
\r
969 DB::quoteValue($param->user_email),
\r
970 DB::quoteValue($param->IndexURL)
\r
972 if ( DB::execute($query) === FALSE )
\r
974 $errinfo = DB::getError();
\r
975 $errors[] = _INST_ERROR5 . ': ' . $errinfo[2];
\r
978 /* push new weblog */
\r
979 $query = "UPDATE %s SET bname = %s, bshortname = %s, burl = %s WHERE bnumber = 1";
\r
980 $query = sprintf($query,
\r
981 tableName('nucleus_blog'),
\r
982 DB::quoteValue($param->blog_name),
\r
983 DB::quoteValue($param->blog_shortname),
\r
984 DB::quoteValue($param->IndexURL)
\r
986 if ( DB::execute($query) === FALSE )
\r
988 $errinfo = DB::getError();
\r
989 $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];
\r
992 /* push default category */
\r
993 $query = "UPDATE %s SET cname = %s, cdesc = %s WHERE catid = 1";
\r
994 $query = sprintf($query,
\r
995 tableName('nucleus_category'),
\r
996 DB::quoteValue(_GENERALCAT_NAME),
\r
997 DB::quoteValue(_GENERALCAT_DESC)
\r
999 if ( DB::execute($query) === FALSE )
\r
1001 $errinfo = DB::getError();
\r
1002 $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];
\r
1006 * 7. install default plugins and skins
\r
1008 global $aConfPlugsToInstall, $aConfSkinsToImport;
\r
1009 $aSkinErrors = array();
\r
1010 $aPlugErrors = array();
\r
1012 if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) )
\r
1014 include_once($DIR_LIBS . 'globalfunctions.php');
\r
1016 if ( !isset($manager) )
\r
1018 $manager = new Manager();
\r
1021 include_once($DIR_LIBS . 'skinie.php');
\r
1023 $aSkinErrors = installCustomSkins();
\r
1024 if ( count($aSkinErrors) > 0 )
\r
1026 array_merge($errors, $aSkinErrors);
\r
1029 $query = "SELECT sdnumber FROM %s WHERE sdname='default'";
\r
1030 $query = sprintf($query, tableName('nucleus_skin_desc'));
\r
1031 $defSkinID = intval(DB::getValue($query));
\r
1033 $query = "UPDATE %s SET bdefskin=%d WHERE bnumber=1";
\r
1034 $query = sprintf($query, tableName('nucleus_blog'), $defSkinID);
\r
1035 DB::execute($query);
\r
1037 $query = "UPDATE %s SET value=%d WHERE name='BaseSkin'";
\r
1038 $query = sprintf($query, tableName('nucleus_config'), $defSkinID);
\r
1039 DB::execute($query);
\r
1041 $aPlugErrors = installCustomPlugs();
\r
1042 if ( count($aPlugErrors) > 0 )
\r
1044 array_merge($errors, $aPlugErrors);
\r
1049 * 8. Write config file ourselves (if possible)
\r
1051 $config_data = '<' . '?php' . "\n";
\r
1052 $config_data .= "// mySQL connection information\n";
\r
1053 $config_data .= "\$MYSQL_HOST = '" . $MYSQL_HOST . "';\n";
\r
1054 $config_data .= "\$MYSQL_USER = '" . $MYSQL_USER . "';\n";
\r
1055 $config_data .= "\$MYSQL_PASSWORD = '" . $MYSQL_PASSWORD . "';\n";
\r
1056 $config_data .= "\$MYSQL_DATABASE = '" . $MYSQL_DATABASE . "';\n";
\r
1057 $config_data .= "\$MYSQL_PREFIX = '" . $MYSQL_PREFIX . "';\n";
\r
1058 $config_data .= "// new in 3.50. first element is db handler, the second is the db driver used by the handler\n";
\r
1059 $config_data .= "// default is \$MYSQL_HANDLER = array('mysql','mysql');\n";
\r
1060 $config_data .= "//\$MYSQL_HANDLER = array('mysql','mysql');\n";
\r
1061 $config_data .= "//\$MYSQL_HANDLER = array('pdo','mysql');\n";
\r
1062 $config_data .= "\$MYSQL_HANDLER = array('" . $MYSQL_HANDLER[0] . "','" . $MYSQL_HANDLER[1] . "');\n";
\r
1063 $config_data .= "\n";
\r
1064 $config_data .= "// main nucleus directory\n";
\r
1065 $config_data .= "\$DIR_NUCLEUS = '" . $DIR_NUCLEUS . "';\n";
\r
1066 $config_data .= "\n";
\r
1067 $config_data .= "// path to media dir\n";
\r
1068 $config_data .= "\$DIR_MEDIA = '" . $DIR_MEDIA . "';\n";
\r
1069 $config_data .= "\n";
\r
1070 $config_data .= "// extra skin files for imported skins\n";
\r
1071 $config_data .= "\$DIR_SKINS = '" . $DIR_SKINS . "';\n";
\r
1072 $config_data .= "\n";
\r
1073 $config_data .= "// these dirs are normally sub dirs of the nucleus dir, but \n";
\r
1074 $config_data .= "// you can redefine them if you wish\n";
\r
1075 $config_data .= "\$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";
\r
1076 $config_data .= "\$DIR_LOCALES = \$DIR_NUCLEUS . 'locales/';\n";
\r
1077 $config_data .= "\$DIR_LIBS = \$DIR_NUCLEUS . 'libs/';\n";
\r
1078 $config_data .= "\n";
\r
1079 $config_data .= "// include libs\n";
\r
1080 $config_data .= "include(\$DIR_LIBS.'globalfunctions.php');\n";
\r
1081 $config_data .= "?" . ">";
\r
1084 if ( @!file_exists('../config.php') || is_writable('../config.php') )
\r
1086 if ( $fp = @fopen('../config.php', 'w') )
\r
1088 $result = @fwrite($fp, $config_data, i18n::strlen($config_data));
\r
1095 // try to change the read-only permission.
\r
1096 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
\r
1098 @chmod('../config.php', 0444);
\r
1103 $_SESSION['config_data'] = $config_data;
\r
1110 * Confirm that you can write to the configuration file
\r
1111 * @return string error message
\r
1113 function canConfigFileWritable()
\r
1115 if ( @file_exists('../config.php') && @!is_writable('../config.php') )
\r
1117 // try to change the read-write permission.
\r
1118 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
\r
1120 @chmod('../config.php', 0666);
\r
1123 if ( @!is_writable('../config.php') )
\r
1125 return _INST_ERROR8;
\r
1132 * To obtain the version of MySQL
\r
1135 function getMySqlVersion()
\r
1137 global $MYSQL_HANDLER, $minimum_mysql_version, $errors;
\r
1138 // Turn on output buffer
\r
1139 // Needed to repress the output of the sql function that are
\r
1140 // not part of php (in this case the @ operator doesn't work)
\r
1143 // note: this piece of code is taken from phpMyAdmin
\r
1144 $conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], 'localhost', '', '');
\r
1148 $row = DB::getAttribute(PDO::ATTR_SERVER_VERSION);
\r
1149 $match = preg_split('#\.#', $row);
\r
1153 $row = @DB::getRow('SHOW VARIABLES LIKE \'version\'');
\r
1157 $match = preg_split('#\.#', $row[1]);
\r
1161 $output = (function_exists('shell_exec')) ? @shell_exec('mysql -V') : '0.0.0';
\r
1162 preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
\r
1163 $match = preg_split('#\.#', $version[0]);
\r
1165 if ( $match[0] == '' )
\r
1167 $match = array('0', '0', '0');
\r
1172 @DB::disConnect();
\r
1174 //End and clean output buffer
\r
1177 return implode($match, '.');
\r
1181 * Add a table prefix if it is used
\r
1183 * @param string $input table name with prefix
\r
1186 function tableName($input)
\r
1188 global $MYSQL_PREFIX;
\r
1189 if ( $MYSQL_PREFIX )
\r
1191 return $MYSQL_PREFIX . $input;
\r
1200 * Install custom plugins
\r
1202 function installCustomPlugs()
\r
1204 global $aConfPlugsToInstall, $DIR_LIBS, $manager;
\r
1206 $aErrors = array();
\r
1207 if ( count($aConfPlugsToInstall) == 0 )
\r
1212 $query = sprintf('SELECT * FROM %s', tableName('nucleus_plugin'));
\r
1213 $res = DB::getResult($query);
\r
1214 $numCurrent = $res->rowCount();
\r
1216 foreach ( $aConfPlugsToInstall as $plugName )
\r
1218 $query = sprintf('INSERT INTO %s (porder, pfile) VALUES (%d, %s)',
\r
1219 tableName('nucleus_plugin'),
\r
1221 DB::quoteValue($plugName));
\r
1222 DB::execute($query);
\r
1224 $manager->clearCachedInfo('installedPlugins');
\r
1225 $plugin =& $manager->getPlugin($plugName);
\r
1226 $plugin->setID($numCurrent);
\r
1230 $query = sprintf('DELETE FROM %s WHERE pfile = %s',
\r
1231 tableName('nucleus_plugin'),
\r
1232 DB::quoteValue($plugName));
\r
1233 DB::execute($query);
\r
1235 array_push($aErrors, sprintf(_INST_ERROR9, $plugName));
\r
1238 $plugin->install();
\r
1241 $query = sprintf('DELETE FROM %s', tableName('nucleus_plugin_event'));
\r
1242 DB::execute($query);
\r
1243 $query = sprintf('SELECT pid, pfile FROM %s', tableName('nucleus_plugin'));
\r
1244 $res = DB::getResult($query);
\r
1246 foreach ( $res as $row )
\r
1248 $plug =& $manager->getPlugin($row['pfile']);
\r
1252 $eventList = $plug->getEventList();
\r
1253 foreach ( $eventList as $eventName )
\r
1255 $query = sprintf('INSERT INTO %s (pid, event) VALUES (%d, %s)',
\r
1256 tableName('nucleus_plugin_event'),
\r
1257 intval($row['pid']),
\r
1258 DB::quoteValue($eventName));
\r
1259 DB::execute($query);
\r
1267 * Install custom skins
\r
1268 * Prepares the installation of custom skins
\r
1270 function installCustomSkins()
\r
1272 global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS;
\r
1274 $aErrors = array();
\r
1275 if ( count($aConfSkinsToImport) == 0 )
\r
1280 $importer = new SkinImport();
\r
1282 foreach ( $aConfSkinsToImport as $skinName )
\r
1284 $importer->reset();
\r
1285 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';
\r
1287 if ( !@file_exists($skinFile) )
\r
1289 array_push($aErrors, sprintf(_INST_ERROR10, $skinFile));
\r
1293 $error = $importer->readFile($skinFile);
\r
1297 array_push($aErrors, sprintf(_INST_ERROR11, $skinName) . ' : ' . $error);
\r
1301 $error = $importer->writeToDatabase(1);
\r
1305 array_push($aErrors, sprintf(_INST_ERROR12, $skinName) . ' : ' . $error);
\r
1313 * Check if some important files of the Nucleus CMS installation are available
\r
1314 * Give an error if one or more files are not accessible
\r
1316 function do_check_files()
\r
1318 $missingfiles = array();
\r
1323 '../nucleus/index.php',
\r
1324 '../nucleus/media.php',
\r
1325 '../nucleus/libs/ACTION.php',
\r
1326 '../nucleus/libs/ACTIONLOG.php',
\r
1327 '../nucleus/libs/ACTIONS.php',
\r
1328 '../nucleus/libs/ADMIN.php',
\r
1329 '../nucleus/libs/BaseActions.php',
\r
1330 '../nucleus/libs/BLOG.php',
\r
1331 '../nucleus/libs/BODYACTIONS.php',
\r
1332 '../nucleus/libs/COMMENT.php',
\r
1333 '../nucleus/libs/COMMENTACTIONS.php',
\r
1334 '../nucleus/libs/COMMENTS.php',
\r
1335 '../nucleus/libs/ENCAPSULATE.php',
\r
1336 '../nucleus/libs/ENTITY.php',
\r
1337 '../nucleus/libs/globalfunctions.php',
\r
1338 '../nucleus/libs/i18n.php',
\r
1339 '../nucleus/libs/ITEM.php',
\r
1340 '../nucleus/libs/ITEMACTIONS.php',
\r
1341 '../nucleus/libs/LINK.php',
\r
1342 '../nucleus/libs/MANAGER.php',
\r
1343 '../nucleus/libs/MEDIA.php',
\r
1344 '../nucleus/libs/MEMBER.php',
\r
1345 '../nucleus/libs/NOTIFICATION.php',
\r
1346 '../nucleus/libs/PAGEFACTORY.php',
\r
1347 '../nucleus/libs/PARSER.php',
\r
1348 '../nucleus/libs/PLUGIN.php',
\r
1349 '../nucleus/libs/PLUGINADMIN.php',
\r
1350 '../nucleus/libs/SEARCH.php',
\r
1351 '../nucleus/libs/showlist.php',
\r
1352 '../nucleus/libs/SKIN.php',
\r
1353 '../nucleus/libs/TEMPLATE.php',
\r
1354 '../nucleus/libs/vars4.1.0.php',
\r
1355 '../nucleus/libs/xmlrpc.inc.php',
\r
1356 '../nucleus/libs/xmlrpcs.inc.php',
\r
1357 '../nucleus/libs/sql/DB.php',
\r
1358 '../nucleus/libs/sql/MYSQLPDO.php'
\r
1361 $count = count($files);
\r
1362 for ( $i = 0; $i < $count; $i++ )
\r
1364 if ( !is_readable($files[$i]) )
\r
1366 array_push($missingfiles, 'File <b>' . $files[$i] . '</b> is missing or not readable.<br />');
\r
1370 if ( count($missingfiles) > 0 )
\r
1372 exit(implode("\n", $missingfiles));
\r
1377 * Updates the configuration in the database
\r
1379 * @param string $name name of the config var
\r
1380 * @param string $value new value of the config var
\r
1383 function updateConfig($name, $value)
\r
1385 $errors = array();
\r
1387 $query = "UPDATE %s SET value = %s WHERE name = %s";
\r
1388 $query = sprintf($query, tableName('nucleus_config'), DB::quoteValue(trim($value)), DB::quoteValue($name));
\r
1390 if ( DB::execute($query) === FALSE )
\r
1392 $errinfo = DB::getError();
\r
1393 $errors[] = _INST_ERROR4 . ': ' . $errinfo[2];
\r
1398 class ParamManager
\r
1400 /* process parameter */
\r
1404 /* mysql connection parameters */
\r
1405 public $mysql_host;
\r
1406 public $mysql_user;
\r
1407 public $mysql_password;
\r
1408 public $mysql_database;
\r
1409 public $mysql_tablePrefix;
\r
1411 /* weblog configuration parameters */
\r
1412 public $blog_name;
\r
1413 public $blog_shortname;
\r
1415 /* member configuration parameters */
\r
1416 public $user_name;
\r
1417 public $user_realname;
\r
1418 public $user_password;
\r
1419 private $user_password2;
\r
1420 public $user_email;
\r
1422 /* URI parameters */
\r
1423 private $root_url;
\r
1428 public $PluginURL;
\r
1429 public $ActionURL;
\r
1431 /* path parameters */
\r
1432 private $root_path;
\r
1433 public $AdminPath;
\r
1434 public $MediaPath;
\r
1435 public $SkinsPath;
\r
1440 public function __construct()
\r
1445 public function init()
\r
1447 // set default values
\r
1448 $this->state = 'locale';
\r
1449 $this->install_mode = 'simple';
\r
1450 $this->locale = 'en_Latn_US';
\r
1451 $this->mysql_host = @ini_get('mysql.default_host');
\r
1452 $this->blog_name = 'My Nucleus CMS';
\r
1453 $this->blog_shortname = 'mynucleuscms';
\r
1456 $directory_separator = preg_quote(DIRECTORY_SEPARATOR, '|');
\r
1457 $this->root_path = implode('/', preg_split("|$directory_separator|", realpath(dirname(__FILE__) . '/..')));
\r
1458 if ( substr($this->root_path, -1, 1) !== '/' )
\r
1460 $this->root_path .= '/';
\r
1462 $base_path_pcre = preg_quote($this->root_path, '|');
\r
1464 /* current directry name */
\r
1465 $directory_name = preg_replace("#{$base_path_pcre}#", '', implode('/', preg_split("#{$directory_separator}#", realpath(dirname(__FILE__)))));
\r
1466 $directory_name_pcre = preg_quote($directory_name, '|');
\r
1469 $root_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
\r
1470 $this->root_url = preg_replace("|$directory_name_pcre(.*)$|", '', $root_url);
\r
1472 $this->AdminPath = $this->root_path . 'nucleus/';
\r
1473 $this->MediaPath = $this->root_path . 'media/';
\r
1474 $this->SkinsPath = $this->root_path . 'skins/';
\r
1476 $this->IndexURL = $this->root_url;
\r
1477 $this->AdminURL = $this->root_url . 'nucleus/';
\r
1478 $this->MediaURL = $this->root_url . 'media/';
\r
1479 $this->SkinsURL = $this->root_url . 'skins/';
\r
1480 $this->PluginURL = $this->root_url . 'nucleus/plugins/';
\r
1481 $this->ActionURL = $this->root_url . 'action.php';
\r
1484 private function read_parameter($parameter)
\r
1486 foreach ( $parameter as $element )
\r
1488 if ( array_key_exists($element, $_POST) )
\r
1490 $this->$element = $_POST[$element];
\r
1495 public function set_state($state)
\r
1497 $states = array('locale', 'mysql', 'weblog', 'detail', 'install');
\r
1498 if ( in_array($state, $states) )
\r
1500 $this->state = $state;
\r
1504 public function set_locale()
\r
1506 $this->read_parameter(array('locale'));
\r
1508 if ( !in_array($this->locale, i18n::get_available_locale_list()) )
\r
1510 $this->locale = 'en_Latn_US';
\r
1514 public function check_mysql_parameters()
\r
1516 global $MYSQL_HANDLER;
\r
1518 $parameters = array('mysql_host', 'mysql_user', 'mysql_password', 'mysql_database', 'mysql_tablePrefix');
\r
1519 $this->read_parameter($parameters);
\r
1521 $errors = array();
\r
1522 if ( $this->mysql_host == '' )
\r
1524 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD1);
\r
1527 if ( $this->mysql_user == '' )
\r
1529 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD2);
\r
1532 if ( $this->mysql_user != ''
\r
1533 && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_user) )
\r
1535 $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD2);
\r
1538 if ( $this->mysql_database == '' )
\r
1540 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD4);
\r
1543 if ( $this->mysql_database != ''
\r
1544 && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_database) )
\r
1546 $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD4);
\r
1549 if ( $this->mysql_tablePrefix != ''
\r
1550 && !preg_match('/^[a-z0-9_]+$/i', $this->mysql_tablePrefix) )
\r
1552 $errors[] = sprintf(_VALID_ERROR3, _DB_FIELD5);
\r
1555 if ( count($errors) == 0 )
\r
1557 $mysql_conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], $this->mysql_host, $this->mysql_user, $this->mysql_password);
\r
1558 if ( $mysql_conn == false )
\r
1560 $errors[] = _DBCONNECT_ERROR;
\r
1564 @DB::disConnect();
\r
1571 public function check_user_parameters()
\r
1573 $parameters = array('user_name', 'user_realname', 'user_password', 'user_password2', 'user_email');
\r
1574 $this->read_parameter($parameters);
\r
1576 $errors = array();
\r
1577 if ( $this->user_realname == '' )
\r
1579 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD1);
\r
1582 if ( $this->user_name == '' )
\r
1584 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD2);
\r
1586 elseif ( !preg_match("/^[a-z0-9]+([ a-z0-9]*[a-z0-9]+)?$/i", $this->user_name) )
\r
1588 $errors[] = _VALID_ERROR5;
\r
1591 if ( $this->user_password == '' || $this->user_password2 == '' )
\r
1593 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD3);
\r
1594 $this->user_password = '';
\r
1596 elseif ( $this->user_password != $this->user_password2 )
\r
1598 $errors[] = _VALID_ERROR6;
\r
1599 $this->user_password = '';
\r
1602 if ( !preg_match("/^[a-z0-9\._+\-]+@[a-z0-9\._\-]+\.[a-z]{2,6}$/i", $this->user_email) )
\r
1604 $errors[] = _VALID_ERROR7;
\r
1610 public function check_weblog_parameters()
\r
1612 $parameters = array('blog_name', 'blog_shortname');
\r
1613 $this->read_parameter($parameters);
\r
1615 $errors = array();
\r
1616 if ( $this->blog_name == '' )
\r
1618 $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD1);
\r
1621 if ( $this->blog_shortname == '' )
\r
1623 $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD2);
\r
1626 if ( !preg_match("/^[a-z0-9]+$/i", $this->blog_shortname) )
\r
1628 $errors[] = _VALID_ERROR4;
\r
1634 public function check_uri_parameters()
\r
1636 $parameters = array('IndexURL', 'AdminURL', 'MediaURL', 'SkinsURL', 'PluginURL', 'ActionURL');
\r
1637 $this->read_parameter($parameters);
\r
1639 $errors = array();
\r
1640 if ( substr($this->IndexURL, -1, 1) !== '/' )
\r
1642 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD1);
\r
1645 if ( substr($this->AdminURL, -1, 1) !== '/' )
\r
1647 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD2);
\r
1650 if ( substr($this->MediaURL, -1, 1) !== '/' )
\r
1652 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD4);
\r
1655 if ( substr($this->SkinsURL, -1, 1) !== '/' )
\r
1657 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD6);
\r
1660 if ( substr($this->PluginURL, -1, 1) !== '/' )
\r
1662 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD8);
\r
1665 if ( strrchr($this->ActionURL, '/') != '/action.php' )
\r
1667 $errors[] = sprintf(_VALID_ERROR9, _PATH_FIELD9);
\r
1673 public function check_path_parameters()
\r
1675 $parameters = array('AdminPath', 'MediaPath', 'SkinsPath');
\r
1676 $this->read_parameter($parameters);
\r
1678 $separators = array('/', DIRECTORY_SEPARATOR);
\r
1679 $errors = array();
\r
1680 if ( !in_array(substr($this->AdminPath, -1, 1), $separators) )
\r
1682 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD3);
\r
1684 elseif ( !file_exists($this->AdminPath) )
\r
1686 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD3);
\r
1689 if ( !in_array(substr($this->MediaPath, -1, 1), $separators) )
\r
1691 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD5);
\r
1693 elseif ( !file_exists($this->MediaPath) )
\r
1695 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD5);
\r
1698 if ( !in_array(substr($this->SkinsPath, -1, 1), $separators) )
\r
1700 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD7);
\r
1702 elseif ( !file_exists($this->SkinsPath) )
\r
1704 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD7);
\r
1711 * check all parameters
\r
1714 public function check_all_parameters()
\r
1716 $this->set_locale();
\r
1719 $isValid &= (count($this->check_mysql_parameters()) == 0);
\r
1720 $isValid &= (count($this->check_user_parameters()) == 0);
\r
1721 $isValid &= (count($this->check_weblog_parameters()) == 0);
\r
1722 $isValid &= (count($this->check_uri_parameters()) == 0);
\r
1723 $isValid &= (count($this->check_path_parameters()) == 0);
\r
1731 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
1732 * Copyright (C) 2002-2012 The Nucleus Group
1734 * This program is free software; you can redistribute it and/or
1735 * modify it under the terms of the GNU General Public License
1736 * as published by the Free Software Foundation; either version 2
1737 * of the License, or (at your option) any later version.
1738 * (see nucleus/documentation/index.html#license for more info)
1740 * This script will install the Nucleus tables in your SQL-database,
1741 * and initialize the data in those tables.
1745 * @license http://nucleuscms.org/license.txt GNU General Public License
1746 * @copyright Copyright (C) 2002-2012 The Nucleus Group
1747 * @version $Id: index.php 1889 2012-06-17 08:46:45Z sakamocchi $
1750 /* global values initialize */
1753 /* reporting all errors for support */
1754 error_reporting(E_ALL);
1756 $minimum_php_version = '5.0.6';
1757 $minimum_mysql_version = '3.23';
1759 $page_footer_copyright = '© 2001-2012 The Nucleus Groupe . Running Nucleus CMS v4.00';
1761 // begin if: server's PHP version is below the minimum; halt installation
1762 if ( version_compare(PHP_VERSION, $minimum_php_version, '<') )
1764 exit('<div style="font-size: xx-large;"> Nucleus requires at least PHP version ' . $minimum_php_version . '</div>');
1767 // make sure there's no unnecessary escaping: # set_magic_quotes_runtime(0);
1768 if ( version_compare(PHP_VERSION, '5.3.0', '<') )
1770 ini_set('magic_quotes_runtime', '0');
1773 /* default installed plugins and skins */
1774 $aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles', 'NP_Medium');
1775 $aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default', 'admin/default', 'admin/bookmarklet');
1777 // Check if some important files
1780 /* i18n class is needed for internationalization */
1781 include_once('../nucleus/libs/i18n.php');
1782 if ( !i18n::init('UTF-8', '../nucleus/locales') )
1784 exit('<div style="font-size: xx-large;"> Failed to initialize iconv or mbstring extension. Would you please contact the administrator of your PHP server? </div>');
1787 // include core classes that are needed for login & plugin handling
1789 // added for 3.5 sql_* wrapper
1790 global $MYSQL_HANDLER;
1792 if ( !isset($MYSQL_HANDLER) )
1794 $MYSQL_HANDLER = array('mysql', '');
1796 // check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x
1797 if ( !function_exists('mysql_query') && !function_exists('mysqli_query') )
1799 exit('<div style="font-size: xx-large;"> Your PHP version does not have support for MySQL :( </div>');
1802 include_once('../nucleus/libs/sql/sql.php');
1805 if ( count($_GET) == 0 && count($_POST) == 0 )
1807 unset($_SESSION['param_manager']);
1810 // restore the $param from the session
1811 if ( array_key_exists('param_manager', $_SESSION) )
1813 $param = $_SESSION['param_manager'];
1817 $param = new ParamManager();
1820 // include translation file
1821 $param->set_locale();
1825 // $param is saved to the session
1826 if ( isset($param) )
1828 $_SESSION['param_manager'] = $param;
1832 unset($_SESSION['param_manager']);
1839 function do_action()
1843 if ( array_key_exists('action', $_POST) )
1849 $isPostback = false;
1853 if ( array_key_exists('mode', $_REQUEST) )
1855 if ( $_REQUEST['mode'] == 'detail' )
1857 $param->set_state('detail');
1859 elseif ( $_REQUEST['mode'] == 'simple' )
1861 $param->set_state('mysql');
1865 // input parameter check
1868 switch ( $param->state )
1871 $param->set_state('mysql');
1872 $isPostback = false;
1875 if ( count($param->check_mysql_parameters()) == 0 )
1877 $param->set_state('weblog');
1878 $isPostback = false;
1882 if ( count($param->check_user_parameters()) == 0
1883 && count($param->check_weblog_parameters()) == 0 )
1885 $param->set_state('install');
1886 $isPostback = false;
1890 if ( $param->check_all_parameters() )
1892 $param->set_state('install');
1893 $isPostback = false;
1901 switch ( $param->state )
1904 show_select_locale_form();
1907 show_database_setting_form($isPostback);
1910 show_blog_setting_form($isPostback);
1913 show_detail_setting_form($isPostback);
1916 show_install_complete_form();
1923 * header tag of the installation screens
1925 function show_header()
1929 /* HTTP 1.1 application for no caching */
1930 header("Cache-Control: no-cache, must-revalidate");
1931 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
1932 header('Content-Type: text/html; charset=' . i18n::get_current_charset());
1934 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1935 <html xmlns="http://www.w3.org/1999/xhtml">
1937 <title><?php echo _TITLE; ?></title>
1938 <link rel="stylesheet" type="text/css" href="./styles/inst.css" />
1939 <style type="text/css">
1941 <?php echo _BODYFONTSTYLE; ?>
1944 <script type="text/javascript">
1945 function SelectText( element ) {
1946 window.setTimeout( function() { element.select() }, 0 );
1948 var isSubmit = false;
1949 function OnceSubmit() {
1952 window.setTimeout( function() { isSubmit = false; }, 10000 );
1961 <div id="navigation">
1962 <h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>
1966 $label = '_LOCALE_' . strtoupper($param->locale);
1967 if ( !defined($label) )
1969 echo $param->locale;
1973 echo constant($label);
1977 if ( in_array($param->state, array('mysql', 'weblog', 'install')) )
1979 echo '<li> > ' . _STEP1, '</li><li';
1980 if ( $param->state == 'mysql' )
1982 echo ' class="gry"';
1984 echo '> > ', _STEP2, '</li><li';
1985 if ( in_array($param->state, array('mysql', 'weblog')) )
1987 echo ' class="gry"';
1989 echo '> > ', _STEP3, "</li>\n";
1991 if ( in_array($param->state, array('mysql', 'weblog', 'detail')) )
1993 echo '<li class="rightbox">';
1994 if ( in_array($param->state, array('mysql', 'weblog')) )
1996 echo '<a href="./?mode=detail">', _MODE2, '</a>';
2000 echo '<a href="./?mode=simple">', _MODE1, '</a>';
2012 * footer tag of the installation screens
2014 function show_footer()
2016 global $page_footer_copyright;
2019 <?php echo $page_footer_copyright; ?>
2027 * Display the form for language select
2029 function show_select_locale_form()
2034 <div id="container">
2035 <p style="font-size:152%;font-weight:bold;">
2036 <?php echo _LOCALE_HEADER; ?>
2038 <form method="post" action="./index.php">
2041 <select name="locale">
2043 $locales = i18n::get_available_locale_list();
2044 foreach ( $locales as $locale )
2046 if ( $param->locale != $locale )
2048 echo "<option value=\"{$locale}\">";
2052 echo "<option value=\"{$locale}\" selected=\"selected\">";
2055 $checkfile = "./locales/{$locale}." . i18n::get_current_charset() . '.php';
2056 if ( !file_exists($checkfile) )
2061 $label = '_LOCALE_' . strtoupper($locale);
2062 if ( !defined($label) )
2068 echo constant($label);
2074 <p><?php echo _LOCALE_DESC1; ?></p>
2075 <p><?php echo _LOCALE_DESC2; ?></p>
2076 <p><?php echo _LOCALE_NEED_HELP;?></p>
2078 <button type="submit" name="action" value="locale" class="sbt_arw">START</button>
2087 * Display the form to set up a database
2088 * @param bool $isPostback
2090 function show_database_setting_form($isPostback)
2092 global $param, $minimum_mysql_version;
2094 $config_writable = canConfigFileWritable();
2095 $mysql_version = getMySqlVersion();
2097 <div id="container">
2101 if ( $config_writable != '' )
2103 echo '<span class="err">', $config_writable, '</span>';
2105 if ( $mysql_version == '0.0.0' )
2107 echo '<span class="err">', _DBVERSION_UNKOWN, '</span>';
2109 elseif ( version_compare($mysql_version, $minimum_mysql_version, '<') )
2111 echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';
2115 <form method="post" action="./index.php">
2117 <h2><?php echo _DB_HEADER; ?></h2>
2122 $errors = $param->check_mysql_parameters();
2123 if ( is_array($errors) )
2125 foreach ( $errors as $error )
2127 echo '<span class="err">', $error, "</span>\n";
2135 <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>
2136 <td><input type="text" name="mysql_host" value="<?php echo $param->mysql_host; ?>" /></td>
2139 <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>
2140 <td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>
2143 <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>
2144 <td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>
2147 <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>
2148 <td><input type="text" name="mysql_database" value="<?php echo $param->mysql_database; ?>" /></td>
2152 <button type="submit" name="mode" value="detail" class="sbt_sqr"><?php echo _MODE2; ?></button>
2153 <button type="submit" name="action" value="mysql" class="sbt_arw"><?php echo _NEXT; ?></button>
2156 <?php echo _DB_TEXT1; ?>
2165 * Displays a form to the blog settings
2166 * @param bool $isPostback
2168 function show_blog_setting_form($isPostback)
2172 <div id="container">
2174 <?php echo _SIMPLE_NAVI2; ?>
2176 <form method="post" action="./index.php">
2178 <h2><?php echo _BLOG_HEADER; ?></h2>
2183 $errors = $param->check_weblog_parameters();
2184 if ( is_array($errors) )
2186 foreach ( $errors as $error )
2188 echo '<span class="err">', $error, "</span>\n";
2196 <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>
2197 <td><input type="text" name="blog_name" value="<?php echo $param->blog_name; ?>" /></td>
2200 <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>
2201 <td><input type="text" name="blog_shortname" value="<?php echo $param->blog_shortname; ?>" /></td>
2207 <h2><?php echo _ADMIN_HEADER; ?></h2>
2212 $errors = $param->check_user_parameters();
2213 if ( is_array($errors) )
2215 foreach ( $errors as $error )
2217 echo '<span class="err">', $error, "</span>\n";
2225 <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>
2226 <td><input type="text" name="user_realname" value="<?php echo $param->user_realname; ?>" /></td>
2229 <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>
2230 <td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>
2233 <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>
2234 <td><input type="password" name="user_password" /></td>
2237 <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>
2238 <td><input type="password" name="user_password2" /></td>
2241 <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>
2242 <td><input type="text" name="user_email" value="<?php echo $param->user_email; ?>" /></td>
2246 <button type="submit" name="action" value="weblog" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>
2255 * Displays a form to the detail settings
2256 * @param bool $isPostback
2258 function show_detail_setting_form($isPostback)
2260 global $param, $minimum_mysql_version;
2262 $mysql_version = getMySqlVersion();
2264 <div id="container_detailed">
2266 <?php echo _DETAIL_NAVI1; ?>
2268 if ( $isPostback && !$param->check_all_parameters() )
2270 echo '<span class="err">', _VALID_ERROR, "</span>\n";
2275 <li>PHP: <?php echo phpversion(); ?></li>
2278 echo ($mysql_version == '0.0.0') ? _DBVERSION_UNKOWN : $mysql_version;
2279 if ( version_compare($mysql_version, $minimum_mysql_version, '<') )
2281 echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';
2285 <form method="post" action="">
2288 <h2><?php echo _DETAIL_HEADER1; ?></h2>
2293 $errors = $param->check_mysql_parameters();
2294 if ( is_array($errors) )
2296 foreach ( $errors as $error )
2298 echo '<span class="err">', $error, "</span>\n";
2306 <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>
2307 <td><input type="text" name="mysql_host" value="<?php echo $param->mysql_host; ?>" /></td>
2310 <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>
2311 <td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>
2314 <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>
2315 <td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>
2318 <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>
2319 <td><input type="text" name="mysql_database" value="<?php echo $param->mysql_database; ?>" /></td>
2322 <th><span class="nam"><?php echo _DB_FIELD5; ?></span><span class="sub"><?php echo _DB_FIELD5_DESC; ?></span></th>
2323 <td><input type="text" name="mysql_tablePrefix" value="<?php echo $param->mysql_tablePrefix; ?>" /></td>
2327 <h2><?php echo _DETAIL_HEADER2; ?></h2>
2332 $errors = $param->check_uri_parameters();
2333 if ( is_array($errors) )
2335 foreach ( $errors as $error )
2337 echo '<span class="err">', $error, "</span>\n";
2340 $errors = $param->check_path_parameters();
2341 if ( is_array($errors) )
2343 foreach ( $errors as $error )
2345 echo '<span class="err">', $error, "</span>\n";
2353 <th><span class="nam"><?php echo _PATH_FIELD1; ?></span></th>
2354 <td><input type="text" name="IndexURL" value="<?php echo $param->IndexURL; ?>" /></td>
2357 <th><span class="nam"><?php echo _PATH_FIELD2; ?></span></th>
2358 <td><input type="text" name="AdminURL" value="<?php echo $param->AdminURL; ?>" /></td>
2361 <th><span class="nam"><?php echo _PATH_FIELD3; ?></span></th>
2362 <td><input type="text" name="AdminPath" value="<?php echo $param->AdminPath; ?>" /></td>
2365 <th><span class="nam"><?php echo _PATH_FIELD4; ?></span></th>
2366 <td><input type="text" name="MediaURL" value="<?php echo $param->MediaURL; ?>" /></td>
2369 <th><span class="nam"><?php echo _PATH_FIELD5; ?></span></th>
2370 <td><input type="text" name="MediaPath" value="<?php echo $param->MediaPath; ?>" /></td>
2373 <th><span class="nam"><?php echo _PATH_FIELD6; ?></span></th>
2374 <td><input type="text" name="SkinsURL" value="<?php echo $param->SkinsURL; ?>" /></td>
2377 <th><span class="nam"><?php echo _PATH_FIELD7; ?></span></th>
2378 <td><input type="text" name="SkinsPath" value="<?php echo $param->SkinsPath; ?>" /></td>
2381 <th><span class="nam"><?php echo _PATH_FIELD8; ?></span></th>
2382 <td><input type="text" name="PluginURL" value="<?php echo $param->PluginURL; ?>" /></td>
2385 <th><span class="nam"><?php echo _PATH_FIELD9; ?></span></th>
2386 <td><input type="text" name="ActionURL" value="<?php echo $param->ActionURL; ?>" /></td>
2390 <?php echo _DETAIL_TEXT3; ?>
2393 <h2><?php echo _DETAIL_HEADER3; ?></h2>
2399 $errors = $param->check_user_parameters();
2400 if ( is_array($errors) )
2402 foreach ( $errors as $error )
2404 echo '<span class="err">', $error, "</span>\n";
2412 <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>
2413 <td><input type="text" name="user_realname" value="<?php echo $param->user_realname; ?>" /></td>
2416 <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>
2417 <td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>
2420 <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>
2421 <td><input type="password" name="user_password" /></td>
2424 <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>
2425 <td><input type="password" name="user_password2" /></td>
2428 <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>
2429 <td><input type="text" name="user_email" value="<?php echo $param->user_email; ?>" /></td>
2433 <h2><?php echo _DETAIL_HEADER4; ?></h2>
2439 $errors = $param->check_weblog_parameters();
2440 if ( is_array($errors) )
2442 foreach ( $errors as $error )
2444 echo '<span class="err">', $error, "</span>\n";
2452 <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>
2453 <td><input type="text" name="blog_name" value="<?php echo $param->blog_name; ?>" /></td>
2456 <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>
2457 <td><input type="text" name="blog_shortname" value="<?php echo $param->blog_shortname; ?>" /></td>
2462 <?php echo _DETAIL_TEXT6; ?>
2466 <button type="submit" name="action" value="detail" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>
2475 * Displays a screen to signal the completion of the installation
2477 function show_install_complete_form()
2479 global $MYSQL_HANDLER, $param;
2480 $errors = do_install();
2482 <div id="container">
2485 if ( is_array($errors) && count($errors) > 0 )
2488 foreach ( $errors as $error )
2490 echo '<span class="err">', $error, "</span>\n";
2496 if ( array_key_exists('config_data', $_SESSION) )
2498 echo '<span class="err">', _INST_TEXT4, '</span>';
2500 <textarea id="config_text" readonly="readonly" onfocus="SelectText(this);"><?php echo htmlentities($_SESSION['config_data'], null, i18n::get_current_charset()) ?></textarea>
2505 echo '<span class="err">', _INST_TEXT5, '</span>';
2509 <form method="post" action="./index.php">
2511 <h2><?php echo _INST_HEADER1; ?></h2>
2513 <?php echo sprintf(_INST_TEXT1, $param->blog_name); ?>
2516 <button type="button" name="toBlog" onclick="location.href='<?php echo $param->IndexURL; ?>';" class="sbt_arw"><?php echo _INST_BUTTON1; ?></button>
2521 <h2><?php echo _INST_HEADER2; ?></h2>
2523 <?php echo _INST_TEXT2; ?>
2526 <button type="button" name="toMng" onclick="location.href='<?php echo $param->AdminURL; ?>';" class="sbt_arw"><?php echo _INST_BUTTON2; ?></button>
2531 <h2><?php echo _INST_HEADER3; ?></h2>
2533 <?php echo _INST_TEXT3; ?>
2536 <button type="button" name="toAddBlog" onclick="location.href='<?php echo $param->AdminURL; ?>index.php?action=createnewlog';" class="sbt_arw"><?php echo _INST_BUTTON3; ?></button>
2549 * The installation process itself
2550 * @return array error messages
2552 function do_install()
2555 global $MYSQL_HANDLER, $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX, $MYSQL_CONN;
2556 global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;
2560 * 1. put all param-vars into vars
2562 $MYSQL_HOST = $param->mysql_host;
2563 $MYSQL_USER = $param->mysql_user;
2564 $MYSQL_PASSWORD = $param->mysql_password;
2565 $MYSQL_DATABASE = $param->mysql_database;
2566 $MYSQL_PREFIX = $param->mysql_tablePrefix;
2568 $DIR_NUCLEUS = $param->AdminPath;
2569 $DIR_MEDIA = $param->MediaPath;
2570 $DIR_SKINS = $param->SkinsPath;
2571 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
2572 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
2573 $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
2576 * 2.open mySQL connection
2578 $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
2579 if ( $MYSQL_CONN == FALSE )
2581 $errors[] = _DBCONNECT_ERROR;
2586 * 3. try to create database if needed
2588 if ( DB::execute("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") === FALSE )
2590 $errinfo = DB::getError();
2591 $errors[] = _INST_ERROR1 . ': ' . $errinfo[2];
2595 * 4. try to select database
2597 $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE);
2600 $errors[] = _INST_ERROR2;
2603 if ( count($errors) > 0 )
2609 * 5. execute queries
2611 $table_names = array(
2612 'nucleus_actionlog',
2625 'nucleus_activation',
2629 $prefixed_table_names = array();
2630 foreach ( $table_names as $table_name )
2632 $prefixed_table_names[] = $MYSQL_PREFIX . $table_name;
2635 // table exists check
2636 $result = DB::getResult('SHOW TABLES');
2637 foreach ( $result as $row )
2639 if ( in_array($row[0], $prefixed_table_names) )
2641 $errors[] = _INST_ERROR3;
2645 if ( count($errors) > 0 )
2650 $filename = 'install.sql';
2651 $fd = fopen($filename, 'r');
2652 $queries = fread($fd, filesize($filename));
2655 $queries = preg_split('#(;\n|;\r)#', $queries);
2657 foreach ( $queries as $query )
2659 if ( preg_match('/\w+/', $query) )
2661 if ( $MYSQL_PREFIX )
2663 $query = str_replace($table_names, $prefixed_table_names, $query);
2666 if ( DB::execute($query) === FALSE )
2668 $errinfo = DB::getError();
2669 $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . $errinfo[2];
2675 * 6. put needed records
2677 /* push first post */
2678 $query = "INSERT INTO %s VALUES (1, %s, %s, %s, 1, 1, %s, 0, 0, 0, 1, 0, 1)";
2679 $query = sprintf($query,
2680 tableName('nucleus_item'),
2681 DB::quoteValue(_1ST_POST_TITLE),
2682 DB::quoteValue(_1ST_POST),
2683 DB::quoteValue(_1ST_POST2),
2684 DB::formatDateTime()
2686 if ( DB::execute($query) === FALSE )
2688 $errinfo = DB::getError();
2689 $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . $errinfo[2];
2692 /* push configurations */
2693 array_merge($errors, updateConfig('IndexURL', $param->IndexURL));
2694 array_merge($errors, updateConfig('AdminURL', $param->AdminURL));
2695 array_merge($errors, updateConfig('MediaURL', $param->MediaURL));
2696 array_merge($errors, updateConfig('SkinsURL', $param->SkinsURL));
2697 array_merge($errors, updateConfig('PluginURL', $param->PluginURL));
2698 array_merge($errors, updateConfig('ActionURL', $param->ActionURL));
2699 array_merge($errors, updateConfig('AdminEmail', $param->user_email));
2700 array_merge($errors, updateConfig('SiteName', $param->blog_name));
2701 array_merge($errors, updateConfig('Locale', i18n::get_current_locale()));
2703 /* push super admin */
2704 $query = "UPDATE %s SET mname = %s, mrealname = %s, mpassword = %s, memail = %s, murl = %s, madmin = 1, mcanlogin = 1 WHERE mnumber = 1";
2705 $query = sprintf($query,
2706 tableName('nucleus_member'),
2707 DB::quoteValue($param->user_name),
2708 DB::quoteValue($param->user_realname),
2709 DB::quoteValue(md5($param->user_password)),
2710 DB::quoteValue($param->user_email),
2711 DB::quoteValue($param->IndexURL)
2713 if ( DB::execute($query) === FALSE )
2715 $errinfo = DB::getError();
2716 $errors[] = _INST_ERROR5 . ': ' . $errinfo[2];
2719 /* push new weblog */
2720 $query = "UPDATE %s SET bname = %s, bshortname = %s, burl = %s WHERE bnumber = 1";
2721 $query = sprintf($query,
2722 tableName('nucleus_blog'),
2723 DB::quoteValue($param->blog_name),
2724 DB::quoteValue($param->blog_shortname),
2725 DB::quoteValue($param->IndexURL)
2727 if ( DB::execute($query) === FALSE )
2729 $errinfo = DB::getError();
2730 $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];
2733 /* push default category */
2734 $query = "UPDATE %s SET cname = %s, cdesc = %s WHERE catid = 1";
2735 $query = sprintf($query,
2736 tableName('nucleus_category'),
2737 DB::quoteValue(_GENERALCAT_NAME),
2738 DB::quoteValue(_GENERALCAT_DESC)
2740 if ( DB::execute($query) === FALSE )
2742 $errinfo = DB::getError();
2743 $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];
2747 * 7. install default plugins and skins
2749 global $aConfPlugsToInstall, $aConfSkinsToImport;
2750 $aSkinErrors = array();
2751 $aPlugErrors = array();
2753 if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) )
2755 include_once($DIR_LIBS . 'globalfunctions.php');
2757 if ( !isset($manager) )
2759 $manager = new Manager();
2762 include_once($DIR_LIBS . 'skinie.php');
2764 $aSkinErrors = installCustomSkins();
2765 if ( count($aSkinErrors) > 0 )
2767 array_merge($errors, $aSkinErrors);
2770 $query = "SELECT sdnumber FROM %s WHERE sdname='admin/default'";
2771 $query = sprintf($query, tableName('nucleus_skin_desc'));
2772 $res = intval(DB::getValue($query));
2773 array_merge($errors, updateConfig('AdminSkin', $res));
2775 $query = "SELECT sdnumber FROM %s WHERE sdname='admin/bookmarklet'";
2776 $query = sprintf($query, tableName('nucleus_skin_desc'));
2777 $res = intval(DB::getValue($query));
2778 array_merge($errors, updateConfig('BookmarkletSkin', $res));
2780 $query = "SELECT sdnumber FROM %s WHERE sdname='default'";
2781 $query = sprintf($query, tableName('nucleus_skin_desc'));
2782 $defSkinID = intval(DB::getValue($query));
2784 $query = "UPDATE %s SET bdefskin=%d WHERE bnumber=1";
2785 $query = sprintf($query, tableName('nucleus_blog'), $defSkinID);
2786 DB::execute($query);
2787 $query = "UPDATE %s SET value=%d WHERE name='BaseSkin'";
2788 $query = sprintf($query, tableName('nucleus_config'), $defSkinID);
2789 DB::execute($query);
2791 $aPlugErrors = installCustomPlugs();
2792 if ( count($aPlugErrors) > 0 )
2794 array_merge($errors, $aPlugErrors);
2799 * 8. Write config file ourselves (if possible)
2801 $config_data = '<' . '?php' . "\n";
2802 $config_data .= "// mySQL connection information\n";
2803 $config_data .= "\$MYSQL_HOST = '" . $MYSQL_HOST . "';\n";
2804 $config_data .= "\$MYSQL_USER = '" . $MYSQL_USER . "';\n";
2805 $config_data .= "\$MYSQL_PASSWORD = '" . $MYSQL_PASSWORD . "';\n";
2806 $config_data .= "\$MYSQL_DATABASE = '" . $MYSQL_DATABASE . "';\n";
2807 $config_data .= "\$MYSQL_PREFIX = '" . $MYSQL_PREFIX . "';\n";
2808 $config_data .= "// new in 3.50. first element is db handler, the second is the db driver used by the handler\n";
2809 $config_data .= "// default is \$MYSQL_HANDLER = array('mysql','mysql');\n";
2810 $config_data .= "//\$MYSQL_HANDLER = array('mysql','mysql');\n";
2811 $config_data .= "//\$MYSQL_HANDLER = array('pdo','mysql');\n";
2812 $config_data .= "\$MYSQL_HANDLER = array('" . $MYSQL_HANDLER[0] . "','" . $MYSQL_HANDLER[1] . "');\n";
2813 $config_data .= "\n";
2814 $config_data .= "// main nucleus directory\n";
2815 $config_data .= "\$DIR_NUCLEUS = '" . $DIR_NUCLEUS . "';\n";
2816 $config_data .= "\n";
2817 $config_data .= "// path to media dir\n";
2818 $config_data .= "\$DIR_MEDIA = '" . $DIR_MEDIA . "';\n";
2819 $config_data .= "\n";
2820 $config_data .= "// extra skin files for imported skins\n";
2821 $config_data .= "\$DIR_SKINS = '" . $DIR_SKINS . "';\n";
2822 $config_data .= "\n";
2823 $config_data .= "// these dirs are normally sub dirs of the nucleus dir, but \n";
2824 $config_data .= "// you can redefine them if you wish\n";
2825 $config_data .= "\$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";
2826 $config_data .= "\$DIR_LOCALES = \$DIR_NUCLEUS . 'locales/';\n";
2827 $config_data .= "\$DIR_LIBS = \$DIR_NUCLEUS . 'libs/';\n";
2828 $config_data .= "\n";
2829 $config_data .= "// include libs\n";
2830 $config_data .= "include(\$DIR_LIBS.'globalfunctions.php');\n";
2831 $config_data .= "?" . ">";
2834 if ( @!file_exists('../config.php') || is_writable('../config.php') )
2836 if ( $fp = @fopen('../config.php', 'w') )
2838 $result = @fwrite($fp, $config_data, i18n::strlen($config_data));
2845 // try to change the read-only permission.
2846 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
2848 @chmod('../config.php', 0444);
2853 $_SESSION['config_data'] = $config_data;
2860 * Confirm that you can write to the configuration file
2861 * @return string error message
2863 function canConfigFileWritable()
2865 if ( @file_exists('../config.php') && @!is_writable('../config.php') )
2867 // try to change the read-write permission.
2868 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
2870 @chmod('../config.php', 0666);
2873 if ( @!is_writable('../config.php') )
2875 return _INST_ERROR8;
2882 * To obtain the version of MySQL
2885 function getMySqlVersion()
2887 global $MYSQL_HANDLER, $minimum_mysql_version, $errors;
2888 // Turn on output buffer
2889 // Needed to repress the output of the sql function that are
2890 // not part of php (in this case the @ operator doesn't work)
2893 // note: this piece of code is taken from phpMyAdmin
2894 $conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], 'localhost', '', '');
2898 $row = DB::getAttribute(PDO::ATTR_SERVER_VERSION);
2899 $match = preg_split('#\.#', $row);
2903 $row = @DB::getRow('SHOW VARIABLES LIKE \'version\'');
2907 $match = preg_split('#\.#', $row[1]);
2911 $output = (function_exists('shell_exec')) ? @shell_exec('mysql -V') : '0.0.0';
2912 preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
2913 $match = preg_split('#\.#', $version[0]);
2915 if ( $match[0] == '' )
2917 $match = array('0', '0', '0');
2924 //End and clean output buffer
2927 return implode($match, '.');
2931 * Add a table prefix if it is used
2933 * @param string $input table name with prefix
2936 function tableName($input)
2938 global $MYSQL_PREFIX;
2939 if ( $MYSQL_PREFIX )
2941 return $MYSQL_PREFIX . $input;
2950 * Install custom plugins
2952 function installCustomPlugs()
2954 global $aConfPlugsToInstall, $DIR_LIBS, $manager;
2957 if ( count($aConfPlugsToInstall) == 0 )
2962 $query = sprintf('SELECT * FROM %s', tableName('nucleus_plugin'));
2963 $res = DB::getResult($query);
2964 $numCurrent = $res->rowCount();
2966 foreach ( $aConfPlugsToInstall as $plugName )
2968 $query = sprintf('INSERT INTO %s (porder, pfile) VALUES (%d, %s)',
2969 tableName('nucleus_plugin'),
2971 DB::quoteValue($plugName));
2972 DB::execute($query);
2974 $manager->clearCachedInfo('installedPlugins');
2975 $plugin =& $manager->getPlugin($plugName);
2976 $plugin->setID($numCurrent);
2980 $query = sprintf('DELETE FROM %s WHERE pfile = %s',
2981 tableName('nucleus_plugin'),
2982 DB::quoteValue($plugName));
2983 DB::execute($query);
2985 array_push($aErrors, sprintf(_INST_ERROR9, $plugName));
2991 $query = sprintf('DELETE FROM %s', tableName('nucleus_plugin_event'));
2992 DB::execute($query);
2993 $query = sprintf('SELECT pid, pfile FROM %s', tableName('nucleus_plugin'));
2994 $res = DB::getResult($query);
2996 foreach ( $res as $row )
2998 $plug =& $manager->getPlugin($row['pfile']);
3002 $eventList = $plug->getEventList();
3003 foreach ( $eventList as $eventName )
3005 $query = sprintf('INSERT INTO %s (pid, event) VALUES (%d, %s)',
3006 tableName('nucleus_plugin_event'),
3007 intval($row['pid']),
3008 DB::quoteValue($eventName));
3009 DB::execute($query);
3017 * Install custom skins
3018 * Prepares the installation of custom skins
3020 function installCustomSkins()
3022 global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS;
3025 if ( count($aConfSkinsToImport) == 0 )
3030 $importer = new SkinImport();
3032 foreach ( $aConfSkinsToImport as $skinName )
3035 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';
3037 if ( !@file_exists($skinFile) )
3039 array_push($aErrors, sprintf(_INST_ERROR10, $skinFile));
3043 $error = $importer->readFile($skinFile);
3047 array_push($aErrors, sprintf(_INST_ERROR11, $skinName) . ' : ' . $error);
3051 $error = $importer->writeToDatabase(1);
3055 array_push($aErrors, sprintf(_INST_ERROR12, $skinName) . ' : ' . $error);
3063 * Check if some important files of the Nucleus CMS installation are available
3064 * Give an error if one or more files are not accessible
3066 function do_check_files()
3068 $missingfiles = array();
3073 '../nucleus/index.php',
3074 '../nucleus/libs/ACTION.php',
3075 '../nucleus/libs/ACTIONLOG.php',
3076 '../nucleus/libs/ACTIONS.php',
3077 '../nucleus/libs/ADMIN.php',
3078 '../nucleus/libs/BaseActions.php',
3079 '../nucleus/libs/BLOG.php',
3080 '../nucleus/libs/BODYACTIONS.php',
3081 '../nucleus/libs/COMMENT.php',
3082 '../nucleus/libs/COMMENTACTIONS.php',
3083 '../nucleus/libs/COMMENTS.php',
3084 '../nucleus/libs/ENTITY.php',
3085 '../nucleus/libs/globalfunctions.php',
3086 '../nucleus/libs/i18n.php',
3087 '../nucleus/libs/ITEM.php',
3088 '../nucleus/libs/ITEMACTIONS.php',
3089 '../nucleus/libs/LINK.php',
3090 '../nucleus/libs/MANAGER.php',
3091 '../nucleus/libs/MEDIA.php',
3092 '../nucleus/libs/MEMBER.php',
3093 '../nucleus/libs/NOTIFICATION.php',
3094 '../nucleus/libs/PARSER.php',
3095 '../nucleus/libs/PLUGIN.php',
3096 '../nucleus/libs/PLUGINADMIN.php',
3097 '../nucleus/libs/SEARCH.php',
3098 '../nucleus/libs/showlist.php',
3099 '../nucleus/libs/SKIN.php',
3100 '../nucleus/libs/TEMPLATE.php',
3101 '../nucleus/libs/vars4.1.0.php',
3102 '../nucleus/libs/xmlrpc.inc.php',
3103 '../nucleus/libs/xmlrpcs.inc.php',
3104 '../nucleus/libs/sql/DB.php',
3105 '../nucleus/libs/sql/MYSQLPDO.php'
3108 $count = count($files);
3109 for ( $i = 0; $i < $count; $i++ )
3111 if ( !is_readable($files[$i]) )
3113 array_push($missingfiles, 'File <b>' . $files[$i] . '</b> is missing or not readable.<br />');
3117 if ( count($missingfiles) > 0 )
3119 exit(implode("\n", $missingfiles));
3124 * Updates the configuration in the database
3126 * @param string $name name of the config var
3127 * @param string $value new value of the config var
3130 function updateConfig($name, $value)
3134 $query = "UPDATE %s SET value = %s WHERE name = %s";
3135 $query = sprintf($query, tableName('nucleus_config'), DB::quoteValue(trim($value)), DB::quoteValue($name));
3137 if ( DB::execute($query) === FALSE )
3139 $errinfo = DB::getError();
3140 $errors[] = _INST_ERROR4 . ': ' . $errinfo[2];
3147 /* process parameter */
3151 /* mysql connection parameters */
3154 public $mysql_password;
3155 public $mysql_database;
3156 public $mysql_tablePrefix;
3158 /* weblog configuration parameters */
3160 public $blog_shortname;
3162 /* member configuration parameters */
3164 public $user_realname;
3165 public $user_password;
3166 private $user_password2;
3169 /* URI parameters */
3178 /* path parameters */
3187 public function __construct()
3192 public function init()
3194 // set default values
3195 $this->state = 'locale';
3196 $this->install_mode = 'simple';
3198 $this->mysql_host = @ini_get('mysql.default_host');
3199 $this->blog_name = 'My Nucleus CMS';
3200 $this->blog_shortname = 'mynucleuscms';
3203 $directory_separator = preg_quote(DIRECTORY_SEPARATOR, '|');
3204 $this->root_path = implode('/', preg_split("|$directory_separator|", realpath(dirname(__FILE__) . '/..')));
3205 if ( substr($this->root_path, -1, 1) !== '/' )
3207 $this->root_path .= '/';
3209 $base_path_pcre = preg_quote($this->root_path, '|');
3211 /* current directry name */
3212 $directory_name = preg_replace("#{$base_path_pcre}#", '', implode('/', preg_split("#{$directory_separator}#", realpath(dirname(__FILE__)))));
3213 $directory_name_pcre = preg_quote($directory_name, '|');
3216 $root_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
3217 $this->root_url = preg_replace("|$directory_name_pcre(.*)$|", '', $root_url);
3219 $this->AdminPath = $this->root_path . 'nucleus/';
3220 $this->MediaPath = $this->root_path . 'media/';
3221 $this->SkinsPath = $this->root_path . 'skins/';
3223 $this->IndexURL = $this->root_url;
3224 $this->AdminURL = $this->root_url . 'nucleus/';
3225 $this->MediaURL = $this->root_url . 'media/';
3226 $this->SkinsURL = $this->root_url . 'skins/';
3227 $this->PluginURL = $this->root_url . 'nucleus/plugins/';
3228 $this->ActionURL = $this->root_url . 'action.php';
3231 private function read_parameter($parameter)
3233 foreach ( $parameter as $element )
3235 if ( array_key_exists($element, $_POST) )
3237 $this->$element = $_POST[$element];
3242 public function set_state($state)
3244 $states = array('locale', 'mysql', 'weblog', 'detail', 'install');
3245 if ( in_array($state, $states) )
3247 $this->state = $state;
3251 public function set_locale()
3253 $this->read_parameter(array('locale'));
3255 if ( !$this->locale )
3258 * default locale select simple implementation
3261 * RFC2616: Hypertext Transfer Protocol -- HTTP/1.1
3262 * http://www.ietf.org/rfc/rfc2616.txt
3264 * 14.4 Accept-Language
3266 * The Accept-Language request-header field is similar to Accept, but
3267 * restricts the set of natural languages that are preferred as a
3268 * response to the request. Language tags are defined in section 3.10.
3270 * Accept-Language = "Accept-Language" ":"
3271 * 1#( language-range [ ";" "q" "=" qvalue ] )
3272 * language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
3274 * Each language-range MAY be given an associated quality value which
3275 * represents an estimate of the user's preference for the languages
3276 * specified by that range. The quality value defaults to "q=1". For
3279 * Accept-Language: da, en-gb;q=0.8, en;q=0.7
3281 * would mean: "I prefer Danish, but will accept British English and
3282 * other types of English." A language-range matches a language-tag if
3283 * it exactly equals the tag, or if it exactly equals a prefix of the
3284 * tag such that the first tag character following the prefix is "-".
3285 * The special range "*", if present in the Accept-Language field,
3286 * matches every tag not matched by any other range present in the
3287 * Accept-Language field.
3289 * TODO: this is appropriate implement or not
3291 $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
3293 /* retrieve language token of language tag from first token */
3295 if ( is_array($languages) && count($languages) > 0 )
3297 $language = preg_replace('#^([\w]+).*$#', '$1', $languages[0]);
3300 $locales = i18n::get_available_locale_list();
3301 foreach ( $locales as $locale )
3303 if ( i18n::strpos($locale, $language) === 0 )
3305 $this->locale = $locale;
3311 /* include installer translation messages */
3312 $translation_file = "./locales/{$this->locale}." . i18n::get_current_charset() . '.php';
3313 if ( !file_exists($translation_file) )
3315 $translation_file = './locales/en_Latn_US.UTF-8.php';
3317 include($translation_file);
3319 /* include global translation messages */
3320 $translation_file = "../nucleus/locales/{$this->locale}." . i18n::get_current_charset() . '.php';
3321 if ( !file_exists($translation_file) )
3323 $translation_file = './locales/en_Latn_US.UTF-8.php';
3325 include($translation_file);
3327 i18n::set_current_locale($this->locale);
3332 public function check_mysql_parameters()
3334 global $MYSQL_HANDLER;
3336 $parameters = array('mysql_host', 'mysql_user', 'mysql_password', 'mysql_database', 'mysql_tablePrefix');
3337 $this->read_parameter($parameters);
3340 if ( $this->mysql_host == '' )
3342 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD1);
3345 if ( $this->mysql_user == '' )
3347 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD2);
3350 if ( $this->mysql_user != ''
3351 && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_user) )
3353 $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD2);
3356 if ( $this->mysql_database == '' )
3358 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD4);
3361 if ( $this->mysql_database != ''
3362 && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_database) )
3364 $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD4);
3367 if ( $this->mysql_tablePrefix != ''
3368 && !preg_match('/^[a-z0-9_]+$/i', $this->mysql_tablePrefix) )
3370 $errors[] = sprintf(_VALID_ERROR3, _DB_FIELD5);
3373 if ( count($errors) == 0 )
3375 $mysql_conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], $this->mysql_host, $this->mysql_user, $this->mysql_password);
3376 if ( $mysql_conn == false )
3378 $errors[] = _DBCONNECT_ERROR;
3389 public function check_user_parameters()
3391 $parameters = array('user_name', 'user_realname', 'user_password', 'user_password2', 'user_email');
3392 $this->read_parameter($parameters);
3395 if ( $this->user_realname == '' )
3397 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD1);
3400 if ( $this->user_name == '' )
3402 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD2);
3404 elseif ( !preg_match("/^[a-z0-9]+([ a-z0-9]*[a-z0-9]+)?$/i", $this->user_name) )
3406 $errors[] = _VALID_ERROR5;
3409 if ( $this->user_password == '' || $this->user_password2 == '' )
3411 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD3);
3412 $this->user_password = '';
3414 elseif ( $this->user_password != $this->user_password2 )
3416 $errors[] = _VALID_ERROR6;
3417 $this->user_password = '';
3420 if ( !preg_match("/^[a-z0-9\._+\-]+@[a-z0-9\._\-]+\.[a-z]{2,6}$/i", $this->user_email) )
3422 $errors[] = _VALID_ERROR7;
3428 public function check_weblog_parameters()
3430 $parameters = array('blog_name', 'blog_shortname');
3431 $this->read_parameter($parameters);
3434 if ( $this->blog_name == '' )
3436 $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD1);
3439 if ( $this->blog_shortname == '' )
3441 $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD2);
3444 if ( !preg_match("/^[a-z0-9]+$/i", $this->blog_shortname) )
3446 $errors[] = _VALID_ERROR4;
3452 public function check_uri_parameters()
3454 $parameters = array('IndexURL', 'AdminURL', 'MediaURL', 'SkinsURL', 'PluginURL', 'ActionURL');
3455 $this->read_parameter($parameters);
3458 if ( substr($this->IndexURL, -1, 1) !== '/' )
3460 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD1);
3463 if ( substr($this->AdminURL, -1, 1) !== '/' )
3465 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD2);
3468 if ( substr($this->MediaURL, -1, 1) !== '/' )
3470 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD4);
3473 if ( substr($this->SkinsURL, -1, 1) !== '/' )
3475 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD6);
3478 if ( substr($this->PluginURL, -1, 1) !== '/' )
3480 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD8);
3483 if ( strrchr($this->ActionURL, '/') != '/action.php' )
3485 $errors[] = sprintf(_VALID_ERROR9, _PATH_FIELD9);
3491 public function check_path_parameters()
3493 $parameters = array('AdminPath', 'MediaPath', 'SkinsPath');
3494 $this->read_parameter($parameters);
3496 $separators = array('/', DIRECTORY_SEPARATOR);
3498 if ( !in_array(substr($this->AdminPath, -1, 1), $separators) )
3500 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD3);
3502 elseif ( !file_exists($this->AdminPath) )
3504 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD3);
3507 if ( !in_array(substr($this->MediaPath, -1, 1), $separators) )
3509 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD5);
3511 elseif ( !file_exists($this->MediaPath) )
3513 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD5);
3516 if ( !in_array(substr($this->SkinsPath, -1, 1), $separators) )
3518 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD7);
3520 elseif ( !file_exists($this->SkinsPath) )
3522 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD7);
3529 * check all parameters
3532 public function check_all_parameters()
3534 $this->set_locale();
3537 $isValid &= (count($this->check_mysql_parameters()) == 0);
3538 $isValid &= (count($this->check_user_parameters()) == 0);
3539 $isValid &= (count($this->check_weblog_parameters()) == 0);
3540 $isValid &= (count($this->check_uri_parameters()) == 0);
3541 $isValid &= (count($this->check_path_parameters()) == 0);
3546 >>>>>>> skinnable-master