OSDN Git Service

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