From a068ecef9c40ef66f38481fb5846d356519f31c7 Mon Sep 17 00:00:00 2001
From: Jean-Christian Denis
Date: Tue, 13 Dec 2022 00:16:35 +0100
Subject: [PATCH] use abstract plugin name
---
_define.php | 8 ++++----
_install.php | 21 ++++++++-------------
_public.php | 4 ++--
_uninstall.php | 20 ++++++++++----------
_widgets.php | 4 ++--
inc/class.enhancepostcontent.php | 8 ++++----
inc/class.epcfilter.php | 3 +--
index.php | 32 ++++++++++++++++----------------
8 files changed, 47 insertions(+), 53 deletions(-)
diff --git a/_define.php b/_define.php
index 9505c9b..9f87fae 100644
--- a/_define.php
+++ b/_define.php
@@ -18,16 +18,16 @@ $this->registerModule(
'Enhance post content',
'Add features to words in post content',
'Jean-Christian Denis and Contributors',
- '2022.11.20',
+ '2022.12.01-dev',
[
'requires' => [['core', '2.24']],
'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
]),
'type' => 'plugin',
- 'support' => 'https://github.com/JcDenis/enhancePostContent',
- 'details' => 'https://plugins.dotaddict.org/dc2/details/enhancePostContent',
- 'repository' => 'https://raw.githubusercontent.com/JcDenis/enhancePostContent/master/dcstore.xml',
+ 'support' => 'https://github.com/JcDenis/' . basename(__DIR__),
+ 'details' => 'https://plugins.dotaddict.org/dc2/details/' . basename(__DIR__),
+ 'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
'settings' => [
'blog' => '#params.epc_params',
],
diff --git a/_install.php b/_install.php
index d11db35..dfe0776 100644
--- a/_install.php
+++ b/_install.php
@@ -48,12 +48,12 @@ try {
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
$s = dcCore::app()->blog->settings->__get(basename(__DIR__));
- $s->put('enhancePostContent_active', false, 'boolean', 'Enable enhancePostContent', false, true);
- $s->put('enhancePostContent_list_sortby', 'epc_key', 'string', 'Admin records list field order', false, true);
- $s->put('enhancePostContent_list_order', 'desc', 'string', 'Admin records list order', false, true);
- $s->put('enhancePostContent_list_nb', 20, 'integer', 'Admin records list nb per page', false, true);
- $s->put('enhancePostContent_allowedtplvalues', serialize(enhancePostContent::defaultAllowedTplValues()), 'string', 'List of allowed template values', false, true);
- $s->put('enhancePostContent_allowedpubpages', serialize(enhancePostContent::defaultAllowedPubPages()), 'string', 'List of allowed template pages', false, true);
+ $s->put('active', false, 'boolean', 'Enable enhancePostContent', false, true);
+ $s->put('list_sortby', 'epc_key', 'string', 'Admin records list field order', false, true);
+ $s->put('list_order', 'desc', 'string', 'Admin records list order', false, true);
+ $s->put('list_nb', 20, 'integer', 'Admin records list nb per page', false, true);
+ $s->put('allowedtplvalues', serialize(enhancePostContent::defaultAllowedTplValues()), 'string', 'List of allowed template values', false, true);
+ $s->put('allowedpubpages', serialize(enhancePostContent::defaultAllowedPubPages()), 'string', 'List of allowed template pages', false, true);
# Filters settings
$filters = enhancePostContent::getFilters();
@@ -67,16 +67,11 @@ try {
'tplValues' => $filter->tplValues,
'pubPages' => $filter->pubPages,
];
- $s->put('enhancePostContent_' . $id, serialize($opt), 'string', 'Settings for ' . $id, false, true);
- /* # only tables
- if (isset($filter['list'])) {
- $s->put('enhancePostContent_' . $id . 'List', serialize($filter['list']), 'string', 'List for ' . $id, false, true);
- }
- */
+ $s->put($id, serialize($opt), 'string', 'Settings for ' . $id, false, true);
}
# Update old versions
- $old_version = dcCore::app()->getVersion($mod_id);
+ $old_version = dcCore::app()->getVersion(basename(__DIR__));
if ($old_version && version_compare('2021.10.05', $old_version, '>=')) {
include_once dirname(__FILE__) . '/inc/lib.epc.update.php';
}
diff --git a/_public.php b/_public.php
index 5f16eca..4f6f5f0 100644
--- a/_public.php
+++ b/_public.php
@@ -16,9 +16,9 @@ if (!defined('DC_RC_PATH')) {
require __DIR__ . '/_widgets.php';
-dcCore::app()->blog->settings->addNamespace('enhancePostContent');
+dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
-if (!dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_active) {
+if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active) {
return null;
}
diff --git a/_uninstall.php b/_uninstall.php
index dc7700b..5132938 100644
--- a/_uninstall.php
+++ b/_uninstall.php
@@ -20,7 +20,7 @@ $this->addUserAction(
/* action */
'delete_all',
/* ns */
- 'enhancePostContent',
+ basename(__DIR__),
/* description */
__('delete all settings')
);
@@ -42,7 +42,7 @@ $this->addUserAction(
/* action */
'delete',
/* ns */
- 'enhancePostContent',
+ basename(__DIR__),
/* description */
__('delete plugin files')
);
@@ -53,7 +53,7 @@ $this->addUserAction(
/* action */
'delete',
/* ns */
- 'enhancePostContent',
+ basename(__DIR__),
/* description */
__('delete the version number')
);
@@ -64,9 +64,9 @@ $this->addDirectAction(
/* action */
'delete_all',
/* ns */
- 'enhancePostContent',
+ basename(__DIR__),
/* description */
- sprintf(__('delete all %s settings'), 'enhancePostContent')
+ sprintf(__('delete all %s settings'), basename(__DIR__))
);
$this->addDirectAction(
@@ -77,7 +77,7 @@ $this->addDirectAction(
/* ns */
initEnhancePostContent::TABLE_NAME,
/* desc */
- sprintf(__('delete %s table'), 'enhancePostContent')
+ sprintf(__('delete %s table'), basename(__DIR__))
);
$this->addDirectAction(
@@ -86,9 +86,9 @@ $this->addDirectAction(
/* action */
'delete',
/* ns */
- 'enhancePostContent',
+ basename(__DIR__),
/* description */
- sprintf(__('delete %s plugin files'), 'enhancePostContent')
+ sprintf(__('delete %s plugin files'), basename(__DIR__))
);
$this->addDirectAction(
@@ -97,7 +97,7 @@ $this->addDirectAction(
/* action */
'delete',
/* ns */
- 'enhancePostContent',
+ basename(__DIR__),
/* description */
- sprintf(__('delete %s version number'), 'enhancePostContent')
+ sprintf(__('delete %s version number'), basename(__DIR__))
);
diff --git a/_widgets.php b/_widgets.php
index f26b01b..ef4e5b6 100644
--- a/_widgets.php
+++ b/_widgets.php
@@ -111,10 +111,10 @@ class enhancePostContentWidget
return null;
}
- dcCore::app()->blog->settings->addNamespace('enhancePostContent');
+ dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
# Page
- if (!dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_active
+ if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active
|| !in_array(dcCore::app()->ctx->current_tpl, ['post.html', 'page.html'])
) {
return null;
diff --git a/inc/class.enhancepostcontent.php b/inc/class.enhancepostcontent.php
index 2537d98..d1e4164 100644
--- a/inc/class.enhancepostcontent.php
+++ b/inc/class.enhancepostcontent.php
@@ -45,8 +45,8 @@ class enhancePostContent
public static function blogAllowedTplValues()
{
- dcCore::app()->blog->settings->addNamespace('enhancePostContent');
- $rs = @unserialize(dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_allowedtplvalues);
+ dcCore::app()->blog->settings->addNamespace(basename(dirname('../' . __DIR__)));
+ $rs = @unserialize(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->allowedtplvalues);
return is_array($rs) ? $rs : self::defaultAllowedTplValues();
}
@@ -91,8 +91,8 @@ class enhancePostContent
public static function blogAllowedPubPages()
{
- dcCore::app()->blog->settings->addNamespace('enhancePostContent');
- $rs = @unserialize(dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_allowedpubpages);
+ dcCore::app()->blog->settings->addNamespace(basename(dirname('../' . __DIR__)));
+ $rs = @unserialize(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->allowedpubpages);
return is_array($rs) ? $rs : self::defaultAllowedPubPages();
}
diff --git a/inc/class.epcfilter.php b/inc/class.epcfilter.php
index 1ae60d1..d3bd633 100644
--- a/inc/class.epcfilter.php
+++ b/inc/class.epcfilter.php
@@ -108,8 +108,7 @@ abstract class epcFilter
private function blogSettings()
{
- $ns = 'enhancePostContent_' . $this->id;
- $opt = @unserialize(dcCore::app()->blog->settings->enhancePostContent->$ns);
+ $opt = @unserialize(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->__get($this->id));
if (!is_array($opt)) {
$opt = [];
diff --git a/index.php b/index.php
index 42309b5..4db4836 100644
--- a/index.php
+++ b/index.php
@@ -60,8 +60,8 @@ try {
'pubPages' => (array) $_POST['filter_pubPages'],
];
- dcCore::app()->blog->settings->addNamespace('enhancePostContent');
- dcCore::app()->blog->settings->enhancePostContent->put('enhancePostContent_' . $filter->id(), serialize($f));
+ dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
+ dcCore::app()->blog->settings->__get(basename(__DIR__))->put($filter->id(), serialize($f));
dcCore::app()->blog->triggerBlog();
@@ -70,7 +70,7 @@ try {
);
dcCore::app()->adminurl->redirect(
- 'admin.plugin.enhancePostContent',
+ 'admin.plugin.' . basename(__DIR__),
['part' => $part],
'#settings'
);
@@ -98,7 +98,7 @@ try {
);
}
dcCore::app()->adminurl->redirect(
- 'admin.plugin.enhancePostContent',
+ 'admin.plugin.' . basename(__DIR__),
['part' => $part],
'#record'
);
@@ -122,7 +122,7 @@ try {
http::redirect($_REQUEST['redir']);
} else {
dcCore::app()->adminurl->redirect(
- 'admin.plugin.enhancePostContent',
+ 'admin.plugin.' . basename(__DIR__),
['part' => $part],
'#record'
);
@@ -150,7 +150,7 @@ if ($filter->has_list) {
dcCore::app()->error->add($e->getMessage());
}
- $header = $sorts->js(dcCore::app()->adminurl->get('admin.plugin.enhancePostContent', ['part' => $part], '&') . '#record');
+ $header = $sorts->js(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__), ['part' => $part], '&') . '#record');
}
# -- Display page --
@@ -159,7 +159,7 @@ if ($filter->has_list) {
echo '
' . __('Enhance post content') . '' .
dcPage::jsPageTabs() .
-dcPage::jsLoad(dcPage::getPF('enhancePostContent/js/index.js')) .
+dcPage::jsLoad(dcPage::getPF(basename(__DIR__) . '/js/index.js')) .
$header .
# --BEHAVIOR-- enhancePostContentAdminHeader
@@ -176,11 +176,11 @@ dcPage::breadcrumb([
dcPage::notices() .
# Filters select menu list
-'
' .
'';
# Filter title and description
@@ -191,7 +191,7 @@ echo '
# Filter settings
echo '