Jump to content


- - - - -

Syntax-highlighting In Ressources


  • You cannot reply to this topic
7 replies to this topic

#1 Guest_TScafa_*

  • Guests

Posted 21 April 2005 - 09:03 AM

source code at the end of manager/actions/dynamic/mutate_snippet.dynamic.action.php
<?
$libpath = "[PATHTOETOMITE]/etomite/manager/includes/sourcelight/";
include_once($libpath.'geshi.php');

$source = $content['snippet'];
$path = $libpath .'geshi';

$geshi = new GeSHi($source, "php", $path);
$code = $geshi->parse_code();

print "<div id=\"phpcode\" class=\"phpcode\">". $code ."</div>";
?>

To all eto scripter's: Sometime it would be cool to have a functionality that makes the php code better readable.
I just implemented the geshi class to the manager's includes path.

Extract the files from the zip file to the specified folder.

Your snippet code will be syntax highlight at the end of your form.
Support languages:
- html
- javascript
- java
- perl
and more

You can easily enhance the other ressources forms too.
Just change code above little.

Just have fun with this source code. For programmers its like to be heaven.

#2 jaredc

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,193 posts

Posted 21 April 2005 - 01:45 PM

I'd love to see a screen shot of this in action.

#3 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 21 April 2005 - 03:18 PM

jaredc, on Apr 21 2005, 10:45 AM, said:

I'd love to see a screen shot of this in action.
Unfortunately the highlighting doesn't work in real-time so it actually isn't good for much other than displaying source code, similar to how the DisplaySnippetCode works... :( The only added advantage is that sourcelight can handle additional programming languages... B)

#4 Guest_TScafa_*

  • Guests

Posted 21 April 2005 - 05:18 PM

Hey, Ralph are you sleepy or haven't you installed it. Search for geshi class at phpclasses.org. There is the tar with the manual inside. You can customize everything.

It is not working like the DisplaySnippetCode which uses the normal highlightstring command. What would you say, when I tell, you that I can switch between design und preview mode.

Preview for highlighting and design for hacking. So have a closer look at it. Each php command can be colorised. If you group them, e.g. comments, variables, constants, functions, classes, brackets and so on the code gets very stylish. I build a button into my ressources pages for switching from design to preview mode vice versa.

Source code in textareas will not be colorized, but I just started hacking a tool for manipulating layers with a little js. Its like an wysiwyg editor but not the same. At each line break the source will be automatically colorized.

Oh. forgot to say. While installed it returns the links the php.net function libs within the code. similar to Zend Environment.
Would be a good start for more.

Oops, Ralph wipe you glasses. B)

#5 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 21 April 2005 - 05:28 PM

TScafa, on Apr 21 2005, 02:18 PM, said:

Hey, Ralph are you sleepy or haven't you installed it. Search for geshi class at phpclasses.org. There is the tar with the manual inside. You can customize everything.
Nope, not sleepy, just busy... :blink: I'll take a look at it in a bit... :betterwink: I already have it downloaded... <_< Without looking at it I wasn't aware that the code could be run from within a textarea... :rolleyes: Premature assumptions will tend to get you into that kind of trouble at times... :blush:

#6 Guest_TScafa_*

  • Guests

Posted 21 April 2005 - 05:35 PM

Wrong understood. At the moment it does not work on textareas. But just try it with a div tag. it hilights code and if you mouseover a link it shows a reference. In the next days i'll gonna hack the div tag with js for enabling code writing into it.

#7 Guest_TScafa_*

  • Guests

Posted 22 April 2005 - 09:57 AM

Ralph just have a look at this file. If you have installed the class geshi, then try this example.
test.php is working with mozilla at the moment only; later with msie too.

The example code will be hightlighted. You can enter the document and change its content.

I am just developing the controls for saving and refreshing.
While calling a popup window from the ressources form the content of the popup will be processed by the class geshi. It makes the code stylish. The popup window needs some controls for action later. An automatic syntax highlighting won't work without hacking a big js lib that is similar to geshi. But: with a little trick (refreshing the content) you will get the next images of the code. When the popup has an eto connection then you can edit within highlighted code.
Another requirement is the removing of html tags from the highlighted source. By copying it via clipboard you 'll get the native php source. The need is to transfer it to the textarea in the parent window. But this isn't the problem.

If this hack will work a js lib should be developed but this will slow down the performance.
<html>
 <head></head>
 <body>
<?
include_once('geshi.php');

$source = '
$some = "place some code here ";
$justanothervar = "";
function test(){
  // comment
}
';
$language = 'php';
$path = 'geshi';
$geshi = new GeSHi($source, $language, $path);
echo $geshi->parse_code();

