use Dotclear Helper

master
Jean-Christian Paul Denis 2023-04-08 11:24:53 +02:00
parent 66500016ab
commit 642ea68a41
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
1 changed files with 70 additions and 72 deletions

View File

@ -21,10 +21,19 @@ use dcCore;
use dcPostsActions; use dcPostsActions;
use dcPage; use dcPage;
use dcRecord; use dcRecord;
use Dotclear\Helper\Html\Form\{
Datetime,
Form,
Hidden,
Label,
Option,
Para,
Text,
Select,
Submit
};
use Dotclear\Helper\Html\Html;
use Exception; use Exception;
use html;
use form;
use formSelectOption;
/** /**
* @ingroup DC_PLUGIN_POSTEXPIRED * @ingroup DC_PLUGIN_POSTEXPIRED
@ -86,7 +95,8 @@ class BackendBehaviors
'title' => __('Expired date'), 'title' => __('Expired date'),
'items' => self::fieldsPostExpired( 'items' => self::fieldsPostExpired(
$post->f('post_type'), $post->f('post_type'),
(int) $post->f('post_id') (int) $post->f('post_id'),
true
), ),
]; ];
} }
@ -157,7 +167,7 @@ class BackendBehaviors
$pa->beginPage( $pa->beginPage(
dcPage::breadcrumb([ dcPage::breadcrumb([
html::escapeHTML(dcCore::app()->blog->name) => '', Html::escapeHTML(dcCore::app()->blog->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true), $pa->getCallerTitle() => $pa->getRedirection(true),
__('Add expired date to this selection') => '', __('Add expired date to this selection') => '',
]), ]),
@ -166,16 +176,18 @@ class BackendBehaviors
); );
echo echo
'<form action="' . $pa->getURI() . '" method="post">' . (new Form('peadd'))->method('post')->action($pa->getURI())->fields([
$pa->getCheckboxes() . (new Text('', $pa->getCheckboxes())),
(new Para())->items(array_merge(
implode('', self::fieldsPostExpired($posts->f('post_type'))) . self::fieldsPostExpired($posts->f('post_type'), null, false),
$pa->hiddenFields(),
dcCore::app()->formNonce() . [
$pa->getHiddenFields() . dcCore::app()->formNonce(false),
form::hidden(['action'], 'post_expired_add') . (new Hidden(['action'], 'post_expired_add')),
'<input type="submit" value="' . __('Save') . '" /></p>' . (new Submit(['do']))->value(__('Save')),
'</form>'; ],
)),
])->render();
$pa->endPage(); $pa->endPage();
} }
@ -258,9 +270,11 @@ class BackendBehaviors
* Expired date form fields * Expired date form fields
* *
* @param string $post_type Posts type * @param string $post_type Posts type
* @return array Array of HTML form fields * @param null|int $post_id Post ID
* @param bool $render Render fileds to HTML
* @return array Array of object form fields
*/ */
private static function fieldsPostExpired(string $post_type, ?int $post_id = null): array private static function fieldsPostExpired(string $post_type, ?int $post_id = null, bool $render = true): array
{ {
$fields = $post_expired = []; $fields = $post_expired = [];
@ -276,65 +290,49 @@ class BackendBehaviors
} }
} }
$fields['post_expired_date'] = '<p><label for="post_expired_date">' . $fields['post_expired_date'] = (new Para())->items([
__('Date:') . '</label>' . (new Label(__('Date:')))->for('post_expired_date'),
form::datetime('post_expired_date', [ (new Datetime('post_expired_date', Html::escapeHTML(self::dateToUser($post_expired['date'] ?? 'now'))))->class(empty($post_expired['date']) ? 'invalid' : ''),
'default' => html::escapeHTML(self::dateToUser($post_expired['date'] ?? 'now')), ]);
'class' => (empty($post_expired['date']) ? 'invalid' : ''),
])
. '</p>';
$fields['post_expired_status'] = '<h5>' . __('On this date, change:') . '</h5>' . $fields['post_expired_status'] = (new Para())->items([
'<p><label for="post_expired_status">' . (new Text('strong', __('On this date, change:'))),
__('Status:') . '</label>' . (new Text('br')),
form::combo( (new Label(__('Status:')))->for('post_expired_status'),
'post_expired_status', (new Select('post_expired_status'))->default(empty($post_expired['status']) ? '' : $post_expired['status'])->items(self::statusCombo()),
self::statusCombo(), ]);
empty($post_expired['status']) ?
'' : $post_expired['status']
) . '</p>';
if ($post_type == 'post') { if ($post_type == 'post') {
$fields['post_expired_category'] = '<p><label for="post_expired_category">' . $fields['post_expired_category'] = (new Para())->items([
__('Category:') . '</label>' . (new Label(__('Category:')))->for('post_expired_category'),
form::combo( (new Select('post_expired_category'))->default(empty($post_expired['category']) ? '' : $post_expired['category'])->items(self::categoriesCombo(
'post_expired_category',
self::categoriesCombo(
dcCore::app()->blog->getCategories( dcCore::app()->blog->getCategories(
['post_type' => 'post'] ['post_type' => 'post']
) )
), )),
empty($post_expired['category']) ? ]);
'' : $post_expired['category']
) . '</p>';
$fields['post_expired_selected'] = '<p><label for="post_expired_selected">' . $fields['post_expired_selected'] = (new Para())->items([
__('Selection:') . '</label>' . (new Label(__('Selection:')))->for('post_expired_selected'),
form::combo( (new Select('post_expired_selected'))->default(empty($post_expired['selected']) ? '' : $post_expired['selected'])->items(self::selectedCombo()),
'post_expired_selected', ]);
self::selectedCombo(),
empty($post_expired['selected']) ?
'' : $post_expired['selected']
) . '</p>';
} }
$fields['post_expired_comment'] = '<p><label for="post_expired_comment">' . $fields['post_expired_comment'] = (new Para())->items([
__('Comments status:') . '</label>' . (new Label(__('Comments status:')))->for('post_expired_comment'),
form::combo( (new Select('post_expired_comment'))->default(empty($post_expired['comment']) ? '' : $post_expired['comment'])->items(self::commentCombo()),
'post_expired_comment', ]);
self::commentCombo(),
empty($post_expired['comment']) ?
'' : $post_expired['comment']
) . '</p>';
$fields['post_expired_trackback'] = '<p><label for="post_expired_trackback">' . $fields['post_expired_trackback'] = (new Para())->items([
__('Trackbacks status:') . '</label>' . (new Label(__('Trackbacks status:')))->for('post_expired_trackback'),
form::combo( (new Select('post_expired_trackback'))->default(empty($post_expired['trackback']) ? '' : $post_expired['trackback'])->items(self::trackbackCombo()),
'post_expired_trackback', ]);
self::trackbackCombo(),
empty($post_expired['trackback']) ? if ($render) {
'' : $post_expired['trackback'] foreach ($fields as $k => $v) {
) . '</p>'; $fields[$k] = $v->render();
}
}
return $fields; return $fields;
} }
@ -358,8 +356,8 @@ class BackendBehaviors
['post_type' => 'post'] ['post_type' => 'post']
); );
while ($categories->fetch()) { while ($categories->fetch()) {
$categories_combo[] = new formSelectOption( $categories_combo[] = new Option(
str_repeat('&nbsp;&nbsp;', ((int) $categories->f('level')) - 1) . '&bull; ' . html::escapeHTML($categories->f('cat_title')), str_repeat('&nbsp;&nbsp;', ((int) $categories->f('level')) - 1) . '&bull; ' . Html::escapeHTML($categories->f('cat_title')),
'!' . $categories->f('cat_id') '!' . $categories->f('cat_id')
); );
} }