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