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
21 * @license http://nucleuscms.org/license.txt GNU General Public License
22 * @copyright Copyright (C) 2002-2007 The Nucleus Group
26 // don't give warnings for uninitialized vars
27 error_reporting(E_ERROR | E_WARNING | E_PARSE);
30 $minimum_php_version = '5.0.6';
31 $minimum_mysql_version = '3.23';
33 // begin if: server's PHP version is below the minimum; halt installation
34 if ( version_compare(PHP_VERSION, $minimum_php_version, '<') )
36 exit('<div style="font-size: xx-large;"> Nucleus requires at least PHP version '. $minimum_php_version .'</div>');
39 // make sure there's no unnecessary escaping: # set_magic_quotes_runtime(0);
40 if ( version_compare(PHP_VERSION, '5.3.0', '<') )
42 ini_set('magic_quotes_runtime', '0');
47 * This part of the ./install/index.php code allows for customization of the install process.
48 * When distributing plugins or skins together with a Nucleus installation, the
49 * configuration below will instruct to install them
51 * -- Start Of Configurable Part --
55 * array with names of plugins to install. Plugin files must be present in the nucleus/plugin/ directory
58 * array('NP_TrackBack', 'NP_MemberGoodies')
60 $aConfPlugsToInstall = array('NP_SkinFiles', 'NP_SecurityEnforcer', 'NP_Text');
63 * array with skins to install. skins must be present under the skins/ directory with
64 * a subdirectory having the same name that contains a skinbackup.xml file
67 * array('base', 'rsd')
69 $aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default');
72 * -- End Of Configurable Part --
76 // Check if some important files
79 // if there are some plugins or skins to import, do not include vars in globalfunctions.php again... so set a flag
80 if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) )
83 $CONF['installscript'] = 1;
86 // we will use postVar, getVar, ... methods instead of $_GET, $_POST ...
87 include_once('../nucleus/libs/vars4.1.0.php');
89 // include core classes that are needed for internationalization
90 include_once('../nucleus/libs/i18n.php');
92 if ( !i18n::init('UTF-8', './locales') )
94 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>');
97 // check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x
98 if ( !function_exists('mysql_query') && !function_exists('mysqli_query') )
100 exit('<div style="font-size: xx-large;"> Your PHP version does not have support for MySQL :( </div>');
103 // include core classes that are needed for login & plugin handling
104 include_once('../nucleus/libs/mysql.php');
106 // added for 3.5 sql_* wrapper
107 global $MYSQL_HANDLER;
109 //set the handler if different from mysql (or mysqli) # $MYSQL_HANDLER = array('pdo','mysql');
110 if ( !isset($MYSQL_HANDLER) )
112 $MYSQL_HANDLER = array('mysql', '');
115 include_once('../nucleus/libs/sql/' . $MYSQL_HANDLER[0] . '.php');
116 // end new for 3.5 sql_* wrapper
124 * header tag of the installation screens
126 function showHeader()
128 /* send HTTP header */
129 header('Content-Type: text/html; charset=' . i18n::get_current_charset());
132 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
133 <html xmlns="http://www.w3.org/1999/xhtml">
135 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo i18n::get_current_charset(); ?>" />
136 <title><?php echo _TITLE; ?></title>
137 <link rel="stylesheet" type="text/css" href="./styles/inst.css" />
138 <style type="text/css">
140 <?php echo _BODYFONTSTYLE; ?>
149 * footer tag of the installation screens
151 function showFooter()
155 © 2001-2012 The Nucleus Groupe . Running Nucleus CMS v4.00
173 if ( postVar('locale') )
175 $_SESSION['locale'] = postVar('locale');
178 /* TODO: if something input related to locale, set it, else set default */
179 i18n::set_current_locale($_SESSION['locale'] ? $_SESSION['locale'] : 'en_Latn_US');
180 $translation_file = './locales/' . i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php';
181 if ( !file_exists($translation_file) )
183 $translation_file = './locales/en_Latn_US.UTF-8.php';
185 include($translation_file);
191 if ( !postVar('action') && !requestVar('mode') )
193 // Initialize the session
195 $_SESSION['mode'] = 'simple';
196 $_SESSION['mysql_host'] = _hsc(@ini_get('mysql.default_host'));
198 showSelectLocaleForm();
203 if ( requestVar('mode') )
205 $_SESSION['mode'] = requestVar('mode');
208 $action = postVar('action');
209 $isValid = doValidate();
210 if ( $action == 'install' && $isValid && doInstall() ) // install process
212 showInstallCompleteForm();
213 // Clearing the session
216 elseif ( $_SESSION['mode'] == 'simple' ) // simple install mode
218 if ( !$action || ( $action == 'next' && count($errors['db_setting']) > 0 ) )
228 if ( $action == 'next' )
232 showBlogSettingForm();
235 else // advanced install mode
241 showDetailSettingForm();
249 * Display the form for language select
251 function showSelectLocaleForm()
253 // Get the browser language that can be displayed
255 $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
256 foreach ($languages as $language)
258 if (strpos($language, ';') === FALSE)
264 $language = preg_replace('#([^;]+).*#', '$1', $language);
271 <div id="navigation">
272 <h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>
276 <p style="font-size:152%;font-weight:bold;">
279 <form method="post" action="./index.php">
282 <select name="locale">
283 <option value="en_Latn_US">English - United States</option>
284 <option value="ja_Jpan_JP">Japanese - Japan</option>
287 <button type="submit" name="mode" value="simple" class="sbt_arw">START</button>
296 * Display the form to set up a database
298 function showDBSettingForm()
301 getMySqlVersion(); // error is stored in $errors['mysql'].
304 <div id="navigation">
305 <h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>
307 <li><?php echo _STEP1; ?></li>
308 <li class="gry"> > <?php echo _STEP2; ?></li>
309 <li class="gry"> > <?php echo _STEP3; ?></li>
310 <li class="rightbox">
311 <a href="./?mode=details"><?php echo _MODE2; ?></a>
318 <?php echo _SIMPLE_NAVI1;
319 if ( !canConfigFileWritable() ) echo '<span class="err">', $errors['config'], '</span>';
320 if ( $errors['mysql'] ) echo '<span class="err">', $errors['mysql'], '</span>';
321 if ( is_array($errors['install']) )
323 foreach ( $errors['install'] as $error )
325 echo '<span class="err">', $error, "</span>\n";
330 <form method="post" action="./index.php">
332 <h2><?php echo _DB_HEADER; ?></h2>
335 if ( is_array($errors['db_setting']) )
337 foreach ( $errors['db_setting'] as $error )
339 echo '<span class="err">', $error, "</span>\n";
346 <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>
347 <td><input type="text" name="mysql_host" value="<?php echo $_SESSION['mysql_host']; ?>" /></td>
350 <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>
351 <td><input type="text" name="mysql_user" value="<?php echo $_SESSION['mysql_user']; ?>" /></td>
354 <th><span class="nam"><?php echo _DB_FIELD3; ?></span><span class="sub"><?php echo _DB_FIELD3_DESC; ?></span></th>
355 <td><input type="text" name="mysql_password" value="<?php echo $_SESSION['mysql_password']; ?>" /></td>
358 <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>
359 <td><input type="text" name="mysql_database" value="<?php echo $_SESSION['mysql_database']; ?>" /></td>
363 <button type="submit" name="mode" value="detail" class="sbt_sqr"><?php echo _MODE2; ?></button>
364 <button type="submit" name="action" value="next" class="sbt_arw"><?php echo _NEXT; ?></button>
367 <?php echo _DB_TEXT1; ?>
376 * Displays a form to the blog settings
378 function showBlogSettingForm()
383 <div id="navigation">
384 <h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>
386 <li><?php echo _STEP1; ?></li>
387 <li> > <?php echo _STEP2; ?></li>
388 <li class="gry"> > <?php echo _STEP3; ?></li>
389 <li class="rightbox">
390 <a href="./?mode=details"><?php echo _MODE2; ?></a>
397 <?php echo _SIMPLE_NAVI2; ?>
399 <form method="post" action="./index.php">
401 <h2><?php echo _BLOG_HEADER; ?></h2>
404 if ( is_array($errors['blog_setting']) )
406 foreach ( $errors['blog_setting'] as $error )
408 echo '<span class="err">', $error, "</span>\n";
415 <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>
416 <td><input type="text" name="blog_name" value="<?php echo $_SESSION['blog_name'] ? $_SESSION['blog_name'] : 'My Nucleus CMS'; ?>" /></td>
419 <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>
420 <td><input type="text" name="blog_shortname" value="<?php echo $_SESSION['blog_shortname'] ? $_SESSION['blog_shortname'] : 'mynucleuscms'; ?>" /></td>
426 <h2><?php echo _ADMIN_HEADER; ?></h2>
429 if ( is_array($errors['user_setting']) )
431 foreach ( $errors['user_setting'] as $error )
433 echo '<span class="err">', $error, "</span>\n";
440 <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>
441 <td><input type="text" name="user_realname" value="<?php echo $_SESSION['user_name']; ?>" /></td>
444 <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>
445 <td><input type="text" name="user_name" value="<?php echo $_SESSION['user_realname']; ?>" /></td>
448 <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span><span class="sub"><?php echo _ADMIN_FIELD3_DESC; ?></span></th>
449 <td><input type="password" name="user_password" /></td>
452 <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span><span class="sub"><?php echo _ADMIN_FIELD4_DESC; ?></span></th>
453 <td><input type="password" name="user_password2" /></td>
456 <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>
457 <td><input type="text" name="user_email" value="<?php echo $_SESSION['user_email']; ?>" /></td>
461 <button type="submit" name="action" value="install" class="sbt_arw"><?php echo _INSTALL; ?></button>
470 * Displays a form to the detail settings
472 function showDetailSettingForm()
477 <div id="navigation">
478 <h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>
480 <li class="rightbox">
481 <a href="./?mode=simple"><?php echo _MODE1; ?></a>
486 <div id="container_detailed">
488 <?php echo _DETAIL_NAVI1; ?>
491 <li>PHP: <?php echo phpversion(); ?></li>
492 <li>MySQL: <?php echo getMySqlVersion();
493 if (array_key_exists('mysql', $errors)) echo '<span class="err">', $errors['mysql'], '</span>'; ?></li>
496 if ( is_array($errors['install']) )
498 echo '<p class="msg">';
499 foreach ( $errors['install'] as $error )
501 echo '<span class="err">', $error, "</span>\n";
507 <form method="post" action="">
510 <h2><?php echo _DETAIL_HEADER1; ?></h2>
512 <?php echo _DETAIL_TEXT1;
513 if ( is_array($errors['db_setting']) )
515 foreach ( $errors['db_setting'] as $error )
517 echo '<span class="err">', $error, "</span>\n";
524 <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>
525 <td><input type="text" name="mysql_host" value="<?php echo $_SESSION['mysql_host']; ?>" /></td>
528 <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>
529 <td><input type="text" name="mysql_user" value="<?php echo $_SESSION['mysql_user']; ?>" /></td>
532 <th><span class="nam"><?php echo _DB_FIELD3; ?></span><span class="sub"><?php echo _DB_FIELD3_DESC; ?></span></th>
533 <td><input type="text" name="mysql_password" value="<?php echo $_SESSION['mysql_password']; ?>" /></td>
536 <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>
537 <td><input type="text" name="mysql_database" value="<?php echo $_SESSION['mysql_database']; ?>" /></td>
540 <th><span class="nam"><?php echo _DB_FIELD5; ?></span><span class="sub"><?php echo _DB_FIELD5_DESC; ?></span></th>
541 <td><input type="text" name="mysql_tablePrefix" value="<?php echo $_SESSION['mysql_tablePrefix']; ?>" /></td>
545 <h2><?php echo _DETAIL_HEADER2; ?></h2>
547 <?php echo _DETAIL_TEXT2;
548 if ( is_array($errors['path_setting']) )
550 foreach ( $errors['path_setting'] as $error )
552 echo '<span class="err">', $error, "</span>\n";
559 <th><span class="nam"><?php echo _PATH_FIELD1; ?></span></th>
560 <td><input type="text" name="IndexURL" value="<?php echo $_SESSION['IndexURL']; ?>" /></td>
563 <th><span class="nam"><?php echo _PATH_FIELD2; ?></span></th>
564 <td><input type="text" name="AdminURL" value="<?php echo $_SESSION['AdminURL']; ?>" /></td>
567 <th><span class="nam"><?php echo _PATH_FIELD3; ?></span></th>
568 <td><input type="text" name="AdminPath" value="<?php echo $_SESSION['AdminPath']; ?>" /></td>
571 <th><span class="nam"><?php echo _PATH_FIELD4; ?></span></th>
572 <td><input type="text" name="MediaURL" value="<?php echo $_SESSION['MediaURL']; ?>" /></td>
575 <th><span class="nam"><?php echo _PATH_FIELD5; ?></span></th>
576 <td><input type="text" name="MediaPath" value="<?php echo $_SESSION['MediaPath']; ?>" /></td>
579 <th><span class="nam"><?php echo _PATH_FIELD6; ?></span></th>
580 <td><input type="text" name="SkinsURL" value="<?php echo $_SESSION['SkinsURL']; ?>" /></td>
583 <th><span class="nam"><?php echo _PATH_FIELD7; ?></span></th>
584 <td><input type="text" name="SkinsPath" value="<?php echo $_SESSION['SkinsPath']; ?>" /></td>
587 <th><span class="nam"><?php echo _PATH_FIELD8; ?></span></th>
588 <td><input type="text" name="PluginURL" value="<?php echo $_SESSION['PluginURL']; ?>" /></td>
591 <th><span class="nam"><?php echo _PATH_FIELD9; ?></span></th>
592 <td><input type="text" name="ActionURL" value="<?php echo $_SESSION['ActionURL']; ?>" /></td>
596 <?php echo _DETAIL_TEXT3; ?>
599 <h2><?php echo _DETAIL_HEADER3; ?></h2>
601 <?php echo _DETAIL_TEXT4;
602 if ( is_array($errors['user_setting']) )
604 foreach ( $errors['user_setting'] as $error )
606 echo '<span class="err">', $error, "</span>\n";
613 <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>
614 <td><input type="text" name="user_realname" value="<?php echo $_SESSION['user_realname']; ?>" /></td>
617 <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>
618 <td><input type="text" name="user_name" value="<?php echo $_SESSION['user_name']; ?>" /></td>
621 <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span><span class="sub"><?php echo _ADMIN_FIELD3_DESC; ?></span></th>
622 <td><input type="password" name="user_password" /></td>
625 <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span><span class="sub"><?php echo _ADMIN_FIELD4_DESC; ?></span></th>
626 <td><input type="password" name="user_password2" /></td>
629 <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>
630 <td><input type="text" name="user_email" value="<?php echo $_SESSION['user_email']; ?>" /></td>
634 <h2><?php echo _DETAIL_HEADER4; ?></h2>
636 <?php echo _DETAIL_TEXT5;
637 if ( is_array($errors['blog_setting']) )
639 foreach ( $errors['blog_setting'] as $error )
641 echo '<span class="err">', $error, "</span>\n";
648 <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>
649 <td><input type="text" name="blog_name" value="<?php echo $_SESSION['blog_name']; ?>" /></td>
652 <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>
653 <td><input type="text" name="blog_shortname" value="<?php echo $_SESSION['blog_shortname']; ?>" /></td>
658 <?php echo _DETAIL_TEXT6; ?>
662 <button type="submit" name="action" value="install" class="sbt_arw"><?php echo _INSTALL; ?></button>
673 * Displays a screen to signal the completion of the installation
675 function showInstallCompleteForm()
680 <div id="navigation">
681 <h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>
683 <li><?php echo _STEP1; ?></li>
684 <li> > <?php echo _STEP2; ?></li>
685 <li> > <?php echo _STEP3; ?></li>
691 <?php echo _INST_TEXT;
692 if ( $errors['config_data'] )
694 echo '<span class="err">', _INST_TEXT4, '</span>';
695 ?><pre><code><?php
696 // mySQL connection information
697 $MYSQL_HOST = '<b><?php echo $_SESSION['mysql_host']; ?></b>';
698 $MYSQL_USER = '<b><?php echo $_SESSION['mysql_user']; ?></b>';
699 $MYSQL_PASSWORD = '<i><b><?php echo $_SESSION['mysql_password']; ?></b></i>';
700 $MYSQL_DATABASE = '<b><?php echo $_SESSION['mysql_database']; ?></b>';
701 $MYSQL_PREFIX = '<b><?php echo $_SESSION['mysql_tablePrefix']; ?></b>';
703 // new in 3.50. first element is db handler, the second is the db driver used by the handler
704 // default is $MYSQL_HANDLER = array('mysql','mysql');
705 //$MYSQL_HANDLER = array('mysql','mysql');
706 //$MYSQL_HANDLER = array('pdo','mysql');
707 $MYSQL_HANDLER = array('mysql','');
709 // main nucleus directory
710 $DIR_NUCLEUS = '<b><?php echo $_SESSION['AdminPath']; ?></b>';
713 $DIR_MEDIA = '<b><?php echo $_SESSION['MediaPath']; ?></b>';
715 // extra skin files for imported skins
716 $DIR_SKINS = '<b><?php echo $_SESSION['SkinsPath']; ?></b>';
718 // these dirs are normally sub dirs of the nucleus dir, but
719 // you can redefine them if you wish
720 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
721 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
722 $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
725 include($DIR_LIBS.'globalfunctions.php');
731 echo '<span class="err">', _INST_TEXT5, '</span>';
735 <form method="post" action="./index.php">
737 <h2><?php echo _INST_HEADER1; ?></h2>
739 <?php echo sprintf(_INST_TEXT1, $_SESSION['blog_name']); ?>
742 <button type="button" name="toBlog" onclick="location.href='<?php echo $_SESSION['IndexURL']; ?>';" class="sbt_arw"><?php echo _INST_BUTTON1; ?></button>
747 <h2><?php echo _INST_HEADER2; ?></h2>
749 <?php echo _INST_TEXT2; ?>
752 <button type="button" name="toMng" onclick="location.href='<?php echo $_SESSION['AdminURL']; ?>';" class="sbt_arw"><?php echo _INST_BUTTON2; ?></button>
757 <h2><?php echo _INST_HEADER3; ?></h2>
759 <?php echo _INST_TEXT3; ?>
762 <button type="button" name="toAddBlog" onclick="location.href='<?php echo $_SESSION['AdminURL']; ?>index.php?action=createnewlog';" class="sbt_arw"><?php echo _INST_BUTTON3; ?></button>
773 function doValidate()
778 // 0. put all POST-vars into sessions
779 if (postVar('mysql_host')) $_SESSION['mysql_host'] = postVar('mysql_host');
780 if (postVar('mysql_user')) $_SESSION['mysql_user'] = postVar('mysql_user');
781 if (postVar('mysql_password')) $_SESSION['mysql_password'] = postVar('mysql_password');
782 if (postVar('mysql_database')) $_SESSION['mysql_database'] = postVar('mysql_database');
783 if (postVar('mysql_tablePrefix')) $_SESSION['mysql_tablePrefix'] = postVar('mysql_tablePrefix');
785 if (postVar('blog_name')) $_SESSION['blog_name'] = postVar('blog_name');
786 if (postVar('blog_shortname')) $_SESSION['blog_shortname'] = postVar('blog_shortname');
788 if (postVar('user_name'))
790 $_SESSION['user_name'] = postVar('user_name');
791 $_SESSION['user_password'] = postVar('user_password');
792 $_SESSION['user_password2'] = postVar('user_password2');
794 if (postVar('user_realname')) $_SESSION['user_realname'] = postVar('user_realname');
795 if (postVar('user_email')) $_SESSION['user_email'] = postVar('user_email');
797 if (postVar('IndexURL')) $_SESSION['IndexURL'] = postVar('IndexURL');
798 if (postVar('AdminURL')) $_SESSION['AdminURL'] = postVar('AdminURL');
799 if (postVar('AdminPath')) $_SESSION['AdminPath'] = postVar('AdminPath');
800 if (postVar('MediaURL')) $_SESSION['MediaURL'] = postVar('MediaURL');
801 if (postVar('SkinsURL')) $_SESSION['SkinsURL'] = postVar('SkinsURL');
802 if (postVar('PluginURL')) $_SESSION['PluginURL'] = postVar('PluginURL');
803 if (postVar('ActionURL')) $_SESSION['ActionURL'] = postVar('ActionURL');
804 if (postVar('MediaPath')) $_SESSION['MediaPath'] = postVar('MediaPath');
805 if (postVar('SkinsPath')) $_SESSION['SkinsPath'] = postVar('SkinsPath');
807 // TODO: I do not know why this is necessary
808 $_SESSION['IndexURL'] = replace_double_backslash($_SESSION['IndexURL']);
809 $_SESSION['AdminURL'] = replace_double_backslash($_SESSION['AdminURL']);
810 $_SESSION['AdminPath'] = replace_double_backslash($_SESSION['AdminPath']);
811 $_SESSION['MediaURL'] = replace_double_backslash($_SESSION['MediaURL']);
812 $_SESSION['SkinsURL'] = replace_double_backslash($_SESSION['SkinsURL']);
813 $_SESSION['PluginURL'] = replace_double_backslash($_SESSION['PluginURL']);
814 $_SESSION['ActionURL'] = replace_double_backslash($_SESSION['ActionURL']);
815 $_SESSION['MediaPath'] = replace_double_backslash($_SESSION['MediaPath']);
816 $_SESSION['SkinsPath'] = replace_double_backslash($_SESSION['SkinsPath']);
819 // 1. check the database connection
820 $errors['db_setting'] = array();
821 if ( !$_SESSION['mysql_host'] )
823 $errors['db_setting'][] = sprintf(_ERROR1, _DB_FIELD1);
826 if ( !$_SESSION['mysql_user'] )
828 $errors['db_setting'][] = sprintf(_ERROR1, _DB_FIELD2);
831 if ( !$_SESSION['mysql_database'] )
833 $errors['db_setting'][] = sprintf(_ERROR1, _DB_FIELD4);
836 if ( $_SESSION['mysql_tablePrefix'] && (!preg_match('/^[a-zA-Z0-9_]+$/i', $_SESSION['mysql_tablePrefix']) ) )
838 $errors['db_setting'][] = sprintf(_ERROR2, _DB_FIELD5);
841 if ( count($errors['db_setting']) == 0 )
843 // try to log in to mySQL
846 // this will need to be changed if we ever allow
847 $MYSQL_CONN = @sql_connect_args($_SESSION['mysql_host'], $_SESSION['mysql_user'], $_SESSION['mysql_password']);
849 if ( $MYSQL_CONN == FALSE )
851 $errors['db_setting'][] = _ERROR3;
855 sql_close($MYSQL_CONN);
859 if (count($errors['db_setting']) > 0)
864 // 2. check the blog settings
865 $errors['blog_setting'] = array();
866 $errors['user_setting'] = array();
867 if ( !$_SESSION['blog_name'] )
869 $errors['blog_setting'][] = sprintf(_ERROR1, _BLOG_FIELD1);
872 if ( !$_SESSION['blog_shortname'] )
874 $errors['blog_setting'][] = sprintf(_ERROR1, _BLOG_FIELD2);
876 elseif ( !_isValidShortName($_SESSION['blog_shortname']) )
878 $errors['blog_setting'][] = _ERROR4;
881 if ( !$_SESSION['user_name'] )
883 $errors['user_setting'][] = sprintf(_ERROR1, _ADMIN_FIELD2);
885 elseif ( !_isValidDisplayName($_SESSION['user_name']) )
887 $errors['user_setting'][] = _ERROR5;
890 if ( !$_SESSION['user_password'] || !$_SESSION['user_password2'] )
892 $errors['user_setting'][] = sprintf(_ERROR1, _ADMIN_FIELD3);
895 if ( $_SESSION['user_password'] != $_SESSION['user_password2'] )
897 $errors['user_setting'][] = _ERROR6;
900 if ( !$_SESSION['user_email'] )
902 $errors['user_setting'][] = sprintf(_ERROR1, _ADMIN_FIELD5);
904 elseif ( !_isValidMailAddress($_SESSION['user_email']) )
906 $errors['user_setting'][] = _ERROR7;
909 if (count($errors['blog_setting']) > 0 || count($errors['user_setting']) > 0)
915 // 3. check the path/url
916 $errors['path_setting'] = array();
917 // TODO: add action.php check
918 if ( !ends_with_slash($_SESSION['IndexURL'])
919 || !ends_with_slash($_SESSION['AdminURL'])
920 || !ends_with_slash($_SESSION['MediaURL'])
921 || !ends_with_slash($_SESSION['SkinsURL'])
922 || !ends_with_slash($_SESSION['PluginURL']) )
924 $errors['path_setting'][] = _ERROR8;
927 if ( !ends_with_slash($_SESSION['AdminPath']) )
929 $errors['path_setting'][] = sprintf(_ERROR9, _PATH_FIELD3);
932 if ( !ends_with_slash($_SESSION['MediaPath']) )
934 $errors['path_setting'][] = sprintf(_ERROR9, _PATH_FIELD5);
937 if ( !ends_with_slash($_SESSION['SkinsPath']) )
939 $errors['path_setting'][] = sprintf(_ERROR9, _PATH_FIELD7);
942 if ( !is_dir($_SESSION['AdminPath']) )
944 $errors['path_setting'][] = _ERROR10;
947 if (count($errors['path_setting']) > 0)
956 * The installation process itself
961 global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX, $MYSQL_CONN;
964 $errors['install'] = array();
966 // 1. put all SESSION-vars into vars
967 $MYSQL_HOST = $_SESSION['mysql_host'];
968 $MYSQL_USER = $_SESSION['mysql_user'];
969 $MYSQL_PASSWORD = $_SESSION['mysql_password'];
970 $MYSQL_DATABASE = $_SESSION['mysql_database'];
971 $MYSQL_PREFIX = $_SESSION['mysql_tablePrefix'];
973 $blog_name = $_SESSION['blog_name'];
974 $blog_shortname = $_SESSION['blog_shortname'];
976 $user_name = $_SESSION['user_name'];
977 $user_realname = $_SESSION['user_realname'];
978 $user_password = $_SESSION['user_password'];
979 $user_email = $_SESSION['user_email'];
981 $config_indexurl = $_SESSION['IndexURL'];
982 $config_adminurl = $_SESSION['AdminURL'];
983 $config_mediaurl = $_SESSION['MediaURL'];
984 $config_skinsurl = $_SESSION['SkinsURL'];
985 $config_pluginurl = $_SESSION['PluginURL'];
986 $config_actionurl = $_SESSION['ActionURL'];
987 $config_adminpath = $_SESSION['AdminPath'];
988 $config_mediapath = $_SESSION['MediaPath'];
989 $config_skinspath = $_SESSION['SkinsPath'];
991 $config_adminemail = $user_email;
992 $config_sitename = $blog_name;
994 // 2.open mySQL connection
996 // this will need to be changed if we ever allow
997 $MYSQL_CONN = @sql_connect_args($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
999 if ( $MYSQL_CONN == FALSE )
1001 $errors['install'][] = _ERROR3;
1005 // 3. try to create database
1006 if ( !sql_query('CREATE DATABASE IF NOT EXISTS ' . $MYSQL_DATABASE) )
1008 $errors['install'][] = _ERROR11 . ': ' . sql_error();
1011 // 4. try to select database
1012 if ( !sql_select_db($MYSQL_DATABASE) )
1014 $errors['install'][] = _ERROR12;
1016 sql_set_charset('utf8');
1018 // 4a. drop table that have already been created
1019 $result = sql_query('SHOW TABLES');
1020 while ($row = mysql_fetch_array($result, MYSQL_NUM))
1022 if ( !sql_query('DROP TABLE ' . $row[0]) )
1024 $errors['install'][] = _ERROR13 . ': ' . sql_error();
1028 if ( count($errors['install']) > 0 )
1033 // 5. execute queries
1034 $filename = 'install.sql';
1035 $fd = fopen($filename, 'r');
1036 $queries = fread($fd, filesize($filename) );
1039 $queries = preg_split('#(;\n|;\r)#', $queries);
1041 $aTableNames = array(
1042 'nucleus_actionlog',
1055 'nucleus_activation',
1059 // these are unneeded (one of the replacements above takes care of them)
1060 // 'nucleus_plugin_event',
1061 // 'nucleus_plugin_option',
1062 // 'nucleus_plugin_option_desc',
1063 // 'nucleus_skin_desc',
1064 // 'nucleus_template_desc',
1066 $aTableNamesPrefixed = array(
1067 $MYSQL_PREFIX . 'nucleus_actionlog',
1068 $MYSQL_PREFIX . 'nucleus_ban',
1069 $MYSQL_PREFIX . 'nucleus_blog',
1070 $MYSQL_PREFIX . 'nucleus_category',
1071 $MYSQL_PREFIX . 'nucleus_comment',
1072 $MYSQL_PREFIX . 'nucleus_config',
1073 $MYSQL_PREFIX . 'nucleus_item',
1074 $MYSQL_PREFIX . 'nucleus_karma',
1075 $MYSQL_PREFIX . 'nucleus_member',
1076 $MYSQL_PREFIX . 'nucleus_plugin',
1077 $MYSQL_PREFIX . 'nucleus_skin',
1078 $MYSQL_PREFIX . 'nucleus_template',
1079 $MYSQL_PREFIX . 'nucleus_team',
1080 $MYSQL_PREFIX . 'nucleus_activation',
1081 $MYSQL_PREFIX . 'nucleus_tickets'
1084 // these are unneeded (one of the replacements above takes care of them)
1085 // $MYSQL_PREFIX . 'nucleus_plugin_event',
1086 // $MYSQL_PREFIX . 'nucleus_plugin_option',
1087 // $MYSQL_PREFIX . 'nucleus_plugin_option_desc',
1088 // $MYSQL_PREFIX . 'nucleus_skin_desc',
1089 // $MYSQL_PREFIX . 'nucleus_template_desc',
1091 $count = count($queries);
1093 for ( $idx = 0; $idx < $count; $idx++ )
1095 $query = trim($queries[$idx]);
1096 // echo "QUERY = <small>" . _hsc($query) . "</small><p>";
1101 if ( $MYSQL_PREFIX )
1103 $query = str_replace($aTableNames, $aTableNamesPrefixed, $query);
1106 if ( !sql_query($query) )
1108 $errors['install'][] = _ERROR13 . ' (<small>' . _hsc($query) . '</small>): ' . sql_error();
1115 // 5a. make first post
1116 $newpost = "INSERT INTO ". tableName('nucleus_item')
1117 . " VALUES (1, '" . _1ST_POST_TITLE . "', '" . _1ST_POST . "', '" . _1ST_POST2 . "', 1, 1, '2005-08-15 11:04:26', 0, 0, 0, 1, 0, 1)";
1118 if ( !sql_query($newpost) )
1120 $errors['install'][] = _ERROR13 . ' (<small>' . _hsc($newpost) . '</small>): ' . sql_error();
1123 // 6. update global settings
1124 updateConfig('IndexURL', $config_indexurl);
1125 updateConfig('AdminURL', $config_adminurl);
1126 updateConfig('MediaURL', $config_mediaurl);
1127 updateConfig('SkinsURL', $config_skinsurl);
1128 updateConfig('PluginURL', $config_pluginurl);
1129 updateConfig('ActionURL', $config_actionurl);
1130 updateConfig('AdminEmail', $config_adminemail);
1131 updateConfig('SiteName', $config_sitename);
1132 updateConfig('Locale', i18n::get_current_locale());
1134 // 7. update GOD member
1135 $query = 'UPDATE ' . tableName('nucleus_member')
1136 . " SET mname = '" . sql_real_escape_string($user_name) . "',"
1137 . " mrealname = '" . sql_real_escape_string($user_realname) . "',"
1138 . " mpassword = '" . md5(sql_real_escape_string($user_password) ) . "',"
1139 . " murl = '" . sql_real_escape_string($config_indexurl) . "',"
1140 . " memail = '" . sql_real_escape_string($user_email) . "',"
1141 . " madmin = 1, mcanlogin = 1"
1142 . " WHERE mnumber = 1";
1144 if ( !sql_query($query) )
1146 $errors['install'][] = _ERROR14 . ': ' . sql_error();
1149 // 8. update weblog settings
1150 $query = 'UPDATE ' . tableName('nucleus_blog')
1151 . " SET bname = '" . sql_real_escape_string($blog_name) . "',"
1152 . " bshortname = '" . sql_real_escape_string($blog_shortname) . "',"
1153 . " burl = '" . sql_real_escape_string($config_indexurl) . "'"
1154 . " WHERE bnumber = 1";
1156 if ( !sql_query($query) )
1158 $errors['install'][] = _ERROR15 . ': ' . sql_error();
1161 // 8-2. update category settings
1162 $query = 'UPDATE ' . tableName('nucleus_category')
1163 . " SET cname = '" . _GENERALCAT_NAME . "',"
1164 . " cdesc = '" . _GENERALCAT_DESC . "'"
1165 . " WHERE catid = 1";
1167 if ( !sql_query($query) )
1169 $errors['install'][] = _ERROR15 . ': ' . sql_error();
1172 // 9. update item date
1173 $query = 'UPDATE ' . tableName('nucleus_item')
1174 . " SET itime = '" . date('Y-m-d H:i:s', time() ) ."'"
1175 . " WHERE inumber = 1";
1177 if ( !sql_query($query) )
1179 $errors['install'][] = _ERROR16 . ': ' . sql_error();
1184 global $aConfPlugsToInstall, $aConfSkinsToImport;
1185 $aSkinErrors = array();
1186 $aPlugErrors = array();
1188 if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) )
1190 // 10. set global variables
1191 global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LOCALES, $DIR_LIBS;
1192 $DIR_NUCLEUS = $config_adminpath;
1193 $DIR_MEDIA = $config_mediapath;
1194 $DIR_SKINS = $config_skinspath;
1195 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
1196 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
1197 $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
1199 // Are utilized in the installCustomPlugs and installCustomSkins functions.
1200 include_once($DIR_LIBS . 'globalfunctions.php');
1202 if ( !isset($manager) )
1204 $manager = new MANAGER;
1207 // 11. install custom skins
1208 $aSkinErrors = installCustomSkins();
1209 if ( count($aSkinErrors) > 0 )
1211 array_push($errors['install'], $aSkinErrors);
1213 $defskinQue = 'SELECT sdnumber FROM ' . tableName('nucleus_skin_desc') . " WHERE sdname='default'";
1214 $res = sql_query($defskinQue);
1215 $obj = sql_fetch_assoc($res);
1216 $defSkinID = $obj['sdnumber'];
1217 $updateQuery = 'UPDATE ' . tableName('nucleus_blog') . ' SET bdefskin=' . intval($defSkinID) . ' WHERE bnumber=1';
1218 sql_query($updateQuery);
1219 $updateQuery = 'UPDATE ' . tableName('nucleus_config') . ' SET value=' . intval($defSkinID). " WHERE name='BaseSkin'";
1220 sql_query($updateQuery);
1222 // 12. install custom plugins
1223 $aPlugErrors = installCustomPlugs($manager);
1224 if ( count($aPlugErrors) > 0 )
1226 array_push($errors['install'], $aPlugErrors);
1230 // 13. Write config file ourselves (if possible)
1231 $config_data = '<' . '?php' . "\n\n";
1232 $config_data .= "// mySQL connection information\n";
1233 $config_data .= "\$MYSQL_HOST = '" . $MYSQL_HOST . "';\n";
1234 $config_data .= "\$MYSQL_USER = '" . $MYSQL_USER . "';\n";
1235 $config_data .= "\$MYSQL_PASSWORD = '" . $MYSQL_PASSWORD . "';\n";
1236 $config_data .= "\$MYSQL_DATABASE = '" . $MYSQL_DATABASE . "';\n";
1237 $config_data .= "\$MYSQL_PREFIX = '" . $MYSQL_PREFIX . "';\n";
1238 $config_data .= "// new in 3.50. first element is db handler, the second is the db driver used by the handler\n";
1239 $config_data .= "// default is \$MYSQL_HANDLER = array('mysql','mysql');\n";
1240 $config_data .= "//\$MYSQL_HANDLER = array('mysql','mysql');\n";
1241 $config_data .= "//\$MYSQL_HANDLER = array('pdo','mysql');\n";
1242 $config_data .= "\$MYSQL_HANDLER = array('".$MYSQL_HANDLER[0]."','".$MYSQL_HANDLER[1]."');\n";
1243 $config_data .= "\n";
1244 $config_data .= "// main nucleus directory\n";
1245 $config_data .= "\$DIR_NUCLEUS = '" . $config_adminpath . "';\n";
1246 $config_data .= "\n";
1247 $config_data .= "// path to media dir\n";
1248 $config_data .= "\$DIR_MEDIA = '" . $config_mediapath . "';\n";
1249 $config_data .= "\n";
1250 $config_data .= "// extra skin files for imported skins\n";
1251 $config_data .= "\$DIR_SKINS = '" . $config_skinspath . "';\n";
1252 $config_data .= "\n";
1253 $config_data .= "// these dirs are normally sub dirs of the nucleus dir, but \n";
1254 $config_data .= "// you can redefine them if you wish\n";
1255 $config_data .= "\$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";
1256 $config_data .= "\$DIR_LOCALES = \$DIR_NUCLEUS . 'locales/';\n";
1257 $config_data .= "\$DIR_LIBS = \$DIR_NUCLEUS . 'libs/';\n";
1258 $config_data .= "\n";
1259 $config_data .= "// include libs\n";
1260 $config_data .= "include(\$DIR_LIBS.'globalfunctions.php');\n";
1261 $config_data .= "?" . ">";
1263 $errors['config_data'] = $config_data;
1265 if ( @!file_exists('../config.php')
1266 || (@file_exists('../config.php') && is_writable('../config.php')) )
1268 if ( $fp = @fopen('../config.php', 'w') )
1270 $result = @fwrite($fp, $config_data, i18n::strlen($config_data) );
1275 unset($errors['config_data']);
1276 if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
1278 @chmod('../config.php', 0444);
1284 if ( count($errors['install']) > 0 )
1289 } // end function doInstall()
1292 * Verifying that you can write to the configuration file
1294 function canConfigFileWritable()
1298 // tell people how they can have their config file filled out automatically
1299 if ( @file_exists('../config.php') && @!is_writable('../config.php') )
1301 // try to change the permissions.
1302 if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
1304 @chmod('../config.php', 0666);
1307 if ( @!is_writable('../config.php') )
1309 $errors['config'] = _ERROR17;
1318 * To obtain the version of MySQL
1322 function getMySqlVersion()
1324 global $minimum_mysql_version, $errors;
1325 // Turn on output buffer
1326 // Needed to repress the output of the sql function that are
1327 // not part of php (in this case the @ operator doesn't work)
1330 // note: this piece of code is taken from phpMyAdmin
1331 $conn = sql_connect_args('localhost', '', '');
1332 $result = @sql_query('SELECT VERSION() AS version', $conn);
1334 if ( $result != FALSE && sql_num_rows($result) > 0 )
1336 $row = sql_fetch_array($result);
1337 $match = i18n::explode('.', $row['version']);
1341 $result = @sql_query('SHOW VARIABLES LIKE \'version\'', $conn);
1343 if ( $result != FALSE && @sql_num_rows($result) > 0 )
1345 $row = sql_fetch_row($result);
1346 $match = i18n::explode('.', $row[1]);
1350 //$output = shell_exec('mysql -V');
1351 $output = ( function_exists('shell_exec') ) ? @shell_exec('mysql -V') : '0.0.0';
1352 preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
1353 $match = i18n::explode('.', $version[0]);
1355 if ( $match[0] == '' )
1357 $match = array('0', '0', '0');
1364 @sql_disconnect($conn);
1366 //End and clean output buffer
1369 $mysqlVersion = implode($match, '.');
1371 if ( $mysqlVersion < $minimum_mysql_version )
1373 $errors['mysql'] = sprintf(_ERROR18 , $minimum_mysql_version);
1376 if ( $mysqlVersion == '0.0.0' )
1382 return $mysqlVersion;
1388 * To obtain information of the directory and path where you want to install the Nucleus.
1390 function getURLAndPath()
1392 // no need to this all! dirname(__FILE__) is all we need -- moraes
1394 // discover full path
1395 $fullPath = serverVar('PATH_TRANSLATED');
1397 if ($fullPath == '') {
1398 $fullPath = serverVar('SCRIPT_FILENAME');
1401 $base_path = str_replace('./index.php', '', $fullPath);
1402 $base_path = replace_double_backslash($base_path);
1403 $base_path = replace_double_backslash($base_path);
1405 // add slash at end if necessary
1406 if (!ends_with_slash($base_path) ) {
1412 * In the code below, there used to be if conditions within the form's HTML that conditionally echoed the URLs.
1415 * if ($base_path) . . .
1419 * I removed this and simplified below, because PHP's type casting will make these always evaluate to TRUE.
1420 * At least currently, $base_path will always be non-empty, since the trailing slash is appended to it.
1421 * Similarly, $index_url will always be non-empty, since the 'http://' is prepended to it.
1422 * Non-empty, non-zero strings evaluated in if conditions are always cast to boolean TRUE.
1423 * The if conditions were accomplishing nothing (currently) and we should avoid using such comparisons, anyway.
1424 * If we need to check for a blank/empty string, use empty().
1426 * I was initially replacing those if conditions with ternary operators for empty(), but then I realized
1427 * they will never be empty.
1429 * In addition, I decided to remove the PHP logic from within the form and set up separate variables (they were
1430 * all just $url before), so the form just echos the values as needed.
1431 * - gregorlove 7/13/2011 5:56 PM
1435 $this_dir = implode('/', i18n::explode(DIRECTORY_SEPARATOR, dirname(__FILE__)));
1436 $base_path = realpath($this_dir . '/..');
1437 $pwd = preg_replace("#$base_path/#", '', $this_dir);
1440 $index_url = 'http://' . serverVar('HTTP_HOST') . serverVar('PHP_SELF');
1441 $index_url = preg_replace("#$pwd/index.php#", '', $index_url);
1442 $index_url = replace_double_backslash($index_url);
1444 // add slash at end if necessary
1445 if ( !ends_with_slash($base_path) )
1449 if ( !ends_with_slash($index_url) )
1454 # Admin URL and path
1455 $admin_url = $index_url . 'nucleus/';
1456 $admin_path = $base_path . 'nucleus/';
1458 # Media URL and path
1459 $media_url = $index_url . 'media/';
1460 $media_path = $base_path . 'media/';
1462 # Skins URL and path
1463 $skins_url = $index_url . 'skins/';
1464 $skins_path = $base_path . 'skins/';
1467 $plugins_url = $admin_url . 'plugins/';
1470 $action_url = $index_url . 'action.php';
1472 $_SESSION['IndexURL'] = $index_url;
1473 $_SESSION['AdminURL'] = $admin_url;
1474 $_SESSION['AdminPath'] = $admin_path;
1475 $_SESSION['MediaURL'] = $media_url;
1476 $_SESSION['MediaPath'] = $media_path;
1477 $_SESSION['SkinsURL'] = $skins_url;
1478 $_SESSION['SkinsPath'] = $skins_path;
1479 $_SESSION['PluginURL'] = $plugins_url;
1480 $_SESSION['ActionURL'] = $action_url;
1485 * Add a table prefix if it is used
1487 * @param string $input table name with prefix
1490 function tableName($input)
1492 if ( $_SESSION['mysql_tablePrefix'] )
1494 return $_SESSION['mysql_tablePrefix'] . $input;
1506 * Install custom plugins
1508 * @param object $manager MANAGER class instance
1510 function installCustomPlugs($manager)
1512 global $aConfPlugsToInstall, $DIR_LIBS;
1516 if ( count($aConfPlugsToInstall) == 0 )
1521 $res = sql_query('SELECT * FROM ' . tableName('nucleus_plugin') );
1522 $numCurrent = sql_num_rows($res);
1524 foreach ( $aConfPlugsToInstall as $plugName )
1526 // do this before calling getPlugin (in case the plugin id is used there)
1527 $query = 'INSERT INTO ' . tableName('nucleus_plugin') . ' (porder, pfile) VALUES (' . (++$numCurrent) . ", '" . sql_real_escape_string($plugName) . "')";
1530 // get and install the plugin
1531 $manager->clearCachedInfo('installedPlugins');
1532 $plugin =& $manager->getPlugin($plugName);
1533 $plugin->setID($numCurrent);
1537 sql_query('DELETE FROM ' . tableName('nucleus_plugin') . " WHERE pfile = '" . sql_real_escape_string($plugName) . "'");
1539 array_push($aErrors, sprintf(_ERROR20 ,$plugName));
1546 // SYNC PLUGIN EVENT LIST
1547 sql_query('DELETE FROM ' . tableName('nucleus_plugin_event') );
1549 // loop over all installed plugins
1550 $res = sql_query('SELECT pid, pfile FROM ' . tableName('nucleus_plugin') );
1552 while ( $o = sql_fetch_object($res) )
1555 $plug =& $manager->getPlugin($o->pfile);
1559 $eventList = $plug->getEventList();
1561 foreach ( $eventList as $eventName )
1563 sql_query('INSERT INTO ' . tableName('nucleus_plugin_event') . ' (pid, event) VALUES (' . $pid . ", '" . $eventName . "')");
1571 } // end function installCustomPlugs()
1575 * Install custom skins
1576 * Prepares the installation of custom skins
1578 function installCustomSkins()
1580 global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS;
1584 if ( count($aConfSkinsToImport) == 0 )
1589 // load skinie class
1590 include_once($DIR_LIBS . 'skinie.php');
1592 $importer = new SKINIMPORT();
1594 foreach ( $aConfSkinsToImport as $skinName )
1597 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';
1599 if ( !@file_exists($skinFile) )
1601 array_push($aErrors, sprintf(_ERROR21, $skinFile));
1605 $error = $importer->readFile($skinFile);
1609 array_push($aErrors, sprintf(_ERROR22, $skinName) . ' : ' . $error);
1613 $error = $importer->writeToDatabase(1);
1617 array_push($aErrors, sprintf(_ERROR22, $skinName) . ' : ' . $error);
1624 } // end function installCustomSkins()
1628 * Check if some important files of the Nucleus CMS installation are available
1629 * Give an error if one or more files are not accessible
1631 function doCheckFiles()
1633 $missingfiles = array();
1638 '../nucleus/index.php',
1639 '../nucleus/media.php',
1640 '../nucleus/libs/globalfunctions.php',
1641 '../nucleus/libs/ADMIN.php',
1642 '../nucleus/libs/BLOG.php',
1643 '../nucleus/libs/COMMENT.php',
1644 '../nucleus/libs/COMMENTS.php',
1645 '../nucleus/libs/ITEM.php',
1646 '../nucleus/libs/MEMBER.php',
1647 '../nucleus/libs/SKIN.php',
1648 '../nucleus/libs/TEMPLATE.php',
1649 '../nucleus/libs/MEDIA.php',
1650 '../nucleus/libs/ACTIONLOG.php',
1651 '../nucleus/libs/vars4.1.0.php',
1652 '../nucleus/libs/i18n.php',
1653 '../nucleus/libs/mysql.php',
1654 '../nucleus/libs/sql/mysql.php'
1657 $count = count($files);
1659 for ( $i = 0; $i < $count; $i++ )
1662 if ( !is_readable($files[$i]) )
1664 array_push( $missingfiles, 'File <b>' . $files[$i] . '</b> is missing or not readable.<br />');
1669 if ( count($missingfiles) > 0 )
1671 exit(implode( "\n", $missingfiles));
1674 } // end function doCheckFiles()
1678 * Updates the configuration in the database
1680 * @param string $name name of the config var
1681 * @param string $value new value of the config var
1684 function updateConfig($name, $value)
1687 $name = addslashes($name);
1688 $value = trim(addslashes($value) );
1690 $query = 'UPDATE ' . tableName('nucleus_config')
1691 . " SET `value` = '$value'"
1692 . " WHERE `name` = '$name'";
1694 if ( !sql_query($query) )
1696 $errors['install'][] = _ERROR13 . ': ' . sql_error();
1698 return sql_insert_id();
1703 * Replaces double backslashs
1705 * @param string $input string that could have double backslashs
1708 function replace_double_backslash($input)
1710 return str_replace('\\', '/', $input);
1715 * Checks if a string ends with a slash
1717 * @param string $input
1720 function ends_with_slash($input)
1722 return ( i18n::strrpos($input, '/') == i18n::strlen($input) - 1);
1727 * Checks if email address is valid
1729 * @param string $address address which should be tested
1732 function _isValidMailAddress($address)
1735 if ( preg_match("/^[a-zA-Z0-9\._-]+@[A-Za-z0-9\._-]+\.[A-Za-z]{2,6}$/", $address) )
1748 * Check if short blog names and nicknames are allowed
1749 * Returns true if the given string is a valid shortname
1750 * logic: only letters and numbers are allowed, no spaces allowed
1752 * FIX: function eregi is deprecated since PHP 5.3.0
1754 * @param string $name name which should be tested
1757 function _isValidShortName($name)
1760 if ( preg_match("/^[a-z0-9]+$/i", $name) )
1773 * Check if a display name is allowed
1774 * Returns true if the given string is a valid display name
1776 * FIX: function eregi is deprecated since PHP 5.3.0
1778 * @param string $name name which should be tested
1781 function _isValidDisplayName($name)
1784 if ( preg_match("/^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$/i", $name) )
1797 * htmlspecialchars wrapper
1799 * NOTE: htmlspecialchars_decode() is ASCII-to-ACII conversion
1800 * and its target string consists of several letters.
1801 * There are no problems.
1805 * @param string $string target string
1806 * @param string $quotation quotation mode. please refer to the argument of PHP built-in htmlspecialchars
1807 * @return string escaped string
1810 function _hsc($string, $quotation=ENT_QUOTES)
1813 * we can use 'double_encode' flag instead of this when dropping supports for PHP 5.2.2 or lower
1815 $string = htmlspecialchars_decode($string, $quotation);
1816 return (string) htmlspecialchars($string, $quotation, i18n::get_current_charset());
1819 /* for the non-php systems that decide to show the contents: