@@ -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)); |
@@ -165,12 +165,10 @@ discard block |
||
165 | 165 | if ( $el == 'rdf' ) { |
166 | 166 | $this->feed_type = RSS; |
167 | 167 | $this->feed_version = '1.0'; |
168 | - } |
|
169 | - elseif ( $el == 'rss' ) { |
|
168 | + } elseif ( $el == 'rss' ) { |
|
170 | 169 | $this->feed_type = RSS; |
171 | 170 | $this->feed_version = $attrs['version']; |
172 | - } |
|
173 | - elseif ( $el == 'feed' ) { |
|
171 | + } elseif ( $el == 'feed' ) { |
|
174 | 172 | $this->feed_type = ATOM; |
175 | 173 | $this->feed_version = $attrs['version']; |
176 | 174 | $this->inchannel = true; |
@@ -181,8 +179,7 @@ discard block |
||
181 | 179 | if ( $el == 'channel' ) |
182 | 180 | { |
183 | 181 | $this->inchannel = true; |
184 | - } |
|
185 | - elseif ($el == 'item' or $el == 'entry' ) |
|
182 | + } elseif ($el == 'item' or $el == 'entry' ) |
|
186 | 183 | { |
187 | 184 | $this->initem = true; |
188 | 185 | if ( isset($attrs['rdf:about']) ) { |
@@ -198,9 +195,7 @@ discard block |
||
198 | 195 | $el == 'textinput' ) |
199 | 196 | { |
200 | 197 | $this->intextinput = true; |
201 | - } |
|
202 | - |
|
203 | - elseif ( |
|
198 | + } elseif ( |
|
204 | 199 | $this->feed_type == RSS and |
205 | 200 | $this->current_namespace == '' and |
206 | 201 | $el == 'image' ) |
@@ -244,8 +239,7 @@ discard block |
||
244 | 239 | if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
245 | 240 | { |
246 | 241 | $link_el = 'link'; |
247 | - } |
|
248 | - else { |
|
242 | + } else { |
|
249 | 243 | $link_el = 'link_' . $attrs['rel']; |
250 | 244 | } |
251 | 245 | |
@@ -263,8 +257,7 @@ discard block |
||
263 | 257 | if ($this->feed_type == ATOM and $this->incontent) |
264 | 258 | { |
265 | 259 | $this->append_content( $text ); |
266 | - } |
|
267 | - else { |
|
260 | + } else { |
|
268 | 261 | $current_el = join('_', array_reverse($this->stack)); |
269 | 262 | $this->append($current_el, $text); |
270 | 263 | } |
@@ -278,37 +271,30 @@ discard block |
||
278 | 271 | $this->items[] = $this->current_item; |
279 | 272 | $this->current_item = array(); |
280 | 273 | $this->initem = false; |
281 | - } |
|
282 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
274 | + } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
283 | 275 | { |
284 | 276 | $this->intextinput = false; |
285 | - } |
|
286 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
277 | + } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
287 | 278 | { |
288 | 279 | $this->inimage = false; |
289 | - } |
|
290 | - elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
280 | + } elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
291 | 281 | { |
292 | 282 | $this->incontent = false; |
293 | - } |
|
294 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
283 | + } elseif ($el == 'channel' or $el == 'feed' ) |
|
295 | 284 | { |
296 | 285 | $this->inchannel = false; |
297 | - } |
|
298 | - elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
286 | + } elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
299 | 287 | // balance tags properly |
300 | 288 | // note: i don't think this is actually neccessary |
301 | 289 | if ( $this->stack[0] == $el ) |
302 | 290 | { |
303 | 291 | $this->append_content("</$el>"); |
304 | - } |
|
305 | - else { |
|
292 | + } else { |
|
306 | 293 | $this->append_content("<$el />"); |
307 | 294 | } |
308 | 295 | |
309 | 296 | array_shift( $this->stack ); |
310 | - } |
|
311 | - else { |
|
297 | + } else { |
|
312 | 298 | array_shift( $this->stack ); |
313 | 299 | } |
314 | 300 | |
@@ -327,8 +313,7 @@ discard block |
||
327 | 313 | public function append_content($text) { |
328 | 314 | if ( $this->initem ) { |
329 | 315 | $this->concat( $this->current_item[ $this->incontent ], $text ); |
330 | - } |
|
331 | - elseif ( $this->inchannel ) { |
|
316 | + } elseif ( $this->inchannel ) { |
|
332 | 317 | $this->concat( $this->channel[ $this->incontent ], $text ); |
333 | 318 | } |
334 | 319 | } |
@@ -343,34 +328,27 @@ discard block |
||
343 | 328 | if ( $this->initem ) { |
344 | 329 | $this->concat( |
345 | 330 | $this->current_item[ $this->current_namespace ][ $el ], $text); |
346 | - } |
|
347 | - elseif ($this->inchannel) { |
|
331 | + } elseif ($this->inchannel) { |
|
348 | 332 | $this->concat( |
349 | 333 | $this->channel[ $this->current_namespace][ $el ], $text ); |
350 | - } |
|
351 | - elseif ($this->intextinput) { |
|
334 | + } elseif ($this->intextinput) { |
|
352 | 335 | $this->concat( |
353 | 336 | $this->textinput[ $this->current_namespace][ $el ], $text ); |
354 | - } |
|
355 | - elseif ($this->inimage) { |
|
337 | + } elseif ($this->inimage) { |
|
356 | 338 | $this->concat( |
357 | 339 | $this->image[ $this->current_namespace ][ $el ], $text ); |
358 | 340 | } |
359 | - } |
|
360 | - else { |
|
341 | + } else { |
|
361 | 342 | if ( $this->initem ) { |
362 | 343 | $this->concat( |
363 | 344 | $this->current_item[ $el ], $text); |
364 | - } |
|
365 | - elseif ($this->intextinput) { |
|
345 | + } elseif ($this->intextinput) { |
|
366 | 346 | $this->concat( |
367 | 347 | $this->textinput[ $el ], $text ); |
368 | - } |
|
369 | - elseif ($this->inimage) { |
|
348 | + } elseif ($this->inimage) { |
|
370 | 349 | $this->concat( |
371 | 350 | $this->image[ $el ], $text ); |
372 | - } |
|
373 | - elseif ($this->inchannel) { |
|
351 | + } elseif ($this->inchannel) { |
|
374 | 352 | $this->concat( |
375 | 353 | $this->channel[ $el ], $text ); |
376 | 354 | } |
@@ -384,10 +362,12 @@ discard block |
||
384 | 362 | $this->channel['description'] = $this->channel['tagline']; |
385 | 363 | for ( $i = 0; $i < count($this->items); $i++) { |
386 | 364 | $item = $this->items[$i]; |
387 | - if ( isset($item['summary']) ) |
|
388 | - $item['description'] = $item['summary']; |
|
389 | - if ( isset($item['atom_content'])) |
|
390 | - $item['content']['encoded'] = $item['atom_content']; |
|
365 | + if ( isset($item['summary']) ) { |
|
366 | + $item['description'] = $item['summary']; |
|
367 | + } |
|
368 | + if ( isset($item['atom_content'])) { |
|
369 | + $item['content']['encoded'] = $item['atom_content']; |
|
370 | + } |
|
391 | 371 | |
392 | 372 | $atom_date = (isset($item['issued']) ) ? $item['issued'] : $item['modified']; |
393 | 373 | if ( $atom_date ) { |
@@ -399,23 +379,23 @@ discard block |
||
399 | 379 | |
400 | 380 | $this->items[$i] = $item; |
401 | 381 | } |
402 | - } |
|
403 | - elseif ( $this->is_rss() ) { |
|
382 | + } elseif ( $this->is_rss() ) { |
|
404 | 383 | $this->channel['tagline'] = $this->channel['description']; |
405 | 384 | for ( $i = 0; $i < count($this->items); $i++) { |
406 | 385 | $item = $this->items[$i]; |
407 | - if ( isset($item['description'])) |
|
408 | - $item['summary'] = $item['description']; |
|
409 | - if ( isset($item['content']['encoded'] ) ) |
|
410 | - $item['atom_content'] = $item['content']['encoded']; |
|
386 | + if ( isset($item['description'])) { |
|
387 | + $item['summary'] = $item['description']; |
|
388 | + } |
|
389 | + if ( isset($item['content']['encoded'] ) ) { |
|
390 | + $item['atom_content'] = $item['content']['encoded']; |
|
391 | + } |
|
411 | 392 | |
412 | 393 | if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) { |
413 | 394 | $epoch = @parse_w3cdtf($item['dc']['date']); |
414 | 395 | if ($epoch and $epoch > 0) { |
415 | 396 | $item['date_timestamp'] = $epoch; |
416 | 397 | } |
417 | - } |
|
418 | - elseif ( isset($item['pubdate']) ) { |
|
398 | + } elseif ( isset($item['pubdate']) ) { |
|
419 | 399 | $epoch = @strtotime($item['pubdate']); |
420 | 400 | if ($epoch > 0) { |
421 | 401 | $item['date_timestamp'] = $epoch; |
@@ -431,8 +411,7 @@ discard block |
||
431 | 411 | public function is_rss () { |
432 | 412 | if ( $this->feed_type == RSS ) { |
433 | 413 | return $this->feed_version; |
434 | - } |
|
435 | - else { |
|
414 | + } else { |
|
436 | 415 | return false; |
437 | 416 | } |
438 | 417 | } |
@@ -440,8 +419,7 @@ discard block |
||
440 | 419 | public function is_atom() { |
441 | 420 | if ( $this->feed_type == ATOM ) { |
442 | 421 | return $this->feed_version; |
443 | - } |
|
444 | - else { |
|
422 | + } else { |
|
445 | 423 | return false; |
446 | 424 | } |
447 | 425 | } |
@@ -453,8 +431,7 @@ discard block |
||
453 | 431 | public function create_parser($source, $out_enc, $in_enc, $detect) { |
454 | 432 | if ( substr(phpversion(),0,1) == 5) { |
455 | 433 | $parser = $this->php5_create_parser($in_enc, $detect); |
456 | - } |
|
457 | - else { |
|
434 | + } else { |
|
458 | 435 | list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); |
459 | 436 | } |
460 | 437 | if ($out_enc) { |
@@ -478,8 +455,7 @@ discard block |
||
478 | 455 | // by default php5 does a fine job of detecting input encodings |
479 | 456 | if(!$detect && $in_enc) { |
480 | 457 | return xml_parser_create($in_enc); |
481 | - } |
|
482 | - else { |
|
458 | + } else { |
|
483 | 459 | return xml_parser_create(''); |
484 | 460 | } |
485 | 461 | } |
@@ -508,8 +484,7 @@ discard block |
||
508 | 484 | if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
509 | 485 | $in_enc = strtoupper($m[1]); |
510 | 486 | $this->source_encoding = $in_enc; |
511 | - } |
|
512 | - else { |
|
487 | + } else { |
|
513 | 488 | $in_enc = 'UTF-8'; |
514 | 489 | } |
515 | 490 | } |
@@ -552,8 +527,7 @@ discard block |
||
552 | 527 | $enc = strtoupper($enc); |
553 | 528 | if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) { |
554 | 529 | return $enc; |
555 | - } |
|
556 | - else { |
|
530 | + } else { |
|
557 | 531 | return false; |
558 | 532 | } |
559 | 533 | } |
@@ -565,8 +539,7 @@ discard block |
||
565 | 539 | } |
566 | 540 | if ( MAGPIE_DEBUG ) { |
567 | 541 | trigger_error( $errormsg, $lvl); |
568 | - } |
|
569 | - else { |
|
542 | + } else { |
|
570 | 543 | error_log( $errormsg, 0); |
571 | 544 | } |
572 | 545 | |
@@ -594,8 +567,11 @@ discard block |
||
594 | 567 | |
595 | 568 | |
596 | 569 | function array_change_key_case($array,$case=CASE_LOWER) { |
597 | - if ($case=CASE_LOWER) $cmd=strtolower; |
|
598 | - elseif ($case=CASE_UPPER) $cmd=strtoupper; |
|
570 | + if ($case=CASE_LOWER) { |
|
571 | + $cmd=strtolower; |
|
572 | + } elseif ($case=CASE_UPPER) { |
|
573 | + $cmd=strtoupper; |
|
574 | + } |
|
599 | 575 | foreach($array as $key=>$value) { |
600 | 576 | $output[$cmd($key)]=$value; |
601 | 577 | } |
@@ -154,7 +154,9 @@ discard block |
||
154 | 154 | |
155 | 155 | public function set_image_wrapper() |
156 | 156 | { |
157 | - if ($this->debug) error_log('Image::set_image_wrapper loaded'); |
|
157 | + if ($this->debug) { |
|
158 | + error_log('Image::set_image_wrapper loaded'); |
|
159 | + } |
|
158 | 160 | try { |
159 | 161 | if (file_exists($this->path)) { |
160 | 162 | $this->image = new Imagick($this->path); |
@@ -163,10 +165,14 @@ discard block |
||
163 | 165 | $this->fill_image_info(); //Fills height, width and type |
164 | 166 | } |
165 | 167 | } else { |
166 | - if ($this->debug) error_log('Image::image does not exist'); |
|
168 | + if ($this->debug) { |
|
169 | + error_log('Image::image does not exist'); |
|
170 | + } |
|
167 | 171 | } |
168 | 172 | } catch(ImagickException $e) { |
169 | - if ($this->debug) error_log($e->getMessage()); |
|
173 | + if ($this->debug) { |
|
174 | + error_log($e->getMessage()); |
|
175 | + } |
|
170 | 176 | } |
171 | 177 | } |
172 | 178 | |
@@ -180,7 +186,9 @@ discard block |
||
180 | 186 | |
181 | 187 | if (in_array($this->type, $this->allowed_extensions)) { |
182 | 188 | $this->image_validated = true; |
183 | - if ($this->debug) error_log('image_validated true'); |
|
189 | + if ($this->debug) { |
|
190 | + error_log('image_validated true'); |
|
191 | + } |
|
184 | 192 | } |
185 | 193 | } |
186 | 194 | |
@@ -196,7 +204,9 @@ discard block |
||
196 | 204 | //@todo implement border logic case for Imagick |
197 | 205 | public function resize($thumbw, $thumbh, $border, $specific_size = false) |
198 | 206 | { |
199 | - if (!$this->image_validated) return false; |
|
207 | + if (!$this->image_validated) { |
|
208 | + return false; |
|
209 | + } |
|
200 | 210 | |
201 | 211 | if ($specific_size) { |
202 | 212 | $width = $thumbw; |
@@ -222,7 +232,9 @@ discard block |
||
222 | 232 | */ |
223 | 233 | |
224 | 234 | public function crop($x, $y, $width, $height, $src_width, $src_height) { |
225 | - if (!$this->image_validated) return false; |
|
235 | + if (!$this->image_validated) { |
|
236 | + return false; |
|
237 | + } |
|
226 | 238 | $this->image->cropimage($width, $height, $x, $y); |
227 | 239 | $this->width = $width; |
228 | 240 | $this->height = $height; |
@@ -230,7 +242,9 @@ discard block |
||
230 | 242 | |
231 | 243 | public function send_image($file = '', $compress = -1, $convert_file_to = null) |
232 | 244 | { |
233 | - if (!$this->image_validated) return false; |
|
245 | + if (!$this->image_validated) { |
|
246 | + return false; |
|
247 | + } |
|
234 | 248 | $type = $this->type; |
235 | 249 | if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { |
236 | 250 | $type = $convert_file_to; |
@@ -238,20 +252,28 @@ discard block |
||
238 | 252 | switch ($type) { |
239 | 253 | case 'jpeg': |
240 | 254 | case 'jpg': |
241 | - if (!$file) header("Content-type: image/jpeg"); |
|
255 | + if (!$file) { |
|
256 | + header("Content-type: image/jpeg"); |
|
257 | + } |
|
242 | 258 | break; |
243 | 259 | case 'png': |
244 | - if (!$file) header("Content-type: image/png"); |
|
260 | + if (!$file) { |
|
261 | + header("Content-type: image/png"); |
|
262 | + } |
|
245 | 263 | break; |
246 | 264 | case 'gif': |
247 | - if (!$file) header("Content-type: image/gif"); |
|
265 | + if (!$file) { |
|
266 | + header("Content-type: image/gif"); |
|
267 | + } |
|
248 | 268 | break; |
249 | 269 | } |
250 | 270 | $result = false; |
251 | 271 | try { |
252 | 272 | $result = $this->image->writeImage($file); |
253 | 273 | } catch(ImagickException $e) { |
254 | - if ($this->debug) error_log($e->getMessage()); |
|
274 | + if ($this->debug) { |
|
275 | + error_log($e->getMessage()); |
|
276 | + } |
|
255 | 277 | } |
256 | 278 | |
257 | 279 | if (!$file) { |
@@ -334,7 +356,9 @@ discard block |
||
334 | 356 | |
335 | 357 | public function resize($thumbw, $thumbh, $border, $specific_size = false) |
336 | 358 | { |
337 | - if (!$this->image_validated) return false; |
|
359 | + if (!$this->image_validated) { |
|
360 | + return false; |
|
361 | + } |
|
338 | 362 | if ($border == 1) { |
339 | 363 | if ($specific_size) { |
340 | 364 | $width = $thumbw; |
@@ -387,7 +411,9 @@ discard block |
||
387 | 411 | * @param int $src_height the source height of the original image |
388 | 412 | */ |
389 | 413 | public function crop($x, $y, $width, $height, $src_width, $src_height) { |
390 | - if (!$this->image_validated) return false; |
|
414 | + if (!$this->image_validated) { |
|
415 | + return false; |
|
416 | + } |
|
391 | 417 | $this->width = $width; |
392 | 418 | $this->height = $height; |
393 | 419 | $src = null; |
@@ -418,7 +444,9 @@ discard block |
||
418 | 444 | |
419 | 445 | public function send_image($file = '', $compress = -1, $convert_file_to = null) |
420 | 446 | { |
421 | - if (!$this->image_validated) return false; |
|
447 | + if (!$this->image_validated) { |
|
448 | + return false; |
|
449 | + } |
|
422 | 450 | $compress = (int)$compress; |
423 | 451 | $type = $this->type; |
424 | 452 | if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { |
@@ -427,19 +455,27 @@ discard block |
||
427 | 455 | switch ($type) { |
428 | 456 | case 'jpeg': |
429 | 457 | case 'jpg': |
430 | - if (!$file) header("Content-type: image/jpeg"); |
|
431 | - if ($compress == -1) $compress = 100; |
|
458 | + if (!$file) { |
|
459 | + header("Content-type: image/jpeg"); |
|
460 | + } |
|
461 | + if ($compress == -1) { |
|
462 | + $compress = 100; |
|
463 | + } |
|
432 | 464 | return imagejpeg($this->bg, $file, $compress); |
433 | 465 | break; |
434 | 466 | case 'png': |
435 | - if (!$file) header("Content-type: image/png"); |
|
467 | + if (!$file) { |
|
468 | + header("Content-type: image/png"); |
|
469 | + } |
|
436 | 470 | if ($compress != -1) { |
437 | 471 | @imagetruecolortopalette($this->bg, true, $compress); |
438 | 472 | } |
439 | 473 | return imagepng($this->bg, $file, $compress); |
440 | 474 | break; |
441 | 475 | case 'gif': |
442 | - if (!$file) header("Content-type: image/gif"); |
|
476 | + if (!$file) { |
|
477 | + header("Content-type: image/gif"); |
|
478 | + } |
|
443 | 479 | if ($compress != -1) { |
444 | 480 | @imagetruecolortopalette($this->bg, true, $compress); |
445 | 481 | } |
@@ -456,7 +492,9 @@ discard block |
||
456 | 492 | */ |
457 | 493 | function convert2bw() |
458 | 494 | { |
459 | - if (!$this->image_validated) return false; |
|
495 | + if (!$this->image_validated) { |
|
496 | + return false; |
|
497 | + } |
|
460 | 498 | |
461 | 499 | $dest_img = imagecreatetruecolor(imagesx($this->bg), imagesy($this->bg)); |
462 | 500 | /* copy ignore the transparent color |
@@ -262,8 +262,9 @@ |
||
262 | 262 | $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
263 | 263 | $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); |
264 | 264 | |
265 | - if (!empty($access_url_id)) |
|
266 | - $where ="WHERE $table_url_rel_session.access_url_id = ".intval($access_url_id); |
|
265 | + if (!empty($access_url_id)) { |
|
266 | + $where ="WHERE $table_url_rel_session.access_url_id = ".intval($access_url_id); |
|
267 | + } |
|
267 | 268 | |
268 | 269 | $sql = "SELECT id, name, access_url_id |
269 | 270 | FROM $tbl_session u |
@@ -2259,7 +2259,9 @@ discard block |
||
2259 | 2259 | $debug = false; |
2260 | 2260 | } |
2261 | 2261 | |
2262 | - if ($debug) echo '<h1>Tracking::get_avg_student_score</h1>'; |
|
2262 | + if ($debug) { |
|
2263 | + echo '<h1>Tracking::get_avg_student_score</h1>'; |
|
2264 | + } |
|
2263 | 2265 | $tbl_stats_exercices = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
2264 | 2266 | $tbl_stats_attempts = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
2265 | 2267 | |
@@ -2336,7 +2338,9 @@ discard block |
||
2336 | 2338 | $condition_user1 AND |
2337 | 2339 | session_id = $session_id |
2338 | 2340 | GROUP BY lp_id, user_id"; |
2339 | - if ($debug) echo $sql; |
|
2341 | + if ($debug) { |
|
2342 | + echo $sql; |
|
2343 | + } |
|
2340 | 2344 | |
2341 | 2345 | $rs_last_lp_view_id = Database::query($sql); |
2342 | 2346 | |
@@ -2352,7 +2356,9 @@ discard block |
||
2352 | 2356 | $lp_view_id = $row_lp_view['id']; |
2353 | 2357 | $lp_id = $row_lp_view['lp_id']; |
2354 | 2358 | $user_id = $row_lp_view['user_id']; |
2355 | - if ($debug) echo '<h2>LP id '.$lp_id.'</h2>'; |
|
2359 | + if ($debug) { |
|
2360 | + echo '<h2>LP id '.$lp_id.'</h2>'; |
|
2361 | + } |
|
2356 | 2362 | |
2357 | 2363 | if ($get_only_latest_attempt_results) { |
2358 | 2364 | //Getting lp_items done by the user |
@@ -2409,7 +2415,9 @@ discard block |
||
2409 | 2415 | lp_i.c_id = $course_id AND |
2410 | 2416 | (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."') |
2411 | 2417 | WHERE lp_view_id = $lp_view_id "; |
2412 | - if ($debug) echo $sql.'<br />'; |
|
2418 | + if ($debug) { |
|
2419 | + echo $sql.'<br />'; |
|
2420 | + } |
|
2413 | 2421 | $res_max_score = Database::query($sql); |
2414 | 2422 | |
2415 | 2423 | while ($row_max_score = Database::fetch_array($res_max_score,'ASSOC')) { |
@@ -2428,7 +2436,9 @@ discard block |
||
2428 | 2436 | $max_score_item_view = $row_max_score['max_score_item_view']; |
2429 | 2437 | $score = $row_max_score['score']; |
2430 | 2438 | |
2431 | - if ($debug) echo '<h3>Item Type: ' .$row_max_score['item_type'].'</h3>'; |
|
2439 | + if ($debug) { |
|
2440 | + echo '<h3>Item Type: ' .$row_max_score['item_type'].'</h3>'; |
|
2441 | + } |
|
2432 | 2442 | |
2433 | 2443 | if ($row_max_score['item_type'] == 'sco') { |
2434 | 2444 | /* Check if it is sco (easier to get max_score) |
@@ -2448,7 +2458,9 @@ discard block |
||
2448 | 2458 | if (!empty($max_score)) { |
2449 | 2459 | $lp_partial_total += $score/$max_score; |
2450 | 2460 | } |
2451 | - if ($debug) echo '<b>$lp_partial_total, $score, $max_score '.$lp_partial_total.' '.$score.' '.$max_score.'</b><br />'; |
|
2461 | + if ($debug) { |
|
2462 | + echo '<b>$lp_partial_total, $score, $max_score '.$lp_partial_total.' '.$score.' '.$max_score.'</b><br />'; |
|
2463 | + } |
|
2452 | 2464 | } else { |
2453 | 2465 | // Case of a TOOL_QUIZ element |
2454 | 2466 | $item_id = $row_max_score['iid']; |
@@ -2470,12 +2482,16 @@ discard block |
||
2470 | 2482 | ORDER BY exe_date DESC |
2471 | 2483 | LIMIT 1"; |
2472 | 2484 | |
2473 | - if ($debug) echo $sql .'<br />'; |
|
2485 | + if ($debug) { |
|
2486 | + echo $sql .'<br />'; |
|
2487 | + } |
|
2474 | 2488 | $result_last_attempt = Database::query($sql); |
2475 | 2489 | $num = Database :: num_rows($result_last_attempt); |
2476 | 2490 | if ($num > 0 ) { |
2477 | 2491 | $id_last_attempt = Database :: result($result_last_attempt, 0, 0); |
2478 | - if ($debug) echo $id_last_attempt.'<br />'; |
|
2492 | + if ($debug) { |
|
2493 | + echo $id_last_attempt.'<br />'; |
|
2494 | + } |
|
2479 | 2495 | |
2480 | 2496 | // Within the last attempt number tracking, get the sum of |
2481 | 2497 | // the max_scores of all questions that it was |
@@ -2494,7 +2510,9 @@ discard block |
||
2494 | 2510 | q.c_id = $course_id |
2495 | 2511 | ) |
2496 | 2512 | AS t"; |
2497 | - if ($debug) echo '$sql: '.$sql.' <br />'; |
|
2513 | + if ($debug) { |
|
2514 | + echo '$sql: '.$sql.' <br />'; |
|
2515 | + } |
|
2498 | 2516 | $res_max_score_bis = Database::query($sql); |
2499 | 2517 | $row_max_score_bis = Database::fetch_array($res_max_score_bis); |
2500 | 2518 | |
@@ -2504,7 +2522,9 @@ discard block |
||
2504 | 2522 | if (!empty($max_score) && floatval($max_score) > 0) { |
2505 | 2523 | $lp_partial_total += $score/$max_score; |
2506 | 2524 | } |
2507 | - if ($debug) echo '$lp_partial_total, $score, $max_score <b>'.$lp_partial_total.' '.$score.' '.$max_score.'</b><br />'; |
|
2525 | + if ($debug) { |
|
2526 | + echo '$lp_partial_total, $score, $max_score <b>'.$lp_partial_total.' '.$score.' '.$max_score.'</b><br />'; |
|
2527 | + } |
|
2508 | 2528 | } |
2509 | 2529 | } |
2510 | 2530 | |
@@ -2517,17 +2537,25 @@ discard block |
||
2517 | 2537 | $count_items++; |
2518 | 2538 | } |
2519 | 2539 | } |
2520 | - if ($debug) echo '$count_items: '.$count_items; |
|
2540 | + if ($debug) { |
|
2541 | + echo '$count_items: '.$count_items; |
|
2542 | + } |
|
2521 | 2543 | } |
2522 | 2544 | } //end for |
2523 | 2545 | |
2524 | 2546 | $score_of_scorm_calculate += $count_items ? (($lp_partial_total / $count_items) * 100) : 0; |
2525 | 2547 | |
2526 | - if ($debug) echo '<h3>$count_items '.$count_items.'</h3>'; |
|
2527 | - if ($debug) echo '<h3>$score_of_scorm_calculate '.$score_of_scorm_calculate.'</h3>'; |
|
2548 | + if ($debug) { |
|
2549 | + echo '<h3>$count_items '.$count_items.'</h3>'; |
|
2550 | + } |
|
2551 | + if ($debug) { |
|
2552 | + echo '<h3>$score_of_scorm_calculate '.$score_of_scorm_calculate.'</h3>'; |
|
2553 | + } |
|
2528 | 2554 | |
2529 | 2555 | $global_result += $score_of_scorm_calculate; |
2530 | - if ($debug) echo '<h3>$global_result '.$global_result.'</h3>'; |
|
2556 | + if ($debug) { |
|
2557 | + echo '<h3>$global_result '.$global_result.'</h3>'; |
|
2558 | + } |
|
2531 | 2559 | } // end while |
2532 | 2560 | } |
2533 | 2561 | |
@@ -2540,7 +2568,9 @@ discard block |
||
2540 | 2568 | c_id = $course_id AND |
2541 | 2569 | (item_type = 'quiz' OR item_type = 'sco') AND |
2542 | 2570 | lp_id = ".$lp_id; |
2543 | - if ($debug) echo $sql; |
|
2571 | + if ($debug) { |
|
2572 | + echo $sql; |
|
2573 | + } |
|
2544 | 2574 | $result_have_quiz = Database::query($sql); |
2545 | 2575 | |
2546 | 2576 | if (Database::num_rows($result_have_quiz) > 0 ) { |
@@ -2551,19 +2581,29 @@ discard block |
||
2551 | 2581 | } |
2552 | 2582 | } |
2553 | 2583 | |
2554 | - if ($debug) echo '<h3>$lp_with_quiz '.$lp_with_quiz.' </h3>'; |
|
2555 | - if ($debug) echo '<h3>Final return</h3>'; |
|
2584 | + if ($debug) { |
|
2585 | + echo '<h3>$lp_with_quiz '.$lp_with_quiz.' </h3>'; |
|
2586 | + } |
|
2587 | + if ($debug) { |
|
2588 | + echo '<h3>Final return</h3>'; |
|
2589 | + } |
|
2556 | 2590 | |
2557 | 2591 | if ($lp_with_quiz != 0) { |
2558 | 2592 | if (!$return_array) { |
2559 | 2593 | $score_of_scorm_calculate = round(($global_result/$lp_with_quiz),2); |
2560 | - if ($debug) var_dump($score_of_scorm_calculate); |
|
2594 | + if ($debug) { |
|
2595 | + var_dump($score_of_scorm_calculate); |
|
2596 | + } |
|
2561 | 2597 | if (empty($lp_ids)) { |
2562 | - if ($debug) echo '<h2>All lps fix: '.$score_of_scorm_calculate.'</h2>'; |
|
2598 | + if ($debug) { |
|
2599 | + echo '<h2>All lps fix: '.$score_of_scorm_calculate.'</h2>'; |
|
2600 | + } |
|
2563 | 2601 | } |
2564 | 2602 | return $score_of_scorm_calculate; |
2565 | 2603 | } else { |
2566 | - if ($debug) var_dump($global_result, $lp_with_quiz); |
|
2604 | + if ($debug) { |
|
2605 | + var_dump($global_result, $lp_with_quiz); |
|
2606 | + } |
|
2567 | 2607 | return array($global_result, $lp_with_quiz); |
2568 | 2608 | } |
2569 | 2609 | } else { |
@@ -3050,11 +3090,13 @@ discard block |
||
3050 | 3090 | |
3051 | 3091 | if (!empty ($id_session)) { |
3052 | 3092 | $sql .= ' WHERE session_course.session_id=' . $id_session; |
3053 | - if (api_is_multiple_url_enabled()) |
|
3054 | - $sql .= ' AND access_url_id = '.$access_url_id; |
|
3055 | - } else { |
|
3056 | - if (api_is_multiple_url_enabled()) |
|
3057 | - $sql .= ' WHERE access_url_id = '.$access_url_id; |
|
3093 | + if (api_is_multiple_url_enabled()) { |
|
3094 | + $sql .= ' AND access_url_id = '.$access_url_id; |
|
3095 | + } |
|
3096 | + } else { |
|
3097 | + if (api_is_multiple_url_enabled()) { |
|
3098 | + $sql .= ' WHERE access_url_id = '.$access_url_id; |
|
3099 | + } |
|
3058 | 3100 | } |
3059 | 3101 | |
3060 | 3102 | $result = Database::query($sql); |
@@ -3162,8 +3204,7 @@ discard block |
||
3162 | 3204 | if ($session['access_start_date'] == '0000-00-00 00:00:00' || empty($session['access_start_date']) |
3163 | 3205 | ) { |
3164 | 3206 | $session['status'] = get_lang('SessionActive'); |
3165 | - } |
|
3166 | - else { |
|
3207 | + } else { |
|
3167 | 3208 | $time_start = api_strtotime($session['access_start_date'], 'UTC'); |
3168 | 3209 | $time_end = api_strtotime($session['access_end_date'], 'UTC'); |
3169 | 3210 | if ($time_start < time() && time() < $time_end) { |
@@ -6599,8 +6640,9 @@ discard block |
||
6599 | 6640 | if (is_array($hpresults)) { |
6600 | 6641 | for($i = 0; $i < sizeof($hpresults); $i++) { |
6601 | 6642 | $title = GetQuizName($hpresults[$i][0],''); |
6602 | - if ($title == '') |
|
6603 | - $title = basename($hpresults[$i][0]); |
|
6643 | + if ($title == '') { |
|
6644 | + $title = basename($hpresults[$i][0]); |
|
6645 | + } |
|
6604 | 6646 | $display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get()); |
6605 | 6647 | ?> |
6606 | 6648 | <tr> |
@@ -6972,8 +7014,9 @@ discard block |
||
6972 | 7014 | for($i = 0; $i < sizeof($hpresults); $i++) { |
6973 | 7015 | $title = GetQuizName($hpresults[$i][0],''); |
6974 | 7016 | |
6975 | - if ($title == '') |
|
6976 | - $title = basename($hpresults[$i][0]); |
|
7017 | + if ($title == '') { |
|
7018 | + $title = basename($hpresults[$i][0]); |
|
7019 | + } |
|
6977 | 7020 | |
6978 | 7021 | $display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get()); |
6979 | 7022 |