diff --git a/migrations/Version20231030225418.php b/migrations/Version20231030225418.php new file mode 100644 index 0000000..e43e71d --- /dev/null +++ b/migrations/Version20231030225418.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE torrent_poster ADD COLUMN position BOOLEAN NOT NULL DEFAULT "center"'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE torrent_poster DROP COLUMN position'); + } +} diff --git a/public/asset/default/css/framework.css b/public/asset/default/css/framework.css index 1c31c9c..0ca71e6 100644 --- a/public/asset/default/css/framework.css +++ b/public/asset/default/css/framework.css @@ -510,10 +510,6 @@ a:visited.background-color-hover-night-light:hover { /* responsive rules */ -.height-148-px { - height: 148px; -} - .width-100 { width: 100%; } diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index d4bb509..7511ff8 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -109,12 +109,19 @@ class TorrentController extends AbstractController // Poster if ($user->isPosters() && $torrent->getTorrentPosterId()) { - $poster = $request->getScheme() . '://' . - $request->getHttpHost() . - $request->getBasePath() . - $torrentService->getImageUriByTorrentPosterId( - $torrent->getTorrentPosterId() - ); + $torrentPoster = $torrentService->getTorrentPoster( + $torrent->getTorrentPosterId() + ); + + $poster = [ + 'position' => $torrentPoster->getPosition(), + 'url' => $request->getScheme() . '://' . + $request->getHttpHost() . + $request->getBasePath() . + $torrentService->getImageUriByTorrentPosterId( + $torrentPoster->getId() + ) + ]; } else @@ -304,12 +311,19 @@ class TorrentController extends AbstractController // Poster if ($user->isPosters() && $torrent->getTorrentPosterId()) { - $poster = $request->getScheme() . '://' . - $request->getHttpHost() . - $request->getBasePath() . - $torrentService->getImageUriByTorrentPosterId( - $torrent->getTorrentPosterId() - ); + $torrentPoster = $torrentService->getTorrentPoster( + $torrent->getTorrentPosterId() + ); + + $poster = [ + 'position' => $torrentPoster->getPosition(), + 'url' => $request->getScheme() . '://' . + $request->getHttpHost() . + $request->getBasePath() . + $torrentService->getImageUriByTorrentPosterId( + $torrentPoster->getId() + ) + ]; } else @@ -484,12 +498,19 @@ class TorrentController extends AbstractController // Poster if ($user->isPosters() && $torrent->getTorrentPosterId()) { - $poster = $request->getScheme() . '://' . - $request->getHttpHost() . - $request->getBasePath() . - $torrentService->getImageUriByTorrentPosterId( - $torrent->getTorrentPosterId() - ); + $torrentPoster = $torrentService->getTorrentPoster( + $torrent->getTorrentPosterId() + ); + + $poster = [ + 'position' => $torrentPoster->getPosition(), + 'url' => $request->getScheme() . '://' . + $request->getHttpHost() . + $request->getBasePath() . + $torrentService->getImageUriByTorrentPosterId( + $torrentPoster->getId() + ) + ]; } else @@ -1905,6 +1926,16 @@ class TorrentController extends AbstractController } } + // Init position + $position = in_array( + $request->get('position'), + [ + 'center', + 'top', + 'bottom' + ] + ) ? $request->get('position') : 'center'; + // Init edition history $editions = []; foreach ($torrentService->findTorrentPosterByTorrentId($torrent->getId()) as $torrentPosterEdition) @@ -1913,6 +1944,7 @@ class TorrentController extends AbstractController [ 'id' => $torrentPosterEdition->getId(), 'added' => $torrentPosterEdition->getAdded(), + 'position' => $torrentPosterEdition->getPosition(), 'approved' => $torrentPosterEdition->isApproved(), 'active' => $torrentPosterEdition->getId() == $torrentPosterCurrent['id'], 'user' => @@ -1940,13 +1972,28 @@ class TorrentController extends AbstractController 'poster' => [ 'error' => [] + ], + 'position' => + [ + 'error' => [], + 'attribute' => + [ + 'value' => $position + ] ] ]; // Process request if ($request->isMethod('post')) { - if ($file = $request->files->get('poster')) + if ($request->get('id') && $torrentService->getTorrentPoster($request->get('id'))) + { + $filename = $torrentService->getStorageFilepathByTorrentPosterId( + $request->get('id') + ); + } + + else if ($file = $request->files->get('poster')) { //// Validate poster file if (filesize($file->getPathName()) > $this->getParameter('app.torrent.poster.size.max')) @@ -1959,11 +2006,15 @@ class TorrentController extends AbstractController { $form['poster']['error'][] = $translator->trans('Image file not supported'); } + + $filename = $file->getPathName(); } else { $form['poster']['error'][] = $translator->trans('Poster file required'); + + $filename = false; } // Request is valid @@ -1971,7 +2022,8 @@ class TorrentController extends AbstractController { // Save data $torrentPoster = $torrentService->addTorrentPoster( - $file->getPathName(), + $filename, + $position, $torrent->getId(), $user->getId(), time(), diff --git a/src/Entity/TorrentPoster.php b/src/Entity/TorrentPoster.php index 495fae3..b25c481 100644 --- a/src/Entity/TorrentPoster.php +++ b/src/Entity/TorrentPoster.php @@ -28,6 +28,9 @@ class TorrentPoster #[ORM\Column(length: 32)] private ?string $md5file = null; + #[ORM\Column(length: 255)] + private ?string $position = null; + public function getId(): ?int { return $this->id; @@ -99,4 +102,16 @@ class TorrentPoster return $this; } + + public function getPosition(): ?string + { + return $this->position; + } + + public function setPosition(string $position): static + { + $this->position = $position; + + return $this; + } } diff --git a/src/Service/TorrentService.php b/src/Service/TorrentService.php index 1e52555..0a5b3bf 100644 --- a/src/Service/TorrentService.php +++ b/src/Service/TorrentService.php @@ -1126,6 +1126,7 @@ class TorrentService public function addTorrentPoster( string $filename, + string $position, int $torrentId, int $userId, int $added, @@ -1139,6 +1140,7 @@ class TorrentService $torrentPoster->setUserId($userId); $torrentPoster->setAdded($added); $torrentPoster->setApproved($approved); + $torrentPoster->setPosition($position); $torrentPoster->setMd5file( md5_file($filename) ); diff --git a/templates/default/torrent/edit/poster.html.twig b/templates/default/torrent/edit/poster.html.twig index a987a22..e4ed5e9 100644 --- a/templates/default/torrent/edit/poster.html.twig +++ b/templates/default/torrent/edit/poster.html.twig @@ -17,18 +17,32 @@ {% endfor %} +