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 (
"'&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 (
"'&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
}
?>