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. 164
      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. 207
      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 @@
.container { .container {
position: relative; position: relative;
overflow: hidden; overflow: hidden;
max-width: 732px; max-width: 748px;
margin: 0 auto; margin: 0 auto;
} }

75
src/Controller/ActivityController.php

@ -15,6 +15,50 @@ use App\Service\TorrentService;
class ActivityController extends AbstractController 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( public function event(
$activity, $activity,
ActivityService $activityService, ActivityService $activityService,
@ -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;
}
} }

164
src/Controller/SearchController.php

@ -9,175 +9,21 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use App\Service\UserService; use App\Service\UserService;
use App\Service\ArticleService;
use App\Service\TorrentService;
use App\Service\ActivityService; use App\Service\ActivityService;
class SearchController extends AbstractController 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( public function module(
?string $query, ?string $query,
?string $type ?string $type
): Response ): Response
{ {
return $this->render('default/search/module.html.twig', [ return $this->render(
'default/search/module.html.twig',
[
'query' => $query, 'query' => $query,
'type' => $type, ]
]); );
} }
private function initUser( private function initUser(

300
src/Controller/TorrentController.php

@ -57,27 +57,11 @@ class TorrentController extends AbstractController
// Get contributors // Get contributors
$contributors = []; $contributors = [];
foreach ($torrentService->getTorrentContributors($torrent) as $userId)
$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()))
{ {
$contributors[$torrentSensitive->getUserId()] = $userService->identicon( $contributors[$userId] = $userService->identicon(
$userService->getUser( $userService->getUser(
$torrentSensitive->getUserId() $userId
)->getAddress() )->getAddress()
); );
} }
@ -98,25 +82,14 @@ class TorrentController extends AbstractController
'id' => $torrent->getId(), 'id' => $torrent->getId(),
'md5file' => $torrent->getMd5File(), 'md5file' => $torrent->getMd5File(),
'added' => $torrent->getAdded(), 'added' => $torrent->getAdded(),
/*
'user' =>
[
'id' => $torrent->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$torrent->getUserId()
)->getAddress()
),
],
*/
'scrape' => 'scrape' =>
[ [
'seeders' => (int) $torrent->getSeeders(), 'seeders' => (int) $torrent->getSeeders(),
'peers' => (int) $torrent->getPeers(), 'peers' => (int) $torrent->getPeers(),
'leechers' => (int) $torrent->getLeechers(), 'leechers' => (int) $torrent->getLeechers(),
], ],
'locales' => $torrentService->findLastTorrentLocalesByTorrentId($torrent->getId()), 'locales' => $torrent->getLocales(),
'sensitive' => $torrentService->findLastTorrentSensitiveByTorrentId($torrent->getId())->isValue(), 'sensitive' => $torrent->isSensitive(),
'download' => 'download' =>
[ [
'file' => 'file' =>
@ -172,8 +145,6 @@ class TorrentController extends AbstractController
'v1' => $file->getInfoHashV1(false), 'v1' => $file->getInfoHashV1(false),
'v2' => $file->getInfoHashV2(false) 'v2' => $file->getInfoHashV2(false)
], ],
// @TODO use download action to filter announcement URL
// 'magnet' => $file->getMagnetLink()
], ],
'trackers' => explode('|', $this->getParameter('app.trackers')), 'trackers' => explode('|', $this->getParameter('app.trackers')),
'activities' => $activityService->findLastActivitiesByTorrentId( 'activities' => $activityService->findLastActivitiesByTorrentId(
@ -192,7 +163,263 @@ class TorrentController extends AbstractController
} }
#[Route( #[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', name: 'torrent_submit',
methods: methods:
[ [
@ -310,6 +537,7 @@ class TorrentController extends AbstractController
$user->isApproved() $user->isApproved()
); );
// Add activity event
$activityService->addEventTorrentAdd( $activityService->addEventTorrentAdd(
$user->getId(), $user->getId(),
time(), time(),
@ -765,7 +993,7 @@ class TorrentController extends AbstractController
} }
else else
{ {
if ($torrentSensitive = $torrentService->findLastTorrentSensitiveByTorrentId($request->get('torrentId'))) if ($torrentSensitive = $torrentService->findLastTorrentSensitiveByTorrentId($torrent->getId()))
{ {
$torrentSensitiveCurrent = $torrentSensitiveCurrent =
[ [

46
src/Controller/UserController.php

@ -31,57 +31,13 @@ class UserController extends AbstractController
); );
return $this->redirectToRoute( return $this->redirectToRoute(
'user_dashboard', 'torrent_recent',
[ [
'_locale' => $user->getLocale() '_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( #[Route(
'/{_locale}/settings', '/{_locale}/settings',
name: 'user_settings', name: 'user_settings',

39
src/Entity/Torrent.php

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

2
src/Entity/TorrentLocales.php

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

4
src/Entity/User.php

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

92
src/Repository/TorrentRepository.php

@ -21,20 +21,94 @@ class TorrentRepository extends ServiceEntityRepository
parent::__construct($registry, Torrent::class); parent::__construct($registry, Torrent::class);
} }
public function searchByKeywords( public function findTorrentsTotal(
array $keywords array $keywords,
): ?array 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'); $query = $this->createQueryBuilder('t');
foreach ($keywords as $keyword) if ($keywords) // @TODO ANY or DTS
{
$orX = $query->expr()->orX();
foreach ($keywords as $i => $keyword)
{ {
$query->orWhere('t.keywords LIKE :query') $orX->add("t.keywords LIKE :keyword{$i}");
->setParameter('query', "%{$keyword}%"); $query->setParameter(":keyword{$i}", "%{$keyword}%");
} }
return $query->orderBy('t.id', 'ASC') // same as t.added $query->andWhere($orX);
->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;
} }
} }

207
src/Service/TorrentService.php

@ -150,7 +150,7 @@ class TorrentService
public function generateTorrentKeywordsByTorrentFilepath( public function generateTorrentKeywordsByTorrentFilepath(
string $filepath, string $filepath,
int $minLength = 3 int $minLength = 3
): string ): array
{ {
$keywords = []; $keywords = [];
@ -175,17 +175,17 @@ class TorrentService
{ {
unset($words[$key]); unset($words[$key]);
} }
else
{
$words[$key] = mb_strtolower($value);
}
} }
$keywords = array_merge($keywords, $words); $keywords = array_merge($keywords, $words);
} }
return mb_strtolower( return array_unique($keywords);
implode(
',',
array_unique($keywords)
)
);
} }
public function getStorageFilepathById(int $id): string public function getStorageFilepathById(int $id): string
@ -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( public function add(
string $filepath, string $filepath,
int $userId, int $userId,
@ -213,6 +232,8 @@ class TorrentService
$this->generateTorrentKeywordsByTorrentFilepath( $this->generateTorrentKeywordsByTorrentFilepath(
$filepath $filepath
), ),
$locales,
$sensitive,
$approved $approved
); );
@ -224,8 +245,6 @@ class TorrentService
) )
); );
if (!empty($locales))
{
$this->addTorrentLocales( $this->addTorrentLocales(
$torrent->getId(), $torrent->getId(),
$userId, $userId,
@ -233,7 +252,6 @@ class TorrentService
$locales, $locales,
$approved $approved
); );
}
$this->addTorrentSensitive( $this->addTorrentSensitive(
$torrent->getId(), $torrent->getId(),
@ -258,7 +276,9 @@ class TorrentService
int $userId, int $userId,
int $added, int $added,
string $md5file, string $md5file,
string $keywords, array $keywords,
array $locales,
bool $sensitive,
bool $approved bool $approved
): ?Torrent ): ?Torrent
{ {
@ -268,6 +288,8 @@ class TorrentService
$torrent->setAdded($added); $torrent->setAdded($added);
$torrent->setMd5File($md5file); $torrent->setMd5File($md5file);
$torrent->setKeywords($keywords); $torrent->setKeywords($keywords);
$torrent->setLocales($locales);
$torrent->setSensitive($sensitive);
$torrent->setApproved($approved); $torrent->setApproved($approved);
$this->entityManagerInterface->persist($torrent); $this->entityManagerInterface->persist($torrent);
@ -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 return $this->entityManagerInterface
->getRepository(Torrent::class) ->getRepository(Torrent::class)
->searchByKeywords( ->findTorrents(
explode(' ', $query) $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
); );
} }
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( public function setTorrentsApprovedByUserId(
int $userId, int $userId,
bool $value bool $value
@ -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 public function findTorrentLocalesByTorrentId(int $torrentId): array
{ {
return $this->entityManagerInterface return $this->entityManagerInterface
@ -400,6 +501,10 @@ class TorrentService
$this->entityManagerInterface->persist($torrentLocales); $this->entityManagerInterface->persist($torrentLocales);
$this->entityManagerInterface->flush(); $this->entityManagerInterface->flush();
$this->updateTorrentLocales(
$torrentLocales->getTorrentId()
);
return $torrentLocales; return $torrentLocales;
} }
@ -412,6 +517,10 @@ class TorrentService
$this->entityManagerInterface->remove($torrentLocales); $this->entityManagerInterface->remove($torrentLocales);
$this->entityManagerInterface->flush(); $this->entityManagerInterface->flush();
$this->updateTorrentLocales(
$torrentLocales->getTorrentId()
);
return $torrentLocales; return $torrentLocales;
} }
@ -434,6 +543,10 @@ class TorrentService
$this->entityManagerInterface->persist($torrentLocales); $this->entityManagerInterface->persist($torrentLocales);
$this->entityManagerInterface->flush(); $this->entityManagerInterface->flush();
$this->updateTorrentLocales(
$torrentId
);
return $torrentLocales; return $torrentLocales;
} }
@ -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 public function findTorrentSensitiveByTorrentId(int $torrentId): array
{ {
return $this->entityManagerInterface return $this->entityManagerInterface
@ -531,6 +626,10 @@ class TorrentService
$this->entityManagerInterface->persist($torrentSensitive); $this->entityManagerInterface->persist($torrentSensitive);
$this->entityManagerInterface->flush(); $this->entityManagerInterface->flush();
$this->updateTorrentSensitive(
$torrentSensitive->getTorrentId()
);
return $torrentSensitive; return $torrentSensitive;
} }
@ -545,6 +644,10 @@ class TorrentService
$this->entityManagerInterface->remove($torrentSensitive); $this->entityManagerInterface->remove($torrentSensitive);
$this->entityManagerInterface->flush(); $this->entityManagerInterface->flush();
$this->updateTorrentSensitive(
$torrentSensitive->getTorrentId()
);
return $torrentSensitive; return $torrentSensitive;
} }
@ -567,6 +670,10 @@ class TorrentService
$this->entityManagerInterface->persist($torrentSensitive); $this->entityManagerInterface->persist($torrentSensitive);
$this->entityManagerInterface->flush(); $this->entityManagerInterface->flush();
$this->updateTorrentSensitive(
$torrentId
);
return $torrentSensitive; return $torrentSensitive;
} }

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

