Back to index

moin  1.9.0~rc2
Functions | Variables
spellchecker.php File Reference

Go to the source code of this file.

Functions

 print_textinputs_var ()
 print_textindex_decl ($text_input_idx)
 print_words_elem ($word, $index, $text_input_idx)
 print_suggs_elem ($suggs, $index, $text_input_idx)
 escape_quote ($str)
 error_handler ($err)
 print_checker_results ()

Variables

 $aspell_prog = '"C:\Program Files\Aspell\bin\aspell.exe"'
 $lang = 'en_US'
 $aspell_opts = "-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt"
 $tempfiledir = "./"
 $spellercss = '../spellerStyle.css'
 $word_win_src = '../wordWindow.js'
 $textinputs = $_POST['textinputs']
 $input_separator = "A"

Function Documentation

error_handler ( err)

Definition at line 64 of file spellchecker.php.

                               {
       echo "error = '" . preg_replace( "/['\\\\]/", "\\\\$0", $err ) . "';\n";
}

Here is the caller graph for this function:

escape_quote ( str)

Definition at line 58 of file spellchecker.php.

                              {
       return preg_replace ( "/'/", "\\'", $str );
}

Here is the caller graph for this function:

Definition at line 70 of file spellchecker.php.

                                 {

       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] );

                     // Strip all tags for the text. (by FredCK - #339 / #681)
                     $text = preg_replace( "/<[^>]+>/", " ", $text ) ;

                     $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 );
}

Here is the call graph for this function:

print_suggs_elem ( suggs,
index,
text_input_idx 
)

Definition at line 44 of file spellchecker.php.

                                                             {
       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";
}

Here is the call graph for this function:

Here is the caller graph for this function:

print_textindex_decl ( text_input_idx)

Definition at line 32 of file spellchecker.php.

                                                 {
       echo "words[$text_input_idx] = [];\n";
       echo "suggs[$text_input_idx] = [];\n";
}

Here is the caller graph for this function:

Definition at line 23 of file spellchecker.php.

                                {
       global $textinputs;
       foreach( $textinputs as $key=>$val ) {
              # $val = str_replace( "'", "%27", $val );
              echo "textinputs[$key] = decodeURIComponent(\"" . $val . "\");\n";
       }
}
print_words_elem ( word,
index,
text_input_idx 
)

Definition at line 38 of file spellchecker.php.

                                                            {
       echo "words[$text_input_idx][$index] = '" . escape_quote( $word ) . "';\n";
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

$aspell_opts = "-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt"

Definition at line 10 of file spellchecker.php.

$aspell_prog = '"C:\Program Files\Aspell\bin\aspell.exe"'

Definition at line 6 of file spellchecker.php.

$input_separator = "A"

Definition at line 18 of file spellchecker.php.

$lang = 'en_US'

Definition at line 9 of file spellchecker.php.

$spellercss = '../spellerStyle.css'

Definition at line 14 of file spellchecker.php.

$tempfiledir = "./"

Definition at line 12 of file spellchecker.php.

$textinputs = $_POST['textinputs']

Definition at line 17 of file spellchecker.php.

$word_win_src = '../wordWindow.js'

Definition at line 15 of file spellchecker.php.