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;
}
Esempio n. 2
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;
}
function source_highlighter($code)
{
    $source = str_replace(array("&gt;", "&lt;", "&quot;", "&amp;"), array(">", "<", "\"", "&"), $code[1]);
    if (false !== stristr($code[0], "[php]")) {
        $lang2geshi = "php";
    } elseif (false !== stristr($code[0], "[sql]")) {
        $lang2geshi = "sql";
    } elseif (false !== stristr($code[0], "[html]")) {
        $lang2geshi = "html4strict";
    } else {
        $lang2geshi = "txt";
    }
    $geshi = new GeSHi($source, $lang2geshi);
    $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
    $geshi->set_overall_style('font: normal normal 100% monospace; color: #000066;', false);
    $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
    $geshi->set_code_style('color: #000020;font-family:monospace; font-size:12px;line-height:6px;', true);
    //$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
    $geshi->enable_classes(false);
    $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
    $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
    $return = "<div class=\"codetop\">CODE</div><div class=\"codemain\">\n";
    $return .= $geshi->parse_code();
    $return .= "\n</div>\n";
    return $return;
}
Esempio n. 4
0
 function _codeBlockHighlighter($codeblock, &$clear)
 {
     $split = preg_split('/[\\r\\n]/', $codeblock, 2, PREG_SPLIT_NO_EMPTY);
     if (count($split) == 2 && preg_match('/^\\s*((\\\\){0,2}\\[([a-zA-Z0-9\\-_]+)\\]\\s*)/', $split[0], $matches)) {
         if ($matches[2] == '\\') {
             $codeblock = substr($codeblock, 1);
             return $codeblock;
         }
         $strlen = strlen($matches[0]);
         $parser = strtolower($matches[3]);
         $codeblock = $split[1];
         if ($strlen > 0) {
             if ($parser == 'console') {
                 $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
                 $codeblock = preg_replace_callback('/^\\n+/', array($this, '_doFencedCodeBlocks_newlines'), $codeblock);
                 $codeblock = "<pre class=\"console\"><code>{$codeblock}</code></pre>";
             } else {
                 $codeblock = preg_replace('/\\n+$/', '', $codeblock);
                 $geshi = new GeSHi($codeblock, $parser);
                 $geshi->set_overall_style('');
                 $codeblock = $geshi->parse_code();
             }
             $clear = false;
         }
     }
     return $codeblock;
 }
Esempio n. 5
0
 public function getSyntaxHighlightedContent($content, $type)
 {
     //$content = ;
     //return array('<pre>' . $content . '</pre>', 'none');
     //error_log("content len=" . strlen($content));
     // サイズがでかすぎたら syntax highlight ナシ
     if (strlen($content) > 1 << 15) {
         error_log($content);
         return array('<pre>' . htmlspecialchars($content, ENT_QUOTES) . '</pre>', 'none');
     }
     if ($type == '__pastit_type_none__') {
         $type = 'none';
         // auto detect
         $first_line = explode(PHP_EOL, $content);
         $first_line = $first_line[0];
         if (preg_match('@#!.+bin/(\\w+)@', $first_line, $m)) {
             $type = $m[1];
         }
         if (preg_match('@#!.+bin/env\\s+(\\w+)@', $first_line, $m)) {
             $type = $m[1];
         }
         if (preg_match('@\\+\\+\\+@', $content) && preg_match('@\\-\\-\\-@', $content)) {
             $type = 'diff';
         }
     }
     require_once 'geshi/geshi.php';
     $geshi = new GeSHi($content, $type);
     $geshi->set_overall_style('font-family: menlo, monaco, \'courier new\', mono-space;');
     $content = $geshi->parse_code();
     //return '<pre class=" superpre">' . PHP_EOL . $body . '</pre>';
     return array($content, $type);
 }
Esempio n. 6
0
 function syntaxHighlight($matches)
 {
     $geshi = new GeSHi($matches[3], empty($matches[2]) ? "txt" : $matches[2]);
     $geshi->enable_classes();
     $geshi->set_overall_style("");
     // empty style
     return $geshi->parse_code();
 }
