Compare commits

..

No commits in common. "924b96126d665ef924676333183ed572af425fd4" and "a036d037acbafeda26df60d5c9cd03c3c582e854" have entirely different histories.

14 changed files with 165 additions and 150 deletions

View File

@ -1,24 +1,3 @@
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.27-blue.svg)](https://fr.dotclear.org/download)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-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,9 +18,8 @@ This plugin creates public aliases of your blog's URLs.
_alias_ requires:
* admin permissions for management
* Dotclear 2.27
* PHP 7.4+
* admin permissions for management
* Dotclear 2.26
## USAGE
@ -29,19 +28,6 @@ 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)
@ -54,4 +40,4 @@ so more there are aliases, more page load is slow.
* Franck-paul
* Jean-Christian Denis
You are welcome to contribute to this code.
You are welcome to contribute to this code.

View File

@ -18,14 +18,13 @@ $this->registerModule(
'alias',
"Create aliases of your blog's URLs",
'Olivier Meunier and contributors',
'1.8',
'1.5.1',
[
'requires' => [['core', '2.27']],
'requires' => [['core', '2.26']],
'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.8</version>
<version>1.5.1</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.8/plugin-alias.zip</file>
<da:dcmin>2.27</da:dcmin>
<file>https://github.com/JcDenis/alias/releases/download/v1.5.1/plugin-alias.zip</file>
<da:dcmin>2.26</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 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B

View File

@ -1,15 +0,0 @@
<?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>

Before

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1,36 +1,37 @@
<?php
/**
* @package Dotclear
*
* @copyright Olivier Meunier & Association Dotclear
* @copyright GPL-2.0-only
*/
// Language: Français
// Module: alias - 1.6
// Date: 2023-04-30 22:52:13
// Author: Jean-Christian Denis
// Translated with Translater - 2023.04.23
#
# 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,71 +1,96 @@
# 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.7.1\n"
"Project-Id-Version: alias 1.6\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2023-07-29T12:49:07+00:00\n"
"Last-Translator: Jean-Christain Denis\n"
"PO-Revision-Date: 2023-04-30T22:52:13+00:00\n"
"Last-Translator: Jean-Christian 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,28 +14,45 @@ declare(strict_types=1);
namespace Dotclear\Plugin\alias;
use dcAdmin;
use dcCore;
use Dotclear\Core\Process;
use Dotclear\Plugin\importExport\{
FlatBackupItem,
FlatExport,
FlatImportV2
};
use dcNsProcess;
use dcPage;
use Dotclear\Plugin\importExport\FlatBackupItem;
use Dotclear\Plugin\importExport\FlatExport;
use Dotclear\Plugin\importExport\FlatImportV2;
class Backend extends Process
class Backend extends dcNsProcess
{
public static function init(): bool
{
return self::status(My::checkContext(My::BACKEND));
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;
}
public static function process(): bool
{
if (!self::status()) {
if (!static::$init) {
return false;
}
My::addBackendMenuItem();
// 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)
);
dcCore::app()->addBehaviors([
'exportFullV2' => function (FlatExport $exp): void {
@ -54,7 +71,7 @@ class Backend extends Process
$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);
@ -64,7 +81,7 @@ class Backend extends Process
$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,20 +15,22 @@ declare(strict_types=1);
namespace Dotclear\Plugin\alias;
use dcCore;
use Dotclear\Core\Process;
use dcNsProcess;
use Dotclear\Database\Structure;
use Exception;
class Install extends Process
class Install extends dcNsProcess
{
public static function init(): bool
{
return self::status(My::checkContext(My::INSTALL));
static::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return static::$init;
}
public static function process(): bool
{
if (!self::status()) {
if (!static::$init) {
return false;
}

View File

@ -15,11 +15,8 @@ declare(strict_types=1);
namespace Dotclear\Plugin\alias;
use dcCore;
use Dotclear\Core\Process;
use Dotclear\Core\Backend\{
Notices,
Page
};
use dcNsProcess;
use dcPage;
use Dotclear\Helper\Html\Form\{
Checkbox,
Div,
@ -39,16 +36,27 @@ use Exception;
/**
* Manage contributions list
*/
class Manage extends Process
class Manage extends dcNsProcess
{
public static function init(): bool
{
return self::status(My::checkContext(My::MANAGE));
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;
}
public static function process(): bool
{
if (!self::status()) {
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)) {
return false;
}
@ -63,8 +71,8 @@ class Manage extends Process
if (isset($_POST['a']) && is_array($_POST['a'])) {
try {
$alias->updateAliases($_POST['a']);
Notices::addSuccessNotice(__('Aliases successfully updated.'));
My::redirect();
dcPage::addSuccessNotice(__('Aliases successfully updated.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
@ -74,8 +82,8 @@ class Manage extends Process
if (isset($_POST['alias_url'])) {
try {
$alias->createAlias($_POST['alias_url'], $_POST['alias_destination'], count($aliases) + 1, !empty($_POST['alias_redirect']));
Notices::addSuccessNotice(__('Alias successfully created.'));
My::redirect();
dcPage::addSuccessNotice(__('Alias successfully created.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
@ -86,23 +94,28 @@ class Manage extends Process
public static function render(): void
{
if (!self::status()) {
if (!static::$init) {
return;
}
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return;
}
$alias = new Alias();
$aliases = $alias->getAliases();
Page::openModule(My::name());
dcPage::openModule(My::name());
if (($_REQUEST['part'] ?? 'list') == 'new') {
echo
Page::breadcrumb([
dcPage::breadcrumb([
__('Plugins') => '',
My::name() => My::manageUrl(['part' => 'list']),
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'list']),
__('New alias') => '',
]) .
Notices::getNotices() .
dcPage::notices() .
(new Div())->items([
(new Text('h3', __('New alias'))),
@ -121,22 +134,21 @@ class Manage extends Process
(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
Page::breadcrumb([
dcPage::breadcrumb([
__('Plugins') => '',
My::name() => '',
]) .
Notices::getNotices() .
dcPage::notices() .
'<p class="top-add"><a class="button add" href="' .
My::manageUrl(['part' => 'new']) .
dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'new']) .
'">' . __('New alias') . '</a></p>';
if (empty($aliases)) {
@ -175,16 +187,15 @@ class Manage extends Process
'</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>';
}
}
Page::helpBlock('alias');
Page::closeModule();
dcPage::helpBlock('alias');
dcPage::closeModule();
}
}

View File

@ -15,22 +15,28 @@ declare(strict_types=1);
namespace Dotclear\Plugin\alias;
use dcCore;
use Dotclear\Module\MyPlugin;
/**
* This module definitions.
* Plugin definitions
*/
class My extends MyPlugin
class My
{
/** @var string Plugin table name */
public const ALIAS_TABLE_NAME = 'alias';
public static function checkCustomContext(int $context): ?bool
/**
* This module id
*/
public static function id(): string
{
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);
return basename(dirname(__DIR__));
}
/**
* This module name
*/
public static function name(): string
{
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
}
}

View File

@ -15,20 +15,22 @@ 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 Process
class Prepend extends dcNsProcess
{
public static function init(): bool
{
return self::status(My::checkContext(My::PREPEND));
static::$init = defined('DC_RC_PATH');
return static::$init;
}
public static function process(): bool
{
if (!self::status()) {
if (!static::$init) {
return false;
}

View File

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