forked from g2x3k/php-irc
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php
More file actions
130 lines (111 loc) · 4.69 KB
/
functions.php
File metadata and controls
130 lines (111 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?
function get_size($path)
{
if(!is_dir($path)) return filesize($path);
if (($handle = opendir($path)) != FALSE) {
$size = 0;
while (false !== ($file = readdir($handle))) {
if($file!='.' && $file!='..') {
// function filesize has been deleted
$size += get_size($path.'/'.$file);
}
}
closedir($handle);
return $size;
}
}
function timeDiff($starttime, $endtime=false , $detailed=true, $short = true){
if ($endtime == false) {
$endtime = time();
}
if(!is_int($starttime)) $starttime = strtotime($starttime);
if(!is_int($endtime)) $endtime = strtotime($endtime);
$diff = ($starttime >= $endtime ? $starttime - $endtime : $endtime - $starttime);
# Set the periods of time
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
if($short){
$periods = array("s", "m", "h", "d", "m", "y");
$lengths = array(1, 60, 3600, 86400, 2630880, 31570560);
}
# Go from decades backwards to seconds
$i = sizeof($lengths) - 1; # Size of the lengths / periods in case you change them
$time = ""; # The string we will hold our times in
while($i >= 0) {
if($diff > @$lengths[$i-1]) { # if the difference is greater than the length we are checking... continue
@$val = @floor(@$diff / @$lengths[@$i-1]); # 65 / 60 = 1. That means one minute. 130 / 60 = 2. Two minutes.. etc
$time .= $val . ($short ? '' : ' ') . $periods[$i-1] . ((!$short && $val > 1) ? 's ' : ' '); # The value, then the name associated, then add 's' if plural
$diff -= ($val * $lengths[$i-1]); # subtract the values we just used from the overall diff so we can find the rest of the information
if(!$detailed) { $i = 0; } # if detailed is turn off (default) only show the first set found, else show all information
}
$i--;
}
return trim($time);
}
function secDiff ($starttime, $endtime = false) {
if ($endtime == false) {
$endtime = time();
}
if(!is_int($starttime)) $starttime = strtotime($starttime);
if(!is_int($endtime)) $endtime = strtotime($endtime);
$diff = ($starttime >= $endtime ? $starttime - $endtime : $endtime - $starttime);
return $diff;
}
function sqlesc($x) {
return "'".mysql_real_escape_string($x)."'";
}
function get_url_contents($url,$post=false,$ref=false,$timeout=10){
global $urlconf;
$crl = curl_init();
$header[] = "Connection: keep-alive";
$header[] = "keep-alive: $timeout";
//$header[] = "Accept: text/html,application/xhtml+xml,application/xml, image/gif, image/x-bitmap, image/jpeg, image/pjpeg, image/jpg;q=0.9,*/*;q=0.8";
$header[] = "Accept: */* ;q=0.9,*/*;q=0.8";
$header[] = "Accept-Language: en-gb,en;q=0.5";
$header[] = "Accept-Encoding: gzip,deflate";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Pragma: "; // browsers keep this blank.
//if ($urlconf["usecookies"]) {
/* $cookie = './cookies/cookie.txt';
if (!file_exists("./cookies")) mkdir("./cookies");
if (!file_exists($cookie)) die("i want cookies");
curl_setopt($crl, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($crl, CURLOPT_COOKIEJAR, $cookie);
*/
curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($crl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($crl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3');
//curl_setopt($crl, CURLOPT_HTTPHEADER, $header);
curl_setopt($crl, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($crl, CURLOPT_URL,$url);
curl_setopt($crl, CURLOPT_VERBOSE, false);
curl_setopt($crl, CURLOPT_HEADER, false);
curl_setopt($crl, CURLOPT_ENCODING, "");
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_SSL_VERIFYPEER, false);
if ($ref != false)
curl_setopt($crl, CURLOPT_REFERER, $ref);
curl_setopt($crl, CURLOPT_AUTOREFERER, 1);
if ($post != false) {
$postvars = $post;
curl_setopt($crl, CURLOPT_POSTFIELDS, $postvars);
}
$ret["html"] = curl_exec($crl);
$ret["url"] = curl_getinfo($crl, CURLINFO_EFFECTIVE_URL);
$ret["speed"] = curl_getinfo($crl, CURLINFO_SPEED_DOWNLOAD);
$ret["size"] = curl_getinfo($crl, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
$ret["type"] = curl_getinfo($crl, CURLINFO_CONTENT_TYPE);
echo "\r\n - REQUEST - ". curl_getinfo($crl, CURLINFO_HEADER_OUT)."\r\n";
$ret["redirtime"] = number_format(curl_getinfo($crl, CURLINFO_REDIRECT_TIME), 2);
$ret["dnslookup"] = number_format(curl_getinfo($crl, CURLINFO_NAMELOOKUP_TIME), 2);
$ret["connection"] = number_format(curl_getinfo($crl, CURLINFO_CONNECT_TIME), 2);
curl_close($crl);
return $ret;
}
function GetJsonFeed($json_url)
{
$feed = file_get_contents($json_url);
return json_decode($feed, true);
}
?>