Esempio n. 7
0
function source_highlighter($source, $lang2geshi)
{
    require_once 'geshi/geshi.php';
    $source = str_replace(array("&#039;", "&gt;", "&lt;", "&quot;", "&amp;"), array("'", ">", "<", "\"", "&"), $source);
    $lang2geshi = $lang2geshi == 'html' ? 'html4strict' : $lang2geshi;
    $geshi = new GeSHi($source, $lang2geshi);
    $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
    $geshi->set_overall_style('font: normal normal 100% monospace; color: #000066;', false);
    $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
    $geshi->set_code_style('color: #000020;font-family:monospace; font-size:12px;line-height:13px;', true);
    $geshi->enable_classes(false);
    $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
    $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
    $return = "<div class=\"codetop\">Code</div><div class=\"codemain\">\n";
    $return .= $geshi->parse_code();
    $return .= "\n</div>\n";
    return $return;
}
Esempio n. 8
0
function AffichageSource($type, $lang, $nom)
{
    if (preg_match("#^../#", $nom) == TRUE) {
        $result = "Erreur lors du chargement du script";
    } else {
        $language = str_replace('.', '', strstr($nom, '.'));
        $source = '';
        $script = 'fichiers/' . $type . '/' . $lang . '/' . $nom;
        if (file_exists($script)) {
            $contenu = file($script);
            while (list($cle, $val) = each($contenu)) {
                $source .= $val;
            }
        }
        $geshi = new GeSHi($source, $language);
        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
        $geshi->set_overall_style('font-size:11px;width:580px;', true);
        $geshi->set_line_style('background: #fcfcfc;', 'background: #f0f0f0;');
        $result = $geshi->parse_code();
    }
    $result .= '<div align=center><a href="?page=' . $type . '">Retour</a></div>';
    return $result;
}
/**
 * User handler for code block
 *
 * @param TexyHandlerInvocation  handler invocation
 * @param string  block type
 * @param string  text to highlight
 * @param string  language
 * @param TexyModifier modifier
 * @return TexyHtml
 */
