upgrade to Dotclear 2.28

This commit is contained in:
Jean-Christian Paul Denis 2023-10-15 12:07:19 +02:00
parent 39df98dcd8
commit 53f72a8748
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
14 changed files with 175 additions and 219 deletions

View File

@ -1,3 +1,9 @@
alias 1.10 - 2023.10.15
===========================================================
* require Dotclear 2.28
* require PHP 8.1
* Upgrade to Dotclear 2.28
alias 1.9 - 2023.08.06 alias 1.9 - 2023.08.06
=========================================================== ===========================================================
* require Dotclear 2.27 * require Dotclear 2.27

View File

@ -1,10 +1,10 @@
# README # README
[![Release](https://img.shields.io/badge/release-1.9-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/alias/releases) [![Release](https://img.shields.io/badge/release-1.10-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/alias/releases)
![Date](https://img.shields.io/badge/date-2023.08.07-c44d58.svg)] ![Date](https://img.shields.io/badge/date-2023.10.15-c44d58.svg)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download) [![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/alias) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/alias)
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/alias/blob/master/LICENSE) [![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/alias/src/branch/master/LICENSE)
## ABOUT ## ABOUT
@ -14,8 +14,8 @@ _alias_ is a plugin for the open-source web publishing software called [Dotclear
## REQUIREMENTS ## REQUIREMENTS
* Dotclear 2.27 * Dotclear 2.28
* PHP 7.4+ * PHP 8.1+
* Dotclear admin permission for management * Dotclear admin permission for management
## USAGE ## USAGE
@ -38,7 +38,7 @@ so more there are aliases, more page load is slow.
## LINKS ## LINKS
* [License](https://git.dotclear.watch/JcDenis/alias/blob/master/LICENSE) * [License](https://git.dotclear.watch/JcDenis/alias/src/branch/master/LICENSE)
* [Packages & details](https://git.dotclear.watch/JcDenis/alias/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/alias)) * [Packages & details](https://git.dotclear.watch/JcDenis/alias/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/alias))
* [Sources & contributions](https://git.dotclear.watch/JcDenis/alias) (or on [GitHub](https://github.com/JcDenis/alias)) * [Sources & contributions](https://git.dotclear.watch/JcDenis/alias) (or on [GitHub](https://github.com/JcDenis/alias))
* [Issues & security](https://git.dotclear.watch/JcDenis/alias/issues) (or on [GitHub](https://github.com/JcDenis/alias/issues)) * [Issues & security](https://git.dotclear.watch/JcDenis/alias/issues) (or on [GitHub](https://github.com/JcDenis/alias/issues))
@ -47,6 +47,6 @@ so more there are aliases, more page load is slow.
* Olivier Meunier (author) * Olivier Meunier (author)
* Franck-paul * Franck-paul
* Jean-Christian Denis * Jean-Christian Denis (latest)
You are welcome to contribute to this code. You are welcome to contribute to this code.

View File

@ -1,33 +1,31 @@
<?php <?php
/** /**
* @brief alias, a plugin for Dotclear 2 * @file
* @brief The plugin alias definition
* @ingroup alias
* *
* @package Dotclear * @defgroup alias Plugin alias.
* @subpackage Plugin
* *
* @author Olivier Meunier and contributors * Create aliases of your blog's URLs.
* *
* @copyright Jean-Christian Denis * @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { declare(strict_types=1);
return null;
}
$this->registerModule( $this->registerModule(
'alias', 'alias',
"Create aliases of your blog's URLs", "Create aliases of your blog's URLs",
'Olivier Meunier and contributors', 'Olivier Meunier and contributors',
'1.9', '1.10',
[ [
'requires' => [['core', '2.27']], 'requires' => [['core', '2.28']],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => 'My',
dcCore::app()->auth::PERMISSION_ADMIN,
]),
'type' => 'plugin', 'type' => 'plugin',
'priority' => 2, 'priority' => 2,
'support' => 'https://git.dotclear.watch/JcDenis/alias/issues', 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
'details' => 'https://git.dotclear.watch/JcDenis/alias/src/branch/master/README.md', 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
'repository' => 'https://git.dotclear.watch/JcDenis/alias/raw/branch/master/dcstore.xml', 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
] ]
); );

View File

@ -1,20 +0,0 @@
<?php
/**
* @brief alias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
class initAlias
{
public const ALIAS_TABLE_NAME = 'alias';
}

View File

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="alias"> <module id="alias">
<name>alias</name> <name>alias</name>
<version>1.9</version> <version>1.10</version>
<author>Olivier Meunier and contributors</author> <author>Olivier Meunier and contributors</author>
<desc>Create aliases of your blog's URLs</desc> <desc>Create aliases of your blog's URLs</desc>
<file>https://git.dotclear.watch/JcDenis/alias/releases/download/v1.9/plugin-alias.zip</file> <file>https://git.dotclear.watch/JcDenis/alias/releases/download/v1.10/plugin-alias.zip</file>
<da:dcmin>2.27</da:dcmin> <da:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/alias/src/branch/master/README.md</da:details> <da:details>https://git.dotclear.watch/JcDenis/alias/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/alias/issues</da:support> <da:support>https://git.dotclear.watch/JcDenis/alias/issues</da:support>
</module> </module>

View File

@ -1,17 +1,11 @@
<?php <?php
/** /**
* @brief alias, a plugin for Dotclear 2 * @file
* @brief The plugin alias resources
* @ingroup alias
* *
* @package Dotclear * @author Olivier Meunier (author)
* @subpackage Plugin * @author Jean-Christian Denis (latest)
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { \Dotclear\App::backend()->resources()->set('help', 'alias', __DIR__ . '/help/help.html');
return;
}
dcCore::app()->resources['help']['alias'] = __DIR__ . '/help/help.html';

View File

@ -1,17 +1,11 @@
<?php <?php
/** /**
* @brief alias, a plugin for Dotclear 2 * @file
* @brief The plugin alias resources
* @ingroup alias
* *
* @package Dotclear * @author Olivier Meunier (author)
* @subpackage Plugin * @author Jean-Christian Denis (latest)
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { \Dotclear\App::backend()->resources()->set('help', 'alias', __DIR__ . '/help/help.html');
return;
}
dcCore::app()->resources['help']['alias'] = __DIR__ . '/help/help.html';

View File

@ -1,20 +1,10 @@
<?php <?php
/**
* @brief alias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\alias; namespace Dotclear\Plugin\alias;
use dcCore; use Dotclear\App;
use Dotclear\Database\Statement\{ use Dotclear\Database\Statement\{
DeleteStatement, DeleteStatement,
SelectStatement SelectStatement
@ -22,17 +12,33 @@ use Dotclear\Database\Statement\{
use Exception; use Exception;
/** /**
* plugin Alias main class * @brief alias main class.
* @ingroup alias
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Alias class Alias
{ {
/** @var array $aliases Stak of aliases */ /**
* Alias table name.
*
* @var string ALIAS_TABLE_NAME
*/
public const ALIAS_TABLE_NAME = 'alias';
/**
* Stack of aliases.
*
* @var array<int, array<string, string>> $aliases
*/
protected array $aliases = []; protected array $aliases = [];
/** /**
* Get aliases. * Get aliases.
* *
* @return array Stack of aliases * @return array<int, array<string, string>> Stack of aliases
*/ */
public function getAliases(): array public function getAliases(): array
{ {
@ -40,20 +46,19 @@ class Alias
return $this->aliases; return $this->aliases;
} }
// nullsafe if (!App::blog()->isDefined()) {
if (is_null(dcCore::app()->blog)) {
return []; return [];
} }
$sql = new SelectStatement(); $sql = new SelectStatement();
$rs = $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) $rs = $sql->from(App::con()->prefix() . Alias::ALIAS_TABLE_NAME)
->columns([ ->columns([
'alias_url', 'alias_url',
'alias_destination', 'alias_destination',
'alias_position', 'alias_position',
'alias_redirect', 'alias_redirect',
]) ])
->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog->id)) ->where('blog_id = ' . $sql->quote(App::blog()->id()))
->order('alias_position ASC') ->order('alias_position ASC')
->select(); ->select();
@ -65,7 +70,7 @@ class Alias
/** /**
* Update aliases stack. * Update aliases stack.
* *
* @param array $aliases The alias stack * @param array<int, array<string, string>> $aliases The alias stack
*/ */
public function updateAliases(array $aliases): void public function updateAliases(array $aliases): void
{ {
@ -76,7 +81,7 @@ class Alias
} }
} }
dcCore::app()->con->begin(); App::con()->begin();
try { try {
$this->deleteAliases(); $this->deleteAliases();
@ -86,9 +91,9 @@ class Alias
} }
} }
dcCore::app()->con->commit(); App::con()->commit();
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->con->rollback(); App::con()->rollback();
throw $e; throw $e;
} }
@ -104,8 +109,7 @@ class Alias
*/ */
public function createAlias(string $url, string $destination, int $position, bool $redirect): void public function createAlias(string $url, string $destination, int $position, bool $redirect): void
{ {
// nullsafe if (!App::blog()->isDefined()) {
if (is_null(dcCore::app()->blog)) {
return; return;
} }
@ -119,8 +123,8 @@ class Alias
throw new Exception(__('Alias destination is empty.')); throw new Exception(__('Alias destination is empty.'));
} }
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::ALIAS_TABLE_NAME); $cur = App::con()->openCursor(App::con()->prefix() . Alias::ALIAS_TABLE_NAME);
$cur->setField('blog_id', (string) dcCore::app()->blog->id); $cur->setField('blog_id', App::blog()->id());
$cur->setField('alias_url', (string) $url); $cur->setField('alias_url', (string) $url);
$cur->setField('alias_destination', (string) $destination); $cur->setField('alias_destination', (string) $destination);
$cur->setField('alias_position', abs((int) $position)); $cur->setField('alias_position', abs((int) $position));
@ -135,14 +139,13 @@ class Alias
*/ */
public function deleteAlias(string $url): void public function deleteAlias(string $url): void
{ {
// nullsafe if (!App::blog()->isDefined()) {
if (is_null(dcCore::app()->blog)) {
return; return;
} }
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) $sql->from(App::con()->prefix() . Alias::ALIAS_TABLE_NAME)
->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog->id)) ->where('blog_id = ' . $sql->quote(App::blog()->id()))
->and('alias_url = ' . $sql->quote($url)) ->and('alias_url = ' . $sql->quote($url))
->delete(); ->delete();
} }
@ -152,14 +155,13 @@ class Alias
*/ */
public function deleteAliases(): void public function deleteAliases(): void
{ {
// nullsafe if (!App::blog()->isDefined()) {
if (is_null(dcCore::app()->blog)) {
return; return;
} }
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) $sql->from(App::con()->prefix() . Alias::ALIAS_TABLE_NAME)
->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog->id)) ->where('blog_id = ' . $sql->quote(App::blog()->id()))
->delete(); ->delete();
} }
@ -172,6 +174,6 @@ class Alias
*/ */
public static function removeBlogUrl(string $url): string public static function removeBlogUrl(string $url): string
{ {
return is_null(dcCore::app()->blog) ? trim($url) : str_replace(dcCore::app()->blog->url, '', trim($url)); return App::blog()->isDefined() ? str_replace(App::blog()->url(), '', trim($url)) : trim($url);
} }
} }

