Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads
 
Add your own
alternative version

HTMLEditor Provider - How to write a custom provider for ASP.NET 2.0

, 5 Sep 2006
A tutorial on how to use the Provider Templates to create your own provider.
HTMLEditor.zip
SeaburyDesign
FCKEditorHTMLProvider
Properties
FreeTextBoxProvider
Properties
HTMLProviderDemo
App_Data
Bin
FCKEditorHTMLProvider.dll
FredCK.FCKeditorV2.dll
FreeTextBox.dll
FreeTextBoxHTMLProvider.dll
HTMLEditor.dll
TextboxHTMLProvider.dll
FCKeditor
editor
css
behaviors
disablehandles.htc
hiddenfield.gif
hiddenfield.htc
showtableborders.htc
images
fck_anchor.gif
fck_flashlogo.gif
fck_pagebreak.gif
dialog
common
fcknumericfield.htc
images
locked.gif
reset.gif
unlocked.gif
fck_about
logo_fckeditor.gif
logo_fredck.gif
fck_docprops
fck_flash
fck_image
fck_link
fck_select
fck_spellerpages
spellerpages
server-scripts
spellchecker.cfm
spellchecker.pl
fck_template
images
template1.gif
template2.gif
template3.gif
fck_universalkey
00.gif
keyboard_layout.gif
filemanager
browser
default
connectors
asp
aspx
cfm
config.cfm
connector.cfm
lasso
config.lasso
connector.lasso
perl
basexml.pl
commands.pl
connector.cgi
io.pl
upload_fck.pl
util.pl
php
py
images
ButtonArrow.gif
Folder.gif
Folder32.gif
FolderOpened.gif
FolderOpened32.gif
FolderUp.gif
icons
32
ai.gif
avi.gif
bmp.gif
cs.gif
default.icon.gif
dll.gif
doc.gif
exe.gif
fla.gif
gif.gif
htm.gif
html.gif
jpg.gif
js.gif
mdb.gif
mp3.gif
pdf.gif
ppt.gif
rdp.gif
swf.gif
swt.gif
txt.gif
vsd.gif
xls.gif
xml.gif
zip.gif
ai.gif
avi.gif
bmp.gif
cs.gif
default.icon.gif
dll.gif
doc.gif
exe.gif
fla.gif
gif.gif
htm.gif
html.gif
jpg.gif
js.gif
mdb.gif
mp3.gif
pdf.gif
ppt.gif
rdp.gif
swf.gif
swt.gif
txt.gif
vsd.gif
xls.gif
xml.gif
zip.gif
spacer.gif
js
upload
asp
aspx
cfm
config.cfm
upload.cfm
lasso
config.lasso
upload.lasso
php
images
anchor.gif
arrow_ltr.gif
arrow_rtl.gif
smiley
msn
angel_smile.gif
angry_smile.gif
broken_heart.gif
cake.gif
confused_smile.gif
cry_smile.gif
devil_smile.gif
embaressed_smile.gif
envelope.gif
heart.gif
kiss.gif
lightbulb.gif
omg_smile.gif
regular_smile.gif
sad_smile.gif
shades_smile.gif
teeth_smile.gif
thumbs_down.gif
thumbs_up.gif
tounge_smile.gif
whatchutalkingabout_smile.gif
wink_smile.gif
spacer.gif
js
lang
plugins
autogrow
placeholder
lang
placeholder.gif
simplecommands
tablecommands
skins
default
fck_strip.gif
images
toolbar.arrowright.gif
toolbar.buttonarrow.gif
toolbar.collapse.gif
toolbar.end.gif
toolbar.expand.gif
toolbar.separator.gif
toolbar.start.gif
office2003
fck_strip.gif
images
toolbar.arrowright.gif
toolbar.bg.gif
toolbar.buttonarrow.gif
toolbar.collapse.gif
toolbar.end.gif
toolbar.expand.gif
toolbar.separator.gif
toolbar.start.gif
silver
fck_strip.gif
images
toolbar.arrowright.gif
toolbar.buttonarrow.gif
toolbar.buttonbg.gif
toolbar.collapse.gif
toolbar.end.gif
toolbar.expand.gif
toolbar.separator.gif
toolbar.start.gif
_source
classes
commandclasses
internals
fckeditor.afp
fckeditor.cfc
fckeditor.cfm
fckeditor.lasso
fckeditor.pl
_samples
afp
fck.afpa
fck.afpa.code
sample01.afp
sampleposteddata.afp
asp
cfm
sample01.cfm
sample02_mx.cfm
html
lasso
sample01.lasso
sample02.lasso
sample03.lasso
sample04.lasso
sampleposteddata.lasso
perl
sample01.cgi
sample02.cgi
sample03.cgi
sample04.cgi
sampleposteddata.cgi
php
py
_plugins
findreplace
find.gif
lang
replace.gif
samples
_testcases
SeaburyDesign
Properties
TextboxHTMLProvider
Properties
HTMLEditor_no_FCK.zip
FCKEditorHTMLProvider.dll
FredCK.FCKeditorV2.dll
FreeTextBox.dll
FreeTextBoxHTMLProvider.dll
HTMLEditor.dll
TextboxHTMLProvider.dll
HtmlEditor_src.zip
<?php
header('Content-type: text/html; charset=utf-8');

