3 class CVSPlugin extends SCM {
4 function CVSPlugin () {
7 $this->name = 'scmcvs';
9 $this->hooks[] = 'scm_page';
10 $this->hooks[] = 'scm_admin_update';
11 $this->hooks[] = 'scm_admin_page';
12 $this->hooks[] = 'scm_stats';
14 $this->hooks[] = 'scm_plugin';
16 require_once('plugins/scmcvs/config.php') ;
18 $this->default_cvs_server = $default_cvs_server ;
20 $this->cvs_root = $cvs_root;
22 $this->cvs_root = "/cvsroot";
24 //$this->default_cvs_server = $default_cvs_server ;
25 //$this->this_server = $this_server ;
26 $this->enabled_by_default = $enabled_by_default ;
31 function getDefaultServer() {
32 return $this->default_cvs_server;
35 function CallHook ($hookname, $params) {
36 global $Language, $HTML;
40 $group_id = $params['group_id'] ;
41 $this->getPage ($group_id) ;
43 case 'scm_admin_update':
44 $this->adminUpdate ($params) ;
46 case 'scm_admin_page':
47 $this->getAdminPage ($params) ;
50 $this->getStats ($params) ;
53 $scm_plugins=& $params['scm_plugins'];
54 $scm_plugins[]=$this->name;
61 function getPage ($group_id) {
62 global $Language, $HTML ;
64 $project =& group_get_object($group_id);
65 if (!$project || !is_object($project)) {
67 } elseif ($project->isError()) {
71 if ($project->usesPlugin($this->name)) {
73 print _('Some CVS documentation is available <a href="http://www.nongnu.org/cvs/">Here</a>');
75 $cvsrootend=$project->getSCMBox().':/cvsroot/'.$project->getUnixName();
76 $cvsrootend = $project->getSCMBox().':'.$this->cvs_root.'/'.$project->getUnixName();
78 // CVS browser links must be displayed if
79 // project enables anon CVS or if logged-in
80 // user is a member of the group
81 $displayCvsBrowser = $project->enableAnonSCM();
82 if(session_loggedin()) {
83 $perm =& $project->getPermission(session_get_user());
84 if ($perm && is_object($perm) && !$perm->isError() && $perm->isMember()) {
85 $displayCvsBrowser = true;
89 // ######################## Table for summary info
95 // ######################## Anonymous CVS Instructions
96 if ($project->enableAnonSCM()){
97 echo _('<p><b>Anonymous CVS Access</b></p><p>This project\'s CVS repository can be checked out through anonymous (pserver) CVS with the following instruction set. The module you wish to check out must be specified as the <i>modulename</i>. When prompted for a password for <i>anonymous</i>, simply press the Enter key.</p>');
100 <tt>cvs -d :pserver:anonymous@' . $cvsrootend.' login</tt><br/>
101 <tt>cvs -d :pserver:anonymous@' . $cvsrootend.' checkout <em>'._('modulename').'</em></tt>
105 // ######################## Developer Access
106 echo _('<p><b>Developer CVS Access via SSH</b></p><p>Only project developers can access the CVS tree via this method. SSH must be installed on your client machine. Substitute <i>modulename</i> and <i>developername</i> with the proper values. Enter your site password when prompted.</p>');
109 <tt>export CVS_RSH=ssh</tt><br/>
110 <tt>cvs -d :ext:<em>'._('developername').'</em>@'.$cvsrootend.' checkout <em>'._('developername').'</em></tt>
113 // ######################## CVS Snapshot
114 if ($displayCvsBrowser) {
117 [<a href="/snapshots.php?group_id='.$group_id.'">'._('Download The Nightly CVS Tree Snapshot').'</a>]
123 <td width="35%" valign="top">
125 // ######################## CVS Browsing
126 echo $HTML->boxTop(_('Repository History'));
127 echo $this->getDetailedStats(array('group_id'=>$group_id)).'<p>';
128 if ($displayCvsBrowser){
129 echo _('<b>Browse the CVS Tree</b><p>Browsing the CVS tree gives you a great view into the current status of this project\'s code. You may also view the complete histories of any file in the repository.</p>');
130 echo '<p>[<a href="/scm/viewvc.php/?root='.$project->getUnixName().'">'._('Browse CVS Repository').'</a>]</p>' ;
131 $hook_params['project_name'] = $project->getUnixName();
132 plugin_hook ("cvs_stats", $hook_params) ;
134 echo $HTML->boxBottom();
143 function adminUpdate ($params) {
144 $group =& group_get_object($params['group_id']);
145 if (!$group || !is_object($group)) {
147 } elseif ($group->isError()) {
150 if ($group->usesPlugin($this->name)) {
151 if ($params['scmcvs_enable_anoncvs']) {
152 $group->SetUsesAnonSCM(true);
154 $group->SetUsesAnonSCM(false);
156 if ($params['scmcvs_enable_pserver']) {
157 $group->SetUsesPserver(true);
159 $group->SetUsesPserver(false);
164 // This function is used to render checkboxes below
167 return 'checked="checked"';
173 function getAdminPage ($params) {
175 $group =& group_get_object($params['group_id']);
177 if ($group->usesPlugin($this->name)) {
180 <input type="checkbox" name="scmcvs_enable_anoncvs" value="1" <?php echo $this->c($group->enableAnonSCM()); ?> /><strong><?php echo _('Enable Anonymous Access') ?></strong>
182 <input type="checkbox" name="scmcvs_enable_pserver" value="1" <?php echo $this->c($group->enablePserver()); ?> /><strong><?php echo _('Enable pserver') ?></strong>
188 function getStats ($params) {
190 $group_id = $params['group_id'] ;
191 $project =& group_get_object($group_id);
192 if (!$project || !is_object($project)) {
194 } elseif ($project->isError()) {
198 if ($project->usesPlugin($this->name)) {
200 SELECT sum(commits) AS commits, sum(adds) AS adds
202 WHERE group_id='$group_id'");
203 $commit_num = db_result($result,0,'commits');
204 $add_num = db_result($result,0,'adds');
211 echo ' (CVS: '.sprintf(_('<strong>%1$s</strong> commits, <strong>%2$s</strong> adds'), number_format($commit_num, 0), number_format($add_num, 0)).")";
215 function getDetailedStats ($params) {
216 global $Language, $HTML;
217 $group_id = $params['group_id'] ;
220 SELECT u.realname, u.user_name, sum(commits) as commits, sum(adds) as adds, sum(adds+commits) as combined
221 FROM stats_cvs_user s, users u
222 WHERE group_id=\''.$group_id.'\' AND s.user_id=u.user_id AND (commits>0 OR adds >0)
223 GROUP BY group_id, realname, user_name
224 ORDER BY combined DESC, realname;
227 if (db_numrows($result) > 0) {
228 $tableHeaders = array(
233 echo $HTML->listTableTop($tableHeaders);
236 $total = array('adds' => 0, 'commits' => 0);
238 while($data = db_fetch_array($result)) {
239 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
240 echo '<td width="50%"><a href="/users/'.$data['user_name'].'/">'.$data['realname'].'</a></td>'.
241 '<td width="25%" align="right">'.$data['adds']. '</td>'.
242 '<td width="25%" align="right">'.$data['commits'].'</td></tr>';
243 $total['adds'] += $data['adds'];
244 $total['commits'] += $data['commits'];
247 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
248 echo '<td width="50%"><strong>'._('Total').':</strong></td>'.
249 '<td width="25%" align="right"><strong>'.$total['adds']. '</strong></td>'.
250 '<td width="25%" align="right"><strong>'.$total['commits'].'</strong></td>';
252 echo $HTML->listTableBottom();
253 echo '<hr size="1" />';
260 // c-file-style: "bsd"