<?php
header("Content-Type: text/plain; charset=utf8"); if(!empty($_GET["file"])) { include "readfile.php";
}
die("Specify a file, please."); }
//Language by extension (c++ and c are alike)
"js" => "javascript",
"c" => "cpp",
"cs" => "csharp",
"h" => "cpp",
"ino"=> "cpp",
"hpp"=> "cpp",
"php"=> "php"
);
//Find extension
$type = getExtension($_GET["file"]);
//Download the file rather than parse
$texttype = "plain";
if(isset($languages[$type])) { $texttype = $languages[$type];
}
header("Content-Type: text/$texttype; charset=utf-8"); header("Content-Disposition: attachment; filename=\"{$_GET["file"]}\""); }
//Clean buiffers
/*while(@ob_end_clean());
ob_implicit_flush(true);
ob_start(); */
//Debug timing to find out why it takes so long...
include "Timer.class.php";
$t = new Timer;
//Record start time
$t("init");
header("Content-Type: text/html; charset=utf-8");
$lang = "";
if(isset($languages[$type])) $lang = $languages[$type];
else
$lang = $type;
//Define, whether a cache file can be loaded, assume not
$cache=false;
//Define cache file name
$t("parsing");
//Check if there is any cache we can use
//If so, skip parsing
//die("Can't parse now");
require "geshi.php";
$g->enable_classes();
$g->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
$g->set_overall_style('font: normal normal 90% monospace; color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', false);
$g->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
$g->set_code_style('color: #000020;', true);
$g->set_link_styles(GESHI_LINK, 'color: #000060;');
$g->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
$g->set_footer_content('Parsed using <a href="http://qbnz.com/highlighter/">GeSHi <VERSION></a> at <TIME>');
$g->set_footer_content_style('font-family: sans-serif; color: #808080; font-size: 50%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
//Save data into a file
//Also cache CSS file for this language
}
}
else {
//$code = file_get_contents("cache/{$_GET['file']}");
//So... cache exist so we may load it
$cache=true;
//I tried to output the file directly from here - didn't help
//readfile(CACHENAME);
//exit;
}
$t("html");
function getExtension() {
//Parse file name (get extension)
$type = explode(".",$_GET["file"]); return $type[count($type)-1]; }
?>
<!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" xml:lang="en" lang="en">
<head>
<title>Source of <?php echo $_GET["file"]; if($cache) echo " [cached]";?></title>
<link rel="stylesheet" href="http://u8.8u.cz/code/css/<?php echo $lang;?>.css" />
<style type="text/css">
<!--
/* <endora> */
html {
background-color: #f0f0f0;
padding:0px;
margin: 0px;
}
body {
font-family: Verdana, Arial, sans-serif;
margin: 0px;
border: 2px solid #e0e0e0;
background-color: #fcfcfc;
padding: 5px;
}
h2 {
margin: .1em 0 .2em .5em;
border-bottom: 1px solid #b0b0b0;
color: #b0b0b0;
font-weight: normal;
font-size: 150%;
}
h3 {
margin: .1em 0 .2em .5em;
color: #b0b0b0;
font-weight: normal;
font-size: 120%;
}
#footer {
text-align: center;
font-size: 80%;
color: #a9a9a9;
}
#footer a {
color: #9999ff;
}
textarea {
border: 1px solid #b0b0b0;
font-size: 90%;
color: #333;
margin-left: 20px;
}
select, input {
margin-left: 20px;
}
p {
font-size: 90%;
margin-left: .5em;
}
div.header {
margin-top: 5px;
}
div.info1 {
float: left;
}
div.buttons {
float:right;
padding-right: 50px;
}
div.buttons a {
background-color: #CCCCE0;
border: 1px solid #AAA;
padding: 5px;
margin: 5px;
border-radius: 5px;
color: white;
font-weight: bold;
text-decoration: none;
}
div.buttons a:hover {
background-color: #93AAFF;
}
div.buttons a:active {
background-color: white;
border-color: blue;
color: #3B73FF;
}
div.header, div.clear {
clear: both;
}
div#display {
margin:0px;
padding:0px;
}
-->
</style>
</head>
<body>
<div class="header">
<div class="info1">Právě prohlížíš: <tt><?php echo $_GET["file"];?></tt> </div>
<div class="buttons"><a href="./">Zpět do složky</a><a href="?dl">Stáhnout</a></div>
<div class="clear"></div>
</div>
<div id="display">
</div>
<?php
//flush();
//ob_flush();
$t("output");
$t("over");
echo PHP_EOL." <!--\n Parse time: {$t["parsing-html"]}\n";
echo " Output time: {$t["output-over"]}\n";
echo " All time: {$t["init-over"]}\n";
echo "\n -->"
?>
<script type="text/javascript">
</script>
</body>
</html>