source: projects/documentation/index.php @ 30

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

Added new documentation as well as a great new layout and some new
features for the documentation system like syntax higlighting (using
geshi).
Furthermore much directory clean up and movements accross directories.

File size: 4.7 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 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  // the web site root path, taken relatively to the
15  // global project path
16  $doc = 'documentation';
17
18  // where to get the file to display: Can be simply
19  // $filename = $_SERVER['QUERY_STRING'];
20  // or path info (advantage that links will work):
21  $filename = substr($_SERVER['PATH_INFO'], 1); # strip trailing slash: /a/b => a/b
22
23  // redirect to default page if no one is given:
24  $default_page = $doc.'/start.htm';
25  if(empty($filename)) { header("Location: $_SERVER[PHP_SELF]/$default_page"); exit; }
26
27  // check if filename is correct
28  $jail_dir = realpath('../'); # don't display files higher than parental dir
29  $file_path = realpath('../'.$filename);
30  $extension = substr(strrchr($file_path, '.'),1);
31  $good_extensions = array('c', 'cpp', 'pl', 'htm', 'txt');
32
33  #var_dump($extension, $filename, $file_path, $jail_dir, $good_extensions, in_array($extension, $good_extensions)); exit();
34  if(0 !== strncmp($file_path, $jail_dir, strlen($jail_dir))
35     || !in_array($extension, $good_extensions)
36     || !is_readable('../'.$filename) ) {
37      // user want's display file higher than parental dir
38      // or file is not a nice file (like *.htm) or file is not
39      // readable, then Redirect to file! Apache will handle error ;-)
40      header("Location: $_SERVER[SCRIPT_NAME]/../../$filename");
41      echo "Won't make file $filename beautiful\nRefering to that file...\n";
42      exit;
43  }
44
45  // since PHP cannot initialize global variables on an intelligent way:
46  $exec_action = $extension=='htm' ? 'display_file' : 'syntax_highlight_file';
47
48  function display_file($filename) {
49      // display HTML file.
50      // parse file until <body> starts...
51      $handle = fopen("../$filename", 'r');
52      if(!$handle) { print "Error at opening $filename\n"; exit; }
53      while(!feof($handle)) {
54          if(strpos(fgets($handle), "<body") !== false)
55              break;
56      }
57      fpassthru($handle);
58  }
59
60  function syntax_highlight_file($filename) {
61      // syntax highlight some file
62      include_once('geshi.php');
63      $geshi = new GeSHi();
64      $geshi->load_from_file("../$filename");
65      $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
66      echo "<h2>Contents of <code>$filename</code></h2>";
67      echo $geshi->parse_code();
68  }
69?>
70<html>
71<head>
72  <title>The Punched Paper Project / <?=$filename; ?></title>
73  <link rel="stylesheet" href="<?=$_SERVER['SCRIPT_NAME'].'/'.$doc; ?>/style.css" type="text/css">
74  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
75</head>
76<body>
77<div id="header">
78  <h1>The Punched Paper Project</h1>
79  <p class="subtitle">/<?=$filename; ?></p>
80  <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>
81</div>
82<div id="navigation">
83<?php
84
85 $nav = array(
86        #all URLs are taken relative to one subdir (e.g. documentation/).
87        'Start' => $default_page,
88        'The Paper Tape Project' => array(
89                'Start' => $doc.'/paper-tape-project.htm',
90                'Data' => 'paper-tape/daten/README.htm',
91                'Perl tools' => 'paper-tape/perl-tools/README.htm',
92                'Labeling and Fonts' => array(
93                        'Generating Labels' => 'paper-tape/schriften/README.htm',
94                        'Paper Tape Font Files' => 'paper-tape/schriften/font_files.htm'
95                ),
96                'Visualisation' => 'paper-tape/visualisator/README.htm',
97                'Generating Paper Tapes online!' => 'paper-tape/web-frontend/'
98        ),
99        'The Punch Card Project' => array(
100                'Start' => $doc.'/punch-card.htm'
101        ),
102        //'About' => $doc.'/about.htm'
103 );
104
105 function print_nav($nav) {
106    global $filename;
107    print "<ul>"; foreach($nav as $name => $url) {
108        echo "\t<li>";
109        if(is_array($url)) {
110           print "<em>$name</em>\n"; print_nav($url);
111        } else
112           print $url == $filename ? "<strong>$name</strong>" : "<a href=\"$_SERVER[SCRIPT_NAME]/$url\">$name</a>";
113        echo "</li>\n";
114    }
115    print "</ul>\n";
116 }
117 print_nav($nav);
118?>
119</div>
120<div id="content">
121<?php
122  call_user_func($exec_action, $filename);#, $exec_array);
123?>
124</div>
125<div id="footer">
126  Further reading:
127  <a href="http://dev.technikum29.de">dev.technikum29.de</a> |
128  <a href="http://dev.technikum29.de/websvn/listing.php?repname=paper-tape-project&path=%2F&sc=0">Paper-Tape-Project WebSVN</a> |
129  <a href="http://koeppel.homeunix.org">koeppel.homeunix.org</a>
130</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