Compare commits

..

No commits in common. "master" and "v1.1" have entirely different histories.
master ... v1.1

18 changed files with 315 additions and 231 deletions

View File

@ -1,16 +1,3 @@
filesAlias 1.2.1 - 2023.11.04
===========================================================
* Require Dotclear 2.28
* Require PHP 8.1
* Fix typo
* Code review
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 filesAlias 1.1 - 2023.08.12
=========================================================== ===========================================================
* Require Dotclear 2.27 * Require Dotclear 2.27

View File

@ -1,22 +1,26 @@
# README # README
[![Release](https://img.shields.io/badge/release-1.2.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/filesAlias/releases) [![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.11.04-c44d58.svg) [![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.28-137bbb.svg)](https://fr.dotclear.org/download) [![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/filesAlias) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/filesAlias)
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/filesAlias/src/branch/master/LICENSE) [![License](https://img.shields.io/github/license/JcDenis/filesAlias)](https://git.dotclear.watch/JcDenis/filesAlias/blob/master/LICENSE)
## ABOUT ## WHAT IS FILESALIAS ?
_filesAlias_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). _filesAlias_ is a plugin for the open-source
web publishing software called Dotclear.
> Create public aliases of your blog's media. Alias can be passworded and/or disposable. This plugin creates public aliases of your blog's media.
Alias can be passworded and/or disposable.
## REQUIREMENTS ## REQUIREMENTS
* Dotclear 2.28 _filesAlias_ requires:
* PHP8.1+
* Dotclear content admin permissions for management * content admin permissions for management
* Dotclear 2.27
* PHP 7.4+
## USAGE ## USAGE
@ -28,16 +32,14 @@ You can change public URL handler (default is _pub/_) by using plugin myUrlhandl
## LINKS ## LINKS
* [License](https://git.dotclear.watch/JcDenis/filesAlias/src/branch/master/LICENSE) * License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
* [Packages & details](https://git.dotclear.watch/JcDenis/filesAlias/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/filesAlias)) * Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/filesAlias) or [GitHub Page](https://github.com/JcDenis/filesAlias)
* [Sources & contributions](https://git.dotclear.watch/JcDenis/filesAlias) (or on [GitHub](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)
* [Issues & security](https://git.dotclear.watch/JcDenis/filesAlias/issues) (or on [GitHub](https://github.com/JcDenis/filesAlias/issues))
* [Discuss & help](https://forum.dotclear.org/viewtopic.php?id=42317)
## CONTRIBUTORS ## CONTRIBUTORS
* Osku (author) * Osku (author)
* Pierre Van Glabeke * Pierre Van Glabeke
* Jean-Christian Denis (latest) * Jean-Christian Denis
You are welcome to contribute to this code. You are welcome to contribute to this code.

View File

@ -1,30 +1,32 @@
<?php <?php
/** /**
* @file * @brief filesAlias, a plugin for Dotclear 2
* @brief The plugin filesAlias definition
* @ingroup filesAlias
* *
* @defgroup filesAlias Plugin filesAlias. * @package Dotclear
* @subpackage Plugin
* *
* Manage aliases of your blog's media. * @author Osku and contributors
* *
* @author Osku (author) * @copyright Jean-Christian Denis
* @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
*/ */
declare(strict_types=1); if (!defined('DC_RC_PATH')) {
return null;
}
$this->registerModule( $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.2.1', '1.1',
[ [
'requires' => [['core', '2.28']], 'requires' => [['core', '2.27']],
'permissions' => 'My', 'permissions' => dcCore::app()->auth->makePermissions([
'type' => 'plugin', dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', ]),
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', 'type' => 'plugin',
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', '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',
] ]
); );

21
_init.php Normal file
View File

@ -0,0 +1,21 @@
<?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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 initFilesAlias
{
/** @var string This plugin table name */
public const ALIAS_TABLE_NAME = 'filesalias';
}

View File

@ -2,11 +2,11 @@
<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.2.1</version> <version>1.1</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.2.1/plugin-filesAlias.zip</file> <file>https://git.dotclear.watch/JcDenis/filesAlias/releases/download/v1.1/plugin-filesAlias.zip</file>
<da:dcmin>2.28</da:dcmin> <da:dcmin>2.27</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/filesAlias/src/branch/master/README.md</da:details> <da:details>https://git.dotclear.watch/JcDenis/filesAlias/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/filesAlias/issues</da:support> <da:support>https://git.dotclear.watch/JcDenis/filesAlias/issues</da:support>
</module> </module>

View File

@ -1,11 +1,13 @@
<?php <?php
/** /**
* @file * @brief filesAlias, a plugin for Dotclear 2
* @brief The plugin filesAlias locales resources
* @ingroup filesAlias
* *
* @author Osku (author) * @package Dotclear
* @author Jean-Christian Denis (latest) * @subpackage Plugin
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html *
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
dcCore::app()->resources['help']['filesAlias'] = __DIR__ . '/help/filesAlias.html'; dcCore::app()->resources['help']['filesAlias'] = __DIR__ . '/help/filesAlias.html';

View File

@ -1,11 +1,13 @@
<?php <?php
/** /**
* @file * @brief filesAlias, a plugin for Dotclear 2
* @brief The plugin filesAlias locales resources
* @ingroup filesAlias
* *
* @author Osku (author) * @package Dotclear
* @author Jean-Christian Denis (latest) * @subpackage Plugin
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html *
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
dcCore::app()->resources['help']['filesAlias'] = __DIR__ . '/help/filesAlias.html'; dcCore::app()->resources['help']['filesAlias'] = __DIR__ . '/help/filesAlias.html';

View File

@ -1,21 +1,23 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
use Dotclear\App; use dcCore;
use Dotclear\Core\Backend\Favorites; use Dotclear\Core\Backend\Favorites;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/**
* @brief filesAlias backend class.
* @ingroup filesAlias
*
* @author Osku (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
@ -32,15 +34,15 @@ class Backend extends Process
My::addBackendMenuItem(); My::addBackendMenuItem();
// backend user dashboard icon // backend user dashboard icon
App::behavior()->addBehavior('adminDashboardFavoritesV2', function (Favorites $favs): void { dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (Favorites $favs): void {
$favs->register(My::id(), [ $favs->register(My::id(), [
'title' => My::name(), 'title' => My::name(),
'url' => My::manageUrl(), 'url' => My::manageUrl(),
'small-icon' => My::icons(), 'small-icon' => My::icons(),
'large-icon' => My::icons(), 'large-icon' => My::icons(),
'permissions' => App::auth()->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
App::auth()::PERMISSION_USAGE, dcCore::app()->auth::PERMISSION_USAGE,
App::auth()::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), ]),
]); ]);
}); });

View File

@ -1,20 +1,22 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
use Dotclear\App; use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/**
* @brief filesAlias frontend class.
* @ingroup filesAlias
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Frontend extends Process class Frontend extends Process
{ {
public static function init(): bool public static function init(): bool
@ -29,13 +31,14 @@ class Frontend extends Process
} }
// add path to template // add path to template
App::frontend()->template()->appendPath( dcCore::app()->tpl->setPath(
dcCore::app()->tpl->getPath(),
My::path() . DIRECTORY_SEPARATOR . 'default-templates' My::path() . DIRECTORY_SEPARATOR . 'default-templates'
); );
// register template value for file alias // register template value for file alias
App::frontend()->template()->addValue( dcCore::app()->tpl->addValue(
'fileAliasURL', 'fileAliasURL',
FrontendTemplate::fileAliasURL(...) [FrontendTemplate::class, 'fileAliasURL']
); );
return true; return true;

View File

@ -1,19 +1,24 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
use ArrayObject; use ArrayObject;
use Dotclear\App; use dcCore;
/** /**
* @brief filesAlias frontend template class. * File alias frontend template.
* @ingroup filesAlias
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class FrontendTemplate class FrontendTemplate
{ {
@ -22,17 +27,17 @@ class FrontendTemplate
* *
* attributes: * attributes:
* *
* - any filters See Tpl::getFilters() * - any filters See dcTemplate::getFilters()
* *
* @param ArrayObject<string, mixed> $attr The attributes * @param ArrayObject $attr The attributes
* *
* @return string * @return string
*/ */
public static function fileAliasURL(ArrayObject $attr): string public static function fileAliasURL(ArrayObject $attr): string
{ {
return '<?php echo ' . sprintf( return '<?php echo ' . sprintf(
App::frontend()->template()->getFilters($attr), dcCore::app()->tpl->getFilters($attr),
'App::blog()->url().App::url()->getBase("filesalias")."/".App::frontend()->context()->filealias->filesalias_url' 'dcCore::app()->blog->url.dcCore::app()->url->getBase("filesalias")."/".dcCore::app()->ctx->filealias->filesalias_url'
) . '; ?>'; ) . '; ?>';
} }
} }

View File

@ -1,22 +1,24 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
use Dotclear\App; use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Database\Structure; use Dotclear\Database\Structure;
use Exception; use Exception;
/**
* @brief filesAlias installation class.
* @ingroup filesAlias
*
* @author Osku (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
@ -31,7 +33,7 @@ class Install extends Process
} }
try { try {
$s = new Structure(App::con(), App::con()->prefix()); $s = new Structure(dcCore::app()->con, dcCore::app()->prefix);
$s->__get(My::ALIAS_TABLE_NAME) $s->__get(My::ALIAS_TABLE_NAME)
->field('blog_id', 'varchar', 32, false) ->field('blog_id', 'varchar', 32, false)
@ -45,11 +47,11 @@ 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(App::con(), App::con()->prefix()))->synchronize($s); (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
return true; return true;

View File

@ -1,10 +1,21 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
use Dotclear\App; use dcCore;
use dcMedia;
use Dotclear\Core\Backend\{ use Dotclear\Core\Backend\{
Notices, Notices,
Page Page
@ -24,14 +35,6 @@ use Dotclear\Helper\Html\Form\{
}; };
use Exception; use Exception;
/**
* @brief filesAlias manage class.
* @ingroup filesAlias
*
* @author Osku (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
{ {
public static function init(): bool public static function init(): bool
@ -41,12 +44,19 @@ class Manage extends Process
public static function process(): bool public static function process(): bool
{ {
if (!self::status() if (!self::status()) {
|| !APP::blog()->isDefined()
) {
return false; return false;
} }
// nullsafe
if (is_null(dcCore::app()->blog)) {
return false;
}
if (!(dcCore::app()->media instanceof dcMedia)) {
dcCore::app()->media = new dcMedia();
}
// Update aliases // Update aliases
if (isset($_POST['a']) && is_array($_POST['a'])) { if (isset($_POST['a']) && is_array($_POST['a'])) {
try { try {
@ -54,7 +64,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) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
@ -66,8 +76,8 @@ class Manage extends Process
$totrash = isset($_POST['filesalias_disposable']) ? true : false; $totrash = isset($_POST['filesalias_disposable']) ? true : false;
$password = empty($_POST['filesalias_password']) ? '' : $_POST['filesalias_password']; $password = empty($_POST['filesalias_password']) ? '' : $_POST['filesalias_password'];
if (preg_match('/^' . preg_quote(App::media()->root_url, '/') . '/', $target)) { if (preg_match('/^' . preg_quote(dcCore::app()->media->root_url, '/') . '/', $target)) {
$target = (string) preg_replace('/^' . preg_quote(App::media()->root_url, '/') . '/', '', $target); $target = preg_replace('/^' . preg_quote(dcCore::app()->media->root_url, '/') . '/', '', $target);
$found = Utils::getMediaId($target); $found = Utils::getMediaId($target);
if (!empty($found)) { if (!empty($found)) {
@ -76,10 +86,10 @@ class Manage extends Process
Notices::addSuccessNotice(__('Alias for this media created.')); Notices::addSuccessNotice(__('Alias for this media created.'));
My::redirect(); My::redirect();
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} else { } else {
App::error()->add(__('Target is not in media manager.')); dcCore::app()->error->add(__('Target is not in media manager.'));
} }
} else { } else {
$found = Utils::getMediaId($target); $found = Utils::getMediaId($target);
@ -90,10 +100,10 @@ class Manage extends Process
Notices::addSuccessNotice(__('Alias for this media modified.')); Notices::addSuccessNotice(__('Alias for this media modified.'));
My::redirect(); My::redirect();
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} else { } else {
App::error()->add(__('Target is not in media manager.')); dcCore::app()->error->add(__('Target is not in media manager.'));
} }
} }
} }
@ -122,36 +132,37 @@ class Manage extends Process
private static function displayAliasForm(): void private static function displayAliasForm(): void
{ {
if (!App::blog()->isDefined()) { // nullsafe
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) {
return; return;
} }
echo echo
Page::breadcrumb([ Page::breadcrumb([
Html::escapeHTML(App::blog()->name()) => '', Html::escapeHTML(dcCore::app()->blog->name) => '',
My::name() => My::manageUrl(), My::name() => My::manageUrl(),
__('New alias') => '', __('New alias') => '',
]) . ]) .
Notices::getNotices() . Notices::getNotices() .
(new Form('filesalias_new'))->action(My::manageUrl())->method('post')->fields([ (new Form('filesalias_new'))->action(My::manageUrl())->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.'), 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
(new Para())->items([ (new Para())->items([
(new Label(__('Destination:')))->for('filesalias_destination')->class('required'), (new Label(__('Destination:')))->for('filesalias_destination')->class('required'),
(new Input('filesalias_destination'))->size(70)->maxlength(255), (new Input('filesalias_destination'))->size(70)->maxlenght(255),
]), ]),
(new Note())->text(__('Destination file must be in media manager.'))->class('form-note'), (new Note())->text(__('Destination file must be in media manager.'))->class('form-note'),
// url // url
(new Para())->items([ (new Para())->items([
(new Label(__('URL (alias):')))->for('filesalias_url')->class('required'), (new Label(__('URL (alias):')))->for('filesalias_url')->class('required'),
(new Input('filesalias_url'))->size(70)->maxlength(255), (new Input('filesalias_url'))->size(70)->maxlenght(255),
]), ]),
(new Note())->text(__('Leave empty to get a randomize alias.'))->class('form-note'), (new Note())->text(__('Leave empty to get a randomize alias.'))->class('form-note'),
// password // password
(new Para())->items([ (new Para())->items([
(new Label(__('Password:')))->for('filesalias_password')->class('required'), (new Label(__('Password:')))->for('filesalias_password')->class('required'),
(new Input('filesalias_password'))->size(70)->maxlength(255), (new Input('filesalias_password'))->size(70)->maxlenght(255),
]), ]),
// disposable // disposable
(new Para())->items([ (new Para())->items([
@ -168,7 +179,8 @@ class Manage extends Process
private static function displayAliasList(): void private static function displayAliasList(): void
{ {
if (!App::blog()->isDefined()) { // nullsafe
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) {
return; return;
} }
@ -176,8 +188,8 @@ class Manage extends Process
echo echo
Page::breadcrumb([ Page::breadcrumb([
Html::escapeHTML(App::blog()->name()) => '', Html::escapeHTML(dcCore::app()->blog->name) => '',
My::name() => '', My::name() => '',
]) . ]) .
Notices::getNotices() . Notices::getNotices() .
'<p class="top-add"><a class="button add" href="' . '<p class="top-add"><a class="button add" href="' .
@ -194,17 +206,17 @@ class Manage extends Process
$destination = is_string($aliases->f('filesalias_destination')) ? $aliases->f('filesalias_destination') : ''; $destination = is_string($aliases->f('filesalias_destination')) ? $aliases->f('filesalias_destination') : '';
$password = is_string($aliases->f('filesalias_password')) ? $aliases->f('filesalias_password') : ''; $password = is_string($aliases->f('filesalias_password')) ? $aliases->f('filesalias_password') : '';
$disposable = !empty($aliases->f('filesalias_disposable')); $disposable = !empty($aliases->f('filesalias_disposable'));
$full = App::blog()->url() . App::url()->getBase('filesalias') . '/' . Html::escapeHTML($url); $full = dcCore::app()->blog->url . dcCore::app()->url->getBase('filesalias') . '/' . Html::escapeHTML($url);
$lines .= '<tr class="line" id="l_' . $i . '">' . $lines .= '<tr class="line" id="l_' . $i . '">' .
'<td>' . '<td>' .
(new Input(['a[' . $i . '][filesalias_destination]']))->size(50)->maxlength(255)->value(Html::escapeHTML($destination))->render() . (new Input(['a[' . $i . '][filesalias_destination]']))->size(50)->maxlenght(255)->value(Html::escapeHTML($destination))->render() .
'</td>' . '</td>' .
'<td>' . '<td>' .
(new Input(['a[' . $i . '][filesalias_url]']))->size(50)->maxlength(255)->value(Html::escapeHTML($url))->render() . (new Input(['a[' . $i . '][filesalias_url]']))->size(50)->maxlenght(255)->value(Html::escapeHTML($url))->render() .
'<a href="' . $full . '">' . __('link') . '</a></td>' . '<a href="' . $full . '">' . __('link') . '</a></td>' .
'<td>' . '<td>' .
(new Input(['a[' . $i . '][filesalias_password]']))->size(50)->maxlength(255)->value(Html::escapeHTML($password))->render() . (new Input(['a[' . $i . '][filesalias_password]']))->size(50)->maxlenght(255)->value(Html::escapeHTML($password))->render() .
'</td>' . '</td>' .
'<td class="maximal">' . '<td class="maximal">' .
(new Checkbox(['a[' . $i . '][filesalias_disposable]'], $disposable))->value(1)->render() . (new Checkbox(['a[' . $i . '][filesalias_disposable]'], $disposable))->value(1)->render() .
@ -221,8 +233,8 @@ class Manage extends Process
'<table><thead>' . '<table><thead>' .
'<caption>' . __('Aliases list') . '</caption>' . '<caption>' . __('Aliases list') . '</caption>' .
'<tr>' . '<tr>' .
'<th class="nowrap" scope="col">' . __('Destination') . ' - <ins>' . Html::escapeHTML(App::media()->root_url) . '</ins><code>(-?-)</code></th>' . '<th class="nowrap" scope="col">' . __('Destination') . ' - <ins>' . Html::escapeHTML(dcCore::app()->media->root_url) . '</ins><code>(-?-)</code></th>' .
'<th class="nowrap" scope="col">' . __('Alias') . ' - <ins>' . App::blog()->url() . App::url()->getBase('filesalias') . '/' . '</ins><code>(-?-)</code></th>' . '<th class="nowrap" scope="col">' . __('Alias') . ' - <ins>' . dcCore::app()->blog->url . dcCore::app()->url->getBase('filesalias') . '/' . '</ins><code>(-?-)</code></th>' .
'<th class="nowrap" scope="col">' . __('Password') . '</th>' . '<th class="nowrap" scope="col">' . __('Password') . '</th>' .
'<th class="nowrap" scope="col">' . __('Disposable') . '</th>' . '<th class="nowrap" scope="col">' . __('Disposable') . '</th>' .
'</tr></thead><body>' . '</tr></thead><body>' .

View File

@ -1,5 +1,15 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
@ -7,21 +17,10 @@ namespace Dotclear\Plugin\filesAlias;
use Dotclear\Module\MyPlugin; use Dotclear\Module\MyPlugin;
/** /**
* @brief filesAlias My helper. * This module definitions.
* @ingroup filesAlias
*
* @author Osku (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 This plugin table name */
* This plugin table name.
*
* @var string ALIAS_TABLE_NAME
*/
public const ALIAS_TABLE_NAME = 'filesalias'; public const ALIAS_TABLE_NAME = 'filesalias';
// Use defautl permissions
} }

View File

@ -1,18 +1,21 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
/** /**
* @brief filesAlias randomizer class. * Adapted from Enrico Pallazzo class
* @ingroup filesAlias
*
* Adapted from Enrico Pallazzo class.
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class PallazzoTools class PallazzoTools
{ {

View File

@ -1,20 +1,22 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
use Dotclear\App; use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/**
* @brief filesAlias prepend class.
* @ingroup filesAlias
*
* @author Osku (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
@ -29,11 +31,11 @@ class Prepend extends Process
} }
// register file alias frontend URL handler // register file alias frontend URL handler
App::url()->register( dcCore::app()->url->register(
'filesalias', 'filesalias',
'pub', 'pub',
'^pub/(.+)$', '^pub/(.+)$',
UrlHandler::alias(...) [UrlHandler::class, 'alias']
); );
return true; return true;

View File

@ -1,20 +1,23 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
/**
* @brief filesAlias uninstall class.
* @ingroup filesAlias
*
* @author Osku (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
@ -24,7 +27,7 @@ class Uninstall extends Process
public static function process(): bool public static function process(): bool
{ {
if (!self::status()) { if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false; return false;
} }

View File

@ -1,21 +1,27 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
use Dotclear\App; use dcCore;
use Dotclear\Core\Frontend\Url; use dcMedia;
use dcUrlHandlers;
/** /**
* @brief filesAlias frontend URL handler class. * File alias frontend URL handler.
* @ingroup filesAlias
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class UrlHandler extends Url class UrlHandler extends dcUrlHandlers
{ {
/** /**
* File alias page. * File alias page.
@ -24,9 +30,14 @@ class UrlHandler extends Url
*/ */
public static function alias(string $args): void public static function alias(string $args): void
{ {
// nullsafe
if (is_null(dcCore::app()->ctx)) {
return;
}
$alias = Utils::getAlias($args); $alias = Utils::getAlias($args);
App::frontend()->context()->__set('filealias', $alias); dcCore::app()->ctx->__set('filealias', $alias);
if ($alias->isEmpty()) { if ($alias->isEmpty()) {
self::p404(); self::p404();
@ -65,7 +76,11 @@ class UrlHandler extends Url
self::p404(); self::p404();
} }
$file = App::media()->getFile($media); if (!(dcCore::app()->media instanceof dcMedia)) {
dcCore::app()->media = new dcMedia();
}
$file = dcCore::app()->media->getFile($media);
if (empty($file->file)) { if (empty($file->file)) {
self::p404(); self::p404();

View File

@ -1,10 +1,21 @@
<?php <?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku 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\filesAlias; namespace Dotclear\Plugin\filesAlias;
use Dotclear\App; use dcCore;
use dcMedia;
use Dotclear\Database\MetaRecord; use Dotclear\Database\MetaRecord;
use Dotclear\Database\Statement\{ use Dotclear\Database\Statement\{
DeleteStatement, DeleteStatement,
@ -13,12 +24,7 @@ use Dotclear\Database\Statement\{
use Exception; use Exception;
/** /**
* @brief filesAlias records helper class. * fileAlias records utils
* @ingroup filesAlias
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Utils class Utils
{ {
@ -29,15 +35,18 @@ class Utils
*/ */
public static function getAliases(): MetaRecord public static function getAliases(): MetaRecord
{ {
// nullsafe
$blog_id = is_null(dcCore::app()->blog) ? '' : dcCore::app()->blog->id;
$sql = new SelectStatement(); $sql = new SelectStatement();
$rs = $sql->from(App::con()->prefix() . My::ALIAS_TABLE_NAME) $rs = $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME)
->columns([ ->columns([
'filesalias_url', 'filesalias_url',
'filesalias_destination', 'filesalias_destination',
'filesalias_password', 'filesalias_password',
'filesalias_disposable', 'filesalias_disposable',
]) ])
->where('blog_id = ' . $sql->quote(App::blog()->id())) ->where('blog_id = ' . $sql->quote($blog_id))
->order('filesalias_url ASC') ->order('filesalias_url ASC')
->select(); ->select();
@ -51,15 +60,18 @@ class Utils
*/ */
public static function getAlias(string $url): MetaRecord public static function getAlias(string $url): MetaRecord
{ {
// nullsafe
$blog_id = is_null(dcCore::app()->blog) ? '' : dcCore::app()->blog->id;
$sql = new SelectStatement(); $sql = new SelectStatement();
$rs = $sql->from(App::con()->prefix() . My::ALIAS_TABLE_NAME) $rs = $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME)
->columns([ ->columns([
'filesalias_url', 'filesalias_url',
'filesalias_destination', 'filesalias_destination',
'filesalias_password', 'filesalias_password',
'filesalias_disposable', 'filesalias_disposable',
]) ])
->where('blog_id = ' . $sql->quote(App::blog()->id())) ->where('blog_id = ' . $sql->quote($blog_id))
->and('filesalias_url = ' . $sql->quote($url)) ->and('filesalias_url = ' . $sql->quote($url))
->order('filesalias_url ASC') ->order('filesalias_url ASC')
->select(); ->select();
@ -85,7 +97,7 @@ class Utils
*/ */
public static function updateAliases(array $aliases): void public static function updateAliases(array $aliases): void
{ {
App::con()->begin(); dcCore::app()->con->begin();
try { try {
self::deleteAliases(); self::deleteAliases();
@ -96,9 +108,9 @@ class Utils
} }
} }
App::con()->commit(); dcCore::app()->con->commit();
} catch (Exception $e) { } catch (Exception $e) {
App::con()->rollback(); dcCore::app()->con->rollback();
throw $e; throw $e;
} }
@ -122,8 +134,11 @@ class Utils
throw new Exception(__('File destination is empty.')); throw new Exception(__('File destination is empty.'));
} }
$cur = App::con()->openCursor(App::con()->prefix() . My::ALIAS_TABLE_NAME); // nullsafe
$cur->setField('blog_id', App::blog()->id()); $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->setField('filesalias_url', (string) $url); $cur->setField('filesalias_url', (string) $url);
$cur->setField('filesalias_destination', (string) $destination); $cur->setField('filesalias_destination', (string) $destination);
$cur->setField('filesalias_password', $password); $cur->setField('filesalias_password', $password);
@ -136,9 +151,12 @@ class Utils
*/ */
public static function deleteAliases(): void public static function deleteAliases(): void
{ {
// nullsafe
$blog_id = is_null(dcCore::app()->blog) ? '' : dcCore::app()->blog->id;
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(App::con()->prefix() . My::ALIAS_TABLE_NAME) $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME)
->where('blog_id = ' . $sql->quote(App::blog()->id())) ->where('blog_id = ' . $sql->quote($blog_id))
->delete(); ->delete();
} }
@ -149,9 +167,12 @@ class Utils
*/ */
public static function deleteAlias(string $url): void public static function deleteAlias(string $url): void
{ {
// nullsafe
$blog_id = is_null(dcCore::app()->blog) ? '' : dcCore::app()->blog->id;
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(App::con()->prefix() . My::ALIAS_TABLE_NAME) $sql->from(dcCore::app()->prefix . My::ALIAS_TABLE_NAME)
->where('blog_id = ' . $sql->quote(App::blog()->id())) ->where('blog_id = ' . $sql->quote($blog_id))
->and('filesalias_url = ' . $sql->quote($url)) ->and('filesalias_url = ' . $sql->quote($url))
->delete(); ->delete();
} }
@ -165,18 +186,19 @@ class Utils
*/ */
public static function getMediaId(string $target): int public static function getMediaId(string $target): int
{ {
if (!App::blog()->isDefined()) { // nullsafe
if (is_null(dcCore::app()->blog)) {
return 0; return 0;
} }
$path = App::blog()->settings()->get('system')->get('public_path'); $path = dcCore::app()->blog->settings->get('system')->get('public_path');
$sql = new SelectStatement(); $sql = new SelectStatement();
$rs = $sql->from(App::con()->prefix() . App::postMedia()::MEDIA_TABLE_NAME) $rs = $sql->from(dcCore::app()->prefix . dcMedia::MEDIA_TABLE_NAME)
->column('media_id') ->column('media_id')
->where('media_path = ' . $sql->quote(is_string($path) ? $path : '')) ->where('media_path = ' . $sql->quote(is_string($path) ? $path : ''))
->and('media_file = ' . $sql->quote($target)) ->and('media_file = ' . $sql->quote($target))
->select(); ->select();
return !is_null($rs) && $rs->count() ? (int) $rs->f('media_id') : 0; return $rs->count() ? (int) $rs->f('media_id') : 0;
} }
} }