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