functions.php 27 KB

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