functions.php 26 KB

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