diff --git a/CHANGELOG.md b/CHANGELOG.md index b110ad1..5d491bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index c5d4c45..d480c5a 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/_define.php b/_define.php index 93ecfa9..2d70034 100644 --- a/_define.php +++ b/_define.php @@ -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', diff --git a/dcstore.xml b/dcstore.xml index 9c51060..05d9cfa 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,10 +2,10 @@ Feeds server - 2023.10.18 + 2023.11.04 Jean-Christian Denis, BG, Pierre Van Glabeke Mix your blog with a feeds planet - https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases/download/v2023.10.18/plugin-zoneclearFeedServer.zip + https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases/download/v2023.11.04/plugin-zoneclearFeedServer.zip 2.28 https://git.dotclear.watch/JcDenis/zoneclearFeedServer/src/branch/master/README.md https://git.dotclear.watch/JcDenis/zoneclearFeedServer/issues diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 62ec94d..a2e6bf1 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -55,6 +55,8 @@ class BackendBehaviors /** * Lists columns user preference. + * + * @param ArrayObject $cols */ public static function adminColumnsListsV2(ArrayObject $cols): void { @@ -83,6 +85,8 @@ class BackendBehaviors /** * Lists filter. + * + * @param ArrayObject $sorts */ public static function adminFiltersListsV2(ArrayObject $sorts): void { @@ -106,14 +110,18 @@ class BackendBehaviors /** * Add head column to posts list. + * + * @param ArrayObject $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 $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 $main_items + * @param ArrayObject $sidebar_items */ public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void { diff --git a/src/Combo.php b/src/Combo.php index 0c96651..a22118f 100644 --- a/src/Combo.php +++ b/src/Combo.php @@ -28,7 +28,7 @@ use Exception; class Combo { /** - * @return array + * @return array */ public static function feedsSortby(): array { @@ -42,7 +42,7 @@ class Combo } /** - * @return array + * @return array */ public static function postsSortby(): array { @@ -56,7 +56,7 @@ class Combo } /** - * @return array + * @return array */ public static function feedsStatus(): array { @@ -67,7 +67,7 @@ class Combo } /** - * @return array + * @return array */ public static function postsStatus(): array { @@ -78,7 +78,7 @@ class Combo } /** - * @return array + * @return array */ public static function updateInterval(): array { @@ -93,7 +93,7 @@ class Combo } /** - * @return array + * @return array */ public static function tagCase(): array { @@ -106,7 +106,7 @@ class Combo } /** - * @return array + * @return array */ public static function pubUpdate(): array { @@ -119,7 +119,7 @@ class Combo } /** - * @return array + * @return array */ public static function postCategories(): array { @@ -127,17 +127,16 @@ 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') : ''; - $cat_id = is_numeric($categories->f('cat_id')) ? (string) $categories->f('cat_id') : ''; - $combo[ - str_repeat('  ', $level - 1) . - '• ' . Html::escapeHTML($cat_title) - ] = $cat_id; - } + 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') : ''; + $cat_id = is_numeric($categories->f('cat_id')) ? (string) $categories->f('cat_id') : ''; + + $combo[ + str_repeat('  ', $level - 1) . + '• ' . Html::escapeHTML($cat_title) + ] = $cat_id; } } catch (Exception $e) { } diff --git a/src/Config.php b/src/Config.php index c6d440e..084a5a3 100644 --- a/src/Config.php +++ b/src/Config.php @@ -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()) diff --git a/src/FeedsActions.php b/src/FeedsActions.php index 6fa4025..5172e9a 100644 --- a/src/FeedsActions.php +++ b/src/FeedsActions.php @@ -97,8 +97,8 @@ class FeedsActions extends Actions $feeds = ZoneclearFeedServer::instance()->getFeeds($params); while ($feeds->fetch()) { - $row = new FeedRow($feeds); - $this->entries[$row->id] = $row->name; + $row = new FeedRow($feeds); + $this->entries[(string) $row->id] = $row->name; } $this->rs = $feeds; } else { diff --git a/src/FeedsDefaultActions.php b/src/FeedsDefaultActions.php index f6287cd..757564e 100644 --- a/src/FeedsDefaultActions.php +++ b/src/FeedsDefaultActions.php @@ -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 $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 $post */ public static function doDeletePost(FeedsActions $ap, ArrayObject $post): void { @@ -153,6 +158,8 @@ class FeedsDefaultActions /** * Delete feeds. + * + * @param ArrayObject $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 $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 $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 $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 $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( diff --git a/src/Manage.php b/src/Manage.php index 4db155d..0109a21 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -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)), diff --git a/src/ManageFeed.php b/src/ManageFeed.php index 2cfbb0b..1689573 100644 --- a/src/ManageFeed.php +++ b/src/ManageFeed.php @@ -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()), diff --git a/src/ManageFeedVars.php b/src/ManageFeedVars.php index c0ecb52..11d504a 100644 --- a/src/ManageFeedVars.php +++ b/src/ManageFeedVars.php @@ -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); diff --git a/src/PostsFilter.php b/src/PostsFilter.php index 49da00a..82505a1 100644 --- a/src/PostsFilter.php +++ b/src/PostsFilter.php @@ -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) { diff --git a/src/Settings.php b/src/Settings.php index cae44a7..bf45693 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -30,10 +30,10 @@ class Settings public readonly int $tag_case; - /** @var array */ + /** @var array */ public readonly array $post_full_tpl; - /** @var array */ + /** @var array */ public readonly array $post_title_redir; public readonly string $user; @@ -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; diff --git a/src/Template.php b/src/Template.php index dd70890..45c7b14 100644 --- a/src/Template.php +++ b/src/Template.php @@ -19,6 +19,9 @@ use Dotclear\Helper\L10n; */ class Template { + /** + * @param ArrayObject $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 $a + */ public static function FeedIf(ArrayObject $a, string $c): string { $if = []; @@ -144,6 +150,9 @@ class Template '' . $c . ''; } + /** + * @param ArrayObject $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 $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 $a + */ public static function FeedDesc(ArrayObject $a): string { return self::getValue($a, 'App::frontend()->context()->feeds->feed_desc'); } + /** + * @param ArrayObject $a + */ public static function FeedOwner(ArrayObject $a): string { return self::getValue($a, 'App::frontend()->context()->feeds->feed_owner'); } + /** + * @param ArrayObject $a + */ public static function FeedCategory(ArrayObject $a): string { return self::getValue($a, 'App::frontend()->context()->feeds->cat_title'); } + /** + * @param ArrayObject $a + */ public static function FeedCategoryID(ArrayObject $a): string { return self::getValue($a, 'App::frontend()->context()->feeds->cat_id'); } + /** + * @param ArrayObject $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 $a + */ public static function FeedCategoryShortURL(ArrayObject $a): string { return self::getValue($a, 'App::frontend()->context()->feeds->cat_url'); } + /** + * @param ArrayObject $a + */ public static function FeedID(ArrayObject $a): string { return self::getValue($a, 'App::frontend()->context()->feeds->feed_id'); } + /** + * @param ArrayObject $a + */ public static function FeedLang(ArrayObject $a): string { return empty($a['full']) ? @@ -208,31 +244,49 @@ class Template ''; } + /** + * @param ArrayObject $a + */ public static function FeedName(ArrayObject $a): string { return self::getValue($a, 'App::frontend()->context()->feeds->feed_name'); } + /** + * @param ArrayObject $a + */ public static function FeedSiteURL(ArrayObject $a): string { return self::getValue($a, 'App::frontend()->context()->feeds->feed_url'); } + /** + * @param ArrayObject $a + */ public static function FeedFeedURL(ArrayObject $a): string { return self::getValue($a, 'App::frontend()->context()->feeds->feed_feed'); } + /** + * @param ArrayObject $a + */ public static function FeedsHeader(ArrayObject $a, string $c): string { return 'context()->feeds->isStart()) : ?>' . $c . ''; } + /** + * @param ArrayObject $a + */ public static function FeedsFooter(ArrayObject $a, string $c): string { return 'context()->feeds->isEnd()) : ?>' . $c . ''; } + /** + * @param ArrayObject $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 $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 $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 $a + */ protected static function getValue(ArrayObject $a, string $v): string { - return 'template()->getFilters($a), $v) . '; ?>'; + return 'template()->getFilters($a), $v) . '; ?>'; } } diff --git a/src/UrlHandler.php b/src/UrlHandler.php index 0d1cf48..99d4187 100644 --- a/src/UrlHandler.php +++ b/src/UrlHandler.php @@ -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 diff --git a/src/ZoneclearFeedServer.php b/src/ZoneclearFeedServer.php index 35be4aa..d097b8d 100644 --- a/src/ZoneclearFeedServer.php +++ b/src/ZoneclearFeedServer.php @@ -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,8 +289,8 @@ class ZoneclearFeedServer /** * Get related posts. * - * @param array $params The query params - * @param bool $count_only Return only result count + * @param array $params The query params + * @param bool $count_only Return only result count * * @return MetaRecord The record instance */ @@ -315,16 +315,14 @@ 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 $params The query params - * @param bool $count_only Return only result count + * @param array $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();