///////////////////////////////////////////////////////////////////////// if (!defined("IN_PASTE")) { die("Access denied!"); } // Parse code in geshi lib include_once 'libs/geshi/geshi.php'; $id = isset($_GET["id"]) ? $_GET["id"] : ""; $p = $startUp->getPaste($id); if (isset($_GET['download'])) { header("Content-type: text/plain"); header("Content-Disposition: attachment; filename=" . $p['title'] . ""); header("Content-Description: " . $p['lang'] . " Generated Data"); echo html_entity_decode(htmlspecialchars_decode($p['paste'])); exit; } if (!empty($p)) { $geshi = new GeSHi(html_entity_decode(htmlspecialchars_decode($p['paste'])), $p['lang']); $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->set_case_keywords(GESHI_CAPS_LOWER); $geshi->set_footer_content('Parsed in <TIME> seconds'); $smarty->assign("result", $geshi->parse_code()); $smarty->assign("getPaste", $p); // Update hits $startUp->updateHits($id); } $hook->set_title('title_paste', 'Detail paste'); $hook->addcontentPaste('defaultpaste', '', 3); if ($hook->hook_exist('paste_page')) { $hook->execute_hook('paste_page'); }
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; }
function wp_codebox_highlight_geshi ($match) { global $codeid, $post; $codeid ++; //get option from DB $cb_plain_txt = get_option("cb_plain_txt"); $cb_line = get_option("cb_line"); $cb_colla = get_option("cb_colla"); $cb_wrap_over = get_option("cb_wrap_over"); $cb_highlight = get_option("cb_highlight"); $cb_strict = get_option("cb_strict"); $cb_caps = get_option("cb_caps"); $cb_tab_width = intval(get_option("cb_tab_width")); $cb_keywords_link = get_option("cb_keywords_link"); if ($match[1]) { $language = strtolower(trim($match[1])); } else { $language = "text"; } $line = trim($match[4]); $file = trim($match[2]); $colla = trim($match[3]); $code = wp_codebox_code_trim($match[5]); $is_windowsie = wp_codebox_is_windowsie(); $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links($cb_keywords_link); $geshi->set_case_keywords($cb_caps); $geshi->set_tab_width($cb_tab_width); $geshi->enable_strict_mode($cb_strict); do_action_ref_array('wp_codebox_init_geshi', array(&$geshi)); $output = "\n"; if (! ($cb_plain_txt)) { $output .= "<div class=\"wp_codebox_msgheader"; if (($cb_colla && (! ($colla == "+"))) || ($colla == "-")) { $output .= " wp_codebox_hide"; } $output .= "\">"; $output .= "<span class=\"right\">"; $output .= "<sup><a href=\"http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples\" target=\"_blank\" title=\"WP-CodeBox HowTo?\"><span style=\"color: #99cc00\">?</span></a></sup>"; if ($is_windowsie) { $output .= "<a href=\"javascript:;\" onclick=\"copycode('p" . $post->ID . "code" . $codeid . "');\">" . __('[Copy to clipboard]', 'wp-codebox') . "</a>"; } /* $output .= "<a href=\"javascript:;\" onclick=\"toggle_collapse('p".$post->ID.$codeid."');\">[<span id=\"p".$post->ID.$codeid."_symbol\">"; if (($cb_colla && (!($colla == "+"))) || ($colla == "-")){$output .= "+";} else {$output.= "-";} $output .= "</span>]</a>"; */ $output .= "</span>"; if ($file) { $output .= "<span class=\"left2\">" . __('Download', 'wp-codebox') . ' <a href="' . get_bloginfo('wpurl') . '/wp-content/plugins/wp-codebox/wp-codebox.php?p=' . $post->ID . '&download=' . wp_specialchars($file) . '">' . wp_specialchars($file) . '</a>'; } else { $output .= "<span class=\"left\">" . "<a href=\"javascript:;\" onclick=\"javascript:showCodeTxt('p" . $post->ID . "code" . $codeid . "'); return false;\">" . __('View Code', 'wp-codebox') . "</a> " . strtoupper($language); } $output .= "</span><div class=\"codebox_clear\"></div></div>"; } $output .= "<div class=\"wp_codebox\">"; $output .= "<table>"; $output .= "<tr "; $output .= "id=\"p" . $post->ID . $codeid . "\">"; if ($cb_line && (! ($line))) $line = "1"; if (($line) && (! ($line == "n"))) { $output .= "<td class=\"line_numbers\">"; $output .= wp_codebox_line_numbers($code, $line); $output .= "</td>"; } $output .= "<td class=\"code\" id=\"p" . $post->ID . "code" . $codeid . "\">"; $output .= $geshi->parse_code(); $output .= "</td></tr></table></div>\n"; return $output; }
/** * Function handler for coloring shortcodes. It's used in comments and for [filesyntax tag] * * @param string $atts * @param string $content * @return string */ function fr_codesyntax_handler($atts, $content = null, $cleanHTML = true, $commentProcessing = false) { global $wp_sh_styling_type; if (empty($content)) { return '<font color="red"><b>' . __('WP-SYNHIGHLIGHT PLUGIN: NOTHING TO HIGHLIGHT! PLEASE READ README.TXT IN PLUGIN FOLDER!', 'wp-synhighlighter') . '</b></font>'; } //Parsing paramters $params = shortcode_atts(array('title' => get_option('wp_synhighlight_default_codeblock_title') ? get_option('wp_synhighlight_default_codeblock_title') : __("Code block", 'wp-synhighlighter'), 'bookmarkname' => '', 'lang' => 'pascal', 'lines' => get_option('wp_synhighlight_default_lines') ? get_option('wp_synhighlight_default_lines') : 'fancy', 'lines_start' => get_option('wp_synhighlight_default_lines_start_with') ? get_option('wp_synhighlight_default_lines_start_with') : '1', 'container' => get_option('wp_synhighlight_default_container') ? get_option('wp_synhighlight_default_container') : 'pre', 'capitalize' => get_option('wp_synhighlight_default_capitalize_keywords') ? get_option('wp_synhighlight_default_capitalize_keywords') : 'no', 'tab_width' => get_option('wp_synhighlight_default_tab_width') ? get_option('wp_synhighlight_default_tab_width') : 4, 'strict' => get_option('wp_synhighlight_default_strict_mode') ? get_option('wp_synhighlight_default_strict_mode') : 'always', 'blockstate' => get_option('wp_synhighlight_default_blockstate') ? get_option('wp_synhighlight_default_blockstate') : 'default', 'highlight_lines' => "", 'doclinks' => !get_option('wp_synhighlight_doclinks_off')), $atts); if ($cleanHTML) { //Clearing all other HTML code $content = strip_tags($content); //Converting HTML entities $content = html_entity_decode($content, ENT_QUOTES); } //Trimming first and last incorrect newlines $content = trim($content); //Windows Live Writer patch foreach ($params as &$param) { $param = trim(html_entity_decode($param, ENT_QUOTES), '"'); } //Highlighting $geshi = new GeSHi($content, $params['lang']); if (!$commentProcessing and ($wp_sh_styling_type == 'theme' or $wp_sh_styling_type == 'embedbody')) { $geshi->enable_classes(); } //Setting Geshi options //Lines switch ($params['lines']) { case 'normal': $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); break; case 'fancy': $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); break; case 'no': $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS); break; } $geshi->start_line_numbers_at($params['lines_start']); //Container switch ($params['container']) { case 'pre': $geshi->set_header_type(GESHI_HEADER_PRE); break; case 'div': $geshi->set_header_type(GESHI_HEADER_DIV); break; case 'pre_valid': $geshi->set_header_type(GESHI_HEADER_PRE_VALID); break; case 'pre_table': $geshi->set_header_type(GESHI_HEADER_PRE_TABLE); break; case 'none': $geshi->set_header_type(GESHI_HEADER_NONE); break; } //Keywords capitalization switch ($params['capitalize']) { case 'no': $geshi->set_case_keywords(GESHI_CAPS_NO_CHANGE); break; case 'upper': $geshi->set_case_keywords(GESHI_CAPS_UPPER); break; case 'lower': $geshi->set_case_keywords(GESHI_CAPS_LOWER); break; } //Tab width $geshi->set_tab_width($params['tab_width']); //Strict mode switch ($params['strict']) { case 'always': $geshi->enable_strict_mode(GESHI_ALWAYS); break; case 'maybe': $geshi->enable_strict_mode(GESHI_MAYBE); break; case 'never': $geshi->enable_strict_mode(GESHI_NEVER); break; } //Block state switch ($params['blockstate']) { case 'collapsed': $initiallyHidden = true; break; case 'default': case 'expanded': default: $initiallyHidden = false; break; } //Controlling doclinks $geshi->enable_keyword_links($params['doclinks']); static $instanceNumber = 0; $instanceNumber++; $bookmarkName = empty($params['bookmarkname']) ? "codesyntax_" . $instanceNumber : $params['bookmarkname']; //Highlighting lines if (!empty($params['highlight_lines'])) { $geshi->highlight_lines_extra(explode(',', $params['highlight_lines'])); } //Checking for geshi errors if ($geshi->error()) { return '<font color="red"><b>' . $geshi->error() . '</b></font>'; } //Styling codeblock $header = wp_synhighlight_get_tpl_header($instanceNumber, $params['title'], $bookmarkName, $initiallyHidden); //Embedding only one copy of each used language style static $embeddedStylesheets = array(); if ($wp_sh_styling_type == 'embedbody' and !in_array($params['lang'], $embeddedStylesheets)) { $header = '<style type="text/css"><!--' . "\r\n" . $geshi->get_stylesheet() . "\r\n" . '-->' . "\r\n" . '</style>' . $header; $embeddedStylesheets[] = $params['lang']; } $footer = wp_synhighlight_get_tpl_footer(); $result = $header . $geshi->parse_code() . $footer; return $result; }