function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
{
    if ($blocktype !== 'block/code') {
        return $invocation->proceed();
    }
    $texy = $invocation->getTexy();
    global $geshiPath;
    if ($lang == 'html') {
        $lang = 'html4strict';
    }
    $content = Texy::outdent($content);
    $geshi = new GeSHi($content, $lang, $geshiPath . 'geshi/');
    // GeSHi could not find the language
    if ($geshi->error) {
        return $invocation->proceed();
    }
    // do syntax-highlighting
    $geshi->set_encoding('UTF-8');
    $geshi->set_header_type(GESHI_HEADER_PRE);
    $geshi->enable_classes();
    $geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
    $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
    $geshi->set_code_style('color: #000020;', 'color: #000020;');
    $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
    $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
    // save generated stylesheet
    $texy->styleSheet .= $geshi->get_stylesheet();
    $content = $geshi->parse_code();
    // check buggy GESHI, it sometimes produce not UTF-8 valid code :-((
    $content = iconv('UTF-8', 'UTF-8//IGNORE', $content);
    // protect output is in HTML
    $content = $texy->protect($content, Texy::CONTENT_BLOCK);
    $el = TexyHtml::el();
    $el->setText($content);
    return $el;
}
unset($lines);
unset($ccount);
unset($matches);
include_once INCLUDES . "bbcodes/geshi/geshi.php";
preg_match_all("#\\[geshi=(.*?)\\](.*?)\\[/geshi\\]#si", $text, $matches, PREG_PATTERN_ORDER);
for ($i = 0; $i < count($matches[1]); $i++) {
    $lines = explode("\n", $matches[2][$i]);
    if (count($lines) < 200) {
        $input = str_replace('<br>', '', str_replace('<br  />', '', str_replace('<br />', '', stripslashes($matches[2][$i]))));
        //replace problematic characters
        $search = array("\\", "&quot;", "&#39;", "&#92;", "&quot;", "&#39;", "&lt;", "&gt;", "&amp;");
        $replace = array("\\\\", "\"", "'", "\\", "\"", "\\'", "<", ">", "&");
        $input = str_replace($search, $replace, $input);
        $geshi = new GeSHi($input, $matches[1][$i]);
        $geshi->set_header_type(GESHI_HEADER_PRE);
        $geshi->set_overall_style('font-family:\'Courier New\', Courier; font-size:12px;');
        $geshi->set_link_styles(GESHI_LINK, 'font-weight:bold;');
        $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
        $geshi->set_footer_content($locale['bb_geshi_info']);
        $geshi->set_footer_content_style('font-family:Verdana,Arial,sans-serif;color:#808080;font-size:9px;font-weight:bold;background-color:#f0f0ff;border-top: 1px solid #d0d0d0;padding:2px;width:400px');
        if (preg_match("/\\/forum\\//i", FUSION_REQUEST) && isset($data['post_id'])) {
            $geshi_save = "<a href='" . INCLUDES . "bbcodes/geshi_bbcode_save.php?thread_id=" . $_GET['thread_id'] . "&amp;post_id=" . $data['post_id'] . "&amp;code_id=" . $i . "'><img src='" . INCLUDES . "bbcodes/images/geshi_save.png' alt='" . $locale['bb_geshi_save'] . "' title='" . $locale['bb_geshi_save'] . "' style='border:none' /></a>&nbsp;&nbsp;";
        } else {
            $geshi_save = "";
        }
        $text = preg_replace("#\\[geshi=(.*?)\\](.*?)\\[/geshi\\]#si", '$2', $text);
        $text = str_replace($matches[2][$i], "<div class='tbl-border tbl2' style='width:400px'>" . $geshi_save . "<strong>GeSHi: " . $geshi->get_language_name() . "</strong></div><div class='tbl-border tbl1' style='width:400px;height:auto;white-space:nowrap;overflow:auto;background-color:#ffffff;'><code style='white-space:nowrap'>" . $geshi->parse_code() . "</code></div>", $text);
    } else {
        $ccount = substr_count($text, "[geshi=");
        for ($i = 0; $i < $ccount; $i++) {
Esempio n. 11
0
 private function highlight(&$text, $lang = 'php', $lines = false)
 {
     $geshi = new GeSHi(trim($text, "\r\n"), $lang);
     $geshi->enable_classes();
     $geshi->set_header_type(GESHI_HEADER_PRE);
     $geshi->set_overall_class("code");
     $geshi->set_encoding("utf-8");
     // [[mw:user:Brianegge]] suggestion
     $geshi->set_overall_style('background: #EEEEEE; border: padding: 0.2em');
     if ($lines == true or $lines == 1 or $lines == '1') {
         $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     } else {
         $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
     }
     return "<style>" . $geshi->get_stylesheet() . "</style>" . $geshi->parse_code();
 }
Esempio n. 12
0
 static function texyBlockHandler($invocation, $blocktype, $content, $lang, $modifier)
 {
     if ($blocktype !== 'block/code') {
         return $invocation->proceed();
     }
     $texy = $invocation->getTexy();
     if ($lang == 'html') {
         $lang = 'html4strict';
     } elseif ($lang == 'yaml') {
         $lang = 'python';
     }
     $content = Texy::outdent($content);
     $geshi = new GeSHi($content, $lang);
     // GeSHi could not find the language
     if ($geshi->error) {
         return $invocation->proceed();
     }
     // do syntax-highlighting
     $geshi->set_encoding('UTF-8');
     $geshi->set_header_type(GESHI_HEADER_PRE);
     $geshi->enable_classes();
     $geshi->enable_keyword_links(false);
     $geshi->set_overall_style('');
     $geshi->set_overall_class('code');
     // save generated stylesheet
     $content = $geshi->parse_code();
     // check buggy GESHI, it sometimes produce not UTF-8 valid code :-((
     $content = iconv('UTF-8', 'UTF-8//IGNORE', $content);
     // protect output is in HTML
     $content = $texy->protect($content, Texy::CONTENT_BLOCK);
     $el = TexyHtml::el();
     $el->setText($content);
     return $el;
 }
Esempio n. 13
0
        </tr>
        <?php 
drawTableBorder('b', 'white');
?>
    </table>

<?php 
// GeSHi is included in any case for the version information in the footer.
include_once '../geshi/src/geshi.php';
if (empty($error)) {
    if (empty($spec)) {
        echo '<div style="height: 128px"></div>';
    } else {
        $geshi = new GeSHi();
        $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
        $geshi->set_overall_style('background-color: #c7d1d2; font-size: small;');
        $geshi->set_line_style('background: #d3e0e7;');
        $geshi->set_header_type(GESHI_HEADER_DIV);
        echo '<div style="height: 32px"></div>';
        // writeMacroHeader
        if (!empty($p)) {
            echo '<table style="width: 70%">';
            drawTableBorder('t', 'white', FALSE, 2);
            showSourceCode($p);
            drawTableBorder('b', 'white', FALSE, 2);
            echo '</table>';
            echo '<div style="height: 16px"></div>';
        }
        // writePrototypeHeader
        if (!empty($h)) {
            echo '<table style="width: 70%">';
Esempio n. 14
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the login screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
    // -------------------------------------------------------------------------
    // Variables
    // -------------------------------------------------------------------------
    $filename_extension = get_filename_extension($net2ftp_globals["entry"]);
    // ------------------------
    // Set the state2 variable depending on the file extension !!!!!
    // ------------------------
    if (getFileType($net2ftp_globals["entry"]) == "IMAGE") {
        $filetype = "image";
    } elseif ($filename_extension == "swf") {
        $filetype = "flash";
    } else {
        $filetype = "text";
    }
    // Form name, back and forward buttons
    $formname = "ViewForm";
    $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
    // Next screen
    $nextscreen = 2;
    // -------------------------------------------------------------------------
    // Text
    // -------------------------------------------------------------------------
    if ($filetype == "text") {
        // Title
        $title = __("View file %1\$s", $net2ftp_globals["entry"]);
        // ------------------------
        // geshi_text
        // ------------------------
        setStatus(2, 10, __("Reading the file"));
        $geshi_text = ftp_readfile("", $net2ftp_globals["directory"], $net2ftp_globals["entry"]);
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        // ------------------------
        // geshi_language
        // ------------------------
        $geshi_language = "";
        $list_language_extensions = array('html4strict' => array('html', 'htm'), 'javascript' => array('js'), 'css' => array('css'), 'php' => array('php', 'php5', 'phtml', 'phps'), 'perl' => array('pl', 'pm', 'cgi'), 'sql' => array('sql'), 'java' => array('java'), 'actionscript' => array('as'), 'ada' => array('a', 'ada', 'adb', 'ads'), 'apache' => array('conf'), 'asm' => array('ash', 'asm'), 'asp' => array('asp'), 'bash' => array('sh'), 'c' => array('c', 'h'), 'c_mac' => array('c'), 'caddcl' => array(), 'cadlisp' => array(), 'cpp' => array('cpp'), 'csharp' => array(), 'd' => array(''), 'delphi' => array('dpk'), 'diff' => array(''), 'email' => array('eml', 'mbox'), 'lisp' => array('lisp'), 'lua' => array('lua'), 'matlab' => array(), 'mpasm' => array(), 'nsis' => array(), 'objc' => array(), 'oobas' => array(), 'oracle8' => array(), 'pascal' => array('pas'), 'python' => array('py'), 'qbasic' => array('bi'), 'smarty' => array('tpl'), 'vb' => array('bas'), 'vbnet' => array(), 'vhdl' => array(), 'visualfoxpro' => array(), 'xml' => array('xml'));
        while (list($language, $extensions) = each($list_language_extensions)) {
            if (in_array($filename_extension, $extensions)) {
                $geshi_language = $language;
                break;
            }
        }
        // ------------------------
        // geshi_path
        // ------------------------
        $geshi_path = NET2FTP_APPLICATION_ROOTDIR . "/plugins/geshi/geshi/";
        // ------------------------
        // Call geshi
        // ------------------------
        setStatus(4, 10, __("Parsing the file"));
        $geshi = new GeSHi($geshi_text, $geshi_language, $geshi_path);
        $geshi->set_encoding(__("iso-8859-1"));
        $geshi->set_header_type(GESHI_HEADER_PRE);
        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
        //		$geshi->enable_classes();
        $geshi->set_overall_style('border: 2px solid #d0d0d0; background-color: #f6f6f6; color: #000066; padding: 10px;', true);
        $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
        $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
        $geshi->set_tab_width(4);
        $geshi_text = $geshi->parse_code();
    } elseif ($filetype == "image") {
        $title = __("View image %1\$s", htmlEncode2($net2ftp_globals["entry"]));
        $image_url = printPHP_SELF("view");
        $image_alt = __("Image") . $net2ftp_globals["entry"];
    } elseif ($filetype == "flash") {
        $title = __("View Macromedia ShockWave Flash movie %1\$s", htmlEncode2($net2ftp_globals["entry"]));
        $flash_url = printPHP_SELF("view");
    }
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
 /**
  * Prepare a CSS snippet suitable for use as a ParserOutput/OutputPage
  * head item
  *
  * @param GeSHi $geshi
  * @return string
  */
 public static function buildHeadItem($geshi)
 {
     global $wgUseSiteCss, $wgSquidMaxage;
     // begin Wikia change
     // VOLDEV-85
     // backporting core fix to monobook font size
     /**
      * GeSHi comes by default with a font-family set to monospace, which
      * causes the font-size to be smaller than one would expect.
      * We append a CSS hack to the default GeSHi styles: specifying 'monospace'
      * twice "resets" the browser font-size specified for monospace.
      *
      * The hack is documented in MediaWiki core under
      * docs/uidesign/monospace.html and in bug 33496.
      */
     // Preserve default since we don't want to override the other style
     // properties set by geshi (padding, font-size, vertical-align etc.)
     $geshi->set_code_style('font-family: monospace, monospace;', true);
     // No need to preserve default (which is just "font-family: monospace;")
     // outputting both is unnecessary
     $geshi->set_overall_style('font-family: monospace, monospace;', false);
     // end Wikia change
     $lang = $geshi->language;
     $css = array();
     $css[] = '<style type="text/css">/*<![CDATA[*/';
     $css[] = ".source-{$lang} {line-height: normal;}";
     $css[] = ".source-{$lang} li, .source-{$lang} pre {";
     $css[] = "\tline-height: normal; border: 0px none white;";
     $css[] = "}";
     $css[] = $geshi->get_stylesheet(false);
     $css[] = '/*]]>*/';
     $css[] = '</style>';
     return implode("\n", $css);
 }
Esempio n. 16
0
 // Use the PRE_VALID header. This means less output source since we don't have to output &nbsp;
 // everywhere. Of course it also means you can't set the tab width.
 // HEADER_PRE_VALID puts the <pre> tag inside the list items (<li>) thus producing valid HTML markup.
 // HEADER_PRE puts the <pre> tag around the list (<ol>) which is invalid in HTML 4 and XHTML 1
 // HEADER_DIV puts a <div> tag arount the list (valid!) but needs to replace whitespaces with &nbsp
 //            thus producing much larger overhead. You can set the tab width though.
 $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
 // Enable CSS classes. You can use get_stylesheet() to output a stylesheet for your code. Using
 // CSS classes results in much less output source.
 $geshi->enable_classes();
 // Enable line numbers. We want fancy line numbers, and we want every 5th line number to be fancy
 $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
 // Set the style for the PRE around the code. The line numbers are contained within this box (not
 // XHTML compliant btw, but if you are liberally minded about these things then you'll appreciate
 // the reduced source output).
 $geshi->set_overall_style('font: normal normal 90% monospace; color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', false);
 // Set the style for line numbers. In order to get style for line numbers working, the <li> element
 // is being styled. This means that the code on the line will also be styled, and most of the time
 // you don't want this. So the set_code_style reverts styles for the line (by using a <div> on the line).
 // So the source output looks like this:
 //
 // <pre style="[set_overall_style styles]"><ol>
 // <li style="[set_line_style styles]"><div style="[set_code_style styles]>...</div></li>
 // ...
 // </ol></pre>
 $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
 $geshi->set_code_style('color: #000020;', true);
 // Styles for hyperlinks in the code. GESHI_LINK for default styles, GESHI_HOVER for hover style etc...
 // note that classes must be enabled for this to work.
 $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
 $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
 /**
  * Initialise a GeSHi object to format some code, performing
  * common setup for all our uses of it
  *
  * @param string $text
  * @param string $lang
  * @return GeSHi
  */
 public static function prepare($text, $lang)
 {
     global $wgSyntaxHighlightKeywordLinks;
     self::initialise();
     $geshi = new GeSHi($text, $lang);
     if ($geshi->error() == GESHI_ERROR_NO_SUCH_LANG) {
         return null;
     }
     $geshi->set_encoding('UTF-8');
     $geshi->enable_classes();
     $geshi->set_overall_class("source-{$lang}");
     $geshi->enable_keyword_links($wgSyntaxHighlightKeywordLinks);
     // If the source code is over 100 kB, disable higlighting of symbols.
     // If over 200 kB, disable highlighting of strings too.
     $bytes = strlen($text);
     if ($bytes > 102400) {
         $geshi->set_symbols_highlighting(false);
         if ($bytes > 204800) {
             $geshi->set_strings_highlighting(false);
         }
     }
     /**
      * GeSHi comes by default with a font-family set to monospace, which
      * causes the font-size to be smaller than one would expect.
      * We append a CSS hack to the default GeSHi styles: specifying 'monospace'
      * twice "resets" the browser font-size specified for monospace.
      *
      * The hack is documented in MediaWiki core under
      * docs/uidesign/monospace.html and in bug 33496.
      */
     // Preserve default since we don't want to override the other style
     // properties set by geshi (padding, font-size, vertical-align etc.)
     $geshi->set_code_style('font-family: monospace, monospace;', true);
     // No need to preserve default (which is just "font-family: monospace;")
     // outputting both is unnecessary
     $geshi->set_overall_style('font-family: monospace, monospace;', false);
     return $geshi;
 }
Esempio n. 18
0
 /**
  * Apply syntax highlighting
  *
  * @param String $language       Code language
  * @param String $code           Code to format
  * @param bool   $enable_classes Enable the CSS class
  * @param string $style          CSS class to apply
  *
  * @return mixed
  */
 static function highlightCode($language, $code, $enable_classes = true, $style = "max-height: 100%; white-space:pre-wrap;")
 {
     if (!class_exists("GeSHi", false)) {
         CAppUI::requireLibraryFile("geshi/geshi");
     }
     $geshi = new GeSHi($code, $language);
     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     $geshi->set_overall_style($style);
     $geshi->set_overall_class("geshi");
     if ($enable_classes) {
         $geshi->enable_classes();
     }
     return $geshi->parse_code();
 }
 /**
  * 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']));
             }
         }
     }
 }
Esempio n. 20
0
function reformat_callback($matches)
{
    $geshi = new GeSHi($matches[2], $matches[1]);
    //$geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
    $geshi->set_overall_style('color:#729fcf;background:#ffffdd;border-left:6px solid #729fcf;', true);
    $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
    return $geshi->parse_code();
}
 /**
  * Process a <code> tag
  */
 private function syntax_highlight($match)
 {
     $code = $this->trim($match[2]);
     // process the match as somewhat XML
     $element = new SimpleXMLElement("<code{$match[1]}></code>");
     $attributes = $element->attributes();
     // Make sure Syntax isn't turned off
     if (isset($attributes['syntax']) && mb_strtolower($attributes['syntax']) == 'off') {
         return $match[0];
     }
     // Get language
     $lang = isset($attributes['syntax']['lang']) ? $attributes['syntax']['lang'] : false;
     if (!$lang) {
         $lang = Options::get('syntax__default_lang');
     }
     $lang = preg_replace('#[^a-zA-Z0-9\\-_]#', '', $lang);
     // should we do line highlighting
     $line = isset($attributes['syntax']['lines']) ? $attributes['syntax']['lines'] : isset($attributes['syntax']['line']) ? $attributes['syntax']['line'] : false;
     if (!$line) {
         $line = Options::get('syntax__line_numbers') ? 'on' : 'off';
     }
     // Turn off error reporting
     $er = error_reporting();
     error_reporting(0);
     // We need to include this here...
     // YOU CAN REMOVE THIS IF YOU HAVE GeSHi in your user/classes
     if (!class_exists('GeSHi')) {
         require_once dirname(__FILE__) . '/geshi.php';
     }
     // Start GeSHi
     $geshi = new GeSHi($code, $lang);
     // we enable classes and use a stylehseet,
     // saves output time
     $geshi->enable_classes(true);
     $geshi->enable_keyword_links(false);
     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS, 5);
     //$geshi->enable_line_numbers( GESHI_FANCY_LINE_NUMBERS, 5 );
     // remove PRE default style
     $geshi->set_overall_style('', false);
     $parsed = $geshi->parse_code();
     error_reporting($er);
     // create output
     $output = "";
     $count = count(explode("\n", $code));
     if ($line == 'on' && $count > 1) {
         $output .= "<table><tr><td class=\"line_numbers\"><pre>";
         $this->line_numbers($code, $output, $count, Options::get('syntax__start_on_one'));
         $output .= "</pre></td><td class=\"code\">{$parsed}</td></tr></table>";
     } else {
         $output .= $parsed;
     }
     return "<div class=\"syntax_highlight\">{$output}</div>";
 }
Esempio n. 22
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;
 }
 /**
  * Highlights the content parts marked as source code using the GeSHi
  * class.
  * @author  Björn Detert <*****@*****.**>
  * @version 20. 9. 2006
  * @param   string $content The text to be parsed
  * @param   object $parent  The calling object (regulary of type tx_mmforum_pi1), so this
  *                          object inherits all configuration and language options from the
  *                          calling object.
  * @param   array  $conf    The calling plugin's configuration vars
  * @return  string          The parsed string
  */
 function syntaxhighlighting($content, $parent, $conf)
 {
     /* Path to Geshi Syntax-Highlighting files. */
     $path = GeneralUtility::getFileAbsFileName('EXT:mm_forum/res/geshi/geshi/', $onlyRelative = 1, $relToTYPO3_mainDir = 0);
     $conf['postparser.']['tsrefUrl'] ? define('GESHI_TS_REF', $conf['postparser.']['tsrefUrl']) : define('GESHI_TS_REF', 'www.typo3.net');
     $res = $this->databaseHandle->exec_SELECTquery('lang_title,lang_pattern,lang_code', 'tx_mmforum_syntaxhl', 'deleted=0');
     while ($data = $this->databaseHandle->sql_fetch_assoc($res)) {
         preg_match_all($data['lang_pattern'], $content, $source_arr);
         while (list($key, $value) = each($source_arr[1])) {
             $value = trim($this->decode_entities($value));
             if ($data['lang_title'] == 'php') {
                 if (!preg_match("/<\\?/", trim(substr($value, 0, 6)))) {
                     $value = "<?\n" . $value . "\n?>";
                 }
             }
             $geshi = new GeSHi($value, $data['lang_code'], $path);
             $geshi->set_header_type(GESHI_HEADER_PRE);
             #$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
             $geshi->set_line_style('background: ' . $conf['postparser.']['sh_linestyle_bg'] . ';', 'background: ' . $conf['postparser.']['sh_linestyle_bg2'] . ';', true);
             $geshi->set_overall_style('margin:0px;', true);
             $geshi->enable_classes();
             $style = '<style type="text/css"><!--';
             $style .= $geshi->get_stylesheet();
             $style .= '--></style>';
             $geshi->enable_strict_mode('FALSE');
             $replace = $geshi->parse_code();
             $time = $geshi->get_time();
             $CodeHead = '<div class="tx-mmforum-pi1-codeheader">' . strtoupper($data['lang_title']) . '</div>';
             // $code_header , check this out?? I get confused ^^
             $replace = '###DONT_PARSE_AGAIN_START###' . $CodeHead . '<div class="tx-mmforum-pi1-codeblock">' . $style . $replace . '</div>###DONT_PARSE_AGAIN_ENDE###';
             $content = str_replace($source_arr[0][$key], $replace, $content);
         }
     }
     return $content;
 }
Esempio n. 24
0
<?php

ini_set('include_path', '/Users/nathanielmchugh/nmdev/geshi');
require 'geshi.php';
$filename = $_GET['file'];
$source = file_get_contents(__DIR__ . '/' . $filename);
$language = 'php';
//
$geshi = new GeSHi($source, $language);
$geshi->enable_classes();
$geshi->set_overall_style('background-color: #ffffee;', true);
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 0);
echo '<html>
<head><title>Code</title>
<style type="text/css">
<!--';
// Echo out the stylesheet for this code block
echo $geshi->get_stylesheet();
// And continue echoing the page
echo '-->
	</style>
</head>
<body>';
echo $geshi->parse_code();
echo '</body>';
Esempio n. 25
0
                        </form>
                    </div>
                ';
                }
                echo '</div>';
            } else {
                echo '<br />';
                print_error("We couldn't retrieve the device information from Oxidized");
                $text = '';
            }
        }
    }
    //end if
    if (!empty($text)) {
        if (isset($previous_config)) {
            $language = 'diff';
        } else {
            $language = 'ios';
        }
        $geshi = new GeSHi($text, $language);
        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
        $geshi->set_overall_style('color: black;');
        // $geshi->set_line_style('color: #999999');
        echo '<div class="config">';
        echo '<input id="linenumbers" class="btn btn-primary" type="submit" value="Hide line numbers"/>';
        echo $geshi->parse_code();
        echo '</div>';
    }
}
//end if
$pagetitle[] = 'Config';
 function ch_highlight_code($matches)
 {
     global $ch_options;
     // undo nl and p formatting
     $plancode = $matches[2];
     $plancode = $this->entodec($plancode);
     $geshi = new GeSHi($plancode, strtolower($matches[1]));
     $geshi->set_encoding('utf-8');
     $geshi->set_header_type(GESHI_HEADER_DIV);
     $geshi->enable_classes(true);
     $language = $geshi->get_language_name();
     if ($language == 'PHP') {
         $geshi->add_keyword(2, 'protected');
         $geshi->add_keyword(2, 'private');
         $geshi->add_keyword(2, 'abstract');
         $geshi->add_keyword(2, 'static');
         $geshi->add_keyword(2, 'final');
         $geshi->add_keyword(2, 'implements');
     } elseif ($language == 'Bash') {
         $geshi->add_keyword(2, 'convert');
         $geshi->add_keyword(2, 'git');
     } elseif ($language == 'Vim Script') {
         $geshi->add_keyword(1, 'endfunction');
     }
     if (ch_go('ch_b_linenumber')) {
         $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     }
     $geshi->enable_strict_mode(ch_go('ch_b_strict_mode'));
     $geshi->set_tab_width(ch_go('ch_in_tab_width'));
     $geshi->set_overall_class('dean_ch');
     $overall_style = '';
     if (!ch_go("ch_b_wrap_text")) {
         $overall_style .= 'white-space: nowrap;';
     } else {
         $overall_style .= 'white-space: wrap;';
     }
     if ($overall_style != '') {
         $geshi->set_overall_style($overall_style, false);
     }
     return $geshi->parse_code();
 }
