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