Esempio n. 1
0
 /**
  * The main method of the Plugin
  *
  * @param	string		$content: The PlugIn content
  * @param	array		$conf: The PlugIn configuration
  * @return	The content that is displayed on the website
  */
 function main($content, $config)
 {
     // get content
     $this->pi_initPIflexForm();
     $config['content.']['lang'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cLang', 'sVIEW');
     $config['content.']['code'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cCode', 'sVIEW');
     $config['content.']['highlight'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cHighlight', 'sOPTIONS');
     $config['content.']['startnumber'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cStartnumber', 'sOPTIONS');
     // init geshi library
     $this->geshi = new GeSHi($config['content.']['code'], $config['content.']['lang']);
     // defaults
     $this->geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     // set highlighted lines
     if ($config['content.']['highlight'] !== '') {
         $this->geshi->highlight_lines_extra(split(',', $config['content.']['highlight']));
     }
     // set startnumber
     if (isset($config['content.']['startnumber'])) {
         $this->geshi->start_line_numbers_at($config['content.']['startnumber']);
     }
     // style
     if (isset($config['default.'])) {
         $this->_styleSubjects($config['default.']);
     }
     if (isset($config[$config['content.']['lang'] . '.'])) {
         $this->_styleSubjects($config[$config['content.']['lang'] . '.']);
     }
     // external stylesheets
     if (isset($config['global.']['external']) && $config['global.']['external'] == 0) {
         // do not use external style sheets
     } else {
         // mtness.net modification: I love stylesheets!
         $this->geshi->enable_classes();
         // Echo out the stylesheet for this code block And continue echoing the page
         $this->geshiCSS = '<style type="text/css"><!--' . $this->geshi->get_stylesheet() . '--></style>';
         // additional headerdata to include the styles
         $GLOBALS['TSFE']->additionalHeaderData['dev_null_geshi:' . $config['content.']['lang']] = $this->geshiCSS;
     }
     // xhtml compliance
     if (isset($config['global.']['xhtmlcompliant']) && $config['global.']['xhtmlcompliant'] == 1) {
         $this->geshi->set_xhtml_compliance(true);
     }
     // check for errors
     if ($this->geshi->error() !== false) {
         // log an error, this happens if the language file is missing or non-readable. Other input
         // specific errors can also occour, eg. if a non-existing container type is set for the engine.
         $GLOBALS['BE_USER']->simplelog($this->geshi->error(), $extKey = 'dev_null_geshi', 1);
     }
     // render
     return $this->pi_wrapInBaseClass($this->geshi->parse_code());
 }
Esempio n. 2
0
 /**
  * 
  * 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", " &nbsp; &nbsp;", $text);
         $text = str_replace("  ", " &nbsp;", $text);
         $text = "<code{$css_code}>{$text}</code>";
     }
     return "\n{$text}\n\n";
 }
Esempio n. 3
0
 function onExtra($name)
 {
     $output = NULL;
     if ($name == "header") {
         if (!$this->yellow->config->get("highlightStylesheetDefault")) {
             $locationStylesheet = $this->yellow->config->get("serverBase") . $this->yellow->config->get("pluginLocation") . "highlight.css";
             $fileNameStylesheet = $this->yellow->config->get("pluginDir") . "highlight.css";
             if (is_file($fileNameStylesheet)) {
                 $output = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"{$locationStylesheet}\" />\n";
             }
         } else {
             $geshi = new GeSHi();
             $geshi->set_language_path($this->yellow->config->get("pluginDir") . "/highlight/");
             foreach ($geshi->get_supported_languages() as $language) {
                 if ($language == "geshi") {
                     continue;
                 }
                 $geshi->set_language($language);
                 $output .= $geshi->get_stylesheet(false);
             }
             $output = "<style type=\"text/css\">\n{$output}</style>";
         }
     }
     return $output;
 }
/**
 * 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;
}
 /**
  * Prepare a CSS snippet suitable for use as a ParserOutput/OutputPage
  * head item
  *
  * @param GeSHi $geshi
  * @return string
  */
 public static function buildHeadItem($geshi)
 {
     global $wgUseSiteCss, $wgSquidMaxage;
     // begin Wikia change
     // VOLDEV-85
     // backporting core fix to monobook font size
     /**
      * GeSHi comes by default with a font-family set to monospace, which
      * causes the font-size to be smaller than one would expect.
      * We append a CSS hack to the default GeSHi styles: specifying 'monospace'
      * twice "resets" the browser font-size specified for monospace.
      *
      * The hack is documented in MediaWiki core under
      * docs/uidesign/monospace.html and in bug 33496.
      */
     // Preserve default since we don't want to override the other style
     // properties set by geshi (padding, font-size, vertical-align etc.)
     $geshi->set_code_style('font-family: monospace, monospace;', true);
     // No need to preserve default (which is just "font-family: monospace;")
     // outputting both is unnecessary
     $geshi->set_overall_style('font-family: monospace, monospace;', false);
     // end Wikia change
     $lang = $geshi->language;
     $css = array();
     $css[] = '<style type="text/css">/*<![CDATA[*/';
     $css[] = ".source-{$lang} {line-height: normal;}";
     $css[] = ".source-{$lang} li, .source-{$lang} pre {";
     $css[] = "\tline-height: normal; border: 0px none white;";
     $css[] = "}";
     $css[] = $geshi->get_stylesheet(false);
     $css[] = '/*]]>*/';
     $css[] = '</style>';
     return implode("\n", $css);
 }
 /**
  * Get the complete CSS code necessary to display styles for given GeSHi instance.
  *
  * @param GeSHi $geshi
  * @return string
  */
 public static function getCSS($geshi)
 {
     $lang = $geshi->language;
     $css = array();
     $css[] = ".source-{$lang} {line-height: normal;}";
     $css[] = ".source-{$lang} li, .source-{$lang} pre {";
     $css[] = "\tline-height: normal; border: 0px none white;";
     $css[] = "}";
     $css[] = $geshi->get_stylesheet(false);
     return implode("\n", $css);
 }
	/**
	 * Prepare a CSS snippet suitable for use as a ParserOutput/OutputPage
	 * head item
	 *
	 * @param GeSHi $geshi
	 * @return string
	 */
	public static function buildHeadItem( $geshi ) {
		/**
		 * Geshi comes by default with a font-family set to monospace which
		 * ends ultimately ends up causing the font-size to be smaller than
		 * one would expect (causing bug 26204).
		 * We append to the default geshi style a CSS hack which is to specify
		 * monospace twice which "reset" the browser font-size specified for monospace.
		 *
		 * The hack is documented in MediaWiki core under
		 * docs/uidesign/monospace.html and in bug 33496.
		 */
		$geshi->set_code_style( 'font-family: monospace, monospace;',
			/** preserve defaults */ true );

		$lang = $geshi->language;
		$css = array();
		$css[] = '<style type="text/css">/*<![CDATA[*/';
		$css[] = ".source-$lang {line-height: normal;}";
		$css[] = ".source-$lang li, .source-$lang pre {";
		$css[] = "\tline-height: normal; border: 0px none white;";
		$css[] = "}";
		$css[] = $geshi->get_stylesheet( false );
		$css[] = '/*]]>*/';
		$css[] = '</style>';
		return implode( "\n", $css );
	}
 /**
  * Highlights the content parts marked as source code using the GeSHi
  * class.
  * @author  Björn Detert <*****@*****.**>
  * @version 20. 9. 2006
  * @param   string $content The text to be parsed
  * @param   object $parent  The calling object (regulary of type tx_mmforum_pi1), so this
  *                          object inherits all configuration and language options from the
  *                          calling object.
  * @param   array  $conf    The calling plugin's configuration vars
  * @return  string          The parsed string
  */
 function syntaxhighlighting($content, $parent, $conf)
 {
     /* Path to Geshi Syntax-Highlighting files. */
     $path = GeneralUtility::getFileAbsFileName('EXT:mm_forum/res/geshi/geshi/', $onlyRelative = 1, $relToTYPO3_mainDir = 0);
     $conf['postparser.']['tsrefUrl'] ? define('GESHI_TS_REF', $conf['postparser.']['tsrefUrl']) : define('GESHI_TS_REF', 'www.typo3.net');
     $res = $this->databaseHandle->exec_SELECTquery('lang_title,lang_pattern,lang_code', 'tx_mmforum_syntaxhl', 'deleted=0');
     while ($data = $this->databaseHandle->sql_fetch_assoc($res)) {
         preg_match_all($data['lang_pattern'], $content, $source_arr);
         while (list($key, $value) = each($source_arr[1])) {
             $value = trim($this->decode_entities($value));
             if ($data['lang_title'] == 'php') {
                 if (!preg_match("/<\\?/", trim(substr($value, 0, 6)))) {
                     $value = "<?\n" . $value . "\n?>";
                 }
             }
             $geshi = new GeSHi($value, $data['lang_code'], $path);
             $geshi->set_header_type(GESHI_HEADER_PRE);
             #$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
             $geshi->set_line_style('background: ' . $conf['postparser.']['sh_linestyle_bg'] . ';', 'background: ' . $conf['postparser.']['sh_linestyle_bg2'] . ';', true);
             $geshi->set_overall_style('margin:0px;', true);
             $geshi->enable_classes();
             $style = '<style type="text/css"><!--';
             $style .= $geshi->get_stylesheet();
             $style .= '--></style>';
             $geshi->enable_strict_mode('FALSE');
             $replace = $geshi->parse_code();
             $time = $geshi->get_time();
             $CodeHead = '<div class="tx-mmforum-pi1-codeheader">' . strtoupper($data['lang_title']) . '</div>';
             // $code_header , check this out?? I get confused ^^
             $replace = '###DONT_PARSE_AGAIN_START###' . $CodeHead . '<div class="tx-mmforum-pi1-codeblock">' . $style . $replace . '</div>###DONT_PARSE_AGAIN_ENDE###';
             $content = str_replace($source_arr[0][$key], $replace, $content);
         }
     }
     return $content;
 }
Esempio n. 9
0
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @package    geshi
 * @subpackage contrib
 * @author     revulo <*****@*****.**>
 * @copyright  2008 revulo
 * @license    http://gnu.org/copyleft/gpl.html GNU GPL
 *
 */
require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'geshi.php';
$geshi = new GeSHi();
$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($languages);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="geshi.css"');
echo "/**\n" . " * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann\n" . " * (http://qbnz.com/highlighter/ and http://geshi.org/)\n" . " */\n";
foreach ($languages as $language) {
    $geshi->set_language($language);
    // note: the false argument is required for stylesheet generators, see API documentation
    $css = $geshi->get_stylesheet(false);
    echo preg_replace('/^\\/\\*\\*.*?\\*\\//s', '', $css);
}
 /**
  * Loads data for this template
  */
 protected function LoadData()
 {
     $head = $this->GetProject()->GetHeadCommit();
     $this->tpl->assign('head', $head);
     $commit = $this->GetProject()->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $this->params['hash'] = $commit->GetTree()->PathToHash($this->params['file']);
         if (empty($this->params['hash'])) {
             throw new GitPHP_FileNotFoundException($this->params['file']);
         }
     }
     $blob = $this->GetProject()->GetObjectManager()->GetBlob($this->params['hash']);
     if ($this->params['file']) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     $blame = new GitPHP_FileBlame($this->GetProject(), $commit, $this->params['file'], $this->exe);
     $this->tpl->assign('blame', $blame->GetBlame());
     if (isset($this->params['output']) && $this->params['output'] == 'js') {
         return;
     }
     $this->tpl->assign('tree', $commit->GetTree());
     if ($this->config->GetValue('geshi')) {
         include_once GITPHP_GESHIDIR . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = GitPHP_Util::GeshiFilenameToLanguage($blob->GetName());
                 if (empty($lang)) {
                     $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 }
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $output = $geshi->parse_code();
                     $bodystart = strpos($output, '<td');
                     $bodyend = strrpos($output, '</tr>');
                     if ($bodystart !== false && $bodyend !== false) {
                         $geshihead = substr($output, 0, $bodystart);
                         $geshifoot = substr($output, $bodyend);
                         $geshibody = substr($output, $bodystart, $bodyend - $bodystart);
                         $this->tpl->assign('geshihead', $geshihead);
                         $this->tpl->assign('geshibody', $geshibody);
                         $this->tpl->assign('geshifoot', $geshifoot);
                         $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                         $this->tpl->assign('geshi', true);
                     }
                 }
             }
         }
     }
 }
