[CONTROLLER][FeedController] Make post processing happen more automatically, reducing noise in individual controllers. Now it's enough to simply extends App\Core\Controller\FeedController, to implement a feed
This commit is contained in:
parent
7783922b2e
commit
3b8a3e953d
|
@ -56,12 +56,12 @@ class Search extends FeedController
|
||||||
$actors = $actor_qb->getQuery()->execute();
|
$actors = $actor_qb->getQuery()->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->process_feed([
|
return [
|
||||||
'_template' => 'search/show.html.twig',
|
'_template' => 'search/show.html.twig',
|
||||||
'query' => $q,
|
'query' => $q,
|
||||||
'notes' => $notes,
|
'notes' => $notes,
|
||||||
'actors' => $actors,
|
'actors' => $actors,
|
||||||
'page' => 1, // TODO paginate
|
'page' => 1, // TODO paginate
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,10 @@ class Directory extends FeedController
|
||||||
*/
|
*/
|
||||||
public function actors(Request $request): array
|
public function actors(Request $request): array
|
||||||
{
|
{
|
||||||
return $this->process_feed([
|
return [
|
||||||
'_template' => 'directory/actors.html.twig',
|
'_template' => 'directory/actors.html.twig',
|
||||||
'actors' => DB::dql('select a from actor a order by a.nickname ASC'),
|
'actors' => DB::dql('select a from actor a order by a.nickname ASC'),
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,9 +49,9 @@ class Directory extends FeedController
|
||||||
*/
|
*/
|
||||||
public function groups(Request $request): array
|
public function groups(Request $request): array
|
||||||
{
|
{
|
||||||
return $this->process_feed([
|
return [
|
||||||
'_template' => 'directory/groups.html.twig',
|
'_template' => 'directory/groups.html.twig',
|
||||||
'groups' => DB::dql('select g from group g order by g.nickname ASC'),
|
'groups' => DB::dql('select g from group g order by g.nickname ASC'),
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,11 +175,11 @@ class Favourite extends FeedController
|
||||||
['id' => $id],
|
['id' => $id],
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->process_feed([
|
return [
|
||||||
'_template' => 'feeds/feed.html.twig',
|
'_template' => 'feeds/feed.html.twig',
|
||||||
'page_title' => 'Favourites feed.',
|
'page_title' => 'Favourites feed.',
|
||||||
'notes' => $notes,
|
'notes' => $notes,
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function favouritesByActorNickname(Request $request, string $nickname)
|
public function favouritesByActorNickname(Request $request, string $nickname)
|
||||||
|
@ -208,11 +208,11 @@ class Favourite extends FeedController
|
||||||
['id' => $id],
|
['id' => $id],
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->process_feed([
|
return [
|
||||||
'_template' => 'feeds/feed.html.twig',
|
'_template' => 'feeds/feed.html.twig',
|
||||||
'page_title' => 'Reverse favourites feed.',
|
'page_title' => 'Reverse favourites feed.',
|
||||||
'notes' => $notes,
|
'notes' => $notes,
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reverseFavouritesByActorNickname(Request $request, string $nickname)
|
public function reverseFavouritesByActorNickname(Request $request, string $nickname)
|
||||||
|
|
|
@ -55,11 +55,11 @@ class Feeds extends FeedController
|
||||||
public function public(Request $request)
|
public function public(Request $request)
|
||||||
{
|
{
|
||||||
$notes = Note::getAllNotes($this->instance_scope);
|
$notes = Note::getAllNotes($this->instance_scope);
|
||||||
return $this->process_feed([
|
return [
|
||||||
'_template' => 'feeds/feed.html.twig',
|
'_template' => 'feeds/feed.html.twig',
|
||||||
'page_title' => 'Public feed',
|
'page_title' => 'Public feed',
|
||||||
'notes' => $notes,
|
'notes' => $notes,
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function home(Request $request, string $nickname)
|
public function home(Request $request, string $nickname)
|
||||||
|
@ -97,20 +97,20 @@ class Feeds extends FeedController
|
||||||
END;
|
END;
|
||||||
$notes = DB::sql($query, ['target_actor_id' => $target->getId()]);
|
$notes = DB::sql($query, ['target_actor_id' => $target->getId()]);
|
||||||
|
|
||||||
return $this->process_feed([
|
return [
|
||||||
'_template' => 'feeds/feed.html.twig',
|
'_template' => 'feeds/feed.html.twig',
|
||||||
'page_title' => 'Home feed',
|
'page_title' => 'Home feed',
|
||||||
'notes' => $notes,
|
'notes' => $notes,
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function network(Request $request)
|
public function network(Request $request)
|
||||||
{
|
{
|
||||||
$notes = Note::getAllNotes($this->public_scope);
|
$notes = Note::getAllNotes($this->public_scope);
|
||||||
return $this->process_feed([
|
return [
|
||||||
'_template' => 'feeds/feed.html.twig',
|
'_template' => 'feeds/feed.html.twig',
|
||||||
'page_title' => 'Network feed',
|
'page_title' => 'Network feed',
|
||||||
'notes' => $notes,
|
'notes' => $notes,
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Core;
|
namespace App\Core;
|
||||||
|
|
||||||
|
use App\Core\Controller\FeedController;
|
||||||
use function App\Core\I18n\_m;
|
use function App\Core\I18n\_m;
|
||||||
use App\Util\Common;
|
use App\Util\Common;
|
||||||
use App\Util\Exception\ClientException;
|
use App\Util\Exception\ClientException;
|
||||||
|
@ -130,6 +131,15 @@ abstract class Controller extends AbstractController implements EventSubscriberI
|
||||||
Event::handle('OverrideTemplate', [$this->vars, &$template]); // Allow plugins to replace the template used for anything
|
Event::handle('OverrideTemplate', [$this->vars, &$template]); // Allow plugins to replace the template used for anything
|
||||||
unset($this->vars['_template'], $response['_template']);
|
unset($this->vars['_template'], $response['_template']);
|
||||||
|
|
||||||
|
$controller = $request->get('_controller');
|
||||||
|
if (\is_array($controller)) {
|
||||||
|
$controller = $controller[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_subclass_of($controller, FeedController::class)) {
|
||||||
|
$this->vars = FeedController::post_process($this->vars);
|
||||||
|
}
|
||||||
|
|
||||||
// Respond in the most preferred acceptable content type
|
// Respond in the most preferred acceptable content type
|
||||||
$route = $request->get('_route');
|
$route = $request->get('_route');
|
||||||
$accept = $request->getAcceptableContentTypes() ?: ['text/html'];
|
$accept = $request->getAcceptableContentTypes() ?: ['text/html'];
|
||||||
|
|
|
@ -38,7 +38,7 @@ use App\Util\Common;
|
||||||
|
|
||||||
abstract class FeedController extends Controller
|
abstract class FeedController extends Controller
|
||||||
{
|
{
|
||||||
protected function process_feed(array $result)
|
public static function post_process(array $result)
|
||||||
{
|
{
|
||||||
$actor = Common::actor();
|
$actor = Common::actor();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user