Subversion Repositories ALCASAR

Rev

Rev 1805 | Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
324 richard 1
<?php
2
function time2str($time)
3
{
4
	$time = floor($time);
5
	if (!$time)
6
		return "0 seconds";
7
	$d = $time/86400;
8
	$d = floor($d);
9
	if ($d){
10
		$str .= "$d days, ";
11
		$time = $time % 86400;
12
	}
13
	$h = $time/3600;
14
	$h = floor($h);
15
	if ($h){
16
		$str .= "$h hours, ";
17
		$time = $time % 3600;
18
	}
19
	$m = $time/60;
20
	$m = floor($m);
21
	if ($m){
22
		$str .= "$m minutes, ";
23
		$time = $time % 60;
24
	}
25
	if ($time)
26
		$str .= "$time seconds, ";
27
	$str = ereg_replace(', $','',$str);
28
 
29
	return $str;
30
}
31
 
32
function time2strclock($time)
33
{
34
	$time = floor($time);
35
	if (!$time)
36
		return "00:00:00";
37
 
38
	$str["days"] = $str["hour"] = $str["min"] = $str["sec"] = "00";
39
 
40
	$d = $time/86400;
41
	$d = floor($d);
42
	if ($d){
43
		if ($d < 10)
44
			$d = "0" . $d;
45
		$str["days"] = "$d";
46
		$time = $time % 86400;
47
	}
48
	$h = $time/3600;
49
	$h = floor($h);
50
	if ($h){
51
		if ($h < 10)
52
			$h = "0" . $h;
53
		$str["hour"] = "$h";
54
		$time = $time % 3600;
55
	}
56
	$m = $time/60;
57
	$m = floor($m);
58
	if ($m){
59
		if ($m < 10)
60
			$m = "0" . $m;
61
		$str["min"] = "$m";
62
		$time = $time % 60;
63
	}
64
	if ($time){
65
		if ($time < 10)
66
			$time = "0" . $time;
67
	}
68
	else
69
		$time = "00";
70
	$str["sec"] = "$time";
71
	if ($str["days"] != "00")
72
		$ret = "$str[days]:$str[hour]:$str[min]:$str[sec]";
73
	else
74
		$ret = "$str[hour]:$str[min]:$str[sec]";
75
 
76
	return $ret;
77
}
78
 
79
function date2timediv($date,$now)
80
{
81
	list($day,$time)=explode(' ',$date);
82
	$day = explode('-',$day);
83
	$time = explode(':',$time);
84
	$timest = mktime($time[0],$time[1],$time[2],$day[1],$day[2],$day[0]);
85
	if (!$now)
86
		$now = time();
87
	return ($now - $timest);
88
}
89
 
90
function date2time($date)
91
{
92
	list($day,$time)=explode(' ',$date);
93
	$day = explode('-',$day);
94
	$time = explode(':',$time);
95
	$timest = mktime($time[0] ?"":0,$time[1],$time[2],$day[1],$day[2],$day[0]);
96
	return $timest;
97
}
98
 
99
function bytes2str($bytes)
100
{
101
	$bytes=floor($bytes);
102
	if ($bytes > 536870912)
103
		$str = sprintf("%5.2f GBs", $bytes/1073741824);
104
	else if ($bytes > 524288)
105
		$str = sprintf("%5.2f MBs", $bytes/1048576);
106
	else
107
		$str = sprintf("%5.2f KBs", $bytes/1024);
108
 
109
	return $str;
110
}
111
 
112
function nothing($ret)
113
{
114
	return $ret;
115
}
116
function check_defaults($val,$op,$def)
117
{
118
	for($i=0;$i<$def[count];$i++){
119
		if ($val == $def[$i] && ($op == '' || $op == $def[operator][$i]))
120
			return 1;
121
	}
122
 
123
	return 0;
124
}
125
 
126
function check_ip($ipaddr) {
127
    if(ereg("^([0-9]{1,3})\x2E([0-9]{1,3})\x2E([0-9]{1,3})\x2E([0-9]{1,3})$", $ipaddr,$digit)) {
128
   	  if(($digit[1] <= 255) && ($digit[2] <= 255) && ($digit[3] <= 255) && ($digit[4] <= 255)) {
129
        return(1);
130
      }
131
    }
132
    return(0);
133
  }
134
 
135
?>