code review
This commit is contained in:
parent
a1470bd16f
commit
02a44ac22a
@ -1,3 +1,10 @@
|
|||||||
|
postExpired 2023.11.04
|
||||||
|
===========================================================
|
||||||
|
* Require Dotclear 2.28
|
||||||
|
* Require PHP 8.1
|
||||||
|
* Fix typo
|
||||||
|
* Code review (phpstan)
|
||||||
|
|
||||||
postExpired 2023.10.19
|
postExpired 2023.10.19
|
||||||
===========================================================
|
===========================================================
|
||||||
* Require Dotclear 2.28
|
* Require Dotclear 2.28
|
||||||
|
@ -18,7 +18,7 @@ $this->registerModule(
|
|||||||
'Expired entries',
|
'Expired entries',
|
||||||
'Change entries options at a given date',
|
'Change entries options at a given date',
|
||||||
'Jean-Christian Denis and Contributors',
|
'Jean-Christian Denis and Contributors',
|
||||||
'2023.10.19',
|
'2023.11.04',
|
||||||
[
|
[
|
||||||
'requires' => [['core', '2.28']],
|
'requires' => [['core', '2.28']],
|
||||||
'permissions' => 'My',
|
'permissions' => 'My',
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
<modules xmlns:da="http://dotaddict.org/da/">
|
<modules xmlns:da="http://dotaddict.org/da/">
|
||||||
<module id="postExpired">
|
<module id="postExpired">
|
||||||
<name>Expired entries</name>
|
<name>Expired entries</name>
|
||||||
<version>2023.10.19</version>
|
<version>2023.11.04</version>
|
||||||
<author>Jean-Christian Denis and Contributors</author>
|
<author>Jean-Christian Denis and Contributors</author>
|
||||||
<desc>Change entries options at a given date</desc>
|
<desc>Change entries options at a given date</desc>
|
||||||
<file>https://git.dotclear.watch/JcDenis/postExpired/releases/download/v2023.10.19/plugin-postExpired.zip</file>
|
<file>https://git.dotclear.watch/JcDenis/postExpired/releases/download/v2023.11.04/plugin-postExpired.zip</file>
|
||||||
<da:dcmin>2.28</da:dcmin>
|
<da:dcmin>2.28</da:dcmin>
|
||||||
<da:details>https://git.dotclear.watch/JcDenis/postExpired/src/branch/master/README.md</da:details>
|
<da:details>https://git.dotclear.watch/JcDenis/postExpired/src/branch/master/README.md</da:details>
|
||||||
<da:support>https://git.dotclear.watch/JcDenis/postExpired/issues</da:support>
|
<da:support>https://git.dotclear.watch/JcDenis/postExpired/issues</da:support>
|
||||||
|
@ -81,9 +81,9 @@ class BackendBehaviors
|
|||||||
/**
|
/**
|
||||||
* Add form to post sidebar.
|
* Add form to post sidebar.
|
||||||
*
|
*
|
||||||
* @param ArrayObject $main_items Main items
|
* @param ArrayObject<string, mixed> $main_items Main items
|
||||||
* @param ArrayObject $sidebar_items Sidebar items
|
* @param ArrayObject<string, mixed> $sidebar_items Sidebar items
|
||||||
* @param ?MetaRecord $post Post record or null
|
* @param ?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
|
||||||
{
|
{
|
||||||
@ -138,8 +138,8 @@ class BackendBehaviors
|
|||||||
/**
|
/**
|
||||||
* Posts actions callback to add expired date.
|
* Posts actions callback to add expired date.
|
||||||
*
|
*
|
||||||
* @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
|
||||||
{
|
{
|
||||||
@ -161,8 +161,8 @@ class BackendBehaviors
|
|||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
foreach ($posts_ids as $post_id) {
|
foreach ($posts_ids as $post_id) {
|
||||||
self::delPostExpired($post_id);
|
self::delPostExpired((int) $post_id);
|
||||||
self::setPostExpired($post_id, $post);
|
self::setPostExpired((int) $post_id, $post);
|
||||||
}
|
}
|
||||||
|
|
||||||
Notices::addSuccessNotice(__('Expired date added.'));
|
Notices::addSuccessNotice(__('Expired date added.'));
|
||||||
@ -202,8 +202,8 @@ class BackendBehaviors
|
|||||||
/**
|
/**
|
||||||
* Posts actions callback to add expired date.
|
* Posts actions callback to add expired date.
|
||||||
*
|
*
|
||||||
* @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
|
||||||
{
|
{
|
||||||
@ -215,7 +215,7 @@ class BackendBehaviors
|
|||||||
|
|
||||||
// Delete expired date
|
// Delete expired date
|
||||||
foreach ($posts_ids as $post_id) {
|
foreach ($posts_ids as $post_id) {
|
||||||
self::delPostExpired($post_id);
|
self::delPostExpired((int) $post_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Notices::addSuccessNotice(__('Expired date deleted.'));
|
Notices::addSuccessNotice(__('Expired date deleted.'));
|
||||||
@ -235,8 +235,8 @@ class BackendBehaviors
|
|||||||
/**
|
/**
|
||||||
* Save expired date.
|
* Save expired date.
|
||||||
*
|
*
|
||||||
* @param int $post_id Post id
|
* @param int $post_id Post id
|
||||||
* @param ArrayObject $post _POST fields
|
* @param ArrayObject<string, mixed> $post _POST fields
|
||||||
*/
|
*/
|
||||||
private static function setPostExpired(int $post_id, ArrayObject $post): void
|
private static function setPostExpired(int $post_id, ArrayObject $post): void
|
||||||
{
|
{
|
||||||
@ -286,7 +286,8 @@ class BackendBehaviors
|
|||||||
* @param string $post_type Posts type
|
* @param string $post_type Posts type
|
||||||
* @param null|int $post_id Post ID
|
* @param null|int $post_id Post ID
|
||||||
* @param bool $render Render fileds to HTML
|
* @param bool $render Render fileds to HTML
|
||||||
* @return array Array of object form fields
|
*
|
||||||
|
* @return array<string, string|Para> Array of object form fields
|
||||||
*/
|
*/
|
||||||
private static function fieldsPostExpired(string $post_type, ?int $post_id = null, bool $render = true): array
|
private static function fieldsPostExpired(string $post_type, ?int $post_id = null, bool $render = true): array
|
||||||
{
|
{
|
||||||
@ -346,13 +347,15 @@ class BackendBehaviors
|
|||||||
(new Checkbox('post_expired_password', !empty($post_expired['password'])))->value(1),
|
(new Checkbox('post_expired_password', !empty($post_expired['password'])))->value(1),
|
||||||
(new Label(__('Change password'), Label::OUTSIDE_LABEL_AFTER))->for('post_expired_password')->class('classic'),
|
(new Label(__('Change password'), Label::OUTSIDE_LABEL_AFTER))->for('post_expired_password')->class('classic'),
|
||||||
(new Label(__('New password:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_expired_newpassword'),
|
(new Label(__('New password:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_expired_newpassword'),
|
||||||
(new Input('post_expired_newpassword'))->size(65)->maxlenght(255)->class('maximal')->value(empty($post_expired['newpassword']) ? '' : $post_expired['newpassword']),
|
(new Input('post_expired_newpassword'))->size(65)->maxlength(255)->class('maximal')->value(empty($post_expired['newpassword']) ? '' : $post_expired['newpassword']),
|
||||||
(new Note())->text(__('Leave empty to remove it'))->class('form-note'),
|
(new Note())->text(__('Leave empty to remove it'))->class('form-note'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($render) {
|
if ($render) {
|
||||||
foreach ($fields as $k => $v) {
|
foreach ($fields as $k => $v) {
|
||||||
$fields[$k] = $v->render();
|
if (!is_string($v)) {
|
||||||
|
$fields[$k] = $v->render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,7 +367,7 @@ class BackendBehaviors
|
|||||||
*
|
*
|
||||||
* @param MetaRecord $categories Categories recordset
|
* @param MetaRecord $categories Categories recordset
|
||||||
*
|
*
|
||||||
* @return array Categorires combo
|
* @return array<int|string, string|Option> Categorires combo
|
||||||
*/
|
*/
|
||||||
private static function categoriesCombo(MetaRecord $categories): array
|
private static function categoriesCombo(MetaRecord $categories): array
|
||||||
{
|
{
|
||||||
@ -394,7 +397,7 @@ class BackendBehaviors
|
|||||||
/**
|
/**
|
||||||
* Custom status combo.
|
* Custom status combo.
|
||||||
*
|
*
|
||||||
* @return array Status combo
|
* @return array<string, string> Status combo
|
||||||
*/
|
*/
|
||||||
private static function statusCombo(): array
|
private static function statusCombo(): array
|
||||||
{
|
{
|
||||||
@ -409,7 +412,7 @@ class BackendBehaviors
|
|||||||
/**
|
/**
|
||||||
* Custom selection combo.
|
* Custom selection combo.
|
||||||
*
|
*
|
||||||
* @return array Selection combo
|
* @return array<string, string> Selection combo
|
||||||
*/
|
*/
|
||||||
private static function selectedCombo(): array
|
private static function selectedCombo(): array
|
||||||
{
|
{
|
||||||
@ -423,7 +426,7 @@ class BackendBehaviors
|
|||||||
/**
|
/**
|
||||||
* Custom comment status combo.
|
* Custom comment status combo.
|
||||||
*
|
*
|
||||||
* @return array Comment status combo
|
* @return array<string, string> Comment status combo
|
||||||
*/
|
*/
|
||||||
private static function commentCombo(): array
|
private static function commentCombo(): array
|
||||||
{
|
{
|
||||||
@ -437,7 +440,7 @@ class BackendBehaviors
|
|||||||
/**
|
/**
|
||||||
* Custom trackback status combo.
|
* Custom trackback status combo.
|
||||||
*
|
*
|
||||||
* @return array Trackback status combo
|
* @return array<string, string> Trackback status combo
|
||||||
*/
|
*/
|
||||||
private static function trackbackCombo(): array
|
private static function trackbackCombo(): array
|
||||||
{
|
{
|
||||||
|
@ -20,8 +20,8 @@ class FrontendTemplate
|
|||||||
/**
|
/**
|
||||||
* Template condition to check if there is an expired date.
|
* Template condition to check if there is an expired date.
|
||||||
*
|
*
|
||||||
* @param ArrayObject $attr Block attributes
|
* @param ArrayObject<string, mixed> $attr Block attributes
|
||||||
* @param string $content Block content
|
* @param string $content Block content
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -47,7 +47,7 @@ class FrontendTemplate
|
|||||||
/**
|
/**
|
||||||
* Template for expired date.
|
* Template for expired date.
|
||||||
*
|
*
|
||||||
* @param ArrayObject $attr Value attributes
|
* @param ArrayObject<string, mixed> $attr Value attributes
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -73,7 +73,7 @@ class FrontendTemplate
|
|||||||
/**
|
/**
|
||||||
* Template for expired time.
|
* Template for expired time.
|
||||||
*
|
*
|
||||||
* @param ArrayObject $attr Value attributes
|
* @param ArrayObject<string, mixed> $attr Value attributes
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +24,7 @@ class My extends MyPlugin
|
|||||||
* This is saved into post_meta as meta_id value,
|
* This is saved into post_meta as meta_id value,
|
||||||
* so this must be less than 255 caracters.
|
* so this must be less than 255 caracters.
|
||||||
*
|
*
|
||||||
* @param array $in Array of options
|
* @param array<string, string> $in Array of options
|
||||||
*
|
*
|
||||||
* @return string "Serialized" options
|
* @return string "Serialized" options
|
||||||
*/
|
*/
|
||||||
@ -43,14 +43,14 @@ class My extends MyPlugin
|
|||||||
*
|
*
|
||||||
* @param string $in "Serialized" options
|
* @param string $in "Serialized" options
|
||||||
*
|
*
|
||||||
* @return array Array of options
|
* @return array<string, string> Array of options
|
||||||
*/
|
*/
|
||||||
public static function decode(string $in): array
|
public static function decode(string $in): array
|
||||||
{
|
{
|
||||||
$out = [];
|
$out = [];
|
||||||
foreach (explode(';', $in) as $v) {
|
foreach (explode(';', $in) as $v) {
|
||||||
$v = explode('|', $v);
|
$v = explode('|', $v);
|
||||||
$out[$v[0]] = $v[1];
|
$out[(string) $v[0]] = (string) $v[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
|
@ -17,7 +17,11 @@ use Dotclear\Schema\Extension\Post;
|
|||||||
*/
|
*/
|
||||||
class rsExtPostExpired extends Post
|
class rsExtPostExpired extends Post
|
||||||
{
|
{
|
||||||
/** @var array $memory Memory to prevent redondant call */
|
/**
|
||||||
|
* Memory to prevent redondant call.
|
||||||
|
*
|
||||||
|
* @var array<string, string> $memory
|
||||||
|
*/
|
||||||
protected static array $memory = [];
|
protected static array $memory = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,8 +44,8 @@ class rsExtPostExpired extends Post
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$v = My::decode($rs_date->f('meta_id'));
|
$v = My::decode($rs_date->f('meta_id'));
|
||||||
static::$memory[$rs->f('post_id')] = $v['date'];
|
static::$memory[(string) $rs->f('post_id')] = (string) $v['date'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::$memory[$rs->f('post_id')];
|
return static::$memory[$rs->f('post_id')];
|
||||||
|
Loading…
Reference in New Issue
Block a user