[25281] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based photo gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | |
---|
[25281] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * API method |
---|
| 26 | * Returns the list of all plugins |
---|
| 27 | * @param mixed[] $params |
---|
| 28 | */ |
---|
[27694] | 29 | function ws_plugins_getList($params, $service) |
---|
[25281] | 30 | { |
---|
| 31 | include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); |
---|
| 32 | |
---|
| 33 | $plugins = new plugins(); |
---|
| 34 | $plugins->sort_fs_plugins('name'); |
---|
| 35 | $plugin_list = array(); |
---|
| 36 | |
---|
| 37 | foreach ($plugins->fs_plugins as $plugin_id => $fs_plugin) |
---|
| 38 | { |
---|
| 39 | if (isset($plugins->db_plugins_by_id[$plugin_id])) |
---|
| 40 | { |
---|
| 41 | $state = $plugins->db_plugins_by_id[$plugin_id]['state']; |
---|
| 42 | } |
---|
| 43 | else |
---|
| 44 | { |
---|
| 45 | $state = 'uninstalled'; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | $plugin_list[] = array( |
---|
| 49 | 'id' => $plugin_id, |
---|
| 50 | 'name' => $fs_plugin['name'], |
---|
| 51 | 'version' => $fs_plugin['version'], |
---|
| 52 | 'state' => $state, |
---|
| 53 | 'description' => $fs_plugin['description'], |
---|
| 54 | ); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | return $plugin_list; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * API method |
---|
| 62 | * Performs an action on a plugin |
---|
| 63 | * @param mixed[] $params |
---|
| 64 | * @option string action |
---|
| 65 | * @option string plugin |
---|
| 66 | * @option string pwg_token |
---|
| 67 | */ |
---|
[27694] | 68 | function ws_plugins_performAction($params, $service) |
---|
[25281] | 69 | { |
---|
| 70 | global $template; |
---|
| 71 | |
---|
| 72 | if (get_pwg_token() != $params['pwg_token']) |
---|
| 73 | { |
---|
| 74 | return new PwgError(403, 'Invalid security token'); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | define('IN_ADMIN', true); |
---|
| 78 | include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); |
---|
| 79 | |
---|
| 80 | $plugins = new plugins(); |
---|
| 81 | $errors = $plugins->perform_action($params['action'], $params['plugin']); |
---|
| 82 | |
---|
| 83 | if (!empty($errors)) |
---|
| 84 | { |
---|
| 85 | return new PwgError(500, $errors); |
---|
| 86 | } |
---|
| 87 | else |
---|
| 88 | { |
---|
| 89 | if (in_array($params['action'], array('activate', 'deactivate'))) |
---|
| 90 | { |
---|
| 91 | $template->delete_compiled_templates(); |
---|
| 92 | } |
---|
| 93 | return true; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | /** |
---|
| 98 | * API method |
---|
| 99 | * Performs an action on a theme |
---|
| 100 | * @param mixed[] $params |
---|
| 101 | * @option string action |
---|
| 102 | * @option string theme |
---|
| 103 | * @option string pwg_token |
---|
| 104 | */ |
---|
[27694] | 105 | function ws_themes_performAction($params, $service) |
---|
[25281] | 106 | { |
---|
| 107 | global $template; |
---|
| 108 | |
---|
| 109 | if (get_pwg_token() != $params['pwg_token']) |
---|
| 110 | { |
---|
| 111 | return new PwgError(403, 'Invalid security token'); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | define('IN_ADMIN', true); |
---|
| 115 | include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); |
---|
| 116 | |
---|
| 117 | $themes = new themes(); |
---|
| 118 | $errors = $themes->perform_action($params['action'], $params['theme']); |
---|
| 119 | |
---|
| 120 | if (!empty($errors)) |
---|
| 121 | { |
---|
| 122 | return new PwgError(500, $errors); |
---|
| 123 | } |
---|
| 124 | else |
---|
| 125 | { |
---|
| 126 | if (in_array($params['action'], array('activate', 'deactivate'))) |
---|
| 127 | { |
---|
| 128 | $template->delete_compiled_templates(); |
---|
| 129 | } |
---|
| 130 | return true; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | * API method |
---|
| 136 | * Updates an extension |
---|
| 137 | * @param mixed[] $params |
---|
| 138 | * @option string type |
---|
| 139 | * @option string id |
---|
| 140 | * @option string revision |
---|
| 141 | * @option string pwg_token |
---|
| 142 | * @option bool reactivate (optional - undocumented) |
---|
| 143 | */ |
---|
[27694] | 144 | function ws_extensions_update($params, $service) |
---|
[25281] | 145 | { |
---|
| 146 | if (!is_webmaster()) |
---|
| 147 | { |
---|
| 148 | return new PwgError(401, l10n('Webmaster status is required.')); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | if (get_pwg_token() != $params['pwg_token']) |
---|
| 152 | { |
---|
| 153 | return new PwgError(403, 'Invalid security token'); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | if (!in_array($params['type'], array('plugins', 'themes', 'languages'))) |
---|
| 157 | { |
---|
| 158 | return new PwgError(403, "invalid extension type"); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 162 | include_once(PHPWG_ROOT_PATH.'admin/include/'.$params['type'].'.class.php'); |
---|
| 163 | |
---|
| 164 | $type = $params['type']; |
---|
| 165 | $extension_id = $params['id']; |
---|
| 166 | $revision = $params['revision']; |
---|
| 167 | |
---|
| 168 | $extension = new $type(); |
---|
| 169 | |
---|
| 170 | if ($type == 'plugins') |
---|
| 171 | { |
---|
| 172 | if ( |
---|
| 173 | isset($extension->db_plugins_by_id[$extension_id]) |
---|
| 174 | and $extension->db_plugins_by_id[$extension_id]['state'] == 'active' |
---|
| 175 | ) |
---|
| 176 | { |
---|
| 177 | $extension->perform_action('deactivate', $extension_id); |
---|
| 178 | |
---|
| 179 | redirect(PHPWG_ROOT_PATH |
---|
| 180 | . 'ws.php' |
---|
| 181 | . '?method=pwg.extensions.update' |
---|
| 182 | . '&type=plugins' |
---|
| 183 | . '&id=' . $extension_id |
---|
| 184 | . '&revision=' . $revision |
---|
| 185 | . '&reactivate=true' |
---|
| 186 | . '&pwg_token=' . get_pwg_token() |
---|
| 187 | . '&format=json' |
---|
| 188 | ); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | $upgrade_status = $extension->extract_plugin_files('upgrade', $revision, $extension_id); |
---|
| 192 | $extension_name = $extension->fs_plugins[$extension_id]['name']; |
---|
| 193 | |
---|
| 194 | if (isset($params['reactivate'])) |
---|
| 195 | { |
---|
| 196 | $extension->perform_action('activate', $extension_id); |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | else if ($type == 'themes') |
---|
| 200 | { |
---|
| 201 | $upgrade_status = $extension->extract_theme_files('upgrade', $revision, $extension_id); |
---|
| 202 | $extension_name = $extension->fs_themes[$extension_id]['name']; |
---|
| 203 | } |
---|
| 204 | else if ($type == 'languages') |
---|
| 205 | { |
---|
| 206 | $upgrade_status = $extension->extract_language_files('upgrade', $revision, $extension_id); |
---|
| 207 | $extension_name = $extension->fs_languages[$extension_id]['name']; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | global $template; |
---|
| 211 | $template->delete_compiled_templates(); |
---|
| 212 | |
---|
| 213 | switch ($upgrade_status) |
---|
| 214 | { |
---|
| 215 | case 'ok': |
---|
| 216 | return l10n('%s has been successfully updated.', $extension_name); |
---|
| 217 | |
---|
| 218 | case 'temp_path_error': |
---|
| 219 | return new PwgError(null, l10n('Can\'t create temporary file.')); |
---|
| 220 | |
---|
| 221 | case 'dl_archive_error': |
---|
| 222 | return new PwgError(null, l10n('Can\'t download archive.')); |
---|
| 223 | |
---|
| 224 | case 'archive_error': |
---|
| 225 | return new PwgError(null, l10n('Can\'t read or extract archive.')); |
---|
| 226 | |
---|
| 227 | default: |
---|
| 228 | return new PwgError(null, l10n('An error occured during extraction (%s).', $upgrade_status)); |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | /** |
---|
| 233 | * API method |
---|
| 234 | * Ignore an update |
---|
| 235 | * @param mixed[] $params |
---|
| 236 | * @option string type (optional) |
---|
| 237 | * @option string id (optional) |
---|
| 238 | * @option bool reset |
---|
| 239 | * @option string pwg_token |
---|
| 240 | */ |
---|
[27694] | 241 | function ws_extensions_ignoreupdate($params, $service) |
---|
[25281] | 242 | { |
---|
| 243 | global $conf; |
---|
| 244 | |
---|
| 245 | define('IN_ADMIN', true); |
---|
| 246 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 247 | |
---|
| 248 | if (!is_webmaster()) |
---|
| 249 | { |
---|
| 250 | return new PwgError(401, 'Access denied'); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | if (get_pwg_token() != $params['pwg_token']) |
---|
| 254 | { |
---|
| 255 | return new PwgError(403, 'Invalid security token'); |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | $conf['updates_ignored'] = unserialize($conf['updates_ignored']); |
---|
| 259 | |
---|
| 260 | // Reset ignored extension |
---|
| 261 | if ($params['reset']) |
---|
| 262 | { |
---|
| 263 | if (!empty($params['type']) and isset($conf['updates_ignored'][ $params['type'] ])) |
---|
| 264 | { |
---|
| 265 | $conf['updates_ignored'][$params['type']] = array(); |
---|
| 266 | } |
---|
| 267 | else |
---|
| 268 | { |
---|
| 269 | $conf['updates_ignored'] = array( |
---|
| 270 | 'plugins'=>array(), |
---|
| 271 | 'themes'=>array(), |
---|
| 272 | 'languages'=>array() |
---|
| 273 | ); |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | conf_update_param('updates_ignored', pwg_db_real_escape_string(serialize($conf['updates_ignored']))); |
---|
| 277 | unset($_SESSION['extensions_need_update']); |
---|
| 278 | return true; |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | if (empty($params['id']) or empty($params['type']) or !in_array($params['type'], array('plugins', 'themes', 'languages'))) |
---|
| 282 | { |
---|
| 283 | return new PwgError(403, 'Invalid parameters'); |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | // Add or remove extension from ignore list |
---|
| 287 | if (!in_array($params['id'], $conf['updates_ignored'][ $params['type'] ])) |
---|
| 288 | { |
---|
| 289 | $conf['updates_ignored'][ $params['type'] ][] = $params['id']; |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | conf_update_param('updates_ignored', pwg_db_real_escape_string(serialize($conf['updates_ignored']))); |
---|
| 293 | unset($_SESSION['extensions_need_update']); |
---|
| 294 | return true; |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | /** |
---|
| 298 | * API method |
---|
| 299 | * Checks for updates (core and extensions) |
---|
| 300 | * @param mixed[] $params |
---|
| 301 | */ |
---|
[27694] | 302 | function ws_extensions_checkupdates($params, $service) |
---|
[25281] | 303 | { |
---|
| 304 | global $conf; |
---|
| 305 | |
---|
| 306 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 307 | include_once(PHPWG_ROOT_PATH.'admin/include/updates.class.php'); |
---|
| 308 | |
---|
| 309 | $update = new updates(); |
---|
| 310 | $result = array(); |
---|
| 311 | |
---|
| 312 | if (!isset($_SESSION['need_update'])) |
---|
| 313 | { |
---|
| 314 | $update->check_piwigo_upgrade(); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | $result['piwigo_need_update'] = $_SESSION['need_update']; |
---|
| 318 | |
---|
| 319 | $conf['updates_ignored'] = unserialize($conf['updates_ignored']); |
---|
| 320 | |
---|
| 321 | if (!isset($_SESSION['extensions_need_update'])) |
---|
| 322 | { |
---|
| 323 | $update->check_extensions(); |
---|
| 324 | } |
---|
| 325 | else |
---|
| 326 | { |
---|
| 327 | $update->check_updated_extensions(); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | if (!is_array($_SESSION['extensions_need_update'])) |
---|
| 331 | { |
---|
| 332 | $result['ext_need_update'] = null; |
---|
| 333 | } |
---|
| 334 | else |
---|
| 335 | { |
---|
| 336 | $result['ext_need_update'] = !empty($_SESSION['extensions_need_update']); |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | return $result; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | ?> |
---|