<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\BaseModule;
use Friendica\Content\BoundariesPager;
-use Friendica\Content\ForumManager;
+use Friendica\Content\Conversation;
+use Friendica\Content\GroupManager;
use Friendica\Content\Nav;
use Friendica\Content\Widget;
use Friendica\Content\Text\HTML;
use Friendica\Core\ACL;
use Friendica\Core\Hook;
+use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
-use Friendica\Core\Session;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
-use Friendica\Model\Group;
+use Friendica\Model\Circle;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Profile;
class Network extends BaseModule
{
/** @var int */
- private static $groupId;
+ private static $circleId;
/** @var int */
- private static $forumContactId;
+ private static $groupContactId;
/** @var string */
private static $selectedTab;
/** @var mixed */
protected function content(array $request = []): string
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
return Login::form();
}
$module = 'network';
DI::page()['aside'] .= Widget::accountTypes($module, self::$accountTypeString);
- DI::page()['aside'] .= Group::sidebarWidget($module, $module . '/group', 'standard', self::$groupId);
- DI::page()['aside'] .= ForumManager::widget($module . '/forum', local_user(), self::$forumContactId);
- DI::page()['aside'] .= Widget::postedByYear($module . '/archive', local_user(), false);
- DI::page()['aside'] .= Widget::networks($module, !self::$forumContactId ? self::$network : '');
+ DI::page()['aside'] .= Circle::sidebarWidget($module, $module . '/circle', 'standard', self::$circleId);
+ DI::page()['aside'] .= GroupManager::widget($module . '/group', DI::userSession()->getLocalUserId(), self::$groupContactId);
+ DI::page()['aside'] .= Widget::postedByYear($module . '/archive', DI::userSession()->getLocalUserId(), false);
+ DI::page()['aside'] .= Widget::networks($module, !self::$groupContactId ? self::$network : '');
DI::page()['aside'] .= Widget\SavedSearches::getHTML(DI::args()->getQueryString());
- DI::page()['aside'] .= Widget::fileAs('filed', null);
+ DI::page()['aside'] .= Widget::fileAs('filed', '');
$arr = ['query' => DI::args()->getQueryString()];
Hook::callAll('network_content_init', $arr);
$items = self::getItems($table, $params);
- if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
}
$content = '';
- if (self::$forumContactId) {
- // If self::$forumContactId belongs to a communitity forum or a privat goup,.add a mention to the status editor
- $condition = ["`id` = ? AND `contact-type` = ?", self::$forumContactId, Contact::TYPE_COMMUNITY];
+ if (self::$groupContactId) {
+ // If self::$groupContactId belongs to a community group or a private group, add a mention to the status editor
+ $condition = ["`id` = ? AND `contact-type` = ?", self::$groupContactId, Contact::TYPE_COMMUNITY];
$contact = DBA::selectFirst('contact', ['addr'], $condition);
if (!empty($contact['addr'])) {
$content = '!' . $contact['addr'];
$a = DI::app();
$default_permissions = [];
- if (self::$groupId) {
- $default_permissions['allow_gid'] = [self::$groupId];
+ if (self::$circleId) {
+ $default_permissions['allow_gid'] = [self::$circleId];
}
$allowedCids = [];
- if (self::$forumContactId) {
- $allowedCids[] = (int) self::$forumContactId;
+ if (self::$groupContactId) {
+ $allowedCids[] = (int) self::$groupContactId;
} elseif (self::$network) {
$condition = [
- 'uid' => local_user(),
+ 'uid' => DI::userSession()->getLocalUserId(),
'network' => self::$network,
'self' => false,
'blocked' => false,
}
$x = [
- 'lockstate' => self::$groupId || self::$forumContactId || self::$network || ACL::getLockstateForUserId($a->getLoggedInUserId()) ? 'lock' : 'unlock',
+ 'lockstate' => self::$circleId || self::$groupContactId || self::$network || ACL::getLockstateForUserId($a->getLoggedInUserId()) ? 'lock' : 'unlock',
'acl' => ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), true, $default_permissions),
- 'bang' => ((self::$groupId || self::$forumContactId || self::$network) ? '!' : ''),
+ 'bang' => ((self::$circleId || self::$groupContactId || self::$network) ? '!' : ''),
'content' => $content,
];
$o .= DI::conversation()->statusEditor($x);
}
- if (self::$groupId) {
- $group = DBA::selectFirst('group', ['name'], ['id' => self::$groupId, 'uid' => local_user()]);
- if (!DBA::isResult($group)) {
- notice(DI::l10n()->t('No such group'));
+ if (self::$circleId) {
+ $circle = DBA::selectFirst('group', ['name'], ['id' => self::$circleId, 'uid' => DI::userSession()->getLocalUserId()]);
+ if (!DBA::isResult($circle)) {
+ DI::sysmsg()->addNotice(DI::l10n()->t('No such circle'));
}
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
- '$title' => DI::l10n()->t('Group: %s', $group['name'])
+ '$title' => DI::l10n()->t('Circle: %s', $circle['name'])
]) . $o;
- } elseif (self::$forumContactId) {
- $contact = Contact::getById(self::$forumContactId);
+ } elseif (self::$groupContactId) {
+ $contact = Contact::getById(self::$groupContactId);
if (DBA::isResult($contact)) {
- $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [
+ $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('contact/list.tpl'), [
'contacts' => [ModuleContact::getContactTemplateVars($contact)],
'id' => DI::args()->get(0),
]) . $o;
} else {
- notice(DI::l10n()->t('Invalid contact.'));
+ DI::sysmsg()->addNotice(DI::l10n()->t('Invalid contact.'));
}
} elseif (!DI::config()->get('theme', 'hide_eventlist')) {
$o .= Profile::getBirthdays();
$ordering = '`commented`';
}
- $o .= DI::conversation()->create($items, 'network', false, false, $ordering, local_user());
+ $o .= DI::conversation()->render($items, Conversation::MODE_NETWORK, false, false, $ordering, DI::userSession()->getLocalUserId());
- if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$pager = new BoundariesPager(
protected function parseRequest(array $get)
{
- self::$groupId = $this->parameters['group_id'] ?? 0;
+ self::$circleId = (int)($this->parameters['circle_id'] ?? 0);
- self::$forumContactId = $this->parameters['contact_id'] ?? 0;
+ self::$groupContactId = (int)($this->parameters['contact_id'] ?? 0);
- self::$selectedTab = Session::get('network-tab', DI::pConfig()->get(local_user(), 'network.view', 'selected_tab', ''));
+ self::$selectedTab = self::getTimelineOrderBySession(DI::userSession(), DI::pConfig());
if (!empty($get['star'])) {
self::$selectedTab = 'star';
self::$star = false;
}
- Session::set('network-tab', self::$selectedTab);
- DI::pConfig()->set(local_user(), 'network.view', 'selected_tab', self::$selectedTab);
+ DI::session()->set('network-tab', self::$selectedTab);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'network.view', 'selected_tab', self::$selectedTab);
self::$accountTypeString = $get['accounttype'] ?? $this->parameters['accounttype'] ?? '';
self::$accountType = User::getAccountTypeByString(self::$accountTypeString);
self::$dateTo = $this->parameters['to'] ?? '';
if (DI::mode()->isMobile()) {
- self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
+ self::$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
} else {
- self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
+ self::$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
DI::config()->get('system', 'itemspage_network'));
}
protected static function getItems(string $table, array $params, array $conditionFields = [])
{
- $conditionFields['uid'] = local_user();
+ $conditionFields['uid'] = DI::userSession()->getLocalUserId();
$conditionStrings = [];
if (!is_null(self::$accountType)) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` >= ? ", DateTimeFormat::convert(self::$dateTo, 'UTC', DI::app()->getTimeZone())]);
}
- if (self::$groupId) {
- $conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", self::$groupId]);
- } elseif (self::$forumContactId) {
- $conditionStrings = DBA::mergeConditions($conditionStrings,
- ["((`contact-id` = ?) OR EXISTS(SELECT `uri-id` FROM `post-user-view` WHERE `post-user-view`.`parent-uri-id` = " . DBA::quoteIdentifier($table) . ".`uri-id` AND (`contact-id` = ? AND `gravity` = ? AND `vid` = ? AND `uid` = ?)))",
- self::$forumContactId, self::$forumContactId, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), local_user()]);
+ if (self::$circleId) {
+ $conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", self::$circleId]);
+ } elseif (self::$groupContactId) {
+ $conditionStrings = DBA::mergeConditions($conditionStrings,
+ ["((`contact-id` = ?) OR `uri-id` IN (SELECT `parent-uri-id` FROM `post-user-view` WHERE (`contact-id` = ? AND `gravity` = ? AND `vid` = ? AND `uid` = ?)))",
+ self::$groupContactId, self::$groupContactId, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), DI::userSession()->getLocalUserId()]);
}
// Currently only the order modes "received" and "commented" are in use
}
if (DBA::isResult($items)) {
- $parents = array_column($items, 'parent-uri-id');
+ $parents = array_column($items, 'uri-id');
} else {
$parents = [];
}
- // We aren't going to try and figure out at the item, group, and page
+ // We aren't going to try and figure out at the item, circle, and page
// level which items you've seen and which you haven't. If you're looking
// at the top level network page just mark everything seen.
- if (!self::$groupId && !self::$forumContactId && !self::$star && !self::$mention) {
- $condition = ['unseen' => true, 'uid' => local_user()];
+ if (!self::$circleId && !self::$groupContactId && !self::$star && !self::$mention) {
+ $condition = ['unseen' => true, 'uid' => DI::userSession()->getLocalUserId()];
self::setItemsSeenByCondition($condition);
} elseif (!empty($parents)) {
- $condition = ['unseen' => true, 'uid' => local_user(), 'parent-uri-id' => $parents];
+ $condition = ['unseen' => true, 'uid' => DI::userSession()->getLocalUserId(), 'parent-uri-id' => $parents];
self::setItemsSeenByCondition($condition);
}
return $items;
}
+
+ /**
+ * Returns the selected network tab of the currently logged-in user
+ *
+ * @param IHandleUserSessions $session
+ * @param IManagePersonalConfigValues $pconfig
+ * @return string
+ */
+ public static function getTimelineOrderBySession(IHandleUserSessions $session, IManagePersonalConfigValues $pconfig): string
+ {
+ return $session->get('network-tab')
+ ?? $pconfig->get($session->getLocalUserId(), 'network.view', 'selected_tab')
+ ?? '';
+ }
}