mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 09:49:22 +02:00
* automatically detect json file in .zip instead of basing on filename
This commit is contained in:
parent
c504588993
commit
73eca63c4f
@ -62,37 +62,51 @@ 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);
|
||||||
$plugin = json_decode($string, true);
|
if(pathinfo($tmp, PATHINFO_DIRNAME) == 'plugins' && pathinfo($tmp, PATHINFO_EXTENSION) == 'json')
|
||||||
if($plugin == NULL) {
|
$json_file = $tmp;
|
||||||
warning('Cannot load ' . BASE . 'plugins/' . $name[0] . '.json. File might be not valid json code.');
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($plugin['install'])) {
|
if(!isset($json_file)) {
|
||||||
if(file_exists(BASE . $plugin['install']))
|
error('Cannot find plugin info .json file. Installation is discontinued.');
|
||||||
require(BASE . $plugin['install']);
|
}
|
||||||
else
|
else if($zip->extractTo($targetdir)) { // place in the directory with same name
|
||||||
warning('Cannot load install script. Your plugin might be not working correctly.');
|
$file_name = BASE . $json_file;
|
||||||
}
|
if(!file_exists($file_name))
|
||||||
|
warning("Cannot load " . $file_name . ". File doesn't exist.");
|
||||||
if(isset($plugin['hooks'])) {
|
else {
|
||||||
foreach($plugin['hooks'] as $_name => $info) {
|
$string = file_get_contents($file_name);
|
||||||
if(isset($hook_types[$info['type']])) {
|
$plugin = json_decode($string, true);
|
||||||
$query = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'hooks` WHERE `name` = ' . $db->quote($_name) . ';');
|
if ($plugin == null) {
|
||||||
if($query->rowCount() == 1) { // found something
|
warning('Cannot load ' . $file_name . '. File might be not valid json code.');
|
||||||
$query = $query->fetch();
|
|
||||||
$db->query('UPDATE `' . TABLE_PREFIX . 'hooks` SET `type` = ' . $hook_types[$info['type']] . ', `file` = ' . $db->quote($info['file']) . ' WHERE `id` = ' . (int)$query['id'] . ';');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$db->query('INSERT INTO `' . TABLE_PREFIX . 'hooks` (`id`, `name`, `type`, `file`) VALUES (NULL, ' . $db->quote($_name) . ', ' . $hook_types[$info['type']] . ', ' . $db->quote($info['file']) . ');');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
warning('Unknown event type: ' . $info['type']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset($plugin['install'])) {
|
||||||
|
if(file_exists(BASE . $plugin['install']))
|
||||||
|
require(BASE . $plugin['install']);
|
||||||
|
else
|
||||||
|
warning('Cannot load install script. Your plugin might be not working correctly.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($plugin['hooks'])) {
|
||||||
|
foreach($plugin['hooks'] as $_name => $info) {
|
||||||
|
if(isset($hook_types[$info['type']])) {
|
||||||
|
$query = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'hooks` WHERE `name` = ' . $db->quote($_name) . ';');
|
||||||
|
if($query->rowCount() == 1) { // found something
|
||||||
|
$query = $query->fetch();
|
||||||
|
$db->query('UPDATE `' . TABLE_PREFIX . 'hooks` SET `type` = ' . $hook_types[$info['type']] . ', `file` = ' . $db->quote($info['file']) . ' WHERE `id` = ' . (int)$query['id'] . ';');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$db->query('INSERT INTO `' . TABLE_PREFIX . 'hooks` (`id`, `name`, `type`, `file`) VALUES (NULL, ' . $db->quote($_name) . ', ' . $hook_types[$info['type']] . ', ' . $db->quote($info['file']) . ');');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
warning('Unknown event type: ' . $info['type']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user