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

Documentation generated on Sat, 07 Oct 2006 16:11:22 +0300 by phpDocumentor 1.3.0RC6