| 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 | 3 | simandl | // does not use parse_ini_file function since php 5.3 does not support comment lines starting with # |
| 40 | 1 | simandl | $contents = file($name); |
| 41 | | | $cursection = ''; |
| 42 | 3 | simandl | $curkey = ''; |
| 43 | 1 | simandl | $first = true; |
| 44 | | | |
| 45 | 3 | simandl | foreach ($contents as $line) { |
| 46 | | | $line = rtrim($line); |
| 47 | | | $str = ltrim($line); |
| 48 | 1 | simandl | if (empty($str)) { |
| 49 | | | continue; |
| 50 | | | } |
| 51 | | | |
| 52 | 3 | simandl | // @todo remove ' in the next major release to be in line with the svn book |
| 53 | 1 | simandl | if ($str{0} == '#' or $str{0} == "'") { |
| 54 | | | continue; |
| 55 | | | } |
| 56 | | | |
| 57 | 3 | simandl | if ($str != $line && !empty($cursection) && !empty($curkey)) { |
| 58 | | | // line starts with whitespace |
| 59 | | | $this->sections[$cursection][$curkey] .= strtolower($str); |
| 60 | | | } else if ($str{0} == '[') { |
| 61 | 1 | simandl | $cursection = strtolower(substr($str, 1, strlen($str) - 2)); |
| 62 | 3 | simandl | if (!($str{strlen($str) - 2} == '/' || $str == '[aliases]' || $str == '[groups]')) { |
| 63 | 1 | simandl | $cursection .= '/'; |
| 64 | | | } |
| 65 | | | $first = true; |
| 66 | | | } else if (!empty($cursection)) { |
| 67 | 3 | simandl | if ($first) { |
| 68 | | | if (($cursection != 'aliases' && $cursection != 'groups') || !isset($this->sections[$cursection])) { |
| 69 | | | $this->sections[$cursection] = array(); |
| 70 | | | } |
| 71 | 1 | simandl | } |
| 72 | 3 | simandl | list($key, $val) = explode('=', $str, 2); |
| 73 | | | $key = strtolower(trim($key)); |
| 74 | | | $curkey = $key; |
| 75 | | | $this->sections[$cursection][$key] = strtolower(trim($val)); |
| 76 | 1 | simandl | $first = false; |
| 77 | | | } |
| 78 | | | } |
| 79 | | | } |
| 80 | | | |
| 81 | | | // }}} |
| 82 | | | |
| 83 | | | // {{{ getSections |
| 84 | | | |
| 85 | | | function &getSections() { |
| 86 | | | return $this->sections; |
| 87 | | | } |
| 88 | | | |
| 89 | | | // }}} |
| 90 | | | |
| 91 | | | // {{{ getValues |
| 92 | | | |
| 93 | | | function getValues($section) { |
| 94 | | | return @$this->sections[strtolower($section)]; |
| 95 | | | } |
| 96 | | | |
| 97 | | | // }}} |
| 98 | | | |
| 99 | | | // {{{ getValue |
| 100 | | | |
| 101 | | | function getValue($section, $key) { |
| 102 | | | return @$this->sections[strtolower($section)][strtolower($key)]; |
| 103 | | | } |
| 104 | | | |
| 105 | | | // }}} |
| 106 | | | } |