1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2010 Pierrick LE GALL http://piwigo.org | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | This program is free software; you can redistribute it and/or modify | |
---|
8 | // | it under the terms of the GNU General Public License as published by | |
---|
9 | // | the Free Software Foundation | |
---|
10 | // | | |
---|
11 | // | This program is distributed in the hope that it will be useful, but | |
---|
12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
14 | // | General Public License for more details. | |
---|
15 | // | | |
---|
16 | // | You should have received a copy of the GNU General Public License | |
---|
17 | // | along with this program; if not, write to the Free Software | |
---|
18 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
19 | // | USA. | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | |
---|
22 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
23 | { |
---|
24 | die ("Hacking attempt!"); |
---|
25 | } |
---|
26 | |
---|
27 | include_once(PHPWG_ROOT_PATH.'admin/include/updates.class.php'); |
---|
28 | include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); |
---|
29 | |
---|
30 | /* |
---|
31 | STEP: |
---|
32 | 0 = check is needed. If version is latest or check fail, we stay on step 0 |
---|
33 | 1 = new version on same branch AND new branch are available => user may choose upgrade. |
---|
34 | 2 = upgrade on same branch |
---|
35 | 3 = upgrade on different branch |
---|
36 | */ |
---|
37 | $step = isset($_GET['step']) ? $_GET['step'] : 0; |
---|
38 | $upgrade_to = isset($_GET['to']) ? $_GET['to'] : ''; |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | Step 0 | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | if ($step == 0) |
---|
44 | { |
---|
45 | $template->assign(array( |
---|
46 | 'CHECK_VERSION' => false, |
---|
47 | 'DEV_VERSION' => false, |
---|
48 | ) |
---|
49 | ); |
---|
50 | |
---|
51 | if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches)) |
---|
52 | { |
---|
53 | $url = PHPWG_URL.'/download/all_versions.php'; |
---|
54 | $url .= '?rand='.md5(uniqid(rand(), true)); // Avoid server cache |
---|
55 | |
---|
56 | if (@fetchRemote($url, $result) |
---|
57 | and $all_versions = @explode("\n", $result) |
---|
58 | and is_array($all_versions)) |
---|
59 | { |
---|
60 | $template->assign('CHECK_VERSION', true); |
---|
61 | |
---|
62 | $last_version = trim($all_versions[0]); |
---|
63 | $upgrade_to = $last_version; |
---|
64 | |
---|
65 | if (version_compare(PHPWG_VERSION, $last_version, '<')) |
---|
66 | { |
---|
67 | $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $last_version); |
---|
68 | $actual_branch = $matches[1]; |
---|
69 | |
---|
70 | if ($new_branch == $actual_branch) |
---|
71 | { |
---|
72 | $step = 2; |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | $step = 3; |
---|
77 | |
---|
78 | // Check if new version exists in same branch |
---|
79 | foreach ($all_versions as $version) |
---|
80 | { |
---|
81 | $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $version); |
---|
82 | |
---|
83 | if ($new_branch == $actual_branch) |
---|
84 | { |
---|
85 | if (version_compare(PHPWG_VERSION, $version, '<')) |
---|
86 | { |
---|
87 | $step = 1; |
---|
88 | } |
---|
89 | break; |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | else |
---|
97 | { |
---|
98 | $template->assign('DEV_VERSION', true); |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | // +-----------------------------------------------------------------------+ |
---|
103 | // | Step 1 | |
---|
104 | // +-----------------------------------------------------------------------+ |
---|
105 | if ($step == 1) |
---|
106 | { |
---|
107 | $template->assign(array( |
---|
108 | 'MINOR_VERSION' => $version, |
---|
109 | 'MAJOR_VERSION' => $last_version, |
---|
110 | ) |
---|
111 | ); |
---|
112 | } |
---|
113 | |
---|
114 | // +-----------------------------------------------------------------------+ |
---|
115 | // | Step 2 | |
---|
116 | // +-----------------------------------------------------------------------+ |
---|
117 | if ($step == 2 and is_webmaster()) |
---|
118 | { |
---|
119 | if (isset($_POST['submit']) and isset($_POST['upgrade_to'])) |
---|
120 | { |
---|
121 | updates::upgrade_to($_POST['upgrade_to'], $step); |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | // +-----------------------------------------------------------------------+ |
---|
126 | // | Step 3 | |
---|
127 | // +-----------------------------------------------------------------------+ |
---|
128 | if ($step == 3 and is_webmaster()) |
---|
129 | { |
---|
130 | // Remote sites are not compatible with Piwigo 2.4+ |
---|
131 | $has_remote_site = false; |
---|
132 | |
---|
133 | $query = 'SELECT galleries_url FROM '.SITES_TABLE.';'; |
---|
134 | $result = pwg_query($query); |
---|
135 | while ($row = pwg_db_fetch_assoc($result)) |
---|
136 | { |
---|
137 | if (url_is_remote($row['galleries_url'])) |
---|
138 | { |
---|
139 | $has_remote_site = true; |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | if ($has_remote_site) |
---|
144 | { |
---|
145 | $url = PHPWG_URL.'/download/messages/upgrade24-remote-sites.php'; |
---|
146 | $url.= '?lang='.$user['language']; |
---|
147 | $url.= '&rand='.md5(uniqid(rand(), true)); // Avoid server cache |
---|
148 | |
---|
149 | $result = null; |
---|
150 | if (@fetchRemote($url, $result)) |
---|
151 | { |
---|
152 | $template->assign('forbid_upgrade_message', $result); |
---|
153 | array_push($page['errors'], $result); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | if (isset($_POST['dumpDatabase'])) |
---|
158 | { |
---|
159 | updates::dump_database(isset($_POST['includeHistory'])); |
---|
160 | } |
---|
161 | |
---|
162 | if (!$has_remote_site and isset($_POST['submit']) and isset($_POST['upgrade_to'])) |
---|
163 | { |
---|
164 | updates::upgrade_to($_POST['upgrade_to'], $step); |
---|
165 | } |
---|
166 | |
---|
167 | $updates = new updates(); |
---|
168 | $updates->get_merged_extensions($upgrade_to); |
---|
169 | $updates->get_server_extensions($upgrade_to); |
---|
170 | $template->assign('missing', $updates->missing); |
---|
171 | } |
---|
172 | |
---|
173 | // +-----------------------------------------------------------------------+ |
---|
174 | // | Process template | |
---|
175 | // +-----------------------------------------------------------------------+ |
---|
176 | |
---|
177 | if (!is_webmaster()) |
---|
178 | { |
---|
179 | array_push($page['errors'], l10n('Webmaster status is required.')); |
---|
180 | } |
---|
181 | |
---|
182 | $template->assign(array( |
---|
183 | 'STEP' => $step, |
---|
184 | 'PHPWG_VERSION' => PHPWG_VERSION, |
---|
185 | 'UPGRADE_TO' => $upgrade_to, |
---|
186 | 'RELEASE_URL' => PHPWG_URL.'/releases/'.$upgrade_to, |
---|
187 | ) |
---|
188 | ); |
---|
189 | |
---|
190 | $template->set_filename('plugin_admin_content', 'updates_pwg.tpl'); |
---|
191 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
192 | |
---|
193 | ?> |
---|