fix type hint and nullsafe
This commit is contained in:
parent
c157393de2
commit
0924c9eedc
@ -17,6 +17,7 @@ namespace Dotclear\Plugin\filesAlias;
|
||||
use dcAdmin;
|
||||
use dcCore;
|
||||
use dcFavorites;
|
||||
use dcMenu;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
|
||||
@ -41,6 +42,7 @@ class Backend extends dcNsProcess
|
||||
}
|
||||
|
||||
// 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()),
|
||||
@ -48,6 +50,7 @@ class Backend extends dcNsProcess
|
||||
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
|
||||
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
|
||||
|
@ -23,7 +23,10 @@ class Install extends dcNsProcess
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ class Manage extends dcNsProcess
|
||||
(new Para())->items([
|
||||
(new Submit(['save']))->value(__('Save')),
|
||||
(new Hidden(['part'], 'new')),
|
||||
(new Text('', dcCore::app()->formNonce())),
|
||||
dcCore::app()->formNonce(false),
|
||||
]),
|
||||
])->render();
|
||||
}
|
||||
@ -209,20 +209,24 @@ class Manage extends dcNsProcess
|
||||
$lines = '';
|
||||
$i = 0;
|
||||
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 . '">' .
|
||||
'<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>' .
|
||||
(new Input(['a[' . $i . '][filesalias_url]']))->size(50)->maxlenght(255)->value(Html::escapeHTML($aliases->f('filesalias_url')))->render() .
|
||||
'<a href="' . $url . '">' . __('link') . '</a></td>' .
|
||||
(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)->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 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>' .
|
||||
'</tr>';
|
||||
$i++;
|
||||
@ -247,7 +251,7 @@ class Manage extends dcNsProcess
|
||||
(new Para())->items([
|
||||
(new Submit(['save']))->value(__('Update')),
|
||||
(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'),
|
||||
])->render();
|
||||
|
@ -35,29 +35,29 @@ class UrlHandler extends dcUrlHandlers
|
||||
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();
|
||||
}
|
||||
|
||||
if (dcCore::app()->ctx->__get('filealias')->f('filesalias_disposable')) {
|
||||
$delete = true;
|
||||
}
|
||||
$disposable = !empty($alias->f('filesalias_disposable'));
|
||||
$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
|
||||
if (!empty($_POST['filepassword']) && $_POST['filepassword'] == dcCore::app()->ctx->__get('filealias')->f('filesalias_password')) {
|
||||
self::servefile(dcCore::app()->ctx->__get('filealias')->f('filesalias_destination'), $args, $delete);
|
||||
if (!empty($_POST['filepassword']) && $_POST['filepassword'] == $password) {
|
||||
self::servefile($destination, $args, $disposable);
|
||||
} else {
|
||||
self::serveDocument('file-password-form.html', 'text/html', false);
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
self::servefile(dcCore::app()->ctx->__get('filealias')->f('filesalias_destination'), $args, $delete);
|
||||
self::servefile($destination, $args, $disposable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ class Utils
|
||||
* 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
|
||||
{
|
||||
@ -103,7 +103,7 @@ class Utils
|
||||
self::deleteAliases();
|
||||
foreach ($aliases as $k => $v) {
|
||||
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']);
|
||||
}
|
||||
}
|
||||
@ -190,11 +190,12 @@ class Utils
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return 0;
|
||||
}
|
||||
$path = dcCore::app()->blog->settings->get('system')->get('public_path');
|
||||
|
||||
$sql = new SelectStatement();
|
||||
$rs = $sql->from(dcCore::app()->prefix . dcMedia::MEDIA_TABLE_NAME)
|
||||
->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))
|
||||
->select();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user