]> git.mxchange.org Git - friendica.git/blob - src/Module/Profile/Status.php
Merge pull request #9603 from annando/notice
[friendica.git] / src / Module / Profile / Status.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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\Core\Session;
30 use Friendica\Database\DBA;
31 use Friendica\DI;
32 use Friendica\Model\Item;
33 use Friendica\Model\Post\Category;
34 use Friendica\Model\Profile as ProfileModel;
35 use Friendica\Model\User;
36 use Friendica\Model\Verb;
37 use Friendica\Module\BaseProfile;
38 use Friendica\Module\Security\Login;
39 use Friendica\Network\HTTPException;
40 use Friendica\Protocol\Activity;
41 use Friendica\Util\DateTimeFormat;
42 use Friendica\Security\Security;
43 use Friendica\Util\Strings;
44 use Friendica\Util\XML;
45
46 class Status extends BaseProfile
47 {
48         public static function content(array $parameters = [])
49         {
50                 $args = DI::args();
51
52                 $a = DI::app();
53
54                 ProfileModel::load($a, $parameters['nickname']);
55
56                 if (empty($a->profile)) {
57                         throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
58                 }
59
60                 if (!$a->profile['net-publish']) {
61                         DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
62                 }
63
64                 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', $a->profile['name']) . '"/>' . "\n";
65                 DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/" title="' . DI::l10n()->t('%s\'s posts', $a->profile['name']) . '"/>' . "\n";
66                 DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/comments" title="' . DI::l10n()->t('%s\'s comments', $a->profile['name']) . '"/>' . "\n";
67                 DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $a->profile['name']) . '"/>' . "\n";
68
69                 $category = $datequery = $datequery2 = '';
70
71                 $dtFormat = DI::dtFormat();
72
73                 if ($args->getArgc() > 3) {
74                         for ($x = 3; $x < $args->getArgc(); $x++) {
75                                 if ($dtFormat->isYearMonthDay($args->get($x))) {
76                                         if ($datequery) {
77                                                 $datequery2 = Strings::escapeHtml($args->get($x));
78                                         } else {
79                                                 $datequery = Strings::escapeHtml($args->get($x));
80                                         }
81                                 } else {
82                                         $category = $args->get($x);
83                                 }
84                         }
85                 }
86
87                 if (empty($category)) {
88                         $category = $_GET['category'] ?? '';
89                 }
90
91                 $hashtags = $_GET['tag'] ?? '';
92
93                 if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['uid'])) {
94                         return Login::form();
95                 }
96
97                 $o = '';
98
99                 if ($a->profile['uid'] == local_user()) {
100                         Nav::setSelected('home');
101                 }
102
103                 $remote_contact = Session::getRemoteContactID($a->profile['uid']);
104                 $is_owner = local_user() == $a->profile['uid'];
105                 $last_updated_key = "profile:" . $a->profile['uid'] . ":" . local_user() . ":" . $remote_contact;
106
107                 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
108                         notice(DI::l10n()->t('Access to this profile has been restricted.'));
109                         return '';
110                 }
111
112                 $o .= self::getTabsHTML($a, 'status', $is_owner, $a->profile['nickname']);
113
114                 $o .= Widget::commonFriendsVisitor($a->profile['uid'], $a->profile['nickname']);
115
116                 $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
117                 $commvisitor = $commpage && $remote_contact;
118
119                 DI::page()['aside'] .= Widget::postedByYear(DI::baseUrl() . '/profile/' . $a->profile['nickname'] . '/status', $a->profile['profile_uid'] ?? 0, true);
120                 DI::page()['aside'] .= Widget::categories(DI::baseUrl() . '/profile/' . $a->profile['nickname'] . '/status', XML::escape($category));
121                 DI::page()['aside'] .= Widget::tagCloud();
122
123                 if (Security::canWriteToUserWall($a->profile['uid'])) {
124                         $x = [
125                                 'is_owner' => $is_owner,
126                                 'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'],
127                                 'default_location' => $is_owner ? $a->user['default-location'] : '',
128                                 'nickname' => $a->profile['nickname'],
129                                 'lockstate' => is_array($a->user)
130                                 && (strlen($a->user['allow_cid'])
131                                         || strlen($a->user['allow_gid'])
132                                         || strlen($a->user['deny_cid'])
133                                         || strlen($a->user['deny_gid'])
134                                 ) ? 'lock' : 'unlock',
135                                 'acl' => $is_owner ? ACL::getFullSelectorHTML(DI::page(), $a->user, true) : '',
136                                 'bang' => '',
137                                 'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
138                                 'profile_uid' => $a->profile['uid'],
139                         ];
140
141                         $o .= status_editor($a, $x);
142                 }
143
144                 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
145                 $condition = Item::getPermissionsConditionArrayByUserId($a->profile['uid']);
146
147                 $last_updated_array = Session::get('last_updated', []);
148
149                 if (!empty($category)) {
150                         $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `category-view` WHERE `name` = ? AND `type` = ? AND `uid` = ?)",
151                                 $category, Category::CATEGORY, $a->profile['uid']]);
152                 }
153
154                 if (!empty($hashtags)) {
155                         $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `tag-search-view` WHERE `name` = ? AND `uid` = ?)",
156                                 $hashtags, $a->profile['uid']]);
157                 }
158
159                 if (!empty($datequery)) {
160                         $condition = DBA::mergeConditions($condition, ["`received` <= ?", DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())]);
161                 }
162                 if (!empty($datequery2)) {
163                         $condition = DBA::mergeConditions($condition, ["`received` >= ?", DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())]);
164                 }
165
166                 // Does the profile page belong to a forum?
167                 // If not then we can improve the performance with an additional condition
168                 $condition2 = ['uid' => $a->profile['uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];
169                 if (!DBA::exists('user', $condition2)) {
170                         $condition = DBA::mergeConditions($condition, ['contact-id' => $a->profile['id']]);
171                 }
172
173                 if (DI::mode()->isMobile()) {
174                         $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
175                                 DI::config()->get('system', 'itemspage_network_mobile'));
176                 } else {
177                         $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
178                                 DI::config()->get('system', 'itemspage_network'));
179                 }
180
181                 $condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
182                         (`gravity` = ? AND `vid` = ? AND `origin` AND `thr-parent-id` IN
183                                 (SELECT `uri-id` FROM `item` AS `i`
184                                         WHERE `gravity` = ? AND `network` IN (?, ?, ?, ?) AND `uid` IN (?, ?)
185                                                 AND `i`.`uri-id` = `item`.`thr-parent-id`)))",
186                         GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT,
187                         Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::OSTATUS,
188                         0, $a->profile['uid']]);
189
190                 $condition = DBA::mergeConditions($condition, ['uid' => $a->profile['uid'], 'network' => Protocol::FEDERATED,
191                         'visible' => true, 'deleted' => false, 'moderated' => false]);
192
193                 $pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
194                 $params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]];
195
196                 $items_stmt = DBA::select('item', ['uri', 'thr-parent-id', 'gravity', 'author-id', 'received'], $condition, $params);
197
198                 // Set a time stamp for this page. We will make use of it when we
199                 // search for new items (update routine)
200                 $last_updated_array[$last_updated_key] = time();
201                 Session::set('last_updated', $last_updated_array);
202
203                 if ($is_owner && !DI::config()->get('theme', 'hide_eventlist')) {
204                         $o .= ProfileModel::getBirthdays();
205                         $o .= ProfileModel::getEventsReminderHTML();
206                 }
207
208                 if ($is_owner) {
209                         $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
210                         if ($unseen) {
211                                 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
212                         }
213                 }
214
215                 $items = DBA::toArray($items_stmt);
216
217                 if ($pager->getStart() == 0 && !empty($a->profile['uid'])) {
218                         $condition = ['private' => [Item::PUBLIC, Item::UNLISTED]];
219                         $remote_user = Session::getRemoteContactID($a->profile['uid']);
220                         if (!empty($remote_user)) {
221                                 $permissionSets = DI::permissionSet()->selectByContactId($remote_user, $a->profile['uid']);
222                                 if (!empty($permissionSets)) {
223                                         $condition = ['psid' => array_merge($permissionSets->column('id'),
224                                                         [DI::permissionSet()->getIdFromACL($a->profile['uid'], '', '', '', '')])];
225                                 }
226                         } elseif ($a->profile['uid'] == local_user()) {
227                                 $condition = [];
228                         }
229         
230                         $pinned_items = Item::selectPinned($a->profile['uid'], ['uri', 'pinned'], $condition);
231                         $pinned = Item::inArray($pinned_items);
232                         $items = array_merge($items, $pinned);
233                 }
234
235                 $o .= conversation($a, $items, 'profile', false, false, 'pinned_received', $a->profile['uid']);
236
237                 $o .= $pager->renderMinimal(count($items));
238
239                 return $o;
240         }
241 }