@ -26,17 +26,17 @@
{{ 'Page' | trans | lower }} {{ pagination.page }} / {{ pagination.pages }} {{ 'Page' | trans | lower }} {{ pagination.page }} / {{ pagination.pages }}
{% if pagination.page > 1 %} {% if pagination.page > 1 %}
{% if pagination.page == 2 %} {% 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 }} {{ 'Back' | trans | lower }}
</a> </a>
{% else %} {% 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 }} {{ 'Back' | trans | lower }}
</a> </a>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if pagination.page < pagination.pages %} {% 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 }} {{ 'Next' | trans | lower }}
</a> </a>
{% endif %} {% endif %}

2
templates/default/layout.html.twig

@ -13,7 +13,7 @@
<header> <header>
<div class="container"> <div class="container">
<div class="row margin-y-16-px text-center"> <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 <span>YGG</span>tracker
</a> </a>
{% block header_search %} {% block header_search %}

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

@ -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 }}" /> <input class="min-width-200-px" type="text" name="query" value="{{ query }}" placeholder="{{ 'Keyword, file, hash...' | trans }}" />
{#
<select name="type"> <select name="type">
{% if type == 'torrent' %} {% if type == 'torrent' %}
<option value="torrent" selected="selected">{{ 'Torrents' | trans }}</option> <option value="torrent" selected="selected">{{ 'Torrents' | trans }}</option>
@ -12,5 +13,6 @@
<option value="article">{{ 'Articles' | trans }}</option> <option value="article">{{ 'Articles' | trans }}</option>
{% endif %} {% endif %}
</select> </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> </form>

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

@ -292,7 +292,7 @@
<div class="padding-t-16-px text-left"> <div class="padding-t-16-px text-left">
{% if torrent.locales %} {% if torrent.locales %}
<div class="padding-y-4-px"> <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> </div>
{% endif %} {% endif %}
</div> </div>

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

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

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

@ -1,17 +1,32 @@
<div class="margin-y-16-px position-fixed margin-l--48-px"> <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 }}"> <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"> <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"/> <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> </svg>
</span> </span>
{% else %} {% 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"> <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"/> <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> </svg>
</a> </a>
{% endif %} {% 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' %} {% if route == 'user_info' %}
<span class="padding-8-px display-block cursor-default" title="{{ 'Profile' | trans }}"> <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"> <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">

Loading…
Cancel
Save