Remove the extra path part
[viewsvn.git] / includes / repository.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Class that manages repositories and can produce lists of
24 * repositories
25 *
26 * @pacakge ViewSVN
27 */
28
29 /**
30 * Repository class that can list repositories and prepare
31 * them for use
32 *
33 * @package DeskPRO
34 * @version $Id$
35 */
36 class Repository
37 {
38 /**
39 * Array of valid repositories
40 * @var array
41 * @access private
42 */
43 var $repositories = array();
44
45 /**
46 * Root path to the repository
47 * @var string
48 * @access private
49 */
50 var $path;
51
52 /**
53 * Whether or not the path is a container
54 * @var bool
55 * @access private
56 */
57 var $container;
58
59 /**
60 * Constructor: prepare for repository
61 *
62 * @param string Path to repository or container
63 * @param bool Whether the path is a container
64 */
65 function Repository($path, $iscontainer)
66 {
67 global $viewsvn;
68
69 $this->path = $viewsvn->fetch_sourcepath($path);
70 $this->container = (bool)$iscontainer;
71
72 if ($this->container)
73 {
74 if ($dir = @opendir($this->path))
75 {
76 while (($file = readdir($dir)) !== false)
77 {
78 if (is_dir($this->path . $file) AND $file{0} != '.' AND is_dir($this->path . $file . '/' . 'db'))
79 {
80 $this->repositories[] = $file;
81 }
82 }
83 closedir($dir);
84 }
85 }
86 else
87 {
88 if (is_dir($this->path . 'db'))
89 {
90 $this->repositories[] = $this->path;
91 }
92 }
93
94 sort($this->repositories);
95
96 if (sizeof($this->repositories) < 1)
97 {
98 $viewsvn->trigger->error($viewsvn->lang->string('There are no valid repositories'));
99 }
100 }
101
102 /**
103 * Returns a list of repositories
104 *
105 * @access public
106 *
107 * @return array List of repositories
108 */
109 function fetch_list()
110 {
111 return $this->repositories;
112 }
113
114 /**
115 * Returns a path to a repository
116 *
117 * @access public
118 *
119 * @param string Repository name
120 *
121 * @return string Full path to the repository
122 */
123 function fetch_path($repository = '')
124 {
125 global $viewsvn;
126
127 if (!in_array($repository, $this->fetch_list()))
128 {
129 $viewsvn->trigger->error($viewsvn->lang->string('Invalid repository name specified'));
130 }
131
132 if ($this->container)
133 {
134 return 'file://' . $this->path . $repository;
135 }
136 else
137 {
138 return 'file://' . $this->path;
139 }
140 }
141
142 /**
143 * Verifies a path inside a repository
144 *
145 * @access public
146 *
147 * @param string Repository name
148 * @param string Path
149 *
150 * @return bool Validity
151 */
152 function verify($repos, $path)
153 {
154 global $viewsvn;
155
156 if ($repospath = $this->fetch_path($repos))
157 {
158 return true;
159 }
160 else
161 {
162 return false;
163 }
164 }
165 }
166
167 /*=====================================================================*\
168 || ###################################################################
169 || # $HeadURL$
170 || # $Id$
171 || ###################################################################
172 \*=====================================================================*/
173 ?>