function source_highlighter($code)
{
    $source = str_replace(array("&gt;", "&lt;", "&quot;", "&amp;"), array(">", "<", "\"", "&"), $code[1]);
    if (false !== stristr($code[0], "[php]")) {
        $lang2geshi = "php";
    } elseif (false !== stristr($code[0], "[sql]")) {
        $lang2geshi = "sql";
    } elseif (false !== stristr($code[0], "[html]")) {
        $lang2geshi = "html4strict";
    } else {
        $lang2geshi = "txt";
    }
    $geshi = new GeSHi($source, $lang2geshi);
    $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
    $geshi->set_overall_style('font: normal normal 100% monospace; color: #000066;', false);
    $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
    $geshi->set_code_style('color: #000020;font-family:monospace; font-size:12px;line-height:6px;', true);
    //$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
    $geshi->enable_classes(false);
    $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
    $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
    $return = "<div class=\"codetop\">CODE</div><div class=\"codemain\">\n";
    $return .= $geshi->parse_code();
    $return .= "\n</div>\n";
    return $return;
}
function source_highlighter($source, $lang2geshi)
{
    require_once 'geshi/geshi.php';
    $source = str_replace(array("&#039;", "&gt;", "&lt;", "&quot;", "&amp;"), array("'", ">", "<", "\"", "&"), $source);
    $lang2geshi = $lang2geshi == 'html' ? 'html4strict' : $lang2geshi;
    $geshi = new GeSHi($source, $lang2geshi);
    $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
    $geshi->set_overall_style('font: normal normal 100% monospace; color: #000066;', false);
    $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
    $geshi->set_code_style('color: #000020;font-family:monospace; font-size:12px;line-height:13px;', true);
    $geshi->enable_classes(false);
    $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
    $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
    $return = "<div class=\"codetop\">Code</div><div class=\"codemain\">\n";
    $return .= $geshi->parse_code();
    $return .= "\n</div>\n";
    return $return;
}
/**
 * User handler for code block
 *
 * @param TexyHandlerInvocation  handler invocation
 * @param string  block type
 * @param string  text to highlight
 * @param string  language
 * @param TexyModifier modifier
 * @return TexyHtml
 */
