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(); } }
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>'; } }
/** * Получаем заголовок * * @return string */ protected function getHeader() { if (isset($this->attributes['title'])) { $title = $this->attributes['title']; } else { $title = $this->geshi->get_language_name(); } return '<div class="bb_code_header"><span class="bb_code_lang">' . htmlspecialchars($title, ENT_NOQUOTES) . '</span></div>'; }
$selectedValue = getPostedValue('selectedValue'); // Create a GeSHi instance. $geshi = new GeSHi(); // Build a list of all the language php files located in the language // directory $languages = array(); if ($handle = opendir($geshi->language_path)) { while (($file = readdir($handle)) !== false) { $pos = strpos($file, '.'); if ($pos > 0 && substr($file, $pos) == '.php') { $languages[] = substr($file, 0, $pos); } } closedir($handle); } // Sort the languages alphabetically sort($languages); // Output the start of the select block echo '<select name="codeType" id="codeType">' . "\n"; // Output an option for each language and set the selected // attribute if we were provided with a selectedValue foreach ($languages as $lang) { $geshi->set_language($lang); $selected = ' '; if ($selectedValue == $lang) { $selected = ' selected="selected"'; } echo '<option value="' . $lang . '"' . $selected . '>' . $geshi->get_language_name() . '</option>' . "\n"; } // Output the end of the select block echo '</select>' . "\n";
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; } } elseif ($_GET['action'] == "filetypes") { ($code = $plugins->load('popup_filetypes_query')) ? eval($code) : null; if (empty($_GET['type'])) { error($lang->phrase('query_string_error'), 'javascript:self.close();'); } $result = $db->query("SELECT * FROM {$db->pre}filetypes WHERE extension LIKE '%{$_GET['type']}%'", __LINE__, __FILE__); $nr = $db->num_rows($result);
/** * added function lang_name, returns human-readable Language (for proper work with my blogsystem) * by BadBoy_, 05/23/2008, http://badboy.pytalhost.de */ function lang_name($language, $path = null) { $geshi = new GeSHi(null, $language, $path); return $geshi->get_language_name(); }
$search = array("\\", """, "'", "\", """, "'", "<", ">", "&"); $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'] . "&post_id=" . $data['post_id'] . "&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> "; } 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++) { 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'] . "&post_id=" . $data['post_id'] . "&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> "; } else { $geshi_save = ""; } $text = preg_replace("#\\[geshi=(.*?)\\](.*?)\\[/geshi\\]#sie", "'<div class=\\'tbl-border tbl2\\' style=\\'width:400px\\'>" . $geshi_save . "<strong><i><u>" . $locale['bb_geshi_parser1'] . ":</u></i> " . $locale['bb_geshi_parser2'] . ":</strong></div><div class=\\'tbl-border tbl1\\' style=\\'width:400px;white-space:nowrap;overflow:auto\\'><code style=\\'white-space:nowrap\\'>'.formatcode('\\2').'<br /><br /><br /></code></div>'", $text); } } unset($lines); }
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; ?> - <?php $geshi->get_language_name(); ?> </title>
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(); }
/** * List of available languages. * * @return array * An array mapping language code to array with the language path and * full language name. */ public static function getAvailableLanguages() { // Try to get it from cache (database actually). $cache = \Drupal::cache(); $available_languages = $cache->get('geshifilter_available_languages_cache'); if (!$available_languages) { // Not in cache: build the array of available_languages. $geshi_library = libraries_load('geshi'); $available_languages = array(); if ($geshi_library['loaded']) { $dirs = array($geshi_library['library path'] . '/geshi', drupal_get_path('module', 'geshifilter') . '/geshi-extra'); foreach ($dirs as $dir) { foreach (file_scan_directory($dir, '/.[pP][hH][pP]$/i') as $filename => $fileinfo) { // Short name. $name = $fileinfo->name; // Get full name. $geshi = new \GeSHi('', $name); $geshi->set_language_path($dir); $fullname = $geshi->get_language_name(); unset($geshi); // Store. $available_languages[$name] = array('language_path' => $dir, 'fullname' => $fullname); } } ksort($available_languages); // Save array to database. $cache->set('geshifilter_available_languages_cache', $available_languages); } } else { $available_languages = $available_languages->data; } return $available_languages; }