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':
69 * Function tries to detect uploaded file type
71 * @param string $filename
72 * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
74 function newmail_get_mediatype($type,$filename) {
76 // fix for browser's that upload file as application/octet-stream
77 case 'application/octet-stream':
78 $ret=newmail_get_mediatype_by_ext($filename);
81 $ret=SM_NEWMAIL_FILETYPE_WAV
;
84 $ret=SM_NEWMAIL_FILETYPE_MP3
;
86 case 'application/ogg':
87 $ret=SM_NEWMAIL_FILETYPE_OGG
;
89 case 'application/x-shockwave-flash':
90 $ret=SM_NEWMAIL_FILETYPE_SWF
;
93 $ret=SM_NEWMAIL_FILETYPE_SVG
;
102 * Function provides filetype detection for browsers, that
103 * upload files with application/octet-stream file type.
104 * Ex. some version of Opera.
105 * @param string $filename
106 * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
108 function newmail_get_mediatype_by_ext($filename) {
109 if (preg_match("/\.wav$/i",$filename)) return SM_NEWMAIL_FILETYPE_WAV
;
110 if (preg_match("/\.mp3$/i",$filename)) return SM_NEWMAIL_FILETYPE_MP3
;
111 if (preg_match("/\.ogg$/i",$filename)) return SM_NEWMAIL_FILETYPE_OGG
;
112 if (preg_match("/\.swf$/i",$filename)) return SM_NEWMAIL_FILETYPE_SWF
;
113 if (preg_match("/\.svg$/i",$filename)) return SM_NEWMAIL_FILETYPE_SVG
;
118 * Creates html object tags of multimedia object
120 * Main function that creates multimedia object tags
121 * @param string $object object name
122 * @param integer $type media object type
123 * @param string $path URL to media object
124 * @param array $args media object attributes
125 * @param string $extra tags that have to buried deep inside object tags
126 * @param bool $addsuffix controls addition of suffix to media object url
127 * @return string object html tags and attributes required by selected media type.
129 function newmail_media_objects($object,$types,$path,$args=array(),$extra='',$addsuffix=true) {
130 global $newmail_mediacompat_mode;
132 // first prepare single object for IE
133 $ret = newmail_media_object_ie($object,$types[0],$path,$args,$addsuffix);
135 // W3.org nested objects
136 $ret.= "<!--[if !IE]> <-->\n"; // not for IE
138 foreach ($types as $type) {
139 $ret.= newmail_media_object($object,$type,$path,$args,$addsuffix);
142 if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
143 $ret.= newmail_media_embed($object,$types[0],$path,$args,$addsuffix);
144 // add $extra code inside objects
148 if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
149 $ret.= newmail_media_embed_close($types[0]);
151 foreach (array_reverse($types) as $type) {
152 $ret.= newmail_media_object_close($type);
154 $ret.= "<!--> <![endif]-->\n"; // end non-IE mode
156 $ret.= newmail_media_object_ie_close($types[0]);
162 * Creates object tags of multimedia object for browsers that comply to w3.org
166 * * Returned string does not contain html closing tag.
167 * * This is internal function, use newmail_media_objects() instead
168 * @link http://www.w3.org/TR/html4/struct/objects.html#edef-OBJECT W3.org specs
169 * @param string $object object name
170 * @param integer $type media object type
171 * @param string $path URL to media object
172 * @param array $args media object attributes
173 * @param bool $addsuffix controls addition of suffix to media object url
174 * @return string object html tags and attributes required by selected media type.
176 function newmail_media_object($object,$type,$path,$args=array(),$addsuffix=true) {
179 $sArgs=newmail_media_prepare_args($args);
182 case SM_NEWMAIL_FILETYPE_SWF
:
183 if ($addsuffix) $suffix='.swf';
184 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
186 .'type="application/x-shockwave-flash">' . "\n";
188 case SM_NEWMAIL_FILETYPE_WAV
:
189 if ($addsuffix) $suffix='.wav';
190 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
192 .'type="audio/x-wav">' . "\n";
194 case SM_NEWMAIL_FILETYPE_OGG
:
195 if ($addsuffix) $suffix='.ogg';
196 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
198 .'type="application/ogg">' . "\n";
200 case SM_NEWMAIL_FILETYPE_MP3
:
201 if ($addsuffix) $suffix='.mp3';
202 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
204 .'type="audio/mpeg">' . "\n";
206 case SM_NEWMAIL_FILETYPE_SVG
:
207 if ($addsuffix) $suffix='.svg';
208 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
210 .'type="image/svg+xml">' . "\n";
219 * Creates multimedia object tags for Internet Explorer (Win32)
222 * * Returned string does not contain html closing tag, because
223 * this multimedia object can include other media objects.
224 * * This is internal function, use newmail_media_objects() instead
226 * @param string $object object name
227 * @param integer $type media object type
228 * @param string $path URL to media object
229 * @param array $args media object attributes
230 * @param bool $addsuffix controls addition of suffix to media object url
231 * @return string object html tags and attributes required by selected media type.
233 function newmail_media_object_ie($object,$type,$path,$args=array(),$addsuffix) {
236 $sArgs=newmail_media_prepare_args($args);
239 case SM_NEWMAIL_FILETYPE_SWF
:
240 if ($addsuffix) $suffix='.swf';
241 $ret_ie ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
242 .'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" '
243 . $sArgs . 'id="' . $object ."\">\n"
244 .'<param name="movie" value="' . $path . $object . $suffix . "\">\n"
245 .'<param name="hidden" value="true">' . "\n";
247 case SM_NEWMAIL_FILETYPE_WAV
:
248 if ($addsuffix) $suffix='.wav';
249 $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
250 .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
251 . $sArgs . 'id="' . $object ."\" \n"
252 .'type="audio/x-wav">' ."\n"
253 .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
255 case SM_NEWMAIL_FILETYPE_MP3
:
256 if ($addsuffix) $suffix='.mp3';
257 $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
258 .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
259 . $sArgs . 'id="' . $object ."\" \n"
260 .'type="audio/mpeg">' ."\n"
261 .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
263 case SM_NEWMAIL_FILETYPE_OGG
:
264 case SM_NEWMAIL_FILETYPE_SVG
:
272 * Creates embed tags of multimedia object
275 * Apple: http://www.apple.com/quicktime/authoring/embed.html
278 * * Returned string does not contain html closing tag.
279 * * embed tags will be created by newmail_media_objects() only
280 * when $newmail_mediacompat_mode option is enabled. Option is not
281 * enabled by default in order to comply to w3.org specs.
282 * * This is internal function, use newmail_media_objects() instead
283 * @link http://www.apple.com/quicktime/authoring/embed.html Info about embed tag
284 * @param string $object object name
285 * @param integer $type media object type
286 * @param string $path URL to media object
287 * @param array $args media object attributes
288 * @param bool $addsuffix controls addition of suffix to media object url
289 * @return string embed html tags and attributes required by selected media type.
291 function newmail_media_embed($object,$type,$path,$args=array(),$addsuffix=true) {
294 $sArgs=newmail_media_prepare_args($args);
297 case SM_NEWMAIL_FILETYPE_SWF
:
298 if ($addsuffix) $suffix='.swf';
299 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
300 .'hidden="true" autostart="true" '. "\n"
302 .'name="' . $object .'" ' . "\n"
303 .'type="application/x-shockwave-flash" ' . "\n"
304 .'pluginspage="http://www.macromedia.com/go/getflashplayer">' . "\n";
306 case SM_NEWMAIL_FILETYPE_WAV
:
307 if ($addsuffix) $suffix='.wav';
308 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
309 .' hidden="true" autostart="true" '. "\n"
311 .' name="' . $object .'" ' . "\n"
312 .' type="audio/x-wav">' . "\n";
314 case SM_NEWMAIL_FILETYPE_OGG
:
315 case SM_NEWMAIL_FILETYPE_MP3
:
316 case SM_NEWMAIL_FILETYPE_SVG
:
324 * Adds closing tags for ie object
326 * * This is internal function, use newmail_media_objects() instead
327 * @param integer $type media object type
328 * @return string closing tag of media object
330 function newmail_media_object_ie_close($type) {
333 case SM_NEWMAIL_FILETYPE_SWF
:
334 case SM_NEWMAIL_FILETYPE_WAV
:
335 case SM_NEWMAIL_FILETYPE_MP3
:
336 $ret_end="</object>\n";
338 case SM_NEWMAIL_FILETYPE_OGG
:
339 case SM_NEWMAIL_FILETYPE_SVG
:
347 * Adds closing tags for object
349 * * This is internal function, use newmail_media_objects() instead
350 * @param integer $type media object type
351 * @return string closing tag of media object
353 function newmail_media_object_close($type) {
356 case SM_NEWMAIL_FILETYPE_SWF
:
357 case SM_NEWMAIL_FILETYPE_WAV
:
358 case SM_NEWMAIL_FILETYPE_OGG
:
359 case SM_NEWMAIL_FILETYPE_MP3
:
360 case SM_NEWMAIL_FILETYPE_SVG
:
361 $ret_end="</object>\n";
370 * Adds closing tags for object
372 * * This is internal function, use newmail_media_objects() instead
373 * @param integer $type media object type
374 * @return string closing tag of media object
376 function newmail_media_embed_close($type) {
379 case SM_NEWMAIL_FILETYPE_SWF
:
380 case SM_NEWMAIL_FILETYPE_WAV
:
381 $ret_end="</embed>\n";
383 case SM_NEWMAIL_FILETYPE_OGG
:
384 case SM_NEWMAIL_FILETYPE_MP3
:
385 case SM_NEWMAIL_FILETYPE_SVG
:
393 * Converts media attributes to string
395 * * attribute values are automatically sanitized by htmlspecialchars()
396 * * This is internal function, use newmail_media_objects() instead
397 * @param array $args array with object attributes
398 * @return string string with object attributes
400 function newmail_media_prepare_args($args) {
402 foreach ($args as $arg => $value) {
403 $ret_args.= $arg . '="' . htmlspecialchars($value) . '" ';
409 * Detects used media type and creates all need tags
410 * @param string $newmail_media
411 * @return string html tags with media objects
413 function newmail_create_media_tags($newmail_media) {
414 global $newmail_mmedia, $newmail_userfile_type;
416 if (preg_match("/^mmedia_+/",$newmail_media)) {
417 $ret_media = "<!-- newmail mmedia option -->\n";
419 $newmail_mmedia_short=preg_replace("/^mmedia_/",'',$newmail_media);
420 // check if media option is not removed
421 if (isset($newmail_mmedia[$newmail_mmedia_short])) {
422 $ret_media.= newmail_media_objects($newmail_mmedia_short,
423 $newmail_mmedia[$newmail_mmedia_short]['types'],
424 sqm_baseuri() . 'plugins/newmail/media/',
425 $newmail_mmedia[$newmail_mmedia_short]['args']);
427 $ret_media.= "<!-- end of newmail mmedia option -->\n";
428 } elseif ($newmail_media=='(userfile)') {
429 $ret_media = "<!-- newmail usermedia option -->\n";
430 $ret_media.= newmail_media_objects('loadfile.php',
431 array($newmail_userfile_type),
432 sqm_baseuri() . 'plugins/newmail/',
433 array('width'=>0,'height'=>0),
435 $ret_media.= "<!-- end of newmail usermedia option -->\n";
437 $ret_media = "<!-- newmail sounds from sounds/*.wav -->\n";
438 $ret_media.= newmail_media_objects(basename($newmail_media),
439 array(SM_NEWMAIL_FILETYPE_WAV
),
440 sqm_baseuri() . 'plugins/newmail/sounds/',
441 array('width'=>0,'height'=>0),
443 $ret_media.= "<!-- end of newmail sounds from sounds/*.wav -->\n";