Guest User

Untitled

a guest
Jun 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <?php
  2. if (is_readable(dirname(__FILE__).'/geshi/geshi.php')) {
  3. require_once(dirname(__FILE__).'/geshi/geshi.php');
  4. } elseif (is_readable(dirname(__FILE__).'/geshi.php')) {
  5. require_once(dirname(__FILE__).'/geshi.php');
  6. }elseif (is_readable('geshi.php')) {
  7. require_once('geshi.php');
  8. } else {
  9. die('Could not find geshi.php - make sure it is in your include path!');
  10. }
  11.  
  12. function geshize_filter($courseid, $text)
  13. {
  14. global $CFG;
  15.  
  16. if (!isset($CFG->filter_geshize)) {
  17. set_config( 'filter_geshize','');
  18. }
  19. preg_match_all('%<code(?:.*?lang="(\w*)".*?)*?>(.*?)</code>%si', $text, $results, PREG_PATTERN_ORDER);
  20. if(!empty($results[2]))
  21. {
  22. foreach($results[2] as $k => $strCode)
  23. {
  24. $strLang = empty($results[1][$k]) ? empty($CFG->filter_geshize_default_language) ? 'php' : $CFG->filter_geshi_default_language : trim($results[1][$k]);
  25. $strCode = trim($strCode);
  26. $geshi = new GeSHi($strCode, $strLang);
  27.  
  28. $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
  29. $geshi->enable_classes();
  30. $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
  31. $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);
  32.  
  33. $geshi->set_line_style('line-height: 1.3em; color: #003030;', 'font-weight: bold; color: #006060;', true);
  34. $geshi->set_code_style('color: #000020;', true);
  35. $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
  36. $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
  37.  
  38. $geshi->set_footer_content('Parsed in <TIME> seconds at <SPEED>, using Moodle-Filter Geshize (c) by Robin Parker and GeSHi <VERSION>');
  39. $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;');
  40.  
  41. $strReplace = '<!-- ========= BEGIN OF GESHI ================ -->' . PHP_EOL;
  42. $strReplace .= '<style type="text/css"><!--' . PHP_EOL . $geshi->get_stylesheet(true) . PHP_EOL .' --></style>';
  43. $strReplace .= '<div class="geshiBox">' . PHP_EOL;
  44. $strReplace .= $geshi->parse_code() . PHP_EOL;
  45. $strReplace .= '</div>' . PHP_EOL;
  46. $strReplace .= '<!-- ========= END OF GESHI ================ -->' . PHP_EOL;
  47. $text = str_replace($results[0][$k], $strReplace, $text);
  48. }
  49. }
  50. return $text;
  51. }
  52. ?>
Add Comment
Please, Sign In to add comment