postWidgetText/index.php

94 lines
2.6 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([
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 {
2022-11-15 21:05:23 +00:00
dcCore::app()->adminurl->redirect('admin.plugin.postWidgetText');
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());
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::jsLoad(dcPage::getPF('postWidgetText/js/index.js')) .
2022-11-15 21:05:23 +00:00
$filter->js(dcCore::app()->adminurl->get('admin.plugin.postWidgetText')) . '
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') => '',
2021-10-29 22:36:04 +00:00
__('Posts widgets') => ''
2021-11-06 15:11:19 +00:00
]) .
2021-10-29 22:36:04 +00:00
dcPage::notices();
$filter->display('admin.plugin.postWidgetText', form::hidden('p', 'postWidgetText'));
2021-11-06 15:11:19 +00:00
$posts_list->display(
$filter->page,
$filter->nb,
2022-11-15 21:05:23 +00:00
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.postWidgetText') . '" method="post" id="form-entries">' .
2021-10-29 22:36:04 +00:00
'%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>' .
2022-11-15 21:05:23 +00:00
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.postWidgetText', array_merge(['p' => 'postWidgetText'], $filter->values(true))) .
dcCore::app()->formNonce() .
2021-10-29 22:36:04 +00:00
'</div>' .
2021-09-10 19:18:51 +00:00
'</form>'
2021-09-10 19:06:49 +00:00
);
# Footer
dcPage::helpBlock('postWidgetText');
2021-11-06 15:11:19 +00:00
echo '</body></html>';