/**
* @license http://nucleuscms.org/license.txt GNU General Public License
* @copyright Copyright (C) 2002-2012 The Nucleus Group
- * @version $Id$
+ * @version $Id: index.php 1889 2012-06-17 08:46:45Z sakamocchi $
*/
/* global values initialize */
/* reporting all errors for support */
error_reporting(E_ALL);
-$minimum_php_version = '5.0.6';
-$minimum_mysql_version = '3.23';
+$minimum_php_version = '5.0.6';
+$minimum_mysql_version = '3.23';
-$page_footer_copyright = '© 2001-2012 The Nucleus Groupe . Running Nucleus CMS v4.00';
+$page_footer_copyright = '© 2001-2012 The Nucleus Groupe . Running Nucleus CMS v4.00';
// begin if: server's PHP version is below the minimum; halt installation
if ( version_compare(PHP_VERSION, $minimum_php_version, '<') )
{
- exit('<div style="font-size: xx-large;"> Nucleus requires at least PHP version '. $minimum_php_version .'</div>');
+ exit('<div style="font-size: xx-large;"> Nucleus requires at least PHP version ' . $minimum_php_version . '</div>');
}
// make sure there's no unnecessary escaping: # set_magic_quotes_runtime(0);
}
/* default installed plugins and skins */
-$aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles', 'NP_Text');
-$aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default');
+$aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles', 'NP_Medium');
+$aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default', 'admin/default', 'admin/bookmarklet');
// Check if some important files
do_check_files();
/* i18n class is needed for internationalization */
include_once('../nucleus/libs/i18n.php');
-if ( !i18n::init('UTF-8', './locales') )
+if ( !i18n::init('UTF-8', '../nucleus/locales') )
{
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>');
}
-// check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x
-if ( !function_exists('mysql_query') && !function_exists('mysqli_query') )
-{
- exit('<div style="font-size: xx-large;"> Your PHP version does not have support for MySQL :( </div>');
-}
-
// include core classes that are needed for login & plugin handling
-include_once('../nucleus/libs/mysql.php');
// added for 3.5 sql_* wrapper
global $MYSQL_HANDLER;
if ( !isset($MYSQL_HANDLER) )
{
$MYSQL_HANDLER = array('mysql', '');
+
+ // check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x
+ if ( !function_exists('mysql_query') && !function_exists('mysqli_query') )
+ {
+ exit('<div style="font-size: xx-large;"> Your PHP version does not have support for MySQL :( </div>');
+}
}
-include_once('../nucleus/libs/sql/' . $MYSQL_HANDLER[0] . '.php');
+include_once('../nucleus/libs/sql/sql.php');
session_start();
if ( count($_GET) == 0 && count($_POST) == 0 )
}
else
{
- $param = new PARAM_MANAGER();
+ $param = new ParamManager();
}
// include translation file
-if ( array_key_exists('locale', $_POST) ) $param->set_locale();
-i18n::set_current_locale($param->locale);
-$translation_file = './locales/' . i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php';
-if ( !file_exists($translation_file) )
-{
- $translation_file = './locales/en_Latn_US.UTF-8.php';
-}
-include($translation_file);
+$param->set_locale();
do_action();
}
exit;
-
/**
* installer action
*/
switch ( $param->state )
{
case 'locale':
- $param->set_locale();
$param->set_state('mysql');
$isPostback = false;
break;
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header('Content-Type: text/html; charset=' . i18n::get_current_charset());
-
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php echo _BODYFONTSTYLE; ?>
-->
</style>
+ <script type="text/javascript">
+ function SelectText( element ) {
+ window.setTimeout( function() { element.select() }, 0 );
+ }
+ var isSubmit = false;
+ function OnceSubmit() {
+ if (!isSubmit) {
+ isSubmit = true;
+ window.setTimeout( function() { isSubmit = false; }, 10000 );
+ return true;
+ }
+ return false;
+ }
+ </script>
</head>
<body>
<div id="header">
<div id="navigation">
<h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>
<ul>
- <?php
- if ( in_array($param->state, array('mysql', 'weblog', 'install')) )
- {
- echo '<li>', _STEP1, '</li><li';
- if ( $param->state == 'mysql' )
- {
- echo ' class="gry"';
- }
- echo '> > ', _STEP2, '</li><li';
- if ( in_array($param->state, array('mysql', 'weblog')) )
- {
- echo ' class="gry"';
- }
- echo '> > ', _STEP3, "</li>\n";
- }
- if ( in_array($param->state, array('mysql', 'weblog', 'detail')) )
- {
- echo '<li class="rightbox">';
- if ( in_array($param->state, array('mysql', 'weblog')) )
- {
- echo '<a href="./?mode=detail">', _MODE2, '</a>';
- }
- else
- {
- echo '<a href="./?mode=simple">', _MODE1, '</a>';
- }
- echo '</li>';
- }
- ?>
+<?php
+ echo '<li>';
+ $label = '_LOCALE_' . strtoupper($param->locale);
+ if ( !defined($label) )
+ {
+ echo $param->locale;
+ }
+ else
+ {
+ echo constant($label);
+ }
+ echo "</li>\n";
+
+ if ( in_array($param->state, array('mysql', 'weblog', 'install')) )
+ {
+ echo '<li> > ' . _STEP1, '</li><li';
+ if ( $param->state == 'mysql' )
+ {
+ echo ' class="gry"';
+ }
+ echo '> > ', _STEP2, '</li><li';
+ if ( in_array($param->state, array('mysql', 'weblog')) )
+ {
+ echo ' class="gry"';
+ }
+ echo '> > ', _STEP3, "</li>\n";
+ }
+ if ( in_array($param->state, array('mysql', 'weblog', 'detail')) )
+ {
+ echo '<li class="rightbox">';
+ if ( in_array($param->state, array('mysql', 'weblog')) )
+ {
+ echo '<a href="./?mode=detail">', _MODE2, '</a>';
+ }
+ else
+ {
+ echo '<a href="./?mode=simple">', _MODE1, '</a>';
+ }
+ echo '</li>';
+ }
+?>
</ul>
</div>
</div>
*/
function show_select_locale_form()
{
- // Get the browser language that can be displayed
- // TODO: default locale select simple implementation
- $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
- foreach ($languages as $language)
- {
- $language = preg_replace('#([\w]+).*#', '$1', $language);
- break;
- }
-
- $locales = array(
- array('en_Latn_US', 'English - United States'),
- array('ja_Jpan_JP', 'Japanese - Japan')
- );
+ global $param;
+
?>
<div id="container">
<p style="font-size:152%;font-weight:bold;">
- Select your locale:
+ <?php echo _LOCALE_HEADER; ?>
</p>
<form method="post" action="./index.php">
<div class="prt">
<select name="locale">
<?php
+ $locales = i18n::get_available_locale_list();
foreach ( $locales as $locale )
{
- echo "<option value=\"$locale[0]\"";
- if ( i18n::strpos($locale[0], $language) === 0 )
+ if ( $param->locale != $locale )
+ {
+ echo "<option value=\"{$locale}\">";
+ }
+ else
+ {
+ echo "<option value=\"{$locale}\" selected=\"selected\">";
+ }
+
+ $checkfile = "./locales/{$locale}." . i18n::get_current_charset() . '.php';
+ if ( !file_exists($checkfile) )
+ {
+ echo '* ';
+ }
+
+ $label = '_LOCALE_' . strtoupper($locale);
+ if ( !defined($label) )
+ {
+ echo $locale;
+ }
+ else
{
- echo ' selected';
+ echo constant($label);
}
- echo ">$locale[1]</option>\n";
+ echo "</option>\n";
}
?>
</select>
+ <p><?php echo _LOCALE_DESC1; ?></p>
+ <p><?php echo _LOCALE_DESC2; ?></p>
+ <p><?php echo _LOCALE_NEED_HELP;?></p>
<p class="sbt">
<button type="submit" name="action" value="locale" class="sbt_arw">START</button>
</p>
$config_writable = canConfigFileWritable();
$mysql_version = getMySqlVersion();
- ?>
+?>
<div id="container">
<p class="msg">
<?php
}
if ( $mysql_version == '0.0.0' )
{
- echo '<span class="err">', _ERROR21, '</span>';
+ echo '<span class="err">', _DBVERSION_UNKOWN, '</span>';
}
elseif ( version_compare($mysql_version, $minimum_mysql_version, '<') )
{
- echo '<span class="err">', sprintf(_ERROR20 , $minimum_mysql_version), '</span>';
+ echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';
}
?>
</p>
<td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>
</tr>
<tr>
- <th><span class="nam"><?php echo _DB_FIELD3; ?></span><span class="sub"><?php echo _DB_FIELD3_DESC; ?></span></th>
+ <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>
<td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>
</tr>
<tr>
function show_blog_setting_form($isPostback)
{
global $param;
-
?>
<div id="container">
<p class="msg">
<td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>
</tr>
<tr>
- <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span><span class="sub"><?php echo _ADMIN_FIELD3_DESC; ?></span></th>
+ <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>
<td><input type="password" name="user_password" /></td>
</tr>
<tr>
- <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span><span class="sub"><?php echo _ADMIN_FIELD4_DESC; ?></span></th>
+ <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>
<td><input type="password" name="user_password2" /></td>
</tr>
<tr>
</tr>
</table>
<p class="sbt">
- <button type="submit" name="action" value="weblog" class="sbt_arw"><?php echo _INSTALL; ?></button>
+ <button type="submit" name="action" value="weblog" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>
</p>
</div>
</form>
<?php
if ( $isPostback && !$param->check_all_parameters() )
{
- echo '<span class="err">', _ERROR26, "</span>\n";
+ echo '<span class="err">', _VALID_ERROR, "</span>\n";
}
?>
</p>
<li>PHP: <?php echo phpversion(); ?></li>
<li>MySQL:
<?php
- echo ($mysql_version == '0.0.0') ? _ERROR21 : $mysql_version;
+ echo ($mysql_version == '0.0.0') ? _DBVERSION_UNKOWN : $mysql_version;
if ( version_compare($mysql_version, $minimum_mysql_version, '<') )
{
- echo '<span class="err">', sprintf(_ERROR20 , $minimum_mysql_version), '</span>';
+ echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';
}
?></li>
</ul>
<td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>
</tr>
<tr>
- <th><span class="nam"><?php echo _DB_FIELD3; ?></span><span class="sub"><?php echo _DB_FIELD3_DESC; ?></span></th>
+ <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>
<td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>
</tr>
<tr>
<td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>
</tr>
<tr>
- <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span><span class="sub"><?php echo _ADMIN_FIELD3_DESC; ?></span></th>
+ <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>
<td><input type="password" name="user_password" /></td>
</tr>
<tr>
- <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span><span class="sub"><?php echo _ADMIN_FIELD4_DESC; ?></span></th>
+ <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>
<td><input type="password" name="user_password2" /></td>
</tr>
<tr>
</p>
<p class="sbt">
- <button type="submit" name="action" value="detail" class="sbt_arw"><?php echo _INSTALL; ?></button>
+ <button type="submit" name="action" value="detail" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>
</p>
</div>
</form>
<?php
if ( is_array($errors) && count($errors) > 0 )
{
- echo _ERROR27;
+ echo _INST_ERROR;
foreach ( $errors as $error )
{
echo '<span class="err">', $error, "</span>\n";
if ( array_key_exists('config_data', $_SESSION) )
{
echo '<span class="err">', _INST_TEXT4, '</span>';
- // FIXME: textareaにしてJavascriptでコピーできたらいい?
?>
-<pre><code><?php echo htmlentities($_SESSION['config_data'], null, i18n::get_current_charset() ) ?></code></pre>
+<textarea id="config_text" readonly="readonly" onfocus="SelectText(this);"><?php echo htmlentities($_SESSION['config_data'], null, i18n::get_current_charset()) ?></textarea>
<?php
}
else
function do_install()
{
global $param;
- global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX, $MYSQL_CONN;
+ global $MYSQL_HANDLER, $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX, $MYSQL_CONN;
global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;
$errors = array();
/*
* 1. put all param-vars into vars
*/
- $MYSQL_HOST = $param->mysql_host;
- $MYSQL_USER = $param->mysql_user;
- $MYSQL_PASSWORD = $param->mysql_password;
- $MYSQL_DATABASE = $param->mysql_database;
- $MYSQL_PREFIX = $param->mysql_tablePrefix;
-
- $DIR_NUCLEUS = $param->AdminPath;
- $DIR_MEDIA = $param->MediaPath;
- $DIR_SKINS = $param->SkinsPath;
- $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
- $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
- $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
+ $MYSQL_HOST = $param->mysql_host;
+ $MYSQL_USER = $param->mysql_user;
+ $MYSQL_PASSWORD = $param->mysql_password;
+ $MYSQL_DATABASE = $param->mysql_database;
+ $MYSQL_PREFIX = $param->mysql_tablePrefix;
+
+ $DIR_NUCLEUS = $param->AdminPath;
+ $DIR_MEDIA = $param->MediaPath;
+ $DIR_SKINS = $param->SkinsPath;
+ $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
+ $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
+ $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
/*
* 2.open mySQL connection
*/
- $MYSQL_CONN = @sql_connect_args($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
- if ( $MYSQL_CONN == false )
+ $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
+ if ( $MYSQL_CONN == FALSE )
{
- $errors[] = _ERROR3;
+ $errors[] = _DBCONNECT_ERROR;
return $errors;
}
/*
* 3. try to create database if needed
*/
- if ( !sql_query('CREATE DATABASE IF NOT EXISTS `' . $MYSQL_DATABASE . '`') )
+ if ( DB::execute("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") === FALSE )
{
- $errors[] = _ERROR12 . ': ' . sql_error();
+ $errinfo = DB::getError();
+ $errors[] = _INST_ERROR1 . ': ' . $errinfo[2];
}
/*
* 4. try to select database
*/
- if ( !sql_select_db($MYSQL_DATABASE) )
+ $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE);
+ if ( !$MYSQL_CONN )
{
- $errors[] = _ERROR13;
+ $errors[] = _INST_ERROR2;
}
- sql_set_charset('utf8');
if ( count($errors) > 0 )
{
}
// table exists check
- $result = sql_query('SHOW TABLES');
- while ($row = mysql_fetch_array($result, MYSQL_NUM))
+ $result = DB::getResult('SHOW TABLES');
+ foreach ( $result as $row )
{
if ( in_array($row[0], $prefixed_table_names) )
{
- $errors[] = _ERROR14;
+ $errors[] = _INST_ERROR3;
break;
}
}
$filename = 'install.sql';
$fd = fopen($filename, 'r');
- $queries = fread($fd, filesize($filename) );
+ $queries = fread($fd, filesize($filename));
fclose($fd);
$queries = preg_split('#(;\n|;\r)#', $queries);
$query = str_replace($table_names, $prefixed_table_names, $query);
}
- if ( !sql_query($query) )
+ if ( DB::execute($query) === FALSE )
{
- $errors[] = _ERROR15 . ' (<small>' . $query . '</small>): ' . sql_error();
+ $errinfo = DB::getError();
+ $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . $errinfo[2];
}
}
}
* 6. put needed records
*/
/* push first post */
- $query = "INSERT INTO %s VALUES (1, '%s', '%s', '%s', 1, 1, '%s', 0, 0, 0, 1, 0, 1)";
- $query = sprintf($query, tableName('nucleus_item'), _1ST_POST_TITLE, _1ST_POST, _1ST_POST2, i18n::formatted_datetime('mysql', time()));
- if ( !sql_query($query) )
+ $query = "INSERT INTO %s VALUES (1, %s, %s, %s, 1, 1, %s, 0, 0, 0, 1, 0, 1)";
+ $query = sprintf($query,
+ tableName('nucleus_item'),
+ DB::quoteValue(_1ST_POST_TITLE),
+ DB::quoteValue(_1ST_POST),
+ DB::quoteValue(_1ST_POST2),
+ DB::formatDateTime()
+ );
+ if ( DB::execute($query) === FALSE )
{
- $errors[] = _ERROR15 . ' (<small>' . $newpost . '</small>): ' . sql_error();
+ $errinfo = DB::getError();
+ $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . $errinfo[2];
}
/* push configurations */
array_merge($errors, updateConfig('SiteName', $param->blog_name));
array_merge($errors, updateConfig('Locale', i18n::get_current_locale()));
- /* escape strings for SQL */
- $user_name = sql_real_escape_string($param->user_name);
- $user_realname = sql_real_escape_string($param->user_realname);
- $user_password = sql_real_escape_string(md5($param->user_password));
- $user_email = sql_real_escape_string($param->user_email);
- $blog_name = sql_real_escape_string($param->blog_name);
- $blog_shortname = sql_real_escape_string($param->blog_shortname);
- $config_indexurl = sql_real_escape_string($param->IndexURL);
-
/* push super admin */
- $query = "UPDATE %s SET mname = '%s', mrealname = '%s', mpassword = '%s', memail = '%s', murl = '%s', madmin = 1, mcanlogin = 1 WHERE mnumber = 1";
- $query = sprintf($query, tableName('nucleus_member'), $user_name, $user_realname, $user_password, $user_email, $config_indexurl);
- if ( !sql_query($query) )
+ $query = "UPDATE %s SET mname = %s, mrealname = %s, mpassword = %s, memail = %s, murl = %s, madmin = 1, mcanlogin = 1 WHERE mnumber = 1";
+ $query = sprintf($query,
+ tableName('nucleus_member'),
+ DB::quoteValue($param->user_name),
+ DB::quoteValue($param->user_realname),
+ DB::quoteValue(md5($param->user_password)),
+ DB::quoteValue($param->user_email),
+ DB::quoteValue($param->IndexURL)
+ );
+ if ( DB::execute($query) === FALSE )
{
- $errors[] = _ERROR16 . ': ' . sql_error();
+ $errinfo = DB::getError();
+ $errors[] = _INST_ERROR5 . ': ' . $errinfo[2];
}
/* push new weblog */
- $query = "UPDATE %s SET bname = '%s', bshortname = '%s', burl = '%s' WHERE bnumber = 1";
- $query = sprintf($query, tableName('nucleus_blog'), $blog_name, $blog_shortname, $config_indexurl);
- if ( !sql_query($query) )
+ $query = "UPDATE %s SET bname = %s, bshortname = %s, burl = %s WHERE bnumber = 1";
+ $query = sprintf($query,
+ tableName('nucleus_blog'),
+ DB::quoteValue($param->blog_name),
+ DB::quoteValue($param->blog_shortname),
+ DB::quoteValue($param->IndexURL)
+ );
+ if ( DB::execute($query) === FALSE )
{
- $errors[] = _ERROR17 . ': ' . sql_error();
+ $errinfo = DB::getError();
+ $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];
}
/* push default category */
- $query = "UPDATE %s SET cname = '%s', cdesc = '%s' WHERE catid = 1";
- $query = sprintf($query, tableName('nucleus_category'), _GENERALCAT_NAME, _GENERALCAT_DESC);
- if ( !sql_query($query) )
+ $query = "UPDATE %s SET cname = %s, cdesc = %s WHERE catid = 1";
+ $query = sprintf($query,
+ tableName('nucleus_category'),
+ DB::quoteValue(_GENERALCAT_NAME),
+ DB::quoteValue(_GENERALCAT_DESC)
+ );
+ if ( DB::execute($query) === FALSE )
{
- $errors[] = _ERROR17 . ': ' . sql_error();
+ $errinfo = DB::getError();
+ $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];
}
- sql_close();
-
/*
* 7. install default plugins and skins
*/
global $manager;
if ( !isset($manager) )
{
- $manager = new MANAGER;
+ $manager = new Manager();
}
+ include_once($DIR_LIBS . 'skinie.php');
+
$aSkinErrors = installCustomSkins();
if ( count($aSkinErrors) > 0 )
{
array_merge($errors, $aSkinErrors);
}
- $query = "SELECT sdnumber FROM %s WHERE sdname='default'";
- $query = sprintf($query, tableName('nucleus_skin_desc'));
- $res = sql_query($query);
- $obj = sql_fetch_assoc($res);
- $defSkinID = (integer) $obj['sdnumber'];
+ $query = "SELECT sdnumber FROM %s WHERE sdname='admin/default'";
+ $query = sprintf($query, tableName('nucleus_skin_desc'));
+ $res = intval(DB::getValue($query));
+ array_merge($errors, updateConfig('AdminSkin', $res));
+
+ $query = "SELECT sdnumber FROM %s WHERE sdname='admin/bookmarklet'";
+ $query = sprintf($query, tableName('nucleus_skin_desc'));
+ $res = intval(DB::getValue($query));
+ array_merge($errors, updateConfig('BookmarkletSkin', $res));
+
+ $query = "SELECT sdnumber FROM %s WHERE sdname='default'";
+ $query = sprintf($query, tableName('nucleus_skin_desc'));
+ $defSkinID = intval(DB::getValue($query));
$query = "UPDATE %s SET bdefskin=%d WHERE bnumber=1";
$query = sprintf($query, tableName('nucleus_blog'), $defSkinID);
- sql_query($query);
+ DB::execute($query);
$query = "UPDATE %s SET value=%d WHERE name='BaseSkin'";
$query = sprintf($query, tableName('nucleus_config'), $defSkinID);
- sql_query($query);
+ DB::execute($query);
- $aPlugErrors = installCustomPlugs($manager);
+ $aPlugErrors = installCustomPlugs();
if ( count($aPlugErrors) > 0 )
{
array_merge($errors, $aPlugErrors);
$config_data .= "// default is \$MYSQL_HANDLER = array('mysql','mysql');\n";
$config_data .= "//\$MYSQL_HANDLER = array('mysql','mysql');\n";
$config_data .= "//\$MYSQL_HANDLER = array('pdo','mysql');\n";
- $config_data .= "\$MYSQL_HANDLER = array('".$MYSQL_HANDLER[0]."','".$MYSQL_HANDLER[1]."');\n";
+ $config_data .= "\$MYSQL_HANDLER = array('" . $MYSQL_HANDLER[0] . "','" . $MYSQL_HANDLER[1] . "');\n";
$config_data .= "\n";
$config_data .= "// main nucleus directory\n";
$config_data .= "\$DIR_NUCLEUS = '" . $DIR_NUCLEUS . "';\n";
{
if ( $fp = @fopen('../config.php', 'w') )
{
- $result = @fwrite($fp, $config_data, i18n::strlen($config_data) );
+ $result = @fwrite($fp, $config_data, i18n::strlen($config_data));
fclose($fp);
}
}
if ( $result )
{
// try to change the read-only permission.
- if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
+ if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
{
@chmod('../config.php', 0444);
}
if ( @file_exists('../config.php') && @!is_writable('../config.php') )
{
// try to change the read-write permission.
- if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
+ if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
{
@chmod('../config.php', 0666);
}
if ( @!is_writable('../config.php') )
{
- return _ERROR19;
+ return _INST_ERROR8;
}
}
return '';
*/
function getMySqlVersion()
{
- global $minimum_mysql_version, $errors;
+ global $MYSQL_HANDLER, $minimum_mysql_version, $errors;
// Turn on output buffer
// Needed to repress the output of the sql function that are
// not part of php (in this case the @ operator doesn't work)
ob_start();
// note: this piece of code is taken from phpMyAdmin
- $conn = sql_connect_args('localhost', '', '');
- $result = @sql_query('SELECT VERSION() AS version', $conn);
+ $conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], 'localhost', '', '');
- if ( $result != FALSE && sql_num_rows($result) > 0 )
+ if ( $conn )
{
- $row = sql_fetch_array($result);
- $match = i18n::explode('.', $row['version']);
+ $row = DB::getAttribute(PDO::ATTR_SERVER_VERSION);
+ $match = preg_split('#\.#', $row);
}
else
{
- $result = @sql_query('SHOW VARIABLES LIKE \'version\'', $conn);
+ $row = @DB::getRow('SHOW VARIABLES LIKE \'version\'');
- if ( $result != FALSE && @sql_num_rows($result) > 0 )
+ if ( $row )
{
- $row = sql_fetch_row($result);
- $match = i18n::explode('.', $row[1]);
+ $match = preg_split('#\.#', $row[1]);
}
else
{
- //$output = shell_exec('mysql -V');
- $output = ( function_exists('shell_exec') ) ? @shell_exec('mysql -V') : '0.0.0';
+ $output = (function_exists('shell_exec')) ? @shell_exec('mysql -V') : '0.0.0';
preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
- $match = i18n::explode('.', $version[0]);
+ $match = preg_split('#\.#', $version[0]);
if ( $match[0] == '' )
{
}
}
- @sql_disconnect($conn);
+ @DB::disConnect();
//End and clean output buffer
ob_end_clean();
/**
* Install custom plugins
- *
- * @param object $manager MANAGER class instance
*/
-function installCustomPlugs($manager)
+function installCustomPlugs()
{
- global $aConfPlugsToInstall, $DIR_LIBS;
+ global $aConfPlugsToInstall, $DIR_LIBS, $manager;
$aErrors = array();
if ( count($aConfPlugsToInstall) == 0 )
return $aErrors;
}
- $res = sql_query('SELECT * FROM ' . tableName('nucleus_plugin') );
- $numCurrent = sql_num_rows($res);
+ $query = sprintf('SELECT * FROM %s', tableName('nucleus_plugin'));
+ $res = DB::getResult($query);
+ $numCurrent = $res->rowCount();
foreach ( $aConfPlugsToInstall as $plugName )
{
- $query = 'INSERT INTO ' . tableName('nucleus_plugin') . ' (porder, pfile) VALUES (' . (++$numCurrent) . ", '" . sql_real_escape_string($plugName) . "')";
- sql_query($query);
+ $query = sprintf('INSERT INTO %s (porder, pfile) VALUES (%d, %s)',
+ tableName('nucleus_plugin'),
+ (++$numCurrent),
+ DB::quoteValue($plugName));
+ DB::execute($query);
$manager->clearCachedInfo('installedPlugins');
$plugin =& $manager->getPlugin($plugName);
if ( !$plugin )
{
- sql_query('DELETE FROM ' . tableName('nucleus_plugin') . " WHERE pfile = '" . sql_real_escape_string($plugName) . "'");
+ $query = sprintf('DELETE FROM %s WHERE pfile = %s',
+ tableName('nucleus_plugin'),
+ DB::quoteValue($plugName));
+ DB::execute($query);
$numCurrent--;
- array_push($aErrors, sprintf(_ERROR22 ,$plugName));
+ array_push($aErrors, sprintf(_INST_ERROR9, $plugName));
continue;
}
$plugin->install();
}
- sql_query('DELETE FROM ' . tableName('nucleus_plugin_event') );
- $res = sql_query('SELECT pid, pfile FROM ' . tableName('nucleus_plugin') );
+ $query = sprintf('DELETE FROM %s', tableName('nucleus_plugin_event'));
+ DB::execute($query);
+ $query = sprintf('SELECT pid, pfile FROM %s', tableName('nucleus_plugin'));
+ $res = DB::getResult($query);
- while ( $o = sql_fetch_object($res) )
+ foreach ( $res as $row )
{
- $pid = $o->pid;
- $plug =& $manager->getPlugin($o->pfile);
+ $plug =& $manager->getPlugin($row['pfile']);
if ( $plug )
{
$eventList = $plug->getEventList();
foreach ( $eventList as $eventName )
{
- sql_query('INSERT INTO ' . tableName('nucleus_plugin_event') . ' (pid, event) VALUES (' . $pid . ", '" . $eventName . "')");
+ $query = sprintf('INSERT INTO %s (pid, event) VALUES (%d, %s)',
+ tableName('nucleus_plugin_event'),
+ intval($row['pid']),
+ DB::quoteValue($eventName));
+ DB::execute($query);
}
}
}
return $aErrors;
}
- include_once($DIR_LIBS . 'skinie.php');
- $importer = new SKINIMPORT();
+ $importer = new SkinImport();
foreach ( $aConfSkinsToImport as $skinName )
{
if ( !@file_exists($skinFile) )
{
- array_push($aErrors, sprintf(_ERROR23, $skinFile));
+ array_push($aErrors, sprintf(_INST_ERROR10, $skinFile));
continue;
}
if ( $error )
{
- array_push($aErrors, sprintf(_ERROR24, $skinName) . ' : ' . $error);
+ array_push($aErrors, sprintf(_INST_ERROR11, $skinName) . ' : ' . $error);
continue;
}
if ( $error )
{
- array_push($aErrors, sprintf(_ERROR25, $skinName) . ' : ' . $error);
+ array_push($aErrors, sprintf(_INST_ERROR12, $skinName) . ' : ' . $error);
continue;
}
}
return $aErrors;
}
-
/**
* Check if some important files of the Nucleus CMS installation are available
* Give an error if one or more files are not accessible
'../index.php',
'../action.php',
'../nucleus/index.php',
- '../nucleus/media.php',
'../nucleus/libs/ACTION.php',
'../nucleus/libs/ACTIONLOG.php',
'../nucleus/libs/ACTIONS.php',
'../nucleus/libs/COMMENT.php',
'../nucleus/libs/COMMENTACTIONS.php',
'../nucleus/libs/COMMENTS.php',
- '../nucleus/libs/ENCAPSULATE.php',
'../nucleus/libs/ENTITY.php',
'../nucleus/libs/globalfunctions.php',
'../nucleus/libs/i18n.php',
'../nucleus/libs/MANAGER.php',
'../nucleus/libs/MEDIA.php',
'../nucleus/libs/MEMBER.php',
- '../nucleus/libs/mysql.php',
'../nucleus/libs/NOTIFICATION.php',
- '../nucleus/libs/PAGEFACTORY.php',
'../nucleus/libs/PARSER.php',
'../nucleus/libs/PLUGIN.php',
'../nucleus/libs/PLUGINADMIN.php',
'../nucleus/libs/vars4.1.0.php',
'../nucleus/libs/xmlrpc.inc.php',
'../nucleus/libs/xmlrpcs.inc.php',
- '../nucleus/libs/sql/mysql.php'
+ '../nucleus/libs/sql/DB.php',
+ '../nucleus/libs/sql/MYSQLPDO.php'
);
$count = count($files);
{
if ( !is_readable($files[$i]) )
{
- array_push( $missingfiles, 'File <b>' . $files[$i] . '</b> is missing or not readable.<br />');
+ array_push($missingfiles, 'File <b>' . $files[$i] . '</b> is missing or not readable.<br />');
}
}
if ( count($missingfiles) > 0 )
{
- exit(implode( "\n", $missingfiles));
+ exit(implode("\n", $missingfiles));
}
}
-
/**
* Updates the configuration in the database
*
function updateConfig($name, $value)
{
$errors = array();
- $name = sql_real_escape_string($name);
- $value = trim(sql_real_escape_string($value) );
- $query = "UPDATE %s SET value = '%s' WHERE name = '%s'";
- $query = sprintf($query, tableName('nucleus_config'), $value, $name);
+ $query = "UPDATE %s SET value = %s WHERE name = %s";
+ $query = sprintf($query, tableName('nucleus_config'), DB::quoteValue(trim($value)), DB::quoteValue($name));
- if ( !sql_query($query) )
+ if ( DB::execute($query) === FALSE )
{
- $errors[] = _ERROR15 . ': ' . sql_error();
+ $errinfo = DB::getError();
+ $errors[] = _INST_ERROR4 . ': ' . $errinfo[2];
}
return $errors;
}
-
-class PARAM_MANAGER
+class ParamManager
{
/* process parameter */
public $state;
// set default values
$this->state = 'locale';
$this->install_mode = 'simple';
- $this->locale = 'en_Latn_US';
+ $this->locale = '';
$this->mysql_host = @ini_get('mysql.default_host');
$this->blog_name = 'My Nucleus CMS';
$this->blog_shortname = 'mynucleuscms';
/* root path */
- $this->root_path = realpath(dirname(__FILE__) . '/..');
+ $directory_separator = preg_quote(DIRECTORY_SEPARATOR, '|');
+ $this->root_path = implode('/', preg_split("|$directory_separator|", realpath(dirname(__FILE__) . '/..')));
if ( substr($this->root_path, -1, 1) !== '/' )
{
$this->root_path .= '/';
}
- $base_path_pcre = preg_quote($this->root_path, '#');
+ $base_path_pcre = preg_quote($this->root_path, '|');
/* current directry name */
- $directory_name = preg_replace("#$base_path_pcre#", '', dirname(__FILE__));
- $directory_name_pcre = preg_quote($directory_name, '#');
+ $directory_name = preg_replace("#{$base_path_pcre}#", '', implode('/', preg_split("#{$directory_separator}#", realpath(dirname(__FILE__)))));
+ $directory_name_pcre = preg_quote($directory_name, '|');
/* root uri */
$root_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
- $this->root_url = preg_replace("#$directory_name_pcre(.*)$#", '', $root_url);
+ $this->root_url = preg_replace("|$directory_name_pcre(.*)$|", '', $root_url);
- $this->AdminPath = $this->root_path . 'nucleus' . DIRECTORY_SEPARATOR;
- $this->MediaPath = $this->root_path . 'media' . DIRECTORY_SEPARATOR;
- $this->SkinsPath = $this->root_path . 'skins' . DIRECTORY_SEPARATOR;
+ $this->AdminPath = $this->root_path . 'nucleus/';
+ $this->MediaPath = $this->root_path . 'media/';
+ $this->SkinsPath = $this->root_path . 'skins/';
$this->IndexURL = $this->root_url;
$this->AdminURL = $this->root_url . 'nucleus/';
{
$this->read_parameter(array('locale'));
- if ( !in_array($this->locale, i18n::get_available_locale_list()) )
+ if ( !$this->locale )
{
- $this->locale = 'en_Latn_US';
+ /**
+ * default locale select simple implementation
+ *
+ * NOTE:
+ * RFC2616: Hypertext Transfer Protocol -- HTTP/1.1
+ * http://www.ietf.org/rfc/rfc2616.txt
+ *
+ * 14.4 Accept-Language
+ *
+ * The Accept-Language request-header field is similar to Accept, but
+ * restricts the set of natural languages that are preferred as a
+ * response to the request. Language tags are defined in section 3.10.
+ *
+ * Accept-Language = "Accept-Language" ":"
+ * 1#( language-range [ ";" "q" "=" qvalue ] )
+ * language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
+ *
+ * Each language-range MAY be given an associated quality value which
+ * represents an estimate of the user's preference for the languages
+ * specified by that range. The quality value defaults to "q=1". For
+ * example,
+ *
+ * Accept-Language: da, en-gb;q=0.8, en;q=0.7
+ *
+ * would mean: "I prefer Danish, but will accept British English and
+ * other types of English." A language-range matches a language-tag if
+ * it exactly equals the tag, or if it exactly equals a prefix of the
+ * tag such that the first tag character following the prefix is "-".
+ * The special range "*", if present in the Accept-Language field,
+ * matches every tag not matched by any other range present in the
+ * Accept-Language field.
+ *
+ * TODO: this is appropriate implement or not
+ */
+ $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+
+ /* retrieve language token of language tag from first token */
+ $language = '';
+ if ( is_array($languages) && count($languages) > 0 )
+ {
+ $language = preg_replace('#^([\w]+).*$#', '$1', $languages[0]);
+ }
+
+ $locales = i18n::get_available_locale_list();
+ foreach ( $locales as $locale )
+ {
+ if ( i18n::strpos($locale, $language) === 0 )
+ {
+ $this->locale = $locale;
+ break;
+ }
+ }
}
+
+ /* include installer translation messages */
+ $translation_file = "./locales/{$this->locale}." . i18n::get_current_charset() . '.php';
+ if ( !file_exists($translation_file) )
+ {
+ $translation_file = './locales/en_Latn_US.UTF-8.php';
+ }
+ include($translation_file);
+
+ /* include global translation messages */
+ $translation_file = "../nucleus/locales/{$this->locale}." . i18n::get_current_charset() . '.php';
+ if ( !file_exists($translation_file) )
+ {
+ $translation_file = './locales/en_Latn_US.UTF-8.php';
+ }
+ include($translation_file);
+
+ i18n::set_current_locale($this->locale);
+
+ return;
}
public function check_mysql_parameters()
{
+ global $MYSQL_HANDLER;
+
$parameters = array('mysql_host', 'mysql_user', 'mysql_password', 'mysql_database', 'mysql_tablePrefix');
$this->read_parameter($parameters);
$errors = array();
if ( $this->mysql_host == '' )
{
- $errors[] = sprintf(_ERROR1, _DB_FIELD1);
+ $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD1);
}
if ( $this->mysql_user == '' )
{
- $errors[] = sprintf(_ERROR1, _DB_FIELD2);
+ $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD2);
}
if ( $this->mysql_user != ''
- && !preg_match('/^[[:alnum:]_-]+$/i', $this->mysql_user) )
+ && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_user) )
{
- $errors[] = sprintf(_ERROR2, _DB_FIELD2);
+ $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD2);
}
- if ( $this->mysql_password == '' )
- {
- $errors[] = sprintf(_ERROR1, _DB_FIELD3);
- }
-
if ( $this->mysql_database == '' )
{
- $errors[] = sprintf(_ERROR1, _DB_FIELD4);
+ $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD4);
}
if ( $this->mysql_database != ''
- && !preg_match('/^[[:alnum:]_-]+$/i', $this->mysql_database) )
+ && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_database) )
{
- $errors[] = sprintf(_ERROR2, _DB_FIELD4);
+ $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD4);
}
if ( $this->mysql_tablePrefix != ''
- && !preg_match('/^[[:alnum:]_-]+$/i', $this->mysql_tablePrefix) )
+ && !preg_match('/^[a-z0-9_]+$/i', $this->mysql_tablePrefix) )
{
- $errors[] = sprintf(_ERROR2, _DB_FIELD5);
+ $errors[] = sprintf(_VALID_ERROR3, _DB_FIELD5);
}
if ( count($errors) == 0 )
{
- $mysql_conn = @sql_connect_args($this->mysql_host, $this->mysql_user, $this->mysql_password);
+ $mysql_conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], $this->mysql_host, $this->mysql_user, $this->mysql_password);
if ( $mysql_conn == false )
{
- $errors[] = _ERROR3;
+ $errors[] = _DBCONNECT_ERROR;
}
else
{
- @sql_close($mysql_conn);
+ @DB::disConnect();
}
}
$this->read_parameter($parameters);
$errors = array();
- if ( $this->user_name == '' )
+ if ( $this->user_realname == '' )
{
- $errors[] = sprintf(_ERROR1, _ADMIN_FIELD2);
+ $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD1);
}
- elseif ( !preg_match("/^[[:alnum:]]+([ [:alnum:]]*[[:alnum:]]+)?$/i", $this->user_name) )
+
+ if ( $this->user_name == '' )
{
- $errors[] = _ERROR5;
+ $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD2);
}
-
- if ( $this->user_realname == '' )
+ elseif ( !preg_match("/^[a-z0-9]+([ a-z0-9]*[a-z0-9]+)?$/i", $this->user_name) )
{
- $errors[] = sprintf(_ERROR1, _ADMIN_FIELD1);
+ $errors[] = _VALID_ERROR5;
}
if ( $this->user_password == '' || $this->user_password2 == '' )
{
- $errors[] = sprintf(_ERROR1, _ADMIN_FIELD3);
+ $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD3);
$this->user_password = '';
}
elseif ( $this->user_password != $this->user_password2 )
{
- $errors[] = _ERROR6;
+ $errors[] = _VALID_ERROR6;
$this->user_password = '';
}
- if ( !preg_match("/^[\w\.-]+@[\w\.-]+\.[[:alpha:]]{2,6}$/", $this->user_email) )
+ if ( !preg_match("/^[a-z0-9\._+\-]+@[a-z0-9\._\-]+\.[a-z]{2,6}$/i", $this->user_email) )
{
- $errors[] = _ERROR7;
+ $errors[] = _VALID_ERROR7;
}
return $errors;
$errors = array();
if ( $this->blog_name == '' )
{
- $errors[] = sprintf(_ERROR1, _BLOG_FIELD1);
+ $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD1);
}
if ( $this->blog_shortname == '' )
{
- $errors[] = sprintf(_ERROR1, _BLOG_FIELD2);
+ $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD2);
}
- if ( !preg_match("/^[a-z0-9]+$/", $this->blog_shortname) )
+ if ( !preg_match("/^[a-z0-9]+$/i", $this->blog_shortname) )
{
- $errors[] = _ERROR4;
+ $errors[] = _VALID_ERROR4;
}
return $errors;
$errors = array();
if ( substr($this->IndexURL, -1, 1) !== '/' )
{
- $errors[] = sprintf(_ERROR8, _PATH_FIELD1);
+ $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD1);
}
if ( substr($this->AdminURL, -1, 1) !== '/' )
{
- $errors[] = sprintf(_ERROR8, _PATH_FIELD2);
+ $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD2);
}
if ( substr($this->MediaURL, -1, 1) !== '/' )
{
- $errors[] = sprintf(_ERROR8, _PATH_FIELD4);
+ $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD4);
}
if ( substr($this->SkinsURL, -1, 1) !== '/' )
{
- $errors[] = sprintf(_ERROR8, _PATH_FIELD6);
+ $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD6);
}
if ( substr($this->PluginURL, -1, 1) !== '/' )
{
- $errors[] = sprintf(_ERROR8, _PATH_FIELD8);
+ $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD8);
}
if ( strrchr($this->ActionURL, '/') != '/action.php' )
{
- $errors[] = sprintf(_ERROR9, _PATH_FIELD9);
+ $errors[] = sprintf(_VALID_ERROR9, _PATH_FIELD9);
}
return $errors;
$separators = array('/', DIRECTORY_SEPARATOR);
$errors = array();
- if ( !in_array(substr($this->AdminPath, -1, 1), $separators) || !file_exists($this->AdminPath) )
+ if ( !in_array(substr($this->AdminPath, -1, 1), $separators) )
{
- $errors[] = sprintf(_ERROR10, _PATH_FIELD3);
+ $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD3);
+ }
+ elseif ( !file_exists($this->AdminPath) )
+ {
+ $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD3);
}
- if ( !in_array(substr($this->MediaPath, -1, 1), $separators) || !file_exists($this->MediaPath) )
+ if ( !in_array(substr($this->MediaPath, -1, 1), $separators) )
+ {
+ $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD5);
+ }
+ elseif ( !file_exists($this->MediaPath) )
{
- $errors[] = sprintf(_ERROR10, _PATH_FIELD5);
+ $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD5);
}
- if ( !in_array(substr($this->SkinsPath, -1, 1), $separators) || !file_exists($this->SkinsPath) )
+ if ( !in_array(substr($this->SkinsPath, -1, 1), $separators) )
+ {
+ $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD7);
+ }
+ elseif ( !file_exists($this->SkinsPath) )
{
- $errors[] = sprintf(_ERROR10, _PATH_FIELD7);
+ $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD7);
}
return $errors;