]> git.mxchange.org Git - friendica.git/blob - include/Contact.php
add remove_user hook (it looks like dreamhost changed all my file permissions, this...
[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
19         q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
20         q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
21         q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
22         q("DELETE FROM `intro` WHERE `uid` = %d", intval($uid));
23         q("DELETE FROM `event` WHERE `uid` = %d", intval($uid));
24         q("DELETE FROM `item` WHERE `uid` = %d", intval($uid));
25         q("DELETE FROM `mail` WHERE `uid` = %d", intval($uid));
26         q("DELETE FROM `photo` WHERE `uid` = %d", intval($uid));
27         q("DELETE FROM `profile` WHERE `uid` = %d", intval($uid));
28         q("DELETE FROM `profile_check` WHERE `uid` = %d", intval($uid));
29         q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($uid));
30         q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
31         if($uid == local_user()) {
32                 unset($_SESSION['authenticated']);
33                 unset($_SESSION['uid']);
34                 goaway($a->get_baseurl());
35         }
36 }
37
38
39 function contact_remove($id) {
40         q("DELETE FROM `contact` WHERE `id` = %d LIMIT 1",
41                 intval($id)
42         );
43         q("DELETE FROM `item` WHERE `contact-id` = %d ",
44                 intval($id)
45         );
46         q("DELETE FROM `photo` WHERE `contact-id` = %d ",
47                 intval($id)
48         );
49         q("DELETE FROM `mail` WHERE `contact-id` = %d ",
50                 intval($id)
51         );
52         q("DELETE FROM `event` WHERE `cid` = %d ",
53                 intval($id)
54         );
55         q("DELETE FROM `queue` WHERE `cid` = %d ",
56                 intval($id)
57         );
58
59 }
60
61
62 // Contact has refused to recognise us as a friend. We will start a countdown.
63 // If they still don't recognise us in 32 days, the relationship is over,
64 // and we won't waste any more time trying to communicate with them.
65 // This provides for the possibility that their database is temporarily messed
66 // up or some other transient event and that there's a possibility we could recover from it.
67  
68 if(! function_exists('mark_for_death')) {
69 function mark_for_death($contact) {
70         if($contact['term-date'] == '0000-00-00 00:00:00') {
71                 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
72                                 dbesc(datetime_convert()),
73                                 intval($contact['id'])
74                 );
75         }
76         else {
77                 $expiry = $contact['term-date'] . ' + 32 days ';
78                 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
79
80                         // relationship is really truly dead. 
81
82                         contact_remove($contact['id']);
83
84                 }
85         }
86
87 }}
88
89 if(! function_exists('unmark_for_death')) {
90 function unmark_for_death($contact) {
91         // It's a miracle. Our dead contact has inexplicably come back to life.
92         q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1",
93                 dbesc('0000-00-00 00:00:00'),
94                 intval($contact['id'])
95         );
96 }}
97
98 if(! function_exists('contact_photo_menu')){
99 function contact_photo_menu($contact) {
100
101         $a = get_app();
102         
103         $contact_url="";
104         $pm_url="";
105         $status_link="";
106         $photos_link="";
107         $posts_link="";
108
109         $sparkle = false;
110         if($contact['network'] === NETWORK_DFRN) {
111                 $sparkle = true;
112                 $profile_link = $a->get_baseurl() . '/redir/' . $contact['id'];
113         }
114         else
115                 $profile_link = $contact['url'];
116
117         if($profile_link === 'mailbox')
118                 $profile_link = '';
119
120         if($sparkle) {
121                 $status_link = $profile_link . "?url=status";
122                 $photos_link = $profile_link . "?url=photos";
123                 $profile_link = $profile_link . "?url=profile";
124                 $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id'];
125         }
126
127         $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
128         $posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['id'];
129
130         $menu = Array(
131                 t("View status") => $status_link,
132                 t("View profile") => $profile_link,
133                 t("View photos") => $photos_link,               
134                 t("View recent") => $posts_link, 
135                 t("Edit contact") => $contact_url,
136                 t("Send PM") => $pm_url,
137         );
138         
139         
140         $args = array('contact' => $contact, 'menu' => $menu);
141         
142         call_hooks('contact_photo_menu', $args);
143         
144         $o = "";
145         foreach($menu as $k=>$v){
146                 if ($v!="") {
147                         if(($k !== t("View recent")) && ($k !== t("Send PM")))
148                                 $o .= "<li><a target=\"redir\" href=\"$v\">$k</a></li>\n";
149                         else
150                                 $o .= "<li><a href=\"$v\">$k</a></li>\n";
151                 }
152         }
153         return $o;
154 }}