ソースを参照

don't use full URL in sounds media preferences.
adding configuration option to disable upload of sound files.
adding svg and ogg support in embed tags.

tokul 20 年 前
コミット
31bb264a73

+ 12 - 8
plugins/newmail/README

@@ -1,13 +1,12 @@
 This plugin is used to notify the user when a new mail arrives. There are
 This plugin is used to notify the user when a new mail arrives. There are
-several ways to do this. One is to play a sound (currently a WAV, SWF or MP3
-file) through the browser whenever the user has unseen messages flagged in the
-left window pane. There are options available (on the options page of course) to
-disable this feature for each user, and to select different media files from the
-users local computer. The default is that this is NOT enabled, so you'll need to
-go to the options menu to turn it on first! There are also options to show a
-popup window via JavaScript.
+several ways to do this. One is to play a sound through the browser whenever 
+the user has unseen messages flagged in the left window pane. There are options 
+available (on the options page of course) to disable this feature for each user, 
+and to select different media files from the users local computer. The default 
+is that this is NOT enabled, so you'll need to go to the options menu to turn 
+it on first! There are also options to show a popup window via JavaScript.
 
 
-Plugin options are visible only when Javascript is enabled or detected by
+Plugin options are visible only when JavaScript is enabled or detected by
 SquirrelMail JavaScript detection functions.
 SquirrelMail JavaScript detection functions.
 
 
 From SquirrelMail 1.5.1 newmail plugin's site configuration can be stored in
 From SquirrelMail 1.5.1 newmail plugin's site configuration can be stored in
@@ -16,6 +15,11 @@ config/newmail_config.php or plugins/newmail/config.php.
 $allowsound setting is replaced with $newmail_allowsound and should be stored
 $allowsound setting is replaced with $newmail_allowsound and should be stored
 inside plugin's site configuration file.
 inside plugin's site configuration file.
 
 
+Plugin supports playback of WAV, SWF, MP3, OGG and SVG media files. Currently
+OGG and SVG files are played only by browsers that implement w3.org nested 
+objects correctly and browsers that can play <embed> objects. Internet Explorer 
+can't play them due to broken <object> implementation. OGG and SVG <object> 
+elements specific to IE are not implemented.
 
 
 CREDITS
 CREDITS
 
 

+ 11 - 3
plugins/newmail/config_default.php

@@ -9,12 +9,20 @@
  */
  */
 
 
 /**
 /**
- * Set $allowsound to false if you don't want sound files available
+ * Set $newmail_allowsound to false if you don't want sound files available
  * @global boolean $newmail_allowsound
  * @global boolean $newmail_allowsound
  */
  */
 global $newmail_allowsound;
 global $newmail_allowsound;
 $newmail_allowsound = true;
 $newmail_allowsound = true;
 
 
+/**
+ * Set $newmail_uploadsounds to false if you don't want to allow uploading 
+ * of custom sound files.
+ * @global boolean $newmail_uploadsounds
+ */
+global $newmail_uploadsounds;
+$newmail_uploadsounds = true;
+
 /**
 /**
  * controls insertion of embed tags
  * controls insertion of embed tags
  * @global boolean $newmail_mediacompat_mode
  * @global boolean $newmail_mediacompat_mode
@@ -30,9 +38,9 @@ $newmail_mediacompat_mode=false;
  * $newmail_mmedia['notify']['args']  = array('width'=>0,'height'=>0);
  * $newmail_mmedia['notify']['args']  = array('width'=>0,'height'=>0);
  *
  *
  * These two entries say that media/ directory contains notify.swf, notify.mp3 and notify.wav files
  * These two entries say that media/ directory contains notify.swf, notify.mp3 and notify.wav files
- * Object entities for these files should be use zero width and height attributes
+ * Object elements for these files should use zero width and height attributes
  * @global array $newmail_mmedia
  * @global array $newmail_mmedia
  */
  */
