changed git call from https to git readonly
[atutor.git] / mods / wiki / fragments / ini.php
1 <?php
2 /*
3    This plugin parses the "ewiki.ini" file and sets ewiki variables
4    and constants accordingly, then loads plugins. Such a configuration
5    file could be prepared using the SetupWizard.
6
7    Note: PHPs parse_ini_file() is insufficient for our .ini file,
8    because it lacks recognizing repeated entry names.
9 */
10
11
12 #-- get file
13 error_reporting(error_reporting() & 0xFFFE);
14 if ($ini = ewiki_parse_ini_file("ewiki.ini")) {
15
16    #-- init database
17    if ($v = $ini["db"]["init"][0]) {
18       foreach (split('&&|;', $v) as $v) {
19          $i = strtok(preg_replace("/[\"\s\']/", "", $v), "(");
20          $v = explode(",", strtok(")"));
21          if ($v && $i) {
22             call_user_func_array($i, $v); // auto function_exists() check
23          }
24       }
25    }
26
27    #-- set options
28    foreach ($ini["config"] as $i=>$v) {
29       $v = $v[0];
30       if ($i[0] == "\$") {
31          $i = preg_replace("/[\s\"\'\$\]]/", "", $i);
32          $i = explode("[", $i);
33          switch (count($i) + (strlen($i[count($i)-1]) ? 0 : 10)) {
34             case 1: $GLOBALS[$i[0]] = $v; break;
35             case 2: $GLOBALS[$i[0]][$i[1]] = $v; break;
36            case 12: $GLOBALS[$i[0]][] = $v; break;
37             case 3: $GLOBALS[$i[0]][$i[1]][$i[2]] = $v; break;
38            case 13: $GLOBALS[$i[0]][$i[1]][] = $v; break;
39             case 4: $GLOBALS[$i[0]][$i[1]][$i[2]][$i[3]] = $v; break;
40            case 14: $GLOBALS[$i[0]][$i[1]][$i[2]][] = $v;
41          }
42       }
43       else {
44          @define($i, $v);
45       }
46    }
47
48    #-- load plugins
49    foreach ($ini["plugins"]["load"] as $v) {
50       include_once($v);
51    }
52    $i = $v = $ini = NULL;
53 }
54
55 #-- add core scripts
56 include_once("ewiki.php");
57
58
59
60 #-- load and decipher .ini files
61 function ewiki_parse_ini_file($fn) {
62    return ewiki_parse_ini_str(@implode("",file($fn)));
63 }
64 function ewiki_parse_ini_str($s)
65 {
66    $r = array();
67    $sect = "global";
68    foreach (explode("\n", $s) as $line) {
69       $line = trim($line);
70       if ($line[0] == "[") {
71          $sect = trim(strtok(substr($line, 1), "]"));
72       }
73       elseif (($line[0] == ";") || ($line[0] == "#")) {
74       }
75       elseif (strpos($line, "=")) {
76          $opt = trim(strtolower(strtok($line, "=")));
77          $val = trim(strtok("\r\n"));
78          $r[$sect][$opt][] = $val;
79       }
80    }
81    return($r);
82 }
83
84
85 ?>