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