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 zoneclearFeedServer 2023.10.18
=========================================================== ===========================================================
* Require Dotclear 2.28 * Require Dotclear 2.28

View File

@ -1,7 +1,7 @@
# README # README
[![Release](https://img.shields.io/badge/release-2023.10.18-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases) [![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.10.18-c44d58.svg) ![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) [![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) [![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) [![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', 'Feeds server',
'Mix your blog with a feeds planet', 'Mix your blog with a feeds planet',
'Jean-Christian Denis, BG, Pierre Van Glabeke', 'Jean-Christian Denis, BG, Pierre Van Glabeke',
'2023.10.18', '2023.11.04',
[ [
'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="zoneclearFeedServer"> <module id="zoneclearFeedServer">
<name>Feeds server</name> <name>Feeds server</name>
<version>2023.10.18</version> <version>2023.11.04</version>
<author>Jean-Christian Denis, BG, Pierre Van Glabeke</author> <author>Jean-Christian Denis, BG, Pierre Van Glabeke</author>
<desc>Mix your blog with a feeds planet</desc> <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:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/zoneclearFeedServer/src/branch/master/README.md</da:details> <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> <da:support>https://git.dotclear.watch/JcDenis/zoneclearFeedServer/issues</da:support>

View File

@ -55,6 +55,8 @@ class BackendBehaviors
/** /**
* Lists columns user preference. * Lists columns user preference.
*
* @param ArrayObject<string, mixed> $cols
*/ */
public static function adminColumnsListsV2(ArrayObject $cols): void public static function adminColumnsListsV2(ArrayObject $cols): void
{ {
@ -83,6 +85,8 @@ class BackendBehaviors
/** /**
* Lists filter. * Lists filter.
*
* @param ArrayObject<string, mixed> $sorts
*/ */
public static function adminFiltersListsV2(ArrayObject $sorts): void public static function adminFiltersListsV2(ArrayObject $sorts): void
{ {
@ -106,14 +110,18 @@ class BackendBehaviors
/** /**
* Add head column to posts list. * Add head column to posts list.
*
* @param ArrayObject<string, mixed> $cols
*/ */
public static function adminPostListHeaderV2(MetaRecord $rs, ArrayObject $cols): void 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. * Add body column to posts list.
*
* @param ArrayObject<string, mixed> $cols
*/ */
public static function adminPostListValueV2(MetaRecord $rs, ArrayObject $cols): void public static function adminPostListValueV2(MetaRecord $rs, ArrayObject $cols): void
{ {
@ -140,6 +148,9 @@ class BackendBehaviors
/** /**
* Add info about feed on post page sidebar. * 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 public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void
{ {

View File

@ -28,7 +28,7 @@ use Exception;
class Combo class Combo
{ {
/** /**
* @return array<string,string> * @return array<string, string>
*/ */
public static function feedsSortby(): array public static function feedsSortby(): array
{ {
@ -42,7 +42,7 @@ class Combo
} }
/** /**
* @return array<string,string> * @return array<string, string>
*/ */
public static function postsSortby(): array public static function postsSortby(): array
{ {
@ -56,7 +56,7 @@ class Combo
} }
/** /**
* @return array<string,string> * @return array<string, string>
*/ */
public static function feedsStatus(): array public static function feedsStatus(): array
{ {
@ -67,7 +67,7 @@ class Combo
} }
/** /**
* @return array<string,int> * @return array<string, int>
*/ */
public static function postsStatus(): array public static function postsStatus(): array
{ {
@ -78,7 +78,7 @@ class Combo
} }
/** /**
* @return array<string,int> * @return array<string, int>
*/ */
public static function updateInterval(): array public static function updateInterval(): array
{ {
@ -93,7 +93,7 @@ class Combo
} }
/** /**
* @return array<string,int> * @return array<string, int>
*/ */
public static function tagCase(): array public static function tagCase(): array
{ {
@ -106,7 +106,7 @@ class Combo
} }
/** /**
* @return array<string,int> * @return array<string, int>
*/ */
public static function pubUpdate(): array public static function pubUpdate(): array
{ {
@ -119,7 +119,7 @@ class Combo
} }
/** /**
* @return array<string,string> * @return array<string, string>
*/ */
public static function postCategories(): array public static function postCategories(): array
{ {
@ -127,17 +127,16 @@ class Combo
try { try {
$categories = App::blog()->getCategories(['post_type' => 'post']); $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[ while ($categories->fetch()) {
str_repeat('&nbsp;&nbsp;', $level - 1) . $level = is_numeric($categories->f('level')) ? (int) $categories->f('level') : 1;
'&bull; ' . Html::escapeHTML($cat_title) $cat_title = is_string($categories->f('cat_title')) ? $categories->f('cat_title') : '';
] = $cat_id; $cat_id = is_numeric($categories->f('cat_id')) ? (string) $categories->f('cat_id') : '';
}
$combo[
str_repeat('&nbsp;&nbsp;', $level - 1) .
'&bull; ' . Html::escapeHTML($cat_title)
] = $cat_id;
} }
} catch (Exception $e) { } catch (Exception $e) {
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -30,10 +30,10 @@ class Settings
public readonly int $tag_case; public readonly int $tag_case;
/** @var array<int,string> */ /** @var array<int, string> */
public readonly array $post_full_tpl; public readonly array $post_full_tpl;
/** @var array<int,string> */ /** @var array<int, string> */
public readonly array $post_title_redir; public readonly array $post_title_redir;
public readonly string $user; public readonly string $user;
@ -90,7 +90,7 @@ class Settings
{ {
$s = My::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})); $s->put($key, $value, gettype($this->{$key}));
return true; return true;

View File

@ -19,6 +19,9 @@ use Dotclear\Helper\L10n;
*/ */
class Template class Template
{ {
/**
* @param ArrayObject<string, mixed> $a
*/
public static function Feeds(ArrayObject $a, string $c): string public static function Feeds(ArrayObject $a, string $c): string
{ {
$lastn = -1; $lastn = -1;
@ -84,6 +87,9 @@ class Template
'App::frontend()->context()->feeds = null; App::frontend()->context()->feeds_params = null; ?>'; '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 public static function FeedIf(ArrayObject $a, string $c): string
{ {
$if = []; $if = [];
@ -144,6 +150,9 @@ class Template
'<?php if(' . implode(' ' . $operator . ' ', $if) . ') : ?>' . $c . '<?php endif; ?>'; '<?php if(' . implode(' ' . $operator . ' ', $if) . ') : ?>' . $c . '<?php endif; ?>';
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedIfFirst(ArrayObject $a): string public static function FeedIfFirst(ArrayObject $a): string
{ {
$ret = Html::escapeHTML(isset($a['return']) && is_string($a['return']) ? $a['return'] : 'first'); $ret = Html::escapeHTML(isset($a['return']) && is_string($a['return']) ? $a['return'] : 'first');
@ -153,6 +162,9 @@ class Template
"echo '" . addslashes($ret) . "'; } ?>"; "echo '" . addslashes($ret) . "'; } ?>";
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedIfOdd(ArrayObject $a): string public static function FeedIfOdd(ArrayObject $a): string
{ {
$ret = Html::escapeHTML(isset($a['return']) && is_string($a['return']) ? $a['return'] : 'odd'); $ret = Html::escapeHTML(isset($a['return']) && is_string($a['return']) ? $a['return'] : 'odd');
@ -162,41 +174,65 @@ class Template
"echo '" . addslashes($ret) . "'; } ?>"; "echo '" . addslashes($ret) . "'; } ?>";
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedDesc(ArrayObject $a): string public static function FeedDesc(ArrayObject $a): string
{ {
return self::getValue($a, 'App::frontend()->context()->feeds->feed_desc'); return self::getValue($a, 'App::frontend()->context()->feeds->feed_desc');
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedOwner(ArrayObject $a): string public static function FeedOwner(ArrayObject $a): string
{ {
return self::getValue($a, 'App::frontend()->context()->feeds->feed_owner'); return self::getValue($a, 'App::frontend()->context()->feeds->feed_owner');
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedCategory(ArrayObject $a): string public static function FeedCategory(ArrayObject $a): string
{ {
return self::getValue($a, 'App::frontend()->context()->feeds->cat_title'); return self::getValue($a, 'App::frontend()->context()->feeds->cat_title');
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedCategoryID(ArrayObject $a): string public static function FeedCategoryID(ArrayObject $a): string
{ {
return self::getValue($a, 'App::frontend()->context()->feeds->cat_id'); return self::getValue($a, 'App::frontend()->context()->feeds->cat_id');
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedCategoryURL(ArrayObject $a): string 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)'); 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 public static function FeedCategoryShortURL(ArrayObject $a): string
{ {
return self::getValue($a, 'App::frontend()->context()->feeds->cat_url'); return self::getValue($a, 'App::frontend()->context()->feeds->cat_url');
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedID(ArrayObject $a): string public static function FeedID(ArrayObject $a): string
{ {
return self::getValue($a, 'App::frontend()->context()->feeds->feed_id'); return self::getValue($a, 'App::frontend()->context()->feeds->feed_id');
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedLang(ArrayObject $a): string public static function FeedLang(ArrayObject $a): string
{ {
return empty($a['full']) ? return empty($a['full']) ?
@ -208,31 +244,49 @@ class Template
'<?php ; } unset($langs); ?>'; '<?php ; } unset($langs); ?>';
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedName(ArrayObject $a): string public static function FeedName(ArrayObject $a): string
{ {
return self::getValue($a, 'App::frontend()->context()->feeds->feed_name'); return self::getValue($a, 'App::frontend()->context()->feeds->feed_name');
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedSiteURL(ArrayObject $a): string public static function FeedSiteURL(ArrayObject $a): string
{ {
return self::getValue($a, 'App::frontend()->context()->feeds->feed_url'); return self::getValue($a, 'App::frontend()->context()->feeds->feed_url');
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedFeedURL(ArrayObject $a): string public static function FeedFeedURL(ArrayObject $a): string
{ {
return self::getValue($a, 'App::frontend()->context()->feeds->feed_feed'); return self::getValue($a, 'App::frontend()->context()->feeds->feed_feed');
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedsHeader(ArrayObject $a, string $c): string public static function FeedsHeader(ArrayObject $a, string $c): string
{ {
return '<?php if (App::frontend()->context()->feeds->isStart()) : ?>' . $c . '<?php endif; ?>'; 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 public static function FeedsFooter(ArrayObject $a, string $c): string
{ {
return '<?php if (App::frontend()->context()->feeds->isEnd()) : ?>' . $c . '<?php endif; ?>'; return '<?php if (App::frontend()->context()->feeds->isEnd()) : ?>' . $c . '<?php endif; ?>';
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedsCount(ArrayObject $a): string public static function FeedsCount(ArrayObject $a): string
{ {
$none = isset($a['none']) && is_string($a['none']) ? addslashes($a['none']) : 'no sources'; $none = isset($a['none']) && is_string($a['none']) ? addslashes($a['none']) : 'no sources';
@ -250,6 +304,9 @@ class Template
'} unset($fcount); ?>'; '} unset($fcount); ?>';
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedsEntriesCount(ArrayObject $a): string public static function FeedsEntriesCount(ArrayObject $a): string
{ {
$none = isset($a['none']) && is_string($a['none']) ? addslashes($a['none']) : 'no entries'; $none = isset($a['none']) && is_string($a['none']) ? addslashes($a['none']) : 'no entries';
@ -274,6 +331,9 @@ class Template
'} unset($allfeeds,$fcount); ?>'; '} unset($allfeeds,$fcount); ?>';
} }
/**
* @param ArrayObject<string, mixed> $a
*/
public static function FeedEntriesCount(ArrayObject $a): string public static function FeedEntriesCount(ArrayObject $a): string
{ {
$none = isset($a['none']) && is_string($a['none']) ? addslashes($a['none']) : 'no entries'; $none = isset($a['none']) && is_string($a['none']) ? addslashes($a['none']) : 'no entries';
@ -292,8 +352,11 @@ class Template
'} unset($fcount); ?>'; '} unset($fcount); ?>';
} }
/**
* @param ArrayObject<string, mixed> $a
*/
protected static function getValue(ArrayObject $a, string $v): string 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 # Server js
} elseif ($args == '/zcfsupd.js' && 3 == $s->bhv_pub_upd) { } 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( self::serveDocument(
'zcfsupd.js', 'zcfsupd.js',
'text/javascript', 'text/javascript',
@ -84,13 +84,11 @@ class UrlHandler extends Url
if (!is_string($theme)) { if (!is_string($theme)) {
self::p404(); self::p404();
} }
$tplset = App::themes()->getDefine($theme)->get('tplset'); $tplset = App::themes()->getDefine(App::blog()->settings()->get('system')->get('theme'))->get('tplset');
$path = My::path() . '/default-templates/'; if (empty($tplset) || !is_dir(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]))) {
if (!empty($tplset) && is_dir($path . $tplset)) { $tplset = App::config()->defaultTplset();
App::frontend()->template()->setPath(App::frontend()->template()->getPath(), $path . $tplset);
} else {
App::frontend()->template()->setPath(App::frontend()->template()->getPath(), $path . App::config()->defaultTplset());
} }
App::frontend()->template()->appendPath(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]));
self::serveDocument('zcfeeds.html'); self::serveDocument('zcfeeds.html');
} }
# Unknow # Unknow

View File

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