xref: /dokuwiki/install.php (revision 3545b2e00f01dc8e3b59ba4b2fc937f296b43bb5)
15cfb8815Schris<?php
25cfb8815Schris/**
35cfb8815Schris *  Dokuwiki installation assistance
45cfb8815Schris *
55cfb8815Schris *  @author      Chris Smith <chris@jalakai.co.uk>
65cfb8815Schris */
75cfb8815Schris
85cfb8815Schrisif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__)).'/');
95cfb8815Schrisif(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
105cfb8815Schrisif(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/');
115cfb8815Schris
12*3545b2e0Schris// check for error reporting override or set error reporting to sane values
13*3545b2e0Schrisif (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE); }
14*3545b2e0Schriselse { error_reporting(DOKU_E_LEVEL); }
15*3545b2e0Schris
1647248316SAndreas Gohr// kill magic quotes
1747248316SAndreas Gohrif (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
1847248316SAndreas Gohr    if (!empty($_GET))    remove_magic_quotes($_GET);
1947248316SAndreas Gohr    if (!empty($_POST))   remove_magic_quotes($_POST);
2047248316SAndreas Gohr    if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE);
2147248316SAndreas Gohr    if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST);
2247248316SAndreas Gohr    @ini_set('magic_quotes_gpc', 0);
2347248316SAndreas Gohr    define('MAGIC_QUOTES_STRIPPED',1);
2447248316SAndreas Gohr}
2547248316SAndreas Gohr@set_magic_quotes_runtime(0);
2647248316SAndreas Gohr@ini_set('magic_quotes_sybase',0);
275cfb8815Schris
2847248316SAndreas Gohr// language strings
2947248316SAndreas Gohrrequire_once(DOKU_INC.'inc/lang/en/lang.php');
3047248316SAndreas Gohr$LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']);
3147248316SAndreas Gohrif(!$LC) $LC = 'en';
3247248316SAndreas Gohrif($LC && $LC != 'en' ) {
3347248316SAndreas Gohr    require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php');
3447248316SAndreas Gohr}
3547248316SAndreas Gohr
3647248316SAndreas Gohr// initialise variables ...
3747248316SAndreas Gohr$error = array();
3847248316SAndreas Gohr
3947248316SAndreas Gohr$dokuwiki_hash = array(
4047248316SAndreas Gohr    '2005-09-22' => 'e33223e957b0b0a130d0520db08f8fb7',
4147248316SAndreas Gohr    '2006-03-05' => '51295727f79ab9af309a2fd9e0b61acc',
4247248316SAndreas Gohr    '2006-03-09' => '51295727f79ab9af309a2fd9e0b61acc',
4347248316SAndreas Gohr    'devel'      => '732131839d559198b985e183eefe9a63',
4447248316SAndreas Gohr);
4547248316SAndreas Gohr
4647248316SAndreas Gohr
4747248316SAndreas Gohr
4847248316SAndreas Gohr// begin output
4947248316SAndreas Gohrheader('Content-Type: text/html; charset=utf-8');
5047248316SAndreas Gohr?>
5147248316SAndreas Gohr<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5247248316SAndreas Gohr "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5347248316SAndreas Gohr<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $LC?>"
5447248316SAndreas Gohr lang="<?php echo $LC?>" dir="<?php echo $lang['direction']?>">
5547248316SAndreas Gohr<head>
5647248316SAndreas Gohr    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5747248316SAndreas Gohr    <title>DokuWiki Installer</title>
5847248316SAndreas Gohr    <style type="text/css">
5947248316SAndreas Gohr        body { width: 90%; margin: 0 auto; font: 84% Verdana, Helvetica, Arial, sans-serif; }
6047248316SAndreas Gohr        img { border: none }
6147248316SAndreas Gohr        br.cl { clear:both; }
6247248316SAndreas Gohr        code { font-size: 110%; color: #008000; }
6347248316SAndreas Gohr        fieldset { border: none }
6447248316SAndreas Gohr        label { display: block;}
6547248316SAndreas Gohr        input.text { width: 30em; margin: 0 0.5em; }
6647248316SAndreas Gohr    </style>
6747248316SAndreas Gohr    <script type="text/javascript" language="javascript">
6847248316SAndreas Gohr        function acltoggle(){
6947248316SAndreas Gohr            var cb = document.getElementById('acl');
7047248316SAndreas Gohr            var fs = document.getElementById('acldep');
7147248316SAndreas Gohr            if(!cb || !fs) return;
7247248316SAndreas Gohr            if(cb.checked){
7347248316SAndreas Gohr                fs.style.display = '';
7447248316SAndreas Gohr            }else{
7547248316SAndreas Gohr                fs.style.display = 'none';
7647248316SAndreas Gohr            }
7747248316SAndreas Gohr        }
7847248316SAndreas Gohr        window.onload = function(){
7947248316SAndreas Gohr            acltoggle();
8047248316SAndreas Gohr            var cb = document.getElementById('acl');
8147248316SAndreas Gohr            if(cb) cb.onchange = acltoggle;
8247248316SAndreas Gohr        };
8347248316SAndreas Gohr    </script>
8447248316SAndreas Gohr</head>
8547248316SAndreas Gohr<body style="">
8647248316SAndreas Gohr    <h1 style="float:left">
8747248316SAndreas Gohr        <img src="http://wiki.splitbrain.org/_media/wiki:dokuwiki-64.png"
8847248316SAndreas Gohr             style="vertical-align: middle;" alt="" />
8947248316SAndreas Gohr        <?php echo $lang['i_installer']?>
9047248316SAndreas Gohr    </h1>
9147248316SAndreas Gohr    <div style="float:right; margin: 1em;">
9247248316SAndreas Gohr        <?php langsel()?>
9347248316SAndreas Gohr    </div>
9447248316SAndreas Gohr    <br class="cl" />
9547248316SAndreas Gohr
9647248316SAndreas Gohr    <div style="float: right; width: 34%;">
9747248316SAndreas Gohr        <?php
9847248316SAndreas Gohr            if(@file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){
9947248316SAndreas Gohr                include(DOKU_INC.'inc/lang/'.$LC.'/install.html');
10047248316SAndreas Gohr            }else{
10147248316SAndreas Gohr                include(DOKU_INC.'inc/lang/en/install.html');
10247248316SAndreas Gohr            }
10347248316SAndreas Gohr        ?>
10447248316SAndreas Gohr    </div>
10547248316SAndreas Gohr
10647248316SAndreas Gohr    <div style="float: left; width: 58%;">
10747248316SAndreas Gohr        <?php
10847248316SAndreas Gohr            if(! (check_functions() && check_permissions()) ){
10947248316SAndreas Gohr                echo '<p>'.$lang['i_problems'].'</p>';
11047248316SAndreas Gohr                print_errors();
11147248316SAndreas Gohr            }elseif(!check_configs()){
11247248316SAndreas Gohr                echo '<p>'.$lang['i_modified'].'</p>';
11347248316SAndreas Gohr                print_errors();
11447248316SAndreas Gohr            }elseif($_REQUEST['submit']){
11547248316SAndreas Gohr                if(!check_data($_REQUEST['d'])){
11647248316SAndreas Gohr                    print_errors();
11747248316SAndreas Gohr                    print_form($_REQUEST['d']);
11847248316SAndreas Gohr                }elseif(!store_data($_REQUEST['d'])){
11947248316SAndreas Gohr                    echo '<p>'.$lang['i_failure'].'</p>';
12047248316SAndreas Gohr                    print_errors();
12147248316SAndreas Gohr                }else{
12247248316SAndreas Gohr                    echo '<p>'.$lang['i_success'].'</p>';
12347248316SAndreas Gohr                }
12447248316SAndreas Gohr            }else{
12547248316SAndreas Gohr                print_form($_REQUEST['d']);
12647248316SAndreas Gohr            }
12747248316SAndreas Gohr        ?>
12847248316SAndreas Gohr    </div>
12947248316SAndreas Gohr
13047248316SAndreas Gohr<div style="clear: both">
13147248316SAndreas Gohr  <a href="http://wiki.splitbrain.org/wiki:dokuwiki"><img src="lib/tpl/default/images/button-dw.png" alt="driven by DokuWiki" /></a>
13247248316SAndreas Gohr  <a href="http://www.php.net"><img src="lib/tpl/default/images/button-php.gif" alt="powered by PHP" /></a>
13347248316SAndreas Gohr</div>
13447248316SAndreas Gohr</body>
13547248316SAndreas Gohr</html>
13647248316SAndreas Gohr<?php
13747248316SAndreas Gohr
13847248316SAndreas Gohr/**
13947248316SAndreas Gohr * Print the input form
14047248316SAndreas Gohr */
14147248316SAndreas Gohrfunction print_form($d){
14247248316SAndreas Gohr    global $lang;
14347248316SAndreas Gohr    global $LC;
14447248316SAndreas Gohr
14547248316SAndreas Gohr    if(!is_array($d)) $d = array();
14647248316SAndreas Gohr    $d = array_map('htmlspecialchars',$d);
14747248316SAndreas Gohr
14847248316SAndreas Gohr    if(!isset($d['acl'])) $d['acl']=1;
14947248316SAndreas Gohr
15047248316SAndreas Gohr    ?>
15147248316SAndreas Gohr    <form action="" method="post">
15247248316SAndreas Gohr    <input type="hidden" name="l" value="<?php echo $LC ?>" />
15347248316SAndreas Gohr    <fieldset>
15447248316SAndreas Gohr        <label for="title"><?php echo $lang['i_wikiname']?>
15547248316SAndreas Gohr        <input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;" />
15647248316SAndreas Gohr        </label>
15747248316SAndreas Gohr
15847248316SAndreas Gohr        <fieldset style="margin-top: 1em;">
15947248316SAndreas Gohr            <label for="acl">
16047248316SAndreas Gohr            <input type="checkbox" name="d[acl]" id="acl" <?php echo(($d['acl'] ? 'checked="checked"' : ''));?> />
16147248316SAndreas Gohr            <?php echo $lang['i_enableacl']?></label>
16247248316SAndreas Gohr
16347248316SAndreas Gohr            <fieldset id="acldep">
16447248316SAndreas Gohr                <label for="superuser"><?php echo $lang['i_superuser']?></label>
16547248316SAndreas Gohr                <input class="text" type="text" name="d[superuser]" id="superuser" value="<?php echo $d['superuser'] ?>" />
16647248316SAndreas Gohr
16747248316SAndreas Gohr                <label for="fullname"><?php echo $lang['fullname']?></label>
16847248316SAndreas Gohr                <input class="text" type="text" name="d[fullname]" id="fullname" value="<?php echo $d['fullname'] ?>" />
16947248316SAndreas Gohr
17047248316SAndreas Gohr                <label for="email"><?php echo $lang['email']?></label>
17147248316SAndreas Gohr                <input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>" />
17247248316SAndreas Gohr
17347248316SAndreas Gohr                <label for="password"><?php echo $lang['pass']?></label>
17447248316SAndreas Gohr                <input class="text" type="password" name="d[password]" id="password" />
17547248316SAndreas Gohr
17647248316SAndreas Gohr                <label for="confirm"><?php echo $lang['passchk']?></label>
17747248316SAndreas Gohr                <input class="text" type="password" name="d[confirm]" id="confirm" />
17847248316SAndreas Gohr            </fieldset>
17947248316SAndreas Gohr        </fieldset>
18047248316SAndreas Gohr
18147248316SAndreas Gohr    </fieldset>
18247248316SAndreas Gohr    <fieldset id="process">
18347248316SAndreas Gohr        <input class="button" type="submit" name="submit" value="<?php echo $lang['btn_save']?>" />
18447248316SAndreas Gohr    </fieldset>
18547248316SAndreas Gohr    </form>
18647248316SAndreas Gohr    <?php
18747248316SAndreas Gohr}
18847248316SAndreas Gohr
18947248316SAndreas Gohr/**
19047248316SAndreas Gohr * Check validity of data
19147248316SAndreas Gohr *
19247248316SAndreas Gohr * @author Andreas Gohr
19347248316SAndreas Gohr */
19447248316SAndreas Gohrfunction check_data($d){
19547248316SAndreas Gohr    global $lang;
19647248316SAndreas Gohr    global $error;
19747248316SAndreas Gohr
19847248316SAndreas Gohr    $ok = true;
19947248316SAndreas Gohr
20047248316SAndreas Gohr    // check input
20147248316SAndreas Gohr    if(empty($d['title'])){
20247248316SAndreas Gohr        $error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
20347248316SAndreas Gohr        $ok      = false;
20447248316SAndreas Gohr    }
20547248316SAndreas Gohr    if($d['acl']){
20647248316SAndreas Gohr        if(!preg_match('/^[a-z1-9_]+$/',$d['superuser'])){
20747248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
20847248316SAndreas Gohr            $ok      = false;
20947248316SAndreas Gohr        }
21047248316SAndreas Gohr        if(empty($d['password'])){
21147248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['pass']);
21247248316SAndreas Gohr            $ok      = false;
21347248316SAndreas Gohr        }
21447248316SAndreas Gohr        if($d['confirm'] != $d['password']){
21547248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['passchk']);
21647248316SAndreas Gohr            $ok      = false;
21747248316SAndreas Gohr        }
21847248316SAndreas Gohr        if(empty($d['fullname']) || strstr($d['fullname'],':')){
21947248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['fullname']);
22047248316SAndreas Gohr            $ok      = false;
22147248316SAndreas Gohr        }
22247248316SAndreas Gohr        if(empty($d['email']) || strstr($d['fullname'],':')){
22347248316SAndreas Gohr            $error[] = sprintf($lang['i_badval'],$lang['email']);
22447248316SAndreas Gohr            $ok      = false;
22547248316SAndreas Gohr        }
22647248316SAndreas Gohr    }
22747248316SAndreas Gohr    return $ok;
22847248316SAndreas Gohr}
22947248316SAndreas Gohr
23047248316SAndreas Gohr/**
23147248316SAndreas Gohr * Writes the data to the config files
23247248316SAndreas Gohr *
23347248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
23447248316SAndreas Gohr */
23547248316SAndreas Gohrfunction store_data($d){
23647248316SAndreas Gohr    $ok = true;
23747248316SAndreas Gohr
23847248316SAndreas Gohr    // create changes.log
23947248316SAndreas Gohr    if (!@file_exists(DOKU_INC.'data/changes.log')){
24047248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_INC.'data/changes.log','');
24147248316SAndreas Gohr    }
24247248316SAndreas Gohr
24347248316SAndreas Gohr    // create local.php
24447248316SAndreas Gohr    $now    = date('r');
24547248316SAndreas Gohr    $output = <<<EOT
24647248316SAndreas Gohr<?php
24747248316SAndreas Gohr/**
24847248316SAndreas Gohr * Dokuwiki's Main Configuration File - Local Settings
24947248316SAndreas Gohr * Auto-generated by install script
25047248316SAndreas Gohr * Date: $now
25147248316SAndreas Gohr */
25247248316SAndreas Gohr
25347248316SAndreas GohrEOT;
25447248316SAndreas Gohr    $output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
25547248316SAndreas Gohr    if($d['acl']){
25647248316SAndreas Gohr        $output .= '$conf[\'useacl\'] = 1'.";\n";
25747248316SAndreas Gohr        $output .= '$conf[\'superuser\'] = \''.$d['superuser']."';\n";
25847248316SAndreas Gohr    }
25947248316SAndreas Gohr    $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
26047248316SAndreas Gohr
26147248316SAndreas Gohr
26247248316SAndreas Gohr    if ($d['acl']) {
26347248316SAndreas Gohr        // create users.auth.php
26447248316SAndreas Gohr        // --- user:MD5password:Real Name:email:groups,comma,seperated
26547248316SAndreas Gohr        $output = join(":",array($d['superuser'], md5($d['password']), $d['fullname'], $d['email'], 'users'));
26647248316SAndreas Gohr        $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n";
26747248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output);
26847248316SAndreas Gohr
26947248316SAndreas Gohr        // create acl.auth.php
27047248316SAndreas Gohr        $output = @file_get_contents(DOKU_CONF.'acl.auth.php.dist');
27147248316SAndreas Gohr        $ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output);
27247248316SAndreas Gohr    }
27347248316SAndreas Gohr    return $ok;
27447248316SAndreas Gohr}
27547248316SAndreas Gohr
27647248316SAndreas Gohr/**
27747248316SAndreas Gohr * Write the given content to a file
27847248316SAndreas Gohr *
27947248316SAndreas Gohr * @author  Chris Smith <chris@jalakai.co.uk>
28047248316SAndreas Gohr */
28147248316SAndreas Gohrfunction fileWrite($filename, $data) {
28247248316SAndreas Gohr    global $error;
28347248316SAndreas Gohr    global $lang;
28447248316SAndreas Gohr
28547248316SAndreas Gohr    if (($fp = @fopen($filename, 'wb')) === false) {
28647248316SAndreas Gohr        $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
28747248316SAndreas Gohr        $error[]  = sprintf($lang['i_writeerr'],$filename);
28847248316SAndreas Gohr        return false;
28947248316SAndreas Gohr    }
29047248316SAndreas Gohr
29147248316SAndreas Gohr    if (!empty($data)) { fwrite($fp, $data);  }
29247248316SAndreas Gohr    fclose($fp);
29347248316SAndreas Gohr    return true;
29447248316SAndreas Gohr}
29547248316SAndreas Gohr
29647248316SAndreas Gohr
29747248316SAndreas Gohr/**
29847248316SAndreas Gohr * check installation dependent local config files and tests for a known
29947248316SAndreas Gohr * unmodified main config file
30047248316SAndreas Gohr *
30147248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
30247248316SAndreas Gohr */
30347248316SAndreas Gohrfunction check_configs(){
30447248316SAndreas Gohr    global $error;
30547248316SAndreas Gohr    global $lang;
30647248316SAndreas Gohr    global $dokuwiki_hash;
30747248316SAndreas Gohr
30847248316SAndreas Gohr    $ok = true;
30947248316SAndreas Gohr
3105cfb8815Schris    $config_files = array(
3115cfb8815Schris        'local' => DOKU_LOCAL.'local.php',
3125cfb8815Schris        'users' => DOKU_LOCAL.'users.auth.php',
3135cfb8815Schris        'auth'  => DOKU_LOCAL.'acl.auth.php'
3145cfb8815Schris    );
3155cfb8815Schris
3165cfb8815Schris
3175cfb8815Schris    // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
31847248316SAndreas Gohr    $installation_hash = md5(@file_get_contents(DOKU_CONF.'dokuwiki.php'));
3195cfb8815Schris    if (!in_array($installation_hash, $dokuwiki_hash)) {
32047248316SAndreas Gohr        $error[] = sprintf($lang['i_badhash'],$installation_hash);
32147248316SAndreas Gohr        $ok = false;
3225cfb8815Schris    }
3235cfb8815Schris
32447248316SAndreas Gohr    // configs shouldn't exist
32547248316SAndreas Gohr    foreach ($config_files as $file) {
32647248316SAndreas Gohr        if (@file_exists($file)) {
32747248316SAndreas Gohr            $file    = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
32847248316SAndreas Gohr            $error[] = sprintf($lang['i_confexists'],$file);
32947248316SAndreas Gohr            $ok      = false;
33047248316SAndreas Gohr        }
33147248316SAndreas Gohr    }
33247248316SAndreas Gohr    return $ok;
33347248316SAndreas Gohr}
33447248316SAndreas Gohr
33547248316SAndreas Gohr
33647248316SAndreas Gohr/**
33747248316SAndreas Gohr * Check other installation dir/file permission requirements
33847248316SAndreas Gohr *
33947248316SAndreas Gohr * @author      Chris Smith <chris@jalakai.co.uk>
34047248316SAndreas Gohr */
34147248316SAndreas Gohrfunction check_permissions(){
34247248316SAndreas Gohr    global $error;
34347248316SAndreas Gohr    global $lang;
34447248316SAndreas Gohr
34547248316SAndreas Gohr    $dirs = array(
34647248316SAndreas Gohr        'conf'      => DOKU_LOCAL,
34747248316SAndreas Gohr        'data'      => DOKU_INC.'data',
34847248316SAndreas Gohr        'pages'     => DOKU_INC.'data/pages',
34947248316SAndreas Gohr        'attic'     => DOKU_INC.'data/attic',
35047248316SAndreas Gohr        'media'     => DOKU_INC.'data/media',
35147248316SAndreas Gohr        'meta'      => DOKU_INC.'data/meta',
35247248316SAndreas Gohr        'cache'     => DOKU_INC.'data/cache',
35347248316SAndreas Gohr        'locks'     => DOKU_INC.'data/locks',
35447248316SAndreas Gohr    );
35547248316SAndreas Gohr
35647248316SAndreas Gohr    $ok = true;
35747248316SAndreas Gohr    foreach($dirs as $dir){
35847248316SAndreas Gohr        if(!@file_exists("$dir/.") || !@is_writable($dir)){
35947248316SAndreas Gohr            $dir     = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $dir);
36047248316SAndreas Gohr            $error[] = sprintf($lang['i_permfail'],$dir);
36147248316SAndreas Gohr            $ok      = false;
36247248316SAndreas Gohr        }
36347248316SAndreas Gohr    }
36447248316SAndreas Gohr    return $ok;
36547248316SAndreas Gohr}
36647248316SAndreas Gohr
36747248316SAndreas Gohr/**
36847248316SAndreas Gohr * Check the availability of functions used in DokuWiki
36947248316SAndreas Gohr *
37047248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
37147248316SAndreas Gohr */
37247248316SAndreas Gohrfunction check_functions(){
37347248316SAndreas Gohr    global $error;
37447248316SAndreas Gohr    global $lang;
37547248316SAndreas Gohr    $funcs = explode(' ','addslashes basename call_user_func chmod copy fgets '.
37647248316SAndreas Gohr                         'file file_exists fseek flush filesize ftell fopen '.
37747248316SAndreas Gohr                         'glob header ignore_user_abort ini_get mail mkdir '.
37847248316SAndreas Gohr                         'ob_start opendir parse_ini_file readfile realpath '.
37947248316SAndreas Gohr                         'rename rmdir serialize session_start unlink usleep');
38047248316SAndreas Gohr
38147248316SAndreas Gohr    $ok = true;
38247248316SAndreas Gohr    foreach($funcs as $func){
38347248316SAndreas Gohr        if(!function_exists($func)){
38447248316SAndreas Gohr            $error[] = sprintf($lang['i_funcna'],$func);
38547248316SAndreas Gohr            $ok = false;
38647248316SAndreas Gohr        }
38747248316SAndreas Gohr    }
38847248316SAndreas Gohr    return $ok;
38947248316SAndreas Gohr}
39047248316SAndreas Gohr
39147248316SAndreas Gohr/**
39247248316SAndreas Gohr * Print language selection
39347248316SAndreas Gohr *
39447248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
39547248316SAndreas Gohr */
39647248316SAndreas Gohrfunction langsel(){
39747248316SAndreas Gohr    global $lang;
39847248316SAndreas Gohr    global $LC;
39947248316SAndreas Gohr
40047248316SAndreas Gohr    $dir = DOKU_INC.'inc/lang';
40147248316SAndreas Gohr    $dh  = opendir($dir);
40247248316SAndreas Gohr    if(!$dh) return;
40347248316SAndreas Gohr
40447248316SAndreas Gohr    $langs = array();
40547248316SAndreas Gohr    while (($file = readdir($dh)) !== false) {
40647248316SAndreas Gohr        if(preg_match('/^[\._]/',$file)) continue;
40747248316SAndreas Gohr        if(is_dir($dir.'/'.$file) && @file_exists($dir.'/'.$file.'/lang.php')){
40847248316SAndreas Gohr            $langs[] = $file;
40947248316SAndreas Gohr        }
41047248316SAndreas Gohr    }
41147248316SAndreas Gohr    closedir($dh);
41247248316SAndreas Gohr    sort($langs);
41347248316SAndreas Gohr
41447248316SAndreas Gohr
41547248316SAndreas Gohr    echo '<form action="">';
41647248316SAndreas Gohr    echo $lang['i_chooselang'];
41747248316SAndreas Gohr    echo ': <select name="l" onchange="submit()">';
41847248316SAndreas Gohr    foreach($langs as $l){
41947248316SAndreas Gohr        $sel = ($l == $LC) ? 'selected="selected"' : '';
42047248316SAndreas Gohr        echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
42147248316SAndreas Gohr    }
42247248316SAndreas Gohr    echo '</select>';
42347248316SAndreas Gohr    echo '<input type="submit" value="'.$lang['btn_update'].'" />';
42447248316SAndreas Gohr    echo '</form>';
42547248316SAndreas Gohr}
42647248316SAndreas Gohr
42747248316SAndreas Gohr/**
42847248316SAndreas Gohr * Print gloabl error array
42947248316SAndreas Gohr *
43047248316SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
43147248316SAndreas Gohr */
43247248316SAndreas Gohrfunction print_errors(){
43347248316SAndreas Gohr    global $error;
43447248316SAndreas Gohr    echo '<ul>';
43547248316SAndreas Gohr    foreach ($error as $err){
43647248316SAndreas Gohr        echo "<li>$err</li>";
43747248316SAndreas Gohr    }
43847248316SAndreas Gohr    echo '</ul>';
43947248316SAndreas Gohr}
4405cfb8815Schris
4415cfb8815Schris/**
4425cfb8815Schris * remove magic quotes recursivly
4435cfb8815Schris *
4445cfb8815Schris * @author Andreas Gohr <andi@splitbrain.org>
4455cfb8815Schris */
4465cfb8815Schrisfunction remove_magic_quotes(&$array) {
4475cfb8815Schris  foreach (array_keys($array) as $key) {
4485cfb8815Schris    if (is_array($array[$key])) {
4495cfb8815Schris      remove_magic_quotes($array[$key]);
4505cfb8815Schris    }else {
4515cfb8815Schris      $array[$key] = stripslashes($array[$key]);
4525cfb8815Schris    }
4535cfb8815Schris  }
4545cfb8815Schris}
4555cfb8815Schris
456