@@ -808,8 +808,9 @@ |
||
808 | 808 | foreach ($param as $key => & $value) { |
809 | 809 | $param_string_parts[] = urlencode($key).'='.urlencode($value); |
810 | 810 | } |
811 | - if (count($param_string_parts) > 0) |
|
812 | - $result .= '&'.implode('&', $param_string_parts); |
|
811 | + if (count($param_string_parts) > 0) { |
|
812 | + $result .= '&'.implode('&', $param_string_parts); |
|
813 | + } |
|
813 | 814 | } |
814 | 815 | return $result; |
815 | 816 | } |
@@ -389,7 +389,9 @@ |
||
389 | 389 | */ |
390 | 390 | function who_is_online_in_this_course($from, $number_of_items, $uid, $time_limit, $course_code) |
391 | 391 | { |
392 | - if (empty($course_code)) return false; |
|
392 | + if (empty($course_code)) { |
|
393 | + return false; |
|
394 | + } |
|
393 | 395 | |
394 | 396 | if (empty($time_limit)) { |
395 | 397 | $time_limit = api_get_setting('time_limit_whosonline'); |
@@ -33,7 +33,9 @@ discard block |
||
33 | 33 | Database::query($query); |
34 | 34 | break; |
35 | 35 | case 'update': |
36 | - if ($new_path[0] == '.') $new_path = substr($new_path, 1); |
|
36 | + if ($new_path[0] == '.') { |
|
37 | + $new_path = substr($new_path, 1); |
|
38 | + } |
|
37 | 39 | $new_path = str_replace('//', '/', $new_path); |
38 | 40 | |
39 | 41 | // Attempt to update - tested & working for root dir |
@@ -379,7 +381,9 @@ discard block |
||
379 | 381 | chdir($path); |
380 | 382 | $handle = opendir($path); |
381 | 383 | while ($element = readdir($handle)) { |
382 | - if ($element == '.' || $element == '..') continue; |
|
384 | + if ($element == '.' || $element == '..') { |
|
385 | + continue; |
|
386 | + } |
|
383 | 387 | // Skip the current and parent directories |
384 | 388 | if (is_dir($element)) { |
385 | 389 | $dir_array[] = $path.'/'.$element; |
@@ -419,7 +423,9 @@ discard block |
||
419 | 423 | chdir($directory); |
420 | 424 | $handle = opendir($directory); |
421 | 425 | while ($element = readdir($handle)) { |
422 | - if ($element == '.' || $element == '..' || $element == '.htaccess') continue; |
|
426 | + if ($element == '.' || $element == '..' || $element == '.htaccess') { |
|
427 | + continue; |
|
428 | + } |
|
423 | 429 | // Skip the current and parent directories |
424 | 430 | if (!is_dir($element)) { |
425 | 431 | $element_array[] = $directory.'/'.$element; |
@@ -469,7 +475,9 @@ discard block |
||
469 | 475 | */ |
470 | 476 | function set_default_settings($upload_path, $filename, $filetype = 'file', $glued_table, $default_visibility = 'v') |
471 | 477 | { |
472 | - if (!$default_visibility) $default_visibility = 'v'; |
|
478 | + if (!$default_visibility) { |
|
479 | + $default_visibility = 'v'; |
|
480 | + } |
|
473 | 481 | |
474 | 482 | // Make sure path is not wrongly formed |
475 | 483 | $upload_path = !empty($upload_path) ? "/$upload_path" : ''; |
@@ -198,8 +198,7 @@ discard block |
||
198 | 198 | $tag_class = 'getid3_' . $tag_name; |
199 | 199 | $tag = new $tag_class($this); |
200 | 200 | $tag->Analyze(); |
201 | - } |
|
202 | - catch (getid3_exception $e) { |
|
201 | + } catch (getid3_exception $e) { |
|
203 | 202 | throw $e; |
204 | 203 | } |
205 | 204 | } |
@@ -243,9 +242,7 @@ discard block |
||
243 | 242 | // use assume format on these if format detection failed |
244 | 243 | if (preg_match('/\.mp[123a]$/i', $filename)) { |
245 | 244 | $determined_format = $file_format_array['mp3']; |
246 | - } |
|
247 | - |
|
248 | - else { |
|
245 | + } else { |
|
249 | 246 | fclose($this->fp); |
250 | 247 | throw new getid3_exception('Unable to determine file format'); |
251 | 248 | } |
@@ -259,8 +256,7 @@ discard block |
||
259 | 256 | if ($determined_format['fail_id3'] === 'ERROR') { |
260 | 257 | fclose($this->fp); |
261 | 258 | throw new getid3_exception('ID3 tags not allowed on this file type.'); |
262 | - } |
|
263 | - elseif ($determined_format['fail_id3'] === 'WARNING') { |
|
259 | + } elseif ($determined_format['fail_id3'] === 'WARNING') { |
|
264 | 260 | @$this->info['id3v1'] and $this->warning('ID3v1 tags not allowed on this file type.'); |
265 | 261 | @$this->info['id3v2'] and $this->warning('ID3v2 tags not allowed on this file type.'); |
266 | 262 | } |
@@ -301,11 +297,9 @@ discard block |
||
301 | 297 | |
302 | 298 | try { |
303 | 299 | $this->option_analyze and $class->Analyze(); |
304 | - } |
|
305 | - catch (getid3_exception $e) { |
|
300 | + } catch (getid3_exception $e) { |
|
306 | 301 | throw $e; |
307 | - } |
|
308 | - catch (Exception $e) { |
|
302 | + } catch (Exception $e) { |
|
309 | 303 | throw new getid3_exception('Corrupt file.'); |
310 | 304 | } |
311 | 305 | |
@@ -460,8 +454,7 @@ discard block |
||
460 | 454 | |
461 | 455 | if (is_array($message)) { |
462 | 456 | $this->warnings = array_merge($this->warnings, $message); |
463 | - } |
|
464 | - else { |
|
457 | + } else { |
|
465 | 458 | $this->warnings[] = $message; |
466 | 459 | } |
467 | 460 | } |
@@ -1101,8 +1094,7 @@ discard block |
||
1101 | 1094 | if (empty($this->info['comments'][$tag_name])) { |
1102 | 1095 | |
1103 | 1096 | // fall through and append value |
1104 | - } |
|
1105 | - elseif ($tag_type == 'id3v1') { |
|
1097 | + } elseif ($tag_type == 'id3v1') { |
|
1106 | 1098 | |
1107 | 1099 | $new_value_length = strlen(trim($value)); |
1108 | 1100 | foreach ($this->info['comments'][$tag_name] as $existing_key => $existing_value) { |
@@ -1112,8 +1104,7 @@ discard block |
||
1112 | 1104 | break 2; |
1113 | 1105 | } |
1114 | 1106 | } |
1115 | - } |
|
1116 | - else { |
|
1107 | + } else { |
|
1117 | 1108 | |
1118 | 1109 | $new_value_length = strlen(trim($value)); |
1119 | 1110 | foreach ($this->info['comments'][$tag_name] as $existing_key => $existing_value) { |
@@ -1588,8 +1588,10 @@ discard block |
||
1588 | 1588 | if (empty($session_visibility)) { |
1589 | 1589 | $session_visibility = $session->getVisibility(); |
1590 | 1590 | //default status loaded if empty |
1591 | - if (empty($session_visibility)) |
|
1592 | - $session_visibility = SESSION_VISIBLE_READ_ONLY; // by default readonly 1 |
|
1591 | + if (empty($session_visibility)) { |
|
1592 | + $session_visibility = SESSION_VISIBLE_READ_ONLY; |
|
1593 | + } |
|
1594 | + // by default readonly 1 |
|
1593 | 1595 | } else { |
1594 | 1596 | if (!in_array($session_visibility, array(SESSION_VISIBLE_READ_ONLY, SESSION_VISIBLE, SESSION_INVISIBLE))) { |
1595 | 1597 | $session_visibility = SESSION_VISIBLE_READ_ONLY; |
@@ -2792,10 +2794,11 @@ discard block |
||
2792 | 2794 | c_id = $courseId AND |
2793 | 2795 | user_id = $user_id "; |
2794 | 2796 | $result = Database::query($sql); |
2795 | - if (Database::affected_rows($result) > 0) |
|
2796 | - return true; |
|
2797 | - else |
|
2798 | - return false; |
|
2797 | + if (Database::affected_rows($result) > 0) { |
|
2798 | + return true; |
|
2799 | + } else { |
|
2800 | + return false; |
|
2801 | + } |
|
2799 | 2802 | } else { |
2800 | 2803 | // The user is not subscribed to the session, so make sure |
2801 | 2804 | // he isn't subscribed to a course in this session either |
@@ -2806,10 +2809,11 @@ discard block |
||
2806 | 2809 | c_id = $courseId AND |
2807 | 2810 | user_id = $user_id "; |
2808 | 2811 | $result = Database::query($sql); |
2809 | - if (Database::affected_rows($result) > 0) |
|
2810 | - return true; |
|
2811 | - else |
|
2812 | - return false; |
|
2812 | + if (Database::affected_rows($result) > 0) { |
|
2813 | + return true; |
|
2814 | + } else { |
|
2815 | + return false; |
|
2816 | + } |
|
2813 | 2817 | } |
2814 | 2818 | } else { |
2815 | 2819 | // Assign user as a coach to course |
@@ -102,8 +102,7 @@ discard block |
||
102 | 102 | $resp = _fetch_remote_file( $url ); |
103 | 103 | if ( is_success( $resp->status ) ) { |
104 | 104 | return _response_to_rss( $resp ); |
105 | - } |
|
106 | - else { |
|
105 | + } else { |
|
107 | 106 | error("Failed to fetch $url and cache is off"); |
108 | 107 | return false; |
109 | 108 | } |
@@ -172,8 +171,7 @@ discard block |
||
172 | 171 | // reset cache on 304 (at minutillo insistent prodding) |
173 | 172 | $cache->set($cache_key, $rss); |
174 | 173 | return $rss; |
175 | - } |
|
176 | - elseif ( is_success( $resp->status ) ) { |
|
174 | + } elseif ( is_success( $resp->status ) ) { |
|
177 | 175 | $rss = _response_to_rss( $resp ); |
178 | 176 | if ( $rss ) { |
179 | 177 | if (MAGPIE_DEBUG > 1) { |
@@ -183,24 +181,20 @@ discard block |
||
183 | 181 | $cache->set( $cache_key, $rss ); |
184 | 182 | return $rss; |
185 | 183 | } |
186 | - } |
|
187 | - else { |
|
184 | + } else { |
|
188 | 185 | $errormsg = "Failed to fetch $url "; |
189 | 186 | if ( $resp->status == '-100' ) { |
190 | 187 | $errormsg .= "(Request timed out after " . MAGPIE_FETCH_TIME_OUT . " seconds)"; |
191 | - } |
|
192 | - elseif ( $resp->error ) { |
|
188 | + } elseif ( $resp->error ) { |
|
193 | 189 | # compensate for Snoopy's annoying habbit to tacking |
194 | 190 | # on '\n' |
195 | 191 | $http_error = substr($resp->error, 0, -2); |
196 | 192 | $errormsg .= "(HTTP Error: $http_error)"; |
197 | - } |
|
198 | - else { |
|
193 | + } else { |
|
199 | 194 | $errormsg .= "(HTTP Response: " . $resp->response_code .')'; |
200 | 195 | } |
201 | 196 | } |
202 | - } |
|
203 | - else { |
|
197 | + } else { |
|
204 | 198 | $errormsg = "Unable to retrieve RSS file for unknown reasons."; |
205 | 199 | } |
206 | 200 | |
@@ -299,8 +293,7 @@ discard block |
||
299 | 293 | // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" |
300 | 294 | if (strpos($h, ": ")) { |
301 | 295 | list($field, $val) = explode(": ", $h, 2); |
302 | - } |
|
303 | - else { |
|
296 | + } else { |
|
304 | 297 | $field = $h; |
305 | 298 | $val = ""; |
306 | 299 | } |
@@ -336,8 +329,7 @@ discard block |
||
336 | 329 | function init () { |
337 | 330 | if ( defined('MAGPIE_INITALIZED') ) { |
338 | 331 | return; |
339 | - } |
|
340 | - else { |
|
332 | + } else { |
|
341 | 333 | define('MAGPIE_INITALIZED', true); |
342 | 334 | } |
343 | 335 | |
@@ -378,8 +370,7 @@ discard block |
||
378 | 370 | |
379 | 371 | if ( MAGPIE_CACHE_ON ) { |
380 | 372 | $ua = $ua . ')'; |
381 | - } |
|
382 | - else { |
|
373 | + } else { |
|
383 | 374 | $ua = $ua . '; No cache)'; |
384 | 375 | } |
385 | 376 |
@@ -124,13 +124,11 @@ discard block |
||
124 | 124 | if ( $this->MAX_AGE > $age ) { |
125 | 125 | // object exists and is current |
126 | 126 | return 'HIT'; |
127 | - } |
|
128 | - else { |
|
127 | + } else { |
|
129 | 128 | // object exists but is old |
130 | 129 | return 'STALE'; |
131 | 130 | } |
132 | - } |
|
133 | - else { |
|
131 | + } else { |
|
134 | 132 | // object does not exist |
135 | 133 | return 'MISS'; |
136 | 134 | } |
@@ -142,8 +140,7 @@ discard block |
||
142 | 140 | $mtime = filemtime( $filename ); |
143 | 141 | $age = time() - $mtime; |
144 | 142 | return $age; |
145 | - } |
|
146 | - else { |
|
143 | + } else { |
|
147 | 144 | return -1; |
148 | 145 | } |
149 | 146 | } |
@@ -185,8 +182,7 @@ discard block |
||
185 | 182 | $this->ERROR = $errormsg; |
186 | 183 | if ( MAGPIE_DEBUG ) { |
187 | 184 | trigger_error( $errormsg, $lvl); |
188 | - } |
|
189 | - else { |
|
185 | + } else { |
|
190 | 186 | error_log( $errormsg, 0); |
191 | 187 | } |
192 | 188 | } |
@@ -37,8 +37,7 @@ discard block |
||
37 | 37 | $offset = 0; |
38 | 38 | if ( $match[10] == 'Z' ) { |
39 | 39 | # zulu time, aka GMT |
40 | - } |
|
41 | - else { |
|
40 | + } else { |
|
42 | 41 | list( $tz_mod, $tz_hour, $tz_min ) = |
43 | 42 | array( $match[8], $match[9], $match[10]); |
44 | 43 | |
@@ -58,8 +57,7 @@ discard block |
||
58 | 57 | } |
59 | 58 | $epoch = $epoch + $offset; |
60 | 59 | return $epoch; |
61 | - } |
|
62 | - else { |
|
60 | + } else { |
|
63 | 61 | return -1; |
64 | 62 | } |
65 | 63 | } |
@@ -124,24 +124,26 @@ discard block |
||
124 | 124 | public function fetch($URI) { |
125 | 125 | //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); |
126 | 126 | $URI_PARTS = parse_url($URI); |
127 | - if (!empty($URI_PARTS["user"])) |
|
128 | - $this->user = $URI_PARTS["user"]; |
|
129 | - if (!empty($URI_PARTS["pass"])) |
|
130 | - $this->pass = $URI_PARTS["pass"]; |
|
127 | + if (!empty($URI_PARTS["user"])) { |
|
128 | + $this->user = $URI_PARTS["user"]; |
|
129 | + } |
|
130 | + if (!empty($URI_PARTS["pass"])) { |
|
131 | + $this->pass = $URI_PARTS["pass"]; |
|
132 | + } |
|
131 | 133 | if (!isset($fp)) { $fp = false; } |
132 | 134 | switch ($URI_PARTS["scheme"]) { |
133 | 135 | case "http": |
134 | 136 | $this->host = $URI_PARTS["host"]; |
135 | - if(!empty($URI_PARTS["port"])) |
|
136 | - $this->port = $URI_PARTS["port"]; |
|
137 | + if(!empty($URI_PARTS["port"])) { |
|
138 | + $this->port = $URI_PARTS["port"]; |
|
139 | + } |
|
137 | 140 | if($this->_connect($fp)) |
138 | 141 | { |
139 | 142 | if($this->_isproxy) |
140 | 143 | { |
141 | 144 | // using proxy, send entire URI |
142 | 145 | $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
143 | - } |
|
144 | - else |
|
146 | + } else |
|
145 | 147 | { |
146 | 148 | $path = $URI_PARTS["path"].(isset($URI_PARTS["query"]) ? "?".$URI_PARTS["query"] : ""); |
147 | 149 | // no proxy, send only the path |
@@ -177,13 +179,12 @@ discard block |
||
177 | 179 | { |
178 | 180 | $this->fetch($frameurl); |
179 | 181 | $this->_framedepth++; |
182 | + } else { |
|
183 | + break; |
|
180 | 184 | } |
181 | - else |
|
182 | - break; |
|
183 | 185 | } |
184 | 186 | } |
185 | - } |
|
186 | - else |
|
187 | + } else |
|
187 | 188 | { |
188 | 189 | return false; |
189 | 190 | } |
@@ -195,14 +196,14 @@ discard block |
||
195 | 196 | return false; |
196 | 197 | } |
197 | 198 | $this->host = $URI_PARTS["host"]; |
198 | - if(!empty($URI_PARTS["port"])) |
|
199 | - $this->port = $URI_PARTS["port"]; |
|
199 | + if(!empty($URI_PARTS["port"])) { |
|
200 | + $this->port = $URI_PARTS["port"]; |
|
201 | + } |
|
200 | 202 | if($this->_isproxy) |
201 | 203 | { |
202 | 204 | // using proxy, send entire URI |
203 | 205 | $this->_httpsrequest($URI,$URI,$this->_httpmethod); |
204 | - } |
|
205 | - else |
|
206 | + } else |
|
206 | 207 | { |
207 | 208 | $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
208 | 209 | // no proxy, send only the path |
@@ -236,9 +237,9 @@ discard block |
||
236 | 237 | { |
237 | 238 | $this->fetch($frameurl); |
238 | 239 | $this->_framedepth++; |
240 | + } else { |
|
241 | + break; |
|
239 | 242 | } |
240 | - else |
|
241 | - break; |
|
242 | 243 | } |
243 | 244 | } |
244 | 245 | return true; |
@@ -279,14 +280,16 @@ discard block |
||
279 | 280 | |
280 | 281 | while(list($key,$val) = each($links[2])) |
281 | 282 | { |
282 | - if(!empty($val)) |
|
283 | - $match[] = $val; |
|
283 | + if(!empty($val)) { |
|
284 | + $match[] = $val; |
|
285 | + } |
|
284 | 286 | } |
285 | 287 | |
286 | 288 | while(list($key,$val) = each($links[3])) |
287 | 289 | { |
288 | - if(!empty($val)) |
|
289 | - $match[] = $val; |
|
290 | + if(!empty($val)) { |
|
291 | + $match[] = $val; |
|
292 | + } |
|
290 | 293 | } |
291 | 294 | |
292 | 295 | // return the links |
@@ -402,27 +405,31 @@ discard block |
||
402 | 405 | |
403 | 406 | private function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
404 | 407 | { |
405 | - if($this->passcookies && $this->_redirectaddr) |
|
406 | - $this->setcookies(); |
|
408 | + if($this->passcookies && $this->_redirectaddr) { |
|
409 | + $this->setcookies(); |
|
410 | + } |
|
407 | 411 | |
408 | 412 | $URI_PARTS = parse_url($URI); |
409 | - if(empty($url)) |
|
410 | - $url = "/"; |
|
413 | + if(empty($url)) { |
|
414 | + $url = "/"; |
|
415 | + } |
|
411 | 416 | $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; |
412 | - if(!empty($this->agent)) |
|
413 | - $headers .= "User-Agent: ".$this->agent."\r\n"; |
|
414 | - if(!empty($this->host) && !isset($this->rawheaders['Host'])) |
|
415 | - $headers .= "Host: ".$this->host."\r\n"; |
|
416 | - if(!empty($this->accept)) |
|
417 | - $headers .= "Accept: ".$this->accept."\r\n"; |
|
417 | + if(!empty($this->agent)) { |
|
418 | + $headers .= "User-Agent: ".$this->agent."\r\n"; |
|
419 | + } |
|
420 | + if(!empty($this->host) && !isset($this->rawheaders['Host'])) { |
|
421 | + $headers .= "Host: ".$this->host."\r\n"; |
|
422 | + } |
|
423 | + if(!empty($this->accept)) { |
|
424 | + $headers .= "Accept: ".$this->accept."\r\n"; |
|
425 | + } |
|
418 | 426 | |
419 | 427 | if($this->use_gzip) { |
420 | 428 | // make sure PHP was built with --with-zlib |
421 | 429 | // and we can handle gzipp'ed data |
422 | 430 | if ( function_exists(gzinflate) ) { |
423 | 431 | $headers .= "Accept-encoding: gzip\r\n"; |
424 | - } |
|
425 | - else { |
|
432 | + } else { |
|
426 | 433 | trigger_error( |
427 | 434 | "use_gzip is on, but PHP was built without zlib support.". |
428 | 435 | " Requesting file(s) without gzip encoding.", |
@@ -430,12 +437,14 @@ discard block |
||
430 | 437 | } |
431 | 438 | } |
432 | 439 | |
433 | - if(!empty($this->referer)) |
|
434 | - $headers .= "Referer: ".$this->referer."\r\n"; |
|
440 | + if(!empty($this->referer)) { |
|
441 | + $headers .= "Referer: ".$this->referer."\r\n"; |
|
442 | + } |
|
435 | 443 | if(!empty($this->cookies)) |
436 | 444 | { |
437 | - if(!is_array($this->cookies)) |
|
438 | - $this->cookies = (array)$this->cookies; |
|
445 | + if(!is_array($this->cookies)) { |
|
446 | + $this->cookies = (array)$this->cookies; |
|
447 | + } |
|
439 | 448 | |
440 | 449 | reset($this->cookies); |
441 | 450 | if ( count($this->cookies) > 0 ) { |
@@ -448,27 +457,33 @@ discard block |
||
448 | 457 | } |
449 | 458 | if(!empty($this->rawheaders)) |
450 | 459 | { |
451 | - if(!is_array($this->rawheaders)) |
|
452 | - $this->rawheaders = (array)$this->rawheaders; |
|
453 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
454 | - $headers .= $headerKey.": ".$headerVal."\r\n"; |
|
460 | + if(!is_array($this->rawheaders)) { |
|
461 | + $this->rawheaders = (array)$this->rawheaders; |
|
462 | + } |
|
463 | + while(list($headerKey,$headerVal) = each($this->rawheaders)) { |
|
464 | + $headers .= $headerKey.": ".$headerVal."\r\n"; |
|
465 | + } |
|
455 | 466 | } |
456 | 467 | if(!empty($content_type)) { |
457 | 468 | $headers .= "Content-type: $content_type"; |
458 | - if ($content_type == "multipart/form-data") |
|
459 | - $headers .= "; boundary=".$this->_mime_boundary; |
|
469 | + if ($content_type == "multipart/form-data") { |
|
470 | + $headers .= "; boundary=".$this->_mime_boundary; |
|
471 | + } |
|
460 | 472 | $headers .= "\r\n"; |
461 | 473 | } |
462 | - if(!empty($body)) |
|
463 | - $headers .= "Content-length: ".strlen($body)."\r\n"; |
|
464 | - if(!empty($this->user) || !empty($this->pass)) |
|
465 | - $headers .= "Authorization: BASIC ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|
474 | + if(!empty($body)) { |
|
475 | + $headers .= "Content-length: ".strlen($body)."\r\n"; |
|
476 | + } |
|
477 | + if(!empty($this->user) || !empty($this->pass)) { |
|
478 | + $headers .= "Authorization: BASIC ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|
479 | + } |
|
466 | 480 | |
467 | 481 | $headers .= "\r\n"; |
468 | 482 | |
469 | 483 | // set the read timeout if needed |
470 | - if ($this->read_timeout > 0) |
|
471 | - socket_set_timeout($fp, $this->read_timeout); |
|
484 | + if ($this->read_timeout > 0) { |
|
485 | + socket_set_timeout($fp, $this->read_timeout); |
|
486 | + } |
|
472 | 487 | $this->timed_out = false; |
473 | 488 | |
474 | 489 | fwrite($fp,$headers.$body,strlen($headers.$body)); |
@@ -488,8 +503,9 @@ discard block |
||
488 | 503 | } |
489 | 504 | |
490 | 505 | // if($currentHeader == "\r\n") |
491 | - if(preg_match("/^\r?\n$/", $currentHeader) ) |
|
492 | - break; |
|
506 | + if(preg_match("/^\r?\n$/", $currentHeader) ) { |
|
507 | + break; |
|
508 | + } |
|
493 | 509 | |
494 | 510 | // if a header begins with Location: or URI:, set the redirect |
495 | 511 | if(preg_match("/^(Location:|URI:)/i",$currentHeader)) |
@@ -502,13 +518,14 @@ discard block |
||
502 | 518 | // no host in the path, so prepend |
503 | 519 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
504 | 520 | // eliminate double slash |
505 | - if(!preg_match("|^/|",$matches[2])) |
|
506 | - $this->_redirectaddr .= "/".$matches[2]; |
|
507 | - else |
|
508 | - $this->_redirectaddr .= $matches[2]; |
|
521 | + if(!preg_match("|^/|",$matches[2])) { |
|
522 | + $this->_redirectaddr .= "/".$matches[2]; |
|
523 | + } else { |
|
524 | + $this->_redirectaddr .= $matches[2]; |
|
525 | + } |
|
526 | + } else { |
|
527 | + $this->_redirectaddr = $matches[2]; |
|
509 | 528 | } |
510 | - else |
|
511 | - $this->_redirectaddr = $matches[2]; |
|
512 | 529 | } |
513 | 530 | |
514 | 531 | if(preg_match("|^HTTP/|",$currentHeader)) |
@@ -561,15 +578,18 @@ discard block |
||
561 | 578 | if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
562 | 579 | { |
563 | 580 | $this->results[] = $results; |
564 | - for($x=0; $x<count($match[1]); $x++) |
|
565 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
581 | + for($x=0; $x<count($match[1]); $x++) { |
|
582 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
583 | + } |
|
566 | 584 | } |
567 | 585 | // have we already fetched framed content? |
568 | - elseif(is_array($this->results)) |
|
569 | - $this->results[] = $results; |
|
586 | + elseif(is_array($this->results)) { |
|
587 | + $this->results[] = $results; |
|
588 | + } |
|
570 | 589 | // no framed content |
571 | - else |
|
572 | - $this->results = $results; |
|
590 | + else { |
|
591 | + $this->results = $results; |
|
592 | + } |
|
573 | 593 | |
574 | 594 | return true; |
575 | 595 | } |
@@ -585,28 +605,35 @@ discard block |
||
585 | 605 | |
586 | 606 | private function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
587 | 607 | { |
588 | - if($this->passcookies && $this->_redirectaddr) |
|
589 | - $this->setcookies(); |
|
608 | + if($this->passcookies && $this->_redirectaddr) { |
|
609 | + $this->setcookies(); |
|
610 | + } |
|
590 | 611 | |
591 | 612 | $headers = array(); |
592 | 613 | |
593 | 614 | $URI_PARTS = parse_url($URI); |
594 | - if(empty($url)) |
|
595 | - $url = "/"; |
|
615 | + if(empty($url)) { |
|
616 | + $url = "/"; |
|
617 | + } |
|
596 | 618 | // GET ... header not needed for curl |
597 | 619 | //$headers[] = $http_method." ".$url." ".$this->_httpversion; |
598 | - if(!empty($this->agent)) |
|
599 | - $headers[] = "User-Agent: ".$this->agent; |
|
600 | - if(!empty($this->host)) |
|
601 | - $headers[] = "Host: ".$this->host; |
|
602 | - if(!empty($this->accept)) |
|
603 | - $headers[] = "Accept: ".$this->accept; |
|
604 | - if(!empty($this->referer)) |
|
605 | - $headers[] = "Referer: ".$this->referer; |
|
620 | + if(!empty($this->agent)) { |
|
621 | + $headers[] = "User-Agent: ".$this->agent; |
|
622 | + } |
|
623 | + if(!empty($this->host)) { |
|
624 | + $headers[] = "Host: ".$this->host; |
|
625 | + } |
|
626 | + if(!empty($this->accept)) { |
|
627 | + $headers[] = "Accept: ".$this->accept; |
|
628 | + } |
|
629 | + if(!empty($this->referer)) { |
|
630 | + $headers[] = "Referer: ".$this->referer; |
|
631 | + } |
|
606 | 632 | if(!empty($this->cookies)) |
607 | 633 | { |
608 | - if(!is_array($this->cookies)) |
|
609 | - $this->cookies = (array)$this->cookies; |
|
634 | + if(!is_array($this->cookies)) { |
|
635 | + $this->cookies = (array)$this->cookies; |
|
636 | + } |
|
610 | 637 | |
611 | 638 | reset($this->cookies); |
612 | 639 | if ( count($this->cookies) > 0 ) { |
@@ -619,31 +646,38 @@ discard block |
||
619 | 646 | } |
620 | 647 | if(!empty($this->rawheaders)) |
621 | 648 | { |
622 | - if(!is_array($this->rawheaders)) |
|
623 | - $this->rawheaders = (array)$this->rawheaders; |
|
624 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
625 | - $headers[] = $headerKey.": ".$headerVal; |
|
649 | + if(!is_array($this->rawheaders)) { |
|
650 | + $this->rawheaders = (array)$this->rawheaders; |
|
651 | + } |
|
652 | + while(list($headerKey,$headerVal) = each($this->rawheaders)) { |
|
653 | + $headers[] = $headerKey.": ".$headerVal; |
|
654 | + } |
|
626 | 655 | } |
627 | 656 | if(!empty($content_type)) { |
628 | - if ($content_type == "multipart/form-data") |
|
629 | - $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
|
630 | - else |
|
631 | - $headers[] = "Content-type: $content_type"; |
|
632 | - } |
|
633 | - if(!empty($body)) |
|
634 | - $headers[] = "Content-length: ".strlen($body); |
|
635 | - if(!empty($this->user) || !empty($this->pass)) |
|
636 | - $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
|
657 | + if ($content_type == "multipart/form-data") { |
|
658 | + $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
|
659 | + } else { |
|
660 | + $headers[] = "Content-type: $content_type"; |
|
661 | + } |
|
662 | + } |
|
663 | + if(!empty($body)) { |
|
664 | + $headers[] = "Content-length: ".strlen($body); |
|
665 | + } |
|
666 | + if(!empty($this->user) || !empty($this->pass)) { |
|
667 | + $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
|
668 | + } |
|
637 | 669 | |
638 | 670 | for($curr_header = 0; $curr_header < count($headers); $curr_header++) { |
639 | 671 | $cmdline_params .= " -H \"".$headers[$curr_header]."\""; |
640 | 672 | } |
641 | 673 | |
642 | - if(!empty($body)) |
|
643 | - $cmdline_params .= " -d \"$body\""; |
|
674 | + if(!empty($body)) { |
|
675 | + $cmdline_params .= " -d \"$body\""; |
|
676 | + } |
|
644 | 677 | |
645 | - if($this->read_timeout > 0) |
|
646 | - $cmdline_params .= " -m ".$this->read_timeout; |
|
678 | + if($this->read_timeout > 0) { |
|
679 | + $cmdline_params .= " -m ".$this->read_timeout; |
|
680 | + } |
|
647 | 681 | |
648 | 682 | $headerfile = uniqid(time()); |
649 | 683 | |
@@ -681,13 +715,14 @@ discard block |
||
681 | 715 | // no host in the path, so prepend |
682 | 716 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
683 | 717 | // eliminate double slash |
684 | - if(!preg_match("|^/|",$matches[2])) |
|
685 | - $this->_redirectaddr .= "/".$matches[2]; |
|
686 | - else |
|
687 | - $this->_redirectaddr .= $matches[2]; |
|
718 | + if(!preg_match("|^/|",$matches[2])) { |
|
719 | + $this->_redirectaddr .= "/".$matches[2]; |
|
720 | + } else { |
|
721 | + $this->_redirectaddr .= $matches[2]; |
|
722 | + } |
|
723 | + } else { |
|
724 | + $this->_redirectaddr = $matches[2]; |
|
688 | 725 | } |
689 | - else |
|
690 | - $this->_redirectaddr = $matches[2]; |
|
691 | 726 | } |
692 | 727 | |
693 | 728 | if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) |
@@ -712,15 +747,18 @@ discard block |
||
712 | 747 | if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
713 | 748 | { |
714 | 749 | $this->results[] = $results; |
715 | - for($x=0; $x<count($match[1]); $x++) |
|
716 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
750 | + for($x=0; $x<count($match[1]); $x++) { |
|
751 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
752 | + } |
|
717 | 753 | } |
718 | 754 | // have we already fetched framed content? |
719 | - elseif(is_array($this->results)) |
|
720 | - $this->results[] = $results; |
|
755 | + elseif(is_array($this->results)) { |
|
756 | + $this->results[] = $results; |
|
757 | + } |
|
721 | 758 | // no framed content |
722 | - else |
|
723 | - $this->results = $results; |
|
759 | + else { |
|
760 | + $this->results = $results; |
|
761 | + } |
|
724 | 762 | |
725 | 763 | unlink("/tmp/$headerfile"); |
726 | 764 | |
@@ -736,8 +774,9 @@ discard block |
||
736 | 774 | { |
737 | 775 | for($x=0; $x<count($this->headers); $x++) |
738 | 776 | { |
739 | - if(preg_match("/^set-cookie:[\s]+([^=]+)=([^;]+)/i", $this->headers[$x],$match)) |
|
740 | - $this->cookies[$match[1]] = $match[2]; |
|
777 | + if(preg_match("/^set-cookie:[\s]+([^=]+)=([^;]+)/i", $this->headers[$x],$match)) { |
|
778 | + $this->cookies[$match[1]] = $match[2]; |
|
779 | + } |
|
741 | 780 | } |
742 | 781 | } |
743 | 782 | |
@@ -773,8 +812,7 @@ discard block |
||
773 | 812 | $this->_isproxy = true; |
774 | 813 | $host = $this->proxy_host; |
775 | 814 | $port = $this->proxy_port; |
776 | - } |
|
777 | - else |
|
815 | + } else |
|
778 | 816 | { |
779 | 817 | $host = $this->host; |
780 | 818 | $port = $this->port; |
@@ -793,8 +831,7 @@ discard block |
||
793 | 831 | // socket connection succeeded |
794 | 832 | |
795 | 833 | return true; |
796 | - } |
|
797 | - else |
|
834 | + } else |
|
798 | 835 | { |
799 | 836 | // socket connection failed |
800 | 837 | $this->status = $errno; |
@@ -837,8 +874,9 @@ discard block |
||
837 | 874 | settype($formvars, "array"); |
838 | 875 | settype($formfiles, "array"); |
839 | 876 | |
840 | - if (count($formvars) == 0 && count($formfiles) == 0) |
|
841 | - return; |
|
877 | + if (count($formvars) == 0 && count($formfiles) == 0) { |
|
878 | + return; |
|
879 | + } |
|
842 | 880 | |
843 | 881 | switch ($this->_submit_type) { |
844 | 882 | case "application/x-www-form-urlencoded": |
@@ -848,8 +886,9 @@ discard block |
||
848 | 886 | while (list($cur_key, $cur_val) = each($val)) { |
849 | 887 | $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
850 | 888 | } |
851 | - } else |
|
852 | - $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
889 | + } else { |
|
890 | + $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
891 | + } |
|
853 | 892 | } |
854 | 893 | break; |
855 | 894 | |
@@ -875,7 +914,9 @@ discard block |
||
875 | 914 | while (list($field_name, $file_names) = each($formfiles)) { |
876 | 915 | settype($file_names, "array"); |
877 | 916 | while (list(, $file_name) = each($file_names)) { |
878 | - if (!is_readable($file_name)) continue; |
|
917 | + if (!is_readable($file_name)) { |
|
918 | + continue; |
|
919 | + } |
|
879 | 920 | |
880 | 921 | $fp = fopen($file_name, "r"); |
881 | 922 | $file_content = fread($fp, filesize($file_name)); |