OSDN Git Service

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