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