OSDN Git Service

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