From e2b7c6350492077590b48e3695350e3b52f449a0 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Tue, 17 Oct 2023 20:48:00 +0200 Subject: [PATCH] upgrade to Dotclear 2.28 --- CHANGELOG.md | 6 ++++ README.md | 33 ++++++++---------- _define.php | 34 +++++++++--------- _init.php | 21 ------------ dcstore.xml | 6 ++-- locales/en/resources.php | 14 ++++---- locales/fr/resources.php | 14 ++++---- src/Backend.php | 30 ++++++++-------- src/Frontend.php | 30 ++++++++-------- src/FrontendTemplate.php | 27 ++++++--------- src/Install.php | 28 +++++++-------- src/Manage.php | 74 +++++++++++++++++----------------------- src/My.php | 27 ++++++++------- src/PallazzoTools.php | 21 +++++------- src/Prepend.php | 26 +++++++------- src/Uninstall.php | 23 ++++++------- src/UrlHandler.php | 39 +++++++-------------- src/Utils.php | 70 +++++++++++++------------------------ 18 files changed, 216 insertions(+), 307 deletions(-) delete mode 100644 _init.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 582eff8..13938e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +filesAlias 1.2 - 2023.10.17 +=========================================================== +* Require Dotclear 2.28 +* Require PHP 8.1 +* Upgrade to Dotclear 2.28 + filesAlias 1.1 - 2023.08.12 =========================================================== * Require Dotclear 2.27 diff --git a/README.md b/README.md index e2bfa9e..515aace 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,22 @@ # README -[![Release](https://img.shields.io/badge/release-1.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/filesAlias/releases) -[![Date](https://img.shields.io/badge/date-2023.08.12-c44d58.svg)](https://git.dotclear.watch/JcDenis/filesAlias/releases) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download) +[![Release](https://img.shields.io/badge/release-1.2-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/filesAlias/releases) +![Date](https://img.shields.io/badge/date-2023.10.17-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/filesAlias) -[![License](https://img.shields.io/github/license/JcDenis/filesAlias)](https://git.dotclear.watch/JcDenis/filesAlias/blob/master/LICENSE) +[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/filesAlias/src/branch/master/LICENSE) -## WHAT IS FILESALIAS ? +## ABOUT -_filesAlias_ is a plugin for the open-source -web publishing software called Dotclear. +_filesAlias_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). -This plugin creates public aliases of your blog's media. -Alias can be passworded and/or disposable. +> Create public aliases of your blog's media. Alias can be passworded and/or disposable. ## REQUIREMENTS -_filesAlias_ requires: - -* content admin permissions for management -* Dotclear 2.27 -* PHP 7.4+ +* Dotclear 2.28 +* PHP8.1+ +* Dotclear content admin permissions for management ## USAGE @@ -32,14 +28,15 @@ You can change public URL handler (default is _pub/_) by using plugin myUrlhandl ## LINKS -* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) -* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/filesAlias) or [GitHub Page](https://github.com/JcDenis/filesAlias) -* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/filesAlias/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/filesAlias) +* [License](https://git.dotclear.watch/JcDenis/filesAlias/src/branch/master/LICENSE) +* [Packages & details](https://git.dotclear.watch/JcDenis/filesAlias/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/filesAlias)) +* [Sources & contributions](https://git.dotclear.watch/JcDenis/filesAlias) (or on [GitHub](https://github.com/JcDenis/filesAlias)) +* [Issues & security](https://git.dotclear.watch/JcDenis/filesAlias/issues) (or on [GitHub](https://github.com/JcDenis/filesAlias/issues)) ## CONTRIBUTORS * Osku (author) * Pierre Van Glabeke -* Jean-Christian Denis +* Jean-Christian Denis (latest) You are welcome to contribute to this code. diff --git a/_define.php b/_define.php index 740badd..1395e1a 100644 --- a/_define.php +++ b/_define.php @@ -1,32 +1,30 @@ registerModule( 'Files alias', "Manage aliases of your blog's media", 'Osku and contributors', - '1.1', + '1.2', [ - 'requires' => [['core', '2.27']], - 'permissions' => dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), - 'type' => 'plugin', - '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', + 'requires' => [['core', '2.28']], + 'permissions' => 'My', + 'type' => 'plugin', + '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 fb705b0..0000000 --- a/_init.php +++ /dev/null @@ -1,21 +0,0 @@ - Files alias - 1.1 + 1.2 Osku and contributors Manage aliases of your blog's media - https://git.dotclear.watch/JcDenis/filesAlias/releases/download/v1.1/plugin-filesAlias.zip - 2.27 + https://git.dotclear.watch/JcDenis/filesAlias/releases/download/v1.2/plugin-filesAlias.zip + 2.28 https://git.dotclear.watch/JcDenis/filesAlias/src/branch/master/README.md https://git.dotclear.watch/JcDenis/filesAlias/issues diff --git a/locales/en/resources.php b/locales/en/resources.php index 6e42d26..881768e 100644 --- a/locales/en/resources.php +++ b/locales/en/resources.php @@ -1,13 +1,11 @@ resources['help']['filesAlias'] = __DIR__ . '/help/filesAlias.html'; diff --git a/locales/fr/resources.php b/locales/fr/resources.php index 6e42d26..881768e 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -1,13 +1,11 @@ resources['help']['filesAlias'] = __DIR__ . '/help/filesAlias.html'; diff --git a/src/Backend.php b/src/Backend.php index 314a13a..95efad4 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -1,23 +1,21 @@ addBehavior('adminDashboardFavoritesV2', function (Favorites $favs): void { + App::behavior()->addBehavior('adminDashboardFavoritesV2', function (Favorites $favs): void { $favs->register(My::id(), [ 'title' => My::name(), 'url' => My::manageUrl(), 'small-icon' => My::icons(), 'large-icon' => My::icons(), - 'permissions' => dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_USAGE, - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, + 'permissions' => App::auth()->makePermissions([ + App::auth()::PERMISSION_USAGE, + App::auth()::PERMISSION_CONTENT_ADMIN, ]), ]); }); diff --git a/src/Frontend.php b/src/Frontend.php index 81e9812..d366176 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -1,22 +1,20 @@ tpl->setPath( - dcCore::app()->tpl->getPath(), + App::frontend()->template()->setPath( + App::frontend()->template()->getPath(), My::path() . DIRECTORY_SEPARATOR . 'default-templates' ); // register template value for file alias - dcCore::app()->tpl->addValue( + App::frontend()->template()->addValue( 'fileAliasURL', - [FrontendTemplate::class, 'fileAliasURL'] + FrontendTemplate::fileAliasURL(...) ); return true; diff --git a/src/FrontendTemplate.php b/src/FrontendTemplate.php index 62d366e..ebdbbb2 100644 --- a/src/FrontendTemplate.php +++ b/src/FrontendTemplate.php @@ -1,24 +1,19 @@ tpl->getFilters($attr), - 'dcCore::app()->blog->url.dcCore::app()->url->getBase("filesalias")."/".dcCore::app()->ctx->filealias->filesalias_url' + App::frontend()->template()->getFilters($attr), + 'App::blog()->url().App::url()->getBase("filesalias")."/".App::frontend()->context()->filealias->filesalias_url' ) . '; ?>'; } } diff --git a/src/Install.php b/src/Install.php index 9ad8d2c..d062ac5 100644 --- a/src/Install.php +++ b/src/Install.php @@ -1,24 +1,22 @@ con, dcCore::app()->prefix); + $s = new Structure(App::con(), App::con()->prefix()); $s->__get(My::ALIAS_TABLE_NAME) ->field('blog_id', 'varchar', 32, false) @@ -47,11 +45,11 @@ class Install extends Process ->reference('fk_filesalias_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 true; diff --git a/src/Manage.php b/src/Manage.php index 79221a2..b47dc47 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -1,21 +1,10 @@ isDefined() + ) { return false; } - // nullsafe - if (is_null(dcCore::app()->blog)) { - return false; - } - - if (!(dcCore::app()->media instanceof dcMedia)) { - dcCore::app()->media = new dcMedia(); - } - // Update aliases if (isset($_POST['a']) && is_array($_POST['a'])) { try { @@ -64,7 +54,7 @@ class Manage extends Process Notices::addSuccessNotice(__('Aliases successfully updated.')); My::redirect(); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } @@ -76,8 +66,8 @@ class Manage extends Process $totrash = isset($_POST['filesalias_disposable']) ? true : false; $password = empty($_POST['filesalias_password']) ? '' : $_POST['filesalias_password']; - if (preg_match('/^' . preg_quote(dcCore::app()->media->root_url, '/') . '/', $target)) { - $target = preg_replace('/^' . preg_quote(dcCore::app()->media->root_url, '/') . '/', '', $target); + if (preg_match('/^' . preg_quote(App::media()->root_url, '/') . '/', $target)) { + $target = preg_replace('/^' . preg_quote(App::media()->root_url, '/') . '/', '', $target); $found = Utils::getMediaId($target); if (!empty($found)) { @@ -86,10 +76,10 @@ class Manage extends Process Notices::addSuccessNotice(__('Alias for this media created.')); My::redirect(); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } else { - dcCore::app()->error->add(__('Target is not in media manager.')); + App::error()->add(__('Target is not in media manager.')); } } else { $found = Utils::getMediaId($target); @@ -100,10 +90,10 @@ class Manage extends Process Notices::addSuccessNotice(__('Alias for this media modified.')); My::redirect(); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } else { - dcCore::app()->error->add(__('Target is not in media manager.')); + App::error()->add(__('Target is not in media manager.')); } } } @@ -132,21 +122,20 @@ class Manage extends Process private static function displayAliasForm(): void { - // nullsafe - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) { + if (!App::blog()->isDefined()) { return; } echo Page::breadcrumb([ - Html::escapeHTML(dcCore::app()->blog->name) => '', - My::name() => My::manageUrl(), - __('New alias') => '', + Html::escapeHTML(App::blog()->name()) => '', + My::name() => My::manageUrl(), + __('New alias') => '', ]) . Notices::getNotices() . (new Form('filesalias_new'))->action(My::manageUrl())->method('post')->fields([ (new Text('h3', Html::escapeHTML(__('New alias')))), - (new Note())->text(sprintf(__('Do not put blog media URL "%s" in fields or it will be removed.'), dcCore::app()->media->root_url))->class('form-note'), + (new Note())->text(sprintf(__('Do not put blog media URL "%s" in fields or it will be removed.'), App::media()->root_url))->class('form-note'), // destination (new Para())->items([ (new Label(__('Destination:')))->for('filesalias_destination')->class('required'), @@ -179,8 +168,7 @@ class Manage extends Process private static function displayAliasList(): void { - // nullsafe - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) { + if (!App::blog()->isDefined()) { return; } @@ -188,8 +176,8 @@ class Manage extends Process echo Page::breadcrumb([ - Html::escapeHTML(dcCore::app()->blog->name) => '', - My::name() => '', + Html::escapeHTML(App::blog()->name()) => '', + My::name() => '', ]) . Notices::getNotices() . '

