Compare commits

..

No commits in common. "master" and "v2023.08.16" have entirely different histories.

33 changed files with 937 additions and 903 deletions

View File

@ -1,29 +1,3 @@
zoneclearFeedServer 2023.11.04
===========================================================
* Require Dotclear 2.28
* Require PHP 8.1
* Code review (phpstan)
zoneclearFeedServer 2023.10.18
===========================================================
* Require Dotclear 2.28
* Require PHP 8.1
* Upgrade plugin activityReport
zoneclearFeedServer 2023.10.14
===========================================================
* Require Dotclear 2.28
* Require PHP 8.1
* Upgrade to Dotclear 2.28
zoneclearFeedServer 2023.08.20
===========================================================
* Require Dotclear 2.27
* Require PHP 8.1
* Change settings to super admin only
* Fix get feed tags
* Fix per blog settings
zoneclearFeedServer 2023.08.16 zoneclearFeedServer 2023.08.16
=========================================================== ===========================================================
* Require Dotclear 2.27 * Require Dotclear 2.27

View File

@ -1,30 +1,33 @@
# README # README
[![Release](https://img.shields.io/badge/release-2023.11.04-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases) [![Release](https://img.shields.io/badge/release-2023.08.16-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases)
![Date](https://img.shields.io/badge/date-2023.11.04-c44d58.svg) [![Date](https://img.shields.io/badge/date-2023.08.16-c44d58.svg)](https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download) [![Dotclear](https://img.shields.io/badge/dotclear-v2.27-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-676e78.svg)](https://git.dotclear.watch/JcDenis/zoneclearFeedServer/blob/master/LICENSE)
## ABOUT ## WHAT IS ZONECLEARFEEDSERVER ?
_zoneclearFeedServer_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). "zoneclear Feeds server" is a plugin for the open-source
web publishing software called Dotclear.
> Mix your blog with a feeds planet It mix your blog with a feeds planet.
## REQUIREMENTS ## REQUIREMENTS
* Dotclear 2.28 _zoneclearFeedServer_ requires:
* super admin permission for plugin and services configuration
* admin permission to manage feeds
* Dotclear 2.27
* PHP 8.1 * PHP 8.1
* Dotclear super admin permissions for plugin and services configuration
* Dotclear admin permissions to manage feeds
## USAGE ## USAGE
First install _zoneclearFeedServer_, manualy from a zip package or from First install zoneclearFeedServer, manualy from a zip package or from
Dotaddict repository. (See Dotclear's documentation to know how do this) Dotaddict repository. (See Dotclear's documentation to know how do this)
Go to ''plugins manager'', expand ''Feed server'' information then Go to ''plugins manager'', expand _zoneclearFeedServer_ information then
go to ''configure plugin'', fill in form. go to ''configure plugin'', fill in form.
Once it's done you can manage your feeds from menu Once it's done you can manage your feeds from menu
@ -32,11 +35,10 @@ Once it's done you can manage your feeds from menu
## LINKS ## LINKS
* [License](https://git.dotclear.watch/JcDenis/zoneclearFeedServer/src/branch/master/LICENSE) * License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
* [Packages & details](https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/zoneclearFeedServer)) * Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/zoneclearFeedServer) or [GitHub Page](https://github.com/JcDenis/zoneclearFeedServer)
* [Sources & contributions](https://git.dotclear.watch/JcDenis/zoneclearFeedServer) (or on [GitHub](https://github.com/JcDenis/zoneclearFeedServer)) * Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/zoneclearFeedServer)
* [Issues & security](https://git.dotclear.watch/JcDenis/zoneclearFeedServer/issues) (or on [GitHub](https://github.com/JcDenis/zoneclearFeedServer/issues)) * Discussion & Help : [Dotclear Forum](http://forum.dotclear.org/viewtopic.php?pid=331158)
* [Discussion & Help](http://forum.dotclear.org/viewtopic.php?pid=331158)
## CONTRIBUTORS ## CONTRIBUTORS

View File

@ -1,28 +1,32 @@
<?php <?php
/** /**
* @file * @brief zoneclearFeedServer, a plugin for Dotclear 2
* @brief The plugin zoneclearFeedServer definition
* @ingroup zoneclearFeedServer
* *
* @defgroup zoneclearFeedServer Plugin zoneclearFeedServer. * @package Dotclear
* @subpackage Plugin
* *
* Mix your blog with a feeds planet. * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @author Jean-Christian Denis (author) * @copyright Jean-Christian Denis
* @author Pierre Van Glabeke
* @author BG
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
declare(strict_types=1); if (!defined('DC_RC_PATH')) {
return null;
}
$this->registerModule( $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.11.04', '2023.08.16',
[ [
'requires' => [['core', '2.28']], 'requires' => [
'permissions' => 'My', ['php', '8.1'],
['core', '2.27'],
],
'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]),
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',

20
_init.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
class initZoneclearFeedServer
{
public const TABLE_NAME = 'zc_feed';
}

View File

@ -5,8 +5,6 @@
# By Olivier Meunier and contributors # By Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license # Licensed under the GPL version 2.0 license
use Dotclear\App;
$opts = getopt('d:c:b:u:h'); $opts = getopt('d:c:b:u:h');
function zchelp(string|int $status = 0): void function zchelp(string|int $status = 0): void
@ -71,18 +69,18 @@ unset($blog_id);
require $dc_root . '/inc/prepend.php'; require $dc_root . '/inc/prepend.php';
unset($dc_root); unset($dc_root);
App::blog()->loadFromBlog(is_string(DC_BLOG_ID) ? DC_BLOG_ID : ''); dcCore::app()->setBlog(is_string(DC_BLOG_ID) ? DC_BLOG_ID : '');
if (!App::blog()->isDefined() || '' == App::blog()->id()) { if (is_null(dcCore::app()->blog) || dcCore::app()->blog->id == null) {
fwrite(STDERR, "Blog is not defined\n"); fwrite(STDERR, "Blog is not defined\n");
exit(1); exit(1);
} }
if (!isset($opts['u']) || !App::auth()->checkUser(is_string($opts['u']) ? $opts['u'] : '')) { if (!isset($opts['u']) || !dcCore::app()->auth->checkUser(is_string($opts['u']) ? $opts['u'] : '')) {
fwrite(STDERR, "Unable to set user\n"); fwrite(STDERR, "Unable to set user\n");
exit(1); exit(1);
} }
App::plugins()->loadModules(DC_PLUGINS_ROOT); dcCore::app()->plugins->loadModules(DC_PLUGINS_ROOT);
try { try {
$zc = Dotclear\Plugin\zoneclearFeedServer\ZoneclearFeedServer::instance(); $zc = Dotclear\Plugin\zoneclearFeedServer\ZoneclearFeedServer::instance();

View File

@ -2,11 +2,11 @@
<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.11.04</version> <version>2023.08.16</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.11.04/plugin-zoneclearFeedServer.zip</file> <file>https://git.dotclear.watch/JcDenis/zoneclearFeedServer/releases/download/v2023.08.16/plugin-zoneclearFeedServer.zip</file>
<da:dcmin>2.28</da:dcmin> <da:dcmin>2.27</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>
</module> </module>

View File

@ -1,11 +1,20 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Core\Process;
use Dotclear\Database\Cursor; use Dotclear\Database\Cursor;
use Dotclear\Plugin\activityReport\{ use Dotclear\Plugin\activityReport\{
Action, Action,
@ -14,27 +23,12 @@ use Dotclear\Plugin\activityReport\{
}; };
/** /**
* @brief zoneclearFeedServer plugin activityReport class.
* @ingroup zoneclearFeedServer
*
* Add feeds actions to the plugin activity report. * Add feeds actions to the plugin activity report.
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class ActivityReportAction extends Process class ActivityReportActions
{ {
public static function init(): bool public static function init(): void
{ {
return self::status(true);
}
public static function process(): bool
{
if (!self::status()) {
return false;
}
$group = new Group(My::id(), My::name()); $group = new Group(My::id(), My::name());
$group->add(new Action( $group->add(new Action(
@ -43,7 +37,7 @@ class ActivityReportAction extends Process
__('Feed named "%s" point to "%s" has been updated by "%s"'), __('Feed named "%s" point to "%s" has been updated by "%s"'),
'zoneclearFeedServerAfterUpdateFeed', 'zoneclearFeedServerAfterUpdateFeed',
function (Cursor $cur, int $id): void { function (Cursor $cur, int $id): void {
$user = App::auth()->getInfo('user_cn'); $user = dcCore::app()->auth->getInfo('user_cn');
if (!is_string($user)) { if (!is_string($user)) {
return; return;
} }
@ -70,7 +64,7 @@ class ActivityReportAction extends Process
__('A new feed named "%s" point to "%s" was added by "%s"'), __('A new feed named "%s" point to "%s" was added by "%s"'),
'zoneclearFeedServerAfterAddFeed', 'zoneclearFeedServerAfterAddFeed',
function (Cursor $cur, int $id): void { function (Cursor $cur, int $id): void {
$user = App::auth()->getInfo('user_cn'); $user = dcCore::app()->auth->getInfo('user_cn');
if (!is_string($user) if (!is_string($user)
|| !is_string($cur->getField('feed_name')) || !is_string($cur->getField('feed_name'))
|| !is_string($cur->getField('feed_feed')) || !is_string($cur->getField('feed_feed'))
@ -121,7 +115,7 @@ class ActivityReportAction extends Process
} }
$row = new FeedRow($rs); $row = new FeedRow($rs);
$user = App::auth()->getInfo('user_cn'); $user = dcCore::app()->auth->getInfo('user_cn');
if (!is_string($user)) { if (!is_string($user)) {
return; return;
} }
@ -151,7 +145,5 @@ class ActivityReportAction extends Process
)); ));
ActivityReport::instance()->groups->add($group); ActivityReport::instance()->groups->add($group);
return true;
} }
} }

View File

@ -1,18 +1,24 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/** /**
* @brief zoneclearFeedServer backend class. * Backend prepend.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Backend extends Process class Backend extends Process
{ {
@ -28,17 +34,19 @@ class Backend extends Process
} }
// behaviors that will be always loaded // behaviors that will be always loaded
App::behavior()->addBehaviors([ dcCore::app()->addBehaviors([
// Allways take care to delete related info about feed post in meta table // Allways take care to delete related info about feed post in meta table
'adminBeforePostDelete' => function (int $post_id): void { 'adminBeforePostDelete' => function (int $post_id): void {
ZoneclearFeedServer::instance()::deletePostsMeta($post_id); ZoneclearFeedServer::instance()::deletePostsMeta($post_id);
}, },
// widgets registration // widgets registration
'initWidgets' => Widgets::init(...), 'initWidgets' => [Widgets::class, 'init'],
// add Uninstaller cleaner for special direct action // add Uninstaller cleaner for special direct action
'UninstallerCleanersConstruct' => function ($uninstaller_stack) { 'UninstallerCleanersConstruct' => function ($uninstaller_stack) {
UninstallCleaner::init($uninstaller_stack); UninstallCleaner::init($uninstaller_stack);
}, },
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'],
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'],
]); ]);
// not active // not active
@ -55,14 +63,14 @@ class Backend extends Process
My::addBackendMenuItem(); My::addBackendMenuItem();
// behaviors that require user perm // behaviors that require user perm
App::behavior()->addBehaviors([ dcCore::app()->addBehaviors([
'adminDashboardFavoritesV2' => BackendBehaviors::adminDashboardFavoritesV2(...), 'adminDashboardFavoritesV2' => [BackendBehaviors::class, 'adminDashboardFavoritesV2'],
'adminColumnsListsV2' => BackendBehaviors::adminColumnsListsV2(...), 'adminColumnsListsV2' => [BackendBehaviors::class, 'adminColumnsListsV2'],
'adminFiltersListsV2' => BackendBehaviors::adminFiltersListsV2(...), 'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'],
'adminPostListHeaderV2' => BackendBehaviors::adminPostListHeaderV2(...), 'adminPostListHeaderV2' => [BackendBehaviors::class, 'adminPostListHeaderV2'],
'adminPostListValueV2' => BackendBehaviors::adminPostListValueV2(...), 'adminPostListValueV2' => [BackendBehaviors::class, 'adminPostListValueV2'],
'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...), 'adminPostHeaders' => [BackendBehaviors::class, 'adminPostHeaders'],
'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...), 'adminPostFormItems' => [BackendBehaviors::class, 'adminPostFormItems'],
]); ]);
return true; return true;

View File

@ -1,30 +1,232 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use ArrayObject; use ArrayObject;
use Dotclear\App; use dcCore;
use dcSettings;
use Dotclear\Core\Backend\Favorites; use Dotclear\Core\Backend\Favorites;
use Dotclear\Database\MetaRecord; use Dotclear\Database\MetaRecord;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox,
Div, Div,
Input,
Label,
Link, Link,
Number,
Para, Para,
Select,
Text Text
}; };
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
/** /**
* @brief zoneclearFeedServer backend behaviors class. * Backend behaviors.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class BackendBehaviors class BackendBehaviors
{ {
/**
* Module settings save.
*
* Used in blog settings and module config.
*/
public static function adminBeforeBlogSettingsUpdate(?dcSettings $blog_settings): void
{
// read settings
$s = ZoneclearFeedServer::instance()->settings;
// write settings
foreach ($s->dump() as $key => $value) {
$s->set($key, $_POST[My::id() . $key] ?? $value);
}
}
/**
* Module settings form.
*
* Used in blog settings and module config.
*/
public static function adminBlogPreferencesFormV2(?dcSettings $blog_settings): void
{
// nullsafe
if (is_null(dcCore::app()->blog)) {
return;
}
$z = ZoneclearFeedServer::instance();
$s = $z->settings;
$msg = [];
if (!is_writable(DC_TPL_CACHE)) {
$msg[] = (new Para())
->class('error')
->text(__('Dotclear cache is not writable or not well configured!'));
}
if ($s->pub_active) {
$msg[] = (new Para())
->items([
(new Link())
->class('onblog_link outgoing')
->text(__('View the public list of feeds') . ' <img alt="" src="images/outgoing-link.svg">')
->href(dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage')),
]);
}
$titles = [];
foreach ($z->getPublicUrlTypes() as $k => $v) {
$titles[] = (new Para(null, 'li'))
->items([
(new Checkbox([My::id() . 'post_title_redir[]', My::id() . 'post_title_redir_' . $v], in_array($v, $s->post_title_redir)))
->value($v),
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'post_title_redir_' . $v),
]);
}
$contents = [];
foreach ($z->getPublicUrlTypes() as $k => $v) {
$contents[] = (new Para(null, 'li'))
->items([
(new Checkbox([My::id() . 'post_full_tpl_[]', My::id() . 'post_full_tpl_' . $v], in_array($v, $s->post_full_tpl)))
->value($v),
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'post_full_tpl_' . $v),
]);
}
echo
(new Div())->class('fieldset')
->items([
!is_null($blog_settings) ?
(new Text('h4', My::name()))
->id('disclaimerParam') :
(new Text()),
(new Div())
->items($msg),
(new Para())
->items([
(new Checkbox(My::id() . 'active', $s->active))
->value(1),
(new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'active'),
]),
(new Div())
->class('clear two-cols')
->items([
(new Div())
->class('fieldset col')
->items([
(new Para())
->items([
(new Label(__('Status of new posts:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'post_status_new'),
(new Select(My::id() . 'post_status_new'))
->items(Combo::postsStatus())
->default((string) $s->post_status_new),
]),
(new Para())
->items([
(new Label(__('Owner of entries created by the feed server:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'user'),
(new Select(My::id() . 'user'))
->items($z->getAllBlogAdmins())
->default($s->user),
]),
(new Para())
->items([
(new Label(__('How to transform imported tags:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'tag_case'),
(new Select(My::id() . 'tag_case'))
->items(Combo::tagCase())
->default((string) $s->tag_case),
]),
]),
(new Div())
->class('fieldset col')
->items([
(new Para())
->items([
(new Label(__('Update feeds on public side:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'bhv_pub_upd'),
(new Select(My::id() . 'bhv_pub_upd'))
->items(Combo::pubUpdate())
->default((string) $s->bhv_pub_upd),
]),
(new Para())
->items([
(new Label(__('Number of feeds to update at one time:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'update_limit'),
(new Number(My::id() . 'update_limit'))
->min(0)
->max(20)
->value($s->update_limit),
]),
(new Para())
->items([
(new Checkbox(My::id() . 'keep_empty_feed', $s->keep_empty_feed))
->value(1),
(new Label(__('Keep active empty feeds'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'keep_empty_feed'),
]),
(new Para())
->items([
(new Checkbox(My::id() . 'pub_active', $s->pub_active))
->value(1),
(new Label(__('Enable public page'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'pub_active'),
]),
]),
]),
(new Div())
->class('two-cols')
->items([
(new Div())
->class('fieldset col')
->items([
(new Text('p', __('Redirect to original post on:'))),
(new Para(null, 'ul'))
->items($titles),
]),
(new Div())
->class('fieldset col')
->items([
(new Text('p', __('Show full content on:'))),
(new Para(null, 'ul'))
->items($contents),
]),
]),
(new Div())->class('clear')->items(
!is_null($blog_settings) && $s->active ?
[(new Para())
->items([
(new Link())
->href(My::managerUrl())
->text(__('Configure feeds')),
])] :
[],
),
(new Div())->class('clear'),
])
->render();
}
/** /**
* User dashboard favorites icon. * User dashboard favorites icon.
*/ */
@ -35,9 +237,9 @@ class BackendBehaviors
'url' => My::manageUrl(), 'url' => My::manageUrl(),
'small-icon' => My::icons(), 'small-icon' => My::icons(),
'large-icon' => My::icons(), 'large-icon' => My::icons(),
'permissions' => App::auth()->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
App::auth()::PERMISSION_USAGE, dcCore::app()->auth::PERMISSION_USAGE,
App::auth()::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), ]),
// update user dashboard favorites icon with nb of updated feeds // update user dashboard favorites icon with nb of updated feeds
'dashboard_cb' => function (ArrayObject $fav): void { 'dashboard_cb' => function (ArrayObject $fav): void {
@ -55,8 +257,6 @@ 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
{ {
@ -85,8 +285,6 @@ 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
{ {
@ -110,22 +308,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 Text('th', __('Feed')))->extra('scope="col"')->render(); $cols['feed'] = (new Para(null, 'th'))->text(__('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
{ {
$rs_meta = App::meta()->getMetadata(['post_id' => $rs->f('post_id'), 'meta_type' => My::META_PREFIX . 'id']); $rs_meta = dcCore::app()->meta->getMetadata(['post_id' => $rs->f('post_id'), 'meta_type' => My::META_PREFIX . 'id']);
if ($rs_meta->isEmpty()) { if ($rs_meta->isEmpty()) {
$item = (new Text('', '-')); $item = (new Text('', '-'));
} else { } else {
@ -148,14 +342,11 @@ 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
{ {
// nullsafe // nullsafe
if (!App::blog()->isDefined()) { if (is_null(dcCore::app()->blog)) {
return; return;
} }
@ -164,7 +355,7 @@ class BackendBehaviors
return; return;
} }
$url = App::meta()->getMetadata([ $url = dcCore::app()->meta->getMetadata([
'post_id' => $post->f('post_id'), 'post_id' => $post->f('post_id'),
'meta_type' => My::META_PREFIX . 'url', 'meta_type' => My::META_PREFIX . 'url',
'limit' => 1, 'limit' => 1,
@ -174,21 +365,21 @@ class BackendBehaviors
return; return;
} }
$author = App::meta()->getMetadata([ $author = dcCore::app()->meta->getMetadata([
'post_id' => $post->f('post_id'), 'post_id' => $post->f('post_id'),
'meta_type' => My::META_PREFIX . 'author', 'meta_type' => My::META_PREFIX . 'author',
'limit' => 1, 'limit' => 1,
]); ]);
$author = $author->isEmpty() ? '' : $author->f('meta_id'); $author = $author->isEmpty() ? '' : $author->f('meta_id');
$site = App::meta()->getMetadata([ $site = dcCore::app()->meta->getMetadata([
'post_id' => $post->f('post_id'), 'post_id' => $post->f('post_id'),
'meta_type' => My::META_PREFIX . 'site', 'meta_type' => My::META_PREFIX . 'site',
'limit' => 1, 'limit' => 1,
]); ]);
$site = $site->isEmpty() ? '' : $site->f('meta_id'); $site = $site->isEmpty() ? '' : $site->f('meta_id');
$sitename = App::meta()->getMetadata([ $sitename = dcCore::app()->meta->getMetadata([
'post_id' => $post->f('post_id'), 'post_id' => $post->f('post_id'),
'meta_type' => My::META_PREFIX . 'sitename', 'meta_type' => My::META_PREFIX . 'sitename',
'limit' => 1, 'limit' => 1,
@ -196,11 +387,11 @@ class BackendBehaviors
$sitename = $sitename->isEmpty() ? '' : $sitename->f('meta_id'); $sitename = $sitename->isEmpty() ? '' : $sitename->f('meta_id');
$edit = (new Text('', '')); $edit = (new Text('', ''));
if (App::auth()->check(App::auth()->makePermissions([ if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
App::auth()::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), App::blog()->id()) ]), dcCore::app()->blog->id)
) { ) {
$fid = App::meta()->getMetadata([ $fid = dcCore::app()->meta->getMetadata([
'post_id' => $post->f('post_id'), 'post_id' => $post->f('post_id'),
'meta_type' => My::META_PREFIX . 'id', 'meta_type' => My::META_PREFIX . 'id',
'limit' => 1, 'limit' => 1,

View File

@ -14,16 +14,12 @@ declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer backend combo helper. * Various combo list.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Combo class Combo
{ {
@ -126,8 +122,8 @@ class Combo
$combo = ['-' => '']; $combo = ['-' => ''];
try { try {
$categories = App::blog()->getCategories(['post_type' => 'post']); $categories = dcCore::app()->blog?->getCategories(['post_type' => 'post']);
if (!is_null($categories)) {
while ($categories->fetch()) { while ($categories->fetch()) {
$level = is_numeric($categories->f('level')) ? (int) $categories->f('level') : 1; $level = is_numeric($categories->f('level')) ? (int) $categories->f('level') : 1;
$cat_title = is_string($categories->f('cat_title')) ? $categories->f('cat_title') : ''; $cat_title = is_string($categories->f('cat_title')) ? $categories->f('cat_title') : '';
@ -138,6 +134,7 @@ class Combo
'&bull; ' . Html::escapeHTML($cat_title) '&bull; ' . Html::escapeHTML($cat_title)
] = $cat_id; ] = $cat_id;
} }
}
} catch (Exception $e) { } catch (Exception $e) {
} }

View File

@ -14,31 +14,17 @@ declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Core\Backend\{ use Dotclear\Core\Backend\{
Notices, Notices,
ModulesList, ModulesList,
Page Page
}; };
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Helper\Html\Form\{
Checkbox,
Div,
Label,
Link,
Number,
Para,
Select,
Text
};
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer config class. * Backend module configuration.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Config extends Process class Config extends Process
{ {
@ -59,30 +45,18 @@ class Config extends Process
} }
try { try {
// read settings BackendBehaviors::adminBeforeBlogSettingsUpdate(null);
$s = ZoneclearFeedServer::instance()->settings;
// write settings
foreach ($s->dump() as $key => $value) {
if (is_array($value) && empty($_POST[My::id() . $key])) {
$s->set($key, []);
} elseif (is_bool($value)) {
$s->set($key, !empty($_POST[My::id() . $key]));
} else {
$s->set($key, $_POST[My::id() . $key] ?: $value);
}
}
Notices::addSuccessNotice( Notices::addSuccessNotice(
__('Configuration has been successfully updated.') __('Configuration has been successfully updated.')
); );
App::backend()->url()->redirect('admin.plugins', [ dcCore::app()->admin->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' => !(dcCore::app()->admin->__get('list') instanceof ModulesList) ? '' : dcCore::app()->admin->__get('list')->getRedir(),
]); ]);
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
return true; return true;
@ -94,161 +68,7 @@ class Config extends Process
return; return;
} }
$z = ZoneclearFeedServer::instance(); BackendBehaviors::adminBlogPreferencesFormV2(null);
$s = $z->settings;
$msg = [];
if (!is_writable(App::config()->cacheRoot())) {
$msg[] = (new Text('p', __('Dotclear cache is not writable or not well configured!')))
->class('error');
}
if ($s->pub_active) {
$msg[] = (new Para())
->items([
(new Link())
->class('onblog_link outgoing')
->text(__('View the public list of feeds') . ' <img alt="" src="images/outgoing-link.svg">')
->href(App::blog()->url() . App::url()->getBase('zoneclearFeedsPage')),
]);
}
$titles = [];
foreach ($z->getPublicUrlTypes() as $k => $v) {
$titles[] = (new Para(null, 'li'))
->items([
(new Checkbox([My::id() . 'post_title_redir[]', My::id() . 'post_title_redir_' . $v], in_array($v, $s->post_title_redir)))
->value($v),
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'post_title_redir_' . $v),
]);
}
$contents = [];
foreach ($z->getPublicUrlTypes() as $k => $v) {
$contents[] = (new Para(null, 'li'))
->items([
(new Checkbox([My::id() . 'post_full_tpl[]', My::id() . 'post_full_tpl_' . $v], in_array($v, $s->post_full_tpl)))
->value($v),
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'post_full_tpl_' . $v),
]);
}
echo
(new Div())
->items([
(new Div())
->items($msg),
(new Para())
->items([
(new Checkbox(My::id() . 'active', $s->active))
->value(1),
(new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'active'),
]),
(new Div())
->class('clear two-cols')
->items([
(new Div())
->class('fieldset col')
->items([
(new Para())
->items([
(new Label(__('Status of new posts:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'post_status_new'),
(new Select(My::id() . 'post_status_new'))
->items(Combo::postsStatus())
->default((string) $s->post_status_new),
]),
(new Para())
->items([
(new Label(__('Owner of entries created by the feed server:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'user'),
(new Select(My::id() . 'user'))
->items($z->getAllBlogAdmins())
->default($s->user),
]),
(new Para())
->items([
(new Label(__('How to transform imported tags:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'tag_case'),
(new Select(My::id() . 'tag_case'))
->items(Combo::tagCase())
->default((string) $s->tag_case),
]),
]),
(new Div())
->class('fieldset col')
->items([
(new Para())
->items([
(new Label(__('Update feeds on public side:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'bhv_pub_upd'),
(new Select(My::id() . 'bhv_pub_upd'))
->items(Combo::pubUpdate())
->default((string) $s->bhv_pub_upd),
]),
(new Para())
->items([
(new Label(__('Number of feeds to update at one time:'), Label::OUTSIDE_LABEL_BEFORE))
->for(My::id() . 'update_limit'),
(new Number(My::id() . 'update_limit'))
->min(0)
->max(20)
->value($s->update_limit),
]),
(new Para())
->items([
(new Checkbox(My::id() . 'keep_empty_feed', $s->keep_empty_feed))
->value(1),
(new Label(__('Keep active empty feeds'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'keep_empty_feed'),
]),
(new Para())
->items([
(new Checkbox(My::id() . 'pub_active', $s->pub_active))
->value(1),
(new Label(__('Enable public page'), Label::OUTSIDE_LABEL_AFTER))
->class('classic')
->for(My::id() . 'pub_active'),
]),
]),
]),
(new Div())
->class('two-cols')
->items([
(new Div())
->class('fieldset col')
->items([
(new Text('p', __('Redirect to original post on:'))),
(new Para(null, 'ul'))
->items($titles),
]),
(new Div())
->class('fieldset col')
->items([
(new Text('p', __('Show full content on:'))),
(new Para(null, 'ul'))
->items($contents),
]),
]),
(new Div())->class('clear')->items(
$s->active ?
[(new Para())
->items([
(new Link())
->href(My::manageUrl())
->text(__('Configure feeds')),
])] :
[],
),
(new Div())->class('clear'),
])
->render();
Page::helpBlock('zoneclearFeedServer'); Page::helpBlock('zoneclearFeedServer');
} }

View File

@ -17,11 +17,7 @@ namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\Database\MetaRecord; use Dotclear\Database\MetaRecord;
/** /**
* @brief zoneclearFeedServer feed meta record row. * Feed meta record row type hinting.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class FeedRow class FeedRow
{ {

View File

@ -1,11 +1,21 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use ArrayObject; use ArrayObject;
use Dotclear\App; use dcCore;
use Dotclear\Core\Backend\Action\Actions; use Dotclear\Core\Backend\Action\Actions;
use Dotclear\Core\Backend\Page; use Dotclear\Core\Backend\Page;
use Dotclear\Database\MetaRecord; use Dotclear\Database\MetaRecord;
@ -17,11 +27,7 @@ use Dotclear\Helper\Html\Html;
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer feeds list actions. * Backend feeds list actions handler.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class FeedsActions extends Actions class FeedsActions extends Actions
{ {
@ -50,7 +56,7 @@ class FeedsActions extends Actions
FeedsDefaultActions::addDefaultFeedsActions($this); FeedsDefaultActions::addDefaultFeedsActions($this);
# --BEHAVIOR-- zoneclearFeedServerAddFeedsActions - FeedsActions # --BEHAVIOR-- zoneclearFeedServerAddFeedsActions - FeedsActions
App::behavior()->callBehavior('zoneclearFeedServerAddFeedsActions', $this); dcCore::app()->callBehavior('zoneclearFeedServerAddFeedsActions', $this);
} }
public function beginPage(string $breadcrumb = '', string $head = ''): void public function beginPage(string $breadcrumb = '', string $head = ''): void
@ -77,10 +83,10 @@ class FeedsActions extends Actions
public function error(Exception $e): void public function error(Exception $e): void
{ {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
$this->beginPage( $this->beginPage(
Page::breadcrumb([ Page::breadcrumb([
Html::escapeHTML(App::blog()->name()) => '', Html::escapeHTML((string) dcCore::app()->blog?->name) => '',
$this->getCallerTitle() => $this->getRedirection(true), $this->getCallerTitle() => $this->getRedirection(true),
__('Feeds actions') => '', __('Feeds actions') => '',
]) ])
@ -98,7 +104,7 @@ 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[(string) $row->id] = $row->name; $this->entries[$row->id] = $row->name;
} }
$this->rs = $feeds; $this->rs = $feeds;
} else { } else {

View File

@ -1,11 +1,22 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use ArrayObject; use ArrayObject;
use Dotclear\App; use dcCore;
use dcMeta;
use Dotclear\Core\Backend\{ use Dotclear\Core\Backend\{
Notices, Notices,
Page Page
@ -24,11 +35,7 @@ use Dotclear\Helper\Html\Html;
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer feeds list default actions. * Backend feeds list default actions.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class FeedsDefaultActions class FeedsDefaultActions
{ {
@ -39,42 +46,40 @@ class FeedsDefaultActions
{ {
$ap->addAction( $ap->addAction(
[__('Change category') => 'changecat'], [__('Change category') => 'changecat'],
self::doChangeCategory(...) [self::class, 'doChangeCategory']
); );
$ap->addAction( $ap->addAction(
[__('Change update interval') => 'changeint'], [__('Change update interval') => 'changeint'],
self::doChangeInterval(...) [self::class, 'doChangeInterval']
); );
$ap->addAction( $ap->addAction(
[__('Disable feed update') => 'disablefeed'], [__('Disable feed update') => 'disablefeed'],
self::doEnableFeed(...) [self::class, 'doEnableFeed']
); );
$ap->addAction( $ap->addAction(
[__('Enable feed update') => 'enablefeed'], [__('Enable feed update') => 'enablefeed'],
self::doEnableFeed(...) [self::class, 'doEnableFeed']
); );
$ap->addAction( $ap->addAction(
[__('Reset last update') => 'resetupdlast'], [__('Reset last update') => 'resetupdlast'],
self::doResetUpdate(...) [self::class, 'doResetUpdate']
); );
$ap->addAction( $ap->addAction(
[__('Update (check) feed') => 'updatefeed'], [__('Update (check) feed') => 'updatefeed'],
self::doUpdateFeed(...) [self::class, 'doUpdateFeed']
); );
$ap->addAction( $ap->addAction(
[__('Delete related posts') => 'deletepost'], [__('Delete related posts') => 'deletepost'],
self::doDeletePost(...) [self::class, 'doDeletePost']
); );
$ap->addAction( $ap->addAction(
[__('Delete feed (without related posts)') => 'deletefeed'], [__('Delete feed (without related posts)') => 'deletefeed'],
self::doDeleteFeed(...) [self::class, 'doDeleteFeed']
); );
} }
/** /**
* 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
{ {
@ -88,7 +93,7 @@ class FeedsDefaultActions
} }
foreach ($ids as $id) { foreach ($ids as $id) {
$ap->zcfs->enableFeed((int) $id, $enable); $ap->zcfs->enableFeed($id, $enable);
} }
Notices::addSuccessNotice(sprintf( Notices::addSuccessNotice(sprintf(
@ -111,8 +116,6 @@ 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
{ {
@ -139,10 +142,10 @@ class FeedsDefaultActions
while ($posts->fetch()) { while ($posts->fetch()) {
if (is_numeric($posts->f('post_id'))) { if (is_numeric($posts->f('post_id'))) {
App::blog()->delPost((int) $posts->f('post_id')); dcCore::app()->blog?->delPost((int) $posts->f('post_id'));
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql $sql
->from(App::con()->prefix() . App::meta()::META_TABLE_NAME) ->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME)
->where('post_id = ' . $posts->f('post_id')) ->where('post_id = ' . $posts->f('post_id'))
->and('meta_type ' . $sql->in($types)) ->and('meta_type ' . $sql->in($types))
->delete(); ->delete();
@ -158,8 +161,6 @@ 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
{ {
@ -172,7 +173,7 @@ class FeedsDefaultActions
} }
foreach ($ids as $id) { foreach ($ids as $id) {
$ap->zcfs->deleteFeed((int) $id); $ap->zcfs->deleteFeed($id);
} }
Notices::addSuccessNotice(sprintf( Notices::addSuccessNotice(sprintf(
@ -188,8 +189,6 @@ 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
{ {
@ -202,7 +201,7 @@ class FeedsDefaultActions
} }
foreach ($ids as $id) { foreach ($ids as $id) {
$ap->zcfs->checkFeedsUpdate((int) $id, true); $ap->zcfs->checkFeedsUpdate($id, true);
} }
Notices::addSuccessNotice(sprintf( Notices::addSuccessNotice(sprintf(
@ -214,8 +213,6 @@ 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
{ {
@ -231,7 +228,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((int) $id, $cur); $ap->zcfs->updateFeed($id, $cur);
//$ap->zcfs->checkFeedsUpdate($id, true); //$ap->zcfs->checkFeedsUpdate($id, true);
} }
@ -244,8 +241,6 @@ 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
{ {
@ -264,7 +259,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((int) $id, $cur); $ap->zcfs->updateFeed($id, $cur);
} }
Notices::addSuccessNotice(sprintf( Notices::addSuccessNotice(sprintf(
@ -275,7 +270,7 @@ class FeedsDefaultActions
} else { } else {
$ap->beginPage( $ap->beginPage(
Page::breadcrumb([ Page::breadcrumb([
Html::escapeHTML(App::blog()->name()) => '', Html::escapeHTML((string) dcCore::app()->blog?->name) => '',
__('Feeds server') => '', __('Feeds server') => '',
$ap->getCallerTitle() => $ap->getRedirection(true), $ap->getCallerTitle() => $ap->getRedirection(true),
__('Change category for this selection') => '', __('Change category for this selection') => '',
@ -299,7 +294,7 @@ class FeedsDefaultActions
(new Submit('do-action')) (new Submit('do-action'))
->value(__('Save')), ->value(__('Save')),
(new Hidden(['action'], 'changecat')), (new Hidden(['action'], 'changecat')),
App::nonce()->formNonce(), dcCore::app()->formNonce(false),
] ]
)), )),
@ -312,8 +307,6 @@ 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
{ {
@ -332,7 +325,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((int) $id, $cur); $ap->zcfs->updateFeed($id, $cur);
} }
Notices::addSuccessNotice(sprintf( Notices::addSuccessNotice(sprintf(
@ -344,7 +337,7 @@ class FeedsDefaultActions
$ap->beginPage( $ap->beginPage(
Page::breadcrumb( Page::breadcrumb(
[ [
Html::escapeHTML(App::blog()->name()) => '', Html::escapeHTML((string) dcCore::app()->blog?->name) => '',
__('Feeds server') => '', __('Feeds server') => '',
$ap->getCallerTitle() => $ap->getRedirection(true), $ap->getCallerTitle() => $ap->getRedirection(true),
__('Change update frequency for this selection') => '', __('Change update frequency for this selection') => '',
@ -369,7 +362,7 @@ class FeedsDefaultActions
(new Submit('do-action')) (new Submit('do-action'))
->value(__('Save')), ->value(__('Save')),
(new Hidden(['action'], 'changeint')), (new Hidden(['action'], 'changeint')),
App::nonce()->formNonce(), dcCore::app()->formNonce(false),
] ]
)), )),

View File

@ -1,11 +1,21 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use ArrayObject; use ArrayObject;
use Dotclear\App; use dcCore;
use Dotclear\Core\Backend\Filter\Filters; use Dotclear\Core\Backend\Filter\Filters;
use Dotclear\Core\Backend\Listing\{ use Dotclear\Core\Backend\Listing\{
Listing, Listing,
@ -22,11 +32,7 @@ use Dotclear\Helper\Html\Form\{
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
/** /**
* @brief zoneclearFeedServer backend feeds list. * Backend feeds list.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class FeedsList extends Listing class FeedsList extends Listing
{ {
@ -120,7 +126,7 @@ class FeedsList extends Listing
if (!is_string($url)) { if (!is_string($url)) {
$url = ''; $url = '';
} }
$tz = App::auth()->getInfo('user_tz'); $tz = dcCore::app()->auth->getInfo('user_tz');
if (!is_string($tz)) { if (!is_string($tz)) {
$tz = 'UTC'; $tz = 'UTC';
} }

View File

@ -1,21 +1,28 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use dcUtils;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Database\MetaRecord; use Dotclear\Database\MetaRecord;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer frontend class. * Frontend prepend.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Frontend extends Process class Frontend extends Process
{ {
@ -32,7 +39,7 @@ class Frontend extends Process
$s = ZoneclearFeedServer::instance()->settings; $s = ZoneclearFeedServer::instance()->settings;
App::behavior()->addBehaviors([ dcCore::app()->addBehaviors([
// posts record // posts record
'coreBlogGetPosts' => function (MetaRecord $rs): void { 'coreBlogGetPosts' => function (MetaRecord $rs): void {
RsExtPosts::$brother_extensions = $rs->extensions(); RsExtPosts::$brother_extensions = $rs->extensions();
@ -43,17 +50,17 @@ class Frontend extends Process
return $context == 'zoneclearFeedsPage' ? __('List of feeds') : ''; return $context == 'zoneclearFeedsPage' ? __('List of feeds') : '';
}, },
// widgets registration // widgets registration
'initWidgets' => Widgets::init(...), 'initWidgets' => [Widgets::class, 'init'],
]); ]);
// Register template blocks // Register template blocks
foreach (My::TPL_BLOCKS as $block) { foreach (My::TPL_BLOCKS as $block) {
App::frontend()->template()->addBlock('zc' . $block, [Template::class, $block]); dcCore::app()->tpl->addBlock('zc' . $block, [Template::class, $block]);
} }
// Register template values // Register template values
foreach (My::TPL_VALUES as $value) { foreach (My::TPL_VALUES as $value) {
App::frontend()->template()->addValue('zc' . $value, [Template::class, $value]); dcCore::app()->tpl->addValue('zc' . $value, [Template::class, $value]);
} }
// module not active // module not active
@ -63,8 +70,8 @@ class Frontend extends Process
// feeds update methods // feeds update methods
if (1 == $s->bhv_pub_upd) { if (1 == $s->bhv_pub_upd) {
App::behavior()->addBehavior('publicBeforeDocumentV2', function (): void { dcCore::app()->addBehavior('publicBeforeDocumentV2', function (): void {
if (in_array(App::url()->type, ['default', 'feed'])) { if (in_array(dcCore::app()->url->type, ['default', 'feed'])) {
try { try {
ZoneclearFeedServer::instance()->checkFeedsUpdate(); ZoneclearFeedServer::instance()->checkFeedsUpdate();
} catch (Exception $e) { } catch (Exception $e) {
@ -72,28 +79,28 @@ class Frontend extends Process
}; };
}); });
} elseif (2 == $s->bhv_pub_upd) { } elseif (2 == $s->bhv_pub_upd) {
App::behavior()->addBehavior('publicAfterDocumentV2', function (): void { dcCore::app()->addBehavior('publicAfterDocumentV2', function (): void {
try { try {
ZoneclearFeedServer::instance()->checkFeedsUpdate(); ZoneclearFeedServer::instance()->checkFeedsUpdate();
} catch (Exception $e) { } catch (Exception $e) {
} }
}); });
} elseif (3 == $s->bhv_pub_upd) { } elseif (3 == $s->bhv_pub_upd) {
App::behavior()->addBehavior('publicHeadContent', function (): void { dcCore::app()->addBehavior('publicHeadContent', function (): void {
if (!App::blog()->isDefined() || App::url()->type != 'default') { if (is_null(dcCore::app()->blog) || dcCore::app()->url->type != 'default') {
return; return;
} }
$blog_url = Html::escapeJS( $blog_url = Html::escapeJS(
App::blog()->url() . dcCore::app()->blog->url .
App::url()->getBase('zoneclearFeedsPage') . dcCore::app()->url->getBase('zoneclearFeedsPage') .
'/zcfsupd' '/zcfsupd'
); );
$blog_id = Html::escapeJS(App::blog()->id()); $blog_id = Html::escapeJS(dcCore::app()->blog->id);
echo echo
"\n<!-- JS for zoneclearFeedServer --> \n" . "\n<!-- JS for zoneclearFeedServer --> \n" .
App::plugins()->jsLoad(App::blog()->url() . App::url()->getBase('zoneclearFeedsPage') . '/zcfsupd.js') . dcUtils::jsLoad(dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage') . '/zcfsupd.js') .
"<script type=\"text/javascript\"> \n//<![CDATA[\n" . "<script type=\"text/javascript\"> \n//<![CDATA[\n" .
' $(function(){if(!document.getElementById){return;} ' . ' $(function(){if(!document.getElementById){return;} ' .
" $('body').zoneclearFeedServer({blog_url:'" . " $('body').zoneclearFeedServer({blog_url:'" .

View File

@ -1,20 +1,26 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Database\Structure; use Dotclear\Database\Structure;
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer install class. * Module installation.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Install extends Process class Install extends Process
{ {
@ -34,7 +40,7 @@ class Install extends Process
Upgrade::preUpgrade(); Upgrade::preUpgrade();
// Tables // Tables
$s = new Structure(App::con(), App::con()->prefix()); $s = new Structure(dcCore::app()->con, dcCore::app()->prefix);
$s->__get(My::TABLE_NAME) $s->__get(My::TABLE_NAME)
->field('feed_id', 'bigint', 0, false) ->field('feed_id', 'bigint', 0, false)
->field('feed_creadt', 'timestamp', 0, false, 'now()') ->field('feed_creadt', 'timestamp', 0, false, 'now()')
@ -61,7 +67,7 @@ class Install extends Process
->index('idx_zcfs_type', 'btree', 'feed_type') ->index('idx_zcfs_type', 'btree', 'feed_type')
->index('idx_zcfs_blog', 'btree', 'blog_id'); ->index('idx_zcfs_blog', 'btree', 'blog_id');
(new Structure(App::con(), App::con()->prefix()))->synchronize($s); (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
// Settings // Settings
$s = My::settings(); $s = My::settings();
@ -78,7 +84,7 @@ class Install extends Process
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
return false; return false;
} }

View File

@ -1,10 +1,20 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Core\Backend\Filter\{ use Dotclear\Core\Backend\Filter\{
Filters, Filters,
FiltersLibrary FiltersLibrary
@ -27,11 +37,7 @@ use Dotclear\Helper\Html\Form\{
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer backend feeds manage class. * Backend feeds list manage page.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Manage extends Process class Manage extends Process
{ {
@ -58,7 +64,7 @@ class Manage extends Process
// not configured // not configured
if (!$s->active || !$s->user) { if (!$s->active || !$s->user) {
App::error()->add(__('Module is not wel configured')); dcCore::app()->error->add(__('Module is not wel configured'));
return true; return true;
} }
@ -125,13 +131,13 @@ class Manage extends Process
$feeds_counter = $z->getFeeds($params, true)->f(0); $feeds_counter = $z->getFeeds($params, true)->f(0);
$feeds_list = new FeedsList($feeds, $feeds_counter); $feeds_list = new FeedsList($feeds, $feeds_counter);
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
Page::openModule( Page::openModule(
My::id(), My::id(),
( (
isset($feeds_list) && !App::error()->flag() ? isset($feeds_list) && !dcCore::app()->error->flag() ?
$feeds_filter->js(My::manageUrl(['part' => 'feeds'], '&')) . $feeds_filter->js(My::manageUrl(['part' => 'feeds'], '&')) .
My::jsLoad('feeds') My::jsLoad('feeds')
: '' : ''
@ -182,7 +188,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

@ -1,10 +1,20 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Core\Backend\Action\ActionsPosts; use Dotclear\Core\Backend\Action\ActionsPosts;
use Dotclear\Core\Backend\{ use Dotclear\Core\Backend\{
Notices, Notices,
@ -28,11 +38,7 @@ use Dotclear\Helper\L10n;
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer backend feeds posts manage class. * Backend feed and feed posts manage page.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class ManageFeed extends Process class ManageFeed extends Process
{ {
@ -64,26 +70,26 @@ class ManageFeed extends Process
$testfeed_params['sql'] = 'AND feed_id <> ' . $v->id . ' '; $testfeed_params['sql'] = 'AND feed_id <> ' . $v->id . ' ';
} }
if ($z->getFeeds($testfeed_params, true)->f(0)) { if ($z->getFeeds($testfeed_params, true)->f(0)) {
App::error()->add(__('Record with same feed URL already exists.')); dcCore::app()->error->add(__('Record with same feed URL already exists.'));
} }
if (empty($v->name)) { if (empty($v->name)) {
App::error()->add(__('You must provide a name.')); dcCore::app()->error->add(__('You must provide a name.'));
} }
if (empty($v->owner)) { if (empty($v->owner)) {
App::error()->add(__('You must provide an owner.')); dcCore::app()->error->add(__('You must provide an owner.'));
} }
if (!$z::validateURL($v->url)) { if (!$z::validateURL($v->url)) {
App::error()->add(__('You must provide valid site URL.')); dcCore::app()->error->add(__('You must provide valid site URL.'));
} }
if (!$z::validateURL($v->feed)) { if (!$z::validateURL($v->feed)) {
App::error()->add(__('You must provide valid feed URL.')); dcCore::app()->error->add(__('You must provide valid feed URL.'));
} }
if (null !== $v->cat_id && !App::blog()->getCategory($v->cat_id)) { if (null !== $v->cat_id && !dcCore::app()->blog?->getCategory($v->cat_id)) {
App::error()->add(__('You must provide valid category.')); dcCore::app()->error->add(__('You must provide valid category.'));
} }
// check failed // check failed
if (App::error()->flag()) { if (dcCore::app()->error->flag()) {
return true; return true;
} }
@ -97,7 +103,7 @@ class ManageFeed extends Process
Notices::addSuccessNotice(__('Feed successfully created.')); Notices::addSuccessNotice(__('Feed successfully created.'));
My::redirect(['part' => 'feed', 'feed_id' => $id]); My::redirect(['part' => 'feed', 'feed_id' => $id]);
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
return true; return true;
} }
@ -152,13 +158,13 @@ class ManageFeed extends Process
'user_id' => 'P.user_id', ]; 'user_id' => 'P.user_id', ];
# --BEHAVIOR-- adminPostsSortbyLexCombo # --BEHAVIOR-- adminPostsSortbyLexCombo
App::behavior()->callBehavior('adminPostsSortbyLexCombo', [& $sortby_lex]); dcCore::app()->callBehavior('adminPostsSortbyLexCombo', [& $sortby_lex]);
$params['no_content'] = true; $params['no_content'] = true;
$params['feed_id'] = $v->id; $params['feed_id'] = $v->id;
$params['order'] = ( $params['order'] = (
array_key_exists($sortby, $sortby_lex) ? array_key_exists($sortby, $sortby_lex) ?
App::con()->lexFields($sortby_lex[$sortby]) : dcCore::app()->con->lexFields($sortby_lex[$sortby]) :
$sortby $sortby
) . ' ' . $order; ) . ' ' . $order;
@ -168,7 +174,7 @@ class ManageFeed extends Process
$counter = $z->getPostsByFeed($params, true); $counter = $z->getPostsByFeed($params, true);
$post_list = new PostsList($posts, $counter->f(0)); $post_list = new PostsList($posts, $counter->f(0));
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
@ -176,7 +182,7 @@ class ManageFeed extends Process
Page::openModule( Page::openModule(
My::id(), My::id(),
( (
$v->id && isset($post_filter) && !App::error()->flag() ? $v->id && isset($post_filter) && !dcCore::app()->error->flag() ?
$post_filter->js(My::manageUrl(['part' => 'feed', 'feed_id' => $v->id], '&') . '#entries') . $post_filter->js(My::manageUrl(['part' => 'feed', 'feed_id' => $v->id], '&') . '#entries') .
My::jsLoad('feed') My::jsLoad('feed')
: '' : ''
@ -235,7 +241,7 @@ class ManageFeed extends Process
(new Input('feed_name')) (new Input('feed_name'))
->class('maximal') ->class('maximal')
->size(60) ->size(60)
->maxlength(255) ->maxlenght(255)
->value($v->name), ->value($v->name),
]), ]),
// feed_owner // feed_owner
@ -247,7 +253,7 @@ class ManageFeed extends Process
(new Input('feed_owner')) (new Input('feed_owner'))
->class('maximal') ->class('maximal')
->size(60) ->size(60)
->maxlength(255) ->maxlenght(255)
->value($v->owner), ->value($v->owner),
]), ]),
// feed_url // feed_url
@ -259,7 +265,7 @@ class ManageFeed extends Process
(new Input('feed_url')) (new Input('feed_url'))
->class('maximal') ->class('maximal')
->size(60) ->size(60)
->maxlength(255) ->maxlenght(255)
->value($v->url), ->value($v->url),
]), ]),
// feed_feed // feed_feed
@ -271,7 +277,7 @@ class ManageFeed extends Process
(new Input('feed_feed')) (new Input('feed_feed'))
->class('maximal') ->class('maximal')
->size(60) ->size(60)
->maxlength(255) ->maxlenght(255)
->value($v->feed), ->value($v->feed),
]), ]),
// feed_desc // feed_desc
@ -282,7 +288,7 @@ class ManageFeed extends Process
(new Input('feed_desc')) (new Input('feed_desc'))
->class('maximal') ->class('maximal')
->size(60) ->size(60)
->maxlength(255) ->maxlenght(255)
->value($v->desc), ->value($v->desc),
]), ]),
// feed_tags // feed_tags
@ -293,7 +299,7 @@ class ManageFeed extends Process
(new Input('feed_tags')) (new Input('feed_tags'))
->class('maximal') ->class('maximal')
->size(60) ->size(60)
->maxlength(255) ->maxlenght(255)
->value($v->tags), ->value($v->tags),
]), ]),
// feed_tweeter // feed_tweeter
@ -304,7 +310,7 @@ class ManageFeed extends Process
(new Input('feed_tweeter')) (new Input('feed_tweeter'))
->class('maximal') ->class('maximal')
->size(60) ->size(60)
->maxlength(255) ->maxlenght(255)
->value($v->tweeter), ->value($v->tweeter),
]), ]),
]), ]),
@ -379,7 +385,7 @@ class ManageFeed extends Process
->render(); ->render();
} }
if ($v->id && $v->can_view_page && isset($post_filter) && isset($post_list) && isset($posts_actions_page) && !App::error()->flag()) { if ($v->id && $v->can_view_page && isset($post_filter) && isset($post_list) && isset($posts_actions_page) && !dcCore::app()->error->flag()) {
echo '<div class="multi-part" title="' . __('Entries') . '" id="entries">'; echo '<div class="multi-part" title="' . __('Entries') . '" id="entries">';
# show posts filters # show posts filters
@ -417,7 +423,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

@ -1,18 +1,24 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
/** /**
* @brief zoneclearFeedServer backend vars definition. * Backend feed manage page vars (type hinting).
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class ManageFeedVars class ManageFeedVars
{ {
@ -46,9 +52,9 @@ class ManageFeedVars
{ {
$z = ZoneclearFeedServer::instance(); $z = ZoneclearFeedServer::instance();
$feed_headlink = '<link rel="%s" title="%s" href="' . App::backend()->getPageURL() . '&amp;part=feed&amp;feed_id=%s" />'; $feed_headlink = '<link rel="%s" title="%s" href="' . dcCore::app()->admin->getPageURL() . '&amp;part=feed&amp;feed_id=%s" />';
$feed_link = '<a href="' . App::backend()->getPageURL() . '&amp;part=feed&amp;feed_id=%s" title="%s">%s</a>'; $feed_link = '<a href="' . dcCore::app()->admin->getPageURL() . '&amp;part=feed&amp;feed_id=%s" title="%s">%s</a>';
$lang = App::auth()->getInfo('user_lang'); $lang = dcCore::app()->auth->getInfo('user_lang');
// default values // default values
$feed_id = 0; $feed_id = 0;
@ -76,7 +82,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()) {
App::error()->add(__('This feed does not exist.')); dcCore::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);
@ -150,7 +156,7 @@ class ManageFeedVars
$feed_feed = !empty($_POST['feed_feed']) && is_string($_POST['feed_feed']) ? $_POST['feed_feed'] : $feed_feed; $feed_feed = !empty($_POST['feed_feed']) && is_string($_POST['feed_feed']) ? $_POST['feed_feed'] : $feed_feed;
$feed_lang = !empty($_POST['feed_lang']) && is_string($_POST['feed_lang']) ? $_POST['feed_lang'] : $feed_lang; $feed_lang = !empty($_POST['feed_lang']) && is_string($_POST['feed_lang']) ? $_POST['feed_lang'] : $feed_lang;
$feed_tags = !empty($_POST['feed_tags']) && is_string($_POST['feed_tags']) ? $_POST['feed_tags'] : $feed_tags; $feed_tags = !empty($_POST['feed_tags']) && is_string($_POST['feed_tags']) ? $_POST['feed_tags'] : $feed_tags;
$feed_get_tags = !empty($_POST['feed_get_tags']); $feed_get_tags = empty($_POST['feed_get_tags']) ? $feed_get_tags : true;
$feed_cat_id = !empty($_POST['feed_cat_id']) && is_numeric($_POST['feed_cat_id']) ? (int) $_POST['feed_cat_id'] : $feed_cat_id; $feed_cat_id = !empty($_POST['feed_cat_id']) && is_numeric($_POST['feed_cat_id']) ? (int) $_POST['feed_cat_id'] : $feed_cat_id;
$feed_upd_int = !empty($_POST['feed_upd_int']) && is_numeric($_POST['feed_upd_int']) ? (int) $_POST['feed_upd_int'] : $feed_upd_int; $feed_upd_int = !empty($_POST['feed_upd_int']) && is_numeric($_POST['feed_upd_int']) ? (int) $_POST['feed_upd_int'] : $feed_upd_int;
$feed_status = empty($_POST['feed_status']) ? $feed_status : 1; $feed_status = empty($_POST['feed_status']) ? $feed_status : 1;
@ -166,7 +172,7 @@ class ManageFeedVars
$this->feed = $feed_feed; $this->feed = $feed_feed;
$this->lang = $feed_lang; $this->lang = $feed_lang;
$this->tags = $feed_tags; $this->tags = $feed_tags;
$this->get_tags = (bool) $feed_get_tags; $this->get_tags = $feed_get_tags;
$this->cat_id = $feed_cat_id; $this->cat_id = $feed_cat_id;
$this->status = $feed_status; $this->status = $feed_status;
$this->upd_int = $feed_upd_int; $this->upd_int = $feed_upd_int;
@ -212,13 +218,13 @@ class ManageFeedVars
$cur->setField('feed_feed', $this->feed); $cur->setField('feed_feed', $this->feed);
$cur->setField('feed_lang', $this->lang); $cur->setField('feed_lang', $this->lang);
$cur->setField('feed_tags', $this->tags); $cur->setField('feed_tags', $this->tags);
$cur->setField('feed_get_tags', (int) $this->get_tags); $cur->setField('feed_get_tags', $this->get_tags);
$cur->setField('cat_id', $this->cat_id); $cur->setField('cat_id', $this->cat_id);
$cur->setField('feed_status', $this->status); $cur->setField('feed_status', $this->status);
$cur->setField('feed_upd_int', $this->upd_int); $cur->setField('feed_upd_int', $this->upd_int);
# --BEHAVIOR-- adminBeforeZoneclearFeedServerFeedSave - Cursor, int # --BEHAVIOR-- adminBeforeZoneclearFeedServerFeedSave - Cursor, int
App::behavior()->callBehavior('adminBeforeZoneclearFeedServerFeedSave', $cur, $id); dcCore::app()->callBehavior('adminBeforeZoneclearFeedServerFeedSave', $cur, $id);
if (!$id) { if (!$id) {
// create feed // create feed
@ -229,7 +235,7 @@ class ManageFeedVars
} }
# --BEHAVIOR-- adminAfterZoneclearFeedServerFeedSave - Cursor - int # --BEHAVIOR-- adminAfterZoneclearFeedServerFeedSave - Cursor - int
App::behavior()->callBehavior('adminAfterZoneclearFeedServerFeedSave', $cur, $id); dcCore::app()->callBehavior('adminAfterZoneclearFeedServerFeedSave', $cur, $id);
return $id; return $id;
} }

View File

@ -1,5 +1,15 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
@ -7,33 +17,17 @@ namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\Module\MyPlugin; use Dotclear\Module\MyPlugin;
/** /**
* @brief zoneclearFeedServer My helper. * This module definitions.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class My extends MyPlugin class My extends MyPlugin
{ {
/** /** @var string This module database table name */
* This module database table name. public const TABLE_NAME = \initZoneclearFeedServer::TABLE_NAME;
*
* @var string TABLE_NAME
*/
public const TABLE_NAME = 'zc_feed';
/** /** @var string This module meta prefix */
* This module meta prefix.
*
* @var string META_PREFIX
*/
public const META_PREFIX = 'zoneclearfeed_'; public const META_PREFIX = 'zoneclearfeed_';
/** /** @var array<int,string> This module template blocks */
* This module template blocks.
*
* @var array<int,string> TPL_BLOCKS
*/
public const TPL_BLOCKS = [ public const TPL_BLOCKS = [
'Feeds', 'Feeds',
'FeedsFooter', 'FeedsFooter',
@ -41,11 +35,7 @@ class My extends MyPlugin
'FeedIf', 'FeedIf',
]; ];
/** /** @var array<int,string> This module template values */
* This module template values.
*
* @var array<int,string> TPL_VALUES
*/
public const TPL_VALUES = [ public const TPL_VALUES = [
'FeedsCount', 'FeedsCount',
'FeedsEntriesCount', 'FeedsEntriesCount',
@ -65,5 +55,8 @@ class My extends MyPlugin
'FeedFeedURL', 'FeedFeedURL',
]; ];
// Use default permissions public static function checkCustomContext(int $context): ?bool
{
return $context == My::BACKEND ? defined('DC_CONTEXT_ADMIN') : null;
}
} }

View File

@ -1,11 +1,22 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use ArrayObject; use ArrayObject;
use Dotclear\App; use dcCore;
use dcUtils;
use Dotclear\Core\Backend\Combos; use Dotclear\Core\Backend\Combos;
use Dotclear\Core\Backend\Filter\{ use Dotclear\Core\Backend\Filter\{
Filter, Filter,
@ -16,11 +27,7 @@ use Dotclear\Helper\Html\Html;
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer backend feeds posts list filter. * Backend feed posts list filters.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class PostsFilter extends Filters class PostsFilter extends Filters
{ {
@ -38,7 +45,7 @@ class PostsFilter extends Filters
]); ]);
# --BEHAVIOR-- zcfsPostFilter # --BEHAVIOR-- zcfsPostFilter
App::behavior()->callBehavior('zcfsPostFilter', $filters); dcCore::app()->callBehavior('zcfsPostFilter', $filters);
$filters = $filters->getArrayCopy(); $filters = $filters->getArrayCopy();
@ -55,18 +62,18 @@ class PostsFilter extends Filters
$users = null; $users = null;
try { try {
$users = App::blog()->getPostsUsers(); $users = dcCore::app()->blog?->getPostsUsers();
if ($users->isEmpty()) { if (is_null($users) || $users->isEmpty()) {
return null; return null;
} }
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
return null; return null;
} }
$combo = Combos::getUsersCombo($users); $combo = Combos::getUsersCombo($users);
App::lexical()->lexicalKeySort($combo); dcUtils::lexicalKeySort($combo);
return (new Filter('user_id')) return (new Filter('user_id'))
->param() ->param()
@ -88,12 +95,12 @@ class PostsFilter extends Filters
$categories = null; $categories = null;
try { try {
$categories = App::blog()->getCategories(); $categories = dcCore::app()->blog?->getCategories();
if ($categories->isEmpty()) { if (is_null($categories) || $categories->isEmpty()) {
return null; return null;
} }
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
return null; return null;
} }
@ -142,12 +149,12 @@ class PostsFilter extends Filters
$dates = null; $dates = null;
try { try {
$dates = App::blog()->getDates(['type' => 'month']); $dates = dcCore::app()->blog?->getDates(['type' => 'month']);
if ($dates->isEmpty()) { if (is_null($dates) || $dates->isEmpty()) {
return null; return null;
} }
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
return null; return null;
} }

View File

@ -1,11 +1,21 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use ArrayObject; use ArrayObject;
use Dotclear\App; use dcCore;
use Dotclear\Core\Backend\Listing\{ use Dotclear\Core\Backend\Listing\{
Listing, Listing,
Pager Pager
@ -21,11 +31,7 @@ use Dotclear\Helper\Html\Form\{
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
/** /**
* @brief zoneclearFeedServer backend feed posts lists. * Backend feed posts lists.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class PostsList extends Listing class PostsList extends Listing
{ {
@ -102,7 +108,7 @@ class PostsList extends Listing
{ {
$cat_title = (new Text('', __('None'))); $cat_title = (new Text('', __('None')));
if ($this->rs->cat_title if ($this->rs->cat_title
&& App::auth()->check(App::auth()->makePermissions([App::auth()::PERMISSION_CATEGORIES]), App::blog()->id()) && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CATEGORIES]), dcCore::app()->blog?->id)
) { ) {
$cat_title = (new Link()) $cat_title = (new Link())
->href('category.php?id=' . $this->rs->cat_id) ->href('category.php?id=' . $this->rs->cat_id)
@ -149,7 +155,7 @@ class PostsList extends Listing
->class('maximal') ->class('maximal')
->items([ ->items([
(new Link()) (new Link())
->href(App::postTypes()->getPostAdminURL($this->rs->post_type, $this->rs->post_id)) ->href(dcCore::app()->getPostAdminURL($this->rs->post_type, $this->rs->post_id))
->title(Html::escapeHTML($this->rs->getURL())) ->title(Html::escapeHTML($this->rs->getURL()))
->text(Html::escapeHTML(trim(Html::clean($this->rs->post_title)))), ->text(Html::escapeHTML(trim(Html::clean($this->rs->post_title)))),
]), ]),

View File

@ -1,18 +1,24 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/** /**
* @brief zoneclearFeedServer prepend class. * Module prepend.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Prepend extends Process class Prepend extends Process
{ {
@ -28,13 +34,18 @@ class Prepend extends Process
} }
// public url for page of description of the flux // public url for page of description of the flux
App::url()->register( dcCore::app()->url->register(
'zoneclearFeedsPage', 'zoneclearFeedsPage',
'zcfeeds', 'zcfeeds',
'^zcfeeds(.*?)$', '^zcfeeds(.*?)$',
UrlHandler::zoneclearFeedsPage(...) [UrlHandler::class, 'zoneclearFeedsPage']
); );
// report zoneclearFeedServer activities
if (defined('ACTIVITY_REPORT') && ACTIVITY_REPORT == 3) {
ActivityReportActions::init();
}
return true; return true;
} }
} }

View File

@ -1,26 +1,30 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use context;
use Dotclear\Core\Frontend\Ctx; use dcCore;
use rsExtPost;
use rsExtPostPublic;
use Dotclear\Database\MetaRecord; use Dotclear\Database\MetaRecord;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Schema\Extension\Post;
use Dotclear\Schema\Extension\PostPublic;
/** /**
* @brief zoneclearFeedServer posts record extension.
* @ingroup zoneclearFeedServer
*
* Posts record extension to integrate feed info. * Posts record extension to integrate feed info.
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class RsExtPosts extends Post class RsExtPosts extends rsExtPost
{ {
/** @var array<string,mixed> $brother_extensions Stack posts record extensions */ /** @var array<string,mixed> $brother_extensions Stack posts record extensions */
public static array $brother_extensions = []; public static array $brother_extensions = [];
@ -35,7 +39,7 @@ class RsExtPosts extends Post
*/ */
public static function zcFeed(MetaRecord $rs, string $info): ?string public static function zcFeed(MetaRecord $rs, string $info): ?string
{ {
$meta = App::meta()->getMetadata([ $meta = dcCore::app()->meta->getMetadata([
'post_id' => $rs->f('post_id'), 'post_id' => $rs->f('post_id'),
'meta_type' => My::META_PREFIX . $info, 'meta_type' => My::META_PREFIX . $info,
'limit' => 1, 'limit' => 1,
@ -57,10 +61,10 @@ class RsExtPosts extends Post
$ext = static::$brother_extensions; $ext = static::$brother_extensions;
if (isset($ext[$type]) && is_callable($ext[$type])) { if (isset($ext[$type]) && is_callable($ext[$type])) {
$func = $ext[$type]; $func = $ext[$type];
} elseif (is_callable([PostPublic::class, $type])) { } elseif (is_callable([rsExtPostPublic::class, $type])) {
$func = [PostPublic::class, $type]; $func = [rsExtPostPublic::class, $type];
} elseif (is_callable([Post::class, $type])) { } elseif (is_callable([rsExtPost::class, $type])) {
$func = [Post::class, $type]; $func = [rsExtPost::class, $type];
} else { } else {
return ''; return '';
} }
@ -114,7 +118,7 @@ class RsExtPosts extends Post
{ {
$url = $rs->__call('zcFeed', ['url']); $url = $rs->__call('zcFeed', ['url']);
$site = $rs->__call('zcFeed', ['site']); $site = $rs->__call('zcFeed', ['site']);
$full = in_array(App::url()->type, ZoneclearFeedServer::instance()->settings->post_title_redir); $full = in_array(dcCore::app()->url->type, ZoneclearFeedServer::instance()->settings->post_title_redir);
return is_string($site) && is_string($url) && $full ? return is_string($site) && is_string($url) && $full ?
ZoneclearFeedServer::instance()::absoluteURL($site, $url) : ZoneclearFeedServer::instance()::absoluteURL($site, $url) :
@ -125,7 +129,7 @@ class RsExtPosts extends Post
* Get post content from post to feed. * Get post content from post to feed.
* *
* @param MetaRecord $rs The record instance * @param MetaRecord $rs The record instance
* @param mixed $absolute_urls Serve absolute URL (type "mixed" from Post) * @param mixed $absolute_urls Serve absolute URL (type "mixed" from rsExtPost)
* *
* @return string The post content * @return string The post content
*/ */
@ -136,14 +140,14 @@ class RsExtPosts extends Post
$content = self::zcFeedBrother('getContent', [&$rs, $absolute_urls]); $content = self::zcFeedBrother('getContent', [&$rs, $absolute_urls]);
if (is_string($url) && is_string($sitename) && $rs->f('post_type') == 'post') { if (is_string($url) && is_string($sitename) && $rs->f('post_type') == 'post') {
if (in_array(App::url()->type, ZoneclearFeedServer::instance()->settings->post_full_tpl)) { if (in_array(dcCore::app()->url->type, ZoneclearFeedServer::instance()->settings->post_full_tpl)) {
return $content . sprintf( return $content . sprintf(
'<p class="zoneclear-original"><em>%s</em></p>', '<p class="zoneclear-original"><em>%s</em></p>',
sprintf(__('Original post on <a href="%s">%s</a>'), $url, $sitename) sprintf(__('Original post on <a href="%s">%s</a>'), $url, $sitename)
); );
} }
$content = Ctx::remove_html($content); $content = context::remove_html($content);
$content = Ctx::cut_string($content, 350); $content = context::cut_string($content, 350);
$content = Html::escapeHTML($content); $content = Html::escapeHTML($content);
return sprintf( return sprintf(

View File

@ -1,15 +1,21 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
/** /**
* @brief zoneclearFeedServer settings. * Module settings (type hinting).
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Settings class Settings
{ {
@ -90,8 +96,9 @@ class Settings
{ {
$s = My::settings(); $s = My::settings();
if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) { if (!is_null($s) && property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) {
$s->put($key, $value, gettype($this->{$key})); $s->drop($key);
$s->put($key, $value, gettype($this->{$key}), '', true, true);
return true; return true;
} }

View File

@ -1,27 +1,30 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use ArrayObject; use ArrayObject;
use Dotclear\App; use dcCore;
use Dotclear\Core\Frontend\Tpl; use dcTemplate;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Helper\L10n; use Dotclear\Helper\L10n;
/** /**
* @brief zoneclearFeedServer frontend tempalte class. * Frontend template blocks and values.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
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;
@ -79,70 +82,67 @@ class Template
return return
'<?php ' . $p . '<?php ' . $p .
'App::frontend()->context()->feeds_params = $zcfs_params;' . "\n" . 'dcCore::app()->ctx->feeds_params = $zcfs_params;' . "\n" .
'$zcfs = ' . ZoneclearFeedServer::class . '::instance();' . "\n" . '$zcfs = ' . ZoneclearFeedServer::class . '::instance();' . "\n" .
'App::frontend()->context()->feeds = $zcfs->getFeeds($zcfs_params); unset($zcfs_params,$zcfs);' . "\n" . 'dcCore::app()->ctx->feeds = $zcfs->getFeeds($zcfs_params); unset($zcfs_params,$zcfs);' . "\n" .
"?>\n" . "?>\n" .
'<?php while (App::frontend()->context()->feeds->fetch()) : ?>' . $c . '<?php endwhile; ' . '<?php while (dcCore::app()->ctx->feeds->fetch()) : ?>' . $c . '<?php endwhile; ' .
'App::frontend()->context()->feeds = null; App::frontend()->context()->feeds_params = null; ?>'; 'dcCore::app()->ctx->feeds = null; dcCore::app()->ctx->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 = [];
$operator = isset($a['operator']) && is_string($a['operator']) ? Tpl::getOperator($a['operator']) : '&&'; $operator = isset($a['operator']) && is_string($a['operator']) ? dcTemplate::getOperator($a['operator']) : '&&';
if (isset($a['type']) && is_string($a['type'])) { if (isset($a['type']) && is_string($a['type'])) {
$type = trim($a['type']); $type = trim($a['type']);
$type = !empty($type) ? $type : 'feed'; $type = !empty($type) ? $type : 'feed';
$if[] = 'App::frontend()->context()->feeds->feed_type == "' . addslashes($type) . '"'; $if[] = 'dcCore::app()->ctx->feeds->feed_type == "' . addslashes($type) . '"';
} }
if (isset($a['site_url']) && is_string($a['site_url'])) { if (isset($a['site_url']) && is_string($a['site_url'])) {
$url = trim($a['site_url']); $url = trim($a['site_url']);
if (substr($url, 0, 1) == '!') { if (substr($url, 0, 1) == '!') {
$url = substr($url, 1); $url = substr($url, 1);
$if[] = 'App::frontend()->context()->feeds->feed_url != "' . addslashes($url) . '"'; $if[] = 'dcCore::app()->ctx->feeds->feed_url != "' . addslashes($url) . '"';
} else { } else {
$if[] = 'App::frontend()->context()->feeds->feed_url == "' . addslashes($url) . '"'; $if[] = 'dcCore::app()->ctx->feeds->feed_url == "' . addslashes($url) . '"';
} }
} }
if (isset($a['feed_url']) && is_string($a['feed_url'])) { if (isset($a['feed_url']) && is_string($a['feed_url'])) {
$url = trim($a['feed_url']); $url = trim($a['feed_url']);
if (substr($url, 0, 1) == '!') { if (substr($url, 0, 1) == '!') {
$url = substr($url, 1); $url = substr($url, 1);
$if[] = 'App::frontend()->context()->feeds->feed_feed != "' . addslashes($url) . '"'; $if[] = 'dcCore::app()->ctx->feeds->feed_feed != "' . addslashes($url) . '"';
} else { } else {
$if[] = 'App::frontend()->context()->feeds->feed_feed == "' . addslashes($url) . '"'; $if[] = 'dcCore::app()->ctx->feeds->feed_feed == "' . addslashes($url) . '"';
} }
} }
if (isset($a['category']) && is_string($a['category'])) { if (isset($a['category']) && is_string($a['category'])) {
$category = addslashes(trim($a['category'])); $category = addslashes(trim($a['category']));
if (substr($category, 0, 1) == '!') { if (substr($category, 0, 1) == '!') {
$category = substr($category, 1); $category = substr($category, 1);
$if[] = '(App::frontend()->context()->feeds->cat_url != "' . $category . '")'; $if[] = '(dcCore::app()->ctx->feeds->cat_url != "' . $category . '")';
} else { } else {
$if[] = '(App::frontend()->context()->feeds->cat_url == "' . $category . '")'; $if[] = '(dcCore::app()->ctx->feeds->cat_url == "' . $category . '")';
} }
} }
if (isset($a['first'])) { if (isset($a['first'])) {
$sign = (bool) $a['first'] ? '=' : '!'; $sign = (bool) $a['first'] ? '=' : '!';
$if[] = 'App::frontend()->context()->feeds->index() ' . $sign . '= 0'; $if[] = 'dcCore::app()->ctx->feeds->index() ' . $sign . '= 0';
} }
if (isset($a['odd'])) { if (isset($a['odd'])) {
$sign = (bool) $a['odd'] ? '=' : '!'; $sign = (bool) $a['odd'] ? '=' : '!';
$if[] = '(App::frontend()->context()->feeds->index()+1)%2 ' . $sign . ' = 1'; $if[] = '(dcCore::app()->ctx->feeds->index()+1)%2 ' . $sign . ' = 1';
} }
if (isset($a['has_category'])) { if (isset($a['has_category'])) {
$sign = (bool) $a['has_category'] ? '' : '!'; $sign = (bool) $a['has_category'] ? '' : '!';
$if[] = $sign . 'App::frontend()->context()->feeds->cat_id'; $if[] = $sign . 'dcCore::app()->ctx->feeds->cat_id';
} }
if (isset($a['has_description'])) { if (isset($a['has_description'])) {
$sign = (bool) $a['has_description'] ? '' : '!'; $sign = (bool) $a['has_description'] ? '' : '!';
$if[] = $sign . 'App::frontend()->context()->feeds->feed_desc'; $if[] = $sign . 'dcCore::app()->ctx->feeds->feed_desc';
} }
return empty($if) ? return empty($if) ?
@ -150,143 +150,95 @@ 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');
return return
'<?php if (App::frontend()->context()->feeds->index() == 0) { ' . '<?php if (dcCore::app()->ctx->feeds->index() == 0) { ' .
"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');
return return
'<?php if ((App::frontend()->context()->feeds->index()+1)%2 == 1) { ' . '<?php if ((dcCore::app()->ctx->feeds->index()+1)%2 == 1) { ' .
"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, 'dcCore::app()->ctx->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, 'dcCore::app()->ctx->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, 'dcCore::app()->ctx->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, 'dcCore::app()->ctx->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, 'dcCore::app()->blog->url.dcCore::app()->url->getBase(\'category\').\'/\'.Html::sanitizeURL(dcCore::app()->ctx->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, 'dcCore::app()->ctx->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, 'dcCore::app()->ctx->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']) ?
self::getValue($a, 'App::frontend()->context()->feeds->feed_lang') : self::getValue($a, 'dcCore::app()->ctx->feeds->feed_lang') :
'<?php $langs = ' . L10n::class . '::getISOcodes(); if (isset($langs[App::frontend()->context()->feeds->feed_lang])) { ?>' . '<?php $langs = ' . L10n::class . '::getISOcodes(); if (isset($langs[dcCore::app()->ctx->feeds->feed_lang])) { ?>' .
self::getValue($a, '$langs[App::frontend()->context()->feeds->feed_lang]') . self::getValue($a, '$langs[dcCore::app()->ctx->feeds->feed_lang]') .
'<?php } else { ?>' . '<?php } else { ?>' .
self::getValue($a, 'App::frontend()->context()->feeds->feed_lang') . self::getValue($a, 'dcCore::app()->ctx->feeds->feed_lang') .
'<?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, 'dcCore::app()->ctx->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, 'dcCore::app()->ctx->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, 'dcCore::app()->ctx->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 (dcCore::app()->ctx->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 (dcCore::app()->ctx->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';
@ -294,7 +246,7 @@ class Template
$more = isset($a['more']) && is_string($a['more']) ? addslashes($a['more']) : '%d sources'; $more = isset($a['more']) && is_string($a['more']) ? addslashes($a['more']) : '%d sources';
return return
"<?php \$fcount = App::frontend()->context()->feeds->count(); \n" . "<?php \$fcount = dcCore::app()->ctx->feeds->count(); \n" .
"if (\$fcount == 0) {\n" . "if (\$fcount == 0) {\n" .
" printf(__('" . $none . "'),\$fcount);\n" . " printf(__('" . $none . "'),\$fcount);\n" .
"} elseif (\$fcount == 1) {\n" . "} elseif (\$fcount == 1) {\n" .
@ -304,9 +256,6 @@ 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';
@ -331,9 +280,6 @@ 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';
@ -342,7 +288,7 @@ class Template
return return
'<?php $zcfs = ' . ZoneclearFeedServer::class . "::instance(); \n" . '<?php $zcfs = ' . ZoneclearFeedServer::class . "::instance(); \n" .
"\$fcount = \$zc->getPostsByFeed(array('feed_id'=>App::frontend()->context()->feeds->feed_id),true)->f(0); \n" . "\$fcount = \$zc->getPostsByFeed(array('feed_id'=>dcCore::app()->ctx->feeds->feed_id),true)->f(0); \n" .
"if (\$fcount == 0) {\n" . "if (\$fcount == 0) {\n" .
" printf(__('" . $none . "'),\$fcount);\n" . " printf(__('" . $none . "'),\$fcount);\n" .
"} elseif (\$fcount == 1) {\n" . "} elseif (\$fcount == 1) {\n" .
@ -352,11 +298,8 @@ 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::frontend()->template()->getFilters($a), $v) . '; ?>'; return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($a), $v) . '; ?>';
} }
} }

View File

@ -1,18 +1,25 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
/** /**
* @brief zoneclearFeedServer uninstall class. * Plugin Uninstaller actions.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Uninstall extends Process class Uninstall extends Process
{ {
@ -23,7 +30,7 @@ class Uninstall extends Process
public static function process(): bool public static function process(): bool
{ {
if (!self::status()) { if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false; return false;
} }

View File

@ -1,10 +1,21 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use dcMeta;
use Dotclear\Database\Statement\{ use Dotclear\Database\Statement\{
DeleteStatement, DeleteStatement,
SelectStatement SelectStatement
@ -18,11 +29,9 @@ use Dotclear\Plugin\Uninstaller\{
}; };
/** /**
* @brief zoneclearFeedServer uninstall cleaner. * Plugin Uninstaller Cleaner object.
* @ingroup zoneclearFeedServer
* *
* @author Jean-Christian Denis * This add special action for feed posts metadata.
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class UninstallCleaner extends CleanerParent class UninstallCleaner extends CleanerParent
{ {
@ -57,7 +66,7 @@ class UninstallCleaner extends CleanerParent
public function values(): array public function values(): array
{ {
$sql = new SelectStatement(); $sql = new SelectStatement();
$sql->from(App::con()->prefix() . App::meta()::META_TABLE_NAME) $sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME)
->columns([ ->columns([
$sql->as($sql->count('*'), 'counter'), $sql->as($sql->count('*'), 'counter'),
]) ])
@ -83,7 +92,7 @@ class UninstallCleaner extends CleanerParent
{ {
if ($action == 'delete_all') { if ($action == 'delete_all') {
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(App::con()->prefix() . App::meta()::META_TABLE_NAME) $sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME)
->where($sql->like('meta_type', My::META_PREFIX . '%')) ->where($sql->like('meta_type', My::META_PREFIX . '%'))
->delete(); ->delete();

View File

@ -1,10 +1,21 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use dcNamespace;
use Dotclear\Database\Statement\{ use Dotclear\Database\Statement\{
SelectStatement, SelectStatement,
UpdateStatement UpdateStatement
@ -12,17 +23,13 @@ use Dotclear\Database\Statement\{
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer upgrade class. * Module versions upgrades.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Upgrade class Upgrade
{ {
public static function preUpgrade(): void public static function preUpgrade(): void
{ {
$current = App::version()->getVersion(My::id()); $current = dcCore::app()->getVersion(My::id());
if (!is_string($current) || empty($current)) { if (!is_string($current) || empty($current)) {
return; return;
} }
@ -52,7 +59,7 @@ class Upgrade
'zoneclearFeedServer_post_title_redir' => 'post_title_redir', 'zoneclearFeedServer_post_title_redir' => 'post_title_redir',
]; ];
$cur = App::blogWorkspace()->openBlogWorkspaceCursor(); $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
foreach ($setting_ids as $old => $new) { foreach ($setting_ids as $old => $new) {
$cur->clean(); $cur->clean();
$cur->setField('setting_id', $new); $cur->setField('setting_id', $new);
@ -62,13 +69,13 @@ class Upgrade
$sql $sql
->where('setting_id = ' . $sql->quote($old)) ->where('setting_id = ' . $sql->quote($old))
->and('setting_ns = ' . $sql->quote('zoneclearFeedServer')) ->and('setting_ns = ' . $sql->quote('zoneclearFeedServer'))
->update($cur); ->update();
} }
// use json rather than serialise for settings array // use json rather than serialise for settings array
$sql = new SelectStatement(); $sql = new SelectStatement();
$record = $sql $record = $sql
->from(App::con()->prefix() . App::blogWorkspace()::NS_TABLE_NAME) ->from(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME)
->where('setting_ns = ' . $sql->quote(My::id())) ->where('setting_ns = ' . $sql->quote(My::id()))
->select(); ->select();
@ -81,7 +88,7 @@ class Upgrade
'post_title_redir' => ['feed'], 'post_title_redir' => ['feed'],
]; ];
$cur = App::blogWorkspace()->openBlogWorkspaceCursor(); $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
while ($record->fetch()) { while ($record->fetch()) {
foreach ($setting_values as $key => $default) { foreach ($setting_values as $key => $default) {
try { try {
@ -98,7 +105,7 @@ class Upgrade
->where('setting_id = ' . $sql->quote($key)) ->where('setting_id = ' . $sql->quote($key))
->and('setting_ns = ' . $sql->quote($record->f('setting_ns'))) ->and('setting_ns = ' . $sql->quote($record->f('setting_ns')))
->and('blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ('= ' . $sql->quote($record->f('blog_id'))))) ->and('blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ('= ' . $sql->quote($record->f('blog_id')))))
->update($cur); ->update();
} }
} }
} }
@ -108,7 +115,7 @@ class Upgrade
// change settings type of json string to array // change settings type of json string to array
$sql = new UpdateStatement(); $sql = new UpdateStatement();
$sql $sql
->ref(App::con()->prefix() . App::blogWorkspace()::NS_TABLE_NAME) ->ref(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME)
->column('setting_type') ->column('setting_type')
->value('array') ->value('array')
->where('setting_id ' . $sql->in([ ->where('setting_id ' . $sql->in([

View File

@ -1,25 +1,31 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Core\Frontend\Url; use dcUrlHandlers;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer frontend URL handler. * Frontend URL handler.
* @ingroup zoneclearFeedServer
* *
* This adds public page that list feeds. * This adds public page that list feeds.
* And serve an endpoint to update feeds through js. * And serve an endpoint to update feeds through js.
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class UrlHandler extends Url class UrlHandler extends dcUrlHandlers
{ {
/** /**
* Feeds source page and update methods. * Feeds source page and update methods.
@ -32,14 +38,14 @@ class UrlHandler extends Url
$s = $z->settings; $s = $z->settings;
# Not active # Not active
if (!App::blog()->isDefined() || !$s->active) { if (is_null(dcCore::app()->blog) || !$s->active) {
self::p404(); self::p404();
} }
# Update feeds (from ajax or other post resquest) # Update feeds (from ajax or other post resquest)
if ($args == '/zcfsupd' && 3 == $s->bhv_pub_upd) { if ($args == '/zcfsupd' && 3 == $s->bhv_pub_upd) {
$msg = ''; $msg = '';
if (!empty($_POST['blogId']) && Html::escapeJS(App::blog()->id()) == $_POST['blogId']) { if (!empty($_POST['blogId']) && Html::escapeJS(dcCore::app()->blog->id) == $_POST['blogId']) {
try { try {
if ($z->checkFeedsUpdate()) { if ($z->checkFeedsUpdate()) {
$msg = sprintf( $msg = sprintf(
@ -70,7 +76,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()->appendPath(My::path() . '/default-templates'); dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), My::path() . '/default-templates');
self::serveDocument( self::serveDocument(
'zcfsupd.js', 'zcfsupd.js',
'text/javascript', 'text/javascript',
@ -80,15 +86,17 @@ class UrlHandler extends Url
# Server feeds description page # Server feeds description page
} elseif (in_array($args, ['', '/']) && $s->pub_active) { } elseif (in_array($args, ['', '/']) && $s->pub_active) {
$theme = App::blog()->settings()->get('system')->get('theme'); $theme = dcCore::app()->blog->settings->get('system')->get('theme');
if (!is_string($theme)) { if (!is_string($theme)) {
self::p404(); self::p404();
} }
$tplset = App::themes()->getDefine(App::blog()->settings()->get('system')->get('theme'))->get('tplset'); $tplset = dcCore::app()->themes->getDefine($theme)->get('tplset');
if (empty($tplset) || !is_dir(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]))) { $path = My::path() . '/default-templates/';
$tplset = App::config()->defaultTplset(); if (!empty($tplset) && is_dir($path . $tplset)) {
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), $path . $tplset);
} else {
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), $path . DC_DEFAULT_TPLSET);
} }
App::frontend()->template()->appendPath(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]));
self::serveDocument('zcfeeds.html'); self::serveDocument('zcfeeds.html');
} }
# Unknow # Unknow

View File

@ -1,23 +1,29 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use Dotclear\App; use dcCore;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Plugin\widgets\WidgetsStack; use Dotclear\Plugin\widgets\WidgetsStack;
use Dotclear\Plugin\widgets\WidgetsElement; use Dotclear\Plugin\widgets\WidgetsElement;
/** /**
* @brief zoneclearFeedServer widgets. * Widgets.
* @ingroup zoneclearFeedServer
* *
* A widget to list feeds source. * A widget to list feeds source.
* A widget to list feeds statistics. * A widget to list feeds statistics.
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Widgets class Widgets
{ {
@ -30,7 +36,7 @@ class Widgets
->create( ->create(
'zcfssource', 'zcfssource',
__('Feeds server: sources'), __('Feeds server: sources'),
self::publicSource(...), [self::class, 'publicSource'],
null, null,
__('List sources of feeds') __('List sources of feeds')
) )
@ -79,7 +85,7 @@ class Widgets
->create( ->create(
'zcfsnumber', 'zcfsnumber',
__('Feeds server: numbers'), __('Feeds server: numbers'),
self::publicNumber(...), [self::class, 'publicNumber'],
null, null,
__('Show some numbers about feeds') __('Show some numbers about feeds')
) )
@ -134,7 +140,7 @@ class Widgets
if ($w->__get('offline') if ($w->__get('offline')
|| !$s->active || !$s->active
|| !$w->checkHomeOnly(App::url()->type) || !$w->checkHomeOnly(dcCore::app()->url->type)
) { ) {
return ''; return '';
} }
@ -167,7 +173,7 @@ class Widgets
if ($w->__get('pagelink') && $s->pub_active) { if ($w->__get('pagelink') && $s->pub_active) {
$pub = sprintf( $pub = sprintf(
'<p><strong><a href="%s">%s</a></strong></p>', '<p><strong><a href="%s">%s</a></strong></p>',
App::blog()->url() . App::url()->getBase('zoneclearFeedsPage'), dcCore::app()->blog?->url . dcCore::app()->url->getBase('zoneclearFeedsPage'),
Html::escapeHTML(is_string($w->__get('pagelink')) ? $w->__get('pagelink') : '') Html::escapeHTML(is_string($w->__get('pagelink')) ? $w->__get('pagelink') : '')
); );
} }
@ -193,7 +199,7 @@ class Widgets
if ($w->__get('offline') if ($w->__get('offline')
|| !$s->active || !$s->active
|| !$w->checkHomeOnly(App::url()->type) || !$w->checkHomeOnly(dcCore::app()->url->type)
) { ) {
return ''; return '';
} }
@ -215,7 +221,7 @@ class Widgets
if ($s->pub_active) { if ($s->pub_active) {
$text = sprintf( $text = sprintf(
'<a href="%s">%s</a>', '<a href="%s">%s</a>',
App::blog()->url() . App::url()->getBase('zoneclearFeedsPage'), dcCore::app()->blog?->url . dcCore::app()->url->getBase('zoneclearFeedsPage'),
$text $text
); );
} }

View File

@ -1,11 +1,26 @@
<?php <?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\zoneclearFeedServer; namespace Dotclear\Plugin\zoneclearFeedServer;
use ArrayObject; use ArrayObject;
use Dotclear\App; use dcAuth;
use dcBlog;
use dcCategories;
use dcCore;
use dcMeta;
use dcUtils;
use Dotclear\Database\{ use Dotclear\Database\{
Cursor, Cursor,
MetaRecord MetaRecord
@ -29,61 +44,29 @@ use Dotclear\Helper\Text;
use Exception; use Exception;
/** /**
* @brief zoneclearFeedServer main class. * Main module class.
* @ingroup zoneclearFeedServer
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class ZoneclearFeedServer class ZoneclearFeedServer
{ {
/** /** @var int Net HTTP feed reader timeout */
* Net HTTP timeout.
*
* @var int NET_HTTP_TIMEOUT
*/
public const NET_HTTP_TIMEOUT = 5; public const NET_HTTP_TIMEOUT = 5;
/** /** @var string Net HTTP feed reader agent */
* Net HTTP feed reader agent.
*
* @var string NET_HTTP_AGENT
*/
public const NET_HTTP_AGENT = 'zoneclearFeedServer - http://zoneclear.org'; public const NET_HTTP_AGENT = 'zoneclearFeedServer - http://zoneclear.org';
/** /** @var int Net HTTP feed reader max redirect */
* Net HTTP feed reader max redirect.
*
* @var int NET_HTTP_MAX_REDIRECT
*/
public const NET_HTTP_MAX_REDIRECT = 2; public const NET_HTTP_MAX_REDIRECT = 2;
/** /** @var ZoneclearFeedServer Self instance */
* Self instance.
*
* @var ZoneclearFeedServer $instance
*/
private static $instance; private static $instance;
/** /** @var Settings The settings instance */
* Settings.
*
* @var Settings $settings
*/
public readonly Settings $settings; public readonly Settings $settings;
/** /** @var null|string $lock File lock for update */
* File lock for update.
*
* @var null|string $lock
*/
private static $lock = null; private static $lock = null;
/** /** @var null|string $user Affiliate user ID */
* Affiliate user ID.
*
* @var null|string $user
*/
private $user = null; private $user = null;
/** /**
@ -115,7 +98,7 @@ class ZoneclearFeedServer
*/ */
public function openCursor(): Cursor public function openCursor(): Cursor
{ {
return App::con()->openCursor(App::con()->prefix() . My::TABLE_NAME); return dcCore::app()->con->openCursor(dcCore::app()->prefix . My::TABLE_NAME);
} }
/** /**
@ -126,7 +109,7 @@ class ZoneclearFeedServer
*/ */
public function updateFeed(int $id, Cursor $cur): void public function updateFeed(int $id, Cursor $cur): void
{ {
App::con()->writeLock(App::con()->prefix() . My::TABLE_NAME); dcCore::app()->con->writeLock(dcCore::app()->prefix . My::TABLE_NAME);
try { try {
if ($id < 1) { if ($id < 1) {
@ -138,18 +121,18 @@ class ZoneclearFeedServer
$cur->update(sprintf( $cur->update(sprintf(
"WHERE feed_id = %s AND blog_id = '%s' ", "WHERE feed_id = %s AND blog_id = '%s' ",
$id, $id,
App::con()->escapeStr(App::blog()->id()) dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id)
)); ));
App::con()->unlock(); dcCore::app()->con->unlock();
$this->trigger(); $this->trigger();
} catch (Exception $e) { } catch (Exception $e) {
App::con()->unlock(); dcCore::app()->con->unlock();
throw $e; throw $e;
} }
# --BEHAVIOR-- zoneclearFeedServerAfterUpdateFeed -- Cursor, int # --BEHAVIOR-- zoneclearFeedServerAfterUpdateFeed -- Cursor, int
App::behavior()->callBehavior('zoneclearFeedServerAfterUpdateFeed', $cur, $id); dcCore::app()->callBehavior('zoneclearFeedServerAfterUpdateFeed', $cur, $id);
} }
/** /**
@ -161,20 +144,20 @@ class ZoneclearFeedServer
*/ */
public function addFeed(Cursor $cur): int public function addFeed(Cursor $cur): int
{ {
App::con()->writeLock(App::con()->prefix() . My::TABLE_NAME); dcCore::app()->con->writeLock(dcCore::app()->prefix . My::TABLE_NAME);
try { try {
$cur->setField('feed_id', $this->getNextId()); $cur->setField('feed_id', $this->getNextId());
$cur->setField('blog_id', App::con()->escapeStr(App::blog()->id())); $cur->setField('blog_id', dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id));
$cur->setField('feed_creadt', date('Y-m-d H:i:s')); $cur->setField('feed_creadt', date('Y-m-d H:i:s'));
$this->getFeedCursor($cur); $this->getFeedCursor($cur);
$cur->insert(); $cur->insert();
App::con()->unlock(); dcCore::app()->con->unlock();
$this->trigger(); $this->trigger();
} catch (Exception $e) { } catch (Exception $e) {
App::con()->unlock(); dcCore::app()->con->unlock();
throw $e; throw $e;
} }
@ -182,7 +165,7 @@ class ZoneclearFeedServer
$id = is_numeric($cur->getField('feed_id')) ? (int) $cur->getField('feed_id') : 0; $id = is_numeric($cur->getField('feed_id')) ? (int) $cur->getField('feed_id') : 0;
# --BEHAVIOR-- zoneclearFeedServerAfterAddFeed -- Cursor, int # --BEHAVIOR-- zoneclearFeedServerAfterAddFeed -- Cursor, int
App::behavior()->callBehavior('zoneclearFeedServerAfterAddFeed', $cur, $id); dcCore::app()->callBehavior('zoneclearFeedServerAfterAddFeed', $cur, $id);
return $id; return $id;
} }
@ -210,7 +193,7 @@ class ZoneclearFeedServer
} }
$cur = $this->openCursor(); $cur = $this->openCursor();
App::con()->writeLock(App::con()->prefix() . My::TABLE_NAME); dcCore::app()->con->writeLock(dcCore::app()->prefix . My::TABLE_NAME);
$cur->setField('feed_upddt', date('Y-m-d H:i:s')); $cur->setField('feed_upddt', date('Y-m-d H:i:s'));
$cur->setField('feed_status', (int) $enable); $cur->setField('feed_status', (int) $enable);
@ -221,18 +204,18 @@ class ZoneclearFeedServer
$cur->update(sprintf( $cur->update(sprintf(
"WHERE feed_id = %s AND blog_id = '%s' ", "WHERE feed_id = %s AND blog_id = '%s' ",
$id, $id,
App::con()->escapeStr(App::blog()->id()) dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id)
)); ));
App::con()->unlock(); dcCore::app()->con->unlock();
$this->trigger(); $this->trigger();
} catch (Exception $e) { } catch (Exception $e) {
App::con()->unlock(); dcCore::app()->con->unlock();
throw $e; throw $e;
} }
# --BEHAVIOR-- zoneclearFeedServerAfterEnableFeed -- int, bool, int # --BEHAVIOR-- zoneclearFeedServerAfterEnableFeed -- int, bool, int
App::behavior()->callBehavior('zoneclearFeedServerAfterEnableFeed', $id, $enable, $time); dcCore::app()->callBehavior('zoneclearFeedServerAfterEnableFeed', $id, $enable, $time);
} }
# #
@ -248,12 +231,12 @@ class ZoneclearFeedServer
} }
# --BEHAVIOR-- zoneclearFeedServerBeforeDeleteFeed -- int # --BEHAVIOR-- zoneclearFeedServerBeforeDeleteFeed -- int
App::behavior()->callBehavior('zoneclearFeedServerBeforeDeleteFeed', $id); dcCore::app()->callBehavior('zoneclearFeedServerBeforeDeleteFeed', $id);
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(App::con()->prefix() . My::TABLE_NAME) $sql->from(dcCore::app()->prefix . My::TABLE_NAME)
->where('feed_id ' . $sql->in($id)) ->where('feed_id ' . $sql->in($id))
->and('blog_id = ' . $sql->quote(App::blog()->id())) ->and('blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id))
->delete(); ->delete();
$this->trigger(); $this->trigger();
@ -270,7 +253,7 @@ class ZoneclearFeedServer
public static function deletePostsMeta(?int $id): void public static function deletePostsMeta(?int $id): void
{ {
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(App::con()->prefix() . App::meta()::META_TABLE_NAME) $sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME)
->where('meta_type ' . $sql->in([ ->where('meta_type ' . $sql->in([
My::META_PREFIX . 'url', My::META_PREFIX . 'url',
My::META_PREFIX . 'author', My::META_PREFIX . 'author',
@ -289,7 +272,7 @@ class ZoneclearFeedServer
/** /**
* Get related posts. * Get related posts.
* *
* @param array<string, mixed> $params The query params * @param array<string,int|string|array> $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
@ -304,24 +287,26 @@ class ZoneclearFeedServer
$sql->join( $sql->join(
(new JoinStatement()) (new JoinStatement())
->left() ->left()
->from(App::con()->prefix() . App::meta()::META_TABLE_NAME . ' F') ->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' F')
->on('P.post_id = F.post_id') ->on('P.post_id = F.post_id')
->statement() ->statement()
); );
$params['sql'] = "AND P.blog_id = '" . App::con()->escapeStr(App::blog()->id()) . "' " . $params['sql'] = "AND P.blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' " .
"AND F.meta_type = '" . My::META_PREFIX . "id' " . "AND F.meta_type = '" . My::META_PREFIX . "id' " .
"AND F.meta_id = '" . App::con()->escapeStr((string) $params['feed_id']) . "' "; "AND F.meta_id = '" . dcCore::app()->con->escapeStr((string) $params['feed_id']) . "' ";
unset($params['feed_id']); unset($params['feed_id']);
return App::blog()->getPosts($params, $count_only, $sql); $rs = dcCore::app()->blog?->getPosts($params, $count_only, $sql);
return is_null($rs) ? MetaRecord::newFromArray([]) : $rs;
} }
/** /**
* Get feed record. * Get feed record.
* *
* @param array<string, mixed> $params The query params * @param array<string,int|string|array> $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
@ -347,17 +332,17 @@ class ZoneclearFeedServer
'C.cat_title, C.cat_url, C.cat_desc '; 'C.cat_title, C.cat_url, C.cat_desc ';
} }
$strReq .= 'FROM ' . App::con()->prefix() . My::TABLE_NAME . ' Z ' . $strReq .= 'FROM ' . dcCore::app()->prefix . My::TABLE_NAME . ' Z ' .
'LEFT OUTER JOIN ' . App::con()->prefix() . App::categories()::CATEGORY_TABLE_NAME . ' C ON Z.cat_id = C.cat_id '; 'LEFT OUTER JOIN ' . dcCore::app()->prefix . dcCategories::CATEGORY_TABLE_NAME . ' C ON Z.cat_id = C.cat_id ';
if (!empty($params['from']) && is_string($params['from'])) { if (!empty($params['from']) && is_string($params['from'])) {
$strReq .= $params['from'] . ' '; $strReq .= $params['from'] . ' ';
} }
$strReq .= "WHERE Z.blog_id = '" . App::con()->escapeStr(App::blog()->id()) . "' "; $strReq .= "WHERE Z.blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' ";
if (isset($params['feed_type']) && is_string($params['feed_type'])) { if (isset($params['feed_type']) && is_string($params['feed_type'])) {
$strReq .= "AND Z.feed_type = '" . App::con()->escapeStr((string) $params['feed_type']) . "' "; $strReq .= "AND Z.feed_type = '" . dcCore::app()->con->escapeStr((string) $params['feed_type']) . "' ";
} else { } else {
$strReq .= "AND Z.feed_type = 'feed' "; $strReq .= "AND Z.feed_type = 'feed' ";
} }
@ -368,21 +353,21 @@ class ZoneclearFeedServer
} elseif (is_numeric($params['feed_id'])) { } elseif (is_numeric($params['feed_id'])) {
$params['feed_id'] = [(int) $params['feed_id']]; $params['feed_id'] = [(int) $params['feed_id']];
} }
$strReq .= 'AND Z.feed_id ' . App::con()->in($params['feed_id']); $strReq .= 'AND Z.feed_id ' . dcCore::app()->con->in($params['feed_id']);
} }
if (isset($params['feed_feed']) && is_string($params['feed_feed'])) { if (isset($params['feed_feed']) && is_string($params['feed_feed'])) {
$strReq .= "AND Z.feed_feed = '" . App::con()->escapeStr((string) $params['feed_feed']) . "' "; $strReq .= "AND Z.feed_feed = '" . dcCore::app()->con->escapeStr((string) $params['feed_feed']) . "' ";
} }
if (isset($params['feed_url']) && is_string($params['feed_url'])) { if (isset($params['feed_url']) && is_string($params['feed_url'])) {
$strReq .= "AND Z.feed_url = '" . App::con()->escapeStr((string) $params['feed_url']) . "' "; $strReq .= "AND Z.feed_url = '" . dcCore::app()->con->escapeStr((string) $params['feed_url']) . "' ";
} }
if (isset($params['feed_status'])) { if (isset($params['feed_status'])) {
$strReq .= 'AND Z.feed_status = ' . ((int) $params['feed_status']) . ' '; $strReq .= 'AND Z.feed_status = ' . ((int) $params['feed_status']) . ' ';
} }
if (!empty($params['q']) && is_string($params['q'])) { if (!empty($params['q']) && is_string($params['q'])) {
$q = App::con()->escapeStr((string) str_replace('*', '%', strtolower($params['q']))); $q = dcCore::app()->con->escapeStr((string) str_replace('*', '%', strtolower($params['q'])));
$strReq .= "AND LOWER(Z.feed_name) LIKE '" . $q . "' "; $strReq .= "AND LOWER(Z.feed_name) LIKE '" . $q . "' ";
} }
@ -392,7 +377,7 @@ class ZoneclearFeedServer
if (!$count_only) { if (!$count_only) {
if (!empty($params['order']) && is_string($params['order'])) { if (!empty($params['order']) && is_string($params['order'])) {
$strReq .= 'ORDER BY ' . App::con()->escapeStr((string) $params['order']) . ' '; $strReq .= 'ORDER BY ' . dcCore::app()->con->escapeStr((string) $params['order']) . ' ';
} else { } else {
$strReq .= 'ORDER BY Z.feed_upddt DESC '; $strReq .= 'ORDER BY Z.feed_upddt DESC ';
} }
@ -403,11 +388,11 @@ class ZoneclearFeedServer
$params['limit'] = (int) $params['limit']; $params['limit'] = (int) $params['limit'];
} }
if (is_int($params['limit']) || is_array($params['limit'])) { if (is_int($params['limit']) || is_array($params['limit'])) {
$strReq .= App::con()->limit($params['limit']); $strReq .= dcCore::app()->con->limit($params['limit']);
} }
} }
return new MetaRecord(App::con()->select($strReq)); return new MetaRecord(dcCore::app()->con->select($strReq));
} }
/** /**
@ -420,7 +405,7 @@ class ZoneclearFeedServer
$sql = new SelectStatement(); $sql = new SelectStatement();
$rs = $sql $rs = $sql
->column($sql->max('feed_id')) ->column($sql->max('feed_id'))
->from(App::con()->prefix() . My::TABLE_NAME) ->from(dcCore::app()->prefix . My::TABLE_NAME)
->select(); ->select();
return (int) $rs?->f(0) + 1; return (int) $rs?->f(0) + 1;
@ -435,14 +420,14 @@ class ZoneclearFeedServer
{ {
try { try {
# Cache writable ? # Cache writable ?
if (!is_writable(App::config()->cacheRoot())) { if (!is_writable(DC_TPL_CACHE)) {
throw new Exception("Can't write in cache fodler"); throw new Exception("Can't write in cache fodler");
} }
# Set file path # Set file path
$f_md5 = md5(App::blog()->id()); $f_md5 = md5((string) dcCore::app()->blog?->id);
$file = sprintf( $file = sprintf(
'%s/%s/%s/%s/%s.txt', '%s/%s/%s/%s/%s.txt',
App::config()->cacheRoot(), DC_TPL_CACHE,
My::id(), My::id(),
substr($f_md5, 0, 2), substr($f_md5, 0, 2),
substr($f_md5, 2, 2), substr($f_md5, 2, 2),
@ -495,7 +480,7 @@ class ZoneclearFeedServer
return false; return false;
} }
$tz = App::blog()->settings()->get('system')->get('blog_timezone'); $tz = dcCore::app()->blog?->settings->get('system')->get('blog_timezone');
Date::setTZ(is_string($tz) ? $tz : 'UTC'); Date::setTZ(is_string($tz) ? $tz : 'UTC');
$time = time(); $time = time();
@ -515,8 +500,8 @@ class ZoneclearFeedServer
$i = 0; $i = 0;
$cur_post = App::blog()->openPostCursor(); $cur_post = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME);
$cur_meta = App::meta()->openMetaCursor(); $cur_meta = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcMeta::META_TABLE_NAME);
while ($f->fetch()) { while ($f->fetch()) {
$row = new FeedRow($f); $row = new FeedRow($f);
@ -555,7 +540,7 @@ class ZoneclearFeedServer
# Set update time of this feed # Set update time of this feed
$this->enableFeed($row->id, (bool) $row->status, $time); $this->enableFeed($row->id, (bool) $row->status, $time);
App::con()->begin(); dcCore::app()->con->begin();
foreach ($feed->items as $item) { foreach ($feed->items as $item) {
$item_TS = $item->TS ? $item->TS : $time; $item_TS = $item->TS ? $item->TS : $time;
@ -570,7 +555,7 @@ class ZoneclearFeedServer
continue; continue;
} }
$item_link = App::con()->escapeStr((string) $item_link); $item_link = dcCore::app()->con->escapeStr((string) $item_link);
$is_new_published_entry = false; $is_new_published_entry = false;
# Not updated since last visit # Not updated since last visit
@ -591,15 +576,15 @@ class ZoneclearFeedServer
'P.post_id', 'P.post_id',
'P.post_status', 'P.post_status',
]) ])
->from($sql->as(App::con()->prefix() . App::blog()::POST_TABLE_NAME, 'P')) ->from($sql->as(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME, 'P'))
->join( ->join(
(new JoinStatement()) (new JoinStatement())
->inner() ->inner()
->from($sql->as(App::con()->prefix() . App::meta()::META_TABLE_NAME, 'M')) ->from($sql->as(dcCore::app()->prefix . dcMeta::META_TABLE_NAME, 'M'))
->on('P.post_id = M.post_id') ->on('P.post_id = M.post_id')
->statement() ->statement()
) )
->where('blog_id = ' . $sql->quote(App::blog()->id())) ->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id))
->and("meta_type = '" . My::META_PREFIX . "url'") ->and("meta_type = '" . My::META_PREFIX . "url'")
->and('meta_id = ' . $sql->quote($item_link)) ->and('meta_id = ' . $sql->quote($item_link))
->select(); ->select();
@ -624,14 +609,14 @@ class ZoneclearFeedServer
# Create entry # Create entry
if ($old_post->isEmpty()) { if ($old_post->isEmpty()) {
# Post # Post
$cur_post->setField('user_id', App::auth()->userID()); $cur_post->setField('user_id', dcCore::app()->auth->userID());
$cur_post->setField('post_format', 'xhtml'); $cur_post->setField('post_format', 'xhtml');
$cur_post->setField('post_status', $s->post_status_new ? App::blog()::POST_PUBLISHED : App::blog()::POST_UNPUBLISHED); $cur_post->setField('post_status', $s->post_status_new);
$cur_post->setField('post_open_comment', 0); $cur_post->setField('post_open_comment', 0);
$cur_post->setField('post_open_tb', 0); $cur_post->setField('post_open_tb', 0);
$post_id = App::auth()->sudo( $post_id = dcCore::app()->auth->sudo(
App::blog()->addPost(...), [dcCore::app()->blog, 'addPost'],
$cur_post $cur_post
); );
@ -644,22 +629,22 @@ class ZoneclearFeedServer
} else { } else {
$post_id = is_numeric($old_post->f('post_id')) ? (int) $old_post->f('post_id') : 0; $post_id = is_numeric($old_post->f('post_id')) ? (int) $old_post->f('post_id') : 0;
App::auth()->sudo( dcCore::app()->auth->sudo(
App::blog()->updPost(...), [dcCore::app()->blog, 'updPost'],
$post_id, $post_id,
$cur_post $cur_post
); );
# Quick delete old meta # Quick delete old meta
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(App::con()->prefix() . App::meta()::META_TABLE_NAME) $sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME)
->where('post_id = ' . $post_id) ->where('post_id = ' . $post_id)
->and($sql->like('meta_type', My::META_PREFIX . '%')) ->and($sql->like('meta_type', My::META_PREFIX . '%'))
->delete(); ->delete();
# Delete old tags # Delete old tags
App::auth()->sudo( dcCore::app()->auth->sudo(
App::meta()->delPostMeta(...), [dcCore::app()->meta, 'delPostMeta'],
$post_id, $post_id,
'tag' 'tag'
); );
@ -698,11 +683,11 @@ class ZoneclearFeedServer
$cur_meta->insert(); $cur_meta->insert();
# Add new tags # Add new tags
$tags = App::meta()->splitMetaValues($row->tags); $tags = dcCore::app()->meta->splitMetaValues($row->tags);
if ($row->get_tags) { if ($row->get_tags) {
# Some feed subjects contains more than one tag # Some feed subjects contains more than one tag
foreach ($item->subject as $subjects) { foreach ($item->subject as $subjects) {
$tmp = App::meta()->splitMetaValues($subjects); $tmp = dcCore::app()->meta->splitMetaValues($subjects);
$tags = array_merge($tags, $tmp); $tags = array_merge($tags, $tmp);
} }
$tags = array_unique($tags); $tags = array_unique($tags);
@ -724,33 +709,33 @@ class ZoneclearFeedServer
} }
if (!in_array($tag, $formated_tags)) { if (!in_array($tag, $formated_tags)) {
$formated_tags[] = $tag; $formated_tags[] = $tag;
App::auth()->sudo( dcCore::app()->auth->sudo(
App::meta()->delPostMeta(...), [dcCore::app()->meta, 'delPostMeta'],
$post_id, $post_id,
'tag', 'tag',
App::meta()::sanitizeMetaID($tag) dcMeta::sanitizeMetaID($tag)
); );
App::auth()->sudo( dcCore::app()->auth->sudo(
App::meta()->setPostMeta(...), [dcCore::app()->meta, 'setPostMeta'],
$post_id, $post_id,
'tag', 'tag',
App::meta()::sanitizeMetaID($tag) dcMeta::sanitizeMetaID($tag)
); );
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
App::con()->rollback(); dcCore::app()->con->rollback();
$this->enableUser(false); $this->enableUser(false);
$this->unlockUpdate(); $this->unlockUpdate();
throw $e; throw $e;
} }
} }
App::con()->commit(); dcCore::app()->con->commit();
} }
# --BEHAVIOR-- zoneclearFeedServerAfterCheckFeedUpdate -- FeedRow # --BEHAVIOR-- zoneclearFeedServerAfterCheckFeedUpdate -- FeedRow
App::behavior()->callBehavior('zoneclearFeedServerAfterCheckFeedUpdate', $row); dcCore::app()->callBehavior('zoneclearFeedServerAfterCheckFeedUpdate', $row);
} }
} }
if ($enabled) { if ($enabled) {
@ -771,18 +756,21 @@ class ZoneclearFeedServer
# Enable # Enable
if ($enable) { if ($enable) {
// backup current user // backup current user
if (!App::auth()->userID()) { if (!is_null(dcCore::app()->auth->userID()) && !is_string(dcCore::app()->auth->userID())) {
throw new Exception('Unable to backup user'); throw new Exception('Unable to backup user');
} }
$this->user = App::auth()->userID(); $this->user = dcCore::app()->auth->userID();
// set zcfs posts user // set zcfs posts user
if (!App::auth()->checkUser($this->settings->user)) { if (!dcCore::app()->auth->checkUser($this->settings->user)) {
throw new Exception('Unable to set user'); throw new Exception('Unable to set user');
} }
# Disable # Disable
} else { } else {
// auth on branch My goes readonly
//dcCore::app()->auth = null;
//dcCore::app()->auth = new dcAuth();
// restore current user // restore current user
App::auth()->checkUser($this->user ?? ''); dcCore::app()->auth->checkUser($this->user ?? '');
} }
} }
@ -797,7 +785,7 @@ class ZoneclearFeedServer
{ {
try { try {
$feed_reader = new Reader(); $feed_reader = new Reader();
$feed_reader->setCacheDir(App::config()->cacheRoot()); $feed_reader->setCacheDir(DC_TPL_CACHE);
$feed_reader->setTimeout(self::NET_HTTP_TIMEOUT); $feed_reader->setTimeout(self::NET_HTTP_TIMEOUT);
$feed_reader->setMaxRedirects(self::NET_HTTP_MAX_REDIRECT); $feed_reader->setMaxRedirects(self::NET_HTTP_MAX_REDIRECT);
$feed_reader->setUserAgent(self::NET_HTTP_AGENT); $feed_reader->setUserAgent(self::NET_HTTP_AGENT);
@ -813,7 +801,7 @@ class ZoneclearFeedServer
*/ */
private function trigger(): void private function trigger(): void
{ {
App::blog()->triggerBlog(); dcCore::app()->blog?->triggerBlog();
} }
/** /**
@ -876,7 +864,7 @@ class ZoneclearFeedServer
# Get super admins # Get super admins
$sql = new SelectStatement(); $sql = new SelectStatement();
$rs = $sql $rs = $sql
->from(App::con()->prefix() . App::auth()::USER_TABLE_NAME) ->from(dcCore::app()->prefix . dcAuth::USER_TABLE_NAME)
->columns([ ->columns([
'user_id', 'user_id',
'user_super', 'user_super',
@ -890,7 +878,7 @@ class ZoneclearFeedServer
if (!is_null($rs) && !$rs->isEmpty()) { if (!is_null($rs) && !$rs->isEmpty()) {
while ($rs->fetch()) { while ($rs->fetch()) {
$user_cn = App::users()->getUserCN( $user_cn = dcUtils::getUserCN(
$rs->f('user_id'), $rs->f('user_id'),
$rs->f('user_name'), $rs->f('user_name'),
$rs->f('user_firstname'), $rs->f('user_firstname'),
@ -910,22 +898,22 @@ class ZoneclearFeedServer
'U.user_firstname', 'U.user_firstname',
'U.user_displayname', 'U.user_displayname',
]) ])
->from($sql->as(App::con()->prefix() . App::auth()::USER_TABLE_NAME, 'U')) ->from($sql->as(dcCore::app()->prefix . dcAuth::USER_TABLE_NAME, 'U'))
->join( ->join(
(new JoinStatement()) (new JoinStatement())
->left() ->left()
->from($sql->as(App::con()->prefix() . App::auth()::PERMISSIONS_TABLE_NAME, 'P')) ->from($sql->as(dcCore::app()->prefix . dcAuth::PERMISSIONS_TABLE_NAME, 'P'))
->on('U.user_id = P.user_id') ->on('U.user_id = P.user_id')
->statement() ->statement()
) )
->where('U.user_status = 1') ->where('U.user_status = 1')
->and('P.blog_id = ' . $sql->quote(App::blog()->id())) ->and('P.blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id))
->and($sql->like('P.permissions', '%|admin|%')) ->and($sql->like('P.permissions', '%|admin|%'))
->select(); ->select();
if (!is_null($rs) && !$rs->isEmpty()) { if (!is_null($rs) && !$rs->isEmpty()) {
while ($rs->fetch()) { while ($rs->fetch()) {
$user_cn = App::users()->getUserCN( $user_cn = dcUtils::getUserCN(
$rs->f('user_id'), $rs->f('user_id'),
$rs->f('user_name'), $rs->f('user_name'),
$rs->f('user_firstname'), $rs->f('user_firstname'),
@ -955,7 +943,7 @@ class ZoneclearFeedServer
]); ]);
# --BEHAVIOR-- zoneclearFeedServerPublicUrlTypes -- ArrayObject # --BEHAVIOR-- zoneclearFeedServerPublicUrlTypes -- ArrayObject
App::behavior()->callBehavior('zoneclearFeedServerPublicUrlTypes', $types); dcCore::app()->callBehavior('zoneclearFeedServerPublicUrlTypes', $types);
return $types->getArrayCopy(); return $types->getArrayCopy();
} }