2019-10-27 14:08:14 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
2023-01-01 14:36:24 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2020-02-09 14:45:36 +00: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/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-10-27 14:08:14 +00:00
|
|
|
|
|
|
|
namespace Friendica\Module\Profile;
|
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
use Friendica\App;
|
|
|
|
use Friendica\Content\Conversation;
|
2019-10-27 14:08:14 +00:00
|
|
|
use Friendica\Content\Nav;
|
|
|
|
use Friendica\Content\Pager;
|
|
|
|
use Friendica\Content\Widget;
|
|
|
|
use Friendica\Core\ACL;
|
2022-12-19 14:23:20 +00:00
|
|
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
|
|
|
use Friendica\Core\L10n;
|
|
|
|
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
2020-11-03 19:24:47 +00:00
|
|
|
use Friendica\Core\Protocol;
|
2022-12-19 14:23:20 +00:00
|
|
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
2019-10-27 14:08:14 +00:00
|
|
|
use Friendica\Database\DBA;
|
2022-04-07 21:52:25 +00:00
|
|
|
use Friendica\Model\Contact;
|
2019-10-27 14:08:14 +00:00
|
|
|
use Friendica\Model\Item;
|
2021-01-16 04:16:09 +00:00
|
|
|
use Friendica\Model\Post;
|
2020-05-03 15:13:40 +00:00
|
|
|
use Friendica\Model\Post\Category;
|
2019-10-27 14:08:14 +00:00
|
|
|
use Friendica\Model\Profile as ProfileModel;
|
|
|
|
use Friendica\Model\User;
|
2020-11-03 19:24:47 +00:00
|
|
|
use Friendica\Model\Verb;
|
2020-01-26 14:49:11 +00:00
|
|
|
use Friendica\Module\BaseProfile;
|
2022-12-19 14:23:20 +00:00
|
|
|
use Friendica\Module\Response;
|
2019-10-27 14:08:14 +00:00
|
|
|
use Friendica\Module\Security\Login;
|
2020-07-08 13:49:39 +00:00
|
|
|
use Friendica\Network\HTTPException;
|
2020-11-03 19:24:47 +00:00
|
|
|
use Friendica\Protocol\Activity;
|
2020-09-30 09:14:01 +00:00
|
|
|
use Friendica\Security\Security;
|
2022-12-19 14:23:20 +00:00
|
|
|
use Friendica\Util\DateTimeFormat;
|
|
|
|
use Friendica\Util\Profiler;
|
2019-10-27 14:08:14 +00:00
|
|
|
use Friendica\Util\Strings;
|
2022-12-19 14:23:20 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2023-01-08 06:32:18 +00:00
|
|
|
class Conversations extends BaseProfile
|
2019-10-27 14:08:14 +00:00
|
|
|
{
|
2022-12-19 14:23:20 +00:00
|
|
|
/** @var App */
|
|
|
|
private $app;
|
|
|
|
/** @var App\Page */
|
|
|
|
private $page;
|
|
|
|
/** @var DateTimeFormat */
|
|
|
|
private $dateTimeFormat;
|
|
|
|
/** @var IManageConfigValues */
|
|
|
|
private $config;
|
|
|
|
/** @var IHandleUserSessions */
|
|
|
|
private $session;
|
|
|
|
/** @var Conversation */
|
|
|
|
private $conversation;
|
|
|
|
/** @var IManagePersonalConfigValues */
|
|
|
|
private $pConfig;
|
|
|
|
/** @var App\Mode */
|
|
|
|
private $mode;
|
|
|
|
|
|
|
|
public function __construct(App\Mode $mode, IManagePersonalConfigValues $pConfig, Conversation $conversation, IHandleUserSessions $session, IManageConfigValues $config, DateTimeFormat $dateTimeFormat, App\Page $page, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
2019-10-27 14:08:14 +00:00
|
|
|
{
|
2022-12-19 14:23:20 +00:00
|
|
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
|
|
|
|
|
|
|
$this->app = $app;
|
|
|
|
$this->page = $page;
|
|
|
|
$this->dateTimeFormat = $dateTimeFormat;
|
|
|
|
$this->config = $config;
|
|
|
|
$this->session = $session;
|
|
|
|
$this->conversation = $conversation;
|
|
|
|
$this->pConfig = $pConfig;
|
|
|
|
$this->mode = $mode;
|
|
|
|
}
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
protected function content(array $request = []): string
|
|
|
|
{
|
|
|
|
$profile = ProfileModel::load($this->app, $this->parameters['nickname'] ?? '');
|
|
|
|
if (empty($profile)) {
|
|
|
|
throw new HTTPException\NotFoundException($this->t('User not found.'));
|
|
|
|
}
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
if ($this->config->get('system', 'block_public') && !$this->session->isAuthenticated()) {
|
|
|
|
return Login::form();
|
|
|
|
}
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
if (!empty($profile['hidewall']) && !$this->session->isAuthenticated()) {
|
|
|
|
$this->baseUrl->redirect('profile/' . $profile['nickname'] . '/restricted');
|
2020-07-08 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 10:09:39 +00:00
|
|
|
if (!$profile['net-publish']) {
|
2022-12-19 14:23:20 +00:00
|
|
|
$this->page['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/dfrn_poll/' . $this->parameters['nickname'] . '" title="DFRN: ' . $this->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
|
|
|
|
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/feed/' . $this->parameters['nickname'] . '/" title="' . $this->t('%s\'s posts', $profile['name']) . '"/>' . "\n";
|
|
|
|
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/feed/' . $this->parameters['nickname'] . '/comments" title="' . $this->t('%s\'s comments', $profile['name']) . '"/>' . "\n";
|
|
|
|
$this->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $this->baseUrl . '/feed/' . $this->parameters['nickname'] . '/activity" title="' . $this->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
|
2019-10-27 14:08:14 +00:00
|
|
|
|
|
|
|
$category = $datequery = $datequery2 = '';
|
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
if ($this->args->getArgc() > 3) {
|
|
|
|
for ($x = 3; $x < $this->args->getArgc(); $x++) {
|
|
|
|
if ($this->dateTimeFormat->isYearMonthDay($this->args->get($x))) {
|
2019-10-27 14:08:14 +00:00
|
|
|
if ($datequery) {
|
2022-12-19 14:23:20 +00:00
|
|
|
$datequery2 = $this->args->get($x);
|
2019-10-27 14:08:14 +00:00
|
|
|
} else {
|
2022-12-19 14:23:20 +00:00
|
|
|
$datequery = $this->args->get($x);
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-12-19 14:23:20 +00:00
|
|
|
$category = $this->args->get($x);
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($category)) {
|
2022-12-19 14:23:20 +00:00
|
|
|
$category = $request['category'] ?? '';
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
$hashtags = $request['tag'] ?? '';
|
2019-10-27 14:08:14 +00:00
|
|
|
|
|
|
|
$o = '';
|
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
if ($profile['uid'] == $this->session->getLocalUserId()) {
|
2019-10-27 14:08:14 +00:00
|
|
|
Nav::setSelected('home');
|
|
|
|
}
|
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
$remote_contact = $this->session->getRemoteContactID($profile['uid']);
|
|
|
|
$is_owner = $this->session->getLocalUserId() == $profile['uid'];
|
|
|
|
$last_updated_key = "profile:" . $profile['uid'] . ":" . $this->session->getLocalUserId() . ":" . $remote_contact;
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2022-11-30 19:38:23 +00:00
|
|
|
$o .= self::getTabsHTML('status', $is_owner, $profile['nickname'], $profile['hide-friends']);
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2021-07-24 10:09:39 +00:00
|
|
|
$o .= Widget::commonFriendsVisitor($profile['uid'], $profile['nickname']);
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
$commpage = $profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
|
2019-10-27 14:08:14 +00:00
|
|
|
$commvisitor = $commpage && $remote_contact;
|
|
|
|
|
2023-01-08 06:32:18 +00:00
|
|
|
$this->page['aside'] .= Widget::postedByYear($this->baseUrl . '/profile/' . $profile['nickname'] . '/conversations', $profile['profile_uid'] ?? 0, true);
|
|
|
|
$this->page['aside'] .= Widget::categories($profile['uid'], $this->baseUrl . '/profile/' . $profile['nickname'] . '/conversations', $category);
|
2022-12-19 14:23:20 +00:00
|
|
|
$this->page['aside'] .= Widget::tagCloud($profile['uid']);
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2021-07-24 10:09:39 +00:00
|
|
|
if (Security::canWriteToUserWall($profile['uid'])) {
|
2019-10-27 14:08:14 +00:00
|
|
|
$x = [
|
2022-12-19 14:23:20 +00:00
|
|
|
'is_owner' => $is_owner,
|
|
|
|
'allow_location' => ($is_owner || $commvisitor) && $profile['allow_location'],
|
2021-08-08 19:30:21 +00:00
|
|
|
'default_location' => $is_owner ? $profile['default-location'] : '',
|
2022-12-19 14:23:20 +00:00
|
|
|
'nickname' => $profile['nickname'],
|
|
|
|
'acl' => $is_owner ? ACL::getFullSelectorHTML($this->page, $this->app->getLoggedInUserId(), true) : '',
|
|
|
|
'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
|
|
|
|
'profile_uid' => $profile['uid'],
|
2019-10-27 14:08:14 +00:00
|
|
|
];
|
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
$o .= $this->conversation->statusEditor($x);
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
// Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched their circles
|
2021-07-24 10:09:39 +00:00
|
|
|
$condition = Item::getPermissionsConditionArrayByUserId($profile['uid']);
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
$last_updated_array = $this->session->get('last_updated', []);
|
2019-10-27 14:08:14 +00:00
|
|
|
|
|
|
|
if (!empty($category)) {
|
2020-11-03 19:24:47 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `category-view` WHERE `name` = ? AND `type` = ? AND `uid` = ?)",
|
2022-12-19 14:23:20 +00:00
|
|
|
$category, Category::CATEGORY, $profile['uid']]);
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($hashtags)) {
|
2020-11-03 19:24:47 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `tag-search-view` WHERE `name` = ? AND `uid` = ?)",
|
2022-12-19 14:23:20 +00:00
|
|
|
$hashtags, $profile['uid']]);
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($datequery)) {
|
2022-12-19 14:23:20 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`received` <= ?", DateTimeFormat::convert($datequery, 'UTC', $this->app->getTimeZone())]);
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
2022-12-19 14:23:20 +00:00
|
|
|
|
2019-10-27 14:08:14 +00:00
|
|
|
if (!empty($datequery2)) {
|
2022-12-19 14:23:20 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`received` >= ?", DateTimeFormat::convert($datequery2, 'UTC', $this->app->getTimeZone())]);
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Does the profile page belong to a forum?
|
|
|
|
// If not then we can improve the performance with an additional condition
|
2022-12-19 14:23:20 +00:00
|
|
|
if ($profile['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
|
2021-07-24 10:09:39 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ['contact-id' => $profile['id']]);
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
if ($this->mode->isMobile()) {
|
|
|
|
$itemspage_network = $this->pConfig->get($this->session->getLocalUserId(), 'system', 'itemspage_mobile_network',
|
|
|
|
$this->config->get('system', 'itemspage_network_mobile'));
|
2019-10-27 14:08:14 +00:00
|
|
|
} else {
|
2022-12-19 14:23:20 +00:00
|
|
|
$itemspage_network = $this->pConfig->get($this->session->getLocalUserId(), 'system', 'itemspage_network',
|
|
|
|
$this->config->get('system', 'itemspage_network'));
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 19:24:47 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
|
2021-02-22 19:47:08 +00:00
|
|
|
(`gravity` = ? AND `vid` = ? AND `origin`
|
2022-12-04 21:57:58 +00:00
|
|
|
AND EXISTS(SELECT `uri-id` FROM `post` WHERE `uri-id` = `post-user-view`.`thr-parent-id` AND `gravity` = ? AND `network` IN (?, ?))))",
|
2022-12-19 14:23:20 +00:00
|
|
|
Item::GRAVITY_PARENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Item::GRAVITY_PARENT, Protocol::ACTIVITYPUB, Protocol::DFRN]);
|
2020-11-03 19:24:47 +00:00
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED,
|
|
|
|
'visible' => true, 'deleted' => false]);
|
2020-11-03 19:24:47 +00:00
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
$pager = new Pager($this->l10n, $this->args->getQueryString(), $itemspage_network);
|
2020-11-03 19:24:47 +00:00
|
|
|
$params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]];
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2021-01-27 10:01:42 +00:00
|
|
|
$items_stmt = Post::select(['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'received'], $condition, $params);
|
2019-10-27 14:08:14 +00:00
|
|
|
|
|
|
|
// Set a time stamp for this page. We will make use of it when we
|
|
|
|
// search for new items (update routine)
|
|
|
|
$last_updated_array[$last_updated_key] = time();
|
2022-12-19 14:23:20 +00:00
|
|
|
$this->session->set('last_updated', $last_updated_array);
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2022-12-19 14:23:20 +00:00
|
|
|
if ($is_owner && !$this->config->get('theme', 'hide_eventlist')) {
|
2019-10-27 14:08:14 +00:00
|
|
|
$o .= ProfileModel::getBirthdays();
|
|
|
|
$o .= ProfileModel::getEventsReminderHTML();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($is_owner) {
|
2022-12-19 14:23:20 +00:00
|
|
|
$unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => $this->session->getLocalUserId()]);
|
2019-10-27 14:08:14 +00:00
|
|
|
if ($unseen) {
|
2022-12-19 14:23:20 +00:00
|
|
|
Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => $this->session->getLocalUserId()]);
|
2019-10-27 14:08:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-16 22:37:27 +00:00
|
|
|
$items = Post::toArray($items_stmt);
|
2019-10-27 14:08:14 +00:00
|
|
|
|
2021-07-24 10:09:39 +00:00
|
|
|
if ($pager->getStart() == 0 && !empty($profile['uid'])) {
|
2022-12-19 14:23:20 +00:00
|
|
|
$pcid = Contact::getPublicIdByUserId($profile['uid']);
|
2022-04-08 06:04:50 +00:00
|
|
|
$pinned = Post\Collection::selectToArrayForContact($pcid, Post\Collection::FEATURED);
|
2022-12-19 14:23:20 +00:00
|
|
|
$items = array_merge($items, $pinned);
|
2020-01-26 19:14:36 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 06:25:55 +00:00
|
|
|
$o .= $this->conversation->create($items, Conversation::MODE_PROFILE, false, false, 'pinned_received', $profile['uid']);
|
2019-10-27 14:08:14 +00:00
|
|
|
|
|
|
|
$o .= $pager->renderMinimal(count($items));
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|