OSDN Git Service

ADD: プラグイン「NP_Medium」
[nucleus-jp/nucleus-next.git] / install / index.php
index 10754db..01f0d0a 100644 (file)
@@ -16,7 +16,7 @@
 /**\r
  * @license http://nucleuscms.org/license.txt GNU General Public License\r
  * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
- * @version $Id: index.php 1745 2012-04-12 23:45:47Z sakamocchi $
+ * @version $Id: index.php 1745 2012-04-12 23:45:47Z sakamocchi $\r
  */\r
 \r
 /* global values initialize */\r
@@ -43,27 +43,20 @@ if ( version_compare(PHP_VERSION, '5.3.0', '<') )
 }\r
 \r
 /* default installed plugins and skins */\r
-$aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles', 'NP_Text');\r
-$aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default', 'defaultadmin');\r
+$aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles', 'NP_Medium');\r
+$aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default', 'admin/default', 'admin/bookmarklet');\r
 \r
 // Check if some important files\r
 do_check_files();\r
 \r
 /* i18n class is needed for internationalization */\r
 include_once('../nucleus/libs/i18n.php');\r
-if ( !i18n::init('UTF-8', './locales') )\r
+if ( !i18n::init('UTF-8', '../nucleus/locales') )\r
 {\r
        exit('<div style="font-size: xx-large;"> Failed to initialize iconv or mbstring extension. Would you please contact the administrator of your PHP server? </div>');\r
 }\r
 \r
-// check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x\r
-if ( !function_exists('mysql_query') && !function_exists('mysqli_query') )\r
-{\r
-       exit('<div style="font-size: xx-large;"> Your PHP version does not have support for MySQL :( </div>');\r
-}\r
-\r
 // include core classes that are needed for login & plugin handling\r
-include_once('../nucleus/libs/mysql.php');\r
 \r
 // added for 3.5 sql_* wrapper\r
 global $MYSQL_HANDLER;\r
@@ -71,8 +64,14 @@ global $MYSQL_HANDLER;
 if ( !isset($MYSQL_HANDLER) )\r
 {\r
        $MYSQL_HANDLER = array('mysql', '');\r
+       \r
+       // check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x\r
+       if ( !function_exists('mysql_query') && !function_exists('mysqli_query') )\r
+       {\r
+               exit('<div style="font-size: xx-large;"> Your PHP version does not have support for MySQL :( </div>');\r
+       }\r
 }\r
-include_once('../nucleus/libs/sql/' . $MYSQL_HANDLER[0] . '.php');\r
+include_once('../nucleus/libs/sql/sql.php');\r
 \r
 session_start();\r
 if ( count($_GET) == 0 && count($_POST) == 0 )\r
@@ -297,19 +296,13 @@ function show_footer()
  */\r
 function show_select_locale_form()\r
 {\r
-       // Get the browser language that can be displayed\r
-       // TODO: default locale select simple implementation\r
-       $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);\r
-       foreach ( $languages as $language )\r
-       {\r
-               $language = preg_replace('#([\w]+).*#', '$1', $language);\r
-               break;\r
+       // get locale list\r
+       $localelist = i18n::get_available_locale_list();\r
+       $locales = array();\r
+       foreach ( $localelist as $locale ) {\r
+               $checkfile = './locales/' . $locale . '.' . i18n::get_current_charset() . '.php';\r
+               $locales[] = array( $locale, (!file_exists($checkfile) ? '*&nbsp;' : '') . $locale );\r
        }\r
-\r
-       $locales = array(\r
-               array('en_Latn_US', 'English - United States'),\r
-               array('ja_Jpan_JP', 'Japanese - Japan')\r
-       );\r
 ?>\r
                <div id="container">\r
                        <p style="font-size:152%;font-weight:bold;">\r
@@ -320,6 +313,11 @@ function show_select_locale_form()
                                <div class="prt">\r
                                        <select name="locale">\r
 <?php\r
+       // Get the browser language that can be displayed\r
+       // TODO: default locale select simple implementation\r
+       $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);\r
+       $language = (is_array($languages) && count($languages) > 0) ? preg_replace('#^([\w]+).*$#', '$1', $languages[0]) : '';\r
+\r
        foreach ( $locales as $locale )\r
        {\r
                echo "<option value=\"$locale[0]\"";\r
@@ -331,6 +329,9 @@ function show_select_locale_form()
        }\r
 ?>\r
                                        </select>\r
