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