예제 #1
0
function print_highlighted($lang)
{
    //The GeSHI syntax highlighter is included.
    include_once 'geshi/geshi.php';
    //The string returned is stored in a variable.
    $filename = get_id($_SERVER['REQUEST_URI']);
    //If file does not exist then it redirects the user to the home page.
    $file = fopen("data/{$filename}", "r") or header("Location: /");
    $source = '';
    while (!feof($file)) {
        $source = $source . fgets($file);
    }
    //The object created is passed two arguments for syntax highlighting.
    $geshi = new GeSHi($source, $lang);
    $geshi->set_overall_style('background-color: #f2f2f2; margin: 0px 35px; border: 1px dotted;', true);
    //$geshi->set_header_type(GESHI_HEADER_PRE_VALID);
    $geshi->set_header_type(GESHI_HEADER_DIV);
    //The flag below shows the line numbers. See GeSHI docs for more options.
    $flag = GESHI_FANCY_LINE_NUMBERS;
    $geshi->enable_line_numbers($flag);
    $geshi->set_line_style(' padding: 0px 15px;');
    //The <pre> tags are included for maintaining the indentation.
    // echo "<pre>";
    echo $geshi->parse_code();
    // echo "</pre></div>";
    return 0;
}
예제 #2
0
function source_highlighter($code)
{
    $source = str_replace(array("&gt;", "&lt;", "&quot;", "&amp;"), array(">", "<", "\"", "&"), $code[1]);
    if (false !== stristr($code[0], "[php]")) {
        $lang2geshi = "php";
    } elseif (false !== stristr($code[0], "[sql]")) {
        $lang2geshi = "sql";
    } elseif (false !== stristr($code[0], "[html]")) {
        $lang2geshi = "html4strict";
    } else {
        $lang2geshi = "txt";
    }
    $geshi = new GeSHi($source, $lang2geshi);
    $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
    $geshi->set_overall_style('font: normal normal 100% monospace; color: #000066;', false);
    $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
    $geshi->set_code_style('color: #000020;font-family:monospace; font-size:12px;line-height:6px;', true);
    //$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
    $geshi->enable_classes(false);
    $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
    $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
    $return = "<div class=\"codetop\">CODE</div><div class=\"codemain\">\n";
    $return .= $geshi->parse_code();
    $return .= "\n</div>\n";
    return $return;
}
예제 #3
0
function handle_geshi($content, $language)
{
    $g = new GeSHi($content, $language);
    $g->enable_classes();
    $g->set_header_type(GESHI_HEADER_DIV);
    $g->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
    #$g->set_overall_style('color:black');
    $g->set_overall_id('source');
    $g->set_code_style('color:black;', "'Courier New', Courier, monospace");
    $g->set_line_style('color:#838383;', '', true);
    return $g->parse_code();
}
function highlight_syntax($code, $langid)
{
    $value = get_record('problemstatement_programming_language', 'id', $langid);
    if ($value) {
        $syntax = $value->geshi;
    } else {
        $syntax = '';
    }
    /*
    	switch ($langid) {
    		case '0': $syntax='cpp'; break;
    		case '1': $syntax='delphi'; break;
    		case '2': $syntax='java'; break;
    		case '3': $syntax='python'; break;
    		case '4': $syntax='csharp'; break;
    	}*/
    $geshi = new GeSHi($code, $syntax);
    $geshi->set_header_type(GESHI_HEADER_DIV);
    //   $geshi->enable_classes(true);
    $geshi->set_overall_style('font-family: monospace;');
    $linenumbers = 1;
    if ($linenumbers) {
        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
        $geshi->set_line_style('color:#222;', 'color:#888;');
        $geshi->set_overall_style('font-size: 14px;font-family: monospace;', true);
    }
    $urls = FALSE;
    $indentsize = FALSE;
    $inline = FALSE;
    if (!$urls) {
        for ($i = 0; $i < 5; $i++) {
            $geshi->set_url_for_keyword_group($i, '');
        }
    }
    if ($indentsize) {
        $geshi->set_tab_width($indentsize);
    }
    $parsed = $geshi->parse_code();
    if ($inline) {
        $parsed = preg_replace('/^<div/', '<span', $parsed);
        $parsed = preg_replace('/<\\/div>$/', '</span>', $parsed);
    }
    //return $geshi->parse_code().$syntax;
    $lang = get_record('problemstatement_programming_language', 'id', $langid);
    if (!$lang) {
        $lang = '';
    }
    $comment = get_string("programwritten", "problemstatement") . $lang->language_name;
    //get_string("lang_".$langid, "problemstatement");
    return $parsed . $comment;
}
예제 #5
0
 public function getCode($data)
 {
     $code = array();
     foreach ($data as $part => $options) {
         $data = file_get_contents($options['file']);
         $geshi = new \GeSHi($data, $options['type']);
         //             $geshi->set_header_type(GESHI_HEADER_NONE);
         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
         $geshi->set_line_style('background: #fcfcfc;', 'background: #fcfcfc;');
         if (array_key_exists('highlight', $options)) {
             $geshi->highlight_lines_extra($options['highlight']);
         }
         $title = sprintf('%s: %s', $part, basename($options['file']));
         $code[$title] = $geshi->parse_code();
     }
     return $code;
 }
