diff options
author | rvelices <rv-github@modusoptimus.com> | 2008-03-06 02:29:29 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2008-03-06 02:29:29 +0000 |
commit | d96b476bd8dc2c38c68294a82c786c9d2a32d288 (patch) | |
tree | d199be649c85722649cacad548196a9fd643956b /admin/include/functions_plugins.inc.php | |
parent | 37446caa5c362d998be6e1343995a5a7548a98a6 (diff) |
- plugins.php does only the tabsheet - nothing else
- need to review plugins_update.php upgrade action
git-svn-id: http://piwigo.org/svn/trunk@2255 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | admin/include/functions_plugins.inc.php | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/admin/include/functions_plugins.inc.php b/admin/include/functions_plugins.inc.php index b51a22fd2..3e79988fd 100644 --- a/admin/include/functions_plugins.inc.php +++ b/admin/include/functions_plugins.inc.php @@ -85,6 +85,93 @@ function get_fs_plugins() } /** + * Activates a plugin. It will be loaded only on the next page ... + * @param string $plugin_id the plugin to activate + * @param array $errors errors to be returned + */ +function activate_plugin($plugin_id, &$errors) +{ + // the plugin_id must exist in the DB as inactive + $db_plugins = get_db_plugins('', $plugin_id); + if (!empty($db_plugins)) + { + $crt_db_plugin = $db_plugins[0]; + if ($crt_db_plugin['state'] != 'inactive') + { + array_push($errors, 'CANNOT ACTIVATE - INVALID CURRENT STATE ' . $crt_db_plugin['state']); + return false; + } + } + else + { + array_push($errors, 'CANNOT ACTIVATE - NOT INSTALLED'); + return false; + } + + // now try to activate it + $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php'; + if (file_exists($file_to_include)) + { + include_once($file_to_include); + if (function_exists('plugin_activate')) + { + plugin_activate($plugin_id, $crt_db_plugin['version'], $errors); + } + } + if (empty($errors)) + { + $query = ' +UPDATE ' . PLUGINS_TABLE . ' SET state="active" WHERE id="' . $plugin_id . '"'; + pwg_query($query); + return true; + } + return false; +} + + +/** + * Deactivates a plugin. It will be unloaded only on the next page ... + * @param string $plugin_id the plugin to activate + * @param array $errors errors to be returned + */ +function deactivate_plugin($plugin_id, &$errors) +{ + // the plugin_id must exist in the DB as inactive + $db_plugins = get_db_plugins('', $plugin_id); + if (!empty($db_plugins)) + { + $crt_db_plugin = $db_plugins[0]; + if ($crt_db_plugin['state'] != 'active') + { + array_push($errors, 'CANNOT DEACTIVATE - INVALID CURRENT STATE ' . $crt_db_plugin['state']); + return false; + } + } + else + { + array_push($errors, 'CANNOT DEACTIVATE - NOT INSTALLED'); + return false; + } + + // now try to deactivate it + $query = ' +UPDATE ' . PLUGINS_TABLE . ' SET state="inactive" WHERE id="' . $plugin_id . '"'; + pwg_query($query); + + $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php'; + if (file_exists($file_to_include)) + { + include_once($file_to_include); + if (function_exists('plugin_deactivate')) + { + plugin_deactivate($plugin_id); + } + } + return true; +} + + +/** * Retrieves an url for a plugin page. * @param string file - php script full name */ @@ -287,6 +374,7 @@ function extension_name_compare($a, $b) { return strcmp(strtolower($a['ext_name']), strtolower($b['ext_name'])); } + function extension_author_compare($a, $b) { $r = strcmp(strtolower($a['author']), strtolower($b['author'])); @@ -294,4 +382,14 @@ function extension_author_compare($a, $b) else return $r; } +function plugin_author_compare($a, $b) +{ + return strcasecmp( $a['author'], $b['author']); +} + +function plugin_version_compare($a, $b) +{ + return version_compare( $a['version'], $b['version']); +} + ?>
\ No newline at end of file |