use Dotclear Helper Form

master
Jean-Christian Paul Denis 2023-04-09 11:36:32 +02:00
parent 3092154cda
commit ffe9e86eae
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
2 changed files with 128 additions and 125 deletions

View File

@ -21,8 +21,12 @@ use dcPage;
use dcFavorites; use dcFavorites;
use dcNsProcess; use dcNsProcess;
use dcSettings; use dcSettings;
use Dotclear\Helper\Html\Form\{
use form; Checkbox,
Input,
Label,
Para
};
class Backend extends dcNsProcess class Backend extends dcNsProcess
{ {
@ -73,9 +77,11 @@ class Backend extends dcNsProcess
'<div class="fieldset"><h4 id="epc_params">' . My::name() . '</h4>' . '<div class="fieldset"><h4 id="epc_params">' . My::name() . '</h4>' .
'<div class="two-cols">' . '<div class="two-cols">' .
'<div class="col">' . '<div class="col">' .
'<p><label class="classic">' . // active
form::checkbox('epc_active', '1', $active) . (new Para())->items([
__('Enable plugin') . '</label></p>' . (new Checkbox('epc_active', $active))->value(1),
(new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER))->for('epc_active')->class('classic'),
])->render() .
'<p class="form-note">' . '<p class="form-note">' .
__('This enable public widgets and contents filter.') . __('This enable public widgets and contents filter.') .
'</p>' . '</p>' .
@ -85,11 +91,17 @@ class Backend extends dcNsProcess
'<div class="col">' . '<div class="col">' .
'<h5>' . __('Extra') . '</h5>' . '<h5>' . __('Extra') . '</h5>' .
'<p>' . __('This is a special feature to edit list of allowed template values and public pages where this plugin works.') . '</p>' . '<p>' . __('This is a special feature to edit list of allowed template values and public pages where this plugin works.') . '</p>' .
'<p><label for="epc_allowedtplvalues">' . __('Allowed DC template values:') . '</label>' . // allowedtplvalues
form::field('epc_allowedtplvalues', 100, 0, Epc::implode($allowedtplvalues)) . '</p>' . (new Para())->items([
(new Label(__('Allowed DC template values:'), Label::OUTSIDE_LABEL_BEFORE))->for('epc_allowedtplvalues'),
(new Input('epc_allowedtplvalues'))->size(100)->maxlenght(0)->value(Epc::implode($allowedtplvalues)),
])->render() .
'<p class="form-note">' . __('Use "readable_name1:template_value1;readable_name2:template_value2;" like "entry content:EntryContent;entry excerpt:EntryExcerpt;".') . '</p>' . '<p class="form-note">' . __('Use "readable_name1:template_value1;readable_name2:template_value2;" like "entry content:EntryContent;entry excerpt:EntryExcerpt;".') . '</p>' .
'<p><label for="epc_allowedpubpages">' . __('Allowed public pages:') . '</label>' . // allowedpubpages
form::field('epc_allowedpubpages', 100, 0, Epc::implode($allowedpubpages)) . '</p>' . (new Para())->items([
(new Label(__('Allowed public pages:'), Label::OUTSIDE_LABEL_BEFORE))->for('epc_allowedpubpages'),
(new Input('epc_allowedpubpages'))->size(100)->maxlenght(0)->value(Epc::implode($allowedpubpages)),
])->render() .
'<p class="form-note">' . __('Use "readable_name1:template_page1;readable_name2:template_page2;" like "post page:post.html;home page:home.html;".') . '</p>' . '<p class="form-note">' . __('Use "readable_name1:template_page1;readable_name2:template_page2;" like "post page:post.html;home page:home.html;".') . '</p>' .
'</div>' . '</div>' .
'</div>' . '</div>' .

View File

@ -19,12 +19,24 @@ use adminGenericFilterV2;
use dcCore; use dcCore;
use dcNsProcess; use dcNsProcess;
use dcPage; use dcPage;
use Dotclear\Helper\Html\Form\{
Checkbox,
Div,
Form,
Hidden,
Input,
label,
Note,
Number,
Para,
Select,
Submit,
Text
};
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Helper\Network\Http; use Dotclear\Helper\Network\Http;
use Exception; use Exception;
use form;
class Manage extends dcNsProcess class Manage extends dcNsProcess
{ {
public static function init(): bool public static function init(): bool
@ -192,109 +204,86 @@ class Manage extends dcNsProcess
My::name() => '', My::name() => '',
$current->filter->name => '', $current->filter->name => '',
]) . ]) .
dcPage::notices() . dcPage::notices();
# Filters select menu list # Filters select menu list
'<form method="get" action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" id="filters_menu">' . echo
'<p class="anchor-nav"><label for="part" class="classic">' . __('Select filter:') . ' </label>' . (new Form('filters_menu'))->method('get')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->fields([
form::combo('part', $current->combo, $current->part) . ' ' . (new Para())->class('anchor-nav')->items([
'<input type="submit" value="' . __('Ok') . '" />' . (new Select('part'))->items($current->combo)->default($current->part),
form::hidden('p', My::id()) . '</p>' . (new Submit(['do']))->value(__('Ok')),
'</form>'; (new Hidden(['p'], My::id())),
]),
])->render();
# Filter title and description # Filter title and description
echo ' echo
<h3>' . $current->filter->name . '</h3> '<h3>' . $current->filter->name . '</h3>' .
<p>' . $current->filter->help . '</p>'; '<p>' . $current->filter->help . '</p>';
# Filter settings # Filter settings
echo ' $form_pages = [(new Text('h4', __('Pages to be filtered')))];
<div class="multi-part" id="setting" title="' . __('Settings') . '">
<form method="post" action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#setting">
<div class="two-boxes odd">
<h4>' . __('Pages to be filtered') . '</h4>';
foreach (Epc::blogAllowedPubPages() as $k => $v) { foreach (Epc::blogAllowedPubPages() as $k => $v) {
echo ' $form_pages[] = (new Para())->items([
<p><label for="filter_pubPages' . $v . '">' . (new Checkbox(['filter_pubPages[]', 'filter_pubPages' . $v], in_array($v, $current->filter->pubPages)))->value(1),
form::checkbox( (new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('filter_pubPages' . $v)->class('classic'),
['filter_pubPages[]', 'filter_pubPages' . $v], ]);
$v,
in_array($v, $current->filter->pubPages)
) .
__($k) . '</label></p>';
} }
echo ' $form_values = [(new Text('h4', __('Contents to be filtered')))];
</div><div class="two-boxes even">
<h4>' . __('Filtering') . '</h4>
<p><label for="filter_nocase">' .
form::checkbox('filter_nocase', '1', $current->filter->nocase) .
__('Case insensitive') . '</label></p>
<p><label for="filter_plural">' .
form::checkbox('filter_plural', '1', $current->filter->plural) .
__('Also use the plural') . '</label></p>
<p><label for="filter_limit">' .
__('Limit the number of replacement to:') . '</label>' .
form::number('filter_limit', ['min' => 0, 'max' => 99, 'default' => (int) $current->filter->limit]) . '
</p>
<p class="form-note">' . __('Leave it blank or set it to 0 for no limit') . '</p>
</div><div class="two-boxes odd">
<h4>' . __('Contents to be filtered') . '</h4>';
foreach (Epc::blogAllowedTplValues() as $k => $v) { foreach (Epc::blogAllowedTplValues() as $k => $v) {
echo ' $form_values[] = (new Para())->items([
<p><label for="filter_tplValues' . $v . '">' . (new Checkbox(['filter_tplValues[]', 'filter_tplValues' . $v], in_array($v, $current->filter->tplValues)))->value(1),
form::checkbox( (new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('filter_tplValues' . $v)->class('classic'),
['filter_tplValues[]', 'filter_tplValues' . $v], ]);
$v,
in_array($v, $current->filter->tplValues)
) .
__($k) . '</label></p>';
} }
echo ' $form_styles = [(new Text('h4', __('Style')))];
</div><div class="two-boxes even">
<h4>' . __('Style') . '</h4>';
foreach ($current->filter->class as $k => $v) { foreach ($current->filter->class as $k => $v) {
echo ' $form_styles[] = (new Para())->items([
<p><label for="filter_style' . $k . '">' . (new Label(sprintf(__('Class "%s":'), $v), Label::OUTSIDE_LABEL_BEFORE))->for('filter_style' . $k),
sprintf(__('Class "%s":'), $v) . '</label>' . (new Input(['filter_style[]', 'filter_style' . $k]))->size(60)->maxlenght(255)->value(Html::escapeHTML($current->filter->style[$k])),
form::field( ]);
['filter_style[]', 'filter_style' . $k],
60,
255,
Html::escapeHTML($current->filter->style[$k])
) .
'</p>';
} }
echo ' echo
<p class="form-note">' . sprintf(__('The inserted HTML tag looks like: %s'), Html::escapeHTML(str_replace('%s', '...', $current->filter->replace))) . '</p> (new Div('setting'))->class('multi-part')->title(__('Settings'))->items([
(new Form('setting_form'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#setting')->separator('')->fields([
(new Div())->class('two-boxes even')->items($form_pages),
(new Div())->class('two-boxes odd')->items([
(new Text('h4', __('Filtering'))),
(new Para())->items([
(new Checkbox('filter_nocase', $current->filter->nocase))->value(1),
(new Label(__('Case insensitive'), Label::OUTSIDE_LABEL_AFTER))->for('filter_nocase')->class('classic'),
]),
(new Para())->items([
(new Checkbox('filter_plural', $current->filter->plural))->value(1),
(new Label(__('Also use the plural'), Label::OUTSIDE_LABEL_AFTER))->for('filter_plural')->class('classic'),
]),
(new Para())->items([
(new Label(__('Limit the number of replacement to:'), Label::OUTSIDE_LABEL_BEFORE))->for('filter_limit'),
(new Number('filter_limit'))->min(0)->max(99)->value((int) $current->filter->limit),
]),
(new Note())->class('form-note')->text(__('Leave it blank or set it to 0 for no limit')),
]),
(new Div())->class('two-boxes even')->items($form_values),
(new Div())->class('two-boxes odd')->items(array_merge($form_styles, [
(new Note())->class('form-note')->text(sprintf(__('The inserted HTML tag looks like: %s'), Html::escapeHTML(str_replace('%s', '...', $current->filter->replace)))),
(new Para())->items([
(new Label(__('Ignore HTML tags:'), Label::OUTSIDE_LABEL_BEFORE))->for('filter_notag'),
(new Input('filter_notag'))->size(60)->maxlenght(255)->value(Html::escapeHTML($current->filter->notag)),
]),
(new Note())->class('form-note')->text(__('This is the list of HTML tags where content will be ignored.') . ' ' . ('' != $current->filter->htmltag ? '' : sprintf(__('Tag "%s" always be ignored.'), $current->filter->htmltag))),
<p><label for="filter_notag">' . __('Ignore HTML tags:') . '</label>' . ])),
form::field('filter_notag', 60, 255, Html::escapeHTML($current->filter->notag)) . ' (new Div())->class('clear')->items([
</p> dcCore::app()->formNonce(false),
<p class="form-note">' . __('This is the list of HTML tags where content will be ignored.') . ' ' . (new Hidden(['action'], 'savefiltersetting')),
('' != $current->filter->htmltag ? '' : sprintf(__('Tag "%s" always be ignored.'), $current->filter->htmltag)) . '</p> (new Hidden(['part'], $current->part)),
</div> (new Submit(['save']))->value(__('Save')),
<div class="clear"> ]),
<p>' . ]),
dcCore::app()->formNonce() . ])->render();
form::hidden(['action'], 'savefiltersetting') .
form::hidden(['part'], $current->part) . '
<input type="submit" name="save" value="' . __('Save') . '" />
</p>
</div>
</form>
</div>';
# Filter records list # Filter records list
if ($current->filter->has_list && isset($sorts) && isset($pager)) { if ($current->filter->has_list && isset($sorts) && isset($pager)) {
@ -303,7 +292,7 @@ class Manage extends dcNsProcess
echo ' echo '
<div class="multi-part" id="record" title="' . __('Records') . '">'; <div class="multi-part" id="record" title="' . __('Records') . '">';
$sorts->display(['admin.plugin.' . My::id(), '#record'], form::hidden('p', My::id()) . form::hidden('part', $current->part)); $sorts->display(['admin.plugin.' . My::id(), '#record'], (new Hidden('p', My::id()))->render() . (new Hidden('part', $current->part))->render());
$pager->display( $pager->display(
$sorts, $sorts,
@ -314,12 +303,15 @@ class Manage extends dcNsProcess
'<div class="two-cols">' . '<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' . '<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' . (new Para())->class('col right')->items(array_merge(
form::hidden('action', 'deleterecords') . dcCore::app()->adminurl->hiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $sorts->values(true))),
'<input id="del-action" type="submit" name="save" value="' . __('Delete selected records') . '" /></p>' . [
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $sorts->values(true))) . dcCore::app()->formNonce(false),
form::hidden('redir', dcCore::app()->adminurl->get('admin.plugin.' . My::id(), $sorts->values(true))) . (new Hidden('redir', dcCore::app()->adminurl->get('admin.plugin.' . My::id(), $sorts->values(true)))),
dcCore::app()->formNonce() . (new Hidden('action', 'deleterecords')),
(new Submit(['save', 'del-action']))->value(__('Delete selected records')),
]
))->render() .
'</div>' . '</div>' .
'</form>' '</form>'
); );
@ -327,26 +319,25 @@ class Manage extends dcNsProcess
echo '</div>'; echo '</div>';
# New record # New record
echo ' echo
<div class="multi-part" id="newrecord" title="' . __('New record') . '"> (new Div('newrecord'))->class('multi-part')->title(__('New record'))->items([
<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#record" method="post" id="form-create">' . (new Form('form-create'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#record')->fields([
(new Para())->items([
'<p><label for="new_key">' . __('Key:') . '</label>' . (new Label(__('Key:'), Label::OUTSIDE_LABEL_BEFORE))->for('new_key'),
form::field('new_key', 60, 255, ['extra_html' => 'required']) . (new Input('new_key'))->size(60)->maxlenght(255)->required(true),
'</p>' . ]),
(new Para())->items([
'<p><label for="new_value">' . __('Value:') . '</label>' . (new Label(__('Value:'), Label::OUTSIDE_LABEL_BEFORE))->for('new_value'),
form::field('new_value', 60, 255, ['extra_html' => 'required']) . (new Input('new_value'))->size(60)->maxlenght(255)->required(true),
'</p> ]),
(new Para())->class('clear')->items([
<p class="clear">' . dcCore::app()->formNonce(false),
form::hidden(['action'], 'savenewrecord') . (new Hidden(['action'], 'savenewrecord')),
form::hidden(['part'], $current->part) . (new Hidden(['part'], $current->part)),
dcCore::app()->formNonce() . ' (new Submit(['save', 'new-action']))->value(__('Save')),
<input id="new-action" type="submit" name="save" value="' . __('Save') . '" /> ]),
</p> ]),
</form> ])->render();
</div>';
} }
# --BEHAVIOR-- enhancePostContentAdminPage # --BEHAVIOR-- enhancePostContentAdminPage