예제 #6
0
function source_highlighter($source, $lang2geshi)
{
    require_once 'geshi/geshi.php';
    $source = str_replace(array("&#039;", "&gt;", "&lt;", "&quot;", "&amp;"), array("'", ">", "<", "\"", "&"), $source);
    $lang2geshi = $lang2geshi == 'html' ? 'html4strict' : $lang2geshi;
    $geshi = new GeSHi($source, $lang2geshi);
    $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
    $geshi->set_overall_style('font: normal normal 100% monospace; color: #000066;', false);
    $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
    $geshi->set_code_style('color: #000020;font-family:monospace; font-size:12px;line-height:13px;', true);
    $geshi->enable_classes(false);
    $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
    $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
    $return = "<div class=\"codetop\">Code</div><div class=\"codemain\">\n";
    $return .= $geshi->parse_code();
    $return .= "\n</div>\n";
    return $return;
}
예제 #7
0
function AffichageSource($type, $lang, $nom)
{
    if (preg_match("#^../#", $nom) == TRUE) {
        $result = "Erreur lors du chargement du script";
    } else {
        $language = str_replace('.', '', strstr($nom, '.'));
        $source = '';
        $script = 'fichiers/' . $type . '/' . $lang . '/' . $nom;
        if (file_exists($script)) {
            $contenu = file($script);
            while (list($cle, $val) = each($contenu)) {
                $source .= $val;
            }
        }
        $geshi = new GeSHi($source, $language);
        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
        $geshi->set_overall_style('font-size:11px;width:580px;', true);
        $geshi->set_line_style('background: #fcfcfc;', 'background: #f0f0f0;');
        $result = $geshi->parse_code();
    }
    $result .= '<div align=center><a href="?page=' . $type . '">Retour</a></div>';
    return $result;
}
/**
 * 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;
}
예제 #9
0
if (strncmp($real_path, SOURCE_ROOT, $base_path_len)) {
    exit("Access outside acceptable path.");
}
// Check file exists
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;
?>
 /**
  * Style language
  *
  * @param array $subjects
  */
 function _styleSubjects($subjects)
 {
     // set overall style
     if (isset($subjects['view'])) {
         $this->geshi->set_overall_style($subjects['view'], $this->_invertOverwrite($subjects['view.']['overwrite']));
     }
     if (isset($subjects['view.']['container'])) {
         switch ($subjects['view.']['container']) {
             case 'none':
             case 'NONE':
             case 'None':
                 $this->geshi->set_header_type(GESHI_HEADER_NONE);
                 break;
             case 'div':
             case 'Div':
             case 'DIV':
                 $this->geshi->set_header_type(GESHI_HEADER_DIV);
                 break;
             case 'pre':
             case 'Pre':
             case 'PRE':
             default:
                 $this->geshi->set_header_type(GESHI_HEADER_PRE);
                 break;
         }
     }
     if (isset($subjects['view.']['tabwidth'])) {
         $this->geshi->set_tab_width(intval($subjects['view.']['tabwidth']));
     }
     // configure linenumbers
     if (isset($subjects['linenumbers'])) {
         $this->geshi->set_line_style($subjects['linenumbers'], isset($subjects['linenumbers.']['fancy']) ? $subjects['linenumbers.']['fancy'] : '', $this->_invertOverwrite($subjects['linenumbers.']['overwrite']));
     }
     // enable / disable linenumbers
     if (isset($subjects['linenumbers.']['enable'])) {
         $this->geshi->enable_line_numbers($subjects['linenumbers.']['enable']);
     }
     // configure code style
     if (isset($subjects['code'])) {
         $this->geshi->set_code_style($subjects['code'], $this->_invertOverwrite($subjects['code.']['overwrite']));
     }
     // configure escape
     if (isset($subjects['escape'])) {
         $this->geshi->set_escape_characters_style($subjects['escape'], $this->_invertOverwrite($subjects['escape.']['overwrite']));
     }
     // configure symbols
     if (isset($subjects['symbols'])) {
         $this->geshi->set_symbols_style($subjects['symbols'], $this->_invertOverwrite($subjects['symbols.']['overwrite']));
     }
     // configure strings
     if (isset($subjects['strings'])) {
         $this->geshi->set_strings_style($subjects['strings'], $this->_invertOverwrite($subjects['strings.']['overwrite']));
     }
     // configure numbers
     if (isset($subjects['numbers'])) {
         $this->geshi->set_numbers_style($subjects['numbers'], $this->_invertOverwrite($subjects['numbers.']['overwrite']));
     }
     // configure comment style
     if (isset($subjects['comments.'])) {
         foreach ($subjects['comments.'] as $key => $value) {
             if (strstr($key, '.') == false) {
                 $this->geshi->set_comments_style($key, $value, $this->_invertOverwrite($subjects['comments.'][$key . '.']['overwrite']));
             }
         }
     }
     // configure keywords style
     if (isset($subjects['keywords.'])) {
         foreach ($subjects['keywords.'] as $key => $value) {
             if (strstr($key, '.') == false) {
                 $this->geshi->set_keyword_group_style($key, $value, $this->_invertOverwrite($subjects['keywords.'][$key . '.']['overwrite']));
             }
         }
     }
     // enable / disable keyword links
     if (isset($subjects['keyword.']['links.']['enable'])) {
         $this->geshi->enable_keyword_links($subjects['keyword.']['links.']['enable']);
     }
     // configure keyword link styles
     if (isset($subjects['keyword.']['links'])) {
         $this->geshi->set_link_styles(GESHI_LINK, $subjects['keyword.']['links']);
     }
     if (isset($subjects['keyword.']['links.']['hover'])) {
         $this->geshi->set_link_styles(GESHI_HOVER, $subjects['keyword.']['links.']['hover']);
     }
     if (isset($subjects['keyword.']['links.']['active'])) {
         $this->geshi->set_link_styles(GESHI_ACTIVE, $subjects['keyword.']['links.']['active']);
     }
     if (isset($subjects['keyword.']['links.']['visited'])) {
         $this->geshi->set_link_styles(GESHI_VISITED, $subjects['keyword.']['links.']['visited']);
     }
     // configure keyword link target
     if (isset($subjects['keyword.']['links.']['target'])) {
         $this->geshi->set_link_target($subjects['keyword.']['links.']['target']);
     }
     // configure method styles
     if (isset($subjects['methods.'])) {
         foreach ($subjects['methods.'] as $key => $value) {
             if (strstr($key, '.') == false) {
                 $this->geshi->set_methods_style($key, $value, $this->_invertOverwrite($subjects['methods.'][$key . '.']['overwrite']));
             }
         }
     }
 }
