]> git.mxchange.org Git - friendica.git/blob - include/Contact.php
Merge pull request #317 from CatoTH/master
[friendica.git] / include / Contact.php
1 <?php
2
3
4 // Included here for completeness, but this is a very dangerous operation.
5 // It is the caller's responsibility to confirm the requestor's intent and
6 // authorisation to do this.
7
8 function user_remove($uid) {
9         if(! $uid)
10                 return;
11         $a = get_app();
12         logger('Removing user: ' . $uid);
13
14         $r = q("select * from user where uid = %d limit 1", intval($uid));
15
16         call_hooks('remove_user',$r[0]);
17
18         // save username (actually the nickname as it is guaranteed 
19         // unique), so it cannot be re-registered in the future.
20
21         q("insert into userd ( username ) values ( '%s' )",
22                 $r[0]['nickname']
23         );
24
25         q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
26         q("DELETE FROM `gcign` WHERE `uid` = %d", intval($uid));
27         q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
28         q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
29         q("DELETE FROM `intro` WHERE `uid` = %d", intval($uid));
30         q("DELETE FROM `event` WHERE `uid` = %d", intval($uid));
31         q("DELETE FROM `item` WHERE `uid` = %d", intval($uid));
32         q("DELETE FROM `item_id` WHERE `uid` = %d", intval($uid));
33         q("DELETE FROM `mail` WHERE `uid` = %d", intval($uid));
34         q("DELETE FROM `mailacct` WHERE `uid` = %d", intval($uid));
35         q("DELETE FROM `manage` WHERE `uid` = %d", intval($uid));
36         q("DELETE FROM `notify` WHERE `uid` = %d", intval($uid));
37         q("DELETE FROM `photo` WHERE `uid` = %d", intval($uid));
38         q("DELETE FROM `attach` WHERE `uid` = %d", intval($uid));
39         q("DELETE FROM `profile` WHERE `uid` = %d", intval($uid));
40         q("DELETE FROM `profile_check` WHERE `uid` = %d", intval($uid));
41         q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($uid));
42         q("DELETE FROM `search` WHERE `uid` = %d", intval($uid));
43         q("DELETE FROM `spam` WHERE `uid` = %d", intval($uid));
44         q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
45         if($uid == local_user()) {
46                 unset($_SESSION['authenticated']);
47                 unset($_SESSION['uid']);
48                 goaway($a->get_baseurl());
49         }
50 }
51
52
53 function contact_remove($id) {
54
55         $r = q("select uid from contact where id = %d limit 1",
56                 intval($id)
57         );
58         if((! count($r)) || (! intval($r[0]['uid'])))
59                 return;
60
61         $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts');
62         if($archive) {
63                 q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d limit 1",
64                         intval($id)
65                 );
66                 return;
67         }
68
69         q("DELETE FROM `contact` WHERE `id` = %d LIMIT 1",
70                 intval($id)
71         );
72         q("DELETE FROM `item` WHERE `contact-id` = %d ",
73                 intval($id)
74         );
75         q("DELETE FROM `photo` WHERE `contact-id` = %d ",
76                 intval($id)
77         );
78         q("DELETE FROM `mail` WHERE `contact-id` = %d ",
79                 intval($id)
80         );
81         q("DELETE FROM `event` WHERE `cid` = %d ",
82                 intval($id)
83         );
84         q("DELETE FROM `queue` WHERE `cid` = %d ",
85                 intval($id)
86         );
87
88 }
89
90
91 // sends an unfriend message. Does not remove the contact
92
93 function terminate_friendship($user,$self,$contact) {
94
95
96         $a = get_app();
97
98         require_once('include/datetime.php');
99
100         if($contact['network'] === NETWORK_OSTATUS) {
101
102                 $slap = replace_macros(get_markup_template('follow_slap.tpl'), array(
103                         '$name' => $user['username'],
104                         '$profile_page' => $a->get_baseurl() . '/profile/' . $user['nickname'],
105                         '$photo' => $self['photo'],
106                         '$thumb' => $self['thumb'],
107                         '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
108                         '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
109                         '$title' => '',
110                         '$type' => 'text',
111                         '$content' => t('stopped following'),
112                         '$nick' => $user['nickname'],
113                         '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
114                         '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
115                 ));
116
117                 if((x($contact,'notify')) && (strlen($contact['notify']))) {
118                         require_once('include/salmon.php');
119                         slapper($user,$contact['notify'],$slap);
120                 }
121         }
122         elseif($contact['network'] === NETWORK_DIASPORA) {
123                 require_once('include/diaspora.php');
124                 diaspora_unshare($user,$contact);
125         }
126         elseif($contact['network'] === NETWORK_DFRN) {
127                 require_once('include/items.php');
128                 dfrn_deliver($user,$contact,'placeholder', 1);
129         }
130
131 }
132
133
134 // Contact has refused to recognise us as a friend. We will start a countdown.
135 // If they still don't recognise us in 32 days, the relationship is over,
136 // and we won't waste any more time trying to communicate with them.
137 // This provides for the possibility that their database is temporarily messed
138 // up or some other transient event and that there's a possibility we could recover from it.
139  
140 if(! function_exists('mark_for_death')) {
141 function mark_for_death($contact) {
142         if($contact['term-date'] == '0000-00-00 00:00:00') {
143                 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
144                                 dbesc(datetime_convert()),
145                                 intval($contact['id'])
146                 );
147         }
148         else {
149                 $expiry = $contact['term-date'] . ' + 32 days ';
150                 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
151
152                         // relationship is really truly dead. 
153
154                         contact_remove($contact['id']);
155
156                 }
157         }
158
159 }}
160
161 if(! function_exists('unmark_for_death')) {
162 function unmark_for_death($contact) {
163         // It's a miracle. Our dead contact has inexplicably come back to life.
164         q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
165                 dbesc('0000-00-00 00:00:00'),
166                 intval($contact['id'])
167         );
168 }}
169
170 if(! function_exists('contact_photo_menu')){
171 function contact_photo_menu($contact) {
172
173         $a = get_app();
174         
175         $contact_url="";
176         $pm_url="";
177         $status_link="";
178         $photos_link="";
179         $posts_link="";
180
181         $sparkle = false;
182         if($contact['network'] === NETWORK_DFRN) {
183                 $sparkle = true;
184                 $profile_link = $a->get_baseurl() . '/redir/' . $contact['id'];
185         }
186         else
187                 $profile_link = $contact['url'];
188
189         if($profile_link === 'mailbox')
190                 $profile_link = '';
191
192         if($sparkle) {
193                 $status_link = $profile_link . "?url=status";
194                 $photos_link = $profile_link . "?url=photos";
195                 $profile_link = $profile_link . "?url=profile";
196                 $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id'];
197         }
198
199         $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
200         $posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['id'];
201
202         $menu = Array(
203                 t("View Status") => $status_link,
204                 t("View Profile") => $profile_link,
205                 t("View Photos") => $photos_link,               
206                 t("Network Posts") => $posts_link, 
207                 t("Edit Contact") => $contact_url,
208                 t("Send PM") => $pm_url,
209         );
210         
211         
212         $args = array('contact' => $contact, 'menu' => &$menu);
213         
214         call_hooks('contact_photo_menu', $args);
215         
216         $o = "";
217         foreach($menu as $k=>$v){
218                 if ($v!="") {
219                         if(($k !== t("Network Posts")) && ($k !== t("Send PM")) && ($k !== t('Edit Contact')))
220                                 $o .= "<li><a target=\"redir\" href=\"$v\">$k</a></li>\n";
221                         else
222                                 $o .= "<li><a href=\"$v\">$k</a></li>\n";
223                 }
224         }
225         return $o;
226 }}
227
228
229 function random_profile() {
230         $r = q("select url from gcontact where url like '%%://%%/profile/%%' order by rand() limit 1");
231         if(count($r))
232                 return dirname($r[0]['url']);
233         return '';
234 }
235
236
237 function contacts_not_grouped($uid,$start = 0,$count = 0) {
238
239         if(! $count) {
240                 $r = q("select count(*) as total from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) ",
241                         intval($uid),
242                         intval($uid)
243                 );
244
245                 return $r;
246
247
248         }
249
250         $r = q("select * from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) and blocked = 0 and pending = 0 limit %d, %d",
251                 intval($uid),
252                 intval($uid),
253                 intval($start),
254                 intval($count)
255         );
256
257         return $r;
258 }
259