functions.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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_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('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_media_enable,$newmail_popup;
  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_media_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_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
  136. $newmail_userfile_type = getPref($data_dir, $username, 'newmail_userfile_type');
  137. $newmail_userfile_name = getPref($data_dir,$username,'newmail_userfile_name','');
  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,$unseen_notify, $newmail_recent;
  154. //echo "GOT HOOK<br><pre>";
  155. //var_dump($statusarr);
  156. //echo "</pre><br>\n";
  157. $mailbox=$statusarr['MAILBOX'];
  158. if ($newmail_media_enable == 'on' ||
  159. $newmail_popup == 'on' ||
  160. $newmail_changetitle == 'on') {
  161. // Skip folders for Sent and Trash
  162. if ($statusarr['MAILBOX'] == $sent_folder || $statusarr['MAILBOX'] == $trash_folder) {
  163. return 0;
  164. }
  165. if ((($mailbox == 'INBOX') && ($unseen_notify == 2)) || ($unseen_notify == 3)) {
  166. if (($newmail_recent == 'on') && (!empty($statusarr['RECENT']))) {
  167. $totalNewArr[$mailbox] = $statusarr['RECENT'];
  168. } elseif ($newmail_recent != 'on' && !empty($statusarr['UNSEEN'])) {
  169. $totalNewArr[$mailbox] = $statusarr['UNSEEN'];
  170. }
  171. }
  172. }
  173. }
  174. /**
  175. * Insert needed data in left_main
  176. */
  177. function newmail_plugin_function() {
  178. global $username, $newmail_media, $newmail_media_enable, $newmail_popup,
  179. $newmail_recent, $newmail_changetitle, $imapConnection, $PHP_SELF;
  180. global $newmail_mmedia, $newmail_allowsound;
  181. global $newmail_userfile_type;
  182. global $newmail_popup_width, $newmail_popup_height;
  183. global $totalNewArr;
  184. if ($newmail_media_enable == 'on' ||
  185. $newmail_popup == 'on' ||
  186. $newmail_changetitle) {
  187. if (!empty($totalNewArr)) { $totalNew=array_sum($totalNewArr); }
  188. else { $totalNew=0; }
  189. // If we found unseen messages, then we
  190. // will play the sound as follows:
  191. if ($newmail_changetitle) {
  192. echo "<script type=\"text/javascript\">\n" .
  193. "function ChangeTitleLoad() {\n";
  194. echo 'window.parent.document.title = "' .
  195. sprintf(ngettext("%s New Message","%s New Messages",$totalNew), $totalNew) .
  196. "\";\n";
  197. echo "if (BeforeChangeTitle != null)\n".
  198. "BeforeChangeTitle();\n".
  199. "}\n".
  200. "BeforeChangeTitle = window.onload;\n".
  201. "window.onload = ChangeTitleLoad;\n".
  202. "</script>\n";
  203. }
  204. // create media output if there are new email messages
  205. if ($newmail_allowsound && $totalNew > 0
  206. && $newmail_media_enable == 'on'
  207. && $newmail_media != '' ) {
  208. echo newmail_create_media_tags($newmail_media);
  209. }
  210. if ($totalNew > 0 && $newmail_popup == 'on') {
  211. // Idea by: Nic Wolfe (Nic@TimelapseProductions.com)
  212. // Web URL: http://fineline.xs.mw
  213. // More code from Tyler Akins
  214. echo "<script type=\"text/javascript\">\n".
  215. "<!--\n".
  216. "function PopupScriptLoad() {\n".
  217. 'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew.
  218. '", "SMPopup",'.
  219. "\"width=$newmail_popup_width,height=$newmail_popup_height,scrollbars=no\");\n".
  220. "if (BeforePopupScript != null)\n".
  221. "BeforePopupScript();\n".
  222. "}\n".
  223. "BeforePopupScript = window.onload;\n".
  224. "window.onload = PopupScriptLoad;\n".
  225. "// End -->\n".
  226. "</script>\n";
  227. }
  228. }
  229. }
  230. // ----- end of hooked functions -----
  231. /**
  232. * Function tries to detect if file contents match declared file type
  233. *
  234. * Function returns default extension for detected mime type or 'false'
  235. *
  236. * TODO: use $contents to check if file is in specified type
  237. * @param string $contents file contents
  238. * @param string $type file mime type
  239. * @return string
  240. */
  241. function newmail_detect_filetype($contents,$type) {
  242. // convert $type to lower case
  243. $type=strtolower($type);
  244. $ret=false;
  245. switch ($type) {
  246. case 'audio/x-wav':
  247. $ret='wav';
  248. break;
  249. case 'audio/mpeg':
  250. $ret='mp3';
  251. break;
  252. case 'application/ogg':
  253. $ret='ogg';
  254. break;
  255. case 'application/x-shockwave-flash':
  256. $ret='swf';
  257. break;
  258. case 'image/svg+xml':
  259. $ret='svg';
  260. break;
  261. default:
  262. $ret=false;
  263. }
  264. return $ret;
  265. }
  266. /**
  267. * Function tries to detect uploaded file type
  268. * @param string $type
  269. * @param string $filename
  270. * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
  271. */
  272. function newmail_get_mediatype($type,$filename) {
  273. switch ($type) {
  274. // fix for browser's that upload file as application/octet-stream
  275. case 'application/octet-stream':
  276. $ret=newmail_get_mediatype_by_ext($filename);
  277. break;
  278. case 'audio/x-wav':
  279. $ret=SM_NEWMAIL_FILETYPE_WAV;
  280. break;
  281. case 'audio/mpeg':
  282. $ret=SM_NEWMAIL_FILETYPE_MP3;
  283. break;
  284. case 'application/ogg':
  285. $ret=SM_NEWMAIL_FILETYPE_OGG;
  286. break;
  287. case 'application/x-shockwave-flash':
  288. $ret=SM_NEWMAIL_FILETYPE_SWF;
  289. break;
  290. case 'image/svg+xml':
  291. $ret=SM_NEWMAIL_FILETYPE_SVG;
  292. break;
  293. default:
  294. $ret=false;
  295. }
  296. return $ret;
  297. }
  298. /**
  299. * Function provides filetype detection for browsers, that
  300. * upload files with application/octet-stream file type.
  301. * Ex. some version of Opera.
  302. * @param string $filename
  303. * @return integer One of SM_NEWMAIL_FILETYPE_* defines or false.
  304. */
  305. function newmail_get_mediatype_by_ext($filename) {
  306. if (preg_match("/\.wav$/i",$filename)) return SM_NEWMAIL_FILETYPE_WAV;
  307. if (preg_match("/\.mp3$/i",$filename)) return SM_NEWMAIL_FILETYPE_MP3;
  308. if (preg_match("/\.ogg$/i",$filename)) return SM_NEWMAIL_FILETYPE_OGG;
  309. if (preg_match("/\.swf$/i",$filename)) return SM_NEWMAIL_FILETYPE_SWF;
  310. if (preg_match("/\.svg$/i",$filename)) return SM_NEWMAIL_FILETYPE_SVG;
  311. return false;
  312. }
  313. /**
  314. * Creates html object tags of multimedia object
  315. *
  316. * Main function that creates multimedia object tags
  317. * @param string $object object name
  318. * @param integer $type media object type
  319. * @param string $path URL to media object
  320. * @param array $args media object attributes
  321. * @param string $extra tags that have to buried deep inside object tags
  322. * @param bool $addsuffix controls addition of suffix to media object url
  323. * @return string object html tags and attributes required by selected media type.
  324. */
  325. function newmail_media_objects($object,$types,$path,$args=array(),$extra='',$addsuffix=true) {
  326. global $newmail_mediacompat_mode;
  327. // first prepare single object for IE
  328. $ret = newmail_media_object_ie($object,$types[0],$path,$args,$addsuffix);
  329. // W3.org nested objects
  330. $ret.= "<!--[if !IE]> <-->\n"; // not for IE
  331. foreach ($types as $type) {
  332. $ret.= newmail_media_object($object,$type,$path,$args,$addsuffix);
  333. }
  334. if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
  335. $ret.= newmail_media_embed($object,$types[0],$path,$args,$addsuffix);
  336. // add $extra code inside objects
  337. if ($extra!='')
  338. $ret.=$extra . "\n";
  339. // close embed tags
  340. if (isset($newmail_mediacompat_mode) && $newmail_mediacompat_mode)
  341. $ret.= newmail_media_embed_close($types[0]);
  342. // close w3.org nested objects
  343. foreach (array_reverse($types) as $type) {
  344. $ret.= newmail_media_object_close($type);
  345. }
  346. $ret.= "<!--> <![endif]-->\n"; // end non-IE mode
  347. // close IE object
  348. $ret.= newmail_media_object_ie_close($types[0]);
  349. return $ret;
  350. }
  351. /**
  352. * Creates object tags of multimedia object for browsers that comply to w3.org
  353. * specifications.
  354. *
  355. * Warnings:
  356. * <ul>
  357. * <li>Returned string does not contain html closing tag.
  358. * <li>This is internal function, use newmail_media_objects() instead
  359. * </ul>
  360. * @link http://www.w3.org/TR/html4/struct/objects.html#edef-OBJECT W3.org specs
  361. * @param string $object object name
  362. * @param integer $type media object type
  363. * @param string $path URL to media object
  364. * @param array $args media object attributes
  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_object($object,$type,$path,$args=array(),$addsuffix=true) {
  369. $ret_w3='';
  370. $suffix='';
  371. $sArgs=newmail_media_prepare_args($args);
  372. switch ($type) {
  373. case SM_NEWMAIL_FILETYPE_SWF:
  374. if ($addsuffix) $suffix='.swf';
  375. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  376. .$sArgs
  377. .'type="application/x-shockwave-flash">' . "\n";
  378. break;
  379. case SM_NEWMAIL_FILETYPE_WAV:
  380. if ($addsuffix) $suffix='.wav';
  381. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  382. .$sArgs
  383. .'type="audio/x-wav">' . "\n";
  384. break;
  385. case SM_NEWMAIL_FILETYPE_OGG:
  386. if ($addsuffix) $suffix='.ogg';
  387. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  388. .$sArgs
  389. .'type="application/ogg">' . "\n";
  390. break;
  391. case SM_NEWMAIL_FILETYPE_MP3:
  392. if ($addsuffix) $suffix='.mp3';
  393. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  394. .$sArgs
  395. .'type="audio/mpeg">' . "\n";
  396. break;
  397. case SM_NEWMAIL_FILETYPE_SVG:
  398. if ($addsuffix) $suffix='.svg';
  399. $ret_w3 = '<object data="' . $path . $object . $suffix . '" '
  400. .$sArgs
  401. .'type="image/svg+xml">' . "\n";
  402. break;
  403. default:
  404. $ret_w3='';
  405. }
  406. return $ret_w3;
  407. }
  408. /**
  409. * Creates multimedia object tags for Internet Explorer (Win32)
  410. *
  411. * Warning:
  412. * * Returned string does not contain html closing tag, because
  413. * this multimedia object can include other media objects.
  414. * * This is internal function, use newmail_media_objects() instead
  415. *
  416. * @param string $object object name
  417. * @param integer $type media object type
  418. * @param string $path URL to media object
  419. * @param array $args media object attributes
  420. * @param bool $addsuffix controls addition of suffix to media object url
  421. * @return string object html tags and attributes required by selected media type.
  422. * @todo add ogg and svg support
  423. */
  424. function newmail_media_object_ie($object,$type,$path,$args=array(),$addsuffix) {
  425. $ret_ie='';
  426. $suffix='';
  427. $sArgs=newmail_media_prepare_args($args);
  428. switch ($type) {
  429. case SM_NEWMAIL_FILETYPE_SWF:
  430. if ($addsuffix) $suffix='.swf';
  431. $ret_ie ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
  432. .'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" '
  433. . $sArgs . 'id="' . $object ."\">\n"
  434. .'<param name="movie" value="' . $path . $object . $suffix . "\">\n"
  435. .'<param name="hidden" value="true">' . "\n";
  436. break;
  437. case SM_NEWMAIL_FILETYPE_WAV:
  438. if ($addsuffix) $suffix='.wav';
  439. $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
  440. .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
  441. . $sArgs . 'id="' . $object ."\" \n"
  442. .'type="audio/x-wav">' ."\n"
  443. .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
  444. break;
  445. case SM_NEWMAIL_FILETYPE_MP3:
  446. if ($addsuffix) $suffix='.mp3';
  447. $ret_ie ='<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '
  448. .'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,0902" '
  449. . $sArgs . 'id="' . $object ."\" \n"
  450. .'type="audio/mpeg">' ."\n"
  451. .'<param name="FileName" value="' . $path . $object . $suffix . "\">\n";
  452. break;
  453. case SM_NEWMAIL_FILETYPE_OGG:
  454. case SM_NEWMAIL_FILETYPE_SVG:
  455. default:
  456. $ret_ie='';
  457. }
  458. return $ret_ie;
  459. }
  460. /**
  461. * Creates embed tags of multimedia object
  462. *
  463. * docs about embed
  464. * Apple: http://www.apple.com/quicktime/authoring/embed.html
  465. *
  466. * Warnings:
  467. * * Returned string does not contain html closing tag.
  468. * * embed tags will be created by newmail_media_objects() only
  469. * when $newmail_mediacompat_mode option is enabled. Option is not
  470. * enabled by default in order to comply to w3.org specs.
  471. * * This is internal function, use newmail_media_objects() instead
  472. * @link http://www.apple.com/quicktime/authoring/embed.html Info about embed tag
  473. * @param string $object object name
  474. * @param integer $type media object type
  475. * @param string $path URL to media object
  476. * @param array $args media object attributes
  477. * @param bool $addsuffix controls addition of suffix to media object url
  478. * @return string embed html tags and attributes required by selected media type.
  479. */
  480. function newmail_media_embed($object,$type,$path,$args=array(),$addsuffix=true) {
  481. $ret_embed='';
  482. $suffix='';
  483. $sArgs=newmail_media_prepare_args($args);
  484. switch ($type) {
  485. case SM_NEWMAIL_FILETYPE_SWF:
  486. if ($addsuffix) $suffix='.swf';
  487. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  488. .'hidden="true" autostart="true" '. "\n"
  489. .$sArgs . "\n"
  490. .'name="' . $object .'" ' . "\n"
  491. .'type="application/x-shockwave-flash" ' . "\n"
  492. .'pluginspage="http://www.macromedia.com/go/getflashplayer">' . "\n";
  493. break;
  494. case SM_NEWMAIL_FILETYPE_WAV:
  495. if ($addsuffix) $suffix='.wav';
  496. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  497. .' hidden="true" autostart="true" '. "\n"
  498. .' ' .$sArgs . "\n"
  499. .' name="' . $object .'" ' . "\n"
  500. .' type="audio/x-wav">' . "\n";
  501. break;
  502. case SM_NEWMAIL_FILETYPE_SVG:
  503. if ($addsuffix) $suffix='.svg';
  504. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  505. .'hidden="true" autostart="true" '. "\n"
  506. .$sArgs . "\n"
  507. .'name="' . $object .'" ' . "\n"
  508. .'type="image/svg-xml" ' . "\n"
  509. .'pluginspage="http://www.adobe.com/svg/viewer/install/">' . "\n";
  510. break;
  511. case SM_NEWMAIL_FILETYPE_OGG:
  512. if ($addsuffix) $suffix='.ogg';
  513. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  514. .' hidden="true" autostart="true" '. "\n"
  515. .' ' .$sArgs . "\n"
  516. .' name="' . $object .'" ' . "\n"
  517. .' type="application/ogg">' . "\n";
  518. break;
  519. case SM_NEWMAIL_FILETYPE_MP3:
  520. if ($addsuffix) $suffix='.mp3';
  521. $ret_embed='<embed src="' . $path . $object . $suffix . '" '. "\n"
  522. .' hidden="true" autostart="true" '. "\n"
  523. .' ' .$sArgs . "\n"
  524. .' name="' . $object .'" ' . "\n"
  525. .' type="audio/mpeg">' . "\n";
  526. break;
  527. default:
  528. $ret_embed='';
  529. }
  530. return $ret_embed;
  531. }
  532. /**
  533. * Adds closing tags for ie object
  534. * Warning:
  535. * * This is internal function, use newmail_media_objects() instead
  536. * @param integer $type media object type
  537. * @return string closing tag of media object
  538. */
  539. function newmail_media_object_ie_close($type) {
  540. $ret_end='';
  541. switch ($type) {
  542. case SM_NEWMAIL_FILETYPE_SWF:
  543. case SM_NEWMAIL_FILETYPE_WAV:
  544. case SM_NEWMAIL_FILETYPE_MP3:
  545. $ret_end="</object>\n";
  546. break;
  547. case SM_NEWMAIL_FILETYPE_OGG:
  548. case SM_NEWMAIL_FILETYPE_SVG:
  549. default:
  550. $ret_end='';
  551. }
  552. return $ret_end;
  553. }
  554. /**
  555. * Adds closing tags for object
  556. * Warning:
  557. * * This is internal function, use newmail_media_objects() instead
  558. * @param integer $type media object type
  559. * @return string closing tag of media object
  560. */
  561. function newmail_media_object_close($type) {
  562. $ret_end='';
  563. switch ($type) {
  564. case SM_NEWMAIL_FILETYPE_SWF:
  565. case SM_NEWMAIL_FILETYPE_WAV:
  566. case SM_NEWMAIL_FILETYPE_OGG:
  567. case SM_NEWMAIL_FILETYPE_MP3:
  568. case SM_NEWMAIL_FILETYPE_SVG:
  569. $ret_end="</object>\n";
  570. break;
  571. default:
  572. $ret_end='';
  573. }
  574. return $ret_end;
  575. }
  576. /**
  577. * Adds closing tags for object
  578. * Warning:
  579. * * This is internal function, use newmail_media_objects() instead
  580. * @param integer $type media object type
  581. * @return string closing tag of media object
  582. */
  583. function newmail_media_embed_close($type) {
  584. $ret_end='';
  585. switch ($type) {
  586. case SM_NEWMAIL_FILETYPE_SWF:
  587. case SM_NEWMAIL_FILETYPE_WAV:
  588. case SM_NEWMAIL_FILETYPE_OGG:
  589. case SM_NEWMAIL_FILETYPE_MP3:
  590. case SM_NEWMAIL_FILETYPE_SVG:
  591. $ret_end="</embed>\n";
  592. break;
  593. default:
  594. $ret_end='';
  595. }
  596. return $ret_end;
  597. }
  598. /**
  599. * Converts media attributes to string
  600. * Warning:
  601. * * attribute values are automatically sanitized by htmlspecialchars()
  602. * * This is internal function, use newmail_media_objects() instead
  603. * @param array $args array with object attributes
  604. * @return string string with object attributes
  605. */
  606. function newmail_media_prepare_args($args) {
  607. $ret_args='';
  608. foreach ($args as $arg => $value) {
  609. $ret_args.= $arg . '="' . htmlspecialchars($value) . '" ';
  610. }
  611. return $ret_args;
  612. }
  613. /**
  614. * Detects used media type and creates all need tags
  615. * @param string $newmail_media
  616. * @return string html tags with media objects
  617. */
  618. function newmail_create_media_tags($newmail_media) {
  619. global $newmail_mmedia, $newmail_userfile_type;
  620. if (preg_match("/^mmedia_+/",$newmail_media)) {
  621. $ret_media = "<!-- newmail mmedia option -->\n";
  622. // remove mmedia key
  623. $newmail_mmedia_short=preg_replace("/^mmedia_/",'',$newmail_media);
  624. // check if media option is not removed
  625. if (isset($newmail_mmedia[$newmail_mmedia_short])) {
  626. $ret_media.= newmail_media_objects($newmail_mmedia_short,
  627. $newmail_mmedia[$newmail_mmedia_short]['types'],
  628. sqm_baseuri() . 'plugins/newmail/media/',
  629. $newmail_mmedia[$newmail_mmedia_short]['args']);
  630. }
  631. $ret_media.= "<!-- end of newmail mmedia option -->\n";
  632. } elseif ($newmail_media=='(userfile)') {
  633. $ret_media = "<!-- newmail usermedia option -->\n";
  634. $ret_media.= newmail_media_objects('loadfile.php',
  635. array($newmail_userfile_type),
  636. sqm_baseuri() . 'plugins/newmail/',
  637. array('width'=>0,'height'=>0),
  638. '',false);
  639. $ret_media.= "<!-- end of newmail usermedia option -->\n";
  640. } else {
  641. $ret_media = "<!-- newmail sounds from sounds/*.wav -->\n";
  642. $ret_media.= newmail_media_objects(basename($newmail_media),
  643. array(SM_NEWMAIL_FILETYPE_WAV),
  644. sqm_baseuri() . 'plugins/newmail/sounds/',
  645. array('width'=>0,'height'=>0),
  646. '',false);
  647. $ret_media.= "<!-- end of newmail sounds from sounds/*.wav -->\n";
  648. }
  649. return $ret_media;
  650. }
  651. ?>