예제 #11
0
파일: paste.php 프로젝트: KingNoosh/Teknik
 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;
 }
	function main($dir,$item,&$pObj) {

		global $LANG;


		if(!t3quixplorer_div::get_is_file($dir, $item)) t3quixplorer_div::showError($item.": ".$LANG->getLL("error.fileexists"));
		if(!t3quixplorer_div::get_show_item($dir, $item)) t3quixplorer_div::showError($item.": ".$LANG->getLL("error.accessfile"));
		$fname = t3quixplorer_div::get_abs_item($dir, $item);
		$fileinfo = t3lib_div::split_fileref($fname);
		$ext = $fileinfo['fileext'];
		$theight = ($GLOBALS["T3Q_VARS"]["textarea_height"] && is_numeric($GLOBALS["T3Q_VARS"]["textarea_height"]))?$GLOBALS["T3Q_VARS"]["textarea_height"]:20;


		$pObj->doc->JScode = '
<script id="prototype-script" type="text/javascript" src="../../t3scodehighlight/contrib/prototype/prototype.js">
</script>
<script src="../../t3scodehighlight/contrib/codepress/codepress.js" type="text/javascript" id="cp-script" lang="en-us"></script>
<link type="text/css" rel="stylesheet" href="../../t3scodehighlight/contrib/codepress/t3codepress.css">
</link>
<script src="../../t3scodehighlight/contrib/codepress/content/en-us.js" type="text/javascript" id="cp-script" lang="en-us"></script>
<script src="../../t3scodehighlight/contrib/codepress/t3codepress_t3lib_tceforms.js" type="text/javascript" id="t3codepress-t3libtceforms-script"></script>

				<script type="text/javascript">

					function closeDoc(){
						window.location=\''.t3quixplorer_div::make_link("list",$dir,NULL).'\';
					}
				</script>

			';

		$content= array();

		if(t3lib_div::_POST("dosave") && t3lib_div::_POST("dosave")=="yes") {
			// Save / Save As
			$item=basename(stripslashes(t3lib_div::_POST("fname")));
			$fname2=t3quixplorer_div::get_abs_item($dir, $item);
			if(!isset($item) || $item=="") t3quixplorer_div::showError($LANG->getLL("error.miscnoname"));
			if($fname!=$fname2 && @file_exists($fname2)) t3quixplorer_div::showError($item.": ".$LANG->getLL("error.itemdoesexist"));
			$this->savefile($fname2);
			$fname=$fname2;
		}

		// open file
		$fp = @fopen($fname, "r");
		if($fp===false) t3quixplorer_div::showError($item.": ".$LANG->getLL("error.openfile"));
		@fclose($fp);

		$fileContent = t3lib_div::getUrl($fname);

		// header
		$s_item=t3quixplorer_div::get_rel_item($dir,$item);	if(strlen($s_item)>50) $s_item="...".substr($s_item,-47);



		//$content[]=$s_item;

		//changed to absolute filename as of version 1.7 ... any complaints?
		$content[] = $fname;

		//$onkeydown = $GLOBALS['T3Q_VARS']['disable_tab'] ? '' : ' onkeydown="return catchTab(this,event)" ';

		$fileinfo = t3lib_div::split_fileref(t3quixplorer_div::get_abs_item($dir,$item));
		$lang = t3lib_div::_GP("highlight_lang");
		$ext = $fileinfo['fileext'];


        $readme = $this->getReadme($dir);
        if(strlen(trim($readme))){
        	$readme = '<div style="border: 1px solid red; background-color: yellow; padding: 10px; display:block;">'.$readme.'</div>';
        }else{
        	$readme = '';
        }
		if(!$lang){
			$lang = $ext;
		}
     if($item == 'setup.txt' || $item == 'config.txt'|| $item == 'constants.txt'){
		$content[]= $readme.'
		  <br />
		    <form id="editform" name="editform" method="post" action="'.t3quixplorer_div::make_link("edit",$dir,$item).'" >
		    <input type="hidden" name="dosave" value="yes"> '.
          '<code id="content" wrap="off" title=".ts" class="cp hideLanguage" style="height: 500px; color: silver; visibility: visible;">'.t3lib_div::formatForTextarea($fileContent).'</code>'
			.'<textarea id="content_ta" name="content_ta" rows="'.$theight.'" wrap="off" style="width: 460px; display: none;" class="cp fixed-font enable-tab">'.t3lib_div::formatForTextarea($fileContent).'</textarea>';

      }else{
		$content[]= $readme.'
		  <br />
		    <form id="editform" name="editform" method="post" action="'.t3quixplorer_div::make_link("edit",$dir,$item).'" >
		    <input type="hidden" name="dosave" value="yes"> '.
          '<code id="content" wrap="off" title=".'.$lang.'" class="cp hideLanguage" style="height: 500px; color: silver; visibility: visible;">'.t3lib_div::formatForTextarea($fileContent).'</code>'
			.'<textarea id="content_ta" name="content_ta" rows="'.$theight.'" wrap="off" style="width: 460px; display: none;" class="cp fixed-font enable-tab">'.t3lib_div::formatForTextarea($fileContent).'</textarea>';

      }



		$content[]= '
			  <br />
		      <table>
			    	<tr>
				  		<td>
				    		<input type="hidden" name="fname" value="'.$item.'">
				  		</td>
		          		<td>
				    		<input type="submit" name="savenow" value="'.$LANG->getLL("message.btnsave").'" >
				  		</td>
				  		<td>
		            <input type="button" value="'.$LANG->getLL("message.btnclose").'" onclick="closeDoc()">
				  		</td></tr></table><br />';





			$fileT3s = $fname;
			if(@is_file($fileT3s)){
			require_once (t3lib_extMgm::extPath("t3quixplorer")."mod1/geshi.php");

			  $inputCode = file_get_contents($fileT3s);



				switch($ext){
					case 'php':
					case 'php3':
					case 'inc':
						$hl = 'php';
						break;

					case 'html':
					case 'htm':
					case 'tmpl':
						$hl = 'html4strict';
						break;

					case 'js':
						$hl = 'javascript';
						break;

					case 'pl':
						$hl = 'perl';
						break;

					default:
						$hl = $ext;
						break;
				}

            if($item == 'setup.txt' || $item == 'config.txt'|| $item == 'constants.txt'){
            	$hl = 'ts';
            }
			switch($hl){
				case 'php':
				case 'xml':
				case 'sql':
				case 'html4strict':
				case 'javascript':
				case 'perl':
				case 'css':
				case 'smarty':
					$geshi = new GeSHi($inputCode,$hl,'geshi/');
					$geshi->use_classes = true;
					$geshi->set_tab_width(4);
					$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
					$geshi->set_link_target('_blank');
					$geshi->set_line_style("font-family:'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;font-size:12px;");

					$content[] = '
					<style type="text/css">

					.'.$hl.' *{font-size:11px;}

					'.$geshi->get_stylesheet().'
					</style>
					';

					$content[] = '<strong>T3S-File: '.$fileT3s.'</strong></br><hr />'.$geshi->parse_code();

					break;
				case 'ts':
					require_once(PATH_t3lib.'class.t3lib_tsparser.php');
					$tsparser = t3lib_div::makeInstance("t3lib_TSparser");
					$tsparser->lineNumberOffset=1;
					$formattedContent = $tsparser->doSyntaxHighlight($inputCode, array($tsparser->lineNumberOffset), 0);
					$content[]='<strong>T3S-File: '.$fileT3s.'</strong></br><hr />'.$formattedContent;
					break;
				default:
					break;
			}
			}

		return implode("",$content);
	}
