Make variables non static

This commit is contained in:
Michael 2023-09-09 12:48:51 +00:00
parent b5f184388a
commit 52db2b3da1
6 changed files with 141 additions and 145 deletions

View file

@ -95,21 +95,21 @@ class Channel extends Timeline
Nav::setSelected('channel'); Nav::setSelected('channel');
$this->page['aside'] .= Widget::accountTypes('channel/' . self::$selectedTab, self::$accountTypeString); $this->page['aside'] .= Widget::accountTypes('channel/' . $this->selectedTab, $this->accountTypeString);
if (!in_array(self::$selectedTab, [TimelineEntity::FOLLOWERS, TimelineEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) { if (!in_array($this->selectedTab, [TimelineEntity::FOLLOWERS, TimelineEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) {
$this->page['aside'] .= $this->getNoSharerWidget('channel'); $this->page['aside'] .= $this->getNoSharerWidget('channel');
} }
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) { if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
$this->page['aside'] .= TrendingTags::getHTML(self::$selectedTab); $this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
} }
// We need the editor here to be able to reshare an item. // We need the editor here to be able to reshare an item.
$o .= $this->conversation->statusEditor([], 0, true); $o .= $this->conversation->statusEditor([], 0, true);
} }
if ($this->timeline->isChannel(self::$selectedTab)) { if ($this->timeline->isChannel($this->selectedTab)) {
$items = $this->getChannelItems(); $items = $this->getChannelItems();
$order = 'created'; $order = 'created';
} else { } else {
@ -129,7 +129,7 @@ class Channel extends Timeline
$this->args->getQueryString(), $this->args->getQueryString(),
$items[0][$order], $items[0][$order],
$items[count($items) - 1][$order], $items[count($items) - 1][$order],
self::$itemsPerPage $this->itemsPerPage
); );
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) { if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
@ -151,14 +151,14 @@ class Channel extends Timeline
{ {
parent::parseRequest($request); parent::parseRequest($request);
if (!self::$selectedTab) { if (!$this->selectedTab) {
self::$selectedTab = TimelineEntity::FORYOU; $this->selectedTab = TimelineEntity::FORYOU;
} }
if (!$this->timeline->isChannel(self::$selectedTab) && !$this->timeline->isCommunity(self::$selectedTab)) { if (!$this->timeline->isChannel($this->selectedTab) && !$this->timeline->isCommunity($this->selectedTab)) {
throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.')); throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
} }
self::$max_id = $request['last_created'] ?? self::$max_id; $this->max_id = $request['last_created'] ?? $this->max_id;
} }
} }

View file

