Exemplo n.º 1
0
function jabFormatCode($code)
{
    @(include_once "geshi-1.0.8.6/geshi/geshi.php");
    if (function_exists('geshi_highlight')) {
        // Strip off language specifier
        $language = null;
        if (preg_match("/^{{(.*)}}\n+/", $code, $matches)) {
            $language = $matches[1];
            $code = preg_replace("/^{{(.*)}}\n+/", "", $code);
        }
        global $jab;
        if ($language == null && isset($jab['syntax_language'])) {
            $language = $jab['syntax_language'];
        }
        if ($language !== null) {
            $geshi = new GeSHi($code, $language, null);
            $geshi->set_header_type(GESHI_HEADER_NONE);
            $geshi->line_ending = "\n";
            $geshi->set_comments_style(1, 'color: #008200;');
            $geshi->set_comments_style('MULTI', 'color: #008200;');
            $geshi->set_strings_style('color: #848200');
            $geshi->set_numbers_style('');
            return "<pre><code>" . $geshi->parse_code() . "</code></pre>";
        }
    }
    return "<pre><code>" . htmlspecialchars($code, ENT_NOQUOTES) . "</code></pre>";
}
Exemplo n.º 2
0
	$geshi->set_numbers_highlighting(false); 	
	$geshi->set_overall_style('color: rgb(0,0,0); border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
	// Note the use of set_code_style to revert colours...
	$geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: black;', 'font-weight: bold; color: blue;', true);

	//for methods 
	$geshi->set_methods_style(1, "color: black;", false);
	
	//for multi-line comments /**/
	$geshi->set_comments_style('MULTI','color: rgb(63,127,95); font-style: code;', false);

	//for 'import' keyword
//	$geshi->set_comments_style(2,'color: rgb(127,0,85); font-weight: bold;', false);

	//for string constants
	$geshi->set_strings_style('color: rgb(42,0,255);', true);

	//for links (standard classes, etc.)
	$geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
	$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');

	//for keywords
	$geshi->set_keyword_group_style(1,'color: rgb(127,0,85); font-weight: bold;', false);
	$geshi->set_keyword_group_style(2,'color: rgb(127,0,85); font-weight: bold;', false); 
	$geshi->set_keyword_group_style(4,'color: rgb(127,0,85); font-weight: bold;', false); 
	
	//new keyword group for 'package'
//	$geshi->add_keyword_group(5, 'color: rgb(127,0,85); font-weight: bold;', true, array('package', 'import'));

	$geshi->set_header_content('SVNKit API examlpe: '.$fileName);
	$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
 /**
  * Style language
  *
  * @param array $subjects
  */
 function _styleSubjects($subjects)
 {
     // set overall style
     if (isset($subjects['view'])) {
         $this->geshi->set_overall_style($subjects['view'], $this->_invertOverwrite($subjects['view.']['overwrite']));
     }
     if (isset($subjects['view.']['container'])) {
         switch ($subjects['view.']['container']) {
             case 'none':
             case 'NONE':
             case 'None':
                 $this->geshi->set_header_type(GESHI_HEADER_NONE);
                 break;
             case 'div':
             case 'Div':
             case 'DIV':
                 $this->geshi->set_header_type(GESHI_HEADER_DIV);
                 break;
             case 'pre':
             case 'Pre':
             case 'PRE':
             default:
                 $this->geshi->set_header_type(GESHI_HEADER_PRE);
                 break;
         }
     }
     if (isset($subjects['view.']['tabwidth'])) {
         $this->geshi->set_tab_width(intval($subjects['view.']['tabwidth']));
     }
     // configure linenumbers
     if (isset($subjects['linenumbers'])) {
         $this->geshi->set_line_style($subjects['linenumbers'], isset($subjects['linenumbers.']['fancy']) ? $subjects['linenumbers.']['fancy'] : '', $this->_invertOverwrite($subjects['linenumbers.']['overwrite']));
     }
     // enable / disable linenumbers
     if (isset($subjects['linenumbers.']['enable'])) {
         $this->geshi->enable_line_numbers($subjects['linenumbers.']['enable']);
     }
     // configure code style
     if (isset($subjects['code'])) {
         $this->geshi->set_code_style($subjects['code'], $this->_invertOverwrite($subjects['code.']['overwrite']));
     }
     // configure escape
     if (isset($subjects['escape'])) {
         $this->geshi->set_escape_characters_style($subjects['escape'], $this->_invertOverwrite($subjects['escape.']['overwrite']));
     }
     // configure symbols
     if (isset($subjects['symbols'])) {
         $this->geshi->set_symbols_style($subjects['symbols'], $this->_invertOverwrite($subjects['symbols.']['overwrite']));
     }
     // configure strings
     if (isset($subjects['strings'])) {
         $this->geshi->set_strings_style($subjects['strings'], $this->_invertOverwrite($subjects['strings.']['overwrite']));
     }
     // configure numbers
     if (isset($subjects['numbers'])) {
         $this->geshi->set_numbers_style($subjects['numbers'], $this->_invertOverwrite($subjects['numbers.']['overwrite']));
     }
     // configure comment style
     if (isset($subjects['comments.'])) {
         foreach ($subjects['comments.'] as $key => $value) {
             if (strstr($key, '.') == false) {
                 $this->geshi->set_comments_style($key, $value, $this->_invertOverwrite($subjects['comments.'][$key . '.']['overwrite']));
             }
         }
     }
     // configure keywords style
     if (isset($subjects['keywords.'])) {
         foreach ($subjects['keywords.'] as $key => $value) {
             if (strstr($key, '.') == false) {
                 $this->geshi->set_keyword_group_style($key, $value, $this->_invertOverwrite($subjects['keywords.'][$key . '.']['overwrite']));
             }
         }
     }
     // enable / disable keyword links
     if (isset($subjects['keyword.']['links.']['enable'])) {
         $this->geshi->enable_keyword_links($subjects['keyword.']['links.']['enable']);
     }
     // configure keyword link styles
     if (isset($subjects['keyword.']['links'])) {
         $this->geshi->set_link_styles(GESHI_LINK, $subjects['keyword.']['links']);
     }
     if (isset($subjects['keyword.']['links.']['hover'])) {
         $this->geshi->set_link_styles(GESHI_HOVER, $subjects['keyword.']['links.']['hover']);
     }
     if (isset($subjects['keyword.']['links.']['active'])) {
         $this->geshi->set_link_styles(GESHI_ACTIVE, $subjects['keyword.']['links.']['active']);
     }
     if (isset($subjects['keyword.']['links.']['visited'])) {
         $this->geshi->set_link_styles(GESHI_VISITED, $subjects['keyword.']['links.']['visited']);
     }
     // configure keyword link target
     if (isset($subjects['keyword.']['links.']['target'])) {
         $this->geshi->set_link_target($subjects['keyword.']['links.']['target']);
     }
     // configure method styles
     if (isset($subjects['methods.'])) {
         foreach ($subjects['methods.'] as $key => $value) {
             if (strstr($key, '.') == false) {
                 $this->geshi->set_methods_style($key, $value, $this->_invertOverwrite($subjects['methods.'][$key . '.']['overwrite']));
             }
         }
     }
 }
Exemplo n.º 4
0
 private function code($string)
 {
     $code = array('4cs', '6502acme', '6502kickass', '6502tasm', '68000devpac', 'abap', 'actionscript', 'actionscript3', 'ada', 'algol68', 'apache', 'applescript', 'apt_sources', 'arm', 'asm', 'asp', 'asymptote', 'autoconf', 'autohotkey', 'autoit', 'avisynth', 'awk', 'bascomavr', 'bash', 'basic4gl', 'bf', 'bibtex', 'blitzbasic', 'bnf', 'boo', 'c', 'caddcl', 'cadlisp', 'cfdg', 'cfm', 'chaiscript', 'cil', 'clojure', 'cmake', 'cobol', 'coffeescript', 'cpp-qt', 'cpp', 'csharp', 'css', 'cuesheet', 'c_loadrunner', 'c_mac', 'd', 'dcl', 'dcpu16', 'dcs', 'delphi', 'diff', 'div', 'dos', 'dot', 'e', 'ecmascript', 'eiffel', 'email', 'epc', 'erlang', 'euphoria', 'f1', 'falcon', 'fo', 'fortran', 'freebasic', 'freeswitch', 'fsharp', 'gambas', 'gdb', 'genero', 'genie', 'gettext', 'glsl', 'gml', 'gnuplot', 'go', 'groovy', 'gwbasic', 'haskell', 'haxe', 'hicest', 'hq9plus', 'html4strict', 'html5', 'icon', 'idl', 'ini', 'inno', 'intercal', 'io', 'j', 'java', 'java5', 'javascript', 'jquery', 'kixtart', 'klonec', 'klonecpp', 'latex', 'lb', 'ldif', 'lisp', 'llvm', 'locobasic', 'logtalk', 'lolcode', 'lotusformulas', 'lotusscript', 'lscript', 'lsl2', 'lua', 'm68k', 'magiksf', 'make', 'mapbasic', 'matlab', 'mirc', 'mmix', 'modula2', 'modula3', 'mpasm', 'mxml', 'mysql', 'nagios', 'netrexx', 'newlisp', 'nsis', 'oberon2', 'objc', 'objeck', 'ocaml-brief', 'ocaml', 'octave', 'oobas', 'oorexx', 'oracle11', 'oracle8', 'oxygene', 'oz', 'parasail', 'parigp', 'pascal', 'pcre', 'per', 'perl', 'perl6', 'pf', 'php-brief', 'php', 'pic16', 'pike', 'pixelbender', 'pli', 'plsql', 'postgresql', 'povray', 'powerbuilder', 'powershell', 'proftpd', 'progress', 'prolog', 'properties', 'providex', 'purebasic', 'pycon', 'pys60', 'python', 'q', 'qbasic', 'rails', 'rebol', 'reg', 'rexx', 'robots', 'rpmspec', 'rsplus', 'ruby', 'sas', 'scala', 'scheme', 'scilab', 'sdlbasic', 'smalltalk', 'smarty', 'spark', 'sparql', 'sql', 'stonescript', 'systemverilog', 'tcl', 'teraterm', 'text', 'thinbasic', 'tsql', 'typoscript', 'unicon', 'upc', 'urbi', 'uscript', 'vala', 'vb', 'vbnet', 'vedit', 'verilog', 'vhdl', 'vim', 'visualfoxpro', 'visualprolog', 'whitespace', 'whois', 'winbatch', 'xbasic', 'xml', 'xorg_conf', 'xpp', 'yaml', 'z80', 'zxbasic');
     /*
      * Loop throught each available programming languages
      */
     foreach ($code as $highlight) {
         // using regex is worth to save some lines :)
         preg_match_all('/\\[' . $highlight . '\\].*?\\[\\/' . $highlight . '\\]/s', $string, $out);
         if (!empty($out[0])) {
             foreach ($out[0] as $multi) {
                 $no_tag = preg_replace('/\\[\\/?.*\\]/', '', $multi);
                 $geshi = new GeSHi($no_tag, $highlight);
                 $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
                 $geshi->set_overall_style('background: #414141;width:100%;');
                 $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
                 $geshi->set_case_keywords(GESHI_CAPS_LOWER);
                 $geshi->set_symbols_style('color: white;', false, 1);
                 $geshi->set_symbols_style('color: #B3F9FF;', false, 2);
                 $geshi->set_methods_style(1, 'color: white;');
                 $geshi->set_strings_style('color: yellow;', false, 'HARD');
                 $geshi->set_strings_style('color: yellow;', false);
                 $geshi->set_numbers_style('color: #FF80E5;');
                 $geshi->set_escape_characters_style('color: #FF80E5;');
                 $geshi->set_regexps_style(1, 'color: white;');
                 $geshi->set_regexps_style(0, 'color: white;');
                 $geshi->set_keyword_group_style(1, 'color: #FF8B8B;', true);
                 $geshi->set_keyword_group_style(2, 'color: #B3F9FF;', true);
                 $geshi->set_keyword_group_style(3, 'color: #B3F9FF;', true);
                 $geshi->set_keyword_group_style(4, 'color: #B3F9FF;', true);
                 $geshi->set_keyword_group_style(5, 'color: #B3F9FF;', true);
                 $geshi->set_keyword_group_style(6, 'color: #B3F9FF;', true);
                 $string = str_replace($multi, $geshi->parse_code(), $string);
             }
         }
     }
     return $string;
 }
Exemplo n.º 5
0
  +----------------------------------------------------------------------+
*/
if ($_SERVER["argc"] < 3) {
    exit("Purpose: Syntax highlight PHP examples in XSLT generated manual.\r\n" . 'Usage: highlight.php [ "xml" | "php" ] [ filename.ext | dir | wildcard ] ...' . "\r\n");
}
set_time_limit(5 * 60);
// can run long, but not more than 5 minutes
ini_set("error_reporting", E_ALL);
// kill the E_STRICT warnings in GeSHi under PHP 5
require dirname(__FILE__) . '/geshi/geshi.php';
$geshi = new GeSHi('', 'php', dirname(__FILE__) . '/geshi/geshi');
$geshi->set_tab_width(4);
$geshi->set_overall_class('phpcode');
$geshi->set_overall_style('font-size: 85%', true);
$geshi->set_symbols_highlighting(false);
$geshi->set_strings_style('color: green', true);
$geshi->set_keyword_group_style(1, 'color: #d09010; font-weight: bold', true);
$geshi->set_numbers_style('color: #aa0000; font-weight: bold', true);
$geshi->set_methods_style('color: black; font-style: italic', true);
$geshi->set_regexps_style(0, 'color: #004090', true);
// use this to get updated stylesheet info if changed via abovementioned API
// file_put_contents('style.css', $geshi->get_stylesheet());
function callback_html_number_entities_decode($matches)
{
    return chr($matches[1]);
}
function callback_highlight_php($matches)
{
    $with_tags = trim(html_entity_decode($matches[1]));
    global $geshi;
    $geshi->set_language('php');
    private function get_queries()
    {
        global $wpdb;
        if (QUERY_CACHE_TYPE_OFF) {
            $wpdb->query('SET SESSION query_cache_type = 0;');
        }
        $html = '';
        if ($wpdb->queries) {
            $total_time = timer_stop(FALSE, 22);
            $total_query_time = 0;
            $class = '';
            $html .= '<table class="mp-queries display" cellpadding="0" cellspacing="0" border="0" width="100%">';
            $html .= '<thead><tr>';
            $html .= '<th>' . __('ID') . '</th>';
            $html .= '<th>' . __('Time') . '</th>';
            $html .= '<th>' . __('Query') . '</th>';
            $html .= '<th>' . __('Called From') . '</th>';
            $html .= '</tr></thead><tbody>';
            if ($this->highlight_syntax) {
                $geshi = new GeSHi('', 'mysql');
                $geshi->set_header_type(GESHI_HEADER_NONE);
                $geshi->set_keyword_group_style(1, 'color: #000;', true);
                $geshi->set_keyword_group_style(5, 'color: #000;', true);
                $geshi->set_strings_style('color: #009;', false, 0);
            }
            $i = 0;
            foreach ($wpdb->queries as $query_entry) {
                $query = $query_entry[0];
                $time = $query_entry[1];
                $trace = $query_entry[2];
                $total_query_time += $time;
                $full_trace = $this->get_trace_by_query($query);
                $displayed_query = preg_replace('/[\\s]+/', ' ', $query);
                if ($this->highlight_syntax) {
                    $geshi->set_source($displayed_query);
                    $displayed_query = $geshi->parse_code();
                }
                if ($full_trace) {
                    $trace_html = $this->get_trace_html($full_trace);
                } else {
                    if ($this->display_files) {
                        $trace = explode(', ', $trace);
                        $trace = implode('<br />', $trace);
                    }
                    $trace_html = $trace;
                }
                $html .= '<tr' . $class . '>';
                $html .= '<td class="mp-column-id">' . ($i + 1) . '</td>';
                $html .= '<td class="mp-column-time">' . number_format($time, 8) . '</td>';
                $html .= '<td class="mp-column-query"><div class="mp-column-query-content">' . $displayed_query . '</div></td>';
                $html .= '<td class="mp-column-trace"><div class="mp-column-trace-content">' . $trace_html . '</div></td>';
                $html .= '</tr>';
                $i++;
            }
            $html .= '</tbody></table>';
            $html .= '
				<script type="text/javascript">
					jQuery(document).ready(function() {
						jQuery(".mp-queries").dataTable({
							"bPaginate": false,
							"bLengthChange": false
						});
						jQuery(".mp-queries .mp-column-trace-content").each(function() {
							jQuery(this).scrollTop(jQuery(this)[0].scrollHeight);
						});
					});
				</script>
			';
        }
        $php_time = $total_time - $total_query_time;
        $mysql_percentage = number_format_i18n($total_query_time / $total_time * 100, 2);
        $php_percentage = number_format_i18n($php_time / $total_time * 100, 2);
        $html .= '<ul class="mp-general-stats">';
        $html .= '<li><strong>' . __('Total query time:') . ' ' . number_format_i18n($total_query_time, 5) . __('s for') . ' ' . count($wpdb->queries) . ' ' . __('queries.') . '</strong></li>';
        if (count($wpdb->queries) != get_num_queries()) {
            $html .= '<li><strong>' . __('Total num_query time:') . ' ' . timer_stop() . ' ' . __('for') . ' ' . get_num_queries() . ' ' . __('num_queries.') . '</strong></li>';
            $html .= '<li class="none_list">' . __('&raquo; Different values in num_query and query? Please set the constant') . ' <code>define(\'SAVEQUERIES\', true);</code> ' . __('in') . ' <code>wp-config.php</code>.</li>';
        }
        if ($total_query_time == 0) {
            $html .= '<li class="none_list">' . __('&raquo; Query time is null (0)? Please set the constant') . ' <code>SAVEQUERIES</code> ' . ' ' . __('at') . ' <code>true</code> ' . __('in') . ' <code>wp-config.php</code>.</li>';
        }
        $html .= '<li>' . __('Page generated in') . ' ' . number_format_i18n($total_time, 5) . __('s (') . $php_percentage . __('% PHP') . ', ' . $mysql_percentage . __('% MySQL') . ')</li>';
        $html .= '</ul>';
        $html .= '<p class="mp-final-message">Be sure to deactivate MySQL Profiler when you\'ve finished debugging!</p>';
        return $html;
    }