functions.php 27 KB

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