PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.2.0
Brevo – Email, SMS, Web Push, Chat, and more. v3.2.0
2.9.13 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.2 3.1.20 3.1.21 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.1.29 3.1.3 3.1.30 3.1.31 3.1.32 3.1.33 3.1.34 3.1.35 3.1.36 3.1.37 3.1.38 3.1.39 3.1.4 3.1.40 3.1.41 3.1.42 3.1.43 3.1.44 3.1.45 3.1.46 3.1.47 3.1.48 3.1.49 3.1.5 3.1.50 3.1.51 3.1.52 3.1.53 3.1.54 3.1.55 3.1.56 3.1.57 3.1.58 3.1.59 3.1.6 3.1.60 3.1.61 3.1.62 3.1.63 3.1.64 3.1.65 3.1.66 3.1.67 3.1.68 3.1.69 3.1.7 3.1.70 3.1.71 3.1.72 3.1.73 3.1.74 3.1.75 3.1.76 3.1.77 3.1.78 3.1.79 3.1.8 3.1.80 3.1.81 3.1.82 3.1.83 3.1.84 3.1.85 3.1.86 3.1.87 3.1.88 3.1.89 3.1.9 3.1.90 3.1.91 3.1.92 3.1.93 3.1.94 3.1.95 3.1.96 3.1.97 3.1.98 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 trunk 1.0 1.5 2.0.8 2.9.10 2.9.11 2.9.12
mailin / inc / push-httpclient.php
mailin / inc Last commit date
templates 1 year ago SendinblueAccount.php 1 year ago SendinblueApiClient.php 1 year ago function.wp_mail.php 8 years ago http-build-url.php 1 year ago index.php 8 years ago mailin.php 3 years ago push-admin.php 1 year ago push-amp.php 1 year ago push-api.php 1 year ago push-httpclient.php 1 year ago push-public.php 1 year ago push-settings.php 1 year ago push-utils.php 1 year ago push-woocommerce.php 1 year ago sendinblue.php 3 years ago sib-api-manager.php 1 year ago sib-form-preview.php 2 years ago sib-sms-code.php 3 years ago table-forms.php 1 year ago
push-httpclient.php
119 lines
1 <?php
2
3 use WonderPush\Net\Request;
4 use WonderPush\Net\Response;
5
6 /**
7 * An implementation of \WonderPush\Net\HttpClientInterface that uses the Curl shipped with WordPress
8 */
9
10 class SIB_Push_HttpClient implements \WonderPush\Net\HttpClientInterface {
11
12 /** @var WP_Http */
13 var $http;
14 /** @var \WonderPush\WonderPush */
15 var $wp;
16 public function __construct(\WonderPush\WonderPush $wonderPush) {
17 $this->http = new WP_Http();
18 $this->wp = $wonderPush;
19 }
20
21 public function execute(Request $request) {
22 // Construct absolute URL
23 $root = $request->getRoot() ?: $this->wp->getApiRoot();
24 $path = $request->getPath();
25 if (!\WonderPush\Util\StringUtil::beginsWith($path, '/')) {
26 $path = '/' . $path;
27 }
28 $url = $root . $path;
29 $qsParams = $request->getQsParams();
30 $headers = $request->getHeaders();
31 $body = null;
32
33 // Construct $qsParams and $body, and honors $request->getParams() too
34 switch ($request->getMethod()) {
35 case Request::GET:
36 case Request::DELETE:
37 $qsParams = array_merge($qsParams, $request->getParams());
38 break;
39 case Request::PUT:
40 case Request::POST:
41 case Request::PATCH:
42 $body = $request->getParams();
43 $files = $request->getFiles();
44 if (count($files)) {
45 $body = $request->getParams() ?: array();
46 foreach ($files as $name => $file) {
47 $body[$name] = new \CURLFile($file['tmp_name'], $file['type'], $file['name']);
48 }
49 } else if (empty($body)) {
50 $body = null;
51 } else {
52 $headers['Content-Type'] = 'application/json';
53 $options = 0;
54 if (defined('JSON_UNESCAPED_SLASHES')) {
55 $options |= JSON_UNESCAPED_SLASHES;
56 }
57 if (defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
58 $options |= JSON_INVALID_UTF8_SUBSTITUTE;
59 } else if (defined('JSON_PARTIAL_OUTPUT_ON_ERROR')) {
60 $options |= JSON_PARTIAL_OUTPUT_ON_ERROR;
61 }
62 $body = json_encode($body, $options);
63 }
64 break;
65 }
66
67 // Incorporate query string into URL
68 if (!empty($qsParams)) {
69 $prevQs = \WonderPush\Util\UrlUtil::parseQueryString(parse_url($url, PHP_URL_QUERY));
70 $qsParams = array_merge($prevQs, $qsParams);
71 $url = \WonderPush\Util\UrlUtil::replaceQueryStringInUrl($url, $qsParams);
72 }
73
74 if (!isset($headers['User-Agent'])) {
75 $curlVersion = array();
76 if (function_exists("curl_version")) {
77 $curlVersion = curl_version();
78 }
79 $headers['User-Agent'] = 'BrevoPushApi/' . \WonderPush\WonderPush::API_VERSION
80 . ' WonderPushPhpLib/' . \WonderPush\WonderPush::VERSION
81 . ' curl/' . \WonderPush\Util\ArrayUtil::getIfSet($curlVersion, 'version', 'na')
82 . ' ' . \WonderPush\Util\ArrayUtil::getIfSet($curlVersion, 'ssl_version', 'curlssl/na')
83 ;
84 }
85
86 $rawResponse = $this->http->request($url, array(
87 'method' => $request->getMethod() ? strtoupper($request->getMethod()) : 'GET',
88 'headers' => $headers,
89 'body' => $body,
90 ));
91
92 // Parse response
93 $response = new Response();
94 $response->setRequest($request);
95
96 if (is_wp_error($rawResponse)) {
97 $response->setStatusCode(0);
98 } else {
99 $response->setStatusCode(
100 isset($rawResponse['response'])
101 && is_array($rawResponse['response'])
102 && isset($rawResponse['response']['code'])
103 ? $rawResponse['response']['code'] : 0
104 );
105 $response->setRawBody(isset($rawResponse['body']) ? $rawResponse['body'] : null);
106 $responseHeaders = array();
107 // Make a copy of the headers, which is not a regular array but a Requests_Utility_CaseInsensitiveDictionary
108 if (isset($rawResponse['headers'])) {
109 foreach ($rawResponse['headers'] as $key => $val) {
110 $responseHeaders[$key] = $val;
111 }
112 }
113 $response->setHeaders($responseHeaders);
114 }
115 return $response;
116 }
117
118 }
119