Browse Source

update torrent features

main
ghost 1 year ago
parent
commit
e713c17333
  1. 2
      public/asset/default/css/framework.css
  2. 75
      src/Controller/ActivityController.php
  3. 166
      src/Controller/SearchController.php
  4. 300
      src/Controller/TorrentController.php
  5. 46
      src/Controller/UserController.php
  6. 39
      src/Entity/Torrent.php
  7. 2
      src/Entity/TorrentLocales.php
  8. 4
      src/Entity/User.php
  9. 92
      src/Repository/TorrentRepository.php
  10. 221
      src/Service/TorrentService.php
  11. 6
      templates/default/activity/list.html.twig
  12. 2
      templates/default/layout.html.twig
  13. 6
      templates/default/search/module.html.twig
  14. 2
      templates/default/torrent/info.html.twig
  15. 4
      templates/default/torrent/list.html.twig
  16. 19
      templates/default/user/module.html.twig

2
public/asset/default/css/framework.css

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
.container {
position: relative;
overflow: hidden;
max-width: 732px;
max-width: 748px;
margin: 0 auto;
}

75
src/Controller/ActivityController.php

@ -15,6 +15,50 @@ use App\Service\TorrentService; @@ -15,6 +15,50 @@ use App\Service\TorrentService;
class ActivityController extends AbstractController
{
#[Route(
'/{_locale}/activity',
name: 'activity_all',
methods:
[
'GET'
]
)]
public function all(
Request $request,
UserService $userService,
ActivityService $activityService
): Response
{
$user = $this->initUser(
$request,
$userService,
$activityService
);
$total = $activityService->findActivitiesTotal(
$user->getEvents()
);
$page = $request->get('page') ? (int) $request->get('page') : 1;
return $this->render(
'default/activity/list.html.twig',
[
'activities' => $activityService->findLastActivities( // @TODO locale/sensitive filters
$user->getEvents(),
$this->getParameter('app.pagination'),
($page - 1) * $this->getParameter('app.pagination')
),
'pagination' =>
[
'page' => $page,
'pages' => ceil($total / $this->getParameter('app.pagination')),
'total' => $total
]
]
);
}
public function event(
$activity,
ActivityService $activityService,
@ -727,4 +771,35 @@ class ActivityController extends AbstractController @@ -727,4 +771,35 @@ class ActivityController extends AbstractController
);
}
}
private function initUser(
Request $request,
UserService $userService,
ActivityService $activityService
): ?\App\Entity\User
{
// Init user
if (!$user = $userService->findUserByAddress($request->getClientIp()))
{
$user = $userService->addUser(
$request->getClientIp(),
time(),
$this->getParameter('app.locale'),
explode('|', $this->getParameter('app.locales')),
$activityService->getEventCodes(),
$this->getParameter('app.theme'),
$this->getParameter('app.sensitive'),
$this->getParameter('app.yggdrasil'),
$this->getParameter('app.approved')
);
// Add user join event
$activityService->addEventUserAdd(
$user->getId(),
time()
);
}
return $user;
}
}

166
src/Controller/SearchController.php

