2023-09-01 21:56:59 +00:00
|
|
|
<?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
|
|
|
*
|
2023-09-01 21:56:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Module\Conversation;
|
|
|
|
|
2023-09-02 21:37:02 +00:00
|
|
|
use Friendica\App;
|
|
|
|
use Friendica\App\Mode;
|
2023-09-01 21:56:59 +00:00
|
|
|
use Friendica\Content\BoundariesPager;
|
|
|
|
use Friendica\Content\Conversation;
|
2023-10-05 05:36:12 +00:00
|
|
|
use Friendica\Content\Conversation\Entity\Channel as ChannelEntity;
|
2023-10-05 19:10:20 +00:00
|
|
|
use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory;
|
2023-09-09 09:14:36 +00:00
|
|
|
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
|
2023-09-19 14:23:02 +00:00
|
|
|
use Friendica\Content\Conversation\Repository\Channel as ChannelRepository;
|
2023-10-05 05:36:12 +00:00
|
|
|
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;
|
2023-09-01 21:56:59 +00:00
|
|
|
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;
|
2023-09-01 21:56:59 +00:00
|
|
|
use Friendica\Core\Renderer;
|
2023-09-02 21:37:02 +00:00
|
|
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
2023-09-01 21:56:59 +00:00
|
|
|
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;
|
2023-09-01 21:56:59 +00:00
|
|
|
|
2023-09-09 09:14:36 +00:00
|
|
|
class Channel extends Timeline
|
2023-09-01 21:56:59 +00:00
|
|
|
{
|
2023-09-09 09:14:36 +00:00
|
|
|
/** @var TimelineFactory */
|
|
|
|
protected $timeline;
|
2023-09-02 21:37:02 +00:00
|
|
|
/** @var Conversation */
|
2023-09-03 03:35:10 +00:00
|
|
|
protected $conversation;
|
2023-09-09 09:14:36 +00:00
|
|
|
/** @var App\Page */
|
|
|
|
protected $page;
|
|
|
|
/** @var SystemMessages */
|
|
|
|
protected $systemMessages;
|
2023-10-05 05:36:12 +00:00
|
|
|
/** @var ChannelFactory */
|
|
|
|
protected $channel;
|
2023-10-05 19:10:20 +00:00
|
|
|
/** @var UserDefinedChannelFactory */
|
|
|
|
protected $userDefinedChannel;
|
2023-10-05 05:36:12 +00:00
|
|
|
/** @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
|
|
|
}
|
|
|
|
|
2023-09-01 21:56:59 +00:00
|
|
|
protected function content(array $request = []): string
|
|
|
|
{
|
2023-09-02 21:37:02 +00:00
|
|
|
if (!$this->session->getLocalUserId()) {
|
2023-09-01 21:56:59 +00:00
|
|
|
return Login::form();
|
|
|
|
}
|
|
|
|
|
2023-09-02 19:16:48 +00:00
|
|
|
$this->parseRequest($request);
|
2023-09-01 21:56:59 +00:00
|
|
|
|
|
|
|
$t = Renderer::getMarkupTemplate("community.tpl");
|
|
|
|
$o = Renderer::replaceMacros($t, [
|
|
|
|
'$content' => '',
|
2023-09-01 22:36:47 +00:00
|
|
|
'$header' => '',
|
2023-09-01 21:56:59 +00:00
|
|
|
]);
|
|
|
|
|
2023-09-02 21:37:02 +00:00
|
|
|
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
|
2023-09-01 21:56:59 +00:00
|
|
|
$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-01 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
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'));
|
2023-10-05 05:36:12 +00:00
|
|
|
$tabs = array_merge($tabs, $this->getTabArray($this->community->getTimelines(true), 'channel'));
|
2023-09-03 08:44:17 +00:00
|
|
|
|
2023-09-01 21:56:59 +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);
|
2023-09-01 21:56:59 +00:00
|
|
|
|
2023-10-05 05:36:12 +00:00
|
|
|
if (!in_array($this->selectedTab, [ChannelEntity::FOLLOWERS, ChannelEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) {
|
2023-09-09 09:14:36 +00:00
|
|
|
$this->page['aside'] .= $this->getNoSharerWidget('channel');
|
2023-09-01 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2023-09-01 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-09-01 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
2023-10-05 19:10:20 +00:00
|
|
|
if ($this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
2023-09-09 09:14:36 +00:00
|
|
|
$items = $this->getChannelItems();
|
|
|
|
$order = 'created';
|
|
|
|
} else {
|
|
|
|
$items = $this->getCommunityItems();
|
|
|
|
$order = 'commented';
|
|
|
|
}
|
2023-09-01 21:56:59 +00:00
|
|
|
|
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.'));
|
2023-09-01 21:56:59 +00:00
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
2023-09-09 09:14:36 +00:00
|
|
|
$o .= $this->conversation->render($items, Conversation::MODE_CHANNEL, false, false, $order, $this->session->getLocalUserId());
|
2023-09-01 21:56:59 +00:00
|
|
|
|
|
|
|
$pager = new BoundariesPager(
|
2023-09-02 21:37:02 +00:00
|
|
|
$this->l10n,
|
|
|
|
$this->args->getQueryString(),
|
2023-09-09 09:14:36 +00:00
|
|
|
$items[0][$order],
|
|
|
|
$items[count($items) - 1][$order],
|
2023-09-09 12:48:51 +00:00
|
|
|
$this->itemsPerPage
|
2023-09-01 21:56:59 +00:00
|
|
|
);
|
|
|
|
|
2023-09-02 21:37:02 +00:00
|
|
|
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
|
2023-09-01 21:56:59 +00:00
|
|
|
$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)
|
2023-09-01 21:56:59 +00:00
|
|
|
{
|
2023-09-09 09:14:36 +00:00
|
|
|
parent::parseRequest($request);
|
2023-09-01 21:56:59 +00:00
|
|
|
|
2023-09-09 12:48:51 +00:00
|
|
|
if (!$this->selectedTab) {
|
2023-10-05 05:36:12 +00:00
|
|
|
$this->selectedTab = ChannelEntity::FORYOU;
|
2023-09-01 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
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-01 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2023-09-02 12:47:48 +00:00
|
|
|
}
|
2023-09-01 21:56:59 +00:00
|
|
|
}
|