+                                       <p>Nucleus is installed in the selected locale, the locale of the Asterisk prefixed will be displayed in English because there is no translation of the installer file.</p>\r
+                                       <p>We will wait for the translator by volunteers!</p>\r
+                                       </p>\r
                                        <p class="sbt">\r
                                                <button type="submit" name="action" value="locale" class="sbt_arw">START</button>\r
                                        </p>\r
@@ -809,7 +810,7 @@ function show_install_complete_form()
 function do_install()\r
 {\r
        global $param;\r
-       global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX, $MYSQL_CONN;\r
+       global $MYSQL_HANDLER, $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX, $MYSQL_CONN;\r
        global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;\r
        $errors = array();\r
 \r
@@ -832,8 +833,8 @@ function do_install()
        /*\r
         * 2.open mySQL connection\r
         */\r
-       $MYSQL_CONN = @sql_connect_args($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);\r
-       if ( $MYSQL_CONN == false )\r
+       $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);\r
+       if ( $MYSQL_CONN == FALSE )\r
        {\r
                $errors[] = _DBCONNECT_ERROR;\r
                return $errors;\r
@@ -842,19 +843,20 @@ function do_install()
        /*\r
         * 3. try to create database if needed\r
         */\r
-       if ( !sql_query("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") )\r
+       if ( DB::execute("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") === FALSE )\r
        {\r
-               $errors[] = _INST_ERROR1 . ': ' . sql_error();\r
+               $errinfo = DB::getError();\r
+               $errors[] = _INST_ERROR1 . ': ' . $errinfo[2];\r
        }\r
 \r
        /*\r
         * 4. try to select database\r
         */\r
-       if ( !sql_select_db($MYSQL_DATABASE) )\r
+       $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE);\r
+       if ( !$MYSQL_CONN )\r
        {\r
                $errors[] = _INST_ERROR2;\r
        }\r
-       sql_set_charset('utf8');\r
 \r
        if ( count($errors) > 0 )\r
        {\r
@@ -889,8 +891,8 @@ function do_install()
        }\r
 \r
        // table exists check\r
-       $result = sql_query('SHOW TABLES');\r
-       while ( $row = mysql_fetch_array($result, MYSQL_NUM) )\r
+       $result = DB::getResult('SHOW TABLES');\r
+       foreach ( $result as $row )\r
        {\r
                if ( in_array($row[0], $prefixed_table_names) )\r
                {\r
@@ -919,9 +921,10 @@ function do_install()
                                $query = str_replace($table_names, $prefixed_table_names, $query);\r
                        }\r
 \r
-                       if ( !sql_query($query) )\r
+                       if ( DB::execute($query) === FALSE )\r
                        {\r
-                               $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . sql_error();\r
+                               $errinfo = DB::getError();\r
+                               $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . $errinfo[2];\r
                        }\r
                }\r
        }\r
@@ -930,11 +933,18 @@ function do_install()
         * 6. put needed records\r
         */\r
        /* push first post */\r
