3) return false; // Initialize $dest is_resource($dest) or $dest = ''; // Try curl to read remote file if (function_exists('curl_init')) { $ch = @curl_init(); @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); @curl_setopt($ch, CURLOPT_URL, $src); @curl_setopt($ch, CURLOPT_HEADER, 1); @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $content = @curl_exec($ch); $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); @curl_close($content); if ($content !== false and $status >= 200 and $status < 400) { if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m)) { return autoupdate_fetchRemote($m[1], $dest, $user_agent, $step+1); } $content = substr($content, $header_length); is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; return true; } } // Try file_get_contents to read remote file if (ini_get('allow_url_fopen')) { $opts['http'] = array('timeout' => $timeout); $ctx = stream_context_create($opts); $content = @file_get_contents($src, 0, $ctx); if ($content !== false) { is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; return true; } } return false; } function autoupdate_deltree($path) { if (is_dir($path)) { $fh = opendir($path); while ($file = readdir($fh)) { if ($file != '.' and $file != '..') { $pathfile = $path . '/' . $file; if (is_dir($pathfile)) { autoupdate_deltree($pathfile); } else { @unlink($pathfile); } } } closedir($fh); return @rmdir($path); } } function check_version_for_autoupdate($version=PHPWG_VERSION) { global $conf, $header_notes; if (preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches) and @autoupdate_fetchRemote(PHPWG_URL.'/download/latest_version', $result, 1)) { $lines = @explode("\r\n", $result); $new_version = trim($lines[1]); $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $new_version); $actual_branch = $matches[1]; $update_to = $actual_branch . '.' . ($matches[2]+1); if (version_compare($version, $new_version) < 0 and $actual_branch == $new_branch) { $path = $conf['local_data_dir'].'/autoupdate/'; $code = $version.'_to_'.$update_to; $filename = $path.$version.'_to_'.$update_to.'.zip'; mkgetdir($path); if (!file_exists($filename) or !filesize($filename)) { $zip = @fopen($filename, 'w+'); @autoupdate_fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.str_replace(array('.', '_'), '', $code), $zip); @fclose($zip); } if (file_exists($filename) and filesize($filename)) { if (isset($_GET['autoupdate']) and preg_match('/\d+\.\d+\.\d+_to_'.preg_quote($version).'/', $_GET['autoupdate'])) { redirect('admin.php?autoupdate='.$code); } else { array_push($header_notes, '
'.l10n('A new version of Piwigo is available.').'
',
''.l10n('Click here to upgrade automatically').'