OSDN Git Service

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