@ -58,7 +58,7 @@ class Community extends Timeline
const GLOBAL = 1; const GLOBAL = 1;
const LOCAL_AND_GLOBAL = 2; const LOCAL_AND_GLOBAL = 2;
protected static $page_style; protected $pageStyle;
/** @var TimelineFactory */ /** @var TimelineFactory */
protected $timeline; protected $timeline;
@ -87,7 +87,7 @@ class Community extends Timeline
$o = Renderer::replaceMacros($t, [ $o = Renderer::replaceMacros($t, [
'$content' => '', '$content' => '',
'$header' => '', '$header' => '',
'$show_global_community_hint' => (self::$selectedTab == TimelineEntity::GLOBAL) && $this->config->get('system', 'show_global_community_hint'), '$show_global_community_hint' => ($this->selectedTab == TimelineEntity::GLOBAL) && $this->config->get('system', 'show_global_community_hint'),
'$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 nodes users.") '$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 nodes users.")
]); ]);
@ -103,14 +103,14 @@ class Community extends Timeline
Nav::setSelected('community'); Nav::setSelected('community');
$this->page['aside'] .= Widget::accountTypes('community/' . self::$selectedTab, self::$accountTypeString); $this->page['aside'] .= Widget::accountTypes('community/' . $this->selectedTab, $this->accountTypeString);
if ($this->session->getLocalUserId() && $this->config->get('system', 'community_no_sharer')) { if ($this->session->getLocalUserId() && $this->config->get('system', 'community_no_sharer')) {
$this->page['aside'] .= $this->getNoSharerWidget('community'); $this->page['aside'] .= $this->getNoSharerWidget('community');
} }
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) { if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
$this->page['aside'] .= TrendingTags::getHTML(self::$selectedTab); $this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
} }
// We need the editor here to be able to reshare an item. // We need the editor here to be able to reshare an item.
@ -133,7 +133,7 @@ class Community extends Timeline
$this->args->getQueryString(), $this->args->getQueryString(),
$items[0]['commented'], $items[0]['commented'],
$items[count($items) - 1]['commented'], $items[count($items) - 1]['commented'],
self::$itemsPerPage $this->itemsPerPage
); );
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) { if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
@ -159,36 +159,36 @@ class Community extends Timeline
throw new HTTPException\ForbiddenException($this->l10n->t('Public access denied.')); throw new HTTPException\ForbiddenException($this->l10n->t('Public access denied.'));
} }
self::$page_style = $this->config->get('system', 'community_page_style'); $this->pageStyle = $this->config->get('system', 'community_page_style');
if (self::$page_style == self::DISABLED) { if ($this->pageStyle == self::DISABLED) {
throw new HTTPException\ForbiddenException($this->l10n->t('Access denied.')); throw new HTTPException\ForbiddenException($this->l10n->t('Access denied.'));
} }
if (!self::$selectedTab) { if (!$this->selectedTab) {
if (!empty($this->config->get('system', 'singleuser'))) { if (!empty($this->config->get('system', 'singleuser'))) {
// On single user systems only the global page does make sense // On single user systems only the global page does make sense
self::$selectedTab = TimelineEntity::GLOBAL; $this->selectedTab = TimelineEntity::GLOBAL;
} else { } else {
// When only the global community is allowed, we use this as default // When only the global community is allowed, we use this as default
self::$selectedTab = self::$page_style == self::GLOBAL ? TimelineEntity::GLOBAL : TimelineEntity::LOCAL; $this->selectedTab = $this->pageStyle == self::GLOBAL ? TimelineEntity::GLOBAL : TimelineEntity::LOCAL;
} }
} }
if (!$this->timeline->isCommunity(self::$selectedTab)) { if (!$this->timeline->isCommunity($this->selectedTab)) {
throw new HTTPException\BadRequestException($this->l10n->t('Community option not available.')); throw new HTTPException\BadRequestException($this->l10n->t('Community option not available.'));
} }
// Check if we are allowed to display the content to visitors // Check if we are allowed to display the content to visitors
if (!$this->session->isAuthenticated()) { if (!$this->session->isAuthenticated()) {
$available = self::$page_style == self::LOCAL_AND_GLOBAL; $available = $this->pageStyle == self::LOCAL_AND_GLOBAL;
if (!$available) { if (!$available) {
$available = (self::$page_style == self::LOCAL) && (self::$selectedTab == TimelineEntity::LOCAL); $available = ($this->pageStyle == self::LOCAL) && ($this->selectedTab == TimelineEntity::LOCAL);
} }
if (!$available) { if (!$available) {
$available = (self::$page_style == self::GLOBAL) && (self::$selectedTab == TimelineEntity::GLOBAL); $available = ($this->pageStyle == self::GLOBAL) && ($this->selectedTab == TimelineEntity::GLOBAL);
} }
if (!$available) { if (!$available) {
@ -196,6 +196,6 @@ class Community extends Timeline
} }
} }
self::$max_id = $request['last_commented'] ?? self::$max_id; $this->max_id = $request['last_commented'] ?? $this->max_id;
} }
} }

View file

