<?php

$ID = '$Id: source.php 200 2004-05-07 12:19:09Z bb $';

// Idee aus den Kommentaren in
// http://ch.php.net/manual/en/function.highlight-file.php

class PrettyPrinter {

  // creates CSS-compliant XHTML

  function style(
    $html='#0000ff', $default='#0000BB', $keyword='#000080', $string='#b60033',
    $comment='#008000', $tag_open_close='#ffffcc'
  ) {
    return
"<style type=\"text/css\">
.code span.html { color: $html; }
.code span.def { color: $default; }
.code span.key { color: $keyword; font-weight: bold;}
.code span.str { color: $string; }
.code span.cmnt { color: $comment; }
.code span.tag { color: $default; background-color: $tag_open_close; }
</style>
";
  }

  function printFile($file) {

    $source = highlight_file($file, TRUE);

    // set up the substitution array
    $substitutions = Array(
      '<font color="' . ini_get('highlight.html') . '">' => '<span class="html">',
      '<font color="' . ini_get('highlight.default') . '">' => '<span class="def">',
      '<font color="' . ini_get('highlight.keyword') . '">' => '<span class="key">',
      '<font color="' . ini_get('highlight.string') . '">' => '<span class="str">',
      '<font color="' . ini_get('highlight.comment') . '">' => '<span class="cmnt">',
      '</font>' => '</span>',
      '<br />' => "\n",
      '' => '',
      '&nbsp;' => ' ',
      '&lt;?' => '<span class="tag">&lt;?</span>',
      '?&gt;' => '<span class="tag">?&gt;</span>'
    );

    $source = strtr($source, $substitutions);

    return '<pre class="code">' . $source . '</pre>';
  }
}

require '../app.inc.php';
require '../appmenu.inc.php';

$pp = new PrettyPrinter();
$src = str_replace('../', '', $_GET['src']);

$app = new Application("Quelltext von $src", $menu);
$app->head_add = $pp->style();

$app->header();

$file = "/home/bb/public_html/$src";
if (is_readable($file) && !is_dir($file))
  echo $pp->printFile($file), "\n\n";
else
  echo "<p>Datei $src nicht gefunden</p>\n\n";

$app->footer();
?>