<?php
if (!defined('goahead_hl_php'))
	die('na');

$mod = '';
if ($ext == 'sh') $mod = 'bash';
if ($ext == 'py') $mod = 'python';
if ($ext == 'vpy') $mod = 'python';
if ($ext == 'cpp') $mod = 'c';
if ($ext == 'c') $mod = 'c';
if ($ext == 'pl') $mod = 'perl';
if ($ext == 'lua') $mod = 'lua';
if ($ext == 'bat') $mod = 'batch';
if ($ext == 'ps1') $mod = 'powershell';
if ($ext == 'patch') $mod = 'diff';
if ($ext == 'txt') $mod = 'txt';
if ($ext == 'go') $mod = 'go';
if ($ext == 'js') $mod = 'js';
if ($ext == 'ipxe') $mod = 'bash';
if ($ext == 'ahk') $mod = 'autohotkey';
if ($name == 'Dockerfile') $mod = 'bash';
if ($name == 'Makefile') $mod = 'bash';

if ($mod == '')
	die('you broke it');

$plain = $_SERVER['REQUEST_URI'];
$plain = str_replace("/?", "/", $plain);

//echo "<pre><code class=\"{$ext}\">\n";
echo "<a class=\"dlcode\" href=\"$plain\">💾 download plaintext</a>\n";
echo "<pre><code class=\"language-{$mod} line-numbers\">";

$r1 = ['&','<','>'];
$r2 = ['&amp;','&lt;','&gt;'];

$code = file_get_contents($dirpath);
$code = str_replace($r1, $r2, $code);
$code = str_replace("\n", "\r\n", $code);
$code = str_replace("\r\r\n", "\r\n", $code);
echo($code);

echo "</code></pre>\n";

echo "<link rel=\"stylesheet\" href=\"/.fim/prism/{$mod}.css\" />\n";
echo "<link rel=\"stylesheet\" href=\"/.fim/hl.css\" />\n";
echo "<script src=\"/.fim/prism/{$mod}.js\"></script>\n";
die();

echo "<link rel=\"stylesheet\" href=\"/.fim/hl/s/monokai-sublime.css\" />\n";
echo "<script src=\"/.fim/hl.js\"></script>\n";
//echo "<script src=\"/.fim/hl/l/{$mod}.js\"></script>\n";
echo "<script>hljs.initHighlightingOnLoad();</script>\n";
die();
