]> git.mxchange.org Git - friendica.git/blob - src/Module/Update/Display.php
a8dea82e1ccdc0d5895e7193f71bdce95802a415
[friendica.git] / src / Module / Update / Display.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  * See update_profile.php for documentation
21  */
22
23 namespace Friendica\Module\Update;
24
25 use Friendica\Model\Post;
26 use Friendica\Module\Item\Display as DisplayModule;
27 use Friendica\Util\DateTimeFormat;
28 use Friendica\Network\HTTPException;
29
30 /**
31  * Asynchronous update class for the display
32  */
33 class Display extends DisplayModule
34 {
35         protected function content(array $request = []): string
36         {
37                 if ($this->config->get('system', 'block_public') && !$this->session->isAuthenticated()) {
38                         throw new HTTPException\UnauthorizedException($this->t('Access denied.'));
39                 }
40
41                 $profileUid  = $request['p'] ?? 0;
42                 $force       = $request['force'] ?? false;
43                 $uriId       = $request['uri_id'] ?? 0;
44
45                 if (empty($uriId)) {
46                         throw new HTTPException\BadRequestException($this->t('Parameter uri_id is missing.'));
47                 }
48
49                 $item = Post::selectFirst(
50                         ['uid', 'parent-uri-id', 'uri-id'],
51                         ['uri-id' => $uriId, 'uid' => [0, $profileUid]],
52                         ['order' => ['uid' => true]]
53                 );
54
55                 if (empty($item)) {
56                         throw new HTTPException\NotFoundException($this->t('The requested item doesn\'t exist or has been deleted.'));
57                 }
58
59                 $this->app->setProfileOwner($item['uid'] ?? $profileUid);
60                 $parentUriId = $item['parent-uri-id'];
61
62                 if (empty($force)) {
63                         $browserUpdate = $this->pConfig->get($profileUid, 'system', 'update_interval');
64                         if (!empty($browserUpdate)) {
65                                 $updateDate = date(DateTimeFormat::MYSQL, time() - (intval($browserUpdate) / 500));
66                                 if (!Post::exists(["`parent-uri-id` = ? AND `uid` IN (?, ?) AND `received` > ?", $parentUriId, 0,
67                                                                    $profileUid, $updateDate])) {
68                                         $this->logger->debug('No updated content. Ending process',
69                                                 ['uri-id' => $uriId, 'uid' => $profileUid, 'updated' => $updateDate]);
70                                         return '';
71                                 } else {
72                                         $this->logger->debug('Updated content found.',
73                                                 ['uri-id' => $uriId, 'uid' => $profileUid, 'updated' => $updateDate]);
74                                 }
75                         }
76                 } else {
77                         $this->logger->debug('Forced content update.', ['uri-id' => $uriId, 'uid' => $profileUid]);
78                 }
79
80                 if (!$this->pConfig->get($this->session->getLocalUserId(), 'system', 'detailed_notif')) {
81                         $this->notification->setAllSeenForUser($this->session->getLocalUserId(), ['parent-uri-id' => $item['parent-uri-id']]);
82                         $this->notify->setAllSeenForUser($this->session->getLocalUserId(), ['parent-uri-id' => $item['parent-uri-id']]);
83                 }
84
85                 return $this->getDisplayData($item, true, $profileUid, $force);
86         }
87 }