3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Profile;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Widget;
27 use Friendica\Core\ACL;
28 use Friendica\Core\Protocol;
29 use Friendica\Core\Session;
30 use Friendica\Database\DBA;
32 use Friendica\Model\Contact;
33 use Friendica\Model\Item;
34 use Friendica\Model\Post;
35 use Friendica\Model\Post\Category;
36 use Friendica\Model\Profile as ProfileModel;
37 use Friendica\Model\User;
38 use Friendica\Model\Verb;
39 use Friendica\Module\BaseProfile;
40 use Friendica\Module\Security\Login;
41 use Friendica\Network\HTTPException;
42 use Friendica\Protocol\Activity;
43 use Friendica\Util\DateTimeFormat;
44 use Friendica\Security\Security;
45 use Friendica\Util\Strings;
46 use Friendica\Util\XML;
48 class Status extends BaseProfile
50 protected function content(array $request = []): string
56 $profile = ProfileModel::load($a, $this->parameters['nickname']);
58 if (empty($profile)) {
59 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
62 if (!$profile['net-publish']) {
63 DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
66 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";
67 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";
68 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";
69 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";
71 $category = $datequery = $datequery2 = '';
73 $dtFormat = DI::dtFormat();
75 if ($args->getArgc() > 3) {
76 for ($x = 3; $x < $args->getArgc(); $x++) {
77 if ($dtFormat->isYearMonthDay($args->get($x))) {
79 $datequery2 = Strings::escapeHtml($args->get($x));
81 $datequery = Strings::escapeHtml($args->get($x));
84 $category = $args->get($x);
89 if (empty($category)) {
90 $category = $_GET['category'] ?? '';
93 $hashtags = $_GET['tag'] ?? '';
95 if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($profile['uid'])) {
101 if ($profile['uid'] == local_user()) {
102 Nav::setSelected('home');
105 $remote_contact = Session::getRemoteContactID($profile['uid']);
106 $is_owner = local_user() == $profile['uid'];
107 $last_updated_key = "profile:" . $profile['uid'] . ":" . local_user() . ":" . $remote_contact;
109 if (!empty($profile['hidewall']) && !$is_owner && !$remote_contact) {
110 DI::sysmsg()->addNotice(DI::l10n()->t('Access to this profile has been restricted.'));
114 $o .= self::getTabsHTML($a, 'status', $is_owner, $profile['nickname'], $profile['hide-friends']);
116 $o .= Widget::commonFriendsVisitor($profile['uid'], $profile['nickname']);
118 $commpage = $profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
119 $commvisitor = $commpage && $remote_contact;
121 DI::page()['aside'] .= Widget::postedByYear(DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', $profile['profile_uid'] ?? 0, true);
122 DI::page()['aside'] .= Widget::categories($profile['uid'], DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', $category);
123 DI::page()['aside'] .= Widget::tagCloud($profile['uid']);
125 if (Security::canWriteToUserWall($profile['uid'])) {
127 'is_owner' => $is_owner,
128 'allow_location' => ($is_owner || $commvisitor) && $profile['allow_location'],
129 'default_location' => $is_owner ? $profile['default-location'] : '',
130 'nickname' => $profile['nickname'],
131 'acl' => $is_owner ? ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), true) : '',
132 'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
133 'profile_uid' => $profile['uid'],
136 $o .= DI::conversation()->statusEditor($x);
139 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
140 $condition = Item::getPermissionsConditionArrayByUserId($profile['uid']);
142 $last_updated_array = DI::session()->get('last_updated', []);
144 if (!empty($category)) {
145 $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `category-view` WHERE `name` = ? AND `type` = ? AND `uid` = ?)",
146 $category, Category::CATEGORY, $profile['uid']]);
149 if (!empty($hashtags)) {
150 $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `tag-search-view` WHERE `name` = ? AND `uid` = ?)",
151 $hashtags, $profile['uid']]);
154 if (!empty($datequery)) {
155 $condition = DBA::mergeConditions($condition, ["`received` <= ?", DateTimeFormat::convert($datequery, 'UTC', $a->getTimeZone())]);
157 if (!empty($datequery2)) {
158 $condition = DBA::mergeConditions($condition, ["`received` >= ?", DateTimeFormat::convert($datequery2, 'UTC', $a->getTimeZone())]);
161 // Does the profile page belong to a forum?
162 // If not then we can improve the performance with an additional condition
163 $condition2 = ['uid' => $profile['uid'], 'account-type' => User::ACCOUNT_TYPE_COMMUNITY];
164 if (!DBA::exists('user', $condition2)) {
165 $condition = DBA::mergeConditions($condition, ['contact-id' => $profile['id']]);
168 if (DI::mode()->isMobile()) {
169 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
170 DI::config()->get('system', 'itemspage_network_mobile'));
172 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
173 DI::config()->get('system', 'itemspage_network'));
176 $condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
177 (`gravity` = ? AND `vid` = ? AND `origin`
178 AND `thr-parent-id` IN (SELECT `uri-id` FROM `post` WHERE `gravity` = ? AND `network` = ?)))",
179 Item::GRAVITY_PARENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Item::GRAVITY_PARENT, Protocol::ACTIVITYPUB]);
181 $condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED,
182 'visible' => true, 'deleted' => false]);
184 $pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
185 $params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]];
187 $items_stmt = Post::select(['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'received'], $condition, $params);
189 // Set a time stamp for this page. We will make use of it when we
190 // search for new items (update routine)
191 $last_updated_array[$last_updated_key] = time();
192 Session::set('last_updated', $last_updated_array);
194 if ($is_owner && !DI::config()->get('theme', 'hide_eventlist')) {
195 $o .= ProfileModel::getBirthdays();
196 $o .= ProfileModel::getEventsReminderHTML();
200 $unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
202 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
206 $items = Post::toArray($items_stmt);
208 if ($pager->getStart() == 0 && !empty($profile['uid'])) {
209 $pcid = Contact::getPublicIdByUserId($profile['uid']);
210 $pinned = Post\Collection::selectToArrayForContact($pcid, Post\Collection::FEATURED);
211 $items = array_merge($items, $pinned);
214 $o .= DI::conversation()->create($items, 'profile', false, false, 'pinned_received', $profile['uid']);
216 $o .= $pager->renderMinimal(count($items));