open($zipFile); // Create all files & dirs, in 1kb chunks for ($i = 0; $i < $zip->numFiles; $i++) { $name = $zip->getNameIndex($i); // Determine output filename $file = $target . $name; // 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 (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); // Start creating a new chunk for the plugins settings $settingsNew = '"plugins" => array('; // Set all the old plugins for ($i = 0; $i < count($oldPlugins); $i++) { $settingsNew .= ' array("' . $oldPlugins[$i][0] . '","' . $oldPlugins[$i][1] . '","' . $oldPlugins[$i][2] . '","' . $oldPlugins[$i][3] . '","' . $oldPlugins[$i][4] . '","' . $oldPlugins[$i][5] . '"),'; } // Then add the new one $settingsNew .= ' array("' . $pluginsData[$_GET['plugin']]['name'] . '","' . $pluginsData[$_GET['plugin']]['icon'] . '","' . $pluginsData[$_GET['plugin']]['style'] . '","' . $pluginsData[$_GET['plugin']]['URL'] . '","' . $pluginsData[$_GET['plugin']]['target'] . '","' . $pluginsData[$_GET['plugin']]['timer'] . '")'; $settingsNew .= ' ),' . PHP_EOL; } // ============ // UNINSTALLING // ============ if ("uninstall" === $_GET['action']) { // Start creating a new chunk for the plugins settings $settingsNew = '"plugins" => array('; // Set all the old plugins for ($i = 0; $i < count($oldPlugins); $i++) { // As long as it's not the one we want to remove if ($oldPlugins[$i][0] !== $pluginsData[$_GET['plugin']]['name']) { $settingsNew .= ' array("' . $oldPlugins[$i][0] . '","' . $oldPlugins[$i][1] . '","' . $oldPlugins[$i][2] . '","' . $oldPlugins[$i][3] . '","' . $oldPlugins[$i][4] . '","' . $oldPlugins[$i][5] . '"),'; } } // Rtrim off the last comma $settingsNew = rtrim($settingsNew, ','); $settingsNew .= ' ),' . PHP_EOL; // Finally, delete the plugin itself $target = '../plugins/'; $dirName = basename($pluginsData[$_GET['plugin']]['zipURL'], ".zip"); deletePlugin($target . $dirName . "/"); } // ======== // UPDATING // ======== if ("update" === $_GET['action']) { // Start creating a new chunk for the plugins settings $settingsNew = '"plugins" => array('; // Redo the arrays using the form data for ($i = 0; $i < count($oldPlugins); $i++) { $timer = intval($_POST['timer' . $i]); if ($timer == 0) { $timer = ""; } $settingsNew .= ' array("' . $_POST['name' . $i] . '","' . $_POST['icon' . $i] . '","' . $_POST['style' . $i] . '","' . $_POST['URL' . $i] . '","' . $_POST['target' . $i] . '","' . $timer . '"),'; } // Rtrim off the last comma $settingsNew = rtrim($settingsNew, ','); $settingsNew .= ' ),' . PHP_EOL; } // Now we have a new settingsNew string to use and files installed/uninstalled // we can update the plugin arrays in the settings file // Identify the bit to replace $repPosStart = strpos($settingsContents, '"plugins"'); $repPosEnd = strpos($settingsContents, '"ftpSites"'); // Compile our new settings $settingsContents = substr($settingsContents, 0, $repPosStart) . $settingsNew . substr($settingsContents, $repPosEnd, strlen($settingsContents)); // 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) { 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
"); } } else { unlink($dir . $file) or die("" . $t['couldnt delete file'] . ": $dir$file
"); } } } closedir($theDir); rmdir($dir); } ?> ICEcoder <?php echo $ICEcoder["versionNo"];?> plugins manager

','plugins')" style="position: absolute; top: 26px; right: 20px">


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


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