예제 #13
0
$triggersList = array();
$i = 0;
foreach ($aTriggers as $aTrigger) {
    if ($aTrigger['NUM_TRIGGERS'] != 0) {
        foreach ($aTrigger['TRIGGERS_NAMES'] as $index => $name) {
            $triggersList[$i]['name'] = $name;
            $triggersList[$i]['execution_time'] = strtolower($aTrigger['TIME']);
            //$t_code = $aTrigger['TRIGGERS_VALUES'][$index]['TRI_WEBBOT'];
            //$t_code = str_replace('"', '\'',$t_code);
            //$t_code = addslashes($t_code);
            //$t_code = Only1br($t_code);
            //highlighting the trigger code using the geshi third party library
            G::LoadThirdParty('geshi', 'geshi');
            $geshi = new GeSHi($aTrigger['TRIGGERS_VALUES'][$index]['TRI_WEBBOT'], 'php');
            $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
            $geshi->set_line_style('background: #f0f0f0;');
            $triggersList[$i]['code'] = $geshi->parse_code();
            //$aTrigger['TRIGGERS_VALUES'][$index]['TRI_WEBBOT'];
            $i++;
        }
    } else {
    }
}
//print_r($_SESSION['TRIGGER_DEBUG']['ERRORS']); die;
$DEBUG_ERRORS = array_unique($_SESSION['TRIGGER_DEBUG']['ERRORS']);
foreach ($DEBUG_ERRORS as $error) {
    if (isset($error['ERROR']) and $error['ERROR'] != '') {
        $triggersList[$i]['name'] = 'Error';
        $triggersList[$i]['execution_time'] = 'error';
        $triggersList[$i]['code'] = $error['ERROR'];
        $i++;
예제 #14
0
    array('name' => 'style', 'type' => 'text',   'description' => 'CSS style'),
    array('name' => 'lang',  'type' => 'select', 'options' => array('php', 'sql', 'html'), 'description' => 'language type'),
    array('name' => 'lines', 'type' => 'text',   'description' => 'lines to be highlighted')
);
**/
if (isset($p['style'])) {
    $p['style'] = ' style="' . $p['style'] . '"';
} else {
    $p['style'] = '';
}
if (!$p['lang']) {
    $p['lang'] = 'php-brief';
} else {
    $p['lang'] = $p['lang'];
}
@(list($type, $body) = explode(':', $body, 2));
if ($type == 'file') {
    $geshi = new GeSHi(trim(file_get_contents("{$g['base_path']}/codes/{$body}")), $p['lang']);
    $geshi->set_header_content('Filename: ' . $body);
} elseif ($type == 'code') {
    $geshi = new GeSHi(trim($body), $p['lang']);
}
if (@count($p['lines'])) {
    $geshi->highlight_lines_extra(explode(',', $p['lines']));
    $geshi->set_highlight_lines_extra_style('background: #330');
}
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_line_style('margin: 3px 0;');
$geshi->set_header_content_style('font-size: 0.8em; color: #333');
$geshi->set_header_type(GESHI_HEADER_DIV);
@($g['slide'] .= '<div class="code">' . $geshi->parse_code() . '</div>');
예제 #15
0
    public function View($ID, $lang)
    {
        $this->id = intval($ID);
        if (empty($this->id)) {
            die("ID not valid!");
        }
        //Elimino tutti i sorgenti che hanno una durata inferiore a time();
        $this->sql->sendQuery("DELETE FROM " . __PREFIX__ . "pastes WHERE expire_date > 0 AND expire_date < " . time());
        $this->my_is_numeric($this->id);
        $this->check_id_exists($this->id);
        require_once "lib/geshi/geshi.php";
        $this->info = mysql_fetch_array($this->sql->sendQuery("SELECT * FROM `" . __PREFIX__ . "pastes` WHERE id = '" . $this->id . "' LIMIT 1;"));
        $geshi = new GeSHi($this->info['text'], $lang);
        $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
        if (!empty($lang)) {
            $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
        }
        $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
        $geshi->set_line_style('background: #fcfcfc;', 'background: #f0f0f0;', true);
        $geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif;  
										 font-size: 90%; 
										 border-bottom: 2px dotted black;
										 padding: 5px;');
        $this->PrintHeader();
        print "<br />\n" . $geshi->parse_code();
    }
예제 #16
0
    // Enable line numbers. We want fancy line numbers, and we want every 5th line number to be fancy
    $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
    // Set the style for the PRE around the code. The line numbers are contained within this box (not
    // XHTML compliant btw, but if you are liberally minded about these things then you'll appreciate
    // the reduced source output).
    $geshi->set_overall_style('font: normal normal 90% monospace; color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', false);
    // Set the style for line numbers. In order to get style for line numbers working, the <li> element
    // is being styled. This means that the code on the line will also be styled, and most of the time
    // you don't want this. So the set_code_style reverts styles for the line (by using a <div> on the line).
    // So the source output looks like this:
    //
    // <pre style="[set_overall_style styles]"><ol>
    // <li style="[set_line_style styles]"><div style="[set_code_style styles]>...</div></li>
    // ...
    // </ol></pre>
    $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
    $geshi->set_code_style('color: #000020;', true);
    // Styles for hyperlinks in the code. GESHI_LINK for default styles, GESHI_HOVER for hover style etc...
    // note that classes must be enabled for this to work.
    $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
    $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
    // Use the header/footer functionality. This puts a div with content within the PRE element, so it is
    // affected by the styles set by set_overall_style. So if the PRE has a border then the header/footer will
    // appear inside it.
    $geshi->set_header_content('<SPEED> <TIME> GeSHi &copy; 2004-2007, Nigel McNie, 2007-2008 Benny Baumann. View source of example.php for example of using GeSHi');
    $geshi->set_header_content_style('font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
    // You can use <TIME> and <VERSION> as placeholders
    $geshi->set_footer_content('Parsed in <TIME> seconds at <SPEED>, using GeSHi <VERSION>');
    $geshi->set_footer_content_style('font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
} else {
    // make sure we don't preselect any language
예제 #17
0
     if ($line_num == true) {
         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     } else {
         $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
     }
     //if lang is same of a last code block then recycle geshi obj and css
     $geshi->set_source($source);
 } else {
     //new source language has been found in the content
     //create a new geshi obj
     $geshi = new GeSHi($source, $lang);
     // And echo the result!//
     $geshi->set_header_type(GESHI_HEADER_PRE);
     $geshi->enable_classes();
     $geshi->set_overall_style('font-size:10pt;', true);
     $geshi->set_line_style('font-size:10pt;', 'font-size:10pt;');
     //$geshi->set_line_style("font-size:10pt;background: #f0f0f0;", "font-size:10pt;background: #fcfcfc;");
     // MISTAKE: for right formatting, this must be out before outing css
     if ($line_num == true) {
         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS, 2);
     } else {
         $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
     }
     // Echo out the stylesheet for this code block
     // chek if css lang has already loaded
     if (!in_array($lang, $langs)) {
         echo '<style type="text/css"><!--' . $geshi->get_stylesheet() . '--></style>';
     }
     // stores languase already found in current page
     array_push($langs, $lang);
 }
예제 #18
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;
 }
