3 * @copyright Copyright (C) 2020, Friendica
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\Update;
24 use Friendica\BaseModule;
25 use Friendica\Content\Pager;
26 use Friendica\Core\Session;
27 use Friendica\Core\System;
28 use Friendica\Database\DBA;
30 use Friendica\Model\Item;
31 use Friendica\Model\Profile as ProfileModel;
32 use Friendica\Network\HTTPException\ForbiddenException;
33 use Friendica\Util\DateTimeFormat;
35 class Profile extends BaseModule
37 public static function rawContent(array $parameters = [])
41 if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['uid'])) {
42 throw new ForbiddenException();
45 $profile_uid = intval($_GET['p'] ?? 0);
47 // Ensure we've got a profile owner if updating.
48 $a->profile['uid'] = $profile_uid;
50 $remote_contact = Session::getRemoteContactID($a->profile['uid']);
51 $is_owner = local_user() == $a->profile['uid'];
52 $last_updated_key = "profile:" . $a->profile['uid'] . ":" . local_user() . ":" . $remote_contact;
54 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
55 throw new ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
60 if (empty($_GET['force']) && DI::pConfig()->get(local_user(), 'system', 'no_auto_update')) {
61 System::htmlUpdateExit($o);
64 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
65 $sql_extra = Item::getPermissionsSQLByUserId($a->profile['uid']);
67 $last_updated_array = Session::get('last_updated', []);
69 $last_updated = $last_updated_array[$last_updated_key] ?? 0;
71 // If the page user is the owner of the page we should query for unseen
72 // items. Otherwise use a timestamp of the last succesful update request.
73 if ($is_owner || !$last_updated) {
74 $sql_extra4 = " AND `item`.`unseen`";
76 $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);
77 $sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'";
81 "SELECT DISTINCT(`parent-uri`) AS `uri`, `item`.`created`
84 ON `contact`.`id` = `item`.`contact-id`
85 AND NOT `contact`.`blocked`
86 AND NOT `contact`.`pending`
87 WHERE `item`.`uid` = ?
89 AND (NOT `item`.`deleted` OR `item`.`gravity` = ?)
90 AND NOT `item`.`moderated`
94 ORDER BY `item`.`received` DESC",
99 if (!DBA::isResult($items_stmt)) {
103 // Set a time stamp for this page. We will make use of it when we
104 // search for new items (update routine)
105 $last_updated_array[$last_updated_key] = time();
106 Session::set('last_updated', $last_updated_array);
108 if ($is_owner && !$profile_uid && !DI::config()->get('theme', 'hide_eventlist')) {
109 $o .= ProfileModel::getBirthdays();
110 $o .= ProfileModel::getEventsReminderHTML();
114 $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
116 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
120 $items = DBA::toArray($items_stmt);
122 $o .= conversation($a, $items, 'profile', $profile_uid, false, 'received', $a->profile['uid']);
124 System::htmlUpdateExit($o);