fix help and next step of PSR2

2.28
Jean-Christian Paul 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 pacKman 2021.08.17
* move to Franck style * move to Franck style

View File

@ -36,15 +36,15 @@ class packmanBehaviors
public static function adminDashboardFavorites($core, $favs) public static function adminDashboardFavorites($core, $favs)
{ {
$favs->register('pacKman', [ $favs->register('pacKman', [
'title' => __('Packages repository'), 'title' => __('Packages repository'),
'url' => 'plugin.php?p=pacKman#packman-repository-repository', 'url' => 'plugin.php?p=pacKman#packman-repository-repository',
'small-icon' => 'index.php?pf=pacKman/icon.png', 'small-icon' => 'index.php?pf=pacKman/icon.png',
'large-icon' => 'index.php?pf=pacKman/icon-big.png', 'large-icon' => 'index.php?pf=pacKman/icon-big.png',
'permissions' => $core->auth->isSuperAdmin(), 'permissions' => $core->auth->isSuperAdmin(),
'active_cb' => array( 'active_cb' => [
'packmanBehaviors', 'packmanBehaviors',
'adminDashboardFavoritesActive' 'adminDashboardFavoritesActive'
) ]
]); ]);
} }

View File

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

View File

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

View File

@ -16,8 +16,8 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$d = dirname(__FILE__).'/inc/'; $d = dirname(__FILE__) . '/inc/';
$__autoload['dcPackman'] = $d.'class.dc.packman.php'; $__autoload['dcPackman'] = $d . 'class.dc.packman.php';
$__autoload['libPackman'] = $d.'lib.packman.php'; $__autoload['libPackman'] = $d . 'lib.packman.php';
$__autoload['packmanFileZip'] = $d.'lib.packman.filezip.php'; $__autoload['packmanFileZip'] = $d . 'lib.packman.filezip.php';

View File

