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