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