OSDN Git Service

change create blog link code on <%bloglist%> for event_GenerateURL
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / install.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2007 The Nucleus Group
5  *
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)
11  * This script will install the Nucleus tables in your SQL-database, and initialize the data in
12  * those tables.
13  *
14  * Below is a friendly way of letting users on non-php systems know that Nucleus won't run there.
15  * ?><div style="font-size: xx-large;">If you see this text in your browser when you open <i>install.php</i>, your web server is not able to run PHP-scripts, and therefor Nucleus will not be able to run there. </div><div style="display: none"><?php
16  */
17
18 /**
19  * @license http://nucleuscms.org/license.txt GNU General Public License
20  * @copyright Copyright (C) 2002-2007 The Nucleus Group
21  * @version $Id: install.php,v 1.7 2007-02-04 06:28:44 kimitake Exp $
22  * $NucleusJP: install.php,v 1.6 2006/07/17 19:59:46 kimitake Exp $
23  */
24
25 /*
26         This part of the install.php code allows for customization of the install process.
27         When distributing plugins or skins together with a Nucleus installation, the
28         configuration below will instruct to install them
29
30         -- Start Of Configurable Part --
31 */
32
33 // array with names of plugins to install. Plugin files must be present in the nucleus/plugin/
34 // directory.
35 //
36 // example:
37 //     array('NP_TrackBack', 'NP_MemberGoodies')
38 $aConfPlugsToInstall = array('NP_SkinFiles');
39
40
41 // array with skins to install. skins must be present under the skins/ directory with
42 // a subdirectory having the same name that contains a skinbackup.xml file
43 //
44 // example:
45 //     array('base','rsd')
46 $aConfSkinsToImport = array('default');
47
48 /*
49         -- End Of Configurable Part --
50 */
51
52 // don't give warnings for uninitialized vars
53 error_reporting(E_ERROR | E_WARNING | E_PARSE);
54
55 // make sure there's no unnecessary escaping:
56 set_magic_quotes_runtime(0);
57
58 // if there are some plugins or skins to import, do not include vars
59 // in globalfunctions.php again... so set a flag
60 if ((count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) ) {
61         global $CONF;
62         $CONF['installscript'] = 1;
63 }
64
65 if (phpversion() >= '4.1.0') {
66         include_once('nucleus/libs/vars4.1.0.php');
67 } else {
68         include_once('nucleus/libs/vars4.0.6.php');
69 }
70
71 include_once('nucleus/libs/mysql.php');
72
73 // check if mysql support is installed
74         if (!function_exists('mysql_query') ) {
75                 _doError('Your PHP version does not have support for MySQL :(');
76         }
77
78         if (postVar('action') == 'go') {
79                 doInstall();
80         } else {
81                 showInstallForm();
82         }
83
84         exit;
85
86 function showInstallForm() {
87         // 0. pre check if all necessary files exist
88         doCheckFiles();
89
90         ?>
91         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
92         <html xmlns="http://www.w3.org/1999/xhtml">
93         <head>
94                 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
95                 <title>Nucleusのインストール</title>
96                 <style type="text/css"><!--
97                         @import url('nucleus/documentation/styles/manual.css');
98                 --></style>
99                 <script type="text/javascript"><!--
100                         var submitcount = 0;
101
102                         // function to make sure the submit button only gets pressed once
103                         function checkSubmit() {
104                                 if (submitcount == 0) {
105                                         submitcount++;
106                                         return true;
107                                 } else {
108                                         return false;
109                                 }
110                         }
111                 --></script>
112         </head>
113         <body>
114                 <div style="text-align:center"><img src="./nucleus/styles/logo.gif" /></div> <!-- Nucleus logo -->
115                 <form method="post" action="install.php">
116
117                 <h1>Install Nucleus</h1>
118
119                 <p>このスクリプトはNucleusのインストールを手助けします。MySQLテーブルのセットアップと、<i>config.php</i>に入力するための情報を表示します(config.phpのパーミッションを0666にしておけば、後者の作業は自動的に行われます)。これをなす為に、いくつかの情報を入力する必要があります。</p>
120
121                 <p>すべての欄の入力が必要です。オプション情報はインストールが完了したら、Nucleusの管理領域から設定可能です。</p>
122
123                 <h1>PHP &amp; MySQL Versions</h1>
124
125                 <p>以下はあなたのウェブホストにおけるPHPインタープリターとMySQLサーバーのバージョンです。Nucleusのサポートフォーラムに問題を報告するときは、この情報を書き添えてください。</p>
126
127                 <ul>
128                         <li>PHP:
129
130 <?php
131         echo phpversion();
132         $minVersion = '4.0.6';
133
134         if (phpversion() < $minVersion) {
135                 echo ' <span class="warning">注意: Nucleusの動作には少なくともバージョン ',$minVersion,' が必要とされます</span>';
136         }
137 ?>
138
139                         </li>
140                         <li>MySQL:
141
142 <?php
143         // note: this piece of code is taken from phpMyAdmin
144         $result = @mysql_query('SELECT VERSION() AS version');
145
146         if ($result != FALSE && @mysql_num_rows($result) > 0) {
147                 $row = mysql_fetch_array($result);
148                 $match = explode('.', $row['version']);
149         } else {
150                 $result = @mysql_query('SHOW VARIABLES LIKE \'version\'');
151
152                 if ($result != FALSE && @mysql_num_rows($result) > 0) {
153                         $row = mysql_fetch_row($result);
154                         $match = explode('.', $row[1]);
155                 } else {
156                         $match[0] = '?';
157                         $match[1] = '?';
158                         $match[2] = '?';
159                 }
160         }
161
162         if (!isset($match) || !isset($match[0]) ) {
163                 $match[0] = 3;
164         }
165
166         if (!isset($match[1]) ) {
167                 $match[1] = 21;
168         }
169
170         if (!isset($match[2]) ) {
171                 $match[2] = 0;
172         }
173
174         if ($match[0] != '?') {
175                 $match[0] = intval($match[0]);
176                 $match[1] = intval($match[1]);
177         }
178
179         $mysqlVersion = implode($match, '.');
180         $minVersion = '3.23';
181
182         echo $mysqlVersion;
183
184         if ($mysqlVersion < $minVersion) {
185                 echo ' <span class="warning">注意: Nucleusの動作には少なくともバージョン ',$minVersion,' が必要とされます</span>';
186         }
187 ?>
188
189                         </li>
190                 </ul>
191
192 <?php
193         // tell people how they can have their config file filled out automatically
194         if (@file_exists('config.php') && @!is_writable('config.php') ) {
195 ?>
196
197                 <h1><i>config.php</i>の自動アップデート</h1>
198
199                 <p>もし<em>config.php</em>を自動的に更新するようにしたいなら、書き込み可能にする必要があります。<em>config.php</em>のパーミッションを<strong>666</strong>にしてください。Nucleusのインストール成功後に、パーミッションを<strong>444</strong>に戻さなければなりません(<a href="nucleus/documentation/tips.html#filepermissions">パーミッション変更の簡易ガイド</a>)。</p>
200
201                 <p>もしファイルに書き込まないという選択をした(あるいは行えない)場合:ご心配なく。インストールの過程で<em>config.php</em>の中身が提供されます。ですから、それをご自身でアップロードしてください。</p>
202
203 <?php } ?>
204
205                 <h1>MySQLのログインデータ</h1>
206
207                 <p>MySQLのデータを以下に入力してください。それらはデータベース・テーブルを作成し情報を入力するために必要なものです。後で、<i>config.php</i>にも記入する必要があります(上記の自動アップデートを利用する場合、その手順は省略されます)。</p>
208
209                 <p>もしこの情報がわからなければ、システム管理者かホスティング元に連絡をとってください。ほとんどの場合、ホスト名は'localhost'です。もしNucleusがあなたのサーバのPHP設定から'default MySQL host'を検知したなら、'ホスト名'に既に記入されているはずです。もっとも、この情報が正確であるという保証はありません。</p>
210
211                 <fieldset>
212                         <legend>基本のデータベース設定</legend>
213                         <table>
214                                 <tr>
215                                         <td>ホスト名:</td>
216                                         <td><input name="mySQL_host" value="<?php echo htmlspecialchars(@ini_get('mysql.default_host') )?>" /></td>
217                                 </tr>
218                                 <tr>
219                                         <td>ユーザー名:</td>
220                                         <td><input name="mySQL_user" /></td>
221                                 </tr>
222                                 <tr>
223                                         <td>パスワード:</td>
224                                         <td><input name="mySQL_password" type="password" /></td>
225                                 </tr>
226                                 <tr>
227                                         <td>データベース名:</td>
228                                         <td><input name="mySQL_database" /> (<input name="mySQL_create" value="1" type="checkbox" id="mySQL_create"><label for="mySQL_create" />データベースを作成する必要がある</label>)</td>
229                                 </tr>
230                         </table>
231                 </fieldset>
232
233                 <fieldset>
234                         <legend>高等なデータベース設定</legend>
235                         <table>
236                                 <tr>
237                                         <td><input name="mySQL_usePrefix" value="1" type="checkbox" id="mySQL_usePrefix"><label for="mySQL_usePrefix" />テーブル・プリフィックスを利用</label></td>
238                                         <td><input name="mySQL_tablePrefix" value="" /></td>
239                                 </tr>
240                         </table>
241
242                         <p>一つのデータベースに複数のNucleusをインストールしており、自分が何をやっているのか理解されている場合を除いては、<strong>これを変更する必要はありません</strong>。</p>
243                         <p>Nucleusによって生成されたすべてのデータベーステーブルは、このプリフィックスが頭につきます。</p>
244                 </fieldset>
245
246         <h1>ディレクトリとURL</h1>
247
248         <p>このインストールスクリプトはNucleusがインストールされているディレクトリとURLを見つけようとしました。下の値をチェックして必要なら訂正してください。ファイルへのパスとURLはスラッシュ'/'で終わらなくてはなりません。</p>
249
250 <?php
251
252         // no need to this all! dirname(__FILE__) is all we need -- moraes
253         /*
254         // discover full path
255         $fullPath = serverVar('PATH_TRANSLATED');
256
257         if ($fullPath == '') {
258                 $fullPath = serverVar('SCRIPT_FILENAME');
259         }
260
261         $basePath = str_replace('install.php', '', $fullPath);
262         $basePath = replaceDoubleBackslash($basePath);
263         $basePath = replaceDoubleBackslash($basePath);
264
265         // add slash at end if necessary
266         if (!endsWithSlash($basePath) ) {
267                 $basePath .= '/';
268         }
269         */
270
271         $basePath = dirname(__FILE__) . '/';
272 ?>
273
274                 <fieldset>
275                         <legend>URLs and directories</legend>
276                         <table>
277                                 <tr>
278                                         <td>Site <strong>URL</strong>:</td>
279                                         <td><input name="IndexURL" size="60" value="<?php
280                                                 $url = 'http://' . serverVar('HTTP_HOST') . serverVar('PHP_SELF');
281                                                 $url = str_replace('install.php', '', $url);
282                                                 $url = replaceDoubleBackslash($url);
283
284                                                 // add slash at end if necessary
285                                                 if (!endsWithSlash($url) ) {
286                                                         $url .= '/';
287                                                 }
288
289                                                 echo $url; ?>" /></td>
290                                 </tr>
291                                 <tr>
292                                         <td>Admin-area <strong>URL</strong>:</td>
293                                         <td><input name="AdminURL" size="60" value="<?php
294                                                 if ($url) {
295                                                         echo $url, 'nucleus/';
296                                                 } ?>" /></td>
297                                 </tr>
298                                 <tr>
299                                         <td>Admin-area <strong>path</strong>:</td>
300                                         <td><input name="AdminPath" size="60" value="<?php
301                                                 if($basePath) {
302                                                         echo $basePath, 'nucleus/';
303                                                 } ?>" /></td>
304                                 </tr>
305                                 <tr>
306                                         <td>Media files <strong>URL</strong>:</td>
307                                         <td><input name="MediaURL" size="60" value="<?php
308                                                 if ($url) {
309                                                         echo $url, 'media/';
310                                                 } ?>" /></td>
311                                 </tr>
312                                 <tr>
313                                         <td>Media directory <strong>path</strong>:</td>
314                                         <td><input name="MediaPath" size="60" value="<?php
315                                                 if ($basePath) {
316                                                         echo $basePath, 'media/';
317                                                 } ?>" /></td>
318                                 </tr>
319                                 <tr>
320                                         <td>Extra skin files <strong>URL</strong>:</td>
321                                         <td><input name="SkinsURL" size="60" value="<?php
322                                                 if ($url) {
323                                                         echo $url, 'skins/';
324                                                 } ?>" />
325                                                 <br />(インポートされたスキンが使用)
326                                         </td>
327                                 </tr>
328                                 <tr>
329                                         <td>Extra skin files directory <strong>path</strong>:</td>
330                                         <td><input name="SkinsPath" size="60" value="<?php
331                                                 if ($basePath) {
332                                                         echo $basePath, 'skins/';
333                                                 } ?>" />
334                                                 <br />(インポートされたスキンのファイル類を置く場所)
335                                         </td>
336                                 </tr>
337                                 <tr>
338                                         <td>Plugin files <strong>URL</strong>:</td>
339                                         <td><input name="PluginURL" size="60" value="<?php
340                                                 if ($url) {
341                                                         echo $url, 'nucleus/plugins/';
342                                                 } ?>" /></td>
343                                 </tr>
344                                 <tr>
345                                         <td>Action <strong>URL</strong>:</td>
346                                         <td><input name="ActionURL" size="60" value="<?php
347                                                 if ($url) {
348                                                         echo $url, 'action.php';
349                                                 } ?>" />
350                                                 <br />(<tt>action.php</tt>へのhttp://から始まるURL)
351                                         </td>
352                                 </tr>
353                         </table>
354                 </fieldset>
355
356                 <p class="note"><strong>付記:</strong> 相対パスではなく<strong>絶対パスを使ってください</strong>。通常、絶対パスは<tt>/home/username/public_html/</tt>のような形をとります。Unixシステム(ほとんどのサーバーがそうです)において、パスはスラッシュから始まります。もしこれらの情報入力に問題が生じたら、あなたのサーバ管理者にたずねるべきです。</p>
357
358                 <h1>管理権限をもつユーザー</h1>
359
360                 <p>以下に、サイトの最初のユーザーを作成するためのいくつかの情報を入力してください。</p>
361
362                 <fieldset>
363                         <legend>管理権限を持つユーザー</legend>
364                         <table>
365                                 <tr>
366                                         <td>表示される名前:</td>
367                                         <td><input name="User_name" value="" /> <small>(許可される文字:a-z と 0-9、最初と最後以外のスペース)</small></td>
368                                 </tr>
369                                 <tr>
370                                         <td>本名(ハンドル名):</td>
371                                         <td><input name="User_realname" value="" /></td>
372                                 </tr>
373                                 <tr>
374                                         <td>パスワード:</td>
375                                         <td><input name="User_password" type="password" value="" /></td>
376                                 </tr>
377                                 <tr>
378                                         <td>パスワードの確認:</td>
379                                         <td><input name="User_password2" type="password" value="" /></td>
380                                 </tr>
381                                 <tr>
382                                         <td>メールアドレス:</td>
383                                         <td><input name="User_email" value="" /> <small>(利用可能なメールアドレスを入れてください)</small></td>
384                                 </tr>
385                         </table>
386                 </fieldset>
387
388                 <h1>ウェブログのデータ</h1>
389
390                 <p>以下に、デフォルトのweblogを作成するためにいくつかの情報を入力してください。このweblogの名前は、サイト名としても利用されます。</p>
391
392                 <fieldset>
393                         <legend>ウェブログのデータ</legend>
394                         <table>
395                                 <tr>
396                                         <td>Blog名:</td>
397                                         <td><input name="Blog_name" size="60" value="My Nucleus CMS" /></td>
398                                 </tr>
399                                 <tr>
400                                         <td>Blogの短縮名:</td>
401                                         <td><input name="Blog_shortname" value="mynucleuscms" /> <small>(許可される文字:a-z と 0-9、スペースは不可)</small></td>
402                                 </tr>
403                         </table>
404                 </fieldset>
405
406                 <h1>データの送信</h1>
407
408                 <p>上に書いてきたデータが正しいか確かめてください。よければデータベース・テーブルと最初のデータを設定するために下のボタンを押してください。少し時間がかかるかもしれませんがご辛抱を。<b>ボタンをクリックするのは一回だけにしてください。</b></p>
409
410                 <p><input name="action" value="go" type="hidden" /> <input type="submit" value="Nucleus CMSのインストール" onclick="return checkSubmit();" /></p>
411
412                 </form>
413         </body>
414 </html>
415
416 <?php }
417
418 function tableName($unPrefixed) {
419         global $mysql_usePrefix, $mysql_prefix;
420
421         if ($mysql_usePrefix == 1) {
422                 return $mysql_prefix . $unPrefixed;
423         } else {
424                 return $unPrefixed;
425         }
426 }
427
428 function doInstall() {
429         global $mysql_usePrefix, $mysql_prefix;
430
431         // 0. put all POST-vars into vars
432         $mysql_host = postVar('mySQL_host');
433         $mysql_user = postVar('mySQL_user');
434         $mysql_password = postVar('mySQL_password');
435         $mysql_database = postVar('mySQL_database');
436         $mysql_create = postVar('mySQL_create');
437         $mysql_usePrefix = postVar('mySQL_usePrefix');
438         $mysql_prefix = postVar('mySQL_tablePrefix');
439         $config_indexurl = postVar('IndexURL');
440         $config_adminurl = postVar('AdminURL');
441         $config_adminpath = postVar('AdminPath');
442         $config_mediaurl = postVar('MediaURL');
443         $config_skinsurl = postVar('SkinsURL');
444         $config_pluginurl = postVar('PluginURL');
445         $config_actionurl = postVar('ActionURL');
446         $config_mediapath = postVar('MediaPath');
447         $config_skinspath = postVar('SkinsPath');
448         $user_name = postVar('User_name');
449         $user_realname = postVar('User_realname');
450         $user_password = postVar('User_password');
451         $user_password2 = postVar('User_password2');
452         $user_email = postVar('User_email');
453         $blog_name = postVar('Blog_name');
454         $blog_shortname = postVar('Blog_shortname');
455         $config_adminemail = $user_email;
456         $config_sitename = $blog_name;
457
458         $config_indexurl = replaceDoubleBackslash($config_indexurl);
459         $config_adminurl = replaceDoubleBackslash($config_adminurl);
460         $config_mediaurl = replaceDoubleBackslash($config_mediaurl);
461         $config_skinsurl = replaceDoubleBackslash($config_skinsurl);
462         $config_pluginurl = replaceDoubleBackslash($config_pluginurl);
463         $config_actionurl = replaceDoubleBackslash($config_actionurl);
464         $config_adminpath = replaceDoubleBackslash($config_adminpath);
465         $config_skinspath = replaceDoubleBackslash($config_skinspath);
466
467         // 1. check all the data
468         $errors = array();
469
470         if (!$mysql_database) {
471                 array_push($errors, 'mySQL database name missing');
472         }
473
474         if (($mysql_usePrefix == 1) && (strlen($mysql_prefix) == 0) ) {
475                 array_push($errors, 'mySQL prefix was selected, but prefix is empty');
476         }
477
478         if (($mysql_usePrefix == 1) && (!eregi('^[a-zA-Z0-9_]+$', $mysql_prefix) ) ) {
479                 array_push($errors, 'mySQL prefix should only contain characters from the ranges A-Z, a-z, 0-9 or underscores');
480         }
481
482         // TODO: add action.php check
483         if (!endsWithSlash($config_indexurl) || !endsWithSlash($config_adminurl) || !endsWithSlash($config_mediaurl) || !endsWithSlash($config_pluginurl) || !endsWithSlash($config_skinsurl) ) {
484                 array_push($errors, 'One of the URLs does not end with a slash, or action url does not end with \'action.php\'');
485         }
486
487         if (!endsWithSlash($config_adminpath) ) {
488                 array_push($errors, 'The path of the administration area does not end with a slash');
489         }
490
491         if (!endsWithSlash($config_mediapath) ) {
492                 array_push($errors, 'The media path does not end with a slash');
493         }
494
495         if (!endsWithSlash($config_skinspath) ) {
496                 array_push($errors, 'The skins path does not end with a slash');
497         }
498
499         if (!is_dir($config_adminpath) ) {
500                 array_push($errors, 'The path of the administration area does not exist on your server');
501         }
502
503         if (!_isValidMailAddress($user_email) ) {
504                 array_push($errors, 'Invalid e-mail address given for user');
505         }
506
507         if (!_isValidDisplayName($user_name) ) {
508                 array_push($errors, 'User name is not a valid display name (allowed chars: a-zA-Z0-9 and spaces)');
509         }
510
511         if (!$user_password || !$user_password2) {
512                 array_push($errors, 'User password is empty');
513         }
514
515         if ($user_password != $user_password2) {
516                 array_push($errors, 'User password do not match');
517         }
518
519         if (!_isValidShortName($blog_shortname) ) {
520                 array_push($errors, 'Invalid short name given for blog (allowed chars: a-z0-9, no spaces)');
521         }
522
523         if (sizeof($errors) > 0) {
524                 showErrorMessages($errors);
525         }
526
527         // 2. try to log in to mySQL
528         global $MYSQL_CONN;
529         $MYSQL_CONN = @mysql_connect($mysql_host, $mysql_user, $mysql_password);
530
531         if ($MYSQL_CONN == false) {
532                 _doError('Could not connect to mySQL server: ' . mysql_error() );
533         }
534
535         // 3. try to create database (if needed)
536         if ($mysql_create == 1) {
537                 mysql_query('CREATE DATABASE ' . $mysql_database) or _doError('Could not create database. Make sure you have the rights to do so. SQL error was: ' . mysql_error() );
538         }
539
540         // 4. try to select database
541         mysql_select_db($mysql_database) or _doError('Could not select database. Make sure it exists');
542
543         // 5. execute queries
544         $filename = 'install.sql';
545         $fd = fopen($filename, 'r');
546         $queries = fread($fd, filesize($filename) );
547         fclose($fd);
548
549         $queries = split("(;\n|;\r)", $queries);
550
551         $aTableNames = array(
552                 'nucleus_actionlog',
553                 'nucleus_ban',
554                 'nucleus_blog',
555                 'nucleus_category',
556                 'nucleus_comment',
557                 'nucleus_config',
558                 'nucleus_item',
559                 'nucleus_karma',
560                 'nucleus_member',
561                 'nucleus_plugin',
562                 'nucleus_skin',
563                 'nucleus_template',
564                 'nucleus_team',
565                 'nucleus_activation',
566                 'nucleus_tickets'
567                 );
568 // these are unneeded (one of the replacements above takes care of them)
569 //                      'nucleus_plugin_event',
570 //                      'nucleus_plugin_option',
571 //                      'nucleus_plugin_option_desc',
572 //                      'nucleus_skin_desc',
573 //                      'nucleus_template_desc',
574
575         $aTableNamesPrefixed = array(
576                 $mysql_prefix . 'nucleus_actionlog',
577                 $mysql_prefix . 'nucleus_ban',
578                 $mysql_prefix . 'nucleus_blog',
579                 $mysql_prefix . 'nucleus_category',
580                 $mysql_prefix . 'nucleus_comment',
581                 $mysql_prefix . 'nucleus_config',
582                 $mysql_prefix . 'nucleus_item',
583                 $mysql_prefix . 'nucleus_karma',
584                 $mysql_prefix . 'nucleus_member',
585                 $mysql_prefix . 'nucleus_plugin',
586                 $mysql_prefix . 'nucleus_skin',
587                 $mysql_prefix . 'nucleus_template',
588                 $mysql_prefix . 'nucleus_team',
589                 $mysql_prefix . 'nucleus_activation',
590                 $mysql_prefix . 'nucleus_tickets'
591                 );
592 // these are unneeded (one of the replacements above takes care of them)
593 //                      $mysql_prefix . 'nucleus_plugin_event',
594 //                      $mysql_prefix . 'nucleus_plugin_option',
595 //                      $mysql_prefix . 'nucleus_plugin_option_desc',
596 //                      $mysql_prefix . 'nucleus_skin_desc',
597 //                      $mysql_prefix . 'nucleus_template_desc',
598
599         $count = count($queries);
600
601         for ($idx = 0; $idx < $count; $idx++) {
602                 $query = trim($queries[$idx]);
603                 // echo "QUERY = <small>" . htmlspecialchars($query) . "</small><p>";
604
605                 if ($query) {
606
607                         if ($mysql_usePrefix == 1) {
608                                         $query = str_replace($aTableNames, $aTableNamesPrefixed, $query);
609                         }
610
611                         mysql_query($query) or _doError('Error while executing query (<small>' . htmlspecialchars($query) . '</small>): ' . mysql_error() );
612                 }
613         }
614
615         // 6. update global settings
616         updateConfig('IndexURL', $config_indexurl);
617         updateConfig('AdminURL', $config_adminurl);
618         updateConfig('MediaURL', $config_mediaurl);
619         updateConfig('SkinsURL', $config_skinsurl);
620         updateConfig('PluginURL', $config_pluginurl);
621         updateConfig('ActionURL', $config_actionurl);
622         updateConfig('AdminEmail', $config_adminemail);
623         updateConfig('SiteName', $config_sitename);
624
625         // 7. update GOD member
626         $query = 'UPDATE ' . tableName('nucleus_member')
627                         . " SET mname='" . addslashes($user_name) . "',"
628                         . " mrealname='" . addslashes($user_realname) . "',"
629                         . " mpassword='" . md5(addslashes($user_password) ) . "',"
630                         . " murl='" . addslashes($config_indexurl) . "',"
631                         . " memail='" . addslashes($user_email) . "',"
632                         . " madmin=1, mcanlogin=1"
633                         . " WHERE mnumber=1";
634
635         mysql_query($query) or _doError('Error while setting member settings: ' . mysql_error() );
636
637         // 8. update weblog settings
638         $query = 'UPDATE ' . tableName('nucleus_blog')
639                         . " SET bname='" . addslashes($blog_name) . "',"
640                         . " bshortname='" . addslashes($blog_shortname) . "',"
641                         . " burl='" . addslashes($config_indexurl) . "'"
642                         . " WHERE bnumber=1";
643
644         mysql_query($query) or _doError('Error while setting weblog settings: ' . mysql_error() );
645
646         // 9. update item date
647         $query = 'UPDATE ' . tableName('nucleus_item')
648                         . " SET itime='" . date('Y-m-d H:i:s', time() ) ."'"
649                         . " WHERE inumber=1";
650
651         mysql_query($query) or _doError('Error with query: ' . mysql_error() );
652
653         global $aConfPlugsToInstall, $aConfSkinsToImport;
654         $aSkinErrors = array();
655         $aPlugErrors = array();
656
657         if ((count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) ) {
658                 // 10. set global variables
659                 global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX;
660
661                 $MYSQL_HOST = $mysql_host;
662                 $MYSQL_USER = $mysql_user;
663                 $MYSQL_PASSWORD = $mysql_password;
664                 $MYSQL_DATABASE = $mysql_database;
665                 $MYSQL_PREFIX = ($mysql_usePrefix == 1)?$mysql_prefix:'';
666
667                 global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;
668
669                 $DIR_NUCLEUS = $config_adminpath;
670                 $DIR_MEDIA = $config_mediapath;
671                 $DIR_SKINS = $config_skinspath;
672                 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
673                 $DIR_LANG = $DIR_NUCLEUS . 'language/';
674                 $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
675
676                 // close database connection (needs to be closed if we want to include globalfunctions.php)
677                 mysql_close();
678
679                 $manager = '';
680                 include_once($DIR_LIBS . 'globalfunctions.php');
681
682                 // 11. install custom skins
683                 $aSkinErrors = installCustomSkins($manager);
684
685                 // 12. install custom plugins
686                 $aPlugErrors = installCustomPlugs($manager);
687         }
688
689         // 12. Write config file ourselves (if possible)
690         $bConfigWritten = 0;
691
692         if (@file_exists('config.php') && is_writable('config.php') && $fp = @fopen('config.php', 'w') ) {
693                 $config_data = '<' . '?php' . "\n\n";
694                 //$config_data .= "\n"; (extraneous, just added extra \n to previous line
695                 $config_data .= "       // mySQL connection information\n";
696                 $config_data .= "       \$MYSQL_HOST = '" . $mysql_host . "';\n";
697                 $config_data .= "       \$MYSQL_USER = '" . $mysql_user . "';\n";
698                 $config_data .= "       \$MYSQL_PASSWORD = '" . $mysql_password . "';\n";
699                 $config_data .= "       \$MYSQL_DATABASE = '" . $mysql_database . "';\n";
700                 $config_data .= "       \$MYSQL_PREFIX = '" . (($mysql_usePrefix == 1)?$mysql_prefix:'') . "';\n";
701                 $config_data .= "\n";
702                 $config_data .= "       // main nucleus directory\n";
703                 $config_data .= "       \$DIR_NUCLEUS = '" . $config_adminpath . "';\n";
704                 $config_data .= "\n";
705                 $config_data .= "       // path to media dir\n";
706                 $config_data .= "       \$DIR_MEDIA = '" . $config_mediapath . "';\n";
707                 $config_data .= "\n";
708                 $config_data .= "       // extra skin files for imported skins\n";
709                 $config_data .= "       \$DIR_SKINS = '" . $config_skinspath . "';\n";
710                 $config_data .= "\n";
711                 $config_data .= "       // these dirs are normally sub dirs of the nucleus dir, but \n";
712                 $config_data .= "       // you can redefine them if you wish\n";
713                 $config_data .= "       \$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";
714                 $config_data .= "       \$DIR_LANG = \$DIR_NUCLEUS . 'language/';\n";
715                 $config_data .= "       \$DIR_LIBS = \$DIR_NUCLEUS . 'libs/';\n";
716                 $config_data .= "\n";
717                 $config_data .= "       // include libs\n";
718                 $config_data .= "       include(\$DIR_LIBS.'globalfunctions.php');\n";
719                 $config_data .= "       if (!extension_loaded('mbstring')) {\n";
720                 $config_data .= "       include(\$DIR_LIBS.'mb_emulator/mb-emulator.php');\n";
721                 $config_data .= "       }\n";
722                 $config_data .= "?" . ">";
723
724                 $result = @fputs($fp, $config_data, strlen($config_data) );
725                 fclose($fp);
726
727                 if ($result) {
728                         $bConfigWritten = 1;
729                 }
730         }
731
732 ?>
733 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
734 <html xmlns="http://www.w3.org/1999/xhtml">
735 <head>
736         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
737         <title>Nucleusのインストール</title>
738         <style>@import url('nucleus/styles/manual.css');</style>
739 </head>
740 <body>
741         <div style='text-align:center'><img src='./nucleus/styles/logo.gif' /></div> <!-- Nucleus logo -->
742
743 <?php
744         $aAllErrors = array_merge($aSkinErrors, $aPlugErrors);
745
746         if (count($aAllErrors) > 0) {
747                 echo '<h1>Skin/Plugin Install errors</h1>';
748                 echo '<ul><li>' . implode('</li><li>', $aAllErrors) . '</li></ul>';
749         }
750
751         if (!$bConfigWritten) { ?>
752                 <h1>インストールはほぼ完了しました!</h1>
753
754                 <p>データベーステーブルの初期値入力が成功しました。後は<i>config.php</i>を書き換えるだけです。以下に書き換えるべき内容を表示します(mysqlのパスワードはマスクされています。ここは実際のものに書き換えてください)</p>
755
756                 <pre><code>&lt;?php
757         // mySQL connection information
758         $MYSQL_HOST = '<b><?php echo $mysql_host?></b>';
759         $MYSQL_USER = '<b><?php echo $mysql_user?></b>';
760         $MYSQL_PASSWORD = '<i><b>xxxxxxxxxxx</b></i>';
761         $MYSQL_DATABASE = '<b><?php echo $mysql_database?></b>';
762         $MYSQL_PREFIX = '<b><?php echo ($mysql_usePrefix == 1)?$mysql_prefix:''?></b>';
763
764         // main nucleus directory
765         $DIR_NUCLEUS = '<b><?php echo $config_adminpath?></b>';
766
767         // path to media dir
768         $DIR_MEDIA = '<b><?php echo $config_mediapath?></b>';
769
770         // extra skin files for imported skins
771         $DIR_SKINS = '<b><?php echo $config_skinspath?></b>';
772
773         // these dirs are normally sub dirs of the nucleus dir, but
774         // you can redefine them if you wish
775         $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';
776         $DIR_LANG = $DIR_NUCLEUS . 'language/';
777         $DIR_LIBS = $DIR_NUCLEUS . 'libs/';
778
779         // include libs
780         include($DIR_LIBS.'globalfunctions.php');
781         if (!extension_loaded('mbstring')) {
782                 include($DIR_LIBS.'mb_emulator/mb-emulator.php');
783         }
784 ?&gt;</code></pre>
785
786         <p>あなたのコンピュータ上のファイルを書き換えたら、FTPを使ってウェブサーバにアップロードしてください。ASCIIモードで送信してファイルを上書きします。</p>
787
788         <div class="note">
789                 <b>付記:</b> <i>config.php</i>の最初や終わりにスペースを空けないようにしましょう。実行時にエラーを引き起こす原因となります。<br />
790                 したがって、config.phpの最初の文字は "&lt;"で最後の文字は"&gt;"としなければなりません。
791         </div>
792
793 <?php } else { ?>
794
795         <h1>インストールは完了しました!</h1>
796
797         <p>Nucleusはインストールされ、<code>config.php</code>はアップデートされました。</p>
798
799         <p>セキュリティのため<code>config.php</code>のパーミッションを444に戻すことを忘れないでください(<a href="nucleus/documentation/tips.html#filepermissions">パーミッション変更の簡易ガイド</a>)。</p>
800
801 <?php } ?>
802
803         <h1>インストールファイルの削除</h1>
804
805         <p>ウェブサーバから次のファイルを削除してください:</p>
806
807         <ul>
808                 <li><b>install.sql</b>:テーブルの構造を内包するファイル</li>
809                 <li><b>install.php</b>:このファイル</li>
810         </ul>
811
812         <p>もしこれらのファイルを削除していなければ、管理領域を開くことが出来ません。</p>
813
814         <h1>ウェブサイトの確認</h1>
815
816         <p>ウェブサイトを使う準備が整いました。
817                 <ul>
818                         <li><a href="<?php echo $config_adminurl?>">管理領域にログインしてサイトの設定を行う</a></li>
819                         <li><a href="<?php echo $config_indexurl?>">すぐにサイトへ行ってみる</a></li>
820                 </ul>
821         </p>
822
823 </body>
824 </html>
825
826 <?php
827 }
828
829 function installCustomPlugs(&$manager) {
830         global $aConfPlugsToInstall, $DIR_LIBS;
831
832         $aErrors = array();
833
834         if (count($aConfPlugsToInstall) == 0) {
835                 return $aErrors;
836         }
837
838         $res = sql_query('SELECT * FROM ' . sql_table('plugin') );
839         $numCurrent = mysql_num_rows($res);
840
841         foreach ($aConfPlugsToInstall as $plugName) {
842                 // do this before calling getPlugin (in case the plugin id is used there)
843                 $query = 'INSERT INTO ' . sql_table('plugin') . ' (porder, pfile) VALUES (' . (++$numCurrent) . ', "' . addslashes($plugName) . '")';
844                 sql_query($query);
845
846                 // get and install the plugin
847                 $plugin =& $manager->getPlugin($plugName);
848
849                 if (!$plugin) {
850                         sql_query('DELETE FROM ' . sql_table('plugin') . ' WHERE pfile=\'' . addslashes($plugName) . '\'');
851                         $numCurrent--;
852                         array_push($aErrors, 'Unable to install plugin ' . $plugName);
853                         continue;
854                 }
855
856                 $plugin->install();
857         }
858
859         // SYNC PLUGIN EVENT LIST
860         sql_query('DELETE FROM ' . sql_table('plugin_event') );
861
862         // loop over all installed plugins
863         $res = sql_query('SELECT pid, pfile FROM ' . sql_table('plugin') );
864
865         while($o = mysql_fetch_object($res) ) {
866                 $pid = $o->pid;
867                 $plug =& $manager->getPlugin($o->pfile);
868
869                 if ($plug) {
870                         $eventList = $plug->getEventList();
871
872                         foreach ($eventList as $eventName) {
873                                 sql_query('INSERT INTO ' . sql_table('plugin_event') . ' (pid, event) VALUES (' . $pid . ', \'' . $eventName . '\')');
874                         }
875                 }
876         }
877
878         return $aErrors;
879 }
880
881 function installCustomSkins(&$manager) {
882         global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS;
883
884         $aErrors = array();
885
886         if (count($aConfSkinsToImport) == 0) {
887                 return $aErrors;
888         }
889
890         // load skinie class
891         include_once($DIR_LIBS . 'skinie.php');
892
893         $importer = new SKINIMPORT();
894
895         foreach ($aConfSkinsToImport as $skinName) {
896                 $importer->reset();
897                 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';
898
899                 if (!@file_exists($skinFile) ) {
900                         array_push($aErrors, 'Unable to import ' . $skinFile . ' : file does not exist');
901                         continue;
902                 }
903
904                 $error = $importer->readFile($skinFile);
905
906                 if ($error) {
907                         array_push($aErrors, 'Unable to import ' . $skinName . ' : ' . $error);
908                         continue;
909                 }
910
911                 $error = $importer->writeToDatabase(1);
912
913                 if ($error) {
914                         array_push($aErrors, 'Unable to import ' . $skinName . ' : ' . $error);
915                         continue;
916                 }
917         }
918
919         return $aErrors;
920 }
921
922 // give an error if one or more nucleus are not accessible
923 function doCheckFiles() {
924         $missingfiles = array();
925         $files = array(
926                 'install.sql',
927                 'index.php',
928                 'action.php',
929                 'nucleus/index.php',
930                 'nucleus/libs/globalfunctions.php',
931                 'nucleus/libs/ADMIN.php',
932                 'nucleus/libs/BLOG.php',
933                 'nucleus/libs/COMMENT.php',
934                 'nucleus/libs/COMMENTS.php',
935                 'nucleus/libs/ITEM.php',
936                 'nucleus/libs/MEMBER.php',
937                 'nucleus/libs/SKIN.php',
938                 'nucleus/libs/TEMPLATE.php',
939                 'nucleus/libs/MEDIA.php',
940                 'nucleus/libs/ACTIONLOG.php',
941                 'nucleus/media.php'
942                 );
943
944         $count = count($files);
945
946         for ($i = 0; $i < $count; $i++) {
947                 if (!is_readable($files[$i]) ) {
948                         array_push($missingfiles, 'File <b>' . $files[$i] . '</b> is missing or not readable.');
949                 }
950         }
951
952 // The above code replaces several if statements of the form:
953
954 //      if (!is_readable('install.sql') ) {
955 //              array_push($missingfiles, 'File <b>install.sql</b> is missing or not readable');
956 //      }
957
958         if (count($missingfiles) > 0) {
959                 showErrorMessages($missingfiles);
960         }
961 }
962
963 function updateConfig($name, $val) {
964         $name = addslashes($name);
965         $val = trim(addslashes($val) );
966
967         $query = 'UPDATE ' . tableName('nucleus_config')
968                         . " SET value='$val'"
969                         . " WHERE name='$name'";
970
971         mysql_query($query) or _doError('Query error while trying to update config: ' . mysql_error() );
972         return mysql_insert_id();
973 }
974
975 function replaceDoubleBackslash($input) {
976         return str_replace('\\', '/', $input);
977 }
978
979 function endsWithSlash($s) {
980         return (strrpos($s, '/') == strlen($s) - 1);
981 }
982
983 /**
984  * Checks if email address is valid
985  */
986 function _isValidMailAddress($address) {
987         if (preg_match("/^[a-zA-Z0-9\._-]+@+[A-Za-z0-9\._-]+\.+[A-Za-z]{2,4}$/", $address) ) {
988                 return 1;
989         } else {
990                 return 0;
991         }
992 }
993
994 // returns true if the given string is a valid shortname
995 // (to check short blog names and nicknames)
996 // logic: starts and ends with a non space, can contain spaces in between
997 //        min 2 chars
998 function _isValidShortName($name) {
999         if (eregi("^[a-z0-9]+$", $name) ) {
1000                 return 1;
1001         } else {
1002                 return 0;
1003         }
1004 }
1005
1006
1007
1008 // returns true if the given string is a valid display name
1009 // (to check nicknames)
1010 function _isValidDisplayName($name) {
1011         if (eregi("^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$", $name) ) {
1012                 return 1;
1013         } else {
1014                 return 0;
1015         }
1016 }
1017
1018 function _doError($msg) {
1019         ?>
1020 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1021 <html xmlns="http://www.w3.org/1999/xhtml">
1022 <head>
1023         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
1024         <title>Nucleus Install</title>
1025         <style>@import url('nucleus/styles/manual.css');</style>
1026 </head>
1027 <body>
1028         <div style='text-align:center'><img src='./nucleus/styles/logo.gif' /></div> <!-- Nucleus logo -->
1029         <h1>Error!</h1>
1030
1031         <p>Error message was: "<?php echo $msg?>";</p>
1032
1033         <p><a href="install.php" onclick="history.back();return false;">Go Back</a></p>
1034 </body>
1035 </html>
1036
1037 <?php
1038         exit;
1039 }
1040
1041 function showErrorMessages($errors) {
1042         ?>
1043 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1044 <html xmlns="http://www.w3.org/1999/xhtml">
1045 <head>
1046         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
1047         <title>Nucleus Install</title>
1048         <style>@import url('nucleus/styles/manual.css');</style>
1049 </head>
1050 <body>
1051         <div style='text-align:center'><img src='./nucleus/styles/logo.gif' /></div> <!-- Nucleus logo -->
1052         <h1>Errors!</h1>
1053
1054         <p>Errors were found:</p>
1055
1056         <ul>
1057
1058 <?php
1059         while($msg = array_shift($errors) ) {
1060                 echo '<li>', $msg, '</li>';
1061         }
1062 ?>
1063
1064         </ul>
1065
1066         <p><a href="install.php" onclick="history.back();return false;">Go Back</a></p>
1067 </body>
1068 </html>
1069
1070 <?php
1071         exit;
1072 }
1073
1074 /* for the non-php systems that decide to show the contents:
1075 ?></div><?php   */
1076
1077 ?>