OSDN Git Service

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