diff --git a/CHANGELOG.md b/CHANGELOG.md index 59dc389..72b337b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 =========================================================== * require Dotclear 2.27 diff --git a/README.md b/README.md index d53dc32..331eed6 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # README -[![Release](https://img.shields.io/badge/release-1.9-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/alias/releases) -![Date](https://img.shields.io/badge/date-2023.08.07-c44d58.svg)] -[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download) +[![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.10.15-c44d58.svg) +[![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) -[![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 @@ -14,8 +14,8 @@ _alias_ is a plugin for the open-source web publishing software called [Dotclear ## REQUIREMENTS -* Dotclear 2.27 -* PHP 7.4+ +* Dotclear 2.28 +* PHP 8.1+ * Dotclear admin permission for management ## USAGE @@ -38,7 +38,7 @@ so more there are aliases, more page load is slow. ## 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)) * [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)) @@ -47,6 +47,6 @@ so more there are aliases, more page load is slow. * Olivier Meunier (author) * Franck-paul -* Jean-Christian Denis +* Jean-Christian Denis (latest) You are welcome to contribute to this code. diff --git a/_define.php b/_define.php index 41a5005..c766234 100644 --- a/_define.php +++ b/_define.php @@ -1,33 +1,31 @@ registerModule( 'alias', "Create aliases of your blog's URLs", 'Olivier Meunier and contributors', - '1.9', + '1.10', [ - 'requires' => [['core', '2.27']], - 'permissions' => dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_ADMIN, - ]), - 'type' => 'plugin', - 'priority' => 2, - 'support' => 'https://git.dotclear.watch/JcDenis/alias/issues', - 'details' => 'https://git.dotclear.watch/JcDenis/alias/src/branch/master/README.md', - 'repository' => 'https://git.dotclear.watch/JcDenis/alias/raw/branch/master/dcstore.xml', + 'requires' => [['core', '2.28']], + 'permissions' => 'My', + 'type' => 'plugin', + 'priority' => 2, + 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', + 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', + 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', ] ); diff --git a/_init.php b/_init.php deleted file mode 100644 index 976a213..0000000 --- a/_init.php +++ /dev/null @@ -1,20 +0,0 @@ - alias - 1.9 + 1.10 Olivier Meunier and contributors Create aliases of your blog's URLs - https://git.dotclear.watch/JcDenis/alias/releases/download/v1.9/plugin-alias.zip - 2.27 + https://git.dotclear.watch/JcDenis/alias/releases/download/v1.10/plugin-alias.zip + 2.28 https://git.dotclear.watch/JcDenis/alias/src/branch/master/README.md https://git.dotclear.watch/JcDenis/alias/issues diff --git a/locales/en/resources.php b/locales/en/resources.php index 60866d0..ee56eec 100644 --- a/locales/en/resources.php +++ b/locales/en/resources.php @@ -1,17 +1,11 @@ resources['help']['alias'] = __DIR__ . '/help/help.html'; +\Dotclear\App::backend()->resources()->set('help', 'alias', __DIR__ . '/help/help.html'); diff --git a/locales/fr/resources.php b/locales/fr/resources.php index 60866d0..ee56eec 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -1,17 +1,11 @@ resources['help']['alias'] = __DIR__ . '/help/help.html'; +\Dotclear\App::backend()->resources()->set('help', 'alias', __DIR__ . '/help/help.html'); diff --git a/src/Alias.php b/src/Alias.php index 5787783..7af2cba 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -1,20 +1,10 @@ > $aliases + */ protected array $aliases = []; /** * Get aliases. * - * @return array Stack of aliases + * @return array> Stack of aliases */ public function getAliases(): array { @@ -40,20 +46,19 @@ class Alias return $this->aliases; } - // nullsafe - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return []; } $sql = new SelectStatement(); - $rs = $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) + $rs = $sql->from(App::con()->prefix() . Alias::ALIAS_TABLE_NAME) ->columns([ 'alias_url', 'alias_destination', 'alias_position', 'alias_redirect', ]) - ->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog->id)) + ->where('blog_id = ' . $sql->quote(App::blog()->id())) ->order('alias_position ASC') ->select(); @@ -65,7 +70,7 @@ class Alias /** * Update aliases stack. * - * @param array $aliases The alias stack + * @param array> $aliases The alias stack */ public function updateAliases(array $aliases): void { @@ -76,7 +81,7 @@ class Alias } } - dcCore::app()->con->begin(); + App::con()->begin(); try { $this->deleteAliases(); @@ -86,9 +91,9 @@ class Alias } } - dcCore::app()->con->commit(); + App::con()->commit(); } catch (Exception $e) { - dcCore::app()->con->rollback(); + App::con()->rollback(); throw $e; } @@ -104,8 +109,7 @@ class Alias */ public function createAlias(string $url, string $destination, int $position, bool $redirect): void { - // nullsafe - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return; } @@ -119,8 +123,8 @@ class Alias throw new Exception(__('Alias destination is empty.')); } - $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::ALIAS_TABLE_NAME); - $cur->setField('blog_id', (string) dcCore::app()->blog->id); + $cur = App::con()->openCursor(App::con()->prefix() . Alias::ALIAS_TABLE_NAME); + $cur->setField('blog_id', App::blog()->id()); $cur->setField('alias_url', (string) $url); $cur->setField('alias_destination', (string) $destination); $cur->setField('alias_position', abs((int) $position)); @@ -135,14 +139,13 @@ class Alias */ public function deleteAlias(string $url): void { - // nullsafe - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return; } $sql = new DeleteStatement(); - $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) - ->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog->id)) + $sql->from(App::con()->prefix() . Alias::ALIAS_TABLE_NAME) + ->where('blog_id = ' . $sql->quote(App::blog()->id())) ->and('alias_url = ' . $sql->quote($url)) ->delete(); } @@ -152,14 +155,13 @@ class Alias */ public function deleteAliases(): void { - // nullsafe - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return; } $sql = new DeleteStatement(); - $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) - ->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog->id)) + $sql->from(App::con()->prefix() . Alias::ALIAS_TABLE_NAME) + ->where('blog_id = ' . $sql->quote(App::blog()->id())) ->delete(); } @@ -172,6 +174,6 @@ class Alias */ 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); } } diff --git a/src/Backend.php b/src/Backend.php index 5d9864c..d27a4c9 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -1,20 +1,10 @@ addBehaviors([ + App::behavior()->addBehaviors([ '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 { $exp->export( 'alias', '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 . "'" ); }, '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->aliases = $bk->alias->getAliases(); }, '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->setField('blog_id', (string) $line->blog_id); $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 { - if ($line->__name == My::ALIAS_TABLE_NAME) { + if ($line->__name == Alias::ALIAS_TABLE_NAME) { $found = false; foreach ($bk->aliases as $v) { if ($v['alias_url'] == $line->alias_url) { diff --git a/src/Install.php b/src/Install.php index 01b3441..80954fb 100644 --- a/src/Install.php +++ b/src/Install.php @@ -1,24 +1,22 @@ con, dcCore::app()->prefix); - $s->__get(My::ALIAS_TABLE_NAME) + $s = new Structure(App::con(), App::con()->prefix()); + $s->__get(Alias::ALIAS_TABLE_NAME) ->field('blog_id', 'varchar', 32, false) ->field('alias_url', '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') ; - (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s); + (new Structure(App::con(), App::con()->prefix()))->synchronize($s); return true; } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); return false; } diff --git a/src/Manage.php b/src/Manage.php index 6a7b077..b7ba871 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -1,20 +1,10 @@ error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } @@ -77,7 +72,7 @@ class Manage extends Process Notices::addSuccessNotice(__('Alias successfully created.')); My::redirect(); } 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 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 Label(__('Alias URL:'), Label::OUTSIDE_LABEL_BEFORE))->for('alias_url'), (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 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 Checkbox('alias_redirect', false))->value(1), (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 '

