mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-03-10 04:21:06 +00:00
implement recent uploads RSS
This commit is contained in:
parent
7c28eaadd2
commit
643d643f46
@ -460,6 +460,87 @@ class TorrentController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/{_locale}/rss/torrents',
|
||||
name: 'rss_torrents_recent',
|
||||
defaults: [
|
||||
'_locale' => '%app.locale%'
|
||||
],
|
||||
requirements: [
|
||||
'_locale' => '%app.locales%'
|
||||
],
|
||||
methods:
|
||||
[
|
||||
'GET'
|
||||
]
|
||||
)]
|
||||
public function rssRecent(
|
||||
Request $request,
|
||||
UserService $userService,
|
||||
TorrentService $torrentService,
|
||||
ActivityService $activityService
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
// Get total torrents
|
||||
$total = $torrentService->findTorrentsTotal(
|
||||
[],
|
||||
$user->getLocales(),
|
||||
!$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
|
||||
!$user->isModerator() ? true : null // show approved content only for regular users
|
||||
);
|
||||
|
||||
// Create torrents list
|
||||
$torrents = [];
|
||||
foreach ($torrentService->findTorrents(
|
||||
[],
|
||||
$user->getLocales(),
|
||||
!$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
|
||||
!$user->isModerator() ? true : null, // show approved content only for regular users
|
||||
$this->getParameter('app.pagination'),
|
||||
0
|
||||
) as $torrent)
|
||||
{
|
||||
// Read file
|
||||
if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId()))
|
||||
{
|
||||
throw $this->createNotFoundException(); // @TODO exception
|
||||
}
|
||||
|
||||
$torrents[] =
|
||||
[
|
||||
'id' => $torrent->getId(),
|
||||
'added' => $torrent->getAdded(),
|
||||
'file' =>
|
||||
[
|
||||
'name' => $file->getName(),
|
||||
],
|
||||
'user' =>
|
||||
[
|
||||
'id' => $torrent->getUserId(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$response = new Response();
|
||||
$response->headers->set('Content-Type', 'text/xml');
|
||||
|
||||
return $this->render(
|
||||
'default/torrent/list.rss.twig',
|
||||
[
|
||||
'query' => $request->query->get('query'),
|
||||
'torrents' => $torrents
|
||||
],
|
||||
$response
|
||||
);
|
||||
}
|
||||
|
||||
// Forms
|
||||
#[Route(
|
||||
'/{_locale}/submit',
|
||||
|
@ -2,6 +2,6 @@
|
||||
<title>{{ 'undefined event' | trans }} {{ 'by' | trans }} #{{ user.id }}</title>
|
||||
<author>#{{ user.id }}</author>
|
||||
<pubDate>{{ added | date('D, d M Y h:i:s O') }}</pubDate>
|
||||
<guid>{{ path('user_info', { userId : user.id }) }}#activity-{{ id }}</guid>
|
||||
<link>{{ path('user_info', { userId : user.id }) }}#activity</link>
|
||||
<guid>{{ url('user_info', { userId : user.id }) }}#activity-{{ id }}</guid>
|
||||
<link>{{ url('user_info', { userId : user.id }) }}#activity</link>
|
||||
</item>
|
@ -2,7 +2,7 @@
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<channel>
|
||||
<atom:link href="{{ url('torrent_recent') }}" rel="self" type="application/rss+xml"></atom:link>
|
||||
<title>{{ name }}</title>
|
||||
<title>{{ name }} - {{ 'Activity' | trans }}</title>
|
||||
<link>{{ url('torrent_recent') }}</link>
|
||||
{% for activity in activities %}
|
||||
{{ render(controller(
|
||||
|
@ -4,7 +4,7 @@
|
||||
<div class="text-right">
|
||||
<h2>{{ 'Recent uploads' | trans }}</h2>
|
||||
<sub>
|
||||
<a class="text-color-night margin-x-4-px" href="{{ path('rss_activity') }}" title="RSS">
|
||||
<a class="text-color-night margin-x-4-px" href="{{ path('rss_torrents_recent') }}" title="RSS">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm1.5 2.5c5.523 0 10 4.477 10 10a1 1 0 1 1-2 0 8 8 0 0 0-8-8 1 1 0 0 1 0-2zm0 4a6 6 0 0 1 6 6 1 1 0 1 1-2 0 4 4 0 0 0-4-4 1 1 0 0 1 0-2zm.5 7a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3z"/>
|
||||
</svg>
|
||||
|
17
templates/default/torrent/list.rss.twig
Normal file
17
templates/default/torrent/list.rss.twig
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<channel>
|
||||
<atom:link href="{{ url('torrent_recent') }}" rel="self" type="application/rss+xml"></atom:link>
|
||||
<title>{{ name }} - {{ 'Torrents' | trans }}</title>
|
||||
<link>{{ url('torrent_recent') }}</link>
|
||||
{% for torrent in torrents %}
|
||||
<item>
|
||||
<title>{{ torrent.file.name }}</title>
|
||||
<author>#{{ torrent.user.id }}</author>
|
||||
<pubDate>{{ torrent.added | date('D, d M Y h:i:s O') }}</pubDate>
|
||||
<guid>{{ url('torrent_info', { torrentId : torrent.id }) }}</guid>
|
||||
<link>{{ url('torrent_info', { torrentId : torrent.id }) }}</link>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</channel>
|
||||
</rss>
|
Loading…
x
Reference in New Issue
Block a user