source: projects/documentation/index.php @ 36

Last change on this file since 36 was 35, checked in by sven, 15 years ago

typos in the menu

File size: 6.4 KB
Line 
1<?php
2/**
3 * The Paper Tape Project -- Documentation
4 *
5 * This is a very small "template" like system that quickly wraps a design
6 * around almost every file (html,txt,source codes,...) in the Paper-Tape-Project
7 * repository.
8 * It should handle links, etc. well and works with PATH_INFO; typical calls are
9 * linke "path/to/documentation/index.php/path/to/file.htm".
10 * There's a small menu nested as PHP array in this script.
11 *
12 * Use this small script as in the public domain.
13 * 22.12.2008, 12.02.2009 -- Sven Koeppel
14 **/
15
16  // the web site root path, taken relatively to the
17  // global project path
18  $doc = 'documentation';
19
20  // where to get the file to display: Can be simply
21  // $filename = $_SERVER['QUERY_STRING'];
22  // or path info (advantage that links will work):
23  $filename = substr($_SERVER['PATH_INFO'], 1); # strip trailing slash: /a/b => a/b
24
25  // show default page if no one is given:
26  $default_page = $doc.'/start.htm';
27  #if(empty($filename)) { header("Location: $_SERVER[PHP_SELF]/$default_page"); exit; }
28  if(empty($filename)) $filename = $default_page;
29
30  // check if filename is correct
31  $jail_dir = realpath('../'); # don't display files higher than parental dir
32  $file_path = realpath('../'.$filename);
33  $extension = substr(strrchr($file_path, '.'),1);
34  $good_extensions = array('c', 'cpp', 'pl', 'htm', 'txt');
35
36  #var_dump($extension, $filename, $file_path, $jail_dir, $good_extensions, in_array($extension, $good_extensions)); exit();
37  if(0 !== strncmp($file_path, $jail_dir, strlen($jail_dir))
38     || !in_array($extension, $good_extensions)
39     || !is_readable('../'.$filename) ) {
40      // user want's display file higher than parental dir
41      // or file is not a nice file (like *.htm) or file is not
42      // readable, then Redirect to file! Apache will handle error ;-)
43      header("Location: $_SERVER[SCRIPT_NAME]/../../$filename");
44      echo "Won't make file $filename beautiful\nRefering to that file...\n";
45      exit;
46  }
47
48  // do a little bit lightweight caching:
49  // don't calculate etag since that's too expensive
50  $last_modified_time = max(
51      filemtime("../$filename"), filemtime($_SERVER['SCRIPT_FILENAME'])
52  ); 
53  #$etag = md5_file("../$filename");
54
55  header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT"); 
56  #header("Etag: $etag");
57
58  if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time) {
59     #|| trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
60     header("HTTP/1.1 304 Not Modified"); 
61     exit; 
62  }
63
64  // since PHP cannot initialize global variables on an intelligent way:
65  $exec_action = $extension=='htm' ? 'display_file' : 'syntax_highlight_file';
66
67  function display_file($filename) {
68      // display HTML file.
69      // parse file until <body> starts...
70      $handle = fopen("../$filename", 'r');
71      if(!$handle) { print "Error at opening $filename\n"; exit; }
72      while(!feof($handle)) {
73          if(strpos(fgets($handle), "<body") !== false)
74              break;
75      }
76      fpassthru($handle);
77  }
78
79  function syntax_highlight_file($filename) {
80      // syntax highlight some file
81      global $extension; // yes, this is bad.
82      echo "<h2>Contents of <code>$filename</code></h2>";
83      if($extension == 'txt') {
84          echo "<pre>";
85          readfile("../$filename");
86          echo "</pre>";
87      } else {
88          include_once('geshi.php');
89          $geshi = new GeSHi();
90          $geshi->load_from_file("../$filename");
91          $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
92          echo $geshi->parse_code();
93      }
94  }
95?>
96<html>
97<head>
98  <title>The Punched Paper Project / <?=$filename; ?></title>
99  <link rel="stylesheet" href="<?=$_SERVER['SCRIPT_NAME'].'/'.$doc; ?>/style.css" type="text/css">
100  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
101</head>
102<body>
103<div id="header">
104  <h1>The Punched Paper Project</h1>
105  <p class="subtitle">/<?=$filename; ?></p>
106  <a href="http://dev.technikum29.de/" class="powered-by"><img src="<?=$_SERVER['SCRIPT_NAME'].'/'.$doc; ?>/src/powered-by-icon.png" alt="technikum29 development zone"></a>
107</div>
108<div id="navigation">
109<?php
110
111 $nav = array(
112        #all URLs are taken relative to one subdir (e.g. documentation/).
113        'Start' => $default_page,
114        'The Paper Tape Project' => array(
115                'Start' => $doc.'/paper-tape-project.htm',
116                'Abstract' => array(
117                        'Subproject overview' => 'paper-tape/README.txt',
118                        'To Do' => 'paper-tape/TODO.txt',
119                        'Using Windows' => 'paper-tape/WINDOWS.txt',
120                ),
121                'Data' => 'paper-tape/daten/README.htm',
122                'Perl tools' => 'paper-tape/perl-tools/README.htm',
123                'Labeling and Fonts' => array(
124                        'Generating Labels' => 'paper-tape/schriften/README.htm',
125                        'Font Files' => 'paper-tape/schriften/font_files.htm'
126                ),
127                'Devices' => array(
128                        'Facit Tape Punch' => 'paper-tape/driver/FACIT-MANUAL.txt',
129                        'Ghielmetti Tape Reader' => 'paper-tape/reader/GHIELMETTI-MANUAL.txt'
130                ),
131                'Driver framework' => array(
132                        'Legacy reader documentation' => 'paper-tape/reader/README.txt',
133                        'Legacy puncher documentation' => 'paper-tape/puncher/README.txt',
134                        'Legacy old puncher documentation' => 'paper-tape/userspace-driver/README.txt'
135                ),
136                'Visualisation' => 'paper-tape/visualisator/README.htm',
137                'Web Frontend' => array(
138                        'Abstract' => 'paper-tape/web-frontend/README.txt',
139                        'Generating Paper Tapes online!' => 'paper-tape/web-frontend/'
140                )
141        ),
142        'The Punch Card Project' => array(
143                'Start' => $doc.'/punch-card.htm',
144                'Device Drivers' => array(
145                        'Overview' => 'punch-card/driver/README.htm',
146                        'Nixdorf 0377.01' => 'punch-card/driver/nixdorf-0377.01/README.htm'
147                )
148        ),
149        #'About' => $doc.'/about.htm'
150 );
151
152 function print_nav($nav) {
153    global $filename;
154    print "<ul>"; foreach($nav as $name => $url) {
155        echo "\t<li>";
156        if(is_array($url)) {
157           print "<em>$name</em>\n"; print_nav($url);
158        } else
159           print $url == $filename ? "<strong>$name</strong>" : "<a href=\"$_SERVER[SCRIPT_NAME]/$url\">$name</a>";
160        echo "</li>\n";
161    }
162    print "</ul>\n";
163 }
164 print_nav($nav);
165?>
166</div>
167<div id="content">
168<?php
169  call_user_func($exec_action, $filename);#, $exec_array);
170?>
171</div>
172<div id="footer">
173  Last modified: <?=date('r', $last_modified_time); ?>
174  <br/>
175  Further reading:
176  <a href="http://dev.technikum29.de">dev.technikum29.de</a> |
177  <a href="http://dev.technikum29.de/websvn/listing.php?repname=paper-tape-project&path=%2F&sc=0">Paper-Tape-Project WebSVN</a> |
178  <a href="http://koeppel.homeunix.org">koeppel.homeunix.org</a>
179</div>
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License