1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
<?php
require_once('common/include/User.class');
class CVSPlugin extends SCM {
function CVSPlugin () {
$this->SCM () ;
$this->name = 'scmcvs';
$this->text = 'CVS';
$this->hooks[] = 'scm_page';
$this->hooks[] = 'scm_admin_update';
$this->hooks[] = 'scm_admin_page';
$this->hooks[] = 'scm_stats';
$this->hooks[] = 'scm_plugin';
// $this->hooks[] = 'group_approved';
$this->hooks[] = 'cssfile';
require_once('plugins/scmcvs/config.php') ;
$this->default_cvs_server = $default_cvs_server ;
//$this->default_cvs_server = $default_cvs_server ;
//$this->this_server = $this_server ;
$this->enabled_by_default = $enabled_by_default ;
$this->register () ;
}
function getDefaultServer() {
return $this->default_cvs_server;
}
function CallHook ($hookname, $params) {
global $Language, $HTML;
switch ($hookname) {
case 'scm_page':
$group_id = $params['group_id'] ;
$this->display_scm_page ($group_id) ;
break ;
case 'scm_admin_update':
$this->scm_admin_update ($params) ;
break ;
case 'scm_admin_page':
$this->display_scm_admin_page ($params) ;
break ;
case 'scm_stats':
$this->display_stats ($params) ;
break;
// case "group_approved":
// $this->group_approved ($params) ;
// break;
case 'cssfile':
$this->cssfile_scm ($params) ;
break;
case 'scm_plugin':
$scm_plugins=& $params['scm_plugins'];
$scm_plugins[]=$this->name;
break;
default:
// Forgot something
}
}
function cssfile_scm ($layout) {
echo '<link rel="stylesheet" type="text/css" href="/plugins/scmcvs/cvsweb/css/cvsweb.css" />';
}
function display_scm_page ($group_id) {
global $Language, $HTML ;
$project =& group_get_object($group_id);
if (!$project || !is_object($project)) {
return false;
} elseif ($project->isError()) {
return false;
}
if ($project->usesPlugin($this->name)) {
print $Language->getText('plugin_scmcvs','documentation');
$cvsrootend=$project->getSCMBox().':/cvsroot/'.$project->getUnixName();
// CVS browser links must be displayed if
// project enables anon CVS or if logged-in
// user is a member of the group
$displayCvsBrowser = $project->enableAnonSCM();
if(session_loggedin()) {
$perm =& $project->getPermission(session_get_user());
if ($perm && is_object($perm) && !$perm->isError() && $perm->isMember()) {
$displayCvsBrowser = true;
}
}
// ######################## Table for summary info
?>
<table width="100%">
<tr valign="top">
<td width="65%">
<?php
// ######################## Anonymous CVS Instructions
if ($project->enableAnonSCM()){
echo $Language->getText('plugin_scmcvs', 'anoncvs');
print '
<p>
<tt>cvs -d :pserver:anonymous@' . $cvsrootend.' login</tt><br/>
<tt>cvs -d :pserver:anonymous@' . $cvsrootend.' checkout <em>'.$Language->getText('plugin_scmcvs', 'modulename').'</em></tt>
</p>';
}
// ######################## Developer Access
echo $Language->getText('plugin_scmcvs', 'devcvs');
print '
<p>
<tt>export CVS_RSH=ssh</tt><br/>
<tt>cvs -d :ext:<em>'.$Language->getText('plugin_scmcvs', 'developername').'</em>@'.$cvsrootend.' checkout <em>'.$Language->getText('plugin_scmcvs', 'modulename').'</em></tt>
</p>';
// ######################## CVS Snapshot
if ($displayCvsBrowser) {
print '
<p>
[<a href="/snapshots.php?group_id='.$group_id.'">'.$Language->getText('plugin_scmcvs', 'download_snapshot').'</a>]
</p>';
}
?>
</td>
<td width="35%" valign="top">
<?php
// ######################## CVS Browsing
echo $HTML->boxTop($Language->getText('plugin_scmcvs', 'history'));
echo $this->display_detailed_stats(array('group_id'=>$group_id)).'<p>';
if ($displayCvsBrowser){
echo $Language->getText('plugin_scmcvs', 'browsetree');
echo '<p>[<a href="'.$this->account_group_cvsweb_url($group_id).'">'.$Language->getText('plugin_scmcvs', 'browseit').'</a>]</p>' ;
$hook_params['project_name'] = $project->getUnixName();
plugin_hook ("cvs_stats", $hook_params) ;
}
echo $HTML->boxBottom();
?>
</td>
</tr>
</table>
<?php
}
}
function scm_admin_update ($params) {
$group =& group_get_object($params['group_id']);
if (!$group || !is_object($group)) {
return false;
} elseif ($group->isError()) {
return false;
}
if ($group->usesPlugin($this->name)) {
if ($params['scmcvs_enable_anoncvs']) {
$group->SetUsesAnonSCM(true);
} else {
$group->SetUsesAnonSCM(false);
}
if ($params['scmcvs_enable_pserver']) {
$group->SetUsesPserver(true);
} else {
$group->SetUsesPserver(false);
}
}
}
// This function is used to render checkboxes below
function c($v) {
if ($v) {
return 'checked="checked"';
} else {
return '';
}
}
function display_scm_admin_page ($params) {
global $Language;
$group =& group_get_object($params['group_id']);
if ($group->usesPlugin($this->name)) {
?>
<p>
<input type="checkbox" name="scmcvs_enable_anoncvs" value="1" <?php echo $this->c($group->enableAnonSCM()); ?> /><strong><?php echo $Language->getText('plugin_scmcvs','enable_anonymous_cvs') ?></strong>
<br />
<input type="checkbox" name="scmcvs_enable_pserver" value="1" <?php echo $this->c($group->enablePserver()); ?> /><strong><?php echo $Language->getText('plugin_scmcvs','enable_pserver') ?></strong>
</p>
<?php
}
}
function display_stats ($params) {
global $Language ;
$group_id = $params['group_id'] ;
$project =& group_get_object($group_id);
if (!$project || !is_object($project)) {
return false;
} elseif ($project->isError()) {
return false;
}
if ($project->usesPlugin($this->name)) {
$result = db_query("
SELECT sum(commits) AS commits, sum(adds) AS adds
FROM stats_cvs_group
WHERE group_id='$group_id'");
$commit_num = db_result($result,0,'commits');
$add_num = db_result($result,0,'adds');
if (!$commit_num) {
$commit_num=0;
}
if (!$add_num) {
$add_num=0;
}
echo ' (CVS: '.$Language->getText('plugin_scmcvs','cvs_commits',array(number_format($commit_num,0),number_format($add_num,0))).")";
}
}
function display_detailed_stats ($params) {
global $Language, $HTML;
$group_id = $params['group_id'] ;
$result = db_query('
SELECT u.realname, u.user_name, sum(commits) as commits, sum(adds) as adds, sum(adds+commits) as combined
FROM stats_cvs_user s, users u
WHERE group_id=\''.$group_id.'\' AND s.user_id=u.user_id AND (commits>0 OR adds >0)
GROUP BY group_id, realname, user_name
ORDER BY combined DESC, realname;
');
if (db_numrows($result) > 0) {
$tableHeaders = array(
$Language->getText('plugin_scmcvs', 'realname'),
$Language->getText('plugin_scmcvs', 'adds'),
$Language->getText('plugin_scmcvs', 'commits')
);
echo $HTML->listTableTop($tableHeaders);
$i = 0;
$total = array('adds' => 0, 'commits' => 0);
while($data = db_fetch_array($result)) {
echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
echo '<td width="50%"><a href="/users/'.$data['user_name'].'/">'.$data['realname'].'</a></td>'.
'<td width="25%" align="right">'.$data['adds']. '</td>'.
'<td width="25%" align="right">'.$data['commits'].'</td></tr>';
$total['adds'] += $data['adds'];
$total['commits'] += $data['commits'];
$i++;
}
echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
echo '<td width="50%"><strong>'.$Language->getText('plugin_scmcvs', 'total').':</strong></td>'.
'<td width="25%" align="right"><strong>'.$total['adds']. '</strong></td>'.
'<td width="25%" align="right"><strong>'.$total['commits'].'</strong></td>';
echo '</tr>';
echo $HTML->listTableBottom();
echo '<hr size="1" />';
}
}
/**
* account_group_cvsweb_url() - Returns URL for group's CVS interface WWW
*
* @param string The group name
* @return URL to access CVS over HTTP
*/
function account_group_cvsweb_url($group_id) {
$project =& group_get_object($group_id);
//return 'http://'.$project->getSCMBox().'/plugins/scmcvs/cvsweb.php/?cvsroot='.$project->getUnixName();
// external SCM box is now handled inside cvsweb.php
return '/plugins/scmcvs/cvsweb.php/?cvsroot='.$project->getUnixName();
}
/*
function group_approved ($params) {
$group_id = $params['group_id'] ;
$project =& group_get_object($group_id);
if ($this->enabled_by_default) {
$group->setPluginUse("scmcvs", 1) ;
} else {
$group->setPluginUse("scmcvs", 0) ;
}
}
*/
}
// Local Variables:
// mode: php
// c-file-style: "bsd"
// End:
?>
|