@ -13,225 +13,216 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null;
return null;
} }
class dcPackman class dcPackman
{ {
public static $exclude = array( public static $exclude = [
'.', '.',
'..', '..',
'__MACOSX', '__MACOSX',
'.svn', '.svn',
'.hg*', '.hg*',
'.git*', '.git*',
'CVS', 'CVS',
'.DS_Store', '.DS_Store',
'Thumbs.db' 'Thumbs.db'
); ];
public static function quote_exclude($exclude) public static function quote_exclude($exclude)
{ {
foreach($exclude AS $k => $v) { foreach($exclude AS $k => $v) {
$exclude[$k] = '#(^|/)('.str_replace( $exclude[$k] = '#(^|/)(' . str_replace(
array('.', '*'), ['.', '*'],
array('\.', '.*?'), ['\.', '.*?'],
trim($v) trim($v)
).')(/|$)#'; ) . ')(/|$)#';
} }
return $exclude; return $exclude;
} }
public static function getPackages($core, $root) public static function getPackages($core, $root)
{ {
$res = array(); $res = array();
$cache = self::getCache().'/'; $cache = self::getCache() . '/';
if (!is_dir($root) || !is_readable($root)) { if (!is_dir($root) || !is_readable($root)) {
return $res;
}
return $res; $files = files::scanDir($root);
} $zip_files = array();
foreach($files AS $file) {
if (!preg_match('#(^|/)(.*?)\.zip(/|$)#', $file)) {
continue;
}
$zip_files[] = $file;
}
$files = files::scanDir($root); if (empty($zip_files)) {
$zip_files = array(); return $res;
foreach($files AS $file) { }
if (!preg_match('#(^|/)(.*?)\.zip(/|$)#', $file)) {
continue;
}
$zip_files[] = $file;
}
if (empty($zip_files)) { $modules = new dcModules($core);
$themes = new dcThemes($core);
return $res; $i = 0;
} foreach($zip_files AS $zip_file) {
$zip = new fileUnzip($root . '/' . $zip_file);
$modules = new dcModules($core); $zip_root_dir = $zip->getRootDir();
$themes = new dcThemes($core);
$i = 0; if ($zip_root_dir != false) {
foreach($zip_files AS $zip_file) { $define = $zip_root_dir . '/_define.php';
$zip = new fileUnzip($root.'/'.$zip_file); $has_define = $zip->hasFile($define);
} else {
$define = '_define.php';
$has_define = $zip->hasFile($define);
}
$zip_root_dir = $zip->getRootDir(); if (!$has_define) {
continue;
}
if ($zip_root_dir != false) { $zip->unzip($define, $cache . '/_define.php');
$define = $zip_root_dir.'/_define.php';
$has_define = $zip->hasFile($define);
}
else {
$define = '_define.php';
$has_define = $zip->hasFile($define);
}
if (!$has_define) { $modules->requireDefine($cache, $zip_root_dir);
continue; if ($modules->moduleExists($zip_root_dir)) {
} $res[$i] = $modules->getModules($zip_root_dir);
} else {
$themes->requireDefine($cache, $zip_root_dir);
$res[$i] = $themes->getModules($zip_root_dir);
}
$res[$i]['id'] = $zip_root_dir;
$res[$i]['root'] = $root . '/' . $zip_file;
$zip->unzip($define,$cache.'/_define.php'); unlink($cache . '_define.php');
$i++;
}
$modules->requireDefine($cache, $zip_root_dir); return $res;
if ($modules->moduleExists($zip_root_dir)) { }
$res[$i] = $modules->getModules($zip_root_dir);
} else {
$themes->requireDefine($cache, $zip_root_dir);
$res[$i] = $themes->getModules($zip_root_dir);
}
$res[$i]['id'] = $zip_root_dir;
$res[$i]['root'] = $root.'/'.$zip_file;
unlink($cache.'_define.php'); public static function pack($info, $root, $files, $overwrite = false, $exclude = [], $nocomment = false)
$i++; {
} if (!($info = self::getInfo($info))
|| !($root = self::getRoot($root))) {
return false;
}
return $res; $exclude = self::getExclude($exclude);
}
public static function pack($info, $root, $files, $overwrite=false, $exclude=array(), $nocomment=false) foreach($files as $file) {
{ if (!($file = self::getFile($file, $info))
if (!($info = self::getInfo($info)) || !($dest = self::getOverwrite($overwrite, $root, $file))) {
|| !($root = self::getRoot($root)) continue;
) { }
return false; @set_time_limit(300);
} $fp = fopen($dest, 'wb');
$exclude = self::getExclude($exclude); $zip = $nocomment ?
new packmanFileZip($fp) : new fileZip($fp);
foreach($files as $file) { foreach($exclude AS $e) {
if (!($file = self::getFile($file, $info)) $zip->addExclusion($e);
|| !($dest = self::getOverwrite($overwrite, $root, $file)) }
) { $zip->addDirectory(
continue; path::real($info['root']),
} $info['id'],
true
);
@set_time_limit(300); $zip->write();
$fp = fopen($dest,'wb'); $zip->close();
unset($zip);
}
$zip = $nocomment ? return true;
new packmanFileZip($fp) : new fileZip($fp); }
foreach($exclude AS $e) { private static function getRoot($root)
$zip->addExclusion($e); {
} $root = path::real($root);
$zip->addDirectory( if (!is_dir($root) || !is_writable($root)) {
path::real($info['root']), throw new Exception('Directory is not writable');
$info['id'], }
true
);
$zip->write(); return $root;
$zip->close(); }
unset($zip);
}
return true; private static function getInfo($info)
} {
if (!isset($info['root'])
|| !isset($info['id'])
|| !is_dir($info['root'])) {
throw new Exception('Failed to get module info');
}
private static function getRoot($root) return $info;
{ }
$root = path::real($root);
if (!is_dir($root) || !is_writable($root)) {
throw new Exception('Directory is not writable');
}
return $root; private static function getExclude($exclude)
} {
$exclude = array_merge(self::$exclude, $exclude);
private static function getInfo($info) return self::quote_exclude($exclude);
{ }
if (!isset($info['root'])
|| !isset($info['id'])
|| !is_dir($info['root']))
{
throw new Exception('Failed to get module info');
}
return $info; private static function getFile($file, $info)
} {
if (empty($file) || empty($info)) {
return null;
}
private static function getExclude($exclude) $file = str_replace(
{ [
$exclude = array_merge(self::$exclude, $exclude); '%type%',
'%id%',
'%version%',
'%author%',
'%time%'
],
[
$info['type'],
$info['id'],
$info['version'],
$info['author'],
time()
],
$file
);
$parts = explode('/', $file);
foreach($parts as $i => $part) {
$parts[$i] = files::tidyFileName($part);
}
return implode('/', $parts) . '.zip';
}
return self::quote_exclude($exclude); private static function getOverwrite($overwrite, $root, $file)
} {
$path = $root . '/' . $file;
if (file_exists($path) && !$overwrite) {
// don't break loop
//throw new Exception('File already exists');
return null;
}
private static function getFile($file, $info) return $path;
{ }
if (empty($file) || empty($info)) {
return null; private static function getCache()
} {
$c = DC_TPL_CACHE . '/packman';
if (!file_exists($c)) {
@mkdir($c);
}
if (!is_writable($c)) {
throw new Exception('Failed to get temporary directory');
}
$file = str_replace( return $c;
array( }
'%type%',
'%id%',
'%version%',
'%author%',
'%time%'
),
array(
$info['type'],
$info['id'],
$info['version'],
$info['author'],
time()
),
$file
);
$parts = explode('/', $file);
foreach($parts as $i => $part) {
$parts[$i] = files::tidyFileName($part);
}
return implode('/', $parts).'.zip';
}
private static function getOverwrite($overwrite, $root, $file)
{
$path = $root.'/'.$file;
if (file_exists($path) && !$overwrite) {
// don't break loop
//throw new Exception('File already exists');
return null;
}
return $path;
}
private static function getCache()
{
$c = DC_TPL_CACHE.'/packman';
if (!file_exists($c)) {
@mkdir($c);
}
if (!is_writable($c)) {
throw new Exception('Failed to get temporary directory');
}
return $c;
}
} }

