fixed function_exist test and used newer mcrypt functions. If squirrelmail
[squirrelmail.git] / plugins / squirrelspell / sqspell_functions.php
index 00b031bde17627741e9fe4723cec3cdd1a6527e8..ee9c1266e846e90c2ae9bff514d64628701dcdb6 100644 (file)
@@ -4,13 +4,15 @@
  * ----------------------
  * All SquirrelSpell-wide functions are in this file.
  *
- * Copyright (c) 1999-2002 The SquirrelMail development team
+ * Copyright (c) 1999-2004 The SquirrelMail development team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * $Id$
  *
  * @author Konstantin Riabitsev <icon@duke.edu> ($Author$)
  * @version $Date$
+ * @package plugins
+ * @subpackage squirrelspell
  */
 
 /**
  * @return            void
  */
 function sqspell_makePage($title, $scriptsrc, $body){
-  global $color, $SQSPELL_VERSION, $MOD;
+  global $color, $SQSPELL_VERSION;
+
+  if (! sqgetGlobalVar('MOD', $MOD, SQ_GET) ) {
+      $MOD = 'options_main';
+  }
+
   displayPageHeader($color, 'None');  
-  echo "&nbsp;<br>\n";
+  echo "&nbsp;<br />\n";
   /**
    * Check if we need to link in a script.
    */
   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>";
+  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 '<tr><td><hr></td></tr>'
-      . '<tr><td align="center"><a href="sqspell_options.php">'
-      . _("Back to &quot;SpellChecker Options&quot; page") 
-      . '</a></td></tr>';
+    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 &quot;SpellChecker Options&quot; page")
+                . '</a>',
+            'center' )
+        ) . "\n";
   }
   /**
    * Close the table and display the version.
    */
-  echo '<tr><td><hr></td></tr>'
-    . '<tr>'
-    . "<td bgcolor=\"$color[9]\" align=center>"
-    . "SquirrelSpell $SQSPELL_VERSION"
-    . '</td>'
-    . '</tr>'
-    . '</table>';
+  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>';
 }
 
 /**
@@ -82,52 +95,40 @@ function sqspell_makePage($title, $scriptsrc, $body){
  * @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]\"";
+  global $color, $SQSPELL_VERSION;
+
+  displayHtmlHeader($title,
+      ($scriptsrc ? "\n<script type=\"text/javascript\" src=\"js/$scriptsrc\"></script>\n" : ''));
+
+  echo "<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\"";
+      echo " onload=\"$onload\"";
   }
   /**
    * Draw the rest of the page.
    */
-  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>'
+  echo ">\n"
+    . 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";
 }
 
@@ -150,7 +151,7 @@ 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)) {
+  if (!function_exists('mcrypt_generic')) {
     return 'PANIC';
   }
   /**
@@ -182,7 +183,14 @@ function sqspell_crypto($mode, $ckey, $input){
   /**
    * Finish up the mcrypt routines and return the processed content.
    */
-  mcrypt_generic_end ($td);
+  if (function_exists('mcrypt_generic_deinit')) {
+      // php 4.1.1+ syntax
+      mcrypt_generic_deinit ($td);
+      mcrypt_module_close ($td);
+  } else {
+      // older depreciated function
+      mcrypt_generic_end ($td);
+  }
   return $crypto;
 }
 
@@ -326,9 +334,13 @@ function sqspell_getWords(){
      * the user's old mailbox password. I admin, this is rather dirty,
      * but efficient. ;)
      */
-    global $key, $onetimepad, $old_key;
-    if ($old_key) {
-      $clear_key=$old_key;
+    sqgetGlobalVar('key', $key, SQ_COOKIE);
+    sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
+
+    sqgetGlobalVar('old_key', $old_key, SQ_POST);
+
+    if ($old_key != '') {
+        $clear_key=$old_key;
     } else {
       /**
        * Get user's password (the key).
@@ -352,21 +364,33 @@ function sqspell_getWords(){
        * The _("SquirrelSpell...) line has to be on one line, otherwise
        * gettext will bork. ;(
        */
-      $msg='<p>'
-        . '<strong>' . _("ATTENTION:") . '</strong><br>'
-        .  _("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.<br>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.")
-        . '</p>'
-        . '<blockquote>'
-        . '<form method="post" onsubmit="return AYS()">'
-        . '<input type="hidden" name="MOD" value="crypto_badkey">'
-        . '<p><input type="checkbox" name="delete_words" value="ON">'
-        . _("Delete my dictionary and start a new one") . '<br>'
-        . _("Decrypt my dictionary with my old password:")
-        . '<input name="old_key" size=\"10\"></p>'
-        . '</blockquote>'
-        . '<p align="center"><input type="submit" value="' 
-        . _("Proceed") . ' &gt;&gt;"></p>'
-        . '</form>';
+      $msg = html_tag( 'p', "\n" .
+                     '<strong>' . _("ATTENTION:") . '</strong><br />'
+                     .  _("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"
+        . '<blockquote>' . "\n"
+        . '<form method="post" onsubmit="return AYS()">' . "\n"
+        . '<input type="hidden" name="MOD" value="crypto_badkey" />' . "\n"
+        . html_tag( 'p',  "\n" .
+              '<input type="checkbox" name="delete_words" value="ON" />'
+              . _("Delete my dictionary and start a new one") . '<br />'
+              . _("Decrypt my dictionary with my old password:")
+              . '<input name="old_key" size="10" />' ,
+          'left' ) . "\n"
+        . '</blockquote>' . "\n"
+        . html_tag( 'p', "\n" .
+              '<input type="submit" value="' 
+              . _("Proceed") . ' &gt;&gt;" />' ,
+          'center' ) . "\n"
+        . '</form>' . "\n";
+      /**
+       * Add some string vars so they can be i18n'd.
+       */
+      $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"
+        . "//--></script>\n";
       /**
        * See if this happened in the pop-up window or when accessing
        * the SpellChecker options page. 
@@ -374,7 +398,7 @@ function sqspell_getWords(){
        */
       global $SCRIPT_NAME;
       if (strstr($SCRIPT_NAME, "sqspell_options")){
-       sqspell_makePage( _("Error Decrypting Dictionary"), 
+       sqspell_makePage(_("Error Decrypting Dictionary"), 
                          "decrypt_error.js", $msg);
       } else {
        sqspell_makeWindow(null, _("Error Decrypting Dictionary"), 
@@ -426,7 +450,9 @@ function sqspell_writeWords($words){
      * User wants to encrypt the file. So be it.
      * Get the user's password to use as a key.
      */
-    global $key, $onetimepad;
+    sqgetGlobalVar('key', $key, SQ_COOKIE);
+    sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
+
     $clear_key=OneTimePadDecrypt($key, $onetimepad);
     /**
      * Try encrypting it. If fails, scream bloody hell.
@@ -505,5 +531,5 @@ function sqspell_ckMOD($rMOD){
  * of the user dictionary files and messing with this can do ugly 
  * stuff. :)
  */
-$SQSPELL_VERSION="v0.3.7";
-?>
+$SQSPELL_VERSION="v0.3.8";
+?>
\ No newline at end of file