예제 #19
0
    public function View($ID, $line, $lang)
    {
        $this->id = intval($ID);
        if (empty($this->id)) {
            die("<div id=\"error\">ID not valid!</div>");
        }
        //Elimino tutti i sorgenti che hanno una durata inferiore a time();
        $this->sql->sendQuery("DELETE FROM " . __PREFIX__ . "pastes WHERE expire_date > 0 AND expire_date < " . time());
        $this->my_is_numeric($this->id);
        $this->check_id_exists($this->id);
        //Thanks sPaste and Stoner
        $this->url = "http://" . $_SERVER["HTTP_HOST"] . substr($_SERVER["PHP_SELF"], 0, strpos($_SERVER["PHP_SELF"], "/", strlen($_SERVER["PHP_SELF"]) - strlen(basename($_SERVER["PHP_SELF"])) - 1));
        if ($line == 'no') {
            $this->line = "<input type=\"button\" value=\"Visual Lines\" onClick=\"location.href='" . $this->url . "/view.php?id=" . $this->id . "&line=yes'\">\n";
        } else {
            if ($line == NULL || $line == 'yes') {
                $this->line = "<input type=\"button\" value=\"No Visual Lines\" onClick=\"location.href='" . $this->url . "/view.php?id=" . $this->id . "&line=no'\">\n";
            } else {
                if ($line != 'yes' && $line != 'no' && $line != NULL) {
                    die("Hacking Attemp!");
                }
            }
        }
        require_once "lib/geshi/geshi.php";
        $this->info = mysql_fetch_array($this->sql->sendQuery("SELECT * FROM `" . __PREFIX__ . "pastes` WHERE id = '" . $this->id . "' LIMIT 1;"));
        if (!empty($lang)) {
            $geshi = new GeSHi($this->info['text'], $lang);
        } else {
            $geshi = new GeSHi($this->info['text'], $this->info['language']);
        }
        $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
        if ($line == 'yes' || $line == NULL) {
            $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
        }
        $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
        $geshi->set_line_style('background: #fcfcfc;', 'background: #f0f0f0;', true);
        $geshi->set_header_content("<font size=\"3\" >\n\n\t\t\t\t\t\t\t\t\tTitle: <b>" . $this->info['title'] . "</b><br />\n\n\t\t\t\t\t\t\t\t\tAuthor: <b>" . $this->info['author'] . "</b><br />\n\n\t\t\t\t\t\t\t\t\tDate: <b>" . $this->info['data'] . "</b> <br />\n\n\t\t\t\t\t\t\t\t\tLanguage: <b>" . $this->info['language'] . "</b>\n\n\t\t\t\t\t\t\t\t\t<br />\n\n\t\t\t\t\t\t\t\t\t<p style=\"float: left;\">Line: <b>" . $this->line . "</b>\n\n\t\t\t\t\t\t\t\t\t<p style=\"float: right;\"><b><a href=\"view.php?mode=raw&id=" . $this->id . "\" target=\"_blank\" >RAW</a> | <a href=\"view.php?mode=embed&id=" . $this->id . "\">EMBED</a></p></b><br /><br />\n\n\t\t\t\t\t\t\t\t\t</font>\n");
        $geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif;  
										 font-size: 90%; 
										 border-bottom: 2px dotted black;
										 padding: 5px;');
        $this->PrintHeader();
        print "<br />\n" . $geshi->parse_code();
        $this->PrintFooter();
    }
 /**
  * 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;
 }
예제 #21
0
파일: index.php 프로젝트: sschuberth/glex1
        <?php 
drawTableBorder('b', 'white');
?>
    </table>

<?php 
// GeSHi is included in any case for the version information in the footer.
include_once '../geshi/src/geshi.php';
if (empty($error)) {
    if (empty($spec)) {
        echo '<div style="height: 128px"></div>';
    } else {
        $geshi = new GeSHi();
        $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
        $geshi->set_overall_style('background-color: #c7d1d2; font-size: small;');
        $geshi->set_line_style('background: #d3e0e7;');
        $geshi->set_header_type(GESHI_HEADER_DIV);
        echo '<div style="height: 32px"></div>';
        // writeMacroHeader
        if (!empty($p)) {
            echo '<table style="width: 70%">';
            drawTableBorder('t', 'white', FALSE, 2);
            showSourceCode($p);
            drawTableBorder('b', 'white', FALSE, 2);
            echo '</table>';
            echo '<div style="height: 16px"></div>';
        }
        // writePrototypeHeader
        if (!empty($h)) {
            echo '<table style="width: 70%">';
            drawTableBorder('t', 'white', FALSE, 2);
예제 #22
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);
}
예제 #23
0
         $_POST['source'] = implode('', @file($path . 'geshi/' . $_POST['language'] . '.php'));
         $_POST['language'] = 'php';
     } else {
         $fill_source = TRUE;
     }
     /* Set GeSHi options */
     $geshi = new GeSHi($_POST['source'], $_POST['language']);
     if ($_POST['container-type'] == 1) {
         $geshi->set_header_type(GESHI_HEADER_DIV);
     }
     if ($_POST['container-type'] == 2) {
         $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
     }
     if ($_POST['line_numbers'] == 2) {
         $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
         $geshi->set_line_style('background: transparent;', 'background: #F0F5FE;', TRUE);
     }
     if ($_POST['line_numbers'] == 3) {
         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     }
     if ($_POST['style_type'] == 2) {
         $geshi->enable_classes();
     }
     if (isset($_POST['submit'])) {
         $geshi_out = $geshi->parse_code();
     }
 } else {
     /* Don't pre-select any language */
     $_POST['language'] = NULL;
 }
 ?>
