1 | <?php |
---|
2 | /** |
---|
3 | * The Paper Tape Project -- Documentation |
---|
4 | * |
---|
5 | * This is a very small "template" like system that quickly wraps a design around any |
---|
6 | * *.htm file in the Paper-Tape-Project repository. It should handle links, etc. |
---|
7 | * well and works with PATH_INFO, typical calls are ".../index.php/path/to/file.htm". |
---|
8 | * There's a small menu nested as PHP array in this script. |
---|
9 | * |
---|
10 | * Use this small script as in the public domain. |
---|
11 | * 22.12.2008 -- Sven Koeppel |
---|
12 | **/ |
---|
13 | |
---|
14 | // where to get the file to display: Can be simply |
---|
15 | // $filename = $_SERVER['QUERY_STRING']; |
---|
16 | // or path info (advantage that links will work): |
---|
17 | $filename = substr($_SERVER['PATH_INFO'], 1); # strip trailing slash: /a/b => a/b |
---|
18 | |
---|
19 | // redirect to default page if no one is given: |
---|
20 | $default_page = 'documentation/start.htm'; |
---|
21 | if(empty($filename)) { header("Location: $_SERVER[PHP_SELF]/$default_page"); exit; } |
---|
22 | |
---|
23 | // check if filename is correct |
---|
24 | $jail_dir = realpath('../'); # don't display files higher than parental dir |
---|
25 | $file_path = realpath('../'.$filename); |
---|
26 | #var_dump(substr($file_path, -3, 3), $filename, $file_path, $jail_dir); |
---|
27 | if(0 !== strncmp($file_path, $jail_dir, strlen($jail_dir)) || |
---|
28 | substr($file_path, -3, 3) != 'htm') { |
---|
29 | // user want's display file higher than parental dir |
---|
30 | // or file is not a *.htm file |
---|
31 | // then Redirect to file! Apache will handle error ;-) |
---|
32 | header("Location: $_SERVER[SCRIPT_NAME]/../../$filename"); |
---|
33 | echo "Won't make file $filename beautiful\nRefering to that file...\n"; |
---|
34 | exit; |
---|
35 | } |
---|
36 | |
---|
37 | // parse file until <body> start.. |
---|
38 | $handle = @fopen("../$filename", 'r'); |
---|
39 | if(!$handle) { header("HTTP/1.0 403 Forbidden"); print "Must not open $filename\n."; exit; } |
---|
40 | while(!feof($handle)) { |
---|
41 | if(strpos(fgets($handle), "<body") !== false) |
---|
42 | break; |
---|
43 | } |
---|
44 | ?> |
---|
45 | <html> |
---|
46 | <head> |
---|
47 | <title>The Paper Tape Project</title> |
---|
48 | <link rel="stylesheet" href="../documentation/style.css" type="text/css"> |
---|
49 | <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> |
---|
50 | </head> |
---|
51 | <body> |
---|
52 | <h1> |
---|
53 | <a href="http://dev.technikum29.de/projekte/"><span>technikum29 Coding projects: </span></a> |
---|
54 | <strong>The Paper Tape Project</strong> |
---|
55 | </h1> |
---|
56 | <div id="navigation"> |
---|
57 | <?php |
---|
58 | |
---|
59 | $nav = array( |
---|
60 | # all URLs are taken relative to one subdir (e.g. documentation/). |
---|
61 | 'Start' => $default_page, |
---|
62 | 'Data' => 'daten/README.htm', |
---|
63 | 'Perl tools' => 'perl-tools/README.htm', |
---|
64 | 'Labeling and Fonts' => array( |
---|
65 | 'Generating Labels' => 'schriften/README.htm', |
---|
66 | 'Paper Tape Font Files' => 'schriften/font_files.htm' |
---|
67 | ), |
---|
68 | 'Visualisation' => 'visualisator/README.htm', |
---|
69 | 'Generating Paper Tapes online!' => 'web-frontend/' |
---|
70 | ); |
---|
71 | |
---|
72 | function print_nav($nav) { |
---|
73 | global $filename; |
---|
74 | print "<ul>"; foreach($nav as $name => $url) { |
---|
75 | echo "\t<li>"; |
---|
76 | if(is_array($url)) { |
---|
77 | print "<em>$name</em>\n"; print_nav($url); |
---|
78 | } else |
---|
79 | print $url == $filename ? "<strong>$name</strong>" : "<a href=\"../$url\">$name</a>"; |
---|
80 | echo "</li>\n"; |
---|
81 | } |
---|
82 | print "</ul>\n"; |
---|
83 | } |
---|
84 | print_nav($nav); |
---|
85 | ?> |
---|
86 | </div> |
---|
87 | <div id="content"> |
---|
88 | <?php |
---|
89 | fpassthru($handle); |
---|
90 | ?> |
---|
91 | </div> |
---|
92 | <hr/> |
---|
93 | <center> |
---|
94 | <a href="http://dev.technikum29.de">dev.technikum29.de</a> | |
---|
95 | <a href="http://dev.technikum29.de/websvn/listing.php?repname=paper-tape-project&path=%2F&sc=0">Paper-Tape-Project WebSVN</a> | |
---|
96 | <a href="http://koeppel.homeunix.org">koeppel.homeunix.org</a> |
---|
97 | </center> |
---|