OSDN Git Service

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