- global $newmail_mmedia;
+global $newmail_mmedia;
 $newmail_mmedia=array();
 $newmail_mmedia=array();
 ?>
 ?>

+ 8 - 1
plugins/newmail/config_sample.php

@@ -8,9 +8,16 @@
  * @subpackage newmail
  * @subpackage newmail
  */
  */
 
 
-// Set $allowsound to false if you don't want sound files available
+// Set $newmail_allowsound to false if you don't want sound files available
 $newmail_allowsound = true;
 $newmail_allowsound = true;
 
 
+/**
+ * Don't allow custom sounds 
+ * prefs are stored in DB and data directory is not shared between
+ * web cluster hosts.
+ */
+$newmail_uploadsounds = false;
+
 // controls insertion of embed tags
 // controls insertion of embed tags
 $newmail_mediacompat_mode=false;
 $newmail_mediacompat_mode=false;
 
 

+ 35 - 5
plugins/newmail/functions.php

@@ -6,6 +6,7 @@
  * @version $Id$
  * @version $Id$
  * @package plugins
  * @package plugins
  * @subpackage newmail
  * @subpackage newmail
+ * @todo add midi support
  */
  */
 
 
 /** @ignore */
 /** @ignore */
@@ -57,7 +58,7 @@ function newmail_optpage_register_block_function() {
  * Save newmail plugin settings
  * Save newmail plugin settings
  */
  */
 function newmail_sav_function() {
 function newmail_sav_function() {
-    global $data_dir, $username, $_FILES;
+    global $data_dir, $username, $_FILES, $newmail_uploadsounds;
 
 
     if ( sqgetGlobalVar('submit_newmail', $submit, SQ_POST) ) {
     if ( sqgetGlobalVar('submit_newmail', $submit, SQ_POST) ) {
         $media_enable = '';
         $media_enable = '';
@@ -99,7 +100,7 @@ function newmail_sav_function() {
         }
         }
 
 
         // process uploaded file
         // 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
             // set temp file and get media file name
             $newmail_tempmedia=getHashedDir($username, $data_dir) . "/$username.tempsound";
             $newmail_tempmedia=getHashedDir($username, $data_dir) . "/$username.tempsound";
             $newmail_mediafile=getHashedFile($username, $data_dir, $username . '.sound');
             $newmail_mediafile=getHashedFile($username, $data_dir, $username . '.sound');
@@ -142,6 +143,10 @@ function newmail_pref_function() {
     $newmail_recent = getPref($data_dir,$username,'newmail_recent');
     $newmail_recent = getPref($data_dir,$username,'newmail_recent');
     $newmail_enable = getPref($data_dir,$username,'newmail_enable');
     $newmail_enable = getPref($data_dir,$username,'newmail_enable');
     $newmail_media = getPref($data_dir, $username, 'newmail_media', '(none)');
     $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 = getPref($data_dir, $username, 'newmail_popup');
     $newmail_popup_width = getPref($data_dir, $username, 'newmail_popup_width',200);
     $newmail_popup_width = getPref($data_dir, $username, 'newmail_popup_width',200);
     $newmail_popup_height = getPref($data_dir, $username, 'newmail_popup_height',130);
     $newmail_popup_height = getPref($data_dir, $username, 'newmail_popup_height',130);
@@ -423,9 +428,11 @@ function newmail_media_objects($object,$types,$path,$args=array(),$extra='',$add
     if ($extra!='')
     if ($extra!='')
         $ret.=$extra . "\n";
         $ret.=$extra . "\n";
 
 
+    // close embed tags
     if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
     if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
         $ret.= newmail_media_embed_close($types[0]);
         $ret.= newmail_media_embed_close($types[0]);
 
 
+    // close w3.org nested objects
     foreach (array_reverse($types) as $type) {
     foreach (array_reverse($types) as $type) {
         $ret.= newmail_media_object_close($type);
         $ret.= newmail_media_object_close($type);
     }
     }
@@ -509,6 +516,7 @@ function newmail_media_object($object,$type,$path,$args=array(),$addsuffix=true)
  * @param array $args media object attributes
  * @param array $args media object attributes
  * @param bool $addsuffix controls addition of suffix to media object url
  * @param bool $addsuffix controls addition of suffix to media object url
  * @return string object html tags and attributes required by selected media type.
  * @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) {
 function newmail_media_object_ie($object,$type,$path,$args=array(),$addsuffix) {
     $ret_ie='';
     $ret_ie='';
@@ -591,9 +599,31 @@ function newmail_media_embed($object,$type,$path,$args=array(),$addsuffix=true)
             .' name="' . $object .'" ' . "\n"
             .' name="' . $object .'" ' . "\n"
             .' type="audio/x-wav">' . "\n";
             .' type="audio/x-wav">' . "\n";
         break;
         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:
     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_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:
     default:
         $ret_embed='';
         $ret_embed='';
     }
     }
@@ -658,11 +688,11 @@ function newmail_media_embed_close($type) {
     switch ($type) {
     switch ($type) {
     case SM_NEWMAIL_FILETYPE_SWF:
     case SM_NEWMAIL_FILETYPE_SWF:
     case SM_NEWMAIL_FILETYPE_WAV:
     case SM_NEWMAIL_FILETYPE_WAV:
-       $ret_end="</embed>\n";
-        break;
     case SM_NEWMAIL_FILETYPE_OGG:
     case SM_NEWMAIL_FILETYPE_OGG:
     case SM_NEWMAIL_FILETYPE_MP3:
     case SM_NEWMAIL_FILETYPE_MP3:
     case SM_NEWMAIL_FILETYPE_SVG:
     case SM_NEWMAIL_FILETYPE_SVG:
+       $ret_end="</embed>\n";
+        break;
     default:
     default:
         $ret_end='';
         $ret_end='';
     }
     }

+ 1 - 1
plugins/newmail/loadfile.php

@@ -28,7 +28,7 @@ $newmail_userfile_type=getPref($data_dir,$username,'newmail_userfile_type',false
 
 
 $newmail_userfile_location=getHashedFile($username, $data_dir, $username . '.sound');
 $newmail_userfile_location=getHashedFile($username, $data_dir, $username . '.sound');
 
 
-if ($newmail_userfile_type!=false && file_exists($newmail_userfile_location)) {
+if ($newmail_uploadsounds && $newmail_userfile_type!=false && file_exists($newmail_userfile_location)) {
     // open media file
     // open media file
     $newmail_userfile_handle = fopen($newmail_userfile_location,'rb');
     $newmail_userfile_handle = fopen($newmail_userfile_location,'rb');
     if ($newmail_userfile_handle) {
     if ($newmail_userfile_handle) {

+ 32 - 26
plugins/newmail/newmail_opt.php

@@ -141,13 +141,13 @@ if ($newmail_allowsound) {
     // Iterate sound files for options
     // Iterate sound files for options
     $d = dir(SM_PATH . 'plugins/newmail/sounds');
     $d = dir(SM_PATH . 'plugins/newmail/sounds');
     while($entry=$d->read()) {
     while($entry=$d->read()) {
-        $fname = get_location () . '/sounds/' . $entry;
+        // $fname = get_location () . '/sounds/' . $entry;
         if ($entry != '..' && $entry != '.' && $entry != 'CVS') {
         if ($entry != '..' && $entry != '.' && $entry != 'CVS') {
             echo '<option ';
             echo '<option ';
-            if ($fname == $newmail_media) {
+            if ($entry == $newmail_media) {
                 echo 'selected="selected" ';
                 echo 'selected="selected" ';
             }
             }
-            echo 'value="' . htmlspecialchars($fname) . '">' .
+            echo 'value="' . htmlspecialchars($entry) . '">' .
                 htmlspecialchars($entry) . "</option>\n";
                 htmlspecialchars($entry) . "</option>\n";
         }
         }
     }
     }
@@ -161,14 +161,17 @@ if ($newmail_allowsound) {
         echo 'value="mmedia_' . $newmail_mm_name . '">'
         echo 'value="mmedia_' . $newmail_mm_name . '">'
             .htmlspecialchars($newmail_mm_name) . "</option>\n";
             .htmlspecialchars($newmail_mm_name) . "</option>\n";
     }
     }
-    // display local file option
-    echo '<option ';
-    if ($newmail_media=='(userfile)') {
-        echo 'selected="selected" ';
+
+    if($newmail_uploadsounds) {
+        // display local file option
+        echo '<option ';
+        if ($newmail_media=='(userfile)') {
+            echo 'selected="selected" ';
+        }
+        echo 'value="(userfile)">'.
+            _("uploaded media file") . "</option>\n";
+        // end of local file option
     }
     }
-    echo 'value="(userfile)">'.
-        _("uploaded media file") . "</option>\n";
-    // end of local file option
 
 
     // Set media file name
     // Set media file name
     if ($newmail_media == '(none)') {
     if ($newmail_media == '(none)') {
@@ -178,7 +181,7 @@ if ($newmail_allowsound) {
     } elseif (preg_match("/^mmedia_+/",$newmail_media)) {
     } elseif (preg_match("/^mmedia_+/",$newmail_media)) {
         $media_output = preg_replace("/^mmedia_/",'',$newmail_media);
         $media_output = preg_replace("/^mmedia_/",'',$newmail_media);
     } else {
     } else {
-        $media_output = substr($newmail_media, strrpos($newmail_media, '/')+1);
+        $media_output = basename($newmail_media);
     }
     }
 
 
     echo '</select>'.
     echo '</select>'.
@@ -187,21 +190,24 @@ if ($newmail_allowsound) {
             "'width=150,height=30,scrollbars=no');" .
             "'width=150,height=30,scrollbars=no');" .
             'return false;' .
             'return false;' .
             '" /></td></tr>';
             '" /></td></tr>';
-    echo  html_tag('tr')
-        . html_tag('td',_("Upload Media File:"),'right','','style="white-space: nowrap;"')
-        . html_tag('td','<input type="file" size="40" name="media_file">')
-        . "</tr>\n";
-
-    echo  html_tag('tr')
-        . html_tag('td',_("Uploaded Media File:"),'right','','style="white-space: nowrap;"')
-        . html_tag('td',($newmail_userfile_name!='' ? htmlspecialchars($newmail_userfile_name) : _("unavailable")))
-        ."</tr>\n";
-
-    if ($newmail_userfile_name!='') {
-        echo '<tr>'
-            .'<td colspan="2" align="center">'
-            .sprintf(_("Media file %s will be removed, if you upload other media file."),basename($newmail_userfile_name))
-            .'</td></tr>';
+    if ($newmail_uploadsounds) {
+        // upload form
+        echo  html_tag('tr')
+            . html_tag('td',_("Upload Media File:"),'right','','style="white-space: nowrap;"')
+            . html_tag('td','<input type="file" size="40" name="media_file">')
+            . "</tr>\n";
+        // display currently uploaded file information
+        echo  html_tag('tr')
+            . html_tag('td',_("Uploaded Media File:"),'right','','style="white-space: nowrap;"')
+            . html_tag('td',($newmail_userfile_name!='' ? htmlspecialchars($newmail_userfile_name) : _("unavailable")))
+            ."</tr>\n";
+    
+        if ($newmail_userfile_name!='') {
+            echo '<tr>'
+                .'<td colspan="2" align="center">'
+                .sprintf(_("Media file %s will be removed, if you upload other media file."),basename($newmail_userfile_name))
+                .'</td></tr>';
+        }
     }
     }
     echo html_tag( 'tr', "\n" .
     echo html_tag( 'tr', "\n" .
                 html_tag( 'td', _("Current File:"), 'right', '', 'style="white-space: nowrap;"' ) .
                 html_tag( 'td', _("Current File:"), 'right', '', 'style="white-space: nowrap;"' ) .