OSDN Git Service

7a8889e53d980d11d09bd9d06832c86ec25e33a9
[nucleus-jp/nucleus-jp-ancient.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  * Below is a friendly way of letting users on non-php systems know that Nucleus won't run there.\r
16  * ?><div style="font-size: xx-large;">If you see this text in your browser when you open <i>/install/</i>, your web server is not able to run PHP-scripts, and therefor Nucleus will not be able to run there. </div><div style="display: none"><?php\r
17  */\r
18 \r
19 /*\r
20         This part of the index.php code allows for customization of the install process.\r
21         When distributing plugins or skins together with a Nucleus installation, the\r
22         configuration below will instruct to install them\r
23 \r
24         -- Start Of Configurable Part --\r
25 */\r
26 \r
27 include('./install_lang_japanese.php');\r
28 \r
29 // array with names of plugins to install. Plugin files must be present in the nucleus/plugin/\r
30 // directory.\r
31 //\r
32 // example:\r
33 //       array('NP_TrackBack', 'NP_MemberGoodies')\r
34 $aConfPlugsToInstall = array(\r
35         'NP_SkinFiles',\r
36 );\r
37 \r
38 \r
39 // array with skins to install. skins must be present under the skins/ directory with\r
40 // a subdirectory having the same name that contains a skinbackup.xml file\r
41 //\r
42 // example:\r
43 //       array('base','rsd')\r
44 $aConfSkinsToImport = array(\r
45         'atom',\r
46         'rss2.0',\r
47         'rsd',\r
48         'default',\r
49 );\r
50 \r
51 /*\r
52         -- End Of Configurable Part --\r
53 */\r
54 \r
55 // don't give warnings for uninitialized vars\r
56 error_reporting(E_ERROR | E_WARNING | E_PARSE);\r
57 \r
58 // make sure there's no unnecessary escaping:\r
59 set_magic_quotes_runtime(0);\r
60 \r
61 // if there are some plugins or skins to import, do not include vars\r
62 // in globalfunctions.php again... so set a flag\r
63 if ((count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) ) {\r
64         global $CONF;\r
65         $CONF['installscript'] = 1;\r
66 }\r
67 \r
68 // compatibility script for php < 4.1.0\r
69 // ToDo: remove this here and from the core\r
70 if (phpversion() >= '4.1.0') {\r
71         include_once('../nucleus/libs/vars4.1.0.php');\r
72 } else {\r
73         include_once('../nucleus/libs/vars4.0.6.php');\r
74 }\r
75 \r
76 // include core classes that are needed for login & plugin handling\r
77 include_once('../nucleus/libs/mysql.php');\r
78 // added for 3.5 sql_* wrapper\r
79 global $MYSQL_HANDLER;\r
80 //set the handler if different from mysql (or mysqli)\r
81 //$MYSQL_HANDLER = array('pdo','mysql');\r
82 if (!isset($MYSQL_HANDLER)) {\r
83         $MYSQL_HANDLER = array('mysql','');\r
84 }\r
85 include_once('../nucleus/libs/sql/'.$MYSQL_HANDLER[0].'.php');\r
86 // end new for 3.5 sql_* wrapper\r
87 \r
88 // check if mysql support is installed\r
89 // this check may not make sense, as is, in a version past 3.5x\r
90 if (!function_exists('mysql_query') ) {\r
91         _doError(_ERROR1);\r
92 }\r
93 \r
94 if (postVar('action') == 'go') {\r
95         doInstall();\r
96 } else {\r
97         showInstallForm();\r
98 }\r
99 \r
100 exit;\r
101 \r
102 /*\r
103  * Show the form for the installation settings\r
104  */\r
105 function showInstallForm() {\r
106         // 0. pre check if all necessary files exist\r
107         doCheckFiles();\r
108 \r
109         ?>\r
110         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
111         <html xmlns="http://www.w3.org/1999/xhtml">\r
112         <head>\r
113                 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />\r
114                 <title><?php echo _TITLE; ?></title>\r
115                 <style type="text/css"><!--\r
116                         @import url('../nucleus/documentation/styles/manual.css');\r
117                 --></style>\r
118                 <script type="text/javascript"><!--\r
119                         var submitcount = 0;\r
120 \r
121                         // function to make sure the submit button only gets pressed once\r
122                         function checkSubmit() {\r
123                                 if (submitcount == 0) {\r
124                                         submitcount++;\r
125                                         return true;\r
126                                 } else {\r
127                                         return false;\r
128                                 }\r
129                         }\r
130                 --></script>\r
131         </head>\r
132         <body>\r
133                 <div style="text-align:center"><img src="../nucleus/styles/logo.gif" alt="<?php echo _ALT_NUCLEUS_CMS_LOGO; ?>" /></div> <!-- Nucleus logo -->\r
134                 <form method="post" action="index.php">\r
135                 \r
136                 <h1><?php echo _HEADER1; ?></h1>\r
137                 \r
138                 <?php echo _TEXT1; ?>\r
139                 \r
140                 <h1><?php echo _HEADER1_2 ?></h1>\r
141                 \r
142                 <?php echo _TEXT1_2; ?>\r
143                 \r
144                 <fieldset>\r
145                         <legend><?php echo _TEXT1_2_TAB_HEAD; ?></legend>\r
146                         <table>\r
147                                 <tr>\r
148                                         <td><?php echo _TEXT1_2_TAB_FIELD1; ?></td>\r
149                                         <td>\r
150                                                 <select name="charset" tabindex="10000">\r
151                                                         <option value="utf8" selected="selected">UTF-8</option>\r
152                                                         <option value="ujis" >EUC-JP</option>\r
153                                                 </select>\r
154                                         </td>\r
155                                 </tr>\r
156                         </table>\r
157                 </fieldset>\r
158                 \r
159                 <h1><?php echo _HEADER2; ?></h1>\r
160                 \r
161                 <?php echo _TEXT2; ?>\r
162                 \r
163                 <ul>\r
164                         <li>PHP:\r
165 <?php\r
166         echo phpversion();\r
167 ?>\r
168                         </li>\r
169                         <li>MySQL:\r
170 <?php\r
171         // Turn on output buffer\r
172         // Needed to repress the output of the sql function that are\r
173         // not part of php (in this case the @ operator doesn't work) \r
174         ob_start();\r
175         // note: this piece of code is taken from phpMyAdmin\r
176         $conn   = sql_connect_args('localhost','','');\r
177         $result = @sql_query('SELECT VERSION() AS version', $conn);\r
178         if ($result != FALSE && sql_num_rows($result) > 0) {\r
179                 $row   = sql_fetch_array($result);\r
180                 $match = explode('.', $row['version']);\r
181         } else {\r
182                 $result = @sql_query('SHOW VARIABLES LIKE \'version\'', $conn);\r
183                 if ($result != FALSE && @sql_num_rows($result) > 0) {\r
184                         $row   = sql_fetch_row($result);\r
185                         $match = explode('.', $row[1]);\r
186                 } else {\r
187                         $output = (function_exists('shell_exec')) ? @shell_exec('mysql -V') : '0.0.0';\r
188                         preg_match('#[0-9]+\.[0-9]+\.[0-9]+#', $output, $version);\r
189                         $match = explode('.', $version[0]);\r
190 \r
191                         if ($match[0] == '') {\r
192                                 $match[0] = '0';\r
193                                 $match[1] = '0';\r
194                                 $match[2] = '0';\r
195                         }\r
196                 }\r
197         }\r
198         @sql_disconnect($conn);\r
199         //End and clean output buffer\r
200         ob_end_clean();\r
201         $mySqlVersion = implode($match, '.');\r
202         $minVersion   = '3.23';\r
203         \r
204         if (version_compare($mySqlVersion, '0.0.0', '==')) {\r
205                 echo _NOTIFICATION1;\r
206         }\r
207         else {\r
208                 echo $mySqlVersion;\r
209         }\r
210 \r
211         if (version_compare($mySqlVersion, $minVersion, '<')) {\r
212                 echo ' <span class="warning" style="display:block">' . sprintf(_TEXT2_WARN1, $minVersion) . '</span>';\r
213         }\r
214 ?>\r
215                         </li>\r
216                 </ul>\r
217 <?php\r
218         if (phpversion() < '5.0.0') {\r
219                 echo ' <p class="deprecated">' . _TEXT2_WARN2 . '</p>';\r
220 ?>\r
221 </form>\r
222 </body>\r
223 </html>\r
224 <?php\r
225                 exit;\r
226         }\r
227 \r
228         // tell people how they can have their config file filled out automatically\r
229         if (@file_exists('../config.php') && @!is_writable('../config.php')) {\r
230 ?>\r
231 \r
232                 <h1><?php echo _HEADER3; ?></h1>\r
233 \r
234                 <?php echo _TEXT3;\r
235 \r
236 } ?>\r
237 \r
238                 <h1><?php echo _HEADER4; ?></h1>\r
239 \r
240                 <?php echo _TEXT4; ?>\r
241 \r
242                 <fieldset>\r
243                         <legend><?php echo _TEXT4_TAB_HEAD; ?></legend>\r
244                         <table>\r
245                                 <tr>\r
246                                         <td><label for="if_mySQL_host"><?php echo _TEXT4_TAB_FIELD1; ?>:</label></td>\r
247                                         <td><input id="if_mySQL_host" name="mySQL_host" value="<?php echo htmlspecialchars(@ini_get('mysql.default_host') )?>" tabindex="10010" /></td>\r
248                                 </tr>\r
249                                 <tr>\r
250                                         <td><label for="if_mySQL_user"><?php echo _TEXT4_TAB_FIELD2; ?>:</label></td>\r
251                                         <td><input id="if_mySQL_user" name="mySQL_user" tabindex="10020" /></td>\r
252                                 </tr>\r
253                                 <tr>\r
254                                         <td><label for="if_mySQL_password"><?php echo _TEXT4_TAB_FIELD3; ?>:</label></td>\r
255                                         <td><input id="if_mySQL_password" name="mySQL_password" type="password" tabindex="10030" /></td>\r
256                                 </tr>\r
257                                 <tr>\r
258                                         <td><label for="if_mySQL_database"><?php echo _TEXT4_TAB_FIELD4; ?>:</label></td>\r
259                                         <td><input id="if_mySQL_database" name="mySQL_database" tabindex="10040" /> (<input name="mySQL_create" value="1" type="checkbox" id="mySQL_create" tabindex="10050" /><label for="mySQL_create"><?php echo _TEXT4_TAB_FIELD4_ADD; ?></label>)</td>\r
260                                 </tr>\r
261                         </table>\r
262                 </fieldset>\r
263 \r
264                 <fieldset>\r
265                         <legend><?php echo _TEXT4_TAB2_HEAD; ?></legend>\r
266                         <table>\r
267                                 <tr>\r
268                                         <td><input name="mySQL_usePrefix" value="1" type="checkbox" id="mySQL_usePrefix" tabindex="10060" /><label for="mySQL_usePrefix"><?php echo _TEXT4_TAB2_FIELD; ?>:</label></td>\r
269                                         <td><input name="mySQL_tablePrefix" value="" tabindex="10070" /></td>\r
270                                 </tr>\r
271                         </table>\r
272 \r
273                         <?php echo _TEXT4_TAB2_ADD; ?>\r
274 \r
275                 </fieldset>\r
276 \r
277         <h1><?php echo _HEADER5; ?></h1>\r
278 \r
279         <?php echo _TEXT5; ?>\r
280 \r
281 <?php\r
282 \r
283         // no need to this all! dirname(__FILE__) is all we need -- moraes\r
284         /*\r
285         // discover full path\r
286         $fullPath = serverVar('PATH_TRANSLATED');\r
287 \r
288         if ($fullPath == '') {\r
289                 $fullPath = serverVar('SCRIPT_FILENAME');\r
290         }\r
291 \r
292         $basePath = str_replace('install.php', '', $fullPath);\r
293         $basePath = replaceDoubleBackslash($basePath);\r
294         $basePath = replaceDoubleBackslash($basePath);\r
295 \r
296         // add slash at end if necessary\r
297         if (!endsWithSlash($basePath) ) {\r
298                 $basePath .= '/';\r
299         }\r
300         */\r
301 \r
302         $basePath = str_replace('install', '', dirname(__FILE__));\r
303 ?>\r
304 \r
305                 <fieldset>\r
306                         <legend><?php echo _TEXT5_TAB_HEAD; ?></legend>\r
307                         <table>\r
308                                 <tr>\r
309                                         <td><label for="if_IndexURL"><?php echo _TEXT5_TAB_FIELD1;?>:</label></td>\r
310                                         <td><input id="if_IndexURL" name="IndexURL" size="60" value="<?php\r
311                                                 $url = 'http://' . serverVar('HTTP_HOST') . serverVar('PHP_SELF');\r
312                                                 $url = str_replace('install/index.php', '', $url);\r
313                                                 $url = replaceDoubleBackslash($url);\r
314 \r
315                                                 // add slash at end if necessary\r
316                                                 if (!endsWithSlash($url) ) {\r
317                                                         $url .= '/';\r
318                                                 }\r
319 \r
320                                                 echo $url; ?>" tabindex="10080" /></td>\r
321                                 </tr>\r
322                                 <tr>\r
323                                         <td><label for="if_AdminURL"><?php echo _TEXT5_TAB_FIELD2;?>:</label></td>\r
324                                         <td><input id="if_AdminURL" name="AdminURL" size="60" value="<?php\r
325                                                 if ($url) {\r
326                                                         echo $url . 'nucleus/';\r
327                                                 } ?>" tabindex="10090" /></td>\r
328                                 </tr>\r
329                                 <tr>\r
330                                         <td><label for="if_AdminPath"><?php echo _TEXT5_TAB_FIELD3;?>:</label></td>\r
331                                         <td><input id="if_AdminPath" name="AdminPath" size="60" value="<?php\r
332                                                 if($basePath) {\r
333                                                         echo $basePath . 'nucleus/';\r
334                                                 } ?>" tabindex="10100" /></td>\r
335                                 </tr>\r
336                                 <tr>\r
337                                         <td><label for="if_MediaURL"><?php echo _TEXT5_TAB_FIELD4;?>:</label></td>\r
338                                         <td><input id="if_MediaURL" name="MediaURL" size="60" value="<?php\r
339                                                 if ($url) {\r
340                                                         echo $url . 'media/';\r
341                                                 } ?>" tabindex="10110" /></td>\r
342                                 </tr>\r
343                                 <tr>\r
344                                         <td><label for="if_MediaPath"><?php echo _TEXT5_TAB_FIELD5;?>:</label></td>\r
345                                         <td><input id="if_MediaPath" name="MediaPath" size="60" value="<?php\r
346                                                 if ($basePath) {\r
347                                                         echo $basePath . 'media/';\r
348                                                 } ?>" tabindex="10120" /></td>\r
349                                 </tr>\r
350                                 <tr>\r
351                                         <td><label for="if_SkinsURL"><?php echo _TEXT5_TAB_FIELD6;?>:</label></td>\r
352                                         <td><input id="if_SkinsURL" name="SkinsURL" size="60" value="<?php\r
353                                                 if ($url) {\r
354                                                         echo $url . 'skins/';\r
355                                                 } ?>" tabindex="10130" />\r
356                                                 <br />(<?php echo _TEXT5_TAB_FIELD7_2; ?>)\r
357                                         </td>\r
358                                 </tr>\r
359                                 <tr>\r
360                                         <td><label for="if_SkinsPath"><?php echo _TEXT5_TAB_FIELD7;?>:</label></td>\r
361                                         <td><input id="if_SkinsPath" name="SkinsPath" size="60" value="<?php\r
362                                                 if ($basePath) {\r
363                                                         echo $basePath . 'skins/';\r
364                                                 } ?>" tabindex="10140" />\r
365                                                 <br />(<?php echo _TEXT5_TAB_FIELD7_2; ?>)\r
366                                         </td>\r
367                                 </tr>\r
368                                 <tr>\r
369                                         <td><label for="if_PluginURL"><?php echo _TEXT5_TAB_FIELD8;?>:</label></td>\r
370                                         <td><input id="if_PluginURL" name="PluginURL" size="60" value="<?php\r
371                                                 if ($url) {\r
372                                                         echo $url . 'nucleus/plugins/';\r
373                                                 } ?>" tabindex="10150" /></td>\r
374                                 </tr>\r
375                                 <tr>\r
376                                         <td><label for="if_ActionURL"><?php echo _TEXT5_TAB_FIELD9;?>:</label></td>\r
377                                         <td><input id="if_ActionURL" name="ActionURL" size="60" value="<?php\r
378                                                 if ($url) {\r
379                                                         echo $url . 'action.php';\r
380                                                 } ?>" tabindex="10160" />\r
381                                                 <br />(<?php echo _TEXT5_TAB_FIELD9_2;?>)\r
382                                         </td>\r
383                                 </tr>\r
384                         </table>\r
385                 </fieldset>\r
386 \r
387                 <?php echo _TEXT5_2; ?>\r
388 \r
389                 <h1><?php echo _HEADER6; ?></h1>\r
390 \r
391                 <?php echo _TEXT6; ?>\r
392 \r
393                 <fieldset>\r
394                         <legend><?php echo _TEXT6_TAB_HEAD; ?></legend>\r
395                         <table>\r
396                                 <tr>\r
397                                         <td><label for="if_User_name"><?php echo _TEXT6_TAB_FIELD1; ?>:</label></td>\r
398                                         <td><input id="if_User_name" name="User_name" value="" tabindex="10170" /> <small>(<?php echo _TEXT6_TAB_FIELD1_2; ?>)</small></td>\r
399                                 </tr>\r
400                                 <tr>\r
401                                         <td><label for="if_User_realname"><?php echo _TEXT6_TAB_FIELD2; ?>:</label></td>\r
402                                         <td><input id="if_User_realname" name="User_realname" value="" tabindex="10180" /></td>\r
403                                 </tr>\r
404                                 <tr>\r
405                                         <td><label for="if_User_password"><?php echo _TEXT6_TAB_FIELD3; ?>:</label></td>\r
406                                         <td><input id="if_User_password" name="User_password" type="password" value="" tabindex="10190" /></td>\r
407                                 </tr>\r
408                                 <tr>\r
409                                         <td><label for="if_User_password2"><?php echo _TEXT6_TAB_FIELD4; ?>:</label></td>\r
410                                         <td><input id="if_User_password2" name="User_password2" type="password" value="" tabindex="10200" /></td>\r
411                                 </tr>\r
412                                 <tr>\r
413                                         <td><label for="if_User_email"><?php echo _TEXT6_TAB_FIELD5; ?>:</label></td>\r
414                                         <td><input id="if_User_email" name="User_email" value="" tabindex="10210" /> <small>(<?php echo _TEXT6_TAB_FIELD5_2; ?>)</small></td>\r
415                                 </tr>\r
416                         </table>\r
417                 </fieldset>\r
418 \r
419                 <h1><?php echo _HEADER7; ?></h1>\r
420 \r
421                 <?php echo _TEXT7; ?>\r
422 \r
423                 <fieldset>\r
424                         <legend><?php echo _TEXT7_TAB_HEAD; ?></legend>\r
425                         <table>\r
426                                 <tr>\r
427                                         <td><label for="if_Blog_name"><?php echo _TEXT7_TAB_FIELD1; ?>:</label></td>\r
428                                         <td><input id="if_Blog_name" name="Blog_name" size="60" value="My Nucleus CMS" tabindex="10220" /></td>\r
429                                 </tr>\r
430                                 <tr>\r
431                                         <td><label for="if_Blog_shortname"><?php echo _TEXT7_TAB_FIELD2; ?>:</label></td>\r
432                                         <td><input id="if_Blog_shortname" name="Blog_shortname" value="mynucleuscms" tabindex="10230" /> <small>(<?php echo _TEXT7_TAB_FIELD2_2; ?>)</small></td>\r
433                                 </tr>\r
434                         </table>\r
435                 </fieldset>\r
436 \r
437                 <h1><?php echo _HEADER8; ?></h1>\r
438 \r
439                 <fieldset>\r
440                         <legend><?php echo _TEXT8_TAB_HEADER; ?></legend>\r
441                         <table>\r
442                                 <tr>\r
443                                         <td><input name="Weblog_ping" value="1" type="checkbox" id="Weblog_ping" tabindex="10240" /><label for="Weblog_ping"><?php echo _TEXT8_TAB_FIELD1; ?></label></td>\r
444                                 </tr>\r
445                         </table>\r
446                 </fieldset>\r
447                 \r
448                 <h1><?php echo _HEADER9; ?></h1>\r
449                 \r
450                 <?php echo _TEXT9; ?>\r
451                 \r
452                 <p>\r
453                 <input name="action" value="go" type="hidden" />\r
454                 <input type="submit" value="<?php echo _BUTTON1; ?>" onclick="return checkSubmit();" tabindex="10250" />\r
455                 </p>\r
456                 \r
457                 </form>\r
458         </body>\r
459 </html>\r
460 \r
461 <?php }\r
462 \r
463 /*\r
464  * Add a table prefix if it is used\r
465  * \r
466  * @param       $unPrefixed\r
467  *                      table name with prefix\r
468  */\r
469 function tableName($unPrefixed) {\r
470         global $mysql_usePrefix, $mysql_prefix;\r
471 \r
472         if ($mysql_usePrefix == 1) {\r
473                 return $mysql_prefix . $unPrefixed;\r
474         } else {\r
475                 return $unPrefixed;\r
476         }\r
477 }\r
478 \r
479 /*\r
480  * The installation process itself\r
481  */\r
482 function doInstall() {\r
483         global $mysql_usePrefix, $mysql_prefix, $weblog_ping;\r
484 \r
485         // 0. put all POST-vars into vars\r
486         $mysql_host             = postVar('mySQL_host');\r
487         $mysql_user             = postVar('mySQL_user');\r
488         $mysql_password = postVar('mySQL_password');\r
489         $mysql_database = postVar('mySQL_database');\r
490         $mysql_create     = postVar('mySQL_create');\r
491         $mysql_usePrefix   = postVar('mySQL_usePrefix');\r
492         $mysql_prefix     = postVar('mySQL_tablePrefix');\r
493         $config_indexurl   = postVar('IndexURL');\r
494         $config_adminurl   = postVar('AdminURL');\r
495         $config_adminpath  = postVar('AdminPath');\r
496         $config_mediaurl   = postVar('MediaURL');\r
497         $config_skinsurl   = postVar('SkinsURL');\r
498         $config_pluginurl  = postVar('PluginURL');\r
499         $config_actionurl  = postVar('ActionURL');\r
500         $config_mediapath  = postVar('MediaPath');\r
501         $config_skinspath  = postVar('SkinsPath');\r
502         $user_name               = postVar('User_name');\r
503         $user_realname   = postVar('User_realname');\r
504         $user_password   = postVar('User_password');\r
505         $user_password2 = postVar('User_password2');\r
506         $user_email             = postVar('User_email');\r
507         $blog_name               = postVar('Blog_name');\r
508         $blog_shortname = postVar('Blog_shortname');\r
509         $charset                   = postVar('charset');\r
510         $config_adminemail = $user_email;\r
511         $config_sitename   = $blog_name;\r
512         $weblog_ping       = postVar('Weblog_ping');\r
513         \r
514         $_POST = array();\r
515         \r
516         $config_indexurl   = replaceDoubleBackslash($config_indexurl);\r
517         $config_adminurl   = replaceDoubleBackslash($config_adminurl);\r
518         $config_mediaurl   = replaceDoubleBackslash($config_mediaurl);\r
519         $config_skinsurl   = replaceDoubleBackslash($config_skinsurl);\r
520         $config_pluginurl  = replaceDoubleBackslash($config_pluginurl);\r
521         $config_actionurl  = replaceDoubleBackslash($config_actionurl);\r
522         $config_adminpath  = replaceDoubleBackslash($config_adminpath);\r
523         $config_skinspath  = replaceDoubleBackslash($config_skinspath);\r
524         $config_mediapath  = replaceDoubleBackslash($config_mediapath);\r
525 \r
526 /**\r
527  * Include and initialize multibyte functions as a replacement for mbstring extension\r
528  *  if mbstring extension is not loaded.\r
529  * Jan.28, 2011. Japanese Package Release Team\r
530  */ \r
531         if (!function_exists('mb_convert_encoding')){\r
532                 global $mbemu_internals;\r
533                 include_once($config_adminpath.'libs/mb_emulator/mb-emulator.php');\r
534         }\r
535         if (function_exists('date_default_timezone_set')){\r
536                  @date_default_timezone_set((function_exists('date_default_timezone_get')) ? @date_default_timezone_get() : 'UTC');\r
537         }\r
538         \r
539         if ($charset == 'ujis') {\r
540                 define('_CHARSET', 'EUC-JP');\r
541                 $config_sitename = mb_convert_encoding($config_sitename, _CHARSET, 'UTF-8');\r
542                 $user_realname  = mb_convert_encoding($user_realname, _CHARSET, 'UTF-8');\r
543                 $blog_name        = mb_convert_encoding($blog_name, _CHARSET, 'UTF-8');\r
544         } else {\r
545                 define('_CHARSET', 'UTF-8');\r
546         }\r
547         \r
548         \r
549         // 1. check all the data\r
550         $errors = array();\r
551 \r
552         if (!$mysql_database) {\r
553                 array_push($errors, _ERROR2);\r
554         }\r
555 \r
556         if (($mysql_usePrefix == 1) && (strlen($mysql_prefix) == 0) ) {\r
557                 array_push($errors, _ERROR3);\r
558         }\r
559 \r
560         if (($mysql_usePrefix == 1) && (!preg_match('#^[a-zA-Z0-9_]+$#', $mysql_prefix) ) ) {\r
561                 array_push($errors, _ERROR4);\r
562         }\r
563 \r
564         // TODO: add action.php check\r
565         if (!endsWithSlash($config_indexurl) || !endsWithSlash($config_adminurl) || !endsWithSlash($config_mediaurl) || !endsWithSlash($config_pluginurl) || !endsWithSlash($config_skinsurl) ) {\r
566                 array_push($errors, _ERROR5);\r
567         }\r
568 \r
569         if (!endsWithSlash($config_adminpath) ) {\r
570                 array_push($errors, _ERROR6);\r
571         }\r
572 \r
573         if (!endsWithSlash($config_mediapath) ) {\r
574                 array_push($errors, _ERROR7);\r
575         }\r
576 \r
577         if (!endsWithSlash($config_skinspath) ) {\r
578                 array_push($errors, _ERROR8);\r
579         }\r
580 \r
581         if (!is_dir($config_adminpath) ) {\r
582                 array_push($errors, _ERROR9);\r
583         }\r
584 \r
585         if (!_isValidMailAddress($user_email) ) {\r
586                 array_push($errors, _ERROR10);\r
587         }\r
588 \r
589         if (!_isValidDisplayName($user_name) ) {\r
590                 array_push($errors, _ERROR11);\r
591         }\r
592 \r
593         if (!$user_password || !$user_password2) {\r
594                 array_push($errors, _ERROR12);\r
595         }\r
596 \r
597         if ($user_password != $user_password2) {\r
598                 array_push($errors, _ERROR13);\r
599         }\r
600 \r
601         if (!_isValidShortName($blog_shortname) ) {\r
602                 array_push($errors, _ERROR14);\r
603         }\r
604 \r
605         if (sizeof($errors) > 0) {\r
606                 showErrorMessages($errors);\r
607         }\r
608 \r
609         // 2. try to log in to mySQL\r
610 \r
611         global $MYSQL_CONN;\r
612         // this will need to be changed if we ever allow\r
613         $MYSQL_CONN = @sql_connect_args($mysql_host, $mysql_user, $mysql_password);\r
614 \r
615         if ($MYSQL_CONN == false) {\r
616                 _doError(_ERROR15 . ': ' . sql_error() );\r
617         }\r
618 \r
619         // 3. try to create database (if needed)\r
620         $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info())));\r
621         $collation = ($charset == 'utf8') ? 'utf8_general_ci' : 'ujis_japanese_ci';\r
622         if ($mysql_create == 1) {\r
623                 $sql = 'CREATE DATABASE '\r
624                          .       $mysql_database;\r
625 // <add for garble measure>\r
626         if (version_compare($mySqlVer, '4.1.0', '>=')) {\r
627                 $sql .= ' DEFAULT CHARACTER SET '\r
628                           .      $charset\r
629                           . ' COLLATE '\r
630                           .      $collation;\r
631         }\r
632 // </add for garble measure>*/\r
633                 sql_query($sql,$MYSQL_CONN) or _doError(_ERROR16 . ': ' . sql_error($MYSQL_CONN));\r
634         }\r
635 \r
636         // 4. try to select database\r
637         sql_select_db($mysql_database,$MYSQL_CONN) or _doError(_ERROR17);\r
638 \r
639         /*\r
640          * 4.5. set character set to this database in MySQL server\r
641          * This processing is added by Nucleus CMS Japanese Package Release Team as of Mar.30, 2011\r
642         */\r
643         sql_set_charset_jp($charset);\r
644         \r
645 \r
646         // 5. execute queries\r
647         $filename = 'install.sql';\r
648         $fd = fopen($filename, 'r');\r
649         $queries = fread($fd, filesize($filename) );\r
650         fclose($fd);\r
651 \r
652         $queries = split("(;\n|;\r)", $queries);\r
653 \r
654         $aTableNames = array(\r
655                 'nucleus_actionlog',\r
656                 'nucleus_ban',\r
657                 'nucleus_blog',\r
658                 'nucleus_category',\r
659                 'nucleus_comment',\r
660                 'nucleus_config',\r
661                 'nucleus_item',\r
662                 'nucleus_karma',\r
663                 'nucleus_member',\r
664                 'nucleus_plugin',\r
665                 'nucleus_skin',\r
666                 'nucleus_template',\r
667                 'nucleus_team',\r
668                 'nucleus_activation',\r
669                 'nucleus_tickets'\r
670         );\r
671 // these are unneeded (one of the replacements above takes care of them)\r
672 //                      'nucleus_plugin_event',\r
673 //                      'nucleus_plugin_option',\r
674 //                      'nucleus_plugin_option_desc',\r
675 //                      'nucleus_skin_desc',\r
676 //                      'nucleus_template_desc',\r
677 \r
678         $aTableNamesPrefixed = array(\r
679                 $mysql_prefix . 'nucleus_actionlog',\r
680                 $mysql_prefix . 'nucleus_ban',\r
681                 $mysql_prefix . 'nucleus_blog',\r
682                 $mysql_prefix . 'nucleus_category',\r
683                 $mysql_prefix . 'nucleus_comment',\r
684                 $mysql_prefix . 'nucleus_config',\r
685                 $mysql_prefix . 'nucleus_item',\r
686                 $mysql_prefix . 'nucleus_karma',\r
687                 $mysql_prefix . 'nucleus_member',\r
688                 $mysql_prefix . 'nucleus_plugin',\r
689                 $mysql_prefix . 'nucleus_skin',\r
690                 $mysql_prefix . 'nucleus_template',\r
691                 $mysql_prefix . 'nucleus_team',\r
692                 $mysql_prefix . 'nucleus_activation',\r
693                 $mysql_prefix . 'nucleus_tickets'\r
694         );\r
695 // these are unneeded (one of the replacements above takes care of them)\r
696 //                      $mysql_prefix . 'nucleus_plugin_event',\r
697 //                      $mysql_prefix . 'nucleus_plugin_option',\r
698 //                      $mysql_prefix . 'nucleus_plugin_option_desc',\r
699 //                      $mysql_prefix . 'nucleus_skin_desc',\r
700 //                      $mysql_prefix . 'nucleus_template_desc',\r
701 \r
702         $count = count($queries);\r
703 \r
704         for ($idx = 0; $idx < $count; $idx++) {\r
705                 $query = trim($queries[$idx]);\r
706                 // echo "QUERY = " . htmlspecialchars($query) . "<p>";\r
707 \r
708                 if ($query) {\r
709 \r
710                         if ($mysql_usePrefix == 1) {\r
711                                         $query = str_replace($aTableNames, $aTableNamesPrefixed, $query);\r
712                         }\r
713 // <add for garble measure>\r
714                         if ($mysql_create != 1 && strpos($query, 'CREATE TABLE') === 0 && version_compare($mySqlVer, '4.1.0', '>=')) {\r
715                                 $query .= ' DEFAULT CHARACTER SET ' . $charset . ' COLLATE ' . $collation;\r
716                         }\r
717 // </add for garble measure>*/\r
718 \r
719                         sql_query($query,$MYSQL_CONN) or _doError(_ERROR30 . ' (' . htmlspecialchars($query) . '): ' . sql_error($MYSQL_CONN) );\r
720                 }\r
721         }\r
722 \r
723         // 5a make first post\r
724         if (strtoupper(_CHARSET) != 'UTF-8') {\r
725                 $itm_title = mb_convert_encoding(_1ST_POST_TITLE, _CHARSET, 'UTF-8');\r
726                 $itm_body  = mb_convert_encoding(_1ST_POST, _CHARSET, 'UTF-8');\r
727                 $itm_more  = mb_convert_encoding(_1ST_POST2, _CHARSET, 'UTF-8');\r
728         } else {\r
729                 $itm_title = _1ST_POST_TITLE;\r
730                 $itm_body  = _1ST_POST;\r
731                 $itm_more  = _1ST_POST2;\r
732         }\r
733         $newpost = "INSERT INTO "\r
734                          . tableName('nucleus_item')\r
735                          . " VALUES ("\r
736                          . "1, "\r
737                          . "'" . $itm_title . "',"\r
738                          . " '" . $itm_body . "',"\r
739                          . " '" . $itm_more . "',"\r
740                          . " 1, 1, '2005-08-15 11:04:26', 0, 0, 0, 1, 0, 1);";\r
741         sql_query($newpost,$MYSQL_CONN) or _doError(_ERROR18 . ' (' . htmlspecialchars($newpost) . '): ' . sql_error($MYSQL_CONN) );\r
742 \r
743         // 6. update global settings\r
744         updateConfig('IndexURL',   $config_indexurl);\r
745         updateConfig('AdminURL',   $config_adminurl);\r
746         updateConfig('MediaURL',   $config_mediaurl);\r
747         updateConfig('SkinsURL',   $config_skinsurl);\r
748         updateConfig('PluginURL',  $config_pluginurl);\r
749         updateConfig('ActionURL',  $config_actionurl);\r
750         updateConfig('AdminEmail', $config_adminemail);\r
751         updateConfig('SiteName',   $config_sitename);\r
752         if ($charset == 'ujis') {\r
753                 updateConfig('Language',   'japanese-euc');\r
754         }\r
755 \r
756         // 7. update GOD member\r
757         $query = 'UPDATE ' . tableName('nucleus_member')\r
758                    . " SET mname         = '" . addslashes($user_name) . "',"\r
759                    . " mrealname         = '" . addslashes($user_realname) . "',"\r
760                    . " mpassword         = '" . md5(addslashes($user_password) ) . "',"\r
761                    . " murl               = '" . addslashes($config_indexurl) . "',"\r
762                    . " memail           = '" . addslashes($user_email) . "',"\r
763                    . " madmin           = 1,"\r
764                    . " mcanlogin         = 1"\r
765                    . " WHERE"\r
766                    . " mnumber     = 1";\r
767 \r
768         sql_query($query,$MYSQL_CONN) or _doError(_ERROR19 . ': ' . sql_error($MYSQL_CONN) );\r
769 \r
770         // 8. update weblog settings\r
771         $query = 'UPDATE ' . tableName('nucleus_blog')\r
772                    . " SET bname  = '" . addslashes($blog_name) . "',"\r
773                    . " bshortname = '" . addslashes($blog_shortname) . "',"\r
774                    . " burl        = '" . addslashes($config_indexurl) . "'"\r
775                    . " WHERE"\r
776                    . " bnumber  = 1";\r
777 \r
778         sql_query($query,$MYSQL_CONN) or _doError(_ERROR20 . ': ' . sql_error($MYSQL_CONN) );\r
779 \r
780         // 8-2. update category settings\r
781         if (strtoupper(_CHARSET) != 'UTF-8') {\r
782                 $cat_name = mb_convert_encoding(_GENERALCAT_NAME, _CHARSET, 'UTF-8');\r
783                 $cat_desc = mb_convert_encoding(_GENERALCAT_DESC, _CHARSET, 'UTF-8');\r
784         } else {\r
785                 $cat_name = _GENERALCAT_NAME;\r
786                 $cat_desc = _GENERALCAT_DESC;\r
787         }\r
788         $query = 'UPDATE ' . tableName('nucleus_category')\r
789                    . " SET cname  = '" . $cat_name . "',"\r
790                    . " cdesc      = '" . $cat_desc . "'"\r
791                    . " WHERE"\r
792                    . " catid      = 1";\r
793 \r
794         sql_query($query,$MYSQL_CONN) or _doError(_ERROR20 . ': ' . sql_error($MYSQL_CONN) );\r
795 \r
796         // 9. update item date\r
797         $query = 'UPDATE ' . tableName('nucleus_item')\r
798                    . " SET   itime   = '" . date('Y-m-d H:i:s', time() ) ."'"\r
799                    . " WHERE inumber = 1";\r
800 \r
801         sql_query($query,$MYSQL_CONN) or _doError(_ERROR21 . ': ' . sql_error($MYSQL_CONN) );\r
802 \r
803         global $aConfPlugsToInstall, $aConfSkinsToImport;\r
804         $aSkinErrors = array();\r
805         $aPlugErrors = array();\r
806 \r
807         if ((count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) ) {\r
808                 // 10. set global variables\r
809                 global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX;\r
810 \r
811                 $MYSQL_HOST      = $mysql_host;\r
812                 $MYSQL_USER      = $mysql_user;\r
813                 $MYSQL_PASSWORD = $mysql_password;\r
814                 $MYSQL_DATABASE = $mysql_database;\r
815                 $MYSQL_PREFIX   = ($mysql_usePrefix == 1) ? $mysql_prefix : '';\r
816 \r
817                 global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;\r
818 \r
819                 $DIR_NUCLEUS = $config_adminpath;\r
820                 $DIR_MEDIA   = $config_mediapath;\r
821                 $DIR_SKINS   = $config_skinspath;\r
822                 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';\r
823                 $DIR_LANG       = $DIR_NUCLEUS . 'language/';\r
824                 $DIR_LIBS       = $DIR_NUCLEUS . 'libs/';\r
825 \r
826                 // close database connection (needs to be closed if we want to include globalfunctions.php)\r
827                 sql_close($MYSQL_CONN);\r
828 \r
829                 $manager = '';\r
830                 include_once($DIR_LIBS . 'globalfunctions.php');\r
831 \r
832                 // 11. install custom skins\r
833                 $aSkinErrors = installCustomSkins($manager);\r
834                 $defskinQue  = 'SELECT `sdnumber` as result FROM ' . sql_table('skin_desc') . ' WHERE `sdname` = "default"';\r
835                 $defSkinID   = quickQuery($defskinQue);\r
836                 $updateQuery = 'UPDATE ' . sql_table('blog') . ' SET `bdefskin` = ' . intval($defSkinID) . ' WHERE `bnumber` = 1';\r
837                 sql_query($updateQuery);\r
838                 $updateQuery = 'UPDATE ' . sql_table('config') . ' SET `value` = ' . intval($defSkinID). ' WHERE `name` = "BaseSkin"';\r
839                 sql_query($updateQuery);\r
840 \r
841                 // 12. install NP_Ping, if decided\r
842                 if ($weblog_ping == 1) {\r
843                         global $aConfPlugsToInstall;\r
844                         array_push($aConfPlugsToInstall, "NP_Ping");\r
845                 }\r
846 \r
847                 // 13. install custom plugins\r
848                 $aPlugErrors = installCustomPlugs($manager);\r
849         }\r
850 \r
851         // 14. Write config file ourselves (if possible)\r
852         $bConfigWritten = 0;\r
853 \r
854         if (@file_exists('../config.php') && is_writable('../config.php') && $fp = @fopen('../config.php', 'w') ) {\r
855                 $config_data = '<' . '?php' . "\n\n";\r
856                 //$config_data .= "\n"; (extraneous, just added extra \n to previous line\r
857                 $config_data .= "   // mySQL connection information\n";\r
858                 $config_data .= "   \$MYSQL_HOST         = '" . $mysql_host . "';\n";\r
859                 $config_data .= "   \$MYSQL_USER         = '" . $mysql_user . "';\n";\r
860                 $config_data .= "   \$MYSQL_PASSWORD = '" . $mysql_password . "';\n";\r
861                 $config_data .= "   \$MYSQL_DATABASE = '" . $mysql_database . "';\n";\r
862                 $config_data .= "   \$MYSQL_PREFIX   = '" . (($mysql_usePrefix == 1) ? $mysql_prefix : '') . "';\n";\r
863                 $config_data .= "   // new in 3.50. first element is db handler, the second is the db driver used by the handler\n";\r
864                 $config_data .= "   // default is \$MYSQL_HANDLER = array('mysql','');\n";\r
865                 $config_data .= "   //\$MYSQL_HANDLER = array('mysql','mysql');\n";\r
866                 $config_data .= "   //\$MYSQL_HANDLER = array('pdo','mysql');\n";\r
867                 $config_data .= "   \$MYSQL_HANDLER = array('".$MYSQL_HANDLER[0]."','".$MYSQL_HANDLER[1]."');\n";\r
868                 $config_data .= "\n";\r
869                 $config_data .= "   // main nucleus directory\n";\r
870                 $config_data .= "   \$DIR_NUCLEUS = '" . $config_adminpath . "';\n";\r
871                 $config_data .= "\n";\r
872                 $config_data .= "   // path to media dir\n";\r
873                 $config_data .= "   \$DIR_MEDIA   = '" . $config_mediapath . "';\n";\r
874                 $config_data .= "\n";\r
875                 $config_data .= "   // extra skin files for imported skins\n";\r
876                 $config_data .= "   \$DIR_SKINS   = '" . $config_skinspath . "';\n";\r
877                 $config_data .= "\n";\r
878                 $config_data .= "   // these dirs are normally sub dirs of the nucleus dir, but \n";\r
879                 $config_data .= "   // you can redefine them if you wish\n";\r
880                 $config_data .= "   \$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";\r
881                 $config_data .= "   \$DIR_LANG  = \$DIR_NUCLEUS . 'language/';\n";\r
882                 $config_data .= "   \$DIR_LIBS  = \$DIR_NUCLEUS . 'libs/';\n";\r
883                 $config_data .= "\n";\r
884                 $config_data .= "   // include libs\n";\r
885                 $config_data .= "   include(\$DIR_LIBS . 'globalfunctions.php');\n";\r
886                 $config_data .= "?" . ">";\r
887 \r
888                 $result = @fputs($fp, $config_data, strlen($config_data) );\r
889                 fclose($fp);\r
890 \r
891                 if ($result) {\r
892                         $bConfigWritten = 1;\r
893                 }\r
894         }\r
895 \r
896 ?>\r
897 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
898 <html xmlns="http://www.w3.org/1999/xhtml">\r
899 <head>\r
900         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
901         <title><?php echo _TITLE; ?></title>\r
902         <style>@import url('../nucleus/styles/manual.css');</style>\r
903 </head>\r
904 <body>\r
905         <div style="text-align:center"><img src="../nucleus/styles/logo.gif" alt="<?php echo _ALT_NUCLEUS_CMS_LOGO; ?>" /></div> <!-- Nucleus logo -->\r
906 \r
907 <?php\r
908         $aAllErrors = array_merge($aSkinErrors, $aPlugErrors);\r
909 \r
910         if (count($aAllErrors) > 0) {\r
911                 echo '<h1>' . _TITLE2 . '</h1>';\r
912                 echo '<ul><li>' . implode('</li><li>', $aAllErrors) . '</li></ul>';\r
913         }\r
914 \r
915         if (!$bConfigWritten) { ?>\r
916                 <h1><?php echo _TITLE3; ?></h1>\r
917 \r
918                 <?php echo _TEXT10; ?>\r
919 \r
920                 <pre><code>&lt;?php\r
921         // mySQL connection information\r
922         $MYSQL_HOST      = '<b><?php echo $mysql_host?></b>';\r
923         $MYSQL_USER      = '<b><?php echo $mysql_user?></b>';\r
924         $MYSQL_PASSWORD = '<i><b>xxxxxxxxxxx</b></i>';\r
925         $MYSQL_DATABASE = '<b><?php echo $mysql_database?></b>';\r
926         $MYSQL_PREFIX   = '<b><?php echo ($mysql_usePrefix == 1)?$mysql_prefix:''?></b>';\r
927 \r
928         // new in 3.50. first element is db handler, the second is the db driver used by the handler\r
929         // default is $MYSQL_HANDLER = array('mysql','');\r
930         $MYSQL_HANDLER = array('<?php echo $MYSQL_HANDLER[0];?>','<?php echo $MYSQL_HANDLER[1];?>');\r
931 \r
932         // main nucleus directory\r
933         $DIR_NUCLEUS = '<b><?php echo $config_adminpath?></b>';\r
934 \r
935         // path to media dir\r
936         $DIR_MEDIA   = '<b><?php echo $config_mediapath?></b>';\r
937 \r
938         // extra skin files for imported skins\r
939         $DIR_SKINS   = '<b><?php echo $config_skinspath?></b>';\r
940 \r
941         // these dirs are normally sub dirs of the nucleus dir, but\r
942         // you can redefine them if you wish\r
943         $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';\r
944         $DIR_LANG       = $DIR_NUCLEUS . 'language/';\r
945         $DIR_LIBS       = $DIR_NUCLEUS . 'libs/';\r
946 \r
947         // include libs\r
948         include($DIR_LIBS . 'globalfunctions.php');\r
949 ?&gt;</code></pre>\r
950 \r
951         <?php echo _TEXT11; ?>\r
952 \r
953         <div class="note">\r
954         <?php echo _TEXT12; ?>\r
955         </div>\r
956 \r
957 <?php } else { ?>\r
958 \r
959         <h1><?php echo _TITLE4; ?></h1>\r
960 \r
961         <?php echo _TEXT13; ?>\r
962 \r
963 <?php } ?>\r
964 \r
965         <h1><?php echo _TITLE5; ?></h1>\r
966         \r
967         <?php echo _TEXT14; ?>\r
968 \r
969         <ul>\r
970                 <li><?php echo _TEXT14_L1; ?></li>\r
971                 <li><?php echo _TEXT14_L2; ?></li>\r
972         </ul>\r
973 \r
974         <h1><?php echo _HEADER10; ?></h1>\r
975 \r
976         <?php echo _TEXT15; ?>\r
977 \r
978                 <ul>\r
979                 <li><?php echo _TEXT15_L1; ?></li>\r
980                 <li><?php echo _TEXT15_L2; ?></li>\r
981                 <li><?php echo _TEXT15_L3; ?></li>\r
982                 </ul>\r
983 \r
984         <?php echo _TEXT16; ?>\r
985 \r
986         <h1><?php echo _HEADER11; ?></h1>\r
987 \r
988         <p><?php echo _TEXT16_H; ?>\r
989                 <ul>\r
990                         <li><a href="<?php echo $config_adminurl?>"><?php echo _TEXT16_L1; ?></a></li>\r
991                         <li><a href="<?php echo $config_indexurl?>"><?php echo _TEXT16_L2; ?></a></li>\r
992                 </ul>\r
993         </p>\r
994 \r
995 </body>\r
996 </html>\r
997 \r
998 <?php\r
999 }\r
1000 \r
1001 /**\r
1002  *  Install custom plugins\r
1003  */\r
1004 function installCustomPlugs(&$manager) {\r
1005         global $aConfPlugsToInstall, $DIR_LIBS;\r
1006 \r
1007         $aErrors = array();\r
1008 \r
1009         if (count($aConfPlugsToInstall) == 0) {\r
1010                 return $aErrors;\r
1011         }\r
1012 \r
1013         $res = sql_query('SELECT * FROM ' . sql_table('plugin') );\r
1014         $numCurrent = sql_num_rows($res);\r
1015 \r
1016         foreach ($aConfPlugsToInstall as $plugName) {\r
1017                 // do this before calling getPlugin (in case the plugin id is used there)\r
1018                 $query = 'INSERT INTO ' . sql_table('plugin') . ' (porder, pfile) VALUES (' . (++$numCurrent) . ', "' . addslashes($plugName) . '")';\r
1019                 sql_query($query);\r
1020 \r
1021                 // get and install the plugin\r
1022                 $manager->clearCachedInfo('installedPlugins');\r
1023                 $plugin =& $manager->getPlugin($plugName);\r
1024                 $plugin->plugid = $numCurrent;\r
1025 \r
1026                 if (!$plugin) {\r
1027                         sql_query('DELETE FROM ' . sql_table('plugin') . ' WHERE pfile=\'' . addslashes($plugName) . '\'');\r
1028                         $numCurrent--;\r
1029                         array_push($aErrors, _ERROR22 . $plugName);\r
1030                         continue;\r
1031                 }\r
1032 \r
1033                 $plugin->install();\r
1034         }\r
1035 \r
1036         // SYNC PLUGIN EVENT LIST\r
1037         sql_query('DELETE FROM ' . sql_table('plugin_event') );\r
1038 \r
1039         // loop over all installed plugins\r
1040         $res = sql_query('SELECT pid, pfile FROM ' . sql_table('plugin') );\r
1041 \r
1042         while($o = sql_fetch_object($res) ) {\r
1043                 $pid  =  $o->pid;\r
1044                 $plug =& $manager->getPlugin($o->pfile);\r
1045 \r
1046                 if ($plug) {\r
1047                         $eventList = $plug->getEventList();\r
1048 \r
1049                         foreach ($eventList as $eventName) {\r
1050                                 sql_query('INSERT INTO ' . sql_table('plugin_event') . ' (pid, event) VALUES (' . $pid . ', \'' . $eventName . '\')');\r
1051                         }\r
1052                 }\r
1053         }\r
1054 \r
1055         return $aErrors;\r
1056 }\r
1057 \r
1058 /**\r
1059  *  Install custom skins\r
1060  *  Prepares the installation of custom skins\r
1061  */\r
1062 function installCustomSkins(&$manager) {\r
1063         global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS;\r
1064 \r
1065         $aErrors = array();\r
1066         global $manager;\r
1067         if (empty($manager)) {\r
1068                 $manager = new MANAGER;\r
1069         }\r
1070 \r
1071         if (count($aConfSkinsToImport) == 0) {\r
1072                 return $aErrors;\r
1073         }\r
1074 \r
1075         // load skinie class\r
1076         include_once($DIR_LIBS . 'skinie.php');\r
1077 \r
1078         $importer = new SKINIMPORT();\r
1079 \r
1080         foreach ($aConfSkinsToImport as $skinName) {\r
1081                 $importer->reset();\r
1082                 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';\r
1083 \r
1084                 if (!@file_exists($skinFile) ) {\r
1085                         array_push($aErrors, _ERROR23_1 . $skinFile . ' : ' . _ERROR23_2);\r
1086                         continue;\r
1087                 }\r
1088 \r
1089                 $error = $importer->readFile($skinFile);\r
1090 \r
1091                 if ($error) {\r
1092                         array_push($aErrors, _ERROR24 . $skinName . ' : ' . $error);\r
1093                         continue;\r
1094                 }\r
1095 \r
1096                 $error = $importer->writeToDatabase(1);\r
1097 \r
1098                 if ($error) {\r
1099                         array_push($aErrors, _ERROR24 . $skinName . ' : ' . $error);\r
1100                         continue;\r
1101                 }\r
1102         }\r
1103 \r
1104         return $aErrors;\r
1105 }\r
1106 \r
1107 /**\r
1108  *  Check if some important files of the Nucleus CMS installation are available\r
1109  *  Give an error if one or more files are not accessible\r
1110  */\r
1111 function doCheckFiles() {\r
1112         $missingfiles = array();\r
1113         $files = array(\r
1114                 'install.sql',\r
1115                 '../index.php',\r
1116                 '../action.php',\r
1117                 '../nucleus/index.php',\r
1118                 '../nucleus/libs/globalfunctions.php',\r
1119                 '../nucleus/libs/ADMIN.php',\r
1120                 '../nucleus/libs/BLOG.php',\r
1121                 '../nucleus/libs/COMMENT.php',\r
1122                 '../nucleus/libs/COMMENTS.php',\r
1123                 '../nucleus/libs/ITEM.php',\r
1124                 '../nucleus/libs/MEMBER.php',\r
1125                 '../nucleus/libs/SKIN.php',\r
1126                 '../nucleus/libs/TEMPLATE.php',\r
1127                 '../nucleus/libs/MEDIA.php',\r
1128                 '../nucleus/libs/ACTIONLOG.php',\r
1129                 '../nucleus/media.php'\r
1130         );\r
1131 \r
1132         $count = count($files);\r
1133 \r
1134         for ($i = 0; $i < $count; $i++) {\r
1135                 if (!is_readable($files[$i]) ) {\r
1136                         array_push($missingfiles, _ERROR25_1 . $files[$i] . _ERROR25_2);\r
1137                 }\r
1138         }\r
1139 \r
1140         if (count($missingfiles) > 0) {\r
1141                 showErrorMessages($missingfiles);\r
1142         }\r
1143 }\r
1144 \r
1145 /**\r
1146  *  Updates the configuration in the database\r
1147  * \r
1148  *  @param      $name\r
1149  *                      name of the config var\r
1150  *  @param      $val\r
1151  *                      new value of the config var\r
1152  */\r
1153 function updateConfig($name, $val) {\r
1154         global $MYSQL_CONN;\r
1155         $name = addslashes($name);\r
1156         $val  = trim(addslashes($val) );\r
1157 \r
1158         $query = 'UPDATE ' . tableName('nucleus_config')\r
1159                    . " SET   value = '$val'"\r
1160                    . " WHERE name  = '$name'";\r
1161 \r
1162         sql_query($query,$MYSQL_CONN) or _doError(_ERROR26 . ': ' . sql_error($MYSQL_CONN) );\r
1163         return sql_insert_id($MYSQL_CONN);\r
1164 }\r
1165 \r
1166 /**\r
1167  *  Replaces doubled backslashs\r
1168  * \r
1169  *  @param      $input\r
1170  *                      string that could have double backslashs\r
1171  */\r
1172 function replaceDoubleBackslash($input) {\r
1173         return str_replace('\\', '/', $input);\r
1174 }\r
1175 \r
1176 /**\r
1177  * Checks if a string ends with a slash \r
1178  * \r
1179  *  @param      $s\r
1180  *                      string\r
1181  */\r
1182 function endsWithSlash($s) {\r
1183         return (strrpos($s, '/') == strlen($s) - 1);\r
1184 }\r
1185 \r
1186 /**\r
1187  * Checks if email address is valid\r
1188  * \r
1189  *  @param      $address\r
1190  *                      address which should be tested\r
1191  */\r
1192 function _isValidMailAddress($address) {\r
1193         if (preg_match("#^[a-zA-Z0-9\._-]+@+[A-Za-z0-9\._-]+\.+[A-Za-z]{2,4}$#", $address) ) {\r
1194                 return 1;\r
1195         } else {\r
1196                 return 0;\r
1197         }\r
1198 }\r
1199 \r
1200 /*\r
1201  * Check if short blog names and nicknames are allowed\r
1202  * Returns true if the given string is a valid shortname\r
1203  * logic: only letters and numbers are allowed, no spaces allowed\r
1204  * \r
1205  * FIX: function eregi is deprecated since PHP 5.3.0\r
1206  * \r
1207  * @param       $name\r
1208  *                      name which should be tested     \r
1209  */\r
1210 function _isValidShortName($name) {\r
1211         if (preg_match("#^[a-zA-Z0-9]+$#", $name) ) {\r
1212                 return 1;\r
1213         } else {\r
1214                 return 0;\r
1215         }\r
1216 }\r
1217 \r
1218 /*\r
1219  * Check if a display name is allowed\r
1220  * Returns true if the given string is a valid display name\r
1221  * \r
1222  * FIX: function eregi is deprecated since PHP 5.3.0\r
1223  * \r
1224  * @param       $name\r
1225  *                      name which should be tested\r
1226  */\r
1227 function _isValidDisplayName($name) {\r
1228         if (preg_match("#^[a-zA-Z0-9]+[a-zA-Z0-9 ]*[a-zA-Z0-9]+$#", $name) ) {\r
1229                 return 1;\r
1230         } else {\r
1231                 return 0;\r
1232         }\r
1233 }\r
1234 \r
1235 /*\r
1236  * Shows error message\r
1237  * \r
1238  * @param       $msg\r
1239  *                      error message\r
1240  */\r
1241 function _doError($msg) {\r
1242         ?>\r
1243 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
1244 <html xmlns="http://www.w3.org/1999/xhtml">\r
1245 <head>\r
1246         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
1247         <title><?php echo _TITLE; ?></title>\r
1248         <style>@import url('../nucleus/styles/manual.css');</style>\r
1249 </head>\r
1250 <body>\r
1251         <div style="text-align:center"><img src="../nucleus/styles/logo.gif" alt="<?php echo _ALT_NUCLEUS_CMS_LOGO; ?>" /></div> <!-- Nucleus logo -->\r
1252         <h1><?php echo _ERROR27; ?></h1>\r
1253 \r
1254         <p><?php echo _ERROR28; ?> "<?php echo $msg; ?>";</p>\r
1255 \r
1256         <p><a href="index.php" onclick="history.back();return false;"><?php echo _TEXT17; ?></a></p>\r
1257 </body>\r
1258 </html>\r
1259 \r
1260 <?php\r
1261         exit;\r
1262 }\r
1263 \r
1264 /*\r
1265  * Shows error messages\r
1266  * \r
1267  * @param       $errors\r
1268  *                      array with error messages\r
1269  */\r
1270 function showErrorMessages($errors) {\r
1271         ?>\r
1272 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
1273 <html xmlns="http://www.w3.org/1999/xhtml">\r
1274 <head>\r
1275         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
1276         <title><?php echo _TITLE; ?></title>\r
1277         <style>@import url('../nucleus/styles/manual.css');</style>\r
1278 </head>\r
1279 <body>\r
1280         <div style="text-align:center"><img src="../nucleus/styles/logo.gif" alt="<?php echo _ALT_NUCLEUS_CMS_LOGO; ?>" /></div> <!-- Nucleus logo -->\r
1281         <h1><?php echo _ERROR27; ?></h1>\r
1282 \r
1283         <p><?php echo _ERROR29; ?>:</p>\r
1284 \r
1285         <ul>\r
1286 \r
1287 <?php\r
1288         while($msg = array_shift($errors) ) {\r
1289                 echo '<li>' . $msg . '</li>';\r
1290         }\r
1291 ?>\r
1292 \r
1293         </ul>\r
1294 \r
1295         <p><a href="index.php" onclick="history.back();return false;"><?php echo _TEXT17; ?></a></p>\r
1296 </body>\r
1297 </html>\r
1298 \r
1299 <?php\r
1300         exit;\r
1301 }\r
1302 \r
1303 /* for the non-php systems that decide to show the contents:\r
1304 ?></div><?php   */\r
1305 \r
1306 ?>