OSDN Git Service

8aab67194248d5ba2a388e809c962f19d59c809a
[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 ($charset == 'ujis') {\r
484                 define('_CHARSET', 'EUC-JP');\r
485                 $config_sitename = mb_convert_encoding($config_sitename, _CHARSET, 'UTF-8');\r
486                 $user_realname  = mb_convert_encoding($user_realname, _CHARSET, 'UTF-8');\r
487                 $blog_name      = mb_convert_encoding($blog_name, _CHARSET, 'UTF-8');\r
488         } else {\r
489                 define('_CHARSET', 'UTF-8');\r
490         }\r
491 \r
492         $config_indexurl   = replaceDoubleBackslash($config_indexurl);\r
493         $config_adminurl   = replaceDoubleBackslash($config_adminurl);\r
494         $config_mediaurl   = replaceDoubleBackslash($config_mediaurl);\r
495         $config_skinsurl   = replaceDoubleBackslash($config_skinsurl);\r
496         $config_pluginurl  = replaceDoubleBackslash($config_pluginurl);\r
497         $config_actionurl  = replaceDoubleBackslash($config_actionurl);\r
498         $config_adminpath  = replaceDoubleBackslash($config_adminpath);\r
499         $config_skinspath  = replaceDoubleBackslash($config_skinspath);\r
500         $config_mediapath  = replaceDoubleBackslash($config_mediapath);\r
501 \r
502         // 1. check all the data\r
503         $errors = array();\r
504 \r
505         if (!$mysql_database) {\r
506                 array_push($errors, _ERROR2);\r
507         }\r
508 \r
509         if (($mysql_usePrefix == 1) && (strlen($mysql_prefix) == 0) ) {\r
510                 array_push($errors, _ERROR3);\r
511         }\r
512 \r
513         if (($mysql_usePrefix == 1) && (!eregi('^[a-zA-Z0-9_]+$', $mysql_prefix) ) ) {\r
514                 array_push($errors, _ERROR4);\r
515         }\r
516 \r
517         // TODO: add action.php check\r
518         if (!endsWithSlash($config_indexurl) || !endsWithSlash($config_adminurl) || !endsWithSlash($config_mediaurl) || !endsWithSlash($config_pluginurl) || !endsWithSlash($config_skinsurl) ) {\r
519                 array_push($errors, _ERROR5);\r
520         }\r
521 \r
522         if (!endsWithSlash($config_adminpath) ) {\r
523                 array_push($errors, _ERROR6);\r
524         }\r
525 \r
526         if (!endsWithSlash($config_mediapath) ) {\r
527                 array_push($errors, _ERROR7);\r
528         }\r
529 \r
530         if (!endsWithSlash($config_skinspath) ) {\r
531                 array_push($errors, _ERROR8);\r
532         }\r
533 \r
534         if (!is_dir($config_adminpath) ) {\r
535                 array_push($errors, _ERROR9);\r
536         }\r
537 \r
538         if (!_isValidMailAddress($user_email) ) {\r
539                 array_push($errors, _ERROR10);\r
540         }\r
541 \r
542         if (!_isValidDisplayName($user_name) ) {\r
543                 array_push($errors, _ERROR11);\r
544         }\r
545 \r
546         if (!$user_password || !$user_password2) {\r
547                 array_push($errors, _ERROR12);\r
548         }\r
549 \r
550         if ($user_password != $user_password2) {\r
551                 array_push($errors, _ERROR13);\r
552         }\r
553 \r
554         if (!_isValidShortName($blog_shortname) ) {\r
555                 array_push($errors, _ERROR14);\r
556         }\r
557 \r
558         if (sizeof($errors) > 0) {\r
559                 showErrorMessages($errors);\r
560         }\r
561 \r
562         // 2-1. try to log in to mySQL\r
563         global $MYSQL_CONN;\r
564         $MYSQL_CONN = @mysql_connect($mysql_host, $mysql_user, $mysql_password);\r
565 \r
566         if ($MYSQL_CONN == false) {\r
567                 _doError(_ERROR15 . ': ' . mysql_error() );\r
568         }\r
569 \r
570 /*/ <add for garble measure>\r
571         // 2-2. set DEFAULT CHARSET and COLLATE\r
572         $mySqlVer = implode('.', array_map('intval', explode('.', mysql_get_server_info($MYSQL_CONN))));\r
573         if ($mySqlVer >= '5.0.7' && phpversion() >= '5.2.3') {\r
574                 mysql_set_charset($charset);\r
575         } else {\r
576                 mysql_query("SET NAMES " . $charset);\r
577         }\r
578         $collation = ($charset == 'utf8') ? 'utf8_unicode_ci' : 'ujis_japanese_ci';\r
579 // </add for garble measure>*/\r
580 \r
581         // 3. try to create database (if needed)\r
582         if ($mysql_create == 1) {\r
583                 $sql = 'CREATE DATABASE '\r
584                          .     $mysql_database\r
585 /*/ <add for garble measure>\r
586                          . ' DEFAULT CHARACTER SET '\r
587                          .     $charset\r
588                          . ' COLLATE '\r
589                          .     $collation\r
590 // </add for garble measure>*/\r
591                          . '';\r
592                 mysql_query($sql) or _doError(_ERROR16 . ': ' . mysql_error());\r
593         }\r
594 \r
595         // 4. try to select database\r
596         mysql_select_db($mysql_database) or _doError(_ERROR17);\r
597 \r
598         // 5. execute queries\r
599         $filename = 'install.sql';\r
600         $fd = fopen($filename, 'r');\r
601         $queries = fread($fd, filesize($filename) );\r
602         fclose($fd);\r
603 \r
604         $queries = split("(;\n|;\r)", $queries);\r
605 \r
606         $aTableNames = array(\r
607                 'nucleus_actionlog',\r
608                 'nucleus_ban',\r
609                 'nucleus_blog',\r
610                 'nucleus_category',\r
611                 'nucleus_comment',\r
612                 'nucleus_config',\r
613                 'nucleus_item',\r
614                 'nucleus_karma',\r
615                 'nucleus_member',\r
616                 'nucleus_plugin',\r
617                 'nucleus_skin',\r
618                 'nucleus_template',\r
619                 'nucleus_team',\r
620                 'nucleus_activation',\r
621                 'nucleus_tickets'\r
622         );\r
623 // these are unneeded (one of the replacements above takes care of them)\r
624 //                      'nucleus_plugin_event',\r
625 //                      'nucleus_plugin_option',\r
626 //                      'nucleus_plugin_option_desc',\r
627 //                      'nucleus_skin_desc',\r
628 //                      'nucleus_template_desc',\r
629 \r
630         $aTableNamesPrefixed = array(\r
631                 $mysql_prefix . 'nucleus_actionlog',\r
632                 $mysql_prefix . 'nucleus_ban',\r
633                 $mysql_prefix . 'nucleus_blog',\r
634                 $mysql_prefix . 'nucleus_category',\r
635                 $mysql_prefix . 'nucleus_comment',\r
636                 $mysql_prefix . 'nucleus_config',\r
637                 $mysql_prefix . 'nucleus_item',\r
638                 $mysql_prefix . 'nucleus_karma',\r
639                 $mysql_prefix . 'nucleus_member',\r
640                 $mysql_prefix . 'nucleus_plugin',\r
641                 $mysql_prefix . 'nucleus_skin',\r
642                 $mysql_prefix . 'nucleus_template',\r
643                 $mysql_prefix . 'nucleus_team',\r
644                 $mysql_prefix . 'nucleus_activation',\r
645                 $mysql_prefix . 'nucleus_tickets'\r
646         );\r
647 // these are unneeded (one of the replacements above takes care of them)\r
648 //                      $mysql_prefix . 'nucleus_plugin_event',\r
649 //                      $mysql_prefix . 'nucleus_plugin_option',\r
650 //                      $mysql_prefix . 'nucleus_plugin_option_desc',\r
651 //                      $mysql_prefix . 'nucleus_skin_desc',\r
652 //                      $mysql_prefix . 'nucleus_template_desc',\r
653 \r
654         $count = count($queries);\r
655 \r
656         for ($idx = 0; $idx < $count; $idx++) {\r
657                 $query = trim($queries[$idx]);\r
658                 // echo "QUERY = <small>" . htmlspecialchars($query) . "</small><p>";\r
659 \r
660                 if ($query) {\r
661 \r
662                         if ($mysql_usePrefix == 1) {\r
663                                         $query = str_replace($aTableNames, $aTableNamesPrefixed, $query);\r
664                         }\r
665 /*/ <add for garble measure>\r
666                         if ($mysql_create != 1 && strpos($query, 'CREATE TABLE') === 0) {\r
667                                 $query .= ' DEFAULT CHARACTER SET ' . $charset . ' COLLATE ' . $collation;\r
668                         }\r
669 // </add for garble measure>*/\r
670 \r
671                         mysql_query($query) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($query) . '</small>): ' . mysql_error() );\r
672                 }\r
673         }\r
674 \r
675         // 5a make first post\r
676         if ($charset == 'ujis') {\r
677                 $itm_title = mb_convert_encoding(_1ST_POST_TITLE, _CHARSET, 'UTF-8');\r
678                 $itm_body  = mb_convert_encoding(_1ST_POST, _CHARSET, 'UTF-8');\r
679                 $itm_more  = mb_convert_encoding(_1ST_POST2, _CHARSET, 'UTF-8');\r
680         } else {\r
681                 $itm_title = _1ST_POST_TITLE;\r
682                 $itm_body  = _1ST_POST;\r
683                 $itm_more  = _1ST_POST2;\r
684         }\r
685         $newpost = "INSERT INTO "\r
686                          . tableName('nucleus_item')\r
687                          . " VALUES ("\r
688                          . "1, "\r
689                          . "'" . $itm_title . "',"\r
690                          . " '" . $itm_body . "',"\r
691                          . " '" . $itm_more . "',"\r
692                          . " 1, 1, '2005-08-15 11:04:26', 0, 0, 0, 1, 0, 1);";\r
693         mysql_query($newpost) or _doError(_ERROR18 . ' (<small>' . htmlspecialchars($newpost) . '</small>): ' . mysql_error() );\r
694 \r
695         // 6. update global settings\r
696         updateConfig('IndexURL',   $config_indexurl);\r
697         updateConfig('AdminURL',   $config_adminurl);\r
698         updateConfig('MediaURL',   $config_mediaurl);\r
699         updateConfig('SkinsURL',   $config_skinsurl);\r
700         updateConfig('PluginURL',  $config_pluginurl);\r
701         updateConfig('ActionURL',  $config_actionurl);\r
702         updateConfig('AdminEmail', $config_adminemail);\r
703         updateConfig('SiteName',   $config_sitename);\r
704         if ($charset == 'ujis') {\r
705                 updateConfig('Language',   'japanese-euc');\r
706         }\r
707 \r
708         // 7. update GOD member\r
709         $query = 'UPDATE ' . tableName('nucleus_member')\r
710                    . " SET mname     = '" . addslashes($user_name) . "',"\r
711                    . " mrealname     = '" . addslashes($user_realname) . "',"\r
712                    . " mpassword     = '" . md5(addslashes($user_password) ) . "',"\r
713                    . " murl          = '" . addslashes($config_indexurl) . "',"\r
714                    . " memail        = '" . addslashes($user_email) . "',"\r
715                    . " madmin        = 1,"\r
716                    . " mcanlogin     = 1"\r
717                    . " WHERE"\r
718                    . " mnumber       = 1";\r
719 \r
720         mysql_query($query) or _doError(_ERROR19 . ': ' . mysql_error() );\r
721 \r
722         // 8. update weblog settings\r
723         $query = 'UPDATE ' . tableName('nucleus_blog')\r
724                    . " SET bname  = '" . addslashes($blog_name) . "',"\r
725                    . " bshortname = '" . addslashes($blog_shortname) . "',"\r
726                    . " burl       = '" . addslashes($config_indexurl) . "'"\r
727                    . " WHERE"\r
728                    . " bnumber    = 1";\r
729 \r
730         mysql_query($query) or _doError(_ERROR20 . ': ' . mysql_error() );\r
731 \r
732         // 8-2. update category settings\r
733         if ($charset == 'ujis') {\r
734                 $cat_name = mb_convert_encoding(_GENERALCAT_NAME, _CHARSET, 'UTF-8');\r
735                 $cat_desc = mb_convert_encoding(_GENERALCAT_DESC, _CHARSET, 'UTF-8');\r
736         } else {\r
737                 $cat_name = _GENERALCAT_NAME;\r
738                 $cat_desc = _GENERALCAT_DESC;\r
739         }\r
740         $query = 'UPDATE ' . tableName('nucleus_category')\r
741                    . " SET cname  = '" . $cat_name . "',"\r
742                    . " cdesc      = '" . $cat_desc . "'"\r
743                    . " WHERE"\r
744                    . " catid      = 1";\r
745 \r
746         mysql_query($query) or _doError(_ERROR20 . ': ' . mysql_error() );\r
747 \r
748         // 9. update item date\r
749         $query = 'UPDATE ' . tableName('nucleus_item')\r
750                    . " SET   itime   = '" . date('Y-m-d H:i:s', time() ) ."'"\r
751                    . " WHERE inumber = 1";\r
752 \r
753         mysql_query($query) or _doError(_ERROR21 . ': ' . mysql_error() );\r
754 \r
755         global $aConfPlugsToInstall, $aConfSkinsToImport;\r
756         $aSkinErrors = array();\r
757         $aPlugErrors = array();\r
758 \r
759         if ((count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) ) {\r
760                 // 10. set global variables\r
761                 global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_PREFIX;\r
762 \r
763                 $MYSQL_HOST     = $mysql_host;\r
764                 $MYSQL_USER     = $mysql_user;\r
765                 $MYSQL_PASSWORD = $mysql_password;\r
766                 $MYSQL_DATABASE = $mysql_database;\r
767                 $MYSQL_PREFIX   = ($mysql_usePrefix == 1) ? $mysql_prefix : '';\r
768 \r
769                 global $DIR_NUCLEUS, $DIR_MEDIA, $DIR_SKINS, $DIR_PLUGINS, $DIR_LANG, $DIR_LIBS;\r
770 \r
771                 $DIR_NUCLEUS = $config_adminpath;\r
772                 $DIR_MEDIA   = $config_mediapath;\r
773                 $DIR_SKINS   = $config_skinspath;\r
774                 $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';\r
775                 $DIR_LANG    = $DIR_NUCLEUS . 'language/';\r
776                 $DIR_LIBS    = $DIR_NUCLEUS . 'libs/';\r
777 \r
778                 // close database connection (needs to be closed if we want to include globalfunctions.php)\r
779                 mysql_close();\r
780 \r
781                 $manager = '';\r
782                 include_once($DIR_LIBS . 'globalfunctions.php');\r
783 \r
784                 // 11. install custom skins\r
785                 $aSkinErrors = installCustomSkins($manager);\r
786 \r
787                 // 12. install NP_Ping, if decided\r
788                 if ($weblog_ping == 1) {\r
789                         global $aConfPlugsToInstall;\r
790                         array_push($aConfPlugsToInstall, "NP_Ping");\r
791                 }\r
792 \r
793                 // 13. install custom plugins\r
794                 $aPlugErrors = installCustomPlugs($manager);\r
795         }\r
796 \r
797         // 14. Write config file ourselves (if possible)\r
798         $bConfigWritten = 0;\r
799 \r
800         if (@file_exists('config.php') && is_writable('config.php') && $fp = @fopen('config.php', 'w') ) {\r
801                 $config_data = '<' . '?php' . "\n\n";\r
802                 //$config_data .= "\n"; (extraneous, just added extra \n to previous line\r
803                 $config_data .= "       // mySQL connection information\n";\r
804                 $config_data .= "       \$MYSQL_HOST     = '" . $mysql_host . "';\n";\r
805                 $config_data .= "       \$MYSQL_USER     = '" . $mysql_user . "';\n";\r
806                 $config_data .= "       \$MYSQL_PASSWORD = '" . $mysql_password . "';\n";\r
807                 $config_data .= "       \$MYSQL_DATABASE = '" . $mysql_database . "';\n";\r
808                 $config_data .= "       \$MYSQL_PREFIX   = '" . (($mysql_usePrefix == 1) ? $mysql_prefix : '') . "';\n";\r
809                 $config_data .= "\n";\r
810                 $config_data .= "       // main nucleus directory\n";\r
811                 $config_data .= "       \$DIR_NUCLEUS = '" . $config_adminpath . "';\n";\r
812                 $config_data .= "\n";\r
813                 $config_data .= "       // path to media dir\n";\r
814                 $config_data .= "       \$DIR_MEDIA   = '" . $config_mediapath . "';\n";\r
815                 $config_data .= "\n";\r
816                 $config_data .= "       // extra skin files for imported skins\n";\r
817                 $config_data .= "       \$DIR_SKINS   = '" . $config_skinspath . "';\n";\r
818                 $config_data .= "\n";\r
819                 $config_data .= "       // these dirs are normally sub dirs of the nucleus dir, but \n";\r
820                 $config_data .= "       // you can redefine them if you wish\n";\r
821                 $config_data .= "       \$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n";\r
822                 $config_data .= "       \$DIR_LANG    = \$DIR_NUCLEUS . 'language/';\n";\r
823                 $config_data .= "       \$DIR_LIBS    = \$DIR_NUCLEUS . 'libs/';\n";\r
824                 $config_data .= "\n";\r
825                 $config_data .= "       // include libs\n";\r
826                 $config_data .= "       include(\$DIR_LIBS . 'globalfunctions.php');\n";\r
827                 $config_data .= "       if (!extension_loaded('mbstring')) {\n";\r
828                 $config_data .= "               include(\$DIR_LIBS . 'mb_emulator/mb-emulator.php');\n";\r
829                 $config_data .= "       }\n";\r
830                 $config_data .= "?" . ">";\r
831 \r
832                 $result = @fputs($fp, $config_data, strlen($config_data) );\r
833                 fclose($fp);\r
834 \r
835                 if ($result) {\r
836                         $bConfigWritten = 1;\r
837                 }\r
838         }\r
839 \r
840 ?>\r
841 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
842 <html xmlns="http://www.w3.org/1999/xhtml">\r
843 <head>\r
844         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
845         <title><?php echo _TITLE; ?></title>\r
846         <style>@import url('nucleus/styles/manual.css');</style>\r
847 </head>\r
848 <body>\r
849         <div style='text-align:center'><img src='./nucleus/styles/logo.gif' /></div> <!-- Nucleus logo -->\r
850 \r
851 <?php\r
852         $aAllErrors = array_merge($aSkinErrors, $aPlugErrors);\r
853 \r
854         if (count($aAllErrors) > 0) {\r
855                 echo '<h1>' . _TITLE2 . '</h1>';\r
856                 echo '<ul><li>' . implode('</li><li>', $aAllErrors) . '</li></ul>';\r
857         }\r
858 \r
859         if (!$bConfigWritten) { ?>\r
860                 <h1><?php echo _TITLE3; ?></h1>\r
861 \r
862                 <? echo _TEXT10; ?>\r
863 \r
864                 <pre><code>&lt;?php\r
865         // mySQL connection information\r
866         $MYSQL_HOST     = '<b><?php echo $mysql_host?></b>';\r
867         $MYSQL_USER     = '<b><?php echo $mysql_user?></b>';\r
868         $MYSQL_PASSWORD = '<i><b>xxxxxxxxxxx</b></i>';\r
869         $MYSQL_DATABASE = '<b><?php echo $mysql_database?></b>';\r
870         $MYSQL_PREFIX   = '<b><?php echo ($mysql_usePrefix == 1)?$mysql_prefix:''?></b>';\r
871 \r
872         // main nucleus directory\r
873         $DIR_NUCLEUS = '<b><?php echo $config_adminpath?></b>';\r
874 \r
875         // path to media dir\r
876         $DIR_MEDIA   = '<b><?php echo $config_mediapath?></b>';\r
877 \r
878         // extra skin files for imported skins\r
879         $DIR_SKINS   = '<b><?php echo $config_skinspath?></b>';\r
880 \r
881         // these dirs are normally sub dirs of the nucleus dir, but\r
882         // you can redefine them if you wish\r
883         $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/';\r
884         $DIR_LANG    = $DIR_NUCLEUS . 'language/';\r
885         $DIR_LIBS    = $DIR_NUCLEUS . 'libs/';\r
886 \r
887         // include libs\r
888         include($DIR_LIBS . 'globalfunctions.php');\r
889         if (!extension_loaded('mbstring')) {\r
890                 include($DIR_LIBS . 'mb_emulator/mb-emulator.php');\r
891         }\r
892 ?&gt;</code></pre>\r
893 \r
894         <?php echo _TEXT11; ?>\r
895 \r
896         <div class="note">\r
897         <?php echo _TEXT12; ?>\r
898         </div>\r
899 \r
900 <?php } else { ?>\r
901 \r
902         <h1><?php echo _TITLE4; ?></h1>\r
903 \r
904         <?php echo _TEXT13; ?>\r
905 \r
906 <?php } ?>\r
907 \r
908         <h1><?php echo _TITLE5; ?></h1>\r
909         \r
910         <?php echo _TEXT14; ?>\r
911 \r
912         <ul>\r
913                 <li><?php echo _TEXT14_L1; ?></li>\r
914                 <li><?php echo _TEXT14_L2; ?></li>\r
915         </ul>\r
916 \r
917         <h1><?php echo _HEADER10; ?></h1>\r
918 \r
919         <?php echo _TEXT15; ?>\r
920 \r
921                 <ul>\r
922                 <li><?php echo _TEXT15_L1; ?></li>\r
923                 <li><?php echo _TEXT15_L2; ?></li>\r
924                 </ul>\r
925 \r
926         <?php echo _TEXT15_EX; ?>\r
927 \r
928         <h1><?php echo _HEADER11; ?></h1>\r
929 \r
930         <p><?php echo _TEXT16; ?>\r
931                 <ul>\r
932                         <li><a href="<?php echo $config_adminurl?>"><?php echo _TEXT16_L1; ?></a></li>\r
933                         <li><a href="<?php echo $config_indexurl?>"><?php echo _TEXT16_L2; ?></a></li>\r
934                 </ul>\r
935         </p>\r
936 \r
937 </body>\r
938 </html>\r
939 \r
940 <?php\r
941 }\r
942 \r
943 function installCustomPlugs(&$manager) {\r
944         global $aConfPlugsToInstall, $DIR_LIBS;\r
945 \r
946         $aErrors = array();\r
947 \r
948         if (count($aConfPlugsToInstall) == 0) {\r
949                 return $aErrors;\r
950         }\r
951 \r
952         $res = sql_query('SELECT * FROM ' . sql_table('plugin') );\r
953         $numCurrent = mysql_num_rows($res);\r
954 \r
955         foreach ($aConfPlugsToInstall as $plugName) {\r
956                 // do this before calling getPlugin (in case the plugin id is used there)\r
957                 $query = 'INSERT INTO ' . sql_table('plugin') . ' (porder, pfile) VALUES (' . (++$numCurrent) . ', "' . addslashes($plugName) . '")';\r
958                 sql_query($query);\r
959 \r
960                 // get and install the plugin\r
961                 $manager->clearCachedInfo('installedPlugins');\r
962                 $plugin =& $manager->getPlugin($plugName);\r
963                 $plugin->plugid = $numCurrent;\r
964 \r
965                 if (!$plugin) {\r
966                         sql_query('DELETE FROM ' . sql_table('plugin') . ' WHERE pfile=\'' . addslashes($plugName) . '\'');\r
967                         $numCurrent--;\r
968                         array_push($aErrors, _ERROR22 . $plugName);\r
969                         continue;\r
970                 }\r
971 \r
972                 $plugin->install();\r
973         }\r
974 \r
975         // SYNC PLUGIN EVENT LIST\r
976         sql_query('DELETE FROM ' . sql_table('plugin_event') );\r
977 \r
978         // loop over all installed plugins\r
979         $res = sql_query('SELECT pid, pfile FROM ' . sql_table('plugin') );\r
980 \r
981         while($o = mysql_fetch_object($res) ) {\r
982                 $pid  =  $o->pid;\r
983                 $plug =& $manager->getPlugin($o->pfile);\r
984 \r
985                 if ($plug) {\r
986                         $eventList = $plug->getEventList();\r
987 \r
988                         foreach ($eventList as $eventName) {\r
989                                 sql_query('INSERT INTO ' . sql_table('plugin_event') . ' (pid, event) VALUES (' . $pid . ', \'' . $eventName . '\')');\r
990                         }\r
991                 }\r
992         }\r
993 \r
994         return $aErrors;\r
995 }\r
996 \r
997 function installCustomSkins(&$manager) {\r
998         global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS;\r
999 \r
1000         $aErrors = array();\r
1001 \r
1002         if (count($aConfSkinsToImport) == 0) {\r
1003                 return $aErrors;\r
1004         }\r
1005 \r
1006         // load skinie class\r
1007         include_once($DIR_LIBS . 'skinie.php');\r
1008 \r
1009         $importer = new SKINIMPORT();\r
1010 \r
1011         foreach ($aConfSkinsToImport as $skinName) {\r
1012                 $importer->reset();\r
1013                 $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml';\r
1014 \r
1015                 if (!@file_exists($skinFile) ) {\r
1016                         array_push($aErrors, _ERROR23_1 . $skinFile . ' : ' . _ERROR23_2);\r
1017                         continue;\r
1018                 }\r
1019 \r
1020                 $error = $importer->readFile($skinFile);\r
1021 \r
1022                 if ($error) {\r
1023                         array_push($aErrors, _ERROR24 . $skinName . ' : ' . $error);\r
1024                         continue;\r
1025                 }\r
1026 \r
1027                 $error = $importer->writeToDatabase(1);\r
1028 \r
1029                 if ($error) {\r
1030                         array_push($aErrors, _ERROR24 . $skinName . ' : ' . $error);\r
1031                         continue;\r
1032                 }\r
1033         }\r
1034 \r
1035         return $aErrors;\r
1036 }\r
1037 \r
1038 // give an error if one or more nucleus are not accessible\r
1039 function doCheckFiles() {\r
1040         $missingfiles = array();\r
1041         $files = array(\r
1042                 'install.sql',\r
1043                 'index.php',\r
1044                 'action.php',\r
1045                 'nucleus/index.php',\r
1046                 'nucleus/libs/globalfunctions.php',\r
1047                 'nucleus/libs/ADMIN.php',\r
1048                 'nucleus/libs/BLOG.php',\r
1049                 'nucleus/libs/COMMENT.php',\r
1050                 'nucleus/libs/COMMENTS.php',\r
1051                 'nucleus/libs/ITEM.php',\r
1052                 'nucleus/libs/MEMBER.php',\r
1053                 'nucleus/libs/SKIN.php',\r
1054                 'nucleus/libs/TEMPLATE.php',\r
1055                 'nucleus/libs/MEDIA.php',\r
1056                 'nucleus/libs/ACTIONLOG.php',\r
1057                 'nucleus/media.php'\r
1058         );\r
1059 \r
1060         $count = count($files);\r
1061 \r
1062         for ($i = 0; $i < $count; $i++) {\r
1063                 if (!is_readable($files[$i]) ) {\r
1064                         array_push($missingfiles, _ERROR25_1 . $files[$i] . _ERROR25_2);\r
1065                 }\r
1066         }\r
1067 \r
1068 // The above code replaces several if statements of the form:\r
1069 \r
1070 //      if (!is_readable('install.sql') ) {\r
1071 //              array_push($missingfiles, 'File <b>install.sql</b> is missing or not readable');\r
1072 //      }\r
1073 \r
1074         if (count($missingfiles) > 0) {\r
1075                 showErrorMessages($missingfiles);\r
1076         }\r
1077 }\r
1078 \r
1079 function updateConfig($name, $val) {\r
1080         $name = addslashes($name);\r
1081         $val  = trim(addslashes($val) );\r
1082 \r
1083         $query = 'UPDATE ' . tableName('nucleus_config')\r
1084                    . " SET   value = '$val'"\r
1085                    . " WHERE name  = '$name'";\r
1086 \r
1087         mysql_query($query) or _doError(_ERROR26 . ': ' . mysql_error() );\r
1088         return mysql_insert_id();\r
1089 }\r
1090 \r
1091 function replaceDoubleBackslash($input) {\r
1092         return str_replace('\\', '/', $input);\r
1093 }\r
1094 \r
1095 function endsWithSlash($s) {\r
1096         return (strrpos($s, '/') == strlen($s) - 1);\r
1097 }\r
1098 \r
1099 /**\r
1100  * Checks if email address is valid\r
1101  */\r
1102 function _isValidMailAddress($address) {\r
1103         if (preg_match("/^[a-zA-Z0-9\._-]+@+[A-Za-z0-9\._-]+\.+[A-Za-z]{2,4}$/", $address) ) {\r
1104                 return 1;\r
1105         } else {\r
1106                 return 0;\r
1107         }\r
1108 }\r
1109 \r
1110 // returns true if the given string is a valid shortname\r
1111 // (to check short blog names and nicknames)\r
1112 // logic: starts and ends with a non space, can contain spaces in between\r
1113 //        min 2 chars\r
1114 function _isValidShortName($name) {\r
1115         if (eregi("^[a-z0-9]+$", $name) ) {\r
1116                 return 1;\r
1117         } else {\r
1118                 return 0;\r
1119         }\r
1120 }\r
1121 \r
1122 \r
1123 \r
1124 // returns true if the given string is a valid display name\r
1125 // (to check nicknames)\r
1126 function _isValidDisplayName($name) {\r
1127         if (eregi("^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$", $name) ) {\r
1128                 return 1;\r
1129         } else {\r
1130                 return 0;\r
1131         }\r
1132 }\r
1133 \r
1134 function _doError($msg) {\r
1135         ?>\r
1136 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
1137 <html xmlns="http://www.w3.org/1999/xhtml">\r
1138 <head>\r
1139         <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />\r
1140         <title><?php echo _TITLE; ?></title>\r
1141         <style>@import url('nucleus/styles/manual.css');</style>\r
1142 </head>\r
1143 <body>\r
1144         <div style='text-align:center'><img src='./nucleus/styles/logo.gif' /></div> <!-- Nucleus logo -->\r
1145         <h1><?php echo _ERROR27; ?></h1>\r
1146 \r
1147         <p><?php echo _ERROR28; ?>: "<?php echo $msg?>";</p>\r
1148 \r
1149         <p><a href="install.php" onclick="history.back();"><?php echo _TEXT17; ?></a></p>\r
1150 </body>\r
1151 </html>\r
1152 \r
1153 <?php\r
1154         exit;\r
1155 }\r
1156 \r
1157 function showErrorMessages($errors) {\r
1158         ?>\r
1159 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
1160 <html xmlns="http://www.w3.org/1999/xhtml">\r
1161 <head>\r
1162         <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />\r
1163         <title><?php echo _TITLE; ?></title>\r
1164         <style>@import url('nucleus/styles/manual.css');</style>\r
1165 </head>\r
1166 <body>\r
1167         <div style='text-align:center'><img src='./nucleus/styles/logo.gif' /></div> <!-- Nucleus logo -->\r
1168         <h1><?php echo _ERROR27; ?></h1>\r
1169 \r
1170         <p><?php echo _ERROR29; ?>:</p>\r
1171 \r
1172         <ul>\r
1173 \r
1174 <?php\r
1175         while($msg = array_shift($errors) ) {\r
1176                 echo '<li>' . $msg . '</li>';\r
1177         }\r
1178 ?>\r
1179 \r
1180         </ul>\r
1181 \r
1182         <p><a href="install.php" onclick="history.back();return false;"><?php echo _TEXT17; ?></a></p>\r
1183 </body>\r
1184 </html>\r
1185 \r
1186 <?php\r
1187         exit;\r
1188 }\r
1189 \r
1190 /* for the non-php systems that decide to show the contents:\r
1191 ?></div><?php   */\r
1192 \r
1193 ?>