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 adminGenericFilterV2;
|
|
|
|
use dcAdminCombos;
|
|
|
|
use dcAdminFilter;
|
|
|
|
use dcAdminFilters;
|
|
|
|
use dcCore;
|
|
|
|
use dcUtils;
|
|
|
|
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-05-07 22:40:58 +00:00
|
|
|
class PostsFilter extends adminGenericFilterV2
|
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([
|
2022-12-10 21:20:42 +00:00
|
|
|
dcAdminFilters::getPageFilter(),
|
|
|
|
$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
|
|
|
*
|
|
|
|
* @return null|dcAdminFilter
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$combo = dcAdminCombos::getUsersCombo($users);
|
|
|
|
dcUtils::lexicalKeySort($combo);
|
|
|
|
|
|
|
|
return (new dcAdminFilter('user_id'))
|
|
|
|
->param()
|
|
|
|
->title(__('Author:'))
|
|
|
|
->options(array_merge(
|
|
|
|
['-' => ''],
|
|
|
|
$combo
|
|
|
|
))
|
|
|
|
->prime(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts categories select
|
2023-06-30 20:55:59 +00:00
|
|
|
*
|
|
|
|
* @return null|dcAdminFilter
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return (new dcAdminFilter('cat_id'))
|
|
|
|
->param()
|
|
|
|
->title(__('Category:'))
|
|
|
|
->options($combo)
|
|
|
|
->prime(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts status select
|
|
|
|
*/
|
|
|
|
public function getPostStatusFilter(): dcAdminFilter
|
|
|
|
{
|
|
|
|
return (new dcAdminFilter('status'))
|
|
|
|
->param('post_status')
|
|
|
|
->title(__('Status:'))
|
|
|
|
->options(array_merge(
|
|
|
|
['-' => ''],
|
|
|
|
dcAdminCombos::getPostStatusesCombo()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts by month select
|
2023-06-30 20:55:59 +00:00
|
|
|
*
|
|
|
|
* @return null|dcAdminFilter
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (new dcAdminFilter('month'))
|
|
|
|
->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(
|
|
|
|
['-' => ''],
|
|
|
|
dcAdminCombos::getDatesCombo($dates)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|