2023-05-07 22:40:58 +00:00
|
|
|
<?php
|
2023-10-14 13:41:43 +00:00
|
|
|
|
2023-05-07 22:40:58 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\zoneclearFeedServer;
|
|
|
|
|
|
|
|
use ArrayObject;
|
2023-10-14 13:41:43 +00:00
|
|
|
use Dotclear\App;
|
2023-08-16 20:03:40 +00:00
|
|
|
use Dotclear\Core\Backend\Favorites;
|
2023-05-07 22:40:58 +00:00
|
|
|
use Dotclear\Database\MetaRecord;
|
|
|
|
use Dotclear\Helper\Html\Form\{
|
|
|
|
Div,
|
|
|
|
Link,
|
|
|
|
Para,
|
|
|
|
Text
|
|
|
|
};
|
|
|
|
use Dotclear\Helper\Html\Html;
|
|
|
|
|
|
|
|
/**
|
2023-10-14 13:41:43 +00:00
|
|
|
* @brief zoneclearFeedServer backend behaviors class.
|
|
|
|
* @ingroup zoneclearFeedServer
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
2023-05-07 22:40:58 +00:00
|
|
|
*/
|
|
|
|
class BackendBehaviors
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* User dashboard favorites icon.
|
|
|
|
*/
|
2023-08-16 20:03:40 +00:00
|
|
|
public static function adminDashboardFavoritesV2(Favorites $favs): void
|
2023-05-07 22:40:58 +00:00
|
|
|
{
|
|
|
|
$favs->register(My::id(), [
|
|
|
|
'title' => My::name(),
|
2023-08-16 20:03:40 +00:00
|
|
|
'url' => My::manageUrl(),
|
|
|
|
'small-icon' => My::icons(),
|
|
|
|
'large-icon' => My::icons(),
|
2023-10-14 13:41:43 +00:00
|
|
|
'permissions' => App::auth()->makePermissions([
|
|
|
|
App::auth()::PERMISSION_USAGE,
|
|
|
|
App::auth()::PERMISSION_CONTENT_ADMIN,
|
2023-05-07 22:40:58 +00:00
|
|
|
]),
|
|
|
|
// update user dashboard favorites icon with nb of updated feeds
|
|
|
|
'dashboard_cb' => function (ArrayObject $fav): void {
|
|
|
|
$count = ZoneclearFeedServer::instance()->getFeeds(['feed_status' => '0'], true)->f(0);
|
|
|
|
if (!$count || !is_numeric($count)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$fav['title'] .= '<br />' . sprintf(__('%s feed disabled', '%s feeds disabled', (int) $count), (int) $count);
|
2023-08-16 20:03:40 +00:00
|
|
|
$fav['large-icon'] = My::fileURL('icon-update.svg');
|
|
|
|
$fav['url'] = My::manageUrl(['part' => 'feeds', 'sortby' => 'feed_status', 'order' => 'asc']);
|
2023-05-07 22:40:58 +00:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists columns user preference.
|
|
|
|
*/
|
|
|
|
public static function adminColumnsListsV2(ArrayObject $cols): void
|
|
|
|
{
|
|
|
|
// feeds
|
|
|
|
$cols[My::id() . 'feeds'] = [
|
|
|
|
__('Feeds server: Feeds'),
|
|
|
|
[
|
|
|
|
'desc' => [true, __('Feed')],
|
|
|
|
'period' => [true, __('Frequency')],
|
|
|
|
'update' => [true, __('Last update')],
|
|
|
|
'entries' => [true, __('Entries')],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
// feed posts
|
|
|
|
$cols[My::id() . 'posts'] = [
|
|
|
|
__('Feeds server: Entries'),
|
|
|
|
[
|
|
|
|
'date' => [true, __('Date')],
|
|
|
|
'category' => [true, __('Category')],
|
|
|
|
'author' => [true, __('Author')],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
// posts feed
|
|
|
|
$cols['posts'][1]['feed'] = [true, __('Feed server')];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists filter.
|
|
|
|
*/
|
|
|
|
public static function adminFiltersListsV2(ArrayObject $sorts): void
|
|
|
|
{
|
|
|
|
// feeds
|
|
|
|
$sorts[My::id() . 'feeds'] = [
|
|
|
|
__('Feeds server: Feeds'),
|
|
|
|
Combo::feedsSortby(),
|
|
|
|
'lowername',
|
|
|
|
'asc',
|
|
|
|
[__('feeds per page'), 30],
|
|
|
|
];
|
|
|
|
// feed posts
|
|
|
|
$sorts[My::id() . 'posts'] = [
|
|
|
|
__('Feeds server: Entries'),
|
|
|
|
Combo::postsSortby(),
|
|
|
|
'post_dt',
|
|
|
|
'desc',
|
|
|
|
[__('entries per page'), 30],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add head column to posts list.
|
|
|
|
*/
|
|
|
|
public static function adminPostListHeaderV2(MetaRecord $rs, ArrayObject $cols): void
|
|
|
|
{
|
2023-05-08 07:41:15 +00:00
|
|
|
$cols['feed'] = (new Para(null, 'th'))->text(__('Feed'))->extra('scope="col"')->render();
|
2023-05-07 22:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add body column to posts list.
|
|
|
|
*/
|
|
|
|
public static function adminPostListValueV2(MetaRecord $rs, ArrayObject $cols): void
|
|
|
|
{
|
2023-10-14 13:41:43 +00:00
|
|
|
$rs_meta = App::meta()->getMetadata(['post_id' => $rs->f('post_id'), 'meta_type' => My::META_PREFIX . 'id']);
|
2023-05-07 22:40:58 +00:00
|
|
|
if ($rs_meta->isEmpty()) {
|
|
|
|
$item = (new Text('', '-'));
|
|
|
|
} else {
|
|
|
|
$row = new FeedRow(ZoneclearFeedServer::instance()->getFeeds(['feed_id' => $rs_meta->f('meta_id')]));
|
|
|
|
$item = (new Link())
|
2023-08-16 20:03:40 +00:00
|
|
|
->href(My::manageUrl(['part' => 'feed', 'feed_id' => $row->id]) . '#feed')
|
2023-05-07 22:40:58 +00:00
|
|
|
->title(__('edit feed'))
|
|
|
|
->text(Html::escapeHTML($row->name));
|
|
|
|
}
|
|
|
|
$cols['feed'] = (new Para(null, 'td'))->class('nowrap')->items([$item])->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add info about feed on post page sidebar.
|
|
|
|
*/
|
|
|
|
public static function adminPostHeaders(): string
|
|
|
|
{
|
2023-08-16 20:03:40 +00:00
|
|
|
return My::jsLoad('post');
|
2023-05-07 22:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add info about feed on post page sidebar.
|
|
|
|
*/
|
|
|
|
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void
|
|
|
|
{
|
|
|
|
// nullsafe
|
2023-10-14 13:41:43 +00:00
|
|
|
if (!App::blog()->isDefined()) {
|
2023-05-07 22:40:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// not feed on new post
|
|
|
|
if ($post === null || $post->f('post_type') != 'post') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-14 13:41:43 +00:00
|
|
|
$url = App::meta()->getMetadata([
|
2023-05-07 22:40:58 +00:00
|
|
|
'post_id' => $post->f('post_id'),
|
|
|
|
'meta_type' => My::META_PREFIX . 'url',
|
|
|
|
'limit' => 1,
|
|
|
|
]);
|
|
|
|
$url = $url->isEmpty() ? '' : $url->f('meta_id');
|
|
|
|
if (!$url) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-14 13:41:43 +00:00
|
|
|
$author = App::meta()->getMetadata([
|
2023-05-07 22:40:58 +00:00
|
|
|
'post_id' => $post->f('post_id'),
|
|
|
|
'meta_type' => My::META_PREFIX . 'author',
|
|
|
|
'limit' => 1,
|
|
|
|
]);
|
|
|
|
$author = $author->isEmpty() ? '' : $author->f('meta_id');
|
|
|
|
|
2023-10-14 13:41:43 +00:00
|
|
|
$site = App::meta()->getMetadata([
|
2023-05-07 22:40:58 +00:00
|
|
|
'post_id' => $post->f('post_id'),
|
|
|
|
'meta_type' => My::META_PREFIX . 'site',
|
|
|
|
'limit' => 1,
|
|
|
|
]);
|
|
|
|
$site = $site->isEmpty() ? '' : $site->f('meta_id');
|
|
|
|
|
2023-10-14 13:41:43 +00:00
|
|
|
$sitename = App::meta()->getMetadata([
|
2023-05-07 22:40:58 +00:00
|
|
|
'post_id' => $post->f('post_id'),
|
|
|
|
'meta_type' => My::META_PREFIX . 'sitename',
|
|
|
|
'limit' => 1,
|
|
|
|
]);
|
|
|
|
$sitename = $sitename->isEmpty() ? '' : $sitename->f('meta_id');
|
|
|
|
|
|
|
|
$edit = (new Text('', ''));
|
2023-10-14 13:41:43 +00:00
|
|
|
if (App::auth()->check(App::auth()->makePermissions([
|
|
|
|
App::auth()::PERMISSION_CONTENT_ADMIN,
|
|
|
|
]), App::blog()->id())
|
2023-05-07 22:40:58 +00:00
|
|
|
) {
|
2023-10-14 13:41:43 +00:00
|
|
|
$fid = App::meta()->getMetadata([
|
2023-05-07 22:40:58 +00:00
|
|
|
'post_id' => $post->f('post_id'),
|
|
|
|
'meta_type' => My::META_PREFIX . 'id',
|
|
|
|
'limit' => 1,
|
|
|
|
]);
|
|
|
|
if (!$fid->isEmpty()) {
|
|
|
|
$edit = (new Link())
|
2023-08-16 20:03:40 +00:00
|
|
|
->href(My::manageUrl(['part' => 'feed', 'feed_id' => $fid->f('meta_id')]))
|
2023-05-07 22:40:58 +00:00
|
|
|
->text(__('Edit this feed'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sidebar_items['options-box']['items'][My::id()] = (new Div('zcfs'))
|
|
|
|
->items([
|
|
|
|
(new Text('h5', __('Feed source'))),
|
|
|
|
(new Para())
|
|
|
|
->separator('<br />')
|
|
|
|
->items([
|
|
|
|
(new Link())
|
|
|
|
->href($url)
|
|
|
|
->title($author . ' - ' . $url)
|
|
|
|
->text(__('feed URL')),
|
|
|
|
(new Link())
|
|
|
|
->href($site)
|
|
|
|
->title($sitename . ' - ' . $site)
|
|
|
|
->text(__('site URL')),
|
|
|
|
$edit,
|
|
|
|
]),
|
|
|
|
])
|
|
|
|
->render();
|
|
|
|
}
|
|
|
|
}
|