code review

This commit is contained in:
Jean-Christian Paul Denis 2023-10-24 21:27:03 +02:00
parent 3f3f0c0521
commit 9e1c801a66
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
8 changed files with 76 additions and 69 deletions

View File

@ -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 fac 1.5 - 2023.10.16
=========================================================== ===========================================================
* Require Dotclear 2.28 * Require Dotclear 2.28

View File

@ -1,7 +1,7 @@
# README # README
[![Release](https://img.shields.io/badge/release-1.5-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/fac/releases) [![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.16-c44d58.svg) ![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) [![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) [![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) [![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/fac/src/branch/master/LICENSE)

View File

@ -17,7 +17,7 @@ $this->registerModule(
'Feed after content', 'Feed after content',
'Add RSS/Atom feeds after entries content', 'Add RSS/Atom feeds after entries content',
'Jean-Christian Denis and Contributors', 'Jean-Christian Denis and Contributors',
'1.5', '1.5.1',
[ [
'requires' => [['core', '2.28']], 'requires' => [['core', '2.28']],
'permissions' => 'My', 'permissions' => 'My',

View File

@ -2,10 +2,10 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="fac"> <module id="fac">
<name>Feed after content</name> <name>Feed after content</name>
<version>1.5</version> <version>1.5.1</version>
<author>Jean-Christian Denis and Contributors</author> <author>Jean-Christian Denis and Contributors</author>
<desc>Add RSS/Atom feeds after entries content</desc> <desc>Add RSS/Atom feeds after entries content</desc>
<file>https://git.dotclear.watch/JcDenis/fac/releases/download/v1.5/plugin-fac.zip</file> <file>https://git.dotclear.watch/JcDenis/fac/releases/download/v1.5.1/plugin-fac.zip</file>
<da:dcmin>2.28</da:dcmin> <da:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/fac/src/branch/master/README.md</da:details> <da:details>https://git.dotclear.watch/JcDenis/fac/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/fac/issues</da:support> <da:support>https://git.dotclear.watch/JcDenis/fac/issues</da:support>

View File

@ -23,10 +23,7 @@ class Backend extends Process
public static function process(): bool public static function process(): bool
{ {
if (!self::status()) { if (self::status()) {
return false;
}
App::behavior()->addBehaviors([ App::behavior()->addBehaviors([
'adminBlogPreferencesFormV2' => BackendBehaviors::adminBlogPreferencesFormV2(...), 'adminBlogPreferencesFormV2' => BackendBehaviors::adminBlogPreferencesFormV2(...),
'adminBeforeBlogSettingsUpdate' => BackendBehaviors::adminBeforeBlogSettingsUpdate(...), 'adminBeforeBlogSettingsUpdate' => BackendBehaviors::adminBeforeBlogSettingsUpdate(...),
@ -37,7 +34,8 @@ class Backend extends Process
'adminBeforePostDelete' => BackendBehaviors::adminBeforePostDelete(...), 'adminBeforePostDelete' => BackendBehaviors::adminBeforePostDelete(...),
'adminPostsActions' => BackendBehaviors::adminPostsActions(...), 'adminPostsActions' => BackendBehaviors::adminPostsActions(...),
]); ]);
}
return true; return self::status();
} }
} }

View File

@ -42,9 +42,9 @@ use Exception;
class BackendBehaviors 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<string, string> List of post type and name
*/ */
public static function getPostsTypes(): array public static function getPostsTypes(): array
{ {
@ -61,7 +61,7 @@ class BackendBehaviors
$types[sprintf( $types[sprintf(
__('"%s" pages from extension muppet'), __('"%s" pages from extension muppet'),
$v['name'] $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 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 public static function adminBeforeBlogSettingsUpdate(BlogSettingsInterface $blog_settings): void
{ {
@ -146,7 +146,7 @@ class BackendBehaviors
} }
/** /**
* Add javascript (toggle) * Add javascript (toggle).
* *
* @return string HTML head * @return string HTML head
*/ */
@ -156,10 +156,10 @@ class BackendBehaviors
} }
/** /**
* Add form to post sidebar * Add form to post sidebar.
* *
* @param ArrayObject $main_items Main items * @param ArrayObject<string, string> $main_items Main items
* @param ArrayObject $sidebar_items Sidebar items * @param ArrayObject<string, array<string, mixed>> $sidebar_items Sidebar items
* @param null|MetaRecord $post Post record or null * @param null|MetaRecord $post Post record or null
*/ */
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void 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 Cursor $cur Current post Cursor
* @param integer $post_id Post id * @param int $post_id Post id
*/ */
public static function adminAfterPostSave(Cursor $cur, int $post_id): void 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 public static function adminBeforePostDelete(int $post_id): void
{ {
@ -221,7 +221,7 @@ class BackendBehaviors
} }
/** /**
* Add actions to posts page combo * Add actions to posts page combo.
* *
* @param ActionsPosts $pa ActionsPostsPage instance * @param ActionsPosts $pa ActionsPostsPage instance
*/ */
@ -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 ActionsPosts $pa ActionsPosts instance
* @param ArrayObject $post _POST actions * @param ArrayObject<string, mixed> $post _POST actions
*/ */
public static function callbackRemove(ActionsPosts $pa, ArrayObject $post): void public static function callbackRemove(ActionsPosts $pa, ArrayObject $post): void
{ {
@ -275,7 +275,7 @@ class BackendBehaviors
# Delete unused feed # Delete unused feed
foreach ($posts_ids as $post_id) { foreach ($posts_ids as $post_id) {
self::delFeed($post_id); self::delFeed((int) $post_id);
} }
Notices::addSuccessNotice(__('Linked feed deleted.')); 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 ActionsPosts $pa ActionsPosts instance
* @param ArrayObject $post _POST actions * @param ArrayObject<string, mixed> $post _POST actions
*/ */
public static function callbackAdd(ActionsPosts $pa, ArrayObject $post): void public static function callbackAdd(ActionsPosts $pa, ArrayObject $post): void
{ {
@ -303,8 +303,8 @@ class BackendBehaviors
if (!empty($post['fac_url']) if (!empty($post['fac_url'])
&& !empty($post['fac_format'])) { && !empty($post['fac_format'])) {
foreach ($posts_ids as $post_id) { foreach ($posts_ids as $post_id) {
self::delFeed($post_id); self::delFeed((int) $post_id);
self::addFeed($post_id, $post); self::addFeed((int) $post_id, $post);
} }
Notices::addSuccessNotice(__('Linked feed added.')); Notices::addSuccessNotice(__('Linked feed added.'));
@ -325,7 +325,7 @@ class BackendBehaviors
(new Text('', $pa->getCheckboxes() . self::formFeed())), (new Text('', $pa->getCheckboxes() . self::formFeed())),
(new Para())->items([ (new Para())->items([
App::nonce()->formNonce(), App::nonce()->formNonce(),
... $pa->giddenFields(), ... $pa->hiddenFields(),
(new Hidden(['action'], 'fac_add')), (new Hidden(['action'], 'fac_add')),
(new Submit(['save']))->value(__('Save')), (new Submit(['save']))->value(__('Save')),
]), ]),
@ -336,10 +336,11 @@ class BackendBehaviors
} }
/** /**
* Linked feed form field * Linked feed form field.
* *
* @param string $url Feed URL * @param string $url Feed URL
* @param string $format Feed format * @param string $format Feed format
*
* @return string Feed form content * @return string Feed form content
*/ */
protected static function formFeed(string $url = '', string $format = ''): string 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<string, string> List of fac formats
*/ */
protected static function comboFac(): array protected static function comboFac(): array
{ {
@ -382,16 +383,16 @@ class BackendBehaviors
$res = []; $res = [];
foreach ($formats as $uid => $f) { foreach ($formats as $uid => $f) {
$res[$f['name']] = $uid; $res[(string) $f['name']] = (string) $uid;
} }
return $res; 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 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 int $post_id Post id
* @param array|ArrayObject $options Feed options * @param array<string, mixed>|ArrayObject<string, mixed> $options Feed options
*/ */
protected static function addFeed(int $post_id, $options): void protected static function addFeed(int $post_id, $options): void
{ {

View File

@ -169,6 +169,9 @@ class Config extends Process
Page::helpBlock('fac'); Page::helpBlock('fac');
} }
/**
* @param array<string, string> $format
*/
private static function displayFacFormat(string $title, string $uid, array $format): void private static function displayFacFormat(string $title, string $uid, array $format): void
{ {
echo echo

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\fac; namespace Dotclear\Plugin\fac;
use Dotclear\App; use Dotclear\App;
use Dotclear\Core\Frontend\Ctx;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Helper\Date; use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
@ -32,7 +31,7 @@ class Frontend extends Process
return false; return false;
} }
App::behavior()->addBehavior('publicEntryAfterContent', function ($___, Ctx $_ctx): void { App::behavior()->addBehavior('publicEntryAfterContent', function ($___, $_____): void {
if (!App::blog()->isDefined()) { if (!App::blog()->isDefined()) {
return; return;
} }
@ -133,7 +132,7 @@ class Frontend extends Process
$feeddesc = ''; $feeddesc = '';
if (My::settings()->get('showfeeddesc') if (My::settings()->get('showfeeddesc')
&& '' != $feed->description) { && '' != $feed->description) {
$feeddesc = '<p>' . $_ctx::global_filters( $feeddesc = '<p>' . App::frontend()->context()->global_filters(
$feed->description, $feed->description,
['encode_xml', 'remove_html'] ['encode_xml', 'remove_html']
) . '</p>'; ) . '</p>';
@ -159,7 +158,7 @@ class Frontend extends Process
$date = Date::dt2str($dateformat, $item->pubdate); $date = Date::dt2str($dateformat, $item->pubdate);
// Entries title // Entries title
$title = $_ctx::global_filters( $title = App::frontend()->context()->global_filters(
str_replace( str_replace(
[ [
'%D', '%D',
@ -175,13 +174,13 @@ class Frontend extends Process
$item->description, $item->description,
$item->content, $item->content,
], ],
$format['linestitletext'] (string) $format['linestitletext']
), ),
['remove_html', 'cut_string' => abs((int) $format['linestitlelength'])], ['remove_html', 'cut_string' => abs((int) $format['linestitlelength'])],
); );
// Entries over title // Entries over title
$overtitle = $_ctx::global_filters( $overtitle = App::frontend()->context()->global_filters(
str_replace( str_replace(
[ [
'%D', '%D',
@ -197,7 +196,7 @@ class Frontend extends Process
$item->description, $item->description,
$item->content, $item->content,
], ],
$format['linestitleover'] (string) $format['linestitleover']
), ),
['remove_html', 'cut_string' => 350], ['remove_html', 'cut_string' => 350],
); );
@ -207,7 +206,7 @@ class Frontend extends Process
if ($format['showlinesdescription'] if ($format['showlinesdescription']
&& '' != $item->description) { && '' != $item->description) {
$description = '<dd>' . $description = '<dd>' .
$_ctx::global_filters( App::frontend()->context()->global_filters(
$item->description, $item->description,
['remove_html' => (int) $format['linesdescriptionnohtml'], 'cut_string' => abs((int) $format['linesdescriptionlength'])] ['remove_html' => (int) $format['linesdescriptionnohtml'], 'cut_string' => abs((int) $format['linesdescriptionlength'])]
) . '</dd>'; ) . '</dd>';
@ -218,7 +217,7 @@ class Frontend extends Process
if ($format['showlinescontent'] if ($format['showlinescontent']
&& '' != $item->content) { && '' != $item->content) {
$content = '<dd>' . $content = '<dd>' .
$_ctx::global_filters( App::frontend()->context()->global_filters(
$item->content, $item->content,
['remove_html' => (int) $format['linescontentnohtml'], 'cut_string' => abs((int) $format['linescontentlength'])] ['remove_html' => (int) $format['linescontentnohtml'], 'cut_string' => abs((int) $format['linescontentlength'])]
) . '</dd>'; ) . '</dd>';