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