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