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