-       $query = "INSERT INTO %s VALUES (1, '%s', '%s', '%s', 1, 1, '%s', 0, 0, 0, 1, 0, 1)";\r
-       $query = sprintf($query, tableName('nucleus_item'), _1ST_POST_TITLE, _1ST_POST, _1ST_POST2, i18n::formatted_datetime('mysql', time()));\r
-       if ( !sql_query($query) )\r
+       $query = "INSERT INTO %s VALUES (1, %s, %s, %s, 1, 1, %s, 0, 0, 0, 1, 0, 1)";\r
+       $query = sprintf($query,\r
+               tableName('nucleus_item'),\r
+               DB::quoteValue(_1ST_POST_TITLE),\r
+               DB::quoteValue(_1ST_POST),\r
+               DB::quoteValue(_1ST_POST2),\r
+               DB::formatDateTime()\r
+       );\r
+       if ( DB::execute($query) === FALSE )\r
        {\r
-               $errors[] = _INST_ERROR4 . ' (<small>' . $newpost . '</small>): ' . sql_error();\r
+               $errinfo = DB::getError();\r
+               $errors[] = _INST_ERROR4 . ' (<small>' . $newpost . '</small>): ' . $errinfo[2];\r
        }\r
 \r
        /* push configurations */\r
@@ -948,41 +958,49 @@ function do_install()
        array_merge($errors, updateConfig('SiteName', $param->blog_name));\r
        array_merge($errors, updateConfig('Locale', i18n::get_current_locale()));\r
 \r
-       /* escape strings for SQL */\r
-       $user_name                      = sql_real_escape_string($param->user_name);\r
-       $user_realname          = sql_real_escape_string($param->user_realname);\r
-       $user_password          = sql_real_escape_string(md5($param->user_password));\r
-       $user_email                     = sql_real_escape_string($param->user_email);\r
-       $blog_name                      = sql_real_escape_string($param->blog_name);\r
-       $blog_shortname         = sql_real_escape_string($param->blog_shortname);\r
-       $config_indexurl        = sql_real_escape_string($param->IndexURL);\r
-\r
        /* push super admin */\r
-       $query = "UPDATE %s SET mname = '%s', mrealname = '%s', mpassword = '%s', memail = '%s', murl = '%s', madmin = 1, mcanlogin = 1 WHERE mnumber = 1";\r
-       $query = sprintf($query, tableName('nucleus_member'), $user_name, $user_realname, $user_password, $user_email, $config_indexurl);\r
-       if ( !sql_query($query) )\r
+       $query = "UPDATE %s SET mname = %s, mrealname = %s, mpassword = %s, memail = %s, murl = %s, madmin = 1, mcanlogin = 1 WHERE mnumber = 1";\r
+       $query = sprintf($query,\r
+               tableName('nucleus_member'),\r
+               DB::quoteValue($param->user_name),\r
+               DB::quoteValue($param->user_realname),\r
+               DB::quoteValue(md5($param->user_password)),\r
+               DB::quoteValue($param->user_email),\r
+               DB::quoteValue($param->IndexURL)\r
+       );\r
+       if ( DB::execute($query) === FALSE )\r
        {\r
-               $errors[] = _INST_ERROR5 . ': ' . sql_error();\r
+               $errinfo = DB::getError();\r
+               $errors[] = _INST_ERROR5 . ': ' . $errinfo[2];\r
        }\r
 \r
        /* push new weblog */\r
-       $query = "UPDATE %s SET bname = '%s', bshortname = '%s', burl = '%s' WHERE bnumber = 1";\r
-       $query = sprintf($query, tableName('nucleus_blog'), $blog_name, $blog_shortname, $config_indexurl);\r
-       if ( !sql_query($query) )\r
+       $query = "UPDATE %s SET bname = %s, bshortname = %s, burl = %s WHERE bnumber = 1";\r
+       $query = sprintf($query,\r
+               tableName('nucleus_blog'),\r
+               DB::quoteValue($param->blog_name),\r
+               DB::quoteValue($param->blog_shortname),\r
+               DB::quoteValue($param->IndexURL)\r
+       );\r
+       if ( DB::execute($query) === FALSE )\r
        {\r
-               $errors[] = _INST_ERROR6 . ': ' . sql_error();\r
+               $errinfo = DB::getError();\r
+               $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];\r
        }\r
 \r
        /* push default category */\r
