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>'; } }
/** * Highlights the passed source code as css * * @param $source */ function textsanitizer_geshi_css_highlight($source) { if (!@(include_once ICMS_LIBRARIES_PATH . '/geshi/geshi.php')) { return false; } $source = icms_core_DataFilter::undoHtmlSpecialChars($source); // Create the new GeSHi object, passing relevant stuff $geshi = new GeSHi($source, 'css'); // Enclose the code in a <div> $geshi->set_header_type(GESHI_HEADER_NONE); // Sets the proper encoding charset other than "ISO-8859-1" $geshi->set_encoding(_CHARSET); $geshi->set_link_target("_blank"); // Parse the code $code = $geshi->parse_code(); $code = "<div class=\"icmsCodeCss\"><code>" . $code . "</code></div>"; return $code; }
/** * Wrapper for GeSHi Code Highlighter, provides caching of its output * * @param string $code source code to be highlighted * @param string $language language to provide highlighting * @param string $wrapper html element to wrap the returned highlighted text * * @author Christopher Smith <*****@*****.**> * @author Andreas Gohr <*****@*****.**> */ function p_xhtml_cached_geshi($code, $language, $wrapper = 'pre') { global $conf, $config_cascade, $INPUT; $language = strtolower($language); // remove any leading or trailing blank lines $code = preg_replace('/^\\s*?\\n|\\s*?\\n$/', '', $code); $cache = getCacheName($language . $code, ".code"); $ctime = @filemtime($cache); if ($ctime && !$INPUT->bool('purge') && $ctime > filemtime(DOKU_INC . 'inc/geshi.php') && $ctime > @filemtime(DOKU_INC . 'inc/geshi/' . $language . '.php') && $ctime > filemtime(reset($config_cascade['main']['default']))) { // dokuwiki changed $highlighted_code = io_readFile($cache, false); } else { $geshi = new GeSHi($code, $language, DOKU_INC . 'inc/geshi'); $geshi->set_encoding('utf-8'); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_link_target($conf['target']['extern']); // remove GeSHi's wrapper element (we'll replace it with our own later) // we need to use a GeSHi wrapper to avoid <BR> throughout the highlighted text $highlighted_code = trim(preg_replace('!^<pre[^>]*>|</pre>$!', '', $geshi->parse_code()), "\n\r"); io_saveFile($cache, $highlighted_code); } // add a wrapper element if required if ($wrapper) { return "<{$wrapper} class=\"code {$language}\">{$highlighted_code}</{$wrapper}>"; } else { return $highlighted_code; } }
/** * Wrapper for GeSHi Code Highlighter, provides caching of its output * * @author Christopher Smith <*****@*****.**> */ function p_xhtml_cached_geshi($code, $language) { $cache = getCacheName($language . $code, ".code"); if (@file_exists($cache) && !$_REQUEST['purge'] && filemtime($cache) > filemtime(DOKU_INC . 'inc/geshi.php')) { $highlighted_code = io_readFile($cache, false); @touch($cache); } else { require_once DOKU_INC . 'inc/geshi.php'; $geshi = new GeSHi($code, strtolower($language), DOKU_INC . 'inc/geshi'); $geshi->set_encoding('utf-8'); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_overall_class("code {$language}"); $geshi->set_link_target($conf['target']['extern']); $highlighted_code = $geshi->parse_code(); io_saveFile($cache, $highlighted_code); } return $highlighted_code; }
/** * Callback for code text * * Uses GeSHi to highlight language syntax * * @author Andreas Gohr <*****@*****.**> */ function code($text, $language = NULL) { global $conf; if (is_null($language)) { $this->preformatted($text); } else { //strip leading blank line $text = preg_replace('/^\\s*?\\n/', '', $text); // Handle with Geshi here require_once DOKU_INC . 'inc/geshi.php'; $geshi = new GeSHi($text, strtolower($language), DOKU_INC . 'inc/geshi'); $geshi->set_encoding('utf-8'); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_overall_class("code {$language}"); $geshi->set_link_target($conf['target']['extern']); $text = $geshi->parse_code(); $this->doc .= $text; } }
/** * 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'])); } } } }
/** * Syntaxhighlight the code using Geshi highlight * * @param string $text The text to highlight * @return string $code the highlighted text */ public static function textsanitizer_geshi_highlight($text) { global $icmsConfigPlugins; if (!@(include_once ICMS_LIBRARIES_PATH . '/geshi/geshi.php')) { return false; } $language = str_replace('.php', '', $icmsConfigPlugins['geshi_default']); // Create the new GeSHi object, passing relevant stuff $geshi = new GeSHi($text, $language); // Enclose the code in a <div> $geshi->set_header_type(GESHI_HEADER_NONE); // Sets the proper encoding charset other than "ISO-8859-1" $geshi->set_encoding(_CHARSET); $geshi->set_link_target('_blank'); // Parse the code $code = $geshi->parse_code(); return $code; }
/** * Wrapper for GeSHi Code Highlighter, provides caching of its output * Modified to calculate cache from URL so we don't have to re-download time and again * * @author Christopher Smith <*****@*****.**> * @author Esther Brunner <*****@*****.**> */ function _cached_geshi($url, $refresh) { global $conf; $cache = getCacheName($url, '.code'); $mtime = @filemtime($cache); // 0 if it doesn't exist if ($mtime != 0 && !$_REQUEST['purge'] && $mtime > time() - $refresh && $mtime > filemtime(DOKU_INC . 'inc/geshi.php')) { $hi_code = io_readFile($cache, false); if ($conf['allowdebug']) { $hi_code .= "\n<!-- cachefile {$cache} used -->\n"; } } else { require_once DOKU_INC . 'inc/geshi.php'; // get the source code language first $search = array('/^htm/', '/^js$/'); $replace = array('html4strict', 'javascript'); $lang = preg_replace($search, $replace, substr(strrchr($url, '.'), 1)); // download external file $http = new DokuHTTPClient(); $http->timeout = 25; //max. 25 sec $code = $http->get($url); $geshi = new GeSHi($code, strtolower($lang), DOKU_INC . 'inc/geshi'); $geshi->set_encoding('utf-8'); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_overall_class("code {$language}"); $geshi->set_link_target($conf['target']['extern']); $hi_code = $geshi->parse_code(); io_saveFile($cache, $hi_code); if ($conf['allowdebug']) { $hi_code .= "\n<!-- no cachefile used, but created -->\n"; } } return $hi_code; }
function main($dir,$item,&$pObj) { global $LANG; if(!t3quixplorer_div::get_is_file($dir, $item)) t3quixplorer_div::showError($item.": ".$LANG->getLL("error.fileexists")); if(!t3quixplorer_div::get_show_item($dir, $item)) t3quixplorer_div::showError($item.": ".$LANG->getLL("error.accessfile")); $fname = t3quixplorer_div::get_abs_item($dir, $item); $fileinfo = t3lib_div::split_fileref($fname); $ext = $fileinfo['fileext']; $theight = ($GLOBALS["T3Q_VARS"]["textarea_height"] && is_numeric($GLOBALS["T3Q_VARS"]["textarea_height"]))?$GLOBALS["T3Q_VARS"]["textarea_height"]:20; $pObj->doc->JScode = ' <script id="prototype-script" type="text/javascript" src="../../t3scodehighlight/contrib/prototype/prototype.js"> </script> <script src="../../t3scodehighlight/contrib/codepress/codepress.js" type="text/javascript" id="cp-script" lang="en-us"></script> <link type="text/css" rel="stylesheet" href="../../t3scodehighlight/contrib/codepress/t3codepress.css"> </link> <script src="../../t3scodehighlight/contrib/codepress/content/en-us.js" type="text/javascript" id="cp-script" lang="en-us"></script> <script src="../../t3scodehighlight/contrib/codepress/t3codepress_t3lib_tceforms.js" type="text/javascript" id="t3codepress-t3libtceforms-script"></script> <script type="text/javascript"> function closeDoc(){ window.location=\''.t3quixplorer_div::make_link("list",$dir,NULL).'\'; } </script> '; $content= array(); if(t3lib_div::_POST("dosave") && t3lib_div::_POST("dosave")=="yes") { // Save / Save As $item=basename(stripslashes(t3lib_div::_POST("fname"))); $fname2=t3quixplorer_div::get_abs_item($dir, $item); if(!isset($item) || $item=="") t3quixplorer_div::showError($LANG->getLL("error.miscnoname")); if($fname!=$fname2 && @file_exists($fname2)) t3quixplorer_div::showError($item.": ".$LANG->getLL("error.itemdoesexist")); $this->savefile($fname2); $fname=$fname2; } // open file $fp = @fopen($fname, "r"); if($fp===false) t3quixplorer_div::showError($item.": ".$LANG->getLL("error.openfile")); @fclose($fp); $fileContent = t3lib_div::getUrl($fname); // header $s_item=t3quixplorer_div::get_rel_item($dir,$item); if(strlen($s_item)>50) $s_item="...".substr($s_item,-47); //$content[]=$s_item; //changed to absolute filename as of version 1.7 ... any complaints? $content[] = $fname; //$onkeydown = $GLOBALS['T3Q_VARS']['disable_tab'] ? '' : ' onkeydown="return catchTab(this,event)" '; $fileinfo = t3lib_div::split_fileref(t3quixplorer_div::get_abs_item($dir,$item)); $lang = t3lib_div::_GP("highlight_lang"); $ext = $fileinfo['fileext']; $readme = $this->getReadme($dir); if(strlen(trim($readme))){ $readme = '<div style="border: 1px solid red; background-color: yellow; padding: 10px; display:block;">'.$readme.'</div>'; }else{ $readme = ''; } if(!$lang){ $lang = $ext; } if($item == 'setup.txt' || $item == 'config.txt'|| $item == 'constants.txt'){ $content[]= $readme.' <br /> <form id="editform" name="editform" method="post" action="'.t3quixplorer_div::make_link("edit",$dir,$item).'" > <input type="hidden" name="dosave" value="yes"> '. '<code id="content" wrap="off" title=".ts" class="cp hideLanguage" style="height: 500px; color: silver; visibility: visible;">'.t3lib_div::formatForTextarea($fileContent).'</code>' .'<textarea id="content_ta" name="content_ta" rows="'.$theight.'" wrap="off" style="width: 460px; display: none;" class="cp fixed-font enable-tab">'.t3lib_div::formatForTextarea($fileContent).'</textarea>'; }else{ $content[]= $readme.' <br /> <form id="editform" name="editform" method="post" action="'.t3quixplorer_div::make_link("edit",$dir,$item).'" > <input type="hidden" name="dosave" value="yes"> '. '<code id="content" wrap="off" title=".'.$lang.'" class="cp hideLanguage" style="height: 500px; color: silver; visibility: visible;">'.t3lib_div::formatForTextarea($fileContent).'</code>' .'<textarea id="content_ta" name="content_ta" rows="'.$theight.'" wrap="off" style="width: 460px; display: none;" class="cp fixed-font enable-tab">'.t3lib_div::formatForTextarea($fileContent).'</textarea>'; } $content[]= ' <br /> <table> <tr> <td> <input type="hidden" name="fname" value="'.$item.'"> </td> <td> <input type="submit" name="savenow" value="'.$LANG->getLL("message.btnsave").'" > </td> <td> <input type="button" value="'.$LANG->getLL("message.btnclose").'" onclick="closeDoc()"> </td></tr></table><br />'; $fileT3s = $fname; if(@is_file($fileT3s)){ require_once (t3lib_extMgm::extPath("t3quixplorer")."mod1/geshi.php"); $inputCode = file_get_contents($fileT3s); switch($ext){ case 'php': case 'php3': case 'inc': $hl = 'php'; break; case 'html': case 'htm': case 'tmpl': $hl = 'html4strict'; break; case 'js': $hl = 'javascript'; break; case 'pl': $hl = 'perl'; break; default: $hl = $ext; break; } if($item == 'setup.txt' || $item == 'config.txt'|| $item == 'constants.txt'){ $hl = 'ts'; } switch($hl){ case 'php': case 'xml': case 'sql': case 'html4strict': case 'javascript': case 'perl': case 'css': case 'smarty': $geshi = new GeSHi($inputCode,$hl,'geshi/'); $geshi->use_classes = true; $geshi->set_tab_width(4); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_link_target('_blank'); $geshi->set_line_style("font-family:'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;font-size:12px;"); $content[] = ' <style type="text/css"> .'.$hl.' *{font-size:11px;} '.$geshi->get_stylesheet().' </style> '; $content[] = '<strong>T3S-File: '.$fileT3s.'</strong></br><hr />'.$geshi->parse_code(); break; case 'ts': require_once(PATH_t3lib.'class.t3lib_tsparser.php'); $tsparser = t3lib_div::makeInstance("t3lib_TSparser"); $tsparser->lineNumberOffset=1; $formattedContent = $tsparser->doSyntaxHighlight($inputCode, array($tsparser->lineNumberOffset), 0); $content[]='<strong>T3S-File: '.$fileT3s.'</strong></br><hr />'.$formattedContent; break; default: break; } } return implode("",$content); }
<?php include_once 'geshi.php'; $source = file_get_contents('sample.ino'); $language = "arduino"; $target = "_blank"; $geshi = new GeSHi($source, $language); $geshi->set_line_style('background: #FCFCFC;'); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_link_target($target); $code = $geshi->parse_code(); // Display highlighted code echo $code; // Write highlighted code to cache... //$destination = "sample.html"; //file_put_contents( $destination, $code );