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\Contact;
24 use Friendica\BaseModule;
25 use Friendica\Content\Widget;
26 use Friendica\Core\Protocol;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Session;
31 use Friendica\Module\Contact;
32 use Friendica\Network\HTTPException\BadRequestException;
33 use Friendica\Network\HTTPException\ForbiddenException;
34 use Friendica\Util\Strings;
37 * GUI for advanced contact details manipulation
39 class Advanced extends BaseModule
41 public static function init(array $parameters = [])
43 if (!Session::isAuthenticated()) {
44 throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
48 public static function post(array $parameters = [])
50 $cid = $parameters['id'];
52 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
53 if (empty($contact)) {
54 throw new BadRequestException(DI::l10n()->t('Contact not found.'));
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);
69 $r = DI::dba()->update(
77 'request' => $request,
78 'confirm' => $confirm,
83 ['id' => $contact['id'], 'uid' => local_user()]
87 DI::logger()->notice('Updating photo.', ['photo' => $photo]);
89 Model\Contact::updateAvatar($contact['id'], $photo, true);
93 notice(DI::l10n()->t('Contact update failed.'));
99 public static function content(array $parameters = [])
101 $cid = $parameters['id'];
103 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
104 if (empty($contact)) {
105 throw new BadRequestException(DI::l10n()->t('Contact not found.'));
108 DI::page()['aside'] = Widget\VCard::getHTML($contact);
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.');
113 $returnaddr = "contact/$cid";
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';
123 $tab_str = Contact::getTabsHTML($contact, Contact::TAB_ADVANCED);
125 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
126 return Renderer::replaceMacros($tpl, [
127 '$tab_str' => $tab_str,
128 '$warning' => $warning,
130 '$returnaddr' => $returnaddr,
131 '$return' => DI::l10n()->t('Return to contact editor'),
132 '$contact_id' => $contact['id'],
133 '$lbl_submit' => DI::l10n()->t('Submit'),
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],