3 namespace Friendica\Module\Contact;
5 use Friendica\BaseModule;
6 use Friendica\Core\Protocol;
7 use Friendica\Core\Renderer;
8 use Friendica\Core\Session;
11 use Friendica\Module\Contact;
12 use Friendica\Network\HTTPException\BadRequestException;
13 use Friendica\Network\HTTPException\ForbiddenException;
14 use Friendica\Util\Strings;
17 * GUI for advanced contact details manipulation
19 class Advanced extends BaseModule
21 public static function init(array $parameters = [])
23 if (!Session::isAuthenticated()) {
24 throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
28 public static function post(array $parameters = [])
30 $cid = $parameters['id'];
32 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
33 if (empty($contact)) {
34 throw new BadRequestException(DI::l10n()->t('Contact not found.'));
37 $name = ($_POST['name'] ?? '') ?: $contact['name'];
38 $nick = $_POST['nick'] ?? '';
39 $url = $_POST['url'] ?? '';
40 $alias = $_POST['alias'] ?? '';
41 $request = $_POST['request'] ?? '';
42 $confirm = $_POST['confirm'] ?? '';
43 $notify = $_POST['notify'] ?? '';
44 $poll = $_POST['poll'] ?? '';
45 $attag = $_POST['attag'] ?? '';
46 $photo = $_POST['photo'] ?? '';
47 $remote_self = $_POST['remote_self'] ?? false;
48 $nurl = Strings::normaliseLink($url);
50 $r = DI::dba()->update(
58 'request' => $request,
59 'confirm' => $confirm,
63 'remote_self' => $remote_self,
65 ['id' => $contact['id'], 'uid' => local_user()]
69 DI::logger()->notice('Updating photo.', ['photo' => $photo]);
71 Model\Contact::updateAvatar($photo, local_user(), $contact['id']);
75 info(DI::l10n()->t('Contact settings applied.') . EOL);
77 notice(DI::l10n()->t('Contact update failed.') . EOL);
83 public static function content(array $parameters = [])
85 $cid = $parameters['id'];
87 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
88 if (empty($contact)) {
89 throw new BadRequestException(DI::l10n()->t('Contact not found.'));
92 Model\Profile::load(DI::app(), "", Model\Contact::getDetailsByURL($contact["url"]));
94 $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.');
95 $info = DI::l10n()->t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
97 $returnaddr = "contact/$cid";
99 // Disable remote self for everything except feeds.
100 // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
101 // Problem is, you couldn't reply to both networks.
102 $allow_remote_self = in_array($contact['network'], [Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])
103 && DI::config()->get('system', 'allow_users_remote_self');
105 if ($contact['network'] == Protocol::FEED) {
106 $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')];
108 $remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '2' => DI::l10n()->t('Mirror as my own posting')];
111 $tab_str = Contact::getTabsHTML(DI::app(), $contact, 6);
113 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
114 return Renderer::replaceMacros($tpl, [
115 '$tab_str' => $tab_str,
116 '$warning' => $warning,
118 '$returnaddr' => $returnaddr,
119 '$return' => DI::l10n()->t('Return to contact editor'),
120 '$update_profile' => in_array($contact['network'], Protocol::FEDERATED),
121 '$udprofilenow' => DI::l10n()->t('Refetch contact data'),
122 '$contact_id' => $contact['id'],
123 '$lbl_submit' => DI::l10n()->t('Submit'),
124 '$label_remote_self' => DI::l10n()->t('Remote Self'),
125 '$allow_remote_self' => $allow_remote_self,
126 '$remote_self' => ['remote_self',
127 DI::l10n()->t('Mirror postings from this contact'),
128 $contact['remote_self'],
129 DI::l10n()->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
133 '$name' => ['name', DI::l10n()->t('Name'), $contact['name']],
134 '$nick' => ['nick', DI::l10n()->t('Account Nickname'), $contact['nick']],
135 '$attag' => ['attag', DI::l10n()->t('@Tagname - overrides Name/Nickname'), $contact['attag']],
136 '$url' => ['url', DI::l10n()->t('Account URL'), $contact['url']],
137 '$alias' => ['alias', DI::l10n()->t('Account URL Alias'), $contact['alias']],
138 '$request' => ['request', DI::l10n()->t('Friend Request URL'), $contact['request']],
139 'confirm' => ['confirm', DI::l10n()->t('Friend Confirm URL'), $contact['confirm']],
140 'notify' => ['notify', DI::l10n()->t('Notification Endpoint URL'), $contact['notify']],
141 'poll' => ['poll', DI::l10n()->t('Poll/Feed URL'), $contact['poll']],
142 'photo' => ['photo', DI::l10n()->t('New photo from this URL'), ''],