fix abstract plugin id on unix system, fix #9

2.28
Jean-Christian Paul Denis 2023-01-07 15:41:21 +01:00
parent ee7f0a459e
commit 7a884d6721
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
6 changed files with 44 additions and 34 deletions

View File

@ -22,11 +22,13 @@ use dcPage;
class Admin class Admin
{ {
private static $pid = '';
protected static $init = false; protected static $init = false;
public static function init(): bool public static function init(): bool
{ {
if (defined('DC_CONTEXT_ADMIN')) { if (defined('DC_CONTEXT_ADMIN')) {
self::$pid = basename(dirname(__DIR__));
self::$init = true; self::$init = true;
} }
@ -40,20 +42,20 @@ class Admin
} }
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
$favs->register(basename(__NAMESPACE__), [ $favs->register(self::$pid, [
'title' => __('Packages repository'), 'title' => __('Packages repository'),
'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-repository'), 'url' => dcCore::app()->adminurl->get('admin.plugin.' . self::$pid, [], '#packman-repository-repository'),
'small-icon' => [dcPage::getPF(basename(__NAMESPACE__) . '/icon.svg'), dcPage::getPF(basename(__NAMESPACE__) . '/icon-dark.svg')], 'small-icon' => [dcPage::getPF(self::$pid . '/icon.svg'), dcPage::getPF(self::$pid . '/icon-dark.svg')],
'large-icon' => [dcPage::getPF(basename(__NAMESPACE__) . '/icon.svg'), dcPage::getPF(basename(__NAMESPACE__) . '/icon-dark.svg')], 'large-icon' => [dcPage::getPF(self::$pid . '/icon.svg'), dcPage::getPF(self::$pid . '/icon-dark.svg')],
//'permissions' => dcCore::app()->auth->isSuperAdmin(), //'permissions' => dcCore::app()->auth->isSuperAdmin(),
]); ]);
}); });
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('Packages repository'), __('Packages repository'),
dcCore::app()->adminurl->get('admin.plugin.' . basename(__NAMESPACE__)) . '#packman-repository-repository', dcCore::app()->adminurl->get('admin.plugin.' . self::$pid) . '#packman-repository-repository',
[dcPage::getPF(basename(__NAMESPACE__) . '/icon.svg'), dcPage::getPF(basename(__NAMESPACE__) . '/icon-dark.svg')], [dcPage::getPF(self::$pid . '/icon.svg'), dcPage::getPF(self::$pid . '/icon-dark.svg')],
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__NAMESPACE__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']), preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . self::$pid)) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->isSuperAdmin() dcCore::app()->auth->isSuperAdmin()
); );

View File

@ -27,11 +27,13 @@ use Exception;
class Config class Config
{ {
private static $pid = '';
protected static $init = false; protected static $init = false;
public static function init(): bool public static function init(): bool
{ {
if (defined('DC_CONTEXT_ADMIN') && defined('DC_CONTEXT_MODULE')) { if (defined('DC_CONTEXT_ADMIN') && defined('DC_CONTEXT_MODULE')) {
self::$pid = basename(dirname(__DIR__));
self::$init = true; self::$init = true;
} }
@ -65,7 +67,7 @@ class Config
); );
if ($check) { 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_nocomment', $pack_nocomment);
$s->put('pack_fixnewline', $pack_fixnewline); $s->put('pack_fixnewline', $pack_fixnewline);
$s->put('pack_overwrite', $pack_overwrite); $s->put('pack_overwrite', $pack_overwrite);
@ -78,7 +80,7 @@ class Config
__('Configuration has been successfully updated.') __('Configuration has been successfully updated.')
); );
http::redirect( 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()) dcCore::app()->admin->__get('list')->getRedir())
); );
@ -98,7 +100,7 @@ class Config
} }
# -- Get settings -- # -- Get settings --
$s = dcCore::app()->blog->settings->__get(basename(__NAMESPACE__)); $s = dcCore::app()->blog->settings->__get(self::$pid);
# -- Display form -- # -- Display form --
echo ' echo '

View File

