Compare commits

..

10 Commits

14 changed files with 150 additions and 165 deletions

View File

@ -1,3 +1,24 @@
1.8 - 2023.07.30
- require Dotclear 2.27
- require PHP 7.4+
- update to Dotclear 2.27-dev
1.7.1 - 2023.06.16
- require dotclear 2.26
- fix non php 7.4 type hint
1.7 - 2023.05.13
- require dotclear 2.26
- release for dc2.26 stable
1.6 - 2023.05.01
- require dotclear 2.26
- use behavior intead of urlHandler (see README)
- fix URL before saving (without blog URL)
- add option for visible redirection
- add plugin Uninstaller features
- change table structure (for redirect option)
1.5.1 - 2023.04.09
- require dotclear 2.26
- use sql statement

View File

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/alias)](https://github.com/JcDenis/alias/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/alias)](https://github.com/JcDenis/alias/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/alias)](https://github.com/JcDenis/alias/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/alias)
[![License](https://img.shields.io/github/license/JcDenis/alias)](https://github.com/JcDenis/alias/blob/master/LICENSE)
@ -18,8 +18,9 @@ This plugin creates public aliases of your blog's URLs.
_alias_ requires:
* admin permissions for management
* Dotclear 2.26
* admin permissions for management
* Dotclear 2.27
* PHP 7.4+
## USAGE
@ -28,6 +29,19 @@ Dotaddict repository. (See Dotclear's documentation to know how do this)
You can manage your aliases from menu ''Alias'' on admin dashboard sidebar.
## RULES
- Only blog URLs can be redirected.
- It can redirect a specific URL "plop" to another one "post/2023/04/24/my-post".
- It can redirect all URLs that content "plop" using alias "/plop/"
by replacing it by destination "post" into requesting URL. (Even if it's not at the begining of the URL!)
- It can not redirect an alias to another alias.
- It has priority on all ohters URLs handlers, so if you create an alias of an existing page,
the destination from plugin _alias_ will be used.
Keep in mind, plugin _alias_ loads all registered aliases to test them on each page load,
so more there are aliases, more page load is slow.
## LINKS
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
@ -40,4 +54,4 @@ You can manage your aliases from menu ''Alias'' on admin dashboard sidebar.
* Franck-paul
* Jean-Christian Denis
You are welcome to contribute to this code.
You are welcome to contribute to this code.

View File

@ -18,13 +18,14 @@ $this->registerModule(
'alias',
"Create aliases of your blog's URLs",
'Olivier Meunier and contributors',
'1.5.1',
'1.8',
[
'requires' => [['core', '2.26']],
'requires' => [['core', '2.27']],
'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_ADMIN,
]),
'type' => 'plugin',
'priority' => 2,
'support' => 'https://github.com/JcDenis/alias',
'details' => 'https://plugins.dotaddict.org/dc2/details/alias',
'repository' => 'https://raw.githubusercontent.com/JcDenis/alias/master/dcstore.xml',

View File

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="alias">
<name>alias</name>
<version>1.5.1</version>
<version>1.8</version>
<author>Olivier Meunier and contributors</author>
<desc>Create aliases of your blog's URLs</desc>
<file>https://github.com/JcDenis/alias/releases/download/v1.5.1/plugin-alias.zip</file>
<da:dcmin>2.26</da:dcmin>
<file>https://github.com/JcDenis/alias/releases/download/v1.8/plugin-alias.zip</file>
<da:dcmin>2.27</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/alias</da:details>
<da:support>https://github.com/JcDenis/alias</da:support>
</module>

BIN
icon.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 677 B

15
icon.svg 100644
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64px" height="64px" viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="refresh1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="编组" transform="translate(-0.500000, 0.000000)">
<rect id="矩形" fill-opacity="0.01" fill="#FFFFFF" x="0.5" y="0" width="48" height="48">
</rect>
<path d="M42,24 C42,14.0588745 33.9411255,6 24,6 C21.559467,6 19.2323766,6.48570507 17.1101186,7.36572524 C16.0143739,7.82008913 14.9732329,8.37956827 13.999274,9.03158409 C13.0176762,9.68871375 12.1043185,10.4398373 11.2720779,11.2720779 C10.4398373,12.1043185 9.68871375,13.0176762 9.03158409,13.999274 M6,24 C6,33.9411255 14.0588745,42 24,42 L24,42 C26.440533,42 28.7676234,41.5142949 30.8898814,40.6342748 C31.9856261,40.1799109 33.0267671,39.6204317 34.000726,38.9684159 C34.9823238,38.3112862 35.8956815,37.5601627 36.7279221,36.7279221 C37.5601627,35.8956815 38.3112862,34.9823238 38.9684159,34.000726" id="Shape" stroke="#676e78" stroke-width="4" stroke-linecap="round" stroke-linejoin="round">
</path>
<path d="M34,16 L50,16" id="Path-5" stroke="#137bbb" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" transform="translate(42.000000, 16.000000) rotate(90.000000) translate(-42.000000, -16.000000) ">
</path>
<path d="M-2,32 L14,32" id="Path-5" stroke="#c44d58" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" transform="translate(6.000000, 32.000000) rotate(90.000000) translate(-6.000000, -32.000000) ">
</path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1,37 +1,36 @@
<?php
// Language: Français
// Module: alias - 1.6
// Date: 2023-04-30 22:52:13
// Author: Jean-Christian Denis
// Translated with Translater - 2023.04.23
/**
* @package Dotclear
*
* @copyright Olivier Meunier & Association Dotclear
* @copyright GPL-2.0-only
*/
#
# DOT NOT MODIFY THIS FILE !
#
use Dotclear\Helper\L10n;
L10n::$locales['Invalid aliases definitions'] = 'Définitions d\'alias invalides';
L10n::$locales['Alias URL is empty.'] = 'L\'URL de l\'alias est vide.';
L10n::$locales['Alias destination is empty.'] = 'La destination de l\'alias est vide.';
L10n::$locales['Aliases successfully updated.'] = 'Alias mis à jour avec succès.';
L10n::$locales['Alias successfully created.'] = 'Alias créer avec succès.';
L10n::$locales['New alias'] = 'Nouvel alias';
L10n::$locales['Alias URL:'] = 'URL de l\'alias :';
L10n::$locales['Alias destination:'] = 'Destination de l\'alias :';
L10n::$locales['Do not put blog URL "%s" in fields.'] = 'Ne pas mettre l\'URL du blog "%s" dans les champs.';
L10n::$locales['Invalid aliases definitions'] = 'Définitions d\'alias invalides';
L10n::$locales['Alias URL is empty.'] = 'L\'URL de l\'alias est vide.';
L10n::$locales['Alias destination is empty.'] = 'La destination de l\'alias est vide.';
L10n::$locales['Aliases successfully updated.'] = 'Alias mis à jour avec succès.';
L10n::$locales['Alias successfully created.'] = 'Alias créer avec succès.';
L10n::$locales['New alias'] = 'Nouvel alias';
L10n::$locales['Alias URL:'] = 'URL de l\'alias :';
L10n::$locales['Alias destination:'] = 'Destination de l\'alias :';
L10n::$locales['Do not put blog URL "%s" in fields.'] = 'Ne pas mettre l\'URL du blog "%s" dans les champs.';
L10n::$locales['Do visible redirection to destination'] = 'Faire une redirection visible vers la destination';
L10n::$locales['No alias'] = 'Aucun alias';
L10n::$locales['There is %s alias.'] = [
'Il y a %s alias.',
'Il y a %s alias.',
L10n::$locales['No alias'] = 'Aucun alias';
L10n::$locales['There is %s alias.'] = [
'Il y a %s alias.',
'Il y a %s alias.',
];
L10n::$locales['Aliases list'] = 'Liste des alias';
L10n::$locales['Alias URL'] = 'URL de l\'alias';
L10n::$locales['Alias destination'] = 'Destination de l\'alias';
L10n::$locales['Alias position'] = 'Position de l\'alias';
L10n::$locales['Redrection'] = 'Redirection';
L10n::$locales['visible redirection to %s'] = 'Redirection visible vers %s';
L10n::$locales['Aliases list'] = 'Liste des alias';
L10n::$locales['Alias URL'] = 'URL de l\'alias';
L10n::$locales['Alias destination'] = 'Destination de l\'alias';
L10n::$locales['Alias position'] = 'Position de l\'alias';
L10n::$locales['Redrection'] = 'Redirection';
L10n::$locales['visible redirection to %s'] = 'Redirection visible vers %s';
L10n::$locales['To remove an alias, empty its URL or destination.'] = 'Pour supprimer un alias, videz son URL ou sa destination.';
L10n::$locales['Aliases'] = 'Alias';
L10n::$locales['Aliases'] = 'Alias';

View File

@ -1,96 +1,71 @@
# Language: Français
# Module: alias - 1.6
# Date: 2023-04-30 22:52:13
# Author: Jean-Christian Denis
# Translated with translater 2023.04.23
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: alias 1.6\n"
"Project-Id-Version: alias 1.7.1\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2023-04-30T22:52:13+00:00\n"
"Last-Translator: Jean-Christian Denis\n"
"PO-Revision-Date: 2023-07-29T12:49:07+00:00\n"
"Last-Translator: Jean-Christain Denis\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: src/Alias.php:75
msgid "Invalid aliases definitions"
msgstr "Définitions d'alias invalides"
#: src/Alias.php:116
msgid "Alias URL is empty."
msgstr "L'URL de l'alias est vide."
#: src/Alias.php:119
msgid "Alias destination is empty."
msgstr "La destination de l'alias est vide."
#: src/Manage.php:74
msgid "Aliases successfully updated."
msgstr "Alias mis à jour avec succès."
#: src/Manage.php:85
msgid "Alias successfully created."
msgstr "Alias créer avec succès."
#: src/Manage.php:116
msgid "New alias"
msgstr "Nouvel alias"
#: src/Manage.php:124
msgid "Alias URL:"
msgstr "URL de l'alias :"
#: src/Manage.php:128
msgid "Alias destination:"
msgstr "Destination de l'alias :"
#: src/Manage.php:131
msgid "Do not put blog URL \"%s\" in fields."
msgstr "Ne pas mettre l'URL du blog \"%s\" dans les champs."
#: src/Manage.php:134
msgid "Do visible redirection to destination"
msgstr "Faire une redirection visible vers la destination"
#: src/Manage.php:155
msgid "No alias"
msgstr "Aucun alias"
#: src/Manage.php:159
msgid "There is %s alias."
msgid_plural "There are %s aliases."
msgstr[0] "Il y a %s alias."
msgstr[1] "Il y a %s alias."
#: src/Manage.php:162
msgid "Aliases list"
msgstr "Liste des alias"
#: src/Manage.php:165
msgid "Alias URL"
msgstr "URL de l'alias"
#: src/Manage.php:166
msgid "Alias destination"
msgstr "Destination de l'alias"
#: src/Manage.php:167
msgid "Alias position"
msgstr "Position de l'alias"
#: src/Manage.php:168
msgid "Redrection"
msgstr "Redirection"
#: src/Manage.php:182
msgid "visible redirection to %s"
msgstr "Redirection visible vers %s"
#: src/Manage.php:188
msgid "To remove an alias, empty its URL or destination."
msgstr "Pour supprimer un alias, videz son URL ou sa destination."

View File

@ -14,45 +14,28 @@ declare(strict_types=1);
namespace Dotclear\Plugin\alias;
use dcAdmin;
use dcCore;
use dcNsProcess;
use dcPage;
use Dotclear\Plugin\importExport\FlatBackupItem;
use Dotclear\Plugin\importExport\FlatExport;
use Dotclear\Plugin\importExport\FlatImportV2;
use Dotclear\Core\Process;
use Dotclear\Plugin\importExport\{
FlatBackupItem,
FlatExport,
FlatImportV2
};
class Backend extends dcNsProcess
class Backend extends Process
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN')
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) //nullsafe PHP < 8.0
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_ADMIN,
]), dcCore::app()->blog->id);
return static::$init;
return self::status(My::checkContext(My::BACKEND));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false;
}
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
dcPage::getPF(My::id() . '/icon.png'),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]), dcCore::app()->blog->id)
);
My::addBackendMenuItem();
dcCore::app()->addBehaviors([
'exportFullV2' => function (FlatExport $exp): void {
@ -71,7 +54,7 @@ class Backend extends dcNsProcess
$bk->alias = new Alias();
$bk->aliases = $bk->alias->getAliases();
},
'importFullV2' => function (bool|FlatBackupItem $line, FlatImportV2 $bk): void {
'importFullV2' => function (/*bool|FlatBackupItem */$line, FlatImportV2 $bk): void {
if ($line->__name == My::ALIAS_TABLE_NAME) {
$bk->cur_alias->clean();
$bk->cur_alias->setField('blog_id', (string) $line->blog_id);
@ -81,7 +64,7 @@ class Backend extends dcNsProcess
$bk->cur_alias->insert();
}
},
'importSingleV2' => function (bool|FlatBackupItem $line, FlatImportV2 $bk): void {
'importSingleV2' => function (/*bool|FlatBackupItem */$line, FlatImportV2 $bk): void {
if ($line->__name == My::ALIAS_TABLE_NAME) {
$found = false;
foreach ($bk->aliases as $v) {

View File

@ -15,22 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\alias;
use dcCore;
use dcNsProcess;
use Dotclear\Core\Process;
use Dotclear\Database\Structure;
use Exception;
class Install extends dcNsProcess
class Install extends Process
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return static::$init;
return self::status(My::checkContext(My::INSTALL));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}

View File

@ -15,8 +15,11 @@ declare(strict_types=1);
namespace Dotclear\Plugin\alias;
use dcCore;
use dcNsProcess;
use dcPage;
use Dotclear\Core\Process;
use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Helper\Html\Form\{
Checkbox,
Div,
@ -36,27 +39,16 @@ use Exception;
/**
* Manage contributions list
*/
class Manage extends dcNsProcess
class Manage extends Process
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN')
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) //nullsafe PHP < 8.0
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_ADMIN,
]), dcCore::app()->blog->id);
return static::$init;
return self::status(My::checkContext(My::MANAGE));
}
public static function process(): bool
{
if (!static::$init) {
return false;
}
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
if (!self::status()) {
return false;
}
@ -71,8 +63,8 @@ class Manage extends dcNsProcess
if (isset($_POST['a']) && is_array($_POST['a'])) {
try {
$alias->updateAliases($_POST['a']);
dcPage::addSuccessNotice(__('Aliases successfully updated.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
Notices::addSuccessNotice(__('Aliases successfully updated.'));
My::redirect();
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
@ -82,8 +74,8 @@ class Manage extends dcNsProcess
if (isset($_POST['alias_url'])) {
try {
$alias->createAlias($_POST['alias_url'], $_POST['alias_destination'], count($aliases) + 1, !empty($_POST['alias_redirect']));
dcPage::addSuccessNotice(__('Alias successfully created.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
Notices::addSuccessNotice(__('Alias successfully created.'));
My::redirect();
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
@ -94,28 +86,23 @@ class Manage extends dcNsProcess
public static function render(): void
{
if (!static::$init) {
return;
}
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
if (!self::status()) {
return;
}
$alias = new Alias();
$aliases = $alias->getAliases();
dcPage::openModule(My::name());
Page::openModule(My::name());
if (($_REQUEST['part'] ?? 'list') == 'new') {
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'list']),
My::name() => My::manageUrl(['part' => 'list']),
__('New alias') => '',
]) .
dcPage::notices() .
Notices::getNotices() .
(new Div())->items([
(new Text('h3', __('New alias'))),
@ -134,21 +121,22 @@ class Manage extends dcNsProcess
(new Label(__('Do visible redirection to destination'), Label::OUTSIDE_LABEL_AFTER))->for('alias_redirect')->class('classic'),
]),
(new Para())->items([
dcCore::app()->formNonce(false),
(new Hidden('part', 'new')),
(new Submit(['do']))->value(__('Save')),
... My::hiddenFields([
'part' => 'new',
]),
]),
]),
])->render();
} else {
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => '',
]) .
dcPage::notices() .
Notices::getNotices() .
'<p class="top-add"><a class="button add" href="' .
dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'new']) .
My::manageUrl(['part' => 'new']) .
'">' . __('New alias') . '</a></p>';
if (empty($aliases)) {
@ -187,15 +175,16 @@ class Manage extends dcNsProcess
'</tbody></table></div>' .
'<p class="form-note">' . __('To remove an alias, empty its URL or destination.') . '</p>' .
(new Para())->items([
dcCore::app()->formNonce(false),
(new Hidden('part', 'list')),
(new Submit(['upd']))->value(__('Update')),
... My::hiddenFields([
'part' => 'list',
]),
])->render() .
'</form>';
}
}
dcPage::helpBlock('alias');
dcPage::closeModule();
Page::helpBlock('alias');
Page::closeModule();
}
}

