From a4e5944412a3236e44b50bc6ac069fe13162cac3 Mon Sep 17 00:00:00 2001 From: mattpass Date: Wed, 27 May 2020 08:09:57 +0100 Subject: [PATCH] Improve plugins-manager.php --- lib/plugins-manager.php | 452 ++++++++++++++++++++++------------------ 1 file changed, 249 insertions(+), 203 deletions(-) diff --git a/lib/plugins-manager.php b/lib/plugins-manager.php index 0be07b4..42b46ae 100644 --- a/lib/plugins-manager.php +++ b/lib/plugins-manager.php @@ -1,172 +1,208 @@ open($zipFile); + // Now unpack the zip + $zip = new ZipArchive; + $zip->open($zipFile); - // Create all files & dirs, in 1kb chunks - for($i=0; $i<$zip->numFiles; $i++) { - $name = $zip->getNameIndex($i); + // Create all files & dirs, in 1kb chunks + for ($i = 0; $i < $zip->numFiles; $i++) { + $name = $zip->getNameIndex($i); - // Determine output filename - $file = $target.$name; + // Determine output filename + $file = $target . $name; - // Create the directories if necessary - $dir = dirname($file); - if (!is_dir($dir)) mkdir($dir, 0777, true); + // Create the directories if necessary + $dir = dirname($file); + if (false === is_dir($dir)) mkdir($dir, 0777, true); - // Read from zip and write to disk - $fpr = $zip->getStream($name); - if (!is_dir($file)) { - $fpw = fopen($file, 'w'); - while ($data = fread($fpr, 1024)) { - fwrite($fpw, $data); - } - fclose($fpw); - } - fclose($fpr); - } - $zip->close(); + // Read from zip and write to disk + $fpr = $zip->getStream($name); + if (false === is_dir($file)) { + $fpw = fopen($file, 'w'); + while ($data = fread($fpr, 1024)) { + fwrite($fpw, $data); + } + fclose($fpw); + } + fclose($fpr); + } + $zip->close(); - // Remove the tmp zip file - unlink($zipFile); + // Remove the tmp zip file + unlink($zipFile); - // Start creating a new chunk for the plugins settings - $settingsNew = '"plugins" => array('; + // Start creating a new chunk for the plugins settings + $settingsNew = '"plugins" => array('; - // Set all the old plugins - for ($i=0; $iif (confirm('".$t['ICEcoder needs to...']."')) {window.location.reload(true);} else {window.location='plugins-manager.php?updatedPlugins&csrf='+parent.parent.ICEcoder.csrf;}"; - } else { - header("Location: plugins-manager.php?updatedPlugins&csrf=".$_SESSION["csrf"]); - echo ""; - } - die("".$t['saving plugins'].""); - } else { - echo ""; - } + // Now update the config file + if (is_writeable("../data/".$settingsFile)) { + $fh = fopen("../data/".$settingsFile, 'w'); + fwrite($fh, $settingsContents); + fclose($fh); + // Finally, reload ICEcoder itself if plugin requires it or just the iFrame screen for the user if it doesn't + if ("install" === $_GET['action'] && "true" === $pluginsData[$_GET['plugin']]['reload']) { + echo ""; + } else { + header("Location: plugins-manager.php?updatedPlugins&csrf=" . $_SESSION["csrf"]); + echo ""; + } + die("" . $t['saving plugins'] . ""); + } else { + echo ""; + } } // Function to delete the plugin dir & files/dirs inside function deletePlugin($dir) { - $mydir = opendir($dir); - while(false !== ($file = readdir($mydir))) { - if($file != "." && $file != "..") { - chmod($dir.$file, 0777); - if(is_dir($dir.$file)) { + global $t; + $theDir = opendir($dir); + while(false !== ($file = readdir($theDir))) { + if($file !== "." && $file !== "..") { + chmod($dir . $file, 0777); + if(is_dir($dir . $file)) { chdir('.'); - deletePlugin($dir.$file.'/'); - if(is_dir($dir.$file)) { - rmdir($dir.$file) or DIE("".$t['couldnt delete dir'].": $dir$file
"); - } + deletePlugin($dir . $file . '/'); + if(is_dir($dir . $file)) { + rmdir($dir . $file) or die("" . $t['couldnt delete dir'] . ": $dir$file
"); + } + } + else { + unlink($dir . $file) or die("" . $t['couldnt delete file'] . ": $dir$file
"); } - else - unlink($dir.$file) or DIE("".$t['couldnt delete file'].": $dir$file
"); } } - closedir($mydir); + closedir($theDir); rmdir($dir); } ?> @@ -174,97 +210,107 @@ function deletePlugin($dir) { -ICEcoder <?php echo $ICEcoder["versionNo"];?> plugins manager - - - + ICEcoder <?php echo $ICEcoder["versionNo"];?> plugins manager + + + +

-','writingPlugins')" style="position: absolute; top: 26px; right: 20px">
+','plugins')" style="position: absolute; top: 26px; right: 20px">
- 0) { - ?> -
-


+ +
+


-
- - - - - - - - '; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo ''; - echo ''; - echo ''; - echo ''; - ?> -
'.$plugins[$i][0].''.$plugins[$i][0].'
'.$t['Update'].'
- "> -
-
- +
+ + + + + + + + '; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo ''; + echo ''; + echo ''; + echo ''; + ?> +
' . $plugins[$i][0] .
+                            '' . $plugins[$i][0] . '
' . $t['Update'] . '
+ "> +
+
+ -
-


+
+


- 0) { - ?> - - '.PHP_EOL; - } + +
+ ' . PHP_EOL; + } - $installUninstallButton = '
'.$t['Install'].'
'; - for ($j=0; $j'.$t['Uninstall'].''; - } - } + $installUninstallButton = '
' . $t['Install'] . '
'; + for ($j = 0; $j < count($plugins); $j++) { + if ($pluginsData[$i]['name'] == $plugins[$j][0]) { + $installUninstallButton = '
' . $t['Uninstall'] . '
'; + } + } - $reloadExtra = $pluginsData[$i]['reload'] == 'true' ? '
'.$t['Reload after install...'].'' : ''; - echo '
'; - echo ''; - $styleExtra = ($i % 2 == 1 || $i == count($pluginsData)-1) ? "0" : "30px"; - echo ''; + $reloadExtra = "true" === $pluginsData[$i]['reload'] ? '
' . $t['Reload after install...'] . '' : ''; + echo ''; + echo ''; + $styleExtra = (1 === $i % 2 || $i === count($pluginsData) - 1) ? "0" : "30px"; + echo ''; - if ($i % 2 == 1 || $i == count($pluginsData)-1) { - echo PHP_EOL.''.PHP_EOL; - } - } - ?> -
'.$pluginsData[$i]['name'].''.$pluginsData[$i]['name'].$reloadExtra.''.$installUninstallButton.''.$pluginsData[$i]['name'] . '' . $pluginsData[$i]['name'] . $reloadExtra . '' . $installUninstallButton . '
+ if (1 === $i % 2 || $i == count($pluginsData) - 1) { + echo PHP_EOL . '' . PHP_EOL; + } + } + ?> + - -
+ +