OSDN Git Service

49fa8e65bfce2c4c4e45a8e17f439d2a97090c76
[nucleus-jp/nucleus-next.git] / install / index.php
1 <?php\r
2 /*\r
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
4  * Copyright (C) 2002-2012 The Nucleus Group\r
5  *\r
6  * This program is free software; you can redistribute it and/or\r
7  * modify it under the terms of the GNU General Public License\r
8  * as published by the Free Software Foundation; either version 2\r
9  * of the License, or (at your option) any later version.\r
10  * (see nucleus/documentation/index.html#license for more info)\r
11  *\r
12  * This script will install the Nucleus tables in your SQL-database,\r
13  * and initialize the data in those tables.\r
14  */\r
15 \r
16 /**\r
17  * @license http://nucleuscms.org/license.txt GNU General Public License\r
18  * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
19  * @version $Id$\r
20  */\r
21 \r
22 /* global values initialize */\r
23 $CONF = array();\r
24 \r
25 /* reporting all errors for support */\r
26 error_reporting(E_ALL);\r
27 \r
28 $minimum_php_version = '5.0.6';\r
29 $minimum_mysql_version = '3.23';\r
30 \r
31 $page_footer_copyright = '&copy; 2001-2012 The Nucleus Groupe . Running Nucleus CMS v4.00';\r
32 \r
33 // begin if: server's PHP version is below the minimum; halt installation\r
34 if ( version_compare(PHP_VERSION, $minimum_php_version, '<') )\r
35 {\r
36         exit('<div style="font-size: xx-large;"> Nucleus requires at least PHP version ' . $minimum_php_version . '</div>');\r
37 }\r
38 \r
39 // make sure there's no unnecessary escaping: # set_magic_quotes_runtime(0);\r
40 if ( version_compare(PHP_VERSION, '5.3.0', '<') )\r
41 {\r
42         ini_set('magic_quotes_runtime', '0');\r
43 }\r
44 \r
45 /* default installed plugins and skins */\r
46 $aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles', 'NP_Text');\r
47 $aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default');\r
48 \r
49 // Check if some important files\r
50 do_check_files();\r
51 \r
52 /* i18n class is needed for internationalization */\r
53 include_once('../nucleus/libs/i18n.php');\r
54 if ( !i18n::init('UTF-8', './locales') )\r
55 {\r
56         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
57 }\r
58 \r
59 // check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x\r
60 if ( !function_exists('mysql_query') && !function_exists('mysqli_query') )\r
61 {\r
62         exit('<div style="font-size: xx-large;"> Your PHP version does not have support for MySQL :( </div>');\r
63 }\r
64 \r
65 // include core classes that are needed for login & plugin handling\r
66 include_once('../nucleus/libs/mysql.php');\r
67 \r
68 // added for 3.5 sql_* wrapper\r
69 global $MYSQL_HANDLER;\r
70 \r
71 if ( !isset($MYSQL_HANDLER) )\r
72 {\r
73         $MYSQL_HANDLER = array('mysql', '');\r
74 }\r
75 include_once('../nucleus/libs/sql/' . $MYSQL_HANDLER[0] . '.php');\r
76 \r
77 session_start();\r
78 if ( count($_GET) == 0 && count($_POST) == 0 )\r
79 {\r
80         unset($_SESSION['param_manager']);\r
81 }\r
82 \r
83 // restore the $param from the session\r
84 if ( array_key_exists('param_manager', $_SESSION) )\r
85 {\r
86         $param = $_SESSION['param_manager'];\r
87 }\r
88 else\r
89 {\r
90         $param = new ParamManager();\r
91 }\r
92 \r
93 // include translation file\r
94 if ( array_key_exists('locale', $_POST) ) $param->set_locale();\r
95 i18n::set_current_locale($param->locale);\r
96 $translation_file = './locales/' . i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php';\r
97 if ( !file_exists($translation_file) )\r
98 {\r
99         $translation_file = './locales/en_Latn_US.UTF-8.php';\r
100 }\r
101 include($translation_file);\r
102 \r
103 do_action();\r
104 \r
105 // $param is saved to the session\r
106 if ( isset($param) )\r
107 {\r
108         $_SESSION['param_manager'] = $param;\r
109 }\r
110 else\r
111 {\r
112         unset($_SESSION['param_manager']);\r
113 }\r
114 exit;\r
115 \r
116 /**\r
117  * installer action\r
118  */\r
119 function do_action()\r
120 {\r
121         global $param;\r
122 \r
123         if ( array_key_exists('action', $_POST) )\r
124         {\r
125                 $isPostback = true;\r
126         }\r
127         else\r
128         {\r
129                 $isPostback = false;\r
130         }\r
131 \r
132         // mode change\r
133         if ( array_key_exists('mode', $_REQUEST) )\r
134         {\r
135                 if ( $_REQUEST['mode'] == 'detail' )\r
136                 {\r
137                         $param->set_state('detail');\r
138                 }\r
139                 elseif ( $_REQUEST['mode'] == 'simple' )\r
140                 {\r
141                         $param->set_state('mysql');\r
142                 }\r
143         }\r
144 \r
145         // input parameter check\r
146         if ( $isPostback )\r
147         {\r
148                 switch ( $param->state )\r
149                 {\r
150                         case 'locale':\r
151                                 $param->set_locale();\r
152                                 $param->set_state('mysql');\r
153                                 $isPostback = false;\r
154                                 break;\r
155                         case 'mysql':\r
156                                 if ( count($param->check_mysql_parameters()) == 0 )\r
157                                 {\r
158                                         $param->set_state('weblog');\r
159                                         $isPostback = false;\r
160                                 }\r
161                                 break;\r
162                         case 'weblog':\r
163                                 if ( count($param->check_user_parameters()) == 0 && count($param->check_weblog_parameters()) == 0 )\r
164                                 {\r
165                                         $param->set_state('install');\r
166                                         $isPostback = false;\r
167                                 }\r
168                                 break;\r
169                         case 'detail':\r
170                                 if ( $param->check_all_parameters() )\r
171                                 {\r
172                                         $param->set_state('install');\r
173                                         $isPostback = false;\r
174                                 }\r
175                                 break;\r
176                 }\r
177         }\r
178 \r
179         // page render\r
180         show_header();\r
181         switch ( $param->state )\r
182         {\r
183                 case 'locale':\r
184                         show_select_locale_form();\r
185                         break;\r
186                 case 'mysql':\r
187                         show_database_setting_form($isPostback);\r
188                         break;\r
189                 case 'weblog':\r
190                         show_blog_setting_form($isPostback);\r
191                         break;\r
192                 case 'detail':\r
193                         show_detail_setting_form($isPostback);\r
194                         break;\r
195                 case 'install':\r
196                         show_install_complete_form();\r
197                         break;\r
198         }\r
199         show_footer();\r
200 }\r
201 \r
202 /**\r
203  * header tag of the installation screens\r
204  **/\r
205 function show_header()\r
206 {\r
207         global $param;\r
208 \r
209         /* HTTP 1.1 application for no caching */\r
210         header("Cache-Control: no-cache, must-revalidate");\r
211         header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");\r
212         header('Content-Type: text/html; charset=' . i18n::get_current_charset());\r
213 ?>\r
214 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
215 <html xmlns="http://www.w3.org/1999/xhtml">\r
216         <head>\r
217                 <title><?php echo _TITLE; ?></title>\r
218                 <link rel="stylesheet" type="text/css" href="./styles/inst.css" />\r
219                 <style type="text/css">\r
220                 <!--\r
221                 <?php echo _BODYFONTSTYLE; ?>\r
222                 -->\r
223                 </style>\r
224                 <script type="text/javascript">\r
225                         function SelectText( element ) {\r
226                                 window.setTimeout( function() { element.select() }, 0 );\r
227                         }\r
228                         var isSubmit = false;\r
229                         function OnceSubmit() {\r
230                                 if (!isSubmit) {\r
231                                         isSubmit = true;\r
232                                         window.setTimeout( function() { isSubmit = false; }, 10000 );\r
233                                         return true;\r
234                                 }\r
235                                 return false;\r
236                         }\r
237                 </script>\r
238         </head>\r
239         <body>\r
240                 <div id="header">\r
241                         <div id="navigation">\r
242                                 <h1><img src="./styles/nucleus_rogo.png" alt="NucleusCMS" /></h1>\r
243                                 <ul>\r
244 <?php\r
245         if ( in_array($param->state, array('mysql', 'weblog', 'install')) )\r
246         {\r
247                 echo '<li>', _STEP1, '</li><li';\r
248                 if ( $param->state == 'mysql' )\r
249                 {\r
250                         echo ' class="gry"';\r
251                 }\r
252                 echo '>&nbsp; &gt; &nbsp;', _STEP2, '</li><li';\r
253                 if ( in_array($param->state, array('mysql', 'weblog')) )\r
254                 {\r
255                         echo ' class="gry"';\r
256                 }\r
257                 echo '>&nbsp; &gt; &nbsp;', _STEP3, "</li>\n";\r
258         }\r
259         if ( in_array($param->state, array('mysql', 'weblog', 'detail')) )\r
260         {\r
261                 echo '<li class="rightbox">';\r
262                 if ( in_array($param->state, array('mysql', 'weblog')) )\r
263                 {\r
264                         echo '<a href="./?mode=detail">', _MODE2, '</a>';\r
265                 }\r
266                 else\r
267                 {\r
268                         echo '<a href="./?mode=simple">', _MODE1, '</a>';\r
269                 }\r
270                 echo '</li>';\r
271         }\r
272 ?>\r
273                                 </ul>\r
274                         </div>\r
275                 </div>\r
276 <?php\r
277 }\r
278 \r
279 /**\r
280  * footer tag of the installation screens\r
281  **/\r
282 function show_footer()\r
283 {\r
284         global $page_footer_copyright;\r
285 ?>\r
286                 <div id="footer">\r
287                         <?php echo $page_footer_copyright; ?>\r
288                 </div>\r
289         </body>\r
290 </html>\r
291 <?php\r
292 }\r
293 \r
294 /**\r
295  * Display the form for language select\r
296  */\r
297 function show_select_locale_form()\r
298 {\r
299         // Get the browser language that can be displayed\r
300         // TODO: default locale select simple implementation\r
301         $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);\r
302         foreach ( $languages as $language )\r
303         {\r
304                 $language = preg_replace('#([\w]+).*#', '$1', $language);\r
305                 break;\r
306         }\r
307 \r
308         $locales = array(\r
309                 array('en_Latn_US', 'English - United States'),\r
310                 array('ja_Jpan_JP', 'Japanese - Japan')\r
311         );\r
312 ?>\r
313                 <div id="container">\r
314                         <p style="font-size:152%;font-weight:bold;">\r
315                                 Select your locale:\r
316                         </p>\r
317                         <form method="post" action="./index.php">\r
318 \r
319                                 <div class="prt">\r
320                                         <select name="locale">\r
321 <?php\r
322         foreach ( $locales as $locale )\r
323         {\r
324                 echo "<option value=\"$locale[0]\"";\r
325                 if ( i18n::strpos($locale[0], $language) === 0 )\r
326                 {\r
327                         echo ' selected';\r
328                 }\r
329                 echo ">$locale[1]</option>\n";\r
330         }\r
331 ?>\r
332                                         </select>\r
333                                         <p class="sbt">\r
334                                                 <button type="submit" name="action" value="locale" class="sbt_arw">START</button>\r
335                                         </p>\r
336                                 </div>\r
337                         </form>\r
338                 </div>\r
339 <?php\r
340 }\r
341 \r
342 /**\r
343  * Display the form to set up a database\r
344  * @param bool $isPostback\r
345  */\r
346 function show_database_setting_form($isPostback)\r
347 {\r
348         global $param, $minimum_mysql_version;\r
349 \r
350         $config_writable = canConfigFileWritable();\r
351         $mysql_version = getMySqlVersion();\r
352 ?>\r
353                 <div id="container">\r
354                         <p class="msg">\r
355 <?php\r
356         echo _SIMPLE_NAVI1;\r
357         if ( $config_writable != '' )\r
358         {\r
359                 echo '<span class="err">', $config_writable, '</span>';\r
360         }\r
361         if ( $mysql_version == '0.0.0' )\r
362         {\r
363                 echo '<span class="err">', _DBVERSION_UNKOWN, '</span>';\r
364         }\r
365         elseif ( version_compare($mysql_version, $minimum_mysql_version, '<') )\r
366         {\r
367                 echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';\r
368         }\r
369 ?>\r
370                         </p>\r
371                         <form method="post" action="./index.php">\r
372                                 <div class="prt">\r
373                                         <h2><?php echo _DB_HEADER; ?></h2>\r
374                                         <p class="msg">\r
375 <?php\r
376         if ( $isPostback )\r
377         {\r
378                 $errors = $param->check_mysql_parameters();\r
379                 if ( is_array($errors) )\r
380                 {\r
381                         foreach ( $errors as $error )\r
382                         {\r
383                                 echo '<span class="err">', $error, "</span>\n";\r
384                         }\r
385                 }\r
386         }\r
387 ?>\r
388                                         </p>\r
389                                         <table>\r
390                                                 <tr>\r
391                                                         <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>\r
392                                                                 <td><input type="text" name="mysql_host" value="<?php echo $param->mysql_host; ?>" /></td>\r
393                                                 </tr>\r
394                                                 <tr>\r
395                                                         <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>\r
396                                                                 <td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>\r
397                                                 </tr>\r
398                                                 <tr>\r
399                                                         <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>\r
400                                                                 <td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>\r
401                                                 </tr>\r
402                                                 <tr>\r
403                                                         <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>\r
404                                                                 <td><input type="text" name="mysql_database" value="<?php echo $param->mysql_database; ?>" /></td>\r
405                                                 </tr>\r
406                                         </table>\r
407                                         <p class="sbt">\r
408                                                 <button type="submit" name="mode" value="detail" class="sbt_sqr"><?php echo _MODE2; ?></button>\r
409                                                 <button type="submit" name="action" value="mysql" class="sbt_arw"><?php echo _NEXT; ?></button>\r
410                                         </p>\r
411                                         <p class="msg">\r
412                                                 <?php echo _DB_TEXT1; ?>\r
413                                         </p>\r
414                                 </div>\r
415                         </form>\r
416                 </div>\r
417 <?php\r
418 }\r
419 \r
420 /**\r
421  * Displays a form to the blog settings\r
422  * @param bool $isPostback\r
423  */\r
424 function show_blog_setting_form($isPostback)\r
425 {\r
426         global $param;\r
427 ?>\r
428                 <div id="container">\r
429                         <p class="msg">\r
430                                 <?php echo _SIMPLE_NAVI2; ?>\r
431                         </p>\r
432                         <form method="post" action="./index.php">\r
433                                 <div class="prt">\r
434                                         <h2><?php echo _BLOG_HEADER; ?></h2>\r
435                                         <p class="msg">\r
436 <?php\r
437         if ( $isPostback )\r
438         {\r
439                 $errors = $param->check_weblog_parameters();\r
440                 if ( is_array($errors) )\r
441                 {\r
442                         foreach ( $errors as $error )\r
443                         {\r
444                                 echo '<span class="err">', $error, "</span>\n";\r
445                         }\r
446                 }\r
447         }\r
448 ?>\r
449                                         </p>\r
450                                         <table>\r
451                                                 <tr>\r
452                                                         <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>\r
453                                                                 <td><input type="text" name="blog_name" value="<?php echo $param->blog_name; ?>" /></td>\r
454                                                 </tr>\r
455                                                 <tr>\r
456                                                         <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>\r
457                                                                 <td><input type="text" name="blog_shortname" value="<?php echo $param->blog_shortname; ?>" /></td>\r
458                                                 </tr>\r
459                                         </table>\r
460                                 </div>\r
461 \r
462                                 <div class="prt">\r
463                                         <h2><?php echo _ADMIN_HEADER; ?></h2>\r
464                                         <p class="msg">\r
465 <?php\r
466         if ( $isPostback )\r
467         {\r
468                 $errors = $param->check_user_parameters();\r
469                 if ( is_array($errors) )\r
470                 {\r
471                         foreach ( $errors as $error )\r
472                         {\r
473                                 echo '<span class="err">', $error, "</span>\n";\r
474                         }\r
475                 }\r
476         }\r
477 ?>\r
478                                         </p>\r
479                                         <table>\r
480                                                 <tr>\r
481                                                         <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>\r
482                                                                 <td><input type="text" name="user_realname" value="<?php echo $param->user_realname; ?>" /></td>\r
483                                                 </tr>\r
484                                                 <tr>\r
485                                                         <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>\r
486                                                                 <td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>\r
487                                                 </tr>\r
488                                                 <tr>\r
489                                                         <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>\r
490                                                                 <td><input type="password" name="user_password" /></td>\r
491                                                 </tr>\r
492                                                 <tr>\r
493                                                         <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>\r
494                                                                 <td><input type="password" name="user_password2" /></td>\r
495                                                 </tr>\r
496                                                 <tr>\r
497                                                         <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>\r
498                                                                 <td><input type="text" name="user_email" value="<?php echo $param->user_email; ?>" /></td>\r
499                                                 </tr>\r
500                                         </table>\r
501                                         <p class="sbt">\r
502                                                 <button type="submit" name="action" value="weblog" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>\r
503                                         </p>\r
504                                 </div>\r
505                         </form>\r
506                 </div>\r
507 <?php\r
508 }\r
509 \r
510 /**\r
511  * Displays a form to the detail settings\r
512  * @param bool $isPostback\r
513  */\r
514 function show_detail_setting_form($isPostback)\r
515 {\r
516         global $param, $minimum_mysql_version;\r
517 \r
518         $mysql_version = getMySqlVersion();\r
519 ?>\r
520                 <div id="container_detailed">\r
521                         <p class="msg">\r
522                                 <?php echo _DETAIL_NAVI1; ?>\r
523 <?php\r
524         if ( $isPostback && !$param->check_all_parameters() )\r
525         {\r
526                 echo '<span class="err">', _VALID_ERROR, "</span>\n";\r
527         }\r
528 ?>\r
529                         </p>\r
530                         <ul class="msg">\r
531                                 <li>PHP: <?php echo phpversion(); ?></li>\r
532                                 <li>MySQL:\r
533 <?php\r
534         echo ($mysql_version == '0.0.0') ? _DBVERSION_UNKOWN : $mysql_version;\r
535         if ( version_compare($mysql_version, $minimum_mysql_version, '<') )\r
536         {\r
537                 echo '<span class="err">', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), '</span>';\r
538         }\r
539 ?></li>\r
540                         </ul>\r
541                         <form method="post" action="">\r
542 \r
543                                 <div class="prt">\r
544                                         <h2><?php echo _DETAIL_HEADER1; ?></h2>\r
545                                         <p class="msg">\r
546 <?php\r
547         if ( $isPostback )\r
548         {\r
549                 $errors = $param->check_mysql_parameters();\r
550                 if ( is_array($errors) )\r
551                 {\r
552                         foreach ( $errors as $error )\r
553                         {\r
554                                 echo '<span class="err">', $error, "</span>\n";\r
555                         }\r
556                 }\r
557         }\r
558 ?>\r
559                                         </p>\r
560                                         <table>\r
561                                                 <tr>\r
562                                                         <th><span class="nam"><?php echo _DB_FIELD1; ?></span><span class="sub"><?php echo _DB_FIELD1_DESC; ?></span></th>\r
563                                                                 <td><input type="text" name="mysql_host" value="<?php echo $param->mysql_host; ?>" /></td>\r
564                                                 </tr>\r
565                                                 <tr>\r
566                                                         <th><span class="nam"><?php echo _DB_FIELD2; ?></span><span class="sub"><?php echo _DB_FIELD2_DESC; ?></span></th>\r
567                                                                 <td><input type="text" name="mysql_user" value="<?php echo $param->mysql_user; ?>" /></td>\r
568                                                 </tr>\r
569                                                 <tr>\r
570                                                         <th><span class="nam"><?php echo _DB_FIELD3; ?></span></th>\r
571                                                                 <td><input type="text" name="mysql_password" value="<?php echo $param->mysql_password; ?>" /></td>\r
572                                                 </tr>\r
573                                                 <tr>\r
574                                                         <th><span class="nam"><?php echo _DB_FIELD4; ?></span><span class="sub"><?php echo _DB_FIELD4_DESC; ?></span></th>\r
575                                                                 <td><input type="text" name="mysql_database" value="<?php echo $param->mysql_database; ?>" /></td>\r
576                                                 </tr>\r
577                                                 <tr>\r
578                                                         <th><span class="nam"><?php echo _DB_FIELD5; ?></span><span class="sub"><?php echo _DB_FIELD5_DESC; ?></span></th>\r
579                                                                 <td><input type="text" name="mysql_tablePrefix" value="<?php echo $param->mysql_tablePrefix; ?>" /></td>\r
580                                                 </tr>\r
581                                         </table>\r
582 \r
583                                         <h2><?php echo _DETAIL_HEADER2; ?></h2>\r
584                                         <p class="msg">\r
585 <?php\r
586         if ( $isPostback )\r
587         {\r
588                 $errors = $param->check_uri_parameters();\r
589                 if ( is_array($errors) )\r
590                 {\r
591                         foreach ( $errors as $error )\r
592                         {\r
593                                 echo '<span class="err">', $error, "</span>\n";\r
594                         }\r
595                 }\r
596                 $errors = $param->check_path_parameters();\r
597                 if ( is_array($errors) )\r
598                 {\r
599                         foreach ( $errors as $error )\r
600                         {\r
601                                 echo '<span class="err">', $error, "</span>\n";\r
602                         }\r
603                 }\r
604         }\r
605 ?>\r
606                                         </p>\r
607                                         <table>\r
608                                                 <tr>\r
609                                                         <th><span class="nam"><?php echo _PATH_FIELD1; ?></span></th>\r
610                                                                 <td><input type="text" name="IndexURL" value="<?php echo $param->IndexURL; ?>" /></td>\r
611                                                 </tr>\r
612                                                 <tr>\r
613                                                         <th><span class="nam"><?php echo _PATH_FIELD2; ?></span></th>\r
614                                                                 <td><input type="text" name="AdminURL" value="<?php echo $param->AdminURL; ?>" /></td>\r
615                                                 </tr>\r
616                                                 <tr>\r
617                                                         <th><span class="nam"><?php echo _PATH_FIELD3; ?></span></th>\r
618                                                                 <td><input type="text" name="AdminPath" value="<?php echo $param->AdminPath; ?>" /></td>\r
619                                                 </tr>\r
620                                                 <tr>\r
621                                                         <th><span class="nam"><?php echo _PATH_FIELD4; ?></span></th>\r
622                                                                 <td><input type="text" name="MediaURL" value="<?php echo $param->MediaURL; ?>" /></td>\r
623                                                 </tr>\r
624                                                 <tr>\r
625                                                         <th><span class="nam"><?php echo _PATH_FIELD5; ?></span></th>\r
626                                                                 <td><input type="text" name="MediaPath" value="<?php echo $param->MediaPath; ?>" /></td>\r
627                                                 </tr>\r
628                                                 <tr>\r
629                                                         <th><span class="nam"><?php echo _PATH_FIELD6; ?></span></th>\r
630                                                                 <td><input type="text" name="SkinsURL" value="<?php echo $param->SkinsURL; ?>" /></td>\r
631                                                 </tr>\r
632                                                 <tr>\r
633                                                         <th><span class="nam"><?php echo _PATH_FIELD7; ?></span></th>\r
634                                                                 <td><input type="text" name="SkinsPath" value="<?php echo $param->SkinsPath; ?>" /></td>\r
635                                                 </tr>\r
636                                                 <tr>\r
637                                                         <th><span class="nam"><?php echo _PATH_FIELD8; ?></span></th>\r
638                                                                 <td><input type="text" name="PluginURL" value="<?php echo $param->PluginURL; ?>" /></td>\r
639                                                 </tr>\r
640                                                 <tr>\r
641                                                         <th><span class="nam"><?php echo _PATH_FIELD9; ?></span></th>\r
642                                                                 <td><input type="text" name="ActionURL" value="<?php echo $param->ActionURL; ?>" /></td>\r
643                                                 </tr>\r
644                                         </table>\r
645                                         <p class="msg">\r
646                                                 <?php echo _DETAIL_TEXT3; ?>\r
647                                         </p>\r
648 \r
649                                         <h2><?php echo _DETAIL_HEADER3; ?></h2>\r
650                                         <p class="msg">\r
651 <?php\r
652         echo _DETAIL_TEXT4;\r
653         if ( $isPostback )\r
654         {\r
655                 $errors = $param->check_user_parameters();\r
656                 if ( is_array($errors) )\r
657                 {\r
658                         foreach ( $errors as $error )\r
659                         {\r
660                                 echo '<span class="err">', $error, "</span>\n";\r
661                         }\r
662                 }\r
663         }\r
664 ?>\r
665                                         </p>\r
666                                         <table>\r
667                                                 <tr>\r
668                                                         <th><span class="nam"><?php echo _ADMIN_FIELD1; ?></span></th>\r
669                                                                 <td><input type="text" name="user_realname" value="<?php echo $param->user_realname; ?>" /></td>\r
670                                                 </tr>\r
671                                                 <tr>\r
672                                                         <th><span class="nam"><?php echo _ADMIN_FIELD2; ?></span><span class="sub"><?php echo _ADMIN_FIELD2_DESC; ?></span></th>\r
673                                                                 <td><input type="text" name="user_name" value="<?php echo $param->user_name; ?>" /></td>\r
674                                                 </tr>\r
675                                                 <tr>\r
676                                                         <th><span class="nam"><?php echo _ADMIN_FIELD3; ?></span></th>\r
677                                                                 <td><input type="password" name="user_password" /></td>\r
678                                                 </tr>\r
679                                                 <tr>\r
680                                                         <th><span class="nam"><?php echo _ADMIN_FIELD4; ?></span></th>\r
681                                                                 <td><input type="password" name="user_password2" /></td>\r
682                                                 </tr>\r
683                                                 <tr>\r
684                                                         <th><span class="nam"><?php echo _ADMIN_FIELD5; ?></span></th>\r
685                                                                 <td><input type="text" name="user_email" value="<?php echo $param->user_email; ?>" /></td>\r
686                                                 </tr>\r
687                                         </table>\r
688 \r
689                                         <h2><?php echo _DETAIL_HEADER4; ?></h2>\r
690                                         <p class="msg">\r
691 <?php\r
692         echo _DETAIL_TEXT5;\r
693         if ( $isPostback )\r
694         {\r
695                 $errors = $param->check_weblog_parameters();\r
696                 if ( is_array($errors) )\r
697                 {\r
698                         foreach ( $errors as $error )\r
699                         {\r
700                                 echo '<span class="err">', $error, "</span>\n";\r
701                         }\r
702                 }\r
703         }\r
704 ?>\r
705                                         </p>\r
706                                         <table>\r
707                                                 <tr>\r
708                                                         <th><span class="nam"><?php echo _BLOG_FIELD1; ?></span></th>\r
709                                                                 <td><input type="text" name="blog_name" value="<?php echo $param->blog_name; ?>" /></td>\r
710                                                 </tr>\r
711                                                 <tr>\r
712                                                         <th><span class="nam"><?php echo _BLOG_FIELD2; ?></span><span class="sub"><?php echo _BLOG_FIELD2_DESC; ?></span></th>\r
713                                                                 <td><input type="text" name="blog_shortname" value="<?php echo $param->blog_shortname; ?>" /></td>\r
714                                                 </tr>\r
715                                         </table>\r
716 \r
717                                         <p class="msg">\r
718                                                 <?php echo _DETAIL_TEXT6; ?>\r
719                                         </p>\r
720 \r
721                                         <p class="sbt">\r
722                                                 <button type="submit" name="action" value="detail" class="sbt_arw" onclick="OnceSubmit()"><?php echo _INSTALL; ?></button>\r
723                                         </p>\r
724                                 </div>\r
725                         </form>\r
726                 </div>\r
727 <?php\r
728 }\r
729 \r
730 /**\r
731  * Displays a screen to signal the completion of the installation\r
732  */\r
733 function show_install_complete_form()\r
734 {\r
735         global $MYSQL_HANDLER, $param;\r
736         $errors = do_install();\r
737 ?>\r
738                 <div id="container">\r
739                         <p class="msg">\r
740 <?php\r
741         if ( is_array($errors) && count($errors) > 0 )\r
742         {\r
743                 echo _INST_ERROR;\r
744                 foreach ( $errors as $error )\r
745                 {\r
746                         echo '<span class="err">', $error, "</span>\n";\r
747                 }\r
748         }\r
749         else\r
750         {\r
751                 echo _INST_TEXT;\r
752                 if ( array_key_exists('config_data', $_SESSION) )\r
753                 {\r
754                         echo '<span class="err">', _INST_TEXT4, '</span>';\r
755 ?>\r
756 <textarea id="config_text" readonly="readonly" onfocus="SelectText(this);"><?php echo htmlentities($_SESSION['config_data'], null, i18n::get_current_charset()) ?></textarea>\r
757 <?php\r
758                 }\r
759                 else\r
760                 {\r
761                         echo '<span class="err">', _INST_TEXT5, '</span>';\r
762                 }\r
763 ?>\r
764                         </p>\r
765                         <form method="post" action="./index.php">\r
766                                 <div class="prt">\r
767                                         <h2><?php echo _INST_HEADER1; ?></h2>\r
768                                         <p class="msg">\r
769                                                 <?php echo sprintf(_INST_TEXT1, $param->blog_name); ?>\r
770                                         </p>\r
771                                         <p class="sbt">\r
772                                                 <button type="button" name="toBlog" onclick="location.href='<?php echo $param->IndexURL; ?>';" class="sbt_arw"><?php echo _INST_BUTTON1; ?></button>\r
773                                         </p>\r
774                                 </div>\r
775 \r
776                                 <div class="prt">\r
777                                         <h2><?php echo _INST_HEADER2; ?></h2>\r
778                                         <p class="msg">\r
779                                                 <?php echo _INST_TEXT2; ?>\r
780                                         </p>\r
781                                         <p class="sbt">\r
782                                                 <button type="button" name="toMng" onclick="location.href='<?php echo $param->AdminURL; ?>';" class="sbt_arw"><?php echo _INST_BUTTON2; ?></button>\r
783                                         </p>\r
784                                 </div>\r
785 \r
786                                 <div class="prt">\r
787                                         <h2><?php echo _INST_HEADER3; ?></h2>\r
788                                         <p class="msg">\r
789                                                 <?php echo _INST_TEXT3; ?>\r
790                                         </p>\r
791                                         <p class="sbt">\r
792                                                 <button type="button" name="toAddBlog" onclick="location.href='<?php echo $param->AdminURL; ?>index.php?action=createnewlog';" class="sbt_arw"><?php echo _INST_BUTTON3; ?></button>\r
793                                         </p>\r
794                                 </div>\r
795                         </form>\r
796 <?php\r
797         }\r
798 ?>\r
799                 </div>\r
800 <?php\r
801         unset($param);\r
802 }\r
803 \r
804 /**\r
805  * The installation process itself\r
806  * @return array error messages\r
807  */\r
808 function do_install()\r
809 {\r
810         global $param;\r
811         global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX, $MYSQL_CONN;\r
812         global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;\r
813         $errors = array();\r
814 \r
815         /*\r
816          * 1. put all param-vars into vars\r
817          */\r
818         $MYSQL_HOST     = $param->mysql_host;\r
819         $MYSQL_USER     = $param->mysql_user;\r
820         $MYSQL_PASSWORD = $param->mysql_password;\r
821         $MYSQL_DATABASE = $param->mysql_database;\r
822         $MYSQL_PREFIX   = $param->mysql_tablePrefix;\r
823 \r
824         $DIR_NUCLEUS = $param->AdminPath;\r
825         $DIR_MEDIA   = $param->MediaPath;\r
826         $DIR_SKINS   = $param->SkinsPath;\r
827         $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';\r
828         $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';\r
829         $DIR_LIBS    = $DIR_NUCLEUS . 'libs/';\r
830 \r
831         /*\r
832          * 2.open mySQL connection\r
833          */\r
834         $MYSQL_CONN = @sql_connect_args($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);\r
835         if ( $MYSQL_CONN == false )\r
836         {\r
837                 $errors[] = _DBCONNECT_ERROR;\r
838                 return $errors;\r
839         }\r
840 \r
841         /*\r
842          * 3. try to create database if needed\r
843          */\r
844         if ( !sql_query("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") )\r
845         {\r
846                 $errors[] = _INST_ERROR1 . ': ' . sql_error();\r
847         }\r
848 \r
849         /*\r
850          * 4. try to select database\r
851          */\r
852         if ( !sql_select_db($MYSQL_DATABASE) )\r
853         {\r
854                 $errors[] = _INST_ERROR2;\r
855         }\r
856         sql_set_charset('utf8');\r
857 \r
858         if ( count($errors) > 0 )\r
859         {\r
860                 return $errors;\r
861         }\r
862 \r
863         /*\r
864          * 5. execute queries\r
865          */\r
866         $table_names = array(\r
867                 'nucleus_actionlog',\r
868                 'nucleus_ban',\r
869                 'nucleus_blog',\r
870                 'nucleus_category',\r
871                 'nucleus_comment',\r
872                 'nucleus_config',\r
873                 'nucleus_item',\r
874                 'nucleus_karma',\r
875                 'nucleus_member',\r
876                 'nucleus_plugin',\r
877                 'nucleus_skin',\r
878                 'nucleus_template',\r
879                 'nucleus_team',\r
880                 'nucleus_activation',\r
881                 'nucleus_tickets'\r
882         );\r
883 \r
884         $prefixed_table_names = array();\r
885         foreach ( $table_names as $table_name )\r
886         {\r
887                 $prefixed_table_names[] = $MYSQL_PREFIX . $table_name;\r
888         }\r
889 \r
890         // table exists check\r
891         $result = sql_query('SHOW TABLES');\r
892         while ( $row = mysql_fetch_array($result, MYSQL_NUM) )\r
893         {\r
894                 if ( in_array($row[0], $prefixed_table_names) )\r
895                 {\r
896                         $errors[] = _INST_ERROR3;\r
897                         break;\r
898                 }\r
899         }\r
900         if ( count($errors) > 0 )\r
901         {\r
902                 return $errors;\r
903         }\r
904 \r
905         $filename = 'install.sql';\r
906         $fd = fopen($filename, 'r');\r
907         $queries = fread($fd, filesize($filename));\r
908         fclose($fd);\r
909 \r
910         $queries = preg_split('#(;\n|;\r)#', $queries);\r
911 \r
912         foreach ( $queries as $query )\r
913         {\r
914                 if ( preg_match('/\w+/', $query) )\r
915                 {\r
916                         if ( $MYSQL_PREFIX )\r
917                         {\r
918                                 $query = str_replace($table_names, $prefixed_table_names, $query);\r
919                         }\r
920 \r
921                         if ( !sql_query($query) )\r
922                         {\r
923                                 $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . sql_error();\r
924                         }\r
925                 }\r
926         }\r
927 \r
928         /*\r
929          * 6. put needed records\r
930          */\r
931         /* push first post */\r
932         $query = "INSERT INTO %s VALUES (1, '%s', '%s', '%s', 1, 1, '%s', 0, 0, 0, 1, 0, 1)";\r
933         $query = sprintf($query, tableName('nucleus_item'), _1ST_POST_TITLE, _1ST_POST, _1ST_POST2, i18n::formatted_datetime('mysql', time()));\r
934         if ( !sql_query($query) )\r
935         {\r
936                 $errors[] = _INST_ERROR4 . ' (<small>' . $newpost . '</small>): ' . sql_error();\r
937         }\r
938 \r
939         /* push configurations */\r
940         array_merge($errors, updateConfig('IndexURL', $param->IndexURL));\r
941         array_merge($errors, updateConfig('AdminURL', $param->AdminURL));\r
942         array_merge($errors, updateConfig('MediaURL', $param->MediaURL));\r
943         array_merge($errors, updateConfig('SkinsURL', $param->SkinsURL));\r
944         array_merge($errors, updateConfig('PluginURL', $param->PluginURL));\r
945         array_merge($errors, updateConfig('ActionURL', $param->ActionURL));\r
946         array_merge($errors, updateConfig('AdminEmail', $param->user_email));\r
947         array_merge($errors, updateConfig('SiteName', $param->blog_name));\r
948         array_merge($errors, updateConfig('Locale', i18n::get_current_locale()));\r
949 \r
950         /* escape strings for SQL */\r
951         $user_name       = sql_real_escape_string($param->user_name);\r
952         $user_realname   = sql_real_escape_string($param->user_realname);\r
953         $user_password   = sql_real_escape_string(md5($param->user_password));\r
954         $user_email      = sql_real_escape_string($param->user_email);\r
955         $blog_name       = sql_real_escape_string($param->blog_name);\r
956         $blog_shortname  = sql_real_escape_string($param->blog_shortname);\r
957         $config_indexurl = sql_real_escape_string($param->IndexURL);\r
958 \r
959         /* push super admin */\r
960         $query = "UPDATE %s SET mname = '%s', mrealname = '%s', mpassword = '%s', memail = '%s', murl = '%s', madmin = 1, mcanlogin = 1 WHERE mnumber = 1";\r
961         $query = sprintf($query, tableName('nucleus_member'), $user_name, $user_realname, $user_password, $user_email, $config_indexurl);\r
962         if ( !sql_query($query) )\r
963         {\r
964                 $errors[] = _INST_ERROR5 . ': ' . sql_error();\r
965         }\r
966 \r
967         /* push new weblog */\r
968         $query = "UPDATE %s SET bname = '%s', bshortname = '%s', burl = '%s' WHERE bnumber = 1";\r
969         $query = sprintf($query, tableName('nucleus_blog'), $blog_name, $blog_shortname, $config_indexurl);\r
970         if ( !sql_query($query) )\r
971         {\r
972                 $errors[] = _INST_ERROR6 . ': ' . sql_error();\r
973         }\r
974 \r
975         /* push default category */\r
976         $query = "UPDATE %s SET cname = '%s', cdesc = '%s' WHERE catid = 1";\r
977         $query = sprintf($query, tableName('nucleus_category'), _GENERALCAT_NAME, _GENERALCAT_DESC);\r
978         if ( !sql_query($query) )\r
979         {\r
980                 $errors[] = _INST_ERROR6 . ': ' . sql_error();\r
981         }\r
982 \r
983         sql_close();\r
984 \r
985         /*\r
986          * 7. install default plugins and skins\r
987          */\r
988         global $aConfPlugsToInstall, $aConfSkinsToImport;\r
989         $aSkinErrors = array();\r
990         $aPlugErrors = array();\r
991 \r
992         if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) )\r
993         {\r
994                 include_once($DIR_LIBS . 'globalfunctions.php');\r
995                 global $manager;\r
996                 if ( !isset($manager) )\r
997                 {\r
998                         $manager = new Manager();\r
999                 }\r
1000 \r
1001                 include_once($DIR_LIBS . 'skinie.php');\r
1002 \r
1003                 $aSkinErrors = installCustomSkins();\r
1004                 if ( count($aSkinErrors) > 0 )\r
1005                 {\r
1006                         array_merge($errors, $aSkinErrors);\r
1007                 }\r
1008 \r
1009                 $query = "SELECT sdnumber FROM %s WHERE sdname='default'";\r
1010                 $query = sprintf($query, tableName('nucleus_skin_desc'));\r
1011                 $res = sql_query($query);\r
1012                 $obj = sql_fetch_assoc($res);\r
1013                 $defSkinID = (integer) $obj['sdnumber'];\r
1014 \r
1015                 $query = "UPDATE %s SET bdefskin=%d WHERE bnumber=1";\r
1016                 $query = sprintf($query, tableName('nucleus_blog'), $defSkinID);\r
1017                 sql_query($query);\r
1018                 $query = "UPDATE %s SET value=%d WHERE name='BaseSkin'";\r
1019                 $query = sprintf($query, tableName('nucleus_config'), $defSkinID);\r
1020                 sql_query($query);\r
1021 \r
1022                 $aPlugErrors = installCustomPlugs();\r
1023                 if ( count($aPlugErrors) > 0 )\r
1024                 {\r
1025                         array_merge($errors, $aPlugErrors);\r
1026                 }\r
1027         }\r
1028 \r
1029         /*\r
1030          * 8. Write config file ourselves (if possible)\r
1031          */\r
1032         $config_data = '<' . '?php' . "\n";\r
1033         $config_data .= "// mySQL connection information\n";\r
1034         $config_data .= "\$MYSQL_HOST = '" . $MYSQL_HOST . "';\n";\r
1035         $config_data .= "\$MYSQL_USER = '" . $MYSQL_USER . "';\n";\r
1036         $config_data .= "\$MYSQL_PASSWORD = '" . $MYSQL_PASSWORD . "';\n";\r
1037         $config_data .= "\$MYSQL_DATABASE = '" . $MYSQL_DATABASE . "';\n";\r
1038         $config_data .= "\$MYSQL_PREFIX = '" . $MYSQL_PREFIX . "';\n";\r
1039         $config_data .= "// new in 3.50. first element is db handler, the second is the db driver used by the handler\n";\r
1040         $config_data .= "// default is \$MYSQL_HANDLER = array('mysql','mysql');\n";\r
1041         $config_data .= "//\$MYSQL_HANDLER = array('mysql','mysql');\n";\r
1042         $config_data .= "//\$MYSQL_HANDLER = array('pdo','mysql');\n";\r
1043         $config_data .= "\$MYSQL_HANDLER = array('" . $MYSQL_HANDLER[0] . "','" . $MYSQL_HANDLER[1] . "');\n";\r
1044         $config_data .= "\n";\r
1045         $config_data .= "// main nucleus directory\n";\r
1046         $config_data .= "\$DIR_NUCLEUS = '" . $DIR_NUCLEUS . "';\n";\r
1047         $config_data .= "\n";\r
1048         $config_data .= "// path to media dir\n";\r
1049         $config_data .= "\$DIR_MEDIA = '" . $DIR_MEDIA . "';\n";\r
1050         $config_data .= "\n";\r
1051         $config_data .= "// extra skin files for imported skins\n";\r
1052         $config_data .= "\$DIR_SKINS = '" . $DIR_SKINS . "';\n";\r
1053         $config_data .= "\n";\r
1054         $config_data .= "// these dirs are normally sub dirs of the nucleus dir, but \n";\r
1055         $config_data .= "// you can redefine them if you wish\n";\r
1056         $config_data .= "\$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";\r
1057         $config_data .= "\$DIR_LOCALES = \$DIR_NUCLEUS . 'locales/';\n";\r
1058         $config_data .= "\$DIR_LIBS = \$DIR_NUCLEUS . 'libs/';\n";\r
1059         $config_data .= "\n";\r
1060         $config_data .= "// include libs\n";\r
1061         $config_data .= "include(\$DIR_LIBS.'globalfunctions.php');\n";\r
1062         $config_data .= "?" . ">";\r
1063 \r
1064         $result = false;\r
1065         if ( @!file_exists('../config.php') || is_writable('../config.php') )\r
1066         {\r
1067                 if ( $fp = @fopen('../config.php', 'w') )\r
1068                 {\r
1069                         $result = @fwrite($fp, $config_data, i18n::strlen($config_data));\r
1070                         fclose($fp);\r
1071                 }\r
1072         }\r
1073 \r
1074         if ( $result )\r
1075         {\r
1076                 // try to change the read-only permission.\r
1077                 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )\r
1078                 {\r
1079                         @chmod('../config.php', 0444);\r
1080                 }\r
1081         }\r
1082         else\r
1083         {\r
1084                 $_SESSION['config_data'] = $config_data;\r
1085         }\r
1086 \r
1087         return $errors;\r
1088 }\r
1089 \r
1090 /**\r
1091  * Confirm that you can write to the configuration file\r
1092  * @return string error message\r
1093  */\r
1094 function canConfigFileWritable()\r
1095 {\r
1096         if ( @file_exists('../config.php') && @!is_writable('../config.php') )\r
1097         {\r
1098                 // try to change the read-write permission.\r
1099                 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )\r
1100                 {\r
1101                         @chmod('../config.php', 0666);\r
1102                 }\r
1103 \r
1104                 if ( @!is_writable('../config.php') )\r
1105                 {\r
1106                         return _INST_ERROR8;\r
1107                 }\r
1108         }\r
1109         return '';\r
1110 }\r
1111 \r
1112 /**\r
1113  * To obtain the version of MySQL\r
1114  * @return string\r
1115  */\r
1116 function getMySqlVersion()\r
1117 {\r
1118         global $minimum_mysql_version, $errors;\r
1119         // Turn on output buffer\r
1120         // Needed to repress the output of the sql function that are\r
1121         // not part of php (in this case the @ operator doesn't work)\r
1122         ob_start();\r
1123 \r
1124         // note: this piece of code is taken from phpMyAdmin\r
1125         $conn = sql_connect_args('localhost', '', '');\r
1126         $result = @sql_query('SELECT VERSION() AS version', $conn);\r
1127 \r
1128         if ( $result != FALSE && sql_num_rows($result) > 0 )\r
1129         {\r
1130                 $row = sql_fetch_array($result);\r
1131                 $match = preg_split('#\.#', $row['version']);\r
1132         }\r
1133         else\r
1134         {\r
1135                 $result = @sql_query('SHOW VARIABLES LIKE \'version\'', $conn);\r
1136 \r
1137                 if ( $result != FALSE && @sql_num_rows($result) > 0 )\r
1138                 {\r
1139                         $row = sql_fetch_row($result);\r
1140                         $match = preg_split('#\.#', $row[1]);\r
1141                 }\r
1142                 else\r
1143                 {\r
1144                         //$output = shell_exec('mysql -V');\r
1145                         $output = (function_exists('shell_exec')) ? @shell_exec('mysql -V') : '0.0.0';\r
1146                         preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);\r
1147                         $match = preg_split('#\.#', $version[0]);\r
1148 \r
1149                         if ( $match[0] == '' )\r
1150                         {\r
1151                                 $match = array('0', '0', '0');\r
1152                         }\r
1153                 }\r
1154         }\r
1155 \r
1156         @sql_disconnect($conn);\r
1157 \r
1158         //End and clean output buffer\r
1159         ob_end_clean();\r
1160 \r
1161         return implode($match, '.');\r
1162 }\r
1163 \r
1164 /**\r
1165  * Add a table prefix if it is used\r
1166  *\r
1167  * @param string $input table name with prefix\r
1168  * @return string\r
1169  */\r
1170 function tableName($input)\r
1171 {\r
1172         global $MYSQL_PREFIX;\r
1173         if ( $MYSQL_PREFIX )\r
1174         {\r
1175                 return $MYSQL_PREFIX . $input;\r
1176         }\r
1177         else\r
1178         {\r
1179                 return $input;\r
1180         }\r
1181 }\r
1182 \r
1183 /**\r
1184  * Install custom plugins\r
1185  */\r
1186 function installCustomPlugs()\r
1187 {\r
1188         global $aConfPlugsToInstall, $DIR_LIBS, $manager;\r
1189 \r
1190         $aErrors = array();\r
1191         if ( count($aConfPlugsToInstall) == 0 )\r
1192         {\r
1193                 return $aErrors;\r
1194         }\r
1195 \r
1196         $res = sql_query('SELECT * FROM ' . tableName('nucleus_plugin'));\r
1197         $numCurrent = sql_num_rows($res);\r
1198 \r
1199         foreach ( $aConfPlugsToInstall as $plugName )\r
1200         {\r
1201                 $query = 'INSERT INTO ' . tableName('nucleus_plugin') . ' (porder, pfile) VALUES (' . (++$numCurrent) . ", '" . sql_real_escape_string($plugName) . "')";\r
1202                 sql_query($query);\r
1203 \r
1204                 $manager->clearCachedInfo('installedPlugins');\r
1205                 $plugin =& $manager->getPlugin($plugName);\r
1206                 $plugin->setID($numCurrent);\r
1207 \r
1208                 if ( !$plugin )\r
1209                 {\r
1210                         sql_query('DELETE FROM ' . tableName('nucleus_plugin') . " WHERE pfile = '" . sql_real_escape_string($plugName) . "'");\r
1211                         $numCurrent--;\r
1212                         array_push($aErrors, sprintf(_INST_ERROR9, $plugName));\r
1213                         continue;\r
1214                 }\r
1215                 $plugin->install();\r
1216         }\r
1217 \r
1218         sql_query('DELETE FROM ' . tableName('nucleus_plugin_event'));\r
1219         $res = sql_query('SELECT pid, pfile FROM ' . tableName('nucleus_plugin'));\r
1220 \r
1221         while ( $o = sql_fetch_object($res) )\r
1222         {\r
1223                 $pid = $o->pid;\r
1224                 $plug =& $manager->getPlugin($o->pfile);\r
1225 \r
1226                 if ( $plug )\r
1227                 {\r
1228                         $eventList = $plug->getEventList();\r
1229                         foreach ( $eventList as $eventName )\r
1230                         {\r
1231                                 sql_query('INSERT INTO ' . tableName('nucleus_plugin_event') . ' (pid, event) VALUES (' . $pid . ", '" . $eventName . "')");\r
1232                         }\r
1233                 }\r
1234         }\r
1235         return $aErrors;\r
1236 }\r
1237 \r
1238 /**\r
1239  * Install custom skins\r
1240  * Prepares the installation of custom skins\r
1241  */\r
1242 function installCustomSkins()\r
1243 {\r
1244         global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS;\r
1245 \r
1246         $aErrors = array();\r
1247         if ( count($aConfSkinsToImport) == 0 )\r
1248         {\r
1249                 return $aErrors;\r
1250         }\r
1251 \r
1252         $importer = new SkinImport();\r
1253 \r
1254         foreach ( $aConfSkinsToImport as $skinName )\r
1255         {\r
1256                 $importer->reset();\r
1257                 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';\r
1258 \r
1259                 if ( !@file_exists($skinFile) )\r
1260                 {\r
1261                         array_push($aErrors, sprintf(_INST_ERROR10, $skinFile));\r
1262                         continue;\r
1263                 }\r
1264 \r
1265                 $error = $importer->readFile($skinFile);\r
1266 \r
1267                 if ( $error )\r
1268                 {\r
1269                         array_push($aErrors, sprintf(_INST_ERROR11, $skinName) . ' : ' . $error);\r
1270                         continue;\r
1271                 }\r
1272 \r
1273                 $error = $importer->writeToDatabase(1);\r
1274 \r
1275                 if ( $error )\r
1276                 {\r
1277                         array_push($aErrors, sprintf(_INST_ERROR12, $skinName) . ' : ' . $error);\r
1278                         continue;\r
1279                 }\r
1280         }\r
1281         return $aErrors;\r
1282 }\r
1283 \r
1284 /**\r
1285  * Check if some important files of the Nucleus CMS installation are available\r
1286  * Give an error if one or more files are not accessible\r
1287  */\r
1288 function do_check_files()\r
1289 {\r
1290         $missingfiles = array();\r
1291         $files = array(\r
1292                 './install.sql',\r
1293                 '../index.php',\r
1294                 '../action.php',\r
1295                 '../nucleus/index.php',\r
1296                 '../nucleus/media.php',\r
1297                 '../nucleus/libs/ACTION.php',\r
1298                 '../nucleus/libs/ACTIONLOG.php',\r
1299                 '../nucleus/libs/ACTIONS.php',\r
1300                 '../nucleus/libs/ADMIN.php',\r
1301                 '../nucleus/libs/BaseActions.php',\r
1302                 '../nucleus/libs/BLOG.php',\r
1303                 '../nucleus/libs/BODYACTIONS.php',\r
1304                 '../nucleus/libs/COMMENT.php',\r
1305                 '../nucleus/libs/COMMENTACTIONS.php',\r
1306                 '../nucleus/libs/COMMENTS.php',\r
1307                 '../nucleus/libs/ENCAPSULATE.php',\r
1308                 '../nucleus/libs/ENTITY.php',\r
1309                 '../nucleus/libs/globalfunctions.php',\r
1310                 '../nucleus/libs/i18n.php',\r
1311                 '../nucleus/libs/ITEM.php',\r
1312                 '../nucleus/libs/ITEMACTIONS.php',\r
1313                 '../nucleus/libs/LINK.php',\r
1314                 '../nucleus/libs/MANAGER.php',\r
1315                 '../nucleus/libs/MEDIA.php',\r
1316                 '../nucleus/libs/MEMBER.php',\r
1317                 '../nucleus/libs/mysql.php',\r
1318                 '../nucleus/libs/NOTIFICATION.php',\r
1319                 '../nucleus/libs/PAGEFACTORY.php',\r
1320                 '../nucleus/libs/PARSER.php',\r
1321                 '../nucleus/libs/PLUGIN.php',\r
1322                 '../nucleus/libs/PLUGINADMIN.php',\r
1323                 '../nucleus/libs/SEARCH.php',\r
1324                 '../nucleus/libs/showlist.php',\r
1325                 '../nucleus/libs/SKIN.php',\r
1326                 '../nucleus/libs/TEMPLATE.php',\r
1327                 '../nucleus/libs/vars4.1.0.php',\r
1328                 '../nucleus/libs/xmlrpc.inc.php',\r
1329                 '../nucleus/libs/xmlrpcs.inc.php',\r
1330                 '../nucleus/libs/sql/mysql.php'\r
1331         );\r
1332 \r
1333         $count = count($files);\r
1334         for ( $i = 0; $i < $count; $i++ )\r
1335         {\r
1336                 if ( !is_readable($files[$i]) )\r
1337                 {\r
1338                         array_push($missingfiles, 'File <b>' . $files[$i] . '</b> is missing or not readable.<br />');\r
1339                 }\r
1340         }\r
1341 \r
1342         if ( count($missingfiles) > 0 )\r
1343         {\r
1344                 exit(implode("\n", $missingfiles));\r
1345         }\r
1346 }\r
1347 \r
1348 /**\r
1349  * Updates the configuration in the database\r
1350  *\r
1351  * @param string $name name of the config var\r
1352  * @param string $value new value of the config var\r
1353  * @return array\r
1354  */\r
1355 function updateConfig($name, $value)\r
1356 {\r
1357         $errors = array();\r
1358         $name = sql_real_escape_string($name);\r
1359         $value = trim(sql_real_escape_string($value));\r
1360 \r
1361         $query = "UPDATE %s SET value = '%s' WHERE name = '%s'";\r
1362         $query = sprintf($query, tableName('nucleus_config'), $value, $name);\r
1363 \r
1364         if ( !sql_query($query) )\r
1365         {\r
1366                 $errors[] = _INST_ERROR4 . ': ' . sql_error();\r
1367         }\r
1368         return $errors;\r
1369 }\r
1370 \r
1371 class ParamManager\r
1372 {\r
1373         /* process parameter */\r
1374         public $state;\r
1375         public $locale;\r
1376 \r
1377         /* mysql connection parameters */\r
1378         public $mysql_host;\r
1379         public $mysql_user;\r
1380         public $mysql_password;\r
1381         public $mysql_database;\r
1382         public $mysql_tablePrefix;\r
1383 \r
1384         /* weblog configuration parameters */\r
1385         public $blog_name;\r
1386         public $blog_shortname;\r
1387 \r
1388         /* member configuration parameters */\r
1389         public $user_name;\r
1390         public $user_realname;\r
1391         public $user_password;\r
1392         private $user_password2;\r
1393         public $user_email;\r
1394 \r
1395         /* URI parameters  */\r
1396         private $root_url;\r
1397         public $IndexURL;\r
1398         public $AdminURL;\r
1399         public $MediaURL;\r
1400         public $SkinsURL;\r
1401         public $PluginURL;\r
1402         public $ActionURL;\r
1403 \r
1404         /* path parameters */\r
1405         private $root_path;\r
1406         public $AdminPath;\r
1407         public $MediaPath;\r
1408         public $SkinsPath;\r
1409 \r
1410         /**\r
1411          * constructor\r
1412          */\r
1413         public function __construct()\r
1414         {\r
1415                 $this->init();\r
1416         }\r
1417 \r
1418         public function init()\r
1419         {\r
1420                 // set default values\r
1421                 $this->state = 'locale';\r
1422                 $this->install_mode = 'simple';\r
1423                 $this->locale = 'en_Latn_US';\r
1424                 $this->mysql_host = @ini_get('mysql.default_host');\r
1425                 $this->blog_name = 'My Nucleus CMS';\r
1426                 $this->blog_shortname = 'mynucleuscms';\r
1427 \r
1428                 /* root path */\r
1429                 //              $this->root_path = realpath(dirname(__FILE__) . '/..');\r
1430                 $directory_separator = preg_quote(DIRECTORY_SEPARATOR, '|');\r
1431                 $this->root_path = implode('/', preg_split("|$directory_separator|", realpath(dirname(__FILE__) . '/..')));\r
1432                 if ( substr($this->root_path, -1, 1) !== '/' )\r
1433                 {\r
1434                         $this->root_path .= '/';\r
1435                 }\r
1436                 $base_path_pcre = preg_quote($this->root_path, '|');\r
1437 \r
1438                 /* current directry name */\r
1439                 $directory_name = preg_replace("|$base_path_pcre|", '', implode('/', preg_split("|$directory_separator|", realpath(dirname(__FILE__)))));\r
1440                 $directory_name_pcre = preg_quote($directory_name, '|');\r
1441 \r
1442                 /* root uri */\r
1443                 $root_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];\r
1444                 $this->root_url = preg_replace("|$directory_name_pcre(.*)$|", '', $root_url);\r
1445 \r
1446                 $this->AdminPath = $this->root_path . 'nucleus/';\r
1447                 $this->MediaPath = $this->root_path . 'media/';\r
1448                 $this->SkinsPath = $this->root_path . 'skins/';\r
1449 \r
1450                 $this->IndexURL = $this->root_url;\r
1451                 $this->AdminURL = $this->root_url . 'nucleus/';\r
1452                 $this->MediaURL = $this->root_url . 'media/';\r
1453                 $this->SkinsURL = $this->root_url . 'skins/';\r
1454                 $this->PluginURL = $this->root_url . 'nucleus/plugins/';\r
1455                 $this->ActionURL = $this->root_url . 'action.php';\r
1456         }\r
1457 \r
1458         private function read_parameter($parameter)\r
1459         {\r
1460                 foreach ( $parameter as $element )\r
1461                 {\r
1462                         if ( array_key_exists($element, $_POST) )\r
1463                         {\r
1464                                 $this->$element = $_POST[$element];\r
1465                         }\r
1466                 }\r
1467         }\r
1468 \r
1469         public function set_state($state)\r
1470         {\r
1471                 $states = array('locale', 'mysql', 'weblog', 'detail', 'install');\r
1472                 if ( in_array($state, $states) )\r
1473                 {\r
1474                         $this->state = $state;\r
1475                 }\r
1476         }\r
1477 \r
1478         public function set_locale()\r
1479         {\r
1480                 $this->read_parameter(array('locale'));\r
1481 \r
1482                 if ( !in_array($this->locale, i18n::get_available_locale_list()) )\r
1483                 {\r
1484                         $this->locale = 'en_Latn_US';\r
1485                 }\r
1486         }\r
1487 \r
1488         public function check_mysql_parameters()\r
1489         {\r
1490                 $parameters = array('mysql_host', 'mysql_user', 'mysql_password', 'mysql_database', 'mysql_tablePrefix');\r
1491                 $this->read_parameter($parameters);\r
1492 \r
1493                 $errors = array();\r
1494                 if ( $this->mysql_host == '' )\r
1495                 {\r
1496                         $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD1);\r
1497                 }\r
1498 \r
1499                 if ( $this->mysql_user == '' )\r
1500                 {\r
1501                         $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD2);\r
1502                 }\r
1503 \r
1504                 if ( $this->mysql_user != ''\r
1505                         && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_user) )\r
1506                 {\r
1507                         $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD2);\r
1508                 }\r
1509 \r
1510                 //              if ( $this->mysql_password == '' )\r
1511                 //              {\r
1512                 //                      $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD3);\r
1513                 //              }\r
1514 \r
1515                 if ( $this->mysql_database == '' )\r
1516                 {\r
1517                         $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD4);\r
1518                 }\r
1519 \r
1520                 if ( $this->mysql_database != ''\r
1521                         && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_database) )\r
1522                 {\r
1523                         $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD4);\r
1524                 }\r
1525 \r
1526                 if ( $this->mysql_tablePrefix != ''\r
1527                         && !preg_match('/^[a-z0-9_]+$/i', $this->mysql_tablePrefix) )\r
1528                 {\r
1529                         $errors[] = sprintf(_VALID_ERROR3, _DB_FIELD5);\r
1530                 }\r
1531 \r
1532                 if ( count($errors) == 0 )\r
1533                 {\r
1534                         $mysql_conn = @sql_connect_args($this->mysql_host, $this->mysql_user, $this->mysql_password);\r
1535                         if ( $mysql_conn == false )\r
1536                         {\r
1537                                 $errors[] = _DBCONNECT_ERROR;\r
1538                         }\r
1539                         else\r
1540                         {\r
1541                                 @sql_close($mysql_conn);\r
1542                         }\r
1543                 }\r
1544 \r
1545                 return $errors;\r
1546         }\r
1547 \r
1548         public function check_user_parameters()\r
1549         {\r
1550                 $parameters = array('user_name', 'user_realname', 'user_password', 'user_password2', 'user_email');\r
1551                 $this->read_parameter($parameters);\r
1552 \r
1553                 $errors = array();\r
1554                 if ( $this->user_realname == '' )\r
1555                 {\r
1556                         $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD1);\r
1557                 }\r
1558 \r
1559                 if ( $this->user_name == '' )\r
1560                 {\r
1561                         $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD2);\r
1562                 }\r
1563                 elseif ( !preg_match("/^[a-z0-9]+([ a-z0-9]*[a-z0-9]+)?$/i", $this->user_name) )\r
1564                 {\r
1565                         $errors[] = _VALID_ERROR5;\r
1566                 }\r
1567 \r
1568                 if ( $this->user_password == '' || $this->user_password2 == '' )\r
1569                 {\r
1570                         $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD3);\r
1571                         $this->user_password = '';\r
1572                 }\r
1573                 elseif ( $this->user_password != $this->user_password2 )\r
1574                 {\r
1575                         $errors[] = _VALID_ERROR6;\r
1576                         $this->user_password = '';\r
1577                 }\r
1578 \r
1579                 if ( !preg_match("/^[a-z0-9\._+\-]+@[a-z0-9\._\-]+\.[a-z]{2,6}$/i", $this->user_email) )\r
1580                 {\r
1581                         $errors[] = _VALID_ERROR7;\r
1582                 }\r
1583 \r
1584                 return $errors;\r
1585         }\r
1586 \r
1587         public function check_weblog_parameters()\r
1588         {\r
1589                 $parameters = array('blog_name', 'blog_shortname');\r
1590                 $this->read_parameter($parameters);\r
1591 \r
1592                 $errors = array();\r
1593                 if ( $this->blog_name == '' )\r
1594                 {\r
1595                         $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD1);\r
1596                 }\r
1597 \r
1598                 if ( $this->blog_shortname == '' )\r
1599                 {\r
1600                         $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD2);\r
1601                 }\r
1602 \r
1603                 if ( !preg_match("/^[a-z0-9]+$/i", $this->blog_shortname) )\r
1604                 {\r
1605                         $errors[] = _VALID_ERROR4;\r
1606                 }\r
1607 \r
1608                 return $errors;\r
1609         }\r
1610 \r
1611         public function check_uri_parameters()\r
1612         {\r
1613                 $parameters = array('IndexURL', 'AdminURL', 'MediaURL', 'SkinsURL', 'PluginURL', 'ActionURL');\r
1614                 $this->read_parameter($parameters);\r
1615 \r
1616                 $errors = array();\r
1617                 if ( substr($this->IndexURL, -1, 1) !== '/' )\r
1618                 {\r
1619                         $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD1);\r
1620                 }\r
1621 \r
1622                 if ( substr($this->AdminURL, -1, 1) !== '/' )\r
1623                 {\r
1624                         $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD2);\r
1625                 }\r
1626 \r
1627                 if ( substr($this->MediaURL, -1, 1) !== '/' )\r
1628                 {\r
1629                         $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD4);\r
1630                 }\r
1631 \r
1632                 if ( substr($this->SkinsURL, -1, 1) !== '/' )\r
1633                 {\r
1634                         $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD6);\r
1635                 }\r
1636 \r
1637                 if ( substr($this->PluginURL, -1, 1) !== '/' )\r
1638                 {\r
1639                         $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD8);\r
1640                 }\r
1641 \r
1642                 if ( strrchr($this->ActionURL, '/') != '/action.php' )\r
1643                 {\r
1644                         $errors[] = sprintf(_VALID_ERROR9, _PATH_FIELD9);\r
1645                 }\r
1646 \r
1647                 return $errors;\r
1648         }\r
1649 \r
1650         public function check_path_parameters()\r
1651         {\r
1652                 $parameters = array('AdminPath', 'MediaPath', 'SkinsPath');\r
1653                 $this->read_parameter($parameters);\r
1654 \r
1655                 $separators = array('/', DIRECTORY_SEPARATOR);\r
1656                 $errors = array();\r
1657                 if ( !in_array(substr($this->AdminPath, -1, 1), $separators) )\r
1658                 {\r
1659                         $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD3);\r
1660                 }\r
1661                 elseif ( !file_exists($this->AdminPath) )\r
1662                 {\r
1663                         $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD3);\r
1664                 }\r
1665 \r
1666                 if ( !in_array(substr($this->MediaPath, -1, 1), $separators) )\r
1667                 {\r
1668                         $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD5);\r
1669                 }\r
1670                 elseif ( !file_exists($this->MediaPath) )\r
1671                 {\r
1672                         $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD5);\r
1673                 }\r
1674 \r
1675                 if ( !in_array(substr($this->SkinsPath, -1, 1), $separators) )\r
1676                 {\r
1677                         $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD7);\r
1678                 }\r
1679                 elseif ( !file_exists($this->SkinsPath) )\r
1680                 {\r
1681                         $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD7);\r
1682                 }\r
1683 \r
1684                 return $errors;\r
1685         }\r
1686 \r
1687         /**\r
1688          * check all parameters\r
1689          * @return bool\r
1690          */\r
1691         public function check_all_parameters()\r
1692         {\r
1693                 $this->set_locale();\r
1694 \r
1695                 $isValid = true;\r
1696                 $isValid &= (count($this->check_mysql_parameters()) == 0);\r
1697                 $isValid &= (count($this->check_user_parameters()) == 0);\r
1698                 $isValid &= (count($this->check_weblog_parameters()) == 0);\r
1699                 $isValid &= (count($this->check_uri_parameters()) == 0);\r
1700                 $isValid &= (count($this->check_path_parameters()) == 0);\r
1701 \r
1702                 return $isValid;\r
1703         }\r
1704 }\r