]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact/Posts.php
Merge pull request #10969 from MrPetovan/task/remove-private-contacts
[friendica.git] / src / Module / Contact / Posts.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\Contact;
23
24 use Friendica\App;
25 use Friendica\BaseModule;
26 use Friendica\Contact\LocalRelationship\Repository\LocalRelationship;
27 use Friendica\Content\Nav;
28 use Friendica\Content\Widget;
29 use Friendica\Core\L10n;
30 use Friendica\Core\Protocol;
31 use Friendica\Database\DBA;
32 use Friendica\Model;
33 use Friendica\Module\Contact;
34 use Friendica\Module\Security\Login;
35 use Friendica\Network\HTTPException\NotFoundException;
36
37 /**
38  *  Show a contact posts and comments
39  */
40 class Posts extends BaseModule
41 {
42         /**
43          * @var LocalRelationship
44          */
45         private $localRelationship;
46         /**
47          * @var App\BaseURL
48          */
49         private $baseUrl;
50         /**
51          * @var App\Page
52          */
53         private $page;
54
55         public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Page $page, array $parameters = [])
56         {
57                 parent::__construct($l10n, $parameters);
58
59                 $this->localRelationship = $localRelationship;
60                 $this->baseUrl           = $baseUrl;
61                 $this->page              = $page;
62         }
63
64         public function content(): string
65         {
66                 if (!local_user()) {
67                         return Login::form($_SERVER['REQUEST_URI']);
68                 }
69
70                 // Backward compatibility: Ensure to use the public contact when the user contact is provided
71                 // Remove by version 2022.03
72                 $data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), local_user());
73                 if (empty($data)) {
74                         throw new NotFoundException($this->t('Contact not found.'));
75                 }
76
77                 $contact = Model\Contact::getById($data['public']);
78                 if (!DBA::isResult($contact)) {
79                         throw new NotFoundException($this->t('Contact not found.'));
80                 }
81
82                 // Don't display contacts that are about to be deleted
83                 if (DBA::isResult($contact) && (!empty($contact['deleted']) || !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM)) {
84                         throw new NotFoundException($this->t('Contact not found.'));
85                 }
86
87                 $localRelationship = $this->localRelationship->getForUserContact(local_user(), $contact['id']);
88                 if ($localRelationship->rel === Model\Contact::SELF) {
89                         $this->baseUrl->redirect('profile/' . $contact['nick']);
90                 }
91
92                 $this->page['aside'] .= Widget\VCard::getHTML($contact);
93
94                 Nav::setSelected('contact');
95
96                 $o = Contact::getTabsHTML($contact, Contact::TAB_POSTS);
97
98                 $o .= Model\Contact::getPostsFromId($contact['id']);
99
100                 return $o;
101         }
102 }