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
===========================================================
* Require Dotclear 2.27

View File

@ -1,22 +1,26 @@
# README
[![Release](https://img.shields.io/badge/release-1.2.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/filesAlias/releases)
![Date](https://img.shields.io/badge/date-2023.11.04-c44d58.svg)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download)
[![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)
[![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
* Dotclear 2.28
* PHP8.1+
* Dotclear content admin permissions for management
_filesAlias_ requires:
* content admin permissions for management
* Dotclear 2.27
* PHP 7.4+
## USAGE
@ -28,16 +32,14 @@ You can change public URL handler (default is _pub/_) by using plugin myUrlhandl
## LINKS
* [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))
* [Discuss & help](https://forum.dotclear.org/viewtopic.php?id=42317)
* 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)
## CONTRIBUTORS
* Osku (author)
* Pierre Van Glabeke
* Jean-Christian Denis (latest)
* Jean-Christian Denis
You are welcome to contribute to this code.

View File

@ -1,27 +1,29 @@
<?php
/**
* @file
* @brief The plugin filesAlias definition
* @ingroup filesAlias
* @brief filesAlias, a plugin for Dotclear 2
*
* @defgroup filesAlias Plugin filesAlias.
* @package Dotclear
* @subpackage Plugin
*
* Manage aliases of your blog's media.
* @author Osku and contributors
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright Jean-Christian Denis
* @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(
'Files alias',
"Manage aliases of your blog's media",
'Osku and contributors',
'1.2.1',
'1.1',
[
'requires' => [['core', '2.28']],
'permissions' => 'My',
'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',

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/">
<module id="filesAlias">
<name>Files alias</name>
<version>1.2.1</version>
<version>1.1</version>
<author>Osku and contributors</author>
<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>
<da:dcmin>2.28</da:dcmin>
<file>https://git.dotclear.watch/JcDenis/filesAlias/releases/download/v1.1/plugin-filesAlias.zip</file>
<da:dcmin>2.27</da:dcmin>
<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>
</module>

View File

@ -1,11 +1,13 @@
<?php
/**
* @file
* @brief The plugin filesAlias locales resources
* @ingroup filesAlias
* @brief filesAlias, a plugin for Dotclear 2
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @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
*/
dcCore::app()->resources['help']['filesAlias'] = __DIR__ . '/help/filesAlias.html';

View File

@ -1,11 +1,13 @@
<?php
/**
* @file
* @brief The plugin filesAlias locales resources
* @ingroup filesAlias
* @brief filesAlias, a plugin for Dotclear 2
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @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
*/
dcCore::app()->resources['help']['filesAlias'] = __DIR__ . '/help/filesAlias.html';

View File

@ -1,21 +1,23 @@
<?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);
namespace Dotclear\Plugin\filesAlias;
use Dotclear\App;
use dcCore;
use Dotclear\Core\Backend\Favorites;
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
{
public static function init(): bool
@ -32,15 +34,15 @@ class Backend extends Process
My::addBackendMenuItem();
// backend user dashboard icon
App::behavior()->addBehavior('adminDashboardFavoritesV2', function (Favorites $favs): void {
dcCore::app()->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' => App::auth()->makePermissions([
App::auth()::PERMISSION_USAGE,
App::auth()::PERMISSION_CONTENT_ADMIN,
'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]),
]);
});

View File

@ -1,20 +1,22 @@
<?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);
namespace Dotclear\Plugin\filesAlias;
use Dotclear\App;
use dcCore;
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
{
public static function init(): bool
@ -29,13 +31,14 @@ class Frontend extends Process
}
// add path to template
App::frontend()->template()->appendPath(
dcCore::app()->tpl->setPath(
dcCore::app()->tpl->getPath(),
My::path() . DIRECTORY_SEPARATOR . 'default-templates'
);
// register template value for file alias
App::frontend()->template()->addValue(
dcCore::app()->tpl->addValue(
'fileAliasURL',
FrontendTemplate::fileAliasURL(...)
[FrontendTemplate::class, 'fileAliasURL']
);
return true;

View File

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

View File

@ -1,22 +1,24 @@
<?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);
namespace Dotclear\Plugin\filesAlias;
use Dotclear\App;
use dcCore;
use Dotclear\Core\Process;
use Dotclear\Database\Structure;
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
{
public static function init(): bool
@ -31,7 +33,7 @@ class Install extends Process
}
try {
$s = new Structure(App::con(), App::con()->prefix());
$s = new Structure(dcCore::app()->con, dcCore::app()->prefix);
$s->__get(My::ALIAS_TABLE_NAME)
->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')
;
(new Structure(App::con(), App::con()->prefix()))->synchronize($s);
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
return true;
} catch (Exception $e) {
App::error()->add($e->getMessage());
dcCore::app()->error->add($e->getMessage());
}
return true;

View File

@ -1,10 +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
*/
declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias;
use Dotclear\App;
use dcCore;
use dcMedia;
use Dotclear\Core\Backend\{
Notices,
Page
@ -24,14 +35,6 @@ use Dotclear\Helper\Html\Form\{
};
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
{
public static function init(): bool
@ -41,12 +44,19 @@ class Manage extends Process
public static function process(): bool
{
if (!self::status()
|| !APP::blog()->isDefined()
) {
if (!self::status()) {
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 {
@ -54,7 +64,7 @@ class Manage extends Process
Notices::addSuccessNotice(__('Aliases successfully updated.'));
My::redirect();
} 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;
$password = empty($_POST['filesalias_password']) ? '' : $_POST['filesalias_password'];
if (preg_match('/^' . preg_quote(App::media()->root_url, '/') . '/', $target)) {
$target = (string) preg_replace('/^' . preg_quote(App::media()->root_url, '/') . '/', '', $target);
if (preg_match('/^' . preg_quote(dcCore::app()->media->root_url, '/') . '/', $target)) {
$target = preg_replace('/^' . preg_quote(dcCore::app()->media->root_url, '/') . '/', '', $target);
$found = Utils::getMediaId($target);
if (!empty($found)) {
@ -76,10 +86,10 @@ class Manage extends Process
Notices::addSuccessNotice(__('Alias for this media created.'));
My::redirect();
} catch (Exception $e) {
App::error()->add($e->getMessage());
dcCore::app()->error->add($e->getMessage());
}
} else {
App::error()->add(__('Target is not in media manager.'));
dcCore::app()->error->add(__('Target is not in media manager.'));
}
} else {
$found = Utils::getMediaId($target);
@ -90,10 +100,10 @@ class Manage extends Process
Notices::addSuccessNotice(__('Alias for this media modified.'));
My::redirect();
} catch (Exception $e) {
App::error()->add($e->getMessage());
dcCore::app()->error->add($e->getMessage());
}
} 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
{
if (!App::blog()->isDefined()) {
// nullsafe
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) {
return;
}
echo
Page::breadcrumb([
Html::escapeHTML(App::blog()->name()) => '',
Html::escapeHTML(dcCore::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.'), 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
(new Para())->items([
(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'),
// url
(new Para())->items([
(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'),
// password
(new Para())->items([
(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
(new Para())->items([
@ -168,7 +179,8 @@ class Manage extends Process
private static function displayAliasList(): void
{
if (!App::blog()->isDefined()) {
// nullsafe
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) {
return;
}
@ -176,7 +188,7 @@ class Manage extends Process
echo
Page::breadcrumb([
Html::escapeHTML(App::blog()->name()) => '',
Html::escapeHTML(dcCore::app()->blog->name) => '',
My::name() => '',
]) .
Notices::getNotices() .
@ -194,17 +206,17 @@ class Manage extends Process
$destination = is_string($aliases->f('filesalias_destination')) ? $aliases->f('filesalias_destination') : '';
$password = is_string($aliases->f('filesalias_password')) ? $aliases->f('filesalias_password') : '';
$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 . '">' .
'<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>' .
(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>' .
'<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 class="maximal">' .
(new Checkbox(['a[' . $i . '][filesalias_disposable]'], $disposable))->value(1)->render() .
@ -221,8 +233,8 @@ class Manage extends Process
'<table><thead>' .
'<caption>' . __('Aliases list') . '</caption>' .
'<tr>' .
'<th class="nowrap" scope="col">' . __('Destination') . ' - <ins>' . Html::escapeHTML(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">' . __('Destination') . ' - <ins>' . Html::escapeHTML(dcCore::app()->media->root_url) . '</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">' . __('Disposable') . '</th>' .
'</tr></thead><body>' .

View File

@ -1,5 +1,15 @@
<?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);
namespace Dotclear\Plugin\filesAlias;
@ -7,21 +17,10 @@ namespace Dotclear\Plugin\filesAlias;
use Dotclear\Module\MyPlugin;
/**
* @brief filesAlias My helper.
* @ingroup filesAlias
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
* This module definitions.
*/
class My extends MyPlugin
{
/**
* This plugin table name.
*
* @var string ALIAS_TABLE_NAME
*/
/** @var string This plugin table name */
public const ALIAS_TABLE_NAME = 'filesalias';
// Use defautl permissions
}

View File

@ -1,18 +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
*/
declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias;
/**
* @brief filesAlias randomizer 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
* Adapted from Enrico Pallazzo class
*/
class PallazzoTools
{

View File

@ -1,20 +1,22 @@
<?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);
namespace Dotclear\Plugin\filesAlias;
use Dotclear\App;
use dcCore;
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
{
public static function init(): bool
@ -29,11 +31,11 @@ class Prepend extends Process
}
// register file alias frontend URL handler
App::url()->register(
dcCore::app()->url->register(
'filesalias',
'pub',
'^pub/(.+)$',
UrlHandler::alias(...)
[UrlHandler::class, 'alias']
);
return true;

View File

@ -1,20 +1,23 @@
<?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);
namespace Dotclear\Plugin\filesAlias;
use dcCore;
use Dotclear\Core\Process;
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
{
public static function init(): bool
@ -24,7 +27,7 @@ class Uninstall extends Process
public static function process(): bool
{
if (!self::status()) {
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false;
}

View File

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

View File

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