From 9e1c801a663a90822f0334116ce5895782d9a265 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Tue, 24 Oct 2023 21:27:03 +0200 Subject: [PATCH] code review --- CHANGELOG.md | 6 +++ README.md | 4 +- _define.php | 2 +- dcstore.xml | 4 +- src/Backend.php | 26 ++++++------- src/BackendBehaviors.php | 83 ++++++++++++++++++++-------------------- src/Config.php | 3 ++ src/Frontend.php | 17 ++++---- 8 files changed, 76 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc775b6..fcc1c66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +fac 1.5.1 - 2023.10.24 +=========================================================== +* Require Dotclear 2.28 +* Require PHP 8.1+ +* Code review + fac 1.5 - 2023.10.16 =========================================================== * Require Dotclear 2.28 diff --git a/README.md b/README.md index 2b798a3..fc71e4e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # README -[![Release](https://img.shields.io/badge/release-1.5-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/fac/releases) -![Date](https://img.shields.io/badge/date-2023.10.16-c44d58.svg) +[![Release](https://img.shields.io/badge/release-1.5.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/fac/releases) +![Date](https://img.shields.io/badge/date-2023.10.24-c44d58.svg) [![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/fac) [![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/fac/src/branch/master/LICENSE) diff --git a/_define.php b/_define.php index 973218a..6b0a611 100644 --- a/_define.php +++ b/_define.php @@ -17,7 +17,7 @@ $this->registerModule( 'Feed after content', 'Add RSS/Atom feeds after entries content', 'Jean-Christian Denis and Contributors', - '1.5', + '1.5.1', [ 'requires' => [['core', '2.28']], 'permissions' => 'My', diff --git a/dcstore.xml b/dcstore.xml index f8354b4..b1b3a56 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,10 +2,10 @@ Feed after content - 1.5 + 1.5.1 Jean-Christian Denis and Contributors Add RSS/Atom feeds after entries content - https://git.dotclear.watch/JcDenis/fac/releases/download/v1.5/plugin-fac.zip + https://git.dotclear.watch/JcDenis/fac/releases/download/v1.5.1/plugin-fac.zip 2.28 https://git.dotclear.watch/JcDenis/fac/src/branch/master/README.md https://git.dotclear.watch/JcDenis/fac/issues diff --git a/src/Backend.php b/src/Backend.php index b1e12a5..caddd10 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -23,21 +23,19 @@ class Backend extends Process public static function process(): bool { - if (!self::status()) { - return false; + if (self::status()) { + App::behavior()->addBehaviors([ + 'adminBlogPreferencesFormV2' => BackendBehaviors::adminBlogPreferencesFormV2(...), + 'adminBeforeBlogSettingsUpdate' => BackendBehaviors::adminBeforeBlogSettingsUpdate(...), + 'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...), + 'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...), + 'adminAfterPostCreate' => BackendBehaviors::adminAfterPostSave(...), + 'adminAfterPostUpdate' => BackendBehaviors::adminAfterPostSave(...), + 'adminBeforePostDelete' => BackendBehaviors::adminBeforePostDelete(...), + 'adminPostsActions' => BackendBehaviors::adminPostsActions(...), + ]); } - App::behavior()->addBehaviors([ - 'adminBlogPreferencesFormV2' => BackendBehaviors::adminBlogPreferencesFormV2(...), - 'adminBeforeBlogSettingsUpdate' => BackendBehaviors::adminBeforeBlogSettingsUpdate(...), - 'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...), - 'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...), - 'adminAfterPostCreate' => BackendBehaviors::adminAfterPostSave(...), - 'adminAfterPostUpdate' => BackendBehaviors::adminAfterPostSave(...), - 'adminBeforePostDelete' => BackendBehaviors::adminBeforePostDelete(...), - 'adminPostsActions' => BackendBehaviors::adminPostsActions(...), - ]); - - return true; + return self::status(); } } diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 919bbcc..9fc0e79 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -42,9 +42,9 @@ use Exception; class BackendBehaviors { /** - * Get combos of types of supported public pages + * Get combos of types of supported public pages. * - * @return array List of post type and name + * @return array List of post type and name */ public static function getPostsTypes(): array { @@ -61,7 +61,7 @@ class BackendBehaviors $types[sprintf( __('"%s" pages from extension muppet'), $v['name'] - )] = $k; + )] = (string) $k; } } @@ -69,9 +69,9 @@ class BackendBehaviors } /** - * Add settings to blog preference + * Add settings to blog preference. * - * @param dcSettings $blog_settings dcSettings instance + * @param BlogSettingsInterface $blog_settings Blog settings instance */ public static function adminBlogPreferencesFormV2(BlogSettingsInterface $blog_settings): void { @@ -133,9 +133,9 @@ class BackendBehaviors } /** - * Save blog settings + * Save blog settings. * - * @param dcSettings $blog_settings dcSettings instance + * @param BlogSettingsInterface $blog_settings Blog settings instance */ public static function adminBeforeBlogSettingsUpdate(BlogSettingsInterface $blog_settings): void { @@ -146,7 +146,7 @@ class BackendBehaviors } /** - * Add javascript (toggle) + * Add javascript (toggle). * * @return string HTML head */ @@ -156,11 +156,11 @@ class BackendBehaviors } /** - * Add form to post sidebar + * Add form to post sidebar. * - * @param ArrayObject $main_items Main items - * @param ArrayObject $sidebar_items Sidebar items - * @param null|MetaRecord $post Post record or null + * @param ArrayObject $main_items Main items + * @param ArrayObject> $sidebar_items Sidebar items + * @param null|MetaRecord $post Post record or null */ public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void { @@ -191,10 +191,10 @@ class BackendBehaviors } /** - * Save linked feed + * Save linked feed. * - * @param Cursor $cur Current post Cursor - * @param integer $post_id Post id + * @param Cursor $cur Current post Cursor + * @param int $post_id Post id */ public static function adminAfterPostSave(Cursor $cur, int $post_id): void { @@ -211,9 +211,9 @@ class BackendBehaviors } /** - * Delete linked feed on post edition + * Delete linked feed on post edition. * - * @param integer $post_id Post id + * @param int $post_id Post id */ public static function adminBeforePostDelete(int $post_id): void { @@ -221,9 +221,9 @@ class BackendBehaviors } /** - * Add actions to posts page combo + * Add actions to posts page combo. * - * @param ActionsPosts $pa ActionsPostsPage instance + * @param ActionsPosts $pa ActionsPostsPage instance */ public static function adminPostsActions(ActionsPosts $pa): void { @@ -249,10 +249,10 @@ class BackendBehaviors } /** - * Posts actions callback to remove linked feed + * Posts actions callback to remove linked feed. * - * @param ActionsPosts $pa ActionsPosts instance - * @param ArrayObject $post _POST actions + * @param ActionsPosts $pa ActionsPosts instance + * @param ArrayObject $post _POST actions */ public static function callbackRemove(ActionsPosts $pa, ArrayObject $post): void { @@ -275,7 +275,7 @@ class BackendBehaviors # Delete unused feed foreach ($posts_ids as $post_id) { - self::delFeed($post_id); + self::delFeed((int) $post_id); } Notices::addSuccessNotice(__('Linked feed deleted.')); @@ -283,10 +283,10 @@ class BackendBehaviors } /** - * Posts actions callback to add linked feed + * Posts actions callback to add linked feed. * - * @param ActionsPosts $pa ActionsPosts instance - * @param ArrayObject $post _POST actions + * @param ActionsPosts $pa ActionsPosts instance + * @param ArrayObject $post _POST actions */ public static function callbackAdd(ActionsPosts $pa, ArrayObject $post): void { @@ -303,8 +303,8 @@ class BackendBehaviors if (!empty($post['fac_url']) && !empty($post['fac_format'])) { foreach ($posts_ids as $post_id) { - self::delFeed($post_id); - self::addFeed($post_id, $post); + self::delFeed((int) $post_id); + self::addFeed((int) $post_id, $post); } Notices::addSuccessNotice(__('Linked feed added.')); @@ -325,7 +325,7 @@ class BackendBehaviors (new Text('', $pa->getCheckboxes() . self::formFeed())), (new Para())->items([ App::nonce()->formNonce(), - ... $pa->giddenFields(), + ... $pa->hiddenFields(), (new Hidden(['action'], 'fac_add')), (new Submit(['save']))->value(__('Save')), ]), @@ -336,11 +336,12 @@ class BackendBehaviors } /** - * Linked feed form field + * Linked feed form field. * - * @param string $url Feed URL - * @param string $format Feed format - * @return string Feed form content + * @param string $url Feed URL + * @param string $format Feed format + * + * @return string Feed form content */ protected static function formFeed(string $url = '', string $format = ''): string { @@ -366,9 +367,9 @@ class BackendBehaviors } /** - * List of fac formats + * List of fac formats. * - * @return array List of fac formats + * @return array List of fac formats */ protected static function comboFac(): array { @@ -382,16 +383,16 @@ class BackendBehaviors $res = []; foreach ($formats as $uid => $f) { - $res[$f['name']] = $uid; + $res[(string) $f['name']] = (string) $uid; } return $res; } /** - * Delete linked feed + * Delete linked feed. * - * @param integer $post_id Post id + * @param int $post_id Post id */ protected static function delFeed(int $post_id): void { @@ -401,10 +402,10 @@ class BackendBehaviors } /** - * Add linked feed + * Add linked feed. * - * @param integer $post_id Post id - * @param array|ArrayObject $options Feed options + * @param int $post_id Post id + * @param array|ArrayObject $options Feed options */ protected static function addFeed(int $post_id, $options): void { diff --git a/src/Config.php b/src/Config.php index b31d449..3de25d5 100644 --- a/src/Config.php +++ b/src/Config.php @@ -169,6 +169,9 @@ class Config extends Process Page::helpBlock('fac'); } + /** + * @param array $format + */ private static function displayFacFormat(string $title, string $uid, array $format): void { echo diff --git a/src/Frontend.php b/src/Frontend.php index 8ab8db3..7895077 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Dotclear\Plugin\fac; use Dotclear\App; -use Dotclear\Core\Frontend\Ctx; use Dotclear\Core\Process; use Dotclear\Helper\Date; use Dotclear\Helper\Html\Html; @@ -32,7 +31,7 @@ class Frontend extends Process return false; } - App::behavior()->addBehavior('publicEntryAfterContent', function ($___, Ctx $_ctx): void { + App::behavior()->addBehavior('publicEntryAfterContent', function ($___, $_____): void { if (!App::blog()->isDefined()) { return; } @@ -133,7 +132,7 @@ class Frontend extends Process $feeddesc = ''; if (My::settings()->get('showfeeddesc') && '' != $feed->description) { - $feeddesc = '

' . $_ctx::global_filters( + $feeddesc = '

' . App::frontend()->context()->global_filters( $feed->description, ['encode_xml', 'remove_html'] ) . '

'; @@ -159,7 +158,7 @@ class Frontend extends Process $date = Date::dt2str($dateformat, $item->pubdate); // Entries title - $title = $_ctx::global_filters( + $title = App::frontend()->context()->global_filters( str_replace( [ '%D', @@ -175,13 +174,13 @@ class Frontend extends Process $item->description, $item->content, ], - $format['linestitletext'] + (string) $format['linestitletext'] ), ['remove_html', 'cut_string' => abs((int) $format['linestitlelength'])], ); // Entries over title - $overtitle = $_ctx::global_filters( + $overtitle = App::frontend()->context()->global_filters( str_replace( [ '%D', @@ -197,7 +196,7 @@ class Frontend extends Process $item->description, $item->content, ], - $format['linestitleover'] + (string) $format['linestitleover'] ), ['remove_html', 'cut_string' => 350], ); @@ -207,7 +206,7 @@ class Frontend extends Process if ($format['showlinesdescription'] && '' != $item->description) { $description = '
' . - $_ctx::global_filters( + App::frontend()->context()->global_filters( $item->description, ['remove_html' => (int) $format['linesdescriptionnohtml'], 'cut_string' => abs((int) $format['linesdescriptionlength'])] ) . '
'; @@ -218,7 +217,7 @@ class Frontend extends Process if ($format['showlinescontent'] && '' != $item->content) { $content = '
' . - $_ctx::global_filters( + App::frontend()->context()->global_filters( $item->content, ['remove_html' => (int) $format['linescontentnohtml'], 'cut_string' => abs((int) $format['linescontentlength'])] ) . '
';