missing sprintf around string
[squirrelmail.git] / plugins / newmail / setup.php
index 0505765b282c723459808cc742e9c831a5fde2a1..acefda2c3971c979be7b18d3d682ff913e8310a8 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * newmail.php
  *
- * Copyright (c) 1999-2004 The SquirrelMail Project Team
+ * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Copyright (c) 2000 by Michael Huttinger
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  */
 
 /**
+ * sqm_baseuri function for setups that don't load it by default
  */
 include_once(SM_PATH . 'functions/display_messages.php');
 
+/** Load plugin functions */
+include_once(SM_PATH . 'plugins/newmail/functions.php');
+
 /**
  * Checks if mailbox contains new messages.
  *
  * @param object $imapConnection
  * @param mixed $mailbox FIXME: option is not used
- * @param string $real_box unformated mailbox name 
+ * @param string $real_box unformated mailbox name
  * @param mixed $delimeter FIXME: option is not used
  * @param string $unseen FIXME: option is not used
  * @param integer $total_new number of new messages
@@ -43,7 +47,7 @@ include_once(SM_PATH . 'functions/display_messages.php');
  */
 function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_new) {
     global $trash_folder, $sent_folder,
-        $unseen_notify, $newmail_allbox, 
+        $unseen_notify, $newmail_allbox,
         $newmail_recent;
 
     $mailboxURL = urlencode($real_box);
@@ -70,7 +74,7 @@ function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter,
     return 0;
 }
 
