aboutsummaryrefslogtreecommitdiffhomepage
path: root/html/functions.php3
blob: 5a86984cfa39dfbc73effdbed1907358b32bf4fb (plain)
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
<?php

/* PHP3 Functions for Proof General Web Pages
 *
 * David Aspinall, June 1999.
 *
 * $Id$
 *
 */

/* Some handy constants */

$pg_email = "proofgen@dcs.ed.ac.uk";
$pg_list = "proofgeneral@dcs.ed.ac.uk";

$pg_title = "Proof General --- Organize your Proofs!";

function mlink($addr) {
  print "<a href=\"mailto:" . $addr . "\">" . $addr . "</a>";
}

function pg_email() {
  mlink("proofgen@dcs.ed.ac.uk");
}


/* Style sheet element for dt doesnt work in
   Netscape, so hack it here.
*/

function dt($string) {
  print "<dt><div style=\"font-style:italic; font-weight: bold\">";
  print $string;
  print "</div></dt>";
}

/* Automatic footnotes? */
/* FIXME: for now, just inline them. */

function footnote ($text) {
   print "<small><i><p>[" . $text . "]</p></small></i>";
}

/* A hyper-link with optional mouse over text.
   Could be made more sophisticated to do roll-overs, 
   or whatever.
*/

function hlink ($url,$text,$mouseover="") {
  print "<a href=\"" . $url . "\"";
  if ($mouseover != "") {
	print " onMouseOver=\"window.status='" . $mouseover . "'; return true;\"";
  };
  print ">" . $text . "</a>";
}

/* Determining download sizes (print broken message if file not found) */

function download_size($filename) {
   if (file_exists($filename)) {
	$size = filesize($filename);
        $sizek = (int) ($size/1024);
   	print " (";
   	if ($sizek == 0) {
	     print $size . " bytes)";
   	} else {
	     print $sizek . "k)";
   	}
   } else {
	print " (link broken)";
   }
}

function download_link($filename,$linkname = "") {
   print "<a href=\"" . $filename . "\">";
   if ($linkname == "") { 
	print $filename;
   } else {
	print $linkname;
   };
   print "</a>";
   print download_size($filename);
}

function date_modified($filename) {
   $time = filemtime($filename);
   if ($time) {
	print "Last modified " . strftime("%d %B %Y",$time) . ".\n";
   }
}

/* Nav bar separator */

$separator  =  ' <img src="images/bullethole.gif" alt="." align=top> ';

/* A link to one of the main pages (must appear in navbar menu) */

function link_root($page,$text) {
    print  "<a  href=\"index.phtml?page=" . $page . "\">";
    print $text;
    print "</a>\n";
}

function small_header($title) {
  include('smallheader.phtml'); 
  print "<h1>" . $title . "</h1>\n</td>\n</table>\n";
}

/* FIXME: improve this function */

function footer($filemodified=".") {
  include('footer.phtml'); 
  date_modified($filemodified);
  print "</address>\n";
  print "</body>\n";
  print "</font>\n";  /* Naughty stuff for older browsers, shouldn't do if V4 */
  print "</html>\n";
}

function click_to_go_back() {
  print "<p>\nClick <a href=\"index.phtml\">here</a> to go back to the Proof General front page.</p>\n";
}

/* Link to a marked up file */
/* NB: could determine type automatically! */

function fileshow($filename,$text="",$title="") {
 if ( $text == "") { $text=$filename; };
 $message=$title;
 if ( $message == "") { $message=$filename; };
 hlink("fileshow.phtml?file=" . urlencode($filename)
       . "&title=" . urlencode($title),
	$text, $message);
}


/* Similar for html file (NB: could pick automatically) */

function htmlshow($filename,$text="",$title="") {
 if ( $text == "") { $text=$filename; };
 $message=$title;
 $urlbits = parse_url($filename);
 if ( $message == "") { $message=$filename; };
 hlink("htmlshow.phtml?file=" . urlencode($urlbits["path"])
       . "&title=" . urlencode($title) 
       . ($urlbits["fragment"]=="" ? "" : "#" . $urlbits["fragment"]),
	$text, $message);
}


/* Markup plain text file, by escaping < and > */

function markup_plain_text($filename) {
  $file = file($filename);
  for($i = 0;$i < count($file);$i++) {
     $line = $file[$i];
     $line = ereg_replace("<","&lt;",$line);
     $line = ereg_replace(">","&gt;",$line);
     print $line;
  };
}

/* Hack an html file to be shown with our style sheet
   and hack relative links to go via htmlshow.phtml. 
   This isn't particularly robust, but seems to work for
   the output of texi2html.
*/

function hack_html($filename,$title="")  {
  if ($title=="") { $title=$filename; };
  $file = file($filename);
  /* Paste style sheet in head */
  for($i = 0;$i < count($file);$i++) {
     $line = $file[$i];
     if (eregi("</HEAD>",$line)) {
        /* Paste in style sheet */
	print "<style type=\"text/css\">\n<!--";
	include("proofgen.css");
	print "-->\n</style>\n";
        /* End style sheet paste in */
        print $line;
	break;
     } else { print $line; };
  }
  /* Now parse rest of document, hacking relative links. */
  /* Matching here is not great, will get confused by html tags inside strings, etc. */
  for (;$i < count($file);$i++)  {
     $line = $file[$i];
       /* PHP has no way to get the match position, so we have to 
	  match a suffix of the line, add extra parenthesis, and calculate it. */
     while (eregi("(<A([^>]*)(HREF=\"([^\"]+)\")(.*))",$line,$linebits)) { 
       /* found URL in a particularly simple form */
       $matchpos = strlen($line) - strlen($linebits[1]);
       print substr($line,0,$matchpos);		/* start of line */
       $line = $linebits[5];			/* rest of line after link */
       $urlbits = parse_url($linebits[4]);
       if ($urlbits["host"]=="") { 
	  /* Assume a relative link, let's hack it. */
	  $newurl = "htmlshow.phtml?file=" 
	    . urlencode(dirname($filename)) . "/" 
	    . $urlbits["path"] 
	    . ($urlbits["fragment"]=="" ? "" : "#" . $urlbits["fragment"]);
	  print "<A " . $linebits[2] . " HREF=\"" . $newurl . "\"";
	} else { print "<A " . $linebits[2] . $linebits[3]; }
     };
     /* Hack on a header and footer */
     if (eregi("<BODY>",$line)) { 
       /* Assume there's nothing else interesting on the line, whoops. */
       small_header("");
       print $line;
     } elseif (eregi("</BODY>",$line)) {
       /* Assume there's nothing else interesting on the line, whoops. */
       click_to_go_back();
       print $line;
     } else {
       print $line;
     };
  }
}