OSDN Git Service

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