* @copyright 1999-2013 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
* @package plugins
* @subpackage squirrelspell
*/
/**
* This function makes a javascript-powered link. Not sure why
* Philippe decided to move it outside the main code, but hey. ;)
* I bet for the i18n reasons.
*
* @param $jscode Javascript code to include in the link.
* @param $title A little pop-up title to provide for the links.
* @param $link The content of the link.
* @return void, since this just draws the content.
*/
function SpellLink($jscode, $title, $link) {
echo "
$link"
. ' | ';
}
/**
* Declaring globals for users with E_ALL set.
*/
global $SQSPELL_APP_DEFAULT, $SQSPELL_APP, $SQSPELL_SPELLCHECKER,
$SQSPELL_FORCE_POPEN, $attachment_dir, $color;
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 two reasons:
* 1) So we can ignore lines starting with ">" (reply's)
* 2) So we can stop processing when we get to "--" on a single line,
* which means that the signature is starting
*/
$sqspell_raw_lines = explode("\n", $sqspell_text);
for ($i=0; $i'){
$sqspell_new_lines[$i] = $sqspell_raw_lines[$i];
} else {
$sqspell_new_lines[$i] = '';
}
}
/**
* $sqspell_new_lines array now contains the lines to submit to the
* spellchecker.
*/
$sqspell_new_text=implode("\n", $sqspell_new_lines);
include_once(SM_PATH . 'plugins/squirrelspell/class/common.php');
$aParams = array();
$aParams['words'] = sqspell_getLang($sqspell_use_app);
if ($SQSPELL_SPELLCHECKER===1) {
include_once(SM_PATH . 'plugins/squirrelspell/class/php_pspell.php');
$aParams['dictionary'] = $SQSPELL_APP[$sqspell_use_app];
$aParams['charset'] = $default_charset;
$check = new php_pspell($aParams);
} else {
include_once(SM_PATH . 'plugins/squirrelspell/class/cmd_spell.php');
$aParams['spell_command'] = $SQSPELL_APP[$sqspell_use_app];
if ($SQSPELL_FORCE_POPEN) {
$aParams['use_proc_open'] = false;
} else {
$aParams['use_proc_open'] = check_php_version(4,3);
}
$aParams['temp_dir'] = $attachment_dir;
$aParams['debug'] = false;
$check = new cmd_spell($aParams);
}
/**
* Check for class constructor function errors
*/
if (!empty($check->error)) {
$msg= ''
. nl2br(sm_encode_html_special_chars($check->error))
. '
';
sqspell_makeWindow(null, _("SquirrelSpell is misconfigured."), null, $msg);
exit;
}
$missed_words=Array();
$misses = Array();
$locations = Array();
$errors=0;
$results = $check->check_text($sqspell_new_text);
/**
* Check for execution errors
*/
if (!empty($check->error)) {
$msg= ''
. nl2br(sm_encode_html_special_chars($check->error))
. '
';
sqspell_makeWindow(null, _("SquirrelSpell is misconfigured."), null, $msg);
exit;
}
if (is_array($results)) {
// convert variables to old style squirrelspell results
if (!empty($results)) {
foreach(array_keys($results) as $word) {
if (isset($results[$word]['locations'])) {
$missed_words[] = $word;
$locations[$word] = implode(', ',$results[$word]['locations']);
if (isset($results[$word]['suggestions'])) {
$misses[$word] = implode(', ',$results[$word]['suggestions']);
} else {
$misses[$word] = '_NONE';
}
} else {
// $word without 'locations'. ignore it
}
}
$errors = count($missed_words);
}
} else {
if (!empty($check->error)) {
$error_msg = nl2br(sm_encode_html_special_chars($check->error));
} else {
$error_msg = _("Unknown error");
}
$msg= ''
. $error_msg
. '
';
sqspell_makeWindow(null, _("SquirrelSpell error."), null, $msg);
exit;
}
if ($errors){
/**
* Load the spelling errors into JavaScript arrays
* (More dark magic!)
*/
$extrajs="\n"
. "\n";
displayHtmlHeader(_("SquirrelSpell Results"),$extrajs);
echo "\n";
?>