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