<?php /* File that handles automagic syntax highlighting of this directory Used with following htaccess thingy: RewriteEngine On # Some people like to use ?plain instead of &plain RewriteCond %{QUERY_STRING} plain RewriteCond %{QUERY_STRING} !code RewriteRule ^(.+\..+) code.php?code=$1&plain RewriteCond %{QUERY_STRING} !code RewriteRule ^(.+\..+) code.php?code=$1 15.07.2010 By KilledWhale */ // If no file is given, there's nothing we can do if (!isset($_GET['code'])) { die(); } $code = realpath($_GET['code']); $path = realpath($_SERVER['document_root']); // Check that given path is a subdirectory if ($path !== substr($code, 0, strlen($path))) { die(); } // No peeking into .htaccess files :) if (substr($code, -9) == ".htaccess") { die(); } // Plain text because Esa94 wanted :) if (isset($_GET['plain'])) { header("Content-Type: text/plain;charset=utf-8"); die(file_get_contents("$code")); } require_once "../geshi/geshi.php"; // Syntax highlight setup $geshi = new GeSHi(); $geshi->load_from_file("$code"); //$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); //$geshi->set_header_type(GESHI_HEADER_PRE_TABLE); $geshi->enable_classes(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title><?php echo basename($code); ?></title> <style type="text/css"> <?php echo '<!--'; echo $geshi->get_stylesheet(); echo '-->'; ?> </style> </head> <body> <?php echo $geshi->parse_code(); ?> </body> </html>