Repository can now take in an array of repositories to include to explicitly allow...
[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 * Whether or not the path is a container
46 * @var bool
47 */
48 public $container;
49
50 // ###################################################################
51 /**
52 * Constructor: prepare for repository
53 *
54 * @param mixed Path to repository or container
55 * @param bool Whether the path is a container
56 * @param array Array of paths to include (only applicable with containers)
57 */
58 function __construct($path, $iscontainer, $include)
59 {
60 global $viewsvn;
61
62 if (is_array($include) AND sizeof($include) > 0 AND $iscontainer)
63 {
64 $this->container = (sizeof($include) > 1);
65 foreach ($include AS $repos)
66 {
67 $this->repositories[$repos] = BSFunctions::FetchSourcePath(BSFunctions::FetchSourcePath($path) . $repos);
68 }
69 }
70 else
71 {
72 $path = BSFunctions::FetchSourcePath($path);
73 $this->container = (bool)$iscontainer;
74 if ($this->container)
75 {
76 if ($dir = @opendir($path))
77 {
78 while (($file = readdir($dir)) !== false)
79 {
80 if (is_dir($path . $file) AND $file{0} != '.' AND is_dir($path . $file . '/' . 'db'))
81 {
82 $this->repositories[$file] = $path . $file;
83 }
84 }
85 closedir($dir);
86 }
87 }
88 else
89 {
90 if (is_dir($path . 'db'))
91 {
92 $this->repositories[basename($path)] = $path;
93 }
94 }
95 }
96
97 ksort($this->repositories);
98
99 if (sizeof($this->repositories) < 1)
100 {
101 $viewsvn->trigger->error(_('There are no valid repositories'));
102 }
103 }
104
105 // ###################################################################
106 /**
107 * Returns a list of repositories
108 *
109 * @return array List of repositories
110 */
111 public function fetchList()
112 {
113 return array_keys($this->repositories);
114 }
115
116 // ###################################################################
117 /**
118 * Returns a path to a repository
119 *
120 * @param string Repository name
121 *
122 * @return string Full path to the repository
123 */
124 public function fetchPath($repository = '')
125 {
126 global $viewsvn;
127
128 if (!isset($this->repositories[$repository]))
129 {
130 $viewsvn->trigger->error(_('Invalid repository name specified'));
131 }
132
133 return 'file://' . $this->repositories[$repository];
134 }
135
136 // ###################################################################
137 /**
138 * Verifies a path inside a repository
139 *
140 * @param string Repository name
141 * @param string Path
142 *
143 * @return bool Validity
144 */
145 public function verify($repos, $path)
146 {
147 global $viewsvn;
148
149 if ($repospath = $this->fetchPath($repos))
150 {
151 return true;
152 }
153 else
154 {
155 return false;
156 }
157 }
158 }
159
160 /*=====================================================================*\
161 || ###################################################################
162 || # $HeadURL$
163 || # $Id$
164 || ###################################################################
165 \*=====================================================================*/
166 ?>