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