function _highlight_code($contents, $language, $line_number, $inline_code) { $contents = htmlspecialchars_decode($contents); if (strtolower($language) == 'bbcode') { import('content/parser/bbcode_highlighter'); $bbcode_highlighter = new BBCodeHighlighter(); $bbcode_highlighter->set_content($contents, PARSER_DO_NOT_STRIP_SLASHES); $bbcode_highlighter->parse($inline_code); $contents = $bbcode_highlighter->get_content(DO_NOT_ADD_SLASHES); } elseif (strtolower($language) == 'tpl' || strtolower($language) == 'template') { import('content/parser/template_highlighter'); require_once PATH_TO_ROOT . '/kernel/framework/content/geshi/geshi.php'; $template_highlighter = new TemplateHighlighter(); $template_highlighter->set_content($contents, PARSER_DO_NOT_STRIP_SLASHES); $template_highlighter->parse($line_number ? GESHI_NORMAL_LINE_NUMBERS : GESHI_NO_LINE_NUMBERS, $inline_code); $contents = $template_highlighter->get_content(DO_NOT_ADD_SLASHES); } elseif ($language != '') { require_once PATH_TO_ROOT . '/kernel/framework/content/geshi/geshi.php'; $Geshi = new GeSHi($contents, $language); if ($line_number) { $Geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); } if ($inline_code) { $Geshi->set_header_type(GESHI_HEADER_NONE); } $contents = '<pre style="display:inline;">' . $Geshi->parse_code() . '</pre>'; } else { $highlight = highlight_string($contents, true); $font_replace = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $highlight); $contents = preg_replace('`color="(.*?)"`', 'style="color:$1"', $font_replace); } return $contents; }
/** * @desc Highlights a content in a supported language using the appropriate syntax highlighter. * The highlighted languages are numerous: actionscript, asm, asp, bash, c, cpp, csharp, css, d, delphi, fortran, html, * java, javascript, latex, lua, matlab, mysql, pascal, perl, php, python, rails, ruby, sql, text, vb, xml, * PHPBoost templates and PHPBoost BBCode. * @param string $contents Content to highlight * @param string $language Language name * @param bool $line_number Indicate whether or not the line number must be added to the code. * @param bool $inline_code Indicate if the code is multi line. */ private static function highlight_code($contents, $language, $line_number, $inline_code) { $contents = TextHelper::htmlspecialchars_decode($contents); //BBCode PHPBoost if (strtolower($language) == 'bbcode') { $bbcode_highlighter = new BBCodeHighlighter(); $bbcode_highlighter->set_content($contents); $bbcode_highlighter->parse($inline_code); $contents = $bbcode_highlighter->get_content(); } elseif (strtolower($language) == 'tpl' || strtolower($language) == 'template') { require_once PATH_TO_ROOT . '/kernel/lib/php/geshi/geshi.php'; $template_highlighter = new TemplateHighlighter(); $template_highlighter->set_content($contents); $template_highlighter->parse($line_number ? GESHI_NORMAL_LINE_NUMBERS : GESHI_NO_LINE_NUMBERS, $inline_code); $contents = $template_highlighter->get_content(); } elseif (strtolower($language) == 'plain') { $plain_code_highlighter = new PlainCodeHighlighter(); $plain_code_highlighter->set_content($contents); $plain_code_highlighter->parse(); $contents = $plain_code_highlighter->get_content(); } elseif ($language != '') { require_once PATH_TO_ROOT . '/kernel/lib/php/geshi/geshi.php'; $Geshi = new GeSHi($contents, $language); if ($line_number) { $Geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); } //No container if we are in an inline tag if ($inline_code) { $Geshi->set_header_type(GESHI_HEADER_NONE); } $contents = '<pre style="display:inline;">' . $Geshi->parse_code() . '</pre>'; } else { $highlight = highlight_string($contents, true); $font_replace = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $highlight); $contents = preg_replace('`color="(.*?)"`', 'style="color:$1"', $font_replace); } return $contents; }