-       $query = "UPDATE %s SET cname = '%s', cdesc = '%s' WHERE catid = 1";\r
-       $query = sprintf($query, tableName('nucleus_category'), _GENERALCAT_NAME, _GENERALCAT_DESC);\r
-       if ( !sql_query($query) )\r
+       $query = "UPDATE %s SET cname = %s, cdesc = %s WHERE catid = 1";\r
+       $query = sprintf($query,\r
+               tableName('nucleus_category'),\r
+               DB::quoteValue(_GENERALCAT_NAME),\r
+               DB::quoteValue(_GENERALCAT_DESC)\r
+       );\r
+       if ( DB::execute($query) === FALSE )\r
        {\r
-               $errors[] = _INST_ERROR6 . ': ' . sql_error();\r
+               $errinfo = DB::getError();\r
+               $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];\r
        }\r
 \r
-       sql_close();\r
-\r
        /*\r
         * 7. install default plugins and skins\r
         */\r
@@ -1006,19 +1024,28 @@ function do_install()
                {\r
                        array_merge($errors, $aSkinErrors);\r
                }\r
-\r
+               \r
+               $query  = "SELECT sdnumber FROM %s WHERE sdname='admin/default'";\r
+               $query  = sprintf($query, tableName('nucleus_skin_desc'));\r
+               $res    = intval(DB::getValue($query));\r
+               array_merge($errors, updateConfig('AdminSkin', $res));\r
+               \r
+               $query  = "SELECT sdnumber FROM %s WHERE sdname='admin/bookmarklet'";\r
+               $query  = sprintf($query, tableName('nucleus_skin_desc'));\r
+               $res    = intval(DB::getValue($query));\r
+               array_merge($errors, updateConfig('BookmarkletSkin', $res));\r
+               \r
                $query          = "SELECT sdnumber FROM %s WHERE sdname='default'";\r
                $query          = sprintf($query, tableName('nucleus_skin_desc'));\r
-               $res            = sql_query($query);\r
-               $obj            = sql_fetch_assoc($res);\r
-               $defSkinID      = (integer) $obj['sdnumber'];\r
+               $defSkinID      = intval(DB::getValue($query));\r
 \r
                $query = "UPDATE %s SET bdefskin=%d WHERE bnumber=1";\r
                $query = sprintf($query, tableName('nucleus_blog'), $defSkinID);\r
-               sql_query($query);\r
+               DB::execute($query);\r
+               \r
                $query = "UPDATE %s SET value=%d WHERE name='BaseSkin'";\r
                $query = sprintf($query, tableName('nucleus_config'), $defSkinID);\r
-               sql_query($query);\r
+               DB::execute($query);\r
 \r
                $aPlugErrors = installCustomPlugs();\r
                if ( count($aPlugErrors) > 0 )\r
@@ -1116,28 +1143,26 @@ function canConfigFileWritable()
  */\r
 function getMySqlVersion()\r
 {\r
-       global $minimum_mysql_version, $errors;\r
+       global $MYSQL_HANDLER, $minimum_mysql_version, $errors;\r
        // Turn on output buffer\r
        // Needed to repress the output of the sql function that are\r
        // not part of php (in this case the @ operator doesn't work)\r
        ob_start();\r
 \r
        // note: this piece of code is taken from phpMyAdmin\r
-       $conn = sql_connect_args('localhost', '', '');\r
-       $result = @sql_query('SELECT VERSION() AS version', $conn);\r
+       $conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], 'localhost', '', '');\r
 \r
