]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact/Advanced.php
Merge pull request #8227 from annando/daemon-checks
[friendica.git] / src / Module / Contact / Advanced.php
1 <?php
2
3 namespace Friendica\Module\Contact;
4
5 use Friendica\BaseModule;
6 use Friendica\Core\Protocol;
7 use Friendica\Core\Renderer;
8 use Friendica\Core\Session;
9 use Friendica\DI;
10 use Friendica\Model;
11 use Friendica\Module\Contact;
12 use Friendica\Network\HTTPException\BadRequestException;
13 use Friendica\Network\HTTPException\ForbiddenException;
14 use Friendica\Util\Strings;
15
16 /**
17  * GUI for advanced contact details manipulation
18  */
19 class Advanced extends BaseModule
20 {
21         public static function init(array $parameters = [])
22         {
23                 if (!Session::isAuthenticated()) {
24                         throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
25                 }
26         }
27
28         public static function post(array $parameters = [])
29         {
30                 $cid = $parameters['id'];
31
32                 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
33                 if (empty($contact)) {
34                         throw new BadRequestException(DI::l10n()->t('Contact not found.'));
35                 }
36
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);
49
50                 $r = DI::dba()->update(
51                         'contact',
52                         [
53                                 'name'        => $name,
54                                 'nick'        => $nick,
55                                 'url'         => $url,
56                                 'nurl'        => $nurl,
57                                 'alias'       => $alias,
58                                 'request'     => $request,
59                                 'confirm'     => $confirm,
60                                 'notify'      => $notify,
61                                 'poll'        => $poll,
62                                 'attag'       => $attag,
63                                 'remote_self' => $remote_self,
64                         ],
65                         ['id' => $contact['id'], 'uid' => local_user()]
66                 );
67
68                 if ($photo) {
69                         DI::logger()->notice('Updating photo.', ['photo' => $photo]);
70
71                         Model\Contact::updateAvatar($photo, local_user(), $contact['id'], true);
72                 }
73
74                 if ($r) {
75                         info(DI::l10n()->t('Contact settings applied.') . EOL);
76                 } else {
77                         notice(DI::l10n()->t('Contact update failed.') . EOL);
78                 }
79
80                 return;
81         }
82
83         public static function content(array $parameters = [])
84         {
85                 $cid = $parameters['id'];
86
87                 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
88                 if (empty($contact)) {
89                         throw new BadRequestException(DI::l10n()->t('Contact not found.'));
90                 }
91
92                 Model\Profile::load(DI::app(), "", Model\Contact::getDetailsByURL($contact["url"]));
93
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.');
96
97                 $returnaddr = "contact/$cid";
98
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');
104
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')];
107                 } else {
108                         $remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '2' => DI::l10n()->t('Mirror as my own posting')];
109                 }
110
111                 $tab_str = Contact::getTabsHTML(DI::app(), $contact, 6);
112
113                 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
114                 return Renderer::replaceMacros($tpl, [
115                         '$tab_str'           => $tab_str,
116                         '$warning'           => $warning,
117                         '$info'              => $info,
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.'),
130                                 $remote_self_options
131                         ],
132
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'), ''],
143                 ]);
144         }
145 }