We now have a working index.php again:
[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 ViewSVN
34 * @version $Id$
35 */
36 class Repository
37 {
38 /**
39 * Array of valid repositories
40 * @var array
41 */
42 private $repositories = array();
43
44 /**
45 * Root path to the repository
46 * @var string
47 */
48 private $path;
49
50 /**
51 * Whether or not the path is a container
52 * @var bool
53 */
54 private $container;
55
56 // ###################################################################
57 /**
58 * Constructor: prepare for repository
59 *
60 * @param string Path to repository or container
61 * @param bool Whether the path is a container
62 */
63 function __construct($path, $iscontainer)
64 {
65 global $viewsvn;
66
67 $this->path = BSFunctions::FetchSourcePath($path);
68 $this->container = (bool)$iscontainer;
69
70 if ($this->container)
71 {
72 if ($dir = @opendir($this->path))
73 {
74 while (($file = readdir($dir)) !== false)
75 {
76 if (is_dir($this->path . $file) AND $file{0} != '.' AND is_dir($this->path . $file . '/' . 'db'))
77 {
78 $this->repositories[] = $file;
79 }
80 }
81 closedir($dir);
82 }
83 }
84 else
85 {
86 if (is_dir($this->path . 'db'))
87 {
88 $this->repositories[] = $this->path;
89 }
90 }
91
92 sort($this->repositories);
93
94 if (sizeof($this->repositories) < 1)
95 {
96 $viewsvn->trigger->error($viewsvn->lang->string('There are no valid repositories'));
97 }
98 }
99
100 // ###################################################################
101 /**
102 * Returns a list of repositories
103 *
104 * @return array List of repositories
105 */
106 public function fetchList()
107 {
108 return $this->repositories;
109 }
110
111 // ###################################################################
112 /**
113 * Returns a path to a repository
114 *
115 * @access public
116 *
117 * @param string Repository name
118 *
119 * @return string Full path to the repository
120 */
121 function fetch_path($repository = '')
122 {
123 global $viewsvn;
124
125 if (!in_array($repository, $this->fetch_list()))
126 {
127 $viewsvn->trigger->error($viewsvn->lang->string('Invalid repository name specified'));
128 }
129
130 if ($this->container)
131 {
132 return 'file://' . $this->path . $repository;
133 }
134 else
135 {
136 return 'file://' . $this->path;
137 }
138 }
139
140 // ###################################################################
141 /**
142 * Verifies a path inside a repository
143 *
144 * @access public
145 *
146 * @param string Repository name
147 * @param string Path
148 *
149 * @return bool Validity
150 */
151 function verify($repos, $path)
152 {
153 global $viewsvn;
154
155 if ($repospath = $this->fetch_path($repos))
156 {
157 return true;
158 }
159 else
160 {
161 return false;
162 }
163 }
164 }
165
166 /*=====================================================================*\
167 || ###################################################################
168 || # $HeadURL$
169 || # $Id$
170 || ###################################################################
171 \*=====================================================================*/
172 ?>