-
Notifications
You must be signed in to change notification settings - Fork 12
/
thestuff.php
53 lines (49 loc) · 1.87 KB
/
thestuff.php
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
<?php
class status {
public function performAction($url,$key,$hash,$action) {
//$action = "status";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . "/command.php?key=".$key."&hash=".$hash."&action=".$action."&ipaddr=true&bw=true&mem=true&hdd=true");
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
// Parse the returned data and build an array
preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $match);
$result = array();
foreach ($match[1] as $x => $y){
$result[$y] = $match[2][$x];
}
return $result;
}
// formatBytes from here: http://stackoverflow.com/a/2510459/710233
public function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
// Uncomment one of the following alternatives
// $bytes /= pow(1024, $pow);
$bytes /= (1 << (10 * $pow));
return round($bytes, $precision) . ' ' . $units[$pow];
}
function googl_shortlink($url) {
$http = new WP_Http();
$headers = array('Content-Type' => 'application/json');
$result = $http->request('https://www.googleapis.com/urlshortener/v1/url', array( 'method' => 'POST', 'body' => '{"longUrl": "' . $url . '"}', 'headers' => $headers));
$result = json_decode($result['body']);
$shortlink = $result->id;
if ($shortlink) {
add_post_meta($post_id, '_googl_shortlink', $shortlink, true);
return $shortlink;
}
else {
return $url;
}
}
}
?>