cosmetics

This commit is contained in:
Jean-Christian Denis 2021-10-23 16:46:03 +02:00
parent d55df97608
commit 05b2b597d3
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
4 changed files with 50 additions and 44 deletions

View file

@ -1,6 +1,8 @@
2021.08.22.1 - dev
- add option to convert newline from files content on the fly
- clean up again...
- fix wrong version on repository
- fix modules sort
2021.08.22
- fix PSR2 coding style

View file

@ -44,7 +44,7 @@ class dcPackman
public static function getPackages($core, $root)
{
$res = array();
$res = [];
$cache = self::getCache() . '/';
if (!is_dir($root) || !is_readable($root)) {
@ -52,8 +52,8 @@ class dcPackman
}
$files = files::scanDir($root);
$zip_files = array();
foreach($files AS $file) {
$zip_files = [];
foreach($files as $file) {
if (!preg_match('#(^|/)(.*?)\.zip(/|$)#', $file)) {
continue;
}
@ -65,7 +65,7 @@ class dcPackman
}
$i = 0;
foreach($zip_files AS $zip_file) {
foreach($zip_files as $zip_file) {
$zip = new fileUnzip($root . '/' . $zip_file);
$zip_root_dir = $zip->getRootDir();
@ -106,7 +106,8 @@ class dcPackman
public static function pack($info, $root, $files, $overwrite = false, $exclude = [], $nocomment = false, $fixnewline = false)
{
if (!($info = self::getInfo($info))
|| !($root = self::getRoot($root))) {
|| !($root = self::getRoot($root))
) {
return false;
}
@ -114,7 +115,8 @@ class dcPackman
foreach($files as $file) {
if (!($file = self::getFile($file, $info))
|| !($dest = self::getOverwrite($overwrite, $root, $file))) {
|| !($dest = self::getOverwrite($overwrite, $root, $file))
) {
continue;
}
@ -160,7 +162,8 @@ class dcPackman
{
if (!isset($info['root'])
|| !isset($info['id'])
|| !is_dir($info['root'])) {
|| !is_dir($info['root'])
) {
throw new Exception('Failed to get module info');
}

View file

@ -42,8 +42,7 @@ class libPackman
);
}
if (!empty($file_b)
&& !is_writable(dirname($repo . '/' . $file_b))) {
if (!empty($file_b) && !is_writable(dirname($repo . '/' . $file_b))) {
$core->error->add(
__('Path to second export package is not writable.')
);
@ -54,11 +53,7 @@ class libPackman
public static function is_writable($path, $file)
{
return !(
empty($path) ||
empty($file) ||
!is_writable(dirname($path . '/' . $file))
);
return !(empty($path) || empty($file) || !is_writable(dirname($path . '/' . $file)));
}
public static function modules($core, $modules, $type, $title)
@ -175,7 +170,6 @@ class libPackman
$dup = [];
foreach(self::sort($modules) AS $module) {
if (isset($dup[$module['root']])) {
continue;
}

View file

@ -18,7 +18,6 @@ if (!defined('DC_CONTEXT_ADMIN')) {
dcPage::checkSuper();
# Queries
$p_url = 'plugin.php?p=pacKman';
$action = isset($_POST['action']) ? $_POST['action'] : '';
$type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : '';
@ -59,11 +58,9 @@ $is_configured = libPackman::is_configured(
);
# Actions
try
{
try {
# Download
if (isset($_REQUEST['package']) && empty($type)) {
$modules = [];
if ($type == 'plugins') {
$modules = dcPackman::getPackages($core, $plugins_path);
@ -77,9 +74,9 @@ try
}
foreach($modules as $f) {
if (preg_match('/' . preg_quote($_REQUEST['package']) . '$/', $f['root'])
&& is_file($f['root']) && is_readable($f['root'])) {
&& is_file($f['root']) && is_readable($f['root'])
) {
# --BEHAVIOR-- packmanBeforeDownloadPackage
$core->callBehavior('packmanBeforeDownloadPackage', $f, $type);
@ -100,14 +97,13 @@ try
header('Content-Type: text/plain');
http::head(404, 'Not Found');
exit;
} elseif (!empty($action) && !$is_editable) {
throw new Exception('No selected modules');
# Pack
} elseif ($action == 'packup') {
foreach ($_POST['modules'] as $root => $id) {
if (!${$type}->moduleExists($id)) {
throw new Exception('No such module');
}
@ -139,13 +135,15 @@ try
dcPage::addSuccessNotice(
__('Package successfully created.')
);
http::redirect(empty($_POST['redir']) ?
$p_url . '#packman-' . $type : $_POST['redir']
);
if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']);
} else {
$core->adminurl->redirect('admin.plugin.pacKman', [], '#packman-' . $type);
}
# Delete
} elseif ($action == 'delete') {
foreach ($_POST['modules'] as $root => $id) {
if (!file_exists($root) || !files::isDeletable($root)) {
throw new Exception('Undeletable file: ' . $root);
@ -157,13 +155,15 @@ try
dcPage::addSuccessNotice(
__('Package successfully deleted.')
);
http::redirect(
$p_url . '#packman-repository-' . $type
);
if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']);
} else {
$core->adminurl->redirect('admin.plugin.pacKman', [], '#packman-repository-' . $type);
}
# Install
} elseif ($action == 'install') {
foreach ($_POST['modules'] as $root => $id) {
# --BEHAVIOR-- packmanBeforeInstallPackage
@ -184,13 +184,15 @@ try
dcPage::addSuccessNotice(
__('Package successfully installed.')
);
http::redirect(
$p_url . '#packman-repository-' . $type
);
if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']);
} else {
$core->adminurl->redirect('admin.plugin.pacKman', [], '#packman-repository-' . $type);
}
# Copy
} elseif (strpos($action, 'copy_to_') !== false) {
if ($action == 'copy_to_plugins') {
$dest = $plugins_path;
} elseif ($action == 'copy_to_themes') {
@ -209,13 +211,15 @@ try
dcPage::addSuccessNotice(
__('Package successfully copied.')
);
http::redirect(
$p_url . '#packman-repository-' . $type
);
if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']);
} else {
$core->adminurl->redirect('admin.plugin.pacKman', [], '#packman-repository-' . $type);
}
# Move
} elseif (strpos($action, 'move_to_') !== false) {
if ($action == 'move_to_plugins') {
$dest = $plugins_path;
} elseif ($action == 'move_to_themes') {
@ -235,9 +239,12 @@ try
dcPage::addSuccessNotice(
__('Package successfully moved.')
);
http::redirect(
$p_url . '#packman-repository-' . $type
);
if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']);
} else {
$core->adminurl->redirect('admin.plugin.pacKman', [], '#packman-repository-' . $type);
}
}
} catch(Exception $e) {
$core->error->add($e->getMessage());
@ -247,7 +254,7 @@ try
echo
'<html><head><title>' . __('pacKman') . '</title>' .
dcPage::jsPageTabs() .
dcPage::jsLoad('index.php?pf=pacKman/js/packman.js');
dcPage::jsLoad(dcPage::getPF('pacKman/js/packman.js'));
# --BEHAVIOR-- packmanAdminHeader
$core->callBehavior('packmanAdminHeader', $core);