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(); } }
/** * * 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", " ", $text); $text = str_replace(" ", " ", $text); $text = "<code{$css_code}>{$text}</code>"; } return "\n{$text}\n\n"; }
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; }; }
/** * 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, '\', '$', '<'); $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("&", "&", $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('{', '}'); $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("[", "[", $ret); return $ret; }
/** * 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; }
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(); }
/** * 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; }
/** * 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 */ private static function prepare($text, $lang) { 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(false); return $geshi; }
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(); }
/** * Function called by the pre_typography extension hook before the text will be parsed by EE * @param string $str text that will be parsed * @param object $typo Typography object * @param array $prefs Preferences sent to $TYPE->parse_type * @return string text where the code has been stripped and code positions marked with an MD5-ID * @access public * @global $EXT Extension-Object to support multiple calls to the same extension hook * @global $OUT could be used to display errors - it isn't at the moment * @todo Display error using $OUT */ function pre_typography($str, $typo, $prefs) { // we don't need the DB, nor IN, nor DSP // should probably use OUT to display user_error messages global $EXT, $OUT; // here we're doing the actual work if ($EXT->last_call !== FALSE) { // A different extension has run before us $str = $EXT->last_call; } $cache_dir = dirname(__FILE__) . '/' . $this->settings['cache_dir']; $rllen = strlen($this->rlimit); $pos = array(); preg_match_all($this->llimit, $str, $matches, PREG_OFFSET_CAPTURE); foreach ($matches[0] as $key => $match) { $pos[$match[1]] = array(); $pos[$match[1]]['match'] = $match[0]; // lang (called type internally for historical reasons) if (!empty($matches[1][$key][0])) { // strip slashes for filesystem security and quotes because the value might be quoted $pos[$match[1]]['type'] = str_replace(array('/', '"', "'"), '', substr($matches[1][$key][0], 5)); } else { $pos[$match[1]]['type'] = NULL; } // strict if (!empty($matches[2][$key][0])) { switch (str_replace(array('"', "'"), '', strtolower(substr($matches[2][$key][0], 7)))) { case 'true': case '1': $pos[$match[1]]['strict'] = TRUE; break; case 'false': case '0': $pos[$match[1]]['strict'] = FALSE; break; default: $pos[$match[1]]['strict'] = NULL; break; } } else { $pos[$match[1]]['strict'] = NULL; } // line $pos[$match[1]]['line'] = !empty($matches[3][$key][0]) ? str_replace(array('"', "'"), '', substr($matches[3][$key][0], 5)) : NULL; // start $pos[$match[1]]['start'] = !empty($matches[4][$key][0]) ? str_replace(array('"', "'"), '', substr($matches[4][$key][0], 6)) : NULL; // keyword_links if (!empty($matches[5][$key][0])) { switch (str_replace(array("'", '"'), '', strtolower(substr($matches[5][$key][0], 14)))) { case 'true': case '1': $pos[$match[1]]['keyword_links'] = TRUE; break; case 'false': case '0': $pos[$match[1]]['keyword_links'] = FALSE; break; default: $pos[$match[1]]['keyword_links'] = NULL; break; } } else { $pos[$match[1]]['keyword_links'] = NULL; } // overall_class $pos[$match[1]]['overall_class'] = !empty($matches[6][$key][0]) ? str_replace(array("'", '"'), '', substr($matches[6][$key][0], 14)) : NULL; // overall_id $pos[$match[1]]['overall_id'] = !empty($matches[7][$key][0]) ? str_replace(array("'", '"'), '', substr($matches[7][$key][0], 11)) : NULL; } // clean variables used in the loop unset($matches, $key, $match); // krsort the array so we can use substr stuff and won't mess future replacements krsort($pos); // Check for the cache dir if (file_exists($cache_dir) && is_dir($cache_dir)) { $cache_dir = realpath($cache_dir) . '/'; if (!is_writable($cache_dir)) { // try to chmod it @chmod($cache_dir, 0777); if (!is_writable($cache_dir)) { // still not writable? display a warning print '<b>Warning</b>: Your <i>' . $this->name . '</i> cache directory <b>' . $cache_dir . '</b> is not writable! This will cause severe performance problems, so I suggest you chmod that dir.'; } } } else { if (!mkdir($cache_dir, 0777)) { print '<b>Warning</b>: Your <i>' . $this->name . '</i> cache directory <b>' . $cache_dir . '</b> could not be created! This will cause severe performance problems, so I suggest you create and chmod that dir.'; } else { // create an index.html so the contents will not be listed. @touch($cache_dir . 'index.html'); } } if (mt_rand(0, 10) == 10) { // on every 10th visit do the garbage collection $cur = time(); $d = dir($cache_dir); while (($f = $d->read()) !== FALSE) { if ($f != 'index.html' && $f[0] != '.') { if ($cur - filemtime($cache_dir . $f) > $this->settings['cache_cutoff']) { // File is older than cutoff, delete it. @unlink($cache_dir . $f); } } } } // loop through the code snippets $i = 0; foreach ($pos as $code_pos => $match) { $error = FALSE; if (($code_end_pos = strpos($str, $this->rlimit, (int) $code_pos + strlen($match['match']))) !== FALSE) { // we have a matching end tag. // make sure cache is regenerated when changing options, too! $md5 = md5(($not_geshified = substr($str, $code_pos + strlen($match['match']), $code_end_pos - $code_pos - strlen($match['match']))) . print_r($match, TRUE) . print_r($this->settings, TRUE)); // check whether we already have this in a cache file if (is_file($cache_dir . $md5) && is_readable($cache_dir . $md5)) { if (is_callable('file_get_contents')) { $geshified = file_get_contents($cache_dir . $md5); // this is for the garbage collection touch($cache_dir . $md5); } else { // screw PHP4! $f = fopen($cache_dir . $md5, 'r'); $geshified = fread($f, filesize($cache_dir . $md5)); fclose($f); touch($cache_dir . $md5); } } else { // no cache so do the GeSHi thing if ($this->settings['geshi_version'] == '1.1') { // use GeSHi 1.1 include_once dirname(__FILE__) . '/geshi-1.1/class.geshi.php'; // highlight code according to type setting, default to setting $geshi = new GeSHi($not_geshified, $match['type'] !== NULL ? $match['type'] : $this->settings['default_type']); $str_error = $geshi->error(); if (empty($str_error)) { // neither line numbers, nor strict mode is supported in GeSHi 1.1 yet. // in fact it does pretty much nothing // there used to be a rather large block of code here, testing wether methods were callable and call them if // that's the case. // parse the code $geshified = $geshi->parseCode(); } else { $error = TRUE; } } else { // use GeSHi 1.0 include_once dirname(__FILE__) . '/geshi-1.0/geshi.php'; // highlight code according to type setting, default to php $geshi = new GeSHi($not_geshified, $match['type'] !== NULL ? $match['type'] : $this->settings['default_type']); $str_error = $geshi->error(); if (empty($str_error)) { // enable line numbers $number_style = !empty($match['line']) ? $match['line'] : $this->settings['default_line']; switch (strtolower(preg_replace('/\\d+/', '', $number_style))) { case 'normal': $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); break; case 'fancy': $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, (int) preg_replace('/[^\\d]*/', '', $number_style)); break; case 'none': $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS); break; } // set first line number if ($match['start']) { $geshi->start_line_numbers_at($match['start']); } // set strict mode if ($match['strict']) { $geshi->enable_strict_mode(TRUE); } // enable or disable keyword links $geshi->enable_keyword_links((bool) ($match['keyword_links'] !== NULL) ? $match['keyword_links'] : $this->settings['keyword_links']); // set overall class name if ($match['overall_class'] != NULL) { $geshi->set_overall_class($match['overall_class']); } // set overall id if ($match['overall_id'] != NULL) { $geshi->set_overall_id($match['overall_id']); } // set header type switch ($this->settings['geshi_header_type']) { case 'div': $geshi->set_header_type(GESHI_HEADER_DIV); break; case 'pre': $geshi->set_header_type(GESHI_HEADER_PRE); break; case 'pre-valid': $geshi->set_header_type(GESHI_HEADER_PRE_VALID); break; case 'pre-table': $geshi->set_header_type(GESHI_HEADER_PRE_TABLE); break; case 'none': $geshi->set_header_type(GESHI_HEADER_NONE); break; } // set encoding (for legacy reasons afaik) $geshi->set_encoding($this->settings['geshi_encoding']); // parse the source code $geshified = $geshi->parse_code(); } else { $error = TRUE; } } if (!file_exists($cache_dir . $md5) && is_writable($cache_dir) || file_exists($cache_dir . $md5) && is_writable($cache_dir . $md5)) { if (!$error) { // we can write to the cache file if (is_callable('file_put_contents')) { file_put_contents($cache_dir . $md5, $geshified); @chmod($cache_dir . $md5, 0777); } else { // when will you guys finally drop PHP4 support? $f = fopen($cache_dir . $md5, 'w'); fwrite($f, $geshified); fclose($f); @chmod($cache_dir . $md5, 0777); } } } else { // We could ignore that, but for performance reasons better warn the user. print '<b>Warning</b>: Your <i>' . $this->name . '</i> cache directory <b>' . $cache_dir . '</b> is not writable! This will cause severe performance problems, so I suggest you chmod that dir.'; } } // save replacement to cache and mark location with an identifier for later replacement if (!isset($_SESSION['cache']['ext.geshify'])) { $_SESSION['cache']['ext.geshify'] = array(); } if (!$error) { $_SESSION['cache']['ext.geshify'][$md5] = $geshified; $str = substr($str, 0, $code_pos) . $md5 . substr($str, $code_end_pos + $rllen); } } // unset used variables, so we don't get messed up unset($code_pos, $code_end_pos, $md5, $geshified, $not_geshified, $geshi, $match, $ident, $error); } return $str; }
} $sourcecode = $codeObj->get(); $sourcecode['source'] = html_entity_decode($sourcecode['source'], ENT_QUOTES); ($code = $plugins->load('popup_hlcode_start')) ? eval($code) : null; if ($_GET['temp'] == 1) { viscacha_header('Content-Type: text/plain'); viscacha_header('Content-Length: ' . strlen($sourcecode['source'])); viscacha_header('Content-Disposition: attachment; filename="' . date('d-m-Y_H-i') . '.txt"'); echo $sourcecode['source']; $slog->updatelogged(); $db->close(); exit; } else { require_once 'classes/class.geshi.php'; $geshi = new GeSHi($sourcecode['source'], strtolower($sourcecode['language']), 'classes/geshi'); $geshi->set_encoding($lang->phrase('charset')); // Use classes for colouring $geshi->enable_classes(); // Output in a div instead in a pre-element $geshi->set_header_type(GESHI_HEADER_DIV); // Linenumbers on - each 5th element is bold $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5); $lang_name = $geshi->get_language_name(); // Print Stylesheet $htmlhead .= '<style type="text/css"><!-- ' . $geshi->get_stylesheet() . ' --></style>'; echo $tpl->parse("popup/header"); ($code = $plugins->load('popup_hlcode_initialized')) ? eval($code) : null; $sourcecode['hl'] = $geshi->parse_code(); echo $tpl->parse("popup/hlcode"); ($code = $plugins->load('popup_hlcode_end')) ? eval($code) : null; }
/** * Initialise a GeSHi object to format some code, performing * common setup for all our uses of it * * @note Used only until MW 1.20 * * @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 ); } } return $geshi; }
function execAction($dir, $item) { // show file contents global $action; if (@eregi($GLOBALS["images_ext"], $item)) { $html = '<img src="' . make_link('get_image', $dir, rawurlencode($item)) . '" alt="' . $GLOBALS["messages"]["actview"] . ": " . $item . '" /><br /><br />'; } elseif (@eregi($GLOBALS["editable_ext"], $item)) { $geshiFile = _EXT_PATH . '/libraries/geshi/geshi.php'; ext_RaiseMemoryLimit('32M'); // GeSHi 1.0.7 is very memory-intensive include_once $geshiFile; // Create the GeSHi object that renders our source beautiful $geshi = new GeSHi('', '', dirname($geshiFile) . '/geshi'); $file = get_abs_item($dir, $item); $pathinfo = pathinfo($file); if (ext_isFTPMode()) { $file = ext_ftp_make_local_copy($file); } if (is_callable(array($geshi, 'load_from_file'))) { $geshi->load_from_file($file); } else { $geshi->set_source(file_get_contents($file)); } if (is_callable(array($geshi, 'get_language_name_from_extension'))) { $lang = $geshi->get_language_name_from_extension($pathinfo['extension']); } else { $pathinfo = pathinfo($item); $lang = $pathinfo['extension']; } $geshi->set_language($lang); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $langs = $GLOBALS["language"]; if ($langs == "japanese") { $enc_list = array("ASCII", "ISO-2022-JP", "UTF-8", "EUCJP-WIN", "SJIS-WIN"); $_e0 = strtoupper(mb_detect_encoding($geshi->source, $enc_list, true)); if ($_e0 == "SJIS-WIN") { $_encoding = "Shift_JIS"; } elseif ($_e0 == "EUCJP-WIN") { $_e0 = "EUC-JP"; } elseif ($_e0 == "ASCII") { $_e0 = "UTF-8"; } else { $_encoding = $_e0; } $geshi->set_encoding($_encoding); } $html = $geshi->parse_code(); if ($langs == "japanese") { if (empty($lang) || strtoupper(mb_detect_encoding($html, $enc_list)) != "UTF-8") { $html = mb_convert_encoding($html, "UTF-8", $_e0); } } if (ext_isFTPMode()) { unlink($file); } $html .= '<hr /><div style="line-height:25px;vertical-align:middle;text-align:center;" class="small">Rendering Time: <strong>' . $geshi->get_time() . ' Sec.</strong></div>'; } else { $html = ' <iframe src="' . make_link('download', $dir, $item, null, null, null, '&action2=view') . '" id="iframe1" width="100%" height="100%" frameborder="0"></iframe>'; } $html = str_replace(array("\r", "\n"), array('\\r', '\\n'), addslashes($html)); ?> { "dialogtitle": "<?php echo $GLOBALS['messages']['actview'] . ": " . $item; ?> ", "height": 500, "autoScroll": true, "html": "<?php echo $html; ?> " } <?php }
public function __construct() { $app = $this; // -- global generic parameters --------------------------------------- $this['app.debug'] = true; $this['app.charset'] = 'UTF-8'; $this['app.name'] = 'easybook'; $this['app.version'] = '4.4'; $this['app.signature'] = "\n" . " | | \n" . " ,---.,---.,---., .|---.,---.,---.|__/ \n" . " |---',---|`---.| || || || || \\ \n" . " `---'`---^`---'`---|`---'`---'`---'` `\n" . " `---'\n"; // -- global directories location ------------------------------------- $this['app.dir.base'] = realpath(__DIR__ . '/../../../'); $this['app.dir.cache'] = $this['app.dir.base'] . '/app/Cache'; $this['app.dir.doc'] = $this['app.dir.base'] . '/doc'; $this['app.dir.resources'] = $this['app.dir.base'] . '/app/Resources'; $this['app.dir.plugins'] = $this['app.dir.base'] . '/src/Easybook/Plugins'; $this['app.dir.translations'] = $this['app.dir.resources'] . '/Translations'; $this['app.dir.skeletons'] = $this['app.dir.resources'] . '/Skeletons'; $this['app.dir.themes'] = $this['app.dir.resources'] . '/Themes'; // -- default edition options ----------------------------------------- // TODO: each edition type should define different values $this['app.edition.defaults'] = array('format' => 'html', 'highlight_code' => false, 'include_styles' => true, 'isbn' => null, 'labels' => array('appendix', 'chapter', 'figure'), 'margin' => array('top' => '25mm', 'bottom' => '25mm', 'inner' => '30mm', 'outter' => '20mm'), 'page_size' => 'A4', 'theme' => 'clean', 'toc' => array('deep' => 2, 'elements' => array('appendix', 'chapter')), 'two_sided' => true); // -- timer ----------------------------------------------------------- $this['app.timer.start'] = 0.0; $this['app.timer.finish'] = 0.0; // -- publishing process variables ------------------------------------ // holds the app theme dir for the current edition $this['publishing.dir.app_theme'] = ''; $this['publishing.dir.book'] = ''; $this['publishing.dir.contents'] = ''; $this['publishing.dir.resources'] = ''; $this['publishing.dir.plugins'] = ''; $this['publishing.dir.templates'] = ''; $this['publishing.dir.output'] = ''; $this['publishing.edition'] = ''; $this['publishing.items'] = array(); // the specific item currently being parsed/modified/decorated/... $this['publishing.active_item'] = array(); $this['publishing.book.slug'] = ''; $this['publishing.book.items'] = array(); // holds all the generated slugs, to avoid repetitions $this['publishing.slugs'] = array(); // holds all the internal links (used in html_chunked and epub editions) $this['publishing.links'] = array(); $this['publishing.list.images'] = array(); $this['publishing.list.tables'] = array(); $this['publishing.id'] = $this->share(function ($app) { if (null != ($isbn = $app->edition('isbn'))) { return array('scheme' => 'isbn', 'value' => $isbn); } // if the book doesn't declare an ISBN, generate // a unique ID based on RFC 4211 UUID v4 return array('scheme' => 'URN', 'value' => Toolkit::uuid()); }); // -- event dispatcher ------------------------------------------------ $this['dispatcher'] = $this->share(function () { return new EventDispatcher(); }); // -- finder ---------------------------------------------------------- $this['finder'] = function () { return new Finder(); }; // -- filesystem ------------------------------------------------------ $this['filesystem'] = $this->share(function ($app) { return new Filesystem(); }); // -- publisher ------------------------------------------------------- $this['publisher'] = $this->share(function ($app) { $outputFormat = $app->edition('format'); switch (strtolower($outputFormat)) { case 'pdf': return new PdfPublisher($app); case 'html': return new HtmlPublisher($app); case 'html_chunked': return new HtmlChunkedPublisher($app); case 'epub': case 'epub2': return new Epub2Publisher($app); //case 'epub3': // return new Epub3Publisher($app); //case 'epub3': // return new Epub3Publisher($app); default: throw new \Exception(sprintf('Unknown "%s" format for "%s" edition (allowed: "pdf", "html", "html_chunked", "epub", "epub2")', $outputFormat, $app->get('publishing.edition'))); } }); // -- parser ---------------------------------------------------------- $this['parser'] = $this->share(function ($app) { $format = strtolower($app['publishing.active_item']['config']['format']); // TODO: extensibility -> support several format parsers (RST, Textile, ...) switch ($format) { case 'md': case 'mdown': case 'markdown': return new MdParser($app); default: throw new \Exception(sprintf('Unknown "%s" format for "%s" content (easybook only supports Markdown)', $format, $app['publishing.active_item']['config']['content'])); } }); // -- twig ------------------------------------------------------------ $this['twig.options'] = array('autoescape' => false, 'charset' => $this['app.charset'], 'debug' => $this['app.debug'], 'strict_variables' => $this['app.debug']); // the twig path used by render() function. This value is set by convenience methods // (renderCustomTemplate(), renderThemeTemplate(), ...) before template rendering $this['twig.path'] = ''; // twig path for custom templates (user defined templates for book/edition) $this['twig.path.custom'] = $this->share(function ($app) { $paths = array(); // edition custom templates // <book-dir>/Resources/Templates/<edition-name>/<template-name>.twig $dir = $app['publishing.dir.templates'] . '/' . $app['publishing.edition']; if (file_exists($dir)) { $paths[] = $dir; } // edition type custom templates (epub, pdf, html, html_chunked) // <book-dir>/Resources/Templates/<edition-type>/<template-name>.twig $dir = $app['publishing.dir.templates'] . '/' . $app->edition('format'); if (file_exists($dir)) { $paths[] = $dir; } // book custom templates (same templates for all editions) // <book-dir>/Resources/Templates/<template-name>.twig $dir = $app['publishing.dir.templates']; if (file_exists($dir)) { $paths[] = $dir; } return $paths; }); // twig path for default theme templates (easybook built-in templates) $this['twig.path.theme'] = $this->share(function ($app) { $paths = array(); $theme = ucfirst($app->edition('theme')); $format = Toolkit::camelize($app->edition('format'), true); // TODO: fix the following hack if ('Epub' == $format) { $format = 'Epub2'; } // default templates for the edition/book theme // <easybook>/app/Resources/Themes/<theme>/<edition-type>/Templates/<template-name>.twig $dir = sprintf('%s/%s/%s/Templates', $app['app.dir.themes'], $theme, $format); if (file_exists($dir)) { $paths[] = $dir; } // default common templates for all the editions of the same theme // <easybook>/app/Resources/Themes/<theme>/Common/Templates/<template-name>.twig $dir = sprintf('%s/%s/Common/Templates', $app['app.dir.themes'], $theme); if (file_exists($dir)) { $paths[] = $dir; } // default base theme for every edition and every book // <easybook>/app/Resources/Themes/Base/<edition-type>/Templates/<template-name>.twig $dir = sprintf('%s/Base/%s/Templates', $app['app.dir.themes'], $format); if (file_exists($dir)) { $paths[] = $dir; } return $paths; }); // twig path for default content templates // (easybook built-in templates for contents; e.g. `license.md.twig`) $this['twig.path.contents'] = $this->share(function ($app) { $paths = array(); $theme = ucfirst($app->edition('theme')); $format = Toolkit::camelize($app->edition('format'), true); // TODO: fix the following hack if ('Epub' == $format) { $format = 'Epub2'; } // default content templates for the edition/book theme // <easybook>/app/Resources/Themes/<theme>/<edition-type>/Contents/<template-name>.twig $dir = sprintf('%s/%s/%s/Contents', $app['app.dir.themes'], $theme, $format); if (file_exists($dir)) { $paths[] = $dir; } // default content templates for every edition and every book // <easybook>/app/Resources/Themes/Base/<edition-type>/Contents/<template-name>.twig $dir = sprintf('%s/Base/%s/Contents', $app['app.dir.themes'], $format); if (file_exists($dir)) { $paths[] = $dir; } return $paths; }); $this['twig.loader'] = function () use($app) { return new \Twig_Loader_Filesystem($app['twig.path']); }; $this['twig'] = function () use($app) { $twig = new \Twig_Environment($app['twig.loader'], $app['twig.options']); $twig->addExtension(new TwigCssExtension()); $twig->addGlobal('app', $app); if (null != $app->get('book')) { $twig->addGlobal('book', $app->get('book')); $publishingEdition = $app->get('publishing.edition'); $editions = $app->book('editions'); $twig->addGlobal('edition', $editions[$publishingEdition]); } return $twig; }; // -- princeXML ------------------------------------------------------- $this['prince.default_paths'] = array('/usr/local/bin/prince', '/usr/bin/prince', 'C:\\Program Files\\Prince\\engine\\bin\\prince.exe'); $this['prince'] = $app->share(function () use($app) { // look for the executable file of PrinceXML $princePath = null; foreach ($app['prince.default_paths'] as $path) { if (file_exists($path)) { $princePath = $path; break; } } if (null == $princePath) { echo sprintf(" In order to generate PDF files, PrinceXML library must be installed. \n\n" . " We couldn't find PrinceXML executable in any of the following directories: \n" . " -> %s \n\n" . " If you haven't installed it yet, you can download a fully-functional demo at: \n" . " %s \n\n" . " If you have installed in a custom directory, please type its full absolute path:\n > ", implode($app['prince.default_paths'], "\n -> "), 'http://www.princexml.com/download'); $input = trim(fgets(STDIN)); if (file_exists($input)) { $princePath = $input; echo "\n"; } else { throw new \Exception(sprintf("We couldn't find the PrinceXML executable in the given directory (%s)", $input)); } } $prince = new Prince($princePath); $prince->setHtml(true); return $prince; }); // -- slugger --------------------------------------------------------- $this['slugger'] = $app->share(function () use($app) { return new Slugger($app); }); // -- code syntax highlighter ----------------------------------------- $this['geshi'] = function () use($app) { require_once __DIR__ . '/../../../vendor/geshi/geshi/geshi.php'; $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; }; // -- labels --------------------------------------------------------- $this['labels'] = $app->share(function () use($app) { $labels = Yaml::parse($app['app.dir.translations'] . '/labels.' . $app->book('language') . '.yml'); // books can define their own labels files if (null != ($customLabelsFile = $app->getCustomLabelsFile())) { $customLabels = Yaml::parse($customLabelsFile); return Toolkit::array_deep_merge($labels, $customLabels); } return $labels; }); // -- titles ---------------------------------------------------------- $this['titles'] = $app->share(function () use($app) { $titles = Yaml::parse($app['app.dir.translations'] . '/titles.' . $app->book('language') . '.yml'); // books can define their own titles files if (null != ($customTitlesFile = $app->getCustomTitlesFile())) { $customTitles = Yaml::parse($customTitlesFile); return Toolkit::array_deep_merge($titles, $customTitles); } return $titles; }); }
/** * 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; }
function fox_code($atts, $thing) { global $file_base_path, $thisfile, $fox_code_prefs; if (isset($fox_code_prefs)) { foreach (array('fileid', 'filename', 'language', 'lines', 'startline', 'overallclass', 'tabs', 'css', 'keywordslinks', 'encoding', 'fromline', 'toline') as $value) { ${$value} = $fox_code_prefs[$value]; } } else { extract(lAtts(array('fileid' => '', 'filename' => '', 'language' => 'php', 'lines' => '1', 'startline' => '1', 'overallclass' => '', 'tabs' => '2', 'css' => '0', 'keywordslinks' => '0', 'encoding' => 'UTF-8', 'fromline' => '', 'toline' => ''), $atts)); } if (!$thisfile) { if ($fileid) { $thisfile = fileDownloadFetchInfo('id = ' . intval($fileid)); } else { if ($filename) { $thisfile = fileDownloadFetchInfo("filename = '" . $filename . "'"); } else { $local_notfile = false; } } } if (!empty($thisfile)) { $filename = $thisfile['filename']; $fileid = $thisfile['id']; if (!empty($fromline) || !empty($toline)) { $handle = fopen($file_base_path . '/' . $filename, "r"); $fromline = !empty($fromline) ? intval($fromline) : intval(1); $toline = !empty($toline) ? intval($toline) : intval(-1); $currentLine = 0; $code = ""; while (!feof($handle)) { $currentLine++; if ($currentLine >= $fromline && ($toline < 0 || $currentLine <= $toline)) { $code .= fgets($handle); } else { fgets($handle); } } fclose($handle); $startline = $fromline; } else { $code = file_get_contents($file_base_path . '/' . $filename); } } else { if (strlen($fox_code_prefs['code']) > 0) { $code = $fox_code_prefs['code']; } else { $code = $thing; } } if (!$overallclass) { $overallclass = $language; } require_once 'geshi.php'; $geshi = new GeSHi(trim($code, "\r\n"), $language); if ((bool) $css) { $geshi->enable_classes(); $geshi->set_overall_class($overallclass); } $geshi->start_line_numbers_at($startline); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->set_encoding($encoding); $geshi->set_tab_width(intval($tabs)); $geshi->enable_keyword_links((bool) $keywordslinks); $geshi->enable_line_numbers((bool) $lines); if (!isset($local_notfile)) { $thisfile = NULL; } return $geshi->parse_code(); }
function plugin_geshi_highlight_code($source, $options) { if (class_exists('GeSHi') === false) { require PLUGIN_GESHI_LIB_DIR . 'geshi.php'; } $geshi = new GeSHi($source, $options['language']); $geshi->set_encoding(CONTENT_CHARSET); if (PLUGIN_GESHI_USE_CSS) { $geshi->enable_classes(); } $class = 'geshi'; if (version_compare(GESHI_VERSION, '1.0.8', '<')) { $class .= ' ' . $options['language']; } if ($options['number']) { $class .= ' number'; } $geshi->set_overall_class($class); if ($options['number']) { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->start_line_numbers_at($options['start']); plugin_geshi_read_setting($geshi, 'default'); plugin_geshi_read_setting($geshi, $options['language']); switch ($geshi->header_type) { case GESHI_HEADER_PRE: $before = array('<ol', '/ol>', '</div', '> ', ' '); $after = array('<code><object><ol style="margin-top: 0; margin-bottom: 0;"', '/ol></object></code>', "\n</div", '> ', ' '); break; case GESHI_HEADER_PRE_TABLE: $before = array(" \n"); $after = array("\n"); if (PLUGIN_GESHI_USE_CSS) { $before[] = '"><td class="'; $after[] = '"><td class="de1 '; } else { $before[] = '"><td'; $after[] = '"><td style="' . $geshi->code_style . '"'; } break; } } else { plugin_geshi_read_setting($geshi, 'default'); plugin_geshi_read_setting($geshi, $options['language']); $before = array(" \n"); $after = array("\n"); } $html = $geshi->parse_code(); if (isset($before) && isset($after)) { $html = str_replace($before, $after, $html); } return $html; }
/** * Get formatted post, ready for inserting into a page * Returns an array of useful information */ function getPost($pid) { $post = $this->db->getPost($pid, $this->conf['subdomain']); if ($post) { //show a quick reference url, poster and parents $post['posttitle'] = "Posted by {$post['poster']} on {$post['postdate']}"; if ($post['parent_pid'] != '0') { $parent_pid = $post['parent_pid']; $parent = $this->db->getPost($parent_pid, $this->conf['subdomain']); if ($parent) { $post['parent_poster'] = trim($parent['poster']); if (strlen($post['parent_poster']) == 0) { $post['parent_poster'] = 'Anonymous'; } $post['parent_url'] = $this->getPostUrl($parent_pid); $post['parent_postdate'] = $parent['postdate']; $post['parent_diffurl'] = $this->conf['this_script'] . "?diff={$pid}"; } } //any amendments - note that a db class might have already //filled this if efficient, othewise we grab it on demand if (!isset($post['followups'])) { $post['followups'] = $this->db->getFollowupPosts($pid); } foreach ($post['followups'] as $idx => $followup) { $post['followups'][$idx]['followup_url'] = $this->getPostUrl($followup['pid']); } $post['downloadurl'] = $this->conf['this_script'] . "?dl={$pid}"; $post['deleteurl'] = $this->conf['this_script'] . "?erase={$pid}"; //store the code for later editing $post['editcode'] = $post['code']; //preprocess $highlight = array(); $prefix_size = strlen($this->conf['highlight_prefix']); if ($prefix_size) { $lines = explode("\n", $post['editcode']); $post['editcode'] = ""; foreach ($lines as $idx => $line) { if (substr($line, 0, $prefix_size) == $this->conf['highlight_prefix']) { $highlight[] = $idx + 1; $line = substr($line, $prefix_size); } $post['editcode'] .= $line . "\n"; } $post['editcode'] = rtrim($post['editcode']); } //get formatted version of code if (strlen($post['codefmt']) == 0) { $geshi = new GeSHi($post['editcode'], $post['format']); $geshi->set_encoding($this->conf['htmlentity_encoding']); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->set_line_style('background: #ffffff;', 'background: #f8f8f8;'); //$geshi->set_comments_style(1, 'color: #008800;',true); //$geshi->set_comments_style('multi', 'color: #008800;',true); //$geshi->set_strings_style('color:#008888',true); //$geshi->set_keyword_group_style(1, 'color:#000088',true); //$geshi->set_keyword_group_style(2, 'color:#000088;font-weight: normal;',true); //$geshi->set_keyword_group_style(3, 'color:black;font-weight: normal;',true); //$geshi->set_keyword_group_style(4, 'color:#000088',true); //$geshi->set_symbols_style('color:#ff0000'); if (count($highlight)) { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->highlight_lines_extra($highlight); $geshi->set_highlight_lines_extra_style('color:black;background:#FFFF88;'); } else { $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2); } $post['codefmt'] = $geshi->parse_code(); $post['codecss'] = $geshi->get_stylesheet(); //save it! $this->db->saveFormatting($pid, $post['codefmt'], $post['codecss']); } $post['pid'] = $pid; } else { $post['codefmt'] = "<b>Unknown post id, it may have been deleted</b><br />"; } return $post; }
/** * 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; } }
/** * 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 $wgTitle, $wgOut; 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(false); // Wikia change start if ($wgTitle instanceof Title && EditPageLayoutHelper::isCodeSyntaxHighlightingEnabled($wgTitle)) { $theme = 'solarized-light'; if (SassUtil::isThemeDark()) { $theme = 'solarized-dark'; } $geshi->set_language_path(GESHI_ROOT . $theme . DIRECTORY_SEPARATOR); $geshi->set_overall_id('theme-' . $theme); $wgOut->addStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/SyntaxHighlight_GeSHi/styles/solarized.scss')); } // Wikia change end return $geshi; }
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; }
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"; }
function geshi_format_code($text, $ext) { $str = ''; $geshi = new GeSHi($text, ''); $lang = $ext == 'diff' ? $ext : $geshi->get_language_name_from_extension($ext); $geshi->set_language($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( false ); $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); $geshi->set_header_type(GESHI_HEADER_DIV); $str .= $geshi->parse_code($text, 1); if ($geshi->error()) { $str .= $geshi->error(); } return $str; }
/** * 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; }
} $sourcecode = $codeObj->get(); $sourcecode['source'] = $gpc->plain_str($sourcecode['source'], false); ($code = $plugins->load('popup_hlcode_start')) ? eval($code) : null; if ($_GET['temp'] == 1) { viscacha_header('Content-Type: text/plain'); viscacha_header('Content-Length: ' . strlen($sourcecode['source'])); viscacha_header('Content-Disposition: attachment; filename="' . gmdate('d-m-Y_H-i', times()) . '.txt"'); echo $sourcecode['source']; $slog->updatelogged(); $db->close(); exit; } else { require_once 'classes/class.geshi.php'; $geshi = new GeSHi($sourcecode['source'], strtolower($sourcecode['language']), 'classes/geshi'); $geshi->set_encoding($lang->charset()); // Use classes for colouring $geshi->enable_classes(); // Output in a div instead in a pre-element $geshi->set_header_type(GESHI_HEADER_DIV); // Linenumbers on - each 5th element is bold $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5); $lang_name = $geshi->get_language_name(); // Print Stylesheet $htmlhead .= '<style type="text/css"><!-- ' . $geshi->get_stylesheet() . ' --></style>'; echo $tpl->parse("popup/header"); ($code = $plugins->load('popup_hlcode_initialized')) ? eval($code) : null; $sourcecode['hl'] = $geshi->parse_code(); echo $tpl->parse("popup/hlcode"); ($code = $plugins->load('popup_hlcode_end')) ? eval($code) : null; }
/** * @param string $type * @param string $text * @param string $language */ function _highlight($type, $text, $language = null) { $style_name = $this->styleset->getStyleName('source code'); if ($type == "file") { $style_name = $this->styleset->getStyleName('source file'); } if (is_null($language)) { $this->_preformatted($text, $style_name); return; } // from inc/parserutils.php:p_xhtml_cached_geshi() $geshi = new GeSHi($text, $language, DOKU_INC . 'inc/geshi'); $geshi->set_encoding('utf-8'); // $geshi->enable_classes(); DO NOT WANT ! $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->enable_keyword_links(false); // 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"); // remove useless leading and trailing whitespace-newlines $highlighted_code = preg_replace('/^ \\n/', '', $highlighted_code); $highlighted_code = preg_replace('/\\n $/', '', $highlighted_code); // replace styles $highlighted_code = str_replace("</span>", "</text:span>", $highlighted_code); $highlighted_code = preg_replace_callback('/<span style="([^"]+)">/', array($this, '_convert_css_styles'), $highlighted_code); // cleanup leftover span tags $highlighted_code = preg_replace('/<span[^>]*>/', "<text:span>", $highlighted_code); $highlighted_code = str_replace(" ", " ", $highlighted_code); $this->_preformatted($highlighted_code, $style_name, false); }
/** * 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; }
/** * 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 * * @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; } }
function plugin_geshi_highlight_code($source, $options) { if (!class_exists('GeSHi')) { require PLUGIN_GESHI_LIB_DIR . 'geshi.php'; } $geshi = new GeSHi($source, $options['language']); $geshi->set_encoding(CONTENT_CHARSET); if (PLUGIN_GESHI_USE_CSS) { $geshi->enable_classes(); } if ($options['number']) { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->start_line_numbers_at($options['start']); $geshi->set_overall_class('geshi number ' . $options['language']); plugin_geshi_read_setting($geshi, 'default'); plugin_geshi_read_setting($geshi, $options['language']); $html = $geshi->parse_code(); if ($geshi->header_type == GESHI_HEADER_PRE) { $before = array('<ol', '/ol>', '</div', '> ', ' '); $after = array('<code><object><ol style="margin-top: 0; margin-bottom: 0;"', '/ol></object></code>', "\n</div", '> ', ' '); $html = str_replace($before, $after, $html); } } else { $geshi->set_overall_class('geshi ' . $options['language']); plugin_geshi_read_setting($geshi, 'default'); plugin_geshi_read_setting($geshi, $options['language']); $html = $geshi->parse_code(); $html = str_replace("\n ", "\n", $html); } return $html; }