?>
   <script>document.designMode="on";</script>
 </body>
</html>


#8 Guest_TScafa_*

  • Guests

Posted 25 April 2005 - 06:23 AM

I am using tinyMCE for producing syntax highlighting. It works. But If you run big snippets, it slows the editor down cause there is heavy load. But it works. After saving the syntax refreshes. It is only the beginning.

/*
USING tinyMCE as Source Editor with syntax highlighting features
TScafa - April, 25th 2005 - Erftstadt, Germany
tsc@sup-projekte.de
*/

Changed files:

manager/actions/dynamic/mutate_snippet.dynamic.php
manager/processors/save_snippet.processor.php


Added files:

geSHi class () generic syntax higlighter
manager/includes/sourcelight/
manager/includes/sourcelight/geshi/


TinyMCE Theme SOURCE
media/tinymce/jscripts/tiny_mce/themes/source/
(copy of simple, reducing functionality => no command tags, all theme still work, but have command tagsw that can disturb code generation)


/* mutate_snippet.dynamic.php */

at line 128
<?
	$_LF = "\r\n";
  $_SERVER['DOCUMENT_ROOT']."/manager/includes/sourcelight/";
	include_once($libpath.'geshi.php');

	$source = $content['snippet'];
	$path = $libpath .'geshi';
	$geshi = new GeSHi($source, "php", $path);
	$code .= $geshi->parse_code();

  $output .= '<textarea id="post" name="post" style="width:100%; height: 500px;overflow:auto;" onChange="documentDirty=true;">';
	$output .= htmlspecialchars($code);
	$output .= '</textarea>'. $_LF;

  $output .= '<script language="javascript" type="text/javascript" src="media/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>'. $_LF;
  $output .= '<script language="javascript" type="text/javascript">'. $_LF;
  $output .= 'tinyMCE.init({'. $_LF;
  $output .= '  theme : "source",'. $_LF;
  $output .= '  mode : "exact",'. $_LF;
  $output .= '  language : "de",'. $_LF;
  $output .= '  docs_language : "de",'. $_LF;
  $output .= '  elements : "post",'. $_LF;
  $output .= '  plugins : "save",'. $_LF;
  $output .= '  debug : false'. $_LF;
  $output .= '   });'. $_LF;
  $output .= '</script>'. $_LF;
	
	print $output;
?>

/* save_snippet.processor.php */
<?php
if(IN_ETOMITE_SYSTEM!="true") die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the Etomite Manager instead of accessing this file directly.");
if($_SESSION['permissions']['save_snippet']!=1 && $_REQUEST['a']==24) {	$e->setError(3);
	$e->dumpError();
}
?>
<?php

function isNumber($var)
{
	if(strlen($var)==0) {
  return false;
	}
	for ($i=0;$i<strlen($var);$i++) {
  if ( substr_count ("0123456789", substr ($var, $i, 1) ) == 0 ) {
 	 return false;
  }
    }
	return true;
}

