2021-12-21 17:30:44 +00:00
|
|
|
<?php
|
|
|
|
|
2021-12-23 18:12:49 +00:00
|
|
|
declare(strict_types = 1);
|
2021-12-21 17:30:44 +00:00
|
|
|
|
|
|
|
// {{{ License
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// }}}
|
2021-12-22 12:22:10 +00:00
|
|
|
/**
|
|
|
|
* Media Feed Plugin for GNU social
|
|
|
|
*
|
|
|
|
* @package GNUsocial
|
|
|
|
* @category Plugin
|
2021-12-23 18:12:49 +00:00
|
|
|
*
|
2021-12-22 12:22:10 +00:00
|
|
|
* @author Phablulo <phablulo@gmail.com>
|
|
|
|
* @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
|
|
|
|
*/
|
2021-12-21 17:30:44 +00:00
|
|
|
|
|
|
|
namespace Plugin\MediaFeed;
|
|
|
|
|
|
|
|
use App\Core\Event;
|
2021-12-23 18:12:49 +00:00
|
|
|
use App\Core\Modules\Plugin;
|
2021-12-21 17:30:44 +00:00
|
|
|
use App\Entity\Actor;
|
2021-12-23 18:12:49 +00:00
|
|
|
use App\Entity\Note;
|
2021-12-21 17:30:44 +00:00
|
|
|
use App\Util\Formatting;
|
2021-12-23 18:12:49 +00:00
|
|
|
use Functional as F;
|
2021-12-21 17:30:44 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-12-23 18:12:49 +00:00
|
|
|
|
2021-12-21 17:30:44 +00:00
|
|
|
/**
|
|
|
|
* Draw the media feed navigation.
|
2021-12-23 18:12:49 +00:00
|
|
|
*
|
|
|
|
* @return bool hook value; true means continue processing, false means stop
|
2021-12-21 17:30:44 +00:00
|
|
|
*/
|
|
|
|
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.
|
2021-12-23 18:12:49 +00:00
|
|
|
$query = mb_strpos($request->getRequestUri(), '?');
|
2021-12-21 17:30:44 +00:00
|
|
|
$mediaURL = $request->getRequestUri() . ($query !== false ? '&' : '?') . 'filter-type=media';
|
|
|
|
$allURL = $request->getPathInfo();
|
|
|
|
if ($query !== false) {
|
2021-12-23 18:12:49 +00:00
|
|
|
$params = explode('&', mb_substr($request->getRequestUri(), $query + 1));
|
|
|
|
$params = array_filter($params, fn ($s) => $s !== 'filter-type=media');
|
|
|
|
$params = implode('&', $params);
|
2021-12-21 17:30:44 +00:00
|
|
|
if ($params) {
|
|
|
|
$allURL .= '?' . $params;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-23 18:12:49 +00:00
|
|
|
$res[] = Formatting::twigRenderFile('mediaFeed/tabs.html.twig', [
|
2021-12-21 17:30:44 +00:00
|
|
|
'main' => [
|
|
|
|
'active' => !$isMediaActive,
|
2021-12-23 18:12:49 +00:00
|
|
|
'url' => $isMediaActive ? $allURL : '',
|
2021-12-21 17:30:44 +00:00
|
|
|
],
|
|
|
|
'media' => [
|
|
|
|
'active' => $isMediaActive,
|
2021-12-23 18:12:49 +00:00
|
|
|
'url' => $isMediaActive ? '' : $mediaURL,
|
|
|
|
],
|
2021-12-21 17:30:44 +00:00
|
|
|
]);
|
|
|
|
return Event::next;
|
|
|
|
}
|
2021-12-23 18:12:49 +00:00
|
|
|
|
2021-12-21 17:30:44 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|