예제 #24
0
 * @package    EasyCreator
 * @subpackage Views
 * @author     Nikolai Plath (elkuku)
 * @author     Created on 06-Oct-2008
 * @license    GNU/GPL, see JROOT/LICENSE.php
 */
//-- No direct access
defined('_JEXEC') || die('=;)');
jimport('geshi.geshi');
$snip = array();
for ($i = $this->startAtLine - 1; $i < $this->endAtLine; $i++) {
    $snip[] = $this->fileContents[$i];
}
//for
$snip = implode("\n", $snip);
//-- Code language for GeSHi
$lang = 'php';
//-- Alternating line colors
$background1 = '#fcfcfc';
$background2 = '#f0f0f0';
//-- Replace tag markers
$snip = str_replace('&lt;', '<', $snip);
$snip = str_replace('&gt;', '>', $snip);
//-- Replace TAB's with spaces
$snip = str_replace("\t", '   ', $snip);
$geshi = new GeSHi($snip, $lang);
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
$geshi->set_line_style('background: ' . $background1 . ';', 'background: ' . $background2 . ';', true);
$geshi->start_line_numbers_at($this->startAtLine);
echo '<h3>' . substr($this->path, strlen(JPATH_ROOT) + 1) . '</h3>';
echo $geshi->parse_code();
예제 #25
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;
 }
