]> git.mxchange.org Git - friendica.git/blob - src/Module/Update/Profile.php
Removed redundant maximagesize = INF statements
[friendica.git] / src / Module / Update / Profile.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\Update;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\System;
26 use Friendica\Database\DBA;
27 use Friendica\DI;
28 use Friendica\Model\Item;
29 use Friendica\Model\Post;
30 use Friendica\Model\Profile as ProfileModel;
31 use Friendica\Model\User;
32 use Friendica\Network\HTTPException\ForbiddenException;
33 use Friendica\Util\DateTimeFormat;
34
35 class Profile extends BaseModule
36 {
37         protected function rawContent(array $request = [])
38         {
39                 $a = DI::app();
40
41                 // Ensure we've got a profile owner if updating.
42                 $a->setProfileOwner((int)($_GET['p'] ?? 0));
43
44                 if (DI::config()->get('system', 'block_public') && !DI::userSession()->getLocalUserId() && !DI::userSession()->getRemoteContactID($a->getProfileOwner())) {
45                         throw new ForbiddenException();
46                 }
47
48                 $remote_contact = DI::userSession()->getRemoteContactID($a->getProfileOwner());
49                 $is_owner = DI::userSession()->getLocalUserId() == $a->getProfileOwner();
50                 $last_updated_key = "profile:" . $a->getProfileOwner() . ":" . DI::userSession()->getLocalUserId() . ":" . $remote_contact;
51
52                 if (!$is_owner && !$remote_contact) {
53                         $user = User::getById($a->getProfileOwner(), ['hidewall']);
54                         if ($user['hidewall']) {
55                                 throw new ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
56                         }
57                 }
58
59                 $o = '';
60
61                 if (empty($_GET['force']) && DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'no_auto_update')) {
62                         System::htmlUpdateExit($o);
63                 }
64
65                 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
66                 $sql_extra = Item::getPermissionsSQLByUserId($a->getProfileOwner());
67
68                 $last_updated_array = DI::session()->get('last_updated', []);
69
70                 $last_updated = $last_updated_array[$last_updated_key] ?? 0;
71
72                 $condition = ["`uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
73                                 AND `visible` AND (NOT `deleted` OR `gravity` = ?)
74                                 AND `wall` " . $sql_extra, $a->getProfileOwner(), Item::GRAVITY_ACTIVITY];
75
76                 if ($_GET['force'] && !empty($_GET['item'])) {
77                         // When the parent is provided, we only fetch this
78                         $condition = DBA::mergeConditions($condition, ['parent' => $_GET['item']]);
79                 } elseif ($is_owner || !$last_updated) {
80                         // If the page user is the owner of the page we should query for unseen
81                         // items. Otherwise use a timestamp of the last succesful update request.
82                         $condition = DBA::mergeConditions($condition, ['unseen' => true]);
83                 } else {
84                         $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);
85                         $condition = DBA::mergeConditions($condition, ["`received` > ?", $gmupdate]);
86                 }
87
88                 $items = Post::selectToArray(['parent-uri-id', 'created', 'received'], $condition, ['group_by' => ['parent-uri-id'], 'order' => ['received' => true]]);
89                 if (!DBA::isResult($items)) {
90                         return;
91                 }
92
93                 // @todo the DBA functions should handle "SELECT field AS alias" in the future,
94                 // so that this workaround here could be removed.
95                 $items = array_map(function ($item) {
96                         $item['uri-id'] = $item['parent-uri-id'];
97                         unset($item['parent-uri-id']);
98                         return $item;
99                 }, $items);
100
101                 // Set a time stamp for this page. We will make use of it when we
102                 // search for new items (update routine)
103                 $last_updated_array[$last_updated_key] = time();
104                 DI::session()->set('last_updated', $last_updated_array);
105
106                 if ($is_owner && !$a->getProfileOwner() && !DI::config()->get('theme', 'hide_eventlist')) {
107                         $o .= ProfileModel::getBirthdays();
108                         $o .= ProfileModel::getEventsReminderHTML();
109                 }
110
111                 if ($is_owner) {
112                         $unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => DI::userSession()->getLocalUserId()]);
113                         if ($unseen) {
114                                 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => DI::userSession()->getLocalUserId()]);
115                         }
116                 }
117
118                 $o .= DI::conversation()->create($items, 'profile', $a->getProfileOwner(), false, 'received', $a->getProfileOwner());
119
120                 System::htmlUpdateExit($o);
121         }
122 }