diff --git a/CHANGELOG.md b/CHANGELOG.md index 04c12f5..5bbf189 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +pacKman 2023.10.09 +=========================================================== +* Require Dotclear 2.28 +* Require PHP 8.1+ +* Code review + pacKman 2023.10.07 =========================================================== * Require Dotclear 2.28 diff --git a/README.md b/README.md index ee84688..e53b5f6 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,22 @@ # README [![Release](https://img.shields.io/badge/release-2023.10.07-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/pacKman/releases) -[![Date](https://img.shields.io/badge/date-2023.10.07-c44d58.svg)](https://git.dotclear.watch/JcDenis/pacKman/releases) +![Date](https://img.shields.io/badge/date-2023.10.07-c44d58.svg) [![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/pacKman) -[![License](https://img.shields.io/github/license/JcDenis/pacKman)](https://git.dotclear.watch/JcDenis/pacKman/blob/master/LICENSE) +[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/pacKman/src/branch/master/LICENSE) -## WHAT IS PACKMAN ? +## ABOUT -_pacKman_ is a plugin for the open-source -web publishing software called Dotclear. +_pacKman_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). -It help super admin to create and manage packages of -themes and plugins from Dotclear administration pages. +> Create and manage packages of themes and plugins from Dotclear administration pages. ## REQUIREMENTS -_pacKman_ requires: - -* Super administrator permissions * Dotclear 2.28 * PHP 8.1+ +* Super administrator permissions * A writable cache directory * A writable directory to put packages. (can be VAR dir) @@ -37,10 +33,11 @@ Once it's done you can manage your packages from menu ## LINKS -* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) -* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/pacKman) or [GitHub Page](https://github.com/JcDenis/pacKman) -* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/pacKman/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/pacKman) -* Discuss and help : [Dotclear Forum](https://forum.dotclear.org/viewtopic.php?id=40066) +* [License](https://git.dotclear.watch/JcDenis/pacKman/src/branch/master/LICENSE) +* [Packages & details](https://git.dotclear.watch/JcDenis/pacKman/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/pacKman)) +* [Sources & contributions](https://git.dotclear.watch/JcDenis/pacKman) (or on [GitHub](https://github.com/JcDenis/pacKman)) +* [Issues & security](https://git.dotclear.watch/JcDenis/pacKman/issues) (or on [GitHub](https://github.com/JcDenis/pacKman/issues)) +* [Discuss and help](https://forum.dotclear.org/viewtopic.php?id=40066) ## CONTRIBUTORS diff --git a/_define.php b/_define.php index 598caaa..d4963a9 100644 --- a/_define.php +++ b/_define.php @@ -1,35 +1,29 @@ registerModule( 'Packages repository', 'Manage your Dotclear packages', 'Jean-Christian Denis', - '2023.10.07', + '2023.10.09', [ - 'requires' => [ - ['php', '8.1'], - ['core', '2.28'], - ], - 'permissions' => null, - 'type' => 'plugin', - 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', - 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', - 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', + 'requires' => [['core', '2.28']], + 'type' => 'plugin', + 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', + 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', + 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', ] ); diff --git a/dcstore.xml b/dcstore.xml index c312fdd..624f031 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,10 +2,10 @@ Packages repository - 2023.10.07 + 2023.10.09 Jean-Christian Denis Manage your Dotclear packages - https://git.dotclear.watch/JcDenis/pacKman/releases/download/v2023.10.07/plugin-pacKman.zip + https://git.dotclear.watch/JcDenis/pacKman/releases/download/v2023.10.09/plugin-pacKman.zip 2.28 https://git.dotclear.watch/JcDenis/pacKman/src/branch/master/README.md https://git.dotclear.watch/JcDenis/pacKman/issues diff --git a/src/Backend.php b/src/Backend.php index c1a8405..3bebdba 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -1,15 +1,5 @@ $exclude The list + * + * @return array $exclude The list + */ public static function quote_exclude(array $exclude): array { foreach ($exclude as $k => $v) { @@ -36,6 +41,13 @@ class Core return $exclude; } + /** + * Get packages list. + * + * @param string $root The path to scan + * + * @return array The list + */ public static function getPackages(string $root): array { $res = []; @@ -134,6 +146,19 @@ class Core return $res; } + /** + * Pack a module. + * + * @param ModuleDefine $define The module + * @param string $root The package path + * @param array $files The files to pack + * @param bool $overwrite Overwrite package + * @param array $exclude The files to exclude (regexp) + * @param bool $nocomment Remove comment from files + * @param bool $fixnewline Fix new lines in files + * + * @return bool True on success + */ public static function pack(ModuleDefine $define, string $root, array $files, bool $overwrite = false, array $exclude = [], bool $nocomment = false, bool $fixnewline = false): bool { // check define diff --git a/src/Install.php b/src/Install.php index 084a91b..8109f04 100644 --- a/src/Install.php +++ b/src/Install.php @@ -1,15 +1,5 @@ callBehavior('packmanBeforeInstallPackage', $type, $id, $root); - if ($type == 'themes') { - App::themes()->installPackage($root, App::themes()); - } else { - App::plugins()->installPackage($root, App::plugins()); - } + $mods = $type == 'themes' ? App::themes() : App::plugins(); + $mods->installPackage($root, $mods); # --BEHAVIOR-- packmanAfterInstallPackage App::behavior()->callBehavior('packmanAfterInstallPackage', $type, $id, $root); diff --git a/src/My.php b/src/My.php index 0c4777d..8d918db 100644 --- a/src/My.php +++ b/src/My.php @@ -1,15 +1,5 @@ EXCLUDED_FILES + */ public const EXCLUDED_FILES = [ '.', '..', @@ -38,6 +37,7 @@ class My extends MyPlugin public static function checkCustomContext(int $context): ?bool { - return in_array($context, [My::BACKEND, My::MANAGE, My::MENU]) ? App::auth()->isSuperAdmin() : null; + // Only backend and super admin + return $context === self::INSTALL ? null : App::task()->checkContext('BACKEND') && App::auth()->isSuperAdmin(); } } diff --git a/src/Settings.php b/src/Settings.php index f90b61a..6facf67 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -1,19 +1,17 @@ pack_nocomment = (bool) ($s?->get('pack_nocomment') ?? false); - $this->pack_fixnewline = (bool) ($s?->get('pack_fixnewline') ?? false); - $this->pack_overwrite = (bool) ($s?->get('pack_overwrite') ?? false); - $this->pack_filename = (string) ($s?->get('pack_filename') ?? '%type%-%id%'); - $this->secondpack_filename = (string) ($s?->get('secondpack_filename') ?? '%type%-%id%-%version%'); - $this->pack_repository = (string) ($s?->get('pack_repository') ?? ''); - $this->pack_typedrepo = (bool) ($s?->get('pack_typedrepo') ?? false); - $this->pack_excludefiles = (string) ($s?->get('pack_excludefiles') ?? '*.zip,*.tar,*.tar.gz,.directory,.hg'); - $this->hide_distrib = (bool) ($s?->get('hide_distrib') ?? false); + $this->pack_nocomment = (bool) ($s->get('pack_nocomment') ?? false); + $this->pack_fixnewline = (bool) ($s->get('pack_fixnewline') ?? false); + $this->pack_overwrite = (bool) ($s->get('pack_overwrite') ?? false); + $this->pack_filename = (string) ($s->get('pack_filename') ?? '%type%-%id%'); + $this->secondpack_filename = (string) ($s->get('secondpack_filename') ?? '%type%-%id%-%version%'); + $this->pack_repository = (string) ($s->get('pack_repository') ?? ''); + $this->pack_typedrepo = (bool) ($s->get('pack_typedrepo') ?? false); + $this->pack_excludefiles = (string) ($s->get('pack_excludefiles') ?? '*.zip,*.tar,*.tar.gz,.directory,.hg'); + $this->hide_distrib = (bool) ($s->get('hide_distrib') ?? false); } - public function getSetting(string $key): mixed + /** + * Get a setting. + * + * @param string $key The key + * + * @return null|bool|string The value + */ + public function getSetting(string $key): null|bool|string { return $this->{$key} ?? null; } /** - * Overwrite a plugin settings (in db) + * Overwrite a plugin settings (in db). * * @param string $key The setting ID * @param mixed $value The setting value @@ -87,9 +92,9 @@ class Settings } /** - * List defined settings keys + * List defined settings keys. * - * @return array The settings keys + * @return array The settings keys */ public function listSettings(): array { diff --git a/src/Uninstall.php b/src/Uninstall.php index e4caa89..2112a91 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -1,23 +1,20 @@ moduleExists('Uninstaller')) { + if (!self::status()) { return false; } diff --git a/src/Utils.php b/src/Utils.php index 2f2420d..eaefaf2 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -1,15 +1,5 @@ pluginsRoot()); $p = array_pop($e); return (string) Path::real($p); @@ -86,7 +85,7 @@ class Utils public static function getRepositoryDir(?string $dir, ?string $typed = null): string { $typed = empty($typed) ? '' : DIRECTORY_SEPARATOR . ($typed == 'themes' ? 'themes' : 'plugins'); - $dir = empty($dir) ? DC_VAR . DIRECTORY_SEPARATOR . 'packman' . $typed : $dir . $typed; + $dir = empty($dir) ? App::config()->varRoot() . DIRECTORY_SEPARATOR . 'packman' . $typed : $dir . $typed; try { @Files::makeDir($dir, true); @@ -97,6 +96,15 @@ class Utils return $dir; } + /** + * Get modules list form. + * + * @param array $modules The modules + * @param string $type The modules type + * @param string $title The list title + * + * @return null|bool True on render + */ public static function modules(array $modules, string $type, string $title): ?bool { if (empty($modules)) { @@ -178,6 +186,15 @@ class Utils return true; } + /** + * Get modules repository list form. + * + * @param array $modules The modules + * @param string $type The modules type + * @param string $title The list title + * + * @return null|bool True on render + */ public static function repository(array $modules, string $type, string $title): ?bool { if (empty($modules)) { @@ -323,6 +340,11 @@ class Utils return true; } + /** + * Sort modules by id. + * + * @param array $modules The modules + */ protected static function sort(array &$modules): void { uasort($modules, fn ($a, $b) => $a->get('version') <=> $b->get('version')); diff --git a/src/Zip.php b/src/Zip.php index 1c14aa5..c983e7d 100644 --- a/src/Zip.php +++ b/src/Zip.php @@ -1,25 +1,34 @@ makeDate($mtime); - $mtime = $this->makeTime($mtime); + $mdate = $this->makeDate((int) $mtime); + $mtime = $this->makeTime((int) $mtime); # Data descriptor $data_desc = "\x50\x4b\x03\x04" .