try to be compliant with Dotclear 2.24+ modules structure

2.28
Jean-Christian Paul Denis 2023-03-06 01:17:30 +01:00
parent b8af237c5d
commit 940173b98b
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
1 changed files with 88 additions and 23 deletions

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\pacKman; namespace Dotclear\Plugin\pacKman;
/* dotclear ns */ /* dotclear ns */
use dcCore;
use dcModules; use dcModules;
use dcThemes; use dcThemes;
@ -44,6 +45,16 @@ class Core
'_disabled', '_disabled',
]; ];
public static function id()
{
return basename(dirname(__DIR__));
}
public static function name()
{
return __('pacKman');
}
public static function quote_exclude(array $exclude): array public static function quote_exclude(array $exclude): array
{ {
foreach ($exclude as $k => $v) { foreach ($exclude as $k => $v) {
@ -79,43 +90,97 @@ class Core
return $res; return $res;
} }
$sandboxes = [
'theme' => clone dcCore::app()->themes,
'plugin' => clone dcCore::app()->plugins,
];
$i = 0; $i = 0;
foreach ($zip_files as $zip_file) { foreach ($zip_files as $zip_file) {
$zip = new fileUnzip($root . '/' . $zip_file); $zip_file = $root . DIRECTORY_SEPARATOR . $zip_file;
$zip = new fileUnzip($zip_file);
$zip->getList(false, '#(^|/)(__MACOSX|\.svn|\.hg.*|\.git.*|\.DS_Store|\.directory|Thumbs\.db)(/|$)#');
$zip_root_dir = $zip->getRootDir(); $zip_root_dir = $zip->getRootDir();
$define = '';
if ($zip_root_dir != false) { if ($zip_root_dir != false) {
$define = $zip_root_dir . '/_define.php'; $target = dirname($zip_file);
$destination = $target . DIRECTORY_SEPARATOR . $zip_root_dir;
$define = $zip_root_dir . '/' . dcModules::MODULE_FILE_DEFINE;
$init = $zip_root_dir . '/' . dcModules::MODULE_FILE_INIT;
$has_define = $zip->hasFile($define); $has_define = $zip->hasFile($define);
} else { } else {
$define = '_define.php'; $target = dirname($zip_file) . DIRECTORY_SEPARATOR . preg_replace('/\.([^.]+)$/', '', basename($zip_file));
$destination = $target;
$define = dcModules::MODULE_FILE_DEFINE;
$init = dcModules::MODULE_FILE_INIT;
$has_define = $zip->hasFile($define); $has_define = $zip->hasFile($define);
} }
if (!$has_define) { if ($zip->isEmpty()) {
$zip->close();
continue; continue;
} }
$zip->unzip($define, $cache . '/_define.php'); if (!$has_define) {
$zip->close();
$modules = new dcModules(); continue;
$modules->requireDefine($cache, $zip_root_dir);
if ($modules->moduleExists($zip_root_dir)) {
$res[$i] = $modules->getModules($zip_root_dir);
} else {
$themes = new dcThemes();
$themes->requireDefine($cache, $zip_root_dir);
$res[$i] = $themes->getModules($zip_root_dir);
} }
if (is_array($res[$i])) {
$res[$i] = array_merge($res[$i], [
'id' => $zip_root_dir,
'root' => $root . '/' . $zip_file,
]);
unlink($cache . '_define.php'); foreach ($sandboxes as $type => $sandbox) {
try {
files::makeDir($destination, true);
// can't load twice _init.php file !
$unlink = false;
if ($zip->hasFile($init)
&& !dcCore::app()->plugins->getDefine(basename($destination))->isDefined()
&& !dcCore::app()->themes->getDefine(basename($destination))->isDefined()
) {
$unlink = true;
$zip->unzip($init, $destination . DIRECTORY_SEPARATOR . dcModules::MODULE_FILE_INIT);
}
$zip->unzip($define, $destination . DIRECTORY_SEPARATOR . dcModules::MODULE_FILE_DEFINE);
$sandbox->resetModulesList();
$sandbox->requireDefine($destination, basename($destination));
if ($unlink) {
unlink($destination . DIRECTORY_SEPARATOR . dcModules::MODULE_FILE_INIT);
}
unlink($destination . DIRECTORY_SEPARATOR . dcModules::MODULE_FILE_DEFINE);
$new_errors = $sandbox->getErrors();
if (!empty($new_errors)) {
$new_errors = implode(" \n", $new_errors);
throw new Exception($new_errors);
}
$module = $sandbox->getDefine(basename($destination));
if (!$module->isDefined() || $module->get('type') != $type) {
throw new Exception('bad module type');
}
$res[$i] = $module->dump();
$res[$i]['root'] = $zip_file;
$i++; $i++;
$zip->close();
files::deltree($destination);
} catch (Exception $e) {
$zip->close();
files::deltree($destination);
continue;
}
} }
} }