code review

This commit is contained in:
Jean-Christian Paul Denis 2023-11-04 22:45:37 +01:00
parent 697027940b
commit ee39711e90
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
17 changed files with 152 additions and 63 deletions

View File

@ -1,3 +1,9 @@
zoneclearFeedServer 2023.11.04
===========================================================
* Require Dotclear 2.28
* Require PHP 8.1
* Code review (phpstan)
zoneclearFeedServer 2023.10.18
===========================================================
* Require Dotclear 2.28

View File

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

View File

@ -19,7 +19,7 @@ $this->registerModule(
'Feeds server',
'Mix your blog with a feeds planet',
'Jean-Christian Denis, BG, Pierre Van Glabeke',
'2023.10.18',
'2023.11.04',
[
'requires' => [['core', '2.28']],
'permissions' => 'My',

View File

@ -2,10 +2,10 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="zoneclearFeedServer">
<name>Feeds server</name>
<version>2023.10.18</version>
<version>2023.11.04</version>
<author>Jean-Christian Denis, BG, Pierre Van Glabeke</author>
<desc>Mix your blog with a feeds planet</desc>
<file>https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases/download/v2023.10.18/plugin-zoneclearFeedServer.zip</file>
<file>https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases/download/v2023.11.04/plugin-zoneclearFeedServer.zip</file>
<da:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/zoneclearFeedServer/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/zoneclearFeedServer/issues</da:support>

View File

@ -55,6 +55,8 @@ class BackendBehaviors
/**
* Lists columns user preference.
*
* @param ArrayObject<string, mixed> $cols
*/
public static function adminColumnsListsV2(ArrayObject $cols): void
{
@ -83,6 +85,8 @@ class BackendBehaviors
/**
* Lists filter.
*
* @param ArrayObject<string, mixed> $sorts
*/
public static function adminFiltersListsV2(ArrayObject $sorts): void
{
@ -106,14 +110,18 @@ class BackendBehaviors
/**
* Add head column to posts list.
*
* @param ArrayObject<string, mixed> $cols
*/
public static function adminPostListHeaderV2(MetaRecord $rs, ArrayObject $cols): void
{
$cols['feed'] = (new Para(null, 'th'))->text(__('Feed'))->extra('scope="col"')->render();
$cols['feed'] = (new Text('th', __('Feed')))->extra('scope="col"')->render();
}
/**
* Add body column to posts list.
*
* @param ArrayObject<string, mixed> $cols
*/
public static function adminPostListValueV2(MetaRecord $rs, ArrayObject $cols): void
{
@ -140,6 +148,9 @@ class BackendBehaviors
/**
* Add info about feed on post page sidebar.
*
* @param ArrayObject<string, mixed> $main_items
* @param ArrayObject<string, mixed> $sidebar_items
*/
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void
{

View File

@ -127,7 +127,7 @@ class Combo
try {
$categories = App::blog()->getCategories(['post_type' => 'post']);
if (!is_null($categories)) {
while ($categories->fetch()) {
$level = is_numeric($categories->f('level')) ? (int) $categories->f('level') : 1;
$cat_title = is_string($categories->f('cat_title')) ? $categories->f('cat_title') : '';
@ -138,7 +138,6 @@ class Combo
'&bull; ' . Html::escapeHTML($cat_title)
] = $cat_id;
}
}
} catch (Exception $e) {
}

View File

@ -76,7 +76,7 @@ class Config extends Process
Notices::addSuccessNotice(
__('Configuration has been successfully updated.')
);
App::bakcend()->url()->redirect('admin.plugins', [
App::backend()->url()->redirect('admin.plugins', [
'module' => My::id(),
'conf' => '1',
'redir' => !(App::backend()->__get('list') instanceof ModulesList) ? '' : App::backend()->__get('list')->getRedir(),
@ -99,9 +99,8 @@ class Config extends Process
$msg = [];
if (!is_writable(App::config()->cacheRoot())) {
$msg[] = (new Para())
->class('error')
->text(__('Dotclear cache is not writable or not well configured!'));
$msg[] = (new Text('p', __('Dotclear cache is not writable or not well configured!')))
->class('error');
}
if ($s->pub_active) {
$msg[] = (new Para())

View File

@ -98,7 +98,7 @@ class FeedsActions extends Actions
$feeds = ZoneclearFeedServer::instance()->getFeeds($params);
while ($feeds->fetch()) {
$row = new FeedRow($feeds);
$this->entries[$row->id] = $row->name;
$this->entries[(string) $row->id] = $row->name;
}
$this->rs = $feeds;
} else {

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer;
use ArrayObject;
use Dotclear\App;
use Dotclear\Core\Backend\{
Notices,
Page
@ -72,6 +73,8 @@ class FeedsDefaultActions
/**
* Enable / disable feeds.
*
* @param ArrayObject<string, mixed> $post
*/
public static function doEnableFeed(FeedsActions $ap, ArrayObject $post): void
{
@ -85,7 +88,7 @@ class FeedsDefaultActions
}
foreach ($ids as $id) {
$ap->zcfs->enableFeed($id, $enable);
$ap->zcfs->enableFeed((int) $id, $enable);
}
Notices::addSuccessNotice(sprintf(
@ -108,6 +111,8 @@ class FeedsDefaultActions
/**
* Delete feeds posts.
*
* @param ArrayObject<string, mixed> $post
*/
public static function doDeletePost(FeedsActions $ap, ArrayObject $post): void
{
@ -153,6 +158,8 @@ class FeedsDefaultActions
/**
* Delete feeds.
*
* @param ArrayObject<string, mixed> $post
*/
public static function doDeleteFeed(FeedsActions $ap, ArrayObject $post): void
{
@ -165,7 +172,7 @@ class FeedsDefaultActions
}
foreach ($ids as $id) {
$ap->zcfs->deleteFeed($id);
$ap->zcfs->deleteFeed((int) $id);
}
Notices::addSuccessNotice(sprintf(
@ -181,6 +188,8 @@ class FeedsDefaultActions
/**
* Update feeds properties.
*
* @param ArrayObject<string, mixed> $post
*/
public static function doUpdateFeed(FeedsActions $ap, ArrayObject $post): void
{
@ -193,7 +202,7 @@ class FeedsDefaultActions
}
foreach ($ids as $id) {
$ap->zcfs->checkFeedsUpdate($id, true);
$ap->zcfs->checkFeedsUpdate((int) $id, true);
}
Notices::addSuccessNotice(sprintf(
@ -205,6 +214,8 @@ class FeedsDefaultActions
/**
* Reset feeds update timer.
*
* @param ArrayObject<string, mixed> $post
*/
public static function doResetUpdate(FeedsActions $ap, ArrayObject $post): void
{
@ -220,7 +231,7 @@ class FeedsDefaultActions
foreach ($ids as $id) {
$cur->clean();
$cur->setField('feed_upd_last', 0);
$ap->zcfs->updateFeed($id, $cur);
$ap->zcfs->updateFeed((int) $id, $cur);
//$ap->zcfs->checkFeedsUpdate($id, true);
}
@ -233,6 +244,8 @@ class FeedsDefaultActions
/**
* Change feeds categories.
*
* @param ArrayObject<string, mixed> $post
*/
public static function doChangeCategory(FeedsActions $ap, ArrayObject $post): void
{
@ -251,7 +264,7 @@ class FeedsDefaultActions
foreach ($ids as $id) {
$cur->clean();
$cur->setField('cat_id', $cat_id == 0 ? null : $cat_id);
$ap->zcfs->updateFeed($id, $cur);
$ap->zcfs->updateFeed((int) $id, $cur);
}
Notices::addSuccessNotice(sprintf(
@ -299,6 +312,8 @@ class FeedsDefaultActions
/**
* Change feeds update interval.
*
* @param ArrayObject<string, mixed> $post
*/
public static function doChangeInterval(FeedsActions $ap, ArrayObject $post): void
{
@ -317,7 +332,7 @@ class FeedsDefaultActions
foreach ($ids as $id) {
$cur->clean();
$cur->setField('feed_upd_int', $upd_int);
$ap->zcfs->updateFeed($id, $cur);
$ap->zcfs->updateFeed((int) $id, $cur);
}
Notices::addSuccessNotice(sprintf(

View File

@ -182,7 +182,7 @@ class Manage extends Process
(new Label(__('Selected feeds action:'), Label::OUTSIDE_LABEL_BEFORE))
->for('action'),
(new Select('action'))
->items($feeds_actions_page->getCombo()),
->items($feeds_actions_page->getCombo() ?? []),
(new Submit('feeds-action'))
->value(__('ok')),
... My::hiddenFields($feeds_filter->values(true)),

View File

@ -417,7 +417,7 @@ class ManageFeed extends Process
(new Label(__('Selected entries action:'), Label::OUTSIDE_LABEL_BEFORE))
->for('action'),
(new Select('action'))
->items($posts_actions_page->getCombo()),
->items($posts_actions_page->getCombo() ?? []),
(new Submit('feed-action'))
->value(__('ok')),
... My::hiddenFields($post_filter->values()),

View File

@ -76,7 +76,7 @@ class ManageFeedVars
$feed = $z->getFeeds(['feed_id' => $_REQUEST['feed_id']]);
if ($feed->isEmpty()) {
Ap::error()->add(__('This feed does not exist.'));
App::error()->add(__('This feed does not exist.'));
$can_view_page = false;
} else {
$row = new FeedRow($feed);

View File

@ -56,7 +56,7 @@ class PostsFilter extends Filters
try {
$users = App::blog()->getPostsUsers();
if (is_null($users) || $users->isEmpty()) {
if ($users->isEmpty()) {
return null;
}
} catch (Exception $e) {
@ -89,7 +89,7 @@ class PostsFilter extends Filters
try {
$categories = App::blog()->getCategories();
if (is_null($categories) || $categories->isEmpty()) {
if ($categories->isEmpty()) {
return null;
}
} catch (Exception $e) {
@ -143,7 +143,7 @@ class PostsFilter extends Filters
try {
$dates = App::blog()->getDates(['type' => 'month']);
if (is_null($dates) || $dates->isEmpty()) {
if ($dates->isEmpty()) {
return null;
}
} catch (Exception $e) {

View File

@ -90,7 +90,7 @@ class Settings
{
$s = My::settings();
if (!is_null($s) && property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) {
if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) {
$s->put($key, $value, gettype($this->{$key}));
return true;

View File

@ -19,6 +19,9 @@ use Dotclear\Helper\L10n;
*/
class Template
{
/**
* @param ArrayObject<string, mixed> $a
*/
public static function Feeds(ArrayObject $a, string $c): string
{
$lastn = -1;
@ -84,6 +87,9 @@ class Template
'App::frontend()->context()->feeds = null; App::frontend()->context()->feeds_params = null; ?>';
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedIf(ArrayObject $a, string $c): string
{
$if = [];
@ -144,6 +150,9 @@ class Template
'<?php if(' . implode(' ' . $operator . ' ', $if) . ') : ?>' . $c . '<?php endif; ?>';
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedIfFirst(ArrayObject $a): string
{
$ret = Html::escapeHTML(isset($a['return']) && is_string($a['return']) ? $a['return'] : 'first');
@ -153,6 +162,9 @@ class Template
"echo '" . addslashes($ret) . "'; } ?>";
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedIfOdd(ArrayObject $a): string
{
$ret = Html::escapeHTML(isset($a['return']) && is_string($a['return']) ? $a['return'] : 'odd');
@ -162,41 +174,65 @@ class Template
"echo '" . addslashes($ret) . "'; } ?>";
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedDesc(ArrayObject $a): string
{
return self::getValue($a, 'App::frontend()->context()->feeds->feed_desc');
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedOwner(ArrayObject $a): string
{
return self::getValue($a, 'App::frontend()->context()->feeds->feed_owner');
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedCategory(ArrayObject $a): string
{
return self::getValue($a, 'App::frontend()->context()->feeds->cat_title');
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedCategoryID(ArrayObject $a): string
{
return self::getValue($a, 'App::frontend()->context()->feeds->cat_id');
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedCategoryURL(ArrayObject $a): string
{
return self::getValue($a, 'App::blog()->url().App::url()->getBase(\'category\').\'/\'.Html::sanitizeURL(App::frontend()->context()->feeds->cat_url)');
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedCategoryShortURL(ArrayObject $a): string
{
return self::getValue($a, 'App::frontend()->context()->feeds->cat_url');
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedID(ArrayObject $a): string
{
return self::getValue($a, 'App::frontend()->context()->feeds->feed_id');
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedLang(ArrayObject $a): string
{
return empty($a['full']) ?
@ -208,31 +244,49 @@ class Template
'<?php ; } unset($langs); ?>';
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedName(ArrayObject $a): string
{
return self::getValue($a, 'App::frontend()->context()->feeds->feed_name');
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedSiteURL(ArrayObject $a): string
{
return self::getValue($a, 'App::frontend()->context()->feeds->feed_url');
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedFeedURL(ArrayObject $a): string
{
return self::getValue($a, 'App::frontend()->context()->feeds->feed_feed');
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedsHeader(ArrayObject $a, string $c): string
{
return '<?php if (App::frontend()->context()->feeds->isStart()) : ?>' . $c . '<?php endif; ?>';
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedsFooter(ArrayObject $a, string $c): string
{
return '<?php if (App::frontend()->context()->feeds->isEnd()) : ?>' . $c . '<?php endif; ?>';
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedsCount(ArrayObject $a): string
{
$none = isset($a['none']) && is_string($a['none']) ? addslashes($a['none']) : 'no sources';
@ -250,6 +304,9 @@ class Template
'} unset($fcount); ?>';
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedsEntriesCount(ArrayObject $a): string
{
$none = isset($a['none']) && is_string($a['none']) ? addslashes($a['none']) : 'no entries';
@ -274,6 +331,9 @@ class Template
'} unset($allfeeds,$fcount); ?>';
}
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedEntriesCount(ArrayObject $a): string
{
$none = isset($a['none']) && is_string($a['none']) ? addslashes($a['none']) : 'no entries';
@ -292,8 +352,11 @@ class Template
'} unset($fcount); ?>';
}
/**
* @param ArrayObject<string, mixed> $a
*/
protected static function getValue(ArrayObject $a, string $v): string
{
return '<?php echo ' . sprintf(App::fontend()->template()->getFilters($a), $v) . '; ?>';
return '<?php echo ' . sprintf(App::frontend()->template()->getFilters($a), $v) . '; ?>';
}
}

View File

@ -70,7 +70,7 @@ class UrlHandler extends Url
# Server js
} elseif ($args == '/zcfsupd.js' && 3 == $s->bhv_pub_upd) {
App::frontend()->template()->setPath(App::frontend()->template()->getPath(), My::path() . '/default-templates');
App::frontend()->template()->appendPath(My::path() . '/default-templates');
self::serveDocument(
'zcfsupd.js',
'text/javascript',
@ -84,13 +84,11 @@ class UrlHandler extends Url
if (!is_string($theme)) {
self::p404();
}
$tplset = App::themes()->getDefine($theme)->get('tplset');
$path = My::path() . '/default-templates/';
if (!empty($tplset) && is_dir($path . $tplset)) {
App::frontend()->template()->setPath(App::frontend()->template()->getPath(), $path . $tplset);
} else {
App::frontend()->template()->setPath(App::frontend()->template()->getPath(), $path . App::config()->defaultTplset());
$tplset = App::themes()->getDefine(App::blog()->settings()->get('system')->get('theme'))->get('tplset');
if (empty($tplset) || !is_dir(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]))) {
$tplset = App::config()->defaultTplset();
}
App::frontend()->template()->appendPath(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]));
self::serveDocument('zcfeeds.html');
}
# Unknow

View File

@ -38,7 +38,7 @@ use Exception;
class ZoneclearFeedServer
{
/**
* .
* Net HTTP timeout.
*
* @var int NET_HTTP_TIMEOUT
*/
@ -66,7 +66,7 @@ class ZoneclearFeedServer
private static $instance;
/**
* .
* Settings.
*
* @var Settings $settings
*/
@ -289,7 +289,7 @@ class ZoneclearFeedServer
/**
* Get related posts.
*
* @param array<string,int|string|array> $params The query params
* @param array<string, mixed> $params The query params
* @param bool $count_only Return only result count
*
* @return MetaRecord The record instance
@ -315,15 +315,13 @@ class ZoneclearFeedServer
unset($params['feed_id']);
$rs = App::blog()->getPosts($params, $count_only, $sql);
return is_null($rs) ? MetaRecord::newFromArray([]) : $rs;
return App::blog()->getPosts($params, $count_only, $sql);
}
/**
* Get feed record.
*
* @param array<string,int|string|array> $params The query params
* @param array<string, mixed> $params The query params
* @param bool $count_only Return only result count
*
* @return MetaRecord The record instance
@ -773,7 +771,7 @@ class ZoneclearFeedServer
# Enable
if ($enable) {
// backup current user
if (!is_null(App::auth()->userID()) && !is_string(App::auth()->userID())) {
if (!App::auth()->userID()) {
throw new Exception('Unable to backup user');
}
$this->user = App::auth()->userID();