X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fsquirrelspell%2Fmodules%2Fcheck_me.mod;h=0d9c510cb1ad6490e1ecb422254b8586181ab626;hb=6c99d1de81366bceab6c9d6cf12179eedc81f9bc;hp=ebc1dc1ff8790201f41c928f9c01827adb966ff5;hpb=2b6b400e03d88916613c47ce603dd5ee218c0588;p=squirrelmail.git diff --git a/plugins/squirrelspell/modules/check_me.mod b/plugins/squirrelspell/modules/check_me.mod index ebc1dc1f..0d9c510c 100644 --- a/plugins/squirrelspell/modules/check_me.mod +++ b/plugins/squirrelspell/modules/check_me.mod @@ -1,20 +1,20 @@ ($Author$) - * @version $Date$ + * @author Konstantin Riabitsev + * @copyright © 1999-2006 The SquirrelMail Project Team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + * @version $Id$ + * @package plugins + * @subpackage squirrelspell */ /** @@ -36,10 +36,14 @@ function SpellLink($jscode, $title, $link) { /** * Declaring globals for users with E_ALL set. */ -global $SQSPELL_APP, $attachment_dir, $SQSPELL_EREG, $color; +global $SQSPELL_APP_DEFAULT, $SQSPELL_APP, $attachment_dir, $color; -$sqspell_text = $_POST['sqspell_text']; -$sqspell_use_app = $_POST['sqspell_use_app']; +if (! sqgetGlobalVar('sqspell_text',$sqspell_text,SQ_POST)) { + $sqspell_text = ''; +} +if (! sqgetGlobalVar('sqspell_use_app',$sqspell_use_app,SQ_POST)) { + $sqspell_use_app = $SQSPELL_APP_DEFAULT; +} /** * Now we explode the lines for three reasons: @@ -66,7 +70,7 @@ for ($i=0; $i= 4.3.0, we can use proc_open and safe mode + * and not mess w/ temp files. Otherwise we will do it the old + * way, (minus the uneeded call to cat that messes up Wintel + * boxen.) + * Thanks Ray Ferguson for providing this patch. */ -do { - $floc = "$attachment_dir/" . md5($sqspell_new_text . microtime()); -} while (file_exists($floc)); -/** - * Write the contents to the file. - */ -$fp=fopen($floc, 'w'); -fwrite($fp, $sqspell_new_text); -fclose($fp); -/** - * Execute ispell/aspell and catch the output. - */ -exec("cat $floc | $sqspell_command 2>&1", $sqspell_output, $sqspell_exitcode); -/** - * Remove the temp file. - */ -unlink($floc); +if( check_php_version ( 4, 3 ) ) { + $descriptorspec = array( + 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 + ); + $spell_proc = @proc_open($sqspell_command, $descriptorspec, $pipes); + if ( ! is_resource ( $spell_proc ) ) { + // TODO: replace error_box() with sqspell_makeWindow() + error_box ( sprintf(_("Could not run the spellchecker command (%s)."), + htmlspecialchars($sqspell_command) ) ); + // display footer (closes html tags) and stop script execution + $oTemplate->display('footer.tpl'); + exit(); + } + if ( ! @fwrite($pipes[0], $sqspell_new_text) ) { + // TODO: replace error_box() with sqspell_makeWindow() + error_box ( _("Error while writing to pipe.") ); + // close all three $pipes here. + for($i=0; $i<=2; $i++) { + // disable all fclose error messages + @fclose($pipes[$i]); + } + // close html tags and abort script. + $oTemplate->display('footer.tpl'); + exit(); + } + fclose($pipes[0]); + $sqspell_output = array(); + for($i=1; $i<=2; $i++) { + while(!feof($pipes[$i])) { + array_push($sqspell_output, rtrim(fgetss($pipes[$i],999),"\r\n")); + } + fclose($pipes[$i]); + } + $sqspell_exitcode=proc_close($spell_proc); +} else { + // add slash to attachment directory, if it does not end with slash. + if (substr($attachment_dir, -1) != '/') + $attachment_dir = $attachment_dir . '/'; + + // find unused file in attachment directory + do { + $floc = $attachment_dir . md5($sqspell_new_text . microtime()); + } while (file_exists($floc)); + + $fp = @fopen($floc, 'w'); + if ( ! is_resource ($fp) ) { + // TODO: replace error_box() with sqspell_makeWindow() + error_box ( sprintf(_("Could not open temporary file '%s'."), + htmlspecialchars($floc) ) ); + // failed to open temp file. abort script. + $oTemplate->display('footer.tpl'); + exit(); + } + if ( ! @fwrite($fp, $sqspell_new_text) ) { + // TODO: replace error_box() with sqspell_makeWindow() + error_box ( sprintf(_("Error while writing to temporary file '%s'."), + htmlspecialchars($floc) ) ); + // close file descriptor + fclose($fp); + // failed writing to temp file. abort script. + $oTemplate->display('footer.tpl'); + exit(); + } + fclose($fp); + exec("$sqspell_command < $floc 2>&1", $sqspell_output, $sqspell_exitcode); + unlink($floc); +} /** * Check if the execution was successful. Bail out if it wasn't. */ if ($sqspell_exitcode){ - $msg= "
" + $msg= '
' . sprintf(_("I tried to execute '%s', but it returned:"), $sqspell_command) . "
"
-     . join("\n", htmlspecialchars($sqspell_output)) . "
" - . "
" - . "
"; + . htmlspecialchars(join("\n", $sqspell_output)) . '' + . '
' + . '
'; sqspell_makeWindow(null, _("SquirrelSpell is misconfigured."), null, $msg); exit; } @@ -127,7 +178,7 @@ if ($sqspell_exitcode){ /** * Load the user dictionary. */ -$words=sqspell_getLang(sqspell_getWords(), $sqspell_use_app); +$words=sqspell_getLang($sqspell_use_app); /** * Define some variables to be used during the processing. */ @@ -163,7 +214,7 @@ for ($i=0; $i\n" - . "\n" - . '' . _("SquirrelSpell Results") . ''; - /** - * Check if there are user-defined stylesheets. - */ - if ($theme_css != '') { - echo "\n"; - } /** * Load the spelling errors into JavaScript arrays * (More dark magic!) */ - echo "\n" - . "\n" - . "\n"; - + . "\n"; + + + displayHtmlHeader(_("SquirrelSpell Results"),$extrajs); + echo "\n"; @@ -301,13 +339,13 @@ if ($errors){ - + -
+
@@ -315,7 +353,7 @@ if ($errors){
- @@ -325,7 +363,7 @@ if ($errors){ echo $sptag . _("Line with an error:") . ''; ?>
- @@ -336,7 +374,7 @@ if ($errors){ ?> - + - + - @@ -431,9 +469,9 @@ if ($errors){ /** * AREN'T YOU SUCH A KNOW-IT-ALL! */ - $msg="
" - . "
"; + $msg='
' . + '
'; sqspell_makeWindow(null, _("No errors found"), null, $msg); } @@ -442,6 +480,5 @@ if ($errors){ * Local variables: * mode: php * End: - * vim: syntax=php + * vim: syntax=php et ts=4 */ -?>
- @@ -345,7 +383,7 @@ if ($errors){ ?> - + onfocus="if(!this.value) this.value=document.forms[0].sqspell_error.value" /> - +


- +


- ' - . ' '; + + ' + . ' '; ?>