alias/index.php

132 lines
4.4 KiB
PHP
Raw Normal View History

2022-11-27 12:57:51 +00:00
<?php
2022-11-27 13:51:46 +00:00
/**
* @brief alias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
2022-11-28 21:52:27 +00:00
* @copyright Jean-Christian Denis
2022-11-27 13:51:46 +00:00
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
2022-11-30 21:51:07 +00:00
dcPage::check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]));
2022-11-27 12:57:51 +00:00
2022-11-27 13:51:46 +00:00
$o = new dcAliases();
2022-11-27 12:57:51 +00:00
$aliases = $o->getAliases();
2022-12-04 14:58:10 +00:00
$part = $_REQUEST['part'] ?? 'list';
2022-11-27 12:57:51 +00:00
# Update aliases
2022-11-27 13:51:46 +00:00
if (isset($_POST['a']) && is_array($_POST['a'])) {
try {
$o->updateAliases($_POST['a']);
dcAdminNotices::addSuccessNotice(__('Aliases successfully updated.'));
dcCore::app()->adminurl->redirect('admin.plugin.alias');
2022-11-27 13:51:46 +00:00
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
2022-11-27 12:57:51 +00:00
}
# New alias
2022-11-27 13:51:46 +00:00
if (isset($_POST['alias_url'])) {
try {
$o->createAlias($_POST['alias_url'], $_POST['alias_destination'], count($aliases) + 1);
dcAdminNotices::addSuccessNotice(__('Alias successfully created.'));
dcCore::app()->adminurl->redirect('admin.plugin.alias');
2022-11-27 13:51:46 +00:00
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
2022-11-27 12:57:51 +00:00
}
?>
<html>
<head>
<title><?php echo __('Aliases'); ?></title>
</head>
<body>
<?php
if ($part == 'new') {
2022-11-27 13:51:46 +00:00
echo
dcPage::breadcrumb([
2022-12-04 14:58:10 +00:00
__('Plugins') => '',
__('Aliases') => dcCore::app()->adminurl->get('admin.plugin.alias', ['part' => 'list']),
__('New alias') => '',
]) .
dcPage::notices() .
'<h3>' . __('New alias') . '</h3>' .
2022-11-27 13:51:46 +00:00
'<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 class="form-note">' . sprintf(__('Do not put blog URL "%s" in fields.'), dcCore::app()->blog->url) . '</p>' .
2022-12-04 14:58:10 +00:00
'<p>' .
dcCore::app()->formNonce() .
form::hidden('part', 'new') .
'<input type="submit" value="' . __('Save') . '" /></p>' .
'</form>';
} else {
echo
dcPage::breadcrumb([
__('Plugins') => '',
2022-12-04 14:58:10 +00:00
__('Aliases') => '',
]) .
dcPage::notices() .
'<p class="top-add"><a class="button add" href="' .
dcCore::app()->adminurl->get('admin.plugin.alias', ['part' => 'new']) .
'">' . __('New alias') . '</a></p>';
2022-11-27 13:51:46 +00:00
if (empty($aliases)) {
echo '<p>' . __('No alias') . '</p>';
} else {
2022-11-27 13:51:46 +00:00
echo
'<form action="' . dcCore::app()->admin->getPageURL() . '" method="post">' .
2022-12-20 20:04:27 +00:00
'<p>' . sprintf(__('There is %s alias.', 'There are %s aliases.', count($aliases)), count($aliases)) . '</p>' .
'<div class="table-outer">' .
'<table>' .
'<caption>' . __('Aliases list') . '</caption>' .
'<thead>' .
2022-11-27 13:51:46 +00:00
'<tr>' .
'<th class="nowrap" scope="col">' . __('Alias URL') . '</th>' .
'<th class="nowrap" scope="col">' . __('Alias destination') . '</th>' .
'<th class="nowrap" scope="col">' . __('Alias position') . '</th>' .
'</tr>' .
'</thead><tbody>';
2022-11-27 13:51:46 +00:00
foreach ($aliases as $k => $v) {
echo
'<tr class="line" id="l_' . $k . '">' .
2022-12-04 14:58:10 +00:00
'<td>' .
form::field(['a[' . $k . '][alias_url]'], 50, 255, html::escapeHTML($v['alias_url'])) . '</td>' .
2022-12-04 14:58:10 +00:00
'<td class="maximal">' .
form::field(['a[' . $k . '][alias_destination]'], 50, 255, html::escapeHTML($v['alias_destination'])) . '</td>' .
2022-12-04 14:58:10 +00:00
'<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>';
}
2022-11-27 12:57:51 +00:00
2022-12-04 14:58:10 +00:00
echo
'</tbody></table></div>' .
'<p class="form-note">' . __('To remove an alias, empty its URL or destination.') . '</p>' .
2022-12-04 14:58:10 +00:00
'<p>' .
dcCore::app()->formNonce() .
form::hidden('part', 'list') .
'<input type="submit" value="' . __('Update') . '" /></p>' .
'</form>';
}
}
2022-11-27 12:57:51 +00:00
dcPage::helpBlock('alias');
?>
</body>
</html>