friendica/src/Module/Profile/Status.php

234 lines
9.2 KiB
PHP
Raw Normal View History

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