View File

@ -14,111 +14,106 @@
class packmanFileZip extends fileZip class packmanFileZip extends fileZip
{ {
protected function writeFile($name,$file,$size,$mtime) protected function writeFile($name, $file, $size, $mtime)
{ {
if (!isset($this->entries[$name])) { if (!isset($this->entries[$name])) {
return; return;
} }
$size = filesize($file); $size = filesize($file);
$this->memoryAllocate($size*3); $this->memoryAllocate($size * 3);
$content = file_get_contents($file); $content = file_get_contents($file);
//cleanup file contents //cleanup file contents
// at this time only php files // at this time only php files
if (substr($file,-4) == '.php') { if (substr($file,-4) == '.php') {
$content = self::removePHPComment($content); $content = self::removePHPComment($content);
} }
$unc_len = strlen($content); $unc_len = strlen($content);
$crc = crc32($content); $crc = crc32($content);
$zdata = gzdeflate($content); $zdata = gzdeflate($content);
$c_len = strlen($zdata); $c_len = strlen($zdata);
unset($content); unset($content);
$mdate = $this->makeDate($mtime); $mdate = $this->makeDate($mtime);
$mtime = $this->makeTime($mtime); $mtime = $this->makeTime($mtime);
# Data descriptor # Data descriptor
$data_desc = $data_desc =
"\x50\x4b\x03\x04". "\x50\x4b\x03\x04" .
"\x14\x00". # ver needed to extract "\x14\x00" . # ver needed to extract
"\x00\x00". # gen purpose bit flag "\x00\x00" . # gen purpose bit flag
"\x08\x00". # compression method "\x08\x00" . # compression method
pack('v',$mtime). # last mod time pack('v', $mtime) . # last mod time
pack('v',$mdate). # last mod date pack('v', $mdate) . # last mod date
pack('V',$crc). # crc32 pack('V', $crc) . # crc32
pack('V',$c_len). # compressed filesize pack('V', $c_len) . # compressed filesize
pack('V',$unc_len). # uncompressed filesize pack('V', $unc_len) . # uncompressed filesize
pack('v',strlen($name)). # length of filename pack('v', strlen($name)) . # length of filename
pack('v',0). # extra field length pack('v' ,0) . # extra field length
$name. # end of "local file header" segment $name . # end of "local file header" segment
$zdata. # "file data" segment $zdata . # "file data" segment
pack('V',$crc). # crc32 pack('V', $crc) . # crc32
pack('V',$c_len). # compressed filesize pack('V', $c_len) . # compressed filesize
pack('V',$unc_len); # uncompressed filesize pack('V', $unc_len); # uncompressed filesize
fwrite($this->fp,$data_desc); fwrite($this->fp, $data_desc);
unset($zdata); unset($zdata);
$new_offset = $this->old_offset + strlen($data_desc); $new_offset = $this->old_offset + strlen($data_desc);
# Add to central directory record # Add to central directory record
$cdrec = $cdrec =
"\x50\x4b\x01\x02". "\x50\x4b\x01\x02" .
"\x00\x00". # version made by "\x00\x00" . # version made by
"\x14\x00". # version needed to extract "\x14\x00" . # version needed to extract
"\x00\x00". # gen purpose bit flag "\x00\x00" . # gen purpose bit flag
"\x08\x00". # compression method "\x08\x00" . # compression method
pack('v',$mtime). # last mod time pack('v', $mtime) . # last mod time
pack('v',$mdate). # last mod date pack('v', $mdate) . # last mod date
pack('V',$crc). # crc32 pack('V', $crc) . # crc32
pack('V',$c_len). # compressed filesize pack('V', $c_len) . # compressed filesize
pack('V',$unc_len). # uncompressed filesize pack('V', $unc_len) . # uncompressed filesize
pack('v',strlen($name)). # length of filename pack('v', strlen($name)) . # length of filename
pack('v',0). # extra field length pack('v', 0) . # extra field length
pack('v',0). # file comment length pack('v', 0) . # file comment length
pack('v',0). # disk number start pack('v', 0) . # disk number start
pack('v',0). # internal file attributes pack('v', 0) . # internal file attributes
pack('V',32). # external file attributes - 'archive' bit set pack('V', 32) . # external file attributes - 'archive' bit set
pack('V',$this->old_offset). # relative offset of local header pack('V', $this->old_offset). # relative offset of local header
$name; $name;
$this->old_offset = $new_offset; $this->old_offset = $new_offset;
$this->ctrl_dir[] = $cdrec; $this->ctrl_dir[] = $cdrec;
} }
protected static function removePHPComment($content) protected static function removePHPComment($content)
{ {
$comment = array(T_COMMENT); $comment = [T_COMMENT];
if (defined('T_DOC_COMMENT')) { if (defined('T_DOC_COMMENT')) {
$comment[] = T_DOC_COMMENT; // PHP 5 $comment[] = T_DOC_COMMENT; // PHP 5
} }
if (defined('T_ML_COMMENT')) { if (defined('T_ML_COMMENT')) {
$comment[] = T_ML_COMMENT; // PHP 4 $comment[] = T_ML_COMMENT; // PHP 4
} }
$newStr = ''; $newStr = '';
$tokens = token_get_all($content); $tokens = token_get_all($content);
foreach ($tokens as $token) foreach ($tokens as $token) {
{ if (is_array($token)) {
if (is_array($token)) if (in_array($token[0], $comment)) {
{ //$newStr .= "\n";
if (in_array($token[0],$comment)) { } else {
//$newStr .= "\n"; $newStr .= $token[1];
} }
else { } else {
$newStr .= $token[1]; $newStr .= $token;
} }
} }
else { return $newStr;
$newStr .= $token; }
}
}
return $newStr;
}
} }
?>

