File: accessfile.php

package info (click to toggle)
websvn 2.3.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,392 kB
  • ctags: 3,248
  • sloc: php: 48,216; sh: 166; makefile: 49
file content (103 lines) | stat: -rw-r--r-- 2,577 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
// WebSVN - Subversion repository viewing via the web using PHP
// Copyright (C) 2004-2006 Tim Armes
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA	02111-1307	USA
//
// --
//
// accessfile.php
//
// Read a .ini style file

class IniFile {
	var $sections;

	// {{{ __construct

	function IniFile() {
		$this->sections = array();
	}

	// }}}

	// {{{ readIniFile

	function readIniFile($name) {
		// does not use parse_ini_file function since php 5.3 does not support comment lines starting with #
		$contents = file($name);
		$cursection = '';
		$curkey = '';
		$first = true;

		foreach ($contents as $line) {
			$line = rtrim($line);
			$str = ltrim($line);
			if (empty($str)) {
				continue;
			}

			// @todo remove ' in the next major release to be in line with the svn book
			if ($str{0} == '#' || $str{0} == "'") {
				continue;
			}

			if ($str != $line && !empty($cursection) && !empty($curkey)) {
				// line starts with whitespace
				$this->sections[$cursection][$curkey] .= strtolower($str);
			} else if ($str{0} == '[' && $str{strlen($str) - 1} == ']') {
				$cursection = strtolower(substr($str, 1, strlen($str) - 2));
				$first = true;
			} else if (!empty($cursection)) {
				if ($first) {
					if (($cursection != 'aliases' && $cursection != 'groups') || !isset($this->sections[$cursection])) {
						$this->sections[$cursection] = array();
					}
				}
				list($key, $val) = explode('=', $str, 2);
				$key = strtolower(trim($key));
				$curkey = $key;
				$this->sections[$cursection][$key] = strtolower(trim($val));
				$first = false;
			}
		}
	}

	// }}}

	// {{{ getSections

	function &getSections() {
		return $this->sections;
	}

	// }}}

	// {{{ getValues

	function getValues($section) {
		return @$this->sections[strtolower($section)];
	}

	// }}}

	// {{{ getValue

	function getValue($section, $key) {
		return @$this->sections[strtolower($section)][strtolower($key)];
	}

	// }}}
}