{if $iterator->isLast() && count($images) > count($previewImages)}
From 9f013bea3bd9b43d3eb0ceb7d312cc4f48ffbadc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20Provazn=C3=ADk?=
<41260648+paproc@users.noreply.github.com>
Date: Sun, 12 Jan 2025 01:20:49 +0000
Subject: [PATCH 3/4] all pages
---
app/Modules/Core/BasePresenter.php | 28 +++++++++++++++++
.../Vyfuk/DefaultModule/DefaultPresenter.php | 28 -----------------
app/RouterFactory.php | 31 ++++++++++++++-----
www/dsef/.htaccess | 2 +-
www/fof/.htaccess | 2 +-
www/fol/.htaccess | 2 +-
www/fykos/.htaccess | 2 +-
7 files changed, 55 insertions(+), 40 deletions(-)
diff --git a/app/Modules/Core/BasePresenter.php b/app/Modules/Core/BasePresenter.php
index 7b97a2f69..36a1c63f5 100644
--- a/app/Modules/Core/BasePresenter.php
+++ b/app/Modules/Core/BasePresenter.php
@@ -13,8 +13,11 @@
use Fykosak\Utils\Localization\UnsupportedLanguageException;
use Fykosak\Utils\UI\Navigation\NavItem;
use Fykosak\Utils\UI\PageTitle;
+use Nette\Application\Responses\FileResponse;
use Nette\Application\UI\Presenter;
use Nette\Application\UI\Template;
+use Nette\DI\Container;
+use Nette\Utils\Image;
abstract class BasePresenter extends Presenter
{
@@ -142,4 +145,29 @@ protected function createComponentPdfGallery(): PdfGalleryControl
{
return new PdfGalleryControl($this->getContext());
}
+
+ private readonly string $wwwDir;
+
+ public function injectWwwDir(Container $container): void
+ {
+ $this->wwwDir = $container->getParameters()['wwwDir'];
+ }
+
+ public function actionPreview(string $path): void
+ {
+ $basepath = realpath($this->wwwDir . '/media');
+ $path = realpath($basepath . '/' . $path);
+ if ($path === false || strpos($path, $basepath . '/') !== 0) {
+ $this->error();
+ }
+ $path = substr($path, strlen($basepath));
+ if (!is_file($basepath . '/preview/' . $path)) {
+ $img = Image::fromFile($basepath . '/' . $path);
+ if (!is_dir(dirname($basepath . '/preview/' . $path))) {
+ mkdir(dirname($basepath . '/preview/' . $path), recursive: true);
+ }
+ $img->resize(1024, 1024)->save($basepath . '/preview/' . $path);
+ }
+ $this->sendResponse(new FileResponse($basepath . '/preview/' . $path));
+ }
}
diff --git a/app/Modules/Vyfuk/DefaultModule/DefaultPresenter.php b/app/Modules/Vyfuk/DefaultModule/DefaultPresenter.php
index 10eceea42..1f46aff73 100644
--- a/app/Modules/Vyfuk/DefaultModule/DefaultPresenter.php
+++ b/app/Modules/Vyfuk/DefaultModule/DefaultPresenter.php
@@ -7,9 +7,6 @@
use App\Models\Downloader\ProblemService;
use App\Models\Downloader\EventService;
use Fykosak\FKSDBDownloaderCore\Requests\SeriesResultsRequest;
-use Nette\Application\Responses\FileResponse;
-use Nette\DI\Container;
-use Nette\Utils\Image;
class DefaultPresenter extends BasePresenter
{
@@ -32,13 +29,6 @@ public function injectEventServicesAndCache(EventService $eventService): void
$this->eventService = $eventService;
}
- private readonly string $wwwDir;
-
- public function injectWwwDir(Container $container): void
- {
- $this->wwwDir = $container->getParameters()['wwwDir'];
- }
-
public function renderDefault(): void
{
$this->template->newsList = $this->loadNews();
@@ -89,22 +79,4 @@ public function loadNews(): array
return $newsList;
}
-
- public function renderPreview(string $path): void
- {
- $basepath = realpath($this->wwwDir . '/media');
- $path = realpath($basepath . '/' . $path);
- if ($path === false || strpos($path, $basepath . '/') !== 0) {
- $this->error();
- }
- $path = substr($path, strlen($basepath));
- if (!is_file($basepath . '/preview/' . $path)) {
- $img = Image::fromFile($basepath . '/' . $path);
- if (!is_dir(dirname($basepath . '/preview/' . $path))) {
- mkdir(dirname($basepath . '/preview/' . $path), recursive: true);
- }
- $img->resize(1024, 1024)->save($basepath . '/preview/' . $path);
- }
- $this->sendResponse(new FileResponse($basepath . '/preview/' . $path));
- }
}
diff --git a/app/RouterFactory.php b/app/RouterFactory.php
index 917da16df..c947b879c 100755
--- a/app/RouterFactory.php
+++ b/app/RouterFactory.php
@@ -162,6 +162,10 @@ public static function createFolRouter(?array $domainList, array $routerMapping)
]);
$router->withModule('Default')
+ ->addRoute('//
/media/preview/', [
+ 'presenter' => 'Default',
+ 'action' => 'preview',
+ ])
->addRoute('///[/]', [
'presenter' => 'Default',
'action' => 'default',
@@ -183,6 +187,10 @@ public static function createFofRouter(?array $domainList, array $routerMapping)
]);
$router->withModule('Default')
+ ->addRoute('///media/preview/', [
+ 'presenter' => 'Default',
+ 'action' => 'preview',
+ ])
->addRoute('///(international|erasmus)', [
'presenter' => 'Erasmus',
'lang' => 'en',
@@ -202,6 +210,10 @@ public static function createDsefRouter(?array $domainList, array $routerMapping
$router = new RouteList();
$router->withModule('Default')
+ ->addRoute('///media/preview/', [
+ 'presenter' => 'Default',
+ 'action' => 'preview',
+ ])
->addRoute('///[/]', [
'presenter' => 'Default',
'action' => 'default',
@@ -228,6 +240,10 @@ public static function createFykosRouter(?array $domainList, array $routerMappin
'presenter' => 'Results',
'action' => 'default',
null => self::useTranslateFilter($domainList, $routerMapping['default'])
+ ])
+ ->addRoute('///media/preview/', [
+ 'presenter' => 'Default',
+ 'action' => 'preview',
]);
$router->withModule('Default')
@@ -252,10 +268,10 @@ public static function createFykosRouter(?array $domainList, array $routerMappin
]);
$router->withModule('Events')
- ->addRoute('///akce/tsaf/-', [
- 'presenter' => 'Tsaf',
- 'action' => 'detail'
- ]);
+ ->addRoute('///akce/tsaf/-', [
+ 'presenter' => 'Tsaf',
+ 'action' => 'detail'
+ ]);
$router->addRoute('////[[/]]', [
'presenter' => 'Default',
@@ -286,13 +302,12 @@ public static function createVyfukRouter(?array $domainList, array $routerMappin
->addRoute('///media/preview/', [
'presenter' => 'Default',
'action' => 'preview',
- null => self::useTranslateFilter($domainList, $routerMapping['default']),
- ])->addRoute('///[/]', [
+ ])
+ ->addRoute('///[/]', [
'presenter' => 'Default',
'action' => 'default',
null => self::useTranslateFilter($domainList, $routerMapping['default']),
- ])
- ;
+ ]);
return $router;
}
diff --git a/www/dsef/.htaccess b/www/dsef/.htaccess
index 68f2bae54..fcdc37ee4 100644
--- a/www/dsef/.htaccess
+++ b/www/dsef/.htaccess
@@ -21,7 +21,7 @@ Require all granted
# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule !\.(pdf|js|mjs|ico|gif|jpg|jpeg|png|webp|svg|css|rar|zip|7z|tar\.gz|map|eot|ttf|otf|woff|woff2)$ index.php [L]
+ RewriteRule !\.(pdf|js|mjs|ico|svg|css|rar|zip|7z|tar\.gz|map|eot|ttf|otf|woff|woff2)$ index.php [L]
# enable gzip compression
diff --git a/www/fof/.htaccess b/www/fof/.htaccess
index 68f2bae54..fcdc37ee4 100644
--- a/www/fof/.htaccess
+++ b/www/fof/.htaccess
@@ -21,7 +21,7 @@ Require all granted
# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule !\.(pdf|js|mjs|ico|gif|jpg|jpeg|png|webp|svg|css|rar|zip|7z|tar\.gz|map|eot|ttf|otf|woff|woff2)$ index.php [L]
+ RewriteRule !\.(pdf|js|mjs|ico|svg|css|rar|zip|7z|tar\.gz|map|eot|ttf|otf|woff|woff2)$ index.php [L]
# enable gzip compression
diff --git a/www/fol/.htaccess b/www/fol/.htaccess
index 68f2bae54..fcdc37ee4 100644
--- a/www/fol/.htaccess
+++ b/www/fol/.htaccess
@@ -21,7 +21,7 @@ Require all granted
# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule !\.(pdf|js|mjs|ico|gif|jpg|jpeg|png|webp|svg|css|rar|zip|7z|tar\.gz|map|eot|ttf|otf|woff|woff2)$ index.php [L]
+ RewriteRule !\.(pdf|js|mjs|ico|svg|css|rar|zip|7z|tar\.gz|map|eot|ttf|otf|woff|woff2)$ index.php [L]
# enable gzip compression
diff --git a/www/fykos/.htaccess b/www/fykos/.htaccess
index 43fb51256..cfa7c46ed 100644
--- a/www/fykos/.htaccess
+++ b/www/fykos/.htaccess
@@ -36,7 +36,7 @@ Require all granted
RewriteRule ^o-nas/sin-slavy /o-nas/byvali-organizatori [R=301,L]
RewriteRule ^en / [R=301,L]
- RewriteRule !\.(pdf|js|mjs|ico|gif|jpg|jpeg|png|webp|svg|css|rar|zip|7z|tar\.gz|map|eot|ttf|otf|woff|woff2|mp4)$ index.php [L]
+ RewriteRule !\.(pdf|js|mjs|ico|svg|css|rar|zip|7z|tar\.gz|map|eot|ttf|otf|woff|woff2|mp4)$ index.php [L]
From d54b143a5ff445463929a00389480bb876c39426 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20Provazn=C3=ADk?=
<41260648+paproc@users.noreply.github.com>
Date: Tue, 14 Jan 2025 19:31:26 +0000
Subject: [PATCH 4/4] more specific name
---
app/Components/ImageGallery/ImageGalleryControl.php | 2 +-
app/Modules/Core/BasePresenter.php | 13 +++----------
app/RouterFactory.php | 10 +++++-----
3 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/app/Components/ImageGallery/ImageGalleryControl.php b/app/Components/ImageGallery/ImageGalleryControl.php
index 8cdc2c922..e43f4b8c3 100644
--- a/app/Components/ImageGallery/ImageGalleryControl.php
+++ b/app/Components/ImageGallery/ImageGalleryControl.php
@@ -43,7 +43,7 @@ public static function getImages(string $path, string $wwwDir): array
foreach ($iterator as $file) {
$imageInfo = getimagesize($file->getPathname());
$wwwPath = substr($file->getPathname(), strlen($wwwDir));
- if (strpos($wwwPath, '/media/') === 0) {
+ if (str_starts_with($wwwPath, '/media/')) {
$images[] = [
'src' => $wwwPath,
'width' => $imageInfo[0],
diff --git a/app/Modules/Core/BasePresenter.php b/app/Modules/Core/BasePresenter.php
index 36a1c63f5..a09f02d37 100644
--- a/app/Modules/Core/BasePresenter.php
+++ b/app/Modules/Core/BasePresenter.php
@@ -146,18 +146,11 @@ protected function createComponentPdfGallery(): PdfGalleryControl
return new PdfGalleryControl($this->getContext());
}
- private readonly string $wwwDir;
-
- public function injectWwwDir(Container $container): void
- {
- $this->wwwDir = $container->getParameters()['wwwDir'];
- }
-
- public function actionPreview(string $path): void
+ final public function actionImageGaleryComponentImagePreview(string $path): void
{
- $basepath = realpath($this->wwwDir . '/media');
+ $basepath = realpath($this->context->getParameter('wwwDir') . '/media');
$path = realpath($basepath . '/' . $path);
- if ($path === false || strpos($path, $basepath . '/') !== 0) {
+ if ($path === false || !str_starts_with($path, $basepath . '/')) {
$this->error();
}
$path = substr($path, strlen($basepath));
diff --git a/app/RouterFactory.php b/app/RouterFactory.php
index c947b879c..5306ae023 100755
--- a/app/RouterFactory.php
+++ b/app/RouterFactory.php
@@ -164,7 +164,7 @@ public static function createFolRouter(?array $domainList, array $routerMapping)
$router->withModule('Default')
->addRoute('///media/preview/', [
'presenter' => 'Default',
- 'action' => 'preview',
+ 'action' => 'imageGaleryComponentImagePreview',
])
->addRoute('///[/]', [
'presenter' => 'Default',
@@ -189,7 +189,7 @@ public static function createFofRouter(?array $domainList, array $routerMapping)
$router->withModule('Default')
->addRoute('///media/preview/', [
'presenter' => 'Default',
- 'action' => 'preview',
+ 'action' => 'imageGaleryComponentImagePreview',
])
->addRoute('///(international|erasmus)', [
'presenter' => 'Erasmus',
@@ -212,7 +212,7 @@ public static function createDsefRouter(?array $domainList, array $routerMapping
$router->withModule('Default')
->addRoute('///media/preview/', [
'presenter' => 'Default',
- 'action' => 'preview',
+ 'action' => 'imageGaleryComponentImagePreview',
])
->addRoute('///[/]', [
'presenter' => 'Default',
@@ -243,7 +243,7 @@ public static function createFykosRouter(?array $domainList, array $routerMappin
])
->addRoute('///media/preview/', [
'presenter' => 'Default',
- 'action' => 'preview',
+ 'action' => 'imageGaleryComponentImagePreview',
]);
$router->withModule('Default')
@@ -301,7 +301,7 @@ public static function createVyfukRouter(?array $domainList, array $routerMappin
])
->addRoute('///media/preview/', [
'presenter' => 'Default',
- 'action' => 'preview',
+ 'action' => 'imageGaleryComponentImagePreview',
])
->addRoute('///[/]', [
'presenter' => 'Default',