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