-       if ( $result != FALSE && sql_num_rows($result) > 0 )\r
+       if ( $conn )\r
        {\r
-               $row = sql_fetch_array($result);\r
-               $match = preg_split('#\.#', $row['version']);\r
+               $row = DB::getAttribute(PDO::ATTR_SERVER_VERSION);\r
+               $match = preg_split('#\.#', $row);\r
        }\r
        else\r
        {\r
-               $result = @sql_query('SHOW VARIABLES LIKE \'version\'', $conn);\r
+               $row = @DB::getRow('SHOW VARIABLES LIKE \'version\'');\r
 \r
-               if ( $result != FALSE && @sql_num_rows($result) > 0 )\r
+               if ( $row )\r
                {\r
-                       $row = sql_fetch_row($result);\r
                        $match = preg_split('#\.#', $row[1]);\r
                }\r
                else\r
@@ -1153,7 +1178,7 @@ function getMySqlVersion()
                }\r
        }\r
 \r
-       @sql_disconnect($conn);\r
+       @DB::disConnect();\r
 \r
        //End and clean output buffer\r
        ob_end_clean();\r
@@ -1193,13 +1218,17 @@ function installCustomPlugs()
                return $aErrors;\r
        }\r
 \r
-       $res = sql_query('SELECT * FROM ' . tableName('nucleus_plugin'));\r
-       $numCurrent = sql_num_rows($res);\r
+       $query = sprintf('SELECT * FROM %s', tableName('nucleus_plugin'));\r
+       $res = DB::getResult($query);\r
+       $numCurrent = $res->rowCount();\r
 \r
        foreach ( $aConfPlugsToInstall as $plugName )\r
        {\r
-               $query = 'INSERT INTO ' . tableName('nucleus_plugin') . ' (porder, pfile) VALUES (' . (++$numCurrent) . ", '" . sql_real_escape_string($plugName) . "')";\r
-               sql_query($query);\r
+               $query = sprintf('INSERT INTO %s (porder, pfile) VALUES (%d, %s)',\r
+                       tableName('nucleus_plugin'),\r
+                       (++$numCurrent),\r
+                       DB::quoteValue($plugName));\r
+               DB::execute($query);\r
 \r
                $manager->clearCachedInfo('installedPlugins');\r
                $plugin =& $manager->getPlugin($plugName);\r
@@ -1207,7 +1236,10 @@ function installCustomPlugs()
 \r
                if ( !$plugin )\r
                {\r
-                       sql_query('DELETE FROM ' . tableName('nucleus_plugin') . " WHERE pfile = '" . sql_real_escape_string($plugName) . "'");\r
+                       $query = sprintf('DELETE FROM %s WHERE pfile = %s',\r
+                               tableName('nucleus_plugin'),\r
+                               DB::quoteValue($plugName));\r
+                       DB::execute($query);\r
                        $numCurrent--;\r
                        array_push($aErrors, sprintf(_INST_ERROR9, $plugName));\r
                        continue;\r
@@ -1215,20 +1247,25 @@ function installCustomPlugs()
                $plugin->install();\r
        }\r
 \r
-       sql_query('DELETE FROM ' . tableName('nucleus_plugin_event'));\r
-       $res = sql_query('SELECT pid, pfile FROM ' . tableName('nucleus_plugin'));\r
+       $query = sprintf('DELETE FROM %s', tableName('nucleus_plugin_event'));\r
+       DB::execute($query);\r
+       $query = sprintf('SELECT pid, pfile FROM %s', tableName('nucleus_plugin'));\r
+       $res = DB::getResult($query);\r
 \r
-       while ( $o = sql_fetch_object($res) )\r
+       foreach ( $res as $row )\r
        {\r
-               $pid = $o->pid;\r
-               $plug =& $manager->getPlugin($o->pfile);\r
+               $plug =& $manager->getPlugin($row['pfile']);\r
 \r
                if ( $plug )\r
                {\r
                        $eventList = $plug->getEventList();\r
                        foreach ( $eventList as $eventName )\r
                        {\r
-                               sql_query('INSERT INTO ' . tableName('nucleus_plugin_event') . ' (pid, event) VALUES (' . $pid . ", '" . $eventName . "')");\r
+                               $query = sprintf('INSERT INTO %s (pid, event) VALUES (%d, %s)',\r
+                                       tableName('nucleus_plugin_event'),\r
+                                       intval($row['pid']),\r
+                                       DB::quoteValue($eventName));\r
+                               DB::execute($query);\r
                        }\r
                }\r
        }\r
@@ -1304,7 +1341,6 @@ function do_check_files()
                '../nucleus/libs/COMMENT.php',\r
                '../nucleus/libs/COMMENTACTIONS.php',\r
                '../nucleus/libs/COMMENTS.php',\r
-               '../nucleus/libs/ENCAPSULATE.php',\r
                '../nucleus/libs/ENTITY.php',\r
                '../nucleus/libs/globalfunctions.php',\r
                '../nucleus/libs/i18n.php',\r
@@ -1314,9 +1350,7 @@ function do_check_files()
                '../nucleus/libs/MANAGER.php',\r
                '../nucleus/libs/MEDIA.php',\r
                '../nucleus/libs/MEMBER.php',\r
-               '../nucleus/libs/mysql.php',\r
                '../nucleus/libs/NOTIFICATION.php',\r
-               '../nucleus/libs/PAGEFACTORY.php',\r
                '../nucleus/libs/PARSER.php',\r
                '../nucleus/libs/PLUGIN.php',\r
                '../nucleus/libs/PLUGINADMIN.php',\r
@@ -1327,7 +1361,8 @@ function do_check_files()
                '../nucleus/libs/vars4.1.0.php',\r
                '../nucleus/libs/xmlrpc.inc.php',\r
                '../nucleus/libs/xmlrpcs.inc.php',\r
-               '../nucleus/libs/sql/mysql.php'\r
+               '../nucleus/libs/sql/DB.php',\r
+               '../nucleus/libs/sql/MYSQLPDO.php'\r
        );\r
 \r
        $count = count($files);\r
