Právě prohlížíš: parser.php
Zpět do složkyStáhnout
  1. <?php
  2. if(!isset($_GET["file"])||!file_exists($_GET["file"])) {
  3. header("Content-Type: text/plain; charset=utf8");
  4. if(!empty($_GET["file"])) {
  5. include "readfile.php";
  6. }
  7. die("Specify a file, please.");
  8. }
  9.  
  10. //Language by extension (c++ and c are alike)
  11. $languages = array(
  12. "js" => "javascript",
  13. "c" => "cpp",
  14. "cs" => "csharp",
  15. "h" => "cpp",
  16. "ino"=> "cpp",
  17. "hpp"=> "cpp",
  18. "php"=> "php"
  19. );
  20. //Find extension
  21. $type = getExtension($_GET["file"]);
  22. //Download the file rather than parse
  23. if(isset($_GET["dl"])) {
  24. $texttype = "plain";
  25.  
  26. if(isset($languages[$type])) {
  27. $texttype = $languages[$type];
  28. }
  29.  
  30. header("Content-Type: text/$texttype; charset=utf-8");
  31. header("Content-Length: ".filesize($_GET["file"]));
  32. header("Content-Disposition: attachment; filename=\"{$_GET["file"]}\"");
  33. readfile($_GET["file"]);
  34. }
  35.  
  36.  
  37.  
  38.  
  39. //Clean buiffers
  40. /*while(@ob_end_clean());
  41. ob_implicit_flush(true);
  42. ob_start(); */
  43.  
  44. //Debug timing to find out why it takes so long...
  45. include "Timer.class.php";
  46. $t = new Timer;
  47. //Record start time
  48. $t("init");
  49.  
  50. header("Content-Type: text/html; charset=utf-8");
  51.  
  52.  
  53.  
  54. $lang = "";
  55. if(isset($languages[$type]))
  56. $lang = $languages[$type];
  57. else
  58. $lang = $type;
  59. //Define, whether a cache file can be loaded, assume not
  60. $cache=false;
  61. //Define cache file name
  62. define("CACHENAME","cache/".str_replace("/","__",$_GET['file']));
  63.  
  64. $t("parsing");
  65.  
  66.  
  67. //Check if there is any cache we can use
  68. //If so, skip parsing
  69. if(!file_exists(CACHENAME)||filemtime($_GET['file'])>filemtime(CACHENAME)) {
  70. //die("Can't parse now");
  71. require "geshi.php";
  72. $g = new GeSHi(file_get_contents($_GET["file"]),$lang);
  73. $g->enable_classes();
  74. $g->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
  75.  
  76. $g->set_overall_style('font: normal normal 90% monospace; color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', false);
  77.  
  78. $g->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
  79. $g->set_code_style('color: #000020;', true);
  80.  
  81. $g->set_link_styles(GESHI_LINK, 'color: #000060;');
  82. $g->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
  83.  
  84. $g->set_footer_content('Parsed using <a href="http://qbnz.com/highlighter/">GeSHi <VERSION></a> at <TIME>');
  85. $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;');
  86. if(!is_dir("cache"))
  87. mkdir("cache");
  88. //Save data into a file
  89. file_put_contents(CACHENAME,$g->parse_code());
  90. //Also cache CSS file for this language
  91. if(!file_exists("css/$lang.css")) {
  92. if(!is_dir("css"))
  93. mkdir("css");
  94. file_put_contents("css/$lang.css",$g->get_stylesheet(true));
  95. }
  96. }
  97. else {
  98. //$code = file_get_contents("cache/{$_GET['file']}");
  99. //So... cache exist so we may load it
  100.  
  101. $cache=true;
  102. //I tried to output the file directly from here - didn't help
  103. //readfile(CACHENAME);
  104. //exit;
  105. }
  106. $t("html");
  107.  
  108. function getExtension() {
  109. //Parse file name (get extension)
  110. $type = explode(".",$_GET["file"]);
  111. return $type[count($type)-1];
  112. }
  113. ?>
  114. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  115. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  116. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  117. <head>
  118. <title>Source of <?php echo $_GET["file"]; if($cache) echo " [cached]";?></title>
  119. <link rel="stylesheet" href="http://u8.8u.cz/code/css/<?php echo $lang;?>.css" />
  120. <style type="text/css">
  121. <!--
  122. /* <endora> */
  123.  
  124. html {
  125. background-color: #f0f0f0;
  126. padding:0px;
  127. margin: 0px;
  128. }
  129. body {
  130. font-family: Verdana, Arial, sans-serif;
  131. margin: 0px;
  132. border: 2px solid #e0e0e0;
  133. background-color: #fcfcfc;
  134. padding: 5px;
  135. }
  136. h2 {
  137. margin: .1em 0 .2em .5em;
  138. border-bottom: 1px solid #b0b0b0;
  139. color: #b0b0b0;
  140. font-weight: normal;
  141. font-size: 150%;
  142. }
  143. h3 {
  144. margin: .1em 0 .2em .5em;
  145. color: #b0b0b0;
  146. font-weight: normal;
  147. font-size: 120%;
  148. }
  149. #footer {
  150. text-align: center;
  151. font-size: 80%;
  152. color: #a9a9a9;
  153. }
  154. #footer a {
  155. color: #9999ff;
  156. }
  157. textarea {
  158. border: 1px solid #b0b0b0;
  159. font-size: 90%;
  160. color: #333;
  161. margin-left: 20px;
  162. }
  163. select, input {
  164. margin-left: 20px;
  165. }
  166. p {
  167. font-size: 90%;
  168. margin-left: .5em;
  169. }
  170.  
  171.  
  172. div.header {
  173. margin-top: 5px;
  174. }
  175. div.info1 {
  176. float: left;
  177.  
  178. }
  179. div.buttons {
  180. float:right;
  181. padding-right: 50px;
  182. }
  183. div.buttons a {
  184. background-color: #CCCCE0;
  185. border: 1px solid #AAA;
  186. padding: 5px;
  187. margin: 5px;
  188. border-radius: 5px;
  189. color: white;
  190. font-weight: bold;
  191. text-decoration: none;
  192. }
  193. div.buttons a:hover {
  194. background-color: #93AAFF;
  195. }
  196. div.buttons a:active {
  197. background-color: white;
  198. border-color: blue;
  199. color: #3B73FF;
  200. }
  201. div.header, div.clear {
  202. clear: both;
  203. }
  204.  
  205.  
  206. div#display {
  207. margin:0px;
  208. padding:0px;
  209. }
  210. -->
  211. </style>
  212. </head>
  213. <body>
  214. <div class="header">
  215. <div class="info1">Právě prohlížíš: <tt><?php echo $_GET["file"];?></tt> </div>
  216. <div class="buttons"><a href="./">Zpět do složky</a><a href="?dl">Stáhnout</a></div>
  217. <div class="clear"></div>
  218. </div>
  219. <div id="display">
  220.  
  221. </div>
  222.  
  223. <?php
  224. //flush();
  225. //ob_flush();
  226.  
  227. $t("output");
  228. readfile(CACHENAME);
  229. $t("over");
  230. echo PHP_EOL." <!--\n Parse time: {$t["parsing-html"]}\n";
  231. echo " Output time: {$t["output-over"]}\n";
  232. echo " All time: {$t["init-over"]}\n";
  233. echo "\n -->"
  234. ?>
  235. <script type="text/javascript">
  236.  
  237. </script>
  238. </body>
  239. </html>
Parsed using GeSHi 1.0.8.11 at 0.072