' . __('No alias') . '

'; } else { echo - '
' . + '' . '

' . sprintf(__('There is %s alias.', 'There are %s aliases.', count($aliases)), count($aliases)) . '

' . '
' . '' . @@ -167,7 +162,7 @@ class Manage extends Process '' . '' . + (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() . '' . ''; } diff --git a/src/My.php b/src/My.php index 63d4385..ef38aa7 100644 --- a/src/My.php +++ b/src/My.php @@ -1,36 +1,31 @@ auth->check(dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_ADMIN, - ]), dcCore::app()->blog->id); + return match ($context) { + My::BACKEND, My::MANAGE, My::MENU => App::task()->checkContext('BACKEND') + && App::auth()->check(App::auth()->makePermissions([ + App::auth()::PERMISSION_ADMIN, + ]), App::blog()->id()), + + default => null, + }; } } diff --git a/src/Prepend.php b/src/Prepend.php index e4f535e..805c1bf 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -1,24 +1,22 @@ addBehavior('urlHandlerGetArgsDocument', function (dcUrlHandlers $handler): void { + App::behavior()->addBehavior('urlHandlerGetArgsDocument', function (Url $handler): void { $found = $redir = false; $type = ''; $part = $args = $_SERVER['URL_REQUEST_PART']; @@ -63,19 +61,20 @@ class Prepend extends Process // Use visible redirection if ($redir) { - Http::redirect(dcCore::app()->blog->url . $part); + Http::redirect(App::blog()->url() . $part); } // regain URL type $_SERVER['URL_REQUEST_PART'] = $part; - dcCore::app()->url->getArgs($part, $type, $args); + $handler->getArgs($part, $type, $args); // call real handler if (!$type) { - dcCore::app()->url->callDefaultHandler($args); + $handler->callDefaultHandler($args); } else { - dcCore::app()->url->callHandler($type, $args); + $handler->callHandler($type, $args); } + exit; }); return true; diff --git a/src/Uninstall.php b/src/Uninstall.php index 7fd2a23..bcb1f73 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -1,23 +1,20 @@ plugins->moduleExists('Uninstaller')) { + if (!self::status()) { return false; } @@ -35,7 +32,7 @@ class Uninstall extends Process ->addUserAction( 'tables', 'delete', - My::ALIAS_TABLE_NAME + Alias::ALIAS_TABLE_NAME ) ->addUserAction( 'plugins', @@ -51,7 +48,7 @@ class Uninstall extends Process ->addDirectAction( 'tables', 'delete', - My::ALIAS_TABLE_NAME + Alias::ALIAS_TABLE_NAME ) ->addDirectAction( 'plugins',
' . (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() . '' . - (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() . '