Changeset 3677 for extensions/floPure/tools/floPure.class.php
- Timestamp:
- Jul 25, 2009, 6:08:26 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/floPure/tools/floPure.class.php
r3586 r3677 57 57 closedir ($dh); // on ferme le repertoire courant 58 58 } 59 function url_is_remote($url) 60 { 61 if ( strncmp($url, 'http://', 7)==0 62 or strncmp($url, 'https://', 8)==0 ) 63 { 64 return true; 65 } 66 return false; 67 } 68 69 function fetchRemote($src, &$dest, $user_agent='Piwigo', $step=0) 70 { 71 // Try to retrieve data from local file? 72 if (!$this->url_is_remote($src)) 73 { 74 $content = @file_get_contents($src); 75 if ($content !== false) 76 { 77 is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 78 return true; 79 } 80 else 81 { 82 return false; 83 } 84 } 85 86 // After 3 redirections, return false 87 if ($step > 3) return false; 88 89 // Initialize $dest 90 is_resource($dest) or $dest = ''; 91 92 // Try curl to read remote file 93 if (function_exists('curl_init')) 94 { 95 $ch = @curl_init(); 96 @curl_setopt($ch, CURLOPT_URL, $src); 97 @curl_setopt($ch, CURLOPT_HEADER, 1); 98 @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); 99 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 100 $content = @curl_exec($ch); 101 $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); 102 $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); 103 @curl_close($ch); 104 if ($content !== false and $status >= 200 and $status < 400) 105 { 106 if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m)) 107 { 108 return $this->fetchRemote($m[1], $dest, $user_agent, $step+1); 109 } 110 $content = substr($content, $header_length); 111 is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 112 return true; 113 } 114 } 115 116 // Try file_get_contents to read remote file 117 if (ini_get('allow_url_fopen')) 118 { 119 $content = @file_get_contents($src); 120 if ($content !== false) 121 { 122 is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 123 return true; 124 } 125 } 126 127 // Try fsockopen to read remote file 128 $src = parse_url($src); 129 $host = $src['host']; 130 $path = isset($src['path']) ? $src['path'] : '/'; 131 $path .= isset($src['query']) ? '?'.$src['query'] : ''; 132 133 if (($s = @fsockopen($host,80,$errno,$errstr,5)) === false) 134 { 135 return false; 136 } 137 138 fwrite($s, 139 "GET ".$path." HTTP/1.0\r\n" 140 ."Host: ".$host."\r\n" 141 ."User-Agent: ".$user_agent."\r\n" 142 ."Accept: */*\r\n" 143 ."\r\n" 144 ); 145 146 $i = 0; 147 $in_content = false; 148 while (!feof($s)) 149 { 150 $line = fgets($s); 151 152 if (rtrim($line,"\r\n") == '' && !$in_content) 153 { 154 $in_content = true; 155 $i++; 156 continue; 157 } 158 if ($i == 0) 159 { 160 if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/',rtrim($line,"\r\n"), $m)) 161 { 162 fclose($s); 163 return false; 164 } 165 $status = (integer) $m[2]; 166 if ($status < 200 || $status >= 400) 167 { 168 fclose($s); 169 return false; 170 } 171 } 172 if (!$in_content) 173 { 174 if (preg_match('/Location:\s+?(.+)$/',rtrim($line,"\r\n"),$m)) 175 { 176 fclose($s); 177 return $this->fetchRemote(trim($m[1]),$dest,$user_agent,$step+1); 178 } 179 $i++; 180 continue; 181 } 182 is_resource($dest) ? @fwrite($dest, $line) : $dest .= $line; 183 $i++; 184 } 185 fclose($s); 186 return true; 187 } 188 189 59 190 function is_not_up_to_date($v_local, $eid) 60 191 {
Note: See TracChangeset
for help on using the changeset viewer.