1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | $service = &$arr[0]; |
---|
6 | |
---|
7 | $service->addMethod( |
---|
8 | 'pwg.plugins.update', |
---|
9 | 'ws_plugins_update', |
---|
10 | array( |
---|
11 | 'id' => array(), |
---|
12 | 'revision' => array(), |
---|
13 | 'pwg_token' => array(), |
---|
14 | ), |
---|
15 | 'Update a plugin. Webmaster only.' |
---|
16 | ); |
---|
17 | |
---|
18 | $service->addMethod( |
---|
19 | 'pwg.themes.update', |
---|
20 | 'ws_themes_update', |
---|
21 | array( |
---|
22 | 'id' => array(), |
---|
23 | 'revision' => array(), |
---|
24 | 'pwg_token' => array(), |
---|
25 | ), |
---|
26 | 'Update a theme. Webmaster only.' |
---|
27 | ); |
---|
28 | |
---|
29 | $service->addMethod( |
---|
30 | 'pwg.languages.update', |
---|
31 | 'ws_languages_update', |
---|
32 | array( |
---|
33 | 'id' => array(), |
---|
34 | 'revision'=> array(), |
---|
35 | 'pwg_token' => array(), |
---|
36 | ), |
---|
37 | 'Update a language. Webmaster only.' |
---|
38 | ); |
---|
39 | |
---|
40 | $service->addMethod( |
---|
41 | 'pwg.extensions.checkUpdates', |
---|
42 | 'ws_extensions_checkupdates', |
---|
43 | array(), |
---|
44 | 'Check if piwigo or extensions are up to date.' |
---|
45 | ); |
---|
46 | |
---|
47 | $service->addMethod( |
---|
48 | 'pwg.extensions.ignoreUpdates', |
---|
49 | 'ws_extensions_ignoreupdates', |
---|
50 | array( |
---|
51 | 'type' => array('default'=>null), |
---|
52 | 'id' => array('default'=>null), |
---|
53 | 'reset' => array('default'=>null), |
---|
54 | 'pwg_token' => array(), |
---|
55 | ), |
---|
56 | 'Ignore an extension if it need update.' |
---|
57 | ); |
---|
58 | |
---|
59 | function ws_plugins_update($params, &$service) |
---|
60 | { |
---|
61 | if (!is_webmaster()) |
---|
62 | { |
---|
63 | return new PwgError(401, l10n('Webmaster status is required.')); |
---|
64 | } |
---|
65 | |
---|
66 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
---|
67 | { |
---|
68 | return new PwgError(403, 'Invalid security token'); |
---|
69 | } |
---|
70 | |
---|
71 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
72 | include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); |
---|
73 | $plugins = new plugins(); |
---|
74 | |
---|
75 | if (isset($params['upgradestatus']) and isset($params['id'])) |
---|
76 | { |
---|
77 | switch ($params['upgradestatus']) |
---|
78 | { |
---|
79 | case 'ok': |
---|
80 | return sprintf(l10n('%s has been successfully upgraded.'), $plugins->fs_plugins[$params['id']]['name']); |
---|
81 | |
---|
82 | case 'temp_path_error': |
---|
83 | return new PwgError(null, l10n('Can\'t create temporary file.')); |
---|
84 | |
---|
85 | case 'dl_archive_error': |
---|
86 | return new PwgError(null, l10n('Can\'t download archive.')); |
---|
87 | |
---|
88 | case 'archive_error': |
---|
89 | return new PwgError(null, l10n('Can\'t read or extract archive.')); |
---|
90 | |
---|
91 | default: |
---|
92 | return new PwgError(null, sprintf(l10n('An error occured during extraction (%s).'), $params['upgradestatus'])); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | if (empty($params['id']) or empty($params['revision'])) |
---|
97 | { |
---|
98 | return new PwgError(null, 'Wrong parameters'); |
---|
99 | } |
---|
100 | |
---|
101 | $plugin_id = $params['id']; |
---|
102 | $revision = $params['revision']; |
---|
103 | |
---|
104 | if (isset($plugins->db_plugins_by_id[$plugin_id]) |
---|
105 | and $plugins->db_plugins_by_id[$plugin_id]['state'] == 'active') |
---|
106 | { |
---|
107 | $plugins->perform_action('deactivate', $plugin_id); |
---|
108 | |
---|
109 | redirect(PHPWG_ROOT_PATH |
---|
110 | . 'ws.php' |
---|
111 | . '?method=pwg.plugins.update' |
---|
112 | . '&revision=' . $revision |
---|
113 | . '&id=' . $plugin_id |
---|
114 | . '&reactivate=true' |
---|
115 | . '&pwg_token=' . get_pwg_token() |
---|
116 | . '&format=json' |
---|
117 | ); |
---|
118 | } |
---|
119 | |
---|
120 | $upgrade_status = $plugins->extract_plugin_files('upgrade', $revision, $plugin_id); |
---|
121 | |
---|
122 | if (isset($params['reactivate'])) |
---|
123 | { |
---|
124 | $plugins->perform_action('activate', $plugin_id); |
---|
125 | } |
---|
126 | |
---|
127 | global $template; |
---|
128 | $template->delete_compiled_templates(); |
---|
129 | |
---|
130 | redirect(PHPWG_ROOT_PATH |
---|
131 | . 'ws.php' |
---|
132 | . '?method=pwg.plugins.update' |
---|
133 | . '&revision=' . $revision |
---|
134 | . '&id=' . $plugin_id |
---|
135 | . '&upgradestatus='.$upgrade_status |
---|
136 | . '&pwg_token=' . get_pwg_token() |
---|
137 | . '&format=json' |
---|
138 | ); |
---|
139 | } |
---|
140 | |
---|
141 | function ws_themes_update($params, &$service) |
---|
142 | { |
---|
143 | if (!is_webmaster()) |
---|
144 | { |
---|
145 | return new PwgError(401, l10n('Webmaster status is required.')); |
---|
146 | } |
---|
147 | |
---|
148 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
---|
149 | { |
---|
150 | return new PwgError(403, 'Invalid security token'); |
---|
151 | } |
---|
152 | |
---|
153 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
154 | include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); |
---|
155 | $themes = new themes(); |
---|
156 | |
---|
157 | $theme_id = $params['id']; |
---|
158 | $revision = $params['revision']; |
---|
159 | |
---|
160 | $upgrade_status = $themes->extract_theme_files('upgrade', $revision, $theme_id); |
---|
161 | |
---|
162 | global $template; |
---|
163 | $template->delete_compiled_templates(); |
---|
164 | |
---|
165 | switch ($upgrade_status) |
---|
166 | { |
---|
167 | case 'ok': |
---|
168 | return sprintf(l10n('%s has been successfully upgraded.'), $themes->fs_themes[$theme_id]['name']); |
---|
169 | |
---|
170 | case 'temp_path_error': |
---|
171 | return new PwgError(null, l10n('Can\'t create temporary file.')); |
---|
172 | |
---|
173 | case 'dl_archive_error': |
---|
174 | return new PwgError(null, l10n('Can\'t download archive.')); |
---|
175 | |
---|
176 | case 'archive_error': |
---|
177 | return new PwgError(null, l10n('Can\'t read or extract archive.')); |
---|
178 | |
---|
179 | default: |
---|
180 | return new PwgError(null, sprintf(l10n('An error occured during extraction (%s).'), $upgrade_status)); |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | function ws_languages_update($params, &$service) |
---|
185 | { |
---|
186 | if (!is_webmaster()) |
---|
187 | { |
---|
188 | return new PwgError(401, l10n('Webmaster status is required.')); |
---|
189 | } |
---|
190 | |
---|
191 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
---|
192 | { |
---|
193 | return new PwgError(403, 'Invalid security token'); |
---|
194 | } |
---|
195 | |
---|
196 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
197 | include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php'); |
---|
198 | $languages = new languages(); |
---|
199 | |
---|
200 | $language_id = $params['id']; |
---|
201 | $revision = $params['revision']; |
---|
202 | |
---|
203 | $upgrade_status = $languages->extract_language_files('upgrade', $revision, $language_id); |
---|
204 | |
---|
205 | global $template; |
---|
206 | $template->delete_compiled_templates(); |
---|
207 | |
---|
208 | switch ($upgrade_status) |
---|
209 | { |
---|
210 | case 'ok': |
---|
211 | return sprintf(l10n('%s has been successfully upgraded.'), $languages->fs_languages[$language_id]['name']); |
---|
212 | |
---|
213 | case 'temp_path_error': |
---|
214 | return new PwgError(null, l10n('Can\'t create temporary file.')); |
---|
215 | |
---|
216 | case 'dl_archive_error': |
---|
217 | return new PwgError(null, l10n('Can\'t download archive.')); |
---|
218 | |
---|
219 | case 'archive_error': |
---|
220 | return new PwgError(null, l10n('Can\'t read or extract archive.')); |
---|
221 | |
---|
222 | default: |
---|
223 | return new PwgError(null, sprintf(l10n('An error occured during extraction (%s).'), $upgrade_status)); |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | function ws_extensions_checkupdates($params, &$service) |
---|
228 | { |
---|
229 | define('IN_ADMIN', true); |
---|
230 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
231 | include_once(AUTOUPDATE_PATH.'include/autoupdate.class.php'); |
---|
232 | $autoupdate = new autoupdate(); |
---|
233 | |
---|
234 | if (!is_webmaster()) |
---|
235 | { |
---|
236 | return new PwgError(401, 'Access denied'); |
---|
237 | } |
---|
238 | |
---|
239 | // Check if gallery or plugins are up to date |
---|
240 | load_language('plugin.lang', dirname(dirname(__FILE__)).'/'); |
---|
241 | |
---|
242 | function autoupdate_error() |
---|
243 | { |
---|
244 | unset($_SESSION['extensions_need_update']); |
---|
245 | return new PwgError(null, 'An error occured'); |
---|
246 | } |
---|
247 | |
---|
248 | if (!isset($_SESSION['need_update'])) |
---|
249 | $autoupdate->check_piwigo_upgrade(); |
---|
250 | |
---|
251 | if ($_SESSION['need_update']) |
---|
252 | return 'piwigo_upgrade'; |
---|
253 | |
---|
254 | // Gallery is up to date -> check extensions |
---|
255 | if (!isset($_SESSION['extensions_need_update'])) |
---|
256 | $autoupdate->check_extensions(); |
---|
257 | else |
---|
258 | $autoupdate->check_updated_extensions(); |
---|
259 | |
---|
260 | if (!empty($_SESSION['extensions_need_update'])) |
---|
261 | return 'ext_upgrade'; |
---|
262 | elseif ($_SESSION['need_update'] === false and $_SESSION['extensions_need_update'] === array()) |
---|
263 | return 'up_to_date'; |
---|
264 | |
---|
265 | autoupdate_error(); |
---|
266 | } |
---|
267 | |
---|
268 | function ws_extensions_ignoreupdates($params, &$service) |
---|
269 | { |
---|
270 | global $conf; |
---|
271 | |
---|
272 | define('IN_ADMIN', true); |
---|
273 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
274 | |
---|
275 | if (!is_webmaster()) |
---|
276 | { |
---|
277 | return new PwgError(401, 'Access denied'); |
---|
278 | } |
---|
279 | |
---|
280 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
---|
281 | { |
---|
282 | return new PwgError(403, 'Invalid security token'); |
---|
283 | } |
---|
284 | |
---|
285 | if ($params['reset']) |
---|
286 | { |
---|
287 | $conf['AU_ignore'] = array('plugins'=>array(),'themes'=>array(),'languages'=>array()); |
---|
288 | conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore']))); |
---|
289 | unset($_SESSION['extensions_need_update']); |
---|
290 | return true; |
---|
291 | } |
---|
292 | |
---|
293 | if (empty($params['id']) or empty($params['type']) |
---|
294 | or !in_array($params['type'], array('plugins', 'themes', 'languages'))) |
---|
295 | { |
---|
296 | return new PwgError(null, 'Invalid parameters'); |
---|
297 | } |
---|
298 | |
---|
299 | // Add or remove plugin from ignore list |
---|
300 | if (!in_array($params['id'], $conf['AU_ignore'][$params['type']])) |
---|
301 | { |
---|
302 | array_push($conf['AU_ignore'][$params['type']], $params['id']); |
---|
303 | } |
---|
304 | conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore']))); |
---|
305 | unset($_SESSION['extensions_need_update']); |
---|
306 | return true; |
---|
307 | } |
---|
308 | |
---|
309 | ?> |
---|