cosmetics

This commit is contained in:
Jean-Christian Paul 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 2021.08.22.1 - dev
- add option to convert newline from files content on the fly - add option to convert newline from files content on the fly
- clean up again... - clean up again...
- fix wrong version on repository
- fix modules sort
2021.08.22 2021.08.22
- fix PSR2 coding style - fix PSR2 coding style

View File

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

View File

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

View File

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