adding option to choose monitored folders. Monitoring according to
[squirrelmail.git] / plugins / newmail / functions.php
1 <?php
2
3 /**
4 * SquirrelMail NewMail plugin
5 *
6 * Functions
7 *
8 * @copyright &copy; 2001-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package plugins
12 * @subpackage newmail
13 * @todo add midi support
14 */
15
16 /** @ignore */
17 if (! defined('SM_PATH')) define('SM_PATH','../../');
18
19 /**
20 * SMPREF_UNSEEN_* constants
21 */
22 include_once(SM_PATH . 'functions/constants.php');
23
24 /** file type defines */
25 define('SM_NEWMAIL_FILETYPE_WAV',2);
26 define('SM_NEWMAIL_FILETYPE_MP3',3);
27 define('SM_NEWMAIL_FILETYPE_OGG',4);
28 define('SM_NEWMAIL_FILETYPE_SWF',5);
29 define('SM_NEWMAIL_FILETYPE_SVG',6);
30
31 /** load default config */
32 if (file_exists(SM_PATH . 'plugins/newmail/config_default.php')) {
33 include_once(SM_PATH . 'plugins/newmail/config_default.php');
34 }
35
36 /** load config */
37 if (file_exists(SM_PATH . 'config/newmail_config.php')) {
38 include_once(SM_PATH . 'config/newmail_config.php');
39 } elseif (file_exists(SM_PATH . 'plugins/newmail/config.php')) {
40 include_once(SM_PATH . 'plugins/newmail/config.php');
41 }
42
43 // ----- hooked functions -----
44
45 /**
46 * Register newmail option block
47 */
48 function newmail_optpage_register_block_function() {
49 // Gets added to the user's OPTIONS page.
50 global $optpage_blocks;
51
52 /* Register Squirrelspell with the $optionpages array. */
53 $optpage_blocks[] = array(
54 'name' => _("NewMail Options"),
55 'url' => sqm_baseuri() . 'plugins/newmail/newmail_opt.php',
56 'desc' => _("This configures settings for playing sounds and/or showing popup windows when new mail arrives."),
57 'js' => TRUE
58 );
59 }
60
61 /**
62 * Save newmail plugin settings
63 */
64 function newmail_sav_function() {
65 global $data_dir, $username, $_FILES, $newmail_uploadsounds;
66
67 if ( sqgetGlobalVar('submit_newmail', $submit, SQ_POST) ) {
68 $media_enable = '';
69 $media_popup = '';
70 $media_recent = '';
71 $media_changetitle = '';
72 $media_sel = '';
73 $popup_width = '';
74 $popup_height = '';
75
76 sqgetGlobalVar('media_enable', $media_enable, SQ_POST);
77 sqgetGlobalVar('media_popup', $media_popup, SQ_POST);
78 sqgetGlobalVar('media_recent', $media_recent, SQ_POST);
79 sqgetGlobalVar('media_changetitle', $media_changetitle, SQ_POST);
80 sqgetGlobalVar('popup_width', $popup_width, SQ_POST);
81 sqgetGlobalVar('popup_height', $popup_height, SQ_POST);
82
83 // sanitize height and width
84 $popup_width = (int) $popup_width;
85 if ($popup_width<=0) $popup_width=200;
86 $popup_height = (int) $popup_height;
87 if ($popup_height<=0) $popup_height=130;
88
89 setPref($data_dir,$username,'newmail_enable',$media_enable);
90 setPref($data_dir,$username,'newmail_popup', $media_popup);
91 setPref($data_dir,$username,'newmail_recent',$media_recent);
92 setPref($data_dir,$username,'newmail_changetitle',$media_changetitle);
93 setPref($data_dir,$username,'newmail_popup_width',$popup_width);
94 setPref($data_dir,$username,'newmail_popup_height',$popup_height);
95
96 if (sqgetGlobalVar('newmail_unseen_notify', $newmail_unseen_notify, SQ_POST)) {
97 $newmail_unseen_notify = (int) $newmail_unseen_notify;
98 setPref($data_dir,$username,'newmail_unseen_notify',$newmail_unseen_notify);
99 }
100
101 if( sqgetGlobalVar('media_sel', $media_sel, SQ_POST) &&
102 $media_sel == '(none)' ) {
103 removePref($data_dir,$username,'newmail_media');
104 } else {
105 setPref($data_dir,$username,'newmail_media',$media_sel);
106 }
107
108 // process uploaded file
109 if ($newmail_uploadsounds && isset($_FILES['media_file']['tmp_name']) && $_FILES['media_file']['tmp_name']!='') {
110 // set temp file and get media file name
111 $newmail_tempmedia=getHashedDir($username, $data_dir) . "/$username.tempsound";
112 $newmail_mediafile=getHashedFile($username, $data_dir, $username . '.sound');
113 if (move_uploaded_file($_FILES['media_file']['tmp_name'], $newmail_tempmedia)) {
114 // new media file is in $newmail_tempmedia
115 if (file_exists($newmail_mediafile)) unlink($newmail_mediafile);
116 if (! rename($newmail_tempmedia,$newmail_mediafile)) {
117 // remove (userfile), if file rename fails
118 removePref($data_dir,$username,'newmail_media');
119 } else {
120 // store media type
121 if (isset($_FILES['media_file']['type']) && isset($_FILES['media_file']['name'])) {
122 setPref($data_dir,$username,'newmail_userfile_type',
123 newmail_get_mediatype($_FILES['media_file']['type'],$_FILES['media_file']['name']));
124 } else {
125 removePref($data_dir,$username,'newmail_userfile_type');
126 }
127 // store file name
128 if (isset($_FILES['media_file']['name'])) {
129 setPref($data_dir,$username,'newmail_userfile_name',basename($_FILES['media_file']['name']));
130 } else {
131 setPref($data_dir,$username,'newmail_userfile_name','mediafile.unknown');
132 }
133 }
134 }
135 }
136 }
137 }
138
139 /**
140 * Load newmail plugin settings
141 */
142 function newmail_pref_function() {
143 global $username,$data_dir;
144 global $newmail_media,$newmail_media_enable,$newmail_popup;
145 global $newmail_recent, $newmail_changetitle;
146 global $newmail_userfile_type, $newmail_userfile_name;
147 global $newmail_popup_width, $newmail_popup_height;
148 global $newmail_unseen_notify;
149
150 $newmail_recent = getPref($data_dir,$username,'newmail_recent');
151 $newmail_media_enable = getPref($data_dir,$username,'newmail_enable');
152 $newmail_media = getPref($data_dir, $username, 'newmail_media', '(none)');
153 // remove full location from setting (since SM 1.5.1 plugin uses only filename).
154 if ($newmail_media!='(none)')
155 $newmail_media = basename($newmail_media);
156
157 $newmail_popup = getPref($data_dir, $username, 'newmail_popup');
158 $newmail_popup_width = getPref($data_dir, $username, 'newmail_popup_width',200);
159 $newmail_popup_height = getPref($data_dir, $username, 'newmail_popup_height',130);
160 $newmail_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
161
162 $newmail_userfile_type = getPref($data_dir, $username, 'newmail_userfile_type');
163 $newmail_userfile_name = getPref($data_dir,$username,'newmail_userfile_name','');
164
165 $newmail_unseen_notify = getPref($data_dir,$username,'newmail_unseen_notify',0);
166 }
167
168 /**
169 * Set loadinfo data
170 *
171 * Used by option page when saving settings.
172 */
173 function newmail_set_loadinfo_function() {
174 global $optpage, $optpage_name;
175 if ($optpage=='newmail') {
176 $optpage_name=_("NewMail Options");
177 }
178 }
179
180
181 /* Receive the status of the folder and do something with it */
182 function newmail_folder_status($statusarr) {
183 global $newmail_media_enable,$newmail_popup,$newmail_changetitle,$trash_folder,
184 $sent_folder,$totalNewArr, $newmail_unseen_notify, $unseen_notify, $newmail_recent;
185
186 /* if $newmail_unseen_notify is set to zero, plugin follows $unseen_notify */
187 if ($newmail_unseen_notify == 0)
188 $newmail_unseen_notify = $unseen_notify;
189
190 $mailbox=$statusarr['MAILBOX'];
191
192 if (($newmail_media_enable == 'on' ||
193 $newmail_popup == 'on' ||
194 $newmail_changetitle == 'on') &&
195 /**
196 * make sure that $newmail_unseen_notify is set to supported value,
197 * currently (1.5.2cvs) SMPREF_UNSEEN_NORMAL has highest integer value
198 * in SMPREF_UNSEEN constants
199 */
200 ($newmail_unseen_notify > SMPREF_UNSEEN_NONE && $newmail_unseen_notify <= SMPREF_UNSEEN_NORMAL)) {
201
202 // Skip folders for Sent and Trash
203 // TODO: make this optional
204 if ($statusarr['MAILBOX'] == $sent_folder || $statusarr['MAILBOX'] == $trash_folder) {
205 return 0;
206 }
207
208 if ((($mailbox == 'INBOX') && ($newmail_unseen_notify == SMPREF_UNSEEN_INBOX)) ||
209 ($newmail_unseen_notify == SMPREF_UNSEEN_SPECIAL && isSpecialMailbox($mailbox)) ||
210 ($newmail_unseen_notify == SMPREF_UNSEEN_NORMAL && ! isSpecialMailbox($mailbox)) ||
211 ($newmail_unseen_notify == SMPREF_UNSEEN_ALL)) {
212 if (($newmail_recent == 'on') && (!empty($statusarr['RECENT']))) {
213 $totalNewArr[$mailbox] = $statusarr['RECENT'];
214 } elseif ($newmail_recent != 'on' && !empty($statusarr['UNSEEN'])) {
215 $totalNewArr[$mailbox] = $statusarr['UNSEEN'];
216 }
217 }
218 }
219 }
220
221 /**
222 * Insert needed data in left_main
223 */
224 function newmail_plugin_function() {
225 global $username, $newmail_media, $newmail_media_enable, $newmail_popup,
226 $newmail_recent, $newmail_changetitle, $imapConnection, $PHP_SELF;
227 global $newmail_mmedia, $newmail_allowsound;
228 global $newmail_userfile_type;
229 global $newmail_popup_width, $newmail_popup_height;
230 global $totalNewArr;
231
232 if ($newmail_media_enable == 'on' ||
233 $newmail_popup == 'on' ||
234 $newmail_changetitle) {
235
236 if (!empty($totalNewArr)) { $totalNew=array_sum($totalNewArr); }
237 else { $totalNew=0; }
238
239 // If we found unseen messages, then we
240 // will play the sound as follows:
241
242 if ($newmail_changetitle) {
243 echo "<script type=\"text/javascript\">\n" .
244 "function ChangeTitleLoad() {\n";
245 echo 'window.parent.document.title = "' .
246 sprintf(ngettext("%s New Message","%s New Messages",$totalNew), $totalNew) .
247 "\";\n";
248 echo "if (BeforeChangeTitle != null)\n".
249 "BeforeChangeTitle();\n".
250 "}\n".
251 "BeforeChangeTitle = window.onload;\n".
252 "window.onload = ChangeTitleLoad;\n".
253 "</script>\n";
254 }
255
256 // create media output if there are new email messages
257 if ($newmail_allowsound && $totalNew > 0
258 && $newmail_media_enable == 'on'
259 && $newmail_media != '' ) {
260 echo newmail_create_media_tags($newmail_media);
261 }
262
263 if ($totalNew > 0 && $newmail_popup == 'on') {
264 // Idea by: Nic Wolfe (Nic@TimelapseProductions.com)
265 // Web URL: http://fineline.xs.mw
266 // More code from Tyler Akins
267 echo "<script type=\"text/javascript\">\n".
268 "<!--\n".
269 "function PopupScriptLoad() {\n".
270 'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew.
271 '", "SMPopup",'.
272 "\"width=$newmail_popup_width,height=$newmail_popup_height,scrollbars=no\");\n".
273 "if (BeforePopupScript != null)\n".
274 "BeforePopupScript();\n".
275 "}\n".
276 "BeforePopupScript = window.onload;\n".
277 "window.onload = PopupScriptLoad;\n".
278 "// End -->\n".
279 "</script>\n";
280 }
281 }
282 }
283
284 // ----- end of hooked functions -----
285
286
287
288 /**
289 * Function tries to detect if file contents match declared file type
290 *
291 * Function returns default extension for detected mime type or 'false'
292 *
293 * TODO: use $contents to check if file is in specified type
294 * @param string $contents file contents
295 * @param string $type file mime type
296 * @return string
297 */
298 function newmail_detect_filetype($contents,$type) {
299 // convert $type to lower case
300 $type=strtolower($type);
301
302 $ret=false;
303
304 switch ($type) {
305 case 'audio/x-wav':
306 $ret='wav';
307 break;
308 case 'audio/mpeg':
309 $ret='mp3';
310 break;
311 case 'application/ogg':
312 $ret='ogg';
313 break;
314 case 'application/x-shockwave-flash':
315 $ret='swf';
316 break;
317 case 'image/svg+xml':
318 $ret='svg';
319 break;
320 default:
321 $ret=false;
322 }
323 return $ret;
324 }
325
326 /**
327 * Function tries to detect uploaded file type
328 * @param string $type
329 * @param string $filename
330 * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
331 */
332 function newmail_get_mediatype($type,$filename) {
333 switch ($type) {
334 // fix for browser's that upload file as application/octet-stream
335 case 'application/octet-stream':
336 $ret=newmail_get_mediatype_by_ext($filename);
337 break;
338 case 'audio/x-wav':
339 $ret=SM_NEWMAIL_FILETYPE_WAV;
340 break;
341 case 'audio/mpeg':
342 $ret=SM_NEWMAIL_FILETYPE_MP3;
343 break;
344 case 'application/ogg':
345 $ret=SM_NEWMAIL_FILETYPE_OGG;
346 break;
347 case 'application/x-shockwave-flash':
348 $ret=SM_NEWMAIL_FILETYPE_SWF;
349 break;
350 case 'image/svg+xml':
351 $ret=SM_NEWMAIL_FILETYPE_SVG;
352 break;
353 default:
354 $ret=false;
355 }
356 return $ret;
357 }
358
359 /**
360 * Function provides filetype detection for browsers, that
361 * upload files with application/octet-stream file type.
362 * Ex. some version of Opera.
363 * @param string $filename
364 * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
365 */
366 function newmail_get_mediatype_by_ext($filename) {
367 if (preg_match("/\.wav$/i",$filename)) return SM_NEWMAIL_FILETYPE_WAV;
368 if (preg_match("/\.mp3$/i",$filename)) return SM_NEWMAIL_FILETYPE_MP3;
369 if (preg_match("/\.ogg$/i",$filename)) return SM_NEWMAIL_FILETYPE_OGG;
370 if (preg_match("/\.swf$/i",$filename)) return SM_NEWMAIL_FILETYPE_SWF;
371 if (preg_match("/\.svg$/i",$filename)) return SM_NEWMAIL_FILETYPE_SVG;
372 return false;
373 }
374
375 /**
376 * Creates html object tags of multimedia object
377 *
378 * Main function that creates multimedia object tags
379 * @param string $object object name
380 * @param integer $type media object type
381 * @param string $path URL to media object
382 * @param array $args media object attributes
383 * @param string $extra tags that have to buried deep inside object tags
384 * @param bool $addsuffix controls addition of suffix to media object url
385 * @return string object html tags and attributes required by selected media type.
386 */
387 function newmail_media_objects($object,$types,$path,$args=array(),$extra='',$addsuffix=true) {
388 global $newmail_mediacompat_mode;
389
390 // first prepare single object for IE
391 $ret = newmail_media_object_ie($object,$types[0],$path,$args,$addsuffix);
392
393 // W3.org nested objects
394 $ret.= "<!--[if !IE]> <-->\n"; // not for IE
395
396 foreach ($types as $type) {
397 $ret.= newmail_media_object($object,$type,$path,$args,$addsuffix);
398 }
399
400 if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
401 $ret.= newmail_media_embed($object,$types[0],$path,$args,$addsuffix);
402 // add $extra code inside objects
403 if ($extra!='')
404 $ret.=$extra . "\n";
405
406 // close embed tags
407 if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
408 $ret.= newmail_media_embed_close($types[0]);
409
410 // close w3.org nested objects
411 foreach (array_reverse($types) as $type) {
412 $ret.= newmail_media_object_close($type);
413 }
414 $ret.= "<!--> <![endif]-->\n"; // end non-IE mode
415 // close IE object
416 $ret.= newmail_media_object_ie_close($types[0]);
417
418 return $ret;
419 }
420
421 /**
422 * Creates object tags of multimedia object for browsers that comply to w3.org
423 * specifications.
424 *
425 * Warnings:
426 * <ul>
427 * <li>Returned string does not contain html closing tag.
428 * <li>This is internal function, use newmail_media_objects() instead
429 * </ul>
430 * @link http://www.w3.org/TR/html4/struct/objects.html#edef-OBJECT W3.org specs
431 * @param string $object object name
432 * @param integer $type media object type
433 * @param string $path URL to media object
434 * @param array $args media object attributes
435 * @param bool $addsuffix controls addition of suffix to media object url
436 * @return string object html tags and attributes required by selected media type.
437 */
438 function newmail_media_object($object,$type,$path,$args=array(),$addsuffix=true) {
439 $ret_w3='';
440 $suffix='';
441 $sArgs=newmail_media_prepare_args($args);
442
443 switch ($type) {
444 case SM_NEWMAIL_FILETYPE_SWF:
445 if ($addsuffix) $suffix='.swf';
446 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
447 .$sArgs
448 .'type="application/x-shockwave-flash">' . "\n";
449 break;
450 case SM_NEWMAIL_FILETYPE_WAV:
451 if ($addsuffix) $suffix='.wav';
452 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
453 .$sArgs
454 .'type="audio/x-wav">' . "\n";
455 break;
456 case SM_NEWMAIL_FILETYPE_OGG:
457 if ($addsuffix) $suffix='.ogg';
458 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
459 .$sArgs
460 .'type="application/ogg">' . "\n";
461 break;
462 case SM_NEWMAIL_FILETYPE_MP3:
463 if ($addsuffix) $suffix='.mp3';
464 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
465 .$sArgs
466 .'type="audio/mpeg">' . "\n";
467 break;
468 case SM_NEWMAIL_FILETYPE_SVG:
469 if ($addsuffix) $suffix='.svg';
470 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
471 .$sArgs
472 .'type="image/svg+xml">' . "\n";
473 break;
474 default:
475 $ret_w3='';
476 }
477 return $ret_w3;
478 }
479
480 /**
481 * Creates multimedia object tags for Internet Explorer (Win32)
482 *
483 * Warning:
484 * * Returned string does not contain html closing tag, because
485 * this multimedia object can include other media objects.
486 * * This is internal function, use newmail_media_objects() instead
487 *
488 * @param string $object object name
489 * @param integer $type media object type
490 * @param string $path URL to media object
491 * @param array $args media object attributes
492 * @param bool $addsuffix controls addition of suffix to media object url
493 * @return string object html tags and attributes required by selected media type.
494 * @todo add ogg and svg support
495 */
496 function newmail_media_object_ie($object,$type,$path,$args=array(),$addsuffix) {
497 $ret_ie='';
498 $suffix='';
499 $sArgs=newmail_media_prepare_args($args);
500
501 switch ($type) {
502 case SM_NEWMAIL_FILETYPE_SWF:
503 if ($addsuffix) $suffix='.swf';
504 $ret_ie ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
505 .'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" '
506 . $sArgs . 'id="' . $object ."\">\n"
507 .'<param name="movie" value="' . $path . $object . $suffix . "\">\n"
508 .'<param name="hidden" value="true">' . "\n";
509 break;
510 case SM_NEWMAIL_FILETYPE_WAV:
511 if ($addsuffix) $suffix='.wav';
512 $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
513 .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
514 . $sArgs . 'id="' . $object ."\" \n"
515 .'type="audio/x-wav">' ."\n"
516 .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
517 break;
518 case SM_NEWMAIL_FILETYPE_MP3:
519 if ($addsuffix) $suffix='.mp3';
520 $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
521 .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
522 . $sArgs . 'id="' . $object ."\" \n"
523 .'type="audio/mpeg">' ."\n"
524 .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
525 break;
526 case SM_NEWMAIL_FILETYPE_OGG:
527 case SM_NEWMAIL_FILETYPE_SVG:
528 default:
529 $ret_ie='';
530 }
531 return $ret_ie;
532 }
533
534 /**
535 * Creates embed tags of multimedia object
536 *
537 * docs about embed
538 * Apple: http://www.apple.com/quicktime/authoring/embed.html
539 *
540 * Warnings:
541 * * Returned string does not contain html closing tag.
542 * * embed tags will be created by newmail_media_objects() only
543 * when $newmail_mediacompat_mode option is enabled. Option is not
544 * enabled by default in order to comply to w3.org specs.
545 * * This is internal function, use newmail_media_objects() instead
546 * @link http://www.apple.com/quicktime/authoring/embed.html Info about embed tag
547 * @param string $object object name
548 * @param integer $type media object type
549 * @param string $path URL to media object
550 * @param array $args media object attributes
551 * @param bool $addsuffix controls addition of suffix to media object url
552 * @return string embed html tags and attributes required by selected media type.
553 */
554 function newmail_media_embed($object,$type,$path,$args=array(),$addsuffix=true) {
555 $ret_embed='';
556 $suffix='';
557 $sArgs=newmail_media_prepare_args($args);
558
559 switch ($type) {
560 case SM_NEWMAIL_FILETYPE_SWF:
561 if ($addsuffix) $suffix='.swf';
562 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
563 .'hidden="true" autostart="true" '. "\n"
564 .$sArgs . "\n"
565 .'name="' . $object .'" ' . "\n"
566 .'type="application/x-shockwave-flash" ' . "\n"
567 .'pluginspage="http://www.macromedia.com/go/getflashplayer">' . "\n";
568 break;
569 case SM_NEWMAIL_FILETYPE_WAV:
570 if ($addsuffix) $suffix='.wav';
571 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
572 .' hidden="true" autostart="true" '. "\n"
573 .' ' .$sArgs . "\n"
574 .' name="' . $object .'" ' . "\n"
575 .' type="audio/x-wav">' . "\n";
576 break;
577 case SM_NEWMAIL_FILETYPE_SVG:
578 if ($addsuffix) $suffix='.svg';
579 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
580 .'hidden="true" autostart="true" '. "\n"
581 .$sArgs . "\n"
582 .'name="' . $object .'" ' . "\n"
583 .'type="image/svg-xml" ' . "\n"
584 .'pluginspage="http://www.adobe.com/svg/viewer/install/">' . "\n";
585 break;
586 case SM_NEWMAIL_FILETYPE_OGG:
587 if ($addsuffix) $suffix='.ogg';
588 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
589 .' hidden="true" autostart="true" '. "\n"
590 .' ' .$sArgs . "\n"
591 .' name="' . $object .'" ' . "\n"
592 .' type="application/ogg">' . "\n";
593 break;
594 case SM_NEWMAIL_FILETYPE_MP3:
595 if ($addsuffix) $suffix='.mp3';
596 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
597 .' hidden="true" autostart="true" '. "\n"
598 .' ' .$sArgs . "\n"
599 .' name="' . $object .'" ' . "\n"
600 .' type="audio/mpeg">' . "\n";
601 break;
602 default:
603 $ret_embed='';
604 }
605 return $ret_embed;
606 }
607
608 /**
609 * Adds closing tags for ie object
610 * Warning:
611 * * This is internal function, use newmail_media_objects() instead
612 * @param integer $type media object type
613 * @return string closing tag of media object
614 */
615 function newmail_media_object_ie_close($type) {
616 $ret_end='';
617 switch ($type) {
618 case SM_NEWMAIL_FILETYPE_SWF:
619 case SM_NEWMAIL_FILETYPE_WAV:
620 case SM_NEWMAIL_FILETYPE_MP3:
621 $ret_end="</object>\n";
622 break;
623 case SM_NEWMAIL_FILETYPE_OGG:
624 case SM_NEWMAIL_FILETYPE_SVG:
625 default:
626 $ret_end='';
627 }
628 return $ret_end;
629 }
630
631 /**
632 * Adds closing tags for object
633 * Warning:
634 * * This is internal function, use newmail_media_objects() instead
635 * @param integer $type media object type
636 * @return string closing tag of media object
637 */
638 function newmail_media_object_close($type) {
639 $ret_end='';
640 switch ($type) {
641 case SM_NEWMAIL_FILETYPE_SWF:
642 case SM_NEWMAIL_FILETYPE_WAV:
643 case SM_NEWMAIL_FILETYPE_OGG:
644 case SM_NEWMAIL_FILETYPE_MP3:
645 case SM_NEWMAIL_FILETYPE_SVG:
646 $ret_end="</object>\n";
647 break;
648 default:
649 $ret_end='';
650 }
651 return $ret_end;
652 }
653
654 /**
655 * Adds closing tags for object
656 * Warning:
657 * * This is internal function, use newmail_media_objects() instead
658 * @param integer $type media object type
659 * @return string closing tag of media object
660 */
661 function newmail_media_embed_close($type) {
662 $ret_end='';
663 switch ($type) {
664 case SM_NEWMAIL_FILETYPE_SWF:
665 case SM_NEWMAIL_FILETYPE_WAV:
666 case SM_NEWMAIL_FILETYPE_OGG:
667 case SM_NEWMAIL_FILETYPE_MP3:
668 case SM_NEWMAIL_FILETYPE_SVG:
669 $ret_end="</embed>\n";
670 break;
671 default:
672 $ret_end='';
673 }
674 return $ret_end;
675 }
676
677 /**
678 * Converts media attributes to string
679 * Warning:
680 * * attribute values are automatically sanitized by htmlspecialchars()
681 * * This is internal function, use newmail_media_objects() instead
682 * @param array $args array with object attributes
683 * @return string string with object attributes
684 */
685 function newmail_media_prepare_args($args) {
686 $ret_args='';
687 foreach ($args as $arg => $value) {
688 $ret_args.= $arg . '="' . htmlspecialchars($value) . '" ';
689 }
690 return $ret_args;
691 }
692
693 /**
694 * Detects used media type and creates all need tags
695 * @param string $newmail_media
696 * @return string html tags with media objects
697 */
698 function newmail_create_media_tags($newmail_media) {
699 global $newmail_mmedia, $newmail_userfile_type;
700
701 if (preg_match("/^mmedia_+/",$newmail_media)) {
702 $ret_media = "<!-- newmail mmedia option -->\n";
703 // remove mmedia key
704 $newmail_mmedia_short=preg_replace("/^mmedia_/",'',$newmail_media);
705 // check if media option is not removed
706 if (isset($newmail_mmedia[$newmail_mmedia_short])) {
707 $ret_media.= newmail_media_objects($newmail_mmedia_short,
708 $newmail_mmedia[$newmail_mmedia_short]['types'],
709 sqm_baseuri() . 'plugins/newmail/media/',
710 $newmail_mmedia[$newmail_mmedia_short]['args']);
711 }
712 $ret_media.= "<!-- end of newmail mmedia option -->\n";
713 } elseif ($newmail_media=='(userfile)') {
714 $ret_media = "<!-- newmail usermedia option -->\n";
715 $ret_media.= newmail_media_objects('loadfile.php',
716 array($newmail_userfile_type),
717 sqm_baseuri() . 'plugins/newmail/',
718 array('width'=>0,'height'=>0),
719 '',false);
720 $ret_media.= "<!-- end of newmail usermedia option -->\n";
721 } else {
722 $ret_media = "<!-- newmail sounds from sounds/*.wav -->\n";
723 $ret_media.= newmail_media_objects(basename($newmail_media),
724 array(SM_NEWMAIL_FILETYPE_WAV),
725 sqm_baseuri() . 'plugins/newmail/sounds/',
726 array('width'=>0,'height'=>0),
727 '',false);
728 $ret_media.= "<!-- end of newmail sounds from sounds/*.wav -->\n";
729 }
730 return $ret_media;
731 }
732 ?>