View File

@ -1,20 +1,10 @@
<?php <?php
/**
* @brief alias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\alias; namespace Dotclear\Plugin\alias;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Plugin\importExport\{ use Dotclear\Plugin\importExport\{
FlatBackupItem, FlatBackupItem,
@ -22,6 +12,14 @@ use Dotclear\Plugin\importExport\{
FlatImportV2 FlatImportV2
}; };
/**
* @brief alias backend class.
* @ingroup alias
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Backend extends Process class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
@ -37,25 +35,25 @@ class Backend extends Process
My::addBackendMenuItem(); My::addBackendMenuItem();
dcCore::app()->addBehaviors([ App::behavior()->addBehaviors([
'exportFullV2' => function (FlatExport $exp): void { 'exportFullV2' => function (FlatExport $exp): void {
$exp->exportTable(My::ALIAS_TABLE_NAME); $exp->exportTable(Alias::ALIAS_TABLE_NAME);
}, },
'exportSingleV2' => function (FlatExport $exp, ?string $blog_id): void { 'exportSingleV2' => function (FlatExport $exp, ?string $blog_id): void {
$exp->export( $exp->export(
'alias', 'alias',
'SELECT alias_url, alias_destination, alias_position ' . 'SELECT alias_url, alias_destination, alias_position ' .
'FROM ' . dcCore::app()->prefix . My::ALIAS_TABLE_NAME . ' A ' . 'FROM ' . App::con()->prefix() . Alias::ALIAS_TABLE_NAME . ' A ' .
"WHERE A.blog_id = '" . $blog_id . "'" "WHERE A.blog_id = '" . $blog_id . "'"
); );
}, },
'importInitV2' => function (FlatImportV2 $bk): void { 'importInitV2' => function (FlatImportV2 $bk): void {
$bk->cur_alias = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::ALIAS_TABLE_NAME); $bk->cur_alias = App::con()->openCursor(App::con()->prefix() . Alias::ALIAS_TABLE_NAME);
$bk->alias = new Alias(); $bk->alias = new Alias();
$bk->aliases = $bk->alias->getAliases(); $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) { if ($line->__name == Alias::ALIAS_TABLE_NAME) {
$bk->cur_alias->clean(); $bk->cur_alias->clean();
$bk->cur_alias->setField('blog_id', (string) $line->blog_id); $bk->cur_alias->setField('blog_id', (string) $line->blog_id);
$bk->cur_alias->setField('alias_url', (string) $line->alias_url); $bk->cur_alias->setField('alias_url', (string) $line->alias_url);
@ -65,7 +63,7 @@ class Backend extends Process
} }
}, },
'importSingleV2' => function (/*bool|FlatBackupItem */$line, FlatImportV2 $bk): void { 'importSingleV2' => function (/*bool|FlatBackupItem */$line, FlatImportV2 $bk): void {
if ($line->__name == My::ALIAS_TABLE_NAME) { if ($line->__name == Alias::ALIAS_TABLE_NAME) {
$found = false; $found = false;
foreach ($bk->aliases as $v) { foreach ($bk->aliases as $v) {
if ($v['alias_url'] == $line->alias_url) { if ($v['alias_url'] == $line->alias_url) {

View File

@ -1,24 +1,22 @@
<?php <?php
/**
* @brief alias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\alias; namespace Dotclear\Plugin\alias;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Database\Structure; use Dotclear\Database\Structure;
use Exception; use Exception;
/**
* @brief alias install class.
* @ingroup alias
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Install extends Process class Install extends Process
{ {
public static function init(): bool public static function init(): bool
@ -33,8 +31,8 @@ class Install extends Process
} }
try { try {
$s = new Structure(dcCore::app()->con, dcCore::app()->prefix); $s = new Structure(App::con(), App::con()->prefix());
$s->__get(My::ALIAS_TABLE_NAME) $s->__get(Alias::ALIAS_TABLE_NAME)
->field('blog_id', 'varchar', 32, false) ->field('blog_id', 'varchar', 32, false)
->field('alias_url', 'varchar', 255, false) ->field('alias_url', 'varchar', 255, false)
->field('alias_destination', 'varchar', 255, false) ->field('alias_destination', 'varchar', 255, false)
@ -49,11 +47,11 @@ class Install extends Process
->reference('fk_alias_blog', 'blog_id', 'blog', 'blog_id', 'cascade', 'cascade') ->reference('fk_alias_blog', 'blog_id', 'blog', 'blog_id', 'cascade', 'cascade')
; ;
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s); (new Structure(App::con(), App::con()->prefix()))->synchronize($s);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
return false; return false;
} }

View File

@ -1,20 +1,10 @@
<?php <?php
/**
* @brief alias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\alias; namespace Dotclear\Plugin\alias;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Core\Backend\{ use Dotclear\Core\Backend\{
Notices, Notices,
@ -37,7 +27,12 @@ use Dotclear\Helper\Html\Html;
use Exception; use Exception;
/** /**
* Manage contributions list * @brief alias manage class.
* @ingroup alias
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Manage extends Process class Manage extends Process
{ {
@ -66,7 +61,7 @@ class Manage extends Process
Notices::addSuccessNotice(__('Aliases successfully updated.')); Notices::addSuccessNotice(__('Aliases successfully updated.'));
My::redirect(); My::redirect();
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
} }
@ -77,7 +72,7 @@ class Manage extends Process
Notices::addSuccessNotice(__('Alias successfully created.')); Notices::addSuccessNotice(__('Alias successfully created.'));
My::redirect(); My::redirect();
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
} }
@ -106,7 +101,7 @@ class Manage extends Process
(new Div())->items([ (new Div())->items([
(new Text('h3', __('New alias'))), (new Text('h3', __('New alias'))),
(new Form(My::id() . '_form'))->method('post')->action(dcCore::app()->admin->getPageURL())->fields([ (new Form(My::id() . '_form'))->method('post')->action(App::backend()->getPageURL())->fields([
(new Para())->class('field')->items([ (new Para())->class('field')->items([
(new Label(__('Alias URL:'), Label::OUTSIDE_LABEL_BEFORE))->for('alias_url'), (new Label(__('Alias URL:'), Label::OUTSIDE_LABEL_BEFORE))->for('alias_url'),
(new Input('alias_url'))->size(50)->maxlenght(255), (new Input('alias_url'))->size(50)->maxlenght(255),
@ -115,7 +110,7 @@ class Manage extends Process
(new Label(__('Alias destination:'), Label::OUTSIDE_LABEL_BEFORE))->for('alias_destination'), (new Label(__('Alias destination:'), Label::OUTSIDE_LABEL_BEFORE))->for('alias_destination'),
(new Input('alias_destination'))->size(50)->maxlenght(255), (new Input('alias_destination'))->size(50)->maxlenght(255),
]), ]),
(new Note())->class('form-note')->text(sprintf(__('Do not put blog URL "%s" in fields.'), dcCore::app()->blog->url)), (new Note())->class('form-note')->text(sprintf(__('Do not put blog URL "%s" in fields.'), App::blog()->url())),
(new Para())->items([ (new Para())->items([
(new Checkbox('alias_redirect', false))->value(1), (new Checkbox('alias_redirect', false))->value(1),
(new Label(__('Do visible redirection to destination'), Label::OUTSIDE_LABEL_AFTER))->for('alias_redirect')->class('classic'), (new Label(__('Do visible redirection to destination'), Label::OUTSIDE_LABEL_AFTER))->for('alias_redirect')->class('classic'),
@ -143,7 +138,7 @@ class Manage extends Process
echo '<p>' . __('No alias') . '</p>'; echo '<p>' . __('No alias') . '</p>';
} else { } else {
echo echo
'<form action="' . dcCore::app()->admin->getPageURL() . '" method="post">' . '<form action="' . App::backend()->getPageURL() . '" method="post">' .
'<p>' . sprintf(__('There is %s alias.', 'There are %s aliases.', count($aliases)), count($aliases)) . '</p>' . '<p>' . sprintf(__('There is %s alias.', 'There are %s aliases.', count($aliases)), count($aliases)) . '</p>' .
'<div class="table-outer">' . '<div class="table-outer">' .
'<table>' . '<table>' .
@ -167,7 +162,7 @@ class Manage extends Process
'<td class="minimal">' . '<td class="minimal">' .
(new Number(['a[' . $k . '][alias_position]']))->min(1)->max(count($aliases))->default((int) $v['alias_position'])->class('position')->title(sprintf(__('position of %s'), Html::escapeHTML($v['alias_url'])))->render() . '</td>' . (new Number(['a[' . $k . '][alias_position]']))->min(1)->max(count($aliases))->default((int) $v['alias_position'])->class('position')->title(sprintf(__('position of %s'), Html::escapeHTML($v['alias_url'])))->render() . '</td>' .
'<td class="maximal">' . '<td class="maximal">' .
(new Checkbox(['a[' . $k . '][alias_redirect]'], (bool) $v['alias_redirect']))->title(sprintf(__('visible redirection to %s'), Html::escapeHTML(dcCore::app()->blog->url . $v['alias_destination'])))->render() . '</td>' . (new Checkbox(['a[' . $k . '][alias_redirect]'], (bool) $v['alias_redirect']))->title(sprintf(__('visible redirection to %s'), Html::escapeHTML(App::blog()->url() . $v['alias_destination'])))->render() . '</td>' .
'</tr>'; '</tr>';
} }

View File

@ -1,36 +1,31 @@
<?php <?php
/**
* @brief alias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\alias; namespace Dotclear\Plugin\alias;
use dcCore; use Dotclear\App;
use Dotclear\Module\MyPlugin; use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * @brief alias My helper.
* @ingroup alias
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class My extends MyPlugin class My extends MyPlugin
{ {
/** @var string Plugin table name */
public const ALIAS_TABLE_NAME = 'alias';
public static function checkCustomContext(int $context): ?bool public static function checkCustomContext(int $context): ?bool
{ {
return !in_array($context, [My::BACKEND, My::MANAGE, My::MENU]) ? null : return match ($context) {
defined('DC_CONTEXT_ADMIN') My::BACKEND, My::MANAGE, My::MENU => App::task()->checkContext('BACKEND')
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ && App::auth()->check(App::auth()->makePermissions([
dcCore::app()->auth::PERMISSION_ADMIN, App::auth()::PERMISSION_ADMIN,
]), dcCore::app()->blog->id); ]), App::blog()->id()),
default => null,
};
} }
} }

View File

@ -1,24 +1,22 @@
<?php <?php
/**
* @brief alias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\alias; namespace Dotclear\Plugin\alias;
use dcCore; use Dotclear\App;
use dcUrlHandlers; use Dotclear\Core\Frontend\Url;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Helper\Network\Http; use Dotclear\Helper\Network\Http;
/**
* @brief alias prepend class.
* @ingroup alias
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Prepend extends Process class Prepend extends Process
{ {
public static function init(): bool public static function init(): bool
@ -32,7 +30,7 @@ class Prepend extends Process
return false; return false;
} }
dcCore::app()->addBehavior('urlHandlerGetArgsDocument', function (dcUrlHandlers $handler): void { App::behavior()->addBehavior('urlHandlerGetArgsDocument', function (Url $handler): void {
$found = $redir = false; $found = $redir = false;
$type = ''; $type = '';
$part = $args = $_SERVER['URL_REQUEST_PART']; $part = $args = $_SERVER['URL_REQUEST_PART'];
@ -63,19 +61,20 @@ class Prepend extends Process
// Use visible redirection // Use visible redirection
if ($redir) { if ($redir) {
Http::redirect(dcCore::app()->blog->url . $part); Http::redirect(App::blog()->url() . $part);
} }
// regain URL type // regain URL type
$_SERVER['URL_REQUEST_PART'] = $part; $_SERVER['URL_REQUEST_PART'] = $part;
dcCore::app()->url->getArgs($part, $type, $args); $handler->getArgs($part, $type, $args);
// call real handler // call real handler
if (!$type) { if (!$type) {
dcCore::app()->url->callDefaultHandler($args); $handler->callDefaultHandler($args);
} else { } else {
dcCore::app()->url->callHandler($type, $args); $handler->callHandler($type, $args);
} }
exit;
}); });
return true; return true;

View File

@ -1,23 +1,20 @@
<?php <?php
/**
* @brief alias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\alias; namespace Dotclear\Plugin\alias;
use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
/**
* @brief alias uninstall class.
* @ingroup alias
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Uninstall extends Process class Uninstall extends Process
{ {
public static function init(): bool public static function init(): bool
@ -27,7 +24,7 @@ class Uninstall extends Process
public static function process(): bool public static function process(): bool
{ {
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) { if (!self::status()) {
return false; return false;
} }
@ -35,7 +32,7 @@ class Uninstall extends Process
->addUserAction( ->addUserAction(
'tables', 'tables',
'delete', 'delete',
My::ALIAS_TABLE_NAME Alias::ALIAS_TABLE_NAME
) )
->addUserAction( ->addUserAction(
'plugins', 'plugins',
@ -51,7 +48,7 @@ class Uninstall extends Process
->addDirectAction( ->addDirectAction(
'tables', 'tables',
'delete', 'delete',
My::ALIAS_TABLE_NAME Alias::ALIAS_TABLE_NAME
) )
->addDirectAction( ->addDirectAction(
'plugins', 'plugins',