diff --git a/src/Backend.php b/src/Backend.php
index 6fed614..2c478ee 100644
--- a/src/Backend.php
+++ b/src/Backend.php
@@ -17,6 +17,7 @@ namespace Dotclear\Plugin\filesAlias;
use dcAdmin;
use dcCore;
use dcFavorites;
+use dcMenu;
use dcNsProcess;
use dcPage;
@@ -41,13 +42,15 @@ class Backend extends dcNsProcess
}
// backend sidebar menu icon
- 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)
- );
+ 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
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
diff --git a/src/Install.php b/src/Install.php
index edca682..89a5a59 100644
--- a/src/Install.php
+++ b/src/Install.php
@@ -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;
}
diff --git a/src/Manage.php b/src/Manage.php
index 08299a9..28e24d1 100644
--- a/src/Manage.php
+++ b/src/Manage.php
@@ -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 .= '
' .
'' .
- (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() .
' | ' .
'' .
- (new Input(['a[' . $i . '][filesalias_url]']))->size(50)->maxlenght(255)->value(Html::escapeHTML($aliases->f('filesalias_url')))->render() .
- '' . __('link') . ' | ' .
+ (new Input(['a[' . $i . '][filesalias_url]']))->size(50)->maxlenght(255)->value(Html::escapeHTML($url))->render() .
+ '' . __('link') . '' .
'' .
- (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() .
' | ' .
'' .
- (new Checkbox(['a[' . $i . '][filesalias_disposable]'], (bool) $aliases->f('filesalias_disposable')))->value(1)->render() .
+ (new Checkbox(['a[' . $i . '][filesalias_disposable]'], $disposable))->value(1)->render() .
' | ' .
'
';
$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();
diff --git a/src/UrlHandler.php b/src/UrlHandler.php
index 2e35ed9..b951d2f 100644
--- a/src/UrlHandler.php
+++ b/src/UrlHandler.php
@@ -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);
}
}
diff --git a/src/Utils.php b/src/Utils.php
index ecb7ae4..2607a61 100644
--- a/src/Utils.php
+++ b/src/Utils.php
@@ -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();