PluginProbe ʕ •ᴥ•ʔ
Rich Showcase for Google Reviews / 1.6
Rich Showcase for Google Reviews v1.6
6.9.7 6.9.6 trunk 1.4 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.5 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.7 1.6.8 1.6.9 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.4 2.4.1 2.4.2 2.5 2.5.1 2.6 2.6.1 2.6.2 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.6.1 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.8.1 4.8.2 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.7.1 5.8 5.9 5.9.1 5.9.2 5.9.3 5.9.7 6.0 6.1 6.2 6.3 6.4 6.4.1 6.5 6.6 6.6.1 6.6.2 6.7 6.8 6.8.1 6.8.2 6.9 6.9.1 6.9.2 6.9.3 6.9.4 6.9.4.1 6.9.4.2 6.9.4.3 6.9.4.4 6.9.5
widget-google-reviews / api / urlopen.php
widget-google-reviews / api Last commit date
json.php 9 years ago urlopen.php 9 years ago
urlopen.php
249 lines
1 <?php
2
3 if (!function_exists('rplg_urlopen')) {
4
5 define('RPLG_USER_AGENT', 'RPLG-WPPlugin/1.0');
6 define('RPLG_SOCKET_TIMEOUT', 10);
7
8 if (!extension_loaded('json')) {
9 require_once(dirname(__FILE__) . '/json.php');
10 function rplg_json_decode($data) {
11 $json = new JSON;
12 return $json->unserialize($data);
13 }
14 } else {
15 function rplg_json_decode($data) {
16 return json_decode($data);
17 }
18 }
19
20 function rplg_json_urlopen($url, $postdata=false, $headers=array()) {
21 if (!($response = rplg_urlopen($url, $postdata, $headers)) || !$response['code']) {
22 //$this->last_error = 'COULDNT_CONNECT';
23 return false;
24 }
25 return rplg_json_decode($response['data']);
26 }
27
28 function rplg_urlopen($url, $postdata=false, $headers=array()) {
29 $response = array(
30 'data' => '',
31 'code' => 0
32 );
33
34 $url = preg_replace('/\s+/', '+', $url);
35
36 if(function_exists('curl_init')) {
37 if (!function_exists('curl_setopt_array')) {
38 function curl_setopt_array(&$ch, $curl_options) {
39 foreach ($curl_options as $option => $value) {
40 if (!curl_setopt($ch, $option, $value)) {
41 return false;
42 }
43 }
44 return true;
45 }
46 }
47 _rplg_curl_urlopen($url, $postdata, $headers, $response);
48 } else if(ini_get('allow_url_fopen') && function_exists('stream_get_contents')) {
49 _rplg_fopen_urlopen($url, $postdata, $headers, $response);
50 } else {
51 _rplg_fsockopen_urlopen($url, $postdata, $headers, $response);
52 }
53 return $response;
54 }
55
56 /*-------------------------------- curl --------------------------------*/
57 function _rplg_curl_urlopen($url, $postdata, $headers, &$response) {
58 $c = curl_init($url);
59 $postdata_str = rplg_get_query_string($postdata);
60
61 $c_options = array(
62 CURLOPT_USERAGENT => RPLG_USER_AGENT,
63 CURLOPT_RETURNTRANSFER => true,
64 CURLOPT_POST => ($postdata_str ? 1 : 0),
65 CURLOPT_HEADER => true,
66 CURLOPT_HTTPHEADER => array_merge(array('Expect:'), $headers),
67 CURLOPT_TIMEOUT => RPLG_SOCKET_TIMEOUT
68 );
69 if($postdata) {
70 $c_options[CURLOPT_POSTFIELDS] = $postdata_str;
71 }
72 curl_setopt_array($c, $c_options);
73
74 $open_basedir = ini_get('open_basedir');
75 if(empty($open_basedir) && filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN) === false) {
76 curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
77 }
78 curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
79
80 $data = curl_exec($c);
81
82 // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string
83 if (stripos($data, "HTTP/1.0 200 Connection established\r\n\r\n") !== false) {
84 $data = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $data);
85 }
86
87 list($resp_headers, $response['data']) = explode("\r\n\r\n", $data, 2);
88
89 $response['headers'] = _rplg_get_response_headers($resp_headers, $response);
90 $response['code'] = curl_getinfo($c, CURLINFO_HTTP_CODE);
91 curl_close($c);
92 }
93
94 /*-------------------------------- fopen --------------------------------*/
95 function _rplg_fopen_urlopen($url, $postdata, $headers, &$response) {
96 $params = array();
97
98 if($postdata) {
99 $params = array('http' => array(
100 'method' => 'POST',
101 'header' => implode("\r\n", array_merge(array('Content-Type: application/x-www-form-urlencoded'), $headers)),
102 'content' => rplg_get_query_string($postdata),
103 'timeout' => RPLG_SOCKET_TIMEOUT
104 ));
105 } else {
106 $params = array('http' => array(
107 'header' => implode("\r\n", $headers)
108 ));
109 }
110
111 ini_set('user_agent', RPLG_USER_AGENT);
112 $ctx = stream_context_create($params);
113 $fp = fopen($url, 'rb', false, $ctx);
114 if(!$fp) { return false; }
115
116 list($unused, $response['code'], $unused) = explode(' ', $http_response_header[0], 3);
117 $resp_headers = array_slice($http_response_header, 1);
118
119 foreach($resp_headers as $unused=>$header) {
120 $header = explode(':', $header);
121 $header[0] = trim($header[0]);
122 $header[1] = trim($header[1]);
123 $resp_headers[strtolower($header[0])] = strtolower($header[1]);
124 }
125 $response['data'] = stream_get_contents($fp);
126 $response['headers'] = $resp_headers;
127 }
128
129 /*-------------------------------- fsockpen --------------------------------*/
130 function _rplg_fsockopen_urlopen($url, $postdata, $headers, &$response) {
131 $buf = '';
132 $req = '';
133 $length = 0;
134 $postdata_str = rplg_get_query_string($postdata);
135 $url_pieces = parse_url($url);
136 $host = $url_pieces['host'];
137
138 if(!isset($url_pieces['port'])) {
139 switch($url_pieces['scheme']) {
140 case 'http':
141 $url_pieces['port'] = 80;
142 break;
143 case 'https':
144 $url_pieces['port'] = 443;
145 $host = 'ssl://' . $url_pieces['host'];
146 break;
147 }
148 }
149
150 if(!isset($url_pieces['path'])) { $url_pieces['path'] = '/'; }
151
152 if(($url_pieces['port'] == 80 && $url_pieces['scheme'] == 'http') ||
153 ($url_pieces['port'] == 443 && $url_pieces['scheme'] == 'https')) {
154 $req_host = $url_pieces['host'];
155 } else {
156 $req_host = $url_pieces['host'] . ':' . $url_pieces['port'];
157 }
158
159 $fp = @fsockopen($host, $url_pieces['port'], $errno, $errstr, RPLG_SOCKET_TIMEOUT);
160 if(!$fp) { return false; }
161
162 $path = $url_pieces['path'];
163 if (isset($url_pieces['query'])) $path .= '?'.$url_pieces['query'];
164
165 $req .= ($postdata_str ? 'POST' : 'GET') . ' ' . $path . " HTTP/1.1\r\n";
166 $req .= 'Host: ' . $req_host . "\r\n";
167 $req .= rplg_get_http_headers_for_request($postdata_str, $headers);
168 if($postdata_str) {
169 $req .= "\r\n\r\n" . $postdata_str;
170 }
171 $req .= "\r\n\r\n";
172
173 fwrite($fp, $req);
174 while(!feof($fp)) {
175 $buf .= fgets($fp, 4096);
176 }
177
178 list($headers, $response['data']) = explode("\r\n\r\n", $buf, 2);
179
180 $headers = _rplg_get_response_headers($headers, $response);
181
182 if(isset($headers['transfer-encoding']) && 'chunked' == strtolower($headers['transfer-encoding'])) {
183 $chunk_data = $response['data'];
184 $joined_data = '';
185 while(true) {
186 list($chunk_length, $chunk_data) = explode("\r\n", $chunk_data, 2);
187 $chunk_length = hexdec($chunk_length);
188 if(!$chunk_length || !strlen($chunk_data)) { break; }
189
190 $joined_data .= substr($chunk_data, 0, $chunk_length);
191 $chunk_data = substr($chunk_data, $chunk_length + 1);
192 $length += $chunk_length;
193 }
194 $response['data'] = $joined_data;
195 } else {
196 $length = $headers['content-length'];
197 }
198 $response['headers'] = $headers;
199 }
200
201 /*-------------------------------- helpers --------------------------------*/
202 function rplg_get_query_string($params) {
203 $query = '';
204
205 if($params) {
206 foreach($params as $key=>$value) {
207 $query .= urlencode($key) . '=' . urlencode($value) . '&';
208 }
209 }
210 return $query;
211 }
212
213 function _rplg_get_response_headers($headers, &$response) {
214 $headers = explode("\r\n", $headers);
215 list($unused, $response['code'], $unused) = explode(' ', $headers[0], 3);
216 $headers = array_slice($headers, 1);
217 foreach($headers as $unused=>$header) {
218 $header = explode(':', $header);
219 $header[0] = trim($header[0]);
220 $header[1] = trim($header[1]);
221 $headers[strtolower($header[0])] = $header[1];
222 }
223 return $headers;
224 }
225
226 function rplg_get_http_headers_for_request($content, $headers) {
227 $req_headers = array();
228 $req_headers[] = 'User-Agent: ' . RPLG_USER_AGENT;
229 $req_headers[] = 'Connection: close';
230 if($content) {
231 $req_headers[] = 'Content-Length: ' . strlen($content);
232 $req_headers[] = 'Content-Type: application/x-www-form-urlencoded';
233 }
234 return implode("\r\n", array_merge($req_headers, $headers));
235 }
236
237 function rplg_url_method() {
238 if(function_exists('curl_init')) {
239 return 'curl';
240 } else if(ini_get('allow_url_fopen') && function_exists('stream_get_contents')) {
241 return 'fopen';
242 } else {
243 return 'fsockopen';
244 }
245 }
246 }
247
248 ?>
249