phpDocumentor updates
[squirrelmail.git] / plugins / newmail / functions.php
index ecb41ecd2a8a2bb931112dc6642c4d2df6f9b72f..d45b59e73bf3ea49d9a0b49c86cef3bde1284212 100644 (file)
@@ -1,11 +1,16 @@
 <?php
+
 /**
  * SquirrelMail NewMail plugin
  *
  * Functions
+ *
+ * @copyright &copy; 2001-2005 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package plugins
  * @subpackage newmail
+ * @todo add midi support
  */
 
 /** @ignore */
@@ -44,22 +49,20 @@ function newmail_optpage_register_block_function() {
     // Gets added to the user's OPTIONS page.
     global $optpage_blocks;
 
-    if ( checkForJavascript() ) {
-        /* Register Squirrelspell with the $optionpages array. */
-        $optpage_blocks[] = array(
-            'name' => _("NewMail Options"),
-            'url'  => sqm_baseuri() . 'plugins/newmail/newmail_opt.php',
-            'desc' => _("This configures settings for playing sounds and/or showing popup windows when new mail arrives."),
-            'js'   => TRUE
-            );
-    }
+    /* Register Squirrelspell with the $optionpages array. */
+    $optpage_blocks[] = array(
+        'name' => _("NewMail Options"),
+        'url'  => sqm_baseuri() . 'plugins/newmail/newmail_opt.php',
+        'desc' => _("This configures settings for playing sounds and/or showing popup windows when new mail arrives."),
+        'js'   => TRUE
+        );
 }
 
 /**
  * Save newmail plugin settings
  */
 function newmail_sav_function() {
-    global $data_dir, $username, $_FILES;
+    global $data_dir, $username, $_FILES, $newmail_uploadsounds;
 
     if ( sqgetGlobalVar('submit_newmail', $submit, SQ_POST) ) {
         $media_enable = '';
@@ -101,7 +104,7 @@ function newmail_sav_function() {
         }
 
         // process uploaded file
-        if (isset($_FILES['media_file']['tmp_name']) && $_FILES['media_file']['tmp_name']!='') {
+        if ($newmail_uploadsounds && 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');
@@ -144,6 +147,10 @@ function newmail_pref_function() {
     $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)');
+    // remove full location from setting (since SM 1.5.1 plugin uses only filename).
+    if ($newmail_media!='(none)')
+        $newmail_media = basename($newmail_media);
+
     $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);
@@ -421,13 +428,15 @@ function newmail_media_objects($object,$types,$path,$args=array(),$extra='',$add
 
     if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
         $ret.= newmail_media_embed($object,$types[0],$path,$args,$addsuffix);
-    // add $extra code inside objects 
+    // add $extra code inside objects
     if ($extra!='')
         $ret.=$extra . "\n";
 
+    // close embed tags
     if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
         $ret.= newmail_media_embed_close($types[0]);
 
+    // close w3.org nested objects
     foreach (array_reverse($types) as $type) {
         $ret.= newmail_media_object_close($type);
     }
@@ -511,6 +520,7 @@ function newmail_media_object($object,$type,$path,$args=array(),$addsuffix=true)
  * @param array $args media object attributes
  * @param bool $addsuffix controls addition of suffix to media object url
  * @return string object html tags and attributes required by selected media type.
+ * @todo add ogg and svg support 
  */
 function newmail_media_object_ie($object,$type,$path,$args=array(),$addsuffix) {
     $ret_ie='';
@@ -552,7 +562,7 @@ function newmail_media_object_ie($object,$type,$path,$args=array(),$addsuffix) {
 
 /**
  * Creates embed tags of multimedia object
- *        
+ *
  * docs about embed
  * Apple: http://www.apple.com/quicktime/authoring/embed.html
  *
@@ -593,11 +603,33 @@ function newmail_media_embed($object,$type,$path,$args=array(),$addsuffix=true)
             .' name="' . $object .'" ' . "\n"
             .' type="audio/x-wav">' . "\n";
         break;
+    case SM_NEWMAIL_FILETYPE_SVG:
+        if ($addsuffix) $suffix='.svg';
+        $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
+            .'hidden="true" autostart="true" '. "\n"
+            .$sArgs . "\n"
+            .'name="' . $object .'" ' . "\n"
+            .'type="image/svg-xml" ' . "\n"
+            .'pluginspage="http://www.adobe.com/svg/viewer/install/">' . "\n";
+        break;
     case SM_NEWMAIL_FILETYPE_OGG:
+        if ($addsuffix) $suffix='.ogg';
+        $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
+            .' hidden="true" autostart="true" '. "\n"
+            .' ' .$sArgs . "\n"
+            .' name="' . $object .'" ' . "\n"
+            .' type="application/ogg">' . "\n";
+        break;
     case SM_NEWMAIL_FILETYPE_MP3:
-    case SM_NEWMAIL_FILETYPE_SVG:
+        if ($addsuffix) $suffix='.mp3';
+        $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
+            .' hidden="true" autostart="true" '. "\n"
+            .' ' .$sArgs . "\n"
+            .' name="' . $object .'" ' . "\n"
+            .' type="audio/mpeg">' . "\n";
+        break;
     default:
-        $ret_embed='';    
+        $ret_embed='';
     }
     return $ret_embed;
 }
@@ -605,7 +637,7 @@ function newmail_media_embed($object,$type,$path,$args=array(),$addsuffix=true)
 /**
  * Adds closing tags for ie object
  * Warning:
- * * This is internal function, use newmail_media_objects() instead 
+ * * This is internal function, use newmail_media_objects() instead
  * @param integer $type media object type
  * @return string closing tag of media object
  */
@@ -620,7 +652,7 @@ function newmail_media_object_ie_close($type) {
     case SM_NEWMAIL_FILETYPE_OGG:
     case SM_NEWMAIL_FILETYPE_SVG:
     default:
-        $ret_end='';    
+        $ret_end='';
     }
     return $ret_end;
 }
@@ -628,7 +660,7 @@ function newmail_media_object_ie_close($type) {
 /**
  * Adds closing tags for object
  * Warning:
- * * This is internal function, use newmail_media_objects() instead 
+ * * This is internal function, use newmail_media_objects() instead
  * @param integer $type media object type
  * @return string closing tag of media object
  */
@@ -643,7 +675,7 @@ function newmail_media_object_close($type) {
         $ret_end="</object>\n";
         break;
     default:
-        $ret_end='';    
+        $ret_end='';
     }
     return $ret_end;
 }
@@ -651,7 +683,7 @@ function newmail_media_object_close($type) {
 /**
  * Adds closing tags for object
  * Warning:
- * * This is internal function, use newmail_media_objects() instead 
+ * * This is internal function, use newmail_media_objects() instead
  * @param integer $type media object type
  * @return string closing tag of media object
  */
@@ -660,13 +692,13 @@ function newmail_media_embed_close($type) {
     switch ($type) {
     case SM_NEWMAIL_FILETYPE_SWF:
     case SM_NEWMAIL_FILETYPE_WAV:
-       $ret_end="</embed>\n";
-        break;
     case SM_NEWMAIL_FILETYPE_OGG:
     case SM_NEWMAIL_FILETYPE_MP3:
     case SM_NEWMAIL_FILETYPE_SVG:
+       $ret_end="</embed>\n";
+        break;
     default:
-        $ret_end='';    
+        $ret_end='';
     }
     return $ret_end;
 }
@@ -675,14 +707,14 @@ function newmail_media_embed_close($type) {
  * Converts media attributes to string
  * Warning:
  * * attribute values are automatically sanitized by htmlspecialchars()
- * * This is internal function, use newmail_media_objects() instead 
+ * * This is internal function, use newmail_media_objects() instead
  * @param array $args array with object attributes
  * @return string string with object attributes
  */
 function newmail_media_prepare_args($args) {
     $ret_args='';
     foreach ($args as $arg => $value) {
-        $ret_args.= $arg . '="' . htmlspecialchars($value) . '" '; 
+        $ret_args.= $arg . '="' . htmlspecialchars($value) . '" ';
     }
     return $ret_args;
 }