-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
pictures preview #94
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.php.net/manual/en/function.str-starts-with.php