* automatically detect json file in .zip instead of basing on filename

This commit is contained in:
slawkens 2017-09-13 09:03:48 +02:00
parent c504588993
commit 73eca63c4f

View File

@ -62,11 +62,24 @@ if(isset($_FILES["plugin"]["name"]))
$zip = new ZipArchive(); $zip = new ZipArchive();
$x = $zip->open($targetzip); // open the zip file to extract $x = $zip->open($targetzip); // open the zip file to extract
if ($x === true) { if ($x === true) {
if($zip->extractTo($targetdir)) { // place in the directory with same name for ($i = 0; $i < $zip->numFiles; $i++) {
$string = file_get_contents(BASE . 'plugins/' . $name[0] . '.json'); $tmp = $zip->getNameIndex($i);
if(pathinfo($tmp, PATHINFO_DIRNAME) == 'plugins' && pathinfo($tmp, PATHINFO_EXTENSION) == 'json')
$json_file = $tmp;
}
if(!isset($json_file)) {
error('Cannot find plugin info .json file. Installation is discontinued.');
}
else if($zip->extractTo($targetdir)) { // place in the directory with same name
$file_name = BASE . $json_file;
if(!file_exists($file_name))
warning("Cannot load " . $file_name . ". File doesn't exist.");
else {
$string = file_get_contents($file_name);
$plugin = json_decode($string, true); $plugin = json_decode($string, true);
if($plugin == NULL) { if ($plugin == null) {
warning('Cannot load ' . BASE . 'plugins/' . $name[0] . '.json. File might be not valid json code.'); warning('Cannot load ' . $file_name . '. File might be not valid json code.');
} }
if(isset($plugin['install'])) { if(isset($plugin['install'])) {
@ -94,6 +107,7 @@ if(isset($_FILES["plugin"]["name"]))
} }
success('<strong>' . $plugin['name'] . '</strong> plugin has been successfully installed.'); success('<strong>' . $plugin['name'] . '</strong> plugin has been successfully installed.');
} }
}
else { else {
error('There was a problem with extracting zip archive.'); error('There was a problem with extracting zip archive.');
} }