3 * @file mod/crepair.php
7 use Friendica\Core\Config;
8 use Friendica\Core\L10n;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Contact;
11 use Friendica\Model\Profile;
13 require_once 'mod/contacts.php';
15 function crepair_init(App $a)
22 if (($a->argc == 2) && intval($a->argv[1])) {
23 $contact = DBA::selectFirst('contact', [], ['uid' => local_user(), 'id' => $a->argv[1]]);
26 if (!x($a->page, 'aside')) {
27 $a->page['aside'] = '';
30 if (DBA::isResult($contact)) {
31 $a->data['contact'] = $contact;
32 Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
36 function crepair_post(App $a)
42 $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
46 $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
49 if (!DBA::isResult($contact)) {
53 $name = defaults($_POST, 'name' , $contact['name']);
54 $nick = defaults($_POST, 'nick' , '');
55 $url = defaults($_POST, 'url' , '');
56 $request = defaults($_POST, 'request' , '');
57 $confirm = defaults($_POST, 'confirm' , '');
58 $notify = defaults($_POST, 'notify' , '');
59 $poll = defaults($_POST, 'poll' , '');
60 $attag = defaults($_POST, 'attag' , '');
61 $photo = defaults($_POST, 'photo' , '');
62 $remote_self = defaults($_POST, 'remote_self', false);
63 $nurl = normalise_link($url);
65 $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
66 WHERE `id` = %d AND `uid` = %d",
77 intval($contact['id']),
82 logger('mod-crepair: updating photo from ' . $photo);
84 Contact::updateAvatar($photo, local_user(), $contact['id']);
88 info(L10n::t('Contact settings applied.') . EOL);
90 notice(L10n::t('Contact update failed.') . EOL);
96 function crepair_content(App $a)
99 notice(L10n::t('Permission denied.') . EOL);
103 $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
107 $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
110 if (!DBA::isResult($contact)) {
111 notice(L10n::t('Contact not found.') . EOL);
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.');
118 $returnaddr = "contacts/$cid";
120 $allow_remote_self = Config::get('system', 'allow_users_remote_self');
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'], [NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_TWITTER])) {
126 $allow_remote_self = false;
129 if ($contact['network'] == NETWORK_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')];
132 $remote_self_options = ['0' => L10n::t('No mirroring'), '2' => L10n::t('Mirror as my own posting')];
135 $update_profile = in_array($contact['network'], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS]);
137 $tab_str = contacts_tab($a, $contact['id'], 5);
139 $tpl = get_markup_template('crepair.tpl');
140 $o = replace_macros($tpl, [
141 '$tab_str' => $tab_str,
142 '$warning' => $warning,
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.'),
159 '$name' => ['name', L10n::t('Name') , htmlentities($contact['name'])],
160 '$nick' => ['nick', L10n::t('Account Nickname'), htmlentities($contact['nick'])],
161 '$attag' => ['attag', L10n::t('@Tagname - overrides Name/Nickname'), $contact['attag']],
162 '$url' => ['url', L10n::t('Account URL'), $contact['url']],
163 '$request' => ['request', L10n::t('Friend Request URL'), $contact['request']],
164 'confirm' => ['confirm', L10n::t('Friend Confirm URL'), $contact['confirm']],
165 'notify' => ['notify', L10n::t('Notification Endpoint URL'), $contact['notify']],
166 'poll' => ['poll', L10n::t('Poll/Feed URL'), $contact['poll']],
167 'photo' => ['photo', L10n::t('New photo from this URL'), ''],