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