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