Changeset 4032
- Timestamp:
- Oct 13, 2009, 11:01:43 PM (14 years ago)
- Location:
- extensions/autoupdate
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/autoupdate/autoupdate.php
r4007 r4032 1 1 <?php 2 3 /* Fetch remote function with timeout */ 4 function autoupdate_fetchRemote($src, &$dest, $timeout=0, $user_agent='Piwigo', $step=0) 5 { 6 // Try to retrieve data from local file? 7 if (!url_is_remote($src)) 8 { 9 $content = @file_get_contents($src); 10 if ($content !== false) 11 { 12 is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 13 return true; 14 } 15 else 16 { 17 return false; 18 } 19 } 20 21 // After 3 redirections, return false 22 if ($step > 3) return false; 23 24 // Initialize $dest 25 is_resource($dest) or $dest = ''; 26 27 // Try curl to read remote file 28 if (function_exists('curl_init')) 29 { 30 $ch = @curl_init(); 31 @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 32 @curl_setopt($ch, CURLOPT_URL, $src); 33 @curl_setopt($ch, CURLOPT_HEADER, 1); 34 @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); 35 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 36 $content = @curl_exec($ch); 37 $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); 38 $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); 39 @curl_close($content); 40 if ($content !== false and $status >= 200 and $status < 400) 41 { 42 if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m)) 43 { 44 return autoupdate_fetchRemote($m[1], $dest, $user_agent, $step+1); 45 } 46 $content = substr($content, $header_length); 47 is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 48 return true; 49 } 50 } 51 52 // Try file_get_contents to read remote file 53 if (ini_get('allow_url_fopen')) 54 { 55 $opts['http'] = array('timeout' => $timeout); 56 $ctx = stream_context_create($opts); 57 $content = @file_get_contents($src, 0, $ctx); 58 if ($content !== false) 59 { 60 is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 61 return true; 62 } 63 } 64 65 return false; 66 } 2 67 3 68 function autoupdate_deltree($path) … … 30 95 global $conf, $header_notes; 31 96 32 if (preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches) and @ fetchRemote(PHPWG_URL.'/download/latest_version', $result))97 if (preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches) and @autoupdate_fetchRemote(PHPWG_URL.'/download/latest_version', $result, 1)) 33 98 { 34 99 $lines = @explode("\r\n", $result); … … 49 114 { 50 115 $zip = @fopen($filename, 'w+'); 51 @ fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.str_replace(array('.', '_'), '', $code), $zip);116 @autoupdate_fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.str_replace(array('.', '_'), '', $code), $zip); 52 117 @fclose($zip); 53 118 }
Note: See TracChangeset
for help on using the changeset viewer.