//$spellercss = '/speller/spellerStyle.css';	// by FredCK
$spellercss = '../spellerStyle.css';			// by FredCK
//$word_win_src = '/speller/wordWindow.js';		// by FredCK
$word_win_src = '../wordWindow.js';				// by FredCK
$textinputs = $_POST['textinputs']; # array
//$aspell_prog = 'aspell';									// by FredCK (for Linux)
$aspell_prog = '"C:\Program Files\Aspell\bin\aspell.exe"';	// by FredCK (for Windows)
$lang = 'en_US';
//$aspell_opts = "-a --lang=$lang --encoding=utf-8";	// by FredCK
$aspell_opts = "-a --lang=$lang --encoding=utf-8 -H";	// by FredCK
$tempfiledir = "./";
$input_separator = "A";

# set the JavaScript variable to the submitted text.
# textinputs is an array, each element corresponding to the (url-encoded)
# value of the text control submitted for spell-checking
function print_textinputs_var() {
	global $textinputs;
	foreach( $textinputs as $key=>$val ) {
		# $val = str_replace( "'", "%27", $val );
		echo "textinputs[$key] = decodeURIComponent(\"" . $val . "\");\n";
	}
}

# make declarations for the text input index
function print_textindex_decl( $text_input_idx ) {
	echo "words[$text_input_idx] = [];\n";
	echo "suggs[$text_input_idx] = [];\n";
}

# set an element of the JavaScript 'words' array to a misspelled word
function print_words_elem( $word, $index, $text_input_idx ) {
	echo "words[$text_input_idx][$index] = '" . escape_quote( $word ) . "';\n";
}


# set an element of the JavaScript 'suggs' array to a list of suggestions
function print_suggs_elem( $suggs, $index, $text_input_idx ) {
	echo "suggs[$text_input_idx][$index] = [";
	foreach( $suggs as $key=>$val ) {
		if( $val ) {
			echo "'" . escape_quote( $val ) . "'";
			if ( $key+1 < count( $suggs )) {
				echo ", ";
			}
		}
	}
	echo "];\n";
}

# escape single quote
function escape_quote( $str ) {
	return preg_replace ( "/'/", "\\'", $str );
}


# handle a server-side error.
function error_handler( $err ) {
	echo "error = '" . escape_quote( $err ) . "';\n";
}

