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 / Curl.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
Curl.php
100 lines
1 <?php
2
3 namespace BackupGuard;
4
5 require_once(dirname(__FILE__).'/RequestHandler.php');
6
7 class Curl extends RequestHandler
8 {
9 private $handle = null;
10
11 public function __construct($url)
12 {
13 parent::__construct($url);
14
15 $this->handle = curl_init();
16
17 $this->set(CURLOPT_SSL_VERIFYPEER, false);
18 $this->set(CURLOPT_SSL_VERIFYHOST, 0);
19 $this->set(CURLOPT_SSLVERSION, 1);
20 $this->set(CURLOPT_RETURNTRANSFER, true);
21 $this->set(CURLOPT_CONNECTTIMEOUT, 10);
22 $this->set(CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0');
23
24 $this->addHeader('Content-type: application/x-www-form-urlencoded');
25 }
26
27 public function post()
28 {
29 $this->set(CURLOPT_POST, true);
30
31 if (count($this->params)) {
32 $this->set(CURLOPT_POSTFIELDS, http_build_query($this->params, '', '&'));
33 }
34
35 return $this->sendRequest('POST');
36 }
37
38 public function get()
39 {
40 $this->set(CURLOPT_HTTPGET, true);
41 return $this->sendRequest('GET');
42 }
43
44 private function sendRequest($type)
45 {
46 $url = $this->url;
47
48 //prepare url for get request
49 if ($type == 'GET' && count($this->params)) {
50 $url = rtrim($url, '/').'/';
51
52 if ($this->getWithQueryParams) { //standard get url, with query params
53 $url .= '?'.http_build_query($this->params, '', '&');
54 }
55 else { //mvs-styled get url
56 $url .= implode('/', array_values($this->params));
57 }
58 }
59
60 $this->set(CURLOPT_URL, $url);
61 if (!empty($this->headers)) {
62 $this->set(CURLOPT_HTTPHEADER, $this->headers);
63 }
64
65 $body = curl_exec($this->handle);
66
67 if ($body !== false) {
68 $this->body = $body;
69 $info = curl_getinfo($this->handle);
70 $this->setResponseInfo($info);
71 return $this->parseResponse();
72 }
73
74 return false;
75 }
76
77 public function set($option, $value)
78 {
79 curl_setopt($this->handle, $option, $value);
80 }
81
82 public function __destruct()
83 {
84 if ($this->handle) {
85 curl_close($this->handle);
86 }
87 }
88
89 private function setResponseInfo($info)
90 {
91 if (isset($info['http_code'])) {
92 $this->httpCode = $info['http_code'];
93 }
94
95 if (isset($info['content_type'])) {
96 $this->contentType = $info['content_type'];
97 }
98 }
99 }
100