Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pictures preview #94

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions app/Components/ImageGallery/ImageGalleryControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Nette\Caching\Storage;
use Nette\DI\Container;
use Nette\Utils\Finder;
use Nette\Utils\Image;
use Nette\Utils\UnknownImageFileException;

class ImageGalleryControl extends DIComponent
Expand Down Expand Up @@ -44,11 +43,21 @@ public static function getImages(string $path, string $wwwDir): array
foreach ($iterator as $file) {
$imageInfo = getimagesize($file->getPathname());
$wwwPath = substr($file->getPathname(), strlen($wwwDir));
$images[] = [
'src' => $wwwPath,
'width' => $imageInfo[0],
'height' => $imageInfo[1],
];
if (strpos($wwwPath, '/media/') === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$images[] = [
'src' => $wwwPath,
'width' => $imageInfo[0],
'height' => $imageInfo[1],
'srcset' => $wwwPath . ' ' . $imageInfo[0] . 'w,' . str_replace('/media/', '/media/preview/', $wwwPath) . ' 1024w',
'previewSrc' => str_replace('/media/', '/media/preview/', $wwwPath),
];
} else {
$images[] = [
'src' => $wwwPath,
'width' => $imageInfo[0],
'height' => $imageInfo[1],
];
}
}

usort($images, function ($a, $b) {
Expand Down
2 changes: 1 addition & 1 deletion app/Components/ImageGallery/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
data-pswp-width="{$image['width']}"
data-pswp-height="{$image['height']}"
target="_blank">
<img src="{$image['src']}" alt="" class="w-100 shadow-1-strong rounded mb-4" style="aspect-ratio: 4/3; object-fit: cover;"/>
<img src="{isset($image['previewSrc'])?$image['previewSrc']:$image['src']}" alt="" class="w-100 shadow-1-strong rounded mb-4" style="aspect-ratio: 4/3; object-fit: cover;" loading="lazy"/>
</a>
</div>
{/foreach}
Expand Down
2 changes: 1 addition & 1 deletion app/Components/ImageGallery/oneLine.latte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="col-lg-2 col-md-12 mb-2 mb-lg-0">
<a href="#" data-index="{$image['index']}">
<div class="position-relative mb-4">
<img src="{$image['src']}" alt="" class="w-100 shadow-1-strong rounded" style="aspect-ratio: 4/3; object-fit: cover;"/>
<img src="{isset($image['previewSrc'])?$image['previewSrc']:$image['src']}" alt="" class="w-100 shadow-1-strong rounded" style="aspect-ratio: 4/3; object-fit: cover;" loading="lazy"/>
{if $iterator->isLast() && count($images) > count($previewImages)}
<div class="position-absolute top-0 start-0 w-100 h-100 d-flex justify-content-center align-items-center" style="background-color: rgba(0, 0, 0, 0.5);">
<i class="fas fa-search-plus text-white fs-3"></i>
Expand Down
28 changes: 28 additions & 0 deletions app/Modules/Core/BasePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -142,4 +145,29 @@ protected function createComponentPdfGallery(): PdfGalleryControl
{
return new PdfGalleryControl($this->getContext());
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tymto sa odrezáva vo všetkých presenteroch akcia preview, čo je veľmi, zlé ak by ju niekto chcel výhladovo použiť.

Ak sa takto nejaká akcia vyčlení (čo je zlý koncpet), tak sa má zafixovať, že že ju nikto neprepíše pomocou final

Každopádne riešenie tohoto je spraviť samostaný presenter, ktorý bude rešiť len fotky.

private readonly string $wwwDir;

public function injectWwwDir(Container $container): void
Copy link
Member

@cevro cevro Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Načo? V presenteri je DI kontainer dostupný.

{
$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));
}
}
32 changes: 25 additions & 7 deletions app/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public static function createFolRouter(?array $domainList, array $routerMapping)
]);

$router->withModule('Default')
->addRoute('//<domain>/media/preview/<path .+>', [
'presenter' => 'Default',
'action' => 'preview',
])
->addRoute('//<domain>/<presenter>[/<action>]', [
'presenter' => 'Default',
'action' => 'default',
Expand All @@ -183,6 +187,10 @@ public static function createFofRouter(?array $domainList, array $routerMapping)
]);

$router->withModule('Default')
->addRoute('//<domain>/media/preview/<path .+>', [
'presenter' => 'Default',
'action' => 'preview',
])
->addRoute('//<domain>/(international|erasmus)', [
'presenter' => 'Erasmus',
'lang' => 'en',
Expand All @@ -202,6 +210,10 @@ public static function createDsefRouter(?array $domainList, array $routerMapping
$router = new RouteList();

$router->withModule('Default')
->addRoute('//<domain>/media/preview/<path .+>', [
'presenter' => 'Default',
'action' => 'preview',
])
->addRoute('//<domain>/<presenter>[/<action>]', [
'presenter' => 'Default',
'action' => 'default',
Expand All @@ -228,6 +240,10 @@ public static function createFykosRouter(?array $domainList, array $routerMappin
'presenter' => 'Results',
'action' => 'default',
null => self::useTranslateFilter($domainList, $routerMapping['default'])
])
->addRoute('//<domain>/media/preview/<path .+>', [
'presenter' => 'Default',
'action' => 'preview',
]);

$router->withModule('Default')
Expand All @@ -252,10 +268,10 @@ public static function createFykosRouter(?array $domainList, array $routerMappin
]);

$router->withModule('Events')
->addRoute('//<domain>/akce/tsaf/<year>-<month>', [
'presenter' => 'Tsaf',
'action' => 'detail'
]);
->addRoute('//<domain>/akce/tsaf/<year>-<month>', [
'presenter' => 'Tsaf',
'action' => 'detail'
]);

$router->addRoute('//<domain>/<module events|akce>/[<presenter>[/<action>]]', [
'presenter' => 'Default',
Expand All @@ -282,9 +298,11 @@ public static function createVyfukRouter(?array $domainList, array $routerMappin
'presenter' => 'Problems',
'action' => 'default',
null => self::useTranslateFilter($domainList, $routerMapping['default']),
]);

$router->withModule('Default')
])
->addRoute('//<domain>/media/preview/<path .+>', [
'presenter' => 'Default',
'action' => 'preview',
])
->addRoute('//<domain>/<presenter>[/<action>]', [
'presenter' => 'Default',
'action' => 'default',
Expand Down
2 changes: 1 addition & 1 deletion www/dsef/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -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]
</IfModule>

# enable gzip compression
Expand Down
2 changes: 1 addition & 1 deletion www/fof/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -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]
</IfModule>

# enable gzip compression
Expand Down
2 changes: 1 addition & 1 deletion www/fol/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -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]
</IfModule>

# enable gzip compression
Expand Down
2 changes: 1 addition & 1 deletion www/fykos/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -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]

</IfModule>

Expand Down
2 changes: 1 addition & 1 deletion www/vyfuk/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -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]
</IfModule>

# enable gzip compression
Expand Down
Loading