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