<?php
    // you can change styles here, but youll have to regenerate vjass.css for the changes to apply
    
    //
    $link_target='_blank';
    $link_style='border-bottom: 0px none #0000ff; text-decoration: none;';
    $link_style_hover='border-bottom: 1px dotted #0000ff; text-decoration: none;';
    $link_style_active='border-bottom: 1px solid #0000ff; text-decoration: none;';
    $link_style_visited='border-bottom: 1px dashed #0000ff; text-decoration: none;';
    
    //
    $libraries_group_id=20;
    $libraries_style='color: #008080;';
    $libraries_case_sensitive=true;
    $libraries_url='http://deaod.de/{FNAME}.j';
    
    //
    $page_title='Viewing: <FILENAME>';
    
    //
    $header_content='<a target="_blank" href="/code/<FILE>">Download <FILENAME></a>';
    $header_style='border-bottom: 1px solid #808080; font-size: 10pt; font-family: sans-serif; padding: 5px';
    
    //
    $footer_content='Parsed using <a style="color:#999999;" href="http://qbnz.com/highlighter/">GeSHi</a> <VERSION> in <TIME> seconds.';
    $footer_style='border-top: 1px solid #808080; font-size: 8pt; font-family: sans-serif; padding: 5px; color: #999999;';
    
    //
    //
    //
    include_once 'geshi.php';
    
    $file=$_GET['file'];
    $filepath=explode('/', $file);
    $filename=$filepath[count($filepath)-1];
    $needle=array('<FILE>','<FILENAME>');
    $replace=array($file, $filename);
    $page_title=str_replace($needle, $replace, $page_title);
    $header_content=str_replace($needle, $replace, $header_content);
    $footer_content=str_replace($needle, $replace, $footer_content);
    $header='<div style="' . $header_style . '">' . $header_content . '</div>';
    $footer='<div style="' . $footer_style . '">' . $footer_content . '</div>';
    if (file_exists($file)) {
        $geshi = new GeSHi();
        $lang_array = array(
            'vjass' => array('j'),
            );
        $geshi->load_from_file($file, $lang_array);
        if ($geshi->error()!==false) {
            echo $geshi->error();
        }
        
        //
        $dh=opendir(dirname(__FILE__) . DIRECTORY_SEPARATOR);
        $libraries=array();
        while (false !== ($dfile = readdir($dh))) {
            if (is_file($dfile) && strpos( $dfile, '.')!==false) {
                $extension=explode('.', $dfile);
                if ($extension[count($extension)-1]=='j' && $filename!=$dfile) {
                    $libraries[]=substr($dfile, 0, -2);
                }
            }
        }
        $geshi->add_keyword_group($libraries_group_id, $libraries_style, $libraries_case_sensitive, $libraries);
        $geshi->set_url_for_keyword_group($libraries_group_id, $libraries_url);
        
        $geshi->set_link_target($link_target);
        $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
        $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
        $geshi->set_link_styles(GESHI_LINK, $link_style);
        $geshi->set_link_styles(GESHI_HOVER, $link_style_hover);
        $geshi->set_link_styles(GESHI_ACTIVE, $link_style_active);
        $geshi->set_link_styles(GESHI_VISITED, $link_style_visited);
        $geshi->enable_classes();
        $geshi->set_footer_content($footer);
        $geshi->set_header_content($header);
        //$css=$geshi->get_stylesheet(false);
        $code=$geshi->parse_code();
        echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
        echo '<html>';
        echo '<head>';
        echo '<title>' . $page_title . '</title>';
        echo '<link rel="stylesheet" type="text/css" href="/code/vjass.css">';
        echo '</head>';
        echo '<body>';
        echo $code;
        echo '</body>';
        echo '</html>';
    } else {
        echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
        echo '<html>';
        echo '<head>';
        echo '<title>Error 404</title>';
        echo '</head>';
        echo '<body><h1>The requested file could not be found!</h1></body>';
        echo '</html>';
    }
?>