]> git.mxchange.org Git - friendica.git/blob - mod/crepair.php
get markup template
[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
16 function crepair_init(App $a)
17 {
18         if (!local_user()) {
19                 return;
20         }
21
22         $contact = null;
23         if (($a->argc == 2) && intval($a->argv[1])) {
24                 $contact = DBA::selectFirst('contact', [], ['uid' => local_user(), 'id' => $a->argv[1]]);
25         }
26
27         if (!x($a->page, 'aside')) {
28                 $a->page['aside'] = '';
29         }
30
31         if (DBA::isResult($contact)) {
32                 $a->data['contact'] = $contact;
33                 Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
34         }
35 }
36
37 function crepair_post(App $a)
38 {
39         if (!local_user()) {
40                 return;
41         }
42
43         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
44
45         $contact = null;
46         if ($cid) {
47                 $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
48         }
49
50         if (!DBA::isResult($contact)) {
51                 return;
52         }
53
54         $name        = defaults($_POST, 'name'       , $contact['name']);
55         $nick        = defaults($_POST, 'nick'       , '');
56         $url         = defaults($_POST, 'url'        , '');
57         $request     = defaults($_POST, 'request'    , '');
58         $confirm     = defaults($_POST, 'confirm'    , '');
59         $notify      = defaults($_POST, 'notify'     , '');
60         $poll        = defaults($_POST, 'poll'       , '');
61         $attag       = defaults($_POST, 'attag'      , '');
62         $photo       = defaults($_POST, 'photo'      , '');
63         $remote_self = defaults($_POST, 'remote_self', false);
64         $nurl        = normalise_link($url);
65
66         $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `nurl` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s', `attag` = '%s' , `remote_self` = %d
67                 WHERE `id` = %d AND `uid` = %d",
68                 DBA::escape($name),
69                 DBA::escape($nick),
70                 DBA::escape($url),
71                 DBA::escape($nurl),
72                 DBA::escape($request),
73                 DBA::escape($confirm),
74                 DBA::escape($notify),
75                 DBA::escape($poll),
76                 DBA::escape($attag),
77                 intval($remote_self),
78                 intval($contact['id']),
79                 local_user()
80         );
81
82         if ($photo) {
83                 Logger::log('mod-crepair: updating photo from ' . $photo);
84
85                 Model\Contact::updateAvatar($photo, local_user(), $contact['id']);
86         }
87
88         if ($r) {
89                 info(L10n::t('Contact settings applied.') . EOL);
90         } else {
91                 notice(L10n::t('Contact update failed.') . EOL);
92         }
93
94         return;
95 }
96
97 function crepair_content(App $a)
98 {
99         if (!local_user()) {
100                 notice(L10n::t('Permission denied.') . EOL);
101                 return;
102         }
103
104         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
105
106         $contact = null;
107         if ($cid) {
108                 $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
109         }
110
111         if (!DBA::isResult($contact)) {
112                 notice(L10n::t('Contact not found.') . EOL);
113                 return;
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::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]);
137
138         $tab_str = Module\Contact::getTabsHTML($a, $contact, 5);
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') , htmlentities($contact['name'])],
161                 '$nick'         => ['nick', L10n::t('Account Nickname'), htmlentities($contact['nick'])],
162                 '$attag'        => ['attag', L10n::t('@Tagname - overrides Name/Nickname'), $contact['attag']],
163                 '$url'          => ['url', L10n::t('Account URL'), $contact['url']],
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 }