header("Content-type: text/html; charset=utf-8");
//why stripslashes
$input = isset($_POST['input'])? ($_POST['input']) :
'//Example
public class Fibonacci {
public static long fib(int n) {
if (n <= 1) return n;
else return fib(n-1) + fib(n-2);
}
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
for (int i = 1; i <= N; i++)
System.out.println(i + ": " + fib(i));
}
}';
$bg = isset($_POST['color']) ? $_POST['color'] : 'fff';
$font = isset($_POST['font']) ? $_POST['font'] : '000';
$in_theme = isset($_POST['theme']) ? $_POST['theme'] : 'bclear';
file_put_contents('browse.log',sprintf("%s - %s - %s - %s\r\n",date(DATE_ATOM),$_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_USER_AGENT'],@$_SERVER['HTTP_REFERER']),FILE_APPEND);
include 'highlight_pipe.php';
$generator = new HighlightPipe;
$generator->input= $input;
$generator->hl_option['theme']= isset($_POST['theme']) ? $_POST['theme'] : 'bclear';
$generator->hl_option['syntax']= isset($_POST['syntax']) ? $_POST['syntax'] : 'java';
$generator->hl_option['linenumbers']= isset($_POST['line']) ? TRUE : FALSE;
$generator->hl_option['line-number-length']= 2;
$generator->hl_option['replace-tabs']= 4;
$generator->hl_option['reformat']= 'java';
//$generator->hl_option['enclose-pre']= FALSE;
$generator->hl_option['encoding']= 'UTF-8';
$result = $generator->getResult();
preg_match_all('/pre style="([^"]+?)font-size([^"]+?)"/',$result,$style);
$preStyle = $style[1][0];
$generator->hl_option['enclose-pre']= FALSE;
$result = $generator->getResult();
$code = '';
foreach(explode("\n",$result) as $row) {
//echo $row . '
';
//echo htmlspecialchars(preg_replace('/([^<][^ ]*)( +?)([^ ]*[^>])/', '$1@$3', $row)) . '
';
//echo preg_replace_callback('/>( *)(.*)( *)', 'space', $row) . '
';
$row = preg_replace_callback('/( *)(\d{1,3})( *)/','space',$row);
$code .= str_replace(' ',' ',$row) . '
';
}
//print $result;
function space($match) {
return str_repeat(' ', strlen($match[1])) . $match[2] . str_repeat(' ',strlen($match[3]));
}
?>