3 * SquirrelMail NewMail plugin
11 /** file type defines */
12 define('SM_NEWMAIL_FILETYPE_WAV',2);
13 define('SM_NEWMAIL_FILETYPE_MP3',3);
14 define('SM_NEWMAIL_FILETYPE_OGG',4);
15 define('SM_NEWMAIL_FILETYPE_SWF',5);
16 define('SM_NEWMAIL_FILETYPE_SVG',6);
18 /** load default config */
19 if (file_exists(SM_PATH
. 'plugins/newmail/config_default.php')) {
20 include_once(SM_PATH
. 'plugins/newmail/config_default.php');
24 if (file_exists(SM_PATH
. 'config/newmail_config.php')) {
25 include_once(SM_PATH
. 'config/newmail_config.php');
26 } elseif (file_exists(SM_PATH
. 'plugins/newmail/config.php')) {
27 include_once(SM_PATH
. 'plugins/newmail/config.php');
31 * Function tries to detect if file contents match declared file type
33 * Function returns default extension for detected mime type or 'false'
35 * TODO: use $contents to check if file is in specified type
36 * @param string $contents file contents
37 * @param string $type file mime type
40 function newmail_detect_filetype($contents,$type) {
41 // convert $type to lower case
42 $type=strtolower($type);
53 case 'application/ogg':
56 case 'application/x-shockwave-flash':
70 * @param string $filename
73 function newmail_get_mediatype($type,$filename) {
75 // fix for browser's that upload file as application/octet-stream
76 case 'application/octet-stream':
77 $ret=newmail_get_mediatype_by_ext($filename);
80 $ret=SM_NEWMAIL_FILETYPE_WAV
;
83 $ret=SM_NEWMAIL_FILETYPE_MP3
;
85 case 'application/ogg':
86 $ret=SM_NEWMAIL_FILETYPE_OGG
;
88 case 'application/x-shockwave-flash':
89 $ret=SM_NEWMAIL_FILETYPE_SWF
;
92 $ret=SM_NEWMAIL_FILETYPE_SVG
;
101 * Function provides filetype detection for browsers, that
102 * upload files with application/octet-stream file type.
104 * @param string $filename
107 function newmail_get_mediatype_by_ext($filename) {
108 if (preg_match("/\.wav$/i",$filename)) return SM_NEWMAIL_FILETYPE_WAV
;
109 if (preg_match("/\.mp3$/i",$filename)) return SM_NEWMAIL_FILETYPE_MP3
;
110 if (preg_match("/\.ogg$/i",$filename)) return SM_NEWMAIL_FILETYPE_OGG
;
111 if (preg_match("/\.swf$/i",$filename)) return SM_NEWMAIL_FILETYPE_SWF
;
112 if (preg_match("/\.svg$/i",$filename)) return SM_NEWMAIL_FILETYPE_SVG
;
117 * Creates html object tags of multimedia object
119 * Main function that creates multimedia object tags
120 * @param string $object object name
121 * @param integer $type media object type
122 * @param string $path URL to media object
123 * @param array $args media object attributes
124 * @param string $extra tags that have to buried deep inside object tags
125 * @param bool $addsuffix controls addition of suffix to media object url
126 * @return string object html tags and attributes required by selected media type.
128 function newmail_media_objects($object,$types,$path,$args=array(),$extra='',$addsuffix=true) {
129 global $newmail_mediacompat_mode;
131 // first prepare single object for IE
132 $ret = newmail_media_object_ie($object,$types[0],$path,$args,$addsuffix);
134 // W3.org nested objects
135 $ret.= "<!--[if !IE]> <-->\n"; // not for IE
137 foreach ($types as $type) {
138 $ret.= newmail_media_object($object,$type,$path,$args,$addsuffix);
141 if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
142 $ret.= newmail_media_embed($object,$types[0],$path,$args,$addsuffix);
143 // add $extra code inside objects
147 if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
148 $ret.= newmail_media_embed_close($types[0]);
150 foreach (array_reverse($types) as $type) {
151 $ret.= newmail_media_object_close($type);
153 $ret.= "<!--> <![endif]-->\n"; // end non-IE mode
155 $ret.= newmail_media_object_ie_close($types[0]);
161 * Creates object tags of multimedia object for browsers that comply to w3.org
165 * * Returned string does not contain html closing tag.
166 * * This is internal function, use newmail_media_objects() instead
167 * @param string $object object name
168 * @param integer $type media object type
169 * @param string $path URL to media object
170 * @param array $args media object attributes
171 * @param bool $addsuffix controls addition of suffix to media object url
172 * @return string object html tags and attributes required by selected media type.
174 function newmail_media_object($object,$type,$path,$args=array(),$addsuffix=true) {
177 $sArgs=newmail_media_prepare_args($args);
180 case SM_NEWMAIL_FILETYPE_SWF
:
181 if ($addsuffix) $suffix='.swf';
182 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
184 .'type="application/x-shockwave-flash">' . "\n";
186 case SM_NEWMAIL_FILETYPE_WAV
:
187 if ($addsuffix) $suffix='.wav';
188 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
190 .'type="audio/x-wav">' . "\n";
192 case SM_NEWMAIL_FILETYPE_OGG
:
193 if ($addsuffix) $suffix='.ogg';
194 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
196 .'type="application/ogg">' . "\n";
198 case SM_NEWMAIL_FILETYPE_MP3
:
199 if ($addsuffix) $suffix='.mp3';
200 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
202 .'type="audio/mpeg">' . "\n";
204 case SM_NEWMAIL_FILETYPE_SVG
:
205 if ($addsuffix) $suffix='.svg';
206 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
208 .'type="image/svg+xml">' . "\n";
217 * Creates multimedia object tags for Internet Explorer (Win32)
220 * * Returned string does not contain html closing tag, because
221 * this multimedia object can include other media objects.
222 * * This is internal function, use newmail_media_objects() instead
224 * @param string $object object name
225 * @param integer $type media object type
226 * @param string $path URL to media object
227 * @param array $args media object attributes
228 * @param bool $addsuffix controls addition of suffix to media object url
229 * @return string object html tags and attributes required by selected media type.
231 function newmail_media_object_ie($object,$type,$path,$args=array(),$addsuffix) {
234 $sArgs=newmail_media_prepare_args($args);
237 case SM_NEWMAIL_FILETYPE_SWF
:
238 if ($addsuffix) $suffix='.swf';
239 $ret_ie ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
240 .'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" '
241 . $sArgs . 'id="' . $object ."\">\n"
242 .'<param name="movie" value="' . $path . $object . $suffix . "\">\n"
243 .'<param name="hidden" value="true">' . "\n";
245 case SM_NEWMAIL_FILETYPE_WAV
:
246 if ($addsuffix) $suffix='.wav';
247 $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
248 .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
249 . $sArgs . 'id="' . $object ."\" \n"
250 .'type="audio/x-wav">' ."\n"
251 .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
253 case SM_NEWMAIL_FILETYPE_MP3
:
254 if ($addsuffix) $suffix='.mp3';
255 $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
256 .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
257 . $sArgs . 'id="' . $object ."\" \n"
258 .'type="audio/mpeg">' ."\n"
259 .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
261 case SM_NEWMAIL_FILETYPE_OGG
:
262 case SM_NEWMAIL_FILETYPE_SVG
:
270 * Creates embed tags of multimedia object
273 * Apple: http://www.apple.com/quicktime/authoring/embed.html
276 * * Returned string does not contain html closing tag.
277 * * embed tags will be created by newmail_media_objects() only
278 * when $newmail_mediacompat_mode option is enabled. Option is not
279 * enabled by default in order to comply to w3.org specs.
280 * * This is internal function, use newmail_media_objects() instead
281 * @link http://www.apple.com/quicktime/authoring/embed.html Info about embed tag
282 * @param string $object object name
283 * @param integer $type media object type
284 * @param string $path URL to media object
285 * @param array $args media object attributes
286 * @param bool $addsuffix controls addition of suffix to media object url
287 * @return string embed html tags and attributes required by selected media type.
289 function newmail_media_embed($object,$type,$path,$args=array(),$addsuffix=true) {
292 $sArgs=newmail_media_prepare_args($args);
295 case SM_NEWMAIL_FILETYPE_SWF
:
296 if ($addsuffix) $suffix='.swf';
297 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
298 .'hidden="true" autostart="true" '. "\n"
300 .'name="' . $object .'" ' . "\n"
301 .'type="application/x-shockwave-flash" ' . "\n"
302 .'pluginspage="http://www.macromedia.com/go/getflashplayer">' . "\n";
304 case SM_NEWMAIL_FILETYPE_WAV
:
305 if ($addsuffix) $suffix='.wav';
306 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
307 .' hidden="true" autostart="true" '. "\n"
309 .' name="' . $object .'" ' . "\n"
310 .' type="audio/x-wav">' . "\n";
312 case SM_NEWMAIL_FILETYPE_OGG
:
313 case SM_NEWMAIL_FILETYPE_MP3
:
314 case SM_NEWMAIL_FILETYPE_SVG
:
322 * Adds closing tags for ie object
324 * * This is internal function, use newmail_media_objects() instead
325 * @param integer $type media object type
326 * @return string closing tag of media object
328 function newmail_media_object_ie_close($type) {
331 case SM_NEWMAIL_FILETYPE_SWF
:
332 case SM_NEWMAIL_FILETYPE_WAV
:
333 case SM_NEWMAIL_FILETYPE_MP3
:
334 $ret_end="</object>\n";
336 case SM_NEWMAIL_FILETYPE_OGG
:
337 case SM_NEWMAIL_FILETYPE_SVG
:
345 * Adds closing tags for object
347 * * This is internal function, use newmail_media_objects() instead
348 * @param integer $type media object type
349 * @return string closing tag of media object
351 function newmail_media_object_close($type) {
354 case SM_NEWMAIL_FILETYPE_SWF
:
355 case SM_NEWMAIL_FILETYPE_WAV
:
356 case SM_NEWMAIL_FILETYPE_OGG
:
357 case SM_NEWMAIL_FILETYPE_MP3
:
358 case SM_NEWMAIL_FILETYPE_SVG
:
359 $ret_end="</object>\n";
368 * Adds closing tags for object
370 * * This is internal function, use newmail_media_objects() instead
371 * @param integer $type media object type
372 * @return string closing tag of media object
374 function newmail_media_embed_close($type) {
377 case SM_NEWMAIL_FILETYPE_SWF
:
378 case SM_NEWMAIL_FILETYPE_WAV
:
379 $ret_end="</embed>\n";
381 case SM_NEWMAIL_FILETYPE_OGG
:
382 case SM_NEWMAIL_FILETYPE_MP3
:
383 case SM_NEWMAIL_FILETYPE_SVG
:
391 * Converts media attributes to string
393 * * attribute values are automatically sanitized by htmlspecialchars()
394 * * This is internal function, use newmail_media_objects() instead
395 * @param array $args array with object attributes
396 * @return string string with object attributes
398 function newmail_media_prepare_args($args) {
400 foreach ($args as $arg => $value) {
401 $ret_args.= $arg . '="' . htmlspecialchars($value) . '" ';
407 * Detects used media type and creates all need tags
408 * @param string $newmail_media
409 * @return string html tags with media objects
411 function newmail_create_media_tags($newmail_media) {
412 global $newmail_mmedia, $newmail_userfile_type;
414 if (preg_match("/^mmedia_+/",$newmail_media)) {
415 $ret_media = "<!-- newmail mmedia option -->\n";
417 $newmail_mmedia_short=preg_replace("/^mmedia_/",'',$newmail_media);
418 // check if media option is not removed
419 if (isset($newmail_mmedia[$newmail_mmedia_short])) {
420 $ret_media.= newmail_media_objects($newmail_mmedia_short,
421 $newmail_mmedia[$newmail_mmedia_short]['types'],
422 sqm_baseuri() . 'plugins/newmail/media/',
423 $newmail_mmedia[$newmail_mmedia_short]['args']);
425 $ret_media.= "<!-- end of newmail mmedia option -->\n";
426 } elseif ($newmail_media=='(userfile)') {
427 $ret_media = "<!-- newmail usermedia option -->\n";
428 $ret_media.= newmail_media_objects('loadfile.php',
429 array($newmail_userfile_type),
430 sqm_baseuri() . 'plugins/newmail/',
431 array('width'=>0,'height'=>0),
433 $ret_media.= "<!-- end of newmail usermedia option -->\n";
435 $ret_media = "<!-- newmail sounds from sounds/*.wav -->\n";
436 $ret_media.= newmail_media_objects(basename($newmail_media),
437 array(SM_NEWMAIL_FILETYPE_WAV
),
438 sqm_baseuri() . 'plugins/newmail/sounds/',
439 array('width'=>0,'height'=>0),
441 $ret_media.= "<!-- end of newmail sounds from sounds/*.wav -->\n";