1: <?php
2: /**
3: * Luxor repository implementation for a simple filesystem hierarchy.
4: *
5: * $Horde: luxor/lib/Files/plain.php,v 1.18 2006/05/23 02:27:39 selsky Exp $
6: *
7: * @author Jan Schneider <jan@horde.org>
8: * @since Luxor 0.1
9: * @package Luxor
10: */
11: class Luxor_Files_plain extends Luxor_Files {
12:
13: /**
14: * Hash containing parameters.
15: *
16: * @var array
17: */
18: var $_params = array();
19:
20: /**
21: * Constructs a new filesystem handler.
22: *
23: * @param array $params A hash containing parameters.
24: */
25: function Luxor_Files_plain($params = array())
26: {
27: $this->_params = $params;
28: }
29:
30: function getFiletime($filename)
31: {
32: return filemtime($this->toReal($filename));
33: }
34:
35: function getFilesize($filename)
36: {
37: return filesize($this->toReal($filename));
38: }
39:
40: /**
41: * Returns a file handler.
42: *
43: * @param string $filename The name of the file to open.
44: *
45: * @return ressource A handler of the file or false on error.
46: */
47: function getFileHandle($filename)
48: {
49: return @fopen($this->toReal($filename), 'r');
50: }
51:
52: /**
53: * Creates a temporary copy of a file.
54: *
55: * @param string $filename The name of the file to be copied.
56: *
57: * @return string The file name of the temporary copy or false
58: * if the file couldn't be copied.
59: */
60: function tmpFile($filename)
61: {
62: $tmp = Horde::getTempFile('luxor');
63: if (!@copy($this->toReal($filename), $tmp)) {
64: return false;
65: }
66: return $tmp;
67: }
68:
69: /**
70: * Returns a directory's content. Backup files are skipped and
71: * directories suffixed with a slash.
72: *
73: * @param string $path The directory to list.
74: *
75: * @return array An array containing all directories and files of
76: * the directory or PEAR_Error if the directory
77: * couldn't be read.
78: */
79: function getDir($path, $release = '')
80: {
81: $path = $this->toReal($path);
82:
83: $dir = @opendir($path);
84: if (!$dir) {
85: return PEAR::raiseError(sprintf(_("Can't open directory %s"), $path));
86: }
87:
88: $dirs = array();
89: $files = array();
90: while (($file = readdir($dir)) !== false) {
91: if (preg_match('/^\.|~$|\.orig$|\.bak$/i', $file) ||
92: (is_dir($path . $file) && $file == 'CVS')) {
93: continue;
94: }
95:
96: if (is_dir($path . $file)) {
97: if (Luxor::isDirParsed($path . $file)) {
98: $dirs[] = $file . '/';
99: }
100: } else {
101: if (Luxor::isFileParsed($path . $file)) {
102: $files[] = $file;
103: }
104: }
105: }
106:
107: closedir($dir);
108: natcasesort($dirs);
109: natcasesort($files);
110: return array_merge($dirs, $files);
111: }
112:
113: /**
114: * Returns the full path to a file.
115: *
116: * @param string $pathname The internally used (relative) name of the file.
117: *
118: * @return string The full path to the file.
119: */
120: function toReal($pathname)
121: {
122: return $this->_params['root'] . $pathname;
123: }
124:
125: /**
126: * Checks if the given path name is a directory.
127: *
128: * @param string $pathname The path name to check.
129: *
130: * @return boolean True if the path name was a directory.
131: */
132: function isDir($pathname)
133: {
134: return is_dir($this->toReal($pathname));
135: }
136:
137: /**
138: * Checks if the given path name is a file.
139: *
140: * @param string $pathname The path name to check.
141: *
142: * @return boolean True if the path name was a file.
143: */
144: function isFile($pathname)
145: {
146: return is_file($this->toReal($pathname));
147: }
148:
149: function getIndex($pathname)
150: {
151: $indexname = $this->toReal($pathname) . '00-INDEX';
152: if (file_exists($indexname)) {
153: $index = file_get_contents($indexname);
154:
155: if (preg_match_all('/\n(\S*)\s*\n\t-\s*([^\n]*)/s', $index, $match)) {
156: $list = array();
157: $iMax = count($match[1]);
158: for ($i = 0; $i < $iMax; $i++) {
159: $list[$match[1][$i]] = $match[2][$i];
160: }
161: return $list;
162: }
163: }
164: return array();
165: }
166:
167: function getAnnotations($pathname)
168: {
169: return array();
170: }
171:
172: }
173: