code review

master
Jean-Christian Paul Denis 2022-12-21 22:27:20 +01:00
parent 8b112f8fec
commit 1b1d6fb40f
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
20 changed files with 684 additions and 579 deletions

View File

@ -40,7 +40,7 @@ dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $f
# Preference form # Preference form
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (dcSettings $blog_settings) { dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (dcSettings $blog_settings) {
$active = (bool) $blog_settings->__get(basename(__DIR__))->active; $active = (bool) $blog_settings->get(basename(__DIR__))->get('active');
$allowedtplvalues = enhancePostContent::blogAllowedTplValues(); $allowedtplvalues = enhancePostContent::blogAllowedTplValues();
$allowedpubpages = enhancePostContent::blogAllowedPubPages(); $allowedpubpages = enhancePostContent::blogAllowedPubPages();
@ -78,9 +78,9 @@ dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function (dcSettings
$allowedtplvalues = enhancePostContent::explode($_POST['epc_allowedtplvalues']); $allowedtplvalues = enhancePostContent::explode($_POST['epc_allowedtplvalues']);
$allowedpubpages = enhancePostContent::explode($_POST['epc_allowedpubpages']); $allowedpubpages = enhancePostContent::explode($_POST['epc_allowedpubpages']);
$blog_settings->__get(basename(__DIR__))->put('active', $active); $blog_settings->get(basename(__DIR__))->put('active', $active);
$blog_settings->__get(basename(__DIR__))->put('allowedtplvalues', json_encode($allowedtplvalues)); $blog_settings->get(basename(__DIR__))->put('allowedtplvalues', json_encode($allowedtplvalues));
$blog_settings->__get(basename(__DIR__))->put('allowedpubpages', json_encode($allowedpubpages)); $blog_settings->get(basename(__DIR__))->put('allowedpubpages', json_encode($allowedpubpages));
}); });
# List filter # List filter

View File

@ -48,8 +48,7 @@ try {
epcUpgrade::growUp(); epcUpgrade::growUp();
// Settings // Settings
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); $s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
$s = dcCore::app()->blog->settings->__get(basename(__DIR__));
$s->put('active', false, 'boolean', 'Enable enhancePostContent', 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_sortby', 'epc_key', 'string', 'Admin records list field order', false, true);

View File

@ -18,7 +18,7 @@ require __DIR__ . '/_widgets.php';
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active) { if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) {
return null; return null;
} }

View File

@ -114,7 +114,7 @@ class enhancePostContentWidget
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
# Page # Page
if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')
|| !in_array(dcCore::app()->ctx->current_tpl, ['post.html', 'page.html']) || !in_array(dcCore::app()->ctx->current_tpl, ['post.html', 'page.html'])
) { ) {
return null; return null;

View File

@ -24,11 +24,7 @@ class adminEpcList extends adminGenericList
public function display($filter, $pager_url, $enclose_block = '') public function display($filter, $pager_url, $enclose_block = '')
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
if ($filter->show()) { echo '<p><strong>' . ($filter->show() ? __('No record matches the filter') : __('No record')) . '</strong></p>';
echo '<p><strong>' . __('No record matches the filter') . '</strong></p>';
} else {
echo '<p><strong>' . __('No record') . '</strong></p>';
}
} else { } else {
$pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10); $pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10);
$pager->base_url = $pager_url; $pager->base_url = $pager_url;

View File

@ -46,7 +46,7 @@ class enhancePostContent
public static function blogAllowedTplValues() public static function blogAllowedTplValues()
{ {
dcCore::app()->blog->settings->addNamespace(basename(dirname('../' . __DIR__))); dcCore::app()->blog->settings->addNamespace(basename(dirname('../' . __DIR__)));
$rs = json_decode(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->allowedtplvalues); $rs = json_decode(dcCore::app()->blog->settings->get(basename(dirname('../' . __DIR__)))->get('allowedtplvalues'));
return is_array($rs) ? $rs : self::defaultAllowedTplValues(); return is_array($rs) ? $rs : self::defaultAllowedTplValues();
} }
@ -92,7 +92,7 @@ class enhancePostContent
public static function blogAllowedPubPages() public static function blogAllowedPubPages()
{ {
dcCore::app()->blog->settings->addNamespace(basename(dirname('../' . __DIR__))); dcCore::app()->blog->settings->addNamespace(basename(dirname('../' . __DIR__)));
$rs = json_decode(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->allowedpubpages); $rs = json_decode(dcCore::app()->blog->settings->get(basename(dirname('../' . __DIR__)))->get('allowedpubpages'));
return is_array($rs) ? $rs : self::defaultAllowedPubPages(); return is_array($rs) ? $rs : self::defaultAllowedPubPages();
} }

