functions.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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' => _("New Mail 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=_("New Mail 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. $newmail_mmedia, $newmail_allowsound, $newmail_userfile_type,
  191. $newmail_popup_width, $newmail_popup_height, $totalNewArr,
  192. $newmail_title_bar_singular, $newmail_title_bar_plural,
  193. $org_title;
  194. if ($newmail_media_enable == 'on' ||
  195. $newmail_popup == 'on' ||
  196. $newmail_changetitle) {
  197. $output = '';
  198. if (!empty($totalNewArr)) { $totalNew=array_sum($totalNewArr); }
  199. else { $totalNew=0; }
  200. // If we found unseen messages, then we
  201. // will play the sound as follows:
  202. if ($newmail_changetitle) {
  203. // make sure default strings are in pot file
  204. $ignore = _("%s New Message");
  205. $ignore = _("%s New Messages");
  206. $singular_title = "%s New Message";
  207. $plural_title = "%s New Messages";
  208. if (!empty($newmail_title_bar_singular))
  209. $singular_title = $newmail_title_bar_singular;
  210. if (!empty($newmail_title_bar_plural))
  211. $plural_title = $newmail_title_bar_plural;
  212. list($singular_title, $plural_title) = str_replace(array('###USERNAME###', '###ORG_TITLE###'), array($username, $org_title), array($singular_title, $plural_title));
  213. $title = sprintf(ngettext($singular_title, $plural_title, $totalNew), $totalNew);
  214. //FIXME: remove HTML from core - put this into a template file
  215. $output .= "<script type=\"text/javascript\">\n"
  216. . "function ChangeTitleLoad() {\n"
  217. . "var BeforeChangeTitle;\n"
  218. . 'window.parent.document.title = "'
  219. . $title
  220. . "\";\n"
  221. . "if (BeforeChangeTitle != null)\n"
  222. . "BeforeChangeTitle();\n"
  223. . "}\n"
  224. . "BeforeChangeTitle = window.onload;\n"
  225. . "window.onload = ChangeTitleLoad;\n"
  226. . "</script>\n";
  227. }
  228. // create media output if there are new email messages
  229. if ($newmail_allowsound && $totalNew > 0
  230. && $newmail_media_enable == 'on'
  231. && $newmail_media != '' ) {
  232. //FIXME: remove HTML from core - put this into a template file
  233. $output .= newmail_create_media_tags($newmail_media);
  234. }
  235. if ($totalNew > 0 && $newmail_popup == 'on') {
  236. //FIXME: remove HTML from core - put this into a template file
  237. $output .= "<script type=\"text/javascript\">\n"
  238. . "<!--\n"
  239. . "function PopupScriptLoad() {\n"
  240. . 'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew
  241. . '", "SMPopup",'
  242. . "\"width=$newmail_popup_width,height=$newmail_popup_height,scrollbars=no\");\n"
  243. . "if (BeforePopupScript != null)\n"
  244. . "BeforePopupScript();\n"
  245. . "}\n"
  246. . "BeforePopupScript = window.onload;\n"
  247. . "window.onload = PopupScriptLoad;\n"
  248. . "// End -->\n"
  249. . "</script>\n";
  250. }
  251. return array('left_main_after' => $output);
  252. }
  253. }
  254. // ----- end of hooked functions -----
  255. /**
  256. * Function tries to detect if file contents match declared file type
  257. *
  258. * Function returns default extension for detected mime type or 'false'
  259. *
  260. * TODO: use $contents to check if file is in specified type
  261. * @param string $contents file contents
  262. * @param string $type file mime type
  263. * @return string
  264. */
  265. function newmail_detect_filetype($contents,$type) {
  266. // convert $type to lower case
  267. $type=strtolower($type);
  268. $ret=false;
  269. switch ($type) {
  270. case 'audio/x-wav':
  271. $ret='wav';
  272. break;
  273. case 'audio/mpeg':
  274. $ret='mp3';
  275. break;
  276. case 'application/ogg':
  277. $ret='ogg';
  278. break;
  279. case 'application/x-shockwave-flash':
  280. $ret='swf';
  281. break;
  282. case 'image/svg+xml':
  283. $ret='svg';
  284. break;
  285. default:
  286. $ret=false;
  287. }
  288. return $ret;
  289. }
  290. /**
  291. * Function tries to detect uploaded file type
  292. * @param string $type
  293. * @param string $filename
  294. * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
  295. */
  296. function newmail_get_mediatype($type,$filename) {
  297. switch ($type) {
  298. // fix for browser's that upload file as application/octet-stream
  299. case 'application/octet-stream':
  300. $ret=newmail_get_mediatype_by_ext($filename);
  301. break;
  302. case 'audio/x-wav':
  303. $ret=SM_NEWMAIL_FILETYPE_WAV;
  304. break;
  305. case 'audio/mpeg':
  306. $ret=SM_NEWMAIL_FILETYPE_MP3;
  307. break;
  308. case 'application/ogg':
  309. $ret=SM_NEWMAIL_FILETYPE_OGG;
  310. break;
  311. case 'application/x-shockwave-flash':
  312. $ret=SM_NEWMAIL_FILETYPE_SWF;
  313. break;
  314. case 'image/svg+xml':
  315. $ret=SM_NEWMAIL_FILETYPE_SVG;
  316. break;
  317. default:
  318. $ret=false;
  319. }
  320. return $ret;
  321. }
  322. /**
  323. * Function provides filetype detection for browsers, that
  324. * upload files with application/octet-stream file type.
  325. * Ex. some version of Opera.
  326. * @param string $filename
  327. * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
  328. */
  329. function newmail_get_mediatype_by_ext($filename) {
  330. if (preg_match("/\.wav$/i",$filename)) return SM_NEWMAIL_FILETYPE_WAV;
  331. if (preg_match("/\.mp3$/i",$filename)) return SM_NEWMAIL_FILETYPE_MP3;
  332. if (preg_match("/\.ogg$/i",$filename)) return SM_NEWMAIL_FILETYPE_OGG;
  333. if (preg_match("/\.swf$/i",$filename)) return SM_NEWMAIL_FILETYPE_SWF;
  334. if (preg_match("/\.svg$/i",$filename)) return SM_NEWMAIL_FILETYPE_SVG;
  335. return false;
  336. }
  337. /**
  338. * Creates html object tags of multimedia object
  339. *
  340. * Main function that creates multimedia object tags
  341. * @param string $object object name
  342. * @param integer $type media object type
  343. * @param string $path URL to media object
  344. * @param array $args media object attributes
  345. * @param string $extra tags that have to buried deep inside object tags
  346. * @param bool $addsuffix controls addition of suffix to media object url
  347. * @return string object html tags and attributes required by selected media type.
  348. */
  349. function newmail_media_objects($object,$types,$path,$args=array(),$extra='',$addsuffix=true) {
  350. global $newmail_mediacompat_mode;
  351. // first prepare single object for IE
  352. $ret = newmail_media_object_ie($object,$types[0],$path,$args,$addsuffix);
  353. // W3.org nested objects
  354. $ret.= "<!--[if !IE]> <-->\n"; // not for IE
  355. foreach ($types as $type) {
  356. $ret.= newmail_media_object($object,$type,$path,$args,$addsuffix);
  357. }
  358. if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
  359. $ret.= newmail_media_embed($object,$types[0],$path,$args,$addsuffix);
  360. // add $extra code inside objects
  361. if ($extra!='')
  362. $ret.=$extra . "\n";
  363. // close embed tags
  364. if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
  365. $ret.= newmail_media_embed_close($types[0]);
  366. // close w3.org nested objects
  367. foreach (array_reverse($types) as $type) {
  368. $ret.= newmail_media_object_close($type);
  369. }
  370. $ret.= "<!--> <![endif]-->\n"; // end non-IE mode
  371. // close IE object
  372. $ret.= newmail_media_object_ie_close($types[0]);
  373. return $ret;
  374. }
  375. /**
  376. * Creates object tags of multimedia object for browsers that comply to w3.org
  377. * specifications.
  378. *
  379. * Warnings:
  380. * <ul>
  381. * <li>Returned string does not contain html closing tag.
  382. * <li>This is internal function, use newmail_media_objects() instead
  383. * </ul>
  384. * @link http://www.w3.org/TR/html4/struct/objects.html#edef-OBJECT W3.org specs
  385. * @param string $object object name
  386. * @param integer $type media object type
  387. * @param string $path URL to media object
  388. * @param array $args media object attributes
  389. * @param bool $addsuffix controls addition of suffix to media object url
  390. * @return string object html tags and attributes required by selected media type.
  391. */
  392. function newmail_media_object($object,$type,$path,$args=array(),$addsuffix=true) {
  393. $ret_w3='';
  394. $suffix='';
  395. $sArgs=newmail_media_prepare_args($args);
  396. switch ($type) {
  397. case SM_NEWMAIL_FILETYPE_SWF:
  398. if ($addsuffix) $suffix='.swf';
  399. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  400. .$sArgs
  401. .'type="application/x-shockwave-flash">' . "\n";
  402. break;
  403. case SM_NEWMAIL_FILETYPE_WAV:
  404. if ($addsuffix) $suffix='.wav';
  405. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  406. .$sArgs
  407. .'type="audio/x-wav">' . "\n";
  408. break;
  409. case SM_NEWMAIL_FILETYPE_OGG:
  410. if ($addsuffix) $suffix='.ogg';
  411. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  412. .$sArgs
  413. .'type="application/ogg">' . "\n";
  414. break;
  415. case SM_NEWMAIL_FILETYPE_MP3:
  416. if ($addsuffix) $suffix='.mp3';
  417. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  418. .$sArgs
  419. .'type="audio/mpeg">' . "\n";
  420. break;
  421. case SM_NEWMAIL_FILETYPE_SVG:
  422. if ($addsuffix) $suffix='.svg';
  423. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  424. .$sArgs
  425. .'type="image/svg+xml">' . "\n";
  426. break;
  427. default:
  428. $ret_w3='';
  429. }
  430. return $ret_w3;
  431. }
  432. /**
  433. * Creates multimedia object tags for Internet Explorer (Win32)
  434. *
  435. * Warning:
  436. * * Returned string does not contain html closing tag, because
  437. * this multimedia object can include other media objects.
  438. * * This is internal function, use newmail_media_objects() instead
  439. *
  440. * @param string $object object name
  441. * @param integer $type media object type
  442. * @param string $path URL to media object
  443. * @param array $args media object attributes
  444. * @param bool $addsuffix controls addition of suffix to media object url
  445. * @return string object html tags and attributes required by selected media type.
  446. * @todo add ogg and svg support
  447. */
  448. function newmail_media_object_ie($object,$type,$path,$args=array(),$addsuffix) {
  449. $ret_ie='';
  450. $suffix='';
  451. $sArgs=newmail_media_prepare_args($args);
  452. switch ($type) {
  453. case SM_NEWMAIL_FILETYPE_SWF:
  454. if ($addsuffix) $suffix='.swf';
  455. $ret_ie ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
  456. .'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" '
  457. . $sArgs . 'id="' . $object ."\">\n"
  458. .'<param name="movie" value="' . $path . $object . $suffix . "\">\n"
  459. .'<param name="hidden" value="true">' . "\n";
  460. break;
  461. case SM_NEWMAIL_FILETYPE_WAV:
  462. if ($addsuffix) $suffix='.wav';
  463. $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
  464. .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
  465. . $sArgs . 'id="' . $object ."\" \n"
  466. .'type="audio/x-wav">' ."\n"
  467. .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
  468. break;
  469. case SM_NEWMAIL_FILETYPE_MP3:
  470. if ($addsuffix) $suffix='.mp3';
  471. $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
  472. .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
  473. . $sArgs . 'id="' . $object ."\" \n"
  474. .'type="audio/mpeg">' ."\n"
  475. .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
  476. break;
  477. case SM_NEWMAIL_FILETYPE_OGG:
  478. case SM_NEWMAIL_FILETYPE_SVG:
  479. default:
  480. $ret_ie='';
  481. }
  482. return $ret_ie;
  483. }
  484. /**
  485. * Creates embed tags of multimedia object
  486. *
  487. * docs about embed
  488. * Apple: http://www.apple.com/quicktime/authoring/embed.html
  489. *
  490. * Warnings:
  491. * * Returned string does not contain html closing tag.
  492. * * embed tags will be created by newmail_media_objects() only
  493. * when $newmail_mediacompat_mode option is enabled. Option is not
  494. * enabled by default in order to comply to w3.org specs.
  495. * * This is internal function, use newmail_media_objects() instead
  496. * @link http://www.apple.com/quicktime/authoring/embed.html Info about embed tag
  497. * @param string $object object name
  498. * @param integer $type media object type
  499. * @param string $path URL to media object
  500. * @param array $args media object attributes
  501. * @param bool $addsuffix controls addition of suffix to media object url
  502. * @return string embed html tags and attributes required by selected media type.
  503. */
  504. function newmail_media_embed($object,$type,$path,$args=array(),$addsuffix=true) {
  505. $ret_embed='';
  506. $suffix='';
  507. $sArgs=newmail_media_prepare_args($args);
  508. switch ($type) {
  509. case SM_NEWMAIL_FILETYPE_SWF:
  510. if ($addsuffix) $suffix='.swf';
  511. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  512. .'hidden="true" autostart="true" '. "\n"
  513. .$sArgs . "\n"
  514. .'name="' . $object .'" ' . "\n"
  515. .'type="application/x-shockwave-flash" ' . "\n"
  516. .'pluginspage="http://www.macromedia.com/go/getflashplayer">' . "\n";
  517. break;
  518. case SM_NEWMAIL_FILETYPE_WAV:
  519. if ($addsuffix) $suffix='.wav';
  520. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  521. .' hidden="true" autostart="true" '. "\n"
  522. .' ' .$sArgs . "\n"
  523. .' name="' . $object .'" ' . "\n"
  524. .' type="audio/x-wav">' . "\n";
  525. break;
  526. case SM_NEWMAIL_FILETYPE_SVG:
  527. if ($addsuffix) $suffix='.svg';
  528. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  529. .'hidden="true" autostart="true" '. "\n"
  530. .$sArgs . "\n"
  531. .'name="' . $object .'" ' . "\n"
  532. .'type="image/svg-xml" ' . "\n"
  533. .'pluginspage="http://www.adobe.com/svg/viewer/install/">' . "\n";
  534. break;
  535. case SM_NEWMAIL_FILETYPE_OGG:
  536. if ($addsuffix) $suffix='.ogg';
  537. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  538. .' hidden="true" autostart="true" '. "\n"
  539. .' ' .$sArgs . "\n"
  540. .' name="' . $object .'" ' . "\n"
  541. .' type="application/ogg">' . "\n";
  542. break;
  543. case SM_NEWMAIL_FILETYPE_MP3:
  544. if ($addsuffix) $suffix='.mp3';
  545. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  546. .' hidden="true" autostart="true" '. "\n"
  547. .' ' .$sArgs . "\n"
  548. .' name="' . $object .'" ' . "\n"
  549. .' type="audio/mpeg">' . "\n";
  550. break;
  551. default:
  552. $ret_embed='';
  553. }
  554. return $ret_embed;
  555. }
  556. /**
  557. * Adds closing tags for ie object
  558. * Warning:
  559. * * This is internal function, use newmail_media_objects() instead
  560. * @param integer $type media object type
  561. * @return string closing tag of media object
  562. */
  563. function newmail_media_object_ie_close($type) {
  564. $ret_end='';
  565. switch ($type) {
  566. case SM_NEWMAIL_FILETYPE_SWF:
  567. case SM_NEWMAIL_FILETYPE_WAV:
  568. case SM_NEWMAIL_FILETYPE_MP3:
  569. $ret_end="</object>\n";
  570. break;
  571. case SM_NEWMAIL_FILETYPE_OGG:
  572. case SM_NEWMAIL_FILETYPE_SVG:
  573. default:
  574. $ret_end='';
  575. }
  576. return $ret_end;
  577. }
  578. /**
  579. * Adds closing tags for object
  580. * Warning:
  581. * * This is internal function, use newmail_media_objects() instead
  582. * @param integer $type media object type
  583. * @return string closing tag of media object
  584. */
  585. function newmail_media_object_close($type) {
  586. $ret_end='';
  587. switch ($type) {
  588. case SM_NEWMAIL_FILETYPE_SWF:
  589. case SM_NEWMAIL_FILETYPE_WAV:
  590. case SM_NEWMAIL_FILETYPE_OGG:
  591. case SM_NEWMAIL_FILETYPE_MP3:
  592. case SM_NEWMAIL_FILETYPE_SVG:
  593. $ret_end="</object>\n";
  594. break;
  595. default:
  596. $ret_end='';
  597. }
  598. return $ret_end;
  599. }
  600. /**
  601. * Adds closing tags for object
  602. * Warning:
  603. * * This is internal function, use newmail_media_objects() instead
  604. * @param integer $type media object type
  605. * @return string closing tag of media object
  606. */
  607. function newmail_media_embed_close($type) {
  608. $ret_end='';
  609. switch ($type) {
  610. case SM_NEWMAIL_FILETYPE_SWF:
  611. case SM_NEWMAIL_FILETYPE_WAV:
  612. case SM_NEWMAIL_FILETYPE_OGG:
  613. case SM_NEWMAIL_FILETYPE_MP3:
  614. case SM_NEWMAIL_FILETYPE_SVG:
  615. $ret_end="</embed>\n";
  616. break;
  617. default:
  618. $ret_end='';
  619. }
  620. return $ret_end;
  621. }
  622. /**
  623. * Converts media attributes to string
  624. * Warning:
  625. * * attribute values are automatically sanitized by htmlspecialchars()
  626. * * This is internal function, use newmail_media_objects() instead
  627. * @param array $args array with object attributes
  628. * @return string string with object attributes
  629. */
  630. function newmail_media_prepare_args($args) {
  631. $ret_args='';
  632. foreach ($args as $arg => $value) {
  633. $ret_args.= $arg . '="' . htmlspecialchars($value) . '" ';
  634. }
  635. return $ret_args;
  636. }
  637. /**
  638. * Detects used media type and creates all need tags
  639. * @param string $newmail_media
  640. * @return string html tags with media objects
  641. */
  642. function newmail_create_media_tags($newmail_media) {
  643. global $newmail_mmedia, $newmail_userfile_type;
  644. if (preg_match("/^mmedia_+/",$newmail_media)) {
  645. $ret_media = "<!-- newmail mmedia option -->\n";
  646. // remove mmedia key
  647. $newmail_mmedia_short=preg_replace("/^mmedia_/",'',$newmail_media);
  648. // check if media option is not removed
  649. if (isset($newmail_mmedia[$newmail_mmedia_short])) {
  650. $ret_media.= newmail_media_objects($newmail_mmedia_short,
  651. $newmail_mmedia[$newmail_mmedia_short]['types'],
  652. sqm_baseuri() . 'plugins/newmail/media/',
  653. $newmail_mmedia[$newmail_mmedia_short]['args']);
  654. }
  655. $ret_media.= "<!-- end of newmail mmedia option -->\n";
  656. } elseif ($newmail_media=='(userfile)') {
  657. $ret_media = "<!-- newmail usermedia option -->\n";
  658. $ret_media.= newmail_media_objects('loadfile.php',
  659. array($newmail_userfile_type),
  660. sqm_baseuri() . 'plugins/newmail/',
  661. array('width'=>0,'height'=>0),
  662. '',false);
  663. $ret_media.= "<!-- end of newmail usermedia option -->\n";
  664. } else {
  665. $ret_media = "<!-- newmail sounds from sounds/*.wav -->\n";
  666. $ret_media.= newmail_media_objects(basename($newmail_media),
  667. array(SM_NEWMAIL_FILETYPE_WAV),
  668. sqm_baseuri() . 'plugins/newmail/sounds/',
  669. array('width'=>0,'height'=>0),
  670. '',false);
  671. $ret_media.= "<!-- end of newmail sounds from sounds/*.wav -->\n";
  672. }
  673. return $ret_media;
  674. }