Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (is_readable(dirname(__FILE__).'/geshi/geshi.php')) {
- require_once(dirname(__FILE__).'/geshi/geshi.php');
- } elseif (is_readable(dirname(__FILE__).'/geshi.php')) {
- require_once(dirname(__FILE__).'/geshi.php');
- }elseif (is_readable('geshi.php')) {
- require_once('geshi.php');
- } else {
- die('Could not find geshi.php - make sure it is in your include path!');
- }
- function geshize_filter($courseid, $text)
- {
- global $CFG;
- if (!isset($CFG->filter_geshize)) {
- set_config( 'filter_geshize','');
- }
- preg_match_all('%<code(?:.*?lang="(\w*)".*?)*?>(.*?)</code>%si', $text, $results, PREG_PATTERN_ORDER);
- if(!empty($results[2]))
- {
- foreach($results[2] as $k => $strCode)
- {
- $strLang = empty($results[1][$k]) ? empty($CFG->filter_geshize_default_language) ? 'php' : $CFG->filter_geshi_default_language : trim($results[1][$k]);
- $strCode = trim($strCode);
- $geshi = new GeSHi($strCode, $strLang);
- $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
- $geshi->enable_classes();
- $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
- $geshi->set_overall_style('font-family: "Bitstream Vera Sans Mono", "Monaco", "Courier New", monospace; font-size: 9pt; color: white; border: 1px solid white; background-color: black; padding: 10px 10px 10px 10px;', false);
- $geshi->set_line_style('line-height: 1.3em; color: #003030;', 'font-weight: bold; color: #006060;', true);
- $geshi->set_code_style('color: #000020;', true);
- $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
- $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
- $geshi->set_footer_content('Parsed in <TIME> seconds at <SPEED>, using Moodle-Filter Geshize (c) by Robin Parker and GeSHi <VERSION>');
- $geshi->set_footer_content_style('font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
- $strReplace = '<!-- ========= BEGIN OF GESHI ================ -->' . PHP_EOL;
- $strReplace .= '<style type="text/css"><!--' . PHP_EOL . $geshi->get_stylesheet(true) . PHP_EOL .' --></style>';
- $strReplace .= '<div class="geshiBox">' . PHP_EOL;
- $strReplace .= $geshi->parse_code() . PHP_EOL;
- $strReplace .= '</div>' . PHP_EOL;
- $strReplace .= '<!-- ========= END OF GESHI ================ -->' . PHP_EOL;
- $text = str_replace($results[0][$k], $strReplace, $text);
- }
- }
- return $text;
- }
- ?>
Add Comment
Please, Sign In to add comment