3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2012 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
12 * This script will install the Nucleus tables in your SQL-database,
\r
13 * and initialize the data in those tables.
\r
17 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
18 * @copyright Copyright (C) 2002-2012 The Nucleus Group
\r
19 * @version $Id: index.php 1745 2012-04-12 23:45:47Z sakamocchi $
\r
22 /* global values initialize */
\r
25 /* reporting all errors for support */
\r
26 error_reporting(E_ALL);
\r
28 $minimum_php_version = '5.0.6';
\r
29 $minimum_mysql_version = '3.23';
\r
31 $page_footer_copyright = '© 2001-2012 The Nucleus Groupe . Running Nucleus CMS v4.00';
\r
33 // begin if: server's PHP version is below the minimum; halt installation
\r
34 if ( version_compare(PHP_VERSION, $minimum_php_version, '<') )
\r
36 exit('<div style="font-size: xx-large;"> Nucleus requires at least PHP version ' . $minimum_php_version . '</div>');
\r
39 // make sure there's no unnecessary escaping: # set_magic_quotes_runtime(0);
\r
40 if ( version_compare(PHP_VERSION, '5.3.0', '<') )
\r
42 ini_set('magic_quotes_runtime', '0');
\r
45 /* default installed plugins and skins */
\r
46 $aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles', 'NP_Medium');
\r
47 $aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default', 'admin/default', 'admin/bookmarklet');
\r
49 // Check if some important files
\r
52 /* i18n class is needed for internationalization */
\r
53 include_once('../nucleus/libs/i18n.php');
\r
54 if ( !i18n::init('UTF-8', '../nucleus/locales') )
\r
56 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
59 // include core classes that are needed for login & plugin handling
\r
61 // added for 3.5 sql_* wrapper
\r
62 global $MYSQL_HANDLER;
\r
64 if ( !isset($MYSQL_HANDLER) )
\r
66 $MYSQL_HANDLER = array('mysql', '');
\r
68 // check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x
\r
69 if ( !function_exists('mysql_query') && !function_exists('mysqli_query') )
\r
71 exit('<div style="font-size: xx-large;"> Your PHP version does not have support for MySQL :( </div>');
\r
74 include_once('../nucleus/libs/sql/sql.php');
\r
77 if ( count($_GET) == 0 && count($_POST) == 0 )
\r
79 unset($_SESSION['param_manager']);
\r
82 // restore the $param from the session
\r
83 if ( array_key_exists('param_manager', $_SESSION) )
\r
85 $param = $_SESSION['param_manager'];
\r
89 $param = new ParamManager();
\r
92 // include translation file
\r
93 if ( array_key_exists('locale', $_POST) ) $param->set_locale();
\r
94 i18n::set_current_locale($param->locale);
\r
95 $translation_file = './locales/' . i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php';
\r
96 if ( !file_exists($translation_file) )
\r
98 $translation_file = './locales/en_Latn_US.UTF-8.php';
\r
100 include($translation_file);
\r
104 // $param is saved to the session
\r
105 if ( isset($param) )
\r
107 $_SESSION['param_manager'] = $param;
\r
111 unset($_SESSION['param_manager']);
\r
118 function do_action()
\r
122 if ( array_key_exists('action', $_POST) )
\r
124 $isPostback = true;
\r
128 $isPostback = false;
\r
132 if ( array_key_exists('mode', $_REQUEST) )
\r
134 if ( $_REQUEST['mode'] == 'detail' )
\r
136 $param->set_state('detail');
\r
138 elseif ( $_REQUEST['mode'] == 'simple' )
\r
140 $param->set_state('mysql');
\r
144 // input parameter check
\r
147 switch ( $param->state )
\r
150 $param->set_locale();
\r
151 $param->set_state('mysql');
\r
152 $isPostback = false;
\r
155 if ( count($param->check_mysql_parameters()) == 0 )
\r
157 $param->set_state('weblog');
\r
158 $isPostback = false;
\r
162 if ( count($param->check_user_parameters()) == 0
\r
163 && count($param->check_weblog_parameters()) == 0 )
\r
165 $param->set_state('install');
\r
166 $isPostback = false;
\r
170 if ( $param->check_all_parameters() )
\r
172 $param->set_state('install');
\r
173 $isPostback = false;
\r
181 switch ( $param->state )
\r
184 show_select_locale_form();
\r
187 show_database_setting_form($isPostback);
\r
190 show_blog_setting_form($isPostback);
\r
193 show_detail_setting_form($isPostback);
\r
196 show_install_complete_form();
\r
203 * header tag of the installation screens
\r
205 function show_header()
\r
209 /* HTTP 1.1 application for no caching */
\r
210 header("Cache-Control: no-cache, must-revalidate");
\r
211 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
\r
212 header('Content-Type: text/html; charset=' . i18n::get_current_charset());
\r
214 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
\r
215 <html xmlns="http://www.w3.org/1999/xhtml">
\r
217 <title><?php echo _TITLE; ?></title>
\r
218 <link rel="stylesheet" type="text/css" href="./styles/inst.css" />
\r
219 <style type="text/css">
\r
221 <?php echo _BODYFONTSTYLE; ?>
\r
224 <script type="text/javascript">
\r
225 function SelectText( element ) {
\r
226 window.setTimeout( function() { element.select() }, 0 );
\r
228 var isSubmit = false;
\r
229 function OnceSubmit() {
\r
232 window.setTimeout( function() { isSubmit = false; }, 10000 );
\r
241 <div id="navigation">
\r
242 <h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>
\r
245 if ( in_array($param->state, array('mysql', 'weblog', 'install')) )
\r
247 echo '<li>', _STEP1, '</li><li';
\r
248 if ( $param->state == 'mysql' )
\r
250 echo ' class="gry"';
\r
252 echo '> > ', _STEP2, '</li><li';
\r
253 if ( in_array($param->state, array('mysql', 'weblog')) )
\r
255 echo ' class="gry"';
\r
257 echo '> > ', _STEP3, "</li>\n";
\r
259 if ( in_array($param->state, array('mysql', 'weblog', 'detail')) )
\r
261 echo '<li class="rightbox">';
\r
262 if ( in_array($param->state, array('mysql', 'weblog')) )
\r
264 echo '<a href="./?mode=detail">', _MODE2, '</a>';
\r
268 echo '<a href="./?mode=simple">', _MODE1, '</a>';
\r
280 * footer tag of the installation screens
\r
282 function show_footer()
\r
284 global $page_footer_copyright;
\r
287 <?php echo $page_footer_copyright; ?>
\r
295 * Display the form for language select
\r
297 function show_select_locale_form()
\r
300 $localelist = i18n::get_available_locale_list();
\r
301 $locales = array();
\r
302 foreach ( $localelist as $locale ) {
\r
303 $checkfile = './locales/' . $locale . '.' . i18n::get_current_charset() . '.php';
\r
304 $locales[] = array( $locale, (!file_exists($checkfile) ? '* ' : '') . $locale );
\r
307 <div id="container">
\r
308 <p style="font-size:152%;font-weight:bold;">
\r
309 Select your locale:
\r
311 <form method="post" action="./index.php">
\r
314 <select name="locale">
\r
316 // Get the browser language that can be displayed
\r
317 // TODO: default locale select simple implementation
\r
318 $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
\r
319 $language = (is_array($languages) && count($languages) > 0) ? preg_replace('#^([\w]+).*$#', '$1', $languages[0]) : '';
\r
321 foreach ( $locales as $locale )
\r
323 echo "<option value=\"$locale[0]\"";
\r
324 if ( i18n::strpos($locale[0], $language) === 0 )
\r
328 echo ">$locale[1]</option>\n";
\r
332 <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
333 <p>We will wait for the translator by volunteers!</p>
\r
336 <button type="submit" name="action" value="locale" class="sbt_arw">START</button>
\r
345 * Display the form to set up a database
\r
346 * @param bool $isPostback
\r
348 function show_database_setting_form($isPostback)
\r
350 global $param, $minimum_mysql_version;
\r
352 $config_writable = canConfigFileWritable();
\r
353 $mysql_version = getMySqlVersion();
\r
355 <div id="container">
\r
358 echo _SIMPLE_NAVI1;
\r
359 if ( $config_writable != '' )
\r
361 echo '<span class="err">', $config_writable, '</span>';
\r
363 if ( $mysql_version == '0.0.0' )
\r
365 echo '<span class="err">', _DBVERSION_UNKOWN, '</span>';
\r
367 elseif ( version_compare($mysql_version, $minimum_mysql_version, '<') )
\r
369 echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';
\r
373 <form method="post" action="./index.php">
\r
375 <h2><?php echo _DB_HEADER; ?></h2>
\r
380 $errors = $param->check_mysql_parameters();
\r
381 if ( is_array($errors) )
\r
383 foreach ( $errors as $error )
\r
385 echo '<span class="err">', $error, "</span>\n";
\r
393 <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>
\r
394 <td><input type="text" name="mysql_host" value="<?php echo $param->mysql_host; ?>" /></td>
\r
397 <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>
\r
398 <td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>
\r
401 <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>
\r
402 <td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>
\r
405 <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>
\r
406 <td><input type="text" name="mysql_database" value="<?php echo $param->mysql_database; ?>" /></td>
\r
410 <button type="submit" name="mode" value="detail" class="sbt_sqr"><?php echo _MODE2; ?></button>
\r
411 <button type="submit" name="action" value="mysql" class="sbt_arw"><?php echo _NEXT; ?></button>
\r
414 <?php echo _DB_TEXT1; ?>
\r
423 * Displays a form to the blog settings
\r
424 * @param bool $isPostback
\r
426 function show_blog_setting_form($isPostback)
\r
430 <div id="container">
\r
432 <?php echo _SIMPLE_NAVI2; ?>
\r
434 <form method="post" action="./index.php">
\r
436 <h2><?php echo _BLOG_HEADER; ?></h2>
\r
441 $errors = $param->check_weblog_parameters();
\r
442 if ( is_array($errors) )
\r
444 foreach ( $errors as $error )
\r
446 echo '<span class="err">', $error, "</span>\n";
\r
454 <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>
\r
455 <td><input type="text" name="blog_name" value="<?php echo $param->blog_name; ?>" /></td>
\r
458 <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>
\r
459 <td><input type="text" name="blog_shortname" value="<?php echo $param->blog_shortname; ?>" /></td>
\r
465 <h2><?php echo _ADMIN_HEADER; ?></h2>
\r
470 $errors = $param->check_user_parameters();
\r
471 if ( is_array($errors) )
\r
473 foreach ( $errors as $error )
\r
475 echo '<span class="err">', $error, "</span>\n";
\r
483 <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>
\r
484 <td><input type="text" name="user_realname" value="<?php echo $param->user_realname; ?>" /></td>
\r
487 <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>
\r
488 <td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>
\r
491 <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>
\r
492 <td><input type="password" name="user_password" /></td>
\r
495 <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>
\r
496 <td><input type="password" name="user_password2" /></td>
\r
499 <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>
\r
500 <td><input type="text" name="user_email" value="<?php echo $param->user_email; ?>" /></td>
\r
504 <button type="submit" name="action" value="weblog" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>
\r
513 * Displays a form to the detail settings
\r
514 * @param bool $isPostback
\r
516 function show_detail_setting_form($isPostback)
\r
518 global $param, $minimum_mysql_version;
\r
520 $mysql_version = getMySqlVersion();
\r
522 <div id="container_detailed">
\r
524 <?php echo _DETAIL_NAVI1; ?>
\r
526 if ( $isPostback && !$param->check_all_parameters() )
\r
528 echo '<span class="err">', _VALID_ERROR, "</span>\n";
\r
533 <li>PHP: <?php echo phpversion(); ?></li>
\r
536 echo ($mysql_version == '0.0.0') ? _DBVERSION_UNKOWN : $mysql_version;
\r
537 if ( version_compare($mysql_version, $minimum_mysql_version, '<') )
\r
539 echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';
\r
543 <form method="post" action="">
\r
546 <h2><?php echo _DETAIL_HEADER1; ?></h2>
\r
551 $errors = $param->check_mysql_parameters();
\r
552 if ( is_array($errors) )
\r
554 foreach ( $errors as $error )
\r
556 echo '<span class="err">', $error, "</span>\n";
\r
564 <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>
\r
565 <td><input type="text" name="mysql_host" value="<?php echo $param->mysql_host; ?>" /></td>
\r
568 <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>
\r
569 <td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>
\r
572 <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>
\r
573 <td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>
\r
576 <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>
\r
577 <td><input type="text" name="mysql_database" value="<?php echo $param->mysql_database; ?>" /></td>
\r
580 <th><span class="nam"><?php echo _DB_FIELD5; ?></span><span class="sub"><?php echo _DB_FIELD5_DESC; ?></span></th>
\r
581 <td><input type="text" name="mysql_tablePrefix" value="<?php echo $param->mysql_tablePrefix; ?>" /></td>
\r
585 <h2><?php echo _DETAIL_HEADER2; ?></h2>
\r
590 $errors = $param->check_uri_parameters();
\r
591 if ( is_array($errors) )
\r
593 foreach ( $errors as $error )
\r
595 echo '<span class="err">', $error, "</span>\n";
\r
598 $errors = $param->check_path_parameters();
\r
599 if ( is_array($errors) )
\r
601 foreach ( $errors as $error )
\r
603 echo '<span class="err">', $error, "</span>\n";
\r
611 <th><span class="nam"><?php echo _PATH_FIELD1; ?></span></th>
\r
612 <td><input type="text" name="IndexURL" value="<?php echo $param->IndexURL; ?>" /></td>
\r
615 <th><span class="nam"><?php echo _PATH_FIELD2; ?></span></th>
\r
616 <td><input type="text" name="AdminURL" value="<?php echo $param->AdminURL; ?>" /></td>
\r
619 <th><span class="nam"><?php echo _PATH_FIELD3; ?></span></th>
\r
620 <td><input type="text" name="AdminPath" value="<?php echo $param->AdminPath; ?>" /></td>
\r
623 <th><span class="nam"><?php echo _PATH_FIELD4; ?></span></th>
\r
624 <td><input type="text" name="MediaURL" value="<?php echo $param->MediaURL; ?>" /></td>
\r
627 <th><span class="nam"><?php echo _PATH_FIELD5; ?></span></th>
\r
628 <td><input type="text" name="MediaPath" value="<?php echo $param->MediaPath; ?>" /></td>
\r
631 <th><span class="nam"><?php echo _PATH_FIELD6; ?></span></th>
\r
632 <td><input type="text" name="SkinsURL" value="<?php echo $param->SkinsURL; ?>" /></td>
\r
635 <th><span class="nam"><?php echo _PATH_FIELD7; ?></span></th>
\r
636 <td><input type="text" name="SkinsPath" value="<?php echo $param->SkinsPath; ?>" /></td>
\r
639 <th><span class="nam"><?php echo _PATH_FIELD8; ?></span></th>
\r
640 <td><input type="text" name="PluginURL" value="<?php echo $param->PluginURL; ?>" /></td>
\r
643 <th><span class="nam"><?php echo _PATH_FIELD9; ?></span></th>
\r
644 <td><input type="text" name="ActionURL" value="<?php echo $param->ActionURL; ?>" /></td>
\r
648 <?php echo _DETAIL_TEXT3; ?>
\r
651 <h2><?php echo _DETAIL_HEADER3; ?></h2>
\r
654 echo _DETAIL_TEXT4;
\r
657 $errors = $param->check_user_parameters();
\r
658 if ( is_array($errors) )
\r
660 foreach ( $errors as $error )
\r
662 echo '<span class="err">', $error, "</span>\n";
\r
670 <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>
\r
671 <td><input type="text" name="user_realname" value="<?php echo $param->user_realname; ?>" /></td>
\r
674 <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>
\r
675 <td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>
\r
678 <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>
\r
679 <td><input type="password" name="user_password" /></td>
\r
682 <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>
\r
683 <td><input type="password" name="user_password2" /></td>
\r
686 <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>
\r
687 <td><input type="text" name="user_email" value="<?php echo $param->user_email; ?>" /></td>
\r
691 <h2><?php echo _DETAIL_HEADER4; ?></h2>
\r
694 echo _DETAIL_TEXT5;
\r
697 $errors = $param->check_weblog_parameters();
\r
698 if ( is_array($errors) )
\r
700 foreach ( $errors as $error )
\r
702 echo '<span class="err">', $error, "</span>\n";
\r
710 <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>
\r
711 <td><input type="text" name="blog_name" value="<?php echo $param->blog_name; ?>" /></td>
\r
714 <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>
\r
715 <td><input type="text" name="blog_shortname" value="<?php echo $param->blog_shortname; ?>" /></td>
\r
720 <?php echo _DETAIL_TEXT6; ?>
\r
724 <button type="submit" name="action" value="detail" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>
\r
733 * Displays a screen to signal the completion of the installation
\r
735 function show_install_complete_form()
\r
737 global $MYSQL_HANDLER, $param;
\r
738 $errors = do_install();
\r
740 <div id="container">
\r
743 if ( is_array($errors) && count($errors) > 0 )
\r
746 foreach ( $errors as $error )
\r
748 echo '<span class="err">', $error, "</span>\n";
\r
754 if ( array_key_exists('config_data', $_SESSION) )
\r
756 echo '<span class="err">', _INST_TEXT4, '</span>';
\r
758 <textarea id="config_text" readonly="readonly" onfocus="SelectText(this);"><?php echo htmlentities($_SESSION['config_data'], null, i18n::get_current_charset()) ?></textarea>
\r
763 echo '<span class="err">', _INST_TEXT5, '</span>';
\r
767 <form method="post" action="./index.php">
\r
769 <h2><?php echo _INST_HEADER1; ?></h2>
\r
771 <?php echo sprintf(_INST_TEXT1, $param->blog_name); ?>
\r
774 <button type="button" name="toBlog" onclick="location.href='<?php echo $param->IndexURL; ?>';" class="sbt_arw"><?php echo _INST_BUTTON1; ?></button>
\r
779 <h2><?php echo _INST_HEADER2; ?></h2>
\r
781 <?php echo _INST_TEXT2; ?>
\r
784 <button type="button" name="toMng" onclick="location.href='<?php echo $param->AdminURL; ?>';" class="sbt_arw"><?php echo _INST_BUTTON2; ?></button>
\r
789 <h2><?php echo _INST_HEADER3; ?></h2>
\r
791 <?php echo _INST_TEXT3; ?>
\r
794 <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
807 * The installation process itself
\r
808 * @return array error messages
\r
810 function do_install()
\r
813 global $MYSQL_HANDLER, $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX, $MYSQL_CONN;
\r
814 global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;
\r
818 * 1. put all param-vars into vars
\r
820 $MYSQL_HOST = $param->mysql_host;
\r
821 $MYSQL_USER = $param->mysql_user;
\r
822 $MYSQL_PASSWORD = $param->mysql_password;
\r
823 $MYSQL_DATABASE = $param->mysql_database;
\r
824 $MYSQL_PREFIX = $param->mysql_tablePrefix;
\r
826 $DIR_NUCLEUS = $param->AdminPath;
\r
827 $DIR_MEDIA = $param->MediaPath;
\r
828 $DIR_SKINS = $param->SkinsPath;
\r
829 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
\r
830 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
\r
831 $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
\r
834 * 2.open mySQL connection
\r
836 $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
\r
837 if ( $MYSQL_CONN == FALSE )
\r
839 $errors[] = _DBCONNECT_ERROR;
\r
844 * 3. try to create database if needed
\r
846 if ( DB::execute("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") === FALSE )
\r
848 $errinfo = DB::getError();
\r
849 $errors[] = _INST_ERROR1 . ': ' . $errinfo[2];
\r
853 * 4. try to select database
\r
855 $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE);
\r
856 if ( !$MYSQL_CONN )
\r
858 $errors[] = _INST_ERROR2;
\r
861 if ( count($errors) > 0 )
\r
867 * 5. execute queries
\r
869 $table_names = array(
\r
870 'nucleus_actionlog',
\r
873 'nucleus_category',
\r
881 'nucleus_template',
\r
883 'nucleus_activation',
\r
887 $prefixed_table_names = array();
\r
888 foreach ( $table_names as $table_name )
\r
890 $prefixed_table_names[] = $MYSQL_PREFIX . $table_name;
\r
893 // table exists check
\r
894 $result = DB::getResult('SHOW TABLES');
\r
895 foreach ( $result as $row )
\r
897 if ( in_array($row[0], $prefixed_table_names) )
\r
899 $errors[] = _INST_ERROR3;
\r
903 if ( count($errors) > 0 )
\r
908 $filename = 'install.sql';
\r
909 $fd = fopen($filename, 'r');
\r
910 $queries = fread($fd, filesize($filename));
\r
913 $queries = preg_split('#(;\n|;\r)#', $queries);
\r
915 foreach ( $queries as $query )
\r
917 if ( preg_match('/\w+/', $query) )
\r
919 if ( $MYSQL_PREFIX )
\r
921 $query = str_replace($table_names, $prefixed_table_names, $query);
\r
924 if ( DB::execute($query) === FALSE )
\r
926 $errinfo = DB::getError();
\r
927 $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . $errinfo[2];
\r
933 * 6. put needed records
\r
935 /* push first post */
\r
936 $query = "INSERT INTO %s VALUES (1, %s, %s, %s, 1, 1, %s, 0, 0, 0, 1, 0, 1)";
\r
937 $query = sprintf($query,
\r
938 tableName('nucleus_item'),
\r
939 DB::quoteValue(_1ST_POST_TITLE),
\r
940 DB::quoteValue(_1ST_POST),
\r
941 DB::quoteValue(_1ST_POST2),
\r
942 DB::formatDateTime()
\r
944 if ( DB::execute($query) === FALSE )
\r
946 $errinfo = DB::getError();
\r
947 $errors[] = _INST_ERROR4 . ' (<small>' . $newpost . '</small>): ' . $errinfo[2];
\r
950 /* push configurations */
\r
951 array_merge($errors, updateConfig('IndexURL', $param->IndexURL));
\r
952 array_merge($errors, updateConfig('AdminURL', $param->AdminURL));
\r
953 array_merge($errors, updateConfig('MediaURL', $param->MediaURL));
\r
954 array_merge($errors, updateConfig('SkinsURL', $param->SkinsURL));
\r
955 array_merge($errors, updateConfig('PluginURL', $param->PluginURL));
\r
956 array_merge($errors, updateConfig('ActionURL', $param->ActionURL));
\r
957 array_merge($errors, updateConfig('AdminEmail', $param->user_email));
\r
958 array_merge($errors, updateConfig('SiteName', $param->blog_name));
\r
959 array_merge($errors, updateConfig('Locale', i18n::get_current_locale()));
\r
961 /* push super admin */
\r
962 $query = "UPDATE %s SET mname = %s, mrealname = %s, mpassword = %s, memail = %s, murl = %s, madmin = 1, mcanlogin = 1 WHERE mnumber = 1";
\r
963 $query = sprintf($query,
\r
964 tableName('nucleus_member'),
\r
965 DB::quoteValue($param->user_name),
\r
966 DB::quoteValue($param->user_realname),
\r
967 DB::quoteValue(md5($param->user_password)),
\r
968 DB::quoteValue($param->user_email),
\r
969 DB::quoteValue($param->IndexURL)
\r
971 if ( DB::execute($query) === FALSE )
\r
973 $errinfo = DB::getError();
\r
974 $errors[] = _INST_ERROR5 . ': ' . $errinfo[2];
\r
977 /* push new weblog */
\r
978 $query = "UPDATE %s SET bname = %s, bshortname = %s, burl = %s WHERE bnumber = 1";
\r
979 $query = sprintf($query,
\r
980 tableName('nucleus_blog'),
\r
981 DB::quoteValue($param->blog_name),
\r
982 DB::quoteValue($param->blog_shortname),
\r
983 DB::quoteValue($param->IndexURL)
\r
985 if ( DB::execute($query) === FALSE )
\r
987 $errinfo = DB::getError();
\r
988 $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];
\r
991 /* push default category */
\r
992 $query = "UPDATE %s SET cname = %s, cdesc = %s WHERE catid = 1";
\r
993 $query = sprintf($query,
\r
994 tableName('nucleus_category'),
\r
995 DB::quoteValue(_GENERALCAT_NAME),
\r
996 DB::quoteValue(_GENERALCAT_DESC)
\r
998 if ( DB::execute($query) === FALSE )
\r
1000 $errinfo = DB::getError();
\r
1001 $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];
\r
1005 * 7. install default plugins and skins
\r
1007 global $aConfPlugsToInstall, $aConfSkinsToImport;
\r
1008 $aSkinErrors = array();
\r
1009 $aPlugErrors = array();
\r
1011 if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) )
\r
1013 include_once($DIR_LIBS . 'globalfunctions.php');
\r
1015 if ( !isset($manager) )
\r
1017 $manager = new Manager();
\r
1020 include_once($DIR_LIBS . 'skinie.php');
\r
1022 $aSkinErrors = installCustomSkins();
\r
1023 if ( count($aSkinErrors) > 0 )
\r
1025 array_merge($errors, $aSkinErrors);
\r
1028 $query = "SELECT sdnumber FROM %s WHERE sdname='admin/default'";
\r
1029 $query = sprintf($query, tableName('nucleus_skin_desc'));
\r
1030 $res = intval(DB::getValue($query));
\r
1031 array_merge($errors, updateConfig('AdminSkin', $res));
\r
1033 $query = "SELECT sdnumber FROM %s WHERE sdname='admin/bookmarklet'";
\r
1034 $query = sprintf($query, tableName('nucleus_skin_desc'));
\r
1035 $res = intval(DB::getValue($query));
\r
1036 array_merge($errors, updateConfig('BookmarkletSkin', $res));
\r
1038 $query = "SELECT sdnumber FROM %s WHERE sdname='default'";
\r
1039 $query = sprintf($query, tableName('nucleus_skin_desc'));
\r
1040 $defSkinID = intval(DB::getValue($query));
\r
1042 $query = "UPDATE %s SET bdefskin=%d WHERE bnumber=1";
\r
1043 $query = sprintf($query, tableName('nucleus_blog'), $defSkinID);
\r
1044 DB::execute($query);
\r
1046 $query = "UPDATE %s SET value=%d WHERE name='BaseSkin'";
\r
1047 $query = sprintf($query, tableName('nucleus_config'), $defSkinID);
\r
1048 DB::execute($query);
\r
1050 $aPlugErrors = installCustomPlugs();
\r
1051 if ( count($aPlugErrors) > 0 )
\r
1053 array_merge($errors, $aPlugErrors);
\r
1058 * 8. Write config file ourselves (if possible)
\r
1060 $config_data = '<' . '?php' . "\n";
\r
1061 $config_data .= "// mySQL connection information\n";
\r
1062 $config_data .= "\$MYSQL_HOST = '" . $MYSQL_HOST . "';\n";
\r
1063 $config_data .= "\$MYSQL_USER = '" . $MYSQL_USER . "';\n";
\r
1064 $config_data .= "\$MYSQL_PASSWORD = '" . $MYSQL_PASSWORD . "';\n";
\r
1065 $config_data .= "\$MYSQL_DATABASE = '" . $MYSQL_DATABASE . "';\n";
\r
1066 $config_data .= "\$MYSQL_PREFIX = '" . $MYSQL_PREFIX . "';\n";
\r
1067 $config_data .= "// new in 3.50. first element is db handler, the second is the db driver used by the handler\n";
\r
1068 $config_data .= "// default is \$MYSQL_HANDLER = array('mysql','mysql');\n";
\r
1069 $config_data .= "//\$MYSQL_HANDLER = array('mysql','mysql');\n";
\r
1070 $config_data .= "//\$MYSQL_HANDLER = array('pdo','mysql');\n";
\r
1071 $config_data .= "\$MYSQL_HANDLER = array('" . $MYSQL_HANDLER[0] . "','" . $MYSQL_HANDLER[1] . "');\n";
\r
1072 $config_data .= "\n";
\r
1073 $config_data .= "// main nucleus directory\n";
\r
1074 $config_data .= "\$DIR_NUCLEUS = '" . $DIR_NUCLEUS . "';\n";
\r
1075 $config_data .= "\n";
\r
1076 $config_data .= "// path to media dir\n";
\r
1077 $config_data .= "\$DIR_MEDIA = '" . $DIR_MEDIA . "';\n";
\r
1078 $config_data .= "\n";
\r
1079 $config_data .= "// extra skin files for imported skins\n";
\r
1080 $config_data .= "\$DIR_SKINS = '" . $DIR_SKINS . "';\n";
\r
1081 $config_data .= "\n";
\r
1082 $config_data .= "// these dirs are normally sub dirs of the nucleus dir, but \n";
\r
1083 $config_data .= "// you can redefine them if you wish\n";
\r
1084 $config_data .= "\$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";
\r
1085 $config_data .= "\$DIR_LOCALES = \$DIR_NUCLEUS . 'locales/';\n";
\r
1086 $config_data .= "\$DIR_LIBS = \$DIR_NUCLEUS . 'libs/';\n";
\r
1087 $config_data .= "\n";
\r
1088 $config_data .= "// include libs\n";
\r
1089 $config_data .= "include(\$DIR_LIBS.'globalfunctions.php');\n";
\r
1090 $config_data .= "?" . ">";
\r
1093 if ( @!file_exists('../config.php') || is_writable('../config.php') )
\r
1095 if ( $fp = @fopen('../config.php', 'w') )
\r
1097 $result = @fwrite($fp, $config_data, i18n::strlen($config_data));
\r
1104 // try to change the read-only permission.
\r
1105 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
\r
1107 @chmod('../config.php', 0444);
\r
1112 $_SESSION['config_data'] = $config_data;
\r
1119 * Confirm that you can write to the configuration file
\r
1120 * @return string error message
\r
1122 function canConfigFileWritable()
\r
1124 if ( @file_exists('../config.php') && @!is_writable('../config.php') )
\r
1126 // try to change the read-write permission.
\r
1127 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
\r
1129 @chmod('../config.php', 0666);
\r
1132 if ( @!is_writable('../config.php') )
\r
1134 return _INST_ERROR8;
\r
1141 * To obtain the version of MySQL
\r
1144 function getMySqlVersion()
\r
1146 global $MYSQL_HANDLER, $minimum_mysql_version, $errors;
\r
1147 // Turn on output buffer
\r
1148 // Needed to repress the output of the sql function that are
\r
1149 // not part of php (in this case the @ operator doesn't work)
\r
1152 // note: this piece of code is taken from phpMyAdmin
\r
1153 $conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], 'localhost', '', '');
\r
1157 $row = DB::getAttribute(PDO::ATTR_SERVER_VERSION);
\r
1158 $match = preg_split('#\.#', $row);
\r
1162 $row = @DB::getRow('SHOW VARIABLES LIKE \'version\'');
\r
1166 $match = preg_split('#\.#', $row[1]);
\r
1170 $output = (function_exists('shell_exec')) ? @shell_exec('mysql -V') : '0.0.0';
\r
1171 preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
\r
1172 $match = preg_split('#\.#', $version[0]);
\r
1174 if ( $match[0] == '' )
\r
1176 $match = array('0', '0', '0');
\r
1181 @DB::disConnect();
\r
1183 //End and clean output buffer
\r
1186 return implode($match, '.');
\r
1190 * Add a table prefix if it is used
\r
1192 * @param string $input table name with prefix
\r
1195 function tableName($input)
\r
1197 global $MYSQL_PREFIX;
\r
1198 if ( $MYSQL_PREFIX )
\r
1200 return $MYSQL_PREFIX . $input;
\r
1209 * Install custom plugins
\r
1211 function installCustomPlugs()
\r
1213 global $aConfPlugsToInstall, $DIR_LIBS, $manager;
\r
1215 $aErrors = array();
\r
1216 if ( count($aConfPlugsToInstall) == 0 )
\r
1221 $query = sprintf('SELECT * FROM %s', tableName('nucleus_plugin'));
\r
1222 $res = DB::getResult($query);
\r
1223 $numCurrent = $res->rowCount();
\r
1225 foreach ( $aConfPlugsToInstall as $plugName )
\r
1227 $query = sprintf('INSERT INTO %s (porder, pfile) VALUES (%d, %s)',
\r
1228 tableName('nucleus_plugin'),
\r
1230 DB::quoteValue($plugName));
\r
1231 DB::execute($query);
\r
1233 $manager->clearCachedInfo('installedPlugins');
\r
1234 $plugin =& $manager->getPlugin($plugName);
\r
1235 $plugin->setID($numCurrent);
\r
1239 $query = sprintf('DELETE FROM %s WHERE pfile = %s',
\r
1240 tableName('nucleus_plugin'),
\r
1241 DB::quoteValue($plugName));
\r
1242 DB::execute($query);
\r
1244 array_push($aErrors, sprintf(_INST_ERROR9, $plugName));
\r
1247 $plugin->install();
\r
1250 $query = sprintf('DELETE FROM %s', tableName('nucleus_plugin_event'));
\r
1251 DB::execute($query);
\r
1252 $query = sprintf('SELECT pid, pfile FROM %s', tableName('nucleus_plugin'));
\r
1253 $res = DB::getResult($query);
\r
1255 foreach ( $res as $row )
\r
1257 $plug =& $manager->getPlugin($row['pfile']);
\r
1261 $eventList = $plug->getEventList();
\r
1262 foreach ( $eventList as $eventName )
\r
1264 $query = sprintf('INSERT INTO %s (pid, event) VALUES (%d, %s)',
\r
1265 tableName('nucleus_plugin_event'),
\r
1266 intval($row['pid']),
\r
1267 DB::quoteValue($eventName));
\r
1268 DB::execute($query);
\r
1276 * Install custom skins
\r
1277 * Prepares the installation of custom skins
\r
1279 function installCustomSkins()
\r
1281 global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS;
\r
1283 $aErrors = array();
\r
1284 if ( count($aConfSkinsToImport) == 0 )
\r
1289 $importer = new SkinImport();
\r
1291 foreach ( $aConfSkinsToImport as $skinName )
\r
1293 $importer->reset();
\r
1294 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';
\r
1296 if ( !@file_exists($skinFile) )
\r
1298 array_push($aErrors, sprintf(_INST_ERROR10, $skinFile));
\r
1302 $error = $importer->readFile($skinFile);
\r
1306 array_push($aErrors, sprintf(_INST_ERROR11, $skinName) . ' : ' . $error);
\r
1310 $error = $importer->writeToDatabase(1);
\r
1314 array_push($aErrors, sprintf(_INST_ERROR12, $skinName) . ' : ' . $error);
\r
1322 * Check if some important files of the Nucleus CMS installation are available
\r
1323 * Give an error if one or more files are not accessible
\r
1325 function do_check_files()
\r
1327 $missingfiles = array();
\r
1332 '../nucleus/index.php',
\r
1333 '../nucleus/media.php',
\r
1334 '../nucleus/libs/ACTION.php',
\r
1335 '../nucleus/libs/ACTIONLOG.php',
\r
1336 '../nucleus/libs/ACTIONS.php',
\r
1337 '../nucleus/libs/ADMIN.php',
\r
1338 '../nucleus/libs/BaseActions.php',
\r
1339 '../nucleus/libs/BLOG.php',
\r
1340 '../nucleus/libs/BODYACTIONS.php',
\r
1341 '../nucleus/libs/COMMENT.php',
\r
1342 '../nucleus/libs/COMMENTACTIONS.php',
\r
1343 '../nucleus/libs/COMMENTS.php',
\r
1344 '../nucleus/libs/ENTITY.php',
\r
1345 '../nucleus/libs/globalfunctions.php',
\r
1346 '../nucleus/libs/i18n.php',
\r
1347 '../nucleus/libs/ITEM.php',
\r
1348 '../nucleus/libs/ITEMACTIONS.php',
\r
1349 '../nucleus/libs/LINK.php',
\r
1350 '../nucleus/libs/MANAGER.php',
\r
1351 '../nucleus/libs/MEDIA.php',
\r
1352 '../nucleus/libs/MEMBER.php',
\r
1353 '../nucleus/libs/NOTIFICATION.php',
\r
1354 '../nucleus/libs/PARSER.php',
\r
1355 '../nucleus/libs/PLUGIN.php',
\r
1356 '../nucleus/libs/PLUGINADMIN.php',
\r
1357 '../nucleus/libs/SEARCH.php',
\r
1358 '../nucleus/libs/showlist.php',
\r
1359 '../nucleus/libs/SKIN.php',
\r
1360 '../nucleus/libs/TEMPLATE.php',
\r
1361 '../nucleus/libs/vars4.1.0.php',
\r
1362 '../nucleus/libs/xmlrpc.inc.php',
\r
1363 '../nucleus/libs/xmlrpcs.inc.php',
\r
1364 '../nucleus/libs/sql/DB.php',
\r
1365 '../nucleus/libs/sql/MYSQLPDO.php'
\r
1368 $count = count($files);
\r
1369 for ( $i = 0; $i < $count; $i++ )
\r
1371 if ( !is_readable($files[$i]) )
\r
1373 array_push($missingfiles, 'File <b>' . $files[$i] . '</b> is missing or not readable.<br />');
\r
1377 if ( count($missingfiles) > 0 )
\r
1379 exit(implode("\n", $missingfiles));
\r
1384 * Updates the configuration in the database
\r
1386 * @param string $name name of the config var
\r
1387 * @param string $value new value of the config var
\r
1390 function updateConfig($name, $value)
\r
1392 $errors = array();
\r
1394 $query = "UPDATE %s SET value = %s WHERE name = %s";
\r
1395 $query = sprintf($query, tableName('nucleus_config'), DB::quoteValue(trim($value)), DB::quoteValue($name));
\r
1397 if ( DB::execute($query) === FALSE )
\r
1399 $errinfo = DB::getError();
\r
1400 $errors[] = _INST_ERROR4 . ': ' . $errinfo[2];
\r
1405 class ParamManager
\r
1407 /* process parameter */
\r
1411 /* mysql connection parameters */
\r
1412 public $mysql_host;
\r
1413 public $mysql_user;
\r
1414 public $mysql_password;
\r
1415 public $mysql_database;
\r
1416 public $mysql_tablePrefix;
\r
1418 /* weblog configuration parameters */
\r
1419 public $blog_name;
\r
1420 public $blog_shortname;
\r
1422 /* member configuration parameters */
\r
1423 public $user_name;
\r
1424 public $user_realname;
\r
1425 public $user_password;
\r
1426 private $user_password2;
\r
1427 public $user_email;
\r
1429 /* URI parameters */
\r
1430 private $root_url;
\r
1435 public $PluginURL;
\r
1436 public $ActionURL;
\r
1438 /* path parameters */
\r
1439 private $root_path;
\r
1440 public $AdminPath;
\r
1441 public $MediaPath;
\r
1442 public $SkinsPath;
\r
1447 public function __construct()
\r
1452 public function init()
\r
1454 // set default values
\r
1455 $this->state = 'locale';
\r
1456 $this->install_mode = 'simple';
\r
1457 $this->locale = 'en_Latn_US';
\r
1458 $this->mysql_host = @ini_get('mysql.default_host');
\r
1459 $this->blog_name = 'My Nucleus CMS';
\r
1460 $this->blog_shortname = 'mynucleuscms';
\r
1463 $directory_separator = preg_quote(DIRECTORY_SEPARATOR, '|');
\r
1464 $this->root_path = implode('/', preg_split("|$directory_separator|", realpath(dirname(__FILE__) . '/..')));
\r
1465 if ( substr($this->root_path, -1, 1) !== '/' )
\r
1467 $this->root_path .= '/';
\r
1469 $base_path_pcre = preg_quote($this->root_path, '|');
\r
1471 /* current directry name */
\r
1472 $directory_name = preg_replace("#{$base_path_pcre}#", '', implode('/', preg_split("#{$directory_separator}#", realpath(dirname(__FILE__)))));
\r
1473 $directory_name_pcre = preg_quote($directory_name, '|');
\r
1476 $root_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
\r
1477 $this->root_url = preg_replace("|$directory_name_pcre(.*)$|", '', $root_url);
\r
1479 $this->AdminPath = $this->root_path . 'nucleus/';
\r
1480 $this->MediaPath = $this->root_path . 'media/';
\r
1481 $this->SkinsPath = $this->root_path . 'skins/';
\r
1483 $this->IndexURL = $this->root_url;
\r
1484 $this->AdminURL = $this->root_url . 'nucleus/';
\r
1485 $this->MediaURL = $this->root_url . 'media/';
\r
1486 $this->SkinsURL = $this->root_url . 'skins/';
\r
1487 $this->PluginURL = $this->root_url . 'nucleus/plugins/';
\r
1488 $this->ActionURL = $this->root_url . 'action.php';
\r
1491 private function read_parameter($parameter)
\r
1493 foreach ( $parameter as $element )
\r
1495 if ( array_key_exists($element, $_POST) )
\r
1497 $this->$element = $_POST[$element];
\r
1502 public function set_state($state)
\r
1504 $states = array('locale', 'mysql', 'weblog', 'detail', 'install');
\r
1505 if ( in_array($state, $states) )
\r
1507 $this->state = $state;
\r
1511 public function set_locale()
\r
1513 $this->read_parameter(array('locale'));
\r
1515 if ( !in_array($this->locale, i18n::get_available_locale_list()) )
\r
1517 $this->locale = 'en_Latn_US';
\r
1521 public function check_mysql_parameters()
\r
1523 global $MYSQL_HANDLER;
\r
1525 $parameters = array('mysql_host', 'mysql_user', 'mysql_password', 'mysql_database', 'mysql_tablePrefix');
\r
1526 $this->read_parameter($parameters);
\r
1528 $errors = array();
\r
1529 if ( $this->mysql_host == '' )
\r
1531 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD1);
\r
1534 if ( $this->mysql_user == '' )
\r
1536 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD2);
\r
1539 if ( $this->mysql_user != ''
\r
1540 && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_user) )
\r
1542 $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD2);
\r
1545 if ( $this->mysql_database == '' )
\r
1547 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD4);
\r
1550 if ( $this->mysql_database != ''
\r
1551 && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_database) )
\r
1553 $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD4);
\r
1556 if ( $this->mysql_tablePrefix != ''
\r
1557 && !preg_match('/^[a-z0-9_]+$/i', $this->mysql_tablePrefix) )
\r
1559 $errors[] = sprintf(_VALID_ERROR3, _DB_FIELD5);
\r
1562 if ( count($errors) == 0 )
\r
1564 $mysql_conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], $this->mysql_host, $this->mysql_user, $this->mysql_password);
\r
1565 if ( $mysql_conn == false )
\r
1567 $errors[] = _DBCONNECT_ERROR;
\r
1571 @DB::disConnect();
\r
1578 public function check_user_parameters()
\r
1580 $parameters = array('user_name', 'user_realname', 'user_password', 'user_password2', 'user_email');
\r
1581 $this->read_parameter($parameters);
\r
1583 $errors = array();
\r
1584 if ( $this->user_realname == '' )
\r
1586 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD1);
\r
1589 if ( $this->user_name == '' )
\r
1591 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD2);
\r
1593 elseif ( !preg_match("/^[a-z0-9]+([ a-z0-9]*[a-z0-9]+)?$/i", $this->user_name) )
\r
1595 $errors[] = _VALID_ERROR5;
\r
1598 if ( $this->user_password == '' || $this->user_password2 == '' )
\r
1600 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD3);
\r
1601 $this->user_password = '';
\r
1603 elseif ( $this->user_password != $this->user_password2 )
\r
1605 $errors[] = _VALID_ERROR6;
\r
1606 $this->user_password = '';
\r
1609 if ( !preg_match("/^[a-z0-9\._+\-]+@[a-z0-9\._\-]+\.[a-z]{2,6}$/i", $this->user_email) )
\r
1611 $errors[] = _VALID_ERROR7;
\r
1617 public function check_weblog_parameters()
\r
1619 $parameters = array('blog_name', 'blog_shortname');
\r
1620 $this->read_parameter($parameters);
\r
1622 $errors = array();
\r
1623 if ( $this->blog_name == '' )
\r
1625 $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD1);
\r
1628 if ( $this->blog_shortname == '' )
\r
1630 $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD2);
\r
1633 if ( !preg_match("/^[a-z0-9]+$/i", $this->blog_shortname) )
\r
1635 $errors[] = _VALID_ERROR4;
\r
1641 public function check_uri_parameters()
\r
1643 $parameters = array('IndexURL', 'AdminURL', 'MediaURL', 'SkinsURL', 'PluginURL', 'ActionURL');
\r
1644 $this->read_parameter($parameters);
\r
1646 $errors = array();
\r
1647 if ( substr($this->IndexURL, -1, 1) !== '/' )
\r
1649 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD1);
\r
1652 if ( substr($this->AdminURL, -1, 1) !== '/' )
\r
1654 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD2);
\r
1657 if ( substr($this->MediaURL, -1, 1) !== '/' )
\r
1659 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD4);
\r
1662 if ( substr($this->SkinsURL, -1, 1) !== '/' )
\r
1664 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD6);
\r
1667 if ( substr($this->PluginURL, -1, 1) !== '/' )
\r
1669 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD8);
\r
1672 if ( strrchr($this->ActionURL, '/') != '/action.php' )
\r
1674 $errors[] = sprintf(_VALID_ERROR9, _PATH_FIELD9);
\r
1680 public function check_path_parameters()
\r
1682 $parameters = array('AdminPath', 'MediaPath', 'SkinsPath');
\r
1683 $this->read_parameter($parameters);
\r
1685 $separators = array('/', DIRECTORY_SEPARATOR);
\r
1686 $errors = array();
\r
1687 if ( !in_array(substr($this->AdminPath, -1, 1), $separators) )
\r
1689 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD3);
\r
1691 elseif ( !file_exists($this->AdminPath) )
\r
1693 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD3);
\r
1696 if ( !in_array(substr($this->MediaPath, -1, 1), $separators) )
\r
1698 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD5);
\r
1700 elseif ( !file_exists($this->MediaPath) )
\r
1702 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD5);
\r
1705 if ( !in_array(substr($this->SkinsPath, -1, 1), $separators) )
\r
1707 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD7);
\r
1709 elseif ( !file_exists($this->SkinsPath) )
\r
1711 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD7);
\r
1718 * check all parameters
\r
1721 public function check_all_parameters()
\r
1723 $this->set_locale();
\r
1726 $isValid &= (count($this->check_mysql_parameters()) == 0);
\r
1727 $isValid &= (count($this->check_user_parameters()) == 0);
\r
1728 $isValid &= (count($this->check_weblog_parameters()) == 0);
\r
1729 $isValid &= (count($this->check_uri_parameters()) == 0);
\r
1730 $isValid &= (count($this->check_path_parameters()) == 0);
\r