@ -9,175 +9,21 @@ use Symfony\Component\HttpFoundation\Response; @@ -9,175 +9,21 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use App\Service\UserService;
use App\Service\ArticleService;
use App\Service\TorrentService;
use App\Service\ActivityService;
class SearchController extends AbstractController
{
#[Route(
'/{_locale}/search',
name: 'search_index',
methods:
[
'GET'
]
)]
public function index(
Request $request,
UserService $userService,
ArticleService $articleService,
TorrentService $torrentService,
ActivityService $activityService
): Response
{
// Init user
$user = $this->initUser(
$request,
$userService,
$activityService
);
$article = $request->query->get('article') ? (int) $request->query->get('article') : 1;
switch ($request->query->get('type'))
{
case 'article':
break;
case 'torrent':
$total = 0; // @TODO pagination
$torrents = [];
foreach ($torrentService->searchTorrents($request->query->get('query')) as $torrent)
{
// Apply locales filter
if ($lastTorrentLocales = $torrentService->findLastTorrentLocalesByTorrentIdApproved($torrent->getId()))
{
if (!count(
array_intersect(
$lastTorrentLocales->getValue(),
$user->getLocales()
)
)) {
$total--;
continue;
}
}
// Apply sensitive filters
if ($lastTorrentSensitive = $torrentService->findLastTorrentSensitiveByTorrentIdApproved($torrent->getId()))
{
if ($user->isSensitive() && $lastTorrentSensitive->isValue())
{
$total--;
continue;
}
}
// Read file
if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId()))
{
$total--;
continue; // @TODO exception
}
// Generate keywords
$keywords = [];
$query = explode(' ', mb_strtolower($request->query->get('query')));
foreach (explode(',', $torrent->getKeywords()) as $keyword)
{
if (in_array($keyword, $query))
{
$keywords[] = urlencode($keyword);
}
}
$torrents[] =
[
'id' => $torrent->getId(),
'added' => $torrent->getAdded(),
'file' =>
[
'name' => $file->getName(),
'size' => $file->getSize(),
],
'scrape' =>
[
'seeders' => (int) $torrent->getSeeders(),
'peers' => (int) $torrent->getPeers(),
'leechers' => (int) $torrent->getLeechers(),
],
'user' =>
[
'id' => $torrent->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$torrent->getUserId()
)->getAddress()
)
],
'keywords' => $keywords,
'download' =>
[
'file' =>
[
'exist' => (bool) $torrentService->findTorrentDownloadFile(
$torrent->getId(),
$user->getId()
),
'total' => $torrentService->findTorrentDownloadFilesTotalByTorrentId(
$torrent->getId()
)
],
'magnet' =>
[
'exist' => (bool) $torrentService->findTorrentDownloadMagnet(
$torrent->getId(),
$user->getId()
),
'total' => $torrentService->findTorrentDownloadMagnetsTotalByTorrentId(
$torrent->getId()
)
]
],
'star' =>
[
'exist' => (bool) $torrentService->findTorrentStar(
$torrent->getId(),
$user->getId()
),
'total' => $torrentService->findTorrentStarsTotalByTorrentId(
$torrent->getId()
)
],
];
}
return $this->render('default/search/torrent.html.twig', [
'query' => $request->query->get('query'),
'torrents' => $torrents
]);
break;
default:
throw $this->createNotFoundException();
}
}
public function module(
?string $query,
?string $type
): Response
{
return $this->render('default/search/module.html.twig', [
'query' => $query,
'type' => $type,
]);
return $this->render(
'default/search/module.html.twig',
[
'query' => $query,
]
);
}
private function initUser(

300
src/Controller/TorrentController.php

@ -57,27 +57,11 @@ class TorrentController extends AbstractController @@ -57,27 +57,11 @@ class TorrentController extends AbstractController
// Get contributors
$contributors = [];
$contributors[$torrent->getUserId()] = $userService->identicon(
$userService->getUser(
$torrent->getUserId()
)->getAddress()
);
if ($torrentLocales = $torrentService->findLastTorrentLocalesByTorrentId($torrent->getId()))
{
$contributors[$torrentLocales->getUserId()] = $userService->identicon(
$userService->getUser(
$torrentLocales->getUserId()
)->getAddress()
);
}
if ($torrentSensitive = $torrentService->findLastTorrentSensitiveByTorrentId($torrent->getId()))
foreach ($torrentService->getTorrentContributors($torrent) as $userId)
{
$contributors[$torrentSensitive->getUserId()] = $userService->identicon(
$contributors[$userId] = $userService->identicon(
$userService->getUser(
$torrentSensitive->getUserId()
$userId
)->getAddress()
);
}
@ -98,25 +82,14 @@ class TorrentController extends AbstractController @@ -98,25 +82,14 @@ class TorrentController extends AbstractController
'id' => $torrent->getId(),
'md5file' => $torrent->getMd5File(),
'added' => $torrent->getAdded(),
/*
'user' =>
[
'id' => $torrent->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$torrent->getUserId()
)->getAddress()
),
],
*/
'scrape' =>
[
'seeders' => (int) $torrent->getSeeders(),
'peers' => (int) $torrent->getPeers(),
'leechers' => (int) $torrent->getLeechers(),
],
'locales' => $torrentService->findLastTorrentLocalesByTorrentId($torrent->getId()),
'sensitive' => $torrentService->findLastTorrentSensitiveByTorrentId($torrent->getId())->isValue(),
'locales' => $torrent->getLocales(),
'sensitive' => $torrent->isSensitive(),
'download' =>
[
'file' =>
@ -172,8 +145,6 @@ class TorrentController extends AbstractController @@ -172,8 +145,6 @@ class TorrentController extends AbstractController
'v1' => $file->getInfoHashV1(false),
'v2' => $file->getInfoHashV2(false)
],
// @TODO use download action to filter announcement URL
// 'magnet' => $file->getMagnetLink()
],
'trackers' => explode('|', $this->getParameter('app.trackers')),
'activities' => $activityService->findLastActivitiesByTorrentId(
@ -192,7 +163,263 @@ class TorrentController extends AbstractController @@ -192,7 +163,263 @@ class TorrentController extends AbstractController
}
#[Route(
'/{_locale}/submit/torrent',
'/{_locale}/search',
name: 'torrent_search',
methods:
[
'GET'
]
)]
public function search(
Request $request,
UserService $userService,
TorrentService $torrentService,
ActivityService $activityService
): Response
{
// Init user
$user = $this->initUser(
$request,
$userService,
$activityService
);
// Init request
$query = $request->get('query') ? explode(' ', $request->get('query')) : [];
$page = $request->get('page') ? (int) $request->get('page') : 1;
// Get total torrents
$total = $torrentService->findTorrentsTotal(
$query,
$user->getLocales(),
$user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
$user->isModerator() ? null : true, // show approved content only for regular users
);
$torrents = [];
foreach ($torrentService->findTorrents(
$query,
$user->getLocales(),
$user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
$user->isModerator() ? null : true, // show approved content only for regular users
$this->getParameter('app.pagination'),
($page - 1) * $this->getParameter('app.pagination')
) as $torrent)
{
// Read file
if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId()))
{
throw $this->createNotFoundException(); // @TODO exception
}
// Generate keywords
$keywords = [];
foreach ($torrent->getKeywords() as $keyword)
{
if (in_array($keyword, $query))
{
$keywords[] = urlencode($keyword);
}
}
$torrents[] =
[
'id' => $torrent->getId(),
'added' => $torrent->getAdded(),
'file' =>
[
'name' => $file->getName(),
'size' => $file->getSize(),
],
'scrape' =>
[
'seeders' => (int) $torrent->getSeeders(),
'peers' => (int) $torrent->getPeers(),
'leechers' => (int) $torrent->getLeechers(),
],
'user' =>
[
'id' => $torrent->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$torrent->getUserId()
)->getAddress()
)
],
'keywords' => $keywords,
'download' =>
[
'file' =>
[
'exist' => (bool) $torrentService->findTorrentDownloadFile(
$torrent->getId(),
$user->getId()
),
'total' => $torrentService->findTorrentDownloadFilesTotalByTorrentId(
$torrent->getId()
)
],
'magnet' =>
[
'exist' => (bool) $torrentService->findTorrentDownloadMagnet(
$torrent->getId(),
$user->getId()
),
'total' => $torrentService->findTorrentDownloadMagnetsTotalByTorrentId(
$torrent->getId()
)
]
],
'star' =>
[
'exist' => (bool) $torrentService->findTorrentStar(
$torrent->getId(),
$user->getId()
),
'total' => $torrentService->findTorrentStarsTotalByTorrentId(
$torrent->getId()
)
],
];
}
return $this->render('default/torrent/list.html.twig', [
'query' => $request->query->get('query'),
'torrents' => $torrents
]);
}
#[Route(
'/{_locale}',
name: 'torrent_recent',
methods:
[
'GET'
]
)]
public function recent(
Request $request,
UserService $userService,
TorrentService $torrentService,
ActivityService $activityService
): Response
{
// Init user
$user = $this->initUser(
$request,
$userService,
$activityService
);
// Init page
$page = $request->get('page') ? (int) $request->get('page') : 1;
// Get total torrents
$total = $torrentService->findTorrentsTotal(
[],
$user->getLocales(),
$user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
$user->isModerator() ? null : true, // show approved content only for regular users
);
// Create torrents list
$torrents = [];
foreach ($torrentService->findTorrents(
[],
$user->getLocales(),
$user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
$user->isModerator() ? null : true, // show approved content only for regular users
$this->getParameter('app.pagination'),
($page - 1) * $this->getParameter('app.pagination')
) as $torrent)
{
// Read file
if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId()))
{
throw $this->createNotFoundException(); // @TODO exception
}
// Generate keywords
$keywords = [];
$query = explode(' ', mb_strtolower($request->query->get('query')));
foreach ($torrent->getKeywords() as $keyword)
{
if (in_array($keyword, $query))
{
$keywords[] = urlencode($keyword);
}
}
$torrents[] =
[
'id' => $torrent->getId(),
'added' => $torrent->getAdded(),
'file' =>
[
'name' => $file->getName(),
'size' => $file->getSize(),
],
'scrape' =>
[
'seeders' => (int) $torrent->getSeeders(),
'peers' => (int) $torrent->getPeers(),
'leechers' => (int) $torrent->getLeechers(),
],
'user' =>
[
'id' => $torrent->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$torrent->getUserId()
)->getAddress()
)
],
'keywords' => $keywords,
'download' =>
[
'file' =>
[
'exist' => (bool) $torrentService->findTorrentDownloadFile(
$torrent->getId(),
$user->getId()
),
'total' => $torrentService->findTorrentDownloadFilesTotalByTorrentId(
$torrent->getId()
)
],
'magnet' =>
[
'exist' => (bool) $torrentService->findTorrentDownloadMagnet(
$torrent->getId(),
$user->getId()
),
'total' => $torrentService->findTorrentDownloadMagnetsTotalByTorrentId(
$torrent->getId()
)
]
],
'star' =>
[
'exist' => (bool) $torrentService->findTorrentStar(
$torrent->getId(),
$user->getId()
),
'total' => $torrentService->findTorrentStarsTotalByTorrentId(
$torrent->getId()
)
],
];
}
return $this->render('default/torrent/list.html.twig', [
'query' => $request->query->get('query'),
'torrents' => $torrents
]);
}
// Forms
#[Route(
'/{_locale}/submit',
name: 'torrent_submit',
methods:
[
@ -310,6 +537,7 @@ class TorrentController extends AbstractController @@ -310,6 +537,7 @@ class TorrentController extends AbstractController
$user->isApproved()
);
// Add activity event
$activityService->addEventTorrentAdd(
$user->getId(),
time(),
@ -765,7 +993,7 @@ class TorrentController extends AbstractController @@ -765,7 +993,7 @@ class TorrentController extends AbstractController
}
else
{
if ($torrentSensitive = $torrentService->findLastTorrentSensitiveByTorrentId($request->get('torrentId')))
if ($torrentSensitive = $torrentService->findLastTorrentSensitiveByTorrentId($torrent->getId()))
{
$torrentSensitiveCurrent =
[

46
src/Controller/UserController.php

@ -31,57 +31,13 @@ class UserController extends AbstractController @@ -31,57 +31,13 @@ class UserController extends AbstractController
);
return $this->redirectToRoute(
'user_dashboard',
'torrent_recent',
[
'_locale' => $user->getLocale()
]
);
}
#[Route(
'/{_locale}',
name: 'user_dashboard',
methods:
[
'GET'
]
)]
public function index(
Request $request,
UserService $userService,
ActivityService $activityService
): Response
{
$user = $this->initUser(
$request,
$userService,
$activityService
);
$total = $activityService->findActivitiesTotal(
$user->getEvents()
);
$page = $request->get('page') ? (int) $request->get('page') : 1;
return $this->render(
'default/user/dashboard.html.twig',
[
'activities' => $activityService->findLastActivities( // @TODO locale/sensitive filters
$user->getEvents(),
$this->getParameter('app.pagination'),
($page - 1) * $this->getParameter('app.pagination')
),
'pagination' =>
[
'page' => $page,
'pages' => ceil($total / $this->getParameter('app.pagination')),
'total' => $total
]
]
);
}
#[Route(
'/{_locale}/settings',
name: 'user_settings',

