home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / admin / ryosimap.inc < prev    next >
Encoding:
Text File  |  2003-05-12  |  7.2 KB  |  286 lines

  1. <?php
  2. /////////////////////////////////////////////////////////
  3. //    
  4. //    include/ryosimap.inc
  5. //
  6. //    (C)Copyright 2000-2002 Ryo Chijiiwa <Ryo@IlohaMail.org>
  7. //
  8. //    This file is part of IlohaMail. IlohaMail is free software released 
  9. //    under the GPL license.  See enclosed file COPYING for details, or 
  10. //    see http://www.fsf.org/copyleft/gpl.html
  11. //
  12. /////////////////////////////////////////////////////////
  13.  
  14. /********************************************************
  15.  
  16.     PURPOSE:
  17.         Legacy library from the "Ryo's Webmail" days.  Contains misc. functions.
  18.     COMMENTS:
  19.         Most of the functions here should eventually be phased out and/or moved to other 
  20.         include's.
  21.  
  22. ********************************************************/
  23.  
  24. function ShowSeen($obj,$true,$false){
  25.     if (($obj->Unseen=='U')||($obj->Recent=='N')){
  26.         return $false;
  27.     }else{
  28.         return $true;
  29.     }
  30. }
  31.  
  32. function ShowBytes($numbytes){
  33.     if ($numbytes > 1024){
  34.         $kb=(int)($numbytes/1024);
  35.         return $kb." KB";
  36.     }else{
  37.         return $numbytes." B";
  38.     }
  39. }
  40.  
  41. function TZDate($tz){
  42.     $server_tz = (int)date("Z");    //server timezone offset in seconds
  43.     $gmt = time() - $server_tz;
  44.     $user_tz = $tz * 60 * 60;         //user tz offset in seconds
  45.     $ts = $gmt + $user_tz;
  46.     
  47.     if ($tz < 0){
  48.         if ($tz > -10){
  49.             $ttz=$tz * -1;
  50.             $tz_string = "-0".$ttz."00";
  51.         }else{
  52.             $tz_string = $tz."00";
  53.         }
  54.     }else if ($tz >= 0){
  55.         if ($tz < 10) $tz_string = "+0".$tz."00";
  56.         else $tz_string = "+".$tz."00";
  57.     }
  58.     return date("D, d M Y H:i:s", $ts)." $tz_string";
  59. }
  60.  
  61. function ShowDate($obj){
  62.     return $obj->date;
  63. }
  64.  
  65. function ShowDate2($str,$cd_a,$mode){
  66.     $pos=strpos($str, ",");
  67.     if ($pos > 0) $str = substr($str, $pos+1);
  68.     $str=trim($str);
  69.     
  70.     $a=explode(" ",$str);
  71.     $month_a=array("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12);
  72.     $month_str=$a[1];
  73.     $month=$month_a[$month_str];
  74.     $day=(int)$a[0];
  75.     $year=(int)$a[2];
  76.     $time=$a[3];
  77.     
  78.     if ($mode=="short"){
  79.         $str = $month."/".$day."/".$year;
  80.     }else if ($mode!="full"){
  81.         if (($cd_a["day"]==$day) && ($cd_a["month"]==$month)){
  82.             $str="";
  83.             $is_today=true;
  84.         }else{
  85.             $str=$month."/".$day;
  86.             $is_today=false;
  87.         }
  88.         if ($cd_a["year"]!=$year) $str.="/".$a[2];
  89.         if ($is_today){
  90.             $ta=explode(":",$time);
  91.             $str.=" ".$ta[0].":".$ta[1]." ".$a[4];
  92.         }
  93.     }
  94.  
  95.     return $str;
  96. }
  97.  
  98. function ShowShortDate($timestamp, $format){
  99.     global $my_prefs;
  100.     
  101.     //get timestamp in user's timezone
  102.     $now = time(); //local time
  103.     $now = $now - date("Z"); //GMT time
  104.     $now = $now + ($my_prefs["timezone"] * 3600); //user's time
  105.  
  106.     $day_secs = 60*((int)date("H", $now)*60 + (int)date("i", $now));
  107.     $week_secs = 60 * 60 * 24 * 7;
  108.     $diff = $now - $timestamp;
  109.     if ($diff < $day_secs){
  110.         $str = $format["today"];
  111.         if (empty($str)) $str="%t";
  112.         $time = LangFormatIntTime(date("Hi", $timestamp), $my_prefs["clock_system"], $format["ampm"], $format["time_format"]);
  113.         $str = str_replace("%t", $time, $str);
  114.         //$str = str_replace("%t", date("H:i", $timestamp), $str);
  115.     }else if ($diff < $week_secs){
  116.         $dsow = $format["dsow"];
  117.         $dow_code = date("w", $timestamp);
  118.         $dow = $dsow[$dow_code];
  119.         //$time = date("H:i", $timestamp);
  120.         $time = LangFormatIntTime(date("Hi", $timestamp), $my_prefs["clock_system"], $format["ampm"], $format["time_format"]);
  121.         $str = $format["lastweek"];
  122.         $str = str_replace("%t", $time, $str);
  123.         $str = str_replace("%w", $dow, $str);
  124.     }else{
  125.         $c_a = getdate();
  126.         $d_a = getdate($timestamp);
  127.         $message_year = $d_a["year"];
  128.         $current_year = $c_a["year"];
  129.         
  130.         if ($message_year != $current_year) $str = $format["prevyears"];
  131.         else $str = $format["thisyear"];
  132.         
  133.         $str = str_replace("%m", $d_a["mon"], $str);
  134.         $str = str_replace("%d", $d_a["mday"], $str);
  135.         $str = str_replace("%y", $d_a["year"], $str);
  136.     }
  137.     return $str;
  138. }
  139.  
  140. function RootedFolderOptions($folders, $defaults, $root){
  141.     if (!empty($root)) $root_len = strlen($root) + 1;
  142.     
  143.     if ($folders == false) {
  144.         echo "Call failed<br>\n";
  145.         return array();
  146.     } else {
  147.         $fa=$defaults;
  148.         reset($fa);
  149.         while (list ($key,$val) = each ($fa)) {
  150.             if (!empty($key)) echo "<option value=\"".$key."\">$val\n";
  151.         }
  152.  
  153.         natcasesort($folders);
  154.            while ( list($k,$folder)=each($folders) ){
  155.             //$folder=$folders[$i];
  156.             if (($fa[$folder]=="") && ($folder[0]!='.') && (!empty($folder))){
  157.                 $folder_name=$folder;
  158.                 if ($root_len > 0){
  159.                     $pos = strpos($folder, $root);
  160.                     if (($pos!==false) && ($pos==0)){
  161.                         $folder_name = substr($folder, $root_len);
  162.                     }
  163.                 }
  164.                 //$folder=$folder;
  165.                 //$fa[$folder]=$folder_name;
  166.                 if ($folder_name[0]!=".") echo "<option value=\"".$folder."\">$folder_name\n";
  167.             }            
  168.         }
  169.     }
  170.     
  171.     //reset($fa);
  172.     //while (list ($key,$val) = each ($fa)) {
  173.     //    if (!empty($key)) echo "<option value=\"".$key."\">$val\n";
  174.     //}
  175. }
  176.  
  177. function FolderOptions3($folders, $defaults){
  178.     if ($folders == false) {
  179.         echo "Call failed<br>\n";
  180.         return array();
  181.     } else {
  182.         natcasesort($folders);
  183.         $fa=$defaults;
  184.         while ( list($k,$folder) = each($folders) ){
  185.             $folder=$folders[$i];
  186.             if (($fa[$folder]=="") && ($folder[0]!='.') && (!empty($folder))){
  187.                 $folder_name=$folder;
  188.                 $folder=$folder;
  189.                 $fa[$folder]=$folder_name;
  190.             }            
  191.         }
  192.     }
  193.     
  194.     reset($fa);
  195.     while (list ($key,$val) = each ($fa)) {
  196.         if (!empty($key)) echo "<option value=\"".$key."\">$val\n";
  197.     }
  198. }
  199.  
  200. function FolderOptions2($folderlist, $default){
  201.     if (is_array($folderlist)){
  202.         natcasesort($folderlist);
  203.         while(list($key,$item)=each($folderlist)){
  204.             if ($item[0]!=".")
  205.                 echo "<option value=\"$item\" ".(strcmp($item, $default)==0?"SELECTED":"").">$item\n";
  206.         }
  207.     }
  208. }
  209.  
  210. function DefaultOptions($folderlist, $default){
  211.     if (is_array($folderlist)){
  212.         natcasesort($folderlist);
  213.         while(list($key,$item)=each($folderlist)){
  214.             if ($item[0]!=".")
  215.                 echo "<option value=\"$key\" ".(strcmp($key, $default)==0?"SELECTED":"").">$item\n";
  216.         }
  217.     }
  218. }
  219.  
  220. function DefaultOptions2($folders, $defaults, $default){
  221.     if ($folders == false) {
  222.         echo "Call failed<br>\n";
  223.         return array();
  224.     } else {
  225.         natcasesort($folders);
  226.         $fa=$defaults;
  227.         while ( list($k,$folder) = each($folders) ){
  228.             $folder=$folders[$i];
  229.             if (($fa[$folder]=="") && ($folder[0]!='.')){
  230.                 $folder_name=$folder;
  231.                 $folder=$folder;
  232.                 $fa[$folder]=$folder_name;
  233.             }            
  234.         }
  235.     }
  236.     
  237.     reset($fa);
  238.     while (list ($key,$val) = each ($fa)) {
  239.         echo "<option value=\"".$key."\" ".(strcmp($key, $default)==0?"SELECTED":"").">".urldecode($val)."\n";
  240.     }
  241. }
  242.  
  243.  
  244. function myWordWrap($string,$num){
  245.     $len=strlen($string);
  246.     $curpos=0;
  247.     $str="";
  248.     
  249.     while (($curpos+$num)<$len){
  250.         $str.=substr($string,$curpos,$num);
  251.         $str.="\n";
  252.         $curpos=$curpos+$num;
  253.     }
  254.     $str.=substr($string,$curpos,$len);
  255.     
  256.     return $str;
  257. }
  258.  
  259. function encodeUTFSafeHTML($str){
  260.     $result = $str;
  261.     $result = str_replace("\"", """, $result);
  262.     $result = str_replace("<", "<", $result);
  263.     $result = str_replace(">", ">", $result);
  264.     
  265.     return $result;
  266. }
  267.  
  268. function encodeHTML($str){
  269.     $result = $str;
  270.     $result = str_replace("&", "&", $result);
  271.     $result = str_replace("<", "<", $result);
  272.     $result = str_replace(">", ">", $result);
  273.     
  274.     return $result;
  275. }
  276.  
  277. function detectURLinWord($word){
  278.     if (ereg("[.]*([fht]+tp[s]*://[a-zA-Z0-9_~#=&%/:;@,\.\?\+-]+)[.]*", $word, $result)){
  279.         return "<a href=\"".$result[0]."\" target=_blank>".htmlspecialchars($word)."</a>";
  280.     }else{
  281.         return encodeHTML($word);
  282.     }
  283. }
  284.  
  285.  
  286. ?>