functions.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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. * SMPREF_UNSEEN_* constants
  18. */
  19. include_once(SM_PATH . 'functions/constants.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_recent = '';
  60. $media_changetitle = '';
  61. $media_sel = '';
  62. $popup_width = '';
  63. $popup_height = '';
  64. sqgetGlobalVar('media_enable', $media_enable, SQ_POST);
  65. sqgetGlobalVar('media_popup', $media_popup, 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_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('newmail_unseen_notify', $newmail_unseen_notify, SQ_POST)) {
  82. $newmail_unseen_notify = (int) $newmail_unseen_notify;
  83. setPref($data_dir,$username,'newmail_unseen_notify',$newmail_unseen_notify);
  84. }
  85. if( sqgetGlobalVar('media_sel', $media_sel, SQ_POST) &&
  86. $media_sel == '(none)' ) {
  87. removePref($data_dir,$username,'newmail_media');
  88. } else {
  89. setPref($data_dir,$username,'newmail_media',$media_sel);
  90. }
  91. // process uploaded file
  92. if ($newmail_uploadsounds && isset($_FILES['media_file']['tmp_name']) && $_FILES['media_file']['tmp_name']!='') {
  93. // set temp file and get media file name
  94. $newmail_tempmedia=getHashedDir($username, $data_dir) . "/$username.tempsound";
  95. $newmail_mediafile=getHashedFile($username, $data_dir, $username . '.sound');
  96. if (move_uploaded_file($_FILES['media_file']['tmp_name'], $newmail_tempmedia)) {
  97. // new media file is in $newmail_tempmedia
  98. if (file_exists($newmail_mediafile)) unlink($newmail_mediafile);
  99. if (! rename($newmail_tempmedia,$newmail_mediafile)) {
  100. // remove (userfile), if file rename fails
  101. removePref($data_dir,$username,'newmail_media');
  102. } else {
  103. // store media type
  104. if (isset($_FILES['media_file']['type']) && isset($_FILES['media_file']['name'])) {
  105. setPref($data_dir,$username,'newmail_userfile_type',
  106. newmail_get_mediatype($_FILES['media_file']['type'],$_FILES['media_file']['name']));
  107. } else {
  108. removePref($data_dir,$username,'newmail_userfile_type');
  109. }
  110. // store file name
  111. if (isset($_FILES['media_file']['name'])) {
  112. setPref($data_dir,$username,'newmail_userfile_name',basename($_FILES['media_file']['name']));
  113. } else {
  114. setPref($data_dir,$username,'newmail_userfile_name','mediafile.unknown');
  115. }
  116. }
  117. }
  118. }
  119. }
  120. }
  121. /**
  122. * Load newmail plugin settings
  123. */
  124. function newmail_pref_function() {
  125. global $username,$data_dir;
  126. global $newmail_media,$newmail_media_enable,$newmail_popup;
  127. global $newmail_recent, $newmail_changetitle;
  128. global $newmail_userfile_type, $newmail_userfile_name;
  129. global $newmail_popup_width, $newmail_popup_height;
  130. global $newmail_unseen_notify;
  131. $newmail_recent = getPref($data_dir,$username,'newmail_recent');
  132. $newmail_media_enable = getPref($data_dir,$username,'newmail_enable');
  133. $newmail_media = getPref($data_dir, $username, 'newmail_media', '(none)');
  134. // remove full location from setting (since SM 1.5.1 plugin uses only filename).
  135. if ($newmail_media!='(none)')
  136. $newmail_media = basename($newmail_media);
  137. $newmail_popup = getPref($data_dir, $username, 'newmail_popup');
  138. $newmail_popup_width = getPref($data_dir, $username, 'newmail_popup_width',200);
  139. $newmail_popup_height = getPref($data_dir, $username, 'newmail_popup_height',130);
  140. $newmail_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
  141. $newmail_userfile_type = getPref($data_dir, $username, 'newmail_userfile_type');
  142. $newmail_userfile_name = getPref($data_dir,$username,'newmail_userfile_name','');
  143. $newmail_unseen_notify = getPref($data_dir,$username,'newmail_unseen_notify',0);
  144. }
  145. /**
  146. * Set loadinfo data
  147. *
  148. * Used by option page when saving settings.
  149. */
  150. function newmail_set_loadinfo_function() {
  151. global $optpage, $optpage_name;
  152. if ($optpage=='newmail') {
  153. $optpage_name=_("NewMail Options");
  154. }
  155. }
  156. /* Receive the status of the folder and do something with it */
  157. function newmail_folder_status($statusarr) {
  158. global $newmail_media_enable,$newmail_popup,$newmail_changetitle,$trash_folder,
  159. $sent_folder,$totalNewArr, $newmail_unseen_notify, $unseen_notify, $newmail_recent;
  160. /* if $newmail_unseen_notify is set to zero, plugin follows $unseen_notify */
  161. if ($newmail_unseen_notify == 0)
  162. $newmail_unseen_notify = $unseen_notify;
  163. $mailbox=$statusarr['MAILBOX'];
  164. if (($newmail_media_enable == 'on' ||
  165. $newmail_popup == 'on' ||
  166. $newmail_changetitle == 'on') &&
  167. /**
  168. * make sure that $newmail_unseen_notify is set to supported value,
  169. * currently (1.5.2cvs) SMPREF_UNSEEN_NORMAL has highest integer value
  170. * in SMPREF_UNSEEN constants
  171. */
  172. ($newmail_unseen_notify > SMPREF_UNSEEN_NONE && $newmail_unseen_notify <= SMPREF_UNSEEN_NORMAL)) {
  173. // Skip folders for Sent and Trash
  174. // TODO: make this optional
  175. if ($statusarr['MAILBOX'] == $sent_folder || $statusarr['MAILBOX'] == $trash_folder) {
  176. return 0;
  177. }
  178. if ((($mailbox == 'INBOX') && ($newmail_unseen_notify == SMPREF_UNSEEN_INBOX)) ||
  179. ($newmail_unseen_notify == SMPREF_UNSEEN_SPECIAL && isSpecialMailbox($mailbox)) ||
  180. ($newmail_unseen_notify == SMPREF_UNSEEN_NORMAL && ! isSpecialMailbox($mailbox)) ||
  181. ($newmail_unseen_notify == SMPREF_UNSEEN_ALL)) {
  182. if (($newmail_recent == 'on') && (!empty($statusarr['RECENT']))) {
  183. $totalNewArr[$mailbox] = $statusarr['RECENT'];
  184. } elseif ($newmail_recent != 'on' && !empty($statusarr['UNSEEN'])) {
  185. $totalNewArr[$mailbox] = $statusarr['UNSEEN'];
  186. }
  187. }
  188. }
  189. }
  190. /**
  191. * Insert needed data in left_main
  192. */
  193. function newmail_plugin_function() {
  194. global $username, $newmail_media, $newmail_media_enable, $newmail_popup,
  195. $newmail_recent, $newmail_changetitle, $imapConnection, $PHP_SELF;
  196. global $newmail_mmedia, $newmail_allowsound;
  197. global $newmail_userfile_type;
  198. global $newmail_popup_width, $newmail_popup_height;
  199. global $totalNewArr;
  200. if ($newmail_media_enable == 'on' ||
  201. $newmail_popup == 'on' ||
  202. $newmail_changetitle) {
  203. if (!empty($totalNewArr)) { $totalNew=array_sum($totalNewArr); }
  204. else { $totalNew=0; }
  205. // If we found unseen messages, then we
  206. // will play the sound as follows:
  207. if ($newmail_changetitle) {
  208. echo "<script type=\"text/javascript\">\n" .
  209. "function ChangeTitleLoad() {\n";
  210. echo 'window.parent.document.title = "' .
  211. sprintf(ngettext("%s New Message","%s New Messages",$totalNew), $totalNew) .
  212. "\";\n";
  213. echo "if (BeforeChangeTitle != null)\n".
  214. "BeforeChangeTitle();\n".
  215. "}\n".
  216. "BeforeChangeTitle = window.onload;\n".
  217. "window.onload = ChangeTitleLoad;\n".
  218. "</script>\n";
  219. }
  220. // create media output if there are new email messages
  221. if ($newmail_allowsound && $totalNew > 0
  222. && $newmail_media_enable == 'on'
  223. && $newmail_media != '' ) {
  224. echo newmail_create_media_tags($newmail_media);
  225. }
  226. if ($totalNew > 0 && $newmail_popup == 'on') {
  227. // Idea by: Nic Wolfe (Nic@TimelapseProductions.com)
  228. // Web URL: http://fineline.xs.mw
  229. // More code from Tyler Akins
  230. echo "<script type=\"text/javascript\">\n".
  231. "<!--\n".
  232. "function PopupScriptLoad() {\n".
  233. 'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew.
  234. '", "SMPopup",'.
  235. "\"width=$newmail_popup_width,height=$newmail_popup_height,scrollbars=no\");\n".
  236. "if (BeforePopupScript != null)\n".
  237. "BeforePopupScript();\n".
  238. "}\n".
  239. "BeforePopupScript = window.onload;\n".
  240. "window.onload = PopupScriptLoad;\n".
  241. "// End -->\n".
  242. "</script>\n";
  243. }
  244. }
  245. }
  246. // ----- end of hooked functions -----
  247. /**
  248. * Function tries to detect if file contents match declared file type
  249. *
  250. * Function returns default extension for detected mime type or 'false'
  251. *
  252. * TODO: use $contents to check if file is in specified type
  253. * @param string $contents file contents
  254. * @param string $type file mime type
  255. * @return string
  256. */
  257. function newmail_detect_filetype($contents,$type) {
  258. // convert $type to lower case
  259. $type=strtolower($type);
  260. $ret=false;
  261. switch ($type) {
  262. case 'audio/x-wav':
  263. $ret='wav';
  264. break;
  265. case 'audio/mpeg':
  266. $ret='mp3';
  267. break;
  268. case 'application/ogg':
  269. $ret='ogg';
  270. break;
  271. case 'application/x-shockwave-flash':
  272. $ret='swf';
  273. break;
  274. case 'image/svg+xml':
  275. $ret='svg';
  276. break;
  277. default:
  278. $ret=false;
  279. }
  280. return $ret;
  281. }
  282. /**
  283. * Function tries to detect uploaded file type
  284. * @param string $type
  285. * @param string $filename
  286. * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
  287. */
  288. function newmail_get_mediatype($type,$filename) {
  289. switch ($type) {
  290. // fix for browser's that upload file as application/octet-stream
  291. case 'application/octet-stream':
  292. $ret=newmail_get_mediatype_by_ext($filename);
  293. break;
  294. case 'audio/x-wav':
  295. $ret=SM_NEWMAIL_FILETYPE_WAV;
  296. break;
  297. case 'audio/mpeg':
  298. $ret=SM_NEWMAIL_FILETYPE_MP3;
  299. break;
  300. case 'application/ogg':
  301. $ret=SM_NEWMAIL_FILETYPE_OGG;
  302. break;
  303. case 'application/x-shockwave-flash':
  304. $ret=SM_NEWMAIL_FILETYPE_SWF;
  305. break;
  306. case 'image/svg+xml':
  307. $ret=SM_NEWMAIL_FILETYPE_SVG;
  308. break;
  309. default:
  310. $ret=false;
  311. }
  312. return $ret;
  313. }
  314. /**
  315. * Function provides filetype detection for browsers, that
  316. * upload files with application/octet-stream file type.
  317. * Ex. some version of Opera.
  318. * @param string $filename
  319. * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
  320. */
  321. function newmail_get_mediatype_by_ext($filename) {
  322. if (preg_match("/\.wav$/i",$filename)) return SM_NEWMAIL_FILETYPE_WAV;
  323. if (preg_match("/\.mp3$/i",$filename)) return SM_NEWMAIL_FILETYPE_MP3;
  324. if (preg_match("/\.ogg$/i",$filename)) return SM_NEWMAIL_FILETYPE_OGG;
  325. if (preg_match("/\.swf$/i",$filename)) return SM_NEWMAIL_FILETYPE_SWF;
  326. if (preg_match("/\.svg$/i",$filename)) return SM_NEWMAIL_FILETYPE_SVG;
  327. return false;
  328. }
  329. /**
  330. * Creates html object tags of multimedia object
  331. *
  332. * Main function that creates multimedia object tags
  333. * @param string $object object name
  334. * @param integer $type media object type
  335. * @param string $path URL to media object
  336. * @param array $args media object attributes
  337. * @param string $extra tags that have to buried deep inside object tags
  338. * @param bool $addsuffix controls addition of suffix to media object url
  339. * @return string object html tags and attributes required by selected media type.
  340. */
  341. function newmail_media_objects($object,$types,$path,$args=array(),$extra='',$addsuffix=true) {
  342. global $newmail_mediacompat_mode;
  343. // first prepare single object for IE
  344. $ret = newmail_media_object_ie($object,$types[0],$path,$args,$addsuffix);
  345. // W3.org nested objects
  346. $ret.= "<!--[if !IE]> <-->\n"; // not for IE
  347. foreach ($types as $type) {
  348. $ret.= newmail_media_object($object,$type,$path,$args,$addsuffix);
  349. }
  350. if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
  351. $ret.= newmail_media_embed($object,$types[0],$path,$args,$addsuffix);
  352. // add $extra code inside objects
  353. if ($extra!='')
  354. $ret.=$extra . "\n";
  355. // close embed tags
  356. if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
  357. $ret.= newmail_media_embed_close($types[0]);
  358. // close w3.org nested objects
  359. foreach (array_reverse($types) as $type) {
  360. $ret.= newmail_media_object_close($type);
  361. }
  362. $ret.= "<!--> <![endif]-->\n"; // end non-IE mode
  363. // close IE object
  364. $ret.= newmail_media_object_ie_close($types[0]);
  365. return $ret;
  366. }
  367. /**
  368. * Creates object tags of multimedia object for browsers that comply to w3.org
  369. * specifications.
  370. *
  371. * Warnings:
  372. * <ul>
  373. * <li>Returned string does not contain html closing tag.
  374. * <li>This is internal function, use newmail_media_objects() instead
  375. * </ul>
  376. * @link http://www.w3.org/TR/html4/struct/objects.html#edef-OBJECT W3.org specs
  377. * @param string $object object name
  378. * @param integer $type media object type
  379. * @param string $path URL to media object
  380. * @param array $args media object attributes
  381. * @param bool $addsuffix controls addition of suffix to media object url
  382. * @return string object html tags and attributes required by selected media type.
  383. */
  384. function newmail_media_object($object,$type,$path,$args=array(),$addsuffix=true) {
  385. $ret_w3='';
  386. $suffix='';
  387. $sArgs=newmail_media_prepare_args($args);
  388. switch ($type) {
  389. case SM_NEWMAIL_FILETYPE_SWF:
  390. if ($addsuffix) $suffix='.swf';
  391. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  392. .$sArgs
  393. .'type="application/x-shockwave-flash">' . "\n";
  394. break;
  395. case SM_NEWMAIL_FILETYPE_WAV:
  396. if ($addsuffix) $suffix='.wav';
  397. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  398. .$sArgs
  399. .'type="audio/x-wav">' . "\n";
  400. break;
  401. case SM_NEWMAIL_FILETYPE_OGG:
  402. if ($addsuffix) $suffix='.ogg';
  403. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  404. .$sArgs
  405. .'type="application/ogg">' . "\n";
  406. break;
  407. case SM_NEWMAIL_FILETYPE_MP3:
  408. if ($addsuffix) $suffix='.mp3';
  409. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  410. .$sArgs
  411. .'type="audio/mpeg">' . "\n";
  412. break;
  413. case SM_NEWMAIL_FILETYPE_SVG:
  414. if ($addsuffix) $suffix='.svg';
  415. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  416. .$sArgs
  417. .'type="image/svg+xml">' . "\n";
  418. break;
  419. default:
  420. $ret_w3='';
  421. }
  422. return $ret_w3;
  423. }
  424. /**
  425. * Creates multimedia object tags for Internet Explorer (Win32)
  426. *
  427. * Warning:
  428. * * Returned string does not contain html closing tag, because
  429. * this multimedia object can include other media objects.
  430. * * This is internal function, use newmail_media_objects() instead
  431. *
  432. * @param string $object object name
  433. * @param integer $type media object type
  434. * @param string $path URL to media object
  435. * @param array $args media object attributes
  436. * @param bool $addsuffix controls addition of suffix to media object url
  437. * @return string object html tags and attributes required by selected media type.
  438. * @todo add ogg and svg support
  439. */
  440. function newmail_media_object_ie($object,$type,$path,$args=array(),$addsuffix) {
  441. $ret_ie='';
  442. $suffix='';
  443. $sArgs=newmail_media_prepare_args($args);
  444. switch ($type) {
  445. case SM_NEWMAIL_FILETYPE_SWF:
  446. if ($addsuffix) $suffix='.swf';
  447. $ret_ie ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
  448. .'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" '
  449. . $sArgs . 'id="' . $object ."\">\n"
  450. .'<param name="movie" value="' . $path . $object . $suffix . "\">\n"
  451. .'<param name="hidden" value="true">' . "\n";
  452. break;
  453. case SM_NEWMAIL_FILETYPE_WAV:
  454. if ($addsuffix) $suffix='.wav';
  455. $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
  456. .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
  457. . $sArgs . 'id="' . $object ."\" \n"
  458. .'type="audio/x-wav">' ."\n"
  459. .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
  460. break;
  461. case SM_NEWMAIL_FILETYPE_MP3:
  462. if ($addsuffix) $suffix='.mp3';
  463. $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
  464. .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
  465. . $sArgs . 'id="' . $object ."\" \n"
  466. .'type="audio/mpeg">' ."\n"
  467. .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
  468. break;
  469. case SM_NEWMAIL_FILETYPE_OGG:
  470. case SM_NEWMAIL_FILETYPE_SVG:
  471. default:
  472. $ret_ie='';
  473. }
  474. return $ret_ie;
  475. }
  476. /**
  477. * Creates embed tags of multimedia object
  478. *
  479. * docs about embed
  480. * Apple: http://www.apple.com/quicktime/authoring/embed.html
  481. *
  482. * Warnings:
  483. * * Returned string does not contain html closing tag.
  484. * * embed tags will be created by newmail_media_objects() only
  485. * when $newmail_mediacompat_mode option is enabled. Option is not
  486. * enabled by default in order to comply to w3.org specs.
  487. * * This is internal function, use newmail_media_objects() instead
  488. * @link http://www.apple.com/quicktime/authoring/embed.html Info about embed tag
  489. * @param string $object object name
  490. * @param integer $type media object type
  491. * @param string $path URL to media object
  492. * @param array $args media object attributes
  493. * @param bool $addsuffix controls addition of suffix to media object url
  494. * @return string embed html tags and attributes required by selected media type.
  495. */
  496. function newmail_media_embed($object,$type,$path,$args=array(),$addsuffix=true) {
  497. $ret_embed='';
  498. $suffix='';
  499. $sArgs=newmail_media_prepare_args($args);
  500. switch ($type) {
  501. case SM_NEWMAIL_FILETYPE_SWF:
  502. if ($addsuffix) $suffix='.swf';
  503. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  504. .'hidden="true" autostart="true" '. "\n"
  505. .$sArgs . "\n"
  506. .'name="' . $object .'" ' . "\n"
  507. .'type="application/x-shockwave-flash" ' . "\n"
  508. .'pluginspage="http://www.macromedia.com/go/getflashplayer">' . "\n";
  509. break;
  510. case SM_NEWMAIL_FILETYPE_WAV:
  511. if ($addsuffix) $suffix='.wav';
  512. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  513. .' hidden="true" autostart="true" '. "\n"
  514. .' ' .$sArgs . "\n"
  515. .' name="' . $object .'" ' . "\n"
  516. .' type="audio/x-wav">' . "\n";
  517. break;
  518. case SM_NEWMAIL_FILETYPE_SVG:
  519. if ($addsuffix) $suffix='.svg';
  520. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  521. .'hidden="true" autostart="true" '. "\n"
  522. .$sArgs . "\n"
  523. .'name="' . $object .'" ' . "\n"
  524. .'type="image/svg-xml" ' . "\n"
  525. .'pluginspage="http://www.adobe.com/svg/viewer/install/">' . "\n";
  526. break;
  527. case SM_NEWMAIL_FILETYPE_OGG:
  528. if ($addsuffix) $suffix='.ogg';
  529. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  530. .' hidden="true" autostart="true" '. "\n"
  531. .' ' .$sArgs . "\n"
  532. .' name="' . $object .'" ' . "\n"
  533. .' type="application/ogg">' . "\n";
  534. break;
  535. case SM_NEWMAIL_FILETYPE_MP3:
  536. if ($addsuffix) $suffix='.mp3';
  537. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  538. .' hidden="true" autostart="true" '. "\n"
  539. .' ' .$sArgs . "\n"
  540. .' name="' . $object .'" ' . "\n"
  541. .' type="audio/mpeg">' . "\n";
  542. break;
  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. case SM_NEWMAIL_FILETYPE_OGG:
  605. case SM_NEWMAIL_FILETYPE_MP3:
  606. case SM_NEWMAIL_FILETYPE_SVG:
  607. $ret_end="</embed>\n";
  608. break;
  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. ?>