3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2007 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
12 * This script will install the Nucleus tables in your SQL-database,
13 * and initialize the data in those tables.
15 * Below is a friendly way of letting users on non-php systems know that Nucleus won't run there.
16 * ?><div style="font-size: xx-large;"> Your web server is not properly configured to run PHP scripts and will not be able to install Nucleus. </div> <div style="display: none;"><?php
20 * @license http://nucleuscms.org/license.txt GNU General Public License
21 * @copyright Copyright (C) 2002-2007 The Nucleus Group
22 * @version $Id: index.php 1651 2012-02-03 14:57:11Z sakamocchi $
25 $minimum_php_version = '5.0.6';
26 $minimum_mysql_version = '3.23';
28 // begin if: server's PHP version is below the minimum; halt installation
29 if ( phpversion() < $minimum_php_version )
35 * This part of the ./install/index.php code allows for customization of the install process.
36 * When distributing plugins or skins together with a Nucleus installation, the
37 * configuration below will instruct to install them
39 * -- Start Of Configurable Part --
43 * array with names of plugins to install. Plugin files must be present in the nucleus/plugin/ directory
46 * array('NP_TrackBack', 'NP_MemberGoodies')
48 $aConfPlugsToInstall = array('NP_SkinFiles', 'NP_SecurityEnforcer', 'NP_Text');
51 * array with skins to install. skins must be present under the skins/ directory with
52 * a subdirectory having the same name that contains a skinbackup.xml file
55 * array('base', 'rsd')
57 $aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default');
60 * -- End Of Configurable Part --
63 // don't give warnings for uninitialized vars
64 error_reporting(E_ERROR | E_WARNING | E_PARSE);
66 // make sure there's no unnecessary escaping: # set_magic_quotes_runtime(0);
67 if ( version_compare(PHP_VERSION, '5.3.0', '<') )
69 ini_set('magic_quotes_runtime', '0');
72 // if there are some plugins or skins to import, do not include vars in globalfunctions.php again... so set a flag
73 if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) )
76 $CONF['installscript'] = 1;
79 if ( !class_exists('i18n', FALSE) )
81 include('../nucleus/libs/i18n.php');
83 if ( !i18n::init('UTF-8', './locales') )
85 exit('Failed to initialize iconv or mbstring extension. Would you please contact the administrator of your PHP server?');
89 // we will use postVar, getVar, ... methods instead of $_GET, $_POST ...
90 include_once('../nucleus/libs/vars4.1.0.php');
92 // include core classes that are needed for login & plugin handling
93 include_once('../nucleus/libs/mysql.php');
95 ## added for 3.5 sql_* wrapper
96 global $MYSQL_HANDLER;
98 //set the handler if different from mysql (or mysqli) # $MYSQL_HANDLER = array('pdo','mysql');
99 if ( !isset($MYSQL_HANDLER) )
101 $MYSQL_HANDLER = array('mysql', '');
104 include_once('../nucleus/libs/sql/' . $MYSQL_HANDLER[0] . '.php');
105 ## end new for 3.5 sql_* wrapper
107 /* TODO: if something input related to locale, sdet it, else set default */
108 include('./locales/en_Latn_US.UTF-8.php');
109 i18n::set_current_locale('en_Latn_US');
111 /* send HTTP header */
112 header('Content-Type: application/xhtml+xml; charset=' . i18n::get_current_charset());
114 // check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x
115 if ( !function_exists('mysql_query') )
120 if ( postVar('action') == 'go' )
133 * Display the form for installation settings
135 function showInstallForm()
137 // 0. pre check if all necessary files exist
140 echo "<?xml version=\"1.0\" encoding=\"" . i18n::get_current_charset() . "\" ?>\n";
141 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
142 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" . preg_replace('#_#', '-', i18n::get_current_locale()) . "\" lang=\"" . preg_replace('#_#', '-', i18n::get_current_locale()) . "\">\n";
145 <title><?php echo _TITLE; ?></title>
146 <link rel="stylesheet" type="text/css" href="../nucleus/documentation/styles/manual.css" />
147 <script type="text/javascript">
151 // function to make sure the submit button only gets pressed once
152 function checkSubmit()
155 if ( submitcount == 0 )
170 <div style="text-align: center;"><img src="../nucleus/styles/logo.gif" alt="<?php echo _ALT_NUCLEUS_CMS_LOGO; ?>" /></div>
171 <form method="post" action="./index.php">
173 <h1><?php echo _HEADER1; ?></h1>
175 <?php echo _TEXT1; ?>
177 <h1><?php echo _HEADER2; ?></h1>
179 <?php echo _TEXT2; ?>
182 <li> PHP: <?php echo phpversion(); ?> </li>
186 // Turn on output buffer
187 // Needed to repress the output of the sql function that are
188 // not part of php (in this case the @ operator doesn't work)
191 // note: this piece of code is taken from phpMyAdmin
192 $conn = sql_connect_args('localhost', '', '');
193 $result = @sql_query('SELECT VERSION() AS version', $conn);
195 if ( $result != FALSE && sql_num_rows($result) > 0 )
197 $row = sql_fetch_array($result);
198 $match = i18n::explode('.', $row['version']);
202 $result = @sql_query('SHOW VARIABLES LIKE \'version\'', $conn);
204 if ( $result != FALSE && @sql_num_rows($result) > 0 )
206 $row = sql_fetch_row($result);
207 $match = i18n::explode('.', $row[1]);
211 //$output = shell_exec('mysql -V');
212 $output = ( function_exists('shell_exec') ) ? @shell_exec('mysql -V') : '0.0.0';
213 preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
214 $match = i18n::explode('.', $version[0]);
216 if ( $match[0] == '' )
227 @sql_disconnect($conn);
229 //End and clean output buffer
232 $mysqlVersion = implode($match, '.');
233 $minVersion = '3.23';
235 if ( $mysqlVersion == '0.0.0' )
244 if ( $mysqlVersion < $minVersion )
246 echo ' <strong>', _TEXT2_WARN2 , $minVersion, '</strong>';
254 // tell people how they can have their config file filled out automatically
255 if ( @file_exists('../config.php') && @!is_writable('../config.php') )
259 <h1><?php echo _HEADER3; ?></h1>
267 <h1><?php echo _HEADER4; ?></h1>
269 <?php echo _TEXT4; ?>
272 <legend><?php echo _TEXT4_TAB_HEAD; ?></legend>
275 <td><label for="if_mySQL_host"><?php echo _TEXT4_TAB_FIELD1; ?>:</label></td>
276 <td><input id="if_mySQL_host" name="mySQL_host" value="<?php echo ENTITY::hsc(@ini_get('mysql.default_host') )?>" /></td>
279 <td><label for="if_mySQL_user"><?php echo _TEXT4_TAB_FIELD2; ?>:</label></td>
280 <td><input id="if_mySQL_user" name="mySQL_user" /></td>
283 <td><label for="if_mySQL_password"><?php echo _TEXT4_TAB_FIELD3; ?>:</label></td>
284 <td><input id="if_mySQL_password" name="mySQL_password" type="password" /></td>
287 <td><label for="if_mySQL_database"><?php echo _TEXT4_TAB_FIELD4; ?>:</label></td>
288 <td><input id="if_mySQL_database" name="mySQL_database" /> (<input name="mySQL_create" value="1" type="checkbox" id="mySQL_create" /><label for="mySQL_create"><?php echo _TEXT4_TAB_FIELD4_ADD; ?></label>)</td>
294 <legend><?php echo _TEXT4_TAB2_HEAD; ?></legend>
297 <td><input name="mySQL_usePrefix" value="1" type="checkbox" id="mySQL_usePrefix" /><label for="mySQL_usePrefix"><?php echo _TEXT4_TAB2_FIELD; ?>:</label></td>
298 <td><input name="mySQL_tablePrefix" value="" /></td>
302 <?php echo _TEXT4_TAB2_ADD; ?>
306 <h1><?php echo _HEADER5; ?></h1>
308 <?php echo _TEXT5; ?>
311 // no need to this all! dirname(__FILE__) is all we need -- moraes
313 // discover full path
314 $fullPath = serverVar('PATH_TRANSLATED');
316 if ($fullPath == '') {
317 $fullPath = serverVar('SCRIPT_FILENAME');
320 $base_path = str_replace('./index.php', '', $fullPath);
321 $base_path = replace_double_backslash($base_path);
322 $base_path = replace_double_backslash($base_path);
324 // add slash at end if necessary
325 if (!ends_with_slash($base_path) ) {
331 * In the code below, there used to be if conditions within the form's HTML that conditionally echoed the URLs.
334 * if ($base_path) . . .
338 * I removed this and simplified below, because PHP's type casting will make these always evaluate to TRUE.
339 * At least currently, $base_path will always be non-empty, since the trailing slash is appended to it.
340 * Similarly, $index_url will always be non-empty, since the 'http://' is prepended to it.
341 * Non-empty, non-zero strings evaluated in if conditions are always cast to boolean TRUE.
342 * The if conditions were accomplishing nothing (currently) and we should avoid using such comparisons, anyway.
343 * If we need to check for a blank/empty string, use empty().
345 * I was initially replacing those if conditions with ternary operators for empty(), but then I realized
346 * they will never be empty.
348 * In addition, I decided to remove the PHP logic from within the form and set up separate variables (they were
349 * all just $url before), so the form just echos the values as needed.
350 * - gregorlove 7/13/2011 5:56 PM
354 $base_path = realpath(dirname(__FILE__) . '/..');
355 $pwd = preg_replace("#{$base_path}/#", '', dirname(__FILE__));
358 $index_url = 'http://' . serverVar('HTTP_HOST') . serverVar('PHP_SELF');
359 $index_url = preg_replace("#{$pwd}/index.php#", '', $index_url);
360 $index_url = replace_double_backslash($index_url);
362 // add slash at end if necessary
363 if ( !ends_with_slash($base_path) )
367 if ( !ends_with_slash($index_url) )
373 $admin_url = $index_url . 'nucleus/';
374 $admin_path = $base_path . 'nucleus/';
377 $media_url = $index_url . 'media/';
378 $media_path = $base_path . 'media/';
381 $skins_url = $index_url . 'skins/';
382 $skins_path = $base_path . 'skins/';
385 $plugins_url = $admin_url . 'plugins/';
388 $action_url = $index_url . 'action.php';
393 <legend><?php echo _TEXT5_TAB_HEAD; ?></legend>
396 <td><label for="if_IndexURL"><?php echo _TEXT5_TAB_FIELD1;?>:</label></td>
397 <td><input id="if_IndexURL" name="IndexURL" size="60" value="<?php echo $index_url; ?>" /></td>
400 <td><label for="if_AdminURL"><?php echo _TEXT5_TAB_FIELD2;?>:</label></td>
401 <td><input id="if_AdminURL" name="AdminURL" size="60" value="<?php echo $admin_url; ?>" /></td>
404 <td><label for="if_AdminPath"><?php echo _TEXT5_TAB_FIELD3;?>:</label></td>
405 <td><input id="if_AdminPath" name="AdminPath" size="60" value="<?php echo $admin_path; ?>" /></td>
408 <td><label for="if_MediaURL"><?php echo _TEXT5_TAB_FIELD4;?>:</label></td>
409 <td><input id="if_MediaURL" name="MediaURL" size="60" value="<?php echo $media_url; ?>" /></td>
412 <td><label for="if_MediaPath"><?php echo _TEXT5_TAB_FIELD5;?>:</label></td>
413 <td><input id="if_MediaPath" name="MediaPath" size="60" value="<?php echo $media_path; ?>" /></td>
416 <td><label for="if_SkinsURL"><?php echo _TEXT5_TAB_FIELD6;?>:</label></td>
417 <td><input id="if_SkinsURL" name="SkinsURL" size="60" value="<?php echo $skins_url; ?>" />
418 <br />(used by imported skins)
422 <td><label for="if_SkinsPath"><?php echo _TEXT5_TAB_FIELD7;?>:</label></td>
423 <td><input id="if_SkinsPath" name="SkinsPath" size="60" value="<?php echo $skins_path; ?>" />
424 <br />(<?php echo _TEXT5_TAB_FIELD7_2;?>)
428 <td><label for="if_PluginURL"><?php echo _TEXT5_TAB_FIELD8;?>:</label></td>
429 <td><input id="if_PluginURL" name="PluginURL" size="60" value="<?php echo $plugins_url; ?>" /></td>
432 <td><label for="if_ActionURL"><?php echo _TEXT5_TAB_FIELD9;?>:</label></td>
433 <td><input id="if_ActionURL" name="ActionURL" size="60" value="<?php echo $action_url; ?>" />
434 <br />(<?php echo _TEXT5_TAB_FIELD9_2;?>)
440 <?php echo _TEXT5_2; ?>
442 <h1><?php echo _HEADER6; ?></h1>
444 <?php echo _TEXT6; ?>
447 <legend><?php echo _TEXT6_TAB_HEAD; ?></legend>
450 <td><label for="if_User_name"><?php echo _TEXT6_TAB_FIELD1; ?>:</label></td>
451 <td><input id="if_User_name" name="User_name" value="" /> <small>(<?php echo _TEXT6_TAB_FIELD1_2; ?>)</small></td>
454 <td><label for="if_User_realname"><?php echo _TEXT6_TAB_FIELD2; ?>:</label></td>
455 <td><input id="if_User_realname" name="User_realname" value="" /></td>
458 <td><label for="if_User_password"><?php echo _TEXT6_TAB_FIELD3; ?>:</label></td>
459 <td><input id="if_User_password" name="User_password" type="password" value="" /></td>
462 <td><label for="if_User_password2"><?php echo _TEXT6_TAB_FIELD4; ?>:</label></td>
463 <td><input id="if_User_password2" name="User_password2" type="password" value="" /></td>
466 <td><label for="if_User_email"><?php echo _TEXT6_TAB_FIELD5; ?>:</label></td>
467 <td><input id="if_User_email" name="User_email" value="" /> <small>(<?php echo _TEXT6_TAB_FIELD5_2; ?>)</small></td>
472 <h1><?php echo _HEADER7; ?></h1>
474 <?php echo _TEXT7; ?>
477 <legend><?php echo _TEXT7_TAB_HEAD; ?></legend>
480 <td><label for="if_Blog_name"><?php echo _TEXT7_TAB_FIELD1; ?>:</label></td>
481 <td><input id="if_Blog_name" name="Blog_name" size="60" value="My Nucleus CMS" /></td>
484 <td><label for="if_Blog_shortname"><?php echo _TEXT7_TAB_FIELD2; ?>:</label></td>
485 <td><input id="if_Blog_shortname" name="Blog_shortname" value="mynucleuscms" /> <small>(<?php echo _TEXT7_TAB_FIELD2_2; ?>)</small></td>
490 <h1><?php echo _HEADER8; ?></h1>
493 <legend><?php echo _TEXT8_TAB_HEADER; ?></legend>
496 <td><input name="Weblog_ping" value="1" type="checkbox" /><label for="Weblog_ping"><?php echo _TEXT8_TAB_FIELD1; ?></label></td>
501 <h1><?php echo _HEADER9; ?></h1>
503 <?php echo _TEXT9; ?>
505 <p><input name="action" value="go" type="hidden" /> <input type="submit" value="<?php echo _BUTTON1; ?>" onclick="return checkSubmit();" /></p>
512 } // end function showInstallForm()
516 * Add a table prefix if it is used
518 * @param string $input table name with prefix
521 function tableName($input)
523 global $mysql_usePrefix, $mysql_prefix;
525 if ( $mysql_usePrefix == 1 )
527 return $mysql_prefix . $input;
538 * The installation process itself
542 global $mysql_usePrefix, $mysql_prefix, $weblog_ping;
544 // 0. put all POST-vars into vars
545 $mysql_host = postVar('mySQL_host');
546 $mysql_user = postVar('mySQL_user');
547 $mysql_password = postVar('mySQL_password');
548 $mysql_database = postVar('mySQL_database');
549 $mysql_create = postVar('mySQL_create');
550 $mysql_usePrefix = postVar('mySQL_usePrefix');
551 $mysql_prefix = postVar('mySQL_tablePrefix');
552 $config_indexurl = postVar('IndexURL');
553 $config_adminurl = postVar('AdminURL');
554 $config_adminpath = postVar('AdminPath');
555 $config_mediaurl = postVar('MediaURL');
556 $config_skinsurl = postVar('SkinsURL');
557 $config_pluginurl = postVar('PluginURL');
558 $config_actionurl = postVar('ActionURL');
559 $config_mediapath = postVar('MediaPath');
560 $config_skinspath = postVar('SkinsPath');
561 $user_name = postVar('User_name');
562 $user_realname = postVar('User_realname');
563 $user_password = postVar('User_password');
564 $user_password2 = postVar('User_password2');
565 $user_email = postVar('User_email');
566 $blog_name = postVar('Blog_name');
567 $blog_shortname = postVar('Blog_shortname');
568 $config_adminemail = $user_email;
569 $config_sitename = $blog_name;
570 $weblog_ping = postVar('Weblog_ping');
572 $config_indexurl = replace_double_backslash($config_indexurl);
573 $config_adminurl = replace_double_backslash($config_adminurl);
574 $config_mediaurl = replace_double_backslash($config_mediaurl);
575 $config_skinsurl = replace_double_backslash($config_skinsurl);
576 $config_pluginurl = replace_double_backslash($config_pluginurl);
577 $config_actionurl = replace_double_backslash($config_actionurl);
578 $config_adminpath = replace_double_backslash($config_adminpath);
579 $config_skinspath = replace_double_backslash($config_skinspath);
581 // 1. check all the data
584 if ( !$mysql_database )
586 array_push($errors, _ERROR2);
589 if ( ($mysql_usePrefix == 1) && (i18n::strlen($mysql_prefix) == 0) )
591 array_push($errors, _ERROR3);
594 if ( ($mysql_usePrefix == 1) && (!preg_match('/^[a-zA-Z0-9_]+$/i', $mysql_prefix) ) )
596 array_push($errors, _ERROR4);
599 // TODO: add action.php check
600 if ( !ends_with_slash($config_indexurl) || !ends_with_slash($config_adminurl) || !ends_with_slash($config_mediaurl) || !ends_with_slash($config_pluginurl) || !ends_with_slash($config_skinsurl) )
602 array_push($errors, _ERROR5);
605 if ( !ends_with_slash($config_adminpath) )
607 array_push($errors, _ERROR6);
610 if ( !ends_with_slash($config_mediapath) )
612 array_push($errors, _ERROR7);
615 if ( !ends_with_slash($config_skinspath) )
617 array_push($errors, _ERROR8);
620 if ( !is_dir($config_adminpath) )
622 array_push($errors, _ERROR9);
625 if ( !_isValidMailAddress($user_email) )
627 array_push($errors, _ERROR10);
630 if ( !_isValidDisplayName($user_name) )
632 array_push($errors, _ERROR11);
635 if ( !$user_password || !$user_password2 )
637 array_push($errors, _ERROR12);
640 if ( $user_password != $user_password2 )
642 array_push($errors, _ERROR13);
645 if ( !_isValidShortName($blog_shortname) )
647 array_push($errors, _ERROR14);
650 if ( sizeof($errors) > 0 )
652 showErrorMessages($errors);
655 // 2. try to log in to mySQL
659 // this will need to be changed if we ever allow
660 $MYSQL_CONN = @sql_connect_args($mysql_host, $mysql_user, $mysql_password);
662 if ( $MYSQL_CONN == FALSE )
664 _doError(_ERROR15 . ': ' . sql_error() );
667 // 3. try to create database (if needed)
668 if ( $mysql_create == 1 )
670 sql_query('CREATE DATABASE ' . $mysql_database, $MYSQL_CONN) or _doError(_ERROR16 . ': ' . sql_error($MYSQL_CONN) );
673 // 4. try to select database
674 sql_select_db($mysql_database, $MYSQL_CONN) or _doError(_ERROR17);
676 // 5. execute queries
677 $filename = 'install.sql';
678 $fd = fopen($filename, 'r');
679 $queries = fread($fd, filesize($filename) );
682 $queries = preg_split('#(;\n|;\r)#', $queries);
684 $aTableNames = array(
698 'nucleus_activation',
702 // these are unneeded (one of the replacements above takes care of them)
703 // 'nucleus_plugin_event',
704 // 'nucleus_plugin_option',
705 // 'nucleus_plugin_option_desc',
706 // 'nucleus_skin_desc',
707 // 'nucleus_template_desc',
709 $aTableNamesPrefixed = array(
710 $mysql_prefix . 'nucleus_actionlog',
711 $mysql_prefix . 'nucleus_ban',
712 $mysql_prefix . 'nucleus_blog',
713 $mysql_prefix . 'nucleus_category',
714 $mysql_prefix . 'nucleus_comment',
715 $mysql_prefix . 'nucleus_config',
716 $mysql_prefix . 'nucleus_item',
717 $mysql_prefix . 'nucleus_karma',
718 $mysql_prefix . 'nucleus_member',
719 $mysql_prefix . 'nucleus_plugin',
720 $mysql_prefix . 'nucleus_skin',
721 $mysql_prefix . 'nucleus_template',
722 $mysql_prefix . 'nucleus_team',
723 $mysql_prefix . 'nucleus_activation',
724 $mysql_prefix . 'nucleus_tickets'
727 // these are unneeded (one of the replacements above takes care of them)
728 // $mysql_prefix . 'nucleus_plugin_event',
729 // $mysql_prefix . 'nucleus_plugin_option',
730 // $mysql_prefix . 'nucleus_plugin_option_desc',
731 // $mysql_prefix . 'nucleus_skin_desc',
732 // $mysql_prefix . 'nucleus_template_desc',
734 $count = count($queries);
736 for ( $idx = 0; $idx < $count; $idx++ )
738 $query = trim($queries[$idx]);
739 // echo "QUERY = <small>" . ENTITY::hsc($query) . "</small><p>";
744 if ( $mysql_usePrefix == 1 )
746 $query = str_replace($aTableNames, $aTableNamesPrefixed, $query);
749 sql_query($query, $MYSQL_CONN) or _doError(_ERROR30 . ' (<small>' . ENTITY::hsc($query) . '</small>): ' . sql_error($MYSQL_CONN) );
754 // 5a make first post
755 $newpost = "INSERT INTO ". tableName('nucleus_item') ." VALUES (1, '" . _1ST_POST_TITLE . "', '" . _1ST_POST . "', '" . _1ST_POST2 . "', 1, 1, '2005-08-15 11:04:26', 0, 0, 0, 1, 0, 1);";
756 sql_query($newpost,$MYSQL_CONN) or _doError(_ERROR18 . ' (<small>' . ENTITY::hsc($newpost) . '</small>): ' . sql_error($MYSQL_CONN) );
758 // 6. update global settings
759 updateConfig('IndexURL', $config_indexurl);
760 updateConfig('AdminURL', $config_adminurl);
761 updateConfig('MediaURL', $config_mediaurl);
762 updateConfig('SkinsURL', $config_skinsurl);
763 updateConfig('PluginURL', $config_pluginurl);
764 updateConfig('ActionURL', $config_actionurl);
765 updateConfig('AdminEmail', $config_adminemail);
766 updateConfig('SiteName', $config_sitename);
768 // 7. update GOD member
769 $query = 'UPDATE ' . tableName('nucleus_member')
770 . " SET mname='" . addslashes($user_name) . "',"
771 . " mrealname='" . addslashes($user_realname) . "',"
772 . " mpassword='" . md5(addslashes($user_password) ) . "',"
773 . " murl='" . addslashes($config_indexurl) . "',"
774 . " memail='" . addslashes($user_email) . "',"
775 . " madmin=1, mcanlogin=1"
776 . " WHERE mnumber=1";
778 sql_query($query,$MYSQL_CONN) or _doError(_ERROR19 . ': ' . sql_error($MYSQL_CONN) );
780 // 8. update weblog settings
781 $query = 'UPDATE ' . tableName('nucleus_blog')
782 . " SET bname='" . addslashes($blog_name) . "',"
783 . " bshortname='" . addslashes($blog_shortname) . "',"
784 . " burl='" . addslashes($config_indexurl) . "'"
785 . " WHERE bnumber=1";
787 sql_query($query, $MYSQL_CONN) or _doError(_ERROR20 . ': ' . sql_error($MYSQL_CONN) );
789 // 9. update item date
790 $query = 'UPDATE ' . tableName('nucleus_item')
791 . " SET itime='" . date('Y-m-d H:i:s', time() ) ."'"
792 . " WHERE inumber=1";
794 sql_query($query,$MYSQL_CONN) or _doError(_ERROR21 . ': ' . sql_error($MYSQL_CONN) );
796 global $aConfPlugsToInstall, $aConfSkinsToImport;
797 $aSkinErrors = array();
798 $aPlugErrors = array();
800 if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) )
802 // 10. set global variables
803 global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX;
805 $MYSQL_HOST = $mysql_host;
806 $MYSQL_USER = $mysql_user;
807 $MYSQL_PASSWORD = $mysql_password;
808 $MYSQL_DATABASE = $mysql_database;
809 $MYSQL_PREFIX = ( $mysql_usePrefix == 1 ) ? $mysql_prefix : '';
811 global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;
813 $DIR_NUCLEUS = $config_adminpath;
814 $DIR_MEDIA = $config_mediapath;
815 $DIR_SKINS = $config_skinspath;
816 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
817 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
818 $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
820 // close database connection (needs to be closed if we want to include globalfunctions.php)
821 sql_close($MYSQL_CONN);
824 include_once($DIR_LIBS . 'globalfunctions.php');
826 // 11. install custom skins
827 $aSkinErrors = installCustomSkins($manager);
828 $defskinQue = 'SELECT `sdnumber` as result FROM ' . sql_table('skin_desc') . ' WHERE `sdname` = "default"';
829 $defSkinID = quickQuery($defskinQue);
830 $updateQuery = 'UPDATE ' . sql_table('blog') . ' SET `bdefskin` = ' . intval($defSkinID) . ' WHERE `bnumber` = 1';
831 sql_query($updateQuery);
832 $updateQuery = 'UPDATE ' . sql_table('config') . ' SET `value` = ' . intval($defSkinID). ' WHERE `name` = "BaseSkin"';
833 sql_query($updateQuery);
835 // 12. install NP_Ping, if decided
836 if ( $weblog_ping == 1 )
838 global $aConfPlugsToInstall;
839 array_push($aConfPlugsToInstall, 'NP_Ping');
842 // 13. install custom plugins
843 $aPlugErrors = installCustomPlugs($manager);
846 // 14. Write config file ourselves (if possible)
849 if ( @file_exists('../config.php') && is_writable('../config.php') && $fp = @fopen('../config.php', 'w') )
851 $config_data = '<' . '?php' . "\n\n";
852 //$config_data .= "\n"; (extraneous, just added extra \n to previous line
853 $config_data .= " // mySQL connection information\n";
854 $config_data .= " \$MYSQL_HOST = '" . $mysql_host . "';\n";
855 $config_data .= " \$MYSQL_USER = '" . $mysql_user . "';\n";
856 $config_data .= " \$MYSQL_PASSWORD = '" . $mysql_password . "';\n";
857 $config_data .= " \$MYSQL_DATABASE = '" . $mysql_database . "';\n";
858 $config_data .= " \$MYSQL_PREFIX = '" . (($mysql_usePrefix == 1)?$mysql_prefix:'') . "';\n";
859 $config_data .= " // new in 3.50. first element is db handler, the second is the db driver used by the handler\n";
860 $config_data .= " // default is \$MYSQL_HANDLER = array('mysql','mysql');\n";
861 $config_data .= " //\$MYSQL_HANDLER = array('mysql','mysql');\n";
862 $config_data .= " //\$MYSQL_HANDLER = array('pdo','mysql');\n";
863 $config_data .= " \$MYSQL_HANDLER = array('".$MYSQL_HANDLER[0]."','".$MYSQL_HANDLER[1]."');\n";
864 $config_data .= "\n";
865 $config_data .= " // main nucleus directory\n";
866 $config_data .= " \$DIR_NUCLEUS = '" . $config_adminpath . "';\n";
867 $config_data .= "\n";
868 $config_data .= " // path to media dir\n";
869 $config_data .= " \$DIR_MEDIA = '" . $config_mediapath . "';\n";
870 $config_data .= "\n";
871 $config_data .= " // extra skin files for imported skins\n";
872 $config_data .= " \$DIR_SKINS = '" . $config_skinspath . "';\n";
873 $config_data .= "\n";
874 $config_data .= " // these dirs are normally sub dirs of the nucleus dir, but \n";
875 $config_data .= " // you can redefine them if you wish\n";
876 $config_data .= " \$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";
877 $config_data .= " \$DIR_LOCALES = \$DIR_NUCLEUS . 'locales/';\n";
878 $config_data .= " \$DIR_LIBS = \$DIR_NUCLEUS . 'libs/';\n";
879 $config_data .= "\n";
880 $config_data .= " // include libs\n";
881 $config_data .= " include(\$DIR_LIBS.'globalfunctions.php');\n";
882 $config_data .= "?" . ">";
884 $result = @fputs($fp, $config_data, i18n::strlen($config_data) );
893 echo "<?xml version=\"1.0\" encoding=\"" . i18n::get_current_charset() . "\" ?>\n";
894 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
895 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" . preg_replace('#_#', '-', i18n::get_current_locale()) . "\" lang=\"" . preg_replace('#_#', '-', i18n::get_current_locale()) . "\">\n";
898 <title><?php echo _TITLE; ?></title>
899 <style>@import url('../nucleus/styles/manual.css');</style>
902 <div style='text-align:center'><img src='../nucleus/styles/logo.gif' /></div> <!-- Nucleus logo -->
905 $aAllErrors = array_merge($aSkinErrors, $aPlugErrors);
907 if ( count($aAllErrors) > 0 )
909 echo '<h1>' . _TITLE2 . '</h1>';
910 echo '<ul><li>' . implode('</li><li>', $aAllErrors) . '</li></ul>';
913 // begin if: config file not written
914 if ( !$bConfigWritten )
917 <h1><?php echo _TITLE3; ?></h1>
919 <?php echo _TEXT10; ?>
922 // mySQL connection information
923 $MYSQL_HOST = '<b><?php echo $mysql_host?></b>';
924 $MYSQL_USER = '<b><?php echo $mysql_user?></b>';
925 $MYSQL_PASSWORD = '<i><b>xxxxxxxxxxx</b></i>';
926 $MYSQL_DATABASE = '<b><?php echo $mysql_database?></b>';
927 $MYSQL_PREFIX = '<b><?php echo ($mysql_usePrefix == 1)?$mysql_prefix:''?></b>';
929 // new in 3.50. first element is db handler, the second is the db driver used by the handler
930 // default is $MYSQL_HANDLER = array('mysql','mysql');
931 //$MYSQL_HANDLER = array('mysql','mysql');
932 //$MYSQL_HANDLER = array('pdo','mysql');
933 $MYSQL_HANDLER = array('mysql','');
935 // main nucleus directory
936 $DIR_NUCLEUS = '<b><?php echo $config_adminpath?></b>';
939 $DIR_MEDIA = '<b><?php echo $config_mediapath?></b>';
941 // extra skin files for imported skins
942 $DIR_SKINS = '<b><?php echo $config_skinspath?></b>';
944 // these dirs are normally sub dirs of the nucleus dir, but
945 // you can redefine them if you wish
946 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
947 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
948 $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
951 include($DIR_LIBS.'globalfunctions.php');
954 <?php echo _TEXT11; ?>
957 <?php echo _TEXT12; ?>
962 // else: config file written
967 <h1><?php echo _TITLE4; ?></h1>
969 <?php echo _TEXT13; ?>
975 <h1><?php echo _TITLE5; ?></h1>
977 <?php echo _TEXT14; ?>
980 <li><?php echo _TEXT14_L1; ?></li>
981 <li><?php echo _TEXT14_L2; ?></li>
984 <h1><?php echo _HEADER10; ?></h1>
986 <?php echo _TEXT15; ?>
989 <li><?php echo _TEXT15_L1; ?></li>
990 <li><?php echo _TEXT15_L2; ?></li>
993 <?php echo _TEXT16; ?>
995 <h1><?php echo _HEADER11; ?></h1>
997 <p><?php echo _TEXT16_H; ?>
999 <li><a href="<?php echo $config_adminurl?>"><?php echo _TEXT16_L1; ?></a></li>
1000 <li><a href="<?php echo $config_indexurl?>"><?php echo _TEXT16_L2; ?></a></li>
1008 } // end function doInstall()
1012 * Install custom plugins
1014 function installCustomPlugs(&$manager)
1016 global $aConfPlugsToInstall, $DIR_LIBS;
1020 if ( count($aConfPlugsToInstall) == 0 )
1025 $res = sql_query('SELECT * FROM ' . sql_table('plugin') );
1026 $numCurrent = sql_num_rows($res);
1028 foreach ( $aConfPlugsToInstall as $plugName )
1030 // do this before calling getPlugin (in case the plugin id is used there)
1031 $query = 'INSERT INTO ' . sql_table('plugin') . ' (`porder`, `pfile`) VALUES (' . (++$numCurrent) . ', "' . addslashes($plugName) . '")';
1034 // get and install the plugin
1035 $manager->clearCachedInfo('installedPlugins');
1036 $plugin =& $manager->getPlugin($plugName);
1037 $plugin->setID($numCurrent);
1041 sql_query('DELETE FROM ' . sql_table('plugin') . ' WHERE `pfile` = \'' . addslashes($plugName) . '\'');
1043 array_push($aErrors, _ERROR22 . $plugName);
1050 // SYNC PLUGIN EVENT LIST
1051 sql_query('DELETE FROM ' . sql_table('plugin_event') );
1053 // loop over all installed plugins
1054 $res = sql_query('SELECT `pid`, `pfile` FROM ' . sql_table('plugin') );
1056 while ( $o = sql_fetch_object($res) )
1059 $plug =& $manager->getPlugin($o->pfile);
1063 $eventList = $plug->getEventList();
1065 foreach ( $eventList as $eventName )
1067 sql_query('INSERT INTO ' . sql_table('plugin_event') . ' (`pid`, `event`) VALUES (' . $pid . ', \'' . $eventName . '\')');
1075 } // end function installCustomPlugs()
1079 * Install custom skins
1080 * Prepares the installation of custom skins
1082 function installCustomSkins(&$manager)
1084 global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS, $manager;
1088 if ( empty($manager) )
1090 $manager = new MANAGER;
1093 if ( count($aConfSkinsToImport) == 0 )
1098 // load skinie class
1099 include_once($DIR_LIBS . 'skinie.php');
1101 $importer = new SKINIMPORT();
1103 foreach ( $aConfSkinsToImport as $skinName )
1106 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';
1108 if ( !@file_exists($skinFile) )
1110 array_push($aErrors, _ERROR23_1 . $skinFile . ' : ' . _ERROR23_2);
1114 $error = $importer->readFile($skinFile);
1118 array_push($aErrors, _ERROR24 . $skinName . ' : ' . $error);
1122 $error = $importer->writeToDatabase(1);
1126 array_push($aErrors, _ERROR24 . $skinName . ' : ' . $error);
1133 } // end function installCustomSkins()
1137 * Check if some important files of the Nucleus CMS installation are available
1138 * Give an error if one or more files are not accessible
1140 function doCheckFiles()
1142 $missingfiles = array();
1147 '../nucleus/index.php',
1148 '../nucleus/libs/globalfunctions.php',
1149 '../nucleus/libs/ADMIN.php',
1150 '../nucleus/libs/BLOG.php',
1151 '../nucleus/libs/COMMENT.php',
1152 '../nucleus/libs/COMMENTS.php',
1153 '../nucleus/libs/ITEM.php',
1154 '../nucleus/libs/MEMBER.php',
1155 '../nucleus/libs/SKIN.php',
1156 '../nucleus/libs/TEMPLATE.php',
1157 '../nucleus/libs/MEDIA.php',
1158 '../nucleus/libs/ACTIONLOG.php',
1159 '../nucleus/media.php'
1162 $count = count($files);
1164 for ( $i = 0; $i < $count; $i++ )
1167 if ( !is_readable($files[$i]) )
1169 array_push($missingfiles, _ERROR25_1 . $files[$i] . _ERROR25_2);
1174 if ( count($missingfiles) > 0 )
1176 showErrorMessages($missingfiles);
1179 } // end function doCheckFiles()
1183 * Updates the configuration in the database
1185 * @param string $name name of the config var
1186 * @param string $value new value of the config var
1189 function updateConfig($name, $value)
1192 $name = addslashes($name);
1193 $value = trim(addslashes($value) );
1195 $query = 'UPDATE ' . tableName('nucleus_config')
1196 . " SET `value` = '$value'"
1197 . " WHERE `name` = '$name'";
1199 sql_query($query, $MYSQL_CONN) or _doError(_ERROR26 . ': ' . sql_error($MYSQL_CONN) );
1200 return sql_insert_id($MYSQL_CONN);
1205 * Replaces double backslashs
1207 * @param string $input string that could have double backslashs
1210 function replace_double_backslash($input)
1212 return str_replace('\\', '/', $input);
1217 * Checks if a string ends with a slash
1219 * @param string $input
1222 function ends_with_slash($input)
1224 return ( i18n::strrpos($input, '/') == i18n::strlen($input) - 1);
1229 * Checks if email address is valid
1231 * @param string $address address which should be tested
1234 function _isValidMailAddress($address)
1237 if ( preg_match("/^[a-zA-Z0-9\._-]+@+[A-Za-z0-9\._-]+\.+[A-Za-z]{2,4}$/", $address) )
1250 * Check if short blog names and nicknames are allowed
1251 * Returns true if the given string is a valid shortname
1252 * logic: only letters and numbers are allowed, no spaces allowed
1254 * FIX: function eregi is deprecated since PHP 5.3.0
1256 * @param string $name name which should be tested
1259 function _isValidShortName($name)
1262 if ( preg_match("/^[a-z0-9]+$/i", $name) )
1275 * Check if a display name is allowed
1276 * Returns true if the given string is a valid display name
1278 * FIX: function eregi is deprecated since PHP 5.3.0
1280 * @param string $name name which should be tested
1283 function _isValidDisplayName($name)
1286 if ( preg_match("/^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$/i", $name) )
1299 * Shows error message
1301 * @param string $msg error message
1303 function _doError($message)
1305 echo "<?xml version=\"1.0\" encoding=\"" . i18n::get_current_charset() . "\" ?>\n";
1306 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
1307 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" . preg_replace('#_#', '-', i18n::get_current_locale()) . "\" lang=\"" . preg_replace('#_#', '-', i18n::get_current_locale()) . "\">\n";
1310 <title><?php echo _TITLE; ?></title>
1311 <style>@import url('../nucleus/styles/manual.css');</style>
1314 <div style="text-align: center;"><img src="../nucleus/styles/logo.gif" /></div>
1315 <h1><?php echo _ERROR27; ?></h1>
1317 <p> <?php echo _ERROR28; ?>: "<?php echo $message; ?>" </p>
1318 <p> <a href="./index.php" onclick="history.back(); return false;"><?php echo _TEXT17; ?></a> </p>
1328 * Shows error messages
1330 * @param array $errors array with error messages
1332 function showErrorMessages($errors)
1334 echo "<?xml version=\"1.0\" encoding=\"" . i18n::get_current_charset() . "\" ?>\n";
1335 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
1336 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" . preg_replace('#_#', '-', i18n::get_current_locale()) . "\" lang=\"" . preg_replace('#_#', '-', i18n::get_current_locale()) . "\">\n";
1339 <title><?php echo _TITLE; ?></title>
1340 <style>@import url('../nucleus/styles/manual.css');</style>
1343 <div style='text-align:center'><img src='../nucleus/styles/logo.gif' /></div> <!-- Nucleus logo -->
1344 <h1><?php echo _ERROR27; ?></h1>
1346 <p><?php echo _ERROR29; ?>:</p>
1351 while ( $msg = array_shift($errors) )
1353 echo '<li>', $msg, '</li>';
1357 <p><a href="./index.php" onclick="history.back();return false;"><?php echo _TEXT17; ?></a></p>
1366 /* for the non-php systems that decide to show the contents: