From 91c7f55946d19f1e76a53fa0c8f685d36c13a34e Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Mon, 23 Aug 2021 15:07:29 +0200 Subject: [PATCH] fix help and next step of PSR2 --- CHANGELOG.md | 5 + _admin.php | 14 +- _config.php | 3 +- _install.php | 38 ++-- _prepend.php | 8 +- inc/class.dc.packman.php | 357 ++++++++++++++++----------------- inc/lib.packman.filezip.php | 211 ++++++++++---------- inc/lib.packman.php | 381 ++++++++++++++++++------------------ index.php | 60 ++---- locales/fr/help/help.html | 5 +- locales/fr/resources.php | 9 +- 11 files changed, 529 insertions(+), 562 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c391667..69f2fbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +pacKman 2021.08.22 + * fix PSR2 coding style + * update license + * fix help + pacKman 2021.08.17 * move to Franck style diff --git a/_admin.php b/_admin.php index f697ebe..e990982 100644 --- a/_admin.php +++ b/_admin.php @@ -36,15 +36,15 @@ class packmanBehaviors public static function adminDashboardFavorites($core, $favs) { $favs->register('pacKman', [ - 'title' => __('Packages repository'), - 'url' => 'plugin.php?p=pacKman#packman-repository-repository', - 'small-icon' => 'index.php?pf=pacKman/icon.png', - 'large-icon' => 'index.php?pf=pacKman/icon-big.png', - 'permissions' => $core->auth->isSuperAdmin(), - 'active_cb' => array( + 'title' => __('Packages repository'), + 'url' => 'plugin.php?p=pacKman#packman-repository-repository', + 'small-icon' => 'index.php?pf=pacKman/icon.png', + 'large-icon' => 'index.php?pf=pacKman/icon-big.png', + 'permissions' => $core->auth->isSuperAdmin(), + 'active_cb' => [ 'packmanBehaviors', 'adminDashboardFavoritesActive' - ) + ] ]); } diff --git a/_config.php b/_config.php index 3adde98..99fc124 100644 --- a/_config.php +++ b/_config.php @@ -65,8 +65,7 @@ if (!empty($_POST['save'])) { $list->getRedir()) ); } - } - catch (Exception $e) { + } catch (Exception $e) { $core->error->add($e->getMessage()); } } diff --git a/_install.php b/_install.php index 62b8ec0..f53ed3d 100644 --- a/_install.php +++ b/_install.php @@ -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; } diff --git a/_prepend.php b/_prepend.php index 42d5761..6f8b012 100644 --- a/_prepend.php +++ b/_prepend.php @@ -16,8 +16,8 @@ if (!defined('DC_RC_PATH')) { return null; } -$d = dirname(__FILE__).'/inc/'; +$d = dirname(__FILE__) . '/inc/'; -$__autoload['dcPackman'] = $d.'class.dc.packman.php'; -$__autoload['libPackman'] = $d.'lib.packman.php'; -$__autoload['packmanFileZip'] = $d.'lib.packman.filezip.php'; \ No newline at end of file +$__autoload['dcPackman'] = $d . 'class.dc.packman.php'; +$__autoload['libPackman'] = $d . 'lib.packman.php'; +$__autoload['packmanFileZip'] = $d . 'lib.packman.filezip.php'; \ No newline at end of file diff --git a/inc/class.dc.packman.php b/inc/class.dc.packman.php index ccbdf58..ae6a68a 100644 --- a/inc/class.dc.packman.php +++ b/inc/class.dc.packman.php @@ -13,225 +13,216 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_CONTEXT_ADMIN')) { - - return null; + return null; } class dcPackman { - public static $exclude = array( - '.', - '..', - '__MACOSX', - '.svn', - '.hg*', - '.git*', - 'CVS', - '.DS_Store', - 'Thumbs.db' - ); + public static $exclude = [ + '.', + '..', + '__MACOSX', + '.svn', + '.hg*', + '.git*', + 'CVS', + '.DS_Store', + 'Thumbs.db' + ]; - public static function quote_exclude($exclude) - { - foreach($exclude AS $k => $v) { - $exclude[$k] = '#(^|/)('.str_replace( - array('.', '*'), - array('\.', '.*?'), - trim($v) - ).')(/|$)#'; - } + public static function quote_exclude($exclude) + { + foreach($exclude AS $k => $v) { + $exclude[$k] = '#(^|/)(' . str_replace( + ['.', '*'], + ['\.', '.*?'], + trim($v) + ) . ')(/|$)#'; + } - return $exclude; - } + return $exclude; + } - public static function getPackages($core, $root) - { - $res = array(); + public static function getPackages($core, $root) + { + $res = array(); - $cache = self::getCache().'/'; - if (!is_dir($root) || !is_readable($root)) { + $cache = self::getCache() . '/'; + 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); - $zip_files = array(); - foreach($files AS $file) { - if (!preg_match('#(^|/)(.*?)\.zip(/|$)#', $file)) { - continue; - } - $zip_files[] = $file; - } + if (empty($zip_files)) { + return $res; + } - 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); - $themes = new dcThemes($core); + $zip_root_dir = $zip->getRootDir(); - $i = 0; - foreach($zip_files AS $zip_file) { - $zip = new fileUnzip($root.'/'.$zip_file); + if ($zip_root_dir != false) { + $define = $zip_root_dir . '/_define.php'; + $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) { - $define = $zip_root_dir.'/_define.php'; - $has_define = $zip->hasFile($define); - } - else { - $define = '_define.php'; - $has_define = $zip->hasFile($define); - } + $zip->unzip($define, $cache . '/_define.php'); - if (!$has_define) { - continue; - } + $modules->requireDefine($cache, $zip_root_dir); + 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); - 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; + return $res; + } - unlink($cache.'_define.php'); - $i++; - } + public static function pack($info, $root, $files, $overwrite = false, $exclude = [], $nocomment = false) + { + 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) - { - if (!($info = self::getInfo($info)) - || !($root = self::getRoot($root)) - ) { + foreach($files as $file) { + if (!($file = self::getFile($file, $info)) + || !($dest = self::getOverwrite($overwrite, $root, $file))) { + 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) { - if (!($file = self::getFile($file, $info)) - || !($dest = self::getOverwrite($overwrite, $root, $file)) - ) { - continue; - } + foreach($exclude AS $e) { + $zip->addExclusion($e); + } + $zip->addDirectory( + path::real($info['root']), + $info['id'], + true + ); - @set_time_limit(300); - $fp = fopen($dest,'wb'); + $zip->write(); + $zip->close(); + unset($zip); + } - $zip = $nocomment ? - new packmanFileZip($fp) : new fileZip($fp); + return true; + } - foreach($exclude AS $e) { - $zip->addExclusion($e); - } - $zip->addDirectory( - path::real($info['root']), - $info['id'], - true - ); + private static function getRoot($root) + { + $root = path::real($root); + if (!is_dir($root) || !is_writable($root)) { + throw new Exception('Directory is not writable'); + } - $zip->write(); - $zip->close(); - unset($zip); - } + return $root; + } - 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) - { - $root = path::real($root); - if (!is_dir($root) || !is_writable($root)) { - throw new Exception('Directory is not writable'); - } + return $info; + } - return $root; - } + private static function getExclude($exclude) + { + $exclude = array_merge(self::$exclude, $exclude); - private static function getInfo($info) - { - if (!isset($info['root']) - || !isset($info['id']) - || !is_dir($info['root'])) - { - throw new Exception('Failed to get module info'); - } + return self::quote_exclude($exclude); + } - return $info; - } + private static function getFile($file, $info) + { + if (empty($file) || empty($info)) { + return null; + } - private static function getExclude($exclude) - { - $exclude = array_merge(self::$exclude, $exclude); + $file = str_replace( + [ + '%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) - { - if (empty($file) || empty($info)) { + return $path; + } - 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( - 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; - } -} + return $c; + } +} \ No newline at end of file diff --git a/inc/lib.packman.filezip.php b/inc/lib.packman.filezip.php index c985064..0765489 100644 --- a/inc/lib.packman.filezip.php +++ b/inc/lib.packman.filezip.php @@ -14,111 +14,106 @@ class packmanFileZip extends fileZip { - protected function writeFile($name,$file,$size,$mtime) - { - if (!isset($this->entries[$name])) { - return; - } - - $size = filesize($file); - $this->memoryAllocate($size*3); - - $content = file_get_contents($file); - - //cleanup file contents - // at this time only php files - if (substr($file,-4) == '.php') { - $content = self::removePHPComment($content); - } - - $unc_len = strlen($content); - $crc = crc32($content); - $zdata = gzdeflate($content); - $c_len = strlen($zdata); - - unset($content); - - $mdate = $this->makeDate($mtime); - $mtime = $this->makeTime($mtime); - - # Data descriptor - $data_desc = - "\x50\x4b\x03\x04". - "\x14\x00". # ver needed to extract - "\x00\x00". # gen purpose bit flag - "\x08\x00". # compression method - pack('v',$mtime). # last mod time - pack('v',$mdate). # last mod date - pack('V',$crc). # crc32 - pack('V',$c_len). # compressed filesize - pack('V',$unc_len). # uncompressed filesize - pack('v',strlen($name)). # length of filename - pack('v',0). # extra field length - $name. # end of "local file header" segment - $zdata. # "file data" segment - pack('V',$crc). # crc32 - pack('V',$c_len). # compressed filesize - pack('V',$unc_len); # uncompressed filesize - - fwrite($this->fp,$data_desc); - unset($zdata); - - $new_offset = $this->old_offset + strlen($data_desc); - - # Add to central directory record - $cdrec = - "\x50\x4b\x01\x02". - "\x00\x00". # version made by - "\x14\x00". # version needed to extract - "\x00\x00". # gen purpose bit flag - "\x08\x00". # compression method - pack('v',$mtime). # last mod time - pack('v',$mdate). # last mod date - pack('V',$crc). # crc32 - pack('V',$c_len). # compressed filesize - pack('V',$unc_len). # uncompressed filesize - pack('v',strlen($name)). # length of filename - pack('v',0). # extra field length - pack('v',0). # file comment length - pack('v',0). # disk number start - pack('v',0). # internal file attributes - pack('V',32). # external file attributes - 'archive' bit set - pack('V',$this->old_offset). # relative offset of local header - $name; - - $this->old_offset = $new_offset; - $this->ctrl_dir[] = $cdrec; - } - - protected static function removePHPComment($content) - { - $comment = array(T_COMMENT); - if (defined('T_DOC_COMMENT')) { - $comment[] = T_DOC_COMMENT; // PHP 5 - } - if (defined('T_ML_COMMENT')) { - $comment[] = T_ML_COMMENT; // PHP 4 - } - - $newStr = ''; - $tokens = token_get_all($content); - - foreach ($tokens as $token) - { - if (is_array($token)) - { - if (in_array($token[0],$comment)) { - //$newStr .= "\n"; - } - else { - $newStr .= $token[1]; - } - } - else { - $newStr .= $token; - } - } - return $newStr; - } -} -?> \ No newline at end of file + protected function writeFile($name, $file, $size, $mtime) + { + if (!isset($this->entries[$name])) { + return; + } + + $size = filesize($file); + $this->memoryAllocate($size * 3); + + $content = file_get_contents($file); + + //cleanup file contents + // at this time only php files + if (substr($file,-4) == '.php') { + $content = self::removePHPComment($content); + } + + $unc_len = strlen($content); + $crc = crc32($content); + $zdata = gzdeflate($content); + $c_len = strlen($zdata); + + unset($content); + + $mdate = $this->makeDate($mtime); + $mtime = $this->makeTime($mtime); + + # Data descriptor + $data_desc = + "\x50\x4b\x03\x04" . + "\x14\x00" . # ver needed to extract + "\x00\x00" . # gen purpose bit flag + "\x08\x00" . # compression method + pack('v', $mtime) . # last mod time + pack('v', $mdate) . # last mod date + pack('V', $crc) . # crc32 + pack('V', $c_len) . # compressed filesize + pack('V', $unc_len) . # uncompressed filesize + pack('v', strlen($name)) . # length of filename + pack('v' ,0) . # extra field length + $name . # end of "local file header" segment + $zdata . # "file data" segment + pack('V', $crc) . # crc32 + pack('V', $c_len) . # compressed filesize + pack('V', $unc_len); # uncompressed filesize + + fwrite($this->fp, $data_desc); + unset($zdata); + + $new_offset = $this->old_offset + strlen($data_desc); + + # Add to central directory record + $cdrec = + "\x50\x4b\x01\x02" . + "\x00\x00" . # version made by + "\x14\x00" . # version needed to extract + "\x00\x00" . # gen purpose bit flag + "\x08\x00" . # compression method + pack('v', $mtime) . # last mod time + pack('v', $mdate) . # last mod date + pack('V', $crc) . # crc32 + pack('V', $c_len) . # compressed filesize + pack('V', $unc_len) . # uncompressed filesize + pack('v', strlen($name)) . # length of filename + pack('v', 0) . # extra field length + pack('v', 0) . # file comment length + pack('v', 0) . # disk number start + pack('v', 0) . # internal file attributes + pack('V', 32) . # external file attributes - 'archive' bit set + pack('V', $this->old_offset). # relative offset of local header + $name; + + $this->old_offset = $new_offset; + $this->ctrl_dir[] = $cdrec; + } + + protected static function removePHPComment($content) + { + $comment = [T_COMMENT]; + if (defined('T_DOC_COMMENT')) { + $comment[] = T_DOC_COMMENT; // PHP 5 + } + if (defined('T_ML_COMMENT')) { + $comment[] = T_ML_COMMENT; // PHP 4 + } + + $newStr = ''; + $tokens = token_get_all($content); + + foreach ($tokens as $token) { + if (is_array($token)) { + if (in_array($token[0], $comment)) { + //$newStr .= "\n"; + } else { + $newStr .= $token[1]; + } + } else { + $newStr .= $token; + } + } + return $newStr; + } +} \ No newline at end of file diff --git a/inc/lib.packman.php b/inc/lib.packman.php index 9c83686..292b095 100644 --- a/inc/lib.packman.php +++ b/inc/lib.packman.php @@ -13,223 +13,222 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_CONTEXT_ADMIN')) { - - return null; + return null; } class libPackman { - public static function is_configured($core, $repo, $file_a, $file_b) - { - if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) { - $core->error->add( - __('Cache directory is not writable.') - ); - } - if (!is_writable($repo)) { - $core->error->add( - __('Path to repository is not writable.') - ); - } + public static function is_configured($core, $repo, $file_a, $file_b) + { + if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) { + $core->error->add( + __('Cache directory is not writable.') + ); + } + if (!is_writable($repo)) { + $core->error->add( + __('Path to repository is not writable.') + ); + } - if (empty($file_a)) { - $core->error->add( - __('You must specify the name of package to export.') - ); - } + if (empty($file_a)) { + $core->error->add( + __('You must specify the name of package to export.') + ); + } - if (!is_writable(dirname($repo.'/'.$file_a))) { - $core->error->add( - __('Path to first export package is not writable.') - ); - } + if (!is_writable(dirname($repo . '/' . $file_a))) { + $core->error->add( + __('Path to first export package is not writable.') + ); + } - if (!empty($file_b) - && !is_writable(dirname($repo.'/'.$file_b))) { - $core->error->add( - __('Path to second export package is not writable.') - ); - } + if (!empty($file_b) + && !is_writable(dirname($repo . '/' . $file_b))) { + $core->error->add( + __('Path to second export package is not writable.') + ); + } - return !$core->error->flag(); - } + return !$core->error->flag(); + } - public static function is_writable($path, $file) - { - return !( - empty($path) || - empty($file) || - !is_writable(dirname($path.'/'.$file)) - ); - } + public static function is_writable($path, $file) + { + return !( + empty($path) || + empty($file) || + !is_writable(dirname($path . '/' . $file)) + ); + } - public static function modules($core, $modules, $type, $title) - { - $type = $type == 'themes' ? 'themes' : 'plugins'; + public static function modules($core, $modules, $type, $title) + { + $type = $type == 'themes' ? 'themes' : 'plugins'; - echo - '
'. - '

'.$title.'

'; + echo + '
' . + '

' . $title . '

'; - if (empty($modules) && !is_array($modules)) { - echo - '

'.__('There are no modules.').'

'. - '
'; + if (empty($modules) && !is_array($modules)) { + echo + '

' . __('There are no modules.') . '

' . + '
'; - return null; - } + return null; + } - echo - '
'. - ''. - ''. - ''. - ''. - ''. - ''; - - foreach (self::sort($modules) as $id => $module) { - echo - ''. - ''. - ''. - ''. - ''. - ''; - } + echo + '' . + '
'.__('Id').''.__('Version').''.__('Name').''.__('Root').'
'. - html::escapeHTML($module['version']). - ''. - __(html::escapeHTML($module['name'])). - ''. - dirname(path::real($module['root'], false)). - '
' . + '' . + '' . + '' . + '' . + ''; - echo - '
' . __('Id') . '' . __('Version') . '' . __('Name') . '' . __('Root') . '
'. - '

'. - '

'. - (!empty($_REQUEST['redir']) ? - form::hidden( - array('redir'), - html::escapeHTML($_REQUEST['redir']) - ) : '' - ). - form::hidden(array('p'), 'pacKman'). - form::hidden(array('type'), $type). - form::hidden(array('action'), 'packup'). - ''. - $core->formNonce().'

'. - '
'. + foreach (self::sort($modules) as $id => $module) { + echo + '' . + '' . + '' . + html::escapeHTML($module['version']) . + '' . + '' . + __(html::escapeHTML($module['name'])) . + '' . + '' . + dirname(path::real($module['root'], false)) . + '' . + ''; + } - '
'; - } - - public static function repository($core, $modules, $type, $title) - { - if (!in_array($type,array('plugins','themes','repository'))) { + echo + '' . + '

' . + '

' . + (!empty($_REQUEST['redir']) ? + form::hidden( + ['redir'], + html::escapeHTML($_REQUEST['redir']) + ) : '' + ) . + form::hidden(['p'], 'pacKman') . + form::hidden(['type'], $type) . + form::hidden(['action'], 'packup') . + '' . + $core->formNonce() . '

' . + '' . - return null; - } + '
'; + } + + public static function repository($core, $modules, $type, $title) + { + if (!in_array($type, ['plugins', 'themes', 'repository'])) { + return null; + } - echo - '
'. - '

'.$title.'

'; + echo + '
' . + '

' . $title . '

'; - if (empty($modules) || !is_array($modules)) { - echo - '

'.__('There are no packages').'

'. - '
'; + if (empty($modules) || !is_array($modules)) { + echo + '

' . __('There are no packages') . '

