OSDN Git Service

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