diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php index 6eca5d0..f82b906 100644 --- a/app/Controllers/AdminController.php +++ b/app/Controllers/AdminController.php @@ -21,6 +21,13 @@ class AdminController extends Controller */ public function system(Request $request, Response $response): Response { + $settings = []; + foreach ($this->database->query('SELECT `key`, `value` FROM `settings`') as $setting) { + $settings[$setting->key] = $setting->value; + } + + $settings['default_user_quota'] = humanFileSize($this->getSetting('default_user_quota', stringToBytes('1G')), 0, true); + return view()->render($response, 'dashboard/system.twig', [ 'usersCount' => $usersCount = $this->database->query('SELECT COUNT(*) AS `count` FROM `users`')->fetch()->count, 'mediasCount' => $mediasCount = $this->database->query('SELECT COUNT(*) AS `count` FROM `uploads`')->fetch()->count, @@ -32,14 +39,7 @@ class AdminController extends Controller 'forced_lang' => $request->getAttribute('forced_lang'), 'php_version' => phpversion(), 'max_memory' => ini_get('memory_limit'), - 'register_enabled' => $this->getSetting('register_enabled', 'off'), - 'hide_by_default' => $this->getSetting('hide_by_default', 'off'), - 'copy_url_behavior' => $this->getSetting('copy_url_behavior', 'off'), - 'quota_enabled' => $this->getSetting('quota_enabled', 'off'), - 'default_user_quota' => humanFileSize($this->getSetting('default_user_quota', stringToBytes('1G')), 0, true), - 'recaptcha_enabled' => $this->getSetting('recaptcha_enabled', 'off'), - 'recaptcha_site_key' => $this->getSetting('recaptcha_site_key'), - 'recaptcha_secret_key' => $this->getSetting('recaptcha_secret_key'), + 'settings' => $settings, ]); } diff --git a/app/Controllers/MediaController.php b/app/Controllers/MediaController.php index 84f94e6..fc9bdfa 100644 --- a/app/Controllers/MediaController.php +++ b/app/Controllers/MediaController.php @@ -33,7 +33,7 @@ class MediaController extends Controller */ public function show(Request $request, Response $response, string $userCode, string $mediaCode, string $token = null): Response { - $media = $this->getMedia($userCode, $mediaCode); + $media = $this->getMedia($userCode, $mediaCode, true); if (!$media || (!$media->published && $this->session->get('user_id') !== $media->user_id && !$this->session->get('admin', false))) { throw new HttpNotFoundException($request); @@ -112,7 +112,7 @@ class MediaController extends Controller */ public function getRaw(Request $request, Response $response, string $userCode, string $mediaCode, ?string $ext = null): Response { - $media = $this->getMedia($userCode, $mediaCode); + $media = $this->getMedia($userCode, $mediaCode, false); if (!$media || !$media->published && $this->session->get('user_id') !== $media->user_id && !$this->session->get('admin', false)) { throw new HttpNotFoundException($request); @@ -144,7 +144,7 @@ class MediaController extends Controller */ public function download(Request $request, Response $response, string $userCode, string $mediaCode): Response { - $media = $this->getMedia($userCode, $mediaCode); + $media = $this->getMedia($userCode, $mediaCode, false); if (!$media || !$media->published && $this->session->get('user_id') !== $media->user_id && !$this->session->get('admin', false)) { throw new HttpNotFoundException($request); @@ -230,7 +230,7 @@ class MediaController extends Controller */ public function deleteByToken(Request $request, Response $response, string $userCode, string $mediaCode, string $token): Response { - $media = $this->getMedia($userCode, $mediaCode); + $media = $this->getMedia($userCode, $mediaCode, false); if (!$media) { throw new HttpNotFoundException($request); @@ -286,16 +286,28 @@ class MediaController extends Controller * @param $userCode * @param $mediaCode * + * @param bool $withTags * @return mixed */ - protected function getMedia($userCode, $mediaCode) + protected function getMedia($userCode, $mediaCode, $withTags = false) { $mediaCode = pathinfo($mediaCode)['filename']; - return $this->database->query('SELECT `uploads`.*, `users`.*, `users`.`id` AS `userId`, `uploads`.`id` AS `mediaId` FROM `uploads` INNER JOIN `users` ON `uploads`.`user_id` = `users`.`id` WHERE `user_code` = ? AND `uploads`.`code` = ? LIMIT 1', [ + $media = $this->database->query('SELECT `uploads`.*, `users`.*, `users`.`id` AS `userId`, `uploads`.`id` AS `mediaId` FROM `uploads` INNER JOIN `users` ON `uploads`.`user_id` = `users`.`id` WHERE `user_code` = ? AND `uploads`.`code` = ? LIMIT 1', [ $userCode, $mediaCode, ])->fetch(); + + if (!$withTags || !$media) { + return $media; + } + + $media->tags = []; + foreach ($this->database->query('SELECT `tags`.`id`, `tags`.`name` FROM `uploads_tags` INNER JOIN `tags` ON `uploads_tags`.`tag_id` = `tags`.`id` WHERE `uploads_tags`.`upload_id` = ?', $media->mediaId) as $tag) { + $media->tags[$tag->id] = $tag->name; + } + + return $media; } /** diff --git a/app/Controllers/SettingController.php b/app/Controllers/SettingController.php index 16fded8..3e432b2 100644 --- a/app/Controllers/SettingController.php +++ b/app/Controllers/SettingController.php @@ -29,6 +29,7 @@ class SettingController extends Controller // registrations $this->updateSetting('register_enabled', param($request, 'register_enabled', 'off')); + $this->updateSetting('auto_tagging', param($request, 'auto_tagging', 'off')); // quota $this->updateSetting('quota_enabled', param($request, 'quota_enabled', 'off')); diff --git a/app/Controllers/UploadController.php b/app/Controllers/UploadController.php index 1c75fef..b0cf325 100644 --- a/app/Controllers/UploadController.php +++ b/app/Controllers/UploadController.php @@ -200,7 +200,9 @@ class UploadController extends Controller ]); $mediaId = $this->database->getPdo()->lastInsertId(); - $this->autoTag($mediaId, $storagePath); + if ($this->getSetting('auto_tagging') === 'on') { + $this->autoTag($mediaId, $storagePath); + } $this->json['message'] = 'OK'; $this->json['url'] = urlFor("/{$user->user_code}/{$code}.{$fileInfo['extension']}"); @@ -225,7 +227,7 @@ class UploadController extends Controller $query = make(TagQuery::class); $query->addTag($type, $mediaId); - if ($type === 'application') { + if ($type === 'application' || $subtype === 'gif') { $query->addTag($subtype, $mediaId); } } diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 5d7d5f6..661925e 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -103,7 +103,7 @@ class UserController extends Controller if (param($request, 'send_notification') !== null) { $resetToken = null; - if (!empty(param($request, 'password'))) { + if (empty(param($request, 'password'))) { $resetToken = bin2hex(random_bytes(16)); $this->database->query('UPDATE `users` SET `reset_token`=? WHERE `id` = ?', [ @@ -284,7 +284,7 @@ class UserController extends Controller */ private function sendCreateNotification($request, $resetToken = null) { - if (empty(param($request, 'password'))) { + if ($resetToken === null && !empty(param($request, 'password'))) { $message = lang('mail.new_account_text_with_pw', [ param($request, 'username'), $this->config['app_name'], diff --git a/app/Exceptions/Handlers/AppErrorHandler.php b/app/Exceptions/Handlers/AppErrorHandler.php index 0da16e0..53b179f 100644 --- a/app/Exceptions/Handlers/AppErrorHandler.php +++ b/app/Exceptions/Handlers/AppErrorHandler.php @@ -2,7 +2,10 @@ namespace App\Exception\Handlers; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; use Slim\Handlers\ErrorHandler; +use Throwable; class AppErrorHandler extends ErrorHandler { @@ -10,4 +13,15 @@ class AppErrorHandler extends ErrorHandler { resolve('logger')->error($error); } + + public function __invoke(ServerRequestInterface $request, Throwable $exception, bool $displayErrorDetails, bool $logErrors, bool $logErrorDetails): ResponseInterface + { + $response = parent::__invoke($request, $exception, $displayErrorDetails, $logErrors, $logErrorDetails); + + if ($response->getStatusCode() !== 404) { + $this->writeToErrorLog(); + } + + return $response; + } } diff --git a/app/Web/Mail.php b/app/Web/Mail.php index a0c4d00..93c6cbd 100644 --- a/app/Web/Mail.php +++ b/app/Web/Mail.php @@ -117,7 +117,7 @@ class Mail $this->addRequiredHeader('X-Mailer: PHP/'.phpversion()); $this->addRequiredHeader('MIME-Version: 1.0'); - $this->addRequiredHeader('Content-Type: text/html; charset=iso-8859-1'); + $this->addRequiredHeader('Content-Type: text/plain; charset=iso-8859-1'); $this->headers .= $this->additionalHeaders; diff --git a/bootstrap/app.php b/bootstrap/app.php index 29c2175..c99e69b 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -112,7 +112,7 @@ $errorHandler = new AppErrorHandler($app->getCallableResolver(), $app->getRespon $errorHandler->registerErrorRenderer('text/html', HtmlErrorRenderer::class); // Add Error Middleware -$errorMiddleware = $app->addErrorMiddleware($config['debug'], true, true); +$errorMiddleware = $app->addErrorMiddleware($config['debug'], false, true); $errorMiddleware->setDefaultErrorHandler($errorHandler); // Load the application routes diff --git a/resources/lang/en.lang.php b/resources/lang/en.lang.php index 0a1d388..80ebf13 100644 --- a/resources/lang/en.lang.php +++ b/resources/lang/en.lang.php @@ -172,4 +172,5 @@ Click on the following link to go to the login page: 'ldap_cant_connect' => 'Can\'t connect to the LDAP auth server.', 'upload_max_file_size' => 'The max file size is currently %s.', 'no_tags' => 'No tags added', + 'auto_tagging' => 'Auto upload tagging', ]; diff --git a/resources/templates/dashboard/grid.twig b/resources/templates/dashboard/grid.twig index 2ac058a..dbc40d7 100644 --- a/resources/templates/dashboard/grid.twig +++ b/resources/templates/dashboard/grid.twig @@ -48,7 +48,7 @@ {% if isDisplayableImage(media.mimetype) %} -
+ {% else %}{{ media.text }}