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