Patches from Michael Long
[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 * sqm_baseuri() function for setups that don't load it by default
21 */
22 include_once(SM_PATH . 'functions/display_messages.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('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 ($newmail_uploadsounds && 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_media_enable,$newmail_popup;
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_media_enable = getPref($data_dir,$username,'newmail_enable');
146 $newmail_media = getPref($data_dir, $username, 'newmail_media', '(none)');
147 // remove full location from setting (since SM 1.5.1 plugin uses only filename).
148 if ($newmail_media!='(none)')
149 $newmail_media = basename($newmail_media);
150
151 $newmail_popup = getPref($data_dir, $username, 'newmail_popup');
152 $newmail_popup_width = getPref($data_dir, $username, 'newmail_popup_width',200);
153 $newmail_popup_height = getPref($data_dir, $username, 'newmail_popup_height',130);
154 $newmail_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
155
156 $newmail_userfile_type = getPref($data_dir, $username, 'newmail_userfile_type');
157 $newmail_userfile_name = getPref($data_dir,$username,'newmail_userfile_name','');
158 }
159
160 /**
161 * Set loadinfo data
162 *
163 * Used by option page when saving settings.
164 */
165 function newmail_set_loadinfo_function() {
166 global $optpage, $optpage_name;
167 if ($optpage=='newmail') {
168 $optpage_name=_("NewMail Options");
169 }
170 }
171
172
173 /* Receive the status of the folder and do something with it */
174 function newmail_folder_status($statusarr) {
175 global $newmail_media_enable,$newmail_popup,$newmail_changetitle,$trash_folder,
176 $send_folder,$totalNewArr,$unseen_notify, $newmail_recent;
177
178 //echo "GOT HOOK<br><pre>";
179 //var_dump($statusarr);
180 //echo "</pre><br>\n";
181
182 $mailbox=$statusarr['MAILBOX'];
183 if ($newmail_media_enable == 'on' ||
184 $newmail_popup == 'on' ||
185 $newmail_changetitle == 'on') {
186
187 // Skip folders for Sent and Trash
188 if ($statusarr['MAILBOX'] == $send_folder || $statusarr['MAILBOX'] == $trash_folder) {
189 return 0;
190 }
191
192 if ((($mailbox == 'INBOX') && ($unseen_notify == 2)) || ($unseen_notify == 3)) {
193 if (($newmail_recent == 'on') && (!empty($statusarr['RECENT']))) {
194 $totalNewArr[$mailbox] = $statusarr['RECENT'];
195 } elseif ($newmail_recent != 'on' && !empty($statusarr['UNSEEN'])) {
196 $totalNewArr[$mailbox] = $statusarr['UNSEEN'];
197 }
198 }
199 }
200 }
201
202 /**
203 * Insert needed data in left_main
204 */
205 function newmail_plugin_function() {
206 global $username, $newmail_media, $newmail_media_enable, $newmail_popup,
207 $newmail_recent, $newmail_changetitle, $imapConnection, $PHP_SELF;
208 global $newmail_mmedia, $newmail_allowsound;
209 global $newmail_userfile_type;
210 global $newmail_popup_width, $newmail_popup_height;
211 global $totalNewArr;
212
213 if ($newmail_media_enable == 'on' ||
214 $newmail_popup == 'on' ||
215 $newmail_changetitle) {
216
217 if (!empty($totalNewArr)) { $totalNew=array_sum($totalNewArr); }
218 else { $totalNew=0; }
219
220 // If we found unseen messages, then we
221 // will play the sound as follows:
222
223 if ($newmail_changetitle) {
224 echo "<script type=\"text/javascript\">\n" .
225 "function ChangeTitleLoad() {\n";
226 echo 'window.parent.document.title = "' .
227 sprintf(ngettext("%s New Message","%s New Messages",$totalNew), $totalNew) .
228 "\";\n";
229 echo "if (BeforeChangeTitle != null)\n".
230 "BeforeChangeTitle();\n".
231 "}\n".
232 "BeforeChangeTitle = window.onload;\n".
233 "window.onload = ChangeTitleLoad;\n".
234 "</script>\n";
235 }
236
237 // create media output if there are new email messages
238 if ($newmail_allowsound && $totalNew > 0
239 && $newmail_media_enable == 'on'
240 && $newmail_media != '' ) {
241 echo newmail_create_media_tags($newmail_media);
242 }
243
244 if ($totalNew > 0 && $newmail_popup == 'on') {
245 // Idea by: Nic Wolfe (Nic@TimelapseProductions.com)
246 // Web URL: http://fineline.xs.mw
247 // More code from Tyler Akins
248 echo "<script type=\"text/javascript\">\n".
249 "<!--\n".
250 "function PopupScriptLoad() {\n".
251 'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew.
252 '", "SMPopup",'.
253 "\"width=$newmail_popup_width,height=$newmail_popup_height,scrollbars=no\");\n".
254 "if (BeforePopupScript != null)\n".
255 "BeforePopupScript();\n".
256 "}\n".
257 "BeforePopupScript = window.onload;\n".
258 "window.onload = PopupScriptLoad;\n".
259 "// End -->\n".
260 "</script>\n";
261 }
262 }
263 }
264
265 // ----- end of hooked functions -----
266
267
268
269 /**
270 * Function tries to detect if file contents match declared file type
271 *
272 * Function returns default extension for detected mime type or 'false'
273 *
274 * TODO: use $contents to check if file is in specified type
275 * @param string $contents file contents
276 * @param string $type file mime type
277 * @return string
278 */
279 function newmail_detect_filetype($contents,$type) {
280 // convert $type to lower case
281 $type=strtolower($type);
282
283 $ret=false;
284
285 switch ($type) {
286 case 'audio/x-wav':
287 $ret='wav';
288 break;
289 case 'audio/mpeg':
290 $ret='mp3';
291 break;
292 case 'application/ogg':
293 $ret='ogg';
294 break;
295 case 'application/x-shockwave-flash':
296 $ret='swf';
297 break;
298 case 'image/svg+xml':
299 $ret='svg';
300 break;
301 default:
302 $ret=false;
303 }
304 return $ret;
305 }
306
307 /**
308 * Function tries to detect uploaded file type
309 * @param string $type
310 * @param string $filename
311 * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
312 */
313 function newmail_get_mediatype($type,$filename) {
314 switch ($type) {
315 // fix for browser's that upload file as application/octet-stream
316 case 'application/octet-stream':
317 $ret=newmail_get_mediatype_by_ext($filename);
318 break;
319 case 'audio/x-wav':
320 $ret=SM_NEWMAIL_FILETYPE_WAV;
321 break;
322 case 'audio/mpeg':
323 $ret=SM_NEWMAIL_FILETYPE_MP3;
324 break;
325 case 'application/ogg':
326 $ret=SM_NEWMAIL_FILETYPE_OGG;
327 break;
328 case 'application/x-shockwave-flash':
329 $ret=SM_NEWMAIL_FILETYPE_SWF;
330 break;
331 case 'image/svg+xml':
332 $ret=SM_NEWMAIL_FILETYPE_SVG;
333 break;
334 default:
335 $ret=false;
336 }
337 return $ret;
338 }
339
340 /**
341 * Function provides filetype detection for browsers, that
342 * upload files with application/octet-stream file type.
343 * Ex. some version of Opera.
344 * @param string $filename
345 * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
346 */
347 function newmail_get_mediatype_by_ext($filename) {
348 if (preg_match("/\.wav$/i",$filename)) return SM_NEWMAIL_FILETYPE_WAV;
349 if (preg_match("/\.mp3$/i",$filename)) return SM_NEWMAIL_FILETYPE_MP3;
350 if (preg_match("/\.ogg$/i",$filename)) return SM_NEWMAIL_FILETYPE_OGG;
351 if (preg_match("/\.swf$/i",$filename)) return SM_NEWMAIL_FILETYPE_SWF;
352 if (preg_match("/\.svg$/i",$filename)) return SM_NEWMAIL_FILETYPE_SVG;
353 return false;
354 }
355
356 /**
357 * Creates html object tags of multimedia object
358 *
359 * Main function that creates multimedia object tags
360 * @param string $object object name
361 * @param integer $type media object type
362 * @param string $path URL to media object
363 * @param array $args media object attributes
364 * @param string $extra tags that have to buried deep inside object tags
365 * @param bool $addsuffix controls addition of suffix to media object url
366 * @return string object html tags and attributes required by selected media type.
367 */
368 function newmail_media_objects($object,$types,$path,$args=array(),$extra='',$addsuffix=true) {
369 global $newmail_mediacompat_mode;
370
371 // first prepare single object for IE
372 $ret = newmail_media_object_ie($object,$types[0],$path,$args,$addsuffix);
373
374 // W3.org nested objects
375 $ret.= "<!--[if !IE]> <-->\n"; // not for IE
376
377 foreach ($types as $type) {
378 $ret.= newmail_media_object($object,$type,$path,$args,$addsuffix);
379 }
380
381 if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
382 $ret.= newmail_media_embed($object,$types[0],$path,$args,$addsuffix);
383 // add $extra code inside objects
384 if ($extra!='')
385 $ret.=$extra . "\n";
386
387 // close embed tags
388 if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
389 $ret.= newmail_media_embed_close($types[0]);
390
391 // close w3.org nested objects
392 foreach (array_reverse($types) as $type) {
393 $ret.= newmail_media_object_close($type);
394 }
395 $ret.= "<!--> <![endif]-->\n"; // end non-IE mode
396 // close IE object
397 $ret.= newmail_media_object_ie_close($types[0]);
398
399 return $ret;
400 }
401
402 /**
403 * Creates object tags of multimedia object for browsers that comply to w3.org
404 * specifications.
405 *
406 * Warnings:
407 * <ul>
408 * <li>Returned string does not contain html closing tag.
409 * <li>This is internal function, use newmail_media_objects() instead
410 * </ul>
411 * @link http://www.w3.org/TR/html4/struct/objects.html#edef-OBJECT W3.org specs
412 * @param string $object object name
413 * @param integer $type media object type
414 * @param string $path URL to media object
415 * @param array $args media object attributes
416 * @param bool $addsuffix controls addition of suffix to media object url
417 * @return string object html tags and attributes required by selected media type.
418 */
419 function newmail_media_object($object,$type,$path,$args=array(),$addsuffix=true) {
420 $ret_w3='';
421 $suffix='';
422 $sArgs=newmail_media_prepare_args($args);
423
424 switch ($type) {
425 case SM_NEWMAIL_FILETYPE_SWF:
426 if ($addsuffix) $suffix='.swf';
427 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
428 .$sArgs
429 .'type="application/x-shockwave-flash">' . "\n";
430 break;
431 case SM_NEWMAIL_FILETYPE_WAV:
432 if ($addsuffix) $suffix='.wav';
433 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
434 .$sArgs
435 .'type="audio/x-wav">' . "\n";
436 break;
437 case SM_NEWMAIL_FILETYPE_OGG:
438 if ($addsuffix) $suffix='.ogg';
439 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
440 .$sArgs
441 .'type="application/ogg">' . "\n";
442 break;
443 case SM_NEWMAIL_FILETYPE_MP3:
444 if ($addsuffix) $suffix='.mp3';
445 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
446 .$sArgs
447 .'type="audio/mpeg">' . "\n";
448 break;
449 case SM_NEWMAIL_FILETYPE_SVG:
450 if ($addsuffix) $suffix='.svg';
451 $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
452 .$sArgs
453 .'type="image/svg+xml">' . "\n";
454 break;
455 default:
456 $ret_w3='';
457 }
458 return $ret_w3;
459 }
460
461 /**
462 * Creates multimedia object tags for Internet Explorer (Win32)
463 *
464 * Warning:
465 * * Returned string does not contain html closing tag, because
466 * this multimedia object can include other media objects.
467 * * This is internal function, use newmail_media_objects() instead
468 *
469 * @param string $object object name
470 * @param integer $type media object type
471 * @param string $path URL to media object
472 * @param array $args media object attributes
473 * @param bool $addsuffix controls addition of suffix to media object url
474 * @return string object html tags and attributes required by selected media type.
475 * @todo add ogg and svg support
476 */
477 function newmail_media_object_ie($object,$type,$path,$args=array(),$addsuffix) {
478 $ret_ie='';
479 $suffix='';
480 $sArgs=newmail_media_prepare_args($args);
481
482 switch ($type) {
483 case SM_NEWMAIL_FILETYPE_SWF:
484 if ($addsuffix) $suffix='.swf';
485 $ret_ie ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
486 .'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" '
487 . $sArgs . 'id="' . $object ."\">\n"
488 .'<param name="movie" value="' . $path . $object . $suffix . "\">\n"
489 .'<param name="hidden" value="true">' . "\n";
490 break;
491 case SM_NEWMAIL_FILETYPE_WAV:
492 if ($addsuffix) $suffix='.wav';
493 $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
494 .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
495 . $sArgs . 'id="' . $object ."\" \n"
496 .'type="audio/x-wav">' ."\n"
497 .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
498 break;
499 case SM_NEWMAIL_FILETYPE_MP3:
500 if ($addsuffix) $suffix='.mp3';
501 $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
502 .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
503 . $sArgs . 'id="' . $object ."\" \n"
504 .'type="audio/mpeg">' ."\n"
505 .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
506 break;
507 case SM_NEWMAIL_FILETYPE_OGG:
508 case SM_NEWMAIL_FILETYPE_SVG:
509 default:
510 $ret_ie='';
511 }
512 return $ret_ie;
513 }
514
515 /**
516 * Creates embed tags of multimedia object
517 *
518 * docs about embed
519 * Apple: http://www.apple.com/quicktime/authoring/embed.html
520 *
521 * Warnings:
522 * * Returned string does not contain html closing tag.
523 * * embed tags will be created by newmail_media_objects() only
524 * when $newmail_mediacompat_mode option is enabled. Option is not
525 * enabled by default in order to comply to w3.org specs.
526 * * This is internal function, use newmail_media_objects() instead
527 * @link http://www.apple.com/quicktime/authoring/embed.html Info about embed tag
528 * @param string $object object name
529 * @param integer $type media object type
530 * @param string $path URL to media object
531 * @param array $args media object attributes
532 * @param bool $addsuffix controls addition of suffix to media object url
533 * @return string embed html tags and attributes required by selected media type.
534 */
535 function newmail_media_embed($object,$type,$path,$args=array(),$addsuffix=true) {
536 $ret_embed='';
537 $suffix='';
538 $sArgs=newmail_media_prepare_args($args);
539
540 switch ($type) {
541 case SM_NEWMAIL_FILETYPE_SWF:
542 if ($addsuffix) $suffix='.swf';
543 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
544 .'hidden="true" autostart="true" '. "\n"
545 .$sArgs . "\n"
546 .'name="' . $object .'" ' . "\n"
547 .'type="application/x-shockwave-flash" ' . "\n"
548 .'pluginspage="http://www.macromedia.com/go/getflashplayer">' . "\n";
549 break;
550 case SM_NEWMAIL_FILETYPE_WAV:
551 if ($addsuffix) $suffix='.wav';
552 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
553 .' hidden="true" autostart="true" '. "\n"
554 .' ' .$sArgs . "\n"
555 .' name="' . $object .'" ' . "\n"
556 .' type="audio/x-wav">' . "\n";
557 break;
558 case SM_NEWMAIL_FILETYPE_SVG:
559 if ($addsuffix) $suffix='.svg';
560 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
561 .'hidden="true" autostart="true" '. "\n"
562 .$sArgs . "\n"
563 .'name="' . $object .'" ' . "\n"
564 .'type="image/svg-xml" ' . "\n"
565 .'pluginspage="http://www.adobe.com/svg/viewer/install/">' . "\n";
566 break;
567 case SM_NEWMAIL_FILETYPE_OGG:
568 if ($addsuffix) $suffix='.ogg';
569 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
570 .' hidden="true" autostart="true" '. "\n"
571 .' ' .$sArgs . "\n"
572 .' name="' . $object .'" ' . "\n"
573 .' type="application/ogg">' . "\n";
574 break;
575 case SM_NEWMAIL_FILETYPE_MP3:
576 if ($addsuffix) $suffix='.mp3';
577 $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
578 .' hidden="true" autostart="true" '. "\n"
579 .' ' .$sArgs . "\n"
580 .' name="' . $object .'" ' . "\n"
581 .' type="audio/mpeg">' . "\n";
582 break;
583 default:
584 $ret_embed='';
585 }
586 return $ret_embed;
587 }
588
589 /**
590 * Adds closing tags for ie object
591 * Warning:
592 * * This is internal function, use newmail_media_objects() instead
593 * @param integer $type media object type
594 * @return string closing tag of media object
595 */
596 function newmail_media_object_ie_close($type) {
597 $ret_end='';
598 switch ($type) {
599 case SM_NEWMAIL_FILETYPE_SWF:
600 case SM_NEWMAIL_FILETYPE_WAV:
601 case SM_NEWMAIL_FILETYPE_MP3:
602 $ret_end="</object>\n";
603 break;
604 case SM_NEWMAIL_FILETYPE_OGG:
605 case SM_NEWMAIL_FILETYPE_SVG:
606 default:
607 $ret_end='';
608 }
609 return $ret_end;
610 }
611
612 /**
613 * Adds closing tags for object
614 * Warning:
615 * * This is internal function, use newmail_media_objects() instead
616 * @param integer $type media object type
617 * @return string closing tag of media object
618 */
619 function newmail_media_object_close($type) {
620 $ret_end='';
621 switch ($type) {
622 case SM_NEWMAIL_FILETYPE_SWF:
623 case SM_NEWMAIL_FILETYPE_WAV:
624 case SM_NEWMAIL_FILETYPE_OGG:
625 case SM_NEWMAIL_FILETYPE_MP3:
626 case SM_NEWMAIL_FILETYPE_SVG:
627 $ret_end="</object>\n";
628 break;
629 default:
630 $ret_end='';
631 }
632 return $ret_end;
633 }
634
635 /**
636 * Adds closing tags for object
637 * Warning:
638 * * This is internal function, use newmail_media_objects() instead
639 * @param integer $type media object type
640 * @return string closing tag of media object
641 */
642 function newmail_media_embed_close($type) {
643 $ret_end='';
644 switch ($type) {
645 case SM_NEWMAIL_FILETYPE_SWF:
646 case SM_NEWMAIL_FILETYPE_WAV:
647 case SM_NEWMAIL_FILETYPE_OGG:
648 case SM_NEWMAIL_FILETYPE_MP3:
649 case SM_NEWMAIL_FILETYPE_SVG:
650 $ret_end="</embed>\n";
651 break;
652 default:
653 $ret_end='';
654 }
655 return $ret_end;
656 }
657
658 /**
659 * Converts media attributes to string
660 * Warning:
661 * * attribute values are automatically sanitized by htmlspecialchars()
662 * * This is internal function, use newmail_media_objects() instead
663 * @param array $args array with object attributes
664 * @return string string with object attributes
665 */
666 function newmail_media_prepare_args($args) {
667 $ret_args='';
668 foreach ($args as $arg => $value) {
669 $ret_args.= $arg . '="' . htmlspecialchars($value) . '" ';
670 }
671 return $ret_args;
672 }
673
674 /**
675 * Detects used media type and creates all need tags
676 * @param string $newmail_media
677 * @return string html tags with media objects
678 */
679 function newmail_create_media_tags($newmail_media) {
680 global $newmail_mmedia, $newmail_userfile_type;
681
682 if (preg_match("/^mmedia_+/",$newmail_media)) {
683 $ret_media = "<!-- newmail mmedia option -->\n";
684 // remove mmedia key
685 $newmail_mmedia_short=preg_replace("/^mmedia_/",'',$newmail_media);
686 // check if media option is not removed
687 if (isset($newmail_mmedia[$newmail_mmedia_short])) {
688 $ret_media.= newmail_media_objects($newmail_mmedia_short,
689 $newmail_mmedia[$newmail_mmedia_short]['types'],
690 sqm_baseuri() . 'plugins/newmail/media/',
691 $newmail_mmedia[$newmail_mmedia_short]['args']);
692 }
693 $ret_media.= "<!-- end of newmail mmedia option -->\n";
694 } elseif ($newmail_media=='(userfile)') {
695 $ret_media = "<!-- newmail usermedia option -->\n";
696 $ret_media.= newmail_media_objects('loadfile.php',
697 array($newmail_userfile_type),
698 sqm_baseuri() . 'plugins/newmail/',
699 array('width'=>0,'height'=>0),
700 '',false);
701 $ret_media.= "<!-- end of newmail usermedia option -->\n";
702 } else {
703 $ret_media = "<!-- newmail sounds from sounds/*.wav -->\n";
704 $ret_media.= newmail_media_objects(basename($newmail_media),
705 array(SM_NEWMAIL_FILETYPE_WAV),
706 sqm_baseuri() . 'plugins/newmail/sounds/',
707 array('width'=>0,'height'=>0),
708 '',false);
709 $ret_media.= "<!-- end of newmail sounds from sounds/*.wav -->\n";
710 }
711 return $ret_media;
712 }
713 ?>