View File

@ -13,223 +13,222 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null;
return null;
} }
class libPackman class libPackman
{ {
public static function is_configured($core, $repo, $file_a, $file_b) public static function is_configured($core, $repo, $file_a, $file_b)
{ {
if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) { if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
$core->error->add( $core->error->add(
__('Cache directory is not writable.') __('Cache directory is not writable.')
); );
} }
if (!is_writable($repo)) { if (!is_writable($repo)) {
$core->error->add( $core->error->add(
__('Path to repository is not writable.') __('Path to repository is not writable.')
); );
} }
if (empty($file_a)) { if (empty($file_a)) {
$core->error->add( $core->error->add(
__('You must specify the name of package to export.') __('You must specify the name of package to export.')
); );
} }
if (!is_writable(dirname($repo.'/'.$file_a))) { if (!is_writable(dirname($repo . '/' . $file_a))) {
$core->error->add( $core->error->add(
__('Path to first export package is not writable.') __('Path to first export package is not writable.')
); );
} }
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.')
); );
} }
return !$core->error->flag(); return !$core->error->flag();
} }
public static function is_writable($path, $file) public static function is_writable($path, $file)
{ {
return !( return !(
empty($path) || empty($path) ||
empty($file) || empty($file) ||
!is_writable(dirname($path.'/'.$file)) !is_writable(dirname($path . '/' . $file))
); );
} }
public static function modules($core, $modules, $type, $title) public static function modules($core, $modules, $type, $title)
{ {
$type = $type == 'themes' ? 'themes' : 'plugins'; $type = $type == 'themes' ? 'themes' : 'plugins';
echo echo
'<div class="multi-part" '. '<div class="multi-part" ' .
'id="packman-'.$type.'" title="'.$title.'">'. 'id="packman-' . $type . '" title="' . $title . '">' .
'<h3>'.$title.'</h3>'; '<h3>' . $title . '</h3>';
if (empty($modules) && !is_array($modules)) { if (empty($modules) && !is_array($modules)) {
echo echo
'<p><strong>'.__('There are no modules.').'</strong></p>'. '<p><strong>' . __('There are no modules.') . '</strong></p>' .
'<div>'; '<div>';
return null; return null;
} }
echo echo
'<form action="plugin.php" method="post">'. '<form action="plugin.php" method="post">' .
'<table class="clear"><tr>'. '<table class="clear"><tr>' .
'<th class="nowrap">'.__('Id').'</th>'. '<th class="nowrap">' . __('Id') . '</th>' .
'<th class="nowrap">'.__('Version').'</th>'. '<th class="nowrap">' . __('Version') . '</th>' .
'<th class="nowrap maximal">'.__('Name').'</th>'. '<th class="nowrap maximal">' . __('Name') . '</th>' .
'<th class="nowrap">'.__('Root').'</th>'. '<th class="nowrap">' . __('Root') . '</th>' .
'</tr>'; '</tr>';
foreach (self::sort($modules) as $id => $module) { foreach (self::sort($modules) as $id => $module) {
echo echo
'<tr class="line">'. '<tr class="line">' .
'<td class="nowrap"><label class="classic">'. '<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). html::escapeHTML($id) .
'</label></td>'. '</label></td>' .
'<td class="nowrap count">'. '<td class="nowrap count">' .
html::escapeHTML($module['version']). html::escapeHTML($module['version']) .
'</td>'. '</td>' .
'<td class="nowrap maximal">'. '<td class="nowrap maximal">' .
__(html::escapeHTML($module['name'])). __(html::escapeHTML($module['name'])) .
'</td>'. '</td>' .
'<td class="nowrap">'. '<td class="nowrap">' .
dirname(path::real($module['root'], false)). dirname(path::real($module['root'], false)) .
'</td>'. '</td>' .
'</tr>'; '</tr>';
} }
echo echo
'</table>'. '</table>' .
'<p class="checkboxes-helpers"></p>'. '<p class="checkboxes-helpers"></p>' .
'<p>'. '<p>' .
(!empty($_REQUEST['redir']) ? (!empty($_REQUEST['redir']) ?
form::hidden( form::hidden(
array('redir'), ['redir'],
html::escapeHTML($_REQUEST['redir']) html::escapeHTML($_REQUEST['redir'])
) : '' ) : ''
). ) .
form::hidden(array('p'), 'pacKman'). form::hidden(['p'], 'pacKman') .
form::hidden(array('type'), $type). form::hidden(['type'], $type) .
form::hidden(array('action'), 'packup'). form::hidden(['action'], 'packup') .
'<input type="submit" name="packup" value="'. '<input type="submit" name="packup" value="' .
__('Pack up selected modules').'" />'. __('Pack up selected modules') .'" />' .
$core->formNonce().'</p>'. $core->formNonce() . '</p>' .
'</form>'. '</form>' .
'</div>'; '</div>';
} }
public static function repository($core, $modules, $type, $title) 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;
}
return null; echo
} '<div class="multi-part" ' .
'id="packman-repository-' . $type . '" title="' . $title . '">' .
'<h3>' . $title . '</h3>';
echo if (empty($modules) || !is_array($modules)) {
'<div class="multi-part" '. echo
'id="packman-repository-'.$type.'" title="'.$title.'">'. '<p><strong>' . __('There are no packages') . '</strong></p>' .
'<h3>'.$title.'</h3>'; '</div>';
if (empty($modules) || !is_array($modules)) { return null;
echo }
'<p><strong>'.__('There are no packages').'</strong></p>'.
'</div>';
return null; $combo_action = [__('delete') => 'delete'];
}
$combo_action = array(__('delete') => 'delete'); if ($type == 'plugins' || $type == 'themes') {
$combo_action[__('install')] = 'install';
}
if ($type != 'plugins') {
$combo_action[sprintf(__('copy to %s directory'), __('plugins'))] = 'copy_to_plugins';
$combo_action[sprintf(__('move to %s directory'), __('plugins'))] = 'move_to_plugins';
}
if ($type != 'themes') {
$combo_action[sprintf(__('copy to %s directory'), __('themes'))] = 'copy_to_themes';
$combo_action[sprintf(__('move to %s directory'), __('themes'))] = 'move_to_themes';
}
if ($type != 'repository') {
$combo_action[sprintf(__('copy to %s directory'), __('repository'))] = 'copy_to_repository';
$combo_action[sprintf(__('move to %s directory'), __('repository'))] = 'move_to_repository';
}
if ($type == 'plugins' || $type == 'themes') { echo
$combo_action[__('install')] = 'install'; '<form action="plugin.php" method="post">' .
} '<table class="clear"><tr>' .
if ($type != 'plugins') { '<th class="nowrap">' . __('Id') . '</th>' .
$combo_action[sprintf(__('copy to %s directory'), __('plugins'))] = 'copy_to_plugins'; '<th class="nowrap">' . __('Version') . '</th>' .
$combo_action[sprintf(__('move to %s directory'), __('plugins'))] = 'move_to_plugins'; '<th class="nowrap">' . __('Name') . '</th>' .
} '<th class="nowrap">' . __('File') . '</th>' .
if ($type != 'themes') { '</tr>';
$combo_action[sprintf(__('copy to %s directory'), __('themes'))] = 'copy_to_themes';
$combo_action[sprintf(__('move to %s directory'), __('themes'))] = 'move_to_themes';
}
if ($type != 'repository') {
$combo_action[sprintf(__('copy to %s directory'), __('repository'))] = 'copy_to_repository';
$combo_action[sprintf(__('move to %s directory'), __('repository'))] = 'move_to_repository';
}
echo $dup = [];
'<form action="plugin.php" method="post">'. foreach(self::sort($modules) AS $module) {
'<table class="clear"><tr>'.
'<th class="nowrap">'.__('Id').'</th>'.
'<th class="nowrap">'.__('Version').'</th>'.
'<th class="nowrap">'.__('Name').'</th>'.
'<th class="nowrap">'.__('File').'</th>'.
'</tr>';
$dup = array(); if (isset($dup[$module['root']])) {
foreach(self::sort($modules) AS $module) { continue;
}
if (isset($dup[$module['root']])) { $dup[$module['root']] = 1;
continue;
}
$dup[$module['root']] = 1; echo
'<tr class="line">' .
'<td class="nowrap"><label class="classic" title="' .
html::escapeHTML($module['root']) . '">' .
form::checkbox(['modules[' . html::escapeHTML($module['root']) . ']'], $module['id']) .
html::escapeHTML($module['id']) .
'</label></td>' .
'<td class="nowrap count">' .
html::escapeHTML($module['version']) .
'</td>' .
'<td class="nowrap maximal">' .
__(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') . '">' .
html::escapeHTML(basename($module['root'])) . '</a>' .
'</td>' .
'</tr>';
}
echo echo
'<tr class="line">'. '</table>' .
'<td class="nowrap"><label class="classic" title="'. '<div class="two-cols">' .
html::escapeHTML($module['root']).'">'. '<p class="col checkboxes-helpers"></p>' .
form::checkbox(array('modules['.html::escapeHTML($module['root']).']'), $module['id']). '<p class="col right">' . __('Selected modules action:') . ' ' .
html::escapeHTML($module['id']). form::combo(['action'], $combo_action) .
'</label></td>'. '<input type="submit" name="packup" value="' . __('ok') . '" />' .
'<td class="nowrap count">'. form::hidden(['p'], 'pacKman') .
html::escapeHTML($module['version']). form::hidden(['tab'], 'repository') .
'</td>'. form::hidden(['type'], $type) .
'<td class="nowrap maximal">'. $core->formNonce() .
__(html::escapeHTML($module['name'])). '</p>' .
'</td>'. '</div>' .
'<td class="nowrap">'. '</form>' .
'<a class="packman-download" href="plugin.php?p=pacKman&amp;package='.basename($module['root']).'&amp;repo='.$type.'" title="'.__('Download').'">'. '</div>';
html::escapeHTML(basename($module['root'])).'</a>'. }
'</td>'.
'</tr>';
}
echo protected static function sort($modules)
'</table>'. {
'<div class="two-cols">'. $sorter = [];
'<p class="col checkboxes-helpers"></p>'. foreach($modules as $id => $module) {
'<p class="col right">'.__('Selected modules action:').' '. $sorter[$id] = $id;
form::combo(array('action'), $combo_action). }
'<input type="submit" name="packup" value="'.__('ok').'" />'. array_multisort($sorter, SORT_ASC, $modules);
form::hidden(array('p'), 'pacKman').
form::hidden(array('tab'), 'repository').
form::hidden(array('type'), $type).
$core->formNonce().
'</p>'.
'</div>'.
'</form>'.
'</div>';
}
protected static function sort($modules) return $modules;
{ }
$sorter = array();
foreach($modules as $id => $module) {
$sorter[$id] = $id;
}
array_multisort($sorter, SORT_ASC, $modules);
return $modules;
}
} }

