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