postWidgetText/index.php

94 lines
2.7 KiB
PHP
Raw Normal View History

2021-09-10 19:06:49 +00:00
<?php
2021-09-10 19:18:51 +00:00
/**
* @brief postWidgetText, a plugin for Dotclear 2
2021-11-06 15:11:19 +00:00
*
2021-09-10 19:18:51 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-06 15:11:19 +00:00
*
2021-09-10 19:18:51 +00:00
* @author Jean-Christian Denis and Contributors
2021-11-06 15:11:19 +00:00
*
2021-09-10 19:18:51 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-09-10 19:06:49 +00:00
if (!defined('DC_CONTEXT_ADMIN')) {
2021-09-10 19:18:51 +00:00
return null;
2021-09-10 19:06:49 +00:00
}
2022-11-15 21:05:23 +00:00
dcPage::check(dcCore::app()->auth->makePermissions([
2022-11-15 21:07:37 +00:00
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]));
2021-09-10 19:06:49 +00:00
2022-11-15 21:05:23 +00:00
$pwt = new postWidgetText();
2021-09-10 19:06:49 +00:00
# Delete widgets
if (!empty($_POST['save']) && !empty($_POST['widgets'])) {
2021-09-10 19:18:51 +00:00
try {
2021-11-06 15:11:19 +00:00
foreach ($_POST['widgets'] as $k => $id) {
$id = (int) $id;
2021-09-10 19:18:51 +00:00
$pwt->delWidget($id);
}
2022-11-15 21:05:23 +00:00
dcAdminNotices::addSuccessNotice(
2021-09-10 19:18:51 +00:00
__('Posts widgets successfully delete.')
);
2021-10-29 22:36:04 +00:00
if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']);
} else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__));
2021-10-29 22:36:04 +00:00
}
2021-11-06 15:11:19 +00:00
} catch (Exception $e) {
2022-11-15 21:05:23 +00:00
dcCore::app()->error->add($e->getMessage());
2021-09-10 19:18:51 +00:00
}
2021-09-10 19:06:49 +00:00
}
2021-10-29 22:36:04 +00:00
# filters
2022-11-15 21:05:23 +00:00
$filter = new adminGenericFilter(dcCore::app(), 'pwt');
2021-10-29 22:36:04 +00:00
$filter->add(dcAdminFilters::getPageFilter());
$params = $filter->params();
2021-09-10 19:06:49 +00:00
# Get posts with text widget
try {
2021-11-06 15:11:19 +00:00
$posts = $pwt->getWidgets($params);
$counter = $pwt->getWidgets($params, true);
2022-11-15 21:05:23 +00:00
$posts_list = new listPostWidgetText(dcCore::app(), $posts, $counter->f(0));
2021-11-06 15:11:19 +00:00
} catch (Exception $e) {
2022-11-15 21:05:23 +00:00
dcCore::app()->error->add($e->getMessage());
2022-12-23 13:10:54 +00:00
$posts_list = null;
2021-09-10 19:06:49 +00:00
}
# Display
echo '
2021-10-29 22:36:04 +00:00
<html><head><title>' . __('Post widget text') . '</title>' .
dcPage::jsModuleLoad(basename(__DIR__) . '/js/index.js') .
$filter->js(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '
2021-09-10 19:06:49 +00:00
</head>
2021-10-29 22:36:04 +00:00
<body>' .
dcPage::breadcrumb([
2021-11-06 15:11:19 +00:00
__('Plugins') => '',
2022-11-15 21:07:37 +00:00
__('Posts widgets') => '',
2021-11-06 15:11:19 +00:00
]) .
2021-10-29 22:36:04 +00:00
dcPage::notices();
2022-12-23 13:10:54 +00:00
if ($posts_list) {
$filter->display('admin.plugin.' . basename(__DIR__), form::hidden('p', basename(__DIR__)));
2021-10-29 22:36:04 +00:00
2022-12-23 13:10:54 +00:00
$posts_list->display(
$filter->page,
$filter->nb,
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)) . '" method="post" id="form-entries">' .
'%s' .
'<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' .
'<input id="do-action" type="submit" name="save" value="' . __('Delete selected widgets') . '" /></p>' .
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . basename(__DIR__), array_merge(['p' => basename(__DIR__)], $filter->values(true))) .
dcCore::app()->formNonce() .
'</div>' .
'</form>'
);
}
2021-09-10 19:06:49 +00:00
2021-11-06 15:11:19 +00:00
echo '</body></html>';