PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.3.4
JetBackup – Backup, Restore & Migrate v1.3.4
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / com / lib / BackupGuard / Stream.php
backup / com / lib / BackupGuard Last commit date
Exception 6 years ago Client.php 6 years ago Config.php 6 years ago Curl.php 6 years ago Helper.php 6 years ago RequestHandler.php 6 years ago Response.php 6 years ago Stream.php 6 years ago
Stream.php
116 lines
1 <?php
2
3 namespace BackupGuard;
4
5 require_once(dirname(__FILE__).'/RequestHandler.php');
6
7 class Stream extends RequestHandler
8 {
9 public function __construct($url)
10 {
11 parent::__construct($url);
12
13 $this->addHeader('Content-type: application/x-www-form-urlencoded');
14 }
15
16 public function post()
17 {
18 return $this->sendRequest('POST');
19 }
20
21 public function get()
22 {
23 return $this->sendRequest('GET');
24 }
25
26 private function sendRequest($type)
27 {
28 //prepare headers
29 $headers = '';
30 if (count($this->headers)) {
31 $headers = implode("\r\n", $this->headers);
32 $headers .= "\r\n";
33 }
34
35 //set http request method
36 $opts = array(
37 'http' => array(
38 'method' => $type,
39 'user_agent' => 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0',
40 'ignore_errors' => '1'
41 )
42 );
43
44 //set headers
45 if ($headers) {
46 $opts['http']['header'] = $headers;
47 }
48
49 $url = $this->url;
50
51 //set params
52 if (count($this->params)) {
53 $data = http_build_query($this->params, '', '&');
54
55 if ($type == 'GET') { //set params inside url
56 $url = rtrim($url, '/').'/';
57
58 if ($this->getWithQueryParams) { //standard get url, with query params
59 $url .= '?'.http_build_query($this->params, '', '&');
60 }
61 else { //mvs-styled get url
62 $url .= implode('/', array_values($this->params));
63 }
64 }
65 else if ($type == 'POST') {
66 $opts['http']['content'] = $data;
67 }
68 }
69
70 $context = @stream_context_create($opts);
71 $fp = @fopen($url, 'r', false, $context);
72
73 if (isset($http_response_header)) {
74 $this->setResponseInfo($http_response_header);
75 }
76
77 if ($fp) {
78 $this->body = @stream_get_contents($fp);
79 @fclose($fp);
80 }
81
82 return $this->parseResponse();
83 }
84
85 private function parseHTTPHeaders($headers)
86 {
87 $head = array();
88 foreach($headers as $k => $v) {
89 $t = explode(':', $v, 2);
90 if (isset($t[1])) {
91 $head[trim($t[0])] = trim($t[1]);
92 }
93 else {
94 $head[] = $v;
95 if (preg_match("#HTTP/[0-9\.]+\s+([0-9]+)#", $v, $out)) {
96 $head['reponse_code'] = intval($out[1]);
97 }
98 }
99 }
100 return $head;
101 }
102
103 private function setResponseInfo($info)
104 {
105 $info = $this->parseHTTPHeaders($info);
106
107 if (isset($info['reponse_code'])) {
108 $this->httpCode = $info['reponse_code'];
109 }
110
111 if (isset($info['Content-Type'])) {
112 $this->contentType = $info['Content-Type'];
113 }
114 }
115 }
116