Example #1
0
 /**
  * The callback function that prepares the code to be xhtml
  *
  * @access  public
  * @param   array   $code_information   Code Data(code and lang)
  * @return  string  XHTML code
  */
 function PrepareCode($code_information)
 {
     $code = $code_information[2];
     $lang = trim($code_information[1]);
     $lang = Jaws_UTF8::html_entity_decode($lang);
     $lang = preg_replace('/[\'\\"]/si', '', $lang);
     $lang = Jaws_UTF8::strtolower($lang);
     $valid_lang = array('php', 'actionscript', 'ada', 'apache', 'asm', 'asp', 'bash', 'applescript', 'caddcl', 'cadlisp', 'c', 'c#', 'cpp', 'css', 'delphi', 'ruby', 'html4strict', 'java', 'javascript', 'lisp', 'lua', 'nsis', 'oobas', 'pascal', 'perl', 'python', 'qbasic', 'sql', 'vb', 'visualfoxpro', 'xml');
     if (in_array($lang, $valid_lang)) {
         //For some fscking reason, geshi applied htmlentities again, so a &lt will be &lt
         $htmltable = get_html_translation_table(HTML_ENTITIES);
         foreach ($htmltable as $key => $value) {
             $code = str_replace(addslashes($value), $key, $code);
         }
         require_once JAWS_PATH . 'libraries/geshi/geshi.php';
         $geshi = new GeSHi($code, $lang, JAWS_PATH . 'libraries/geshi/geshi');
         $geshi->set_header_type(GESHI_HEADER_DIV);
         $geshi->enable_keyword_links(false);
         $new_code = $geshi->parse_code();
         $new_html = '<div class="code">' . $new_code . '</div>';
         //  $ndew_html = str_replace('<div>', '<div class="code">',
         //                                     str_replace('</div>', '</div>', $geshi->parse_code()));
         unset($geshi);
     } else {
         $new_html = "<code>\n";
         $new_html .= $code;
         $new_html .= "</code>\n";
     }
     return $new_html;
 }