예제 #26
0
&nbsp;<p>Let's go right away with an example using Html and Javascript. Just 
copy the following code, save it in a .html file and then open it from a Web 
Browser. The example prints the current title and the time remaining.</p>
<?php 
$source = "<html>\n\t<head>\n\t\t<script type=\"text/javascript\" src=\"http://code.jquery.com/jquery-latest.js\"></script>\n\t\t<script type=\"text/javascript\">\n\t\tfunction getLiveInfo(){\n\t\t\t\$.getJSON('http://samesub.com/api/v1/live/getall?callback=?',\n\t\t\t\t{},\n\t\t\t\tfunction(data) {\n\t\t\t\t\t//If everything is ok(response_code == 200), let's print some LIVE information\n\t\t\t\t\tif(data.response_code == 200){\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}else{\n\t\t\t\t\t\t//Otherwise alert data.response_message\t\t\t\t\n\t\t\t\t\t\talert(data.response_message);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t\t\n\t\t//When the page has loaded, we call our function\n\t\t\$(document).ready(function() {\n\t\t\tgetLiveInfo();\n\t\t});\n\t\t</script>\n\t</head>\n\t<body>\n\t\t<h1>My First Samesub API example</h1>\n\t\t<p>Current Title: <span id=\"title\"></span></p>\n\t\t<p>Time remaining: <span id=\"time_remaining\"></span></p>\n\t</body>\n</html>";
$language = 'Javascript';
$geshi = new GeSHi($source, $language);
$geshi->enable_classes();
$geshi->set_overall_class('myjs_lines');
$geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
$geshi->set_overall_style("padding:0 0 5px 0;border:1px solid #999999");
$geshi->set_tab_width(2);
$geshi->set_header_content("(<LANGUAGE>) Example - Getting current subject info in homepage(LIVE) using Jquery");
$geshi->set_header_content_style("background-color: #DFDFFF;font-size:14px;font-weight:bold;");
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_line_style('background: #fcfcfc;', true);
Yii::app()->clientScript->registerCss('highlightcode', $geshi->get_stylesheet());
echo $geshi->parse_code();
?>

<p>&nbsp;</p>
<p>Let's analyze the code step by step:</p>
<ol>
	<li>We include the <a href="http://jquery.com/">Jquery Javascript Framework</a> 
	to make our work more easy.</li>
<li>We use the 
<a href="api#live/getall">live/getall</a> API resource to get the information in live(homepage).</li>
	<li>For this example we have added a callback parameter to the url (notice
	<b>callback=?</b>) to prevent 'Same Origin' security policy error, since 
	this example runs in a Web Browser. Read
	<a href="http://en.wikipedia.org/wiki/JSONP">JSONp</a> for more. <b>NOTE</b>: 
예제 #27
0
<?php

include_once 'geshi.php';
$source = file_get_contents('sample.ino');
$language = "arduino";
$target = "_blank";
$geshi = new GeSHi($source, $language);
$geshi->set_line_style('background: #FCFCFC;');
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_link_target($target);
$code = $geshi->parse_code();
// Display highlighted code
echo $code;
// Write highlighted code to cache...
//$destination = "sample.html";
//file_put_contents( $destination, $code );