OSDN Git Service

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