]> git.mxchange.org Git - friendica.git/blob - mod/crepair.php
Merge pull request #8191 from MrPetovan/task/7967-mastodon-api-custom_emojis
[friendica.git] / mod / crepair.php
1 <?php
2 /**
3  * @file mod/crepair.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\Logger;
8 use Friendica\Core\Protocol;
9 use Friendica\Core\Renderer;
10 use Friendica\Database\DBA;
11 use Friendica\DI;
12 use Friendica\Model;
13 use Friendica\Module;
14 use Friendica\Util\Strings;
15
16 function crepair_init(App $a)
17 {
18         if (!local_user()) {
19                 return;
20         }
21 }
22
23 function crepair_post(App $a)
24 {
25         if (!local_user()) {
26                 return;
27         }
28
29         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
30
31         $contact = null;
32         if ($cid) {
33                 $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
34         }
35
36         if (!DBA::isResult($contact)) {
37                 return;
38         }
39
40         $name        = ($_POST['name']        ?? '') ?: $contact['name'];
41         $nick        =  $_POST['nick']        ?? '';
42         $url         =  $_POST['url']         ?? '';
43         $alias       =  $_POST['alias']       ?? '';
44         $request     =  $_POST['request']     ?? '';
45         $confirm     =  $_POST['confirm']     ?? '';
46         $notify      =  $_POST['notify']      ?? '';
47         $poll        =  $_POST['poll']        ?? '';
48         $attag       =  $_POST['attag']       ?? '';
49         $photo       =  $_POST['photo']       ?? '';
50         $remote_self =  $_POST['remote_self'] ?? false;
51         $nurl        = Strings::normaliseLink($url);
52
53         $r = DBA::update(
54                 'contact',
55                 [
56                         'name'        => $name,
57                         'nick'        => $nick,
58                         'url'         => $url,
59                         'nurl'        => $nurl,
60                         'alias'       => $alias,
61                         'request'     => $request,
62                         'confirm'     => $confirm,
63                         'notify'      => $notify,
64                         'poll'        => $poll,
65                         'attag'       => $attag,
66                         'remote_self' => $remote_self,
67                 ],
68                 ['id' => $contact['id'], 'uid' => local_user()]
69         );
70
71         if ($photo) {
72                 Logger::log('mod-crepair: updating photo from ' . $photo);
73
74                 Model\Contact::updateAvatar($photo, local_user(), $contact['id']);
75         }
76
77         if ($r) {
78                 info(DI::l10n()->t('Contact settings applied.') . EOL);
79         } else {
80                 notice(DI::l10n()->t('Contact update failed.') . EOL);
81         }
82
83         return;
84 }
85
86 function crepair_content(App $a)
87 {
88         if (!local_user()) {
89                 notice(DI::l10n()->t('Permission denied.') . EOL);
90                 return;
91         }
92
93         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
94
95         $contact = null;
96         if ($cid) {
97                 $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
98         }
99
100         if (!DBA::isResult($contact)) {
101                 notice(DI::l10n()->t('Contact not found.') . EOL);
102                 return;
103         }
104
105         if (empty(DI::page()['aside'])) {
106                 DI::page()['aside'] = '';
107         }
108
109         if (DBA::isResult($contact)) {
110                 $a->data['contact'] = $contact;
111                 Model\Profile::load($a, "", Model\Contact::getDetailsByURL($contact["url"]));
112         }
113
114         $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.');
115         $info = DI::l10n()->t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
116
117         $returnaddr = "contact/$cid";
118
119         $allow_remote_self = DI::config()->get('system', 'allow_users_remote_self');
120
121         // Disable remote self for everything except feeds.
122         // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
123         // Problem is, you couldn't reply to both networks.
124         if (!in_array($contact['network'], [Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])) {
125                 $allow_remote_self = false;
126         }
127
128         if ($contact['network'] == Protocol::FEED) {
129                 $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')];
130         } else {
131                 $remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '2' => DI::l10n()->t('Mirror as my own posting')];
132         }
133
134         $update_profile = in_array($contact['network'], Protocol::FEDERATED);
135
136         $tab_str = Module\Contact::getTabsHTML($a, $contact, 6);
137
138         $tpl = Renderer::getMarkupTemplate('crepair.tpl');
139         $o = Renderer::replaceMacros($tpl, [
140                 '$tab_str'        => $tab_str,
141                 '$warning'        => $warning,
142                 '$info'           => $info,
143                 '$returnaddr'     => $returnaddr,
144                 '$return'         => DI::l10n()->t('Return to contact editor'),
145                 '$update_profile' => $update_profile,
146                 '$udprofilenow'   => DI::l10n()->t('Refetch contact data'),
147                 '$contact_id'     => $contact['id'],
148                 '$lbl_submit'     => DI::l10n()->t('Submit'),
149                 '$label_remote_self' => DI::l10n()->t('Remote Self'),
150                 '$allow_remote_self' => $allow_remote_self,
151                 '$remote_self' => ['remote_self',
152                         DI::l10n()->t('Mirror postings from this contact'),
153                         $contact['remote_self'],
154                         DI::l10n()->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
155                         $remote_self_options
156                 ],
157
158                 '$name'         => ['name', DI::l10n()->t('Name') , $contact['name']],
159                 '$nick'         => ['nick', DI::l10n()->t('Account Nickname'), $contact['nick']],
160                 '$attag'        => ['attag', DI::l10n()->t('@Tagname - overrides Name/Nickname'), $contact['attag']],
161                 '$url'          => ['url', DI::l10n()->t('Account URL'), $contact['url']],
162                 '$alias'        => ['alias', DI::l10n()->t('Account URL Alias'), $contact['alias']],
163                 '$request'      => ['request', DI::l10n()->t('Friend Request URL'), $contact['request']],
164                 'confirm'       => ['confirm', DI::l10n()->t('Friend Confirm URL'), $contact['confirm']],
165                 'notify'        => ['notify', DI::l10n()->t('Notification Endpoint URL'), $contact['notify']],
166                 'poll'          => ['poll', DI::l10n()->t('Poll/Feed URL'), $contact['poll']],
167                 'photo'         => ['photo', DI::l10n()->t('New photo from this URL'), ''],
168         ]);
169
170         return $o;
171 }