]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact/Advanced.php
Replace `$parameters` argument per method with `static::$parameters`
[friendica.git] / src / Module / Contact / Advanced.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\BaseModule;
25 use Friendica\Content\Widget;
26 use Friendica\Core\Protocol;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Session;
29 use Friendica\DI;
30 use Friendica\Model;
31 use Friendica\Module\Contact;
32 use Friendica\Network\HTTPException\BadRequestException;
33 use Friendica\Network\HTTPException\ForbiddenException;
34 use Friendica\Util\Strings;
35
36 /**
37  * GUI for advanced contact details manipulation
38  */
39 class Advanced extends BaseModule
40 {
41         public static function init()
42         {
43                 if (!Session::isAuthenticated()) {
44                         throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
45                 }
46         }
47
48         public static function post()
49         {
50                 $cid = static::$parameters['id'];
51
52                 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
53                 if (empty($contact)) {
54                         throw new BadRequestException(DI::l10n()->t('Contact not found.'));
55                 }
56
57                 $name        = ($_POST['name'] ?? '') ?: $contact['name'];
58                 $nick        = $_POST['nick'] ?? '';
59                 $url         = $_POST['url'] ?? '';
60                 $alias       = $_POST['alias'] ?? '';
61                 $request     = $_POST['request'] ?? '';
62                 $confirm     = $_POST['confirm'] ?? '';
63                 $notify      = $_POST['notify'] ?? '';
64                 $poll        = $_POST['poll'] ?? '';
65                 $attag       = $_POST['attag'] ?? '';
66                 $photo       = $_POST['photo'] ?? '';
67                 $nurl        = Strings::normaliseLink($url);
68
69                 $r = DI::dba()->update(
70                         'contact',
71                         [
72                                 'name'        => $name,
73                                 'nick'        => $nick,
74                                 'url'         => $url,
75                                 'nurl'        => $nurl,
76                                 'alias'       => $alias,
77                                 'request'     => $request,
78                                 'confirm'     => $confirm,
79                                 'notify'      => $notify,
80                                 'poll'        => $poll,
81                                 'attag'       => $attag,
82                         ],
83                         ['id' => $contact['id'], 'uid' => local_user()]
84                 );
85
86                 if ($photo) {
87                         DI::logger()->notice('Updating photo.', ['photo' => $photo]);
88
89                         Model\Contact::updateAvatar($contact['id'], $photo, true);
90                 }
91
92                 if (!$r) {
93                         notice(DI::l10n()->t('Contact update failed.'));
94                 }
95
96                 return;
97         }
98
99         public static function content()
100         {
101                 $cid = static::$parameters['id'];
102
103                 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
104                 if (empty($contact)) {
105                         throw new BadRequestException(DI::l10n()->t('Contact not found.'));
106                 }
107
108                 DI::page()['aside'] = Widget\VCard::getHTML($contact);
109
110                 $warning = DI::l10n()->t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.');
111                 $info    = DI::l10n()->t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
112
113                 $returnaddr = "contact/$cid";
114
115                 // This data is fetched automatically for most networks.
116                 // Editing does only makes sense for mail and feed contacts.
117                 if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
118                         $readonly = 'readonly';
119                 } else {
120                         $readonly = '';
121                 }
122
123                 $tab_str = Contact::getTabsHTML($contact, Contact::TAB_ADVANCED);
124
125                 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
126                 return Renderer::replaceMacros($tpl, [
127                         '$tab_str'           => $tab_str,
128                         '$warning'           => $warning,
129                         '$info'              => $info,
130                         '$returnaddr'        => $returnaddr,
131                         '$return'            => DI::l10n()->t('Return to contact editor'),
132                         '$contact_id'        => $contact['id'],
133                         '$lbl_submit'        => DI::l10n()->t('Submit'),
134
135                         '$name'    => ['name', DI::l10n()->t('Name'), $contact['name'], '', '', $readonly],
136                         '$nick'    => ['nick', DI::l10n()->t('Account Nickname'), $contact['nick'], '', '', $readonly],
137                         '$attag'   => ['attag', DI::l10n()->t('@Tagname - overrides Name/Nickname'), $contact['attag']],
138                         '$url'     => ['url', DI::l10n()->t('Account URL'), $contact['url'], '', '', $readonly],
139                         '$alias'   => ['alias', DI::l10n()->t('Account URL Alias'), $contact['alias'], '', '', $readonly],
140                         '$request' => ['request', DI::l10n()->t('Friend Request URL'), $contact['request'], '', '', $readonly],
141                         'confirm'  => ['confirm', DI::l10n()->t('Friend Confirm URL'), $contact['confirm'], '', '', $readonly],
142                         'notify'   => ['notify', DI::l10n()->t('Notification Endpoint URL'), $contact['notify'], '', '', $readonly],
143                         'poll'     => ['poll', DI::l10n()->t('Poll/Feed URL'), $contact['poll'], '', '', $readonly],
144                         'photo'    => ['photo', DI::l10n()->t('New photo from this URL'), '', '', '', $readonly],
145                 ]);
146         }
147 }