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 info(DI::l10n()->t('Contact settings applied.') . EOL);
96 notice(DI::l10n()->t('Contact update failed.') . EOL);
102 public static function content(array $parameters = [])
104 $cid = $parameters['id'];
106 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
107 if (empty($contact)) {
108 throw new BadRequestException(DI::l10n()->t('Contact not found.'));
111 Model\Profile::load(DI::app(), "", Model\Contact::getDetailsByURL($contact["url"]));
113 $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.');
114 $info = DI::l10n()->t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
116 $returnaddr = "contact/$cid";
118 // Disable remote self for everything except feeds.
119 // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
120 // Problem is, you couldn't reply to both networks.
121 $allow_remote_self = in_array($contact['network'], [Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])
122 && DI::config()->get('system', 'allow_users_remote_self');
124 if ($contact['network'] == Protocol::FEED) {
125 $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')];
127 $remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '2' => DI::l10n()->t('Mirror as my own posting')];
130 $tab_str = Contact::getTabsHTML(DI::app(), $contact, 6);
132 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
133 return Renderer::replaceMacros($tpl, [
134 '$tab_str' => $tab_str,
135 '$warning' => $warning,
137 '$returnaddr' => $returnaddr,
138 '$return' => DI::l10n()->t('Return to contact editor'),
139 '$update_profile' => in_array($contact['network'], Protocol::FEDERATED),
140 '$udprofilenow' => DI::l10n()->t('Refetch contact data'),
141 '$contact_id' => $contact['id'],
142 '$lbl_submit' => DI::l10n()->t('Submit'),
143 '$label_remote_self' => DI::l10n()->t('Remote Self'),
144 '$allow_remote_self' => $allow_remote_self,
145 '$remote_self' => ['remote_self',
146 DI::l10n()->t('Mirror postings from this contact'),
147 $contact['remote_self'],
148 DI::l10n()->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
152 '$name' => ['name', DI::l10n()->t('Name'), $contact['name']],
153 '$nick' => ['nick', DI::l10n()->t('Account Nickname'), $contact['nick']],
154 '$attag' => ['attag', DI::l10n()->t('@Tagname - overrides Name/Nickname'), $contact['attag']],
155 '$url' => ['url', DI::l10n()->t('Account URL'), $contact['url']],
156 '$alias' => ['alias', DI::l10n()->t('Account URL Alias'), $contact['alias']],
157 '$request' => ['request', DI::l10n()->t('Friend Request URL'), $contact['request']],
158 'confirm' => ['confirm', DI::l10n()->t('Friend Confirm URL'), $contact['confirm']],
159 'notify' => ['notify', DI::l10n()->t('Notification Endpoint URL'), $contact['notify']],
160 'poll' => ['poll', DI::l10n()->t('Poll/Feed URL'), $contact['poll']],
161 'photo' => ['photo', DI::l10n()->t('New photo from this URL'), ''],