View File

@ -21,8 +21,7 @@ dcPage::checkSuper();
# Queries # Queries
$p_url = 'plugin.php?p=pacKman'; $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'], $type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : '';
array('plugins', 'themes', 'repository')) ? $_POST['type'] : '';
# Settings # Settings
$core->blog->settings->addNamespace('pacKman'); $core->blog->settings->addNamespace('pacKman');
@ -66,14 +65,12 @@ try
# Download # Download
if (isset($_REQUEST['package']) && empty($type)) { if (isset($_REQUEST['package']) && empty($type)) {
$modules = array(); $modules = [];
if ($type == 'plugins') { if ($type == 'plugins') {
$modules = dcPackman::getPackages($core, $plugins_path); $modules = dcPackman::getPackages($core, $plugins_path);
} } elseif ($type == 'themes') {
elseif ($type == 'themes') {
$modules = dcPackman::getPackages($core, $themes_path); $modules = dcPackman::getPackages($core, $themes_path);
} } else {
else {
$modules = array_merge( $modules = array_merge(
dcPackman::getPackages($core, dirname($repo_path . '/' . $s->packman_pack_filename)), dcPackman::getPackages($core, dirname($repo_path . '/' . $s->packman_pack_filename)),
dcPackman::getPackages($core, dirname($repo_path . '/' . $s->packman_secondpack_filename)) dcPackman::getPackages($core, dirname($repo_path . '/' . $s->packman_secondpack_filename))
@ -83,8 +80,7 @@ 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);
@ -105,13 +101,11 @@ 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) {
@ -124,10 +118,10 @@ try
$module['type'] = $type == 'themes' ? 'theme' : 'plugin'; $module['type'] = $type == 'themes' ? 'theme' : 'plugin';
$root = $s->packman_pack_repository; $root = $s->packman_pack_repository;
$files = array( $files = [
$s->packman_pack_filename, $s->packman_pack_filename,
$s->packman_secondpack_filename $s->packman_secondpack_filename
); ];
$nocomment = $s->packman_pack_nocomment; $nocomment = $s->packman_pack_nocomment;
$overwrite = $s->packman_pack_overwrite; $overwrite = $s->packman_pack_overwrite;
$exclude = explode(',', $s->packman_pack_excludefiles); $exclude = explode(',', $s->packman_pack_excludefiles);
@ -148,10 +142,9 @@ try
http::redirect(empty($_POST['redir']) ? http::redirect(empty($_POST['redir']) ?
$p_url . '#packman-' . $type : $_POST['redir'] $p_url . '#packman-' . $type : $_POST['redir']
); );
}
# 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)) {
@ -167,10 +160,9 @@ try
http::redirect( http::redirect(
$p_url . '#packman-repository-' . $type $p_url . '#packman-repository-' . $type
); );
}
# Install # Install
elseif ($action == 'install') { } elseif ($action == 'install') {
foreach ($_POST['modules'] as $root => $id) { foreach ($_POST['modules'] as $root => $id) {
@ -195,18 +187,15 @@ try
http::redirect( http::redirect(
$p_url . '#packman-repository-' . $type $p_url . '#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') {
$dest = $themes_path; $dest = $themes_path;
} } elseif ($action == 'copy_to_repository') {
elseif ($action == 'copy_to_repository') {
$dest = $repo_path; $dest = $repo_path;
} }
@ -223,18 +212,15 @@ try
http::redirect( http::redirect(
$p_url . '#packman-repository-' . $type $p_url . '#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') {
$dest = $themes_path; $dest = $themes_path;
} } elseif ($action == 'move_to_repository') {
elseif ($action == 'move_to_repository') {
$dest = $repo_path; $dest = $repo_path;
} }
@ -253,8 +239,7 @@ try
$p_url . '#packman-repository-' . $type $p_url . '#packman-repository-' . $type
); );
} }
} } catch(Exception $e) {
catch(Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
@ -270,12 +255,10 @@ $core->callBehavior('packmanAdminHeader', $core);
echo echo
'</head><body>' . '</head><body>' .
dcPage::breadcrumb( dcPage::breadcrumb([
array(
__('Plugins') => '', __('Plugins') => '',
__('pacKman') => '' __('pacKman') => ''
) ]).
).
dcPage::notices(); dcPage::notices();
if ($core->error->flag()) { if ($core->error->flag()) {
@ -284,9 +267,8 @@ if ($core->error->flag()) {
'<a href="plugins.php?module=pacKman&amp;conf=1&amp;redir=' . '<a href="plugins.php?module=pacKman&amp;conf=1&amp;redir=' .
urlencode('plugin.php?p=pacKman') . '">' . __('Configuration') . '</a>' . urlencode('plugin.php?p=pacKman') . '">' . __('Configuration') . '</a>' .
'</p>'; '</p>';
}
else {
} else {
$repo_path_modules = array_merge( $repo_path_modules = array_merge(
dcPackman::getPackages( dcPackman::getPackages(
$core, $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> <p>Si vous souhaitez plus d'aide ou apporter votre contribution à cette extension, voici quelques liens utiles.</p>
<ul> <ul>
<li><a href="http://forum.dotclear.org/viewtopic.php?id=40066">Sujet sur le forum Dotclear</a></li> <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://github.com/JcDenis/pacKman">Dépôt github</a></li>
<li><a href="https://bitbucket.org/JcDenis/packman">Dépôt hg</a></li> <li><a href="https://plugins.dotaddict.org/dc2/details/pacKman">Dépôt Dotaddict</a></li>
<li><a href="http://jcd.lv/pacKman">Billet dédié sur le blog de l'auteur</a></li>
</ul> </ul>
</body> </body>

View File

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