/**
  * @desc Highlights the code. It uses the geshi HTML syntax highlighter and then it highlights the specific template syntax.
  * @param int $line_number GESHI_NO_LINE_NUMBERS => no line numbers, GESHI_NORMAL_LINE_NUMBERS line numbers.
  * @param bool $inline_code true if it's a sigle line code, otherwise false.
  */
 public function parse($line_number = GESHI_NO_LINE_NUMBERS, $inline_code = false)
 {
     //The template language of PHPBoost contains HTML. We first ask to highlight the html code.
     require_once PATH_TO_ROOT . '/kernel/lib/php/geshi/geshi.php';
     $geshi = new GeSHi($this->content, 'html');
     if ($line_number) {
         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     }
     //GeSHi must not put any div or pre tag before and after the content
     if ($inline_code) {
         $geshi->set_header_type(GESHI_HEADER_NONE);
     }
     $this->content = $geshi->parse_code();
     //Now we highlight the specific syntax of PHPBoost templates
     //Conditionnal block
     $this->content = preg_replace('`# IF ( NOT)? ((?:\\w+\\.)*)(\\w+) #`i', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">IF$1</span> <span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$2</span><span style="' . self::TPL_VARIABLE_STYLE . '">$3</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content);
     $this->content = preg_replace('`# ELSEIF ( NOT)? ((?:\\w+\\.)*)(\\w+) #`i', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">ELSEIF$1</span> <span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$2</span><span style="' . self::TPL_VARIABLE_STYLE . '">$3</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content);
     $this->content = str_replace('# ELSE #', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">ELSE</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content);
     $this->content = str_replace('# ENDIF #', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">ENDIF</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content);
     //Loops
     $this->content = preg_replace('`# START ((?:\\w+\\.)*)(\\w+) #`i', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">START</span> <span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$1</span><span style="' . self::TPL_VARIABLE_STYLE . '">$2</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content);
     $this->content = preg_replace('`# END ((?:\\w+\\.)*)(\\w+) #`i', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">END</span> <span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$1</span><span style="' . self::TPL_VARIABLE_STYLE . '">$2</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content);
     //Inclusions
     $this->content = preg_replace('`# INCLUDE ((?:\\w+\\.)*)([\\w]+) #`', '<span style="' . self::TPL_SHARP_STYLE . '">#</span> <span style="' . self::TPL_KEYWORD_STYLE . '">INCLUDE </span> <span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$1</span><span style="' . self::TPL_VARIABLE_STYLE . '">$2</span> <span style="' . self::TPL_SHARP_STYLE . '">#</span>', $this->content);
     //Simple variable
     $this->content = preg_replace('`{([\\w]+)}`i', '<span style="' . self::TPL_BRACES_STYLE . '">{</span><span style="' . self::TPL_VARIABLE_STYLE . '">$1</span><span style="' . self::TPL_BRACES_STYLE . '">}</span>', $this->content);
     //Loop variable
     $this->content = preg_replace('`{((?:[\\w]+\\.)+)([\\w]+)}`i', '<span style="' . self::TPL_BRACES_STYLE . '">{</span><span style="' . self::TPL_NESTED_VARIABLE_STYLE . '">$1</span><span style="' . self::TPL_VARIABLE_STYLE . '">$2</span><span style="' . self::TPL_BRACES_STYLE . '">}</span>', $this->content);
     if ($inline_code) {
         $this->content = '<pre style="display:inline; font-color:courier new;">' . $this->content . '</pre>';
     }
 }
 function _highlight_code($contents, $language, $line_number, $inline_code)
 {
     $contents = htmlspecialchars_decode($contents);
     if (strtolower($language) == 'bbcode') {
         import('content/parser/bbcode_highlighter');
         $bbcode_highlighter = new BBCodeHighlighter();
         $bbcode_highlighter->set_content($contents, PARSER_DO_NOT_STRIP_SLASHES);
         $bbcode_highlighter->parse($inline_code);
         $contents = $bbcode_highlighter->get_content(DO_NOT_ADD_SLASHES);
     } elseif (strtolower($language) == 'tpl' || strtolower($language) == 'template') {
         import('content/parser/template_highlighter');
         require_once PATH_TO_ROOT . '/kernel/framework/content/geshi/geshi.php';
         $template_highlighter = new TemplateHighlighter();
         $template_highlighter->set_content($contents, PARSER_DO_NOT_STRIP_SLASHES);
         $template_highlighter->parse($line_number ? GESHI_NORMAL_LINE_NUMBERS : GESHI_NO_LINE_NUMBERS, $inline_code);
         $contents = $template_highlighter->get_content(DO_NOT_ADD_SLASHES);
     } elseif ($language != '') {
         require_once PATH_TO_ROOT . '/kernel/framework/content/geshi/geshi.php';
         $Geshi = new GeSHi($contents, $language);
         if ($line_number) {
             $Geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
         }
         if ($inline_code) {
             $Geshi->set_header_type(GESHI_HEADER_NONE);
         }
         $contents = '<pre style="display:inline;">' . $Geshi->parse_code() . '</pre>';
     } else {
         $highlight = highlight_string($contents, true);
         $font_replace = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $highlight);
         $contents = preg_replace('`color="(.*?)"`', 'style="color:$1"', $font_replace);
     }
     return $contents;
 }
 /**
  * Format the content of this snippet with GeSHi and return the output.
  * @return string Formatted code output
  */
 function getFormattedOutput()
 {
     require_once dirname(__DIR__) . '/thirdparty/geshi/geshi.php';
     $g = new GeSHi($this->Code, $this->Language);
     $g->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     return $g->parse_code();
 }
Exemple #4
0
 public function renderTagCode(array $tag, array $rendererStates)
 {
     if (strtolower(strval($tag['option'])) == 'html') {
         $tag['option'] = 'html5';
     }
     if (!$tag['option']) {
         $tag['option'] = 'text';
     }
     $content = $this->stringifyTree($tag['children']);
     $content = XenForo_Helper_String::censorString($content);
     $geshi = new GeSHi($content, $tag['option']);
     if (XenForo_Application::get('options')->get('dpSyntaxHighlighterShowLines')) {
         $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     }
     $geshi->set_link_target('_blank" rel="nofollow');
     $geshi->set_header_type(GESHI_HEADER_NONE);
     $geshi->set_tab_width(4);
     $content = $geshi->parse_code();
     if ($this->_view) {
         $template = $this->_view->createTemplateObject('dp_bb_code_tag_code', array('content' => $content, 'language' => $geshi->get_language_name()));
         return $template->render();
     } else {
         return '<div style="margin: 1em auto" title="Code">' . $content . '</div>';
     }
 }
Exemple #5
0
function JHP_Geshi_replacer(&$matches)
{
    //	print_r($matches);
    //// 	die();
    jimport('geshi.geshi');
    jimport('domit.xml_saxy_shared');
    $args = SAXY_Parser_Base::parseAttributes($matches[1]);
    // 	print_r($args);
    $text = $matches[2];
    $lang = JArrayHelper::getValue($args, 'lang', 'phpz');
    $lines = JArrayHelper::getValue($args, 'lines', 'true');
    $html_entities_match = array("|\\<br \\/\\>|", "#<#", "#>#", "|&#39;|", '#&quot;#', '#&nbsp;#');
    $html_entities_replace = array("\n", '&lt;', '&gt;', "'", '"', ' ');
    $text = preg_replace($html_entities_match, $html_entities_replace, $text);
    $text = str_replace('&lt;', '<', $text);
    $text = str_replace('&gt;', '>', $text);
    $text = str_replace("\t", '  ', $text);
    $geshi = new GeSHi($text, $lang);
    if ($lines == 'true') {
        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
    }
    $text = $geshi->parse_code();
    $text = '???' . $text . '???';
    return $text;
}
Exemple #6
0
 /**
  * Highlight a given piece of source code.
  * Works for xhtml only. Falls back to original highlighter for
  * other formats.
  *
  * @param string $text   Text to highlight
  * @param string $role   Source code role to use (php, xml, html, ...)
  * @param string $format Output format (pdf, xhtml, troff, ...)
  *
  * @return string Highlighted code
  */
 public function highlight($text, $role, $format)
 {
     $geshi = new \GeSHi($text, $role);
     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     $geshi->set_header_type(GESHI_HEADER_DIV);
     return $geshi->parse_code();
 }
Exemple #7
0
function print_highlighted($lang)
{
    //The GeSHI syntax highlighter is included.
    include_once 'geshi/geshi.php';
    //The string returned is stored in a variable.
    $filename = get_id($_SERVER['REQUEST_URI']);
    //If file does not exist then it redirects the user to the home page.
    $file = fopen("data/{$filename}", "r") or header("Location: /");
    $source = '';
    while (!feof($file)) {
        $source = $source . fgets($file);
    }
    //The object created is passed two arguments for syntax highlighting.
    $geshi = new GeSHi($source, $lang);
    $geshi->set_overall_style('background-color: #f2f2f2; margin: 0px 35px; border: 1px dotted;', true);
    //$geshi->set_header_type(GESHI_HEADER_PRE_VALID);
    $geshi->set_header_type(GESHI_HEADER_DIV);
    //The flag below shows the line numbers. See GeSHI docs for more options.
    $flag = GESHI_FANCY_LINE_NUMBERS;
    $geshi->enable_line_numbers($flag);
    $geshi->set_line_style(' padding: 0px 15px;');
    //The <pre> tags are included for maintaining the indentation.
    // echo "<pre>";
    echo $geshi->parse_code();
    // echo "</pre></div>";
    return 0;
}
Exemple #8
0
/**
* Replaces the matched tags an image
* @param array An array of matches (see preg_match_all)
* @return string
*/
function plgContentGeshi_replacer(&$matches)
{
    $params =& $GLOBALS['_MAMBOT_GESHI_PARAMS'];
    jimport('geshi.geshi');
    jimport('domit.xml_saxy_shared');
    $args = SAXY_Parser_Base::parseAttributes($matches[1]);
    $text = $matches[2];
    $lang = JArrayHelper::getValue($args, 'lang', 'php');
    $lines = JArrayHelper::getValue($args, 'lines', 'false');
    $html_entities_match = array("|\\<br \\/\\>|", "#<#", "#>#", "|&#39;|", '#&quot;#', '#&nbsp;#');
    $html_entities_replace = array("\n", '&lt;', '&gt;', "'", '"', ' ');
    $text = preg_replace($html_entities_match, $html_entities_replace, $text);
    $text = str_replace('&lt;', '<', $text);
    $text = str_replace('&gt;', '>', $text);
    /*
    	// Replace 2 spaces with "&nbsp; " so non-tabbed code indents without making huge long lines.
    	$text = str_replace("  ", "&nbsp; ", $text);
    	// now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
    	$text = str_replace("  ", " &nbsp;", $text);
    */
    // Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
    //$text = str_replace("\t", "&nbsp; &nbsp;", $text);
    $text = str_replace("\t", '  ', $text);
    $geshi = new GeSHi($text, $lang);
    if ($lines == 'true') {
        $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
    }
    $text = $geshi->parse_code();
    return $text;
}
 function load()
 {
     if ($this->exists() == true) {
         $this->import();
         $this->lng = $this->data['language'];
         $this->source = $this->data['source'];
     } else {
         if (!class_exists('GeSHi')) {
             include_once 'classes/class.geshi.php';
         }
         global $lang;
         $language = $this->hasLanguage() ? $this->lng : 'text';
         $geshi = new GeSHi($this->source, $language, 'classes/geshi');
         $geshi->set_encoding($lang->charset());
         $geshi->enable_classes(false);
         $geshi->set_header_type(GESHI_HEADER_DIV);
         $geshi->enable_keyword_links(true);
         $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
         if (!$this->hasLanguage()) {
             $geshi->enable_highlighting(false);
             $geshi->set_numbers_highlighting(false);
             $geshi->set_brackets_highlighting(false);
             $language = '';
         } else {
             $language = $geshi->get_language_name();
         }
         $this->data = array('language' => $language, 'parsed' => $geshi->parse_code(), 'source' => $this->source);
         $this->export();
     }
 }
Exemple #10
0
 /**
  * 
  * Renders a token into text matching the requested format.
  * 
  * @access public
  * 
  * @param array $options The "options" portion of the token (second
  * element).
  * 
  * @return string The text rendered from the token options.
  * 
  */
 function token($options)
 {
     $text = $options['text'];
     $attr = $options['attr'];
     $type = strtolower($attr['type']);
     $css = $this->formatConf(' class="%s"', 'css');
     $css_code = $this->formatConf(' class="%s"', 'css_code');
     $css_php = $this->formatConf(' class="%s"', 'css_php');
     $css_html = $this->formatConf(' class="%s"', 'css_html');
     $geshi_class = path::file("plugins") . "geshi/geshi.php";
     if ($type != "" && file_exists(path::file("plugins") . "geshi/geshi.php") && is_readable(path::file("plugins") . "geshi/geshi.php")) {
         require_once path::file("plugins") . "geshi/geshi.php";
         $geshi = new GeSHi(trim($text), $type, path::file("plugins") . "geshi/geshi/");
         $geshi->set_encoding("utf-8");
         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS, 1);
         $geshi->set_header_type(GESHI_HEADER_DIV);
         $geshi->enable_classes();
         $geshi->set_overall_class('geshi_code');
         $text = $geshi->parse_code();
         $style = $geshi->get_stylesheet();
         global $page_handler;
         $style = "<style type='text/css'>\n{$style}\n</style>";
         $page_handler->add_header_data($style);
     } else {
         //generic code example:
         //convert tabs to four spaces,
         //convert entities.
         $text = trim(htmlentities($text));
         $text = str_replace("\t", " &nbsp; &nbsp;", $text);
         $text = str_replace("  ", " &nbsp;", $text);
         $text = "<code{$css_code}>{$text}</code>";
     }
     return "\n{$text}\n\n";
 }
 public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer)
 {
     $ret = parent::getTemplateVars($renderer);
     $row = $this->getRow();
     if ($row->language) {
         $geshi = new GeSHi($row->code, $row->language);
         if ($row->line_numbers) {
             $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
         } else {
             $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
         }
         $ret['html'] = $geshi->parse_code();
     } else {
         $ret['html'] = '<code>' . htmlspecialchars($row->code) . '</code>';
     }
     return $ret;
 }
 /**
  * @param string $arguments array with the type
  * @param array $code string of the code to parse
  * @param \ShortcodeParser $parser Parser root user.
  * @param string $shortcode
  * @param array $extra
  *
  * @return String of parsed code.
  */
 public static function handle_shortcode($arguments, $code, $parser, $shortcode, $extra = array())
 {
     if (!isset($arguments['type'])) {
         /** Assuming most code is PHP. Feel free to update. Should this be a configurable? */
         $arguments['type'] = 'php';
     }
     $geshi = new \GeSHi(html_entity_decode(str_replace('<br>', "\n", $code)), $arguments['type']);
     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     return $geshi->parse_code();
 }
Exemple #13
0
function render_code(&$renderer, $code, $lang)
{
    // code
    $renderer->doc .= "<div class=\"code_block_code\">";
    $geshi = new GeSHi($code, $lang);
    $geshi->set_header_type(GESHI_HEADER_DIV);
    $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
    $renderer->doc .= $geshi->parse_code();
    $renderer->doc .= "</div>";
}
Exemple #14
0
 static function generic_render_code($source, $lang, $line_numbers = false)
 {
     require_once self::$geshi_file;
     $geshi = new GeSHi($source, $lang);
     if ($line_numbers) {
         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     }
     $geshi->enable_keyword_links(false);
     return $geshi->parse_code();
 }
Exemple #15
0
 /**
  * Нумерация строк
  *
  * @return Code
  */
 protected function setNum()
 {
     if (isset($this->attributes['num'])) {
         $this->geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
         if ('' !== $this->attributes['num']) {
             $num = (int) $this->attributes['num'];
             $this->geshi->start_line_numbers_at($num);
         }
     }
     return $this;
 }
function markdown_code_highlighter($code, $language, $rss = false)
{
    $code = stripslashes(trim(htmlspecialchars_decode($code, ENT_NOQUOTES)));
    $geshi = new GeSHi($code, $language);
    $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
    if ($rss == false) {
        $geshi->set_header_type(GESHI_HEADER_NONE);
        $geshi->enable_classes();
    }
    return '<pre class="lang-' . $language . '"><code>' . $geshi->parse_code() . '</code></pre>';
}
Exemple #17
0
function handle_geshi($content, $language)
{
    $g = new GeSHi($content, $language);
    $g->enable_classes();
    $g->set_header_type(GESHI_HEADER_DIV);
    $g->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
    #$g->set_overall_style('color:black');
    $g->set_overall_id('source');
    $g->set_code_style('color:black;', "'Courier New', Courier, monospace");
    $g->set_line_style('color:#838383;', '', true);
    return $g->parse_code();
}
 public function register(Application $app)
 {
     $app['geshi'] = function () use($app) {
         $geshi = new \GeSHi();
         $geshi->enable_classes();
         // this must be the first method (see Geshi doc)
         $geshi->set_encoding($app['app.charset']);
         $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
         $geshi->enable_keyword_links(false);
         return $geshi;
     };
 }
Exemple #19
0
 public function code(&$buff)
 {
     $geshi = new GeSHi($buff, $this->lang_alias($this->lang));
     $geshi->set_header_type(GESHI_HEADER_PRE);
     $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     $geshi->code_style = $geshi->line_style1 = '';
     $geshi->keyword_links = false;
     $error = $geshi->error();
     if ($error) {
         debug($error);
     }
     return '<span class="code">' . ($error ? nl2br(htmlspecialchars($buff)) : $geshi->parse_code()) . '</span>';
 }
Exemple #20
0
function vorschau($K_Egl, $BenutzerId, $fid, $tid, $sid, $bid, $zid, $neu, $bemerkung)
{
    if (!$K_Egl) {
        fehler(__FILE__, __LINE__, 1, 'Zwichenablage fuer die Vorschau wurde nicht aktualisiert, da nicht eingeloggt');
    }
    $comp = trim($_POST['text']);
    $code = $_POST['codearea'];
    if (strlen($code)) {
        include_once '../forum/geshi/geshi.php';
        $sprachen = array('bash' => 'bash', 'C', 'c', 'cpp', 'cpp', 'HTML' => 'html4strict', 'Java' => 'java', 'JavaScript' => 'javascript', 'lisp' => 'lisp', 'PHP' => 'php-brief', 'Perl' => 'perl', 'Python' => 'python');
        $sprache = 'text';
        if (isset($_POST['codelang'])) {
            $sprache = $sprachen[$_POST['codelang']];
            if ($sprache == '') {
                $sprache = 'text';
            } else {
                $t = stripslashes($code);
                $ersatz = array('&gt;' => '>', '&lt;' => '<', '&quot;' => '"', '&#039;' => '\'', '&amp;' => '&');
                $t = strtr($t, $ersatz);
                if (isset($_POST['codezz']) and $_POST['codezz'] != "") {
                    $a = explode(',', $_POST['codezz']);
                    if (count($a) == 2) {
                        $code_start = intval($a[0]);
                        $code_ende = intval($a[1]);
                    }
                }
                $geshi = new GeSHi($t, $sprache, 'geshi/geshi');
                $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                if (isset($code_start)) {
                    $geshi->highlight_lines_extra(range($code_start, $code_ende));
                }
                $code = $geshi->parse_code();
            }
        }
        if (isset($_POST['textarea_zeile']) and intval($_POST['textarea_zeile']) != -1) {
            $zeilen = intval($_POST['textarea_zeile']);
            $vorderteil = implode("\n", array_slice(explode("\n", $comp, $zeilen + 1), 0, $zeilen));
            $hinterteil = ltrim(substr($comp, strlen($vorderteil)));
            $vorderteil = rtrim($vorderteil);
            $comp = $vorderteil . '<div class="code-bereich">' . $code . '</div>' . $hinterteil;
        } else {
            $comp = $comp . '<div class="code-bereich">' . $code . '</div>';
        }
    }
    $comp = addslashes($comp);
    mysql_query("UPDATE Benutzer\n                SET Ablage = '{$comp}'\n                WHERE BenutzerId = '{$BenutzerId}'") or fehler(__FILE__, __LINE__, 0, 'Zwischenablage fuer die Vorschau konnte nicht aktualisiert werden');
    $vorschau = strlen($comp) ? 'j' : 'n';
    $bemerkung = rawurlencode($bemerkung);
    $titel = rawurlencode(substr(strip_tags(trim($_POST['titel'])), 0, 50));
    include 'gz-beitraege.php';
}
Exemple #21
0
 /**
  *	Send output to browser. 
  */
 function toHTML($code_text, $parm)
 {
     global $e107cache;
     $class = e107::getBB()->getClass('code');
     $pref = e107::getPref();
     $tp = e107::getParser();
     if ($pref['smiley_activate']) {
         if (!is_object($tp->e_emote)) {
             $tp->e_emote = new e_emoteFilter();
         }
         $code_text = $tp->e_emote->filterEmotesRev($code_text);
     }
     $search = array(E_NL, '&#092;', '&#036;', '&lt;');
     $replace = array("\r\n", "\\", '$', '<');
     $code_text = str_replace($search, $replace, $code_text);
     if (isset($pref['useGeshi']) && $pref['useGeshi'] && file_exists(e_PLUGIN . "geshi/geshi.php")) {
         $code_md5 = md5($code_text);
         if (!($CodeCache = $e107cache->retrieve('GeshiParsed_' . $code_md5))) {
             require_once e_PLUGIN . "geshi/geshi.php";
             if ($parm) {
                 $geshi = new GeSHi($code_text, $parm, e_PLUGIN . "geshi/geshi/");
             } else {
                 $geshi = new GeSHi($code_text, $pref['defaultLanGeshi'] ? $pref['defaultLanGeshi'] : 'php', e_PLUGIN . "geshi/geshi/");
             }
             $geshi->line_style1 = "font-family: 'Courier New', Courier, monospace; font-weight: normal; font-style: normal;";
             $geshi->set_encoding('utf-8');
             $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
             $geshi->set_header_type(GESHI_HEADER_DIV);
             $CodeCache = $geshi->parse_code();
             $e107cache->set('GeshiParsed_' . $code_md5, $CodeCache);
         }
         $ret = "<code class='code_highlight code-box {$class}' style='unicode-bidi: embed; direction: ltr'>" . str_replace("&amp;", "&", $CodeCache) . "</code>";
     } else {
         $code_text = html_entity_decode($code_text, ENT_QUOTES, 'utf-8');
         $code_text = trim($code_text);
         $code_text = htmlspecialchars($code_text, ENT_QUOTES, 'utf-8');
         $srch = array('{', '}');
         $repl = array('&lbrace;', '&rbrace;');
         $code_text = str_replace($srch, $repl, $code_text);
         // avoid code getting parsed as templates or shortcodes.
         if ($parm == 'inline') {
             return "<code style='unicode-bidi: embed; direction: ltr'>" . $code_text . "</code>";
         }
         //	$highlighted_text = highlight_string($code_text, TRUE);
         // highlighted_text = str_replace(array("<code>","</code>"),"",$highlighted_text);
         $divClass = $parm ? $parm : 'code_highlight';
         $ret = "<pre class='prettyprint linenums " . $tp->toAttribute($divClass) . " code-box {$class}' style='unicode-bidi: embed; direction: ltr'>" . $code_text . "</pre>";
     }
     $ret = str_replace("[", "&#091;", $ret);
     return $ret;
 }
function highlight_syntax($code, $langid)
{
    $value = get_record('problemstatement_programming_language', 'id', $langid);
    if ($value) {
        $syntax = $value->geshi;
    } else {
        $syntax = '';
    }
    /*
    	switch ($langid) {
    		case '0': $syntax='cpp'; break;
    		case '1': $syntax='delphi'; break;
    		case '2': $syntax='java'; break;
    		case '3': $syntax='python'; break;
    		case '4': $syntax='csharp'; break;
    	}*/
    $geshi = new GeSHi($code, $syntax);
    $geshi->set_header_type(GESHI_HEADER_DIV);
    //   $geshi->enable_classes(true);
    $geshi->set_overall_style('font-family: monospace;');
    $linenumbers = 1;
    if ($linenumbers) {
        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
        $geshi->set_line_style('color:#222;', 'color:#888;');
        $geshi->set_overall_style('font-size: 14px;font-family: monospace;', true);
    }
    $urls = FALSE;
    $indentsize = FALSE;
    $inline = FALSE;
    if (!$urls) {
        for ($i = 0; $i < 5; $i++) {
            $geshi->set_url_for_keyword_group($i, '');
        }
    }
    if ($indentsize) {
        $geshi->set_tab_width($indentsize);
    }
    $parsed = $geshi->parse_code();
    if ($inline) {
        $parsed = preg_replace('/^<div/', '<span', $parsed);
        $parsed = preg_replace('/<\\/div>$/', '</span>', $parsed);
    }
    //return $geshi->parse_code().$syntax;
    $lang = get_record('problemstatement_programming_language', 'id', $langid);
    if (!$lang) {
        $lang = '';
    }
    $comment = get_string("programwritten", "problemstatement") . $lang->language_name;
    //get_string("lang_".$langid, "problemstatement");
    return $parsed . $comment;
}
Exemple #23
0
 public static function output($text, $syntax = 'none')
 {
     if ($syntax == 'none') {
         return '<pre>' . $text . '</pre>';
     } else {
         // Since we may be coming from another syntax highlighter,
         // we'll try downcasing the syntax name and hope we get lucky.
         $syntax = strtolower($syntax);
         $geshi = new GeSHi($text, $syntax);
     }
     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
     $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     return $geshi->parse_code();
 }
 public function __toString()
 {
     $this->captureEnd();
     require_once APPLICATION_PATH . '/../library/geshi/geshi.php';
     $geshi = new GeSHi($this->_source, $this->_language);
     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     $html = '<div class="example">';
     if ($this->_title) {
         $html .= '<p class="title">' . $this->_title . '</p>';
     }
     $html .= '<div class="code">';
     $html .= $geshi->parse_code();
     $html .= '</div>';
     $html .= '</div>';
     return $html;
 }
Exemple #25
0
function highlight_sql_query($sql)
{
    require_once 'classes/class.geshi.php';
    $path = 'classes/geshi';
    $language = 'mysql';
    if (!file_exists($path . '/' . $language . '.php')) {
        $language = 'sql';
        if (!file_exists($path . '/' . $language . '.php')) {
            return null;
        }
    }
    $geshi = new GeSHi($sql, $language, $path);
    $geshi->enable_classes(false);
    $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
    return $geshi->parse_code();
}
Exemple #26
0
 public function getCode($data)
 {
     $code = array();
     foreach ($data as $part => $options) {
         $data = file_get_contents($options['file']);
         $geshi = new \GeSHi($data, $options['type']);
         //             $geshi->set_header_type(GESHI_HEADER_NONE);
         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
         $geshi->set_line_style('background: #fcfcfc;', 'background: #fcfcfc;');
         if (array_key_exists('highlight', $options)) {
             $geshi->highlight_lines_extra($options['highlight']);
         }
         $title = sprintf('%s: %s', $part, basename($options['file']));
         $code[$title] = $geshi->parse_code();
     }
     return $code;
 }
 /**
  * Highlight the content
  * @param string code to highlighted
  * @return string highlighted by defined language in html tags
  */
 public function highlight($content)
 {
     include_once dirname(__FILE__) . '/geshi.php';
     if (!class_exists('GeSHi')) {
         throw new CHttpException(500, 'GeSHi core missing');
     }
     $geshi = new GeSHi($content, strtolower($this->language));
     if ($this->showLineNumbers) {
         $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     }
     foreach ($this->containerOptions as $attribute => $options) {
         if (method_exists($geshi, 'set_overall_' . $attribute)) {
             call_user_func(array($geshi, 'set_overall_' . $attribute), $options);
         }
     }
     return $geshi->parse_code();
 }
 function addEntry()
 {
     require_once 'inc/geshi.php';
     $code = $this->post['code'];
     $lang = $this->post['lang'];
     $poster = $this->post['poster'];
     $conn = parent::getPDOConn();
     if ($conn == NULL) {
         parent::addError("Server error - Could not connect to the database");
         return false;
     }
     if (empty($code) || empty($lang)) {
         parent::addError("You haven't pasted anything!");
         return false;
     }
     if (empty($poster)) {
         $poster = "Anonymous";
     }
     $stmt = $conn->prepare("SELECT * FROM `langs` WHERE `lang` = :lang");
     $stmt->bindParam(":lang", $lang);
     if ($stmt->execute()) {
         $res = $stmt->fetch(PDO::FETCH_ASSOC);
         if (empty($res)) {
             parent::addError("Invalid language");
             return false;
         }
     }
     $geshi = new GeSHi($code, $lang);
     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     if ($lang !== "None") {
         $formatted = $geshi->parse_code();
     } else {
         $formatted = "<pre>" . htmlentities($code) . "</pre>";
     }
     $hash = $this->makeHash($this->post['code'], $formatted, $this->post['lang']);
     $stmt = $conn->prepare("INSERT INTO `pastes` VALUES('', ?, ?, ?, ?, ?, ?)");
     if ($stmt->execute(array(htmlentities($code), $formatted, $res['filename'], $hash, $poster, time()))) {
         parent::addMessage("Paste has been added!  Click <a href=\"view.php?pid=" . $hash . "\">here</a> to view.<br /><input type=\"text\" value=\"http://pb.pwnds.info/view.php?pid=" . $hash . "\" readonly />");
         return $hash;
     } else {
         parent::addError("Server error - Couldn't add paste.  " . $this->post['lang'] . " " . print_r($stmt->errorInfo(), true));
         return false;
     }
 }
Exemple #29
0
 public function codeHighlight($source, $lang)
 {
     Zend_Loader::loadFile("geshi.php", array(config::getFilename("geshi/"), "/usr/share/php-geshi"), true);
     if ($lang == "cpp") {
         $lang = "C++";
     }
     if ($lang == "gcj") {
         $lang = "Java";
     }
     if (!class_exists("GeSHi")) {
         return "<!-- GeSHi disabled --> <pre>" . htmlspecialchars($source) . "</pre>";
     }
     $geshi = new GeSHi($source, $lang);
     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     $geshi->set_overall_class("geshi");
     $code = $geshi->parse_code();
     return $code;
 }
Exemple #30
-1
function task_modifier_scan_text($string)
{
    $CI =& get_instance();
    $CI->config->load('geshi');
    $highlight_map = $CI->config->item('geshi_highlighting_map');
    $html = str_get_html($string, true, true, DEFAULT_TARGET_CHARSET, false);
    foreach ($html->find('pre br') as $br) {
        $br->outertext = "\n";
    }
    foreach ($html->find('pre.highlight') as $highlighted_code) {
        $lang = $highlighted_code->lang;
        if (isset($highlight_map[$lang])) {
            $content = str_replace('&nbsp;', ' ', htmlspecialchars_decode(strip_tags($highlighted_code->innertext), ENT_HTML5 | ENT_QUOTES));
            $geshi = new GeSHi($content, $highlight_map[$lang]);
            $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
            $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
            $highlighted_code->innertext = $geshi->parse_code();
            $highlighted_code->lang = null;
        } else {
            $highlighted_code->lang = null;
            $highlighted_code->class = null;
        }
    }
    ob_start();
    echo $html;
    return ob_get_clean();
}