working)
* Update shown when the folder is newer than what was installed
* Enable the plugin starts running
* Disable it stops, tables untouched
*/
if (!defined('ACP_ROOT')) {
http_response_code(403);
die('Direct access denied.');
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['clear_plugin_repository_cache'])) {
if (plugin_repository_clear_cache()) {
acp_log('plugins.cache_clear');
acp_flash_success(t('acp.plgbr.cache_deleted'));
} else {
acp_flash_error(t('acp.plgbr.cache_delete_failed', [
'path' => '' . h(plugin_repository_cache_path()) . '',
]));
}
acp_redirect('plugins', array('tab' => 'browse', 'refresh' => 1));
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['repo_install'])) {
$key = znote_plugin_sanitize((string)$_POST['repo_install']);
$overwrite = !empty($_POST['overwrite']);
$result = plugin_repository_install($key, $overwrite);
if ($result === '') {
$sqlError = znote_plugin_install($key);
if ($sqlError !== '') {
acp_flash_error(t('acp.plgbr.install_failed', ['error' => h($sqlError)]));
} else {
znote_plugin_set_enabled($key, true);
acp_log('plugins.repo_install', $key);
$m = znote_plugin_manifest($key);
acp_flash_success(t('acp.plgbr.installed', [
'plugin' => '' . h($m['name']) . '',
'path' => 'plugins/' . h($key) . '/',
]));
}
} elseif ($result === 'already-installed') {
acp_flash_error(t('acp.plgbr.already_installed', ['plugin' => '' . h($key) . '']));
} else {
acp_flash_error(t('acp.plgbr.install_failed', ['error' => h($result)]));
}
acp_redirect('plugins', array('tab' => 'browse'));
}
if (($_GET['tab'] ?? '') === 'browse') {
// "Refresh catalogue" also wipes the local caches - a stale cache is what
// usually keeps a just-installed or updated plugin from showing correctly.
if (isset($_GET['refresh']) && function_exists('znote_cache_flush')) {
znote_cache_flush();
acp_log('plugins.catalogue_refresh');
}
include ACP_ROOT . '/modules/_partials/plugins_browse.php';
return;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = znote_plugin_sanitize((string)($_POST['plugin'] ?? ''));
$action = (string)($_POST['action'] ?? '');
$known = znote_plugins(true);
if ($name === '' || !isset($known[$name])) {
acp_flash_error(t('acp.plg.no_such'));
acp_redirect('plugins');
}
$plugin = $known[$name];
$label = $plugin['name'];
switch ($action) {
case 'install':
$error = znote_plugin_install($name);
if ($error !== '') {
acp_flash_error(t('acp.plg.install_failed', ['plugin' => $label, 'error' => $error]));
break;
}
// Installing implies wanting it on. Nobody installs a plugin in
// order to leave it switched off.
znote_plugin_set_enabled($name, true);
acp_log('plugin.install', $name, ['version' => $plugin['version']]);
acp_flash_success(t('acp.plg.installed', ['plugin' => $label, 'version' => $plugin['version']]));
break;
case 'update':
$from = $plugin['installed_version'];
$error = znote_plugin_install($name);
if ($error !== '') {
acp_flash_error(t('acp.plg.update_failed', ['plugin' => $label, 'error' => $error]));
} else {
acp_log('plugin.update', $name, ['from' => $from, 'to' => $plugin['version']]);
acp_flash_success(t('acp.plg.updated', ['plugin' => $label, 'from' => $from, 'to' => $plugin['version']]));
}
break;
case 'enable':
if (!$plugin['compatible']) {
acp_flash_error(h(implode(' ', $plugin['compatibility_errors'])));
} elseif (znote_plugin_set_enabled($name, true)) {
acp_log('plugin.enable', $name);
acp_flash_success(t('acp.plg.enabled', ['plugin' => $label]));
} else {
acp_flash_error(t_default('acp.plg.enable_failed', 'Could not enable {plugin}.', ['plugin' => h($label)]));
}
break;
case 'disable':
znote_plugin_set_enabled($name, false);
acp_log('plugin.disable', $name);
acp_flash_info(t('acp.plg.disabled', ['plugin' => $label]));
break;
case 'uninstall':
// Forgets the install, keeps the data. Dropping a player's coupons
// because someone clicked a button would be the wrong default.
znote_plugin_uninstall($name);
acp_log('plugin.uninstall', $name);
acp_flash_info(t('acp.plg.uninstalled', ['plugin' => $label]));
break;
default:
acp_flash_error(t('acp.plg.unknown_action'));
}
acp_redirect('plugins');
}
$plugins = znote_plugins(true);
$active = 0;
$updatable = 0;
foreach ($plugins as $plugin) {
if ($plugin['enabled'] && $plugin['installed'] && $plugin['compatible']) {
$active++;
}
if ($plugin['update']) {
$updatable++;
}
}
?>
| = t('acp.plg.col_plugin') ?> | = t('acp.plg.col_adds') ?> | = t('acp.plg.col_version') ?> | = t('acp.plg.col_status') ?> | |
|---|---|---|---|---|
= h($plugin['name']) ?>
= h($plugin['description']) ?>
= h($name) ?>
· = h($plugin['author']) ?>
· = t('acp.plg.website') ?>
= h(implode(' ', $plugin['compatibility_errors'])) ?>
|
= $adds ? h(implode(', ', $adds)) : '' . t('acp.plg.hooks_only') . '' ?> | = $plugin['version'] !== '' ? h($plugin['version']) : '—' ?> = h(t_default('acp.plg.incompatible', 'Incompatible')) ?> = t('acp.plg.installed_label', ['version' => h($plugin['installed_version'])]) ?> | = t('acp.plg.update_available') ?> = t('acp.plg.not_installed') ?> = t('acp.plg.running_pill') ?> = t('acp.plg.disabled_pill') ?> | = t('acp.plg.view') ?> = t_default('acp.plg.settings', 'Settings') ?> |
= t('acp.plg.how_install') ?>
= t('acp.plg.how_install_text', [
'folder' => 'plugins/',
'install' => '' . t('acp.plg.install') . '',
]) ?>
= t('acp.plg.how_update') ?>
= t('acp.plg.how_update_text', [
'json' => 'plugin.json',
'update' => 'Update',
]) ?>
= t('acp.plg.how_remove') ?> = t('acp.plg.how_remove_text', [ 'disable' => '' . t('acp.plg.disable') . '', 'uninstall' => '' . t('acp.plg.uninstall') . '', ]) ?>
= t('acp.plg.how_write', [
'json' => 'plugin.json',
'readme' => 'plugins/README.md',
'example' => 'plugins/shop_coupons/',
]) ?>