functions.php 26 KB

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