@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | public $headers; |
95 | 95 | |
96 | 96 | /** |
97 | - * Start the curl object |
|
98 | - * - allow for user override values |
|
99 | - * |
|
100 | - * @param array $options An array of cURL options |
|
101 | - * @param int $max_redirect Maximum number of redirects |
|
102 | - */ |
|
97 | + * Start the curl object |
|
98 | + * - allow for user override values |
|
99 | + * |
|
100 | + * @param array $options An array of cURL options |
|
101 | + * @param int $max_redirect Maximum number of redirects |
|
102 | + */ |
|
103 | 103 | public function __construct($options = array(), $max_redirect = 3) |
104 | 104 | { |
105 | 105 | // Initialize class variables |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | - * Main calling function, |
|
112 | - * - will request the page data from a given $url |
|
113 | - * - optionally will post data to the page form if post data is supplied |
|
114 | - * - passed arrays will be converted to a post string joined with &'s |
|
115 | - * - calls set_options to set the curl opts array values based on the defaults and user input |
|
116 | - * |
|
117 | - * @param string $url the site we are going to fetch |
|
118 | - * @param array $post_data any post data as form name => value |
|
119 | - * @return object An instance of the curl_fetch_web_data class |
|
120 | - */ |
|
111 | + * Main calling function, |
|
112 | + * - will request the page data from a given $url |
|
113 | + * - optionally will post data to the page form if post data is supplied |
|
114 | + * - passed arrays will be converted to a post string joined with &'s |
|
115 | + * - calls set_options to set the curl opts array values based on the defaults and user input |
|
116 | + * |
|
117 | + * @param string $url the site we are going to fetch |
|
118 | + * @param array $post_data any post data as form name => value |
|
119 | + * @return object An instance of the curl_fetch_web_data class |
|
120 | + */ |
|
121 | 121 | public function get_url_data($url, $post_data = array()) |
122 | 122 | { |
123 | 123 | // POSTing some data perhaps? |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
137 | - * Makes the actual cURL call |
|
138 | - * - stores responses (url, code, error, headers, body) in the response array |
|
139 | - * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
140 | - * |
|
141 | - * @param string $url The site to fetch |
|
142 | - * @param bool $redirect Whether or not this was a redirect request |
|
143 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
144 | - */ |
|
137 | + * Makes the actual cURL call |
|
138 | + * - stores responses (url, code, error, headers, body) in the response array |
|
139 | + * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
140 | + * |
|
141 | + * @param string $url The site to fetch |
|
142 | + * @param bool $redirect Whether or not this was a redirect request |
|
143 | + * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
144 | + */ |
|
145 | 145 | private function curl_request($url, $redirect = false) |
146 | 146 | { |
147 | 147 | // we do have a url I hope |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Used if being redirected to ensure we have a fully qualified address |
|
197 | - * |
|
198 | - * @param string $last_url The URL we went to |
|
199 | - * @param string $new_url The URL we were redirected to |
|
200 | - * @return string The new URL that was in the HTTP header |
|
201 | - */ |
|
196 | + * Used if being redirected to ensure we have a fully qualified address |
|
197 | + * |
|
198 | + * @param string $last_url The URL we went to |
|
199 | + * @param string $new_url The URL we were redirected to |
|
200 | + * @return string The new URL that was in the HTTP header |
|
201 | + */ |
|
202 | 202 | private function get_redirect_url($last_url = '', $new_url = '') |
203 | 203 | { |
204 | 204 | // Get the elements for these urls |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Used to return the results to the calling program |
|
220 | - * - called as ->result() will return the full final array |
|
221 | - * - called as ->result('body') to just return the page source of the result |
|
222 | - * |
|
223 | - * @param string $area Used to return an area such as body, header, error |
|
224 | - * @return string The response |
|
225 | - */ |
|
219 | + * Used to return the results to the calling program |
|
220 | + * - called as ->result() will return the full final array |
|
221 | + * - called as ->result('body') to just return the page source of the result |
|
222 | + * |
|
223 | + * @param string $area Used to return an area such as body, header, error |
|
224 | + * @return string The response |
|
225 | + */ |
|
226 | 226 | public function result($area = '') |
227 | 227 | { |
228 | 228 | $max_result = count($this->response) - 1; |
@@ -235,13 +235,13 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | - * Will return all results from all loops (redirects) |
|
239 | - * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
240 | - * - Call as ->result_raw() for everything. |
|
241 | - * |
|
242 | - * @param string $response_number Which response we want to get |
|
243 | - * @return array|string The entire response array or just the specified response |
|
244 | - */ |
|
238 | + * Will return all results from all loops (redirects) |
|
239 | + * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
240 | + * - Call as ->result_raw() for everything. |
|
241 | + * |
|
242 | + * @param string $response_number Which response we want to get |
|
243 | + * @return array|string The entire response array or just the specified response |
|
244 | + */ |
|
245 | 245 | public function result_raw($response_number = '') |
246 | 246 | { |
247 | 247 | if (!is_numeric($response_number)) |
@@ -254,13 +254,13 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
257 | - * Takes supplied POST data and url encodes it |
|
258 | - * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
259 | - * - drops vars with @ since we don't support sending files (uploading) |
|
260 | - * |
|
261 | - * @param array|string $post_data The raw POST data |
|
262 | - * @return string A string of post data |
|
263 | - */ |
|
257 | + * Takes supplied POST data and url encodes it |
|
258 | + * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
259 | + * - drops vars with @ since we don't support sending files (uploading) |
|
260 | + * |
|
261 | + * @param array|string $post_data The raw POST data |
|
262 | + * @return string A string of post data |
|
263 | + */ |
|
264 | 264 | private function build_post_data($post_data) |
265 | 265 | { |
266 | 266 | if (is_array($post_data)) |
@@ -279,11 +279,11 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | - * Sets the final cURL options for the current call |
|
283 | - * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
284 | - * - sets the callback function now that $this is existing |
|
285 | - * @return void |
|
286 | - */ |
|
282 | + * Sets the final cURL options for the current call |
|
283 | + * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
284 | + * - sets the callback function now that $this is existing |
|
285 | + * @return void |
|
286 | + */ |
|
287 | 287 | private function set_options() |
288 | 288 | { |
289 | 289 | // Callback to parse the returned headers, if any |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
311 | - * Called to initiate a redirect from a 301, 302 or 307 header |
|
312 | - * - resets the cURL options for the loop, sets the referrer flag |
|
313 | - * |
|
314 | - * @param string $target_url The URL we want to redirect to |
|
315 | - * @param string $referer_url The URL that we're redirecting from |
|
316 | - */ |
|
311 | + * Called to initiate a redirect from a 301, 302 or 307 header |
|
312 | + * - resets the cURL options for the loop, sets the referrer flag |
|
313 | + * |
|
314 | + * @param string $target_url The URL we want to redirect to |
|
315 | + * @param string $referer_url The URL that we're redirecting from |
|
316 | + */ |
|
317 | 317 | private function redirect($target_url, $referer_url) |
318 | 318 | { |
319 | 319 | // no no I last saw that over there ... really, 301, 302, 307 |
@@ -10,8 +10,9 @@ discard block |
||
10 | 10 | * @version 2.1 Beta 4 |
11 | 11 | */ |
12 | 12 | |
13 | -if (!defined('SMF')) |
|
13 | +if (!defined('SMF')) { |
|
14 | 14 | die('No direct access...'); |
15 | +} |
|
15 | 16 | |
16 | 17 | /** |
17 | 18 | * Class curl_fetch_web_data |
@@ -121,10 +122,11 @@ discard block |
||
121 | 122 | public function get_url_data($url, $post_data = array()) |
122 | 123 | { |
123 | 124 | // POSTing some data perhaps? |
124 | - if (!empty($post_data) && is_array($post_data)) |
|
125 | - $this->post_data = $this->build_post_data($post_data); |
|
126 | - elseif (!empty($post_data)) |
|
127 | - $this->post_data = trim($post_data); |
|
125 | + if (!empty($post_data) && is_array($post_data)) { |
|
126 | + $this->post_data = $this->build_post_data($post_data); |
|
127 | + } elseif (!empty($post_data)) { |
|
128 | + $this->post_data = trim($post_data); |
|
129 | + } |
|
128 | 130 | |
129 | 131 | // set the options and get it |
130 | 132 | $this->set_options(); |
@@ -145,10 +147,11 @@ discard block |
||
145 | 147 | private function curl_request($url, $redirect = false) |
146 | 148 | { |
147 | 149 | // we do have a url I hope |
148 | - if ($url == '') |
|
149 | - return false; |
|
150 | - else |
|
151 | - $this->options[CURLOPT_URL] = $url; |
|
150 | + if ($url == '') { |
|
151 | + return false; |
|
152 | + } else { |
|
153 | + $this->options[CURLOPT_URL] = $url; |
|
154 | + } |
|
152 | 155 | |
153 | 156 | // if we have not already been redirected, set it up so we can if needed |
154 | 157 | if (!$redirect) |
@@ -228,10 +231,11 @@ discard block |
||
228 | 231 | $max_result = count($this->response) - 1; |
229 | 232 | |
230 | 233 | // just return a specifed area or the entire result? |
231 | - if ($area == '') |
|
232 | - return $this->response[$max_result]; |
|
233 | - else |
|
234 | - return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result]; |
|
234 | + if ($area == '') { |
|
235 | + return $this->response[$max_result]; |
|
236 | + } else { |
|
237 | + return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result]; |
|
238 | + } |
|
235 | 239 | } |
236 | 240 | |
237 | 241 | /** |
@@ -244,9 +248,9 @@ discard block |
||
244 | 248 | */ |
245 | 249 | public function result_raw($response_number = '') |
246 | 250 | { |
247 | - if (!is_numeric($response_number)) |
|
248 | - return $this->response; |
|
249 | - else |
|
251 | + if (!is_numeric($response_number)) { |
|
252 | + return $this->response; |
|
253 | + } else |
|
250 | 254 | { |
251 | 255 | $response_number = min($response_number, count($this->response) - 1); |
252 | 256 | return $this->response[$response_number]; |
@@ -268,13 +272,14 @@ discard block |
||
268 | 272 | $postvars = array(); |
269 | 273 | |
270 | 274 | // build the post data, drop ones with leading @'s since those can be used to send files, we don't support that. |
271 | - foreach ($post_data as $name => $value) |
|
272 | - $postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value); |
|
275 | + foreach ($post_data as $name => $value) { |
|
276 | + $postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value); |
|
277 | + } |
|
273 | 278 | |
274 | 279 | return implode('&', $postvars); |
280 | + } else { |
|
281 | + return $post_data; |
|
275 | 282 | } |
276 | - else |
|
277 | - return $post_data; |
|
278 | 283 | |
279 | 284 | } |
280 | 285 | |
@@ -295,9 +300,9 @@ discard block |
||
295 | 300 | $keys = array_merge(array_keys($this->default_options), array_keys($this->user_options)); |
296 | 301 | $vals = array_merge($this->default_options, $this->user_options); |
297 | 302 | $this->options = array_combine($keys, $vals); |
303 | + } else { |
|
304 | + $this->options = $this->default_options; |
|
298 | 305 | } |
299 | - else |
|
300 | - $this->options = $this->default_options; |
|
301 | 306 | |
302 | 307 | // POST data options, here we don't allow any overide |
303 | 308 | if (isset($this->post_data)) |