## get the list of misspelled words. Put the results in the javascript words array
## for each misspelled word, get suggestions and put in the javascript suggs array
function print_checker_results() {

	global $aspell_prog;
	global $aspell_opts;
	global $tempfiledir;
	global $textinputs;
	global $input_separator;
	$aspell_err = "";
	# create temp file
	$tempfile = tempnam( $tempfiledir, 'aspell_data_' );

	# open temp file, add the submitted text.
	if( $fh = fopen( $tempfile, 'w' )) {
		for( $i = 0; $i < count( $textinputs ); $i++ ) {
			$text = urldecode( $textinputs[$i] );
			$lines = explode( "\n", $text );
			fwrite ( $fh, "%\n" ); # exit terse mode
			fwrite ( $fh, "^$input_separator\n" );
			fwrite ( $fh, "!\n" ); # enter terse mode
			foreach( $lines as $key=>$value ) {
				# use carat on each line to escape possible aspell commands
				fwrite( $fh, "^$value\n" );
			}
		}
		fclose( $fh );

		# exec aspell command - redirect STDERR to STDOUT
		$cmd = "$aspell_prog $aspell_opts < $tempfile 2>&1";
		if( $aspellret = shell_exec( $cmd )) {
			$linesout = explode( "\n", $aspellret );
			$index = 0;
			$text_input_index = -1;
			# parse each line of aspell return
			foreach( $linesout as $key=>$val ) {
				$chardesc = substr( $val, 0, 1 );
				# if '&', then not in dictionary but has suggestions
				# if '#', then not in dictionary and no suggestions
				# if '*', then it is a delimiter between text inputs
				# if '@' then version info
				if( $chardesc == '&' || $chardesc == '#' ) {
					$line = explode( " ", $val, 5 );
					print_words_elem( $line[1], $index, $text_input_index );
					if( isset( $line[4] )) {
						$suggs = explode( ", ", $line[4] );
					} else {
						$suggs = array();
					}
					print_suggs_elem( $suggs, $index, $text_input_index );
					$index++;
				} elseif( $chardesc == '*' ) {
					$text_input_index++;
					print_textindex_decl( $text_input_index );
					$index = 0;
				} elseif( $chardesc != '@' && $chardesc != "" ) {
					# assume this is error output
					$aspell_err .= $val;
				}
			}
			if( $aspell_err ) {
				$aspell_err = "Error executing `$cmd`\\n$aspell_err";
				error_handler( $aspell_err );
			}
		} else {
			error_handler( "System error: Aspell program execution failed (`$cmd`)" );
		}
	} else {
		error_handler( "System error: Could not open file '$tempfile' for writing" );
	}

	# close temp file, delete file
	unlink( $tempfile );
}


?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="<?php echo $spellercss ?>" />
<script language="javascript" src="<?php echo $word_win_src ?>"></script>
<script language="javascript">
var suggs = new Array();
var words = new Array();
var textinputs = new Array();
var error;
<?php

print_textinputs_var();

print_checker_results();

?>

var wordWindowObj = new wordWindow();
wordWindowObj.originalSpellings = words;
wordWindowObj.suggestions = suggs;
wordWindowObj.textInputs = textinputs;

function init_spell() {
	// check if any error occured during server-side processing
	if( error ) {
		alert( error );
	} else {
		// call the init_spell() function in the parent frameset
		if (parent.frames.length) {
			parent.init_spell( wordWindowObj );
		} else {
			alert('This page was loaded outside of a frameset. It might not display properly');
		}
	}
}



</script>

</head>
<!-- <body onLoad="init_spell();">		by FredCK -->
<body onLoad="init_spell();" bgcolor="#ffffff">

<script type="text/javascript">
wordWindowObj.writeBody();
</script>

</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Todd Davis
Systems Engineer Virtual RadioLogic
United States United States
Todd Davis has been working in web and application development for several years, using Silverlight, ASP.NET, VB.NET, C#, C++ and Javascript, as well as a great deal of work with SQL server and IIS.
 
He currently works for Virtual Radiologic in Eden Prairie, MN, however he is better known for his varied work in the open source community, especially the DotNetNuke project for which he provided several world-renowned training videos and modules. A huge advocate of open source and open knowledge sharing, everything on his website (www.SeaburyDesign.com) is always offered for free.
 
Whenever he is not actively coding at his laptop (a rarity to be sure), he can be found woodworking, walking with his wife and kids, or motoring along the back roads of MN on his Harley Davidson Fatboy.

| Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 5 Sep 2006
Article Copyright 2006 by Todd Davis
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid