/** * Runs source code through Geshi syntax highlighting engine. * * @param string $source Source code to process * @param string $lang Language of source code * @return string * @access public */ function syntax($source, $lang) { $source = $source; $language = $lang; $geshi = new Geshi($source, $lang); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_header_type(GESHI_HEADER_DIV); return $geshi->parse_code(); }
/** * Configure a geshi Instance the way we want it. * app/config/geshi.php * * @param Geshi $geshi * @return void */ protected function _configureInstance($geshi) { $geshi->set_header_type(GESHI_HEADER_NONE); $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2); $geshi->enable_classes(); $geshi->set_tab_width(4); }
function geshi_formatted($str, $type = 'PHP') { global $_CONF, $CONF_FORUM; include_once 'geshi.php'; $geshi = new Geshi($str, $type, "{$CONF_FORUM['path_include']}geshi"); $geshi->set_header_type(GESHI_HEADER_DIV); //$geshi->enable_strict_mode(true); //$geshi->enable_classes(); $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS, 5); $geshi->set_overall_style('font-size: 12px; color: #000066; border: 1px solid #d0d0d0; background-color: #FAFAFA;', true); // Note the use of set_code_style to revert colours... $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_line_style('background: red;', true); $geshi->set_link_styles(GESHI_LINK, 'color: #000060;'); $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;'); $geshi->set_header_content("{$type} Formatted Code"); $geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 90%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;'); return $geshi->parse_code(); }
$page['pathinfo'] = git_get_path_info($page['project'], $page['commit_id'], $page['path']); $page['data'] = fix_encoding(join("\n", run_git($page['project'], "cat-file blob {$page['hash']}"))); $page['lastlog'] = git_get_commit_info($page['project'], 'HEAD', $page['path']); // GeSHi support if ($conf['geshi'] && strpos($page['path'], '.')) { $old_mask = error_reporting(E_ALL ^ E_NOTICE); require_once $conf['geshi_path']; $parts = explode('.', $page['path']); $ext = array_pop($parts); $geshi = new Geshi($page['data']); $lang = $geshi->get_language_name_from_extension($ext); if (strlen($lang) > 0) { $geshi->set_language($lang); if (is_int($conf['geshi_line_numbers'])) { if ($conf['geshi_line_numbers'] == 0) { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); } else { $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, $conf['geshi_line_numbers']); } } $page['html_data'] = $geshi->parse_code(); } error_reporting($old_mask); } } elseif (in_array($action, array_keys(VGPlugin::$plugin_actions))) { VGPlugin::$plugin_actions[$action]->action($action); die; } else { die('Invalid action'); } require 'templates/header.php';
/** * Display a file using appropriate highlighting * * @return void */ public function showAction() { include_once 'geshi/geshi.php'; $this->view->project = $this->_project; $config = new USVN_Config_Ini(USVN_CONFIG_FILE, USVN_CONFIG_SECTION); $project_name = str_replace(USVN_URL_SEP, '/', $this->_project->name); $svn_file_path = $this->getRequest()->getParam('file'); $this->view->path = $svn_file_path; $local_file_path = USVN_SVNUtils::getRepositoryPath($config->subversion->path . "/svn/" . $project_name . "/" . $svn_file_path); $file_ext = pathinfo($svn_file_path, PATHINFO_EXTENSION); $revision = $this->getRequest()->getParam('rev'); $file_rev = ''; if (!empty($revision)) { if (is_numeric($revision) && $revision > 0) { $cmd = USVN_SVNUtils::svnCommand("log --non-interactive --revision {$revision} --quiet {$local_file_path}"); $verif = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return); if (!$return) { $this->view->revision = $revision; $file_rev = '--revision ' . $revision; } } } if (empty($file_rev)) { $cmd = USVN_SVNUtils::svnCommand("info {$local_file_path}"); $infos = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return); if (preg_match_all('#^([^:]+): (.*)$#m', $infos, $tmp)) { $infos = array(); foreach ($tmp[1] as $k => $v) { $infos[$v] = $tmp[2][$k]; } $this->view->revision = $infos['Last Changed Rev']; if ($revision) { $this->view->message = T_("The requested revision does not exist. Switching to the last changed revision."); } } } $cmd = USVN_SVNUtils::svnCommand("log --non-interactive --quiet {$local_file_path}"); $revs = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return); if (preg_match_all('#^r([0-9]+) \\|#m', $revs, $tmp)) { $revs = array(); $this->view->prev_revision = NULL; $this->view->next_revision = NULL; foreach ($tmp[1] as $k => $rev) { if ($this->view->prev_revision === NULL && intval($rev) < intval($this->view->revision)) { $this->view->prev_revision = $rev; } if ($rev > $this->view->revision) { $this->view->next_revision = $rev; } $revs[] = $rev; } $this->view->select_revisions = $revs; } $cmd = USVN_SVNUtils::svnCommand("cat --non-interactive {$file_rev} {$local_file_path}"); $source = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return); if ($return) { throw new USVN_Exception(T_("Can't read from subversion repository.\nCommand:\n%s\n\nError:\n%s"), $cmd, $message); } else { $this->view->color_view = $this->getRequest()->getParam('color'); $this->view->diff_view = $this->getRequest()->getParam('diff'); $this->view->diff_revision = $this->getRequest()->getParam('drev'); if ($this->view->diff_revision >= $this->view->revision) { $this->view->diff_revision = $this->view->prev_revision; } if ($this->getRequest()->getParam('post') === NULL) { $this->view->color_view = 1; } $geshi = new Geshi(); $lang_name = $geshi->get_language_name_from_extension($file_ext); $this->view->language = $lang_name; $geshi->set_language($this->view->color_view ? $lang_name : NULL, true); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); if ($this->view->diff_view && ($this->view->diff_revision || $this->view->prev_revision)) { $d_revs = ($this->view->diff_revision ? $this->view->diff_revision : $this->view->prev_revision) . ':' . $this->view->revision; $cmd = USVN_SVNUtils::svnCommand("diff --non-interactive --revision {$d_revs} {$local_file_path}"); $diff = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return); if ($return) { $this->view->message = T_('The requested diff revision does not exist.'); } else { $new_source = array(); $source = explode("\n", $source); array_pop($source); // Skip the final "\n" $diff = explode("\n", $diff); array_pop($diff); // Skip the final "\n" $source_line = NULL; $count_line = 0; $diff_lines = array(); while (($line = array_shift($diff)) !== NULL) { $line = trim($line); if (preg_match('#^@@ \\-[0-9,]+ \\+([0-9]+),[0-9]+ @@$#', $line, $tmp)) { if ($source_line === NULL) { $source_line = 1; } while (intval($source_line) < intval($tmp[1])) { array_push($new_source, array_shift($source)); $source_line++; $count_line++; } continue; } if ($source_line !== NULL) { $diff_char = substr($line, 0, 1); if ($diff_char == '\\') { continue; } elseif ($diff_char == '-') { array_push($new_source, substr($line, 1)); $diff_lines[$count_line] = '-'; } else { if ($diff_char == '+') { $diff_lines[$count_line] = '+'; } array_push($new_source, array_shift($source)); $source_line++; } $count_line++; } } if (count($source)) { $new_source = array_merge($new_source, $source); } $source = implode("\n", $new_source); unset($new_source); $this->view->diff_lines = $diff_lines; } } $geshi->set_source($source); $geshi->set_header_type(GESHI_HEADER_DIV); $this->view->highlighted_source = $geshi->parse_code(); if ($this->view->diff_view) { if (preg_match('#^<div ([^>]*)><ol>(.*)</ol></div>(\\s*)$#s', $this->view->highlighted_source, $tmp)) { $this->view->diff_div = $tmp[1]; $this->view->highlighted_source = $tmp[2]; } } } }
public function showPaste() { // Nothing given? go home if (!array_key_exists('id', $_GET) && !array_key_exists('code', $_GET)) { redirect(WEB_PATH); } // Using code? if (array_key_exists('code', $_GET)) { $code = $this->_sql->escape(trim($_GET['code'])); $q = "`code` = '{$code}'"; } elseif (array_key_exists('id', $_GET)) { $id = $this->_sql->escape(trim($_GET['id'])); $id = hexdec($id); // deliberately fail for new posts if ($id > 1080) { $id = -1; } $q = "`id` = '{$id}'"; } // Try getting it $get = $this->_sql->query("\n\t\t\tselect\n\t\t\t\t`date`, `language`, `paste`, `id`, `code`, `password`, `ip`, `private`\n\t\t\tfrom\n\t\t\t\t`pastes`\n\t\t\twhere\n\t\t\t\t{$q}\n\t\t\tlimit 1\n\t\t"); // Not existant? if ($this->_sql->num($get) == 0) { $this->_layout->error('Paste not existant'); } // Is; get info then free ram $info = $this->_sql->fetch_assoc($get); $this->_sql->free($info); // permalink $permalink = 'http://bn6.it/' . ($info['code'] != '' ? 'p/' . htmlspecialchars($info['code']) : dechex($info['id'])); // Is passworded if (!array_key_exists($info['id'], $_SESSION['my_pastes']) && strlen($info['password']) == 32) { // Show form if not submitted or if password is incorrect if (!array_key_exists('paste_pw', $_POST) || trim($info['password']) != md5($info['ip'] . $_POST['paste_pw'])) { // If password submitted but incorrect say so if (array_key_exists('paste_pw', $_POST) && trim($info['password']) != md5($info['ip'] . $_POST['paste_pw'])) { $this->_layout->setError('Invalid password'); } $this->_layout->head('Private Passworded Paste'); echo ' <form action="' . $permalink . '" method="post"> <div id="pw_form"> <div class="form_row"><label for="paste_pw">Password for paste:</label> <input type="password" id="paste_pw" name="paste_pw" /></div> <div class="form_row"> <input type="submit" value="View" /></div> </div> </form> '; $this->_layout->foot(); return; } } // Update last viewed $this->_sql->query("update `pastes` set `last_view` = unix_timestamp() where `id` = '{$info['id']}' limit 1"); // determine language $t = $this->getTypes(true); $type = 'plaintext'; if ($info['language'] > 0) { foreach ($t as $ti) { if ($ti[0] == $info['language']) { $type = $ti[1]; break; } } } // load geshi require_once LOCAL_PATH . 'geshi/geshi.php'; $geshi = new Geshi($info['paste'], $type); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); // Auto focus permalink box, if was me who submitted it if (array_key_exists($info['id'], $_SESSION['my_pastes'])) { $this->_layout->setSelect('perma'); unset($_SESSION['my_pastes'][$info['id']]); } // start layout $this->_layout->head($type); // give it echo '<div id="paste"> <div id="paste_body"> ' . $geshi->parse_code() . ' </div> </div> <div id="paste_meta"> <form action="" method="post" onsubmit="return false;" class="fake_form"> <ul> <li><label for="perma">Permalink:</label> <input title="Protip: this field is auto-selected on any paste page for clickless copying" onfocus="this.select();" id="perma" type="text" class="uneditable" readonly="readonly" value="' . $permalink . '" /></li> <li>Date posted: ' . date('m/d/Y @ h:i A', $info['date']) . '</li> ' . ($info['private'] ? '<li>This paste is private.</li>' : '') . ' </ul> </form> </div>'; // Show form with this paste stuff already in it echo '<h2>Revise/reply to paste</h2>'; $this->showForm(array('reply' => true, 'lang' => $info['language'], 'post' => stripslashes($info['paste'])), false); // end layout $this->_layout->foot(); }