Source for dblsaiko.net and knifepoint.net
<?php

parse_str($_SERVER['QUERY_STRING'], $query);

$root = $_SERVER['DOCUMENT_ROOT'];
$req = $_SERVER['DOCUMENT_URI'];

$highlight = false;

if (isset($query['hl'])) {
  $highlight = intval($query['hl']) != 0;
} else {
  $ua = $_SERVER['HTTP_USER_AGENT'];
  if (
    preg_match('/MSIE/i', $ua) ||
    preg_match('/Firefox/i', $ua) ||
    preg_match('/OPR/i', $ua) ||
    preg_match('/Chrome/i', $ua) ||
    preg_match('/Safari/i', $ua) ||
    preg_match('/Netscape/i', $ua) ||
    preg_match('/Edge/i', $ua) ||
    preg_match('/Trident/i', $ua) ||
    preg_match('/NetSurf/i', $ua) ||
    preg_match('/SerenityOS/i', $ua)
  ) {
    $highlight = true;
  }
}

if ($highlight) {
  header('Content-Type: text/html');

  echo "<!DOCTYPE HTML>\n<html>\n<head>\n";
  echo '<title>' . basename($req) . "</title>\n";
  echo '<style>' . shell_exec("pygmentize -S pastie -f html") . "</style>\n";
  echo "</head>\n";
  echo "<body>[<a href=\"?hl=0\">raw/download</a>]\n<hr>\n";

  $output = shell_exec('pygmentize -f html ' . escapeshellarg("$root/$req"));
  if ($output == '') {
    $output = shell_exec('pygmentize -l text -f html ' . escapeshellarg("$root/$req"));
  }
  echo $output;

  echo '</body></html>';
} else {
  $ct = mime_content_type("$root/$req");
  header("Content-Type: $ct");
  echo file_get_contents("$root/$req");
}