5b4bf11ffa1581a4c801e223f278b927a80459ee
[clearscm.git] / web / php / clearscm.php
1 <?php
2 ////////////////////////////////////////////////////////////////////////////////
3 //
4 // File:        $RCSfile: clearscm.php,v $
5 // Revision:    $Revision: 1.23 $
6 // Description: Reports large files
7 // Author:      Andrew@DeFaria.com
8 // Created:     Wed Apr 11 18:37:09 2007
9 // Modified:    $Date: 2013/03/18 22:46:55 $
10 // Language:    Php
11 //
12 // (c) Copyright 2007, ClearSCM Inc., all rights reserved
13 //
14 ////////////////////////////////////////////////////////////////////////////////
15 $base = $_SERVER['DOCUMENT_ROOT'];
16
17 function menu_css () {
18   global $base;
19
20   $lines = @file ("$base/css/Menus.css")
21     or die ("Unable to open $base/css/Menus.css");
22
23   print "<style type=\"text/css\">\n";
24
25   foreach ($lines as $line) {
26     print $line;
27   } // foreach
28
29   print "</style>";
30 } // menu_css
31
32 function menu () {
33   print <<<END
34 <div class="imrcmain0 imgl" style="width:100%;z-index:999999;position:relative;">
35   <div class="imcm imde" id="imouter0">
36     <ul id="imenus0">
37     <li class="imatm" style="width:100px;"><a href="/"><span class="imea imeam"></span>Home</a></li>
38
39     <li class="imatm" style="width:145px;">
40       <a class="" href="/services"><span class="imea imeam"><span></span></span>Services</a>
41
42       <div class="imsc">
43         <div class="imsubc" style="width:145px;top:0px;left:0px;">
44           <ul style="">
45             <li><a href="/services/consultancy.php">Consultancy</a></li>
46             <li><a href="/services/custom_software.php">Custom Software Solutions</a></li>
47             <li><a href="/services/sysadmin.php">Systems Adminsitration</a></li>
48             <li><a href="/services/web.php">Web Applications</a></li>
49             <li><a href="/services/customers.php">Customers</a></li>
50           </ul>
51         </div>
52       </div>
53     </li>
54
55     <li class="imatm" style="width:145px;">
56       <a class="" href="/services/scm"><span class="imea imeam"><span></span></span>SCM</a>
57
58       <div class="imsc">
59         <div class="imsubc" style="width:145px;top:0px;left:0px;">
60           <ul style="">
61             <li><a href="/clearcase"><span class="imea imeas"><span></span></span>Clearcase</a>
62               <div class="imsc">
63                 <div class="imsubc" style="width:140px;top:-23px;left:132px;">
64                   <ul style="">
65                     <li><a href="/clearcase/triggers.php">Triggers</a></li>
66                     <li><a href="/php/cvs_man.php?file=cc/etf.pl">Evil Twin Finder</a></li>
67                     <li><a href="/php/cvs_man.php?file=cc/diffbl.pl">GUI DiffBL</a></li>
68                     <li><a href="/php/cvs_man.php?file=cc/viewager.cgi">View Ager</a></li>
69                     <li><a href="/clearcase/OpenSourceBuild.php/">Open Source Builds</a></li>
70                   </ul>
71                 </div>
72               </div>
73             </li>
74             <li><a href="/clearquest"><span class="imea imeas"><span></span></span>Clearquest</a>
75               <div class="imsc">
76                 <div class="imsubc" style="width:140px;top:-23px;left:132px;">
77                   <ul style="">
78                     <li><a href="/clearquest/cqd">Clearquest Daemon</a></li>
79                     <li><a href="/clearquest/db.php">DB Conversions</a></li>
80                   </ul>
81                 </div>
82               </div>
83             </li>
84             <li><a href="/cvs"><span class="imea imeas"><span></span></span>CVS</a>
85               <div class="imsc">
86                 <div class="imsubc" style="width:140px;top:-23px;left:132px;">
87                   <ul style="">
88                     <li><a href="/viewvc/clearscm.com/">Respository</a></li>
89                   </ul>
90                 </div>
91               </div>
92             </li>
93           </ul>
94         </div>
95       </div>
96     </li>
97
98     <li class="imatm" style="width:145px;"><a href="/scripts"><span class="imea imeam"><span></span></span>Scripting</a>
99       <div class="imsc">
100         <div class="imsubc" style="width:146px;top:0px;left:0px;">
101           <ul style="">
102             <li><a href="/scripts/perl.php">Perl</a></li>
103             <li><a href="/scripts/ecrd">ECRDig</a></li>
104           </ul>
105         </div>
106       </div>
107     </li>
108
109     <li class="imatm" style="width:145px;"><a href="/sysadm"><span class="imea imeam"><span></span></span>Sysadm</a>
110       <div class="imsc">
111         <div class="imsubc" style="width:146px;top:0px;left:0px;">
112           <ul style="">
113             <li><a href="/sysadm/env">Environment</a></li>
114           </ul>
115         </div>
116       </div>
117     </li>
118
119     <li class="imatm" style="width:145px;"><a href="#"><span class="imea imeam"><span></span></span>About</a>
120       <div class="imsc">
121         <div class="imsubc" style="width:146px;top:0px;left:0px;">
122           <ul style="">
123             <li><a href="/services">Services</a></li>
124             <li><a href="/people.php">Our People</a></li>
125             <li><a href="/contact.php">Contact Us</a></li>
126           </ul>
127         </div>
128       </div>
129     </li>
130   </ul>
131
132   <div class="imclear">&nbsp;</div>
133   </div>
134 </div>
135 END;
136 } // menu
137
138 function heading () {
139   print "<div id=head>";
140   menu ();
141   print <<<END
142   <h1 style="color:#fff;text-align:center;font-size:3em">ClearSCM Inc.</h1>
143
144   <div class="filtered">
145     <p><strong>You are viewing an unstyled version of this
146     page.</strong> Either your browser does not support Cascading
147     Style Sheets (CSS) or CSS styling has been disabled.</p>
148   </div>
149 END;
150 } // heading
151
152 function start_box ($type) {
153   print <<<END
154 <!--B-->  <div class="rcbox"><div class="$type"><b class="xtop"><b class="xb1"></b><b class="xb2"></b><b class="xb3"></b><b class="xb4"></b></b><div class="xboxcontent">
155 END;
156 } // start_box
157
158 function end_box () {
159   print <<<END
160 <!--A-->  </div><b class="xbottom"><b class="xb4"></b><b class="xb3"></b><b class="xb2"></b><b class="xb1"></b></b></div></div>
161 END;
162 } // end_box
163
164 function search_box () {
165   print <<<END
166 <div id="search">
167   <!-- Start: Search my site with Google -->
168   <form method="get" action="http://www.google.com/search" name="search">
169   <div>Search my site
170   <input type="text" name="q" size="15" id="q" maxlength=255 value=""
171     onclick="document.search.q.value='';">
172   <input type="hidden" name="domains" value="clearscm.com">
173   <input type="hidden" name="sitesearch" value="clearscm.com">
174   </div>
175   </form>
176   <!-- End: Search my site with Google -->
177 </div>
178 <br>
179 END;
180 } // search_box
181
182 function copyright ($start_year = "",
183                     $author     = "Andrew DeFaria",
184                     $email      = "info@clearscm.com",
185                     $home       = "") {
186   global $base;
187   global $base1;
188
189   $today        = getdate ();
190   $current_year = $today ["year"];
191
192   $this_file = $base1 . "/" . $_SERVER['PHP_SELF'];
193
194   $mod_time  = date ("F d Y @ g:i a", filemtime ($this_file));
195
196   print <<<END
197 <div id="foot"><p>
198   Last modified: $mod_time<br>
199   Copyright &copy;&nbsp;
200 END;
201
202   if ($start_year != "") {
203     print "$start_year-";
204   } // if
205
206 print <<<END
207 $current_year, ClearSCM Inc. - All rights reserved
208 </p></div>
209 END;
210 } // copyright
211
212 function get_file_from_cvs ($file,
213                             $machine    = "clearscm.com",
214                             $port       = ":8080",
215                             $path       = "/viewvc/clearscm.com/") {
216   $user     = "andrew";
217   $password = "airafed";
218   $url  = "http://$user:$password@$machine$port$path$file?view=co";
219
220   $contents = @file ($url)
221     or die ("$url not found");
222
223   return $contents;
224 } # get_file_from_cvs
225
226 function display_contents_as_code ($contents) {
227   print "<div class=code>";
228   print "<table id=listing cellspacing=0 cellpadding=2 border=0 width=90%>";
229
230   $line_number = 1;
231
232   foreach ($contents as $line) {
233     print "<tr>";
234     print "  <td id=line-number><a name=line_$line_number></a>" .
235       $line_number++ . "</td>";
236     print "  <td id=code><tt>";
237
238     for ($i = 0; $i < strlen ($line); $i++) {
239       if ($line [$i] == " ") {
240         if ($i == 0 && $line_number == 2) {
241           continue;
242         } // if
243         echo "&nbsp;";
244       } else if ($line [$i] == "\t") {
245         echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
246       } else if ($line [$i] != "\n") {
247         echo $line [$i];
248       } // if
249     } // for
250
251     print "</tt></td>";
252     print "</tr>\n";
253   } // foreach
254
255   print "</table>";
256   print "</div>";
257 } // display_contents_as_code
258
259 function display_contents_as_snippet ($contents) {
260   print "<div class=code>";
261
262   foreach ($code as $line) {
263     for ($i = 0; $i < strlen ($line); $i++) {
264       if ($line [$i] == " ") {
265         echo "&nbsp;";
266       } else if ($line [$i] == "\t") {
267         echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
268       } else if ($line [$i] != "\n") {
269         echo $line [$i];
270       } // if
271     } // for
272   } // foreach
273
274   print "</div>";
275 } // display_contents_as_snippet
276
277 function display_code ($file,
278                        $machine = "clearscm.com",
279                        $port    = ":8080",
280                        $path    = "/viewvc/clearscm.com/") {
281   display_contents_as_code (get_file_from_cvs ($file, $machine, $port, $path));
282 } # display_code
283
284 function cvs_man ($file,
285                   $machine      = "clearscm.com",
286                   $port         = ":8080",
287                   $path         = "/viewvc/clearscm.com/") {
288
289   $desc_spec = array (
290     0 => array ("pipe", "r"), // stdout
291     1 => array ("pipe", "w"), // stdin
292     2 => array ("pipe", "w"), // stderr
293   );
294
295   $pod2html = proc_open ("pod2html -cachedir /tmp -noindex -htmlroot=http://perldoc.perl.org", $desc_spec, $pipes);
296
297   if (!is_resource ($pod2html)) {
298     die ("Unable to start pod2html");
299   } // if
300
301   $stdin        = $pipes [0];
302   $stdout       = $pipes [1];
303   $stderr       = $pipes [2];
304
305   $contents = get_file_from_cvs ($file, $machine, $port, $path);
306
307   // Write to stdin
308   foreach ($contents as $line) {
309     fwrite ($stdin, $line);
310   } // foreach
311   fclose ($stdin);
312
313   $end_of_index         = 0;
314   $pre_just_ended       = 0;
315   $machine              = "clearscm.com";
316   $port                 = "";
317   $path                 = "/viewvc/clearscm.com/";
318   $url                  = "http://$machine$port$path$file?view=co";
319   $history              = "http://$machine$port$path$file";
320
321   // Now get the output and write it out
322   while (!feof ($stdout)) {
323     $line = fgets ($stdout);
324
325     if (preg_match ("/<!-- INDEX END -->/", $line)) {
326       $end_of_index = 1;
327       continue;
328     }
329
330     if (!$end_of_index) {
331       continue;
332     } // if
333
334     // Filter some CVS keywords properly
335     $line = preg_replace ("/\\\$Revision\:\s*(\S*)\s*\\\$/",
336                           "Revision <a href=\"$history\">$1</a>",
337                           $line);
338     $line = preg_replace ("/\\\$Date\:\s*(.*)\s*\\\$/",
339                           "Modifed $1",
340                           $line);
341     $line = preg_replace ("/\\\$RCSfile\:\s*(\S*),v\s*\\\$/",
342                           "$1",
343                           $line);
344
345     // Collapse adjacent <pre> sections to instead have a simple blank
346     // line
347     if (preg_match ("/<\/pre>$/", $line)) {
348       $line = preg_replace ("/<\/pre>/", "", $line);
349       print "$line\n";
350       $pre_just_ended = 1;
351       continue;
352     } // if
353
354     if (preg_match ("/^<pre>$/", $line)) {
355       if ($pre_just_ended) {
356         $pre_just_ended = 0;
357         continue;
358       } // if
359     } else {
360       if ($pre_just_ended) {
361         $pre_just_ended = 0;
362         echo "</pre></div>$line";
363         continue;
364       } // if
365     } // if
366
367     $line = preg_replace ("/<pre>/",
368                           "<div class=code><pre>",
369                           $line);
370     $line = preg_replace ("/<\/pre>/",
371                           "</pre></div>",
372                           $line);
373     $line = preg_replace ("/<a name=.*>(.*)<\/a>/",
374                           "$1",
375                           $line);
376     $line = preg_replace ("/NAME (\S*)<\/h1>/",
377                           "NAME $1 <a href=\"$url\"><img src=\"/Icons/Download.jpg\" border=0 title=Download></a></h1>",
378                           $line);
379     $line = preg_replace ("/NAME (\S*)<\/h2>/",
380                           "NAME $1 <a href=\"$url\"><img src=\"/Icons/Download.jpg\" border=0 title=Download></a></h2>",
381                           $line);
382     echo $line;
383   } // while
384
385   fclose ($stdout);
386
387   //while (!feof ($stderr)) {
388   //  echo fgets ($stderr) . "<br>";
389   //} // while
390
391   fclose ($stderr);
392
393   proc_close ($pod2html);
394 } // cvs_man
395 ?>