3 * @copyright Copyright (C) 2020, Friendica
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 $remote_self = $_POST['remote_self'] ?? false;
67 $nurl = Strings::normaliseLink($url);
69 $r = DI::dba()->update(
77 'request' => $request,
78 'confirm' => $confirm,
82 'remote_self' => $remote_self,
84 ['id' => $contact['id'], 'uid' => local_user()]
88 DI::logger()->notice('Updating photo.', ['photo' => $photo]);
90 Model\Contact::updateAvatar($photo, local_user(), $contact['id'], true);
94 notice(DI::l10n()->t('Contact update failed.') . EOL);
100 public static function content(array $parameters = [])
102 $cid = $parameters['id'];
104 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
105 if (empty($contact)) {
106 throw new BadRequestException(DI::l10n()->t('Contact not found.'));
109 Model\Profile::load(DI::app(), "", Model\Contact::getByURL($contact["url"], false));
111 $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.');
112 $info = DI::l10n()->t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
114 $returnaddr = "contact/$cid";
116 // Disable remote self for everything except feeds.
117 // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
118 // Problem is, you couldn't reply to both networks.
119 $allow_remote_self = in_array($contact['network'], [Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])
120 && DI::config()->get('system', 'allow_users_remote_self');
122 if ($contact['network'] == Protocol::FEED) {
123 $remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '1' => DI::l10n()->t('Mirror as forwarded posting'), '2' => DI::l10n()->t('Mirror as my own posting')];
125 $remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '2' => DI::l10n()->t('Mirror as my own posting')];
128 $tab_str = Contact::getTabsHTML(DI::app(), $contact, 6);
130 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
131 return Renderer::replaceMacros($tpl, [
132 '$tab_str' => $tab_str,
133 '$warning' => $warning,
135 '$returnaddr' => $returnaddr,
136 '$return' => DI::l10n()->t('Return to contact editor'),
137 '$update_profile' => in_array($contact['network'], Protocol::FEDERATED),
138 '$udprofilenow' => DI::l10n()->t('Refetch contact data'),
139 '$contact_id' => $contact['id'],
140 '$lbl_submit' => DI::l10n()->t('Submit'),
141 '$label_remote_self' => DI::l10n()->t('Remote Self'),
142 '$allow_remote_self' => $allow_remote_self,
143 '$remote_self' => ['remote_self',
144 DI::l10n()->t('Mirror postings from this contact'),
145 $contact['remote_self'],
146 DI::l10n()->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
150 '$name' => ['name', DI::l10n()->t('Name'), $contact['name']],
151 '$nick' => ['nick', DI::l10n()->t('Account Nickname'), $contact['nick']],
152 '$attag' => ['attag', DI::l10n()->t('@Tagname - overrides Name/Nickname'), $contact['attag']],
153 '$url' => ['url', DI::l10n()->t('Account URL'), $contact['url']],
154 '$alias' => ['alias', DI::l10n()->t('Account URL Alias'), $contact['alias']],
155 '$request' => ['request', DI::l10n()->t('Friend Request URL'), $contact['request']],
156 'confirm' => ['confirm', DI::l10n()->t('Friend Confirm URL'), $contact['confirm']],
157 'notify' => ['notify', DI::l10n()->t('Notification Endpoint URL'), $contact['notify']],
158 'poll' => ['poll', DI::l10n()->t('Poll/Feed URL'), $contact['poll']],
159 'photo' => ['photo', DI::l10n()->t('New photo from this URL'), ''],