OSDN Git Service

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