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 $param->set_locale();
\r
97 // $param is saved to the session
\r
98 if ( isset($param) )
\r
100 $_SESSION['param_manager'] = $param;
\r
104 unset($_SESSION['param_manager']);
\r
111 function do_action()
\r
115 if ( array_key_exists('action', $_POST) )
\r
117 $isPostback = true;
\r
121 $isPostback = false;
\r
125 if ( array_key_exists('mode', $_REQUEST) )
\r
127 if ( $_REQUEST['mode'] == 'detail' )
\r
129 $param->set_state('detail');
\r
131 elseif ( $_REQUEST['mode'] == 'simple' )
\r
133 $param->set_state('mysql');
\r
137 // input parameter check
\r
140 switch ( $param->state )
\r
143 $param->set_state('mysql');
\r
144 $isPostback = false;
\r
147 if ( count($param->check_mysql_parameters()) == 0 )
\r
149 $param->set_state('weblog');
\r
150 $isPostback = false;
\r
154 if ( count($param->check_user_parameters()) == 0
\r
155 && count($param->check_weblog_parameters()) == 0 )
\r
157 $param->set_state('install');
\r
158 $isPostback = false;
\r
162 if ( $param->check_all_parameters() )
\r
164 $param->set_state('install');
\r
165 $isPostback = false;
\r
173 switch ( $param->state )
\r
176 show_select_locale_form();
\r
179 show_database_setting_form($isPostback);
\r
182 show_blog_setting_form($isPostback);
\r
185 show_detail_setting_form($isPostback);
\r
188 show_install_complete_form();
\r
195 * header tag of the installation screens
\r
197 function show_header()
\r
201 /* HTTP 1.1 application for no caching */
\r
202 header("Cache-Control: no-cache, must-revalidate");
\r
203 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
\r
204 header('Content-Type: text/html; charset=' . i18n::get_current_charset());
\r
206 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
\r
207 <html xmlns="http://www.w3.org/1999/xhtml">
\r
209 <title><?php echo _TITLE; ?></title>
\r
210 <link rel="stylesheet" type="text/css" href="./styles/inst.css" />
\r
211 <style type="text/css">
\r
213 <?php echo _BODYFONTSTYLE; ?>
\r
216 <script type="text/javascript">
\r
217 function SelectText( element ) {
\r
218 window.setTimeout( function() { element.select() }, 0 );
\r
220 var isSubmit = false;
\r
221 function OnceSubmit() {
\r
224 window.setTimeout( function() { isSubmit = false; }, 10000 );
\r
233 <div id="navigation">
\r
234 <h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>
\r
237 if ( in_array($param->state, array('mysql', 'weblog', 'install')) )
\r
239 echo '<li>', _STEP1, '</li><li';
\r
240 if ( $param->state == 'mysql' )
\r
242 echo ' class="gry"';
\r
244 echo '> > ', _STEP2, '</li><li';
\r
245 if ( in_array($param->state, array('mysql', 'weblog')) )
\r
247 echo ' class="gry"';
\r
249 echo '> > ', _STEP3, "</li>\n";
\r
251 if ( in_array($param->state, array('mysql', 'weblog', 'detail')) )
\r
253 echo '<li class="rightbox">';
\r
254 if ( in_array($param->state, array('mysql', 'weblog')) )
\r
256 echo '<a href="./?mode=detail">', _MODE2, '</a>';
\r
260 echo '<a href="./?mode=simple">', _MODE1, '</a>';
\r
272 * footer tag of the installation screens
\r
274 function show_footer()
\r
276 global $page_footer_copyright;
\r
279 <?php echo $page_footer_copyright; ?>
\r
287 * Display the form for language select
\r
289 function show_select_locale_form()
\r
294 <div id="container">
\r
295 <p style="font-size:152%;font-weight:bold;">
\r
296 <?php echo _LOCALE_HEADER; ?>
\r
298 <form method="post" action="./index.php">
\r
301 <select name="locale">
\r
303 $locales = i18n::get_available_locale_list();
\r
304 foreach ( $locales as $locale )
\r
306 if ( $param->locale != $locale )
\r
308 echo "<option value=\"{$locale}\">";
\r
312 echo "<option value=\"{$locale}\" selected=\"selected\">";
\r
315 $checkfile = "./locales/{$locale}." . i18n::get_current_charset() . '.php';
\r
316 if ( !file_exists($checkfile) )
\r
321 $label = '_LOCALE_' . strtoupper($locale);
\r
322 if ( !defined($label) )
\r
328 echo constant($label);
\r
330 echo "</option>\n";
\r
334 <p><?php echo _LOCALE_DESC1; ?></p>
\r
335 <p><?php echo _LOCALE_DESC2; ?></p>
\r
336 <p><?php echo _LOCALE_NEED_HELP;?></p>
\r
338 <button type="submit" name="action" value="locale" class="sbt_arw">START</button>
\r
347 * Display the form to set up a database
\r
348 * @param bool $isPostback
\r
350 function show_database_setting_form($isPostback)
\r
352 global $param, $minimum_mysql_version;
\r
354 $config_writable = canConfigFileWritable();
\r
355 $mysql_version = getMySqlVersion();
\r
357 <div id="container">
\r
360 echo _SIMPLE_NAVI1;
\r
361 if ( $config_writable != '' )
\r
363 echo '<span class="err">', $config_writable, '</span>';
\r
365 if ( $mysql_version == '0.0.0' )
\r
367 echo '<span class="err">', _DBVERSION_UNKOWN, '</span>';
\r
369 elseif ( version_compare($mysql_version, $minimum_mysql_version, '<') )
\r
371 echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';
\r
375 <form method="post" action="./index.php">
\r
377 <h2><?php echo _DB_HEADER; ?></h2>
\r
382 $errors = $param->check_mysql_parameters();
\r
383 if ( is_array($errors) )
\r
385 foreach ( $errors as $error )
\r
387 echo '<span class="err">', $error, "</span>\n";
\r
395 <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>
\r
396 <td><input type="text" name="mysql_host" value="<?php echo $param->mysql_host; ?>" /></td>
\r
399 <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>
\r
400 <td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>
\r
403 <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>
\r
404 <td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>
\r
407 <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>
\r
408 <td><input type="text" name="mysql_database" value="<?php echo $param->mysql_database; ?>" /></td>
\r
412 <button type="submit" name="mode" value="detail" class="sbt_sqr"><?php echo _MODE2; ?></button>
\r
413 <button type="submit" name="action" value="mysql" class="sbt_arw"><?php echo _NEXT; ?></button>
\r
416 <?php echo _DB_TEXT1; ?>
\r
425 * Displays a form to the blog settings
\r
426 * @param bool $isPostback
\r
428 function show_blog_setting_form($isPostback)
\r
432 <div id="container">
\r
434 <?php echo _SIMPLE_NAVI2; ?>
\r
436 <form method="post" action="./index.php">
\r
438 <h2><?php echo _BLOG_HEADER; ?></h2>
\r
443 $errors = $param->check_weblog_parameters();
\r
444 if ( is_array($errors) )
\r
446 foreach ( $errors as $error )
\r
448 echo '<span class="err">', $error, "</span>\n";
\r
456 <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>
\r
457 <td><input type="text" name="blog_name" value="<?php echo $param->blog_name; ?>" /></td>
\r
460 <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>
\r
461 <td><input type="text" name="blog_shortname" value="<?php echo $param->blog_shortname; ?>" /></td>
\r
467 <h2><?php echo _ADMIN_HEADER; ?></h2>
\r
472 $errors = $param->check_user_parameters();
\r
473 if ( is_array($errors) )
\r
475 foreach ( $errors as $error )
\r
477 echo '<span class="err">', $error, "</span>\n";
\r
485 <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>
\r
486 <td><input type="text" name="user_realname" value="<?php echo $param->user_realname; ?>" /></td>
\r
489 <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>
\r
490 <td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>
\r
493 <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>
\r
494 <td><input type="password" name="user_password" /></td>
\r
497 <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>
\r
498 <td><input type="password" name="user_password2" /></td>
\r
501 <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>
\r
502 <td><input type="text" name="user_email" value="<?php echo $param->user_email; ?>" /></td>
\r
506 <button type="submit" name="action" value="weblog" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>
\r
515 * Displays a form to the detail settings
\r
516 * @param bool $isPostback
\r
518 function show_detail_setting_form($isPostback)
\r
520 global $param, $minimum_mysql_version;
\r
522 $mysql_version = getMySqlVersion();
\r
524 <div id="container_detailed">
\r
526 <?php echo _DETAIL_NAVI1; ?>
\r
528 if ( $isPostback && !$param->check_all_parameters() )
\r
530 echo '<span class="err">', _VALID_ERROR, "</span>\n";
\r
535 <li>PHP: <?php echo phpversion(); ?></li>
\r
538 echo ($mysql_version == '0.0.0') ? _DBVERSION_UNKOWN : $mysql_version;
\r
539 if ( version_compare($mysql_version, $minimum_mysql_version, '<') )
\r
541 echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';
\r
545 <form method="post" action="">
\r
548 <h2><?php echo _DETAIL_HEADER1; ?></h2>
\r
553 $errors = $param->check_mysql_parameters();
\r
554 if ( is_array($errors) )
\r
556 foreach ( $errors as $error )
\r
558 echo '<span class="err">', $error, "</span>\n";
\r
566 <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>
\r
567 <td><input type="text" name="mysql_host" value="<?php echo $param->mysql_host; ?>" /></td>
\r
570 <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>
\r
571 <td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>
\r
574 <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>
\r
575 <td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>
\r
578 <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>
\r
579 <td><input type="text" name="mysql_database" value="<?php echo $param->mysql_database; ?>" /></td>
\r
582 <th><span class="nam"><?php echo _DB_FIELD5; ?></span><span class="sub"><?php echo _DB_FIELD5_DESC; ?></span></th>
\r
583 <td><input type="text" name="mysql_tablePrefix" value="<?php echo $param->mysql_tablePrefix; ?>" /></td>
\r
587 <h2><?php echo _DETAIL_HEADER2; ?></h2>
\r
592 $errors = $param->check_uri_parameters();
\r
593 if ( is_array($errors) )
\r
595 foreach ( $errors as $error )
\r
597 echo '<span class="err">', $error, "</span>\n";
\r
600 $errors = $param->check_path_parameters();
\r
601 if ( is_array($errors) )
\r
603 foreach ( $errors as $error )
\r
605 echo '<span class="err">', $error, "</span>\n";
\r
613 <th><span class="nam"><?php echo _PATH_FIELD1; ?></span></th>
\r
614 <td><input type="text" name="IndexURL" value="<?php echo $param->IndexURL; ?>" /></td>
\r
617 <th><span class="nam"><?php echo _PATH_FIELD2; ?></span></th>
\r
618 <td><input type="text" name="AdminURL" value="<?php echo $param->AdminURL; ?>" /></td>
\r
621 <th><span class="nam"><?php echo _PATH_FIELD3; ?></span></th>
\r
622 <td><input type="text" name="AdminPath" value="<?php echo $param->AdminPath; ?>" /></td>
\r
625 <th><span class="nam"><?php echo _PATH_FIELD4; ?></span></th>
\r
626 <td><input type="text" name="MediaURL" value="<?php echo $param->MediaURL; ?>" /></td>
\r
629 <th><span class="nam"><?php echo _PATH_FIELD5; ?></span></th>
\r
630 <td><input type="text" name="MediaPath" value="<?php echo $param->MediaPath; ?>" /></td>
\r
633 <th><span class="nam"><?php echo _PATH_FIELD6; ?></span></th>
\r
634 <td><input type="text" name="SkinsURL" value="<?php echo $param->SkinsURL; ?>" /></td>
\r
637 <th><span class="nam"><?php echo _PATH_FIELD7; ?></span></th>
\r
638 <td><input type="text" name="SkinsPath" value="<?php echo $param->SkinsPath; ?>" /></td>
\r
641 <th><span class="nam"><?php echo _PATH_FIELD8; ?></span></th>
\r
642 <td><input type="text" name="PluginURL" value="<?php echo $param->PluginURL; ?>" /></td>
\r
645 <th><span class="nam"><?php echo _PATH_FIELD9; ?></span></th>
\r
646 <td><input type="text" name="ActionURL" value="<?php echo $param->ActionURL; ?>" /></td>
\r
650 <?php echo _DETAIL_TEXT3; ?>
\r
653 <h2><?php echo _DETAIL_HEADER3; ?></h2>
\r
656 echo _DETAIL_TEXT4;
\r
659 $errors = $param->check_user_parameters();
\r
660 if ( is_array($errors) )
\r
662 foreach ( $errors as $error )
\r
664 echo '<span class="err">', $error, "</span>\n";
\r
672 <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>
\r
673 <td><input type="text" name="user_realname" value="<?php echo $param->user_realname; ?>" /></td>
\r
676 <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>
\r
677 <td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>
\r
680 <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>
\r
681 <td><input type="password" name="user_password" /></td>
\r
684 <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>
\r
685 <td><input type="password" name="user_password2" /></td>
\r
688 <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>
\r
689 <td><input type="text" name="user_email" value="<?php echo $param->user_email; ?>" /></td>
\r
693 <h2><?php echo _DETAIL_HEADER4; ?></h2>
\r
696 echo _DETAIL_TEXT5;
\r
699 $errors = $param->check_weblog_parameters();
\r
700 if ( is_array($errors) )
\r
702 foreach ( $errors as $error )
\r
704 echo '<span class="err">', $error, "</span>\n";
\r
712 <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>
\r
713 <td><input type="text" name="blog_name" value="<?php echo $param->blog_name; ?>" /></td>
\r
716 <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>
\r
717 <td><input type="text" name="blog_shortname" value="<?php echo $param->blog_shortname; ?>" /></td>
\r
722 <?php echo _DETAIL_TEXT6; ?>
\r
726 <button type="submit" name="action" value="detail" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>
\r
735 * Displays a screen to signal the completion of the installation
\r
737 function show_install_complete_form()
\r
739 global $MYSQL_HANDLER, $param;
\r
740 $errors = do_install();
\r
742 <div id="container">
\r
745 if ( is_array($errors) && count($errors) > 0 )
\r
748 foreach ( $errors as $error )
\r
750 echo '<span class="err">', $error, "</span>\n";
\r
756 if ( array_key_exists('config_data', $_SESSION) )
\r
758 echo '<span class="err">', _INST_TEXT4, '</span>';
\r
760 <textarea id="config_text" readonly="readonly" onfocus="SelectText(this);"><?php echo htmlentities($_SESSION['config_data'], null, i18n::get_current_charset()) ?></textarea>
\r
765 echo '<span class="err">', _INST_TEXT5, '</span>';
\r
769 <form method="post" action="./index.php">
\r
771 <h2><?php echo _INST_HEADER1; ?></h2>
\r
773 <?php echo sprintf(_INST_TEXT1, $param->blog_name); ?>
\r
776 <button type="button" name="toBlog" onclick="location.href='<?php echo $param->IndexURL; ?>';" class="sbt_arw"><?php echo _INST_BUTTON1; ?></button>
\r
781 <h2><?php echo _INST_HEADER2; ?></h2>
\r
783 <?php echo _INST_TEXT2; ?>
\r
786 <button type="button" name="toMng" onclick="location.href='<?php echo $param->AdminURL; ?>';" class="sbt_arw"><?php echo _INST_BUTTON2; ?></button>
\r
791 <h2><?php echo _INST_HEADER3; ?></h2>
\r
793 <?php echo _INST_TEXT3; ?>
\r
796 <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
809 * The installation process itself
\r
810 * @return array error messages
\r
812 function do_install()
\r
815 global $MYSQL_HANDLER, $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX, $MYSQL_CONN;
\r
816 global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;
\r
820 * 1. put all param-vars into vars
\r
822 $MYSQL_HOST = $param->mysql_host;
\r
823 $MYSQL_USER = $param->mysql_user;
\r
824 $MYSQL_PASSWORD = $param->mysql_password;
\r
825 $MYSQL_DATABASE = $param->mysql_database;
\r
826 $MYSQL_PREFIX = $param->mysql_tablePrefix;
\r
828 $DIR_NUCLEUS = $param->AdminPath;
\r
829 $DIR_MEDIA = $param->MediaPath;
\r
830 $DIR_SKINS = $param->SkinsPath;
\r
831 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
\r
832 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
\r
833 $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
\r
836 * 2.open mySQL connection
\r
838 $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
\r
839 if ( $MYSQL_CONN == FALSE )
\r
841 $errors[] = _DBCONNECT_ERROR;
\r
846 * 3. try to create database if needed
\r
848 if ( DB::execute("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") === FALSE )
\r
850 $errinfo = DB::getError();
\r
851 $errors[] = _INST_ERROR1 . ': ' . $errinfo[2];
\r
855 * 4. try to select database
\r
857 $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE);
\r
858 if ( !$MYSQL_CONN )
\r
860 $errors[] = _INST_ERROR2;
\r
863 if ( count($errors) > 0 )
\r
869 * 5. execute queries
\r
871 $table_names = array(
\r
872 'nucleus_actionlog',
\r
875 'nucleus_category',
\r
883 'nucleus_template',
\r
885 'nucleus_activation',
\r
889 $prefixed_table_names = array();
\r
890 foreach ( $table_names as $table_name )
\r
892 $prefixed_table_names[] = $MYSQL_PREFIX . $table_name;
\r
895 // table exists check
\r
896 $result = DB::getResult('SHOW TABLES');
\r
897 foreach ( $result as $row )
\r
899 if ( in_array($row[0], $prefixed_table_names) )
\r
901 $errors[] = _INST_ERROR3;
\r
905 if ( count($errors) > 0 )
\r
910 $filename = 'install.sql';
\r
911 $fd = fopen($filename, 'r');
\r
912 $queries = fread($fd, filesize($filename));
\r
915 $queries = preg_split('#(;\n|;\r)#', $queries);
\r
917 foreach ( $queries as $query )
\r
919 if ( preg_match('/\w+/', $query) )
\r
921 if ( $MYSQL_PREFIX )
\r
923 $query = str_replace($table_names, $prefixed_table_names, $query);
\r
926 if ( DB::execute($query) === FALSE )
\r
928 $errinfo = DB::getError();
\r
929 $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . $errinfo[2];
\r
935 * 6. put needed records
\r
937 /* push first post */
\r
938 $query = "INSERT INTO %s VALUES (1, %s, %s, %s, 1, 1, %s, 0, 0, 0, 1, 0, 1)";
\r
939 $query = sprintf($query,
\r
940 tableName('nucleus_item'),
\r
941 DB::quoteValue(_1ST_POST_TITLE),
\r
942 DB::quoteValue(_1ST_POST),
\r
943 DB::quoteValue(_1ST_POST2),
\r
944 DB::formatDateTime()
\r
946 if ( DB::execute($query) === FALSE )
\r
948 $errinfo = DB::getError();
\r
949 $errors[] = _INST_ERROR4 . ' (<small>' . $newpost . '</small>): ' . $errinfo[2];
\r
952 /* push configurations */
\r
953 array_merge($errors, updateConfig('IndexURL', $param->IndexURL));
\r
954 array_merge($errors, updateConfig('AdminURL', $param->AdminURL));
\r
955 array_merge($errors, updateConfig('MediaURL', $param->MediaURL));
\r
956 array_merge($errors, updateConfig('SkinsURL', $param->SkinsURL));
\r
957 array_merge($errors, updateConfig('PluginURL', $param->PluginURL));
\r
958 array_merge($errors, updateConfig('ActionURL', $param->ActionURL));
\r
959 array_merge($errors, updateConfig('AdminEmail', $param->user_email));
\r
960 array_merge($errors, updateConfig('SiteName', $param->blog_name));
\r
961 array_merge($errors, updateConfig('Locale', i18n::get_current_locale()));
\r
963 /* push super admin */
\r
964 $query = "UPDATE %s SET mname = %s, mrealname = %s, mpassword = %s, memail = %s, murl = %s, madmin = 1, mcanlogin = 1 WHERE mnumber = 1";
\r
965 $query = sprintf($query,
\r
966 tableName('nucleus_member'),
\r
967 DB::quoteValue($param->user_name),
\r
968 DB::quoteValue($param->user_realname),
\r
969 DB::quoteValue(md5($param->user_password)),
\r
970 DB::quoteValue($param->user_email),
\r
971 DB::quoteValue($param->IndexURL)
\r
973 if ( DB::execute($query) === FALSE )
\r
975 $errinfo = DB::getError();
\r
976 $errors[] = _INST_ERROR5 . ': ' . $errinfo[2];
\r
979 /* push new weblog */
\r
980 $query = "UPDATE %s SET bname = %s, bshortname = %s, burl = %s WHERE bnumber = 1";
\r
981 $query = sprintf($query,
\r
982 tableName('nucleus_blog'),
\r
983 DB::quoteValue($param->blog_name),
\r
984 DB::quoteValue($param->blog_shortname),
\r
985 DB::quoteValue($param->IndexURL)
\r
987 if ( DB::execute($query) === FALSE )
\r
989 $errinfo = DB::getError();
\r
990 $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];
\r
993 /* push default category */
\r
994 $query = "UPDATE %s SET cname = %s, cdesc = %s WHERE catid = 1";
\r
995 $query = sprintf($query,
\r
996 tableName('nucleus_category'),
\r
997 DB::quoteValue(_GENERALCAT_NAME),
\r
998 DB::quoteValue(_GENERALCAT_DESC)
\r
1000 if ( DB::execute($query) === FALSE )
\r
1002 $errinfo = DB::getError();
\r
1003 $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];
\r
1007 * 7. install default plugins and skins
\r
1009 global $aConfPlugsToInstall, $aConfSkinsToImport;
\r
1010 $aSkinErrors = array();
\r
1011 $aPlugErrors = array();
\r
1013 if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) )
\r
1015 include_once($DIR_LIBS . 'globalfunctions.php');
\r
1017 if ( !isset($manager) )
\r
1019 $manager = new Manager();
\r
1022 include_once($DIR_LIBS . 'skinie.php');
\r
1024 $aSkinErrors = installCustomSkins();
\r
1025 if ( count($aSkinErrors) > 0 )
\r
1027 array_merge($errors, $aSkinErrors);
\r
1030 $query = "SELECT sdnumber FROM %s WHERE sdname='admin/default'";
\r
1031 $query = sprintf($query, tableName('nucleus_skin_desc'));
\r
1032 $res = intval(DB::getValue($query));
\r
1033 array_merge($errors, updateConfig('AdminSkin', $res));
\r
1035 $query = "SELECT sdnumber FROM %s WHERE sdname='admin/bookmarklet'";
\r
1036 $query = sprintf($query, tableName('nucleus_skin_desc'));
\r
1037 $res = intval(DB::getValue($query));
\r
1038 array_merge($errors, updateConfig('BookmarkletSkin', $res));
\r
1040 $query = "SELECT sdnumber FROM %s WHERE sdname='default'";
\r
1041 $query = sprintf($query, tableName('nucleus_skin_desc'));
\r
1042 $defSkinID = intval(DB::getValue($query));
\r
1044 $query = "UPDATE %s SET bdefskin=%d WHERE bnumber=1";
\r
1045 $query = sprintf($query, tableName('nucleus_blog'), $defSkinID);
\r
1046 DB::execute($query);
\r
1048 $query = "UPDATE %s SET value=%d WHERE name='BaseSkin'";
\r
1049 $query = sprintf($query, tableName('nucleus_config'), $defSkinID);
\r
1050 DB::execute($query);
\r
1052 $aPlugErrors = installCustomPlugs();
\r
1053 if ( count($aPlugErrors) > 0 )
\r
1055 array_merge($errors, $aPlugErrors);
\r
1060 * 8. Write config file ourselves (if possible)
\r
1062 $config_data = '<' . '?php' . "\n";
\r
1063 $config_data .= "// mySQL connection information\n";
\r
1064 $config_data .= "\$MYSQL_HOST = '" . $MYSQL_HOST . "';\n";
\r
1065 $config_data .= "\$MYSQL_USER = '" . $MYSQL_USER . "';\n";
\r
1066 $config_data .= "\$MYSQL_PASSWORD = '" . $MYSQL_PASSWORD . "';\n";
\r
1067 $config_data .= "\$MYSQL_DATABASE = '" . $MYSQL_DATABASE . "';\n";
\r
1068 $config_data .= "\$MYSQL_PREFIX = '" . $MYSQL_PREFIX . "';\n";
\r
1069 $config_data .= "// new in 3.50. first element is db handler, the second is the db driver used by the handler\n";
\r
1070 $config_data .= "// default is \$MYSQL_HANDLER = array('mysql','mysql');\n";
\r
1071 $config_data .= "//\$MYSQL_HANDLER = array('mysql','mysql');\n";
\r
1072 $config_data .= "//\$MYSQL_HANDLER = array('pdo','mysql');\n";
\r
1073 $config_data .= "\$MYSQL_HANDLER = array('" . $MYSQL_HANDLER[0] . "','" . $MYSQL_HANDLER[1] . "');\n";
\r
1074 $config_data .= "\n";
\r
1075 $config_data .= "// main nucleus directory\n";
\r
1076 $config_data .= "\$DIR_NUCLEUS = '" . $DIR_NUCLEUS . "';\n";
\r
1077 $config_data .= "\n";
\r
1078 $config_data .= "// path to media dir\n";
\r
1079 $config_data .= "\$DIR_MEDIA = '" . $DIR_MEDIA . "';\n";
\r
1080 $config_data .= "\n";
\r
1081 $config_data .= "// extra skin files for imported skins\n";
\r
1082 $config_data .= "\$DIR_SKINS = '" . $DIR_SKINS . "';\n";
\r
1083 $config_data .= "\n";
\r
1084 $config_data .= "// these dirs are normally sub dirs of the nucleus dir, but \n";
\r
1085 $config_data .= "// you can redefine them if you wish\n";
\r
1086 $config_data .= "\$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";
\r
1087 $config_data .= "\$DIR_LOCALES = \$DIR_NUCLEUS . 'locales/';\n";
\r
1088 $config_data .= "\$DIR_LIBS = \$DIR_NUCLEUS . 'libs/';\n";
\r
1089 $config_data .= "\n";
\r
1090 $config_data .= "// include libs\n";
\r
1091 $config_data .= "include(\$DIR_LIBS.'globalfunctions.php');\n";
\r
1092 $config_data .= "?" . ">";
\r
1095 if ( @!file_exists('../config.php') || is_writable('../config.php') )
\r
1097 if ( $fp = @fopen('../config.php', 'w') )
\r
1099 $result = @fwrite($fp, $config_data, i18n::strlen($config_data));
\r
1106 // try to change the read-only permission.
\r
1107 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
\r
1109 @chmod('../config.php', 0444);
\r
1114 $_SESSION['config_data'] = $config_data;
\r
1121 * Confirm that you can write to the configuration file
\r
1122 * @return string error message
\r
1124 function canConfigFileWritable()
\r
1126 if ( @file_exists('../config.php') && @!is_writable('../config.php') )
\r
1128 // try to change the read-write permission.
\r
1129 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
\r
1131 @chmod('../config.php', 0666);
\r
1134 if ( @!is_writable('../config.php') )
\r
1136 return _INST_ERROR8;
\r
1143 * To obtain the version of MySQL
\r
1146 function getMySqlVersion()
\r
1148 global $MYSQL_HANDLER, $minimum_mysql_version, $errors;
\r
1149 // Turn on output buffer
\r
1150 // Needed to repress the output of the sql function that are
\r
1151 // not part of php (in this case the @ operator doesn't work)
\r
1154 // note: this piece of code is taken from phpMyAdmin
\r
1155 $conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], 'localhost', '', '');
\r
1159 $row = DB::getAttribute(PDO::ATTR_SERVER_VERSION);
\r
1160 $match = preg_split('#\.#', $row);
\r
1164 $row = @DB::getRow('SHOW VARIABLES LIKE \'version\'');
\r
1168 $match = preg_split('#\.#', $row[1]);
\r
1172 $output = (function_exists('shell_exec')) ? @shell_exec('mysql -V') : '0.0.0';
\r
1173 preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
\r
1174 $match = preg_split('#\.#', $version[0]);
\r
1176 if ( $match[0] == '' )
\r
1178 $match = array('0', '0', '0');
\r
1183 @DB::disConnect();
\r
1185 //End and clean output buffer
\r
1188 return implode($match, '.');
\r
1192 * Add a table prefix if it is used
\r
1194 * @param string $input table name with prefix
\r
1197 function tableName($input)
\r
1199 global $MYSQL_PREFIX;
\r
1200 if ( $MYSQL_PREFIX )
\r
1202 return $MYSQL_PREFIX . $input;
\r
1211 * Install custom plugins
\r
1213 function installCustomPlugs()
\r
1215 global $aConfPlugsToInstall, $DIR_LIBS, $manager;
\r
1217 $aErrors = array();
\r
1218 if ( count($aConfPlugsToInstall) == 0 )
\r
1223 $query = sprintf('SELECT * FROM %s', tableName('nucleus_plugin'));
\r
1224 $res = DB::getResult($query);
\r
1225 $numCurrent = $res->rowCount();
\r
1227 foreach ( $aConfPlugsToInstall as $plugName )
\r
1229 $query = sprintf('INSERT INTO %s (porder, pfile) VALUES (%d, %s)',
\r
1230 tableName('nucleus_plugin'),
\r
1232 DB::quoteValue($plugName));
\r
1233 DB::execute($query);
\r
1235 $manager->clearCachedInfo('installedPlugins');
\r
1236 $plugin =& $manager->getPlugin($plugName);
\r
1237 $plugin->setID($numCurrent);
\r
1241 $query = sprintf('DELETE FROM %s WHERE pfile = %s',
\r
1242 tableName('nucleus_plugin'),
\r
1243 DB::quoteValue($plugName));
\r
1244 DB::execute($query);
\r
1246 array_push($aErrors, sprintf(_INST_ERROR9, $plugName));
\r
1249 $plugin->install();
\r
1252 $query = sprintf('DELETE FROM %s', tableName('nucleus_plugin_event'));
\r
1253 DB::execute($query);
\r
1254 $query = sprintf('SELECT pid, pfile FROM %s', tableName('nucleus_plugin'));
\r
1255 $res = DB::getResult($query);
\r
1257 foreach ( $res as $row )
\r
1259 $plug =& $manager->getPlugin($row['pfile']);
\r
1263 $eventList = $plug->getEventList();
\r
1264 foreach ( $eventList as $eventName )
\r
1266 $query = sprintf('INSERT INTO %s (pid, event) VALUES (%d, %s)',
\r
1267 tableName('nucleus_plugin_event'),
\r
1268 intval($row['pid']),
\r
1269 DB::quoteValue($eventName));
\r
1270 DB::execute($query);
\r
1278 * Install custom skins
\r
1279 * Prepares the installation of custom skins
\r
1281 function installCustomSkins()
\r
1283 global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS;
\r
1285 $aErrors = array();
\r
1286 if ( count($aConfSkinsToImport) == 0 )
\r
1291 $importer = new SkinImport();
\r
1293 foreach ( $aConfSkinsToImport as $skinName )
\r
1295 $importer->reset();
\r
1296 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';
\r
1298 if ( !@file_exists($skinFile) )
\r
1300 array_push($aErrors, sprintf(_INST_ERROR10, $skinFile));
\r
1304 $error = $importer->readFile($skinFile);
\r
1308 array_push($aErrors, sprintf(_INST_ERROR11, $skinName) . ' : ' . $error);
\r
1312 $error = $importer->writeToDatabase(1);
\r
1316 array_push($aErrors, sprintf(_INST_ERROR12, $skinName) . ' : ' . $error);
\r
1324 * Check if some important files of the Nucleus CMS installation are available
\r
1325 * Give an error if one or more files are not accessible
\r
1327 function do_check_files()
\r
1329 $missingfiles = array();
\r
1334 '../nucleus/index.php',
\r
1335 '../nucleus/libs/ACTION.php',
\r
1336 '../nucleus/libs/ACTIONLOG.php',
\r
1337 '../nucleus/libs/ACTIONS.php',
\r
1338 '../nucleus/libs/ADMIN.php',
\r
1339 '../nucleus/libs/BaseActions.php',
\r
1340 '../nucleus/libs/BLOG.php',
\r
1341 '../nucleus/libs/BODYACTIONS.php',
\r
1342 '../nucleus/libs/COMMENT.php',
\r
1343 '../nucleus/libs/COMMENTACTIONS.php',
\r
1344 '../nucleus/libs/COMMENTS.php',
\r
1345 '../nucleus/libs/ENTITY.php',
\r
1346 '../nucleus/libs/globalfunctions.php',
\r
1347 '../nucleus/libs/i18n.php',
\r
1348 '../nucleus/libs/ITEM.php',
\r
1349 '../nucleus/libs/ITEMACTIONS.php',
\r
1350 '../nucleus/libs/LINK.php',
\r
1351 '../nucleus/libs/MANAGER.php',
\r
1352 '../nucleus/libs/MEDIA.php',
\r
1353 '../nucleus/libs/MEMBER.php',
\r
1354 '../nucleus/libs/NOTIFICATION.php',
\r
1355 '../nucleus/libs/PARSER.php',
\r
1356 '../nucleus/libs/PLUGIN.php',
\r
1357 '../nucleus/libs/PLUGINADMIN.php',
\r
1358 '../nucleus/libs/SEARCH.php',
\r
1359 '../nucleus/libs/showlist.php',
\r
1360 '../nucleus/libs/SKIN.php',
\r
1361 '../nucleus/libs/TEMPLATE.php',
\r
1362 '../nucleus/libs/vars4.1.0.php',
\r
1363 '../nucleus/libs/xmlrpc.inc.php',
\r
1364 '../nucleus/libs/xmlrpcs.inc.php',
\r
1365 '../nucleus/libs/sql/DB.php',
\r
1366 '../nucleus/libs/sql/MYSQLPDO.php'
\r
1369 $count = count($files);
\r
1370 for ( $i = 0; $i < $count; $i++ )
\r
1372 if ( !is_readable($files[$i]) )
\r
1374 array_push($missingfiles, 'File <b>' . $files[$i] . '</b> is missing or not readable.<br />');
\r
1378 if ( count($missingfiles) > 0 )
\r
1380 exit(implode("\n", $missingfiles));
\r
1385 * Updates the configuration in the database
\r
1387 * @param string $name name of the config var
\r
1388 * @param string $value new value of the config var
\r
1391 function updateConfig($name, $value)
\r
1393 $errors = array();
\r
1395 $query = "UPDATE %s SET value = %s WHERE name = %s";
\r
1396 $query = sprintf($query, tableName('nucleus_config'), DB::quoteValue(trim($value)), DB::quoteValue($name));
\r
1398 if ( DB::execute($query) === FALSE )
\r
1400 $errinfo = DB::getError();
\r
1401 $errors[] = _INST_ERROR4 . ': ' . $errinfo[2];
\r
1406 class ParamManager
\r
1408 /* process parameter */
\r
1412 /* mysql connection parameters */
\r
1413 public $mysql_host;
\r
1414 public $mysql_user;
\r
1415 public $mysql_password;
\r
1416 public $mysql_database;
\r
1417 public $mysql_tablePrefix;
\r
1419 /* weblog configuration parameters */
\r
1420 public $blog_name;
\r
1421 public $blog_shortname;
\r
1423 /* member configuration parameters */
\r
1424 public $user_name;
\r
1425 public $user_realname;
\r
1426 public $user_password;
\r
1427 private $user_password2;
\r
1428 public $user_email;
\r
1430 /* URI parameters */
\r
1431 private $root_url;
\r
1436 public $PluginURL;
\r
1437 public $ActionURL;
\r
1439 /* path parameters */
\r
1440 private $root_path;
\r
1441 public $AdminPath;
\r
1442 public $MediaPath;
\r
1443 public $SkinsPath;
\r
1448 public function __construct()
\r
1453 public function init()
\r
1455 // set default values
\r
1456 $this->state = 'locale';
\r
1457 $this->install_mode = 'simple';
\r
1458 $this->locale = '';
\r
1459 $this->mysql_host = @ini_get('mysql.default_host');
\r
1460 $this->blog_name = 'My Nucleus CMS';
\r
1461 $this->blog_shortname = 'mynucleuscms';
\r
1464 $directory_separator = preg_quote(DIRECTORY_SEPARATOR, '|');
\r
1465 $this->root_path = implode('/', preg_split("|$directory_separator|", realpath(dirname(__FILE__) . '/..')));
\r
1466 if ( substr($this->root_path, -1, 1) !== '/' )
\r
1468 $this->root_path .= '/';
\r
1470 $base_path_pcre = preg_quote($this->root_path, '|');
\r
1472 /* current directry name */
\r
1473 $directory_name = preg_replace("#{$base_path_pcre}#", '', implode('/', preg_split("#{$directory_separator}#", realpath(dirname(__FILE__)))));
\r
1474 $directory_name_pcre = preg_quote($directory_name, '|');
\r
1477 $root_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
\r
1478 $this->root_url = preg_replace("|$directory_name_pcre(.*)$|", '', $root_url);
\r
1480 $this->AdminPath = $this->root_path . 'nucleus/';
\r
1481 $this->MediaPath = $this->root_path . 'media/';
\r
1482 $this->SkinsPath = $this->root_path . 'skins/';
\r
1484 $this->IndexURL = $this->root_url;
\r
1485 $this->AdminURL = $this->root_url . 'nucleus/';
\r
1486 $this->MediaURL = $this->root_url . 'media/';
\r
1487 $this->SkinsURL = $this->root_url . 'skins/';
\r
1488 $this->PluginURL = $this->root_url . 'nucleus/plugins/';
\r
1489 $this->ActionURL = $this->root_url . 'action.php';
\r
1492 private function read_parameter($parameter)
\r
1494 foreach ( $parameter as $element )
\r
1496 if ( array_key_exists($element, $_POST) )
\r
1498 $this->$element = $_POST[$element];
\r
1503 public function set_state($state)
\r
1505 $states = array('locale', 'mysql', 'weblog', 'detail', 'install');
\r
1506 if ( in_array($state, $states) )
\r
1508 $this->state = $state;
\r
1512 public function set_locale()
\r
1514 $this->read_parameter(array('locale'));
\r
1516 if ( !$this->locale )
\r
1519 * default locale select simple implementation
\r
1522 * RFC2616: Hypertext Transfer Protocol -- HTTP/1.1
\r
1523 * http://www.ietf.org/rfc/rfc2616.txt
\r
1525 * 14.4 Accept-Language
\r
1527 * The Accept-Language request-header field is similar to Accept, but
\r
1528 * restricts the set of natural languages that are preferred as a
\r
1529 * response to the request. Language tags are defined in section 3.10.
\r
1531 * Accept-Language = "Accept-Language" ":"
\r
1532 * 1#( language-range [ ";" "q" "=" qvalue ] )
\r
1533 * language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
\r
1535 * Each language-range MAY be given an associated quality value which
\r
1536 * represents an estimate of the user's preference for the languages
\r
1537 * specified by that range. The quality value defaults to "q=1". For
\r
1540 * Accept-Language: da, en-gb;q=0.8, en;q=0.7
\r
1542 * would mean: "I prefer Danish, but will accept British English and
\r
1543 * other types of English." A language-range matches a language-tag if
\r
1544 * it exactly equals the tag, or if it exactly equals a prefix of the
\r
1545 * tag such that the first tag character following the prefix is "-".
\r
1546 * The special range "*", if present in the Accept-Language field,
\r
1547 * matches every tag not matched by any other range present in the
\r
1548 * Accept-Language field.
\r
1550 * TODO: this is appropriate implement or not
\r
1552 $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
\r
1554 /* retrieve language token of language tag from first token */
\r
1556 if ( is_array($languages) && count($languages) > 0 )
\r
1558 $language = preg_replace('#^([\w]+).*$#', '$1', $languages[0]);
\r
1561 $locales = i18n::get_available_locale_list();
\r
1562 foreach ( $locales as $locale )
\r
1564 if ( i18n::strpos($locale, $language) === 0 )
\r
1566 $this->locale = $locale;
\r
1572 /* include installer translation messages */
\r
1573 $translation_file = "./locales/{$this->locale}." . i18n::get_current_charset() . '.php';
\r
1574 if ( !file_exists($translation_file) )
\r
1576 $translation_file = './locales/en_Latn_US.UTF-8.php';
\r
1578 include($translation_file);
\r
1580 /* include global translation messages */
\r
1581 $translation_file = "../nucleus/locales/{$this->locale}." . i18n::get_current_charset() . '.php';
\r
1582 if ( !file_exists($translation_file) )
\r
1584 $translation_file = './locales/en_Latn_US.UTF-8.php';
\r
1586 include($translation_file);
\r
1588 i18n::set_current_locale($this->locale);
\r
1593 public function check_mysql_parameters()
\r
1595 global $MYSQL_HANDLER;
\r
1597 $parameters = array('mysql_host', 'mysql_user', 'mysql_password', 'mysql_database', 'mysql_tablePrefix');
\r
1598 $this->read_parameter($parameters);
\r
1600 $errors = array();
\r
1601 if ( $this->mysql_host == '' )
\r
1603 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD1);
\r
1606 if ( $this->mysql_user == '' )
\r
1608 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD2);
\r
1611 if ( $this->mysql_user != ''
\r
1612 && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_user) )
\r
1614 $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD2);
\r
1617 if ( $this->mysql_database == '' )
\r
1619 $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD4);
\r
1622 if ( $this->mysql_database != ''
\r
1623 && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_database) )
\r
1625 $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD4);
\r
1628 if ( $this->mysql_tablePrefix != ''
\r
1629 && !preg_match('/^[a-z0-9_]+$/i', $this->mysql_tablePrefix) )
\r
1631 $errors[] = sprintf(_VALID_ERROR3, _DB_FIELD5);
\r
1634 if ( count($errors) == 0 )
\r
1636 $mysql_conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], $this->mysql_host, $this->mysql_user, $this->mysql_password);
\r
1637 if ( $mysql_conn == false )
\r
1639 $errors[] = _DBCONNECT_ERROR;
\r
1643 @DB::disConnect();
\r
1650 public function check_user_parameters()
\r
1652 $parameters = array('user_name', 'user_realname', 'user_password', 'user_password2', 'user_email');
\r
1653 $this->read_parameter($parameters);
\r
1655 $errors = array();
\r
1656 if ( $this->user_realname == '' )
\r
1658 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD1);
\r
1661 if ( $this->user_name == '' )
\r
1663 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD2);
\r
1665 elseif ( !preg_match("/^[a-z0-9]+([ a-z0-9]*[a-z0-9]+)?$/i", $this->user_name) )
\r
1667 $errors[] = _VALID_ERROR5;
\r
1670 if ( $this->user_password == '' || $this->user_password2 == '' )
\r
1672 $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD3);
\r
1673 $this->user_password = '';
\r
1675 elseif ( $this->user_password != $this->user_password2 )
\r
1677 $errors[] = _VALID_ERROR6;
\r
1678 $this->user_password = '';
\r
1681 if ( !preg_match("/^[a-z0-9\._+\-]+@[a-z0-9\._\-]+\.[a-z]{2,6}$/i", $this->user_email) )
\r
1683 $errors[] = _VALID_ERROR7;
\r
1689 public function check_weblog_parameters()
\r
1691 $parameters = array('blog_name', 'blog_shortname');
\r
1692 $this->read_parameter($parameters);
\r
1694 $errors = array();
\r
1695 if ( $this->blog_name == '' )
\r
1697 $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD1);
\r
1700 if ( $this->blog_shortname == '' )
\r
1702 $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD2);
\r
1705 if ( !preg_match("/^[a-z0-9]+$/i", $this->blog_shortname) )
\r
1707 $errors[] = _VALID_ERROR4;
\r
1713 public function check_uri_parameters()
\r
1715 $parameters = array('IndexURL', 'AdminURL', 'MediaURL', 'SkinsURL', 'PluginURL', 'ActionURL');
\r
1716 $this->read_parameter($parameters);
\r
1718 $errors = array();
\r
1719 if ( substr($this->IndexURL, -1, 1) !== '/' )
\r
1721 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD1);
\r
1724 if ( substr($this->AdminURL, -1, 1) !== '/' )
\r
1726 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD2);
\r
1729 if ( substr($this->MediaURL, -1, 1) !== '/' )
\r
1731 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD4);
\r
1734 if ( substr($this->SkinsURL, -1, 1) !== '/' )
\r
1736 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD6);
\r
1739 if ( substr($this->PluginURL, -1, 1) !== '/' )
\r
1741 $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD8);
\r
1744 if ( strrchr($this->ActionURL, '/') != '/action.php' )
\r
1746 $errors[] = sprintf(_VALID_ERROR9, _PATH_FIELD9);
\r
1752 public function check_path_parameters()
\r
1754 $parameters = array('AdminPath', 'MediaPath', 'SkinsPath');
\r
1755 $this->read_parameter($parameters);
\r
1757 $separators = array('/', DIRECTORY_SEPARATOR);
\r
1758 $errors = array();
\r
1759 if ( !in_array(substr($this->AdminPath, -1, 1), $separators) )
\r
1761 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD3);
\r
1763 elseif ( !file_exists($this->AdminPath) )
\r
1765 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD3);
\r
1768 if ( !in_array(substr($this->MediaPath, -1, 1), $separators) )
\r
1770 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD5);
\r
1772 elseif ( !file_exists($this->MediaPath) )
\r
1774 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD5);
\r
1777 if ( !in_array(substr($this->SkinsPath, -1, 1), $separators) )
\r
1779 $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD7);
\r
1781 elseif ( !file_exists($this->SkinsPath) )
\r
1783 $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD7);
\r
1790 * check all parameters
\r
1793 public function check_all_parameters()
\r
1795 $this->set_locale();
\r
1798 $isValid &= (count($this->check_mysql_parameters()) == 0);
\r
1799 $isValid &= (count($this->check_user_parameters()) == 0);
\r
1800 $isValid &= (count($this->check_weblog_parameters()) == 0);
\r
1801 $isValid &= (count($this->check_uri_parameters()) == 0);
\r
1802 $isValid &= (count($this->check_path_parameters()) == 0);
\r