fix help and next step of PSR2

This commit is contained in:
Jean-Christian Denis 2021-08-23 15:07:29 +02:00
parent 42f12a73e6
commit 91c7f55946
11 changed files with 529 additions and 562 deletions

View file

@ -1,3 +1,8 @@
pacKman 2021.08.22
* fix PSR2 coding style
* update license
* fix help
pacKman 2021.08.17
* move to Franck style

View file

@ -41,10 +41,10 @@ class packmanBehaviors
'small-icon' => 'index.php?pf=pacKman/icon.png',
'large-icon' => 'index.php?pf=pacKman/icon-big.png',
'permissions' => $core->auth->isSuperAdmin(),
'active_cb' => array(
'active_cb' => [
'packmanBehaviors',
'adminDashboardFavoritesActive'
)
]
]);
}

View file

@ -65,8 +65,7 @@ if (!empty($_POST['save'])) {
$list->getRedir())
);
}
}
catch (Exception $e) {
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}

View file

@ -18,52 +18,52 @@ if (!defined('DC_CONTEXT_ADMIN')) {
# -- Module specs --
$dc_min = '2.6';
$dc_min = '2.18';
$mod_id = 'pacKman';
$mod_conf = array(
array(
$mod_conf = [
[
'packman_menu_plugins',
'Add link to pacKman in plugins page',
false,
'boolean'
),
array(
],
[
'packman_pack_nocomment',
'Remove comments from files',
false,
'boolean'
),
array(
],
[
'packman_pack_overwrite',
'Overwrite existing package',
false,
'boolean'
),
array(
],
[
'packman_pack_filename',
'Name of package',
'%type%-%id%',
'string'
),
array(
],
[
'packman_secondpack_filename',
'Name of second package',
'%type%-%id%-%version%',
'string'
),
array(
],
[
'packman_pack_repository',
'Path to package repository',
'',
'string'
),
array(
],
[
'packman_pack_excludefiles',
'Extra files to exclude from package',
'*.zip,*.tar,*.tar.gz,.directory,.hg',
'string'
)
);
]
];
# -- Nothing to change below --
@ -73,9 +73,7 @@ try {
if (version_compare(
$core->getVersion($mod_id),
$core->plugins->moduleInfo($mod_id, 'version'),
'>='
)) {
'>=')) {
return null;
}

View file

@ -13,13 +13,12 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
class dcPackman
{
public static $exclude = array(
public static $exclude = [
'.',
'..',
'__MACOSX',
@ -29,14 +28,14 @@ class dcPackman
'CVS',
'.DS_Store',
'Thumbs.db'
);
];
public static function quote_exclude($exclude)
{
foreach($exclude AS $k => $v) {
$exclude[$k] = '#(^|/)(' . str_replace(
array('.', '*'),
array('\.', '.*?'),
['.', '*'],
['\.', '.*?'],
trim($v)
) . ')(/|$)#';
}
@ -50,7 +49,6 @@ class dcPackman
$cache = self::getCache() . '/';
if (!is_dir($root) || !is_readable($root)) {
return $res;
}
@ -64,7 +62,6 @@ class dcPackman
}
if (empty($zip_files)) {
return $res;
}
@ -80,8 +77,7 @@ class dcPackman
if ($zip_root_dir != false) {
$define = $zip_root_dir . '/_define.php';
$has_define = $zip->hasFile($define);
}
else {
} else {
$define = '_define.php';
$has_define = $zip->hasFile($define);
}
@ -109,12 +105,10 @@ class dcPackman
return $res;
}
public static function pack($info, $root, $files, $overwrite=false, $exclude=array(), $nocomment=false)
public static function pack($info, $root, $files, $overwrite = false, $exclude = [], $nocomment = false)
{
if (!($info = self::getInfo($info))
|| !($root = self::getRoot($root))
) {
|| !($root = self::getRoot($root))) {
return false;
}
@ -122,8 +116,7 @@ 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;
}
@ -164,8 +157,7 @@ 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');
}
@ -182,25 +174,24 @@ class dcPackman
private static function getFile($file, $info)
{
if (empty($file) || empty($info)) {
return null;
}
$file = str_replace(
array(
[
'%type%',
'%id%',
'%version%',
'%author%',
'%time%'
),
array(
],
[
$info['type'],
$info['id'],
$info['version'],
$info['author'],
time()
),
],
$file
);
$parts = explode('/', $file);

View file

@ -92,7 +92,7 @@ class packmanFileZip extends fileZip
protected static function removePHPComment($content)
{
$comment = array(T_COMMENT);
$comment = [T_COMMENT];
if (defined('T_DOC_COMMENT')) {
$comment[] = T_DOC_COMMENT; // PHP 5
}
@ -103,22 +103,17 @@ class packmanFileZip extends fileZip
$newStr = '';
$tokens = token_get_all($content);
foreach ($tokens as $token)
{
if (is_array($token))
{
foreach ($tokens as $token) {
if (is_array($token)) {
if (in_array($token[0], $comment)) {
//$newStr .= "\n";
}
else {
} else {
$newStr .= $token[1];
}
}
else {
} else {
$newStr .= $token;
}
}
return $newStr;
}
}
?>

View file

@ -13,7 +13,6 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
@ -93,7 +92,7 @@ class libPackman
echo
'<tr class="line">' .
'<td class="nowrap"><label class="classic">' .
form::checkbox(array('modules['.html::escapeHTML($module['root']).']'), html::escapeHTML($id)).
form::checkbox(['modules[' . html::escapeHTML($module['root']) . ']'], html::escapeHTML($id)) .
html::escapeHTML($id) .
'</label></td>' .
'<td class="nowrap count">' .
@ -114,13 +113,13 @@ class libPackman
'<p>' .
(!empty($_REQUEST['redir']) ?
form::hidden(
array('redir'),
['redir'],
html::escapeHTML($_REQUEST['redir'])
) : ''
) .
form::hidden(array('p'), 'pacKman').
form::hidden(array('type'), $type).
form::hidden(array('action'), 'packup').
form::hidden(['p'], 'pacKman') .
form::hidden(['type'], $type) .
form::hidden(['action'], 'packup') .
'<input type="submit" name="packup" value="' .
__('Pack up selected modules') .'" />' .
$core->formNonce() . '</p>' .
@ -131,8 +130,7 @@ class libPackman
public static function repository($core, $modules, $type, $title)
{
if (!in_array($type,array('plugins','themes','repository'))) {
if (!in_array($type, ['plugins', 'themes', 'repository'])) {
return null;
}
@ -149,7 +147,7 @@ class libPackman
return null;
}
$combo_action = array(__('delete') => 'delete');
$combo_action = [__('delete') => 'delete'];
if ($type == 'plugins' || $type == 'themes') {
$combo_action[__('install')] = 'install';
@ -176,7 +174,7 @@ class libPackman
'<th class="nowrap">' . __('File') . '</th>' .
'</tr>';
$dup = array();
$dup = [];
foreach(self::sort($modules) AS $module) {
if (isset($dup[$module['root']])) {
@ -189,7 +187,7 @@ class libPackman
'<tr class="line">' .
'<td class="nowrap"><label class="classic" title="' .
html::escapeHTML($module['root']) . '">' .
form::checkbox(array('modules['.html::escapeHTML($module['root']).']'), $module['id']).
form::checkbox(['modules[' . html::escapeHTML($module['root']) . ']'], $module['id']) .
html::escapeHTML($module['id']) .
'</label></td>' .
'<td class="nowrap count">' .
@ -199,7 +197,8 @@ class libPackman
__(html::escapeHTML($module['name'])) .
'</td>' .
'<td class="nowrap">' .
'<a class="packman-download" href="plugin.php?p=pacKman&amp;package='.basename($module['root']).'&amp;repo='.$type.'" title="'.__('Download').'">'.
'<a class="packman-download" href="plugin.php?p=pacKman&amp;package=' .
basename($module['root']) . '&amp;repo=' . $type . '" title="'. __('Download') . '">' .
html::escapeHTML(basename($module['root'])) . '</a>' .
'</td>' .
'</tr>';
@ -210,11 +209,11 @@ class libPackman
'<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' . __('Selected modules action:') . ' ' .
form::combo(array('action'), $combo_action).
form::combo(['action'], $combo_action) .
'<input type="submit" name="packup" value="' . __('ok') . '" />' .
form::hidden(array('p'), 'pacKman').
form::hidden(array('tab'), 'repository').
form::hidden(array('type'), $type).
form::hidden(['p'], 'pacKman') .
form::hidden(['tab'], 'repository') .
form::hidden(['type'], $type) .
$core->formNonce() .
'</p>' .
'</div>' .
@ -224,7 +223,7 @@ class libPackman
protected static function sort($modules)
{
$sorter = array();
$sorter = [];
foreach($modules as $id => $module) {
$sorter[$id] = $id;
}

View file

@ -21,8 +21,7 @@ dcPage::checkSuper();
# Queries
$p_url = 'plugin.php?p=pacKman';
$action = isset($_POST['action']) ? $_POST['action'] : '';
$type = isset($_POST['type']) && in_array($_POST['type'],
array('plugins', 'themes', 'repository')) ? $_POST['type'] : '';
$type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : '';
# Settings
$core->blog->settings->addNamespace('pacKman');
@ -66,14 +65,12 @@ try
# Download
if (isset($_REQUEST['package']) && empty($type)) {
$modules = array();
$modules = [];
if ($type == 'plugins') {
$modules = dcPackman::getPackages($core, $plugins_path);
}
elseif ($type == 'themes') {
} elseif ($type == 'themes') {
$modules = dcPackman::getPackages($core, $themes_path);
}
else {
} else {
$modules = array_merge(
dcPackman::getPackages($core, dirname($repo_path . '/' . $s->packman_pack_filename)),
dcPackman::getPackages($core, dirname($repo_path . '/' . $s->packman_secondpack_filename))
@ -83,8 +80,7 @@ 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);
@ -105,13 +101,11 @@ try
header('Content-Type: text/plain');
http::head(404, 'Not Found');
exit;
}
elseif (!empty($action) && !$is_editable) {
} elseif (!empty($action) && !$is_editable) {
throw new Exception('No selected modules');
}
# Pack
elseif ($action == 'packup') {
} elseif ($action == 'packup') {
foreach ($_POST['modules'] as $root => $id) {
@ -124,10 +118,10 @@ try
$module['type'] = $type == 'themes' ? 'theme' : 'plugin';
$root = $s->packman_pack_repository;
$files = array(
$files = [
$s->packman_pack_filename,
$s->packman_secondpack_filename
);
];
$nocomment = $s->packman_pack_nocomment;
$overwrite = $s->packman_pack_overwrite;
$exclude = explode(',', $s->packman_pack_excludefiles);
@ -148,10 +142,9 @@ try
http::redirect(empty($_POST['redir']) ?
$p_url . '#packman-' . $type : $_POST['redir']
);
}
# Delete
elseif ($action == 'delete') {
} elseif ($action == 'delete') {
foreach ($_POST['modules'] as $root => $id) {
if (!file_exists($root) || !files::isDeletable($root)) {
@ -167,10 +160,9 @@ try
http::redirect(
$p_url . '#packman-repository-' . $type
);
}
# Install
elseif ($action == 'install') {
} elseif ($action == 'install') {
foreach ($_POST['modules'] as $root => $id) {
@ -195,18 +187,15 @@ try
http::redirect(
$p_url . '#packman-repository-' . $type
);
}
# Copy
elseif (strpos($action, 'copy_to_') !== false) {
} elseif (strpos($action, 'copy_to_') !== false) {
if ($action == 'copy_to_plugins') {
$dest = $plugins_path;
}
elseif ($action == 'copy_to_themes') {
} elseif ($action == 'copy_to_themes') {
$dest = $themes_path;
}
elseif ($action == 'copy_to_repository') {
} elseif ($action == 'copy_to_repository') {
$dest = $repo_path;
}
@ -223,18 +212,15 @@ try
http::redirect(
$p_url . '#packman-repository-' . $type
);
}
# Move
elseif (strpos($action, 'move_to_') !== false) {
} elseif (strpos($action, 'move_to_') !== false) {
if ($action == 'move_to_plugins') {
$dest = $plugins_path;
}
elseif ($action == 'move_to_themes') {
} elseif ($action == 'move_to_themes') {
$dest = $themes_path;
}
elseif ($action == 'move_to_repository') {
} elseif ($action == 'move_to_repository') {
$dest = $repo_path;
}
@ -253,8 +239,7 @@ try
$p_url . '#packman-repository-' . $type
);
}
}
catch(Exception $e) {
} catch(Exception $e) {
$core->error->add($e->getMessage());
}
@ -270,12 +255,10 @@ $core->callBehavior('packmanAdminHeader', $core);
echo
'</head><body>' .
dcPage::breadcrumb(
array(
dcPage::breadcrumb([
__('Plugins') => '',
__('pacKman') => ''
)
).
]).
dcPage::notices();
if ($core->error->flag()) {
@ -284,9 +267,8 @@ if ($core->error->flag()) {
'<a href="plugins.php?module=pacKman&amp;conf=1&amp;redir=' .
urlencode('plugin.php?p=pacKman') . '">' . __('Configuration') . '</a>' .
'</p>';
}
else {
} else {
$repo_path_modules = array_merge(
dcPackman::getPackages(
$core,

View file

@ -55,9 +55,8 @@
<p>Si vous souhaitez plus d'aide ou apporter votre contribution à cette extension, voici quelques liens utiles.</p>
<ul>
<li><a href="http://forum.dotclear.org/viewtopic.php?id=40066">Sujet sur le forum Dotclear</a></li>
<li><a href="http://lab.dotclear.org/wiki/plugin/pacKman">Dépôt svn</a></li>
<li><a href="https://bitbucket.org/JcDenis/packman">Dépôt hg</a></li>
<li><a href="http://jcd.lv/pacKman">Billet dédié sur le blog de l'auteur</a></li>
<li><a href="https://github.com/JcDenis/pacKman">Dépôt github</a></li>
<li><a href="https://plugins.dotaddict.org/dc2/details/pacKman">Dépôt Dotaddict</a></li>
</ul>
</body>

View file

@ -13,10 +13,9 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
return null;
}
if (!empty($_REQUEST['module']) && $_REQUEST['module'] == 'pacKman') {
$__resources['help']['core_plugins_conf'] = dirname(__FILE__).'/help/help.html';
if (!isset($__resources['help']['pacKman'])) {
$__resources['help']['pacKman'] = dirname(__FILE__) . '/help/help.html';
}