View File

@ -108,7 +108,7 @@ abstract class epcFilter
private function blogSettings() private function blogSettings()
{ {
$opt = json_decode((string) dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->__get($this->id)); $opt = json_decode((string) dcCore::app()->blog->settings->get(basename(dirname('../' . __DIR__)))->get($this->id));
if (empty($opt)) { if (empty($opt)) {
$opt = []; $opt = [];

View File

@ -1,4 +1,15 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -1,4 +1,15 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -1,4 +1,15 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -1,4 +1,15 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -1,4 +1,15 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -1,4 +1,15 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -1,4 +1,15 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -1,4 +1,15 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -1,4 +1,15 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -1,4 +1,15 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -21,15 +21,15 @@ class epcUpgrade
$current = dcCore::app()->getVersion(basename(dirname('../' . __DIR__))); $current = dcCore::app()->getVersion(basename(dirname('../' . __DIR__)));
if ($current && version_compare($current, '0.6.6', '<=')) { if ($current && version_compare($current, '0.6.6', '<=')) {
self::postUpgrade00060607(); self::upTo00060607();
} }
if ($current && version_compare($current, '2021.10.06', '<=')) { if ($current && version_compare($current, '2021.10.06', '<=')) {
self::postUpgrade20211006(); self::upTo20211006();
} }
if ($current && version_compare($current, '2022.11.20', '<=')) { if ($current && version_compare($current, '2022.11.20', '<=')) {
self::preUpgrade20221120(); self::upTo20221120();
} }
} }
@ -38,7 +38,7 @@ class epcUpgrade
* *
* - filters move from settings to dedicated table * - filters move from settings to dedicated table
*/ */
private static function postUpgrade00060607() private static function upTo00060607()
{ {
# Move old filters lists from settings to database # Move old filters lists from settings to database
$f = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL "); $f = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL ");
@ -71,7 +71,7 @@ class epcUpgrade
* *
* - filters change name to id * - filters change name to id
*/ */
private static function postUpgrade20211006() private static function upTo20211006()
{ {
# Move old filter name to filter id # Move old filter name to filter id
$rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . initEnhancePostContent::TABLE_NAME); $rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . initEnhancePostContent::TABLE_NAME);
@ -92,12 +92,12 @@ class epcUpgrade
* - setting ns changes to abstract one (no real changes), * - setting ns changes to abstract one (no real changes),
* - setting value change from serialize to json_encode (if it's array) * - setting value change from serialize to json_encode (if it's array)
*/ */
private static function preUpgrade20221120() private static function upTo20221120()
{ {
// list of settings using serialize values to move to json // list of settings using serialize values to move to json
$ids = [ $ids = [
'allowedtplvalues', 'allowedtplvalues',
'allowedpubpages' 'allowedpubpages',
]; ];
foreach (enhancePostContent::getFilters() as $id => $f) { foreach (enhancePostContent::getFilters() as $id => $f) {
$ids[] = $id; $ids[] = $id;

View File

@ -61,7 +61,7 @@ try {
]; ];
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
dcCore::app()->blog->settings->__get(basename(__DIR__))->put($filter->id(), json_encode($f)); dcCore::app()->blog->settings->get(basename(__DIR__))->put($filter->id(), json_encode($f));
dcCore::app()->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
@ -159,7 +159,7 @@ if ($filter->has_list) {
echo ' echo '
<html><head><title>' . __('Enhance post content') . '</title>' . <html><head><title>' . __('Enhance post content') . '</title>' .
dcPage::jsPageTabs() . dcPage::jsPageTabs() .
dcPage::jsLoad(dcPage::getPF(basename(__DIR__) . '/js/index.js')) . dcPage::jsModuleLoad(basename(__DIR__) . '/js/index.js') .
$header . $header .
# --BEHAVIOR-- enhancePostContentAdminHeader # --BEHAVIOR-- enhancePostContentAdminHeader