3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 * See update_profile.php for documentation
23 namespace Friendica\Module\Conversation;
26 use Friendica\App\Mode;
27 use Friendica\Content\BoundariesPager;
28 use Friendica\Content\Conversation;
29 use Friendica\Content\Conversation\Entity\Community as CommunityEntity;
30 use Friendica\Content\Conversation\Factory\Community as CommunityFactory;
31 use Friendica\Content\Conversation\Repository\Channel;
32 use Friendica\Content\Feature;
33 use Friendica\Content\Nav;
34 use Friendica\Content\Text\HTML;
35 use Friendica\Content\Widget;
36 use Friendica\Content\Widget\TrendingTags;
37 use Friendica\Core\Cache\Capability\ICanCache;
38 use Friendica\Core\Config\Capability\IManageConfigValues;
39 use Friendica\Core\L10n;
40 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
41 use Friendica\Core\Renderer;
42 use Friendica\Core\Session\Capability\IHandleUserSessions;
43 use Friendica\Network\HTTPException;
44 use Friendica\Database\Database;
45 use Friendica\Module\Response;
46 use Friendica\Navigation\SystemMessages;
47 use Friendica\Util\Profiler;
48 use Psr\Log\LoggerInterface;
50 class Community extends Timeline
53 * Type of the community page
57 const DISABLED_VISITOR = -1;
60 const LOCAL_AND_GLOBAL = 2;
64 /** @var CommunityFactory */
66 /** @var Conversation */
67 protected $conversation;
70 /** @var SystemMessages */
71 protected $systemMessages;
73 public function __construct(Channel $channel, CommunityFactory $community, 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 = [])
75 parent::__construct($channel, $mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
77 $this->community = $community;
78 $this->conversation = $conversation;
80 $this->systemMessages = $systemMessages;
83 protected function content(array $request = []): string
85 $this->parseRequest($request);
87 $t = Renderer::getMarkupTemplate("community.tpl");
88 $o = Renderer::replaceMacros($t, [
91 '$show_global_community_hint' => ($this->selectedTab == CommunityEntity::GLOBAL) && $this->config->get('system', 'show_global_community_hint'),
92 '$global_community_hint' => $this->l10n->t("This community stream shows all public posts received by this node. They may not reflect the opinions of this node’s users.")
95 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
96 $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
97 $o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]);
100 if (empty($request['mode']) || ($request['mode'] != 'raw')) {
101 $tabs = $this->getTabArray($this->community->getTimelines($this->session->isAuthenticated()), 'community');
102 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
103 $o .= Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
105 Nav::setSelected('community');
107 $this->page['aside'] .= Widget::accountTypes('community/' . $this->selectedTab, $this->accountTypeString);
109 if ($this->session->getLocalUserId() && $this->config->get('system', 'community_no_sharer')) {
110 $this->page['aside'] .= $this->getNoSharerWidget('community');
113 if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
114 $this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
117 // We need the editor here to be able to reshare an item.
118 if ($this->session->isAuthenticated()) {
119 $o .= $this->conversation->statusEditor([], 0, true);
123 $items = $this->getCommunityItems();
125 if (!$this->database->isResult($items)) {
126 $this->systemMessages->addNotice($this->l10n->t('No results.'));
130 $o .= $this->conversation->render($items, Conversation::MODE_COMMUNITY, false, false, 'received', $this->session->getLocalUserId());
132 $pager = new BoundariesPager(
134 $this->args->getQueryString(),
135 $items[0]['received'],
136 $items[count($items) - 1]['received'],
140 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
141 $o .= HTML::scrollLoader();
143 $o .= $pager->renderMinimal(count($items));
150 * Computes module parameters from the request and local configuration
152 * @throws HTTPException\BadRequestException
153 * @throws HTTPException\ForbiddenException
155 protected function parseRequest($request)
157 parent::parseRequest($request);
159 if ($this->config->get('system', 'block_public') && !$this->session->isAuthenticated()) {
160 throw new HTTPException\ForbiddenException($this->l10n->t('Public access denied.'));
163 $this->pageStyle = $this->config->get('system', 'community_page_style');
165 if ($this->pageStyle == self::DISABLED) {
166 throw new HTTPException\ForbiddenException($this->l10n->t('Access denied.'));
169 if (!$this->selectedTab) {
170 if (!empty($this->config->get('system', 'singleuser'))) {
171 // On single user systems only the global page does make sense
172 $this->selectedTab = CommunityEntity::GLOBAL;
174 // When only the global community is allowed, we use this as default
175 $this->selectedTab = $this->pageStyle == self::GLOBAL ? CommunityEntity::GLOBAL : CommunityEntity::LOCAL;
179 if (!$this->community->isTimeline($this->selectedTab)) {
180 throw new HTTPException\BadRequestException($this->l10n->t('Community option not available.'));
183 // Check if we are allowed to display the content to visitors
184 if (!$this->session->isAuthenticated()) {
185 $available = $this->pageStyle == self::LOCAL_AND_GLOBAL;
188 $available = ($this->pageStyle == self::LOCAL) && ($this->selectedTab == CommunityEntity::LOCAL);
192 $available = ($this->pageStyle == self::GLOBAL) && ($this->selectedTab == CommunityEntity::GLOBAL);
196 throw new HTTPException\ForbiddenException($this->l10n->t('Not available.'));
200 $this->maxId = $request['last_received'] ?? $this->maxId;
201 $this->minId = $request['first_received'] ?? $this->minId;