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