Index: /extensions/autoupdate/autoupdate.php =================================================================== --- /extensions/autoupdate/autoupdate.php (revision 3897) +++ /extensions/autoupdate/autoupdate.php (revision 3898) @@ -13,5 +13,5 @@ if (is_dir($pathfile)) { - deltree($pathfile); + autoupdate_deltree($pathfile); } else @@ -23,4 +23,49 @@ 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 @fetchRemote(PHPWG_URL.'/download/latest_version', $result)) + { + $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+'); + @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').'