2022-12-10 21:20:42 +00:00
|
|
|
<?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
|
|
|
|
*/
|
2023-05-07 22:40:58 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\zoneclearFeedServer;
|
|
|
|
|
|
|
|
use ArrayObject;
|
|
|
|
use dcCore;
|
|
|
|
use dcUtils;
|
2023-08-16 20:03:40 +00:00
|
|
|
use Dotclear\Core\Backend\Combos;
|
|
|
|
use Dotclear\Core\Backend\Filter\{
|
|
|
|
Filter,
|
|
|
|
Filters,
|
|
|
|
FiltersLibrary
|
|
|
|
};
|
2023-05-07 22:40:58 +00:00
|
|
|
use Dotclear\Helper\Html\Html;
|
|
|
|
use Exception;
|
2022-12-10 21:20:42 +00:00
|
|
|
|
|
|
|
/**
|
2023-05-07 22:40:58 +00:00
|
|
|
* Backend feed posts list filters.
|
2022-12-10 21:20:42 +00:00
|
|
|
*/
|
2023-08-16 20:03:40 +00:00
|
|
|
class PostsFilter extends Filters
|
2022-12-10 21:20:42 +00:00
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
2023-05-07 22:40:58 +00:00
|
|
|
// use user posts pref
|
|
|
|
parent::__construct('posts');
|
2022-12-10 21:20:42 +00:00
|
|
|
|
2023-05-07 22:40:58 +00:00
|
|
|
$filters = new ArrayObject([
|
2023-08-16 20:03:40 +00:00
|
|
|
FiltersLibrary::getPageFilter(),
|
2022-12-10 21:20:42 +00:00
|
|
|
$this->getPostUserFilter(),
|
|
|
|
$this->getPostCategoriesFilter(),
|
|
|
|
$this->getPostStatusFilter(),
|
|
|
|
$this->getPostMonthFilter(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
# --BEHAVIOR-- zcfsPostFilter
|
|
|
|
dcCore::app()->callBehavior('zcfsPostFilter', $filters);
|
|
|
|
|
|
|
|
$filters = $filters->getArrayCopy();
|
|
|
|
|
|
|
|
$this->add($filters);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts users select
|
2023-06-30 20:55:59 +00:00
|
|
|
*
|
2023-08-16 20:03:40 +00:00
|
|
|
* @return null|Filter
|
2022-12-10 21:20:42 +00:00
|
|
|
*/
|
2023-06-30 20:55:59 +00:00
|
|
|
public function getPostUserFilter()
|
2022-12-10 21:20:42 +00:00
|
|
|
{
|
|
|
|
$users = null;
|
|
|
|
|
|
|
|
try {
|
2023-05-07 22:40:58 +00:00
|
|
|
$users = dcCore::app()->blog?->getPostsUsers();
|
|
|
|
if (is_null($users) || $users->isEmpty()) {
|
2022-12-10 21:20:42 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-08-16 20:03:40 +00:00
|
|
|
$combo = Combos::getUsersCombo($users);
|
2022-12-10 21:20:42 +00:00
|
|
|
dcUtils::lexicalKeySort($combo);
|
|
|
|
|
2023-08-16 20:03:40 +00:00
|
|
|
return (new Filter('user_id'))
|
2022-12-10 21:20:42 +00:00
|
|
|
->param()
|
|
|
|
->title(__('Author:'))
|
|
|
|
->options(array_merge(
|
|
|
|
['-' => ''],
|
|
|
|
$combo
|
|
|
|
))
|
|
|
|
->prime(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts categories select
|
2023-06-30 20:55:59 +00:00
|
|
|
*
|
2023-08-16 20:03:40 +00:00
|
|
|
* @return null|Filter
|
2022-12-10 21:20:42 +00:00
|
|
|
*/
|
2023-06-30 20:55:59 +00:00
|
|
|
public function getPostCategoriesFilter()
|
2022-12-10 21:20:42 +00:00
|
|
|
{
|
|
|
|
$categories = null;
|
|
|
|
|
|
|
|
try {
|
2023-05-07 22:40:58 +00:00
|
|
|
$categories = dcCore::app()->blog?->getCategories();
|
|
|
|
if (is_null($categories) || $categories->isEmpty()) {
|
2022-12-10 21:20:42 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$combo = [
|
|
|
|
'-' => '',
|
|
|
|
__('(No cat)') => 'NULL',
|
|
|
|
];
|
|
|
|
while ($categories->fetch()) {
|
2023-05-07 22:40:58 +00:00
|
|
|
if (is_numeric($categories->f('level')) && is_string($categories->f('cat_title'))) {
|
|
|
|
$combo[
|
|
|
|
str_repeat(' ', ((int) $categories->f('level') - 1) * 4) .
|
|
|
|
Html::escapeHTML($categories->f('cat_title')) . ' (' . $categories->f('nb_post') . ')'
|
|
|
|
] = $categories->f('cat_id');
|
|
|
|
}
|
2022-12-10 21:20:42 +00:00
|
|
|
}
|
|
|
|
|
2023-08-16 20:03:40 +00:00
|
|
|
return (new Filter('cat_id'))
|
2022-12-10 21:20:42 +00:00
|
|
|
->param()
|
|
|
|
->title(__('Category:'))
|
|
|
|
->options($combo)
|
|
|
|
->prime(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts status select
|
|
|
|
*/
|
2023-08-16 20:03:40 +00:00
|
|
|
public function getPostStatusFilter(): Filter
|
2022-12-10 21:20:42 +00:00
|
|
|
{
|
2023-08-16 20:03:40 +00:00
|
|
|
return (new Filter('status'))
|
2022-12-10 21:20:42 +00:00
|
|
|
->param('post_status')
|
|
|
|
->title(__('Status:'))
|
|
|
|
->options(array_merge(
|
|
|
|
['-' => ''],
|
2023-08-16 20:03:40 +00:00
|
|
|
Combos::getPostStatusesCombo()
|
2022-12-10 21:20:42 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts by month select
|
2023-06-30 20:55:59 +00:00
|
|
|
*
|
2023-08-16 20:03:40 +00:00
|
|
|
* @return null|Filter
|
2022-12-10 21:20:42 +00:00
|
|
|
*/
|
2023-06-30 20:55:59 +00:00
|
|
|
public function getPostMonthFilter()
|
2022-12-10 21:20:42 +00:00
|
|
|
{
|
|
|
|
$dates = null;
|
|
|
|
|
|
|
|
try {
|
2023-05-07 22:40:58 +00:00
|
|
|
$dates = dcCore::app()->blog?->getDates(['type' => 'month']);
|
|
|
|
if (is_null($dates) || $dates->isEmpty()) {
|
2022-12-10 21:20:42 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-08-16 20:03:40 +00:00
|
|
|
return (new Filter('month'))
|
2022-12-10 21:20:42 +00:00
|
|
|
->param('post_month', function ($f) { return substr($f[0], 4, 2); })
|
|
|
|
->param('post_year', function ($f) { return substr($f[0], 0, 4); })
|
|
|
|
->title(__('Month:'))
|
|
|
|
->options(array_merge(
|
|
|
|
['-' => ''],
|
2023-08-16 20:03:40 +00:00
|
|
|
Combos::getDatesCombo($dates)
|
2022-12-10 21:20:42 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|