From ee7f0a459e52250f7429a260b7b16444d18c5f5d Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 7 Jan 2023 00:56:30 +0100 Subject: [PATCH] use abstract plugin id instead of packman\Core::id() --- inc/Admin.php | 14 +++++++------- inc/Config.php | 6 +++--- inc/Core.php | 5 ----- inc/Install.php | 8 ++++---- inc/Manage.php | 20 ++++++++++---------- inc/Uninstall.php | 18 +++++++++--------- 6 files changed, 33 insertions(+), 38 deletions(-) diff --git a/inc/Admin.php b/inc/Admin.php index b7b1164..7080e0b 100644 --- a/inc/Admin.php +++ b/inc/Admin.php @@ -40,20 +40,20 @@ class Admin } dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { - $favs->register(Core::id(), [ + $favs->register(basename(__NAMESPACE__), [ 'title' => __('Packages repository'), - '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')], + 'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-repository'), + 'small-icon' => [dcPage::getPF(basename(__NAMESPACE__) . '/icon.svg'), dcPage::getPF(basename(__NAMESPACE__) . '/icon-dark.svg')], + 'large-icon' => [dcPage::getPF(basename(__NAMESPACE__) . '/icon.svg'), dcPage::getPF(basename(__NAMESPACE__) . '/icon-dark.svg')], //'permissions' => dcCore::app()->auth->isSuperAdmin(), ]); }); dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Packages repository'), - 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()->adminurl->get('admin.plugin.' . basename(__NAMESPACE__)) . '#packman-repository-repository', + [dcPage::getPF(basename(__NAMESPACE__) . '/icon.svg'), dcPage::getPF(basename(__NAMESPACE__) . '/icon-dark.svg')], + preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__NAMESPACE__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']), dcCore::app()->auth->isSuperAdmin() ); diff --git a/inc/Config.php b/inc/Config.php index 79071ff..c657a0f 100644 --- a/inc/Config.php +++ b/inc/Config.php @@ -65,7 +65,7 @@ class Config ); if ($check) { - $s = dcCore::app()->blog->settings->__get(Core::id()); + $s = dcCore::app()->blog->settings->__get(basename(__NAMESPACE__)); $s->put('pack_nocomment', $pack_nocomment); $s->put('pack_fixnewline', $pack_fixnewline); $s->put('pack_overwrite', $pack_overwrite); @@ -78,7 +78,7 @@ class Config __('Configuration has been successfully updated.') ); http::redirect( - dcCore::app()->admin->__get('list')->getURL('module=' . Core::id() . '&conf=1&redir=' . + dcCore::app()->admin->__get('list')->getURL('module=' . basename(__NAMESPACE__) . '&conf=1&redir=' . dcCore::app()->admin->__get('list')->getRedir()) ); @@ -98,7 +98,7 @@ class Config } # -- Get settings -- - $s = dcCore::app()->blog->settings->__get(Core::id()); + $s = dcCore::app()->blog->settings->__get(basename(__NAMESPACE__)); # -- Display form -- echo ' diff --git a/inc/Core.php b/inc/Core.php index e5215da..82f11c4 100644 --- a/inc/Core.php +++ b/inc/Core.php @@ -30,11 +30,6 @@ use Exception; class Core { - public static function id() - { - return basename(dirname(__DIR__)); - } - /** @var array Excluded files */ public static $exclude = [ '.', diff --git a/inc/Install.php b/inc/Install.php index 9f3446e..ae17af6 100644 --- a/inc/Install.php +++ b/inc/Install.php @@ -74,7 +74,7 @@ class Install public static function init(): bool { - self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(Core::id(), dcCore::app()->plugins->moduleInfo(Core::id(), 'version')); + self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(basename(__NAMESPACE__), dcCore::app()->plugins->moduleInfo(basename(__NAMESPACE__), 'version')); return self::$init; } @@ -91,7 +91,7 @@ class Install // Set module settings foreach (self::$mod_conf as $v) { - dcCore::app()->blog->settings->__get(Core::id())->put( + dcCore::app()->blog->settings->__get(basename(__NAMESPACE__))->put( $v[0], $v[2], $v[3], @@ -111,7 +111,7 @@ class Install public static function growUp(): void { - $current = dcCore::app()->getVersion(Core::id()); + $current = dcCore::app()->getVersion(basename(__NAMESPACE__)); // Update settings id, ns if ($current && version_compare($current, '2022.12.19.1', '<=')) { @@ -124,7 +124,7 @@ class Install if (preg_match('/^packman_(.*?)$/', $record->setting_id, $match)) { $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME); $cur->setting_id = $match[1]; - $cur->setting_ns = Core::id(); + $cur->setting_ns = basename(__NAMESPACE__); $cur->update( "WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'pacKman' " . 'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' ")) diff --git a/inc/Manage.php b/inc/Manage.php index 5b90c42..0859d52 100644 --- a/inc/Manage.php +++ b/inc/Manage.php @@ -60,7 +60,7 @@ class Manage $type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : ''; # Settings - $s = dcCore::app()->blog->settings->get(Core::id()); + $s = dcCore::app()->blog->settings->get(basename(__NAMESPACE__)); $dir = Utils::getRepositoryDir($s->get('pack_repository')); # Modules @@ -127,7 +127,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-' . $type); } # Pack @@ -166,7 +166,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-' . $type); } # Delete @@ -191,7 +191,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); } # Install @@ -218,7 +218,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); } # Copy @@ -244,7 +244,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); } # Move @@ -271,7 +271,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); } } } catch (Exception $e) { @@ -286,7 +286,7 @@ class Manage } # Settings - $s = dcCore::app()->blog->settings->get(Core::id()); + $s = dcCore::app()->blog->settings->get(basename(__NAMESPACE__)); $dir = Utils::getRepositoryDir($s->get('pack_repository')); $is_configured = Utils::is_configured( @@ -299,7 +299,7 @@ class Manage echo '' . __('pacKman') . '' . dcPage::jsPageTabs() . - dcPage::jsLoad(dcPage::getPF(Core::id() . '/js/packman.js')); + dcPage::jsModuleLoad(basename(__NAMESPACE__) . '/js/packman.js'); # --BEHAVIOR-- packmanAdminHeader dcCore::app()->callBehavior('packmanAdminHeader'); @@ -316,7 +316,7 @@ class Manage if (dcCore::app()->error->flag() || !$is_configured) { echo '
' . __('pacKman is not well configured.') . ' ' . - '' . __('Configuration') . '' . + '' . __('Configuration') . '' . '
'; } else { $repo_path_modules = array_merge( diff --git a/inc/Uninstall.php b/inc/Uninstall.php index 86da62e..18a9ab9 100644 --- a/inc/Uninstall.php +++ b/inc/Uninstall.php @@ -37,7 +37,7 @@ class Uninstall /* action */ 'delete_all', /* ns */ - Core::id(), + basename(__NAMESPACE__), /* desc */ __('delete all settings') ); @@ -48,7 +48,7 @@ class Uninstall /* action */ 'delete', /* ns */ - Core::id(), + basename(__NAMESPACE__), /* desc */ __('delete plugin files') ); @@ -59,7 +59,7 @@ class Uninstall /* action */ 'delete', /* ns */ - Core::id(), + basename(__NAMESPACE__), /* desc */ __('delete the version number') ); @@ -70,9 +70,9 @@ class Uninstall /* action */ 'delete_all', /* ns */ - Core::id(), + basename(__NAMESPACE__), /* desc */ - sprintf(__('delete all %s settings'), Core::id()) + sprintf(__('delete all %s settings'), basename(__NAMESPACE__)) ); $uninstaller->addDirectAction( @@ -81,9 +81,9 @@ class Uninstall /* action */ 'delete', /* ns */ - Core::id(), + basename(__NAMESPACE__), /* desc */ - sprintf(__('delete %s plugin files'), Core::id()) + sprintf(__('delete %s plugin files'), basename(__NAMESPACE__)) ); $uninstaller->addDirectAction( @@ -92,9 +92,9 @@ class Uninstall /* action */ 'delete', /* ns */ - Core::id(), + basename(__NAMESPACE__), /* desc */ - sprintf(__('delete %s version number'), Core::id()) + sprintf(__('delete %s version number'), basename(__NAMESPACE__)) ); return true;