functions.php 26 KB

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