friendica/src/Module/Conversation/Channel.php

185 lines
7.1 KiB
PHP
Raw Normal View History

<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
2023-09-02 19:37:20 +00:00
*
*/
namespace Friendica\Module\Conversation;
2023-09-02 21:37:02 +00:00
use Friendica\App;
use Friendica\App\Mode;
use Friendica\Content\BoundariesPager;
use Friendica\Content\Conversation;
use Friendica\Content\Conversation\Entity\Channel as ChannelEntity;
2023-10-05 19:10:20 +00:00
use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory;
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
2023-09-19 14:23:02 +00:00
use Friendica\Content\Conversation\Repository\Channel as ChannelRepository;
use Friendica\Content\Conversation\Factory\Channel as ChannelFactory;
use Friendica\Content\Conversation\Factory\Community as CommunityFactory;
use Friendica\Content\Conversation\Factory\Network as NetworkFactory;
2023-10-05 19:10:20 +00:00
use Friendica\Content\Conversation\Factory\UserDefinedChannel;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Content\Text\HTML;
use Friendica\Content\Widget;
use Friendica\Content\Widget\TrendingTags;
2023-09-02 21:37:02 +00:00
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
2023-09-02 21:37:02 +00:00
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException;
2023-09-02 21:48:55 +00:00
use Friendica\Database\Database;
2023-09-02 21:37:02 +00:00
use Friendica\Module\Response;
2023-09-03 05:23:49 +00:00
use Friendica\Navigation\SystemMessages;
2023-09-02 21:37:02 +00:00
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
class Channel extends Timeline
{
/** @var TimelineFactory */
protected $timeline;
2023-09-02 21:37:02 +00:00
/** @var Conversation */
2023-09-03 03:35:10 +00:00
protected $conversation;
/** @var App\Page */
protected $page;
/** @var SystemMessages */
protected $systemMessages;
/** @var ChannelFactory */
protected $channel;
2023-10-05 19:10:20 +00:00
/** @var UserDefinedChannelFactory */
protected $userDefinedChannel;
/** @var CommunityFactory */
protected $community;
/** @var NetworkFactory */
protected $networkFactory;
2023-10-05 19:10:20 +00:00
public function __construct(UserDefinedChannelFactory $userDefinedChannel, NetworkFactory $network, CommunityFactory $community, ChannelFactory $channelFactory, ChannelRepository $channel, TimelineFactory $timeline, Conversation $conversation, App\Page $page, SystemMessages $systemMessages, Mode $mode, IHandleUserSessions $session, Database $database, IManagePersonalConfigValues $pConfig, IManageConfigValues $config, ICanCache $cache, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
2023-09-02 21:37:02 +00:00
{
2023-09-19 09:05:28 +00:00
parent::__construct($channel, $mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
2023-09-02 21:37:02 +00:00
2023-10-05 19:10:20 +00:00
$this->timeline = $timeline;
$this->conversation = $conversation;
$this->page = $page;
$this->systemMessages = $systemMessages;
$this->channel = $channelFactory;
$this->community = $community;
$this->networkFactory = $network;
$this->userDefinedChannel = $userDefinedChannel;
2023-09-02 21:37:02 +00:00
}
protected function content(array $request = []): string
{
2023-09-02 21:37:02 +00:00
if (!$this->session->getLocalUserId()) {
return Login::form();
}
2023-09-02 19:16:48 +00:00
$this->parseRequest($request);
$t = Renderer::getMarkupTemplate("community.tpl");
$o = Renderer::replaceMacros($t, [
'$content' => '',
2023-09-01 22:36:47 +00:00
'$header' => '',
]);
2023-09-02 21:37:02 +00:00
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
2023-09-02 21:37:02 +00:00
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]);
}
2023-09-02 19:16:48 +00:00
if (empty($request['mode']) || ($request['mode'] != 'raw')) {
2023-10-05 19:10:20 +00:00
$tabs = $this->getTabArray($this->channel->getTimelines($this->session->getLocalUserId()), 'channel');
$tabs = array_merge($tabs, $this->getTabArray($this->userDefinedChannel->getForUser($this->session->getLocalUserId()), 'channel'));
$tabs = array_merge($tabs, $this->getTabArray($this->community->getTimelines(true), 'channel'));
2023-09-03 08:44:17 +00:00
$tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
$o .= Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
Nav::setSelected('channel');
2023-09-09 12:48:51 +00:00
$this->page['aside'] .= Widget::accountTypes('channel/' . $this->selectedTab, $this->accountTypeString);
if (!in_array($this->selectedTab, [ChannelEntity::FOLLOWERS, ChannelEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) {
$this->page['aside'] .= $this->getNoSharerWidget('channel');
}
2023-09-02 21:37:02 +00:00
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
2023-09-09 12:48:51 +00:00
$this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
}
// We need the editor here to be able to reshare an item.
2023-09-02 21:37:02 +00:00
$o .= $this->conversation->statusEditor([], 0, true);
}
2023-10-05 19:10:20 +00:00
if ($this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
$items = $this->getChannelItems();
$order = 'created';
} else {
$items = $this->getCommunityItems();
$order = 'commented';
}
2023-09-02 21:48:55 +00:00
if (!$this->database->isResult($items)) {
2023-09-02 21:37:02 +00:00
$this->systemMessages->addNotice($this->l10n->t('No results.'));
return $o;
}
$o .= $this->conversation->render($items, Conversation::MODE_CHANNEL, false, false, $order, $this->session->getLocalUserId());
$pager = new BoundariesPager(
2023-09-02 21:37:02 +00:00
$this->l10n,
$this->args->getQueryString(),
$items[0][$order],
$items[count($items) - 1][$order],
2023-09-09 12:48:51 +00:00
$this->itemsPerPage
);
2023-09-02 21:37:02 +00:00
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$o .= $pager->renderMinimal(count($items));
}
return $o;
}
/**
* Computes module parameters from the request and local configuration
*
* @throws HTTPException\BadRequestException
* @throws HTTPException\ForbiddenException
*/
2023-09-02 19:16:48 +00:00
protected function parseRequest(array $request)
{
parent::parseRequest($request);
2023-09-09 12:48:51 +00:00
if (!$this->selectedTab) {
$this->selectedTab = ChannelEntity::FORYOU;
}
2023-10-05 19:10:20 +00:00
if (!$this->channel->isTimeline($this->selectedTab) && !$this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) && !$this->community->isTimeline($this->selectedTab)) {
2023-09-02 21:37:02 +00:00
throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
}
2023-09-09 13:02:20 +00:00
$this->maxId = $request['last_created'] ?? $this->maxId;
2023-09-16 04:20:38 +00:00
$this->minId = $request['first_created'] ?? $this->minId;
}
}