Source for file cmd_spell.php
Documentation is available at cmd_spell.php
* Command line spellcheck class
* Quick brownn fox brownn
* @(#) International Ispell Version 3.1.20 10/10/95, patch 1
* & brownn 5 7: brown, Browne, browns, brown n, brown-n
* & brownn 5 18: brown, Browne, browns, brown n, brown-n
* & brownn 5 1: brown, Browne, browns, brown n, brown-n
* & twentytwo 2 1: twenty two, twenty-two
* $params['spell_command'] = 'ispell -d american -a';
* $params['use_proc_open'] = false; // (check_php_version(4,3))
* $params['temp_dir'] = '/tmp/'; // $attachment_dir
* $params['userdic'] = array(); // user's dictionary
* $params['debug'] = true;
* $spell = new cmd_spell($params);
* // check $spell->error buffer
* $text = "Quick brownn fox brownn\n\nbrownn squirrel.\ntwentytwo owttnewt";
* $results = $spell->check_text($text);
* // check $spell->error buffer
* @copyright © 1999-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: cmd_spell.php,v 1.1 2006/09/30 17:35:20 tokul Exp $
* @subpackage squirrelspell
* Command line spellcheck class, compatible with ispell and aspell.
* @subpackage squirrelspell
* Controls which function is used to execute ispell. proc_open()
* should be used in PHP 4.3+. exec() can be used in older PHP versions.
if (! isset
($aParams['spell_command'])) {
return $this->set_error('Spellcheck command is not set.');
if (isset
($aParams['userdic'])) {
$this->userdic =
$aParams['userdic'];
if (isset
($aParams['use_proc_open'])) {
if (isset
($aParams['temp_dir'])) {
// add slash to attachment directory, if it does not end with slash.
return $this->set_error('Temporally directory is not set.');
if (isset
($aParams['debug']) && (bool)
$aParams['debug']) {
* @return mixed array with command output or false.
0 =>
array('pipe', 'r'), // stdin is a pipe that the child will read from
1 =>
array('pipe', 'w'), // stdout is a pipe that the child will write to
2 =>
array('pipe', 'w'), // stderr is a pipe that the child will write to
if ( ! @fwrite($pipes[0],$sText) ) {
$this->set_error(_("Error while writing to pipe."));
// close all three $pipes here.
// disable all fclose error messages
$sqspell_output =
array();
while(!feof($pipes[$i])) {
foreach ($sqspell_output as $line) {
* @return mixed array with command output or false.
// find unused file in attachment directory
$fp =
@fopen($floc, 'w');
if ( ! @fwrite($fp, $sText) ) {
foreach ($sqspell_output as $line) {
* Prepares string for ispell/aspell parsing
* Function adds an extra space at the beginning of each line. This way
* ispell/aspell don't treat these as command characters.
// prepend space to every sqspell_new_text line
foreach (explode("\n",$sText) as $line) {
$ret.=
' ' .
$line .
"\n";
* @param string $sText text
* Define some variables to be used during the processing.
* Now we process the output of sqspell_command (ispell or aspell in
* ispell compatibility mode, whichever). I'm going to be scarce on
* comments here, since you can just look at the ispell/aspell output
* and figure out what's going on. ;) The best way to describe this is
for ($i=
0; $i<
sizeof($sqspell_output); $i++
){
switch (substr($sqspell_output[$i], 0, 1)){
* Ispell adds empty lines when an end of line is reached
* This means there's a misspelled word and a few suggestions.
list
($left, $right) =
explode(": ", $sqspell_output[$i]);
$sqspell_word=
$tmparray[1];
* Check if the word is in user dictionary.
$sqspell_symb=
intval($tmparray[3])-
1;
foreach(explode(',',$right) as $word) {
$this->missed_words[$sqspell_word]['locations'][] =
"$current_line:$sqspell_symb";
* This means a misspelled word and no suggestions.
$tmparray =
explode(" ", $sqspell_output[$i]);
$sqspell_word=
$tmparray[1];
* Check if the word is in user dictionary.
$sqspell_symb=
intval($tmparray[2])-
1;
$this->missed_words[$sqspell_word]['suggestions'] =
array();
$this->missed_words[$sqspell_word]['locations'][] =
"$current_line:$sqspell_symb";
* Define the command used to spellcheck the document.
#$sqspell_command=$SQSPELL_APP[$sqspell_use_app];
Documentation generated on Sat, 07 Oct 2006 16:09:13 +0300 by phpDocumentor 1.3.0RC6