Source for file functions.php

Documentation is available at functions.php

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

Documentation generated on Mon, 13 Jan 2020 04:22:36 +0100 by phpDocumentor 1.4.3