Compare commits

..

No commits in common. "0f28393c6182acddfded0871f799ed8e90806fdb" and "f64d6de462705247fd8cc2c057011fd081030131" have entirely different histories.

11 changed files with 183 additions and 128 deletions

View File

@ -1,45 +1,33 @@
filesAlias 1.1 - 2023.08.12 todo:
=========================================================== - add form to admin media item page
* Require Dotclear 2.27
* Require PHP 7.4+
* Upgrade to Dotclear 2.27
* Move third party repository
* Use Dotclear style for CHANGELOG
filesAlias 1.0 - 2023.05.13 1.0 - 2023.05.13
=========================================================== - require dotclear 2.26
* require dotclear 2.26 - fix type hint and nullsafe
* fix type hint and nullsafe
filesAlias 0.9.1 - 2023.04.23 0.9.1 - 2023.04.23
=========================================================== - require dotclear 2.26
* require dotclear 2.26 - use latest dotclear namespace (database)
* use latest dotclear namespace (database)
filesAlias 0.9 - 2023.04.22 0.9 - 2023.04.22
=========================================================== - require dotclear 2.26
* require dotclear 2.26 - add plugin Uninstaller features
* add plugin Uninstaller features - use sql statement
* use sql statement - fix nullsafe warnings
* fix nullsafe warnings - fix static init
* fix static init - add code doc
* add code doc
filesAlias 0.8 - 2023.03.26 0.8 - 2023.03.26
=========================================================== - require dotclear 2.26
* require dotclear 2.26 - use namespace
* use namespace
filesAlias 0.7.1 - 2022.12.21 0.7.1 - 2022.12.21
=========================================================== - use abstract plugin id
* use abstract plugin id - fix install
* fix install
filesAlias 0.7 - 2022.12.04 0.7 - 2022.12.04
=========================================================== - update to Dotclear 2.24
* update to Dotclear 2.24 - refresh admin UI
* refresh admin UI
filesAlias 0.6 - 2015.06.19 0.6 - 2015.06.19
=========================================================== - first public release
* first public release

View File

@ -1,10 +1,11 @@
# README # README
[![Release](https://img.shields.io/badge/release-1.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/filesAlias/releases) [![Release](https://img.shields.io/github/v/release/JcDenis/filesAlias)](https://github.com/JcDenis/filesAlias/releases)
[![Date](https://img.shields.io/badge/date-2023.08.12-c44d58.svg)](https://git.dotclear.watch/JcDenis/filesAlias/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/filesAlias)](https://github.com/JcDenis/filesAlias/releases)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download) [![Issues](https://img.shields.io/github/issues/JcDenis/filesAlias)](https://github.com/JcDenis/filesAlias/issues)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/filesAlias) [![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download)
[![License](https://img.shields.io/github/license/JcDenis/filesAlias)](https://git.dotclear.watch/JcDenis/filesAlias/blob/master/LICENSE) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/filesAlias)
[![License](https://img.shields.io/github/license/JcDenis/filesAlias)](https://github.com/JcDenis/filesAlias/blob/master/LICENSE)
## WHAT IS FILESALIAS ? ## WHAT IS FILESALIAS ?
@ -16,11 +17,10 @@ Alias can be passworded and/or disposable.
## REQUIREMENTS ## REQUIREMENTS
_filesAlias_ requires: _filesAlias_ requires:
* content admin permissions for management * content admin permissions for management
* Dotclear 2.27 * Dotclear 2.26
* PHP 7.4+
## USAGE ## USAGE
@ -32,14 +32,14 @@ You can change public URL handler (default is _pub/_) by using plugin myUrlhandl
## LINKS ## LINKS
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) * 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) * Source & contribution : [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) * Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/filesAlias)
## CONTRIBUTORS ## CONTRIBUTORS
* Osku (author) * Osku
* Pierre Van Glabeke * Pierre Van Glabeke
* Jean-Christian Denis * Jean-Christian Denis
You are welcome to contribute to this code. You are welcome to contribute to this code.

View File

@ -10,7 +10,7 @@
* @copyright Jean-Christian Denis * @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')) { if (!defined('DC_RC_PATH') || is_null(dcCore::app()->auth)) {
return null; return null;
} }
@ -18,15 +18,16 @@ $this->registerModule(
'Files alias', 'Files alias',
"Manage aliases of your blog's media", "Manage aliases of your blog's media",
'Osku and contributors', 'Osku and contributors',
'1.1', '1.0',
[ [
'requires' => [['core', '2.27']], 'requires' => [['core', '2.26']],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), ]),
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', //'support' => 'http://forum.dotclear.org/viewtopic.php?id=42317',
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', 'support' => 'https://github.com/JcDenis/' . basename(__DIR__),
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', 'details' => 'https://plugins.dotaddict.org/dc2/details/' . basename(__DIR__),
'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
] ]
); );

View File

