2020-02-16 04:38:56 -05:00
< ? php
/**
2023-01-01 09:36:24 -05:00
* @ copyright Copyright ( C ) 2010 - 2023 , the Friendica project
2020-02-16 04:38:56 -05:00
*
* @ 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 />.
*
* See update_profile . php for documentation
*/
namespace Friendica\Module\Conversation ;
2023-09-09 09:14:36 +00:00
use Friendica\App ;
use Friendica\App\Mode ;
2020-02-16 04:38:56 -05:00
use Friendica\Content\BoundariesPager ;
2023-01-12 06:25:55 +00:00
use Friendica\Content\Conversation ;
2023-09-09 09:14:36 +00:00
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity ;
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory ;
2020-02-16 04:38:56 -05:00
use Friendica\Content\Feature ;
use Friendica\Content\Nav ;
2020-09-27 05:25:32 +00:00
use Friendica\Content\Text\HTML ;
2020-10-05 16:48:28 +00:00
use Friendica\Content\Widget ;
2020-02-16 04:38:56 -05:00
use Friendica\Content\Widget\TrendingTags ;
2023-09-09 09:14:36 +00:00
use Friendica\Core\Cache\Capability\ICanCache ;
use Friendica\Core\Config\Capability\IManageConfigValues ;
use Friendica\Core\L10n ;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues ;
2020-02-16 04:38:56 -05:00
use Friendica\Core\Renderer ;
2023-09-09 09:14:36 +00:00
use Friendica\Core\Session\Capability\IHandleUserSessions ;
2020-02-16 04:38:56 -05:00
use Friendica\Network\HTTPException ;
2023-09-09 09:14:36 +00:00
use Friendica\Database\Database ;
use Friendica\Module\Response ;
use Friendica\Navigation\SystemMessages ;
use Friendica\Util\Profiler ;
use Psr\Log\LoggerInterface ;
2020-02-16 04:38:56 -05:00
2023-09-09 09:14:36 +00:00
class Community extends Timeline
2020-02-16 04:38:56 -05:00
{
2022-10-17 09:24:32 +00:00
/**
* Type of the community page
* @ {
*/
const DISABLED = - 2 ;
const DISABLED_VISITOR = - 1 ;
const LOCAL = 0 ;
const GLOBAL = 1 ;
const LOCAL_AND_GLOBAL = 2 ;
2023-09-09 12:48:51 +00:00
protected $pageStyle ;
2023-09-09 09:14:36 +00:00
/** @var TimelineFactory */
protected $timeline ;
/** @var Conversation */
protected $conversation ;
/** @var App\Page */
protected $page ;
/** @var SystemMessages */
protected $systemMessages ;
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 = [])
{
parent :: __construct ( $mode , $session , $database , $pConfig , $config , $cache , $l10n , $baseUrl , $args , $logger , $profiler , $response , $server , $parameters );
$this -> timeline = $timeline ;
$this -> conversation = $conversation ;
$this -> page = $page ;
$this -> systemMessages = $systemMessages ;
}
2020-02-16 04:38:56 -05:00
2021-11-20 15:38:03 +01:00
protected function content ( array $request = []) : string
2020-02-16 04:38:56 -05:00
{
2023-09-09 09:14:36 +00:00
$this -> parseRequest ( $request );
2020-02-16 04:38:56 -05:00
2022-09-25 06:34:13 +00:00
$t = Renderer :: getMarkupTemplate ( " community.tpl " );
$o = Renderer :: replaceMacros ( $t , [
'$content' => '' ,
'$header' => '' ,
2023-09-09 12:48:51 +00:00
'$show_global_community_hint' => ( $this -> selectedTab == TimelineEntity :: GLOBAL ) && $this -> config -> get ( 'system' , 'show_global_community_hint' ),
2023-09-09 09:14:36 +00:00
'$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. " )
2022-09-25 06:34:13 +00:00
]);
2023-09-09 09:14:36 +00:00
if ( $this -> pConfig -> get ( $this -> session -> getLocalUserId (), 'system' , 'infinite_scroll' )) {
2020-09-27 05:25:32 +00:00
$tpl = Renderer :: getMarkupTemplate ( 'infinite_scroll_head.tpl' );
2023-09-09 09:14:36 +00:00
$o .= Renderer :: replaceMacros ( $tpl , [ '$reload_uri' => $this -> args -> getQueryString ()]);
2020-09-27 05:25:32 +00:00
}
2020-09-27 05:46:07 +00:00
2023-09-09 09:14:36 +00:00
if ( empty ( $request [ 'mode' ]) || ( $request [ 'mode' ] != 'raw' )) {
$tabs = $this -> getTabArray ( $this -> timeline -> getCommunities ( $this -> session -> isAuthenticated ()), 'community' );
2020-09-27 05:25:32 +00:00
$tab_tpl = Renderer :: getMarkupTemplate ( 'common_tabs.tpl' );
$o .= Renderer :: replaceMacros ( $tab_tpl , [ '$tabs' => $tabs ]);
2020-02-16 04:38:56 -05:00
2020-09-27 05:46:07 +00:00
Nav :: setSelected ( 'community' );
2023-09-09 12:48:51 +00:00
$this -> page [ 'aside' ] .= Widget :: accountTypes ( 'community/' . $this -> selectedTab , $this -> accountTypeString );
2023-09-09 09:14:36 +00:00
if ( $this -> session -> getLocalUserId () && $this -> config -> get ( 'system' , 'community_no_sharer' )) {
$this -> page [ 'aside' ] .= $this -> getNoSharerWidget ( 'community' );
2020-09-27 05:46:07 +00:00
}
2023-02-04 19:14:21 -05:00
2023-09-09 09:14:36 +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 );
2020-09-27 05:46:07 +00:00
}
// We need the editor here to be able to reshare an item.
2023-09-09 09:14:36 +00:00
if ( $this -> session -> isAuthenticated ()) {
$o .= $this -> conversation -> statusEditor ([], 0 , true );
2020-09-27 05:46:07 +00:00
}
}
2020-02-16 04:38:56 -05:00
2023-09-09 09:14:36 +00:00
$items = $this -> getCommunityItems ();
2020-02-16 04:38:56 -05:00
2023-09-09 09:14:36 +00:00
if ( ! $this -> database -> isResult ( $items )) {
$this -> systemMessages -> addNotice ( $this -> l10n -> t ( 'No results.' ));
2020-02-16 04:38:56 -05:00
return $o ;
}
2023-09-16 04:21:59 +00:00
$o .= $this -> conversation -> render ( $items , Conversation :: MODE_COMMUNITY , false , false , 'received' , $this -> session -> getLocalUserId ());
2020-02-16 04:38:56 -05:00
$pager = new BoundariesPager (
2023-09-09 09:14:36 +00:00
$this -> l10n ,
$this -> args -> getQueryString (),
2023-09-16 04:21:59 +00:00
$items [ 0 ][ 'received' ],
$items [ count ( $items ) - 1 ][ 'received' ],
2023-09-09 12:48:51 +00:00
$this -> itemsPerPage
2020-02-16 04:38:56 -05:00
);
2023-09-09 09:14:36 +00:00
if ( $this -> pConfig -> get ( $this -> session -> getLocalUserId (), 'system' , 'infinite_scroll' )) {
2020-09-27 05:25:32 +00:00
$o .= HTML :: scrollLoader ();
} else {
$o .= $pager -> renderMinimal ( count ( $items ));
}
2022-09-25 06:34:13 +00:00
return $o ;
2020-02-16 04:38:56 -05:00
}
/**
* Computes module parameters from the request and local configuration
*
* @ throws HTTPException\BadRequestException
* @ throws HTTPException\ForbiddenException
*/
2023-09-09 09:14:36 +00:00
protected function parseRequest ( $request )
2020-02-16 04:38:56 -05:00
{
2023-09-09 09:14:36 +00:00
parent :: parseRequest ( $request );
if ( $this -> config -> get ( 'system' , 'block_public' ) && ! $this -> session -> isAuthenticated ()) {
throw new HTTPException\ForbiddenException ( $this -> l10n -> t ( 'Public access denied.' ));
2020-02-16 04:38:56 -05:00
}
2023-09-09 12:48:51 +00:00
$this -> pageStyle = $this -> config -> get ( 'system' , 'community_page_style' );
2020-02-16 04:38:56 -05:00
2023-09-09 12:48:51 +00:00
if ( $this -> pageStyle == self :: DISABLED ) {
2023-09-09 09:14:36 +00:00
throw new HTTPException\ForbiddenException ( $this -> l10n -> t ( 'Access denied.' ));
2020-02-16 04:38:56 -05:00
}
2023-09-09 12:48:51 +00:00
if ( ! $this -> selectedTab ) {
2023-09-09 09:14:36 +00:00
if ( ! empty ( $this -> config -> get ( 'system' , 'singleuser' ))) {
2020-02-16 04:38:56 -05:00
// On single user systems only the global page does make sense
2023-09-09 12:48:51 +00:00
$this -> selectedTab = TimelineEntity :: GLOBAL ;
2020-02-16 04:38:56 -05:00
} else {
// When only the global community is allowed, we use this as default
2023-09-09 12:48:51 +00:00
$this -> selectedTab = $this -> pageStyle == self :: GLOBAL ? TimelineEntity :: GLOBAL : TimelineEntity :: LOCAL ;
2020-02-16 04:38:56 -05:00
}
}
2023-09-09 12:48:51 +00:00
if ( ! $this -> timeline -> isCommunity ( $this -> selectedTab )) {
2023-09-09 09:14:36 +00:00
throw new HTTPException\BadRequestException ( $this -> l10n -> t ( 'Community option not available.' ));
2020-02-16 04:38:56 -05:00
}
// Check if we are allowed to display the content to visitors
2023-09-09 09:14:36 +00:00
if ( ! $this -> session -> isAuthenticated ()) {
2023-09-09 12:48:51 +00:00
$available = $this -> pageStyle == self :: LOCAL_AND_GLOBAL ;
2020-02-16 04:38:56 -05:00
if ( ! $available ) {
2023-09-09 12:48:51 +00:00
$available = ( $this -> pageStyle == self :: LOCAL ) && ( $this -> selectedTab == TimelineEntity :: LOCAL );
2020-02-16 04:38:56 -05:00
}
if ( ! $available ) {
2023-09-09 12:48:51 +00:00
$available = ( $this -> pageStyle == self :: GLOBAL ) && ( $this -> selectedTab == TimelineEntity :: GLOBAL );
2020-02-16 04:38:56 -05:00
}
if ( ! $available ) {
2023-09-09 09:14:36 +00:00
throw new HTTPException\ForbiddenException ( $this -> l10n -> t ( 'Not available.' ));
2020-02-16 04:38:56 -05:00
}
}
2023-09-16 04:21:59 +00:00
$this -> maxId = $request [ 'last_received' ] ? ? $this -> maxId ;
$this -> minId = $request [ 'first_received' ] ? ? $this -> minId ;
2020-02-16 04:38:56 -05:00
}
}