code review
This commit is contained in:
parent
a1470bd16f
commit
02a44ac22a
7 changed files with 48 additions and 34 deletions
|
@ -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
|
||||
===========================================================
|
||||
* Require Dotclear 2.28
|
||||
|
|
|
@ -18,7 +18,7 @@ $this->registerModule(
|
|||
'Expired entries',
|
||||
'Change entries options at a given date',
|
||||
'Jean-Christian Denis and Contributors',
|
||||
'2023.10.19',
|
||||
'2023.11.04',
|
||||
[
|
||||
'requires' => [['core', '2.28']],
|
||||
'permissions' => 'My',
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="postExpired">
|
||||
<name>Expired entries</name>
|
||||
<version>2023.10.19</version>
|
||||
<version>2023.11.04</version>
|
||||
<author>Jean-Christian Denis and Contributors</author>
|
||||
<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: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>
|
||||
|
|
|
@ -81,8 +81,8 @@ class BackendBehaviors
|
|||
/**
|
||||
* Add form to post sidebar.
|
||||
*
|
||||
* @param ArrayObject $main_items Main items
|
||||
* @param ArrayObject $sidebar_items Sidebar items
|
||||
* @param ArrayObject<string, mixed> $main_items Main items
|
||||
* @param ArrayObject<string, mixed> $sidebar_items Sidebar items
|
||||
* @param ?MetaRecord $post Post record or null
|
||||
*/
|
||||
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void
|
||||
|
@ -139,7 +139,7 @@ class BackendBehaviors
|
|||
* Posts actions callback to add expired date.
|
||||
*
|
||||
* @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
|
||||
{
|
||||
|
@ -161,8 +161,8 @@ class BackendBehaviors
|
|||
)
|
||||
) {
|
||||
foreach ($posts_ids as $post_id) {
|
||||
self::delPostExpired($post_id);
|
||||
self::setPostExpired($post_id, $post);
|
||||
self::delPostExpired((int) $post_id);
|
||||
self::setPostExpired((int) $post_id, $post);
|
||||
}
|
||||
|
||||
Notices::addSuccessNotice(__('Expired date added.'));
|
||||
|
@ -203,7 +203,7 @@ class BackendBehaviors
|
|||
* Posts actions callback to add expired date.
|
||||
*
|
||||
* @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
|
||||
{
|
||||
|
@ -215,7 +215,7 @@ class BackendBehaviors
|
|||
|
||||
// Delete expired date
|
||||
foreach ($posts_ids as $post_id) {
|
||||
self::delPostExpired($post_id);
|
||||
self::delPostExpired((int) $post_id);
|
||||
}
|
||||
|
||||
Notices::addSuccessNotice(__('Expired date deleted.'));
|
||||
|
@ -236,7 +236,7 @@ class BackendBehaviors
|
|||
* Save expired date.
|
||||
*
|
||||
* @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
|
||||
{
|
||||
|
@ -286,7 +286,8 @@ class BackendBehaviors
|
|||
* @param string $post_type Posts type
|
||||
* @param null|int $post_id Post ID
|
||||
* @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
|
||||
{
|
||||
|
@ -346,15 +347,17 @@ class BackendBehaviors
|
|||
(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(__('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'),
|
||||
]);
|
||||
|
||||
if ($render) {
|
||||
foreach ($fields as $k => $v) {
|
||||
if (!is_string($v)) {
|
||||
$fields[$k] = $v->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
@ -364,7 +367,7 @@ class BackendBehaviors
|
|||
*
|
||||
* @param MetaRecord $categories Categories recordset
|
||||
*
|
||||
* @return array Categorires combo
|
||||
* @return array<int|string, string|Option> Categorires combo
|
||||
*/
|
||||
private static function categoriesCombo(MetaRecord $categories): array
|
||||
{
|
||||
|
@ -394,7 +397,7 @@ class BackendBehaviors
|
|||
/**
|
||||
* Custom status combo.
|
||||
*
|
||||
* @return array Status combo
|
||||
* @return array<string, string> Status combo
|
||||
*/
|
||||
private static function statusCombo(): array
|
||||
{
|
||||
|
@ -409,7 +412,7 @@ class BackendBehaviors
|
|||
/**
|
||||
* Custom selection combo.
|
||||
*
|
||||
* @return array Selection combo
|
||||
* @return array<string, string> Selection combo
|
||||
*/
|
||||
private static function selectedCombo(): array
|
||||
{
|
||||
|
@ -423,7 +426,7 @@ class BackendBehaviors
|
|||
/**
|
||||
* Custom comment status combo.
|
||||
*
|
||||
* @return array Comment status combo
|
||||
* @return array<string, string> Comment status combo
|
||||
*/
|
||||
private static function commentCombo(): array
|
||||
{
|
||||
|
@ -437,7 +440,7 @@ class BackendBehaviors
|
|||
/**
|
||||
* Custom trackback status combo.
|
||||
*
|
||||
* @return array Trackback status combo
|
||||
* @return array<string, string> Trackback status combo
|
||||
*/
|
||||
private static function trackbackCombo(): array
|
||||
{
|
||||
|
|
|
@ -20,7 +20,7 @@ class FrontendTemplate
|
|||
/**
|
||||
* 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
|
||||
*
|
||||
* @return string
|
||||
|
@ -47,7 +47,7 @@ class FrontendTemplate
|
|||
/**
|
||||
* Template for expired date.
|
||||
*
|
||||
* @param ArrayObject $attr Value attributes
|
||||
* @param ArrayObject<string, mixed> $attr Value attributes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
@ -73,7 +73,7 @@ class FrontendTemplate
|
|||
/**
|
||||
* Template for expired time.
|
||||
*
|
||||
* @param ArrayObject $attr Value attributes
|
||||
* @param ArrayObject<string, mixed> $attr Value attributes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -24,7 +24,7 @@ class My extends MyPlugin
|
|||
* This is saved into post_meta as meta_id value,
|
||||
* 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
|
||||
*/
|
||||
|
@ -43,14 +43,14 @@ class My extends MyPlugin
|
|||
*
|
||||
* @param string $in "Serialized" options
|
||||
*
|
||||
* @return array Array of options
|
||||
* @return array<string, string> Array of options
|
||||
*/
|
||||
public static function decode(string $in): array
|
||||
{
|
||||
$out = [];
|
||||
foreach (explode(';', $in) as $v) {
|
||||
$v = explode('|', $v);
|
||||
$out[$v[0]] = $v[1];
|
||||
$out[(string) $v[0]] = (string) $v[1];
|
||||
}
|
||||
|
||||
return $out;
|
||||
|
|
|
@ -17,7 +17,11 @@ use Dotclear\Schema\Extension\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 = [];
|
||||
|
||||
/**
|
||||
|
@ -41,7 +45,7 @@ class rsExtPostExpired extends Post
|
|||
}
|
||||
|
||||
$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')];
|
||||
|
|
Loading…
Reference in a new issue