1 | 1 | simandl | <?php |
2 | | | // WebSVN - Subversion repository viewing via the web using PHP |
3 | | | // Copyright (C) 2004-2006 Tim Armes |
4 | | | // |
5 | | | // This program is free software; you can redistribute it and/or modify |
6 | | | // it under the terms of the GNU General Public License as published by |
7 | | | // the Free Software Foundation; either version 2 of the License, or |
8 | | | // (at your option) any later version. |
9 | | | // |
10 | | | // This program is distributed in the hope that it will be useful, |
11 | | | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | | // GNU General Public License for more details. |
14 | | | // |
15 | | | // You should have received a copy of the GNU General Public License |
16 | | | // along with this program; if not, write to the Free Software |
17 | | | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | | | // |
19 | | | // -- |
20 | | | // |
21 | | | // accessfile.php |
22 | | | // |
23 | | | // Read a .ini style file |
24 | | | |
25 | | | class IniFile { |
26 | | | var $sections; |
27 | | | |
28 | | | // {{{ __construct |
29 | | | |
30 | | | function IniFile() { |
31 | | | $this->sections = array(); |
32 | | | } |
33 | | | |
34 | | | // }}} |
35 | | | |
36 | | | // {{{ readIniFile |
37 | | | |
38 | | | function readIniFile($name) { |
39 | | | $contents = file($name); |
40 | | | $cursection = ''; |
41 | | | $first = true; |
42 | | | |
43 | | | foreach ($contents as $str) { |
44 | | | $str = trim($str); |
45 | | | if (empty($str)) { |
46 | | | continue; |
47 | | | } |
48 | | | |
49 | | | if ($str{0} == '#' or $str{0} == "'") { |
50 | | | continue; |
51 | | | } |
52 | | | |
53 | | | if ($str{0} == '[') { |
54 | | | $cursection = strtolower(substr($str, 1, strlen($str) - 2)); |
55 | | | if (!($str{strlen($str) - 2} == '/' or $str == '[groups]')) { |
56 | | | $cursection .= '/'; |
57 | | | } |
58 | | | $first = true; |
59 | | | } else if (!empty($cursection)) { |
60 | | | if ($first === true) { |
61 | | | $this->sections[$cursection] = array(); |
62 | | | } |
63 | | | list($key, $val) = split('=', $str); |
64 | | | $this->sections[$cursection][strtolower(trim($key))] = strtolower(trim($val)); |
65 | | | $first = false; |
66 | | | } |
67 | | | } |
68 | | | } |
69 | | | |
70 | | | // }}} |
71 | | | |
72 | | | // {{{ getSections |
73 | | | |
74 | | | function &getSections() { |
75 | | | return $this->sections; |
76 | | | } |
77 | | | |
78 | | | // }}} |
79 | | | |
80 | | | // {{{ getValues |
81 | | | |
82 | | | function getValues($section) { |
83 | | | return @$this->sections[strtolower($section)]; |
84 | | | } |
85 | | | |
86 | | | // }}} |
87 | | | |
88 | | | // {{{ getValue |
89 | | | |
90 | | | function getValue($section, $key) { |
91 | | | return @$this->sections[strtolower($section)][strtolower($key)]; |
92 | | | } |
93 | | | |
94 | | | // }}} |
95 | | | } |