use new Zip Helper (and various fix)
This commit is contained in:
parent
e9886ee444
commit
4046c9e2e7
@ -1,14 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
// Language: Français
|
/**
|
||||||
// Module: tinyPacker -
|
* @package Dotclear
|
||||||
// Date: 2023-01-30 18:50:34
|
*
|
||||||
// Author: Pierre Van Glabeke
|
* @copyright Olivier Meunier & Association Dotclear
|
||||||
// Translated with dcTranslater - 2022.12.26
|
* @copyright GPL-2.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
#
|
#
|
||||||
# DOT NOT MODIFY THIS FILE !
|
# DOT NOT MODIFY THIS FILE !
|
||||||
#
|
#
|
||||||
|
|
||||||
l10n::$locales['Destination directory is not writable.'] = 'Le répertoire de destination n\'est pas accessible en écriture.';
|
l10n::$locales['Destination directory is not writable.'] = 'Le répertoire de destination n\'est pas accessible en écriture.';
|
||||||
l10n::$locales['Quick pack theme or plugin into public dir'] = 'Empaquetage rapide de thème ou plugin dans le répertoire public';
|
l10n::$locales['Quick pack theme or plugin into public dir'] = 'Empaquetage rapide de thème ou plugin dans le répertoire public';
|
||||||
|
@ -15,13 +15,14 @@ declare(strict_types=1);
|
|||||||
namespace Dotclear\Plugin\tinyPacker;
|
namespace Dotclear\Plugin\tinyPacker;
|
||||||
|
|
||||||
/* dotclear */
|
/* dotclear */
|
||||||
|
use adminModulesList;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcNsProcess;
|
use dcNsProcess;
|
||||||
use dcPage;
|
use dcPage;
|
||||||
|
use Dotclear\Helper\File\Zip\Zip;
|
||||||
|
|
||||||
/* clearbricks */
|
/* clearbricks */
|
||||||
use files;
|
use files;
|
||||||
use fileZip;
|
|
||||||
use html;
|
use html;
|
||||||
use http;
|
use http;
|
||||||
use path;
|
use path;
|
||||||
@ -36,9 +37,27 @@ use Exception;
|
|||||||
*/
|
*/
|
||||||
class Backend extends dcNsProcess
|
class Backend extends dcNsProcess
|
||||||
{
|
{
|
||||||
|
/** @var string Public packages folder */
|
||||||
|
public const TINYPACKER_DIR = 'packages';
|
||||||
|
|
||||||
|
/** @var array Excluded files and dirs */
|
||||||
|
public const TINYPACKER_EXCLUDE = [
|
||||||
|
'\.',
|
||||||
|
'\.\.',
|
||||||
|
'__MACOSX',
|
||||||
|
'\.svn',
|
||||||
|
'\.hg.*?',
|
||||||
|
'\.git.*?',
|
||||||
|
'CVS',
|
||||||
|
'\.directory',
|
||||||
|
'\.DS_Store',
|
||||||
|
'Thumbs\.db',
|
||||||
|
'_disabled',
|
||||||
|
];
|
||||||
|
|
||||||
public static function init(): bool
|
public static function init(): bool
|
||||||
{
|
{
|
||||||
static::$init = defined('DC_CONTEXT_ADMIN') && dcCOre::app()->auth->isSuperAdmin();
|
static::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->auth->isSuperAdmin();
|
||||||
|
|
||||||
return static::$init;
|
return static::$init;
|
||||||
}
|
}
|
||||||
@ -50,7 +69,7 @@ class Backend extends dcNsProcess
|
|||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->addBehaviors([
|
dcCore::app()->addBehaviors([
|
||||||
'adminModulesListGetActions' => function ($list, $id, $_) {
|
'adminModulesListGetActions' => function (adminModulesList $list, string $id, array $_): string {
|
||||||
return in_array($list->getList(), [
|
return in_array($list->getList(), [
|
||||||
'plugin-activate',
|
'plugin-activate',
|
||||||
'theme-activate',
|
'theme-activate',
|
||||||
@ -58,25 +77,24 @@ class Backend extends dcNsProcess
|
|||||||
'<input type="submit" name="%s[%s]" value="Pack" />',
|
'<input type="submit" name="%s[%s]" value="Pack" />',
|
||||||
self::id(),
|
self::id(),
|
||||||
html::escapeHTML($id)
|
html::escapeHTML($id)
|
||||||
) : null;
|
) : '';
|
||||||
},
|
},
|
||||||
'adminModulesListDoActions' => function ($list, $modules, $type) {
|
'adminModulesListDoActions' => function (adminModulesList $list, array $modules, string $type): void {
|
||||||
# Pack action
|
# Pack action
|
||||||
if (empty($_POST[self::id()])
|
if (empty($_POST[self::id()])
|
||||||
|| !is_array($_POST[self::id()])) {
|
|| !is_array($_POST[self::id()])) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Repository directory
|
# Repository directory
|
||||||
$dir = path::real(
|
$dir = (string) path::real(
|
||||||
dcCore::app()->blog->public_path . '/packages',
|
dcCore::app()->blog->public_path . DIRECTORY_SEPARATOR . self::TINYPACKER_DIR,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
if (!empty($dir) && !is_dir($dir)) {
|
||||||
if (!is_dir($dir)) {
|
|
||||||
files::makeDir($dir, true);
|
files::makeDir($dir, true);
|
||||||
}
|
}
|
||||||
if (!is_writable($dir)) {
|
if (empty($dir) || !is_writable($dir)) {
|
||||||
throw new Exception(__('Destination directory is not writable.'));
|
throw new Exception(__('Destination directory is not writable.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,21 +107,6 @@ class Backend extends dcNsProcess
|
|||||||
}
|
}
|
||||||
$module = $list->modules->getModules($id);
|
$module = $list->modules->getModules($id);
|
||||||
|
|
||||||
# Excluded files and dirs
|
|
||||||
$exclude = [
|
|
||||||
'\.',
|
|
||||||
'\.\.',
|
|
||||||
'__MACOSX',
|
|
||||||
'\.svn',
|
|
||||||
'\.hg.*?',
|
|
||||||
'\.git.*?',
|
|
||||||
'CVS',
|
|
||||||
'\.directory',
|
|
||||||
'\.DS_Store',
|
|
||||||
'Thumbs\.db',
|
|
||||||
'_disabled',
|
|
||||||
];
|
|
||||||
|
|
||||||
# Packages names
|
# Packages names
|
||||||
$files = [
|
$files = [
|
||||||
$type . '-' . $id . '.zip',
|
$type . '-' . $id . '.zip',
|
||||||
@ -111,21 +114,19 @@ class Backend extends dcNsProcess
|
|||||||
];
|
];
|
||||||
|
|
||||||
# Create zip
|
# Create zip
|
||||||
foreach ($files as $f) {
|
foreach ($files as $file) {
|
||||||
@set_time_limit(300);
|
@set_time_limit(300);
|
||||||
$fp = fopen($dir . '/' . $f, 'wb');
|
|
||||||
|
|
||||||
$zip = new fileZip($fp);
|
$zip = new Zip($dir . '/' . $file);
|
||||||
|
|
||||||
foreach ($exclude as $e) {
|
foreach (self::TINYPACKER_EXCLUDE as $e) {
|
||||||
$zip->addExclusion(sprintf(
|
$zip->addExclusion(sprintf(
|
||||||
'#(^|/)(%s)(/|$)#',
|
'#(^|/)(%s)(/|$)#',
|
||||||
$e
|
$e
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip->addDirectory($module['root'], $id, true);
|
$zip->addDirectory((string) path::real($module['root']), $id, true);
|
||||||
$zip->write();
|
|
||||||
$zip->close();
|
$zip->close();
|
||||||
unset($zip);
|
unset($zip);
|
||||||
}
|
}
|
||||||
@ -140,7 +141,7 @@ class Backend extends dcNsProcess
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function id()
|
private static function id(): string
|
||||||
{
|
{
|
||||||
return basename(dirname(__DIR__));
|
return basename(dirname(__DIR__));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user