39
src/Entity/Torrent.php

@ -6,7 +6,6 @@ use App\Repository\TorrentRepository; @@ -6,7 +6,6 @@ use App\Repository\TorrentRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
// @TODO #[ORM\Index(columns: ['keywords'], name: 'keywords_idx', flags: ['fulltext'])]
#[ORM\Entity(repositoryClass: TorrentRepository::class)]
class Torrent
@ -25,14 +24,20 @@ class Torrent @@ -25,14 +24,20 @@ class Torrent
#[ORM\Column(nullable: true)]
private ?int $scraped = null;
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $locales = [];
#[ORM\Column]
private ?bool $sensitive = null;
#[ORM\Column]
private ?bool $approved = null;
#[ORM\Column(length: 32)]
private ?string $md5file = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $keywords = null;
#[ORM\Column(type: Types::SIMPLE_ARRAY, nullable: true)]
private ?array $keywords = null;
#[ORM\Column(nullable: true)]
private ?int $seeders = null;
@ -103,18 +108,42 @@ class Torrent @@ -103,18 +108,42 @@ class Torrent
return $this;
}
public function getKeywords(): ?string
public function getKeywords(): ?array
{
return $this->keywords;
}
public function setKeywords(?string $keywords): static
public function setKeywords(?array $keywords): static
{
$this->keywords = $keywords;
return $this;
}
public function getLocales(): array
{
return $this->locales;
}
public function setLocales(array $locales): static
{
$this->locales = $locales;
return $this;
}
public function isSensitive(): ?bool
{
return $this->sensitive;
}
public function setSensitive(bool $sensitive): static
{
$this->sensitive = $sensitive;
return $this;
}
public function isApproved(): ?bool
{
return $this->approved;

2
src/Entity/TorrentLocales.php

@ -23,7 +23,7 @@ class TorrentLocales @@ -23,7 +23,7 @@ class TorrentLocales
#[ORM\Column]
private ?int $added = null;
#[ORM\Column(type: Types::ARRAY)]
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $value = [];
#[ORM\Column]

4
src/Entity/User.php

@ -32,10 +32,10 @@ class User @@ -32,10 +32,10 @@ class User
#[ORM\Column(length: 2)]
private ?string $locale = null;
#[ORM\Column(type: Types::ARRAY)]
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $locales = [];
#[ORM\Column(type: Types::ARRAY)]
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $events = [];
#[ORM\Column(length: 255)]

92
src/Repository/TorrentRepository.php

@ -21,20 +21,94 @@ class TorrentRepository extends ServiceEntityRepository @@ -21,20 +21,94 @@ class TorrentRepository extends ServiceEntityRepository
parent::__construct($registry, Torrent::class);
}
public function searchByKeywords(
array $keywords
): ?array
public function findTorrentsTotal(
array $keywords,
array $locales,
?bool $sensitive = null,
?bool $approved = null,
int $limit = 0,
int $offset = 10
): int
{
return $this->getTorrentsQueryByFilter(
$keywords,
$locales,
$sensitive,
$approved,
)->select('count(t.id)')
->getQuery()
->getSingleScalarResult();
}
public function findTorrents(
array $keywords,
array $locales,
?bool $sensitive = null,
?bool $approved = null,
int $limit = 0,
int $offset = 10
): array
{
return $this->getTorrentsQueryByFilter(
$keywords,
$locales,
$sensitive,
$approved,
)->setMaxResults($limit)
->setFirstResult($offset)
->orderBy('t.id', 'DESC') // same as t.added
->getQuery()
->getResult();
}
private function getTorrentsQueryByFilter(
array $keywords,
array $locales,
?bool $sensitive = null,
?bool $approved = null,
): \Doctrine\ORM\QueryBuilder
{
$query = $this->createQueryBuilder('t');
foreach ($keywords as $keyword)
if ($keywords) // @TODO ANY or DTS
{
$query->orWhere('t.keywords LIKE :query')
->setParameter('query', "%{$keyword}%");
$orX = $query->expr()->orX();
foreach ($keywords as $i => $keyword)
{
$orX->add("t.keywords LIKE :keyword{$i}");
$query->setParameter(":keyword{$i}", "%{$keyword}%");
}
$query->andWhere($orX);
}
return $query->orderBy('t.id', 'ASC') // same as t.added
->getQuery()
->getResult();
if ($locales) // @TODO ANY or DTS
{
$orX = $query->expr()->orX();
foreach ($locales as $i => $locale)
{
$orX->add("t.locales LIKE :locale{$i}");
$query->setParameter(":locale{$i}", "%{$locale}%");
}
$query->andWhere($orX);
}
if (is_bool($sensitive))
{
$query->andWhere('t.sensitive = :sensitive')
->setParameter('sensitive', $sensitive);
}
if (is_bool($approved))
{
$query->andWhere('t.approved = :approved')
->setParameter('approved', $approved);
}
return $query;
}
}

