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