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\Core\Protocol;
26 use Friendica\Core\Renderer;
27 use Friendica\Core\Session;
30 use Friendica\Module\Contact;
31 use Friendica\Network\HTTPException\BadRequestException;
32 use Friendica\Network\HTTPException\ForbiddenException;
33 use Friendica\Util\Strings;
36 * GUI for advanced contact details manipulation
38 class Advanced extends BaseModule
40 public static function init(array $parameters = [])
42 if (!Session::isAuthenticated()) {
43 throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
47 public static function post(array $parameters = [])
49 $cid = $parameters['id'];
51 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
52 if (empty($contact)) {
53 throw new BadRequestException(DI::l10n()->t('Contact not found.'));
56 $name = ($_POST['name'] ?? '') ?: $contact['name'];
57 $nick = $_POST['nick'] ?? '';
58 $url = $_POST['url'] ?? '';
59 $alias = $_POST['alias'] ?? '';
60 $request = $_POST['request'] ?? '';
61 $confirm = $_POST['confirm'] ?? '';
62 $notify = $_POST['notify'] ?? '';
63 $poll = $_POST['poll'] ?? '';
64 $attag = $_POST['attag'] ?? '';
65 $photo = $_POST['photo'] ?? '';
66 $nurl = Strings::normaliseLink($url);
68 $r = DI::dba()->update(
76 'request' => $request,
77 'confirm' => $confirm,
82 ['id' => $contact['id'], 'uid' => local_user()]
86 DI::logger()->notice('Updating photo.', ['photo' => $photo]);
88 Model\Contact::updateAvatar($contact['id'], $photo, true);
92 notice(DI::l10n()->t('Contact update failed.'));
98 public static function content(array $parameters = [])
100 $cid = $parameters['id'];
102 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
103 if (empty($contact)) {
104 throw new BadRequestException(DI::l10n()->t('Contact not found.'));
107 Model\Profile::load(DI::app(), "", Model\Contact::getByURL($contact["url"], false));
109 $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.');
110 $info = DI::l10n()->t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
112 $returnaddr = "contact/$cid";
114 // This data is fetched automatically for most networks.
115 // Editing does only makes sense for mail and feed contacts.
116 if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
117 $readonly = 'readonly';
122 $tab_str = Contact::getTabsHTML($contact, Contact::TAB_ADVANCED);
124 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
125 return Renderer::replaceMacros($tpl, [
126 '$tab_str' => $tab_str,
127 '$warning' => $warning,
129 '$returnaddr' => $returnaddr,
130 '$return' => DI::l10n()->t('Return to contact editor'),
131 '$contact_id' => $contact['id'],
132 '$lbl_submit' => DI::l10n()->t('Submit'),
134 '$name' => ['name', DI::l10n()->t('Name'), $contact['name'], '', '', $readonly],
135 '$nick' => ['nick', DI::l10n()->t('Account Nickname'), $contact['nick'], '', '', $readonly],
136 '$attag' => ['attag', DI::l10n()->t('@Tagname - overrides Name/Nickname'), $contact['attag']],
137 '$url' => ['url', DI::l10n()->t('Account URL'), $contact['url'], '', '', $readonly],
138 '$alias' => ['alias', DI::l10n()->t('Account URL Alias'), $contact['alias'], '', '', $readonly],
139 '$request' => ['request', DI::l10n()->t('Friend Request URL'), $contact['request'], '', '', $readonly],
140 'confirm' => ['confirm', DI::l10n()->t('Friend Confirm URL'), $contact['confirm'], '', '', $readonly],
141 'notify' => ['notify', DI::l10n()->t('Notification Endpoint URL'), $contact['notify'], '', '', $readonly],
142 'poll' => ['poll', DI::l10n()->t('Poll/Feed URL'), $contact['poll'], '', '', $readonly],
143 'photo' => ['photo', DI::l10n()->t('New photo from this URL'), '', '', '', $readonly],