fix type hint and nullsafe

master
Jean-Christian Paul Denis 2023-05-13 11:25:27 +02:00
parent c157393de2
commit 0924c9eedc
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
5 changed files with 40 additions and 29 deletions

View File

@ -17,6 +17,7 @@ namespace Dotclear\Plugin\filesAlias;
use dcAdmin; use dcAdmin;
use dcCore; use dcCore;
use dcFavorites; use dcFavorites;
use dcMenu;
use dcNsProcess; use dcNsProcess;
use dcPage; use dcPage;
@ -41,6 +42,7 @@ class Backend extends dcNsProcess
} }
// backend sidebar menu icon // backend sidebar menu icon
if ((dcCore::app()->menu[dcAdmin::MENU_BLOG] instanceof dcMenu)) {
dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem( dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem(
My::name(), My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()), dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
@ -48,6 +50,7 @@ class Backend extends dcNsProcess
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), 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) 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 (dcFavorites $favs): void { dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {

View File

@ -23,7 +23,10 @@ class Install extends dcNsProcess
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version')); 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; return static::$init;
} }

View File

@ -179,7 +179,7 @@ class Manage extends dcNsProcess
(new Para())->items([ (new Para())->items([
(new Submit(['save']))->value(__('Save')), (new Submit(['save']))->value(__('Save')),
(new Hidden(['part'], 'new')), (new Hidden(['part'], 'new')),
(new Text('', dcCore::app()->formNonce())), dcCore::app()->formNonce(false),
]), ]),
])->render(); ])->render();
} }
@ -209,20 +209,24 @@ class Manage extends dcNsProcess
$lines = ''; $lines = '';
$i = 0; $i = 0;
while ($aliases->fetch()) { while ($aliases->fetch()) {
$url = dcCore::app()->blog->url . dcCore::app()->url->getBase('filesalias') . '/' . Html::escapeHTML($aliases->f('filesalias_url')); $url = is_string($aliases->f('filesalias_url')) ? $aliases->f('filesalias_url') : '';
$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 = 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)->maxlenght(255)->value(Html::escapeHTML($aliases->f('filesalias_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)->maxlenght(255)->value(Html::escapeHTML($aliases->f('filesalias_url')))->render() . (new Input(['a[' . $i . '][filesalias_url]']))->size(50)->maxlenght(255)->value(Html::escapeHTML($url))->render() .
'<a href="' . $url . '">' . __('link') . '</a></td>' . '<a href="' . $full . '">' . __('link') . '</a></td>' .
'<td>' . '<td>' .
(new Input(['a[' . $i . '][filesalias_password]']))->size(50)->maxlenght(255)->value(Html::escapeHTML($aliases->f('filesalias_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]'], (bool) $aliases->f('filesalias_disposable')))->value(1)->render() . (new Checkbox(['a[' . $i . '][filesalias_disposable]'], $disposable))->value(1)->render() .
'</td>' . '</td>' .
'</tr>'; '</tr>';
$i++; $i++;
@ -247,7 +251,7 @@ class Manage extends dcNsProcess
(new Para())->items([ (new Para())->items([
(new Submit(['save']))->value(__('Update')), (new Submit(['save']))->value(__('Update')),
(new Hidden(['part'], 'list')), (new Hidden(['part'], 'list')),
(new Text('', dcCore::app()->formNonce())), 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

@ -35,29 +35,29 @@ class UrlHandler extends dcUrlHandlers
return; return;
} }
$delete = false; $alias = Utils::getAlias($args);
dcCore::app()->ctx->__set('filealias', Utils::getAlias($args)); dcCore::app()->ctx->__set('filealias', $alias);
if (dcCore::app()->ctx->__get('filealias')->isEmpty()) { if ($alias->isEmpty()) {
self::p404(); self::p404();
} }
if (dcCore::app()->ctx->__get('filealias')->f('filesalias_disposable')) { $disposable = !empty($alias->f('filesalias_disposable'));
$delete = true; $password = is_string($alias->f('filesalias_password')) ? $alias->f('filesalias_password') : '';
} $destination = is_string($alias->f('filesalias_destination')) ? $alias->f('filesalias_destination') : '';
if (dcCore::app()->ctx->__get('filealias')->f('filesalias_password')) { if ($password) {
# Check for match # Check for match
if (!empty($_POST['filepassword']) && $_POST['filepassword'] == dcCore::app()->ctx->__get('filealias')->f('filesalias_password')) { if (!empty($_POST['filepassword']) && $_POST['filepassword'] == $password) {
self::servefile(dcCore::app()->ctx->__get('filealias')->f('filesalias_destination'), $args, $delete); self::servefile($destination, $args, $disposable);
} else { } else {
self::serveDocument('file-password-form.html', 'text/html', false); self::serveDocument('file-password-form.html', 'text/html', false);
return; return;
} }
} else { } else {
self::servefile(dcCore::app()->ctx->__get('filealias')->f('filesalias_destination'), $args, $delete); self::servefile($destination, $args, $disposable);
} }
} }

View File

@ -93,7 +93,7 @@ class Utils
* filesalias_password => string * filesalias_password => string
* ] * ]
* *
* @param array $aliases The new aliases * @param array{filesalias_url:string,filesalias_destination:string,filesalias_disposable:bool,filesalias_password:string} $aliases The new aliases
*/ */
public static function updateAliases(array $aliases): void public static function updateAliases(array $aliases): void
{ {
@ -103,7 +103,7 @@ class Utils
self::deleteAliases(); self::deleteAliases();
foreach ($aliases as $k => $v) { foreach ($aliases as $k => $v) {
if (!empty($v['filesalias_url']) && !empty($v['filesalias_destination'])) { if (!empty($v['filesalias_url']) && !empty($v['filesalias_destination'])) {
$v['filesalias_disposable'] = isset($v['filesalias_disposable']) ? true : false; $v['filesalias_disposable'] = !empty($v['filesalias_disposable']);
self::createAlias($v['filesalias_url'], $v['filesalias_destination'], $v['filesalias_disposable'], $v['filesalias_password']); self::createAlias($v['filesalias_url'], $v['filesalias_destination'], $v['filesalias_disposable'], $v['filesalias_password']);
} }
} }
@ -190,11 +190,12 @@ class Utils
if (is_null(dcCore::app()->blog)) { if (is_null(dcCore::app()->blog)) {
return 0; return 0;
} }
$path = dcCore::app()->blog->settings->get('system')->get('public_path');
$sql = new SelectStatement(); $sql = new SelectStatement();
$rs = $sql->from(dcCore::app()->prefix . dcMedia::MEDIA_TABLE_NAME) $rs = $sql->from(dcCore::app()->prefix . dcMedia::MEDIA_TABLE_NAME)
->column('media_id') ->column('media_id')
->where('media_path = ' . $sql->quote((string) dcCore::app()->blog->settings->get('system')->get('public_path'))) ->where('media_path = ' . $sql->quote(is_string($path) ? $path : ''))
->and('media_file = ' . $sql->quote($target)) ->and('media_file = ' . $sql->quote($target))
->select(); ->select();