View File

@ -15,28 +15,22 @@ declare(strict_types=1);
namespace Dotclear\Plugin\alias;
use dcCore;
use Dotclear\Module\MyPlugin;
/**
* Plugin definitions
* This module definitions.
*/
class My
class My extends MyPlugin
{
/** @var string Plugin table name */
public const ALIAS_TABLE_NAME = 'alias';
/**
* This module id
*/
public static function id(): string
public static function checkCustomContext(int $context): ?bool
{
return basename(dirname(__DIR__));
}
/**
* This module name
*/
public static function name(): string
{
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
return !in_array($context, [My::BACKEND, My::MANAGE, My::MENU]) ? null :
defined('DC_CONTEXT_ADMIN')
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_ADMIN,
]), dcCore::app()->blog->id);
}
}

View File

@ -15,22 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\alias;
use dcCore;
use dcNsProcess;
use dcUrlHandlers;
use Dotclear\Core\Process;
use Dotclear\Helper\Network\Http;
class Prepend extends dcNsProcess
class Prepend extends Process
{
public static function init(): bool
{
static::$init = defined('DC_RC_PATH');
return static::$init;
return self::status(My::checkContext(My::PREPEND));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}

View File

@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\alias;
use dcCore;
use dcNsProcess;
use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller;
class Uninstall extends dcNsProcess
class Uninstall extends Process
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN');
return static::$init;
return self::status(My::checkContext(My::UNINSTALL));
}
public static function process(): bool
{
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false;
}