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