Advertisement
Guest User

GeSHi best results

a guest
Aug 23rd, 2011
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.50 KB | None | 0 0
  1. /**
  2.     * Second parse code tag
  3.     */
  4.     function bbcode_second_pass_code($type, $code)
  5.     {
  6.         global $phpbb_root_path;
  7.         // when using the /e modifier, preg_replace slashes double-quotes but does not
  8.         // seem to slash anything else
  9.         $code = str_replace('\"', '"', $code);
  10. // ------------------------------------------------------------------------------------
  11.       // edited by jb (nebler.org)
  12.       // including geshi
  13.      
  14.       // geshipfad, relativ zum haupt-ordner (oder absolut (untested))
  15.       $geshi_path = $phpbb_root_path . 'includes/geshi/geshi.php';
  16.  
  17.         if (empty($type))
  18.         {
  19.             $code = str_replace("\t", '   ', $code);
  20.                 $code = str_replace('  ', '  ', $code);
  21.                 $code = str_replace('  ', '  ', $code);
  22.  
  23.                 // remove newline at the beginning
  24.                 if (!empty($code) && $code[0] == "\n")
  25.                 {
  26.                     $code = substr($code, 1);
  27.                 }
  28.         }
  29.         else if(!include_once( $geshi_path ) ) { // include = zur laufzeit, requier zum start
  30.             echo 'geshi n\'a pas pu être!';
  31.         } else
  32.         {
  33.             // Es kommt nicht ursprünglicher Code an ...
  34.             // hier die rückformatierung, vllt nicht schön aber selten ;)
  35.             // Not the english way ... steht irgendwo im quellcode :)
  36.             $astr_to = array('<', '>', '[', ']', '.', ':','"','&');
  37.             $astr_from = array('&lt;', '&gt;', '[', ']', '.', ':','&quot;', '&amp;');
  38.  
  39.             $code = str_replace($astr_from, $astr_to, $code);
  40.  
  41.             // binde geshi ein, siehe geshi-faq
  42.             // geshi Objekt erzeugen und code erzeuegn  
  43.             $geshi = new GeSHi( $code, $type );
  44.             // Zeilennummern aktivieren, besonderes highlght alle 5 Zeilen, siehe documentation von geshi
  45.             $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
  46.             // header type setzten, siehe documentation von geshi
  47.             $geshi->set_header_type(GESHI_HEADER_NONE);
  48.              
  49.             // code parsen und highlighten
  50.             $code = $geshi->parse_code();  
  51.          
  52.             // überflüssige <br /> entfernen
  53.             $code = str_replace( "\n", "\r", $code );                    
  54.         }
  55.         // ------------------------------------------------------------------------------------
  56.         $code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');
  57.  
  58.         return $code;
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement