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