OSDN Git Service

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