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 if (empty(DI::page()['aside'])) {
93 DI::page()['aside'] = '';
98 $a->data['contact'] = $contact;
99 Model\Profile::load($a, "", Model\Contact::getDetailsByURL($contact["url"]));
101 $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.');
102 $info = DI::l10n()->t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
104 $returnaddr = "contact/$cid";
106 $allow_remote_self = DI::config()->get('system', 'allow_users_remote_self');
108 // Disable remote self for everything except feeds.
109 // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
110 // Problem is, you couldn't reply to both networks.
111 if (!in_array($contact['network'], [Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])) {
112 $allow_remote_self = false;
115 if ($contact['network'] == Protocol::FEED) {
116 $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')];
118 $remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '2' => DI::l10n()->t('Mirror as my own posting')];
121 $update_profile = in_array($contact['network'], Protocol::FEDERATED);
123 $tab_str = Contact::getTabsHTML($a, $contact, 6);
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 '$update_profile' => $update_profile,
133 '$udprofilenow' => DI::l10n()->t('Refetch contact data'),
134 '$contact_id' => $contact['id'],
135 '$lbl_submit' => DI::l10n()->t('Submit'),
136 '$label_remote_self' => DI::l10n()->t('Remote Self'),
137 '$allow_remote_self' => $allow_remote_self,
138 '$remote_self' => ['remote_self',
139 DI::l10n()->t('Mirror postings from this contact'),
140 $contact['remote_self'],
141 DI::l10n()->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
145 '$name' => ['name', DI::l10n()->t('Name'), $contact['name']],
146 '$nick' => ['nick', DI::l10n()->t('Account Nickname'), $contact['nick']],
147 '$attag' => ['attag', DI::l10n()->t('@Tagname - overrides Name/Nickname'), $contact['attag']],
148 '$url' => ['url', DI::l10n()->t('Account URL'), $contact['url']],
149 '$alias' => ['alias', DI::l10n()->t('Account URL Alias'), $contact['alias']],
150 '$request' => ['request', DI::l10n()->t('Friend Request URL'), $contact['request']],
151 'confirm' => ['confirm', DI::l10n()->t('Friend Confirm URL'), $contact['confirm']],
152 'notify' => ['notify', DI::l10n()->t('Notification Endpoint URL'), $contact['notify']],
153 'poll' => ['poll', DI::l10n()->t('Poll/Feed URL'), $contact['poll']],
154 'photo' => ['photo', DI::l10n()->t('New photo from this URL'), ''],