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