221
src/Service/TorrentService.php

@ -150,7 +150,7 @@ class TorrentService @@ -150,7 +150,7 @@ class TorrentService
public function generateTorrentKeywordsByTorrentFilepath(
string $filepath,
int $minLength = 3
): string
): array
{
$keywords = [];
@ -175,17 +175,17 @@ class TorrentService @@ -175,17 +175,17 @@ class TorrentService
{
unset($words[$key]);
}
else
{
$words[$key] = mb_strtolower($value);
}
}
$keywords = array_merge($keywords, $words);
}
return mb_strtolower(
implode(
',',
array_unique($keywords)
)
);
return array_unique($keywords);
}
public function getStorageFilepathById(int $id): string
@ -197,6 +197,25 @@ class TorrentService @@ -197,6 +197,25 @@ class TorrentService
);
}
public function getTorrentContributors(Torrent $torrent): array
{
$contributors = [];
foreach ($this->findTorrentLocalesByTorrentId($torrent->getUserId()) as $torrentLocale)
{
$contributors[] = $torrentLocale->getUserId();
}
foreach ($this->findTorrentSensitiveByTorrentId($torrent->getUserId()) as $torrentSensitive)
{
$contributors[] = $torrentSensitive->getUserId();
}
$contributors[] = $torrent->getUserId();
return array_unique($contributors);
}
public function add(
string $filepath,
int $userId,
@ -213,6 +232,8 @@ class TorrentService @@ -213,6 +232,8 @@ class TorrentService
$this->generateTorrentKeywordsByTorrentFilepath(
$filepath
),
$locales,
$sensitive,
$approved
);
@ -224,16 +245,13 @@ class TorrentService @@ -224,16 +245,13 @@ class TorrentService
)
);
if (!empty($locales))
{
$this->addTorrentLocales(
$torrent->getId(),
$userId,
$added,
$locales,
$approved
);
}
$this->addTorrentLocales(
$torrent->getId(),
$userId,
$added,
$locales,
$approved
);
$this->addTorrentSensitive(
$torrent->getId(),
@ -258,7 +276,9 @@ class TorrentService @@ -258,7 +276,9 @@ class TorrentService
int $userId,
int $added,
string $md5file,
string $keywords,
array $keywords,
array $locales,
bool $sensitive,
bool $approved
): ?Torrent
{
@ -268,6 +288,8 @@ class TorrentService @@ -268,6 +288,8 @@ class TorrentService
$torrent->setAdded($added);
$torrent->setMd5File($md5file);
$torrent->setKeywords($keywords);
$torrent->setLocales($locales);
$torrent->setSensitive($sensitive);
$torrent->setApproved($approved);
$this->entityManagerInterface->persist($torrent);
@ -288,12 +310,41 @@ class TorrentService @@ -288,12 +310,41 @@ class TorrentService
);
}
public function searchTorrents(string $query) : array
public function findTorrents(
array $keywords,
array $locales,
?bool $sensitive,
?bool $approved,
int $limit,
int $offset
) : array
{
return $this->entityManagerInterface
->getRepository(Torrent::class)
->searchByKeywords(
explode(' ', $query)
->findTorrents(
$keywords,
$locales,
$sensitive,
$approved,
$limit,
$offset
);
}
public function findTorrentsTotal(
array $keywords,
array $locales,
?bool $sensitive,
?bool $approved
) : int
{
return $this->entityManagerInterface
->getRepository(Torrent::class)
->findTorrentsTotal(
$keywords,
$locales,
$sensitive,
$approved
);
}
@ -308,6 +359,74 @@ class TorrentService @@ -308,6 +359,74 @@ class TorrentService
);
}
public function updateTorrentSensitive(
int $torrentId,
): void
{
if ($torrent = $this->getTorrent($torrentId))
{
if ($torrentSensitive = $this->entityManagerInterface
->getRepository(TorrentSensitive::class)
->findOneBy(
[
'torrentId' => $torrentId,
'approved' => true,
],
[
'id' => 'DESC'
]
))
{
$torrent->setSensitive(
$torrentSensitive->isValue()
);
$this->entityManagerInterface->persist($torrent);
$this->entityManagerInterface->flush();
}
}
}
public function updateTorrentLocales(
int $torrentId
): void
{
if ($torrent = $this->getTorrent($torrentId))
{
if ($torrentLocales = $this->entityManagerInterface
->getRepository(TorrentLocales::class)
->findOneBy(
[
'torrentId' => $torrentId,
'approved' => true,
],
[
'id' => 'DESC'
]
))
{
$torrent->setLocales($torrentLocales->getValue());
$this->entityManagerInterface->persist($torrent);
$this->entityManagerInterface->flush();
}
}
}
public function setTorrentApprovedByTorrentId(
int $torrentId,
bool $value
): void
{
if ($torrent = $this->getTorrent($torrentId))
{
$torrent->setApproved($value);
$this->entityManagerInterface->persist($torrent);
$this->entityManagerInterface->flush();
}
}
public function setTorrentsApprovedByUserId(
int $userId,
bool $value
@ -355,24 +474,6 @@ class TorrentService @@ -355,24 +474,6 @@ class TorrentService
);
}
public function findLastTorrentLocalesByTorrentIdApproved(
int $torrentId,
bool $approved = true
): ?TorrentLocales
{
return $this->entityManagerInterface
->getRepository(TorrentLocales::class)
->findOneBy(
[
'torrentId' => $torrentId,
'approved' => $approved
],
[
'id' => 'DESC'
]
);
}
public function findTorrentLocalesByTorrentId(int $torrentId): array
{
return $this->entityManagerInterface
@ -400,6 +501,10 @@ class TorrentService @@ -400,6 +501,10 @@ class TorrentService
$this->entityManagerInterface->persist($torrentLocales);
$this->entityManagerInterface->flush();
$this->updateTorrentLocales(
$torrentLocales->getTorrentId()
);
return $torrentLocales;
}
@ -412,6 +517,10 @@ class TorrentService @@ -412,6 +517,10 @@ class TorrentService
$this->entityManagerInterface->remove($torrentLocales);
$this->entityManagerInterface->flush();
$this->updateTorrentLocales(
$torrentLocales->getTorrentId()
);
return $torrentLocales;
}
@ -434,6 +543,10 @@ class TorrentService @@ -434,6 +543,10 @@ class TorrentService
$this->entityManagerInterface->persist($torrentLocales);
$this->entityManagerInterface->flush();
$this->updateTorrentLocales(
$torrentId
);
return $torrentLocales;
}
@ -484,24 +597,6 @@ class TorrentService @@ -484,24 +597,6 @@ class TorrentService
);
}
public function findLastTorrentSensitiveByTorrentIdApproved(
int $torrentId,
bool $approved = true
): ?TorrentSensitive
{
return $this->entityManagerInterface
->getRepository(TorrentSensitive::class)
->findOneBy(
[
'torrentId' => $torrentId,
'approved' => $approved,
],
[
'id' => 'DESC'
]
);
}
public function findTorrentSensitiveByTorrentId(int $torrentId): array
{
return $this->entityManagerInterface
@ -531,6 +626,10 @@ class TorrentService @@ -531,6 +626,10 @@ class TorrentService
$this->entityManagerInterface->persist($torrentSensitive);
$this->entityManagerInterface->flush();
$this->updateTorrentSensitive(
$torrentSensitive->getTorrentId()
);
return $torrentSensitive;
}
@ -545,6 +644,10 @@ class TorrentService @@ -545,6 +644,10 @@ class TorrentService
$this->entityManagerInterface->remove($torrentSensitive);
$this->entityManagerInterface->flush();
$this->updateTorrentSensitive(
$torrentSensitive->getTorrentId()
);
return $torrentSensitive;
}
@ -567,6 +670,10 @@ class TorrentService @@ -567,6 +670,10 @@ class TorrentService
$this->entityManagerInterface->persist($torrentSensitive);
$this->entityManagerInterface->flush();
$this->updateTorrentSensitive(
$torrentId
);
return $torrentSensitive;
}

