Index: branches/instantcommons/includes/Image.php |
— | — | @@ -371,7 +371,7 @@ |
372 | 372 | $rname=tempnam(wfTempDir(),'icresponse.xml'); |
373 | 373 | $url = $wgInstantCommonsServerPath.'/api.php?action=instantcommons&format=xml&media='.$this->name; |
374 | 374 | $fp = fopen($rname, "w"); |
375 | | - $xmlString = $this-> my_file_get_contents($url, $fp); |
| 375 | + $xmlString = $this-> curl_file_get_contents($url, $fp); |
376 | 376 | $p =& new ApiInstantCommons('instantcommons', 'maint'); |
377 | 377 | fclose($fp); |
378 | 378 | //TODO: Replace the xml-parser with a preg_grep since it's a single line of XML that's returned. |
— | — | @@ -394,12 +394,12 @@ |
395 | 395 | $icFileUrl = $wgInstantCommonsServerPath.$row['URL']; |
396 | 396 | $fp = fopen("{$this->mSavedFile}", "w"); |
397 | 397 | if($row['SIZE'] > 3000) {wfDebug(join($row, ' | ')); |
398 | | - $this-> my_file_get_contents($icFileUrl, $this->mSavedFile, TRUE); |
| 398 | + $this-> curl_file_get_contents($icFileUrl, $this->mSavedFile, TRUE); |
399 | 399 | }else { |
400 | 400 | /* |
401 | 401 | $icFileUrl = $wgInstantCommonsServerPath.$row['URL']; |
402 | 402 | $icFp = fopen("{$this->mSavedFile}", "w"); |
403 | | - my_file_get_contents($icFileUrl, $icFp); |
| 403 | + curl_file_get_contents($icFileUrl, $icFp); |
404 | 404 | fclose($icFp);*/ |
405 | 405 | |
406 | 406 | $ch = curl_init($wgInstantCommonsServerPath.$row['URL']); |
— | — | @@ -456,8 +456,33 @@ |
457 | 457 | $this->dataLoaded = true; |
458 | 458 | wfProfileOut( __METHOD__ ); |
459 | 459 | } |
| 460 | + |
| 461 | + /** |
| 462 | + * Use cURL to read the content of a URL into a string |
| 463 | + * @param string $url - the URL to fetch |
| 464 | + * @param resource $fp - filename to write file contents to |
| 465 | + * @param boolean $bg - call cURL in the background (don't hang page until complete) |
| 466 | + * @param int $timeout - cURL connect timeout |
| 467 | + */ |
| 468 | + function curl_file_get_contents($url, $fp, $bg=FALSE, $timeout = 1){//ref: http://groups-beta.google.com/group/comp.lang.php/browse_thread/thread/8efbbaced3c45e3c/d63c7891cf8e380b?lnk=raot |
| 469 | + if(!$bg){ |
| 470 | + $ch = curl_init(); |
| 471 | + curl_setopt ($ch, CURLOPT_URL, $url); |
| 472 | + curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); |
| 473 | + curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); |
| 474 | + curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout); |
| 475 | + $file_contents = curl_exec($ch); |
| 476 | + curl_close($ch); |
| 477 | + } else {//call curl in the background to download the file |
| 478 | + $cmd = 'curl '.escapeshellcmd($url).' -o '.$fp.'&'; |
| 479 | + wfDebug('Curl download initiated='.$cmd ); |
| 480 | + pclose(popen($cmd, 'r')); |
| 481 | + $file_contents = 1; |
| 482 | + } |
| 483 | + return $file_contents; |
| 484 | + } |
460 | 485 | |
461 | | - /* |
| 486 | + /** |
462 | 487 | * Load image metadata from a DB result row |
463 | 488 | */ |
464 | 489 | function loadFromRow( &$row ) { |