Esempio n. 27
0
//$geshi->set_line_style('background: #fcfcfc;', true);
Yii::app()->clientScript->registerCss('highlightcode2', $geshi->get_stylesheet());
echo $geshi->parse_code();
?>

<p>&nbsp;</p>
<p>Now we modify our function:<br>
&nbsp;</p>
<?php 
$source = "\nvar counter = 0;\nvar reset_comment = false;\nvar comment_id = 0;\nvar subject_id = 0;\n\nfunction getLiveInfo(){\n\t\$.getJSON('http://samesub.com/api/v1/live/getall?callback=?',\n\t\t{subject_id:subject_id, coment_id:comment_id},\n\t\tfunction(data) {\n\t\t\t//If everything is ok(response_code == 200), let's print some LIVE information\n\t\t\tif(data.response_code == 200){\n\t\t\t\tcounter = data.time_remaining;\n\t\t\t\tif(data.new_sub != 0 || data.new_comment != 0 ){\n\t\t\t\t\tif(data.new_sub != 0) {\n\t\t\t\t\t\t//Every time there is a nuew sub, comments must be cleared\n\t\t\t\t\t\treset_comment=true;\n\t\t\t\t\t\tcomment_id = 0;\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t//Display subject\n\t\t\t\t\t\tsubject_id = data.subject_id;\n\t\t\t\t\t\t\$('#title').html(data.title);\n\t\t\t\t\t\t\$('#time_remaining').html(data.time_remaining + ' seconds.');\n\t\t\t\t\t}\n\t\t\t\t\tif(data.new_comment != 0){\n\t\t\t\t\t\tcomment_id = data.comment_id;\n\t\t\t\t\t\tshow_comments(data.comments);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\t//Otherwise alert data.response_message\t\t\t\t\n\t\t\t\talert(data.response_message);\n\t\t\t}\n\t\t}\n\t);\n\tvar aa = setTimeout('getLiveInfo()',8000);\n}\n\nfunction show_comments(comments){\n\tif(reset_comment == true) {\n\t\t\$('#comments_box').html('');//Clear all previous comments\n\t}\n\tfor(var i in comments) {\n\t\t\$('#comments_box').prepend(comments[i]['comment_text']+ '<br />');\n\t}\n}\n\nvar myInterval = setInterval(\n\tfunction(){\n\t\tcounter = counter - 1;\n\t\t\$('#time_remaining').html(counter + ' seconds.');\n\t}\n,1000);\n";
$language = 'Javascript';
$geshi = new GeSHi($source, $language);
$geshi->enable_classes();
$geshi->set_overall_class('myjs_no_lines');
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->set_overall_style("padding:1px 15px 1px 15px;border:1px solid #999999;background: #fcfcfc;font: normal normal 1em/1.2em monospace;");
$geshi->set_tab_width(2);
//$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
//$geshi->set_line_style('background: #fcfcfc;', true);
Yii::app()->clientScript->registerCss('highlightcode2', $geshi->get_stylesheet());
echo $geshi->parse_code();
?>
<p>&nbsp;</p>
<p>As you can see there are several changes: </p>
<ol>
	<li>We have declared few global variables.</li>
	<li>We have splitted our function in three main parts: the <b>getLiveInfo</b> 
	function itself, the <b>show_comments</b> function, and the interval 
	function.</li>
	<li>Notice that now we are sending two data parameters to the <b>getJSON</b> 
	jquery function; the <b>subject_id</b> and <b>comment_id</b> parameters.</li>
