OSDN Git Service

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