Browse Source

implement poster position settings #18

main 2.4.0
ghost 1 year ago
parent
commit
5c76a17df5
  1. 31
      migrations/Version20231030225418.php
  2. 4
      public/asset/default/css/framework.css
  3. 92
      src/Controller/TorrentController.php
  4. 15
      src/Entity/TorrentPoster.php
  5. 2
      src/Service/TorrentService.php
  6. 43
      templates/default/torrent/edit/poster.html.twig
  7. 2
      templates/default/torrent/info.html.twig
  8. 2
      templates/default/torrent/list.html.twig
  9. 12
      translations/messages+intl-icu.cs.xlf
  10. 12
      translations/messages+intl-icu.de.xlf
  11. 12
      translations/messages+intl-icu.en.xlf
  12. 12
      translations/messages+intl-icu.eo.xlf
  13. 12
      translations/messages+intl-icu.es.xlf
  14. 12
      translations/messages+intl-icu.fr.xlf
  15. 12
      translations/messages+intl-icu.he.xlf
  16. 12
      translations/messages+intl-icu.it.xlf
  17. 12
      translations/messages+intl-icu.ka.xlf
  18. 12
      translations/messages+intl-icu.lv.xlf
  19. 12
      translations/messages+intl-icu.nl.xlf
  20. 12
      translations/messages+intl-icu.pl.xlf
  21. 12
      translations/messages+intl-icu.pt.xlf
  22. 12
      translations/messages+intl-icu.ru.xlf
  23. 12
      translations/messages+intl-icu.uk.xlf

31
migrations/Version20231030225418.php

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231030225418 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}

4
public/asset/default/css/framework.css

