OSDN Git Service

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