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\Timeline as TimelineEntity;
30 use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
31 use Friendica\Content\Feature;
32 use Friendica\Content\Nav;
33 use Friendica\Content\Text\HTML;
34 use Friendica\Content\Widget;
35 use Friendica\Content\Widget\TrendingTags;
36 use Friendica\Core\Cache\Capability\ICanCache;
37 use Friendica\Core\Config\Capability\IManageConfigValues;
38 use Friendica\Core\L10n;
39 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
40 use Friendica\Core\Renderer;
41 use Friendica\Core\Session\Capability\IHandleUserSessions;
42 use Friendica\Network\HTTPException;
43 use Friendica\Database\Database;
44 use Friendica\Module\Response;
45 use Friendica\Navigation\SystemMessages;
46 use Friendica\Util\Profiler;
47 use Psr\Log\LoggerInterface;
49 class Community extends Timeline
52 * Type of the community page
56 const DISABLED_VISITOR = -1;
59 const LOCAL_AND_GLOBAL = 2;
61 protected static $page_style;
63 /** @var TimelineFactory */
65 /** @var Conversation */
66 protected $conversation;
69 /** @var SystemMessages */
70 protected $systemMessages;
72 public function __construct(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 = [])
74 parent::__construct($mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
76 $this->timeline = $timeline;
77 $this->conversation = $conversation;
79 $this->systemMessages = $systemMessages;
82 protected function content(array $request = []): string
84 $this->parseRequest($request);
86 $t = Renderer::getMarkupTemplate("community.tpl");
87 $o = Renderer::replaceMacros($t, [
90 '$show_global_community_hint' => (self::$selectedTab == TimelineEntity::GLOBAL) && $this->config->get('system', 'show_global_community_hint'),
91 '$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.")
94 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
95 $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
96 $o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]);
99 if (empty($request['mode']) || ($request['mode'] != 'raw')) {
100 $tabs = $this->getTabArray($this->timeline->getCommunities($this->session->isAuthenticated()), 'community');
101 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
102 $o .= Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
104 Nav::setSelected('community');
106 $this->page['aside'] .= Widget::accountTypes('community/' . self::$selectedTab, self::$accountTypeString);
108 if ($this->session->getLocalUserId() && $this->config->get('system', 'community_no_sharer')) {
109 $this->page['aside'] .= $this->getNoSharerWidget('community');
112 if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
113 $this->page['aside'] .= TrendingTags::getHTML(self::$selectedTab);
116 // We need the editor here to be able to reshare an item.
117 if ($this->session->isAuthenticated()) {
118 $o .= $this->conversation->statusEditor([], 0, true);
122 $items = $this->getCommunityItems();
124 if (!$this->database->isResult($items)) {
125 $this->systemMessages->addNotice($this->l10n->t('No results.'));
129 $o .= $this->conversation->render($items, Conversation::MODE_COMMUNITY, false, false, 'commented', $this->session->getLocalUserId());
131 $pager = new BoundariesPager(
133 $this->args->getQueryString(),
134 $items[0]['commented'],
135 $items[count($items) - 1]['commented'],
139 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
140 $o .= HTML::scrollLoader();
142 $o .= $pager->renderMinimal(count($items));
149 * Computes module parameters from the request and local configuration
151 * @throws HTTPException\BadRequestException
152 * @throws HTTPException\ForbiddenException
154 protected function parseRequest($request)
156 parent::parseRequest($request);
158 if ($this->config->get('system', 'block_public') && !$this->session->isAuthenticated()) {
159 throw new HTTPException\ForbiddenException($this->l10n->t('Public access denied.'));
162 self::$page_style = $this->config->get('system', 'community_page_style');
164 if (self::$page_style == self::DISABLED) {
165 throw new HTTPException\ForbiddenException($this->l10n->t('Access denied.'));
168 if (!self::$selectedTab) {
169 if (!empty($this->config->get('system', 'singleuser'))) {
170 // On single user systems only the global page does make sense
171 self::$selectedTab = TimelineEntity::GLOBAL;
173 // When only the global community is allowed, we use this as default
174 self::$selectedTab = self::$page_style == self::GLOBAL ? TimelineEntity::GLOBAL : TimelineEntity::LOCAL;
178 if (!$this->timeline->isCommunity(self::$selectedTab)) {
179 throw new HTTPException\BadRequestException($this->l10n->t('Community option not available.'));
182 // Check if we are allowed to display the content to visitors
183 if (!$this->session->isAuthenticated()) {
184 $available = self::$page_style == self::LOCAL_AND_GLOBAL;
187 $available = (self::$page_style == self::LOCAL) && (self::$selectedTab == TimelineEntity::LOCAL);
191 $available = (self::$page_style == self::GLOBAL) && (self::$selectedTab == TimelineEntity::GLOBAL);
195 throw new HTTPException\ForbiddenException($this->l10n->t('Not available.'));
199 self::$max_id = $request['last_commented'] ?? self::$max_id;