[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] news_admin/js/fckeditor/editor/dialog/fck_spellerpag
From: |
skwashd |
Subject: |
[Phpgroupware-cvs] news_admin/js/fckeditor/editor/dialog/fck_spellerpages/spellerpages/server-scripts spellchecker-orig.php, 1.1 spellchecker-pspell.php, 1.1 spellchecker.php, 1.1 |
Date: |
Tue, 24 May 2005 16:32:00 +0200 |
Update of
news_admin/js/fckeditor/editor/dialog/fck_spellerpages/spellerpages/server-scripts
Added Files:
Branch: MAIN
spellchecker-orig.php
spellchecker-pspell.php
spellchecker.php
Log Message:
I am working on a much better version of news_admin, this is just a taste of
what is coming.
Adding FCKeditor, which has the following issues:
* Images and files support FCKd
* Spellcheck FCKing up
Didn't include non php code or samples other unneeded crap
====================================================
Index: spellchecker-orig.php
<?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>
====================================================
Index: spellchecker-pspell.php
<?php
/**************************************************************************\
* phpGroupWare - Communik8r
*
* http://www.phpgroupware.org
*
* Written by Dave Hall skwashd at phpgroupware.org
*
* Portions Copyright 2005, Free Software Foundation Inc
*
* -----------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by
the *
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
/* $Id: spellchecker-pspell.php,v 1.1 2005/05/24 14:32:53 skwashd Exp $
*/
/*
* This is a rather heavily modified version of spellpages
(spellpages.sf.net)
* This version is based on the version which shipped with
* FCKeditor (fckeditor.sf.net). The interface will remains the same
* but the internals now use php-pspell not the aspell cli.
* Also this script is now tightly integrated with phpgw.
*/
$GLOBALS['phpgw_info']['flags'] = array
(
'currentapp' => 'communik8r',
'noheader' => True,
'nonavbar' => True,
//'nocachecontrol' => True
);
include('../../../../../../../../header.inc.php');//yes boys and grrls
that is how far down we are :P
if ( !extension_loaded('pspell') )
{
$prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
if( address@hidden( "{$prefix}pspell" . PHP_SHLIB_SUFFIX) )
{
error_handler( lang('error: php-pspell is not
available, contact your system administrator') );
exit;
}
}
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
# 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()
{
foreach( $_POST['textinputs'] as $key => $val )
{
echo "textinputs[$key] =
decodeURIComponent(\"{$val}\");\n";
}
}
# make declarations for the text input index
function print_textindex_decl( $text_input_idx )
{
echo "words[0][$text_input_idx] = [];\n";
echo "suggs[0][$text_input_idx] = [];\n";
}
# set an element of the JavaScript 'words' array to a misspelled word
function print_words_elem( $word, $index )
{
echo "words[0][$index] = '" . escape_quote( $word ) . "';\n";
}
# set an element of the JavaScript 'suggs' array to a list of
suggestions
function print_suggs_elem( $suggs, $word_index )
{
if ( !is_array($suggs) )
{
$suggs = array();
}
$vals = array();
foreach ( $suggs as $val )
{
if( $val )
{
$vals[] = "'" . escape_quote( $val ) . "'";
}
}
echo "suggs[0][$word_index] = [" . implode(', ', $vals) .
"];\n";
}
# escape single quote
function escape_quote( $str )
{
return addslashes($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()
{
$lang =
$GLOBALS['phpgw_info']['user']['preferences']['common']['lang']; //only for
readability
$dict = pspell_new($lang, '', '', 'utf-8');
$aspell_err = "";
$text = urldecode( implode("\n", $_POST['textinputs']) );
$words = array_flip( array_flip( preg_split('/[\W]+?/', $text)
) );
$i = 0;
print_textindex_decl(0);
foreach ($words as $word)
{
if ( ($word = trim($word) ) && !pspell_check($dict,
$word) )
{
print_words_elem($word, $i);
print_suggs_elem( pspell_suggest($dict, $word),
$i );
++$i;
}
}
}
?>
<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;
words[0] = Array();
suggs[0] = Array();
<?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>
====================================================
Index: spellchecker.php
<?php
/**************************************************************************\
* phpGroupWare - Communik8r
*
* http://www.phpgroupware.org
*
* Written by Dave Hall skwashd at phpgroupware.org
*
* Portions Copyright 2005, Free Software Foundation Inc
*
* -----------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by
the *
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
/* $Id: spellchecker.php,v 1.1 2005/05/24 14:32:53 skwashd Exp $ */
/*
* This is a rather heavily modified version of spellpages
(spellpages.sf.net)
* This version is based on the version which shipped with
* FCKeditor (fckeditor.sf.net). The interface will remains the same
* but the internals now use php-pspell not the aspell cli.
* Also this script is now tightly integrated with phpgw.
*/
$GLOBALS['phpgw_info']['flags'] = array
(
'currentapp' => 'communik8r',
'noheader' => True,
'nonavbar' => True,
//'nocachecontrol' => True
);
include('../../../../../../../../header.inc.php');//yes boys and grrls
that is how far down we are :P
if ( !extension_loaded('pspell') )
{
$prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
if( address@hidden( "{$prefix}pspell" . PHP_SHLIB_SUFFIX) )
{
error_handler( lang('error: php-pspell is not
available, contact your system administrator') );
exit;
}
}
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
# 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()
{
foreach( $_POST['textinputs'] as $key => $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 )
{
echo "words[0][$index] = '" . escape_quote( $word ) . "';\n";
}
# set an element of the JavaScript 'suggs' array to a list of
suggestions
function print_suggs_elem( $suggs, $word_index )
{
if ( !is_array($suggs) )
{
$suggs = array();
}
$vals = array();
foreach ( $suggs as $val )
{
if( $val )
{
$vals[] = "'" . escape_quote( $val ) . "'";
}
}
echo "suggs[0][$word_index] = [" . implode(', ', $vals) .
"];\n";
}
# escape single quote
function escape_quote( $str )
{
return addslashes($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()
{
$lang =
$GLOBALS['phpgw_info']['user']['preferences']['common']['lang']; //only for
readability
$dict = pspell_new($lang, '', '', 'utf-8');
$text = urldecode( implode("\n", $_POST['textinputs']) );
$words = array_flip( array_flip( preg_split('/[\W]+?/', $text)
) );
$i = 0;
print_textindex_decl(0);
foreach ($words as $word)
{
if ( !pspell_check($dict, $word) )
{
print_words_elem($word, $i);
print_suggs_elem( pspell_suggest($dict, $word),
$i );
++$i;
}
}
}
?>
<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>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] news_admin/js/fckeditor/editor/dialog/fck_spellerpages/spellerpages/server-scripts spellchecker-orig.php, 1.1 spellchecker-pspell.php, 1.1 spellchecker.php, 1.1,
skwashd <=
- Prev by Date:
[Phpgroupware-cvs] news_admin/js/fckeditor/editor/css fck_internal.css, 1.1 fck_editorarea.css, 1.1
- Next by Date:
[Phpgroupware-cvs] news_admin/js/fckeditor/editor/skins/default fck_contextmenu.css, 1.1 fck_dialog.css, 1.1 fck_editor.css, 1.1
- Previous by thread:
[Phpgroupware-cvs] news_admin/js/fckeditor/editor/css fck_internal.css, 1.1 fck_editorarea.css, 1.1
- Next by thread:
[Phpgroupware-cvs] news_admin/js/fckeditor/editor/skins/default fck_contextmenu.css, 1.1 fck_dialog.css, 1.1 fck_editor.css, 1.1
- Index(es):