2 /** Subversion plugin for Gforge
3 * Copyright 2003 Roland Mas <lolando@debian.org>
4 * Copyright 2004 Roland Mas <roland@gnurandal.com>
5 * The Gforge Group, LLC <http://gforgegroup.com/>
6 * Based on the CVS plugin, which was derived from Gforge, which was
7 * derived from Sourceforge
9 * This file is not part of Gforge
11 * This plugin, like Gforge, is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * GForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
26 require_once('common/include/User.class');
28 class SVNPlugin extends SCM {
29 function SVNPlugin () {
31 $this->name = 'scmsvn';
33 $this->hooks[] = 'scm_page';
34 $this->hooks[] = 'scm_admin_update';
35 $this->hooks[] = 'scm_admin_page';
37 $this->hooks[] = 'scm_stats';
38 // $this->hooks[] = 'group_approved';
39 $this->hooks[] = 'scm_plugin';
41 require_once('plugins/scmsvn/config.php') ;
43 $this->default_svn_server = $default_svn_server ;
44 $this->enabled_by_default = $enabled_by_default ;
45 $this->use_ssh = $use_ssh;
46 $this->use_dav = $use_dav;
47 $this->use_ssl = $use_ssl;
48 $this->svn_root = $svn_root;
53 function getDefaultServer() {
54 return $this->default_svn_server ;
57 function CallHook ($hookname, $params) {
58 global $Language, $HTML ;
62 $group_id = $params['group_id'] ;
63 $this->getPage ($group_id) ;
65 case 'scm_admin_update':
66 $this->AdminUpdate ($params) ;
68 case 'scm_admin_page':
69 $this->getAdminPage ($params) ;
72 $this->getStats ($params) ;
74 // case 'group_approved':
75 // $this->groupApproved ($params) ;
78 $scm_plugins=& $params['scm_plugins'];
79 $scm_plugins[]=$this->name;
86 function getPage ($group_id) {
87 global $Language, $HTML ;
89 $project =& group_get_object($group_id);
90 if (!$project || !is_object($project)) {
92 } elseif ($project->isError()) {
96 if ($project->usesPlugin ($this->name)) {
98 // SVN browser links must be displayed if
99 // project enables anon SVN or if logged-in
100 // user is a member of the group
101 $displaySvnBrowser = $project->enableAnonSCM();
102 if(session_loggedin()) {
103 $perm =& $project->getPermission(session_get_user());
104 if ($perm && is_object($perm) && !$perm->isError() && $perm->isMember()) {
105 $displaySvnBrowser = true;
109 // ######################## Table for summary info
115 print $Language->getText('plugin_scmsvn','documentation');
117 // ######################## Anonymous SVN Instructions
118 if ($project->enableAnonSCM()) {
119 print $Language->getText('plugin_scmsvn', 'anonsvn');
121 if ($this->use_ssh) {
122 print '<tt>svn checkout svn://'.$project->getSCMBox().'/'.$this->svn_root.'/'.$project->getUnixName().'</tt><br />';
124 if ($this->use_dav) {
125 print '<tt>svn checkout http'.(($this->use_ssl) ? 's' : '').'://' . $project->getSCMBox(). '/' . $this->svn_root .'/'. $project->getUnixName() .'</tt><br/>';
130 // ######################## Developer Access
131 if ($this->use_ssh) {
132 echo $Language->getText('plugin_scmsvn', 'devsvnssh');
133 print '<p><tt>svn checkout svn+ssh://<i>'.$Language->getText('plugin_scmsvn', 'developername').'</i>@' . $project->getSCMBox() . '/'. $this->svn_root .'/'. $project->getUnixName().'</tt></p>' ;
135 if ($this->use_dav) {
136 echo $Language->getText('plugin_scmsvn', 'devsvndav');
137 print '<p><tt>svn checkout --username <i>'.$Language->getText('plugin_scmsvn', 'developername').'</i> http'.(($this->use_ssl) ? 's' : '').'://'. $project->getSCMBox() .'/'. $this->svn_root .'/'.$project->getUnixName().'</tt></p>' ;
140 // ######################## SVN Snapshot
141 if ($displaySvnBrowser) {
142 $filename=$project->getUnixName().'-scm-latest.tar.gz';
143 if (file_exists($sys_scm_snapshots_path.'/'.$filename)) {
144 print '<p>[<a href="/snapshots.php?group_id='.$group_id.'">'
145 .$Language->getText('plugin_scmsvn', 'download_snapshot').
152 <td width="35%" valign="top">
154 // ######################## SVN Browsing
155 echo $HTML->boxTop($Language->getText('plugin_scmsvn', 'history'));
156 echo $this->getDetailedStats(array('group_id'=>$group_id)).'<p>';
157 if ($displaySvnBrowser) {
158 echo $Language->getText('plugin_scmsvn', 'browsetree');
159 echo '<p>[<a href="/scm/viewvc.php/?root='.$project->getUnixName().'">'.$Language->getText('plugin_scmsvn', 'browseit').'</a>]</p>' ;
162 echo $HTML->boxBottom();
171 function AdminUpdate ($params) {
172 $group =& group_get_object($params['group_id']);
173 if (!$group || !is_object($group)) {
175 } elseif ($group->isError()) {
178 if ( $group->usesPlugin ( $this->name ) ) {
179 if ($params['scmsvn_enable_anon_svn']) {
180 $group->SetUsesAnonSCM(true);
182 $group->SetUsesAnonSCM(false);
187 // This function is used to render checkboxes below
190 return 'checked="checked"';
196 function getAdminPage ($params) {
198 $group =& group_get_object($params['group_id']);
199 if ( $group->usesPlugin ( $this->name ) ) {
201 <p><input type="checkbox" name="scmsvn_enable_anon_svn" value="1" <?php echo $this->c($group->enableAnonSCM()); ?> /><strong><?php echo $Language->getText('plugin_scmsvn', 'enable_anonymous_svn') ?></strong></p>
206 function getStats ($params) {
208 $group_id = $params['group_id'] ;
209 $project =& group_get_object($group_id);
210 if (!$project || !is_object($project)) {
212 } elseif ($project->isError()) {
216 if ($project->usesPlugin ($this->name)) {
217 list($commit_num, $add_num) = $this->getTotalStats($group_id);
218 echo ' (SVN: '.$Language->getText('plugin_scmsvn','svn_updates',array(number_format($commit_num,0),number_format($add_num,0))).')';
222 // Get the total stats for a group
223 function getTotalStats($group_id) {
225 SELECT SUM(commits) AS commits, SUM(adds) AS adds
227 WHERE group_id='$group_id'");
228 $commit_num = db_result($result,0,0);
229 $add_num = db_result($result,0,1);
236 return array($commit_num, $add_num);
239 // Not used at the moment and probably useless
240 function groupApproved ($params) {
241 $group_id = $params['group_id'] ;
243 $project =& group_get_object($group_id);
244 if (!$project || !is_object($project)) {
246 } elseif ($project->isError()) {
249 if ($this->enabled_by_default) {
250 $project->setPluginUse('scmsvn', 1) ;
252 $project->setPluginUse('scmsvn', 0) ;
257 function getDetailedStats ($params) {
258 global $Language, $HTML;
259 $group_id = $params['group_id'] ;
262 SELECT u.realname, u.user_name, sum(commits) as commits, sum(adds) as adds, sum(adds+commits) as combined
263 FROM stats_cvs_user s, users u
264 WHERE group_id=\''.$group_id.'\' AND s.user_id=u.user_id AND (commits>0 OR adds >0)
265 GROUP BY group_id, realname, user_name
266 ORDER BY combined DESC, realname;
269 if (db_numrows($result) > 0) {
270 $tableHeaders = array(
271 $Language->getText('plugin_scmsvn', 'realname'),
272 $Language->getText('plugin_scmsvn', 'adds'),
273 $Language->getText('plugin_scmsvn', 'commits')
275 echo $HTML->listTableTop($tableHeaders);
278 $total = array('adds' => 0, 'commits' => 0);
280 while($data = db_fetch_array($result)) {
281 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
282 echo '<td width="50%">' .
283 '<a href="/users/'.$data['user_name'].'/">'.$data['realname'].'</a>' .
284 '</td><td width="25%" align="right">'.$data['adds']. '</td>'.
285 '<td width="25%" align="right">'.$data['commits'].'</td></tr>';
286 $total['adds'] += $data['adds'];
287 $total['commits'] += $data['commits'];
290 list($commit_num, $add_num) = $this->getTotalStats($group_id);
291 if ($commit_num > $total['commits'] ||
292 $add_num > $total['adds']) {
293 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
294 echo '<td width="50%">' .
295 $Language->getText('plugin_scmsvn', 'unknown') .
296 '</td><td width="25%" align="right">'.
297 ($add_num - $total['adds']) . '</td>'.
298 '<td width="25%" align="right">'.
299 ($commit_num - $total['commits']) .
303 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
304 echo '<td width="50%"><strong>'.$Language->getText('plugin_scmsvn', 'total').':</strong></td>'.
305 '<td width="25%" align="right"><strong>'.$add_num. '</strong></td>'.
306 '<td width="25%" align="right"><strong>'.$commit_num.'</strong></td>';
308 echo $HTML->listTableBottom();
309 echo '<hr size="1" />';
316 // c-file-style: "bsd"