@ -116,30 +116,30 @@ class Network extends Timeline
$module = 'network'; $module = 'network';
$this->page['aside'] .= Widget::accountTypes($module, self::$accountTypeString); $this->page['aside'] .= Widget::accountTypes($module, $this->accountTypeString);
$arr = ['query' => $this->args->getQueryString()]; $arr = ['query' => $this->args->getQueryString()];
Hook::callAll('network_content_init', $arr); Hook::callAll('network_content_init', $arr);
$o = ''; $o = '';
if ($this->timeline->isChannel(self::$selectedTab)) { if ($this->timeline->isChannel($this->selectedTab)) {
if (!in_array(self::$selectedTab, [TimelineEntity::FOLLOWERS, TimelineEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) { if (!in_array($this->selectedTab, [TimelineEntity::FOLLOWERS, TimelineEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) {
$this->page['aside'] .= $this->getNoSharerWidget($module); $this->page['aside'] .= $this->getNoSharerWidget($module);
} }
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) { if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
$this->page['aside'] .= TrendingTags::getHTML(self::$selectedTab); $this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
} }
$items = $this->getChannelItems(); $items = $this->getChannelItems();
} elseif ($this->timeline->isCommunity(self::$selectedTab)) { } elseif ($this->timeline->isCommunity($this->selectedTab)) {
if ($this->session->getLocalUserId() && $this->config->get('system', 'community_no_sharer')) { if ($this->session->getLocalUserId() && $this->config->get('system', 'community_no_sharer')) {
$this->page['aside'] .= $this->getNoSharerWidget($module); $this->page['aside'] .= $this->getNoSharerWidget($module);
} }
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) { if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
$this->page['aside'] .= TrendingTags::getHTML(self::$selectedTab); $this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
} }
$items = $this->getCommunityItems(); $items = $this->getCommunityItems();
@ -152,7 +152,7 @@ class Network extends Timeline
$this->page['aside'] .= Widget::fileAs('filed', ''); $this->page['aside'] .= Widget::fileAs('filed', '');
// Fetch a page full of parent items for this page // Fetch a page full of parent items for this page
$params = ['limit' => self::$itemsPerPage]; $params = ['limit' => $this->itemsPerPage];
$table = 'network-thread-view'; $table = 'network-thread-view';
$items = $this->getItems($table, $params); $items = $this->getItems($table, $params);
@ -260,7 +260,7 @@ class Network extends Timeline
$this->args->getQueryString(), $this->args->getQueryString(),
$items[0][self::$order] ?? null, $items[0][self::$order] ?? null,
$items[count($items) - 1][self::$order] ?? null, $items[count($items) - 1][self::$order] ?? null,
self::$itemsPerPage $this->itemsPerPage
); );
$o .= $pager->renderMinimal(count($items)); $o .= $pager->renderMinimal(count($items));
@ -316,51 +316,51 @@ class Network extends Timeline
self::$groupContactId = (int)($this->parameters['contact_id'] ?? 0); self::$groupContactId = (int)($this->parameters['contact_id'] ?? 0);
if (!self::$selectedTab) { if (!$this->selectedTab) {
self::$selectedTab = self::getTimelineOrderBySession(DI::userSession(), $this->pConfig); $this->selectedTab = self::getTimelineOrderBySession(DI::userSession(), $this->pConfig);
} elseif (!$this->timeline->isChannel(self::$selectedTab) && !$this->timeline->isCommunity(self::$selectedTab)) { } elseif (!$this->timeline->isChannel($this->selectedTab) && !$this->timeline->isCommunity($this->selectedTab)) {
throw new HTTPException\BadRequestException($this->l10n->t('Network feed not available.')); throw new HTTPException\BadRequestException($this->l10n->t('Network feed not available.'));
} }
if (!empty($request['star'])) { if (!empty($request['star'])) {
self::$selectedTab = TimelineEntity::STAR; $this->selectedTab = TimelineEntity::STAR;
self::$star = true; self::$star = true;
} else { } else {
self::$star = self::$selectedTab == TimelineEntity::STAR; self::$star = $this->selectedTab == TimelineEntity::STAR;
} }
if (!empty($request['mention'])) { if (!empty($request['mention'])) {
self::$selectedTab = TimelineEntity::MENTION; $this->selectedTab = TimelineEntity::MENTION;
self::$mention = true; self::$mention = true;
} else { } else {
self::$mention = self::$selectedTab == TimelineEntity::MENTION; self::$mention = $this->selectedTab == TimelineEntity::MENTION;
} }
if (!empty($request['order'])) { if (!empty($request['order'])) {
self::$selectedTab = $request['order']; $this->selectedTab = $request['order'];
self::$order = $request['order']; self::$order = $request['order'];
self::$star = false; self::$star = false;
self::$mention = false; self::$mention = false;
} elseif (in_array(self::$selectedTab, [TimelineEntity::RECEIVED, TimelineEntity::STAR])) { } elseif (in_array($this->selectedTab, [TimelineEntity::RECEIVED, TimelineEntity::STAR])) {
self::$order = 'received'; self::$order = 'received';
} elseif ((self::$selectedTab == TimelineEntity::CREATED) || $this->timeline->isChannel(self::$selectedTab)) { } elseif (($this->selectedTab == TimelineEntity::CREATED) || $this->timeline->isChannel($this->selectedTab)) {
self::$order = 'created'; self::$order = 'created';
} else { } else {
self::$order = 'commented'; self::$order = 'commented';
} }
self::$selectedTab = self::$selectedTab ?? self::$order; $this->selectedTab = $this->selectedTab ?? self::$order;
// Prohibit combined usage of "star" and "mention" // Prohibit combined usage of "star" and "mention"
if (self::$selectedTab == TimelineEntity::STAR) { if ($this->selectedTab == TimelineEntity::STAR) {
self::$mention = false; self::$mention = false;
} elseif (self::$selectedTab == TimelineEntity::MENTION) { } elseif ($this->selectedTab == TimelineEntity::MENTION) {
self::$star = false; self::$star = false;
} }
$this->session->set('network-tab', self::$selectedTab); $this->session->set('network-tab', $this->selectedTab);
$this->pConfig->set($this->session->getLocalUserId(), 'network.view', 'selected_tab', self::$selectedTab); $this->pConfig->set($this->session->getLocalUserId(), 'network.view', 'selected_tab', $this->selectedTab);
self::$network = $request['nets'] ?? ''; self::$network = $request['nets'] ?? '';
@ -369,17 +369,17 @@ class Network extends Timeline
switch (self::$order) { switch (self::$order) {
case 'received': case 'received':
self::$max_id = $request['last_received'] ?? self::$max_id; $this->max_id = $request['last_received'] ?? $this->max_id;
break; break;
case 'created': case 'created':
self::$max_id = $request['last_created'] ?? self::$max_id; $this->max_id = $request['last_created'] ?? $this->max_id;
break; break;
case 'uriid': case 'uriid':
self::$max_id = $request['last_uriid'] ?? self::$max_id; $this->max_id = $request['last_uriid'] ?? $this->max_id;
break; break;
default: default:
self::$order = 'commented'; self::$order = 'commented';
self::$max_id = $request['last_commented'] ?? self::$max_id; $this->max_id = $request['last_commented'] ?? $this->max_id;
} }
} }
@ -388,8 +388,8 @@ class Network extends Timeline
$conditionFields['uid'] = $this->session->getLocalUserId(); $conditionFields['uid'] = $this->session->getLocalUserId();
$conditionStrings = []; $conditionStrings = [];
if (!is_null(self::$accountType)) { if (!is_null($this->accountType)) {
$conditionFields['contact-type'] = self::$accountType; $conditionFields['contact-type'] = $this->accountType;
} }
if (self::$star) { if (self::$star) {
@ -418,45 +418,45 @@ class Network extends Timeline
} }
// Currently only the order modes "received" and "commented" are in use // Currently only the order modes "received" and "commented" are in use
if (!empty(self::$item_uri_id)) { if (!empty($this->itemUriId)) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ['uri-id' => self::$item_uri_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ['uri-id' => $this->itemUriId]);
} else { } else {
if (isset(self::$max_id)) { if (isset($this->max_id)) {
switch (self::$order) { switch (self::$order) {
case 'received': case 'received':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", self::$max_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", $this->max_id]);
break; break;
case 'commented': case 'commented':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", self::$max_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", $this->max_id]);
break; break;
case 'created': case 'created':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", self::$max_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", $this->max_id]);
break; break;
case 'uriid': case 'uriid':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", self::$max_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", $this->max_id]);
break; break;
} }
} }
if (isset(self::$min_id)) { if (isset($this->min_id)) {
switch (self::$order) { switch (self::$order) {
case 'received': case 'received':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` > ?", self::$min_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` > ?", $this->min_id]);
break; break;
case 'commented': case 'commented':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` > ?", self::$min_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` > ?", $this->min_id]);
break; break;
case 'created': case 'created':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` > ?", self::$min_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` > ?", $this->min_id]);
break; break;
case 'uriid': case 'uriid':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` > ?", self::$min_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` > ?", $this->min_id]);
break; break;
} }
} }
} }
if (isset(self::$min_id) && !isset(self::$max_id)) { if (isset($this->min_id) && !isset($this->max_id)) {
// min_id quirk: querying in reverse order with min_id gets the most recent rows, regardless of how close // min_id quirk: querying in reverse order with min_id gets the most recent rows, regardless of how close
// they are to min_id. We change the query ordering to get the expected data, and we need to reverse the // they are to min_id. We change the query ordering to get the expected data, and we need to reverse the
// order of the results. // order of the results.
@ -468,7 +468,7 @@ class Network extends Timeline
$items = DBA::selectToArray($table, [], DBA::mergeConditions($conditionFields, $conditionStrings), $params); $items = DBA::selectToArray($table, [], DBA::mergeConditions($conditionFields, $conditionStrings), $params);
// min_id quirk, continued // min_id quirk, continued
if (isset(self::$min_id) && !isset(self::$max_id)) { if (isset($this->min_id) && !isset($this->max_id)) {
$items = array_reverse($items); $items = array_reverse($items);
} }

View file

@ -47,23 +47,21 @@ use Psr\Log\LoggerInterface;
class Timeline extends BaseModule class Timeline extends BaseModule
{ {
/** @var string */ /** @var string */
protected static $selectedTab; protected $selectedTab;
/** @var mixed */ /** @var mixed */
protected static $min_id; protected $min_id;
/** @var mixed */ /** @var mixed */
protected static $max_id; protected $max_id;
/** @var string */ /** @var string */
protected static $accountTypeString; protected $accountTypeString;
/** @var int */ /** @var int */
protected static $accountType; protected $accountType;
/** @var int */ /** @var int */
protected static $item_id; protected $itemUriId;
/** @var int */ /** @var int */
protected static $item_uri_id; protected $itemsPerPage;
/** @var int */
protected static $itemsPerPage;
/** @var bool */ /** @var bool */
protected static $no_sharer; protected $noSharer;
/** @var App\Mode $mode */ /** @var App\Mode $mode */
protected $mode; protected $mode;
@ -99,20 +97,20 @@ class Timeline extends BaseModule
protected function parseRequest(array $request) protected function parseRequest(array $request)
{ {
$this->logger->debug('Got request', $request); $this->logger->debug('Got request', $request);
self::$selectedTab = $this->parameters['content'] ?? ''; $this->selectedTab = $this->parameters['content'] ?? '';
self::$accountTypeString = $request['accounttype'] ?? $this->parameters['accounttype'] ?? ''; $this->accountTypeString = $request['accounttype'] ?? $this->parameters['accounttype'] ?? '';
self::$accountType = User::getAccountTypeByString(self::$accountTypeString); $this->accountType = User::getAccountTypeByString($this->accountTypeString);
if ($this->mode->isMobile()) { if ($this->mode->isMobile()) {
self::$itemsPerPage = $this->pConfig->get( $this->itemsPerPage = $this->pConfig->get(
$this->session->getLocalUserId(), $this->session->getLocalUserId(),
'system', 'system',
'itemspage_mobile_network', 'itemspage_mobile_network',
$this->config->get('system', 'itemspage_network_mobile') $this->config->get('system', 'itemspage_network_mobile')
); );
} else { } else {
self::$itemsPerPage = $this->pConfig->get( $this->itemsPerPage = $this->pConfig->get(
$this->session->getLocalUserId(), $this->session->getLocalUserId(),
'system', 'system',
'itemspage_network', 'itemspage_network',
@ -122,32 +120,30 @@ class Timeline extends BaseModule
if (!empty($request['item'])) { if (!empty($request['item'])) {
$item = Post::selectFirst(['parent', 'parent-uri-id'], ['id' => $request['item']]); $item = Post::selectFirst(['parent', 'parent-uri-id'], ['id' => $request['item']]);
self::$item_id = $item['parent'] ?? 0; $this->itemUriId = $item['parent-uri-id'] ?? 0;
self::$item_uri_id = $item['parent-uri-id'] ?? 0;
} else { } else {
self::$item_id = 0; $this->itemUriId = 0;
self::$item_uri_id = 0;
} }
self::$min_id = $request['min_id'] ?? null; $this->min_id = $request['min_id'] ?? null;
self::$max_id = $request['max_id'] ?? null; $this->max_id = $request['max_id'] ?? null;
self::$no_sharer = !empty($request['no_sharer']); $this->noSharer = !empty($request['no_sharer']);
} }
protected function getNoSharerWidget(string $base): string protected function getNoSharerWidget(string $base): string
{ {
$path = self::$selectedTab; $path = $this->selectedTab;
if (!empty(self::$accountTypeString)) { if (!empty($this->accountTypeString)) {
$path .= '/' . self::$accountTypeString; $path .= '/' . $this->accountTypeString;
} }
$query_parameters = []; $query_parameters = [];
if (!empty(self::$min_id)) { if (!empty($this->min_id)) {
$query_parameters['min_id'] = self::$min_id; $query_parameters['min_id'] = $this->min_id;
} }
if (!empty(self::$max_id)) { if (!empty($this->max_id)) {
$query_parameters['max_id'] = self::$max_id; $query_parameters['max_id'] = $this->max_id;
} }
$path_all = $path . (!empty($query_parameters) ? '?' . http_build_query($query_parameters) : ''); $path_all = $path . (!empty($query_parameters) ? '?' . http_build_query($query_parameters) : '');
@ -156,7 +152,7 @@ class Timeline extends BaseModule
'$title' => $this->l10n->t('Own Contacts'), '$title' => $this->l10n->t('Own Contacts'),
'$path_all' => $path_all, '$path_all' => $path_all,
'$path_no_sharer' => $path_no_sharer, '$path_no_sharer' => $path_no_sharer,
'$no_sharer' => self::$no_sharer, '$no_sharer' => $this->noSharer,
'$all' => $this->l10n->t('Include'), '$all' => $this->l10n->t('Include'),
'$no_sharer_label' => $this->l10n->t('Hide'), '$no_sharer_label' => $this->l10n->t('Hide'),
'$base' => $base, '$base' => $base,
@ -171,7 +167,7 @@ class Timeline extends BaseModule
$tabs[] = [ $tabs[] = [
'label' => $tab->label, 'label' => $tab->label,
'url' => $tab->path ?? $prefix . '/' . $tab->code, 'url' => $tab->path ?? $prefix . '/' . $tab->code,
'sel' => self::$selectedTab == $tab->code ? 'active' : '', 'sel' => $this->selectedTab == $tab->code ? 'active' : '',
'title' => $tab->description, 'title' => $tab->description,
'id' => $prefix . '-' . $tab->code . '-tab', 'id' => $prefix . '-' . $tab->code . '-tab',
'accesskey' => $tab->accessKey, 'accesskey' => $tab->accessKey,
@ -190,13 +186,13 @@ class Timeline extends BaseModule
{ {
$uid = $this->session->getLocalUserId(); $uid = $this->session->getLocalUserId();
if (self::$selectedTab == TimelineEntity::WHATSHOT) { if ($this->selectedTab == TimelineEntity::WHATSHOT) {
if (!is_null(self::$accountType)) { if (!is_null($this->accountType)) {
$condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` = ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), self::$accountType]; $condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` = ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $this->accountType];
} else { } else {
$condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` != ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), Contact::TYPE_COMMUNITY]; $condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` != ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), Contact::TYPE_COMMUNITY];
} }
} elseif (self::$selectedTab == TimelineEntity::FORYOU) { } elseif ($this->selectedTab == TimelineEntity::FORYOU) {
$cid = Contact::getPublicIdByUserId($uid); $cid = Contact::getPublicIdByUserId($uid);
$condition = [ $condition = [
@ -206,9 +202,9 @@ class Timeline extends BaseModule
$cid, $this->getMedianRelationThreadScore($cid, 4), $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $cid, $cid, $this->getMedianRelationThreadScore($cid, 4), $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $cid,
$uid, Contact::FRIEND, Contact::SHARING $uid, Contact::FRIEND, Contact::SHARING
]; ];
} elseif (self::$selectedTab == TimelineEntity::FOLLOWERS) { } elseif ($this->selectedTab == TimelineEntity::FOLLOWERS) {
$condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $uid, Contact::FOLLOWER]; $condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $uid, Contact::FOLLOWER];
} elseif (self::$selectedTab == TimelineEntity::SHARERSOFSHARERS) { } elseif ($this->selectedTab == TimelineEntity::SHARERSOFSHARERS) {
$cid = Contact::getPublicIdByUserId($uid); $cid = Contact::getPublicIdByUserId($uid);
// @todo Suggest posts from contacts that are followed most by our followers // @todo Suggest posts from contacts that are followed most by our followers
@ -218,44 +214,44 @@ class Timeline extends BaseModule
AND NOT `cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?))", AND NOT `cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?))",
DateTimeFormat::utc('now - ' . $this->config->get('channel', 'sharer_interaction_days') . ' day'), $cid, $this->getMedianRelationThreadScore($cid, 4), $cid DateTimeFormat::utc('now - ' . $this->config->get('channel', 'sharer_interaction_days') . ' day'), $cid, $this->getMedianRelationThreadScore($cid, 4), $cid
]; ];
} elseif (self::$selectedTab == TimelineEntity::IMAGE) { } elseif ($this->selectedTab == TimelineEntity::IMAGE) {
$condition = ["`media-type` & ?", 1]; $condition = ["`media-type` & ?", 1];
} elseif (self::$selectedTab == TimelineEntity::VIDEO) { } elseif ($this->selectedTab == TimelineEntity::VIDEO) {
$condition = ["`media-type` & ?", 2]; $condition = ["`media-type` & ?", 2];
} elseif (self::$selectedTab == TimelineEntity::AUDIO) { } elseif ($this->selectedTab == TimelineEntity::AUDIO) {
$condition = ["`media-type` & ?", 4]; $condition = ["`media-type` & ?", 4];
} elseif (self::$selectedTab == TimelineEntity::LANGUAGE) { } elseif ($this->selectedTab == TimelineEntity::LANGUAGE) {
$condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", $this->l10n->convertCodeForLanguageDetection(User::getLanguageCode($uid))]; $condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", $this->l10n->convertCodeForLanguageDetection(User::getLanguageCode($uid))];
} }
if (self::$selectedTab != TimelineEntity::LANGUAGE) { if ($this->selectedTab != TimelineEntity::LANGUAGE) {
$condition = $this->addLanguageCondition($uid, $condition); $condition = $this->addLanguageCondition($uid, $condition);
} }
$condition = DBA::mergeConditions($condition, ["NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed`))", $uid]); $condition = DBA::mergeConditions($condition, ["NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed`))", $uid]);
if ((self::$selectedTab != TimelineEntity::WHATSHOT) && !is_null(self::$accountType)) { if (($this->selectedTab != TimelineEntity::WHATSHOT) && !is_null($this->accountType)) {
$condition = DBA::mergeConditions($condition, ['contact-type' => self::$accountType]); $condition = DBA::mergeConditions($condition, ['contact-type' => $this->accountType]);
} }
$params = ['order' => ['created' => true], 'limit' => self::$itemsPerPage]; $params = ['order' => ['created' => true], 'limit' => $this->itemsPerPage];
if (!empty(self::$item_uri_id)) { if (!empty($this->itemUriId)) {
$condition = DBA::mergeConditions($condition, ['uri-id' => self::$item_uri_id]); $condition = DBA::mergeConditions($condition, ['uri-id' => $this->itemUriId]);
} else { } else {
if (self::$no_sharer) { if ($this->noSharer) {
$condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-engagement`.`uri-id`)", $this->session->getLocalUserId()]); $condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-engagement`.`uri-id`)", $this->session->getLocalUserId()]);
} }
if (isset(self::$max_id)) { if (isset($this->max_id)) {
$condition = DBA::mergeConditions($condition, ["`created` < ?", self::$max_id]); $condition = DBA::mergeConditions($condition, ["`created` < ?", $this->max_id]);
} }
if (isset(self::$min_id)) { if (isset($this->min_id)) {
$condition = DBA::mergeConditions($condition, ["`created` > ?", self::$min_id]); $condition = DBA::mergeConditions($condition, ["`created` > ?", $this->min_id]);
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order // Previous page case: we want the items closest to min_id but for that we need to reverse the query order
if (!isset(self::$max_id)) { if (!isset($this->max_id)) {
$params['order']['created'] = false; $params['order']['created'] = false;
} }
} }
@ -267,7 +263,7 @@ class Timeline extends BaseModule
} }
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order // Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
if (empty(self::$item_uri_id) && isset(self::$min_id) && !isset(self::$max_id)) { if (empty($this->itemUriId) && isset($this->min_id) && !isset($this->max_id)) {
$items = array_reverse($items); $items = array_reverse($items);
} }
@ -375,13 +371,13 @@ class Timeline extends BaseModule
$items = $this->selectItems(); $items = $this->selectItems();
$maxpostperauthor = (int) $this->config->get('system', 'max_author_posts_community_page'); $maxpostperauthor = (int) $this->config->get('system', 'max_author_posts_community_page');
if ($maxpostperauthor != 0 && self::$selectedTab == 'local') { if ($maxpostperauthor != 0 && $this->selectedTab == 'local') {
$count = 1; $count = 1;
$previousauthor = ''; $previousauthor = '';
$numposts = 0; $numposts = 0;
$selected_items = []; $selected_items = [];
while (count($selected_items) < self::$itemsPerPage && ++$count < 50 && count($items) > 0) { while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) {
foreach ($items as $item) { foreach ($items as $item) {
if ($previousauthor == $item["author-link"]) { if ($previousauthor == $item["author-link"]) {
++$numposts; ++$numposts;
@ -390,18 +386,18 @@ class Timeline extends BaseModule
} }
$previousauthor = $item["author-link"]; $previousauthor = $item["author-link"];
if (($numposts < $maxpostperauthor) && (count($selected_items) < self::$itemsPerPage)) { if (($numposts < $maxpostperauthor) && (count($selected_items) < $this->itemsPerPage)) {
$selected_items[] = $item; $selected_items[] = $item;
} }
} }
// If we're looking at a "previous page", the lookup continues forward in time because the list is // If we're looking at a "previous page", the lookup continues forward in time because the list is
// sorted in chronologically decreasing order // sorted in chronologically decreasing order
if (isset(self::$min_id)) { if (isset($this->min_id)) {
self::$min_id = $items[0]['commented']; $this->min_id = $items[0]['commented'];
} else { } else {
// In any other case, the lookup continues backwards in time // In any other case, the lookup continues backwards in time
self::$max_id = $items[count($items) - 1]['commented']; $this->max_id = $items[count($items) - 1]['commented'];
} }
$items = $this->selectItems(); $items = $this->selectItems();
@ -422,15 +418,15 @@ class Timeline extends BaseModule
*/ */
private function selectItems() private function selectItems()
{ {
if (self::$selectedTab == 'local') { if ($this->selectedTab == 'local') {
if (!is_null(self::$accountType)) { if (!is_null($this->accountType)) {
$condition = ["`wall` AND `origin` AND `private` = ? AND `owner-contact-type` = ?", Item::PUBLIC, self::$accountType]; $condition = ["`wall` AND `origin` AND `private` = ? AND `owner-contact-type` = ?", Item::PUBLIC, $this->accountType];
} else { } else {
$condition = ["`wall` AND `origin` AND `private` = ?", Item::PUBLIC]; $condition = ["`wall` AND `origin` AND `private` = ?", Item::PUBLIC];
} }
} elseif (self::$selectedTab == 'global') { } elseif ($this->selectedTab == 'global') {
if (!is_null(self::$accountType)) { if (!is_null($this->accountType)) {
$condition = ["`uid` = ? AND `private` = ? AND `owner-contact-type` = ?", 0, Item::PUBLIC, self::$accountType]; $condition = ["`uid` = ? AND `private` = ? AND `owner-contact-type` = ?", 0, Item::PUBLIC, $this->accountType];
} else { } else {
$condition = ["`uid` = ? AND `private` = ?", 0, Item::PUBLIC]; $condition = ["`uid` = ? AND `private` = ?", 0, Item::PUBLIC];
} }
@ -438,24 +434,24 @@ class Timeline extends BaseModule
return []; return [];
} }
$params = ['order' => ['commented' => true], 'limit' => self::$itemsPerPage]; $params = ['order' => ['commented' => true], 'limit' => $this->itemsPerPage];
if (!empty(self::$item_uri_id)) { if (!empty($this->itemUriId)) {
$condition = DBA::mergeConditions($condition, ['uri-id' => self::$item_uri_id]); $condition = DBA::mergeConditions($condition, ['uri-id' => $this->itemUriId]);
} else { } else {
if ($this->session->getLocalUserId() && self::$no_sharer) { if ($this->session->getLocalUserId() && $this->noSharer) {
$condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-thread-user-view`.`uri-id`)", $this->session->getLocalUserId()]); $condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-thread-user-view`.`uri-id`)", $this->session->getLocalUserId()]);
} }
if (isset(self::$max_id)) { if (isset($this->max_id)) {
$condition = DBA::mergeConditions($condition, ["`commented` < ?", self::$max_id]); $condition = DBA::mergeConditions($condition, ["`commented` < ?", $this->max_id]);
} }
if (isset(self::$min_id)) { if (isset($this->min_id)) {
$condition = DBA::mergeConditions($condition, ["`commented` > ?", self::$min_id]); $condition = DBA::mergeConditions($condition, ["`commented` > ?", $this->min_id]);
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order // Previous page case: we want the items closest to min_id but for that we need to reverse the query order
if (!isset(self::$max_id)) { if (!isset($this->max_id)) {
$params['order']['commented'] = false; $params['order']['commented'] = false;
} }
} }
@ -469,7 +465,7 @@ class Timeline extends BaseModule
} }
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order // Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
if (empty(self::$item_uri_id) && isset(self::$min_id) && !isset(self::$max_id)) { if (empty($this->itemUriId) && isset($this->min_id) && !isset($this->max_id)) {
$items = array_reverse($items); $items = array_reverse($items);
} }

View file

@ -38,7 +38,7 @@ class Channel extends ChannelModule
$o = ''; $o = '';
if (!empty($request['force'])) { if (!empty($request['force'])) {
if ($this->timeline->isChannel(self::$selectedTab)) { if ($this->timeline->isChannel($this->selectedTab)) {
$items = $this->getChannelItems(); $items = $this->getChannelItems();
} else { } else {
$items = $this->getCommunityItems(); $items = $this->getCommunityItems();

View file

@ -65,7 +65,7 @@ class Network extends NetworkModule
$conditionFields['unseen'] = true; $conditionFields['unseen'] = true;
} }
$params = ['limit' => self::$itemsPerPage]; $params = ['limit' => $this->itemsPerPage];
$table = 'network-thread-view'; $table = 'network-thread-view';
$items = $this->getItems($table, $params, $conditionFields); $items = $this->getItems($table, $params, $conditionFields);