-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtools.php
344 lines (293 loc) · 7.02 KB
/
tools.php
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?php
define("GITHUB_URL", "https://github.com/sancus-tee");
define("TRAVIS_URL", "https://travis-ci.org/sancus-tee");
function doc_ref($id, $title = null)
{
if (empty($title))
$title = $id;
echo <<<EOF
<a href="doc.php#$id">$title</a>
EOF;
}
function instruction($name, $opcode)
{
echo <<<EOF
<h3>$name <small>$opcode</small></h3>
EOF;
}
function api_call($func)
{
echo <<<EOF
<p>Convenience wrapper:</p>
<pre class="prettyprint">
$func
</pre>
EOF;
}
function gen_navbar_entries()
{
global $navbar_links, $page_title;
foreach ($navbar_links as $title => $url)
{
echo "<li";
if ($title == $page_title)
echo " class=\"active\"";
echo "><a href=\"$url\">$title</a></li>\n";
}
}
function start_section_header($id)
{
global $sections;
$title = $sections[$id];
echo <<<EOF
<div class="page-header">
<h1 id="$id" class="section-header">
$title
EOF;
}
function end_section_header()
{
echo <<<EOF
</h1>
</div>
EOF;
}
function start_subsection_header($id)
{
global $sections;
$title = $sections[$id];
echo <<<EOF
<div class="page-header">
<h2 id="$id" class="subsection-header">
$title
EOF;
}
function end_subsection_header()
{
echo <<<EOF
</h2>
</div>
EOF;
}
function get_pub_opt($pub, $opt)
{
return isset($pub[$opt]) ? $pub[$opt] : null;
}
function publication_list($pubs)
{
if (!empty($pubs))
{
echo <<<EOF
<p class=research-par></p>
<div class=research-list>
<ul>
EOF;
foreach ($pubs as $pub)
{
$author = $pub["author"];
$title = $pub["title"];
$publisher = $pub["publisher"];
$date = $pub["date"];
$id = get_pub_opt($pub, "id");
$pdf = get_pub_opt($pub, "pdf");
$slides = get_pub_opt($pub, "slides");
$bibtex = get_pub_opt($pub, "bibtex");
$src = get_pub_opt($pub, "src");
$web = get_pub_opt($pub, "web");
$video = get_pub_opt($pub, "video");
echo <<<EOF
<li>$author. <strong>$title.</strong> <em>$publisher</em>, $date.
EOF;
if (!empty($pdf))
{
$url = ($pdf === true) ? "publications/$id.pdf" : $pdf;
echo <<<EOF
<a href=$url><img alt="pdf" src="icons/pdf.png"></a>
EOF;
}
if (!empty($slides))
{
$url = ($slides === true) ? "publications/$id-slides.pdf" : $slides;
echo <<<EOF
<a href=$url><img alt="slides" src="icons/slides.png"></a>
EOF;
}
if (!empty($bibtex))
{
$url = ($bibtex === true) ? "publications/$id.bib" : $bibtex;
echo <<<EOF
<a href=$url><img alt="bibtex" src="icons/bibtex.png"></a>
EOF;
}
if (!empty($src))
{
echo <<<EOF
<a href=$src><img alt="src" src="icons/src.png"></a>
EOF;
}
if (!empty($web))
{
$url = ($web === true) ? "$id" : $web;
echo <<<EOF
<a href=$url><img alt="web" src="icons/web.png"></a>
EOF;
}
if (!empty($video))
{
$url = ($video === true) ? "$id" : $video;
echo <<<EOF
<a href=$url><img alt="video" src="icons/video.png"></a>
EOF;
}
echo <<<EOF
</li>
EOF;
}
echo <<<EOF
</ul>
</div>
EOF;
}
}
function install_section($id, $downloads = null, $prereqs = null, $git=null)
{
start_section_header($id);
if (!empty($git))
{
$url=GITHUB_URL . "/" . $git;
echo <<<EOF
<small><a href=$url><img alt="src" src="icons/github-32px.png"></a></small>
EOF;
}
if (!empty($downloads))
{
echo <<<EOF
<div class="btn-group header-button">
<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">Download <span class="caret"></span></button>
<ul class="dropdown-menu">
EOF;
foreach ($downloads as $title => $url)
{
echo <<<EOF
<li><a href="downloads/$url">$title</a></li>
EOF;
}
echo <<<EOF
</ul>
</div>
EOF;
}
end_section_header();
if (empty($prereqs))
return;
echo <<<EOF
<table class="table table-bordered table-condensed prerequisites">
<caption>Prerequisites</caption>
<thead>
<tr>
<th>Name</th>
<th>Ubuntu package</th>
<th>Version</th>
</tr>
</thead>
<tbody>
EOF;
foreach ($prereqs as $prereq)
{
$class = $prereq["build"] ? "build-prereq" : "runtime-prereq";
$package_name = $prereq["package"];
if (empty($package_name))
{
$package = "N/A";
$note = isset($prereq["note"]) ? $prereq["note"] : null;
if (!empty($note))
$package .= $note;
}
else
$package = "<a href=\"apt:$package_name\">$package_name</a>";
$version = $prereq["version"];
if (empty($version))
$version = "N/A";
echo <<<EOF
<tr class="$class">
<td><a href="{$prereq["url"]}">{$prereq["name"]}</a></td>
<td>$package</td>
<td>$version</td>
</tr>
EOF;
}
echo <<<EOF
</tbody>
</table>
EOF;
}
function doc_section($id, $cmd = null, $install = null)
{
start_section_header($id);
if (!empty($cmd))
{
echo <<<EOF
<small>$cmd</small>
EOF;
}
if (!empty($install))
{
echo <<<EOF
<div class="btn-group header-button">
<a href="install.php#$install" class="btn btn-primary" >Install</a>
</div>
EOF;
}
end_section_header();
}
function example_section($id, $git=null, $travis=null)
{
start_section_header($id);
if (!empty($git))
{
$url=GITHUB_URL . "/" . $git;
echo <<<EOF
<small><a href=$url><img alt="src" src="icons/github-32px.png"></a></small>
EOF;
}
if (!empty($travis))
{
$url=TRAVIS_URL . "/" . $travis;
echo <<<EOF
<small><a href=$url><img alt="status" src="https://travis-ci.org/sancus-tee/sancus-examples.svg?branch=master"></a></small>
EOF;
}
end_section_header();
}
function research_section($id)
{
start_subsection_header($id);
end_subsection_header();
}
function display_source_file($file)
{
echo <<<EOF
<pre class="prettyprint">
<a href="code/$file" class="btn btn-primary src-button">$file</a>
EOF;
echo chop(htmlspecialchars(file_get_contents("code/$file")));
echo "</pre>\n";
}
function create_sancus_button($href, $lbl, $icon)
{
echo <<<EOF
<a href=$href class="btn btn-default sancus-btn" role="button">
$lbl <i class="fa fa-$icon" aria-hidden="true"></i></a>
EOF;
}
function create_sancus_objective($title, $icon, $text)
{
echo <<<EOF
<div class="col-sm-4 sancus-objective">
<span class="oi oi-$icon sancus-em"></span>
<h4>$title</h4>
<p>$text<p>
</div>
EOF;
}
?>