2019-10-27 10:08:14 -04:00
|
|
|
<?php
|
2020-02-09 09:45:36 -05:00
|
|
|
/**
|
2022-01-02 02:27:47 -05:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2020-02-09 09:45:36 -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/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-10-27 10:08:14 -04:00
|
|
|
|
|
|
|
namespace Friendica\Module\Profile;
|
|
|
|
|
|
|
|
use Friendica\Content\Nav;
|
|
|
|
use Friendica\Content\Pager;
|
|
|
|
use Friendica\Content\Widget;
|
|
|
|
use Friendica\Core\ACL;
|
2020-11-03 14:24:47 -05:00
|
|
|
use Friendica\Core\Protocol;
|
2019-10-27 10:08:14 -04:00
|
|
|
use Friendica\Core\Session;
|
|
|
|
use Friendica\Database\DBA;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Model\Item;
|
2021-01-15 23:16:09 -05:00
|
|
|
use Friendica\Model\Post;
|
2020-05-03 11:13:40 -04:00
|
|
|
use Friendica\Model\Post\Category;
|
2019-10-27 10:08:14 -04:00
|
|
|
use Friendica\Model\Profile as ProfileModel;
|
|
|
|
use Friendica\Model\User;
|
2020-11-03 14:24:47 -05:00
|
|
|
use Friendica\Model\Verb;
|
2020-01-26 09:49:11 -05:00
|
|
|
use Friendica\Module\BaseProfile;
|
2019-10-27 10:08:14 -04:00
|
|
|
use Friendica\Module\Security\Login;
|
2020-07-08 09:49:39 -04:00
|
|
|
use Friendica\Network\HTTPException;
|
2020-11-03 14:24:47 -05:00
|
|
|
use Friendica\Protocol\Activity;
|
2019-10-27 10:08:14 -04:00
|
|
|
use Friendica\Util\DateTimeFormat;
|
2020-09-30 05:14:01 -04:00
|
|
|
use Friendica\Security\Security;
|
2019-10-27 10:08:14 -04:00
|
|
|
use Friendica\Util\Strings;
|
|
|
|
use Friendica\Util\XML;
|
|
|
|
|
2020-01-26 09:49:11 -05:00
|
|
|
class Status extends BaseProfile
|
2019-10-27 10:08:14 -04:00
|
|
|
{
|
2021-11-20 09:38:03 -05:00
|
|
|
protected function content(array $request = []): string
|
2019-10-27 10:08:14 -04:00
|
|
|
{
|
|
|
|
$args = DI::args();
|
|
|
|
|
|
|
|
$a = DI::app();
|
|
|
|
|
2021-11-14 17:19:25 -05:00
|
|
|
$profile = ProfileModel::load($a, $this->parameters['nickname']);
|
2019-10-27 10:08:14 -04:00
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
if (empty($profile)) {
|
2020-07-08 09:49:39 -04:00
|
|
|
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
|
|
|
}
|
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
if (!$profile['net-publish']) {
|
2019-10-27 10:08:14 -04:00
|
|
|
DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
|
|
|
|
}
|
|
|
|
|
2021-11-14 17:19:25 -05:00
|
|
|
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/dfrn_poll/' . $this->parameters['nickname'] . '" title="DFRN: ' . DI::l10n()->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
|
|
|
|
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $this->parameters['nickname'] . '/" title="' . DI::l10n()->t('%s\'s posts', $profile['name']) . '"/>' . "\n";
|
|
|
|
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $this->parameters['nickname'] . '/comments" title="' . DI::l10n()->t('%s\'s comments', $profile['name']) . '"/>' . "\n";
|
|
|
|
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $this->parameters['nickname'] . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
|
2019-10-27 10:08:14 -04:00
|
|
|
|
|
|
|
$category = $datequery = $datequery2 = '';
|
|
|
|
|
|
|
|
$dtFormat = DI::dtFormat();
|
|
|
|
|
2020-01-25 16:23:09 -05:00
|
|
|
if ($args->getArgc() > 3) {
|
|
|
|
for ($x = 3; $x < $args->getArgc(); $x++) {
|
2020-02-01 08:06:35 -05:00
|
|
|
if ($dtFormat->isYearMonthDay($args->get($x))) {
|
2019-10-27 10:08:14 -04:00
|
|
|
if ($datequery) {
|
|
|
|
$datequery2 = Strings::escapeHtml($args->get($x));
|
|
|
|
} else {
|
|
|
|
$datequery = Strings::escapeHtml($args->get($x));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$category = $args->get($x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($category)) {
|
|
|
|
$category = $_GET['category'] ?? '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$hashtags = $_GET['tag'] ?? '';
|
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($profile['uid'])) {
|
2019-10-27 10:08:14 -04:00
|
|
|
return Login::form();
|
|
|
|
}
|
|
|
|
|
|
|
|
$o = '';
|
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
if ($profile['uid'] == local_user()) {
|
2019-10-27 10:08:14 -04:00
|
|
|
Nav::setSelected('home');
|
|
|
|
}
|
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
$remote_contact = Session::getRemoteContactID($profile['uid']);
|
|
|
|
$is_owner = local_user() == $profile['uid'];
|
|
|
|
$last_updated_key = "profile:" . $profile['uid'] . ":" . local_user() . ":" . $remote_contact;
|
2019-10-27 10:08:14 -04:00
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
if (!empty($profile['hidewall']) && !$is_owner && !$remote_contact) {
|
2020-07-23 02:25:01 -04:00
|
|
|
notice(DI::l10n()->t('Access to this profile has been restricted.'));
|
2019-10-27 10:08:14 -04:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2021-08-08 06:14:56 -04:00
|
|
|
$o .= self::getTabsHTML($a, 'status', $is_owner, $profile['nickname'], $profile['hide-friends']);
|
2019-10-27 10:08:14 -04:00
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
$o .= Widget::commonFriendsVisitor($profile['uid'], $profile['nickname']);
|
2019-10-27 10:08:14 -04:00
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
$commpage = $profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
|
2019-10-27 10:08:14 -04:00
|
|
|
$commvisitor = $commpage && $remote_contact;
|
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
DI::page()['aside'] .= Widget::postedByYear(DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', $profile['profile_uid'] ?? 0, true);
|
2022-02-18 23:58:23 -05:00
|
|
|
DI::page()['aside'] .= Widget::categories($profile['uid'], DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', $category);
|
2021-07-24 06:09:39 -04:00
|
|
|
DI::page()['aside'] .= Widget::tagCloud($profile['uid']);
|
2019-10-27 10:08:14 -04:00
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
if (Security::canWriteToUserWall($profile['uid'])) {
|
2019-10-27 10:08:14 -04:00
|
|
|
$x = [
|
|
|
|
'is_owner' => $is_owner,
|
2021-07-24 06:09:39 -04:00
|
|
|
'allow_location' => ($is_owner || $commvisitor) && $profile['allow_location'],
|
2021-08-08 15:30:21 -04:00
|
|
|
'default_location' => $is_owner ? $profile['default-location'] : '',
|
2021-07-24 06:09:39 -04:00
|
|
|
'nickname' => $profile['nickname'],
|
2021-08-09 16:33:46 -04:00
|
|
|
'acl' => $is_owner ? ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), true) : '',
|
2019-10-27 10:08:14 -04:00
|
|
|
'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
|
2021-07-24 06:09:39 -04:00
|
|
|
'profile_uid' => $profile['uid'],
|
2019-10-27 10:08:14 -04:00
|
|
|
];
|
|
|
|
|
2021-09-23 17:18:36 -04:00
|
|
|
$o .= DI::conversation()->statusEditor($x);
|
2019-10-27 10:08:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
|
2021-07-24 06:09:39 -04:00
|
|
|
$condition = Item::getPermissionsConditionArrayByUserId($profile['uid']);
|
2019-10-27 10:08:14 -04:00
|
|
|
|
|
|
|
$last_updated_array = Session::get('last_updated', []);
|
|
|
|
|
|
|
|
if (!empty($category)) {
|
2020-11-03 14:24:47 -05:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `category-view` WHERE `name` = ? AND `type` = ? AND `uid` = ?)",
|
2021-07-24 06:09:39 -04:00
|
|
|
$category, Category::CATEGORY, $profile['uid']]);
|
2019-10-27 10:08:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($hashtags)) {
|
2020-11-03 14:24:47 -05:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `tag-search-view` WHERE `name` = ? AND `uid` = ?)",
|
2021-07-24 06:09:39 -04:00
|
|
|
$hashtags, $profile['uid']]);
|
2019-10-27 10:08:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($datequery)) {
|
2021-10-03 12:38:47 -04:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`received` <= ?", DateTimeFormat::convert($datequery, 'UTC', $a->getTimeZone())]);
|
2019-10-27 10:08:14 -04:00
|
|
|
}
|
|
|
|
if (!empty($datequery2)) {
|
2021-10-03 12:38:47 -04:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`received` >= ?", DateTimeFormat::convert($datequery2, 'UTC', $a->getTimeZone())]);
|
2019-10-27 10:08:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Does the profile page belong to a forum?
|
|
|
|
// If not then we can improve the performance with an additional condition
|
2022-02-09 00:56:12 -05:00
|
|
|
$condition2 = ['uid' => $profile['uid'], 'account-type' => User::ACCOUNT_TYPE_COMMUNITY];
|
2020-11-03 14:24:47 -05:00
|
|
|
if (!DBA::exists('user', $condition2)) {
|
2021-07-24 06:09:39 -04:00
|
|
|
$condition = DBA::mergeConditions($condition, ['contact-id' => $profile['id']]);
|
2019-10-27 10:08:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DI::mode()->isMobile()) {
|
2020-02-16 13:04:26 -05:00
|
|
|
$itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
|
|
|
|
DI::config()->get('system', 'itemspage_network_mobile'));
|
2019-10-27 10:08:14 -04:00
|
|
|
} else {
|
2020-02-16 13:04:26 -05:00
|
|
|
$itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
|
|
|
|
DI::config()->get('system', 'itemspage_network'));
|
2019-10-27 10:08:14 -04:00
|
|
|
}
|
|
|
|
|
2020-11-03 14:24:47 -05:00
|
|
|
$condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
|
2021-02-22 14:47:08 -05:00
|
|
|
(`gravity` = ? AND `vid` = ? AND `origin`
|
|
|
|
AND EXISTS(SELECT `uri-id` FROM `post` WHERE `gravity` = ? AND `network` IN (?, ?, ?, ?)
|
|
|
|
AND `uri-id` = `post-user-view`.`thr-parent-id`)))",
|
2020-11-03 14:24:47 -05:00
|
|
|
GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT,
|
2021-02-22 14:47:08 -05:00
|
|
|
Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::OSTATUS]);
|
2020-11-03 14:24:47 -05:00
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
$condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED,
|
2021-02-13 14:56:03 -05:00
|
|
|
'visible' => true, 'deleted' => false]);
|
2020-11-03 14:24:47 -05:00
|
|
|
|
2020-02-16 11:53:52 -05:00
|
|
|
$pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
|
2020-11-03 14:24:47 -05:00
|
|
|
$params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]];
|
2019-10-27 10:08:14 -04:00
|
|
|
|
2021-01-27 05:01:42 -05:00
|
|
|
$items_stmt = Post::select(['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'received'], $condition, $params);
|
2019-10-27 10:08:14 -04: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();
|
|
|
|
Session::set('last_updated', $last_updated_array);
|
|
|
|
|
|
|
|
if ($is_owner && !DI::config()->get('theme', 'hide_eventlist')) {
|
|
|
|
$o .= ProfileModel::getBirthdays();
|
|
|
|
$o .= ProfileModel::getEventsReminderHTML();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($is_owner) {
|
2021-01-15 23:16:09 -05:00
|
|
|
$unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
|
2019-10-27 10:08:14 -04:00
|
|
|
if ($unseen) {
|
|
|
|
Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-16 17:37:27 -05:00
|
|
|
$items = Post::toArray($items_stmt);
|
2019-10-27 10:08:14 -04:00
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
if ($pager->getStart() == 0 && !empty($profile['uid'])) {
|
2020-09-06 11:05:42 -04:00
|
|
|
$condition = ['private' => [Item::PUBLIC, Item::UNLISTED]];
|
2021-07-24 06:09:39 -04:00
|
|
|
$remote_user = Session::getRemoteContactID($profile['uid']);
|
2020-11-03 14:24:47 -05:00
|
|
|
if (!empty($remote_user)) {
|
2021-07-24 06:09:39 -04:00
|
|
|
$permissionSets = DI::permissionSet()->selectByContactId($remote_user, $profile['uid']);
|
2020-09-06 11:05:42 -04:00
|
|
|
if (!empty($permissionSets)) {
|
|
|
|
$condition = ['psid' => array_merge($permissionSets->column('id'),
|
2021-10-17 17:12:26 -04:00
|
|
|
[DI::permissionSet()->selectPublicForUser($profile['uid'])->id])];
|
2020-09-06 11:05:42 -04:00
|
|
|
}
|
2021-07-24 06:09:39 -04:00
|
|
|
} elseif ($profile['uid'] == local_user()) {
|
2020-09-06 11:05:42 -04:00
|
|
|
$condition = [];
|
|
|
|
}
|
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
$pinned_items = Post::selectPinned($profile['uid'], ['uri-id', 'pinned'], $condition);
|
2021-01-19 02:23:01 -05:00
|
|
|
$pinned = Post::toArray($pinned_items);
|
2020-01-26 14:14:36 -05:00
|
|
|
$items = array_merge($items, $pinned);
|
|
|
|
}
|
|
|
|
|
2021-09-23 17:18:36 -04:00
|
|
|
$o .= DI::conversation()->create($items, 'profile', false, false, 'pinned_received', $profile['uid']);
|
2019-10-27 10:08:14 -04:00
|
|
|
|
|
|
|
$o .= $pager->renderMinimal(count($items));
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|