source: projects/documentation/index.php @ 31

Last change on this file since 31 was 31, checked in by sven, 11 years ago

Improved documentation (navigation linking)

File size: 5.6 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  // redirect to 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
29  // check if filename is correct
30  $jail_dir = realpath('../'); # don't display files higher than parental dir
31  $file_path = realpath('../'.$filename);
32  $extension = substr(strrchr($file_path, '.'),1);
33  $good_extensions = array('c', 'cpp', 'pl', 'htm', 'txt');
34
35  #var_dump($extension, $filename, $file_path, $jail_dir, $good_extensions, in_array($extension, $good_extensions)); exit();
36  if(0 !== strncmp($file_path, $jail_dir, strlen($jail_dir))
37     || !in_array($extension, $good_extensions)
38     || !is_readable('../'.$filename) ) {
39      // user want's display file higher than parental dir
40      // or file is not a nice file (like *.htm) or file is not
41      // readable, then Redirect to file! Apache will handle error ;-)
42      header("Location: $_SERVER[SCRIPT_NAME]/../../$filename");
43      echo "Won't make file $filename beautiful\nRefering to that file...\n";
44      exit;
45  }
46
47  // since PHP cannot initialize global variables on an intelligent way:
48  $exec_action = $extension=='htm' ? 'display_file' : 'syntax_highlight_file';
49
50  function display_file($filename) {
51      // display HTML file.
52      // parse file until <body> starts...
53      $handle = fopen("../$filename", 'r');
54      if(!$handle) { print "Error at opening $filename\n"; exit; }
55      while(!feof($handle)) {
56          if(strpos(fgets($handle), "<body") !== false)
57              break;
58      }
59      fpassthru($handle);
60  }
61
62  function syntax_highlight_file($filename) {
63      // syntax highlight some file
64      global $extension; // yes, this is bad.
65      echo "<h2>Contents of <code>$filename</code></h2>";
66      if($extension == 'txt') {
67          echo "<pre>";
68          readfile("../$filename");
69          echo "</pre>";
70      } else {
71          include_once('geshi.php');
72          $geshi = new GeSHi();
73          $geshi->load_from_file("../$filename");
74          $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
75          echo $geshi->parse_code();
76      }
77  }
78?>
79<html>
80<head>
81  <title>The Punched Paper Project / <?=$filename; ?></title>
82  <link rel="stylesheet" href="<?=$_SERVER['SCRIPT_NAME'].'/'.$doc; ?>/style.css" type="text/css">
83  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
84</head>
85<body>
86<div id="header">
87  <h1>The Punched Paper Project</h1>
88  <p class="subtitle">/<?=$filename; ?></p>
89  <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>
90</div>
91<div id="navigation">
92<?php
93
94 $nav = array(
95        #all URLs are taken relative to one subdir (e.g. documentation/).
96        'Start' => $default_page,
97        'The Paper Tape Project' => array(
98                'Start' => $doc.'/paper-tape-project.htm',
99                'Abstract' => array(
100                        'Subproject overview' => 'paper-tape/README.txt',
101                        'To Do' => 'paper-tape/TODO.txt',
102                        'Using Windows' => 'paper-tape/WINDOWS.txt',
103                ),
104                'Data' => 'paper-tape/daten/README.htm',
105                'Perl tools' => 'paper-tape/perl-tools/README.htm',
106                'Labeling and Fonts' => array(
107                        'Generating Labels' => 'paper-tape/schriften/README.htm',
108                        'Font Files' => 'paper-tape/schriften/font_files.htm'
109                ),
110                'Devices' => array(
111                        'Facit Tape Punch' => 'paper-tape/driver/FACIT-MANUAL.txt',
112                        'Ghielmetti Tape Reader' => 'paper-tape/reader/GHIELMETTI-MANUAL.txt'
113                ),
114                'Driver framework' => array(
115                        'Legacy reader documentation' => 'paper-tape/reader/README.txt',
116                        'Legacy puncher documentation' => 'paper-tape/puncher/README.txt',
117                        'Legacy old puncher documentation' => 'paper-tape/userspace-driver/README.txt'
118                ),
119                'Visualisation' => 'paper-tape/visualisator/README.htm',
120                'Web Frontend' => array(
121                        'Abstract' => 'paper-tape/web-frontend/README.txt',
122                        'Generating Paper Tapes online!' => 'paper-tape/web-frontend/'
123                )
124        ),
125        'The Punch Card Project' => array(
126                'Start' => $doc.'/punch-card.htm'
127        ),
128        #'About' => $doc.'/about.htm'
129 );
130
131 function print_nav($nav) {
132    global $filename;
133    print "<ul>"; foreach($nav as $name => $url) {
134        echo "\t<li>";
135        if(is_array($url)) {
136           print "<em>$name</em>\n"; print_nav($url);
137        } else
138           print $url == $filename ? "<strong>$name</strong>" : "<a href=\"$_SERVER[SCRIPT_NAME]/$url\">$name</a>";
139        echo "</li>\n";
140    }
141    print "</ul>\n";
142 }
143 print_nav($nav);
144?>
145</div>
146<div id="content">
147<?php
148  call_user_func($exec_action, $filename);#, $exec_array);
149?>
150</div>
151<div id="footer">
152  Further reading:
153  <a href="http://dev.technikum29.de">dev.technikum29.de</a> |
154  <a href="http://dev.technikum29.de/websvn/listing.php?repname=paper-tape-project&path=%2F&sc=0">Paper-Tape-Project WebSVN</a> |
155  <a href="http://koeppel.homeunix.org">koeppel.homeunix.org</a>
156</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