' . + '
'; - return null; - } + return null; + } - $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'; - } + $combo_action = [__('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'; + } - echo - '
'. - ''. - ''. - ''. - ''. - ''. - ''; + echo + '' . + '
'.__('Id').''.__('Version').''.__('Name').''.__('File').'
' . + '' . + '' . + '' . + '' . + ''; - $dup = array(); - foreach(self::sort($modules) AS $module) { + $dup = []; + foreach(self::sort($modules) AS $module) { - if (isset($dup[$module['root']])) { - continue; - } + if (isset($dup[$module['root']])) { + continue; + } - $dup[$module['root']] = 1; + $dup[$module['root']] = 1; - echo - ''. - ''. - ''. - ''. - ''. - ''; - } + echo + '' . + '' . + '' . + '' . + '' . + ''; + } - echo - '
' . __('Id') . '' . __('Version') . '' . __('Name') . '' . __('File') . '
'. - html::escapeHTML($module['version']). - ''. - __(html::escapeHTML($module['name'])). - ''. - ''. - html::escapeHTML(basename($module['root'])).''. - '
' . + html::escapeHTML($module['version']) . + '' . + __(html::escapeHTML($module['name'])) . + '' . + '' . + html::escapeHTML(basename($module['root'])) . '' . + '
'. - '
'. - '

'. - '

'.__('Selected modules action:').' '. - form::combo(array('action'), $combo_action). - ''. - form::hidden(array('p'), 'pacKman'). - form::hidden(array('tab'), 'repository'). - form::hidden(array('type'), $type). - $core->formNonce(). - '

'. - '
'. - '
'. - '
'; - } + echo + '' . + '
' . + '

' . + '

' . __('Selected modules action:') . ' ' . + form::combo(['action'], $combo_action) . + '' . + form::hidden(['p'], 'pacKman') . + form::hidden(['tab'], 'repository') . + form::hidden(['type'], $type) . + $core->formNonce() . + '

' . + '
' . + '' . + '
'; + } - protected static function sort($modules) - { - $sorter = array(); - foreach($modules as $id => $module) { - $sorter[$id] = $id; - } - array_multisort($sorter, SORT_ASC, $modules); + protected static function sort($modules) + { + $sorter = []; + foreach($modules as $id => $module) { + $sorter[$id] = $id; + } + array_multisort($sorter, SORT_ASC, $modules); - return $modules; - } -} + return $modules; + } +} \ No newline at end of file diff --git a/index.php b/index.php index a7fa45f..abaf256 100644 --- a/index.php +++ b/index.php @@ -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 '' . -dcPage::breadcrumb( - array( +dcPage::breadcrumb([ __('Plugins') => '', __('pacKman') => '' - ) -). +]). dcPage::notices(); if ($core->error->flag()) { @@ -284,9 +267,8 @@ if ($core->error->flag()) { '' . __('Configuration') . '' . '

'; -} -else { +} else { $repo_path_modules = array_merge( dcPackman::getPackages( $core, diff --git a/locales/fr/help/help.html b/locales/fr/help/help.html index 975ca2a..5265a86 100644 --- a/locales/fr/help/help.html +++ b/locales/fr/help/help.html @@ -55,9 +55,8 @@

Si vous souhaitez plus d'aide ou apporter votre contribution à cette extension, voici quelques liens utiles.

diff --git a/locales/fr/resources.php b/locales/fr/resources.php index 74b5f58..c2bad28 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -13,10 +13,9 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + 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'; +} \ No newline at end of file