]> git.mxchange.org Git - friendica.git/blob - mod/crepair.php
Improve Console/Config display for array values
[friendica.git] / mod / crepair.php
1 <?php
2 /**
3  * @file mod/crepair.php
4  */
5 use Friendica\App;
6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Database\DBM;
9 use Friendica\Model\Contact;
10 use Friendica\Model\Profile;
11
12 require_once 'mod/contacts.php';
13
14 function crepair_init(App $a)
15 {
16         if (!local_user()) {
17                 return;
18         }
19
20         $contact = null;
21         if (($a->argc == 2) && intval($a->argv[1])) {
22                 $contact = dba::selectFirst('contact', [], ['uid' => local_user(), 'id' => $a->argv[1]]);
23         }
24
25         if (!x($a->page, 'aside')) {
26                 $a->page['aside'] = '';
27         }
28
29         if (DBM::is_result($contact)) {
30                 $a->data['contact'] = $contact;
31                 Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
32         }
33 }
34
35 function crepair_post(App $a)
36 {
37         if (!local_user()) {
38                 return;
39         }
40
41         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
42
43         $contact = null;
44         if ($cid) {
45                 $contact = dba::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
46         }
47
48         if (!DBM::is_result($contact)) {
49                 return;
50         }
51
52         $name        = defaults($_POST, 'name'       , $contact['name']);
53         $nick        = defaults($_POST, 'nick'       , '');
54         $url         = defaults($_POST, 'url'        , '');
55         $request     = defaults($_POST, 'request'    , '');
56         $confirm     = defaults($_POST, 'confirm'    , '');
57         $notify      = defaults($_POST, 'notify'     , '');
58         $poll        = defaults($_POST, 'poll'       , '');
59         $attag       = defaults($_POST, 'attag'      , '');
60         $photo       = defaults($_POST, 'photo'      , '');
61         $remote_self = defaults($_POST, 'remote_self', false);
62         $nurl        = normalise_link($url);
63
64         $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
65                 WHERE `id` = %d AND `uid` = %d",
66                 dbesc($name),
67                 dbesc($nick),
68                 dbesc($url),
69                 dbesc($nurl),
70                 dbesc($request),
71                 dbesc($confirm),
72                 dbesc($notify),
73                 dbesc($poll),
74                 dbesc($attag),
75                 intval($remote_self),
76                 intval($contact['id']),
77                 local_user()
78         );
79
80         if ($photo) {
81                 logger('mod-crepair: updating photo from ' . $photo);
82
83                 Contact::updateAvatar($photo, local_user(), $contact['id']);
84         }
85
86         if ($r) {
87                 info(L10n::t('Contact settings applied.') . EOL);
88         } else {
89                 notice(L10n::t('Contact update failed.') . EOL);
90         }
91
92         return;
93 }
94
95 function crepair_content(App $a)
96 {
97         if (!local_user()) {
98                 notice(L10n::t('Permission denied.') . EOL);
99                 return;
100         }
101
102         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
103
104                 $contact = null;
105         if ($cid) {
106                 $contact = dba::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
107         }
108
109         if (!DBM::is_result($contact)) {
110                 notice(L10n::t('Contact not found.') . EOL);
111                 return;
112         }
113
114         $warning = 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 = L10n::t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
116
117         $returnaddr = "contacts/$cid";
118
119         $allow_remote_self = 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'], [NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_TWITTER])) {
125                 $allow_remote_self = false;
126         }
127
128         if ($contact['network'] == NETWORK_FEED) {
129                 $remote_self_options = ['0' => L10n::t('No mirroring'), '1' => L10n::t('Mirror as forwarded posting'), '2' => L10n::t('Mirror as my own posting')];
130         } else {
131                 $remote_self_options = ['0' => L10n::t('No mirroring'), '2' => L10n::t('Mirror as my own posting')];
132         }
133
134         $update_profile = in_array($contact['network'], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS]);
135
136         $tab_str = contacts_tab($a, $contact['id'], 5);
137
138         $tpl = get_markup_template('crepair.tpl');
139         $o = replace_macros($tpl, [
140                 '$tab_str'        => $tab_str,
141                 '$warning'        => $warning,
142                 '$info'           => $info,
143                 '$returnaddr'     => $returnaddr,
144                 '$return'         => L10n::t('Return to contact editor'),
145                 '$update_profile' => $update_profile,
146                 '$udprofilenow'   => L10n::t('Refetch contact data'),
147                 '$contact_id'     => $contact['id'],
148                 '$lbl_submit'     => L10n::t('Submit'),
149                 '$label_remote_self' => L10n::t('Remote Self'),
150                 '$allow_remote_self' => $allow_remote_self,
151                 '$remote_self' => ['remote_self',
152                         L10n::t('Mirror postings from this contact'),
153                         $contact['remote_self'],
154                         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', L10n::t('Name') , htmlentities($contact['name'])],
159                 '$nick'         => ['nick', L10n::t('Account Nickname'), htmlentities($contact['nick'])],
160                 '$attag'        => ['attag', L10n::t('@Tagname - overrides Name/Nickname'), $contact['attag']],
161                 '$url'          => ['url', L10n::t('Account URL'), $contact['url']],
162                 '$request'      => ['request', L10n::t('Friend Request URL'), $contact['request']],
163                 'confirm'       => ['confirm', L10n::t('Friend Confirm URL'), $contact['confirm']],
164                 'notify'        => ['notify', L10n::t('Notification Endpoint URL'), $contact['notify']],
165                 'poll'          => ['poll', L10n::t('Poll/Feed URL'), $contact['poll']],
166                 'photo'         => ['photo', L10n::t('New photo from this URL'), ''],
167         ]);
168
169         return $o;
170 }