]> git.mxchange.org Git - friendica.git/blob - src/Module/Update/Profile.php
Merge pull request #8293 from MrPetovan/task/5562-community-pagination
[friendica.git] / src / Module / Update / Profile.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\Update;
23
24 use Friendica\BaseModule;
25 use Friendica\Content\Pager;
26 use Friendica\Core\Session;
27 use Friendica\Core\System;
28 use Friendica\Database\DBA;
29 use Friendica\DI;
30 use Friendica\Model\Item;
31 use Friendica\Model\Profile as ProfileModel;
32 use Friendica\Network\HTTPException\ForbiddenException;
33 use Friendica\Util\DateTimeFormat;
34
35 class Profile extends BaseModule
36 {
37         public static function rawContent(array $parameters = [])
38         {
39                 $a = DI::app();
40
41                 if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['uid'])) {
42                         throw new ForbiddenException();
43                 }
44
45                 $o = '';
46
47                 $profile_uid = intval($_GET['p'] ?? 0);
48
49                 // Ensure we've got a profile owner if updating.
50                 $a->profile['uid'] = $profile_uid;
51
52                 $remote_contact = Session::getRemoteContactID($a->profile['uid']);
53                 $is_owner = local_user() == $a->profile['uid'];
54                 $last_updated_key = "profile:" . $a->profile['uid'] . ":" . local_user() . ":" . $remote_contact;
55
56                 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
57                         throw new ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
58                 }
59
60                 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
61                 $sql_extra = Item::getPermissionsSQLByUserId($a->profile['uid']);
62
63                 $last_updated_array = Session::get('last_updated', []);
64
65                 $last_updated = $last_updated_array[$last_updated_key] ?? 0;
66
67                 // If the page user is the owner of the page we should query for unseen
68                 // items. Otherwise use a timestamp of the last succesful update request.
69                 if ($is_owner || !$last_updated) {
70                         $sql_extra4 = " AND `item`.`unseen`";
71                 } else {
72                         $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);
73                         $sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'";
74                 }
75
76                 $items_stmt = DBA::p(
77                         "SELECT DISTINCT(`parent-uri`) AS `uri`, `item`.`created`
78                         FROM `item`
79                         INNER JOIN `contact`
80                         ON `contact`.`id` = `item`.`contact-id`
81                                 AND NOT `contact`.`blocked`
82                                 AND NOT `contact`.`pending`
83                         WHERE `item`.`uid` = ?
84                                 AND `item`.`visible`
85                                 AND     (NOT `item`.`deleted` OR `item`.`gravity` = ?)
86                                 AND NOT `item`.`moderated`
87                                 AND `item`.`wall`
88                                 $sql_extra4
89                                 $sql_extra
90                         ORDER BY `item`.`received` DESC",
91                         $a->profile['uid'],
92                         GRAVITY_ACTIVITY
93                 );
94
95                 if (!DBA::isResult($items_stmt)) {
96                         return '';
97                 }
98
99                 // Set a time stamp for this page. We will make use of it when we
100                 // search for new items (update routine)
101                 $last_updated_array[$last_updated_key] = time();
102                 Session::set('last_updated', $last_updated_array);
103
104                 if ($is_owner && !$profile_uid && !DI::config()->get('theme', 'hide_eventlist')) {
105                         $o .= ProfileModel::getBirthdays();
106                         $o .= ProfileModel::getEventsReminderHTML();
107                 }
108
109                 if ($is_owner) {
110                         $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
111                         if ($unseen) {
112                                 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
113                         }
114                 }
115
116                 $items = DBA::toArray($items_stmt);
117
118                 $o .= conversation($a, $items, 'profile', $profile_uid, false, 'received', $a->profile['uid']);
119
120                 System::htmlUpdateExit($o);
121         }
122 }