diff --git a/inc/Admin.php b/inc/Admin.php index 7080e0b..ff217f2 100644 --- a/inc/Admin.php +++ b/inc/Admin.php @@ -22,11 +22,13 @@ use dcPage; class Admin { + private static $pid = ''; protected static $init = false; public static function init(): bool { if (defined('DC_CONTEXT_ADMIN')) { + self::$pid = basename(dirname(__DIR__)); self::$init = true; } @@ -40,20 +42,20 @@ class Admin } dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { - $favs->register(basename(__NAMESPACE__), [ + $favs->register(self::$pid, [ 'title' => __('Packages repository'), - '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')], + 'url' => dcCore::app()->adminurl->get('admin.plugin.' . self::$pid, [], '#packman-repository-repository'), + 'small-icon' => [dcPage::getPF(self::$pid . '/icon.svg'), dcPage::getPF(self::$pid . '/icon-dark.svg')], + 'large-icon' => [dcPage::getPF(self::$pid . '/icon.svg'), dcPage::getPF(self::$pid . '/icon-dark.svg')], //'permissions' => dcCore::app()->auth->isSuperAdmin(), ]); }); dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Packages repository'), - 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()->adminurl->get('admin.plugin.' . self::$pid) . '#packman-repository-repository', + [dcPage::getPF(self::$pid . '/icon.svg'), dcPage::getPF(self::$pid . '/icon-dark.svg')], + preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . self::$pid)) . '(&.*)?$/', $_SERVER['REQUEST_URI']), dcCore::app()->auth->isSuperAdmin() ); diff --git a/inc/Config.php b/inc/Config.php index c657a0f..56096ae 100644 --- a/inc/Config.php +++ b/inc/Config.php @@ -27,11 +27,13 @@ use Exception; class Config { + private static $pid = ''; protected static $init = false; public static function init(): bool { if (defined('DC_CONTEXT_ADMIN') && defined('DC_CONTEXT_MODULE')) { + self::$pid = basename(dirname(__DIR__)); self::$init = true; } @@ -65,7 +67,7 @@ class Config ); if ($check) { - $s = dcCore::app()->blog->settings->__get(basename(__NAMESPACE__)); + $s = dcCore::app()->blog->settings->__get(self::$pid); $s->put('pack_nocomment', $pack_nocomment); $s->put('pack_fixnewline', $pack_fixnewline); $s->put('pack_overwrite', $pack_overwrite); @@ -78,7 +80,7 @@ class Config __('Configuration has been successfully updated.') ); http::redirect( - dcCore::app()->admin->__get('list')->getURL('module=' . basename(__NAMESPACE__) . '&conf=1&redir=' . + dcCore::app()->admin->__get('list')->getURL('module=' . self::$pid . '&conf=1&redir=' . dcCore::app()->admin->__get('list')->getRedir()) ); @@ -98,7 +100,7 @@ class Config } # -- Get settings -- - $s = dcCore::app()->blog->settings->__get(basename(__NAMESPACE__)); + $s = dcCore::app()->blog->settings->__get(self::$pid); # -- Display form -- echo ' diff --git a/inc/Install.php b/inc/Install.php index ae17af6..1919a55 100644 --- a/inc/Install.php +++ b/inc/Install.php @@ -70,11 +70,13 @@ class Install ]; // Nothing to change below + private static $pid = ''; protected static $init = false; public static function init(): bool { - self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(basename(__NAMESPACE__), dcCore::app()->plugins->moduleInfo(basename(__NAMESPACE__), 'version')); + self::$pid = basename(dirname(__DIR__)); + self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(self::$pid, dcCore::app()->plugins->moduleInfo(self::$pid, 'version')); return self::$init; } @@ -91,7 +93,7 @@ class Install // Set module settings foreach (self::$mod_conf as $v) { - dcCore::app()->blog->settings->__get(basename(__NAMESPACE__))->put( + dcCore::app()->blog->settings->__get(self::$pid)->put( $v[0], $v[2], $v[3], @@ -111,7 +113,7 @@ class Install public static function growUp(): void { - $current = dcCore::app()->getVersion(basename(__NAMESPACE__)); + $current = dcCore::app()->getVersion(self::$pid); // Update settings id, ns if ($current && version_compare($current, '2022.12.19.1', '<=')) { @@ -124,7 +126,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 = basename(__NAMESPACE__); + $cur->setting_ns = self::$pid; $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 0859d52..368e5f3 100644 --- a/inc/Manage.php +++ b/inc/Manage.php @@ -31,6 +31,7 @@ class Manage { private static $plugins_path = ''; private static $themes_path = ''; + private static $pid = ''; protected static $init = false; public static function init(): bool @@ -43,6 +44,7 @@ class Manage $p = array_pop($e); self::$plugins_path = (string) path::real($p); self::$themes_path = dcCore::app()->blog->themes_path; + self::$pid = basename(dirname(__DIR__)); self::$init = true; } @@ -60,7 +62,7 @@ class Manage $type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : ''; # Settings - $s = dcCore::app()->blog->settings->get(basename(__NAMESPACE__)); + $s = dcCore::app()->blog->settings->get(self::$pid); $dir = Utils::getRepositoryDir($s->get('pack_repository')); # Modules @@ -127,7 +129,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-' . $type); } # Pack @@ -166,7 +168,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-' . $type); } # Delete @@ -191,7 +193,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-repository-' . $type); } # Install @@ -218,7 +220,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-repository-' . $type); } # Copy @@ -244,7 +246,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-repository-' . $type); } # Move @@ -271,7 +273,7 @@ class Manage if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); + dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-repository-' . $type); } } } catch (Exception $e) { @@ -286,7 +288,7 @@ class Manage } # Settings - $s = dcCore::app()->blog->settings->get(basename(__NAMESPACE__)); + $s = dcCore::app()->blog->settings->get(self::$pid); $dir = Utils::getRepositoryDir($s->get('pack_repository')); $is_configured = Utils::is_configured( @@ -299,7 +301,7 @@ class Manage echo '' . __('pacKman') . '' . dcPage::jsPageTabs() . - dcPage::jsModuleLoad(basename(__NAMESPACE__) . '/js/packman.js'); + dcPage::jsModuleLoad(self::$pid . '/js/packman.js'); # --BEHAVIOR-- packmanAdminHeader dcCore::app()->callBehavior('packmanAdminHeader'); @@ -316,7 +318,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/Prepend.php b/inc/Prepend.php index 5d5e8fb..6abe79b 100644 --- a/inc/Prepend.php +++ b/inc/Prepend.php @@ -47,7 +47,7 @@ class Prepend foreach (self::LIBS as $lib) { Clearbricks::lib()->autoload([ - implode('\\', ['Dotclear','Plugin', basename(__NAMESPACE__), $lib]) => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php', + __NAMESPACE__ . '\\' . $lib => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php', ]); } diff --git a/inc/Uninstall.php b/inc/Uninstall.php index 18a9ab9..3fbab35 100644 --- a/inc/Uninstall.php +++ b/inc/Uninstall.php @@ -16,10 +16,12 @@ namespace Dotclear\Plugin\pacKman; class Uninstall { + private static $pid = ''; protected static $init = false; public static function init(): bool { + self::$pid = basename(dirname(__DIR__)); self::$init = defined('DC_RC_PATH'); return self::$init; @@ -37,7 +39,7 @@ class Uninstall /* action */ 'delete_all', /* ns */ - basename(__NAMESPACE__), + self::$pid, /* desc */ __('delete all settings') ); @@ -48,7 +50,7 @@ class Uninstall /* action */ 'delete', /* ns */ - basename(__NAMESPACE__), + self::$pid, /* desc */ __('delete plugin files') ); @@ -59,7 +61,7 @@ class Uninstall /* action */ 'delete', /* ns */ - basename(__NAMESPACE__), + self::$pid, /* desc */ __('delete the version number') ); @@ -70,9 +72,9 @@ class Uninstall /* action */ 'delete_all', /* ns */ - basename(__NAMESPACE__), + self::$pid, /* desc */ - sprintf(__('delete all %s settings'), basename(__NAMESPACE__)) + sprintf(__('delete all %s settings'), self::$pid) ); $uninstaller->addDirectAction( @@ -81,9 +83,9 @@ class Uninstall /* action */ 'delete', /* ns */ - basename(__NAMESPACE__), + self::$pid, /* desc */ - sprintf(__('delete %s plugin files'), basename(__NAMESPACE__)) + sprintf(__('delete %s plugin files'), self::$pid) ); $uninstaller->addDirectAction( @@ -92,9 +94,9 @@ class Uninstall /* action */ 'delete', /* ns */ - basename(__NAMESPACE__), + self::$pid, /* desc */ - sprintf(__('delete %s version number'), basename(__NAMESPACE__)) + sprintf(__('delete %s version number'), self::$pid) ); return true;