@ -510,10 +510,6 @@ a:visited.background-color-hover-night-light:hover { @@ -510,10 +510,6 @@ a:visited.background-color-hover-night-light:hover {
/* responsive rules */
.height-148-px {
height: 148px;
}
.width-100 {
width: 100%;
}

92
src/Controller/TorrentController.php

@ -109,12 +109,19 @@ class TorrentController extends AbstractController @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -1971,7 +2022,8 @@ class TorrentController extends AbstractController
{
// Save data
$torrentPoster = $torrentService->addTorrentPoster(
$file->getPathName(),
$filename,
$position,
$torrent->getId(),
$user->getId(),
time(),

15
src/Entity/TorrentPoster.php

@ -28,6 +28,9 @@ class TorrentPoster @@ -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 @@ -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;
}
}

2
src/Service/TorrentService.php

@ -1126,6 +1126,7 @@ class TorrentService @@ -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 @@ -1139,6 +1140,7 @@ class TorrentService
$torrentPoster->setUserId($userId);
$torrentPoster->setAdded($added);
$torrentPoster->setApproved($approved);
$torrentPoster->setPosition($position);
$torrentPoster->setMd5file(
md5_file($filename)
);

43
templates/default/torrent/edit/poster.html.twig

@ -17,18 +17,32 @@ @@ -17,18 +17,32 @@
{% endfor %}
<input class="width-100" type="file" name="poster" value="" />
</div>
<div class="margin-y-16-px">
<input type="radio" name="position" id="position-center" value="center" {% if form.position.attribute.value == 'center' %}checked="checked"{% endif %} />
<label class="margin-x-4-px" for="position-center">
{{ 'Center' | trans }}
</label>
<input type="radio" name="position" id="position-top" value="top" {% if form.position.attribute.value == 'top' %}checked="checked"{% endif %} />
<label class="margin-x-4-px" for="position-top">
{{ 'Top' | trans }}
</label>
<input type="radio" name="position" id="position-bottom" value="bottom" {% if form.position.attribute.value == 'bottom' %}checked="checked"{% endif %} />
<label class="margin-x-4-px" for="position-bottom">
{{ 'Bottom' | trans }}
</label>
</div>
<div class="padding-t-4-px margin-b-16-px border-bottom-default"></div>
<div class="text-right">
<a class="margin-r-8-px" href="{{ path('torrent_info', { torrentId : torrentId }) }}">
{{'cancel' | trans }}
{{ 'cancel' | trans }}
</a>
<input class="button-green" type="submit" value="{{'Submit'|trans }}" />
</div>
</form>
</div>
{% for edition in editions %}
<div class="padding-x-24-px padding-y-16-px margin-y-8-px border-radius-3-px {% if edition.active %}background-color-night-light height-148-px{% else %}background-color-night{% endif %} {% if edition.poster %}background-poster{% endif %}"
{% if edition.poster %}style="background-image:url('{{ edition.poster }}')"{% endif %}>
<div class="padding-x-24-px padding-y-16-px margin-y-8-px border-radius-3-px {% if edition.active %}background-color-night-light{% else %}background-color-night{% endif %} {% if edition.poster %}background-poster{% endif %}"
{% if edition.poster %}style="background-image:url('{{ edition.poster }}');background-position:{{ edition.position }}"{% endif %}>
{% if edition.active %}
{{ edition.added | format_ago }}
{% else %}
@ -79,6 +93,29 @@ @@ -79,6 +93,29 @@
{% endif %}
{% endif %}
</div>
{% if edition.active %}
<form name="poster-edition-{{ edition.id }}" method="post" action="{{ path('torrent_poster_edit', { torrentId : torrentId }) }}">
<input type="hidden" name="id" value="{{ edition.id }}" />
<div class="margin-y-16-px">
<input type="radio" name="position" id="poster-edition-{{ edition.id }}-position-center" value="center" {% if edition.position == 'center' %}checked="checked"{% endif %} />
<label class="margin-x-4-px" for="poster-edition-{{ edition.id }}-position-center">
{{ 'Center' | trans }}
</label>
<input type="radio" name="position" id="poster-edition-{{ edition.id }}-position-top" value="top" {% if edition.position == 'top' %}checked="checked"{% endif %} />
<label class="margin-x-4-px" for="poster-edition-{{ edition.id }}-position-top">
{{ 'Top' | trans }}
</label>
<input type="radio" name="position" id="poster-edition-{{ edition.id }}-position-bottom" value="bottom" {% if edition.position == 'bottom' %}checked="checked"{% endif %} />
<label class="margin-x-4-px" for="poster-edition-{{ edition.id }}-position-bottom">
{{ 'Bottom' | trans }}
</label>
</div>
<div class="padding-t-4-px margin-b-16-px border-bottom-default"></div>
<div class="text-right">
<input class="button-green" type="submit" value="{{'Submit'|trans }}" />
</div>
</form>
{% endif %}
</div>
{% endfor %}
{% endblock %}

2
templates/default/torrent/info.html.twig

@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
{% endblock %}
{% block main_content %}
<div class="padding-24-px margin-y-8-px border-radius-3-px background-color-night {% if torrent.poster %}background-poster{% endif %}"
{% if torrent.poster %}style="background-image:url('{{ torrent.poster }}')"{% endif %}>
{% if torrent.poster %}style="background-image:url('{{ torrent.poster.url }}');background-position:{{ torrent.poster.position }}"{% endif %}>
<h1 class="display-block text-center margin-b-16-px">
{{ file.name }}
{#{{ 'Torrent' | trans }} #{{ torrent.id }}#}

2
templates/default/torrent/list.html.twig

@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
{% if torrents %}
{% for torrent in torrents %}
<div class="padding-24-px margin-y-8-px border-radius-3-px background-color-night {% if torrent.poster %}background-poster{% endif %}"
{% if torrent.poster %}style="background-image:url('{{ torrent.poster }}')"{% endif %}>
{% if torrent.poster %}style="background-image:url('{{ torrent.poster.url }}');background-position:{{ torrent.poster.position }}"{% endif %}>
<a name="{{ torrent.id }}"></a>
<div class="margin-b-16-px">
<h2>

12
translations/messages+intl-icu.cs.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.de.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.en.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.eo.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.es.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.fr.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.he.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.it.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.ka.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.lv.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.nl.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.pl.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.pt.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Torrent posters</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Center</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Top</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Bottom</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.ru.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Постеры торрентов</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Центр</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Верх</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Низ</target>
</trans-unit>
</body>
</file>
</xliff>

12
translations/messages+intl-icu.uk.xlf

@ -785,6 +785,18 @@ @@ -785,6 +785,18 @@
<source>Torrent posters</source>
<target>Постери торентів</target>
</trans-unit>
<trans-unit id="2UYGdCf" resname="Center">
<source>Center</source>
<target>Центр</target>
</trans-unit>
<trans-unit id="1c389.9" resname="Top">
<source>Top</source>
<target>Верх</target>
</trans-unit>
<trans-unit id="R5rSGsk" resname="Bottom">
<source>Bottom</source>
<target>Низ</target>
</trans-unit>
</body>
</file>
</xliff>

Loading…
Cancel
Save