@ -2,12 +2,12 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="filesAlias"> <module id="filesAlias">
<name>Files alias</name> <name>Files alias</name>
<version>1.1</version> <version>1.0</version>
<author>Osku and contributors</author> <author>Osku and contributors</author>
<desc>Manage aliases of your blog's media</desc> <desc>Manage aliases of your blog's media</desc>
<file>https://git.dotclear.watch/JcDenis/filesAlias/releases/download/v1.1/plugin-filesAlias.zip</file> <file>https://github.com/JcDenis/filesAlias/releases/download/v1.0/plugin-filesAlias.zip</file>
<da:dcmin>2.27</da:dcmin> <da:dcmin>2.26</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/filesAlias/src/branch/master/README.md</da:details> <da:details>https://plugins.dotaddict.org/dc2/details/filesAlias</da:details>
<da:support>https://git.dotclear.watch/JcDenis/filesAlias/issues</da:support> <da:support>https://github.com/JcDenis/filesAlias</da:support>
</module> </module>
</modules> </modules>

View File

@ -14,32 +14,55 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
use dcAdmin;
use dcCore; use dcCore;
use Dotclear\Core\Backend\Favorites; use dcFavorites;
use Dotclear\Core\Process; use dcMenu;
use dcNsProcess;
use dcPage;
class Backend extends Process class Backend extends dcNsProcess
{ {
public static function init(): bool public static function init(): bool
{ {
return self::status(My::checkContext(My::BACKEND)); static::$init = defined('DC_CONTEXT_ADMIN');
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!self::status()) { if (!static::$init) {
return false; return false;
} }
My::addBackendMenuItem(); // nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false;
}
// backend sidebar menu icon
if ((dcCore::app()->menu[dcAdmin::MENU_BLOG] instanceof dcMenu)) {
dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem(
My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
dcPage::getPF(My::id() . '/icon.svg'),
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_CONTENT_ADMIN]), dcCore::app()->blog->id)
);
}
// backend user dashboard icon // backend user dashboard icon
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (Favorites $favs): void { dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
// nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) {
return;
}
$favs->register(My::id(), [ $favs->register(My::id(), [
'title' => My::name(), 'title' => My::name(),
'url' => My::manageUrl(), 'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
'small-icon' => My::icons(), 'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
'large-icon' => My::icons(), 'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE, dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,

View File

@ -15,18 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
use dcCore; use dcCore;
use Dotclear\Core\Process; use dcNsProcess;
class Frontend extends Process class Frontend extends dcNsProcess
{ {
public static function init(): bool public static function init(): bool
{ {
return self::status(My::checkContext(My::FRONTEND)); static::$init = defined('DC_RC_PATH');
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!self::status()) { if (!static::$init) {
return false; return false;
} }

View File

@ -15,20 +15,25 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
use dcCore; use dcCore;
use Dotclear\Core\Process; use dcNsProcess;
use Dotclear\Database\Structure; use Dotclear\Database\Structure;
use Exception; use Exception;
class Install extends Process class Install extends dcNsProcess
{ {
public static function init(): bool public static function init(): bool
{ {
return self::status(My::checkContext(My::INSTALL)); if (defined('DC_CONTEXT_ADMIN')) {
$version = dcCore::app()->plugins->moduleInfo(My::id(), 'version');
static::$init = is_string($version) ? dcCore::app()->newVersion(My::id(), $version) : true;
}
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!self::status()) { if (!static::$init) {
return false; return false;
} }
@ -47,7 +52,8 @@ class Install extends Process
->reference('fk_filesalias_blog', 'blog_id', 'blog', 'blog_id', 'cascade', 'cascade') ->reference('fk_filesalias_blog', 'blog_id', 'blog', 'blog_id', 'cascade', 'cascade')
; ;
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s); $si = new Structure(dcCore::app()->con, dcCore::app()->prefix);
$changes = $si->synchronize($s);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {

View File

@ -16,11 +16,8 @@ namespace Dotclear\Plugin\filesAlias;
use dcCore; use dcCore;
use dcMedia; use dcMedia;
use Dotclear\Core\Backend\{ use dcNsProcess;
Notices, use dcPage;
Page
};
use Dotclear\Core\Process;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
@ -35,21 +32,30 @@ use Dotclear\Helper\Html\Form\{
}; };
use Exception; use Exception;
class Manage extends Process class Manage extends dcNsProcess
{ {
public static function init(): bool 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
&& 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 public static function process(): bool
{ {
if (!self::status()) { if (!static::$init) {
return false; return false;
} }
// nullsafe // nullsafe
if (is_null(dcCore::app()->blog)) { if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false; return false;
} }
@ -61,8 +67,8 @@ class Manage extends Process
if (isset($_POST['a']) && is_array($_POST['a'])) { if (isset($_POST['a']) && is_array($_POST['a'])) {
try { try {
Utils::updateAliases($_POST['a']); Utils::updateAliases($_POST['a']);
Notices::addSuccessNotice(__('Aliases successfully updated.')); dcPage::addSuccessNotice(__('Aliases successfully updated.'));
My::redirect(); dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
@ -83,8 +89,8 @@ class Manage extends Process
if (!empty($found)) { if (!empty($found)) {
try { try {
Utils::createAlias($url, $target, $totrash, $password); Utils::createAlias($url, $target, $totrash, $password);
Notices::addSuccessNotice(__('Alias for this media created.')); dcPage::addSuccessNotice(__('Alias for this media created.'));
My::redirect(); dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
@ -97,8 +103,8 @@ class Manage extends Process
if (!empty($found)) { if (!empty($found)) {
try { try {
Utils::createAlias($url, $target, $totrash, $password); Utils::createAlias($url, $target, $totrash, $password);
Notices::addSuccessNotice(__('Alias for this media modified.')); dcPage::addSuccessNotice(__('Alias for this media modified.'));
My::redirect(); dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
@ -113,11 +119,11 @@ class Manage extends Process
public static function render(): void public static function render(): void
{ {
if (!self::status()) { if (!static::$init) {
return; return;
} }
Page::openModule(My::name()); dcPage::openModule(My::name());
if (($_REQUEST['part'] ?? '') == 'new') { if (($_REQUEST['part'] ?? '') == 'new') {
self::displayAliasForm(); self::displayAliasForm();
@ -125,26 +131,26 @@ class Manage extends Process
self::displayAliasList(); self::displayAliasList();
} }
Page::helpBlock('filesAlias'); dcPage::helpBlock('filesAlias');
Page::closeModule(); dcPage::closeModule();
} }
private static function displayAliasForm(): void private static function displayAliasForm(): void
{ {
// nullsafe // nullsafe
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) { if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl) || is_null(dcCore::app()->media)) {
return; return;
} }
echo echo
Page::breadcrumb([ dcPage::breadcrumb([
Html::escapeHTML(dcCore::app()->blog->name) => '', Html::escapeHTML(dcCore::app()->blog->name) => '',
My::name() => My::manageUrl(), My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
__('New alias') => '', __('New alias') => '',
]) . ]) .
Notices::getNotices() . dcPage::notices() .
(new Form('filesalias_new'))->action(My::manageUrl())->method('post')->fields([ (new Form('filesalias_new'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->method('post')->fields([
(new Text('h3', Html::escapeHTML(__('New alias')))), (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.'), dcCore::app()->media->root_url))->class('form-note'),
// destination // destination
@ -172,7 +178,8 @@ class Manage extends Process
// submit // submit
(new Para())->items([ (new Para())->items([
(new Submit(['save']))->value(__('Save')), (new Submit(['save']))->value(__('Save')),
... My::hiddenFields(['part' => 'new']), (new Hidden(['part'], 'new')),
dcCore::app()->formNonce(false),
]), ]),
])->render(); ])->render();
} }
@ -180,20 +187,20 @@ class Manage extends Process
private static function displayAliasList(): void private static function displayAliasList(): void
{ {
// nullsafe // nullsafe
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) { if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl) || is_null(dcCore::app()->media)) {
return; return;
} }
$aliases = Utils::getAliases(); $aliases = Utils::getAliases();
echo echo
Page::breadcrumb([ dcPage::breadcrumb([
Html::escapeHTML(dcCore::app()->blog->name) => '', Html::escapeHTML(dcCore::app()->blog->name) => '',
My::name() => '', My::name() => '',
]) . ]) .
Notices::getNotices() . dcPage::notices() .
'<p class="top-add"><a class="button add" href="' . '<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>'; '">' . __('New alias') . '</a></p>';
if ($aliases->isEmpty()) { if ($aliases->isEmpty()) {
@ -226,7 +233,7 @@ class Manage extends Process
} }
echo echo
(new Form('filesalias_list'))->action(My::manageUrl())->method('post')->fields([ (new Form('filesalias_list'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->method('post')->fields([
(new Text( (new Text(
'', '',
'<div class="table-outer">' . '<div class="table-outer">' .
@ -243,7 +250,8 @@ class Manage extends Process
)), )),
(new Para())->items([ (new Para())->items([
(new Submit(['save']))->value(__('Update')), (new Submit(['save']))->value(__('Update')),
... My::hiddenFields(['part' => 'list']), (new Hidden(['part'], 'list')),
dcCore::app()->formNonce(false),
]), ]),
(new Note())->text(__('To remove a link, empty its alias or destination.'))->class('form-note'), (new Note())->text(__('To remove a link, empty its alias or destination.'))->class('form-note'),
])->render(); ])->render();

View File

@ -14,13 +14,36 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
use Dotclear\Module\MyPlugin; use dcCore;
/** /**
* This module definitions. * This module definitions.
*/ */
class My extends MyPlugin class My extends \initFilesAlias
{ {
/** @var string This plugin table name */ /**
public const ALIAS_TABLE_NAME = 'filesalias'; * This module id.
*/
public static function id(): string
{
return basename(dirname(__DIR__));
}
/**
* This module name.
*/
public static function name(): string
{
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
return __(is_string($name) ? $name : self::id());
}
/**
* This module path.
*/
public static function path(): string
{
return dirname(__DIR__);
}
} }

View File

@ -15,18 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
use dcCore; use dcCore;
use Dotclear\Core\Process; use dcNsProcess;
class Prepend extends Process class Prepend extends dcNsProcess
{ {
public static function init(): bool 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 public static function process(): bool
{ {
if (!self::status()) { if (!static::$init) {
return false; return false;
} }

View File

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