. // }}} /** * Media Feed Plugin for GNU social * * @package GNUsocial * @category Plugin * * @author Phablulo * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace Plugin\MediaFeed; use App\Core\Event; use App\Core\Modules\Plugin; use App\Entity\Actor; use App\Entity\Note; use App\Util\Formatting; use Functional as F; use Symfony\Component\HttpFoundation\Request; class MediaFeed extends Plugin { public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): bool { if ($request->get('filter-type') === 'media') { $notes = F\select($notes, fn (Note $n) => \count($n->getAttachments()) > 0); } return Event::next; } /** * Draw the media feed navigation. * * @return bool hook value; true means continue processing, false means stop */ public function onBeforeFeed(Request $request, &$res): bool { $isMediaActive = $request->get('filter-type') === 'media'; // we need two urls: one with filter-type=media and without it. $query = mb_strpos($request->getRequestUri(), '?'); $mediaURL = $request->getRequestUri() . ($query !== false ? '&' : '?') . 'filter-type=media'; $allURL = $request->getPathInfo(); if ($query !== false) { $params = explode('&', mb_substr($request->getRequestUri(), $query + 1)); $params = array_filter($params, fn ($s) => $s !== 'filter-type=media'); $params = implode('&', $params); if ($params) { $allURL .= '?' . $params; } } $res[] = Formatting::twigRenderFile('mediaFeed/tabs.html.twig', [ 'main' => [ 'active' => !$isMediaActive, 'url' => $isMediaActive ? $allURL : '', ], 'media' => [ 'active' => $isMediaActive, 'url' => $isMediaActive ? '' : $mediaURL, ], ]); return Event::next; } /** * Output our dedicated stylesheet * * @param array $styles stylesheets path * * @return bool hook value; true means continue processing, false means stop */ public function onEndShowStyles(array &$styles, string $route): bool { $styles[] = 'plugins/MediaFeed/assets/css/mediaFeed.css'; return Event::next; } }