OSDN Git Service

[NEW] データベースをハンドルする新しいDBクラスを追加。関連する修正を反映。
[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: index.php 1745 2012-04-12 23:45:47Z sakamocchi $\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 \r
67 // added for 3.5 sql_* wrapper\r
68 global $MYSQL_HANDLER;\r
69 \r
70 if ( !isset($MYSQL_HANDLER) )\r
71 {\r
72         $MYSQL_HANDLER = array('mysql', '');\r
73 }\r
74 include_once('../nucleus/libs/sql/sql.php');\r
75 \r
76 session_start();\r
77 if ( count($_GET) == 0 && count($_POST) == 0 )\r
78 {\r
79         unset($_SESSION['param_manager']);\r
80 }\r
81 \r
82 // restore the $param from the session\r
83 if ( array_key_exists('param_manager', $_SESSION) )\r
84 {\r
85         $param = $_SESSION['param_manager'];\r
86 }\r
87 else\r
88 {\r
89         $param = new ParamManager();\r
90 }\r
91 \r
92 // include translation file\r
93 if ( array_key_exists('locale', $_POST) ) $param->set_locale();\r
94 i18n::set_current_locale($param->locale);\r
95 $translation_file = './locales/' . i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php';\r
96 if ( !file_exists($translation_file) )\r
97 {\r
98         $translation_file = './locales/en_Latn_US.UTF-8.php';\r
99 }\r
100 include($translation_file);\r
101 \r
102 do_action();\r
103 \r
104 // $param is saved to the session\r
105 if ( isset($param) )\r
106 {\r
107         $_SESSION['param_manager'] = $param;\r
108 }\r
109 else\r
110 {\r
111         unset($_SESSION['param_manager']);\r
112 }\r
113 exit;\r
114 \r
115 /**\r
116  * installer action\r
117  */\r
118 function do_action()\r
119 {\r
120         global $param;\r
121 \r
122         if ( array_key_exists('action', $_POST) )\r
123         {\r
124                 $isPostback = true;\r
125         }\r
126         else\r
127         {\r
128                 $isPostback = false;\r
129         }\r
130 \r
131         // mode change\r
132         if ( array_key_exists('mode', $_REQUEST) )\r
133         {\r
134                 if ( $_REQUEST['mode'] == 'detail' )\r
135                 {\r
136                         $param->set_state('detail');\r
137                 }\r
138                 elseif ( $_REQUEST['mode'] == 'simple' )\r
139                 {\r
140                         $param->set_state('mysql');\r
141                 }\r
142         }\r
143 \r
144         // input parameter check\r
145         if ( $isPostback )\r
146         {\r
147                 switch ( $param->state )\r
148                 {\r
149                         case 'locale':\r
150                                 $param->set_locale();\r
151                                 $param->set_state('mysql');\r
152                                 $isPostback = false;\r
153                                 break;\r
154                         case 'mysql':\r
155                                 if ( count($param->check_mysql_parameters()) == 0 )\r
156                                 {\r
157                                         $param->set_state('weblog');\r
158                                         $isPostback = false;\r
159                                 }\r
160                                 break;\r
161                         case 'weblog':\r
162                                 if ( count($param->check_user_parameters()) == 0\r
163                                         && 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_HANDLER, $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 = @DB::setConnectionInfo($MYSQL_HANDLER[1], $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 ( DB::execute("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") === FALSE )\r
845         {\r
846                 $errinfo = DB::getError();\r
847                 $errors[] = _INST_ERROR1 . ': ' . $errinfo[2];\r
848         }\r
849 \r
850         /*\r
851          * 4. try to select database\r
852          */\r
853         $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE);\r
854         if ( !$MYSQL_CONN )\r
855         {\r
856                 $errors[] = _INST_ERROR2;\r
857         }\r
858 \r
859         if ( count($errors) > 0 )\r
860         {\r
861                 return $errors;\r
862         }\r
863 \r
864         /*\r
865          * 5. execute queries\r
866          */\r
867         $table_names = array(\r
868                 'nucleus_actionlog',\r
869                 'nucleus_ban',\r
870                 'nucleus_blog',\r
871                 'nucleus_category',\r
872                 'nucleus_comment',\r
873                 'nucleus_config',\r
874                 'nucleus_item',\r
875                 'nucleus_karma',\r
876                 'nucleus_member',\r
877                 'nucleus_plugin',\r
878                 'nucleus_skin',\r
879                 'nucleus_template',\r
880                 'nucleus_team',\r
881                 'nucleus_activation',\r
882                 'nucleus_tickets'\r
883         );\r
884 \r
885         $prefixed_table_names = array();\r
886         foreach ( $table_names as $table_name )\r
887         {\r
888                 $prefixed_table_names[] = $MYSQL_PREFIX . $table_name;\r
889         }\r
890 \r
891         // table exists check\r
892         $result = DB::getResult('SHOW TABLES');\r
893         foreach ( $result as $row )\r
894         {\r
895                 if ( in_array($row[0], $prefixed_table_names) )\r
896                 {\r
897                         $errors[] = _INST_ERROR3;\r
898                         break;\r
899                 }\r
900         }\r
901         if ( count($errors) > 0 )\r
902         {\r
903                 return $errors;\r
904         }\r
905 \r
906         $filename = 'install.sql';\r
907         $fd = fopen($filename, 'r');\r
908         $queries = fread($fd, filesize($filename));\r
909         fclose($fd);\r
910 \r
911         $queries = preg_split('#(;\n|;\r)#', $queries);\r
912 \r
913         foreach ( $queries as $query )\r
914         {\r
915                 if ( preg_match('/\w+/', $query) )\r
916                 {\r
917                         if ( $MYSQL_PREFIX )\r
918                         {\r
919                                 $query = str_replace($table_names, $prefixed_table_names, $query);\r
920                         }\r
921 \r
922                         if ( DB::execute($query) === FALSE )\r
923                         {\r
924                                 $errinfo = DB::getError();\r
925                                 $errors[] = _INST_ERROR4 . ' (<small>' . $query . '</small>): ' . $errinfo[2];\r
926                         }\r
927                 }\r
928         }\r
929 \r
930         /*\r
931          * 6. put needed records\r
932          */\r
933         /* push first post */\r
934         $query = "INSERT INTO %s VALUES (1, %s, %s, %s, 1, 1, '%s', 0, 0, 0, 1, 0, 1)";\r
935         $query = sprintf($query,\r
936                 tableName('nucleus_item'),\r
937                 DB::quoteValue(_1ST_POST_TITLE),\r
938                 DB::quoteValue(_1ST_POST),\r
939                 DB::quoteValue(_1ST_POST2),\r
940                 DB::formatDateTime(time())\r
941         );\r
942         if ( !DB::execute($query) )\r
943         {\r
944                 $errinfo = DB::getError();\r
945                 $errors[] = _INST_ERROR4 . ' (<small>' . $newpost . '</small>): ' . $errinfo[2];\r
946         }\r
947 \r
948         /* push configurations */\r
949         array_merge($errors, updateConfig('IndexURL', $param->IndexURL));\r
950         array_merge($errors, updateConfig('AdminURL', $param->AdminURL));\r
951         array_merge($errors, updateConfig('MediaURL', $param->MediaURL));\r
952         array_merge($errors, updateConfig('SkinsURL', $param->SkinsURL));\r
953         array_merge($errors, updateConfig('PluginURL', $param->PluginURL));\r
954         array_merge($errors, updateConfig('ActionURL', $param->ActionURL));\r
955         array_merge($errors, updateConfig('AdminEmail', $param->user_email));\r
956         array_merge($errors, updateConfig('SiteName', $param->blog_name));\r
957         array_merge($errors, updateConfig('Locale', i18n::get_current_locale()));\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,\r
962                 tableName('nucleus_member'),\r
963                 DB::quoteValue($param->user_name),\r
964                 DB::quoteValue($param->user_realname),\r
965                 DB::quoteValue(md5($param->user_password)),\r
966                 DB::quoteValue($param->user_email),\r
967                 DB::quoteValue($param->IndexURL)\r
968         );\r
969         if ( !DB::execute($query) )\r
970         {\r
971                 $errinfo = DB::getError();\r
972                 $errors[] = _INST_ERROR5 . ': ' . $errinfo[2];\r
973         }\r
974 \r
975         /* push new weblog */\r
976         $query = "UPDATE %s SET bname = %s, bshortname = %s, burl = %s WHERE bnumber = 1";\r
977         $query = sprintf($query,\r
978                 tableName('nucleus_blog'),\r
979                 DB::quoteValue($param->blog_name),\r
980                 DB::quoteValue($param->blog_shortname),\r
981                 DB::quoteValue($param->IndexURL)\r
982         );\r
983         if ( !DB::execute($query) )\r
984         {\r
985                 $errinfo = DB::getError();\r
986                 $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];\r
987         }\r
988 \r
989         /* push default category */\r
990         $query = "UPDATE %s SET cname = '%s', cdesc = '%s' WHERE catid = 1";\r
991         $query = sprintf($query,\r
992                 tableName('nucleus_category'),\r
993                 DB::quoteValue(_GENERALCAT_NAME),\r
994                 DB::quoteValue(_GENERALCAT_DESC)\r
995         );\r
996         if ( !DB::execute($query) )\r
997         {\r
998                 $errinfo = DB::getError();\r
999                 $errors[] = _INST_ERROR6 . ': ' . $errinfo[2];\r
1000         }\r
1001 \r
1002         /*\r
1003          * 7. install default plugins and skins\r
1004          */\r
1005         global $aConfPlugsToInstall, $aConfSkinsToImport;\r
1006         $aSkinErrors = array();\r
1007         $aPlugErrors = array();\r
1008 \r
1009         if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) )\r
1010         {\r
1011                 include_once($DIR_LIBS . 'globalfunctions.php');\r
1012                 global $manager;\r
1013                 if ( !isset($manager) )\r
1014                 {\r
1015                         $manager = new Manager();\r
1016                 }\r
1017 \r
1018                 include_once($DIR_LIBS . 'skinie.php');\r
1019                 \r
1020                 $aSkinErrors = installCustomSkins();\r
1021                 if ( count($aSkinErrors) > 0 )\r
1022                 {\r
1023                         array_merge($errors, $aSkinErrors);\r
1024                 }\r
1025 \r
1026                 $query          = "SELECT sdnumber FROM %s WHERE sdname='default'";\r
1027                 $query          = sprintf($query, tableName('nucleus_skin_desc'));\r
1028                 $defSkinID      = intval(DB::getValue($query));\r
1029 \r
1030                 $query = "UPDATE %s SET bdefskin=%d WHERE bnumber=1";\r
1031                 $query = sprintf($query, tableName('nucleus_blog'), $defSkinID);\r
1032                 DB::execute($query);\r
1033                 $query = "UPDATE %s SET value=%d WHERE name='BaseSkin'";\r
1034                 $query = sprintf($query, tableName('nucleus_config'), $defSkinID);\r
1035                 DB::execute($query);\r
1036 \r
1037                 $aPlugErrors = installCustomPlugs();\r
1038                 if ( count($aPlugErrors) > 0 )\r
1039                 {\r
1040                         array_merge($errors, $aPlugErrors);\r
1041                 }\r
1042         }\r
1043 \r
1044         /*\r
1045          * 8. Write config file ourselves (if possible)\r
1046          */\r
1047         $config_data = '<' . '?php' . "\n";\r
1048         $config_data .= "// mySQL connection information\n";\r
1049         $config_data .= "\$MYSQL_HOST = '" . $MYSQL_HOST . "';\n";\r
1050         $config_data .= "\$MYSQL_USER = '" . $MYSQL_USER . "';\n";\r
1051         $config_data .= "\$MYSQL_PASSWORD = '" . $MYSQL_PASSWORD . "';\n";\r
1052         $config_data .= "\$MYSQL_DATABASE = '" . $MYSQL_DATABASE . "';\n";\r
1053         $config_data .= "\$MYSQL_PREFIX = '" . $MYSQL_PREFIX . "';\n";\r
1054         $config_data .= "// new in 3.50. first element is db handler, the second is the db driver used by the handler\n";\r
1055         $config_data .= "// default is \$MYSQL_HANDLER = array('mysql','mysql');\n";\r
1056         $config_data .= "//\$MYSQL_HANDLER = array('mysql','mysql');\n";\r
1057         $config_data .= "//\$MYSQL_HANDLER = array('pdo','mysql');\n";\r
1058         $config_data .= "\$MYSQL_HANDLER = array('" . $MYSQL_HANDLER[0] . "','" . $MYSQL_HANDLER[1] . "');\n";\r
1059         $config_data .= "\n";\r
1060         $config_data .= "// main nucleus directory\n";\r
1061         $config_data .= "\$DIR_NUCLEUS = '" . $DIR_NUCLEUS . "';\n";\r
1062         $config_data .= "\n";\r
1063         $config_data .= "// path to media dir\n";\r
1064         $config_data .= "\$DIR_MEDIA = '" . $DIR_MEDIA . "';\n";\r
1065         $config_data .= "\n";\r
1066         $config_data .= "// extra skin files for imported skins\n";\r
1067         $config_data .= "\$DIR_SKINS = '" . $DIR_SKINS . "';\n";\r
1068         $config_data .= "\n";\r
1069         $config_data .= "// these dirs are normally sub dirs of the nucleus dir, but \n";\r
1070         $config_data .= "// you can redefine them if you wish\n";\r
1071         $config_data .= "\$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";\r
1072         $config_data .= "\$DIR_LOCALES = \$DIR_NUCLEUS . 'locales/';\n";\r
1073         $config_data .= "\$DIR_LIBS = \$DIR_NUCLEUS . 'libs/';\n";\r
1074         $config_data .= "\n";\r
1075         $config_data .= "// include libs\n";\r
1076         $config_data .= "include(\$DIR_LIBS.'globalfunctions.php');\n";\r
1077         $config_data .= "?" . ">";\r
1078 \r
1079         $result = false;\r
1080         if ( @!file_exists('../config.php') || is_writable('../config.php') )\r
1081         {\r
1082                 if ( $fp = @fopen('../config.php', 'w') )\r
1083                 {\r
1084                         $result = @fwrite($fp, $config_data, i18n::strlen($config_data));\r
1085                         fclose($fp);\r
1086                 }\r
1087         }\r
1088 \r
1089         if ( $result )\r
1090         {\r
1091                 // try to change the read-only permission.\r
1092                 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )\r
1093                 {\r
1094                         @chmod('../config.php', 0444);\r
1095                 }\r
1096         }\r
1097         else\r
1098         {\r
1099                 $_SESSION['config_data'] = $config_data;\r
1100         }\r
1101 \r
1102         return $errors;\r
1103 }\r
1104 \r
1105 /**\r
1106  * Confirm that you can write to the configuration file\r
1107  * @return string error message\r
1108  */\r
1109 function canConfigFileWritable()\r
1110 {\r
1111         if ( @file_exists('../config.php') && @!is_writable('../config.php') )\r
1112         {\r
1113                 // try to change the read-write permission.\r
1114                 if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )\r
1115                 {\r
1116                         @chmod('../config.php', 0666);\r
1117                 }\r
1118 \r
1119                 if ( @!is_writable('../config.php') )\r
1120                 {\r
1121                         return _INST_ERROR8;\r
1122                 }\r
1123         }\r
1124         return '';\r
1125 }\r
1126 \r
1127 /**\r
1128  * To obtain the version of MySQL\r
1129  * @return string\r
1130  */\r
1131 function getMySqlVersion()\r
1132 {\r
1133         global $MYSQL_HANDLER, $minimum_mysql_version, $errors;\r
1134         // Turn on output buffer\r
1135         // Needed to repress the output of the sql function that are\r
1136         // not part of php (in this case the @ operator doesn't work)\r
1137         ob_start();\r
1138 \r
1139         // note: this piece of code is taken from phpMyAdmin\r
1140         $conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], 'localhost', '', '');\r
1141 \r
1142         if ( $conn )\r
1143         {\r
1144                 $row = DB::getAttribute(PDO::ATTR_SERVER_VERSION);\r
1145                 $match = preg_split('#\.#', $row);\r
1146         }\r
1147         else\r
1148         {\r
1149                 $row = @DB::getRow('SHOW VARIABLES LIKE \'version\'');\r
1150 \r
1151                 if ( $row )\r
1152                 {\r
1153                         $match = preg_split('#\.#', $row[1]);\r
1154                 }\r
1155                 else\r
1156                 {\r
1157                         $output = (function_exists('shell_exec')) ? @shell_exec('mysql -V') : '0.0.0';\r
1158                         preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);\r
1159                         $match = preg_split('#\.#', $version[0]);\r
1160 \r
1161                         if ( $match[0] == '' )\r
1162                         {\r
1163                                 $match = array('0', '0', '0');\r
1164                         }\r
1165                 }\r
1166         }\r
1167 \r
1168         @DB::disConnect();\r
1169 \r
1170         //End and clean output buffer\r
1171         ob_end_clean();\r
1172 \r
1173         return implode($match, '.');\r
1174 }\r
1175 \r
1176 /**\r
1177  * Add a table prefix if it is used\r
1178  *\r
1179  * @param string $input table name with prefix\r
1180  * @return string\r
1181  */\r
1182 function tableName($input)\r
1183 {\r
1184         global $MYSQL_PREFIX;\r
1185         if ( $MYSQL_PREFIX )\r
1186         {\r
1187                 return $MYSQL_PREFIX . $input;\r
1188         }\r
1189         else\r
1190         {\r
1191                 return $input;\r
1192         }\r
1193 }\r
1194 \r
1195 /**\r
1196  * Install custom plugins\r
1197  */\r
1198 function installCustomPlugs()\r
1199 {\r
1200         global $aConfPlugsToInstall, $DIR_LIBS, $manager;\r
1201 \r
1202         $aErrors = array();\r
1203         if ( count($aConfPlugsToInstall) == 0 )\r
1204         {\r
1205                 return $aErrors;\r
1206         }\r
1207 \r
1208         $query = sprintf('SELECT * FROM %s', tableName('nucleus_plugin'));\r
1209         $res = DB::getResult($query);\r
1210         $numCurrent = $res->rowCount();\r
1211 \r
1212         foreach ( $aConfPlugsToInstall as $plugName )\r
1213         {\r
1214                 $query = sprintf('INSERT INTO %s (porder, pfile) VALUES (%d, %s)',\r
1215                         tableName('nucleus_plugin'),\r
1216                         (++$numCurrent),\r
1217                         DB::quoteValue($plugName));\r
1218                 DB::execute($query);\r
1219 \r
1220                 $manager->clearCachedInfo('installedPlugins');\r
1221                 $plugin =& $manager->getPlugin($plugName);\r
1222                 $plugin->setID($numCurrent);\r
1223 \r
1224                 if ( !$plugin )\r
1225                 {\r
1226                         $query = sprintf('DELETE FROM %s WHERE pfile = %s',\r
1227                                 tableName('nucleus_plugin'),\r
1228                                 DB::quoteValue($plugName));\r
1229                         DB::execute($query);\r
1230                         $numCurrent--;\r
1231                         array_push($aErrors, sprintf(_INST_ERROR9, $plugName));\r
1232                         continue;\r
1233                 }\r
1234                 $plugin->install();\r
1235         }\r
1236 \r
1237         $query = sprintf('DELETE FROM %s', tableName('nucleus_plugin_event'));\r
1238         DB::execute($query);\r
1239         $query = sprintf('SELECT pid, pfile FROM %s', tableName('nucleus_plugin'));\r
1240         $res = DB::getResult($query);\r
1241 \r
1242         foreach ( $res as $row )\r
1243         {\r
1244                 $plug =& $manager->getPlugin($row['pfile']);\r
1245 \r
1246                 if ( $plug )\r
1247                 {\r
1248                         $eventList = $plug->getEventList();\r
1249                         foreach ( $eventList as $eventName )\r
1250                         {\r
1251                                 $query = sprintf('INSERT INTO %s (pid, event) VALUES (%d, %s)',\r
1252                                         tableName('nucleus_plugin_event'),\r
1253                                         intval($row['pid']),\r
1254                                         DB::quoteValue($eventName));\r
1255                                 DB::execute($query);\r
1256                         }\r
1257                 }\r
1258         }\r
1259         return $aErrors;\r
1260 }\r
1261 \r
1262 /**\r
1263  * Install custom skins\r
1264  * Prepares the installation of custom skins\r
1265  */\r
1266 function installCustomSkins()\r
1267 {\r
1268         global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS;\r
1269 \r
1270         $aErrors = array();\r
1271         if ( count($aConfSkinsToImport) == 0 )\r
1272         {\r
1273                 return $aErrors;\r
1274         }\r
1275 \r
1276         $importer = new SkinImport();\r
1277 \r
1278         foreach ( $aConfSkinsToImport as $skinName )\r
1279         {\r
1280                 $importer->reset();\r
1281                 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';\r
1282 \r
1283                 if ( !@file_exists($skinFile) )\r
1284                 {\r
1285                         array_push($aErrors, sprintf(_INST_ERROR10, $skinFile));\r
1286                         continue;\r
1287                 }\r
1288 \r
1289                 $error = $importer->readFile($skinFile);\r
1290 \r
1291                 if ( $error )\r
1292                 {\r
1293                         array_push($aErrors, sprintf(_INST_ERROR11, $skinName) . ' : ' . $error);\r
1294                         continue;\r
1295                 }\r
1296 \r
1297                 $error = $importer->writeToDatabase(1);\r
1298 \r
1299                 if ( $error )\r
1300                 {\r
1301                         array_push($aErrors, sprintf(_INST_ERROR12, $skinName) . ' : ' . $error);\r
1302                         continue;\r
1303                 }\r
1304         }\r
1305         return $aErrors;\r
1306 }\r
1307 \r
1308 /**\r
1309  * Check if some important files of the Nucleus CMS installation are available\r
1310  * Give an error if one or more files are not accessible\r
1311  */\r
1312 function do_check_files()\r
1313 {\r
1314         $missingfiles = array();\r
1315         $files = array(\r
1316                 './install.sql',\r
1317                 '../index.php',\r
1318                 '../action.php',\r
1319                 '../nucleus/index.php',\r
1320                 '../nucleus/media.php',\r
1321                 '../nucleus/libs/ACTION.php',\r
1322                 '../nucleus/libs/ACTIONLOG.php',\r
1323                 '../nucleus/libs/ACTIONS.php',\r
1324                 '../nucleus/libs/ADMIN.php',\r
1325                 '../nucleus/libs/BaseActions.php',\r
1326                 '../nucleus/libs/BLOG.php',\r
1327                 '../nucleus/libs/BODYACTIONS.php',\r
1328                 '../nucleus/libs/COMMENT.php',\r
1329                 '../nucleus/libs/COMMENTACTIONS.php',\r
1330                 '../nucleus/libs/COMMENTS.php',\r
1331                 '../nucleus/libs/ENCAPSULATE.php',\r
1332                 '../nucleus/libs/ENTITY.php',\r
1333                 '../nucleus/libs/globalfunctions.php',\r
1334                 '../nucleus/libs/i18n.php',\r
1335                 '../nucleus/libs/ITEM.php',\r
1336                 '../nucleus/libs/ITEMACTIONS.php',\r
1337                 '../nucleus/libs/LINK.php',\r
1338                 '../nucleus/libs/MANAGER.php',\r
1339                 '../nucleus/libs/MEDIA.php',\r
1340                 '../nucleus/libs/MEMBER.php',\r
1341                 '../nucleus/libs/NOTIFICATION.php',\r
1342                 '../nucleus/libs/PAGEFACTORY.php',\r
1343                 '../nucleus/libs/PARSER.php',\r
1344                 '../nucleus/libs/PLUGIN.php',\r
1345                 '../nucleus/libs/PLUGINADMIN.php',\r
1346                 '../nucleus/libs/SEARCH.php',\r
1347                 '../nucleus/libs/showlist.php',\r
1348                 '../nucleus/libs/SKIN.php',\r
1349                 '../nucleus/libs/TEMPLATE.php',\r
1350                 '../nucleus/libs/vars4.1.0.php',\r
1351                 '../nucleus/libs/xmlrpc.inc.php',\r
1352                 '../nucleus/libs/xmlrpcs.inc.php',\r
1353                 '../nucleus/libs/data/DB.php',\r
1354                 '../nucleus/libs/data/MYSQLPDO.php'\r
1355         );\r
1356 \r
1357         $count = count($files);\r
1358         for ( $i = 0; $i < $count; $i++ )\r
1359         {\r
1360                 if ( !is_readable($files[$i]) )\r
1361                 {\r
1362                         array_push($missingfiles, 'File <b>' . $files[$i] . '</b> is missing or not readable.<br />');\r
1363                 }\r
1364         }\r
1365 \r
1366         if ( count($missingfiles) > 0 )\r
1367         {\r
1368                 exit(implode("\n", $missingfiles));\r
1369         }\r
1370 }\r
1371 \r
1372 /**\r
1373  * Updates the configuration in the database\r
1374  *\r
1375  * @param string $name name of the config var\r
1376  * @param string $value new value of the config var\r
1377  * @return array\r
1378  */\r
1379 function updateConfig($name, $value)\r
1380 {\r
1381         $errors = array();\r
1382 \r
1383         $query = "UPDATE %s SET value = %s WHERE name = %s";\r
1384         $query = sprintf($query, tableName('nucleus_config'), DB::quoteValue(trim($value)), DB::quoteValue($name));\r
1385 \r
1386         if ( !DB::execute($query) )\r
1387         {\r
1388                 $errinfo = DB::getError();\r
1389                 $errors[] = _INST_ERROR4 . ': ' . $errinfo[2];\r
1390         }\r
1391         return $errors;\r
1392 }\r
1393 \r
1394 class ParamManager\r
1395 {\r
1396         /* process parameter */\r
1397         public $state;\r
1398         public $locale;\r
1399 \r
1400         /* mysql connection parameters */\r
1401         public $mysql_host;\r
1402         public $mysql_user;\r
1403         public $mysql_password;\r
1404         public $mysql_database;\r
1405         public $mysql_tablePrefix;\r
1406 \r
1407         /* weblog configuration parameters */\r
1408         public $blog_name;\r
1409         public $blog_shortname;\r
1410 \r
1411         /* member configuration parameters */\r
1412         public $user_name;\r
1413         public $user_realname;\r
1414         public $user_password;\r
1415         private $user_password2;\r
1416         public $user_email;\r
1417 \r
1418         /* URI parameters  */\r
1419         private $root_url;\r
1420         public $IndexURL;\r
1421         public $AdminURL;\r
1422         public $MediaURL;\r
1423         public $SkinsURL;\r
1424         public $PluginURL;\r
1425         public $ActionURL;\r
1426 \r
1427         /* path parameters */\r
1428         private $root_path;\r
1429         public $AdminPath;\r
1430         public $MediaPath;\r
1431         public $SkinsPath;\r
1432 \r
1433         /**\r
1434          * constructor\r
1435          */\r
1436         public function __construct()\r
1437         {\r
1438                 $this->init();\r
1439         }\r
1440 \r
1441         public function init()\r
1442         {\r
1443                 // set default values\r
1444                 $this->state = 'locale';\r
1445                 $this->install_mode = 'simple';\r
1446                 $this->locale = 'en_Latn_US';\r
1447                 $this->mysql_host = @ini_get('mysql.default_host');\r
1448                 $this->blog_name = 'My Nucleus CMS';\r
1449                 $this->blog_shortname = 'mynucleuscms';\r
1450 \r
1451                 /* root path */\r
1452                 $directory_separator = preg_quote(DIRECTORY_SEPARATOR, '|');\r
1453                 $this->root_path = implode('/', preg_split("|$directory_separator|", realpath(dirname(__FILE__) . '/..')));\r
1454                 if ( substr($this->root_path, -1, 1) !== '/' )\r
1455                 {\r
1456                         $this->root_path .= '/';\r
1457                 }\r
1458                 $base_path_pcre = preg_quote($this->root_path, '|');\r
1459 \r
1460                 /* current directry name */\r
1461                 $directory_name = preg_replace("#{$base_path_pcre}#", '', implode('/', preg_split("#{$directory_separator}#", realpath(dirname(__FILE__)))));\r
1462                 $directory_name_pcre = preg_quote($directory_name, '|');\r
1463 \r
1464                 /* root uri */\r
1465                 $root_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];\r
1466                 $this->root_url = preg_replace("|$directory_name_pcre(.*)$|", '', $root_url);\r
1467 \r
1468                 $this->AdminPath = $this->root_path . 'nucleus/';\r
1469                 $this->MediaPath = $this->root_path . 'media/';\r
1470                 $this->SkinsPath = $this->root_path . 'skins/';\r
1471 \r
1472                 $this->IndexURL  = $this->root_url;\r
1473                 $this->AdminURL  = $this->root_url . 'nucleus/';\r
1474                 $this->MediaURL  = $this->root_url . 'media/';\r
1475                 $this->SkinsURL  = $this->root_url . 'skins/';\r
1476                 $this->PluginURL = $this->root_url . 'nucleus/plugins/';\r
1477                 $this->ActionURL = $this->root_url . 'action.php';\r
1478         }\r
1479 \r
1480         private function read_parameter($parameter)\r
1481         {\r
1482                 foreach ( $parameter as $element )\r
1483                 {\r
1484                         if ( array_key_exists($element, $_POST) )\r
1485                         {\r
1486                                 $this->$element = $_POST[$element];\r
1487                         }\r
1488                 }\r
1489         }\r
1490 \r
1491         public function set_state($state)\r
1492         {\r
1493                 $states = array('locale', 'mysql', 'weblog', 'detail', 'install');\r
1494                 if ( in_array($state, $states) )\r
1495                 {\r
1496                         $this->state = $state;\r
1497                 }\r
1498         }\r
1499 \r
1500         public function set_locale()\r
1501         {\r
1502                 $this->read_parameter(array('locale'));\r
1503 \r
1504                 if ( !in_array($this->locale, i18n::get_available_locale_list()) )\r
1505                 {\r
1506                         $this->locale = 'en_Latn_US';\r
1507                 }\r
1508         }\r
1509 \r
1510         public function check_mysql_parameters()\r
1511         {\r
1512                 global $MYSQL_HANDLER;\r
1513                 \r
1514                 $parameters = array('mysql_host', 'mysql_user', 'mysql_password', 'mysql_database', 'mysql_tablePrefix');\r
1515                 $this->read_parameter($parameters);\r
1516 \r
1517                 $errors = array();\r
1518                 if ( $this->mysql_host == '' )\r
1519                 {\r
1520                         $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD1);\r
1521                 }\r
1522 \r
1523                 if ( $this->mysql_user == '' )\r
1524                 {\r
1525                         $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD2);\r
1526                 }\r
1527                 \r
1528                 if ( $this->mysql_user != ''\r
1529                         && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_user) )\r
1530                 {\r
1531                         $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD2);\r
1532                 }\r
1533                 \r
1534                 if ( $this->mysql_database == '' )\r
1535                 {\r
1536                         $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD4);\r
1537                 }\r
1538 \r
1539                 if ( $this->mysql_database != ''\r
1540                         && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_database) )\r
1541                 {\r
1542                         $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD4);\r
1543                 }\r
1544 \r
1545                 if ( $this->mysql_tablePrefix != ''\r
1546                         && !preg_match('/^[a-z0-9_]+$/i', $this->mysql_tablePrefix) )\r
1547                 {\r
1548                         $errors[] = sprintf(_VALID_ERROR3, _DB_FIELD5);\r
1549                 }\r
1550                 \r
1551                 if ( count($errors) == 0 )\r
1552                 {\r
1553                         $mysql_conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], $this->mysql_host, $this->mysql_user, $this->mysql_password);\r
1554                         if ( $mysql_conn == false )\r
1555                         {\r
1556                                 $errors[] = _DBCONNECT_ERROR;\r
1557                         }\r
1558                         else\r
1559                         {\r
1560                                 @DB::disConnect();\r
1561                         }\r
1562                 }\r
1563 \r
1564                 return $errors;\r
1565         }\r
1566 \r
1567         public function check_user_parameters()\r
1568         {\r
1569                 $parameters = array('user_name', 'user_realname', 'user_password', 'user_password2', 'user_email');\r
1570                 $this->read_parameter($parameters);\r
1571 \r
1572                 $errors = array();\r
1573                 if ( $this->user_realname == '' )\r
1574                 {\r
1575                         $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD1);\r
1576                 }\r
1577 \r
1578                 if ( $this->user_name == '' )\r
1579                 {\r
1580                         $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD2);\r
1581                 }\r
1582                 elseif ( !preg_match("/^[a-z0-9]+([ a-z0-9]*[a-z0-9]+)?$/i", $this->user_name) )\r
1583                 {\r
1584                         $errors[] = _VALID_ERROR5;\r
1585                 }\r
1586 \r
1587                 if ( $this->user_password == '' || $this->user_password2 == '' )\r
1588                 {\r
1589                         $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD3);\r
1590                         $this->user_password = '';\r
1591                 }\r
1592                 elseif ( $this->user_password != $this->user_password2 )\r
1593                 {\r
1594                         $errors[] = _VALID_ERROR6;\r
1595                         $this->user_password = '';\r
1596                 }\r
1597 \r
1598                 if ( !preg_match("/^[a-z0-9\._+\-]+@[a-z0-9\._\-]+\.[a-z]{2,6}$/i", $this->user_email) )\r
1599                 {\r
1600                         $errors[] = _VALID_ERROR7;\r
1601                 }\r
1602 \r
1603                 return $errors;\r
1604         }\r
1605 \r
1606         public function check_weblog_parameters()\r
1607         {\r
1608                 $parameters = array('blog_name', 'blog_shortname');\r
1609                 $this->read_parameter($parameters);\r
1610 \r
1611                 $errors = array();\r
1612                 if ( $this->blog_name == '' )\r
1613                 {\r
1614                         $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD1);\r
1615                 }\r
1616 \r
1617                 if ( $this->blog_shortname == '' )\r
1618                 {\r
1619                         $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD2);\r
1620                 }\r
1621 \r
1622                 if ( !preg_match("/^[a-z0-9]+$/i", $this->blog_shortname) )\r
1623                 {\r
1624                         $errors[] = _VALID_ERROR4;\r
1625                 }\r
1626 \r
1627                 return $errors;\r
1628         }\r
1629 \r
1630         public function check_uri_parameters()\r
1631         {\r
1632                 $parameters = array('IndexURL', 'AdminURL', 'MediaURL', 'SkinsURL', 'PluginURL', 'ActionURL');\r
1633                 $this->read_parameter($parameters);\r
1634 \r
1635                 $errors = array();\r
1636                 if ( substr($this->IndexURL, -1, 1) !== '/' )\r
1637                 {\r
1638                         $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD1);\r
1639                 }\r
1640 \r
1641                 if ( substr($this->AdminURL, -1, 1) !== '/' )\r
1642                 {\r
1643                         $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD2);\r
1644                 }\r
1645 \r
1646                 if ( substr($this->MediaURL, -1, 1) !== '/' )\r
1647                 {\r
1648                         $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD4);\r
1649                 }\r
1650 \r
1651                 if ( substr($this->SkinsURL, -1, 1) !== '/' )\r
1652                 {\r
1653                         $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD6);\r
1654                 }\r
1655 \r
1656                 if ( substr($this->PluginURL, -1, 1) !== '/' )\r
1657                 {\r
1658                         $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD8);\r
1659                 }\r
1660 \r
1661                 if ( strrchr($this->ActionURL, '/') != '/action.php' )\r
1662                 {\r
1663                         $errors[] = sprintf(_VALID_ERROR9, _PATH_FIELD9);\r
1664                 }\r
1665 \r
1666                 return $errors;\r
1667         }\r
1668 \r
1669         public function check_path_parameters()\r
1670         {\r
1671                 $parameters = array('AdminPath', 'MediaPath', 'SkinsPath');\r
1672                 $this->read_parameter($parameters);\r
1673 \r
1674                 $separators = array('/', DIRECTORY_SEPARATOR);\r
1675                 $errors = array();\r
1676                 if ( !in_array(substr($this->AdminPath, -1, 1), $separators) )\r
1677                 {\r
1678                         $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD3);\r
1679                 }\r
1680                 elseif ( !file_exists($this->AdminPath) )\r
1681                 {\r
1682                         $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD3);\r
1683                 }\r
1684 \r
1685                 if ( !in_array(substr($this->MediaPath, -1, 1), $separators) )\r
1686                 {\r
1687                         $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD5);\r
1688                 }\r
1689                 elseif ( !file_exists($this->MediaPath) )\r
1690                 {\r
1691                         $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD5);\r
1692                 }\r
1693 \r
1694                 if ( !in_array(substr($this->SkinsPath, -1, 1), $separators) )\r
1695                 {\r
1696                         $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD7);\r
1697                 }\r
1698                 elseif ( !file_exists($this->SkinsPath) )\r
1699                 {\r
1700                         $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD7);\r
1701                 }\r
1702 \r
1703                 return $errors;\r
1704         }\r
1705 \r
1706         /**\r
1707          * check all parameters\r
1708          * @return bool\r
1709          */\r
1710         public function check_all_parameters()\r
1711         {\r
1712                 $this->set_locale();\r
1713 \r
1714                 $isValid = true;\r
1715                 $isValid &= (count($this->check_mysql_parameters()) == 0);\r
1716                 $isValid &= (count($this->check_user_parameters()) == 0);\r
1717                 $isValid &= (count($this->check_weblog_parameters()) == 0);\r
1718                 $isValid &= (count($this->check_uri_parameters()) == 0);\r
1719                 $isValid &= (count($this->check_path_parameters()) == 0);\r
1720 \r
1721                 return $isValid;\r
1722         }\r
1723 }\r