- /**
- ** sqspell_functions.php -- All SquirrelSpell-wide functions are in this file.
- **
- ** Copyright (c) 1999-2001 The SquirrelMail development team
- ** Licensed under the GNU GPL. For full terms see the file COPYING.
- **
- **
- **
- ** $Id$
- **/
-
- function sqspell_makePage($title, $scriptsrc, $body){
- /*
- ** GUI wrap-around for the OPTIONS page.
- */
- global $color, $SQSPELL_VERSION, $MOD;
- displayPageHeader($color, 'None');
-
- echo " <br>\n";
- if($scriptsrc) {
- echo "<script type=\"text/javascript\" src=\"js/$scriptsrc\"></script>\n";
- }
- echo '<table width="95%" align="center" border="0" cellpadding="2" cellspacing="0">'.
- '<tr>'.
- "<td bgcolor=\"$color[9]\" align=center>".
- "<strong>$title</strong>".
- '</td>'.
- '</tr>'.
- '<tr><td><hr></td></tr>'.
- "<tr><td>$body</td></tr>";
- if ($MOD!="options_main"){
- // Generate a nice return-to-main link.
- echo '<tr><td><hr></td></tr>'.
- '<tr><td align="center"><a href="sqspell_options.php">' .
- _("Back to "SpellChecker Options" page") . '</a></td></tr>';
- }
- echo '<tr><td><hr></td></tr>'.
- '<tr>'.
- "<td bgcolor=\"$color[9]\" align=center>".
- "SquirrelSpell $SQSPELL_VERSION".
- '</td>'.
- '</tr>'.
- '</table>';
- }
-
- function sqspell_makeWindow($onload, $title, $scriptsrc, $body){
-
- /*
- ** GUI wrap-around for the pop-up window interface.
- */
- global $color, $SQSPELL_VERSION, $theme_css;
-
- echo "<html>\n".
- "<head>\n".
- "<title>$title</title>\n";
- if ($theme_css != "") {
- echo "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"$theme_css\">\n";
- }
- if ($scriptsrc){
- echo "<script type=\"text/javascript\" src=\"js/$scriptsrc\"></script>\n";
- }
- echo "</head>\n".
- "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\"";
- if ($onload) {
- echo " onload=\"$onload\"";
- }
- echo '>'.
- '<table width="100%" border="0" cellpadding="2">'.
- '<tr>'.
- "<td bgcolor=\"$color[9]\" align=center>".
- "<strong>$title</strong>".
- '</td>'.
- '</tr>'.
- '<tr><td><hr></td></tr>'.
- '<tr>'.
- "<td>$body</td>".
- '</tr>'.
- '<tr><td><hr></td></tr>'.
- '<tr>'.
- "<td bgcolor=\"$color[9]\" align=center>".
- "SquirrelSpell $SQSPELL_VERSION".
- '</td>'.
- '</tr>'.
- '</table>'.
- "</body>\n</html>\n";
- }
-
- function sqspell_crypto($mode, $ckey, $input){
- //
- // This function does the encryption and decryption of the user
- // dictionary. It is only available when PHP is compiled
- // --with-mcrypt. See doc/CRYPTO for more information.
- //
- if (!function_exists(mcrypt_generic)) {
- return 'PANIC';
- }
- $td = mcrypt_module_open(MCRYPT_Blowfish, "", MCRYPT_MODE_ECB, "");
- $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
- mcrypt_generic_init($td, $ckey, $iv);
- switch ($mode){
- case 'encrypt':
- $crypto = mcrypt_generic($td, $input);
- break;
- case 'decrypt':
- $crypto = mdecrypt_generic($td, $input);
- // See if it decrypted successfully. If so, it should contain
- // the string "# SquirrelSpell".
- if (!strstr($crypto, "# SquirrelSpell"))
- $crypto='PANIC';
- break;
- }
- mcrypt_generic_end ($td);
- return $crypto;
- }
-
- function sqspell_upgradeWordsFile($words_string){
- /*
- ** This function transparently upgrades the 0.2 dictionary format to
- ** 0.3, since user-defined languages have been added in 0.3 and
- ** the new format keeps user dictionaries selection in the file.
- */
- global $SQSPELL_APP_DEFAULT, $SQSPELL_VERSION;
-
- /* Define just one dictionary for this user -- the default.
- ** If the user wants more, s/he can set them up in personal
- ** preferences. See doc/UPGRADING for more info.
- */
- $new_words_string=substr_replace($words_string, "# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# Last Revision: " . date("Y-m-d") . "\n# LANG: $SQSPELL_APP_DEFAULT\n# $SQSPELL_APP_DEFAULT", 0, strpos($words_string, "\n")) . "# End\n";
- sqspell_writeWords($new_words_string);
- return $new_words_string;
- }
-
- function sqspell_getSettings($words){
- /*
- ** Right now it just returns an array with the dictionaries
- ** available to the user for spell-checking. It will probably
- ** do more in the future, as features are added.
- */
- global $SQSPELL_APP, $SQSPELL_APP_DEFAULT;
- if (sizeof($SQSPELL_APP) > 1){
- // OK, so there are more than one dictionary option.
- // Now load the user prefs.
- if(!$words)
- $words=sqspell_getWords();
- if ($words){
- // find which dictionaries user wants to use
- preg_match("/# LANG: (.*)/i", $words, $matches);
- $langs=explode(", ", $matches[1]);
- } else {
- // User doesn't have a personal dictionary. Set him up with
- // a default setting.
- $langs[0]=$SQSPELL_APP_DEFAULT;
- }
- } else {
- // There is only one dictionary defined system-wide.
- $langs[0]=$SQSPELL_APP_DEFAULT;
- }
- return $langs;
+/**
+ * This function is the GUI wrapper for the options page. SquirrelSpell
+ * uses it for creating all Options pages.
+ *
+ * @param $title The title of the page to display
+ * @param $scriptsrc This is used to link a file.js into the
+ * <script src="file.js"></script> format. This
+ * allows to separate javascript from the rest of the
+ * plugin and place it into the js/ directory.
+ * @param $body The body of the message to display.
+ * @return void
+ */
+function sqspell_makePage($title, $scriptsrc, $body){
+ global $color, $SQSPELL_VERSION;
+
+ if (! sqgetGlobalVar('MOD', $MOD, SQ_GET) ) {
+ $MOD = 'options_main';
+ }
+
+ displayPageHeader($color, 'None');
+ echo " <br />\n";
+ /**
+ * Check if we need to link in a script.
+ */
+ if($scriptsrc) {
+ echo "<script type=\"text/javascript\" src=\"js/$scriptsrc\"></script>\n";
+ }
+ echo html_tag( 'table', '', 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) . "\n"
+ . html_tag( 'tr', "\n" .
+ html_tag( 'td', '<strong>' . $title .'</strong>', 'center', $color[9] )
+ ) . "\n"
+ . html_tag( 'tr', "\n" .
+ html_tag( 'td', '<hr>', 'left' )
+ ) . "\n"
+ . html_tag( 'tr', "\n" .
+ html_tag( 'td', $body, 'left' )
+ ) . "\n";
+ /**
+ * Generate a nice "Return to Options" link, unless this is the
+ * starting page.
+ */
+ if ($MOD != "options_main"){
+ echo html_tag( 'tr', "\n" .
+ html_tag( 'td', '<hr>', 'left' )
+ ) . "\n"
+ . html_tag( 'tr', "\n" .
+ html_tag( 'td', '<a href="sqspell_options.php">'
+ . _("Back to "SpellChecker Options" page")
+ . '</a>',
+ 'center' )
+ ) . "\n";
+ }
+ /**
+ * Close the table and display the version.
+ */
+ echo html_tag( 'tr', "\n" .
+ html_tag( 'td', '<hr>', 'left' )
+ ) . "\n"
+ . html_tag( 'tr',
+ html_tag( 'td', 'SquirrelSpell ' . $SQSPELL_VERSION, 'center', $color[9] )
+ ) . "\n</table>\n";
+ echo '</body></html>';
+}
+
+/**
+ * Function similar to the one above. This one is a general wrapper
+ * for the Squirrelspell pop-up window. It's called form nearly
+ * everywhere, except the check_me module, since that one is highly
+ * customized.
+ *
+ * @param $onload Used to indicate and pass the name of a js function
+ * to call in a <body onload="function()" for automatic
+ * onload script execution.
+ * @param $title Title of the page.
+ * @param $scriptsrc If defined, link this javascript source page into
+ * the document using <script src="file.js"> format.
+ * @param $body The content to include.
+ * @return void
+ */
+function sqspell_makeWindow($onload, $title, $scriptsrc, $body){
+ global $color, $SQSPELL_VERSION, $theme_css;
+ echo "<html>\n"
+ . "<head>\n"
+ . "<title>$title</title>\n";
+ /**
+ * Check if we have a defined css theme to use.
+ */
+ if ($theme_css != "") {
+ echo "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"$theme_css\">\n";
+ }
+ /**
+ * Link in the .js file if needed
+ */
+ if ($scriptsrc){
+ echo "<script type=\"text/javascript\" src=\"js/$scriptsrc\"></script>\n";
+ }
+ echo "</head>\n"
+ . "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" "
+ . "vlink=\"$color[7]\" alink=\"$color[7]\"";
+ /**
+ * Provide an onload="jsfunction()" if asked to.
+ */
+ if ($onload) {
+ echo " onload=\"$onload\"";
+ }
+ /**
+ * Draw the rest of the page.
+ */
+ echo '>'
+ . html_tag( 'table', "\n" .
+ html_tag( 'tr', "\n" .
+ html_tag( 'td', '<strong>' . $title . '</strong>', 'center', $color[9] )
+ ) . "\n" .
+ html_tag( 'tr', "\n" .
+ html_tag( 'td', '<hr>', 'left' )
+ ) . "\n" .
+ html_tag( 'tr', "\n" .
+ html_tag( 'td', $body, 'left' )
+ ) . "\n" .
+ html_tag( 'tr', "\n" .
+ html_tag( 'td', '<hr>', 'left' )
+ ) . "\n" .
+ html_tag( 'tr', "\n" .
+ html_tag( 'td', 'SquirrelSpell ' . $SQSPELL_VERSION, 'center', $color[9] )
+ ) ,
+ '', '', 'width="100%" border="0" cellpadding="2"' )
+ . "</body>\n</html>\n";
+}
+
+/**
+ * This function does the encryption and decryption of the user
+ * dictionary. It is only available when PHP is compiled with
+ * mcrypt support (--with-mcrypt). See doc/CRYPTO for more
+ * information.
+ *
+ * @param $mode A string with either of the two recognized values:
+ * "encrypt" or "decrypt".
+ * @param $ckey The key to use for processing (the user's password
+ * in our case.
+ * @param $input Content to decrypt or encrypt, according to $mode.
+ * @return encrypted/decrypted content, or "PANIC" if the
+ * process bails out.
+ */
+function sqspell_crypto($mode, $ckey, $input){
+ /**
+ * Double-check if we have the mcrypt_generic function. Bail out if
+ * not so.
+ */
+ if (!function_exists(mcrypt_generic)) {
+ return 'PANIC';
+ }
+ /**
+ * Setup mcrypt routines.
+ */
+ $td = mcrypt_module_open(MCRYPT_Blowfish, "", MCRYPT_MODE_ECB, "");
+ $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
+ mcrypt_generic_init($td, $ckey, $iv);
+ /**
+ * See what we have to do depending on $mode.
+ * 'encrypt' -- Encrypt the content.
+ * 'decrypt' -- Decrypt the content.
+ */
+ switch ($mode){
+ case 'encrypt':
+ $crypto = mcrypt_generic($td, $input);
+ break;
+ case 'decrypt':
+ $crypto = mdecrypt_generic($td, $input);
+ /**
+ * See if it decrypted successfully. If so, it should contain
+ * the string "# SquirrelSpell". If not, then bail out.
+ */
+ if (!strstr($crypto, "# SquirrelSpell")){
+ $crypto='PANIC';