-/** 
+/**
  * Init newmail plugin
  */
 function squirrelmail_plugin_init_newmail() {
@@ -105,7 +109,7 @@ function newmail_optpage_register_block() {
  * Save newmail plugin settings
  */
 function newmail_sav() {
-    global $data_dir, $username;
+    global $data_dir, $username, $_FILES;
 
     if ( sqgetGlobalVar('submit_newmail', $submit, SQ_POST) ) {
         $media_enable = '';
@@ -114,25 +118,67 @@ function newmail_sav() {
         $media_recent = '';
         $media_changetitle = '';
         $media_sel = '';
+        $popup_width = '';
+        $popup_height = '';
 
         sqgetGlobalVar('media_enable',      $media_enable,      SQ_POST);
         sqgetGlobalVar('media_popup',       $media_popup,       SQ_POST);
         sqgetGlobalVar('media_allbox',      $media_allbox,      SQ_POST);
         sqgetGlobalVar('media_recent',      $media_recent,      SQ_POST);
         sqgetGlobalVar('media_changetitle', $media_changetitle, SQ_POST);
+        sqgetGlobalVar('popup_width',       $popup_width,       SQ_POST);
+        sqgetGlobalVar('popup_height',      $popup_height,      SQ_POST);
+
+        // sanitize height and width
+        $popup_width = (int) $popup_width;
+        if ($popup_width<=0) $popup_width=200;
+        $popup_height = (int) $popup_height;
+        if ($popup_height<=0) $popup_height=130;
 
         setPref($data_dir,$username,'newmail_enable',$media_enable);
         setPref($data_dir,$username,'newmail_popup', $media_popup);
         setPref($data_dir,$username,'newmail_allbox',$media_allbox);
         setPref($data_dir,$username,'newmail_recent',$media_recent);
         setPref($data_dir,$username,'newmail_changetitle',$media_changetitle);
+        setPref($data_dir,$username,'newmail_popup_width',$popup_width);
+        setPref($data_dir,$username,'newmail_popup_height',$popup_height);
 
         if( sqgetGlobalVar('media_sel', $media_sel, SQ_POST) &&
-            ($media_sel == '(none)' || $media_sel == '(local media)') ) {
+            $media_sel == '(none)' ) {
             removePref($data_dir,$username,'newmail_media');
         } else {
             setPref($data_dir,$username,'newmail_media',$media_sel);
         }
+
+        // process uploaded file
+        if (isset($_FILES['media_file']['tmp_name']) && $_FILES['media_file']['tmp_name']!='') {
+            // set temp file and get media file name
+            $newmail_tempmedia=getHashedDir($username, $data_dir) . "/$username.tempsound";
+            $newmail_mediafile=getHashedFile($username, $data_dir, $username . '.sound');
+            if (move_uploaded_file($_FILES['media_file']['tmp_name'], $newmail_tempmedia)) {
+                // new media file is in $newmail_tempmedia
+                if (file_exists($newmail_mediafile)) unlink($newmail_mediafile);
+                if (! rename($newmail_tempmedia,$newmail_mediafile)) {
+                    // remove (userfile), if file rename fails
+                    removePref($data_dir,$username,'newmail_media');
+                } else {
+                    // store media type
+                    if (isset($_FILES['media_file']['type']) && isset($_FILES['media_file']['name'])) {
+                        setPref($data_dir,$username,'newmail_userfile_type',
+                           newmail_get_mediatype($_FILES['media_file']['type'],$_FILES['media_file']['name']));
+                    } else {
+                        removePref($data_dir,$username,'newmail_userfile_type');
+                    }
+                    // store file name
+                    if (isset($_FILES['media_file']['name'])) {
+                        setPref($data_dir,$username,'newmail_userfile_name',basename($_FILES['media_file']['name']));
+                    } else {
+                        setPref($data_dir,$username,'newmail_userfile_name','mediafile.unknown');
+                    }
+
+                }
+            }
+        }
     }
 }
 
@@ -143,13 +189,20 @@ function newmail_pref() {
     global $username,$data_dir;
     global $newmail_media,$newmail_enable,$newmail_popup,$newmail_allbox;
     global $newmail_recent, $newmail_changetitle;
+    global $newmail_userfile_type, $newmail_userfile_name;
+    global $newmail_popup_width, $newmail_popup_height;
 
     $newmail_recent = getPref($data_dir,$username,'newmail_recent');
     $newmail_enable = getPref($data_dir,$username,'newmail_enable');
     $newmail_media = getPref($data_dir, $username, 'newmail_media', '(none)');
     $newmail_popup = getPref($data_dir, $username, 'newmail_popup');
+    $newmail_popup_width = getPref($data_dir, $username, 'newmail_popup_width',200);
+    $newmail_popup_height = getPref($data_dir, $username, 'newmail_popup_height',130);
     $newmail_allbox = getPref($data_dir, $username, 'newmail_allbox');
     $newmail_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
+
+    $newmail_userfile_type = getPref($data_dir, $username, 'newmail_userfile_type');
+    $newmail_userfile_name = getPref($data_dir,$username,'newmail_userfile_name','');
 }
 
 /**
@@ -170,6 +223,9 @@ function newmail_set_loadinfo() {
 function newmail_plugin() {
     global $username, $newmail_media, $newmail_enable, $newmail_popup,
         $newmail_recent, $newmail_changetitle, $imapConnection, $PHP_SELF;
+    global $newmail_mmedia, $newmail_allowsound;
+    global $newmail_userfile_type;
+    global $newmail_popup_width, $newmail_popup_height;
 
     if ($newmail_enable == 'on' ||
         $newmail_popup == 'on' ||
@@ -198,19 +254,19 @@ function newmail_plugin() {
                     }
                 }
                 if (! $noselect) {
-                    $status += CheckNewMailboxSound($imapConnection, 
+                    $status += CheckNewMailboxSound($imapConnection,
                                                     $mailbox,
-                                                    $boxes[$i]['unformatted'], 
-                                                    $delimeter, 
+                                                    $boxes[$i]['unformatted'],
+                                                    $delimeter,
                                                     $boxes[$i]['unseen'],
                                                     $totalNew);
                 }
             } else {
-                $status += CheckNewMailboxSound($imapConnection, 
-                                                $mailbox, 
+                $status += CheckNewMailboxSound($imapConnection,
+                                                $mailbox,
                                                 $boxes[$i]['unformatted'],
-                                                $delimeter, 
-                                                $boxes[$i]['unseen'], 
+                                                $delimeter,
+                                                $boxes[$i]['unseen'],
                                                 $totalNew);
             }
         }
@@ -221,10 +277,10 @@ function newmail_plugin() {
         // will play the sound as follows:
 
         if ($newmail_changetitle) {
-            echo "<script language=\"javascript\">\n" .
+            echo "<script language=\"javascript\" type=\"text/javascript\">\n" .
                 "function ChangeTitleLoad() {\n";
             echo 'window.parent.document.title = "' .
-                sprintf(ngettext("%s New Message","%s New Messages",$totalNew), $totalNew) . 
+                sprintf(ngettext("%s New Message","%s New Messages",$totalNew), $totalNew) .
                 "\";\n";
             echo    "if (BeforeChangeTitle != null)\n".
                 "BeforeChangeTitle();\n".
@@ -234,28 +290,29 @@ function newmail_plugin() {
                 "</script>\n";
         }
 
-        if ($totalNew > 0 && $newmail_enable == 'on' && $newmail_media != '' ) {
-            echo '<embed src="'.htmlspecialchars($newmail_media) .
-                "\" hidden=\"true\" autostart=\"true\">\n";
+        // create media output if there are new email messages
+        if ($newmail_allowsound && $totalNew > 0 && $newmail_enable == 'on' && $newmail_media != '' ) {
+            echo newmail_create_media_tags($newmail_media);
         }
+
         if ($totalNew > 0 && $newmail_popup == 'on') {
+            // Idea by:  Nic Wolfe (Nic@TimelapseProductions.com)
+            // Web URL:  http://fineline.xs.mw
+            // More code from Tyler Akins
             echo "<script language=\"JavaScript\">\n".
                 "<!--\n".
                 "function PopupScriptLoad() {\n".
                 'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew.
                 '", "SMPopup",'.
-                "\"width=200,height=130,scrollbars=no\");\n".
+                "\"width=$newmail_popup_width,height=$newmail_popup_height,scrollbars=no\");\n".
                 "if (BeforePopupScript != null)\n".
                 "BeforePopupScript();\n".
                 "}\n".
                 "BeforePopupScript = window.onload;\n".
                 "window.onload = PopupScriptLoad;\n".
-                // Idea by:  Nic Wolfe (Nic@TimelapseProductions.com)
-                // Web URL:  http://fineline.xs.mw
-                // More code from Tyler Akins
                 "// End -->\n".
                 "</script>\n";
         }
     }
 }
-?>
\ No newline at end of file
+?>