1 | <?php |
---|
2 | |
---|
3 | function autoupdate_deltree($path) |
---|
4 | { |
---|
5 | if (is_dir($path)) |
---|
6 | { |
---|
7 | $fh = opendir($path); |
---|
8 | while ($file = readdir($fh)) |
---|
9 | { |
---|
10 | if ($file != '.' and $file != '..') |
---|
11 | { |
---|
12 | $pathfile = $path . '/' . $file; |
---|
13 | if (is_dir($pathfile)) |
---|
14 | { |
---|
15 | deltree($pathfile); |
---|
16 | } |
---|
17 | else |
---|
18 | { |
---|
19 | @unlink($pathfile); |
---|
20 | } |
---|
21 | } |
---|
22 | } |
---|
23 | closedir($fh); |
---|
24 | return @rmdir($path); |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
29 | |
---|
30 | if (isset($_GET['autoupdate'])) |
---|
31 | { |
---|
32 | if ($_GET['autoupdate'] == 'success') |
---|
33 | { |
---|
34 | array_push($page['infos'], sprintf(l10n('autoupdate_success'), PHPWG_VERSION)); |
---|
35 | } |
---|
36 | elseif ($file = $conf['local_data_dir'].'/autoupdate/'.$_GET['autoupdate'].'.zip' and file_exists($file)) |
---|
37 | { |
---|
38 | include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); |
---|
39 | $zip = new PclZip($file); |
---|
40 | if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, PCLZIP_OPT_REMOVE_PATH, $_GET['autoupdate'], PCLZIP_OPT_REPLACE_NEWER)) |
---|
41 | { |
---|
42 | if (file_exists(PHPWG_ROOT_PATH.'obsolete.list') |
---|
43 | and $old_files = file(PHPWG_ROOT_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
44 | and !empty($old_files)) |
---|
45 | { |
---|
46 | array_push($old_files, 'obsolete.list'); |
---|
47 | foreach($old_files as $old_file) |
---|
48 | { |
---|
49 | $path = PHPWG_ROOT_PATH.$old_file; |
---|
50 | if (is_file($path)) |
---|
51 | { |
---|
52 | @unlink($path); |
---|
53 | } |
---|
54 | elseif (is_dir($path)) |
---|
55 | { |
---|
56 | autoupdate_deltree($path); |
---|
57 | } |
---|
58 | } |
---|
59 | } |
---|
60 | autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); |
---|
61 | redirect('admin.php?autoupdate=success'); |
---|
62 | } |
---|
63 | else |
---|
64 | { |
---|
65 | autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); |
---|
66 | array_push($page['errors'], l10n('autoupdate_fail')); |
---|
67 | } |
---|
68 | } |
---|
69 | else |
---|
70 | { |
---|
71 | array_push($page['errors'], l10n('autoupdate_fail')); |
---|
72 | } |
---|
73 | } |
---|
74 | elseif (preg_match('/\d+\.\d+\.\d+/', PHPWG_VERSION) and fetchRemote(PHPWG_URL.'/download/latest_version', $result)) |
---|
75 | { |
---|
76 | $lines = @explode("\r\n", $result); |
---|
77 | $new_version = trim($lines[1]); |
---|
78 | $new_branch = substr($new_version, 0, 3); |
---|
79 | $actual_branch = substr(PHPWG_VERSION, 0, 3); |
---|
80 | $actual_version = $actual_branch . '.x'; |
---|
81 | |
---|
82 | if (version_compare(PHPWG_VERSION, $new_version) < 0 |
---|
83 | and $actual_branch == $new_branch) |
---|
84 | { |
---|
85 | $path = $conf['local_data_dir'].'/autoupdate/'; |
---|
86 | $filename = $path.$actual_version.'_to_'.$new_version.'.zip'; |
---|
87 | mkgetdir($path); |
---|
88 | |
---|
89 | if (!file_exists($filename) or !filesize($filename)) |
---|
90 | { |
---|
91 | $zip = @fopen($filename, 'w+'); |
---|
92 | @fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.str_replace('.', '', $actual_version).'to'.str_replace('.', '', $new_version), $zip); |
---|
93 | @fclose($zip); |
---|
94 | } |
---|
95 | |
---|
96 | if (file_exists($filename) and filesize($filename)) |
---|
97 | { |
---|
98 | array_push($header_notes, |
---|
99 | l10n('A new version of Piwigo is available.').'<br>', |
---|
100 | '<a href="admin.php?autoupdate='.$actual_version.'_to_'.$new_version.'" onClick="return confirm(\''.l10n('autoupdate_alert').'\');">'.l10n('Click here to upgrade automatically').'</a>' |
---|
101 | ); |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | ?> |
---|