Happy 2017
[squirrelmail.git] / plugins / squirrelspell / sqspell_functions.php
index ad871e31b1d221f19b73d4927de067a3f84ccff7..dfb14986e9dafe5d97ac28304addcfafd4e19693 100644 (file)
 <?php
+
 /**
  * sqspell_functions.php
- * ----------------------
- * All SquirrelSpell-wide functions are in this file.
  *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
+ * All SquirrelSpell-wide functions are in this file.
  *
- * @author Konstantin Riabitsev <icon@duke.edu>
+ * @author Konstantin Riabitsev <icon at duke.edu>
+ * @copyright 1999-2017 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package plugins
  * @subpackage squirrelspell
  */
 
+/** globalize configuration vars **/
+global $SQSPELL_APP, $SQSPELL_APP_DEFAULT, $SQSPELL_WORDS_FILE, $SQSPELL_CRYPTO;
+
+/**
+ * load plugin configuration
+ * @todo allow storing configuration file in config/ directory
+ */
+include_once(SM_PATH . 'plugins/squirrelspell/sqspell_config.php');
+
+/**
+ * Workaround for including function squirrelspell_version() in SM 1.5 CVS,
+ * where plugins' setup.php is not included by default.
+ */
+include_once(SM_PATH . 'plugins/squirrelspell/setup.php');
+
+/** Hooked functions **/
+
+/**
+ * Register option page block (internal function)
+ * @since 1.5.1 (sqspell 0.5)
+ * @return void
+ */
+function squirrelspell_optpage_block_function() {
+  global $optpage_blocks;
+
+  /**
+   * Dependency on JavaScript is checked by SquirrelMail scripts
+   * Register Squirrelspell with the $optpage_blocks array.
+   */
+  $optpage_blocks[] =
+    array(
+      'name' => _("SpellChecker Options"),
+      'url'  => '../plugins/squirrelspell/sqspell_options.php',
+      'desc' => _("Here you may set up how your personal dictionary is stored, edit it, or choose which languages should be available to you when spell-checking."),
+      'js'   => TRUE);
+}
+
+/**
+ * This function adds a "Check Spelling" link to the "Compose" row
+ * during message composition (internal function).
+ * @since 1.5.1 (sqspell 0.5)
+ * @return void
+ */
+function squirrelspell_setup_function() {
+  /**
+   * Check if this browser is capable of displaying SquirrelSpell
+   * correctly.
+   */
+  if (checkForJavascript()) {
+
+    global $oTemplate, $base_uri, $nbsp;
+
+    $output = addButton(_("Check Spelling"), 
+                        'check_spelling', 
+                        array('onclick' => 'window.open(\'' . $base_uri 
+                                         . 'plugins/squirrelspell/sqspell_interface.php\', \'sqspell\', \'status=yes,width=550,height=370,resizable=yes\')')) . $nbsp;
+
+    return array('compose_button_row' => $output);
+  }
+}
+
+/**
+ * Upgrade dictionaries (internal function)
+ *
+ * Transparently upgrades user's dictionaries when message listing is loaded
+ * @since 1.5.1 (sqspell 0.5)
+ */
+function squirrelspell_upgrade_function() {
+  global $data_dir, $username;
+
+  if (! sqspell_check_version(0,5)) {
+    $langs=sqspell_getSettings_old(null);
+    $words=sqspell_getWords_old();
+    sqspell_saveSettings($langs);
+    foreach ($langs as $lang) {
+      $lang_words=sqspell_getLang_old($words,$lang);
+      $aLang_words=explode("\n",$lang_words);
+      $new_words=array();
+      foreach($aLang_words as $word) {
+        if (! preg_match("/^#/",$word) && trim($word)!='') {
+          $new_words[]=$word;
+        }
+      }
+      sqspell_writeWords($new_words,$lang);
+    }
+    // bump up version number
+    setPref($data_dir,$username,'sqspell_version','0.5');
+  }
+}
+
+/** Internal functions **/
+
 /**
  * This function is the GUI wrapper for the options page. SquirrelSpell
  * uses it for creating all Options pages.
  * @return            void
  */
 function sqspell_makePage($title, $scriptsrc, $body){
-  global $color, $SQSPELL_VERSION;
+  global $color;
 
   if (! sqgetGlobalVar('MOD', $MOD, SQ_GET) ) {
       $MOD = 'options_main';
   }
 
-  displayPageHeader($color, 'None');
+  displayPageHeader($color);
   echo "&nbsp;<br />\n";
   /**
    * Check if we need to link in a script.
@@ -93,7 +185,7 @@ function sqspell_makePage($title, $scriptsrc, $body){
  * @return            void
  */
 function sqspell_makeWindow($onload, $title, $scriptsrc, $body){
-  global $color, $SQSPELL_VERSION;
+  global $color;
 
   displayHtmlHeader($title,
       ($scriptsrc ? "\n<script type=\"text/javascript\" src=\"js/$scriptsrc\"></script>\n" : ''));
@@ -126,8 +218,10 @@ function sqspell_makeWindow($onload, $title, $scriptsrc, $body){
           html_tag( 'tr', "\n" .
               html_tag( 'td', 'SquirrelSpell ' . squirrelspell_version(), 'center', $color[9] )
           ) ,
-      '', '', 'width="100%" border="0" cellpadding="2"' )
-    . "</body>\n</html>\n";
+      '', '', 'width="100%" border="0" cellpadding="2"' );
+
+  global $oTemplate;
+  $oTemplate->display('footer.tpl');
 }
 
 /**
@@ -289,7 +383,7 @@ function sqspell_upgradeWordsFile($words_string){
 
 /**
  * gets list of available dictionaries from user's prefs.
- * Function was modified in 1.5.1 (sqspell 0.5). 
+ * Function was modified in 1.5.1 (sqspell 0.5).
  * Older function is suffixed with '_old'
  * @return array list of dictionaries used by end user.
  */