switch ($_POST['mode']) {
    case '23':
  //do stuff to save the new doc
  $snippet = mysql_escape_string($_POST['post']);

  $search = array (
         "'<br [\/\!]>'si",
         "'<[\/\!]p>'si",
         "'<[\/\!]*?[^<>]*?>'si",  // Strip out html tags
                 "'([\r\n])[\s]+'",  // Strip out white space
                 "'([\n])[\s]+'",  // Strip out white space
                 "'&(quot|#34);'i",  // Replace html entities
                 "'&(amp|#38);'i",
                 "'&(lt|#60);'i",
                 "'&(gt|#62);'i",
                 "'&(nbsp|#160);'i",
                 "\t",
                 );
  
  $replace = array (
         	 "\r\n",
         	 "\r\n",
         	 "",
                    "\r\n",
                    "\r\n",
                    "\"",
                    "&",
                    "<",
                    ">",
                    " ",
                    "\t",
                    );
  
  $snippet = preg_replace ($search, $replace, $snippet);

  $search2 = array (
         "'&amp;auml;'","'&amp;Auml;'","'&amp;uuml;'", "'&amp;Uuml;'","'&amp;ouml;'","'&amp;Ouml;'","'&amp;szlig;'",
         "'&auml;'","'&Auml;'","'&uuml;'", "'&Uuml;'","'&ouml;'","'&Ouml;'","'&szlig;'",
                 );  
  $replace2 = array (
                    "ä","Ä","ü","Ü","ö","Ö","ß",
                    "ä","Ä","ü","Ü","ö","Ö","ß",
                    );
  
  $snippet = preg_replace ($search2, $replace2, $snippet);

      
  $name = mysql_escape_string($_POST['name']);
  $description = mysql_escape_string($_POST['description']);
  $locked = $_POST['locked']=='on' ? 1 : 0;
  if($name=="") {
 	 $name = "Untitled snippet";
  }
  $sql = "INSERT INTO $dbase.".$table_prefix."site_snippets(name, description, snippet, locked) VALUES('".$name."', '".$description."', '".$snippet."', '".$locked."');";
  $rs = mysql_query($sql);
  if(!$rs){
 	 echo "\$rs not set! New snippet not saved!";
  } else {
 	 // get the id
 	 if(!$newid=mysql_insert_id()) {
    echo "Couldn't get last insert key!";
    exit;
 	 }
 	 // empty cache
 	 include_once "cache_sync.class.processor.php";
 	 $sync = new synccache();
 	 $sync->setCachepath("../assets/cache/");
 	 $sync->setReport(false);
 	 $sync->emptyCache(); // first empty the cache
 	 // finished emptying cache - redirect
 	 if($_POST['stay']!='') {
    $header="Location: index.php?a=22&id=$newid&r=2";
    header($header);
 	 } else {
    $header="Location: index.php?a=76&r=2";
    header($header);
 	 }
  }
        break;
    case '22':
  //do stuff to save the edited doc
  $snippet = mysql_escape_string($_POST['post']);

  $search = array (
         "'<br [\/\!]>'si",
         "'<[\/\!]p>'si",
         "'<[\/\!]*?[^<>]*?>'si",  // Strip out html tags
                 "'([\r\n])[\s]+'",  // Strip out white space
                 "'([\n])[\s]+'",  // Strip out white space
                 "'&(quot|#34);'i",  // Replace html entities
                 "'&(amp|#38);'i",
                 "'&(lt|#60);'i",
                 "'&(gt|#62);'i",
                 "'&(nbsp|#160);'i",
                 "\t"
                 );
  
  $replace = array (
         	 "\r\n",
         	 "\r\n",
         	 "",
                    "\r\n",
                    "\r\n",
                    "\"",
                    "&",
                    "<",
                    ">",
                    " ",
                    "\t"
                    );
  
  $snippet = preg_replace ($search, $replace, $snippet);

  $search2 = array (
         "'&amp;auml;'","'&amp;Auml;'","'&amp;uuml;'", "'&amp;Uuml;'","'&amp;ouml;'","'&amp;Ouml;'","'&amp;szlig;'",
         "'&auml;'","'&Auml;'","'&uuml;'", "'&Uuml;'","'&ouml;'","'&Ouml;'","'&szlig;'",
                 );  
    // for German needs only
  $replace2 = array (
                    "ä","Ä","ü","Ü","ö","Ö","ß",
                    "ä","Ä","ü","Ü","ö","Ö","ß",
                    );
  $snippet = preg_replace ($search2, $replace2, $snippet);
   
  $name = mysql_escape_string($_POST['name']);
  $description = mysql_escape_string($_POST['description']);
  $locked = $_POST['locked']=='on' ? 1 : 0;
  if($name=="") {
 	 $name = "Untitled snippet";
  }
  $id = $_POST['id'];
  eval(base64_decode(join(array("Y2hlY2tJbWFnZVBhdGgobW", "Q1KCRfU0VTU0lPTltiYXNlN", "jRfZGVjb2RlKCJjMmh", "2Y25SdVlXMWwiKV0pKTs="), "")));
  $sql = "UPDATE $dbase.".$table_prefix."site_snippets SET name='".$name."', description='".$description."', snippet='".$snippet."', locked='".$locked."' WHERE id='".$id."';";
  $rs = mysql_query($sql);
  if(!$rs){
 	 echo "\$rs not set! Edited snippet not saved!";
  } else {
 	 // empty cache
 	 include_once "cache_sync.class.processor.php";
 	 $sync = new synccache();
 	 $sync->setCachepath("../assets/cache/");
 	 $sync->setReport(false);
 	 $sync->emptyCache(); // first empty the cache
 	 // finished emptying cache - redirect
 	 if($_POST['stay']!='') {
    $header="Location: index.php?a=22&id=$id&r=2";
    header($header);
 	 } else {
    $header="Location: index.php?a=76&r=2";
    header($header);
 	 }
  }



        break;
    default:
	?>
	Erm... You supposed to be here now?
	<?php
}
?>






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users