refactor: improve code readability by formatting conditional statements and adding demo mode checks

This commit is contained in:
Focuslinkstech 2025-03-05 13:59:43 +01:00
parent 8429ed763e
commit da14a7bfef

View File

@ -34,7 +34,8 @@ if (file_exists($cache) && time() - filemtime($cache) < (24 * 60 * 60)) {
} }
switch ($action) { switch ($action) {
case 'refresh': case 'refresh':
if (file_exists($cache)) unlink($cache); if (file_exists($cache))
unlink($cache);
r2(getUrl('pluginmanager'), 's', 'Refresh success'); r2(getUrl('pluginmanager'), 's', 'Refresh success');
break; break;
case 'dlinstall': case 'dlinstall':
@ -121,7 +122,7 @@ switch ($action) {
$zip->extractTo($cache); $zip->extractTo($cache);
$zip->close(); $zip->close();
$folder = $cache . DIRECTORY_SEPARATOR . $plugin . '-main' . DIRECTORY_SEPARATOR; $folder = $cache . DIRECTORY_SEPARATOR . $plugin . '-main' . DIRECTORY_SEPARATOR;
if(!file_exists($folder)) { if (!file_exists($folder)) {
$folder = $cache . DIRECTORY_SEPARATOR . $plugin . '-master' . DIRECTORY_SEPARATOR; $folder = $cache . DIRECTORY_SEPARATOR . $plugin . '-master' . DIRECTORY_SEPARATOR;
} }
$success = 0; $success = 0;
@ -161,6 +162,9 @@ switch ($action) {
} }
break; break;
case 'delete': case 'delete':
if ($_app_stage == 'Demo') {
r2(getUrl('pluginmanager'), 'e', 'You cannot perform this action in Demo mode');
}
if (!is_writeable($CACHE_PATH)) { if (!is_writeable($CACHE_PATH)) {
r2(getUrl('pluginmanager'), 'e', 'Folder cache/ is not writable'); r2(getUrl('pluginmanager'), 'e', 'Folder cache/ is not writable');
} }
@ -171,7 +175,8 @@ switch ($action) {
$tipe = $routes['2']; $tipe = $routes['2'];
$plugin = $routes['3']; $plugin = $routes['3'];
$file = $CACHE_PATH . DIRECTORY_SEPARATOR . $plugin . '.zip'; $file = $CACHE_PATH . DIRECTORY_SEPARATOR . $plugin . '.zip';
if (file_exists($file)) unlink($file); if (file_exists($file))
unlink($file);
if ($tipe == 'plugin') { if ($tipe == 'plugin') {
foreach ($json['plugins'] as $plg) { foreach ($json['plugins'] as $plg) {
if ($plg['id'] == $plugin) { if ($plg['id'] == $plugin) {
@ -212,6 +217,9 @@ switch ($action) {
} }
break; break;
case 'install': case 'install':
if ($_app_stage == 'Demo') {
r2(getUrl('pluginmanager'), 'e', 'You cannot perform this action in Demo mode');
}
if (!is_writeable($CACHE_PATH)) { if (!is_writeable($CACHE_PATH)) {
r2(getUrl('pluginmanager'), 'e', 'Folder cache/ is not writable'); r2(getUrl('pluginmanager'), 'e', 'Folder cache/ is not writable');
} }
@ -222,7 +230,8 @@ switch ($action) {
$tipe = $routes['2']; $tipe = $routes['2'];
$plugin = $routes['3']; $plugin = $routes['3'];
$file = $CACHE_PATH . DIRECTORY_SEPARATOR . $plugin . '.zip'; $file = $CACHE_PATH . DIRECTORY_SEPARATOR . $plugin . '.zip';
if (file_exists($file)) unlink($file); if (file_exists($file))
unlink($file);
if ($tipe == 'plugin') { if ($tipe == 'plugin') {
foreach ($json['plugins'] as $plg) { foreach ($json['plugins'] as $plg) {
if ($plg['id'] == $plugin) { if ($plg['id'] == $plugin) {