6
templates/default/user/dashboard.html.twig → templates/default/activity/list.html.twig

@ -26,17 +26,17 @@ @@ -26,17 +26,17 @@
{{ 'Page' | trans | lower }} {{ pagination.page }} / {{ pagination.pages }}
{% if pagination.page > 1 %}
{% if pagination.page == 2 %}
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('user_dashboard') }}">
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('activity_all') }}">
{{ 'Back' | trans | lower }}
</a>
{% else %}
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('user_dashboard', { page : pagination.page - 1 }) }}">
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('activity_all', { page : pagination.page - 1 }) }}">
{{ 'Back' | trans | lower }}
</a>
{% endif %}
{% endif %}
{% if pagination.page < pagination.pages %}
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('user_dashboard', { page : pagination.page + 1 }) }}">
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('activity_all', { page : pagination.page + 1 }) }}">
{{ 'Next' | trans | lower }}
</a>
{% endif %}

2
templates/default/layout.html.twig

@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
<header>
<div class="container">
<div class="row margin-y-16-px text-center">
<a class="logo" href="{{ path('user_dashboard') }}">
<a class="logo" href="{{ path('torrent_recent') }}">
<span>YGG</span>tracker
</a>
{% block header_search %}

6
templates/default/search/module.html.twig

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
<form class="margin-t-16-px" name="search" method="get" action="{{ path('search_index') }}">
<form class="margin-t-16-px" name="search" method="get" action="{{ path('torrent_search') }}">
<input class="min-width-200-px" type="text" name="query" value="{{ query }}" placeholder="{{ 'Keyword, file, hash...' | trans }}" />
{#
<select name="type">
{% if type == 'torrent' %}
<option value="torrent" selected="selected">{{ 'Torrents' | trans }}</option>
@ -12,5 +13,6 @@ @@ -12,5 +13,6 @@
<option value="article">{{ 'Articles' | trans }}</option>
{% endif %}
</select>
<input {% if query %}class="button-green"{% endif %} type="submit" value="{{ 'Search' | trans }}" />
#}
<input {% if query is not null %}class="button-green"{% endif %} type="submit" value="{{ 'Search' | trans }}" />
</form>

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

@ -292,7 +292,7 @@ @@ -292,7 +292,7 @@
<div class="padding-t-16-px text-left">
{% if torrent.locales %}
<div class="padding-y-4-px">
{% for i, locale in torrent.locales.value %}{% if i > 0 %},{% endif %} {{ locale|locale_name(locale)|u.title }}{% endfor %}
{% for i, locale in torrent.locales %}{% if i > 0 %},{% endif %} {{ locale|locale_name(locale)|u.title }}{% endfor %}
</div>
{% endif %}
</div>

4
templates/default/search/torrent.html.twig → templates/default/torrent/list.html.twig

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
{% extends 'default/layout.html.twig' %}
{% block title %}{% if query %}{{ query }}{% else %}{{ 'New' | trans }}{% endif %} - {{ 'Torrents' | trans }} - {{ name }}{% endblock %}
{% block title %}{% if query %}{{ query }}{% else %}{{ 'Recent' | trans }}{% endif %} - {{ 'Torrents' | trans }} - {{ name }}{% endblock %}
{% block main_content %}
{% if torrents %}
{% for torrent in torrents %}
@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
{% if torrent.keywords %}
<div class="margin-b-16-px">
{% for keyword in torrent.keywords %}
<a href="{{ path('search_index', { query : keyword, type : 'torrent' }) }}">
<a href="{{ path('torrent_search', { query : keyword }) }}">
#{{ keyword }}
</a>
{% endfor %}

19
templates/default/user/module.html.twig

@ -1,17 +1,32 @@ @@ -1,17 +1,32 @@
<div class="margin-y-16-px position-fixed margin-l--48-px">
{% if route == 'user_dashboard' %}
{% if route == 'torrent_recent' %}
<span class="padding-8-px display-block cursor-default" title="{{ 'Home' | trans }}">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">
<path d="M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z"/>
</svg>
</span>
{% else %}
<a rel="nofollow" class="padding-8-px display-block text-color-night" href="{{ path('user_dashboard') }}" title="{{ 'Home' | trans }}">
<a rel="nofollow" class="padding-8-px display-block text-color-night" href="{{ path('torrent_recent') }}" title="{{ 'Home' | trans }}">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">
<path d="M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z"/>
</svg>
</a>
{% endif %}
{% if route == 'activity_all' %}
<span class="padding-8-px display-block cursor-default" title="{{ 'Activity' | trans }}">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 3a5 5 0 1 1-4.546 2.914.5.5 0 0 0-.908-.417A6 6 0 1 0 8 2v1z"/>
<path d="M8 4.466V.534a.25.25 0 0 0-.41-.192L5.23 2.308a.25.25 0 0 0 0 .384l2.36 1.966A.25.25 0 0 0 8 4.466z"/>
</svg>
</span>
{% else %}
<a rel="nofollow" class="padding-8-px display-block text-color-night" href="{{ path('activity_all') }}" title="{{ 'Activity' | trans }}">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 3a5 5 0 1 1-4.546 2.914.5.5 0 0 0-.908-.417A6 6 0 1 0 8 2v1z"/>
<path d="M8 4.466V.534a.25.25 0 0 0-.41-.192L5.23 2.308a.25.25 0 0 0 0 .384l2.36 1.966A.25.25 0 0 0 8 4.466z"/>
</svg>
</a>
{% endif %}
{% if route == 'user_info' %}
<span class="padding-8-px display-block cursor-default" title="{{ 'Profile' | trans }}">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">

Loading…
Cancel
Save