Esempio n. 28
0
$real_path = realpath($path);
if (strncmp($real_path, SOURCE_ROOT, $base_path_len)) {
    exit("Access outside acceptable path.");
}
// Check file exists
if (!file_exists($path)) {
    exit("File not found ({$path}).");
}
// Prepare GeSHi instance
$geshi = new GeSHi();
$geshi->set_language('text');
$geshi->load_from_file($path);
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->enable_classes();
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
$geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
$geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
$geshi->set_code_style('color: #000020;', 'color: #000020;');
$geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
$geshi->set_header_content('Source code viewer - ' . $path . ' - ' . $geshi->get_language_name());
$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;');
$geshi->set_footer_content('Parsed in <TIME> seconds,  using GeSHi <VERSION>');
$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Source code viewer - <?php 
echo $path;
Esempio n. 29
0
<?php

error_reporting(1);
header('Content-Type:text/plain; charset=utf-8');
if (!empty($_POST['UGC']) && !empty($_POST['UGL'])) {
    include_once dirname(__FILE__) . '/geshi.php';
    if (get_magic_quotes_gpc()) {
        $_POST['UGC'] = stripslashes($_POST['UGC']);
    }
    $_POST['UGC'] = stripslashes($_POST['UGC']);
    $_POST['UGL'] = strtolower($_POST['UGL']);
    $GeSHi = new GeSHi($_POST['UGC'], $_POST['UGL']);
    //$GeSHi->enable_classes();
    $GeSHi->set_header_type(GESHI_HEADER_NONE);
    $GeSHi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
    $GeSHi->enable_keyword_links(false);
    $GeSHi->set_overall_style('');
    $GeSHi->set_tab_width(4);
    echo $GeSHi->parse_code();
}
Esempio n. 30
0
            }
        }
    }
    $drop['text'] = implode("\n", $drop['text']);
}
//geshi object
$geshi = new GeSHi(stripslashes($drop['text']), $drop['lang']);
$geshi->highlight_lines_extra($highlight);
$geshi->set_tab_width(4);
$geshi->set_highlight_lines_extra_style('background:#FFFF88;');
$geshi->enable_keyword_links(false);
//geshi line numbers
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_header_type(GESHI_HEADER_DIV);
//geshi styling for syntax box
$geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #fdfdf6; line-height:1.3em;', true);
$geshi->set_line_style('font: normal normal \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060; padding-right: 5px;', true);
$geshi->set_code_style('color: #000020;', 'color: #000020;');
if ($drop['editable'] == 1) {
    if (!isset($_GET['passkey'])) {
        $editable = ' You may <a href="' . $DROP_CONF_siteURL . '/' . $drop['id'] . '/edit">edit this</a> drop.';
    } else {
        $editable = ' You may <a href="' . substr($_SERVER['REQUEST_URI'], 0, -30) . '/edit?pkey=' . $_GET['passkey'] . '">edit this</a> drop.';
    }
} else {
    if ($drop['editable'] == 0) {
        $editable = '';
    } else {
        die("WOAH! WE HAVE AN ERROR IN THE HOUSE!!! CONTACT THE AUTHORITIES!");
    }
}