@@ -1355,15 +1390,14 @@ function do_check_files()
 function updateConfig($name, $value)\r
 {\r
        $errors = array();\r
-       $name = sql_real_escape_string($name);\r
-       $value = trim(sql_real_escape_string($value));\r
 \r
-       $query = "UPDATE %s SET value = '%s' WHERE name = '%s'";\r
-       $query = sprintf($query, tableName('nucleus_config'), $value, $name);\r
+       $query = "UPDATE %s SET value = %s WHERE name = %s";\r
+       $query = sprintf($query, tableName('nucleus_config'), DB::quoteValue(trim($value)), DB::quoteValue($name));\r
 \r
-       if ( !sql_query($query) )\r
+       if ( DB::execute($query) === FALSE )\r
        {\r
-               $errors[] = _INST_ERROR4 . ': ' . sql_error();\r
+               $errinfo = DB::getError();\r
+               $errors[] = _INST_ERROR4 . ': ' . $errinfo[2];\r
        }\r
        return $errors;\r
 }\r
@@ -1486,6 +1520,8 @@ class ParamManager
 \r
        public function check_mysql_parameters()\r
        {\r
+               global $MYSQL_HANDLER;\r
+               \r
                $parameters = array('mysql_host', 'mysql_user', 'mysql_password', 'mysql_database', 'mysql_tablePrefix');\r
                $this->read_parameter($parameters);\r
 \r
@@ -1525,14 +1561,14 @@ class ParamManager
                \r
                if ( count($errors) == 0 )\r
                {\r
-                       $mysql_conn = @sql_connect_args($this->mysql_host, $this->mysql_user, $this->mysql_password);\r
+                       $mysql_conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], $this->mysql_host, $this->mysql_user, $this->mysql_password);\r
                        if ( $mysql_conn == false )\r
                        {\r
                                $errors[] = _DBCONNECT_ERROR;\r
                        }\r
                        else\r
                        {\r
-                               @sql_disconnect($mysql_conn);\r
+                               @DB::disConnect();\r
                        }\r
                }\r
 \r