clean alias list and separate new alias form

master
Jean-Christian Paul Denis 2022-12-04 15:54:52 +01:00
parent 0c0e5b20e7
commit a353e769e1
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
1 changed files with 67 additions and 36 deletions

103
index.php
View File

@ -18,6 +18,7 @@ dcPage::check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]));
$o = new dcAliases(); $o = new dcAliases();
$aliases = $o->getAliases(); $aliases = $o->getAliases();
$part = $_REQUEST['part'] ?? 'list';
# Update aliases # Update aliases
if (isset($_POST['a']) && is_array($_POST['a'])) { if (isset($_POST['a']) && is_array($_POST['a'])) {
@ -49,50 +50,80 @@ if (isset($_POST['alias_url'])) {
<body> <body>
<?php <?php
echo if ($part == 'new') {
dcPage::breadcrumb([ echo
__('Plugins') => '', dcPage::breadcrumb([
__('Aliases') => '', __('Plugins') => '',
]) . __('Aliases') => dcCore::app()->adminurl->get('admin.plugin.alias', ['part' => 'list']),
dcPage::notices() . __('New alias') => '',
]) .
'<h3>' . __('Aliases list') . '</h3>'; dcPage::notices() .
'<h3>' . __('New alias') . '</h3>' .
if (empty($aliases)) { '<form action="' . dcCore::app()->admin->getPageURL() . '" method="post">' .
echo '<p>' . __('No alias') . '</p>'; '<p class="field"><label>' . __('Alias URL:') . ' ' . form::field('alias_url', 50, 255) . '</label></p>' .
'<p class="field"><label>' . __('Alias destination:') . ' ' . form::field('alias_destination', 50, 255) . '</label></p>' .
'<p class="form-note">' . sprintf(__('Do not put blog URL "%s" in fields.'), dcCore::app()->blog->url) . '</p>' .
'<p>' .
dcCore::app()->formNonce() .
form::hidden('part', 'new') .
'<input type="submit" value="' . __('Save') . '" /></p>' .
'</form>';
} else { } else {
echo echo
'<form action="' . dcCore::app()->admin->getPageURL() . '" method="post">' . dcPage::breadcrumb([
'<table><tr>' . __('Plugins') => '',
'<td>' . __('Alias URL') . '</td>' . __('Aliases') => ''
'<td>' . __('Alias destination') . '</td>' . ]) .
'<td>' . __('Alias position') . '</td>' . dcPage::notices() .
'</tr>'; '<p class="top-add"><a class="button add" href="' .
dcCore::app()->adminurl->get('admin.plugin.alias', ['part' => 'new']) .
'">' . __('New alias') . '</a></p>';
foreach ($aliases as $k => $v) { if (empty($aliases)) {
echo '<p>' . __('No alias') . '</p>';
} else {
echo echo
'<form action="' . dcCore::app()->admin->getPageURL() . '" method="post">' .
'<div class="table-outer">' .
'<table>' .
'<caption>' . __('Aliases list') . '</caption>' .
'<thead>' .
'<tr>' . '<tr>' .
'<td>' . form::field(['a[' . $k . '][alias_url]'], 30, 255, html::escapeHTML($v['alias_url'])) . '</td>' . '<th class="nowrap" scope="col">' . __('Alias URL') . '</th>' .
'<td>' . form::field(['a[' . $k . '][alias_destination]'], 50, 255, html::escapeHTML($v['alias_destination'])) . '</td>' . '<th class="nowrap" scope="col">' . __('Alias destination') . '</th>' .
'<td>' . form::field(['a[' . $k . '][alias_position]'], 3, 5, html::escapeHTML($v['alias_position'])) . '</td>' . '<th class="nowrap" scope="col">' . __('Alias position') . '</th>' .
'</tr>'; '</tr>' .
'</thead><tbody>';
foreach ($aliases as $k => $v) {
echo
'<tr class="line" id="l_' . $k . '">' .
'<td>' .
form::field(['a[' . $k . '][alias_url]'], 50, 255, html::escapeHTML($v['alias_url'])) . '</td>' .
'<td class="maximal">' .
form::field(['a[' . $k . '][alias_destination]'], 50, 255, html::escapeHTML($v['alias_destination'])) . '</td>' .
'<td class="minimal">' .
form::number(['a[' . $k . '][alias_position]'], [
'min' => 1,
'max' => count($aliases),
'default' => (int) $v['alias_position'],
'class' => 'position',
'extra_html' => 'title="' . sprintf(__('position of %s'), html::escapeHTML($v['alias_url'])) . '"',
]) . '</td>' .
'</tr>';
}
echo
'</tbody></table></div>' .
'<p class="form-note">' . __('To remove an alias, empty its URL or destination.') . '</p>' .
'<p>' .
dcCore::app()->formNonce() .
form::hidden('part', 'list') .
'<input type="submit" value="' . __('Update') . '" /></p>' .
'</form>';
} }
echo '</table>' .
'<p>' . __('To remove an alias, empty its URL or destination.') . '</p>' .
'<p>' . dcCore::app()->formNonce() .
'<input type="submit" value="' . __('Update') . '" /></p>' .
'</form>';
} }
echo
'<h3>' . __('New alias') . '</h3>' .
'<form action="' . dcCore::app()->admin->getPageURL() . '" method="post">' .
'<p class="field"><label>' . __('Alias URL:') . ' ' . form::field('alias_url', 50, 255) . '</label></p>' .
'<p class="field"><label>' . __('Alias destination:') . ' ' . form::field('alias_destination', 50, 255) . '</label></p>' .
'<p>' . dcCore::app()->formNonce() . '<input type="submit" value="' . __('Save') . '" /></p>' .
'</form>';
dcPage::helpBlock('alias'); dcPage::helpBlock('alias');
?> ?>
</body> </body>