diff --git a/_admin.php b/_admin.php new file mode 100644 index 0000000..e811bd4 --- /dev/null +++ b/_admin.php @@ -0,0 +1,17 @@ +blog->settings->addNamespace(basename(__DIR__)); + if (defined('DC_CONTEXT_ADMIN')) { + dcCore::app()->blog->settings->addNamespace(Core::id()); + self::$init = true; + } + + return self::$init; } public static function process() { + if (!self::$init) { + return false; + } + dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { - $favs->register(basename(__DIR__), [ + $favs->register(Core::id(), [ 'title' => __('Packages repository'), - 'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__), [], '#packman-repository-repository'), - 'small-icon' => [dcPage::getPF(basename(__DIR__) . '/icon.svg'), dcPage::getPF(basename(__DIR__) . '/icon-dark.svg')], - 'large-icon' => [dcPage::getPF(basename(__DIR__) . '/icon.svg'), dcPage::getPF(basename(__DIR__) . '/icon-dark.svg')], + 'url' => dcCore::app()->adminurl->get('admin.plugin.' . Core::id(), [], '#packman-repository-repository'), + 'small-icon' => [dcPage::getPF(Core::id() . '/icon.svg'), dcPage::getPF(Core::id() . '/icon-dark.svg')], + 'large-icon' => [dcPage::getPF(Core::id() . '/icon.svg'), dcPage::getPF(Core::id() . '/icon-dark.svg')], //'permissions' => dcCore::app()->auth->isSuperAdmin(), ]); }); dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Packages repository'), - dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)) . '#packman-repository-repository', - [dcPage::getPF(basename(__DIR__) . '/icon.svg'), dcPage::getPF(basename(__DIR__) . '/icon-dark.svg')], - preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + dcCore::app()->adminurl->get('admin.plugin.' . Core::id()) . '#packman-repository-repository', + [dcPage::getPF(Core::id() . '/icon.svg'), dcPage::getPF(Core::id() . '/icon-dark.svg')], + preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . Core::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), dcCore::app()->auth->isSuperAdmin() ); } } - -Admin::init(); -Admin::process(); diff --git a/inc/Config.php b/inc/Config.php index f9225b0..5eda42d 100644 --- a/inc/Config.php +++ b/inc/Config.php @@ -12,11 +12,7 @@ */ declare(strict_types=1); -namespace plugins\pacKman; - -if (!defined('DC_CONTEXT_MODULE')) { - return null; -} +namespace Dotclear\Plugin\pacKman; /* dotclear ns */ use dcCore; @@ -32,13 +28,24 @@ use Exception; class Config { - public static function init(): void + private static $init = false; + + public static function init(): bool { - dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); + if (defined('DC_CONTEXT_ADMIN')) { + dcCore::app()->blog->settings->addNamespace(Core::id()); + self::$init = true; + } + + return self::$init; } public static function process(): void { + if (!self::$init) { + return; + } + if (empty($_POST['save'])) { return; } @@ -60,7 +67,7 @@ class Config ); if ($check) { - $s = dcCore::app()->blog->settings->__get(basename(__DIR__)); + $s = dcCore::app()->blog->settings->__get(Core::id()); $s->put('packman_pack_nocomment', $packman_pack_nocomment); $s->put('packman_pack_fixnewline', $packman_pack_fixnewline); $s->put('packman_pack_overwrite', $packman_pack_overwrite); @@ -73,7 +80,7 @@ class Config __('Configuration has been successfully updated.') ); http::redirect( - dcCore::app()->admin->__get('list')->getURL('module=' . basename(__DIR__) . '&conf=1&redir=' . + dcCore::app()->admin->__get('list')->getURL('module=' . Core::id() . '&conf=1&redir=' . dcCore::app()->admin->__get('list')->getRedir()) ); } @@ -82,18 +89,14 @@ class Config } } - public static function render(): void + public static function render() { - # -- Get settings -- - $s = dcCore::app()->blog->settings->__get(basename(__DIR__)); + if (!self::$init) { + return false; + } - $packman_pack_nocomment = $s->packman_pack_nocomment; - $packman_pack_fixnewline = $s->packman_pack_fixnewline; - $packman_pack_overwrite = $s->packman_pack_overwrite; - $packman_pack_filename = $s->packman_pack_filename; - $packman_secondpack_filename = $s->packman_secondpack_filename; - $packman_pack_repository = $s->packman_pack_repository; - $packman_pack_excludefiles = $s->packman_pack_excludefiles; + # -- Get settings -- + $s = dcCore::app()->blog->settings->__get(Core::id()); # -- Display form -- echo ' @@ -101,7 +104,7 @@ class Config

' . __('Root') . '

' . '

' . sprintf( __('Preconization: %s'), @@ -114,17 +117,17 @@ class Config

' . __('Files') . '

' . sprintf(__('Preconization: %s'), '%type%-%id%') . '

' . sprintf(__('Preconization: %s'), '%type%-%id%-%version%') . '

@@ -133,22 +136,18 @@ class Config

' . __('Content') . '

' . sprintf(__('Preconization: %s'), '*.zip,*.tar,*.tar.gz') . '

'; } } - -Config::init(); -Config::process(); -Config::render(); diff --git a/inc/Core.php b/inc/Core.php index 03c025f..2f0c487 100644 --- a/inc/Core.php +++ b/inc/Core.php @@ -12,11 +12,7 @@ */ declare(strict_types=1); -namespace plugins\pacKman; - -if (!defined('DC_CONTEXT_ADMIN')) { - return null; -} +namespace Dotclear\Plugin\pacKman; /* dotclear ns */ use dcModules; @@ -34,6 +30,11 @@ use Exception; class Core { + public static function id() + { + return basename(dirname(__DIR__)); + } + /** @var array Excluded files */ public static $exclude = [ '.', @@ -147,12 +148,12 @@ class Core $fp = fopen($dest, 'wb'); if ($nocomment) { - FileZip::$remove_comment = true; + Filezip::$remove_comment = true; } if ($fixnewline) { - FileZip::$fix_newline = true; + Filezip::$fix_newline = true; } - $zip = new FileZip($fp); + $zip = new Filezip($fp); foreach ($exclude as $e) { $zip->addExclusion($e); diff --git a/inc/Filezip.php b/inc/Filezip.php index c557e14..71242f0 100644 --- a/inc/Filezip.php +++ b/inc/Filezip.php @@ -12,16 +12,12 @@ */ declare(strict_types=1); -namespace plugins\pacKman; - -if (!defined('DC_CONTEXT_ADMIN')) { - return null; -} +namespace Dotclear\Plugin\pacKman; /* clearbricks ns */ //use fileZip; -class FileZip extends \fileZip +class Filezip extends \fileZip { /** @var boolean Remove comments from files content */ public static $remove_comment = false; diff --git a/inc/Install.php b/inc/Install.php index 7489e24..e1f9c7a 100644 --- a/inc/Install.php +++ b/inc/Install.php @@ -12,11 +12,7 @@ */ declare(strict_types=1); -namespace plugins\pacKman; - -if (!defined('DC_CONTEXT_ADMIN')) { - return null; -} +namespace Dotclear\Plugin\pacKman; /* dotclear ns */ use dcCore; @@ -73,21 +69,26 @@ class Install ]; # -- Nothing to change below -- + private static $init = false; + + public static function init(): bool + { + self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(Core::id(), dcCore::app()->plugins->moduleInfo(Core::id(), 'version')); + + return self::$init; + } + public static function process() { - try { - # Check module version - if (!dcCore::app()->newVersion( - basename(__DIR__), - dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') - )) { - return null; - } + if (!self::$init) { + return false; + } + try { # Set module settings - dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); + dcCore::app()->blog->settings->addNamespace(Core::id()); foreach (self::$mod_conf as $v) { - dcCore::app()->blog->settings->__get(basename(__DIR__))->put( + dcCore::app()->blog->settings->__get(Core::id())->put( $v[0], $v[2], $v[3], @@ -105,5 +106,3 @@ class Install } } } - -return Install::process(); diff --git a/inc/Manage.php b/inc/Manage.php index 062b0f7..0c3423a 100644 --- a/inc/Manage.php +++ b/inc/Manage.php @@ -12,11 +12,7 @@ */ declare(strict_types=1); -namespace plugins\pacKman; - -if (!defined('DC_CONTEXT_ADMIN')) { - return null; -} +namespace Dotclear\Plugin\pacKman; /* dotclear ns */ use dcCore; @@ -31,31 +27,41 @@ use path; /* php ns */ use Exception; -class Index +class Manage { private static $plugins_path = ''; private static $themes_path = ''; + private static $init = false; - public static function init() + public static function init(): bool { - dcPage::checkSuper(); - dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); + if (defined('DC_CONTEXT_ADMIN')) { + dcPage::checkSuper(); + dcCore::app()->blog->settings->addNamespace(Core::id()); - # Paths - $e = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT); - $p = array_pop($e); - self::$plugins_path = (string) path::real($p); - self::$themes_path = dcCore::app()->blog->themes_path; + # Paths + $e = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT); + $p = array_pop($e); + self::$plugins_path = (string) path::real($p); + self::$themes_path = dcCore::app()->blog->themes_path; + self::$init = true; + } + + return self::$init; } - public static function process() + public static function process(): void { + if (!self::$init) { + return; + } + # Queries $action = $_POST['action'] ?? ''; $type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : ''; # Settings - $s = dcCore::app()->blog->settings->__get(basename(__DIR__)); + $s = dcCore::app()->blog->settings->get(Core::id()); # Modules if (!(dcCore::app()->themes instanceof dcThemes)) { @@ -67,8 +73,8 @@ class Index # Rights $is_writable = Utils::is_writable( - $s->packman_pack_repository, - $s->packman_pack_filename + $s->get('packman_pack_repository'), + $s->get('packman_pack_filename') ); $is_editable = !empty($type) && !empty($_POST['modules']) @@ -85,8 +91,8 @@ class Index $modules = Core::getPackages(self::$themes_path); } else { $modules = array_merge( - Core::getPackages(dirname($s->packman_pack_repository . '/' . $s->packman_pack_filename)), - Core::getPackages(dirname($s->packman_pack_repository . '/' . $s->packman_secondpack_filename)) + Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_pack_filename'))), + Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_secondpack_filename'))) ); } @@ -127,15 +133,15 @@ class Index $module['id'] = $id; $module['type'] = $type == 'themes' ? 'theme' : 'plugin'; - $root = (string) $s->packman_pack_repository; + $root = (string) $s->get('packman_pack_repository'); $files = [ - (string) $s->packman_pack_filename, - (string) $s->packman_secondpack_filename, + (string) $s->get('packman_pack_filename'), + (string) $s->get('packman_secondpack_filename'), ]; - $nocomment = (bool) $s->packman_pack_nocomment; - $fixnewline = (bool) $s->packman_pack_fixnewline; - $overwrite = (bool) $s->packman_pack_overwrite; - $exclude = explode(',', (string) $s->packman_pack_excludefiles); + $nocomment = (bool) $s->get('packman_pack_nocomment'); + $fixnewline = (bool) $s->get('packman_pack_fixnewline'); + $overwrite = (bool) $s->get('packman_pack_overwrite'); + $exclude = explode(',', (string) $s->get('packman_pack_excludefiles')); # --BEHAVIOR-- packmanBeforeCreatePackage dcCore::app()->callBehavior('packmanBeforeCreatePackage', $module); @@ -153,7 +159,7 @@ class Index if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), [], '#packman-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-' . $type); } # Delete @@ -173,7 +179,7 @@ class Index if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type); } # Install @@ -200,12 +206,12 @@ class Index if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type); } # Copy } elseif (strpos($action, 'copy_to_') !== false) { - $dest = $s->packman_pack_repository; + $dest = (string) $s->get('packman_pack_repository'); if ($action == 'copy_to_plugins') { $dest = self::$plugins_path; } elseif ($action == 'copy_to_themes') { @@ -226,12 +232,12 @@ class Index if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type); } # Move } elseif (strpos($action, 'move_to_') !== false) { - $dest = $s->packman_pack_repository; + $dest = (string) $s->get('packman_pack_repository'); if ($action == 'move_to_plugins') { $dest = self::$plugins_path; } elseif ($action == 'move_to_themes') { @@ -253,7 +259,7 @@ class Index if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type); } } } catch (Exception $e) { @@ -263,20 +269,24 @@ class Index public static function render() { + if (!self::$init) { + return false; + } + # Settings - $s = dcCore::app()->blog->settings->__get(basename(__DIR__)); + $s = dcCore::app()->blog->settings->get(Core::id()); $is_configured = Utils::is_configured( - $s->packman_pack_repository, - $s->packman_pack_filename, - $s->packman_secondpack_filename + $s->get('packman_pack_repository'), + $s->get('packman_pack_filename'), + $s->get('packman_secondpack_filename') ); # Display echo '' . __('pacKman') . '' . dcPage::jsPageTabs() . - dcPage::jsLoad(dcPage::getPF(basename(__DIR__) . '/js/packman.js')); + dcPage::jsLoad(dcPage::getPF(Core::id() . '/js/packman.js')); # --BEHAVIOR-- packmanAdminHeader dcCore::app()->callBehavior('packmanAdminHeader'); @@ -293,12 +303,12 @@ class Index if (dcCore::app()->error->flag() || !$is_configured) { echo '
' . __('pacKman is not well configured.') . ' ' . - '' . __('Configuration') . '' . + '' . __('Configuration') . '' . '
'; } else { $repo_path_modules = array_merge( - Core::getPackages(dirname($s->packman_pack_repository . '/' . $s->packman_pack_filename)), - Core::getPackages(dirname($s->packman_pack_repository . '/' . $s->packman_secondpack_filename)) + Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_pack_filename'))), + Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_secondpack_filename'))) ); $plugins_path_modules = Core::getPackages(self::$plugins_path); $themes_path_modules = Core::getPackages(self::$themes_path); @@ -343,7 +353,3 @@ class Index ''; } } - -Index::init(); -Index::process(); -Index::render(); diff --git a/inc/Prepend.php b/inc/Prepend.php index 6e14812..60470d4 100644 --- a/inc/Prepend.php +++ b/inc/Prepend.php @@ -12,25 +12,43 @@ */ declare(strict_types=1); -namespace plugins\pacKman; - -if (!defined('DC_RC_PATH')) { - return null; -} +namespace Dotclear\Plugin\pacKman; /* clearbricks ns */ use Clearbricks; class Prepend { - public static function init() + private const LIBS = [ + 'Admin', + 'Config', + 'Core', + 'Filezip', + 'Install', + 'Manage', + 'Prepend', + 'Uninstall', + 'Utils', + ]; + private static $init = false; + + public static function init(): bool { - Clearbricks::lib()->autoload([ - 'plugins\\pacKman\\Core' => __DIR__ . '/inc/class.core.php', - 'plugins\\pacKman\\Utils' => __DIR__ . '/inc/class.utils.php', - 'plugins\\pacKman\\FileZip' => __DIR__ . '/inc/class.filezip.php', - ]); + self::$init = defined('DC_RC_PATH'); + + return self::$init; + } + + public static function process() + { + if (!self::$init) { + return false; + } + + foreach (self::LIBS as $lib) { + Clearbricks::lib()->autoload(['Dotclear\\Plugin\\pacKman\\' . $lib => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php']); + } + + return true; } } - -Prepend::init(); diff --git a/inc/Uninstall.php b/inc/Uninstall.php index 63e5123..df942e6 100644 --- a/inc/Uninstall.php +++ b/inc/Uninstall.php @@ -10,72 +10,91 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_CONTEXT_ADMIN')) { - return null; +declare(strict_types=1); + +namespace Dotclear\Plugin\pacKman; + +class Uninstall +{ + private static $init = false; + + public static function init(): bool + { + self::$init = defined('DC_RC_PATH'); + + return self::$init; + } + + public static function process($uninstaller) + { + if (!self::$init) { + return false; + } + + $uninstaller->addUserAction( + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + Core::id(), + /* desc */ + __('delete all settings') + ); + + $uninstaller->addUserAction( + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + Core::id(), + /* desc */ + __('delete plugin files') + ); + + $uninstaller->addUserAction( + /* type */ + 'versions', + /* action */ + 'delete', + /* ns */ + Core::id(), + /* desc */ + __('delete the version number') + ); + + $uninstaller->addDirectAction( + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + Core::id(), + /* desc */ + sprintf(__('delete all %s settings'), Core::id()) + ); + + $uninstaller->addDirectAction( + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + Core::id(), + /* desc */ + sprintf(__('delete %s plugin files'), Core::id()) + ); + + $uninstaller->addDirectAction( + /* type */ + 'versions', + /* action */ + 'delete', + /* ns */ + Core::id(), + /* desc */ + sprintf(__('delete %s version number'), Core::id()) + ); + } } - -$this->addUserAction( - /* type */ - 'settings', - /* action */ - 'delete_all', - /* ns */ - basename(__DIR__), - /* desc */ - __('delete all settings') -); - -$this->addUserAction( - /* type */ - 'plugins', - /* action */ - 'delete', - /* ns */ - basename(__DIR__), - /* desc */ - __('delete plugin files') -); - -$this->addUserAction( - /* type */ - 'versions', - /* action */ - 'delete', - /* ns */ - basename(__DIR__), - /* desc */ - __('delete the version number') -); - -$this->addDirectAction( - /* type */ - 'settings', - /* action */ - 'delete_all', - /* ns */ - basename(__DIR__), - /* desc */ - sprintf(__('delete all %s settings'), basename(__DIR__)) -); - -$this->addDirectAction( - /* type */ - 'plugins', - /* action */ - 'delete', - /* ns */ - basename(__DIR__), - /* desc */ - sprintf(__('delete %s plugin files'), basename(__DIR__)) -); - -$this->addDirectAction( - /* type */ - 'versions', - /* action */ - 'delete', - /* ns */ - basename(__DIR__), - /* desc */ - sprintf(__('delete %s version number'), basename(__DIR__)) -); diff --git a/inc/Utils.php b/inc/Utils.php index 965aa5b..f808b1d 100644 --- a/inc/Utils.php +++ b/inc/Utils.php @@ -12,11 +12,7 @@ */ declare(strict_types=1); -namespace plugins\pacKman; - -if (!defined('DC_CONTEXT_ADMIN')) { - return null; -} +namespace Dotclear\Plugin\pacKman; /* dotclear ns */ use dcCore; diff --git a/index.php b/index.php new file mode 100644 index 0000000..38593a4 --- /dev/null +++ b/index.php @@ -0,0 +1,18 @@ +