Esempio n. 11
0
<!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>
    <style type="text/css">
    <!--
    <?php 
// Output the stylesheet. Note it doesn't output the <style> tag
echo $geshi->get_stylesheet();
?>
    html {
        background-color: #f0f0f0;
    }
    body {
        font-family: Verdana, Arial, sans-serif;
        margin: 10px;
        border: 2px solid #e0e0e0;
        background-color: #fcfcfc;
        padding: 5px;
    }
    h2 {
        margin: .1em 0 .2em .5em;
        border-bottom: 1px solid #b0b0b0;
        color: #b0b0b0;
Esempio n. 12
0
<?php

/*
  This file is part of the Pastebin package.
  Copyright (c) 2003-2008, Stephen Olesen
  All rights reserved.
  More information is available at http://pastebin.ca/
*/
### Generate CSS for all the GeSHi languages
$langs = array('actionscript', 'ada', 'apache', 'asm', 'asp', 'asterisk-conf', 'asterisk-exten', 'bash', 'c', 'c_mac', 'caddcl', 'cadlisp', 'cpp', 'csharp', 'css', 'delphi', 'html4strict', 'java', 'javascript', 'lisp', 'lua', 'mpasm', 'nsis', 'objc', 'oobas', 'oracle8', 'pascal', 'perl', 'php-brief', 'php', 'python', 'qbasic', 'smarty', 'sql', 'vb', 'vbnet', 'visualfoxpro', 'xml');
require_once "geshi.php";
foreach ($langs as $v) {
    $g = new GeSHi("...", $v);
    $g->enable_classes();
    $g->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
    $g->set_header_type(GESHI_HEADER_DIV);
    #$g->set_overall_id('source');
    #$g->set_overall_class($v);
    $g->set_code_style('color:black;', "'Courier New', Courier, monospace");
    $g->set_line_style('color:#838383;', '', true);
    $fd = fopen("css/lang/{$v}.css", "w");
    fwrite($fd, $g->get_stylesheet(false));
    fclose($fd);
}
Esempio n. 13
0
 /**
  * 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;
 }
Esempio n. 14
0
 /**
  * Put the last options to the sql: highlight, backticks....
  *
  * @param string  $sql
  * @param boolean $deactivateForeignKeys
  * @param boolean $backticks
  * @param boolean $highlight
  * @param boolean $lineNumbers
  *
  * @return string
  */
 private function finalizeSQLSyntax($sql, $deactivateForeignKeys, $backticks, $highlight, $lineNumbers)
 {
     $sql = implode(';' . PHP_EOL, $sql) . ';' . PHP_EOL;
     // Set line numbers, backticks....
     // Manage latest options
     if ($deactivateForeignKeys) {
         $sql = 'SET FOREIGN_KEY_CHECKS = 0;' . PHP_EOL . PHP_EOL . $sql;
         $sql .= PHP_EOL . 'SET FOREIGN_KEY_CHECKS = 1;';
     }
     // At the end
     if (!$backticks) {
         $sql = str_replace('`', '', $sql);
     }
     // Highlight Syntax ?
     $css = '';
     if ($highlight || $lineNumbers) {
         $geshi = new \GeSHi($sql, 'mysql');
         $geshi->enable_classes();
         $geshi->enable_keyword_links(false);
         if ($lineNumbers) {
             $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
         }
         if ($highlight) {
             $css = $geshi->get_stylesheet();
         }
         $sql = $geshi->parse_code();
     } else {
         $sql = "<pre>{$sql}</pre>";
     }
     return ['sql' => $sql, 'css' => $css];
 }
function wp_geshi_highlight_and_generate_css()
{
    global $wp_geshi_codesnipmatch_arrays;
    global $wp_geshi_css_code;
    global $wp_geshi_highlighted_matches;
    global $wp_geshi_requested_css_files;
    global $wp_geshi_used_languages;
    // It is time to initialize the highlighting machinery.
    // Check for `class_exists('GeSHi')` for preventing
    // `Cannot redeclare class GeSHi` errors. Another plugin may already have
    // included its own version of GeSHi.
    // TODO: in this case, include GeSHi of WP-GeSHi-Highlight anyway, via
    // namespacing or class renaming.
    if (!class_exists('GeSHi')) {
        include_once "geshi/geshi.php";
    }
    $wp_geshi_css_code = "";
    foreach ($wp_geshi_codesnipmatch_arrays as $match_index => $match) {
        // Process match details. The array structure is explained in
        // a comment to function `wp_geshi_filter_replace_code()`.
        $language = strtolower(trim($match[1]));
        $line = trim($match[2]);
        $escaped = trim($match[3]);
        $cssfile = trim($match[4]);
        $code = wp_geshi_code_trim($match[5]);
        if ($escaped == "true") {
            $code = htmlspecialchars_decode($code);
        }
        // (C) Ryan McGeary
        // Set up GeSHi.
        $geshi = new GeSHi($code, $language);
        // Output CSS code / do *not* create inline styles.
        $geshi->enable_classes();
        // Disable keyword links.
        $geshi->enable_keyword_links(false);
        if ($line) {
            $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
            $geshi->start_line_numbers_at($line);
        }
        // Set the output type. Reference:
        // http://qbnz.com/highlighter/geshi-doc.html#the-code-container
        $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
        // By default, geshi sets font size to 1em and line height to 1.2em.
        // That does not fit many modern CSS architectures. Make this
        // relative and, most importantly, customizable.
        $geshi->set_code_style('');
        // If the current language has not been processed in a previous
        // iteration:
        // - create CSS code for this language
        // - append this to the `$wp_geshi_css_code string`.
        // $geshi->get_stylesheet(false) disables the economy mode, i.e.
        // this will return the full CSS code for the given language.
        // This allows for reusing the same CSS code for multiple code
        // blocks of the same language.
        if (!in_array($language, $wp_geshi_used_languages)) {
            $wp_geshi_used_languages[] = $language;
            $wp_geshi_css_code .= $geshi->get_stylesheet(false);
        }
        $output = "";
        // cssfile "none" means no wrapping divs at all.
        if ($cssfile != "none") {
            if (empty($cssfile)) {
                // For this code snippet the default css file is required.
                $cssfile = "wp-geshi-highlight";
            }
            // Append "the css file" to the array.
            $wp_geshi_requested_css_files[] = $cssfile;
            $output .= "\n\n" . '<div class="' . $cssfile . '-wrap5">' . '<div class="' . $cssfile . '-wrap4">' . '<div class="' . $cssfile . '-wrap3">' . '<div class="' . $cssfile . '-wrap2">' . '<div class="' . $cssfile . '-wrap">' . '<div class="' . $cssfile . '">';
        }
        // Create highlighted HTML code.
        $output .= $geshi->parse_code();
        if ($cssfile != "none") {
            $output .= '</div></div></div></div></div></div>' . "\n\n";
        }
        // Store highlighted HTML code for later usage.
        $wp_geshi_highlighted_matches[$match_index] = $output;
    }
    // At this point, all code snippets are parsed. Highlighted code is stored.
    // CSS code has been generated. Delete what is not required anymore.
    unset($wp_geshi_codesnipmatch_arrays);
}
Esempio n. 16
0
/**
 * Function handler for coloring shortcodes. It's used in comments and for [filesyntax tag]
 *
 * @param string $atts
 * @param string $content
 * @return string
 */
function fr_codesyntax_handler($atts, $content = null, $cleanHTML = true, $commentProcessing = false)
{
    global $wp_sh_styling_type;
    if (empty($content)) {
        return '<font color="red"><b>' . __('WP-SYNHIGHLIGHT PLUGIN: NOTHING TO HIGHLIGHT! PLEASE READ README.TXT IN PLUGIN FOLDER!', 'wp-synhighlighter') . '</b></font>';
    }
    //Parsing paramters
    $params = shortcode_atts(array('title' => get_option('wp_synhighlight_default_codeblock_title') ? get_option('wp_synhighlight_default_codeblock_title') : __("Code block", 'wp-synhighlighter'), 'bookmarkname' => '', 'lang' => 'pascal', 'lines' => get_option('wp_synhighlight_default_lines') ? get_option('wp_synhighlight_default_lines') : 'fancy', 'lines_start' => get_option('wp_synhighlight_default_lines_start_with') ? get_option('wp_synhighlight_default_lines_start_with') : '1', 'container' => get_option('wp_synhighlight_default_container') ? get_option('wp_synhighlight_default_container') : 'pre', 'capitalize' => get_option('wp_synhighlight_default_capitalize_keywords') ? get_option('wp_synhighlight_default_capitalize_keywords') : 'no', 'tab_width' => get_option('wp_synhighlight_default_tab_width') ? get_option('wp_synhighlight_default_tab_width') : 4, 'strict' => get_option('wp_synhighlight_default_strict_mode') ? get_option('wp_synhighlight_default_strict_mode') : 'always', 'blockstate' => get_option('wp_synhighlight_default_blockstate') ? get_option('wp_synhighlight_default_blockstate') : 'default', 'highlight_lines' => "", 'doclinks' => !get_option('wp_synhighlight_doclinks_off')), $atts);
    if ($cleanHTML) {
        //Clearing all other HTML code
        $content = strip_tags($content);
        //Converting HTML entities
        $content = html_entity_decode($content, ENT_QUOTES);
    }
    //Trimming first and last incorrect newlines
    $content = trim($content);
    //Windows Live Writer patch
    foreach ($params as &$param) {
        $param = trim(html_entity_decode($param, ENT_QUOTES), '"');
    }
    //Highlighting
    $geshi = new GeSHi($content, $params['lang']);
    if (!$commentProcessing and ($wp_sh_styling_type == 'theme' or $wp_sh_styling_type == 'embedbody')) {
        $geshi->enable_classes();
    }
    //Setting Geshi options
    //Lines
    switch ($params['lines']) {
        case 'normal':
            $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
            break;
        case 'fancy':
            $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
            break;
        case 'no':
            $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
            break;
    }
    $geshi->start_line_numbers_at($params['lines_start']);
    //Container
    switch ($params['container']) {
        case 'pre':
            $geshi->set_header_type(GESHI_HEADER_PRE);
            break;
        case 'div':
            $geshi->set_header_type(GESHI_HEADER_DIV);
            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;
    }
    //Keywords capitalization
    switch ($params['capitalize']) {
        case 'no':
            $geshi->set_case_keywords(GESHI_CAPS_NO_CHANGE);
            break;
        case 'upper':
            $geshi->set_case_keywords(GESHI_CAPS_UPPER);
            break;
        case 'lower':
            $geshi->set_case_keywords(GESHI_CAPS_LOWER);
            break;
    }
    //Tab width
    $geshi->set_tab_width($params['tab_width']);
    //Strict mode
    switch ($params['strict']) {
        case 'always':
            $geshi->enable_strict_mode(GESHI_ALWAYS);
            break;
        case 'maybe':
            $geshi->enable_strict_mode(GESHI_MAYBE);
            break;
        case 'never':
            $geshi->enable_strict_mode(GESHI_NEVER);
            break;
    }
    //Block state
    switch ($params['blockstate']) {
        case 'collapsed':
            $initiallyHidden = true;
            break;
        case 'default':
        case 'expanded':
        default:
            $initiallyHidden = false;
            break;
    }
    //Controlling doclinks
    $geshi->enable_keyword_links($params['doclinks']);
    static $instanceNumber = 0;
    $instanceNumber++;
    $bookmarkName = empty($params['bookmarkname']) ? "codesyntax_" . $instanceNumber : $params['bookmarkname'];
    //Highlighting lines
    if (!empty($params['highlight_lines'])) {
        $geshi->highlight_lines_extra(explode(',', $params['highlight_lines']));
    }
    //Checking for geshi errors
    if ($geshi->error()) {
        return '<font color="red"><b>' . $geshi->error() . '</b></font>';
    }
    //Styling codeblock
    $header = wp_synhighlight_get_tpl_header($instanceNumber, $params['title'], $bookmarkName, $initiallyHidden);
    //Embedding only one copy of each used language style
    static $embeddedStylesheets = array();
    if ($wp_sh_styling_type == 'embedbody' and !in_array($params['lang'], $embeddedStylesheets)) {
        $header = '<style type="text/css"><!--' . "\r\n" . $geshi->get_stylesheet() . "\r\n" . '-->' . "\r\n" . '</style>' . $header;
        $embeddedStylesheets[] = $params['lang'];
    }
    $footer = wp_synhighlight_get_tpl_footer();
    $result = $header . $geshi->parse_code() . $footer;
    return $result;
}
Esempio n. 17
0
<?php

if (isset($_POST)) {
    include 'geshi.php';
    $source = stripslashes($_POST['source']);
    $lang = $_POST['lang'];
    $path = 'geshi/';
    $geshi = new GeSHi($source, $lang, $path);
    if ($_POST['css_classes'] == 1) {
        $geshi->enable_classes();
        $styles = '<style type="text/css"><!--';
        $styles .= $geshi->get_stylesheet();
        $styles .= '	--></style>';
    } else {
        $style = NULL;
    }
    switch ($_POST['code_container']) {
        case 1:
            $geshi->set_header_type(GESHI_HEADER_NONE);
            break;
        case 2:
            $geshi->set_header_type(GESHI_HEADER_PRE);
            break;
        case 3:
            $geshi->set_header_type(GESHI_HEADER_DIV);
            break;
    }
    switch ($_POST['linenum']) {
        case 1:
            $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
            break;
Esempio n. 18
0
#footer{text-align:center;font-size:80%;color:#BBBABA;clear:both;padding-top:16px;}
a{color:#0497D3;text-decoration:none;}
a:hover{color:#191919;}
textarea{border:1px solid #BBBABA;font-size:90%;color:#676666;width:53%;margin-bottom:6px;}
p{font-size:90%;}
#clear{text-align:right;width:100px;float:left;padding-right:1%;}
#submit{width:100px;float:left;}
#style-radio{float:right;padding-right:2%;margin:0;}
#style-radio input:hover{cursor:pointer;}
#language{text-align:left;width:31%;color:#676666;background-color:#FFF;border:1px solid #BBBABA;height:24px;margin-bottom:12px;}
.ui_button{font-size:12px;text-align:center;width:86px;border:1px solid #BBBABA;color:#4F4E4E;background-color:#FFF;background-image:url(../../../../admin/theme/ckPixie/images/sprites.gif);background-position:-27px -765px;padding:4px 12px;}
.ui_button:hover{background-color:#DBDADA;background-image:none;cursor:pointer;}
<?php 
    if (isset($_POST['submit']) && $_POST['style_type'] === 2) {
        /* Output the stylesheet. Note it doesn't output the <style> tag */
        echo $geshi->get_stylesheet(TRUE);
    }
    ?>
</style>
</head>
<body>
<?php 
    if (isset($_POST['submit'])) {
        print $geshi_out;
    }
    if (!isset($_POST['submit'])) {
        ?>
<form accept-charset="UTF-8" action="<?php 
        echo basename($_SERVER['PHP_SELF']);
        ?>
" method="post">
	/**
	 * Prepare a CSS snippet suitable for use as a ParserOutput/OutputPage
	 * head item
	 *
	 * @param GeSHi $geshi
	 * @return string
	 */
	public static function buildHeadItem( $geshi ) {
		global $wgUseSiteCss, $wgSquidMaxage;
		$lang = $geshi->language;
		$css = array();
		$css[] = '<style type="text/css">/*<![CDATA[*/';
		$css[] = ".source-$lang {line-height: normal;}";
		$css[] = ".source-$lang li, .source-$lang pre {";
		$css[] = "\tline-height: normal; border: 0px none white;";
		$css[] = "}";
		$css[] = $geshi->get_stylesheet( false );
		$css[] = '/*]]>*/';
		$css[] = '</style>';
		return implode( "\n", $css );
	}
Esempio n. 20
0
 function getPaste($pid)
 {
     $post = $this->db->getPaste($pid);
     if ($post) {
         // Show a quick reference url, title and parents.
         $expires = is_null($post['expires']) ? " (Never Expires) " : " - Expires on " . date("D, F jS @ g:ia", strtotime($post['expires']));
         $post['posttitle'] = "<b>{$post['title']}</b> - Posted on {$post['postdate']} {$expires}";
         if ($post['parent_pid'] > 0) {
             $parent_pid = $post['parent_pid'];
             $parent = $this->db->getPaste($parent_pid);
             if ($parent) {
                 $post['parent_title'] = $parent['title'];
                 $post['parent_url'] = $this->getPasteUrl($parent_pid);
                 $post['parent_postdate'] = $parent['postdate'];
                 $post['parent_diffurl'] = $this->conf['diff_url'] . "{$pid}";
             }
         }
         // Amendments
         $post['followups'] = $this->db->getFollowupPosts($pid);
         foreach ($post['followups'] as $idx => $followup) {
             $post['followups'][$idx]['followup_url'] = $this->getPasteUrl($followup['pid']);
         }
         if ($post['password'] != 'EMPTY') {
             $post['downloadurl'] = $this->conf['url'] . "?dl={$pid}&pass="******"?dl={$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->enable_classes();
             $geshi->set_header_type(GESHI_HEADER_DIV);
             $geshi->set_line_style('background: #ffffff;', 'background: #f4f4f4;');
             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 probably expired.</b><br />";
     }
     return $post;
 }
Esempio n. 21
0
 /**
  * Loads data for this template
  */
 protected function LoadData()
 {
     $commit = $this->GetProject()->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     $tree = $commit->GetTree();
     $this->tpl->assign('tree', $commit->GetTree());
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $this->params['hash'] = $tree->PathToHash($this->params['file']);
         if (empty($this->params['hash'])) {
             throw new GitPHP_FileNotFoundException($this->params['file']);
         }
     }
     $blob = $this->GetProject()->GetObjectManager()->GetBlob($this->params['hash']);
     if (!empty($this->params['file'])) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     if ($this->Plain()) {
         return;
     }
     $head = $this->GetProject()->GetHeadCommit();
     $this->tpl->assign('head', $head);
     if ($this->config->GetValue('filemimetype')) {
         $mimeReader = new GitPHP_FileMimeTypeReader($blob, $this->GetMimeStrategy());
         $mimetype = $mimeReader->GetMimeType(true);
         if ($mimetype == 'image') {
             $this->tpl->assign('datatag', true);
             $this->tpl->assign('mime', $mimeReader->GetMimeType());
             $this->tpl->assign('data', base64_encode($blob->GetData()));
             return;
         }
     }
     if ($this->config->GetValue('geshi')) {
         include_once GITPHP_GESHIDIR . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = GitPHP_Util::GeshiFilenameToLanguage($blob->GetName());
                 if (empty($lang)) {
                     $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 }
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $geshi->set_overall_id('blobData');
                     $this->tpl->assign('geshiout', $geshi->parse_code());
                     $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                     $this->tpl->assign('geshi', true);
                     return;
                 }
             }
         }
     }
     $this->tpl->assign('bloblines', $blob->GetData(true));
 }
Esempio n. 22
0
<p>&nbsp;</p>
<p>Now we modify our function:<br>
&nbsp;</p>
<?php 
$source = "\nvar counter = 0;\nvar reset_comment = false;\nvar comment_id = 0;\nvar subject_id = 0;\n\nfunction getLiveInfo(){\n\t\$.getJSON('http://samesub.com/api/v1/live/getall?callback=?',\n\t\t{subject_id:subject_id, coment_id:comment_id},\n\t\tfunction(data) {\n\t\t\t//If everything is ok(response_code == 200), let's print some LIVE information\n\t\t\tif(data.response_code == 200){\n\t\t\t\tcounter = data.time_remaining;\n\t\t\t\tif(data.new_sub != 0 || data.new_comment != 0 ){\n\t\t\t\t\tif(data.new_sub != 0) {\n\t\t\t\t\t\t//Every time there is a nuew sub, comments must be cleared\n\t\t\t\t\t\treset_comment=true;\n\t\t\t\t\t\tcomment_id = 0;\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t//Display subject\n\t\t\t\t\t\tsubject_id = data.subject_id;\n\t\t\t\t\t\t\$('#title').html(data.title);\n\t\t\t\t\t\t\$('#time_remaining').html(data.time_remaining + ' seconds.');\n\t\t\t\t\t}\n\t\t\t\t\tif(data.new_comment != 0){\n\t\t\t\t\t\tcomment_id = data.comment_id;\n\t\t\t\t\t\tshow_comments(data.comments);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\t//Otherwise alert data.response_message\t\t\t\t\n\t\t\t\talert(data.response_message);\n\t\t\t}\n\t\t}\n\t);\n\tvar aa = setTimeout('getLiveInfo()',8000);\n}\n\nfunction show_comments(comments){\n\tif(reset_comment == true) {\n\t\t\$('#comments_box').html('');//Clear all previous comments\n\t}\n\tfor(var i in comments) {\n\t\t\$('#comments_box').prepend(comments[i]['comment_text']+ '<br />');\n\t}\n}\n\nvar myInterval = setInterval(\n\tfunction(){\n\t\tcounter = counter - 1;\n\t\t\$('#time_remaining').html(counter + ' seconds.');\n\t}\n,1000);\n";
$language = 'Javascript';
$geshi = new GeSHi($source, $language);
$geshi->enable_classes();
$geshi->set_overall_class('myjs_no_lines');
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->set_overall_style("padding:1px 15px 1px 15px;border:1px solid #999999;background: #fcfcfc;font: normal normal 1em/1.2em monospace;");
$geshi->set_tab_width(2);
//$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
//$geshi->set_line_style('background: #fcfcfc;', true);
Yii::app()->clientScript->registerCss('highlightcode2', $geshi->get_stylesheet());
echo $geshi->parse_code();
?>
<p>&nbsp;</p>
<p>As you can see there are several changes: </p>
<ol>
	<li>We have declared few global variables.</li>
	<li>We have splitted our function in three main parts: the <b>getLiveInfo</b> 
	function itself, the <b>show_comments</b> function, and the interval 
	function.</li>
	<li>Notice that now we are sending two data parameters to the <b>getJSON</b> 
	jquery function; the <b>subject_id</b> and <b>comment_id</b> parameters.</li>
	<li>Notice that the values we are sending in the two parameters are the same 
	values we are receiving from the server.</li>
	<li>The only way to know if there are newer comments than the last we 
	received is by telling the server which was the last <b>comment_id</b> we 
 /**
  * Prepare a CSS snippet suitable for use as a ParserOutput/OutputPage
  * head item
  *
  * @param GeSHi $geshi
  * @return string
  */
 private static function buildHeadItem($geshi)
 {
     global $wgUseSiteCss, $wgSquidMaxage;
     $lang = $geshi->language;
     $css[] = '<style type="text/css">/*<![CDATA[*/';
     $css[] = ".source-{$lang} {line-height: normal;}";
     $css[] = ".source-{$lang} li, .source-{$lang} pre {";
     $css[] = "\tline-height: normal; border: 0px none white;";
     $css[] = "}";
     $css[] = $geshi->get_stylesheet(false);
     $css[] = '/*]]>*/';
     $css[] = '</style>';
     if ($wgUseSiteCss) {
         $title = Title::makeTitle(NS_MEDIAWIKI, 'Geshi.css');
         $q = "usemsgcache=yes&action=raw&ctype=text/css&smaxage={$wgSquidMaxage}";
         $css[] = '<style type="text/css">/*<![CDATA[*/';
         $css[] = '@import "' . $title->getLocalUrl($q) . '";';
         $css[] = '/*]]>*/';
         $css[] = '</style>';
     }
     return implode("\n", $css);
 }
Esempio n. 24
0
 /**
  * LoadData
  *
  * Loads data for this template
  *
  * @access protected
  */
 protected function LoadData()
 {
     $commit = $this->project->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $this->params['hash'] = $commit->PathToHash($this->params['file']);
     }
     $blob = $this->project->GetBlob($this->params['hash']);
     if (!empty($this->params['file'])) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     if (isset($this->params['plain']) && $this->params['plain']) {
         return;
     }
     $head = $this->project->GetHeadCommit();
     $this->tpl->assign('head', $head);
     $this->tpl->assign('tree', $commit->GetTree());
     if (GitPHP_Config::GetInstance()->GetValue('filemimetype', true)) {
         $mime = $blob->FileMime();
         if ($mime) {
             $mimetype = strtok($mime, '/');
             if ($mimetype == 'image') {
                 $this->tpl->assign('datatag', true);
                 $this->tpl->assign('mime', $mime);
                 $this->tpl->assign('data', base64_encode($blob->GetData()));
                 return;
             }
         }
     }
     if (GitPHP_Config::GetInstance()->GetValue('geshi', true)) {
         include_once GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('geshiroot', 'lib/geshi/')) . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $geshi->set_overall_id('blobData');
                     $this->tpl->assign('geshiout', $geshi->parse_code());
                     $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                     $this->tpl->assign('geshi', true);
                     return;
                 }
             }
         }
     }
     $this->tpl->assign('bloblines', $blob->GetData(true));
 }
<?php

require_once "geshi.php";
$iterator = new DirectoryIterator(dirname(__FILE__) . '/geshi');
foreach ($iterator as $fileObj) {
    if ($fileObj->isDot() or $fileObj->isDir()) {
        continue;
    }
    $geshi = new GeSHi("", $fileObj->getBasename(".php"));
    file_put_contents(dirname(__FILE__) . '/../themes/default/geshi/' . $fileObj->getBasename(".php") . '.css', $geshi->get_stylesheet(false));
}
Esempio n. 26
0
} else {
    // make sure we don't preselect any language
    $_POST['language'] = null;
}
?>
<!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>GeSHi examples</title>
<style type="text/css">
<!--
<?php 
if (isset($_POST['submit'])) {
    // Output the stylesheet. Note it doesn't output the <style> tag
    echo $geshi->get_stylesheet(true);
}
?>
html {
background-color: #f0f0f0;
}
body {
font-family: Verdana, Arial, sans-serif;
margin: 10px;
border: 2px solid #e0e0e0;
background-color: #fcfcfc;
padding: 5px;
}
h2 {
margin: .1em 0 .2em .5em;
border-bottom: 1px solid #b0b0b0;
Esempio n. 27
0
print '<!DOCTYPE html><html><head>' . '<title>Source</title>' . "\n" . '<style type="text/css">/*<![CDATA[*/' . "\nhtml { background-color: #333; }\nbody { font-family: 'Trebuchet MS', serif;  font-size: 0.9em;  margin: 2em auto;\nwidth: 50em; padding: 2em; border: 3px solid #000; background-color: #EEE; }\na { color: blue; }\na:hover { color: #000033; }\n/*]]>*/</style></head>\n<body>\n";
if (isset($_GET['sauce'])) {
    if (!valid_path($_GET['sauce']) || !is_file($_GET['sauce'])) {
        print '<h1>YOR ISP MAC ADDRESS HAS BEEN REPORTING TO THE FBI!!!</h1>';
        exit;
    } else {
        require_once '/home/ben/geshi/geshi.php';
        $lang = ext($_GET['sauce']);
        switch ($lang) {
            case 'py':
                $lang = 'python';
                break;
        }
        $geshi = new GeSHi(file_get_contents($_GET['sauce']), $lang);
        $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
        $geshi->enable_classes();
        //$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
        $geshi->enable_keyword_links(false);
        $geshi->set_keyword_group_style(1, 'color: #DD0000;');
        $geshi->set_keyword_group_style(2, 'color: #666;');
        $geshi->set_keyword_group_style(3, 'color: #0033CC;');
        $geshi->set_keyword_group_style(4, 'color: #00CC33;');
        $geshi->set_comments_style(1, 'color: #00CC00;');
        $geshi->set_comments_style(2, 'color: #00CC00;');
        $geshi->set_comments_style('MULTI', 'color: #009900;');
        print '<style type="text/css">/*<![CDATA[*/' . $geshi->get_stylesheet() . "/*]]>*/</style>\n" . $geshi->parse_code();
    }
} else {
    dir_walk();
}
print "\n</body></html>\n";
Esempio n. 28
0
 private function highlight(&$text, $lang = 'php', $lines = false)
 {
     $geshi = new GeSHi(trim($text, "\r\n"), $lang);
     $geshi->enable_classes();
     $geshi->set_header_type(GESHI_HEADER_PRE);
     $geshi->set_overall_class("code");
     $geshi->set_encoding("utf-8");
     // [[mw:user:Brianegge]] suggestion
     $geshi->set_overall_style('background: #EEEEEE; border: padding: 0.2em');
     if ($lines == true or $lines == 1 or $lines == '1') {
         $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     } else {
         $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
     }
     return "<style>" . $geshi->get_stylesheet() . "</style>" . $geshi->parse_code();
 }
Esempio n. 29
0
        $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);
    $cache = array();
    while ($row = $db->fetch_assoc($result)) {
Esempio n. 30
0
 /**
  * get the data for the paste-poste
  * 
  * @return type 
  */
 public function getPaste()
 {
     $conf = \Pste\Registry::getInstance()->config;
     $pid = $this->pid;
     $paste = new \Pste\Model\Paste($pid);
     $post = $paste->getContent();
     if (!$post) {
         return $this->forward(new StaticPage(array('template' => 'components/paste_invalid.php')));
     }
     $this->followUp(new PasteForm(array('request' => $this->request)));
     $postPass = $this->request->hasParam('thePassword') ? $this->request->getParam('thePassword') : null;
     $pass = $post['password'];
     $restrictedPost = null !== $pass && $pass !== sha1("EMPTY") ? true : false;
     $accessAllowed = !$restrictedPost || sha1($postPass) == $pass ? true : false;
     $passwordFail = $restrictedPost && null !== $postPass && $postPass !== $pass ? true : false;
     if (!$accessAllowed) {
         require_once 'components/StaticPage.php';
         return $this->forward(new StaticPage(array('template' => 'components/paste_password.php', 'fail' => $passwordFail)));
     }
     $paste = $post;
     // Show a quick reference url, poster and parents .
     $expires = is_null($post['expires']) ? "Never Expires" : "Expires on " . date("F D jS g:i A", strtotime($post['expires']));
     $paste['posttitle'] = "Posted as {$post['poster']} on {$post['postdate']} - {$expires}";
     $paste['editcode'] = $paste['code'];
     // Preprocess
     $highlight = array();
     $prefix_size = strlen($this->conf['highlight_prefix']);
     if ($prefix_size) {
         $lines = explode("\n", $post['code']);
         $paste['editcode'] = "";
         foreach ($lines as $idx => $line) {
             if (substr($line, 0, $prefix_size) == $conf['highlight_prefix']) {
                 $highlight[] = $idx + 1;
                 $line = substr($line, $prefix_size);
             }
             $paste['editcode'] .= $line . "\n";
         }
         $paste['editcode'] = rtrim($post['editcode']);
     }
     $requestedFormat = $this->request->getParam('udf');
     $format = $requestedFormat ? $requestedFormat : $post['format'];
     // Get formatted version of code
     if (0 && strlen($post['codefmt']) > 0 && $format == $post['format']) {
         $paste['codefmt'] = $post['codefmt'];
     } else {
         $geshi = new \GeSHi($paste['editcode'], $format);
         $geshi->enable_classes();
         $geshi->set_header_type(GESHI_HEADER_DIV);
         $geshi->set_line_style('background: #ffffff;', 'background: #f4f4f4;');
         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);
         }
         $paste['codefmt'] = $geshi->parse_code();
         $paste['codecss'] = $geshi->get_stylesheet();
     }
     $paste['pid'] = $pid;
     $paste['downloadurl'] = $conf->url . $post['pid'];
     $this->url = $conf->url;
     $this->post = $paste;
     $this->geshiformats = $conf->get('geshiformats');
     $this->popular_syntax = $conf->get('popular_syntax');
     $this->format = $format;
 }