]> git.mxchange.org Git - friendica.git/blob - src/Module/Profile/Status.php
Remove unused first parameter from BaseProfile::getTabsHTML
[friendica.git] / src / Module / Profile / Status.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Module\Profile;
23
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\Database\DBA;
30 use Friendica\DI;
31 use Friendica\Model\Contact;
32 use Friendica\Model\Item;
33 use Friendica\Model\Post;
34 use Friendica\Model\Post\Category;
35 use Friendica\Model\Profile as ProfileModel;
36 use Friendica\Model\User;
37 use Friendica\Model\Verb;
38 use Friendica\Module\BaseProfile;
39 use Friendica\Module\Security\Login;
40 use Friendica\Network\HTTPException;
41 use Friendica\Protocol\Activity;
42 use Friendica\Util\DateTimeFormat;
43 use Friendica\Security\Security;
44 use Friendica\Util\Strings;
45 use Friendica\Util\XML;
46
47 class Status extends BaseProfile
48 {
49         protected function content(array $request = []): string
50         {
51                 $args = DI::args();
52
53                 $a = DI::app();
54
55                 $profile = ProfileModel::load($a, $this->parameters['nickname']);
56
57                 if (empty($profile)) {
58                         throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
59                 }
60
61                 if (!$profile['net-publish']) {
62                         DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
63                 }
64
65                 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";
66                 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";
67                 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";
68                 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";
69
70                 $category = $datequery = $datequery2 = '';
71
72                 $dtFormat = DI::dtFormat();
73
74                 if ($args->getArgc() > 3) {
75                         for ($x = 3; $x < $args->getArgc(); $x++) {
76                                 if ($dtFormat->isYearMonthDay($args->get($x))) {
77                                         if ($datequery) {
78                                                 $datequery2 = Strings::escapeHtml($args->get($x));
79                                         } else {
80                                                 $datequery = Strings::escapeHtml($args->get($x));
81                                         }
82                                 } else {
83                                         $category = $args->get($x);
84                                 }
85                         }
86                 }
87
88                 if (empty($category)) {
89                         $category = $_GET['category'] ?? '';
90                 }
91
92                 $hashtags = $_GET['tag'] ?? '';
93
94                 if (DI::config()->get('system', 'block_public') && !DI::userSession()->getLocalUserId() && !DI::userSession()->getRemoteContactID($profile['uid'])) {
95                         return Login::form();
96                 }
97
98                 $o = '';
99
100                 if ($profile['uid'] == DI::userSession()->getLocalUserId()) {
101                         Nav::setSelected('home');
102                 }
103
104                 $remote_contact = DI::userSession()->getRemoteContactID($profile['uid']);
105                 $is_owner = DI::userSession()->getLocalUserId() == $profile['uid'];
106                 $last_updated_key = "profile:" . $profile['uid'] . ":" . DI::userSession()->getLocalUserId() . ":" . $remote_contact;
107
108                 if (!empty($profile['hidewall']) && !DI::userSession()->isAuthenticated()) {
109                         $this->baseUrl->redirect('profile/' . $profile['nickname'] . '/restricted');
110                 }
111
112                 $o .= self::getTabsHTML('status', $is_owner, $profile['nickname'], $profile['hide-friends']);
113
114                 $o .= Widget::commonFriendsVisitor($profile['uid'], $profile['nickname']);
115
116                 $commpage = $profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
117                 $commvisitor = $commpage && $remote_contact;
118
119                 DI::page()['aside'] .= Widget::postedByYear(DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', $profile['profile_uid'] ?? 0, true);
120                 DI::page()['aside'] .= Widget::categories($profile['uid'], DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', $category);
121                 DI::page()['aside'] .= Widget::tagCloud($profile['uid']);
122
123                 if (Security::canWriteToUserWall($profile['uid'])) {
124                         $x = [
125                                 'is_owner' => $is_owner,
126                                 'allow_location' => ($is_owner || $commvisitor) && $profile['allow_location'],
127                                 'default_location' => $is_owner ? $profile['default-location'] : '',
128                                 'nickname' => $profile['nickname'],
129                                 'acl' => $is_owner ? ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), true) : '',
130                                 'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
131                                 'profile_uid' => $profile['uid'],
132                         ];
133
134                         $o .= DI::conversation()->statusEditor($x);
135                 }
136
137                 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
138                 $condition = Item::getPermissionsConditionArrayByUserId($profile['uid']);
139
140                 $last_updated_array = DI::session()->get('last_updated', []);
141
142                 if (!empty($category)) {
143                         $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `category-view` WHERE `name` = ? AND `type` = ? AND `uid` = ?)",
144                                 $category, Category::CATEGORY, $profile['uid']]);
145                 }
146
147                 if (!empty($hashtags)) {
148                         $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `tag-search-view` WHERE `name` = ? AND `uid` = ?)",
149                                 $hashtags, $profile['uid']]);
150                 }
151
152                 if (!empty($datequery)) {
153                         $condition = DBA::mergeConditions($condition, ["`received` <= ?", DateTimeFormat::convert($datequery, 'UTC', $a->getTimeZone())]);
154                 }
155                 if (!empty($datequery2)) {
156                         $condition = DBA::mergeConditions($condition, ["`received` >= ?", DateTimeFormat::convert($datequery2, 'UTC', $a->getTimeZone())]);
157                 }
158
159                 // Does the profile page belong to a forum?
160                 // If not then we can improve the performance with an additional condition
161                 $condition2 = ['uid' => $profile['uid'], 'account-type' => User::ACCOUNT_TYPE_COMMUNITY];
162                 if (!DBA::exists('user', $condition2)) {
163                         $condition = DBA::mergeConditions($condition, ['contact-id' => $profile['id']]);
164                 }
165
166                 if (DI::mode()->isMobile()) {
167                         $itemspage_network = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
168                                 DI::config()->get('system', 'itemspage_network_mobile'));
169                 } else {
170                         $itemspage_network = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
171                                 DI::config()->get('system', 'itemspage_network'));
172                 }
173
174                 $condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
175                         (`gravity` = ? AND `vid` = ? AND `origin`
176                         AND `thr-parent-id` IN (SELECT `uri-id` FROM `post` WHERE `gravity` = ? AND `network` IN (?, ?))))",
177                         Item::GRAVITY_PARENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Item::GRAVITY_PARENT, Protocol::ACTIVITYPUB, Protocol::DFRN]);
178
179                 $condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED,
180                         'visible' => true, 'deleted' => false]);
181
182                 $pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
183                 $params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]];
184
185                 $items_stmt = Post::select(['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'received'], $condition, $params);
186
187                 // Set a time stamp for this page. We will make use of it when we
188                 // search for new items (update routine)
189                 $last_updated_array[$last_updated_key] = time();
190                 DI::session()->set('last_updated', $last_updated_array);
191
192                 if ($is_owner && !DI::config()->get('theme', 'hide_eventlist')) {
193                         $o .= ProfileModel::getBirthdays();
194                         $o .= ProfileModel::getEventsReminderHTML();
195                 }
196
197                 if ($is_owner) {
198                         $unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => DI::userSession()->getLocalUserId()]);
199                         if ($unseen) {
200                                 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => DI::userSession()->getLocalUserId()]);
201                         }
202                 }
203
204                 $items = Post::toArray($items_stmt);
205
206                 if ($pager->getStart() == 0 && !empty($profile['uid'])) {
207                         $pcid = Contact::getPublicIdByUserId($profile['uid']);
208                         $pinned = Post\Collection::selectToArrayForContact($pcid, Post\Collection::FEATURED);
209                         $items = array_merge($items, $pinned);
210                 }
211
212                 $o .= DI::conversation()->create($items, 'profile', false, false, 'pinned_received', $profile['uid']);
213
214                 $o .= $pager->renderMinimal(count($items));
215
216                 return $o;
217         }
218 }