3 * @copyright Copyright (C) 2010-2021, the Friendica project
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\Core\Session;
26 use Friendica\Core\System;
27 use Friendica\Database\DBA;
29 use Friendica\Model\Item;
30 use Friendica\Model\Post;
31 use Friendica\Model\Profile as ProfileModel;
32 use Friendica\Model\User;
33 use Friendica\Network\HTTPException\ForbiddenException;
34 use Friendica\Util\DateTimeFormat;
36 class Profile extends BaseModule
38 public static function rawContent()
42 // Ensure we've got a profile owner if updating.
43 $a->setProfileOwner($_GET['p'] ?? 0);
45 if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->getProfileOwner())) {
46 throw new ForbiddenException();
49 $remote_contact = Session::getRemoteContactID($a->getProfileOwner());
50 $is_owner = local_user() == $a->getProfileOwner();
51 $last_updated_key = "profile:" . $a->getProfileOwner() . ":" . local_user() . ":" . $remote_contact;
53 if (!$is_owner && !$remote_contact) {
54 $user = User::getById($a->getProfileOwner(), ['hidewall']);
55 if ($user['hidewall']) {
56 throw new ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
62 if (empty($_GET['force']) && DI::pConfig()->get(local_user(), 'system', 'no_auto_update')) {
63 System::htmlUpdateExit($o);
66 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
67 $sql_extra = Item::getPermissionsSQLByUserId($a->getProfileOwner());
69 $last_updated_array = Session::get('last_updated', []);
71 $last_updated = $last_updated_array[$last_updated_key] ?? 0;
73 if ($_GET['force'] && !empty($_GET['item'])) {
74 // When the parent is provided, we only fetch this
75 $sql_extra4 = " AND `parent` = " . intval($_GET['item']);
76 } elseif ($is_owner || !$last_updated) {
77 // If the page user is the owner of the page we should query for unseen
78 // items. Otherwise use a timestamp of the last succesful update request.
79 $sql_extra4 = " AND `unseen`";
81 $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);
82 $sql_extra4 = " AND `received` > '" . $gmupdate . "'";
86 "SELECT `parent-uri-id` AS `uri-id`, MAX(`created`), MAX(`received`) FROM `post-user-view`
87 WHERE `uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
88 AND `visible` AND (NOT `deleted` OR `gravity` = ?)
89 AND `wall` $sql_extra4 $sql_extra
90 GROUP BY `parent-uri-id` ORDER BY `received` DESC",
91 $a->getProfileOwner(),
95 if (!DBA::isResult($items_stmt)) {
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);
104 if ($is_owner && !$a->getProfileOwner() && !DI::config()->get('theme', 'hide_eventlist')) {
105 $o .= ProfileModel::getBirthdays();
106 $o .= ProfileModel::getEventsReminderHTML();
110 $unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
112 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
116 $items = DBA::toArray($items_stmt);
118 $o .= DI::conversation()->create($items, 'profile', $a->getProfileOwner(), false, 'received', $a->getProfileOwner());
120 System::htmlUpdateExit($o);