function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
{
    if ($blocktype !== 'block/code') {
        return $invocation->proceed();
    }
    $texy = $invocation->getTexy();
    global $geshiPath;
    if ($lang == 'html') {
        $lang = 'html4strict';
    }
    $content = Texy::outdent($content);
    $geshi = new GeSHi($content, $lang, $geshiPath . 'geshi/');
    // GeSHi could not find the language
    if ($geshi->error) {
        return $invocation->proceed();
    }
    // do syntax-highlighting
    $geshi->set_encoding('UTF-8');
    $geshi->set_header_type(GESHI_HEADER_PRE);
    $geshi->enable_classes();
    $geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
    $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
    $geshi->set_code_style('color: #000020;', 'color: #000020;');
    $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
    $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
    // save generated stylesheet
    $texy->styleSheet .= $geshi->get_stylesheet();
    $content = $geshi->parse_code();
    // check buggy GESHI, it sometimes produce not UTF-8 valid code :-((
    $content = iconv('UTF-8', 'UTF-8//IGNORE', $content);
    // protect output is in HTML
    $content = $texy->protect($content, Texy::CONTENT_BLOCK);
    $el = TexyHtml::el();
    $el->setText($content);
    return $el;
}
Exemple #4
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the login screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
    // -------------------------------------------------------------------------
    // Variables
    // -------------------------------------------------------------------------
    $filename_extension = get_filename_extension($net2ftp_globals["entry"]);
    // ------------------------
    // Set the state2 variable depending on the file extension !!!!!
    // ------------------------
    if (getFileType($net2ftp_globals["entry"]) == "IMAGE") {
        $filetype = "image";
    } elseif ($filename_extension == "swf") {
        $filetype = "flash";
    } else {
        $filetype = "text";
    }
    // Form name, back and forward buttons
    $formname = "ViewForm";
    $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
    // Next screen
    $nextscreen = 2;
    // -------------------------------------------------------------------------
    // Text
    // -------------------------------------------------------------------------
    if ($filetype == "text") {
        // Title
        $title = __("View file %1\$s", $net2ftp_globals["entry"]);
        // ------------------------
        // geshi_text
        // ------------------------
        setStatus(2, 10, __("Reading the file"));
        $geshi_text = ftp_readfile("", $net2ftp_globals["directory"], $net2ftp_globals["entry"]);
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        // ------------------------
        // geshi_language
        // ------------------------
        $geshi_language = "";
        $list_language_extensions = array('html4strict' => array('html', 'htm'), 'javascript' => array('js'), 'css' => array('css'), 'php' => array('php', 'php5', 'phtml', 'phps'), 'perl' => array('pl', 'pm', 'cgi'), 'sql' => array('sql'), 'java' => array('java'), 'actionscript' => array('as'), 'ada' => array('a', 'ada', 'adb', 'ads'), 'apache' => array('conf'), 'asm' => array('ash', 'asm'), 'asp' => array('asp'), 'bash' => array('sh'), 'c' => array('c', 'h'), 'c_mac' => array('c'), 'caddcl' => array(), 'cadlisp' => array(), 'cpp' => array('cpp'), 'csharp' => array(), 'd' => array(''), 'delphi' => array('dpk'), 'diff' => array(''), 'email' => array('eml', 'mbox'), 'lisp' => array('lisp'), 'lua' => array('lua'), 'matlab' => array(), 'mpasm' => array(), 'nsis' => array(), 'objc' => array(), 'oobas' => array(), 'oracle8' => array(), 'pascal' => array('pas'), 'python' => array('py'), 'qbasic' => array('bi'), 'smarty' => array('tpl'), 'vb' => array('bas'), 'vbnet' => array(), 'vhdl' => array(), 'visualfoxpro' => array(), 'xml' => array('xml'));
        while (list($language, $extensions) = each($list_language_extensions)) {
            if (in_array($filename_extension, $extensions)) {
                $geshi_language = $language;
                break;
            }
        }
        // ------------------------
        // geshi_path
        // ------------------------
        $geshi_path = NET2FTP_APPLICATION_ROOTDIR . "/plugins/geshi/geshi/";
        // ------------------------
        // Call geshi
        // ------------------------
        setStatus(4, 10, __("Parsing the file"));
        $geshi = new GeSHi($geshi_text, $geshi_language, $geshi_path);
        $geshi->set_encoding(__("iso-8859-1"));
        $geshi->set_header_type(GESHI_HEADER_PRE);
        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
        //		$geshi->enable_classes();
        $geshi->set_overall_style('border: 2px solid #d0d0d0; background-color: #f6f6f6; color: #000066; padding: 10px;', true);
        $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
        $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
        $geshi->set_tab_width(4);
        $geshi_text = $geshi->parse_code();
    } elseif ($filetype == "image") {
        $title = __("View image %1\$s", htmlEncode2($net2ftp_globals["entry"]));
        $image_url = printPHP_SELF("view");
        $image_alt = __("Image") . $net2ftp_globals["entry"];
    } elseif ($filetype == "flash") {
        $title = __("View Macromedia ShockWave Flash movie %1\$s", htmlEncode2($net2ftp_globals["entry"]));
        $flash_url = printPHP_SELF("view");
    }
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
unset($ccount);
unset($matches);
include_once INCLUDES . "bbcodes/geshi/geshi.php";
preg_match_all("#\\[geshi=(.*?)\\](.*?)\\[/geshi\\]#si", $text, $matches, PREG_PATTERN_ORDER);
for ($i = 0; $i < count($matches[1]); $i++) {
    $lines = explode("\n", $matches[2][$i]);
    if (count($lines) < 200) {
        $input = str_replace('<br>', '', str_replace('<br  />', '', str_replace('<br />', '', stripslashes($matches[2][$i]))));
        //replace problematic characters
        $search = array("\\", "&quot;", "&#39;", "&#92;", "&quot;", "&#39;", "&lt;", "&gt;", "&amp;");
        $replace = array("\\\\", "\"", "'", "\\", "\"", "\\'", "<", ">", "&");
        $input = str_replace($search, $replace, $input);
        $geshi = new GeSHi($input, $matches[1][$i]);
        $geshi->set_header_type(GESHI_HEADER_PRE);
        $geshi->set_overall_style('font-family:\'Courier New\', Courier; font-size:12px;');
        $geshi->set_link_styles(GESHI_LINK, 'font-weight:bold;');
        $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
        $geshi->set_footer_content($locale['bb_geshi_info']);
        $geshi->set_footer_content_style('font-family:Verdana,Arial,sans-serif;color:#808080;font-size:9px;font-weight:bold;background-color:#f0f0ff;border-top: 1px solid #d0d0d0;padding:2px;width:400px');
        if (preg_match("/\\/forum\\//i", FUSION_REQUEST) && isset($data['post_id'])) {
            $geshi_save = "<a href='" . INCLUDES . "bbcodes/geshi_bbcode_save.php?thread_id=" . $_GET['thread_id'] . "&amp;post_id=" . $data['post_id'] . "&amp;code_id=" . $i . "'><img src='" . INCLUDES . "bbcodes/images/geshi_save.png' alt='" . $locale['bb_geshi_save'] . "' title='" . $locale['bb_geshi_save'] . "' style='border:none' /></a>&nbsp;&nbsp;";
        } else {
            $geshi_save = "";
        }
        $text = preg_replace("#\\[geshi=(.*?)\\](.*?)\\[/geshi\\]#si", '$2', $text);
        $text = str_replace($matches[2][$i], "<div class='tbl-border tbl2' style='width:400px'>" . $geshi_save . "<strong>GeSHi: " . $geshi->get_language_name() . "</strong></div><div class='tbl-border tbl1' style='width:400px;height:auto;white-space:nowrap;overflow:auto;background-color:#ffffff;'><code style='white-space:nowrap'>" . $geshi->parse_code() . "</code></div>", $text);
    } else {
        $ccount = substr_count($text, "[geshi=");
        for ($i = 0; $i < $ccount; $i++) {
            if (preg_match("/\\/forum\\//i", FUSION_REQUEST) && isset($data['post_id'])) {
Exemple #6
0
}
// Check file exists
if (!file_exists($path)) {
    exit("File not found ({$path}).");
}
// Prepare GeSHi instance
$geshi = new GeSHi();
$geshi->set_language('text');
$geshi->load_from_file($path);
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->enable_classes();
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
$geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
$geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
$geshi->set_code_style('color: #000020;', 'color: #000020;');
$geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
$geshi->set_header_content('Source code viewer - ' . $path . ' - ' . $geshi->get_language_name());
$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
$geshi->set_footer_content('Parsed in <TIME> seconds,  using GeSHi <VERSION>');
$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Source code viewer - <?php 
echo $path;
?>
 - <?php 
$geshi->get_language_name();
 /**
  * Style language
  *
  * @param array $subjects
  */
 function _styleSubjects($subjects)
 {
     // set overall style
     if (isset($subjects['view'])) {
         $this->geshi->set_overall_style($subjects['view'], $this->_invertOverwrite($subjects['view.']['overwrite']));
     }
     if (isset($subjects['view.']['container'])) {
         switch ($subjects['view.']['container']) {
             case 'none':
             case 'NONE':
             case 'None':
                 $this->geshi->set_header_type(GESHI_HEADER_NONE);
                 break;
             case 'div':
             case 'Div':
             case 'DIV':
                 $this->geshi->set_header_type(GESHI_HEADER_DIV);
                 break;
             case 'pre':
             case 'Pre':
             case 'PRE':
             default:
                 $this->geshi->set_header_type(GESHI_HEADER_PRE);
                 break;
         }
     }
     if (isset($subjects['view.']['tabwidth'])) {
         $this->geshi->set_tab_width(intval($subjects['view.']['tabwidth']));
     }
     // configure linenumbers
     if (isset($subjects['linenumbers'])) {
         $this->geshi->set_line_style($subjects['linenumbers'], isset($subjects['linenumbers.']['fancy']) ? $subjects['linenumbers.']['fancy'] : '', $this->_invertOverwrite($subjects['linenumbers.']['overwrite']));
     }
     // enable / disable linenumbers
     if (isset($subjects['linenumbers.']['enable'])) {
         $this->geshi->enable_line_numbers($subjects['linenumbers.']['enable']);
     }
     // configure code style
     if (isset($subjects['code'])) {
         $this->geshi->set_code_style($subjects['code'], $this->_invertOverwrite($subjects['code.']['overwrite']));
     }
     // configure escape
     if (isset($subjects['escape'])) {
         $this->geshi->set_escape_characters_style($subjects['escape'], $this->_invertOverwrite($subjects['escape.']['overwrite']));
     }
     // configure symbols
     if (isset($subjects['symbols'])) {
         $this->geshi->set_symbols_style($subjects['symbols'], $this->_invertOverwrite($subjects['symbols.']['overwrite']));
     }
     // configure strings
     if (isset($subjects['strings'])) {
         $this->geshi->set_strings_style($subjects['strings'], $this->_invertOverwrite($subjects['strings.']['overwrite']));
     }
     // configure numbers
     if (isset($subjects['numbers'])) {
         $this->geshi->set_numbers_style($subjects['numbers'], $this->_invertOverwrite($subjects['numbers.']['overwrite']));
     }
     // configure comment style
     if (isset($subjects['comments.'])) {
         foreach ($subjects['comments.'] as $key => $value) {
             if (strstr($key, '.') == false) {
                 $this->geshi->set_comments_style($key, $value, $this->_invertOverwrite($subjects['comments.'][$key . '.']['overwrite']));
             }
         }
     }
     // configure keywords style
     if (isset($subjects['keywords.'])) {
         foreach ($subjects['keywords.'] as $key => $value) {
             if (strstr($key, '.') == false) {
                 $this->geshi->set_keyword_group_style($key, $value, $this->_invertOverwrite($subjects['keywords.'][$key . '.']['overwrite']));
             }
         }
     }
     // enable / disable keyword links
     if (isset($subjects['keyword.']['links.']['enable'])) {
         $this->geshi->enable_keyword_links($subjects['keyword.']['links.']['enable']);
     }
     // configure keyword link styles
     if (isset($subjects['keyword.']['links'])) {
         $this->geshi->set_link_styles(GESHI_LINK, $subjects['keyword.']['links']);
     }
     if (isset($subjects['keyword.']['links.']['hover'])) {
         $this->geshi->set_link_styles(GESHI_HOVER, $subjects['keyword.']['links.']['hover']);
     }
     if (isset($subjects['keyword.']['links.']['active'])) {
         $this->geshi->set_link_styles(GESHI_ACTIVE, $subjects['keyword.']['links.']['active']);
     }
     if (isset($subjects['keyword.']['links.']['visited'])) {
         $this->geshi->set_link_styles(GESHI_VISITED, $subjects['keyword.']['links.']['visited']);
     }
     // configure keyword link target
     if (isset($subjects['keyword.']['links.']['target'])) {
         $this->geshi->set_link_target($subjects['keyword.']['links.']['target']);
     }
     // configure method styles
     if (isset($subjects['methods.'])) {
         foreach ($subjects['methods.'] as $key => $value) {
             if (strstr($key, '.') == false) {
                 $this->geshi->set_methods_style($key, $value, $this->_invertOverwrite($subjects['methods.'][$key . '.']['overwrite']));
             }
         }
     }
 }