' . '' . @@ -233,8 +221,8 @@ class Manage extends Process '' . '' . '' . - '' . - '' . + '' . + '' . '' . '' . '' . diff --git a/src/My.php b/src/My.php index 172ed9d..76918ed 100644 --- a/src/My.php +++ b/src/My.php @@ -1,15 +1,5 @@ url->register( + App::url()->register( 'filesalias', 'pub', '^pub/(.+)$', - [UrlHandler::class, 'alias'] + UrlHandler::alias(...) ); return true; diff --git a/src/Uninstall.php b/src/Uninstall.php index 5754dcb..8574876 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -1,23 +1,20 @@ plugins->moduleExists('Uninstaller')) { + if (!self::status()) { return false; } diff --git a/src/UrlHandler.php b/src/UrlHandler.php index b951d2f..573bcd3 100644 --- a/src/UrlHandler.php +++ b/src/UrlHandler.php @@ -1,27 +1,21 @@ ctx)) { - return; - } - $alias = Utils::getAlias($args); - dcCore::app()->ctx->__set('filealias', $alias); + App::frontend()->context()->__set('filealias', $alias); if ($alias->isEmpty()) { self::p404(); @@ -76,11 +65,7 @@ class UrlHandler extends dcUrlHandlers self::p404(); } - if (!(dcCore::app()->media instanceof dcMedia)) { - dcCore::app()->media = new dcMedia(); - } - - $file = dcCore::app()->media->getFile($media); + $file = App::media()->getFile($media); if (empty($file->file)) { self::p404(); diff --git a/src/Utils.php b/src/Utils.php index 2607a61..98fecc6 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -1,21 +1,10 @@ blog) ? '' : dcCore::app()->blog->id; - $sql = new SelectStatement(); - $rs = $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) + $rs = $sql->from(App::con()->prefix() . My::ALIAS_TABLE_NAME) ->columns([ 'filesalias_url', 'filesalias_destination', 'filesalias_password', 'filesalias_disposable', ]) - ->where('blog_id = ' . $sql->quote($blog_id)) + ->where('blog_id = ' . $sql->quote(App::blog()->id())) ->order('filesalias_url ASC') ->select(); @@ -60,18 +51,15 @@ class Utils */ public static function getAlias(string $url): MetaRecord { - // nullsafe - $blog_id = is_null(dcCore::app()->blog) ? '' : dcCore::app()->blog->id; - $sql = new SelectStatement(); - $rs = $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) + $rs = $sql->from(App::con()->prefix() . My::ALIAS_TABLE_NAME) ->columns([ 'filesalias_url', 'filesalias_destination', 'filesalias_password', 'filesalias_disposable', ]) - ->where('blog_id = ' . $sql->quote($blog_id)) + ->where('blog_id = ' . $sql->quote(App::blog()->id())) ->and('filesalias_url = ' . $sql->quote($url)) ->order('filesalias_url ASC') ->select(); @@ -97,7 +85,7 @@ class Utils */ public static function updateAliases(array $aliases): void { - dcCore::app()->con->begin(); + App::con()->begin(); try { self::deleteAliases(); @@ -108,9 +96,9 @@ class Utils } } - dcCore::app()->con->commit(); + App::con()->commit(); } catch (Exception $e) { - dcCore::app()->con->rollback(); + App::con()->rollback(); throw $e; } @@ -134,11 +122,8 @@ class Utils throw new Exception(__('File destination is empty.')); } - // nullsafe - $blog_id = is_null(dcCore::app()->blog) ? '' : dcCore::app()->blog->id; - - $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::ALIAS_TABLE_NAME); - $cur->setField('blog_id', $blog_id); + $cur = App::con()->openCursor(App::con()->prefix() . My::ALIAS_TABLE_NAME); + $cur->setField('blog_id', App::blog()->id()); $cur->setField('filesalias_url', (string) $url); $cur->setField('filesalias_destination', (string) $destination); $cur->setField('filesalias_password', $password); @@ -151,12 +136,9 @@ class Utils */ public static function deleteAliases(): void { - // nullsafe - $blog_id = is_null(dcCore::app()->blog) ? '' : dcCore::app()->blog->id; - $sql = new DeleteStatement(); - $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) - ->where('blog_id = ' . $sql->quote($blog_id)) + $sql->from(App::con()->prefix() . My::ALIAS_TABLE_NAME) + ->where('blog_id = ' . $sql->quote(App::blog()->id())) ->delete(); } @@ -167,12 +149,9 @@ class Utils */ public static function deleteAlias(string $url): void { - // nullsafe - $blog_id = is_null(dcCore::app()->blog) ? '' : dcCore::app()->blog->id; - $sql = new DeleteStatement(); - $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME) - ->where('blog_id = ' . $sql->quote($blog_id)) + $sql->from(App::con()->prefix() . My::ALIAS_TABLE_NAME) + ->where('blog_id = ' . $sql->quote(App::blog()->id())) ->and('filesalias_url = ' . $sql->quote($url)) ->delete(); } @@ -186,14 +165,13 @@ class Utils */ public static function getMediaId(string $target): int { - // nullsafe - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return 0; } - $path = dcCore::app()->blog->settings->get('system')->get('public_path'); + $path = App::blog()->settings()->get('system')->get('public_path'); $sql = new SelectStatement(); - $rs = $sql->from(dcCore::app()->prefix . dcMedia::MEDIA_TABLE_NAME) + $rs = $sql->from(App::con()->prefix() . App::postMedia()::MEDIA_TABLE_NAME) ->column('media_id') ->where('media_path = ' . $sql->quote(is_string($path) ? $path : '')) ->and('media_file = ' . $sql->quote($target))
' . __('Aliases list') . '
' . __('Destination') . ' - ' . Html::escapeHTML(dcCore::app()->media->root_url) . '(-?-)' . __('Alias') . ' - ' . dcCore::app()->blog->url . dcCore::app()->url->getBase('filesalias') . '/' . '(-?-)' . __('Destination') . ' - ' . Html::escapeHTML(App::media()->root_url) . '(-?-)' . __('Alias') . ' - ' . App::blog()->url() . App::url()->getBase('filesalias') . '/' . '(-?-)' . __('Password') . '' . __('Disposable') . '