@@ -574,7 +668,7 @@ function sqspell_writeWords($words,$lang){
      */
     sqgetGlobalVar('key', $key, SQ_COOKIE);
     sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
-    
+
     $clear_key=OneTimePadDecrypt($key, $onetimepad);
     /**
      * Try encrypting it. If fails, scream bloody hell.
@@ -648,7 +742,7 @@ function sqspell_writeWords_old($words){
 
 /**
  * Deletes user's dictionary
- * Function was modified in 1.5.1 (sqspell 0.5). Older function is suffixed 
+ * Function was modified in 1.5.1 (sqspell 0.5). Older function is suffixed
  * with '_old'
  * @param string $lang dictionary
  */
@@ -704,7 +798,7 @@ function sqspell_ckMOD($rMOD){
       || strstr($rMOD, '/')
       || strstr($rMOD, '%')
       || strstr($rMOD, "\\")){
-    echo _("Cute.");
+    echo _("Invalid URL");
     exit;
   }
 }
@@ -755,18 +849,20 @@ function sqspell_handle_crypt_panic($lang=false) {
     .  _("SquirrelSpell was unable to decrypt your personal dictionary. This is most likely due to the fact that you have changed your mailbox password. In order to proceed, you will have to supply your old password so that SquirrelSpell can decrypt your personal dictionary. It will be re-encrypted with your new password after this. If you haven't encrypted your dictionary, then it got mangled and is no longer valid. You will have to delete it and start anew. This is also true if you don't remember your old password -- without it, the encrypted data is no longer accessible.") ,
     'left' ) .  "\n"
     . (($lang) ? html_tag('p',sprintf(_("Your %s dictionary is encrypted with password that differs from your current password."),
-                                      htmlspecialchars($lang)),'left') : '') 
+                                      sm_encode_html_special_chars($lang)),'left') : '')
     . '<blockquote>' . "\n"
     . '<form method="post" onsubmit="return AYS()">' . "\n"
     . '<input type="hidden" name="MOD" value="crypto_badkey" />' . "\n"
-    . (($lang) ? 
-       '<input type="hidden" name="dict_lang" value="'.htmlspecialchars($lang).'" />' : 
+    . (($lang) ?
+       '<input type="hidden" name="dict_lang" value="'.sm_encode_html_special_chars($lang).'" />' :
        '<input type="hidden" name="old_setup" value="yes" />')
     . html_tag( 'p',  "\n" .
-        '<input type="checkbox" name="delete_words" value="ON" />'
-        . _("Delete my dictionary and start a new one") . '<br />'
+        '<input type="checkbox" name="delete_words" value="ON" id="delete_words" />'
+        . '<label for="delete_words">'
+        . _("Delete my dictionary and start a new one")
+        . '</label><br /><label for="old_key">'
         . _("Decrypt my dictionary with my old password:")
-        . '<input name="old_key" size="10" />' ,
+        . '</label><input type="text" name="old_key" id="old_key" size="10" />' ,
         'left' ) . "\n"
         . '</blockquote>' . "\n"
         . html_tag( 'p', "\n"
@@ -777,7 +873,7 @@ function sqspell_handle_crypt_panic($lang=false) {
   /**
    * Add some string vars so they can be i18n'd.
    */
-  $msg .= "<script type='text/javascript'><!--\n"
+  $msg .= "<script type=\"text/javascript\"><!--\n"
     . "var ui_choice = \"" . _("You must make a choice") ."\";\n"
     . "var ui_candel = \"" . _("You can either delete your dictionary or type in the old password. Not both.") . "\";\n"
     . "var ui_willdel = \"" . _("This will delete your personal dictionary file. Proceed?") . "\";\n"
@@ -806,4 +902,3 @@ function sqspell_handle_crypt_panic($lang=false) {
  * @deprecated
  */
 $SQSPELL_VERSION="v0.3.8";
-?>
\ No newline at end of file