@ -70,11 +70,13 @@ class Install
]; ];
// Nothing to change below // Nothing to change below
private static $pid = '';
protected static $init = false; protected static $init = false;
public static function init(): bool 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; return self::$init;
} }
@ -91,7 +93,7 @@ class Install
// Set module settings // Set module settings
foreach (self::$mod_conf as $v) { 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[0],
$v[2], $v[2],
$v[3], $v[3],
@ -111,7 +113,7 @@ class Install
public static function growUp(): void public static function growUp(): void
{ {
$current = dcCore::app()->getVersion(basename(__NAMESPACE__)); $current = dcCore::app()->getVersion(self::$pid);
// Update settings id, ns // Update settings id, ns
if ($current && version_compare($current, '2022.12.19.1', '<=')) { if ($current && version_compare($current, '2022.12.19.1', '<=')) {
@ -124,7 +126,7 @@ class Install
if (preg_match('/^packman_(.*?)$/', $record->setting_id, $match)) { if (preg_match('/^packman_(.*?)$/', $record->setting_id, $match)) {
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME); $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
$cur->setting_id = $match[1]; $cur->setting_id = $match[1];
$cur->setting_ns = basename(__NAMESPACE__); $cur->setting_ns = self::$pid;
$cur->update( $cur->update(
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'pacKman' " . "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) . "' ")) 'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))

View File

@ -31,6 +31,7 @@ class Manage
{ {
private static $plugins_path = ''; private static $plugins_path = '';
private static $themes_path = ''; private static $themes_path = '';
private static $pid = '';
protected static $init = false; protected static $init = false;
public static function init(): bool public static function init(): bool
@ -43,6 +44,7 @@ class Manage
$p = array_pop($e); $p = array_pop($e);
self::$plugins_path = (string) path::real($p); self::$plugins_path = (string) path::real($p);
self::$themes_path = dcCore::app()->blog->themes_path; self::$themes_path = dcCore::app()->blog->themes_path;
self::$pid = basename(dirname(__DIR__));
self::$init = true; self::$init = true;
} }
@ -60,7 +62,7 @@ class Manage
$type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : ''; $type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : '';
# Settings # Settings
$s = dcCore::app()->blog->settings->get(basename(__NAMESPACE__)); $s = dcCore::app()->blog->settings->get(self::$pid);
$dir = Utils::getRepositoryDir($s->get('pack_repository')); $dir = Utils::getRepositoryDir($s->get('pack_repository'));
# Modules # Modules
@ -127,7 +129,7 @@ class Manage
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-' . $type); dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-' . $type);
} }
# Pack # Pack
@ -166,7 +168,7 @@ class Manage
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-' . $type); dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-' . $type);
} }
# Delete # Delete
@ -191,7 +193,7 @@ class Manage
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-repository-' . $type);
} }
# Install # Install
@ -218,7 +220,7 @@ class Manage
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-repository-' . $type);
} }
# Copy # Copy
@ -244,7 +246,7 @@ class Manage
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__), [], '#packman-repository-' . $type); dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid, [], '#packman-repository-' . $type);
} }
# Move # Move
@ -271,7 +273,7 @@ class Manage
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } 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) { } catch (Exception $e) {
@ -286,7 +288,7 @@ class Manage
} }
# Settings # Settings
$s = dcCore::app()->blog->settings->get(basename(__NAMESPACE__)); $s = dcCore::app()->blog->settings->get(self::$pid);
$dir = Utils::getRepositoryDir($s->get('pack_repository')); $dir = Utils::getRepositoryDir($s->get('pack_repository'));
$is_configured = Utils::is_configured( $is_configured = Utils::is_configured(
@ -299,7 +301,7 @@ class Manage
echo echo
'<html><head><title>' . __('pacKman') . '</title>' . '<html><head><title>' . __('pacKman') . '</title>' .
dcPage::jsPageTabs() . dcPage::jsPageTabs() .
dcPage::jsModuleLoad(basename(__NAMESPACE__) . '/js/packman.js'); dcPage::jsModuleLoad(self::$pid . '/js/packman.js');
# --BEHAVIOR-- packmanAdminHeader # --BEHAVIOR-- packmanAdminHeader
dcCore::app()->callBehavior('packmanAdminHeader'); dcCore::app()->callBehavior('packmanAdminHeader');
@ -316,7 +318,7 @@ class Manage
if (dcCore::app()->error->flag() || !$is_configured) { if (dcCore::app()->error->flag() || !$is_configured) {
echo echo
'<div class="warning">' . __('pacKman is not well configured.') . ' ' . '<div class="warning">' . __('pacKman is not well configured.') . ' ' .
'<a href="' . dcCore::app()->adminurl->get('admin.plugins', ['module' => basename(__NAMESPACE__), 'conf' => '1', 'redir' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__NAMESPACE__))]) . '">' . __('Configuration') . '</a>' . '<a href="' . dcCore::app()->adminurl->get('admin.plugins', ['module' => self::$pid, 'conf' => '1', 'redir' => dcCore::app()->adminurl->get('admin.plugin.' . self::$pid)]) . '">' . __('Configuration') . '</a>' .
'</div>'; '</div>';
} else { } else {
$repo_path_modules = array_merge( $repo_path_modules = array_merge(

View File

@ -47,7 +47,7 @@ class Prepend
foreach (self::LIBS as $lib) { foreach (self::LIBS as $lib) {
Clearbricks::lib()->autoload([ Clearbricks::lib()->autoload([
implode('\\', ['Dotclear','Plugin', basename(__NAMESPACE__), $lib]) => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php', __NAMESPACE__ . '\\' . $lib => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php',
]); ]);
} }

View File

@ -16,10 +16,12 @@ namespace Dotclear\Plugin\pacKman;
class Uninstall class Uninstall
{ {
private static $pid = '';
protected static $init = false; protected static $init = false;
public static function init(): bool public static function init(): bool
{ {
self::$pid = basename(dirname(__DIR__));
self::$init = defined('DC_RC_PATH'); self::$init = defined('DC_RC_PATH');
return self::$init; return self::$init;
@ -37,7 +39,7 @@ class Uninstall
/* action */ /* action */
'delete_all', 'delete_all',
/* ns */ /* ns */
basename(__NAMESPACE__), self::$pid,
/* desc */ /* desc */
__('delete all settings') __('delete all settings')
); );
@ -48,7 +50,7 @@ class Uninstall
/* action */ /* action */
'delete', 'delete',
/* ns */ /* ns */
basename(__NAMESPACE__), self::$pid,
/* desc */ /* desc */
__('delete plugin files') __('delete plugin files')
); );
@ -59,7 +61,7 @@ class Uninstall
/* action */ /* action */
'delete', 'delete',
/* ns */ /* ns */
basename(__NAMESPACE__), self::$pid,
/* desc */ /* desc */
__('delete the version number') __('delete the version number')
); );
@ -70,9 +72,9 @@ class Uninstall
/* action */ /* action */
'delete_all', 'delete_all',
/* ns */ /* ns */
basename(__NAMESPACE__), self::$pid,
/* desc */ /* desc */
sprintf(__('delete all %s settings'), basename(__NAMESPACE__)) sprintf(__('delete all %s settings'), self::$pid)
); );
$uninstaller->addDirectAction( $uninstaller->addDirectAction(
@ -81,9 +83,9 @@ class Uninstall
/* action */ /* action */
'delete', 'delete',
/* ns */ /* ns */
basename(__NAMESPACE__), self::$pid,
/* desc */ /* desc */
sprintf(__('delete %s plugin files'), basename(__NAMESPACE__)) sprintf(__('delete %s plugin files'), self::$pid)
); );
$uninstaller->addDirectAction( $uninstaller->addDirectAction(
@ -92,9 +94,9 @@ class Uninstall
/* action */ /* action */
'delete', 'delete',
/* ns */ /* ns */
basename(__NAMESPACE__), self::$pid,
/* desc */ /* desc */
sprintf(__('delete %s version number'), basename(__NAMESPACE__)) sprintf(__('delete %s version number'), self::$pid)
); );
return true; return true;